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
|
|
|
|
|
2001-08-14 00:03:26 +02:00
|
|
|
// License is granted to use or modify this software ('XML-RPC for PHP')
|
2001-08-08 01:00:28 +02:00
|
|
|
// 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.
|
|
|
|
|
2001-08-14 00:03:26 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2001-08-08 01:00:28 +02:00
|
|
|
class xmlrpcmsg
|
|
|
|
{
|
|
|
|
var $payload;
|
|
|
|
var $methodname;
|
2001-08-14 00:03:26 +02:00
|
|
|
var $params = array();
|
2003-08-28 16:31:11 +02:00
|
|
|
var $debug = 0;
|
2001-08-08 01:00:28 +02:00
|
|
|
|
|
|
|
function xmlrpcmsg($meth, $pars=0)
|
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
$this->methodname = $meth;
|
2003-08-28 16:31:11 +02:00
|
|
|
if (is_array($pars) && sizeof($pars)>0)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
for($i=0; $i<sizeof($pars); $i++)
|
|
|
|
{
|
|
|
|
$this->addParam($pars[$i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function xml_header()
|
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
return '<?xml version="1.0"?>' . "\n" . '<methodCall>' . "\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function xml_footer()
|
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
return '</methodCall>' . "\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function createPayload()
|
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
$this->payload = $this->xml_header();
|
|
|
|
$this->payload .= '<methodName>' . $this->methodname . '</methodName>' . "\n";
|
|
|
|
if (sizeof($this->params))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
$this->payload .= '<params>' . "\n";
|
|
|
|
for($i=0; $i<sizeof($this->params); $i++)
|
|
|
|
{
|
|
|
|
$p = $this->params[$i];
|
|
|
|
$this->payload .= '<param>' . "\n" . $p->serialize() . '</param>' . "\n";
|
|
|
|
}
|
|
|
|
$this->payload .= '</params>' . "\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2001-08-14 00:03:26 +02:00
|
|
|
$this->payload .= $this->xml_footer();
|
|
|
|
$this->payload = str_replace("\n", "\r\n", $this->payload);
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
2001-08-09 04:54:56 +02:00
|
|
|
function method($meth='')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
if ($meth != '')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
$this->methodname = $meth;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
return $this->methodname;
|
|
|
|
}
|
|
|
|
|
|
|
|
function serialize()
|
|
|
|
{
|
|
|
|
$this->createPayload();
|
|
|
|
return $this->payload;
|
|
|
|
}
|
|
|
|
|
2001-08-14 00:03:26 +02:00
|
|
|
function addParam($par)
|
|
|
|
{
|
|
|
|
$this->params[] = $par;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getParam($i)
|
|
|
|
{
|
|
|
|
return $this->params[$i];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNumParams()
|
|
|
|
{
|
|
|
|
return sizeof($this->params);
|
|
|
|
}
|
2001-08-08 01:00:28 +02:00
|
|
|
|
|
|
|
function parseResponseFile($fp)
|
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
$ipd = '';
|
2001-08-08 01:00:28 +02:00
|
|
|
|
2001-08-14 00:03:26 +02:00
|
|
|
while($data = fread($fp, 32768))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
$ipd .= $data;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2001-12-06 15:43:05 +01:00
|
|
|
/* echo $ipd;exit; */
|
2001-08-08 01:00:28 +02:00
|
|
|
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-11-30 05:05:07 +01:00
|
|
|
$GLOBALS['_xh'][$parser]['ha'] = '';
|
2001-08-08 01:00:28 +02:00
|
|
|
|
|
|
|
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
|
2001-08-14 00:03:26 +02:00
|
|
|
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
|
|
|
|
2001-08-30 02:29:55 +02:00
|
|
|
$hdrfnd = 0;
|
2001-08-08 01:00:28 +02:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
2003-10-20 18:34:29 +02:00
|
|
|
echo '<PRE style="text-align: left;">---GOT---' . "\n" . htmlspecialchars($data) . "\n" . '---END---' . "\n" . '</PRE>';
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2001-08-30 02:29:55 +02:00
|
|
|
if ($data == '')
|
|
|
|
{
|
|
|
|
error_log('No response received from server.');
|
|
|
|
$r = CreateObject(
|
|
|
|
'phpgwapi.xmlrpcresp',
|
|
|
|
0,
|
|
|
|
$GLOBALS['xmlrpcerr']['no_data'],
|
|
|
|
$GLOBALS['xmlrpcstr']['no_data']
|
|
|
|
);
|
|
|
|
xml_parser_free($parser);
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
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.
|
2001-12-07 22:51:36 +01:00
|
|
|
if (ereg("^HTTP",$data) && !ereg("^HTTP/[0-9.]+ 200 ", $data))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
$errstr = substr($data, 0, strpos($data, "\n")-1);
|
2001-08-09 04:54:56 +02:00
|
|
|
error_log('HTTP error, got response: ' .$errstr);
|
2001-12-06 16:51:06 +01:00
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp','', $GLOBALS['xmlrpcerr']['http_error'],
|
2001-08-09 04:54:56 +02:00
|
|
|
$GLOBALS['xmlrpcstr']['http_error'] . ' (' . $errstr . ')');
|
2001-08-08 01:00:28 +02:00
|
|
|
xml_parser_free($parser);
|
|
|
|
return $r;
|
|
|
|
}
|
2001-11-30 04:59:21 +01:00
|
|
|
|
|
|
|
// if using HTTP, then gotta get rid of HTTP headers here
|
|
|
|
// and we store them in the 'ha' bit of our data array
|
|
|
|
if (ereg("^HTTP", $data))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-11-30 04:59:21 +01:00
|
|
|
$ar=explode("\r\n", $data);
|
|
|
|
$newdata = '';
|
|
|
|
$hdrfnd = 0;
|
|
|
|
for ($i=0; $i<sizeof($ar); $i++)
|
|
|
|
{
|
|
|
|
if (!$hdrfnd)
|
|
|
|
{
|
|
|
|
if (strlen($ar[$i])>0)
|
|
|
|
{
|
|
|
|
$GLOBALS['_xh'][$parser]['ha'] .= $ar[$i]. "\r\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$hdrfnd=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$newdata.=$ar[$i] . "\r\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$data=$newdata;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2001-11-30 04:59:21 +01:00
|
|
|
|
2001-08-08 01:00:28 +02:00
|
|
|
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
|
|
|
|
{
|
2001-08-14 00:03:26 +02:00
|
|
|
$errstr = sprintf('XML error: %s at line %d',
|
2001-08-08 01:00:28 +02:00
|
|
|
xml_error_string(xml_get_error_code($parser)),
|
|
|
|
xml_get_current_line_number($parser));
|
|
|
|
}
|
|
|
|
error_log($errstr);
|
2001-12-06 16:51:06 +01:00
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp', '', $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)
|
|
|
|
{
|
2003-10-20 18:34:29 +02:00
|
|
|
echo '<PRE style="text-align: left;">---EVALING---['
|
2001-08-14 00:03:26 +02:00
|
|
|
. 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-12-06 16:51:06 +01:00
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp', '', $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;';
|
2004-01-26 04:33:09 +01:00
|
|
|
$code = str_replace(',,',",'',",$code);
|
2005-06-30 15:36:47 +02:00
|
|
|
$allok = 0;
|
|
|
|
@eval($code);
|
|
|
|
if(!$allok)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2005-06-30 15:36:47 +02:00
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp','', $GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcstr']['invalid_return']);
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-30 15:36:47 +02:00
|
|
|
if ($GLOBALS['_xh'][$parser]['isf'])
|
|
|
|
{
|
|
|
|
$f = $v->structmem('faultCode');
|
|
|
|
$fs = $v->structmem('faultString');
|
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp',$v, $f->scalarval(), $fs->scalarval());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$r = CreateObject('phpgwapi.xmlrpcresp',$v);
|
|
|
|
}
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
}
|
2001-12-07 22:51:36 +01:00
|
|
|
$r->hdrs = $GLOBALS['_xh'][$parser]['ha']; //split("\r?\n", $GLOBALS['_xh'][$parser]['ha'][1]);
|
2001-08-08 01:00:28 +02:00
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|