egroupware_official/phpgwapi/inc/class.soapmsg.inc.php

184 lines
5.0 KiB
PHP
Raw Normal View History

2001-07-16 08:05:33 +02:00
<?php
2001-09-28 23:31:39 +02:00
/*
SOAPx4
by Dietrich Ayala (C) 2001 dietrich@ganx4.com
This project began based on code from the 2 projects below,
and still contains some original code. The licenses of both must be respected.
XML-RPC for PHP
originally by Edd Dumbill (C) 1999-2000
SOAP for PHP
by Victor Zou (C) 2000-2001 <victor@gigaideas.com.cn>
*/
/* changelog:
2001-07-04
- abstract type system to support either 1999 or 2001 schema (arg, typing still needs much
solidification.)
- implemented proxy support, based on sample code from miles lott <milos@speakeasy.net>
- much general cleanup of code & cleaned out what was left of original xml-rpc/gigaideas code
- implemented a transport argument into send() that allows you to specify different transports
(assuming you have implemented the function, and added it to the conditional statement in send()
- abstracted the determination of charset in Content-type header
2001-07-5
- fixed more weird type/namespace issues
*/
// $path can be a complete endpoint url, with the other parameters left blank:
// $soap_client = new soap_client("http://path/to/soap/server");
2001-08-18 16:37:52 +02:00
/* $Id$ */
// soap message class
class soapmsg
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
// params is an array of soapval objects
function soapmsg($method,$params,$method_namespace='http://testuri.org',$new_namespaces=False)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
// globalize method namespace
$GLOBALS['methodNamespace'] = $method_namespace;
$namespaces = $GLOBALS['namespaces'];
2001-08-18 16:37:52 +02:00
// make method struct
$this->value = CreateObject('phpgwapi.soapval',$method,"struct",$params,$method_namespace);
if(is_array($new_namespaces))
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
$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;
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
$this->payload = '';
$this->debug_flag = True;
$this->debug_str = "entering soapmsg() with soapval ".$this->value->name."\n";
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
function make_envelope($payload)
2001-07-16 08:05:33 +02:00
{
$namespaces = $GLOBALS['namespaces'];
2001-08-18 16:37:52 +02:00
@reset($namespaces);
while(list($k,$v) = @each($namespaces))
/* foreach($namespaces as $k => $v) */
{
$ns_string .= " xmlns:$v=\"$k\"";
}
return "<SOAP-ENV:Envelope $ns_string SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
. $payload . "</SOAP-ENV:Envelope>\n";
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
function make_body($payload)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
return "<SOAP-ENV:Body>\n" . $payload . "</SOAP-ENV:Body>\n";
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
function createPayload()
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
$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);
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
function serialize()
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
if($this->payload == '')
{
$this->createPayload();
return $this->payload;
}
else
{
return $this->payload;
}
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
// returns a soapval object
function parseResponse($data)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
$this->debug("Entering parseResponse()");
//$this->debug(" w/ data $data");
// strip headers here
//$clean_data = preg_replace('/'."\r\n".'/',"\n", $data);
if(preg_match('/'."^.*\r\n\r\n<".'/',$data))
2001-08-18 16:37:52 +02:00
{
$this->debug("found proper seperation of headers and document");
$this->debug("getting rid of headers, stringlen: ".strlen($data));
$clean_data = preg_replace('/'."^.*\r\n\r\n<".'/',"<", $data);
2001-08-18 16:37:52 +02:00
$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(preg_match('/'."^HTTP".'/',$clean_data) && !preg_match('/'."200$".'/', $clean_data))
2001-08-18 16:37:52 +02:00
{
// 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;
}
2001-07-16 08:05:33 +02:00
2001-08-18 16:37:52 +02:00
// dbg
function debug($string)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
if($this->debug_flag)
{
$this->debug_str .= "$string\n";
}
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
// preps debug data for encoding into soapmsg
function serializeDebug()
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
if($this->debug_flag)
{
return "<!-- DEBUG INFO:\n".$this->debug_str."-->\n";
}
else
{
return '';
}
2001-07-16 08:05:33 +02:00
}
}
?>