public function query($method, $parameters = null)
 {
     $request = xmlrpc_encode_request($method, $parameters);
     $headers = array("Content-type: text/xml", "Content-length: " . strlen($request));
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $this->url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
     if ($this->timeout) {
         curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
     }
     $rawResponse = curl_exec($curl);
     $curlErrno = curl_errno($curl);
     $curlError = curl_error($curl);
     curl_close($curl);
     if ($curlErrno) {
         throw new NetworkException($curlError, $curlErrno);
     }
     $result = xmlrpc_decode($rawResponse);
     if (xmlrpc_is_fault($result)) {
         throw new NetworkException($result['faultString'], $result['faultCode']);
     }
     return $result;
 }
 function callRemote($method)
 {
     // Curl is required so generate a fault if curl functions cannot be found.
     if (!$this->curl) {
         return array('faultCode' => -1, 'faultString' => 'Curl functions are unavailable.');
     }
     // The first argument will always be the method name while all remaining arguments need
     // to be passed along with the call.
     $args = func_get_args();
     array_shift($args);
     if ($this->xmlrpc) {
         // If php has xmlrpc support use the built in functions.
         $request = xmlrpc_encode_request($method, $args);
         $result = $this->__xmlrpc_call($request);
         $decodedResult = xmlrpc_decode($result);
     } else {
         // If no xmlrpc support is found, use the phpxmlrpc library. This involves containing
         // all variables inside the xmlrpcval class.
         $encapArgs = array();
         foreach ($args as $arg) {
             $encapArgs[] = $this->__phpxmlrpc_encapsulate($arg);
         }
         $msg = new xmlrpcmsg($method, $encapArgs);
         $client = new xmlrpc_client($this->url);
         $client->verifypeer = false;
         $result = $client->send($msg);
         if ($result->errno) {
             $decodedResult = array('faultCode' => $result->errno, 'faultString' => $result->errstr);
         } else {
             $decodedResult = php_xmlrpc_decode($result->value());
         }
     }
     return $decodedResult;
 }
