Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / pidl / lib / Parse / Pidl / Samba4 / NDR / Parser.pm
index 3e724c986da89fc47cd121c7519e3e6c60cde80e..83bca288edee8bc760cb82b5943cd48849031382 100644 (file)
@@ -204,12 +204,12 @@ sub ParseArrayPushHeader($$$$$$)
        }
 
        if ((!$l->{IS_SURROUNDING}) and $l->{IS_CONFORMANT}) {
-               $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, $size));");
+               $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, $size));");
        }
        
        if ($l->{IS_VARYING}) {
-               $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, 0));");  # array offset
-               $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, $length));");
+               $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, 0));");  # array offset
+               $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, $length));");
        } 
 
        return $length;
@@ -567,17 +567,24 @@ sub ParseElementPushLevel
        }
 
        if ($l->{TYPE} eq "POINTER" and $deferred) {
+               my $rel_var_name = $var_name;
                if ($l->{POINTER_TYPE} ne "ref") {
                        $self->pidl("if ($var_name) {");
                        $self->indent;
                        if ($l->{POINTER_TYPE} eq "relative") {
-                               $self->pidl("NDR_CHECK(ndr_push_relative_ptr2($ndr, $var_name));");
+                               $self->pidl("NDR_CHECK(ndr_push_relative_ptr2_start($ndr, $rel_var_name));");
+                       }
+                       if ($l->{POINTER_TYPE} eq "relative_short") {
+                               $self->pidl("NDR_CHECK(ndr_push_short_relative_ptr2($ndr, $var_name));");
                        }
                }
                $var_name = get_value_of($var_name);
                $self->ParseElementPushLevel($e, GetNextLevel($e, $l), $ndr, $var_name, $env, 1, 1);
 
                if ($l->{POINTER_TYPE} ne "ref") {
+                       if ($l->{POINTER_TYPE} eq "relative") {
+                               $self->pidl("NDR_CHECK(ndr_push_relative_ptr2_end($ndr, $rel_var_name));");
+                       }
                        $self->deindent;
                        $self->pidl("}");
                }
@@ -670,6 +677,8 @@ sub ParsePtrPush($$$$$)
                }
        } elsif ($l->{POINTER_TYPE} eq "relative") {
                $self->pidl("NDR_CHECK(ndr_push_relative_ptr1($ndr, $var_name));");
+       } elsif ($l->{POINTER_TYPE} eq "relative_short") {
+               $self->pidl("NDR_CHECK(ndr_push_short_relative_ptr1($ndr, $var_name));");
        } elsif ($l->{POINTER_TYPE} eq "unique") {
                $self->pidl("NDR_CHECK(ndr_push_unique_ptr($ndr, $var_name));");
        } elsif ($l->{POINTER_TYPE} eq "full") {
@@ -1038,7 +1047,7 @@ sub ParseElementPullLevel
                        $self->pidl("if ($var_name) {");
                        $self->indent;
 
-                       if ($l->{POINTER_TYPE} eq "relative") {
+                       if ($l->{POINTER_TYPE} eq "relative" or $l->{POINTER_TYPE} eq "relative_short") {
                                $self->pidl("uint32_t _relative_save_offset;");
                                $self->pidl("_relative_save_offset = $ndr->offset;");
                                $self->pidl("NDR_CHECK(ndr_pull_relative_ptr2($ndr, $var_name));");
@@ -1053,7 +1062,12 @@ sub ParseElementPullLevel
                $self->ParseMemCtxPullEnd($e, $l, $ndr);
 
                if ($l->{POINTER_TYPE} ne "ref") {
-                       if ($l->{POINTER_TYPE} eq "relative") {
+                       if ($l->{POINTER_TYPE} eq "relative") {
+                               $self->pidl("if ($ndr->offset > $ndr->relative_highest_offset) {");
+                               $self->indent;
+                               $self->pidl("$ndr->relative_highest_offset = $ndr->offset;");
+                               $self->deindent;
+                               $self->pidl("}");
                                $self->pidl("$ndr->offset = _relative_save_offset;");
                        }
                        $self->deindent;
@@ -1165,6 +1179,8 @@ sub ParsePtrPull($$$$$)
                 ($l->{POINTER_TYPE} eq "relative") or
                 ($l->{POINTER_TYPE} eq "full")) {
                $self->pidl("NDR_CHECK(ndr_pull_generic_ptr($ndr, &_ptr_$e->{NAME}));");
+       } elsif ($l->{POINTER_TYPE} eq "relative_short") {
+               $self->pidl("NDR_CHECK(ndr_pull_relative_ptr_short($ndr, &_ptr_$e->{NAME}));");
        } else {
                die("Unhandled pointer type $l->{POINTER_TYPE}");
        }
@@ -1185,7 +1201,7 @@ sub ParsePtrPull($$$$$)
        }
 
        #$self->pidl("memset($var_name, 0, sizeof($var_name));");
-       if ($l->{POINTER_TYPE} eq "relative") {
+       if ($l->{POINTER_TYPE} eq "relative" or $l->{POINTER_TYPE} eq "relative_short") {
                $self->pidl("NDR_CHECK(ndr_pull_relative_ptr1($ndr, $var_name, _ptr_$e->{NAME}));");
        }
        $self->deindent;
@@ -1220,9 +1236,9 @@ sub ParseStructPushPrimitives($$$$$)
                                $size = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e->{ORIGINAL});
                        }
 
-                       $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, $size));");
+                       $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, $size));");
                } else {
-                       $self->pidl("NDR_CHECK(ndr_push_uint32($ndr, NDR_SCALARS, ndr_string_array_size($ndr, $varname->$e->{NAME})));");
+                       $self->pidl("NDR_CHECK(ndr_push_uint3264($ndr, NDR_SCALARS, ndr_string_array_size($ndr, $varname->$e->{NAME})));");
                }
        }
 
