diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/scripting/ejs/smbcalls.c | 33 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_sys.c | 2 | ||||
-rw-r--r-- | source4/web_server/http.c | 46 |
3 files changed, 70 insertions, 11 deletions
diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index 839ec7b634..815b3e2b5d 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -203,6 +203,38 @@ static int jsonrpc_include(int eid, int argc, char **argv) } +static int ejs_debug(int eid, int argc, char **argv) +{ + int i; + int level; + void *ctx = mprMemCtx(); + char *msg; + + + if (argc < 2) { + return -1; + } + + level = atoi(argv[0]); + + msg = talloc_zero_size(ctx, 1); + if (msg == NULL) { + DEBUG(0, ("out of memory in debug()\n")); + return 0; + } + + for (i = 1; i < argc; i++) { + msg = talloc_append_string(ctx, msg, argv[i]); + if (msg == NULL) { + DEBUG(0, ("out of memory in debug()\n")); + return 0; + } + } + + DEBUG(level, ("%s", msg)); + talloc_free(msg); + return 0; +} static void (*ejs_exception_handler) (const char *) = NULL; @@ -241,5 +273,6 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) ejsDefineStringCFunction(-1, "libinclude", ejs_libinclude, NULL, MPR_VAR_SCRIPT_HANDLE); ejsDefineCFunction(-1, "version", ejs_version, NULL, MPR_VAR_SCRIPT_HANDLE); ejsDefineStringCFunction(-1, "jsonrpc_include", jsonrpc_include, NULL, MPR_VAR_SCRIPT_HANDLE); + ejsDefineStringCFunction(-1, "debug", ejs_debug, NULL, MPR_VAR_SCRIPT_HANDLE); } diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c index 42990f49c0..97fcc19cd1 100644 --- a/source4/scripting/ejs/smbcalls_sys.c +++ b/source4/scripting/ejs/smbcalls_sys.c @@ -413,7 +413,7 @@ static int ejs_sys_init(MprVarHandle eid, int argc, struct MprVar **argv) mprSetCFunction(obj, "interfaces", ejs_sys_interfaces); mprSetCFunction(obj, "hostname", ejs_sys_hostname); mprSetCFunction(obj, "nttime", ejs_sys_nttime); - mprSetCFunction(obj, "getTimeOfDay", ejs_sys_gettimeofday); + mprSetCFunction(obj, "gettimeofday", ejs_sys_gettimeofday); mprSetCFunction(obj, "unix2nttime", ejs_sys_unix2nttime); mprSetCFunction(obj, "gmmktime", ejs_sys_gmmktime); mprSetCFunction(obj, "gmtime", ejs_sys_gmtime); diff --git a/source4/web_server/http.c b/source4/web_server/http.c index 6e42c8a39c..057acc70b3 100644 --- a/source4/web_server/http.c +++ b/source4/web_server/http.c @@ -36,6 +36,7 @@ #define SWAT_SESSION_KEY "SwatSessionId" #define HTTP_PREAUTH_URI "/scripting/preauth.esp" #define JSONRPC_REQUEST "/services" +#define JSONRPC_SERVER "/services/request.esp" /* state of the esp subsystem for a specific request */ struct esp_state { @@ -415,9 +416,10 @@ static void http_setup_arrays(struct esp_state *esp) SETVAR(ESP_REQUEST_OBJ, "CONTENT_LENGTH", talloc_asprintf(esp, "%u", web->input.content_length)); SETVAR(ESP_REQUEST_OBJ, "QUERY_STRING", web->input.query_string); -#if 0 /* djl -- not yet. need to track down the compiler warning */ - SETVAR(ESP_REQUEST_OBJ, "POST_DATA", web->input.partial); -#endif + SETVAR(ESP_REQUEST_OBJ, "POST_DATA", + talloc_strndup(esp, + web->input.partial.data, + web->input.partial.length)); SETVAR(ESP_REQUEST_OBJ, "REQUEST_METHOD", web->input.post_request?"POST":"GET"); SETVAR(ESP_REQUEST_OBJ, "REQUEST_URI", web->input.url); p = strrchr(web->input.url, '/'); @@ -427,7 +429,6 @@ static void http_setup_arrays(struct esp_state *esp) struct MprVar mpv = mprObject("socket_address"); mprSetPtrChild(&mpv, "socket_address", peer_address); espSetVar(req, ESP_REQUEST_OBJ, "REMOTE_SOCKET_ADDRESS", mpv); - SETVAR(ESP_REQUEST_OBJ, "REMOTE_ADDR", peer_address->addr); } p = socket_get_peer_name(web->conn->socket, esp); @@ -523,6 +524,30 @@ static void esp_request(struct esp_state *esp, const char *url) } /* + process a JSON RPC request +*/ +static void jsonrpc_request(struct esp_state *esp) +{ + const char *path = http_local_path(esp->web, JSONRPC_SERVER); + + /* Ensure we got a valid path. */ + if (path == NULL) { + /* should never occur */ + http_error(esp->web, 500, "Internal server error"); + return; + } + + /* Ensure that the JSON-RPC server request script exists */ + if (!file_exist(path)) { + http_error_unix(esp->web, path); + return; + } + + /* Call the server request script */ + esp_request(esp, JSONRPC_SERVER); +} + +/* perform pre-authentication on every page is /scripting/preauth.esp exists. If this script generates any non-whitepace output at all, then we don't run the requested URL. @@ -859,7 +884,11 @@ void http_process_input(struct websrv_context *web) * Work out the mime type. First, we see if the request is a JSON-RPC * service request. If not, we look at the extension. */ - if (strcmp(web->input.url, JSONRPC_REQUEST) == 0) { + if (strncmp(web->input.url, + JSONRPC_REQUEST, + sizeof(JSONRPC_REQUEST) - 1) == 0 && + (web->input.url[sizeof(JSONRPC_REQUEST) - 1] == '\0' || + web->input.url[sizeof(JSONRPC_REQUEST) - 1] == '/')) { page_type = page_type_jsonrpc; file_type = "text/json"; @@ -876,6 +905,7 @@ void http_process_input(struct websrv_context *web) } if (file_type == NULL) { file_type = "text/html"; + page_type = page_type_simple; } } @@ -908,11 +938,7 @@ void http_process_input(struct websrv_context *web) break; case page_type_jsonrpc: -#if 0 /* djl -- not yet */ - if (! jsonrpc_request(esp)) { - http_error(web, 500, "Out of memory"); - } -#endif + jsonrpc_request(esp); break; } |