Exemple #3
0
function xmlrpc_decode($xmlrpc_val)
{
    $kind = $xmlrpc_val->kindOf();
    if ($kind == "scalar") {
        return $xmlrpc_val->scalarval();
    } else {
        if ($kind == "array") {
            $size = $xmlrpc_val->arraysize();
            $arr = array();
            for ($i = 0; $i < $size; $i++) {
                $arr[] = xmlrpc_decode($xmlrpc_val->arraymem($i));
            }
            return $arr;
        } else {
            if ($kind == "struct") {
                $xmlrpc_val->structreset();
                $arr = array();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $arr[$key] = xmlrpc_decode($value);
                }
                return $arr;
            }
        }
    }
}
Exemple #4
0
 /**
  * send xml data to OpenNebula RPC server
  * @param $method
  * @param $argument
  */
 function rpc_send($method, $argument)
 {
     //Using the XML-RPC extension to format the XML package
     $request = xmlrpc_encode_request($method, $argument);
     $req = curl_init($this->service_url);
     //Using the cURL extension to send it off,  first creating a custom header block
     $headers = array();
     array_push($headers, "Content-Type: text/xml");
     array_push($headers, "Content-Length: " . strlen($request));
     array_push($headers, "\r\n");
     //URL to post to
     curl_setopt($req, CURLOPT_URL, $this->service_url);
     //Setting options for a secure SSL based xmlrpc server
     curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($req, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($req, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($req, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($req, CURLOPT_POSTFIELDS, $request);
     //Finally run
     $response = curl_exec($req);
     //Close the cURL connection
     curl_close($req);
     //Decoding the response to be displayed
     $result = xmlrpc_decode($response);
     return $result;
 }
Exemple #5
0
function getcomments($m)
{
    $err = '';
    $ra = array();
    // get the first param
    $msgID = xmlrpc_decode($m->getParam(0));
    $countID = "{$msgID}_count";
    $sql = 'SELECT * FROM phpgw_discuss WHERE msg_id=' . $msgID;
    $GLOBALS['phpgw']->db->query($sql, __LINE__, __FILE__);
    $count = $GLOBALS['phpgw']->db->num_rows();
    while ($data = $GLOBALS['phpgw']->db->next_record()) {
        $name = $GLOBALS['phpgw']->db->f('name');
        $comment = $GLOBALS['phpgw']->db->f('comment');
        // push a new struct onto the return array
        $ra[] = CreateObject('phpgwapi.xmlrpcval', array('name' => CreateObject('phpgwapi.xmlrpcval', $name), 'comment' => CreateObject('phpgwapi.xmlrpcval', $comment)), 'struct');
    }
    // if we generated an error, create an error return response
    if ($err) {
        return CreateObject('phpgwapi.xmlrpcresp', '', $GLOBALS['xmlrpcerruser'], $err);
    } else {
        // otherwise, we create the right response
        // with the state name
        return CreateObject('phpgwapi.xmlrpcresp', CreateObject('phpgwapi.xmlrpcval', $ra, 'array'));
    }
}
Exemple #6
0
 /**
  * Ping Blog Update Services
  *
  * @param array $options are name, website, url
  */
 function ping($options = array())
 {
     $type = 'REST';
     if (function_exists('xmlrpc_encode_request')) {
         $type = 'XML-RPC';
     }
     switch ($type) {
         case 'REST':
             // construct parameters
             $params = array('name' => $options['name'], 'url' => $options['url']);
             $params = array_map('rawurlencode', $params);
             $paramString = http_build_query($params);
             // Rest Update Ping Services
             foreach ($this->__services['rest'] as $serviceApi) {
                 $requestUrl = $serviceApi . '?' . $paramString;
                 $response = file_get_contents($requestUrl);
             }
             break;
         case 'XML-RPC':
             // construct parameters
             $params = array($options['name'], $options['website'], $options['url'], $options['feed']);
             $request = xmlrpc_encode_request("weblogUpdates.extendedPing", $params);
             $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
             foreach ($this->__services['rpc'] as $endPoint) {
                 // Ping the services
                 $file = file_get_contents($endPoint, false, $context);
                 $response = xmlrpc_decode($file);
                 //no need to process the response
             }
             break;
     }
 }
function getcomments($m)
{
    global $xmlrpcerruser;
    $err = "";
    $ra = array();
    // get the first param
    if (XMLRPC_EPI_ENABLED == '1') {
        $msgID = xmlrpc_decode($m->getParam(0));
    } else {
        $msgID = php_xmlrpc_decode($m->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 xmlrpcresp(0, $xmlrpcerruser, $err);
    } else {
        // otherwise, we create the right response
        // with the state name
        return new xmlrpcresp(php_xmlrpc_encode($ra));
    }
}
Exemple #8
0
 private function _request($request)
 {
     $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: text/xml', 'content' => $request)));
     $response = file_get_contents('https://api.loopia.se/RPCSERV', false, $context);
     $response = xmlrpc_decode($response);
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function parse($xmlString, &$isFault)
 {
     $result = xmlrpc_decode($xmlString, 'UTF-8');
     $isFault = false;
     $toBeVisited = [&$result];
     while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) {
         $type = gettype($value);
         if ($type === 'object') {
             $xmlRpcType = $value->{'xmlrpc_type'};
             if ($xmlRpcType === 'datetime') {
                 $value = DateTime::createFromFormat('Ymd\\TH:i:s', $value->scalar, isset($timezone) ? $timezone : ($timezone = new DateTimeZone('UTC')));
             } elseif ($xmlRpcType === 'base64') {
                 if ($value->scalar !== '') {
                     $value = Base64::serialize($value->scalar);
                 } else {
                     $value = null;
                 }
             }
         } elseif ($type === 'array') {
             foreach ($value as &$element) {
                 $toBeVisited[] =& $element;
             }
         }
         array_shift($toBeVisited);
     }
     if (is_array($result)) {
         reset($result);
         $isFault = xmlrpc_is_fault($result);
     }
     return $result;
 }
Exemple #10
0
 function onStartNoticeSave($notice)
 {
     $args = $this->testArgs($notice);
     common_debug("Blogspamnet args = " . print_r($args, TRUE));
     $request = xmlrpc_encode_request('testComment', array($args));
     $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml\r\n" . "User-Agent: " . $this->userAgent(), 'content' => $request)));
     $file = file_get_contents($this->baseUrl, false, $context);
     $response = xmlrpc_decode($file);
     if (xmlrpc_is_fault($response)) {
         throw new ServerException("{$response['faultString']} ({$response['faultCode']})", 500);
     } else {
         common_debug("Blogspamnet results = " . $response);
         if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
             throw new ServerException(sprintf(_("Error from %s: %s"), $this->baseUrl, $match[2]), 500);
         } else {
             if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
                 throw new ClientException(sprintf(_("Spam checker results: %s"), $match[2]), 400);
             } else {
                 if (preg_match('/^OK$/', $response)) {
                     // don't do anything
                 } else {
                     throw new ServerException(sprintf(_("Unexpected response from %s: %s"), $this->baseUrl, $response), 500);
                 }
             }
         }
     }
     return true;
 }
 function xmlrpcCall($url, $method, $params)
 {
     // xmlrpc encode parameters
     for ($i = 0; $i < count($params); $i++) {
         if (get_class($params[$i]) != 'xmlrpcval') {
             $params[$i] = xmlrpc_encode($params[$i]);
         }
     }
     // send request
     $message = new xmlrpcmsg($method, $params);
     debug("XML-RPC message", $message->serialize());
     $addr = parse_url($url);
     $client = new xmlrpc_client($url, $addr['host'], $addr['port']);
     //if($debug)
     //  $client->setDebug(1);
     debug("XML-RPC", "call to " . $url);
     $response = $client->send($message);
     // process response
     debug("XML-RPC Response", $response->serialize());
     if (!$response) {
         debug("No response", "probably host is unreachable");
     } elseif ($response->faultCode() != 0) {
         // there was an error
         debug("Error response: ", $response->faultCode() . "  " . $response->faultString());
     } else {
         $retval = $response->value();
         if ($retval) {
             $retval = xmlrpc_decode($retval);
         }
         debug("Response", $retval);
         return $retval;
     }
     return NULL;
 }
 function onStartNoticeSave($notice)
 {
     $args = $this->testArgs($notice);
     common_debug("Blogspamnet args = " . print_r($args, TRUE));
     $requestBody = xmlrpc_encode_request('testComment', array($args));
     $request = new HTTPClient($this->baseUrl, HTTPClient::METHOD_POST);
     $request->setHeader('Content-Type', 'text/xml');
     $request->setBody($requestBody);
     $httpResponse = $request->send();
     $response = xmlrpc_decode($httpResponse->getBody());
     if (xmlrpc_is_fault($response)) {
         throw new ServerException("{$response['faultString']} ({$response['faultCode']})", 500);
     } else {
         common_debug("Blogspamnet results = " . $response);
         if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
             throw new ServerException(sprintf(_("Error from %s: %s"), $this->baseUrl, $match[2]), 500);
         } else {
             if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
                 throw new ClientException(sprintf(_("Spam checker results: %s"), $match[2]), 400);
             } else {
                 if (preg_match('/^OK$/', $response)) {
                     // don't do anything
                 } else {
                     throw new ServerException(sprintf(_("Unexpected response from %s: %s"), $this->baseUrl, $response), 500);
                 }
             }
         }
     }
     return true;
 }
 public static function get_response($server, $request, &$error = null, $fresh = false)
 {
     $ch = vpl_jailserver_manager::get_curl($server, $request, $fresh);
     $raw_response = curl_exec($ch);
     if ($raw_response === false) {
         $error = 'request failed: ' . s(curl_error($ch));
         curl_close($ch);
         return false;
     } else {
         curl_close($ch);
         $error = '';
         $response = xmlrpc_decode($raw_response, "UTF-8");
         if (is_array($response)) {
             if (xmlrpc_is_fault($response)) {
                 $error = 'xmlrpc is fault: ' . s($response["faultString"]);
             } else {
                 return $response;
             }
         } else {
             $error = 'http error ' . s(strip_tags($raw_response));
             $fail = true;
         }
         return false;
     }
 }
 private function sendRequest($request)
 {
     $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request, 'timeout' => $this->timeout)));
     $status = @file_get_contents("http://" . $this->host . ":" . $this->port . "/RPC2", false, $context);
     $retval = xmlrpc_decode($status);
     return $retval;
 }