@@ -1235,6 +1251,8 @@ sub ParseStructPushPrimitives($$$$$)
        }
 
        $self->ParseElementPush($_, $ndr, $env, 1, 0) foreach (@{$struct->{ELEMENTS}});
+
+       $self->pidl("NDR_CHECK(ndr_push_trailer_align($ndr, $struct->{ALIGN}));");
 }
 
 sub ParseStructPushDeferred($$$$)
@@ -1287,7 +1305,7 @@ sub ParseEnumPush($$$$)
        my($type_fn) = $enum->{BASE_TYPE};
 
        $self->start_flags($enum, $ndr);
-       $self->pidl("NDR_CHECK(ndr_push_$type_fn($ndr, NDR_SCALARS, $varname));");
+       $self->pidl("NDR_CHECK(ndr_push_enum_$type_fn($ndr, NDR_SCALARS, $varname));");
        $self->end_flags($enum, $ndr);
 }
 
@@ -1301,7 +1319,7 @@ sub ParseEnumPull($$$$)
 
        $self->pidl("$type_v_decl v;");
        $self->start_flags($enum, $ndr);
-       $self->pidl("NDR_CHECK(ndr_pull_$type_fn($ndr, NDR_SCALARS, &v));");
+       $self->pidl("NDR_CHECK(ndr_pull_enum_$type_fn($ndr, NDR_SCALARS, &v));");
        $self->pidl("*$varname = v;");
 
        $self->end_flags($enum, $ndr);
@@ -1464,9 +1482,13 @@ sub DeclarePtrVariables($$)
 {
        my ($self,$e) = @_;
        foreach my $l (@{$e->{LEVELS}}) {
+               my $size = 32;
                if ($l->{TYPE} eq "POINTER" and 
                        not ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP")) {
-                       $self->pidl("uint32_t _ptr_$e->{NAME};");
+                       if ($l->{POINTER_TYPE} eq "relative_short") {
+                               $size = 16;
+                       }
+                       $self->pidl("uint${size}_t _ptr_$e->{NAME};");
                        last;
                }
        }
@@ -1533,6 +1555,8 @@ sub ParseStructPullPrimitives($$$$$)
        $self->ParseElementPull($_, $ndr, $env, 1, 0) foreach (@{$struct->{ELEMENTS}});
 
        $self->add_deferred();
+
+       $self->pidl("NDR_CHECK(ndr_pull_trailer_align($ndr, $struct->{ALIGN}));");
 }
 
 sub ParseStructPullDeferred($$$$$)
@@ -1594,7 +1618,7 @@ sub ParseStructNdrSize($$$$)
        if (my $flags = has_property($t, "flag")) {
                $self->pidl("flags |= $flags;");
        }
