本文整理汇总了PHP中xmlrpc_decode_request函数的典型用法代码示例。如果您正苦于以下问题:PHP xmlrpc_decode_request函数的具体用法?PHP xmlrpc_decode_request怎么用?PHP xmlrpc_decode_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlrpc_decode_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmlrpc_request
function xmlrpc_request($host, $port, $location, $function, &$request_data)
{
/*
* This method sends a very basic XML-RPC request. $host, $port, $location,
* and $function are pretty simple. $request_data can be any PHP type,
* and this function returns the PHP type of whatever the xmlrpc function
* returns.
*
* WARNING: This function dies upon failure.
*/
// Send request
$request_xml = xmlrpc_encode_request($function, $request_data);
// Split out response into headers, and xml
$response = urlpost($host, $port, $location, $request_xml);
$response_array = split("\r\n\r\n", $response, 2);
$response_headers = split("\r\n", $response_array[0]);
$response_xml = $response_array[1];
$http_array = split(" ", $response_headers[0], 3);
if ($http_array[1] != "200") {
trigger_error("xmlrpc request failed: ({$http_array[1]}, {$http_array[2]}) at {$host}:{$port} using {$location}");
} else {
// Get native PHP types and return them for data.
$response_data = xmlrpc_decode_request($response_xml, $function);
return $response_data;
}
}
示例2: registerObjects
public function registerObjects()
{
$postRequest = $this->getRequest();
//Utils::debug($postRequest, 'rpc.log', false);
//extract method
$methodRequest = '';
$classname = '';
$method = '';
$result = xmlrpc_decode_request($postRequest, $methodRequest);
if ($methodRequest) {
list($classname, $method) = explode('.', $methodRequest);
}
//Utils::debug("class = $classname, method = $method");
try {
$this->director->pluginManager->loadPlugin($classname);
} catch (Exception $e) {
// normal plugin failed, try to load admin plugin
try {
$this->director->adminManager->loadPlugin($classname);
} catch (Exception $err) {
$this->log->error("error loading coreplugin : {$err}");
}
//throw new Exception($e->getMessage());
}
}
示例3: __call
public function __call($method, $params)
{
if (!function_exists('xmlrpc_encode_request')) {
throw new \Exception("The php5-xmlrpc extension is not installed. Please install this to use this functionality");
}
$xml = xmlrpc_encode_request($method, $params);
//\GO::debug($xml);
if ($this->curl_hdl === null) {
// Create cURL resource
$this->curl_hdl = curl_init();
// Configure options
curl_setopt($this->curl_hdl, CURLOPT_URL, $this->uri);
curl_setopt($this->curl_hdl, CURLOPT_HEADER, 0);
curl_setopt($this->curl_hdl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl_hdl, CURLOPT_POST, true);
curl_setopt($this->curl_hdl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->curl_hdl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($this->curl_hdl, CURLOPT_TIMEOUT, 10);
if (isset($this->_user)) {
curl_setopt($this->curl_hdl, CURLOPT_USERPWD, $this->_user . ":" . $this->_pass);
}
}
curl_setopt($this->curl_hdl, CURLOPT_POSTFIELDS, $xml);
// Invoke RPC command
$response = curl_exec($this->curl_hdl);
$errorNo = curl_errno($this->curl_hdl);
if ($errorNo) {
throw new \Exception($this->_curlErrorCodes[$errorNo]);
}
//\GO::debug($response);
$result = xmlrpc_decode_request($response, $method);
return $result;
}
示例4: parse_request
/**
* This method parses the request input, it needs to get:
* 1/ user authentication - username+password or token
* 2/ function name
* 3/ function parameters
*/
protected function parse_request()
{
// Retrieve and clean the POST/GET parameters from the parameters specific to the server.
parent::set_web_service_call_settings();
// Get GET and POST parameters.
$methodvariables = array_merge($_GET, $_POST);
if ($this->authmethod == WEBSERVICE_AUTHMETHOD_USERNAME) {
$this->username = isset($methodvariables['wsusername']) ? $methodvariables['wsusername'] : null;
unset($methodvariables['wsusername']);
$this->password = isset($methodvariables['wspassword']) ? $methodvariables['wspassword'] : null;
unset($methodvariables['wspassword']);
} else {
$this->token = isset($methodvariables['wstoken']) ? $methodvariables['wstoken'] : null;
unset($methodvariables['wstoken']);
}
// Get the XML-RPC request data.
$rawpostdata = file_get_contents("php://input");
$methodname = null;
// Decode the request to get the decoded parameters and the name of the method to be called.
$decodedparams = xmlrpc_decode_request($rawpostdata, $methodname);
$methodinfo = external_api::external_function_info($methodname);
$methodparams = array_keys($methodinfo->parameters_desc->keys);
// Add the decoded parameters to the methodvariables array.
if (is_array($decodedparams)) {
foreach ($decodedparams as $index => $param) {
// See MDL-53962 - XML-RPC requests will usually be sent as an array (as in, one with indicies).
// We need to use a bit of "magic" to add the correct index back. Zend used to do this for us.
$methodvariables[$methodparams[$index]] = $param;
}
}
$this->functionname = $methodname;
$this->parameters = $methodvariables;
}
示例5: parse_request
/**
* This method parses the request input, it needs to get:
* 1/ user authentication - username+password or token
* 2/ function name
* 3/ function parameters
*/
protected function parse_request()
{
// Retrieve and clean the POST/GET parameters from the parameters specific to the server.
parent::set_web_service_call_settings();
// Get GET and POST parameters.
$methodvariables = array_merge($_GET, $_POST);
if ($this->authmethod == WEBSERVICE_AUTHMETHOD_USERNAME) {
$this->username = isset($methodvariables['wsusername']) ? $methodvariables['wsusername'] : null;
unset($methodvariables['wsusername']);
$this->password = isset($methodvariables['wspassword']) ? $methodvariables['wspassword'] : null;
unset($methodvariables['wspassword']);
} else {
$this->token = isset($methodvariables['wstoken']) ? $methodvariables['wstoken'] : null;
unset($methodvariables['wstoken']);
}
// Get the XML-RPC request data.
$rawpostdata = file_get_contents("php://input");
$methodname = null;
// Decode the request to get the decoded parameters and the name of the method to be called.
$decodedparams = xmlrpc_decode_request($rawpostdata, $methodname);
// Add the decoded parameters to the methodvariables array.
if (is_array($decodedparams)) {
foreach ($decodedparams as $param) {
// Check if decoded param is an associative array.
if (is_array($param) && array_keys($param) !== range(0, count($param) - 1)) {
$methodvariables = array_merge($methodvariables, $param);
} else {
$methodvariables[] = $param;
}
}
}
$this->functionname = $methodname;
$this->parameters = $methodvariables;
}
示例6: __construct
function __construct($payload, $payload_signed, $payload_encrypted)
{
$this->payload = $payload;
// xmlrpc_decode_request is defined such that the '$method' string is
// passed in by reference.
$this->params = xmlrpc_decode_request($this->payload, $this->method, 'UTF-8');
// The method name is not allowed to have a dot, except for a single dot
// which preceeds the php extension. It can have slashes but it cannot
// begin with a slash. We specifically don't want .. to be possible.
if (0 == preg_match("@^[A-Za-z0-9]+/[A-Za-z0-9/_-]+(\\.php/)?[A-Za-z0-9_-]+\$@", $this->method)) {
throw new XmlrpcServerException('The function does not exist', 6010);
}
if ($payload_signed && $payload_encrypted || $this->method == 'system/keyswap') {
// The remote server's credentials checked out.
// You might want to enable some methods for unsigned/unencrypted
// transport
} else {
// For now, we throw an exception
throw new XmlrpcServerException('The signature on your message was not valid', 6005);
}
// The system methods are treated differently.
if (array_key_exists($this->method, $this->system_methods)) {
$xmlrpcserver = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpcserver, $this->method, array(&$this, $this->system_methods[$this->method]));
} else {
// Security: I'm thinking that we should not return separate errors for
// the file not existing, the file not being readable, etc. as
// it might provide an opportunity for outsiders to scan the
// server for random files. So just a single message/code for
// all failures here kthxbye.
if (strpos($this->method, '/') !== false) {
$this->callstack = explode('/', $this->method);
} else {
throw new XmlrpcServerException('The function does not exist', 6011);
}
// Read custom xmlrpc functions from local
if (function_exists('local_xmlrpc_services')) {
foreach (local_xmlrpc_services() as $name => $localservices) {
$this->services[$name] = array_merge($this->services[$name], $localservices);
}
}
foreach ($this->services as $container) {
if (array_key_exists($this->method, $container)) {
$xmlrpcserver = xmlrpc_server_create();
$bool = xmlrpc_server_register_method($xmlrpcserver, $this->method, 'api_dummy_method');
$this->response = xmlrpc_server_call_method($xmlrpcserver, $payload, $container[$this->method], array("encoding" => "utf-8"));
$bool = xmlrpc_server_destroy($xmlrpcserver);
return $this->response;
}
}
throw new XmlrpcServerException('No such method: ' . $this->method);
}
$temp = '';
$this->response = xmlrpc_server_call_method($xmlrpcserver, $payload, $temp, array("encoding" => "utf-8"));
return $this->response;
}
示例7: readRequest
/**
* Reads the HTTP request from client and decodes the XML data
*
* @return void
*/
public function readRequest()
{
$this->_debug("-----> " . __CLASS__ . '::' . __FUNCTION__ . "()", 9);
// Parent will do the request reading
parent::readRequest();
// Assign and decode the request
$this->requestRawXml =& $this->requestRawBody;
$this->params = xmlrpc_decode_request($this->requestRawXml, $this->method);
// Set the response header
$this->setResponseHeader('Content-type', 'text/xml');
}
示例8: decodeStream
function decodeStream($rawResponse)
{
/// @todo test if this automatically groks encoding from xml or not...
$meth = '';
$resp = xmlrpc_decode_request($rawResponse, $meth);
if (!is_array($resp)) {
return false;
}
$this->Name = $meth;
$this->Parameters = $resp;
return true;
}
示例9: handle
/**
* Handle RPC request(s).
* Fluent interface.
*
* @param boolean|string $request RPC request (string), FALSE read from php://input once or TRUE to keep listing on php://input for multiple requests
* @return RPC_Server_XMLRPC
*
* @todo implement keep alive
*/
public function handle($request = false)
{
$keep_alive = (int) $request === 1;
if ($keep_alive || empty($request)) {
$request = "";
while ($line = fread(STDIN, 1024)) {
$request .= $line;
if (substr($request, -1) == "") {
break;
}
}
$request = substr($request, 0, strlen($request) - 1);
}
try {
$method = null;
$args = xmlrpc_decode_request($request, $method);
if (empty($method)) {
throw new Exception("Invalid XMLRPC request.");
}
if (!is_callable(array($this->object, $method))) {
throw new Exception("RPC call failed: Unable to call method '{$method}'.");
}
$result = call_user_func_array(array($this->object, $method), $args);
$output = xmlrpc_encode_request(null, $result);
} catch (ExpectedException $e) {
$output = xmlrpc_encode(array("faultCode" => $e->getCode(), "faultString" => $e->getMessage()));
} catch (\Exception $e) {
$output = xmlrpc_encode(array("faultCode" => -1, "faultString" => "Unexpected exception."));
$this->putExtraInfo('X-Exception', $e->getMessage());
if (class_exists(__NAMESPACE__ . '::ErrorHandler', false) && ErrorHandler::isInit()) {
ErrorHandler::i()->handleException($e);
}
}
$content_type = HTTP::header_getValue('Content-Type');
if (empty($content_type) || $content_type == 'text/xml') {
fwrite($this->stream, $output);
} else {
if (HTTP::headers_sendable()) {
if ($keep_alive) {
trigger_error("Using keep-alive together with sending non-XMLRPC is not allowed. Found header 'Content-Type: {$content_type}'.", E_USER_WARNING);
fwrite($this->stream, xmlrpc_encode(array("faultCode" => 0, "faultString" => "Could not send non-XMLRPC output because of keep-alive.")));
}
} else {
$this->putExtraInfo('Content-Type', $content_type);
}
}
return $this;
}
示例10: findRoute
public function findRoute($path)
{
global $HTTP_RAW_POST_DATA;
$result = parent::findRoute($path);
//$rawdata = xmlrpc_encode_request("authorize", array( "cons", "cons" ));
//if ((!$result["action"] || !$result["params"]) && ($rawdata))
if ((!$result["action"] || !$result["params"]) && ($rawdata = $HTTP_RAW_POST_DATA)) {
$params = xmlrpc_decode_request($rawdata, &$action);
if (!$result["action"]) {
$result["action"] = $action;
}
if (!$result["params"]) {
$result["params"] = $params;
}
}
return $result;
}
示例11: fromXmlString
public function fromXmlString($xmlString)
{
$this->parameters = xmlrpc_decode_request($xmlString, $this->methodName);
$this->fixupParameter($this->parameters);
if ($this->methodName === null) {
throw new UnexpectedValueException("Invalid XML-RPC structure (/methodCall/methodName not found)");
}
if ($this->parameters === null) {
if (($simpleXml = @simplexml_load_string($xmlString)) === false) {
$errors = array();
foreach (libxml_get_errors() as $error) {
$errors[] = $error->message;
}
throw new UnexpectedValueException("Invalid XML-RPC message:" . implode("\n", $errors));
}
}
}
示例12: executeRPC2
/**
* This is the main handle for the xmlrpc calls
*/
public function executeRPC2($request)
{
// get all the defined RPC
$rpc_functions = $this->getRPCFunctions();
// http POST method is required for modifying the database
$this->forward404Unless($request->isMethod('post'), "HTTP POST is required");
// log to debug
ezDbg::err("enter xmlrpc");
// get xmlrpc request string posted as a raw
$xmlrpc_reqstr = file_get_contents("php://input");
// parse the xmlrpc_reqstr
$method_name = null;
$xmlrpc_params = xmlrpc_decode_request($xmlrpc_reqstr, &$method_name);
ezDbg::err("enter method_name={$method_name} xmlrpc param=" . print_r($xmlrpc_params, true));
if (!isset($rpc_functions[$method_name])) {
$xmlrpc_resp = array("faultCode" => 1, "faultString" => "unknown method name (" . $method_name . ")");
} else {
$rpc_function = $rpc_functions[$method_name];
$nparam = $rpc_function['nparam'];
if (count($xmlrpc_params) < $nparam) {
$xmlrpc_resp = array("faultCode" => 1, "faultString" => $method_name . " require " . $nparam . " parameters.");
} else {
try {
ezDbg::err('trying to call (' . $rpc_function['function'] . ')', $xmlrpc_params);
$xmlrpc_resp = call_user_func_array($rpc_function['function'], $xmlrpc_params);
//$xmlrpc_resp = sfWebRPCPluginDemo::superAddFct(2,3);
} catch (Exception $e) {
$xmlrpc_resp = array("faultCode" => 1, "faultString" => "" . $e->getMessage());
}
}
}
// encode the xmlrpc_resp
$xmlrpc_respstr = xmlrpc_encode($xmlrpc_resp);
// KLUDGE: xmlrpc_encode is unable to add the methodResponse required
$arr = split("\n", $xmlrpc_respstr);
$arr[0] .= "\n<methodResponse>";
$arr[count($arr) - 1] = "</methodResponse>";
$xmlrpc_respstr = implode("\n", $arr);
ezDbg::err("enter xmlrpc resp=" . print_r($xmlrpc_respstr, true));
// disable the web_debug bar
sfConfig::set('sf_web_debug', false);
// return the $value in xml
$this->getResponse()->setHttpHeader('Content-Type', 'text/xml');
return $this->renderText($xmlrpc_respstr);
}
示例13: parse
/**
* Parse request
*
* @param \Zend\Http\Request $request
* @param \Zend\Http\Response $request
* @return string|null $error
*/
public function parse(Request $request, Response $response)
{
$error = parent::parse($request, $response);
if ($error) {
return $error;
}
$method = null;
$params = xmlrpc_decode_request($request->getContent(), $method, 'utf-8');
if (!$params) {
return self::PARSE;
}
if (empty($method) || empty($params)) {
return self::INVALID_REQUEST;
}
$this->method = $method;
$this->params = $params;
return null;
}
示例14: inputFilter
public function inputFilter($data, stdClass $context)
{
if ($data !== "" && $data[0] === '<') {
$context->userdata->format = "xmlrpc";
$method = null;
$params = xmlrpc_decode_request($data, $method, "UTF-8");
$stream = new BytesIO();
$writer = new Writer($stream, true);
if (isset($method)) {
$stream->write(Tags::TagCall);
$writer->writeString($method);
if (isset($params)) {
$writer->writeArray($params);
}
}
$stream->write(Tags::TagEnd);
$data = $stream->toString();
}
return $data;
}
示例15: createRequest
/**
* @param Request $request
* @return XmlRpcRequest
* @throws RpcException
*/
public function createRequest(Request $request)
{
if (!$request->isMethod('POST')) {
throw new InvalidRequestException(self::MESSAGE_INVALID_HTTP_METHOD);
}
if ($request->getContentType() != 'xml') {
throw new InvalidRequestException(self::MESSAGE_INVALID_CONTENT_TYPE);
}
$params = xmlrpc_decode_request($request->getContent(), $method, 'UTF-8');
if (is_null($method)) {
throw new RequestParseException(self::MESSAGE_INVALID_BODY);
}
if (empty($method)) {
throw new InvalidRequestException(self::MESSAGE_METHOD_REQUIRED);
}
if (!is_array($params)) {
throw new InvalidRequestException(self::MESSAGE_METHOD_PARAMS_TYPE);
}
return new XmlRpcRequest($request, $method, $params);
}