@EXPORT_OK = qw(DeclLevel);
use strict;
-use Parse::Pidl qw(warning fatal);
+use Parse::Pidl qw(warning error fatal);
use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference);
use Parse::Pidl::Util qw(ParseExpr has_property is_constant);
use Parse::Pidl::NDR qw(GetNextLevel);
return $res;
}
-sub AllocOutVar($$$$)
+sub AllocOutVar($$$$$)
{
- my ($e, $mem_ctx, $name, $env) = @_;
+ my ($e, $mem_ctx, $name, $env, $fail) = @_;
my $l = $e->{LEVELS}[0];
if ($l->{TYPE} eq "POINTER") {
my $nl = GetNextLevel($e, $l);
$l = $nl if ($nl->{TYPE} eq "ARRAY");
- }
+ } elsif
# we don't support multi-dimentional arrays yet
- if ($l->{TYPE} eq "ARRAY") {
+ ($l->{TYPE} eq "ARRAY") {
my $nl = GetNextLevel($e, $l);
if ($nl->{TYPE} eq "ARRAY") {
fatal($e->{ORIGINAL},"multi-dimentional [out] arrays are not supported!");
}
+ } else {
+ # neither pointer nor array, no need to alloc something.
+ return;
}
if ($l->{TYPE} eq "ARRAY") {
- my $size = ParseExpr($l->{SIZE_IS}, $env, $e);
- pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);";
+ unless(defined($l->{SIZE_IS})) {
+ error($e->{ORIGINAL}, "No size known for array `$e->{NAME}'");
+ pidl "#error No size known for array `$e->{NAME}'";
+ } else {
+ my $size = ParseExpr($l->{SIZE_IS}, $env, $e);
+ pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);";
+ }
} else {
pidl "$name = talloc_zero($mem_ctx, " . DeclLevel($e, 1) . ");";
}
pidl "if ($name == NULL) {";
- pidl "\ttalloc_free($mem_ctx);";
- pidl "\treturn false;";
+ $fail->();
pidl "}";
pidl "";
}
+sub CallWithStruct($$$$)
+{
+ my ($pipes_struct, $mem_ctx, $fn, $fail) = @_;
+ my $env = GenerateFunctionOutEnv($fn);
+ my $hasout = 0;
+ foreach (@{$fn->{ELEMENTS}}) {
+ if (grep(/out/, @{$_->{DIRECTION}})) { $hasout = 1; }
+ }
+
+ pidl "ZERO_STRUCT(r->out);" if ($hasout);
+
+ my $proto = "_$fn->{NAME}(pipes_struct *p, struct $fn->{NAME} *r";
+ my $ret = "_$fn->{NAME}($pipes_struct, r";
+ foreach (@{$fn->{ELEMENTS}}) {
+ my @dir = @{$_->{DIRECTION}};
+ if (grep(/in/, @dir) and grep(/out/, @dir)) {
+ pidl "r->out.$_->{NAME} = r->in.$_->{NAME};";
+ }
+ }
+
+ foreach (@{$fn->{ELEMENTS}}) {
+ my @dir = @{$_->{DIRECTION}};
+ if (grep(/in/, @dir) and grep(/out/, @dir)) {
+ # noop
+ } elsif (grep(/out/, @dir) and not
+ has_property($_, "represent_as")) {
+ AllocOutVar($_, $mem_ctx, "r->out.$_->{NAME}", $env, $fail);
+ }
+ }
+ $ret .= ")";
+ $proto .= ");";
+
+ if ($fn->{RETURN_TYPE}) {
+ $ret = "r->out.result = $ret";
+ $proto = "$fn->{RETURN_TYPE} $proto";
+ } else {
+ $proto = "void $proto";
+ }
+
+ pidl_hdr "$proto";
+ pidl "$ret;";
+}
+
sub ParseFunction($$)
{
my ($if,$fn) = @_;
pidl "DATA_BLOB blob;";
pidl "struct $fn->{NAME} *r;";
pidl "";
- pidl "call = &ndr_table_$if->{NAME}.calls[$op];";
+ pidl "call = &p->interface->calls[$op];";
pidl "";
pidl "r = talloc(talloc_tos(), struct $fn->{NAME});";
pidl "if (r == NULL) {";
pidl "}";
pidl "";
- my $env = GenerateFunctionOutEnv($fn);
- my $hasout = 0;
- foreach (@{$fn->{ELEMENTS}}) {
- if (grep(/out/, @{$_->{DIRECTION}})) { $hasout = 1; }
- }
-
- pidl "ZERO_STRUCT(r->out);" if ($hasout);
-
- my $proto = "_$fn->{NAME}(pipes_struct *p, struct $fn->{NAME} *r";
- my $ret = "_$fn->{NAME}(p, r";
- foreach (@{$fn->{ELEMENTS}}) {
- my @dir = @{$_->{DIRECTION}};
- if (grep(/in/, @dir) and grep(/out/, @dir)) {
- pidl "r->out.$_->{NAME} = r->in.$_->{NAME};";
+ CallWithStruct("p", "r", $fn,
+ sub {
+ pidl "\ttalloc_free(r);";
+ pidl "\treturn false;";
}
- }
-
- foreach (@{$fn->{ELEMENTS}}) {
- my @dir = @{$_->{DIRECTION}};
- if (grep(/in/, @dir) and grep(/out/, @dir)) {
- # noop
- } elsif (grep(/out/, @dir) and not
- has_property($_, "represent_as")) {
- AllocOutVar($_, "r", "r->out.$_->{NAME}", $env);
- }
- }
- $ret .= ")";
- $proto .= ");";
-
- if ($fn->{RETURN_TYPE}) {
- $ret = "r->out.result = $ret";
- $proto = "$fn->{RETURN_TYPE} $proto";
- } else {
- $proto = "void $proto";
- }
-
- pidl_hdr "$proto";
- pidl "$ret;";
+ );
pidl "";
pidl "if (p->rng_fault_state) {";
pidl "";
}
+sub ParseDispatchFunction($)
+{
+ my ($if) = @_;
+
+ pidl_hdr "NTSTATUS rpc_$if->{NAME}_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, const char *interface, uint32_t interface_version, uint32_t opnum, void *r);";
+ pidl "NTSTATUS rpc_$if->{NAME}_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, const char *interface, uint32_t interface_version, uint32_t opnum, void *_r)";
+ pidl "{";
+ indent;
+ pidl "if (cli->pipes_struct == NULL) {";
+ pidl "\treturn NT_STATUS_INVALID_PARAMETER;";
+ pidl "}";
+ pidl "";
+ pidl "switch (opnum)";
+ pidl "{";
+ indent;
+ foreach my $fn (@{$if->{FUNCTIONS}}) {
+ next if ($fn->{PROPERTIES}{noopnum});
+ my $op = "NDR_".uc($fn->{NAME});
+ pidl "case $op: {";
+ indent;
+ pidl "struct $fn->{NAME} *r = (struct $fn->{NAME} *)_r;";
+ CallWithStruct("cli->pipes_struct", "mem_ctx", $fn,
+ sub { pidl "return NT_STATUS_NO_MEMORY;"; });
+ pidl "return NT_STATUS_OK;";
+ deindent;
+ pidl "}";
+ pidl "";
+ }
+
+ pidl "default:";
+ pidl "\treturn NT_STATUS_NOT_IMPLEMENTED;";
+ deindent;
+ pidl "}";
+ deindent;
+ pidl "}";
+
+ pidl "";
+}
+
sub ParseInterface($)
{
my $if = shift;
pidl "}";
pidl "";
+ ParseDispatchFunction($if);
+
pidl_hdr "NTSTATUS rpc_$if->{NAME}_init(void);";
pidl "NTSTATUS rpc_$if->{NAME}_init(void)";
pidl "{";
- pidl "\treturn rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", \&ndr_table_$if->{NAME}.syntax_id, api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));";
+ pidl "\treturn rpc_srv_register(SMB_RPC_INTERFACE_VERSION, \"$if->{NAME}\", \"$if->{NAME}\", NDR_".$uif."_UUID, NDR_".$uif."_VERSION, api_$if->{NAME}_cmds, sizeof(api_$if->{NAME}_cmds) / sizeof(struct api_struct));";
pidl "}";
pidl_hdr "#endif /* __SRV_$uif\__ */";