function mobi_parse_requrest() { global $request_method, $request_params, $params_num; $ver = phpversion(); if ($ver[0] >= 5) { $data = file_get_contents('php://input'); } else { $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; } if (count($_SERVER) == 0) { $r = new xmlrpcresp('', 15, 'XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated'); echo $r->serialize('UTF-8'); exit; } if (isset($_SERVER['HTTP_CONTENT_ENCODING'])) { $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']); } else { $content_encoding = ''; } if ($content_encoding != '' && strlen($data)) { if ($content_encoding == 'deflate' || $content_encoding == 'gzip') { // if decoding works, use it. else assume data wasn't gzencoded if (function_exists('gzinflate')) { if ($content_encoding == 'deflate' && ($degzdata = @gzuncompress($data))) { $data = $degzdata; } elseif ($degzdata = @gzinflate(substr($data, 10))) { $data = $degzdata; } } else { $r = new xmlrpcresp('', 106, 'Received from client compressed HTTP request and cannot decompress'); echo $r->serialize('UTF-8'); exit; } } } $parsers = php_xmlrpc_decode_xml($data); $request_method = $parsers->methodname; $request_params = php_xmlrpc_decode(new xmlrpcval($parsers->params, 'array')); $params_num = count($request_params); }
/** * output error/success message * * @param String $message * @param Boolean $result * @patam Integer $errorCode * @return string default as xmlrpc */ public static function alert($message, $result = false, $errorCode = NULL, $error_detail = '') { header('Content-Type: text/xml'); self::resetGlobals(); $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval($result, 'boolean'), 'result_text' => new xmlrpcval($message, 'base64'), 'error' => new xmlrpcval($error_detail, 'base64')), 'struct')); if (ob_get_length()) { ob_end_clean(); } echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $response->serialize('UTF-8'); exit; }
die('XML-RPC server accepts POST requests only.'); } // Disable Cookies $_COOKIE = array(); if (!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = implode("\r\n", file('php://input')); } // Trim requests (used by XML-RPC library); fix for mozBlog and other cases where '<?xml' isn't on the very first line $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); require_once dirname(__FILE__) . '/../conf/_config.php'; require_once $inc_path . '_main.inc.php'; load_funcs('xmlrpc/model/_xmlrpc.funcs.php'); if (CANUSEXMLRPC !== TRUE || !$Settings->get('general_xmlrpc')) { // We cannot use XML-RPC: send an error response ( "17 Internal server error" ). $errMessage = CANUSEXMLRPC !== TRUE ? 'Cannot use XML-RPC. Probably the server is missing the XML extension. Error: ' . CANUSEXMLRPC : 'XML-RPC services are disabled on this system.'; $errResponse = new xmlrpcresp(0, 17, $errMessage); die($errResponse->serialize()); } // We can't display standard error messages. We must return XMLRPC responses. $DB->halt_on_error = false; $DB->show_errors = false; $post_default_title = ''; // posts submitted via the xmlrpc interface get that title /** * Array defining the available Remote Procedure Calls: */ $xmlrpc_procs = array(); // Load APIs: include_once $inc_path . 'xmlrpc/apis/_blogger.api.php'; include_once $inc_path . 'xmlrpc/apis/_b2.api.php'; include_once $inc_path . 'xmlrpc/apis/_metaweblog.api.php';
function echoInput() { global $HTTP_RAW_POST_DATA; // a debugging routine: just echos back the input // packet as a string value $r = new xmlrpcresp(); $r->xv = new xmlrpcval("'Aha said I: '" . $HTTP_RAW_POST_DATA, 'string'); print $r->serialize(); }
function mob_error($err_str) { @ob_clean(); $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(false, 'boolean'), 'result_text' => new xmlrpcval(processBody($err_str), 'base64')), 'struct')); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $response->serialize('UTF-8'); exit; }
$output['Number of Tokens:'] = new xmlrpcval(number_format($regs[1])); break; case 'oldest atime': $output['Oldest Token:'] = new xmlrpcval(date('r', $regs[1])); break; case 'newest atime': $output['Newest Token:'] = new xmlrpcval(date('r', $regs[1])); break; case 'last journal sync atime': $output['Last Journal Sync:'] = new xmlrpcval(date('r', $regs[1])); break; case 'last expiry atime': $output['Last Expiry:'] = new xmlrpcval(date('r', $regs[1])); break; case 'last expire reduction count': $output['Last Expiry Reduction Count:'] = new xmlrpcval(number_format($regs[1])); break; } } } return new xmlrpcresp(new xmlrpcval($output, 'struct')); } $s = new xmlrpc_server(array('get_quarantine' => array('function' => 'rpc_get_quarantine', 'signature' => array(array('array', 'string')), 'docstring' => 'This service returns a listing of files in the relative quarantine directory.'), 'return_quarantined_file' => array('function' => 'rpc_return_quarantined_file', 'signature' => array(array('base64', 'string')), 'docstring' => 'This service returns the contents of a quarantined file.'), 'quarantine_list_items' => array('function' => 'rpc_quarantine_list_items', 'signature' => array(array('array', 'string')), 'docstring' => 'This service lists the files quarantined for a given message.'), 'quarantine_release' => array('function' => 'rpc_quarantine_release', 'signature' => array(array('string', 'array', 'array', 'string')), 'docstring' => 'This service release a message from the quarantine.'), 'quarantine_learn' => array('function' => 'rpc_quarantine_learn', 'signature' => array(array('string', 'array', 'array', 'string')), 'docstring' => 'This service runs sa-learn on a message in the quarantine.'), 'quarantine_delete' => array('function' => 'rpc_quarantine_delete', 'signature' => array(array('string', 'array', 'array')), 'docstring' => 'This service deltes one or more items from the quarantine.'), 'sophos_status' => array('function' => 'rpc_sophos_status', 'signature' => array(array('string')), 'docstring' => 'This service returns the Sophos version and IDE information.'), 'get_conf_var' => array('function' => 'rpc_get_conf_var', 'signature' => array(array('string', 'string')), 'docstring' => 'This service returns a named configuration value from MailScanner.conf.'), 'dump_mailscanner_conf' => array('function' => 'rpc_dump_mailscanner_conf', 'signature' => array(array('struct')), 'docstring' => 'This service returns all configuration values and settings from MailScanner.conf.'), 'get_bayes_info' => array('function' => 'rpc_bayes_info', 'signature' => array(array('struct')), 'docstring' => 'This service return information about the bayes database.')), false); // Check that the client is authorised to connect if (is_rpc_client_allowed()) { $s->service(); } else { global $xmlrpcerruser; $output = new xmlrpcresp(0, $xmlrpcerruser + 1, "Client {$_SERVER['SERVER_ADDR']} is not authorized to connect."); print $output->serialize(); }
function testNilvalue() { // default case: we do not accept nil values received $v = new xmlrpcval('hello', 'null'); $r = new xmlrpcresp($v); $s = $r->serialize(); $m = new xmlrpcmsg('dummy'); $r = $m->parseresponse($s); $this->assertequals(2, $r->faultCode()); // enable reception of nil values $GLOBALS['xmlrpc_null_extension'] = true; $r = $m->parseresponse($s); $v = $r->value(); $this->assertequals('null', $v->scalartyp()); // test with the apache version: EX:NIL $GLOBALS['xmlrpc_null_apache_encoding'] = true; // serialization $v = new xmlrpcval('hello', 'null'); $s = $v->serialize(); $this->assertequals(1, preg_match('#<value><ex:nil/></value>#', $s)); // deserialization $r = new xmlrpcresp($v); $s = $r->serialize(); $r = $m->parseresponse($s); $v = $r->value(); $this->assertequals('null', $v->scalartyp()); $GLOBALS['xmlrpc_null_extension'] = false; $r = $m->parseresponse($s); $this->assertequals(2, $r->faultCode()); }
/* include the libs */ include "xmlrpc-2.2.2/lib/xmlrpc.inc"; include "xmlrpc-2.2.2/lib/xmlrpcs.inc"; require_once 'common.inc.php'; if (preg_match('`bp_api\\.php`', $_SERVER['PHP_SELF'])) { db_connect(); /* get xml */ $sXml = file_get_contents('php://input'); /* create md5 hash with XML and your secretKey */ $sAuthHash = strtolower(md5($sXml . $sSecretKey)); /* check authentication */ if (strcmp($sAuthHash, $_GET['authHash']) != 0) { /* authentication failed - generate fault code and string */ $aOutput = array('faultCode' => '-1', 'faultString' => 'authentication failed'); $pResp = new xmlrpcresp(php_xmlrpc_encode($aOutput)); echo $pResp->serialize(); } else { /* authentication okay */ /* set common signature for the methods */ $aSignature = array(array($xmlrpcStruct, $xmlrpcStruct)); $pMyGameClass = new TheGame(); /* methods to be registered - $pMyGameClass is an instance of class TheGame */ $aRegister = array('game.login' => array('function' => array($pMyGameClass, 'Login'), 'signature' => $aSignature), 'game.registerAndLogin' => array('function' => array($pMyGameClass, 'Register'), 'signature' => $aSignature), 'game.getUserStats' => array('function' => array($pMyGameClass, 'GetStats'), 'signature' => $aSignature), 'bookItem' => array('function' => array($pMyGameClass, 'BookItem'), 'signature' => $aSignature), 'blockedNotify' => array('function' => array($pMyGameClass, 'BlockedNotify'), 'signature' => $aSignature), 'getUserPaymentLanguage' => array('function' => array($pMyGameClass, 'GetUserPaymentLanguage'), 'signature' => $aSignature), 'getUserExchangeRate' => array('function' => array($pMyGameClass, 'GetUserExchangeRate'), 'signature' => $aSignature), 'currencySwap' => array('function' => array($pMyGameClass, 'CurrencySwap'), 'signature' => $aSignature)); /* create server, set encoding and invoke */ $pServer = new xmlrpc_server($aRegister, false); $pServer->response_charset_encoding = 'UTF-8'; $pServer->service(); } } /* example game class */
function tapatalk_error($error) { if (!strstr($_SERVER['PHP_SELF'], 'mobiquo.php')) { return; } if (defined('IN_MOBIQUO')) { global $lang, $include_topic_num, $search, $function_file_name; if ($error == $lang->error_nosearchresults) { if ($include_topic_num) { if ($search['resulttype'] != 'posts') { $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'total_topic_num' => new xmlrpcval(0, 'int'), 'topics' => new xmlrpcval(array(), 'array')), 'struct')); } else { $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'total_post_num' => new xmlrpcval(0, 'int'), 'posts' => new xmlrpcval(array(), 'array')), 'struct')); } } else { $response = new xmlrpcresp(new xmlrpcval(array(), 'array')); } } else { if ($function_file_name == 'thankyoulike' && strpos($error, $lang->tyl_redirect_back)) { $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean')), 'struct')); } else { $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(false, 'boolean'), 'result_text' => new xmlrpcval(trim(strip_tags($error)), 'base64')), 'struct')); } } echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $response->serialize('UTF-8'); exit; } }
function testNilvalue() { // default case: we do not accept nil values received $v = new xmlrpcval('hello', 'null'); $r = new xmlrpcresp($v); $s = $r->serialize(); $m = new xmlrpcmsg('dummy'); $r = $m->parseresponse($s); $this->assertequals(2, $r->faultCode()); // enable reception of nil values $GLOBALS['xmlrpc_null_extension'] = true; $r = $m->parseresponse($s); $v = $r->value(); $this->assertequals('null', $v->scalartyp()); }
function error_status($status = 0, $result_text = '') { @ob_clean(); if (!headers_sent()) { header('200 OK'); header('Mobiquo_is_login: false'); header('Content-Type: text/xml'); } $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(false, 'boolean'), 'status' => new xmlrpcval($status, 'string'), 'result_text' => new xmlrpcval($result_text, 'base64')), 'struct')); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $response->serialize('UTF-8'); exit; }
function obExit($header = null, $do_footer = null, $from_index = false, $from_fatal_error = false) { global $context, $settings, $modSettings, $txt, $smcFunc, $boarddir; static $header_done = false, $footer_done = false, $level = 0, $has_fatal_error = false; // tapatalk add if ($_GET['action'] == 'admin' || isset($context['kick_message'])) { @ob_clean(); if (!headers_sent()) { header('Mobiquo_is_login:'******'user']['is_logged'] ? 'true' : 'false')); header('Content-Type: text/xml'); } if ($_GET['action'] == 'admin') { $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(false, 'boolean'), 'is_login_mod' => new xmlrpcval(false, 'boolean')), 'struct')); } else { $response = new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(false, 'boolean'), 'result_text' => new xmlrpcval(basic_clean($context['kick_message']), 'base64')), 'struct')); } echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $response->serialize('UTF-8'); exit; } // Attempt to prevent a recursive loop. ++$level; if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { exit; } if ($from_fatal_error) { $has_fatal_error = true; } // Clear out the stat cache. trackStats(); // If we have mail to send, send it. if (!empty($context['flush_mail'])) { AddMailQueue(true); } $do_header = $header === null ? !$header_done : $header; if ($do_footer === null) { $do_footer = $do_header; } // Has the template/header been done yet? if ($do_header) { // Was the page title set last minute? Also update the HTML safe one. if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])); } //tapatalk add include_once $boarddir . '/mobiquo/smartbanner.php'; // Start up the session URL fixer. ob_start('ob_sessrewrite'); if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { $buffers = explode(',', $settings['output_buffers']); } elseif (!empty($settings['output_buffers'])) { $buffers = $settings['output_buffers']; } else { $buffers = array(); } if (isset($modSettings['integrate_buffer'])) { $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); } if (!empty($buffers)) { foreach ($buffers as $function) { $function = trim($function); $call = strpos($function, '::') !== false ? explode('::', $function) : $function; // Is it valid? if (is_callable($call)) { ob_start($call); } } } // Display the screen in the logical order. template_header(); $header_done = true; } if ($do_footer) { if (WIRELESS && !isset($context['sub_template'])) { fatal_lang_error('wireless_error_notyet', false); } // Just show the footer, then. loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); // Anything special to put out? if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { echo $context['insert_after_template']; } // Just so we don't get caught in an endless loop of errors from the footer... if (!$footer_done) { $footer_done = true; template_footer(); // (since this is just debugging... it's okay that it's after </html>.) if (!isset($_REQUEST['xml'])) { db_debug_junk(); } } } // Remember this URL in case someone doesn't like sending HTTP_REFERER. if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; } // For session check verfication.... don't switch browsers... $_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; if (!empty($settings['strict_doctype'])) { // The theme author wants to use the STRICT doctype (only God knows why). $temp = ob_get_contents(); if (function_exists('ob_clean')) { ob_clean(); } else { ob_end_clean(); ob_start('ob_sessrewrite'); } echo strtr($temp, array('var smf_iso_case_folding' => 'var target_blank = \'_blank\'; var smf_iso_case_folding', 'target="_blank"' => 'onclick="this.target=target_blank"')); } // Hand off the output to the portal, etc. we're integrated with. call_integration_hook('integrate_exit', array($do_footer && !WIRELESS)); // Don't exit if we're coming from index.php; that will pass through normally. if (!$from_index || WIRELESS) { exit; } }
/** * Takes the xmlrpc object and generates the response to be set back * @param {xmlrpc_server} $server XML-RPC Server instance * @param {xmlrpcresp} $r XML-RPC Response object to relay to client * @return {string} Response to be sent to the client */ protected function generateErrorResponse(xmlrpc_server $server, xmlrpcresp $r) { $this->response->addHeader('Content-Type', $r->content_type); $this->response->addHeader('Vary', 'Accept-Charset'); $payload = $server->xml_header(); if (empty($r->payload)) { $r->serialize(); } $payload = $payload . $r->payload; return $payload; }
/** * Contributed by Justin Miller <*****@*****.**> * Requires curl to be built into PHP * NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers! * @access private */ function &sendPayloadCURL($msg, $server, $port, $timeout = 0, $username = '', $password = '', $authtype = 1, $cert = '', $certpass = '', $cacert = '', $cacertdir = '', $proxyhost = '', $proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1, $method = 'https', $keepalive = false, $key = '', $keypass = '') { if (!function_exists('curl_init')) { $this->errstr = 'CURL unavailable on this install'; $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_curl'], $GLOBALS['xmlrpcstr']['no_curl']); return $r; } if ($method == 'https') { if (($info = curl_version()) && (is_string($info) && strpos($info, 'OpenSSL') === null || is_array($info) && !isset($info['ssl_version']))) { $this->errstr = 'SSL unavailable on this install'; $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_ssl'], $GLOBALS['xmlrpcstr']['no_ssl']); return $r; } } if ($port == 0) { if ($method == 'http') { $port = 80; } else { $port = 443; } } // Only create the payload if it was not created previously if (empty($msg->payload)) { $msg->createPayload($this->request_charset_encoding); } // Deflate request body and set appropriate request headers $payload = $msg->payload; if (function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate')) { if ($this->request_compression == 'gzip') { $a = @gzencode($payload); if ($a) { $payload = $a; $encoding_hdr = 'Content-Encoding: gzip'; } } else { $a = @gzcompress($payload); if ($a) { $payload = $a; $encoding_hdr = 'Content-Encoding: deflate'; } } } else { $encoding_hdr = ''; } if ($this->debug > 1) { print "<PRE>\n---SENDING---\n" . htmlentities($payload) . "\n---END---\n</PRE>"; // let the client see this now in case http times out... flush(); } if (!$keepalive || !$this->xmlrpc_curl_handle) { $curl = curl_init($method . '://' . $server . ':' . $port . $this->path); if ($keepalive) { $this->xmlrpc_curl_handle = $curl; } } else { $curl = $this->xmlrpc_curl_handle; } // results into variable curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if ($this->debug) { curl_setopt($curl, CURLOPT_VERBOSE, 1); } curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); // required for XMLRPC: post the data curl_setopt($curl, CURLOPT_POST, 1); // the data curl_setopt($curl, CURLOPT_POSTFIELDS, $payload); // return the header too curl_setopt($curl, CURLOPT_HEADER, 1); // NB: if we set an empty string, CURL will add http header indicating // ALL methods it is supporting. This is possibly a better option than // letting the user tell what curl can / cannot do... if (is_array($this->accepted_compression) && count($this->accepted_compression)) { //curl_setopt($curl, CURLOPT_ENCODING, implode(',', $this->accepted_compression)); // empty string means 'any supported by CURL' (shall we catch errors in case CURLOPT_SSLKEY undefined ?) if (count($this->accepted_compression) == 1) { curl_setopt($curl, CURLOPT_ENCODING, $this->accepted_compression[0]); } else { curl_setopt($curl, CURLOPT_ENCODING, ''); } } // extra headers $headers = array('Content-Type: ' . $msg->content_type, 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings)); if (is_array($this->accepted_content_type) && count($this->accepted_content_type)) { $headers[] = 'Accept: ' . implode(', ', $this->accepted_content_type); } // if no keepalive is wanted, let the server know it in advance if (!$keepalive) { $headers[] = 'Connection: close'; } // request compression header if ($encoding_hdr) { $headers[] = $encoding_hdr; } curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // timeout is borked if ($timeout) { curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1); } if ($username && $password) { curl_setopt($curl, CURLOPT_USERPWD, $username . ':' . $password); if (defined('CURLOPT_HTTPAUTH')) { curl_setopt($curl, CURLOPT_HTTPAUTH, $authtype); } else { if ($authtype != 1) { error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported by the current PHP/curl install'); } } } if ($method == 'https') { // set cert file if ($cert) { curl_setopt($curl, CURLOPT_SSLCERT, $cert); } // set cert password if ($certpass) { curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $certpass); } // whether to verify remote host's cert curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer); // set ca certificates file/dir if ($cacert) { curl_setopt($curl, CURLOPT_CAINFO, $cacert); } if ($cacertdir) { curl_setopt($curl, CURLOPT_CAPATH, $cacertdir); } // set key file (shall we catch errors in case CURLOPT_SSLKEY undefined ?) if ($key) { curl_setopt($curl, CURLOPT_SSLKEY, $key); } // set key password (shall we catch errors in case CURLOPT_SSLKEY undefined ?) if ($keypass) { curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keypass); } // whether to verify cert's common name (CN); 0 for no, 1 to verify that it exists, and 2 to verify that it matches the hostname used curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost); } // proxy info if ($proxyhost) { if ($proxyport == 0) { $proxyport = 8080; // NB: even for HTTPS, local connection is on port 8080 } curl_setopt($curl, CURLOPT_PROXY, $proxyhost . ':' . $proxyport); //curl_setopt($curl, CURLOPT_PROXYPORT,$proxyport); if ($proxyusername) { curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyusername . ':' . $proxypassword); if (defined('CURLOPT_PROXYAUTH')) { curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyauthtype); } else { if ($proxyauthtype != 1) { error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported by the current PHP/curl install'); } } } } // NB: should we build cookie http headers by hand rather than let CURL do it? // the following code does not honour 'expires', 'path' and 'domain' cookie attributes // set to client obj the the user... if (count($this->cookies)) { $cookieheader = ''; foreach ($this->cookies as $name => $cookie) { $cookieheader .= $name . '=' . $cookie['value'] . '; '; } curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2)); } foreach ($this->extracurlopts as $opt => $val) { curl_setopt($curl, $opt, $val); } $result = curl_exec($curl); if ($this->debug > 1) { print "<PRE>\n---CURL INFO---\n"; foreach (curl_getinfo($curl) as $name => $val) { if (is_array($val)) { $val = implode("\n", $val); } print $name . ': ' . htmlentities($val) . "\n"; } print "---END---\n</PRE>"; } if (!$result) { $this->errstr = 'no response'; $resp = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['curl_fail'], $GLOBALS['xmlrpcstr']['curl_fail'] . ': ' . curl_error($curl)); curl_close($curl); if ($keepalive) { $this->xmlrpc_curl_handle = null; } } else { if (!$keepalive) { curl_close($curl); } $resp =& $msg->parseResponse($result, true, $this->return_type); // if we got back a 302, we can not reuse the curl handle for later calls if ($resp->faultCode() == $GLOBALS['xmlrpcerr']['http_error'] && $keepalive) { curl_close($curl); $this->xmlrpc_curl_handle = null; } } return $resp; }
if (function_exists('xmlrpc_set_type')) { begin_test('Data encoding (large array)', 'xmlrpc-epi encoding'); for ($i = 0; $i < $num_tests; $i++) { for ($j = 0; $j < 10; $j++) { foreach ($keys as $k) { xmlrpc_set_type($data[$j][$k][4], 'datetime'); xmlrpc_set_type($data[$j][$k][8], 'datetime'); } } $out = xmlrpc_encode($data); } end_test('Data encoding (large array)', 'xmlrpc-epi encoding', $out); } // test 'old style' data decoding vs. 'automatic style' decoding $dummy = new xmlrpcmsg(''); $out = new xmlrpcresp($value); $in = '<?xml version="1.0" ?>' . "\n" . $out->serialize(); begin_test('Data decoding (large array)', 'manual decoding'); for ($i = 0; $i < $num_tests; $i++) { $response =& $dummy->ParseResponse($in, true); $value = $response->value(); $result = array(); for ($k = 0; $k < $value->arraysize(); $k++) { $val1 = $value->arraymem($k); $out = array(); while (list($name, $val) = $val1->structeach()) { $out[$name] = array(); for ($j = 0; $j < $val->arraysize(); $j++) { $data = $val->arraymem($j); $out[$name][] = $data->scalarval(); }
/** * A debugging routine: just echoes back the input packet as a string value * DEPRECATED! */ function echoInput() { $r = new xmlrpcresp(new xmlrpcval("'Aha said I: '" . $GLOBALS['HTTP_RAW_POST_DATA'], 'string')); print $r->serialize(); }
/** * Handles RPC request methods * @param {xmlrpcmsg} $request XML-RPC Request Object */ public function handleRPCMethod(xmlrpcmsg $request) { $username = $request->getParam(1)->getval(); $password = $request->getParam(2)->getval(); if ($this->authenticate($username, $password)) { $method = str_replace(array('blogger.', 'metaWeblog.', 'kapost.'), '', $request->methodname); if (!in_array($request->methodname, $this->exposed_methods) || !method_exists($this, $method)) { return $this->httpError(403, _t('KapostService.METHOD_NOT_ALLOWED', '_Action "{method}" is not allowed on class Kapost Service.', array('method' => $request->methodname))); } //Pack params into call to method if they are not the authentication parameters $params = array(); for ($i = 0; $i < $request->getNumParams(); $i++) { if ($i != 1 && $i != 2) { $params[] = php_xmlrpc_decode($request->getParam($i)); } } //Convert the custom fields to an associtive array if (array_key_exists(1, $params) && is_array($params[1]) && array_key_exists('custom_fields', $params[1])) { $params[1]['custom_fields'] = $this->struct_to_assoc($params[1]['custom_fields']); } //If transactions are supported start one for newPost and editPost if (($method == 'newPost' || $method == 'editPost') && DB::getConn()->supportsTransactions()) { DB::getConn()->transactionStart(); } //Call the method $response = call_user_func_array(array($this, $method), $params); if ($response instanceof xmlrpcresp) { //If transactions are supported check the response and rollback in the case of a fault if (($method == 'newPost' || $method == 'editPost' || $method == 'newMediaObject') && DB::getConn()->supportsTransactions()) { if ($response->faultCode() != 0) { DB::getConn()->transactionRollback(); } else { DB::getConn()->transactionEnd(); } } return $response; //Response is already encoded so return } //Encode the response $response = php_xmlrpc_encode($response); if (is_object($response) && $response instanceof xmlrpcval) { $response = new xmlrpcresp($response); if (($method == 'newPost' || $method == 'editPost' || $method == 'newMediaObject') && DB::getConn()->supportsTransactions()) { if ($response->faultCode() != 0) { DB::getConn()->transactionRollback(); } else { DB::getConn()->transactionEnd(); } } return $response; } return $this->httpError(500, _t('KapostService.INVALID_RESPONSE', '_Invalid response returned from {method}, response was: {response}', array('method' => $method, 'response' => print_r($response, true)))); } return $this->httpError(401, _t('KapostService.AUTH_FAIL', '_Authentication Failed, please check the App Center credentials for the SilverStripe end point.')); }