phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] api class.nusoap.php, NONE, 1.1.2.1 class.soap_client


From: Dan Kuykendall <address@hidden>
Subject: [Phpgroupware-cvs] api class.nusoap.php, NONE, 1.1.2.1 class.soap_client.php, NONE, 1.1.2.1 class.soap_server.php, NONE, 1.1.2.1 starter.inc.php, 1.1.1.1.2.22, 1.1.1.1.2.23
Date: Fri, 07 Nov 2003 09:05:45 +0000

Update of /cvsroot/phpgroupware/api
In directory subversions:/tmp/cvs-serv27648/api

Modified Files:
      Tag: proposal-branch
        starter.inc.php 
Added Files:
      Tag: proposal-branch
        class.nusoap.php class.soap_client.php class.soap_server.php 
Log Message:
initial soap interface

Index: starter.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/starter.inc.php,v
retrieving revision 1.1.1.1.2.22
retrieving revision 1.1.1.1.2.23
diff -C2 -d -r1.1.1.1.2.22 -r1.1.1.1.2.23
*** starter.inc.php     3 Nov 2003 20:21:42 -0000       1.1.1.1.2.22
--- starter.inc.php     7 Nov 2003 09:05:42 -0000       1.1.1.1.2.23
***************
*** 49,53 ****
        * Make sure we have a valid client type                                 
     *
        