Exemple #15
0
 /**
  * Sends an XML RPC request to the XML RPC server
  * @param $methodName string Name of the XML RPC method to call
  * @param $params array Array of parameters to pass to the XML RPC method. Type is detected automatically. For a struct just encode an array within $params.
  * @return array Array of returned parameters
  */
 public function send($methodName, $params)
 {
     $request = xmlrpc_encode_request($methodName, $params);
     $response = $this->sendRequest($request);
     $response = xmlrpc_decode(trim($response));
     //Without the trim function returns null
     return $response;
 }
Exemple #16
0
 /**
  * Call server RPC method
  * 
  * @param string method name
  * @param array arguments
  * @return string
  */
 function __call($function, $argv)
 {
     $request = xmlrpc_encode_request($function, $argv);
     $headers = array('Content-Type: text/xml', 'Content-Length: ' . strlen($request) . "\r\n\r\n" . $request);
     $this->SetHeaders($headers);
     $this->Fetch($this->Host, array(), true);
     return xmlrpc_decode($this->Result);
 }
Exemple #17
0
function do_xmlrpc($request)
{
    global $rpc_connect;
    $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
    $file = file_get_contents($rpc_connect, false, $context);
    $file = str_replace("i8", "double", $file);
    return xmlrpc_decode($file);
}
 public function request($function, array $parameters = null)
 {
     $request = \xmlrpc_encode_request($function, $parameters);
     $context = \stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
     $file = \file_get_contents($this->imgSeekUrl . '/RPC', false, $context);
     $response = \xmlrpc_decode($file);
     return $response;
 }
