Merge branch 'upstream'
[jelmer/samba4-debian.git] / source / pidl / lib / Parse / Pidl / Samba4 / NDR / Parser.pm
index 6e6d2276818d52b226d936ddd87ba126e243162e..0d1806a0fae31201cfb847e8735b0d75f382cd1f 100644 (file)
@@ -775,8 +775,7 @@ sub ParseElementPrint($$$$)
                                $self->pidl("for ($counter=0;$counter<$length;$counter++) {");
                                $self->indent;
                                $self->pidl("char *idx_$l->{LEVEL_INDEX}=NULL;");
-                               $self->pidl("asprintf(&idx_$l->{LEVEL_INDEX}, \"[\%d]\", $counter);");
-                               $self->pidl("if (idx_$l->{LEVEL_INDEX}) {");
+                               $self->pidl("if (asprintf(&idx_$l->{LEVEL_INDEX}, \"[\%d]\", $counter) != -1) {");
                                $self->indent;
 
                                $var_name = get_array_element($var_name, $counter);
@@ -1611,7 +1610,7 @@ sub ParseUnionPushPrimitives($$$)
                if ($el->{CASE} eq "default") {
                        $have_default = 1;
                }
-               $self->pidl("$el->{CASE}:");
+               $self->pidl("$el->{CASE}: {");
 
                if ($el->{TYPE} ne "EMPTY") {
                        $self->indent;
@@ -1625,7 +1624,7 @@ sub ParseUnionPushPrimitives($$$)
                        $self->ParseElementPush($el, "ndr", {$el->{NAME} => "$varname->$el->{NAME}"}, 1, 0);
                        $self->deindent;
                }
-               $self->pidl("break;");
+               $self->pidl("break; }");
                $self->pidl("");
        }
        if (! $have_default) {
@@ -2149,9 +2148,9 @@ sub ParseFunctionPull($$)
                        $self->pidl("NDR_PULL_ALLOC_N(ndr, r->out.$e->{NAME}, $size);");
 
                        if (grep(/in/, @{$e->{DIRECTION}})) {
-                               $self->pidl("memcpy(r->out.$e->{NAME}, r->in.$e->{NAME}, $size * sizeof(*r->in.$e->{NAME}));");
+                               $self->pidl("memcpy(r->out.$e->{NAME}, r->in.$e->{NAME}, ($size) * sizeof(*r->in.$e->{NAME}));");
                        } else {
-                               $self->pidl("memset(r->out.$e->{NAME}, 0, $size * sizeof(*r->out.$e->{NAME}));");
+                               $self->pidl("memset(r->out.$e->{NAME}, 0, ($size) * sizeof(*r->out.$e->{NAME}));");
                        }
                } else {
                        $self->pidl("NDR_PULL_ALLOC(ndr, r->out.$e->{NAME});");
@@ -2191,6 +2190,26 @@ sub ParseFunctionPull($$)
        $self->pidl("");
 }
 
+sub AuthServiceStruct($$$)
+{
+       my ($self, $ifacename, $authservice) = @_;
+       my @a = split /,/, $authservice;
+       my $authservice_count = $#a + 1;
+
+       $self->pidl("static const char * const $ifacename\_authservice_strings[] = {");
+       foreach my $ap (@a) {
+               $self->pidl("\t$ap, ");
+       }
+       $self->pidl("};");
+       $self->pidl("");
+
+       $self->pidl("static const struct ndr_interface_string_array $ifacename\_authservices = {");
+       $self->pidl("\t.count\t= $authservice_count,");
+       $self->pidl("\t.names\t= $ifacename\_authservice_strings");
+       $self->pidl("};");
+       $self->pidl("");
+}
+
 #####################################################################
 # produce a function call table
 sub FunctionTable($$)
@@ -2238,21 +2257,8 @@ sub FunctionTable($$)
                $interface->{PROPERTIES}->{authservice} = "\"host\"";
        }
 
-       my @a = split /,/, $interface->{PROPERTIES}->{authservice};
-       my $authservice_count = $#a + 1;
-
-       $self->pidl("static const char * const $interface->{NAME}\_authservice_strings[] = {");
-       foreach my $ap (@a) {
-               $self->pidl("\t$ap, ");
-       }
-       $self->pidl("};");
-       $self->pidl("");
-
-       $self->pidl("static const struct ndr_interface_string_array $interface->{NAME}\_authservices = {");
-       $self->pidl("\t.count\t= $endpoint_count,");
-       $self->pidl("\t.names\t= $interface->{NAME}\_authservice_strings");
-       $self->pidl("};");
-       $self->pidl("");
+       $self->AuthServiceStruct($interface->{NAME}, 
+                                    $interface->{PROPERTIES}->{authservice});
 
        $self->pidl("\nconst struct ndr_interface_table ndr_table_$interface->{NAME} = {");
        $self->pidl("\t.name\t\t= \"$interface->{NAME}\",");