Skip to content

Commit a8cc0b0

Browse files
committed
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
2 parents 1e18f11 + 657547f commit a8cc0b0

File tree

4 files changed

+94
-68
lines changed

4 files changed

+94
-68
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ PHP NEWS
7373
User-Agent header). (carloschilazo at gmail dot com)
7474
. Fixed bug #60842, #51775 (Chunked response parsing error when
7575
chunksize length line is > 10 bytes). (Ilia)
76+
. Fixed bug #49853 (Soap Client stream context header option ignored).
77+
(Dmitry)
7678

7779
- PDO
7880
. Fixed bug #61292 (Segfault while calling a method on an overloaded PDO

ext/soap/php_http.c

Lines changed: 78 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int get_http_headers(php_stream *socketd,char **response, int *out_size T
3232
smart_str_appendl(str,const,sizeof(const)-1)
3333

3434
/* Proxy HTTP Authentication */
35-
void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
35+
int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
3636
{
3737
zval **login, **password;
3838

@@ -53,11 +53,13 @@ void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
5353
smart_str_append_const(soap_headers, "\r\n");
5454
efree(buf);
5555
smart_str_free(&auth);
56+
return 1;
5657
}
58+
return 0;
5759
}
5860

5961
/* HTTP Authentication */
60-
void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
62+
int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
6163
{
6264
zval **login, **password;
6365

@@ -79,6 +81,78 @@ void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
7981
smart_str_append_const(soap_headers, "\r\n");
8082
efree(buf);
8183
smart_str_free(&auth);
84+
return 1;
85+
}
86+
return 0;
87+
}
88+
89+
/* Additional HTTP headers */
90+
void http_context_headers(php_stream_context* context,
91+
zend_bool has_authorization,
92+
zend_bool has_proxy_authorization,
93+
zend_bool has_cookies,
94+
smart_str* soap_headers TSRMLS_DC)
95+
{
96+
zval **tmp;
97+
98+
if (context &&
99+
php_stream_context_get_option(context, "http", "header", &tmp) == SUCCESS &&
100+
Z_TYPE_PP(tmp) == IS_STRING && Z_STRLEN_PP(tmp)) {
101+
char *s = Z_STRVAL_PP(tmp);
102+
char *p;
103+
int name_len;
104+
105+
while (*s) {
106+
/* skip leading newlines and spaces */
107+
while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
108+
s++;
109+
}
110+
/* extract header name */
111+
p = s;
112+
name_len = -1;
113+
while (*p) {
114+
if (*p == ':') {
115+
if (name_len < 0) name_len = p - s;
116+
break;
117+
} else if (*p == ' ' || *p == '\t') {
118+
if (name_len < 0) name_len = p - s;
119+
} else if (*p == '\r' || *p == '\n') {
120+
break;
121+
}
122+
p++;
123+
}
124+
if (*p == ':') {
125+
/* extract header value */
126+
while (*p && *p != '\r' && *p != '\n') {
127+
p++;
128+
}
129+
/* skip some predefined headers */
130+
if ((name_len != sizeof("host")-1 ||
131+
strncasecmp(s, "host", sizeof("host")-1) != 0) &&
132+
(name_len != sizeof("connection")-1 ||
133+
strncasecmp(s, "connection", sizeof("connection")-1) != 0) &&
134+
(name_len != sizeof("user-agent")-1 ||
135+
strncasecmp(s, "user-agent", sizeof("user-agent")-1) != 0) &&
136+
(name_len != sizeof("content-length")-1 ||
137+
strncasecmp(s, "content-length", sizeof("content-length")-1) != 0) &&
138+
(name_len != sizeof("content-type")-1 ||
139+
strncasecmp(s, "content-type", sizeof("content-type")-1) != 0) &&
140+
(!has_cookies ||
141+
name_len != sizeof("cookie")-1 ||
142+
strncasecmp(s, "cookie", sizeof("cookie")-1) != 0) &&
143+
(!has_authorization ||
144+
name_len != sizeof("authorization")-1 ||
145+
strncasecmp(s, "authorization", sizeof("authorization")-1) != 0) &&
146+
(!has_proxy_authorization ||
147+
name_len != sizeof("proxy-authorization")-1 ||
148+
strncasecmp(s, "proxy-authorization", sizeof("proxy-authorization")-1) != 0)) {
149+
/* add header */
150+
smart_str_appendl(soap_headers, s, p-s);
151+
smart_str_append_const(soap_headers, "\r\n");
152+
}
153+
}
154+
s = (*p) ? (p + 1) : p;
155+
}
82156
}
83157
}
84158

@@ -664,8 +738,7 @@ int make_http_soap_request(zval *this_ptr,
664738

665739
/* Proxy HTTP Authentication */
666740
if (use_proxy && !use_ssl) {
667-
has_proxy_authorization = 1;
668-
proxy_authentication(this_ptr, &soap_headers TSRMLS_CC);
741+
has_proxy_authorization = proxy_authentication(this_ptr, &soap_headers TSRMLS_CC);
669742
}
670743

671744
/* Send cookies along with request */
@@ -707,65 +780,7 @@ int make_http_soap_request(zval *this_ptr,
707780
}
708781
}
709782

