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

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:18 +0000 (2 days ago)

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