cvs: pear /SOAP Client.php Message.php Parser.php Server.php Transport.php Value.php /SOAP/Transport HTTP.php SMTP.php /SOAP/Type dateTime.php
hexBinary.php /SOAP/interop client_params.php client_round2_base.php server_soapinterop_groupB.php

From: Date: Mon, 25 Feb 2002 18:59:51 +0000
Subject: cvs: pear /SOAP Client.php Message.php Parser.php Server.php Transport.php Value.php /SOAP/Transport HTTP.php SMTP.php /SOAP/Type dateTime.php
hexBinary.php /SOAP/interop client_params.php client_round2_base.php server_soapinterop_groupB.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-2617@lists.php.net to get a copy of this message
shane Mon Feb 25 13:59:51 2002 EDT Modified files: /pear/SOAP Client.php Message.php Parser.php Server.php Transport.php Value.php /pear/SOAP/Transport HTTP.php SMTP.php /pear/SOAP/Type dateTime.php hexBinary.php /pear/SOAP/interop client_params.php client_round2_base.php server_soapinterop_groupB.php Log: ok, so I lied, here's Sebastian's patch also, fixed server I broke last night.

Index: pear/SOAP/Client.php diff -u pear/SOAP/Client.php:1.5 pear/SOAP/Client.php:1.6 --- pear/SOAP/Client.php:1.5 Mon Feb 25 00:06:35 2002 +++ pear/SOAP/Client.php Mon Feb 25 13:59:46 2002 @@ -17,13 +17,14 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: Client.php,v 1.5 2002/02/25 05:06:35 shane Exp $ +// $Id: Client.php,v 1.6 2002/02/25 18:59:46 shane Exp $ // -require_once "PEAR.php"; -require_once "SOAP/Transport.php"; -require_once "SOAP/Message.php"; -require_once "SOAP/Value.php"; -require_once "SOAP/WSDL.php"; + +require_once 'PEAR.php'; +require_once 'SOAP/Transport.php'; +require_once 'SOAP/Message.php'; +require_once 'SOAP/Value.php'; +require_once 'SOAP/WSDL.php'; /** * SOAP Client Class @@ -36,7 +37,7 @@ * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4 * * @access public -* @version $Id: Client.php,v 1.5 2002/02/25 05:06:35 shane Exp $ +* @version $Id: Client.php,v 1.6 2002/02/25 18:59:46 shane Exp $ * @package SOAP::Client * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates * @author Stig Bakken <ssb@fast.no> Conversion to PEAR @@ -47,7 +48,7 @@ var $fault, $faultcode, $faultstring, $faultdetail; var $endpoint, $portName; var $debug_flag = false; - var $endpointType = ""; + var $endpointType = ''; var $wsdl = NULL; /** @@ -66,7 +67,7 @@ // make values if ($wsdl) { - $this->endpointType = "wsdl"; + $this->endpointType = 'wsdl'; // instantiate wsdl class $this->wsdl = new SOAP_WSDL($this->endpoint); } @@ -106,7 +107,8 @@ function call($method,$params=array(),$namespace=false,$soapAction=false) { $this->fault = FALSE; - if ($this->endpointType == "wsdl") { + + if ($this->endpointType == 'wsdl') { // get portName if (!$this->portName) { $this->portName = $this->wsdl->getPortName($method); @@ -119,10 +121,12 @@ $this->debug("portName: $this->portName"); // get operation data if ($opData = $this->wsdl->getOperationData($this->portName,$method)) { - $soapAction = $opData["soapAction"]; + $soapAction = $opData['soapAction']; + // set input params - $i = count($opData["input"]["parts"])-1; - foreach ($opData["input"]["parts"] as $name => $type) { + $i = count($opData['input']['parts'])-1; + + foreach ($opData['input']['parts'] as $name => $type) { if (isset($params[$name])) { $nparams[$name] = $params[$name]; } else { @@ -139,8 +143,8 @@ // get namespace if (!$namespace && $this->endpointType == 'wsdl') { $namespace = $this->wsdl->getNamespace($this->portName,$method); - #if ($this->endpointType != "wsdl") { - # //die("method call requires namespace if wsdl is not available!"); + #if ($this->endpointType != 'wsdl') { + # //die('method call requires namespace if wsdl is not available!'); #} elseif (!$namespace = $this->wsdl->getNamespace($this->portName,$method)) { # //die("no namespace found in wsdl for operation: $method!"); #} @@ -155,8 +159,9 @@ $soap_transport = new SOAP_Transport($this->endpoint, $this->debug_flag); - $this->debug($dbg."instantiated client successfully"); + $this->debug($dbg.'instantiated client successfully'); $this->debug("endpoint: $this->endpoint<br>\n"); + // send $dbg = "sending msg w/ soapaction '$soapAction'..."; @@ -166,9 +171,10 @@ // parse the response $return = $soapmsg->parseResponse($this->response); $this->debug($soap_transport->debug_str); - $this->debug($dbg."sent message successfully and got a(n) ".gettype($return)." back"); + $this->debug($dbg.'sent message successfully and got a(n) '.gettype($return).' back'); + // check for valid response - if (strcasecmp(get_class($return),"SOAP_Value")==0) { + if (strcasecmp(get_class($return),'SOAP_Value')==0) { // decode to native php datatype $returnArray = $return->decode(); // fault? @@ -193,10 +199,11 @@ } return $returnArray; } else { - return $this->raiseError("didn't get SOAP_Value object back from client", -1); + return $this->raiseError('didn\'t get SOAP_Value object back from client', -1); } } - return $this->raiseError("client send/recieve error", -1); + + return $this->raiseError('client send/recieve error', -1); } /** @@ -208,7 +215,7 @@ function debug($string) { if ($this->debug_flag) { - $this->debug_data .= "SOAP_Client: ".preg_replace("/>/","/>\r\n/",$string)."\n"; + $this->debug_data .= 'SOAP_Client: '.preg_replace("/>/","/>\r\n/",$string)."\n"; } } } Index: pear/SOAP/Message.php diff -u pear/SOAP/Message.php:1.5 pear/SOAP/Message.php:1.6 --- pear/SOAP/Message.php:1.5 Mon Feb 25 00:06:36 2002 +++ pear/SOAP/Message.php Mon Feb 25 13:59:47 2002 @@ -17,11 +17,12 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: Message.php,v 1.5 2002/02/25 05:06:36 shane Exp $ +// $Id: Message.php,v 1.6 2002/02/25 18:59:47 shane Exp $ // -require_once("SOAP/globals.php"); -require_once("SOAP/Parser.php"); -require_once("SOAP/Value.php"); + +require_once('SOAP/globals.php'); +require_once('SOAP/Parser.php'); +require_once('SOAP/Value.php'); /** * SOAP Message Class @@ -30,7 +31,7 @@ * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4 * * @access public -* @version $Id: Message.php,v 1.5 2002/02/25 05:06:36 shane Exp $ +* @version $Id: Message.php,v 1.6 2002/02/25 18:59:47 shane Exp $ * @package SOAP::Message * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates * @author Dietrich Ayala <dietrich@ganx4.com> Original Author @@ -49,24 +50,30 @@ * * @access public */ - function SOAP_Message($method,$params,$method_namespace="http://testuri.org",$new_namespaces=NULL) + function SOAP_Message($method,$params,$method_namespace='http://testuri.org',$new_namespaces=NULL) { // globalize method namespace global $methodNamespace; $methodNamespace = $method_namespace; + // make method struct - $this->value = new SOAP_Value($method,"struct",$params,$method_namespace); + $this->value = new SOAP_Value($method,'struct',$params,$method_namespace); + if (is_array($new_namespaces)) { global $SOAP_namespaces; + $i = count($SOAP_namespaces); + foreach ($new_namespaces as $v) { - $SOAP_namespaces[$v] = "ns".$i++; + $SOAP_namespaces[$v] = 'ns'.$i++; } + $this->namespaces = $SOAP_namespaces; } - $this->payload = ""; + + $this->payload = ''; $this->debug_flag = false; - $this->debug_str = "entering SOAP_Message() with SOAP_Value ".$this->value->name."\n"; + $this->debug_str = 'entering SOAP_Message() with SOAP_Value '.$this->value->name."\n"; } /** @@ -80,7 +87,9 @@ function _makeEnvelope($payload) { global $SOAP_namespaces; - $ns_string = ""; + + $ns_string = ''; + foreach ($SOAP_namespaces as $k => $v) { $ns_string .= "xmlns:$v=\"$k\"\n "; } @@ -127,7 +136,7 @@ */ function serialize() { - if ($this->payload == "") { + if ($this->payload == '') { $this->_createPayload(); return $this->payload; } @@ -144,9 +153,10 @@ */ function parseResponse($data) { - $this->debug("Entering parseResponse()"); + $this->debug('Entering parseResponse()'); $this->debug(" w/ data $data"); - $this->debug("about to create parser instance w/ data"); + $this->debug('about to create parser instance w/ data'); + // parse response $response = new SOAP_Parser($data); // return array of parameters @@ -164,7 +174,7 @@ function debug($string) { if ($this->debug_flag) { - $this->debug_str .= "SOAP_Message: ".preg_replace("/>/","/>\r\n/",$string)."\n"; + $this->debug_str .= 'SOAP_Message: '.preg_replace("/>/","/>\r\n/",$string)."\n"; } } @@ -179,7 +189,8 @@ if ($this->debug_flag) { return "<!-- DEBUG INFO:\n".$this->debug_str."-->\n"; } - return ""; + + return ''; } } ?> Index: pear/SOAP/Parser.php diff -u pear/SOAP/Parser.php:1.5 pear/SOAP/Parser.php:1.6 --- pear/SOAP/Parser.php:1.5 Mon Feb 25 01:14:32 2002 +++ pear/SOAP/Parser.php Mon Feb 25 13:59:47 2002 @@ -17,66 +17,68 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: Parser.php,v 1.5 2002/02/25 06:14:32 shane Exp $ +// $Id: Parser.php,v 1.6 2002/02/25 18:59:47 shane Exp $ // -require_once("SOAP/globals.php"); -require_once("SOAP/Value.php"); + +require_once('SOAP/globals.php'); +require_once('SOAP/Value.php'); /** -* SOAP parser +* SOAP Parser * this class is used by SOAP::Message and SOAP::Server to parse soap packets * * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4 * * @access public -* @version $Id: Parser.php,v 1.5 2002/02/25 06:14:32 shane Exp $ +* @version $Id: Parser.php,v 1.6 2002/02/25 18:59:47 shane Exp $ * @package SOAP::Parser * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates * @author Dietrich Ayala <dietrich@ganx4.com> Original Author */ class SOAP_Parser { - var $status = ""; + var $status = ''; var $position = 0; var $pos_stat = 0; var $depth = 0; - var $default_namespace = ""; + var $default_namespace = ''; var $namespaces = array(); var $message = array(); var $fault = false; - var $fault_code = ""; - var $fault_str = ""; - var $fault_detail = ""; + var $fault_code = ''; + var $fault_str = ''; + var $fault_detail = ''; var $depth_array = array(); var $debug_flag = true; - var $debug_str = ""; - var $previous_element = ""; + var $debug_str = ''; + var $previous_element = ''; var $soapresponse = NULL; var $parent = 0; var $root_struct_name = array(); - var $curent_root_struct_name = ""; - var $entities = array ( "&" => "&amp;", "<" => "&lt;", ">" => "&gt;", - "'" => "&apos;", '"' => "&quot;" ); - var $xml = ""; - var $xml_encoding = ""; + var $curent_root_struct_name = ''; + var $entities = array ( '&' => '&amp;', '<' => '&lt;', '>' => '&gt;', + "'" => '&apos;', '"' => '&quot;' ); + var $xml = ''; + var $xml_encoding = ''; var $root_struct = array(); var $curent_root_struct = 0; var $references = array(); var $need_references = array(); var $XMLSchemaVersion; - function SOAP_Parser($xml,$encoding="UTF-8") + function SOAP_Parser($xml,$encoding='UTF-8') { $this->setSchemaVersion(SOAP_XML_SCHEMA_VERSION); //global $soapTypes; //$this->soapTypes = $soapTypes; $this->xml = $xml; $this->xml_encoding = $encoding; - // determines where in the message we are (envelope,header,body,method) + // determines where in the message we are (envelope,header,body,method) // Check whether content has been read. if (!empty($xml)) { - $this->debug("Entering SOAP_Parser()"); + $this->debug('Entering SOAP_Parser()'); + //$this->debug("DATA DUMP:\n\n$xml"); // Create an XML parser. $parser = xml_parser_create($this->xml_encoding); @@ -85,15 +87,16 @@ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); // Set the object for the parser. xml_set_object($parser, &$this); + // Set the element handlers for the parser. - xml_set_element_handler($parser, "startElement","endElement"); - xml_set_character_data_handler($parser,"characterData"); - xml_set_default_handler($parser, "defaultHandler"); + xml_set_element_handler($parser, 'startElement','endElement'); + xml_set_character_data_handler($parser,'characterData'); + xml_set_default_handler($parser, 'defaultHandler'); // Parse the XML file. if (!xml_parse($parser,$xml,true)) { // Display an error message. - $this->debug(sprintf("XML error on line %d: %s", + $this->debug(sprintf('XML error on line %d: %s', xml_get_current_line_number($parser), xml_error_string(xml_get_error_code($parser)))); $this->fault = true; @@ -103,7 +106,7 @@ } xml_parser_free($parser); } else { - $this->debug("xml was empty, didn't parse!"); + $this->debug('xml was empty, didn\'t parse!'); } } @@ -112,8 +115,8 @@ global $SOAP_namespaces; $this->XMLSchemaVersion = $schemaVersion; $tmpNS = array_flip($SOAP_namespaces); - $tmpNS["xsd"] = $this->XMLSchemaVersion; - $tmpNS["xsi"] = $this->XMLSchemaVersion."-instance"; + $tmpNS['xsd'] = $this->XMLSchemaVersion; + $tmpNS['xsi'] = $this->XMLSchemaVersion.'-instance'; $SOAP_namespaces = array_flip($tmpNS); } @@ -121,14 +124,16 @@ function buildResponse($pos) { $response = NULL; - if ($this->message[$pos]["children"] != "") { - $this->debug("children string = ".$this->message[$pos]["children"]); - $children = explode("|",$this->message[$pos]["children"]); - $this->debug("it has ".count($children)." children"); + + if ($this->message[$pos]['children'] != '') { + $this->debug('children string = '.$this->message[$pos]['children']); + $children = explode('|',$this->message[$pos]['children']); + $this->debug('it has '.count($children).' children'); + foreach ($children as $c => $child_pos) { - //$this->debug("child pos $child_pos: ".$this->message[$child_pos]["name"]); - if ($this->message[$child_pos]["type"] != NULL) { - $this->debug("entering buildResponse() for ".$this->message[$child_pos]["name"].", array pos $c, pos: $child_pos"); + //$this->debug("child pos $child_pos: ".$this->message[$child_pos]['name']); + if ($this->message[$child_pos]['type'] != NULL) { + $this->debug('entering buildResponse() for '.$this->message[$child_pos]['name'].", array pos $c, pos: $child_pos"); $response[] = $this->buildResponse($child_pos); } } @@ -172,9 +177,10 @@ $response = new SOAP_Value($this->message[$pos]["name"], $this->message[$pos]["type"] , $response); } else { #print "Parser creating: {$this->message[$pos]["name"]} type: {$this->message[$pos]["type"]}\n"; - $this->debug("inside buildresponse: creating SOAP_Value ".$this->message[$pos]["name"]." of type ".$this->message[$pos]["type"]." and value: ".$this->message[$pos]["cdata"]); - $response = new SOAP_Value($this->message[$pos]["name"], $this->message[$pos]["type"] , $this->message[$pos]["cdata"]); + $this->debug('inside buildresponse: creating SOAP_Value '.$this->message[$pos]['name'].' of type '.$this->message[$pos]['type'].' and value: '.$this->message[$pos]['cdata']); + $response = new SOAP_Value($this->message[$pos]['name'], $this->message[$pos]['type'] , $this->message[$pos]['cdata']); } + return $response; } @@ -184,20 +190,24 @@ // position in a total number of elements, starting from 0 // update class level pos $pos = $this->position++; + // and set mine - $this->message[$pos]["pos"] = $pos; + $this->message[$pos]['pos'] = $pos; + // parent/child/depth determinations // depth = how many levels removed from root? // set mine as current global depth and increment global depth value - $this->message[$pos]["depth"] = $this->depth++; + $this->message[$pos]['depth'] = $this->depth++; // else add self as child to whoever the current parent is if ($pos != 0) { - $this->message[$this->parent]["children"] .= "|$pos"; + $this->message[$this->parent]['children'] .= "|$pos"; } + // set my parent - $this->message[$pos]["parent"] = $this->parent; + $this->message[$pos]['parent'] = $this->parent; + // set self as current value for this depth $this->depth_array[$this->depth] = $pos; // set self as current parent @@ -205,13 +215,13 @@ // set status if (preg_match("/:Envelope$/i",$name)) { - $this->status = "envelope"; + $this->status = 'envelope'; } elseif (preg_match("/:Header$/i",$name)) { - $this->status = "header"; + $this->status = 'header'; } elseif (preg_match("/:Body$/i",$name)) { - $this->status = "body"; + $this->status = 'body'; // set method - } elseif ($this->status == "body") { + } elseif ($this->status == 'body') { // is this element allowed to be a root? // XXX this needs to be optimized, we loop through attrs twice now $can_root = TRUE; @@ -220,50 +230,61 @@ $can_root = FALSE; } } - $this->status = "method"; + + $this->status = 'method'; + if ($can_root) { - if (strpos($name,":") !== false) { - $this->root_struct_name[] = $this->curent_root_struct_name = substr(strrchr($name,":"),1); + if (strpos($name,':') !== false) { + $this->root_struct_name[] = $this->curent_root_struct_name = substr(strrchr($name,':'),1); } else { $this->root_struct_name[] = $this->curent_root_struct_name = $name; } + $this->root_struct[] = $this->curent_root_struct = $pos; - $this->message[$pos]["type"] = "struct"; + $this->message[$pos]['type'] = 'struct'; } } + // set my status - $this->message[$pos]["status"] = $this->status; + $this->message[$pos]['status'] = $this->status; // set name - $this->message[$pos]["name"] = htmlspecialchars($name); + $this->message[$pos]['name'] = htmlspecialchars($name); + // set attrs - $this->message[$pos]["attrs"] = $attrs; + $this->message[$pos]['attrs'] = $attrs; + // get namespace - if (strpos($name,":") !== false) { - $namespace = substr($name,0,strpos($name,":")); - $this->message[$pos]["namespace"] = $namespace; + if (strpos($name,':') !== false) { + $namespace = substr($name,0,strpos($name,':')); + $this->message[$pos]['namespace'] = $namespace; $this->default_namespace = $namespace; } else { - $this->message[$pos]["namespace"] = $this->default_namespace; + $this->message[$pos]['namespace'] = $this->default_namespace; } + // loop through atts, logging ns and type declarations foreach ($attrs as $key => $value) { // if ns declarations, add to class level array of valid namespaces if (preg_match('/^xmlns:/i',$key)) { - $prefix = substr(strrchr($key,":"),1); - if ($prefix == "xsd") { + $prefix = substr(strrchr($key,':'),1); + + if ($prefix == 'xsd') { $this->setSchemaVersion($value); } - $this->namespaces[substr(strrchr($key,":"),1)] = $value; + + $this->namespaces[substr(strrchr($key,':'),1)] = $value; + // set method namespace if ($name == $this->curent_root_struct_name) { $this->methodNamespace = $value; } // if it's a type declaration, set type } elseif (preg_match('/:type$/i',$key)) { - $type = substr(strrchr($value,":"),1); + $type = substr(strrchr($value,':'),1); + if (!$type) $type = $value; - $this->message[$pos]["type"] = $type; + $this->message[$pos]['type'] = $type; #print "set type for {$this->message[$pos]['name']} to {$this->message[$pos]['type']}\n"; // should do something here with the namespace of specified type? } elseif (preg_match('/:arrayType$/i',$key)) { @@ -308,8 +329,8 @@ // get type if not explicitly declared in an xsi:type attribute // XXX check on integrating wsdl validation here - if ($this->message[$pos]['type'] == "") { - if ($this->message[$pos]['children'] != "") { + if ($this->message[$pos]['type'] == '') { + if ($this->message[$pos]['children'] != '') { $this->message[$pos]['type'] = 'struct'; } else { $parent = $this->message[$pos]['parent']; @@ -324,29 +345,32 @@ // set eval str start if it has a valid type and is inside the method if ($pos >= $this->curent_root_struct) { - $this->message[$pos]["inval"] = "true"; + $this->message[$pos]['inval'] = 'true'; } // if in the process of making a soap_val, close the parentheses and move on... - if ($this->message[$pos]["inval"] == "true") { - $this->message[$pos]["inval"] == "false"; + if ($this->message[$pos]['inval'] == 'true') { + $this->message[$pos]['inval'] == 'false'; } + // if tag we are currently closing is the method wrapper if ($pos == $this->curent_root_struct) { - $this->status = "body"; - } elseif (stristr($name,":Body")) { - $this->status = "header"; - } elseif (stristr($name,":Header")) { - $this->status = "envelope"; + $this->status = 'body'; + } elseif (stristr($name,':Body')) { + $this->status = 'header'; + } elseif (stristr($name,':Header')) { + $this->status = 'envelope'; } + // set parent back to my parent - $this->parent = $this->message[$pos]["parent"]; - $this->debug("parsed $name end, type '".$this->message[$pos]["type"]."' children = ".$this->message[$pos]["children"]); - #print ("parsed $name end, type '".$this->message[$pos]["type"]."' children = ".$this->message[$pos]["children"]."\n"); + $this->parent = $this->message[$pos]['parent']; + $this->debug("parsed $name end, type '".$this->message[$pos]['type']."' children = ".$this->message[$pos]['children']); + #print ("parsed $name end, type '".$this->message[$pos]['type']."' children = ".$this->message[$pos]['children']."\n"); # handle any reverse references now $idref = $this->message[$pos]['id']; - if ($idref != "" && array_key_exists($idref,$this->need_references)) { + + if ($idref != '' && array_key_exists($idref,$this->need_references)) { foreach ($this->need_references[$idref] as $ref_pos) { #XXX is this stuff there already? $this->message[$ref_pos]['children'] = &$this->message[$pos]['children']; @@ -363,7 +387,7 @@ function characterData($parser, $data) { $pos = $this->depth_array[$this->depth]; - $this->message[$pos]["cdata"] .= $data; + $this->message[$pos]['cdata'] .= $data; } // default handler @@ -388,16 +412,17 @@ if ($this->soapresponse) { return $this->soapresponse; } else { - $this->debug("ERROR: did not successfully eval the msg"); + $this->debug('ERROR: did not successfully eval the msg'); $this->fault = true; - return new SOAP_Value("Fault","struct",array(new SOAP_Value("faultcode","string","SOAP-ENV:Parser"),new SOAP_Value("faultstring","string","couldn't build response"))); + + return new SOAP_Value('Fault','struct',array(new SOAP_Value('faultcode','string','SOAP-ENV:Parser'),new SOAP_Value('faultstring','string',"couldn't build response"))); } } function debug($string) { if ($this->debug_flag) { - $this->debug_str .= "SOAP_Parser: ".preg_replace("/>/","/>\r\n/",$string)."\n"; + $this->debug_str .= 'SOAP_Parser: '.preg_replace("/>/","/>\r\n/",$string)."\n"; } } Index: pear/SOAP/Server.php diff -u pear/SOAP/Server.php:1.4 pear/SOAP/Server.php:1.5 --- pear/SOAP/Server.php:1.4 Mon Feb 25 00:06:36 2002 +++ pear/SOAP/Server.php Mon Feb 25 13:59:47 2002 @@ -17,24 +17,25 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: Server.php,v 1.4 2002/02/25 05:06:36 shane Exp $ +// $Id: Server.php,v 1.5 2002/02/25 18:59:47 shane Exp $ // -require_once("SOAP/globals.php"); -require_once("SOAP/Parser.php"); -require_once("SOAP/Message.php"); -require_once("SOAP/Value.php"); + +require_once('SOAP/globals.php'); +require_once('SOAP/Parser.php'); +require_once('SOAP/Message.php'); +require_once('SOAP/Value.php'); // make errors handle properly in windows error_reporting(2039); /** * SOAP::Server -* soap server class +* SOAP Server Class * * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4 * * @access public -* @version $Id: Server.php,v 1.4 2002/02/25 05:06:36 shane Exp $ +* @version $Id: Server.php,v 1.5 2002/02/25 18:59:47 shane Exp $ * @package SOAP::Client * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates * @author Dietrich Ayala <dietrich@ganx4.com> Original Author @@ -42,15 +43,15 @@ class SOAP_Server { var $dispatch_map = array(); // create empty dispatch map var $debug_flag = true; - var $debug_str = ""; - var $headers = ""; - var $request = ""; - var $xml_encoding = "UTF-8"; + var $debug_str = ''; + var $headers = ''; + var $request = ''; + var $xml_encoding = 'UTF-8'; var $fault = false; - var $fault_code = ""; - var $fault_str = ""; - var $fault_actor = ""; - var $result = "successful"; // for logging interop results to db + var $fault_code = ''; + var $fault_str = ''; + var $fault_actor = ''; + var $result = 'successful'; // for logging interop results to db function SOAP_Server($debug = FALSE) { // turn on debugging? @@ -63,7 +64,8 @@ // $response is a soap_msg object $response = $this->parseRequest($data); $this->debug("parsed request and got an object of this class '".get_class($response)."'"); - $this->debug("server sending..."); + $this->debug('server sending...'); + // pass along the debug string if ($this->debug_flag) { $response->debug($this->debug_str); @@ -77,7 +79,8 @@ //$header[] = "HTTP/1.0 200 OK\r\n"; $header[] = "Status: 200 OK\r\n"; } - $header[] = "Server: ".SOAP_LIBRARY_NAME."\r\n"; + + $header[] = 'Server: '.SOAP_LIBRARY_NAME."\r\n"; $header[] = "Connection: Close\r\n"; $header[] = "Content-Type: text/xml; charset=$this->xml_encoding\r\n"; $header[] = "Content-Length: ".strlen($payload)."\r\n\r\n"; @@ -89,28 +92,32 @@ print $payload; } - function parseRequest($data="") + function parseRequest($data='') { - $this->debug("entering parseRequest() on ".date("H:i Y-m-d")); - $this->debug("request uri: ".$HTTP_SERVER_VARS["REQUEST_URI"]); + $this->debug('entering parseRequest() on '.date('H:i Y-m-d')); + $this->debug('request uri: '.$HTTP_SERVER_VARS['REQUEST_URI']); + // get headers - if (function_exists("getallheaders")) { + if (function_exists('getallheaders')) { + $this->headers = getallheaders(); foreach ($this->headers as $k=>$v) { $dump .= "$k: $v\r\n"; } + // get SOAPAction header - if ($headers_array["SOAPAction"]) { - $this->SOAPAction = str_replace('"','',$headers_array["SOAPAction"]); + if ($headers_array['SOAPAction']) { + $this->SOAPAction = str_replace('"','',$headers_array['SOAPAction']); $this->service = $this->SOAPAction; } + // get the character encoding of the incoming request - if (ereg("=",$headers_array["Content-Type"])) { - $enc = str_replace("\"","",substr(strstr($headers_array["Content-Type"],"="),1)); + if (ereg('=',$headers_array['Content-Type'])) { + $enc = str_replace('"','',substr(strstr($headers_array['Content-Type'],'='),1)); if (eregi("^(ISO-8859-1|US-ASCII|UTF-8)$",$enc)) { $this->xml_encoding = $enc; } else { - $this->xml_encoding = "us-ascii"; + $this->xml_encoding = 'us-ascii'; } } $this->debug("got encoding: $this->xml_encoding"); @@ -119,14 +126,14 @@ // parse response, get soap parser obj $parser = new SOAP_Parser($data,$this->xml_encoding); // get/set methodname - $this->methodname = $parser->root_struct_name; + $this->methodname = $parser->root_struct_name[0]; $this->debug("method name: $this->methodname"); // does method exist? if (!function_exists($this->methodname)) { // "method not found" fault here $this->debug("method '$this->methodname' not found!"); - $this->result = "fault: method not found"; - $this->makeFault("Server","method '$this->methodname' not defined in service '$this->service'"); + $this->result = 'fault: method not found'; + $this->makeFault('Server',"method '$this->methodname' not defined in service '$this->service'"); return $this->fault(); } $this->debug("method '$this->methodname' exists"); @@ -134,30 +141,34 @@ if ($parser->fault()) { // parser debug $this->debug($parser->debug_str); - $this->result = "fault: error in msg parsing"; - $this->makeFault("Server","error in msg parsing:\n".$parser->getResponse()); + $this->result = 'fault: error in msg parsing'; + $this->makeFault('Server',"error in msg parsing:\n".$parser->getResponse()); + // return soapresp return $this->fault(); // else successfully parsed request into SOAP_Value object } else { // evaluate message, getting back a SOAP_Value object - $this->debug("calling parser->getResponse()"); + $this->debug('calling parser->getResponse()'); + if (!$request_val = $parser->getResponse()) { return $this->fault(); } // parser debug $this->debug($parser->debug_str); + /* set namespaces - if ($parser->namespaces["xsd"] != "") { - //print "got ".$parser->namespaces["xsd"]; + if ($parser->namespaces['xsd'] != '') { + //print 'got '.$parser->namespaces['xsd']; global $SOAP_namespaces; - $this->XMLSchemaVersion = $parser->namespaces["xsd"]; + $this->XMLSchemaVersion = $parser->namespaces['xsd']; $tmpNS = array_flip($SOAP_namespaces); - $tmpNS["xsd"] = $this->XMLSchemaVersion; - $tmpNS["xsi"] = $this->XMLSchemaVersion."-instance"; + $tmpNS['xsd'] = $this->XMLSchemaVersion; + $tmpNS['xsi'] = $this->XMLSchemaVersion.'-instance'; $SOAP_namespaces = array_flip($tmpNS); }*/ - if (strcasecmp(get_class($request_val),"SOAP_Value")==0) { + + if (strcasecmp(get_class($request_val),'SOAP_Value')==0) { // verify that SOAP_Value objects in request match the methods signature if ($this->verifyMethod($request_val)) { $this->debug("request data - name: $request_val->name, type: $request_val->type, value: $request_val->value"); @@ -166,8 +177,8 @@ $request_data = $request_val->decode(); $this->debug($request_val->debug_str); $this->debug("request data: $request_data"); - $this->debug("about to call method '$this->methodname'"); + // if there are parameters to pass if ($request_data) { // call method with parameters @@ -179,24 +190,28 @@ $this->debug("calling $this->methodname w/ no params"); $method_response = call_user_func($this->methodname); } + $this->debug("done calling method: $this->methodname"); + // if return val is SOAP_Message - if (strcasecmp(get_class($method_response),"SOAP_Message")==0) { - if (eregi("fault",$method_response->value->name)) { + if (strcasecmp(get_class($method_response),'SOAP_Message')==0) { + if (eregi('fault',$method_response->value->name)) { $this->fault = true; } $return_msg = $method_response; } else { // if return val is SOAP_Value object - if (strcasecmp(get_class($method_response),"SOAP_Value")==0) { + if (strcasecmp(get_class($method_response),'SOAP_Value')==0) { $return_val = array($method_response); + // create soap_val object w/ return values from method, use method signature to determine type } else { $this->debug("creating new SOAP_Value to return, of type $this->return_type"); if (is_array($this->return_type) && is_array($method_response)) { $i = 0; + foreach ($this->return_type as $key => $type) { - if (is_numeric($key)) $key = "item"; + if (is_numeric($key)) $key = 'item'; $return_val[] = new SOAP_Value($key,$type,$method_response[$i++]); } } else { @@ -213,19 +228,24 @@ if ($this->debug_flag) { $this->debug($return_val->debug_str); } - $this->debug("creating return soap_msg object: ".$this->methodname."Response"); + + $this->debug("creating return soap_msg object: ".$this->methodname.'Response'); // response object is a soap_msg object - $return_msg = new SOAP_Message($this->methodname."Response",$return_val,"$this->service"); + $return_msg = new SOAP_Message($this->methodname.'Response',$return_val,"$this->service"); } + if ($this->debug_flag) { $return_msg->debug_flag = true; } - $this->result = "successful"; + + $this->result = 'successful'; + return $return_msg; } else { // debug - $this->debug("ERROR: request not verified against method signature"); - $this->result = "fault: request failed validation against method signature"; + $this->debug('ERROR: request not verified against method signature'); + $this->result = 'fault: request failed validation against method signature'; + // return soapresp return $this->fault(); } @@ -233,8 +253,9 @@ // debug $this->debug("ERROR: parser did not return SOAP_Value object: $request_val ".get_class($request_val)); $this->result = "fault: parser did not return SOAP_Value object: $request_val"; + // return fault - $this->makeFault("Server","parser did not return SOAP_Value object: $request_val"); + $this->makeFault('Server',"parser did not return SOAP_Value object: $request_val"); return $this->fault(); } } @@ -243,23 +264,27 @@ function verifyMethod($request) { global $SOAP_typemap; + //return true; - $this->debug("entered verifyMethod() w/ request name: ".$request->name); + $this->debug('entered verifyMethod() w/ request name: '.$request->name); $params = $request->value; + // if there are input parameters required... - if ($sig = $this->dispatch_map[$this->methodname]["in"]) { + if ($sig = $this->dispatch_map[$this->methodname]['in']) { $this->input_value = count($sig); $this->return_type = $this->getReturnType($this->methodname); if (is_array($params)) { if ($this->debug_flag) { - $this->debug("entered verifyMethod() with ".count($params)." parameters"); + $this->debug('entered verifyMethod() with '.count($params).' parameters'); + foreach ($params as $v) { $this->debug("param '$v->name' of type '$v->type'"); } } // validate the number of parameters if (count($params) == count($sig)) { - $this->debug("got correct number of parameters: ".count($sig)); + $this->debug('got correct number of parameters: '.count($sig)); + // make array of param types foreach ($params as $param) { $p[] = strtolower($param->type); @@ -274,9 +299,12 @@ if (strcasecmp($sig_t[$i],$p[$i])!=0 && !(isset($SOAP_typemap[SOAP_XML_SCHEMA_VERSION][$sig_t[$i]]) && strcasecmp($SOAP_typemap[SOAP_XML_SCHEMA_VERSION][$sig_t[$i]],$SOAP_typemap[SOAP_XML_SCHEMA_VERSION][$p[$i]])==0)) { + $param = $params[$i]; + $this->debug("mismatched parameter types: [{$sig_t[$i]}] != [{$p[$i]}]"); - $this->makeFault("Client","soap request contained mismatching parameters of name $param->name had type [{$p[$i]}], which did not match signature's type: [{$sig_t[$i]}], matched? ".(strcasecmp($sig_t[$i],$p[$i]))); + $this->makeFault('Client',"soap request contained mismatching parameters of name $param->name had type [{$p[$i]}], which did not match signature's type: [{$sig_t[$i]}], matched? ".(strcasecmp($sig_t[$i],$p[$i]))); + return false; } $this->debug("parameter type match: $sig_t[$i] = $p[$i]"); @@ -284,14 +312,16 @@ return true; // oops, wrong number of paramss } else { - $this->debug("oops, wrong number of parameter!"); - $this->makeFault("Client","soap request contained incorrect number of parameters. method '$this->methodname' required ".count($sig)." and request provided ".count($params)); + $this->debug('oops, wrong number of parameters!'); + $this->makeFault('Client',"soap request contained incorrect number of parameters. method '$this->methodname' required ".count($sig).' and request provided '.count($params)); + return false; } // oops, no params... } else { - $this->debug("oops, no parameters sent! Method '$this->methodname' requires ".count($sig)." input parameters!"); - $this->makeFault("Client","soap request contained incorrect number of parameters. method '$this->methodname' requires ".count($sig)." parameters, and request provided none"); + $this->debug("oops, no parameters sent! Method '$this->methodname' requires ".count($sig).' input parameters!'); + $this->makeFault('Client',"soap request contained incorrect number of parameters. method '$this->methodname' requires ".count($sig).' parameters, and request provided none'); + return false; } // no params @@ -329,21 +359,21 @@ // add a method to the dispatch map function addToMap($methodname,$in,$out) { - $this->dispatch_map[$methodname]["in"] = $in; - $this->dispatch_map[$methodname]["out"] = $out; + $this->dispatch_map[$methodname]['in'] = $in; + $this->dispatch_map[$methodname]['out'] = $out; } // set up a fault function fault() { - return new SOAP_Message("Fault", + return new SOAP_Message('Fault', array( - "faultcode" => $this->fault_code, - "faultstring" => $this->fault_str, - "faultactor" => $this->fault_actor, - "faultdetail" => $this->fault_detail.$this->debug_str + 'faultcode' => $this->fault_code, + 'faultstring' => $this->fault_str, + 'faultactor' => $this->fault_actor, + 'faultdetail' => $this->fault_detail.$this->debug_str ), - "http://schemas.xmlsoap.org/soap/envelope/" + 'http://schemas.xmlsoap.org/soap/envelope/' ); } Index: pear/SOAP/Transport.php diff -u pear/SOAP/Transport.php:1.5 pear/SOAP/Transport.php:1.6 --- pear/SOAP/Transport.php:1.5 Mon Feb 25 00:11:05 2002 +++ pear/SOAP/Transport.php Mon Feb 25 13:59:47 2002 @@ -17,9 +17,11 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: Transport.php,v 1.5 2002/02/25 05:11:05 shane Exp $ +// $Id: Transport.php,v 1.6 2002/02/25 18:59:47 shane Exp $ // -require_once("PEAR.php"); + +require_once('PEAR.php'); + /** * SOAP Transport Layer * This layer can use different protocols dependant on the endpoint url provided @@ -27,16 +29,16 @@ * no knowlege of the transport protocols is available at this level * * @access public -* @version $Id: Transport.php,v 1.5 2002/02/25 05:11:05 shane Exp $ +* @version $Id: Transport.php,v 1.6 2002/02/25 18:59:47 shane Exp $ * @package SOAP::Transport * @author Shane Caraveo <shane@php.net> */ class SOAP_Transport extends PEAR { var $transport = NULL; - var $outgoing_payload = ""; - var $incoming_payload = ""; - var $errmsg = ""; + var $outgoing_payload = ''; + var $incoming_payload = ''; + var $errmsg = ''; /** * SOAP::Transport constructor @@ -49,13 +51,15 @@ { /* only HTTP transport for now, later look at url for scheme */ $this->debug_flag = $debug; + $urlparts = @parse_url($url); - if (strcasecmp($urlparts['scheme'],"http")==0) { - require_once("SOAP/Transport/HTTP.php"); + + if (strcasecmp($urlparts['scheme'],'http')==0) { + require_once('SOAP/Transport/HTTP.php'); $this->transport = new SOAP_Transport_HTTP($url); return; - } else if (strcasecmp($urlparts['scheme'],"mailto")==0) { - require_once("SOAP/Transport/SMTP.php"); + } else if (strcasecmp($urlparts['scheme'],'mailto')==0) { + require_once('SOAP/Transport/SMTP.php'); $this->transport = new SOAP_Transport_SMTP($url); return; } @@ -73,7 +77,7 @@ * @return boolean * @access public */ - function send(&$response, &$soap_data, $action = "", $timeout=0) + function send(&$response, &$soap_data, $action = '', $timeout=0) { if (!$this->transport) return $this->raiseError($this->errmsg, -1); Index: pear/SOAP/Value.php diff -u pear/SOAP/Value.php:1.8 pear/SOAP/Value.php:1.9 --- pear/SOAP/Value.php:1.8 Mon Feb 25 00:06:36 2002 +++ pear/SOAP/Value.php Mon Feb 25 13:59:47 2002 @@ -17,7 +17,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: Value.php,v 1.8 2002/02/25 05:06:36 shane Exp $ +// $Id: Value.php,v 1.9 2002/02/25 18:59:47 shane Exp $ // require_once('SOAP/globals.php'); require_once('SOAP/Type/dateTime.php'); @@ -29,7 +29,7 @@ * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4 * * @access public -* @version $Id: Value.php,v 1.8 2002/02/25 05:06:36 shane Exp $ +* @version $Id: Value.php,v 1.9 2002/02/25 18:59:47 shane Exp $ * @package SOAP::Client * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates * @author Dietrich Ayala <dietrich@ganx4.com> Original Author @@ -38,19 +38,19 @@ class SOAP_Value { var $convert_strings = FALSE; - var $value = ""; + var $value = ''; var $type_code = 0; var $type_prefix = false; - var $array_type = ""; + var $array_type = ''; var $debug_flag = true; - var $debug_str = ""; - var $name = ""; + var $debug_str = ''; + var $name = ''; var $type; var $soapTypes; - var $namespace = ""; - var $prefix = ""; + var $namespace = ''; + var $prefix = ''; - function SOAP_Value($name="",$type=false,$value=-1,$namespace=false,$type_namespace=false) + function SOAP_Value($name='',$type=false,$value=-1,$namespace=false,$type_namespace=false) { global $soapTypes, $SOAP_typemap, $SOAP_namespaces, $methodNamespace; // detect type if not passed @@ -64,23 +64,26 @@ if ($namespace) { $this->namespace = $namespace; + if (!isset($SOAP_namespaces[$namespace])) { - $SOAP_namespaces[$namespace] = "ns".(count($SOAP_namespaces)+1); + $SOAP_namespaces[$namespace] = 'ns'.(count($SOAP_namespaces)+1); } + $this->prefix = $SOAP_namespaces[$namespace]; } // get type prefix - if (strpos($type,":")!==false) { - $this->type = substr(strrchr($type,":"),1,strlen(strrchr($type,":"))); - $this->type_prefix = substr($type,0,strpos($type,":")); + if (strpos($type,':')!==false) { + $this->type = substr(strrchr($type,':'),1,strlen(strrchr($type,':'))); + $this->type_prefix = substr($type,0,strpos($type,':')); } elseif ($type_namespace) { if (!isset($SOAP_namespaces[$type_namespace])) { - $SOAP_namespaces[$type_namespace] = "ns".(count($SOAP_namespaces)+1); + $SOAP_namespaces[$type_namespace] = 'ns'.(count($SOAP_namespaces)+1); } + $this->type_prefix = $SOAP_namespaces[$type_namespace]; // if type namespace was not explicitly passed, and we're not in a method struct: - } elseif (!$this->type_prefix && $type != "struct" /*!isset($type_namespace)*/) { + } elseif (!$this->type_prefix && $type != 'struct' /*!isset($type_namespace)*/) { // try to get type prefix from typeMap if ($ns = $this->verifyType($this->type)) { $this->type_prefix = $SOAP_namespaces[$ns]; @@ -95,12 +98,12 @@ $this->type_code = VALUE_SCALAR; $this->addScalar($value,$this->type,$name); // if array - } elseif (strcasecmp("array",$this->type) == 0 || - strcasecmp("ur-type",$this->type) == 0) { + } elseif (strcasecmp('array',$this->type) == 0 || + strcasecmp('ur-type',$this->type) == 0) { $this->type_code = VALUE_ARRAY; $this->addArray($value); // if struct - } elseif (stristr($this->type,"struct")) { + } elseif (stristr($this->type,'struct')) { $this->type_code = VALUE_STRUCT; $this->addStruct($value); } elseif (is_array($value)) { @@ -108,11 +111,11 @@ $this->addStruct($value); } else { $this->type_code = VALUE_SCALAR; - $this->addScalar($value,"string",$name); + $this->addScalar($value,'string',$name); } } - function addScalar($value, $type, $name="") + function addScalar($value, $type, $name='') { $this->debug("adding scalar '$name' of type '$type'"); @@ -122,20 +125,21 @@ function addArray($vals) { - $this->debug("adding array '$this->name' with ".count($vals)." vals"); + $this->debug("adding array '$this->name' with ".count($vals).' vals'); $this->value = array(); if (is_array($vals) && count($vals) >= 1) { foreach ($vals as $k => $v) { $this->debug("checking value $k : $v"); + // if SOAP_Value, add.. - if (strcasecmp(get_class($v),"SOAP_Value")==0) { + if (strcasecmp(get_class($v),'SOAP_Value')==0) { $this->value[] = $v; $this->debug($v->debug_str); // else make obj and serialize } else { - $type = ""; + $type = ''; $type = $this->_getSoapType($v, $type); - $new_val = new SOAP_Value("item",$type,$v); + $new_val = new SOAP_Value('item',$type,$v); $this->debug($new_val->debug_str); $this->value[] = $new_val; } @@ -146,11 +150,11 @@ function addStruct($vals) { - $this->debug("adding struct '$this->name' with ".count($vals)." vals"); + $this->debug("adding struct '$this->name' with ".count($vals).' vals'); if (is_array($vals) && count($vals) >= 1) { foreach ($vals as $k => $v) { // if serialize, if SOAP_Value - if (strcasecmp(get_class($v),"SOAP_Value")==0) { + if (strcasecmp(get_class($v),'SOAP_Value')==0) { $this->value[] = $v; $this->debug($v->debug_str); // else make obj and serialize @@ -174,21 +178,25 @@ $array_types[$array_val->type] = 1; #$xml .= $this->serializeval($array_val); } + if ($array_val->type_prefix) { - $type = $array_val->type_prefix.":".$array_val->type; + $type = $array_val->type_prefix.':'.$array_val->type; } else { $type = $array_val->type; } + $sz = count($value); + if (count($array_types) == 1) { - if (array_key_exists("array",$array_types)) { + if (array_key_exists('array',$array_types)) { // seems we have a multi dimensional array, figure it out if we do foreach ($value as $array_val) { $numtypes = $this->_getArrayType($array_val->value, $type, $size, $xml); if ($numtypes > 1) return $numtypes; } + if ($sz) { - $size = $sz.",".$size; + $size = $sz.','.$size; } else { $size = $sz; } @@ -210,16 +218,20 @@ if (!$soapval) { $soapval = $this; } + $this->debug("serializing '$soapval->name' of type '$soapval->type'"); + if (is_int($soapval->name)) { - $soapval->name = "item"; + $soapval->name = 'item'; } - $xml = ""; + $xml = ''; + switch ($soapval->type_code) { case 3: // struct - $this->debug("got a struct"); + $this->debug('got a struct'); + if ($soapval->prefix && $soapval->type_prefix) { $xml .= "<$soapval->prefix:$soapval->name xsi:type=\"$soapval->type_prefix:$soapval->type\">\n"; } elseif ($soapval->type_prefix) { @@ -242,24 +254,28 @@ break; case 2: // array - $offset =""; + $offset =''; + // XXX this will be slow on larger array's. We can probably move this // out to an external helper function. Basicly, it flattens array's to allow us // to serialize multi-dimensional array's $numtypes = $this->_getArrayType($soapval->value, $array_type, $ar_size, $xml); #$numtypes = 0; + if ($numtypes != 1) { - $xml =""; + $xml =''; foreach ($soapval->value as $array_val) { $array_types[$array_val->type] = 1; $xml .= $this->serializeval($array_val); } + $ar_size = count($soapval->value); + if (count($array_types) > 1) { - $array_type = "xsd:ur-type"; + $array_type = 'xsd:ur-type'; } elseif (count($array_types) == 1) { - if ($array_val->type_prefix != "") { - $array_type = $array_val->type_prefix.":".$array_val->type; + if ($array_val->type_prefix != '') { + $array_type = $array_val->type_prefix.':'.$array_val->type; } else { $array_type = $array_val->type; } @@ -303,15 +319,15 @@ $this->debug("inside SOAP_Value->decode for $soapval->name of type $soapval->type and value: $soapval->value"); // scalar decode if ($soapval->type_code == VALUE_SCALAR) { - if ($soapval->type == "boolean") { - #echo strcasecmp($soapval->value,"false"); - if ($soapval->value != "0" && - strcasecmp($soapval->value,"false") !=0) { + if ($soapval->type == 'boolean') { + #echo strcasecmp($soapval->value,'false'); + if ($soapval->value != '0' && + strcasecmp($soapval->value,'false') !=0) { $soapval->value = TRUE; } else { $soapval->value = FALSE; } - #} else if ($soapval->type == "dateTime") { + #} else if ($soapval->type == 'dateTime') { # # we don't realy know what a user want's in return, # # but we'll just do unix time stamps for now # # THOUGHT: we could return a class instead. @@ -353,8 +369,7 @@ return $soapval->value; } # couldn't decode, return a fault! - return array( - 'faultcode' => 'SOAP-ENV:Value', + return array('faultcode' => 'SOAP-ENV:Value', 'faultstring' => 'couldn\'t decode response, invalid type_code', 'faultdetail' => '' ); @@ -411,50 +426,50 @@ } elseif (isArray($value)) { foreach ($value as $k => $v) { if (preg_match("/^[0-9]+$/",$k)) { - $type = "array"; + $type = 'array'; } else { - $type = "struct"; + $type = 'struct'; } break; } } elseif (isInt($value)) { - $type = "int"; + $type = 'int'; } elseif (isFloat($value)) { - $type = "float"; + $type = 'float'; } elseif (SOAP_Type_hexBinary::is_hexbin($value)) { - $type = "hexBinary"; + $type = 'hexBinary'; } elseif (isBase64($value)) { - $type = "base64Binary"; + $type = 'base64Binary'; } elseif (isBoolean($value)) { - $type = "boolean"; + $type = 'boolean'; } else { $type = gettype($value); # php defaults a lot of stuff to string, if we have no # idea what the type realy is, we have to try to figure it out # this is the best we can do if the user did not use the SOAP_Value class - if ($type == "string") $doconvert = TRUE; + if ($type == 'string') $doconvert = TRUE; } } # we have the type, handle any value munging we need if ($doconvert) { $dt = new SOAP_Type_dateTime($value); if ($dt->toUnixtime() != -1) { - $type = "dateTime"; + $type = 'dateTime'; $value = $dt->toSOAP(); } } else - if ($type == "dateTime") { + if ($type == 'dateTime') { # encode a dateTime to ISOE $dt = new SOAP_Type_dateTime($value); $value = $dt->toSOAP(); } else // php type name mangle - if ($type == "integer") { - $type = "int"; + if ($type == 'integer') { + $type = 'int'; } else - if ($type == "boolean") { - if (($value != 0 && $value !='0') || strcasecmp($value,"true")==0) $value = "true"; - else $value = "false"; + if ($type == 'boolean') { + if (($value != 0 && $value !='0') || strcasecmp($value,'true')==0) $value = 'true'; + else $value = 'false'; } return $type; } @@ -462,7 +477,7 @@ function debug($string) { if ($this->debug_flag) { - $this->debug_str .= "SOAP_Value: ".preg_replace("/>/","/>\r\n/",$string)."\n"; + $this->debug_str .= 'SOAP_Value: '.preg_replace("/>/","/>\r\n/",$string)."\n"; } } } @@ -470,24 +485,24 @@ // support functions function isBase64($value) { - return $value[strlen($value)-1]=="=" && preg_match("/[A-Za-z=\/\+]+/",$value); + return $value[strlen($value)-1]=='=' && preg_match("/[A-Za-z=\/\+]+/",$value); } function isBoolean($value) { - return gettype($value) == "boolean" || strcasecmp($value, "true")==0 || strcasecmp($value, "false")==0; + return gettype($value) == 'boolean' || strcasecmp($value, 'true')==0 || strcasecmp($value, 'false')==0; } function isFloat($value) { return gettype($value) == FLOAT || - $value === "NaN" || $value === "INF" || $value === "-INF" || - (is_numeric($value) && strstr($value,".")); + $value === 'NaN' || $value === 'INF' || $value === '-INF' || + (is_numeric($value) && strstr($value,'.')); } function isInt($value) { - return gettype($value) == "integer" || (is_numeric($value) && !strstr($value,".")); + return gettype($value) == 'integer' || (is_numeric($value) && !strstr($value,'.')); } function isArray($value) Index: pear/SOAP/Transport/HTTP.php diff -u pear/SOAP/Transport/HTTP.php:1.5 pear/SOAP/Transport/HTTP.php:1.6 --- pear/SOAP/Transport/HTTP.php:1.5 Mon Feb 25 00:06:37 2002 +++ pear/SOAP/Transport/HTTP.php Mon Feb 25 13:59:49 2002 @@ -16,27 +16,30 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> | // +----------------------------------------------------------------------+ // -// $Id: HTTP.php,v 1.5 2002/02/25 05:06:37 shane Exp $ +// $Id: HTTP.php,v 1.6 2002/02/25 18:59:49 shane Exp $ // -require_once("SOAP/globals.php"); + +require_once('SOAP/globals.php'); + /** * HTTP Transport for SOAP * * @access public -* @version $Id: HTTP.php,v 1.5 2002/02/25 05:06:37 shane Exp $ +* @version $Id: HTTP.php,v 1.6 2002/02/25 18:59:49 shane Exp $ * @package SOAP::Transport::HTTP * @author Shane Caraveo <shane@php.net> */ class SOAP_Transport_HTTP { - var $credentials = ""; + var $credentials = ''; var $_userAgent; var $timeout = 4; // connect timeout var $errno = 0; - var $errmsg = ""; + var $errmsg = ''; var $urlparts = NULL; - var $url = ""; - var $incoming_payload = ""; + var $url = ''; + var $incoming_payload = ''; + /** * SOAP_Transport_HTTP Constructor * @@ -62,7 +65,7 @@ * @return boolean (success or failure) * @access public */ - function send(&$msg, &$response, $action = "", $timeout=0) + function send(&$msg, &$response, $action = '', $timeout=0) { if (!$this->_validateUrl()) { return FALSE; @@ -88,7 +91,7 @@ */ function setCredentials($username, $password) { - $this->credentials = "Authorization: Basic ".base64_encode($username.":".$password)."\r\n"; + $this->credentials = 'Authorization: Basic '.base64_encode($username.':'.$password)."\r\n"; } // private members @@ -127,7 +130,7 @@ function _parseResponse() { if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s",$this->incoming_payload,$match)) { - $this->response = preg_replace("/[\r|\n]/","",$match[2]); + $this->response = preg_replace("/[\r|\n]/",'',$match[2]); // if no content, return false return strlen($this->response) > 0; } @@ -164,7 +167,7 @@ * @return boolean * @access private */ - function _sendHTTP(&$msg, &$response, $action = "") + function _sendHTTP(&$msg, &$response, $action = '') { $this->_getRequest($msg, $action); @@ -189,8 +192,9 @@ } fclose($fp); + if (!$this->_parseResponse()) { - $this->errmsg = "Invalid HTTP Response"; + $this->errmsg = 'Invalid HTTP Response'; return FALSE; } $response = $this->response; @@ -212,9 +216,9 @@ /* NOTE This function uses the CURL functions * Your php must be compiled with CURL */ - if (!extension_loaded("php_curl")) { + if (!extension_loaded('php_curl')) { $this->errno = -1; - $this->errmsg = "CURL Extension is required for HTTPS"; + $this->errmsg = 'CURL Extension is required for HTTPS'; return FALSE; } Index: pear/SOAP/Transport/SMTP.php diff -u pear/SOAP/Transport/SMTP.php:1.2 pear/SOAP/Transport/SMTP.php:1.3 --- pear/SOAP/Transport/SMTP.php:1.2 Mon Feb 25 00:06:37 2002 +++ pear/SOAP/Transport/SMTP.php Mon Feb 25 13:59:49 2002 @@ -16,7 +16,7 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.2 2002/02/25 05:06:37 shane Exp $ +// $Id: SMTP.php,v 1.3 2002/02/25 18:59:49 shane Exp $ // // Status: rough draft, untested // @@ -27,28 +27,28 @@ // ability to define smtp options (encoding, from, etc.) // -require_once("SOAP/globals.php"); -# we have to use the message class to return a proper soap response -require_once("SOAP/Message.php"); +require_once('SOAP/globals.php'); +require_once('SOAP/Message.php'); /** * SMTP Transport for SOAP * * @access public -* @version $Id: SMTP.php,v 1.2 2002/02/25 05:06:37 shane Exp $ +* @version $Id: SMTP.php,v 1.3 2002/02/25 18:59:49 shane Exp $ * @package SOAP::Transport::SMTP * @author Shane Caraveo <shane@php.net> */ class SOAP_Transport_SMTP { - var $credentials = ""; + var $credentials = ''; var $_userAgent; var $timeout = 4; // connect timeout var $errno = 0; - var $errmsg = ""; + var $errmsg = ''; var $urlparts = NULL; - var $url = ""; - var $incoming_payload = ""; + var $url = ''; + var $incoming_payload = ''; + /** * SOAP_Transport_SMTP Constructor * @@ -74,7 +74,7 @@ * @return boolean (success or failure) * @access public */ - function send(&$msg, &$response, $action = "", $timeout=0) + function send(&$msg, &$response, $action = '', $timeout=0) { if (!$this->_validateUrl()) { return FALSE; @@ -85,19 +85,23 @@ "MIME-Version: 1.0\n". "Content-Type: text/xml; charset=\"utf-8\"\n". "Content-Transfer-Encoding: quoted-printable\n"; - $subject = "SOAP Message"; + $subject = 'SOAP Message'; + # we want to return a proper XML message $result = mail($this->urlparts['path'], $subject, $msg, $headers); + if ($result) { - $val = new SOAP_Value("return","boolean",TRUE); + $val = new SOAP_Value('return','boolean',TRUE); } else { - $val = new SOAP_Value("Fault","struct",array( - new SOAP_Value("faultcode","string","SOAP-ENV:Transport"), - new SOAP_Value("faultstring","string","couldn't send message to $action") + $val = new SOAP_Value('Fault','struct',array( + new SOAP_Value('faultcode','string','SOAP-ENV:Transport'), + new SOAP_Value('faultstring','string',"couldn't send message to $action") )); } - $return_msg = new SOAP_Message("Response",array($val),"smtp"); + + $return_msg = new SOAP_Message('Response',array($val),'smtp'); $response = $return_msg->serialize(); + return $result; } @@ -142,5 +146,5 @@ return TRUE; } -}; // end SOAP_Transport_HTTP +} // end SOAP_Transport_HTTP ?> Index: pear/SOAP/Type/dateTime.php diff -u pear/SOAP/Type/dateTime.php:1.3 pear/SOAP/Type/dateTime.php:1.4 --- pear/SOAP/Type/dateTime.php:1.3 Mon Feb 25 00:06:37 2002 +++ pear/SOAP/Type/dateTime.php Mon Feb 25 13:59:49 2002 @@ -17,7 +17,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: dateTime.php,v 1.3 2002/02/25 05:06:37 shane Exp $ +// $Id: dateTime.php,v 1.4 2002/02/25 18:59:49 shane Exp $ // class SOAP_Type_dateTime { @@ -36,7 +36,8 @@ function SOAP_Type_dateTime($date = -1) { if ($date == -1) $date = time(); - if (gettype($date) == "integer") { + + if (gettype($date) == 'integer') { $this->timestamp = $date; } else { $this->timestamp = $this->toUnixtime($date); @@ -52,26 +53,27 @@ { if (!$timestamp) $timestamp = $this->timestamp; if ($timestamp < 0) return 0; - return date("Y-m-d\TH:i:sO",$timestamp); + + return date('Y-m-d\TH:i:sO',$timestamp); } function _split($datestr) { if (!$datestr) $datestr = $this->toString(); - else if (gettype($datestr) == "integer") + else if (gettype($datestr) == 'integer') $datestr = $this->toString($datestr); if (ereg($this->ereg_iso8601,$datestr,$regs)) { - if ($regs[8] != "" && $regs[8] != "Z") { + if ($regs[8] != '' && $regs[8] != 'Z') { $op = substr($regs[8],0,1); $h = substr($regs[8],1,2); - if (strstr($regs[8],":")) { + if (strstr($regs[8],':')) { $m = substr($regs[8],4,2); } else { $m = substr($regs[8],3,2); } - if ($op == "+") { + if ($op == '+') { $regs[4] = $regs[4] - $h; if ($regs[4] < 0) $regs[4] += 24; $regs[5] = $regs[5] - $m; @@ -91,10 +93,12 @@ function toUTC($datestr = NULL) { $regs = $this->_split($datestr); + if ($regs) { - return sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]); + return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]); } - return ""; + + return ''; } function toUnixtime($datestr = NULL) @@ -120,7 +124,7 @@ return -1; } - function _test($orig = "2001-04-25T09:31:41-0700") + function _test($orig = '2001-04-25T09:31:41-0700') { $utc = $this->toUTC($orig); $ts1 = $this->toUnixtime($orig); Index: pear/SOAP/Type/hexBinary.php diff -u pear/SOAP/Type/hexBinary.php:1.2 pear/SOAP/Type/hexBinary.php:1.3 --- pear/SOAP/Type/hexBinary.php:1.2 Wed Feb 20 03:16:33 2002 +++ pear/SOAP/Type/hexBinary.php Mon Feb 25 13:59:49 2002 @@ -1,11 +1,30 @@ <?php - +// +// +----------------------------------------------------------------------+ +// | PHP Version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2002 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.02 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more | +// | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | +// +----------------------------------------------------------------------+ +// +// $Id: hexBinary.php,v 1.3 2002/02/25 18:59:49 shane Exp $ +// class SOAP_Type_hexBinary { function to_bin($value) { $len = strlen($value); - return pack("H" . $len, $value); + return pack('H' . $len, $value); } function to_hex($value) { @@ -15,7 +34,9 @@ { # first see if there are any invalid chars $l = strlen($value); - if ($l < 1 || strspn($value, "0123456789ABCDEFabcdef") != $l) return FALSE; + + if ($l < 1 || strspn($value, '0123456789ABCDEFabcdef') != $l) return FALSE; + $bin = SOAP_Type_hexBinary::to_bin($value); $hex = SOAP_Type_hexBinary::to_hex($bin); return strcasecmp($value, $hex) == 0; Index: pear/SOAP/interop/client_params.php diff -u pear/SOAP/interop/client_params.php:1.3 pear/SOAP/interop/client_params.php:1.4 --- pear/SOAP/interop/client_params.php:1.3 Mon Feb 25 01:14:33 2002 +++ pear/SOAP/interop/client_params.php Mon Feb 25 13:59:50 2002 @@ -17,7 +17,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: client_params.php,v 1.3 2002/02/25 06:14:33 shane Exp $ +// $Id: client_params.php,v 1.4 2002/02/25 18:59:50 shane Exp $ // require_once("SOAP/Value.php"); @@ -127,7 +127,7 @@ "varFloat"=>325.325 ); $method_params["GroupB"]['soapval']["echoStructAsSimpleTypes"]['inputStruct'] = - new SOAP_Value("inputStruct","SOAPStruct", + new SOAP_Value("inputStruct","struct", array( #push struct elements into one soap value new SOAP_Value("varString","string","arg"), new SOAP_Value("varInt","int",34), Index: pear/SOAP/interop/client_round2_base.php diff -u pear/SOAP/interop/client_round2_base.php:1.7 pear/SOAP/interop/client_round2_base.php:1.8 --- pear/SOAP/interop/client_round2_base.php:1.7 Mon Feb 25 01:14:33 2002 +++ pear/SOAP/interop/client_round2_base.php Mon Feb 25 13:59:50 2002 @@ -17,7 +17,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: client_round2_base.php,v 1.7 2002/02/25 06:14:33 shane Exp $ +// $Id: client_round2_base.php,v 1.8 2002/02/25 18:59:50 shane Exp $ // require_once("SOAP/Client.php"); require_once("client_params.php"); @@ -27,7 +27,7 @@ $localonly = 0; // set to 1 to test only your local server $usebuiltin = 0; // use builtin list of endpoints -$test = 'GroupB'; // which test to do: base, GroupB, GroupC +$test = 'base'; // which test to do: base, GroupB, GroupC $parm = 'soapval'; // use base types: php, soapval $show = 1; $debug = 0; Index: pear/SOAP/interop/server_soapinterop_groupB.php diff -u pear/SOAP/interop/server_soapinterop_groupB.php:1.1 pear/SOAP/interop/server_soapinterop_groupB.php:1.2 --- pear/SOAP/interop/server_soapinterop_groupB.php:1.1 Mon Feb 25 00:06:37 2002 +++ pear/SOAP/interop/server_soapinterop_groupB.php Mon Feb 25 13:59:50 2002 @@ -17,7 +17,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: server_soapinterop_groupB.php,v 1.1 2002/02/25 05:06:37 shane Exp $ +// $Id: server_soapinterop_groupB.php,v 1.2 2002/02/25 18:59:50 shane Exp $ // require_once('SOAP/Server.php'); @@ -35,8 +35,19 @@ array('return' => 'struct')); function echoSimpleTypesAsStruct($string, $int, $float) { - # convert a SOAPStruct to an array - $ret = array($string, $int, $float); + # convert a input into struct + /*$ret = new SOAP_Value("return","struct", + array( #push struct elements into one soap value + new SOAP_Value("varString","string",$string), + new SOAP_Value("varInt","int",$int), + new SOAP_Value("varFloat","float",$float) + ) + );*/ + $ret = array( + "varString"=>$string, + "varInt"=>$int, + "varFloat"=>$float + ); return $ret; }
« previous php.pear.cvs (#2617) next »