]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
r19165: handle errors better for jsonrpc. generate an error object whenever possible
authorDerrell Lipman <derrell@samba.org>
Sat, 7 Oct 2006 20:31:27 +0000 (20:31 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:20:47 +0000 (14:20 -0500)
(This used to be commit aa8e4227a11d997f7c4c5af2b7a3c7c371b8c1cd)

source4/scripting/ejs/smbcalls.c
source4/web_server/http.c

index b0df390427f7ba441430daa82ce31dd46acffcf7..62a956bb96e301e0d25fc2119925418a501ea44f 100644 (file)
@@ -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);
                 }
         }
index f9867a152a4bc94d4038d9766ea6342cc5870377..4aef4a1dc881ada2f265c8e38808d192d71d8897 100644 (file)
@@ -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);
 }
 
 /*