summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/ejs/smbcalls.c1
-rw-r--r--source4/web_server/http.c47
2 files changed, 46 insertions, 2 deletions
diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c
index b0df390427..62a956bb96 100644
--- a/source4/scripting/ejs/smbcalls.c
+++ b/source4/scripting/ejs/smbcalls.c
@@ -193,6 +193,7 @@ static int jsonrpc_include(int eid, int argc, char **argv)
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);
}
}
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);
}
/*