Source for file rpc.php
Documentation is available at rpc.php
* $Id: rpc.php,v 1.1 2009/08/07 01:59:36 sam2kb Exp $
* @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
require_once("./includes/general.php");
// Set RPC response headers
header('Content-Type: text/plain');
header('Content-Encoding: UTF-8');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " .
gmdate("D, d M Y H:i:s") .
" GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
if (isset
($_POST["json_data"]))
if (!$raw && isset
($_GLOBALS) && isset
($_GLOBALS["HTTP_RAW_POST_DATA"]))
$raw =
$_GLOBALS["HTTP_RAW_POST_DATA"];
if (!$raw && isset
($HTTP_RAW_POST_DATA))
$raw =
$HTTP_RAW_POST_DATA;
$fp =
fopen("php://input", "r");
die('{"result":null,"id":null,"error":{"errstr":"Could not get raw post data.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}');
// Passthrough request to remote server
if (isset
($config['general.remote_rpc_url'])) {
$url =
parse_url($config['general.remote_rpc_url']);
$req =
"POST " .
$url["path"] .
" HTTP/1.0\r\n";
$req .=
"Connection: close\r\n";
$req .=
"Host: " .
$url['host'] .
"\r\n";
$req .=
"Content-Length: " .
strlen($raw) .
"\r\n";
if (!isset
($url['port']) ||
!$url['port'])
$socket =
fsockopen($url['host'], intval($url['port']), $errno, $errstr, 30);
// Read response headers and data
$resp .=
fgets($socket, 4096);
// Split response header/data
$resp =
explode("\r\n\r\n", $resp);
echo
$resp[1]; // Output body
$input =
$json->decode($raw);
if (isset
($config['general.engine'])) {
$spellchecker =
new $config['general.engine']($config);
die('{"result":null,"id":null,"error":{"errstr":"You must choose an spellchecker engine in the config.php file.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}');
// Request and response id should always be the same
// Return JSON encoded string
echo
$json->encode($output);