710-
if (context &&
711-
php_stream_context_get_option(context, "http", "header", &tmp) == SUCCESS &&
712-
Z_TYPE_PP(tmp) == IS_STRING && Z_STRLEN_PP(tmp)) {
713-
char *s = Z_STRVAL_PP(tmp);
714-
char *p;
715-
int name_len;
716-
717-
while (*s) {
718-
/* skip leading newlines and spaces */
719-
while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
720-
s++;
721-
}
722-
/* extract header name */
723-
p = s;
724-
name_len = -1;
725-
while (*p) {
726-
if (*p == ':') {
727-
if (name_len < 0) name_len = p - s;
728-
break;
729-
} else if (*p == ' ' || *p == '\t') {
730-
if (name_len < 0) name_len = p - s;
731-
} else if (*p == '\r' || *p == '\n') {
732-
break;
733-
}
734-
p++;
735-
}
736-
if (*p == ':') {
737-
/* extract header value */
738-
while (*p && *p != '\r' && *p != '\n') {
739-
p++;
740-
}
741-
/* skip some predefined headers */
742-
if ((name_len != sizeof("host")-1 ||
743-
strncasecmp(s, "host", sizeof("host")-1) != 0) &&
744-
(name_len != sizeof("connection")-1 ||
745-
strncasecmp(s, "connection", sizeof("connection")-1) != 0) &&
746-
(name_len != sizeof("user-agent")-1 ||
747-
strncasecmp(s, "user-agent", sizeof("user-agent")-1) != 0) &&
748-
(name_len != sizeof("content-length")-1 ||
749-
strncasecmp(s, "content-length", sizeof("content-length")-1) != 0) &&
750-
(name_len != sizeof("content-type")-1 ||
751-
strncasecmp(s, "content-type", sizeof("content-type")-1) != 0) &&
752-
(!has_cookies ||
753-
name_len != sizeof("cookie")-1 ||
754-
strncasecmp(s, "cookie", sizeof("cookie")-1) != 0) &&
755-
(!has_authorization ||
756-
name_len != sizeof("authorization")-1 ||
757-
strncasecmp(s, "authorization", sizeof("authorization")-1) != 0) &&
758-
(!has_proxy_authorization ||
759-
name_len != sizeof("proxy-authorization")-1 ||
760-
strncasecmp(s, "proxy-authorization", sizeof("proxy-authorization")-1) != 0)) {
761-
/* add header */
762-
smart_str_appendl(&soap_headers, s, p-s);
763-
smart_str_append_const(&soap_headers, "\r\n");
764-
}
765-
}
766-
s = (*p) ? (p + 1) : p;
767-
}
768-
}
783+
http_context_headers(context, has_authorization, has_proxy_authorization, has_cookies, &soap_headers TSRMLS_CC);
769784

770785
smart_str_append_const(&soap_headers, "\r\n");
771786
smart_str_0(&soap_headers);

ext/soap/php_http.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ int make_http_soap_request(zval *this_ptr,
3131
char **response,
3232
int *response_len TSRMLS_DC);
3333

34-
void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
35-
void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
34+
int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
35+
int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
36+
void http_context_headers(php_stream_context* context,
37+
zend_bool has_authorization,
38+
zend_bool has_proxy_authorization,
39+
zend_bool has_cookies,
40+
smart_str* soap_headers TSRMLS_DC);
3641
#endif

ext/soap/php_sdl.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,8 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl TSRMLS_DC)
31963196
smart_str headers = {0};
31973197
char* key = NULL;
31983198
time_t t = time(0);
3199+
zend_bool has_proxy_authorization = 0;
3200+
zend_bool has_authorization = 0;
31993201

32003202
if (strchr(uri,':') != NULL || IS_ABSOLUTE_PATH(uri, uri_len)) {
32013203
uri_len = strlen(uri);
@@ -3299,10 +3301,10 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl TSRMLS_DC)
32993301
zval_ptr_dtor(&str_proxy);
33003302
}
33013303

3302-
proxy_authentication(this_ptr, &headers TSRMLS_CC);
3304+
has_proxy_authorization = proxy_authentication(this_ptr, &headers TSRMLS_CC);
33033305
}
33043306

3305-
basic_authentication(this_ptr, &headers TSRMLS_CC);
3307+
has_authorization = basic_authentication(this_ptr, &headers TSRMLS_CC);
33063308

33073309
/* Use HTTP/1.1 with "Connection: close" by default */
33083310
if (php_stream_context_get_option(context, "http", "protocol_version", &tmp) == FAILURE) {
@@ -3311,14 +3313,16 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl TSRMLS_DC)
33113313
ZVAL_DOUBLE(http_version, 1.1);
33123314
php_stream_context_set_option(context, "http", "protocol_version", http_version);
33133315
zval_ptr_dtor(&http_version);
3314-
smart_str_appendl(&headers, "Connection: close", sizeof("Connection: close")-1);
3316+
smart_str_appendl(&headers, "Connection: close\r\n", sizeof("Connection: close\r\n")-1);
33153317
}
33163318

33173319
if (headers.len > 0) {
33183320
zval *str_headers;
33193321

33203322
if (!context) {
33213323
context = php_stream_context_alloc(TSRMLS_C);
3324+
} else {
3325+
http_context_headers(context, has_authorization, has_proxy_authorization, 0, &headers TSRMLS_CC);
33223326
}
33233327

33243328
smart_str_0(&headers);

0 commit comments

Comments
 (0)