forked from extern/egroupware
Formatting, add Id tags
This commit is contained in:
parent
d247b25603
commit
927fb55c0a
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/*
|
||||
|
||||
SOAPx4
|
||||
by Dietrich Ayala (C) 2001 dietrich@ganx4.com
|
||||
@ -13,7 +13,7 @@
|
||||
SOAP for PHP
|
||||
by Victor Zou (C) 2000-2001 <victor@gigaideas.com.cn>
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
/* changelog:
|
||||
2001-07-04
|
||||
@ -30,6 +30,9 @@
|
||||
|
||||
// $path can be a complete endpoint url, with the other parameters left blank:
|
||||
// $soap_client = new soap_client("http://path/to/soap/server");
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
class soap_client
|
||||
{
|
||||
function soap_client($path,$server=False,$port=False)
|
||||
@ -40,30 +43,30 @@
|
||||
$this->errno;
|
||||
$this->errstring;
|
||||
$this->debug_flag = False;
|
||||
$this->debug_str = "";
|
||||
$this->username = "";
|
||||
$this->password = "";
|
||||
$this->action = "";
|
||||
$this->incoming_payload = "";
|
||||
$this->outgoing_payload = "";
|
||||
$this->response = "";
|
||||
$this->action = "";
|
||||
$this->debug_str = '';
|
||||
$this->username = '';
|
||||
$this->password = '';
|
||||
$this->action = '';
|
||||
$this->incoming_payload = '';
|
||||
$this->outgoing_payload = '';
|
||||
$this->response = '';
|
||||
$this->action = '';
|
||||
|
||||
// endpoint mangling
|
||||
if(ereg("^http://",$path))
|
||||
{
|
||||
$path = str_replace("http://","",$path);
|
||||
$this->path = strstr($path,"/");
|
||||
$path = str_replace('http://','',$path);
|
||||
$this->path = strstr($path,'/');
|
||||
$this->debug("path = $this->path");
|
||||
if(ereg(":",$path))
|
||||
if(ereg(':',$path))
|
||||
{
|
||||
$this->server = substr($path,0,strpos($path,":"));
|
||||
$this->port = substr(strstr($path,":"),1);
|
||||
$this->port = substr($this->port,0,strpos($this->port,"/"));
|
||||
$this->server = substr($path,0,strpos($path,':'));
|
||||
$this->port = substr(strstr($path,':'),1);
|
||||
$this->port = substr($this->port,0,strpos($this->port,'/'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->server = substr($path,0,strpos($path,"/"));
|
||||
$this->server = substr($path,0,strpos($path,'/'));
|
||||
}
|
||||
}
|
||||
if($port)
|
||||
@ -132,19 +135,21 @@
|
||||
}
|
||||
|
||||
$soap_data = $msg->serialize();
|
||||
$this->outgoing_payload = "POST ".
|
||||
$this->path.
|
||||
" HTTP/1.0\r\n".
|
||||
"User-Agent: SOAPx4 v0.13492\r\n".
|
||||
"Host: ".$this->server . "\r\n".
|
||||
$credentials.
|
||||
"Content-Type: text/xml\r\nContent-Length: ".strlen($soap_data)."\r\n".
|
||||
"SOAPAction: \"$this->action\""."\r\n\r\n".
|
||||
$soap_data;
|
||||
$this->outgoing_payload = 'POST '
|
||||
. $this->path
|
||||
. " HTTP/1.0\r\n"
|
||||
. 'User-Agent: phpGroupware/' . $cliversion . '(PHP) ' . "\r\n"
|
||||
. 'X-PHPGW-Server: ' . $this->server . "\r\n"
|
||||
. 'X-PHPGW-Version: ' . $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] . "\r\n"
|
||||
. 'Host: '.$this->server . "\r\n"
|
||||
. $credentials
|
||||
. "Content-Type: text/xml\r\nContent-Length: " . strlen($soap_data) . "\r\n"
|
||||
. 'SOAPAction: "' . $this->action . '"' . "\r\n\r\n"
|
||||
. $soap_data;
|
||||
// send
|
||||
if(!fputs($fp, $this->outgoing_payload, strlen($this->outgoing_payload)))
|
||||
{
|
||||
$this->debug("Write error");
|
||||
$this->debug('Write error');
|
||||
}
|
||||
|
||||
// get reponse
|
||||
@ -181,15 +186,17 @@
|
||||
}
|
||||
|
||||
$soap_data = $msg->serialize();
|
||||
$this->outgoing_payload = "POST ".
|
||||
$this->path.
|
||||
" HTTP/1.0\r\n".
|
||||
"User-Agent: SOAPx4 v0.13492\r\n".
|
||||
"Host: ".$this->server . "\r\n".
|
||||
$credentials.
|
||||
"Content-Type: text/xml\r\nContent-Length: ".strlen($soap_data)."\r\n".
|
||||
"SOAPAction: \"$this->action\""."\r\n\r\n".
|
||||
$soap_data;
|
||||
$this->outgoing_payload = 'POST '
|
||||
. $this->path
|
||||
. " HTTP/1.0\r\n"
|
||||
. 'User-Agent: phpGroupware/' . $cliversion . '(PHP) ' . "\r\n"
|
||||
. 'X-PHPGW-Server: ' . $this->server . "\r\n"
|
||||
. 'X-PHPGW-Version: ' . $GLOBALS['phpgw_info']['server']['versions']['phpgwapi'] . "\r\n"
|
||||
. 'Host: ' . $this->server . "\r\n"
|
||||
. $credentials
|
||||
. "Content-Type: text/xml\r\nContent-Length: " . strlen($soap_data) . "\r\n"
|
||||
. 'SOAPAction: "' . $this->action . '"' . "\r\n\r\n"
|
||||
. $soap_data;
|
||||
|
||||
// send
|
||||
$ch = curl_init();
|
||||
|
@ -1,373 +1,375 @@
|
||||
<?php
|
||||
class soap_parser
|
||||
{
|
||||
function soap_parser($xml='',$encoding='UTF-8')
|
||||
/* $Id$ */
|
||||
|
||||
class soap_parser
|
||||
{
|
||||
global $soapTypes;
|
||||
|
||||
$this->soapTypes = $soapTypes;
|
||||
$this->xml = $xml;
|
||||
$this->xml_encoding = $encoding;
|
||||
$this->root_struct = "";
|
||||
// options: envelope,header,body,method
|
||||
// determines where in the message we are (envelope,header,body,method)
|
||||
$this->status = "";
|
||||
$this->position = 0;
|
||||
$this->pos_stat = 0;
|
||||
$this->depth = 0;
|
||||
$this->default_namespace = "";
|
||||
$this->namespaces = array();
|
||||
$this->message = array();
|
||||
$this->fault = false;
|
||||
$this->fault_code = "";
|
||||
$this->fault_str = "";
|
||||
$this->fault_detail = "";
|
||||
$this->eval_str = "";
|
||||
$this->depth_array = array();
|
||||
$this->debug_flag = True;
|
||||
$this->debug_str = "";
|
||||
$this->previous_element = "";
|
||||
|
||||
$this->entities = array (
|
||||
"&" => "&",
|
||||
"<" => "<",
|
||||
">" => ">",
|
||||
"'" => "'",
|
||||
'"' => """
|
||||
);
|
||||
|
||||
// Check whether content has been read.
|
||||
if(!empty($xml))
|
||||
function soap_parser($xml='',$encoding='UTF-8')
|
||||
{
|
||||
$this->debug("Entering soap_parser()");
|
||||
//$this->debug("DATA DUMP:\n\n$xml");
|
||||
// Create an XML parser.
|
||||
$this->parser = xml_parser_create($this->xml_encoding);
|
||||
// Set the options for parsing the XML data.
|
||||
//xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
|
||||
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
|
||||
// Set the object for the parser.
|
||||
xml_set_object($this->parser, &$this);
|
||||
// Set the element handlers for the parser.
|
||||
xml_set_element_handler($this->parser, "start_element","end_element");
|
||||
xml_set_character_data_handler($this->parser,"character_data");
|
||||
xml_set_default_handler($this->parser, "default_handler");
|
||||
global $soapTypes;
|
||||
|
||||
// Parse the XML file.
|
||||
if(!xml_parse($this->parser,$xml,true))
|
||||
$this->soapTypes = $soapTypes;
|
||||
$this->xml = $xml;
|
||||
$this->xml_encoding = $encoding;
|
||||
$this->root_struct = "";
|
||||
// options: envelope,header,body,method
|
||||
// determines where in the message we are (envelope,header,body,method)
|
||||
$this->status = '';
|
||||
$this->position = 0;
|
||||
$this->pos_stat = 0;
|
||||
$this->depth = 0;
|
||||
$this->default_namespace = '';
|
||||
$this->namespaces = array();
|
||||
$this->message = array();
|
||||
$this->fault = false;
|
||||
$this->fault_code = '';
|
||||
$this->fault_str = '';
|
||||
$this->fault_detail = '';
|
||||
$this->eval_str = '';
|
||||
$this->depth_array = array();
|
||||
$this->debug_flag = True;
|
||||
$this->debug_str = '';
|
||||
$this->previous_element = '';
|
||||
|
||||
$this->entities = array (
|
||||
'&' => '&',
|
||||
'<' => '<',
|
||||
'>' => '>',
|
||||
"'" => ''',
|
||||
'"' => '"'
|
||||
);
|
||||
|
||||
// Check whether content has been read.
|
||||
if(!empty($xml))
|
||||
{
|
||||
// Display an error message.
|
||||
$this->debug(sprintf("XML error on line %d: %s",
|
||||
xml_get_current_line_number($this->parser),
|
||||
xml_error_string(xml_get_error_code($this->parser))));
|
||||
$this->fault = true;
|
||||
$this->debug('Entering soap_parser()');
|
||||
//$this->debug("DATA DUMP:\n\n$xml");
|
||||
// Create an XML parser.
|
||||
$this->parser = xml_parser_create($this->xml_encoding);
|
||||
// Set the options for parsing the XML data.
|
||||
//xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
|
||||
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
|
||||
// Set the object for the parser.
|
||||
xml_set_object($this->parser, &$this);
|
||||
// Set the element handlers for the parser.
|
||||
xml_set_element_handler($this->parser, 'start_element','end_element');
|
||||
xml_set_character_data_handler($this->parser,'character_data');
|
||||
xml_set_default_handler($this->parser, 'default_handler');
|
||||
|
||||
// Parse the XML file.
|
||||
if(!xml_parse($this->parser,$xml,true))
|
||||
{
|
||||
// Display an error message.
|
||||
$this->debug(sprintf("XML error on line %d: %s",
|
||||
xml_get_current_line_number($this->parser),
|
||||
xml_error_string(xml_get_error_code($this->parser))));
|
||||
$this->fault = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// get final eval string
|
||||
$this->eval_str = "\$response = ".trim($this->build_eval($this->root_struct)).";";
|
||||
}
|
||||
xml_parser_free($this->parser);
|
||||
}
|
||||
else
|
||||
{
|
||||
// get final eval string
|
||||
$this->eval_str = "\$response = ".trim($this->build_eval($this->root_struct)).";";
|
||||
$this->debug("xml was empty, didn't parse!");
|
||||
}
|
||||
xml_parser_free($this->parser);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("xml was empty, didn't parse!");
|
||||
}
|
||||
}
|
||||
|
||||
// loop through msg, building eval_str
|
||||
function build_eval($pos)
|
||||
{
|
||||
$this->debug("inside build_eval() for $pos: ".$this->message[$pos]["name"]);
|
||||
$eval_str = $this->message[$pos]["eval_str"];
|
||||
// loop through children, building...
|
||||
if($this->message[$pos]["children"] != "")
|
||||
// loop through msg, building eval_str
|
||||
function build_eval($pos)
|
||||
{
|
||||
$this->debug("children string = ".$this->message[$pos]["children"]);
|
||||
$children = explode("|",$this->message[$pos]["children"]);
|
||||
$this->debug("it has ".count($children)." children");
|
||||
@reset($children);
|
||||
while(list($c,$child_pos) = @each($children))
|
||||
/* foreach($children as $c => $child_pos) */
|
||||
$this->debug("inside build_eval() for $pos: ".$this->message[$pos]["name"]);
|
||||
$eval_str = $this->message[$pos]['eval_str'];
|
||||
// loop through children, building...
|
||||
if($this->message[$pos]['children'] != '')
|
||||
{
|
||||
//$this->debug("child pos $child_pos: ".$this->message[$child_pos]["name"]);
|
||||
if($this->message[$child_pos]["eval_str"] != "")
|
||||
$this->debug('children string = '.$this->message[$pos]['children']);
|
||||
$children = explode('|',$this->message[$pos]['children']);
|
||||
$this->debug('it has '.count($children).' children');
|
||||
@reset($children);
|
||||
while(list($c,$child_pos) = @each($children))
|
||||
/* foreach($children as $c => $child_pos) */
|
||||
{
|
||||
$this->debug("entering build_eval() for ".$this->message[$child_pos]["name"].", array pos $c, pos: $child_pos");
|
||||
$eval_str .= $this->build_eval($child_pos).", ";
|
||||
//$this->debug("child pos $child_pos: ".$this->message[$child_pos]["name"]);
|
||||
if($this->message[$child_pos]['eval_str'] != '')
|
||||
{
|
||||
$this->debug('entering build_eval() for '.$this->message[$child_pos]['name'].", array pos $c, pos: $child_pos");
|
||||
$eval_str .= $this->build_eval($child_pos).', ';
|
||||
}
|
||||
}
|
||||
$eval_str = substr($eval_str,0,strlen($eval_str)-2);
|
||||
}
|
||||
$eval_str = substr($eval_str,0,strlen($eval_str)-2);
|
||||
// add current node's eval_str
|
||||
$eval_str .= $this->message[$pos]['end_eval_str'];
|
||||
return $eval_str;
|
||||
}
|
||||
// add current node's eval_str
|
||||
$eval_str .= $this->message[$pos]["end_eval_str"];
|
||||
return $eval_str;
|
||||
}
|
||||
|
||||
// start-element handler
|
||||
function start_element($parser, $name, $attrs)
|
||||
{
|
||||
// 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;
|
||||
// start-element handler
|
||||
function start_element($parser, $name, $attrs)
|
||||
{
|
||||
// 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;
|
||||
|
||||
// parent/child/depth determinations
|
||||
// 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++;
|
||||
// depth = how many levels removed from root?
|
||||
// set mine as current global depth and increment global depth value
|
||||
$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";
|
||||
}
|
||||
// set my 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
|
||||
$this->parent = $pos;
|
||||
// else add self as child to whoever the current parent is
|
||||
if($pos != 0)
|
||||
{
|
||||
$this->message[$this->parent]['children'] .= "|$pos";
|
||||
}
|
||||
// set my 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
|
||||
$this->parent = $pos;
|
||||
|
||||
// set status
|
||||
if(ereg(":Envelope$",$name))
|
||||
{
|
||||
$this->status = "envelope";
|
||||
}
|
||||
elseif(ereg(":Header$",$name))
|
||||
{
|
||||
$this->status = "header";
|
||||
}
|
||||
elseif(ereg(":Body$",$name))
|
||||
{
|
||||
$this->status = "body";
|
||||
// set method
|
||||
}
|
||||
elseif($this->status == "body")
|
||||
{
|
||||
$this->status = "method";
|
||||
// set status
|
||||
if(ereg(":Envelope$",$name))
|
||||
{
|
||||
$this->status = 'envelope';
|
||||
}
|
||||
elseif(ereg(":Header$",$name))
|
||||
{
|
||||
$this->status = 'header';
|
||||
}
|
||||
elseif(ereg(":Body$",$name))
|
||||
{
|
||||
$this->status = 'body';
|
||||
// set method
|
||||
}
|
||||
elseif($this->status == 'body')
|
||||
{
|
||||
$this->status = 'method';
|
||||
if(ereg(':',$name))
|
||||
{
|
||||
$this->root_struct_name = substr(strrchr($name,':'),1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->root_struct_name = $name;
|
||||
}
|
||||
$this->root_struct = $pos;
|
||||
$this->message[$pos]['type'] = 'struct';
|
||||
}
|
||||
// set my status
|
||||
$this->message[$pos]['status'] = $this->status;
|
||||
|
||||
// set name
|
||||
$this->message[$pos]['name'] = htmlspecialchars($name);
|
||||
// set attrs
|
||||
$this->message[$pos]['attrs'] = $attrs;
|
||||
// get namespace
|
||||
if(ereg(":",$name))
|
||||
{
|
||||
$this->root_struct_name = substr(strrchr($name,":"),1);
|
||||
$namespace = substr($name,0,strpos($name,':'));
|
||||
$this->message[$pos]['namespace'] = $namespace;
|
||||
$this->default_namespace = $namespace;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->root_struct_name = $name;
|
||||
$this->message[$pos]['namespace'] = $this->default_namespace;
|
||||
}
|
||||
$this->root_struct = $pos;
|
||||
$this->message[$pos]["type"] = "struct";
|
||||
}
|
||||
// set my status
|
||||
$this->message[$pos]["status"] = $this->status;
|
||||
|
||||
// set name
|
||||
$this->message[$pos]["name"] = htmlspecialchars($name);
|
||||
// set attrs
|
||||
$this->message[$pos]["attrs"] = $attrs;
|
||||
// get namespace
|
||||
if(ereg(":",$name))
|
||||
{
|
||||
$namespace = substr($name,0,strpos($name,":"));
|
||||
$this->message[$pos]["namespace"] = $namespace;
|
||||
$this->default_namespace = $namespace;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->message[$pos]["namespace"] = $this->default_namespace;
|
||||
}
|
||||
// loop through atts, logging ns and type declarations
|
||||
@reset($attrs);
|
||||
while (list($key,$value) = @each($attrs))
|
||||
/* foreach($attrs as $key => $value) */
|
||||
{
|
||||
// if ns declarations, add to class level array of valid namespaces
|
||||
if(ereg("xmlns:",$key))
|
||||
// loop through atts, logging ns and type declarations
|
||||
@reset($attrs);
|
||||
while (list($key,$value) = @each($attrs))
|
||||
/* foreach($attrs as $key => $value) */
|
||||
{
|
||||
$namespaces[substr(strrchr($key,":"),1)] = $value;
|
||||
if($name == $this->root_struct_name)
|
||||
// if ns declarations, add to class level array of valid namespaces
|
||||
if(ereg('xmlns:',$key))
|
||||
{
|
||||
$this->methodNamespace = $value;
|
||||
$namespaces[substr(strrchr($key,':'),1)] = $value;
|
||||
if($name == $this->root_struct_name)
|
||||
{
|
||||
$this->methodNamespace = $value;
|
||||
}
|
||||
}
|
||||
// if it's a type declaration, set type
|
||||
elseif($key == 'xsi:type')
|
||||
{
|
||||
// then get attname and set $type
|
||||
$type = substr(strrchr($value,':'),1);
|
||||
}
|
||||
}
|
||||
// if it's a type declaration, set type
|
||||
elseif($key == "xsi:type")
|
||||
|
||||
// set type if available
|
||||
if($type)
|
||||
{
|
||||
// then get attname and set $type
|
||||
$type = substr(strrchr($value,":"),1);
|
||||
$this->message[$pos]['type'] = $type;
|
||||
}
|
||||
|
||||
// debug
|
||||
//$this->debug("parsed $name start, eval = '".$this->message[$pos]["eval_str"]."'");
|
||||
}
|
||||
|
||||
// set type if available
|
||||
if($type)
|
||||
// end-element handler
|
||||
function end_element($parser, $name)
|
||||
{
|
||||
$this->message[$pos]["type"] = $type;
|
||||
}
|
||||
|
||||
// debug
|
||||
//$this->debug("parsed $name start, eval = '".$this->message[$pos]["eval_str"]."'");
|
||||
}
|
||||
|
||||
// end-element handler
|
||||
function end_element($parser, $name)
|
||||
{
|
||||
// position of current element is equal to the last value left in depth_array for my depth
|
||||
$pos = $this->depth_array[$this->depth];
|
||||
// bring depth down a notch
|
||||
$this->depth--;
|
||||
// position of current element is equal to the last value left in depth_array for my depth
|
||||
$pos = $this->depth_array[$this->depth];
|
||||
// bring depth down a notch
|
||||
$this->depth--;
|
||||
|
||||
// get type if not set already
|
||||
if($this->message[$pos]["type"] == "")
|
||||
{
|
||||
// if($this->message[$pos]["cdata"] == "" && $this->message[$pos]["children"] != "")
|
||||
if($this->message[$pos]["children"] != "")
|
||||
// get type if not set already
|
||||
if($this->message[$pos]['type'] == '')
|
||||
{
|
||||
$this->message[$pos]["type"] = "SOAPStruct";
|
||||
// if($this->message[$pos]['cdata'] == '' && $this->message[$pos]['children'] != '')
|
||||
if($this->message[$pos]['children'] != '')
|
||||
{
|
||||
$this->message[$pos]['type'] = 'SOAPStruct';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->message[$pos]['type'] = 'string';
|
||||
}
|
||||
}
|
||||
|
||||
// set eval str start if it has a valid type and is inside the method
|
||||
if($pos >= $this->root_struct)
|
||||
{
|
||||
$this->message[$pos]['eval_str'] .= "\n CreateObject(\"phpgwapi.soapval\",\"".htmlspecialchars($name)."\", \"".$this->message[$pos]["type"]."\" ";
|
||||
$this->message[$pos]['end_eval_str'] = ')';
|
||||
$this->message[$pos]['inval'] = 'true';
|
||||
/*
|
||||
if($this->message[$pos]["name"] == $this->root_struct_name){
|
||||
$this->message[$pos]["end_eval_str"] .= " ,\"$this->methodNamespace\"";
|
||||
}
|
||||
*/
|
||||
if($this->message[$pos]['children'] != '')
|
||||
{
|
||||
$this->message[$pos]['eval_str'] .= ', array( ';
|
||||
$this->message[$pos]['end_eval_str'] .= ' )';
|
||||
}
|
||||
}
|
||||
|
||||
// if i have no children and have cdata...then i must be a scalar value, so add my data to the eval_str
|
||||
if($this->status == 'method' && $this->message[$pos]['children'] == '')
|
||||
{
|
||||
// add cdata w/ no quotes if only int/float/dbl
|
||||
if($this->message[$pos]['type'] == 'string')
|
||||
{
|
||||
$this->message[$pos]['eval_str'] .= ", \"".$this->message[$pos]['cdata']."\"";
|
||||
}
|
||||
elseif($this->message[$pos]['type'] == 'int' || $this->message[$pos]['type'] == 'float' || $this->message[$pos]['type'] == 'double')
|
||||
{
|
||||
//$this->debug("adding cdata w/o quotes");
|
||||
$this->message[$pos]['eval_str'] .= ', '.trim($this->message[$pos]['cdata']);
|
||||
}
|
||||
elseif(is_string($this->message[$pos]['cdata']))
|
||||
{
|
||||
//$this->debug("adding cdata w/ quotes");
|
||||
$this->message[$pos]['eval_str'] .= ", \"".$this->message[$pos]['cdata']."\"";
|
||||
}
|
||||
}
|
||||
// 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 tag we are currently closing is the method wrapper
|
||||
if($pos == $this->root_struct)
|
||||
{
|
||||
$this->status = 'body';
|
||||
}
|
||||
elseif(ereg(':Body',$name))
|
||||
{
|
||||
$this->status = 'header';
|
||||
}
|
||||
elseif(ereg(':Header',$name))
|
||||
{
|
||||
$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']."'eval_str = '".trim($this->message[$pos]['eval_str'])."' and children = ".$this->message[$pos]['children']);
|
||||
}
|
||||
|
||||
// element content handler
|
||||
function character_data($parser, $data)
|
||||
{
|
||||
$pos = $this->depth_array[$this->depth];
|
||||
$this->message[$pos]['cdata'] .= $data;
|
||||
//$this->debug("parsed ".$this->message[$pos]["name"]." cdata, eval = '$this->eval_str'");
|
||||
}
|
||||
|
||||
// default handler
|
||||
function default_handler($parser, $data)
|
||||
{
|
||||
//$this->debug("DEFAULT HANDLER: $data");
|
||||
}
|
||||
|
||||
// function to get fault code
|
||||
function fault()
|
||||
{
|
||||
if($this->fault)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->message[$pos]["type"] = "string";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// set eval str start if it has a valid type and is inside the method
|
||||
if($pos >= $this->root_struct)
|
||||
// have this return a soap_val object
|
||||
function get_response()
|
||||
{
|
||||
$this->message[$pos]["eval_str"] .= "\n CreateObject(\"phpgwapi.soapval\",\"".htmlspecialchars($name)."\", \"".$this->message[$pos]["type"]."\" ";
|
||||
$this->message[$pos]["end_eval_str"] = ")";
|
||||
$this->message[$pos]["inval"] = "true";
|
||||
/*
|
||||
if($this->message[$pos]["name"] == $this->root_struct_name){
|
||||
$this->message[$pos]["end_eval_str"] .= " ,\"$this->methodNamespace\"";
|
||||
}
|
||||
*/
|
||||
if($this->message[$pos]["children"] != "")
|
||||
$this->debug("eval()ing eval_str: $this->eval_str");
|
||||
@eval("$this->eval_str");
|
||||
if($response)
|
||||
{
|
||||
$this->message[$pos]["eval_str"] .= ", array( ";
|
||||
$this->message[$pos]["end_eval_str"] .= " )";
|
||||
$this->debug("successfully eval'd msg");
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
// if i have no children and have cdata...then i must be a scalar value, so add my data to the eval_str
|
||||
if($this->status == "method" && $this->message[$pos]["children"] == "")
|
||||
{
|
||||
// add cdata w/ no quotes if only int/float/dbl
|
||||
if($this->message[$pos]["type"] == "string")
|
||||
else
|
||||
{
|
||||
$this->message[$pos]["eval_str"] .= ", \"".$this->message[$pos]["cdata"]."\"";
|
||||
}
|
||||
elseif($this->message[$pos]["type"] == "int" || $this->message[$pos]["type"] == "float" || $this->message[$pos]["type"] == "double")
|
||||
{
|
||||
//$this->debug("adding cdata w/o quotes");
|
||||
$this->message[$pos]["eval_str"] .= ", ".trim($this->message[$pos]["cdata"]);
|
||||
}
|
||||
elseif(is_string($this->message[$pos]["cdata"]))
|
||||
{
|
||||
//$this->debug("adding cdata w/ quotes");
|
||||
$this->message[$pos]["eval_str"] .= ", \"".$this->message[$pos]["cdata"]."\"";
|
||||
}
|
||||
}
|
||||
// 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 tag we are currently closing is the method wrapper
|
||||
if($pos == $this->root_struct)
|
||||
{
|
||||
$this->status = "body";
|
||||
}
|
||||
elseif(ereg(":Body",$name))
|
||||
{
|
||||
$this->status = "header";
|
||||
}
|
||||
elseif(ereg(":Header",$name))
|
||||
{
|
||||
$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"]."'eval_str = '".trim($this->message[$pos]["eval_str"])."' and children = ".$this->message[$pos]["children"]);
|
||||
}
|
||||
|
||||
// element content handler
|
||||
function character_data($parser, $data)
|
||||
{
|
||||
$pos = $this->depth_array[$this->depth];
|
||||
$this->message[$pos]["cdata"] .= $data;
|
||||
//$this->debug("parsed ".$this->message[$pos]["name"]." cdata, eval = '$this->eval_str'");
|
||||
}
|
||||
|
||||
// default handler
|
||||
function default_handler($parser, $data)
|
||||
{
|
||||
//$this->debug("DEFAULT HANDLER: $data");
|
||||
}
|
||||
|
||||
// function to get fault code
|
||||
function fault()
|
||||
{
|
||||
if($this->fault)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// have this return a soap_val object
|
||||
function get_response()
|
||||
{
|
||||
$this->debug("eval()ing eval_str: $this->eval_str");
|
||||
@eval("$this->eval_str");
|
||||
if($response)
|
||||
{
|
||||
$this->debug("successfully eval'd msg");
|
||||
return $response;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("ERROR: did not successfully eval the msg");
|
||||
$this->fault = true;
|
||||
return CreateObject('phpgwapi.soapval',
|
||||
"Fault",
|
||||
"struct",
|
||||
array(
|
||||
CreateObject('phpgwapi.soapval',
|
||||
"faultcode",
|
||||
"string",
|
||||
"SOAP-ENV:Server"
|
||||
),
|
||||
CreateObject('phpgwapi.soapval',
|
||||
"faultstring",
|
||||
"string",
|
||||
"couldn't eval \"$this->eval_str\""
|
||||
$this->debug('ERROR: did not successfully eval the msg');
|
||||
$this->fault = true;
|
||||
return CreateObject('phpgwapi.soapval',
|
||||
'Fault',
|
||||
'struct',
|
||||
array(
|
||||
CreateObject('phpgwapi.soapval',
|
||||
'faultcode',
|
||||
'string',
|
||||
'SOAP-ENV:Server'
|
||||
),
|
||||
CreateObject('phpgwapi.soapval',
|
||||
'faultstring',
|
||||
'string',
|
||||
"couldn't eval \"$this->eval_str\""
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function debug($string)
|
||||
{
|
||||
if($this->debug_flag)
|
||||
function debug($string)
|
||||
{
|
||||
$this->debug_str .= "$string\n";
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$this->debug_str .= "$string\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function decode_entities($text)
|
||||
{
|
||||
@reset($this->entities);
|
||||
while(list($entity,$encoded) = @each($this->entities))
|
||||
/* foreach($this->entities as $entity => $encoded) */
|
||||
function decode_entities($text)
|
||||
{
|
||||
$text = str_replace($encoded,$entity,$text);
|
||||
@reset($this->entities);
|
||||
while(list($entity,$encoded) = @each($this->entities))
|
||||
/* foreach($this->entities as $entity => $encoded) */
|
||||
{
|
||||
$text = str_replace($encoded,$entity,$text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -1,443 +1,444 @@
|
||||
<?php
|
||||
// SOAP server class
|
||||
// SOAP server class
|
||||
|
||||
// for example usage, see the test_server.php file.
|
||||
// for example usage, see the test_server.php file.
|
||||
|
||||
/* changelog:
|
||||
2001-07-05
|
||||
- detection of character encoding in Content-Type header. server
|
||||
will now call the soap_parser object with the specified encoding
|
||||
- server will now return the Content-Type header with the sender's encoding type specified
|
||||
must still learn more bout encoding, and figure out what i have to do to be able to
|
||||
make sure that my response is *actually* encoded correctly
|
||||
2001-07-21
|
||||
- force proper error reporting for windows compatibility
|
||||
2001-07-27
|
||||
- get_all_headers() check for windows compatibility
|
||||
/* changelog:
|
||||
2001-07-05
|
||||
- detection of character encoding in Content-Type header. server
|
||||
will now call the soap_parser object with the specified encoding
|
||||
- server will now return the Content-Type header with the sender's encoding type specified
|
||||
must still learn more bout encoding, and figure out what i have to do to be able to
|
||||
make sure that my response is *actually* encoded correctly
|
||||
2001-07-21
|
||||
- force proper error reporting for windows compatibility
|
||||
2001-07-27
|
||||
- get_all_headers() check for windows compatibility
|
||||
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
*/
|
||||
// make errors handle properly in windows
|
||||
error_reporting(2039);
|
||||
|
||||
// make errors handle properly in windows
|
||||
error_reporting(2039);
|
||||
|
||||
class soap_server
|
||||
{
|
||||
function soap_server()
|
||||
class soap_server
|
||||
{
|
||||
// create empty dispatch map
|
||||
$this->dispatch_map = array();
|
||||
$this->debug_flag = True;
|
||||
$this->debug_str = '';
|
||||
$this->headers = '';
|
||||
$this->request = '';
|
||||
$this->xml_encoding = 'UTF-8';
|
||||
$this->fault = false;
|
||||
$this->fault_code = '';
|
||||
$this->fault_str = '';
|
||||
$this->fault_actor = '';
|
||||
// for logging interop results to db
|
||||
$this->result = 'successful';
|
||||
}
|
||||
|
||||
// parses request and posts response
|
||||
function service($data)
|
||||
{
|
||||
// $response is a soap_msg object
|
||||
$response = $this->parse_request($data);
|
||||
$this->debug("parsed request and got an object of this class '".get_class($response)."'");
|
||||
$this->debug("server sending...");
|
||||
// pass along the debug string
|
||||
if($this->debug_flag)
|
||||
function soap_server()
|
||||
{
|
||||
$response->debug($this->debug_str);
|
||||
}
|
||||
$payload = $response->serialize();
|
||||
// print headers
|
||||
if($this->fault)
|
||||
{
|
||||
$header[] = "HTTP/1.0 500 Internal Server Error\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$header[] = "HTTP/1.0 200 OK\r\n";
|
||||
$header[] = "Status: 200\r\n";
|
||||
}
|
||||
$header[] = "Server: SOAPx4 Server v0.344359s\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";
|
||||
@reset($header);
|
||||
while(list($null,$hdr) = @each($header))
|
||||
/* foreach($header as $hdr) */
|
||||
{
|
||||
header($hdr);
|
||||
}
|
||||
print $payload;
|
||||
}
|
||||
|
||||
function parse_request($data='')
|
||||
{
|
||||
global $HTTP_SERVER_VARS;
|
||||
|
||||
$this->debug("entering parse_request() on ".date("H:i Y-m-d"));
|
||||
$request_uri = $HTTP_SERVER_VARS["REQUEST_URI"];
|
||||
$this->debug("request uri: $request_uri");
|
||||
// get headers
|
||||
if(function_exists("getallheaders"))
|
||||
{
|
||||
$this->headers = getallheaders();
|
||||
while(list($k,$v) = @each($this->headers))
|
||||
/* foreach($this->headers as $k=>$v) */
|
||||
{
|
||||
$dump .= "$k: $v\r\n";
|
||||
}
|
||||
// get SOAPAction header
|
||||
if($this->headers["SOAPAction"])
|
||||
{
|
||||
$this->SOAPAction = str_replace('"','',$this->headers["SOAPAction"]);
|
||||
$this->service = $this->SOAPAction;
|
||||
}
|
||||
// get character encoding
|
||||
if(ereg("=",$this->headers["Content-Type"]))
|
||||
{
|
||||
$this->xml_encoding = str_replace("\"","",substr(strstr($this->headers["Content-Type"],"="),1));
|
||||
}
|
||||
elseif(ereg("^text/xml",$this->headers["Content-Type"]))
|
||||
{
|
||||
$this->xml_encoding = "us-ascii";
|
||||
}
|
||||
$this->debug("got encoding: $this->xml_encoding");
|
||||
}
|
||||
$this->request = $dump."\r\n\r\n".$data;
|
||||
// parse response, get soap parser obj
|
||||
$parser = CreateObject('phpgwapi.soap_parser',$data);
|
||||
// get/set methodname
|
||||
$this->methodname = $parser->root_struct_name;
|
||||
$this->debug("method name: $this->methodname");
|
||||
|
||||
// does method exist?
|
||||
if(function_exists($this->methodname))
|
||||
{
|
||||
$this->debug("method '$this->methodname' exists");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phpgroupware customization - createobject based on methodname */
|
||||
list($app,$class,$method) = explode('.',$this->methodname);
|
||||
$obj = CreateObject(sprintf('%s.%s',$app,$class));
|
||||
/*
|
||||
// "method not found" fault here
|
||||
$this->debug("method '$obj->method' not found!");
|
||||
$this->result = "fault: method not found";
|
||||
$this->make_fault("Server","method '$obj->method' not defined in service '$this->service'");
|
||||
return $this->fault();
|
||||
*/
|
||||
// create empty dispatch map
|
||||
$this->dispatch_map = array();
|
||||
$this->debug_flag = True;
|
||||
$this->debug_str = '';
|
||||
$this->headers = '';
|
||||
$this->request = '';
|
||||
$this->xml_encoding = 'UTF-8';
|
||||
$this->fault = false;
|
||||
$this->fault_code = '';
|
||||
$this->fault_str = '';
|
||||
$this->fault_actor = '';
|
||||
// for logging interop results to db
|
||||
$this->result = 'successful';
|
||||
}
|
||||
|
||||
// if fault occurred during message parsing
|
||||
if($parser->fault())
|
||||
// parses request and posts response
|
||||
function service($data)
|
||||
{
|
||||
// parser debug
|
||||
$this->debug($parser->debug_str);
|
||||
$this->result = "fault: error in msg parsing or eval";
|
||||
$this->make_fault("Server","error in msg parsing or eval:\n".$parser->get_response());
|
||||
// return soapresp
|
||||
return $this->fault();
|
||||
// else successfully parsed request into soapval object
|
||||
}
|
||||
else
|
||||
{
|
||||
// get eval_str
|
||||
$this->debug("calling parser->get_response()");
|
||||
// evaluate it, getting back a soapval object
|
||||
if(!$request_val = $parser->get_response())
|
||||
// $response is a soap_msg object
|
||||
$response = $this->parse_request($data);
|
||||
$this->debug("parsed request and got an object of this class '".get_class($response)."'");
|
||||
$this->debug("server sending...");
|
||||
// pass along the debug string
|
||||
if($this->debug_flag)
|
||||
{
|
||||
return $this->fault();
|
||||
$response->debug($this->debug_str);
|
||||
}
|
||||
// parser debug
|
||||
$this->debug($parser->debug_str);
|
||||
if(get_class($request_val) == "soapval")
|
||||
$payload = $response->serialize();
|
||||
// print headers
|
||||
if($this->fault)
|
||||
{
|
||||
if (is_object($obj))
|
||||
$header[] = "HTTP/1.0 500 Internal Server Error\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$header[] = "HTTP/1.0 200 OK\r\n";
|
||||
$header[] = "Status: 200\r\n";
|
||||
}
|
||||
$header[] = "Server: SOAPx4 Server v0.344359s\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";
|
||||
@reset($header);
|
||||
while(list($null,$hdr) = @each($header))
|
||||
/* foreach($header as $hdr) */
|
||||
{
|
||||
header($hdr);
|
||||
}
|
||||
print $payload;
|
||||
}
|
||||
|
||||
function parse_request($data='')
|
||||
{
|
||||
global $HTTP_SERVER_VARS;
|
||||
|
||||
$this->debug('entering parse_request() on '.date('H:i Y-m-d'));
|
||||
$request_uri = $HTTP_SERVER_VARS['REQUEST_URI'];
|
||||
$this->debug("request uri: $request_uri");
|
||||
// get headers
|
||||
if(function_exists('getallheaders'))
|
||||
{
|
||||
$this->headers = getallheaders();
|
||||
while(list($k,$v) = @each($this->headers))
|
||||
/* foreach($this->headers as $k=>$v) */
|
||||
{
|
||||
/* Add the function to the server map */
|
||||
$in = "array('" . implode("','",$obj->soap_functions[$method]['in']) . "')";
|
||||
$out = "array('" . implode("','",$obj->soap_functions[$method]['out']) . "')";
|
||||
$evalmap = "\$this->add_to_map(\$this->methodname,$in,$out);";
|
||||
eval($evalmap);
|
||||
$dump .= "$k: $v\r\n";
|
||||
}
|
||||
/* verify that soapval objects in request match the methods signature */
|
||||
if($this->verify_method($request_val))
|
||||
// get SOAPAction header
|
||||
if($this->headers['SOAPAction'])
|
||||
{
|
||||
$this->debug("request data - name: $request_val->name, type: $request_val->type, value: $request_val->value");
|
||||
if($this->input_value)
|
||||
{
|
||||
/* decode the soapval object, and pass resulting values to the requested method */
|
||||
if(!$request_data = $request_val->decode())
|
||||
{
|
||||
$this->make_fault("Server","Unable to decode response from soapval object into native php type.");
|
||||
return $this->fault();
|
||||
}
|
||||
$this->debug("request data: $request_data");
|
||||
}
|
||||
$this->SOAPAction = str_replace('"','',$this->headers['SOAPAction']);
|
||||
$this->service = $this->SOAPAction;
|
||||
}
|
||||
// get character encoding
|
||||
if(ereg("=",$this->headers['Content-Type']))
|
||||
{
|
||||
$this->xml_encoding = str_replace("\"","",substr(strstr($this->headers["Content-Type"],"="),1));
|
||||
}
|
||||
elseif(ereg("^text/xml",$this->headers['Content-Type']))
|
||||
{
|
||||
$this->xml_encoding = 'us-ascii';
|
||||
}
|
||||
$this->debug("got encoding: $this->xml_encoding");
|
||||
}
|
||||
$this->request = $dump."\r\n\r\n".$data;
|
||||
// parse response, get soap parser obj
|
||||
$parser = CreateObject('phpgwapi.soap_parser',$data);
|
||||
// get/set methodname
|
||||
$this->methodname = $parser->root_struct_name;
|
||||
$this->debug("method name: $this->methodname");
|
||||
|
||||
// does method exist?
|
||||
if(function_exists($this->methodname))
|
||||
{
|
||||
$this->debug("method '$this->methodname' exists");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phpgroupware customization - createobject based on methodname */
|
||||
list($app,$class,$method) = explode('.',$this->methodname);
|
||||
$obj = CreateObject(sprintf('%s.%s',$app,$class));
|
||||
/*
|
||||
// "method not found" fault here
|
||||
$this->debug("method '$obj->method' not found!");
|
||||
$this->result = "fault: method not found";
|
||||
$this->make_fault("Server","method '$obj->method' not defined in service '$this->service'");
|
||||
return $this->fault();
|
||||
*/
|
||||
}
|
||||
|
||||
/* if there are return values */
|
||||
if($this->return_type = $this->get_return_type())
|
||||
// if fault occurred during message parsing
|
||||
if($parser->fault())
|
||||
{
|
||||
// parser debug
|
||||
$this->debug($parser->debug_str);
|
||||
$this->result = 'fault: error in msg parsing or eval';
|
||||
$this->make_fault("Server","error in msg parsing or eval:\n".$parser->get_response());
|
||||
// return soapresp
|
||||
return $this->fault();
|
||||
// else successfully parsed request into soapval object
|
||||
}
|
||||
else
|
||||
{
|
||||
// get eval_str
|
||||
$this->debug('calling parser->get_response()');
|
||||
// evaluate it, getting back a soapval object
|
||||
if(!$request_val = $parser->get_response())
|
||||
{
|
||||
return $this->fault();
|
||||
}
|
||||
// parser debug
|
||||
$this->debug($parser->debug_str);
|
||||
if(get_class($request_val) == 'soapval')
|
||||
{
|
||||
if (is_object($obj))
|
||||
{
|
||||
$this->debug("got return type: '$this->return_type'");
|
||||
/* if there are parameters to pass */
|
||||
if($request_data)
|
||||
/* Add the function to the server map */
|
||||
$in = "array('" . implode("','",$obj->soap_functions[$method]['in']) . "')";
|
||||
$out = "array('" . implode("','",$obj->soap_functions[$method]['out']) . "')";
|
||||
$evalmap = "\$this->add_to_map(\$this->methodname,$in,$out);";
|
||||
eval($evalmap);
|
||||
}
|
||||
/* verify that soapval objects in request match the methods signature */
|
||||
if($this->verify_method($request_val))
|
||||
{
|
||||
$this->debug("request data - name: $request_val->name, type: $request_val->type, value: $request_val->value");
|
||||
if($this->input_value)
|
||||
{
|
||||
if (is_object($obj))
|
||||
/* decode the soapval object, and pass resulting values to the requested method */
|
||||
if(!$request_data = $request_val->decode())
|
||||
{
|
||||
$code = "\$method_response = call_user_method(\$method,\$obj,";
|
||||
$this->debug("about to call method '$class -> $method'");
|
||||
$this->make_fault("Server","Unable to decode response from soapval object into native php type.");
|
||||
return $this->fault();
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = "\$method_response = call_user_func(\$this->methodname,";
|
||||
$this->debug("about to call method '$this->methodname'");
|
||||
}
|
||||
/* call method with parameters */
|
||||
$this->debug("about to call method '$class -> $method'");
|
||||
while(list($x,$y) = each($request_data))
|
||||
{
|
||||
$code .= "\$request_data[$x]" . ',';
|
||||
}
|
||||
$code = substr($code,0,-1) .");";
|
||||
if(eval($code))
|
||||
$this->debug("request data: $request_data");
|
||||
}
|
||||
|
||||
/* if there are return values */
|
||||
if($this->return_type = $this->get_return_type())
|
||||
{
|
||||
$this->debug("got return type: '$this->return_type'");
|
||||
/* if there are parameters to pass */
|
||||
if($request_data)
|
||||
{
|
||||
if (is_object($obj))
|
||||
{
|
||||
$this->make_fault("Server","Method call failed for '$obj->method' with params: ".join(",",$request_data));
|
||||
$code = "\$method_response = call_user_method(\$method,\$obj,";
|
||||
$this->debug("about to call method '$class -> $method'");
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->make_fault("Server","Method call failed for '$this->methodname' with params: ".join(",",$request_data));
|
||||
$code = "\$method_response = call_user_func(\$this->methodname,";
|
||||
$this->debug("about to call method '$this->methodname'");
|
||||
}
|
||||
return $this->fault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* call method w/ no parameters */
|
||||
if (is_object($obj))
|
||||
{
|
||||
$this->debug("about to call method '$obj->method'");
|
||||
if(!$method_response = call_user_method($method,$obj))
|
||||
/* call method with parameters */
|
||||
$this->debug("about to call method '$class -> $method'");
|
||||
while(list($x,$y) = each($request_data))
|
||||
{
|
||||
$this->make_fault("Server","Method call failed for '$obj->method' with no params");
|
||||
$code .= "\$request_data[$x]" . ',';
|
||||
}
|
||||
$code = substr($code,0,-1) .');';
|
||||
if(eval($code))
|
||||
{
|
||||
if (is_object($obj))
|
||||
{
|
||||
$this->make_fault("Server","Method call failed for '$obj->method' with params: ".join(",",$request_data));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->make_fault("Server","Method call failed for '$this->methodname' with params: ".join(",",$request_data));
|
||||
}
|
||||
return $this->fault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("about to call method '$this->methodname'");
|
||||
if(!$method_response = call_user_func($this->methodname))
|
||||
/* call method w/ no parameters */
|
||||
if (is_object($obj))
|
||||
{
|
||||
$this->make_fault("Server","Method call failed for '$this->methodname' with no params");
|
||||
return $this->fault();
|
||||
$this->debug("about to call method '$obj->method'");
|
||||
if(!$method_response = call_user_method($method,$obj))
|
||||
{
|
||||
$this->make_fault("Server","Method call failed for '$obj->method' with no params");
|
||||
return $this->fault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("about to call method '$this->methodname'");
|
||||
if(!$method_response = call_user_func($this->methodname))
|
||||
{
|
||||
$this->make_fault("Server","Method call failed for '$this->methodname' with no params");
|
||||
return $this->fault();
|
||||
}
|
||||
}
|
||||
}
|
||||
/* no return values */
|
||||
}
|
||||
/* no return values */
|
||||
}
|
||||
else
|
||||
{
|
||||
if($request_data)
|
||||
else
|
||||
{
|
||||
/* call method with parameters */
|
||||
$code = "\$method_response = call_user_method(\$method,\$obj,";
|
||||
while(list($x,$y) = each($request_data))
|
||||
if($request_data)
|
||||
{
|
||||
$code .= "\$request_data[$x]" . ',';
|
||||
/* call method with parameters */
|
||||
$code = "\$method_response = call_user_method(\$method,\$obj,";
|
||||
while(list($x,$y) = each($request_data))
|
||||
{
|
||||
$code .= "\$request_data[$x]" . ',';
|
||||
}
|
||||
$code = substr($code,0,-1) .');';
|
||||
$this->debug("about to call method '$obj->method'");
|
||||
eval($code);
|
||||
}
|
||||
$code = substr($code,0,-1) .");";
|
||||
$this->debug("about to call method '$obj->method'");
|
||||
eval($code);
|
||||
else
|
||||
{
|
||||
/* call method w/ no parameters */
|
||||
$this->debug("about to call method '$obj->method'");
|
||||
call_user_method($method,$obj);
|
||||
}
|
||||
}
|
||||
/* return fault */
|
||||
if(get_class($method_response) == 'soapmsg')
|
||||
{
|
||||
if(eregi('fault',$method_response->value->name))
|
||||
{
|
||||
$this->fault = True;
|
||||
}
|
||||
$return_msg = $method_response;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* call method w/ no parameters */
|
||||
$this->debug("about to call method '$obj->method'");
|
||||
call_user_method($method,$obj);
|
||||
/* return soapval object */
|
||||
|
||||
if(get_class($method_response) == 'soapval')
|
||||
{
|
||||
$return_val = $method_response;
|
||||
/* create soap_val object w/ return values from method, use method signature to determine type */
|
||||
}
|
||||
else
|
||||
{
|
||||
$return_val = CreateObject('phpgwapi.soapval',$method,$this->return_type,$method_response);
|
||||
}
|
||||
$this->debug($return_val->debug_str);
|
||||
/* response object is a soap_msg object */
|
||||
$return_msg = CreateObject('phpgwapi.soapmsg',$method.'Response',array($return_val),$this->service);
|
||||
}
|
||||
}
|
||||
/* return fault */
|
||||
if(get_class($method_response) == "soapmsg")
|
||||
{
|
||||
if(eregi("fault",$method_response->value->name))
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$this->fault = True;
|
||||
$return_msg->debug_flag = true;
|
||||
}
|
||||
$return_msg = $method_response;
|
||||
$this->result = 'successful';
|
||||
return $return_msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* return soapval object */
|
||||
|
||||
if(get_class($method_response) == "soapval")
|
||||
{
|
||||
$return_val = $method_response;
|
||||
/* create soap_val object w/ return values from method, use method signature to determine type */
|
||||
}
|
||||
else
|
||||
{
|
||||
$return_val = CreateObject('phpgwapi.soapval',$method,$this->return_type,$method_response);
|
||||
}
|
||||
$this->debug($return_val->debug_str);
|
||||
/* response object is a soap_msg object */
|
||||
$return_msg = CreateObject('phpgwapi.soapmsg',$method."Response",array($return_val),$this->service);
|
||||
// debug
|
||||
$this->debug("ERROR: request not verified against method signature");
|
||||
$this->result = "fault: request failed validation against method signature";
|
||||
// return soapresp
|
||||
return $this->fault();
|
||||
}
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$return_msg->debug_flag = true;
|
||||
}
|
||||
$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";
|
||||
// return soapresp
|
||||
$this->debug("ERROR: parser did not return soapval object: $request_val ".get_class($request_val));
|
||||
$this->result = "fault: parser did not return soapval object: $request_val";
|
||||
// return fault
|
||||
$this->make_fault('Server',"parser did not return soapval object: $request_val");
|
||||
return $this->fault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// debug
|
||||
$this->debug("ERROR: parser did not return soapval object: $request_val ".get_class($request_val));
|
||||
$this->result = "fault: parser did not return soapval object: $request_val";
|
||||
// return fault
|
||||
$this->make_fault("Server","parser did not return soapval object: $request_val");
|
||||
return $this->fault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function verify_method($request)
|
||||
{
|
||||
//return true;
|
||||
$this->debug("entered verify_method() w/ request name: ".$request->name);
|
||||
$params = $request->value;
|
||||
// if there are input parameters required...
|
||||
if($sig = $this->dispatch_map[$this->methodname]["in"])
|
||||
function verify_method($request)
|
||||
{
|
||||
$this->input_value = count($sig);
|
||||
if(is_array($params))
|
||||
//return true;
|
||||
$this->debug('entered verify_method() w/ request name: '.$request->name);
|
||||
$params = $request->value;
|
||||
// if there are input parameters required...
|
||||
if($sig = $this->dispatch_map[$this->methodname]["in"])
|
||||
{
|
||||
$this->debug("entered verify_method() with ".count($params)." parameters");
|
||||
@reset($params);
|
||||
while(list($null,$v) = @each($params))
|
||||
/* foreach($params as $v) */
|
||||
$this->input_value = count($sig);
|
||||
if(is_array($params))
|
||||
{
|
||||
$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));
|
||||
// make array of param types
|
||||
$this->debug('entered verify_method() with '.count($params).' parameters');
|
||||
@reset($params);
|
||||
while(list($null,$param) = @each($params))
|
||||
/* foreach($params as $param) */
|
||||
while(list($null,$v) = @each($params))
|
||||
/* foreach($params as $v) */
|
||||
{
|
||||
$p[] = strtolower($param->type);
|
||||
$this->debug("param '$v->name' of type '$v->type'");
|
||||
}
|
||||
// validate each param's type
|
||||
for($i=0; $i < count($p); $i++)
|
||||
// validate the number of parameters
|
||||
if(count($params) == count($sig))
|
||||
{
|
||||
// type not match
|
||||
if(strtolower($sig[$i]) != strtolower($p[$i]))
|
||||
$this->debug("got correct number of parameters: ".count($sig));
|
||||
// make array of param types
|
||||
@reset($params);
|
||||
while(list($null,$param) = @each($params))
|
||||
/* foreach($params as $param) */
|
||||
{
|
||||
$this->debug("mismatched parameter types: $sig[$i] != $p[$i]");
|
||||
$this->make_fault("Client","soap request contained mismatching parameters of name $v->name had type $p[$i], which did not match signature's type: $sig[$i]");
|
||||
return false;
|
||||
$p[] = strtolower($param->type);
|
||||
}
|
||||
$this->debug("parameter type match: $sig[$i] = $p[$i]");
|
||||
// validate each param's type
|
||||
for($i=0; $i < count($p); $i++)
|
||||
{
|
||||
// type not match
|
||||
if(strtolower($sig[$i]) != strtolower($p[$i]))
|
||||
{
|
||||
$this->debug("mismatched parameter types: $sig[$i] != $p[$i]");
|
||||
$this->make_fault('Client',"soap request contained mismatching parameters of name $v->name had type $p[$i], which did not match signature's type: $sig[$i]");
|
||||
return false;
|
||||
}
|
||||
$this->debug("parameter type match: $sig[$i] = $p[$i]");
|
||||
}
|
||||
return true;
|
||||
// oops, wrong number of paramss
|
||||
}
|
||||
return true;
|
||||
// oops, wrong number of paramss
|
||||
else
|
||||
{
|
||||
$this->debug('oops, wrong number of parameter!');
|
||||
$this->make_fault('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, wrong number of parameter!");
|
||||
$this->make_fault("Client","soap request contained incorrect number of parameters. method '$this->methodname' required ".count($sig)." and request provided ".count($params));
|
||||
$this->debug("oops, no parameters sent! Method '$this->methodname' requires ".count($sig)." input parameters!");
|
||||
$this->make_fault('Client',"soap request contained incorrect number of parameters. method '$this->methodname' requires ".count($sig)." parameters, and request provided none");
|
||||
return false;
|
||||
}
|
||||
// oops, no params...
|
||||
// no params
|
||||
}
|
||||
elseif( (count($params)==0) && (count($sig) <= 1) )
|
||||
{
|
||||
$this->input_values = 0;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("oops, no parameters sent! Method '$this->methodname' requires ".count($sig)." input parameters!");
|
||||
$this->make_fault("Client","soap request contained incorrect number of parameters. method '$this->methodname' requires ".count($sig)." parameters, and request provided none");
|
||||
return false;
|
||||
//$this->debug("well, request passed parameters to a method that requires none?");
|
||||
//$this->make_fault("Client","method '$this->methodname' requires no parameters. The request passed in ".count($params).": ".@implode(" param: ",$params) );
|
||||
return true;
|
||||
}
|
||||
// no params
|
||||
}
|
||||
elseif( (count($params)==0) && (count($sig) <= 1) )
|
||||
|
||||
// get string return type from dispatch map
|
||||
function get_return_type()
|
||||
{
|
||||
$this->input_values = 0;
|
||||
return true;
|
||||
if(count($this->dispatch_map[$this->methodname]['out']) >= 1)
|
||||
{
|
||||
$type = array_shift($this->dispatch_map[$this->methodname]['out']);
|
||||
$this->debug("got return type from dispatch map: '$type'");
|
||||
return $type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
// dbg
|
||||
function debug($string)
|
||||
{
|
||||
//$this->debug("well, request passed parameters to a method that requires none?");
|
||||
//$this->make_fault("Client","method '$this->methodname' requires no parameters. The request passed in ".count($params).": ".@implode(" param: ",$params) );
|
||||
return true;
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$this->debug_str .= "$string\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get string return type from dispatch map
|
||||
function get_return_type()
|
||||
{
|
||||
if(count($this->dispatch_map[$this->methodname]["out"]) >= 1)
|
||||
// add a method to the dispatch map
|
||||
function add_to_map($methodname,$in,$out)
|
||||
{
|
||||
$type = array_shift($this->dispatch_map[$this->methodname]["out"]);
|
||||
$this->debug("got return type from dispatch map: '$type'");
|
||||
return $type;
|
||||
$this->dispatch_map[$methodname]['in'] = $in;
|
||||
$this->dispatch_map[$methodname]['out'] = $out;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// dbg
|
||||
function debug($string)
|
||||
{
|
||||
if($this->debug_flag)
|
||||
// set up a fault
|
||||
function fault()
|
||||
{
|
||||
$this->debug_str .= "$string\n";
|
||||
return CreateObject('phpgwapi.soapmsg',
|
||||
'Fault',
|
||||
array(
|
||||
'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/'
|
||||
);
|
||||
}
|
||||
|
||||
function make_fault($fault_code,$fault_string)
|
||||
{
|
||||
$this->fault_code = $fault_code;
|
||||
$this->fault_str = $fault_string;
|
||||
$this->fault = true;
|
||||
}
|
||||
}
|
||||
|
||||
// add a method to the dispatch map
|
||||
function add_to_map($methodname,$in,$out)
|
||||
{
|
||||
$this->dispatch_map[$methodname]["in"] = $in;
|
||||
$this->dispatch_map[$methodname]["out"] = $out;
|
||||
}
|
||||
|
||||
// set up a fault
|
||||
function fault()
|
||||
{
|
||||
return CreateObject('phpgwapi.soapmsg',
|
||||
"Fault",
|
||||
array(
|
||||
"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/"
|
||||
);
|
||||
}
|
||||
|
||||
function make_fault($fault_code,$fault_string)
|
||||
{
|
||||
$this->fault_code = $fault_code;
|
||||
$this->fault_str = $fault_string;
|
||||
$this->fault = true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -1,153 +1,153 @@
|
||||
<?php
|
||||
|
||||
/* soapx4 high level class
|
||||
|
||||
usage:
|
||||
usage:
|
||||
|
||||
// instantiate client with server info
|
||||
$soapclient = new soapclient( string path [ ,boolean wsdl] );
|
||||
// instantiate client with server info
|
||||
$soapclient = new soapclient( string path [ ,boolean wsdl] );
|
||||
|
||||
// call method, get results
|
||||
echo $soapclient->call( string methodname [ ,array parameters] );
|
||||
// call method, get results
|
||||
echo $soapclient->call( string methodname [ ,array parameters] );
|
||||
|
||||
// bye bye client
|
||||
unset($soapclient);
|
||||
// bye bye client
|
||||
unset($soapclient);
|
||||
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
class soapclient
|
||||
{
|
||||
function soapclient($endpoint,$wsdl=False,$portName=False)
|
||||
class soapclient
|
||||
{
|
||||
$this->debug_flag = True;
|
||||
$this->endpoint = $endpoint;
|
||||
$this->portName = False;
|
||||
|
||||
// make values
|
||||
if($wsdl)
|
||||
function soapclient($endpoint,$wsdl=False,$portName=False)
|
||||
{
|
||||
$this->endpointType = 'wsdl';
|
||||
if($portName)
|
||||
{
|
||||
$this->portName = $portName;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->debug_flag = True;
|
||||
$this->endpoint = $endpoint;
|
||||
$this->portName = False;
|
||||
|
||||
function call($method,$params='',$namespace=false,$soapAction=false)
|
||||
{
|
||||
if($this->endpointType == 'wsdl')
|
||||
{
|
||||
// instantiate wsdl class
|
||||
$this->wsdl = CreateObject('phpgwapi.wsdl',$this->endpoint);
|
||||
// get portName
|
||||
if(!$this->portName)
|
||||
// make values
|
||||
if($wsdl)
|
||||
{
|
||||
$this->portName = $this->wsdl->getPortName($method);
|
||||
}
|
||||
// get endpoint
|
||||
if(!$this->endpoint = $this->wsdl->getEndpoint($this->portName))
|
||||
{
|
||||
die("no port of name '$this->portName' in the wsdl at that location!");
|
||||
}
|
||||
$this->debug("endpoint: $this->endpoint");
|
||||
$this->debug("portName: $this->portName");
|
||||
}
|
||||
// get soapAction
|
||||
if(!$soapAction)
|
||||
{
|
||||
if($this->endpointType != "wsdl")
|
||||
{
|
||||
die("method call requires soapAction if wsdl is not available!");
|
||||
}
|
||||
if(!$soapAction = $this->wsdl->getSoapAction($this->portName,$method))
|
||||
{
|
||||
die("no soapAction for operation: $method!");
|
||||
}
|
||||
}
|
||||
$this->debug("soapAction: $soapAction");
|
||||
// get namespace
|
||||
if(!$namespace)
|
||||
{
|
||||
if($this->endpointType != "wsdl")
|
||||
{
|
||||
die("method call requires namespace if wsdl is not available!");
|
||||
}
|
||||
if(!$namespace = $this->wsdl->getNamespace($this->portName,$method))
|
||||
{
|
||||
die("no soapAction for operation: $method!");
|
||||
}
|
||||
}
|
||||
$this->debug("namespace: $namespace");
|
||||
|
||||
// make message
|
||||
$soapmsg = CreateObject('phpgwapi.soapmsg',$method,$params,$namespace);
|
||||
/* _debug_array($soapmsg); */
|
||||
|
||||
// instantiate client
|
||||
$dbg = "calling server at '$this->endpoint'...";
|
||||
if($soap_client = CreateObject('phpgwapi.soap_client',$this->endpoint))
|
||||
{
|
||||
//$soap_client->debug_flag = true;
|
||||
$this->debug($dbg."instantiated client successfully");
|
||||
$this->debug("client data:<br>server: $soap_client->server<br>path: $soap_client->path<br>port: $soap_client->port");
|
||||
// send
|
||||
$dbg = "sending msg w/ soapaction '$soapAction'...";
|
||||
if($return = $soap_client->send($soapmsg,$soapAction))
|
||||
{
|
||||
$this->request = $soap_client->outgoing_payload;
|
||||
$this->response = $soap_client->incoming_payload;
|
||||
$this->debug($dbg."sent message successfully and got a '$return' back");
|
||||
// check for valid response
|
||||
if(get_class($return) == "soapval")
|
||||
$this->endpointType = 'wsdl';
|
||||
if($portName)
|
||||
{
|
||||
// fault?
|
||||
if(eregi("fault",$return->name))
|
||||
$this->portName = $portName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function call($method,$params='',$namespace=false,$soapAction=false)
|
||||
{
|
||||
if($this->endpointType == 'wsdl')
|
||||
{
|
||||
// instantiate wsdl class
|
||||
$this->wsdl = CreateObject('phpgwapi.wsdl',$this->endpoint);
|
||||
// get portName
|
||||
if(!$this->portName)
|
||||
{
|
||||
$this->portName = $this->wsdl->getPortName($method);
|
||||
}
|
||||
// get endpoint
|
||||
if(!$this->endpoint = $this->wsdl->getEndpoint($this->portName))
|
||||
{
|
||||
die("no port of name '$this->portName' in the wsdl at that location!");
|
||||
}
|
||||
$this->debug("endpoint: $this->endpoint");
|
||||
$this->debug("portName: $this->portName");
|
||||
}
|
||||
// get soapAction
|
||||
if(!$soapAction)
|
||||
{
|
||||
if($this->endpointType != 'wsdl')
|
||||
{
|
||||
die("method call requires soapAction if wsdl is not available!");
|
||||
}
|
||||
if(!$soapAction = $this->wsdl->getSoapAction($this->portName,$method))
|
||||
{
|
||||
die("no soapAction for operation: $method!");
|
||||
}
|
||||
}
|
||||
$this->debug("soapAction: $soapAction");
|
||||
// get namespace
|
||||
if(!$namespace)
|
||||
{
|
||||
if($this->endpointType != 'wsdl')
|
||||
{
|
||||
die("method call requires namespace if wsdl is not available!");
|
||||
}
|
||||
if(!$namespace = $this->wsdl->getNamespace($this->portName,$method))
|
||||
{
|
||||
die("no soapAction for operation: $method!");
|
||||
}
|
||||
}
|
||||
$this->debug("namespace: $namespace");
|
||||
|
||||
// make message
|
||||
$soapmsg = CreateObject('phpgwapi.soapmsg',$method,$params,$namespace);
|
||||
/* _debug_array($soapmsg); */
|
||||
|
||||
// instantiate client
|
||||
$dbg = "calling server at '$this->endpoint'...";
|
||||
if($soap_client = CreateObject('phpgwapi.soap_client',$this->endpoint))
|
||||
{
|
||||
//$soap_client->debug_flag = true;
|
||||
$this->debug($dbg.'instantiated client successfully');
|
||||
$this->debug("client data:<br>server: $soap_client->server<br>path: $soap_client->path<br>port: $soap_client->port");
|
||||
// send
|
||||
$dbg = "sending msg w/ soapaction '$soapAction'...";
|
||||
if($return = $soap_client->send($soapmsg,$soapAction))
|
||||
{
|
||||
$this->request = $soap_client->outgoing_payload;
|
||||
$this->response = $soap_client->incoming_payload;
|
||||
$this->debug($dbg . "sent message successfully and got a '$return' back");
|
||||
// check for valid response
|
||||
if(get_class($return) == 'soapval')
|
||||
{
|
||||
$this->debug("got fault");
|
||||
$faultArray = $return->decode();
|
||||
@reset($faultArray);
|
||||
while(list($k,$v) = @each($faultArray))
|
||||
/* foreach($faultArray as $k => $v) */
|
||||
// fault?
|
||||
if(eregi('fault',$return->name))
|
||||
{
|
||||
print "$k = $v<br>";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$returnArray = $return->decode();
|
||||
if(is_array($returnArray))
|
||||
{
|
||||
return array_shift($returnArray);
|
||||
$this->debug('got fault');
|
||||
$faultArray = $return->decode();
|
||||
@reset($faultArray);
|
||||
while(list($k,$v) = @each($faultArray))
|
||||
/* foreach($faultArray as $k => $v) */
|
||||
{
|
||||
print "$k = $v<br>";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("didn't get array back from decode() for $return->name");
|
||||
return false;
|
||||
$returnArray = $return->decode();
|
||||
if(is_array($returnArray))
|
||||
{
|
||||
return array_shift($returnArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("didn't get array back from decode() for $return->name");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("didn't get soapval object back from client");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->debug("didn't get soapval object back from client");
|
||||
$this->debug('client send/recieve error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
function debug($string)
|
||||
{
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$this->debug("client send/recieve error");
|
||||
return false;
|
||||
print $string . '<br>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function debug($string)
|
||||
{
|
||||
if($this->debug_flag)
|
||||
{
|
||||
print $string."<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -1,149 +1,151 @@
|
||||
<?php
|
||||
// soap message class
|
||||
class soapmsg
|
||||
{
|
||||
// params is an array of soapval objects
|
||||
function soapmsg($method,$params,$method_namespace='http://testuri.org',$new_namespaces=False)
|
||||
/* $Id$ */
|
||||
|
||||
// soap message class
|
||||
class soapmsg
|
||||
{
|
||||
// globalize method namespace
|
||||
global $methodNamespace;
|
||||
$methodNamespace = $method_namespace;
|
||||
// make method struct
|
||||
$this->value = CreateObject('phpgwapi.soapval',$method,"struct",$params,$method_namespace);
|
||||
if(is_array($new_namespaces))
|
||||
// params is an array of soapval objects
|
||||
function soapmsg($method,$params,$method_namespace='http://testuri.org',$new_namespaces=False)
|
||||
{
|
||||
// globalize method namespace
|
||||
global $methodNamespace;
|
||||
$methodNamespace = $method_namespace;
|
||||
// make method struct
|
||||
$this->value = CreateObject('phpgwapi.soapval',$method,"struct",$params,$method_namespace);
|
||||
if(is_array($new_namespaces))
|
||||
{
|
||||
global $namespaces;
|
||||
$i = count($namespaces);
|
||||
@reset($new_namespaces);
|
||||
while(list($null,$v) = @each($new_namespaces))
|
||||
/* foreach($new_namespaces as $v) */
|
||||
{
|
||||
$namespaces[$v] = 'ns' . $i++;
|
||||
}
|
||||
$this->namespaces = $namespaces;
|
||||
}
|
||||
$this->payload = '';
|
||||
$this->debug_flag = True;
|
||||
$this->debug_str = "entering soapmsg() with soapval ".$this->value->name."\n";
|
||||
}
|
||||
|
||||
function make_envelope($payload)
|
||||
{
|
||||
global $namespaces;
|
||||
$i = count($namespaces);
|
||||
@reset($new_namespaces);
|
||||
while(list($null,$v) = @each($new_namespaces))
|
||||
/* foreach($new_namespaces as $v) */
|
||||
@reset($namespaces);
|
||||
while(list($k,$v) = @each($namespaces))
|
||||
/* foreach($namespaces as $k => $v) */
|
||||
{
|
||||
$namespaces[$v] = "ns".$i++;
|
||||
$ns_string .= " xmlns:$v=\"$k\"";
|
||||
}
|
||||
$this->namespaces = $namespaces;
|
||||
return "<SOAP-ENV:Envelope $ns_string SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
|
||||
. $payload . "</SOAP-ENV:Envelope>\n";
|
||||
}
|
||||
$this->payload = '';
|
||||
$this->debug_flag = True;
|
||||
$this->debug_str = "entering soapmsg() with soapval ".$this->value->name."\n";
|
||||
}
|
||||
|
||||
function make_envelope($payload)
|
||||
{
|
||||
global $namespaces;
|
||||
@reset($namespaces);
|
||||
while(list($k,$v) = @each($namespaces))
|
||||
/* foreach($namespaces as $k => $v) */
|
||||
function make_body($payload)
|
||||
{
|
||||
$ns_string .= " xmlns:$v=\"$k\"";
|
||||
return "<SOAP-ENV:Body>\n" . $payload . "</SOAP-ENV:Body>\n";
|
||||
}
|
||||
return "<SOAP-ENV:Envelope $ns_string SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
|
||||
. $payload . "</SOAP-ENV:Envelope>\n";
|
||||
}
|
||||
|
||||
function make_body($payload)
|
||||
{
|
||||
return "<SOAP-ENV:Body>\n" . $payload . "</SOAP-ENV:Body>\n";
|
||||
}
|
||||
|
||||
function createPayload()
|
||||
{
|
||||
$value = $this->value;
|
||||
$payload = $this->make_envelope($this->make_body($value->serialize()));
|
||||
$this->debug($value->debug_str);
|
||||
$payload = "<?xml version=\"1.0\"?>\n".$payload;
|
||||
if($this->debug_flag)
|
||||
function createPayload()
|
||||
{
|
||||
$payload .= $this->serializeDebug();
|
||||
$value = $this->value;
|
||||
$payload = $this->make_envelope($this->make_body($value->serialize()));
|
||||
$this->debug($value->debug_str);
|
||||
$payload = "<?xml version=\"1.0\"?>\n".$payload;
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$payload .= $this->serializeDebug();
|
||||
}
|
||||
$this->payload = str_replace("\n","\r\n", $payload);
|
||||
}
|
||||
$this->payload = str_replace("\n","\r\n", $payload);
|
||||
}
|
||||
|
||||
function serialize()
|
||||
{
|
||||
if($this->payload == '')
|
||||
function serialize()
|
||||
{
|
||||
$this->createPayload();
|
||||
return $this->payload;
|
||||
if($this->payload == '')
|
||||
{
|
||||
$this->createPayload();
|
||||
return $this->payload;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// returns a soapval object
|
||||
function parseResponse($data)
|
||||
{
|
||||
return $this->payload;
|
||||
$this->debug("Entering parseResponse()");
|
||||
//$this->debug(" w/ data $data");
|
||||
// strip headers here
|
||||
//$clean_data = ereg_replace("\r\n","\n", $data);
|
||||
if(ereg("^.*\r\n\r\n<",$data))
|
||||
{
|
||||
$this->debug("found proper seperation of headers and document");
|
||||
$this->debug("getting rid of headers, stringlen: ".strlen($data));
|
||||
$clean_data = ereg_replace("^.*\r\n\r\n<","<", $data);
|
||||
$this->debug("cleaned data, stringlen: ".strlen($clean_data));
|
||||
}
|
||||
else
|
||||
{
|
||||
// return fault
|
||||
return CreateObject('phpgwapi.soapval',
|
||||
'fault',
|
||||
'SOAPStruct',
|
||||
Array(
|
||||
CreateObject('phpgwapi.soapval','faultcode','string','SOAP-MSG'),
|
||||
CreateObject('phpgwapi.soapval','faultstring','string','HTTP Error'),
|
||||
CreateObject('phpgwapi.soapval','faultdetail','string','HTTP headers were not immediately followed by \'\r\n\r\n\'')
|
||||
)
|
||||
);
|
||||
}
|
||||
/*
|
||||
// if response is a proper http response, and is not a 200
|
||||
if(ereg("^HTTP",$clean_data) && !ereg("200$", $clean_data))
|
||||
{
|
||||
// get error data
|
||||
$errstr = substr($clean_data, 0, strpos($clean_data, "\n")-1);
|
||||
// return fault
|
||||
return CreateObject('phpgwapi.soapval',
|
||||
"fault",
|
||||
"SOAPStruct",
|
||||
array(
|
||||
CreateObject('phpgwapi.soapval',"faultcode","string","SOAP-MSG"),
|
||||
CreateObject('phpgwapi.soapval',"faultstring","string","HTTP error")
|
||||
)
|
||||
);
|
||||
}
|
||||
*/
|
||||
$this->debug("about to create parser instance w/ data: $clean_data");
|
||||
// parse response
|
||||
$response = CreateObject('phpgwapi.soap_parser',$clean_data);
|
||||
// return array of parameters
|
||||
$ret = $response->get_response();
|
||||
$this->debug($response->debug_str);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// dbg
|
||||
function debug($string)
|
||||
{
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$this->debug_str .= "$string\n";
|
||||
}
|
||||
}
|
||||
|
||||
// preps debug data for encoding into soapmsg
|
||||
function serializeDebug()
|
||||
{
|
||||
if($this->debug_flag)
|
||||
{
|
||||
return "<!-- DEBUG INFO:\n".$this->debug_str."-->\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// returns a soapval object
|
||||
function parseResponse($data)
|
||||
{
|
||||
$this->debug("Entering parseResponse()");
|
||||
//$this->debug(" w/ data $data");
|
||||
// strip headers here
|
||||
//$clean_data = ereg_replace("\r\n","\n", $data);
|
||||
if(ereg("^.*\r\n\r\n<",$data))
|
||||
{
|
||||
$this->debug("found proper seperation of headers and document");
|
||||
$this->debug("getting rid of headers, stringlen: ".strlen($data));
|
||||
$clean_data = ereg_replace("^.*\r\n\r\n<","<", $data);
|
||||
$this->debug("cleaned data, stringlen: ".strlen($clean_data));
|
||||
}
|
||||
else
|
||||
{
|
||||
// return fault
|
||||
return CreateObject('phpgwapi.soapval',
|
||||
'fault',
|
||||
'SOAPStruct',
|
||||
Array(
|
||||
CreateObject('phpgwapi.soapval','faultcode','string','SOAP-MSG'),
|
||||
CreateObject('phpgwapi.soapval','faultstring','string','HTTP Error'),
|
||||
CreateObject('phpgwapi.soapval','faultdetail','string','HTTP headers were not immediately followed by \'\r\n\r\n\'')
|
||||
)
|
||||
);
|
||||
}
|
||||
/*
|
||||
// if response is a proper http response, and is not a 200
|
||||
if(ereg("^HTTP",$clean_data) && !ereg("200$", $clean_data))
|
||||
{
|
||||
// get error data
|
||||
$errstr = substr($clean_data, 0, strpos($clean_data, "\n")-1);
|
||||
// return fault
|
||||
return CreateObject('phpgwapi.soapval',
|
||||
"fault",
|
||||
"SOAPStruct",
|
||||
array(
|
||||
CreateObject('phpgwapi.soapval',"faultcode","string","SOAP-MSG"),
|
||||
CreateObject('phpgwapi.soapval',"faultstring","string","HTTP error")
|
||||
)
|
||||
);
|
||||
}
|
||||
*/
|
||||
$this->debug("about to create parser instance w/ data: $clean_data");
|
||||
// parse response
|
||||
$response = CreateObject('phpgwapi.soap_parser',$clean_data);
|
||||
// return array of parameters
|
||||
$ret = $response->get_response();
|
||||
$this->debug($response->debug_str);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// dbg
|
||||
function debug($string)
|
||||
{
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$this->debug_str .= "$string\n";
|
||||
}
|
||||
}
|
||||
|
||||
// preps debug data for encoding into soapmsg
|
||||
function serializeDebug()
|
||||
{
|
||||
if($this->debug_flag)
|
||||
{
|
||||
return "<!-- DEBUG INFO:\n".$this->debug_str."-->\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -1,436 +1,438 @@
|
||||
<?php
|
||||
// soap value object
|
||||
class soapval
|
||||
{
|
||||
// function soapval($name='',$type=False,$value=-1,$namespace=False,$type_namespace=False)
|
||||
function soapval($name='',$type=False,$value=0,$namespace=False,$type_namespace=False)
|
||||
/* $Id$ */
|
||||
|
||||
// soap value object
|
||||
class soapval
|
||||
{
|
||||
global $soapTypes, $typemap, $namespaces, $methodNamespace;
|
||||
|
||||
// detect type if not passed
|
||||
if(!$type)
|
||||
// function soapval($name='',$type=False,$value=-1,$namespace=False,$type_namespace=False)
|
||||
function soapval($name='',$type=False,$value=0,$namespace=False,$type_namespace=False)
|
||||
{
|
||||
if(is_array($value) && count($value) >= 1)
|
||||
global $soapTypes, $typemap, $namespaces, $methodNamespace;
|
||||
|
||||
// detect type if not passed
|
||||
if(!$type)
|
||||
{
|
||||
if(ereg("[a-zA-Z0-9\-]*",key($v)))
|
||||
if(is_array($value) && count($value) >= 1)
|
||||
{
|
||||
$type = "struct";
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = "array";
|
||||
}
|
||||
}
|
||||
elseif(is_int($v))
|
||||
{
|
||||
$type = "int";
|
||||
}
|
||||
elseif(is_float($v) || $v == "NaN" || $v == "INF")
|
||||
{
|
||||
$type = "float";
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = gettype($value);
|
||||
}
|
||||
}
|
||||
// php type name mangle
|
||||
if($type == "integer")
|
||||
{
|
||||
$type = "int";
|
||||
}
|
||||
|
||||
$this->soapTypes = $soapTypes;
|
||||
$this->name = $name;
|
||||
$this->value = "";
|
||||
$this->type = $type;
|
||||
$this->type_code = 0;
|
||||
$this->type_prefix = false;
|
||||
$this->array_type = "";
|
||||
$this->debug_flag = True;
|
||||
$this->debug_str = "";
|
||||
$this->debug("Entering soapval - name: '$name' type: '$type'");
|
||||
|
||||
if($namespace)
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
if(!isset($namespaces[$namespace]))
|
||||
{
|
||||
$namespaces[$namespace] = "ns".(count($namespaces)+1);
|
||||
}
|
||||
$this->prefix = $namespaces[$namespace];
|
||||
}
|
||||
|
||||
// get type prefix
|
||||
if(ereg(":",$type))
|
||||
{
|
||||
$this->type = substr(strrchr($type,":"),1,strlen(strrchr($type,":")));
|
||||
$this->type_prefix = substr($type,0,strpos($type,":"));
|
||||
}
|
||||
elseif($type_namespace)
|
||||
{
|
||||
if(!isset($namespaces[$type_namespace]))
|
||||
{
|
||||
$namespaces[$type_namespace] = "ns".(count($namespaces)+1);
|
||||
}
|
||||
$this->type_prefix = $namespaces[$type_namespace];
|
||||
}
|
||||
|
||||
// if type namespace was not explicitly passed, and we're not in a method struct:
|
||||
elseif(!$this->type_prefix && !isset($this->namespace))
|
||||
{
|
||||
// try to get type prefix from typeMap
|
||||
if(!$this->type_prefix = $this->verify_type($type))
|
||||
{
|
||||
// else default to method namespace
|
||||
$this->type_prefix = $namespaces[$methodNamespace];
|
||||
}
|
||||
}
|
||||
|
||||
// if scalar
|
||||
if($this->soapTypes[$this->type] == 1)
|
||||
{
|
||||
$this->type_code = 1;
|
||||
$this->addScalar($value,$this->type,$name);
|
||||
// if array
|
||||
}
|
||||
elseif($this->soapTypes[$this->type] == 2)
|
||||
{
|
||||
$this->type_code = 2;
|
||||
$this->addArray($value);
|
||||
// if struct
|
||||
}
|
||||
elseif($this->soapTypes[$this->type] == 3)
|
||||
{
|
||||
$this->type_code = 3;
|
||||
$this->addStruct($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
//if($namespace == $methodNamespace){
|
||||
$this->type_code = 3;
|
||||
$this->addStruct($value);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
function addScalar($value, $type, $name="")
|
||||
{
|
||||
$this->debug("adding scalar '$name' of type '$type'");
|
||||
|
||||
// if boolean, change value to 1 or 0
|
||||
if ($type == "boolean")
|
||||
{
|
||||
if((strcasecmp($value,"true") == 0) || ($value == 1))
|
||||
{
|
||||
$value = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
function addArray($vals)
|
||||
{
|
||||
$this->debug("adding array '$this->name' with ".count($vals)." vals");
|
||||
$this->value = array();
|
||||
if(is_array($vals) && count($vals) >= 1)
|
||||
{
|
||||
@reset($vals);
|
||||
while(list($k,$v) = @each($vals))
|
||||
/* foreach($vals as $k => $v) */
|
||||
{
|
||||
$this->debug("checking value $k : $v");
|
||||
// if soapval, add..
|
||||
if(get_class($v) == "soapval")
|
||||
{
|
||||
$this->value[] = $v;
|
||||
$this->debug($v->debug_str);
|
||||
// else make obj and serialize
|
||||
}
|
||||
else
|
||||
{
|
||||
if(is_array($v))
|
||||
if(ereg("[a-zA-Z0-9\-]*",key($v)))
|
||||
{
|
||||
if(ereg("[a-zA-Z\-]*",key($v)))
|
||||
{
|
||||
$type = "struct";
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = "array";
|
||||
}
|
||||
}
|
||||
elseif(!ereg("^[0-9]*$",$k) && in_array($k,array_keys($this->soapTypes)))
|
||||
{
|
||||
$type = $k;
|
||||
}
|
||||
elseif(is_int($v))
|
||||
{
|
||||
$type = "int";
|
||||
}
|
||||
elseif(is_float($v) || $v == "NaN" || $v == "INF")
|
||||
{
|
||||
$type = "float";
|
||||
$type = 'struct';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = gettype($v);
|
||||
$type = 'array';
|
||||
}
|
||||
$new_val = CreateObject('phpgwapi.soapval',"item",$type,$v);
|
||||
$this->debug($new_val->debug_str);
|
||||
$this->value[] = $new_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function addStruct($vals)
|
||||
{
|
||||
$this->debug("adding struct '$this->name' with ".count($vals)." vals");
|
||||
if(is_array($vals) && count($vals) >= 1)
|
||||
{
|
||||
@reset($vals);
|
||||
while(list($k,$v) = @each($vals))
|
||||
/* foreach($vals as $k => $v) */
|
||||
{
|
||||
// if serialize, if soapval
|
||||
if(get_class($v) == "soapval")
|
||||
elseif(is_int($v))
|
||||
{
|
||||
$this->value[] = $v;
|
||||
$this->debug($v->debug_str);
|
||||
// else make obj and serialize
|
||||
$type = 'int';
|
||||
}
|
||||
elseif(is_float($v) || $v == 'NaN' || $v == 'INF')
|
||||
{
|
||||
$type = 'float';
|
||||
}
|
||||
else
|
||||
{
|
||||
if(is_array($v))
|
||||
$type = gettype($value);
|
||||
}
|
||||
}
|
||||
// php type name mangle
|
||||
if($type == 'integer')
|
||||
{
|
||||
$type = 'int';
|
||||
}
|
||||
|
||||
$this->soapTypes = $soapTypes;
|
||||
$this->name = $name;
|
||||
$this->value = '';
|
||||
$this->type = $type;
|
||||
$this->type_code = 0;
|
||||
$this->type_prefix = false;
|
||||
$this->array_type = '';
|
||||
$this->debug_flag = True;
|
||||
$this->debug_str = '';
|
||||
$this->debug("Entering soapval - name: '$name' type: '$type'");
|
||||
|
||||
if($namespace)
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
if(!isset($namespaces[$namespace]))
|
||||
{
|
||||
$namespaces[$namespace] = "ns".(count($namespaces)+1);
|
||||
}
|
||||
$this->prefix = $namespaces[$namespace];
|
||||
}
|
||||
|
||||
// get type prefix
|
||||
if(ereg(":",$type))
|
||||
{
|
||||
$this->type = substr(strrchr($type,':'),1,strlen(strrchr($type,':')));
|
||||
$this->type_prefix = substr($type,0,strpos($type,':'));
|
||||
}
|
||||
elseif($type_namespace)
|
||||
{
|
||||
if(!isset($namespaces[$type_namespace]))
|
||||
{
|
||||
$namespaces[$type_namespace] = 'ns'.(count($namespaces)+1);
|
||||
}
|
||||
$this->type_prefix = $namespaces[$type_namespace];
|
||||
}
|
||||
|
||||
// if type namespace was not explicitly passed, and we're not in a method struct:
|
||||
elseif(!$this->type_prefix && !isset($this->namespace))
|
||||
{
|
||||
// try to get type prefix from typeMap
|
||||
if(!$this->type_prefix = $this->verify_type($type))
|
||||
{
|
||||
// else default to method namespace
|
||||
$this->type_prefix = $namespaces[$methodNamespace];
|
||||
}
|
||||
}
|
||||
|
||||
// if scalar
|
||||
if($this->soapTypes[$this->type] == 1)
|
||||
{
|
||||
$this->type_code = 1;
|
||||
$this->addScalar($value,$this->type,$name);
|
||||
// if array
|
||||
}
|
||||
elseif($this->soapTypes[$this->type] == 2)
|
||||
{
|
||||
$this->type_code = 2;
|
||||
$this->addArray($value);
|
||||
// if struct
|
||||
}
|
||||
elseif($this->soapTypes[$this->type] == 3)
|
||||
{
|
||||
$this->type_code = 3;
|
||||
$this->addStruct($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
//if($namespace == $methodNamespace){
|
||||
$this->type_code = 3;
|
||||
$this->addStruct($value);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
function addScalar($value, $type, $name="")
|
||||
{
|
||||
$this->debug("adding scalar '$name' of type '$type'");
|
||||
|
||||
// if boolean, change value to 1 or 0
|
||||
if ($type == "boolean")
|
||||
{
|
||||
if((strcasecmp($value,"true") == 0) || ($value == 1))
|
||||
{
|
||||
$value = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
function addArray($vals)
|
||||
{
|
||||
$this->debug("adding array '$this->name' with ".count($vals)." vals");
|
||||
$this->value = array();
|
||||
if(is_array($vals) && count($vals) >= 1)
|
||||
{
|
||||
@reset($vals);
|
||||
while(list($k,$v) = @each($vals))
|
||||
/* foreach($vals as $k => $v) */
|
||||
{
|
||||
$this->debug("checking value $k : $v");
|
||||
// if soapval, add..
|
||||
if(get_class($v) == 'soapval')
|
||||
{
|
||||
@reset($v);
|
||||
while(list($a,$b) = @each($v))
|
||||
/* foreach($v as $a => $b) */
|
||||
$this->value[] = $v;
|
||||
$this->debug($v->debug_str);
|
||||
// else make obj and serialize
|
||||
}
|
||||
else
|
||||
{
|
||||
if(is_array($v))
|
||||
{
|
||||
if($a == "0")
|
||||
if(ereg("[a-zA-Z\-]*",key($v)))
|
||||
{
|
||||
$type = "array";
|
||||
$type = 'struct';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = "struct";
|
||||
$type = 'array';
|
||||
}
|
||||
break;
|
||||
}
|
||||
elseif(!ereg("^[0-9]*$",$k) && in_array($k,array_keys($this->soapTypes)))
|
||||
{
|
||||
$type = $k;
|
||||
}
|
||||
elseif(is_int($v))
|
||||
{
|
||||
$type = 'int';
|
||||
}
|
||||
elseif(is_float($v) || $v == 'NaN' || $v == 'INF')
|
||||
{
|
||||
$type = 'float';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = gettype($v);
|
||||
}
|
||||
$new_val = CreateObject('phpgwapi.soapval','item',$type,$v);
|
||||
$this->debug($new_val->debug_str);
|
||||
$this->value[] = $new_val;
|
||||
}
|
||||
// elseif(is_array($k) && in_array($k,array_keys($this->soapTypes)))
|
||||
elseif(is_array($k,in_array($k,array_keys($this->soapTypes))))
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function addStruct($vals)
|
||||
{
|
||||
$this->debug("adding struct '$this->name' with ".count($vals).' vals');
|
||||
if(is_array($vals) && count($vals) >= 1)
|
||||
{
|
||||
@reset($vals);
|
||||
while(list($k,$v) = @each($vals))
|
||||
/* foreach($vals as $k => $v) */
|
||||
{
|
||||
// if serialize, if soapval
|
||||
if(get_class($v) == 'soapval')
|
||||
{
|
||||
$this->debug("got type '$type' for value '$v' from soapTypes array!");
|
||||
$type = $k;
|
||||
}
|
||||
elseif(is_int($v))
|
||||
{
|
||||
$type = "int";
|
||||
}
|
||||
elseif(is_float($v) || $v == "NaN" || $v == "INF")
|
||||
{
|
||||
$type = "float";
|
||||
$this->value[] = $v;
|
||||
$this->debug($v->debug_str);
|
||||
// else make obj and serialize
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = gettype($v);
|
||||
$this->debug("got type '$type' for value '$v' from php gettype()!");
|
||||
if(is_array($v))
|
||||
{
|
||||
@reset($v);
|
||||
while(list($a,$b) = @each($v))
|
||||
/* foreach($v as $a => $b) */
|
||||
{
|
||||
if($a == "0")
|
||||
{
|
||||
$type = 'array';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = 'struct';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// elseif(is_array($k) && in_array($k,array_keys($this->soapTypes)))
|
||||
elseif(is_array($k,in_array($k,array_keys($this->soapTypes))))
|
||||
{
|
||||
$this->debug("got type '$type' for value '$v' from soapTypes array!");
|
||||
$type = $k;
|
||||
}
|
||||
elseif(is_int($v))
|
||||
{
|
||||
$type = 'int';
|
||||
}
|
||||
elseif(is_float($v) || $v == "NaN" || $v == "INF")
|
||||
{
|
||||
$type = 'float';
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = gettype($v);
|
||||
$this->debug("got type '$type' for value '$v' from php gettype()!");
|
||||
}
|
||||
$new_val = CreateObject('phpgwapi.soapval',$k,$type,$v);
|
||||
$this->debug($new_val->debug_str);
|
||||
$this->value[] = $new_val;
|
||||
}
|
||||
$new_val = CreateObject('phpgwapi.soapval',$k,$type,$v);
|
||||
$this->debug($new_val->debug_str);
|
||||
$this->value[] = $new_val;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = array();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->value = array();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// turn soapvals into xml, woohoo!
|
||||
function serializeval($soapval=false)
|
||||
{
|
||||
if(!$soapval)
|
||||
// turn soapvals into xml, woohoo!
|
||||
function serializeval($soapval=false)
|
||||
{
|
||||
$soapval = $this;
|
||||
if(!$soapval)
|
||||
{
|
||||
$soapval = $this;
|
||||
}
|
||||
$this->debug("serializing '$soapval->name' of type '$soapval->type'");
|
||||
if($soapval->name == '')
|
||||
{
|
||||
$soapval->name = 'return';
|
||||
}
|
||||
|
||||
switch($soapval->type_code)
|
||||
{
|
||||
case 3:
|
||||
// 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)
|
||||
{
|
||||
$xml .= "<$soapval->name xsi:type=\"$soapval->type_prefix:$soapval->type\">\n";
|
||||
}
|
||||
elseif($soapval->prefix)
|
||||
{
|
||||
$xml .= "<$soapval->prefix:$soapval->name>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml .= "<$soapval->name>\n";
|
||||
}
|
||||
if(is_array($soapval->value))
|
||||
{
|
||||
@reset($soapval->value);
|
||||
while(list($k,$v) = @each($soapval->value))
|
||||
/* foreach($soapval->value as $k => $v) */
|
||||
{
|
||||
$xml .= $this->serializeval($v);
|
||||
}
|
||||
}
|
||||
if($soapval->prefix)
|
||||
{
|
||||
$xml .= "</$soapval->prefix:$soapval->name>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml .= "</$soapval->name>\n";
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// array
|
||||
@reset($soapval->value);
|
||||
while(list($null,$array_val) = @each($soapval->value))
|
||||
/* foreach($soapval->value as $array_val) */
|
||||
{
|
||||
$array_types[$array_val->type] = 1;
|
||||
$xml .= $this->serializeval($array_val);
|
||||
}
|
||||
if(count($array_types) > 1)
|
||||
{
|
||||
$array_type = 'xsd:ur-type';
|
||||
}
|
||||
elseif(count($array_types) >= 1)
|
||||
{
|
||||
$array_type = $array_val->type_prefix.":".$array_val->type;
|
||||
}
|
||||
|
||||
$xml = "<$soapval->name xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_type."[".sizeof($soapval->value)."]\">\n".$xml."</$soapval->name>\n";
|
||||
break;
|
||||
case 1:
|
||||
$xml .= "<$soapval->name xsi:type=\"$soapval->type_prefix:$soapval->type\">$soapval->value</$soapval->name>\n";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $xml;
|
||||
}
|
||||
$this->debug("serializing '$soapval->name' of type '$soapval->type'");
|
||||
if($soapval->name == "")
|
||||
|
||||
// serialize
|
||||
function serialize()
|
||||
{
|
||||
$soapval->name = "return";
|
||||
return $this->serializeval($this);
|
||||
}
|
||||
|
||||
switch($soapval->type_code)
|
||||
|
||||
function decode($soapval=false)
|
||||
{
|
||||
case 3:
|
||||
// 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)
|
||||
{
|
||||
$xml .= "<$soapval->name xsi:type=\"$soapval->type_prefix:$soapval->type\">\n";
|
||||
}
|
||||
elseif($soapval->prefix)
|
||||
{
|
||||
$xml .= "<$soapval->prefix:$soapval->name>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml .= "<$soapval->name>\n";
|
||||
}
|
||||
if(!$soapval)
|
||||
{
|
||||
$soapval = $this;
|
||||
}
|
||||
// scalar decode
|
||||
if($soapval->type_code == 1)
|
||||
{
|
||||
return $soapval->value;
|
||||
// array decode
|
||||
}
|
||||
elseif($soapval->type_code == 2)
|
||||
{
|
||||
if(is_array($soapval->value))
|
||||
{
|
||||
@reset($soapval->value);
|
||||
while(list($k,$v) = @each($soapval->value))
|
||||
/* foreach($soapval->value as $k => $v) */
|
||||
while(list($null,$item) = @each($soapval->value))
|
||||
/* foreach($soapval->value as $item) */
|
||||
{
|
||||
$xml .= $this->serializeval($v);
|
||||
$return[] = $this->decode($item);
|
||||
}
|
||||
}
|
||||
if($soapval->prefix)
|
||||
{
|
||||
$xml .= "</$soapval->prefix:$soapval->name>\n";
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml .= "</$soapval->name>\n";
|
||||
return array();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// array
|
||||
@reset($soapval->value);
|
||||
while(list($null,$array_val) = @each($soapval->value))
|
||||
/* foreach($soapval->value as $array_val) */
|
||||
{
|
||||
$array_types[$array_val->type] = 1;
|
||||
$xml .= $this->serializeval($array_val);
|
||||
}
|
||||
if(count($array_types) > 1)
|
||||
{
|
||||
$array_type = "xsd:ur-type";
|
||||
}
|
||||
elseif(count($array_types) >= 1)
|
||||
{
|
||||
$array_type = $array_val->type_prefix.":".$array_val->type;
|
||||
}
|
||||
|
||||
$xml = "<$soapval->name xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_type."[".sizeof($soapval->value)."]\">\n".$xml."</$soapval->name>\n";
|
||||
break;
|
||||
case 1:
|
||||
$xml .= "<$soapval->name xsi:type=\"$soapval->type_prefix:$soapval->type\">$soapval->value</$soapval->name>\n";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $xml;
|
||||
}
|
||||
|
||||
// serialize
|
||||
function serialize()
|
||||
{
|
||||
return $this->serializeval($this);
|
||||
}
|
||||
|
||||
function decode($soapval=false)
|
||||
{
|
||||
if(!$soapval)
|
||||
{
|
||||
$soapval = $this;
|
||||
}
|
||||
// scalar decode
|
||||
if($soapval->type_code == 1)
|
||||
{
|
||||
return $soapval->value;
|
||||
// array decode
|
||||
}
|
||||
elseif($soapval->type_code == 2)
|
||||
{
|
||||
if(is_array($soapval->value))
|
||||
{
|
||||
@reset($soapval->value);
|
||||
while(list($null,$item) = @each($soapval->value))
|
||||
/* foreach($soapval->value as $item) */
|
||||
{
|
||||
$return[] = $this->decode($item);
|
||||
}
|
||||
return $return;
|
||||
// struct decode
|
||||
}
|
||||
else
|
||||
elseif($soapval->type_code == 3)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
// struct decode
|
||||
}
|
||||
elseif($soapval->type_code == 3)
|
||||
{
|
||||
if(is_array($soapval->value))
|
||||
{
|
||||
@reset($soapval->value);
|
||||
while(list($null,$item) = @each($soapval->value))
|
||||
/* foreach($soapval->value as $item) */
|
||||
if(is_array($soapval->value))
|
||||
{
|
||||
$return[$item->name] = $this->decode($item);
|
||||
@reset($soapval->value);
|
||||
while(list($null,$item) = @each($soapval->value))
|
||||
/* foreach($soapval->value as $item) */
|
||||
{
|
||||
$return[$item->name] = $this->decode($item);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// verify type
|
||||
function verify_type($type)
|
||||
{
|
||||
if ($type)
|
||||
{
|
||||
// global $namespaces,$soapTypes,$typemap;
|
||||
global $namespaces,$typemap;
|
||||
|
||||
@reset($typemap);
|
||||
while(list($namespace,$types) = @each($typemap))
|
||||
/* foreach($typemap as $namespace => $types) */
|
||||
{
|
||||
if(in_array($type,$types))
|
||||
else
|
||||
{
|
||||
return $namespaces[$namespace];
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// alias for verify_type() - pass it a type, and it returns it's prefix
|
||||
function get_prefix($type)
|
||||
{
|
||||
if($prefix = $this->verify_type($type))
|
||||
// verify type
|
||||
function verify_type($type)
|
||||
{
|
||||
return $prefix;
|
||||
if ($type)
|
||||
{
|
||||
// global $namespaces,$soapTypes,$typemap;
|
||||
global $namespaces,$typemap;
|
||||
|
||||
@reset($typemap);
|
||||
while(list($namespace,$types) = @each($typemap))
|
||||
/* foreach($typemap as $namespace => $types) */
|
||||
{
|
||||
if(in_array($type,$types))
|
||||
{
|
||||
return $namespaces[$namespace];
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function debug($string)
|
||||
{
|
||||
if($this->debug_flag)
|
||||
|
||||
// alias for verify_type() - pass it a type, and it returns it's prefix
|
||||
function get_prefix($type)
|
||||
{
|
||||
$this->debug_str .= "$string\n";
|
||||
if($prefix = $this->verify_type($type))
|
||||
{
|
||||
return $prefix;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function debug($string)
|
||||
{
|
||||
if($this->debug_flag)
|
||||
{
|
||||
$this->debug_str .= "$string\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user