dmitry          Fri Apr  2 06:12:45 2004 EDT

  Modified files:              
    /php-src/ext/soap   php_http.c php_soap.h soap.c 
  Log:
  SoapClint support for multiple hosts (through WSDL) with cookies.
  
  
http://cvs.php.net/diff.php/php-src/ext/soap/php_http.c?r1=1.47&r2=1.48&ty=u
Index: php-src/ext/soap/php_http.c
diff -u php-src/ext/soap/php_http.c:1.47 php-src/ext/soap/php_http.c:1.48
--- php-src/ext/soap/php_http.c:1.47    Thu Apr  1 05:47:43 2004
+++ php-src/ext/soap/php_http.c Fri Apr  2 06:12:43 2004
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: php_http.c,v 1.47 2004/04/01 10:47:43 dmitry Exp $ */
+/* $Id: php_http.c,v 1.48 2004/04/02 11:12:43 dmitry Exp $ */
 
 #include "php_soap.h"
 #include "ext/standard/base64.h"
@@ -205,19 +205,13 @@
                add_property_stringl(this_ptr, "__last_request", buf, buf_size, 1);
        }
 
-       /* Check if keep-alive connection is still opened */
-       if (stream != NULL && !stream_alive(stream TSRMLS_CC)) {
-               php_stream_close(stream);
-               zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", 
sizeof("httpsocket"));
-               zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", 
sizeof("_use_proxy"));
-               stream = NULL;
-               use_proxy = 0;
-       }
-
        if (location != NULL && location[0] != '\000') {
                phpurl = php_url_parse(location);
        }
-       if (phpurl == NULL) {
+       if (phpurl == NULL || phpurl->host == NULL) {
+         if (phpurl != NULL) {
+               php_url_free(phpurl);
+         }
                xmlFree(buf);
                add_soap_fault(this_ptr, "HTTP", "Unable to parse URL", NULL, NULL 
TSRMLS_CC);
                return FALSE;
@@ -254,6 +248,37 @@
                phpurl->port = use_ssl ? 443 : 80;
        }
 
+       /* Check if request to the same host */
+       if (stream != NULL) {
+         php_url *orig;
+               if (zend_hash_find(Z_OBJPROP_P(this_ptr), "httpurl", 
sizeof("httpurl"), (void **)&tmp) == SUCCESS &&
+                   (orig = (php_url *) zend_fetch_resource(tmp TSRMLS_CC, -1, 
"httpurl", NULL, 1, le_url)) != NULL &&
+                   ((use_proxy && !use_ssl) ||
+                    (((use_ssl && orig->scheme != NULL && strcmp(orig->scheme, 
"https") == 0) ||
+                     (!use_ssl && orig->scheme == NULL) ||
+                     (!use_ssl && strcmp(orig->scheme, "https") != 0)) &&
+                    strcmp(orig->host, phpurl->host) == 0 &&
+                    orig->port == phpurl->port))) {
+    } else {
+                       php_stream_close(stream);
+                       zend_hash_del(Z_OBJPROP_P(this_ptr), "httpurl", 
sizeof("httpurl"));
+                       zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", 
sizeof("httpsocket"));
+                       zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", 
sizeof("_use_proxy"));
+                       stream = NULL;
+                       use_proxy = 0;
+    }
+       }
+
+       /* Check if keep-alive connection is still opened */
+       if (stream != NULL && !stream_alive(stream TSRMLS_CC)) {
+               php_stream_close(stream);
+               zend_hash_del(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl"));
+               zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", 
sizeof("httpsocket"));
+               zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", 
sizeof("_use_proxy"));
+               stream = NULL;
+               use_proxy = 0;
+       }
+
        if (!stream) {
                stream = http_connect(this_ptr, phpurl, use_ssl, &use_proxy TSRMLS_CC);
                if (stream) {
@@ -270,6 +295,10 @@
 
        if (stream) {
                zval **cookies, **login, **password;
+         int ret = zend_list_insert(phpurl, le_url);
+
+               add_property_resource(this_ptr, "httpurl", ret);
+               /*zend_list_addref(ret);*/
 
                smart_str_append_const(&soap_headers, "POST ");
                if (use_proxy && !use_ssl) {
@@ -347,15 +376,15 @@
                                        request = Z_STRVAL(retval);
                                        request_size = Z_STRLEN(retval);
                                } else {
-                       php_url_free(phpurl);
-                       if (request != buf) {efree(request);}
-                       xmlFree(buf);
-                       smart_str_free(&soap_headers);
-                       php_stream_close(stream);
-                       zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", 
sizeof("httpsocket"));
-                       zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", 
sizeof("_use_proxy"));
-                       add_soap_fault(this_ptr, "HTTP", "Compression Failed", NULL, 
NULL TSRMLS_CC);
-                       return FALSE;
+                                       if (request != buf) {efree(request);}
+                                       xmlFree(buf);
+                                       smart_str_free(&soap_headers);
+                                       php_stream_close(stream);
+                                       zend_hash_del(Z_OBJPROP_P(this_ptr), 
"httpurl", sizeof("httpurl"));
+                                       zend_hash_del(Z_OBJPROP_P(this_ptr), 
"httpsocket", sizeof("httpsocket"));
+                                       zend_hash_del(Z_OBJPROP_P(this_ptr), 
"_use_proxy", sizeof("_use_proxy"));
+                                       add_soap_fault(this_ptr, "HTTP", "Compression 
Failed", NULL, NULL TSRMLS_CC);
+                                       return FALSE;
                                }
                  }
                }
