Skip to content

ext/soap: setting xml namespace in classmap #12411

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

Closed
wants to merge 6 commits into from

Conversation

lxShaDoWxl
Copy link
Contributor

Added support setting namespace in classmap. For multiple namespace and not unique name type

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR.
I have some remarks for changes to the code that'll simplify this a bit and improve performance.

@lxShaDoWxl lxShaDoWxl force-pushed the feat/soap-classmap-ns branch from f116186 to 3bc3728 Compare October 12, 2023 03:30
@lxShaDoWxl
Copy link
Contributor Author

Thanks for your PR. I have some remarks for changes to the code that'll simplify this a bit and improve performance.

Thanks! 🙏

@nielsdos
Copy link
Member

Thanks for the changes, looks pretty good.

One thing I wonder about the classmap is this; if we have:
'classmap' => array('{http://schemas.nothing.com}book'=>'bookNs', 'book'=>'book')
then I expect a book in the namespace http://schemas.nothing.com to return an object of type bookNs. But now it returns an object of type book. That happens because to_zval_object_ex first looks up in SOAP_GLOBAL(class_map) without taking into account the namespace. Only when that returns NULL the namespace lookup happens. I think that's unintuitive and the checks probably should be reversed. What do you think?

@lxShaDoWxl
Copy link
Contributor Author

maybe change the order?

  1. search with namespace
  2. if null to search whout namespace
    the initial search order made sure that there was no unnecessary search in the old php code

@nielsdos
Copy link
Member

Perhaps changed order. I get that you want to avoid the additional lookup. Makes me think that the zend_string construction could be cached maybe too.
Anyway, let's maybe hear @dstogov 's opinion on this, because he developed the SOAP extension in the first place.

Comment on lines 1394 to 1398
classname = zend_hash_str_find_deref(SOAP_GLOBAL(class_map), type->type_str, strlen(type->type_str));
if(classname == NULL){
if (type->ns) {
zend_string *nscat =zend_strpprintf(0, "{%s}%s", type->ns, type->type_str);
classname = zend_hash_find_deref(SOAP_GLOBAL(class_map),nscat);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I think it's better to change the order (first search in namespace).
  • Usage of zend_strpprintf() on each lookup looks inefficient (additional memory allocation/deallocation). It would be great to find a better solution.

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this looks good.
I have only minor comments, and I don't see a simple decision to get rid from zend_strprintf(). So I wouldn't object about committing the patch in the current state.

@nielsdos please take care about finalizing and landing this.

@nielsdos
Copy link
Member

@lxShaDoWxl Let's change the check order.

Also, an idea to avoid constantly allocating temporary strings:

  • Add a field to _encodeType: zend_string *cached_clark_notation;. This will lazily cache the clark notation string.
  • If cached_clark_notation is non-NULL, don't create a temporary string, but use that string for lookup.
  • If it is NULL you need to make a temp string. When creating a temporary string, you can store it in cached_clark_notation if the sdl is non-persistent.
  • Make sure to zend_string_addref at the right locations to copy the string over
  • For the const encode defaultEncoding[] table you can set up the strings as persistent in module initialization, and deallocate them in module finalization.

If you're unsure how to do it, I can take it from here if you want :)

@lxShaDoWxl
Copy link
Contributor Author

@nielsdos please do it 🙏 I didn't understand everything myself how to do it😅

@nielsdos
Copy link
Member

Okay no worries, I'll have a look later this week to finish this.

@lxShaDoWxl
Copy link
Contributor Author

@nielsdos I did it a little differently, please take a look lxShaDoWxl@bbbb545

@nielsdos
Copy link
Member

@lxShaDoWxl that looks pretty good, thank you! I left some comments, after addressing those feel free to add it to this PR.
The only thing left is that the builtin convertors inside the defaultEncoding are not supported with the clark notation because their pointer stays NULL.
You can fix that by removing the const from the array, and filling in the zend_strings in the PHP_MINIT_FUNCTION(soap) in soap.c, and releasing them in the PHP_MSHUTDOWN_FUNCTION(soap) function in soap.c

@lxShaDoWxl
Copy link
Contributor Author

lxShaDoWxl commented Oct 20, 2023

@nielsdos I added the defaultEncoding initialization to php_soap_prepare_globals. Can't do zend_string_release in PHP_MSHUTDOWN_FUNCTION 😰
not work code

int i;
i = 0;
do {
    if(defaultEncoding[i].details.clark_notation){
        zend_string_release_ex(defaultEncoding[i].details.clark_notation, 1);
    }
    i++;
} while (defaultEncoding[i].details.type != END_KNOWN_TYPES);

@nielsdos
Copy link
Member

@lxShaDoWxl I've pushed the fix for your issue to your branch. The code you posted for MSHUTDOWN should now work.
The problem was that spprintf & zend_strpprintf allocate request strings, not persistent strings, a simply copy fixes it.

@lxShaDoWxl
Copy link
Contributor Author

@nielsdos Thanks! I added my code to PHP_MSHUTDOWN_FUNCTION

@nielsdos nielsdos closed this in e58af7c Oct 23, 2023
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged this manually as I had to rebase onto master, and I performed some small style tweaks and added a note to NEWS and UPGRADING.
Thank you very much for your contribution! Good work.
Merged as e58af7c

@dstogov
Copy link
Member

dstogov commented Oct 24, 2023

It seems some of the last soap patches broke something. See https://github.com/php/php-src/actions/runs/6621079042/job/17984591267

@nielsdos please take care

@nielsdos
Copy link
Member

Ok I will be able to check tonight.

@nielsdos
Copy link
Member

Fixed here: #12514

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants