python: Avoid duplicate copies of some objects in different packages.
[ira/wip.git] / source4 / librpc / rpc / dcerpc.i
1 /* Tastes like -*- C -*- */
2
3 /* 
4    Unix SMB/CIFS implementation.
5
6    Swig interface to librpc functions.
7
8    Copyright (C) Tim Potter 2004
9    Copyright (C) Jelmer Vernooij 2007
10    
11    This program is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 3 of the License, or
14    (at your option) any later version.
15    
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20    
21    You should have received a copy of the GNU General Public License
22    along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 %module dcerpc
26
27 %{
28
29 /* This symbol is used in both includes.h and Python.h which causes an
30    annoying compiler warning. */
31
32 #ifdef HAVE_FSTAT
33 #undef HAVE_FSTAT
34 #endif
35
36 #include "includes.h"
37 #include "dynconfig.h"
38 #include "librpc/rpc/dcerpc.h"
39 #include "param/param.h"
40
41 #undef strcpy
42
43 %}
44
45 %import "../../lib/talloc/talloc.i"
46 %import "../../auth/credentials/credentials.i"
47
48 %typemap(in,noblock=1, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
49         $1 = &temp_dcerpc_pipe;
50 }
51
52 %typemap(argout,noblock=1) struct dcerpc_pipe ** {
53         /* Set REF_ALLOC flag so we don't have to do too much extra
54            mucking around with ref variables in ndr unmarshalling. */
55
56         (*$1)->conn->flags |= DCERPC_NDR_REF_ALLOC;
57
58         /* Return swig handle on dcerpc_pipe */
59
60     $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
61 }
62
63 %types(struct dcerpc_pipe *);
64
65 %rename(pipe_connect) dcerpc_pipe_connect;
66
67 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
68                              struct dcerpc_pipe **pp, 
69                              const char *binding,
70                              const struct ndr_interface_table *table,
71                              struct cli_credentials *credentials,
72                              struct event_context *ev,
73                              struct loadparm_context *lp_ctx);
74
75 %typemap(in,noblock=1) DATA_BLOB * (DATA_BLOB temp_data_blob) {
76         temp_data_blob.data = PyString_AsString($input);
77         temp_data_blob.length = PyString_Size($input);
78         $1 = &temp_data_blob;
79 }
80
81 const char *dcerpc_server_name(struct dcerpc_pipe *p);
82
83 /* Some typemaps for easier access to resume handles.  Really this can
84    also be done using the uint32 carray functions, but it's a bit of a
85    hassle.  TODO: Fix memory leak here. */
86
87 %typemap(in,noblock=1) uint32_t *resume_handle {
88         $1 = malloc(sizeof(*$1));
89         *$1 = PyLong_AsLong($input);
90 }
91
92 %typemap(out,noblock=1) uint32_t *resume_handle {
93         $result = PyLong_FromLong(*$1);
94 }
95
96 %typemap(in,noblock=1) struct policy_handle * {
97
98         if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,
99                              SWIG_POINTER_EXCEPTION)) == -1) 
100                 return NULL;
101
102         if ($1 == NULL) {
103                 PyErr_SetString(PyExc_TypeError, "None is not a valid policy handle");
104                 return NULL;
105         }
106 }
107
108 /* When returning a policy handle to Python we need to make a copy of
109    as the talloc context it is created under is destroyed after the
110    wrapper function returns.  TODO: Fix memory leak created here. */
111
112 %typemap(out,noblock=1) struct policy_handle * {
113         if ($1) {
114                 struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle));
115                 memcpy(temp, $1, sizeof(struct policy_handle));
116                 $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0);
117         } else {
118                 Py_INCREF(Py_None);
119                 $result = Py_None;
120         }
121 }