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: 2115 2565 82.5 %
Date: 2014-10-24 Functions: 61 65 93.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Fri, 24 Oct 2014 05:21:54 +0000 (7 days ago)

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