r14687: Start working on support for represent_as() and transmit_as() as
authorJelmer Vernooij <jelmer@samba.org>
Fri, 24 Mar 2006 01:03:02 +0000 (01:03 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:59:08 +0000 (13:59 -0500)
an alternative to subcontext()
(This used to be commit 744402160d5f994f5440553bb726e95a13033a83)

source4/pidl/TODO
source4/pidl/lib/Parse/Pidl/NDR.pm
source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
source4/pidl/pidl
source4/pidl/tests/Util.pm
source4/pidl/tests/ndr_represent.pl [new file with mode: 0644]

index db64df3dd973a689375e1a056900a82bb7ecb2e6..6203bd412f2c12e178e946aa96235fb167c05b26 100644 (file)
@@ -12,6 +12,9 @@
 - auto-alloc [ref] pointers for Samba4 during pull if they were NULL
  
 - replace subcontext() with represent_as()
+ - NTSTATUS FROM_to_TO (const FROM *f, TO **t); /* FIXME: t needs to be allocated using talloc */
+ - NTSTATUS TO_to_FROM (const TO *t, FROM **f); /* FIXME: f needs to be allocated using talloc */
+ - `
 
 - --explain-ndr option that dumps out parse tree ?
 
index a709abba10166edb1333c07e5c3fc078426e30ff..1d5059bfb59a8d7a52f2ce3ec4a2e612bd52fd5d 100644 (file)
@@ -2,7 +2,7 @@
 # Samba4 NDR info tree generator
 # Copyright tridge@samba.org 2000-2003
 # Copyright tpot@samba.org 2001
-# Copyright jelmer@samba.org 2004-2005
+# Copyright jelmer@samba.org 2004-2006
 # released under the GNU GPL
 
 =pod
@@ -258,6 +258,8 @@ sub GetElementLevelTable($)
 
        push (@$order, {
                TYPE => "DATA",
+               CONVERT_TO => has_property($e, ""),
+               CONVERT_FROM => has_property($e, ""),
                DATA_TYPE => $e->{TYPE},
                IS_DEFERRED => $is_deferred,
                CONTAINS_DEFERRED => can_contain_deferred($e),
@@ -319,8 +321,8 @@ sub find_largest_alignment($)
                        $a = 4; 
                } elsif (has_property($e, "subcontext")) { 
                        $a = 1;
-               } elsif (has_property($e, "represent_as")) {
-                       $a = align_type($e->{PROPERTIES}->{represent_as});
+               } elsif (has_property($e, "transmit_as")) {
+                       $a = align_type($e->{PROPERTIES}->{transmit_as});
                } else {
                        $a = align_type($e->{TYPE}); 
                }
@@ -368,6 +370,7 @@ sub ParseElement($)
                TYPE => $e->{TYPE},
                PROPERTIES => $e->{PROPERTIES},
                LEVELS => GetElementLevelTable($e),
+               REPRESENTATION_TYPE => $e->{PROPERTIES}->{represent_as},
                ALIGN => align_type($e->{TYPE}),
                ORIGINAL => $e
        };
@@ -796,6 +799,7 @@ my %property_list = (
        "default"               => ["ELEMENT"],
 
        "represent_as"          => ["ELEMENT"],
+       "transmit_as"           => ["ELEMENT"],
 
        # subcontext
        "subcontext"            => ["ELEMENT"],
@@ -900,6 +904,19 @@ sub ValidElement($)
                }
        }
 
+
+       if (has_property($e, "subcontext") and has_property($e, "represent_as")) {
+               fatal($e, el_name($e) . " : subcontext() and represent_as() can not be used on the same element");
+       }
+
+       if (has_property($e, "subcontext") and has_property($e, "transmit_as")) {
+               fatal($e, el_name($e) . " : subcontext() and transmit_as() can not be used on the same element");
+       }
+
+       if (has_property($e, "represent_as") and has_property($e, "transmit_as")) {
+               fatal($e, el_name($e) . " : represent_as() and transmit_as() can not be used on the same element");
+       }
+
        if (defined (has_property($e, "subcontext_size")) and not defined(has_property($e, "subcontext"))) {
                fatal($e, el_name($e) . " : subcontext_size() on non-subcontext element");
        }
index f19f4df3190c3dd6e6662938ec9260b89256ae12..ace1e796727a61406ce30dd68128ace48b7505d5 100644 (file)
@@ -1,6 +1,7 @@
 ###################################################
 # client calls generator
 # Copyright tridge@samba.org 2003
+# Copyright jelmer@samba.org 2005-2006
 # released under the GNU GPL
 
 package Parse::Pidl::Samba4::NDR::Client;
index bc7e4ce545018fe692963c3478ab1f385aea7f04..81e30e1053b9d9ca827040fac22f9fcf5af86842 100644 (file)
@@ -2,7 +2,7 @@
 # Samba4 NDR parser generator for IDL structures
 # Copyright tridge@samba.org 2000-2003
 # Copyright tpot@samba.org 2001
-# Copyright jelmer@samba.org 2004-2005
+# Copyright jelmer@samba.org 2004-2006
 # released under the GNU GPL
 
 package Parse::Pidl::Samba4::NDR::Parser;
@@ -674,6 +674,12 @@ sub ParseElementPush($$$$$$)
 
        return unless $primitives or ($deferred and ContainsDeferred($e, $e->{LEVELS}[0]));
 
+       # Representation type is different from transmit_as
+       if ($e->{REPRESENTATION_TYPE}) {
+               pidl "/* FIXME: Convert from $e->{REPRESENTATION_TYPE} to $e->{TYPE} */";
+               pidl "NDR_CHECK(ndr_$e->{REPRESENTATION_TYPE}_to_$e->{TYPE}(FIXME, FIXME));";
+       }
+
        start_flags($e);
 
        if (my $value = has_property($e, "value")) {
@@ -683,6 +689,7 @@ sub ParseElementPush($$$$$$)
        ParseElementPushLevel($e, $e->{LEVELS}[0], $ndr, $var_name, $env, $primitives, $deferred);
 
        end_flags($e);
+
 }
 
 #####################################################################
@@ -1067,6 +1074,12 @@ sub ParseElementPull($$$$$$)
        ParseElementPullLevel($e,$e->{LEVELS}[0],$ndr,$var_name,$env,$primitives,$deferred);
 
        end_flags($e);
+
+       # Representation type is different from transmit_as
+       if ($e->{REPRESENTATION_TYPE}) {
+               pidl "/* FIXME: Convert from $e->{TYPE} to $e->{REPRESENTATION_TYPE} */";
+               pidl "NDR_CHECK(ndr_$e->{TYPE}_to_$e->{REPRESENTATION_TYPE}(FIXME, FIXME));";
+       }
 }
 
 #####################################################################
index d913e84e7d5dbb33f76b760674a3fa7d8477b7a5..314ab7c60b190f92cddc5aa38af82240d642abd9 100755 (executable)
@@ -279,7 +279,8 @@ Datagram support (ncadg_*)
 
 in, out, ref, length_is, switch_is, size_is, uuid, case, default, string, 
 unique, ptr, pointer_default, v1_enum, object, helpstring, range, local, 
-call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as.
+call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as, 
+transmit_as.
 
 =head2 PIDL Specific properties
 
@@ -357,7 +358,7 @@ helpstringdll, hidden, idl_module, idl_quote, id, immediatebind, importlib,
 import, include, includelib, last_is, lcid, licensed, max_is, module, 
 ms_union, no_injected_text, nonbrowsable, noncreatable, nonextensible, odl, 
 oleautomation, optional, pragma, propget, propputref, propput, readonly, 
-requestedit, restricted, retval, source, transmit_as, uidefault, 
+requestedit, restricted, retval, source, uidefault, 
 usesgetlasterror, vararg, vi_progid, wire_marshal. 
 
 =head1 EXAMPLES
index 3e0f2148544568bf7275c42e56f5cf9bffbcfddb..bb633f6e32ce299862946a3ffc4847b65c02b217 100644 (file)
@@ -1,5 +1,5 @@
 # Some simple utility functions for pidl tests
-# Copyright (C) 2005 Jelmer Vernooij
+# Copyright (C) 2005-2006 Jelmer Vernooij
 # Published under the GNU General Public License
 
 package Util;
@@ -18,9 +18,9 @@ use Parse::Pidl::Samba4::Header;
 
 # Generate a Samba4 parser for an IDL fragment and run it with a specified 
 # piece of code to check whether the parser works as expected
-sub test_samba4_ndr($$$)
+sub test_samba4_ndr
 {
-       my ($name,$idl,$c) = @_;
+       my ($name,$idl,$c,$extra) = @_;
        my $pidl = Parse::Pidl::IDL::parse_string("interface echo { $idl }; ", "<$name>");
        
        ok(defined($pidl), "($name) parse idl");
@@ -58,6 +58,7 @@ SKIP: {
        print CC $header;
        print CC $ndrheader;
        print CC $ndrparser;
+       print CC $extra if ($extra);
        print CC "int main(int argc, const char **argv)
 {
        TALLOC_CTX *mem_ctx = talloc_init(NULL);
diff --git a/source4/pidl/tests/ndr_represent.pl b/source4/pidl/tests/ndr_represent.pl
new file mode 100644 (file)
index 0000000..772df2b
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+# NDR represent_as() / transmit_as() tests
+# (C) 2006 Jelmer Vernooij. Published under the GNU GPL
+use strict;
+
+use Test::More tests => 1 * 8;
+use FindBin qw($RealBin);
+use lib "$RealBin/../lib";
+use lib "$RealBin";
+use Util qw(test_samba4_ndr);
+
+SKIP: {
+       skip "represent_as() is not finished yet", 8;
+
+test_samba4_ndr('represent_as-simple', 
+'
+       void bla([in,represent_as(foo)] uint8 x);
+',
+'
+       uint8_t expected[] = { 0x0D };
+       DATA_BLOB in_blob = { expected, 1 };
+       struct ndr_pull *ndr = ndr_pull_init_blob(&in_blob, NULL);
+       struct bla r;
+
+       if (NT_STATUS_IS_ERR(ndr_pull_bla(ndr, NDR_SCALARS|NDR_BUFFERS, &r)))
+               return 1;
+
+       if (r != 13)
+               return 2;
+',
+'
+NTSTATUS ndr_uint8_to_foo(uint8 from, foo *to)
+{
+       *to = from;
+       return NT_STATUS_OK;
+}
+'
+);
+
+}