diff options
Diffstat (limited to 'services/request.esp')
-rw-r--r-- | services/request.esp | 87 |
1 files changed, 62 insertions, 25 deletions
diff --git a/services/request.esp b/services/request.esp index 6f7e61e6e4..ae106be8ea 100644 --- a/services/request.esp +++ b/services/request.esp @@ -13,7 +13,6 @@ * This is a simple JSON-RPC server. */ - /* Bring in the json format/parse functions */ jsonrpc_include("json.esp"); @@ -30,6 +29,10 @@ string_init(global); /* Bring the system functions into the global frame */ sys_init(global); +/* Bring the session functions into the global frame */ +system_session(global); + + function printf() { print(vsprintf(arguments)); @@ -44,7 +47,7 @@ function printf() jsonrpc = new Object(); jsonrpc.Constant = new Object(); jsonrpc.Constant.ErrorOrigin = new Object(); /* error origins */ -jsonrpc.Constant.ErrorCode = new Object(); /* server-generated error codes */ +jsonrpc.Constant.ServerError = new Object(); /* server-generated error codes */ jsonrpc.method = new Object(); /* methods available in requested class */ /* @@ -74,7 +77,7 @@ jsonrpc.Constant.ErrorOrigin.Client = 4; * The default error code, used only when no specific error code is passed to * the JsonRpcError constructor. This code should generally not be used. */ -jsonrpc.Constant.ErrorCode.Unknown = 0; +jsonrpc.Constant.ServerError.Unknown = 0; /** * Error code, value 1: Illegal Service @@ -82,14 +85,14 @@ jsonrpc.Constant.ErrorCode.Unknown = 0; * The service name contains illegal characters or is otherwise deemed * unacceptable to the JSON-RPC server. */ -jsonrpc.Constant.ErrorCode.IllegalService = 1; +jsonrpc.Constant.ServerError.IllegalService = 1; /** * Error code, value 2: Service Not Found * * The requested service does not exist at the JSON-RPC server. */ -jsonrpc.Constant.ErrorCode.ServiceNotFound = 2; +jsonrpc.Constant.ServerError.ServiceNotFound = 2; /** * Error code, value 3: Class Not Found @@ -99,14 +102,14 @@ jsonrpc.Constant.ErrorCode.ServiceNotFound = 2; * detailed than "Method Not Found", but that error would always also be legal * (and true) whenever this one is returned. (Not used in this implementation) */ -jsonrpc.Constant.ErrorCode.ClassNotFound = 3; // not used in this implementation +jsonrpc.Constant.ServerError.ClassNotFound = 3; /** * Error code, value 4: Method Not Found * * The method specified in the request is not found in the requested service. */ -jsonrpc.Constant.ErrorCode.MethodNotFound = 4; +jsonrpc.Constant.ServerError.MethodNotFound = 4; /* * Error code, value 5: Parameter Mismatch @@ -118,7 +121,7 @@ jsonrpc.Constant.ErrorCode.MethodNotFound = 4; * This error is also used to indicate an illegal parameter value, in server * scripts. */ -jsonrpc.Constant.ErrorCode.ParameterMismatch = 5; +jsonrpc.Constant.ServerError.ParameterMismatch = 5; /** * Error code, value 6: Permission Denied @@ -129,23 +132,50 @@ jsonrpc.Constant.ErrorCode.ParameterMismatch = 5; * authentication. If the caller has not properly authenticated to use the * requested method, this error code is returned. */ -jsonrpc.Constant.ErrorCode.PermissionDenied = 6; +jsonrpc.Constant.ServerError.PermissionDenied = 6; + +/*** Errors generated by this server which are not qooxdoo-standard ***/ /* - * Error code, value 7: Unexpected Output + * Error code, value 1000: Unexpected Output * * The called method illegally generated output to the browser, which would * have preceeded the JSON-RPC data. */ -jsonrpc.Constant.ErrorCode.UnexpectedOutput = 7; +jsonrpc.Constant.ServerError.UnexpectedOutput = 1000; /* - * Error code, value 8: Resource Error + * Error code, value 1001: Resource Error * * Too many resources were requested, a system limitation on the total number * of resources has been reached, or a resource or resource id was misused. */ -jsonrpc.Constant.ErrorCode.ResourceError = 8; +jsonrpc.Constant.ServerError.ResourceError = 1001; + +/* + * Error code, value 1002: Not Logged In + * + * The user has logged out and must re-authenticate, or this is a brand new + * session and the user must log in. + * + */ +jsonrpc.Constant.ServerError.NotLoggedIn = 1002; + +/* + * Error code, value 1003: Session Expired + * + * The session has expired and the user must re-authenticate. + * + */ +jsonrpc.Constant.ServerError.SessionExpired = 1003; + +/* + * Error code, value 1004: Login Failed + * + * An attempt to log in failed. + * + */ +jsonrpc.Constant.ServerError.LoginFailed = 1004; @@ -250,6 +280,14 @@ function _JsonRpcError_create(origin, code, message) } o.setScriptTransportId = _setScriptTransportId; + function _setInfo(info) + { + // Add the info field only if info is actually provided. + // This is an extension to qooxdoo's normal Error return value. + this.data.info = info; + } + o.setInfo = _setInfo; + function _Send() { var error = this; @@ -276,7 +314,7 @@ var jsonInput = null; /* Allocate a generic error object */ error = jsonrpc.createError(jsonrpc.Constant.ErrorOrigin.Server, - jsonrpc.Constant.ErrorCode.Unknown, + jsonrpc.Constant.ServerError.Unknown, "Unknown error"); /* Assume (default) we're not using ScriptTransport */ @@ -329,7 +367,7 @@ var nameFirstLetter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* - * Ensure the method name is kosher. A meethod name should be: + * Ensure the method name is kosher. A method name should be: * * - first character is in [a-zA-Z] * - other characters are in [_a-zA-Z0-9] @@ -339,7 +377,7 @@ var nameFirstLetter = if (strspn(jsonInput.method, nameChars) != strlen(jsonInput.method)) { /* There's some illegal character in the service name */ - error.setError(jsonrpc.Constant.ErrorCode.MethodNotFound, + error.setError(jsonrpc.Constant.ServerError.MethodNotFound, "Illegal character found in method name."); error.Send(); return; @@ -348,7 +386,7 @@ if (strspn(jsonInput.method, nameChars) != strlen(jsonInput.method)) /* Now ensure that it begins with a letter */ if (strspn(substr(jsonInput.method, 0, 1), nameFirstLetter) != 1) { - error.setError(jsonrpc.Constant.ErrorCode.MethodNotFound, + error.setError(jsonrpc.Constant.ServerError.MethodNotFound, "The method name does not begin with a letter"); error.Send(); return; @@ -366,7 +404,7 @@ if (strspn(substr(jsonInput.method, 0, 1), nameFirstLetter) != 1) if (strspn(jsonInput.service, "." + nameChars) != strlen(jsonInput.service)) { /* There's some illegal character in the service name */ - error.setError(jsonrpc.Constant.ErrorCode.IllegalService, + error.setError(jsonrpc.Constant.ServerError.IllegalService, "Illegal character found in service name."); error.Send(); return; @@ -381,7 +419,7 @@ if (strspn(jsonInput.service, "." + nameChars) != strlen(jsonInput.service)) */ if (typeof(strstr(jsonInput.service, "..")) != "pointer") { - error.setError(jsonrpc.Constant.ErrorCode.IllegalService, + error.setError(jsonrpc.Constant.ServerError.IllegalService, "Illegal use of two consecutive dots in service name"); error.Send(); return; @@ -395,7 +433,7 @@ for (var i = 0; i < serviceComponents.length; i++) { if (strspn(substr(serviceComponents[i], 0, 1), nameFirstLetter) != 1) { - error.setError(jsonrpc.Constant.ErrorCode.IllegalService, + error.setError(jsonrpc.Constant.ServerError.IllegalService, "A service name component does not begin with a letter"); error.Send(); return; @@ -413,7 +451,7 @@ var servicePath = join("/", serviceComponents) + ".esp"; if (jsonrpc_include(servicePath)) { /* Couldn't find the requested service */ - error.setError(jsonrpc.Constant.ErrorCode.ServiceNotFound, + error.setError(jsonrpc.Constant.ServerError.ServiceNotFound, "Service class `" + servicePath + "` does not exist."); error.Send(); return; @@ -451,7 +489,7 @@ if (valid) if (! valid) { - error.setError(jsonrpc.Constant.ErrorCode.MethodNotFound, + error.setError(jsonrpc.Constant.ServerError.MethodNotFound, "Method `" + jsonInput.method + "` not found."); error.Send(); return; @@ -467,10 +505,9 @@ if (! valid) */ if (! json_authenticate(serviceComponents, jsonInput.method, - scriptTransportId)) + scriptTransportId, + error)) { - error.setError(jsonrpc.Constant.ErrorCode.PermissionDenied, - "Permission denied"); error.Send(); return; } |