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

Generated by: LCOV version 1.10

Generated at Sat, 29 Aug 2015 10:22:23 +0000 (2 days ago)

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