From ebb948c24e667f651fe882100cc478f0534b8760 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 18 Mar 2011 17:39:23 +0300 Subject: [PATCH] rework initial sanitycheck to use JSON --- backend.php | 19 +++++---------- errors.php | 4 ++-- functions.js | 18 ++++---------- functions.php | 23 +++--------------- modules/backend-rpc.php | 16 ++++++------- prefs.js | 17 -------------- tt-rss.js | 52 ----------------------------------------- 7 files changed, 22 insertions(+), 127 deletions(-) diff --git a/backend.php b/backend.php index 5839c0d2b..d13b2d62a 100644 --- a/backend.php +++ b/backend.php @@ -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": diff --git a/errors.php b/errors.php index cd76d10a6..12aeffe75 100644 --- a/errors.php +++ b/errors.php @@ -1,7 +1,7 @@ $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 ""; - print ""; - print ""; - } - /** * Subscribes the user to the given feed * diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index bb76fd168..ea1867e0c 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -307,23 +307,21 @@ return; } - // XML method if ($subop == "sanityCheck") { + header("Content-Type: text/plain"); $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; - print ""; - if (sanity_check($link)) { - print ""; + $reply = array(); - print ""; + $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 ""; + print json_encode($reply); return; } diff --git a/prefs.js b/prefs.js index 012e0432a..2d7f9dff1 100644 --- a/prefs.js +++ b/prefs.js @@ -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..."); diff --git a/tt-rss.js b/tt-rss.js index 3d0f53044..57b62c710 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -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) {