PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/soap - soap.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 2006 2387 84.0 %
Date: 2015-05-30 Functions: 67 71 94.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2015 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Authors: Brad Lafountain <rodif_bl@yahoo.com>                        |
      16             :   |          Shane Caraveo <shane@caraveo.com>                           |
      17             :   |          Dmitry Stogov <dmitry@zend.com>                             |
      18             :   +----------------------------------------------------------------------+
      19             : */
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : #include "php_soap.h"
      26             : #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
      27             : #include "ext/session/php_session.h"
      28             : #endif
      29             : #include "zend_exceptions.h"
      30             : 
      31             : 
      32             : static int le_sdl = 0;
      33             : int le_url = 0;
      34             : static int le_service = 0;
      35             : static int le_typemap = 0;
      36             : 
      37             : typedef struct _soapHeader {
      38             :         sdlFunctionPtr                    function;
      39             :         zval                              function_name;
      40             :         int                               mustUnderstand;
      41             :         int                               num_params;
      42             :         zval                             *parameters;
      43             :         zval                              retval;
      44             :         sdlSoapBindingFunctionHeaderPtr   hdr;
      45             :         struct _soapHeader               *next;
      46             : } soapHeader;
      47             : 
      48             : /* Local functions */
      49             : static void function_to_string(sdlFunctionPtr function, smart_str *buf);
      50             : static void type_to_string(sdlTypePtr type, smart_str *buf, int level);
      51             : 
      52             : static void clear_soap_fault(zval *obj);
      53             : static void set_soap_fault(zval *obj, char *fault_code_ns, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, char *name);
      54             : static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail);
      55             : static void soap_server_fault(char* code, char* string, char *actor, zval* details, char *name);
      56             : static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeader* hdr);
      57             : 
      58             : static sdlParamPtr get_param(sdlFunctionPtr function, char *param_name, int index, int);
      59             : static sdlFunctionPtr get_function(sdlPtr sdl, const char *function_name);
      60             : static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr node);
      61             : 
      62             : static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, char* actor, zval *function_name, int *num_params, zval **parameters, int *version, soapHeader **headers);
      63             : static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function_name,char *uri,zval *ret, soapHeader *headers, int version);
      64             : static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function, char *function_name, char *uri, zval *arguments, int arg_count, int version, HashTable *soap_headers);
      65             : static xmlNodePtr serialize_parameter(sdlParamPtr param,zval *param_val,int index,char *name, int style, xmlNodePtr parent);
      66             : static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName, int style, xmlNodePtr parent);
      67             : 
      68             : static void delete_service(void *service);
      69             : static void delete_url(void *handle);
      70             : static void delete_hashtable(void *hashtable);
      71             : 
      72             : static void soap_error_handler(int error_num, const char *error_filename, const uint error_lineno, const char *format, va_list args);
      73             : 
      74             : #define SOAP_SERVER_BEGIN_CODE() \
      75             :         zend_bool _old_handler = SOAP_GLOBAL(use_soap_error_handler);\
      76             :         char* _old_error_code = SOAP_GLOBAL(error_code);\
      77             :         zend_object* _old_error_object = Z_OBJ(SOAP_GLOBAL(error_object));\
      78             :         int _old_soap_version = SOAP_GLOBAL(soap_version);\
      79             :         SOAP_GLOBAL(use_soap_error_handler) = 1;\
      80             :         SOAP_GLOBAL(error_code) = "Server";\
      81             :         Z_OBJ(SOAP_GLOBAL(error_object)) = Z_OBJ(EX(This));
      82             : 
      83             : #define SOAP_SERVER_END_CODE() \
      84             :         SOAP_GLOBAL(use_soap_error_handler) = _old_handler;\
      85             :         SOAP_GLOBAL(error_code) = _old_error_code;\
      86             :         Z_OBJ(SOAP_GLOBAL(error_object)) = _old_error_object;\
      87             :         SOAP_GLOBAL(soap_version) = _old_soap_version;
      88             : 
      89             : #define SOAP_CLIENT_BEGIN_CODE() \
      90             :         zend_bool _old_handler = SOAP_GLOBAL(use_soap_error_handler);\
      91             :         char* _old_error_code = SOAP_GLOBAL(error_code);\
      92             :         zend_object* _old_error_object = Z_OBJ(SOAP_GLOBAL(error_object));\
      93             :         int _old_soap_version = SOAP_GLOBAL(soap_version);\
      94             :         zend_bool _old_in_compilation = CG(in_compilation); \
      95             :         zend_execute_data *_old_current_execute_data = EG(current_execute_data); \
      96             :         zval *_old_stack_top = EG(vm_stack_top); \
      97             :         int _bailout = 0;\
      98             :         SOAP_GLOBAL(use_soap_error_handler) = 1;\
      99             :         SOAP_GLOBAL(error_code) = "Client";\
     100             :         Z_OBJ(SOAP_GLOBAL(error_object)) = Z_OBJ(EX(This));\
     101             :         zend_try {
     102             : 
     103             : #define SOAP_CLIENT_END_CODE() \
     104             :         } zend_catch {\
     105             :                 CG(in_compilation) = _old_in_compilation; \
     106             :                 EG(current_execute_data) = _old_current_execute_data; \
     107             :                 if (EG(exception) == NULL || \
     108             :                     !instanceof_function(EG(exception)->ce, soap_fault_class_entry)) {\
     109             :                         _bailout = 1;\
     110             :                 }\
     111             :                 if (_old_stack_top != EG(vm_stack_top)) { \
     112             :                         while (EG(vm_stack)->prev != NULL && \
     113             :                                ((char*)_old_stack_top < (char*)EG(vm_stack) || \
     114             :                                 (char*) _old_stack_top > (char*)EG(vm_stack)->end)) { \
     115             :                                 zend_vm_stack tmp = EG(vm_stack)->prev; \
     116             :                                 efree(EG(vm_stack)); \
     117             :                                 EG(vm_stack) = tmp; \
     118             :                                 EG(vm_stack_end) = tmp->end; \
     119             :                         } \
     120             :                         EG(vm_stack)->top = _old_stack_top; \
     121             :                 } \
     122             :         } zend_end_try();\
     123             :         SOAP_GLOBAL(use_soap_error_handler) = _old_handler;\
     124             :         SOAP_GLOBAL(error_code) = _old_error_code;\
     125             :         Z_OBJ(SOAP_GLOBAL(error_object)) = _old_error_object;\
     126             :         SOAP_GLOBAL(soap_version) = _old_soap_version;\
     127             :         if (_bailout) {\
     128             :                 zend_bailout();\
     129             :         }
     130             : 
     131             : #define FETCH_THIS_SDL(ss) \
     132             :         { \
     133             :                 zval *__tmp; \
     134             :                 if(FIND_SDL_PROPERTY(getThis(), __tmp) != NULL) { \
     135             :                         FETCH_SDL_RES(ss,__tmp); \
     136             :                 } else { \
     137             :                         ss = NULL; \
     138             :                 } \
     139             :         }
     140             : 
     141             : #define FIND_SDL_PROPERTY(ss,tmp) (tmp = zend_hash_str_find(Z_OBJPROP_P(ss), "sdl", sizeof("sdl")-1))
     142             : #define FETCH_SDL_RES(ss,tmp) ss = (sdlPtr) zend_fetch_resource_ex(tmp, "sdl", le_sdl)
     143             : 
     144             : #define FIND_TYPEMAP_PROPERTY(ss,tmp) (tmp = zend_hash_str_find(Z_OBJPROP_P(ss), "typemap", sizeof("typemap")-1))
     145             : #define FETCH_TYPEMAP_RES(ss,tmp) ss = (HashTable*) zend_fetch_resource_ex(tmp, "typemap", le_typemap)
     146             : 
     147             : #define FETCH_THIS_SERVICE(ss) \
     148             :         { \
     149             :                 zval *tmp; \
     150             :                 if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()),"service", sizeof("service")-1)) != NULL) { \
     151             :                         ss = (soapServicePtr)zend_fetch_resource_ex(tmp, "service", le_service); \
     152             :                 } else { \
     153             :                         php_error_docref(NULL, E_WARNING, "Can not fetch service object"); \
     154             :                         SOAP_SERVER_END_CODE(); \
     155             :                         return; \
     156             :                 } \
     157             :         }
     158             : 
     159             : static zend_class_entry* soap_class_entry;
     160             : static zend_class_entry* soap_server_class_entry;
     161             : static zend_class_entry* soap_fault_class_entry;
     162             : static zend_class_entry* soap_header_class_entry;
     163             : static zend_class_entry* soap_param_class_entry;
     164             : zend_class_entry* soap_var_class_entry;
     165             : 
     166             : ZEND_DECLARE_MODULE_GLOBALS(soap)
     167             : 
     168             : static void (*old_error_handler)(int, const char *, const uint, const char*, va_list);
     169             : 
     170             : #ifdef va_copy
     171             : #define call_old_error_handler(error_num, error_filename, error_lineno, format, args) \
     172             : { \
     173             :         va_list copy; \
     174             :         va_copy(copy, args); \
     175             :         old_error_handler(error_num, error_filename, error_lineno, format, copy); \
     176             :         va_end(copy); \
     177             : }
     178             : #else
     179             : #define call_old_error_handler(error_num, error_filename, error_lineno, format, args) \
     180             : { \
     181             :         old_error_handler(error_num, error_filename, error_lineno, format, args); \
     182             : }
     183             : #endif
     184             : 
     185             : #define PHP_SOAP_SERVER_CLASSNAME "SoapServer"
     186             : #define PHP_SOAP_CLIENT_CLASSNAME "SoapClient"
     187             : #define PHP_SOAP_VAR_CLASSNAME    "SoapVar"
     188             : #define PHP_SOAP_FAULT_CLASSNAME  "SoapFault"
     189             : #define PHP_SOAP_PARAM_CLASSNAME  "SoapParam"
     190             : #define PHP_SOAP_HEADER_CLASSNAME "SoapHeader"
     191             : 
     192             : PHP_RINIT_FUNCTION(soap);
     193             : PHP_MINIT_FUNCTION(soap);
     194             : PHP_MSHUTDOWN_FUNCTION(soap);
     195             : PHP_MINFO_FUNCTION(soap);
     196             : 
     197             : /*
     198             :   Registry Functions
     199             :   TODO: this!
     200             : */
     201             : PHP_FUNCTION(soap_encode_to_xml);
     202             : PHP_FUNCTION(soap_encode_to_zval);
     203             : PHP_FUNCTION(use_soap_error_handler);
     204             : PHP_FUNCTION(is_soap_fault);
     205             : 
     206             : 
     207             : /* Server Functions */
     208             : PHP_METHOD(SoapServer, SoapServer);
     209             : PHP_METHOD(SoapServer, setClass);
     210             : PHP_METHOD(SoapServer, setObject);
     211             : PHP_METHOD(SoapServer, addFunction);
     212             : PHP_METHOD(SoapServer, getFunctions);
     213             : PHP_METHOD(SoapServer, handle);
     214             : PHP_METHOD(SoapServer, setPersistence);
     215             : PHP_METHOD(SoapServer, fault);
     216             : PHP_METHOD(SoapServer, addSoapHeader);
     217             : 
     218             : /* Client Functions */
     219             : PHP_METHOD(SoapClient, SoapClient);
     220             : PHP_METHOD(SoapClient, __call);
     221             : PHP_METHOD(SoapClient, __getLastRequest);
     222             : PHP_METHOD(SoapClient, __getLastResponse);
     223             : PHP_METHOD(SoapClient, __getLastRequestHeaders);
     224             : PHP_METHOD(SoapClient, __getLastResponseHeaders);
     225             : PHP_METHOD(SoapClient, __getFunctions);
     226             : PHP_METHOD(SoapClient, __getTypes);
     227             : PHP_METHOD(SoapClient, __doRequest);
     228             : PHP_METHOD(SoapClient, __setCookie);
     229             : PHP_METHOD(SoapClient, __getCookies);
     230             : PHP_METHOD(SoapClient, __setLocation);
     231             : PHP_METHOD(SoapClient, __setSoapHeaders);
     232             : 
     233             : /* SoapVar Functions */
     234             : PHP_METHOD(SoapVar, SoapVar);
     235             : 
     236             : /* SoapFault Functions */
     237             : PHP_METHOD(SoapFault, SoapFault);
     238             : PHP_METHOD(SoapFault, __toString);
     239             : 
     240             : /* SoapParam Functions */
     241             : PHP_METHOD(SoapParam, SoapParam);
     242             : 
     243             : /* SoapHeader Functions */
     244             : PHP_METHOD(SoapHeader, SoapHeader);
     245             : 
     246             : #define SOAP_CTOR(class_name, func_name, arginfo, flags) PHP_ME(class_name, func_name, arginfo, flags)
     247             : 
     248             : /* {{{ arginfo */
     249             : ZEND_BEGIN_ARG_INFO(arginfo_soap__void, 0)
     250             : ZEND_END_ARG_INFO()
     251             : 
     252             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapparam_soapparam, 0, 0, 2)
     253             :         ZEND_ARG_INFO(0, data)
     254             :         ZEND_ARG_INFO(0, name)
     255             : ZEND_END_ARG_INFO()
     256             : 
     257             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapheader_soapheader, 0, 0, 2)
     258             :         ZEND_ARG_INFO(0, namespace)
     259             :         ZEND_ARG_INFO(0, name)
     260             :         ZEND_ARG_INFO(0, data)
     261             :         ZEND_ARG_INFO(0, mustunderstand)
     262             :         ZEND_ARG_INFO(0, actor)
     263             : ZEND_END_ARG_INFO()
     264             : 
     265             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapfault_soapfault, 0, 0, 2)
     266             :         ZEND_ARG_INFO(0, faultcode)
     267             :         ZEND_ARG_INFO(0, faultstring)
     268             :         ZEND_ARG_INFO(0, faultactor)
     269             :         ZEND_ARG_INFO(0, detail)
     270             :         ZEND_ARG_INFO(0, faultname)
     271             :         ZEND_ARG_INFO(0, headerfault)
     272             : ZEND_END_ARG_INFO()
     273             : 
     274             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapvar_soapvar, 0, 0, 2)
     275             :         ZEND_ARG_INFO(0, data)
     276             :         ZEND_ARG_INFO(0, encoding)
     277             :         ZEND_ARG_INFO(0, type_name)
     278             :         ZEND_ARG_INFO(0, type_namespace)
     279             :         ZEND_ARG_INFO(0, node_name)
     280             :         ZEND_ARG_INFO(0, node_namespace)
     281             : ZEND_END_ARG_INFO()
     282             : 
     283             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_fault, 0, 0, 2)
     284             :         ZEND_ARG_INFO(0, code)
     285             :         ZEND_ARG_INFO(0, string)
     286             :         ZEND_ARG_INFO(0, actor)
     287             :         ZEND_ARG_INFO(0, details)
     288             :         ZEND_ARG_INFO(0, name)
     289             : ZEND_END_ARG_INFO()
     290             : 
     291             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_addsoapheader, 0, 0, 1)
     292             :         ZEND_ARG_INFO(0, object)
     293             : ZEND_END_ARG_INFO()
     294             : 
     295             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_soapserver, 0, 0, 1)
     296             :         ZEND_ARG_INFO(0, wsdl)
     297             :         ZEND_ARG_INFO(0, options)
     298             : ZEND_END_ARG_INFO()
     299             : 
     300             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_setpersistence, 0, 0, 1)
     301             :         ZEND_ARG_INFO(0, mode)
     302             : ZEND_END_ARG_INFO()
     303             : 
     304             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_setclass, 0, 0, 1)
     305             :         ZEND_ARG_INFO(0, class_name)
     306             :         ZEND_ARG_INFO(0, args)
     307             : ZEND_END_ARG_INFO()
     308             : 
     309             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_setobject, 0, 0, 1)
     310             :         ZEND_ARG_INFO(0, object)
     311             : ZEND_END_ARG_INFO()
     312             : 
     313             : ZEND_BEGIN_ARG_INFO(arginfo_soapserver_getfunctions, 0)
     314             : ZEND_END_ARG_INFO()
     315             : 
     316             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_addfunction, 0, 0, 1)
     317             :         ZEND_ARG_INFO(0, functions)
     318             : ZEND_END_ARG_INFO()
     319             : 
     320             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_handle, 0, 0, 0)
     321             :         ZEND_ARG_INFO(0, soap_request)
     322             : ZEND_END_ARG_INFO()
     323             : 
     324             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient_soapclient, 0, 0, 1)
     325             :         ZEND_ARG_INFO(0, wsdl)
     326             :         ZEND_ARG_INFO(0, options)
     327             : ZEND_END_ARG_INFO()
     328             : 
     329             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___call, 0, 0, 2)
     330             :         ZEND_ARG_INFO(0, function_name)
     331             :         ZEND_ARG_INFO(0, arguments)
     332             : ZEND_END_ARG_INFO()
     333             : 
     334             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___soapcall, 0, 0, 2)
     335             :         ZEND_ARG_INFO(0, function_name)
     336             :         ZEND_ARG_INFO(0, arguments)
     337             :         ZEND_ARG_INFO(0, options)
     338             :         ZEND_ARG_INFO(0, input_headers)
     339             :         ZEND_ARG_INFO(1, output_headers)
     340             : ZEND_END_ARG_INFO()
     341             : 
     342             : ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getfunctions, 0)
     343             : ZEND_END_ARG_INFO()
     344             : 
     345             : ZEND_BEGIN_ARG_INFO(arginfo_soapclient___gettypes, 0)
     346             : ZEND_END_ARG_INFO()
     347             : 
     348             : ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getlastrequest, 0)
     349             : ZEND_END_ARG_INFO()
     350             : 
     351             : ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getlastresponse, 0)
     352             : ZEND_END_ARG_INFO()
     353             : 
     354             : ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getlastrequestheaders, 0)
     355             : ZEND_END_ARG_INFO()
     356             : 
     357             : ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getlastresponseheaders, 0)
     358             : ZEND_END_ARG_INFO()
     359             : 
     360             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___dorequest, 0, 0, 4)
     361             :         ZEND_ARG_INFO(0, request)
     362             :         ZEND_ARG_INFO(0, location)
     363             :         ZEND_ARG_INFO(0, action)
     364             :         ZEND_ARG_INFO(0, version)
     365             :         ZEND_ARG_INFO(0, one_way)
     366             : ZEND_END_ARG_INFO()
     367             : 
     368             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___setcookie, 0, 0, 1)
     369             :         ZEND_ARG_INFO(0, name)
     370             :         ZEND_ARG_INFO(0, value)
     371             : ZEND_END_ARG_INFO()
     372             : 
     373             : ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getcookies, 0)
     374             : ZEND_END_ARG_INFO()
     375             : 
     376             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___setsoapheaders, 0, 0, 1)
     377             :         ZEND_ARG_INFO(0, soapheaders)
     378             : ZEND_END_ARG_INFO()
     379             : 
     380             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___setlocation, 0, 0, 0)
     381             :         ZEND_ARG_INFO(0, new_location)
     382             : ZEND_END_ARG_INFO()
     383             : 
     384             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soap_use_soap_error_handler, 0, 0, 0)
     385             :         ZEND_ARG_INFO(0, handler)
     386             : ZEND_END_ARG_INFO()
     387             : 
     388             : ZEND_BEGIN_ARG_INFO_EX(arginfo_soap_is_soap_fault, 0, 0, 1)
     389             :         ZEND_ARG_INFO(0, object)
     390             : ZEND_END_ARG_INFO()
     391             : /* }}} */
     392             : 
     393             : static const zend_function_entry soap_functions[] = {
     394             :         PHP_FE(use_soap_error_handler,  arginfo_soap_use_soap_error_handler)
     395             :         PHP_FE(is_soap_fault,                   arginfo_soap_is_soap_fault)
     396             :         PHP_FE_END
     397             : };
     398             : 
     399             : static const zend_function_entry soap_fault_functions[] = {
     400             :         SOAP_CTOR(SoapFault, SoapFault, arginfo_soapfault_soapfault, 0)
     401             :         PHP_ME(SoapFault, __toString, arginfo_soap__void, 0)
     402             :         PHP_FE_END
     403             : };
     404             : 
     405             : static const zend_function_entry soap_server_functions[] = {
     406             :         SOAP_CTOR(SoapServer, SoapServer,       arginfo_soapserver_soapserver, 0)
     407             :         PHP_ME(SoapServer, setPersistence,      arginfo_soapserver_setpersistence, 0)
     408             :         PHP_ME(SoapServer, setClass,            arginfo_soapserver_setclass, 0)
     409             :         PHP_ME(SoapServer, setObject,           arginfo_soapserver_setobject, 0)
     410             :         PHP_ME(SoapServer, addFunction,         arginfo_soapserver_addfunction, 0)
     411             :         PHP_ME(SoapServer, getFunctions,        arginfo_soapserver_getfunctions, 0)
     412             :         PHP_ME(SoapServer, handle,                      arginfo_soapserver_handle, 0)
     413             :         PHP_ME(SoapServer, fault,                       arginfo_soapserver_fault, 0)
     414             :         PHP_ME(SoapServer, addSoapHeader,       arginfo_soapserver_addsoapheader, 0)
     415             :         PHP_FE_END
     416             : };
     417             : 
     418             : static const zend_function_entry soap_client_functions[] = {
     419             :         SOAP_CTOR(SoapClient, SoapClient, arginfo_soapclient_soapclient, 0)
     420             :         PHP_ME(SoapClient, __call,                                              arginfo_soapclient___call, 0)
     421             :         ZEND_NAMED_ME(__soapCall, ZEND_MN(SoapClient___call), arginfo_soapclient___soapcall, 0)
     422             :         PHP_ME(SoapClient, __getLastRequest,                    arginfo_soapclient___getlastrequest, 0)
     423             :         PHP_ME(SoapClient, __getLastResponse,                   arginfo_soapclient___getlastresponse, 0)
     424             :         PHP_ME(SoapClient, __getLastRequestHeaders,     arginfo_soapclient___getlastrequestheaders, 0)
     425             :         PHP_ME(SoapClient, __getLastResponseHeaders,    arginfo_soapclient___getlastresponseheaders, 0)
     426             :         PHP_ME(SoapClient, __getFunctions,                              arginfo_soapclient___getfunctions, 0)
     427             :         PHP_ME(SoapClient, __getTypes,                                  arginfo_soapclient___gettypes, 0)
     428             :         PHP_ME(SoapClient, __doRequest,                                 arginfo_soapclient___dorequest, 0)
     429             :         PHP_ME(SoapClient, __setCookie,                                 arginfo_soapclient___setcookie, 0)
     430             :         PHP_ME(SoapClient, __getCookies,                                arginfo_soapclient___getcookies, 0)
     431             :         PHP_ME(SoapClient, __setLocation,                               arginfo_soapclient___setlocation, 0)
     432             :         PHP_ME(SoapClient, __setSoapHeaders,                    arginfo_soapclient___setsoapheaders, 0)
     433             :         PHP_FE_END
     434             : };
     435             : 
     436             : static const zend_function_entry soap_var_functions[] = {
     437             :         SOAP_CTOR(SoapVar, SoapVar, arginfo_soapvar_soapvar, 0)
     438             :         PHP_FE_END
     439             : };
     440             : 
     441             : static const zend_function_entry soap_param_functions[] = {
     442             :         SOAP_CTOR(SoapParam, SoapParam, arginfo_soapparam_soapparam, 0)
     443             :         PHP_FE_END
     444             : };
     445             : 
     446             : static const zend_function_entry soap_header_functions[] = {
     447             :         SOAP_CTOR(SoapHeader, SoapHeader, arginfo_soapheader_soapheader, 0)
     448             :         PHP_FE_END
     449             : };
     450             : 
     451             : zend_module_entry soap_module_entry = {
     452             : #ifdef STANDARD_MODULE_HEADER
     453             :   STANDARD_MODULE_HEADER,
     454             : #endif
     455             :   "soap",
     456             :   soap_functions,
     457             :   PHP_MINIT(soap),
     458             :   PHP_MSHUTDOWN(soap),
     459             :   PHP_RINIT(soap),
     460             :   NULL,
     461             :   PHP_MINFO(soap),
     462             : #ifdef STANDARD_MODULE_HEADER
     463             :   PHP_SOAP_VERSION,
     464             : #endif
     465             :   STANDARD_MODULE_PROPERTIES,
     466             : };
     467             : 
     468             : #ifdef COMPILE_DL_SOAP
     469             : #ifdef ZTS
     470             : ZEND_TSRMLS_CACHE_DEFINE();
     471             : #endif
     472             : ZEND_GET_MODULE(soap)
     473             : #endif
     474             : 
     475       20952 : ZEND_INI_MH(OnUpdateCacheMode)
     476             : {
     477             :         char *p;
     478             : #ifndef ZTS
     479       20952 :         char *base = (char *) mh_arg2;
     480             : #else
     481             :         char *base = (char *) ts_resource(*((int *) mh_arg2));
     482             : #endif
     483             : 
     484       20952 :         p = (char*) (base+(size_t) mh_arg1);
     485             : 
     486       20952 :         *p = (char)atoi(new_value->val);
     487             : 
     488       20952 :         return SUCCESS;
     489             : }
     490             : 
     491       20952 : static PHP_INI_MH(OnUpdateCacheDir)
     492             : {
     493             :         /* Only do the open_basedir check at runtime */
     494       20952 :         if (stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) {
     495             :                 char *p;
     496             : 
     497           0 :                 if (memchr(new_value->val, '\0', new_value->len) != NULL) {
     498           0 :                         return FAILURE;
     499             :                 }
     500             : 
     501             :                 /* we do not use zend_memrchr() since path can contain ; itself */
     502           0 :                 if ((p = strchr(new_value->val, ';'))) {
     503             :                         char *p2;
     504           0 :                         p++;
     505           0 :                         if ((p2 = strchr(p, ';'))) {
     506           0 :                                 p = p2 + 1;
     507             :                         }
     508             :                 } else {
     509           0 :                         p = new_value->val;
     510             :                 }
     511             : 
     512           0 :                 if (PG(open_basedir) && *p && php_check_open_basedir(p)) {
     513           0 :                         return FAILURE;
     514             :                 }
     515             :         }
     516             : 
     517       20952 :         OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
     518       20952 :         return SUCCESS;
     519             : }
     520             : 
     521             : PHP_INI_BEGIN()
     522             : STD_PHP_INI_ENTRY("soap.wsdl_cache_enabled",     "1", PHP_INI_ALL, OnUpdateBool,
     523             :                   cache_enabled, zend_soap_globals, soap_globals)
     524             : STD_PHP_INI_ENTRY("soap.wsdl_cache_dir",         "/tmp", PHP_INI_ALL, OnUpdateCacheDir,
     525             :                   cache_dir, zend_soap_globals, soap_globals)
     526             : STD_PHP_INI_ENTRY("soap.wsdl_cache_ttl",         "86400", PHP_INI_ALL, OnUpdateLong,
     527             :                   cache_ttl, zend_soap_globals, soap_globals)
     528             : STD_PHP_INI_ENTRY("soap.wsdl_cache",             "1", PHP_INI_ALL, OnUpdateCacheMode,
     529             :                   cache_mode, zend_soap_globals, soap_globals)
     530             : STD_PHP_INI_ENTRY("soap.wsdl_cache_limit",       "5", PHP_INI_ALL, OnUpdateLong,
     531             :                   cache_limit, zend_soap_globals, soap_globals)
     532             : PHP_INI_END()
     533             : 
     534             : static HashTable defEnc, defEncIndex, defEncNs;
     535             : 
     536       20952 : static void php_soap_prepare_globals()
     537             : {
     538             :         int i;
     539             :         encodePtr enc;
     540             : 
     541       20952 :         zend_hash_init(&defEnc, 0, NULL, NULL, 1);
     542       20952 :         zend_hash_init(&defEncIndex, 0, NULL, NULL, 1);
     543       20952 :         zend_hash_init(&defEncNs, 0, NULL, NULL, 1);
     544             : //???   defEncNs.flags |= HASH_FLAG_BIG_DATA;
     545             : 
     546       20952 :         i = 0;
     547             :         do {
     548     1550448 :                 enc = &defaultEncoding[i];
     549             : 
     550             :                 /* If has a ns and a str_type then index it */
     551     1550448 :                 if (defaultEncoding[i].details.type_str) {
     552     1529496 :                         if (defaultEncoding[i].details.ns != NULL) {
     553             :                                 char *ns_type;
     554     1529496 :                                 spprintf(&ns_type, 0, "%s:%s", defaultEncoding[i].details.ns, defaultEncoding[i].details.type_str);
     555     1529496 :                                 zend_hash_str_add_ptr(&defEnc, ns_type, strlen(ns_type), enc);
     556     1529496 :                                 efree(ns_type);
     557             :                         } else {
     558           0 :                                 zend_hash_str_add_ptr(&defEnc, defaultEncoding[i].details.type_str, strlen(defaultEncoding[i].details.type_str), enc);
     559             :                         }
     560             :                 }
     561             :                 /* Index everything by number */
     562     1550448 :                 if (!zend_hash_index_exists(&defEncIndex, defaultEncoding[i].details.type)) {
     563     1278072 :                         zend_hash_index_update_ptr(&defEncIndex, defaultEncoding[i].details.type, enc);
     564             :                 }
     565     1550448 :                 i++;
     566     1550448 :         } while (defaultEncoding[i].details.type != END_KNOWN_TYPES);
     567             : 
     568             :         /* hash by namespace */
     569             :         zend_hash_str_add_ptr(&defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE)-1, XSD_NS_PREFIX);
     570             :         zend_hash_str_add_ptr(&defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1, XSD_NS_PREFIX);
     571             :         zend_hash_str_add_ptr(&defEncNs, XSI_NAMESPACE, sizeof(XSI_NAMESPACE)-1, XSI_NS_PREFIX);
     572             :         zend_hash_str_add_ptr(&defEncNs, XML_NAMESPACE, sizeof(XML_NAMESPACE)-1, XML_NS_PREFIX);
     573             :         zend_hash_str_add_ptr(&defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1, SOAP_1_1_ENC_NS_PREFIX);
     574             :         zend_hash_str_add_ptr(&defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1, SOAP_1_2_ENC_NS_PREFIX);
     575       20952 : }
     576             : 
     577       20952 : static void php_soap_init_globals(zend_soap_globals *soap_globals)
     578             : {
     579       20952 :         soap_globals->defEnc = defEnc;
     580       20952 :         soap_globals->defEncIndex = defEncIndex;
     581       20952 :         soap_globals->defEncNs = defEncNs;
     582       20952 :         soap_globals->typemap = NULL;
     583       20952 :         soap_globals->use_soap_error_handler = 0;
     584       20952 :         soap_globals->error_code = NULL;
     585       20952 :         ZVAL_OBJ(&soap_globals->error_object, NULL);
     586       20952 :         soap_globals->sdl = NULL;
     587       20952 :         soap_globals->soap_version = SOAP_1_1;
     588       20952 :         soap_globals->mem_cache = NULL;
     589       20952 :         soap_globals->ref_map = NULL;
     590       20952 : }
     591             : 
     592       20988 : PHP_MSHUTDOWN_FUNCTION(soap)
     593             : {
     594       20988 :         zend_error_cb = old_error_handler;
     595       20988 :         zend_hash_destroy(&SOAP_GLOBAL(defEnc));
     596       20988 :         zend_hash_destroy(&SOAP_GLOBAL(defEncIndex));
     597       20988 :         zend_hash_destroy(&SOAP_GLOBAL(defEncNs));
     598       20988 :         if (SOAP_GLOBAL(mem_cache)) {
     599           1 :                 zend_hash_destroy(SOAP_GLOBAL(mem_cache));
     600           1 :                 free(SOAP_GLOBAL(mem_cache));
     601             :         }
     602       20988 :         UNREGISTER_INI_ENTRIES();
     603       20988 :         return SUCCESS;
     604             : }
     605             : 
     606       20909 : PHP_RINIT_FUNCTION(soap)
     607             : {
     608             : #if defined(COMPILE_DL_SOAP) && defined(ZTS)
     609             :         ZEND_TSRMLS_CACHE_UPDATE();
     610             : #endif
     611       20909 :         SOAP_GLOBAL(typemap) = NULL;
     612       20909 :         SOAP_GLOBAL(use_soap_error_handler) = 0;
     613       20909 :         SOAP_GLOBAL(error_code) = NULL;
     614       20909 :         ZVAL_OBJ(&SOAP_GLOBAL(error_object), NULL);
     615       20909 :         SOAP_GLOBAL(sdl) = NULL;
     616       20909 :         SOAP_GLOBAL(soap_version) = SOAP_1_1;
     617       20909 :         SOAP_GLOBAL(encoding) = NULL;
     618       20909 :         SOAP_GLOBAL(class_map) = NULL;
     619       20909 :         SOAP_GLOBAL(features) = 0;
     620       20909 :         SOAP_GLOBAL(ref_map) = NULL;
     621       20909 :         return SUCCESS;
     622             : }
     623             : 
     624         305 : static void delete_sdl_res(zend_resource *res)
     625             : {
     626         305 :         delete_sdl(res->ptr);
     627         305 : }
     628             : 
     629           2 : static void delete_url_res(zend_resource *res)
     630             : {
     631           2 :         delete_url(res->ptr);
     632           2 : }
     633             : 
     634         458 : static void delete_service_res(zend_resource *res)
     635             : {
     636         458 :         delete_service(res->ptr);
     637         458 : }
     638             : 
     639           7 : static void delete_hashtable_res(zend_resource *res)
     640             : {
     641           7 :         delete_hashtable(res->ptr);
     642           7 : }
     643             : 
     644       20952 : PHP_MINIT_FUNCTION(soap)
     645             : {
     646             :         zend_class_entry ce;
     647             : 
     648             : #if defined(COMPILE_DL_SOAP) && defined(ZTS)
     649             :         ZEND_TSRMLS_CACHE_UPDATE();
     650             : #endif
     651             :         /* TODO: add ini entry for always use soap errors */
     652       20952 :         php_soap_prepare_globals();
     653       20952 :         ZEND_INIT_MODULE_GLOBALS(soap, php_soap_init_globals, NULL);
     654       20952 :         REGISTER_INI_ENTRIES();
     655             : 
     656             :         /* Register SoapClient class */
     657             :         /* BIG NOTE : THIS EMITS AN COMPILATION WARNING UNDER ZE2 - handle_function_call deprecated.
     658             :                 soap_call_function_handler should be of type struct _zend_function, not (*handle_function_call).
     659             :         */
     660             :         {
     661             :                 zend_internal_function fe;
     662             : 
     663       20952 :                 fe.type = ZEND_INTERNAL_FUNCTION;
     664       20952 :                 fe.handler = ZEND_MN(SoapClient___call);
     665       20952 :                 fe.function_name = NULL;
     666       20952 :                 fe.scope = NULL;
     667       20952 :                 fe.fn_flags = 0;
     668       20952 :                 fe.prototype = NULL;
     669       20952 :                 fe.num_args = 2;
     670       20952 :                 fe.arg_info = NULL;
     671       20952 :                 zend_set_function_arg_flags((zend_function*)&fe);
     672             : 
     673       20952 :                 INIT_OVERLOADED_CLASS_ENTRY(ce, PHP_SOAP_CLIENT_CLASSNAME, soap_client_functions,
     674             :                         (zend_function *)&fe, NULL, NULL);
     675       20952 :                 soap_class_entry = zend_register_internal_class(&ce);
     676             :         }
     677             :         /* Register SoapVar class */
     678       20952 :         INIT_CLASS_ENTRY(ce, PHP_SOAP_VAR_CLASSNAME, soap_var_functions);
     679       20952 :         soap_var_class_entry = zend_register_internal_class(&ce);
     680             : 
     681             :         /* Register SoapServer class */
     682       20952 :         INIT_CLASS_ENTRY(ce, PHP_SOAP_SERVER_CLASSNAME, soap_server_functions);
     683       20952 :         soap_server_class_entry = zend_register_internal_class(&ce);
     684             : 
     685             :         /* Register SoapFault class */
     686       20952 :         INIT_CLASS_ENTRY(ce, PHP_SOAP_FAULT_CLASSNAME, soap_fault_functions);
     687       20952 :         soap_fault_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default());
     688             : 
     689             :         /* Register SoapParam class */
     690       20952 :         INIT_CLASS_ENTRY(ce, PHP_SOAP_PARAM_CLASSNAME, soap_param_functions);
     691       20952 :         soap_param_class_entry = zend_register_internal_class(&ce);
     692             : 
     693       20952 :         INIT_CLASS_ENTRY(ce, PHP_SOAP_HEADER_CLASSNAME, soap_header_functions);
     694       20952 :         soap_header_class_entry = zend_register_internal_class(&ce);
     695             : 
     696       20952 :         le_sdl = zend_register_list_destructors_ex(delete_sdl_res, NULL, "SOAP SDL", module_number);
     697       20952 :         le_url = zend_register_list_destructors_ex(delete_url_res, NULL, "SOAP URL", module_number);
     698       20952 :         le_service = zend_register_list_destructors_ex(delete_service_res, NULL, "SOAP service", module_number);
     699       20952 :         le_typemap = zend_register_list_destructors_ex(delete_hashtable_res, NULL, "SOAP table", module_number);
     700             : 
     701       20952 :         REGISTER_LONG_CONSTANT("SOAP_1_1", SOAP_1_1, CONST_CS | CONST_PERSISTENT);
     702       20952 :         REGISTER_LONG_CONSTANT("SOAP_1_2", SOAP_1_2, CONST_CS | CONST_PERSISTENT);
     703             : 
     704       20952 :         REGISTER_LONG_CONSTANT("SOAP_PERSISTENCE_SESSION", SOAP_PERSISTENCE_SESSION, CONST_CS | CONST_PERSISTENT);
     705       20952 :         REGISTER_LONG_CONSTANT("SOAP_PERSISTENCE_REQUEST", SOAP_PERSISTENCE_REQUEST, CONST_CS | CONST_PERSISTENT);
     706       20952 :         REGISTER_LONG_CONSTANT("SOAP_FUNCTIONS_ALL", SOAP_FUNCTIONS_ALL, CONST_CS | CONST_PERSISTENT);
     707             : 
     708       20952 :         REGISTER_LONG_CONSTANT("SOAP_ENCODED", SOAP_ENCODED, CONST_CS | CONST_PERSISTENT);
     709       20952 :         REGISTER_LONG_CONSTANT("SOAP_LITERAL", SOAP_LITERAL, CONST_CS | CONST_PERSISTENT);
     710             : 
     711       20952 :         REGISTER_LONG_CONSTANT("SOAP_RPC", SOAP_RPC, CONST_CS | CONST_PERSISTENT);
     712       20952 :         REGISTER_LONG_CONSTANT("SOAP_DOCUMENT", SOAP_DOCUMENT, CONST_CS | CONST_PERSISTENT);
     713             : 
     714       20952 :         REGISTER_LONG_CONSTANT("SOAP_ACTOR_NEXT", SOAP_ACTOR_NEXT, CONST_CS | CONST_PERSISTENT);
     715       20952 :         REGISTER_LONG_CONSTANT("SOAP_ACTOR_NONE", SOAP_ACTOR_NONE, CONST_CS | CONST_PERSISTENT);
     716       20952 :         REGISTER_LONG_CONSTANT("SOAP_ACTOR_UNLIMATERECEIVER", SOAP_ACTOR_UNLIMATERECEIVER, CONST_CS | CONST_PERSISTENT);
     717             : 
     718       20952 :         REGISTER_LONG_CONSTANT("SOAP_COMPRESSION_ACCEPT", SOAP_COMPRESSION_ACCEPT, CONST_CS | CONST_PERSISTENT);
     719       20952 :         REGISTER_LONG_CONSTANT("SOAP_COMPRESSION_GZIP", SOAP_COMPRESSION_GZIP, CONST_CS | CONST_PERSISTENT);
     720       20952 :         REGISTER_LONG_CONSTANT("SOAP_COMPRESSION_DEFLATE", SOAP_COMPRESSION_DEFLATE, CONST_CS | CONST_PERSISTENT);
     721             : 
     722       20952 :         REGISTER_LONG_CONSTANT("SOAP_AUTHENTICATION_BASIC", SOAP_AUTHENTICATION_BASIC, CONST_CS | CONST_PERSISTENT);
     723       20952 :         REGISTER_LONG_CONSTANT("SOAP_AUTHENTICATION_DIGEST", SOAP_AUTHENTICATION_DIGEST, CONST_CS | CONST_PERSISTENT);
     724             : 
     725       20952 :         REGISTER_LONG_CONSTANT("UNKNOWN_TYPE", UNKNOWN_TYPE, CONST_CS | CONST_PERSISTENT);
     726             : 
     727       20952 :         REGISTER_LONG_CONSTANT("XSD_STRING", XSD_STRING, CONST_CS | CONST_PERSISTENT);
     728       20952 :         REGISTER_LONG_CONSTANT("XSD_BOOLEAN", XSD_BOOLEAN, CONST_CS | CONST_PERSISTENT);
     729       20952 :         REGISTER_LONG_CONSTANT("XSD_DECIMAL", XSD_DECIMAL, CONST_CS | CONST_PERSISTENT);
     730       20952 :         REGISTER_LONG_CONSTANT("XSD_FLOAT", XSD_FLOAT, CONST_CS | CONST_PERSISTENT);
     731       20952 :         REGISTER_LONG_CONSTANT("XSD_DOUBLE", XSD_DOUBLE, CONST_CS | CONST_PERSISTENT);
     732       20952 :         REGISTER_LONG_CONSTANT("XSD_DURATION", XSD_DURATION, CONST_CS | CONST_PERSISTENT);
     733       20952 :         REGISTER_LONG_CONSTANT("XSD_DATETIME", XSD_DATETIME, CONST_CS | CONST_PERSISTENT);
     734       20952 :         REGISTER_LONG_CONSTANT("XSD_TIME", XSD_TIME, CONST_CS | CONST_PERSISTENT);
     735       20952 :         REGISTER_LONG_CONSTANT("XSD_DATE", XSD_DATE, CONST_CS | CONST_PERSISTENT);
     736       20952 :         REGISTER_LONG_CONSTANT("XSD_GYEARMONTH", XSD_GYEARMONTH, CONST_CS | CONST_PERSISTENT);
     737       20952 :         REGISTER_LONG_CONSTANT("XSD_GYEAR", XSD_GYEAR, CONST_CS | CONST_PERSISTENT);
     738       20952 :         REGISTER_LONG_CONSTANT("XSD_GMONTHDAY", XSD_GMONTHDAY, CONST_CS | CONST_PERSISTENT);
     739       20952 :         REGISTER_LONG_CONSTANT("XSD_GDAY", XSD_GDAY, CONST_CS | CONST_PERSISTENT);
     740       20952 :         REGISTER_LONG_CONSTANT("XSD_GMONTH", XSD_GMONTH, CONST_CS | CONST_PERSISTENT);
     741       20952 :         REGISTER_LONG_CONSTANT("XSD_HEXBINARY", XSD_HEXBINARY, CONST_CS | CONST_PERSISTENT);
     742       20952 :         REGISTER_LONG_CONSTANT("XSD_BASE64BINARY", XSD_BASE64BINARY, CONST_CS | CONST_PERSISTENT);
     743       20952 :         REGISTER_LONG_CONSTANT("XSD_ANYURI", XSD_ANYURI, CONST_CS | CONST_PERSISTENT);
     744       20952 :         REGISTER_LONG_CONSTANT("XSD_QNAME", XSD_QNAME, CONST_CS | CONST_PERSISTENT);
     745       20952 :         REGISTER_LONG_CONSTANT("XSD_NOTATION", XSD_NOTATION, CONST_CS | CONST_PERSISTENT);
     746       20952 :         REGISTER_LONG_CONSTANT("XSD_NORMALIZEDSTRING", XSD_NORMALIZEDSTRING, CONST_CS | CONST_PERSISTENT);
     747       20952 :         REGISTER_LONG_CONSTANT("XSD_TOKEN", XSD_TOKEN, CONST_CS | CONST_PERSISTENT);
     748       20952 :         REGISTER_LONG_CONSTANT("XSD_LANGUAGE", XSD_LANGUAGE, CONST_CS | CONST_PERSISTENT);
     749       20952 :         REGISTER_LONG_CONSTANT("XSD_NMTOKEN", XSD_NMTOKEN, CONST_CS | CONST_PERSISTENT);
     750       20952 :         REGISTER_LONG_CONSTANT("XSD_NAME", XSD_NAME, CONST_CS | CONST_PERSISTENT);
     751       20952 :         REGISTER_LONG_CONSTANT("XSD_NCNAME", XSD_NCNAME, CONST_CS | CONST_PERSISTENT);
     752       20952 :         REGISTER_LONG_CONSTANT("XSD_ID", XSD_ID, CONST_CS | CONST_PERSISTENT);
     753       20952 :         REGISTER_LONG_CONSTANT("XSD_IDREF", XSD_IDREF, CONST_CS | CONST_PERSISTENT);
     754       20952 :         REGISTER_LONG_CONSTANT("XSD_IDREFS", XSD_IDREFS, CONST_CS | CONST_PERSISTENT);
     755       20952 :         REGISTER_LONG_CONSTANT("XSD_ENTITY", XSD_ENTITY, CONST_CS | CONST_PERSISTENT);
     756       20952 :         REGISTER_LONG_CONSTANT("XSD_ENTITIES", XSD_ENTITIES, CONST_CS | CONST_PERSISTENT);
     757       20952 :         REGISTER_LONG_CONSTANT("XSD_INTEGER", XSD_INTEGER, CONST_CS | CONST_PERSISTENT);
     758       20952 :         REGISTER_LONG_CONSTANT("XSD_NONPOSITIVEINTEGER", XSD_NONPOSITIVEINTEGER, CONST_CS | CONST_PERSISTENT);
     759       20952 :         REGISTER_LONG_CONSTANT("XSD_NEGATIVEINTEGER", XSD_NEGATIVEINTEGER, CONST_CS | CONST_PERSISTENT);
     760       20952 :         REGISTER_LONG_CONSTANT("XSD_LONG", XSD_LONG, CONST_CS | CONST_PERSISTENT);
     761       20952 :         REGISTER_LONG_CONSTANT("XSD_INT", XSD_INT, CONST_CS | CONST_PERSISTENT);
     762       20952 :         REGISTER_LONG_CONSTANT("XSD_SHORT", XSD_SHORT, CONST_CS | CONST_PERSISTENT);
     763       20952 :         REGISTER_LONG_CONSTANT("XSD_BYTE", XSD_BYTE, CONST_CS | CONST_PERSISTENT);
     764       20952 :         REGISTER_LONG_CONSTANT("XSD_NONNEGATIVEINTEGER", XSD_NONNEGATIVEINTEGER, CONST_CS | CONST_PERSISTENT);
     765       20952 :         REGISTER_LONG_CONSTANT("XSD_UNSIGNEDLONG", XSD_UNSIGNEDLONG, CONST_CS | CONST_PERSISTENT);
     766       20952 :         REGISTER_LONG_CONSTANT("XSD_UNSIGNEDINT", XSD_UNSIGNEDINT, CONST_CS | CONST_PERSISTENT);
     767       20952 :         REGISTER_LONG_CONSTANT("XSD_UNSIGNEDSHORT", XSD_UNSIGNEDSHORT, CONST_CS | CONST_PERSISTENT);
     768       20952 :         REGISTER_LONG_CONSTANT("XSD_UNSIGNEDBYTE", XSD_UNSIGNEDBYTE, CONST_CS | CONST_PERSISTENT);
     769       20952 :         REGISTER_LONG_CONSTANT("XSD_POSITIVEINTEGER", XSD_POSITIVEINTEGER, CONST_CS | CONST_PERSISTENT);
     770       20952 :         REGISTER_LONG_CONSTANT("XSD_NMTOKENS", XSD_NMTOKENS, CONST_CS | CONST_PERSISTENT);
     771       20952 :         REGISTER_LONG_CONSTANT("XSD_ANYTYPE", XSD_ANYTYPE, CONST_CS | CONST_PERSISTENT);
     772       20952 :         REGISTER_LONG_CONSTANT("XSD_ANYXML", XSD_ANYXML, CONST_CS | CONST_PERSISTENT);
     773             : 
     774       20952 :         REGISTER_LONG_CONSTANT("APACHE_MAP", APACHE_MAP, CONST_CS | CONST_PERSISTENT);
     775             : 
     776       20952 :         REGISTER_LONG_CONSTANT("SOAP_ENC_OBJECT", SOAP_ENC_OBJECT, CONST_CS | CONST_PERSISTENT);
     777       20952 :         REGISTER_LONG_CONSTANT("SOAP_ENC_ARRAY", SOAP_ENC_ARRAY, CONST_CS | CONST_PERSISTENT);
     778             : 
     779       20952 :         REGISTER_LONG_CONSTANT("XSD_1999_TIMEINSTANT", XSD_1999_TIMEINSTANT, CONST_CS | CONST_PERSISTENT);
     780             : 
     781       20952 :         REGISTER_STRING_CONSTANT("XSD_NAMESPACE", XSD_NAMESPACE, CONST_CS | CONST_PERSISTENT);
     782       20952 :         REGISTER_STRING_CONSTANT("XSD_1999_NAMESPACE", XSD_1999_NAMESPACE,  CONST_CS | CONST_PERSISTENT);
     783             : 
     784       20952 :         REGISTER_LONG_CONSTANT("SOAP_SINGLE_ELEMENT_ARRAYS", SOAP_SINGLE_ELEMENT_ARRAYS, CONST_CS | CONST_PERSISTENT);
     785       20952 :         REGISTER_LONG_CONSTANT("SOAP_WAIT_ONE_WAY_CALLS", SOAP_WAIT_ONE_WAY_CALLS, CONST_CS | CONST_PERSISTENT);
     786       20952 :         REGISTER_LONG_CONSTANT("SOAP_USE_XSI_ARRAY_TYPE", SOAP_USE_XSI_ARRAY_TYPE, CONST_CS | CONST_PERSISTENT);
     787             : 
     788       20952 :         REGISTER_LONG_CONSTANT("WSDL_CACHE_NONE",   WSDL_CACHE_NONE,   CONST_CS | CONST_PERSISTENT);
     789       20952 :         REGISTER_LONG_CONSTANT("WSDL_CACHE_DISK",   WSDL_CACHE_DISK,   CONST_CS | CONST_PERSISTENT);
     790       20952 :         REGISTER_LONG_CONSTANT("WSDL_CACHE_MEMORY", WSDL_CACHE_MEMORY, CONST_CS | CONST_PERSISTENT);
     791       20952 :         REGISTER_LONG_CONSTANT("WSDL_CACHE_BOTH",   WSDL_CACHE_BOTH,   CONST_CS | CONST_PERSISTENT);
     792             : 
     793             :         /* New SOAP SSL Method Constants */
     794       20952 :         REGISTER_LONG_CONSTANT("SOAP_SSL_METHOD_TLS",    SOAP_SSL_METHOD_TLS,    CONST_CS | CONST_PERSISTENT);
     795       20952 :         REGISTER_LONG_CONSTANT("SOAP_SSL_METHOD_SSLv2",  SOAP_SSL_METHOD_SSLv2,  CONST_CS | CONST_PERSISTENT);
     796       20952 :         REGISTER_LONG_CONSTANT("SOAP_SSL_METHOD_SSLv3",  SOAP_SSL_METHOD_SSLv3,  CONST_CS | CONST_PERSISTENT);
     797       20952 :         REGISTER_LONG_CONSTANT("SOAP_SSL_METHOD_SSLv23", SOAP_SSL_METHOD_SSLv23, CONST_CS | CONST_PERSISTENT);
     798             : 
     799       20952 :         old_error_handler = zend_error_cb;
     800       20952 :         zend_error_cb = soap_error_handler;
     801             : 
     802       20952 :         return SUCCESS;
     803             : }
     804             : 
     805         142 : PHP_MINFO_FUNCTION(soap)
     806             : {
     807         142 :         php_info_print_table_start();
     808         142 :         php_info_print_table_row(2, "Soap Client", "enabled");
     809         142 :         php_info_print_table_row(2, "Soap Server", "enabled");
     810         142 :         php_info_print_table_end();
     811         142 :         DISPLAY_INI_ENTRIES();
     812         142 : }
     813             : 
     814             : 
     815             : /* {{{ proto object SoapParam::SoapParam ( mixed data, string name)
     816             :    SoapParam constructor */
     817          30 : PHP_METHOD(SoapParam, SoapParam)
     818             : {
     819             :         zval *data;
     820             :         char *name;
     821             :         size_t name_length;
     822             :         zval *this_ptr;
     823             : 
     824          30 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &data, &name, &name_length) == FAILURE) {
     825           0 :                 return;
     826             :         }
     827          30 :         if (name_length == 0) {
     828           0 :                 php_error_docref(NULL, E_WARNING, "Invalid parameter name");
     829           0 :                 return;
     830             :         }
     831             : 
     832          30 :         this_ptr = getThis();
     833          30 :         add_property_stringl(this_ptr, "param_name", name, name_length);
     834          30 :         add_property_zval(this_ptr, "param_data", data);
     835             : }
     836             : /* }}} */
     837             : 
     838             : 
     839             : /* {{{ proto object SoapHeader::SoapHeader ( string namespace, string name [, mixed data [, bool mustUnderstand [, mixed actor]]])
     840             :    SoapHeader constructor */
     841          31 : PHP_METHOD(SoapHeader, SoapHeader)
     842             : {
     843          31 :         zval *data = NULL, *actor = NULL;
     844             :         char *name, *ns;
     845             :         size_t name_len, ns_len;
     846          31 :         zend_bool must_understand = 0;
     847             :         zval *this_ptr;
     848             : 
     849          31 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|zbz", &ns, &ns_len, &name, &name_len, &data, &must_understand, &actor) == FAILURE) {
     850           0 :                 return;
     851             :         }
     852          31 :         if (ns_len == 0) {
     853           1 :                 php_error_docref(NULL, E_WARNING, "Invalid namespace");
     854           1 :                 return;
     855             :         }
     856          30 :         if (name_len == 0) {
     857           0 :                 php_error_docref(NULL, E_WARNING, "Invalid header name");
     858           0 :                 return;
     859             :         }
     860             : 
     861          30 :         this_ptr = getThis();
     862          30 :         add_property_stringl(this_ptr, "namespace", ns, ns_len);
     863          30 :         add_property_stringl(this_ptr, "name", name, name_len);
     864          30 :         if (data) {
     865          26 :                 add_property_zval(this_ptr, "data", data);
     866             :         }
     867          30 :         add_property_bool(this_ptr, "mustUnderstand", must_understand);
     868          30 :         if (actor == NULL) {
     869           8 :         } else if (Z_TYPE_P(actor) == IS_LONG &&
     870           2 :           (Z_LVAL_P(actor) == SOAP_ACTOR_NEXT ||
     871           0 :            Z_LVAL_P(actor) == SOAP_ACTOR_NONE ||
     872           0 :            Z_LVAL_P(actor) == SOAP_ACTOR_UNLIMATERECEIVER)) {
     873           2 :                 add_property_long(this_ptr, "actor", Z_LVAL_P(actor));
     874           0 :         } else if (Z_TYPE_P(actor) == IS_STRING && Z_STRLEN_P(actor) > 0) {
     875           0 :                 add_property_stringl(this_ptr, "actor", Z_STRVAL_P(actor), Z_STRLEN_P(actor));
     876             :         } else {
     877           0 :                 php_error_docref(NULL, E_WARNING, "Invalid actor");
     878             :         }
     879             : }
     880             : 
     881             : /* {{{ proto object SoapFault::SoapFault ( string faultcode, string faultstring [, string faultactor [, mixed detail [, string faultname [, mixed headerfault]]]])
     882             :    SoapFault constructor */
     883          67 : PHP_METHOD(SoapFault, SoapFault)
     884             : {
     885          67 :         char *fault_string = NULL, *fault_code = NULL, *fault_actor = NULL, *name = NULL, *fault_code_ns = NULL;
     886          67 :         size_t fault_string_len, fault_actor_len = 0, name_len = 0, fault_code_len = 0;
     887          67 :         zval *code = NULL, *details = NULL, *headerfault = NULL, *this_ptr;
     888             : 
     889          67 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs|s!z!s!z",
     890             :                 &code,
     891             :                 &fault_string, &fault_string_len,
     892             :                 &fault_actor, &fault_actor_len,
     893             :                 &details, &name, &name_len, &headerfault) == FAILURE) {
     894           0 :                 return;
     895             :         }
     896             : 
     897         134 :         if (Z_TYPE_P(code) == IS_NULL) {
     898         134 :         } else if (Z_TYPE_P(code) == IS_STRING) {
     899          67 :                 fault_code = Z_STRVAL_P(code);
     900          67 :                 fault_code_len = Z_STRLEN_P(code);
     901           0 :         } else if (Z_TYPE_P(code) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(code)) == 2) {
     902             :                 zval *t_ns, *t_code;
     903             : 
     904           0 :                 zend_hash_internal_pointer_reset(Z_ARRVAL_P(code));
     905           0 :                 t_ns = zend_hash_get_current_data(Z_ARRVAL_P(code));
     906           0 :                 zend_hash_move_forward(Z_ARRVAL_P(code));
     907           0 :                 t_code = zend_hash_get_current_data(Z_ARRVAL_P(code));
     908           0 :                 if (Z_TYPE_P(t_ns) == IS_STRING && Z_TYPE_P(t_code) == IS_STRING) {
     909           0 :                   fault_code_ns = Z_STRVAL_P(t_ns);
     910           0 :                   fault_code = Z_STRVAL_P(t_code);
     911           0 :                   fault_code_len = Z_STRLEN_P(t_code);
     912             :                 } else {
     913           0 :                         php_error_docref(NULL, E_WARNING, "Invalid fault code");
     914           0 :                         return;
     915             :                 }
     916             :         } else  {
     917           0 :                 php_error_docref(NULL, E_WARNING, "Invalid fault code");
     918           0 :                 return;
     919             :         }
     920          67 :         if (fault_code != NULL && fault_code_len == 0) {
     921           0 :                 php_error_docref(NULL, E_WARNING, "Invalid fault code");
     922           0 :                 return;
     923             :         }
     924          67 :         if (name != NULL && name_len == 0) {
     925           0 :                 name = NULL;
     926             :         }
     927             : 
     928          67 :         this_ptr = getThis();
     929          67 :         set_soap_fault(this_ptr, fault_code_ns, fault_code, fault_string, fault_actor, details, name);
     930          67 :         if (headerfault != NULL) {
     931           1 :                 add_property_zval(this_ptr, "headerfault", headerfault);
     932             :         }
     933             : }
     934             : /* }}} */
     935             : 
     936             : 
     937             : /* {{{ proto object SoapFault::SoapFault ( string faultcode, string faultstring [, string faultactor [, mixed detail [, string faultname [, mixed headerfault]]]])
     938             :    SoapFault constructor */
     939           1 : PHP_METHOD(SoapFault, __toString)
     940             : {
     941             :         zval *faultcode, *faultstring, *file, *line, trace, rv1, rv2, rv3, rv4;
     942             :         zend_string *str;
     943             :         zend_fcall_info fci;
     944             :         zval *this_ptr;
     945             : 
     946           1 :         if (zend_parse_parameters_none() == FAILURE) {
     947           0 :                 return;
     948             :         }
     949             : 
     950           1 :         this_ptr = getThis();
     951           1 :         faultcode   = zend_read_property(soap_fault_class_entry, this_ptr, "faultcode", sizeof("faultcode")-1, 1, &rv1);
     952           1 :         faultstring = zend_read_property(soap_fault_class_entry, this_ptr, "faultstring", sizeof("faultstring")-1, 1, &rv2);
     953           1 :         file = zend_read_property(soap_fault_class_entry, this_ptr, "file", sizeof("file")-1, 1, &rv3);
     954           1 :         line = zend_read_property(soap_fault_class_entry, this_ptr, "line", sizeof("line")-1, 1, &rv4);
     955             : 
     956           1 :         fci.size = sizeof(fci);
     957           1 :         fci.function_table = &Z_OBJCE_P(getThis())->function_table;
     958           2 :         ZVAL_STRINGL(&fci.function_name, "gettraceasstring", sizeof("gettraceasstring")-1);
     959           1 :         fci.symbol_table = NULL;
     960           1 :         fci.object = Z_OBJ(EX(This));
     961           1 :         fci.retval = &trace;
     962           1 :         fci.param_count = 0;
     963           1 :         fci.params = NULL;
     964           1 :         fci.no_separation = 1;
     965             : 
     966           1 :         zend_call_function(&fci, NULL);
     967             : 
     968           1 :         zval_ptr_dtor(&fci.function_name);
     969             : 
     970           1 :         convert_to_string(faultcode);
     971           1 :         convert_to_string(faultstring);
     972           1 :         convert_to_string(file);
     973           1 :         convert_to_long(line);
     974           1 :         convert_to_string(&trace);
     975             : 
     976           5 :         str = strpprintf(0, "SoapFault exception: [%s] %s in %s:%pd\nStack trace:\n%s",
     977           3 :                        Z_STRVAL_P(faultcode), Z_STRVAL_P(faultstring), Z_STRVAL_P(file), Z_LVAL_P(line),
     978           2 :                        Z_STRLEN(trace) ? Z_STRVAL(trace) : "#0 {main}\n");
     979             : 
     980           1 :         zval_ptr_dtor(&trace);
     981             : 
     982           1 :         RETVAL_STR(str);
     983             : }
     984             : /* }}} */
     985             : 
     986             : /* {{{ proto object SoapVar::SoapVar ( mixed data, int encoding [, string type_name [, string type_namespace [, string node_name [, string node_namespace]]]])
     987             :    SoapVar constructor */
     988         105 : PHP_METHOD(SoapVar, SoapVar)
     989             : {
     990             :         zval *data, *type, *this_ptr;
     991         105 :         char *stype = NULL, *ns = NULL, *name = NULL, *namens = NULL;
     992         105 :         size_t stype_len = 0, ns_len = 0, name_len = 0, namens_len = 0;
     993             : 
     994         105 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z!z|ssss", &data, &type, &stype, &stype_len, &ns, &ns_len, &name, &name_len, &namens, &namens_len) == FAILURE) {
     995           0 :                 return;
     996             :         }
     997             : 
     998         105 :         this_ptr = getThis();
     999         210 :         if (Z_TYPE_P(type) == IS_NULL) {
    1000           2 :                 add_property_long(this_ptr, "enc_type", UNKNOWN_TYPE);
    1001             :         } else {
    1002         103 :                 if (zend_hash_index_exists(&SOAP_GLOBAL(defEncIndex), Z_LVAL_P(type))) {
    1003         103 :                         add_property_long(this_ptr, "enc_type", Z_LVAL_P(type));
    1004             :                 } else {
    1005           0 :                         php_error_docref(NULL, E_WARNING, "Invalid type ID");
    1006           0 :                         return;
    1007             :                 }
    1008             :         }
    1009             : 
    1010         105 :         if (data) {
    1011         103 :                 add_property_zval(this_ptr, "enc_value", data);
    1012             :         }
    1013             : 
    1014         105 :         if (stype && stype_len > 0) {
    1015          21 :                 add_property_stringl(this_ptr, "enc_stype", stype, stype_len);
    1016             :         }
    1017         105 :         if (ns && ns_len > 0) {
    1018          21 :                 add_property_stringl(this_ptr, "enc_ns", ns, ns_len);
    1019             :         }
    1020         105 :         if (name && name_len > 0) {
    1021          25 :                 add_property_stringl(this_ptr, "enc_name", name, name_len);
    1022             :         }
    1023         105 :         if (namens && namens_len > 0) {
    1024           2 :                 add_property_stringl(this_ptr, "enc_namens", namens, namens_len);
    1025             :         }
    1026             : }
    1027             : /* }}} */
    1028             : 
    1029          15 : static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht)
    1030             : {
    1031             :         zval *tmp;
    1032             :         HashTable *ht2;
    1033          15 :         HashTable *typemap = NULL;
    1034             : 
    1035          45 :         ZEND_HASH_FOREACH_VAL(ht, tmp) {
    1036          15 :                 char *type_name = NULL;
    1037          15 :                 char *type_ns = NULL;
    1038          15 :                 zval *to_xml = NULL;
    1039          15 :                 zval *to_zval = NULL;
    1040             :                 encodePtr enc, new_enc;
    1041             :                 zend_string *name;
    1042             : 
    1043          15 :                 if (Z_TYPE_P(tmp) != IS_ARRAY) {
    1044           0 :                         php_error_docref(NULL, E_WARNING, "Wrong 'typemap' option");
    1045           0 :                         return NULL;
    1046             :                 }
    1047          15 :                 ht2 = Z_ARRVAL_P(tmp);
    1048             : 
    1049         101 :                 ZEND_HASH_FOREACH_STR_KEY_VAL(ht2, name, tmp) {
    1050          43 :                         if (name) {
    1051          73 :                                 if (name->len == sizeof("type_name")-1 &&
    1052          15 :                                     strncmp(name->val, "type_name", sizeof("type_name")-1) == 0) {
    1053          15 :                                         if (Z_TYPE_P(tmp) == IS_STRING) {
    1054          15 :                                                 type_name = Z_STRVAL_P(tmp);
    1055             :                                         } else if (Z_TYPE_P(tmp) != IS_NULL) {
    1056             :                                         }
    1057          58 :                                 } else if (name->len == sizeof("type_ns")-1 &&
    1058          15 :                                     strncmp(name->val, "type_ns", sizeof("type_ns")-1) == 0) {
    1059          15 :                                         if (Z_TYPE_P(tmp) == IS_STRING) {
    1060          15 :                                                 type_ns = Z_STRVAL_P(tmp);
    1061             :                                         } else if (Z_TYPE_P(tmp) != IS_NULL) {
    1062             :                                         }
    1063          27 :                                 } else if (name->len == sizeof("to_xml")-1 &&
    1064           7 :                                     strncmp(name->val, "to_xml", sizeof("to_xml")-1) == 0) {
    1065           7 :                                         to_xml = tmp;
    1066          12 :                                 } else if (name->len == sizeof("from_xml")-1 &&
    1067           6 :                                     strncmp(name->val, "from_xml", sizeof("from_xml")-1) == 0) {
    1068           6 :                                         to_zval = tmp;
    1069             :                                 }
    1070             :                         }
    1071             :                 } ZEND_HASH_FOREACH_END();
    1072             : 
    1073          15 :                 if (type_name) {
    1074          15 :                         smart_str nscat = {0};
    1075             : 
    1076          15 :                         if (type_ns) {
    1077          15 :                                 enc = get_encoder(sdl, type_ns, type_name);
    1078             :                         } else {
    1079           0 :                                 enc = get_encoder_ex(sdl, type_name, strlen(type_name));
    1080             :                         }
    1081             : 
    1082          15 :                         new_enc = emalloc(sizeof(encode));
    1083          15 :                         memset(new_enc, 0, sizeof(encode));
    1084             : 
    1085          15 :                         if (enc) {
    1086           9 :                                 new_enc->details.type = enc->details.type;
    1087           9 :                                 new_enc->details.ns = estrdup(enc->details.ns);
    1088           9 :                                 new_enc->details.type_str = estrdup(enc->details.type_str);
    1089           9 :                                 new_enc->details.sdl_type = enc->details.sdl_type;
    1090             :                         } else {
    1091           6 :                                 enc = get_conversion(UNKNOWN_TYPE);
    1092           6 :                                 new_enc->details.type = enc->details.type;
    1093           6 :                                 if (type_ns) {
    1094           6 :                                         new_enc->details.ns = estrdup(type_ns);
    1095             :                                 }
    1096           6 :                                 new_enc->details.type_str = estrdup(type_name);
    1097             :                         }
    1098          15 :                         new_enc->to_xml = enc->to_xml;
    1099          15 :                         new_enc->to_zval = enc->to_zval;
    1100          15 :                         new_enc->details.map = emalloc(sizeof(soapMapping));
    1101          15 :                         memset(new_enc->details.map, 0, sizeof(soapMapping));
    1102          15 :                         if (to_xml) {
    1103           7 :                                 ZVAL_COPY(&new_enc->details.map->to_xml, to_xml);
    1104           7 :                                 new_enc->to_xml = to_xml_user;
    1105           8 :                         } else if (enc->details.map && Z_TYPE(enc->details.map->to_xml) != IS_UNDEF) {
    1106           0 :                                 ZVAL_COPY(&new_enc->details.map->to_xml, &enc->details.map->to_xml);
    1107             :                         }
    1108          15 :                         if (to_zval) {
    1109           6 :                                 ZVAL_COPY(&new_enc->details.map->to_zval, to_zval);
    1110           6 :                                 new_enc->to_zval = to_zval_user;
    1111           9 :                         } else if (enc->details.map && Z_TYPE(enc->details.map->to_zval) != IS_UNDEF) {
    1112           0 :                                 ZVAL_COPY(&new_enc->details.map->to_zval, &enc->details.map->to_zval);
    1113             :                         }
    1114          15 :                         if (!typemap) {
    1115          15 :                                 typemap = emalloc(sizeof(HashTable));
    1116          15 :                                 zend_hash_init(typemap, 0, NULL, delete_encoder, 0);
    1117             :                         }
    1118             : 
    1119          15 :                         if (type_ns) {
    1120          15 :                                 smart_str_appends(&nscat, type_ns);
    1121             :                                 smart_str_appendc(&nscat, ':');
    1122             :                         }
    1123          15 :                         smart_str_appends(&nscat, type_name);
    1124             :                         smart_str_0(&nscat);
    1125          15 :                         zend_hash_update_ptr(typemap, nscat.s, new_enc);
    1126             :                         smart_str_free(&nscat);
    1127             :                 }
    1128             :         } ZEND_HASH_FOREACH_END();
    1129          15 :         return typemap;
    1130             : }
    1131             : 
    1132             : 
    1133             : /* {{{ proto object SoapServer::SoapServer ( mixed wsdl [, array options])
    1134             :    SoapServer constructor */
    1135         458 : PHP_METHOD(SoapServer, SoapServer)
    1136             : {
    1137             :         soapServicePtr service;
    1138         458 :         zval *wsdl = NULL, *options = NULL;
    1139             :         zend_resource *res;
    1140         458 :         int version = SOAP_1_1;
    1141             :         zend_long cache_wsdl;
    1142         458 :         HashTable *typemap_ht = NULL;
    1143             : 
    1144         458 :         SOAP_SERVER_BEGIN_CODE();
    1145             : 
    1146         458 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z|a", &wsdl, &options) == FAILURE) {
    1147           0 :                 php_error_docref(NULL, E_ERROR, "Invalid parameters");
    1148             :         }
    1149             : 
    1150         964 :         if (Z_TYPE_P(wsdl) != IS_STRING && Z_TYPE_P(wsdl) != IS_NULL) {
    1151           0 :                 php_error_docref(NULL, E_ERROR, "Invalid parameters");
    1152             :         }
    1153             : 
    1154         458 :         service = emalloc(sizeof(soapService));
    1155         458 :         memset(service, 0, sizeof(soapService));
    1156         458 :         service->send_errors = 1;
    1157             : 
    1158         458 :         cache_wsdl = SOAP_GLOBAL(cache_enabled) ? SOAP_GLOBAL(cache_mode) : 0;
    1159             : 
    1160         458 :         if (options != NULL) {
    1161         235 :                 HashTable *ht = Z_ARRVAL_P(options);
    1162             :                 zval *tmp;
    1163             : 
    1164         235 :                 if ((tmp = zend_hash_str_find(ht, "soap_version", sizeof("soap_version")-1)) != NULL) {
    1165         300 :                         if (Z_TYPE_P(tmp) == IS_LONG &&
    1166         150 :                             (Z_LVAL_P(tmp) == SOAP_1_1 || Z_LVAL_P(tmp) == SOAP_1_2)) {
    1167          75 :                                 version = Z_LVAL_P(tmp);
    1168             :                         } else {
    1169           0 :                                 php_error_docref(NULL, E_ERROR, "'soap_version' option must be SOAP_1_1 or SOAP_1_2");
    1170             :                         }
    1171             :                 }
    1172             : 
    1173         331 :                 if ((tmp = zend_hash_str_find(ht, "uri", sizeof("uri")-1)) != NULL &&
    1174             :                     Z_TYPE_P(tmp) == IS_STRING) {
    1175          48 :                         service->uri = estrndup(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
    1176         374 :                 } else if (Z_TYPE_P(wsdl) == IS_NULL) {
    1177           0 :                         php_error_docref(NULL, E_ERROR, "'uri' option is required in nonWSDL mode");
    1178             :                 }
    1179             : 
    1180         316 :                 if ((tmp = zend_hash_str_find(ht, "actor", sizeof("actor")-1)) != NULL &&
    1181             :                     Z_TYPE_P(tmp) == IS_STRING) {
    1182          81 :                         service->actor = estrndup(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
    1183             :                 }
    1184             : 
    1185         239 :                 if ((tmp = zend_hash_str_find(ht, "encoding", sizeof("encoding")-1)) != NULL &&
    1186             :                     Z_TYPE_P(tmp) == IS_STRING) {
    1187             :                         xmlCharEncodingHandlerPtr encoding;
    1188             : 
    1189           4 :                         encoding = xmlFindCharEncodingHandler(Z_STRVAL_P(tmp));
    1190           4 :                         if (encoding == NULL) {
    1191           0 :                                 php_error_docref(NULL, E_ERROR, "Invalid 'encoding' option - '%s'", Z_STRVAL_P(tmp));
    1192             :                         } else {
    1193           4 :                           service->encoding = encoding;
    1194             :                         }
    1195             :                 }
    1196             : 
    1197         246 :                 if ((tmp = zend_hash_str_find(ht, "classmap", sizeof("classmap")-1)) != NULL &&
    1198             :                         Z_TYPE_P(tmp) == IS_ARRAY) {
    1199          11 :                         service->class_map = zend_array_dup(Z_ARRVAL_P(tmp));
    1200             :                 }
    1201             : 
    1202         251 :                 if ((tmp = zend_hash_str_find(ht, "typemap", sizeof("typemap")-1)) != NULL &&
    1203             :                         Z_TYPE_P(tmp) == IS_ARRAY &&
    1204           8 :                         zend_hash_num_elements(Z_ARRVAL_P(tmp)) > 0) {
    1205           8 :                         typemap_ht = Z_ARRVAL_P(tmp);
    1206             :                 }
    1207             : 
    1208         323 :                 if ((tmp = zend_hash_str_find(ht, "features", sizeof("features")-1)) != NULL &&
    1209             :                         Z_TYPE_P(tmp) == IS_LONG) {
    1210          88 :                         service->features = Z_LVAL_P(tmp);
    1211             :                 }
    1212             : 
    1213         236 :                 if ((tmp = zend_hash_str_find(ht, "cache_wsdl", sizeof("cache_wsdl")-1)) != NULL &&
    1214             :                     Z_TYPE_P(tmp) == IS_LONG) {
    1215           1 :                         cache_wsdl = Z_LVAL_P(tmp);
    1216             :                 }
    1217             : 
    1218         235 :                 if ((tmp = zend_hash_str_find(ht, "send_errors", sizeof("send_errors")-1)) != NULL) {
    1219           1 :                         if (Z_TYPE_P(tmp) == IS_FALSE) {
    1220           0 :                                 service->send_errors = 0;
    1221           1 :                         } else if (Z_TYPE_P(tmp) == IS_TRUE) {
    1222           0 :                                 service->send_errors = 1;
    1223           1 :                         } else if (Z_TYPE_P(tmp) == IS_LONG) {
    1224           1 :                                 service->send_errors = Z_LVAL_P(tmp);
    1225             :                         }
    1226             :                 }
    1227             : 
    1228         446 :         } else if (Z_TYPE_P(wsdl) == IS_NULL) {
    1229           0 :                 php_error_docref(NULL, E_ERROR, "'uri' option is required in nonWSDL mode");
    1230             :         }
    1231             : 
    1232         458 :         service->version = version;
    1233         458 :         service->type = SOAP_FUNCTIONS;
    1234         458 :         service->soap_functions.functions_all = FALSE;
    1235         458 :         service->soap_functions.ft = emalloc(sizeof(HashTable));
    1236         458 :         zend_hash_init(service->soap_functions.ft, 0, NULL, ZVAL_PTR_DTOR, 0);
    1237             : 
    1238         916 :         if (Z_TYPE_P(wsdl) != IS_NULL) {
    1239         410 :                 service->sdl = get_sdl(getThis(), Z_STRVAL_P(wsdl), cache_wsdl);
    1240         410 :                 if (service->uri == NULL) {
    1241         410 :                         if (service->sdl->target_ns) {
    1242         410 :                                 service->uri = estrdup(service->sdl->target_ns);
    1243             :                         } else {
    1244             :                                 /*FIXME*/
    1245           0 :                                 service->uri = estrdup("http://unknown-uri/");
    1246             :                         }
    1247             :                 }
    1248             :         }
    1249             : 
    1250         458 :         if (typemap_ht) {
    1251           8 :                 service->typemap = soap_create_typemap(service->sdl, typemap_ht);
    1252             :         }
    1253             : 
    1254         458 :         res = zend_register_resource(service, le_service);
    1255         458 :         add_property_resource(getThis(), "service", res);
    1256             : 
    1257         458 :         SOAP_SERVER_END_CODE();
    1258         458 : }
    1259             : /* }}} */
    1260             : 
    1261             : 
    1262             : /* {{{ proto object SoapServer::setPersistence ( int mode )
    1263             :    Sets persistence mode of SoapServer */
    1264           2 : PHP_METHOD(SoapServer, setPersistence)
    1265             : {
    1266             :         soapServicePtr service;
    1267             :         zend_long value;
    1268             : 
    1269           2 :         SOAP_SERVER_BEGIN_CODE();
    1270             : 
    1271           2 :         FETCH_THIS_SERVICE(service);
    1272             : 
    1273           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &value) != FAILURE) {
    1274           2 :                 if (service->type == SOAP_CLASS) {
    1275           5 :                         if (value == SOAP_PERSISTENCE_SESSION ||
    1276           1 :                                 value == SOAP_PERSISTENCE_REQUEST) {
    1277           2 :                                 service->soap_class.persistence = value;
    1278             :                         } else {
    1279           0 :                                 php_error_docref(NULL, E_WARNING, "Tried to set persistence with bogus value (%pd)", value);
    1280           0 :                                 return;
    1281             :                         }
    1282             :                 } else {
    1283           0 :                         php_error_docref(NULL, E_WARNING, "Tried to set persistence when you are using you SOAP SERVER in function mode, no persistence needed");
    1284           0 :                         return;
    1285             :                 }
    1286             :         }
    1287             : 
    1288           2 :         SOAP_SERVER_END_CODE();
    1289             : }
    1290             : /* }}} */
    1291             : 
    1292             : 
    1293             : /* {{{ proto void SoapServer::setClass(string class_name [, mixed args])
    1294             :    Sets class which will handle SOAP requests */
    1295         310 : PHP_METHOD(SoapServer, setClass)
    1296             : {
    1297             :         soapServicePtr service;
    1298             :         zend_string *classname;
    1299             :         zend_class_entry *ce;
    1300         310 :         int num_args = 0;
    1301         310 :         zval *argv = NULL;
    1302             : 
    1303         310 :         SOAP_SERVER_BEGIN_CODE();
    1304             : 
    1305         310 :         FETCH_THIS_SERVICE(service);
    1306             : 
    1307         310 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S*", &classname, &argv, &num_args) == FAILURE) {
    1308           0 :                 return;
    1309             :         }
    1310             : 
    1311         310 :         ce = zend_lookup_class(classname);
    1312             : 
    1313         310 :         if (ce) {
    1314         310 :                 service->type = SOAP_CLASS;
    1315         310 :                 service->soap_class.ce = ce;
    1316             : 
    1317         310 :                 service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
    1318         310 :                 service->soap_class.argc = num_args;
    1319         310 :                 if (service->soap_class.argc > 0) {
    1320             :                         int i;
    1321           1 :                         service->soap_class.argv = safe_emalloc(sizeof(zval), service->soap_class.argc, 0);
    1322           2 :                         for (i = 0;i < service->soap_class.argc;i++) {
    1323           1 :                                 ZVAL_COPY(&service->soap_class.argv[i], &argv[i]);
    1324             :                         }
    1325             :                 }
    1326             :         } else {
    1327           0 :                 php_error_docref(NULL, E_WARNING, "Tried to set a non existent class (%s)", classname->val);
    1328           0 :                 return;
    1329             :         }
    1330             : 
    1331         310 :         SOAP_SERVER_END_CODE();
    1332             : }
    1333             : /* }}} */
    1334             : 
    1335             : 
    1336             : /* {{{ proto void SoapServer::setObject(object)
    1337             :    Sets object which will handle SOAP requests */
    1338           4 : PHP_METHOD(SoapServer, setObject)
    1339             : {
    1340             :         soapServicePtr service;
    1341             :         zval *obj;
    1342             : 
    1343           4 :         SOAP_SERVER_BEGIN_CODE();
    1344             : 
    1345           4 :         FETCH_THIS_SERVICE(service);
    1346             : 
    1347           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) {
    1348           0 :                 return;
    1349             :         }
    1350             : 
    1351           4 :         service->type = SOAP_OBJECT;
    1352             : 
    1353           4 :         ZVAL_COPY(&service->soap_object, obj);
    1354             : 
    1355           4 :         SOAP_SERVER_END_CODE();
    1356             : }
    1357             : /* }}} */
    1358             : 
    1359             : 
    1360             : /* {{{ proto array SoapServer::getFunctions(void)
    1361             :    Returns list of defined functions */
    1362           4 : PHP_METHOD(SoapServer, getFunctions)
    1363             : {
    1364             :         soapServicePtr  service;
    1365           4 :         HashTable      *ft = NULL;
    1366             : 
    1367           4 :         SOAP_SERVER_BEGIN_CODE();
    1368             : 
    1369           4 :         if (zend_parse_parameters_none() == FAILURE) {
    1370           0 :                 return;
    1371             :         }
    1372             : 
    1373           4 :         FETCH_THIS_SERVICE(service);
    1374             : 
    1375           4 :         array_init(return_value);
    1376           4 :         if (service->type == SOAP_OBJECT) {
    1377           1 :                 ft = &(Z_OBJCE(service->soap_object)->function_table);
    1378           3 :         } else if (service->type == SOAP_CLASS) {
    1379           2 :                 ft = &service->soap_class.ce->function_table;
    1380           1 :         } else if (service->soap_functions.functions_all == TRUE) {
    1381           0 :                 ft = EG(function_table);
    1382           1 :         } else if (service->soap_functions.ft != NULL) {
    1383             :                 zval *name;
    1384             : 
    1385           5 :                 ZEND_HASH_FOREACH_VAL(service->soap_functions.ft, name) {
    1386           4 :                         add_next_index_str(return_value, zend_string_copy(Z_STR_P(name)));
    1387             :                 } ZEND_HASH_FOREACH_END();
    1388             :         }
    1389           4 :         if (ft != NULL) {
    1390             :                 zend_function *f;
    1391             : 
    1392          15 :                 ZEND_HASH_FOREACH_PTR(ft, f) {
    1393           6 :                         if ((service->type != SOAP_OBJECT && service->type != SOAP_CLASS) || (f->common.fn_flags & ZEND_ACC_PUBLIC)) {
    1394          10 :                                 add_next_index_str(return_value, zend_string_copy(f->common.function_name));
    1395             :                         }
    1396             :                 } ZEND_HASH_FOREACH_END();
    1397             :         }
    1398             : 
    1399           4 :         SOAP_SERVER_END_CODE();
    1400             : }
    1401             : /* }}} */
    1402             : 
    1403             : 
    1404             : /* {{{ proto void SoapServer::addFunction(mixed functions)
    1405             :    Adds one or several functions those will handle SOAP requests */
    1406         143 : PHP_METHOD(SoapServer, addFunction)
    1407             : {
    1408             :         soapServicePtr service;
    1409             :         zval *function_name, function_copy;
    1410             : 
    1411         143 :         SOAP_SERVER_BEGIN_CODE();
    1412             : 
    1413         143 :         FETCH_THIS_SERVICE(service);
    1414             : 
    1415         143 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &function_name) == FAILURE) {
    1416           0 :                 return;
    1417             :         }
    1418             : 
    1419             :         /* TODO: could use zend_is_callable here */
    1420             : 
    1421         286 :         if (Z_TYPE_P(function_name) == IS_ARRAY) {
    1422           3 :                 if (service->type == SOAP_FUNCTIONS) {
    1423             :                         zval *tmp_function;
    1424             : 
    1425           3 :                         if (service->soap_functions.ft == NULL) {
    1426           0 :                                 service->soap_functions.functions_all = FALSE;
    1427           0 :                                 service->soap_functions.ft = emalloc(sizeof(HashTable));
    1428           0 :                                 zend_hash_init(service->soap_functions.ft, zend_hash_num_elements(Z_ARRVAL_P(function_name)), NULL, ZVAL_PTR_DTOR, 0);
    1429             :                         }
    1430             : 
    1431          15 :                         ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(function_name), tmp_function) {
    1432             :                                 zend_string *key;
    1433             :                                 zend_function *f;
    1434             : 
    1435           6 :                                 if (Z_TYPE_P(tmp_function) != IS_STRING) {
    1436           0 :                                         php_error_docref(NULL, E_WARNING, "Tried to add a function that isn't a string");
    1437           0 :                                         return;
    1438             :                                 }
    1439             : 
    1440          12 :                                 key = zend_string_alloc(Z_STRLEN_P(tmp_function), 0);
    1441           6 :                                 zend_str_tolower_copy(key->val, Z_STRVAL_P(tmp_function), Z_STRLEN_P(tmp_function));
    1442             : 
    1443          12 :                                 if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
    1444           0 :                                         php_error_docref(NULL, E_WARNING, "Tried to add a non existent function '%s'", Z_STRVAL_P(tmp_function));
    1445           0 :                                         return;
    1446             :                                 }
    1447             : 
    1448           6 :                                 ZVAL_STR_COPY(&function_copy, f->common.function_name);
    1449           6 :                                 zend_hash_update(service->soap_functions.ft, key, &function_copy);
    1450             : 
    1451             :                                 zend_string_release(key);
    1452             :                         } ZEND_HASH_FOREACH_END();
    1453             :                 }
    1454         280 :         } else if (Z_TYPE_P(function_name) == IS_STRING) {
    1455             :                 zend_string *key;
    1456             :                 zend_function *f;
    1457             : 
    1458         278 :                 key = zend_string_alloc(Z_STRLEN_P(function_name), 0);
    1459         139 :                 zend_str_tolower_copy(key->val, Z_STRVAL_P(function_name), Z_STRLEN_P(function_name));
    1460             : 
    1461         278 :                 if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
    1462           0 :                         php_error_docref(NULL, E_WARNING, "Tried to add a non existent function '%s'", Z_STRVAL_P(function_name));
    1463           0 :                         return;
    1464             :                 }
    1465         139 :                 if (service->soap_functions.ft == NULL) {
    1466           0 :                         service->soap_functions.functions_all = FALSE;
    1467           0 :                         service->soap_functions.ft = emalloc(sizeof(HashTable));
    1468           0 :                         zend_hash_init(service->soap_functions.ft, 0, NULL, ZVAL_PTR_DTOR, 0);
    1469             :                 }
    1470             : 
    1471         139 :                 ZVAL_STR_COPY(&function_copy, f->common.function_name);
    1472         139 :                 zend_hash_update(service->soap_functions.ft, key, &function_copy);
    1473             :                 zend_string_release(key);
    1474           2 :         } else if (Z_TYPE_P(function_name) == IS_LONG) {
    1475           1 :                 if (Z_LVAL_P(function_name) == SOAP_FUNCTIONS_ALL) {
    1476           1 :                         if (service->soap_functions.ft != NULL) {
    1477           1 :                                 zend_hash_destroy(service->soap_functions.ft);
    1478           1 :                                 efree(service->soap_functions.ft);
    1479           1 :                                 service->soap_functions.ft = NULL;
    1480             :                         }
    1481           1 :                         service->soap_functions.functions_all = TRUE;
    1482             :                 } else {
    1483           0 :                         php_error_docref(NULL, E_WARNING, "Invalid value passed");
    1484           0 :                         return;
    1485             :                 }
    1486             :         }
    1487             : 
    1488         143 :         SOAP_SERVER_END_CODE();
    1489             : }
    1490             : /* }}} */
    1491             : 
    1492           8 : static void _soap_server_exception(soapServicePtr service, sdlFunctionPtr function, zval *this_ptr) /* {{{ */
    1493             : {
    1494             :         zval exception_object;
    1495             : 
    1496           8 :         ZVAL_OBJ(&exception_object, EG(exception));
    1497           8 :         if (instanceof_function(Z_OBJCE(exception_object), soap_fault_class_entry)) {
    1498           5 :                 soap_server_fault_ex(function, &exception_object, NULL);
    1499           3 :         } else if (instanceof_function(Z_OBJCE(exception_object), zend_get_engine_exception())) {
    1500           2 :                 if (service->send_errors) {
    1501             :                         zval rv;
    1502           2 :                         zend_string *msg = zval_get_string(zend_read_property(zend_exception_get_base(), &exception_object, "message", sizeof("message")-1, 0, &rv));
    1503           1 :                         add_soap_fault_ex(&exception_object, this_ptr, "Server", msg->val, NULL, NULL);
    1504             :                         zend_string_release(msg);
    1505             :                 } else {
    1506           1 :                         add_soap_fault_ex(&exception_object, this_ptr, "Server", "Internal Error", NULL, NULL);
    1507             :                 }
    1508           2 :                 soap_server_fault_ex(function, &exception_object, NULL);
    1509             :         } 
    1510           8 : }
    1511             : /* }}} */
    1512             : 
    1513             : /* {{{ proto void SoapServer::handle ( [string soap_request])
    1514             :    Handles a SOAP request */
    1515         478 : PHP_METHOD(SoapServer, handle)
    1516             : {
    1517             :         int soap_version, old_soap_version;
    1518         478 :         sdlPtr old_sdl = NULL;
    1519             :         soapServicePtr service;
    1520         478 :         xmlDocPtr doc_request=NULL, doc_return;
    1521             :         zval function_name, *params, *soap_obj, retval;
    1522             :         char *fn_name, cont_len[30];
    1523         478 :         int num_params = 0, size, i, call_status = 0;
    1524             :         xmlChar *buf;
    1525             :         HashTable *function_table;
    1526         478 :         soapHeader *soap_headers = NULL;
    1527             :         sdlFunctionPtr function;
    1528         478 :         char *arg = NULL;
    1529         478 :         size_t arg_len = 0;
    1530             :         xmlCharEncodingHandlerPtr old_encoding;
    1531             :         HashTable *old_class_map, *old_typemap;
    1532             :         int old_features;
    1533             : 
    1534         478 :         SOAP_SERVER_BEGIN_CODE();
    1535             : 
    1536         478 :         FETCH_THIS_SERVICE(service);
    1537         478 :         SOAP_GLOBAL(soap_version) = service->version;
    1538             : 
    1539         478 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &arg, &arg_len) == FAILURE) {
    1540           0 :                 return;
    1541             :         }
    1542             : 
    1543         487 :         if (SG(request_info).request_method &&
    1544           5 :             strcmp(SG(request_info).request_method, "GET") == 0 &&
    1545           2 :             SG(request_info).query_string &&
    1546           2 :             stricmp(SG(request_info).query_string, "wsdl") == 0) {
    1547             : 
    1548           2 :                 if (service->sdl) {
    1549             : /*
    1550             :                         char *hdr = emalloc(sizeof("Location: ")+strlen(service->sdl->source));
    1551             :                         strcpy(hdr,"Location: ");
    1552             :                         strcat(hdr,service->sdl->source);
    1553             :                         sapi_add_header(hdr, sizeof("Location: ")+strlen(service->sdl->source)-1, 1);
    1554             :                         efree(hdr);
    1555             : */
    1556             :                         zval readfile, readfile_ret, param;
    1557             : 
    1558           1 :                         sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
    1559           2 :                         ZVAL_STRING(&param, service->sdl->source);
    1560           2 :                         ZVAL_STRING(&readfile, "readfile");
    1561           1 :                         if (call_user_function(EG(function_table), NULL, &readfile, &readfile_ret, 1, &param ) == FAILURE) {
    1562           0 :                                 soap_server_fault("Server", "Couldn't find WSDL", NULL, NULL, NULL);
    1563             :                         }
    1564             : 
    1565           1 :                         zval_ptr_dtor(&param);
    1566             :                         zval_dtor(&readfile);
    1567             :                         zval_dtor(&readfile_ret);
    1568             : 
    1569           1 :                         SOAP_SERVER_END_CODE();
    1570           1 :                         return;
    1571             :                 } else {
    1572           1 :                         soap_server_fault("Server", "WSDL generation is not supported yet", NULL, NULL, NULL);
    1573             : /*
    1574             :                         sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8"), 1);
    1575             :                         PUTS("<?xml version=\"1.0\" ?>\n<definitions\n");
    1576             :                         PUTS("    xmlns=\"http://schemas.xmlsoap.org/wsdl/\"\n");
    1577             :                         PUTS("    targetNamespace=\"");
    1578             :                         PUTS(service->uri);
    1579             :                         PUTS("\">\n");
    1580             :                         PUTS("</definitions>");
    1581             : */
    1582           0 :                         SOAP_SERVER_END_CODE();
    1583           0 :                         return;
    1584             :                 }
    1585             :         }
    1586             : 
    1587         476 :         ZVAL_NULL(&retval);
    1588             : 
    1589         476 :         if (php_output_start_default() != SUCCESS) {
    1590           0 :                 php_error_docref(NULL, E_ERROR,"ob_start failed");
    1591             :         }
    1592             : 
    1593         476 :         if (ZEND_NUM_ARGS() == 0) {
    1594           6 :                 if (SG(request_info).request_body && 0 == php_stream_rewind(SG(request_info).request_body)) {
    1595             :                         zval *server_vars, *encoding;
    1596           3 :                         php_stream_filter *zf = NULL;
    1597           3 :                         zend_string *server = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0);
    1598             : 
    1599           3 :                         zend_is_auto_global(server);
    1600          11 :                         if ((server_vars = zend_hash_find(&EG(symbol_table), server)) != NULL &&
    1601             :                             Z_TYPE_P(server_vars) == IS_ARRAY &&
    1602           3 :                             (encoding = zend_hash_str_find(Z_ARRVAL_P(server_vars), "HTTP_CONTENT_ENCODING", sizeof("HTTP_CONTENT_ENCODING")-1)) != NULL &&
    1603             :                             Z_TYPE_P(encoding) == IS_STRING) {
    1604             : 
    1605           8 :                                 if (strcmp(Z_STRVAL_P(encoding),"gzip") == 0
    1606           3 :                                 ||  strcmp(Z_STRVAL_P(encoding),"x-gzip") == 0
    1607           2 :                                 ||  strcmp(Z_STRVAL_P(encoding),"deflate") == 0
    1608             :                                 ) {
    1609             :                                         zval filter_params;
    1610             : 
    1611           2 :                                         array_init_size(&filter_params, 1);
    1612           2 :                                         add_assoc_long_ex(&filter_params, "window", sizeof("window")-1, 0x2f); /* ANY WBITS */
    1613             : 
    1614           2 :                                         zf = php_stream_filter_create("zlib.inflate", &filter_params, 0);
    1615             :                                         zval_dtor(&filter_params);
    1616             : 
    1617           2 :                                         if (zf) {
    1618           2 :                                                 php_stream_filter_append(&SG(request_info).request_body->readfilters, zf);
    1619             :                                         } else {
    1620           0 :                                                 php_error_docref(NULL, E_WARNING,"Can't uncompress compressed request");
    1621             :                                                 zend_string_release(server);
    1622           0 :                                                 return;
    1623             :                                         }
    1624             :                                 } else {
    1625           0 :                                         php_error_docref(NULL, E_WARNING,"Request is compressed with unknown compression '%s'",Z_STRVAL_P(encoding));
    1626             :                                         zend_string_release(server);
    1627           0 :                                         return;
    1628             :                                 }
    1629             :                         }
    1630             :                         zend_string_release(server);
    1631             : 
    1632           3 :                         doc_request = soap_xmlParseFile("php://input");
    1633             : 
    1634           3 :                         if (zf) {
    1635           2 :                                 php_stream_filter_remove(zf, 1);
    1636             :                         }
    1637             :                 } else {
    1638           0 :                         zval_ptr_dtor(&retval);
    1639           0 :                         return;
    1640             :                 }
    1641             :         } else {
    1642         473 :                 doc_request = soap_xmlParseMemory(arg,arg_len);
    1643             :         }
    1644             : 
    1645         476 :         if (doc_request == NULL) {
    1646           0 :                 soap_server_fault("Client", "Bad Request", NULL, NULL, NULL);
    1647             :         }
    1648         476 :         if (xmlGetIntSubset(doc_request) != NULL) {
    1649           3 :                 xmlNodePtr env = get_node(doc_request->children,"Envelope");
    1650           3 :                 if (env && env->ns) {
    1651           3 :                         if (strcmp((char*)env->ns->href, SOAP_1_1_ENV_NAMESPACE) == 0) {
    1652           0 :                                 SOAP_GLOBAL(soap_version) = SOAP_1_1;
    1653           3 :                         } else if (strcmp((char*)env->ns->href,SOAP_1_2_ENV_NAMESPACE) == 0) {
    1654           3 :                                 SOAP_GLOBAL(soap_version) = SOAP_1_2;
    1655             :                         }
    1656             :                 }
    1657           3 :                 xmlFreeDoc(doc_request);
    1658           3 :                 soap_server_fault("Server", "DTD are not supported by SOAP", NULL, NULL, NULL);
    1659             :         }
    1660             : 
    1661         473 :         old_sdl = SOAP_GLOBAL(sdl);
    1662         473 :         SOAP_GLOBAL(sdl) = service->sdl;
    1663         473 :         old_encoding = SOAP_GLOBAL(encoding);
    1664         473 :         SOAP_GLOBAL(encoding) = service->encoding;
    1665         473 :         old_class_map = SOAP_GLOBAL(class_map);
    1666         473 :         SOAP_GLOBAL(class_map) = service->class_map;
    1667         473 :         old_typemap = SOAP_GLOBAL(typemap);
    1668         473 :         SOAP_GLOBAL(typemap) = service->typemap;
    1669         473 :         old_features = SOAP_GLOBAL(features);
    1670         473 :         SOAP_GLOBAL(features) = service->features;
    1671         473 :         old_soap_version = SOAP_GLOBAL(soap_version);
    1672         473 :         function = deserialize_function_call(service->sdl, doc_request, service->actor, &function_name, &num_params, &params, &soap_version, &soap_headers);
    1673         455 :         xmlFreeDoc(doc_request);
    1674             : 
    1675         455 :         if (EG(exception)) {
    1676           1 :                 php_output_discard();
    1677           1 :                 _soap_server_exception(service, function, getThis());
    1678           1 :                 goto fail;
    1679             :         }
    1680             : 
    1681         454 :         service->soap_headers_ptr = &soap_headers;
    1682             : 
    1683         454 :         soap_obj = NULL;
    1684         454 :         if (service->type == SOAP_OBJECT) {
    1685           3 :                 soap_obj = &service->soap_object;
    1686           3 :                 function_table = &((Z_OBJCE_P(soap_obj))->function_table);
    1687         451 :         } else if (service->type == SOAP_CLASS) {
    1688             : #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
    1689             :                 /* If persistent then set soap_obj from from the previous created session (if available) */
    1690         292 :                 if (service->soap_class.persistence == SOAP_PERSISTENCE_SESSION) {
    1691             :                         zval *tmp_soap;
    1692             :                         zval *session_vars;
    1693             : 
    1694           2 :                         if (PS(session_status) != php_session_active &&
    1695           0 :                             PS(session_status) != php_session_disabled) {
    1696           0 :                                 php_session_start();
    1697             :                         }
    1698             : 
    1699             :                         /* Find the soap object and assign */
    1700           2 :                         session_vars = &PS(http_session_vars);
    1701           2 :                         ZVAL_DEREF(session_vars);
    1702           6 :                         if (Z_TYPE_P(session_vars) == IS_ARRAY &&
    1703           2 :                             (tmp_soap = zend_hash_str_find(Z_ARRVAL_P(session_vars), "_bogus_session_name", sizeof("_bogus_session_name")-1)) != NULL &&
    1704             :                             Z_TYPE_P(tmp_soap) == IS_OBJECT &&
    1705           1 :                             Z_OBJCE_P(tmp_soap) == service->soap_class.ce) {
    1706           1 :                                 soap_obj = tmp_soap;
    1707             :                         }
    1708             :                 }
    1709             : #endif
    1710             :                 /* If new session or something weird happned */
    1711         292 :                 if (soap_obj == NULL) {
    1712             :                         zval tmp_soap;
    1713             : 
    1714         291 :                         object_init_ex(&tmp_soap, service->soap_class.ce);
    1715             : 
    1716             :                         /* Call constructor */
    1717         291 :                         if (zend_hash_str_exists(&Z_OBJCE(tmp_soap)->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1)) {
    1718             :                                 zval c_ret, constructor;
    1719             : 
    1720           2 :                                 ZVAL_STRING(&constructor, ZEND_CONSTRUCTOR_FUNC_NAME);
    1721           1 :                                 if (call_user_function(NULL, &tmp_soap, &constructor, &c_ret, service->soap_class.argc, service->soap_class.argv) == FAILURE) {
    1722           0 :                                         php_error_docref(NULL, E_ERROR, "Error calling constructor");
    1723             :                                 }
    1724           1 :                                 if (EG(exception)) {
    1725           0 :                                         php_output_discard();
    1726           0 :                                         _soap_server_exception(service, function, getThis());
    1727             :                                         zval_dtor(&constructor);
    1728             :                                         zval_dtor(&c_ret);
    1729           0 :                                         zval_ptr_dtor(&tmp_soap);
    1730           0 :                                         goto fail;
    1731             :                                 }
    1732             :                                 zval_dtor(&constructor);
    1733             :                                 zval_dtor(&c_ret);
    1734             :                         } else {
    1735         290 :                                 int class_name_len = service->soap_class.ce->name->len;
    1736         290 :                                 char *class_name = emalloc(class_name_len+1);
    1737             : 
    1738         290 :                                 memcpy(class_name, service->soap_class.ce->name->val, class_name_len+1);
    1739         290 :                                 if (zend_hash_str_exists(&Z_OBJCE(tmp_soap)->function_table, php_strtolower(class_name, class_name_len), class_name_len)) {
    1740             :                                         zval c_ret, constructor;
    1741             : 
    1742           0 :                                         ZVAL_STR_COPY(&constructor, service->soap_class.ce->name);
    1743           0 :                                         if (call_user_function(NULL, &tmp_soap, &constructor, &c_ret, service->soap_class.argc, service->soap_class.argv) == FAILURE) {
    1744           0 :                                                 php_error_docref(NULL, E_ERROR, "Error calling constructor");
    1745             :                                         }
    1746             : 
    1747           0 :                                         if (EG(exception)) {
    1748           0 :                                                 php_output_discard();
    1749           0 :                                                 _soap_server_exception(service, function, getThis());
    1750             :                                                 zval_dtor(&constructor);
    1751             :                                                 zval_dtor(&c_ret);
    1752           0 :                                                 efree(class_name);
    1753           0 :                                                 zval_ptr_dtor(&tmp_soap);
    1754           0 :                                                 goto fail;
    1755             :                                         }
    1756             : 
    1757             :                                         zval_dtor(&constructor);
    1758             :                                         zval_dtor(&c_ret);
    1759             :                                 }
    1760         290 :                                 efree(class_name);
    1761             :                         }
    1762             : #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
    1763             :                         /* If session then update session hash with new object */
    1764         291 :                         if (service->soap_class.persistence == SOAP_PERSISTENCE_SESSION) {
    1765             :                                 zval *tmp_soap_pp;
    1766           1 :                                 zval *session_vars = &PS(http_session_vars);
    1767             : 
    1768           1 :                                 ZVAL_DEREF(session_vars);
    1769           3 :                                 if (Z_TYPE_P(session_vars) == IS_ARRAY &&
    1770           1 :                                     (tmp_soap_pp = zend_hash_str_update(Z_ARRVAL_P(session_vars), "_bogus_session_name", sizeof("_bogus_session_name")-1, &tmp_soap)) != NULL) {
    1771           1 :                                         soap_obj = tmp_soap_pp;
    1772             :                                 } else {
    1773           0 :                                         soap_obj = &tmp_soap;
    1774             :                                 }
    1775             :                         } else {
    1776         290 :                                 soap_obj = &tmp_soap;
    1777             :                         }
    1778             : #else
    1779             :                         soap_obj = &tmp_soap;
    1780             : #endif
    1781             : 
    1782             :                 }
    1783         292 :                 function_table = &((Z_OBJCE_P(soap_obj))->function_table);
    1784             :         } else {
    1785         159 :                 if (service->soap_functions.functions_all == TRUE) {
    1786           1 :                         function_table = EG(function_table);
    1787             :                 } else {
    1788         158 :                         function_table = service->soap_functions.ft;
    1789             :                 }
    1790             :         }
    1791             : 
    1792         454 :         doc_return = NULL;
    1793             : 
    1794             :         /* Process soap headers */
    1795         454 :         if (soap_headers != NULL) {
    1796          38 :                 soapHeader *header = soap_headers;
    1797         112 :                 while (header != NULL) {
    1798          42 :                         soapHeader *h = header;
    1799             : 
    1800          42 :                         header = header->next;
    1801             : #if 0
    1802             :                         if (service->sdl && !h->function && !h->hdr) {
    1803             :                                 if (h->mustUnderstand) {
    1804             :                                         soap_server_fault("MustUnderstand","Header not understood", NULL, NULL, NULL);
    1805             :                                 } else {
    1806             :                                         continue;
    1807             :                                 }
    1808             :                         }
    1809             : #endif
    1810          42 :                         fn_name = estrndup(Z_STRVAL(h->function_name),Z_STRLEN(h->function_name));
    1811          97 :                         if (zend_hash_str_exists(function_table, php_strtolower(fn_name, Z_STRLEN(h->function_name)), Z_STRLEN(h->function_name)) ||
    1812          14 :                             ((service->type == SOAP_CLASS || service->type == SOAP_OBJECT) &&
    1813          14 :                              zend_hash_str_exists(function_table, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
    1814          56 :                                 if (service->type == SOAP_CLASS || service->type == SOAP_OBJECT) {
    1815          28 :                                         call_status = call_user_function(NULL, soap_obj, &h->function_name, &h->retval, h->num_params, h->parameters);
    1816             :                                 } else {
    1817           0 :                                         call_status = call_user_function(EG(function_table), NULL, &h->function_name, &h->retval, h->num_params, h->parameters);
    1818             :                                 }
    1819          28 :                                 if (call_status != SUCCESS) {
    1820           0 :                                         php_error_docref(NULL, E_WARNING, "Function '%s' call failed", Z_STRVAL(h->function_name));
    1821           0 :                                         return;
    1822             :                                 }
    1823          64 :                                 if (Z_TYPE(h->retval) == IS_OBJECT &&
    1824           8 :                                     instanceof_function(Z_OBJCE(h->retval), soap_fault_class_entry)) {
    1825             : //???                                   zval *headerfault = NULL;
    1826             :                                         zval *tmp;
    1827             : 
    1828           1 :                                         if ((tmp = zend_hash_str_find(Z_OBJPROP(h->retval), "headerfault", sizeof("headerfault")-1)) != NULL &&
    1829             :                                             Z_TYPE_P(tmp) != IS_NULL) {
    1830             : //???                                           headerfault = tmp;
    1831             :                                         }
    1832           1 :                                         php_output_discard();
    1833           1 :                                         soap_server_fault_ex(function, &h->retval, h);
    1834           1 :                                         efree(fn_name);
    1835           1 :                                         if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(soap_obj);}
    1836           1 :                                         goto fail;
    1837          27 :                                 } else if (EG(exception)) {
    1838           0 :                                         php_output_discard();
    1839           0 :                                         _soap_server_exception(service, function, getThis());
    1840           0 :                                         efree(fn_name);
    1841           0 :                                         if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(soap_obj);}
    1842           0 :                                         goto fail;
    1843             :                                 }
    1844          14 :                         } else if (h->mustUnderstand) {
    1845           5 :                                 soap_server_fault("MustUnderstand","Header not understood", NULL, NULL, NULL);
    1846             :                         }
    1847          36 :                         efree(fn_name);
    1848             :                 }
    1849             :         }
    1850             : 
    1851         448 :         fn_name = estrndup(Z_STRVAL(function_name),Z_STRLEN(function_name));
    1852         895 :         if (zend_hash_str_exists(function_table, php_strtolower(fn_name, Z_STRLEN(function_name)), Z_STRLEN(function_name)) ||
    1853           3 :             ((service->type == SOAP_CLASS || service->type == SOAP_OBJECT) &&
    1854           2 :              zend_hash_str_exists(function_table, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
    1855         737 :                 if (service->type == SOAP_CLASS || service->type == SOAP_OBJECT) {
    1856         289 :                         call_status = call_user_function(NULL, soap_obj, &function_name, &retval, num_params, params);
    1857         289 :                         if (service->type == SOAP_CLASS) {
    1858             : #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
    1859         286 :                                 if (service->soap_class.persistence != SOAP_PERSISTENCE_SESSION) {
    1860         284 :                                         zval_ptr_dtor(soap_obj);
    1861         284 :                                         soap_obj = NULL;
    1862             :                                 }
    1863             : #else
    1864             :                                 zval_ptr_dtor(soap_obj);
    1865             :                                 soap_obj = NULL;
    1866             : #endif
    1867             :                         }
    1868             :                 } else {
    1869         159 :                         call_status = call_user_function(EG(function_table), NULL, &function_name, &retval, num_params, params);
    1870             :                 }
    1871             :         } else {
    1872           0 :                 php_error(E_ERROR, "Function '%s' doesn't exist", Z_STRVAL(function_name));
    1873             :         }
    1874         442 :         efree(fn_name);
    1875             : 
    1876         442 :         if (EG(exception)) {
    1877           6 :                 php_output_discard();
    1878           6 :                 _soap_server_exception(service, function, getThis());
    1879           6 :                 if (service->type == SOAP_CLASS) {
    1880             : #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
    1881           1 :                         if (soap_obj && service->soap_class.persistence != SOAP_PERSISTENCE_SESSION) {
    1882             : #else
    1883             :                         if (soap_obj) {
    1884             : #endif
    1885           0 :                                 zval_ptr_dtor(soap_obj);
    1886             :                         }
    1887             :                 }
    1888           6 :                 goto fail;
    1889             :         }
    1890             : 
    1891         436 :         if (call_status == SUCCESS) {
    1892             :                 char *response_name;
    1893             : 
    1894         553 :                 if (Z_TYPE(retval) == IS_OBJECT &&
    1895         117 :                     instanceof_function(Z_OBJCE(retval), soap_fault_class_entry)) {
    1896          59 :                         php_output_discard();
    1897          59 :                         soap_server_fault_ex(function, &retval, NULL);
    1898          59 :                         goto fail;
    1899             :                 }
    1900             : 
    1901         623 :                 if (function && function->responseName) {
    1902         246 :                         response_name = estrdup(function->responseName);
    1903             :                 } else {
    1904         131 :                         response_name = emalloc(Z_STRLEN(function_name) + sizeof("Response"));
    1905         131 :                         memcpy(response_name,Z_STRVAL(function_name),Z_STRLEN(function_name));
    1906         131 :                         memcpy(response_name+Z_STRLEN(function_name),"Response",sizeof("Response"));
    1907             :                 }
    1908         377 :                 doc_return = serialize_response_call(function, response_name, service->uri, &retval, soap_headers, soap_version);
    1909         376 :                 efree(response_name);
    1910             :         } else {
    1911           0 :                 php_error_docref(NULL, E_WARNING, "Function '%s' call failed", Z_STRVAL(function_name));
    1912           0 :                 return;
    1913             :         }
    1914             : 
    1915         376 :         if (EG(exception)) {
    1916           1 :                 php_output_discard();
    1917           1 :                 _soap_server_exception(service, function, getThis());
    1918           1 :                 if (service->type == SOAP_CLASS) {
    1919             : #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
    1920           1 :                         if (soap_obj && service->soap_class.persistence != SOAP_PERSISTENCE_SESSION) {
    1921             : #else
    1922             :                         if (soap_obj) {
    1923             : #endif
    1924           0 :                                 zval_ptr_dtor(soap_obj);
    1925             :                         }
    1926             :                 }
    1927           1 :                 goto fail;
    1928             :         }
    1929             : 
    1930             :         /* Flush buffer */
    1931         375 :         php_output_discard();
    1932             : 
    1933         375 :         if (doc_return) {
    1934             :                 /* xmlDocDumpMemoryEnc(doc_return, &buf, &size, XML_CHAR_ENCODING_UTF8); */
    1935         293 :                 xmlDocDumpMemory(doc_return, &buf, &size);
    1936             : 
    1937         293 :                 if (size == 0) {
    1938           0 :                         php_error_docref(NULL, E_ERROR, "Dump memory failed");
    1939             :                 }
    1940             : 
    1941         293 :                 if (soap_version == SOAP_1_2) {
    1942          50 :                         sapi_add_header("Content-Type: application/soap+xml; charset=utf-8", sizeof("Content-Type: application/soap+xml; charset=utf-8")-1, 1);
    1943             :                 } else {
    1944         243 :                         sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
    1945             :                 }
    1946             : 
    1947         293 :                 xmlFreeDoc(doc_return);
    1948             : 
    1949         293 :                 if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
    1950           0 :                         sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
    1951             :                 } else {
    1952         293 :                         snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
    1953         293 :                         sapi_add_header(cont_len, strlen(cont_len), 1);
    1954             :                 }
    1955         293 :                 php_write(buf, size);
    1956         293 :                 xmlFree(buf);
    1957             :         } else {
    1958          82 :                 sapi_add_header("HTTP/1.1 202 Accepted", sizeof("HTTP/1.1 202 Accepted")-1, 1);
    1959          82 :                 sapi_add_header("Content-Length: 0", sizeof("Content-Length: 0")-1, 1);
    1960             :         }
    1961             : 
    1962             : fail:
    1963         443 :         SOAP_GLOBAL(soap_version) = old_soap_version;
    1964         443 :         SOAP_GLOBAL(encoding) = old_encoding;
    1965         443 :         SOAP_GLOBAL(sdl) = old_sdl;
    1966         443 :         SOAP_GLOBAL(class_map) = old_class_map;
    1967         443 :         SOAP_GLOBAL(typemap) = old_typemap;
    1968         443 :         SOAP_GLOBAL(features) = old_features;
    1969             : 
    1970             :         /* Free soap headers */
    1971         443 :         zval_ptr_dtor(&retval);
    1972         929 :         while (soap_headers != NULL) {
    1973          43 :                 soapHeader *h = soap_headers;
    1974             :                 int i;
    1975             : 
    1976          43 :                 soap_headers = soap_headers->next;
    1977          43 :                 if (h->parameters) {
    1978          37 :                         i = h->num_params;
    1979         112 :                         while (i > 0) {
    1980          38 :                                 zval_ptr_dtor(&h->parameters[--i]);
    1981             :                         }
    1982          37 :                         efree(h->parameters);
    1983             :                 }
    1984          43 :                 zval_dtor(&h->function_name);
    1985          43 :                 zval_dtor(&h->retval);
    1986          43 :                 efree(h);
    1987             :         }
    1988         443 :         service->soap_headers_ptr = NULL;
    1989             : 
    1990             :         /* Free Memory */
    1991         443 :         if (num_params > 0) {
    1992         819 :                 for (i = 0; i < num_params;i++) {
    1993         447 :                         zval_ptr_dtor(&params[i]);
    1994             :                 }
    1995         372 :                 efree(params);
    1996             :         }
    1997             :         zval_dtor(&function_name);
    1998             : 
    1999         443 :         SOAP_SERVER_END_CODE();
    2000             : }
    2001             : /* }}} */
    2002             : 
    2003             : 
    2004             : /* {{{ proto SoapServer::fault ( staring code, string string [, string actor [, mixed details [, string name]]] )
    2005             :    Issue SoapFault indicating an error */
    2006           2 : PHP_METHOD(SoapServer, fault)
    2007             : {
    2008           2 :         char *code, *string, *actor=NULL, *name=NULL;
    2009           2 :         size_t code_len, string_len, actor_len = 0, name_len = 0;
    2010           2 :         zval* details = NULL;
    2011             :         soapServicePtr service;
    2012             :         xmlCharEncodingHandlerPtr old_encoding;
    2013             : 
    2014           2 :         SOAP_SERVER_BEGIN_CODE();
    2015           2 :         FETCH_THIS_SERVICE(service);
    2016           2 :         old_encoding = SOAP_GLOBAL(encoding);
    2017           2 :         SOAP_GLOBAL(encoding) = service->encoding;
    2018             : 
    2019           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|szs",
    2020             :             &code, &code_len, &string, &string_len, &actor, &actor_len, &details,
    2021             :             &name, &name_len) == FAILURE) {
    2022           0 :                 return;
    2023             :         }
    2024             : 
    2025           2 :         soap_server_fault(code, string, actor, details, name);
    2026             : 
    2027           0 :         SOAP_GLOBAL(encoding) = old_encoding;
    2028           0 :         SOAP_SERVER_END_CODE();
    2029             : }
    2030             : /* }}} */
    2031             : 
    2032           6 : PHP_METHOD(SoapServer, addSoapHeader)
    2033             : {
    2034             :         soapServicePtr service;
    2035             :         zval *fault;
    2036             :         soapHeader **p;
    2037             : 
    2038           6 :         SOAP_SERVER_BEGIN_CODE();
    2039             : 
    2040           6 :         FETCH_THIS_SERVICE(service);
    2041             : 
    2042          12 :         if (!service || !service->soap_headers_ptr) {
    2043           0 :                 php_error_docref(NULL, E_WARNING, "The SoapServer::addSoapHeader function may be called only during SOAP request processing");
    2044           0 :                 return;
    2045             :         }
    2046             : 
    2047           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &fault, soap_header_class_entry) == FAILURE) {
    2048           0 :                 return;
    2049             :         }
    2050             : 
    2051           6 :         p = service->soap_headers_ptr;
    2052          15 :         while (*p != NULL) {
    2053           3 :                 p = &(*p)->next;
    2054             :         }
    2055           6 :         *p = emalloc(sizeof(soapHeader));
    2056           6 :         memset(*p, 0, sizeof(soapHeader));
    2057           6 :         ZVAL_NULL(&(*p)->function_name);
    2058           6 :         (*p)->retval = *fault;
    2059           6 :         zval_copy_ctor(&(*p)->retval);
    2060             : 
    2061           6 :         SOAP_SERVER_END_CODE();
    2062             : }
    2063             : 
    2064          98 : static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeader *hdr)
    2065             : {
    2066             :         int soap_version;
    2067             :         xmlChar *buf;
    2068             :         char cont_len[30];
    2069             :         int size;
    2070             :         xmlDocPtr doc_return;
    2071             :         zval *agent_name;
    2072          98 :         int use_http_error_status = 1;
    2073             : 
    2074          98 :         soap_version = SOAP_GLOBAL(soap_version);
    2075             : 
    2076          98 :         doc_return = serialize_response_call(function, NULL, NULL, fault, hdr, soap_version);
    2077             : 
    2078          98 :         xmlDocDumpMemory(doc_return, &buf, &size);
    2079             : 
    2080         196 :         if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) &&
    2081          98 :                 (agent_name = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT")-1)) != NULL &&
    2082             :                 Z_TYPE_P(agent_name) == IS_STRING) {
    2083           0 :                 if (strncmp(Z_STRVAL_P(agent_name), "Shockwave Flash", sizeof("Shockwave Flash")-1) == 0) {
    2084           0 :                         use_http_error_status = 0;
    2085             :                 }
    2086             :         }
    2087             :         /*
    2088             :            Want to return HTTP 500 but apache wants to over write
    2089             :            our fault code with their own handling... Figure this out later
    2090             :         */
    2091          98 :         if (use_http_error_status) {
    2092          98 :                 sapi_add_header("HTTP/1.1 500 Internal Service Error", sizeof("HTTP/1.1 500 Internal Service Error")-1, 1);
    2093             :         }
    2094          98 :         if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
    2095           0 :                 sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
    2096             :         } else {
    2097          98 :                 snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
    2098          98 :                 sapi_add_header(cont_len, strlen(cont_len), 1);
    2099             :         }
    2100          98 :         if (soap_version == SOAP_1_2) {
    2101          26 :                 sapi_add_header("Content-Type: application/soap+xml; charset=utf-8", sizeof("Content-Type: application/soap+xml; charset=utf-8")-1, 1);
    2102             :         } else {
    2103          72 :                 sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
    2104             :         }
    2105             : 
    2106          98 :         php_write(buf, size);
    2107             : 
    2108          98 :         xmlFreeDoc(doc_return);
    2109          98 :         xmlFree(buf);
    2110          98 :         zend_clear_exception();
    2111          98 : }
    2112             : 
    2113          23 : static void soap_server_fault(char* code, char* string, char *actor, zval* details, char* name)
    2114             : {
    2115             :         zval ret;
    2116             : 
    2117          23 :         ZVAL_NULL(&ret);
    2118          23 :         set_soap_fault(&ret, NULL, code, string, actor, details, name);
    2119             :         /* TODO: Which function */
    2120          23 :         soap_server_fault_ex(NULL, &ret, NULL);
    2121          23 :         zend_bailout();
    2122           0 : }
    2123             : 
    2124      377110 : static void soap_error_handler(int error_num, const char *error_filename, const uint error_lineno, const char *format, va_list args)
    2125             : {
    2126             :         zend_bool _old_in_compilation;
    2127             :         zend_execute_data *_old_current_execute_data;
    2128             :         int _old_http_response_code;
    2129             :         char *_old_http_status_line;
    2130             : 
    2131      377110 :         _old_in_compilation = CG(in_compilation);
    2132      377110 :         _old_current_execute_data = EG(current_execute_data);
    2133      377110 :         _old_http_response_code = SG(sapi_headers).http_response_code;
    2134      377110 :         _old_http_status_line = SG(sapi_headers).http_status_line;
    2135             : 
    2136      377110 :         if (!SOAP_GLOBAL(use_soap_error_handler) || !EG(objects_store).object_buckets || (error_num & E_EXCEPTION)) {
    2137      376535 :                 call_old_error_handler(error_num, error_filename, error_lineno, format, args);
    2138      375652 :                 return;
    2139             :         }
    2140             : 
    2141        1154 :         if (Z_OBJ(SOAP_GLOBAL(error_object)) &&
    2142         575 :             instanceof_function(Z_OBJCE(SOAP_GLOBAL(error_object)), soap_class_entry)) {
    2143             :                 zval *tmp;
    2144          11 :                 int use_exceptions = 0;
    2145             : 
    2146          13 :                 if ((tmp = zend_hash_str_find(Z_OBJPROP(SOAP_GLOBAL(error_object)), "_exceptions", sizeof("_exceptions")-1)) == NULL ||
    2147             :                      Z_TYPE_P(tmp) != IS_FALSE) {
    2148           9 :                      use_exceptions = 1;
    2149             :                 }
    2150             : 
    2151          11 :                 if ((error_num == E_USER_ERROR ||
    2152             :                      error_num == E_COMPILE_ERROR ||
    2153             :                      error_num == E_CORE_ERROR ||
    2154             :                      error_num == E_ERROR ||
    2155             :                      error_num == E_PARSE) &&
    2156             :                     use_exceptions) {
    2157             :                         zval fault;
    2158           5 :                         char* code = SOAP_GLOBAL(error_code);
    2159             :                         char buffer[1024];
    2160             :                         int buffer_len;
    2161             : //???                   zval outbuf, outbuflen;
    2162             : #ifdef va_copy
    2163             :                         va_list argcopy;
    2164             : #endif
    2165             :                         zend_object **old_objects;
    2166           5 :                         int old = PG(display_errors);
    2167             : 
    2168             : //???                   INIT_ZVAL(outbuf);
    2169             : //???                   INIT_ZVAL(outbuflen);
    2170             : #ifdef va_copy
    2171           5 :                         va_copy(argcopy, args);
    2172           5 :                         buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, argcopy);
    2173           5 :                         va_end(argcopy);
    2174             : #else
    2175             :                         buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, args);
    2176             : #endif
    2177           5 :                         buffer[sizeof(buffer)-1]=0;
    2178           5 :                         if (buffer_len > sizeof(buffer) - 1 || buffer_len < 0) {
    2179           0 :                                 buffer_len = sizeof(buffer) - 1;
    2180             :                         }
    2181             : 
    2182           5 :                         if (code == NULL) {
    2183           0 :                                 code = "Client";
    2184             :                         }
    2185           5 :                         add_soap_fault_ex(&fault, &SOAP_GLOBAL(error_object), code, buffer, NULL, NULL);
    2186             :                         Z_ADDREF(fault);
    2187           5 :                         zend_throw_exception_object(&fault);
    2188             : 
    2189           5 :                         old_objects = EG(objects_store).object_buckets;
    2190           5 :                         EG(objects_store).object_buckets = NULL;
    2191           5 :                         PG(display_errors) = 0;
    2192           5 :                         SG(sapi_headers).http_status_line = NULL;
    2193           5 :                         zend_try {
    2194           5 :                                 call_old_error_handler(error_num, error_filename, error_lineno, format, args);
    2195           5 :                         } zend_catch {
    2196           5 :                                 CG(in_compilation) = _old_in_compilation;
    2197           5 :                                 EG(current_execute_data) = _old_current_execute_data;
    2198           5 :                                 if (SG(sapi_headers).http_status_line) {
    2199           0 :                                         efree(SG(sapi_headers).http_status_line);
    2200             :                                 }
    2201           5 :                                 SG(sapi_headers).http_status_line = _old_http_status_line;
    2202           5 :                                 SG(sapi_headers).http_response_code = _old_http_response_code;
    2203           5 :                         } zend_end_try();
    2204           5 :                         EG(objects_store).object_buckets = old_objects;
    2205           5 :                         PG(display_errors) = old;
    2206           5 :                         zend_bailout();
    2207          14 :                 } else if (!use_exceptions ||
    2208           4 :                            !SOAP_GLOBAL(error_code) ||
    2209           4 :                            strcmp(SOAP_GLOBAL(error_code),"WSDL") != 0) {
    2210             :                         /* Ignore libxml warnings during WSDL parsing */
    2211           4 :                         call_old_error_handler(error_num, error_filename, error_lineno, format, args);
    2212             :                 }
    2213             :         } else {
    2214         564 :                 int old = PG(display_errors);
    2215         564 :                 int fault = 0;
    2216             :                 zval fault_obj;
    2217             : #ifdef va_copy
    2218             :                 va_list argcopy;
    2219             : #endif
    2220             : 
    2221         564 :                 if (error_num == E_USER_ERROR ||
    2222             :                     error_num == E_COMPILE_ERROR ||
    2223             :                     error_num == E_CORE_ERROR ||
    2224             :                     error_num == E_ERROR ||
    2225             :                     error_num == E_PARSE) {
    2226             : 
    2227           8 :                         char* code = SOAP_GLOBAL(error_code);
    2228             :                         char buffer[1024];
    2229             :                         zval outbuf;
    2230             :                         zval *tmp;
    2231             :                         soapServicePtr service;
    2232             : 
    2233           8 :                         ZVAL_UNDEF(&outbuf);
    2234           8 :                         if (code == NULL) {
    2235           0 :                                 code = "Server";
    2236             :                         }
    2237          40 :                         if (Z_OBJ(SOAP_GLOBAL(error_object)) &&
    2238           8 :                             instanceof_function(Z_OBJCE(SOAP_GLOBAL(error_object)), soap_server_class_entry) &&
    2239           8 :                         (tmp = zend_hash_str_find(Z_OBJPROP(SOAP_GLOBAL(error_object)), "service", sizeof("service")-1)) != NULL &&
    2240           8 :                                 (service = (soapServicePtr)zend_fetch_resource_ex(tmp, "service", le_service)) &&
    2241           8 :                                 !service->send_errors) {
    2242           0 :                                 strcpy(buffer, "Internal Error");
    2243             :                         } else {
    2244             :                                 int buffer_len;
    2245             :                                 zval outbuflen;
    2246             : 
    2247             : //???                           INIT_ZVAL(outbuflen);
    2248             : 
    2249             : #ifdef va_copy
    2250           8 :                                 va_copy(argcopy, args);
    2251           8 :                                 buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, argcopy);
    2252           8 :                                 va_end(argcopy);
    2253             : #else
    2254             :                                 buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, args);
    2255             : #endif
    2256           8 :                                 buffer[sizeof(buffer)-1]=0;
    2257           8 :                                 if (buffer_len > sizeof(buffer) - 1 || buffer_len < 0) {
    2258           0 :                                         buffer_len = sizeof(buffer) - 1;
    2259             :                                 }
    2260             : 
    2261             :                                 /* Get output buffer and send as fault detials */
    2262           8 :                                 if (php_output_get_length(&outbuflen) != FAILURE && Z_LVAL(outbuflen) != 0) {
    2263           0 :                                         php_output_get_contents(&outbuf);
    2264             :                                 }
    2265           8 :                                 php_output_discard();
    2266             : 
    2267             :                         }
    2268           8 :                         ZVAL_NULL(&fault_obj);
    2269           8 :                         set_soap_fault(&fault_obj, NULL, code, buffer, NULL, &outbuf, NULL);
    2270           8 :                         fault = 1;
    2271             :                 }
    2272             : 
    2273         564 :                 PG(display_errors) = 0;
    2274         564 :                 SG(sapi_headers).http_status_line = NULL;
    2275         564 :                 zend_try {
    2276         564 :                         call_old_error_handler(error_num, error_filename, error_lineno, format, args);
    2277           8 :                 } zend_catch {
    2278           8 :                         CG(in_compilation) = _old_in_compilation;
    2279           8 :                         EG(current_execute_data) = _old_current_execute_data;
    2280           8 :                         if (SG(sapi_headers).http_status_line) {
    2281           0 :                                 efree(SG(sapi_headers).http_status_line);
    2282             :                         }
    2283           8 :                         SG(sapi_headers).http_status_line = _old_http_status_line;
    2284           8 :                         SG(sapi_headers).http_response_code = _old_http_response_code;
    2285         564 :                 } zend_end_try();
    2286         564 :                 PG(display_errors) = old;
    2287             : 
    2288         564 :                 if (fault) {
    2289           8 :                         soap_server_fault_ex(NULL, &fault_obj, NULL);
    2290           8 :                         zend_bailout();
    2291             :                 }
    2292             :         }
    2293             : }
    2294             : 
    2295           0 : PHP_FUNCTION(use_soap_error_handler)
    2296             : {
    2297           0 :         zend_bool handler = 1;
    2298             : 
    2299           0 :         ZVAL_BOOL(return_value, SOAP_GLOBAL(use_soap_error_handler));
    2300           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &handler) == SUCCESS) {
    2301           0 :                 SOAP_GLOBAL(use_soap_error_handler) = handler;
    2302             :         }
    2303           0 : }
    2304             : 
    2305           0 : PHP_FUNCTION(is_soap_fault)
    2306             : {
    2307             :         zval *fault;
    2308             : 
    2309           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &fault) == SUCCESS &&
    2310           0 :             Z_TYPE_P(fault) == IS_OBJECT &&
    2311           0 :             instanceof_function(Z_OBJCE_P(fault), soap_fault_class_entry)) {
    2312           0 :                 RETURN_TRUE;
    2313             :         }
    2314           0 :         RETURN_FALSE
    2315             : }
    2316             : 
    2317             : /* SoapClient functions */
    2318             : 
    2319             : /* {{{ proto object SoapClient::SoapClient ( mixed wsdl [, array options])
    2320             :    SoapClient constructor */
    2321         388 : PHP_METHOD(SoapClient, SoapClient)
    2322             : {
    2323             : 
    2324         388 :         zval *wsdl, *options = NULL;
    2325         388 :         int  soap_version = SOAP_1_1;
    2326         388 :         php_stream_context *context = NULL;
    2327             :         zend_long cache_wsdl;
    2328         388 :         sdlPtr sdl = NULL;
    2329         388 :         HashTable *typemap_ht = NULL;
    2330         388 :         zval *this_ptr = getThis();
    2331             : 
    2332         388 :         SOAP_CLIENT_BEGIN_CODE();
    2333             : 
    2334         388 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z|a", &wsdl, &options) == FAILURE) {
    2335           0 :                 php_error_docref(NULL, E_ERROR, "Invalid parameters");
    2336             :         }
    2337             : 
    2338         854 :         if (Z_TYPE_P(wsdl) != IS_STRING && Z_TYPE_P(wsdl) != IS_NULL) {
    2339           0 :                 php_error_docref(NULL, E_ERROR, "$wsdl must be string or null");
    2340             :         }
    2341             : 
    2342         388 :         cache_wsdl = SOAP_GLOBAL(cache_enabled) ? SOAP_GLOBAL(cache_mode) : 0;
    2343             : 
    2344         388 :         if (options != NULL) {
    2345         366 :                 HashTable *ht = Z_ARRVAL_P(options);
    2346             :                 zval *tmp, tmp2;
    2347             : 
    2348         732 :                 if (Z_TYPE_P(wsdl) == IS_NULL) {
    2349             :                         /* Fetching non-WSDL mode options */
    2350         234 :                         if ((tmp = zend_hash_str_find(ht, "uri", sizeof("uri")-1)) != NULL &&
    2351             :                             Z_TYPE_P(tmp) == IS_STRING) {
    2352         156 :                                 add_property_str(this_ptr, "uri", zend_string_copy(Z_STR_P(tmp)));
    2353             :                         } else {
    2354           0 :                                 php_error_docref(NULL, E_ERROR, "'uri' option is required in nonWSDL mode");
    2355             :                         }
    2356             : 
    2357          80 :                         if ((tmp = zend_hash_str_find(ht, "style", sizeof("style")-1)) != NULL &&
    2358             :                                         Z_TYPE_P(tmp) == IS_LONG &&
    2359           1 :                                         (Z_LVAL_P(tmp) == SOAP_RPC || Z_LVAL_P(tmp) == SOAP_DOCUMENT)) {
    2360           1 :                                 add_property_long(this_ptr, "style", Z_LVAL_P(tmp));
    2361             :                         }
    2362             : 
    2363          81 :                         if ((tmp = zend_hash_str_find(ht, "use", sizeof("use")-1)) != NULL &&
    2364             :                                         Z_TYPE_P(tmp) == IS_LONG &&
    2365           2 :                                         (Z_LVAL_P(tmp) == SOAP_LITERAL || Z_LVAL_P(tmp) == SOAP_ENCODED)) {
    2366           1 :                                 add_property_long(this_ptr, "use", Z_LVAL_P(tmp));
    2367             :                         }
    2368             :                 }
    2369             : 
    2370         367 :                 if ((tmp = zend_hash_str_find(ht, "stream_context", sizeof("stream_context")-1)) != NULL &&
    2371             :                                 Z_TYPE_P(tmp) == IS_RESOURCE) {
    2372           1 :                         context = php_stream_context_from_zval(tmp, 1);
    2373             :                         Z_ADDREF_P(tmp);
    2374             :                 }
    2375             : 
    2376         526 :                 if ((tmp = zend_hash_str_find(ht, "location", sizeof("location")-1)) != NULL &&
    2377             :                     Z_TYPE_P(tmp) == IS_STRING) {
    2378         160 :                         add_property_str(this_ptr, "location", zend_string_copy(Z_STR_P(tmp)));
    2379         572 :                 } else if (Z_TYPE_P(wsdl) == IS_NULL) {
    2380           0 :                         php_error_docref(NULL, E_ERROR, "'location' option is required in nonWSDL mode");
    2381             :                 }
    2382             : 
    2383         366 :                 if ((tmp = zend_hash_str_find(ht, "soap_version", sizeof("soap_version")-1)) != NULL) {
    2384           2 :                         if (Z_TYPE_P(tmp) == IS_LONG ||
    2385           0 :                             (Z_LVAL_P(tmp) == SOAP_1_1 && Z_LVAL_P(tmp) == SOAP_1_2)) {
    2386           2 :                                 soap_version = Z_LVAL_P(tmp);
    2387             :                         }
    2388             :                 }
    2389         367 :                 if ((tmp = zend_hash_str_find(ht, "login", sizeof("login")-1)) != NULL &&
    2390             :                     Z_TYPE_P(tmp) == IS_STRING) {
    2391           2 :                         add_property_str(this_ptr, "_login", zend_string_copy(Z_STR_P(tmp)));
    2392           2 :                         if ((tmp = zend_hash_str_find(ht, "password", sizeof("password")-1)) != NULL &&
    2393             :                             Z_TYPE_P(tmp) == IS_STRING) {
    2394           2 :                                 add_property_str(this_ptr, "_password", zend_string_copy(Z_STR_P(tmp)));
    2395             :                         }
    2396           1 :                         if ((tmp = zend_hash_str_find(ht, "authentication", sizeof("authentication")-1)) != NULL &&
    2397             :                             Z_TYPE_P(tmp) == IS_LONG &&
    2398           0 :                             Z_LVAL_P(tmp) == SOAP_AUTHENTICATION_DIGEST) {
    2399           0 :                                 add_property_null(this_ptr, "_digest");
    2400             :                         }
    2401             :                 }
    2402         367 :                 if ((tmp = zend_hash_str_find(ht, "proxy_host", sizeof("proxy_host")-1)) != NULL &&
    2403             :                     Z_TYPE_P(tmp) == IS_STRING) {
    2404           2 :                         add_property_str(this_ptr, "_proxy_host", zend_string_copy(Z_STR_P(tmp)));
    2405           1 :                         if ((tmp = zend_hash_str_find(ht, "proxy_port", sizeof("proxy_port")-1)) != NULL) {
    2406           1 :                                 if (Z_TYPE_P(tmp) != IS_LONG) {
    2407           2 :                                         ZVAL_LONG(&tmp2, zval_get_long(tmp));
    2408           1 :                                         tmp = &tmp2;
    2409             :                                 }
    2410           1 :                                 add_property_long(this_ptr, "_proxy_port", Z_LVAL_P(tmp));
    2411             :                         }
    2412           1 :                         if ((tmp = zend_hash_str_find(ht, "proxy_login", sizeof("proxy_login")-1)) != NULL &&
    2413             :                             Z_TYPE_P(tmp) == IS_STRING) {
    2414           0 :                                 add_property_str(this_ptr, "_proxy_login", zend_string_copy(Z_STR_P(tmp)));
    2415           0 :                                 if ((tmp = zend_hash_str_find(ht, "proxy_password", sizeof("proxy_password")-1)) != NULL &&
    2416             :                                     Z_TYPE_P(tmp) == IS_STRING) {
    2417           0 :                                         add_property_str(this_ptr, "_proxy_password", zend_string_copy(Z_STR_P(tmp)));
    2418             :                                 }
    2419             :                         }
    2420             :                 }
    2421         366 :                 if ((tmp = zend_hash_str_find(ht, "local_cert", sizeof("local_cert")-1)) != NULL &&
    2422             :                     Z_TYPE_P(tmp) == IS_STRING) {
    2423           0 :                   if (!context) {
    2424           0 :                         context = php_stream_context_alloc();
    2425             :                   }
    2426           0 :                         php_stream_context_set_option(context, "ssl", "local_cert", tmp);
    2427           0 :                         if ((tmp = zend_hash_str_find(ht, "passphrase", sizeof("passphrase")-1)) != NULL &&
    2428             :                             Z_TYPE_P(tmp) == IS_STRING) {
    2429           0 :                                 php_stream_context_set_option(context, "ssl", "passphrase", tmp);
    2430             :                         }
    2431             :                 }
    2432        1342 :                 if ((tmp = zend_hash_str_find(ht, "trace", sizeof("trace")-1)) != NULL &&
    2433             :                     (Z_TYPE_P(tmp) == IS_TRUE ||
    2434         324 :                      (Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == 1))) {
    2435         328 :                         add_property_long(this_ptr, "trace", 1);
    2436             :                 }
    2437             : 
    2438        1315 :                 if ((tmp = zend_hash_str_find(ht, "exceptions", sizeof("exceptions")-1)) != NULL &&
    2439             :                     (Z_TYPE_P(tmp) == IS_FALSE ||
    2440         315 :                      (Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == 0))) {
    2441         319 :                         add_property_bool(this_ptr, "_exceptions", 0);
    2442             :                 }
    2443             : 
    2444         366 :                 if ((tmp = zend_hash_str_find(ht, "compression", sizeof("compression")-1)) != NULL &&
    2445             :                     Z_TYPE_P(tmp) == IS_LONG &&
    2446           0 :               zend_hash_str_exists(EG(function_table), "gzinflate", sizeof("gzinflate")-1) &&
    2447           0 :               zend_hash_str_exists(EG(function_table), "gzdeflate", sizeof("gzdeflate")-1) &&
    2448           0 :               zend_hash_str_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1) &&
    2449           0 :               zend_hash_str_exists(EG(function_table), "gzcompress", sizeof("gzcompress")-1) &&
    2450           0 :               zend_hash_str_exists(EG(function_table), "gzencode", sizeof("gzencode")-1)) {
    2451           0 :                         add_property_long(this_ptr, "compression", Z_LVAL_P(tmp));
    2452             :                 }
    2453         379 :                 if ((tmp = zend_hash_str_find(ht, "encoding", sizeof("encoding")-1)) != NULL &&
    2454             :                     Z_TYPE_P(tmp) == IS_STRING) {
    2455             :                         xmlCharEncodingHandlerPtr encoding;
    2456             : 
    2457          13 :                         encoding = xmlFindCharEncodingHandler(Z_STRVAL_P(tmp));
    2458          13 :                         if (encoding == NULL) {
    2459           0 :                                 php_error_docref(NULL, E_ERROR, "Invalid 'encoding' option - '%s'", Z_STRVAL_P(tmp));
    2460             :                         } else {
    2461          13 :                                 xmlCharEncCloseFunc(encoding);
    2462          26 :                                 add_property_str(this_ptr, "_encoding", zend_string_copy(Z_STR_P(tmp)));
    2463             :                         }
    2464             :                 }
    2465         376 :                 if ((tmp = zend_hash_str_find(ht, "classmap", sizeof("classmap")-1)) != NULL &&
    2466             :                         Z_TYPE_P(tmp) == IS_ARRAY) {
    2467             : //???                   zval *class_map;
    2468             : //???
    2469             : //???                   MAKE_STD_ZVAL(class_map);
    2470             : //???                   MAKE_COPY_ZVAL(tmp, class_map);
    2471             : //???                   Z_DELREF_P(class_map);
    2472             : //???
    2473          10 :                         add_property_zval(this_ptr, "_classmap", tmp);
    2474             :                 }
    2475             : 
    2476         380 :                 if ((tmp = zend_hash_str_find(ht, "typemap", sizeof("typemap")-1)) != NULL &&
    2477             :                         Z_TYPE_P(tmp) == IS_ARRAY &&
    2478           7 :                         zend_hash_num_elements(Z_ARRVAL_P(tmp)) > 0) {
    2479           7 :                         typemap_ht = Z_ARRVAL_P(tmp);
    2480             :                 }
    2481             : 
    2482         453 :                 if ((tmp = zend_hash_str_find(ht, "features", sizeof("features")-1)) != NULL &&
    2483             :                         Z_TYPE_P(tmp) == IS_LONG) {
    2484          87 :                         add_property_long(this_ptr, "_features", Z_LVAL_P(tmp));
    2485             :             }
    2486             : 
    2487         366 :                 if ((tmp = zend_hash_str_find(ht, "connection_timeout", sizeof("connection_timeout")-1)) != NULL) {
    2488           0 :                         if (Z_TYPE_P(tmp) != IS_LONG) {
    2489           0 :                                 ZVAL_LONG(&tmp2, zval_get_long(tmp));
    2490           0 :                                 tmp = &tmp2;
    2491             :                         }
    2492           0 :                         if (Z_LVAL_P(tmp) > 0) {
    2493           0 :                                 add_property_long(this_ptr, "_connection_timeout", Z_LVAL_P(tmp));
    2494             :                         }
    2495             :                 }
    2496             : 
    2497         366 :                 if (context) {
    2498           1 :                         add_property_resource(this_ptr, "_stream_context", context->res);
    2499             :                 }
    2500             : 
    2501         377 :                 if ((tmp = zend_hash_str_find(ht, "cache_wsdl", sizeof("cache_wsdl")-1)) != NULL &&
    2502             :                     Z_TYPE_P(tmp) == IS_LONG) {
    2503          11 :                         cache_wsdl = Z_LVAL_P(tmp);
    2504             :                 }
    2505             : 
    2506         366 :                 if ((tmp = zend_hash_str_find(ht, "user_agent", sizeof("user_agent")-1)) != NULL &&
    2507             :                     Z_TYPE_P(tmp) == IS_STRING) {
    2508           0 :                         add_property_str(this_ptr, "_user_agent", zend_string_copy(Z_STR_P(tmp)));
    2509             :                 }
    2510             : 
    2511         366 :                 if ((tmp = zend_hash_str_find(ht, "keep_alive", sizeof("keep_alive")-1)) != NULL &&
    2512             :                                 (Z_TYPE_P(tmp) == IS_FALSE ||
    2513           0 :                                  (Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == 0))) {
    2514           0 :                         add_property_long(this_ptr, "_keep_alive", 0);
    2515             :                 }
    2516             : 
    2517         366 :                 if ((tmp = zend_hash_str_find(ht, "ssl_method", sizeof("ssl_method")-1)) != NULL &&
    2518             :                         Z_TYPE_P(tmp) == IS_LONG) {
    2519           0 :                         add_property_long(this_ptr, "_ssl_method", Z_LVAL_P(tmp));
    2520             :                 }
    2521          44 :         } else if (Z_TYPE_P(wsdl) == IS_NULL) {
    2522           0 :                 php_error_docref(NULL, E_ERROR, "'location' and 'uri' options are required in nonWSDL mode");
    2523             :         }
    2524             : 
    2525         388 :         add_property_long(this_ptr, "_soap_version", soap_version);
    2526             : 
    2527         776 :         if (Z_TYPE_P(wsdl) != IS_NULL) {
    2528             :                 int    old_soap_version;
    2529             :                 zend_resource *res;
    2530             : 
    2531         310 :                 old_soap_version = SOAP_GLOBAL(soap_version);
    2532         310 :                 SOAP_GLOBAL(soap_version) = soap_version;
    2533             : 
    2534         310 :                 sdl = get_sdl(this_ptr, Z_STRVAL_P(wsdl), cache_wsdl);
    2535         305 :                 res = zend_register_resource(sdl, le_sdl);
    2536             : 
    2537         305 :                 add_property_resource(this_ptr, "sdl", res);
    2538             : 
    2539         305 :                 SOAP_GLOBAL(soap_version) = old_soap_version;
    2540             :         }
    2541             : 
    2542         383 :         if (typemap_ht) {
    2543           7 :                 HashTable *typemap = soap_create_typemap(sdl, typemap_ht);
    2544           7 :                 if (typemap) {
    2545             :                         zend_resource *res;
    2546             : 
    2547           7 :                         res = zend_register_resource(typemap, le_typemap);
    2548           7 :                         add_property_resource(this_ptr, "typemap", res);
    2549             :                 }
    2550             :         }
    2551           5 :         SOAP_CLIENT_END_CODE();
    2552         387 : }
    2553             : /* }}} */
    2554             : 
    2555         398 : static int do_request(zval *this_ptr, xmlDoc *request, char *location, char *action, int version, int one_way, zval *response)
    2556             : {
    2557         398 :         int    ret = TRUE;
    2558             :         char  *buf;
    2559             :         int    buf_size;
    2560             :         zval   func;
    2561             :         zval  params[5];
    2562             :         zval  *trace;
    2563             :         zval  *fault;
    2564         398 :         int    _bailout = 0;
    2565             : 
    2566         398 :         ZVAL_NULL(response);
    2567             : 
    2568         398 :         xmlDocDumpMemory(request, (xmlChar**)&buf, &buf_size);
    2569         398 :         if (!buf) {
    2570           0 :                 add_soap_fault(this_ptr, "HTTP", "Error build soap request", NULL, NULL);
    2571           0 :                 return FALSE;
    2572             :         }
    2573             : 
    2574         398 :         zend_try {
    2575        1411 :                 if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL &&
    2576         337 :                     (Z_TYPE_P(trace) == IS_TRUE || (Z_TYPE_P(trace) == IS_LONG && Z_LVAL_P(trace) != 0))) {
    2577         337 :                         add_property_stringl(this_ptr, "__last_request", buf, buf_size);
    2578             :                 }
    2579             : 
    2580         796 :                 ZVAL_STRINGL(&func,"__doRequest",sizeof("__doRequest")-1);
    2581         796 :                 ZVAL_STRINGL(&params[0], buf, buf_size);
    2582         398 :                 if (location == NULL) {
    2583           0 :                         ZVAL_NULL(&params[1]);
    2584             :                 } else {
    2585         796 :                         ZVAL_STRING(&params[1], location);
    2586             :                 }
    2587         398 :                 if (action == NULL) {
    2588           4 :                         ZVAL_NULL(&params[2]);
    2589             :                 } else {
    2590         788 :                         ZVAL_STRING(&params[2], action);
    2591             :                 }
    2592         398 :                 ZVAL_LONG(&params[3], version);
    2593         398 :                 ZVAL_LONG(&params[4], one_way);
    2594             : 
    2595         398 :                 if (call_user_function(NULL, this_ptr, &func, response, 5, params) != SUCCESS) {
    2596           1 :                         add_soap_fault(this_ptr, "Client", "SoapClient::__doRequest() failed", NULL, NULL);
    2597           1 :                         ret = FALSE;
    2598         390 :                 } else if (Z_TYPE_P(response) != IS_STRING) {
    2599         319 :                         if (EG(exception) && instanceof_function(EG(exception)->ce, zend_get_engine_exception())) {
    2600             :                                 zval rv;
    2601             :                                 zend_string *msg;
    2602             :                                 zval exception_object;
    2603             : 
    2604           1 :                                 ZVAL_OBJ(&exception_object, EG(exception));
    2605           2 :                                 msg = zval_get_string(zend_read_property(zend_exception_get_base(), &exception_object, "message", sizeof("message")-1, 0, &rv));
    2606             :                                 /* change class */
    2607           1 :                                 EG(exception)->ce = soap_fault_class_entry;
    2608           1 :                                 set_soap_fault(&exception_object, NULL, "Client", msg->val, NULL, NULL, NULL);
    2609             :                                 zend_string_release(msg);
    2610         317 :                         } else if ((fault = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault")-1)) == NULL) {
    2611           0 :                                 add_soap_fault(this_ptr, "Client", "SoapClient::__doRequest() returned non string value", NULL, NULL);
    2612             :                         }
    2613         318 :                         ret = FALSE;
    2614         129 :                 } else if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL &&
    2615          19 :                     (Z_TYPE_P(trace) == IS_TRUE || (Z_TYPE_P(trace) == IS_LONG && Z_LVAL_P(trace) != 0))) {
    2616          38 :                         add_property_str(this_ptr, "__last_response", zend_string_copy(Z_STR_P(response)));
    2617             :                 }
    2618           7 :         } zend_catch {
    2619           7 :                 _bailout = 1;
    2620         398 :         } zend_end_try();
    2621         398 :         zval_ptr_dtor(&func);
    2622         398 :         zval_ptr_dtor(&params[4]);
    2623         398 :         zval_ptr_dtor(&params[3]);
    2624         398 :         zval_ptr_dtor(&params[2]);
    2625         398 :         zval_ptr_dtor(&params[1]);
    2626         398 :         zval_ptr_dtor(&params[0]);
    2627         398 :         xmlFree(buf);
    2628         398 :         if (_bailout) {
    2629           7 :                 zend_bailout();
    2630             :         }
    2631         391 :         if (ret && (fault = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault")-1)) != NULL) {
    2632           0 :                 ret = FALSE;
    2633             :         }
    2634         391 :         return ret;
    2635             : }
    2636             : 
    2637         400 : static void do_soap_call(zend_execute_data *execute_data,
    2638             :                          zval* this_ptr,
    2639             :                          char* function,
    2640             :                          size_t function_len,
    2641             :                          int arg_count,
    2642             :                          zval* real_args,
    2643             :                          zval* return_value,
    2644             :                          char* location,
    2645             :                          char* soap_action,
    2646             :                          char* call_uri,
    2647             :                          HashTable* soap_headers,
    2648             :                          zval* output_headers
    2649             :                         )
    2650             : {
    2651             :         zval *tmp;
    2652             :         zval *trace;
    2653         400 :         sdlPtr sdl = NULL;
    2654         400 :         sdlPtr old_sdl = NULL;
    2655             :         sdlFunctionPtr fn;
    2656         400 :         xmlDocPtr request = NULL;
    2657         400 :         int ret = FALSE;
    2658             :         int soap_version;
    2659             :         zval response;
    2660             :         xmlCharEncodingHandlerPtr old_encoding;
    2661             :         HashTable *old_class_map;
    2662             :         int old_features;
    2663         400 :         HashTable *old_typemap, *typemap = NULL;
    2664         400 :         smart_str action = {0};
    2665             : 
    2666         400 :         SOAP_CLIENT_BEGIN_CODE();
    2667             : 
    2668        1416 :         if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL &&
    2669         338 :                 (Z_TYPE_P(trace) == IS_TRUE || (Z_TYPE_P(trace) == IS_LONG && Z_LVAL_P(trace) != 0))) {
    2670         338 :                 zend_hash_str_del(Z_OBJPROP_P(this_ptr), "__last_request", sizeof("__last_request")-1);
    2671         338 :                 zend_hash_str_del(Z_OBJPROP_P(this_ptr), "__last_response", sizeof("__last_response")-1);
    2672             :         }
    2673        1200 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_soap_version", sizeof("_soap_version")-1)) != NULL &&
    2674         399 :                 Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == SOAP_1_2) {
    2675           2 :                 soap_version = SOAP_1_2;
    2676             :         } else {
    2677         398 :                 soap_version = SOAP_1_1;
    2678             :         }
    2679             : 
    2680         400 :         if (location == NULL) {
    2681         504 :                 if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "location", sizeof("location")-1)) != NULL &&
    2682             :                     Z_TYPE_P(tmp) == IS_STRING) {
    2683         105 :                   location = Z_STRVAL_P(tmp);
    2684             :                 }
    2685             :         }
    2686             : 
    2687         400 :         if (FIND_SDL_PROPERTY(this_ptr,tmp) != NULL) {
    2688         301 :                 FETCH_SDL_RES(sdl,tmp);
    2689             :         }
    2690         400 :         if (FIND_TYPEMAP_PROPERTY(this_ptr,tmp) != NULL) {
    2691           7 :                 FETCH_TYPEMAP_RES(typemap,tmp);
    2692             :         }
    2693             : 
    2694         400 :         clear_soap_fault(this_ptr);
    2695             : 
    2696         400 :         SOAP_GLOBAL(soap_version) = soap_version;
    2697         400 :         old_sdl = SOAP_GLOBAL(sdl);
    2698         400 :         SOAP_GLOBAL(sdl) = sdl;
    2699         400 :         old_encoding = SOAP_GLOBAL(encoding);
    2700         426 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_encoding", sizeof("_encoding")-1)) != NULL &&
    2701             :             Z_TYPE_P(tmp) == IS_STRING) {
    2702          13 :                 SOAP_GLOBAL(encoding) = xmlFindCharEncodingHandler(Z_STRVAL_P(tmp));
    2703             :         } else {
    2704         387 :                 SOAP_GLOBAL(encoding) = NULL;
    2705             :         }
    2706         400 :         old_class_map = SOAP_GLOBAL(class_map);
    2707         420 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_classmap", sizeof("_classmap")-1)) != NULL &&
    2708             :             Z_TYPE_P(tmp) == IS_ARRAY) {
    2709          10 :                 SOAP_GLOBAL(class_map) = Z_ARRVAL_P(tmp);
    2710             :         } else {
    2711         390 :                 SOAP_GLOBAL(class_map) = NULL;
    2712             :         }
    2713         400 :         old_typemap = SOAP_GLOBAL(typemap);
    2714         400 :         SOAP_GLOBAL(typemap) = typemap;
    2715         400 :         old_features = SOAP_GLOBAL(features);
    2716         574 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_features", sizeof("_features")-1)) != NULL &&
    2717             :             Z_TYPE_P(tmp) == IS_LONG) {
    2718          87 :                 SOAP_GLOBAL(features) = Z_LVAL_P(tmp);
    2719             :         } else {
    2720         313 :                 SOAP_GLOBAL(features) = 0;
    2721             :         }
    2722             : 
    2723         400 :         zend_try {
    2724         400 :                 if (sdl != NULL) {
    2725         301 :                         fn = get_function(sdl, function);
    2726         301 :                         if (fn != NULL) {
    2727         301 :                                 sdlBindingPtr binding = fn->binding;
    2728         301 :                                 int one_way = 0;
    2729             : 
    2730         388 :                                 if (fn->responseName == NULL &&
    2731          87 :                                     fn->responseParameters == NULL &&
    2732             :                                     soap_headers == NULL) {
    2733          87 :                                         one_way = 1;
    2734             :                                 }
    2735             : 
    2736         301 :                                 if (location == NULL) {
    2737         294 :                                         location = binding->location;
    2738             :                                 }
    2739         301 :                                 if (binding->bindingType == BINDING_SOAP) {
    2740         300 :                                         sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)fn->bindingAttributes;
    2741         300 :                                         request = serialize_function_call(this_ptr, fn, NULL, fnb->input.ns, real_args, arg_count, soap_version, soap_headers);
    2742         298 :                                         ret = do_request(this_ptr, request, location, fnb->soapAction, soap_version, one_way, &response);
    2743             :                                 } else {
    2744           1 :                                         request = serialize_function_call(this_ptr, fn, NULL, sdl->target_ns, real_args, arg_count, soap_version, soap_headers);
    2745           1 :                                         ret = do_request(this_ptr, request, location, NULL, soap_version, one_way, &response);
    2746             :                                 }
    2747             : 
    2748         294 :                                 xmlFreeDoc(request);
    2749         294 :                                 request = NULL;
    2750             : 
    2751         343 :                                 if (ret && Z_TYPE(response) == IS_STRING) {
    2752          49 :                                         encode_reset_ns();
    2753          49 :                                         ret = parse_packet_soap(this_ptr, Z_STRVAL(response), Z_STRLEN(response), fn, NULL, return_value, output_headers);
    2754          49 :                                         encode_finish();
    2755             :                                 }
    2756             : 
    2757             :                                 zval_dtor(&response);
    2758             : 
    2759             :                         } else {
    2760           0 :                                 smart_str error = {0};
    2761             :                                 smart_str_appends(&error,"Function (\"");
    2762           0 :                                 smart_str_appends(&error,function);
    2763             :                                 smart_str_appends(&error,"\") is not a valid method for this service");
    2764             :                                 smart_str_0(&error);
    2765           0 :                                 add_soap_fault(this_ptr, "Client", error.s->val, NULL, NULL);
    2766             :                                 smart_str_free(&error);
    2767             :                         }
    2768             :                 } else {
    2769             :                         zval *uri;
    2770             : 
    2771         198 :                         if ((uri = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "uri", sizeof("uri")-1)) == NULL || Z_TYPE_P(uri) != IS_STRING) {
    2772           0 :                                 add_soap_fault(this_ptr, "Client", "Error finding \"uri\" property", NULL, NULL);
    2773          99 :                         } else if (location == NULL) {
    2774           0 :                                 add_soap_fault(this_ptr, "Client", "Error could not find \"location\" property", NULL, NULL);
    2775             :                         } else {
    2776          99 :                                 if (call_uri == NULL) {
    2777          40 :                                         call_uri = Z_STRVAL_P(uri);
    2778             :                                 }
    2779          99 :                                 request = serialize_function_call(this_ptr, NULL, function, call_uri, real_args, arg_count, soap_version, soap_headers);
    2780             : 
    2781          99 :                                 if (soap_action == NULL) {
    2782          41 :                                         smart_str_appends(&action, call_uri);
    2783             :                                         smart_str_appendc(&action, '#');
    2784          41 :                                         smart_str_appends(&action, function);
    2785             :                                 } else {
    2786          58 :                                         smart_str_appends(&action, soap_action);
    2787             :                                 }
    2788             :                                 smart_str_0(&action);
    2789             : 
    2790          99 :                                 ret = do_request(this_ptr, request, location, action.s->val, soap_version, 0, &response);
    2791             : 
    2792             :                                 smart_str_free(&action);
    2793          97 :                                 xmlFreeDoc(request);
    2794          97 :                                 request = NULL;
    2795             : 
    2796         120 :                                 if (ret && Z_TYPE(response) == IS_STRING) {
    2797          23 :                                         encode_reset_ns();
    2798          23 :                                         ret = parse_packet_soap(this_ptr, Z_STRVAL(response), Z_STRLEN(response), NULL, function, return_value, output_headers);
    2799          23 :                                         encode_finish();
    2800             :                                 }
    2801             : 
    2802             :                                 zval_dtor(&response);
    2803             :                         }
    2804             :                 }
    2805             : 
    2806         391 :                 if (!ret) {
    2807             :                         zval* fault;
    2808         323 :                         if ((fault = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault")-1)) != NULL) {
    2809         322 :                                 ZVAL_COPY(return_value, fault);
    2810             :                         } else {
    2811           1 :                                 add_soap_fault_ex(return_value, this_ptr, "Client", "Unknown Error", NULL, NULL);
    2812             :                                 Z_ADDREF_P(return_value);
    2813             :                         }
    2814             :                 } else {
    2815             :                         zval* fault;
    2816          68 :                         if ((fault = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault")-1)) != NULL) {
    2817           0 :                                 ZVAL_COPY(return_value, fault);
    2818             :                         }
    2819             :                 }
    2820             : 
    2821        1766 :                 if (!EG(exception) &&
    2822             :                     Z_TYPE_P(return_value) == IS_OBJECT &&
    2823         347 :                     instanceof_function(Z_OBJCE_P(return_value), soap_fault_class_entry) &&
    2824         321 :                     ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_exceptions", sizeof("_exceptions")-1)) == NULL ||
    2825             :                            Z_TYPE_P(tmp) != IS_FALSE)) {
    2826             :                         Z_ADDREF_P(return_value);
    2827           2 :                         zend_throw_exception_object(return_value);
    2828             :                 }
    2829             : 
    2830           9 :         } zend_catch {
    2831           9 :                 _bailout = 1;
    2832         400 :         } zend_end_try();
    2833             : 
    2834         400 :         if (SOAP_GLOBAL(encoding) != NULL) {
    2835          13 :                 xmlCharEncCloseFunc(SOAP_GLOBAL(encoding));
    2836             :         }
    2837             : 
    2838         400 :         SOAP_GLOBAL(features) = old_features;
    2839         400 :         SOAP_GLOBAL(typemap) = old_typemap;
    2840         400 :         SOAP_GLOBAL(class_map) = old_class_map;
    2841         400 :         SOAP_GLOBAL(encoding) = old_encoding;
    2842         400 :         SOAP_GLOBAL(sdl) = old_sdl;
    2843         400 :         if (_bailout) {
    2844             :                 smart_str_free(&action);
    2845           9 :                 if (request) {
    2846           7 :                         xmlFreeDoc(request);
    2847             :                 }
    2848           9 :                 _bailout = 0;
    2849           9 :                 zend_bailout();
    2850             :         }
    2851           9 :         SOAP_CLIENT_END_CODE();
    2852         392 : }
    2853             : 
    2854           4 : static void verify_soap_headers_array(HashTable *ht)
    2855             : {
    2856             :         zval *tmp;
    2857             : 
    2858          16 :         ZEND_HASH_FOREACH_VAL(ht, tmp) {
    2859          12 :                 if (Z_TYPE_P(tmp) != IS_OBJECT ||
    2860           6 :                     !instanceof_function(Z_OBJCE_P(tmp), soap_header_class_entry)) {
    2861           0 :                         php_error_docref(NULL, E_ERROR, "Invalid SOAP header");
    2862             :                 }
    2863             :         } ZEND_HASH_FOREACH_END();
    2864           4 : }
    2865             : 
    2866             : 
    2867             : /* {{{ proto mixed SoapClient::__call ( string function_name, array arguments [, array options [, array input_headers [, array output_headers]]])
    2868             :    Calls a SOAP function */
    2869         400 : PHP_METHOD(SoapClient, __call)
    2870             : {
    2871         400 :         char *function, *location=NULL, *soap_action = NULL, *uri = NULL;
    2872             :         size_t function_len;
    2873         400 :         int i = 0;
    2874         400 :         HashTable* soap_headers = NULL;
    2875         400 :         zval *options = NULL;
    2876         400 :         zval *headers = NULL;
    2877         400 :         zval *output_headers = NULL;
    2878             :         zval *args;
    2879         400 :         zval *real_args = NULL;
    2880             :         zval *param;
    2881             :         int arg_count;
    2882             :         zval *tmp;
    2883         400 :         zend_bool free_soap_headers = 0;
    2884             :         zval *this_ptr;
    2885             : 
    2886         400 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa|a!zz/",
    2887             :                 &function, &function_len, &args, &options, &headers, &output_headers) == FAILURE) {
    2888           0 :                 return;
    2889             :         }
    2890             : 
    2891         400 :         if (options) {
    2892          60 :                 HashTable *hto = Z_ARRVAL_P(options);
    2893          61 :                 if ((tmp = zend_hash_str_find(hto, "location", sizeof("location")-1)) != NULL &&
    2894             :                         Z_TYPE_P(tmp) == IS_STRING) {
    2895           1 :                         location = Z_STRVAL_P(tmp);
    2896             :                 }
    2897             : 
    2898         118 :                 if ((tmp = zend_hash_str_find(hto, "soapaction", sizeof("soapaction")-1)) != NULL &&
    2899             :                         Z_TYPE_P(tmp) == IS_STRING) {
    2900          58 :                         soap_action = Z_STRVAL_P(tmp);
    2901             :                 }
    2902             : 
    2903         119 :                 if ((tmp = zend_hash_str_find(hto, "uri", sizeof("uri")-1)) != NULL &&
    2904             :                         Z_TYPE_P(tmp) == IS_STRING) {
    2905          59 :                         uri = Z_STRVAL_P(tmp);
    2906             :                 }
    2907             :         }
    2908             : 
    2909         412 :         if (headers == NULL || Z_TYPE_P(headers) == IS_NULL) {
    2910          24 :         } else if (Z_TYPE_P(headers) == IS_ARRAY) {
    2911           2 :                 soap_headers = Z_ARRVAL_P(headers);
    2912           2 :                 verify_soap_headers_array(soap_headers);
    2913           2 :                 free_soap_headers = 0;
    2914          40 :         } else if (Z_TYPE_P(headers) == IS_OBJECT &&
    2915          10 :                    instanceof_function(Z_OBJCE_P(headers), soap_header_class_entry)) {
    2916          10 :             soap_headers = emalloc(sizeof(HashTable));
    2917          10 :                 zend_hash_init(soap_headers, 0, NULL, ZVAL_PTR_DTOR, 0);
    2918          10 :                 zend_hash_next_index_insert(soap_headers, headers);
    2919          10 :                 Z_ADDREF_P(headers);
    2920          10 :                 free_soap_headers = 1;
    2921             :         } else{
    2922           0 :                 php_error_docref(NULL, E_WARNING, "Invalid SOAP header");
    2923           0 :                 return;
    2924             :         }
    2925             : 
    2926             :         /* Add default headers */
    2927         400 :         this_ptr = getThis();
    2928         406 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__default_headers", sizeof("__default_headers")-1)) != NULL && Z_TYPE_P(tmp) == IS_ARRAY) {
    2929           5 :                 HashTable *default_headers = Z_ARRVAL_P(tmp);
    2930           5 :                 if (soap_headers) {
    2931           1 :                         if (!free_soap_headers) {
    2932           1 :                                 soap_headers = zend_array_dup(soap_headers);
    2933           1 :                                 free_soap_headers = 1;
    2934             :                         }
    2935           5 :                         ZEND_HASH_FOREACH_VAL(default_headers, tmp) {
    2936             :                                 Z_ADDREF_P(tmp);
    2937           2 :                                 zend_hash_next_index_insert(soap_headers, tmp);
    2938             :                         } ZEND_HASH_FOREACH_END();
    2939             :                 } else {
    2940           4 :                         soap_headers = Z_ARRVAL_P(tmp);
    2941           4 :                         free_soap_headers = 0;
    2942             :                 }
    2943             :         }
    2944             : 
    2945         400 :         arg_count = zend_hash_num_elements(Z_ARRVAL_P(args));
    2946             : 
    2947         400 :         if (arg_count > 0) {
    2948         356 :                 real_args = safe_emalloc(sizeof(zval), arg_count, 0);
    2949        1248 :                 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), param) {
    2950             :                         /*zval_add_ref(param);*/
    2951         446 :                         ZVAL_COPY_VALUE(&real_args[i], param);
    2952         446 :                         i++;
    2953             :                 } ZEND_HASH_FOREACH_END();
    2954             :         }
    2955         400 :         if (output_headers) {
    2956           0 :                 array_init(output_headers);
    2957             :         }
    2958         400 :         do_soap_call(execute_data, this_ptr, function, function_len, arg_count, real_args, return_value, location, soap_action, uri, soap_headers, output_headers);
    2959         392 :         if (arg_count > 0) {
    2960         348 :                 efree(real_args);
    2961             :         }
    2962             : 
    2963         392 :         if (soap_headers && free_soap_headers) {
    2964          11 :                 zend_hash_destroy(soap_headers);
    2965          11 :                 efree(soap_headers);
    2966             :         }
    2967             : }
    2968             : /* }}} */
    2969             : 
    2970             : 
    2971             : /* {{{ proto array SoapClient::__getFunctions ( void )
    2972             :    Returns list of SOAP functions */
    2973           4 : PHP_METHOD(SoapClient, __getFunctions)
    2974             : {
    2975             :         sdlPtr sdl;
    2976             : 
    2977           4 :         FETCH_THIS_SDL(sdl);
    2978             : 
    2979           4 :         if (zend_parse_parameters_none() == FAILURE) {
    2980           0 :                 return;
    2981             :         }
    2982             : 
    2983           4 :         if (sdl) {
    2984           4 :                 smart_str buf = {0};
    2985             :                 sdlFunctionPtr function;
    2986             : 
    2987           4 :                 array_init(return_value);
    2988          18 :                 ZEND_HASH_FOREACH_PTR(&sdl->functions, function) {
    2989           7 :                         function_to_string(function, &buf);
    2990           7 :                         add_next_index_stringl(return_value, buf.s->val, buf.s->len);
    2991             :                         smart_str_free(&buf);
    2992             :                 } ZEND_HASH_FOREACH_END();
    2993             :         }
    2994             : }
    2995             : /* }}} */
    2996             : 
    2997             : 
    2998             : /* {{{ proto array SoapClient::__getTypes ( void )
    2999             :    Returns list of SOAP types */
    3000           4 : PHP_METHOD(SoapClient, __getTypes)
    3001             : {
    3002             :         sdlPtr sdl;
    3003             : 
    3004           4 :         FETCH_THIS_SDL(sdl);
    3005             : 
    3006           4 :         if (zend_parse_parameters_none() == FAILURE) {
    3007           0 :                 return;
    3008             :         }
    3009             : 
    3010           4 :         if (sdl) {
    3011             :                 sdlTypePtr type;
    3012           4 :                 smart_str buf = {0};
    3013             : 
    3014           4 :                 array_init(return_value);
    3015           4 :                 if (sdl->types) {
    3016         108 :                         ZEND_HASH_FOREACH_PTR(sdl->types, type) {
    3017          52 :                                 type_to_string(type, &buf, 0);
    3018          52 :                                 add_next_index_stringl(return_value, buf.s->val, buf.s->len);
    3019             :                                 smart_str_free(&buf);
    3020             :                         } ZEND_HASH_FOREACH_END();
    3021             :                 }
    3022             :         }
    3023             : }
    3024             : /* }}} */
    3025             : 
    3026             : 
    3027             : /* {{{ proto string SoapClient::__getLastRequest ( void )
    3028             :    Returns last SOAP request */
    3029         529 : PHP_METHOD(SoapClient, __getLastRequest)
    3030             : {
    3031             :         zval *tmp;
    3032             : 
    3033         529 :         if (zend_parse_parameters_none() == FAILURE) {
    3034           0 :                 return;
    3035             :         }
    3036             : 
    3037        1058 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()), "__last_request", sizeof("__last_request")-1)) != NULL &&
    3038             :             Z_TYPE_P(tmp) == IS_STRING) {
    3039         529 :                 RETURN_STR_COPY(Z_STR_P(tmp));
    3040             :         }
    3041           0 :         RETURN_NULL();
    3042             : }
    3043             : /* }}} */
    3044             : 
    3045             : 
    3046             : /* {{{ proto object SoapClient::__getLastResponse ( void )
    3047             :    Returns last SOAP response */
    3048           6 : PHP_METHOD(SoapClient, __getLastResponse)
    3049             : {
    3050             :         zval *tmp;
    3051             : 
    3052           6 :         if (zend_parse_parameters_none() == FAILURE) {
    3053           0 :                 return;
    3054             :         }
    3055             : 
    3056          12 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()), "__last_response", sizeof("__last_response")-1)) != NULL &&
    3057             :             Z_TYPE_P(tmp) == IS_STRING) {
    3058           6 :                 RETURN_STR_COPY(Z_STR_P(tmp));
    3059             :         }
    3060           0 :         RETURN_NULL();
    3061             : }
    3062             : /* }}} */
    3063             : 
    3064             : 
    3065             : /* {{{ proto string SoapClient::__getLastRequestHeaders(void)
    3066             :    Returns last SOAP request headers */
    3067           0 : PHP_METHOD(SoapClient, __getLastRequestHeaders)
    3068             : {
    3069             :         zval *tmp;
    3070             : 
    3071           0 :         if (zend_parse_parameters_none() == FAILURE) {
    3072           0 :                 return;
    3073             :         }
    3074             : 
    3075           0 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()), "__last_request_headers", sizeof("__last_request_headers")-1)) != NULL &&
    3076             :             Z_TYPE_P(tmp) == IS_STRING) {
    3077           0 :                 RETURN_STR_COPY(Z_STR_P(tmp));
    3078             :         }
    3079           0 :         RETURN_NULL();
    3080             : }
    3081             : /* }}} */
    3082             : 
    3083             : 
    3084             : /* {{{ proto string SoapClient::__getLastResponseHeaders(void)
    3085             :    Returns last SOAP response headers */
    3086           0 : PHP_METHOD(SoapClient, __getLastResponseHeaders)
    3087             : {
    3088             :         zval *tmp;
    3089             : 
    3090           0 :         if (zend_parse_parameters_none() == FAILURE) {
    3091           0 :                 return;
    3092             :         }
    3093             : 
    3094           0 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()), "__last_response_headers", sizeof("__last_response_headers")-1)) != NULL &&
    3095             :             Z_TYPE_P(tmp) == IS_STRING) {
    3096           0 :                 RETURN_STR_COPY(Z_STR_P(tmp));
    3097             :         }
    3098           0 :         RETURN_NULL();
    3099             : }
    3100             : /* }}} */
    3101             : 
    3102             : 
    3103             : /* {{{ proto string SoapClient::__doRequest()
    3104             :    SoapClient::__doRequest() */
    3105         318 : PHP_METHOD(SoapClient, __doRequest)
    3106             : {
    3107             :   char *buf, *location, *action;
    3108             :   size_t   buf_size, location_size, action_size;
    3109             :   zend_long  version;
    3110         318 :   zend_long  one_way = 0;
    3111         318 :   zval *this_ptr = getThis();
    3112             : 
    3113         318 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "sssl|l",
    3114             :             &buf, &buf_size,
    3115             :             &location, &location_size,
    3116             :             &action, &action_size,
    3117             :             &version, &one_way) == FAILURE) {
    3118           0 :                 return;
    3119             :         }
    3120         318 :         if (SOAP_GLOBAL(features) & SOAP_WAIT_ONE_WAY_CALLS) {
    3121           0 :                 one_way = 0;
    3122             :         }
    3123         318 :         if (one_way) {
    3124          85 :                 if (make_http_soap_request(this_ptr, buf, buf_size, location, action, version, NULL)) {
    3125           0 :                         RETURN_EMPTY_STRING();
    3126             :                 }
    3127         233 :         } else if (make_http_soap_request(this_ptr, buf, buf_size, location, action, version,
    3128             :             return_value)) {
    3129           1 :                 return;
    3130             :         }
    3131         317 :         RETURN_NULL();
    3132             : }
    3133             : /* }}} */
    3134             : 
    3135             : /* {{{ proto void SoapClient::__setCookie(string name [, strung value])
    3136             :    Sets cookie thet will sent with SOAP request.
    3137             :    The call to this function will effect all following calls of SOAP methods.
    3138             :    If value is not specified cookie is removed. */
    3139           1 : PHP_METHOD(SoapClient, __setCookie)
    3140             : {
    3141             :         char *name;
    3142           1 :         char *val = NULL;
    3143           1 :         size_t  name_len, val_len = 0;
    3144             :         zval *cookies;
    3145           1 :         zval *this_ptr = getThis();
    3146             : 
    3147           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &val, &val_len) == FAILURE) {
    3148           0 :                 return;
    3149             :         }
    3150             : 
    3151           1 :         if (val == NULL) {
    3152           0 :                 if ((cookies = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1)) != NULL &&
    3153             :                     Z_TYPE_P(cookies) == IS_ARRAY) {
    3154           0 :                         zend_hash_str_del(Z_ARRVAL_P(cookies), name, name_len);
    3155             :                 }
    3156             :         } else {
    3157             :                 zval zcookie;
    3158             : 
    3159           1 :                 if ((cookies = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1)) == NULL ||
    3160             :                     Z_TYPE_P(cookies) != IS_ARRAY) {
    3161             :                         zval tmp_cookies;
    3162             : 
    3163           1 :                         array_init(&tmp_cookies);
    3164           1 :                         cookies = zend_hash_str_update(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1, &tmp_cookies);
    3165             :                 }
    3166             : 
    3167           1 :                 array_init(&zcookie);
    3168           1 :                 add_index_stringl(&zcookie, 0, val, val_len);
    3169           1 :                 add_assoc_zval_ex(cookies, name, name_len, &zcookie);
    3170             :         }
    3171             : }
    3172             : /* }}} */
    3173             : 
    3174             : /* {{{ proto array SoapClient::__getCookies ( void )
    3175             :    Returns list of cookies */
    3176           1 : PHP_METHOD(SoapClient, __getCookies)
    3177             : {
    3178             :         zval *cookies;
    3179             : 
    3180           1 :         if (zend_parse_parameters_none() == FAILURE) {
    3181           0 :                 return;
    3182             :         }
    3183             : 
    3184             : 
    3185           2 :         if ((cookies = zend_hash_str_find(Z_OBJPROP_P(getThis()), "_cookies", sizeof("_cookies")-1)) != NULL &&
    3186             :             Z_TYPE_P(cookies) == IS_ARRAY) {
    3187           1 :                 RETURN_ARR(zend_array_dup(Z_ARRVAL_P(cookies)));
    3188             :         } else {
    3189           0 :                 array_init(return_value);
    3190             :         }
    3191             : }
    3192             : /* }}} */
    3193             : 
    3194             : /* {{{ proto void SoapClient::__setSoapHeaders(array SoapHeaders)
    3195             :    Sets SOAP headers for subsequent calls (replaces any previous
    3196             :    values).
    3197             :    If no value is specified, all of the headers are removed. */
    3198           4 : PHP_METHOD(SoapClient, __setSoapHeaders)
    3199             : {
    3200           4 :         zval *headers = NULL;
    3201           4 :         zval *this_ptr = getThis();
    3202             : 
    3203           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &headers) == FAILURE) {
    3204           0 :                 return;
    3205             :         }
    3206             : 
    3207           8 :         if (headers == NULL || Z_TYPE_P(headers) == IS_NULL) {
    3208           1 :                 zend_hash_str_del(Z_OBJPROP_P(this_ptr), "__default_headers", sizeof("__default_headers")-1);
    3209           6 :         } else if (Z_TYPE_P(headers) == IS_ARRAY) {
    3210             :                 zval *default_headers;
    3211             : 
    3212           2 :                 verify_soap_headers_array(Z_ARRVAL_P(headers));
    3213           2 :                 if ((default_headers = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__default_headers", sizeof("__default_headers")-1)) == NULL) {
    3214           2 :                         add_property_zval(this_ptr, "__default_headers", headers);
    3215             :                 }
    3216           4 :         } else if (Z_TYPE_P(headers) == IS_OBJECT &&
    3217           1 :                    instanceof_function(Z_OBJCE_P(headers), soap_header_class_entry)) {
    3218             :                 zval default_headers;
    3219             : 
    3220           1 :                 array_init(&default_headers);
    3221           1 :                 Z_ADDREF_P(headers);
    3222           1 :                 add_next_index_zval(&default_headers, headers);
    3223           1 :                 add_property_zval(this_ptr, "__default_headers", &default_headers);
    3224             :                 Z_DELREF_P(&default_headers);
    3225             :         } else{
    3226           0 :                 php_error_docref(NULL, E_WARNING, "Invalid SOAP header");
    3227             :         }
    3228           4 :         RETURN_TRUE;
    3229             : }
    3230             : /* }}} */
    3231             : 
    3232             : 
    3233             : 
    3234             : /* {{{ proto string SoapClient::__setLocation([string new_location])
    3235             :    Sets the location option (the endpoint URL that will be touched by the
    3236             :    following SOAP requests).
    3237             :    If new_location is not specified or null then SoapClient will use endpoint
    3238             :    from WSDL file.
    3239             :    The function returns old value of location options. */
    3240           6 : PHP_METHOD(SoapClient, __setLocation)
    3241             : {
    3242           6 :         char *location = NULL;
    3243           6 :         size_t  location_len = 0;
    3244             :         zval *tmp;
    3245           6 :         zval *this_ptr = getThis();
    3246             : 
    3247           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &location, &location_len) == FAILURE) {
    3248           0 :                 return;
    3249             :         }
    3250             : 
    3251          14 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "location", sizeof("location")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) {
    3252           4 :                 RETVAL_STR_COPY(Z_STR_P(tmp));
    3253             :         } else {
    3254           2 :                 RETVAL_NULL();
    3255             :         }
    3256             : 
    3257           9 :         if (location && location_len) {
    3258           3 :                 add_property_stringl(this_ptr, "location", location, location_len);
    3259             :         } else {
    3260           3 :                 zend_hash_str_del(Z_OBJPROP_P(this_ptr), "location", sizeof("location")-1);
    3261             :         }
    3262             : }
    3263             : /* }}} */
    3264             : 
    3265         400 : static void clear_soap_fault(zval *obj)
    3266             : {
    3267         800 :         if (obj != NULL && Z_TYPE_P(obj) == IS_OBJECT) {
    3268         400 :                 zend_hash_str_del(Z_OBJPROP_P(obj), "__soap_fault", sizeof("__soap_fault")-1);
    3269             :         }
    3270         400 : }
    3271             : 
    3272           8 : static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail)
    3273             : {
    3274           8 :         ZVAL_NULL(fault);
    3275           8 :         set_soap_fault(fault, NULL, fault_code, fault_string, fault_actor, fault_detail, NULL);
    3276           8 :         add_property_zval(obj, "__soap_fault", fault);
    3277             :         Z_DELREF_P(fault);
    3278           8 : }
    3279             : 
    3280         322 : void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail)
    3281             : {
    3282             :         zval fault;
    3283             : 
    3284         322 :         ZVAL_NULL(&fault);
    3285         322 :         set_soap_fault(&fault, NULL, fault_code, fault_string, fault_actor, fault_detail, NULL);
    3286         322 :         add_property_zval(obj, "__soap_fault", &fault);
    3287             :         Z_DELREF(fault);
    3288         322 : }
    3289             : 
    3290         429 : static void set_soap_fault(zval *obj, char *fault_code_ns, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, char *name)
    3291             : {
    3292         429 :         if (Z_TYPE_P(obj) != IS_OBJECT) {
    3293         361 :                 object_init_ex(obj, soap_fault_class_entry);
    3294             :         }
    3295             : 
    3296         429 :         add_property_string(obj, "faultstring", fault_string ? fault_string : "");
    3297         429 :         zend_update_property_string(zend_exception_get_default(), obj, "message", sizeof("message")-1, (fault_string ? fault_string : ""));
    3298             : 
    3299         429 :         if (fault_code != NULL) {
    3300         429 :                 int soap_version = SOAP_GLOBAL(soap_version);
    3301             : 
    3302         429 :                 if (fault_code_ns) {
    3303           0 :                         add_property_string(obj, "faultcode", fault_code);
    3304           0 :                         add_property_string(obj, "faultcodens", fault_code_ns);
    3305             :                 } else {
    3306         429 :                         if (soap_version == SOAP_1_1) {
    3307         401 :                                 add_property_string(obj, "faultcode", fault_code);
    3308        1454 :                                 if (strcmp(fault_code,"Client") == 0 ||
    3309         394 :                                     strcmp(fault_code,"Server") == 0 ||
    3310         330 :                                     strcmp(fault_code,"VersionMismatch") == 0 ||
    3311         329 :                                   strcmp(fault_code,"MustUnderstand") == 0) {
    3312          73 :                                         add_property_string(obj, "faultcodens", SOAP_1_1_ENV_NAMESPACE);
    3313             :                                 }
    3314          28 :                         } else if (soap_version == SOAP_1_2) {
    3315          28 :                                 if (strcmp(fault_code,"Client") == 0) {
    3316           9 :                                         add_property_string(obj, "faultcode", "Sender");
    3317           9 :                                         add_property_string(obj, "faultcodens", SOAP_1_2_ENV_NAMESPACE);
    3318          19 :                                 } else if (strcmp(fault_code,"Server") == 0) {
    3319           8 :                                         add_property_string(obj, "faultcode", "Receiver");
    3320           8 :                                         add_property_string(obj, "faultcodens", SOAP_1_2_ENV_NAMESPACE);
    3321          33 :                                 } else if (strcmp(fault_code,"VersionMismatch") == 0 ||
    3322          10 :                                            strcmp(fault_code,"MustUnderstand") == 0 ||
    3323           6 :                                            strcmp(fault_code,"DataEncodingUnknown") == 0) {
    3324           6 :                                         add_property_string(obj, "faultcode", fault_code);
    3325           6 :                                         add_property_string(obj, "faultcodens", SOAP_1_2_ENV_NAMESPACE);
    3326             :                                 } else {
    3327           5 :                                         add_property_string(obj, "faultcode", fault_code);
    3328             :                                 }
    3329             :                         }
    3330             :                 }
    3331             :         }
    3332         429 :         if (fault_actor != NULL) {
    3333           0 :                 add_property_string(obj, "faultactor", fault_actor);
    3334             :         }
    3335         488 :         if (fault_detail != NULL && Z_TYPE_P(fault_detail) != IS_UNDEF) {
    3336          50 :                 add_property_zval(obj, "detail", fault_detail);
    3337             :         }
    3338         429 :         if (name != NULL) {
    3339          54 :                 add_property_string(obj, "_name", name);
    3340             :         }
    3341         429 : }
    3342             : 
    3343         484 : static void deserialize_parameters(xmlNodePtr params, sdlFunctionPtr function, int *num_params, zval **parameters)
    3344             : {
    3345         484 :         int cur_param = 0,num_of_params = 0;
    3346         484 :         zval *tmp_parameters = NULL;
    3347             : 
    3348         484 :         if (function != NULL) {
    3349             :                 sdlParamPtr param;
    3350             :                 xmlNodePtr val;
    3351         414 :                 int     use_names = 0;
    3352             : 
    3353         414 :                 if (function->requestParameters == NULL) {
    3354           0 :                         return;
    3355             :                 }
    3356         414 :                 num_of_params = zend_hash_num_elements(function->requestParameters);
    3357        1274 :                 ZEND_HASH_FOREACH_PTR(function->requestParameters, param) {
    3358         430 :                         if (get_node(params, param->paramName) != NULL) {
    3359         309 :                                 use_names = 1;
    3360             :                         }
    3361             :                 } ZEND_HASH_FOREACH_END();
    3362         414 :                 if (use_names) {
    3363         252 :                         tmp_parameters = safe_emalloc(num_of_params, sizeof(zval), 0);
    3364         865 :                         ZEND_HASH_FOREACH_PTR(function->requestParameters, param) {
    3365         309 :                                 val = get_node(params, param->paramName);
    3366         309 :                                 if (!val) {
    3367             :                                         /* TODO: may be "nil" is not OK? */
    3368           0 :                                         ZVAL_NULL(&tmp_parameters[cur_param]);
    3369             :                                 } else {
    3370         309 :                                         master_to_zval(&tmp_parameters[cur_param], param->encode, val);
    3371             :                                 }
    3372         304 :                                 cur_param++;
    3373             :                         } ZEND_HASH_FOREACH_END();
    3374         247 :                         *parameters = tmp_parameters;
    3375         247 :                         *num_params = num_of_params;
    3376         247 :                         return;
    3377             :                 }
    3378             :         }
    3379         232 :         if (params) {
    3380             :                 xmlNodePtr trav;
    3381             : 
    3382         157 :                 num_of_params = 0;
    3383         157 :                 trav = params;
    3384         491 :                 while (trav != NULL) {
    3385         177 :                         if (trav->type == XML_ELEMENT_NODE) {
    3386         175 :                                 num_of_params++;
    3387             :                         }
    3388         177 :                         trav = trav->next;
    3389             :                 }
    3390             : 
    3391         687 :                 if (num_of_params == 1 &&
    3392             :                     function &&
    3393         118 :                     function->binding &&
    3394         118 :                     function->binding->bindingType == BINDING_SOAP &&
    3395         118 :                     ((sdlSoapBindingFunctionPtr)function->bindingAttributes)->style == SOAP_DOCUMENT &&
    3396          87 :                     (function->requestParameters == NULL ||
    3397          87 :                      zend_hash_num_elements(function->requestParameters) == 0) &&
    3398           1 :                     strcmp((char *)params->name, function->functionName) == 0) {
    3399           1 :                         num_of_params = 0;
    3400         156 :                 } else if (num_of_params > 0) {
    3401         154 :                         tmp_parameters = safe_emalloc(num_of_params, sizeof(zval), 0);
    3402             : 
    3403         154 :                         trav = params;
    3404         481 :                         while (trav != 0 && cur_param < num_of_params) {
    3405         174 :                                 if (trav->type == XML_ELEMENT_NODE) {
    3406             :                                         encodePtr enc;
    3407         174 :                                         sdlParamPtr param = NULL;
    3408         294 :                                         if (function != NULL &&
    3409         120 :                                             (param = zend_hash_index_find_ptr(function->requestParameters, cur_param)) == NULL) {
    3410           0 :                                                                                         soap_server_fault("Client", "Error cannot find parameter", NULL, NULL, NULL);
    3411             :                                         }
    3412         174 :                                         if (param == NULL) {
    3413          54 :                                                 enc = NULL;
    3414             :                                         } else {
    3415         120 :                                                 enc = param->encode;
    3416             :                                         }
    3417         174 :                                         master_to_zval(&tmp_parameters[cur_param], enc, trav);
    3418         173 :                                         cur_param++;
    3419             :                                 }
    3420         173 :                                 trav = trav->next;
    3421             :                         }
    3422             :                 }
    3423             :         }
    3424         231 :         if (num_of_params > cur_param) {
    3425           0 :                 soap_server_fault("Client","Missing parameter", NULL, NULL, NULL);
    3426             :         }
    3427         231 :         (*parameters) = tmp_parameters;
    3428         231 :         (*num_params) = num_of_params;
    3429             : }
    3430             : 
    3431         479 : static sdlFunctionPtr find_function(sdlPtr sdl, xmlNodePtr func, zval* function_name)
    3432             : {
    3433             :         sdlFunctionPtr function;
    3434             : 
    3435         479 :         function = get_function(sdl, (char*)func->name);
    3436         479 :         if (function && function->binding && function->binding->bindingType == BINDING_SOAP) {
    3437         339 :                 sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
    3438         339 :                 if (fnb->style == SOAP_DOCUMENT) {
    3439          90 :                         if (func->children != NULL ||
    3440          13 :                             (function->requestParameters != NULL &&
    3441          13 :                              zend_hash_num_elements(function->requestParameters) > 0)) {
    3442          63 :                                 function = NULL;
    3443             :                         }
    3444             :                 }
    3445             :         }
    3446         479 :         if (sdl != NULL && function == NULL) {
    3447         140 :                 function = get_doc_function(sdl, func);
    3448             :         }
    3449             : 
    3450         479 :         if (function != NULL) {
    3451         774 :                 ZVAL_STRING(function_name, (char *)function->functionName);
    3452             :         } else {
    3453         184 :                 ZVAL_STRING(function_name, (char *)func->name);
    3454             :         }
    3455             : 
    3456         479 :         return function;
    3457             : }
    3458             : 
    3459         473 : static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, char* actor, zval *function_name, int *num_params, zval **parameters, int *version, soapHeader **headers)
    3460             : {
    3461         473 :         char* envelope_ns = NULL;
    3462             :         xmlNodePtr trav,env,head,body,func;
    3463             :         xmlAttrPtr attr;
    3464             :         sdlFunctionPtr function;
    3465             : 
    3466         473 :         encode_reset_ns();
    3467             : 
    3468             :         /* Get <Envelope> element */
    3469         473 :         env = NULL;
    3470         473 :         trav = request->children;
    3471        1417 :         while (trav != NULL) {
    3472         473 :                 if (trav->type == XML_ELEMENT_NODE) {
    3473         872 :                         if (env == NULL && node_is_equal_ex(trav,"Envelope",SOAP_1_1_ENV_NAMESPACE)) {
    3474         399 :                                 env = trav;
    3475         399 :                                 *version = SOAP_1_1;
    3476         399 :                                 envelope_ns = SOAP_1_1_ENV_NAMESPACE;
    3477         399 :                                 SOAP_GLOBAL(soap_version) = SOAP_1_1;
    3478         146 :                         } else if (env == NULL && node_is_equal_ex(trav,"Envelope",SOAP_1_2_ENV_NAMESPACE)) {
    3479          72 :                                 env = trav;
    3480          72 :                                 *version = SOAP_1_2;
    3481          72 :                                 envelope_ns = SOAP_1_2_ENV_NAMESPACE;
    3482          72 :                                 SOAP_GLOBAL(soap_version) = SOAP_1_2;
    3483             :                         } else {
    3484           2 :                                 soap_server_fault("VersionMismatch", "Wrong Version", NULL, NULL, NULL);
    3485             :                         }
    3486             :                 }
    3487         471 :                 trav = trav->next;
    3488             :         }
    3489         471 :         if (env == NULL) {
    3490           0 :                 soap_server_fault("Client", "looks like we got XML without \"Envelope\" element", NULL, NULL, NULL);
    3491             :         }
    3492             : 
    3493         471 :         attr = env->properties;
    3494        1224 :         while (attr != NULL) {
    3495         284 :                 if (attr->ns == NULL) {
    3496           1 :                         soap_server_fault("Client", "A SOAP Envelope element cannot have non Namespace qualified attributes", NULL, NULL, NULL);
    3497         283 :                 } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) {
    3498           1 :                         if (*version == SOAP_1_2) {
    3499           1 :                                 soap_server_fault("Client", "encodingStyle cannot be specified on the Envelope", NULL, NULL, NULL);
    3500           0 :                         } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
    3501           0 :                                 soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL);
    3502             :                         }
    3503             :                 }
    3504         282 :                 attr = attr->next;
    3505             :         }
    3506             : 
    3507             :         /* Get <Header> element */
    3508         469 :         head = NULL;
    3509         469 :         trav = env->children;
    3510         939 :         while (trav != NULL && trav->type != XML_ELEMENT_NODE) {
    3511           1 :                 trav = trav->next;
    3512             :         }
    3513         469 :         if (trav != NULL && node_is_equal_ex(trav,"Header",envelope_ns)) {
    3514          49 :                 head = trav;
    3515          49 :                 trav = trav->next;
    3516             :         }
    3517             : 
    3518             :         /* Get <Body> element */
    3519         469 :         body = NULL;
    3520         938 :         while (trav != NULL && trav->type != XML_ELEMENT_NODE) {
    3521           0 :                 trav = trav->next;
    3522             :         }
    3523         469 :         if (trav != NULL && node_is_equal_ex(trav,"Body",envelope_ns)) {
    3524         468 :                 body = trav;
    3525         468 :                 trav = trav->next;
    3526             :         }
    3527         938 :         while (trav != NULL && trav->type != XML_ELEMENT_NODE) {
    3528           0 :                 trav = trav->next;
    3529             :         }
    3530         469 :         if (body == NULL) {
    3531           1 :                 soap_server_fault("Client", "Body must be present in a SOAP envelope", NULL, NULL, NULL);
    3532             :         }
    3533         468 :         attr = body->properties;
    3534         937 :         while (attr != NULL) {
    3535           2 :                 if (attr->ns == NULL) {
    3536           0 :                         if (*version == SOAP_1_2) {
    3537           0 :                                 soap_server_fault("Client", "A SOAP Body element cannot have non Namespace qualified attributes", NULL, NULL, NULL);
    3538             :                         }
    3539           2 :                 } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) {
    3540           1 :                         if (*version == SOAP_1_2) {
    3541           1 :                                 soap_server_fault("Client", "encodingStyle cannot be specified on the Body", NULL, NULL, NULL);
    3542           0 :                         } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
    3543           0 :                                 soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL);
    3544             :                         }
    3545             :                 }
    3546           1 :                 attr = attr->next;
    3547             :         }
    3548             : 
    3549         467 :         if (trav != NULL && *version == SOAP_1_2) {
    3550           1 :                 soap_server_fault("Client", "A SOAP 1.2 envelope can contain only Header and Body", NULL, NULL, NULL);
    3551             :         }
    3552             : 
    3553         466 :         func = NULL;
    3554         466 :         trav = body->children;
    3555         961 :         while (trav != NULL) {
    3556         465 :                 if (trav->type == XML_ELEMENT_NODE) {
    3557             : /*
    3558             :                         if (func != NULL) {
    3559             :                                 soap_server_fault("Client", "looks like we got \"Body\" with several functions call", NULL, NULL, NULL);
    3560             :                         }
    3561             : */
    3562         436 :                         func = trav;
    3563         436 :                         break; /* FIXME: the rest of body is ignored */
    3564             :                 }
    3565          29 :                 trav = trav->next;
    3566             :         }
    3567         466 :         if (func == NULL) {
    3568          30 :                 function = get_doc_function(sdl, NULL);
    3569          30 :                 if (function != NULL) {
    3570          60 :                         ZVAL_STRING(function_name, (char *)function->functionName);
    3571             :                 } else {
    3572           0 :                         soap_server_fault("Client", "looks like we got \"Body\" without function call", NULL, NULL, NULL);
    3573             :                 }
    3574             :         } else {
    3575         436 :                 if (*version == SOAP_1_1) {
    3576         398 :                         attr = get_attribute_ex(func->properties,"encodingStyle",SOAP_1_1_ENV_NAMESPACE);
    3577         398 :                         if (attr && strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
    3578           0 :                                 soap_server_fault("Client","Unknown Data Encoding Style", NULL, NULL, NULL);
    3579             :                         }
    3580             :                 } else {
    3581          38 :                         attr = get_attribute_ex(func->properties,"encodingStyle",SOAP_1_2_ENV_NAMESPACE);
    3582          38 :                         if (attr && strcmp((char*)attr->children->content,SOAP_1_2_ENC_NAMESPACE) != 0) {
    3583           1 :                                 soap_server_fault("DataEncodingUnknown","Unknown Data Encoding Style", NULL, NULL, NULL);
    3584             :                         }
    3585             :                 }
    3586         435 :                 function = find_function(sdl, func, function_name);
    3587         435 :                 if (sdl != NULL && function == NULL) {
    3588           1 :                         if (*version == SOAP_1_2) {
    3589           1 :                                 soap_server_fault("rpc:ProcedureNotPresent","Procedure not present", NULL, NULL, NULL);
    3590             :                         } else {
    3591           0 :                                 php_error(E_ERROR, "Procedure '%s' not present", func->name);
    3592             :                         }
    3593             :                 }
    3594             :         }
    3595             : 
    3596         464 :         *headers = NULL;
    3597         464 :         if (head) {
    3598          47 :                 soapHeader *h, *last = NULL;
    3599             : 
    3600          47 :                 attr = head->properties;
    3601          94 :                 while (attr != NULL) {
    3602           0 :                         if (attr->ns == NULL) {
    3603           0 :                                 soap_server_fault("Client", "A SOAP Header element cannot have non Namespace qualified attributes", NULL, NULL, NULL);
    3604           0 :                         } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) {
    3605           0 :                                 if (*version == SOAP_1_2) {
    3606           0 :                                         soap_server_fault("Client", "encodingStyle cannot be specified on the Header", NULL, NULL, NULL);
    3607           0 :                                 } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
    3608           0 :                                         soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL);
    3609             :                                 }
    3610             :                         }
    3611           0 :                         attr = attr->next;
    3612             :                 }
    3613          47 :                 trav = head->children;
    3614         142 :                 while (trav != NULL) {
    3615          51 :                         if (trav->type == XML_ELEMENT_NODE) {
    3616          51 :                                 xmlNodePtr hdr_func = trav;
    3617          51 :                                 int mustUnderstand = 0;
    3618             : 
    3619          51 :                                 if (*version == SOAP_1_1) {
    3620          13 :                                         attr = get_attribute_ex(hdr_func->properties,"encodingStyle",SOAP_1_1_ENV_NAMESPACE);
    3621          13 :                                         if (attr && strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
    3622           0 :                                                 soap_server_fault("Client","Unknown Data Encoding Style", NULL, NULL, NULL);
    3623             :                                         }
    3624          13 :                                         attr = get_attribute_ex(hdr_func->properties,"actor",envelope_ns);
    3625          13 :                                         if (attr != NULL) {
    3626           2 :                                                 if (strcmp((char*)attr->children->content,SOAP_1_1_ACTOR_NEXT) != 0 &&
    3627           0 :                                                     (actor == NULL || strcmp((char*)attr->children->content,actor) != 0)) {
    3628             :                                                   goto ignore_header;
    3629             :                                                 }
    3630             :                                         }
    3631          38 :                                 } else if (*version == SOAP_1_2) {
    3632          38 :                                         attr = get_attribute_ex(hdr_func->properties,"encodingStyle",SOAP_1_2_ENV_NAMESPACE);
    3633          38 :                                         if (attr && strcmp((char*)attr->children->content,SOAP_1_2_ENC_NAMESPACE) != 0) {
    3634           0 :                                                 soap_server_fault("DataEncodingUnknown","Unknown Data Encoding Style", NULL, NULL, NULL);
    3635             :                                         }
    3636          38 :                                         attr = get_attribute_ex(hdr_func->properties,"role",envelope_ns);
    3637          38 :                                         if (attr != NULL) {
    3638          52 :                                                 if (strcmp((char*)attr->children->content,SOAP_1_2_ACTOR_UNLIMATERECEIVER) != 0 &&
    3639          16 :                                                     strcmp((char*)attr->children->content,SOAP_1_2_ACTOR_NEXT) != 0 &&
    3640          10 :                                                     (actor == NULL || strcmp((char*)attr->children->content,actor) != 0)) {
    3641             :                                                   goto ignore_header;
    3642             :                                                 }
    3643             :                                         }
    3644             :                                 }
    3645          47 :                                 attr = get_attribute_ex(hdr_func->properties,"mustUnderstand",envelope_ns);
    3646          47 :                                 if (attr) {
    3647          53 :                                         if (strcmp((char*)attr->children->content,"1") == 0 ||
    3648          10 :                                             strcmp((char*)attr->children->content,"true") == 0) {
    3649          18 :                                                 mustUnderstand = 1;
    3650          17 :                                         } else if (strcmp((char*)attr->children->content,"0") == 0 ||
    3651           6 :                                                    strcmp((char*)attr->children->content,"false") == 0) {
    3652           4 :                                                 mustUnderstand = 0;
    3653             :                                         } else {
    3654           3 :                                                 soap_server_fault("Client","mustUnderstand value is not boolean", NULL, NULL, NULL);
    3655             :                                         }
    3656             :                                 }
    3657          44 :                                 h = emalloc(sizeof(soapHeader));
    3658          44 :                                 memset(h, 0, sizeof(soapHeader));
    3659          44 :                                 h->mustUnderstand = mustUnderstand;
    3660          44 :                                 h->function = find_function(sdl, hdr_func, &h->function_name);
    3661          44 :                                 if (!h->function && sdl && function && function->binding && function->binding->bindingType == BINDING_SOAP) {
    3662             :                                         sdlSoapBindingFunctionHeaderPtr hdr;
    3663          28 :                                         sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
    3664          28 :                                         if (fnb->input.headers) {
    3665          23 :                                                 smart_str key = {0};
    3666             : 
    3667          23 :                                                 if (hdr_func->ns) {
    3668          23 :                                                         smart_str_appends(&key, (char*)hdr_func->ns->href);
    3669             :                                                         smart_str_appendc(&key, ':');
    3670             :                                                 }
    3671          23 :                                                 smart_str_appendl(&key, Z_STRVAL(h->function_name), Z_STRLEN(h->function_name));
    3672             :                                                 smart_str_0(&key);
    3673          46 :                                                 if ((hdr = zend_hash_find_ptr(fnb->input.headers, key.s)) != NULL) {
    3674          21 :                                                         h->hdr = hdr;
    3675             :                                                 }
    3676             :                                                 smart_str_free(&key);
    3677             :                                         }
    3678             :                                 }
    3679          44 :                                 if (h->hdr) {
    3680          21 :                                         h->num_params = 1;
    3681          21 :                                         h->parameters = emalloc(sizeof(zval));
    3682          21 :                                         master_to_zval(&h->parameters[0], h->hdr->encode, hdr_func);
    3683             :                                 } else {
    3684          23 :                                         if (h->function && h->function->binding && h->function->binding->bindingType == BINDING_SOAP) {
    3685          15 :                                                 sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)h->function->bindingAttributes;
    3686          15 :                                                 if (fnb->style == SOAP_RPC) {
    3687           0 :                                                         hdr_func = hdr_func->children;
    3688             :                                                 }
    3689             :                                         }
    3690          23 :                                         deserialize_parameters(hdr_func, h->function, &h->num_params, &h->parameters);
    3691             :                                 }
    3692          44 :                                 ZVAL_NULL(&h->retval);
    3693          44 :                                 if (last == NULL) {
    3694          40 :                                         *headers = h;
    3695             :                                 } else {
    3696           4 :                                         last->next = h;
    3697             :                                 }
    3698          44 :                                 last = h;
    3699             :                         }
    3700             : ignore_header:
    3701          48 :                         trav = trav->next;
    3702             :                 }
    3703             :         }
    3704             : 
    3705         860 :         if (function && function->binding && function->binding->bindingType == BINDING_SOAP) {
    3706         399 :                 sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
    3707         399 :                 if (fnb->style == SOAP_RPC) {
    3708         275 :                         func = func->children;
    3709             :                 }
    3710             :         } else {
    3711          62 :                 func = func->children;
    3712             :         }
    3713         461 :         deserialize_parameters(func, function, num_params, parameters);
    3714             : 
    3715         455 :         encode_finish();
    3716             : 
    3717         455 :         return function;
    3718             : }
    3719             : 
    3720          32 : static void set_soap_header_attributes(xmlNodePtr h, HashTable *ht, int version)
    3721             : {
    3722             :         zval *tmp;
    3723             : 
    3724          64 :         if ((tmp = zend_hash_str_find(ht, "mustUnderstand", sizeof("mustUnderstand")-1)) != NULL &&
    3725             :             Z_TYPE_P(tmp) == IS_TRUE) {
    3726           8 :                 if (version == SOAP_1_1) {
    3727           8 :                         xmlSetProp(h, BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":mustUnderstand"), BAD_CAST("1"));
    3728             :                 } else {
    3729           0 :                         xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":mustUnderstand"), BAD_CAST("true"));
    3730             :                 }
    3731             :         }
    3732          32 :         if ((tmp = zend_hash_str_find(ht, "actor", sizeof("actor")-1)) != NULL) {
    3733           2 :                 if (Z_TYPE_P(tmp) == IS_STRING) {
    3734           0 :                         if (version == SOAP_1_1) {
    3735           0 :                                 xmlSetProp(h, BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":actor"), BAD_CAST(Z_STRVAL_P(tmp)));
    3736             :                         } else {
    3737           0 :                                 xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(Z_STRVAL_P(tmp)));
    3738             :                         }
    3739           2 :                 } else if (Z_TYPE_P(tmp) == IS_LONG) {
    3740           2 :                         if (version == SOAP_1_1) {
    3741           2 :                                 if (Z_LVAL_P(tmp) == SOAP_ACTOR_NEXT) {
    3742           2 :                                         xmlSetProp(h, BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":actor"), BAD_CAST(SOAP_1_1_ACTOR_NEXT));
    3743             :                                 }
    3744             :                         } else {
    3745           0 :                                 if (Z_LVAL_P(tmp) == SOAP_ACTOR_NEXT) {
    3746           0 :                                         xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_NEXT));
    3747           0 :                                 } else if (Z_LVAL_P(tmp) == SOAP_ACTOR_NONE) {
    3748           0 :                                         xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_NONE));
    3749           0 :                                 } else if (Z_LVAL_P(tmp) == SOAP_ACTOR_UNLIMATERECEIVER) {
    3750           0 :                                         xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_UNLIMATERECEIVER));
    3751             :                                 }
    3752             :                         }
    3753             :                 }
    3754             :         }
    3755          32 : }
    3756             : 
    3757         391 : static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, char *function_name, char *uri, zval *ret, int version, int main, xmlNodePtr *node)
    3758             : {
    3759         391 :         xmlNodePtr method = NULL, param;
    3760         391 :         sdlParamPtr parameter = NULL;
    3761             :         int param_count;
    3762             :         int style, use;
    3763         391 :         xmlNsPtr ns = NULL;
    3764             : 
    3765         733 :         if (function != NULL && function->binding->bindingType == BINDING_SOAP) {
    3766         342 :                 sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
    3767             : 
    3768         342 :                 style = fnb->style;
    3769         342 :                 use = fnb->output.use;
    3770         342 :                 if (style == SOAP_RPC) {
    3771         239 :                         ns = encode_add_ns(body, fnb->output.ns);
    3772         239 :                         if (function->responseName) {
    3773         157 :                                 method = xmlNewChild(body, ns, BAD_CAST(function->responseName), NULL);
    3774          82 :                         } else if (function->responseParameters) {
    3775           0 :                                 method = xmlNewChild(body, ns, BAD_CAST(function->functionName), NULL);
    3776             :                         }
    3777             :                 }
    3778             :         } else {
    3779          49 :                 style = main?SOAP_RPC:SOAP_DOCUMENT;
    3780          49 :                 use = main?SOAP_ENCODED:SOAP_LITERAL;
    3781          49 :                 if (style == SOAP_RPC) {
    3782          49 :                         ns = encode_add_ns(body, uri);
    3783          49 :                         method = xmlNewChild(body, ns, BAD_CAST(function_name), NULL);
    3784             :                 }
    3785             :         }
    3786             : 
    3787         391 :         if (function != NULL) {
    3788         342 :                 if (function->responseParameters) {
    3789         260 :                         param_count = zend_hash_num_elements(function->responseParameters);
    3790             :                 } else {
    3791          82 :                   param_count = 0;
    3792             :                 }
    3793             :         } else {
    3794          49 :           param_count = 1;
    3795             :         }
    3796             : 
    3797         391 :         if (param_count == 1) {
    3798         276 :                 parameter = get_param(function, NULL, 0, TRUE);
    3799             : 
    3800         276 :                 if (style == SOAP_RPC) {
    3801             :                   xmlNode *rpc_result;
    3802         218 :                         if (main && version == SOAP_1_2) {
    3803          23 :                                 xmlNs *rpc_ns = xmlNewNs(body, BAD_CAST(RPC_SOAP12_NAMESPACE), BAD_CAST(RPC_SOAP12_NS_PREFIX));
    3804          23 :                                 rpc_result = xmlNewChild(method, rpc_ns, BAD_CAST("result"), NULL);
    3805          23 :                                 param = serialize_parameter(parameter, ret, 0, "return", use, method);
    3806          23 :                                 xmlNodeSetContent(rpc_result,param->name);
    3807             :                         } else {
    3808         172 :                                 param = serialize_parameter(parameter, ret, 0, "return", use, method);
    3809             :                         }
    3810             :                 } else {
    3811          81 :                         param = serialize_parameter(parameter, ret, 0, "return", use, body);
    3812         162 :                         if (function && function->binding->bindingType == BINDING_SOAP) {
    3813          81 :                                 if (parameter && parameter->element) {
    3814          76 :                                         ns = encode_add_ns(param, parameter->element->namens);
    3815          76 :                                         xmlNodeSetName(param, BAD_CAST(parameter->element->name));
    3816          76 :                                         xmlSetNs(param, ns);
    3817             :                                 }
    3818           0 :                         } else if (strcmp((char*)param->name,"return") == 0) {
    3819           0 :                                 ns = encode_add_ns(param, uri);
    3820           0 :                                 xmlNodeSetName(param, BAD_CAST(function_name));
    3821           0 :                                 xmlSetNs(param, ns);
    3822             :                         }
    3823             :                 }
    3824         119 :         } else if (param_count > 1 && Z_TYPE_P(ret) == IS_ARRAY) {
    3825             :                 zval *data;
    3826           4 :                 int i = 0;
    3827             :                 zend_string *param_name;
    3828             : //???
    3829           4 :                 zend_ulong param_index = i;
    3830             : 
    3831          28 :                 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(ret), param_index, param_name, data) {
    3832          12 :                         parameter = get_param(function, param_name->val, param_index, TRUE);
    3833          12 :                         if (style == SOAP_RPC) {
    3834          12 :                                 param = serialize_parameter(parameter, data, i, param_name->val, use, method);
    3835             :                         } else {
    3836           0 :                                 param = serialize_parameter(parameter, data, i, param_name->val, use, body);
    3837           0 :                                 if (function && function->binding->bindingType == BINDING_SOAP) {
    3838           0 :                                         if (parameter && parameter->element) {
    3839           0 :                                                 ns = encode_add_ns(param, parameter->element->namens);
    3840           0 :                                                 xmlNodeSetName(param, BAD_CAST(parameter->element->name));
    3841           0 :                                                 xmlSetNs(param, ns);
    3842             :                                         }
    3843             :                                 }
    3844             :                         }
    3845             : 
    3846          12 :                         i++;
    3847          12 :                         param_index = i;
    3848             :                 } ZEND_HASH_FOREACH_END();
    3849             :         }
    3850         390 :         if (use == SOAP_ENCODED && version == SOAP_1_2 && method != NULL) {
    3851          26 :                 xmlSetNsProp(method, body->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_2_ENC_NAMESPACE));
    3852             :         }
    3853         390 :         if (node) {
    3854          14 :                 *node = method;
    3855             :         }
    3856         390 :         return use;
    3857             : }
    3858             : 
    3859         475 : static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function_name, char *uri, zval *ret, soapHeader* headers, int version)
    3860             : {
    3861             :         xmlDocPtr doc;
    3862         475 :         xmlNodePtr envelope = NULL, body, param;
    3863         475 :         xmlNsPtr ns = NULL;
    3864         475 :         int use = SOAP_LITERAL;
    3865         475 :         xmlNodePtr head = NULL;
    3866             : 
    3867         475 :         encode_reset_ns();
    3868             : 
    3869         475 :         doc = xmlNewDoc(BAD_CAST("1.0"));
    3870         475 :         doc->charset = XML_CHAR_ENCODING_UTF8;
    3871         475 :         doc->encoding = xmlCharStrdup("UTF-8");
    3872             : 
    3873         475 :         if (version == SOAP_1_1) {
    3874         399 :                 envelope = xmlNewDocNode(doc, NULL, BAD_CAST("Envelope"), NULL);
    3875         399 :                 ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_1_ENV_NAMESPACE), BAD_CAST(SOAP_1_1_ENV_NS_PREFIX));
    3876         399 :                 xmlSetNs(envelope,ns);
    3877          76 :         } else if (version == SOAP_1_2) {
    3878          76 :                 envelope = xmlNewDocNode(doc, NULL, BAD_CAST("Envelope"), NULL);
    3879          76 :                 ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENV_NAMESPACE), BAD_CAST(SOAP_1_2_ENV_NS_PREFIX));
    3880          76 :                 xmlSetNs(envelope,ns);
    3881             :         } else {
    3882           0 :                 soap_server_fault("Server", "Unknown SOAP version", NULL, NULL, NULL);
    3883             :         }
    3884         475 :         xmlDocSetRootElement(doc, envelope);
    3885             : 
    3886         729 :         if (Z_TYPE_P(ret) == IS_OBJECT &&
    3887         156 :             instanceof_function(Z_OBJCE_P(ret), soap_fault_class_entry)) {
    3888             :           char *detail_name;
    3889             :                 HashTable* prop;
    3890             :                 zval *tmp;
    3891          98 :                 sdlFaultPtr fault = NULL;
    3892          98 :                 char *fault_ns = NULL;
    3893             : 
    3894          98 :                 prop = Z_OBJPROP_P(ret);
    3895             : 
    3896          99 :                 if (headers &&
    3897           1 :                     (tmp = zend_hash_str_find(prop, "headerfault", sizeof("headerfault")-1)) != NULL) {
    3898           1 :                         encodePtr hdr_enc = NULL;
    3899           1 :                         int hdr_use = SOAP_LITERAL;
    3900           1 :                         zval *hdr_ret  = tmp;
    3901           1 :                         char *hdr_ns   = headers->hdr?headers->hdr->ns:NULL;
    3902           1 :                         char *hdr_name = Z_STRVAL(headers->function_name);
    3903             : 
    3904           1 :                         head = xmlNewChild(envelope, ns, BAD_CAST("Header"), NULL);
    3905           2 :                         if (Z_TYPE_P(hdr_ret) == IS_OBJECT &&
    3906           1 :                             instanceof_function(Z_OBJCE_P(hdr_ret), soap_header_class_entry)) {
    3907           1 :                                 HashTable* ht = Z_OBJPROP_P(hdr_ret);
    3908             :                                 sdlSoapBindingFunctionHeaderPtr hdr;
    3909           1 :                                 smart_str key = {0};
    3910             : 
    3911           2 :                                 if ((tmp = zend_hash_str_find(ht, "namespace", sizeof("namespace")-1)) != NULL &&
    3912             :                               Z_TYPE_P(tmp) == IS_STRING) {
    3913           1 :                                         smart_str_appendl(&key, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
    3914             :                                         smart_str_appendc(&key, ':');
    3915           1 :                                         hdr_ns = Z_STRVAL_P(tmp);
    3916             :                                 }
    3917           2 :                                 if ((tmp = zend_hash_str_find(ht, "name", sizeof("name")-1)) != NULL &&
    3918             :                                     Z_TYPE_P(tmp) == IS_STRING) {
    3919           1 :                                         smart_str_appendl(&key, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
    3920           1 :                                         hdr_name = Z_STRVAL_P(tmp);
    3921             :                                 }
    3922             :                                 smart_str_0(&key);
    3923           2 :                                 if (headers->hdr && headers->hdr->headerfaults &&
    3924           1 :                                     (hdr = zend_hash_find_ptr(headers->hdr->headerfaults, key.s)) != NULL) {
    3925           1 :                                         hdr_enc = hdr->encode;
    3926           1 :                                         hdr_use = hdr->use;
    3927             :                                 }
    3928             :                                 smart_str_free(&key);
    3929           1 :                                 if ((tmp = zend_hash_str_find(ht, "data", sizeof("data")-1)) != NULL) {
    3930           1 :                                         hdr_ret = tmp;
    3931             :                                 } else {
    3932           0 :                                         hdr_ret = NULL;
    3933             :                                 }
    3934             :                         }
    3935             : 
    3936           1 :                         if (headers->function) {
    3937           0 :                                 if (serialize_response_call2(head, headers->function, Z_STRVAL(headers->function_name), uri, hdr_ret, version, 0, NULL) == SOAP_ENCODED) {
    3938           0 :                                         use = SOAP_ENCODED;
    3939             :                                 }
    3940             :                         } else {
    3941           1 :                                 xmlNodePtr xmlHdr = master_to_xml(hdr_enc, hdr_ret, hdr_use, head);
    3942           1 :                                 if (hdr_name) {
    3943           1 :                                         xmlNodeSetName(xmlHdr, BAD_CAST(hdr_name));
    3944             :                                 }
    3945           1 :                                 if (hdr_ns) {
    3946           1 :                                         xmlNsPtr nsptr = encode_add_ns(xmlHdr, hdr_ns);
    3947           1 :                                         xmlSetNs(xmlHdr, nsptr);
    3948             :                                 }
    3949             :                         }
    3950             :                 }
    3951             : 
    3952          98 :                 body = xmlNewChild(envelope, ns, BAD_CAST("Body"), NULL);
    3953          98 :                 param = xmlNewChild(body, ns, BAD_CAST("Fault"), NULL);
    3954             : 
    3955         187 :                 if ((tmp = zend_hash_str_find(prop, "faultcodens", sizeof("faultcodens")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) {
    3956          89 :                         fault_ns = Z_STRVAL_P(tmp);
    3957             :                 }
    3958          98 :                 use = SOAP_LITERAL;
    3959         206 :                 if ((tmp = zend_hash_str_find(prop, "_name", sizeof("_name")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) {
    3960             :                         sdlFaultPtr tmp_fault;
    3961         108 :                         if (function && function->faults &&
    3962          54 :                             (tmp_fault = zend_hash_find_ptr(function->faults, Z_STR_P(tmp))) != NULL) {
    3963          54 :                                 fault = tmp_fault;
    3964         162 :                                 if (function->binding &&
    3965          54 :                                     function->binding->bindingType == BINDING_SOAP &&
    3966          54 :                                     fault->bindingAttributes) {
    3967          53 :                                         sdlSoapBindingFunctionFaultPtr fb = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
    3968          53 :                                         use = fb->use;
    3969          53 :                                         if (fault_ns == NULL) {
    3970           0 :                                                 fault_ns = fb->ns;
    3971             :                                         }
    3972             :                                 }
    3973             :                         }
    3974          44 :                 } else if (function && function->faults &&
    3975           0 :                            zend_hash_num_elements(function->faults) == 1) {
    3976             : 
    3977           0 :                         zend_hash_internal_pointer_reset(function->faults);
    3978           0 :                         fault = zend_hash_get_current_data_ptr(function->faults);
    3979           0 :                         if (function->binding &&
    3980           0 :                             function->binding->bindingType == BINDING_SOAP &&
    3981           0 :                             fault->bindingAttributes) {
    3982           0 :                                 sdlSoapBindingFunctionFaultPtr fb = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
    3983           0 :                                 use = fb->use;
    3984           0 :                                 if (fault_ns == NULL) {
    3985           0 :                                         fault_ns = fb->ns;
    3986             :                                 }
    3987             :                         }
    3988             :                 }
    3989             : 
    3990          98 :                 if (fault_ns == NULL &&
    3991             :                     fault &&
    3992           0 :                     fault->details &&
    3993           0 :                     zend_hash_num_elements(fault->details) == 1) {
    3994             :                         sdlParamPtr sparam;
    3995             : 
    3996           0 :                         zend_hash_internal_pointer_reset(fault->details);
    3997           0 :                         sparam = zend_hash_get_current_data_ptr(fault->details);
    3998           0 :                         if (sparam->element) {
    3999           0 :                                 fault_ns = sparam->element->namens;
    4000             :                         }
    4001             :                 }
    4002             : 
    4003          98 :                 if (version == SOAP_1_1) {
    4004         144 :                         if ((tmp = zend_hash_str_find(prop, "faultcode", sizeof("faultcode")-1)) != NULL &&
    4005             :                             Z_TYPE_P(tmp) == IS_STRING) {
    4006          72 :                                 xmlNodePtr node = xmlNewNode(NULL, BAD_CAST("faultcode"));
    4007          72 :                                 zend_string *str = php_escape_html_entities((unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), 0, 0, NULL);
    4008          72 :                                 xmlAddChild(param, node);
    4009          72 :                                 if (fault_ns) {
    4010          66 :                                         xmlNsPtr nsptr = encode_add_ns(node, fault_ns);
    4011          66 :                                         xmlChar *code = xmlBuildQName(BAD_CAST(str->val), nsptr->prefix, NULL, 0);
    4012          66 :                                         xmlNodeSetContent(node, code);
    4013          66 :                                         xmlFree(code);
    4014             :                                 } else {
    4015           6 :                                         xmlNodeSetContentLen(node, BAD_CAST(str->val), (int)str->len);
    4016             :                                 }
    4017             :                                 zend_string_release(str);
    4018             :                         }
    4019          72 :                         if ((tmp = zend_hash_str_find(prop, "faultstring", sizeof("faultstring")-1)) != NULL) {
    4020          72 :                                 xmlNodePtr node = master_to_xml(get_conversion(IS_STRING), tmp, SOAP_LITERAL, param);
    4021          72 :                                 xmlNodeSetName(node, BAD_CAST("faultstring"));
    4022             :                         }
    4023          72 :                         if ((tmp = zend_hash_str_find(prop, "faultactor", sizeof("faultactor")-1)) != NULL) {
    4024           0 :                                 xmlNodePtr node = master_to_xml(get_conversion(IS_STRING), tmp, SOAP_LITERAL, param);
    4025           0 :                                 xmlNodeSetName(node, BAD_CAST("faultactor"));
    4026             :                         }
    4027          72 :                         detail_name = "detail";
    4028             :                 } else {
    4029          52 :                         if ((tmp = zend_hash_str_find(prop, "faultcode", sizeof("faultcode")-1)) != NULL &&
    4030             :                             Z_TYPE_P(tmp) == IS_STRING) {
    4031          26 :                                 xmlNodePtr node = xmlNewChild(param, ns, BAD_CAST("Code"), NULL);
    4032          26 :                                 zend_string *str = php_escape_html_entities((unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), 0, 0, NULL);
    4033          26 :                                 node = xmlNewChild(node, ns, BAD_CAST("Value"), NULL);
    4034          26 :                                 if (fault_ns) {
    4035          23 :                                         xmlNsPtr nsptr = encode_add_ns(node, fault_ns);
    4036          23 :                                         xmlChar *code = xmlBuildQName(BAD_CAST(str->val), nsptr->prefix, NULL, 0);
    4037          23 :                                         xmlNodeSetContent(node, code);
    4038          23 :                                         xmlFree(code);
    4039             :                                 } else {
    4040           3 :                                         xmlNodeSetContentLen(node, BAD_CAST(str->val), (int)str->len);
    4041             :                                 }
    4042             :                                 zend_string_release(str);
    4043             :                         }
    4044          26 :                         if ((tmp = zend_hash_str_find(prop, "faultstring", sizeof("faultstring")-1)) != NULL) {
    4045          26 :                                 xmlNodePtr node = xmlNewChild(param, ns, BAD_CAST("Reason"), NULL);
    4046          26 :                                 node = master_to_xml(get_conversion(IS_STRING), tmp, SOAP_LITERAL, node);
    4047          26 :                                 xmlNodeSetName(node, BAD_CAST("Text"));
    4048          26 :                                 xmlSetNs(node, ns);
    4049             :                         }
    4050          26 :                         detail_name = SOAP_1_2_ENV_NS_PREFIX":Detail";
    4051             :                 }
    4052         152 :                 if (fault && fault->details && zend_hash_num_elements(fault->details) == 1) {
    4053             :                         xmlNodePtr node;
    4054          54 :                         zval *detail = NULL;
    4055             :                         sdlParamPtr sparam;
    4056             :                         xmlNodePtr x;
    4057             : 
    4058         102 :                         if ((tmp = zend_hash_str_find(prop, "detail", sizeof("detail")-1)) != NULL &&
    4059             :                             Z_TYPE_P(tmp) != IS_NULL) {
    4060          48 :                                 detail = tmp;
    4061             :                         }
    4062          54 :                         node = xmlNewNode(NULL, BAD_CAST(detail_name));
    4063          54 :                         xmlAddChild(param, node);
    4064             : 
    4065          54 :                         zend_hash_internal_pointer_reset(fault->details);
    4066         108 :                         sparam = zend_hash_get_current_data_ptr(fault->details);
    4067             : 
    4068         133 :                         if (detail &&
    4069             :                             Z_TYPE_P(detail) == IS_OBJECT &&
    4070          18 :                             sparam->element &&
    4071          10 :                             zend_hash_num_elements(Z_OBJPROP_P(detail)) == 1 &&
    4072           3 :                             (tmp = zend_hash_str_find(Z_OBJPROP_P(detail), sparam->element->name, strlen(sparam->element->name))) != NULL) {
    4073           0 :                                 detail = tmp;
    4074             :                         }
    4075             : 
    4076          54 :                         x = serialize_parameter(sparam, detail, 1, NULL, use, node);
    4077             : 
    4078         216 :                         if (function &&
    4079          54 :                             function->binding &&
    4080          54 :                             function->binding->bindingType == BINDING_SOAP &&
    4081          54 :                             function->bindingAttributes) {
    4082          54 :                                 sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
    4083          81 :                                 if (fnb->style == SOAP_RPC && !sparam->element) {
    4084          27 :                                   if (fault->bindingAttributes) {
    4085          27 :                                                 sdlSoapBindingFunctionFaultPtr fb = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
    4086          27 :                                                 if (fb->ns) {
    4087          27 :                                                         xmlNsPtr ns = encode_add_ns(x, fb->ns);
    4088          27 :                                                         xmlSetNs(x, ns);
    4089             :                                                 }
    4090             :                                         }
    4091             :                                 } else {
    4092          27 :                                         if (sparam->element) {
    4093          27 :                                                 ns = encode_add_ns(x, sparam->element->namens);
    4094          27 :                                                 xmlNodeSetName(x, BAD_CAST(sparam->element->name));
    4095          27 :                                                 xmlSetNs(x, ns);
    4096             :                                         }
    4097             :                                 }
    4098             :                         }
    4099          54 :                         if (use == SOAP_ENCODED && version == SOAP_1_2) {
    4100           0 :                                 xmlSetNsProp(x, envelope->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_2_ENC_NAMESPACE));
    4101             :                         }
    4102          44 :                 } else if ((tmp = zend_hash_str_find(prop, "detail", sizeof("detail")-1)) != NULL &&
    4103             :                     Z_TYPE_P(tmp) != IS_NULL) {
    4104           0 :                         serialize_zval(tmp, NULL, detail_name, use, param);
    4105             :                 }
    4106             :         } else {
    4107             : 
    4108         377 :                 if (headers) {
    4109             :                         soapHeader *h;
    4110             : 
    4111          35 :                         head = xmlNewChild(envelope, ns, BAD_CAST("Header"), NULL);
    4112          35 :                         h = headers;
    4113         112 :                         while (h != NULL) {
    4114          84 :                                 if (Z_TYPE(h->retval) != IS_NULL) {
    4115          27 :                                         encodePtr hdr_enc = NULL;
    4116          27 :                                         int hdr_use = SOAP_LITERAL;
    4117          27 :                                         zval *hdr_ret = &h->retval;
    4118          27 :                                         char *hdr_ns   = h->hdr?h->hdr->ns:NULL;
    4119          27 :                                         char *hdr_name = Z_STRVAL(h->function_name);
    4120          27 :                                         HashTable *ht = NULL;
    4121             : 
    4122          67 :                                         if (Z_TYPE(h->retval) == IS_OBJECT &&
    4123          13 :                                             instanceof_function(Z_OBJCE(h->retval), soap_header_class_entry)) {
    4124             :                                                 zval *tmp;
    4125             :                                                 sdlSoapBindingFunctionHeaderPtr hdr;
    4126          13 :                                                 smart_str key = {0};
    4127             : 
    4128          13 :                                                 ht = Z_OBJPROP(h->retval);
    4129          26 :                                                 if ((tmp = zend_hash_str_find(ht, "namespace", sizeof("namespace")-1)) != NULL &&
    4130             :                                               Z_TYPE_P(tmp) == IS_STRING) {
    4131          13 :                                                         smart_str_appendl(&key, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
    4132             :                                                         smart_str_appendc(&key, ':');
    4133          13 :                                                         hdr_ns = Z_STRVAL_P(tmp);
    4134             :                                                 }
    4135          26 :                                                 if ((tmp = zend_hash_str_find(ht, "name", sizeof("name")-1)) != NULL &&
    4136             :                                                     Z_TYPE_P(tmp) == IS_STRING) {
    4137          13 :                                                         smart_str_appendl(&key, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
    4138          13 :                                                         hdr_name = Z_STRVAL_P(tmp);
    4139             :                                                 }
    4140             :                                                 smart_str_0(&key);
    4141          13 :                                                 if (function && function->binding && function->binding->bindingType == BINDING_SOAP) {
    4142           8 :                                                         sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
    4143             : 
    4144          16 :                                                         if (fnb->output.headers &&
    4145           8 :                                                             (hdr = zend_hash_find_ptr(fnb->output.headers, key.s)) != NULL) {
    4146           8 :                                                                 hdr_enc = hdr->encode;
    4147           8 :                                                                 hdr_use = hdr->use;
    4148             :                                                         }
    4149             :                                                 }
    4150             :                                                 smart_str_free(&key);
    4151          13 :                                                 if ((tmp = zend_hash_str_find(ht, "data", sizeof("data")-1)) != NULL) {
    4152          13 :                                                         hdr_ret = tmp;
    4153             :                                                 } else {
    4154           0 :                                                         hdr_ret = NULL;
    4155             :                                                 }
    4156             :                                         }
    4157             : 
    4158          27 :                                         if (h->function) {
    4159          14 :                                                 xmlNodePtr xmlHdr = NULL;
    4160             : 
    4161          14 :                                                 if (serialize_response_call2(head, h->function, Z_STRVAL(h->function_name), uri, hdr_ret, version, 0, &xmlHdr) == SOAP_ENCODED) {
    4162           0 :                                                         use = SOAP_ENCODED;
    4163             :                                                 }
    4164          14 :                                                 if (ht) {
    4165           0 :                                                         set_soap_header_attributes(xmlHdr, ht, version);
    4166             :                                                 }
    4167             :                                         } else {
    4168          13 :                                                 xmlNodePtr xmlHdr = master_to_xml(hdr_enc, hdr_ret, hdr_use, head);
    4169          13 :                                                 if (hdr_name) {
    4170          13 :                                                         xmlNodeSetName(xmlHdr, BAD_CAST(hdr_name));
    4171             :                                                 }
    4172          13 :                                                 if (hdr_ns) {
    4173          13 :                                                         xmlNsPtr nsptr = encode_add_ns(xmlHdr,hdr_ns);
    4174          13 :                                                         xmlSetNs(xmlHdr, nsptr);
    4175             :                                                 }
    4176          13 :                                                 if (ht) {
    4177          13 :                                                         set_soap_header_attributes(xmlHdr, ht, version);
    4178             :                                                 }
    4179             :                                         }
    4180             :                                 }
    4181          42 :                                 h = h->next;
    4182             :                         }
    4183             : 
    4184          35 :                         if (head->children == NULL) {
    4185          12 :                                 xmlUnlinkNode(head);
    4186          12 :                                 xmlFreeNode(head);
    4187             :                         }
    4188             :                 }
    4189             : 
    4190         377 :                 body = xmlNewChild(envelope, ns, BAD_CAST("Body"), NULL);
    4191             : 
    4192         377 :                 if (serialize_response_call2(body, function, function_name, uri, ret, version, 1, NULL) == SOAP_ENCODED) {
    4193         205 :                         use = SOAP_ENCODED;
    4194             :                 }
    4195             : 
    4196             :         }
    4197             : 
    4198         474 :         if (use == SOAP_ENCODED) {
    4199         232 :                 xmlNewNs(envelope, BAD_CAST(XSD_NAMESPACE), BAD_CAST(XSD_NS_PREFIX));
    4200         232 :                 if (version == SOAP_1_1) {
    4201         206 :                         xmlNewNs(envelope, BAD_CAST(SOAP_1_1_ENC_NAMESPACE), BAD_CAST(SOAP_1_1_ENC_NS_PREFIX));
    4202         206 :                         xmlSetNsProp(envelope, envelope->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_1_ENC_NAMESPACE));
    4203          26 :                 } else if (version == SOAP_1_2) {
    4204          26 :                         xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENC_NAMESPACE), BAD_CAST(SOAP_1_2_ENC_NS_PREFIX));
    4205             :                 }
    4206             :         }
    4207             : 
    4208         474 :         encode_finish();
    4209             : 
    4210         556 :         if (function && function->responseName == NULL &&
    4211          82 :             body->children == NULL && head == NULL) {
    4212          82 :                 xmlFreeDoc(doc);
    4213          82 :                 return NULL;
    4214             :         }
    4215         392 :         return doc;
    4216             : }
    4217             : 
    4218         400 : static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function, char *function_name, char *uri, zval *arguments, int arg_count, int version, HashTable *soap_headers)
    4219             : {
    4220             :         xmlDoc *doc;
    4221         400 :         xmlNodePtr envelope = NULL, body, method = NULL, head = NULL;
    4222         400 :         xmlNsPtr ns = NULL;
    4223             :         zval *zstyle, *zuse;
    4224             :         int i, style, use;
    4225         400 :         HashTable *hdrs = NULL;
    4226             : 
    4227         400 :         encode_reset_ns();
    4228             : 
    4229         400 :         doc = xmlNewDoc(BAD_CAST("1.0"));
    4230         400 :         doc->encoding = xmlCharStrdup("UTF-8");
    4231         400 :         doc->charset = XML_CHAR_ENCODING_UTF8;
    4232         400 :         if (version == SOAP_1_1) {
    4233         398 :                 envelope = xmlNewDocNode(doc, NULL, BAD_CAST("Envelope"), NULL);
    4234         398 :                 ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_1_ENV_NAMESPACE), BAD_CAST(SOAP_1_1_ENV_NS_PREFIX));
    4235         398 :                 xmlSetNs(envelope, ns);
    4236           2 :         } else if (version == SOAP_1_2) {
    4237           2 :                 envelope = xmlNewDocNode(doc, NULL, BAD_CAST("Envelope"), NULL);
    4238           2 :                 ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENV_NAMESPACE), BAD_CAST(SOAP_1_2_ENV_NS_PREFIX));
    4239           2 :                 xmlSetNs(envelope, ns);
    4240             :         } else {
    4241           0 :                 soap_error0(E_ERROR, "Unknown SOAP version");
    4242             :         }
    4243         400 :         xmlDocSetRootElement(doc, envelope);
    4244             : 
    4245         400 :         if (soap_headers) {
    4246          16 :                 head = xmlNewChild(envelope, ns, BAD_CAST("Header"), NULL);
    4247             :         }
    4248             : 
    4249         400 :         body = xmlNewChild(envelope, ns, BAD_CAST("Body"), NULL);
    4250             : 
    4251         700 :         if (function && function->binding->bindingType == BINDING_SOAP) {
    4252         300 :                 sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
    4253             : 
    4254         300 :                 hdrs = fnb->input.headers;
    4255         300 :                 style = fnb->style;
    4256             :                 /*FIXME: how to pass method name if style is SOAP_DOCUMENT */
    4257             :                 /*style = SOAP_RPC;*/
    4258         300 :                 use = fnb->input.use;
    4259         300 :                 if (style == SOAP_RPC) {
    4260         198 :                         ns = encode_add_ns(body, fnb->input.ns);
    4261         198 :                         if (function->requestName) {
    4262         198 :                                 method = xmlNewChild(body, ns, BAD_CAST(function->requestName), NULL);
    4263             :                         } else {
    4264           0 :                                 method = xmlNewChild(body, ns, BAD_CAST(function->functionName), NULL);
    4265             :                         }
    4266             :                 }
    4267             :         } else {
    4268         108 :                 if ((zstyle = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "style", sizeof("style")-1)) != NULL &&
    4269             :                     Z_TYPE_P(zstyle) == IS_LONG) {
    4270           4 :                         style = Z_LVAL_P(zstyle);
    4271             :                 } else {
    4272          96 :                         style = SOAP_RPC;
    4273             :                 }
    4274             :                 /*FIXME: how to pass method name if style is SOAP_DOCUMENT */
    4275             :                 /*style = SOAP_RPC;*/
    4276         100 :                 if (style == SOAP_RPC) {
    4277         100 :                         ns = encode_add_ns(body, uri);
    4278         100 :                         if (function_name) {
    4279          99 :                                 method = xmlNewChild(body, ns, BAD_CAST(function_name), NULL);
    4280           2 :                         } else if (function && function->requestName) {
    4281           1 :                                 method = xmlNewChild(body, ns, BAD_CAST(function->requestName), NULL);
    4282           0 :                         } else if (function && function->functionName) {
    4283           0 :                                 method = xmlNewChild(body, ns, BAD_CAST(function->functionName), NULL);
    4284             :                         } else {
    4285           0 :                                 method = body;
    4286             :                         }
    4287             :                 } else {
    4288           0 :                         method = body;
    4289             :                 }
    4290             : 
    4291         108 :                 if ((zuse = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "use", sizeof("use")-1)) != NULL &&
    4292           4 :                      Z_TYPE_P(zuse) == IS_LONG && Z_LVAL_P(zuse) == SOAP_LITERAL) {
    4293           0 :                         use = SOAP_LITERAL;
    4294             :                 } else {
    4295         100 :                         use = SOAP_ENCODED;
    4296             :                 }
    4297             :         }
    4298             : 
    4299         844 :         for (i = 0;i < arg_count;i++) {
    4300             :                 xmlNodePtr param;
    4301         446 :                 sdlParamPtr parameter = get_param(function, NULL, i, FALSE);
    4302             : 
    4303         446 :                 if (style == SOAP_RPC) {
    4304         356 :                         param = serialize_parameter(parameter, &arguments[i], i, NULL, use, method);
    4305          90 :                 } else if (style == SOAP_DOCUMENT) {
    4306          90 :                         param = serialize_parameter(parameter, &arguments[i], i, NULL, use, body);
    4307          89 :                         if (function && function->binding->bindingType == BINDING_SOAP) {
    4308          89 :                                 if (parameter && parameter->element) {
    4309          83 :                                         ns = encode_add_ns(param, parameter->element->namens);
    4310          83 :                                         xmlNodeSetName(param, BAD_CAST(parameter->element->name));
    4311          83 :                                         xmlSetNs(param, ns);
    4312             :                                 }
    4313             :                         }
    4314             :                 }
    4315             :         }
    4316             : 
    4317         398 :         if (function && function->requestParameters) {
    4318         298 :                 int n = zend_hash_num_elements(function->requestParameters);
    4319             : 
    4320         298 :                 if (n > arg_count) {
    4321          20 :                         for (i = arg_count; i < n; i++) {
    4322             :                                 xmlNodePtr param;
    4323          10 :                                 sdlParamPtr parameter = get_param(function, NULL, i, FALSE);
    4324             : 
    4325          10 :                                 if (style == SOAP_RPC) {
    4326           1 :                                         param = serialize_parameter(parameter, NULL, i, NULL, use, method);
    4327           9 :                                 } else if (style == SOAP_DOCUMENT) {
    4328           9 :                                         param = serialize_parameter(parameter, NULL, i, NULL, use, body);
    4329           9 :                                         if (function && function->binding->bindingType == BINDING_SOAP) {
    4330           9 :                                                 if (parameter && parameter->element) {
    4331           9 :                                                         ns = encode_add_ns(param, parameter->element->namens);
    4332           9 :                                                         xmlNodeSetName(param, BAD_CAST(parameter->element->name));
    4333           9 :                                                         xmlSetNs(param, ns);
    4334             :                                                 }
    4335             :                                         }
    4336             :                                 }
    4337             :                         }
    4338             :                 }
    4339             :         }
    4340             : 
    4341         398 :         if (head) {
    4342             :                 zval* header;
    4343             : 
    4344          56 :                 ZEND_HASH_FOREACH_VAL(soap_headers, header) {
    4345          20 :                         HashTable *ht = Z_OBJPROP_P(header);
    4346             :                         zval *name, *ns, *tmp;
    4347             : 
    4348          77 :                         if ((name = zend_hash_str_find(ht, "name", sizeof("name")-1)) != NULL &&
    4349             :                             Z_TYPE_P(name) == IS_STRING &&
    4350          19 :                             (ns = zend_hash_str_find(ht, "namespace", sizeof("namespace")-1)) != NULL &&
    4351             :                             Z_TYPE_P(ns) == IS_STRING) {
    4352             :                                 xmlNodePtr h;
    4353             :                                 xmlNsPtr nsptr;
    4354          19 :                                 int hdr_use = SOAP_LITERAL;
    4355          19 :                                 encodePtr enc = NULL;
    4356             : 
    4357          19 :                                 if (hdrs) {
    4358          11 :                                         smart_str key = {0};
    4359             :                                         sdlSoapBindingFunctionHeaderPtr hdr;
    4360             : 
    4361          11 :                                         smart_str_appendl(&key, Z_STRVAL_P(ns), Z_STRLEN_P(ns));
    4362             :                                         smart_str_appendc(&key, ':');
    4363          11 :                                         smart_str_appendl(&key, Z_STRVAL_P(name), Z_STRLEN_P(name));
    4364             :                                         smart_str_0(&key);
    4365          22 :                                         if ((hdr = zend_hash_find_ptr(hdrs, key.s)) != NULL) {
    4366          10 :                                                 hdr_use = hdr->use;
    4367          10 :                                                 enc = hdr->encode;
    4368          10 :                                                 if (hdr_use == SOAP_ENCODED) {
    4369           0 :                                                         use = SOAP_ENCODED;
    4370             :                                                 }
    4371             :                                         }
    4372             :                                         smart_str_free(&key);
    4373             :                                 }
    4374             : 
    4375          19 :                                 if ((tmp = zend_hash_str_find(ht, "data", sizeof("data")-1)) != NULL) {
    4376          12 :                                         h = master_to_xml(enc, tmp, hdr_use, head);
    4377          12 :                                         xmlNodeSetName(h, BAD_CAST(Z_STRVAL_P(name)));
    4378             :                                 } else {
    4379           7 :                                         h = xmlNewNode(NULL, BAD_CAST(Z_STRVAL_P(name)));
    4380           7 :                                         xmlAddChild(head, h);
    4381             :                                 }
    4382          19 :                                 nsptr = encode_add_ns(h, Z_STRVAL_P(ns));
    4383          19 :                                 xmlSetNs(h, nsptr);
    4384          19 :                                 set_soap_header_attributes(h, ht, version);
    4385             :                         }
    4386             :                 } ZEND_HASH_FOREACH_END();
    4387             :         }
    4388             : 
    4389         398 :         if (use == SOAP_ENCODED) {
    4390         288 :                 xmlNewNs(envelope, BAD_CAST(XSD_NAMESPACE), BAD_CAST(XSD_NS_PREFIX));
    4391         288 :                 if (version == SOAP_1_1) {
    4392         286 :                         xmlNewNs(envelope, BAD_CAST(SOAP_1_1_ENC_NAMESPACE), BAD_CAST(SOAP_1_1_ENC_NS_PREFIX));
    4393         286 :                         xmlSetNsProp(envelope, envelope->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_1_ENC_NAMESPACE));
    4394           2 :                 } else if (version == SOAP_1_2) {
    4395           2 :                         xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENC_NAMESPACE), BAD_CAST(SOAP_1_2_ENC_NS_PREFIX));
    4396           2 :                         if (method) {
    4397           2 :                                 xmlSetNsProp(method, envelope->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_2_ENC_NAMESPACE));
    4398             :                         }
    4399             :                 }
    4400             :         }
    4401             : 
    4402         398 :         encode_finish();
    4403             : 
    4404         398 :         return doc;
    4405             : }
    4406             : 
    4407         798 : static xmlNodePtr serialize_parameter(sdlParamPtr param, zval *param_val, int index, char *name, int style, xmlNodePtr parent)
    4408             : {
    4409             :         char *paramName;
    4410             :         xmlNodePtr xmlParam;
    4411             :         char paramNameBuf[10];
    4412             : 
    4413        1802 :         if (param_val &&
    4414             :             Z_TYPE_P(param_val) == IS_OBJECT &&
    4415         222 :             Z_OBJCE_P(param_val) == soap_param_class_entry) {
    4416             :                 zval *param_name;
    4417             :                 zval *param_data;
    4418             : 
    4419          90 :                 if ((param_name = zend_hash_str_find(Z_OBJPROP_P(param_val), "param_name", sizeof("param_name")-1)) != NULL &&
    4420             :                     Z_TYPE_P(param_name) == IS_STRING &&
    4421          30 :                     (param_data = zend_hash_str_find(Z_OBJPROP_P(param_val), "param_data", sizeof("param_data")-1)) != NULL) {
    4422          30 :                         param_val = param_data;
    4423          30 :                         name = Z_STRVAL_P(param_name);
    4424             :                 }
    4425             :         }
    4426             : 
    4427        1452 :         if (param != NULL && param->paramName != NULL) {
    4428         654 :                 paramName = param->paramName;
    4429             :         } else {
    4430         144 :                 if (name == NULL) {
    4431          65 :                         paramName = paramNameBuf;
    4432          65 :                         snprintf(paramName, sizeof(paramNameBuf), "param%d",index);
    4433             :                 } else {
    4434          79 :                         paramName = name;
    4435             :                 }
    4436             :         }
    4437             : 
    4438         798 :         xmlParam = serialize_zval(param_val, param, paramName, style, parent);
    4439             : 
    4440         795 :         return xmlParam;
    4441             : }
    4442             : 
    4443         798 : static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName, int style, xmlNodePtr parent)
    4444             : {
    4445             :         xmlNodePtr xmlParam;
    4446             :         encodePtr enc;
    4447             :         zval defval;
    4448             : 
    4449         798 :         ZVAL_UNDEF(&defval);
    4450         798 :         if (param != NULL) {
    4451         654 :                 enc = param->encode;
    4452         654 :                 if (val == NULL) {
    4453          16 :                         if (param->element) {
    4454          13 :                                 if (param->element->fixed) {
    4455           0 :                                         ZVAL_STRING(&defval, param->element->fixed);
    4456           0 :                                         val = &defval;
    4457          13 :                                 } else if (param->element->def && !param->element->nillable) {
    4458           2 :                                         ZVAL_STRING(&defval, param->element->def);
    4459           1 :                                         val = &defval;
    4460             :                                 }
    4461             :                         }
    4462             :                 }
    4463             :         } else {
    4464         144 :                 enc = NULL;
    4465             :         }
    4466         798 :         xmlParam = master_to_xml(enc, val, style, parent);
    4467         795 :         zval_ptr_dtor(&defval);
    4468         795 :         if (!strcmp((char*)xmlParam->name, "BOGUS")) {
    4469         789 :                 xmlNodeSetName(xmlParam, BAD_CAST(paramName));
    4470             :         }
    4471         795 :         return xmlParam;
    4472             : }
    4473             : 
    4474         744 : static sdlParamPtr get_param(sdlFunctionPtr function, char *param_name, int index, int response)
    4475             : {
    4476             :         sdlParamPtr tmp;
    4477             :         HashTable   *ht;
    4478             : 
    4479         744 :         if (function == NULL) {
    4480         144 :                 return NULL;
    4481             :         }
    4482             : 
    4483         600 :         if (response == FALSE) {
    4484         361 :                 ht = function->requestParameters;
    4485             :         } else {
    4486         239 :                 ht = function->responseParameters;
    4487             :         }
    4488             : 
    4489         600 :         if (ht == NULL) {
    4490           0 :           return NULL;
    4491             :         }
    4492             : 
    4493         600 :         if (param_name != NULL) {
    4494          24 :                 if ((tmp = zend_hash_str_find_ptr(ht, param_name, strlen(param_name))) != NULL) {
    4495           0 :                         return tmp;
    4496             :                 } else {
    4497          48 :                         ZEND_HASH_FOREACH_PTR(ht, tmp) {
    4498          24 :                                 if (tmp->paramName && strcmp(param_name, tmp->paramName) == 0) {
    4499          12 :                                         return tmp;
    4500             :                                 }
    4501             :                         } ZEND_HASH_FOREACH_END();
    4502             :                 }
    4503             :         } else {
    4504        1176 :                 if ((tmp = zend_hash_index_find_ptr(ht, index)) != NULL) {
    4505         588 :                         return tmp;
    4506             :                 }
    4507             :         }
    4508           0 :         return NULL;
    4509             : }
    4510             : 
    4511         780 : static sdlFunctionPtr get_function(sdlPtr sdl, const char *function_name)
    4512             : {
    4513             :         sdlFunctionPtr tmp;
    4514             : 
    4515         780 :         int len = strlen(function_name);
    4516         780 :         char *str = estrndup(function_name,len);
    4517         780 :         php_strtolower(str,len);
    4518         780 :         if (sdl != NULL) {
    4519        1434 :                 if ((tmp = zend_hash_str_find_ptr(&sdl->functions, str, len)) != NULL) {
    4520         640 :                         efree(str);
    4521         640 :                         return tmp;
    4522          77 :                 } else if (sdl->requests != NULL && (tmp = zend_hash_str_find_ptr(sdl->requests, str, len)) != NULL) {
    4523           0 :                         efree(str);
    4524           0 :                         return tmp;
    4525             :                 }
    4526             :         }
    4527         140 :         efree(str);
    4528         140 :         return NULL;
    4529             : }
    4530             : 
    4531         170 : static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr params)
    4532             : {
    4533         170 :         if (sdl) {
    4534             :                 sdlFunctionPtr tmp;
    4535             :                 sdlParamPtr    param;
    4536             : 
    4537        2841 :                 ZEND_HASH_FOREACH_PTR(&sdl->functions, tmp) {
    4538        1406 :                         if (tmp->binding && tmp->binding->bindingType == BINDING_SOAP) {
    4539        1406 :                                 sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)tmp->bindingAttributes;
    4540        1406 :                                 if (fnb->style == SOAP_DOCUMENT) {
    4541        1097 :                                         if (params == NULL) {
    4542          66 :                                                 if (tmp->requestParameters == NULL ||
    4543          33 :                                                     zend_hash_num_elements(tmp->requestParameters) == 0) {
    4544          30 :                                                   return tmp;
    4545             :                                                 }
    4546        2128 :                                         } else if (tmp->requestParameters != NULL &&
    4547        1064 :                                                    zend_hash_num_elements(tmp->requestParameters) > 0) {
    4548        1028 :                                                 int ok = 1;
    4549        1028 :                                                 xmlNodePtr node = params;
    4550             : 
    4551        2169 :                                                 ZEND_HASH_FOREACH_PTR(tmp->requestParameters, param) {
    4552        1029 :                                                         if (param->element) {
    4553        1024 :                                                                 if (strcmp(param->element->name, (char*)node->name) != 0) {
    4554         917 :                                                                         ok = 0;
    4555         917 :                                                                         break;
    4556             :                                                                 }
    4557         214 :                                                                 if (param->element->namens != NULL && node->ns != NULL) {
    4558         107 :                                                                         if (strcmp(param->element->namens, (char*)node->ns->href) != 0) {
    4559           0 :                                                                                 ok = 0;
    4560           0 :                                                                                 break;
    4561             :                                                                         }
    4562           0 :                                                                 } else if ((void*)param->element->namens != (void*)node->ns) {
    4563           0 :                                                                         ok = 0;
    4564           0 :                                                                         break;
    4565             :                                                                 }
    4566           5 :                                                         } else if (strcmp(param->paramName, (char*)node->name) != 0) {
    4567           0 :                                                                 ok = 0;
    4568           0 :                                                                 break;
    4569             :                                                         }
    4570         112 :                                                         node = node->next;
    4571             :                                                 } ZEND_HASH_FOREACH_END();
    4572        1028 :                                                 if (ok /*&& node == NULL*/) {
    4573         111 :                                                         return tmp;
    4574             :                                                 }
    4575             :                                         }
    4576             :                                 }
    4577             :                         }
    4578             :                 } ZEND_HASH_FOREACH_END();
    4579             :         }
    4580          29 :         return NULL;
    4581             : }
    4582             : 
    4583           7 : static void function_to_string(sdlFunctionPtr function, smart_str *buf)
    4584             : {
    4585           7 :         int i = 0;
    4586             :         sdlParamPtr param;
    4587             : 
    4588          21 :         if (function->responseParameters &&
    4589           7 :             zend_hash_num_elements(function->responseParameters) > 0) {
    4590           7 :                 if (zend_hash_num_elements(function->responseParameters) == 1) {
    4591           7 :                         zend_hash_internal_pointer_reset(function->responseParameters);
    4592          14 :                         param = zend_hash_get_current_data_ptr(function->responseParameters);
    4593          14 :                         if (param->encode && param->encode->details.type_str) {
    4594           7 :                                 smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str));
    4595             :                                 smart_str_appendc(buf, ' ');
    4596             :                         } else {
    4597             :                                 smart_str_appendl(buf, "UNKNOWN ", 8);
    4598             :                         }
    4599             :                 } else {
    4600           0 :                         i = 0;
    4601             :                         smart_str_appendl(buf, "list(", 5);
    4602           0 :                         ZEND_HASH_FOREACH_PTR(function->responseParameters, param) {
    4603           0 :                                 if (i > 0) {
    4604             :                                         smart_str_appendl(buf, ", ", 2);
    4605             :                                 }
    4606           0 :                                 if (param->encode && param->encode->details.type_str) {
    4607           0 :                                         smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str));
    4608             :                                 } else {
    4609             :                                         smart_str_appendl(buf, "UNKNOWN", 7);
    4610             :                                 }
    4611             :                                 smart_str_appendl(buf, " $", 2);
    4612           0 :                                 smart_str_appendl(buf, param->paramName, strlen(param->paramName));
    4613           0 :                                 i++;
    4614             :                         } ZEND_HASH_FOREACH_END();
    4615             :                         smart_str_appendl(buf, ") ", 2);
    4616             :                 }
    4617             :         } else {
    4618             :                 smart_str_appendl(buf, "void ", 5);
    4619             :         }
    4620             : 
    4621           7 :         smart_str_appendl(buf, function->functionName, strlen(function->functionName));
    4622             : 
    4623             :         smart_str_appendc(buf, '(');
    4624           7 :         if (function->requestParameters) {
    4625           7 :                 i = 0;
    4626          21 :                 ZEND_HASH_FOREACH_PTR(function->requestParameters, param) {
    4627           7 :                         if (i > 0) {
    4628             :                                 smart_str_appendl(buf, ", ", 2);
    4629             :                         }
    4630          14 :                         if (param->encode && param->encode->details.type_str) {
    4631           7 :                                 smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str));
    4632             :                         } else {
    4633             :                                 smart_str_appendl(buf, "UNKNOWN", 7);
    4634             :                         }
    4635             :                         smart_str_appendl(buf, " $", 2);
    4636           7 :                         smart_str_appendl(buf, param->paramName, strlen(param->paramName));
    4637           7 :                         i++;
    4638             :                 } ZEND_HASH_FOREACH_END();
    4639             :         }
    4640             :         smart_str_appendc(buf, ')');
    4641             :         smart_str_0(buf);
    4642           7 : }
    4643             : 
    4644         118 : static void model_to_string(sdlContentModelPtr model, smart_str *buf, int level)
    4645             : {
    4646             :         int i;
    4647             : 
    4648         118 :         switch (model->kind) {
    4649             :                 case XSD_CONTENT_ELEMENT:
    4650          76 :                         type_to_string(model->u.element, buf, level);
    4651             :                         smart_str_appendl(buf, ";\n", 2);
    4652          76 :                         break;
    4653             :                 case XSD_CONTENT_ANY:
    4654           2 :                         for (i = 0;i < level;i++) {
    4655             :                                 smart_str_appendc(buf, ' ');
    4656             :                         }
    4657             :                         smart_str_appendl(buf, "<anyXML> any;\n", sizeof("<anyXML> any;\n")-1);
    4658           1 :                         break;
    4659             :                 case XSD_CONTENT_SEQUENCE:
    4660             :                 case XSD_CONTENT_ALL:
    4661             :                 case XSD_CONTENT_CHOICE: {
    4662             :                         sdlContentModelPtr tmp;
    4663             : 
    4664         195 :                         ZEND_HASH_FOREACH_PTR(model->u.content, tmp) {
    4665          77 :                                 model_to_string(tmp, buf, level);
    4666             :                         } ZEND_HASH_FOREACH_END();
    4667          41 :                         break;
    4668             :                 }
    4669             :                 case XSD_CONTENT_GROUP:
    4670           0 :                         model_to_string(model->u.group->model, buf, level);
    4671             :                 default:
    4672             :                   break;
    4673             :         }
    4674         118 : }
    4675             : 
    4676         128 : static void type_to_string(sdlTypePtr type, smart_str *buf, int level)
    4677             : {
    4678             :         int i;
    4679         128 :         smart_str spaces = {0};
    4680             : 
    4681         204 :         for (i = 0;i < level;i++) {
    4682             :                 smart_str_appendc(&spaces, ' ');
    4683             :         }
    4684         128 :         if (spaces.s) {
    4685          76 :                 smart_str_appendl(buf, spaces.s->val, spaces.s->len);
    4686             :         }
    4687         128 :         switch (type->kind) {
    4688             :                 case XSD_TYPEKIND_SIMPLE:
    4689          78 :                         if (type->encode) {
    4690          76 :                                 smart_str_appendl(buf, type->encode->details.type_str, strlen(type->encode->details.type_str));
    4691             :                                 smart_str_appendc(buf, ' ');
    4692             :                         } else {
    4693             :                                 smart_str_appendl(buf, "anyType ", sizeof("anyType ")-1);
    4694             :                         }
    4695          78 :                         smart_str_appendl(buf, type->name, strlen(type->name));
    4696          78 :                         break;
    4697             :                 case XSD_TYPEKIND_LIST:
    4698             :                         smart_str_appendl(buf, "list ", 5);
    4699           2 :                         smart_str_appendl(buf, type->name, strlen(type->name));
    4700           2 :                         if (type->elements) {
    4701             :                                 sdlTypePtr item_type;
    4702             : 
    4703             :                                 smart_str_appendl(buf, " {", 2);
    4704           6 :                                 ZEND_HASH_FOREACH_PTR(type->elements, item_type) {
    4705           2 :                                         smart_str_appendl(buf, item_type->name, strlen(item_type->name));
    4706             :                                 } ZEND_HASH_FOREACH_END();
    4707             :                                 smart_str_appendc(buf, '}');
    4708             :                         }
    4709           2 :                         break;
    4710             :                 case XSD_TYPEKIND_UNION:
    4711             :                         smart_str_appendl(buf, "union ", 6);
    4712           0 :                         smart_str_appendl(buf, type->name, strlen(type->name));
    4713           0 :                         if (type->elements) {
    4714             :                                 sdlTypePtr item_type;
    4715           0 :                                 int first = 0;
    4716             : 
    4717             :                                 smart_str_appendl(buf, " {", 2);
    4718           0 :                                 ZEND_HASH_FOREACH_PTR(type->elements, item_type) {
    4719           0 :                                         if (!first) {
    4720             :                                                 smart_str_appendc(buf, ',');
    4721           0 :                                                 first = 0;
    4722             :                                         }
    4723           0 :                                         smart_str_appendl(buf, item_type->name, strlen(item_type->name));
    4724             :                                 } ZEND_HASH_FOREACH_END();
    4725             :                                 smart_str_appendc(buf, '}');
    4726             :                         }
    4727           0 :                         break;
    4728             :                 case XSD_TYPEKIND_COMPLEX:
    4729             :                 case XSD_TYPEKIND_RESTRICTION:
    4730             :                 case XSD_TYPEKIND_EXTENSION:
    4731          52 :                         if (type->encode &&
    4732           2 :                             (type->encode->details.type == IS_ARRAY ||
    4733           1 :                              type->encode->details.type == SOAP_ENC_ARRAY)) {
    4734             :                           sdlAttributePtr attr;
    4735             :                           sdlExtraAttributePtr ext;
    4736             : 
    4737           3 :                                 if (type->attributes &&
    4738           1 :                                     (attr = zend_hash_str_find_ptr(type->attributes, SOAP_1_1_ENC_NAMESPACE":arrayType",
    4739             :                                       sizeof(SOAP_1_1_ENC_NAMESPACE":arrayType")-1)) != NULL &&
    4740           1 :                                         attr->extraAttributes &&
    4741           0 :                                     (ext = zend_hash_str_find_ptr(attr->extraAttributes, WSDL_NAMESPACE":arrayType", sizeof(WSDL_NAMESPACE":arrayType")-1)) != NULL) {
    4742           0 :                                         char *end = strchr(ext->val, '[');
    4743             :                                         int len;
    4744           0 :                                         if (end == NULL) {
    4745           0 :                                                 len = strlen(ext->val);
    4746             :                                         } else {
    4747           0 :                                                 len = end-ext->val;
    4748             :                                         }
    4749           0 :                                         if (len == 0) {
    4750             :                                                 smart_str_appendl(buf, "anyType", sizeof("anyType")-1);
    4751             :                                         } else {
    4752           0 :                                                 smart_str_appendl(buf, ext->val, len);
    4753             :                                         }
    4754             :                                         smart_str_appendc(buf, ' ');
    4755           0 :                                         smart_str_appendl(buf, type->name, strlen(type->name));
    4756           0 :                                         if (end != NULL) {
    4757           0 :                                                 smart_str_appends(buf, end);
    4758             :                                         }
    4759             :                                 } else {
    4760             :                                         sdlTypePtr elementType;
    4761           2 :                                         if (type->attributes &&
    4762           1 :                                             (attr = zend_hash_str_find_ptr(type->attributes, SOAP_1_2_ENC_NAMESPACE":itemType",
    4763             :                                               sizeof(SOAP_1_2_ENC_NAMESPACE":itemType")-1)) != NULL &&
    4764           0 :                                                 attr->extraAttributes &&
    4765           0 :                                     (ext = zend_hash_str_find_ptr(attr->extraAttributes, WSDL_NAMESPACE":itemType", sizeof(WSDL_NAMESPACE":arrayType")-1)) != NULL) {
    4766           0 :                                                 smart_str_appends(buf, ext->val);
    4767             :                                                 smart_str_appendc(buf, ' ');
    4768           1 :                                         } else if (type->elements &&
    4769           0 :                                                    zend_hash_num_elements(type->elements) == 1 &&
    4770           0 :                                                    (zend_hash_internal_pointer_reset(type->elements),
    4771           0 :                                                     (elementType = zend_hash_get_current_data_ptr(type->elements)) != NULL) &&
    4772           0 :                                                    elementType->encode && elementType->encode->details.type_str) {
    4773           0 :                                                 smart_str_appends(buf, elementType->encode->details.type_str);
    4774             :                                                 smart_str_appendc(buf, ' ');
    4775             :                                         } else {
    4776             :                                                 smart_str_appendl(buf, "anyType ", 8);
    4777             :                                         }
    4778           1 :                                         smart_str_appendl(buf, type->name, strlen(type->name));
    4779           2 :                                         if (type->attributes &&
    4780           1 :                                             (attr = zend_hash_str_find_ptr(type->attributes, SOAP_1_2_ENC_NAMESPACE":arraySize",
    4781             :                                               sizeof(SOAP_1_2_ENC_NAMESPACE":arraySize")-1)) != NULL &&
    4782           0 :                                                 attr->extraAttributes &&
    4783           0 :                                             (ext = zend_hash_str_find_ptr(attr->extraAttributes, WSDL_NAMESPACE":itemType", sizeof(WSDL_NAMESPACE":arraySize")-1)) != NULL) {
    4784             :                                                 smart_str_appendc(buf, '[');
    4785           0 :                                                 smart_str_appends(buf, ext->val);
    4786             :                                                 smart_str_appendc(buf, ']');
    4787             :                                         } else {
    4788             :                                                 smart_str_appendl(buf, "[]", 2);
    4789             :                                         }
    4790             :                                 }
    4791             :                         } else {
    4792             :                                 smart_str_appendl(buf, "struct ", 7);
    4793          47 :                                 smart_str_appendl(buf, type->name, strlen(type->name));
    4794             :                                 smart_str_appendc(buf, ' ');
    4795             :                                 smart_str_appendl(buf, "{\n", 2);
    4796          95 :                                 if ((type->kind == XSD_TYPEKIND_RESTRICTION ||
    4797          48 :                                      type->kind == XSD_TYPEKIND_EXTENSION) && type->encode) {
    4798           1 :                                         encodePtr enc = type->encode;
    4799           7 :                                         while (enc && enc->details.sdl_type &&
    4800           1 :                                                enc != enc->details.sdl_type->encode &&
    4801           1 :                                                enc->details.sdl_type->kind != XSD_TYPEKIND_SIMPLE &&
    4802           1 :                                                enc->details.sdl_type->kind != XSD_TYPEKIND_LIST &&
    4803           1 :                                                enc->details.sdl_type->kind != XSD_TYPEKIND_UNION) {
    4804           1 :                                                 enc = enc->details.sdl_type->encode;
    4805             :                                         }
    4806           1 :                                         if (enc) {
    4807           0 :                                                 smart_str_appendl(buf, spaces.s->val, spaces.s->len);
    4808             :                                                 smart_str_appendc(buf, ' ');
    4809           0 :                                                 smart_str_appendl(buf, type->encode->details.type_str, strlen(type->encode->details.type_str));
    4810             :                                                 smart_str_appendl(buf, " _;\n", 4);
    4811             :                                         }
    4812             :                                 }
    4813          47 :                                 if (type->model) {
    4814          41 :                                         model_to_string(type->model, buf, level+1);
    4815             :                                 }
    4816          47 :                                 if (type->attributes) {
    4817             :                                         sdlAttributePtr attr;
    4818             : 
    4819           0 :                                         ZEND_HASH_FOREACH_PTR(type->attributes, attr) {
    4820           0 :                                                 smart_str_appendl(buf, spaces.s->val, spaces.s->len);
    4821             :                                                 smart_str_appendc(buf, ' ');
    4822           0 :                                                 if (attr->encode && attr->encode->details.type_str) {
    4823           0 :                                                         smart_str_appends(buf, attr->encode->details.type_str);
    4824             :                                                         smart_str_appendc(buf, ' ');
    4825             :                                                 } else {
    4826             :                                                         smart_str_appendl(buf, "UNKNOWN ", 8);
    4827             :                                                 }
    4828           0 :                                                 smart_str_appends(buf, attr->name);
    4829             :                                                 smart_str_appendl(buf, ";\n", 2);
    4830             :                                         } ZEND_HASH_FOREACH_END();
    4831             :                                 }
    4832          47 :                                 if (spaces.s) {
    4833           0 :                                         smart_str_appendl(buf, spaces.s->val, spaces.s->len);
    4834             :                                 }
    4835             :                                 smart_str_appendc(buf, '}');
    4836             :                         }
    4837             :                         break;
    4838             :                 default:
    4839             :                         break;
    4840             :         }
    4841             :         smart_str_free(&spaces);
    4842             :         smart_str_0(buf);
    4843         128 : }
    4844             : 
    4845           2 : static void delete_url(void *handle)
    4846             : {
    4847           2 :         php_url_free((php_url*)handle);
    4848           2 : }
    4849             : 
    4850         458 : static void delete_service(void *data)
    4851             : {
    4852         458 :         soapServicePtr service = (soapServicePtr)data;
    4853             : 
    4854         458 :         if (service->soap_functions.ft) {
    4855         457 :                 zend_hash_destroy(service->soap_functions.ft);
    4856         457 :                 efree(service->soap_functions.ft);
    4857             :         }
    4858             : 
    4859         458 :         if (service->typemap) {
    4860           8 :                 zend_hash_destroy(service->typemap);
    4861           8 :                 efree(service->typemap);
    4862             :         }
    4863             : 
    4864         458 :         if (service->soap_class.argc) {
    4865             :                 int i;
    4866           2 :                 for (i = 0; i < service->soap_class.argc;i++) {
    4867           1 :                         zval_ptr_dtor(&service->soap_class.argv[i]);
    4868             :                 }
    4869           1 :                 efree(service->soap_class.argv);
    4870             :         }
    4871             : 
    4872         458 :         if (service->actor) {
    4873          81 :                 efree(service->actor);
    4874             :         }
    4875         458 :         if (service->uri) {
    4876         458 :                 efree(service->uri);
    4877             :         }
    4878         458 :         if (service->sdl) {
    4879         410 :                 delete_sdl(service->sdl);
    4880             :         }
    4881         458 :         if (service->encoding) {
    4882           4 :                 xmlCharEncCloseFunc(service->encoding);
    4883             :         }
    4884         458 :         if (service->class_map) {
    4885          11 :                 zend_hash_destroy(service->class_map);
    4886          11 :                 FREE_HASHTABLE(service->class_map);
    4887             :         }
    4888         458 :         zval_ptr_dtor(&service->soap_object);
    4889         458 :         efree(service);
    4890         458 : }
    4891             : 
    4892           7 : static void delete_hashtable(void *data)
    4893             : {
    4894           7 :         HashTable *ht = (HashTable*)data;
    4895           7 :         zend_hash_destroy(ht);
    4896           7 :         efree(ht);
    4897           7 : }

Generated by: LCOV version 1.10

Generated at Sat, 30 May 2015 05:52:56 +0000 (16 hours ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.