diff options
author | Derrell Lipman <derrell@samba.org> | 2006-10-07 20:31:27 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:20:47 -0500 |
commit | 1c681891b2d00a21efa02488d80bc48c3ddab783 (patch) | |
tree | 78f22179fa1252491d5f7ac04f294569df52be55 /source4/web_server | |
parent | 7c793e1bb74593357708e92dba6a99d89ac77c59 (diff) | |
download | samba-1c681891b2d00a21efa02488d80bc48c3ddab783.tar.gz samba-1c681891b2d00a21efa02488d80bc48c3ddab783.tar.bz2 samba-1c681891b2d00a21efa02488d80bc48c3ddab783.zip |
r19165: handle errors better for jsonrpc. generate an error object whenever possible
(This used to be commit aa8e4227a11d997f7c4c5af2b7a3c7c371b8c1cd)
Diffstat (limited to 'source4/web_server')
-rw-r--r-- | source4/web_server/http.c | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/source4/web_server/http.c b/source4/web_server/http.c index f9867a152a..4aef4a1dc8 100644 --- a/source4/web_server/http.c +++ b/source4/web_server/http.c @@ -528,7 +528,21 @@ static void esp_request(struct esp_state *esp, const char *url) */ 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 @@ static void jsonrpc_request(struct esp_state *esp) } /* 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); } /* |