svn commit: samba r8220 - in branches/SAMBA_4_0: source/build/pidl source/scripting/ejs testprogs/ejs

tridge at samba.org tridge at samba.org
Fri Jul 8 04:55:07 GMT 2005


Author: tridge
Date: 2005-07-08 04:55:07 +0000 (Fri, 08 Jul 2005)
New Revision: 8220

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8220

Log:
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

Modified:
   branches/SAMBA_4_0/source/build/pidl/ejs.pm
   branches/SAMBA_4_0/source/scripting/ejs/ejsrpc.c
   branches/SAMBA_4_0/source/scripting/ejs/ejsrpc.h
   branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c
   branches/SAMBA_4_0/source/scripting/ejs/smbcalls_rpc.c
   branches/SAMBA_4_0/source/scripting/ejs/smbscript.c
   branches/SAMBA_4_0/testprogs/ejs/echo.js


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/ejs.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/ejs.pm	2005-07-08 04:51:27 UTC (rev 8219)
+++ branches/SAMBA_4_0/source/build/pidl/ejs.pm	2005-07-08 04:55:07 UTC (rev 8220)
@@ -10,6 +10,7 @@
 use pidl::typelist;
 
 my($res);
+my %constants;
 
 sub pidl ($)
 {
@@ -409,6 +410,17 @@
 {
 	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 @@
 # push a bitmap
 sub EjsBitmapPush($$)
 {
-	# ignored for now
+	my $name = shift;
+	my $e = shift;
+#	print util::MyDumper($e);
 }
 
 
@@ -486,6 +500,8 @@
 	my @fns = ();
 	my $name = $interface->{NAME};
 
+	%constants = ();
+
 	foreach my $d (@{$interface->{TYPEDEFS}}) {
 		EjsTypedefPush($d);
 		EjsTypedefPull($d);
@@ -506,6 +522,18 @@
 	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";
 }
 

Modified: branches/SAMBA_4_0/source/scripting/ejs/ejsrpc.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/ejsrpc.c	2005-07-08 04:51:27 UTC (rev 8219)
+++ branches/SAMBA_4_0/source/scripting/ejs/ejsrpc.c	2005-07-08 04:55:07 UTC (rev 8220)
@@ -273,7 +273,8 @@
 		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 @@
 {
 	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));
+}

Modified: branches/SAMBA_4_0/source/scripting/ejs/ejsrpc.h
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/ejsrpc.h	2005-07-08 04:51:27 UTC (rev 8219)
+++ branches/SAMBA_4_0/source/scripting/ejs/ejsrpc.h	2005-07-08 04:55:07 UTC (rev 8220)
@@ -68,6 +68,8 @@
 			 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); \

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c	2005-07-08 04:51:27 UTC (rev 8219)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c	2005-07-08 04:55:07 UTC (rev 8220)
@@ -198,3 +198,11 @@
 	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);
+}

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_rpc.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_rpc.c	2005-07-08 04:51:27 UTC (rev 8219)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_rpc.c	2005-07-08 04:55:07 UTC (rev 8220)
@@ -173,3 +173,12 @@
 	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);
+}

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbscript.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbscript.c	2005-07-08 04:51:27 UTC (rev 8219)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbscript.c	2005-07-08 04:55:07 UTC (rev 8220)
@@ -88,6 +88,8 @@
 		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]);

Modified: branches/SAMBA_4_0/testprogs/ejs/echo.js
===================================================================
--- branches/SAMBA_4_0/testprogs/ejs/echo.js	2005-07-08 04:51:27 UTC (rev 8219)
+++ branches/SAMBA_4_0/testprogs/ejs/echo.js	2005-07-08 04:55:07 UTC (rev 8220)
@@ -185,18 +185,18 @@
 
 	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);
 }
 
 /*



More information about the samba-cvs mailing list