use pidl::typelist;
my($res);
+my %constants;
sub pidl ($)
{
{
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";
# push a bitmap
sub EjsBitmapPush($$)
{
- # ignored for now
+ my $name = shift;
+ my $e = shift;
+# print util::MyDumper($e);
}
my @fns = ();
my $name = $interface->{NAME};
+ %constants = ();
+
foreach my $d (@{$interface->{TYPEDEFS}}) {
EjsTypedefPush($d);
EjsTypedefPull($d);
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";
}
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;
}
{
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));
+}
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); \
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);
+}
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);
+}
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]);
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);
}
/*