Mercurial > hg > rlgwebd
diff webtty.js @ 13:bf7c26d0b66d
webtty: switch upward protocol to JSON
Switch the client-to-server messages from the HTML forms format to
JSON (for the webtty app). Message numbers are sent but not yet used.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Sun, 13 May 2012 20:50:13 -0700 |
parents | 481dcee353c9 |
children | 7466927c17a5 |
line wrap: on
line diff
--- a/webtty.js Sun May 13 08:47:35 2012 -0700 +++ b/webtty.js Sun May 13 20:50:13 2012 -0700 @@ -144,22 +144,14 @@ /* Returns the contents of a form */ function getFormValues(formtext) { - var pairstrs = formtext.split("&"); - var data = {}; - for (var i = 0; i < pairstrs.length; i++) - { - var eqsign = pairstrs[i].indexOf("="); - if (eqsign > 0) { - rawname = pairstrs[i].slice(0, eqsign); - rawval = pairstrs[i].slice(eqsign + 1); - name = urlDec(rawname); - val = urlDec(rawval); - if (!(name in data)) - data[name] = []; - data[name].push(val); - } + var jsonobj; + try { + jsonobj = JSON.parse(formtext); + } catch (e) { + if (e instanceof SyntaxError) + return null; } - return data; + return jsonobj; } function login(req, res, formdata) { @@ -298,14 +290,14 @@ sendError(res, 1); return; } - if (formdata["quit"] == "quit") { + if (formdata["t"] == "q") { /* The client wants to quit. */ // FIXME need to send a message back to the client cterm.close(); } - else if (formdata["keys"]) { + else if (formdata["t"] == "d" && typeof(formdata["d"]) == "string") { /* process the keys */ - hexstr = formdata["keys"][0].replace(/[^0-9a-f]/gi, ""); + hexstr = formdata["d"].replace(/[^0-9a-f]/gi, ""); if (hexstr.length % 2 != 0) { sendError(res, 2); return;