rework initial sanitycheck to use JSON

master
Andrew Dolgov 14 years ago
parent 81f6deea47
commit ebb948c24e

@ -69,18 +69,6 @@
authenticate_user($link, "admin", null);
}
/* if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
&& $op != "rss" && $op != "getUnread" && $op != "publish" && $op != "getProfiles") {
if ($op == "rpc" || $op == "viewfeed" || $op == "view") {
print_error_xml(6); exit;
} else {
header("Location: tt-rss.php?return=" .
urlencode($_SERVER['REQUEST_URI']));
}
exit;
} */
if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" &&
$op != "rss" && $op != "getUnread" && $op != "getProfiles") {
@ -144,7 +132,12 @@
require_once "modules/pref-labels.php";
require_once "modules/pref-users.php";
if (!sanity_check($link)) { return; }
$error = sanity_check($link);
if ($error['code'] != 0) {
print json_encode(array("error" => $error));
return;
}
switch($op) { // Select action according to $op value.
case "rpc":

@ -1,7 +1,7 @@
<?php
require_once "functions.php";
$ERRORS[0] = __("Unknown error");
$ERRORS[0] = "";
$ERRORS[1] = __("This program requires XmlHttpRequest " .
"to function properly. Your browser doesn't seem to support it.");
@ -25,7 +25,7 @@
$ERRORS[9] = __("Configuration check failed");
$ERRORS[10] = __("Your version of MySQL is not currently supported. Please see
$ERRORS[10] = __("Your version of MySQL is not currently supported. Please see
official site for more information.");
$ERRORS[11] = "[This error is not returned by server]";

@ -1055,36 +1055,26 @@ function backend_sanity_check_callback(transport) {
return;
}
if (!transport.responseXML) {
if (!store) {
fatalError(3, "Sanity check: Received reply is not XML",
transport.responseText);
return;
}
}
var reply = transport.responseXML.getElementsByTagName("error")[0];
var reply = JSON.parse(transport.responseText);
if (!reply) {
fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
return;
}
var error_code = reply.getAttribute("error-code");
var error_code = reply['error']['code'];
if (error_code && error_code != 0) {
return fatalError(error_code, reply.getAttribute("error-msg"));
return fatalError(error_code, reply['error']['message']);
}
console.log("sanity check ok");
var params = transport.responseXML.getElementsByTagName("init-params")[0];
var params = reply['init-params'];
if (params) {
console.log('reading init-params...');
params = JSON.parse(params.firstChild.nodeValue);
if (params) {
for (k in params) {
var v = params[k];

@ -2227,6 +2227,8 @@
function sanity_check($link) {
global $ERRORS;
$error_code = 0;
$schema_version = get_schema_version($link);
@ -2245,12 +2247,7 @@
$error_code = 12;
}
if ($error_code != 0) {
print_error_xml($error_code);
return false;
} else {
return true;
}
return array("code" => $error_code, "message" => $ERRORS[$error_code]);
}
function file_is_locked($filename) {
@ -2851,20 +2848,6 @@
return $version[1];
}
function print_error_xml($code, $add_msg = "") {
global $ERRORS;
$error_msg = $ERRORS[$code];
if ($add_msg) {
$error_msg = "$error_msg; $add_msg";
}
print "<rpc-reply>";
print "<error error-code=\"$code\" error-msg=\"$error_msg\"/>";
print "</rpc-reply>";
}
/**
* Subscribes the user to the given feed
*

@ -307,23 +307,21 @@
return;
}
// XML method
if ($subop == "sanityCheck") {
header("Content-Type: text/plain");
$_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
print "<rpc-reply>";
if (sanity_check($link)) {
print "<error error-code=\"0\"/>";
$reply = array();
print "<init-params><![CDATA[";
print json_encode(make_init_params($link));
print "]]></init-params>";
$reply['error'] = sanity_check($link);
print_runtime_info($link);
if ($reply['error']['code'] == 0) {
$reply['init-params'] = make_init_params($link);
$reply['runtime-info'] = make_runtime_info($link);
}
print "</rpc-reply>";
print json_encode($reply);
return;
}

@ -1539,23 +1539,6 @@ function clearFeedAccessKeys() {
return false;
}
function handle_rpc_reply(transport, scheduled_call) {
try {
if (transport.responseXML) {
if (!transport_error_check(transport)) return false;
} else {
notify_error("Error communicating with server.");
}
} catch (e) {
exception_error("handle_rpc_reply", e, transport);
}
return true;
}
function resetFeedOrder() {
try {
notify_progress("Loading, please wait...");

@ -1022,58 +1022,6 @@ function showFeedsWithErrors() {
displayDlg('feedUpdateErrors');
}
function handle_rpc_reply(transport, scheduled_call) {
try {
if (transport.responseXML) {
if (!transport_error_check(transport)) return false;
var seq = transport.responseXML.getElementsByTagName("seq")[0];
if (seq) {
seq = seq.firstChild.nodeValue;
if (get_seq() != seq) {
//console.log("[handle_rpc_reply] sequence mismatch: " + seq);
return true;
}
}
var message = transport.responseXML.getElementsByTagName("message")[0];
if (message) {
message = message.firstChild.nodeValue;
if (message == "UPDATE_COUNTERS") {
console.log("need to refresh counters...");
setInitParam("last_article_id", -1);
_force_scheduled_update = true;
}
}
var counters = transport.responseXML.getElementsByTagName("counters")[0];
if (counters)
parse_counters(JSON.parse(counters.firstChild.nodeValue), scheduled_call);
var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
if (runtime_info)
parse_runtime_info(JSON.parse(runtime_info.firstChild.nodeValue));
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
} else {
notify_error("Error communicating with server.");
}
} catch (e) {
exception_error("handle_rpc_reply", e, transport);
}
return true;
}
function scheduleFeedUpdate(id, is_cat) {
try {
if (!id) {

Loading…
Cancel
Save