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 xmlrpcval
|
|
|
|
{
|
|
|
|
var $me = array();
|
|
|
|
var $mytype = 0;
|
|
|
|
|
2001-11-13 22:03:24 +01:00
|
|
|
function xmlrpcval($val = -1, $type = '')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$this->me = array();
|
|
|
|
$this->mytype = 0;
|
2001-11-13 22:03:24 +01:00
|
|
|
|
2002-02-09 22:19:22 +01:00
|
|
|
if($val != -1 || $type != '')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
if($type == '')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
$type = 'string';
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2002-02-09 22:19:22 +01:00
|
|
|
if($GLOBALS['xmlrpcTypes'][$type] == 1)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$this->addScalar($val,$type);
|
|
|
|
}
|
2002-02-09 22:19:22 +01:00
|
|
|
elseif($GLOBALS['xmlrpcTypes'][$type] == 2)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$this->addArray($val);
|
|
|
|
}
|
2002-02-09 22:19:22 +01:00
|
|
|
elseif($GLOBALS['xmlrpcTypes'][$type] == 3)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$this->addStruct($val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addScalar($val, $type='string')
|
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
if ($this->mytype == 1)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
echo '<B>xmlrpcval</B>: scalar can have only one value<BR>';
|
2001-08-08 01:00:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-02-09 22:19:22 +01:00
|
|
|
$typeof = $GLOBALS['xmlrpcTypes'][$type];
|
|
|
|
if ($typeof != 1)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
echo '<B>xmlrpcval</B>: not a scalar type ('.$typeof.')<BR>';
|
2001-08-08 01:00:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-02-09 22:19:22 +01:00
|
|
|
if ($type == xmlrpcBoolean)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
if (strcasecmp($val,'true') == 0 ||
|
|
|
|
$val == 1 ||
|
|
|
|
($val == True && strcasecmp($val,'false')))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$val=1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$val=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-09 22:19:22 +01:00
|
|
|
if ($this->mytype == 2)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
// we're adding to an array here
|
2002-02-09 22:19:22 +01:00
|
|
|
$ar = $this->me['array'];
|
2001-08-08 01:00:28 +02:00
|
|
|
$ar[] = CreateObject('phpgwapi.xmlrpcval',$val, $type);
|
2002-02-09 22:19:22 +01:00
|
|
|
$this->me['array'] = $ar;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// a scalar, so set the value and remember we're scalar
|
2002-02-09 22:19:22 +01:00
|
|
|
$this->me[$type] = $val;
|
|
|
|
$this->mytype = $typeof;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addArray($vals)
|
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
if($this->mytype != 0)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
echo '<B>xmlrpcval</B>: already initialized as a [' . $this->kindOf() . ']<BR>';
|
2001-08-08 01:00:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-02-09 22:19:22 +01:00
|
|
|
$this->mytype = $GLOBALS['xmlrpcTypes']['array'];
|
|
|
|
$this->me['array'] = $vals;
|
2001-08-08 01:00:28 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addStruct($vals)
|
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
if($this->mytype != 0)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
echo '<B>xmlrpcval</B>: already initialized as a [' . $this->kindOf() . ']<BR>';
|
2001-08-08 01:00:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-02-09 22:19:22 +01:00
|
|
|
$this->mytype = $GLOBALS['xmlrpcTypes']['struct'];
|
|
|
|
$this->me['struct'] = $vals;
|
2001-08-08 01:00:28 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dump($ar)
|
|
|
|
{
|
|
|
|
reset($ar);
|
2002-02-09 22:19:22 +01:00
|
|
|
while(list($key,$val) = each($ar))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
echo $key.' => '.$val.'<br>';
|
2002-02-09 22:19:22 +01:00
|
|
|
if($key == 'array')
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
while(list($key2,$val2) = each($val))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
echo '-- ' . $key2.' => ' . $val2 . '<br>';
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function kindOf()
|
|
|
|
{
|
|
|
|
switch($this->mytype)
|
|
|
|
{
|
|
|
|
case 3:
|
2001-08-09 04:54:56 +02:00
|
|
|
return 'struct';
|
2001-08-08 01:00:28 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2001-08-09 04:54:56 +02:00
|
|
|
return 'array';
|
2001-08-08 01:00:28 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2001-08-09 04:54:56 +02:00
|
|
|
return 'scalar';
|
2001-08-08 01:00:28 +02:00
|
|
|
break;
|
|
|
|
default:
|
2001-08-09 04:54:56 +02:00
|
|
|
return 'undef';
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function serializedata($typ, $val)
|
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs = '';
|
2001-08-08 01:00:28 +02:00
|
|
|
if($typ)
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
switch($GLOBALS['xmlrpcTypes'][$typ])
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
case 3:
|
|
|
|
// struct
|
2001-08-09 04:54:56 +02:00
|
|
|
$rs .= '<struct>'."\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
reset($val);
|
|
|
|
while(list($key2, $val2)=each($val))
|
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= '<member><name>' . $key2 . '</name>' . "\n" . $this->serializeval($val2) . '</member>' . "\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2001-08-09 04:54:56 +02:00
|
|
|
$rs .= '</struct>';
|
2001-08-08 01:00:28 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// array
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= '<array>' . "\n" . '<data>' . "\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
for($i=0; $i<sizeof($val); $i++)
|
|
|
|
{
|
|
|
|
$rs .= $this->serializeval($val[$i]);
|
|
|
|
}
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= '</data>' . "\n" . '</array>';
|
2001-08-08 01:00:28 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= '<' . $typ . '>';
|
|
|
|
switch($typ)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
case xmlrpcBase64:
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= base64_encode($val);
|
2001-08-08 01:00:28 +02:00
|
|
|
break;
|
2001-08-09 04:54:56 +02:00
|
|
|
case xmlrpcBoolean:
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= ($val ? '1' : '0');
|
2001-08-09 04:54:56 +02:00
|
|
|
break;
|
|
|
|
case xmlrpcString:
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= htmlspecialchars($val);
|
2001-08-08 01:00:28 +02:00
|
|
|
break;
|
|
|
|
default:
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= $val;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= '</' . $typ . '>';
|
2001-08-08 01:00:28 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rs;
|
|
|
|
}
|
|
|
|
|
|
|
|
function serialize()
|
|
|
|
{
|
|
|
|
return $this->serializeval($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function serializeval($o)
|
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs = '';
|
|
|
|
$ar = $o->me;
|
2001-08-08 01:00:28 +02:00
|
|
|
reset($ar);
|
|
|
|
list($typ, $val) = each($ar);
|
2002-02-09 22:19:22 +01:00
|
|
|
$rs .= '<value>';
|
|
|
|
$rs .= @$this->serializedata($typ, $val);
|
|
|
|
$rs .= '</value>' . "\n";
|
2001-08-08 01:00:28 +02:00
|
|
|
return $rs;
|
|
|
|
}
|
|
|
|
|
|
|
|
function structmem($m)
|
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
$nv = $this->me['struct'][$m];
|
2001-08-08 01:00:28 +02:00
|
|
|
return $nv;
|
|
|
|
}
|
|
|
|
|
|
|
|
function structreset()
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
reset($this->me['struct']);
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function structeach()
|
|
|
|
{
|
2001-08-09 04:54:56 +02:00
|
|
|
return each($this->me['struct']);
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getval()
|
|
|
|
{
|
|
|
|
// UNSTABLE
|
|
|
|
reset($this->me);
|
2002-02-09 22:19:22 +01:00
|
|
|
list($a,$b) = each($this->me);
|
2001-08-08 01:00:28 +02:00
|
|
|
// contributed by I Sofer, 2001-03-24
|
|
|
|
// add support for nested arrays to scalarval
|
|
|
|
// i've created a new method here, so as to
|
|
|
|
// preserve back compatibility
|
|
|
|
|
2002-02-09 22:19:22 +01:00
|
|
|
if(is_array($b))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2001-08-08 01:18:21 +02:00
|
|
|
@reset($b);
|
|
|
|
while(list($id,$cont) = @each($b))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$b[$id] = $cont->scalarval();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add support for structures directly encoding php objects
|
2002-02-09 22:19:22 +01:00
|
|
|
if(is_object($b))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$t = get_object_vars($b);
|
2001-08-08 01:18:21 +02:00
|
|
|
@reset($t);
|
|
|
|
while(list($id,$cont) = @each($t))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
$t[$id] = $cont->scalarval();
|
|
|
|
}
|
2001-08-08 01:18:21 +02:00
|
|
|
@reset($t);
|
|
|
|
while(list($id,$cont) = @each($t))
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
|
|
|
eval('$b->'.$id.' = $cont;');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// end contrib
|
|
|
|
return $b;
|
|
|
|
}
|
|
|
|
|
|
|
|
function scalarval()
|
|
|
|
{
|
|
|
|
reset($this->me);
|
2002-02-09 22:19:22 +01:00
|
|
|
list($a,$b) = each($this->me);
|
2001-08-08 01:00:28 +02:00
|
|
|
return $b;
|
|
|
|
}
|
|
|
|
|
|
|
|
function scalartyp()
|
|
|
|
{
|
|
|
|
reset($this->me);
|
2002-02-09 22:19:22 +01:00
|
|
|
list($a,$b) = each($this->me);
|
|
|
|
if ($a == xmlrpcI4)
|
2001-08-08 01:00:28 +02:00
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
$a = xmlrpcInt;
|
2001-08-08 01:00:28 +02:00
|
|
|
}
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
|
|
|
|
function arraymem($m)
|
|
|
|
{
|
2002-02-09 22:19:22 +01:00
|
|
|
$nv = @$this->me['array'][$m];
|
2001-08-08 01:00:28 +02:00
|
|
|
return $nv;
|
|
|
|
}
|
|
|
|
|
|
|
|
function arraysize()
|
|
|
|
{
|
|
|
|
reset($this->me);
|
2002-02-09 22:19:22 +01:00
|
|
|
list($a,$b) = each($this->me);
|
2001-08-08 01:00:28 +02:00
|
|
|
return sizeof($b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|