From 58c82af64dc10f4ae11625426397c40e1e1c7e3d Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Tue, 27 Jun 2006 23:32:56 +0000 Subject: [PATCH] Improved the error reporting in SOAP extension on request failure. --- NEWS | 1 + ext/soap/php_http.c | 41 ++++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 285a48de86..0c155ff4ac 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ PHP NEWS - Changed realpath cache to be disabled when "open_basedir" or "safe_mode" are enabled on per-request basis. (Ilia) +- Improved the error reporting in SOAP extension on request failure. (Ilia) - New crypt() implementation for win32 which is about 10 times faster and has more friendly license. (Frank, Dmitry) - Improved performance of the implode() function on associated arrays. (Ilia) diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index e70a006dcb..e8eff561be 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -237,6 +237,7 @@ int make_http_soap_request(zval *this_ptr, int http_status; int content_type_xml = 0; char *content_encoding; + char *http_msg = NULL; zend_bool old_allow_url_fopen; if (this_ptr == NULL || Z_TYPE_P(this_ptr) != IS_OBJECT) { @@ -729,6 +730,14 @@ try_again: tmp++; http_status = atoi(tmp); } + tmp = strstr(tmp," "); + if (tmp != NULL) { + tmp++; + if (http_msg) { + efree(http_msg); + } + http_msg = estrdup(tmp); + } efree(http_version); /* Try and get headers again */ @@ -842,6 +851,9 @@ try_again: 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", "Error Fetching http body, No Content-Length, connection closed or chunked data", NULL, NULL TSRMLS_CC); + if (http_msg) { + efree(http_msg); + } return FALSE; } @@ -1044,6 +1056,9 @@ try_again: efree(content_encoding); efree(http_headers); efree(http_body); + if (http_msg) { + efree(http_msg); + } add_soap_fault(this_ptr, "HTTP", "Unknown Content-Encoding", NULL, NULL TSRMLS_CC); return FALSE; } @@ -1057,6 +1072,9 @@ try_again: efree(http_headers); efree(http_body); add_soap_fault(this_ptr, "HTTP", "Can't uncompress compressed response", NULL, NULL TSRMLS_CC); + if (http_msg) { + efree(http_msg); + } return FALSE; } efree(content_encoding); @@ -1087,27 +1105,16 @@ try_again: if (error) { efree(*buffer); - if (http_status == 400) { - add_soap_fault(this_ptr, "HTTP", "Bad Request", NULL, NULL TSRMLS_CC); - } else if (http_status == 401) { - add_soap_fault(this_ptr, "HTTP", "Unauthorized Request", NULL, NULL TSRMLS_CC); - } else if (http_status == 405) { - add_soap_fault(this_ptr, "HTTP", "Method not allowed", NULL, NULL TSRMLS_CC); - } else if (http_status == 415) { - add_soap_fault(this_ptr, "HTTP", "Unsupported Media Type", NULL, NULL TSRMLS_CC); - } else if (http_status >= 400 && http_status < 500) { - add_soap_fault(this_ptr, "HTTP", "Client Error", NULL, NULL TSRMLS_CC); - } else if (http_status == 500) { - add_soap_fault(this_ptr, "HTTP", "Internal Server Error", NULL, NULL TSRMLS_CC); - } else if (http_status >= 500 && http_status < 600) { - add_soap_fault(this_ptr, "HTTP", "Server Error", NULL, NULL TSRMLS_CC); - } else { - add_soap_fault(this_ptr, "HTTP", "Unsupported HTTP status code", NULL, NULL TSRMLS_CC); - } + add_soap_fault(this_ptr, "HTTP", http_msg, NULL, NULL TSRMLS_CC); + efree(http_msg); return FALSE; } } + if (http_msg) { + efree(http_msg); + } + return TRUE; } -- 2.50.1