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;
 }
 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;
     }
 }
Esempio n. 3
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;
 }
 /**
  * {@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;
 }
 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;
 }
Esempio n. 6
0
 /**
  *  This method checks whether the given argument is an XML-RPC fault.
  *
  * @param mixed $fault
  *
  * @return bool
  */
 public static function isFault($fault)
 {
     if (isset($fault) && is_array($fault)) {
         return xmlrpc_is_fault($fault);
     } else {
         return false;
     }
 }
Esempio n. 7
0
function get_xmlrpc_error($resp)
{
    if (is_array($resp) && xmlrpc_is_fault($resp)) {
        $message = 'Moodle Integrator - ' . $resp['faultCode'] . ' - ' . $resp['faultString'];
        return ErrorMessage(array($message), 'error');
    }
    return null;
}
Esempio n. 8
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;
}
 /**
  * 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;
 }
Esempio n. 10
0
 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";
 }
Esempio n. 11
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;
     }
 }
 public function __call($method, array $parameters = array())
 {
     $request = xmlrpc_encode_request(strlen($this->_namespace) > 0 ? "{$this->_namespace}.{$method}" : $method, $parameters);
     $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
     $file = file_get_contents($this->_url, false, $context);
     $response = xmlrpc_decode($file);
     if (is_null($response)) {
         throw new XmlRpcClientException(array('faultString' => 'Invalid response from ' . $this->_url, 'faultCode' => 999));
     }
     if (@xmlrpc_is_fault($response)) {
         throw new XmlRpcClientException($response);
     }
     return $response;
 }
Esempio n. 14
0
 public function __call($name, $arguments)
 {
     error_log("[FreesideSelfService] {$name} called, sending to " . $this->URL);
     $request = xmlrpc_encode_request("FS.SelfService.XMLRPC.{$name}", $arguments);
     $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
     $file = file_get_contents($this->URL, false, $context);
     $response = xmlrpc_decode($file);
     if (xmlrpc_is_fault($response)) {
         trigger_error("[FreesideSelfService] XML-RPC communication error: {$response['faultString']} ({$response['faultCode']})");
     } else {
         //error_log("[FreesideSelfService] $response");
         return $response;
     }
 }
Esempio n. 15
0
function make_request($xml, &$output)
{
    /* НАЧАЛО ЗАПРОСА */
    $options = ['http' => ['method' => "POST", 'header' => "User-Agent: PHPRPC/1.0\r\n" . "Content-Type: text/xml\r\n" . "Content-length: " . strlen($xml) . "\r\n\n", 'content' => "{$xml}"]];
    $context = stream_context_create($options);
    $retval = file_get_contents('http://phpoopsite.local/xml-rpc/xml-rpc-server.php', false, $context);
    /* КОНЕЦ ЗАПРОСА */
    $data = xmlrpc_decode($retval);
    if (is_array($data) && xmlrpc_is_fault($data)) {
        $output = $data;
    } else {
        $output = unserialize(base64_decode($data));
    }
}
Esempio n. 16
0
function make_request($request_xml, &$output)
{
    $retval = call_socket('php.loc', 80, '/test/xml-rpc/xml-rpc-server.php', $request_xml);
    /*НАЧАЛО ЗАПРОСА*/
    /*$opts = array('http'=>array('method'=>"POST",'header'=>"User-Agent: PHPRPC/1.0\r\n"."Content-Type: text/xml\r\n"."Content-Length: ".strlen($request_xml)."\r\n",'content'=>"$request_xml"));
    		$context = stream_context_create($opts);
    		$retval = file_get_contents('http://php.loc/test/xml-rpc/xml-rpc-server.php');
    		/*КОНЕЦ ЗАПРОСА*/
    $data = xmlrpc_decode($retval);
    if (is_array($data) && xmlrpc_is_fault($data)) {
        $output = $data;
    } else {
        $output = unserialize(base64_decode($data));
    }
}
Esempio n. 17
0
 protected function requestSend($methodName, $args = array())
 {
     $output_options = array("output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup"), "version" => "xmlrpc", "encoding" => "utf-8");
     $this->_post_fields = xmlrpc_encode_request($methodName, $args, $output_options);
     // $headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT);
     $output = $this->curl($this->_options['endpoint']);
     $response = xmlrpc_decode($output, 'utf-8');
     if (!is_array($response)) {
         exit(print_r($this->_ch_info, true));
     } elseif (xmlrpc_is_fault($response)) {
         var_dump($response);
         $response = false;
     }
     return $response;
 }
Esempio n. 18
0
 private function _call($request)
 {
     $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: text/xml', 'content' => $request)));
     if ($file = @file_get_contents($this->server, false, $context)) {
         $file = str_replace('i8', 'double', $file);
         $file = utf8_encode($file);
         $ret = xmlrpc_decode($file);
         if (is_array($ret) && xmlrpc_is_fault($ret)) {
             throw new Exception('request failed:' . $ret['faultCode'] . ': ' . $ret['faultString']);
         }
     } else {
         throw new Exception('request failed (' . $this->server . "):\n\n" . $request . "\n");
     }
     return $ret;
 }
