1 ###################################################
2 # Samba4 parser generator for IDL structures
3 # Copyright tridge@samba.org 2000-2003
4 # Copyright tpot@samba.org 2001
5 # released under the GNU GPL
12 # the list of needed functions
21 #####################################################################
22 # parse a properties list
23 sub ParseProperties($)
26 foreach my $d (@{$props}) {
27 if (ref($d) ne "HASH") {
30 foreach my $k (keys %{$d}) {
31 pidl "[$k($d->{$k})] ";
37 ###################################
38 # find a sibling var in a structure
43 my($fn) = $e->{PARENT};
45 if ($name =~ /\*(.*)/) {
49 if ($fn->{TYPE} eq "FUNCTION") {
50 for my $e2 (@{$fn->{DATA}}) {
51 if ($e2->{NAME} eq $name) {
57 for my $e2 (@{$fn->{ELEMENTS}}) {
58 if ($e2->{NAME} eq $name) {
62 die "invalid sibling '$name'";
65 ####################################################################
66 # work out the name of a size_is() variable
67 sub find_size_var($$$)
71 my($var_prefix) = shift;
73 my($fn) = $e->{PARENT};
75 if (util::is_constant($size)) {
79 if ($size =~ /ndr->|\(/) {
85 if ($size =~ /\*(.*)/) {
90 if ($fn->{TYPE} ne "FUNCTION") {
91 return $prefix . "r->$size";
94 my $e2 = find_sibling($e, $size);
96 if (util::has_property($e2, "in") && util::has_property($e2, "out")) {
97 return $prefix . "$var_prefix$size";
99 if (util::has_property($e2, "in")) {
100 return $prefix . "r->in.$size";
102 if (util::has_property($e2, "out")) {
103 return $prefix . "r->out.$size";
106 die "invalid variable in $size for element $e->{NAME} in $fn->{NAME}\n";
110 #####################################################################
111 # work out is a parse function should be declared static or not
115 if ($fn->{TYPE} eq "TYPEDEF") {
116 if (util::has_property($fn->{DATA}, "public")) {
121 if ($fn->{TYPE} eq "FUNCTION") {
122 if (util::has_property($fn, "public")) {
130 ###################################################################
131 # setup any special flags for an element or structure
135 my $flags = util::has_property($e, "flag");
136 if (defined $flags) {
137 pidl "\t{ uint32_t _flags_save_$e->{TYPE} = ndr->flags;\n";
138 pidl "\tndr->flags |= $flags;\n";
142 ###################################################################
143 # end any special flags for an element or structure
147 my $flags = util::has_property($e, "flag");
148 if (defined $flags) {
149 pidl "\tndr->flags = _flags_save_$e->{TYPE};\n\t}\n";
154 #####################################################################
155 # work out the correct alignment for a structure
161 for my $e (@{$s->{ELEMENTS}}) {
164 if (!util::need_wire_pointer($e)
165 && defined $structs{$e->{TYPE}}) {
166 if ($structs{$e->{TYPE}}->{DATA}->{TYPE} eq "STRUCT") {
167 $a = struct_alignment($structs{$e->{TYPE}}->{DATA});
168 } elsif ($structs{$e->{TYPE}}->{DATA}->{TYPE} eq "UNION") {
169 if (defined $structs{$e->{TYPE}}->{DATA}) {
170 $a = union_alignment($structs{$e->{TYPE}}->{DATA});
174 $a = util::type_align($e);
185 #####################################################################
186 # work out the correct alignment for a union
193 foreach my $e (@{$u->{DATA}}) {
196 if ($e->{TYPE} eq "EMPTY") {
200 if (!util::need_wire_pointer($e)
201 && defined $structs{$e->{DATA}->{TYPE}}) {
202 my $s = $structs{$e->{DATA}->{TYPE}};
203 if ($s->{DATA}->{TYPE} eq "STRUCT") {
204 $a = struct_alignment($s->{DATA});
205 } elsif ($s->{DATA}->{TYPE} eq "UNION") {
206 $a = union_alignment($s->{DATA});
209 $a = util::type_align($e->{DATA});
220 #####################################################################
221 # parse an array - push side
222 sub ParseArrayPush($$$)
225 my $var_prefix = shift;
226 my $ndr_flags = shift;
228 my $size = find_size_var($e, util::array_size($e), $var_prefix);
230 if (defined $e->{CONFORMANT_SIZE}) {
231 # the conformant size has already been pushed
232 } elsif (!util::is_inline_array($e)) {
233 # we need to emit the array size
234 pidl "\t\tNDR_CHECK(ndr_push_uint32(ndr, $size));\n";
237 if (my $length = util::has_property($e, "length_is")) {
238 $length = find_size_var($e, $length, $var_prefix);
239 pidl "\t\tNDR_CHECK(ndr_push_uint32(ndr, 0));\n";
240 pidl "\t\tNDR_CHECK(ndr_push_uint32(ndr, $length));\n";
244 if (util::is_scalar_type($e->{TYPE})) {
245 pidl "\t\tNDR_CHECK(ndr_push_array_$e->{TYPE}(ndr, $ndr_flags, $var_prefix$e->{NAME}, $size));\n";
247 pidl "\t\tNDR_CHECK(ndr_push_array(ndr, $ndr_flags, $var_prefix$e->{NAME}, sizeof($var_prefix$e->{NAME}\[0]), $size, (ndr_push_flags_fn_t)ndr_push_$e->{TYPE}));\n";
251 #####################################################################
253 sub ParseArrayPrint($$)
256 my $var_prefix = shift;
257 my $size = find_size_var($e, util::array_size($e), $var_prefix);
258 my $length = util::has_property($e, "length_is");
260 if (defined $length) {
261 $size = find_size_var($e, $length, $var_prefix);
264 if (util::is_scalar_type($e->{TYPE})) {
265 pidl "\t\tndr_print_array_$e->{TYPE}(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME}, $size);\n";
267 pidl "\t\tndr_print_array(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME}, sizeof($var_prefix$e->{NAME}\[0]), $size, (ndr_print_fn_t)ndr_print_$e->{TYPE});\n";
271 #####################################################################
272 # parse an array - pull side
273 sub ParseArrayPull($$$)
276 my $var_prefix = shift;
277 my $ndr_flags = shift;
279 my $size = find_size_var($e, util::array_size($e), $var_prefix);
280 my $alloc_size = $size;
282 # if this is a conformant array then we use that size to allocate, and make sure
283 # we allocate enough to pull the elements
284 if (defined $e->{CONFORMANT_SIZE}) {
285 $alloc_size = $e->{CONFORMANT_SIZE};
287 pidl "\tif ($size > $alloc_size) {\n";
288 pidl "\t\treturn ndr_pull_error(ndr, NDR_ERR_CONFORMANT_SIZE, \"Bad conformant size %u should be %u\", $alloc_size, $size);\n";
290 } elsif (!util::is_inline_array($e)) {
291 if ($var_prefix =~ /^r->out/ && $size =~ /^\*r->in/) {
292 my $size2 = substr($size, 1);
293 pidl "if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) { NDR_ALLOC(ndr, $size2); }\n";
296 # non fixed arrays encode the size just before the array
298 pidl "\t\tuint32_t _array_size;\n";
299 pidl "\t\tNDR_CHECK(ndr_pull_uint32(ndr, &_array_size));\n";
300 if ($size =~ /r->in/) {
301 pidl "\t\tif (!(ndr->flags & LIBNDR_FLAG_REF_ALLOC) && _array_size != $size) {\n";
303 pidl "\t\tif ($size != _array_size) {\n";
305 pidl "\t\t\treturn ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE, \"Bad array size %u should be %u\", _array_size, $size);\n";
307 if ($size =~ /r->in/) {
308 pidl "else { $size = _array_size; }\n";
313 if ((util::need_alloc($e) && !util::is_fixed_array($e)) ||
314 ($var_prefix eq "r->in." && util::has_property($e, "ref"))) {
315 if (!util::is_inline_array($e) || $ndr_flags eq "NDR_SCALARS") {
316 pidl "\t\tNDR_ALLOC_N(ndr, $var_prefix$e->{NAME}, MAX(1, $alloc_size));\n";
320 if (($var_prefix eq "r->out." && util::has_property($e, "ref"))) {
321 if (!util::is_inline_array($e) || $ndr_flags eq "NDR_SCALARS") {
322 pidl "\tif (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {";
323 pidl "\t\tNDR_ALLOC_N(ndr, $var_prefix$e->{NAME}, MAX(1, $alloc_size));\n";
330 if (my $length = util::has_property($e, "length_is")) {
331 $length = find_size_var($e, $length, $var_prefix);
332 pidl "\t\tuint32_t _offset, _length;\n";
333 pidl "\t\tNDR_CHECK(ndr_pull_uint32(ndr, &_offset));\n";
334 pidl "\t\tNDR_CHECK(ndr_pull_uint32(ndr, &_length));\n";
335 pidl "\t\tif (_offset != 0) return ndr_pull_error(ndr, NDR_ERR_OFFSET, \"Bad array offset 0x%08x\", _offset);\n";
336 pidl "\t\tif (_length > $size || _length != $length) return ndr_pull_error(ndr, NDR_ERR_LENGTH, \"Bad array length 0x%08x > size 0x%08x\", _offset, $size);\n\n";
340 if (util::is_scalar_type($e->{TYPE})) {
341 pidl "\t\tNDR_CHECK(ndr_pull_array_$e->{TYPE}(ndr, $ndr_flags, $var_prefix$e->{NAME}, $size));\n";
343 pidl "\t\tNDR_CHECK(ndr_pull_array(ndr, $ndr_flags, (void **)$var_prefix$e->{NAME}, sizeof($var_prefix$e->{NAME}\[0]), $size, (ndr_pull_flags_fn_t)ndr_pull_$e->{TYPE}));\n";
350 #####################################################################
351 # parse scalars in a structure element
352 sub ParseElementPushScalar($$$)
355 my($var_prefix) = shift;
356 my($ndr_flags) = shift;
357 my $cprefix = util::c_push_prefix($e);
358 my $sub_size = util::has_property($e, "subcontext");
362 if (my $value = util::has_property($e, "value")) {
363 pidl "\t$cprefix$var_prefix$e->{NAME} = $value;\n";
366 if (util::has_property($e, "relative")) {
367 pidl "\tNDR_CHECK(ndr_push_relative1(ndr, $var_prefix$e->{NAME}));\n";
368 } elsif (util::is_inline_array($e)) {
369 ParseArrayPush($e, "r->", "NDR_SCALARS");
370 } elsif (util::need_wire_pointer($e)) {
371 pidl "\tNDR_CHECK(ndr_push_ptr(ndr, $var_prefix$e->{NAME}));\n";
372 } elsif (util::need_alloc($e)) {
373 # no scalar component
374 } elsif (my $switch = util::has_property($e, "switch_is")) {
375 ParseElementPushSwitch($e, $var_prefix, $ndr_flags, $switch);
376 } elsif (defined $sub_size) {
377 if (util::is_builtin_type($e->{TYPE})) {
378 pidl "\tNDR_CHECK(ndr_push_subcontext_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_push_fn_t) ndr_push_$e->{TYPE}));\n";
380 pidl "\tNDR_CHECK(ndr_push_subcontext_flags_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_push_flags_fn_t) ndr_push_$e->{TYPE}));\n";
382 } elsif (util::is_builtin_type($e->{TYPE})) {
383 pidl "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $cprefix$var_prefix$e->{NAME}));\n";
385 pidl "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $ndr_flags, $cprefix$var_prefix$e->{NAME}));\n";
391 #####################################################################
392 # print scalars in a structure element
393 sub ParseElementPrintScalar($$)
396 my($var_prefix) = shift;
397 my $cprefix = util::c_push_prefix($e);
399 if (util::has_property($e, "noprint")) {
403 if (my $value = util::has_property($e, "value")) {
404 pidl "\tif (ndr->flags & LIBNDR_PRINT_SET_VALUES) {\n";
405 pidl "\t\t$cprefix$var_prefix$e->{NAME} = $value;\n";
409 if (util::is_fixed_array($e)) {
410 ParseElementPrintBuffer($e, $var_prefix);
411 } elsif (util::has_direct_buffers($e)) {
412 pidl "\tndr_print_ptr(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME});\n";
413 pidl "\tndr->depth++;\n";
414 ParseElementPrintBuffer($e, $var_prefix);
415 pidl "\tndr->depth--;\n";
416 } elsif (my $switch = util::has_property($e, "switch_is")) {
417 ParseElementPrintSwitch($e, $var_prefix, $switch);
419 pidl "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $cprefix$var_prefix$e->{NAME});\n";
423 #####################################################################
424 # parse scalars in a structure element - pull size
425 sub ParseElementPullSwitch($$$$)
428 my($var_prefix) = shift;
429 my($ndr_flags) = shift;
431 my $switch_var = find_size_var($e, $switch, $var_prefix);
433 my $cprefix = util::c_pull_prefix($e);
435 my $utype = $structs{$e->{TYPE}};
436 if (!defined $utype ||
437 !util::has_property($utype->{DATA}, "nodiscriminant")) {
438 my $e2 = find_sibling($e, $switch);
439 pidl "\tif (($ndr_flags) & NDR_SCALARS) {\n";
440 pidl "\t\t $e2->{TYPE} _level;\n";
441 pidl "\t\tNDR_CHECK(ndr_pull_$e2->{TYPE}(ndr, &_level));\n";
442 if ($switch_var =~ /r->in/) {
443 pidl "\t\tif (!(ndr->flags & LIBNDR_FLAG_REF_ALLOC) && _level != $switch_var) {\n";
445 pidl "\t\tif (_level != $switch_var) {\n";
447 pidl "\t\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value %u in $e->{NAME}\", _level);\n";
449 if ($switch_var =~ /r->/) {
450 pidl "else { $switch_var = _level; }\n";
455 my $sub_size = util::has_property($e, "subcontext");
456 if (defined $sub_size) {
457 pidl "\tNDR_CHECK(ndr_pull_subcontext_union_fn(ndr, $sub_size, $switch_var, $cprefix$var_prefix$e->{NAME}, (ndr_pull_union_fn_t) ndr_pull_$e->{TYPE}));\n";
459 pidl "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $ndr_flags, $switch_var, $cprefix$var_prefix$e->{NAME}));\n";
465 #####################################################################
466 # push switch element
467 sub ParseElementPushSwitch($$$$)
470 my($var_prefix) = shift;
471 my($ndr_flags) = shift;
473 my $switch_var = find_size_var($e, $switch, $var_prefix);
474 my $cprefix = util::c_push_prefix($e);
476 my $utype = $structs{$e->{TYPE}};
477 if (!defined $utype ||
478 !util::has_property($utype->{DATA}, "nodiscriminant")) {
479 my $e2 = find_sibling($e, $switch);
480 pidl "\tif (($ndr_flags) & NDR_SCALARS) {\n";
481 pidl "\t\tNDR_CHECK(ndr_push_$e2->{TYPE}(ndr, $switch_var));\n";
485 my $sub_size = util::has_property($e, "subcontext");
486 if (defined $sub_size) {
487 pidl "\tNDR_CHECK(ndr_push_subcontext_union_fn(ndr, $sub_size, $switch_var, $cprefix$var_prefix$e->{NAME}, (ndr_push_union_fn_t) ndr_push_$e->{TYPE}));\n";
489 pidl "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $ndr_flags, $switch_var, $cprefix$var_prefix$e->{NAME}));\n";
493 #####################################################################
494 # print scalars in a structure element
495 sub ParseElementPrintSwitch($$$)
498 my($var_prefix) = shift;
500 my $switch_var = find_size_var($e, $switch, $var_prefix);
501 my $cprefix = util::c_push_prefix($e);
503 pidl "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $switch_var, $cprefix$var_prefix$e->{NAME});\n";
507 #####################################################################
508 # parse scalars in a structure element - pull size
509 sub ParseElementPullScalar($$$)
512 my($var_prefix) = shift;
513 my($ndr_flags) = shift;
514 my $cprefix = util::c_pull_prefix($e);
515 my $sub_size = util::has_property($e, "subcontext");
519 if (util::is_inline_array($e)) {
520 ParseArrayPull($e, "r->", "NDR_SCALARS");
521 } elsif (util::need_wire_pointer($e)) {
522 pidl "\tNDR_CHECK(ndr_pull_ptr(ndr, &_ptr_$e->{NAME}));\n";
523 pidl "\tif (_ptr_$e->{NAME}) {\n";
524 pidl "\t\tNDR_ALLOC(ndr, $var_prefix$e->{NAME});\n";
525 if (util::has_property($e, "relative")) {
526 pidl "\t\tNDR_CHECK(ndr_pull_relative1(ndr, $var_prefix$e->{NAME}, _ptr_$e->{NAME}));";
529 pidl "\t\t$var_prefix$e->{NAME} = NULL;\n";
531 } elsif (util::need_alloc($e)) {
532 # no scalar component
533 } elsif (my $switch = util::has_property($e, "switch_is")) {
534 ParseElementPullSwitch($e, $var_prefix, $ndr_flags, $switch);
535 } elsif (defined $sub_size) {
536 if (util::is_builtin_type($e->{TYPE})) {
537 pidl "\tNDR_CHECK(ndr_pull_subcontext_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_pull_fn_t) ndr_pull_$e->{TYPE}));\n";
539 pidl "\tNDR_CHECK(ndr_pull_subcontext_flags_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_pull_flags_fn_t) ndr_pull_$e->{TYPE}));\n";
541 } elsif (util::is_builtin_type($e->{TYPE})) {
542 pidl "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $cprefix$var_prefix$e->{NAME}));\n";
544 pidl "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $ndr_flags, $cprefix$var_prefix$e->{NAME}));\n";
550 #####################################################################
551 # parse buffers in a structure element
552 sub ParseElementPushBuffer($$$)
555 my($var_prefix) = shift;
556 my($ndr_flags) = shift;
557 my $cprefix = util::c_push_prefix($e);
558 my $sub_size = util::has_property($e, "subcontext");
560 if (util::is_pure_scalar($e)) {
566 if (util::need_wire_pointer($e)) {
567 pidl "\tif ($var_prefix$e->{NAME}) {\n";
568 if (util::has_property($e, "relative")) {
569 pidl "\t\tNDR_CHECK(ndr_push_relative2(ndr, $var_prefix$e->{NAME}));\n";
573 if (util::is_inline_array($e)) {
574 ParseArrayPush($e, "r->", "NDR_BUFFERS");
575 } elsif (util::array_size($e)) {
576 ParseArrayPush($e, "r->", "NDR_SCALARS|NDR_BUFFERS");
577 } elsif (my $switch = util::has_property($e, "switch_is")) {
578 if ($e->{POINTERS}) {
579 ParseElementPushSwitch($e, $var_prefix, "NDR_BUFFERS|NDR_SCALARS", $switch);
581 ParseElementPushSwitch($e, $var_prefix, "NDR_BUFFERS", $switch);
583 } elsif (defined $sub_size) {
584 if ($e->{POINTERS}) {
585 if (util::is_builtin_type($e->{TYPE})) {
586 pidl "\tNDR_CHECK(ndr_push_subcontext_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_push_fn_t) ndr_push_$e->{TYPE}));\n";
588 pidl "\tNDR_CHECK(ndr_push_subcontext_flags_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_push_flags_fn_t) ndr_push_$e->{TYPE}));\n";
591 } elsif (util::is_builtin_type($e->{TYPE})) {
592 pidl "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $cprefix$var_prefix$e->{NAME}));\n";
593 } elsif ($e->{POINTERS}) {
594 pidl "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, NDR_SCALARS|NDR_BUFFERS, $cprefix$var_prefix$e->{NAME}));\n";
596 pidl "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $ndr_flags, $cprefix$var_prefix$e->{NAME}));\n";
599 if (util::need_wire_pointer($e)) {
606 #####################################################################
607 # print buffers in a structure element
608 sub ParseElementPrintBuffer($$)
611 my($var_prefix) = shift;
612 my $cprefix = util::c_push_prefix($e);
614 if (util::need_wire_pointer($e)) {
615 pidl "\tif ($var_prefix$e->{NAME}) {\n";
618 if (util::array_size($e)) {
619 ParseArrayPrint($e, $var_prefix)
620 } elsif (my $switch = util::has_property($e, "switch_is")) {
621 ParseElementPrintSwitch($e, $var_prefix, $switch);
623 pidl "\t\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $cprefix$var_prefix$e->{NAME});\n";
626 if (util::need_wire_pointer($e)) {
632 #####################################################################
633 # parse buffers in a structure element - pull side
634 sub ParseElementPullBuffer($$$)
637 my($var_prefix) = shift;
638 my($ndr_flags) = shift;
639 my $cprefix = util::c_pull_prefix($e);
640 my $sub_size = util::has_property($e, "subcontext");
642 if (util::is_pure_scalar($e)) {
648 if (util::need_wire_pointer($e)) {
649 pidl "\tif ($var_prefix$e->{NAME}) {\n";
650 if (util::has_property($e, "relative")) {
651 pidl "\t\tstruct ndr_pull_save _relative_save;\n";
652 pidl "\t\tndr_pull_save(ndr, &_relative_save);\n";
653 pidl "\t\tNDR_CHECK(ndr_pull_relative2(ndr, $var_prefix$e->{NAME}));\n";
657 if (util::is_inline_array($e)) {
658 ParseArrayPull($e, "r->", "NDR_BUFFERS");
659 } elsif (util::array_size($e)) {
660 ParseArrayPull($e, "r->", "NDR_SCALARS|NDR_BUFFERS");
661 } elsif (my $switch = util::has_property($e, "switch_is")) {
662 if ($e->{POINTERS}) {
663 ParseElementPullSwitch($e, $var_prefix, "NDR_SCALARS|NDR_BUFFERS", $switch);
665 ParseElementPullSwitch($e, $var_prefix, "NDR_BUFFERS", $switch);
667 } elsif (defined $sub_size) {
668 if ($e->{POINTERS}) {
669 if (util::is_builtin_type($e->{TYPE})) {
670 pidl "\tNDR_CHECK(ndr_pull_subcontext_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_pull_fn_t) ndr_pull_$e->{TYPE}));\n";
672 pidl "\tNDR_CHECK(ndr_pull_subcontext_flags_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_pull_flags_fn_t) ndr_pull_$e->{TYPE}));\n";
675 } elsif (util::is_builtin_type($e->{TYPE})) {
676 pidl "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $cprefix$var_prefix$e->{NAME}));\n";
677 } elsif ($e->{POINTERS}) {
678 pidl "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, NDR_SCALARS|NDR_BUFFERS, $cprefix$var_prefix$e->{NAME}));\n";
680 pidl "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $ndr_flags, $cprefix$var_prefix$e->{NAME}));\n";
683 if (util::need_wire_pointer($e)) {
684 if (util::has_property($e, "relative")) {
685 pidl "\t\tndr_pull_restore(ndr, &_relative_save);\n";
693 #####################################################################
695 sub ParseStructPush($)
700 if (! defined $struct->{ELEMENTS}) {
704 start_flags($struct);
706 # see if the structure contains a conformant array. If it
707 # does, then it must be the last element of the structure, and
708 # we need to push the conformant length early, as it fits on
709 # the wire before the structure (and even before the structure
711 my $e = $struct->{ELEMENTS}[-1];
712 if (defined $e->{ARRAY_LEN} && $e->{ARRAY_LEN} eq "*") {
713 my $size = find_size_var($e, util::array_size($e), "r->");
714 $e->{CONFORMANT_SIZE} = $size;
716 pidl "\tNDR_CHECK(ndr_push_uint32(ndr, $size));\n";
719 pidl "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
721 pidl "\tNDR_CHECK(ndr_push_struct_start(ndr));\n";
723 my $align = struct_alignment($struct);
724 pidl "\tNDR_CHECK(ndr_push_align(ndr, $align));\n";
726 foreach my $e (@{$struct->{ELEMENTS}}) {
727 ParseElementPushScalar($e, "r->", "NDR_SCALARS");
731 pidl "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n";
732 foreach my $e (@{$struct->{ELEMENTS}}) {
733 ParseElementPushBuffer($e, "r->", "NDR_BUFFERS");
736 pidl "\tndr_push_struct_end(ndr);\n";
743 #####################################################################
744 # generate a struct print function
745 sub ParseStructPrint($)
749 if (! defined $struct->{ELEMENTS}) {
753 start_flags($struct);
755 pidl "\tndr->depth++;\n";
756 foreach my $e (@{$struct->{ELEMENTS}}) {
757 ParseElementPrintScalar($e, "r->");
759 pidl "\tndr->depth--;\n";
764 #####################################################################
765 # parse a struct - pull side
766 sub ParseStructPull($)
771 if (! defined $struct->{ELEMENTS}) {
775 # see if the structure contains a conformant array. If it
776 # does, then it must be the last element of the structure, and
777 # we need to pull the conformant length early, as it fits on
778 # the wire before the structure (and even before the structure
780 my $e = $struct->{ELEMENTS}[-1];
781 if (defined $e->{ARRAY_LEN} && $e->{ARRAY_LEN} eq "*") {
783 pidl "\tuint32_t _conformant_size;\n";
784 $conform_e->{CONFORMANT_SIZE} = "_conformant_size";
787 # declare any internal pointers we need
788 foreach my $e (@{$struct->{ELEMENTS}}) {
789 if (util::need_wire_pointer($e)) {
790 pidl "\tuint32_t _ptr_$e->{NAME};\n";
794 start_flags($struct);
796 pidl "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
798 pidl "\tNDR_CHECK(ndr_pull_struct_start(ndr));\n";
800 if (defined $conform_e) {
801 pidl "\tNDR_CHECK(ndr_pull_uint32(ndr, &$conform_e->{CONFORMANT_SIZE}));\n";
804 my $align = struct_alignment($struct);
805 pidl "\tNDR_CHECK(ndr_pull_align(ndr, $align));\n";
807 foreach my $e (@{$struct->{ELEMENTS}}) {
808 ParseElementPullScalar($e, "r->", "NDR_SCALARS");
812 pidl "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n";
813 foreach my $e (@{$struct->{ELEMENTS}}) {
814 ParseElementPullBuffer($e, "r->", "NDR_BUFFERS");
817 pidl "\tndr_pull_struct_end(ndr);\n";
825 #####################################################################
826 # parse a union - push side
827 sub ParseUnionPush($)
830 my $have_default = 0;
834 pidl "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
836 pidl "\tNDR_CHECK(ndr_push_struct_start(ndr));\n";
838 # my $align = union_alignment($e);
839 # pidl "\tNDR_CHECK(ndr_push_align(ndr, $align));\n";
841 pidl "\tswitch (level) {\n";
842 foreach my $el (@{$e->{DATA}}) {
843 if ($el->{CASE} eq "default") {
847 pidl "\tcase $el->{CASE}:\n";
849 if ($el->{TYPE} eq "UNION_ELEMENT") {
850 ParseElementPushScalar($el->{DATA}, "r->", "NDR_SCALARS");
854 if (! $have_default) {
856 pidl "\t\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n";
860 pidl "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n";
861 pidl "\tswitch (level) {\n";
862 foreach my $el (@{$e->{DATA}}) {
863 if ($el->{CASE} eq "default") {
866 pidl "\tcase $el->{CASE}:\n";
868 if ($el->{TYPE} eq "UNION_ELEMENT") {
869 ParseElementPushBuffer($el->{DATA}, "r->", "NDR_BUFFERS");
873 if (! $have_default) {
875 pidl "\t\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n";
878 pidl "\tndr_push_struct_end(ndr);\n";
883 #####################################################################
885 sub ParseUnionPrint($)
888 my $have_default = 0;
892 pidl "\tswitch (level) {\n";
893 foreach my $el (@{$e->{DATA}}) {
894 if ($el->{CASE} eq "default") {
898 pidl "\tcase $el->{CASE}:\n";
900 if ($el->{TYPE} eq "UNION_ELEMENT") {
901 ParseElementPrintScalar($el->{DATA}, "r->");
905 if (! $have_default) {
906 pidl "\tdefault:\n\t\tndr_print_bad_level(ndr, name, level);\n";
913 #####################################################################
914 # parse a union - pull side
915 sub ParseUnionPull($)
918 my $have_default = 0;
922 pidl "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
924 pidl "\tNDR_CHECK(ndr_pull_struct_start(ndr));\n";
926 # my $align = union_alignment($e);
927 # pidl "\tNDR_CHECK(ndr_pull_align(ndr, $align));\n";
929 pidl "\tswitch (level) {\n";
930 foreach my $el (@{$e->{DATA}}) {
931 if ($el->{CASE} eq "default") {
932 pidl "\tdefault: {\n";
935 pidl "\tcase $el->{CASE}: {\n";
937 if ($el->{TYPE} eq "UNION_ELEMENT") {
938 my $e2 = $el->{DATA};
939 if ($e2->{POINTERS}) {
940 pidl "\t\tuint32_t _ptr_$e2->{NAME};\n";
942 ParseElementPullScalar($el->{DATA}, "r->", "NDR_SCALARS");
944 pidl "\tbreak; }\n\n";
946 if (! $have_default) {
948 pidl "\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n";
952 pidl "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n";
953 pidl "\tswitch (level) {\n";
954 foreach my $el (@{$e->{DATA}}) {
955 if ($el->{CASE} eq "default") {
958 pidl "\tcase $el->{CASE}:\n";
960 if ($el->{TYPE} eq "UNION_ELEMENT") {
961 ParseElementPullBuffer($el->{DATA}, "r->", "NDR_BUFFERS");
965 if (! $have_default) {
967 pidl "\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n";
970 pidl "\tndr_pull_struct_end(ndr);\n";
975 #####################################################################
981 if (ref($data) eq "HASH") {
982 ($data->{TYPE} eq "STRUCT") &&
983 ParseStructPush($data);
984 ($data->{TYPE} eq "UNION") &&
985 ParseUnionPush($data);
989 #####################################################################
990 # generate a print function for a type
991 sub ParseTypePrint($)
995 if (ref($data) eq "HASH") {
996 ($data->{TYPE} eq "STRUCT") &&
997 ParseStructPrint($data);
998 ($data->{TYPE} eq "UNION") &&
999 ParseUnionPrint($data);
1003 #####################################################################
1005 sub ParseTypePull($)
1009 if (ref($data) eq "HASH") {
1010 ($data->{TYPE} eq "STRUCT") &&
1011 ParseStructPull($data);
1012 ($data->{TYPE} eq "UNION") &&
1013 ParseUnionPull($data);
1017 #####################################################################
1018 # parse a typedef - push side
1019 sub ParseTypedefPush($)
1022 my $static = fn_prefix($e);
1024 if (! $needed{"push_$e->{NAME}"}) {
1025 # print "push_$e->{NAME} not needed\n";
1029 if ($e->{DATA}->{TYPE} eq "STRUCT") {
1030 pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, struct $e->{NAME} *r)";
1032 ParseTypePush($e->{DATA});
1033 pidl "\treturn NT_STATUS_OK;\n";
1037 if ($e->{DATA}->{TYPE} eq "UNION") {
1038 pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, uint16_t level, union $e->{NAME} *r)";
1040 ParseTypePush($e->{DATA});
1041 pidl "\treturn NT_STATUS_OK;\n";
1047 #####################################################################
1048 # parse a typedef - pull side
1049 sub ParseTypedefPull($)
1052 my $static = fn_prefix($e);
1054 if (! $needed{"pull_$e->{NAME}"}) {
1055 # print "pull_$e->{NAME} not needed\n";
1059 if ($e->{DATA}->{TYPE} eq "STRUCT") {
1060 pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, struct $e->{NAME} *r)";
1062 ParseTypePull($e->{DATA});
1063 pidl "\treturn NT_STATUS_OK;\n";
1067 if ($e->{DATA}->{TYPE} eq "UNION") {
1068 pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, uint16_t level, union $e->{NAME} *r)";
1070 ParseTypePull($e->{DATA});
1071 pidl "\treturn NT_STATUS_OK;\n";
1077 #####################################################################
1078 # parse a typedef - print side
1079 sub ParseTypedefPrint($)
1083 if ($e->{DATA}->{TYPE} eq "STRUCT") {
1084 pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, struct $e->{NAME} *r)";
1086 pidl "\tndr_print_struct(ndr, name, \"$e->{NAME}\");\n";
1087 ParseTypePrint($e->{DATA});
1091 if ($e->{DATA}->{TYPE} eq "UNION") {
1092 pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, uint16_t level, union $e->{NAME} *r)";
1094 pidl "\tndr_print_union(ndr, name, level, \"$e->{NAME}\");\n";
1095 ParseTypePrint($e->{DATA});
1100 #####################################################################
1101 # parse a function - print side
1102 sub ParseFunctionPrint($)
1106 pidl "void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, struct $fn->{NAME} *r)";
1108 pidl "\tndr_print_struct(ndr, name, \"$fn->{NAME}\");\n";
1109 pidl "\tndr->depth++;\n";
1111 pidl "\tif (flags & NDR_SET_VALUES) {\n";
1112 pidl "\t\tndr->flags |= LIBNDR_PRINT_SET_VALUES;\n";
1115 pidl "\tif (flags & NDR_IN) {\n";
1116 pidl "\t\tndr_print_struct(ndr, \"in\", \"$fn->{NAME}\");\n";
1117 pidl "\tndr->depth++;\n";
1118 foreach my $e (@{$fn->{DATA}}) {
1119 if (util::has_property($e, "in")) {
1120 ParseElementPrintScalar($e, "r->in.");
1123 pidl "\tndr->depth--;\n";
1126 pidl "\tif (flags & NDR_OUT) {\n";
1127 pidl "\t\tndr_print_struct(ndr, \"out\", \"$fn->{NAME}\");\n";
1128 pidl "\tndr->depth++;\n";
1129 foreach my $e (@{$fn->{DATA}}) {
1130 if (util::has_property($e, "out")) {
1131 ParseElementPrintScalar($e, "r->out.");
1134 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
1135 if (util::is_scalar_type($fn->{RETURN_TYPE})) {
1136 pidl "\tndr_print_$fn->{RETURN_TYPE}(ndr, \"result\", r->out.result);\n";
1138 pidl "\tndr_print_$fn->{RETURN_TYPE}(ndr, \"result\", &r->out.result);\n";
1141 pidl "\tndr->depth--;\n";
1144 pidl "\tndr->depth--;\n";
1149 #####################################################################
1150 # parse a function element
1151 sub ParseFunctionElementPush($$)
1156 if (util::array_size($e)) {
1157 if (util::need_wire_pointer($e)) {
1158 pidl "\tNDR_CHECK(ndr_push_ptr(ndr, r->$inout.$e->{NAME}));\n";
1159 pidl "\tif (r->$inout.$e->{NAME}) {\n";
1160 ParseArrayPush($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1163 ParseArrayPush($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1166 ParseElementPushScalar($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1167 if ($e->{POINTERS}) {
1168 ParseElementPushBuffer($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1173 #####################################################################
1175 sub ParseFunctionPush($)
1178 my $static = fn_prefix($fn);
1180 pidl $static . "NTSTATUS ndr_push_$fn->{NAME}(struct ndr_push *ndr, int flags, struct $fn->{NAME} *r)\n{\n";
1182 pidl "\n\tif (!(flags & NDR_IN)) goto ndr_out;\n\n";
1183 foreach my $e (@{$fn->{DATA}}) {
1184 if (util::has_property($e, "in")) {
1185 ParseFunctionElementPush($e, "in");
1189 pidl "\nndr_out:\n";
1190 pidl "\tif (!(flags & NDR_OUT)) goto done;\n\n";
1191 foreach my $e (@{$fn->{DATA}}) {
1192 if (util::has_property($e, "out")) {
1193 ParseFunctionElementPush($e, "out");
1197 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
1198 pidl "\tNDR_CHECK(ndr_push_$fn->{RETURN_TYPE}(ndr, r->out.result));\n";
1202 pidl "\n\treturn NT_STATUS_OK;\n}\n\n";
1205 #####################################################################
1206 # parse a function element
1207 sub ParseFunctionElementPull($$)
1212 if (util::array_size($e)) {
1213 if (util::need_wire_pointer($e)) {
1214 pidl "\tNDR_CHECK(ndr_pull_ptr(ndr, &_ptr_$e->{NAME}));\n";
1215 pidl "\tif (_ptr_$e->{NAME}) {\n";
1216 } elsif ($inout eq "out" && util::has_property($e, "ref")) {
1217 pidl "\tif (r->$inout.$e->{NAME}) {\n";
1221 ParseArrayPull($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1224 if ($inout eq "out" && util::has_property($e, "ref")) {
1225 pidl "\tif (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {\n";
1226 pidl "\tNDR_ALLOC(ndr, r->out.$e->{NAME});\n";
1229 if ($inout eq "in" && util::has_property($e, "ref")) {
1230 pidl "\tNDR_ALLOC(ndr, r->in.$e->{NAME});\n";
1233 ParseElementPullScalar($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1234 if ($e->{POINTERS}) {
1235 ParseElementPullBuffer($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1241 ############################################################
1242 # allocate ref variables
1243 sub AllocateRefVars($)
1246 my $asize = util::array_size($e);
1248 # note that if the variable is also an "in"
1249 # variable then we copy the initial value from
1252 if (!defined $asize) {
1253 # its a simple variable
1254 pidl "\tNDR_ALLOC(ndr, r->out.$e->{NAME});\n";
1255 if (util::has_property($e, "in")) {
1256 pidl "\t*r->out.$e->{NAME} = *r->in.$e->{NAME};\n";
1258 pidl "\tZERO_STRUCTP(r->out.$e->{NAME});\n";
1264 my $size = find_size_var($e, $asize, "r->out.");
1265 pidl "\tNDR_ALLOC_N(ndr, r->out.$e->{NAME}, MAX(1, $size));\n";
1266 if (util::has_property($e, "in")) {
1267 pidl "\tmemcpy(r->out.$e->{NAME},r->in.$e->{NAME},$size * sizeof(*r->in.$e->{NAME}));\n";
1269 pidl "\tmemset(r->out.$e->{NAME}, 0, $size * sizeof(*r->out.$e->{NAME}));\n";
1274 #####################################################################
1276 sub ParseFunctionPull($)
1279 my $static = fn_prefix($fn);
1281 # pull function args
1282 pidl $static . "NTSTATUS ndr_pull_$fn->{NAME}(struct ndr_pull *ndr, int flags, struct $fn->{NAME} *r)\n{\n";
1284 # declare any internal pointers we need
1285 foreach my $e (@{$fn->{DATA}}) {
1286 if (util::need_wire_pointer($e)) {
1287 pidl "\tuint32_t _ptr_$e->{NAME};\n";
1291 pidl "\n\tif (!(flags & NDR_IN)) goto ndr_out;\n\n";
1293 # auto-init the out section of a structure. I originally argued that
1294 # this was a bad idea as it hides bugs, but coping correctly
1295 # with initialisation and not wiping ref vars is turning
1296 # out to be too tricky (tridge)
1297 foreach my $e (@{$fn->{DATA}}) {
1298 if (util::has_property($e, "out")) {
1299 pidl "\tZERO_STRUCT(r->out);\n\n";
1304 foreach my $e (@{$fn->{DATA}}) {
1305 if (util::has_property($e, "in")) {
1306 ParseFunctionElementPull($e, "in");
1308 # we need to allocate any reference output variables, so that
1309 # a dcerpc backend can be sure they are non-null
1310 if (util::has_property($e, "out") && util::has_property($e, "ref")) {
1311 AllocateRefVars($e);
1315 pidl "\nndr_out:\n";
1316 pidl "\tif (!(flags & NDR_OUT)) goto done;\n\n";
1317 foreach my $e (@{$fn->{DATA}}) {
1318 if (util::has_property($e, "out")) {
1319 ParseFunctionElementPull($e, "out");
1323 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
1324 pidl "\tNDR_CHECK(ndr_pull_$fn->{RETURN_TYPE}(ndr, &r->out.result));\n";
1328 pidl "\n\treturn NT_STATUS_OK;\n}\n\n";
1331 #####################################################################
1332 # produce a function call table
1333 sub FunctionTable($)
1335 my($interface) = shift;
1336 my($data) = $interface->{INHERITED_DATA};
1338 my $uname = uc $interface->{NAME};
1340 foreach my $d (@{$data}) {
1341 if ($d->{TYPE} eq "FUNCTION") { $count++; }
1348 pidl "static const struct dcerpc_interface_call $interface->{NAME}\_calls[] = {\n";
1349 foreach my $d (@{$data}) {
1350 if ($d->{TYPE} eq "FUNCTION") {
1352 pidl "\t\t\"$d->{NAME}\",\n";
1353 pidl "\t\tsizeof(struct $d->{NAME}),\n";
1354 pidl "\t\t(ndr_push_flags_fn_t) ndr_push_$d->{NAME},\n";
1355 pidl "\t\t(ndr_pull_flags_fn_t) ndr_pull_$d->{NAME},\n";
1356 pidl "\t\t(ndr_print_function_t) ndr_print_$d->{NAME}\n";
1360 pidl "\t{ NULL, 0, NULL, NULL }\n};\n\n";
1364 if (! defined $interface->{PROPERTIES}->{endpoints}) {
1365 $interface->{PROPERTIES}->{endpoints} = $interface->{NAME};
1368 my @e = split / /, $interface->{PROPERTIES}->{endpoints};
1369 my $endpoint_count = $#e + 1;
1371 pidl "static const char * const $interface->{NAME}\_endpoint_strings[] = {\n\t";
1372 for (my $i=0; $i < $#e; $i++) {
1373 pidl "\"$e[$i]\", ";
1375 pidl "\"$e[$#e]\"\n";
1378 pidl "static const struct dcerpc_endpoint_list $interface->{NAME}\_endpoints = {\n";
1379 pidl "\t$endpoint_count, $interface->{NAME}\_endpoint_strings\n";
1382 pidl "\nconst struct dcerpc_interface_table dcerpc_table_$interface->{NAME} = {\n";
1383 pidl "\t\"$interface->{NAME}\",\n";
1384 pidl "\tDCERPC_$uname\_UUID,\n";
1385 pidl "\tDCERPC_$uname\_VERSION,\n";
1386 pidl "\tDCERPC_$uname\_HELPSTRING,\n";
1388 pidl "\t$interface->{NAME}\_calls,\n";
1389 pidl "\t&$interface->{NAME}\_endpoints\n";
1394 #####################################################################
1395 # parse the interface definitions
1396 sub ParseInterface($)
1398 my($interface) = shift;
1399 my($data) = $interface->{DATA};
1401 foreach my $d (@{$data}) {
1402 if ($d->{TYPE} eq "TYPEDEF") {
1403 $structs{$d->{NAME}} = $d;
1409 foreach my $d (@{$data}) {
1410 ($d->{TYPE} eq "TYPEDEF") &&
1411 ParseTypedefPush($d);
1412 ($d->{TYPE} eq "FUNCTION") &&
1413 ParseFunctionPush($d);
1415 foreach my $d (@{$data}) {
1416 ($d->{TYPE} eq "TYPEDEF") &&
1417 ParseTypedefPull($d);
1418 ($d->{TYPE} eq "FUNCTION") &&
1419 ParseFunctionPull($d);
1421 foreach my $d (@{$data}) {
1422 if ($d->{TYPE} eq "TYPEDEF" &&
1423 !util::has_property($d->{DATA}, "noprint")) {
1424 ParseTypedefPrint($d);
1426 if ($d->{TYPE} eq "FUNCTION" &&
1427 !util::has_property($d, "noprint")) {
1428 ParseFunctionPrint($d);
1432 FunctionTable($interface);
1436 sub NeededFunction($)
1439 $needed{"pull_$fn->{NAME}"} = 1;
1440 $needed{"push_$fn->{NAME}"} = 1;
1441 foreach my $e (@{$fn->{DATA}}) {
1443 $needed{"pull_$e->{TYPE}"} = 1;
1444 $needed{"push_$e->{TYPE}"} = 1;
1448 sub NeededTypedef($)
1451 if (util::has_property($t->{DATA}, "public")) {
1452 $needed{"pull_$t->{NAME}"} = 1;
1453 $needed{"push_$t->{NAME}"} = 1;
1455 if ($t->{DATA}->{TYPE} eq "STRUCT") {
1456 for my $e (@{$t->{DATA}->{ELEMENTS}}) {
1457 $e->{PARENT} = $t->{DATA};
1458 if ($needed{"pull_$t->{NAME}"}) {
1459 $needed{"pull_$e->{TYPE}"} = 1;
1461 if ($needed{"push_$t->{NAME}"}) {
1462 $needed{"push_$e->{TYPE}"} = 1;
1466 if ($t->{DATA}->{TYPE} eq "UNION") {
1467 for my $e (@{$t->{DATA}->{DATA}}) {
1468 $e->{PARENT} = $t->{DATA};
1469 if ($e->{TYPE} eq "UNION_ELEMENT") {
1470 if ($needed{"pull_$t->{NAME}"}) {
1471 $needed{"pull_$e->{DATA}->{TYPE}"} = 1;
1473 if ($needed{"push_$t->{NAME}"}) {
1474 $needed{"push_$e->{DATA}->{TYPE}"} = 1;
1481 #####################################################################
1482 # work out what parse functions are needed
1485 my($interface) = shift;
1486 my($data) = $interface->{DATA};
1487 foreach my $d (@{$data}) {
1488 ($d->{TYPE} eq "FUNCTION") &&
1491 foreach my $d (reverse @{$data}) {
1492 ($d->{TYPE} eq "TYPEDEF") &&
1497 #####################################################################
1498 # parse a parsed IDL structure back into an IDL file
1502 my($filename) = shift;
1504 open(OUT, ">$filename") || die "can't open $filename";
1506 pidl "/* parser auto-generated by pidl */\n\n";
1507 pidl "#include \"includes.h\"\n\n";
1508 foreach my $x (@{$idl}) {
1509 if ($x->{TYPE} eq "INTERFACE") {
1515 pidl IdlClient::Parse($idl);