diff options
Diffstat (limited to 'ext/soap/php_http.c')
-rw-r--r-- | ext/soap/php_http.c | 212 |
1 files changed, 102 insertions, 110 deletions
diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 0935ce36ad..a1cee555a8 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ @@ -26,7 +26,7 @@ static char *get_http_header_value(char *headers, char *type); static int get_http_body(php_stream *socketd, int close, char *headers, char **response, int *out_size TSRMLS_DC); -static int get_http_headers(php_stream *socketd,char **response, int *out_size TSRMLS_DC); +static zend_string *get_http_headers(php_stream *socketd TSRMLS_DC); #define smart_str_append_const(str, const) \ smart_str_appendl(str,const,sizeof(const)-1) @@ -40,17 +40,17 @@ int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) zend_string *buf; smart_str auth = {0}; - smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRSIZE_P(login)); + smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRLEN_P(login)); smart_str_appendc(&auth, ':'); 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_STRSIZE_P(password)); + smart_str_appendl(&auth, Z_STRVAL_P(password), Z_STRLEN_P(password)); } smart_str_0(&auth); 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->val, buf->len); smart_str_append_const(soap_headers, "\r\n"); - STR_RELEASE(buf); + zend_string_release(buf); smart_str_free(&auth); return 1; } @@ -67,17 +67,17 @@ int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) zend_string* buf; smart_str auth = {0}; - smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRSIZE_P(login)); + smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRLEN_P(login)); smart_str_appendc(&auth, ':'); 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_STRSIZE_P(password)); + smart_str_appendl(&auth, Z_STRVAL_P(password), Z_STRLEN_P(password)); } smart_str_0(&auth); 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->val, buf->len); smart_str_append_const(soap_headers, "\r\n"); - STR_RELEASE(buf); + zend_string_release(buf); smart_str_free(&auth); return 1; } @@ -95,7 +95,7 @@ void http_context_headers(php_stream_context* context, if (context && (tmp = php_stream_context_get_option(context, "http", "header")) != NULL && - Z_TYPE_P(tmp) == IS_STRING && Z_STRSIZE_P(tmp)) { + Z_TYPE_P(tmp) == IS_STRING && Z_STRLEN_P(tmp)) { char *s = Z_STRVAL_P(tmp); char *p; int name_len; @@ -161,7 +161,7 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph char *host; char *name; char *protocol; - php_int_t namelen; + zend_long namelen; int port; int old_error_reporting; struct timeval tv; @@ -170,17 +170,17 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph 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_INT) { + Z_TYPE_P(proxy_port) == IS_LONG) { host = Z_STRVAL_P(proxy_host); - port = Z_IVAL_P(proxy_port); + port = Z_LVAL_P(proxy_port); *use_proxy = 1; } else { host = phpurl->host; port = phpurl->port; } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_connection_timeout", sizeof("_connection_timeout")-1)) != NULL && - Z_TYPE_P(tmp) == IS_INT && Z_IVAL_P(tmp) > 0) { - tv.tv_sec = Z_IVAL_P(tmp); + Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) > 0) { + tv.tv_sec = Z_LVAL_P(tmp); tv.tv_usec = 0; timeout = &tv; } @@ -191,9 +191,9 @@ 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 ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_ssl_method", sizeof("_ssl_method")-1)) != NULL && - Z_TYPE_P(tmp) == IS_INT) { + Z_TYPE_P(tmp) == IS_LONG) { /* uses constants declared in soap.c to determine ssl uri protocol */ - switch (Z_IVAL_P(tmp)) { + switch (Z_LVAL_P(tmp)) { case SOAP_SSL_METHOD_TLS: protocol = "tls"; break; @@ -236,8 +236,6 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph /* SSL & proxy */ if (stream && *use_proxy && use_ssl) { smart_str soap_headers = {0}; - char *http_headers; - int http_header_size; smart_str_append_const(&soap_headers, "CONNECT "); smart_str_appends(&soap_headers, phpurl->host); @@ -260,13 +258,13 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph smart_str_free(&soap_headers); if (stream) { - if (!get_http_headers(stream, &http_headers, &http_header_size TSRMLS_CC) || http_headers == NULL) { + zend_string *http_headers = get_http_headers(stream TSRMLS_CC); + if (http_headers) { + zend_string_free(http_headers); + } else { php_stream_close(stream); stream = NULL; } - if (http_headers) { - efree(http_headers); - } } /* enable SSL transport layer */ if (stream) { @@ -274,8 +272,8 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph proper encrypyion method based on constants defined in soap.c */ int crypto_method = STREAM_CRYPTO_METHOD_SSLv23_CLIENT; if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_ssl_method", sizeof("_ssl_method")-1)) != NULL && - Z_TYPE_P(tmp) == IS_INT) { - switch (Z_IVAL_P(tmp)) { + Z_TYPE_P(tmp) == IS_LONG) { + switch (Z_LVAL_P(tmp)) { case SOAP_SSL_METHOD_TLS: crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; break; @@ -341,13 +339,14 @@ int make_http_soap_request(zval *this_ptr, zval *trace, *tmp; int use_proxy = 0; int use_ssl; - char *http_headers, *http_body, *content_type, *http_version, *cookie_itt; - int http_header_size, http_body_size, http_close; + char *http_body, *content_type, *http_version, *cookie_itt; + int http_body_size, http_close; + zend_string *http_headers; char *connection; int http_1_1; int http_status; int content_type_xml = 0; - php_int_t redirect_max = 20; + zend_long redirect_max = 20; char *content_encoding; char *http_msg = NULL; zend_bool old_allow_url_fopen; @@ -363,13 +362,13 @@ int make_http_soap_request(zval *this_ptr, request = buf; request_size = buf_size; /* Compress request */ - if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "compression", sizeof("compression")-1)) != NULL && Z_TYPE_P(tmp) == IS_INT) { - int level = Z_IVAL_P(tmp) & 0x0f; - int kind = Z_IVAL_P(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_IVAL_P(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) { @@ -379,7 +378,7 @@ int make_http_soap_request(zval *this_ptr, int n; ZVAL_STRINGL(¶ms[0], buf, buf_size); - ZVAL_INT(¶ms[1], level); + ZVAL_LONG(¶ms[1], level); if (kind == SOAP_COMPRESSION_DEFLATE) { n = 2; ZVAL_STRING(&func, "gzcompress"); @@ -388,7 +387,7 @@ int make_http_soap_request(zval *this_ptr, n = 3; ZVAL_STRING(&func, "gzencode"); smart_str_append_const(&soap_headers_z,"Content-Encoding: gzip\r\n"); - ZVAL_INT(¶ms[2], 0x1f); + ZVAL_LONG(¶ms[2], 0x1f); } if (call_user_function(CG(function_table), (zval*)NULL, &func, &retval, n, params TSRMLS_CC) == SUCCESS && Z_TYPE(retval) == IS_STRING) { @@ -396,7 +395,7 @@ int make_http_soap_request(zval *this_ptr, zval_ptr_dtor(&func); // TODO: free retval ??? request = Z_STRVAL(retval); - request_size = Z_STRSIZE(retval); + request_size = Z_STRLEN(retval); } else { zval_ptr_dtor(¶ms[0]); zval_ptr_dtor(&func); @@ -409,8 +408,8 @@ int make_http_soap_request(zval *this_ptr, 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 ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_use_proxy", sizeof("_use_proxy")-1)) != NULL && Z_TYPE_P(tmp) == IS_INT) { - use_proxy = Z_IVAL_P(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; @@ -427,9 +426,9 @@ int make_http_soap_request(zval *this_ptr, if (context && (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_STRSIZE_P(tmp), &redirect_max, NULL, 1)) { - if (Z_TYPE_P(tmp) == IS_INT) - redirect_max = Z_IVAL_P(tmp); + 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); } } @@ -504,7 +503,7 @@ try_again: if (stream) { php_stream_auto_cleanup(stream); add_property_resource(this_ptr, "httpsocket", stream->res); - add_property_int(this_ptr, "_use_proxy", use_proxy); + add_property_long(this_ptr, "_use_proxy", use_proxy); } else { php_url_free(phpurl); if (request != buf) {efree(request);} @@ -566,7 +565,7 @@ try_again: } if (!http_1_1 || ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_keep_alive", sizeof("_keep_alive")-1)) != NULL && - Z_IVAL_P(tmp) == 0)) { + Z_LVAL_P(tmp) == 0)) { smart_str_append_const(&soap_headers, "\r\n" "Connection: close\r\n"); } else { @@ -575,17 +574,17 @@ try_again: } 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_STRSIZE_P(tmp) > 0) { + if (Z_STRLEN_P(tmp) > 0) { smart_str_append_const(&soap_headers, "User-Agent: "); - smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRSIZE_P(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 && (tmp = php_stream_context_get_option(context, "http", "user_agent")) != NULL && Z_TYPE_P(tmp) == IS_STRING) { - if (Z_STRSIZE_P(tmp) > 0) { + if (Z_STRLEN_P(tmp) > 0) { smart_str_append_const(&soap_headers, "User-Agent: "); - smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRSIZE_P(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)) { @@ -596,7 +595,7 @@ try_again: smart_str_append_const(&soap_headers, "User-Agent: PHP-SOAP/"PHP_VERSION"\r\n"); } - smart_str_append(&soap_headers, &soap_headers_z); + smart_str_append_smart_str(&soap_headers, &soap_headers_z); if (soap_version == SOAP_1_2) { smart_str_append_const(&soap_headers,"Content-Type: application/soap+xml; charset=utf-8"); @@ -615,7 +614,7 @@ try_again: } } smart_str_append_const(&soap_headers,"Content-Length: "); - smart_str_append_int(&soap_headers, request_size); + smart_str_append_long(&soap_headers, request_size); smart_str_append_const(&soap_headers, "\r\n"); /* HTTP Authentication */ @@ -631,44 +630,44 @@ try_again: unsigned char hash[16]; PHP_MD5Init(&md5ctx); - snprintf(cnonce, sizeof(cnonce), "%ld", php_rand(TSRMLS_C)); + snprintf(cnonce, sizeof(cnonce), ZEND_LONG_FMT, php_rand(TSRMLS_C)); PHP_MD5Update(&md5ctx, (unsigned char*)cnonce, strlen(cnonce)); PHP_MD5Final(hash, &md5ctx); make_digest(cnonce, hash); if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "nc", sizeof("nc")-1)) != NULL && - Z_TYPE_P(tmp) == IS_INT) { - Z_IVAL_P(tmp)++; - snprintf(nc, sizeof(nc), "%08ld", Z_IVAL_P(tmp)); + Z_TYPE_P(tmp) == IS_LONG) { + Z_LVAL_P(tmp)++; + snprintf(nc, sizeof(nc), "%08ld", Z_LVAL_P(tmp)); } else { - add_assoc_int(digest, "nc", 1); + add_assoc_long(digest, "nc", 1); strcpy(nc, "00000001"); } PHP_MD5Init(&md5ctx); - PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(login), Z_STRSIZE_P(login)); + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(login), Z_STRLEN_P(login)); PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); 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_STRSIZE_P(tmp)); + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); 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_STRSIZE_P(password)); + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(password), Z_STRLEN_P(password)); } PHP_MD5Final(hash, &md5ctx); make_digest(HA1, hash); if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "algorithm", sizeof("algorithm")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING && - Z_STRSIZE_P(tmp) == sizeof("md5-sess")-1 && + 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 ((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_STRSIZE_P(tmp)); + 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); @@ -692,7 +691,7 @@ try_again: /* if (zend_hash_find(Z_ARRVAL_PP(digest), "qop", sizeof("qop"), (void **)&tmp) == SUCCESS && Z_TYPE_PP(tmp) == IS_STRING && - Z_STRSIZE_PP(tmp) == sizeof("auth-int")-1 && + Z_STRLEN_PP(tmp) == sizeof("auth-int")-1 && stricmp(Z_STRVAL_PP(tmp), "auth-int") == 0) { PHP_MD5Update(&md5ctx, ":", 1); PHP_MD5Update(&md5ctx, HEntity, HASHHEXLEN); @@ -706,7 +705,7 @@ try_again: PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); 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_STRSIZE_P(tmp)); + PHP_MD5Update(&md5ctx, (unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } PHP_MD5Update(&md5ctx, (unsigned char*)":", 1); if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "qop", sizeof("qop")-1)) != NULL && @@ -724,16 +723,16 @@ try_again: make_digest(response, hash); smart_str_append_const(&soap_headers, "Authorization: Digest username=\""); - smart_str_appendl(&soap_headers, Z_STRVAL_P(login), Z_STRSIZE_P(login)); + 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_P(tmp), Z_STRSIZE_P(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } 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_P(tmp), Z_STRSIZE_P(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } smart_str_append_const(&soap_headers, "\", uri=\""); if (phpurl->path) { @@ -763,12 +762,12 @@ try_again: 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_P(tmp), Z_STRSIZE_P(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } 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_P(tmp), Z_STRSIZE_P(tmp)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); } smart_str_append_const(&soap_headers, "\"\r\n"); } @@ -776,18 +775,18 @@ try_again: zend_string *buf; smart_str auth = {0}; - smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRSIZE_P(login)); + smart_str_appendl(&auth, Z_STRVAL_P(login), Z_STRLEN_P(login)); smart_str_appendc(&auth, ':'); 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_STRSIZE_P(password)); + smart_str_appendl(&auth, Z_STRVAL_P(password), Z_STRLEN_P(password)); } smart_str_0(&auth); 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->val, buf->len); smart_str_append_const(&soap_headers, "\r\n"); - STR_RELEASE(buf); + zend_string_release(buf); smart_str_free(&auth); } } @@ -819,13 +818,13 @@ try_again: 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_STRSIZE_P(tmp)) == 0) && + 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_P(value), Z_STRSIZE_P(value)); + smart_str_appendl(&soap_headers, Z_STRVAL_P(value), Z_STRLEN_P(value)); smart_str_appendc(&soap_headers, ';'); } } @@ -841,7 +840,7 @@ try_again: smart_str_append_const(&soap_headers, "\r\n"); smart_str_0(&soap_headers); if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL && - Z_IVAL_P(trace) > 0) { + 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); @@ -874,8 +873,8 @@ try_again: } do { - if (!get_http_headers(stream, &http_headers, &http_header_size TSRMLS_CC)) { - if (http_headers) {efree(http_headers);} + http_headers = get_http_headers(stream TSRMLS_CC); + if (!http_headers) { if (request != buf) {efree(request);} php_stream_close(stream); zend_hash_str_del(Z_OBJPROP_P(this_ptr), "httpsocket", sizeof("httpsocket")-1); @@ -886,14 +885,14 @@ try_again: } if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL && - Z_IVAL_P(trace) > 0) { - add_property_stringl(this_ptr, "__last_response_headers", http_headers, http_header_size); + Z_LVAL_P(trace) > 0) { + add_property_str(this_ptr, "__last_response_headers", zend_string_copy(http_headers)); } /* Check to see what HTTP status was sent */ http_1_1 = 0; http_status = 0; - http_version = get_http_header_value(http_headers,"HTTP/"); + http_version = get_http_header_value(http_headers->val, "HTTP/"); if (http_version) { char *tmp; @@ -918,7 +917,7 @@ try_again: /* Try and get headers again */ if (http_status == 100) { - efree(http_headers); + zend_string_release(http_headers); } } } while (http_status == 100); @@ -929,9 +928,9 @@ try_again: we shouldn't be changing urls so path dont matter too much */ - cookie_itt = strstr(http_headers,"Set-Cookie: "); + cookie_itt = strstr(http_headers->val, "Set-Cookie: "); while (cookie_itt) { - char *end_pos, *cookie; + char *cookie; char *eqpos, *sempos; zval *cookies; @@ -941,7 +940,6 @@ try_again: cookies = zend_hash_str_update(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1, &tmp_cookies); } - end_pos = strstr(cookie_itt,"\r\n"); cookie = get_http_header_value(cookie_itt,"Set-Cookie: "); eqpos = strstr(cookie, "="); @@ -1007,7 +1005,7 @@ try_again: if (http_1_1) { http_close = FALSE; if (use_proxy && !use_ssl) { - connection = get_http_header_value(http_headers,"Proxy-Connection: "); + connection = get_http_header_value(http_headers->val, "Proxy-Connection: "); if (connection) { if (strncasecmp(connection, "close", sizeof("close")-1) == 0) { http_close = TRUE; @@ -1016,7 +1014,7 @@ try_again: } } if (http_close == FALSE) { - connection = get_http_header_value(http_headers,"Connection: "); + connection = get_http_header_value(http_headers->val, "Connection: "); if (connection) { if (strncasecmp(connection, "close", sizeof("close")-1) == 0) { http_close = TRUE; @@ -1027,7 +1025,7 @@ try_again: } else { http_close = TRUE; if (use_proxy && !use_ssl) { - connection = get_http_header_value(http_headers,"Proxy-Connection: "); + connection = get_http_header_value(http_headers->val, "Proxy-Connection: "); if (connection) { if (strncasecmp(connection, "Keep-Alive", sizeof("Keep-Alive")-1) == 0) { http_close = FALSE; @@ -1036,7 +1034,7 @@ try_again: } } if (http_close == TRUE) { - connection = get_http_header_value(http_headers,"Connection: "); + connection = get_http_header_value(http_headers->val, "Connection: "); if (connection) { if (strncasecmp(connection, "Keep-Alive", sizeof("Keep-Alive")-1) == 0) { http_close = FALSE; @@ -1046,10 +1044,10 @@ try_again: } } - if (!get_http_body(stream, http_close, http_headers, &http_body, &http_body_size TSRMLS_CC)) { + if (!get_http_body(stream, http_close, http_headers->val, &http_body, &http_body_size TSRMLS_CC)) { if (request != buf) {efree(request);} php_stream_close(stream); - efree(http_headers); + zend_string_release(http_headers); 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); @@ -1073,11 +1071,11 @@ try_again: if (http_status >= 300 && http_status < 400) { char *loc; - if ((loc = get_http_header_value(http_headers,"Location: ")) != NULL) { + if ((loc = get_http_header_value(http_headers->val, "Location: ")) != NULL) { php_url *new_url = php_url_parse(loc); if (new_url != NULL) { - efree(http_headers); + zend_string_release(http_headers); efree(http_body); efree(loc); if (new_url->scheme == NULL && new_url->path != NULL) { @@ -1119,7 +1117,7 @@ try_again: } else if (http_status == 401) { /* Digest authentication */ zval *digest, *login, *password; - char *auth = get_http_header_value(http_headers, "WWW-Authenticate: "); + char *auth = get_http_header_value(http_headers->val, "WWW-Authenticate: "); if (auth && strstr(auth, "Digest") == auth && @@ -1185,7 +1183,7 @@ try_again: phpurl = new_url; efree(auth); - efree(http_headers); + zend_string_release(http_headers); efree(http_body); goto try_again; @@ -1196,7 +1194,7 @@ try_again: smart_str_free(&soap_headers_z); /* Check and see if the server even sent a xml document */ - content_type = get_http_header_value(http_headers,"Content-Type: "); + content_type = get_http_header_value(http_headers->val, "Content-Type: "); if (content_type) { char *pos = NULL; int cmplen; @@ -1216,7 +1214,7 @@ try_again: ZVAL_STRINGL(err, http_body, http_body_size, 1); add_soap_fault(this_ptr, "HTTP", "Didn't receive an xml document", NULL, err TSRMLS_CC); efree(content_type); - efree(http_headers); + zend_string_release(http_headers); efree(http_body); return FALSE; } @@ -1226,7 +1224,7 @@ try_again: } /* Decompress response */ - content_encoding = get_http_header_value(http_headers,"Content-Encoding: "); + content_encoding = get_http_header_value(http_headers->val, "Content-Encoding: "); if (content_encoding) { zval func; zval retval; @@ -1243,7 +1241,7 @@ try_again: ZVAL_STRINGL(¶ms[0], http_body, http_body_size); } else { efree(content_encoding); - efree(http_headers); + zend_string_release(http_headers); efree(http_body); if (http_msg) { efree(http_msg); @@ -1261,7 +1259,7 @@ try_again: zval_ptr_dtor(¶ms[0]); zval_ptr_dtor(&func); efree(content_encoding); - efree(http_headers); + zend_string_release(http_headers); efree(http_body); add_soap_fault(this_ptr, "HTTP", "Can't uncompress compressed response", NULL, NULL TSRMLS_CC); if (http_msg) { @@ -1278,14 +1276,14 @@ try_again: efree(http_body); } - efree(http_headers); + zend_string_release(http_headers); if (http_status >= 400) { int error = 0; - if (Z_STRSIZE_P(return_value) == 0) { + if (Z_STRLEN_P(return_value) == 0) { error = 1; - } else if (Z_STRSIZE_P(return_value) > 0) { + } else if (Z_STRLEN_P(return_value) > 0) { if (!content_type_xml) { char *s = Z_STRVAL_P(return_value); @@ -1486,31 +1484,25 @@ static int get_http_body(php_stream *stream, int close, char *headers, char **r return TRUE; } -static int get_http_headers(php_stream *stream, char **response, int *out_size TSRMLS_DC) +static zend_string *get_http_headers(php_stream *stream TSRMLS_DC) { - int done = FALSE; smart_str tmp_response = {0}; char headerbuf[8192]; - while (!done) { - if (!php_stream_gets(stream, headerbuf, sizeof(headerbuf))) { - break; - } - + while (php_stream_gets(stream, headerbuf, sizeof(headerbuf))) { if ((headerbuf[0] == '\r' && headerbuf[1] == '\n') || (headerbuf[0] == '\n')) { /* empty line marks end of headers */ - done = TRUE; - break; + smart_str_0(&tmp_response); + return tmp_response.s; } /* add header to collection */ smart_str_appends(&tmp_response, headerbuf); } - smart_str_0(&tmp_response); - (*response) = tmp_response.s->val; - (*out_size) = tmp_response.s->len; - return done; + + smart_str_free(&tmp_response); + return NULL; } /* * Local variables: |