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

Generated by: LCOV version 1.10

Generated at Sun, 18 Jan 2015 09:00:47 +0000 (7 days ago)

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