diff options
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl/Samba4')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm | 616 |
1 files changed, 307 insertions, 309 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm index ea8a96872c..0473341db3 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -8,8 +8,7 @@ package Parse::Pidl::Samba4::EJS; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(get_pointer_to get_value_of check_null_pointer $res - $res_hdr fn_declare TypeFunctionName); +@EXPORT_OK = qw(get_pointer_to get_value_of check_null_pointer fn_declare TypeFunctionName); use strict; use Parse::Pidl::Typelist; @@ -21,36 +20,38 @@ use Parse::Pidl::Samba4::NDR::Parser qw(GenerateStructEnv GenerateFunctionInEnv use vars qw($VERSION); $VERSION = '0.01'; -my $res; -my $res_hdr; - -my %constants; - -my $tabs = ""; +sub new($) { + my ($class) = @_; + my $self = { res => "", res_hdr => "", tabs => "", constants => {}}; + bless($self, $class); +} -sub pidl_hdr ($) +sub pidl_hdr ($$) { - $res_hdr .= shift; + my $self = shift; + $self->{res_hdr} .= shift; } -sub pidl($) +sub pidl($$) { - my $d = shift; + my ($self, $d) = @_; if ($d) { - $res .= $tabs; - $res .= $d; + $self->{res} .= $self->{tabs}; + $self->{res} .= $d; } - $res .= "\n"; + $self->{res} .= "\n"; } -sub indent() +sub indent($) { - $tabs .= "\t"; + my ($self) = @_; + $self->{tabs} .= "\t"; } -sub deindent() +sub deindent($) { - $tabs = substr($tabs, 0, -1); + my ($self) = @_; + $self->{tabs} = substr($self->{tabs}, 0, -1); } sub get_pointer_to($) @@ -79,39 +80,39 @@ sub get_value_of($) ##################################################################### # check that a variable we get from ParseExpr isn't a null pointer -sub check_null_pointer($) +sub check_null_pointer($$) { - my $size = shift; + my ($self, $size) = @_; if ($size =~ /^\*/) { my $size2 = substr($size, 1); - pidl "if ($size2 == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;"; + $self->pidl("if ($size2 == NULL) return NT_STATUS_INVALID_PARAMETER_MIX;"); } } ##################################################################### # work out is a parse function should be declared static or not -sub fn_declare($$) +sub fn_declare($$$) { - my ($fn,$decl) = @_; + my ($self,$fn,$decl) = @_; if (has_property($fn, "public")) { - pidl_hdr "$decl;\n"; - pidl "_PUBLIC_ $decl"; + $self->pidl_hdr("$decl;\n"); + $self->pidl("_PUBLIC_ $decl"); } else { - pidl "static $decl"; + $self->pidl("static $decl"); } } ########################### # pull a scalar element -sub EjsPullScalar($$$$$) +sub EjsPullScalar($$$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; return if (has_property($e, "value")); if (ref($e->{TYPE}) eq "HASH" and not defined($e->{TYPE}->{NAME})) { - EjsTypePull($e->{TYPE}, $var); + $self->EjsTypePull($e->{TYPE}, $var); } else { my $pl = Parse::Pidl::NDR::GetPrevLevel($e, $l); $var = get_pointer_to($var); @@ -127,50 +128,50 @@ sub EjsPullScalar($$$$$) } else { $t = $e->{TYPE}; } - pidl "NDR_CHECK(ejs_pull_$t(ejs, v, $name, $var));"; + $self->pidl("NDR_CHECK(ejs_pull_$t(ejs, v, $name, $var));"); } } ########################### # pull a pointer element -sub EjsPullPointer($$$$$) +sub EjsPullPointer($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; - pidl "if (ejs_pull_null(ejs, v, $name)) {"; - indent; + my ($self, $e, $l, $var, $name, $env) = @_; + $self->pidl("if (ejs_pull_null(ejs, v, $name)) {"); + $self->indent; if ($l->{POINTER_TYPE} eq "ref") { - pidl "return NT_STATUS_INVALID_PARAMETER_MIX;"; + $self->pidl("return NT_STATUS_INVALID_PARAMETER_MIX;"); } else { - pidl "$var = NULL;"; + $self->pidl("$var = NULL;"); } - deindent; - pidl "} else {"; - indent; - pidl "EJS_ALLOC(ejs, $var);"; + $self->deindent; + $self->pidl("} else {"); + $self->indent; + $self->pidl("EJS_ALLOC(ejs, $var);"); $var = get_value_of($var); - EjsPullElement($e, GetNextLevel($e, $l), $var, $name, $env); - deindent; - pidl "}"; + $self->EjsPullElement($e, GetNextLevel($e, $l), $var, $name, $env); + $self->deindent; + $self->pidl("}"); } ########################### # pull a string element -sub EjsPullString($$$$$) +sub EjsPullString($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; my $pl = GetPrevLevel($e, $l); $var = get_pointer_to($var); if (defined($pl) and $pl->{TYPE} eq "POINTER") { $var = get_pointer_to($var); } - pidl "NDR_CHECK(ejs_pull_string(ejs, v, $name, $var));"; + $self->pidl("NDR_CHECK(ejs_pull_string(ejs, v, $name, $var));"); } ########################### # pull an array element -sub EjsPullArray($$$$$) +sub EjsPullArray($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; my $nl = GetNextLevel($e, $l); my $length = ParseExpr($l->{LENGTH_IS}, $env, $e); my $size = ParseExpr($l->{SIZE_IS}, $env, $e); @@ -181,121 +182,121 @@ sub EjsPullArray($$$$$) # uint8 arrays are treated as data blobs if ($nl->{TYPE} eq 'DATA' && $e->{TYPE} eq 'uint8') { if (!$l->{IS_FIXED}) { - check_null_pointer($size); - pidl "EJS_ALLOC_N(ejs, $var, $size);"; + $self->check_null_pointer($size); + $self->pidl("EJS_ALLOC_N(ejs, $var, $size);"); } - check_null_pointer($length); - pidl "ejs_pull_array_uint8(ejs, v, $name, $var, $length);"; + $self->check_null_pointer($length); + $self->pidl("ejs_pull_array_uint8(ejs, v, $name, $var, $length);"); return; } my $avar = $var . "[i]"; - pidl "{"; - indent; - pidl "uint32_t i;"; + $self->pidl("{"); + $self->indent; + $self->pidl("uint32_t i;"); if (!$l->{IS_FIXED}) { - pidl "EJS_ALLOC_N(ejs, $var, $size);"; + $self->pidl("EJS_ALLOC_N(ejs, $var, $size);"); } - pidl "for (i=0;i<$length;i++) {"; - indent; - pidl "char *id = talloc_asprintf(ejs, \"%s.%u\", $name, i);"; - EjsPullElement($e, $nl, $avar, "id", $env); - pidl "talloc_free(id);"; - deindent; - pidl "}"; - pidl "ejs_push_uint32(ejs, v, $name \".length\", &i);"; - deindent; - pidl "}"; + $self->pidl("for (i=0;i<$length;i++) {"); + $self->indent; + $self->pidl("char *id = talloc_asprintf(ejs, \"%s.%u\", $name, i);"); + $self->EjsPullElement($e, $nl, $avar, "id", $env); + $self->pidl("talloc_free(id);"); + $self->deindent; + $self->pidl("}"); + $self->pidl("ejs_push_uint32(ejs, v, $name \".length\", &i);"); + $self->deindent; + $self->pidl("}"); } ########################### # pull a switch element -sub EjsPullSwitch($$$$$) +sub EjsPullSwitch($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; my $switch_var = ParseExpr($l->{SWITCH_IS}, $env, $e); - pidl "ejs_set_switch(ejs, $switch_var);"; - EjsPullElement($e, GetNextLevel($e, $l), $var, $name, $env); + $self->pidl("ejs_set_switch(ejs, $switch_var);"); + $self->EjsPullElement($e, GetNextLevel($e, $l), $var, $name, $env); } ########################### # pull a structure element -sub EjsPullElement($$$$$) +sub EjsPullElement($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; if (($l->{TYPE} eq "POINTER")) { - EjsPullPointer($e, $l, $var, $name, $env); + $self->EjsPullPointer($e, $l, $var, $name, $env); } elsif (has_property($e, "charset")) { - EjsPullString($e, $l, $var, $name, $env); + $self->EjsPullString($e, $l, $var, $name, $env); } elsif ($l->{TYPE} eq "ARRAY") { - EjsPullArray($e, $l, $var, $name, $env); + $self->EjsPullArray($e, $l, $var, $name, $env); } elsif ($l->{TYPE} eq "DATA") { - EjsPullScalar($e, $l, $var, $name, $env); + $self->EjsPullScalar($e, $l, $var, $name, $env); } elsif (($l->{TYPE} eq "SWITCH")) { - EjsPullSwitch($e, $l, $var, $name, $env); + $self->EjsPullSwitch($e, $l, $var, $name, $env); } else { - pidl "return ejs_panic(ejs, \"unhandled pull type $l->{TYPE}\");"; + $self->pidl("return ejs_panic(ejs, \"unhandled pull type $l->{TYPE}\");"); } } ############################################# # pull a structure/union element at top level -sub EjsPullElementTop($$) +sub EjsPullElementTop($$$) { - my ($e, $env) = @_; + my ($self, $e, $env) = @_; my $l = $e->{LEVELS}[0]; my $var = ParseExpr($e->{NAME}, $env, $e); my $name = "\"$e->{NAME}\""; - EjsPullElement($e, $l, $var, $name, $env); + $self->EjsPullElement($e, $l, $var, $name, $env); } ########################### # pull a struct -sub EjsStructPull($$) +sub EjsStructPull($$$) { - my ($d, $varname) = @_; + my ($self, $d, $varname) = @_; my $env = GenerateStructEnv($d, $varname); - pidl "NDR_CHECK(ejs_pull_struct_start(ejs, &v, name));"; + $self->pidl("NDR_CHECK(ejs_pull_struct_start(ejs, &v, name));"); foreach my $e (@{$d->{ELEMENTS}}) { - EjsPullElementTop($e, $env); + $self->EjsPullElementTop($e, $env); } } ########################### # pull a union -sub EjsUnionPull($$) +sub EjsUnionPull($$$) { - my ($d, $varname) = @_; + my ($self, $d, $varname) = @_; my $have_default = 0; - pidl "NDR_CHECK(ejs_pull_struct_start(ejs, &v, name));"; - pidl "switch (ejs->switch_var) {"; - indent; + $self->pidl("NDR_CHECK(ejs_pull_struct_start(ejs, &v, name));"); + $self->pidl("switch (ejs->switch_var) {"); + $self->indent; foreach my $e (@{$d->{ELEMENTS}}) { if ($e->{CASE} eq "default") { $have_default = 1; } - pidl "$e->{CASE}:"; - indent; + $self->pidl("$e->{CASE}:"); + $self->indent; if ($e->{TYPE} ne "EMPTY") { - EjsPullElementTop($e, { $e->{NAME} => "$varname->$e->{NAME}"}); + $self->EjsPullElementTop($e, { $e->{NAME} => "$varname->$e->{NAME}"}); } - pidl "break;"; - deindent; + $self->pidl("break;"); + $self->deindent; } if (! $have_default) { - pidl "default:"; - indent; - pidl "return ejs_panic(ejs, \"Bad switch value\");"; - deindent; + $self->pidl("default:"); + $self->indent; + $self->pidl("return ejs_panic(ejs, \"Bad switch value\");"); + $self->deindent; } - deindent; - pidl "}"; + $self->deindent; + $self->pidl("}"); } ############################################## # put the enum elements in the constants array -sub EjsEnumConstant($) +sub EjsEnumConstant($$) { - my $d = shift; + my ($self, $d) = @_; my $v = 0; foreach my $e (@{$d->{ELEMENTS}}) { my $el = $e; @@ -304,73 +305,73 @@ sub EjsEnumConstant($) $el = $1; $v = $2; } - $constants{$el} = $v; + $self->{constants}->{$el} = $v; $v++; } } ########################### # pull a enum -sub EjsEnumPull($$) +sub EjsEnumPull($$$) { - my ($d, $varname) = @_; - EjsEnumConstant($d); - pidl "unsigned e;"; - pidl "NDR_CHECK(ejs_pull_enum(ejs, v, name, &e));"; - pidl "*$varname = e;"; + my ($self, $d, $varname) = @_; + $self->EjsEnumConstant($d); + $self->pidl("unsigned e;"); + $self->pidl("NDR_CHECK(ejs_pull_enum(ejs, v, name, &e));"); + $self->pidl("*$varname = e;"); } ########################### # pull a bitmap -sub EjsBitmapPull($$) +sub EjsBitmapPull($$$) { - my ($d, $varname) = @_; + my ($self, $d, $varname) = @_; my $type_fn = $d->{BASE_TYPE}; - pidl "NDR_CHECK(ejs_pull_$type_fn(ejs, v, name, $varname));"; + $self->pidl("NDR_CHECK(ejs_pull_$type_fn(ejs, v, name, $varname));"); } -sub EjsTypePullFunction($$) +sub EjsTypePullFunction($$$) { - sub EjsTypePullFunction($$); - my ($d, $name) = @_; + sub EjsTypePullFunction($$$); + my ($self, $d, $name) = @_; return if (has_property($d, "noejs")); if ($d->{TYPE} eq "TYPEDEF") { - EjsTypePullFunction($d->{DATA}, $name); + $self->EjsTypePullFunction($d->{DATA}, $name); return; } if ($d->{TYPE} eq "STRUCT") { - fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, struct $name *r)"); + $self->fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, struct $name *r)"); } elsif ($d->{TYPE} eq "UNION") { - fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, union $name *r)"); + $self->fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, union $name *r)"); } elsif ($d->{TYPE} eq "ENUM") { - fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, enum $name *r)"); + $self->fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, enum $name *r)"); } elsif ($d->{TYPE} eq "BITMAP") { my($type_decl) = Parse::Pidl::Typelist::mapTypeName($d->{BASE_TYPE}); - fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, $type_decl *r)"); + $self->fn_declare($d, "NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, $type_decl *r)"); } - pidl "{"; - indent; + $self->pidl("{"); + $self->indent; - EjsTypePull($d, "r"); + $self->EjsTypePull($d, "r"); - pidl "return NT_STATUS_OK;"; - deindent; - pidl "}\n"; + $self->pidl("return NT_STATUS_OK;"); + $self->deindent; + $self->pidl("}\n"); } -sub EjsTypePull($$) +sub EjsTypePull($$$) { - my ($d, $varname) = @_; + my ($self, $d, $varname) = @_; if ($d->{TYPE} eq 'STRUCT') { - EjsStructPull($d, $varname); + $self->EjsStructPull($d, $varname); } elsif ($d->{TYPE} eq 'UNION') { - EjsUnionPull($d, $varname); + $self->EjsUnionPull($d, $varname); } elsif ($d->{TYPE} eq 'ENUM') { - EjsEnumPull($d, $varname); + $self->EjsEnumPull($d, $varname); } elsif ($d->{TYPE} eq 'BITMAP') { - EjsBitmapPull($d, $varname); + $self->EjsBitmapPull($d, $varname); } else { warn "Unhandled pull $varname of type $d->{TYPE}"; } @@ -378,16 +379,16 @@ sub EjsTypePull($$) ##################### # generate a function -sub EjsPullFunction($) +sub EjsPullFunction($$) { - my $d = shift; + my ($self, $d) = @_; my $env = GenerateFunctionInEnv($d); my $name = $d->{NAME}; - pidl "\nstatic NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, struct $name *r)"; - pidl "{"; - indent; - pidl "NDR_CHECK(ejs_pull_struct_start(ejs, &v, \"input\"));"; + $self->pidl("\nstatic NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, struct $name *r)"); + $self->pidl("{"); + $self->indent; + $self->pidl("NDR_CHECK(ejs_pull_struct_start(ejs, &v, \"input\"));"); # we pull non-array elements before array elements as arrays # may have length_is() or size_is() properties that depend @@ -395,28 +396,28 @@ sub EjsPullFunction($) foreach my $e (@{$d->{ELEMENTS}}) { next unless (grep(/in/, @{$e->{DIRECTION}})); next if (has_property($e, "length_is") || has_property($e, "size_is")); - EjsPullElementTop($e, $env); + $self->EjsPullElementTop($e, $env); } foreach my $e (@{$d->{ELEMENTS}}) { next unless (grep(/in/, @{$e->{DIRECTION}})); next unless (has_property($e, "length_is") || has_property($e, "size_is")); - EjsPullElementTop($e, $env); + $self->EjsPullElementTop($e, $env); } - pidl "return NT_STATUS_OK;"; - deindent; - pidl "}\n"; + $self->pidl("return NT_STATUS_OK;"); + $self->deindent; + $self->pidl("}\n"); } ########################### # push a scalar element -sub EjsPushScalar($$$$$) +sub EjsPushScalar($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; if (ref($e->{TYPE}) eq "HASH" and not defined($e->{TYPE}->{NAME})) { - EjsTypePush($e->{TYPE}, get_pointer_to($var)); + $self->EjsTypePush($e->{TYPE}, get_pointer_to($var)); } else { # have to handle strings specially :( my $pl = GetPrevLevel($e, $l); @@ -426,58 +427,58 @@ sub EjsPushScalar($$$$$) $var = get_pointer_to($var); } - pidl "NDR_CHECK(".TypeFunctionName("ejs_push", $e->{TYPE})."(ejs, v, $name, $var));"; + $self->pidl("NDR_CHECK(".TypeFunctionName("ejs_push", $e->{TYPE})."(ejs, v, $name, $var));"); } } ########################### # push a string element -sub EjsPushString($$$$$) +sub EjsPushString($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; my $pl = GetPrevLevel($e, $l); if (defined($pl) and $pl->{TYPE} eq "POINTER") { $var = get_pointer_to($var); } - pidl "NDR_CHECK(ejs_push_string(ejs, v, $name, $var));"; + $self->pidl("NDR_CHECK(ejs_push_string(ejs, v, $name, $var));"); } ########################### # push a pointer element -sub EjsPushPointer($$$$$) +sub EjsPushPointer($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; - pidl "if (NULL == $var) {"; - indent; + my ($self, $e, $l, $var, $name, $env) = @_; + $self->pidl("if (NULL == $var) {"); + $self->indent; if ($l->{POINTER_TYPE} eq "ref") { - pidl "return NT_STATUS_INVALID_PARAMETER_MIX;"; + $self->pidl("return NT_STATUS_INVALID_PARAMETER_MIX;"); } else { - pidl "NDR_CHECK(ejs_push_null(ejs, v, $name));"; + $self->pidl("NDR_CHECK(ejs_push_null(ejs, v, $name));"); } - deindent; - pidl "} else {"; - indent; + $self->deindent; + $self->pidl("} else {"); + $self->indent; $var = get_value_of($var); - EjsPushElement($e, GetNextLevel($e, $l), $var, $name, $env); - deindent; - pidl "}"; + $self->EjsPushElement($e, GetNextLevel($e, $l), $var, $name, $env); + $self->deindent; + $self->pidl("}"); } ########################### # push a switch element -sub EjsPushSwitch($$$$$) +sub EjsPushSwitch($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; my $switch_var = ParseExpr($l->{SWITCH_IS}, $env, $e); - pidl "ejs_set_switch(ejs, $switch_var);"; - EjsPushElement($e, GetNextLevel($e, $l), $var, $name, $env); + $self->pidl("ejs_set_switch(ejs, $switch_var);"); + $self->EjsPushElement($e, GetNextLevel($e, $l), $var, $name, $env); } ########################### # push an array element -sub EjsPushArray($$$$$) +sub EjsPushArray($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; my $nl = GetNextLevel($e, $l); my $length = ParseExpr($l->{LENGTH_IS}, $env, $e); my $pl = GetPrevLevel($e, $l); @@ -486,130 +487,130 @@ sub EjsPushArray($$$$$) } # uint8 arrays are treated as data blobs if ($nl->{TYPE} eq 'DATA' && $e->{TYPE} eq 'uint8') { - check_null_pointer($length); - pidl "ejs_push_array_uint8(ejs, v, $name, $var, $length);"; + $self->check_null_pointer($length); + $self->pidl("ejs_push_array_uint8(ejs, v, $name, $var, $length);"); return; } my $avar = $var . "[i]"; - pidl "{"; - indent; - pidl "uint32_t i;"; - pidl "for (i=0;i<$length;i++) {"; - indent; - pidl "const char *id = talloc_asprintf(ejs, \"%s.%u\", $name, i);"; - EjsPushElement($e, $nl, $avar, "id", $env); - deindent; - pidl "}"; - pidl "ejs_push_uint32(ejs, v, $name \".length\", &i);"; - deindent; - pidl "}"; + $self->pidl("{"); + $self->indent; + $self->pidl("uint32_t i;"); + $self->pidl("for (i=0;i<$length;i++) {"); + $self->indent; + $self->pidl("const char *id = talloc_asprintf(ejs, \"%s.%u\", $name, i);"); + $self->EjsPushElement($e, $nl, $avar, "id", $env); + $self->deindent; + $self->pidl("}"); + $self->pidl("ejs_push_uint32(ejs, v, $name \".length\", &i);"); + $self->deindent; + $self->pidl("}"); } ################################ # push a structure/union element -sub EjsPushElement($$$$$) +sub EjsPushElement($$$$$$) { - my ($e, $l, $var, $name, $env) = @_; + my ($self, $e, $l, $var, $name, $env) = @_; if (($l->{TYPE} eq "POINTER")) { - EjsPushPointer($e, $l, $var, $name, $env); + $self->EjsPushPointer($e, $l, $var, $name, $env); } elsif (has_property($e, "charset")) { - EjsPushString($e, $l, $var, $name, $env); + $self->EjsPushString($e, $l, $var, $name, $env); } elsif ($l->{TYPE} eq "ARRAY") { - EjsPushArray($e, $l, $var, $name, $env); + $self->EjsPushArray($e, $l, $var, $name, $env); } elsif ($l->{TYPE} eq "DATA") { - EjsPushScalar($e, $l, $var, $name, $env); + $self->EjsPushScalar($e, $l, $var, $name, $env); } elsif (($l->{TYPE} eq "SWITCH")) { - EjsPushSwitch($e, $l, $var, $name, $env); + $self->EjsPushSwitch($e, $l, $var, $name, $env); } else { - pidl "return ejs_panic(ejs, \"unhandled push type $l->{TYPE}\");"; + $self->pidl("return ejs_panic(ejs, \"unhandled push type $l->{TYPE}\");"); } } ############################################# # push a structure/union element at top level -sub EjsPushElementTop($$) +sub EjsPushElementTop($$$) { - my ($e, $env) = @_; + my ($self, $e, $env) = @_; my $l = $e->{LEVELS}[0]; my $var = ParseExpr($e->{NAME}, $env, $e); my $name = "\"$e->{NAME}\""; - EjsPushElement($e, $l, $var, $name, $env); + $self->EjsPushElement($e, $l, $var, $name, $env); } ########################### # push a struct -sub EjsStructPush($$) +sub EjsStructPush($$$) { - my ($d, $varname) = @_; + my ($self, $d, $varname) = @_; my $env = GenerateStructEnv($d, $varname); - pidl "NDR_CHECK(ejs_push_struct_start(ejs, &v, name));"; + $self->pidl("NDR_CHECK(ejs_push_struct_start(ejs, &v, name));"); foreach my $e (@{$d->{ELEMENTS}}) { - EjsPushElementTop($e, $env); + $self->EjsPushElementTop($e, $env); } } ########################### # push a union -sub EjsUnionPush($$) +sub EjsUnionPush($$$) { - my ($d, $varname) = @_; + my ($self, $d, $varname) = @_; my $have_default = 0; - pidl "NDR_CHECK(ejs_push_struct_start(ejs, &v, name));"; - pidl "switch (ejs->switch_var) {"; - indent; + $self->pidl("NDR_CHECK(ejs_push_struct_start(ejs, &v, name));"); + $self->pidl("switch (ejs->switch_var) {"); + $self->indent; foreach my $e (@{$d->{ELEMENTS}}) { if ($e->{CASE} eq "default") { $have_default = 1; } - pidl "$e->{CASE}:"; - indent; + $self->pidl("$e->{CASE}:"); + $self->indent; if ($e->{TYPE} ne "EMPTY") { - EjsPushElementTop($e, { $e->{NAME} => "$varname->$e->{NAME}"} ); + $self->EjsPushElementTop($e, { $e->{NAME} => "$varname->$e->{NAME}"} ); } - pidl "break;"; - deindent; + $self->pidl("break;"); + $self->deindent; } if (! $have_default) { - pidl "default:"; - indent; - pidl "return ejs_panic(ejs, \"Bad switch value\");"; - deindent; + $self->pidl("default:"); + $self->indent; + $self->pidl("return ejs_panic(ejs, \"Bad switch value\");"); + $self->deindent; } - deindent; - pidl "}"; + $self->deindent; + $self->pidl("}"); } ########################### # push a enum -sub EjsEnumPush($$) +sub EjsEnumPush($$$) { - my ($d, $varname) = @_; - EjsEnumConstant($d); - pidl "unsigned e = ".get_value_of($varname).";"; - pidl "NDR_CHECK(ejs_push_enum(ejs, v, name, &e));"; + my ($self, $d, $varname) = @_; + $self->EjsEnumConstant($d); + $self->pidl("unsigned e = ".get_value_of($varname).";"); + $self->pidl("NDR_CHECK(ejs_push_enum(ejs, v, name, &e));"); } ########################### # push a bitmap -sub EjsBitmapPush($$) +sub EjsBitmapPush($$$) { - my ($d, $varname) = @_; + my ($self, $d, $varname) = @_; my $type_fn = $d->{BASE_TYPE}; # put the bitmap elements in the constants array foreach my $e (@{$d->{ELEMENTS}}) { if ($e =~ /^(\w*)\s*(.*)\s*$/) { my $bname = $1; my $v = $2; - $constants{$bname} = $v; + $self->{constants}->{$bname} = $v; } } - pidl "NDR_CHECK(ejs_push_$type_fn(ejs, v, name, $varname));"; + $self->pidl("NDR_CHECK(ejs_push_$type_fn(ejs, v, name, $varname));"); } -sub EjsTypePushFunction($$) +sub EjsTypePushFunction($$$) { - sub EjsTypePushFunction($$); - my ($d, $name) = @_; + sub EjsTypePushFunction($$$); + my ($self, $d, $name) = @_; return if (has_property($d, "noejs")); my $var = undef; @@ -627,30 +628,30 @@ sub EjsTypePushFunction($$) my($type_decl) = Parse::Pidl::Typelist::mapTypeName($dt->{BASE_TYPE}); $var = "const $type_decl *r"; } - fn_declare($d, "NTSTATUS ".TypeFunctionName("ejs_push", $d) . "(struct ejs_rpc *ejs, struct MprVar *v, const char *name, $var)"); - pidl "{"; - indent; - EjsTypePush($d, "r"); - pidl "return NT_STATUS_OK;"; - deindent; - pidl "}\n"; + $self->fn_declare($d, "NTSTATUS ".TypeFunctionName("ejs_push", $d) . "(struct ejs_rpc *ejs, struct MprVar *v, const char *name, $var)"); + $self->pidl("{"); + $self->indent; + $self->EjsTypePush($d, "r"); + $self->pidl("return NT_STATUS_OK;"); + $self->deindent; + $self->pidl("}\n"); } -sub EjsTypePush($$) +sub EjsTypePush($$$) { - sub EjsTypePush($$); - my ($d, $varname) = @_; + sub EjsTypePush($$$); + my ($self, $d, $varname) = @_; if ($d->{TYPE} eq 'STRUCT') { - EjsStructPush($d, $varname); + $self->EjsStructPush($d, $varname); } elsif ($d->{TYPE} eq 'UNION') { - EjsUnionPush($d, $varname); + $self->EjsUnionPush($d, $varname); } elsif ($d->{TYPE} eq 'ENUM') { - EjsEnumPush($d, $varname); + $self->EjsEnumPush($d, $varname); } elsif ($d->{TYPE} eq 'BITMAP') { - EjsBitmapPush($d, $varname); + $self->EjsBitmapPush($d, $varname); } elsif ($d->{TYPE} eq 'TYPEDEF') { - EjsTypePush($d->{DATA}, $varname); + $self->EjsTypePush($d->{DATA}, $varname); } else { warn "Unhandled push $varname of type $d->{TYPE}"; } @@ -658,145 +659,142 @@ sub EjsTypePush($$) ##################### # generate a function -sub EjsPushFunction($) +sub EjsPushFunction($$) { - my $d = shift; + my ($self, $d) = @_; my $env = GenerateFunctionOutEnv($d); - pidl "\nstatic NTSTATUS ejs_push_$d->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, const struct $d->{NAME} *r)"; - pidl "{"; - indent; - pidl "NDR_CHECK(ejs_push_struct_start(ejs, &v, \"output\"));"; + $self->pidl("\nstatic NTSTATUS ejs_push_$d->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, const struct $d->{NAME} *r)"); + $self->pidl("{"); + $self->indent; + $self->pidl("NDR_CHECK(ejs_push_struct_start(ejs, &v, \"output\"));"); foreach my $e (@{$d->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); - EjsPushElementTop($e, $env); + $self->EjsPushElementTop($e, $env); } if ($d->{RETURN_TYPE}) { - pidl "NDR_CHECK(".TypeFunctionName("ejs_push", $d->{RETURN_TYPE})."(ejs, v, \"result\", &r->out.result));"; + $self->pidl("NDR_CHECK(".TypeFunctionName("ejs_push", $d->{RETURN_TYPE})."(ejs, v, \"result\", &r->out.result));"); } - pidl "return NT_STATUS_OK;"; - deindent; - pidl "}\n"; + $self->pidl("return NT_STATUS_OK;"); + $self->deindent; + $self->pidl("}\n"); } ################################# # generate a ejs mapping function -sub EjsFunction($$) +sub EjsFunction($$$) { - my ($d, $iface) = @_; + my ($self, $d, $iface) = @_; my $name = $d->{NAME}; my $callnum = uc("DCERPC_$name"); my $table = "&dcerpc_table_$iface"; - pidl "static int ejs_$name(int eid, int argc, struct MprVar **argv)"; - pidl "{"; - indent; - pidl "return ejs_rpc_call(eid, argc, argv, $table, $callnum, (ejs_pull_function_t)ejs_pull_$name, (ejs_push_function_t)ejs_push_$name);"; - deindent; - pidl "}\n"; + $self->pidl("static int ejs_$name(int eid, int argc, struct MprVar **argv)"); + $self->pidl("{"); + $self->indent; + $self->pidl("return ejs_rpc_call(eid, argc, argv, $table, $callnum, (ejs_pull_function_t)ejs_pull_$name, (ejs_push_function_t)ejs_push_$name);"); + $self->deindent; + $self->pidl("}\n"); } ################### # handle a constant -sub EjsConst($) +sub EjsConst($$) { - my $const = shift; - $constants{$const->{NAME}} = $const->{VALUE}; + my ($self, $const) = @_; + $self->{constants}->{$const->{NAME}} = $const->{VALUE}; } sub EjsImport { + my $self = shift; my @imports = @_; foreach (@imports) { s/\.idl\"$//; s/^\"//; - pidl_hdr "#include \"librpc/gen_ndr/ndr_$_\_ejs\.h\"\n"; + $self->pidl_hdr("#include \"librpc/gen_ndr/ndr_$_\_ejs\.h\"\n"); } } ##################################################################### # parse the interface definitions -sub EjsInterface($$) +sub EjsInterface($$$) { - my($interface,$needed) = @_; + my($self,$interface,$needed) = @_; my @fns = (); my $name = $interface->{NAME}; - %constants = (); - - pidl_hdr "#ifndef _HEADER_EJS_$interface->{NAME}\n"; - pidl_hdr "#define _HEADER_EJS_$interface->{NAME}\n\n"; + $self->pidl_hdr("#ifndef _HEADER_EJS_$interface->{NAME}\n"); + $self->pidl_hdr("#define _HEADER_EJS_$interface->{NAME}\n\n"); - pidl_hdr "\n"; + $self->pidl_hdr("\n"); foreach my $d (@{$interface->{TYPES}}) { - ($needed->{TypeFunctionName("ejs_push", $d)}) && EjsTypePushFunction($d, $d->{NAME}); - ($needed->{TypeFunctionName("ejs_pull", $d)}) && EjsTypePullFunction($d, $d->{NAME}); + ($needed->{TypeFunctionName("ejs_push", $d)}) && $self->EjsTypePushFunction($d, $d->{NAME}); + ($needed->{TypeFunctionName("ejs_pull", $d)}) && $self->EjsTypePullFunction($d, $d->{NAME}); } foreach my $d (@{$interface->{FUNCTIONS}}) { next if not defined($d->{OPNUM}); next if has_property($d, "noejs"); - EjsPullFunction($d); - EjsPushFunction($d); - EjsFunction($d, $name); + $self->EjsPullFunction($d); + $self->EjsPushFunction($d); + $self->EjsFunction($d, $name); push (@fns, $d->{NAME}); } foreach my $d (@{$interface->{CONSTS}}) { - EjsConst($d); + $self->EjsConst($d); } - pidl "static int ejs_$name\_init(int eid, int argc, struct MprVar **argv)"; - pidl "{"; - indent; - pidl "struct MprVar *obj = mprInitObject(eid, \"$name\", argc, argv);"; + $self->pidl("static int ejs_$name\_init(int eid, int argc, struct MprVar **argv)"); + $self->pidl("{"); + $self->indent; + $self->pidl("struct MprVar *obj = mprInitObject(eid, \"$name\", argc, argv);"); foreach (@fns) { - pidl "mprSetCFunction(obj, \"$_\", ejs_$_);"; + $self->pidl("mprSetCFunction(obj, \"$_\", ejs_$_);"); } - foreach my $v (keys %constants) { - my $value = $constants{$v}; + foreach my $v (keys %{$self->{constants}}) { + my $value = $self->{constants}->{$v}; if (substr($value, 0, 1) eq "\"") { - pidl "mprSetVar(obj, \"$v\", mprString($value));"; + $self->pidl("mprSetVar(obj, \"$v\", mprString($value));"); } else { - pidl "mprSetVar(obj, \"$v\", mprCreateNumberVar($value));"; + $self->pidl("mprSetVar(obj, \"$v\", mprCreateNumberVar($value));"); } } - pidl "return ejs_rpc_init(obj, \"$name\");"; - deindent; - pidl "}\n"; + $self->pidl("return ejs_rpc_init(obj, \"$name\");"); + $self->deindent; + $self->pidl("}\n"); - pidl "NTSTATUS ejs_init_$name(void)"; - pidl "{"; - indent; - pidl "ejsDefineCFunction(-1, \"$name\_init\", ejs_$name\_init, NULL, MPR_VAR_SCRIPT_HANDLE);"; - pidl "return NT_STATUS_OK;"; - deindent; - pidl "}"; + $self->pidl("NTSTATUS ejs_init_$name(void)"); + $self->pidl("{"); + $self->indent; + $self->pidl("ejsDefineCFunction(-1, \"$name\_init\", ejs_$name\_init, NULL, MPR_VAR_SCRIPT_HANDLE);"); + $self->pidl("return NT_STATUS_OK;"); + $self->deindent; + $self->pidl("}"); - pidl_hdr "\n"; - pidl_hdr "#endif /* _HEADER_EJS_$interface->{NAME} */\n"; + $self->pidl_hdr("\n"); + $self->pidl_hdr("#endif /* _HEADER_EJS_$interface->{NAME} */\n"); } ##################################################################### # parse a parsed IDL into a C header -sub Parse($$) +sub Parse($$$) { - my($ndr,$hdr) = @_; + my($self,$ndr,$hdr) = @_; my $ejs_hdr = $hdr; $ejs_hdr =~ s/.h$/_ejs.h/; - $res = ""; - $res_hdr = ""; - pidl_hdr "/* header auto-generated by pidl */\n\n"; + $self->pidl_hdr("/* header auto-generated by pidl */\n\n"); - pidl " + $self->pidl(" /* EJS wrapper functions auto-generated by pidl */ #include \"includes.h\" #include \"librpc/rpc/dcerpc.h\" @@ -807,7 +805,7 @@ sub Parse($$) #include \"$hdr\" #include \"$ejs_hdr\" -"; +"); my %needed = (); @@ -816,11 +814,11 @@ sub Parse($$) } foreach my $x (@$ndr) { - ($x->{TYPE} eq "INTERFACE") && EjsInterface($x, \%needed); - ($x->{TYPE} eq "IMPORT") && EjsImport(@{$x->{PATHS}}); + ($x->{TYPE} eq "INTERFACE") && $self->EjsInterface($x, \%needed); + ($x->{TYPE} eq "IMPORT") && $self->EjsImport(@{$x->{PATHS}}); } - return ($res_hdr, $res); + return ($self->{res_hdr}, $self->{res}); } sub NeededFunction($$) |