2001-07-16 08:05:33 +02:00
|
|
|
<?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)
|
|
|
|
{
|
|
|
|
// 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);
|
2001-08-02 10:59:08 +02:00
|
|
|
@reset($new_namespaces);
|
|
|
|
while(list($null,$v) = @each($new_namespaces))
|
|
|
|
/* foreach($new_namespaces as $v) */
|
2001-07-16 08:05:33 +02:00
|
|
|
{
|
|
|
|
$namespaces[$v] = "ns".$i++;
|
|
|
|
}
|
|
|
|
$this->namespaces = $namespaces;
|
|
|
|
}
|
|
|
|
$this->payload = '';
|
2001-07-28 22:24:32 +02:00
|
|
|
$this->debug_flag = True;
|
2001-07-16 08:05:33 +02:00
|
|
|
$this->debug_str = "entering soapmsg() with soapval ".$this->value->name."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function make_envelope($payload)
|
|
|
|
{
|
|
|
|
global $namespaces;
|
2001-08-02 10:59:08 +02:00
|
|
|
@reset($namespaces);
|
|
|
|
while(list($k,$v) = @each($namespaces))
|
|
|
|
/* foreach($namespaces as $k => $v) */
|
2001-07-16 08:05:33 +02:00
|
|
|
{
|
|
|
|
$ns_string .= " xmlns:$v=\"$k\"";
|
|
|
|
}
|
2001-07-30 05:40:08 +02:00
|
|
|
return "<SOAP-ENV:Envelope $ns_string SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
|
2001-07-16 08:05:33 +02:00
|
|
|
. $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)
|
|
|
|
{
|
|
|
|
$payload .= $this->serializeDebug();
|
|
|
|
}
|
|
|
|
$this->payload = str_replace("\n","\r\n", $payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
function serialize()
|
|
|
|
{
|
|
|
|
if($this->payload == '')
|
|
|
|
{
|
|
|
|
$this->createPayload();
|
|
|
|
return $this->payload;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this->payload;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns a soapval object
|
|
|
|
function parseResponse($data)
|
|
|
|
{
|
|
|
|
$this->debug("Entering parseResponse()");
|
|
|
|
//$this->debug(" w/ data $data");
|
2001-07-30 05:40:08 +02:00
|
|
|
// strip headers here
|
|
|
|
//$clean_data = ereg_replace("\r\n","\n", $data);
|
|
|
|
if(ereg("^.*\r\n\r\n<",$data))
|
2001-07-16 08:05:33 +02:00
|
|
|
{
|
2001-07-30 05:40:08 +02:00
|
|
|
$this->debug("found proper seperation of headers and document");
|
2001-07-16 08:05:33 +02:00
|
|
|
$this->debug("getting rid of headers, stringlen: ".strlen($data));
|
2001-07-30 05:40:08 +02:00
|
|
|
$clean_data = ereg_replace("^.*\r\n\r\n<","<", $data);
|
2001-07-16 08:05:33 +02:00
|
|
|
$this->debug("cleaned data, stringlen: ".strlen($clean_data));
|
|
|
|
}
|
2001-07-30 05:40:08 +02:00
|
|
|
else
|
2001-07-16 08:05:33 +02:00
|
|
|
{
|
2001-07-30 05:40:08 +02:00
|
|
|
// 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\'')
|
|
|
|
)
|
|
|
|
);
|
2001-07-16 08:05:33 +02:00
|
|
|
}
|
2001-07-30 05:40:08 +02:00
|
|
|
/*
|
2001-07-16 08:05:33 +02:00
|
|
|
// 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")
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2001-07-30 05:40:08 +02:00
|
|
|
*/
|
2001-07-16 08:05:33 +02:00
|
|
|
$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 '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|