vinted-memcached 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/BENCHMARKS +142 -0
- data/CHANGELOG +176 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +45 -0
- data/LICENSE +184 -0
- data/Manifest +209 -0
- data/README.rdoc +124 -0
- data/Rakefile +134 -0
- data/TODO +1 -0
- data/ext/extconf-make.rb +25 -0
- data/ext/extconf.rb +78 -0
- data/ext/libmemcached-0.32/AUTHORS +7 -0
- data/ext/libmemcached-0.32/COPYING +32 -0
- data/ext/libmemcached-0.32/ChangeLog +303 -0
- data/ext/libmemcached-0.32/INSTALL +302 -0
- data/ext/libmemcached-0.32/Makefile.am +36 -0
- data/ext/libmemcached-0.32/Makefile.in +911 -0
- data/ext/libmemcached-0.32/NEWS +1 -0
- data/ext/libmemcached-0.32/README +33 -0
- data/ext/libmemcached-0.32/THANKS +14 -0
- data/ext/libmemcached-0.32/TODO +11 -0
- data/ext/libmemcached-0.32/aclocal.m4 +2108 -0
- data/ext/libmemcached-0.32/clients/Makefile.am +80 -0
- data/ext/libmemcached-0.32/clients/Makefile.in +773 -0
- data/ext/libmemcached-0.32/clients/client_options.h +32 -0
- data/ext/libmemcached-0.32/clients/execute.c +64 -0
- data/ext/libmemcached-0.32/clients/execute.h +5 -0
- data/ext/libmemcached-0.32/clients/generator.c +74 -0
- data/ext/libmemcached-0.32/clients/generator.h +20 -0
- data/ext/libmemcached-0.32/clients/memcat.c +178 -0
- data/ext/libmemcached-0.32/clients/memcp.c +251 -0
- data/ext/libmemcached-0.32/clients/memdump.c +170 -0
- data/ext/libmemcached-0.32/clients/memerror.c +80 -0
- data/ext/libmemcached-0.32/clients/memflush.c +143 -0
- data/ext/libmemcached-0.32/clients/memrm.c +160 -0
- data/ext/libmemcached-0.32/clients/memslap.c +441 -0
- data/ext/libmemcached-0.32/clients/memstat.c +326 -0
- data/ext/libmemcached-0.32/clients/utilities.c +207 -0
- data/ext/libmemcached-0.32/clients/utilities.h +41 -0
- data/ext/libmemcached-0.32/config/compile +143 -0
- data/ext/libmemcached-0.32/config/config.guess +1561 -0
- data/ext/libmemcached-0.32/config/config.rpath +666 -0
- data/ext/libmemcached-0.32/config/config.sub +1686 -0
- data/ext/libmemcached-0.32/config/depcomp +630 -0
- data/ext/libmemcached-0.32/config/install-sh +520 -0
- data/ext/libmemcached-0.32/config/ltmain.sh +9636 -0
- data/ext/libmemcached-0.32/config/missing +376 -0
- data/ext/libmemcached-0.32/config.h.in +254 -0
- data/ext/libmemcached-0.32/configure +23843 -0
- data/ext/libmemcached-0.32/configure.ac +120 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.am +111 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.in +1069 -0
- data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
- data/ext/libmemcached-0.32/libmemcached/common.h +189 -0
- data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
- data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
- data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +30 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +82 -0
- data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +385 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.c +153 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.h +305 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +290 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +371 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +146 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_do.c +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_exist.c +114 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_exist.h +20 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +23 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.c +494 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.c +594 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.h +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_response.c +529 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +437 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_touch.c +60 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_touch.h +31 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +604 -0
- data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
- data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
- data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
- data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
- data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
- data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
- data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
- data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
- data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
- data/ext/libmemcached-0.32/m4/libtool.m4 +7831 -0
- data/ext/libmemcached-0.32/m4/ltoptions.m4 +369 -0
- data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
- data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
- data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +98 -0
- data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
- data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
- data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
- data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
- data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
- data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
- data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
- data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
- data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
- data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
- data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
- data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
- data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
- data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
- data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
- data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
- data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
- data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
- data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
- data/ext/libmemcached-0.32/support/Makefile.am +4 -0
- data/ext/libmemcached-0.32/support/Makefile.in +487 -0
- data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
- data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
- data/ext/libmemcached-0.32/tests/Makefile.am +113 -0
- data/ext/libmemcached-0.32/tests/Makefile.in +762 -0
- data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
- data/ext/libmemcached-0.32/tests/function.c +4904 -0
- data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
- data/ext/libmemcached-0.32/tests/output.cmp +7 -0
- data/ext/libmemcached-0.32/tests/output.res +7 -0
- data/ext/libmemcached-0.32/tests/output2.res +46 -0
- data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
- data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
- data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
- data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
- data/ext/libmemcached-0.32/tests/server.c +118 -0
- data/ext/libmemcached-0.32/tests/server.h +25 -0
- data/ext/libmemcached-0.32/tests/start.c +16 -0
- data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
- data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
- data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
- data/ext/libmemcached-0.32/tests/test.c +137 -0
- data/ext/libmemcached-0.32/tests/test.h +46 -0
- data/ext/libmemcached-0.32/tests/udp.c +76 -0
- data/ext/rlibmemcached.i +258 -0
- data/ext/rlibmemcached_wrap.c +13917 -0
- data/lib/memcached/auth.rb +16 -0
- data/lib/memcached/behaviors.rb +78 -0
- data/lib/memcached/exceptions.rb +84 -0
- data/lib/memcached/experimental.rb +48 -0
- data/lib/memcached/marshal_codec.rb +10 -0
- data/lib/memcached/memcached.rb +732 -0
- data/lib/memcached/rails.rb +250 -0
- data/lib/memcached.rb +33 -0
- data/memcached.gemspec +0 -0
- data/test/profile/benchmark.rb +280 -0
- data/test/profile/c_profiler.rb +14 -0
- data/test/profile/exercise.rb +185 -0
- data/test/profile/rb_profiler.rb +21 -0
- data/test/profile/valgrind.rb +10 -0
- data/test/setup.rb +30 -0
- data/test/teardown.rb +0 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/binding_test.rb +8 -0
- data/test/unit/memcached_experimental_test.rb +272 -0
- data/test/unit/memcached_test.rb +1487 -0
- data/test/unit/rails_test.rb +330 -0
- metadata +336 -0
@@ -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
|
+
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/*
|
2
|
+
* Summary: String 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_SERVER_H__
|
10
|
+
#define __MEMCACHED_SERVER_H__
|
11
|
+
|
12
|
+
#ifdef __cplusplus
|
13
|
+
extern "C" {
|
14
|
+
#endif
|
15
|
+
|
16
|
+
struct memcached_server_st {
|
17
|
+
bool is_allocated;
|
18
|
+
bool sockaddr_inited;
|
19
|
+
uint16_t count;
|
20
|
+
unsigned int cursor_active;
|
21
|
+
unsigned int port;
|
22
|
+
int cached_errno;
|
23
|
+
int fd;
|
24
|
+
uint32_t io_bytes_sent; /* # bytes sent since last read */
|
25
|
+
uint32_t server_failure_counter;
|
26
|
+
uint32_t weight;
|
27
|
+
uint8_t major_version;
|
28
|
+
uint8_t micro_version;
|
29
|
+
uint8_t minor_version;
|
30
|
+
memcached_connection type;
|
31
|
+
char *read_ptr;
|
32
|
+
char *cached_server_error;
|
33
|
+
size_t read_buffer_length;
|
34
|
+
size_t read_data_length;
|
35
|
+
size_t write_buffer_offset;
|
36
|
+
struct addrinfo *address_info;
|
37
|
+
time_t next_retry;
|
38
|
+
memcached_st *root;
|
39
|
+
uint64_t limit_maxbytes;
|
40
|
+
char read_buffer[MEMCACHED_MAX_BUFFER];
|
41
|
+
char write_buffer[MEMCACHED_MAX_BUFFER];
|
42
|
+
char hostname[MEMCACHED_MAX_HOST_LENGTH];
|
43
|
+
};
|
44
|
+
|
45
|
+
#define memcached_server_count(A) (A)->number_of_hosts
|
46
|
+
#define memcached_server_name(A,B) (B).hostname
|
47
|
+
#define memcached_server_port(A,B) (B).port
|
48
|
+
#define memcached_server_list(A) (A)->hosts
|
49
|
+
#define memcached_server_response_count(A) (A)->cursor_active
|
50
|
+
|
51
|
+
LIBMEMCACHED_API
|
52
|
+
memcached_return memcached_server_cursor(memcached_st *ptr,
|
53
|
+
memcached_server_function *callback,
|
54
|
+
void *context,
|
55
|
+
unsigned int number_of_callbacks);
|
56
|
+
|
57
|
+
LIBMEMCACHED_API
|
58
|
+
memcached_server_st *memcached_server_by_key(memcached_st *ptr, const char *key,
|
59
|
+
size_t key_length, memcached_return *error);
|
60
|
+
|
61
|
+
LIBMEMCACHED_API
|
62
|
+
const char *memcached_server_error(memcached_server_st *ptr);
|
63
|
+
|
64
|
+
LIBMEMCACHED_API
|
65
|
+
void memcached_server_error_reset(memcached_server_st *ptr);
|
66
|
+
|
67
|
+
/* These should not currently be used by end users */
|
68
|
+
/* TODO: Is the above comment valid? If so, how can we unit test these if they
|
69
|
+
* aren't exported. If not, we should remove the comment */
|
70
|
+
LIBMEMCACHED_API
|
71
|
+
memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr);
|
72
|
+
|
73
|
+
LIBMEMCACHED_API
|
74
|
+
memcached_server_st *memcached_server_create_with(memcached_st *memc, memcached_server_st *host,
|
75
|
+
const char *hostname, unsigned int port,
|
76
|
+
uint32_t weight, memcached_connection type);
|
77
|
+
|
78
|
+
LIBMEMCACHED_API
|
79
|
+
void memcached_server_free(memcached_server_st *ptr);
|
80
|
+
LIBMEMCACHED_API
|
81
|
+
memcached_server_st *memcached_server_clone(memcached_server_st *clone, memcached_server_st *ptr);
|
82
|
+
LIBMEMCACHED_API
|
83
|
+
memcached_analysis_st *memcached_analyze(memcached_st *memc, memcached_stat_st *memc_stat,
|
84
|
+
memcached_return *error);
|
85
|
+
|
86
|
+
LIBMEMCACHED_API
|
87
|
+
memcached_return memcached_server_remove(memcached_server_st *st_ptr);
|
88
|
+
|
89
|
+
#ifdef __cplusplus
|
90
|
+
}
|
91
|
+
#endif
|
92
|
+
|
93
|
+
#endif /* __MEMCACHED_SERVER_H__ */
|