1 ###################################################
2 # Samba4 parser generator for IDL structures
3 # Copyright tridge@samba.org 2000-2003
4 # Copyright tpot@samba.org 2001
5 # Copyright jelmer@samba.org 2004
6 # released under the GNU GPL
13 # 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_set_flags(&ndr->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 # check the size_is and length_is constraints
273 sub CheckArraySizes($$)
276 my $var_prefix = shift;
278 if (util::has_property($e, "size_is")) {
279 my $size = find_size_var($e, util::array_size($e), $var_prefix);
280 pidl "\tNDR_CHECK(ndr_check_array_size(ndr, (void*)&$var_prefix$e->{NAME}, $size));\n";
283 if (my $length = util::has_property($e, "length_is")) {
284 $length = find_size_var($e, $length, $var_prefix);
285 pidl "\tNDR_CHECK(ndr_check_array_length(ndr, (void*)&$var_prefix$e->{NAME}, $length));\n";
290 #####################################################################
291 # parse an array - pull side
292 sub ParseArrayPull($$$)
295 my $var_prefix = shift;
296 my $ndr_flags = shift;
298 my $size = find_size_var($e, util::array_size($e), $var_prefix);
299 my $alloc_size = $size;
301 # if this is a conformant array then we use that size to allocate, and make sure
302 # we allocate enough to pull the elements
303 if (defined $e->{CONFORMANT_SIZE}) {
304 $alloc_size = $e->{CONFORMANT_SIZE};
306 pidl "\tif ($size > $alloc_size) {\n";
307 pidl "\t\treturn ndr_pull_error(ndr, NDR_ERR_CONFORMANT_SIZE, \"Bad conformant size %u should be %u\", $alloc_size, $size);\n";
309 } elsif (!util::is_inline_array($e)) {
310 if ($var_prefix =~ /^r->out/ && $size =~ /^\*r->in/) {
311 my $size2 = substr($size, 1);
312 pidl "if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) { NDR_ALLOC(ndr, $size2); }\n";
315 # non fixed arrays encode the size just before the array
316 pidl "\t\tNDR_CHECK(ndr_pull_array_size(ndr, &$var_prefix$e->{NAME}));\n";
317 $alloc_size = "ndr_get_array_size(ndr, &$var_prefix$e->{NAME})";
320 if ((util::need_alloc($e) && !util::is_fixed_array($e)) ||
321 ($var_prefix eq "r->in." && util::has_property($e, "ref"))) {
322 if (!util::is_inline_array($e) || $ndr_flags eq "NDR_SCALARS") {
323 pidl "\t\tNDR_ALLOC_N(ndr, $var_prefix$e->{NAME}, $alloc_size);\n";
327 if (($var_prefix eq "r->out." && util::has_property($e, "ref"))) {
328 if (!util::is_inline_array($e) || $ndr_flags eq "NDR_SCALARS") {
329 pidl "\tif (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {";
330 pidl "\t\tNDR_ALLOC_N(ndr, $var_prefix$e->{NAME}, $alloc_size);\n";
335 if (my $length = util::has_property($e, "length_is")) {
336 pidl "\t\tNDR_CHECK(ndr_pull_array_length(ndr, &$var_prefix$e->{NAME}));\n";
337 $size = "ndr_get_array_length(ndr, &$var_prefix$e->{NAME})";
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";
348 #####################################################################
349 # parse scalars in a structure element
350 sub ParseElementPushScalar($$$)
353 my($var_prefix) = shift;
354 my($ndr_flags) = shift;
355 my $cprefix = util::c_push_prefix($e);
356 my $sub_size = util::has_property($e, "subcontext");
360 if (my $value = util::has_property($e, "value")) {
361 pidl "\t$cprefix$var_prefix$e->{NAME} = $value;\n";
364 if (util::has_property($e, "relative")) {
365 pidl "\tNDR_CHECK(ndr_push_relative1(ndr, $var_prefix$e->{NAME}));\n";
366 } elsif (util::is_inline_array($e)) {
367 ParseArrayPush($e, "r->", "NDR_SCALARS");
368 } elsif (util::need_wire_pointer($e)) {
369 pidl "\tNDR_CHECK(ndr_push_ptr(ndr, $var_prefix$e->{NAME}));\n";
370 } elsif (util::need_alloc($e)) {
371 # no scalar component
372 } elsif (my $switch = util::has_property($e, "switch_is")) {
373 ParseElementPushSwitch($e, $var_prefix, $ndr_flags, $switch);
374 } elsif (defined $sub_size) {
375 if (util::is_builtin_type($e->{TYPE})) {
376 pidl "\tNDR_CHECK(ndr_push_subcontext_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_push_fn_t) ndr_push_$e->{TYPE}));\n";
378 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";
380 } elsif (util::is_builtin_type($e->{TYPE})) {
381 pidl "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $cprefix$var_prefix$e->{NAME}));\n";
383 pidl "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $ndr_flags, $cprefix$var_prefix$e->{NAME}));\n";
389 #####################################################################
390 # print scalars in a structure element
391 sub ParseElementPrintScalar($$)
394 my($var_prefix) = shift;
395 my $cprefix = util::c_push_prefix($e);
397 if (util::has_property($e, "noprint")) {
401 if (my $value = util::has_property($e, "value")) {
402 pidl "\tif (ndr->flags & LIBNDR_PRINT_SET_VALUES) {\n";
403 pidl "\t\t$cprefix$var_prefix$e->{NAME} = $value;\n";
407 if (util::is_fixed_array($e)) {
408 ParseElementPrintBuffer($e, $var_prefix);
409 } elsif (util::has_direct_buffers($e)) {
410 pidl "\tndr_print_ptr(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME});\n";
411 pidl "\tndr->depth++;\n";
412 ParseElementPrintBuffer($e, $var_prefix);
413 pidl "\tndr->depth--;\n";
414 } elsif (my $switch = util::has_property($e, "switch_is")) {
415 ParseElementPrintSwitch($e, $var_prefix, $switch);
417 pidl "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $cprefix$var_prefix$e->{NAME});\n";
421 #####################################################################
422 # parse scalars in a structure element - pull size
423 sub ParseElementPullSwitch($$$$)
426 my($var_prefix) = shift;
427 my($ndr_flags) = shift;
429 my $switch_var = find_size_var($e, $switch, $var_prefix);
431 my $cprefix = util::c_pull_prefix($e);
433 my $utype = $structs{$e->{TYPE}};
434 if (!defined $utype ||
435 !util::has_property($utype->{DATA}, "nodiscriminant")) {
436 my $e2 = find_sibling($e, $switch);
437 pidl "\tif (($ndr_flags) & NDR_SCALARS) {\n";
438 pidl "\t\t $e2->{TYPE} _level;\n";
439 pidl "\t\tNDR_CHECK(ndr_pull_$e2->{TYPE}(ndr, &_level));\n";
440 if ($switch_var =~ /r->in/) {
441 pidl "\t\tif (!(ndr->flags & LIBNDR_FLAG_REF_ALLOC) && _level != $switch_var) {\n";
443 pidl "\t\tif (_level != $switch_var) {\n";
445 pidl "\t\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value %u in $e->{NAME}\", _level);\n";
447 if ($switch_var =~ /r->/) {
448 pidl "else { $switch_var = _level; }\n";
453 my $sub_size = util::has_property($e, "subcontext");
454 if (defined $sub_size) {
455 pidl "\tif (($ndr_flags) & NDR_SCALARS) {\n";
456 pidl "\t\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 "\tif(($ndr_flags) & NDR_SCALARS) {\n";
488 pidl "\t\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";
491 pidl "\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $ndr_flags, $switch_var, $cprefix$var_prefix$e->{NAME}));\n";
495 #####################################################################
496 # print scalars in a structure element
497 sub ParseElementPrintSwitch($$$)
500 my($var_prefix) = shift;
502 my $switch_var = find_size_var($e, $switch, $var_prefix);
503 my $cprefix = util::c_push_prefix($e);
505 pidl "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $switch_var, $cprefix$var_prefix$e->{NAME});\n";
509 #####################################################################
510 # parse scalars in a structure element - pull size
511 sub ParseElementPullScalar($$$)
514 my($var_prefix) = shift;
515 my($ndr_flags) = shift;
516 my $cprefix = util::c_pull_prefix($e);
517 my $sub_size = util::has_property($e, "subcontext");
521 if (util::is_inline_array($e)) {
522 ParseArrayPull($e, "r->", "NDR_SCALARS");
523 } elsif (util::need_wire_pointer($e)) {
524 pidl "\tNDR_CHECK(ndr_pull_ptr(ndr, &_ptr_$e->{NAME}));\n";
525 pidl "\tif (_ptr_$e->{NAME}) {\n";
526 pidl "\t\tNDR_ALLOC(ndr, $var_prefix$e->{NAME});\n";
527 if (util::has_property($e, "relative")) {
528 pidl "\t\tNDR_CHECK(ndr_pull_relative1(ndr, $var_prefix$e->{NAME}, _ptr_$e->{NAME}));";
531 pidl "\t\t$var_prefix$e->{NAME} = NULL;\n";
533 } elsif (util::need_alloc($e)) {
534 # no scalar component
535 } elsif (my $switch = util::has_property($e, "switch_is")) {
536 ParseElementPullSwitch($e, $var_prefix, $ndr_flags, $switch);
537 } elsif (defined $sub_size) {
538 if (util::is_builtin_type($e->{TYPE})) {
539 pidl "\tNDR_CHECK(ndr_pull_subcontext_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_pull_fn_t) ndr_pull_$e->{TYPE}));\n";
541 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";
543 } elsif (util::is_builtin_type($e->{TYPE})) {
544 pidl "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $cprefix$var_prefix$e->{NAME}));\n";
546 pidl "\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $ndr_flags, $cprefix$var_prefix$e->{NAME}));\n";
548 if (my $range = util::has_property($e, "range")) {
549 my ($low, $high) = split(/ /, $range, 2);
550 pidl "\tif ($var_prefix$e->{NAME} < $low || $var_prefix$e->{NAME} > $high) {\n";
551 pidl "\t\treturn ndr_pull_error(ndr, NDR_ERR_RANGE, \"value out of range\");\n\t}\n";
557 #####################################################################
558 # parse buffers in a structure element
559 sub ParseElementPushBuffer($$$)
562 my($var_prefix) = shift;
563 my($ndr_flags) = shift;
564 my $cprefix = util::c_push_prefix($e);
565 my $sub_size = util::has_property($e, "subcontext");
567 if (util::is_pure_scalar($e)) {
573 if (util::need_wire_pointer($e)) {
574 pidl "\tif ($var_prefix$e->{NAME}) {\n";
575 if (util::has_property($e, "relative")) {
576 pidl "\t\tNDR_CHECK(ndr_push_relative2(ndr, $var_prefix$e->{NAME}));\n";
580 if (util::is_inline_array($e)) {
581 ParseArrayPush($e, "r->", "NDR_BUFFERS");
582 } elsif (util::array_size($e)) {
583 ParseArrayPush($e, "r->", "NDR_SCALARS|NDR_BUFFERS");
584 } elsif (my $switch = util::has_property($e, "switch_is")) {
585 if ($e->{POINTERS}) {
586 ParseElementPushSwitch($e, $var_prefix, "NDR_BUFFERS|NDR_SCALARS", $switch);
588 ParseElementPushSwitch($e, $var_prefix, "NDR_BUFFERS", $switch);
590 } elsif (defined $sub_size) {
591 if ($e->{POINTERS}) {
592 if (util::is_builtin_type($e->{TYPE})) {
593 pidl "\tNDR_CHECK(ndr_push_subcontext_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_push_fn_t) ndr_push_$e->{TYPE}));\n";
595 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";
598 } elsif (util::is_builtin_type($e->{TYPE})) {
599 pidl "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $cprefix$var_prefix$e->{NAME}));\n";
600 } elsif ($e->{POINTERS}) {
601 pidl "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, NDR_SCALARS|NDR_BUFFERS, $cprefix$var_prefix$e->{NAME}));\n";
603 pidl "\t\tNDR_CHECK(ndr_push_$e->{TYPE}(ndr, $ndr_flags, $cprefix$var_prefix$e->{NAME}));\n";
606 if (util::need_wire_pointer($e)) {
613 #####################################################################
614 # print buffers in a structure element
615 sub ParseElementPrintBuffer($$)
618 my($var_prefix) = shift;
619 my $cprefix = util::c_push_prefix($e);
621 if (util::need_wire_pointer($e)) {
622 pidl "\tif ($var_prefix$e->{NAME}) {\n";
625 if (util::array_size($e)) {
626 ParseArrayPrint($e, $var_prefix)
627 } elsif (my $switch = util::has_property($e, "switch_is")) {
628 ParseElementPrintSwitch($e, $var_prefix, $switch);
630 pidl "\t\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $cprefix$var_prefix$e->{NAME});\n";
633 if (util::need_wire_pointer($e)) {
639 #####################################################################
640 # parse buffers in a structure element - pull side
641 sub ParseElementPullBuffer($$$)
644 my($var_prefix) = shift;
645 my($ndr_flags) = shift;
646 my $cprefix = util::c_pull_prefix($e);
647 my $sub_size = util::has_property($e, "subcontext");
649 if (util::is_pure_scalar($e)) {
655 if (util::need_wire_pointer($e)) {
656 pidl "\tif ($var_prefix$e->{NAME}) {\n";
657 if (util::has_property($e, "relative")) {
658 pidl "\t\tstruct ndr_pull_save _relative_save;\n";
659 pidl "\t\tndr_pull_save(ndr, &_relative_save);\n";
660 pidl "\t\tNDR_CHECK(ndr_pull_relative2(ndr, $var_prefix$e->{NAME}));\n";
664 if (util::is_inline_array($e)) {
665 ParseArrayPull($e, "r->", "NDR_BUFFERS");
666 } elsif (util::array_size($e)) {
667 ParseArrayPull($e, "r->", "NDR_SCALARS|NDR_BUFFERS");
668 } elsif (my $switch = util::has_property($e, "switch_is")) {
669 if ($e->{POINTERS}) {
670 ParseElementPullSwitch($e, $var_prefix, "NDR_SCALARS|NDR_BUFFERS", $switch);
672 ParseElementPullSwitch($e, $var_prefix, "NDR_BUFFERS", $switch);
674 } elsif (defined $sub_size) {
675 if ($e->{POINTERS}) {
676 if (util::is_builtin_type($e->{TYPE})) {
677 pidl "\tNDR_CHECK(ndr_pull_subcontext_fn(ndr, $sub_size, $cprefix$var_prefix$e->{NAME}, (ndr_pull_fn_t) ndr_pull_$e->{TYPE}));\n";
679 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";
682 } elsif (util::is_builtin_type($e->{TYPE})) {
683 pidl "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $cprefix$var_prefix$e->{NAME}));\n";
684 } elsif ($e->{POINTERS}) {
685 pidl "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, NDR_SCALARS|NDR_BUFFERS, $cprefix$var_prefix$e->{NAME}));\n";
687 pidl "\t\tNDR_CHECK(ndr_pull_$e->{TYPE}(ndr, $ndr_flags, $cprefix$var_prefix$e->{NAME}));\n";
690 if (util::need_wire_pointer($e)) {
691 if (util::has_property($e, "relative")) {
692 pidl "\t\tndr_pull_restore(ndr, &_relative_save);\n";
700 #####################################################################
702 sub ParseStructPush($)
706 if (! defined $struct->{ELEMENTS}) {
710 start_flags($struct);
712 # see if the structure contains a conformant array. If it
713 # does, then it must be the last element of the structure, and
714 # we need to push the conformant length early, as it fits on
715 # the wire before the structure (and even before the structure
717 my $e = $struct->{ELEMENTS}[-1];
718 if (defined $e->{ARRAY_LEN} && $e->{ARRAY_LEN} eq "*") {
719 my $size = find_size_var($e, util::array_size($e), "r->");
720 $e->{CONFORMANT_SIZE} = $size;
721 pidl "\tNDR_CHECK(ndr_push_uint32(ndr, $size));\n";
724 if (defined $e->{TYPE} && $e->{TYPE} eq "string"
725 && util::property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
726 pidl "\tNDR_CHECK(ndr_push_uint32(ndr, ndr_string_array_size(ndr, r->$e->{NAME})));\n";
729 pidl "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
731 pidl "\tNDR_CHECK(ndr_push_struct_start(ndr));\n";
733 my $align = struct_alignment($struct);
734 pidl "\tNDR_CHECK(ndr_push_align(ndr, $align));\n";
736 foreach my $e (@{$struct->{ELEMENTS}}) {
737 ParseElementPushScalar($e, "r->", "NDR_SCALARS");
741 pidl "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n";
742 foreach my $e (@{$struct->{ELEMENTS}}) {
743 ParseElementPushBuffer($e, "r->", "NDR_BUFFERS");
746 pidl "\tndr_push_struct_end(ndr);\n";
753 #####################################################################
754 # generate a struct print function
755 sub ParseStructPrint($)
759 if (! defined $struct->{ELEMENTS}) {
763 start_flags($struct);
765 pidl "\tndr->depth++;\n";
766 foreach my $e (@{$struct->{ELEMENTS}}) {
767 ParseElementPrintScalar($e, "r->");
769 pidl "\tndr->depth--;\n";
774 #####################################################################
775 # parse a struct - pull side
776 sub ParseStructPull($)
781 if (! defined $struct->{ELEMENTS}) {
785 # see if the structure contains a conformant array. If it
786 # does, then it must be the last element of the structure, and
787 # we need to pull the conformant length early, as it fits on
788 # the wire before the structure (and even before the structure
790 my $e = $struct->{ELEMENTS}[-1];
791 if (defined $e->{ARRAY_LEN} && $e->{ARRAY_LEN} eq "*") {
795 if (defined $e->{TYPE} && $e->{TYPE} eq "string"
796 && util::property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
800 if (defined $conform_e) {
802 pidl "\tuint32_t _conformant_size;\n";
803 $conform_e->{CONFORMANT_SIZE} = "_conformant_size";
806 # declare any internal pointers we need
807 foreach my $e (@{$struct->{ELEMENTS}}) {
808 if (util::need_wire_pointer($e)) {
809 pidl "\tuint32_t _ptr_$e->{NAME};\n";
813 start_flags($struct);
815 pidl "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
817 pidl "\tNDR_CHECK(ndr_pull_struct_start(ndr));\n";
819 if (defined $conform_e) {
820 pidl "\tNDR_CHECK(ndr_pull_uint32(ndr, &$conform_e->{CONFORMANT_SIZE}));\n";
823 my $align = struct_alignment($struct);
824 pidl "\tNDR_CHECK(ndr_pull_align(ndr, $align));\n";
826 foreach my $e (@{$struct->{ELEMENTS}}) {
827 ParseElementPullScalar($e, "r->", "NDR_SCALARS");
831 pidl "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n";
832 foreach my $e (@{$struct->{ELEMENTS}}) {
833 ParseElementPullBuffer($e, "r->", "NDR_BUFFERS");
836 foreach my $e (@{$struct->{ELEMENTS}}) {
837 CheckArraySizes($e, "r->");
840 pidl "\tndr_pull_struct_end(ndr);\n";
847 #####################################################################
848 # calculate size of ndr struct
849 sub ParseStructNdrSize($)
852 my $static = fn_prefix($t);
855 pidl $static . "size_t ndr_size_$t->{NAME}(int ret, const struct $t->{NAME} *r, int flags)\n";
858 if (util::has_property($t->{DATA}, "flag")) {
859 pidl "\tflags = flags | " . $t->{DATA}->{PROPERTIES}->{flag} . ";\n";
862 pidl "\tif(!r) return 0;\n";
864 pidl "\tret = NDR_SIZE_ALIGN(ret, " . struct_alignment($t->{DATA}) . ", flags);\n";
866 for my $e (@{$t->{DATA}->{ELEMENTS}}) {
869 if (util::has_property($e, "subcontext")) {
870 pidl "\tret += $e->{PROPERTIES}->{subcontext}; /* Subcontext length */\n";
873 if (util::has_property($e, "switch_is")) {
874 $switch = ", r->$e->{PROPERTIES}->{switch_is}";
877 if ($e->{POINTERS} > 0) {
878 pidl "\tret = ndr_size_ptr(ret, &r->$e->{NAME}, flags); \n";
879 } elsif (util::is_inline_array($e)) {
880 $sizevar = find_size_var($e, util::array_size($e), "r->");
883 pidl "\t\tfor(i = 0; i < $sizevar; i++) {\n";
884 pidl "\t\t\tret = ndr_size_$e->{TYPE}(ret, &r->" . $e->{NAME} . "[i], flags);\n";
888 pidl "\tret = ndr_size_$e->{TYPE}(ret, &r->$e->{NAME}$switch, flags); \n";
892 # Add lengths of relative members
893 for my $e (@{$t->{DATA}->{ELEMENTS}}) {
894 next unless (util::has_property($e, "relative"));
896 pidl "\tif (r->$e->{NAME}) {\n";
897 pidl "\t\tret = ndr_size_$e->{TYPE}(ret, r->$e->{NAME}, flags); \n";
901 pidl "\treturn ret;\n";
905 #####################################################################
906 # parse a union - push side
907 sub ParseUnionPush($)
910 my $have_default = 0;
914 pidl "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
916 pidl "\tNDR_CHECK(ndr_push_struct_start(ndr));\n";
918 # my $align = union_alignment($e);
919 # pidl "\tNDR_CHECK(ndr_push_align(ndr, $align));\n";
921 pidl "\tswitch (level) {\n";
922 foreach my $el (@{$e->{DATA}}) {
923 if ($el->{CASE} eq "default") {
927 pidl "\tcase $el->{CASE}:\n";
929 if ($el->{TYPE} eq "UNION_ELEMENT") {
930 ParseElementPushScalar($el->{DATA}, "r->", "NDR_SCALARS");
934 if (! $have_default) {
936 pidl "\t\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n";
940 pidl "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n";
941 pidl "\tswitch (level) {\n";
942 foreach my $el (@{$e->{DATA}}) {
943 if ($el->{CASE} eq "default") {
946 pidl "\tcase $el->{CASE}:\n";
948 if ($el->{TYPE} eq "UNION_ELEMENT") {
949 ParseElementPushBuffer($el->{DATA}, "r->", "NDR_BUFFERS");
953 if (! $have_default) {
955 pidl "\t\treturn ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n";
958 pidl "\tndr_push_struct_end(ndr);\n";
963 #####################################################################
965 sub ParseUnionPrint($)
968 my $have_default = 0;
972 pidl "\tswitch (level) {\n";
973 foreach my $el (@{$e->{DATA}}) {
974 if ($el->{CASE} eq "default") {
978 pidl "\tcase $el->{CASE}:\n";
980 if ($el->{TYPE} eq "UNION_ELEMENT") {
981 ParseElementPrintScalar($el->{DATA}, "r->");
985 if (! $have_default) {
986 pidl "\tdefault:\n\t\tndr_print_bad_level(ndr, name, level);\n";
993 #####################################################################
994 # parse a union - pull side
995 sub ParseUnionPull($)
998 my $have_default = 0;
1002 pidl "\tif (!(ndr_flags & NDR_SCALARS)) goto buffers;\n";
1004 pidl "\tNDR_CHECK(ndr_pull_struct_start(ndr));\n";
1006 # my $align = union_alignment($e);
1007 # pidl "\tNDR_CHECK(ndr_pull_align(ndr, $align));\n";
1009 pidl "\tswitch (level) {\n";
1010 foreach my $el (@{$e->{DATA}}) {
1011 if ($el->{CASE} eq "default") {
1012 pidl "\tdefault: {\n";
1015 pidl "\tcase $el->{CASE}: {\n";
1017 if ($el->{TYPE} eq "UNION_ELEMENT") {
1018 my $e2 = $el->{DATA};
1019 if ($e2->{POINTERS}) {
1020 pidl "\t\tuint32_t _ptr_$e2->{NAME};\n";
1022 ParseElementPullScalar($el->{DATA}, "r->", "NDR_SCALARS");
1024 pidl "\tbreak; }\n\n";
1026 if (! $have_default) {
1027 pidl "\tdefault:\n";
1028 pidl "\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n";
1032 pidl "\tif (!(ndr_flags & NDR_BUFFERS)) goto done;\n";
1033 pidl "\tswitch (level) {\n";
1034 foreach my $el (@{$e->{DATA}}) {
1035 if ($el->{CASE} eq "default") {
1036 pidl "\tdefault:\n";
1038 pidl "\tcase $el->{CASE}:\n";
1040 if ($el->{TYPE} eq "UNION_ELEMENT") {
1041 ParseElementPullBuffer($el->{DATA}, "r->", "NDR_BUFFERS");
1043 pidl "\tbreak;\n\n";
1045 if (! $have_default) {
1046 pidl "\tdefault:\n";
1047 pidl "\t\treturn ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value \%u\", level);\n";
1050 pidl "\tndr_pull_struct_end(ndr);\n";
1055 #####################################################################
1056 # calculate size of ndr union
1058 sub ParseUnionNdrSize($)
1061 my $static = fn_prefix($t);
1063 pidl $static . "size_t ndr_size_$t->{NAME}(int ret, const union $t->{NAME} *data, uint16 level, int flags)\n";
1065 if (util::has_property($t->{DATA}, "flag")) {
1066 pidl "\tflags = flags | " . $t->{DATA}->{PROPERTIES}->{flag} . ";\n";
1068 pidl "\tif(!data) return 0;\n\n";
1070 pidl "\tret = NDR_SIZE_ALIGN(ret, " . union_alignment($t->{DATA}) . ", flags);\n";
1072 pidl "\tswitch(level) {\n";
1074 for my $e (@{$t->{DATA}->{DATA}}) {
1075 if ($e->{TYPE} eq "UNION_ELEMENT") {
1077 if ($e->{CASE} eq "default") {
1078 pidl "\t\tdefault:";
1080 pidl "\t\tcase $e->{CASE}:";
1083 pidl " return ndr_size_$e->{DATA}->{TYPE}(ret, &data->$e->{DATA}->{NAME}, flags); \n";
1088 pidl "\treturn ret;\n";
1092 #####################################################################
1094 sub ParseTypePush($)
1098 if (ref($data) eq "HASH") {
1099 ($data->{TYPE} eq "STRUCT") &&
1100 ParseStructPush($data);
1101 ($data->{TYPE} eq "UNION") &&
1102 ParseUnionPush($data);
1106 #####################################################################
1107 # generate a print function for a type
1108 sub ParseTypePrint($)
1112 if (ref($data) eq "HASH") {
1113 ($data->{TYPE} eq "STRUCT") &&
1114 ParseStructPrint($data);
1115 ($data->{TYPE} eq "UNION") &&
1116 ParseUnionPrint($data);
1120 #####################################################################
1122 sub ParseTypePull($)
1126 if (ref($data) eq "HASH") {
1127 ($data->{TYPE} eq "STRUCT") &&
1128 ParseStructPull($data);
1129 ($data->{TYPE} eq "UNION") &&
1130 ParseUnionPull($data);
1134 #####################################################################
1135 # parse a typedef - push side
1136 sub ParseTypedefPush($)
1139 my $static = fn_prefix($e);
1141 if (! needed::is_needed("push_$e->{NAME}")) {
1142 # print "push_$e->{NAME} not needed\n";
1146 if ($e->{DATA}->{TYPE} eq "STRUCT") {
1147 pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, struct $e->{NAME} *r)";
1149 ParseTypePush($e->{DATA});
1150 pidl "\treturn NT_STATUS_OK;\n";
1154 if ($e->{DATA}->{TYPE} eq "UNION") {
1155 pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, int level, union $e->{NAME} *r)";
1157 ParseTypePush($e->{DATA});
1158 pidl "\treturn NT_STATUS_OK;\n";
1164 #####################################################################
1165 # parse a typedef - pull side
1166 sub ParseTypedefPull($)
1169 my $static = fn_prefix($e);
1171 if (! needed::is_needed("pull_$e->{NAME}")) {
1172 # print "pull_$e->{NAME} not needed\n";
1176 if ($e->{DATA}->{TYPE} eq "STRUCT") {
1177 pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, struct $e->{NAME} *r)";
1179 ParseTypePull($e->{DATA});
1180 pidl "\treturn NT_STATUS_OK;\n";
1184 if ($e->{DATA}->{TYPE} eq "UNION") {
1185 pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, int level, union $e->{NAME} *r)";
1187 ParseTypePull($e->{DATA});
1188 pidl "\treturn NT_STATUS_OK;\n";
1194 #####################################################################
1195 # parse a typedef - print side
1196 sub ParseTypedefPrint($)
1200 if ($e->{DATA}->{TYPE} eq "STRUCT") {
1201 pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, struct $e->{NAME} *r)";
1203 pidl "\tndr_print_struct(ndr, name, \"$e->{NAME}\");\n";
1204 ParseTypePrint($e->{DATA});
1208 if ($e->{DATA}->{TYPE} eq "UNION") {
1209 pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, int level, union $e->{NAME} *r)";
1211 pidl "\tndr_print_union(ndr, name, level, \"$e->{NAME}\");\n";
1212 ParseTypePrint($e->{DATA});
1217 #####################################################################
1218 ## calculate the size of a structure
1219 sub ParseTypedefNdrSize($)
1222 if (! needed::is_needed("ndr_size_$t->{NAME}")) {
1226 ($t->{DATA}->{TYPE} eq "STRUCT") &&
1227 ParseStructNdrSize($t);
1229 ($t->{DATA}->{TYPE} eq "UNION") &&
1230 ParseUnionNdrSize($t);
1234 #####################################################################
1235 # parse a function - print side
1236 sub ParseFunctionPrint($)
1240 pidl "void ndr_print_$fn->{NAME}(struct ndr_print *ndr, const char *name, int flags, struct $fn->{NAME} *r)";
1242 pidl "\tndr_print_struct(ndr, name, \"$fn->{NAME}\");\n";
1243 pidl "\tndr->depth++;\n";
1245 pidl "\tif (flags & NDR_SET_VALUES) {\n";
1246 pidl "\t\tndr->flags |= LIBNDR_PRINT_SET_VALUES;\n";
1249 pidl "\tif (flags & NDR_IN) {\n";
1250 pidl "\t\tndr_print_struct(ndr, \"in\", \"$fn->{NAME}\");\n";
1251 pidl "\tndr->depth++;\n";
1252 foreach my $e (@{$fn->{DATA}}) {
1253 if (util::has_property($e, "in")) {
1254 ParseElementPrintScalar($e, "r->in.");
1257 pidl "\tndr->depth--;\n";
1260 pidl "\tif (flags & NDR_OUT) {\n";
1261 pidl "\t\tndr_print_struct(ndr, \"out\", \"$fn->{NAME}\");\n";
1262 pidl "\tndr->depth++;\n";
1263 foreach my $e (@{$fn->{DATA}}) {
1264 if (util::has_property($e, "out")) {
1265 ParseElementPrintScalar($e, "r->out.");
1268 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
1269 if (util::is_scalar_type($fn->{RETURN_TYPE})) {
1270 pidl "\tndr_print_$fn->{RETURN_TYPE}(ndr, \"result\", r->out.result);\n";
1272 pidl "\tndr_print_$fn->{RETURN_TYPE}(ndr, \"result\", &r->out.result);\n";
1275 pidl "\tndr->depth--;\n";
1278 pidl "\tndr->depth--;\n";
1283 #####################################################################
1284 # parse a function element
1285 sub ParseFunctionElementPush($$)
1290 if (util::array_size($e)) {
1291 if (util::need_wire_pointer($e)) {
1292 pidl "\tNDR_CHECK(ndr_push_ptr(ndr, r->$inout.$e->{NAME}));\n";
1293 pidl "\tif (r->$inout.$e->{NAME}) {\n";
1294 ParseArrayPush($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1297 ParseArrayPush($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1300 ParseElementPushScalar($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1301 if ($e->{POINTERS}) {
1302 ParseElementPushBuffer($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1307 #####################################################################
1309 sub ParseFunctionPush($)
1312 my $static = fn_prefix($fn);
1314 pidl $static . "NTSTATUS ndr_push_$fn->{NAME}(struct ndr_push *ndr, int flags, struct $fn->{NAME} *r)\n{\n";
1316 pidl "\n\tif (!(flags & NDR_IN)) goto ndr_out;\n\n";
1318 foreach my $e (@{$fn->{DATA}}) {
1319 if (util::has_property($e, "in")) {
1320 ParseFunctionElementPush($e, "in");
1324 pidl "\nndr_out:\n";
1325 pidl "\tif (!(flags & NDR_OUT)) goto done;\n\n";
1327 foreach my $e (@{$fn->{DATA}}) {
1328 if (util::has_property($e, "out")) {
1329 ParseFunctionElementPush($e, "out");
1333 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
1334 pidl "\tNDR_CHECK(ndr_push_$fn->{RETURN_TYPE}(ndr, r->out.result));\n";
1338 pidl "\n\treturn NT_STATUS_OK;\n}\n\n";
1341 #####################################################################
1342 # parse a function element
1343 sub ParseFunctionElementPull($$)
1348 if (util::array_size($e)) {
1349 if (util::need_wire_pointer($e)) {
1350 pidl "\tNDR_CHECK(ndr_pull_ptr(ndr, &_ptr_$e->{NAME}));\n";
1351 pidl "\tif (_ptr_$e->{NAME}) {\n";
1352 } elsif ($inout eq "out" && util::has_property($e, "ref")) {
1353 pidl "\tif (r->$inout.$e->{NAME}) {\n";
1357 ParseArrayPull($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1360 if ($inout eq "out" && util::has_property($e, "ref")) {
1361 pidl "\tif (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {\n";
1362 pidl "\tNDR_ALLOC(ndr, r->out.$e->{NAME});\n";
1365 if ($inout eq "in" && util::has_property($e, "ref")) {
1366 pidl "\tNDR_ALLOC(ndr, r->in.$e->{NAME});\n";
1369 ParseElementPullScalar($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1370 if ($e->{POINTERS}) {
1371 ParseElementPullBuffer($e, "r->$inout.", "NDR_SCALARS|NDR_BUFFERS");
1377 ############################################################
1378 # allocate ref variables
1379 sub AllocateRefVars($)
1382 my $asize = util::array_size($e);
1384 # note that if the variable is also an "in"
1385 # variable then we copy the initial value from
1388 if (!defined $asize) {
1389 # its a simple variable
1390 pidl "\tNDR_ALLOC(ndr, r->out.$e->{NAME});\n";
1391 if (util::has_property($e, "in")) {
1392 pidl "\t*r->out.$e->{NAME} = *r->in.$e->{NAME};\n";
1394 pidl "\tZERO_STRUCTP(r->out.$e->{NAME});\n";
1400 my $size = find_size_var($e, $asize, "r->out.");
1401 pidl "\tNDR_ALLOC_N(ndr, r->out.$e->{NAME}, $size);\n";
1402 if (util::has_property($e, "in")) {
1403 pidl "\tmemcpy(r->out.$e->{NAME},r->in.$e->{NAME},$size * sizeof(*r->in.$e->{NAME}));\n";
1405 pidl "\tmemset(r->out.$e->{NAME}, 0, $size * sizeof(*r->out.$e->{NAME}));\n";
1410 #####################################################################
1412 sub ParseFunctionPull($)
1415 my $static = fn_prefix($fn);
1417 # pull function args
1418 pidl $static . "NTSTATUS ndr_pull_$fn->{NAME}(struct ndr_pull *ndr, int flags, struct $fn->{NAME} *r)\n{\n";
1420 # declare any internal pointers we need
1421 foreach my $e (@{$fn->{DATA}}) {
1422 if (util::need_wire_pointer($e)) {
1423 pidl "\tuint32_t _ptr_$e->{NAME};\n";
1427 pidl "\n\tif (!(flags & NDR_IN)) goto ndr_out;\n\n";
1429 # auto-init the out section of a structure. I originally argued that
1430 # this was a bad idea as it hides bugs, but coping correctly
1431 # with initialisation and not wiping ref vars is turning
1432 # out to be too tricky (tridge)
1433 foreach my $e (@{$fn->{DATA}}) {
1434 if (util::has_property($e, "out")) {
1435 pidl "\tZERO_STRUCT(r->out);\n\n";
1440 foreach my $e (@{$fn->{DATA}}) {
1441 if (util::has_property($e, "in")) {
1442 ParseFunctionElementPull($e, "in");
1444 # we need to allocate any reference output variables, so that
1445 # a dcerpc backend can be sure they are non-null
1446 if (util::has_property($e, "out") && util::has_property($e, "ref")) {
1447 AllocateRefVars($e);
1451 foreach my $e (@{$fn->{DATA}}) {
1452 if (util::has_property($e, "in")) {
1453 CheckArraySizes($e, "r->in.");
1457 pidl "\nndr_out:\n";
1458 pidl "\tif (!(flags & NDR_OUT)) goto done;\n\n";
1460 foreach my $e (@{$fn->{DATA}}) {
1461 if (util::has_property($e, "out")) {
1462 ParseFunctionElementPull($e, "out");
1466 foreach my $e (@{$fn->{DATA}}) {
1467 if (util::has_property($e, "out")) {
1468 CheckArraySizes($e, "r->out.");
1472 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
1473 pidl "\tNDR_CHECK(ndr_pull_$fn->{RETURN_TYPE}(ndr, &r->out.result));\n";
1477 pidl "\n\treturn NT_STATUS_OK;\n}\n\n";
1480 #####################################################################
1481 # produce a function call table
1482 sub FunctionTable($)
1484 my($interface) = shift;
1485 my($data) = $interface->{INHERITED_DATA};
1487 my $uname = uc $interface->{NAME};
1489 foreach my $d (@{$data}) {
1490 if ($d->{TYPE} eq "FUNCTION") { $count++; }
1493 return if ($count == 0);
1495 pidl "static const struct dcerpc_interface_call $interface->{NAME}\_calls[] = {\n";
1496 foreach my $d (@{$data}) {
1497 if ($d->{TYPE} eq "FUNCTION") {
1499 pidl "\t\t\"$d->{NAME}\",\n";
1500 pidl "\t\tsizeof(struct $d->{NAME}),\n";
1501 pidl "\t\t(ndr_push_flags_fn_t) ndr_push_$d->{NAME},\n";
1502 pidl "\t\t(ndr_pull_flags_fn_t) ndr_pull_$d->{NAME},\n";
1503 pidl "\t\t(ndr_print_function_t) ndr_print_$d->{NAME}\n";
1507 pidl "\t{ NULL, 0, NULL, NULL }\n};\n\n";
1509 # If no endpoint is set, default to the interface name as a named pipe
1510 if (! defined $interface->{PROPERTIES}->{endpoint}) {
1511 $interface->{PROPERTIES}->{endpoint} = "\"ncacn_np:[\\\\pipe\\\\" . $interface->{NAME} . "]\"";
1514 my @e = split / /, $interface->{PROPERTIES}->{endpoint};
1515 my $endpoint_count = $#e + 1;
1517 pidl "static const char * const $interface->{NAME}\_endpoint_strings[] = {\n";
1518 foreach my $ep (@e) {
1523 pidl "static const struct dcerpc_endpoint_list $interface->{NAME}\_endpoints = {\n";
1524 pidl "\t$endpoint_count, $interface->{NAME}\_endpoint_strings\n";
1527 pidl "\nconst struct dcerpc_interface_table dcerpc_table_$interface->{NAME} = {\n";
1528 pidl "\t\"$interface->{NAME}\",\n";
1529 pidl "\tDCERPC_$uname\_UUID,\n";
1530 pidl "\tDCERPC_$uname\_VERSION,\n";
1531 pidl "\tDCERPC_$uname\_HELPSTRING,\n";
1533 pidl "\t$interface->{NAME}\_calls,\n";
1534 pidl "\t&$interface->{NAME}\_endpoints\n";
1537 pidl "static NTSTATUS dcerpc_ndr_$interface->{NAME}_init(void)\n";
1539 pidl "\treturn librpc_register_interface(&dcerpc_table_$interface->{NAME});\n";
1543 #####################################################################
1544 # parse the interface definitions
1545 sub ParseInterface($)
1547 my($interface) = shift;
1548 my($data) = $interface->{DATA};
1550 foreach my $d (@{$data}) {
1551 if ($d->{TYPE} eq "TYPEDEF") {
1552 $structs{$d->{NAME}} = $d;
1556 foreach my $d (@{$data}) {
1557 ($d->{TYPE} eq "TYPEDEF") &&
1558 ParseTypedefNdrSize($d);
1561 foreach my $d (@{$data}) {
1562 ($d->{TYPE} eq "TYPEDEF") &&
1563 ParseTypedefPush($d);
1564 ($d->{TYPE} eq "FUNCTION") &&
1565 ParseFunctionPush($d);
1567 foreach my $d (@{$data}) {
1568 ($d->{TYPE} eq "TYPEDEF") &&
1569 ParseTypedefPull($d);
1570 ($d->{TYPE} eq "FUNCTION") &&
1571 ParseFunctionPull($d);
1573 foreach my $d (@{$data}) {
1574 if ($d->{TYPE} eq "TYPEDEF" &&
1575 !util::has_property($d->{DATA}, "noprint")) {
1576 ParseTypedefPrint($d);
1578 if ($d->{TYPE} eq "FUNCTION" &&
1579 !util::has_property($d, "noprint")) {
1580 ParseFunctionPrint($d);
1584 FunctionTable($interface);
1587 sub RegistrationFunction($$)
1590 my $filename = shift;
1592 $filename =~ /.*\/ndr_(.*).c/;
1594 pidl "NTSTATUS dcerpc_$basename\_init(void)\n";
1596 pidl "\tNTSTATUS status = NT_STATUS_OK;\n";
1597 foreach my $interface (@{$idl}) {
1598 next if $interface->{TYPE} ne "INTERFACE";
1600 my $data = $interface->{INHERITED_DATA};
1602 foreach my $d (@{$data}) {
1603 if ($d->{TYPE} eq "FUNCTION") { $count++; }
1606 next if ($count == 0);
1608 pidl "\tstatus = dcerpc_ndr_$interface->{NAME}_init();\n";
1609 pidl "\tif (NT_STATUS_IS_ERR(status)) {\n";
1610 pidl "\t\treturn status;\n";
1613 pidl "\treturn status;\n";
1617 #####################################################################
1618 # parse a parsed IDL structure back into an IDL file
1622 my($filename) = shift;
1623 my $h_filename = $filename;
1625 if ($h_filename =~ /(.*)\.c/) {
1626 $h_filename = "$1.h";
1629 open(OUT, ">$filename") || die "can't open $filename";
1631 pidl "/* parser auto-generated by pidl */\n\n";
1632 pidl "#include \"includes.h\"\n";
1633 pidl "#include \"$h_filename\"\n\n";
1635 foreach my $x (@{$idl}) {
1636 if ($x->{TYPE} eq "INTERFACE") {
1637 needed::BuildNeeded($x);
1642 RegistrationFunction($idl, $filename);