1 ###################################################
2 # Samba4 parser generator for swig wrappers
3 # Copyright tpot@samba.org 2004
4 # released under the GNU GPL
19 $result .= "\t// $e->{TYPE} $e->{NAME} ";
21 $result .= "(scalar) "
22 if util::is_scalar_type($e->{TYPE});
24 $result .= "pointers=$e->{POINTERS} "
25 if $e->{POINTERS} > 0;
27 my($size_is) = util::has_property($e, "size_is");
28 $result .= "size_is=" . $size_is . " " if $size_is;
30 my($length_is) = util::has_property($e, "length_is");
31 $result .= "length_is=" . $length_is . " " if $length_is;
33 $result .= "array_len=" . $e->{ARRAY_LEN} . " " if $e->{ARRAY_LEN};
45 my($obj) = "PyDict_GetItem(obj, PyString_FromString(\"$e->{NAME}\"))";
49 if (($e->{TYPE} eq "policy_handle" || $e->{TYPE} eq "string") && $e->{POINTERS} == 1) {
50 $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_from_python($obj);\n";
54 if ($e->{TYPE} eq "string" && $e->{POINTERS} == 1) {
55 $result .= "\ts->$prefix$e->{NAME} = policy_handle_from_python($obj);\n";
59 # Generate conversion for element
61 if (util::is_scalar_type($e->{TYPE})) {
62 if ($e->{POINTERS} == 0) {
63 if ($e->{ARRAY_LEN}) {
64 # pointer to scalar with array len property
65 $result .= DebugElement($e);
67 $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_from_python($obj);\n";
71 $result .= DebugElement($e);
75 $result .= DebugElement($e);
89 if ($e->{TYPE} eq "policy_handle" && $e->{POINTERS} == 1) {
90 $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), policy_handle_to_python(s->$prefix$e->{NAME}));\n";
94 if ($e->{TYPE} eq "string" && $e->{POINTERS} == 1) {
95 $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), string_to_python(s->$prefix$e->{NAME}));\n";
99 # Generate conversion for element
101 if (util::is_scalar_type($e->{TYPE})) {
102 if ($e->{POINTERS} == 0) {
103 if ($e->{ARRAY_LEN}) {
104 # pointer to scalar with array len property
105 $result .= DebugElement($e);
107 $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_to_python(s->$prefix$e->{NAME}));\n";
111 $result .= DebugElement($e);
115 $result .= DebugElement($e);
127 $res .= "/* Convert Python dict to struct $fn->{NAME}.in */\n\n";
129 $res .= "int $fn->{NAME}_from_python(TALLOC_CTX *mem_ctx, struct $fn->{NAME} *s, PyObject *obj)\n";
132 foreach my $e (@{$fn->{DATA}}) {
133 $res .= XFromPython($e, "in.") if util::has_property($e, "in")
137 $res .= "\treturn True;\n";
140 $res .= "/* Convert struct $fn->{NAME}.out to Python dict */\n\n";
142 $res .= "int $fn->{NAME}_to_python(TALLOC_CTX *mem_ctx, PyObject *obj, struct $fn->{NAME} *s)\n";
145 foreach my $e (@{$fn->{DATA}}) {
146 $res .= XToPython($e, "out.") if util::has_property($e, "out")
150 $res .= "\treturn True;\n";
157 $res .= "%typemap(in) struct $fn->{NAME} * (struct $fn->{NAME} temp) {\n";
158 $res .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(int) $fn->{NAME}\");\n\n";
159 $res .= "\t$fn->{NAME}_from_python(mem_ctx, &temp, \$input);\n";
160 $res .= "\t\$1 = &temp;\n";
165 $res .= "%typemap(argout) struct $fn->{NAME} * {\n";
166 $res .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(argout) $fn->{NAME}\");\n\n";
167 $res .= "\tlong status = PyLong_AsLong(resultobj);\n";
168 $res .= "\tPyObject *dict;\n";
170 $res .= "\tif (status != 0) {\n";
171 $res .= "\t\tset_ntstatus_exception(status);\n";
172 $res .= "\t\treturn NULL;\n";
175 $res .= "\tdict = PyDict_New();\n";
177 $res .= "\t$fn->{NAME}_to_python(mem_ctx, dict, \$1);\n";
179 $res .= "\tresultobj = dict;\n";
182 # Function definitions
184 $res .= "%rename($fn->{NAME}) dcerpc_$fn->{NAME};\n";
185 $res .= "$fn->{RETURN_TYPE} dcerpc_$fn->{NAME}(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $fn->{NAME} *r);\n\n";
193 $res .= "/* Convert Python dict to struct $s->{NAME} */\n\n";
195 $res .= "int python_to_$s->{NAME}(TALLOC_CTX *mem_ctx, struct $s->{NAME} *s, PyObject *obj)\n";
198 foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
199 $res .= XFromPython($e, "");
203 $res .= "\treturn TRUE;\n";
206 $res .= "/* Convert struct $s->{NAME} to Python dict */\n\n";
208 $res .= "int $s->{NAME}_to_python(TALLOC_CTX *mem_ctx, PyObject *obj, struct $s->{NAME} *s)\n";
211 foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
212 $res .= XToPython($e, "");
216 $res .= "\treturn TRUE;\n";
227 ($e->{DATA}{TYPE} eq "STRUCT") && ParseStruct($e);
231 sub ParseInheritedData($)
235 foreach my $e (@{$data}) {
236 ($e->{TYPE} eq "FUNCTION") && ParseFunction($e);
237 ($e->{TYPE} eq "TYPEDEF") && ParseTypedef($e);
245 $name = $hdr->{NAME};
246 $res .= "#define DCERPC_" . uc($name) . "_UUID \"$hdr->{PROPERTIES}->{uuid}\"\n";
247 $res .= "const int DCERPC_" . uc($name) . "_VERSION = " . $hdr->{PROPERTIES}->{version} . ";\n";
248 $res .= "#define DCERPC_" . uc($name) . "_NAME \"" . $name . "\"\n";
251 ParseInheritedData($hdr->{INHERITED_DATA});
258 $res = "/* auto-generated by pidl */\n\n";
260 foreach my $x (@{$idl}) {
261 ($x->{TYPE} eq "INTERFACE") && ParseHeader($x);