2010-05-11 22:46:19 +04:00
#!/usr/bin/env perl
2000-12-14 07:09:29 +03:00
###################################################
2004-05-09 11:10:12 +04:00
# package to parse IDL files and generate code for
2000-12-14 07:09:29 +03:00
# rpc functions in Samba
2003-11-28 03:48:05 +03:00
# Copyright tridge@samba.org 2000-2003
2007-02-07 22:03:19 +03:00
# Copyright jelmer@samba.org 2005-2007
2000-12-14 07:09:29 +03:00
# released under the GNU GPL
2005-09-21 13:27:17 +04:00
=pod
2005-10-08 04:33:19 +04:00
2005-09-21 13:16:55 +04:00
=head1 NAME
2005-10-08 04:33:19 +04:00
pidl - An IDL compiler written in Perl
2005-09-21 13:16:55 +04:00
=head1 SYNOPSIS
pidl --help
2005-10-08 04:33:19 +04:00
2008-12-16 18:48:48 +03:00
pidl [--outputdir[=OUTNAME]] [--includedir DIR...] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--python[=OUTPUT]] [--ndr-parser[=OUTPUT]] [--client] [--server] [--warn-compat] [--quiet] [--verbose] [--template] [--ws-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-ndr-client[=OUTPUT]] [--samba3-ndr-server[=OUTPUT]] [--typelib=[OUTPUT]] [<idlfile>.idl]...
2005-09-21 13:16:55 +04:00
=head1 DESCRIPTION
2014-09-27 17:41:22 +04:00
pidl is an IDL compiler written in Perl that aims to be somewhat
compatible with the midl compiler. IDL is short for
2005-09-21 13:16:55 +04:00
"Interface Definition Language".
2014-09-27 17:41:22 +04:00
pidl can generate stubs for DCE/RPC server code, DCE/RPC
2006-07-06 00:49:50 +04:00
client code and Wireshark dissectors for DCE/RPC traffic.
2005-09-21 13:16:55 +04:00
2014-09-27 17:41:22 +04:00
IDL compilers like pidl take a description
of an interface as their input and use it to generate C
(though support for other languages may be added later) code that
can use these interfaces, pretty print data sent
using these interfaces, or even generate Wireshark
dissectors that can parse data sent over the
wire by these interfaces.
2005-09-21 13:16:55 +04:00
2014-09-27 17:41:22 +04:00
pidl takes IDL files in the same format as is used by midl,
2005-09-21 13:16:55 +04:00
converts it to a .pidl file (which contains pidl's internal representation of the interface) and can then generate whatever output you need.
2014-09-27 17:41:22 +04:00
.pidl files should be used for debugging purposes only. Write your
2005-09-21 13:16:55 +04:00
interface definitions in .idl format.
2014-09-27 17:41:22 +04:00
The goal of pidl is to implement a IDL compiler that can be used
while developing the RPC subsystem in Samba (for
2005-09-21 13:16:55 +04:00
both marshalling/unmarshalling and debugging purposes).
=head1 OPTIONS
=over 4
=item I<--help>
2005-09-21 13:27:17 +04:00
Show list of available options.
2008-01-18 20:30:00 +03:00
=item I<--version>
Show pidl version
2014-09-27 17:41:22 +04:00
2005-09-21 13:16:55 +04:00
=item I<--outputdir OUTNAME>
2014-09-27 17:41:22 +04:00
Write output files to the specified directory. Defaults to the current
2005-09-21 13:16:55 +04:00
directory.
2006-11-06 23:01:22 +03:00
=item I<--includedir DIR>
2014-09-27 17:41:22 +04:00
Add DIR to the search path used by the preprocessor. This option can be
2006-11-06 23:01:22 +03:00
specified multiple times.
2014-09-27 17:41:22 +04:00
2005-09-21 13:16:55 +04:00
=item I<--parse-idl-tree>
2014-09-27 17:41:22 +04:00
Read internal tree structure from input files rather
2006-06-08 19:20:05 +04:00
than assuming they contain IDL.
2005-09-21 13:16:55 +04:00
=item I<--dump-idl>
2005-09-21 13:27:17 +04:00
Generate a new IDL file. File will be named OUTNAME.idl.
2005-09-21 13:16:55 +04:00
=item I<--header>
Generate a C header file for the specified interface. Filename defaults to OUTNAME.h.
=item I<--ndr-parser>
2014-09-27 17:41:22 +04:00
Generate a C file and C header containing NDR parsers. The filename for
the parser defaults to ndr_OUTNAME.c. The header filename will be the
2005-12-25 04:33:35 +03:00
parser filename with the extension changed from .c to .h.
2005-09-21 13:16:55 +04:00
2005-12-25 18:19:55 +03:00
=item I<--tdr-parser>
2014-09-27 17:41:22 +04:00
Generate a C file and C header containing TDR parsers. The filename for
the parser defaults to tdr_OUTNAME.c. The header filename will be the
2005-12-25 18:19:55 +03:00
parser filename with the extension changed from .c to .h.
2008-01-13 00:15:12 +03:00
=item I<--typelib>
Write type information to the specified file.
2005-09-21 13:16:55 +04:00
=item I<--server>
2014-09-27 17:41:22 +04:00
Generate boilerplate for the RPC server that implements
2005-09-21 13:16:55 +04:00
the interface. Filename defaults to ndr_OUTNAME_s.c.
=item I<--template>
2014-09-27 17:41:22 +04:00
Generate stubs for a RPC server that implements the interface. Output will
2005-09-21 13:16:55 +04:00
be written to stdout.
2006-07-06 00:49:50 +04:00
=item I<--ws-parser>
2005-09-21 13:16:55 +04:00
2006-07-06 00:49:50 +04:00
Generate an Wireshark dissector (in C) and header file. The dissector filename
2014-09-27 17:41:22 +04:00
defaults to packet-dcerpc-OUTNAME.c while the header filename defaults to
2005-09-25 16:27:36 +04:00
packet-dcerpc-OUTNAME.h.
2014-09-27 17:41:22 +04:00
Pidl will read additional data from an Wireshark conformance file if present.
Such a file should have the same location as the IDL file but with the
2006-07-06 00:49:50 +04:00
extension I<cnf> rather than I<idl>. See L<Parse::Pidl::Wireshark::Conformance>
2005-10-08 04:33:19 +04:00
for details on the format of this file.
2005-09-21 13:16:55 +04:00
=item I<--diff>
2014-09-27 17:41:22 +04:00
Parse an IDL file, generate a new IDL file based on the internal data
structures and see if there are any differences with the original IDL file.
2005-09-21 13:16:55 +04:00
Useful for debugging pidl.
=item I<--dump-idl-tree>
2014-09-27 17:41:22 +04:00
Tell pidl to dump the internal tree representation of an IDL
2005-09-21 13:16:55 +04:00
file the to disk. Useful for debugging pidl.
=item I<--dump-ndr-tree>
2014-09-27 17:41:22 +04:00
Tell pidl to dump the internal NDR information tree it generated
2005-09-21 13:16:55 +04:00
from the IDL file to disk. Useful for debugging pidl.
2006-05-04 20:04:08 +04:00
=item I<--samba3-ndr-client>
2014-09-27 17:41:22 +04:00
Generate client calls for Samba3, to be placed in rpc_client/. Instead of
calling out to the code in Samba3's rpc_parse/, this will call out to
2006-05-04 20:04:08 +04:00
Samba4's NDR code instead.
2006-09-13 18:13:48 +04:00
=item I<--samba3-ndr-server>
2014-09-27 17:41:22 +04:00
Generate server calls for Samba3, to be placed in rpc_server/. Instead of
calling out to the code in Samba3's rpc_parse/, this will call out to
2006-09-13 18:13:48 +04:00
Samba4's NDR code instead.
2005-09-21 13:16:55 +04:00
=back
=head1 IDL SYNTAX
IDL files are always preprocessed using the C preprocessor.
2014-09-27 17:41:22 +04:00
Pretty much everything in an interface (the interface itself, functions,
parameters) can have attributes (or properties whatever name you give them).
Attributes always prepend the element they apply to and are surrounded
by square brackets ([]). Multiple attributes are separated by comma's;
arguments to attributes are specified between parentheses.
2005-09-21 13:16:55 +04:00
2014-09-27 17:41:22 +04:00
See the section COMPATIBILITY for the list of attributes that
2005-09-21 13:16:55 +04:00
pidl supports.
C-style comments can be used.
2014-09-27 17:41:22 +04:00
2005-09-21 13:16:55 +04:00
=head2 CONFORMANT ARRAYS
A conformant array is one with that ends in [*] or []. The strange
2014-09-27 17:41:22 +04:00
things about conformant arrays are that they can only appear as the last
element of a structure (unless there is a pointer to the conformant array,
of course) and the array size appears before the structure itself on the wire.
2005-09-21 13:16:55 +04:00
So, in this example:
typedef struct {
long abc;
2014-09-27 17:41:22 +04:00
long count;
2005-09-21 13:16:55 +04:00
long foo;
[size_is(count)] long s[*];
} Struct1;
it appears like this:
[size_is] [abc] [count] [foo] [s...]
the first [size_is] field is the allocation size of the array, and
occurs before the array elements and even before the structure
alignment.
Note that size_is() can refer to a constant, but that doesn't change
the wire representation. It does not make the array a fixed array.
midl.exe would write the above array as the following C header:
typedef struct {
long abc;
2014-09-27 17:41:22 +04:00
long count;
2005-09-21 13:16:55 +04:00
long foo;
long s[1];
} Struct1;
pidl takes a different approach, and writes it like this:
2016-02-05 17:25:57 +03:00
typedef struct {
2005-09-21 13:16:55 +04:00
long abc;
2014-09-27 17:41:22 +04:00
long count;
2005-09-21 13:16:55 +04:00
long foo;
long *s;
} Struct1;
=head2 VARYING ARRAYS
A varying array looks like this:
typedef struct {
long abc;
2014-09-27 17:41:22 +04:00
long count;
2005-09-21 13:16:55 +04:00
long foo;
[size_is(count)] long *s;
} Struct1;
This will look like this on the wire:
[abc] [count] [foo] [PTR_s] [count] [s...]
=head2 FIXED ARRAYS
A fixed array looks like this:
2016-02-05 17:25:57 +03:00
typedef struct {
long s[10];
} Struct1;
2005-09-21 13:16:55 +04:00
The NDR representation looks just like 10 separate long
declarations. The array size is not encoded on the wire.
pidl also supports "inline" arrays, which are not part of the IDL/NDR
standard. These are declared like this:
2016-02-05 17:25:57 +03:00
typedef struct {
uint32 foo;
uint32 count;
uint32 bar;
long s[count];
} Struct1;
2005-09-21 13:16:55 +04:00
This appears like this:
[foo] [count] [bar] [s...]
Fixed arrays are an extension added to support some of the strange
2014-09-27 17:41:22 +04:00
embedded structures in security descriptors and spoolss.
2005-09-21 13:16:55 +04:00
2014-09-27 17:41:22 +04:00
This section is by no means complete. See the OpenGroup and MSDN
2005-09-21 13:16:55 +04:00
documentation for additional information.
=head1 COMPATIBILITY WITH MIDL
=head2 Missing features in pidl
2014-09-27 17:41:22 +04:00
The following MIDL features are not (yet) implemented in pidl
2005-09-21 13:16:55 +04:00
or are implemented with an incompatible interface:
=over
2005-09-21 13:27:17 +04:00
=item *
Asynchronous communication
2014-09-27 17:41:22 +04:00
=item *
2005-09-21 13:27:17 +04:00
Typelibs (.tlb files)
=item *
Datagram support (ncadg_*)
2005-09-21 13:16:55 +04:00
=back
2006-11-22 02:15:57 +03:00
=head2 Supported attributes and statements
2005-09-21 13:16:55 +04:00
2014-09-27 17:41:22 +04:00
in, out, ref, length_is, switch_is, size_is, uuid, case, default, string,
unique, ptr, pointer_default, v1_enum, object, helpstring, range, local,
call_as, endpoint, switch_type, progid, coclass, iid_is, represent_as,
2007-08-31 04:03:54 +04:00
transmit_as, import, include, cpp_quote.
2005-09-21 13:16:55 +04:00
=head2 PIDL Specific properties
=over 4
=item public
The [public] property on a structure or union is a pidl extension that
forces the generated pull/push functions to be non-static. This allows
you to declare types that can be used between modules. If you don't
specify [public] then pull/push functions for other than top-level
functions are declared static.
2014-09-27 17:41:22 +04:00
2005-09-21 13:16:55 +04:00
=item noprint
The [noprint] property is a pidl extension that allows you to specify
that pidl should not generate a ndr_print_*() function for that
structure or union. This is used when you wish to define your own
print function that prints a structure in a nicer manner. A good
example is the use of [noprint] on dom_sid, which allows the
pretty-printing of SIDs.
=item value
The [value(expression)] property is a pidl extension that allows you
to specify the value of a field when it is put on the wire. This
allows fields that always have a well-known value to be automatically
filled in, thus making the API more programmer friendly. The
expression can be any C expression.
=item relative
The [relative] property can be supplied on a pointer. When it is used
it declares the pointer as a spoolss style "relative" pointer, which
means it appears on the wire as an offset within the current
encapsulating structure. This is not part of normal IDL/NDR, but it is
a very useful extension as it avoids the manual encoding of many
complex structures.
=item subcontext(length)
Specifies that a size of I<length>
2014-09-27 17:41:22 +04:00
bytes should be read, followed by a blob of that size,
2005-09-21 13:16:55 +04:00
which will be parsed as NDR.
2014-09-27 17:41:22 +04:00
subcontext() is deprecated now, and should not be used in new code.
2007-02-07 22:03:19 +03:00
Instead, use represent_as() or transmit_as().
2005-09-21 13:16:55 +04:00
=item flag
2014-09-27 17:41:22 +04:00
Specify boolean options, mostly used for
low-level NDR options. Several options
2005-09-21 13:16:55 +04:00
can be specified using the | character.
Note that flags are inherited by substructures!
=item nodiscriminant
The [nodiscriminant] property on a union means that the usual uint16
discriminent field at the start of the union on the wire is
omitted. This is not normally allowed in IDL/NDR, but is used for some
spoolss structures.
=item charset(name)
2014-09-27 17:41:22 +04:00
Specify that the array or string uses the specified
charset. If this attribute is specified, pidl will
take care of converting the character data from this format
2005-09-21 13:16:55 +04:00
to the host format. Commonly used values are UCS2, DOS and UTF8.
=back
2006-11-22 02:15:57 +03:00
=head2 Unsupported MIDL properties or statements
2005-09-21 13:16:55 +04:00
2014-09-27 17:41:22 +04:00
aggregatable, appobject, async_uuid, bindable, control,
defaultbind, defaultcollelem, defaultvalue, defaultvtable, dispinterface,
displaybind, dual, entry, first_is, helpcontext, helpfile, helpstringcontext,
helpstringdll, hidden, idl_module, idl_quote, id, immediatebind, importlib,
includelib, last_is, lcid, licensed, max_is, module,
ms_union, no_injected_text, nonbrowsable, noncreatable, nonextensible, odl,
oleautomation, optional, pragma, propget, propputref, propput, readonly,
requestedit, restricted, retval, source, uidefault,
usesgetlasterror, vararg, vi_progid, wire_marshal.
2005-09-21 13:16:55 +04:00
=head1 EXAMPLES
2006-07-06 00:49:50 +04:00
# Generating an Wireshark parser
$ ./pidl --ws-parser -- atsvc.idl
2014-09-27 17:41:22 +04:00
2005-10-08 04:33:19 +04:00
# Generating a TDR parser and header
2005-12-25 18:19:55 +03:00
$ ./pidl --tdr-parser --header -- regf.idl
2005-09-21 13:16:55 +04:00
2006-09-13 18:13:48 +04:00
# Generating a Samba3 client and server
$ ./pidl --samba3-ndr-client --samba3-ndr-server -- dfs.idl
2005-09-21 13:16:55 +04:00
2005-10-08 04:33:19 +04:00
# Generating a Samba4 NDR parser, client and server
$ ./pidl --ndr-parser --ndr-client --ndr-server -- samr.idl
2005-09-21 13:16:55 +04:00
=head1 SEE ALSO
2016-02-09 17:43:53 +03:00
L<https://msdn.microsoft.com/en-us/library/windows/desktop/aa373864%28v=vs.85%29.aspx>
L<https://wiki.wireshark.org/DCE/RPC>,
L<https://www.samba.org/>,
2005-10-08 04:33:19 +04:00
L<yapp(1)>
2005-09-21 13:16:55 +04:00
2005-09-25 16:27:36 +04:00
=head1 LICENSE
2016-02-09 17:43:53 +03:00
pidl is licensed under the GNU General Public License L<https://www.gnu.org/licenses/gpl.html>.
2005-09-25 16:27:36 +04:00
2005-09-21 13:16:55 +04:00
=head1 AUTHOR
2014-09-27 17:41:22 +04:00
pidl was written by Andrew Tridgell, Stefan Metzmacher, Tim Potter and Jelmer
2005-10-08 04:33:19 +04:00
Vernooij. The current maintainer is Jelmer Vernooij.
2005-09-21 13:16:55 +04:00
2014-09-27 17:41:22 +04:00
This manpage was written by Jelmer Vernooij, partially based on the original
pidl README by Andrew Tridgell.
2005-09-21 13:16:55 +04:00
=cut
2005-09-21 13:27:17 +04:00
2000-12-14 07:09:29 +03:00
use strict;
2019-11-30 12:34:54 +03:00
use warnings;
2007-01-12 01:47:29 +03:00
use FindBin qw($RealBin $Script);
2005-08-22 04:22:21 +04:00
use lib "$RealBin/lib";
2000-12-14 07:09:29 +03:00
use Getopt::Long;
2003-11-23 06:42:20 +03:00
use File::Basename;
2008-01-18 20:30:00 +03:00
use Parse::Pidl qw ( $VERSION );
2005-07-09 19:32:08 +04:00
use Parse::Pidl::Util;
2008-09-12 16:33:20 +04:00
use Parse::Pidl::ODL;
2005-07-09 19:32:08 +04:00
#####################################################################
# save a data structure into a file
sub SaveStructure($$)
{
my($filename,$v) = @_;
2005-08-03 02:01:04 +04:00
FileSave($filename, Parse::Pidl::Util::MyDumper($v));
2005-07-09 19:32:08 +04:00
}
#####################################################################
# load a data structure from a file (as saved with SaveStructure)
sub LoadStructure($)
{
my $f = shift;
2005-08-03 02:01:04 +04:00
my $contents = FileLoad($f);
2005-07-09 19:32:08 +04:00
defined $contents || return undef;
return eval "$contents";
}
2000-12-14 07:09:29 +03:00
2005-08-03 02:01:04 +04:00
#####################################################################
# read a file into a string
sub FileLoad($)
{
2016-02-05 17:25:57 +03:00
my($filename) = shift;
local(*INPUTFILE);
open(INPUTFILE, $filename) || return undef;
my($saved_delim) = $/;
undef $/;
my($data) = <INPUTFILE>;
close(INPUTFILE);
$/ = $saved_delim;
return $data;
2005-08-03 02:01:04 +04:00
}
#####################################################################
# write a string into a file
sub FileSave($$)
{
2016-02-05 17:25:57 +03:00
my($filename) = shift;
my($v) = shift;
local(*FILE);
open(FILE, ">$filename") || die "can't open $filename";
print FILE $v;
close(FILE);
2005-08-03 02:01:04 +04:00
}
2014-09-27 17:41:22 +04:00
my(@opt_incdirs) = ();
2000-12-14 07:09:29 +03:00
my($opt_help) = 0;
2008-01-18 20:30:00 +03:00
my($opt_version) = 0;
2005-09-12 17:49:51 +04:00
my($opt_parse_idl_tree) = 0;
my($opt_dump_idl_tree);
my($opt_dump_ndr_tree);
2005-09-09 14:59:54 +04:00
my($opt_dump_idl) = 0;
2000-12-14 07:09:29 +03:00
my($opt_diff) = 0;
2005-07-28 01:09:16 +04:00
my($opt_header);
2005-10-04 03:27:33 +04:00
my($opt_samba3_header);
my($opt_samba3_parser);
my($opt_samba3_server);
2006-05-04 20:04:08 +04:00
my($opt_samba3_ndr_client);
2006-09-13 18:13:48 +04:00
my($opt_samba3_ndr_server);
2013-01-21 21:42:45 +04:00
my($opt_samba3_template) = 0;
2003-12-15 13:55:10 +03:00
my($opt_template) = 0;
2005-06-15 14:11:33 +04:00
my($opt_client);
2008-01-13 00:15:12 +03:00
my($opt_typelib);
2005-06-15 14:11:33 +04:00
my($opt_server);
2005-07-27 23:58:09 +04:00
my($opt_ndr_parser);
2005-08-03 00:12:31 +04:00
my($opt_tdr_parser);
2006-07-06 00:49:50 +04:00
my($opt_ws_parser);
2008-01-04 06:21:16 +03:00
my($opt_python);
2005-05-17 15:43:46 +04:00
my($opt_quiet) = 0;
2005-07-27 22:53:07 +04:00
my($opt_outputdir) = '.';
2005-06-15 14:11:33 +04:00
my($opt_verbose) = 0;
r6973: Merge new version of pidl into the main SAMBA_4_0 branch.
The main difference in this new version is the extra data structure generated
between the IDL data structure and the NDR parser:
IDL -> NDR -> { ndr_parser, ndr_header, eparser, etc }
This makes the ndr_parser.pm internals much more sane.
Other changes include:
- Remove unnecessary calls with NDR_BUFFERS (for example, GUID doesn't have any buffers, just scalars) as well as some (unnecessary) nested setting of flags.
- Parse array loops in the C code rather then calling ndr_pull_array(). This allows us to have, for example, arrays of pointers or arrays of pointers to arrays, etc..
- Use if() {} rather then if () goto foo; everywhere
- NDR_IN no longer implies LIBNDR_FLAG_REF_ALLOC
- By default, top level pointers are now "ref" (as is the default in
most other IDL compilers). This can be overridden using the
default_pointer_top() property.
- initial work on new ethereal parser generators by Alan DeKok and me
- pidl now writes errors in the standard format used by compilers, which
is parsable by most editors
- ability to warn about the fact that pidl extension(s) have been used,
useful for making sure IDL files work with other IDL compilers.
oh, and there's probably some other things I can't think of right now..
(This used to be commit 13cf227615f6b9e0e5fa62e59197024410254f01)
2005-05-25 17:50:27 +04:00
my($opt_warn_compat) = 0;
2008-05-09 15:20:42 +04:00
my($opt_dcom_proxy);
my($opt_com_header);
2000-12-14 07:09:29 +03:00
#########################################
# display help text
sub ShowHelp()
{
2008-01-18 20:30:00 +03:00
print "perl IDL parser and code generator\n";
ShowVersion();
print"
2005-10-08 04:33:19 +04:00
Copyright (C) Andrew Tridgell <tridge\@samba.org>
Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
2005-02-21 17:30:49 +03:00
2007-01-12 01:47:29 +03:00
Usage: $Script [options] [--] <idlfile> [<idlfile>...]
2005-08-20 23:39:19 +04:00
Generic Options:
--help this help page
2008-01-18 20:30:00 +03:00
--version show pidl version
2005-08-20 23:39:19 +04:00
--outputdir=OUTDIR put output in OUTDIR/ [.]
--warn-compat warn about incompatibility with other compilers
--quiet be quiet
--verbose be verbose
2006-11-06 23:01:22 +03:00
--includedir DIR search DIR for included files
2005-08-20 23:39:19 +04:00
2005-09-09 14:59:54 +04:00
Debugging:
2005-09-12 17:49:51 +04:00
--dump-idl-tree[=FILE] dump internal representation to file [BASENAME.pidl]
--parse-idl-tree read internal representation instead of IDL
--dump-ndr-tree[=FILE] dump internal NDR data tree to file [BASENAME.ndr]
2005-09-09 14:59:54 +04:00
--dump-idl regenerate IDL file
--diff run diff on original IDL and dumped output
2008-01-13 00:15:12 +03:00
--typelib print type information
2005-09-09 14:59:54 +04:00
2005-08-20 23:39:19 +04:00
Samba 4 output:
2005-08-24 15:17:28 +04:00
--header[=OUTFILE] create generic header file [BASENAME.h]
--ndr-parser[=OUTFILE] create a C NDR parser [ndr_BASENAME.c]
--client[=OUTFILE] create a C NDR client [ndr_BASENAME_c.c]
--tdr-parser[=OUTFILE] create a C TDR parser [tdr_BASENAME.c]
2008-01-04 06:21:16 +03:00
--python[=OUTFILE] create python wrapper file [py_BASENAME.c]
2005-08-24 15:17:28 +04:00
--server[=OUTFILE] create server boilerplate [ndr_BASENAME_s.c]
2005-08-20 23:39:19 +04:00
--template print a template for a pipe
2008-05-09 15:20:42 +04:00
--dcom-proxy[=OUTFILE] create DCOM proxy [ndr_BASENAME_p.c]
--com-header[=OUTFILE] create header for COM [com_BASENAME.h]
2005-02-21 17:30:49 +03:00
2005-10-04 03:27:33 +04:00
Samba 3 output:
2014-09-27 17:41:22 +04:00
--samba3-ndr-client[=OUTF] create client calls for Samba3
2006-05-04 20:04:08 +04:00
using Samba4's NDR code [cli_BASENAME.c]
2014-09-27 17:41:22 +04:00
--samba3-ndr-server[=OUTF] create server call wrapper for Samba3
2006-09-13 18:13:48 +04:00
using Samba4's NDR code [srv_BASENAME.c]
2013-01-21 21:42:45 +04:00
--samba3-template print a template for a pipe
2005-10-04 03:27:33 +04:00
2006-07-06 00:49:50 +04:00
Wireshark parsers:
--ws-parser[=OUTFILE] create Wireshark parser and header
2005-05-29 03:38:52 +04:00
\n";
2016-02-05 17:25:57 +03:00
exit(0);
2000-12-14 07:09:29 +03:00
}
2008-01-18 20:30:00 +03:00
#########################################
# Display version
sub ShowVersion()
{
2016-02-05 17:25:57 +03:00
print "perl IDL version $VERSION\n";
2008-01-18 20:30:00 +03:00
}
2000-12-14 07:09:29 +03:00
# main program
2005-09-23 17:06:23 +04:00
my $result = GetOptions (
2016-02-05 17:25:57 +03:00
'help|h|?' => \$opt_help,
'version' => \$opt_version,
'outputdir=s' => \$opt_outputdir,
'dump-idl' => \$opt_dump_idl,
2005-09-12 17:49:51 +04:00
'dump-idl-tree:s' => \$opt_dump_idl_tree,
'parse-idl-tree' => \$opt_parse_idl_tree,
'dump-ndr-tree:s' => \$opt_dump_ndr_tree,
2006-05-04 20:04:08 +04:00
'samba3-ndr-client:s' => \$opt_samba3_ndr_client,
2006-09-13 18:13:48 +04:00
'samba3-ndr-server:s' => \$opt_samba3_ndr_server,
2016-02-05 17:25:57 +03:00
'samba3-template' => \$opt_samba3_template,
2005-07-28 01:09:16 +04:00
'header:s' => \$opt_header,
2016-02-05 17:25:57 +03:00
'server:s' => \$opt_server,
2008-01-13 00:15:12 +03:00
'typelib:s' => \$opt_typelib,
2016-02-05 17:25:57 +03:00
'tdr-parser:s' => \$opt_tdr_parser,
'template' => \$opt_template,
'ndr-parser:s' => \$opt_ndr_parser,
'client:s' => \$opt_client,
'ws-parser:s' => \$opt_ws_parser,
2008-01-04 06:21:16 +03:00
'python' => \$opt_python,
2016-02-05 17:25:57 +03:00
'diff' => \$opt_diff,
'dcom-proxy:s' => \$opt_dcom_proxy,
2008-05-09 15:20:42 +04:00
'com-header:s' => \$opt_com_header,
2016-02-05 17:25:57 +03:00
'quiet' => \$opt_quiet,
2005-06-15 14:11:33 +04:00
'verbose' => \$opt_verbose,
2016-02-05 17:25:57 +03:00
'warn-compat' => \$opt_warn_compat,
2006-11-06 23:01:22 +03:00
'includedir=s@' => \@opt_incdirs
2016-02-05 17:25:57 +03:00
);
2000-12-14 07:09:29 +03:00
2005-09-23 17:06:23 +04:00
if (not $result) {
exit(1);
}
2000-12-14 07:41:45 +03:00
if ($opt_help) {
2016-02-05 17:25:57 +03:00
ShowHelp();
exit(0);
2000-12-14 07:41:45 +03:00
}
2008-01-18 20:30:00 +03:00
if ($opt_version) {
2016-02-05 17:25:57 +03:00
ShowVersion();
exit(0);
2008-01-18 20:30:00 +03:00
}
2003-11-23 06:42:20 +03:00
sub process_file($)
{
my $idl_file = shift;
2005-07-27 22:53:07 +04:00
my $outputdir = $opt_outputdir;
2003-12-08 02:47:35 +03:00
my $pidl;
r6973: Merge new version of pidl into the main SAMBA_4_0 branch.
The main difference in this new version is the extra data structure generated
between the IDL data structure and the NDR parser:
IDL -> NDR -> { ndr_parser, ndr_header, eparser, etc }
This makes the ndr_parser.pm internals much more sane.
Other changes include:
- Remove unnecessary calls with NDR_BUFFERS (for example, GUID doesn't have any buffers, just scalars) as well as some (unnecessary) nested setting of flags.
- Parse array loops in the C code rather then calling ndr_pull_array(). This allows us to have, for example, arrays of pointers or arrays of pointers to arrays, etc..
- Use if() {} rather then if () goto foo; everywhere
- NDR_IN no longer implies LIBNDR_FLAG_REF_ALLOC
- By default, top level pointers are now "ref" (as is the default in
most other IDL compilers). This can be overridden using the
default_pointer_top() property.
- initial work on new ethereal parser generators by Alan DeKok and me
- pidl now writes errors in the standard format used by compilers, which
is parsable by most editors
- ability to warn about the fact that pidl extension(s) have been used,
useful for making sure IDL files work with other IDL compilers.
oh, and there's probably some other things I can't think of right now..
(This used to be commit 13cf227615f6b9e0e5fa62e59197024410254f01)
2005-05-25 17:50:27 +04:00
my $ndr;
2003-11-23 06:42:20 +03:00
my $basename = basename($idl_file, ".idl");
2005-05-17 15:43:46 +04:00
unless ($opt_quiet) { print "Compiling $idl_file\n"; }
2003-12-07 16:39:45 +03:00
2005-09-12 17:49:51 +04:00
if ($opt_parse_idl_tree) {
$pidl = LoadStructure($idl_file);
defined $pidl || die "Failed to load $idl_file";
2005-09-09 14:59:54 +04:00
} else {
2005-07-09 19:32:08 +04:00
require Parse::Pidl::IDL;
2006-11-06 23:01:22 +03:00
$pidl = Parse::Pidl::IDL::parse_file($idl_file, \@opt_incdirs);
2013-05-25 18:19:24 +04:00
defined $pidl || die "Failed to parse $idl_file";
2005-09-09 14:59:54 +04:00
}
2008-09-16 06:35:34 +04:00
require Parse::Pidl::Typelist;
2008-12-22 03:51:38 +03:00
Parse::Pidl::Typelist::LoadIdl($pidl, $basename);
2008-09-16 06:35:34 +04:00
2005-09-12 17:49:51 +04:00
if (defined($opt_dump_idl_tree)) {
my($pidl_file) = ($opt_dump_idl_tree or "$outputdir/$basename.pidl");
SaveStructure($pidl_file, $pidl) or die "Failed to save $pidl_file\n";
2003-11-23 06:42:20 +03:00
}
2004-04-26 06:05:48 +04:00
2005-09-09 14:59:54 +04:00
if ($opt_dump_idl) {
2005-07-09 19:32:08 +04:00
require Parse::Pidl::Dump;
print Parse::Pidl::Dump($pidl);
2003-11-23 06:42:20 +03:00
}
2004-05-09 11:10:12 +04:00
2005-02-21 17:30:49 +03:00
if ($opt_diff) {
2005-07-27 22:53:07 +04:00
my($tempfile) = "$outputdir/$basename.tmp";
2005-08-03 02:01:04 +04:00
FileSave($tempfile, IdlDump::Dump($pidl));
2005-02-21 17:30:49 +03:00
system("diff -wu $idl_file $tempfile");
unlink($tempfile);
}
2008-05-09 15:20:42 +04:00
my $comh_filename = ($opt_com_header or "$outputdir/com_$basename.h");
if (defined($opt_com_header)) {
require Parse::Pidl::Samba4::COM::Header;
my $res = Parse::Pidl::Samba4::COM::Header::Parse($pidl,"$outputdir/ndr_$basename.h");
if ($res) {
FileSave($comh_filename, $res);
}
}
if (defined($opt_dcom_proxy)) {
require Parse::Pidl::Samba4::COM::Proxy;
my $res = Parse::Pidl::Samba4::COM::Proxy::Parse($pidl,$comh_filename);
if ($res) {
my ($client) = ($opt_dcom_proxy or "$outputdir/$basename\_p.c");
FileSave($client, $res);
}
}
r6973: Merge new version of pidl into the main SAMBA_4_0 branch.
The main difference in this new version is the extra data structure generated
between the IDL data structure and the NDR parser:
IDL -> NDR -> { ndr_parser, ndr_header, eparser, etc }
This makes the ndr_parser.pm internals much more sane.
Other changes include:
- Remove unnecessary calls with NDR_BUFFERS (for example, GUID doesn't have any buffers, just scalars) as well as some (unnecessary) nested setting of flags.
- Parse array loops in the C code rather then calling ndr_pull_array(). This allows us to have, for example, arrays of pointers or arrays of pointers to arrays, etc..
- Use if() {} rather then if () goto foo; everywhere
- NDR_IN no longer implies LIBNDR_FLAG_REF_ALLOC
- By default, top level pointers are now "ref" (as is the default in
most other IDL compilers). This can be overridden using the
default_pointer_top() property.
- initial work on new ethereal parser generators by Alan DeKok and me
- pidl now writes errors in the standard format used by compilers, which
is parsable by most editors
- ability to warn about the fact that pidl extension(s) have been used,
useful for making sure IDL files work with other IDL compilers.
oh, and there's probably some other things I can't think of right now..
(This used to be commit 13cf227615f6b9e0e5fa62e59197024410254f01)
2005-05-25 17:50:27 +04:00
if ($opt_warn_compat) {
2005-07-09 19:32:08 +04:00
require Parse::Pidl::Compat;
Parse::Pidl::Compat::Check($pidl);
r6973: Merge new version of pidl into the main SAMBA_4_0 branch.
The main difference in this new version is the extra data structure generated
between the IDL data structure and the NDR parser:
IDL -> NDR -> { ndr_parser, ndr_header, eparser, etc }
This makes the ndr_parser.pm internals much more sane.
Other changes include:
- Remove unnecessary calls with NDR_BUFFERS (for example, GUID doesn't have any buffers, just scalars) as well as some (unnecessary) nested setting of flags.
- Parse array loops in the C code rather then calling ndr_pull_array(). This allows us to have, for example, arrays of pointers or arrays of pointers to arrays, etc..
- Use if() {} rather then if () goto foo; everywhere
- NDR_IN no longer implies LIBNDR_FLAG_REF_ALLOC
- By default, top level pointers are now "ref" (as is the default in
most other IDL compilers). This can be overridden using the
default_pointer_top() property.
- initial work on new ethereal parser generators by Alan DeKok and me
- pidl now writes errors in the standard format used by compilers, which
is parsable by most editors
- ability to warn about the fact that pidl extension(s) have been used,
useful for making sure IDL files work with other IDL compilers.
oh, and there's probably some other things I can't think of right now..
(This used to be commit 13cf227615f6b9e0e5fa62e59197024410254f01)
2005-05-25 17:50:27 +04:00
}
2008-09-12 16:57:19 +04:00
$pidl = Parse::Pidl::ODL::ODL2IDL($pidl, dirname($idl_file), \@opt_incdirs);
2008-09-12 16:33:20 +04:00
2009-10-06 10:49:59 +04:00
if (defined($opt_ws_parser)) {
2016-02-05 17:25:57 +03:00
require Parse::Pidl::Wireshark::NDR;
2009-10-06 10:49:59 +04:00
2016-02-05 17:25:57 +03:00
my $cnffile = $idl_file;
$cnffile =~ s/\.idl$/\.cnf/;
2009-10-06 10:49:59 +04:00
2016-02-05 17:25:57 +03:00
my $generator = new Parse::Pidl::Wireshark::NDR();
$generator->Initialize($cnffile);
2009-10-06 10:49:59 +04:00
}
if (defined($opt_ws_parser) or
2016-02-05 17:25:57 +03:00
defined($opt_client) or
defined($opt_server) or
defined($opt_header) or
defined($opt_ndr_parser) or
defined($opt_python) or
defined($opt_dump_ndr_tree) or
defined($opt_samba3_header) or
defined($opt_samba3_parser) or
defined($opt_samba3_server) or
defined($opt_samba3_ndr_client) or
defined($opt_samba3_ndr_server)) {
2005-07-09 19:32:08 +04:00
require Parse::Pidl::NDR;
$ndr = Parse::Pidl::NDR::Parse($pidl);
r6973: Merge new version of pidl into the main SAMBA_4_0 branch.
The main difference in this new version is the extra data structure generated
between the IDL data structure and the NDR parser:
IDL -> NDR -> { ndr_parser, ndr_header, eparser, etc }
This makes the ndr_parser.pm internals much more sane.
Other changes include:
- Remove unnecessary calls with NDR_BUFFERS (for example, GUID doesn't have any buffers, just scalars) as well as some (unnecessary) nested setting of flags.
- Parse array loops in the C code rather then calling ndr_pull_array(). This allows us to have, for example, arrays of pointers or arrays of pointers to arrays, etc..
- Use if() {} rather then if () goto foo; everywhere
- NDR_IN no longer implies LIBNDR_FLAG_REF_ALLOC
- By default, top level pointers are now "ref" (as is the default in
most other IDL compilers). This can be overridden using the
default_pointer_top() property.
- initial work on new ethereal parser generators by Alan DeKok and me
- pidl now writes errors in the standard format used by compilers, which
is parsable by most editors
- ability to warn about the fact that pidl extension(s) have been used,
useful for making sure IDL files work with other IDL compilers.
oh, and there's probably some other things I can't think of right now..
(This used to be commit 13cf227615f6b9e0e5fa62e59197024410254f01)
2005-05-25 17:50:27 +04:00
}
2005-09-12 17:49:51 +04:00
if (defined($opt_dump_ndr_tree)) {
my($ndr_file) = ($opt_dump_ndr_tree or "$outputdir/$basename.ndr");
SaveStructure($ndr_file, $ndr) or die "Failed to save $ndr_file\n";
}
2005-12-25 18:19:55 +03:00
my $gen_header = ($opt_header or "$outputdir/$basename.h");
2005-07-28 01:09:16 +04:00
if (defined($opt_header)) {
2005-12-25 01:11:44 +03:00
require Parse::Pidl::Samba4::Header;
2007-08-16 14:54:11 +04:00
FileSave($gen_header, Parse::Pidl::Samba4::Header::Parse($ndr));
2005-07-28 01:09:16 +04:00
}
2005-07-27 22:53:07 +04:00
my $h_filename = "$outputdir/ndr_$basename.h";
2010-08-05 23:01:25 +04:00
my $c_header = "$outputdir/ndr_$basename\_c.h";
if (defined($opt_client) or defined($opt_samba3_ndr_client)) {
2005-12-25 01:11:44 +03:00
require Parse::Pidl::Samba4::NDR::Client;
2006-03-15 02:35:30 +03:00
my ($c_client) = ($opt_client or "$outputdir/ndr_$basename\_c.c");
2010-08-05 23:01:25 +04:00
$c_header = $c_client;
2006-03-15 02:35:30 +03:00
$c_header =~ s/\.c$/.h/;
2004-11-18 23:53:23 +03:00
2010-08-05 15:29:56 +04:00
my $generator = new Parse::Pidl::Samba4::NDR::Client();
my ($srcd,$hdrd) = $generator->Parse(
2006-03-15 02:35:30 +03:00
$ndr,$gen_header,$h_filename,$c_header);
FileSave($c_client, $srcd);
FileSave($c_header, $hdrd);
2004-11-18 23:53:23 +03:00
}
2008-01-04 06:21:16 +03:00
if (defined($opt_python)) {
require Parse::Pidl::Samba4::Python;
2014-09-27 17:41:22 +04:00
my $generator = new Parse::Pidl::Samba4::Python();
2019-06-25 06:41:40 +03:00
if (!defined($opt_client)) {
$c_header = undef;
}
2014-09-27 17:41:22 +04:00
my ($prsr) = $generator->Parse($basename, $ndr,
2019-06-25 06:41:40 +03:00
$c_header, $h_filename);
2008-01-04 06:21:16 +03:00
FileSave("$outputdir/py_$basename.c", $prsr);
}
2005-06-15 14:11:33 +04:00
if (defined($opt_server)) {
2005-12-25 01:11:44 +03:00
require Parse::Pidl::Samba4::NDR::Server;
2004-11-19 23:21:13 +03:00
2005-12-25 01:11:44 +03:00
FileSave(($opt_server or "$outputdir/ndr_$basename\_s.c"), Parse::Pidl::Samba4::NDR::Server::Parse($ndr,$h_filename));
2003-12-14 16:22:12 +03:00
}
2004-05-09 11:10:12 +04:00
2005-07-27 23:58:09 +04:00
if (defined($opt_ndr_parser)) {
2005-12-25 04:33:35 +03:00
my $parser_fname = ($opt_ndr_parser or "$outputdir/ndr_$basename.c");
2005-12-25 01:11:44 +03:00
require Parse::Pidl::Samba4::NDR::Parser;
2007-04-22 19:59:34 +04:00
my $generator = new Parse::Pidl::Samba4::NDR::Parser();
my ($header,$parser) = $generator->Parse($ndr, $gen_header, $h_filename);
2005-12-25 04:33:35 +03:00
FileSave($parser_fname, $parser);
2006-03-16 23:02:31 +03:00
FileSave($h_filename, $header);
2005-12-25 04:33:35 +03:00
2004-09-08 15:54:01 +04:00
}
2006-07-06 00:49:50 +04:00
if (defined($opt_ws_parser)) {
2016-02-05 17:25:57 +03:00
require Parse::Pidl::Wireshark::NDR;
my($eparser) = ($opt_ws_parser or "$outputdir/packet-dcerpc-$basename.c");
my $eheader = $eparser;
$eheader =~ s/\.c$/\.h/;
my $cnffile = $idl_file;
$cnffile =~ s/\.idl$/\.cnf/;
my $generator = new Parse::Pidl::Wireshark::NDR();
my ($dp, $dh) = $generator->Parse($ndr, $idl_file, $eheader, $cnffile);
FileSave($eparser, $dp) if defined($dp);
FileSave($eheader, $dh) if defined($dh);
r6973: Merge new version of pidl into the main SAMBA_4_0 branch.
The main difference in this new version is the extra data structure generated
between the IDL data structure and the NDR parser:
IDL -> NDR -> { ndr_parser, ndr_header, eparser, etc }
This makes the ndr_parser.pm internals much more sane.
Other changes include:
- Remove unnecessary calls with NDR_BUFFERS (for example, GUID doesn't have any buffers, just scalars) as well as some (unnecessary) nested setting of flags.
- Parse array loops in the C code rather then calling ndr_pull_array(). This allows us to have, for example, arrays of pointers or arrays of pointers to arrays, etc..
- Use if() {} rather then if () goto foo; everywhere
- NDR_IN no longer implies LIBNDR_FLAG_REF_ALLOC
- By default, top level pointers are now "ref" (as is the default in
most other IDL compilers). This can be overridden using the
default_pointer_top() property.
- initial work on new ethereal parser generators by Alan DeKok and me
- pidl now writes errors in the standard format used by compilers, which
is parsable by most editors
- ability to warn about the fact that pidl extension(s) have been used,
useful for making sure IDL files work with other IDL compilers.
oh, and there's probably some other things I can't think of right now..
(This used to be commit 13cf227615f6b9e0e5fa62e59197024410254f01)
2005-05-25 17:50:27 +04:00
}
2005-08-03 00:12:31 +04:00
if (defined($opt_tdr_parser)) {
2005-12-25 18:19:55 +03:00
my $tdr_parser = ($opt_tdr_parser or "$outputdir/tdr_$basename.c");
my $tdr_header = $tdr_parser;
$tdr_header =~ s/\.c$/\.h/;
2005-12-25 01:11:44 +03:00
require Parse::Pidl::Samba4::TDR;
2007-04-22 17:57:07 +04:00
my $generator = new Parse::Pidl::Samba4::TDR();
my ($hdr,$prsr) = $generator->Parser($pidl, $tdr_header, $gen_header);
2005-12-25 18:19:55 +03:00
FileSave($tdr_parser, $prsr);
FileSave($tdr_header, $hdr);
2005-08-03 00:12:31 +04:00
}
2008-01-13 00:15:12 +03:00
if (defined($opt_typelib)) {
my $typelib = ($opt_typelib or "$outputdir/$basename.tlb");
require Parse::Pidl::Typelist;
FileSave($typelib, Parse::Pidl::Typelist::GenerateTypeLib());
}
2003-12-15 13:55:10 +03:00
if ($opt_template) {
2005-12-25 01:11:44 +03:00
require Parse::Pidl::Samba4::Template;
print Parse::Pidl::Samba4::Template::Parse($pidl);
2003-12-15 13:55:10 +03:00
}
2005-10-04 03:27:33 +04:00
2013-01-21 21:42:45 +04:00
if ($opt_samba3_template) {
require Parse::Pidl::Samba3::Template;
print Parse::Pidl::Samba3::Template::Parse($pidl);
}
2006-05-04 20:04:08 +04:00
if (defined($opt_samba3_ndr_client)) {
2006-05-06 15:44:00 +04:00
my $client = ($opt_samba3_ndr_client or "$outputdir/cli_$basename.c");
my $header = $client; $header =~ s/\.c$/\.h/;
2006-05-04 20:04:08 +04:00
require Parse::Pidl::Samba3::ClientNDR;
2007-04-22 18:19:22 +04:00
my $generator = new Parse::Pidl::Samba3::ClientNDR();
2010-08-05 23:01:25 +04:00
my ($c_code,$h_code) = $generator->Parse($ndr, $header, $c_header);
2006-05-06 15:44:00 +04:00
FileSave($client, $c_code);
FileSave($header, $h_code);
2006-05-04 20:04:08 +04:00
}
2006-09-13 18:13:48 +04:00
if (defined($opt_samba3_ndr_server)) {
my $server = ($opt_samba3_ndr_server or "$outputdir/srv_$basename.c");
my $header = $server; $header =~ s/\.c$/\.h/;
require Parse::Pidl::Samba3::ServerNDR;
my ($c_code,$h_code) = Parse::Pidl::Samba3::ServerNDR::Parse($ndr, $header, $h_filename);
FileSave($server, $c_code);
FileSave($header, $h_code);
}
2006-05-04 20:04:08 +04:00
2003-11-09 11:28:47 +03:00
}
2005-08-22 03:56:47 +04:00
if (scalar(@ARGV) == 0) {
2007-01-12 01:47:29 +03:00
print "$Script: no input files\n";
2005-09-23 17:06:23 +04:00
exit(1);
2003-11-08 16:24:14 +03:00
}
2005-08-22 03:56:47 +04:00
process_file($_) foreach (@ARGV);