summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorDerrell Lipman <derrell@samba.org>2006-09-25 02:49:56 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:20:17 -0500
commitc5718959e6a6d0454a870cbd311e707e69c98e85 (patch)
tree0ff02ec691bce1ef1181d1000466937feb264e43 /source4
parent4d3434ff6e83799a1690b3ad3475beb3ef6f12ba (diff)
downloadsamba-c5718959e6a6d0454a870cbd311e707e69c98e85.tar.gz
samba-c5718959e6a6d0454a870cbd311e707e69c98e85.tar.bz2
samba-c5718959e6a6d0454a870cbd311e707e69c98e85.zip
r18880: JSON-RPC work in progress
(This used to be commit 34bffbaebf50c2a75c91285d5ec82e8f377981cc)
Diffstat (limited to 'source4')
-rw-r--r--source4/param/loadparm.c3
-rw-r--r--source4/scripting/ejs/smbcalls.c82
-rw-r--r--source4/scripting/ejs/smbcalls_sys.c84
-rw-r--r--source4/scripting/libjs/provision.js2
-rw-r--r--source4/web_server/http.c85
5 files changed, 230 insertions, 26 deletions
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index 2b2926d053..1e5df4fcbe 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -114,6 +114,7 @@ typedef struct
char *szWINS_URL;
char *szPrivateDir;
char **jsInclude;
+ char *jsonrpcBase;
char **szPasswordServers;
char *szSocketOptions;
char *szRealm;
@@ -542,6 +543,7 @@ static struct parm_struct parm_table[] = {
{"modules dir", P_STRING, P_GLOBAL, &Globals.szModulesDir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
{"pid directory", P_STRING, P_GLOBAL, &Globals.szPidDir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
{"js include", P_LIST, P_GLOBAL, &Globals.jsInclude, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+ {"jsonrpc base", P_STRING, P_GLOBAL, &Globals.jsonrpcBase, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
{"setup directory", P_STRING, P_GLOBAL, &Globals.szSetupDir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
{"socket address", P_STRING, P_GLOBAL, &Globals.szSocketAddress, NULL, NULL, FLAG_DEVELOPER},
@@ -911,6 +913,7 @@ _PUBLIC_ FN_GLOBAL_LIST(lp_auth_methods, &Globals.AuthMethods)
_PUBLIC_ FN_GLOBAL_BOOL(lp_paranoid_server_security, &Globals.paranoid_server_security)
static FN_GLOBAL_INTEGER(lp_announce_as, &Globals.announce_as)
_PUBLIC_ FN_GLOBAL_LIST(lp_js_include, &Globals.jsInclude)
+_PUBLIC_ FN_GLOBAL_STRING(lp_jsonrpc_base, &Globals.jsonrpcBase)
_PUBLIC_
_PUBLIC_
_PUBLIC_ FN_LOCAL_STRING(lp_servicename, szService)
diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c
index 1bfbd3b47a..85cc5f7027 100644
--- a/source4/scripting/ejs/smbcalls.c
+++ b/source4/scripting/ejs/smbcalls.c
@@ -67,6 +67,45 @@ static int ejs_typeof(MprVarHandle eid, int argc, struct MprVar **argv)
}
/*
+ return the native type of a variable
+*/
+static int ejs_typeof_native(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ const struct {
+ MprType type;
+ const char *name;
+ } types[] = {
+ { MPR_TYPE_UNDEFINED, "undefined" },
+ { MPR_TYPE_NULL, "null" },
+ { MPR_TYPE_BOOL, "boolean" },
+ { MPR_TYPE_CFUNCTION, "c_function" },
+ { MPR_TYPE_FLOAT, "float" },
+ { MPR_TYPE_INT, "integer" },
+ { MPR_TYPE_INT64, "integer64" },
+ { MPR_TYPE_OBJECT, "object" },
+ { MPR_TYPE_FUNCTION, "function" },
+ { MPR_TYPE_STRING, "string" },
+ { MPR_TYPE_STRING_CFUNCTION, "string_c_function" },
+ { MPR_TYPE_PTR, "pointer" }
+ };
+ int i;
+ const char *type = NULL;
+
+ if (argc != 1) return -1;
+
+ for (i=0;i<ARRAY_SIZE(types);i++) {
+ if (argv[0]->type == types[i].type) {
+ type = types[i].name;
+ break;
+ }
+ }
+ if (type == NULL) return -1;
+
+ mpr_ReturnString(eid, type);
+ return 0;
+}
+
+/*
libinclude() allows you to include js files using a search path specified
in "js include =" in smb.conf.
*/
@@ -113,6 +152,47 @@ static int ejs_libinclude(int eid, int argc, char **argv)
}
/*
+ jsonrpc_include() allows you to include jsonrpc files from a path
+ based at "jsonrpc base =" in smb.conf.
+*/
+static int ejs_jsonrpc_include(int eid, int argc, char **argv)
+{
+ int ret = -1;
+ char *path;
+ char *emsg;
+ const char *jsonrpc_base = lp_jsonrpc_base();
+ struct MprVar result;
+
+
+ if (jsonrpc_base == NULL || jsonrpc_base == NULL) {
+ ejsSetErrorMsg(eid, "js include path not set");
+ return -1;
+ }
+
+ if (argc != 1) {
+ mpr_Return(eid, mprCreateIntegerVar(-1));
+ return 0;
+ }
+
+ path = talloc_asprintf(mprMemCtx(), "%s/%s", jsonrpc_base, argv[0]);
+ if (path == NULL) {
+ mpr_Return(eid, mprCreateIntegerVar(-1));
+ return 0;
+ }
+
+ if (file_exist(path)) {
+ ret = ejsEvalFile(eid, path, &result, &emsg);
+ if (ret < 0) {
+ printf("file found; ret=%d (%s)\n", ret, emsg);
+ }
+ }
+
+ mpr_Return(eid, mprCreateIntegerVar(ret));
+ talloc_free(path);
+ return 0;
+}
+
+/*
return the current version
*/
static int ejs_version(MprVarHandle eid, int argc, struct MprVar **argv)
@@ -153,7 +233,9 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *))
talloc_free(shared_init);
ejsDefineCFunction(-1, "typeof", ejs_typeof, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineCFunction(-1, "nativeTypeOf", ejs_typeof_native, NULL, MPR_VAR_SCRIPT_HANDLE);
ejsDefineStringCFunction(-1, "libinclude", ejs_libinclude, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineStringCFunction(-1, "jsonrpc_include", ejs_jsonrpc_include, NULL, MPR_VAR_SCRIPT_HANDLE);
ejsDefineCFunction(-1, "version", ejs_version, NULL, MPR_VAR_SCRIPT_HANDLE);
}
diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c
index d8aaf3898a..42990f49c0 100644
--- a/source4/scripting/ejs/smbcalls_sys.c
+++ b/source4/scripting/ejs/smbcalls_sys.c
@@ -58,6 +58,22 @@ static int ejs_sys_hostname(MprVarHandle eid, int argc, struct MprVar **argv)
/*
+ return current time as seconds and microseconds
+*/
+static int ejs_sys_gettimeofday(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct timeval tv = timeval_current();
+ struct MprVar v = mprObject("timeval");
+ struct MprVar sec = mprCreateIntegerVar(tv.tv_sec);
+ struct MprVar usec = mprCreateIntegerVar(tv.tv_usec);
+
+ mprCreateProperty(&v, "sec", &sec);
+ mprCreateProperty(&v, "usec", &usec);
+ mpr_Return(eid, v);
+ return 0;
+}
+
+/*
return current time as a 64 bit nttime value
*/
static int ejs_sys_nttime(MprVarHandle eid, int argc, struct MprVar **argv)
@@ -86,6 +102,35 @@ static int ejs_sys_unix2nttime(MprVarHandle eid, int argc, struct MprVar **argv)
}
/*
+ return the GMT time represented by the struct tm argument, as a time_t value
+*/
+static int ejs_sys_gmmktime(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct MprVar *o;
+ struct tm tm;
+ if (argc != 1 || !mprVarIsObject(argv[0]->type)) {
+ ejsSetErrorMsg(eid, "sys_gmmktime invalid arguments");
+ return -1;
+ }
+
+ o = argv[0];
+#define TM_EL(n) tm.n = mprVarToNumber(mprGetProperty(o, #n, NULL))
+ TM_EL(tm_sec);
+ TM_EL(tm_min);
+ TM_EL(tm_hour);
+ TM_EL(tm_mday);
+ TM_EL(tm_mon);
+ TM_EL(tm_year);
+ TM_EL(tm_wday);
+ TM_EL(tm_yday);
+ TM_EL(tm_isdst);
+#undef TM_EL
+
+ mpr_Return(eid, mprCreateIntegerVar(mktime(&tm)));
+ return 0;
+}
+
+/*
return the given time as a gmtime structure
*/
static int ejs_sys_gmtime(MprVarHandle eid, int argc, struct MprVar **argv)
@@ -97,6 +142,41 @@ static int ejs_sys_gmtime(MprVarHandle eid, int argc, struct MprVar **argv)
ejsSetErrorMsg(eid, "sys_gmtime invalid arguments");
return -1;
}
+ t = (time_t) mprVarToNumber(argv[0]);
+ tm = gmtime(&t);
+ if (tm == NULL) {
+ mpr_Return(eid, mprCreateUndefinedVar());
+ return 0;
+ }
+ ret = mprObject("gmtime");
+#define TM_EL(n) mprSetVar(&ret, #n, mprCreateIntegerVar(tm->n))
+ TM_EL(tm_sec);
+ TM_EL(tm_min);
+ TM_EL(tm_hour);
+ TM_EL(tm_mday);
+ TM_EL(tm_mon);
+ TM_EL(tm_year);
+ TM_EL(tm_wday);
+ TM_EL(tm_yday);
+ TM_EL(tm_isdst);
+#undef TM_EL
+
+ mpr_Return(eid, ret);
+ return 0;
+}
+
+/*
+ return the given NT time as a gmtime structure
+*/
+static int ejs_sys_ntgmtime(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ time_t t;
+ struct MprVar ret;
+ struct tm *tm;
+ if (argc != 1 || !mprVarIsNumber(argv[0]->type)) {
+ ejsSetErrorMsg(eid, "sys_ntgmtime invalid arguments");
+ return -1;
+ }
t = nt_time_to_unix(mprVarToNumber(argv[0]));
tm = gmtime(&t);
if (tm == NULL) {
@@ -114,6 +194,7 @@ static int ejs_sys_gmtime(MprVarHandle eid, int argc, struct MprVar **argv)
TM_EL(tm_wday);
TM_EL(tm_yday);
TM_EL(tm_isdst);
+#undef TM_EL
mpr_Return(eid, ret);
return 0;
@@ -332,8 +413,11 @@ 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, "unix2nttime", ejs_sys_unix2nttime);
+ mprSetCFunction(obj, "gmmktime", ejs_sys_gmmktime);
mprSetCFunction(obj, "gmtime", ejs_sys_gmtime);
+ mprSetCFunction(obj, "ntgmtime", ejs_sys_ntgmtime);
mprSetCFunction(obj, "ldaptime", ejs_sys_ldaptime);
mprSetCFunction(obj, "httptime", ejs_sys_httptime);
mprSetStringCFunction(obj, "unlink", ejs_sys_unlink);
diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js
index 1328cfe8fe..bba3d124ff 100644
--- a/source4/scripting/libjs/provision.js
+++ b/source4/scripting/libjs/provision.js
@@ -113,7 +113,7 @@ function ldaptime()
*/
function datestring()
{
- var t = sys.gmtime(sys.nttime());
+ var t = sys.ntgmtime(sys.nttime());
return sprintf("%04u%02u%02u%02u",
t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour);
}
diff --git a/source4/web_server/http.c b/source4/web_server/http.c
index 45cc57d87a..6e42c8a39c 100644
--- a/source4/web_server/http.c
+++ b/source4/web_server/http.c
@@ -35,6 +35,7 @@
#define SWAT_SESSION_KEY "SwatSessionId"
#define HTTP_PREAUTH_URI "/scripting/preauth.esp"
+#define JSONRPC_REQUEST "/services"
/* state of the esp subsystem for a specific request */
struct esp_state {
@@ -414,6 +415,9 @@ 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, "REQUEST_METHOD", web->input.post_request?"POST":"GET");
SETVAR(ESP_REQUEST_OBJ, "REQUEST_URI", web->input.url);
p = strrchr(web->input.url, '/');
@@ -518,7 +522,6 @@ static void esp_request(struct esp_state *esp, const char *url)
talloc_free(buf);
}
-
/*
perform pre-authentication on every page is /scripting/preauth.esp
exists. If this script generates any non-whitepace output at all,
@@ -541,9 +544,9 @@ static BOOL http_preauth(struct esp_state *esp)
esp_request(esp, HTTP_PREAUTH_URI);
for (i=0;i<esp->web->output.content.length;i++) {
if (!isspace(esp->web->output.content.data[i])) {
- /* if the preauth has generated content, then force it to be
- html, so that we can show the login page for failed
- access to images */
+ /* if the preauth has generated content, then force it
+ to be html, so that we can show the login page for
+ failed access to images */
http_setHeader(esp->web, "Content-Type: text/html", 0);
return False;
}
@@ -763,11 +766,16 @@ void http_process_input(struct websrv_context *web)
void *ejs_save = ejs_save_state();
int i;
const char *file_type = NULL;
- BOOL esp_enable = False;
+ enum page_type {
+ page_type_simple,
+ page_type_esp,
+ page_type_jsonrpc
+ };
+ enum page_type page_type;
const struct {
const char *extension;
const char *mime_type;
- BOOL esp_enable;
+ enum page_type page_type;
} mime_types[] = {
{"gif", "image/gif"},
{"png", "image/png"},
@@ -847,20 +855,29 @@ void http_process_input(struct websrv_context *web)
esp->req = espCreateRequest(web, web->input.url, esp->variables);
if (esp->req == NULL) goto internal_error;
- /* work out the mime type */
- p = strrchr(web->input.url, '.');
- if (p == NULL) {
- esp_enable = True;
- }
- for (i=0;p && i<ARRAY_SIZE(mime_types);i++) {
+ /*
+ * 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) {
+ page_type = page_type_jsonrpc;
+ file_type = "text/json";
+
+ } else {
+ p = strrchr(web->input.url, '.');
+ if (p == NULL) {
+ page_type = page_type_esp;
+ }
+ for (i=0;p && i<ARRAY_SIZE(mime_types);i++) {
if (strcmp(mime_types[i].extension, p+1) == 0) {
- file_type = mime_types[i].mime_type;
- esp_enable = mime_types[i].esp_enable;
+ file_type = mime_types[i].mime_type;
+ page_type = mime_types[i].page_type;
}
- }
- if (file_type == NULL) {
+ }
+ if (file_type == NULL) {
file_type = "text/html";
- }
+ }
+ }
/* setup basic headers */
http_setResponseCode(web, 200);
@@ -872,14 +889,32 @@ void http_process_input(struct websrv_context *web)
http_setup_arrays(esp);
- /* possibly do pre-authentication */
- if (http_preauth(esp)) {
- if (esp_enable) {
- esp_request(esp, web->input.url);
- } else {
- http_simple_request(web);
- }
- }
+ /*
+ * Do pre-authentication. If pre-authentication succeeds, do
+ * page-type-specific processing.
+ */
+ switch(page_type)
+ {
+ case page_type_simple:
+ if (http_preauth(esp)) {
+ http_simple_request(web);
+ }
+ break;
+
+ case page_type_esp:
+ if (http_preauth(esp)) {
+ esp_request(esp, web->input.url);
+ }
+ break;
+
+ case page_type_jsonrpc:
+#if 0 /* djl -- not yet */
+ if (! jsonrpc_request(esp)) {
+ http_error(web, 500, "Out of memory");
+ }
+#endif
+ break;
+ }
if (web->conn == NULL) {
/* the connection has been terminated above us, probably