summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-07 06:25:04 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:19:18 -0500
commit7c3fc18315645f2f7a31732c0b1505a2bef29cb7 (patch)
tree8c443965368704a6c56351739f50c73d67cd6f01 /source4/scripting/ejs
parent93aba2c0871a0991dceba2a580d4b04f196adec3 (diff)
downloadsamba-7c3fc18315645f2f7a31732c0b1505a2bef29cb7.tar.gz
samba-7c3fc18315645f2f7a31732c0b1505a2bef29cb7.tar.bz2
samba-7c3fc18315645f2f7a31732c0b1505a2bef29cb7.zip
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)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/config.mk7
-rw-r--r--source4/scripting/ejs/ejsrpc.c121
-rw-r--r--source4/scripting/ejs/ejsrpc.h32
-rw-r--r--source4/scripting/ejs/smbcalls_irpc.c2
-rw-r--r--source4/scripting/ejs/smbcalls_rpc.c23
5 files changed, 155 insertions, 30 deletions
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
@@ -96,6 +96,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
*/
NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs,
@@ -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;i<length;i++) {
+ char *id = talloc_asprintf(ejs, "%u", i);
+ NT_STATUS_HAVE_NO_MEMORY(id);
+ NDR_CHECK(ejs_pull(ejs, v, id, (i*elsize)+data));
+ talloc_free(id);
+ }
+ return mprSetVar(v, "length", mprCreateIntegerVar(i));
+}
+
+
+/*
+ push an array of elements
+*/
+NTSTATUS ejs_push_array(struct ejs_rpc *ejs,
+ struct MprVar *v, const char *name, uint32_t length,
+ size_t elsize, void *r, ejs_push_t ejs_push)
+{
+ int i;
+ char *data;
+
+ NDR_CHECK(ejs_push_struct_start(ejs, &v, name));
+
+ data = r;
+
+ for (i=0;i<length;i++) {
+ char *id = talloc_asprintf(ejs, "%u", i);
+ NT_STATUS_HAVE_NO_MEMORY(id);
+ NDR_CHECK(ejs_push(ejs, v, id, (i*elsize)+data));
+ talloc_free(id);
+ }
+ return NT_STATUS_OK;
+}
+
diff --git a/source4/scripting/ejs/ejsrpc.h b/source4/scripting/ejs/ejsrpc.h
index 4ce1858474..8ddd6a394e 100644
--- a/source4/scripting/ejs/ejsrpc.h
+++ b/source4/scripting/ejs/ejsrpc.h
@@ -24,35 +24,43 @@ struct ejs_rpc {
};
+typedef NTSTATUS (*ejs_pull_t)(struct ejs_rpc *, struct MprVar *, const char *, void *);
+typedef NTSTATUS (*ejs_push_t)(struct ejs_rpc *, struct MprVar *, const char *, const void *);
typedef NTSTATUS (*ejs_pull_function_t)(struct ejs_rpc *, struct MprVar *, void *);
typedef NTSTATUS (*ejs_push_function_t)(struct ejs_rpc *, struct MprVar *, const void *);
+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);
NTSTATUS ejs_pull_rpc(struct MprVar *v, void *ptr, ejs_pull_function_t ejs_pull);
NTSTATUS ejs_push_rpc(struct MprVar *v, const void *ptr, ejs_push_function_t ejs_push);
+NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name);
+NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name);
NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, uint8_t *r);
NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, uint8_t r);
-
NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, uint16_t *r);
NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, uint16_t r);
-
NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, uint32_t *r);
NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, uint32_t r);
+NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs,
+ struct MprVar *v, const char *name, uint64_t *r);
+NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs,
+ struct MprVar *v, const char *name, uint64_t r);
+NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs,
+ struct MprVar *v, const char *name, unsigned *r);
+NTSTATUS ejs_push_enum(struct ejs_rpc *ejs,
+ struct MprVar *v, const char *name, unsigned r);
+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);
+NTSTATUS ejs_push_array(struct ejs_rpc *ejs,
+ struct MprVar *v, const char *name, uint32_t length,
+ size_t elsize, void *r, ejs_push_t ejs_push);
-/* echo calls - PLEASE LEAVE THESE HERE TILL PIDL KNOWS HOW TO
- GENERATE THEM */
-
-#include "librpc/gen_ndr/ndr_echo.h"
-
-NTSTATUS ejs_pull_echo_AddOne(struct ejs_rpc *ejs,
- struct MprVar *v, struct echo_AddOne *r);
-NTSTATUS ejs_push_echo_AddOne(struct ejs_rpc *ejs,
- struct MprVar *v,
- const struct echo_AddOne *r);
diff --git a/source4/scripting/ejs/smbcalls_irpc.c b/source4/scripting/ejs/smbcalls_irpc.c
index 9b0efc69e4..4fd4671732 100644
--- a/source4/scripting/ejs/smbcalls_irpc.c
+++ b/source4/scripting/ejs/smbcalls_irpc.c
@@ -187,7 +187,7 @@ static NTSTATUS ejs_push_nbtd_info(struct ndr_ejs *ndr, union nbtd_info *r,
return NT_STATUS_OK;
}
-static NTSTATUS ndr_push_nbtd_information(struct ndr_push *ndr,
+static NTSTATUS ndr_push_nbtd_information(struct ndr_ejs *ndr,
struct nbtd_information *r, struct MprVar *v)
{
NDR_CHECK(ejs_push_set_switch_value(ndr, &r->out.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();
}
-
-