Exemple #19
0
 public function call($method, $params = null)
 {
     $postData = xmlrpc_encode_request($method, $params);
     $httpHeader = array('Content-Type: text/xml;charset=UTF-8');
     $curlResult = CURL::post($this->url, $postData, $httpHeader);
     if ($curlResult === 'Error') {
         return [];
     }
     return xmlrpc_decode($curlResult);
 }
Exemple #20
0
 /**
  * Execute the request. Populates result field.
  */
 public function execute()
 {
     $rr = new RemoteRequest($this->url, 'POST');
     $rr->add_header('Content-Type: text/xml;charset=utf-8');
     $rr->set_body($this->request_body);
     // should throw an error on failure
     $rr->execute();
     // in that case, we should never get here
     $this->result = xmlrpc_decode($rr->get_response_body());
 }
 public static function sendPingback($endpoint, $source, $target)
 {
     $payload = xmlrpc_encode_request('pingback.ping', array($source, $target));
     $response = static::_post($endpoint, $payload, array('Content-type: application/xml'));
     if (is_array(xmlrpc_decode($response))) {
         return false;
     } elseif (is_string($response) && !empty($response)) {
         return true;
     }
 }
Exemple #22
0
function ping_broadcast_notice($notice)
{
    if ($notice->is_local != Notice::LOCAL_PUBLIC && $notice->is_local != Notice::LOCAL_NONPUBLIC) {
        return true;
    }
    # Array of servers, URL => type
    $notify = common_config('ping', 'notify');
    $profile = $notice->getProfile();
    $tags = ping_notice_tags($notice);
    foreach ($notify as $notify_url => $type) {
        switch ($type) {
            case 'xmlrpc':
            case 'extended':
                $req = xmlrpc_encode_request('weblogUpdates.ping', array($profile->nickname, common_local_url('showstream', array('nickname' => $profile->nickname)), common_local_url('shownotice', array('notice' => $notice->id)), common_local_url('userrss', array('nickname' => $profile->nickname)), $tags));
                $request = HTTPClient::start();
                $request->setConfig('connect_timeout', common_config('ping', 'timeout'));
                $request->setConfig('timeout', common_config('ping', 'timeout'));
                try {
                    $httpResponse = $request->post($notify_url, array('Content-Type: text/xml'), $req);
                } catch (Exception $e) {
                    common_log(LOG_ERR, "Exception pinging {$notify_url}: " . $e->getMessage());
                    continue;
                }
                if (!$httpResponse || mb_strlen($httpResponse->getBody()) == 0) {
                    common_log(LOG_WARNING, "XML-RPC empty results for ping ({$notify_url}, {$notice->id}) ");
                    continue;
                }
                $response = xmlrpc_decode($httpResponse->getBody());
                if (is_array($response) && xmlrpc_is_fault($response)) {
                    common_log(LOG_WARNING, "XML-RPC error for ping ({$notify_url}, {$notice->id}) " . "{$response['faultString']} ({$response['faultCode']})");
                } else {
                    common_log(LOG_INFO, "Ping success for {$notify_url} {$notice->id}");
                }
                break;
            case 'get':
            case 'post':
                $args = array('name' => $profile->nickname, 'url' => common_local_url('showstream', array('nickname' => $profile->nickname)), 'changesURL' => common_local_url('userrss', array('nickname' => $profile->nickname)));
                $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
                if ($type === 'get') {
                    $result = $fetcher->get($notify_url . '?' . http_build_query($args), array('User-Agent: StatusNet/' . STATUSNET_VERSION));
                } else {
                    $result = $fetcher->post($notify_url, http_build_query($args), array('User-Agent: StatusNet/' . STATUSNET_VERSION));
                }
                if ($result->status != '200') {
                    common_log(LOG_WARNING, "Ping error for '{$notify_url}' ({$notice->id}): " . "{$result->body}");
                } else {
                    common_log(LOG_INFO, "Ping success for '{$notify_url}' ({$notice->id}): " . "'{$result->body}'");
                }
                break;
            default:
                common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
        }
    }
    return true;
}
Exemple #23
0
/**
 * Get the remote machine's SSL Cert
 *
 * @param  string  $uri     The URI of a file on the remote computer, including
 *                          its http:// or https:// prefix
 * @return string           A PEM formatted SSL Certificate.
 */
