From e1ecd4c689e7a113d9cecc9d10dc24635ff4e8b3 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 29 May 2025 19:15:02 +0200 Subject: [PATCH 1/4] Implement request #61105: Support Soap 1.2 SoapFault Reason Text lang attribute This is on the border line of a bugfix and a new feature. Anyway, this is necessary to fix compatibility with .NET clients. --- UPGRADING | 5 ++ ext/soap/php_http.c | 24 ++--- ext/soap/php_packet_soap.c | 44 ++++++---- ext/soap/php_soap.h | 3 +- ext/soap/soap.c | 136 +++++++++++++++++------------ ext/soap/soap.stub.php | 5 +- ext/soap/soap_arginfo.h | 10 ++- ext/soap/tests/bugs/bug38005.phpt | 2 +- ext/soap/tests/bugs/bug68996.phpt | 2 +- ext/soap/tests/bugs/bug73037.phpt | 5 +- ext/soap/tests/fault_language.phpt | 29 ++++++ ext/soap/tests/soap12/T12.phpt | 2 +- ext/soap/tests/soap12/T13.phpt | 2 +- ext/soap/tests/soap12/T14.phpt | 2 +- ext/soap/tests/soap12/T23.phpt | 2 +- ext/soap/tests/soap12/T24.phpt | 2 +- ext/soap/tests/soap12/T25.phpt | 2 +- ext/soap/tests/soap12/T27.phpt | 2 +- ext/soap/tests/soap12/T28.phpt | 2 +- ext/soap/tests/soap12/T33.phpt | 2 +- ext/soap/tests/soap12/T35.phpt | 2 +- ext/soap/tests/soap12/T36.phpt | 2 +- ext/soap/tests/soap12/T39.phpt | 2 +- ext/soap/tests/soap12/T56.phpt | 2 +- ext/soap/tests/soap12/T58.phpt | 2 +- ext/soap/tests/soap12/T59.phpt | 2 +- ext/soap/tests/soap12/T61.phpt | 2 +- ext/soap/tests/soap12/T63.phpt | 2 +- ext/soap/tests/soap12/T64.phpt | 2 +- ext/soap/tests/soap12/T65.phpt | 2 +- ext/soap/tests/soap12/T69.phpt | 2 +- ext/soap/tests/soap12/T70.phpt | 2 +- ext/soap/tests/soap12/T71.phpt | 2 +- ext/soap/tests/soap12/T72.phpt | 2 +- ext/soap/tests/soap12/T80.phpt | 2 +- 35 files changed, 195 insertions(+), 118 deletions(-) create mode 100644 ext/soap/tests/fault_language.phpt diff --git a/UPGRADING b/UPGRADING index 26c87d7aeb795..0eb11cb5af87f 100644 --- a/UPGRADING +++ b/UPGRADING @@ -201,6 +201,11 @@ PHP 8.5 UPGRADE NOTES - SOAP: . Enumeration cases are now dumped in __getTypes(). + . Implemented request #61105: + support for Soap 1.2 Reason Text xml:lang attribute. + The signature of SoapFault::__construct() and SoapServer::fault() therefore + now have an optional $lang parameter. + This support solves compatibility with .NET SOAP clients. - XSL: . The $namespace argument of XSLTProcessor::getParameter(), diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index a1bd7dff0c8a5..84a10368d22fe 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -455,7 +455,7 @@ int make_http_soap_request(zval *this_ptr, if (request != buf) { zend_string_release_ex(request, 0); } - add_soap_fault(this_ptr, "HTTP", "Unable to parse URL", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Unable to parse URL", NULL, NULL, SOAP_GLOBAL(lang_en)); smart_str_free(&soap_headers_z); efree(http_msg); return FALSE; @@ -469,7 +469,7 @@ int make_http_soap_request(zval *this_ptr, if (request != buf) { zend_string_release_ex(request, 0); } - add_soap_fault(this_ptr, "HTTP", "Unknown protocol. Only http and https are allowed.", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Unknown protocol. Only http and https are allowed.", NULL, NULL, SOAP_GLOBAL(lang_en)); smart_str_free(&soap_headers_z); efree(http_msg); return FALSE; @@ -482,7 +482,7 @@ int make_http_soap_request(zval *this_ptr, if (request != buf) { zend_string_release_ex(request, 0); } - add_soap_fault(this_ptr, "HTTP", "SSL support is not available in this build", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "SSL support is not available in this build", NULL, NULL, SOAP_GLOBAL(lang_en)); PG(allow_url_fopen) = old_allow_url_fopen; smart_str_free(&soap_headers_z); efree(http_msg); @@ -537,7 +537,7 @@ int make_http_soap_request(zval *this_ptr, if (request != buf) { zend_string_release_ex(request, 0); } - add_soap_fault(this_ptr, "HTTP", "Could not connect to host", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Could not connect to host", NULL, NULL, SOAP_GLOBAL(lang_en)); PG(allow_url_fopen) = old_allow_url_fopen; smart_str_free(&soap_headers_z); efree(http_msg); @@ -908,14 +908,14 @@ int make_http_soap_request(zval *this_ptr, convert_to_null(Z_CLIENT_HTTPURL_P(this_ptr)); convert_to_null(Z_CLIENT_HTTPSOCKET_P(this_ptr)); convert_to_null(Z_CLIENT_USE_PROXY_P(this_ptr)); - add_soap_fault(this_ptr, "HTTP", "Failed Sending HTTP SOAP request", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Failed Sending HTTP SOAP request", NULL, NULL, SOAP_GLOBAL(lang_en)); smart_str_free(&soap_headers_z); efree(http_msg); return FALSE; } smart_str_free(&soap_headers); } else { - add_soap_fault(this_ptr, "HTTP", "Failed to create stream??", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Failed to create stream??", NULL, NULL, SOAP_GLOBAL(lang_en)); smart_str_free(&soap_headers_z); efree(http_msg); return FALSE; @@ -932,7 +932,7 @@ int make_http_soap_request(zval *this_ptr, php_stream_close(stream); convert_to_null(Z_CLIENT_HTTPSOCKET_P(this_ptr)); convert_to_null(Z_CLIENT_USE_PROXY_P(this_ptr)); - add_soap_fault(this_ptr, "HTTP", "Error Fetching http headers", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Error Fetching http headers", NULL, NULL, SOAP_GLOBAL(lang_en)); smart_str_free(&soap_headers_z); efree(http_msg); return FALSE; @@ -1121,7 +1121,7 @@ int make_http_soap_request(zval *this_ptr, zend_string_release_ex(http_headers, 0); convert_to_null(Z_CLIENT_HTTPSOCKET_P(this_ptr)); convert_to_null(Z_CLIENT_USE_PROXY_P(this_ptr)); - add_soap_fault(this_ptr, "HTTP", "Error Fetching http body, No Content-Length, connection closed or chunked data", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Error Fetching http body, No Content-Length, connection closed or chunked data", NULL, NULL, SOAP_GLOBAL(lang_en)); if (http_msg) { efree(http_msg); } @@ -1180,7 +1180,7 @@ int make_http_soap_request(zval *this_ptr, phpurl = new_url; if (--redirect_max < 1) { - add_soap_fault(this_ptr, "HTTP", "Redirection limit reached, aborting", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Redirection limit reached, aborting", NULL, NULL, SOAP_GLOBAL(lang_en)); smart_str_free(&soap_headers_z); efree(http_msg); return FALSE; @@ -1318,7 +1318,7 @@ int make_http_soap_request(zval *this_ptr, if (http_msg) { efree(http_msg); } - add_soap_fault(this_ptr, "HTTP", "Unknown Content-Encoding", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Unknown Content-Encoding", NULL, NULL, SOAP_GLOBAL(lang_en)); return FALSE; } if (call_user_function(CG(function_table), (zval*)NULL, &func, &retval, 1, params) == SUCCESS && @@ -1334,7 +1334,7 @@ int make_http_soap_request(zval *this_ptr, efree(content_encoding); zend_string_release_ex(http_headers, 0); zend_string_release_ex(http_body, 0); - add_soap_fault(this_ptr, "HTTP", "Can't uncompress compressed response", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Can't uncompress compressed response", NULL, NULL, SOAP_GLOBAL(lang_en)); if (http_msg) { efree(http_msg); } @@ -1368,7 +1368,7 @@ int make_http_soap_request(zval *this_ptr, if (error) { zval_ptr_dtor(return_value); ZVAL_UNDEF(return_value); - add_soap_fault(this_ptr, "HTTP", http_msg, NULL, NULL); + add_soap_fault(this_ptr, "HTTP", http_msg, NULL, NULL, SOAP_GLOBAL(lang_en)); efree(http_msg); return FALSE; } diff --git a/ext/soap/php_packet_soap.c b/ext/soap/php_packet_soap.c index fddb6b63874d9..90e92a7cd4bdb 100644 --- a/ext/soap/php_packet_soap.c +++ b/ext/soap/php_packet_soap.c @@ -40,11 +40,11 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio response = soap_xmlParseMemory(buffer, buffer_size); if (!response) { - add_soap_fault(this_ptr, "Client", "looks like we got no XML document", NULL, NULL); + add_soap_fault(this_ptr, "Client", "looks like we got no XML document", NULL, NULL, SOAP_GLOBAL(lang_en)); return false; } if (xmlGetIntSubset(response) != NULL) { - add_soap_fault(this_ptr, "Client", "DTD are not supported by SOAP", NULL, NULL); + add_soap_fault(this_ptr, "Client", "DTD are not supported by SOAP", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } @@ -63,7 +63,7 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio envelope_ns = SOAP_1_2_ENV_NAMESPACE; soap_version = SOAP_1_2; } else { - add_soap_fault(this_ptr, "VersionMismatch", "Wrong Version", NULL, NULL); + add_soap_fault(this_ptr, "VersionMismatch", "Wrong Version", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } @@ -71,7 +71,7 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio trav = trav->next; } if (env == NULL) { - add_soap_fault(this_ptr, "Client", "looks like we got XML without \"Envelope\" element", NULL, NULL); + add_soap_fault(this_ptr, "Client", "looks like we got XML without \"Envelope\" element", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } @@ -79,16 +79,16 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio attr = env->properties; while (attr != NULL) { if (attr->ns == NULL) { - add_soap_fault(this_ptr, "Client", "A SOAP Envelope element cannot have non Namespace qualified attributes", NULL, NULL); + add_soap_fault(this_ptr, "Client", "A SOAP Envelope element cannot have non Namespace qualified attributes", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) { if (soap_version == SOAP_1_2) { - add_soap_fault(this_ptr, "Client", "encodingStyle cannot be specified on the Envelope", NULL, NULL); + add_soap_fault(this_ptr, "Client", "encodingStyle cannot be specified on the Envelope", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } else if (strcmp((char*)attr->children->content, SOAP_1_1_ENC_NAMESPACE) != 0) { - add_soap_fault(this_ptr, "Client", "Unknown data encoding style", NULL, NULL); + add_soap_fault(this_ptr, "Client", "Unknown data encoding style", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } @@ -120,7 +120,7 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio trav = trav->next; } if (body == NULL) { - add_soap_fault(this_ptr, "Client", "Body must be present in a SOAP envelope", NULL, NULL); + add_soap_fault(this_ptr, "Client", "Body must be present in a SOAP envelope", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } @@ -128,17 +128,17 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio while (attr != NULL) { if (attr->ns == NULL) { if (soap_version == SOAP_1_2) { - add_soap_fault(this_ptr, "Client", "A SOAP Body element cannot have non Namespace qualified attributes", NULL, NULL); + add_soap_fault(this_ptr, "Client", "A SOAP Body element cannot have non Namespace qualified attributes", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) { if (soap_version == SOAP_1_2) { - add_soap_fault(this_ptr, "Client", "encodingStyle cannot be specified on the Body", NULL, NULL); + add_soap_fault(this_ptr, "Client", "encodingStyle cannot be specified on the Body", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } else if (strcmp((char*)attr->children->content, SOAP_1_1_ENC_NAMESPACE) != 0) { - add_soap_fault(this_ptr, "Client", "Unknown data encoding style", NULL, NULL); + add_soap_fault(this_ptr, "Client", "Unknown data encoding style", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } @@ -146,7 +146,7 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio attr = attr->next; } if (trav != NULL && soap_version == SOAP_1_2) { - add_soap_fault(this_ptr, "Client", "A SOAP 1.2 envelope can contain only Header and Body", NULL, NULL); + add_soap_fault(this_ptr, "Client", "A SOAP 1.2 envelope can contain only Header and Body", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } @@ -155,16 +155,16 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio attr = head->properties; while (attr != NULL) { if (attr->ns == NULL) { - add_soap_fault(this_ptr, "Client", "A SOAP Header element cannot have non Namespace qualified attributes", NULL, NULL); + add_soap_fault(this_ptr, "Client", "A SOAP Header element cannot have non Namespace qualified attributes", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) { if (soap_version == SOAP_1_2) { - add_soap_fault(this_ptr, "Client", "encodingStyle cannot be specified on the Header", NULL, NULL); + add_soap_fault(this_ptr, "Client", "encodingStyle cannot be specified on the Header", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } else if (strcmp((char*)attr->children->content, SOAP_1_1_ENC_NAMESPACE) != 0) { - add_soap_fault(this_ptr, "Client", "Unknown data encoding style", NULL, NULL); + add_soap_fault(this_ptr, "Client", "Unknown data encoding style", NULL, NULL, SOAP_GLOBAL(lang_en)); xmlFreeDoc(response); return false; } @@ -177,6 +177,7 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio fault = get_node_ex(body->children,"Fault",envelope_ns); if (fault != NULL) { char *faultcode = NULL; + zend_string *lang = NULL; zend_string *faultstring = NULL, *faultactor = NULL; zval details; xmlNodePtr tmp; @@ -219,13 +220,19 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio tmp = get_node(fault->children,"Reason"); if (tmp != NULL && tmp->children != NULL) { - /* TODO: lang attribute */ tmp = get_node(tmp->children,"Text"); if (tmp != NULL && tmp->children != NULL) { zval zv; master_to_zval(&zv, get_conversion(IS_STRING), tmp); convert_to_string(&zv) faultstring = Z_STR(zv); + + /* xml:lang is required by SOAP 1.2, but for BC reasons we allow it to be missing */ + xmlAttrPtr lang_attr = get_attribute_ex(tmp->properties, "lang", (const char *) XML_XML_NAMESPACE); + if (lang_attr != NULL && lang_attr->children != NULL) { + const char *lang_str = (const char *) lang_attr->children->content; + lang = zend_string_init(lang_str, strlen(lang_str), false); + } } } @@ -234,13 +241,16 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio master_to_zval(&details, NULL, tmp); } } - add_soap_fault(this_ptr, faultcode, faultstring ? ZSTR_VAL(faultstring) : NULL, faultactor ? ZSTR_VAL(faultactor) : NULL, &details); + add_soap_fault(this_ptr, faultcode, faultstring ? ZSTR_VAL(faultstring) : NULL, faultactor ? ZSTR_VAL(faultactor) : NULL, &details, lang); if (faultstring) { zend_string_release_ex(faultstring, 0); } if (faultactor) { zend_string_release_ex(faultactor, 0); } + if (lang) { + zend_string_release_ex(lang, false); + } if (Z_REFCOUNTED(details)) { Z_DELREF(details); } diff --git a/ext/soap/php_soap.h b/ext/soap/php_soap.h index 89dbf4408be2f..98e3d4af6f19d 100644 --- a/ext/soap/php_soap.h +++ b/ext/soap/php_soap.h @@ -170,6 +170,7 @@ ZEND_BEGIN_MODULE_GLOBALS(soap) HashTable wsdl_cache; int cur_uniq_ref; HashTable *ref_map; + zend_string *lang_en; ZEND_END_MODULE_GLOBALS(soap) #ifdef ZTS @@ -194,7 +195,7 @@ extern zend_class_entry* soap_sdl_class_entry; extern HashTable php_soap_defEncNs, php_soap_defEnc, php_soap_defEncIndex; -void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail); +void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, zend_string *lang); #define soap_error0(severity, format) \ php_error(severity, "SOAP-ERROR: " format) diff --git a/ext/soap/soap.c b/ext/soap/soap.c index e0577ac648cae..7955af8941724 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -49,9 +49,10 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf); static void type_to_string(sdlTypePtr type, smart_str *buf, int level); static void clear_soap_fault(zval *obj); -static void set_soap_fault(zval *obj, const char *fault_code_ns, const char *fault_code, const char *fault_string, const char *fault_actor, zval *fault_detail, zend_string *name); -static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail); -static ZEND_NORETURN void soap_server_fault(char* code, char* string, char *actor, zval* details, zend_string *name); +static void set_soap_fault(zval *obj, const char *fault_code_ns, const char *fault_code, const char *fault_string, const char *fault_actor, zval *fault_detail, zend_string *name, zend_string *lang); +static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, zend_string *lang); +static ZEND_NORETURN void soap_server_fault(char* code, char* string, char *actor, zval* details, zend_string *name, zend_string *lang); +static ZEND_NORETURN void soap_server_fault_en(char* code, char* string, char *actor, zval* details, zend_string *name); static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeader* hdr); static sdlParamPtr get_param(sdlFunctionPtr function, const char *param_name, zend_ulong index, int); @@ -156,6 +157,7 @@ static void soap_error_handler(int error_num, zend_string *error_filename, uint3 #define Z_FAULT_DETAIL_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), FAULT_PROP_START_OFFSET + 4)) #define Z_FAULT_NAME_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), FAULT_PROP_START_OFFSET + 5)) #define Z_FAULT_HEADERFAULT_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), FAULT_PROP_START_OFFSET + 6)) +#define Z_FAULT_LANG_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), FAULT_PROP_START_OFFSET + 7)) #define FETCH_THIS_SERVICE_NO_BAILOUT(ss) \ { \ @@ -448,6 +450,7 @@ static void php_soap_init_globals(zend_soap_globals *soap_globals) soap_globals->soap_version = SOAP_1_1; soap_globals->mem_cache = NULL; soap_globals->ref_map = NULL; + soap_globals->lang_en = zend_string_init_interned(ZEND_STRL("en"), true); } PHP_MSHUTDOWN_FUNCTION(soap) @@ -467,6 +470,7 @@ PHP_MSHUTDOWN_FUNCTION(soap) zend_hash_destroy(SOAP_GLOBAL(mem_cache)); free(SOAP_GLOBAL(mem_cache)); } + zend_string_release_ex(SOAP_GLOBAL(lang_en), true); UNREGISTER_INI_ENTRIES(); return SUCCESS; } @@ -645,6 +649,7 @@ static void soap_fault_dtor_properties(zval *obj) zval_ptr_dtor(Z_FAULT_DETAIL_P(obj)); zval_ptr_dtor(Z_FAULT_NAME_P(obj)); zval_ptr_dtor(Z_FAULT_HEADERFAULT_P(obj)); + zval_ptr_dtor(Z_FAULT_LANG_P(obj)); ZVAL_EMPTY_STRING(Z_FAULT_STRING_P(obj)); ZVAL_NULL(Z_FAULT_CODE_P(obj)); ZVAL_NULL(Z_FAULT_CODENS_P(obj)); @@ -652,6 +657,7 @@ static void soap_fault_dtor_properties(zval *obj) ZVAL_NULL(Z_FAULT_DETAIL_P(obj)); ZVAL_NULL(Z_FAULT_NAME_P(obj)); ZVAL_NULL(Z_FAULT_HEADERFAULT_P(obj)); + ZVAL_NULL(Z_FAULT_LANG_P(obj)); } /* {{{ SoapFault constructor */ @@ -660,11 +666,12 @@ PHP_METHOD(SoapFault, __construct) char *fault_string = NULL, *fault_code = NULL, *fault_actor = NULL, *fault_code_ns = NULL; size_t fault_string_len, fault_actor_len = 0, fault_code_len = 0; zend_string *name = NULL; + zend_string *lang = NULL; zval *details = NULL, *headerfault = NULL, *this_ptr; zend_string *code_str; HashTable *code_ht; - ZEND_PARSE_PARAMETERS_START(2, 6) + ZEND_PARSE_PARAMETERS_START(2, 7) Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(code_ht, code_str) Z_PARAM_STRING(fault_string, fault_string_len) Z_PARAM_OPTIONAL @@ -672,6 +679,7 @@ PHP_METHOD(SoapFault, __construct) Z_PARAM_ZVAL_OR_NULL(details) Z_PARAM_STR_OR_NULL(name) Z_PARAM_ZVAL_OR_NULL(headerfault) + Z_PARAM_PATH_STR_OR_NULL(lang) ZEND_PARSE_PARAMETERS_END(); if (code_str) { @@ -700,7 +708,7 @@ PHP_METHOD(SoapFault, __construct) } this_ptr = ZEND_THIS; - set_soap_fault(this_ptr, fault_code_ns, fault_code, fault_string, fault_actor, details, name); + set_soap_fault(this_ptr, fault_code_ns, fault_code, fault_string, fault_actor, details, name, lang); if (headerfault != NULL) { ZVAL_COPY(Z_FAULT_HEADERFAULT_P(this_ptr), headerfault); } @@ -1245,10 +1253,10 @@ static void _soap_server_exception(soapServicePtr service, sdlFunctionPtr functi if (service->send_errors) { zval rv; zend_string *msg = zval_get_string(zend_read_property_ex(zend_ce_error, Z_OBJ(exception_object), ZSTR_KNOWN(ZEND_STR_MESSAGE), /* silent */ false, &rv)); - add_soap_fault_ex(&exception_object, this_ptr, "Server", ZSTR_VAL(msg), NULL, NULL); + add_soap_fault_ex(&exception_object, this_ptr, "Server", ZSTR_VAL(msg), NULL, NULL, SOAP_GLOBAL(lang_en)); zend_string_release_ex(msg, 0); } else { - add_soap_fault_ex(&exception_object, this_ptr, "Server", "Internal Error", NULL, NULL); + add_soap_fault_ex(&exception_object, this_ptr, "Server", "Internal Error", NULL, NULL, SOAP_GLOBAL(lang_en)); } soap_server_fault_ex(function, &exception_object, NULL); } @@ -1288,7 +1296,7 @@ PHP_METHOD(SoapServer, handle) SOAP_GLOBAL(soap_version) = service->version; if (arg && ZEND_SIZE_T_INT_OVFL(arg_len)) { - soap_server_fault("Server", "Input string is too long", NULL, NULL, NULL); + soap_server_fault_en("Server", "Input string is too long", NULL, NULL, NULL); SOAP_SERVER_END_CODE(); return; } @@ -1314,13 +1322,13 @@ PHP_METHOD(SoapServer, handle) php_stream_passthru(stream); php_stream_close(stream); } else { - soap_server_fault("Server", "Couldn't find WSDL", NULL, NULL, NULL); + soap_server_fault_en("Server", "Couldn't find WSDL", NULL, NULL, NULL); } SOAP_SERVER_END_CODE(); return; } else { - soap_server_fault("Server", "WSDL generation is not supported yet", NULL, NULL, NULL); + soap_server_fault_en("Server", "WSDL generation is not supported yet", NULL, NULL, NULL); /* sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8"), 1); PUTS("\nchildren,"Envelope"); @@ -1405,7 +1413,7 @@ PHP_METHOD(SoapServer, handle) } } xmlFreeDoc(doc_request); - soap_server_fault("Server", "DTD are not supported by SOAP", NULL, NULL, NULL); + soap_server_fault_en("Server", "DTD are not supported by SOAP", NULL, NULL, NULL); } old_sdl = SOAP_GLOBAL(sdl); @@ -1463,7 +1471,7 @@ PHP_METHOD(SoapServer, handle) soap_obj = tmp_soap_p; } else if (Z_OBJCE_P(tmp_soap_p) == php_ce_incomplete_class) { /* See #51561, communicate limitation to user */ - soap_server_fault("Server", "SoapServer class was deserialized from the session prior to loading the class passed to SoapServer::setClass(). Start the session after loading all classes to resolve this issue.", NULL, NULL, NULL); + soap_server_fault_en("Server", "SoapServer class was deserialized from the session prior to loading the class passed to SoapServer::setClass(). Start the session after loading all classes to resolve this issue.", NULL, NULL, NULL); } } } @@ -1522,7 +1530,7 @@ PHP_METHOD(SoapServer, handle) #if 0 if (service->sdl && !h->function && !h->hdr) { if (h->mustUnderstand) { - soap_server_fault("MustUnderstand","Header not understood", NULL, NULL, NULL); + soap_server_fault_en("MustUnderstand","Header not understood", NULL, NULL, NULL); } else { continue; } @@ -1553,7 +1561,7 @@ PHP_METHOD(SoapServer, handle) goto fail; } } else if (h->mustUnderstand) { - soap_server_fault("MustUnderstand","Header not understood", NULL, NULL, NULL); + soap_server_fault_en("MustUnderstand","Header not understood", NULL, NULL, NULL); } } } @@ -1716,12 +1724,13 @@ PHP_METHOD(SoapServer, fault) size_t code_len, string_len, actor_len = 0; zval* details = NULL; zend_string *name = NULL; + zend_string *lang = NULL; soapServicePtr service; xmlCharEncodingHandlerPtr old_encoding; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|szS", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|szSS!", &code, &code_len, &string, &string_len, &actor, &actor_len, &details, - &name) == FAILURE) { + &name, &lang) == FAILURE) { RETURN_THROWS(); } @@ -1730,7 +1739,7 @@ PHP_METHOD(SoapServer, fault) old_encoding = SOAP_GLOBAL(encoding); SOAP_GLOBAL(encoding) = service->encoding; - soap_server_fault(code, string, actor, details, name); + soap_server_fault(code, string, actor, details, name, lang); SOAP_GLOBAL(encoding) = old_encoding; SOAP_SERVER_END_CODE(); @@ -1826,18 +1835,23 @@ static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeade } /* }}} */ -static ZEND_NORETURN void soap_server_fault(char* code, char* string, char *actor, zval* details, zend_string* name) /* {{{ */ +static ZEND_NORETURN void soap_server_fault(char* code, char* string, char *actor, zval* details, zend_string* name, zend_string *lang) /* {{{ */ { zval ret; ZVAL_NULL(&ret); - set_soap_fault(&ret, NULL, code, string, actor, details, name); + set_soap_fault(&ret, NULL, code, string, actor, details, name, lang); /* TODO: Which function */ soap_server_fault_ex(NULL, &ret, NULL); zend_bailout(); } /* }}} */ +static ZEND_NORETURN void soap_server_fault_en(char* code, char* string, char *actor, zval* details, zend_string* name) +{ + soap_server_fault(code, string, actor, details, name, SOAP_GLOBAL(lang_en)); +} + static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */ { bool _old_in_compilation; @@ -1861,7 +1875,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, z code = "Client"; } - add_soap_fault_ex(&fault, &SOAP_GLOBAL(error_object), code, ZSTR_VAL(message), NULL, NULL); + add_soap_fault_ex(&fault, &SOAP_GLOBAL(error_object), code, ZSTR_VAL(message), NULL, NULL, SOAP_GLOBAL(lang_en)); Z_ADDREF(fault); zend_throw_exception_object(&fault); zend_bailout(); @@ -1904,7 +1918,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, z } ZVAL_NULL(&fault_obj); - set_soap_fault(&fault_obj, NULL, code, ZSTR_VAL(buffer), NULL, &outbuf, NULL); + set_soap_fault(&fault_obj, NULL, code, ZSTR_VAL(buffer), NULL, &outbuf, NULL, SOAP_GLOBAL(lang_en)); zend_string_release(buffer); fault = 1; } @@ -2215,7 +2229,7 @@ static bool do_request(zval *this_ptr, xmlDoc *request, const char *location, co xmlDocDumpMemory(request, (xmlChar**)&buf, &buf_size); if (!buf) { - add_soap_fault(this_ptr, "HTTP", "Error build soap request", NULL, NULL); + add_soap_fault(this_ptr, "HTTP", "Error build soap request", NULL, NULL, SOAP_GLOBAL(lang_en)); return false; } @@ -2245,7 +2259,7 @@ static bool do_request(zval *this_ptr, xmlDoc *request, const char *location, co if (EG(exception) && instanceof_function(EG(exception)->ce, zend_ce_error)) { /* Programmer error in __doRequest() implementation, let it bubble up. */ } else if (Z_TYPE_P(Z_CLIENT_SOAP_FAULT_P(this_ptr)) != IS_OBJECT) { - add_soap_fault(this_ptr, "Client", "SoapClient::__doRequest() returned non string value", NULL, NULL); + add_soap_fault(this_ptr, "Client", "SoapClient::__doRequest() returned non string value", NULL, NULL, SOAP_GLOBAL(lang_en)); } ret = false; } else if (Z_TYPE_P(trace) == IS_TRUE) { @@ -2405,15 +2419,15 @@ static void do_soap_call(zend_execute_data *execute_data, smart_str_append(&error,function); smart_str_appends(&error,"\") is not a valid method for this service"); smart_str_0(&error); - add_soap_fault(this_ptr, "Client", ZSTR_VAL(error.s), NULL, NULL); + add_soap_fault(this_ptr, "Client", ZSTR_VAL(error.s), NULL, NULL, SOAP_GLOBAL(lang_en)); smart_str_free(&error); } } else { zval *uri = Z_CLIENT_URI_P(this_ptr); if (Z_TYPE_P(uri) != IS_STRING) { - add_soap_fault(this_ptr, "Client", "Error finding \"uri\" property", NULL, NULL); + add_soap_fault(this_ptr, "Client", "Error finding \"uri\" property", NULL, NULL, SOAP_GLOBAL(lang_en)); } else if (location == NULL) { - add_soap_fault(this_ptr, "Client", "Error could not find \"location\" property", NULL, NULL); + add_soap_fault(this_ptr, "Client", "Error could not find \"location\" property", NULL, NULL, SOAP_GLOBAL(lang_en)); } else { if (call_uri == NULL) { call_uri = Z_STR_P(uri); @@ -2450,7 +2464,7 @@ static void do_soap_call(zend_execute_data *execute_data, if (Z_TYPE_P(fault) == IS_OBJECT) { ZVAL_COPY(return_value, fault); } else { - add_soap_fault_ex(return_value, this_ptr, "Client", "Unknown Error", NULL, NULL); + add_soap_fault_ex(return_value, this_ptr, "Client", "Unknown Error", NULL, NULL, SOAP_GLOBAL(lang_en)); Z_ADDREF_P(return_value); } } else { @@ -2898,10 +2912,10 @@ static void clear_soap_fault(zval *obj) /* {{{ */ } /* }}} */ -static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail) /* {{{ */ +static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, zend_string *lang) /* {{{ */ { ZVAL_NULL(fault); - set_soap_fault(fault, NULL, fault_code, fault_string, fault_actor, fault_detail, NULL); + set_soap_fault(fault, NULL, fault_code, fault_string, fault_actor, fault_detail, NULL, lang); zval *target; if (instanceof_function(Z_OBJCE_P(obj), soap_class_entry)) { target = Z_CLIENT_SOAP_FAULT_P(obj); @@ -2915,14 +2929,14 @@ static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fa } /* }}} */ -void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail) /* {{{ */ +void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, zend_string *lang) /* {{{ */ { zval fault; - add_soap_fault_ex(&fault, obj, fault_code, fault_string, fault_actor, fault_detail); + add_soap_fault_ex(&fault, obj, fault_code, fault_string, fault_actor, fault_detail, lang); } /* }}} */ -static void set_soap_fault(zval *obj, const char *fault_code_ns, const char *fault_code, const char *fault_string, const char *fault_actor, zval *fault_detail, zend_string *name) /* {{{ */ +static void set_soap_fault(zval *obj, const char *fault_code_ns, const char *fault_code, const char *fault_string, const char *fault_actor, zval *fault_detail, zend_string *name, zend_string *lang) /* {{{ */ { if (Z_TYPE_P(obj) != IS_OBJECT) { object_init_ex(obj, soap_fault_class_entry); @@ -2973,6 +2987,9 @@ static void set_soap_fault(zval *obj, const char *fault_code_ns, const char *fau if (name != NULL) { ZVAL_STR_COPY(Z_FAULT_NAME_P(obj), name); } + if (lang != NULL) { + ZVAL_STR_COPY(Z_FAULT_LANG_P(obj), lang); + } } /* }}} */ @@ -3043,7 +3060,7 @@ static void deserialize_parameters(xmlNodePtr params, sdlFunctionPtr function, u sdlParamPtr param = NULL; if (function != NULL && (param = zend_hash_index_find_ptr(function->requestParameters, cur_param)) == NULL) { - soap_server_fault("Client", "Error cannot find parameter", NULL, NULL, NULL); + soap_server_fault_en("Client", "Error cannot find parameter", NULL, NULL, NULL); } if (param == NULL) { enc = NULL; @@ -3058,7 +3075,7 @@ static void deserialize_parameters(xmlNodePtr params, sdlFunctionPtr function, u } } if (num_of_params > cur_param) { - soap_server_fault("Client","Missing parameter", NULL, NULL, NULL); + soap_server_fault_en("Client","Missing parameter", NULL, NULL, NULL); } (*parameters) = tmp_parameters; (*num_params) = num_of_params; @@ -3145,7 +3162,7 @@ static xmlNodePtr get_envelope(xmlNodePtr trav, int *version, char **envelope_ns return trav; } - soap_server_fault("VersionMismatch", "Wrong Version", NULL, NULL, NULL); + soap_server_fault_en("VersionMismatch", "Wrong Version", NULL, NULL, NULL); } trav = trav->next; } @@ -3165,18 +3182,18 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c /* Get element */ env = get_envelope(request->children, version, &envelope_ns); if (!env) { - soap_server_fault("Client", "looks like we got XML without \"Envelope\" element", NULL, NULL, NULL); + soap_server_fault_en("Client", "looks like we got XML without \"Envelope\" element", NULL, NULL, NULL); } attr = env->properties; while (attr != NULL) { if (attr->ns == NULL) { - soap_server_fault("Client", "A SOAP Envelope element cannot have non Namespace qualified attributes", NULL, NULL, NULL); + soap_server_fault_en("Client", "A SOAP Envelope element cannot have non Namespace qualified attributes", NULL, NULL, NULL); } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) { if (*version == SOAP_1_2) { - soap_server_fault("Client", "encodingStyle cannot be specified on the Envelope", NULL, NULL, NULL); + soap_server_fault_en("Client", "encodingStyle cannot be specified on the Envelope", NULL, NULL, NULL); } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) { - soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL); + soap_server_fault_en("Client", "Unknown data encoding style", NULL, NULL, NULL); } } attr = attr->next; @@ -3206,26 +3223,26 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c trav = trav->next; } if (body == NULL) { - soap_server_fault("Client", "Body must be present in a SOAP envelope", NULL, NULL, NULL); + soap_server_fault_en("Client", "Body must be present in a SOAP envelope", NULL, NULL, NULL); } attr = body->properties; while (attr != NULL) { if (attr->ns == NULL) { if (*version == SOAP_1_2) { - soap_server_fault("Client", "A SOAP Body element cannot have non Namespace qualified attributes", NULL, NULL, NULL); + soap_server_fault_en("Client", "A SOAP Body element cannot have non Namespace qualified attributes", NULL, NULL, NULL); } } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) { if (*version == SOAP_1_2) { - soap_server_fault("Client", "encodingStyle cannot be specified on the Body", NULL, NULL, NULL); + soap_server_fault_en("Client", "encodingStyle cannot be specified on the Body", NULL, NULL, NULL); } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) { - soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL); + soap_server_fault_en("Client", "Unknown data encoding style", NULL, NULL, NULL); } } attr = attr->next; } if (trav != NULL && *version == SOAP_1_2) { - soap_server_fault("Client", "A SOAP 1.2 envelope can contain only Header and Body", NULL, NULL, NULL); + soap_server_fault_en("Client", "A SOAP 1.2 envelope can contain only Header and Body", NULL, NULL, NULL); } func = NULL; @@ -3234,7 +3251,7 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c if (trav->type == XML_ELEMENT_NODE) { /* if (func != NULL) { - soap_server_fault("Client", "looks like we got \"Body\" with several functions call", NULL, NULL, NULL); + soap_server_fault_en("Client", "looks like we got \"Body\" with several functions call", NULL, NULL, NULL); } */ func = trav; @@ -3251,19 +3268,19 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c if (function) { ZVAL_STRING(function_name, (char *)function->functionName); } else { - soap_server_fault("Client", "looks like we got \"Body\" without function call", NULL, NULL, NULL); + soap_server_fault_en("Client", "looks like we got \"Body\" without function call", NULL, NULL, NULL); } } } else { if (*version == SOAP_1_1) { attr = get_attribute_ex(func->properties,"encodingStyle",SOAP_1_1_ENV_NAMESPACE); if (attr && strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) { - soap_server_fault("Client","Unknown Data Encoding Style", NULL, NULL, NULL); + soap_server_fault_en("Client","Unknown Data Encoding Style", NULL, NULL, NULL); } } else { attr = get_attribute_ex(func->properties,"encodingStyle",SOAP_1_2_ENV_NAMESPACE); if (attr && strcmp((char*)attr->children->content,SOAP_1_2_ENC_NAMESPACE) != 0) { - soap_server_fault("DataEncodingUnknown","Unknown Data Encoding Style", NULL, NULL, NULL); + soap_server_fault_en("DataEncodingUnknown","Unknown Data Encoding Style", NULL, NULL, NULL); } } if (!function) { @@ -3271,7 +3288,7 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c } if (sdl != NULL && function == NULL) { if (*version == SOAP_1_2) { - soap_server_fault("rpc:ProcedureNotPresent","Procedure not present", NULL, NULL, NULL); + soap_server_fault_en("rpc:ProcedureNotPresent","Procedure not present", NULL, NULL, NULL); } else { php_error(E_ERROR, "Procedure '%s' not present", func->name); } @@ -3285,12 +3302,12 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c attr = head->properties; while (attr != NULL) { if (attr->ns == NULL) { - soap_server_fault("Client", "A SOAP Header element cannot have non Namespace qualified attributes", NULL, NULL, NULL); + soap_server_fault_en("Client", "A SOAP Header element cannot have non Namespace qualified attributes", NULL, NULL, NULL); } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) { if (*version == SOAP_1_2) { - soap_server_fault("Client", "encodingStyle cannot be specified on the Header", NULL, NULL, NULL); + soap_server_fault_en("Client", "encodingStyle cannot be specified on the Header", NULL, NULL, NULL); } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) { - soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL); + soap_server_fault_en("Client", "Unknown data encoding style", NULL, NULL, NULL); } } attr = attr->next; @@ -3304,7 +3321,7 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c if (*version == SOAP_1_1) { attr = get_attribute_ex(hdr_func->properties,"encodingStyle",SOAP_1_1_ENV_NAMESPACE); if (attr && strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) { - soap_server_fault("Client","Unknown Data Encoding Style", NULL, NULL, NULL); + soap_server_fault_en("Client","Unknown Data Encoding Style", NULL, NULL, NULL); } attr = get_attribute_ex(hdr_func->properties,"actor",envelope_ns); if (attr != NULL) { @@ -3316,7 +3333,7 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c } else if (*version == SOAP_1_2) { attr = get_attribute_ex(hdr_func->properties,"encodingStyle",SOAP_1_2_ENV_NAMESPACE); if (attr && strcmp((char*)attr->children->content,SOAP_1_2_ENC_NAMESPACE) != 0) { - soap_server_fault("DataEncodingUnknown","Unknown Data Encoding Style", NULL, NULL, NULL); + soap_server_fault_en("DataEncodingUnknown","Unknown Data Encoding Style", NULL, NULL, NULL); } attr = get_attribute_ex(hdr_func->properties,"role",envelope_ns); if (attr != NULL) { @@ -3336,7 +3353,7 @@ static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, c strcmp((char*)attr->children->content,"false") == 0) { mustUnderstand = 0; } else { - soap_server_fault("Client","mustUnderstand value is not boolean", NULL, NULL, NULL); + soap_server_fault_en("Client","mustUnderstand value is not boolean", NULL, NULL, NULL); } } h = emalloc(sizeof(soapHeader)); @@ -3565,7 +3582,7 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, const char *fu ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENV_NAMESPACE), BAD_CAST(SOAP_1_2_ENV_NS_PREFIX)); xmlSetNs(envelope,ns); } else { - soap_server_fault("Server", "Unknown SOAP version", NULL, NULL, NULL); + soap_server_fault_en("Server", "Unknown SOAP version", NULL, NULL, NULL); } xmlDocSetRootElement(doc, envelope); @@ -3734,6 +3751,11 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, const char *fu node = master_to_xml(get_conversion(IS_STRING), tmp, SOAP_LITERAL, node); xmlNodeSetName(node, BAD_CAST("Text")); xmlSetNs(node, ns); + + /* xml:lang attribute is required for in SOAP 1.2 */ + tmp = Z_FAULT_LANG_P(ret); + zend_string *lang = Z_ISNULL_P(tmp) ? ZSTR_EMPTY_ALLOC() : Z_STR_P(tmp); + xmlNodeSetLang(node, BAD_CAST ZSTR_VAL(lang)); } detail_name = SOAP_1_2_ENV_NS_PREFIX":Detail"; } diff --git a/ext/soap/soap.stub.php b/ext/soap/soap.stub.php index 82f884e24b308..bae208625a085 100644 --- a/ext/soap/soap.stub.php +++ b/ext/soap/soap.stub.php @@ -477,8 +477,9 @@ class SoapFault extends Exception public mixed $detail = null; public ?string $_name = null; public mixed $headerfault = null; + public ?string $lang = null; - public function __construct(array|string|null $code, string $string, ?string $actor = null, mixed $details = null, ?string $name = null, mixed $headerFault = null) {} + public function __construct(array|string|null $code, string $string, ?string $actor = null, mixed $details = null, ?string $name = null, mixed $headerFault = null, ?string $lang = null) {} public function __toString(): string {} } @@ -502,7 +503,7 @@ class SoapServer public function __construct(?string $wsdl, array $options = []) {} /** @tentative-return-type */ - public function fault(string $code, string $string, string $actor = "", mixed $details = null, string $name = ""): void {} + public function fault(string $code, string $string, string $actor = "", mixed $details = null, string $name = "", ?string $lang = null): void {} /** @tentative-return-type */ public function addSoapHeader(SoapHeader $header): void {} diff --git a/ext/soap/soap_arginfo.h b/ext/soap/soap_arginfo.h index 9ec093c5c9cd2..3f51a0c3eb8fe 100644 --- a/ext/soap/soap_arginfo.h +++ b/ext/soap/soap_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7712aba90b16090fbe7c124c1e3f26b2cc3e2ab2 */ + * Stub hash: d659b333906570feb6b50f9aaccf3f5714504c70 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_use_soap_error_handler, 0, 0, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 0, "true") @@ -29,6 +29,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SoapFault___construct, 0, 0, 2) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, details, IS_MIXED, 0, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, headerFault, IS_MIXED, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, lang, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SoapFault___toString, 0, 0, IS_STRING, 0) @@ -54,6 +55,7 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SoapServer_fault ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, actor, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, details, IS_MIXED, 0, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, lang, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SoapServer_addSoapHeader, 0, 1, IS_VOID, 0) @@ -444,6 +446,12 @@ static zend_class_entry *register_class_SoapFault(zend_class_entry *class_entry_ zend_declare_typed_property(class_entry, property_headerfault_name, &property_headerfault_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ANY)); zend_string_release(property_headerfault_name); + zval property_lang_default_value; + ZVAL_NULL(&property_lang_default_value); + zend_string *property_lang_name = zend_string_init("lang", sizeof("lang") - 1, 1); + zend_declare_typed_property(class_entry, property_lang_name, &property_lang_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); + zend_string_release(property_lang_name); + return class_entry; } diff --git a/ext/soap/tests/bugs/bug38005.phpt b/ext/soap/tests/bugs/bug38005.phpt index e77278b1b6b64..ca3944ebc3db3 100644 --- a/ext/soap/tests/bugs/bug38005.phpt +++ b/ext/soap/tests/bugs/bug38005.phpt @@ -42,4 +42,4 @@ echo($client->__getLastResponse()); --EXPECT-- This is our fault: Ä -TestThis is our fault: Ä +TestThis is our fault: Ä diff --git a/ext/soap/tests/bugs/bug68996.phpt b/ext/soap/tests/bugs/bug68996.phpt index 618f5ec730e7e..bcc0e66cbebf9 100644 --- a/ext/soap/tests/bugs/bug68996.phpt +++ b/ext/soap/tests/bugs/bug68996.phpt @@ -56,4 +56,4 @@ handleFormatted($s, $HTTP_RAW_POST_DATA); some msg -some msg +some msg diff --git a/ext/soap/tests/bugs/bug73037.phpt b/ext/soap/tests/bugs/bug73037.phpt index da89382beb2c0..7a5b997767729 100644 --- a/ext/soap/tests/bugs/bug73037.phpt +++ b/ext/soap/tests/bugs/bug73037.phpt @@ -109,12 +109,13 @@ HDRS; $out .= fread($fp, 1024); } - $pos = strpos($out, ""); + $marker = ''; + $pos = strpos($out, $marker); if (false === $pos) { echo $out; goto cleanup; } - $pos0 = $pos + strlen(""); + $pos0 = $pos + strlen($marker); $pos = strpos($out, ""); if (false === $pos) { echo $out; diff --git a/ext/soap/tests/fault_language.phpt b/ext/soap/tests/fault_language.phpt new file mode 100644 index 0000000000000..9cadad2619f03 --- /dev/null +++ b/ext/soap/tests/fault_language.phpt @@ -0,0 +1,29 @@ +--TEST-- +SOAP Server: user fault with language +--EXTENSIONS-- +soap +--FILE-- +fault("MyFault", "My fault string", lang: "custom"); +} + +$server = new SoapServer(null, ['uri' => 'http://testuri.org', 'soap_version' => SOAP_1_2]); +$server->addFunction("test"); + +$HTTP_RAW_POST_DATA = << + + + + + +EOF; + +$server->handle($HTTP_RAW_POST_DATA); +?> +--EXPECT-- + +MyFaultMy fault string diff --git a/ext/soap/tests/soap12/T12.phpt b/ext/soap/tests/soap12/T12.phpt index d3f21ca601446..e659ba0e216dd 100644 --- a/ext/soap/tests/soap12/T12.phpt +++ b/ext/soap/tests/soap12/T12.phpt @@ -20,4 +20,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:MustUnderstandHeader not understood +env:MustUnderstandHeader not understood diff --git a/ext/soap/tests/soap12/T13.phpt b/ext/soap/tests/soap12/T13.phpt index 011409b189a46..9a32367164273 100644 --- a/ext/soap/tests/soap12/T13.phpt +++ b/ext/soap/tests/soap12/T13.phpt @@ -20,4 +20,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:MustUnderstandHeader not understood +env:MustUnderstandHeader not understood diff --git a/ext/soap/tests/soap12/T14.phpt b/ext/soap/tests/soap12/T14.phpt index 30916455a471d..4ed23550b099b 100644 --- a/ext/soap/tests/soap12/T14.phpt +++ b/ext/soap/tests/soap12/T14.phpt @@ -20,4 +20,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:SendermustUnderstand value is not boolean +env:SendermustUnderstand value is not boolean diff --git a/ext/soap/tests/soap12/T23.phpt b/ext/soap/tests/soap12/T23.phpt index 1df101db6aa98..4f7f02893cf89 100644 --- a/ext/soap/tests/soap12/T23.phpt +++ b/ext/soap/tests/soap12/T23.phpt @@ -21,4 +21,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:SendermustUnderstand value is not boolean +env:SendermustUnderstand value is not boolean diff --git a/ext/soap/tests/soap12/T24.phpt b/ext/soap/tests/soap12/T24.phpt index a5b304d9843c2..f170b66c704ad 100644 --- a/ext/soap/tests/soap12/T24.phpt +++ b/ext/soap/tests/soap12/T24.phpt @@ -18,4 +18,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:VersionMismatchWrong Version +env:VersionMismatchWrong Version diff --git a/ext/soap/tests/soap12/T25.phpt b/ext/soap/tests/soap12/T25.phpt index 1993d6723a35f..f6e9bd8b4867c 100644 --- a/ext/soap/tests/soap12/T25.phpt +++ b/ext/soap/tests/soap12/T25.phpt @@ -19,4 +19,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:ReceiverDTD are not supported by SOAP +env:ReceiverDTD are not supported by SOAP diff --git a/ext/soap/tests/soap12/T27.phpt b/ext/soap/tests/soap12/T27.phpt index 097a0f6353072..09591b7faebdd 100644 --- a/ext/soap/tests/soap12/T27.phpt +++ b/ext/soap/tests/soap12/T27.phpt @@ -25,4 +25,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:ReceiverSOAP-ERROR: Encoding: Violation of encoding rules +env:ReceiverSOAP-ERROR: Encoding: Violation of encoding rules diff --git a/ext/soap/tests/soap12/T28.phpt b/ext/soap/tests/soap12/T28.phpt index 23deba54acd0a..01a3795e47094 100644 --- a/ext/soap/tests/soap12/T28.phpt +++ b/ext/soap/tests/soap12/T28.phpt @@ -18,4 +18,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:SenderencodingStyle cannot be specified on the Body +env:SenderencodingStyle cannot be specified on the Body diff --git a/ext/soap/tests/soap12/T33.phpt b/ext/soap/tests/soap12/T33.phpt index bd9667186a062..eccb85234d1cc 100644 --- a/ext/soap/tests/soap12/T33.phpt +++ b/ext/soap/tests/soap12/T33.phpt @@ -17,4 +17,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -rpc:ProcedureNotPresentProcedure not present +rpc:ProcedureNotPresentProcedure not present diff --git a/ext/soap/tests/soap12/T35.phpt b/ext/soap/tests/soap12/T35.phpt index a2d6436b7b28c..76d72be4372bc 100644 --- a/ext/soap/tests/soap12/T35.phpt +++ b/ext/soap/tests/soap12/T35.phpt @@ -21,4 +21,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:MustUnderstandHeader not understood +env:MustUnderstandHeader not understood diff --git a/ext/soap/tests/soap12/T36.phpt b/ext/soap/tests/soap12/T36.phpt index 86501ff740427..44cac71747c61 100644 --- a/ext/soap/tests/soap12/T36.phpt +++ b/ext/soap/tests/soap12/T36.phpt @@ -20,4 +20,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:MustUnderstandHeader not understood +env:MustUnderstandHeader not understood diff --git a/ext/soap/tests/soap12/T39.phpt b/ext/soap/tests/soap12/T39.phpt index 735e4882a6f5b..2d46655278aa5 100644 --- a/ext/soap/tests/soap12/T39.phpt +++ b/ext/soap/tests/soap12/T39.phpt @@ -19,4 +19,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:SendermustUnderstand value is not boolean +env:SendermustUnderstand value is not boolean diff --git a/ext/soap/tests/soap12/T56.phpt b/ext/soap/tests/soap12/T56.phpt index 7922bf78d1828..8feddb651d42b 100644 --- a/ext/soap/tests/soap12/T56.phpt +++ b/ext/soap/tests/soap12/T56.phpt @@ -30,4 +30,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:ReceiverSOAP-ERROR: Encoding: Unresolved reference '#data-2' +env:ReceiverSOAP-ERROR: Encoding: Unresolved reference '#data-2' diff --git a/ext/soap/tests/soap12/T58.phpt b/ext/soap/tests/soap12/T58.phpt index 59a9eba0b6116..69c20a4f8670e 100644 --- a/ext/soap/tests/soap12/T58.phpt +++ b/ext/soap/tests/soap12/T58.phpt @@ -24,4 +24,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:ReceiverSOAP-ERROR: Encoding: Violation of encoding rules +env:ReceiverSOAP-ERROR: Encoding: Violation of encoding rules diff --git a/ext/soap/tests/soap12/T59.phpt b/ext/soap/tests/soap12/T59.phpt index 4413301730467..69d597d9f96e7 100644 --- a/ext/soap/tests/soap12/T59.phpt +++ b/ext/soap/tests/soap12/T59.phpt @@ -25,4 +25,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:ReceiverSOAP-ERROR: Encoding: Violation of id and ref information items '#data' +env:ReceiverSOAP-ERROR: Encoding: Violation of id and ref information items '#data' diff --git a/ext/soap/tests/soap12/T61.phpt b/ext/soap/tests/soap12/T61.phpt index 79f5c1efff5ad..44fc42d0e09ab 100644 --- a/ext/soap/tests/soap12/T61.phpt +++ b/ext/soap/tests/soap12/T61.phpt @@ -25,4 +25,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:ReceiverSOAP-ERROR: Encoding: '*' may only be first arraySize value in list +env:ReceiverSOAP-ERROR: Encoding: '*' may only be first arraySize value in list diff --git a/ext/soap/tests/soap12/T63.phpt b/ext/soap/tests/soap12/T63.phpt index 4706241668de7..a8cf3c431b24b 100644 --- a/ext/soap/tests/soap12/T63.phpt +++ b/ext/soap/tests/soap12/T63.phpt @@ -21,5 +21,5 @@ include "soap12-test.inc"; ?> --EXPECT-- -Country code must be 2 letters.env:SenderNot a valid country code +Country code must be 2 letters.env:SenderNot a valid country code ok diff --git a/ext/soap/tests/soap12/T64.phpt b/ext/soap/tests/soap12/T64.phpt index 8196644e0472d..aea1caab38cd4 100644 --- a/ext/soap/tests/soap12/T64.phpt +++ b/ext/soap/tests/soap12/T64.phpt @@ -21,4 +21,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:ReceiverDTD are not supported by SOAP +env:ReceiverDTD are not supported by SOAP diff --git a/ext/soap/tests/soap12/T65.phpt b/ext/soap/tests/soap12/T65.phpt index 0c6f3b953e4f0..9ddd97f5d598a 100644 --- a/ext/soap/tests/soap12/T65.phpt +++ b/ext/soap/tests/soap12/T65.phpt @@ -23,4 +23,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:ReceiverDTD are not supported by SOAP +env:ReceiverDTD are not supported by SOAP diff --git a/ext/soap/tests/soap12/T69.phpt b/ext/soap/tests/soap12/T69.phpt index 44097d982e74e..c0aed746618f6 100644 --- a/ext/soap/tests/soap12/T69.phpt +++ b/ext/soap/tests/soap12/T69.phpt @@ -16,4 +16,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:SenderBody must be present in a SOAP envelope +env:SenderBody must be present in a SOAP envelope diff --git a/ext/soap/tests/soap12/T70.phpt b/ext/soap/tests/soap12/T70.phpt index 7a9be2d3ecc96..ee36184a4029c 100644 --- a/ext/soap/tests/soap12/T70.phpt +++ b/ext/soap/tests/soap12/T70.phpt @@ -20,4 +20,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:SenderA SOAP 1.2 envelope can contain only Header and Body +env:SenderA SOAP 1.2 envelope can contain only Header and Body diff --git a/ext/soap/tests/soap12/T71.phpt b/ext/soap/tests/soap12/T71.phpt index 7bed55473d981..ef0eeb6a8c7aa 100644 --- a/ext/soap/tests/soap12/T71.phpt +++ b/ext/soap/tests/soap12/T71.phpt @@ -21,4 +21,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:SenderA SOAP Envelope element cannot have non Namespace qualified attributes +env:SenderA SOAP Envelope element cannot have non Namespace qualified attributes diff --git a/ext/soap/tests/soap12/T72.phpt b/ext/soap/tests/soap12/T72.phpt index 76ae9d57bf1fb..8fc374901a401 100644 --- a/ext/soap/tests/soap12/T72.phpt +++ b/ext/soap/tests/soap12/T72.phpt @@ -19,4 +19,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:SenderencodingStyle cannot be specified on the Envelope +env:SenderencodingStyle cannot be specified on the Envelope diff --git a/ext/soap/tests/soap12/T80.phpt b/ext/soap/tests/soap12/T80.phpt index 521c34651b638..c7c03c78e35d0 100644 --- a/ext/soap/tests/soap12/T80.phpt +++ b/ext/soap/tests/soap12/T80.phpt @@ -16,4 +16,4 @@ include "soap12-test.inc"; ?> --EXPECT-- -env:DataEncodingUnknownUnknown Data Encoding Style +env:DataEncodingUnknownUnknown Data Encoding Style From 0bea07de5a88f7a6d3a1a422e7afb130c99ca436 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:11:42 +0200 Subject: [PATCH 2/4] Change lang from ?string to string --- ext/soap/soap.c | 8 ++++---- ext/soap/soap.stub.php | 6 +++--- ext/soap/soap_arginfo.h | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 7955af8941724..87b0678dc8189 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -657,7 +657,7 @@ static void soap_fault_dtor_properties(zval *obj) ZVAL_NULL(Z_FAULT_DETAIL_P(obj)); ZVAL_NULL(Z_FAULT_NAME_P(obj)); ZVAL_NULL(Z_FAULT_HEADERFAULT_P(obj)); - ZVAL_NULL(Z_FAULT_LANG_P(obj)); + ZVAL_EMPTY_STRING(Z_FAULT_LANG_P(obj)); } /* {{{ SoapFault constructor */ @@ -1724,11 +1724,11 @@ PHP_METHOD(SoapServer, fault) size_t code_len, string_len, actor_len = 0; zval* details = NULL; zend_string *name = NULL; - zend_string *lang = NULL; + zend_string *lang = ZSTR_EMPTY_ALLOC(); soapServicePtr service; xmlCharEncodingHandlerPtr old_encoding; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|szSS!", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|szSS", &code, &code_len, &string, &string_len, &actor, &actor_len, &details, &name, &lang) == FAILURE) { RETURN_THROWS(); @@ -3754,7 +3754,7 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, const char *fu /* xml:lang attribute is required for in SOAP 1.2 */ tmp = Z_FAULT_LANG_P(ret); - zend_string *lang = Z_ISNULL_P(tmp) ? ZSTR_EMPTY_ALLOC() : Z_STR_P(tmp); + zend_string *lang = Z_STR_P(tmp); xmlNodeSetLang(node, BAD_CAST ZSTR_VAL(lang)); } detail_name = SOAP_1_2_ENV_NS_PREFIX":Detail"; diff --git a/ext/soap/soap.stub.php b/ext/soap/soap.stub.php index bae208625a085..2520bd1346963 100644 --- a/ext/soap/soap.stub.php +++ b/ext/soap/soap.stub.php @@ -477,9 +477,9 @@ class SoapFault extends Exception public mixed $detail = null; public ?string $_name = null; public mixed $headerfault = null; - public ?string $lang = null; + public string $lang = ""; - public function __construct(array|string|null $code, string $string, ?string $actor = null, mixed $details = null, ?string $name = null, mixed $headerFault = null, ?string $lang = null) {} + public function __construct(array|string|null $code, string $string, ?string $actor = null, mixed $details = null, ?string $name = null, mixed $headerFault = null, string $lang = "") {} public function __toString(): string {} } @@ -503,7 +503,7 @@ class SoapServer public function __construct(?string $wsdl, array $options = []) {} /** @tentative-return-type */ - public function fault(string $code, string $string, string $actor = "", mixed $details = null, string $name = "", ?string $lang = null): void {} + public function fault(string $code, string $string, string $actor = "", mixed $details = null, string $name = "", string $lang = ""): void {} /** @tentative-return-type */ public function addSoapHeader(SoapHeader $header): void {} diff --git a/ext/soap/soap_arginfo.h b/ext/soap/soap_arginfo.h index 3f51a0c3eb8fe..e932f2af71093 100644 --- a/ext/soap/soap_arginfo.h +++ b/ext/soap/soap_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: d659b333906570feb6b50f9aaccf3f5714504c70 */ + * Stub hash: 78a27b18c6b4007494a6aed9acc5f6e99c6f0350 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_use_soap_error_handler, 0, 0, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 0, "true") @@ -29,7 +29,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SoapFault___construct, 0, 0, 2) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, details, IS_MIXED, 0, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, headerFault, IS_MIXED, 0, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, lang, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, lang, IS_STRING, 0, "\"\"") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SoapFault___toString, 0, 0, IS_STRING, 0) @@ -55,7 +55,7 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SoapServer_fault ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, actor, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, details, IS_MIXED, 0, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 0, "\"\"") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, lang, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, lang, IS_STRING, 0, "\"\"") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SoapServer_addSoapHeader, 0, 1, IS_VOID, 0) @@ -447,9 +447,9 @@ static zend_class_entry *register_class_SoapFault(zend_class_entry *class_entry_ zend_string_release(property_headerfault_name); zval property_lang_default_value; - ZVAL_NULL(&property_lang_default_value); + ZVAL_EMPTY_STRING(&property_lang_default_value); zend_string *property_lang_name = zend_string_init("lang", sizeof("lang") - 1, 1); - zend_declare_typed_property(class_entry, property_lang_name, &property_lang_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); + zend_declare_typed_property(class_entry, property_lang_name, &property_lang_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING)); zend_string_release(property_lang_name); return class_entry; From e144fc664bf86cc12c9613e03a6e3946c157a8a9 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:57:48 +0200 Subject: [PATCH 3/4] Factor out --- ext/soap/soap.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 87b0678dc8189..3f1a16c094774 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -50,10 +50,12 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level); static void clear_soap_fault(zval *obj); static void set_soap_fault(zval *obj, const char *fault_code_ns, const char *fault_code, const char *fault_string, const char *fault_actor, zval *fault_detail, zend_string *name, zend_string *lang); +static void add_soap_fault_en(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail); static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, zend_string *lang); +static void add_soap_fault_ex_en(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail); static ZEND_NORETURN void soap_server_fault(char* code, char* string, char *actor, zval* details, zend_string *name, zend_string *lang); -static ZEND_NORETURN void soap_server_fault_en(char* code, char* string, char *actor, zval* details, zend_string *name); static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeader* hdr); +static ZEND_NORETURN void soap_server_fault_en(char* code, char* string, char *actor, zval* details, zend_string *name); static sdlParamPtr get_param(sdlFunctionPtr function, const char *param_name, zend_ulong index, int); static sdlFunctionPtr get_function(sdlPtr sdl, const char *function_name, size_t function_name_length); @@ -1253,10 +1255,10 @@ static void _soap_server_exception(soapServicePtr service, sdlFunctionPtr functi if (service->send_errors) { zval rv; zend_string *msg = zval_get_string(zend_read_property_ex(zend_ce_error, Z_OBJ(exception_object), ZSTR_KNOWN(ZEND_STR_MESSAGE), /* silent */ false, &rv)); - add_soap_fault_ex(&exception_object, this_ptr, "Server", ZSTR_VAL(msg), NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_ex_en(&exception_object, this_ptr, "Server", ZSTR_VAL(msg), NULL, NULL); zend_string_release_ex(msg, 0); } else { - add_soap_fault_ex(&exception_object, this_ptr, "Server", "Internal Error", NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_ex_en(&exception_object, this_ptr, "Server", "Internal Error", NULL, NULL); } soap_server_fault_ex(function, &exception_object, NULL); } @@ -1875,7 +1877,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, z code = "Client"; } - add_soap_fault_ex(&fault, &SOAP_GLOBAL(error_object), code, ZSTR_VAL(message), NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_ex_en(&fault, &SOAP_GLOBAL(error_object), code, ZSTR_VAL(message), NULL, NULL); Z_ADDREF(fault); zend_throw_exception_object(&fault); zend_bailout(); @@ -2229,7 +2231,7 @@ static bool do_request(zval *this_ptr, xmlDoc *request, const char *location, co xmlDocDumpMemory(request, (xmlChar**)&buf, &buf_size); if (!buf) { - add_soap_fault(this_ptr, "HTTP", "Error build soap request", NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_en(this_ptr, "HTTP", "Error build soap request", NULL, NULL); return false; } @@ -2259,7 +2261,7 @@ static bool do_request(zval *this_ptr, xmlDoc *request, const char *location, co if (EG(exception) && instanceof_function(EG(exception)->ce, zend_ce_error)) { /* Programmer error in __doRequest() implementation, let it bubble up. */ } else if (Z_TYPE_P(Z_CLIENT_SOAP_FAULT_P(this_ptr)) != IS_OBJECT) { - add_soap_fault(this_ptr, "Client", "SoapClient::__doRequest() returned non string value", NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_en(this_ptr, "Client", "SoapClient::__doRequest() returned non string value", NULL, NULL); } ret = false; } else if (Z_TYPE_P(trace) == IS_TRUE) { @@ -2419,15 +2421,15 @@ static void do_soap_call(zend_execute_data *execute_data, smart_str_append(&error,function); smart_str_appends(&error,"\") is not a valid method for this service"); smart_str_0(&error); - add_soap_fault(this_ptr, "Client", ZSTR_VAL(error.s), NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_en(this_ptr, "Client", ZSTR_VAL(error.s), NULL, NULL); smart_str_free(&error); } } else { zval *uri = Z_CLIENT_URI_P(this_ptr); if (Z_TYPE_P(uri) != IS_STRING) { - add_soap_fault(this_ptr, "Client", "Error finding \"uri\" property", NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_en(this_ptr, "Client", "Error finding \"uri\" property", NULL, NULL); } else if (location == NULL) { - add_soap_fault(this_ptr, "Client", "Error could not find \"location\" property", NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_en(this_ptr, "Client", "Error could not find \"location\" property", NULL, NULL); } else { if (call_uri == NULL) { call_uri = Z_STR_P(uri); @@ -2464,7 +2466,7 @@ static void do_soap_call(zend_execute_data *execute_data, if (Z_TYPE_P(fault) == IS_OBJECT) { ZVAL_COPY(return_value, fault); } else { - add_soap_fault_ex(return_value, this_ptr, "Client", "Unknown Error", NULL, NULL, SOAP_GLOBAL(lang_en)); + add_soap_fault_ex_en(return_value, this_ptr, "Client", "Unknown Error", NULL, NULL); Z_ADDREF_P(return_value); } } else { @@ -2929,6 +2931,11 @@ static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fa } /* }}} */ +static void add_soap_fault_ex_en(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail) +{ + add_soap_fault_ex(fault, obj, fault_code, fault_string, fault_actor, fault_detail, SOAP_GLOBAL(lang_en)); +} + void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, zend_string *lang) /* {{{ */ { zval fault; @@ -2936,6 +2943,11 @@ void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault } /* }}} */ +static void add_soap_fault_en(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail) +{ + add_soap_fault(obj, fault_code, fault_string, fault_actor, fault_detail, SOAP_GLOBAL(lang_en)); +} + static void set_soap_fault(zval *obj, const char *fault_code_ns, const char *fault_code, const char *fault_string, const char *fault_actor, zval *fault_detail, zend_string *name, zend_string *lang) /* {{{ */ { if (Z_TYPE_P(obj) != IS_OBJECT) { From c51f0df32a7acd192cfe85aa2e747c36ab12b7ac Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 13 Jun 2025 18:35:35 +0200 Subject: [PATCH 4/4] review --- ext/soap/php_packet_soap.c | 6 ++---- ext/soap/soap.c | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/ext/soap/php_packet_soap.c b/ext/soap/php_packet_soap.c index 90e92a7cd4bdb..31ed094ef2fc7 100644 --- a/ext/soap/php_packet_soap.c +++ b/ext/soap/php_packet_soap.c @@ -177,7 +177,7 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio fault = get_node_ex(body->children,"Fault",envelope_ns); if (fault != NULL) { char *faultcode = NULL; - zend_string *lang = NULL; + zend_string *lang = ZSTR_EMPTY_ALLOC(); zend_string *faultstring = NULL, *faultactor = NULL; zval details; xmlNodePtr tmp; @@ -248,9 +248,7 @@ bool parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunctio if (faultactor) { zend_string_release_ex(faultactor, 0); } - if (lang) { - zend_string_release_ex(lang, false); - } + zend_string_release_ex(lang, false); if (Z_REFCOUNTED(details)) { Z_DELREF(details); } diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 3f1a16c094774..cdb0216ebcf83 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -668,7 +668,7 @@ PHP_METHOD(SoapFault, __construct) char *fault_string = NULL, *fault_code = NULL, *fault_actor = NULL, *fault_code_ns = NULL; size_t fault_string_len, fault_actor_len = 0, fault_code_len = 0; zend_string *name = NULL; - zend_string *lang = NULL; + zend_string *lang = ZSTR_EMPTY_ALLOC(); zval *details = NULL, *headerfault = NULL, *this_ptr; zend_string *code_str; HashTable *code_ht; @@ -681,7 +681,7 @@ PHP_METHOD(SoapFault, __construct) Z_PARAM_ZVAL_OR_NULL(details) Z_PARAM_STR_OR_NULL(name) Z_PARAM_ZVAL_OR_NULL(headerfault) - Z_PARAM_PATH_STR_OR_NULL(lang) + Z_PARAM_PATH_STR(lang) ZEND_PARSE_PARAMETERS_END(); if (code_str) { @@ -1730,7 +1730,7 @@ PHP_METHOD(SoapServer, fault) soapServicePtr service; xmlCharEncodingHandlerPtr old_encoding; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|szSS", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|szSP", &code, &code_len, &string, &string_len, &actor, &actor_len, &details, &name, &lang) == FAILURE) { RETURN_THROWS(); @@ -2999,9 +2999,7 @@ static void set_soap_fault(zval *obj, const char *fault_code_ns, const char *fau if (name != NULL) { ZVAL_STR_COPY(Z_FAULT_NAME_P(obj), name); } - if (lang != NULL) { - ZVAL_STR_COPY(Z_FAULT_LANG_P(obj), lang); - } + ZVAL_STR_COPY(Z_FAULT_LANG_P(obj), lang); } /* }}} */