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

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:23 +0000 (28 hours ago)

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