diff options
author | Dmitry Stogov <dmitry@zend.com> | 2014-05-15 02:44:47 +0400 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2014-05-15 02:44:47 +0400 |
commit | c446e575880d503921a795ee7cc4126b8b84457b (patch) | |
tree | f77308734e3f0ae024c5900a852e10b2138e72d0 /ext/soap/php_http.c | |
parent | 3ae86b9cce0df92069d971feef2af526cdabf7f5 (diff) | |
download | php-git-c446e575880d503921a795ee7cc4126b8b84457b.tar.gz |
ext/soap support for phpng (incomplete - just compilable)
Diffstat (limited to 'ext/soap/php_http.c')
-rw-r--r-- | ext/soap/php_http.c | 486 |
1 files changed, 239 insertions, 247 deletions
diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index f3abe680c9..a9eb2ae719 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -34,24 +34,23 @@ static int get_http_headers(php_stream *socketd,char **response, int *out_size T /* Proxy HTTP Authentication */ int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) { - zval **login, **password; + zval *login, *password; - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_login", sizeof("_proxy_login"), (void **)&login) == SUCCESS) { - unsigned char* buf; - int len; + if ((login = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_proxy_login", sizeof("_proxy_login")-1)) != NULL) { + zend_string *buf; smart_str auth = {0}; - smart_str_appendl(&auth, Z_STRVAL_PP(login), Z_STRLEN_PP(login)); + smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRLEN_P(login)); smart_str_appendc(&auth, ':'); - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_password", sizeof("_proxy_password"), (void **)&password) == SUCCESS) { - smart_str_appendl(&auth, Z_STRVAL_PP(password), Z_STRLEN_PP(password)); + if ((password = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_proxy_password", sizeof("_proxy_password")-1)) != NULL) { + smart_str_appendl(&auth, Z_STRVAL_P(password), Z_STRLEN_P(password)); } smart_str_0(&auth); - buf = php_base64_encode((unsigned char*)auth.c, auth.len, &len); + buf = php_base64_encode((unsigned char*)auth.s->val, auth.s->len); smart_str_append_const(soap_headers, "Proxy-Authorization: Basic "); - smart_str_appendl(soap_headers, (char*)buf, len); + smart_str_appendl(soap_headers, (char*)buf->val, buf->len); smart_str_append_const(soap_headers, "\r\n"); - efree(buf); + STR_RELEASE(buf); smart_str_free(&auth); return 1; } @@ -61,25 +60,24 @@ int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) /* HTTP Authentication */ int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) { - zval **login, **password; + zval *login, *password; - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_login", sizeof("_login"), (void **)&login) == SUCCESS && - !zend_hash_exists(Z_OBJPROP_P(this_ptr), "_digest", sizeof("_digest"))) { - unsigned char* buf; - int len; + if ((login = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_login", sizeof("_login")-1)) != NULL && + !zend_hash_str_exists(Z_OBJPROP_P(this_ptr), "_digest", sizeof("_digest")-1)) { + zend_string* buf; smart_str auth = {0}; - smart_str_appendl(&auth, Z_STRVAL_PP(login), Z_STRLEN_PP(login)); + smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRLEN_P(login)); smart_str_appendc(&auth, ':'); - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password"), (void **)&password) == SUCCESS) { - smart_str_appendl(&auth, Z_STRVAL_PP(password), Z_STRLEN_PP(password)); + if ((password = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password")-1)) != NULL) { + smart_str_appendl(&auth, Z_STRVAL_P(password), Z_STRLEN_P(password)); } smart_str_0(&auth); - buf = php_base64_encode((unsigned char*)auth.c, auth.len, &len); + buf = php_base64_encode((unsigned char*)auth.s->val, auth.s->len); smart_str_append_const(soap_headers, "Authorization: Basic "); - smart_str_appendl(soap_headers, (char*)buf, len); + smart_str_appendl(soap_headers, (char*)buf->val, buf->len); smart_str_append_const(soap_headers, "\r\n"); - efree(buf); + STR_RELEASE(buf); smart_str_free(&auth); return 1; } @@ -93,12 +91,12 @@ void http_context_headers(php_stream_context* context, zend_bool has_cookies, smart_str* soap_headers TSRMLS_DC) { - zval **tmp; + zval *tmp; if (context && - php_stream_context_get_option(context, "http", "header", &tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING && Z_STRLEN_PP(tmp)) { - char *s = Z_STRVAL_PP(tmp); + (tmp = php_stream_context_get_option(context, "http", "header")) != NULL && + Z_TYPE_P(tmp) == IS_STRING && Z_STRLEN_P(tmp)) { + char *s = Z_STRVAL_P(tmp); char *p; int name_len; @@ -159,7 +157,7 @@ void http_context_headers(php_stream_context* context, static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, php_stream_context *context, int *use_proxy TSRMLS_DC) { php_stream *stream; - zval **proxy_host, **proxy_port, **tmp; + zval *proxy_host, *proxy_port, *tmp; char *host; char *name; char *protocol; @@ -169,20 +167,20 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph struct timeval tv; struct timeval *timeout = NULL; - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_host", sizeof("_proxy_host"), (void **) &proxy_host) == SUCCESS && - Z_TYPE_PP(proxy_host) == IS_STRING && - zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_port", sizeof("_proxy_port"), (void **) &proxy_port) == SUCCESS && - Z_TYPE_PP(proxy_port) == IS_LONG) { - host = Z_STRVAL_PP(proxy_host); - port = Z_LVAL_PP(proxy_port); + if ((proxy_host = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_proxy_host", sizeof("_proxy_host")-1)) != NULL && + Z_TYPE_P(proxy_host) == IS_STRING && + (proxy_port = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_proxy_port", sizeof("_proxy_port")-1)) != NULL && + Z_TYPE_P(proxy_port) == IS_LONG) { + host = Z_STRVAL_P(proxy_host); + port = Z_LVAL_P(proxy_port); *use_proxy = 1; } else { host = phpurl->host; port = phpurl->port; } - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_connection_timeout", sizeof("_connection_timeout"), (void **) &tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_LONG && Z_LVAL_PP(tmp) > 0) { - tv.tv_sec = Z_LVAL_PP(tmp); + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_connection_timeout", sizeof("_connection_timeout")-1)) != NULL && + Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) > 0) { + tv.tv_sec = Z_LVAL_P(tmp); tv.tv_usec = 0; timeout = &tv; } @@ -192,10 +190,10 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph /* Changed ternary operator to an if/else so that additional comparisons can be done on the ssl_method property */ if (use_ssl && !*use_proxy) { - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_ssl_method", sizeof("_ssl_method"), (void **) &tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_LONG) { + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_ssl_method", sizeof("_ssl_method")-1)) != NULL && + Z_TYPE_P(tmp) == IS_LONG) { /* uses constants declared in soap.c to determine ssl uri protocol */ - switch (Z_LVAL_PP(tmp)) { + switch (Z_LVAL_P(tmp)) { case SOAP_SSL_METHOD_TLS: protocol = "tls"; break; @@ -255,7 +253,7 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph smart_str_append_const(&soap_headers, "\r\n"); proxy_authentication(this_ptr, &soap_headers TSRMLS_CC); smart_str_append_const(&soap_headers, "\r\n"); - if (php_stream_write(stream, soap_headers.c, soap_headers.len) != soap_headers.len) { + if (php_stream_write(stream, soap_headers.s->val, soap_headers.s->len) != soap_headers.s->len) { php_stream_close(stream); stream = NULL; } @@ -275,9 +273,9 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph /* if a stream is created without encryption, check to see if SSL method parameter is specified and use proper encrypyion method based on constants defined in soap.c */ int crypto_method = STREAM_CRYPTO_METHOD_SSLv23_CLIENT; - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_ssl_method", sizeof("_ssl_method"), (void **) &tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_LONG) { - switch (Z_LVAL_PP(tmp)) { + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_ssl_method", sizeof("_ssl_method")-1)) != NULL && + Z_TYPE_P(tmp) == IS_LONG) { + switch (Z_LVAL_P(tmp)) { case SOAP_SSL_METHOD_TLS: crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; break; @@ -332,8 +330,7 @@ int make_http_soap_request(zval *this_ptr, char *location, char *soapaction, int soap_version, - char **buffer, - int *buffer_len TSRMLS_DC) + zval *return_value TSRMLS_DC) { char *request; smart_str soap_headers = {0}; @@ -341,7 +338,7 @@ int make_http_soap_request(zval *this_ptr, int request_size, err; php_url *phpurl = NULL; php_stream *stream; - zval **trace, **tmp; + zval *trace, *tmp; int use_proxy = 0; int use_ssl; char *http_headers, *http_body, *content_type, *http_version, *cookie_itt; @@ -366,41 +363,37 @@ int make_http_soap_request(zval *this_ptr, request = buf; request_size = buf_size; /* Compress request */ - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "compression", sizeof("compression"), (void **)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_LONG) { - int level = Z_LVAL_PP(tmp) & 0x0f; - int kind = Z_LVAL_PP(tmp) & SOAP_COMPRESSION_DEFLATE; + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "compression", sizeof("compression")-1)) != NULL && Z_TYPE_P(tmp) == IS_LONG) { + int level = Z_LVAL_P(tmp) & 0x0f; + int kind = Z_LVAL_P(tmp) & SOAP_COMPRESSION_DEFLATE; if (level > 9) {level = 9;} - if ((Z_LVAL_PP(tmp) & SOAP_COMPRESSION_ACCEPT) != 0) { + if ((Z_LVAL_P(tmp) & SOAP_COMPRESSION_ACCEPT) != 0) { smart_str_append_const(&soap_headers_z,"Accept-Encoding: gzip, deflate\r\n"); } if (level > 0) { zval func; zval retval; - zval param1, param2, param3; - zval *params[3]; + zval params[3]; int n; - params[0] = ¶m1; - INIT_PZVAL(params[0]); - params[1] = ¶m2; - INIT_PZVAL(params[1]); - params[2] = ¶m3; - INIT_PZVAL(params[2]); - ZVAL_STRINGL(params[0], buf, buf_size, 0); - ZVAL_LONG(params[1], level); + //???ZVAL_STRINGL(params[0], buf, buf_size, 0); + ZVAL_STRINGL(¶ms[0], buf, buf_size); + ZVAL_LONG(¶ms[1], level); if (kind == SOAP_COMPRESSION_DEFLATE) { n = 2; - ZVAL_STRING(&func, "gzcompress", 0); + //???ZVAL_STRING(&func, "gzcompress", 0); + ZVAL_STRING(&func, "gzcompress"); smart_str_append_const(&soap_headers_z,"Content-Encoding: deflate\r\n"); } else { n = 3; - ZVAL_STRING(&func, "gzencode", 0); + //???ZVAL_STRING(&func, "gzencode", 0); + ZVAL_STRING(&func, "gzencode"); smart_str_append_const(&soap_headers_z,"Content-Encoding: gzip\r\n"); - ZVAL_LONG(params[2], 0x1f); + ZVAL_LONG(¶ms[2], 0x1f); } - if (call_user_function(CG(function_table), (zval**)NULL, &func, &retval, n, params TSRMLS_CC) == SUCCESS && + if (call_user_function(CG(function_table), (zval*)NULL, &func, &retval, n, params TSRMLS_CC) == SUCCESS && Z_TYPE(retval) == IS_STRING) { request = Z_STRVAL(retval); request_size = Z_STRLEN(retval); @@ -412,10 +405,10 @@ int make_http_soap_request(zval *this_ptr, } } - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket"), (void **)&tmp) == SUCCESS) { + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1)) != NULL) { php_stream_from_zval_no_verify(stream,tmp); - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy"), (void **)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_LONG) { - use_proxy = Z_LVAL_PP(tmp); + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1)) != NULL && Z_TYPE_P(tmp) == IS_LONG) { + use_proxy = Z_LVAL_P(tmp); } } else { stream = NULL; @@ -425,16 +418,16 @@ int make_http_soap_request(zval *this_ptr, phpurl = php_url_parse(location); } - if (SUCCESS == zend_hash_find(Z_OBJPROP_P(this_ptr), - "_stream_context", sizeof("_stream_context"), (void**)&tmp)) { - context = php_stream_context_from_zval(*tmp, 0); + if (NULL != (tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), + "_stream_context", sizeof("_stream_context")-1))) { + context = php_stream_context_from_zval(tmp, 0); } if (context && - php_stream_context_get_option(context, "http", "max_redirects", &tmp) == SUCCESS) { - if (Z_TYPE_PP(tmp) != IS_STRING || !is_numeric_string(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &redirect_max, NULL, 1)) { - if (Z_TYPE_PP(tmp) == IS_LONG) - redirect_max = Z_LVAL_PP(tmp); + (tmp = php_stream_context_get_option(context, "http", "max_redirects")) != NULL) { + if (Z_TYPE_P(tmp) != IS_STRING || !is_numeric_string(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), &redirect_max, NULL, 1)) { + if (Z_TYPE_P(tmp) == IS_LONG) + redirect_max = Z_LVAL_P(tmp); } } @@ -476,7 +469,7 @@ try_again: /* Check if request to the same host */ if (stream != NULL) { php_url *orig; - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl"), (void **)&tmp) == SUCCESS && + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")-1)) != NULL && (orig = (php_url *) zend_fetch_resource(tmp TSRMLS_CC, -1, "httpurl", NULL, 1, le_url)) != NULL && ((use_proxy && !use_ssl) || (((use_ssl && orig->scheme != NULL && strcmp(orig->scheme, "https") == 0) || @@ -486,9 +479,9 @@ try_again: orig->port == phpurl->port))) { } else { php_stream_close(stream); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1); stream = NULL; use_proxy = 0; } @@ -497,9 +490,9 @@ try_again: /* Check if keep-alive connection is still opened */ if (stream != NULL && php_stream_eof(stream)) { php_stream_close(stream); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1); stream = NULL; use_proxy = 0; } @@ -508,7 +501,7 @@ try_again: stream = http_connect(this_ptr, phpurl, use_ssl, context, &use_proxy TSRMLS_CC); if (stream) { php_stream_auto_cleanup(stream); - add_property_resource(this_ptr, "httpsocket", php_stream_get_resource_id(stream)); + add_property_resource(this_ptr, "httpsocket", stream->res); add_property_long(this_ptr, "_use_proxy", use_proxy); } else { php_url_free(phpurl); @@ -522,16 +515,16 @@ try_again: PG(allow_url_fopen) = old_allow_url_fopen; if (stream) { - zval **cookies, **login, **password; - int ret = zend_list_insert(phpurl, le_url TSRMLS_CC); + zval *cookies, *login, *password; + zend_resource *ret = zend_register_resource(NULL, phpurl, le_url TSRMLS_CC); add_property_resource(this_ptr, "httpurl", ret); /*zend_list_addref(ret);*/ if (context && - php_stream_context_get_option(context, "http", "protocol_version", &tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_DOUBLE && - Z_DVAL_PP(tmp) == 1.0) { + (tmp = php_stream_context_get_option(context, "http", "protocol_version")) != NULL && + Z_TYPE_P(tmp) == IS_DOUBLE && + Z_DVAL_P(tmp) == 1.0) { http_1_1 = 0; } else { http_1_1 = 1; @@ -570,27 +563,27 @@ try_again: smart_str_append_unsigned(&soap_headers, phpurl->port); } if (!http_1_1 || - (zend_hash_find(Z_OBJPROP_P(this_ptr), "_keep_alive", sizeof("_keep_alive"), (void **)&tmp) == SUCCESS && - Z_LVAL_PP(tmp) == 0)) { + ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_keep_alive", sizeof("_keep_alive")-1)) != NULL && + Z_LVAL_P(tmp) == 0)) { smart_str_append_const(&soap_headers, "\r\n" "Connection: close\r\n"); } else { smart_str_append_const(&soap_headers, "\r\n" "Connection: Keep-Alive\r\n"); } - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_user_agent", sizeof("_user_agent"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { - if (Z_STRLEN_PP(tmp) > 0) { + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_user_agent", sizeof("_user_agent")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { + if (Z_STRLEN_P(tmp) > 0) { smart_str_append_const(&soap_headers, "User-Agent: "); - smart_str_appendl(&soap_headers, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); smart_str_append_const(&soap_headers, "\r\n"); } } else if (context && - php_stream_context_get_option(context, "http", "user_agent", &tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { - if (Z_STRLEN_PP(tmp) > 0) { + (tmp = php_stream_context_get_option(context, "http", "user_agent")) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { + if (Z_STRLEN_P(tmp) > 0) { smart_str_append_const(&soap_headers, "User-Agent: "); - smart_str_appendl(&soap_headers, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); smart_str_append_const(&soap_headers, "\r\n"); } } else if (FG(user_agent)) { @@ -624,13 +617,13 @@ try_again: smart_str_append_const(&soap_headers, "\r\n"); /* HTTP Authentication */ - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_login", sizeof("_login"), (void **)&login) == SUCCESS && - Z_TYPE_PP(login) == IS_STRING) { - zval **digest; + if ((login = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_login", sizeof("_login")-1)) != NULL && + Z_TYPE_P(login) == IS_STRING) { + zval *digest; has_authorization = 1; - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_digest", sizeof("_digest"), (void **)&digest) == SUCCESS) { - if (Z_TYPE_PP(digest) == IS_ARRAY) { + if ((digest = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_digest", sizeof("_digest")-1)) != NULL) { + if (Z_TYPE_P(digest) == IS_ARRAY) { char HA1[33], HA2[33], response[33], cnonce[33], nc[9]; PHP_MD5_CTX md5ctx; unsigned char hash[16]; @@ -641,39 +634,39 @@ try_again: PHP_MD5Final(hash, &md5ctx); make_digest(cnonce, hash); - if (zend_hash_find(Z_ARRVAL_PP(digest), "nc", sizeof("nc"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_LONG) { - Z_LVAL_PP(tmp)++; - snprintf(nc, sizeof(nc), "%08ld", Z_LVAL_PP(tmp)); + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "nc", sizeof("nc")-1)) != NULL && + Z_TYPE_P(tmp) == IS_LONG) { + Z_LVAL_P(tmp)++; + snprintf(nc, sizeof(nc), "%08ld", Z_LVAL_P(tmp)); } else { - add_assoc_long(*digest, "nc", 1); + add_assoc_long(digest, "nc", 1); strcpy(nc, "00000001"); } PHP_MD5Init(&md5ctx); - PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_PP(login), Z_STRLEN_PP(login)); + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(login), Z_STRLEN_P(login)); PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); - if (zend_hash_find(Z_ARRVAL_PP(digest), "realm", sizeof("realm"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { - PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "realm", sizeof("realm")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password"), (void **)&password) == SUCCESS && - Z_TYPE_PP(password) == IS_STRING) { - PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_PP(password), Z_STRLEN_PP(password)); + if ((password = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password")-1)) != NULL && + Z_TYPE_P(password) == IS_STRING) { + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(password), Z_STRLEN_P(password)); } PHP_MD5Final(hash, &md5ctx); make_digest(HA1, hash); - if (zend_hash_find(Z_ARRVAL_PP(digest), "algorithm", sizeof("algorithm"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING && - Z_STRLEN_PP(tmp) == sizeof("md5-sess")-1 && - stricmp(Z_STRVAL_PP(tmp), "md5-sess") == 0) { + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "algorithm", sizeof("algorithm")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING && + Z_STRLEN_P(tmp) == sizeof("md5-sess")-1 && + stricmp(Z_STRVAL_P(tmp), "md5-sess") == 0) { PHP_MD5Init(&md5ctx); PHP_MD5Update(&md5ctx, (unsigned char*)HA1, 32); PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); - if (zend_hash_find(Z_ARRVAL_PP(digest), "nonce", sizeof("nonce"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { - PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "nonce", sizeof("nonce")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); PHP_MD5Update(&md5ctx, (unsigned char*)cnonce, 8); @@ -709,13 +702,13 @@ try_again: PHP_MD5Init(&md5ctx); PHP_MD5Update(&md5ctx, (unsigned char*)HA1, 32); PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); - if (zend_hash_find(Z_ARRVAL_PP(digest), "nonce", sizeof("nonce"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { - PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "nonce", sizeof("nonce")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); - if (zend_hash_find(Z_ARRVAL_PP(digest), "qop", sizeof("qop"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "qop", sizeof("qop")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { PHP_MD5Update(&md5ctx, (unsigned char*)nc, 8); PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); PHP_MD5Update(&md5ctx, (unsigned char*)cnonce, 8); @@ -729,16 +722,16 @@ try_again: make_digest(response, hash); smart_str_append_const(&soap_headers, "Authorization: Digest username=\""); - smart_str_appendl(&soap_headers, Z_STRVAL_PP(login), Z_STRLEN_PP(login)); - if (zend_hash_find(Z_ARRVAL_PP(digest), "realm", sizeof("realm"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { + smart_str_appendl(&soap_headers, Z_STRVAL_P(login), Z_STRLEN_P(login)); + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "realm", sizeof("realm")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { smart_str_append_const(&soap_headers, "\", realm=\""); - smart_str_appendl(&soap_headers, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } - if (zend_hash_find(Z_ARRVAL_PP(digest), "nonce", sizeof("nonce"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "nonce", sizeof("nonce")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { smart_str_append_const(&soap_headers, "\", nonce=\""); - smart_str_appendl(&soap_headers, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } smart_str_append_const(&soap_headers, "\", uri=\""); if (phpurl->path) { @@ -754,8 +747,8 @@ try_again: smart_str_appendc(&soap_headers, '#'); smart_str_appends(&soap_headers, phpurl->fragment); } - if (zend_hash_find(Z_ARRVAL_PP(digest), "qop", sizeof("qop"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "qop", sizeof("qop")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { /* TODO: Support for qop="auth-int" */ smart_str_append_const(&soap_headers, "\", qop=\"auth"); smart_str_append_const(&soap_headers, "\", nc=\""); @@ -765,35 +758,34 @@ try_again: } smart_str_append_const(&soap_headers, "\", response=\""); smart_str_appendl(&soap_headers, response, 32); - if (zend_hash_find(Z_ARRVAL_PP(digest), "opaque", sizeof("opaque"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "opaque", sizeof("opaque")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { smart_str_append_const(&soap_headers, "\", opaque=\""); - smart_str_appendl(&soap_headers, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } - if (zend_hash_find(Z_ARRVAL_PP(digest), "algorithm", sizeof("algorithm"), (void **)&tmp) == SUCCESS && - Z_TYPE_PP(tmp) == IS_STRING) { + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "algorithm", sizeof("algorithm")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING) { smart_str_append_const(&soap_headers, "\", algorithm=\""); - smart_str_appendl(&soap_headers, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } smart_str_append_const(&soap_headers, "\"\r\n"); } } else { - unsigned char* buf; - int len; + zend_string *buf; smart_str auth = {0}; - smart_str_appendl(&auth, Z_STRVAL_PP(login), Z_STRLEN_PP(login)); + smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRLEN_P(login)); smart_str_appendc(&auth, ':'); - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password"), (void **)&password) == SUCCESS && - Z_TYPE_PP(password) == IS_STRING) { - smart_str_appendl(&auth, Z_STRVAL_PP(password), Z_STRLEN_PP(password)); + if ((password = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password")-1)) != NULL && + Z_TYPE_P(password) == IS_STRING) { + smart_str_appendl(&auth, Z_STRVAL_P(password), Z_STRLEN_P(password)); } smart_str_0(&auth); - buf = php_base64_encode((unsigned char*)auth.c, auth.len, &len); + buf = php_base64_encode((unsigned char*)auth.s->val, auth.s->len); smart_str_append_const(&soap_headers, "Authorization: Basic "); - smart_str_appendl(&soap_headers, (char*)buf, len); + smart_str_appendl(&soap_headers, (char*)buf->val, buf->len); smart_str_append_const(&soap_headers, "\r\n"); - efree(buf); + STR_RELEASE(buf); smart_str_free(&auth); } } @@ -804,40 +796,39 @@ try_again: } /* Send cookies along with request */ - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == SUCCESS) { - zval **data; - char *key; - uint key_len; + if ((cookies = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1)) != NULL) { + zval *data; + zend_string *key; int i, n; has_cookies = 1; - n = zend_hash_num_elements(Z_ARRVAL_PP(cookies)); + n = zend_hash_num_elements(Z_ARRVAL_P(cookies)); if (n > 0) { - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(cookies)); + zend_hash_internal_pointer_reset(Z_ARRVAL_P(cookies)); smart_str_append_const(&soap_headers, "Cookie: "); for (i = 0; i < n; i++) { - zend_hash_get_current_data(Z_ARRVAL_PP(cookies), (void **)&data); - zend_hash_get_current_key_ex(Z_ARRVAL_PP(cookies), &key, &key_len, NULL, 0, NULL); - - if (Z_TYPE_PP(data) == IS_ARRAY) { - zval** value; - - if (zend_hash_index_find(Z_ARRVAL_PP(data), 0, (void**)&value) == SUCCESS && - Z_TYPE_PP(value) == IS_STRING) { - zval **tmp; - if ((zend_hash_index_find(Z_ARRVAL_PP(data), 1, (void**)&tmp) == FAILURE || - strncmp(phpurl->path?phpurl->path:"/",Z_STRVAL_PP(tmp),Z_STRLEN_PP(tmp)) == 0) && - (zend_hash_index_find(Z_ARRVAL_PP(data), 2, (void**)&tmp) == FAILURE || - in_domain(phpurl->host,Z_STRVAL_PP(tmp))) && - (use_ssl || zend_hash_index_find(Z_ARRVAL_PP(data), 3, (void**)&tmp) == FAILURE)) { - smart_str_appendl(&soap_headers, key, key_len); + data = zend_hash_get_current_data(Z_ARRVAL_P(cookies)); + zend_hash_get_current_key_ex(Z_ARRVAL_P(cookies), &key, NULL, 0, NULL); + + if (Z_TYPE_P(data) == IS_ARRAY) { + zval *value; + + if ((value = zend_hash_index_find(Z_ARRVAL_P(data), 0)) != NULL && + Z_TYPE_P(value) == IS_STRING) { + zval *tmp; + if (((tmp = zend_hash_index_find(Z_ARRVAL_P(data), 1)) == NULL || + strncmp(phpurl->path?phpurl->path:"/",Z_STRVAL_P(tmp),Z_STRLEN_P(tmp)) == 0) && + ((tmp = zend_hash_index_find(Z_ARRVAL_P(data), 2)) == NULL || + in_domain(phpurl->host,Z_STRVAL_P(tmp))) && + (use_ssl || (tmp = zend_hash_index_find(Z_ARRVAL_P(data), 3)) == NULL)) { + smart_str_appendl(&soap_headers, key->val, key->len); smart_str_appendc(&soap_headers, '='); - smart_str_appendl(&soap_headers, Z_STRVAL_PP(value), Z_STRLEN_PP(value)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(value), Z_STRLEN_P(value)); smart_str_appendc(&soap_headers, ';'); } } } - zend_hash_move_forward(Z_ARRVAL_PP(cookies)); + zend_hash_move_forward(Z_ARRVAL_P(cookies)); } smart_str_append_const(&soap_headers, "\r\n"); } @@ -847,20 +838,20 @@ try_again: smart_str_append_const(&soap_headers, "\r\n"); smart_str_0(&soap_headers); - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) &trace) == SUCCESS && - Z_LVAL_PP(trace) > 0) { - add_property_stringl(this_ptr, "__last_request_headers", soap_headers.c, soap_headers.len); + if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL && + Z_LVAL_P(trace) > 0) { + add_property_stringl(this_ptr, "__last_request_headers", soap_headers.s->val, soap_headers.s->len); } smart_str_appendl(&soap_headers, request, request_size); smart_str_0(&soap_headers); - err = php_stream_write(stream, soap_headers.c, soap_headers.len); - if (err != soap_headers.len) { + err = php_stream_write(stream, soap_headers.s->val, soap_headers.s->len); + if (err != soap_headers.s->len) { if (request != buf) {efree(request);} php_stream_close(stream); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1); add_soap_fault(this_ptr, "HTTP", "Failed Sending HTTP SOAP request", NULL, NULL TSRMLS_CC); smart_str_free(&soap_headers_z); return FALSE; @@ -872,10 +863,10 @@ try_again: return FALSE; } - if (!buffer) { + if (!return_value) { php_stream_close(stream); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1); smart_str_free(&soap_headers_z); return TRUE; } @@ -885,15 +876,15 @@ try_again: if (http_headers) {efree(http_headers);} if (request != buf) {efree(request);} php_stream_close(stream); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1); add_soap_fault(this_ptr, "HTTP", "Error Fetching http headers", NULL, NULL TSRMLS_CC); smart_str_free(&soap_headers_z); return FALSE; } - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) &trace) == SUCCESS && - Z_LVAL_PP(trace) > 0) { + if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL && + Z_LVAL_P(trace) > 0) { add_property_stringl(this_ptr, "__last_response_headers", http_headers, http_header_size); } @@ -940,13 +931,12 @@ try_again: while (cookie_itt) { char *end_pos, *cookie; char *eqpos, *sempos; - zval **cookies; + zval *cookies; - if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == FAILURE) { - zval *tmp_cookies; - MAKE_STD_ZVAL(tmp_cookies); - array_init(tmp_cookies); - zend_hash_update(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), &tmp_cookies, sizeof(zval *), (void **)&cookies); + if ((cookies = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1)) == NULL) { + zval tmp_cookies; + array_init(&tmp_cookies); + cookies = zend_hash_str_update(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1, &tmp_cookies); } end_pos = strstr(cookie_itt,"\r\n"); @@ -957,7 +947,7 @@ try_again: if (eqpos != NULL && (sempos == NULL || sempos > eqpos)) { smart_str name = {0}; int cookie_len; - zval *zcookie; + zval zcookie; if (sempos != NULL) { cookie_len = sempos-(eqpos+1); @@ -968,9 +958,8 @@ try_again: smart_str_appendl(&name, cookie, eqpos - cookie); smart_str_0(&name); - ALLOC_INIT_ZVAL(zcookie); - array_init(zcookie); - add_index_stringl(zcookie, 0, eqpos + 1, cookie_len); + array_init(&zcookie); + add_index_stringl(&zcookie, 0, eqpos + 1, cookie_len); if (sempos != NULL) { char *options = cookie + cookie_len+1; @@ -979,12 +968,12 @@ try_again: sempos = strstr(options, ";"); if (strstr(options,"path=") == options) { eqpos = options + sizeof("path=")-1; - add_index_stringl(zcookie, 1, eqpos, sempos?(sempos-eqpos):strlen(eqpos)); + add_index_stringl(&zcookie, 1, eqpos, sempos?(sempos-eqpos):strlen(eqpos)); } else if (strstr(options,"domain=") == options) { eqpos = options + sizeof("domain=")-1; - add_index_stringl(zcookie, 2, eqpos, sempos?(sempos-eqpos):strlen(eqpos)); + add_index_stringl(&zcookie, 2, eqpos, sempos?(sempos-eqpos):strlen(eqpos)); } else if (strstr(options,"secure") == options) { - add_index_bool(zcookie, 3, 1); + add_index_bool(&zcookie, 3, 1); } if (sempos != NULL) { options = sempos+1; @@ -993,18 +982,19 @@ try_again: } } } - if (!zend_hash_index_exists(Z_ARRVAL_P(zcookie), 1)) { + if (!zend_hash_index_exists(Z_ARRVAL(zcookie), 1)) { char *t = phpurl->path?phpurl->path:"/"; char *c = strrchr(t, '/'); if (c) { - add_index_stringl(zcookie, 1, t, c-t); + add_index_stringl(&zcookie, 1, t, c-t); } } - if (!zend_hash_index_exists(Z_ARRVAL_P(zcookie), 2)) { - add_index_string(zcookie, 2, phpurl->host); + if (!zend_hash_index_exists(Z_ARRVAL(zcookie), 2)) { + add_index_string(&zcookie, 2, phpurl->host); } - add_assoc_zval_ex(*cookies, name.c, name.len+1, zcookie); + // TODO: avoid reallocation ??? + add_assoc_zval_ex(cookies, name.s->val, name.s->len, &zcookie); smart_str_free(&name); } @@ -1059,8 +1049,8 @@ try_again: if (request != buf) {efree(request);} php_stream_close(stream); efree(http_headers); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1); add_soap_fault(this_ptr, "HTTP", "Error Fetching http body, No Content-Length, connection closed or chunked data", NULL, NULL TSRMLS_CC); if (http_msg) { efree(http_msg); @@ -1073,8 +1063,8 @@ try_again: if (http_close) { php_stream_close(stream); - zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")); - zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1); + zend_hash_str_del(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1); stream = NULL; } @@ -1127,20 +1117,21 @@ try_again: } } else if (http_status == 401) { /* Digest authentication */ - zval **digest, **login, **password; + zval *digest, *login, *password; char *auth = get_http_header_value(http_headers, "WWW-Authenticate: "); if (auth && strstr(auth, "Digest") == auth && - (zend_hash_find(Z_OBJPROP_P(this_ptr), "_digest", sizeof("_digest"), (void **)&digest) == FAILURE || - Z_TYPE_PP(digest) != IS_ARRAY) && - zend_hash_find(Z_OBJPROP_P(this_ptr), "_login", sizeof("_login"), (void **)&login) == SUCCESS && - Z_TYPE_PP(login) == IS_STRING && - zend_hash_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password"), (void **)&password) == SUCCESS && - Z_TYPE_PP(password) == IS_STRING) { + ((digest = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_digest", sizeof("_digest")-1)) == NULL || + Z_TYPE_P(digest) != IS_ARRAY) && + (login = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_login", sizeof("_login")-1)) != NULL && + Z_TYPE_P(login) == IS_STRING && + (password = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password")-1)) != NULL && + Z_TYPE_P(password) == IS_STRING) { char *s; - zval *digest = NULL; + zval digest; + ZVAL_UNDEF(&digest); s = auth + sizeof("Digest")-1; while (*s != '\0') { char *name, *val; @@ -1169,19 +1160,18 @@ try_again: ++s; } } - if (digest == NULL) { - ALLOC_INIT_ZVAL(digest); - array_init(digest); + if (Z_TYPE(digest) == IS_UNDEF) { + array_init(&digest); } - add_assoc_string(digest, name, val); + add_assoc_string(&digest, name, val); } } - if (digest != NULL) { + if (Z_TYPE(digest) != IS_UNDEF) { php_url *new_url = emalloc(sizeof(php_url)); - Z_DELREF_P(digest); - add_property_zval_ex(this_ptr, "_digest", sizeof("_digest"), digest TSRMLS_CC); + Z_DELREF(digest); + add_property_zval_ex(this_ptr, "_digest", sizeof("_digest")-1, &digest TSRMLS_CC); *new_url = *phpurl; if (phpurl->scheme) phpurl->scheme = estrdup(phpurl->scheme); @@ -1239,22 +1229,21 @@ try_again: if (content_encoding) { zval func; zval retval; - zval param; - zval *params[1]; + zval params[1]; if ((strcmp(content_encoding,"gzip") == 0 || strcmp(content_encoding,"x-gzip") == 0) && - zend_hash_exists(EG(function_table), "gzinflate", sizeof("gzinflate"))) { - ZVAL_STRING(&func, "gzinflate", 0); - params[0] = ¶m; - ZVAL_STRINGL(params[0], http_body+10, http_body_size-10, 0); - INIT_PZVAL(params[0]); + zend_hash_str_exists(EG(function_table), "gzinflate", sizeof("gzinflate")-1)) { + //???ZVAL_STRING(&func, "gzinflate", 0); + //???ZVAL_STRINGL(params[0], http_body+10, http_body_size-10, 0); + ZVAL_STRING(&func, "gzinflate"); + ZVAL_STRINGL(¶ms[0], http_body+10, http_body_size-10); } else if (strcmp(content_encoding,"deflate") == 0 && - zend_hash_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress"))) { - ZVAL_STRING(&func, "gzuncompress", 0); - params[0] = ¶m; - ZVAL_STRINGL(params[0], http_body, http_body_size, 0); - INIT_PZVAL(params[0]); + zend_hash_str_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1)) { + //???ZVAL_STRING(&func, "gzuncompress", 0); + //???ZVAL_STRINGL(params[0], http_body, http_body_size, 0); + ZVAL_STRING(&func, "gzuncompress"); + ZVAL_STRINGL(¶ms[0], http_body, http_body_size); } else { efree(content_encoding); efree(http_headers); @@ -1265,11 +1254,10 @@ try_again: add_soap_fault(this_ptr, "HTTP", "Unknown Content-Encoding", NULL, NULL TSRMLS_CC); return FALSE; } - if (call_user_function(CG(function_table), (zval**)NULL, &func, &retval, 1, params TSRMLS_CC) == SUCCESS && + if (call_user_function(CG(function_table), (zval*)NULL, &func, &retval, 1, params TSRMLS_CC) == SUCCESS && Z_TYPE(retval) == IS_STRING) { efree(http_body); - *buffer = Z_STRVAL(retval); - *buffer_len = Z_STRLEN(retval); + ZVAL_COPY_VALUE(return_value, &retval); } else { efree(content_encoding); efree(http_headers); @@ -1282,8 +1270,11 @@ try_again: } efree(content_encoding); } else { - *buffer = http_body; - *buffer_len = http_body_size; + // TODO: avoid reallocation ??? + //???*buffer = http_body; + //???*buffer_len = http_body_size; + ZVAL_STRINGL(return_value, http_body, http_body_size); + efree(http_body); } efree(http_headers); @@ -1291,11 +1282,11 @@ try_again: if (http_status >= 400) { int error = 0; - if (*buffer_len == 0) { + if (Z_STRLEN_P(return_value) == 0) { error = 1; - } else if (*buffer_len > 0) { + } else if (Z_STRLEN_P(return_value) > 0) { if (!content_type_xml) { - char *s = *buffer; + char *s = Z_STRVAL_P(return_value); while (*s != '\0' && *s < ' ') { s++; @@ -1307,7 +1298,8 @@ try_again: } if (error) { - efree(*buffer); + zval_ptr_dtor(return_value); + ZVAL_UNDEF(return_value); add_soap_fault(this_ptr, "HTTP", http_msg, NULL, NULL TSRMLS_CC); efree(http_msg); return FALSE; @@ -1515,8 +1507,8 @@ static int get_http_headers(php_stream *stream, char **response, int *out_size T smart_str_appends(&tmp_response, headerbuf); } smart_str_0(&tmp_response); - (*response) = tmp_response.c; - (*out_size) = tmp_response.len; + (*response) = tmp_response.s->val; + (*out_size) = tmp_response.s->len; return done; } /* |