Esempio n. 1
4
 public function __call($method, $args = array())
 {
     $params = array();
     foreach ($args as $arg) {
         // argument already encoded, perhaps via encodeBinary
         if ($arg instanceof PhpXmlRpc\Value) {
             $params[] = $arg;
             continue;
         }
         // serialize all objects first
         if (is_object($arg)) {
             $arg = serialize($arg);
         }
         $params[] = $this->encoder->encode($arg);
     }
     $req = new PhpXmlRpc\Request($method, $params);
     $result = $this->client->send($req);
     if ($result === 0) {
         throw new Eventum_RPC_Exception($this->client->errstr);
     }
     if (is_object($result) && $result->faultCode()) {
         throw new Eventum_RPC_Exception($result->faultString());
     }
     $value = $this->encoder->decode($result->value());
     return $value;
 }
Esempio n. 2
0
function getComments($req)
{
    $err = "";
    $ra = array();
    $encoder = new PhpXmlRpc\Encoder();
    $msgID = $encoder->decode($req->getParam(0));
    $dbh = dba_open("/tmp/comments.db", "r", "db2");
    if ($dbh) {
        $countID = "{$msgID}_count";
        if (dba_exists($countID, $dbh)) {
            $count = dba_fetch($countID, $dbh);
            for ($i = 0; $i < $count; $i++) {
                $name = dba_fetch("{$msgID}_name_{$i}", $dbh);
                $comment = dba_fetch("{$msgID}_comment_{$i}", $dbh);
                // push a new struct onto the return array
                $ra[] = array("name" => $name, "comment" => $comment);
            }
        }
    }
    // if we generated an error, create an error return response
    if ($err) {
        return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
    } else {
        // otherwise, we create the right response
        return new PhpXmlRpc\Response($encoder->encode($ra));
    }
}
Esempio n. 3
0
 /**
  * Translates any method call to an xmlrpc call.
  *
  * @author Toth Istvan
  *
  * @param string $name remote function name. Will be prefixed
  * @param array $arguments
  *
  * @return mixed
  *
  * @throws Exception
  */
 function __call($name, $arguments)
 {
     $encoder = new PhpXmlRpc\Encoder();
     $valueArray = array();
     foreach ($arguments as $parameter) {
         $valueArray[] = $encoder->encode($parameter);
     }
     // just in case this was set to something else
     $this->client->return_type = 'phpvals';
     $resp = $this->client->send(new PhpXmlRpc\Request($this->prefix . $name, $valueArray));
     if ($resp->faultCode()) {
         throw new Exception($resp->faultString(), $resp->faultCode());
     } else {
         return $resp->value();
     }
 }
Esempio n. 4
0
/**
 * Forward an xmlrpc request to another server, and return to client the response received.
 *
 * DO NOT RUN AS IS IN PRODUCTION - this is an open relay !!!
 *
 * @param PhpXmlRpc\Request $req (see method docs below for a description of the expected parameters)
 *
 * @return PhpXmlRpc\Response
 */
function forward_request($req)
{
    $encoder = new \PhpXmlRpc\Encoder();
    // create client
    $timeout = 0;
    $url = $encoder->decode($req->getParam(0));
    $client = new PhpXmlRpc\Client($url);
    if ($req->getNumParams() > 3) {
        // we have to set some options onto the client.
        // Note that if we do not untaint the received values, warnings might be generated...
        $options = $encoder->decode($req->getParam(3));
        foreach ($options as $key => $val) {
            switch ($key) {
                case 'Cookie':
                    break;
                case 'Credentials':
                    break;
                case 'RequestCompression':
                    $client->setRequestCompression($val);
                    break;
                case 'SSLVerifyHost':
                    $client->setSSLVerifyHost($val);
                    break;
                case 'SSLVerifyPeer':
                    $client->setSSLVerifyPeer($val);
                    break;
                case 'Timeout':
                    $timeout = (int) $val;
                    break;
            }
            // switch
        }
    }
    // build call for remote server
    /// @todo find a way to forward client info (such as IP) to server, either
    /// - as xml comments in the payload, or
    /// - using std http header conventions, such as X-forwarded-for...
    $reqMethod = $encoder->decode($req->getParam(1));
    $pars = $req->getParam(2);
    $req = new PhpXmlRpc\Request($reqMethod);
    foreach ($pars as $par) {
        $req->addParam($par);
    }
    // add debug info into response we give back to caller
    PhpXmlRpc\Server::xmlrpc_debugmsg("Sending to server {$url} the payload: " . $req->serialize());
    return $client->send($req, $timeout);
}
Esempio n. 5
0
<html>
<head><title>xmlrpc - Getstatename demo</title></head>
<body>
<h1>Getstatename demo</h1>

<h2>Send a U.S. state number to the server and get back the state name</h2>

