1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
###################################################
# Samba3 common helper functions
# Copyright jelmer@samba.org 2005
# released under the GNU GPL
package Parse::Pidl::Samba3::Types;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(DeclShort DeclLong InitType DissectType AddType);
use strict;
use Parse::Pidl::Util qw(has_property ParseExpr);
use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
use vars qw($VERSION);
$VERSION = '0.01';
sub init_scalar($$$$)
{
my ($e,$l,$n,$v) = @_;
return "$n = $v;";
}
sub dissect_scalar($$$)
{
my ($e,$l,$n) = @_;
my $t = lc($e->{TYPE});
return "prs_$t(\"$e->{NAME}\", ps, depth, &$n)";
}
sub decl_string($)
{
my $e = shift;
return "UNISTR2";
}
sub init_string($$$$)
{
my ($e,$l,$n,$v) = @_;
return "init_unistr2(&$n, $v, UNI_FLAGS_NONE);";
}
sub dissect_string($$$)
{
my ($e,$l,$n) = @_;
return "FIXME";
}
my $known_types = {
uint8 => {
DECL => "uint8",
INIT => \&init_scalar,
DISSECT => \&dissect_scalar,
},
uint16 => {
DECL => "uint16",
INIT => \&init_scalar,
DISSECT => \&dissect_scalar,
},
uint32 => {
DECL => "uint32",
INIT => \&init_scalar,
DISSECT => \&dissect_scalar,
},
string => {
DECL => \&decl_string,
INIT => \&init_string,
DISSECT => \&dissect_string,
},
NTSTATUS => {
DECL => "NTSTATUS",
INIT => \&init_scalar,
DISSECT => \&dissect_scalar,
},
WERROR => {
DECL => "WERROR",
INIT => \&init_scalar,
DISSECT => \&dissect_scalar,
},
};
sub AddType($$)
{
my ($t,$d) = @_;
warn("Reregistering type $t") if (defined($known_types->{$t}));
$known_types->{$t} = $d;
}
sub GetType($)
{
my $e = shift;
my $t = $known_types->{$e->{TYPE}};
return undef if not $t;
# DECL can be a function
if (ref($t->{DECL}) eq "CODE") {
return $t->{DECL}->($e);
} else {
return $t->{DECL};
}
}
# Return type without special stuff, as used in
# struct declarations
sub DeclShort($)
{
my $e = shift;
my $t = GetType($e);
return undef if not $t;
return "$t $e->{NAME}";
}
sub DeclLong($)
{
my $e = shift;
my $t = GetType($e);
return undef if not $t;
return "$t $e->{NAME}";
}
sub InitType($$$$)
{
my ($e, $l, $varname, $value) = @_;
my $t = $known_types->{$l->{DATA_TYPE}};
return undef if not $t;
# INIT can be a function
if (ref($t->{INIT}) eq "CODE") {
return $t->{INIT}->($e, $l, $varname, $value);
} else {
return $t->{INIT};
}
}
sub DissectType($$$)
{
my ($e, $l, $varname) = @_;
my $t = $known_types->{$l->{DATA_TYPE}};
return undef if not $t;
# DISSECT can be a function
if (ref($t->{DISSECT}) eq "CODE") {
return $t->{DISSECT}->($e, $l, $varname);
} else {
return $t->{DISSECT};
}
}
1;
|