Skip to content

Get rid of redundant SOAP globals #18702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/soap/php_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -3456,7 +3456,7 @@ xmlNsPtr encode_add_ns(xmlNodePtr node, const char* ns)
if (xmlns == NULL) {
xmlChar* prefix;

if ((prefix = zend_hash_str_find_ptr(&SOAP_GLOBAL(defEncNs), (char*)ns, strlen(ns))) != NULL) {
if ((prefix = zend_hash_str_find_ptr(&php_soap_defEncNs, (char*)ns, strlen(ns))) != NULL) {
xmlns = xmlNewNs(node->doc->children, BAD_CAST(ns), prefix);
} else {
smart_str prefix = {0};
Expand Down Expand Up @@ -3531,7 +3531,7 @@ encodePtr get_conversion(int encode)
{
encodePtr enc;

if ((enc = zend_hash_index_find_ptr(&SOAP_GLOBAL(defEncIndex), encode)) == NULL) {
if ((enc = zend_hash_index_find_ptr(&php_soap_defEncIndex, encode)) == NULL) {
soap_error0(E_ERROR, "Encoding: Cannot find encoding");
return NULL;
} else {
Expand Down
2 changes: 1 addition & 1 deletion ext/soap/php_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, size_t len)
{
encodePtr enc;

if ((enc = zend_hash_str_find_ptr(&SOAP_GLOBAL(defEnc), nscat, len)) != NULL) {
if ((enc = zend_hash_str_find_ptr(&php_soap_defEnc, nscat, len)) != NULL) {
return enc;
} else if (sdl && sdl->encoders && (enc = zend_hash_str_find_ptr(sdl->encoders, nscat, len)) != NULL) {
return enc;
Expand Down
5 changes: 2 additions & 3 deletions ext/soap/php_soap.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ struct _soapService {


ZEND_BEGIN_MODULE_GLOBALS(soap)
HashTable defEncNs; /* mapping of default namespaces to prefixes */
HashTable defEnc;
HashTable defEncIndex;
HashTable *typemap;
int cur_uniq_ns;
int soap_version;
Expand Down Expand Up @@ -195,6 +192,8 @@ extern zend_class_entry* soap_var_class_entry;
extern zend_class_entry* soap_url_class_entry;
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);

#define soap_error0(severity, format) \
Expand Down
39 changes: 19 additions & 20 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,18 @@ STD_PHP_INI_ENTRY("soap.wsdl_cache_limit", "5", PHP_INI_ALL, OnUpdateLong,
cache_limit, zend_soap_globals, soap_globals)
PHP_INI_END()

static HashTable defEnc, defEncIndex, defEncNs;
/* Real globals shared for the entire processes across threads, only written during init. */
HashTable php_soap_defEncNs; /* mapping of default namespaces to prefixes */
HashTable php_soap_defEnc, php_soap_defEncIndex;

static void php_soap_prepare_globals(void)
{
int i;
encode* enc;

zend_hash_init(&defEnc, 0, NULL, NULL, 1);
zend_hash_init(&defEncIndex, 0, NULL, NULL, 1);
zend_hash_init(&defEncNs, 0, NULL, NULL, 1);
zend_hash_init(&php_soap_defEnc, 0, NULL, NULL, 1);
zend_hash_init(&php_soap_defEncIndex, 0, NULL, NULL, 1);
zend_hash_init(&php_soap_defEncNs, 0, NULL, NULL, 1);

i = 0;
do {
Expand All @@ -412,35 +414,32 @@ static void php_soap_prepare_globals(void)
size_t clark_notation_len = spprintf(&clark_notation, 0, "{%s}%s", enc->details.ns, enc->details.type_str);
enc->details.clark_notation = zend_string_init(clark_notation, clark_notation_len, true);
size_t ns_type_len = spprintf(&ns_type, 0, "%s:%s", enc->details.ns, enc->details.type_str);
zend_hash_str_add_ptr(&defEnc, ns_type, ns_type_len, (void*)enc);
zend_hash_str_add_ptr(&php_soap_defEnc, ns_type, ns_type_len, (void*)enc);
efree(clark_notation);
efree(ns_type);
} else {
zend_hash_str_add_ptr(&defEnc, defaultEncoding[i].details.type_str, strlen(defaultEncoding[i].details.type_str), (void*)enc);
zend_hash_str_add_ptr(&php_soap_defEnc, defaultEncoding[i].details.type_str, strlen(defaultEncoding[i].details.type_str), (void*)enc);
}
}
/* Index everything by number */
zend_hash_index_add_ptr(&defEncIndex, defaultEncoding[i].details.type, (void*)enc);
zend_hash_index_add_ptr(&php_soap_defEncIndex, defaultEncoding[i].details.type, (void*)enc);
i++;
} while (defaultEncoding[i].details.type != END_KNOWN_TYPES);

/* hash by namespace */
zend_hash_str_add_ptr(&defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE)-1, XSD_NS_PREFIX);
zend_hash_str_add_ptr(&defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1, XSD_NS_PREFIX);
zend_hash_str_add_ptr(&defEncNs, XSI_NAMESPACE, sizeof(XSI_NAMESPACE)-1, XSI_NS_PREFIX);
zend_hash_str_add_ptr(&defEncNs, XML_NAMESPACE, sizeof(XML_NAMESPACE)-1, XML_NS_PREFIX);
zend_hash_str_add_ptr(&defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1, SOAP_1_1_ENC_NS_PREFIX);
zend_hash_str_add_ptr(&defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1, SOAP_1_2_ENC_NS_PREFIX);
zend_hash_str_add_ptr(&php_soap_defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE)-1, XSD_NS_PREFIX);
zend_hash_str_add_ptr(&php_soap_defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1, XSD_NS_PREFIX);
zend_hash_str_add_ptr(&php_soap_defEncNs, XSI_NAMESPACE, sizeof(XSI_NAMESPACE)-1, XSI_NS_PREFIX);
zend_hash_str_add_ptr(&php_soap_defEncNs, XML_NAMESPACE, sizeof(XML_NAMESPACE)-1, XML_NS_PREFIX);
zend_hash_str_add_ptr(&php_soap_defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1, SOAP_1_1_ENC_NS_PREFIX);
zend_hash_str_add_ptr(&php_soap_defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1, SOAP_1_2_ENC_NS_PREFIX);
}

static void php_soap_init_globals(zend_soap_globals *soap_globals)
{
#if defined(COMPILE_DL_SOAP) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
soap_globals->defEnc = defEnc;
soap_globals->defEncIndex = defEncIndex;
soap_globals->defEncNs = defEncNs;
soap_globals->typemap = NULL;
soap_globals->use_soap_error_handler = 0;
soap_globals->error_code = NULL;
Expand All @@ -461,9 +460,9 @@ PHP_MSHUTDOWN_FUNCTION(soap)
i++;
} while (defaultEncoding[i].details.type != END_KNOWN_TYPES);
zend_error_cb = old_error_handler;
zend_hash_destroy(&SOAP_GLOBAL(defEnc));
zend_hash_destroy(&SOAP_GLOBAL(defEncIndex));
zend_hash_destroy(&SOAP_GLOBAL(defEncNs));
zend_hash_destroy(&php_soap_defEnc);
zend_hash_destroy(&php_soap_defEncIndex);
zend_hash_destroy(&php_soap_defEncNs);
if (SOAP_GLOBAL(mem_cache)) {
zend_hash_destroy(SOAP_GLOBAL(mem_cache));
free(SOAP_GLOBAL(mem_cache));
Expand Down Expand Up @@ -765,7 +764,7 @@ PHP_METHOD(SoapVar, __construct)
if (type_is_null) {
ZVAL_LONG(Z_VAR_ENC_TYPE_P(this_ptr), UNKNOWN_TYPE);
} else {
if (zend_hash_index_exists(&SOAP_GLOBAL(defEncIndex), type)) {
if (zend_hash_index_exists(&php_soap_defEncIndex, type)) {
ZVAL_LONG(Z_VAR_ENC_TYPE_P(this_ptr), type);
} else {
zend_argument_value_error(2, "is not a valid encoding");
Expand Down