/** * Factory method that constructs the appropriate XML-RPC encoded type value * * @param mixed Value to be encode * @param string Explicit XML-RPC type as enumerated in the XML-RPC spec (defaults to automatically selected type) * @return mixed The encoded value */ public static function createFromNative($value, $explicitType) { $type = strtolower($explicitType); $availableTypes = array('datetime', 'base64', 'struct'); if (in_array($type, $availableTypes)) { if ($type == 'struct') { if (!is_array($value)) { throw new XML_RPC2_Exception('With struct type, value has to be an array'); } // Because of http://bugs.php.net/bug.php?id=21949 // is some cases (structs with numeric indexes), we need to be able to force the "struct" type // (xmlrpc_set_type doesn't help for this, so we need this ugly hack) $new = array(); while (list($k, $v) = each($value)) { $new["xml_rpc2_ugly_struct_hack_{$k}"] = $v; // with this "string" prefix, we are sure that the array will be seen as a "struct" } return $new; } $value2 = (string) $value; if (!xmlrpc_set_type($value2, $type)) { throw new XML_RPC2_Exception('Error returned from xmlrpc_set_type'); } return $value2; } return $value; }
/** {@inheritdoc} */ public function serialize($method, array $params = []) { $toBeVisited = [&$params]; while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) { $type = gettype($value); if ($type === 'array') { foreach ($value as &$child) { $toBeVisited[] =& $child; } } elseif ($type === 'object') { if ($value instanceof DateTime) { $value = $value->format('Ymd\\TH:i:s'); xmlrpc_set_type($value, 'datetime'); } elseif ($value instanceof Base64Interface) { $value = $value->getDecoded(); xmlrpc_set_type($value, 'base64'); } else { $value = get_object_vars($value); } } elseif ($type === 'resource') { throw SerializationException::invalidType($value); } array_shift($toBeVisited); } return xmlrpc_encode_request($method, $params, ['encoding' => 'UTF-8', 'escaping' => 'markup', 'verbosity' => 'no_white_space']); }
function xmlrpc_getText($method_name, $params) { $uid =& $params[0]; /* remote user (for snitch) */ $r_uid = addslashes($params[1]); /* is snitch enabled for the remote user? */ $isSnitch = $params[2]; # error_log(date("[m/d/Y h:i:s] ") . "planworld.plan.getText: L:${uid}, R:${r_uid}, S:${isSnitch} (${_SERVER['REMOTE_ADDR']})\n", 3, "/tmp/planworld.log"); $r_user = User::factory($r_uid); // error_log(date("[m/d/Y h:i:s] ") . "planworld.plan.getText: ${r_user->getUsername()}\n", 3, "/tmp/planworld.log"); if (is_string($uid) && Planworld::isUser(addslashes($uid))) { $user = User::factory($uid); } else { # error_log(date("[m/d/Y h:i:s] ") . "planworld.plan.getText: No such user: ${uid}\n", 3, "/tmp/planworld.log"); return array('faultCode' => 800, 'faultString' => 'No such user'); } if (!$user->getWorld()) { $err = "[This user's plan is not available]"; # error_log(date("[m/d/Y h:i:s] ") . "planworld.plan.getText: Plan not available: ${uid}\n", 3, "/tmp/planworld.log"); xmlrpc_set_type($err, 'base64'); /* $err used to be passed by reference but that is deprecated. --JLO2 */ return $err; } if ($isSnitch) { $user->addSnitchView($r_user); } $text = $user->getPlan($r_user); xmlrpc_set_type($text, 'base64'); return $text; }
/** * Fixes up */ protected function fixUpTypes($response) { if (is_array($response)) { foreach ($response as &$value) { $value = $this->fixUpTypes($value); } } if ($response instanceof DateTime) { $response = $response->format("Ymd\\TH:i:s"); xmlrpc_set_type($response, 'datetime'); } return $response; }
function dateChange($method_name, $params, $app_data) { $date_str = $params[0]->scalar; $date = strptime($date_str, "%Y%m%dT%H:%M:%S"); foreach ($params[1] as $name => $val) { if ($name == "date") { continue; } $date[$name] = $val; } $ret = sprintf("%04d%02d%02dT%02d:%02d:%02d", $date["tm_year"] + 1900, $date["tm_mon"] + 1, $date["tm_mday"], $date["tm_hour"], $date["tm_min"], $date["tm_sec"]); xmlrpc_set_type($ret, "datetime"); return $ret; }
function run_easy_tests($server, $debug = 0, $output = null) { global $decl_1, $decl_2, $decl_3, $decl_4; run_test($server, $debug, $output, "interopEchoTests.echoString", "That government is best, which governs least"); run_test($server, $debug, $output, "interopEchoTests.echoBoolean", true); run_test($server, $debug, $output, "interopEchoTests.echoInteger", 42); run_test($server, $debug, $output, "interopEchoTests.echoFloat", 3.1416); run_test($server, $debug, $output, "interopEchoTests.echoStruct", array("varFloat" => 1.2345, "varInt" => 186000, "varString" => "a string")); run_test($server, $debug, $output, "interopEchoTests.echoStringArray", array($decl_1, $decl_2, $decl_3, $decl_4)); run_test($server, $debug, $output, "interopEchoTests.echoIntegerArray", array(23, 234, 1, 0, -10, 999)); run_test($server, $debug, $output, "interopEchoTests.echoFloatArray", array(2.45, 9.9999)); run_test($server, $debug, $output, "interopEchoTests.echoStructArray", array(array("varFloat" => 1.2345, "varInt" => 186000, "varString" => "a string"), array("varFloat" => 10.98765, "varInt" => 3200, "varString" => "happy little string"))); $foo = "some base64 string"; xmlrpc_set_type(&$foo, "base64"); run_test($server, $debug, $output, "interopEchoTests.echoBase64", $foo); $foo = "19980717T14:08:55"; xmlrpc_set_type(&$foo, "datetime"); run_test($server, $debug, $output, "interopEchoTests.echoDate", $foo); run_no_param_test($server, $debug, $output, "interopEchoTests.noInParams"); }
/** * Add a parameter to the array of parameters. * * @param string $argument A transport ID, as defined in lib.php * @param string $type The argument type, can be one of: * none * empty * base64 * boolean * datetime * double * int * string * array * struct * In its weakly-typed wisdom, PHP will (currently) * ignore everything except datetime and base64 * @return bool True on success */ function add_param($argument, $type = 'string') { $allowed_types = array('none', 'empty', 'base64', 'boolean', 'datetime', 'double', 'int', 'i4', 'string', 'array', 'struct'); if (!in_array($type, $allowed_types)) { return false; } if ($type != 'datetime' && $type != 'base64') { $this->params[] = $argument; return true; } // Note weirdness - The type of $argument gets changed to an object with // value and type properties. // bool xmlrpc_set_type ( string &value, string type ) xmlrpc_set_type($argument, $type); $this->params[] = $argument; return true; }
<?php $params = date("Ymd\\TH:i:s", time()); xmlrpc_set_type($params, 'datetime'); echo xmlrpc_encode($params);
logDebug($uploadfile); $image_filename = basename($_FILES['Filedata']['name']); $media_id = ''; $error_msg = 'there was a problem with the server'; logDebug('number of files uploaded ' . count($_FILES)); foreach ($_FILES as $key => $value) { logDebug("Key: {$key}; Value: {$value}"); } /* here's where we actually do the work */ if ($auth[0] != null) { if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadfile)) { logDebug("File is valid, and was successfully uploaded."); /* open and read in the image file data */ $handle = fopen($uploadfile, "r"); $media_binary = fread($handle, filesize($uploadfile)); xmlrpc_set_type(&$media_binary, "base64"); fclose($handle); unlink($uploadfile); /* build the args for the XML-RPC query */ $zapi_query = array($image_filename, $image_filename, "", $media_binary); /* send it to the zoto server */ $result = zapi_call($zapi_key, $zapi_auth, $zapi_function, $zapi_query); if (is_array($result)) { foreach ($result as $key => $value) { logDebug("Key: {$key}; Value: {$value}"); } if ($result[0] == '0') { $upload_success = true; global $media_id; $media_id = $result[1]; } else {
function validatePDF_2($magic, $callback_URL, $fileID, $file) { global $hotdir, $max_processing_seconds, $INP, $NPDF_ERR, $NPDF, $ORIG_ERR, $ORIG_OK, $PROC_ERR, $PROC_OK, $REP_ERR, $REP_OK, $INP_absolute, $xmlrpc, $DEBUG; ignore_user_abort(); // function may take a long time set_time_limit($max_processing_seconds + 10); // does not work in safe mode ini_set("max_execution_time", $max_processing_seconds + 10); // does not work in safe mode if ($DEBUG) { informAdmin("DEBUG: called validatePDF_2( {$magic}, {$callback_URL}, {$fileID}, {$file} )"); } // security issue $file = basename($file); // to avoid s.th. like '../../../etc/passwd' // wait for pitstop to process the file $file_log = "{$file}_log.pdf"; // PitStop names reports like this $start_time = time(); while (file_exists(cleanPath("{$hotdir}/{$INP}/{$file}")) && $start_time + $max_processing_seconds > time()) { clearstatcache(); sleep(5); } // MISCONCEPTION - PitStop removes the input file before all other files have been written to disk. Especially the Report takes longer. // wait for report to appear $report_present = false; while (!$report_present && $start_time + $max_processing_seconds > time()) { clearstatcache(); $report_present = file_exists(cleanPath("{$hotdir}/{$REP_ERR}/{$file_log}")) || file_exists(cleanPath("{$hotdir}/{$REP_OK}/{$file_log}")) || file_exists(cleanPath("{$hotdir}/{$NPDF_ERR}/{$file_log}")); sleep(5); } if ($start_time + $max_processing_seconds <= time()) { // cleanup - not all files will be present, thus neglect warnings cleanup($file); informAdmin("validation tooks too long. PitStop server not running? HotDir is '{$hotdir}' and input folder is named '{$INP}'"); return false; // validation tooks too long } sleep(5); // let PitStop write all files clearstatcache(); $valid = 2; // validation was aborted // PitStop has removed the file, now check the result if (file_exists(cleanPath("{$hotdir}/{$NPDF}/{$file}"))) { $reportFileName = cleanPath("{$hotdir}/{$NPDF_ERR}/{$file_log}"); $valid = false; } if (file_exists(cleanPath("{$hotdir}/{$ORIG_ERR}/{$file}"))) { $reportFileName = cleanPath("{$hotdir}/{$REP_ERR}/{$file_log}"); $valid = false; } if (file_exists(cleanPath("{$hotdir}/{$ORIG_OK}/{$file}"))) { $reportFileName = cleanPath("{$hotdir}/{$REP_OK}/{$file_log}"); $valid = true; } if ($valid === 2) { // cleanup - not all files will be present, thus neglect warnings cleanup($file); informAdmin("validation was aborted. Input file was removed, but result is not present."); return false; } if ($DEBUG) { if ($valid) { $temp = "pdf file is valid"; } else { $temp = "file is not valid"; } informAdmin("DEBUG: validation process completed.\n{$temp}"); } // PitStop may produce reports with 350 pages and more. These reports can be as large as 8 MiB. // If pdftk (http://www.pdftk.com) is available, truncate the report; otherwise do not send, if too large $data = truncate_pdf($reportFileName); // call the callback function to announce results of validation $server = parse_url($callback_URL); $server['port'] = $server['port'] ? $server['port'] : 80; if ($xmlrpc['pear']) { // use XML_RPC impl. to contact the callback function, which in turn will commit the result to the database $client = new XML_RPC_Client($server['path'], $server['host'], $server['port']); $params = array(new XML_RPC_Value($data, 'base64'), new XML_RPC_Value($valid, 'boolean'), new XML_RPC_Value($magic, 'int'), new XML_RPC_Value($fileID, 'int')); $xmlrpc_message = new XML_RPC_Message('validatePDF_callback', $params); if ($DEBUG) { $client->setDebug(1); ob_start(); } $client->send($xmlrpc_message); if ($DEBUG) { informAdmin("server reports:\n" . ob_get_contents()); ob_end_clean(); } } elseif ($xmlrpc['internal']) { // use internal impl. to contact the callback function, which in turn will commit the result to the database xmlrpc_set_type($data, "base64"); // converts the string to an object with encoding 'base64' $params = array($data, $valid, $magic, $fileID); $output = array('output_type' => 'php'); xu_rpc_http_concise(array(method => 'validatePDF_callback', args => $params, host => $server['host'], uri => $server['path'], port => $server['port'], debug => 0, output => $output)); } if ($DEBUG) { informAdmin("DEBUG: callback function validatePDF_callback() at {$callback_URL} was called."); } // cleanup - not all files will be present, thus neglect warnings cleanup($file); }
<?php $a = '~~~~~~~~~~~~~~~~~~'; $ok = xmlrpc_set_type($a, 'datetime'); var_dump($ok); echo "Done\n";
<?php $d = date(DATE_ISO8601); xmlrpc_set_type($d, 'datetime'); echo xmlrpc_encode_request('method.call', array('date' => $d)); $d = '2008-01-01 20:00:00'; xmlrpc_set_type($d, 'datetime'); echo xmlrpc_encode_request('method.call', array('date' => $d));
/** * Set the correct type for each element in an array * * @param array $array * * @since 2.2 */ private function _setXmlrpcType(&$array) { foreach ($array as $key => $element) { if (is_a($element, '\\DateTime')) { $array[$key] = $element->format("Ymd\\TH:i:sO"); xmlrpc_set_type($array[$key], 'datetime'); } elseif (is_array($element)) { $this->_setXmlrpcType($array[$key]); } } }
/** * @param mixed $value * @param string $type base64 or datetime * @return bool */ public static function setType(&$value, $type) { xmlrpc_set_type($value, $type); }
/** * Return a Trans object so that a potentially non XML-safe string can be sent * into the XML-RPC stream. * e.g. a password can contains the & character, so the password string must be encoded. */ function prepare_string($pass) { xmlrpc_set_type($pass, 'base64'); return $pass; }
} end_test('Data encoding (large array)', 'manual encoding', $out); begin_test('Data encoding (large array)', 'automatic encoding'); $encoder = new Encoder(); for ($i = 0; $i < $num_tests; $i++) { $value = $encoder->encode($data, array('auto_dates')); $out = $value->serialize(); } end_test('Data encoding (large array)', 'automatic encoding', $out); 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 Request(''); $out = new Response($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();
/** * This method returns an XML-RPC base64 object from a given binary string. * * @param string $binary * * @return object */ public static function base64($binary) { xmlrpc_set_type($binary, 'base64'); return $binary; }