@@ -402,26 +431,45 @@
                                        
zend_hash_get_current_data(Z_ARRVAL_PP(cookies), (void **)&data);
                                        
zend_hash_get_current_key(Z_ARRVAL_PP(cookies), &key, NULL, FALSE);
 
-                                       smart_str_appendl(&soap_headers, key, 
strlen(key));
-                                       smart_str_appendc(&soap_headers, '=');
-                                       smart_str_appendl(&soap_headers, 
Z_STRVAL_PP(data), Z_STRLEN_PP(data));
-                                       smart_str_append_const(&soap_headers, ";");
+                                       if (Z_TYPE_PP(data) == IS_ARRAY) {
+                                         zval** value;
+
+                                               if 
(zend_hash_index_find(Z_ARRVAL_PP(data), 0, (void**)&value) == SUCCESS &&
+                                                   Z_TYPE_PP(value) == IS_STRING) {
+                                                 zval **tmp;
+                                                 if 
(zend_hash_index_find(Z_ARRVAL_PP(data), 1, (void**)&tmp) == SUCCESS &&
+                                                     
strncmp(phpurl->path,Z_STRVAL_PP(tmp),Z_STRLEN_PP(tmp)) == 0 &&
+                                                     
zend_hash_index_find(Z_ARRVAL_PP(data), 2, (void**)&tmp) == SUCCESS &&
+                                                     
strcmp(phpurl->host,Z_STRVAL_PP(tmp)) == 0 &&
+                                                     (use_ssl || 
zend_hash_index_find(Z_ARRVAL_PP(data), 3, (void**)&tmp) == FAILURE)) {
+                                                               
smart_str_appendl(&soap_headers, key, strlen(key));
+                                                               
smart_str_appendc(&soap_headers, '=');
+                                                               
smart_str_appendl(&soap_headers, Z_STRVAL_PP(value), Z_STRLEN_PP(value));
+                                                               
smart_str_appendc(&soap_headers, ';');
+                                                       }
+                                               }
+                                       }
                                        zend_hash_move_forward(Z_ARRVAL_PP(cookies));
                                }
                                smart_str_append_const(&soap_headers, "\r\n");
                        }
                }
                smart_str_append_const(&soap_headers, "\r\n");
