summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-08 04:55:07 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:19:21 -0500
commitc11204339ae86604a6edd6491f5ee03bf5e3c950 (patch)
treedea831ae95df9afda92768e3397e8579ebe4a71f
parentd105d5e9e40d9950f0c8e61ac17d352c4cb4e6e2 (diff)
downloadsamba-c11204339ae86604a6edd6491f5ee03bf5e3c950.tar.gz
samba-c11204339ae86604a6edd6491f5ee03bf5e3c950.tar.bz2
samba-c11204339ae86604a6edd6491f5ee03bf5e3c950.zip
r8220: added auto-generation of ENUM constants in ejs wrapper. So we can now use the enum name
instead of a integer in ejs scripts making rpc calls (This used to be commit a61cdee384c3002860016c1740276529493d318d)
-rw-r--r--source4/build/pidl/ejs.pm30
-rw-r--r--source4/scripting/ejs/ejsrpc.c21
-rw-r--r--source4/scripting/ejs/ejsrpc.h2
-rw-r--r--source4/scripting/ejs/smbcalls.c8
-rw-r--r--source4/scripting/ejs/smbcalls_rpc.c9
-rw-r--r--source4/scripting/ejs/smbscript.c2
-rw-r--r--testprogs/ejs/echo.js16
7 files changed, 78 insertions, 10 deletions
diff --git a/source4/build/pidl/ejs.pm b/source4/build/pidl/ejs.pm
index 3fe9579aba..24204b79b3 100644
--- a/source4/build/pidl/ejs.pm
+++ b/source4/build/pidl/ejs.pm
@@ -10,6 +10,7 @@ use strict;
use pidl::typelist;
my($res);
+my %constants;
sub pidl ($)
{
@@ -409,6 +410,17 @@ sub EjsEnumPush($$)
{
my $name = shift;
my $d = shift;
+ my $v = 0;
+ # put the enum elements in the constants array
+ foreach my $e (@{$d->{ELEMENTS}}) {
+ chomp $e;
+ if ($e =~ /^(.*)=\s*(.*)\s*$/) {
+ $e = $1;
+ $v = $2;
+ }
+ $constants{$e} = $v;
+ $v++;
+ }
pidl "\nstatic NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const enum $name *r)\n{\n";
pidl "\tunsigned e = *r;\n";
pidl "\tNDR_CHECK(ejs_push_enum(ejs, v, name, &e));\n";
@@ -420,7 +432,9 @@ sub EjsEnumPush($$)
# push a bitmap
sub EjsBitmapPush($$)
{
- # ignored for now
+ my $name = shift;
+ my $e = shift;
+# print util::MyDumper($e);
}
@@ -486,6 +500,8 @@ sub EjsInterface($)
my @fns = ();
my $name = $interface->{NAME};
+ %constants = ();
+
foreach my $d (@{$interface->{TYPEDEFS}}) {
EjsTypedefPush($d);
EjsTypedefPull($d);
@@ -506,6 +522,18 @@ sub EjsInterface($)
foreach (@fns) {
pidl "\tejsDefineCFunction(-1, \"dcerpc_$_\", ejs_$_, NULL, MPR_VAR_SCRIPT_HANDLE);\n";
}
+ pidl "}\n\n";
+
+ pidl "void setup_ejs_constants_$name(int eid)\n";
+ pidl "{\n";
+ foreach my $v (keys %constants) {
+ my $value = $constants{$v};
+ if (substr($value, 0, 1) eq "\"") {
+ pidl "\tejs_set_constant_string(eid, \"$v\", $value);\n";
+ } else {
+ pidl "\tejs_set_constant_int(eid, \"$v\", $value);\n";
+ }
+ }
pidl "}\n";
}
diff --git a/source4/scripting/ejs/ejsrpc.c b/source4/scripting/ejs/ejsrpc.c
index 19c1a2fc8d..6536b94ca4 100644
--- a/source4/scripting/ejs/ejsrpc.c
+++ b/source4/scripting/ejs/ejsrpc.c
@@ -273,7 +273,8 @@ NTSTATUS ejs_pull_string(struct ejs_rpc *ejs,
DEBUG(1,("ejs_pull_string: unable to find '%s'\n", name));
return NT_STATUS_INVALID_PARAMETER_MIX;
}
- *s = mprToString(var);
+ *s = talloc_strdup(ejs, mprToString(var));
+ NT_STATUS_HAVE_NO_MEMORY(*s);
return NT_STATUS_OK;
}
@@ -285,3 +286,21 @@ NTSTATUS ejs_push_string(struct ejs_rpc *ejs,
{
return mprSetVar(v, name, mprCreateStringVar(s, True));
}
+
+/*
+ setup a constant int
+*/
+void ejs_set_constant_int(int eid, const char *name, int value)
+{
+ struct MprVar *v = ejsGetGlobalObject(eid);
+ mprSetVar(v, name, mprCreateIntegerVar(value));
+}
+
+/*
+ setup a constant string
+*/
+void ejs_set_constant_string(int eid, const char *name, const char *value)
+{
+ struct MprVar *v = ejsGetGlobalObject(eid);
+ mprSetVar(v, name, mprCreateStringVar(value, False));
+}
diff --git a/source4/scripting/ejs/ejsrpc.h b/source4/scripting/ejs/ejsrpc.h
index fdf15c027c..0435b52365 100644
--- a/source4/scripting/ejs/ejsrpc.h
+++ b/source4/scripting/ejs/ejsrpc.h
@@ -68,6 +68,8 @@ NTSTATUS ejs_pull_string(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, char **s);
NTSTATUS ejs_push_string(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, const char *s);
+void ejs_set_constant_int(int eid, const char *name, int value);
+void ejs_set_constant_string(int eid, const char *name, const char *value);
#define EJS_ALLOC_SIZE(ejs, s, size) do { \
(s) = talloc_size(ejs, size); \
diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c
index 041bd59f1a..0f43da349d 100644
--- a/source4/scripting/ejs/smbcalls.c
+++ b/source4/scripting/ejs/smbcalls.c
@@ -198,3 +198,11 @@ void smb_setup_ejs_functions(void)
ejsDefineStringCFunction(-1, "getDomainList", ejs_domain_list, NULL, MPR_VAR_SCRIPT_HANDLE);
ejsDefineCFunction(-1, "userAuth", ejs_userAuth, NULL, MPR_VAR_SCRIPT_HANDLE);
}
+
+/*
+ setup constants that can be used from ejs
+*/
+void smb_setup_ejs_constants(int eid)
+{
+ smb_setup_ejs_rpc_constants(eid);
+}
diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c
index 6ec3e29e50..f8ea37b754 100644
--- a/source4/scripting/ejs/smbcalls_rpc.c
+++ b/source4/scripting/ejs/smbcalls_rpc.c
@@ -173,3 +173,12 @@ void smb_setup_ejs_rpc(void)
ejsDefineCFunction(-1, "rpc_connect", ejs_rpc_connect, NULL, MPR_VAR_SCRIPT_HANDLE);
setup_ejs_rpcecho();
}
+
+/*
+ setup constants for rpc calls
+*/
+void smb_setup_ejs_rpc_constants(int eid)
+{
+ void setup_ejs_constants_rpcecho(int);
+ setup_ejs_constants_rpcecho(eid);
+}
diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c
index aa0fc42c48..244ae0b42a 100644
--- a/source4/scripting/ejs/smbscript.c
+++ b/source4/scripting/ejs/smbscript.c
@@ -88,6 +88,8 @@ void ejs_exception(const char *reason)
exit(127);
}
+ smb_setup_ejs_constants(eid);
+
/* setup ARGV[] in the ejs environment */
for (i=1;argv[i];i++) {
argv_list = str_list_add(argv_list, argv[i]);
diff --git a/testprogs/ejs/echo.js b/testprogs/ejs/echo.js
index 4bc8fdefb1..df12e46486 100644
--- a/testprogs/ejs/echo.js
+++ b/testprogs/ejs/echo.js
@@ -185,18 +185,18 @@ function test_TestEnum(conn)
print("Testing echo_TestEnum\n");
- io.input.foo1 = 1;
+ io.input.foo1 = ECHO_ENUM1;
io.input.foo2 = new Object();
- io.input.foo2.e1 = 1;
- io.input.foo2.e2 = 1;
+ io.input.foo2.e1 = ECHO_ENUM1;
+ io.input.foo2.e2 = ECHO_ENUM1_32;
io.input.foo3 = new Object();
- io.input.foo3.e1 = 2;
+ io.input.foo3.e1 = ECHO_ENUM2;
status = dcerpc_echo_TestEnum(conn, io);
check_status_ok(status);
- assert(io.output.foo1 == 1);
- assert(io.output.foo2.e1 == 2);
- assert(io.output.foo2.e2 == 1);
- assert(io.output.foo3.e1 == 2);
+ assert(io.output.foo1 == ECHO_ENUM1);
+ assert(io.output.foo2.e1 == ECHO_ENUM2);
+ assert(io.output.foo2.e2 == ECHO_ENUM1_32);
+ assert(io.output.foo3.e1 == ECHO_ENUM2);
}
/*