\****************************************************************************/
!       if(!isset($GLOBALS['phpgw_interface']) || 
!preg_match("/^(browser|xmlrpc)$/i", $GLOBALS['phpgw_interface'] ))
        {
                $GLOBALS['phpgw_interface'] = 'browser';
--- 49,53 ----
        * Make sure we have a valid client type                                 
     *
        
\****************************************************************************/
!       if(!isset($GLOBALS['phpgw_interface']) || 
!preg_match("/^(browser|xmlrpc|soap)$/i", $GLOBALS['phpgw_interface'] ))
        {
                $GLOBALS['phpgw_interface'] = 'browser';

--- NEW FILE: class.soap_client.php ---
<?php
//      include_once(PHPGW_API.SEP.'class.api_nusoap.php'); 
/*

NuSOAP - Web Services Toolkit for PHP

Copyright (c) 2002 NuSphere Corporation

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

If you have any questions or comments, please email:

Dietrich Ayala
address@hidden
http://dietrich.ganx4.com/nusoap

NuSphere Corporation
http://www.nusphere.com

*/
/**
*
* api_soap_client higher level class for easy usage.
*
* usage:
*
* // instantiate client with server info
* $soapclient = new api_soap_client( string path [ ,boolean wsdl] );
*
* // call method, get results
* echo $soapclient->call( string methodname [ ,array parameters] );
*
* // bye bye client
* unset($soapclient);
*
* @author   Dietrich Ayala <address@hidden>
* @version  v 0.6.3
* @access   public
*/
class api_soap_client extends nusoap_base  {

        var $username = '';
        var $password = '';
        var $requestHeaders = false;
        var $responseHeaders;
        var $endpoint;
        var $error_str = false;
    var $proxyhost = '';
    var $proxyport = '';
    var $xml_encoding = '';
        var $http_encoding = false;
        var $timeout = 0;
        var $endpointType = '';
        var $persistentConnection = false;
        var $defaultRpcParams = false;
        
        /**
        * fault related variables
        *
        * @var      fault
        * @var      faultcode
        * @var      faultstring
        * @var      faultdetail
        * @access   public
        */
        var $fault, $faultcode, $faultstring, $faultdetail;

        /**
        * constructor
        *
        * @param    string $endpoint SOAP server or WSDL URL
        * @param    bool $wsdl optional, set to true if using WSDL
        * @param        int $portName optional portName in WSDL document
        * @access   public
        */
        function api_soap_client($endpoint,$wsdl = false){
                $this->endpoint = $endpoint;

                // make values
                if($wsdl){
                        $this->endpointType = 'wsdl';
                        $this->wsdlFile = $this->endpoint;
                        
                        // instantiate wsdl object and parse wsdl file
                        $this->debug('instantiating wsdl class with doc: 
'.$endpoint);
                        $this->wsdl =& new 
wsdl($this->wsdlFile,$this->proxyhost,$this->proxyport);
                        $this->debug("wsdl debug: \n".$this->wsdl->debug_str);
                        $this->wsdl->debug_str = '';
                        // catch errors
                        if($errstr = $this->wsdl->getError()){
                                $this->debug('got wsdl error: '.$errstr);
                                $this->setError('wsdl error: '.$errstr);
                        } elseif($this->operations = 
$this->wsdl->getOperations()){
                                $this->debug( 'got '.count($this->operations).' 
operations from wsdl '.$this->wsdlFile);
                        } else {
                                $this->debug( 'getOperations returned false');
                                $this->setError('no operations defined in the 
WSDL document!');
                        }
                }
        }

        /**
        * calls method, returns PHP native type
        *
        * @param    string $method SOAP server URL or path
        * @param    array $params array of parameters, can be associative or not
        * @param        string $namespace optional method namespace
        * @param        string $soapAction optional SOAPAction value
        * @param        boolean $headers optional array of soapval objects for 
headers
        * @param        boolean $rpcParams optional treat params as RPC for 
use="literal"
        *                   This can be used on a per-call basis to overrider 
defaultRpcParams.
        * @return       mixed
        * @access   public
        */
        function 
call($operation,$params=array(),$namespace='',$soapAction='',$headers=false,$rpcParams=null){
                $this->operation = $operation;
                $this->fault = false;
                $this->error_str = '';
                $this->request = '';
                $this->response = '';
                $this->faultstring = '';
                $this->faultcode = '';
                $this->opData = array();
                
                $this->debug("call: $operation, $params, $namespace, 
$soapAction, $headers, $rpcParams");
                $this->debug("endpointType: $this->endpointType");
                // if wsdl, get operation data and process parameters
                if($this->endpointType == 'wsdl' && $opData = 
$this->getOperationData($operation)){

                        $this->opData = $opData;
                        foreach($opData as $key => $value){
                                $this->debug("$key -> $value");
                        }
                        $soapAction = $opData['soapAction'];
                        $this->endpoint = $opData['endpoint'];
                        $namespace = isset($opData['input']['namespace']) ? 
$opData['input']['namespace'] :     'http://testuri.org';
                        $style = $opData['style'];
                        // add ns to ns array
                        if($namespace != '' && 
!isset($this->wsdl->namespaces[$namespace])){
                                $this->wsdl->namespaces['nu'] = $namespace;
            }
                        // serialize payload
                        
                        if($opData['input']['use'] == 'literal') {
                                if (is_null($rpcParams)) {
                                        $rpcParams = $this->defaultRpcParams;
                                }
                                if ($rpcParams) {
                                        $this->debug("serializing literal 
params for operation $operation");
                                        $payload = 
$this->wsdl->serializeRPCParameters($operation,'input',$params);
                                        $defaultNamespace = 
$this->wsdl->wsdl_info['targetNamespace'];
                                } else {
                                        $this->debug("serializing literal 
document for operation $operation");
                                        $payload = is_array($params) ? 
array_shift($params) : $params;
                                }
                        } else {
                                $this->debug("serializing encoded params for 
operation $operation");
                                $payload = 
"<".$this->wsdl->getPrefixFromNamespace($namespace).":$operation>".
                                
$this->wsdl->serializeRPCParameters($operation,'input',$params).
                                
'</'.$this->wsdl->getPrefixFromNamespace($namespace).":$operation>";
                        }
                        $this->debug('payload size: '.strlen($payload));
                        // serialize envelope
                        $soapmsg = 
$this->serializeEnvelope($payload,$this->requestHeaders,$this->wsdl->usedNamespaces,$style);
                        $this->debug("wsdl debug: \n".$this->wsdl->debug_str);
                        $this->wsdl->debug_str = '';
                } elseif($this->endpointType == 'wsdl') {
                        $this->setError( 'operation '.$operation.' not 
present.');
                        $this->debug("operation '$operation' not present.");
                        $this->debug("wsdl debug: \n".$this->wsdl->debug_str);
                        return false;
                // no wsdl
                } else {
                        // make message
                        if(!isset($style)){
                                $style = 'rpc';
                        }
            if($namespace == ''){
                $namespace = 'http://testuri.org';
                $this->wsdl->namespaces['ns1'] = $namespace;
            }
                        // serialize envelope
                        $payload = '';
                        foreach($params as $k => $v){
                                $payload .= $this->serialize_val($v,$k);
                        }
                        $payload = "<ns1:$operation 
xmlns:ns1=\"$namespace\">\n".$payload."</ns1:$operation>\n";
                        $soapmsg = 
$this->serializeEnvelope($payload,$this->requestHeaders);
                }
                $this->debug("endpoint: $this->endpoint, soapAction: 
$soapAction, namespace: $namespace");
                // send
                $this->debug('sending msg (len: '.strlen($soapmsg).") w/ 
soapaction '$soapAction'...");
                $return = $this->send($soapmsg,$soapAction,$this->timeout);
                if($errstr = $this->getError()){
                        $this->debug('Error: '.$errstr);
                        return false;
                } else {
                        $this->return = $return;
                        $this->debug('sent message successfully and got a(n) 
'.gettype($return).' back');
                        
                        // fault?
                        if(is_array($return) && isset($return['faultcode'])){
                                $this->debug('got fault');
                                $this->setError($return['faultcode'].': 
'.$return['faultstring']);
                                $this->fault = true;
                                foreach($return as $k => $v){
                                        $this->$k = $v;
                                        $this->debug("$k = $v<br>");
                                }
                                return $return;
                        } else {
                                // array of return values
                                if(is_array($return)){
                                        // multiple 'out' parameters
                                        if(sizeof($return) > 1){
                                                return $return;
                                        }
                                        // single 'out' parameter
                                        return array_shift($return);
                                // nothing returned (ie, echoVoid)
                                } else {
                                        return "";
                                }
                        }
                }
        }

        /**
        * get available data pertaining to an operation
        *
        * @param    string $operation operation name
        * @return       array array of data pertaining to the operation
        * @access   public
        */
        function getOperationData($operation){
                if(isset($this->operations[$operation])){
                        return $this->operations[$operation];
                }
                $this->debug("No data for operation: $operation");
        }

    /**
    * send the SOAP message
    *
    * Note: if the operation has multiple return values
    * the return value of this method will be an array
    * of those values.
    *
        * @param    string $msg a SOAPx4 soapmsg object
        * @param    string $soapaction SOAPAction value
        * @param    integer $timeout set timeout in seconds
        * @return       mixed native PHP types.
        * @access   private
        */
        function send($msg, $soapaction = '', $timeout=0) {
                // detect transport
                switch(true){
                        // http(s)
                        case ereg('^http',$this->endpoint):
                                $this->debug('transporting via HTTP');
                                if($this->persistentConnection && 
is_object($this->persistentConnection)){
                                        $http =& $this->persistentConnection;
                                } else {
                                        $http = new 
soap_transport_http($this->endpoint);
                                        // pass encoding into transport layer, 
so appropriate http headers are sent
                                        $http->soap_defencoding = 
$this->soap_defencoding;
                                }
                                $http->setSOAPAction($soapaction);
                                if($this->proxyhost && $this->proxyport){
                                        
$http->setProxy($this->proxyhost,$this->proxyport);
                                }
                if($this->username != '' && $this->password != '') {
                                        
$http->setCredentials($this->username,$this->password);
                                }
                                if($this->http_encoding != ''){
                                        
$http->setEncoding($this->http_encoding);
                                }
                                $this->debug('sending message, length: 
'.strlen($msg));
                                if(ereg('^http:',$this->endpoint)){
                                //if(strpos($this->endpoint,'http:')){
                                        $response = $http->send($msg,$timeout);
                                } elseif(ereg('^https',$this->endpoint)){
                                //} elseif(strpos($this->endpoint,'https:')){
                                        //if(phpversion() == '4.3.0-dev'){
                                                //$response = 
$http->send($msg,$timeout);
                                //$this->request = $http->outgoing_payload;
                                                //$this->response = 
$http->incoming_payload;
                                        //} else
                                        if (extension_loaded('curl')) {
                                                $response = 
$http->sendHTTPS($msg,$timeout);
                                        } else {
                                                $this->setError('CURL 
Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
                                        }                                       
                        
                                } else {
                                        $this->setError('no http/s in endpoint 
url');
                                }
                                $this->request = $http->outgoing_payload;
                                $this->response = $http->incoming_payload;
                                $this->debug("transport debug 
data...\n".$http->debug_str);
                                // save transport object if using persistent 
connections
                                if($this->persistentConnection && 
!is_object($this->persistentConnection)){
                                        $this->persistentConnection = $http;
                                }
                                if($err = $http->getError()){
                                        $this->setError('HTTP Error: '.$err);
                                        return false;
                                } elseif($this->getError()){
                                        return false;
                                } else {
                                        $this->debug('got response, length: 
'.strlen($response));
                                        return $this->parseResponse($response);
                                }
                        break;
                        default:
                                $this->setError('no transport found, or 
selected transport is not yet supported!');
                        return false;
                        break;
                }
        }

        /**
        * processes SOAP message returned from server
        *
        * @param        string unprocessed response data from server
        * @return       mixed value of the message, decoded into a PHP type
        * @access   private
        */
    function parseResponse($data) {
                $this->debug('Entering parseResponse(), about to create 
soap_parser instance');
                $parser = new 
soap_parser($data,$this->xml_encoding,$this->operation);
                // if parse errors
                if($errstr = $parser->getError()){
                        $this->setError( $errstr);
                        // destroy the parser object
                        unset($parser);
                        return false;
                } else {
                        // get SOAP headers
                        $this->responseHeaders = $parser->getHeaders();
                        // get decoded message
                        $return = $parser->get_response();
                        // add parser debug data to our debug
                        $this->debug($parser->debug_str);
            // add document for doclit support
            $this->document = $parser->document;
                        // destroy the parser object
                        unset($parser);
                        // return decode message
                        return $return;
                }
         }

        /**
        * set the SOAP headers
        *
        * @param        $headers string XML
        * @access   public
        */
        function setHeaders($headers){
                $this->requestHeaders = $headers;
        }

        /**
        * get the response headers
        *
        * @return       mixed object SOAPx4 soapval object or empty if no 
headers
        * @access   public
        */
        function getHeaders(){
            if($this->responseHeaders != '') {
                        return $this->responseHeaders;
            }
        }

        /**
        * set proxy info here
        *
        * @param    string $proxyhost
        * @param    string $proxyport
        * @access   public
        */
        function setHTTPProxy($proxyhost, $proxyport) {
                $this->proxyhost = $proxyhost;
                $this->proxyport = $proxyport;
        }

        /**
        * if authenticating, set user credentials here
        *
        * @param    string $username
        * @param    string $password
        * @access   public
        */
        function setCredentials($username, $password) {
                $this->username = $username;
                $this->password = $password;
        }
        
        /**
        * use HTTP encoding
        *
        * @param    string $enc
        * @access   public
        */
        function setHTTPEncoding($enc='gzip, deflate'){
                $this->http_encoding = $enc;
        }
        
        /**
        * use HTTP persistent connections if possible
        *
        * @access   public
        */
        function useHTTPPersistentConnection(){
                $this->persistentConnection = true;
        }
        
        /**
        * gets the default RPC parameter setting.
        * If true, default is that call params are like RPC even for document 
style.
        * Each call() can override this value.
        *
        * @access public
        */
        function getDefaultRpcParams() {
                return $this->defaultRpcParams;
        }

        /**
        * sets the default RPC parameter setting.
        * If true, default is that call params are like RPC even for document 
style
        * Each call() can override this value.
        *
        * @param    boolean $rpcParams
        * @access public
        */
        function setDefaultRpcParams($rpcParams) {
                $this->defaultRpcParams = $rpcParams;
        }
        
        /**
        * dynamically creates proxy class, allowing user to directly call 
methods from wsdl
        *
        * @return   object soap_proxy object
        * @access   public
        */
        function getProxy(){
                $evalStr = '';
                foreach($this->operations as $operation => $opData){
                        if($operation != ''){
                                // create param string
                                $paramStr = '';
                                if(sizeof($opData['input']['parts']) > 0){
                                        foreach($opData['input']['parts'] as 
$name => $type){
                                                $paramStr .= "\$$name,";
                                        }
                                        $paramStr = 
substr($paramStr,0,strlen($paramStr)-1);
                                }
                                $opData['namespace'] = 
!isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
                                $evalStr .= "function $operation ($paramStr){
                                        // load params into array
                                        \$params = array($paramStr);
                                        return 
\$this->call('$operation',\$params,'".$opData['namespace']."','".$opData['soapAction']."');
                                }";
                                unset($paramStr);
                        }
                }
                $r = rand();
                $evalStr = 'class soap_proxy_'.$r.' extends api_soap_client {
                                '.$evalStr.'
                        }';
                //print "proxy class:<pre>$evalStr</pre>";
                // eval the class
                eval($evalStr);
                // instantiate proxy object
                eval("\$proxy = new soap_proxy_$r('');");
                // transfer current wsdl data to the proxy thereby avoiding 
parsing the wsdl twice
                $proxy->endpointType = 'wsdl';
                $proxy->wsdlFile = $this->wsdlFile;
                $proxy->wsdl = $this->wsdl;
                $proxy->operations = $this->operations;
                $proxy->defaultRpcParams = $this->defaultRpcParams;
                return $proxy;
        }
}

--- NEW FILE: class.nusoap.php ---
<?php

/*

NuSOAP - Web Services Toolkit for PHP

Copyright (c) 2002 NuSphere Corporation

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
[...3041 lines suppressed...]
                //
                foreach($children as $child_pos){
                        if(isset($struct)){
                                $params[] = 
&$this->message[$child_pos]['result'];
                        } else {
                                        
$params[$this->message[$child_pos]['name']] = 
&$this->message[$child_pos]['result'];
                        }
                }
                        }
                        return is_array($params) ? $params : array();
                } else {
                $this->debug('no children');
            if(strpos($this->message[$pos]['cdata'],'&')){
                        return  
strtr($this->message[$pos]['cdata'],array_flip($this->entities));
            } else {
                return $this->message[$pos]['cdata'];
            }
                }
        }
}

--- NEW FILE: class.soap_server.php ---
<?php
        include_once(PHPGW_API.SEP.'class.nusoap.php'); 
/**
*
* api_soap_server allows the user to create a SOAP server
* that is capable of receiving messages and returning responses
*
* NOTE: WSDL functionality is experimental
*
* @author   Dietrich Ayala <address@hidden>
* @version  v 0.6.3
* @access   public
*/
class api_soap_server extends nusoap_base
{

        var $service = ''; // service name
    var $operations = array(); // assoc array of operations => opData
    var $responseHeaders = false;
        var $headers = '';
        var $request = '';
        var $charset_encoding = 'UTF-8';
        var $fault = false;
        var $result = 'successful';
        var $wsdl = false;
        var $externalWSDLURL = false;
    var $debug_flag = false;
        
        /**
        * constructor
    * the optional parameter is a path to a WSDL file that you'd like to bind 
the server instance to.
        *
    * @param string $wsdl path or URL to a WSDL file
        * @access   public
        */
        function api_soap_server($wsdl=false){

                // turn on debugging?
                global $debug;
                if(isset($debug)){
                        $this->debug_flag = 0;
                }

                // wsdl
                if($wsdl){
                        $this->wsdl = new wsdl($wsdl);
                        $this->externalWSDLURL = $wsdl;
                        if($err = $this->wsdl->getError()){
                                die('WSDL ERROR: '.$err);
                        }
                }
        }

        /**
        * processes request and returns response
        *
        * @param    string $data usually is the value of $HTTP_RAW_POST_DATA
        * @access   public
        */
        function service($data){
                // print wsdl
                global $QUERY_STRING;
                if(isset($_SERVER['QUERY_STRING'])){
                        $qs = $_SERVER['QUERY_STRING'];
                } elseif(isset($GLOBALS['QUERY_STRING'])){
                        $qs = $GLOBALS['QUERY_STRING'];
                } elseif(isset($QUERY_STRING) && $QUERY_STRING != ''){
                        $qs = $QUERY_STRING;
                }
                // gen wsdl
                if(isset($qs) && ereg('wsdl', $qs) ){
                        if($this->externalWSDLURL){
                                header('Location: '.$this->externalWSDLURL);
                                exit();
                        } else {
//                              header("Content-Type: text/xml\r\n");
                                print $this->wsdl->serialize();
                                exit();
                        }
                }
                
                // print web interface
                if($data == '' && $this->wsdl){
                        print $this->webDescription();
                } else {
                        
                        // $response is the serialized response message
                        $response = $this->parse_request($data);
                        return;
                        $this->debug('server sending...');
                        $payload = $response;
            // add debug data if in debug mode
                        if(isset($this->debug_flag) && $this->debug_flag == 1){
                $payload .= "<!--\n".str_replace('--','- 
-',$this->debug_str)."\n-->";
            }
                        // print headers
                        if($this->fault){
                                $header[] = "HTTP/1.0 500 Internal Server 
Error\r\n";
                                $header[] = "Status: 500 Internal Server 
Error\r\n";
                        } else {
                                $header[] = "Status: 200 OK\r\n";
                        }
                        $header[] = "Server: $this->title Server 
v$this->version\r\n";
                        $header[] = "Connection: Close\r\n";
//                      $header[] = "Content-Type: text/xml; 
charset=$this->charset_encoding\r\n";
                        $header[] = "Content-Length: 
".strlen($payload)."\r\n\r\n";
                        reset($header);
                        foreach($header as $hdr){
                                header($hdr);
                        }
                        $this->response = join("\r\n",$header).$payload;
                        print $payload;
                }
        }

        /**
        * parses request and posts response
        *
        * @param    string $data XML string
        * @return       string XML response msg
        * @access   private
        */
        function parse_request($data='') {
                $this->debug('entering parseRequest() on '.date('H:i Y-m-d'));
        $dump = '';
                // get headers
                if(function_exists('getallheaders')){
                        $this->headers = getallheaders();
                        foreach($this->headers as $k=>$v){
                                $dump .= "$k: $v\r\n";
                                $this->debug("$k: $v");
                        }
                        // get SOAPAction header
                        if(isset($this->headers['SOAPAction'])){
                                $this->SOAPAction = 
str_replace('"','',$this->headers['SOAPAction']);
                        }
                        // get the character encoding of the incoming request
                        if(strpos($this->headers['Content-Type'],'=')){
                                $enc = 
str_replace('"','',substr(strstr($this->headers["Content-Type"],'='),1));
                                if(eregi('^(ISO-8859-1|US-ASCII|UTF-8)$',$enc)){
                                        $this->xml_encoding = $enc;
                                } else {
                                        $this->xml_encoding = 'us-ascii';
                                }
                        }
                        $this->debug('got encoding: '.$this->charset_encoding);
                } elseif(is_array($_SERVER)){
                        $this->headers['User-Agent'] = 
$_SERVER['HTTP_USER_AGENT'];
                        $this->SOAPAction = isset($_SERVER['SOAPAction']) ? 
$_SERVER['SOAPAction'] : '';
                }
                $this->request = $dump."\r\n\r\n".$data;
                // parse response, get soap parser obj
                $parser = new soap_parser($data,$this->charset_encoding);
                // if fault occurred during message parsing
                if($err = $parser->getError()){
                        // parser debug
                        $this->debug("parser debug: \n".$parser->debug_str);
                        $this->result = 'fault: error in msg parsing: '.$err;
                        $this->fault('Server',"error in msg parsing:\n".$err);
                        // return soapresp
                        return $this->fault->serialize();
                // else successfully parsed request into soapval object
                } else {
                        // get/set methodname
                        $this->methodname = $parser->root_struct_name;

                        $this->debug('method name: '.$this->methodname);
//echo '$this->methodname<br>';
//html_print_r($this->methodname);
                        // evaluate message, getting back parameters
                        $this->debug('calling parser->get_response()');
                        $request_data = $parser->get_response();
                        $this->inputs = $request_data;
                        return;
                        
echo '$request_data<br>';
html_print_r($request_data);
exit;
                        // parser debug
                        $this->debug("parser debug: \n".$parser->debug_str);
                        // verify that request parameters match the method's 
signature
                        
if($this->verify_method($this->methodname,$request_data)){
                                // if there are parameters to pass
                    $this->debug('params var dump 
'.$this->varDump($request_data));
                                if($request_data){
                                        $this->debug("calling 
'$this->methodname' with params");
                                        if (! 
function_exists('call_user_func_array')) {
                                                $this->debug('calling method 
using eval()');
                                                $funcCall = 
$this->methodname.'(';
                                                foreach($request_data as 
$param) {
                                                        $funcCall .= 
"\"$param\",";
                                                }
                                                $funcCall = substr($funcCall, 
0, -1).')';
                                                $this->debug('function 
call:<br>'.$funcCall);
                                                @eval("\$method_response = 
$funcCall;");
                                        } else {
                                                $this->debug('calling method 
using call_user_func_array()');
                                                $method_response = 
call_user_func_array("$this->methodname",$request_data);
                                        }
                        $this->debug('response var 
dump'.$this->varDump($method_response));
                                } else {
                                        // call method w/ no parameters
                                        $this->debug("calling $this->methodname 
w/ no params");
                                        $m = $this->methodname;
                                        $method_response = @$m();
                                }

                                
                                $this->debug("done calling method: 
$this->methodname, received $method_response of 
type".gettype($method_response));
                                // if we got nothing back. this might be ok 
(echoVoid)
                                if(isset($method_response) && $method_response 
!= '' || is_bool($method_response)) {
                                        // if fault
                                        if(get_class($method_response) == 
'soap_fault'){
                                                $this->debug('got a fault 
object from method');
                                                $this->fault = $method_response;
                                                return 
$method_response->serialize();
                                        // if return val is soapval object
                                        } elseif(get_class($method_response) == 
'soapval'){
                                                $this->debug('got a soapval 
object from method');
                                                $return_val = 
$method_response->serialize();
                                        // returned other
                                        } else {
                                                $this->debug('got a(n) 
'.gettype($method_response).' from method');
                                                $this->debug('serializing 
return value');
                                                if($this->wsdl){
                                                        // weak attempt at 
supporting multiple output params
                                                        
if(sizeof($this->opData['output']['parts']) > 1){
                                                        $opParams = 
$method_response;
                                                    } else {
                                                        $opParams = 
array($method_response);
                                                    }
                                                    $return_val = 
$this->wsdl->serializeRPCParameters($this->methodname,'output',$opParams);
                                                } else {
                                                    $return_val = 
$this->serialize_val($method_response);
                                                }
                                        }
                                        $this->debug('return 
val:'.$this->varDump($return_val));
                                } else {
                                        $return_val = '';
                                        $this->debug('got no response from 
method');
                                }
                                $this->debug('serializing response');
                                $payload = 
'<'.$this->methodname."Response>".$return_val.'</'.$this->methodname."Response>";
                                $this->result = 'successful';
                                if($this->wsdl){
                                        //if($this->debug_flag){
                                $this->debug("WSDL debug 
data:\n".$this->wsdl->debug_str);
                        //      }
                                        // Added: In case we use a WSDL, return 
a serialized env. WITH the usedNamespaces.
                                        return 
$this->serializeEnvelope($payload,$this->responseHeaders,$this->wsdl->usedNamespaces,$this->opData['style']);
                                } else {
                                        return 
$this->serializeEnvelope($payload,$this->responseHeaders);
                                }
                        } else {
                                // debug
                                $this->debug('ERROR: request not verified 
against method signature');
                                $this->result = 'fault: request failed 
validation against method signature';
                                // return fault
                                $this->fault('Server',"Operation 
'$this->methodname' not defined in service.");
                                return $this->fault->serialize();
                        }
                }
        }


        function handle_result($method_response)
        {
                                $this->debug("done calling method: 
$this->methodname, received $method_response of 
type".gettype($method_response));
                                // if we got nothing back. this might be ok 
(echoVoid)
                                if(isset($method_response) && $method_response 
!= '' || is_bool($method_response)) {
                                        // if fault
                                        if(get_class($method_response) == 
'soap_fault'){
                                                $this->debug('got a fault 
object from method');
                                                $this->fault = $method_response;
                                                return 
$method_response->serialize();
                                        // if return val is soapval object
                                        } elseif(get_class($method_response) == 
'soapval'){
                                                $this->debug('got a soapval 
object from method');
                                                $return_val = 
$method_response->serialize();
                                        // returned other
                                        } else {
                                                $this->debug('got a(n) 
'.gettype($method_response).' from method');
                                                $this->debug('serializing 
return value');
                                                if($this->wsdl){
                                                        // weak attempt at 
supporting multiple output params
                                                        
if(sizeof($this->opData['output']['parts']) > 1){
                                                        $opParams = 
$method_response;
                                                    } else {
                                                        $opParams = 
array($method_response);
                                                    }
                                                    $return_val = 
$this->wsdl->serializeRPCParameters($this->methodname,'output',$opParams);
                                                } else {
                                                    $return_val = 
$this->serialize_val($method_response);
                                                }
                                        }
                                        $this->debug('return 
val:'.$this->varDump($return_val));
                                } else {
                                        $return_val = '';
                                        $this->debug('got no response from 
method');
                                }
                                $this->debug('serializing response');
                                $payload = 
'<'.$this->methodname."Response>".$return_val.'</'.$this->methodname."Response>";
                                $this->result = 'successful';
                                if($this->wsdl){
                                        //if($this->debug_flag){
                                $this->debug("WSDL debug 
data:\n".$this->wsdl->debug_str);
                        //      }
                                        // Added: In case we use a WSDL, return 
a serialized env. WITH the usedNamespaces.
                                        return 
$this->serializeEnvelope($payload,$this->responseHeaders,$this->wsdl->usedNamespaces,$this->opData['style']);
                                } else {
                                        return 
$this->serializeEnvelope($payload,$this->responseHeaders);
                                }
        }       

        
        /**
        * takes the value that was created by parsing the request
        * and compares to the method's signature, if available.
        *
        * @param        mixed
        * @return       boolean
        * @access   private
        */
        function verify_method($operation,$request){
                if(isset($this->wsdl) && is_object($this->wsdl)){
                        if($this->wsdl->getOperationData($operation)){
                                return true;
                        }
            } elseif(isset($this->operations[$operation])){
                        return true;
                }
                return false;
        }

        /**
        * add a method to the dispatch map
        *
        * @param    string $methodname
        * @param    string $in array of input values
        * @param    string $out array of output values
        * @access   public
        */
        function add_to_map($methodname,$in,$out){
                        $this->operations[$methodname] = array('name' => 
$methodname,'in' => $in,'out' => $out);
        }

        /**
        * register a service with the server
        *
        * @param    string $methodname
        * @param    string $in assoc array of input values: key = param name, 
value = param type
        * @param    string $out assoc array of output values: key = param name, 
value = param type
        * @param        string $namespace
        * @param        string $soapaction
        * @param        string $style (rpc|literal)
        * @access   public
        */
        function 
register($name,$in=false,$out=false,$namespace=false,$soapaction=false,$style=false,$use=false){
                if($this->externalWSDLURL){
                        die('You cannot bind to an external WSDL file, and 
register methods outside of it! Please choose either WSDL or no WSDL.');
                }
            if(false == $in) {
                }
                if(false == $out) {
                }
                if(false == $namespace) {
                }
                if(false == $soapaction) {
                        global $SERVER_NAME, $SCRIPT_NAME;
                        $soapaction = "http://$SERVER_NAME$SCRIPT_NAME";;
                }
                if(false == $style) {
                        $style = "rpc";
                }
                if(false == $use) {
                        $use = "encoded";
                }
                
                $this->operations[$name] = array(
            'name' => $name,
            'in' => $in,
            'out' => $out,
            'namespace' => $namespace,
            'soapaction' => $soapaction,
            'style' => $style);
        if($this->wsdl){
                
$this->wsdl->addOperation($name,$in,$out,$namespace,$soapaction,$style,$use);
            }
                return true;
        }

        /**
        * create a fault. this also acts as a flag to the server that a fault 
has occured.
        *
        * @param        string faultcode
        * @param        string faultactor
        * @param        string faultstring
        * @param        string faultdetail
        * @access   public
        */
        function fault($faultcode,$faultactor,$faultstring='',$faultdetail=''){
                $this->fault = new 
soap_fault($faultcode,$faultactor,$faultstring,$faultdetail);
        }

    /**
    * prints html description of services
    *
    * @access private
    */
    function webDescription(){
                $b = '
                <html><head><title>NuSOAP: '.$this->wsdl->serviceName.'</title>
                <style type="text/css">
                    body    { font-family: arial; color: #000000; 
background-color: #ffffff; margin: 0px 0px 0px 0px; }
                    p       { font-family: arial; color: #000000; margin-top: 
0px; margin-bottom: 12px; }
                    pre { background-color: silver; padding: 5px; font-family: 
Courier New; font-size: x-small; color: #000000;}
                    ul      { margin-top: 10px; margin-left: 20px; }
                    li      { list-style-type: none; margin-top: 10px; color: 
#000000; }
                    .content{
                        margin-left: 0px; padding-bottom: 2em; }
                    .nav {
                        padding-top: 10px; padding-bottom: 10px; padding-left: 
15px; font-size: .70em;
                        margin-top: 10px; margin-left: 0px; color: #000000;
                        background-color: #ccccff; width: 20%; margin-left: 
20px; margin-top: 20px; }
                    .title {
                        font-family: arial; font-size: 26px; color: #ffffff;
                        background-color: #999999; width: 105%; margin-left: 
0px;
                        padding-top: 10px; padding-bottom: 10px; padding-left: 
15px;}
                    .hidden {
                        position: absolute; visibility: hidden; z-index: 200; 
left: 250px; top: 100px;
                        font-family: arial; overflow: hidden; width: 600;
                        padding: 20px; font-size: 10px; background-color: 
#999999;
                        layer-background-color:#FFFFFF; }
                    a,a:active  { color: charcoal; font-weight: bold; }
                    a:visited   { color: #666666; font-weight: bold; }
                    a:hover     { color: cc3300; font-weight: bold; }
                </style>
                <script language="JavaScript" type="text/javascript">
                <!--
                // POP-UP CAPTIONS...
                function lib_bwcheck(){ //Browsercheck (needed)
                    this.ver=navigator.appVersion
                    this.agent=navigator.userAgent
                    this.dom=document.getElementById?1:0
                    this.opera5=this.agent.indexOf("Opera 5")>-1
                    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && 
!this.opera5)?1:0;
                    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && 
!this.opera5)?1:0;
                    this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
                    this.ie=this.ie4||this.ie5||this.ie6
                    this.mac=this.agent.indexOf("Mac")>-1
                    this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
                    this.ns4=(document.layers && !this.dom)?1:0;
                    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || 
this.ns6 || this.opera5)
                    return this
                }
                var bw = new lib_bwcheck()
                //Makes crossbrowser object.
                function makeObj(obj){
                    this.evnt=bw.dom? 
document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
                    if(!this.evnt) return false
                    this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0;
                    
this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0;
                    this.writeIt=b_writeIt;
                    return this
                }
                // A unit of measure that will be added when setting the 
position of a layer.
                //var px = bw.ns4||window.opera?"":"px";
                function b_writeIt(text){
                    if (bw.ns4){this.wref.write(text);this.wref.close()}
                    else this.wref.innerHTML = text
                }
                //Shows the messages
                var oDesc;
                function popup(divid){
                    if(oDesc = new makeObj(divid)){
                        oDesc.css.visibility = "visible"
                    }
                }
                function popout(){ // Hides message
                    if(oDesc) oDesc.css.visibility = "hidden"
                }
                //-->
                </script>
                </head>
                <body>
                <div class=content>
                        <br><br>
                        <div class=title>'.$this->wsdl->serviceName.'</div>
                        <div class=nav>
                                <p>View the <a 
href="'.$GLOBALS['PHP_SELF'].'?wsdl">WSDL</a> for the service.
                                Click on an operation name to view it&apos;s 
details.</p>
                                <ul>';
                                foreach($this->wsdl->getOperations() as $op => 
$data){
                                    $b .= "<li><a href='#' 
onclick=\"popup('$op')\">$op</a></li>";
                                    // create hidden div
                                    $b .= "<div id='$op' class='hidden'>
                                    <a href='#' onclick='popout()'><font 
color='#ffffff'>Close</font></a><br><br>";
                                    foreach($data as $donnie => $marie){ // 
loop through opdata
                                                if($donnie == 'input' || 
$donnie == 'output'){ // show input/output data
                                                    $b .= "<font 
color='white'>".ucfirst($donnie).':</font><br>';
                                                    foreach($marie as $captain 
=> $tenille){ // loop through data
                                                                if($captain == 
'parts'){ // loop thru parts
                                                                    $b .= 
"&nbsp;&nbsp;$captain:<br>";
                                                        
//if(is_array($tenille)){
                                                                        
foreach($tenille as $joanie => $chachi){
                                                                                
        $b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
                                                                        }
                                                                //}
                                                                } else {
                                                                    $b .= 
"&nbsp;&nbsp;$captain: $tenille<br>";
                                                                }
                                                    }
                                                } else {
                                                    $b .= "<font 
color='white'>".ucfirst($donnie).":</font> $marie<br>";
                                                }
                                    }
                                        $b .= '</div>';
                                }
                                $b .= '
                                <ul>
                        </div>
                </div></body></html>';
                return $b;
    }

    /**
    * sets up wsdl object
    * this acts as a flag to enable internal WSDL generation
    * NOTE: NOT FUNCTIONAL
    *
    * @param string $serviceName, name of the service
    * @param string $namespace, tns namespace
    */
    function configureWSDL($serviceName,$namespace = false,$endpoint = 
false,$style='rpc', $transport = 'http://schemas.xmlsoap.org/soap/http')
    {
                $SERVER_NAME = isset($_SERVER['SERVER_NAME']) ? 
$_SERVER['SERVER_NAME'] : $GLOBALS['SERVER_NAME'];
                $SCRIPT_NAME = isset($_SERVER['SCRIPT_NAME']) ? 
$_SERVER['SCRIPT_NAME'] : $GLOBALS['SCRIPT_NAME'];
        if(false == $namespace) {
            $namespace = "http://$SERVER_NAME/soap/$serviceName";;
        }
        
        if(false == $endpoint) {
            $endpoint = "http://$SERVER_NAME$SCRIPT_NAME";;
        }
        
                $this->wsdl = new wsdl;
                $this->wsdl->serviceName = $serviceName;
        $this->wsdl->endpoint = $endpoint;
                $this->wsdl->namespaces['tns'] = $namespace;
                $this->wsdl->namespaces['soap'] = 
'http://schemas.xmlsoap.org/wsdl/soap/';
                $this->wsdl->namespaces['wsdl'] = 
'http://schemas.xmlsoap.org/wsdl/';
        $this->wsdl->bindings[$serviceName.'Binding'] = array(
                'name'=>$serviceName.'Binding',
            'style'=>$style,
            'transport'=>$transport,
            'portType'=>$serviceName.'PortType');
        $this->wsdl->ports[$serviceName.'Port'] = array(
                'binding'=>$serviceName.'Binding',
            'location'=>$endpoint,
            'bindingType'=>'http://schemas.xmlsoap.org/wsdl/soap/');
    }
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]