Skip to content

Commit

Permalink
Migrate SOAP URL resource to object
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed May 7, 2024
1 parent 2d66993 commit 64d0fa5
Show file tree
Hide file tree
Showing 6 changed files with 676 additions and 602 deletions.
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ PHP 8.4 UPGRADE NOTES
. Calling simplexml_import_dom() with a non-XML object now throws a TypeError
instead of a ValueError.

- SOAP:
. SoapClient::$httpurl is now a Soap\Url object rather than a resource.
Checks using is_resource() (i.e. is_resource($client->httpurl)) should be
replaced with checks for null (i.e. $client->httpurl !== null).
- SPL:
. Out of bounds accesses in SplFixedArray now throw an exception of type
OutOfBoundsException instead of RuntimeException. As OutOfBoundsException
Expand Down
16 changes: 11 additions & 5 deletions ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ int make_http_soap_request(zval *this_ptr,
if (stream != NULL) {
php_url *orig;
tmp = Z_CLIENT_HTTPURL_P(this_ptr);
if (Z_TYPE_P(tmp) == IS_RESOURCE &&
(orig = (php_url *) zend_fetch_resource_ex(tmp, "httpurl", le_url)) != NULL &&
if (Z_TYPE_P(tmp) == IS_OBJECT && instanceof_function(Z_OBJCE_P(tmp), soap_url_class_entry) &&
(orig = Z_SOAP_URL_P(tmp)->url) != NULL &&
((use_proxy && !use_ssl) ||
(((use_ssl && orig->scheme != NULL && zend_string_equals_literal(orig->scheme, "https")) ||
(!use_ssl && orig->scheme == NULL) ||
Expand Down Expand Up @@ -536,9 +536,15 @@ int make_http_soap_request(zval *this_ptr,

if (stream) {
zval *cookies, *login, *password;
zend_resource *ret = zend_register_resource(phpurl, le_url);
ZVAL_RES(Z_CLIENT_HTTPURL_P(this_ptr), ret);
GC_ADDREF(ret);

zval *url_zval = Z_CLIENT_HTTPURL_P(this_ptr);
if (Z_TYPE_P(url_zval) == IS_OBJECT) {
zval_ptr_dtor(url_zval);
}

object_init_ex(url_zval, soap_url_class_entry);
soap_url_object *url_obj = Z_SOAP_URL_P(url_zval);
url_obj->url = phpurl;

if (context &&
(tmp = php_stream_context_get_option(context, "http", "protocol_version")) != NULL &&
Expand Down
14 changes: 12 additions & 2 deletions ext/soap/php_soap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
# define stricmp strcasecmp
#endif

extern int le_url;

typedef struct _encodeType encodeType, *encodeTypePtr;
typedef struct _encode encode, *encodePtr;

Expand Down Expand Up @@ -194,6 +192,7 @@ ZEND_TSRMLS_CACHE_EXTERN()

extern zend_class_entry* soap_class_entry;
extern zend_class_entry* soap_var_class_entry;
extern zend_class_entry* soap_url_class_entry;

void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail);

Expand Down Expand Up @@ -253,4 +252,15 @@ static zend_always_inline zval *php_soap_deref(zval *zv) {
#define Z_CLIENT_LAST_REQUEST_HEADERS_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 34))
#define Z_CLIENT_LAST_RESPONSE_HEADERS_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 35))

typedef struct soap_url_object {
php_url *url;
zend_object std;
} soap_url_object;

static inline soap_url_object *soap_url_object_fetch(zend_object *obj)
{
return (soap_url_object *) ((char *) obj - XtOffsetOf(soap_url_object, std));
}

#define Z_SOAP_URL_P(zv) soap_url_object_fetch(Z_OBJ_P(zv))
#endif
55 changes: 41 additions & 14 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@


static int le_sdl = 0;
int le_url = 0;
static int le_typemap = 0;

typedef struct _soapHeader {
Expand Down Expand Up @@ -65,7 +64,6 @@ static xmlNodePtr serialize_parameter(sdlParamPtr param,zval *param_val,int inde
static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName, int style, xmlNodePtr parent);

static void delete_service(void *service);
static void delete_url(void *handle);
static void delete_hashtable(void *hashtable);

static void soap_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
Expand Down Expand Up @@ -178,8 +176,10 @@ static zend_class_entry* soap_fault_class_entry;
static zend_class_entry* soap_header_class_entry;
static zend_class_entry* soap_param_class_entry;
zend_class_entry* soap_var_class_entry;
zend_class_entry *soap_url_class_entry;

static zend_object_handlers soap_server_object_handlers;
static zend_object_handlers soap_url_object_handlers;

typedef struct {
soapServicePtr service;
Expand All @@ -206,6 +206,34 @@ static void soap_server_object_free(zend_object *obj) {
zend_object_std_dtor(obj);
}

static zend_object *soap_url_object_create(zend_class_entry *ce)
{
soap_url_object *url_obj = zend_object_alloc(sizeof(soap_url_object), ce);

zend_object_std_init(&url_obj->std, ce);
object_properties_init(&url_obj->std, ce);

return &url_obj->std;
}

static void soap_url_object_free(zend_object *obj)
{
soap_url_object *url_obj = soap_url_object_fetch(obj);

if (url_obj->url) {
php_url_free(url_obj->url);
url_obj->url = NULL;
}

zend_object_std_dtor(&url_obj->std);
}

static zend_function *soap_url_object_get_constructor(zend_object *object)
{
zend_throw_error(NULL, "Cannot directly construct Soap\\Url");

return NULL;
}
ZEND_DECLARE_MODULE_GLOBALS(soap)

static void (*old_error_handler)(int, zend_string *, const uint32_t, zend_string *);
Expand Down Expand Up @@ -395,11 +423,6 @@ static void delete_sdl_res(zend_resource *res)
delete_sdl(res->ptr);
}

static void delete_url_res(zend_resource *res)
{
delete_url(res->ptr);
}

static void delete_hashtable_res(zend_resource *res)
{
delete_hashtable(res->ptr);
Expand Down Expand Up @@ -436,9 +459,19 @@ PHP_MINIT_FUNCTION(soap)
soap_header_class_entry = register_class_SoapHeader();

le_sdl = zend_register_list_destructors_ex(delete_sdl_res, NULL, "SOAP SDL", module_number);
le_url = zend_register_list_destructors_ex(delete_url_res, NULL, "SOAP URL", module_number);
le_typemap = zend_register_list_destructors_ex(delete_hashtable_res, NULL, "SOAP table", module_number);

soap_url_class_entry = register_class_Soap_Url();
soap_url_class_entry->create_object = soap_url_object_create;
soap_url_class_entry->default_object_handlers = &soap_url_object_handlers;

memcpy(&soap_url_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
soap_url_object_handlers.offset = XtOffsetOf(soap_url_object, std);
soap_url_object_handlers.free_obj = soap_url_object_free;
soap_url_object_handlers.get_constructor = soap_url_object_get_constructor;
soap_url_object_handlers.clone_obj = NULL;
soap_url_object_handlers.compare = zend_objects_not_comparable;

register_soap_symbols(module_number);

old_error_handler = zend_error_cb;
Expand Down Expand Up @@ -4355,12 +4388,6 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */
}
/* }}} */

static void delete_url(void *handle) /* {{{ */
{
php_url_free((php_url*)handle);
}
/* }}} */

static void delete_service(void *data) /* {{{ */
{
soapServicePtr service = (soapServicePtr)data;
Expand Down
Loading

0 comments on commit 64d0fa5

Please sign in to comment.