Example #1
0
 $mname = $v->arraymem($i);
 print "<H3>" . $mname->scalarval() . "</H3>\n";
 $f = new xmlrpcmsg('system.methodHelp');
 $f->addParam(new xmlrpcval($mname->scalarval(), "string"));
 $w = rpc_call($c, $f);
 if ($w) {
     $txt = $w->scalarval();
     if ($txt != "") {
         print "<H4>Documentation</H4><P>{$txt}</P>\n";
     } else {
         print "<P>No documentation available.</P>\n";
     }
 }
 $f = new xmlrpcmsg('system.methodSignature');
 $f->addParam(new xmlrpcval($mname->scalarval(), "string"));
 $w = rpc_call($c, $f);
 if ($w) {
     print "<H4>Signature</H4><P>\n";
     if ($w->kindOf() == "array") {
         for ($j = 0; $j < $w->arraysize(); $j++) {
             $x = $w->arraymem($j);
             $ret = $x->arraymem(0);
             print "<CODE>" . $ret->scalarval() . " " . $mname->scalarval() . "(";
             if ($x->arraysize() > 1) {
                 for ($k = 1; $k < $x->arraysize(); $k++) {
                     $y = $x->arraymem($k);
                     print $y->scalarval();
                     if ($k < $x->arraysize() - 1) {
                         print ", ";
                     }
                 }
Example #2
0
function start_standalone_http_server($port = NULL, $addr = NULL)
{
    if (!$addr) {
        $addr = '127.0.0.1';
    } else {
        if (!is_ipaddress($addr)) {
            return "invalid address\n";
        }
    }
    if (!$port) {
        $port = 8000;
    } else {
        if (!preg_match('/\\d+/', $port)) {
            return "invalid port\n";
        }
    }
    $socket = stream_socket_server("tcp://{$addr}:{$port}", $errno, $errstr);
    if (!$socket) {
        return $errstr . ' (' . $errno . ')' . PHP_EOL;
    } else {
        $defaults = array('Content-Type' => 'text/html', 'Server' => 'PHP ' . phpversion());
        while ($conn = stream_socket_accept($socket, -1)) {
            $request = '';
            $ct = 0;
            // The ronin-rpc engine may not be the most compliant web client
            // while (substr($request, -4) !== "\r\n\r\n") {
            while (!preg_match('/\\r\\n\\r\\n/m', $request)) {
                $request .= fread($conn, 1024);
            }
            // We expect only one query parameter and we do not care what its called
            if (!preg_match('|[A-Z]+ /[^\\?]*(?:([^=]+)=([^\\s]+))? HTTP/\\d.\\d|', $request, $matches)) {
                print "recieved an invalid query string ({$request})\n";
                continue;
            }
            $request = urldecode($matches[2]);
            $response = rpc_serialize(rpc_call(rpc_deserialize($request)));
            $body = "<!-- <rpc:response>{$response}</rpc:response> -->";
            $header = "Content-Type: text/html\r\n";
            $header .= "Server: PHP " . phpversion() . "\r\n";
            $header .= "Content-Length: " . strlen($body) . "\r\n";
            fwrite($conn, implode("\r\n", array('HTTP/1.1 200', $header, $body)));
            fclose($conn);
        }
        fclose($socket);
    }
}