Author: jelmer
Date: 2006-03-24 01:03:02 +0000 (Fri, 24 Mar 2006)
New Revision: 14687

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14687

Log:
Start working on support for represent_as() and transmit_as() as 
an alternative to subcontext()

Added:
   branches/SAMBA_4_0/source/pidl/tests/ndr_represent.pl
Modified:
   branches/SAMBA_4_0/source/pidl/TODO
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
   branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
   branches/SAMBA_4_0/source/pidl/pidl
   branches/SAMBA_4_0/source/pidl/tests/Util.pm


Changeset:
Modified: branches/SAMBA_4_0/source/pidl/TODO
===================================================================
--- branches/SAMBA_4_0/source/pidl/TODO 2006-03-23 21:47:16 UTC (rev 14686)
+++ branches/SAMBA_4_0/source/pidl/TODO 2006-03-24 01:03:02 UTC (rev 14687)
@@ -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 ?
 

Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm        2006-03-23 
21:47:16 UTC (rev 14686)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/NDR.pm        2006-03-24 
01:03:02 UTC (rev 14687)
@@ -2,7 +2,7 @@
 # Samba4 NDR info tree generator
 # Copyright [EMAIL PROTECTED] 2000-2003
 # Copyright [EMAIL PROTECTED] 2001
-# Copyright [EMAIL PROTECTED] 2004-2005
+# Copyright [EMAIL PROTECTED] 2004-2006
 # released under the GNU GPL
 
 =pod
@@ -258,6 +258,8 @@
 
        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 @@
                        $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 @@
                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 @@
        "default"               => ["ELEMENT"],
 
        "represent_as"          => ["ELEMENT"],
+       "transmit_as"           => ["ELEMENT"],
 
        # subcontext
        "subcontext"            => ["ELEMENT"],
@@ -900,6 +904,19 @@
                }
        }
 
+
+       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");
        }

Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm  
2006-03-23 21:47:16 UTC (rev 14686)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm  
2006-03-24 01:03:02 UTC (rev 14687)
@@ -1,6 +1,7 @@
 ###################################################
 # client calls generator
 # Copyright [EMAIL PROTECTED] 2003
+# Copyright [EMAIL PROTECTED] 2005-2006
 # released under the GNU GPL
 
 package Parse::Pidl::Samba4::NDR::Client;

Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm  
2006-03-23 21:47:16 UTC (rev 14686)
+++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm  
2006-03-24 01:03:02 UTC (rev 14687)
@@ -2,7 +2,7 @@
 # Samba4 NDR parser generator for IDL structures
 # Copyright [EMAIL PROTECTED] 2000-2003
 # Copyright [EMAIL PROTECTED] 2001
-# Copyright [EMAIL PROTECTED] 2004-2005
+# Copyright [EMAIL PROTECTED] 2004-2006
 # released under the GNU GPL
 
 package Parse::Pidl::Samba4::NDR::Parser;
@@ -674,6 +674,12 @@
 
        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 @@
        ParseElementPushLevel($e, $e->{LEVELS}[0], $ndr, $var_name, $env, 
$primitives, $deferred);
 
        end_flags($e);
+
 }
 
 #####################################################################
@@ -1067,6 +1074,12 @@
        
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));";
+       }
 }
 
 #####################################################################

Modified: branches/SAMBA_4_0/source/pidl/pidl
===================================================================
--- branches/SAMBA_4_0/source/pidl/pidl 2006-03-23 21:47:16 UTC (rev 14686)
+++ branches/SAMBA_4_0/source/pidl/pidl 2006-03-24 01:03:02 UTC (rev 14687)
@@ -279,7 +279,8 @@
 
 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 @@
 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

Modified: branches/SAMBA_4_0/source/pidl/tests/Util.pm
===================================================================
--- branches/SAMBA_4_0/source/pidl/tests/Util.pm        2006-03-23 21:47:16 UTC 
(rev 14686)
+++ branches/SAMBA_4_0/source/pidl/tests/Util.pm        2006-03-24 01:03:02 UTC 
(rev 14687)
@@ -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 @@
 
 # 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 @@
        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);

Added: branches/SAMBA_4_0/source/pidl/tests/ndr_represent.pl
===================================================================
--- branches/SAMBA_4_0/source/pidl/tests/ndr_represent.pl       2006-03-23 
21:47:16 UTC (rev 14686)
+++ branches/SAMBA_4_0/source/pidl/tests/ndr_represent.pl       2006-03-24 
01:03:02 UTC (rev 14687)
@@ -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;
+}
+'
+);
+
+}

Reply via email to