include "xmlrpc.inc"; $f = new xmlrpcmsg('examples.getStateName'); print "<h3>Testing value serialization</h3>\n"; $v = new xmlrpcval(23, "int"); print "<PRE>" . htmlentities($v->serialize()) . "</PRE>"; $v = new xmlrpcval("What are you saying? >> << &&"); print "<PRE>" . htmlentities($v->serialize()) . "</PRE>"; $v = new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean')), "array"); print "<PRE>" . htmlentities($v->serialize()) . "</PRE>"; $v = new xmlrpcval(array("thearray" => new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean'), new xmlrpcval(0, 'boolean'), new xmlrpcval(true, 'boolean'), new xmlrpcval(false, 'boolean')), "array"), "theint" => new xmlrpcval(23, 'int'), "thestring" => new xmlrpcval("foobarwhizz"), "thestruct" => new xmlrpcval(array("one" => new xmlrpcval(1, 'int'), "two" => new xmlrpcval(2, 'int')), "struct")), "struct"); print "<PRE>" . htmlentities($v->serialize()) . "</PRE>"; $w = new xmlrpcval(array($v, new xmlrpcval("That was the struct!")), "array"); print "<PRE>" . htmlentities($w->serialize()) . "</PRE>"; $w = new xmlrpcval("Mary had a little lamb,\nWhose fleece was white as snow,\nAnd everywhere that Mary went\nthe lamb was sure to go.\n\nMary had a little lamb\nShe tied it to a pylon\nTen thousand volts went down its back\nAnd turned it into nylon", "base64"); print "<PRE>" . htmlentities($w->serialize()) . "</PRE>"; print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>"; $f->method(''); $f->addParam(new xmlrpcval("41", "int")); print "<h3>Testing request serialization</h3>\n"; $op = $f->serialize(); print "<PRE>" . htmlentities($op) . "</PRE>"; print "<h3>Testing ISO date format</h3><pre>\n"; $t = time(); $date = iso8601_encode($t); print "Now is {$t} --> {$date}\n"; print "Or in UTC, that is " . iso8601_encode($t, 1) . "\n"; $tb = iso8601_decode($date); print "That is to say {$date} --> {$tb}\n"; print "Which comes out at " . iso8601_encode($tb) . "\n"; print "Which was the time in UTC at " . iso8601_decode($date, 1) . "\n"; print "</pre>\n";
/** * Takes an xmlrpc value in PHP xmlrpcval object format * and translates it into native PHP types. * * @author Dan Libby (dan@libby.com) * * @param xmlrpcval $xmlrpc_val * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects * @return mixed */ function php_xmlrpc_decode($xmlrpc_val, $options = '') { $kind = $xmlrpc_val->kindOf(); if ($kind == 'scalar') { return $xmlrpc_val->scalarval(); } elseif ($kind == 'array') { $size = $xmlrpc_val->arraysize(); $arr = array(); for ($i = 0; $i < $size; $i++) { $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options); } return $arr; } elseif ($kind == 'struct') { $xmlrpc_val->structreset(); // If user said so, try to rebuild php objects for specific struct vals. /// @todo should we raise a warning for class not found? // shall we check for proper subclass of xmlrpcval instead of // presence of _php_class to detect what we can do? if (@in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) { $obj = @new $xmlrpc_val->_php_class(); while (list($key, $value) = $xmlrpc_val->structeach()) { $obj->{$key} = php_xmlrpc_decode($value, $options); } return $obj; } else { $arr = array(); while (list($key, $value) = $xmlrpc_val->structeach()) { $arr[$key] = php_xmlrpc_decode($value, $options); } return $arr; } } }
/** * Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types. * * Works with xmlrpc message objects as input, too. * * Given proper options parameter, can rebuild generic php object instances * (provided those have been encoded to xmlrpc format using a corresponding * option in php_xmlrpc_encode()) * PLEASE NOTE that rebuilding php objects involves calling their constructor function. * This means that the remote communication end can decide which php code will * get executed on your server, leaving the door possibly open to 'php-injection' * style of attacks (provided you have some classes defined on your server that * might wreak havoc if instances are built outside an appropriate context). * Make sure you trust the remote server/client before eanbling this! * * @author Dan Libby (dan@libby.com) * * @param xmlrpcval $xmlrpc_val * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is * @return mixed */ function php_xmlrpc_decode($xmlrpc_val, $options = array()) { switch ($xmlrpc_val->kindOf()) { case 'scalar': if (in_array('extension_api', $options)) { reset($xmlrpc_val->me); list($typ, $val) = each($xmlrpc_val->me); switch ($typ) { case 'dateTime.iso8601': $xmlrpc_val->scalar = $val; $xmlrpc_val->xmlrpc_type = 'datetime'; $xmlrpc_val->timestamp = iso8601_decode($val); return $xmlrpc_val; case 'base64': $xmlrpc_val->scalar = $val; $xmlrpc_val->type = $typ; return $xmlrpc_val; default: return $xmlrpc_val->scalarval(); } } if (in_array('dates_as_objects', $options) && $xmlrpc_val->scalartyp() == 'dateTime.iso8601') { // we return a Datetime object instead of a string // since now the constructor of xmlrpcval accepts safely strings, ints and datetimes, // we cater to all 3 cases here $out = $xmlrpc_val->scalarval(); if (is_string($out)) { $out = strtotime($out); } if (is_int($out)) { $result = new Datetime(); $result->setTimestamp($out); return $result; } elseif (is_a($out, 'Datetime')) { return $out; } } return $xmlrpc_val->scalarval(); case 'array': $size = $xmlrpc_val->arraysize(); $arr = array(); for ($i = 0; $i < $size; $i++) { $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options); } return $arr; case 'struct': $xmlrpc_val->structreset(); // If user said so, try to rebuild php objects for specific struct vals. /// @todo should we raise a warning for class not found? // shall we check for proper subclass of xmlrpcval instead of // presence of _php_class to detect what we can do? if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) { $obj = @new $xmlrpc_val->_php_class(); while (list($key, $value) = $xmlrpc_val->structeach()) { $obj->{$key} = php_xmlrpc_decode($value, $options); } return $obj; } else { $arr = array(); while (list($key, $value) = $xmlrpc_val->structeach()) { $arr[$key] = php_xmlrpc_decode($value, $options); } return $arr; } case 'msg': $paramcount = $xmlrpc_val->getNumParams(); $arr = array(); for ($i = 0; $i < $paramcount; $i++) { $arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i)); } return $arr; } }
case 'list_methods': jimport('joomla.html.html'); $msg = new xmlrpcmsg('system.listMethods'); $xmlrpcdoc = $client->send($msg); //echo var_dump($xmlrpcdoc); //die; if ($xmlrpcdoc->faultCode() == 0) { $result = $xmlrpcdoc->value(); $array = $result->scalarval(); } else { print $xmlrpcdoc->faultString(); } $methods = array(); for ($i = 0; $i < sizeof($array); $i++) { $var = new xmlrpcval($array[$i]); $array_method = $var->scalarval(); $methods[$i] = JHTML::_('select.option', $array_method->scalarval()); } $output = 'Methods<br />'; $output .= JHTML::_('select.genericlist', $methods, 'method', 'size="10"', 'value', 'text'); $output .= ' <input name="args" type="text" />'; $output .= ' <input name="task" type="submit" value="exec" />'; break; case 'exec': $method = JRequest::getVar('method', '', '', 'cmd'); $args = JRequest::getVar('args'); $message = new xmlrpcmsg($method, array(new xmlrpcval(0, "int"))); $xmlrpcdoc = $client->send($message); if ($xmlrpcdoc->faultCode() == 0) { $scalar_var = $xmlrpcdoc->value(); $output = var_export($scalar_var->scalarval(), true);
function testMinusOneString() { $v = new xmlrpcval('-1'); $u = new xmlrpcval('-1', 'string'); $this->assertEquals($u->scalarval(), $v->scalarval()); }
/** * Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types. * * Works with xmlrpc message objects as input, too. * * Given proper options parameter, can rebuild generic php object instances * (provided those have been encoded to xmlrpc format using a corresponding * option in php_xmlrpc_encode()) * PLEASE NOTE that rebuilding php objects involves calling their constructor function. * This means that the remote communication end can decide which php code will * get executed on your server, leaving the door possibly open to 'php-injection' * style of attacks (provided you have some classes defined on your server that * might wreak havoc if instances are built outside an appropriate context). * Make sure you trust the remote server/client before eanbling this! * * @author Dan Libby (dan@libby.com) * * @param xmlrpcval $xmlrpc_val * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects * @return mixed */ function php_xmlrpc_decode($xmlrpc_val, $options=array()) { switch($xmlrpc_val->kindOf()) { case 'scalar': if (in_array('extension_api', $options)) { reset($xmlrpc_val->me); list($typ,$val) = each($xmlrpc_val->me); switch ($typ) { case 'dateTime.iso8601': $xmlrpc_val->scalar = $val; $xmlrpc_val->xmlrpc_type = 'datetime'; $xmlrpc_val->timestamp = iso8601_decode($val); return $xmlrpc_val; case 'base64': $xmlrpc_val->scalar = $val; $xmlrpc_val->type = $typ; return $xmlrpc_val; default: return $xmlrpc_val->scalarval(); } } return $xmlrpc_val->scalarval(); case 'array': $size = $xmlrpc_val->arraysize(); $arr = array(); for($i = 0; $i < $size; $i++) { $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options); } return $arr; case 'struct': $xmlrpc_val->structreset(); // If user said so, try to rebuild php objects for specific struct vals. /// @todo should we raise a warning for class not found? // shall we check for proper subclass of xmlrpcval instead of // presence of _php_class to detect what we can do? if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) { $obj = @new $xmlrpc_val->_php_class; while(list($key,$value)=$xmlrpc_val->structeach()) { $obj->$key = php_xmlrpc_decode($value, $options); } return $obj; } else { $arr = array(); while(list($key,$value)=$xmlrpc_val->structeach()) { $arr[$key] = php_xmlrpc_decode($value, $options); } return $arr; } case 'msg': $paramcount = $xmlrpc_val->getNumParams(); $arr = array(); for($i = 0; $i < $paramcount; $i++) { $arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i)); } return $arr; } }
function TestLocale() { $locale = setlocale(LC_NUMERIC, 0); /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma... if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) { $v = new xmlrpcval(1.1, 'double'); if (strpos($v->scalarval(), ',') == 1) { $r = $v->serialize(); $this->assertequals(false, strpos($r, ',')); } setlocale(LC_NUMERIC, $locale); } }
function TestLocale() { $locale = setlocale(LC_NUMERIC, 0); if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) { $v = new xmlrpcval(1.1, 'double'); $r = $v->serialize(); $this->assertequals(false, strpos($r, ',')); $this->assertequals(1, strpos($v->scalarval(), ',')); setlocale(LC_NUMERIC, $locale); } }