summaryrefslogtreecommitdiff
path: root/ext/soap/php_http.c
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2017-08-06 17:48:05 +0800
committerXinchen Hui <laruence@gmail.com>2017-08-06 17:48:05 +0800
commit513b0093c2b480bb752fb354012f42c446769486 (patch)
tree71b34ea413aef37d25f233324122bcdb278b7eda /ext/soap/php_http.c
parent6546c516dd61f7f9efecbd9144c02218614d4c51 (diff)
downloadphp-git-513b0093c2b480bb752fb354012f42c446769486.tar.gz
Refactor php_url struct to save memory dup in common cases
Diffstat (limited to 'ext/soap/php_http.c')
-rw-r--r--ext/soap/php_http.c90
1 files changed, 46 insertions, 44 deletions
diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c
index c0b5f61216..d8d8f95f2b 100644
--- a/ext/soap/php_http.c
+++ b/ext/soap/php_http.c
@@ -179,7 +179,7 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph
port = Z_LVAL_P(proxy_port);
*use_proxy = 1;
} else {
- host = phpurl->host;
+ host = ZSTR_VAL(phpurl->host);
port = phpurl->port;
}
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_connection_timeout", sizeof("_connection_timeout")-1)) != NULL &&
@@ -243,18 +243,18 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph
/* Set peer_name or name verification will try to use the proxy server name */
if (!context || (tmp = php_stream_context_get_option(context, "ssl", "peer_name")) == NULL) {
- ZVAL_STRING(&ssl_proxy_peer_name, phpurl->host);
+ ZVAL_STR_COPY(&ssl_proxy_peer_name, phpurl->host);
php_stream_context_set_option(PHP_STREAM_CONTEXT(stream), "ssl", "peer_name", &ssl_proxy_peer_name);
zval_ptr_dtor(&ssl_proxy_peer_name);
}
smart_str_append_const(&soap_headers, "CONNECT ");
- smart_str_appends(&soap_headers, phpurl->host);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host));
smart_str_appendc(&soap_headers, ':');
smart_str_append_unsigned(&soap_headers, phpurl->port);
smart_str_append_const(&soap_headers, " HTTP/1.1\r\n");
smart_str_append_const(&soap_headers, "Host: ");
- smart_str_appends(&soap_headers, phpurl->host);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host));
if (phpurl->port != 80) {
smart_str_appendc(&soap_headers, ':');
smart_str_append_unsigned(&soap_headers, phpurl->port);
@@ -454,9 +454,9 @@ try_again:
}
use_ssl = 0;
- if (phpurl->scheme != NULL && strcmp(phpurl->scheme, "https") == 0) {
+ if (phpurl->scheme != NULL && zend_string_equals_literal(phpurl->scheme, "https")) {
use_ssl = 1;
- } else if (phpurl->scheme == NULL || strcmp(phpurl->scheme, "http") != 0) {
+ } else if (phpurl->scheme == NULL || !zend_string_equals_literal(phpurl->scheme, "http")) {
php_url_free(phpurl);
if (request != buf) {
zend_string_release(request);
@@ -489,10 +489,10 @@ try_again:
if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")-1)) != NULL &&
(orig = (php_url *) zend_fetch_resource_ex(tmp, "httpurl", le_url)) != NULL &&
((use_proxy && !use_ssl) ||
- (((use_ssl && orig->scheme != NULL && strcmp(orig->scheme, "https") == 0) ||
+ (((use_ssl && orig->scheme != NULL && zend_string_equals_literal(orig->scheme, "https")) ||
(!use_ssl && orig->scheme == NULL) ||
- (!use_ssl && strcmp(orig->scheme, "https") != 0)) &&
- strcmp(orig->host, phpurl->host) == 0 &&
+ (!use_ssl && !zend_string_equals_literal(orig->scheme, "https"))) &&
+ strcmp(ZSTR_VAL(orig->host), ZSTR_VAL(phpurl->host)) == 0 &&
orig->port == phpurl->port))) {
} else {
php_stream_close(stream);
@@ -553,24 +553,24 @@ try_again:
smart_str_append_const(&soap_headers, "POST ");
if (use_proxy && !use_ssl) {
- smart_str_appends(&soap_headers, phpurl->scheme);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->scheme));
smart_str_append_const(&soap_headers, "://");
- smart_str_appends(&soap_headers, phpurl->host);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host));
smart_str_appendc(&soap_headers, ':');
smart_str_append_unsigned(&soap_headers, phpurl->port);
}
if (phpurl->path) {
- smart_str_appends(&soap_headers, phpurl->path);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->path));
} else {
smart_str_appendc(&soap_headers, '/');
}
if (phpurl->query) {
smart_str_appendc(&soap_headers, '?');
- smart_str_appends(&soap_headers, phpurl->query);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->query));
}
if (phpurl->fragment) {
smart_str_appendc(&soap_headers, '#');
- smart_str_appends(&soap_headers, phpurl->fragment);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->fragment));
}
if (http_1_1) {
smart_str_append_const(&soap_headers, " HTTP/1.1\r\n");
@@ -578,7 +578,7 @@ try_again:
smart_str_append_const(&soap_headers, " HTTP/1.0\r\n");
}
smart_str_append_const(&soap_headers, "Host: ");
- smart_str_appends(&soap_headers, phpurl->host);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host));
if (phpurl->port != (use_ssl?443:80)) {
smart_str_appendc(&soap_headers, ':');
smart_str_append_unsigned(&soap_headers, phpurl->port);
@@ -702,13 +702,13 @@ try_again:
PHP_MD5Init(&md5ctx);
PHP_MD5Update(&md5ctx, (unsigned char*)"POST:", sizeof("POST:")-1);
if (phpurl->path) {
- PHP_MD5Update(&md5ctx, (unsigned char*)phpurl->path, strlen(phpurl->path));
+ PHP_MD5Update(&md5ctx, (unsigned char*)ZSTR_VAL(phpurl->path), ZSTR_LEN(phpurl->path));
} else {
PHP_MD5Update(&md5ctx, (unsigned char*)"/", 1);
}
if (phpurl->query) {
PHP_MD5Update(&md5ctx, (unsigned char*)"?", 1);
- PHP_MD5Update(&md5ctx, (unsigned char*)phpurl->query, strlen(phpurl->query));
+ PHP_MD5Update(&md5ctx, (unsigned char*)ZSTR_VAL(phpurl->query), ZSTR_LEN(phpurl->query));
}
PHP_MD5Final(hash, &md5ctx);
@@ -750,17 +750,17 @@ try_again:
}
smart_str_append_const(&soap_headers, "\", uri=\"");
if (phpurl->path) {
- smart_str_appends(&soap_headers, phpurl->path);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->path));
} else {
smart_str_appendc(&soap_headers, '/');
}
if (phpurl->query) {
smart_str_appendc(&soap_headers, '?');
- smart_str_appends(&soap_headers, phpurl->query);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->query));
}
if (phpurl->fragment) {
smart_str_appendc(&soap_headers, '#');
- smart_str_appends(&soap_headers, phpurl->fragment);
+ smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->fragment));
}
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "qop", sizeof("qop")-1)) != NULL &&
Z_TYPE_P(tmp) == IS_STRING) {
@@ -835,10 +835,10 @@ try_again:
zval *tmp;
if (((tmp = zend_hash_index_find(Z_ARRVAL_P(data), 1)) == NULL ||
Z_TYPE_P(tmp) != IS_STRING ||
- strncmp(phpurl->path?phpurl->path:"/",Z_STRVAL_P(tmp),Z_STRLEN_P(tmp)) == 0) &&
+ strncmp(phpurl->path?ZSTR_VAL(phpurl->path):"/",Z_STRVAL_P(tmp),Z_STRLEN_P(tmp)) == 0) &&
((tmp = zend_hash_index_find(Z_ARRVAL_P(data), 2)) == NULL ||
Z_TYPE_P(tmp) != IS_STRING ||
- in_domain(phpurl->host,Z_STRVAL_P(tmp))) &&
+ in_domain(ZSTR_VAL(phpurl->host),Z_STRVAL_P(tmp))) &&
(use_ssl || (tmp = zend_hash_index_find(Z_ARRVAL_P(data), 3)) == NULL)) {
smart_str_append(&soap_headers, key);
smart_str_appendc(&soap_headers, '=');
@@ -1006,14 +1006,15 @@ try_again:
}
}
if (!zend_hash_index_exists(Z_ARRVAL(zcookie), 1)) {
- char *t = phpurl->path?phpurl->path:"/";
+ char *t = phpurl->path?ZSTR_VAL(phpurl->path):"/";
char *c = strrchr(t, '/');
if (c) {
add_index_stringl(&zcookie, 1, t, c-t);
}
}
if (!zend_hash_index_exists(Z_ARRVAL(zcookie), 2)) {
- add_index_string(&zcookie, 2, phpurl->host);
+ add_index_str(&zcookie, 2, phpurl->host);
+ GC_REFCOUNT(phpurl->host)++;
}
zend_symtable_update(Z_ARRVAL_P(cookies), name.s, &zcookie);
@@ -1108,26 +1109,27 @@ try_again:
zend_string_release(http_body);
efree(loc);
if (new_url->scheme == NULL && new_url->path != NULL) {
- new_url->scheme = phpurl->scheme ? estrdup(phpurl->scheme) : NULL;
- new_url->host = phpurl->host ? estrdup(phpurl->host) : NULL;
+ new_url->scheme = phpurl->scheme ? zend_string_copy(phpurl->scheme) : NULL;
+ new_url->host = phpurl->host ? zend_string_copy(phpurl->host) : NULL;
new_url->port = phpurl->port;
- if (new_url->path && new_url->path[0] != '/') {
+ if (new_url->path && ZSTR_VAL(new_url->path)[0] != '/') {
if (phpurl->path) {
- char *t = phpurl->path;
+ char *t = ZSTR_VAL(phpurl->path);
char *p = strrchr(t, '/');
if (p) {
- char *s = emalloc((p - t) + strlen(new_url->path) + 2);
- strncpy(s, t, (p - t) + 1);
- s[(p - t) + 1] = 0;
- strcat(s, new_url->path);
- efree(new_url->path);
+ zend_string *s = zend_string_alloc((p - t) + ZSTR_LEN(new_url->path) + 2, 0);
+ strncpy(ZSTR_VAL(s), t, (p - t) + 1);
+ ZSTR_VAL(s)[(p - t) + 1] = 0;
+ strcat(ZSTR_VAL(s), ZSTR_VAL(new_url->path));
+ zend_string_release(new_url->path);
new_url->path = s;
}
} else {
- char *s = emalloc(strlen(new_url->path) + 2);
- s[0] = '/'; s[1] = 0;
- strcat(s, new_url->path);
- efree(new_url->path);
+ zend_string *s = zend_string_alloc(ZSTR_LEN(new_url->path) + 2, 0);
+ ZSTR_VAL(s)[0] = '/';
+ ZSTR_VAL(s)[1] = 0;
+ strcat(ZSTR_VAL(s), ZSTR_VAL(new_url->path));
+ zend_string_release(new_url->path);
new_url->path = s;
}
}
@@ -1202,13 +1204,13 @@ try_again:
add_property_zval_ex(this_ptr, "_digest", sizeof("_digest")-1, &digest);
*new_url = *phpurl;
- if (phpurl->scheme) phpurl->scheme = estrdup(phpurl->scheme);
- if (phpurl->user) phpurl->user = estrdup(phpurl->user);
- if (phpurl->pass) phpurl->pass = estrdup(phpurl->pass);
- if (phpurl->host) phpurl->host = estrdup(phpurl->host);
- if (phpurl->path) phpurl->path = estrdup(phpurl->path);
- if (phpurl->query) phpurl->query = estrdup(phpurl->query);
- if (phpurl->fragment) phpurl->fragment = estrdup(phpurl->fragment);
+ if (phpurl->scheme) phpurl->scheme = zend_string_copy(phpurl->scheme);
+ if (phpurl->user) phpurl->user = zend_string_copy(phpurl->user);
+ if (phpurl->pass) phpurl->pass = zend_string_copy(phpurl->pass);
+ if (phpurl->host) phpurl->host = zend_string_copy(phpurl->host);
+ if (phpurl->path) phpurl->path = zend_string_copy(phpurl->path);
+ if (phpurl->query) phpurl->query = zend_string_copy(phpurl->query);
+ if (phpurl->fragment) phpurl->fragment = zend_string_copy(phpurl->fragment);
phpurl = new_url;
efree(auth);