Esempio n. 19
0
function __call($method, $params = null, $debug = false)
{
    global $billing_config;
    $request = xmlrpc_encode_request('stargazer.' . $method, $params, array('escaping' => 'markup', 'encoding' => 'utf-8'));
    $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: text/xml', 'content' => $request)));
    $file = file_get_contents('http://' . $billing_config['STG_HOST'] . ':' . $billing_config['XMLRPC_PORT'] . '/RPC2', false, $context);
    $response = xmlrpc_decode($file);
    if (is_array($response) && xmlrpc_is_fault($response)) {
        trigger_error("xmlrpc: {$response['faultString']} ({$response['faultCode']})");
    }
    if ($debug) {
        echo print_r($response);
    }
    return $response;
}
 /**
  * Search for a list of subtitles in opensubtitles.org
  *
  * @param string $userToken
  * @param string $movieToken
  * @param int    $fileSize
  *
  * @return array
  */
 private function searchSubtitles($userToken, $movieToken, $fileSize)
 {
     $request = xmlrpc_encode_request("SearchSubtitles", array($userToken, array(array('sublanguageid' => $this->lang, 'moviehash' => $movieToken, 'moviebytesize' => $fileSize))));
     $response = $this->generateResponse($request);
     if ($response && xmlrpc_is_fault($response)) {
         trigger_error("xmlrpc: {$response['faultString']} ({$response['faultCode']})");
     } else {
         if ($this->isWrongStatus($response)) {
             trigger_error('no login');
         } else {
             return $response;
         }
     }
     return array();
 }
Esempio n. 21
0
 /**
  * Make RPC-XML request
  *
  * @param string $method
  * @param mixed $params
  */
 protected function _call($method, $params = array())
 {
     $request = xmlrpc_encode_request($method, $params);
     $options = array('http' => array('method' => 'POST', 'header' => $this->_haeders, 'content' => $request));
     $context = stream_context_create($options);
     $file = file_get_contents($this->_url, false, $context);
     $response = xmlrpc_decode(trim($file));
     if (!$response) {
         throw new Exception('Invalid response from ' . $this->_url);
     }
     if (is_array($response) && xmlrpc_is_fault($response)) {
         throw new Exception($response['faultString'], $response['faultCode']);
     }
     return $response;
 }