+               smart_str_0(&soap_headers);
+               if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), 
(void **) &trace) == SUCCESS &&
+                   Z_LVAL_PP(trace) > 0) {
+                       add_property_stringl(this_ptr, "__last_request_headers", 
soap_headers.c, soap_headers.len, 1);
+               }
                smart_str_appendl(&soap_headers, request, request_size);
                smart_str_0(&soap_headers);
 
                err = php_stream_write(stream, soap_headers.c, soap_headers.len);
                if (err != soap_headers.len) {
-                       php_url_free(phpurl);
                        if (request != buf) {efree(request);}
                        xmlFree(buf);
                        smart_str_free(&soap_headers);
                        php_stream_close(stream);
+                       zend_hash_del(Z_OBJPROP_P(this_ptr), "httpurl", 
sizeof("httpurl"));
                        zend_hash_del(Z_OBJPROP_P(this_ptr), "httpsocket", 
sizeof("httpsocket"));
                        zend_hash_del(Z_OBJPROP_P(this_ptr), "_use_proxy", 
sizeof("_use_proxy"));
                        add_soap_fault(this_ptr, "HTTP", "Failed Sending HTTP SOAP 
request", NULL, NULL TSRMLS_CC);
@@ -430,7 +478,6 @@
                smart_str_free(&soap_headers);
 
        }
-       php_url_free(phpurl);
        if (request != buf) {efree(request);}
        xmlFree(buf);
        return TRUE;
@@ -464,6 +511,11 @@
                return FALSE;
        }
 
