Changeset 988 for vendor/current/pidl
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- Location:
- vendor/current/pidl
- Files:
-
- 1 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/pidl/README
r414 r988 1 1 Introduction: 2 2 ============= 3 This directory contains the source code of the pidl (Perl IDL) 4 compiler for Samba 4. 3 This directory contains the source code of the pidl (Perl IDL) 4 compiler for Samba 4. 5 5 6 6 The main sources for pidl are available using Git as part of 7 the combined Samba 3 / Samba 4tree. Use:7 the Samba source tree. Use: 8 8 git clone git://git.samba.org/samba.git 9 9 10 Pidl works by building a parse tree from a .pidl file (a simple 11 dump of it's internal parse tree) or a .idl file 12 (a file format mostly like the IDL file format midl uses). 13 The IDL file parser is in idl.yp (a yacc file converted to 10 Pidl works by building a parse tree from a .pidl file (a simple 11 dump of it's internal parse tree) or a .idl file 12 (a file format mostly like the IDL file format midl uses). 13 The IDL file parser is in idl.yp (a yacc file converted to 14 14 perl code by yapp) 15 16 After a parse tree is present, pidl will call one of it's backends17 (which one depends on the options given on the command-line). Here is18 a list of current backends:19 15 20 16 Standalone installation: 21 17 ======================== 22 Run Makefile.PL to generate the Makefile. 18 Run Makefile.PL to generate the Makefile. 23 19 24 20 Then run "make install" (as root) to install. … … 26 22 Internals overview: 27 23 =================== 24 25 After a parse tree is present, pidl will call one of it's backends 26 (which one depends on the options given on the command-line). Here is 27 a list of current backends: 28 28 29 29 -- Generic -- … … 56 56 57 57 Tips for hacking on pidl: 58 - Look at the pidl's parse tree by using the --keep option and looking59 at the generated .pidl file.60 - The various backends have a lot in common, if you don't understand how one 61 implements something, look at the others 58 - Inspect pidl's parse tree by using the --keep option and looking at the 59 generated .pidl file. 60 - The various backends have a lot in common, if you don't understand how one 61 implements something, look at the others. 62 62 - See pidl(1) and the documentation on midl 63 - See 'info bison' and yapp(1) for information on the file format of idl.yp 63 - See 'info bison' and yapp(1) for information on the file format of idl.yp 64 - Run the tests (all in tests/) -
vendor/current/pidl/TODO
r414 r988 15 15 - --explain-ndr option that dumps out parse tree ? 16 16 17 - sep erate tables for NDR and DCE/RPC17 - separate tables for NDR and DCE/RPC 18 18 - maybe no tables for NDR at all? we only need them for ndrdump 19 19 and that can use dlsym() -
vendor/current/pidl/lib/Parse/Pidl/Dump.pm
r414 r988 40 40 41 41 foreach my $d ($props) { 42 foreach my $k ( keys %{$d}) {42 foreach my $k (sort(keys %{$d})) { 43 43 if ($k eq "in") { 44 44 $res .= "[in] "; … … 245 245 246 246 $res .= "[\n"; 247 foreach my $k ( keys %{$data}) {247 foreach my $k (sort(keys %{$data})) { 248 248 $first || ($res .= ",\n"); $first = 0; 249 249 $res .= "$k($data->{$k})"; -
vendor/current/pidl/lib/Parse/Pidl/NDR.pm
r860 r988 950 950 my ($e) = @_; 951 951 952 if (property_matches($e, "flag", ".*STR_NULLTERM.*")) { 953 return 1; 954 } 955 if (exists($e->{LEVELS}) and $e->{LEVELS}->[0]->{TYPE} eq "ARRAY" and 956 ($e->{LEVELS}->[0]->{IS_FIXED} or $e->{LEVELS}->[0]->{IS_INLINE}) and 957 has_property($e, "charset")) 958 { 959 return 1; 960 } 961 952 962 foreach my $l (@{$e->{LEVELS}}) { 953 963 return 1 if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED}); 964 } 965 if (property_matches($e, "charset", ".*DOS.*")) { 966 return 1; 954 967 } 955 968 -
vendor/current/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
r740 r988 14 14 use strict; 15 15 use Parse::Pidl qw(fatal warning error); 16 use Parse::Pidl::Util qw(has_property ParseExpr );16 use Parse::Pidl::Util qw(has_property ParseExpr genpad); 17 17 use Parse::Pidl::NDR qw(ContainsPipe); 18 18 use Parse::Pidl::Typelist qw(mapTypeName); … … 29 29 sub fn_declare($$) { my ($self,$n) = @_; $self->pidl($n); $self->pidl_hdr("$n;"); } 30 30 31 sub genpad($)32 {33 my ($s) = @_;34 my $nt = int((length($s)+1)/8);35 my $lt = ($nt*8)-1;36 my $ns = (length($s)-$lt);37 return "\t"x($nt)." "x($ns);38 }39 40 31 sub new($) 41 32 { … … 60 51 my $ret = ""; 61 52 62 foreach my $d ( keys %{$props}) {53 foreach my $d (sort(keys %{$props})) { 63 54 next if (grep(/^$d$/, @$ignores)); 64 55 if($props->{$d} ne "1") { -
vendor/current/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm
r919 r988 15 15 use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); 16 16 use Parse::Pidl::Util qw(ParseExpr has_property is_constant); 17 use Parse::Pidl::NDR qw(GetNextLevel );17 use Parse::Pidl::NDR qw(GetNextLevel ContainsPipe); 18 18 use Parse::Pidl::Samba4 qw(ElementStars DeclLong); 19 19 use Parse::Pidl::Samba4::Header qw(GenerateFunctionOutEnv); … … 25 25 my $res_hdr; 26 26 my $tabs = ""; 27 sub pidl_reset() { $res=""; $res_hdr="", $tabs=""; } 28 sub pidl_return() { my $s = $res; my $h = $res_hdr; pidl_reset(); return ($s, $h) } 27 29 sub indent() { $tabs.="\t"; } 28 30 sub deindent() { $tabs = substr($tabs, 1); } … … 49 51 } 50 52 51 sub AllocOutVar($$$$$ )52 { 53 my ($e, $mem_ctx, $name, $env, $ fail) = @_;53 sub AllocOutVar($$$$$$$) 54 { 55 my ($e, $mem_ctx, $name, $env, $check, $cleanup, $return) = @_; 54 56 55 57 my $l = $e->{LEVELS}[0]; … … 84 86 } 85 87 86 pidl "if ($name == NULL) {"; 87 $fail->(); 88 pidl "}"; 89 pidl ""; 90 } 91 92 sub CallWithStruct($$$$) 93 { 94 my ($pipes_struct, $mem_ctx, $fn, $fail) = @_; 88 pidl "if (" . $check->($name) . ") {"; 89 indent; 90 pidl $cleanup->($name) if defined($cleanup); 91 pidl $return->($name) if defined($return); 92 deindent; 93 pidl "}"; 94 pidl ""; 95 } 96 97 sub CallWithStruct($$$$$$) 98 { 99 my ($pipes_struct, $mem_ctx, $fn, $check, $cleanup, $return) = @_; 95 100 my $env = GenerateFunctionOutEnv($fn); 96 101 my $hasout = 0; … … 101 106 pidl "ZERO_STRUCT(r->out);" if ($hasout); 102 107 103 my $proto = "_$fn->{NAME}(struct pipes_struct *p, struct $fn->{NAME} *r";104 my $ret = "_$fn->{NAME}($pipes_struct, r";105 108 foreach (@{$fn->{ELEMENTS}}) { 106 109 my @dir = @{$_->{DIRECTION}}; … … 111 114 112 115 foreach (@{$fn->{ELEMENTS}}) { 116 next if ContainsPipe($_, $_->{LEVELS}[0]); 113 117 my @dir = @{$_->{DIRECTION}}; 114 118 if (grep(/in/, @dir) and grep(/out/, @dir)) { … … 116 120 } elsif (grep(/out/, @dir) and not 117 121 has_property($_, "represent_as")) { 118 AllocOutVar($_, $mem_ctx, "r->out.$_->{NAME}", $env, $fail); 119 } 120 } 121 $ret .= ")"; 122 $proto .= ");"; 122 AllocOutVar($_, $mem_ctx, "r->out.$_->{NAME}", $env, 123 $check, $cleanup, $return); 124 } 125 } 126 127 my $proto = "_$fn->{NAME}(struct pipes_struct *p, struct $fn->{NAME} *r)"; 128 my $ret = "_$fn->{NAME}($pipes_struct, r)"; 123 129 124 130 if ($fn->{RETURN_TYPE}) { 125 131 $ret = "r->out.result = $ret"; 126 $proto = "$fn->{RETURN_TYPE}$proto";132 $proto = mapTypeName($fn->{RETURN_TYPE})." $proto"; 127 133 } else { 128 134 $proto = "void $proto"; 129 135 } 130 136 131 pidl_hdr "$proto ";137 pidl_hdr "$proto;"; 132 138 pidl "$ret;"; 133 139 } … … 176 182 pidl ""; 177 183 178 CallWithStruct("p", "r", $fn, 179 sub { 180 pidl "\ttalloc_free(r);"; 181 pidl "\treturn false;"; 184 CallWithStruct("p", "r", $fn, 185 sub ($) { 186 my ($name) = @_; 187 return "${name} == NULL"; 188 }, 189 sub ($) { 190 my ($name) = @_; 191 return "talloc_free(r);"; 192 }, 193 sub ($) { 194 my ($name) = @_; 195 return "return false;"; 182 196 } 183 197 ); … … 286 300 my($ndr,$header,$ndr_header) = @_; 287 301 288 $res = ""; 289 $res_hdr = ""; 302 pidl_reset(); 290 303 291 304 pidl "/*"; … … 304 317 } 305 318 306 return ($res, $res_hdr);319 return pidl_return(); 307 320 } 308 321 -
vendor/current/pidl/lib/Parse/Pidl/Samba4/Header.pm
r740 r988 39 39 my $ret = ""; 40 40 41 foreach my $d ( keys %{$props}) {41 foreach my $d (sort(keys %{$props})) { 42 42 next if (grep(/^$d$/, @$ignores)); 43 43 if($props->{$d} ne "1") { … … 143 143 my $with_val = 0; 144 144 my $without_val = 0; 145 pidl " { __do nnot_use_enum_$name=0x7FFFFFFF}\n";145 pidl " { __do_not_use_enum_$name=0x7FFFFFFF}\n"; 146 146 foreach my $e (@{$enum->{ELEMENTS}}) { 147 147 my $t = "$e"; -
vendor/current/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm
r740 r988 12 12 13 13 use Parse::Pidl qw(fatal warning error); 14 use Parse::Pidl::Util qw(has_property ParseExpr );14 use Parse::Pidl::Util qw(has_property ParseExpr genpad); 15 15 use Parse::Pidl::NDR qw(ContainsPipe); 16 16 use Parse::Pidl::Typelist qw(mapTypeName); … … 29 29 sub pidl_both($$) { my ($self, $txt) = @_; $self->{hdr} .= "$txt\n"; $self->{res_hdr} .= "$txt\n"; } 30 30 sub fn_declare($$) { my ($self,$n) = @_; $self->pidl($n); $self->pidl_hdr("$n;"); } 31 32 sub genpad($)33 {34 my ($s) = @_;35 my $nt = int((length($s)+1)/8);36 my $lt = ($nt*8)-1;37 my $ns = (length($s)-$lt);38 return "\t"x($nt)." "x($ns);39 }40 31 41 32 sub new($) … … 159 150 160 151 $self->pidl("status = dcerpc_binding_handle_call_recv(subreq);"); 161 $self->pidl(" if (!NT_STATUS_IS_OK(status)) {");162 $self-> indent;163 $self-> pidl("tevent_req_nterror(req, status);");152 $self->pidl("TALLOC_FREE(subreq);"); 153 $self->pidl("if (tevent_req_nterror(req, status)) {"); 154 $self->indent; 164 155 $self->pidl("return;"); 165 156 $self->deindent; … … 260 251 my $ret = ""; 261 252 262 foreach my $d ( keys %{$props}) {253 foreach my $d (sort(keys %{$props})) { 263 254 next if (grep(/^$d$/, @$ignores)); 264 255 if($props->{$d} ne "1") { … … 401 392 } 402 393 394 my $dest_ptr = "$o$e->{NAME}"; 395 my $elem_size = "sizeof(*$dest_ptr)"; 396 $self->pidl("if ($dest_ptr != $out_var) {"); 397 $self->indent; 403 398 if (has_property($e, "charset")) { 404 $self->pidl("memcpy(discard_const_p(uint8_t *, $o$e->{NAME}), $out_var, $copy_len_var * sizeof(*$o$e->{NAME}));"); 405 } else { 406 $self->pidl("memcpy($o$e->{NAME}, $out_var, $copy_len_var * sizeof(*$o$e->{NAME}));"); 407 } 399 $dest_ptr = "discard_const_p(uint8_t *, $dest_ptr)"; 400 } 401 $self->pidl("memcpy($dest_ptr, $out_var, $copy_len_var * $elem_size);"); 402 $self->deindent; 403 $self->pidl("}"); 408 404 409 405 $self->deindent; … … 564 560 $self->pidl("status = dcerpc_$name\_r_recv(subreq, mem_ctx);"); 565 561 $self->pidl("TALLOC_FREE(subreq);"); 566 $self->pidl("if (!NT_STATUS_IS_OK(status)) {"); 567 $self->indent; 568 $self->pidl("tevent_req_nterror(req, status);"); 562 $self->pidl("if (tevent_req_nterror(req, status)) {"); 563 $self->indent; 569 564 $self->pidl("return;"); 570 565 $self->deindent; … … 693 688 } 694 689 $self->pidl(""); 690 691 $self->pidl("/* Out parameters */"); 692 foreach my $e (@{$fn->{ELEMENTS}}) { 693 next unless grep(/out/, @{$e->{DIRECTION}}); 694 695 $self->ParseCopyArgument($fn, $e, "r.out.", "_"); 696 } 697 $self->pidl(""); 698 699 if (defined($fn->{RETURN_TYPE})) { 700 $self->pidl("/* Result */"); 701 $self->pidl("ZERO_STRUCT(r.out.result);"); 702 $self->pidl(""); 703 } 695 704 696 705 $self->pidl("status = dcerpc_$name\_r(h, mem_ctx, &r);"); -
vendor/current/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
r860 r988 199 199 $size = $length = "ndr_string_length($var_name, sizeof(*$var_name))"; 200 200 } 201 if (defined($l->{SIZE_IS})) { 202 $size = ParseExpr($l->{SIZE_IS}, $env, $e); 203 } 204 if (defined($l->{LENGTH_IS})) { 205 $length = ParseExpr($l->{LENGTH_IS}, $env, $e); 206 } 201 207 } else { 202 208 $size = ParseExpr($l->{SIZE_IS}, $env, $e); … … 256 262 } 257 263 } 258 warning($element->{ORIGINAL}, "Got pointer for `$e->{NAME}', expected fully derefe nced variable") if ($nump > length($ptr));264 warning($element->{ORIGINAL}, "Got pointer for `$e->{NAME}', expected fully dereferenced variable") if ($nump > length($ptr)); 259 265 return ($origvar); 260 266 } … … 413 419 } 414 420 415 if ($l->{IS_CONFORMANT} and not $l->{IS_ZERO_TERMINATED}) {421 if ($l->{IS_CONFORMANT} and (defined($l->{SIZE_IS}) or not $l->{IS_ZERO_TERMINATED})) { 416 422 $self->defer("if ($var_name) {"); 417 423 $self->defer_indent; … … 425 431 } 426 432 427 if ($l->{IS_VARYING} and not $l->{IS_ZERO_TERMINATED}) {433 if ($l->{IS_VARYING} and (defined($l->{LENGTH_IS}) or not $l->{IS_ZERO_TERMINATED})) { 428 434 $self->defer("if ($var_name) {"); 429 435 $self->defer_indent; … … 627 633 } 628 634 629 if ($l->{TYPE} eq "POINTER" and $deferred) { 635 if ($l->{TYPE} eq "POINTER" and $l->{POINTER_TYPE} eq "ignore") { 636 $self->pidl("/* [ignore] '$e->{NAME}' */"); 637 } elsif ($l->{TYPE} eq "POINTER" and $deferred) { 630 638 my $rel_var_name = $var_name; 631 639 if ($l->{POINTER_TYPE} ne "ref") { … … 663 671 664 672 if ((($primitives and not $l->{IS_DEFERRED}) or ($deferred and $l->{IS_DEFERRED})) and not $array_pointless) { 665 $self->pidl("for ($counter = 0; $counter < $length; $counter++) {");673 $self->pidl("for ($counter = 0; $counter < ($length); $counter++) {"); 666 674 $self->indent; 667 675 $self->ParseElementPushLevel($e, GetNextLevel($e, $l), $ndr, $var_name, $env, 1, 0); … … 671 679 672 680 if ($deferred and ContainsDeferred($e, $l) and not $array_pointless) { 673 $self->pidl("for ($counter = 0; $counter < $length; $counter++) {");681 $self->pidl("for ($counter = 0; $counter < ($length); $counter++) {"); 674 682 $self->indent; 675 683 $self->ParseElementPushLevel($e, GetNextLevel($e, $l), $ndr, $var_name, $env, 0, 1); … … 730 738 731 739 if ($l->{POINTER_TYPE} eq "ref") { 732 $self->pidl("if ($var_name == NULL) {"); 733 $self->indent; 734 $self->pidl("return ndr_push_error($ndr, NDR_ERR_INVALID_POINTER, \"NULL [ref] pointer\");"); 735 $self->deindent; 736 $self->pidl("}"); 740 if ($l->{LEVEL_INDEX} > 0) { 741 $self->pidl("if ($var_name == NULL) {"); 742 $self->indent; 743 $self->pidl("return ndr_push_error($ndr, NDR_ERR_INVALID_POINTER, \"NULL [ref] pointer\");"); 744 $self->deindent; 745 $self->pidl("}"); 746 } 737 747 if ($l->{LEVEL} eq "EMBEDDED") { 738 $self->pidl("NDR_CHECK(ndr_push_ref_ptr(ndr)); ");748 $self->pidl("NDR_CHECK(ndr_push_ref_ptr(ndr)); /* $var_name */"); 739 749 } 740 750 } elsif ($l->{POINTER_TYPE} eq "relative") { … … 746 756 } elsif ($l->{POINTER_TYPE} eq "full") { 747 757 $self->pidl("NDR_CHECK(ndr_push_full_ptr($ndr, $var_name));"); 758 } elsif ($l->{POINTER_TYPE} eq "ignore") { 759 # We don't want this pointer to appear on the wire at all 760 $self->pidl("NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, 0));"); 748 761 } else { 749 762 die("Unhandled pointer type $l->{POINTER_TYPE}"); … … 805 818 806 819 return if (has_property($e, "noprint")); 820 my $cur_depth = 0; 821 my $ignore_depth = 0xFFFF; 807 822 808 823 if ($e->{REPRESENTATION_TYPE} ne $e->{TYPE}) { … … 818 833 819 834 foreach my $l (@{$e->{LEVELS}}) { 835 $cur_depth += 1; 836 837 if ($cur_depth > $ignore_depth) { 838 next; 839 } 840 820 841 if ($l->{TYPE} eq "POINTER") { 821 842 $self->pidl("ndr_print_ptr($ndr, \"$e->{NAME}\", $var_name);"); 843 if ($l->{POINTER_TYPE} eq "ignore") { 844 $self->pidl("/* [ignore] '$e->{NAME}' */"); 845 $ignore_depth = $cur_depth; 846 last; 847 } 822 848 $self->pidl("$ndr->depth++;"); 823 849 if ($l->{POINTER_TYPE} ne "ref") { … … 833 859 } 834 860 835 if ($l->{IS_ZERO_TERMINATED} ) {861 if ($l->{IS_ZERO_TERMINATED} and not defined($l->{LENGTH_IS})) { 836 862 $length = "ndr_string_length($var_name, sizeof(*$var_name))"; 837 863 } else { … … 852 878 $self->pidl("$ndr->print($ndr, \"\%s: ARRAY(\%d)\", \"$e->{NAME}\", (int)$length);"); 853 879 $self->pidl("$ndr->depth++;"); 854 $self->pidl("for ($counter =0;$counter<$length;$counter++) {");880 $self->pidl("for ($counter = 0; $counter < ($length); $counter++) {"); 855 881 $self->indent; 856 882 … … 867 893 868 894 foreach my $l (reverse @{$e->{LEVELS}}) { 895 $cur_depth -= 1; 896 897 if ($cur_depth > $ignore_depth) { 898 next; 899 } 900 869 901 if ($l->{TYPE} eq "POINTER") { 902 if ($l->{POINTER_TYPE} eq "ignore") { 903 next; 904 } 905 870 906 if ($l->{POINTER_TYPE} ne "ref") { 871 907 $self->deindent; … … 1007 1043 1008 1044 return undef unless ($l->{TYPE} eq "POINTER" or $l->{TYPE} eq "ARRAY"); 1045 return undef if (($l->{TYPE} eq "POINTER") and ($l->{POINTER_TYPE} eq "ignore")); 1009 1046 1010 1047 return undef unless ($l->{TYPE} ne "ARRAY" or ArrayDynamicallyAllocated($e,$l)); … … 1115 1152 1116 1153 # add additional constructions 1117 if ($l->{TYPE} eq "POINTER" and $deferred) { 1154 if ($l->{TYPE} eq "POINTER" and $l->{POINTER_TYPE} eq "ignore") { 1155 $self->pidl("/* [ignore] '$e->{NAME}' */"); 1156 } elsif ($l->{TYPE} eq "POINTER" and $deferred) { 1118 1157 if ($l->{POINTER_TYPE} ne "ref") { 1119 1158 $self->pidl("if ($var_name) {"); … … 1135 1174 1136 1175 if ($l->{POINTER_TYPE} ne "ref") { 1137 if ($l->{POINTER_TYPE} eq "relative" ) {1176 if ($l->{POINTER_TYPE} eq "relative" or $l->{POINTER_TYPE} eq "relative_short") { 1138 1177 $self->pidl("if ($ndr->offset > $ndr->relative_highest_offset) {"); 1139 1178 $self->indent; … … 1167 1206 } 1168 1207 1169 $self->pidl("for ($counter = 0; $counter < $length; $counter++) {");1208 $self->pidl("for ($counter = 0; $counter < ($length); $counter++) {"); 1170 1209 $self->indent; 1171 1210 $self->ParseElementPullLevel($e, $nl, $ndr, $var_name, $env, 1, 0); … … 1175 1214 1176 1215 if ($deferred and ContainsDeferred($e, $l)) { 1177 $self->pidl("for ($counter = 0; $counter < $length; $counter++) {");1216 $self->pidl("for ($counter = 0; $counter < ($length); $counter++) {"); 1178 1217 $self->indent; 1179 1218 $self->ParseElementPullLevel($e,GetNextLevel($e,$l), $ndr, $var_name, $env, 0, 1); … … 1256 1295 } elsif ($l->{POINTER_TYPE} eq "relative_short") { 1257 1296 $self->pidl("NDR_CHECK(ndr_pull_relative_ptr_short($ndr, &_ptr_$e->{NAME}));"); 1297 } elsif ($l->{POINTER_TYPE} eq "ignore") { 1298 #We want to consume the pointer bytes, but ignore the pointer value 1299 $self->pidl("NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &_ptr_$e->{NAME}));"); 1300 $self->pidl("_ptr_$e->{NAME} = 0;"); 1258 1301 } else { 1259 1302 die("Unhandled pointer type $l->{POINTER_TYPE}"); … … 1263 1306 $self->indent; 1264 1307 1265 # Don't do this for arrays, they're allocated at the actual level1266 # of the array1267 unless ($next_is_array or $next_is_string) {1268 $self->pidl("NDR_PULL_ALLOC($ndr, $var_name);");1308 if ($l->{POINTER_TYPE} eq "ignore") { 1309 # Don't do anything, we don't want to do the 1310 # allocation, as we forced it to NULL just above, and 1311 # we may not know the declared type anyway. 1269 1312 } else { 1270 # FIXME: Yes, this is nasty. 1271 # We allocate an array twice 1272 # - once just to indicate that it's there, 1273 # - then the real allocation... 1274 $self->pidl("NDR_PULL_ALLOC($ndr, $var_name);"); 1313 # Don't do this for arrays, they're allocated at the actual level 1314 # of the array 1315 unless ($next_is_array or $next_is_string) { 1316 $self->pidl("NDR_PULL_ALLOC($ndr, $var_name);"); 1317 } else { 1318 # FIXME: Yes, this is nasty. 1319 # We allocate an array twice 1320 # - once just to indicate that it's there, 1321 # - then the real allocation... 1322 $self->pidl("NDR_PULL_ALLOC($ndr, $var_name);"); 1323 } 1275 1324 } 1276 1325 … … 1285 1334 } 1286 1335 1336 sub CheckRefPtrs($$$$) 1337 { 1338 my ($self,$e,$ndr,$env) = @_; 1339 1340 return if ContainsPipe($e, $e->{LEVELS}[0]); 1341 return if ($e->{LEVELS}[0]->{TYPE} ne "POINTER"); 1342 return if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref"); 1343 1344 my $var_name = $env->{$e->{NAME}}; 1345 $var_name = append_prefix($e, $var_name); 1346 1347 $self->pidl("if ($var_name == NULL) {"); 1348 $self->indent; 1349 $self->pidl("return ndr_push_error($ndr, NDR_ERR_INVALID_POINTER, \"NULL [ref] pointer\");"); 1350 $self->deindent; 1351 $self->pidl("}"); 1352 } 1353 1287 1354 sub ParseStructPushPrimitives($$$$$) 1288 1355 { 1289 1356 my ($self, $struct, $ndr, $varname, $env) = @_; 1357 1358 $self->CheckRefPtrs($_, $ndr, $env) foreach (@{$struct->{ELEMENTS}}); 1290 1359 1291 1360 # see if the structure contains a conformant array. If it … … 1307 1376 $size = "ndr_string_length($varname->$e->{NAME}, sizeof(*$varname->$e->{NAME}))"; 1308 1377 } 1378 if (defined($e->{LEVELS}[0]->{SIZE_IS})) { 1379 $size = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e->{ORIGINAL}); 1380 } 1309 1381 } else { 1310 1382 $size = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e->{ORIGINAL}); … … 1357 1429 $self->start_flags($struct, $ndr); 1358 1430 1431 $self->pidl("NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);"); 1359 1432 $self->pidl("if (ndr_flags & NDR_SCALARS) {"); 1360 1433 $self->indent; … … 1610 1683 foreach my $l (@{$e->{LEVELS}}) { 1611 1684 my $mem_flags = $self->ParseMemCtxPullFlags($e, $l); 1685 1686 if (($l->{TYPE} eq "POINTER") and ($l->{POINTER_TYPE} eq "ignore")) { 1687 last; 1688 } 1689 1612 1690 if (defined($mem_flags)) { 1613 $self->pidl("TALLOC_CTX *_mem_save_$e->{NAME}_$l->{LEVEL_INDEX} ;");1691 $self->pidl("TALLOC_CTX *_mem_save_$e->{NAME}_$l->{LEVEL_INDEX} = NULL;"); 1614 1692 } 1615 1693 } … … 1674 1752 my $env = GenerateStructEnv($struct, $varname); 1675 1753 1754 $self->pidl("NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);"); 1676 1755 $self->pidl("if (ndr_flags & NDR_SCALARS) {"); 1677 1756 $self->indent; … … 1778 1857 } 1779 1858 $self->DeclareArrayVariables($el); 1780 $self->ParseElementPush($el, $ndr, {$el->{NAME} => "$varname->$el->{NAME}"}, 1, 0); 1859 my $el_env = {$el->{NAME} => "$varname->$el->{NAME}"}; 1860 $self->CheckRefPtrs($el, $ndr, $el_env); 1861 $self->ParseElementPush($el, $ndr, $el_env, 1, 0); 1781 1862 $self->deindent; 1782 1863 } … … 1837 1918 $self->start_flags($e, $ndr); 1838 1919 1920 $self->pidl("NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);"); 1839 1921 $self->pidl("if (ndr_flags & NDR_SCALARS) {"); 1840 1922 $self->indent; … … 2014 2096 $self->pidl("level = ndr_pull_get_switch_value($ndr, $varname);"); 2015 2097 2098 $self->pidl("NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);"); 2016 2099 $self->pidl("if (ndr_flags & NDR_SCALARS) {"); 2017 2100 $self->indent; … … 2296 2379 } 2297 2380 2381 $self->pidl("NDR_PUSH_CHECK_FN_FLAGS(ndr, flags);"); 2382 2298 2383 $self->pidl("if (flags & NDR_IN) {"); 2299 2384 $self->indent; … … 2302 2387 2303 2388 EnvSubstituteValue($env, $fn); 2389 2390 foreach my $e (@{$fn->{ELEMENTS}}) { 2391 if (grep(/in/,@{$e->{DIRECTION}})) { 2392 $self->CheckRefPtrs($e, $ndr, $env); 2393 } 2394 } 2304 2395 2305 2396 foreach my $e (@{$fn->{ELEMENTS}}) { … … 2316 2407 2317 2408 $env = GenerateFunctionOutEnv($fn); 2409 EnvSubstituteValue($env, $fn); 2410 2411 foreach my $e (@{$fn->{ELEMENTS}}) { 2412 if (grep(/out/,@{$e->{DIRECTION}})) { 2413 $self->CheckRefPtrs($e, $ndr, $env); 2414 } 2415 } 2416 2318 2417 foreach my $e (@{$fn->{ELEMENTS}}) { 2319 2418 if (grep(/out/,@{$e->{DIRECTION}})) { … … 2382 2481 $double_cases{"$e->{NAME}"} = 1; 2383 2482 } 2483 2484 $self->pidl("NDR_PULL_CHECK_FN_FLAGS(ndr, flags);"); 2384 2485 2385 2486 $self->pidl("if (flags & NDR_IN) {"); … … 2704 2805 my $name = uc $interface->{NAME}; 2705 2806 $self->pidl_hdr("#define NDR_$name\_UUID " . 2706 Parse::Pidl::Util::make_str(lc($interface->{PROPERTIES}->{uuid}))); 2707 2708 if(!defined $interface->{PROPERTIES}->{version}) { $interface->{PROPERTIES}->{version} = "0.0"; } 2709 $self->pidl_hdr("#define NDR_$name\_VERSION $interface->{PROPERTIES}->{version}"); 2807 Parse::Pidl::Util::make_str(lc($interface->{UUID}))); 2808 2809 $self->pidl_hdr("#define NDR_$name\_VERSION $interface->{VERSION}"); 2710 2810 2711 2811 $self->pidl_hdr("#define NDR_$name\_NAME \"$interface->{NAME}\""); -
vendor/current/pidl/lib/Parse/Pidl/Samba4/NDR/Server.pm
r740 r988 78 78 my $name = $interface->{NAME}; 79 79 my $uname = uc $name; 80 my $uuid = lc($interface->{ PROPERTIES}->{uuid});81 my $if_version = $interface->{ PROPERTIES}->{version};80 my $uuid = lc($interface->{UUID}); 81 my $if_version = $interface->{VERSION}; 82 82 83 83 pidl " … … 252 252 } 253 253 254 return false; 255 } 256 254 return false; 255 } 256 257 257 NTSTATUS dcerpc_server_$name\_init(void) 258 258 { … … 290 290 my $count = 0; 291 291 292 $res .= "NTSTATUS dcerpc_server_$interface->{NAME}\_init(void);\n"; 293 $res .= "\n"; 294 292 295 if (!defined $interface->{PROPERTIES}->{uuid}) { 293 296 return $res; … … 320 323 $res .= "/* server functions auto-generated by pidl */\n"; 321 324 $res .= "#include \"$header\"\n"; 325 $res .= "#include <util/debug.h>\n"; 322 326 $res .= "\n"; 323 327 -
vendor/current/pidl/lib/Parse/Pidl/Samba4/Python.pm
r740 r988 11 11 use strict; 12 12 use Parse::Pidl qw(warning fatal error); 13 use Parse::Pidl::Typelist qw(hasType resolveType getType mapTypeName expandAlias );13 use Parse::Pidl::Typelist qw(hasType resolveType getType mapTypeName expandAlias bitmap_type_fn enum_type_fn); 14 14 use Parse::Pidl::Util qw(has_property ParseExpr unmake_str); 15 15 use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsPipe is_charset_array); … … 23 23 sub new($) { 24 24 my ($class) = @_; 25 my $self = { res => "", res_hdr => "", tabs => "", constants => {}, 25 my $self = { res => "", res_hdr => "", tabs => "", 26 constants => [], constants_uniq => {}, 26 27 module_methods => [], module_objects => [], ready_types => [], 27 module_imports => {}, type_imports => {}, 28 module_imports => [], module_imports_uniq => {}, 29 type_imports => [], type_imports_uniq => {}, 28 30 patch_type_calls => [], prereadycode => [], 29 31 postreadycode => []}; … … 95 97 my ($self, $name, $type, $value) = @_; 96 98 97 $self->{constants}->{$name} = [$type, $value]; 99 unless (defined $self->{constants_uniq}->{$name}) { 100 my $h = {"key" => $name, "val" => [$type, $value]}; 101 push @{$self->{constants}}, $h; 102 $self->{constants_uniq}->{$name} = $h; 103 } 98 104 } 99 105 … … 107 113 $e =~ /^([A-Za-z0-9_]+)/; 108 114 my $cname = $1; 109 115 110 116 $self->register_constant($cname, $d, $cname); 111 117 } … … 201 207 $self->pidl("{"); 202 208 $self->indent; 203 $self->pidl("$cname *object = ($cname *)py _talloc_get_ptr(obj);");209 $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(obj);"); 204 210 $self->pidl("PyObject *py_$e->{NAME};"); 205 $self->ConvertObjectToPython("py _talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}", "return NULL;");211 $self->ConvertObjectToPython("pytalloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}", "return NULL;"); 206 212 $self->pidl("return py_$e->{NAME};"); 207 213 $self->deindent; … … 212 218 $self->pidl("{"); 213 219 $self->indent; 214 $self->pidl("$cname *object = ($cname *)py _talloc_get_ptr(py_obj);");215 my $mem_ctx = "py _talloc_get_mem_ctx(py_obj)";220 $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); 221 my $mem_ctx = "pytalloc_get_mem_ctx(py_obj)"; 216 222 my $l = $e->{LEVELS}[0]; 217 223 my $nl = GetNextLevel($e, $l); 218 if ($l->{TYPE} eq "POINTER" and 224 if ($l->{TYPE} eq "POINTER" and 219 225 not ($nl->{TYPE} eq "ARRAY" and ($nl->{IS_FIXED} or is_charset_array($e, $nl))) and 220 226 not ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE}))) { 221 $self->pidl("talloc_unlink( py_talloc_get_mem_ctx(py_obj), $varname);");227 $self->pidl("talloc_unlink($mem_ctx, discard_const($varname));"); 222 228 } 223 229 $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); … … 232 238 $self->indent; 233 239 foreach my $e (@{$d->{ELEMENTS}}) { 234 $self->pidl("{ discard_const_p(char, \"$e->{NAME}\"), py_$name\_get_$e->{NAME}, py_$name\_set_$e->{NAME} },"); 235 } 236 $self->pidl("{ NULL }"); 240 $self->pidl("{"); 241 $self->indent; 242 $self->pidl(".name = discard_const_p(char, \"$e->{NAME}\"),"); 243 $self->pidl(".get = py_$name\_get_$e->{NAME},"); 244 $self->pidl(".set = py_$name\_set_$e->{NAME},"); 245 $self->pidl(".doc = discard_const_p(char, \"PIDL-generated element $e->{NAME}\")"); 246 $self->deindent; 247 $self->pidl("},"); 248 } 249 $self->pidl("{ .name = NULL }"); 237 250 $self->deindent; 238 251 $self->pidl("};"); … … 243 256 $self->pidl("{"); 244 257 $self->indent; 245 $self->pidl("return py _talloc_new($cname, type);");258 $self->pidl("return pytalloc_new($cname, type);"); 246 259 $self->deindent; 247 260 $self->pidl("}"); … … 250 263 my $py_methods = "NULL"; 251 264 252 # If the struct is not public there ndr_pull/ndr_push functions will 265 # If the struct is not public there ndr_pull/ndr_push functions will 253 266 # be static so not callable from here 254 267 if (has_property($d, "public")) { … … 256 269 $self->pidl("{"); 257 270 $self->indent; 258 $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);"); 271 $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); 272 $self->pidl("PyObject *ret = NULL;"); 259 273 $self->pidl("DATA_BLOB blob;"); 260 274 $self->pidl("enum ndr_err_code err;"); 261 $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_push_flags_fn_t)ndr_push_$name);"); 275 $self->pidl("TALLOC_CTX *tmp_ctx = talloc_new(pytalloc_get_mem_ctx(py_obj));"); 276 $self->pidl("if (tmp_ctx == NULL) {"); 277 $self->indent; 278 $self->pidl("PyErr_SetNdrError(NDR_ERR_ALLOC);"); 279 $self->pidl("return NULL;"); 280 $self->deindent; 281 $self->pidl("}"); 282 $self->pidl("err = ndr_push_struct_blob(&blob, tmp_ctx, object, (ndr_push_flags_fn_t)ndr_push_$name);"); 262 283 $self->pidl("if (err != NDR_ERR_SUCCESS) {"); 263 284 $self->indent; 285 $self->pidl("TALLOC_FREE(tmp_ctx);"); 264 286 $self->pidl("PyErr_SetNdrError(err);"); 265 287 $self->pidl("return NULL;"); … … 267 289 $self->pidl("}"); 268 290 $self->pidl(""); 269 $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); 270 $self->deindent; 271 $self->pidl("}"); 272 $self->pidl(""); 273 274 $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); 291 $self->pidl("ret = PyString_FromStringAndSize((char *)blob.data, blob.length);"); 292 $self->pidl("TALLOC_FREE(tmp_ctx);"); 293 $self->pidl("return ret;"); 294 $self->deindent; 295 $self->pidl("}"); 296 $self->pidl(""); 297 298 $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args, PyObject *kwargs)"); 275 299 $self->pidl("{"); 276 300 $self->indent; 277 $self->pidl("$cname *object = ($cname *)py _talloc_get_ptr(py_obj);");301 $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); 278 302 $self->pidl("DATA_BLOB blob;"); 303 $self->pidl("Py_ssize_t blob_length = 0;"); 279 304 $self->pidl("enum ndr_err_code err;"); 280 $self->pidl("if (!PyArg_ParseTuple(args, \"s#:__ndr_unpack__\", &blob.data, &blob.length))"); 281 $self->pidl("\treturn NULL;"); 282 $self->pidl(""); 283 $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); 305 $self->pidl("const char * const kwnames[] = { \"data_blob\", \"allow_remaining\", NULL };"); 306 $self->pidl("PyObject *allow_remaining_obj = NULL;"); 307 $self->pidl("bool allow_remaining = false;"); 308 $self->pidl(""); 309 $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s#|O:__ndr_unpack__\","); 310 $self->indent; 311 $self->pidl("discard_const_p(char *, kwnames),"); 312 $self->pidl("&blob.data, &blob_length,"); 313 $self->pidl("&allow_remaining_obj)) {"); 314 $self->deindent; 315 $self->indent; 316 $self->pidl("return NULL;"); 317 $self->deindent; 318 $self->pidl("}"); 319 $self->pidl("blob.length = blob_length;"); 320 $self->pidl(""); 321 $self->pidl("if (allow_remaining_obj && PyObject_IsTrue(allow_remaining_obj)) {"); 322 $self->indent; 323 $self->pidl("allow_remaining = true;"); 324 $self->deindent; 325 $self->pidl("}"); 326 $self->pidl(""); 327 $self->pidl("if (allow_remaining) {"); 328 $self->indent; 329 $self->pidl("err = ndr_pull_struct_blob(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); 330 $self->deindent; 331 $self->pidl("} else {"); 332 $self->indent; 333 $self->pidl("err = ndr_pull_struct_blob_all(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); 334 $self->deindent; 335 $self->pidl("}"); 284 336 $self->pidl("if (err != NDR_ERR_SUCCESS) {"); 285 337 $self->indent; … … 297 349 $self->pidl("{"); 298 350 $self->indent; 299 $self->pidl("$cname *object = ($cname *)py _talloc_get_ptr(py_obj);");351 $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); 300 352 $self->pidl("PyObject *ret;"); 301 353 $self->pidl("char *retstr;"); 302 354 $self->pidl(""); 303 $self->pidl("retstr = ndr_print_struct_string(py _talloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_$name, \"$name\", object);");355 $self->pidl("retstr = ndr_print_struct_string(pytalloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_$name, \"$name\", object);"); 304 356 $self->pidl("ret = PyString_FromString(retstr);"); 305 357 $self->pidl("talloc_free(retstr);"); … … 314 366 $self->indent; 315 367 $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.ndr_pack(object) -> blob\\nNDR pack\" },"); 316 $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS , \"S.ndr_unpack(class, blob) -> None\\nNDR unpack\" },");368 $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS|METH_KEYWORDS, \"S.ndr_unpack(class, blob, allow_remaining=False) -> None\\nNDR unpack\" },"); 317 369 $self->pidl("{ \"__ndr_print__\", (PyCFunction)py_$name\_ndr_print, METH_VARARGS, \"S.ndr_print(object) -> None\\nNDR print\" },"); 318 370 $self->pidl("{ NULL, NULL, 0, NULL }"); … … 322 374 } 323 375 324 $self->pidl_hdr("static forwardPyTypeObject $name\_Type;\n");376 $self->pidl_hdr("static PyTypeObject $name\_Type;\n"); 325 377 $self->pidl(""); 326 378 my $docstring = $self->DocString($d, $name); … … 336 388 $self->pidl(".tp_methods = $py_methods,"); 337 389 $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); 338 $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),");339 390 $self->pidl(".tp_new = py_$name\_new,"); 340 391 $self->deindent; … … 343 394 $self->pidl(""); 344 395 345 my $talloc_typename = $self->import_type_variable("talloc", "Object"); 346 $self->register_module_prereadycode(["$name\_Type.tp_base = $talloc_typename;", ""]); 396 my $talloc_typename = $self->import_type_variable("talloc", "BaseObject"); 397 $self->register_module_prereadycode(["$name\_Type.tp_base = $talloc_typename;", 398 "$name\_Type.tp_basicsize = pytalloc_BaseObject_size();", 399 ""]); 347 400 348 401 return "&$typeobject"; … … 372 425 foreach my $dir (@{$e->{DIRECTION}}) { 373 426 my $main = get_metadata_var($e); 374 if ($main) { 375 $metadata_args->{$dir}->{$main} = $e->{NAME}; 427 if ($main) { 428 $metadata_args->{$dir}->{$main} = $e->{NAME}; 376 429 } 377 430 } … … 399 452 foreach my $e (@{$fn->{ELEMENTS}}) { 400 453 next unless (grep(/out/,@{$e->{DIRECTION}})); 401 next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or 454 next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or 402 455 ($metadata_args->{out}->{$e->{NAME}}) and grep(/out/, @{$e->{DIRECTION}})); 403 456 $self->pidl("PyObject *py_$e->{NAME};"); … … 482 535 foreach my $e (@{$fn->{ELEMENTS}}) { 483 536 next unless (grep(/in/,@{$e->{DIRECTION}})); 484 next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or 537 next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or 485 538 ($metadata_args->{out}->{$e->{NAME}}) and grep(/out/, @{$e->{DIRECTION}})); 486 539 $self->pidl("PyObject *py_$e->{NAME};"); … … 612 665 if ($actual_ctype->{TYPE} eq "UNION" and defined($actual_ctype->{ELEMENTS})) { 613 666 $self->pidl("PyObject *py_import_$d->{NAME}(TALLOC_CTX *mem_ctx, int level, " .mapTypeName($d) . " *in)"); 667 $self->pidl_hdr("PyObject *py_import_$d->{NAME}(TALLOC_CTX *mem_ctx, int level, " .mapTypeName($d) . " *in);\n"); 614 668 $self->pidl("{"); 615 669 $self->indent; … … 620 674 621 675 $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, int level, PyObject *in)"); 676 $self->pidl_hdr(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, int level, PyObject *in);\n"); 622 677 $self->pidl("{"); 623 678 $self->indent; … … 658 713 659 714 if (defined $interface->{PROPERTIES}->{uuid}) { 660 $self->pidl_hdr("static forwardPyTypeObject $interface->{NAME}_InterfaceType;\n");715 $self->pidl_hdr("static PyTypeObject $interface->{NAME}_InterfaceType;\n"); 661 716 $self->pidl(""); 662 717 … … 704 759 $self->deindent; 705 760 $self->pidl("}"); 706 707 $self->pidl(""); 708 709 my $signature = 761 762 $self->pidl(""); 763 764 my $signature = 710 765 "\"$interface->{NAME}(binding, lp_ctx=None, credentials=None) -> connection\\n\" 711 766 \"\\n\" … … 741 796 $self->register_module_prereadycode(["$if_typename.tp_base = $dcerpc_typename;", ""]); 742 797 $self->register_module_postreadycode(["if (!PyInterface_AddNdrRpcMethods(&$if_typename, py_ndr_$interface->{NAME}\_methods))", "\treturn;", ""]); 798 799 800 $self->pidl("static PyObject *syntax_$interface->{NAME}_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)"); 801 $self->pidl("{"); 802 $self->indent; 803 $self->pidl("return py_dcerpc_syntax_init_helper(type, args, kwargs, &ndr_table_$interface->{NAME}.syntax_id);"); 804 $self->deindent; 805 $self->pidl("}"); 806 807 $self->pidl(""); 808 809 my $signature = "\"abstract_syntax()\\n\""; 810 811 my $docstring = $self->DocString($interface, $interface->{NAME}."_syntax"); 812 813 if ($docstring) { 814 $docstring = "$signature$docstring"; 815 } else { 816 $docstring = $signature; 817 } 818 819 my $syntax_typename = "$interface->{NAME}_SyntaxType"; 820 821 $self->pidl("static PyTypeObject $syntax_typename = {"); 822 $self->indent; 823 $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); 824 $self->pidl(".tp_name = \"$basename.$interface->{NAME}\","); 825 $self->pidl(".tp_doc = $docstring,"); 826 $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); 827 $self->pidl(".tp_new = syntax_$interface->{NAME}_new,"); 828 $self->deindent; 829 $self->pidl("};"); 830 831 $self->pidl(""); 832 833 $self->register_module_typeobject("abstract_syntax", "&$syntax_typename"); 834 my $ndr_typename = $self->import_type_variable("samba.dcerpc.misc", "ndr_syntax_id"); 835 $self->register_module_prereadycode(["$syntax_typename.tp_base = $ndr_typename;", 836 "$syntax_typename.tp_basicsize = pytalloc_BaseObject_size();", 837 ""]); 743 838 } 744 839 … … 778 873 $var_name = "dep_$var_name"; 779 874 780 $self->{module_imports}->{$var_name} = $module_path; 781 875 unless (defined $self->{module_imports_uniq}->{$var_name}) { 876 my $h = { "key" => $var_name, "val" => $module_path}; 877 push @{$self->{module_imports}}, $h; 878 $self->{module_imports_uniq}->{$var_name} = $h; 879 } 782 880 return $var_name; 783 881 } … … 788 886 789 887 $self->register_module_import($module); 790 unless (defined($self->{type_imports}->{$name})) { 791 $self->{type_imports}->{$name} = $module; 888 unless (defined $self->{type_imports_uniq}->{$name}) { 889 my $h = { "key" => $name, "val" => $module}; 890 push @{$self->{type_imports}}, $h; 891 $self->{type_imports_uniq}->{$name} = $h; 792 892 } 793 893 return "$name\_Type"; … … 797 897 { 798 898 my ($self, $orig_ctype) = @_; 799 # FIXME: Have a global lookup table for types that look different on the 899 # FIXME: Have a global lookup table for types that look different on the 800 900 # wire than they are named in C? 801 if ($orig_ctype->{NAME} eq "dom_sid2" or $orig_ctype->{NAME} eq "dom_sid28") { 901 if ($orig_ctype->{NAME} eq "dom_sid2" or 902 $orig_ctype->{NAME} eq "dom_sid28" or 903 $orig_ctype->{NAME} eq "dom_sid0") { 802 904 $orig_ctype->{NAME} = "dom_sid"; 803 905 } 906 if ($orig_ctype->{NAME} eq "spoolss_security_descriptor") { 907 $orig_ctype->{NAME} = "security_descriptor"; 908 } 909 804 910 my $ctype = resolveType($orig_ctype); 805 911 unless (defined($ctype->{BASEFILE})) { … … 868 974 } 869 975 870 if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP") { 976 # We need to cover ENUMs, BITMAPS and SCALAR values here, as 977 # all could otherwise be assigned invalid integer values 978 my $ctype_alias = ""; 979 my $uint_max = ""; 980 if ($actual_ctype->{TYPE} eq "ENUM") { 981 # Importantly, ENUM values are unsigned in pidl, and 982 # typically map to uint32 983 $ctype_alias = enum_type_fn($actual_ctype); 984 } elsif ($actual_ctype->{TYPE} eq "BITMAP") { 985 $ctype_alias = bitmap_type_fn($actual_ctype); 986 } elsif ($actual_ctype->{TYPE} eq "SCALAR") { 987 $ctype_alias = expandAlias($actual_ctype->{NAME}); 988 } 989 990 # This is the unsigned Python Integer -> C integer validation 991 # case. The signed case is below. 992 if ($ctype_alias =~ /^(uint[0-9]*|hyper|udlong|udlongr 993 |NTTIME_hyper|NTTIME|NTTIME_1sec 994 |uid_t|gid_t)$/x) { 995 $self->pidl("{"); 996 $self->indent; 997 $self->pidl("const unsigned long long uint_max = ndr_sizeof2uintmax(sizeof($target));"); 871 998 $self->pidl("if (PyLong_Check($cvar)) {"); 872 999 $self->indent; 873 $self->pidl("$target = PyLong_AsLongLong($cvar);"); 1000 $self->pidl("unsigned long long test_var;"); 1001 $self->pidl("test_var = PyLong_AsUnsignedLongLong($cvar);"); 1002 $self->pidl("if (PyErr_Occurred() != NULL) {"); 1003 $self->indent; 1004 $self->pidl($fail); 1005 $self->deindent; 1006 $self->pidl("}"); 1007 $self->pidl("if (test_var > uint_max) {"); 1008 $self->indent; 1009 $self->pidl("PyErr_Format(PyExc_OverflowError, \"Expected type %s or %s within range 0 - %llu, got %llu\",\\"); 1010 $self->pidl(" PyInt_Type.tp_name, PyLong_Type.tp_name, uint_max, test_var);"); 1011 $self->pidl($fail); 1012 $self->deindent; 1013 $self->pidl("}"); 1014 $self->pidl("$target = test_var;"); 874 1015 $self->deindent; 875 1016 $self->pidl("} else if (PyInt_Check($cvar)) {"); 876 1017 $self->indent; 877 $self->pidl("$target = PyInt_AsLong($cvar);"); 1018 $self->pidl("long test_var;"); 1019 $self->pidl("test_var = PyInt_AsLong($cvar);"); 1020 $self->pidl("if (test_var < 0 || test_var > uint_max) {"); 1021 $self->indent; 1022 $self->pidl("PyErr_Format(PyExc_OverflowError, \"Expected type %s or %s within range 0 - %llu, got %ld\",\\"); 1023 $self->pidl(" PyInt_Type.tp_name, PyLong_Type.tp_name, uint_max, test_var);"); 1024 $self->pidl($fail); 1025 $self->deindent; 1026 $self->pidl("}"); 1027 $self->pidl("$target = test_var;"); 878 1028 $self->deindent; 879 1029 $self->pidl("} else {"); … … 884 1034 $self->deindent; 885 1035 $self->pidl("}"); 1036 $self->deindent; 1037 $self->pidl("}"); 886 1038 return; 887 1039 } 888 if ($actual_ctype->{TYPE} eq "SCALAR" ) { 889 if (expandAlias($actual_ctype->{NAME}) =~ /^(u?int64|hyper|dlong|udlong|udlongr|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) { 890 $self->pidl("if (PyLong_Check($cvar)) {"); 891 $self->indent; 892 $self->pidl("$target = PyLong_AsLongLong($cvar);"); 893 $self->deindent; 894 $self->pidl("} else if (PyInt_Check($cvar)) {"); 895 $self->indent; 896 $self->pidl("$target = PyInt_AsLong($cvar);"); 897 $self->deindent; 898 $self->pidl("} else {"); 899 $self->indent; 900 $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type %s or %s\",\\"); 901 $self->pidl(" PyInt_Type.tp_name, PyLong_Type.tp_name);"); 902 $self->pidl($fail); 903 $self->deindent; 904 $self->pidl("}"); 905 return; 906 } 907 if (expandAlias($actual_ctype->{NAME}) =~ /^(char|u?int[0-9]*|time_t|uid_t|gid_t)$/) { 908 $self->pidl("PY_CHECK_TYPE(&PyInt_Type, $cvar, $fail);"); 909 $self->pidl("$target = PyInt_AsLong($cvar);"); 910 return; 911 } 1040 1041 # Confirm the signed python integer fits in the C type 1042 # correctly. It is subtly different from the unsigned case 1043 # above, so while it looks like a duplicate, it is not 1044 # actually a duplicate. 1045 if ($ctype_alias =~ /^(dlong|char|int[0-9]*|time_t)$/x) { 1046 $self->pidl("{"); 1047 $self->indent; 1048 $self->pidl("const long long int_max = ndr_sizeof2intmax(sizeof($target));"); 1049 $self->pidl("const long long int_min = -int_max - 1;"); 1050 $self->pidl("if (PyLong_Check($cvar)) {"); 1051 $self->indent; 1052 $self->pidl("long long test_var;"); 1053 $self->pidl("test_var = PyLong_AsLongLong($cvar);"); 1054 $self->pidl("if (PyErr_Occurred() != NULL) {"); 1055 $self->indent; 1056 $self->pidl($fail); 1057 $self->deindent; 1058 $self->pidl("}"); 1059 $self->pidl("if (test_var < int_min || test_var > int_max) {"); 1060 $self->indent; 1061 $self->pidl("PyErr_Format(PyExc_OverflowError, \"Expected type %s or %s within range %lld - %lld, got %lld\",\\"); 1062 $self->pidl(" PyInt_Type.tp_name, PyLong_Type.tp_name, int_min, int_max, test_var);"); 1063 $self->pidl($fail); 1064 $self->deindent; 1065 $self->pidl("}"); 1066 $self->pidl("$target = test_var;"); 1067 $self->deindent; 1068 $self->pidl("} else if (PyInt_Check($cvar)) {"); 1069 $self->indent; 1070 $self->pidl("long test_var;"); 1071 $self->pidl("test_var = PyInt_AsLong($cvar);"); 1072 $self->pidl("if (test_var < int_min || test_var > int_max) {"); 1073 $self->indent; 1074 $self->pidl("PyErr_Format(PyExc_OverflowError, \"Expected type %s or %s within range %lld - %lld, got %ld\",\\"); 1075 $self->pidl(" PyInt_Type.tp_name, PyLong_Type.tp_name, int_min, int_max, test_var);"); 1076 $self->pidl($fail); 1077 $self->deindent; 1078 $self->pidl("}"); 1079 $self->pidl("$target = test_var;"); 1080 $self->deindent; 1081 $self->pidl("} else {"); 1082 $self->indent; 1083 $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type %s or %s\",\\"); 1084 $self->pidl(" PyInt_Type.tp_name, PyLong_Type.tp_name);"); 1085 $self->pidl($fail); 1086 $self->deindent; 1087 $self->pidl("}"); 1088 $self->deindent; 1089 $self->pidl("}"); 1090 return; 912 1091 } 913 1092 … … 920 1099 } 921 1100 $self->pidl("PY_CHECK_TYPE($ctype_name, $cvar, $fail);"); 922 $self->pidl("if (talloc_reference($mem_ctx, py _talloc_get_mem_ctx($cvar)) == NULL) {");1101 $self->pidl("if (talloc_reference($mem_ctx, pytalloc_get_mem_ctx($cvar)) == NULL) {"); 923 1102 $self->indent; 924 1103 $self->pidl("PyErr_NoMemory();"); … … 926 1105 $self->deindent; 927 1106 $self->pidl("}"); 928 $self->assign($target, "(".mapTypeName($ctype)." *)py _talloc_get_ptr($cvar)");1107 $self->assign($target, "(".mapTypeName($ctype)." *)pytalloc_get_ptr($cvar)"); 929 1108 return; 930 1109 } … … 935 1114 } 936 1115 937 if ($actual_ctype->{TYPE} eq "SCALAR" and 1116 if ($actual_ctype->{TYPE} eq "SCALAR" and 938 1117 ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string" or $actual_ctype->{NAME} eq "nbt_name" or $actual_ctype->{NAME} eq "wrepl_nbt_name")) { 939 1118 $self->pidl("$target = talloc_strdup($mem_ctx, PyString_AS_STRING($cvar));"); … … 973 1152 if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") { 974 1153 $self->pidl("$target = W_ERROR(PyInt_AsLong($cvar));"); 1154 return; 1155 } 1156 1157 if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "HRESULT") { 1158 $self->pidl("$target = HRES_ERROR(PyInt_AsLong($cvar));"); 975 1159 return; 976 1160 } … … 1060 1244 $self->pidl("if (!$var_name) { $fail; }"); 1061 1245 $self->pidl("talloc_set_name_const($var_name, \"ARRAY: $var_name\");"); 1246 } else { 1247 $self->pidl("if (ARRAY_SIZE($var_name) != PyList_GET_SIZE($py_var)) {"); 1248 $self->indent; 1249 $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected list of type %s, length %zu, got %zd\", Py_TYPE($py_var)->tp_name, ARRAY_SIZE($var_name), PyList_GET_SIZE($py_var));"); 1250 $self->pidl("$fail"); 1251 $self->deindent; 1252 $self->pidl("}"); 1062 1253 } 1063 1254 $self->pidl("for ($counter = 0; $counter < PyList_GET_SIZE($py_var); $counter++) {"); … … 1109 1300 $ctypename = expandAlias($ctypename); 1110 1301 1111 if ($ctypename =~ /^(u?int64|hyper|dlong|udlong|udlongr|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) { 1112 return "PyLong_FromLongLong($cvar)"; 1113 } 1114 1115 if ($ctypename =~ /^(char|u?int[0-9]*|time_t|uid_t|gid_t)$/) { 1302 if ($ctypename =~ /^(int64|dlong)$/) { 1303 return "ndr_PyLong_FromLongLong($cvar)"; 1304 } 1305 1306 if ($ctypename =~ /^(uint64|hyper|NTTIME_hyper|NTTIME|NTTIME_1sec|udlong|udlongr|uid_t|gid_t)$/) { 1307 return "ndr_PyLong_FromUnsignedLongLong($cvar)"; 1308 } 1309 1310 if ($ctypename =~ /^(char|int|int8|int16|int32|time_t)$/) { 1116 1311 return "PyInt_FromLong($cvar)"; 1312 } 1313 1314 # Needed to ensure unsigned values in a 32 or 16 bit enum is 1315 # cast correctly to a uint32_t, not sign extended to a a 1316 # possibly 64 bit unsigned long. (enums are signed in C, 1317 # unsigned in NDR) 1318 if ($ctypename =~ /^(uint32|uint3264)$/) { 1319 return "ndr_PyLong_FromUnsignedLongLong((uint32_t)$cvar)"; 1320 } 1321 1322 if ($ctypename =~ /^(uint|uint8|uint16|uint1632)$/) { 1323 return "PyInt_FromLong((uint16_t)$cvar)"; 1117 1324 } 1118 1325 … … 1129 1336 } 1130 1337 1338 if ($ctypename eq "HRESULT") { 1339 return "PyErr_FromHRESULT($cvar)"; 1340 } 1341 1131 1342 if (($ctypename eq "string" or $ctypename eq "nbt_string" or $ctypename eq "nbt_name" or $ctypename eq "wrepl_nbt_name")) { 1132 1343 return "PyString_FromStringOrNULL($cvar)"; … … 1138 1349 1139 1350 # Not yet supported 1140 if ($ctypename eq "string_array") { return " PyCObject_FromTallocPtr($cvar)"; }1351 if ($ctypename eq "string_array") { return "pytalloc_CObject_FromTallocPtr($cvar)"; } 1141 1352 if ($ctypename eq "ipv4address") { return "PyString_FromStringOrNULL($cvar)"; } 1142 1353 if ($ctypename eq "ipv6address") { return "PyString_FromStringOrNULL($cvar)"; } … … 1144 1355 if ($ctypename eq "dnsp_string") { return "PyString_FromStringOrNULL($cvar)"; } 1145 1356 if ($ctypename eq "pointer") { 1146 return " PyCObject_FromTallocPtr($cvar)";1357 return "pytalloc_CObject_FromTallocPtr($cvar)"; 1147 1358 } 1148 1359 … … 1161 1372 if ($actual_ctype->{TYPE} eq "TYPEDEF") { 1162 1373 $actual_ctype = $actual_ctype->{DATA}; 1163 } 1164 1374 } 1375 1165 1376 if ($actual_ctype->{TYPE} eq "ENUM") { 1166 1377 return $self->ConvertScalarToPython(Parse::Pidl::Typelist::enum_type_fn($actual_ctype), $cvar); … … 1177 1388 return "NULL"; # FIXME! 1178 1389 } 1179 return "py _talloc_reference_ex($ctype_name, $mem_ctx, $cvar)";1390 return "pytalloc_reference_ex($ctype_name, $mem_ctx, $cvar)"; 1180 1391 } 1181 1392 … … 1255 1466 my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; 1256 1467 $self->pidl("int $counter;"); 1257 $self->pidl("for ($counter = 0; $counter < $length; $counter++) {");1468 $self->pidl("for ($counter = 0; $counter < ($length); $counter++) {"); 1258 1469 $self->indent; 1259 1470 my $member_var = "py_$e->{NAME}_$l->{LEVEL_INDEX}"; … … 1300 1511 $self->pidl_hdr(" 1301 1512 /* Python wrapper functions auto-generated by pidl */ 1513 #define PY_SSIZE_T_CLEAN 1 /* We use Py_ssize_t for PyArg_ParseTupleAndKeywords */ 1302 1514 #include <Python.h> 1303 1515 #include \"includes.h\" … … 1308 1520 #include \"$ndr_hdr\" 1309 1521 1522 /* 1523 * These functions are here to ensure they can be optomised out by 1524 * the compiler based on the constant input values 1525 */ 1526 1527 static inline unsigned long long ndr_sizeof2uintmax(size_t var_size) 1528 { 1529 switch (var_size) { 1530 case 8: 1531 return UINT64_MAX; 1532 case 4: 1533 return UINT32_MAX; 1534 case 2: 1535 return UINT16_MAX; 1536 case 1: 1537 return UINT8_MAX; 1538 } 1539 1540 return 0; 1541 } 1542 1543 static inline long long ndr_sizeof2intmax(size_t var_size) 1544 { 1545 switch (var_size) { 1546 case 8: 1547 return INT64_MAX; 1548 case 4: 1549 return INT32_MAX; 1550 case 2: 1551 return INT16_MAX; 1552 case 1: 1553 return INT8_MAX; 1554 } 1555 1556 return 0; 1557 } 1558 1559 static inline PyObject *ndr_PyLong_FromLongLong(long long v) 1560 { 1561 if (v > LONG_MAX || v < LONG_MIN) { 1562 return PyLong_FromLongLong(v); 1563 } else { 1564 return PyInt_FromLong(v); 1565 } 1566 } 1567 1568 static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v) 1569 { 1570 if (v > LONG_MAX) { 1571 return PyLong_FromUnsignedLongLong(v); 1572 } else { 1573 return PyInt_FromLong(v); 1574 } 1575 } 1576 1310 1577 "); 1311 1578 … … 1314 1581 ($x->{TYPE} eq "INTERFACE") && $self->Interface($x, $basename); 1315 1582 } 1316 1583 1317 1584 $self->pidl("static PyMethodDef $basename\_methods[] = {"); 1318 1585 $self->indent; … … 1333 1600 $self->indent; 1334 1601 $self->pidl("PyObject *m;"); 1335 foreach (keys %{$self->{module_imports}}) {1336 $self->pidl("PyObject *$ _;");1602 foreach my $h (@{$self->{module_imports}}) { 1603 $self->pidl("PyObject *$h->{'key'};"); 1337 1604 } 1338 1605 $self->pidl(""); 1339 1606 1340 foreach (keys %{$self->{module_imports}}) {1341 my $var_name = $ _;1342 my $module_path = $ self->{module_imports}->{$var_name};1607 foreach my $h (@{$self->{module_imports}}) { 1608 my $var_name = $h->{'key'}; 1609 my $module_path = $h->{'val'}; 1343 1610 $self->pidl("$var_name = PyImport_ImportModule(\"$module_path\");"); 1344 1611 $self->pidl("if ($var_name == NULL)"); … … 1347 1614 } 1348 1615 1349 foreach (keys %{$self->{type_imports}}) {1350 my $type_var = "$ _\_Type";1351 my $module_path = $ self->{type_imports}->{$_};1616 foreach my $h (@{$self->{type_imports}}) { 1617 my $type_var = "$h->{'key'}\_Type"; 1618 my $module_path = $h->{'val'}; 1352 1619 $self->pidl_hdr("static PyTypeObject *$type_var;\n"); 1353 my $pretty_name = PrettifyTypeName($ _, $module_path);1620 my $pretty_name = PrettifyTypeName($h->{'key'}, $module_path); 1354 1621 my $module_var = "dep_$module_path"; 1355 1622 $module_var =~ s/\./_/g; … … 1382 1649 $self->pidl("\treturn;"); 1383 1650 $self->pidl(""); 1384 foreach my $name (keys %{$self->{constants}}) { 1651 foreach my $h (@{$self->{constants}}) { 1652 my $name = $h->{'key'}; 1385 1653 my $py_obj; 1386 my ($ctype, $cvar) = @{$ self->{constants}->{$name}};1654 my ($ctype, $cvar) = @{$h->{'val'}}; 1387 1655 if ($cvar =~ /^[0-9]+$/ or $cvar =~ /^0x[0-9a-fA-F]+$/) { 1388 $py_obj = " PyInt_FromLong($cvar)";1656 $py_obj = "ndr_PyLong_FromUnsignedLongLong($cvar)"; 1389 1657 } elsif ($cvar =~ /^".*"$/) { 1390 1658 $py_obj = "PyString_FromString($cvar)"; -
vendor/current/pidl/lib/Parse/Pidl/Samba4/Template.pm
r414 r988 8 8 use vars qw($VERSION); 9 9 $VERSION = '0.01'; 10 11 use Parse::Pidl::Util qw(genpad); 10 12 11 13 use strict; … … 21 23 my $name = $interface->{NAME}; 22 24 23 $res .= 24 "/* 25 $res .= 26 "/* 25 27 Unix SMB/CIFS implementation. 26 28 … … 28 30 29 31 Copyright (C) YOUR NAME HERE YEAR 30 32 31 33 This program is free software; you can redistribute it and/or modify 32 34 it under the terms of the GNU General Public License as published by 33 35 the Free Software Foundation; either version 3 of the License, or 34 36 (at your option) any later version. 35 37 36 38 This program is distributed in the hope that it will be useful, 37 39 but WITHOUT ANY WARRANTY; without even the implied warranty of 38 40 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 39 41 GNU General Public License for more details. 40 42 41 43 You should have received a copy of the GNU General Public License 42 44 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 53 55 if ($d->{TYPE} eq "FUNCTION") { 54 56 my $fname = $d->{NAME}; 57 my $pad = genpad("static $d->{RETURN_TYPE} dcesrv_$fname"); 55 58 $res .= 56 59 " 57 /* 58 $fname 60 /* 61 $fname 59 62 */ 60 static $d->{RETURN_TYPE} dcesrv_$fname(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, 61 struct $fname *r) 63 64 static $d->{RETURN_TYPE} dcesrv_$fname(struct dcesrv_call_state *dce_call, 65 $pad"."TALLOC_CTX *mem_ctx, 66 $pad"."struct $fname *r) 62 67 { 63 68 "; … … 75 80 } 76 81 77 $res .= 82 $res .= 78 83 " 79 84 /* include the generated boilerplate */ … … 90 95 $res = ""; 91 96 foreach my $x (@{$idl}) { 92 ($x->{TYPE} eq "INTERFACE") && 97 ($x->{TYPE} eq "INTERFACE") && 93 98 Template($x); 94 99 } -
vendor/current/pidl/lib/Parse/Pidl/Typelist.pm
r740 r988 61 61 "NTTIME_hyper" => "NTTIME", 62 62 "WERROR" => "WERROR", 63 "HRESULT" => "HRESULT", 63 64 "NTSTATUS" => "NTSTATUS", 64 65 "COMRESULT" => "COMRESULT", … … 84 85 "short" => "int16", 85 86 "HYPER_T" => "hyper", 86 "HRESULT" => "COMRESULT",87 "mode_t" => "uint32", 87 88 ); 88 89 -
vendor/current/pidl/lib/Parse/Pidl/Util.pm
r414 r988 7 7 require Exporter; 8 8 @ISA = qw(Exporter); 9 @EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str unmake_str print_uuid MyDumper );9 @EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str unmake_str print_uuid MyDumper genpad); 10 10 use vars qw($VERSION); 11 11 $VERSION = '0.01'; … … 44 44 { 45 45 require Data::Dumper; 46 $Data::Dumper::Sortkeys = 1; 46 47 my $s = shift; 47 48 return Data::Dumper::Dumper($s); … … 176 177 } 177 178 179 =item B<genpad> 180 return an empty string consisting of tabs and spaces suitable for proper indent 181 of C-functions. 182 183 =cut 184 sub genpad($) 185 { 186 my ($s) = @_; 187 my $nt = int((length($s)+1)/8); 188 my $lt = ($nt*8)-1; 189 my $ns = (length($s)-$lt); 190 return "\t"x($nt)." "x($ns); 191 } 192 178 193 =back 179 194 -
vendor/current/pidl/lib/Parse/Pidl/Wireshark/Conformance.pm
r740 r988 22 22 Conformance files are simple text files with a single command on each line. 23 23 Empty lines and lines starting with a '#' character are ignored. 24 Arguments to commands are sep erated by spaces.24 Arguments to commands are separated by spaces. 25 25 26 26 The following commands are currently supported: … … 60 60 61 61 Remove the specified prefix from all function names (if present). 62 62 63 63 =item I<PROTOCOL> longname shortname filtername 64 64 … … 270 270 271 271 if (defined($type)) { 272 272 $data->{noemit}->{$type} = 1; 273 273 } else { 274 274 $data->{noemit_dissector} = 1; 275 275 } 276 276 } … … 285 285 } 286 286 287 287 $data->{manual}->{$fn} = 1; 288 288 } 289 289 … … 364 364 my %field_handlers = ( 365 365 TYPE => \&handle_type, 366 NOEMIT => \&handle_noemit, 366 NOEMIT => \&handle_noemit, 367 367 MANUAL => \&handle_manual, 368 PARAM_VALUE => \&handle_param_value, 369 HF_FIELD => \&handle_hf_field, 370 HF_RENAME => \&handle_hf_rename, 368 PARAM_VALUE => \&handle_param_value, 369 HF_FIELD => \&handle_hf_field, 370 HF_RENAME => \&handle_hf_rename, 371 371 ETT_FIELD => \&handle_ett_field, 372 372 TFS => \&handle_tfs, -
vendor/current/pidl/lib/Parse/Pidl/Wireshark/NDR.pm
r740 r988 28 28 use Parse::Pidl::Dump qw(DumpType DumpFunction); 29 29 use Parse::Pidl::Wireshark::Conformance qw(ReadConformance); 30 use File::Basename; 30 use File::Basename; 31 31 32 32 use vars qw($VERSION); … … 58 58 sub field2name($) 59 59 { 60 61 62 63 64 65 60 my($field) = shift; 61 62 $field =~ s/_/ /g; # Replace underscores with spaces 63 $field =~ s/(\w+)/\u\L$1/g; # Capitalise each word 64 65 return $field; 66 66 } 67 67 … … 92 92 my ($self, $d) = @_; 93 93 return if (defined($self->{cur_fn}) and defined($self->{conformance}->{manual}->{$self->{cur_fn}})); 94 94 95 95 if ($d) { 96 96 $self->{res}->{code} .= $self->{tabs}; … … 144 144 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})})); 145 145 146 146 foreach (@{$e->{ELEMENTS}}) { 147 147 if (/([^=]*)=(.*)/) { 148 148 $self->pidl_hdr("#define $1 ($2)"); 149 149 } 150 150 } 151 151 152 152 $self->pidl_hdr("extern const value_string $valsstring\[];"); 153 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, g uint32*param _U_);");153 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, g$e->{BASE_TYPE} *param _U_);"); 154 154 155 155 $self->pidl_def("const value_string ".$valsstring."[] = {"); 156 156 foreach (@{$e->{ELEMENTS}}) { 157 157 next unless (/([^=]*)=(.*)/); 158 158 $self->pidl_def("\t{ $1, \"$1\" },"); … … 164 164 $self->pidl_fn_start($dissectorname); 165 165 $self->pidl_code("int"); 166 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, g uint32*param _U_)");166 $self->pidl_code("$dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_, int hf_index _U_, g$e->{BASE_TYPE} *param _U_)"); 167 167 $self->pidl_code("{"); 168 168 $self->indent; 169 169 $self->pidl_code("g$e->{BASE_TYPE} parameter=0;"); 170 $self->pidl_code("if (param){");170 $self->pidl_code("if (param) {"); 171 171 $self->indent; 172 $self->pidl_code("parameter =(g$e->{BASE_TYPE})*param;");172 $self->pidl_code("parameter = *param;"); 173 173 $self->deindent; 174 174 $self->pidl_code("}"); 175 175 $self->pidl_code("offset = dissect_ndr_$e->{BASE_TYPE}(tvb, offset, pinfo, tree, drep, hf_index, ¶meter);"); 176 $self->pidl_code("if (param){");176 $self->pidl_code("if (param) {"); 177 177 $self->indent; 178 $self->pidl_code("*param =(guint32)parameter;");178 $self->pidl_code("*param = parameter;"); 179 179 $self->deindent; 180 180 $self->pidl_code("}"); … … 187 187 $enum_size =~ s/uint//g; 188 188 $self->register_type($name, "offset = $dissectorname(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_UINT$enum_size", "BASE_DEC", "0", "VALS($valsstring)", $enum_size / 8); 189 } 190 191 sub Pipe($$$$) 192 { 193 my ($self,$e,$name,$ifname) = @_; 194 error($e->{ORIGINAL}, "Pipe not yet supported"); 195 return; 189 196 } 190 197 … … 206 213 $self->pidl_code("proto_tree *tree = NULL;"); 207 214 $self->pidl_code(""); 208 215 209 216 $self->pidl_code("g$e->{BASE_TYPE} flags;"); 210 217 if ($e->{ALIGN} > 1) { … … 216 223 $self->pidl_code("if (parent_tree) {"); 217 224 $self->indent; 218 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, TRUE);");225 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, $e->{ALIGN}, DREP_ENC_INTEGER(drep));"); 219 226 $self->pidl_code("tree = proto_item_add_subtree(item,ett_$ifname\_$name);"); 220 227 $self->deindent; … … 234 241 235 242 $self->{hf_used}->{$hf_bitname} = 1; 236 243 237 244 $self->register_hf_field($hf_bitname, field2name($en), $filtername, "FT_BOOLEAN", $e->{ALIGN} * 8, "TFS(&$name\_$en\_tfs)", $ev, ""); 238 245 … … 247 254 } 248 255 $self->pidl_def("};"); 249 256 250 257 $self->pidl_code("proto_tree_add_boolean(tree, $hf_bitname, tvb, offset-$e->{ALIGN}, $e->{ALIGN}, flags);"); 251 258 $self->pidl_code("if (flags&$ev){"); … … 271 278 } 272 279 273 sub ElementLevel($$$$$$$) 274 { 275 my ($self,$e,$l,$hf,$myname,$pn,$ifname) = @_; 276 277 my $param = 0; 280 sub ElementLevel($$$$$$$$) 281 { 282 my ($self,$e,$l,$hf,$myname,$pn,$ifname,$param) = @_; 278 283 279 284 if (defined($self->{conformance}->{dissectorparams}->{$myname})) { … … 317 322 318 323 ($bs = 1) if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_ASCII.*")); 319 324 320 325 if (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*") and property_matches($e, "flag", ".*LIBNDR_FLAG_STR_LEN4.*")) { 321 326 $self->pidl_code("char *data;\n"); … … 324 329 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_STR_SIZE4.*")) { 325 330 $self->pidl_code("offset = dissect_ndr_vstring(tvb, offset, pinfo, tree, drep, $bs, $hf, FALSE, NULL);"); 331 } elsif (property_matches($e, "flag", ".*STR_NULLTERM.*")) { 332 if ($bs == 2) { 333 $self->pidl_code("offset = dissect_null_term_wstring(tvb, offset, pinfo, tree, drep, $hf , 0);") 334 } else { 335 $self->pidl_code("offset = dissect_null_term_string(tvb, offset, pinfo, tree, drep, $hf , 0);") 336 } 326 337 } else { 327 338 warn("Unable to handle string with flags $e->{PROPERTIES}->{flag}"); 328 339 } 340 } elsif ($l->{DATA_TYPE} eq "DATA_BLOB") { 341 my $remain = 0; 342 $remain = 1 if (property_matches($e->{ORIGINAL}, "flag", ".*LIBNDR_FLAG_REMAINING.*")); 343 $self->pidl_code("offset = dissect_ndr_datablob(tvb, offset, pinfo, tree, drep, $hf, $remain);"); 329 344 } else { 330 345 my $call; 331 346 332 347 if ($self->{conformance}->{imports}->{$l->{DATA_TYPE}}) { 333 $call = $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{DATA}; 348 $call = $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{DATA}; 334 349 $self->{conformance}->{imports}->{$l->{DATA_TYPE}}->{USED} = 1; 335 } elsif (defined($self->{conformance}->{imports}->{"$pn.$e->{NAME}"})) { 336 $call = $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{DATA}; 350 351 } elsif (defined($self->{conformance}->{imports}->{"$pn.$e->{NAME}"})) { 352 $call = $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{DATA}; 337 353 $self->{conformance}->{imports}->{"$pn.$e->{NAME}"}->{USED} = 1; 338 354 339 355 } elsif (defined($self->{conformance}->{types}->{$l->{DATA_TYPE}})) { 340 356 $call= $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{DISSECTOR_NAME}; 341 357 $self->{conformance}->{types}->{$l->{DATA_TYPE}}->{USED} = 1; 342 358 } else { 343 $self->pidl_code("offset = $ifname\_dissect_struct_" . $l->{DATA_TYPE} . "(tvb,offset,pinfo,tree,drep,$hf,$param);"); 359 my $t; 360 if (ref($l->{DATA_TYPE}) eq "HASH" ) { 361 $t = "$l->{DATA_TYPE}->{TYPE}_$l->{DATA_TYPE}->{NAME}"; 362 } else { 363 $t = $l->{DATA_TYPE}; 364 } 365 366 $self->pidl_code("offset = $ifname\_dissect_struct_" . $t . "(tvb,offset,pinfo,tree,drep,$hf,$param);"); 344 367 345 368 return; … … 351 374 } 352 375 } elsif ($_->{TYPE} eq "SUBCONTEXT") { 376 my $varswitch; 377 if (has_property($e, "switch_is")) { 378 $varswitch = $e->{PROPERTIES}->{switch_is}; 379 } 353 380 my $num_bits = ($l->{HEADER_SIZE}*8); 381 my $hf2 = $self->register_hf_field($hf."_", "Subcontext length", "$ifname.$pn.$_->{NAME}subcontext", "FT_UINT$num_bits", "BASE_HEX", "NULL", 0, ""); 382 $num_bits = 3264 if ($num_bits == 32); 383 $self->{hf_used}->{$hf2} = 1; 384 $self->pidl_code("dcerpc_info *di = (dcerpc_info*)pinfo->private_data;"); 354 385 $self->pidl_code("guint$num_bits size;"); 355 $self->pidl_code("int start_offset = offset;");386 $self->pidl_code("int conformant = di->conformant_run;"); 356 387 $self->pidl_code("tvbuff_t *subtvb;"); 357 $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf, &size);"); 358 $self->pidl_code("proto_tree_add_text(tree, tvb, start_offset, offset - start_offset + size, \"Subcontext size\");"); 388 $self->pidl_code(""); 389 # We need to be able to dissect the length of the context in every case 390 # and conformant run skips the dissections of scalars ... 391 $self->pidl_code("if (!conformant) {"); 392 $self->indent; 393 $self->pidl_code("guint32 saved_flags = di->call_data->flags;"); 394 $self->pidl_code("offset = dissect_ndr_uint$num_bits(tvb, offset, pinfo, tree, drep, $hf2, &size);"); 395 # This is a subcontext, there is normally no such thing as 396 # 64 bit NDR is subcontext so we clear the flag so that we can 397 # continue to dissect handmarshalled stuff with pidl 398 $self->pidl_code("di->call_data->flags &= ~DCERPC_IS_NDR64;"); 359 399 360 400 $self->pidl_code("subtvb = tvb_new_subset(tvb, offset, size, -1);"); 361 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, drep);"); 401 if ($param ne 0) { 402 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, drep, $param);"); 403 } else { 404 $self->pidl_code("$myname\_(subtvb, 0, pinfo, tree, drep);"); 405 } 406 $self->pidl_code("offset += size;"); 407 $self->pidl_code("di->call_data->flags = saved_flags;"); 408 $self->deindent; 409 $self->pidl_code("}"); 410 } elsif ($_->{TYPE} eq "PIPE") { 411 error($e->{ORIGINAL}, "Type PIPE not yet supported"); 362 412 } else { 363 413 die("Unknown type `$_->{TYPE}'"); … … 365 415 } 366 416 367 sub Element($$$) 368 { 369 my ($self,$e,$pn,$ifname) = @_; 417 sub SwitchType($$;$) 418 { 419 my ($e, $type, $nodiscriminant) = @_; 420 421 my $switch_dt = getType($type); 422 my $switch_type = undef; 423 if ($switch_dt->{DATA}->{TYPE} eq "ENUM") { 424 $switch_type = Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); 425 } elsif ($switch_dt->{DATA}->{TYPE} eq "BITMAP") { 426 $switch_type = Parse::Pidl::Typelist::bitmap_type_fn($switch_dt->{DATA}); 427 } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") { 428 if (defined $e->{SWITCH_TYPE}) { 429 $switch_type = "$e->{SWITCH_TYPE}"; 430 } else { 431 $switch_type = "$switch_dt->{DATA}->{NAME}"; 432 } 433 } elsif (not defined $e->{SWITCH_TYPE}) { 434 $switch_type = $nodiscriminant; 435 } 436 437 return $switch_type 438 } 439 440 sub Element($$$$$) 441 { 442 my ($self,$e,$pn,$ifname,$isoruseswitch) = @_; 370 443 371 444 my $dissectorname = "$ifname\_dissect\_element\_".StripPrefixes($pn, $self->{conformance}->{strip_prefixes})."\_".StripPrefixes($e->{NAME}, $self->{conformance}->{strip_prefixes}); 372 445 373 my $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);"; 446 my ($call_code, $moreparam); 447 my $param = 0; 448 if (defined $isoruseswitch) { 449 my $type = $isoruseswitch->[0]; 450 my $name = $isoruseswitch->[1]; 451 452 my $switch_raw_type = SwitchType($e, $type, "uint32"); 453 if (not defined($switch_raw_type)) { 454 die("Unknown type[$type]\n"); 455 } 456 my $switch_type = "g${switch_raw_type}"; 457 458 $moreparam = ", $switch_type *".$name; 459 $param = $name; 460 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep, &$name);"; 461 } else { 462 $moreparam = ""; 463 $call_code = "offset = $dissectorname(tvb, offset, pinfo, tree, drep);"; 464 } 465 374 466 375 467 my $type = $self->find_type($e->{TYPE}); … … 393 485 }; 394 486 } 487 if (property_matches($e, "flag", ".*LIBNDR_FLAG_ALIGN.*")) { 488 my $align_flag = $e->{PROPERTIES}->{flag}; 489 if ($align_flag =~ m/LIBNDR_FLAG_ALIGN(\d+)/) { 490 $call_code = "ALIGN_TO_$1_BYTES; ".$call_code; 491 } 492 } 395 493 396 494 my $hf = $self->register_hf_field("hf_$ifname\_$pn\_$e->{NAME}", field2name($e->{NAME}), "$ifname.$pn.$e->{NAME}", $type->{FT_TYPE}, $type->{BASE_TYPE}, $type->{VALSSTRING}, $type->{MASK}, ""); … … 404 502 my $add = ""; 405 503 504 my $oldparam = undef; 406 505 foreach (@{$e->{LEVELS}}) { 506 if (defined $_->{SWITCH_IS}) { 507 $oldparam = $param; 508 $param = "*$param"; 509 } 407 510 next if ($_->{TYPE} eq "SWITCH"); 408 $self->pidl_def("static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_ );");511 $self->pidl_def("static int $dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_$moreparam);"); 409 512 $self->pidl_fn_start("$dissectorname$add"); 410 513 $self->pidl_code("static int"); 411 $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_ )");514 $self->pidl_code("$dissectorname$add(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_$moreparam)"); 412 515 $self->pidl_code("{"); 413 516 $self->indent; 414 517 415 $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname); 518 $self->ElementLevel($e,$_,$hf,$dissectorname.$add,$pn,$ifname,$param); 519 if (defined $oldparam) { 520 $param = $oldparam; 521 } 416 522 417 523 $self->pidl_code(""); … … 434 540 435 541 foreach (@{$fn->{ELEMENTS}}) { 436 $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname ) if not defined($dissectornames{$_->{NAME}});437 } 438 542 $dissectornames{$_->{NAME}} = $self->Element($_, $fn->{NAME}, $ifname, undef) if not defined($dissectornames{$_->{NAME}}); 543 } 544 439 545 my $fn_name = $_->{NAME}; 440 546 $fn_name =~ s/^${ifname}_//; … … 447 553 $self->indent; 448 554 if ( not defined($fn->{RETURN_TYPE})) { 449 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR") 555 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS" or $fn->{RETURN_TYPE} eq "WERROR") 450 556 { 451 557 $self->pidl_code("guint32 status;\n"); … … 456 562 $self->pidl_code("g$fn->{RETURN_TYPE} status;\n"); 457 563 } else { 458 564 error($fn, "return type `$fn->{RETURN_TYPE}' not yet supported"); 459 565 } 460 566 } else { … … 474 580 } elsif ($fn->{RETURN_TYPE} eq "NTSTATUS") { 475 581 $self->pidl_code("offset = dissect_ntstatus(tvb, offset, pinfo, tree, drep, hf\_$ifname\_status, &status);\n"); 476 $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))");582 $self->pidl_code("if (status != 0)"); 477 583 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, NT_errors, \"Unknown NT status 0x%08x\"));\n"); 478 584 $return_types{$ifname}->{"status"} = ["NTSTATUS", "NT Error"]; 479 585 } elsif ($fn->{RETURN_TYPE} eq "WERROR") { 480 586 $self->pidl_code("offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf\_$ifname\_werror, &status);\n"); 481 $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))");587 $self->pidl_code("if (status != 0)"); 482 588 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Error: %s\", val_to_str(status, WERR_errors, \"Unknown DOS error 0x%08x\"));\n"); 483 589 484 590 $return_types{$ifname}->{"werror"} = ["WERROR", "Windows Error"]; 485 591 } elsif (my $type = getType($fn->{RETURN_TYPE})) { … … 489 595 490 596 $self->pidl_code("offset = $return_dissect(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"); 491 $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))");597 $self->pidl_code("if (status != 0)"); 492 598 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %s\", val_to_str(status, $ifname\_$fn->{RETURN_TYPE}\_vals, \"Unknown " . $fn->{RETURN_TYPE} . " error 0x%08x\"));\n"); 493 599 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; 494 600 } elsif ($type->{DATA}->{TYPE} eq "SCALAR") { 495 601 $self->pidl_code("offset = dissect_ndr_$fn->{RETURN_TYPE}(tvb, offset, pinfo, tree, drep, hf\_$ifname\_$fn->{RETURN_TYPE}_status, &status);"); 496 $self->pidl_code("if (status != 0 && check_col(pinfo->cinfo, COL_INFO))");602 $self->pidl_code("if (status != 0)"); 497 603 $self->pidl_code("\tcol_append_fstr(pinfo->cinfo, COL_INFO, \", Status: %d\", status);\n"); 498 604 $return_types{$ifname}->{$fn->{RETURN_TYPE}."_status"} = [$fn->{RETURN_TYPE}, $fn->{RETURN_TYPE}]; … … 535 641 536 642 my $res = ""; 537 ($res.="\t".$self->Element($_, $name, $ifname)."\n\n") foreach (@{$e->{ELEMENTS}}); 643 my $varswitchs = {}; 644 # will contain the switch var declaration; 645 my $vars = []; 646 foreach (@{$e->{ELEMENTS}}) { 647 if (has_property($_, "switch_is")) { 648 $varswitchs->{$_->{PROPERTIES}->{switch_is}} = []; 649 } 650 } 651 foreach (@{$e->{ELEMENTS}}) { 652 my $switch_info = undef; 653 654 my $v = $_->{NAME}; 655 if (scalar(grep {/^$v$/} keys(%$varswitchs)) == 1) { 656 # This element is one of the switch attribute 657 my $switch_raw_type = SwitchType($e, $_->{TYPE}, "uint32"); 658 if (not defined($switch_raw_type)) { 659 die("Unknown type[$_->{TYPE}]\n"); 660 } 661 my $switch_type = "g${switch_raw_type}"; 662 663 push @$vars, "$switch_type $v;"; 664 $switch_info = [ $_->{TYPE}, $v ]; 665 $varswitchs->{$v} = $switch_info; 666 } 667 668 if (has_property($_, "switch_is")) { 669 my $varswitch = $_->{PROPERTIES}->{switch_is}; 670 $switch_info = $varswitchs->{$varswitch}; 671 } 672 673 $res.="\t".$self->Element($_, $name, $ifname, $switch_info)."\n\n"; 674 } 675 676 my $doalign = undef; 677 if ($e->{ALIGN} > 1 and not property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) { 678 $doalign = 1; 679 } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) { 680 $doalign = 0; 681 } 538 682 539 683 $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);"); … … 544 688 $self->pidl_code("{"); 545 689 $self->indent; 690 $self->pidl_code($_) foreach (@$vars); 546 691 $self->pidl_code("proto_item *item = NULL;"); 547 692 $self->pidl_code("proto_tree *tree = NULL;"); 548 if ($e->{ALIGN} > 1) { 549 $self->pidl_code("dcerpc_info *di = pinfo->private_data;"); 693 if (defined($doalign)) { 694 $self->pidl_code("dcerpc_info *di = (dcerpc_info *)pinfo->private_data;"); 695 if ($doalign == 0) { 696 $self->pidl_code("gboolean oldalign = di->no_align;"); 697 } 550 698 } 551 699 $self->pidl_code("int old_offset;"); 552 700 $self->pidl_code(""); 553 701 554 if ($e->{ALIGN} > 1) { 555 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); 556 } 557 $self->pidl_code(""); 702 if (defined($doalign)) { 703 if ($doalign == 1) { 704 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); 705 } 706 if ($doalign == 0) { 707 $self->pidl_code("di->no_align = TRUE;"); 708 } 709 $self->pidl_code(""); 710 } 558 711 559 712 $self->pidl_code("old_offset = offset;"); … … 561 714 $self->pidl_code("if (parent_tree) {"); 562 715 $self->indent; 563 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);");716 $self->pidl_code("item = proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, ENC_NA);"); 564 717 $self->pidl_code("tree = proto_item_add_subtree(item, ett_$ifname\_$name);"); 565 718 $self->deindent; … … 569 722 570 723 $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n"); 571 if ( $e->{ALIGN} >1) {724 if (defined($doalign) and $doalign == 1) { 572 725 $self->pidl_code(""); 573 726 $self->pidl_code("if (di->call_data->flags & DCERPC_IS_NDR64) {"); … … 577 730 $self->pidl_code("}"); 578 731 } 732 if (defined($doalign) and $doalign == 0) { 733 $self->pidl_code(""); 734 $self->pidl_code("di->no_align = oldalign;"); 735 } 579 736 $self->pidl_code(""); 580 737 $self->pidl_code("return offset;"); … … 593 750 594 751 return if (defined($self->{conformance}->{noemit}->{StripPrefixes($name, $self->{conformance}->{strip_prefixes})})); 595 752 596 753 $self->register_ett("ett_$ifname\_$name"); 597 754 … … 600 757 $res.="\n\t\t$_->{CASE}:\n"; 601 758 if ($_->{TYPE} ne "EMPTY") { 602 $res.="\t\t\t".$self->Element($_, $name, $ifname )."\n";759 $res.="\t\t\t".$self->Element($_, $name, $ifname, undef)."\n"; 603 760 } 604 761 $res.="\t\tbreak;\n"; 605 762 } 606 763 607 my $switch_type; 608 my $switch_dissect; 609 my $switch_dt = getType($e->{SWITCH_TYPE}); 610 if ($switch_dt->{DATA}->{TYPE} eq "ENUM") { 611 $switch_type = "g".Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); 612 $switch_dissect = "dissect_ndr_" .Parse::Pidl::Typelist::enum_type_fn($switch_dt->{DATA}); 613 } elsif ($switch_dt->{DATA}->{TYPE} eq "SCALAR") { 614 $switch_type = "g$e->{SWITCH_TYPE}"; 615 $switch_dissect = "dissect_ndr_$e->{SWITCH_TYPE}"; 764 my $switch_type = undef; 765 my $switch_dissect = undef; 766 my $switch_raw_type = SwitchType($e, $e->{SWITCH_TYPE}); 767 if (defined($switch_raw_type)) { 768 $switch_type = "g${switch_raw_type}"; 769 $switch_dissect = "dissect_ndr_${switch_raw_type}"; 616 770 } 617 771 … … 624 778 $self->pidl_code("proto_tree *tree = NULL;"); 625 779 $self->pidl_code("int old_offset;"); 626 $self->pidl_code("$switch_type level;"); 780 if (!defined $switch_type) { 781 $self->pidl_code("guint32 level = param;"); 782 } else { 783 $self->pidl_code("$switch_type level;"); 784 } 627 785 $self->pidl_code(""); 628 786 … … 637 795 $self->pidl_code(""); 638 796 639 $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);"); 640 641 if ($e->{ALIGN} > 1) { 642 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); 643 $self->pidl_code(""); 797 if (defined $switch_type) { 798 $self->pidl_code("offset = $switch_dissect(tvb, offset, pinfo, tree, drep, hf_index, &level);"); 799 800 if ($e->{ALIGN} > 1) { 801 $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;"); 802 $self->pidl_code(""); 803 } 644 804 } 645 805 … … 660 820 { 661 821 my ($self,$const,$ifname) = @_; 662 822 663 823 if (!defined($const->{ARRAY_LEN}[0])) { 664 665 666 667 824 $self->pidl_hdr("#define $const->{NAME}\t( $const->{VALUE} )\n"); 825 } else { 826 $self->pidl_hdr("#define $const->{NAME}\t $const->{VALUE}\n"); 827 } 668 828 } 669 829 … … 680 840 681 841 $self->PrintIdl(DumpType($e->{ORIGINAL})); 682 683 842 { 684 843 ENUM => \&Enum, … … 686 845 UNION => \&Union, 687 846 BITMAP => \&Bitmap, 688 TYPEDEF => \&Typedef 847 TYPEDEF => \&Typedef, 848 PIPE => \&Pipe 689 849 }->{$e->{TYPE}}->($self, $e, $name, $ifname); 690 850 } … … 701 861 $self->{res}->{code}.=$self->DumpHfList()."\n"; 702 862 $self->{res}->{code}.="\n".DumpEttList($self->{ett})."\n"; 703 863 704 864 if (defined($x->{UUID})) { 705 # These can be changed to non-pidl_code names if the old dissectors706 # in epan/dissctors are deleted.707 708 709 710 711 712 713 714 715 716 865 # These can be changed to non-pidl_code names if the old 866 # dissectors in epan/dissectors are deleted. 867 868 my $name = uc($x->{NAME}) . " (pidl)"; 869 my $short_name = uc($x->{NAME}); 870 my $filter_name = $x->{NAME}; 871 872 if (has_property($x, "helpstring")) { 873 $name = $x->{PROPERTIES}->{helpstring}; 874 } 875 876 if (defined($self->{conformance}->{protocols}->{$x->{NAME}})) { 717 877 $short_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{SHORTNAME}; 718 878 $name = $self->{conformance}->{protocols}->{$x->{NAME}}->{LONGNAME}; 719 879 $filter_name = $self->{conformance}->{protocols}->{$x->{NAME}}->{FILTERNAME}; 720 721 722 723 724 725 880 } 881 882 $self->pidl_code("proto_dcerpc_$x->{NAME} = proto_register_protocol(".make_str($name).", ".make_str($short_name).", ".make_str($filter_name).");"); 883 884 $self->pidl_code("proto_register_field_array(proto_dcerpc_$x->{NAME}, hf, array_length (hf));"); 885 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));"); 726 886 } else { 727 728 729 730 } 731 887 $self->pidl_code("proto_dcerpc = proto_get_id_by_filter_name(\"dcerpc\");"); 888 $self->pidl_code("proto_register_field_array(proto_dcerpc, hf, array_length(hf));"); 889 $self->pidl_code("proto_register_subtree_array(ett, array_length(ett));"); 890 } 891 732 892 $self->deindent; 733 893 $self->pidl_code("}\n"); … … 741 901 if (defined($x->{UUID})) { 742 902 $self->pidl_fn_start("proto_reg_handoff_dcerpc_$x->{NAME}"); 743 744 745 746 747 748 749 750 903 $self->pidl_code("void proto_reg_handoff_dcerpc_$x->{NAME}(void)"); 904 $self->pidl_code("{"); 905 $self->indent; 906 $self->pidl_code("dcerpc_init_uuid(proto_dcerpc_$x->{NAME}, ett_dcerpc_$x->{NAME},"); 907 $self->pidl_code("\t&uuid_dcerpc_$x->{NAME}, ver_dcerpc_$x->{NAME},"); 908 $self->pidl_code("\t$x->{NAME}_dissectors, hf_$x->{NAME}_opnum);"); 909 $self->deindent; 910 $self->pidl_code("}"); 751 911 $self->pidl_fn_end("proto_reg_handoff_dcerpc_$x->{NAME}"); 752 912 … … 771 931 foreach (@imports) { 772 932 next if($_ eq "security"); 773 s/\.idl\"$//;774 933 s/^\"//; 934 s/\.idl"?$//; 775 935 $self->pidl_hdr("#include \"packet-dcerpc-$_\.h\""); 776 936 } … … 796 956 my $if_uuid = $x->{UUID}; 797 957 798 799 800 801 $self->pidl_def("\t0x" . substr($if_uuid, 1, 8)802 803 804 $self->pidl_def("\t{ 0x" . substr($if_uuid, 20, 2)958 $self->pidl_def("/* Version information */\n\n"); 959 960 $self->pidl_def("static e_uuid_t uuid_dcerpc_$x->{NAME} = {"); 961 $self->pidl_def("\t0x" . substr($if_uuid, 1, 8) 962 . ", 0x" . substr($if_uuid, 10, 4) 963 . ", 0x" . substr($if_uuid, 15, 4) . ","); 964 $self->pidl_def("\t{ 0x" . substr($if_uuid, 20, 2) 805 965 . ", 0x" . substr($if_uuid, 22, 2) 806 807 808 809 810 811 812 813 814 my $maj =$x->{VERSION};815 816 817 966 . ", 0x" . substr($if_uuid, 25, 2) 967 . ", 0x" . substr($if_uuid, 27, 2) 968 . ", 0x" . substr($if_uuid, 29, 2) 969 . ", 0x" . substr($if_uuid, 31, 2) 970 . ", 0x" . substr($if_uuid, 33, 2) 971 . ", 0x" . substr($if_uuid, 35, 2) . " }"); 972 $self->pidl_def("};"); 973 974 my $maj = 0x0000FFFF & $x->{VERSION}; 975 $maj =~ s/\.(.*)$//g; 976 $self->pidl_def("static guint16 ver_dcerpc_$x->{NAME} = $maj;"); 977 $self->pidl_def(""); 818 978 } 819 979 … … 821 981 822 982 $self->Interface($x); 823 824 983 $self->pidl_code("\n".DumpFunctionTable($x)); 825 984 826 foreach ( keys %{$return_types{$x->{NAME}}}) {985 foreach (sort(keys %{$return_types{$x->{NAME}}})) { 827 986 my ($type, $desc) = @{$return_types{$x->{NAME}}->{$_}}; 828 987 my $dt = $self->find_type($type); … … 869 1028 $self->{conformance} = { 870 1029 imports => {}, 871 header_fields=> {} 1030 header_fields=> {} 872 1031 }; 873 1032 874 1033 ReadConformance($cnf_file, $self->{conformance}) or print STDERR "warning: No conformance file `$cnf_file'\n"; 875 1034 876 1035 foreach my $bytes (qw(1 2 4 8)) { 877 1036 my $bits = $bytes * 8; … … 879 1038 $self->register_type("int$bits", "offset = PIDL_dissect_uint$bits(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);", "FT_INT$bits", "BASE_DEC", 0, "NULL", $bytes); 880 1039 } 881 1040 1041 $self->register_type("uint3264", "offset = dissect_ndr_uint3264(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT32", "BASE_DEC", 0, "NULL", 8); 1042 $self->register_type("hyper", "offset = dissect_ndr_uint64(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 8); 882 1043 $self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4); 883 1044 $self->register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1); … … 891 1052 $self->register_type("time_t", "offset = dissect_ndr_time_t(tvb, offset, pinfo,tree, drep, \@HF\@, NULL);","FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); 892 1053 $self->register_type("NTTIME_1sec", "offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, \@HF\@);", "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", 0, "NULL", 4); 893 $self->register_type(" SID", "1054 $self->register_type("dom_sid28", "{ 894 1055 dcerpc_info *di = (dcerpc_info *)pinfo->private_data; 895 896 1056 di->hf_index = \@HF\@; 897 1057 1058 offset = dissect_ndr_nt_SID28(tvb, offset, pinfo, tree, drep); 1059 }", "FT_STRING", "BASE_NONE", 0, "NULL", 4); 1060 $self->register_type("SID", "{ 1061 dcerpc_info *di = (dcerpc_info *)pinfo->private_data; 1062 1063 di->hf_index = \@HF\@; 1064 898 1065 offset = dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param); 899 ","FT_STRING", "BASE_NONE", 0, "NULL", 4);900 $self->register_type("WERROR", 1066 }", "FT_STRING", "BASE_NONE", 0, "NULL", 4); 1067 $self->register_type("WERROR", 901 1068 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(WERR_errors)", 4); 902 $self->register_type("NTSTATUS", 1069 $self->register_type("NTSTATUS", 903 1070 "offset = PIDL_dissect_uint32(tvb, offset, pinfo, tree, drep, \@HF\@, \@PARAM\@);","FT_UINT32", "BASE_DEC", 0, "VALS(NT_errors)", 4); 1071 $self->register_type("ipv6address", "proto_tree_add_item(tree, \@HF\@, tvb, offset, 16, ENC_NA); offset += 16;", "FT_IPv6", "BASE_NONE", 0, "NULL", 16); 1072 $self->register_type("ipv4address", "proto_tree_add_item(tree, \@HF\@, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4;", "FT_IPv4", "BASE_NONE", 0, "NULL", 4); 904 1073 905 1074 } … … 915 1084 return (undef, undef) if defined($self->{conformance}->{noemit_dissector}); 916 1085 917 my $notice = 1086 my $notice = 918 1087 "/* DO NOT EDIT 919 1088 This filter was automatically generated 920 1089 from $idl_file and $cnf_file. 921 922 Pidl is a perl based IDL compiler for DCE/RPC idl files. 1090 1091 Pidl is a perl based IDL compiler for DCE/RPC idl files. 923 1092 It is maintained by the Samba team, not the Wireshark team. 924 Instructions on how to download and install Pidl can be 1093 Instructions on how to download and install Pidl can be 925 1094 found at http://wiki.wireshark.org/Pidl 926 1095 */ … … 931 1100 932 1101 $self->{res}->{headers} = "\n"; 933 $self->{res}->{headers} .= "#ifdef HAVE_CONFIG_H\n";934 1102 $self->{res}->{headers} .= "#include \"config.h\"\n"; 935 $self->{res}->{headers} .= "#endif\n\n";936 1103 937 1104 $self->{res}->{headers} .= "#ifdef _MSC_VER\n"; … … 984 1151 985 1152 $self->CheckUsed($self->{conformance}); 986 1153 987 1154 return ($parser,$header); 988 1155 } … … 996 1163 my ($self, $name) = @_; 997 1164 998 push (@{$self->{ett}}, $name); 1165 push (@{$self->{ett}}, $name); 999 1166 } 1000 1167 … … 1025 1192 ############################################################################### 1026 1193 1027 sub register_hf_field($$$$$$$$$) 1194 sub register_hf_field($$$$$$$$$) 1028 1195 { 1029 1196 my ($self,$index,$name,$filter_name,$ft_type,$base_type,$valsstring,$mask,$blurb) = @_; … … 1045 1212 }; 1046 1213 1047 if ((not defined($blurb) or $blurb eq "") and 1214 if ((not defined($blurb) or $blurb eq "") and 1048 1215 defined($self->{conformance}->{fielddescription}->{$index})) { 1049 $self->{conformance}->{header_fields}->{$index}->{BLURB} = 1216 $self->{conformance}->{header_fields}->{$index}->{BLURB} = 1050 1217 $self->{conformance}->{fielddescription}->{$index}->{DESCRIPTION}; 1051 1218 $self->{conformance}->{fielddescription}->{$index}->{USED} = 1; … … 1055 1222 } 1056 1223 1224 sub change_hf_field_type($$$$) 1225 { 1226 my ($self,$index,$ft_type,$base_type) = @_; 1227 if (defined ($self->{conformance}->{hf_renames}->{$index})) { 1228 print "Field $index has been renamed to ".$self->{conformance}->{hf_renames}->{$index}->{NEWNAME}." you can't change it's type"; 1229 return 0; 1230 } 1231 1232 if (!defined ($self->{conformance}->{header_fields}->{$index})) { 1233 print "Field $index doesn't exists"; 1234 return 0; 1235 } 1236 $self->{conformance}->{header_fields}->{$index}->{FT_TYPE} = $ft_type; 1237 $self->{conformance}->{header_fields}->{$index}->{BASE_TYPE} = $base_type; 1238 return 1; 1239 } 1240 1057 1241 sub DumpHfDeclaration($) 1058 1242 { … … 1062 1246 $res = "\n/* Header field declarations */\n"; 1063 1247 1064 foreach ( keys %{$self->{conformance}->{header_fields}})1248 foreach (sort(keys %{$self->{conformance}->{header_fields}})) 1065 1249 { 1066 1250 $res .= "static gint $_ = -1;\n"; … … 1072 1256 sub make_str_or_null($) 1073 1257 { 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1258 my $str = shift; 1259 if (substr($str, 0, 1) eq "\"") { 1260 $str = substr($str, 1, length($str)-2); 1261 } 1262 $str =~ s/^\s*//; 1263 $str =~ s/\s*$//; 1264 if ($str eq "") { 1265 return "NULL"; 1266 } 1267 return make_str($str); 1084 1268 } 1085 1269 … … 1089 1273 my $res = "\tstatic hf_register_info hf[] = {\n"; 1090 1274 1091 foreach ( values %{$self->{conformance}->{header_fields}})1275 foreach (sort {$a->{INDEX} cmp $b->{INDEX}} values %{$self->{conformance}->{header_fields}}) 1092 1276 { 1093 $res .= "\t{ &$_->{INDEX}, 1277 $res .= "\t{ &$_->{INDEX}, 1094 1278 { ".make_str($_->{NAME}).", ".make_str($_->{FILTER}).", $_->{FT_TYPE}, $_->{BASE_TYPE}, $_->{VALSSTRING}, $_->{MASK}, ".make_str_or_null($_->{BLURB}).", HFILL }}, 1095 1279 "; … … 1110 1294 my $res = "static dcerpc_sub_dissector $if->{NAME}\_dissectors[] = {\n"; 1111 1295 foreach (@{$if->{FUNCTIONS}}) { 1112 1296 my $fn_name = $_->{NAME}; 1113 1297 $fn_name =~ s/^$if->{NAME}_//; 1114 1298 $res.= "\t{ $_->{OPNUM}, \"$fn_name\",\n"; -
vendor/current/pidl/lib/wscript_build
r740 r988 2 2 3 3 # install the pidl modules 4 bld.INSTALL_WILDCARD('${DATAROOTDIR}/perl5', '**/*.pm', flat=False) 4 bld.INSTALL_FILES(bld.env.PERL_LIB_INSTALL_DIR, 5 ''' 6 Parse/Pidl.pm 7 Parse/Pidl/Samba4.pm 8 Parse/Pidl/CUtil.pm 9 Parse/Pidl/Expr.pm 10 Parse/Pidl/Wireshark/Conformance.pm 11 Parse/Pidl/Wireshark/NDR.pm 12 Parse/Pidl/ODL.pm 13 Parse/Pidl/Dump.pm 14 Parse/Pidl/Util.pm 15 Parse/Pidl/Samba4/Header.pm 16 Parse/Pidl/Samba4/COM/Header.pm 17 Parse/Pidl/Samba4/COM/Proxy.pm 18 Parse/Pidl/Samba4/COM/Stub.pm 19 Parse/Pidl/Samba4/TDR.pm 20 Parse/Pidl/Samba4/NDR/Server.pm 21 Parse/Pidl/Samba4/NDR/Client.pm 22 Parse/Pidl/Samba4/NDR/Parser.pm 23 Parse/Pidl/Samba4/Python.pm 24 Parse/Pidl/Samba4/Template.pm 25 Parse/Pidl/IDL.pm 26 Parse/Pidl/Typelist.pm 27 Parse/Pidl/Samba3/ClientNDR.pm 28 Parse/Pidl/Samba3/ServerNDR.pm 29 Parse/Pidl/Compat.pm 30 Parse/Pidl/NDR.pm 31 ''', 32 flat=False) 33 34 if not bld.CONFIG_SET('USING_SYSTEM_PARSE_YAPP_DRIVER'): 35 bld.INSTALL_FILES(bld.env.PERL_LIB_INSTALL_DIR, 36 'Parse/Yapp/Driver.pm', 37 flat=False) -
vendor/current/pidl/pidl
r919 r988 22 22 =head1 DESCRIPTION 23 23 24 pidl is an IDL compiler written in Perl that aims to be somewhat 25 compatible with the midl compiler. IDL is short for 24 pidl is an IDL compiler written in Perl that aims to be somewhat 25 compatible with the midl compiler. IDL is short for 26 26 "Interface Definition Language". 27 27 28 pidl can generate stubs for DCE/RPC server code, DCE/RPC 28 pidl can generate stubs for DCE/RPC server code, DCE/RPC 29 29 client code and Wireshark dissectors for DCE/RPC traffic. 30 30 31 IDL compilers like pidl take a description 32 of an interface as their input and use it to generate C 33 (though support for other languages may be added later) code that 34 can use these interfaces, pretty print data sent 35 using these interfaces, or even generate Wireshark 36 dissectors that can parse data sent over the 37 wire by these interfaces. 38 39 pidl takes IDL files in the same format as is used by midl, 31 IDL compilers like pidl take a description 32 of an interface as their input and use it to generate C 33 (though support for other languages may be added later) code that 34 can use these interfaces, pretty print data sent 35 using these interfaces, or even generate Wireshark 36 dissectors that can parse data sent over the 37 wire by these interfaces. 38 39 pidl takes IDL files in the same format as is used by midl, 40 40 converts it to a .pidl file (which contains pidl's internal representation of the interface) and can then generate whatever output you need. 41 .pidl files should be used for debugging purposes only. Write your 41 .pidl files should be used for debugging purposes only. Write your 42 42 interface definitions in .idl format. 43 43 44 The goal of pidl is to implement a IDL compiler that can be used 45 while developing the RPC subsystem in Samba (for 44 The goal of pidl is to implement a IDL compiler that can be used 45 while developing the RPC subsystem in Samba (for 46 46 both marshalling/unmarshalling and debugging purposes). 47 47 … … 57 57 58 58 Show pidl version 59 59 60 60 =item I<--outputdir OUTNAME> 61 61 62 Write output files to the specified directory. Defaults to the current 62 Write output files to the specified directory. Defaults to the current 63 63 directory. 64 64 65 65 =item I<--includedir DIR> 66 66 67 Add DIR to the search path used by the preprocessor. This option can be 67 Add DIR to the search path used by the preprocessor. This option can be 68 68 specified multiple times. 69 69 70 70 =item I<--parse-idl-tree> 71 71 72 Read internal tree structure from input files rather 72 Read internal tree structure from input files rather 73 73 than assuming they contain IDL. 74 74 … … 83 83 =item I<--ndr-parser> 84 84 85 Generate a C file and C header containing NDR parsers. The filename for 86 the parser defaults to ndr_OUTNAME.c. The header filename will be the 85 Generate a C file and C header containing NDR parsers. The filename for 86 the parser defaults to ndr_OUTNAME.c. The header filename will be the 87 87 parser filename with the extension changed from .c to .h. 88 88 89 89 =item I<--tdr-parser> 90 90 91 Generate a C file and C header containing TDR parsers. The filename for 92 the parser defaults to tdr_OUTNAME.c. The header filename will be the 91 Generate a C file and C header containing TDR parsers. The filename for 92 the parser defaults to tdr_OUTNAME.c. The header filename will be the 93 93 parser filename with the extension changed from .c to .h. 94 94 … … 99 99 =item I<--server> 100 100 101 Generate boilerplate for the RPC server that implements 101 Generate boilerplate for the RPC server that implements 102 102 the interface. Filename defaults to ndr_OUTNAME_s.c. 103 103 104 104 =item I<--template> 105 105 106 Generate stubs for a RPC server that implements the interface. Output will 106 Generate stubs for a RPC server that implements the interface. Output will 107 107 be written to stdout. 108 108 … … 110 110 111 111 Generate an Wireshark dissector (in C) and header file. The dissector filename 112 defaults to packet-dcerpc-OUTNAME.c while the header filename defaults to 112 defaults to packet-dcerpc-OUTNAME.c while the header filename defaults to 113 113 packet-dcerpc-OUTNAME.h. 114 115 Pidl will read additional data from an Wireshark conformance file if present. 116 Such a file should have the same location as the IDL file but with the 114 115 Pidl will read additional data from an Wireshark conformance file if present. 116 Such a file should have the same location as the IDL file but with the 117 117 extension I<cnf> rather than I<idl>. See L<Parse::Pidl::Wireshark::Conformance> 118 118 for details on the format of this file. … … 120 120 =item I<--diff> 121 121 122 Parse an IDL file, generate a new IDL file based on the internal data 123 structures and see if there are any differences with the original IDL file. 122 Parse an IDL file, generate a new IDL file based on the internal data 123 structures and see if there are any differences with the original IDL file. 124 124 Useful for debugging pidl. 125 125 126 126 =item I<--dump-idl-tree> 127 127 128 Tell pidl to dump the internal tree representation of an IDL 128 Tell pidl to dump the internal tree representation of an IDL 129 129 file the to disk. Useful for debugging pidl. 130 130 131 131 =item I<--dump-ndr-tree> 132 132 133 Tell pidl to dump the internal NDR information tree it generated 133 Tell pidl to dump the internal NDR information tree it generated 134 134 from the IDL file to disk. Useful for debugging pidl. 135 135 136 136 =item I<--samba3-ndr-client> 137 137 138 Generate client calls for Samba3, to be placed in rpc_client/. Instead of 139 calling out to the code in Samba3's rpc_parse/, this will call out to 138 Generate client calls for Samba3, to be placed in rpc_client/. Instead of 139 calling out to the code in Samba3's rpc_parse/, this will call out to 140 140 Samba4's NDR code instead. 141 141 142 142 =item I<--samba3-ndr-server> 143 143 144 Generate server calls for Samba3, to be placed in rpc_server/. Instead of 145 calling out to the code in Samba3's rpc_parse/, this will call out to 144 Generate server calls for Samba3, to be placed in rpc_server/. Instead of 145 calling out to the code in Samba3's rpc_parse/, this will call out to 146 146 Samba4's NDR code instead. 147 147 … … 152 152 IDL files are always preprocessed using the C preprocessor. 153 153 154 Pretty much everything in an interface (the interface itself, functions, 155 parameters) can have attributes (or properties whatever name you give them). 156 Attributes always prepend the element they apply to and are surrounded 157 by square brackets ([]). Multiple attributes are separated by comma's; 158 arguments to attributes are specified between parentheses. 159 160 See the section COMPATIBILITY for the list of attributes that 154 Pretty much everything in an interface (the interface itself, functions, 155 parameters) can have attributes (or properties whatever name you give them). 156 Attributes always prepend the element they apply to and are surrounded 157 by square brackets ([]). Multiple attributes are separated by comma's; 158 arguments to attributes are specified between parentheses. 159 160 See the section COMPATIBILITY for the list of attributes that 161 161 pidl supports. 162 162 163 163 C-style comments can be used. 164 164 165 165 =head2 CONFORMANT ARRAYS 166 166 167 167 A conformant array is one with that ends in [*] or []. The strange 168 things about conformant arrays are that they can only appear as the last 169 element of a structure (unless there is a pointer to the conformant array, 170 of course) and the array size appears before the structure itself on the wire. 168 things about conformant arrays are that they can only appear as the last 169 element of a structure (unless there is a pointer to the conformant array, 170 of course) and the array size appears before the structure itself on the wire. 171 171 172 172 So, in this example: … … 174 174 typedef struct { 175 175 long abc; 176 long count; 176 long count; 177 177 long foo; 178 178 [size_is(count)] long s[*]; … … 194 194 typedef struct { 195 195 long abc; 196 long count; 196 long count; 197 197 long foo; 198 198 long s[1]; … … 203 203 typedef struct { 204 204 long abc; 205 long count; 205 long count; 206 206 long foo; 207 207 long *s; … … 214 214 typedef struct { 215 215 long abc; 216 long count; 216 long count; 217 217 long foo; 218 218 [size_is(count)] long *s; … … 249 249 250 250 Fixed arrays are an extension added to support some of the strange 251 embedded structures in security descriptors and spoolss. 252 253 This section is by no means complete. See the OpenGroup and MSDN 251 embedded structures in security descriptors and spoolss. 252 253 This section is by no means complete. See the OpenGroup and MSDN 254 254 documentation for additional information. 255 255 … … 258 258 =head2 Missing features in pidl 259 259 260 The following MIDL features are not (yet) implemented in pidl 260 The following MIDL features are not (yet) implemented in pidl 261 261 or are implemented with an incompatible interface: 262 262 … … 267 267 Asynchronous communication 268 268 269 =item * 269 =item * 270 270 271 271 Typelibs (.tlb files) … … 279 279 =head2 Supported attributes and statements 280 280 281 in, out, ref, length_is, switch_is, size_is, uuid, case, default, string, 282 unique, ptr, pointer_default, v1_enum, object, helpstring, range, local, 283 call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as, 281 in, out, ref, length_is, switch_is, size_is, uuid, case, default, string, 282 unique, ptr, pointer_default, v1_enum, object, helpstring, range, local, 283 call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as, 284 284 transmit_as, import, include, cpp_quote. 285 285 … … 295 295 specify [public] then pull/push functions for other than top-level 296 296 functions are declared static. 297 297 298 298 =item noprint 299 299 … … 325 325 326 326 Specifies that a size of I<length> 327 bytes should be read, followed by a blob of that size, 327 bytes should be read, followed by a blob of that size, 328 328 which will be parsed as NDR. 329 329 330 subcontext() is deprecated now, and should not be used in new code. 330 subcontext() is deprecated now, and should not be used in new code. 331 331 Instead, use represent_as() or transmit_as(). 332 332 333 333 =item flag 334 334 335 Specify boolean options, mostly used for 336 low-level NDR options. Several options 335 Specify boolean options, mostly used for 336 low-level NDR options. Several options 337 337 can be specified using the | character. 338 338 Note that flags are inherited by substructures! … … 347 347 =item charset(name) 348 348 349 Specify that the array or string uses the specified 350 charset. If this attribute is specified, pidl will 351 take care of converting the character data from this format 349 Specify that the array or string uses the specified 350 charset. If this attribute is specified, pidl will 351 take care of converting the character data from this format 352 352 to the host format. Commonly used values are UCS2, DOS and UTF8. 353 353 … … 356 356 =head2 Unsupported MIDL properties or statements 357 357 358 aggregatable, appobject, async_uuid, bindable, control, 359 defaultbind, defaultcollelem, defaultvalue, defaultvtable, dispinterface, 360 displaybind, dual, entry, first_is, helpcontext, helpfile, helpstringcontext, 361 helpstringdll, hidden, idl_module, idl_quote, id, immediatebind, importlib, 362 includelib, last_is, lcid, licensed, max_is, module, 363 ms_union, no_injected_text, nonbrowsable, noncreatable, nonextensible, odl, 364 oleautomation, optional, pragma, propget, propputref, propput, readonly, 365 requestedit, restricted, retval, source, uidefault, 366 usesgetlasterror, vararg, vi_progid, wire_marshal. 358 aggregatable, appobject, async_uuid, bindable, control, 359 defaultbind, defaultcollelem, defaultvalue, defaultvtable, dispinterface, 360 displaybind, dual, entry, first_is, helpcontext, helpfile, helpstringcontext, 361 helpstringdll, hidden, idl_module, idl_quote, id, immediatebind, importlib, 362 includelib, last_is, lcid, licensed, max_is, module, 363 ms_union, no_injected_text, nonbrowsable, noncreatable, nonextensible, odl, 364 oleautomation, optional, pragma, propget, propputref, propput, readonly, 365 requestedit, restricted, retval, source, uidefault, 366 usesgetlasterror, vararg, vi_progid, wire_marshal. 367 367 368 368 =head1 EXAMPLES … … 370 370 # Generating an Wireshark parser 371 371 $ ./pidl --ws-parser -- atsvc.idl 372 372 373 373 # Generating a TDR parser and header 374 374 $ ./pidl --tdr-parser --header -- regf.idl … … 383 383 384 384 L<http://msdn.microsoft.com/library/en-us/rpc/rpc/field_attributes.asp>, 385 L<http://wiki.wireshark.org/DCE/RPC>, 385 L<http://wiki.wireshark.org/DCE/RPC>, 386 386 L<http://www.samba.org/>, 387 387 L<yapp(1)> … … 393 393 =head1 AUTHOR 394 394 395 pidl was written by Andrew Tridgell, Stefan Metzmacher, Tim Potter and Jelmer 395 pidl was written by Andrew Tridgell, Stefan Metzmacher, Tim Potter and Jelmer 396 396 Vernooij. The current maintainer is Jelmer Vernooij. 397 397 398 This manpage was written by Jelmer Vernooij, partially based on the original 399 pidl README by Andrew Tridgell. 400 398 This manpage was written by Jelmer Vernooij, partially based on the original 399 pidl README by Andrew Tridgell. 400 401 401 =cut 402 402 … … 405 405 use FindBin qw($RealBin $Script); 406 406 use lib "$RealBin/lib"; 407 use lib "$RealBin/../share/perl5";408 407 use Getopt::Long; 409 408 use File::Basename; … … 452 451 my($v) = shift; 453 452 local(*FILE); 454 open(FILE, ">$filename") || die "can't open $filename"; 453 open(FILE, ">$filename") || die "can't open $filename"; 455 454 print FILE $v; 456 455 close(FILE); 457 456 } 458 457 459 my(@opt_incdirs) = (); 458 my(@opt_incdirs) = (); 460 459 my($opt_help) = 0; 461 460 my($opt_version) = 0; … … 471 470 my($opt_samba3_ndr_client); 472 471 my($opt_samba3_ndr_server); 472 my($opt_samba3_template) = 0; 473 473 my($opt_template) = 0; 474 474 my($opt_client); … … 527 527 528 528 Samba 3 output: 529 --samba3-ndr-client[=OUTF] create client calls for Samba3 529 --samba3-ndr-client[=OUTF] create client calls for Samba3 530 530 using Samba4's NDR code [cli_BASENAME.c] 531 --samba3-ndr-server[=OUTF] create server call wrapper for Samba3 531 --samba3-ndr-server[=OUTF] create server call wrapper for Samba3 532 532 using Samba4's NDR code [srv_BASENAME.c] 533 --samba3-template print a template for a pipe 533 534 534 535 Wireshark parsers: … … 547 548 # main program 548 549 my $result = GetOptions ( 549 'help|h|?' => \$opt_help, 550 'help|h|?' => \$opt_help, 550 551 'version' => \$opt_version, 551 552 'outputdir=s' => \$opt_outputdir, … … 556 557 'samba3-ndr-client:s' => \$opt_samba3_ndr_client, 557 558 'samba3-ndr-server:s' => \$opt_samba3_ndr_server, 559 'samba3-template' => \$opt_samba3_template, 558 560 'header:s' => \$opt_header, 559 561 'server:s' => \$opt_server, … … 667 669 if (defined($opt_ws_parser) or 668 670 defined($opt_client) or 669 defined($opt_server) or 671 defined($opt_server) or 670 672 defined($opt_header) or 671 673 defined($opt_ndr_parser) or 672 defined($opt_python) or 674 defined($opt_python) or 673 675 defined($opt_dump_ndr_tree) or 674 defined($opt_samba3_header) or 675 defined($opt_samba3_parser) or 676 defined($opt_samba3_server) or 676 defined($opt_samba3_header) or 677 defined($opt_samba3_parser) or 678 defined($opt_samba3_server) or 677 679 defined($opt_samba3_ndr_client) or 678 680 defined($opt_samba3_ndr_server)) { … … 710 712 if (defined($opt_python)) { 711 713 require Parse::Pidl::Samba4::Python; 712 my $generator = new Parse::Pidl::Samba4::Python(); 713 my ($prsr) = $generator->Parse($basename, $ndr, 714 my $generator = new Parse::Pidl::Samba4::Python(); 715 my ($prsr) = $generator->Parse($basename, $ndr, 714 716 "$outputdir/ndr_$basename\_c.h", $h_filename); 715 717 FileSave("$outputdir/py_$basename.c", $prsr); … … 769 771 } 770 772 773 if ($opt_samba3_template) { 774 require Parse::Pidl::Samba3::Template; 775 print Parse::Pidl::Samba3::Template::Parse($pidl); 776 } 777 771 778 if (defined($opt_samba3_ndr_client)) { 772 779 my $client = ($opt_samba3_ndr_client or "$outputdir/cli_$basename.c"); -
vendor/current/pidl/tests/Util.pm
r740 r988 119 119 my $outfile; 120 120 if (defined($test_data_prefix)) { 121 $outfile = "$test_data_prefix/test-$name"; 121 $outfile = "$test_data_prefix/test-$name"; 122 122 } else { 123 123 $outfile = "./test-$name"; -
vendor/current/pidl/tests/samba-ndr.pl
r740 r988 222 222 ALIGN => 4, 223 223 ELEMENTS => [ ]}, "ndr", "x"); 224 is($generator->{res}, "if (ndr_flags & NDR_SCALARS) { 224 is($generator->{res}, "NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); 225 if (ndr_flags & NDR_SCALARS) { 225 226 NDR_CHECK(ndr_push_align(ndr, 4)); 226 227 NDR_CHECK(ndr_push_trailer_align(ndr, 4)); … … 246 247 SURROUNDING_ELEMENT => $e, 247 248 ELEMENTS => [ $e ]}, "ndr", "x"); 248 is($generator->{res}, "if (ndr_flags & NDR_SCALARS) { 249 is($generator->{res}, "NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); 250 if (ndr_flags & NDR_SCALARS) { 249 251 NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, ndr_string_array_size(ndr, x->el1))); 250 252 NDR_CHECK(ndr_push_align(ndr, 4)); -
vendor/current/pidl/tests/typelist.pl
r414 r988 53 53 54 54 is(1, hasType("foo")); 55 is(0, hasType("nonexist ant"));55 is(0, hasType("nonexistent")); 56 56 is(0, hasType({TYPE => "ENUM", NAME => "someUnknownType"})); 57 57 is(1, hasType({TYPE => "ENUM", NAME => "foo"})); … … 60 60 61 61 is(1, is_scalar("uint32")); 62 is(0, is_scalar("nonexist ant"));62 is(0, is_scalar("nonexistent")); 63 63 is(1, is_scalar({TYPE => "ENUM"})); 64 64 is(0, is_scalar({TYPE => "STRUCT"})); -
vendor/current/pidl/tests/wireshark-conf.pl
r414 r988 16 16 { 17 17 my $str = shift; 18 18 open(TMP, "+>", undef) or die("unable to open temp file"); 19 19 print TMP $str; 20 20 seek(TMP, 0, 0); -
vendor/current/pidl/tests/wireshark-ndr.pl
r414 r988 228 228 229 229 is($x->DumpHfList(), "\tstatic hf_register_info hf[] = { 230 { &hf_bla, 230 { &hf_bla, 231 231 { \"Bla\", \"bla.field\", FT_UINT32, BASE_DEC, NULL, 255, \"NULL\", HFILL }}, 232 232 }; -
vendor/current/pidl/wscript
r740 r988 1 1 #!/usr/bin/env python 2 2 3 import os, sys,Logs3 import os, Logs 4 4 from samba_utils import MODE_755 5 5 6 # This function checks if a perl module is installed on the system. 7 def check_system_perl_module(conf, module, version=None): 8 bundle_name = module.replace('::', '_') 9 module_check = module 10 11 # Create module string with version 12 if version: 13 module_check = module + ' ' + str(version) 14 15 # Check if we have to bundle it. 16 if conf.LIB_MUST_BE_BUNDLED(bundle_name.lower()): 17 return False 18 19 # Check for system perl module 20 if not conf.check_perl_module(module_check): 21 return False 22 23 conf.define('USING_SYSTEM_%s' % bundle_name.upper(), 1) 24 25 return True 26 6 27 def set_options(opt): 7 opt.tool_options('perl')28 return 8 29 9 30 def configure(conf): 10 conf.check_tool('perl') 31 # Check if perl(Parse::Yapp::Driver) is available. 32 check_system_perl_module(conf, "Parse::Yapp::Driver", 1.05) 33 11 34 # we need a recent version of MakeMaker to get the right man page names 12 35 if conf.CHECK_PERL_MANPAGE(): … … 20 43 21 44 def build(bld): 22 bld.INSTALL_FILES('${BINDIR}', 'pidl', chmod=MODE_755 )45 bld.INSTALL_FILES('${BINDIR}', 'pidl', chmod=MODE_755, perl_fixup=True) 23 46 24 47 bld.RECURSE('lib') … … 26 49 if not bld.CONFIG_SET('HAVE_PERL_MAKEMAKER'): 27 50 return 28 29 pidl_src = ['pidl']30 pidl_src.extend(bld.path.ant_glob('lib/**/*.pm').split())31 51 32 52 pidl_manpages = { … … 45 65 bld.env.pidl_srcdir = os.path.join(bld.srcnode.abspath(), 'pidl') 46 66 47 blib_bld = os.path.join(bld.srcnode.abspath(bld.env), 'pidl/blib')48 49 67 bld.SET_BUILD_GROUP('final') 50 68 if 'POD2MAN' in bld.env and bld.env['POD2MAN'] != '': 51 69 for src, manpage in pidl_manpages.iteritems(): 52 bld(rule='${P ERL} ${POD2MAN} -c "Samba Documentation" ${SRC} ${TGT}',70 bld(rule='${POD2MAN} -c "Samba Documentation" ${SRC} ${TGT}', 53 71 shell=True, 54 72 source=src,
Note:
See TracChangeset
for help on using the changeset viewer.