summaryrefslogtreecommitdiff
path: root/source4/build/pidl
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2004-05-16 07:39:43 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:53:48 -0500
commitd4fc084c81ad9a91f2b8ceb32c5119fa4c462ff6 (patch)
treeb3d422a54231a463342368876718bff5c97bb1f3 /source4/build/pidl
parent0f3b182ba95dc062c0bcb10efea30938fba47a7c (diff)
downloadsamba-d4fc084c81ad9a91f2b8ceb32c5119fa4c462ff6.tar.gz
samba-d4fc084c81ad9a91f2b8ceb32c5119fa4c462ff6.tar.bz2
samba-d4fc084c81ad9a91f2b8ceb32c5119fa4c462ff6.zip
r750: Rename global $name -> $module.
Start working on parsing structs. (This used to be commit d162dcb52f96b1adfac7123201d31c07ee5c90d6)
Diffstat (limited to 'source4/build/pidl')
-rw-r--r--source4/build/pidl/eparser.pm161
1 files changed, 122 insertions, 39 deletions
diff --git a/source4/build/pidl/eparser.pm b/source4/build/pidl/eparser.pm
index baad7c6489..bb29389538 100644
--- a/source4/build/pidl/eparser.pm
+++ b/source4/build/pidl/eparser.pm
@@ -9,7 +9,7 @@ package IdlEParser;
use strict;
use dump;
-my($name);
+my($module);
#####################################################################
# handlers for parsing ndr argument types
@@ -44,13 +44,26 @@ sub ParamString($)
return $res;
}
+sub ParamStruct($)
+{
+ my($p) = shift;
+ my($res);
+
+ $res .= "\toffset = dissect_${module}_$p->{TYPE}(tvb, offset, pinfo, tree, drep);\n";
+
+ return $res;
+}
+
my %param_handlers = (
+ 'uint8' => \&ParamSimpleNdrType,
'uint16' => \&ParamSimpleNdrType,
'uint32' => \&ParamSimpleNdrType,
'policy_handle' => \&ParamPolicyHandle,
'string' => \&ParamString,
);
+my %hf_info = (); # Field info - remember for trailing stuff
+
#####################################################################
# parse a function
sub ParseParameter($)
@@ -127,8 +140,47 @@ sub ParseStruct($$)
{
my($name) = shift;
my($struct) = shift;
+ my($res);
+
+ # Add struct name to param handler list
+
+ $param_handlers{$name} = \&ParamStruct;
+
+ # Create parse function
+
+ $res .= "/*\n\n";
+ $res .= IdlDump::DumpStruct($struct);
+ $res .= "\n\n*/\n\n";
+
+ $res .= << "EOF";
+int dissect_${module}_$name(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep)
+{
+ proto_item *item = NULL;
+ proto_tree *tree = NULL;
+ int old_offset = offset;
+
+ if (parent_tree) {
+ item = proto_tree_add_text(parent_tree, tvb, offset, -1, "$name");
+ tree = proto_item_add_subtree(item, ett_dcerpc_$module);
+ }
+
+EOF
+
+ foreach my $d (@{$struct->{ELEMENTS}}) {
+ $res .= ParseParameter($d);
+ }
+
+
+$res .= << "EOF";
+
+ proto_item_set_len(item, offset - old_offset);
+
+ return offset;
+}
+
+EOF
- return "/* Struct $name */\n\n";
+ return $res;
}
#####################################################################
@@ -175,8 +227,6 @@ sub Pass2Interface($)
#####################################################################
# Pass 1: Stuff required before structs and functions
-my %hf_info = (); # Field info - remember for trailing stuff
-
sub Pass1ModuleHeader($)
{
my($d) = shift;
@@ -198,7 +248,7 @@ EOF
if ($d->{TYPE} eq "MODULEHEADER" and defined($d->{PROPERTIES}->{uuid})) {
my $uuid = $d->{PROPERTIES}->{uuid};
- $res .= "static e_uuid_t uuid_dcerpc_$name = {\n";
+ $res .= "static e_uuid_t uuid_dcerpc_$module = {\n";
$res .= "\t0x" . substr($uuid, 0, 8);
$res .= ", 0x" . substr($uuid, 9, 4);
$res .= ", 0x" . substr($uuid, 14, 4) . ",\n";
@@ -242,40 +292,73 @@ sub type2base($)
return "BASE_NONE";
}
+sub AddField($$)
+{
+ my($name) = shift;
+ my($type) = shift;
+ my($res) = "";
+
+ my $hf_name = "${name}_${type}";
+ return $res, if defined $hf_info{$hf_name};
+
+ # Make a note about new field
+
+ $res .= "static int hf_$hf_name = -1;\n";
+ $hf_info{$hf_name} = {
+ 'ft' => type2ft($type),
+ 'base' => type2base($name),
+ 'name' => $name
+ };
+
+ return $res;
+}
+
+sub ScanFunction($)
+{
+ my($fn) = shift;
+ my($res) = "";
+
+ foreach my $args ($fn) {
+ foreach my $params (@{$args}) {
+ $res .= AddField($params->{NAME}, $params->{TYPE});
+ }
+ }
+ return $res;
+}
+
+sub ScanTypedef($)
+{
+ my($td) = shift;
+ my($res) = "";
+
+ if ($td->{TYPE} eq "STRUCT") {
+ foreach my $e (@{$td->{ELEMENTS}}) {
+ $res .= AddField($e->{NAME}, $e->{TYPE});
+ }
+ }
+
+ return $res;
+}
+
sub Pass1Interface($)
{
my($interface) = shift;
my($res) = "";
$res .= << "EOF";
-static int proto_dcerpc_$name = -1;
+static int proto_dcerpc_$module = -1;
static int hf_opnum = -1;
static int hf_rc = -1;
static int hf_policy_handle = -1;
-static gint ett_dcerpc_$name = -1;
+static gint ett_dcerpc_$module = -1;
EOF
foreach my $fn (@{$interface->{DATA}}) {
- next, if $fn->{TYPE} ne "FUNCTION";
- foreach my $args ($fn->{DATA}) {
- foreach my $params (@{$args}) {
-
- my $hf_name = "$params->{NAME}_$params->{TYPE}";
- next, if defined $hf_info{$hf_name};
-
- # Make a note about new field
-
- $res .= "static int hf_$hf_name = -1;\n";
- $hf_info{$hf_name} = {
- 'ft' => type2ft($params->{TYPE}),
- 'base' => type2base($params->{TYPE}),
- 'name' => $params->{NAME}
- };
- }
- }
+ $res .= ScanFunction($fn->{DATA}), if $fn->{TYPE} eq "FUNCTION";
+ $res .= ScanTypedef($fn->{DATA}), if $fn->{TYPE} eq "TYPEDEF";
}
$res .= "\n";
@@ -291,7 +374,7 @@ sub Pass3Interface($)
my($interface) = shift;
my($res) = "";
- $res .= "static dcerpc_sub_dissector dcerpc_${name}_dissectors[] = {\n";
+ $res .= "static dcerpc_sub_dissector dcerpc_${module}_dissectors[] = {\n";
my $num = 0;
@@ -299,8 +382,8 @@ sub Pass3Interface($)
if ($d->{TYPE} eq "FUNCTION") {
# Strip module name from function name, if present
my $n = $d->{NAME};
- $n = substr($d->{NAME}, length($name) + 1),
- if $name eq substr($d->{NAME}, 0, length($name));
+ $n = substr($d->{NAME}, length($module) + 1),
+ if $module eq substr($d->{NAME}, 0, length($module));
$res .= "\t{ $num, \"$n\",\n";
$res .= "\t\t$d->{NAME}_rqst,\n";
@@ -325,7 +408,7 @@ sub Parse($)
# Pass 0: set module name
foreach $d (@{$idl}) {
- $name = $d->{NAME}, if ($d->{TYPE} eq "INTERFACE");
+ $module = $d->{NAME}, if ($d->{TYPE} eq "INTERFACE");
}
# Pass 1: header stuff
@@ -349,11 +432,11 @@ sub Parse($)
my $hf_register_info = << "EOF";
\t{ &hf_opnum,
-\t { \"Operation\", \"$name.opnum\", FT_UINT16, BASE_DEC, NULL, 0x0, \"Operation\", HFILL }},
+\t { \"Operation\", \"$module.opnum\", FT_UINT16, BASE_DEC, NULL, 0x0, \"Operation\", HFILL }},
\t{ &hf_policy_handle,
-\t { \"Policy handle\", \"$name.policy\", FT_BYTES, BASE_NONE, NULL, 0x0, \"Policy handle\", HFILL }},
+\t { \"Policy handle\", \"$module.policy\", FT_BYTES, BASE_NONE, NULL, 0x0, \"Policy handle\", HFILL }},
\t{ &hf_rc,
-\t { \"Return code\", \"$name.rc\", FT_UINT32, BASE_HEX, VALS(NT_errors), 0x0, \"Return status code\", HFILL }},
+\t { \"Return code\", \"$module.rc\", FT_UINT32, BASE_HEX, VALS(NT_errors), 0x0, \"Return status code\", HFILL }},
EOF
foreach my $hf (keys(%hf_info)) {
@@ -366,30 +449,30 @@ EOF
$res .= << "EOF";
void
-proto_register_dcerpc_${name}(void)
+proto_register_dcerpc_${module}(void)
{
static hf_register_info hf[] = {
$hf_register_info
};
static gint *ett[] = {
- &ett_dcerpc_$name,
+ &ett_dcerpc_$module,
$ett_info
};
- proto_dcerpc_$name = proto_register_protocol("$name", "$name", "$name");
+ proto_dcerpc_$module = proto_register_protocol("$module", "$module", "$module");
- proto_register_field_array (proto_dcerpc_${name}, hf, array_length (hf));
+ proto_register_field_array (proto_dcerpc_$module, hf, array_length (hf));
proto_register_subtree_array(ett, array_length(ett));
}
void
-proto_reg_handoff_dcerpc_$name(void)
+proto_reg_handoff_dcerpc_$module(void)
{
- dcerpc_init_uuid(proto_dcerpc_$name, ett_dcerpc_$name,
- &uuid_dcerpc_$name, ver_dcerpc_$name,
- dcerpc_${name}_dissectors, hf_opnum);
+ dcerpc_init_uuid(proto_dcerpc_$module, ett_dcerpc_$module,
+ &uuid_dcerpc_$module, ver_dcerpc_$module,
+ dcerpc_${module}_dissectors, hf_opnum);
}
EOF