2001-08-08 01:00:28 +02:00
|
|
|
<?php
|
|
|
|
// by Edd Dumbill (C) 1999-2001
|
|
|
|
// <edd@usefulinc.com>
|
|
|
|
// xmlrpc.inc,v 1.18 2001/07/06 18:23:57 edmundd
|
|
|
|
|
|
|
|
// License is granted to use or modify this software ("XML-RPC for PHP")
|
|
|
|
// for commercial or non-commercial use provided the copyright of the author
|
|
|
|
// is preserved in any distributed or derivative work.
|
|
|
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
|
|
|
|
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
class xmlrpcmsg
|
|
|
|
{
|
|
|
|
var $payload;
|
|
|
|
var $methodname;
|
|
|
|
var $params=array();
|
|
|
|
var $debug=0;
|
|
|
|
|
|
|
|
function xmlrpcmsg($meth, $pars=0)
|
|
|
|
{
|
|
|
|
$this->methodname=$meth;
|
|
|
|
if (is_array($pars) && sizeof($pars)>0)
|
|
|
|
{
|
|
|
|
for($i=0; $i<sizeof($pars); $i++)
|
|
|
|
{
|
|
|
|
$this->addParam($pars[$i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function xml_header()
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
return '<?xml version="1.0"?>'."\n".'<methodCall>'."\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function xml_footer()
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
return '</methodCall>'."\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function createPayload()
|
|
|
|
{
|
|
|
|
$this->payload=$this->xml_header();
|
2001-08-09 04:54:56 +02:00
|
|
|
$this->payload.='<methodName>' . $this->methodname . '</methodName>'."\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
// if (sizeof($this->params)) {
|
2001-08-09 04:54:56 +02:00
|
|
|
$this->payload.='<params>'."\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
for($i=0; $i<sizeof($this->params); $i++)
|
|
|
|
{
|
|
|
|
$p=$this->params[$i];
|
2001-08-09 04:54:56 +02:00
|
|
|
$this->payload.='<param>'."\n" . $p->serialize() . '</param>'."\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2001-08-09 04:54:56 +02:00
|
|
|
$this->payload.='</params>'."\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
// }
|
|
|
|
$this->payload.=$this->xml_footer();
|
|
|
|
$this->payload=str_replace("\n", "\r\n", $this->payload);
|
|
|
|
}
|
|
|
|
|
2001-08-09 04:54:56 +02:00
|
|
|
function method($meth='')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
if ($meth!='')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$this->methodname=$meth;
|
|
|
|
}
|
|
|
|
return $this->methodname;
|
|
|
|
}
|
|
|
|
|
|
|
|
function serialize()
|
|
|
|
{
|
|
|
|
$this->createPayload();
|
|
|
|
return $this->payload;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addParam($par) { $this->params[]=$par; }
|
|
|
|
function getParam($i) { return $this->params[$i]; }
|
|
|
|
function getNumParams() { return sizeof($this->params); }
|
|
|
|
|
|
|
|
function parseResponseFile($fp)
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
$ipd='';
|
2001-08-08 01:00:28 +02:00
|
|
|
|
|
|
|
while($data=fread($fp, 32768))
|
|
|
|
{
|
|
|
|
$ipd.=$data;
|
|
|
|
}
|
|
|
|
return $this->parseResponse($ipd);
|
|
|
|
}
|
|
|
|
|
2001-08-09 04:54:56 +02:00
|
|
|
function parseResponse($data='')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
$parser = xml_parser_create($GLOBALS['xmlrpc_defencoding']);
|
2001-08-08 01:00:28 +02:00
|
|
|
|
2001-08-09 04:54:56 +02:00
|
|
|
$GLOBALS['_xh'][$parser] = array();
|
|
|
|
$GLOBALS['_xh'][$parser]['st'] = '';
|
|
|
|
$GLOBALS['_xh'][$parser]['cm'] = 0;
|
|
|
|
$GLOBALS['_xh'][$parser]['isf'] = 0;
|
|
|
|
$GLOBALS['_xh'][$parser]['ac'] = '';
|
|
|
|
$GLOBALS['_xh'][$parser]['qt'] = '';
|
2001-08-09 06:50:11 +02:00
|
|
|
$GLOBALS['_xh'][$parser]['ha'] = '';
|
2001-08-08 01:00:28 +02:00
|
|
|
|
|
|
|
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
|
|
|
|
xml_set_element_handler($parser, "xmlrpc_se", "xmlrpc_ee");
|
|
|
|
xml_set_character_data_handler($parser, "xmlrpc_cd");
|
|
|
|
xml_set_default_handler($parser, "xmlrpc_dh");
|
2001-08-09 04:54:56 +02:00
|
|
|
// $xmlrpc_value = CreateObject('phpgwapi.xmlrpcval');
|
2001-08-08 01:00:28 +02:00
|
|
|
|
|
|
|
$hdrfnd=0;
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
print '<PRE>---GOT---'."\n" . htmlspecialchars($data) . "\n".'---END---'."\n".'</PRE>';
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
// see if we got an HTTP 200 OK, else bomb
|
|
|
|
// but only do this if we're using the HTTP protocol.
|
|
|
|
if (ereg("^HTTP",$data) && !ereg("^HTTP/[0-9\.]+ 200 ", $data))
|
|
|
|
{
|
|
|
|
$errstr= substr($data, 0, strpos($data, "\n")-1);
|
2001-08-09 04:54:56 +02:00
|
|
|
error_log('HTTP error, got response: ' .$errstr);
|
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp',0, $GLOBALS['xmlrpcerr']['http_error'],
|
|
|
|
$GLOBALS['xmlrpcstr']['http_error'] . ' (' . $errstr . ')');
|
2001-08-08 01:00:28 +02:00
|
|
|
xml_parser_free($parser);
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
// gotta get rid of headers here
|
|
|
|
if ((!$hdrfnd) && ereg("^(.*)\r\n\r\n",$data,$_xh[$parser]['ha']))
|
|
|
|
{
|
|
|
|
$data=ereg_replace("^.*\r\n\r\n", "", $data);
|
|
|
|
$hdrfnd=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xml_parse($parser, $data, sizeof($data)))
|
|
|
|
{
|
|
|
|
// thanks to Peter Kocks <peter.kocks@baygate.com>
|
|
|
|
if((xml_get_current_line_number($parser)) == 1)
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
$errstr = 'XML error at line 1, check URL';
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$errstr = sprintf("XML error: %s at line %d",
|
|
|
|
xml_error_string(xml_get_error_code($parser)),
|
|
|
|
xml_get_current_line_number($parser));
|
|
|
|
}
|
|
|
|
error_log($errstr);
|
2001-08-09 04:54:56 +02:00
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp',CreateObject('phpgwapi.xmlrpcval'), $GLOBALS['xmlrpcerr']['invalid_return'],$GLOBALS['xmlrpcstr']['invalid_return']);
|
2001-08-08 01:00:28 +02:00
|
|
|
xml_parser_free($parser);
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
xml_parser_free($parser);
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
print '<PRE>---EVALING---[' .
|
|
|
|
strlen($GLOBALS['_xh'][$parser]['st']) . ' chars]---'."\n" .
|
|
|
|
htmlspecialchars($GLOBALS['_xh'][$parser]['st']) . ';'."\n".'---END---</PRE>';
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2001-08-09 04:54:56 +02:00
|
|
|
if (strlen($GLOBALS['_xh'][$parser]['st']) == 0)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
// then something odd has happened
|
|
|
|
// and it's time to generate a client side error
|
|
|
|
// indicating something odd went on
|
2001-08-09 04:54:56 +02:00
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp',CreateObject('phpgwapi.xmlrpcval'), $GLOBALS['xmlrpcerr']['invalid_return'],$GLOBALS['xmlrpcstr']['invalid_return']);
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
$code = '$v=' . $GLOBALS['_xh'][$parser]['st'] . '; $allOK=1;';
|
2001-08-08 01:00:28 +02:00
|
|
|
$code = ereg_replace(',,',",'',",$code);
|
|
|
|
eval($code);
|
2001-08-09 04:54:56 +02:00
|
|
|
if ($GLOBALS['_xh'][$parser]['isf'])
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
$f = $v->structmem('faultCode');
|
|
|
|
$fs = $v->structmem('faultString');
|
2001-08-08 01:00:28 +02:00
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp',$v, $f->scalarval(), $fs->scalarval());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp',$v);
|
|
|
|
}
|
|
|
|
}
|
2001-08-09 04:54:56 +02:00
|
|
|
$r->hdrs=split("\r?\n", $GLOBALS['_xh'][$parser]['ha'][1]);
|
2001-08-08 01:00:28 +02:00
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|