com pecl/caching/memcache: refactor sasl, fix stupid test code with static user (prev commit), rename setSaslData to setSaslAuthData to match other
interfaces: config.w32 memcache.c memcache_binary_protocol .c memcache_pool.c php_memcache.h
| From: | Pierre Joye | Date: | Tue, 05 Nov 2013 17:39:23 +0000 |
| Subject: | com pecl/caching/memcache: refactor sasl, fix stupid test code with static user (prev commit), rename setSaslData to setSaslAuthData to match other interfaces: config.w32 memcache.c memcache_binary_protocol .c memcache_pool.c php_memcache.h |
||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-19975@lists.php.net to get a copy of this message | ||
Commit: 890d7be4c141ac798e0cd8c5ab39ea0de42cff29
Author: Pierre Joye <pierre.php@gmail.com> Tue, 5 Nov 2013 18:39:23 +0100
Parents: 0ea871e6fb767b003c060e560803e21c9a8d25e0
Branches: NON_BLOCKING_IO
Link: http://git.php.net/?p=pecl/caching/memcache.git;a=commitdiff;h=890d7be4c141ac798e0cd8c5ab39ea0de42cff29
Log:
refactor sasl, fix stupid test code with static user (prev commit), rename setSaslData to
setSaslAuthData to match other interfaces
Changed paths:
M config.w32
M memcache.c
M memcache_binary_protocol.c
M memcache_pool.c
M php_memcache.h
Diff:
diff --git a/config.w32 b/config.w32
index f2cf3eb..6915115 100644
--- a/config.w32
+++ b/config.w32
@@ -4,7 +4,7 @@
ARG_ENABLE("memcache", "memcache support", "no");
if (PHP_MEMCACHE != "no") {
- if (!PHP_ZLIB_SHARED || CHECK_LIB("zlib.lib", "memcache", PHP_MEMCACHE)) {
+ if (!PHP_ZLIB_SHARED || CHECK_LIB("zlib_a.lib", "memcache", PHP_MEMCACHE)) {
EXTENSION("memcache", " \
memcache.c \
memcache_ascii_protocol.c \
diff --git a/memcache.c b/memcache.c
index fe09b06..7569a63 100644
--- a/memcache.c
+++ b/memcache.c
@@ -93,7 +93,7 @@ static zend_function_entry php_memcache_pool_class_functions[] = {
PHP_FALIAS(decrement, memcache_decrement, NULL)
PHP_FALIAS(close, memcache_close, NULL)
PHP_FALIAS(flush, memcache_flush, NULL)
- PHP_FALIAS(setSaslAuthData, memcache_set_sasl_data, NULL)
+ PHP_FALIAS(setSaslAuthData, memcache_set_sasl_auth_data, NULL)
{NULL, NULL, NULL}
};
@@ -792,9 +792,6 @@ static mmc_t *php_mmc_pool_addserver(
pool->failure_callback = &php_mmc_failure_callback;
list_id = MEMCACHE_LIST_INSERT(pool, le_memcache_pool);
add_property_resource(mmc_object, "connection", list_id);
-
- zend_declare_property_null(memcache_pool_ce, "username", strlen("username"),
ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(memcache_pool_ce, "password", strlen("password"),
ZEND_ACC_PUBLIC TSRMLS_CC);
}
else {
pool = (mmc_pool_t *)zend_list_find(Z_LVAL_PP(connection), &resource_type);
@@ -830,6 +827,26 @@ static mmc_t *php_mmc_pool_addserver(
*pool_result = pool;
}
+ if (pool->protocol == &mmc_binary_protocol) {
+ zval *username = zend_read_property(memcache_ce, mmc_object, "username",
strlen("username"), 1 TSRMLS_CC);
+ zval *password = zend_read_property(memcache_ce, mmc_object, "password",
strlen("password"), 1 TSRMLS_CC);
+ if (Z_TYPE_P(username) == IS_STRING && Z_TYPE_P(password) == IS_STRING) {
+ if (Z_STRLEN_P(username) > 1 && Z_STRLEN_P(password) > 1) {
+ mmc_request_t *request;
+ zval sasl_value;
+
+ /* allocate request */
+ request = mmc_pool_request(pool, MMC_PROTO_TCP, mmc_stored_handler, &sasl_value,
mmc_pool_failover_handler, NULL TSRMLS_CC);
+ pool->protocol->set_sasl_auth_data(pool, request, Z_STRVAL_P(username),
Z_STRVAL_P(password) TSRMLS_CC);
+
+ /* schedule request */
+ if (mmc_pool_schedule_key(pool, request->key, request->key_len, request,
MEMCACHE_G(redundancy) TSRMLS_CC) != MMC_OK) {
+ return NULL;
+ }
+ }
+ }
+ }
+
return mmc;
}
/* }}} */
@@ -839,7 +856,6 @@ static void php_mmc_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool persistent)
zval *mmc_object = getThis();
mmc_pool_t *pool;
mmc_t *mmc;
- zval *username, *password;
char *host;
int host_len;
long tcp_port = MEMCACHE_G(default_port);
@@ -848,7 +864,6 @@ static void php_mmc_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool persistent)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ld", &host, &host_len,
&tcp_port, &timeout) == FAILURE) {
return;
}
-
/* initialize pool and object if need be */
if (!mmc_object) {
int list_id;
@@ -858,8 +873,7 @@ static void php_mmc_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool persistent)
mmc_object = return_value;
object_init_ex(mmc_object, memcache_ce);
add_property_resource(mmc_object, "connection", list_id);
- }
- else {
+ } else {
RETVAL_TRUE;
}
@@ -882,26 +896,6 @@ static void php_mmc_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool persistent)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't connect to %s:%d, %s (%d)",
host, mmc->tcp.port, mmc->error ? mmc->error : "Unknown error", mmc->errnum);
RETURN_FALSE;
}
-
- if (pool->protocol == &mmc_binary_protocol) {
- username = zend_read_property(memcache_ce, mmc_object, "username",
strlen("username"), 1 TSRMLS_CC);
- password = zend_read_property(memcache_ce, mmc_object, "password",
strlen("password"), 1 TSRMLS_CC);
-
- if (Z_TYPE_P(username) == IS_STRING && Z_TYPE_P(password) == IS_STRING) {
- mmc_request_t *request;
-
- /* allocate request */
- request = mmc_pool_request(pool, MMC_PROTO_TCP, mmc_stored_handler, return_value,
mmc_pool_failover_handler, NULL TSRMLS_CC);
- pool->protocol->set_sasl_auth_data(pool, request, Z_STRVAL_P(username),
Z_STRVAL_P(password) TSRMLS_CC);
-
- /* schedule request */
- if (mmc_pool_schedule_key(pool, request->key, request->key_len, request,
MEMCACHE_G(redundancy) TSRMLS_CC) != MMC_OK) {
- RETURN_FALSE;
- }
-
- mmc_pool_select(pool TSRMLS_CC);
- }
- }
}
/* }}} */
diff --git a/memcache_binary_protocol.c b/memcache_binary_protocol.c
index 0bf57b3..fc21357 100644
--- a/memcache_binary_protocol.c
+++ b/memcache_binary_protocol.c
@@ -717,7 +717,6 @@ static void mmc_set_sasl_auth_data(mmc_pool_t *pool, mmc_request_t *request, con
int status, prevlen, valuelen;
mmc_sasl_request_header *header;
mmc_binary_request_t *req = (mmc_binary_request_t *)request;
- zval *sasl_data;
unsigned int flags = 0;
request->parse = mmc_request_parse_response;
@@ -749,10 +748,12 @@ static void mmc_set_sasl_auth_data(mmc_pool_t *pool, mmc_request_t *request,
con
header->base.cas = 0x0;
smart_str_appendl(&(request->sendbuf.value), "\0", 1);
- smart_str_appendl(&(request->sendbuf.value), "phpuser",
strlen("phpuser"));
+ smart_str_appendl(&(request->sendbuf.value), user, strlen(user));
smart_str_appendl(&(request->sendbuf.value), "\0", 1);
- smart_str_appendl(&(request->sendbuf.value), "123456",
strlen("123456"));
-
+ smart_str_appendl(&(request->sendbuf.value), password, strlen(password));
+#if MMC_DEBUG
+ mmc_binary_hexdump(request->sendbuf.value.c, request->sendbuf.value.len);
+#endif
return;
}
/* }}} */
diff --git a/memcache_pool.c b/memcache_pool.c
index 694dec9..17f5f54 100644
--- a/memcache_pool.c
+++ b/memcache_pool.c
@@ -988,6 +988,7 @@ int mmc_pool_open(mmc_pool_t *pool, mmc_t *mmc, mmc_stream_t *io, int udp TSRMLS
case MMC_STATUS_DISCONNECTED:
case MMC_STATUS_FAILED:
+
return mmc_server_connect(pool, mmc, io, udp TSRMLS_CC);
}
diff --git a/php_memcache.h b/php_memcache.h
index 1c96958..92f0d6b 100644
--- a/php_memcache.h
+++ b/php_memcache.h
@@ -64,7 +64,7 @@ PHP_FUNCTION(memcache_increment);
PHP_FUNCTION(memcache_decrement);
PHP_FUNCTION(memcache_close);
PHP_FUNCTION(memcache_flush);
-PHP_FUNCTION(memcache_set_sasl_data);
+PHP_FUNCTION(memcache_set_sasl_auth_data);
#define PHP_MEMCACHE_VERSION "3.0.9-dev"