<h3>The code demonstrates usage of automatic encoding/decoding of php variables into xmlrpc values</h3>
<?php 
include_once __DIR__ . "/../../src/Autoloader.php";
PhpXmlRpc\Autoloader::register();
if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
    $stateNo = (int) $_POST["stateno"];
    $encoder = new PhpXmlRpc\Encoder();
    $req = new PhpXmlRpc\Request('examples.getStateName', array($encoder->encode($stateNo)));
    print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n";
    $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
    $client->setDebug(1);
    $r = $client->send($req);
    if (!$r->faultCode()) {
        $v = $r->value();
        print "<br/>State number <b>" . $stateNo . "</b> is <b>" . htmlspecialchars($encoder->decode($v)) . "</b><br/>";
    } else {
        print "An error occurred: ";
        print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
    }
} else {
    $stateNo = "";
}
print "<form action=\"getstatename.php\" method=\"POST\">\n<input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>\n<p>Enter a state number to query its name</p>";
?>
Esempio n. 6
0
             }
             echo "</form></td>\n";
             echo "<td{$class}><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">" . "<input type=\"hidden\" name=\"host\" value=\"" . htmlspecialchars($host, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"port\" value=\"" . htmlspecialchars($port, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"path\" value=\"" . htmlspecialchars($path, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"id\" value=\"" . htmlspecialchars($id, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"debug\" value=\"{$debug}\" />" . "<input type=\"hidden\" name=\"username\" value=\"" . htmlspecialchars($username, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"password\" value=\"" . htmlspecialchars($password, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"authtype\" value=\"{$authtype}\" />" . "<input type=\"hidden\" name=\"verifyhost\" value=\"{$verifyhost}\" />" . "<input type=\"hidden\" name=\"verifypeer\" value=\"{$verifypeer}\" />" . "<input type=\"hidden\" name=\"cainfo\" value=\"" . htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"proxy\" value=\"" . htmlspecialchars($proxy, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"proxyuser\" value=\"" . htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"proxypwd\" value=\"" . htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"responsecompression\" value=\"{$responsecompression}\" />" . "<input type=\"hidden\" name=\"requestcompression\" value=\"{$requestcompression}\" />" . "<input type=\"hidden\" name=\"clientcookies\" value=\"" . htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"protocol\" value=\"{$protocol}\" />" . "<input type=\"hidden\" name=\"timeout\" value=\"" . htmlspecialchars($timeout, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"method\" value=\"" . htmlspecialchars($method, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"methodsig\" value=\"" . $i . "\" />" . "<input type=\"hidden\" name=\"methodpayload\" value=\"" . htmlspecialchars($payload, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"altmethodpayload\" value=\"" . htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset) . "\" />" . "<input type=\"hidden\" name=\"wstype\" value=\"{$wstype}\" />" . "<input type=\"hidden\" name=\"run\" value=\"now\" />" . "<input type=\"hidden\" name=\"action\" value=\"wrap\" />" . "<input type=\"submit\" value=\"Generate method call stub code\" />";
             echo "</form></td></tr>\n";
         }
     }
     echo "</tbody>\n</table>";
     break;
 case 'wrap':
     $r1 = $resp[0]->value();
     $r2 = $resp[1]->value();
     if ($r2->kindOf() != "array" || $r2->count() <= $methodsig) {
         echo "Error: signature unknown\n";
     } else {
         $mdesc = $r1->scalarval();
         $encoder = new PhpXmlRpc\Encoder();
         $msig = $encoder->decode($r2);
         $msig = $msig[$methodsig];
         $proto = $protocol == 2 ? 'https' : $protocol == 1 ? 'http11' : '';
         if ($proxy == '' && $username == '' && !$requestcompression && !$responsecompression && $clientcookies == '') {
             $opts = 1;
             // simple client copy in stub code
         } else {
             $opts = 0;
             // complete client copy in stub code
         }
         if ($wstype == 1) {
             $prefix = 'jsonrpc';
         } else {
             $prefix = 'xmlrpc';
         }
Esempio n. 7
0
function i_whichToolkit($req)
{
    global $SERVER_SOFTWARE;
    $ret = array("toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/", "toolkitName" => PhpXmlRpc\PhpXmlRpc::$xmlrpcName, "toolkitVersion" => PhpXmlRpc\PhpXmlRpc::$xmlrpcVersion, "toolkitOperatingSystem" => isset($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE']);
    $encoder = new PhpXmlRpc\Encoder();
    return new PhpXmlRpc\Response($encoder->encode($ret));
}
 public function testServerWrappedFunction()
 {
     $m = new xmlrpcmsg('tests.getStateName.2', array(new xmlrpcval(23, 'int')));
     $v = $this->send($m);
     $this->assertEquals('Michigan', $v->scalarval());
     // this generates an exception in the function which was wrapped, which is by default wrapped in a known error response
     $m = new xmlrpcmsg('tests.getStateName.2', array(new xmlrpcval(0, 'int')));
     $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
     // check if the generated function dispatch map is fine, by checking if the server registered it
     $m = new xmlrpcmsg('system.methodSignature', array(new xmlrpcval('tests.getStateName.2')));
     $v = $this->send($m);
     $encoder = new \PhpXmlRpc\Encoder();
     $this->assertEquals(array(array('string', 'int')), $encoder->decode($v));
 }
Esempio n. 9
0
<html>
<head><title>xmlrpc - Which toolkit demo</title></head>
<body>
<h1>Which toolkit demo</h1>
<h2>Query server for toolkit information</h2>
<h3>The code demonstrates usage of the PhpXmlRpc\Encoder class</h3>
<?php 
include_once __DIR__ . "/../../src/Autoloader.php";
PhpXmlRpc\Autoloader::register();
$req = new PhpXmlRpc\Request('interopEchoTests.whichToolkit', array());
$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
$resp = $client->send($req);
if (!$resp->faultCode()) {
    $encoder = new PhpXmlRpc\Encoder();
    $value = $encoder->decode($resp->value());
    print "<pre>";
    print "name: " . htmlspecialchars($value["toolkitName"]) . "\n";
    print "version: " . htmlspecialchars($value["toolkitVersion"]) . "\n";
    print "docs: " . htmlspecialchars($value["toolkitDocsUrl"]) . "\n";
    print "os: " . htmlspecialchars($value["toolkitOperatingSystem"]) . "\n";
    print "</pre>";
} else {
    print "An error occurred: ";
    print "Code: " . htmlspecialchars($resp->faultCode()) . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n";
}
?>
</body>
</html>