memcached 1.2.6 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +206 -12
  3. data/Rakefile +32 -1
  4. data/ext/extconf.rb +10 -35
  5. data/ext/libmemcached-0.32/AUTHORS +7 -0
  6. data/ext/libmemcached-0.32/COPYING +32 -0
  7. data/ext/libmemcached-0.32/ChangeLog +303 -0
  8. data/ext/libmemcached-0.32/INSTALL +302 -0
  9. data/ext/libmemcached-0.32/Makefile.am +36 -0
  10. data/ext/libmemcached-0.32/Makefile.in +828 -0
  11. data/ext/libmemcached-0.32/NEWS +1 -0
  12. data/ext/libmemcached-0.32/README +33 -0
  13. data/ext/libmemcached-0.32/THANKS +14 -0
  14. data/ext/libmemcached-0.32/TODO +11 -0
  15. data/ext/libmemcached-0.32/aclocal.m4 +1852 -0
  16. data/ext/libmemcached-0.32/clients/Makefile.am +73 -0
  17. data/ext/libmemcached-0.32/clients/Makefile.in +770 -0
  18. data/ext/libmemcached-0.32/clients/client_options.h +32 -0
  19. data/ext/libmemcached-0.32/clients/execute.c +64 -0
  20. data/ext/libmemcached-0.32/clients/execute.h +5 -0
  21. data/ext/libmemcached-0.32/clients/generator.c +74 -0
  22. data/ext/libmemcached-0.32/clients/generator.h +20 -0
  23. data/ext/libmemcached-0.32/clients/memcat.c +178 -0
  24. data/ext/libmemcached-0.32/clients/memcp.c +251 -0
  25. data/ext/libmemcached-0.32/clients/memdump.c +170 -0
  26. data/ext/libmemcached-0.32/clients/memerror.c +80 -0
  27. data/ext/libmemcached-0.32/clients/memflush.c +143 -0
  28. data/ext/libmemcached-0.32/clients/memrm.c +160 -0
  29. data/ext/libmemcached-0.32/clients/memslap.c +441 -0
  30. data/ext/libmemcached-0.32/clients/memstat.c +326 -0
  31. data/ext/libmemcached-0.32/clients/utilities.c +207 -0
  32. data/ext/libmemcached-0.32/clients/utilities.h +41 -0
  33. data/ext/libmemcached-0.32/config.h.in +252 -0
  34. data/ext/libmemcached-0.32/config/compile +143 -0
  35. data/ext/libmemcached-0.32/config/config.guess +1561 -0
  36. data/ext/libmemcached-0.32/config/config.rpath +666 -0
  37. data/ext/libmemcached-0.32/config/config.sub +1686 -0
  38. data/ext/libmemcached-0.32/config/depcomp +630 -0
  39. data/ext/libmemcached-0.32/config/install-sh +520 -0
  40. data/ext/libmemcached-0.32/config/ltmain.sh +8406 -0
  41. data/ext/libmemcached-0.32/config/missing +376 -0
  42. data/ext/libmemcached-0.32/configure +23048 -0
  43. data/ext/libmemcached-0.32/configure.ac +122 -0
  44. data/ext/libmemcached-0.32/docs/Makefile.am +415 -0
  45. data/ext/libmemcached-0.32/docs/Makefile.in +918 -0
  46. data/ext/libmemcached-0.32/docs/libmemcached.pod +123 -0
  47. data/ext/libmemcached-0.32/docs/libmemcached_examples.pod +115 -0
  48. data/ext/libmemcached-0.32/docs/libmemcachedutil.pod +40 -0
  49. data/ext/libmemcached-0.32/docs/memcached_analyze.pod +52 -0
  50. data/ext/libmemcached-0.32/docs/memcached_auto.pod +97 -0
  51. data/ext/libmemcached-0.32/docs/memcached_behavior.pod +224 -0
  52. data/ext/libmemcached-0.32/docs/memcached_callback.pod +123 -0
  53. data/ext/libmemcached-0.32/docs/memcached_create.pod +61 -0
  54. data/ext/libmemcached-0.32/docs/memcached_delete.pod +54 -0
  55. data/ext/libmemcached-0.32/docs/memcached_dump.pod +53 -0
  56. data/ext/libmemcached-0.32/docs/memcached_flush.pod +46 -0
  57. data/ext/libmemcached-0.32/docs/memcached_flush_buffers.pod +42 -0
  58. data/ext/libmemcached-0.32/docs/memcached_generate_hash_value.pod +57 -0
  59. data/ext/libmemcached-0.32/docs/memcached_get.pod +161 -0
  60. data/ext/libmemcached-0.32/docs/memcached_memory_allocators.pod +73 -0
  61. data/ext/libmemcached-0.32/docs/memcached_pool.pod +77 -0
  62. data/ext/libmemcached-0.32/docs/memcached_quit.pod +47 -0
  63. data/ext/libmemcached-0.32/docs/memcached_sasl.pod +63 -0
  64. data/ext/libmemcached-0.32/docs/memcached_server_st.pod +75 -0
  65. data/ext/libmemcached-0.32/docs/memcached_servers.pod +102 -0
  66. data/ext/libmemcached-0.32/docs/memcached_set.pod +187 -0
  67. data/ext/libmemcached-0.32/docs/memcached_stats.pod +82 -0
  68. data/ext/libmemcached-0.32/docs/memcached_strerror.pod +46 -0
  69. data/ext/libmemcached-0.32/docs/memcached_user_data.pod +49 -0
  70. data/ext/libmemcached-0.32/docs/memcached_verbosity.pod +41 -0
  71. data/ext/libmemcached-0.32/docs/memcached_version.pod +56 -0
  72. data/ext/libmemcached-0.32/docs/memcat.pod +37 -0
  73. data/ext/libmemcached-0.32/docs/memcp.pod +40 -0
  74. data/ext/libmemcached-0.32/docs/memdump.pod +31 -0
  75. data/ext/libmemcached-0.32/docs/memerror.pod +30 -0
  76. data/ext/libmemcached-0.32/docs/memflush.pod +35 -0
  77. data/ext/libmemcached-0.32/docs/memrm.pod +34 -0
  78. data/ext/libmemcached-0.32/docs/memslap.pod +33 -0
  79. data/ext/libmemcached-0.32/docs/memstat.pod +35 -0
  80. data/ext/libmemcached-0.32/libmemcached/Makefile.am +107 -0
  81. data/ext/libmemcached-0.32/libmemcached/Makefile.in +1050 -0
  82. data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
  83. data/ext/libmemcached-0.32/libmemcached/common.h +183 -0
  84. data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
  85. data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
  86. data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
  87. data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
  88. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +28 -0
  89. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +78 -0
  90. data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
  91. data/ext/libmemcached-0.32/libmemcached/memcached.c +152 -0
  92. data/ext/libmemcached-0.32/libmemcached/memcached.h +302 -0
  93. data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
  94. data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
  95. data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +366 -0
  96. data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
  97. data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
  98. data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
  99. data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +285 -0
  100. data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
  101. data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
  102. data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +361 -0
  103. data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +145 -0
  104. data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
  105. data/ext/libmemcached-0.32/libmemcached/memcached_do.c +34 -0
  106. data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
  107. data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
  108. data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
  109. data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +22 -0
  110. data/ext/libmemcached-0.32/libmemcached/memcached_get.c +495 -0
  111. data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
  112. data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
  113. data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
  114. data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
  115. data/ext/libmemcached-0.32/libmemcached/memcached_io.c +547 -0
  116. data/ext/libmemcached-0.32/libmemcached/memcached_io.h +59 -0
  117. data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
  118. data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
  119. data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
  120. data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
  121. data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
  122. data/ext/libmemcached-0.32/libmemcached/memcached_response.c +528 -0
  123. data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
  124. data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
  125. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
  126. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
  127. data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
  128. data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
  129. data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +454 -0
  130. data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
  131. data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
  132. data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
  133. data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
  134. data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
  135. data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
  136. data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
  137. data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
  138. data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
  139. data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
  140. data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
  141. data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
  142. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
  143. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +602 -0
  144. data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
  145. data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
  146. data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
  147. data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
  148. data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
  149. data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
  150. data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
  151. data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
  152. data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
  153. data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
  154. data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
  155. data/ext/libmemcached-0.32/m4/libtool.m4 +7360 -0
  156. data/ext/libmemcached-0.32/m4/ltoptions.m4 +368 -0
  157. data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
  158. data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
  159. data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +92 -0
  160. data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
  161. data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
  162. data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
  163. data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
  164. data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
  165. data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
  166. data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
  167. data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
  168. data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
  169. data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
  170. data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
  171. data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
  172. data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
  173. data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
  174. data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
  175. data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
  176. data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
  177. data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
  178. data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
  179. data/ext/libmemcached-0.32/support/Makefile.am +4 -0
  180. data/ext/libmemcached-0.32/support/Makefile.in +485 -0
  181. data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
  182. data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
  183. data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
  184. data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
  185. data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
  186. data/ext/libmemcached-0.32/tests/Makefile.am +105 -0
  187. data/ext/libmemcached-0.32/tests/Makefile.in +748 -0
  188. data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
  189. data/ext/libmemcached-0.32/tests/function.c +4781 -0
  190. data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
  191. data/ext/libmemcached-0.32/tests/output.cmp +7 -0
  192. data/ext/libmemcached-0.32/tests/output.res +7 -0
  193. data/ext/libmemcached-0.32/tests/output2.res +46 -0
  194. data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
  195. data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
  196. data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
  197. data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
  198. data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
  199. data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
  200. data/ext/libmemcached-0.32/tests/server.c +118 -0
  201. data/ext/libmemcached-0.32/tests/server.h +25 -0
  202. data/ext/libmemcached-0.32/tests/start.c +16 -0
  203. data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
  204. data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
  205. data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
  206. data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
  207. data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
  208. data/ext/libmemcached-0.32/tests/test.c +137 -0
  209. data/ext/libmemcached-0.32/tests/test.h +46 -0
  210. data/ext/libmemcached-0.32/tests/udp.c +76 -0
  211. data/memcached.gemspec +4 -4
  212. data/test/unit/memcached_test.rb +30 -0
  213. metadata +213 -16
  214. data/ext/libmemcached-0.32.tar.gz +0 -0
  215. data/ext/libmemcached-1.patch +0 -270
  216. data/ext/libmemcached-10.patch +0 -12
  217. data/ext/libmemcached-2.patch +0 -116
  218. data/ext/libmemcached-3.patch +0 -8
  219. data/ext/libmemcached-4.patch +0 -40
  220. data/ext/libmemcached-5.patch +0 -832
  221. data/ext/libmemcached-6.patch +0 -20
  222. data/ext/libmemcached-7.patch +0 -2989
  223. data/ext/libmemcached-8.patch +0 -137
  224. data/ext/libmemcached-9.patch +0 -13
  225. data/ext/sasl.patch +0 -29283