-       $self->pidl("return ndr_size_struct($varname, flags, (ndr_push_flags_fn_t)ndr_push_$name, ic);");
+       $self->pidl("return ndr_size_struct($varname, flags, (ndr_push_flags_fn_t)ndr_push_$name);");
 }
 
 sub DeclStruct($$$$)
@@ -1606,7 +1630,7 @@ sub DeclStruct($$$$)
 sub ArgsStructNdrSize($$$)
 {
        my ($d, $name, $varname) = @_;
-       return "const struct $name *$varname, struct smb_iconv_convenience *ic, int flags";
+       return "const struct $name *$varname, int flags";
 }
 
 $typefamily{STRUCT} = {
@@ -1629,7 +1653,7 @@ sub ParseUnionNdrSize($$$)
                $self->pidl("flags |= $flags;");
        }
 
-       $self->pidl("return ndr_size_union($varname, flags, level, (ndr_push_flags_fn_t)ndr_push_$name, ic);");
+       $self->pidl("return ndr_size_union($varname, flags, level, (ndr_push_flags_fn_t)ndr_push_$name);");
 }
 
 sub ParseUnionPushPrimitives($$$$)
@@ -1644,6 +1668,10 @@ sub ParseUnionPushPrimitives($$$$)
                $self->pidl("NDR_CHECK(ndr_push_$e->{SWITCH_TYPE}($ndr, NDR_SCALARS, level));");
        }
 
+       if (defined($e->{ALIGN})) {
+               $self->pidl("NDR_CHECK(ndr_push_union_align($ndr, $e->{ALIGN}));");
+       }
+
        $self->pidl("switch (level) {");
        $self->indent;
        foreach my $el (@{$e->{ELEMENTS}}) {
@@ -1669,7 +1697,7 @@ sub ParseUnionPushPrimitives($$$$)
        }
        if (! $have_default) {
                $self->pidl("default:");
-               $self->pidl("\treturn ndr_push_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);");
+               $self->pidl("\treturn ndr_push_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u at \%s\", level, __location__);");
        }
        $self->deindent;
        $self->pidl("}");
@@ -1705,7 +1733,7 @@ sub ParseUnionPushDeferred($$$$)
        }
        if (! $have_default) {
                $self->pidl("default:");
-               $self->pidl("\treturn ndr_push_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);");
+               $self->pidl("\treturn ndr_push_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u at \%s\", level, __location__);");
        }
        $self->deindent;
        $self->pidl("}");
@@ -1784,10 +1812,14 @@ sub ParseUnionPullPrimitives($$$$$)
        if (defined($switch_type)) {
                $self->pidl("NDR_CHECK(ndr_pull_$switch_type($ndr, NDR_SCALARS, &_level));");
                $self->pidl("if (_level != level) {"); 
-               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value %u for $varname\", _level);");
+               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value %u for $varname at \%s\", _level, __location__);");
                $self->pidl("}");
        }
 
+       if (defined($e->{ALIGN})) {
+               $self->pidl("NDR_CHECK(ndr_pull_union_align($ndr, $e->{ALIGN}));");
+       }
+
        $self->pidl("switch (level) {");
        $self->indent;
        foreach my $el (@{$e->{ELEMENTS}}) {
@@ -1814,7 +1846,7 @@ sub ParseUnionPullPrimitives($$$$$)
        }
        if (! $have_default) {
                $self->pidl("default:");
-               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);");
+               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u at \%s\", level, __location__);");
        }
        $self->deindent;
        $self->pidl("}");
@@ -1848,7 +1880,7 @@ sub ParseUnionPullDeferred($$$$)
        }
        if (! $have_default) {
                $self->pidl("default:");
-               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);");
+               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u at \%s\", level, __location__);");
        }
        $self->deindent;
        $self->pidl("}");
@@ -1909,7 +1941,7 @@ sub DeclUnion($$$$)
 sub ArgsUnionNdrSize($$)
 {
        my ($d,$name) = @_;
-       return "const union $name *r, uint32_t level, struct smb_iconv_convenience *ic, int flags";
+       return "const union $name *r, uint32_t level, int flags";
 }
 
 $typefamily{UNION} = {
@@ -2123,7 +2155,7 @@ sub AllocateArrayLevel($$$$$$)
                $self->pidl("}");
                if (grep(/in/,@{$e->{DIRECTION}}) and
                    grep(/out/,@{$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}));");
                }
                return;
        }