From 7c3fc18315645f2f7a31732c0b1505a2bef29cb7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 7 Jul 2005 06:25:04 +0000 Subject: r8192: updated the glue code for the generated ejs functions from pidl only handles a small subset of all IDL files so far (This used to be commit 14b6436cc51f599572932bef72c49e0da4888073) --- source4/scripting/ejs/config.mk | 7 +- source4/scripting/ejs/ejsrpc.c | 121 +++++++++++++++++++++++++++++++++- source4/scripting/ejs/ejsrpc.h | 32 +++++---- source4/scripting/ejs/smbcalls_irpc.c | 2 +- source4/scripting/ejs/smbcalls_rpc.c | 23 ++++--- 5 files changed, 155 insertions(+), 30 deletions(-) (limited to 'source4/scripting/ejs') diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 0ce7f2df83..0c0caa9ef0 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -2,9 +2,8 @@ # Start LIBRARY EJSRPC [SUBSYSTEM::EJSRPC] OBJ_FILES = \ - scripting/ejs/ejsrpc.o \ - scripting/ejs/ejs_echo.o -REQUIRED_SUBSYSTEMS = RPC_NDR_ECHO + scripting/ejs/ejsrpc.o +REQUIRED_SUBSYSTEMS = RPC_EJS_ECHO NOPROTO = YES # End SUBSYSTEM EJSRPC ####################### @@ -20,7 +19,7 @@ OBJ_FILES = \ scripting/ejs/smbcalls_cli.o \ scripting/ejs/smbcalls_rpc.o \ scripting/ejs/mprutil.o -REQUIRED_SUBSYSTEMS = AUTH EJS LIBBASIC RPC_NDR_ECHO EJSRPC +REQUIRED_SUBSYSTEMS = AUTH EJS LIBBASIC EJSRPC # End SUBSYSTEM SMBCALLS ####################### diff --git a/source4/scripting/ejs/ejsrpc.c b/source4/scripting/ejs/ejsrpc.c index 990dee123c..242d748b36 100644 --- a/source4/scripting/ejs/ejsrpc.c +++ b/source4/scripting/ejs/ejsrpc.c @@ -95,6 +95,32 @@ static NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val) } +/* + start the ejs pull process for a structure +*/ +NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name) +{ + *v = mprGetProperty(*v, name, NULL); + if (*v == NULL) { + return NT_STATUS_INVALID_PARAMETER; + } + return NT_STATUS_OK; +} + + +/* + start the ejs push process for a structure +*/ +NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name) +{ + struct MprVar s = mprCreateObjVar(name, MPR_DEFAULT_HASH_SIZE); + *v = mprSetProperty(*v, name, &s); + if (*v == NULL) { + return NT_STATUS_INVALID_PARAMETER; + } + return NT_STATUS_OK; +} + /* pull a uint8 from a mpr variable to a C element */ @@ -152,7 +178,6 @@ NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs, } *r = mprVarToInteger(var); return NT_STATUS_OK; - } NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs, @@ -160,3 +185,97 @@ NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs, { return mprSetVar(v, name, mprCreateIntegerVar(r)); } + +NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, uint64_t *r) +{ + struct MprVar *var; + var = mprGetVar(v, name); + if (var == NULL) { + return NT_STATUS_INVALID_PARAMETER_MIX; + } + *r = mprVarToInteger(var); + return NT_STATUS_OK; +} + +NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, uint64_t r) +{ + return mprSetVar(v, name, mprCreateIntegerVar(r)); +} + + +/* + pull a enum from a mpr variable to a C element + a enum is just treating as an unsigned integer at this level +*/ +NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, unsigned *r) +{ + struct MprVar *var; + var = mprGetVar(v, name); + if (var == NULL) { + return NT_STATUS_INVALID_PARAMETER_MIX; + } + *r = mprVarToInteger(var); + return NT_STATUS_OK; + +} + +NTSTATUS ejs_push_enum(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, unsigned r) +{ + return mprSetVar(v, name, mprCreateIntegerVar(r)); +} + + +/* + pull an array of elements +*/ +NTSTATUS ejs_pull_array(struct ejs_rpc *ejs, + struct MprVar *v, const char *name, uint32_t length, + size_t elsize, void **r, ejs_pull_t ejs_pull) +{ + int i; + char *data; + + NDR_CHECK(ejs_pull_struct_start(ejs, &v, name)); + + (*r) = talloc_array_size(ejs, elsize, length); + NT_STATUS_HAVE_NO_MEMORY(*r); + + data = *r; + + for (i=0;iout.info, r->in.level)); diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c index ec47da0e9c..631f1c3a37 100644 --- a/source4/scripting/ejs/smbcalls_rpc.c +++ b/source4/scripting/ejs/smbcalls_rpc.c @@ -81,29 +81,28 @@ done: example: status = rpc_call(conn, "echo_AddOne", io); */ -static int ejs_rpc_call(MprVarHandle eid, int argc, struct MprVar **argv) + int ejs_rpc_call(int eid, int argc, struct MprVar **argv, + const char *callname, + ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) { struct MprVar *conn, *io; const struct dcerpc_interface_table *iface; struct dcerpc_pipe *p; - const char *callname; const struct dcerpc_interface_call *call; NTSTATUS status; void *ptr; struct rpc_request *req; int callnum; - if (argc != 3 || + if (argc != 2 || argv[0]->type != MPR_TYPE_OBJECT || - argv[1]->type != MPR_TYPE_STRING || - argv[2]->type != MPR_TYPE_OBJECT) { + argv[1]->type != MPR_TYPE_OBJECT) { ejsSetErrorMsg(eid, "rpc_call invalid arguments"); return -1; } conn = argv[0]; - callname = mprToString(argv[1]); - io = argv[2]; + io = argv[1]; /* get the pipe info */ p = mprGetPtr(conn, "pipe"); @@ -129,7 +128,7 @@ static int ejs_rpc_call(MprVarHandle eid, int argc, struct MprVar **argv) } /* convert the mpr object into a C structure */ - status = ejs_pull_rpc(io, ptr, (ejs_pull_function_t)ejs_pull_echo_AddOne); + status = ejs_pull_rpc(io, ptr, ejs_pull); if (!NT_STATUS_IS_OK(status)) { goto done; } @@ -153,7 +152,7 @@ static int ejs_rpc_call(MprVarHandle eid, int argc, struct MprVar **argv) ndr_print_function_debug(call->ndr_print, call->name, NDR_OUT, ptr); } - status = ejs_push_rpc(io, ptr, (ejs_push_function_t)ejs_push_echo_AddOne); + status = ejs_push_rpc(io, ptr, ejs_push); talloc_free(ptr); done: @@ -161,13 +160,13 @@ done: return 0; } + /* setup C functions that be called from ejs */ void smb_setup_ejs_rpc(void) { + void setup_ejs_rpcecho(void); ejsDefineCFunction(-1, "rpc_connect", ejs_rpc_connect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "rpc_call", ejs_rpc_call, NULL, MPR_VAR_SCRIPT_HANDLE); + setup_ejs_rpcecho(); } - - -- cgit