@@ -0,0 +1,57 @@
1
+ /*
2
+ memcached_result_st are used to internally represent the return values from
3
+ memcached. We use a structure so that long term as identifiers are added
4
+ to memcached we will be able to absorb new attributes without having
5
+ to addjust the entire API.
6
+ */
7
+ #include "common.h"
8
+
9
+ memcached_result_st *memcached_result_create(memcached_st *memc,
10
+ memcached_result_st *ptr)
11
+ {
12
+ /* Saving malloc calls :) */
13
+ if (ptr)
14
+ memset(ptr, 0, sizeof(memcached_result_st));
15
+ else
16
+ {
17
+ ptr= memc->call_malloc(memc, sizeof(memcached_result_st));
18
+
19
+ if (ptr == NULL)
20
+ return NULL;
21
+ ptr->is_allocated= true;
22
+ }
23
+
24
+ ptr->root= memc;
25
+ memcached_string_create(memc, &ptr->value, 0);
26
+ WATCHPOINT_ASSERT(ptr->value.string == NULL);
27
+
28
+ return ptr;
29
+ }
30
+
31
+ void memcached_result_reset(memcached_result_st *ptr)
32
+ {
33
+ ptr->key_length= 0;
34
+ memcached_string_reset(&ptr->value);
35
+ ptr->flags= 0;
36
+ ptr->cas= 0;
37
+ ptr->expiration= 0;
38
+ }
39
+
40
+ /*
41
+ NOTE turn into macro
42
+ */
43
+ memcached_return memcached_result_set_value(memcached_result_st *ptr, const char *value, size_t length)
44
+ {
45
+ return memcached_string_append(&ptr->value, value, length);
46
+ }
47
+
48
+ void memcached_result_free(memcached_result_st *ptr)
49
+ {
50
+ if (ptr == NULL)
51
+ return;
52
+
53
+ memcached_string_free(&ptr->value);
54
+
55
+ if (ptr->is_allocated)
56
+ free(ptr);
57
+ }
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Summary: Result structure used for libmemcached.
3
+ *
4
+ * Copy: See Copyright for the status of this software.
5
+ *
6
+ * Author: Brian Aker
7
+ */
8
+
9
+ #ifndef __MEMCACHED_RESULT_H__
10
+ #define __MEMCACHED_RESULT_H__
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ struct memcached_result_st {
17
+ uint32_t flags;
18
+ bool is_allocated;
19
+ time_t expiration;
20
+ memcached_st *root;
21
+ size_t key_length;
22
+ uint64_t cas;
23
+ memcached_string_st value;
24
+ char key[MEMCACHED_MAX_KEY];
25
+ /* Add result callback function */
26
+ };
27
+
28
+ /* Result Struct */
29
+ LIBMEMCACHED_API
30
+ void memcached_result_free(memcached_result_st *result);
31
+ LIBMEMCACHED_API
32
+ void memcached_result_reset(memcached_result_st *ptr);
33
+ LIBMEMCACHED_API
34
+ memcached_result_st *memcached_result_create(memcached_st *ptr,
35
+ memcached_result_st *result);
36
+ #define memcached_result_key_value(A) (A)->key
37
+ #define memcached_result_key_length(A) (A)->key_length
38
+ #define memcached_result_string_st(A) ((A)->value)
39
+ #ifdef FIX
40
+ #define memcached_result_value(A) memcached_string_value((A)->value)
41
+ #define memcached_result_length(A) memcached_string_length((A)->value)
42
+ #else
43
+ LIBMEMCACHED_API
44
+ char *memcached_result_value(memcached_result_st *ptr);
45
+ LIBMEMCACHED_API
46
+ size_t memcached_result_length(memcached_result_st *ptr);
47
+ #endif
48
+ #define memcached_result_flags(A) (A)->flags
49
+ #define memcached_result_cas(A) (A)->cas
50
+ LIBMEMCACHED_API
51
+ memcached_return memcached_result_set_value(memcached_result_st *ptr, const char *value, size_t length);
52
+ #define memcached_result_set_flags(A,B) (A)->flags=(B)
53
+ #define memcached_result_set_expiration(A,B) (A)->expiration=(B)
54
+
55
+ #ifdef __cplusplus
56
+ }
57
+ #endif
58
+
59
+ #endif /* __MEMCACHED_RESULT_H__ */
@@ -0,0 +1,225 @@
1
+ #include "common.h"
2
+
3
+ void memcached_set_sasl_callbacks(memcached_st *ptr,
4
+ const sasl_callback_t *callbacks)
5
+ {
6
+ ptr->sasl_callbacks= callbacks;
7
+ }
8
+
9
+ const sasl_callback_t *memcached_get_sasl_callbacks(memcached_st *ptr)
10
+ {
11
+ return ptr->sasl_callbacks;
12
+ }
13
+
14
+ /**
15
+ * Resolve the names for both ends of a connection
16
+ * @param fd socket to check
17
+ * @param laddr local address (out)
18
+ * @param raddr remote address (out)
19
+ * @return true on success false otherwise (errno contains more info)
20
+ */
21
+ static bool resolve_names(int fd, char *laddr, char *raddr)
22
+ {
23
+ char host[NI_MAXHOST];
24
+ char port[NI_MAXSERV];
25
+ struct sockaddr_storage saddr;
26
+ socklen_t salen= sizeof(saddr);
27
+
28
+ if ((getsockname(fd, (struct sockaddr *)&saddr, &salen) < 0) ||
29
+ (getnameinfo((struct sockaddr *)&saddr, salen, host, sizeof(host),
30
+ port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV) < 0))
31
+ return false;
32
+
33
+ (void)sprintf(laddr, "%s;%s", host, port);
34
+ salen= sizeof(saddr);
35
+
36
+ if ((getpeername(fd, (struct sockaddr *)&saddr, &salen) < 0) ||
37
+ (getnameinfo((struct sockaddr *)&saddr, salen, host, sizeof(host),
38
+ port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV) < 0))
39
+ return false;
40
+
41
+ (void)sprintf(raddr, "%s;%s", host, port);
42
+
43
+ return true;
44
+ }
45
+
46
+ memcached_return memcached_sasl_authenticate_connection(memcached_server_st *server)
47
+ {
48
+ memcached_return rc;
49
+
50
+ /* SANITY CHECK: SASL can only be used with the binary protocol */
51
+ unlikely ((server->root->flags & MEM_BINARY_PROTOCOL) == 0)
52
+ return MEMCACHED_FAILURE;
53
+
54
+ /* Try to get the supported mech from the server. Servers without SASL
55
+ * support will return UNKNOWN COMMAND, so we can just treat that
56
+ * as authenticated
57
+ */
58
+ protocol_binary_request_no_extras request= {
59
+ .message.header.request= {
60
+ .magic= PROTOCOL_BINARY_REQ,
61
+ .opcode= PROTOCOL_BINARY_CMD_SASL_LIST_MECHS
62
+ }
63
+ };
64
+
65
+ if (memcached_io_write(server, request.bytes,
66
+ sizeof(request.bytes), 1) != sizeof(request.bytes))
67
+ return MEMCACHED_WRITE_FAILURE;
68
+
69
+ memcached_server_response_increment(server);
70
+
71
+ char mech[MEMCACHED_MAX_BUFFER];
72
+ rc= memcached_response(server, mech, sizeof(mech), NULL);
73
+ if (rc != MEMCACHED_SUCCESS)
74
+ {
75
+ if (rc == MEMCACHED_PROTOCOL_ERROR)
76
+ rc= MEMCACHED_SUCCESS;
77
+
78
+ return rc;
79
+ }
80
+
81
+ /* set ip addresses */
82
+ char laddr[NI_MAXHOST + NI_MAXSERV];
83
+ char raddr[NI_MAXHOST + NI_MAXSERV];
84
+
85
+ unlikely (!resolve_names(server->fd, laddr, raddr))
86
+ {
87
+ server->cached_errno= errno;
88
+ return MEMCACHED_ERRNO;
89
+ }
90
+
91
+ sasl_conn_t *conn;
92
+ int ret= sasl_client_new("memcached", server->hostname, laddr, raddr,
93
+ server->root->sasl_callbacks, 0, &conn);
94
+ if (ret != SASL_OK)
95
+ return MEMCACHED_AUTH_PROBLEM;
96
+
97
+ const char *data;
98
+ const char *chosenmech;
99
+ unsigned int len;
100
+ ret= sasl_client_start(conn, mech, NULL, &data, &len, &chosenmech);
101
+
102
+ if (ret != SASL_OK && ret != SASL_CONTINUE)
103
+ {
104
+ rc= MEMCACHED_AUTH_PROBLEM;
105
+ goto end;
106
+ }
107
+
108
+ uint16_t keylen= (uint16_t)strlen(chosenmech);
109
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SASL_AUTH;
110
+ request.message.header.request.keylen= htons(keylen);
111
+ request.message.header.request.bodylen= htonl(len + keylen);
112
+
113
+ do {
114
+ /* send the packet */
115
+ if (memcached_io_write(server, request.bytes,
116
+ sizeof(request.bytes), 0) != sizeof(request.bytes) ||
117
+ memcached_io_write(server, chosenmech, keylen, 0) != keylen ||
118
+ memcached_io_write(server, data, len, 1) != (int)len)
119
+ {
120
+ rc= MEMCACHED_WRITE_FAILURE;
121
+ goto end;
122
+ }
123
+ memcached_server_response_increment(server);
124
+
125
+ /* read the response */
126
+ rc= memcached_response(server, NULL, 0, NULL);
127
+ if (rc != MEMCACHED_AUTH_CONTINUE)
128
+ goto end;
129
+
130
+ ret= sasl_client_step(conn, memcached_result_value(&server->root->result),
131
+ (unsigned int)memcached_result_length(&server->root->result),
132
+ NULL, &data, &len);
133
+
134
+ if (ret != SASL_OK && ret != SASL_CONTINUE)
135
+ {
136
+ rc= MEMCACHED_AUTH_PROBLEM;
137
+ goto end;
138
+ }
139
+
140
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SASL_STEP;
141
+ request.message.header.request.bodylen= htonl(len + keylen);
142
+ } while (true);
143
+
144
+ end:
145
+ /* Release resources */
146
+ sasl_dispose(&conn);
147
+
148
+ return rc;
149
+ }
150
+
151
+ static int get_username(void *context, int id, const char **result,
152
+ unsigned int *len)
153
+ {
154
+ if (!context || !result || (id != SASL_CB_USER && id != SASL_CB_AUTHNAME))
155
+ return SASL_BADPARAM;
156
+
157
+ *result= context;
158
+ if (len)
159
+ *len= (unsigned int)strlen(*result);
160
+
161
+ return SASL_OK;
162
+ }
163
+
164
+ static int get_password(sasl_conn_t *conn, void *context, int id,
165
+ sasl_secret_t **psecret)
166
+ {
167
+ if (!conn || ! psecret || id != SASL_CB_PASS)
168
+ return SASL_BADPARAM;
169
+
170
+ *psecret= context;
171
+
172
+ return SASL_OK;
173
+ }
174
+
175
+ memcached_return memcached_set_sasl_auth_data(memcached_st *ptr,
176
+ const char *username,
177
+ const char *password)
178
+ {
179
+ if (ptr == NULL || username == NULL ||
180
+ password == NULL || ptr->sasl_callbacks != NULL)
181
+ return MEMCACHED_FAILURE;
182
+
183
+ sasl_callback_t *cb= ptr->call_calloc(ptr, 4, sizeof(sasl_callback_t));
184
+ char *name= ptr->call_malloc(ptr, strlen(username) + 1);
185
+ sasl_secret_t *secret= ptr->call_malloc(ptr, strlen(password) + 1 + sizeof(*secret))
186
+ ;
187
+ if (cb == NULL || name == NULL || secret == NULL)
188
+ {
189
+ ptr->call_free(ptr, cb);
190
+ ptr->call_free(ptr, name);
191
+ ptr->call_free(ptr, secret);
192
+ return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
193
+ }
194
+
195
+ secret->len= strlen(password);
196
+ strcpy((void*)secret->data, password);
197
+
198
+ cb[0].id= SASL_CB_USER;
199
+ cb[0].proc= get_username;
200
+ cb[0].context= strcpy(name, username);
201
+ cb[1].id= SASL_CB_AUTHNAME;
202
+ cb[1].proc= get_username;
203
+ cb[1].context= name;
204
+ cb[2].id= SASL_CB_PASS;
205
+ cb[2].proc= get_password;
206
+ cb[2].context= secret;
207
+ cb[3].id= SASL_CB_LIST_END;
208
+
209
+ memcached_set_sasl_callbacks(ptr, cb);
210
+
211
+ return MEMCACHED_SUCCESS;
212
+ }
213
+
214
+ memcached_return memcached_destroy_sasl_auth_data(memcached_st *ptr)
215
+ {
216
+ if (ptr == NULL || ptr->sasl_callbacks == NULL)
217
+ return MEMCACHED_FAILURE;
218
+
219
+ ptr->call_free(ptr, ptr->sasl_callbacks[0].context);
220
+ ptr->call_free(ptr, ptr->sasl_callbacks[2].context);
221
+ ptr->call_free(ptr, (void*)ptr->sasl_callbacks);
222
+ ptr->sasl_callbacks= NULL;
223
+
224
+ return MEMCACHED_SUCCESS;
225
+ }
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Summary: SASL support for memcached
3
+ *
4
+ * Copy: See Copyright for the status of this software.
5
+ *
6
+ * Author: Trond Norbye
7
+ */
8
+
9
+ #ifndef LIBMEMCACHED_MEMCACHED_SASL_H
10
+ #define LIBMEMCACHED_MEMCACHED_SASL_H
11
+
12
+ #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
13
+ #include <sasl/sasl.h>
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
19
+ LIBMEMCACHED_API
20
+ void memcached_set_sasl_callbacks(memcached_st *ptr,
21
+ const sasl_callback_t *callbacks);
22
+
23
+ LIBMEMCACHED_API
24
+ memcached_return memcached_set_sasl_auth_data(memcached_st *ptr,
25
+ const char *username,
26
+ const char *password);
27
+
28
+ LIBMEMCACHED_API
29
+ memcached_return memcached_destroy_sasl_auth_data(memcached_st *ptr);
30
+
31
+
32
+ LIBMEMCACHED_API
33
+ const sasl_callback_t *memcached_get_sasl_callbacks(memcached_st *ptr);
34
+
35
+ LIBMEMCACHED_LOCAL
36
+ memcached_return memcached_sasl_authenticate_connection(memcached_server_st *server);
37
+
38
+ #ifdef __cplusplus
39
+ }
40
+ #endif
41
+
42
+ #endif /* LIBMEMCACHED_WITH_SASL_SUPPORT */
43
+
44
+ #endif /* LIBMEMCACHED_MEMCACHED_SASL_H */
@@ -0,0 +1,159 @@
1
+ /*
2
+ This is a partial implementation for fetching/creating memcached_server_st objects.
3
+ */
4
+ #include "common.h"
5
+
6
+ memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr)
7
+ {
8
+ if (ptr == NULL)
9
+ {
10
+ ptr= (memcached_server_st *)calloc(1, sizeof(memcached_server_st));
11
+
12
+ if (!ptr)
13
+ return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
14
+
15
+ ptr->is_allocated= true;
16
+ }
17
+ else
18
+ memset(ptr, 0, sizeof(memcached_server_st));
19
+
20
+ ptr->root= memc;
21
+
22
+ return ptr;
23
+ }
24
+
25
+ memcached_server_st *memcached_server_create_with(memcached_st *memc, memcached_server_st *host,
26
+ const char *hostname, unsigned int port,
27
+ uint32_t weight, memcached_connection type)
28
+ {
29
+ host= memcached_server_create(memc, host);
30
+
31
+ if (host == NULL)
32
+ return NULL;
33
+
34
+ strncpy(host->hostname, hostname, MEMCACHED_MAX_HOST_LENGTH - 1);
35
+ host->root= memc ? memc : NULL;
36
+ host->port= port;
37
+ host->weight= weight;
38
+ host->fd= -1;
39
+ host->type= type;
40
+ host->read_ptr= host->read_buffer;
41
+ if (memc)
42
+ host->next_retry= memc->retry_timeout;
43
+ if (type == MEMCACHED_CONNECTION_UDP)
44
+ {
45
+ host->write_buffer_offset= UDP_DATAGRAM_HEADER_LENGTH;
46
+ memcached_io_init_udp_header(host, 0);
47
+ }
48
+
49
+ return host;
50
+ }
51
+
52
+ void memcached_server_free(memcached_server_st *ptr)
53
+ {
54
+ memcached_quit_server(ptr, 0);
55
+ memcached_server_error_reset(ptr);
56
+
57
+ if (ptr->address_info)
58
+ freeaddrinfo(ptr->address_info);
59
+
60
+ if (ptr->is_allocated)
61
+ ptr->root->call_free(ptr->root, ptr);
62
+ else
63
+ memset(ptr, 0, sizeof(memcached_server_st));
64
+ }
65
+
66
+ /*
67
+ If we do not have a valid object to clone from, we toss an error.
68
+ */
69
+ memcached_server_st *memcached_server_clone(memcached_server_st *clone, memcached_server_st *ptr)
70
+ {
71
+ memcached_server_st *rv= NULL;
72
+
73
+ /* We just do a normal create if ptr is missing */
74
+ if (ptr == NULL)
75
+ return NULL;
76
+
77
+ rv = memcached_server_create_with(ptr->root, clone,
78
+ ptr->hostname, ptr->port, ptr->weight,
79
+ ptr->type);
80
+ if (rv != NULL)
81
+ {
82
+ rv->cached_errno= ptr->cached_errno;
83
+ if (ptr->cached_server_error) {
84
+ size_t err_len = strlen(ptr->cached_server_error) + 1;
85
+ rv->cached_server_error = malloc(err_len);
86
+ strncpy(rv->cached_server_error, ptr->cached_server_error, err_len);
87
+ }
88
+ }
89
+
90
+ return rv;
91
+
92
+ }
93
+
94
+ memcached_return memcached_server_cursor(memcached_st *ptr,
95
+ memcached_server_function *callback,
96
+ void *context,
97
+ unsigned int number_of_callbacks)
98
+ {
99
+ unsigned int y;
100
+
101
+ for (y= 0; y < ptr->number_of_hosts; y++)
102
+ {
103
+ unsigned int x;
104
+
105
+ for (x= 0; x < number_of_callbacks; x++)
106
+ {
107
+ unsigned int iferror;
108
+
109
+ iferror= (*callback[x])(ptr, &ptr->hosts[y], context);
110
+
111
+ if (iferror)
112
+ continue;
113
+ }
114
+ }
115
+
116
+ return MEMCACHED_SUCCESS;
117
+ }
118
+
119
+ memcached_server_st *memcached_server_by_key(memcached_st *ptr, const char *key, size_t key_length, memcached_return *error)
120
+ {
121
+ uint32_t server_key;
122
+
123
+ *error= memcached_validate_key_length(key_length,
124
+ ptr->flags & MEM_BINARY_PROTOCOL);
125
+ unlikely (*error != MEMCACHED_SUCCESS)
126
+ return NULL;
127
+
128
+ unlikely (ptr->number_of_hosts == 0)
129
+ {
130
+ *error= MEMCACHED_NO_SERVERS;
131
+ return NULL;
132
+ }
133
+
134
+ if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
135
+ {
136
+ *error= MEMCACHED_BAD_KEY_PROVIDED;
137
+ return NULL;
138
+ }
139
+
140
+ server_key= memcached_generate_hash(ptr, key, key_length);
141
+
142
+ return &ptr->hosts[server_key];
143
+ }
144
+
145
+ const char *memcached_server_error(memcached_server_st *ptr)
146
+ {
147
+ if (ptr->cached_server_error)
148
+ return ptr->cached_server_error;
149
+ else
150
+ return NULL;
151
+ }
152
+
153
+ void memcached_server_error_reset(memcached_server_st *ptr)
154
+ {
155
+ if (ptr->cached_server_error) {
156
+ free(ptr->cached_server_error);
157
+ ptr->cached_server_error = 0;
158
+ }
159
+ }