]> git.wh0rd.org Git - tt-rss.git/commitdiff
rework initial sanitycheck to use JSON
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 18 Mar 2011 14:39:23 +0000 (17:39 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 18 Mar 2011 14:39:23 +0000 (17:39 +0300)
backend.php
errors.php
functions.js
functions.php
modules/backend-rpc.php
prefs.js
tt-rss.js

index 5839c0d2b2a650009a7fff26d8a08c0f6c2d77f5..d13b2d62a474481048c386ba1ab967787e898b02 100644 (file)
                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") {
 
        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":
index cd76d10a680261f72e74832cb63724306731b598..12aeffe751943c219d9c65eed4442573f73bf7f0 100644 (file)
@@ -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]";
index 411c82494d6d08958e269a273ebce893880a82be..ba82ebe111b731214231bca2e0c28864cf406358 100644 (file)
@@ -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];
index b0c768ff8b77a14d377f508cd854f4964d82233d..1e9e5a576701ae14ba5d10c253714052cf7677b7 100644 (file)
 
        function sanity_check($link) {
 
+               global $ERRORS;
+
                $error_code = 0;
                $schema_version = get_schema_version($link);
 
                        $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) {
                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
         *
index bb76fd168affc77f1b38f921c1a672ec03205d51..ea1867e0c4e2dc04739434f40f5896d1ff81b94a 100644 (file)
                        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;
                }
 
index 012e0432a97bce593225c60c7014dfcc69e08d07..2d7f9dff1697d2429e380ee69757bf59815b8d86 100644 (file)
--- 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...");
index 3d0f53044b8e4993b9cc5824901e2c0d154ccd0d..57b62c71068c38b13975e4277fd3e15eb23eb923 100644 (file)
--- 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) {