diff options
-rw-r--r-- | ext/soap/config.m4 | 5 | ||||
-rw-r--r-- | ext/soap/php_encoding.c | 11 | ||||
-rw-r--r-- | ext/soap/php_http.c | 53 | ||||
-rw-r--r-- | ext/soap/php_http.h | 2 | ||||
-rw-r--r-- | ext/soap/php_packet_soap.c | 1 | ||||
-rw-r--r-- | ext/soap/php_sdl.c | 16 | ||||
-rw-r--r-- | ext/soap/php_soap.h | 14 | ||||
-rw-r--r-- | ext/soap/soap.c | 100 |
8 files changed, 109 insertions, 93 deletions
diff --git a/ext/soap/config.m4 b/ext/soap/config.m4 index 3d5672b3fb..d730222325 100644 --- a/ext/soap/config.m4 +++ b/ext/soap/config.m4 @@ -1,12 +1,7 @@ dnl $Id$ dnl config.m4 for extension soap -dnl Comments in this file start with the string 'dnl'. -dnl Remove where necessary. This file will not work -dnl without editing. - PHP_ARG_ENABLE(soap, whether to enable soap support, -Make sure that the comment is aligned: [ --enable-soap[=DIR] Enable soap support. DIR is libxml2 library directory.]) diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 86d2c80b76..b450ebb149 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -242,6 +242,7 @@ zval *to_zval_user(encodeType type, xmlNodePtr node) if(call_user_function(EG(function_table), NULL, type.map->map_functions.to_zval, ret, 1, ¶m TSRMLS_CC) == FAILURE) php_error(E_ERROR, "Error calling to_zval"); zval_ptr_dtor(¶m); + efree(param); } return ret; } @@ -286,7 +287,7 @@ zval *to_zval_stringl(encodeType type, xmlNodePtr data) xmlNodePtr to_xml_string(encodeType type, zval *data, int style) { xmlNodePtr ret; - char *str; + char *str, *pstr; int new_len; ret = xmlNewNode(NULL, "BOGUS"); @@ -294,7 +295,13 @@ xmlNodePtr to_xml_string(encodeType type, zval *data, int style) convert_to_string(data); str = php_escape_html_entities(Z_STRVAL_P(data), Z_STRLEN_P(data), &new_len, 0, 0, NULL); - xmlNodeSetContentLen(ret, str, new_len); + + pstr = malloc(new_len + 1); + memcpy(pstr, str, new_len); + pstr[new_len] = '\0'; + efree(str); + + xmlNodeSetContentLen(ret, pstr, new_len); if(style == SOAP_ENCODED) set_ns_and_type(ret, type); diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 1ebb59d3cb..fdb2403468 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -10,8 +10,6 @@ void send_http_soap_request(zval *this_ptr, xmlDoc *doc, char *function_name, ch SOAP_STREAM stream; zval **trace; -/* TSRMLS_FETCH();*/ - FETCH_THIS_SOCKET(stream); FETCH_THIS_URL(phpurl); FETCH_THIS_SDL(sdl); @@ -45,10 +43,17 @@ void send_http_soap_request(zval *this_ptr, xmlDoc *doc, char *function_name, ch phpurl = php_url_parse(url); -#ifdef PHP_STREAMS - stream = php_stream_sock_open_host(phpurl->host, (unsigned short)(phpurl->port == 0 ? 80 : phpurl->port), SOCK_STREAM, 0, 0); + if (phpurl->port == 0) { + if (strcmp(phpurl->scheme, "http") == 0) + phpurl->port = 80; + else if (strcmp(phpurl->scheme, "https") == 0) + phpurl->port = 443; + } + +#ifdef PHP_HAVE_STREAMS + stream = php_stream_sock_open_host(phpurl->host, (unsigned short)phpurl->port, SOCK_STREAM, NULL, NULL); #else - stream = get_socket(phpurl->host, (phpurl->port == 0 ? 80 : phpurl->port), 10); + stream = get_socket(phpurl->host, phpurl->port, 10); #endif if(stream) { @@ -59,12 +64,9 @@ void send_http_soap_request(zval *this_ptr, xmlDoc *doc, char *function_name, ch ret = zend_list_insert(phpurl, le_url); add_property_resource(this_ptr, "httpurl", ret); zend_list_addref(ret); - } - else + } else { php_error(E_ERROR,"Could not connect to host"); - /* - php_url_free(phpurl); - */ + } } if(stream) @@ -85,8 +87,8 @@ void send_http_soap_request(zval *this_ptr, xmlDoc *doc, char *function_name, ch soap_headers = emalloc(size + strlen(soapaction)); sprintf(soap_headers, header, phpurl->path, phpurl->host, buf_size, soapaction); } - -#ifdef PHP_STREAMS + +#ifdef PHP_HAVE_STREAMS err = php_stream_write(stream, soap_headers, strlen(soap_headers)); #else err = send(stream, soap_headers, strlen(soap_headers), 0); @@ -118,7 +120,7 @@ void send_http_soap_request(zval *this_ptr, xmlDoc *doc, char *function_name, ch smart_str_appendl(&cookie_str, "\r\n", 2); smart_str_0(&cookie_str); -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS err = php_stream_write(stream, cookie_str.c, cookie_str.len); #else err = send(stream, cookie_str.c, cookie_str.len,0); @@ -129,7 +131,7 @@ void send_http_soap_request(zval *this_ptr, xmlDoc *doc, char *function_name, ch smart_str_free(&cookie_str); } -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS err = php_stream_write(stream, "\r\n", 2); #else err = send(stream, "\r\n", 2, 0); @@ -138,7 +140,7 @@ void send_http_soap_request(zval *this_ptr, xmlDoc *doc, char *function_name, ch php_error(E_ERROR,"Failed Sending HTTP Headers"); -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS err = php_stream_write(stream, buf, buf_size); #else err = send(stream, buf, buf_size, 0); @@ -160,8 +162,6 @@ void get_http_soap_response(zval *this_ptr, char **buffer, int *buffer_len TSRML SOAP_STREAM stream; zval **trace; -/* TSRMLS_FETCH();*/ - FETCH_THIS_SDL(sdl); if(FIND_SOCKET_PROPERTY(this_ptr, socket_ref) != FAILURE) @@ -246,7 +246,7 @@ void get_http_soap_response(zval *this_ptr, char **buffer, int *buffer_len TSRML if(http_close) { -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS php_stream_close(stream); #else SOCK_CLOSE(stream); @@ -377,7 +377,7 @@ int get_http_body(SOAP_STREAM stream, char *headers, char **response, int *out_ while(!done) { for (cur = 0; cur < 3 || !(chunk_size[cur - 2] == '\r' && chunk_size[cur - 1] == '\n'); cur++) -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS chunk_size[cur] = php_stream_getc(stream); #else chunk_size[cur] = php_sock_fgetc(stream); @@ -389,14 +389,14 @@ int get_http_body(SOAP_STREAM stream, char *headers, char **response, int *out_ len_size = 0; while(http_buf_size < buf_size) { -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS len_size += php_stream_read(stream, &http_buf[http_buf_size], buf_size - len_size); #else len_size += php_sock_fread(&http_buf[http_buf_size], buf_size - len_size, stream); #endif http_buf_size += len_size; } -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS php_stream_getc(stream);php_stream_getc(stream); #else /* Eat up '\r' '\n' */ @@ -415,7 +415,7 @@ int get_http_body(SOAP_STREAM stream, char *headers, char **response, int *out_ http_buf = emalloc(size + 1); while(http_buf_size < size) -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS http_buf_size += php_stream_read(stream, &http_buf[http_buf_size], size - http_buf_size); #else http_buf_size += php_sock_fread(&http_buf[http_buf_size], size - http_buf_size, stream); @@ -436,13 +436,12 @@ int get_http_headers(SOAP_STREAM stream, char **response, int *out_size TSRMLS_D int done; char chr; smart_str tmp_response = {0}; -/* TSRMLS_FETCH();//i think this is not needed - even the parameter */ done = FALSE; while(!done) { -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS chr = php_stream_getc(stream); #else chr = php_sock_fgetc(stream); @@ -456,16 +455,16 @@ int get_http_headers(SOAP_STREAM stream, char **response, int *out_size TSRMLS_D smart_str_0(&tmp_response); done = TRUE; } - } - else + } else { return FALSE; + } } (*response) = tmp_response.c; (*out_size) = tmp_response.len; return TRUE; } -#ifndef PHP_STREAMS +#ifndef PHP_HAVE_STREAMS SOCKET get_socket(char* host,int portno,int time) { SOCKET socketd = -1; diff --git a/ext/soap/php_http.h b/ext/soap/php_http.h index 44d4e32e5d..d7f5b44c7a 100644 --- a/ext/soap/php_http.h +++ b/ext/soap/php_http.h @@ -8,7 +8,7 @@ char *get_http_header_value(char *headers, char *type); int get_http_body(SOAP_STREAM socketd, char *headers, char **response, int *out_size TSRMLS_DC); int get_http_headers(SOAP_STREAM socketd,char **response, int *out_size TSRMLS_DC); -#ifndef PHP_STREAMS +#ifndef PHP_HAVE_STREAMS #ifndef ZEND_WIN32 # ifndef closesocket # define closesocket close diff --git a/ext/soap/php_packet_soap.c b/ext/soap/php_packet_soap.c index 104040fa9f..5411c31ee9 100644 --- a/ext/soap/php_packet_soap.c +++ b/ext/soap/php_packet_soap.c @@ -5,7 +5,6 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction xmlDocPtr response; xmlNodePtr trav, trav2, env, body, resp, cur, fault; zval **tmp_ret; -/* TSRMLS_FETCH();*/ response = xmlParseMemory(buffer, buffer_size); xmlCleanupParser(); diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 6481027a73..c34f33b9e9 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -232,6 +232,9 @@ xmlNodePtr sdl_to_xml_array(sdlTypePtr type, zval *data, int style) smart_str_appendc(&array_type_and_size, ':'); smart_str_appends(&array_type_and_size, value); smart_str_0(&array_type_and_size); + + smart_str_free(prefix); + efree(prefix); } } else @@ -317,6 +320,10 @@ sdlBindingPtr get_binding_from_type(sdlPtr sdl, int type) { sdlBindingPtr *binding; + if (sdl == NULL) { + return NULL; + } + for(zend_hash_internal_pointer_reset(sdl->bindings); zend_hash_get_current_data(sdl->bindings, (void **) &binding) == SUCCESS; zend_hash_move_forward(sdl->bindings)) @@ -539,13 +546,13 @@ sdlPtr load_wsdl(char *struri, sdlPtr parent) xmlCleanupParser(); if(!wsdl) - php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Could't load"); + php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Couldn't load from %s", struri); tmpsdl->doc = wsdl; root = wsdl->children; definitions = get_node(root, "definitions"); if(!definitions) - php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Could't find definitions"); + php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: Couldn't find definitions in %s", struri); targetNamespace = get_attribute(definitions->properties, "targetNamespace"); if(targetNamespace) @@ -619,10 +626,11 @@ sdlPtr load_wsdl(char *struri, sdlPtr parent) parse_namespace(bindingAttr->children->content, &ctype, &ns); binding = get_node_with_attribute(definitions->children, "binding", "name", ctype); - if(ns) efree(ns); if(ctype) efree(ctype); if(!binding) - php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: No binding"); + php_error(E_ERROR, "SOAP-ERROR: Parsing WSDL: No binding element with name \"%s\"", ctype); + + if(ns) efree(ns); if(ctype) efree(ctype); if(tmpbinding->bindingType == BINDING_SOAP) { diff --git a/ext/soap/php_soap.h b/ext/soap/php_soap.h index 470d998245..23ba3a6141 100644 --- a/ext/soap/php_soap.h +++ b/ext/soap/php_soap.h @@ -16,22 +16,14 @@ # include "ext/domxml/php_domxml.h" #endif -/* - PHP_STREAMS were introduced php-4.2.0.. i think - Make this part of configure -*/ -#ifdef STREAMS_DC -# define PHP_STREAMS -#endif - #ifdef PHP_WIN32 -# ifdef PHP_STREAMS +# ifdef PHP_HAVE_STREAMS # define SOAP_STREAM php_stream * # else # define SOAP_STREAM SOCKET # endif #else -# ifdef PHP_STREAMS +# ifdef PHP_HAVE_STREAMS # define SOAP_STREAM php_stream * # else # define SOCKET unsigned int @@ -320,7 +312,7 @@ int my_call_user_function(HashTable *function_table, zval **object_pp, zval *fun #define ENDFOREACH(n) \ } \ - } while(n = n->next); + } while ((n = n->next)); #define ZERO_PARAM() \ if(ZEND_NUM_ARGS() != 0) \ diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 7435ba2952..4a40fec6cf 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -922,7 +922,7 @@ PHP_FUNCTION(handle) fn_name = estrndup(Z_STRVAL(function_name),Z_STRLEN(function_name)); response_name = emalloc(Z_STRLEN(function_name) + strlen("Response") + 1); - sprintf(response_name,"%sResponse\0",fn_name); + sprintf(response_name,"%sResponse",fn_name); if(service->type == SOAP_CLASS) { @@ -1044,7 +1044,7 @@ PHP_FUNCTION(handle) if(size == 0) php_error(E_ERROR, "Dump memory failed"); - sprintf(cont_len, "Content-Length: %d\0", size); + sprintf(cont_len, "Content-Length: %d", size); sapi_add_header("Content-Type: text/xml", sizeof("Content-Type: text/xml"), 1); sapi_add_header(cont_len, strlen(cont_len) + 1, 1); @@ -1118,7 +1118,7 @@ void soap_error_handler(int error_num, const char *error_filename, const uint er xmlDocDumpMemoryEnc(doc_return, &buf, &size, XML_CHAR_ENCODING_UTF8); */ xmlDocDumpMemory(doc_return, &buf, &size); - sprintf(cont_len,"Content-Length: %d\0", size); + sprintf(cont_len,"Content-Length: %d", size); sapi_add_header(cont_len, strlen(cont_len) + 1, 1); sapi_add_header("Content-Type: text/xml", sizeof("Content-Type: text/xml"), 1); @@ -1300,35 +1300,39 @@ PHP_FUNCTION(__parse) char *message, *function; int message_len, function_len; int num_params; - zval **ret_params; + zval **ret_params = NULL; sdlPtr sdl; sdlFunctionPtr fn; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &message, &message_len, &function, &function_len) == FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &message, &message_len, &function, &function_len) == FAILURE) { php_error(E_ERROR, "Invalid arguments to SoapObject->__parse"); + } FETCH_THIS_SDL(sdl); - if(sdl != NULL) - { + if (sdl != NULL) { sdlBindingPtr binding; FETCH_THIS_PORT(binding); fn = get_function(binding, function); - if(fn != NULL) + + if (fn != NULL) { parse_packet_soap(getThis(), message, message_len, fn, NULL, &ret_params, &num_params TSRMLS_CC); + } + } else { + parse_packet_soap(getThis(), message, message_len, NULL, function, &ret_params, &num_params TSRMLS_CC); } - else - parse_packet_soap(getThis(), message, message_len, NULL, function, &ret_params, &num_params TSRMLS_CC); - if(num_params > 0) - { + if (num_params > 0) { *return_value = *ret_params[0]; - zval_add_ref(&return_value); + /* zval_add_ref(&return_value); */ + } else { + ZVAL_NULL(return_value); + } + + if (ret_params) { efree(ret_params); } - else - ZVAL_NULL(return_value) } PHP_FUNCTION(__call) @@ -1340,7 +1344,7 @@ PHP_FUNCTION(__call) zval **param; xmlDocPtr request = NULL; int num_params, arg_count; - zval **ret_params; + zval **ret_params = NULL; char *buffer; int len; @@ -1369,14 +1373,16 @@ PHP_FUNCTION(__call) parse_packet_soap(getThis(), buffer, len, NULL, function, &ret_params, &num_params TSRMLS_CC); efree(buffer); - if(num_params > 0) - { + if(num_params > 0) { *return_value = *ret_params[0]; - zval_add_ref(&return_value); + /* zval_add_ref(&return_value); */ + } else { + ZVAL_NULL(return_value); + } + + if (ret_params) { efree(ret_params); } - else - ZVAL_NULL(return_value) } PHP_FUNCTION(__isfault) @@ -1533,8 +1539,7 @@ void soap_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_refe clear_soap_fault(thisObj); - if(sdl != NULL) - { + if (sdl != NULL) { sdlBindingPtr binding; FETCH_THIS_PORT(binding); @@ -1542,7 +1547,7 @@ void soap_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_refe if(fn != NULL) { int num_params; - zval **ret_params; + zval **ret_params = NULL; char *buffer; char *ns; int len; @@ -1565,14 +1570,16 @@ void soap_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_refe parse_packet_soap(getThis(), buffer, len, fn, NULL, &ret_params, &num_params TSRMLS_CC); efree(buffer); - if(num_params > 0) - { + if(num_params > 0) { *return_value = *ret_params[0]; - zval_add_ref(&return_value); + /* zval_add_ref(&return_value); */ + } else { + ZVAL_NULL(return_value); + } + + if (ret_params) { efree(ret_params); } - else - ZVAL_NULL(return_value); } else { @@ -1582,7 +1589,7 @@ void soap_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_refe else { int num_params; - zval **ret_params; + zval **ret_params = NULL; zval **uri; smart_str *action; char *buffer; @@ -1596,20 +1603,24 @@ void soap_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_refe send_http_soap_request(getThis(), request, function, action->c TSRMLS_CC); smart_str_free(action); + efree(action); xmlFreeDoc(request); get_http_soap_response(getThis(), &buffer, &len TSRMLS_CC); parse_packet_soap(getThis(), buffer, len, NULL, function, &ret_params, &num_params TSRMLS_CC); efree(buffer); - if(num_params > 0) - { + if(num_params > 0) { *return_value = *ret_params[0]; - zval_add_ref(&return_value); + /* zval_add_ref(&return_value); */ + } else { + ZVAL_NULL(return_value); + } + + if (ret_params) { + FREE_ZVAL(ret_params[0]); efree(ret_params); } - else - ZVAL_NULL(return_value); } efree(arguments); } @@ -1658,7 +1669,6 @@ void deseralize_function_call(sdlPtr sdl, xmlDocPtr request, zval *function_name { xmlNodePtr trav,trav2,trav3,trav4,env,body; int cur_param = 0,num_of_params = 0; -/* TSRMLS_FETCH();*/ trav = request->children; FOREACHNODE(trav,"Envelope",env) @@ -1669,7 +1679,7 @@ void deseralize_function_call(sdlPtr sdl, xmlDocPtr request, zval *function_name trav3 = body->children; do { - /* TODO: make 'strict' (use th sdl defnintions) */ + /* TODO: make 'strict' (use the sdl defnintions) */ if(trav3->type == XML_ELEMENT_NODE) { zval tmp_function_name, **tmp_parameters; @@ -1695,7 +1705,7 @@ void deseralize_function_call(sdlPtr sdl, xmlDocPtr request, zval *function_name if(trav4->type == XML_ELEMENT_NODE) num_of_params++; - }while(trav4 = trav4->next); + } while ((trav4 = trav4->next)); } else num_of_params = zend_hash_num_elements(function->requestParameters); @@ -1720,13 +1730,13 @@ void deseralize_function_call(sdlPtr sdl, xmlDocPtr request, zval *function_name cur_param++; } - }while(trav4 = trav4->next); + } while ((trav4 = trav4->next)); } (*parameters) = tmp_parameters; (*num_params) = num_of_params; break; } - }while(trav3 = trav3->next); + } while ((trav3 = trav3->next)); } ENDFOREACH(trav2); @@ -1740,7 +1750,7 @@ xmlDocPtr seralize_response_call(sdlFunctionPtr function, char *function_name, c xmlNode *envelope,*body,*method, *param; xmlNs *ns; sdlParamPtr parameter = NULL; - smart_str *gen_ns; + smart_str *gen_ns = NULL; encode_reset_ns(); @@ -1798,6 +1808,11 @@ xmlDocPtr seralize_response_call(sdlFunctionPtr function, char *function_name, c xmlAddChild(method,param); } + if (gen_ns) { + smart_str_free(gen_ns); + efree(gen_ns); + } + return doc; } @@ -1900,6 +1915,7 @@ xmlDocPtr seralize_function_call(zval *this_ptr, sdlFunctionPtr function, char * } } smart_str_free(gen_ns); + efree(gen_ns); return doc; } @@ -2103,7 +2119,7 @@ void delete_sdl(void *handle) void delete_http_socket(void *handle) { SOAP_STREAM stream = (SOAP_STREAM)handle; -#ifdef PHP_STREAMS +#ifdef PHP_HAVE_STREAMS TSRMLS_FETCH(); php_stream_close(stream); #else |