Esempio n. 22
0
function ping_broadcast_notice($notice)
{
    if (!$notice->is_local) {
        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));
                $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml\r\n" . "User-Agent: Laconica/" . LACONICA_VERSION . "\r\n", 'content' => $req)));
                $file = file_get_contents($notify_url, false, $context);
                if ($file === false || mb_strlen($file) == 0) {
                    common_log(LOG_WARNING, "XML-RPC empty results for ping ({$notify_url}, {$notice->id}) ");
                    continue;
                }
                $response = xmlrpc_decode($file);
                if (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: Laconica/' . LACONICA_VERSION));
                } else {
                    $result = $fetcher->post($notify_url, http_build_query($args), array('User-Agent: Laconica/' . LACONICA_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;
}
function make_request($request_xml, &$arrMessage, $code)
{
    $opts = ['http' => ['method' => "POST", 'header' => "User-Agent: PHPRPC/1.0\r\n" . "Content-Type: text/xml\r\n" . "Content-length: " . strlen($request_xml) . "\r\n", 'content' => $request_xml]];
    $context = stream_context_create($opts);
    //$fp = fopen('http://xml-rpc/server.php', 'r', false, $context);
    //$retval = stream_get_contents($fp);
    $retval = file_get_contents('http://phpoopsite.local/demo/xml-rpc/server.php', false, $context);
    $data = xmlrpc_decode($retval);
    if (is_array($data) && xmlrpc_is_fault($data)) {
        $arrMessage[] = "Невозможно получить данные о полке номер {$code}";
        $arrMessage[] = "Error Code: " . $data['faultCode'];
        $arrMessage[] = "Error Message: " . $data['faultString'];
    } else {
        $arrMessage[] = $data;
    }
}
Esempio n. 24
0
 /**
  * RPC method proxy
  *
  * @param string $method RPC method name
  * @param array $params RPC method arguments
  * @return mixed decoded RPC response
  * @throws Exception
  */
 public function __call($method, array $params)
 {
     if (strlen($this->__namespace)) {
         $method = $this->__namespace . '.' . $method;
     }
     $this->__request->setContentType("text/xml");
     $this->__request->setRawPostData(xmlrpc_encode_request($method, $params, array("encoding" => $this->__encoding) + (array) $this->__options));
     $response = $this->__request->send();
     if ($response->getResponseCode() != 200) {
         throw new Exception($response->getResponseStatus(), $response->getResponseCode());
     }
     $data = xmlrpc_decode($response->getBody(), $this->__encoding);
     if (xmlrpc_is_fault($data)) {
         throw new Exception((string) $data['faultString'], (int) $data['faultCode']);
     }
     return $data;
 }
 public function call($url, $method, $parameters, $options = array())
 {
     $options = array_merge(array('verbosity' => 'no_white_space'), $options);
     $data['post'] = xmlrpc_encode_request($method, $parameters, $options);
     $data['post'] = str_replace(array('<string>&#60;base64&#62;', '&#60;/base64&#62;</string>'), array('<base64>', '</base64>'), $data['post']);
     $data['headers']['Content-Type'] = 'text/xml';
     $data['method'] = 'post';
     xhttp::addHookToRequest($data, 'data-preparation', array(__CLASS__, 'set_rpc_data'), 8);
     $response = xhttp::fetch($url, $data);
     $response['raw'] = $response['body'];
     $response['body'] = str_replace('i8>', 'i4>', $response['body']);
     $response['body'] = xmlrpc_decode($response['body']);
     if ($response['body'] and xmlrpc_is_fault($response['body'])) {
         $response['rpc_fault'] = $response['body']['faultString'];
         $response['rpc_fault_code'] = $response['body']['faultCode'];
     }
     return $response;
 }
Esempio n. 26
0
 /**
  * @param string RPC method name
  * @param array RPC method parameters
  * @return mixed RPC request result
  * @throws TRpcClientRequestException if the client fails to connect to the server
  * @throws TRpcClientResponseException if the response represents an RPC fault
  */
 public function __call($method, $parameters)
 {
     // send request
     $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'text/xml');
     // skip response handling if the request was just a notification request
     if ($this->isNotification) {
         return true;
     }
     // decode response
     if (($_response = xmlrpc_decode($_response)) === null) {
         throw new TRpcClientResponseException('Empty response received');
     }
     // handle error response
     if (xmlrpc_is_fault($_response)) {
         throw new TRpcClientResponseException($_response['faultString'], $_response['faultCode']);
     }
     return $_response;
 }
Esempio n. 27
0
 /**
  * Execute client WS request with token authentication
  *
  * @param string $functionname the function name
  * @param array $params An associative array containing the the parameters of the function being called.
  * @return mixed The decoded XML RPC response.
  * @throws moodle_exception
  */
 public function call($functionname, $params = array())
 {
     if ($this->token) {
         $this->serverurl->param('wstoken', $this->token);
     }
     // Set output options.
     $outputoptions = array('encoding' => 'utf-8');
     // Encode the request.
     $request = xmlrpc_encode_request($functionname, $params, $outputoptions);
     // Set the headers.
     $headers = array('Content-Length' => strlen($request), 'Content-Type' => 'text/xml; charset=utf-8', 'Host' => $this->serverurl->get_host(), 'User-Agent' => 'Moodle XML-RPC Client/1.0');
     // Get the response.
     $response = download_file_content($this->serverurl, $headers, $request);
     // Decode the response.
     $result = xmlrpc_decode($response);
     if (is_array($result) && xmlrpc_is_fault($result)) {
         throw new Exception($result['faultString'], $result['faultCode']);
     }
     return $result;
 }
Esempio n. 28
0
 public function __call($method, $args = array())
 {
     $data = xmlrpc_encode_request($method, $args);
     $header[] = 'Content-type: text/xml';
     $header[] = 'Content-length: ' . strlen($data);
     $curl = curl_init($this->host);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_TIMEOUT, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
     $response = curl_exec($curl);
     if (curl_errno($curl)) {
         throw new EpicClient_Exception(curl_error($curl));
     }
     curl_close($curl);
     $data = xmlrpc_decode($response);
     if (xmlrpc_is_fault($data)) {
         throw new EpicClient_Exception($data['faultString'], $data['faultCode']);
     }
     return $data;
 }
 public function sendCommand($command, $params = [])
 {
     $this->response = null;
     $request = xmlrpc_encode_request($command, $params);
     $context = stream_context_create(['http' => ['method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request]]);
     try {
         $file = file_get_contents(Yii::$app->params['daemon']['xmlrpc_url'], false, $context);
     } catch (ErrorException $e) {
         $this->state = self::ERROR_CONNECTION_REFUSED;
         return;
     }
     $response = xmlrpc_decode($file);
     if (is_string($response)) {
         $response = [$response];
     }
     if ($response && xmlrpc_is_fault($response)) {
         $this->state = self::ERROR_XMLRPC_IS_FAULT;
         return;
     }
     $this->state = self::SUCCESS;
     $this->response = $response;
 }
Esempio n. 30
0
 /**
  * {@inheritdoc}
  */
 public function parse($xmlString)
 {
     if ($this->validateResponse) {
         XmlChecker::isValid($xmlString);
     }
     $result = xmlrpc_decode($xmlString, 'UTF-8');
     if ($result === null && self::isBiggerThanParseLimit($xmlString)) {
         throw ParserException::xmlrpcExtensionLibxmlParsehugeNotSupported();
     }
     $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 = Base64Value::serialize($value->scalar);
                 } else {
                     $value = null;
                 }
             }
         } elseif ($type === 'array') {
             foreach ($value as &$element) {
                 $toBeVisited[] =& $element;
             }
         }
         array_shift($toBeVisited);
     }
     if (is_array($result)) {
         reset($result);
         if (xmlrpc_is_fault($result)) {
             throw FaultException::createFromResponse($result);
         }
     }
     return $result;
 }