summaryrefslogtreecommitdiff
path: root/ext/soap/php_http.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2012-03-21 16:42:08 +0400
committerDmitry Stogov <dmitry@zend.com>2012-03-21 16:42:08 +0400
commita8cc0b05b45110ccf408ea9410447bf82b8826f2 (patch)
treee0cae83e715042a6122cac2fbe736f48158a94ae /ext/soap/php_http.c
parent1e18f11c9ab56fb120c9e26ecd3f68f0651cddde (diff)
parent657547f8c4758efcf85c73fec6d7fd8b3983d7cb (diff)
downloadphp-git-a8cc0b05b45110ccf408ea9410447bf82b8826f2.tar.gz
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Fixed bug #49853 (Soap Client stream context header option ignored) Conflicts: NEWS ext/soap/php_sdl.c
Diffstat (limited to 'ext/soap/php_http.c')
-rw-r--r--ext/soap/php_http.c141
1 files changed, 78 insertions, 63 deletions
diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c
index 2933576ed8..a15648808d 100644
--- a/ext/soap/php_http.c
+++ b/ext/soap/php_http.c
@@ -32,7 +32,7 @@ static int get_http_headers(php_stream *socketd,char **response, int *out_size T
smart_str_appendl(str,const,sizeof(const)-1)
/* Proxy HTTP Authentication */
-void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
+int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
{
zval **login, **password;
@@ -53,11 +53,13 @@ void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
smart_str_append_const(soap_headers, "\r\n");
efree(buf);
smart_str_free(&auth);
+ return 1;
}
+ return 0;
}
/* HTTP Authentication */
-void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
+int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
{
zval **login, **password;
@@ -79,6 +81,78 @@ void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
smart_str_append_const(soap_headers, "\r\n");
efree(buf);
smart_str_free(&auth);
+ return 1;
+ }
+ return 0;
+}
+
+/* Additional HTTP headers */
+void http_context_headers(php_stream_context* context,
+ zend_bool has_authorization,
+ zend_bool has_proxy_authorization,
+ zend_bool has_cookies,
+ smart_str* soap_headers TSRMLS_DC)
+{
+ 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);
+ char *p;
+ int name_len;
+
+ while (*s) {
+ /* skip leading newlines and spaces */
+ while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
+ s++;
+ }
+ /* extract header name */
+ p = s;
+ name_len = -1;
+ while (*p) {
+ if (*p == ':') {
+ if (name_len < 0) name_len = p - s;
+ break;
+ } else if (*p == ' ' || *p == '\t') {
+ if (name_len < 0) name_len = p - s;
+ } else if (*p == '\r' || *p == '\n') {
+ break;
+ }
+ p++;
+ }
+ if (*p == ':') {
+ /* extract header value */
+ while (*p && *p != '\r' && *p != '\n') {
+ p++;
+ }
+ /* skip some predefined headers */
+ if ((name_len != sizeof("host")-1 ||
+ strncasecmp(s, "host", sizeof("host")-1) != 0) &&
+ (name_len != sizeof("connection")-1 ||
+ strncasecmp(s, "connection", sizeof("connection")-1) != 0) &&
+ (name_len != sizeof("user-agent")-1 ||
+ strncasecmp(s, "user-agent", sizeof("user-agent")-1) != 0) &&
+ (name_len != sizeof("content-length")-1 ||
+ strncasecmp(s, "content-length", sizeof("content-length")-1) != 0) &&
+ (name_len != sizeof("content-type")-1 ||
+ strncasecmp(s, "content-type", sizeof("content-type")-1) != 0) &&
+ (!has_cookies ||
+ name_len != sizeof("cookie")-1 ||
+ strncasecmp(s, "cookie", sizeof("cookie")-1) != 0) &&
+ (!has_authorization ||
+ name_len != sizeof("authorization")-1 ||
+ strncasecmp(s, "authorization", sizeof("authorization")-1) != 0) &&
+ (!has_proxy_authorization ||
+ name_len != sizeof("proxy-authorization")-1 ||
+ strncasecmp(s, "proxy-authorization", sizeof("proxy-authorization")-1) != 0)) {
+ /* add header */
+ smart_str_appendl(soap_headers, s, p-s);
+ smart_str_append_const(soap_headers, "\r\n");
+ }
+ }
+ s = (*p) ? (p + 1) : p;
+ }
}
}
@@ -664,8 +738,7 @@ try_again:
/* Proxy HTTP Authentication */
if (use_proxy && !use_ssl) {
- has_proxy_authorization = 1;
- proxy_authentication(this_ptr, &soap_headers TSRMLS_CC);
+ has_proxy_authorization = proxy_authentication(this_ptr, &soap_headers TSRMLS_CC);
}
/* Send cookies along with request */
@@ -707,65 +780,7 @@ try_again:
}
}
- 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);
- char *p;
- int name_len;
-
- while (*s) {
- /* skip leading newlines and spaces */
- while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
- s++;
- }
- /* extract header name */
- p = s;
- name_len = -1;
- while (*p) {
- if (*p == ':') {
- if (name_len < 0) name_len = p - s;
- break;
- } else if (*p == ' ' || *p == '\t') {
- if (name_len < 0) name_len = p - s;
- } else if (*p == '\r' || *p == '\n') {
- break;
- }
- p++;
- }
- if (*p == ':') {
- /* extract header value */
- while (*p && *p != '\r' && *p != '\n') {
- p++;
- }
- /* skip some predefined headers */
- if ((name_len != sizeof("host")-1 ||
- strncasecmp(s, "host", sizeof("host")-1) != 0) &&
- (name_len != sizeof("connection")-1 ||
- strncasecmp(s, "connection", sizeof("connection")-1) != 0) &&
- (name_len != sizeof("user-agent")-1 ||
- strncasecmp(s, "user-agent", sizeof("user-agent")-1) != 0) &&
- (name_len != sizeof("content-length")-1 ||
- strncasecmp(s, "content-length", sizeof("content-length")-1) != 0) &&
- (name_len != sizeof("content-type")-1 ||
- strncasecmp(s, "content-type", sizeof("content-type")-1) != 0) &&
- (!has_cookies ||
- name_len != sizeof("cookie")-1 ||
- strncasecmp(s, "cookie", sizeof("cookie")-1) != 0) &&
- (!has_authorization ||
- name_len != sizeof("authorization")-1 ||
- strncasecmp(s, "authorization", sizeof("authorization")-1) != 0) &&
- (!has_proxy_authorization ||
- name_len != sizeof("proxy-authorization")-1 ||
- strncasecmp(s, "proxy-authorization", sizeof("proxy-authorization")-1) != 0)) {
- /* add header */
- smart_str_appendl(&soap_headers, s, p-s);
- smart_str_append_const(&soap_headers, "\r\n");
- }
- }
- s = (*p) ? (p + 1) : p;
- }
- }
+ http_context_headers(context, has_authorization, has_proxy_authorization, has_cookies, &soap_headers TSRMLS_CC);
smart_str_append_const(&soap_headers, "\r\n");
smart_str_0(&soap_headers);