+       if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) 
&trace) == SUCCESS &&
+           Z_LVAL_PP(trace) > 0) {
+               add_property_stringl(this_ptr, "__last_response_headers", 
http_headers, http_header_size, 1);
+       }
+
        /* Check to see what HTTP status was sent */
        http_version = get_http_header_value(http_headers,"HTTP/");
        if (http_version) {
@@ -597,50 +649,86 @@
           matter too much
        */
        cookie_itt = strstr(http_headers,"Set-Cookie: ");
-       while (cookie_itt) {
-               char *end_pos, *cookie;
-               char *eqpos, *sempos;
-               smart_str name = {0}, value = {0};
-               zval **cookies, *z_cookie;
-
-               if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", 
sizeof("_cookies"), (void **)&cookies) == FAILURE) {
-                       zval *tmp_cookies;
-                       MAKE_STD_ZVAL(tmp_cookies);
-                       array_init(tmp_cookies);
-                       zend_hash_update(Z_OBJPROP_P(this_ptr), "_cookies", 
sizeof("_cookies"), &tmp_cookies, sizeof(zval *), (void **)&cookies);
-               }
-
-               end_pos = strstr(cookie_itt,"\r\n");
-               cookie = get_http_header_value(cookie_itt,"Set-Cookie: ");
-
-               eqpos = strstr(cookie, "=");
-               sempos = strstr(cookie, ";");
-               if (eqpos != NULL && (sempos == NULL || sempos > eqpos)) {
-                       int cookie_len;
+       if (cookie_itt &&
+                 zend_hash_find(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl"), 
(void **)&tmp) == SUCCESS) {
 
-                       if (sempos != NULL) {
-                               cookie_len = sempos-(eqpos+1);
-                       } else {
-                               cookie_len = strlen(cookie)-(eqpos-cookie)-1;
-                       }
-
-                       smart_str_appendl(&name, cookie, eqpos - cookie);
-                       smart_str_0(&name);
+         php_url *phpurl = (php_url*)zend_fetch_resource(tmp TSRMLS_CC, -1, 
"httpurl", NULL, 1, le_url);
 
-                       smart_str_appendl(&value, eqpos + 1, cookie_len);
-                       smart_str_0(&value);
+         if (phpurl) {
+                       while (cookie_itt) {
+                               char *end_pos, *cookie;
+                               char *eqpos, *sempos;
+                               zval **cookies;
+
+                               if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", 
sizeof("_cookies"), (void **)&cookies) == FAILURE) {
+                                       zval *tmp_cookies;
+                                       MAKE_STD_ZVAL(tmp_cookies);
+                                       array_init(tmp_cookies);
+                                       zend_hash_update(Z_OBJPROP_P(this_ptr), 
"_cookies", sizeof("_cookies"), &tmp_cookies, sizeof(zval *), (void **)&cookies);
+                               }
 
-                       MAKE_STD_ZVAL(z_cookie);
-                       ZVAL_STRINGL(z_cookie, value.c, value.len, 1);
+                               end_pos = strstr(cookie_itt,"\r\n");
+                               cookie = get_http_header_value(cookie_itt,"Set-Cookie: 
");
 
-                       zend_hash_update(Z_ARRVAL_PP(cookies), name.c, name.len + 1, 
&z_cookie, sizeof(zval *), NULL);
-               }
+                               eqpos = strstr(cookie, "=");
+                               sempos = strstr(cookie, ";");
+                               if (eqpos != NULL && (sempos == NULL || sempos > 
eqpos)) {
+                                       smart_str name = {0};
+                                       int cookie_len;
+                                       zval *zcookie;
+
+                                       if (sempos != NULL) {
+                                               cookie_len = sempos-(eqpos+1);
+                                       } else {
+                                               cookie_len = 
strlen(cookie)-(eqpos-cookie)-1;
+                                       }
+
+                                       smart_str_appendl(&name, cookie, eqpos - 
cookie);
+                                       smart_str_0(&name);
+
+                                       ALLOC_INIT_ZVAL(zcookie);
+                                       array_init(zcookie);
+                                       add_index_stringl(zcookie, 0, eqpos + 1, 
cookie_len, 1);
+
+                                       if (sempos != NULL) {
+                                               char *options = cookie + cookie_len+1;
+                                               while (*options) {
+                                                       while (*options == ' ') 
{options++;}
+                                                       sempos = strstr(options, ";");
+                                                       if (strstr(options,"path=") == 
options) {
+                                                               eqpos = options + 
sizeof("path=")-1;
+                                                               
add_index_stringl(zcookie, 1, eqpos, sempos?(sempos-eqpos):strlen(eqpos), 1);
+                                                       } else if 
(strstr(options,"domain=") == options) {
+                                                               eqpos = options + 
sizeof("domain=")-1;
+                                                               
add_index_stringl(zcookie, 2, eqpos, sempos?(sempos-eqpos):strlen(eqpos), 1);
+                                                       } else if 
(strstr(options,"secure") == options) {
+                                                               
add_index_bool(zcookie, 3, 1);
+                                                       }
+                                                       if (sempos != NULL) {
+                                                               options = sempos+1;
+                                                       } else {
+                                                         break;
+                                                       }
+                                               }
+                                       }
+               if (!zend_hash_index_exists(Z_ARRVAL_P(zcookie), 1)) {
+                 char *c = strrchr(phpurl->path, '/');
+                 if (c) {
+                                                       add_index_stringl(zcookie, 1, 
phpurl->path, c-phpurl->path, 1);
+                                               }
+               }
+               if (!zend_hash_index_exists(Z_ARRVAL_P(zcookie), 2)) {
+                                               add_index_string(zcookie, 2, 
phpurl->host, 1);
+               }
 
-               cookie_itt = strstr(cookie_itt + sizeof("Set-Cookie: "), "Set-Cookie: 
");
+                                       add_assoc_zval_ex(*cookies, name.c, 
name.len+1, zcookie);
+                                       smart_str_free(&name);
+                               }
 
-               smart_str_free(&value);
-               smart_str_free(&name);
-               efree(cookie);
+                               cookie_itt = strstr(cookie_itt + sizeof("Set-Cookie: 
"), "Set-Cookie: ");
+                               efree(cookie);
+                       }
+               }
        }
 
        content_encoding = get_http_header_value(http_headers,"Content-Encoding: ");
http://cvs.php.net/diff.php/php-src/ext/soap/php_soap.h?r1=1.31&r2=1.32&ty=u
Index: php-src/ext/soap/php_soap.h
diff -u php-src/ext/soap/php_soap.h:1.31 php-src/ext/soap/php_soap.h:1.32
--- php-src/ext/soap/php_soap.h:1.31    Wed Feb 25 09:04:41 2004
+++ php-src/ext/soap/php_soap.h Fri Apr  2 06:12:44 2004
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: php_soap.h,v 1.31 2004/02/25 14:04:41 dmitry Exp $ */
+/* $Id: php_soap.h,v 1.32 2004/04/02 11:12:44 dmitry Exp $ */
 
 #ifndef PHP_SOAP_H
 #define PHP_SOAP_H
@@ -47,6 +47,8 @@
 # define stricmp strcasecmp
 #endif
 
+extern int le_url;
+
 typedef struct _encodeType encodeType, *encodeTypePtr;
 typedef struct _encode encode, *encodePtr;
 
http://cvs.php.net/diff.php/php-src/ext/soap/soap.c?r1=1.98&r2=1.99&ty=u
Index: php-src/ext/soap/soap.c
diff -u php-src/ext/soap/soap.c:1.98 php-src/ext/soap/soap.c:1.99
--- php-src/ext/soap/soap.c:1.98        Thu Apr  1 05:47:44 2004
+++ php-src/ext/soap/soap.c     Fri Apr  2 06:12:44 2004
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: soap.c,v 1.98 2004/04/01 10:47:44 dmitry Exp $ */
+/* $Id: soap.c,v 1.99 2004/04/02 11:12:44 dmitry Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -29,7 +29,7 @@
 #endif
 
 static int le_sdl = 0;
-static int le_url = 0;
+int le_url = 0;
 static int le_service = 0;
 
 typedef struct _soapHeader {
@@ -230,6 +230,8 @@
 PHP_METHOD(SoapClient, __call);
 PHP_METHOD(SoapClient, __getLastRequest);
 PHP_METHOD(SoapClient, __getLastResponse);
+PHP_METHOD(SoapClient, __getLastRequestHeaders);
+PHP_METHOD(SoapClient, __getLastResponseHeaders);
 PHP_METHOD(SoapClient, __getFunctions);
 PHP_METHOD(SoapClient, __getTypes);
 
@@ -297,6 +299,8 @@
        PHP_ME(SoapClient, __call, __call_args, 0)
        PHP_ME(SoapClient, __getLastRequest, NULL, 0)
        PHP_ME(SoapClient, __getLastResponse, NULL, 0)
+       PHP_ME(SoapClient, __getLastRequestHeaders, NULL, 0)
+       PHP_ME(SoapClient, __getLastResponseHeaders, NULL, 0)
        PHP_ME(SoapClient, __getFunctions, NULL, 0)
        PHP_ME(SoapClient, __getTypes, NULL, 0)
        {NULL, NULL, NULL}
@@ -1345,7 +1349,7 @@
                        /* Find the soap object and assign */
                        if (zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), 
"_bogus_session_name", sizeof("_bogus_session_name"), (void **) &tmp_soap) == SUCCESS 
&&
                            Z_TYPE_PP(tmp_soap) == IS_OBJECT &&
-                           Z_OBJCE_PP(tmp_soap) == service->soap_class.ce) {          
                 
+                           Z_OBJCE_PP(tmp_soap) == service->soap_class.ce) {
                                soap_obj = *tmp_soap;
                        }
                }
@@ -1382,7 +1386,7 @@
                        } else {
 #else
       {
-#endif 
+#endif
                                int class_name_len = 
strlen(service->soap_class.ce->name);
                                char *class_name = emalloc(class_name_len+1);
 
@@ -2190,6 +2194,26 @@
        RETURN_NULL();
 }
 
+PHP_METHOD(SoapClient, __getLastRequestHeaders)
+{
+       zval **tmp;
+
+       if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_request_headers", 
sizeof("__last_request_headers"), (void **)&tmp) == SUCCESS) {
+               RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1);
+       }
+       RETURN_NULL();
+}
+
+PHP_METHOD(SoapClient, __getLastResponseHeaders)
+{
+       zval **tmp;
+
+       if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_response_headers", 
sizeof("__last_response_headers"), (void **)&tmp) == SUCCESS) {
+               RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1);
+       }
+       RETURN_NULL();
+}
+
 #ifndef ZEND_ENGINE_2
 static void soap_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, 
zend_property_reference *property_reference)
 {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to