summaryrefslogtreecommitdiff
path: root/jsonrpc
diff options
context:
space:
mode:
Diffstat (limited to 'jsonrpc')
-rw-r--r--jsonrpc/json.esp28
-rw-r--r--jsonrpc/jsondate.esp6
-rw-r--r--jsonrpc/request.esp55
3 files changed, 32 insertions, 57 deletions
diff --git a/jsonrpc/json.esp b/jsonrpc/json.esp
index ad0e13a6c3..32f0fa776a 100644
--- a/jsonrpc/json.esp
+++ b/jsonrpc/json.esp
@@ -37,6 +37,11 @@ function _escape(s)
}
}
+ if (arr.length == 0)
+ {
+ return "";
+ }
+
return join("", arr);
}
@@ -72,10 +77,14 @@ function _encode(o)
}
else if (type == "float" ||
type == "integer" ||
- type == "integer64" ||
- type == "pointer")
+ type == "integer64")
+ {
+ return o + 0;
+ }
+ else if (type == "pointer")
{
- return (o + 0);
+ var x = "" + o;
+ return '"' + substr(x, 16, strlen(x) - 16 - 1) + '"';
}
else if (type == "object")
{
@@ -128,6 +137,10 @@ function _encode(o)
{
return '"' + this._internal.escape(o) + '"';
}
+ else
+ {
+ return '{ "unknown_object":"' + type + '"}';
+ }
}
/* Allocate the public Json access object */
@@ -193,6 +206,7 @@ Json._internal.convert['\x1f'] = '\\u001f';
/* Test it */
+/*
libinclude("base.js");
function testFormat()
{
@@ -211,7 +225,11 @@ function testFormat()
test.obj.array[1] = 223;
printf("%s\n", Json.encode(test));
}
+testFormat();
+*/
+/*
+libinclude("base.js");
function testParse()
{
var s;
@@ -236,8 +254,6 @@ function testParse()
obj = Json.decode(s);
printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj));
}
-
-//testFormat();
testParse();
-
+*/
%>
diff --git a/jsonrpc/jsondate.esp b/jsonrpc/jsondate.esp
index af2c7e2e3f..b2f2b9ec11 100644
--- a/jsonrpc/jsondate.esp
+++ b/jsonrpc/jsondate.esp
@@ -78,7 +78,7 @@ function _JSON_Date_create(secondsSinceEpoch)
if (typeof(secondsSinceEpoch) != "number")
{
- var currentTime = getTimeOfDay();
+ var currentTime = gettimeofday();
secondsSinceEpoch = currentTime.sec;
microseconds = currentTime.usec;
}
@@ -105,7 +105,7 @@ function _JSON_Date_create(secondsSinceEpoch)
{
return this.month;
}
- o.getUtcMonth = getUtcMonth;
+ o.getUtcMonth = _getUtcMonth;
function _getUtcDay()
{
@@ -167,7 +167,7 @@ function _JSON_Date_create(secondsSinceEpoch)
if (! secondsSinceEpoch)
{
- var now = getTimeOfDay();
+ var now = gettimeofday();
o.setEpochTime(now.sec);
}
else
diff --git a/jsonrpc/request.esp b/jsonrpc/request.esp
index a8080d9dc7..d58a00069c 100644
--- a/jsonrpc/request.esp
+++ b/jsonrpc/request.esp
@@ -14,6 +14,7 @@
*/
/* Bring in the date class */
+jsonrpc_include("json.esp");
jsonrpc_include("jsondate.esp");
/* bring the string functions into the global frame */
@@ -28,12 +29,6 @@ function printf()
}
-/* KLUDGE... */
-form = new Array();
-server = new Array();
-request = new Array();
-/* ...KLUDGE */
-
/*
* All of our manipulation of JSON RPC methods will be through this object.
* Each class of methods will assign to here, and all of the constants will
@@ -147,7 +142,7 @@ function sendReply(reply, scriptTransportId)
if (scriptTransportId == jsonrpc.Constant.ScriptTransport.NotInUse)
{
/* ... then just output the reply. */
- printf(reply);
+ write(reply);
}
else
{
@@ -156,43 +151,11 @@ function sendReply(reply, scriptTransportId)
"qx.io.remote.ScriptTransport._requestFinished(" +
scriptTransportId + ", " + reply +
");";
- printf(reply);
+ write(reply);
}
}
-/*
- * class Json
- *
- * This class provides the JSON encoder and decoder, and some utility
- * functions.
- */
-Json = new Object();
-
-/* KLUDGE... */
-function _jsonDecode(s)
-{
- var o = new Object();
- o.id = 23;
- o.service = "qooxdoo.test";
- o.method = "echo";
- o.params = new Array(1);
- o.params[0] = "hello world";
- return o;
-}
-/* ...KLUDGE */
-
-Json.decode = _jsonDecode;
-
-/* KLUDGE... */
-function _jsonEncode(o)
-{
- return "{ result: \"hello world\" }"
-}
-/* ...KLUDGE */
-
-Json.encode = _jsonEncode;
-
function _jsonValidRequest(req)
{
if (req == undefined)
@@ -300,14 +263,14 @@ error = jsonrpc.createError(jsonrpc.Constant.ErrorOrigin.Server,
scriptTransportId = jsonrpc.Constant.ScriptTransport.NotInUse;
/* What type of request did we receive? */
-if (server["REQUEST_METHOD"] == "POST" &&
- server["CONENT_TYPE"] == "text/json")
+if (request["REQUEST_METHOD"] == "POST" &&
+ request["CONTENT_TYPE"] == "text/json")
{
/* We found literal POSTed json-rpc data (we hope) */
input = request["POST_DATA"];
jsonInput = Json.decode(input);
}
-else if (server["REQUEST_METHOD"] == "GET" &&
+else if (request["REQUEST_METHOD"] == "GET" &&
form["_ScriptTransport_id"] != undefined &&
form["_ScriptTransport_data"] != undefined)
{
@@ -318,10 +281,6 @@ else if (server["REQUEST_METHOD"] == "GET" &&
jsonInput = Json.decode(input);
}
-/* KLUDGE... */
-jsonInput = Json.decode(input);
-/* ...KLUDGE */
-
/* Ensure that this was a JSON-RPC service request */
if (! jsonrpc.validRequest(jsonInput))
{
@@ -329,7 +288,7 @@ if (! jsonrpc.validRequest(jsonInput))
* This request was not issued with JSON-RPC so echo the error rather than
* issuing a JsonRpcError response.
*/
- printf("JSON-RPC request expected; service, method or params missing<br>");
+ write("JSON-RPC request expected; service, method or params missing<br>");
return;
}