}
if ($protocol == 2 || $protocol == 3) {
- $client->setSSLVerifyPeer($verifypeer);
- $client->setSSLVerifyHost($verifyhost);
+ $client->setOption(\PhpXmlRpc\Client::OPT_VERIFY_PEER, $verifypeer);
+ $client->setOption(\PhpXmlRpc\Client::OPT_VERIFY_HOST, $verifyhost);
if ($cainfo) {
$client->setCaCertificate($cainfo);
}
switch ($requestcompression) {
case 0:
- $client->request_compression = '';
+ $client->setOption(\PhpXmlRpc\Client::OPT_REQUEST_COMPRESSION, '');
break;
case 1:
- $client->request_compression = 'gzip';
+ $client->setOption(\PhpXmlRpc\Client::OPT_REQUEST_COMPRESSION, 'gzip');
break;
case 2:
- $client->request_compression = 'deflate';
+ $client->setOption(\PhpXmlRpc\Client::OPT_REQUEST_COMPRESSION, 'deflate');
break;
}
switch ($responsecompression) {
case 0:
- $client->accepted_compression = '';
+ $client->setOption(\PhpXmlRpc\Client::OPT_ACCEPTED_COMPRESSION, '');
break;
case 1:
- $client->accepted_compression = array('gzip');
+ $client->setOption(\PhpXmlRpc\Client::OPT_ACCEPTED_COMPRESSION, array('gzip'));
break;
case 2:
- $client->accepted_compression = array('deflate');
+ $client->setOption(\PhpXmlRpc\Client::OPT_ACCEPTED_COMPRESSION, ('deflate'));
break;
case 3:
- $client->accepted_compression = array('gzip', 'deflate');
+ $client->setOption(\PhpXmlRpc\Client::OPT_ACCEPTED_COMPRESSION, array('gzip', 'deflate'));
break;
}
<h3>Changelog</h3>
<ul>
- <li>2023-XX-YY: display in the top row the version of the libraries in use; made the generated code throw instead
+ <li>2023-02-YY: display in the top row the version of the libraries in use; made the generated code throw instead
of returning a Response object on error; fixes for the json-rpc debugger</li>
<li>2022-12-18: fix XSS vulnerability in the debugger; load jsxmlrpc from CDN; minor improvements</li>
<li>2022-11-28: allow to use http/2 protocol; two security issues fixed in the underlying library</li>
// NB: we are _assuming_ that the server did return a scalar xml-rpc value here.
// If the server is not trusted, we might check that via `$val->kindOf() == 'scalar'`
output('<br/>State number <b>' . $stateNo . '</b> is <b>'
- . htmlspecialchars($val->scalarval()) . '</b><br/><br/>');
+ . htmlspecialchars($val->scalarVal()) . '</b><br/><br/>');
} else {
output('An error occurred: ');
output('<pre>Code: ' . htmlspecialchars($resp->faultCode())
$c->setOption(Client::OPT_REQUEST_CHARSET_ENCODING, 'UTF-8');
$r = $c->send(new Request('examples.stringecho', array(new Value($input))));
-$output = $r->value()->scalarval();
+$output = $r->value()->scalarVal();
echo "This is the value we got back from the server (in CP-1252): ";
var_dump($output);
// let code exceptions float all the way to the remote caller as xml-rpc faults - it helps debugging.
// At the same time, it opens a wide security hole, and should never be enabled on public or production servers...
-//$srv->exception_handling = 1;
+//$srv->->setOption(Server::OPT_EXCEPTION_HANDLING, 1);
// NB: take care not to output anything else after this call, as it will mess up the responses and it will be hard to
// debug. In case you have to do so, at least re-emit a correct Content-Length http header (requires output buffering)
$sno = $req->getParam(0);
// extract the value of the state number
- $snv = $sno->scalarval();
+ $snv = $sno->scalarVal();
// look it up in our array (zero-based)
if (isset(self::$stateNames[$snv - 1])) {
$s = $req->getParam(0);
$t = $req->getParam(1);
- return new Response(new Value($s->scalarval() + $t->scalarval(), Value::$xmlrpcInt));
+ return new Response(new Value($s->scalarVal() + $t->scalarVal(), Value::$xmlrpcInt));
}
public static $addtwodouble_sig = array(array('double', 'double', 'double'));
$s = $req->getParam(0);
$t = $req->getParam(1);
- return new Response(new Value($s->scalarval() + $t->scalarval(), Value::$xmlrpcDouble));
+ return new Response(new Value($s->scalarVal() + $t->scalarVal(), Value::$xmlrpcDouble));
}
public static $stringecho_sig = array(array('string', 'string'));
public static function stringEcho($req)
{
// just sends back a string
- return new Response(new Value($req->getParam(0)->scalarval()));
+ return new Response(new Value($req->getParam(0)->scalarVal()));
}
public static $echoback_sig = array(array('string', 'string'));
// This is to test that base64 encoding is working as expected
$incoming = $req->getParam(0);
- return new Response(new Value($incoming->scalarval(), Value::$xmlrpcString));
+ return new Response(new Value($incoming->scalarVal(), Value::$xmlrpcString));
}
public static $bitflipper_sig = array(array('array', 'array'));
$rv = new Value(array(), Value::$xmlrpcArray);
foreach ($v as $b) {
- if ($b->scalarval()) {
+ if ($b->scalarVal()) {
$rv[] = new Value(false, Value::$xmlrpcBoolean);
} else {
$rv[] = new Value(true, Value::$xmlrpcBoolean);
$mBcc = $req->getParam(5);
$mMime = $req->getParam(6);
- if ($mTo->scalarval() == "") {
+ if ($mTo->scalarVal() == "") {
$err = "Error, no 'To' field specified";
}
- if ($mFrom->scalarval() == "") {
+ if ($mFrom->scalarVal() == "") {
$err = "Error, no 'From' field specified";
}
/// @todo in real life, we should check for presence of return characters to avoid header injection!
- $msgHdr = "From: " . $mFrom->scalarval() . "\n";
- $msgHdr .= "To: " . $mTo->scalarval() . "\n";
+ $msgHdr = "From: " . $mFrom->scalarVal() . "\n";
+ $msgHdr .= "To: " . $mTo->scalarVal() . "\n";
- if ($mCc->scalarval() != "") {
- $msgHdr .= "Cc: " . $mCc->scalarval() . "\n";
+ if ($mCc->scalarVal() != "") {
+ $msgHdr .= "Cc: " . $mCc->scalarVal() . "\n";
}
- if ($mBcc->scalarval() != "") {
- $msgHdr .= "Bcc: " . $mBcc->scalarval() . "\n";
+ if ($mBcc->scalarVal() != "") {
+ $msgHdr .= "Bcc: " . $mBcc->scalarVal() . "\n";
}
- if ($mMime->scalarval() != "") {
- $msgHdr .= "Content-type: " . $mMime->scalarval() . "\n";
+ if ($mMime->scalarVal() != "") {
+ $msgHdr .= "Content-type: " . $mMime->scalarVal() . "\n";
}
$msgHdr .= "X-Mailer: XML-RPC for PHP mailer 1.0";
if ($err == "") {
- if (!mail("", $mSub->scalarval(), $mBody->scalarval(), $msgHdr)) {
+ if (!mail("", $mSub->scalarVal(), $mBody->scalarVal(), $msgHdr)) {
$err = "Error, could not send the mail.";
}
}
$a = $req->getParam(0);
$b = $req->getParam(1);
- if ($a->scalartyp() == Value::$xmlrpcNull)
- return new Response(new Value(plain_findstate($b->scalarval())));
+ if ($a->scalarTyp() == Value::$xmlrpcNull)
+ return new Response(new Value(plain_findstate($b->scalarVal())));
else
- return new Response(new Value(plain_findstate($a->scalarval())));
+ return new Response(new Value(plain_findstate($a->scalarVal())));
}
return array(
foreach ($sno as $str) {
foreach ($str as $key => $val) {
if ($key == "curly") {
- $numCurly += $val->scalarval();
+ $numCurly += $val->scalarVal();
}
}
}
$moe = $sno["moe"];
$larry = $sno["larry"];
$curly = $sno["curly"];
- $num = $moe->scalarval() + $larry->scalarval() + $curly->scalarval();
+ $num = $moe->scalarVal() + $larry->scalarVal() + $curly->scalarVal();
return new Response(new Value($num, Value::$xmlrpcInt));
}
$first = $ar[0];
$last = $ar[$sz - 1];
- return new Response(new Value($first->scalarval() . $last->scalarval(), Value::$xmlrpcString));
+ return new Response(new Value($first->scalarVal() . $last->scalarVal(), Value::$xmlrpcString));
}
),
"function" => function ($req)
{
$sno = $req->getParam(0);
- $v = $sno->scalarval();
+ $v = $sno->scalarVal();
return new Response(new Value(
array(
$larry = $fools["larry"];
$moe = $fools["moe"];
- return new Response(new Value($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), Value::$xmlrpcInt));
+ return new Response(new Value($curly->scalarVal() + $larry->scalarVal() + $moe->scalarVal(), Value::$xmlrpcInt));
}
),
"function" => function ($req)
{
$sno = $req->getParam(0);
- $str = $sno->scalarval();
+ $str = $sno->scalarVal();
$gt = 0;
$lt = 0;
$ap = 0;
if ($req->getNumParams()) {
$p1 = $req->getParam(0);
if ($p1->kindOf() === 'scalar') {
- $errNum = (int)$p1->scalarval();
+ $errNum = (int)$p1->scalarVal();
}
}
throw new Exception("it's just a test", $errNum);
// create client
$timeout = 0;
- $url = $req->getParam(0)->scalarval();
+ $url = $req->getParam(0)->scalarVal();
// *** NB *** here we should validate the received url, using f.e. a whitelist of approved servers _and protocols_...
// fe. any url using the 'file://' protocol might be considered a hacking attempt
$client = new Client($url);
case 'followRedirects':
// requires cURL to be enabled
if ($val) {
- $client->use_curl = Client::USE_CURL_ALWAYS;
- $client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR => 3));
+ $client->setOption(Client::OPT_USE_CURL, Client::USE_CURL_ALWAYS);
+ $client->setOption(Client::OPT_EXTRA_CURL_OPTS, array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR => 3));
}
case 'Cookies':
/// @todo add support for this if needed
case 'RequestCharsetEncoding':
// allow the server to work as charset transcoder.
// NB: works best with mbstring enabled
- $client->request_charset_encoding = $val;
+ $client->setOption(Client::OPT_REQUEST_CHARSET_ENCODING, $val);
break;
case 'RequestCompression':
- $client->setRequestCompression($val);
+ $client->setOption(Client::OPT_REQUEST_COMPRESSION, $val);
break;
case 'SSLVerifyHost':
- $client->setSSLVerifyHost($val);
+ $client->setOption(Client::OPT_VERIFY_HOST, $val);
break;
case 'SSLVerifyPeer':
- $client->setSSLVerifyPeer($val);
+ $client->setOption(Client::OPT_VERIFY_PEER, $val);
break;
case 'Timeout':
$timeout = (integer)$val;
/// - as xml comments in the payload, or
/// - using std http header conventions, such as X-forwarded-for (but public servers should strip
/// X-forwarded-for anyway, unless they consider this server as trusted...)
- $reqMethod = $req->getParam(1)->scalarval();
+ $reqMethod = $req->getParam(1)->scalarVal();
$req = new Request($reqMethod);
if ($req->getNumParams() > 1) {
$pars = $req->getParam(2);
$v = new PhpXmlRpc\Value('hello world', 'base64');
output("Base64: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
-output("(value of base64 string is: '" . $v->scalarval() . "')<BR><BR>");
+output("(value of base64 string is: '" . $v->scalarVal() . "')<BR><BR>");
$v = new PhpXmlRpc\Value(
array(
for ($i = 0; $i < $num_tests; $i++) {
$vals = array();
for ($j = 0; $j < 10; $j++) {
- $valarray = array();
+ $valArray = array();
foreach ($data[$j] as $key => $val) {
$values = array();
$values[] = new Value($val[0], 'int');
$values[] = new Value($val[7], 'string');
$values[] = new Value($val[8], 'boolean');
$values[] = new Value($val[9], 'dateTime.iso8601');
- $valarray[$key] = new Value($values, 'array');
+ $valArray[$key] = new Value($values, 'array');
}
- $vals[] = new Value($valarray, 'struct');
+ $vals[] = new Value($valArray, 'struct');
}
$value = new Value($vals, 'array');
$out = $value->serialize();
// do not interfere with http compression
$c->setAcceptedCompression(false);
- //$c->debug = 1;
+ //$c->setDebug(1);
$testName = "Repeated send (small array) to $srv";
end_test($testName, 'http 10', $response);
if (function_exists('curl_init')) {
- $c->keepalive = false;
+ $c->setOption(Client::OPT_KEEPALIVE, false);
begin_test($testName, 'http 11 no keepalive');
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
end_test($testName, 'multicall', $response);
if (function_exists('gzinflate')) {
- $c->accepted_compression = array('gzip');
- $c->request_compression = 'gzip';
+ $c->setOption(Client::OPT_ACCEPTED_COMPRESSION, array('gzip'));
+ $c->setOption(Client::OPT_REQUEST_COMPRESSION, 'gzip');
begin_test($testName, 'http 10 w. compression');
$response = array();
end_test($testName, 'http 10 w. compression', $response);
if (function_exists('curl_init')) {
- $c->keepalive = false;
+ $c->setOption(Client::OPT_KEEPALIVE, false);
begin_test($testName, 'http 11 w. compression and no keepalive');
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
}
end_test($testName, 'http 11 w. compression and no keepalive', $response);
- $c->keepalive = true;
+ $c->setOption(Client::OPT_KEEPALIVE, true);
begin_test($testName, 'http 11 w. keep-alive and compression');
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
$srv = 'https://' . $args['HTTPSSERVER'] . $args['HTTPSURI'];
$c = new Client($args['HTTPSURI'], $args['HTTPSSERVER'], 443, 'https');
}
- $c->setSSLVerifyPeer(!$args['HTTPSIGNOREPEER']);
- $c->setSSLVerifyHost($args['HTTPSVERIFYHOST']);
+ $c->setOption(Client::OPT_VERIFY_PEER, !$args['HTTPSIGNOREPEER']);
+ $c->setOption(Client::OPT_VERIFY_HOST, $args['HTTPSVERIFYHOST']);
// do not interfere with http compression
- $c->setAcceptedCompression(false);
+ $c->setOption(Client::OPT_ACCEPTED_COMPRESSION, false);
//$c->debug = 1;
$testName = "Repeated send (small array) to $srv";
+ $c->setOption(Client::OPT_KEEPALIVE, false);
begin_test($testName, 'https no keep-alive');
- $c->keepalive = false;
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
$resp = $c->send($req);
}
end_test($testName, 'https no keep-alive', $response);
+ $c->setOption(Client::OPT_KEEPALIVE, true);
begin_test($testName, 'https w. keep-alive');
- $c->keepalive = true;
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
$resp = $c->send($req, 10);
end_test($testName, 'https multicall', $response);
if (function_exists('gzinflate')) {
- $c->accepted_compression = array('gzip');
- $c->request_compression = 'gzip';
+ $c->setOption(Client::OPT_ACCEPTED_COMPRESSION, array('gzip'));
+ $c->setOption(Client::OPT_REQUEST_COMPRESSION, 'gzip');
- $c->keepalive = false;
+ $c->setOption(Client::OPT_KEEPALIVE, false);
begin_test($testName, 'https w. compression and no keepalive');
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
}
end_test($testName, 'https w. compression and no keepalive', $response);
- $c->keepalive = true;
+ $c->setOption(Client::OPT_KEEPALIVE, true);
begin_test($testName, 'https w. keep-alive and compression');
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
$srv = 'https://' . $args['HTTPSSERVER'] . $args['HTTPSURI'];
$c = new Client($args['HTTPSURI'], $args['HTTPSSERVER'], 443, 'h2');
}
- $c->setSSLVerifyPeer(!$args['HTTPSIGNOREPEER']);
- $c->setSSLVerifyHost($args['HTTPSVERIFYHOST']);
+ $c->setOption(Client::OPT_VERIFY_PEER, !$args['HTTPSIGNOREPEER']);
+ $c->setOption(Client::OPT_VERIFY_HOST, $args['HTTPSVERIFYHOST']);
// do not interfere with http compression
- $c->setAcceptedCompression(false);
- //$c->debug = 1;
+ $c->setOption(Client::OPT_ACCEPTED_COMPRESSION, false);
+ //$c->setDebug(1);
$testName = "Repeated send (small array) to $srv - HTTP/2";
+ $c->setOption(Client::OPT_KEEPALIVE, false);
begin_test($testName, 'http2 no keep-alive');
- $c->keepalive = false;
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
$resp = $c->send($req);
}
end_test($testName, 'http2 no keep-alive', $response);
+ $c->setOption(Client::OPT_KEEPALIVE, true);
begin_test($testName, 'http2 w. keep-alive');
- $c->keepalive = true;
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
$resp = $c->send($req, 10);
end_test($testName, 'http2 multicall', $response);
if (function_exists('gzinflate')) {
- $c->accepted_compression = array('gzip');
- $c->request_compression = 'gzip';
+ $c->setOption(Client::OPT_ACCEPTED_COMPRESSION, array('gzip'));
+ $c->setOption(Client::OPT_REQUEST_COMPRESSION, 'gzip');
- $c->keepalive = false;
+ $c->setOption(Client::OPT_KEEPALIVE, false);
begin_test($testName, 'http2 w. compression and no keepalive');
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
}
end_test($testName, 'http2 w. compression and no keepalive', $response);
- $c->keepalive = true;
+ $c->setOption(Client::OPT_KEEPALIVE, true);
begin_test($testName, 'http2 w. keep-alive and compression');
$response = array();
for ($i = 0; $i < $num_tests; $i++) {
return;
}
+ /// @todo replace with setOption when dropping the BC layer
$this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS);
$this->client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR => 3));
$this->method = 'https';
$this->client->method = 'https';
$this->client->path = $this->args['HTTPSURI'];
+ /// @todo replace with setOptions when dropping the BC layer
$this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
$this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
$this->client->setSSLVersion($this->args['SSLVERSION']);
$this->method = 'https';
$this->client->method = 'https';
$this->client->path = $this->args['HTTPSURI'];
+ /// @todo replace with setOptions when dropping the BC layer
$this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
$this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
$this->client->setSSLVersion($this->args['SSLVERSION']);
return;
}
- $this->client->server = $this->args['HTTPSSERVER'];
$this->method = 'https';
$this->client->method = 'https';
- $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
+ $this->client->server = $this->args['HTTPSSERVER'];
$this->client->path = $this->args['HTTPSURI'];
+ /// @todo replace with setOptions when dropping the BC layer
+ $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
$this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
$this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
$this->client->setSSLVersion($this->args['SSLVERSION']);
return;
}
- $this->client->server = $this->args['HTTPSSERVER'];
$this->method = 'h2';
$this->client->method = 'h2';
+ $this->client->server = $this->args['HTTPSSERVER'];
$this->client->path = $this->args['HTTPSURI'];
+ /// @todo replace with setOptions when dropping the BC layer
$this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
$this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
$this->client->setSSLVersion($this->args['SSLVERSION']);