svn commit: samba r19165 - in branches/SAMBA_4_0/source:
scripting/ejs web_server
derrell at samba.org
derrell at samba.org
Sat Oct 7 20:31:27 GMT 2006
Author: derrell
Date: 2006-10-07 20:31:27 +0000 (Sat, 07 Oct 2006)
New Revision: 19165
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19165
Log:
handle errors better for jsonrpc. generate an error object whenever possible
Modified:
branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c
branches/SAMBA_4_0/source/web_server/http.c
Changeset:
Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c 2006-10-07 10:33:33 UTC (rev 19164)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c 2006-10-07 20:31:27 UTC (rev 19165)
@@ -193,6 +193,7 @@
if (file_exist(path)) {
ret = ejsEvalFile(eid, path, &result, &emsg);
if (ret < 0) {
+ ejsSetErrorMsg(eid, "Could not eval file");
printf("file found; ret=%d (%s)\n", ret, emsg);
}
}
Modified: branches/SAMBA_4_0/source/web_server/http.c
===================================================================
--- branches/SAMBA_4_0/source/web_server/http.c 2006-10-07 10:33:33 UTC (rev 19164)
+++ branches/SAMBA_4_0/source/web_server/http.c 2006-10-07 20:31:27 UTC (rev 19165)
@@ -528,7 +528,21 @@
*/
static void jsonrpc_request(struct esp_state *esp)
{
- const char *path = http_local_path(esp->web, JSONRPC_SERVER);
+ struct websrv_context *web = esp->web;
+ const char *path = http_local_path(web, JSONRPC_SERVER);
+ MprVar *global;
+ MprVar v;
+ MprVar temp;
+ int size;
+ int res;
+ char *emsg = NULL;
+ char *emsg2 = NULL;
+ char *buf;
+ char *error_script =
+ "error.setOrigin(jsonrpc.Constant.ErrorOrigin.Server); "
+ "error.setError(jsonrpc.Constant.ErrorCode.UnexpectedOutput, "
+ " global.errorString);"
+ "error.Send();";
/* Ensure we got a valid path. */
if (path == NULL) {
@@ -544,7 +558,36 @@
}
/* Call the server request script */
- esp_request(esp, JSONRPC_SERVER);
+ if (http_readFile(web, &buf, &size, JSONRPC_SERVER) != 0) {
+ http_error_unix(web, JSONRPC_SERVER);
+ return;
+ }
+
+#if HAVE_SETJMP_H
+ if (setjmp(ejs_exception_buf) != 0) {
+ http_error(web, 500, exception_reason);
+ return;
+ }
+#endif
+
+ res = espProcessRequest(esp->req, JSONRPC_SERVER, buf, &emsg);
+ if (res != 0 && emsg) {
+ /* Save the error in a string accessible from javascript */
+ global = ejsGetGlobalObject(0);
+ v = mprString(emsg);
+ mprCreateProperty(global, "errorString", &v);
+
+ /* Create and send a JsonRpcError object */
+ if (ejsEvalScript(0,
+ error_script,
+ &temp,
+ &emsg2) != 0) {
+ http_writeBlock(web, "<pre>", 5);
+ http_writeBlock(web, emsg, strlen(emsg));
+ http_writeBlock(web, "</pre>", 6);
+ }
+ }
+ talloc_free(buf);
}
/*
More information about the samba-cvs
mailing list