function mnet_get_public_key($uri, $application = null)
{
    global $CFG, $MNET;
    // The key may be cached in the mnet_set_public_key function...
    // check this first
    $key = mnet_set_public_key($uri);
    if ($key != false) {
        return $key;
    }
    if (empty($application)) {
        $application = get_record('mnet_application', 'name', 'moodle');
    }
    $rq = xmlrpc_encode_request('system/keyswap', array($CFG->wwwroot, $MNET->public_key, $application->name), array("encoding" => "utf-8"));
    $ch = curl_init($uri . $application->xmlrpc_server_url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Moodle');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $rq);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml charset=UTF-8"));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $res = xmlrpc_decode(curl_exec($ch));
    // check for curl errors
    $curlerrno = curl_errno($ch);
    if ($curlerrno != 0) {
        debugging("Request for {$uri} failed with curl error {$curlerrno}");
    }
    // check HTTP error code
    $info = curl_getinfo($ch);
    if (!empty($info['http_code']) and $info['http_code'] != 200) {
        debugging("Request for {$uri} failed with HTTP code " . $info['http_code']);
    }
    curl_close($ch);
    if (!is_array($res)) {
        // ! error
        $public_certificate = $res;
        $credentials = array();
        if (strlen(trim($public_certificate))) {
            $credentials = openssl_x509_parse($public_certificate);
            $host = $credentials['subject']['CN'];
            if (strpos($uri, $host) !== false) {
                mnet_set_public_key($uri, $public_certificate);
                return $public_certificate;
            } else {
                debugging("Request for {$uri} returned public key for different URI - {$host}");
            }
        } else {
            debugging("Request for {$uri} returned empty response");
        }
    } else {
        debugging("Request for {$uri} returned unexpected result");
    }
    return false;
}
Exemple #24
0
 /**
  * Run an XMLRPC command. Name should be a query name and params an array of parameters, eg:
  * $this->raw("checkAuthentication", ["adam", "qwerty"]);
  * If successful returns back an array of useful information.
  *
  * Note that $params["id"] is reserved for query ID, you may set it to something if you wish.
  * If you do, the same ID will be passed back with the reply from Anope.
  *
  * @param $name
  * @param $params
  * @return array|null
  */
 public function run($name, $params)
 {
     $xmlquery = xmlrpc_encode_request($name, $params);
     $context = stream_context_create(["http" => ["method" => "POST", "header" => "Content-Type: text/xml", "content" => $xmlquery]]);
     $inbuf = file_get_contents($this->host, false, $context);
     $response = xmlrpc_decode($inbuf);
     if ($response) {
         return $response;
     }
     return null;
 }
 function normalValidate($command, $la, $code)
 {
     $request = xmlrpc_encode_request("validate", array($command, $la, AV_LOGIN, AV_PASSWD, $code));
     $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
     $file = file_get_contents(AV_RPC_URL, false, $context);
     $response = xmlrpc_decode($file);
     if (xmlrpc_is_fault($response)) {
         return false;
     }
     return $response['status'] == "OK";
 }
 /**
  * Calls the method on the server with the given parameters
  *
  * @param  string $method       The method name
  * @param  array  $parameters   The argument parameters for the method
  *
  * @return string
  */
 protected function call($method, array $parameters = array())
 {
     $request = xmlrpc_encode_request($method, $parameters);
     $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
     $contents = $this->fileRetriever->retrieveContents($this->getDSN(), $context);
     $response = xmlrpc_decode($contents);
     if ($response && is_array($response) && xmlrpc_is_fault($response)) {
         trigger_error("xmlrpc: {$response['faultString']} ({$response['faultCode']})");
     }
     return $response;
 }
 public function __call($method, $params)
 {
     if ($this->namespace) {
         $method = $this->namespace . '.' . $method;
     }
     $this->request->setRawPostData(xmlrpc_encode_request($method, $params));
     $response = $this->request->send();
     if ($response->getResponseCode() != 200) {
         throw new Exception($response->getBody(), $response->getResponseCode());
     }
     return xmlrpc_decode($response->getBody(), 'utf-8');
 }
Exemple #28
0
 public function execute($server)
 {
     $file = file_get_contents($server, false, $this->context);
     if ($file == false) {
         throw new Exception("Server didn't send an answer!");
     }
     $response = xmlrpc_decode($file);
     if (is_array($response) && xmlrpc_is_fault($response)) {
         throw new XMLRPCException($response['faultString'], $response['faultCode']);
     }
     return $response;
 }
 protected function commit_rpc()
 {
     $request = xmlrpc_encode_request($this->method, $this->parms);
     $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml; charset=utf-8\r\n" . "User-Agent: XMLRPC::Client JorgeRPCclient", 'content' => $request)));
     $file = file_get_contents("http://{$this->rpc_server}" . ":" . "{$this->rpc_port}", false, $context);
     $response = xmlrpc_decode($file, "utf8");
     if (xmlrpc_is_fault($response)) {
         throw new Exception("XML-RPC Call Failed. Unrecoverable condition", 0);
     } else {
         return $response;
     }
 }
function do_xmlrpc($request)
{
    global $rpc_connect;
    $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
    if ($file = @file_get_contents($rpc_connect, false, $context)) {
        $file = str_replace("i8", "double", $file);
        $file = utf8_encode($file);
        return xmlrpc_decode($file);
    } else {
        die("<h1>Cannot connect to rtorrent :(</h1>");
    }
}