dmitry Fri Jul 8 05:36:43 2005 EDT Modified files: (Branch: PHP_5_0) /php-src/ext/soap php_http.c php_http.h php_sdl.c Log: Fixed HTTP basic authentication headers during subrequsts to xsd files http://cvs.php.net/diff.php/php-src/ext/soap/php_http.c?r1=1.55.2.18&r2=1.55.2.19&ty=u Index: php-src/ext/soap/php_http.c diff -u php-src/ext/soap/php_http.c:1.55.2.18 php-src/ext/soap/php_http.c:1.55.2.19 --- php-src/ext/soap/php_http.c:1.55.2.18 Mon May 30 19:46:28 2005 +++ php-src/ext/soap/php_http.c Fri Jul 8 05:36:42 2005 @@ -17,7 +17,7 @@ | Dmitry Stogov <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: php_http.c,v 1.55.2.18 2005/05/30 23:46:28 iliaa Exp $ */ +/* $Id: php_http.c,v 1.55.2.19 2005/07/08 09:36:42 dmitry Exp $ */ #include "php_soap.h" #include "ext/standard/base64.h" @@ -55,7 +55,7 @@ } /* Proxy HTTP Authentication */ -static void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) +void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) { zval **login, **password; @@ -79,6 +79,32 @@ } } +/* HTTP Authentication */ +void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) +{ + 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"))) { + char* buf; + int len; + smart_str auth = {0}; + + smart_str_appendl(&auth, Z_STRVAL_PP(login), Z_STRLEN_PP(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)); + } + smart_str_0(&auth); + buf = php_base64_encode(auth.c, auth.len, &len); + smart_str_append_const(soap_headers, "Authorization: Basic "); + smart_str_appendl(soap_headers, buf, len); + smart_str_append_const(soap_headers, "\r\n"); + efree(buf); + smart_str_free(&auth); + } +} + static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, int *use_proxy TSRMLS_DC) { php_stream *stream; http://cvs.php.net/diff.php/php-src/ext/soap/php_http.h?r1=1.14&r2=1.14.2.1&ty=u Index: php-src/ext/soap/php_http.h diff -u php-src/ext/soap/php_http.h:1.14 php-src/ext/soap/php_http.h:1.14.2.1 --- php-src/ext/soap/php_http.h:1.14 Mon Jun 21 08:56:33 2004 +++ php-src/ext/soap/php_http.h Fri Jul 8 05:36:42 2005 @@ -17,7 +17,7 @@ | Dmitry Stogov <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: php_http.h,v 1.14 2004/06/21 12:56:33 dmitry Exp $ */ +/* $Id: php_http.h,v 1.14.2.1 2005/07/08 09:36:42 dmitry Exp $ */ #ifndef PHP_HTTP_H #define PHP_HTTP_H @@ -31,4 +31,6 @@ char **response, int *response_len TSRMLS_DC); +void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC); +void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC); #endif http://cvs.php.net/diff.php/php-src/ext/soap/php_sdl.c?r1=1.70.2.11&r2=1.70.2.12&ty=u Index: php-src/ext/soap/php_sdl.c diff -u php-src/ext/soap/php_sdl.c:1.70.2.11 php-src/ext/soap/php_sdl.c:1.70.2.12 --- php-src/ext/soap/php_sdl.c:1.70.2.11 Wed Jun 1 10:42:50 2005 +++ php-src/ext/soap/php_sdl.c Fri Jul 8 05:36:42 2005 @@ -17,7 +17,7 @@ | Dmitry Stogov <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: php_sdl.c,v 1.70.2.11 2005/06/01 14:42:50 dmitry Exp $ */ +/* $Id: php_sdl.c,v 1.70.2.12 2005/07/08 09:36:42 dmitry Exp $ */ #include "php_soap.h" #include "ext/libxml/php_libxml.h" @@ -206,46 +206,13 @@ xmlDocPtr wsdl; xmlNodePtr root, definitions, trav; xmlAttrPtr targetNamespace; - php_stream_context *context=NULL; - zval **proxy_host, **proxy_port, *orig_context, *new_context; if (zend_hash_exists(&ctx->docs, struri, strlen(struri)+1)) { return; } - - 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) { - zval str_port, *str_proxy; - smart_str proxy = {0}; - str_port = **proxy_port; - zval_copy_ctor(&str_port); - convert_to_string(&str_port); - smart_str_appends(&proxy,"tcp://"); - smart_str_appends(&proxy,Z_STRVAL_PP(proxy_host)); - smart_str_appends(&proxy,":"); - smart_str_appends(&proxy,Z_STRVAL(str_port)); - zval_dtor(&str_port); - MAKE_STD_ZVAL(str_proxy); - ZVAL_STRING(str_proxy, proxy.c, 1); - smart_str_free(&proxy); - - context = php_stream_context_alloc(); - php_stream_context_set_option(context, "http", "proxy", str_proxy); - zval_ptr_dtor(&str_proxy); - MAKE_STD_ZVAL(new_context); - php_stream_context_to_zval(context, new_context); - orig_context = php_libxml_switch_context(new_context TSRMLS_CC); - } wsdl = soap_xmlParseFile(struri); - if (context) { - php_libxml_switch_context(orig_context TSRMLS_CC); - zval_ptr_dtor(&new_context); - } - if (!wsdl) { soap_error1(E_ERROR, "Parsing WSDL: Couldn't load from '%s'", struri); } @@ -2246,6 +2213,57 @@ sdlPtr sdl = NULL; char* old_error_code = SOAP_GLOBAL(error_code); int uri_len; + php_stream_context *context=NULL; + zval **proxy_host, **proxy_port, *orig_context, *new_context; + smart_str headers = {0}; + + 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) { + zval str_port, *str_proxy; + smart_str proxy = {0}; + str_port = **proxy_port; + zval_copy_ctor(&str_port); + convert_to_string(&str_port); + smart_str_appends(&proxy,"tcp://"); + smart_str_appends(&proxy,Z_STRVAL_PP(proxy_host)); + smart_str_appends(&proxy,":"); + smart_str_appends(&proxy,Z_STRVAL(str_port)); + zval_dtor(&str_port); + MAKE_STD_ZVAL(str_proxy); + ZVAL_STRING(str_proxy, proxy.c, 1); + smart_str_free(&proxy); + + context = php_stream_context_alloc(); + php_stream_context_set_option(context, "http", "proxy", str_proxy); + zval_ptr_dtor(&str_proxy); + + proxy_authentication(this_ptr, &headers TSRMLS_CC); + } + + basic_authentication(this_ptr, &headers TSRMLS_CC); + + if (headers.len > 0) { + zval *str_headers; + + if (!context) { + context = php_stream_context_alloc(); + } + + smart_str_0(&headers); + MAKE_STD_ZVAL(str_headers); + ZVAL_STRING(str_headers, headers.c, 1); + php_stream_context_set_option(context, "http", "header", str_headers); + smart_str_free(&headers); + zval_ptr_dtor(&str_headers); + } + + if (context) { + MAKE_STD_ZVAL(new_context); + php_stream_context_to_zval(context, new_context); + orig_context = php_libxml_switch_context(new_context TSRMLS_CC); + } SOAP_GLOBAL(error_code) = "WSDL"; @@ -2286,7 +2304,14 @@ } else { sdl = load_wsdl(this_ptr, uri TSRMLS_CC); } + SOAP_GLOBAL(error_code) = old_error_code; + + if (context) { + php_libxml_switch_context(orig_context TSRMLS_CC); + zval_ptr_dtor(&new_context); + } + return sdl; }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php