r26572: Fix warnings in the Python code.
[ab/samba.git/.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
40 #undef strcpy
41
42 %}
43
44 %include "../../lib/talloc/talloc.i"
45 %include "../../auth/credentials/credentials.i"
46
47 %typemap(in,noblock=1, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
48         $1 = &temp_dcerpc_pipe;
49 }
50
51 %typemap(argout,noblock=1) struct dcerpc_pipe ** {
52         /* Set REF_ALLOC flag so we don't have to do too much extra
53            mucking around with ref variables in ndr unmarshalling. */
54
55         (*$1)->conn->flags |= DCERPC_NDR_REF_ALLOC;
56
57         /* Return swig handle on dcerpc_pipe */
58
59     $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
60 }
61
62 %types(struct dcerpc_pipe *);
63
64 %rename(pipe_connect) dcerpc_pipe_connect;
65
66 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
67                              struct dcerpc_pipe **pp, 
68                              const char *binding,
69                              const struct ndr_interface_table *table,
70                              struct cli_credentials *credentials,
71                              struct event_context *ev,
72                              struct loadparm_context *lp_ctx);
73
74 %typemap(in,noblock=1) DATA_BLOB * (DATA_BLOB temp_data_blob) {
75         temp_data_blob.data = PyString_AsString($input);
76         temp_data_blob.length = PyString_Size($input);
77         $1 = &temp_data_blob;
78 }
79
80 const char *dcerpc_server_name(struct dcerpc_pipe *p);
81
82 /* Some typemaps for easier access to resume handles.  Really this can
83    also be done using the uint32 carray functions, but it's a bit of a
84    hassle.  TODO: Fix memory leak here. */
85
86 %typemap(in,noblock=1) uint32_t *resume_handle {
87         $1 = malloc(sizeof(*$1));
88         *$1 = PyLong_AsLong($input);
89 }
90
91 %typemap(out,noblock=1) uint32_t *resume_handle {
92         $result = PyLong_FromLong(*$1);
93 }
94
95 %typemap(in,noblock=1) struct policy_handle * {
96
97         if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,
98                              SWIG_POINTER_EXCEPTION)) == -1) 
99                 return NULL;
100
101         if ($1 == NULL) {
102                 PyErr_SetString(PyExc_TypeError, "None is not a valid policy handle");
103                 return NULL;
104         }
105 }
106
107 /* When returning a policy handle to Python we need to make a copy of
108    as the talloc context it is created under is destroyed after the
109    wrapper function returns.  TODO: Fix memory leak created here. */
110
111 %typemap(out,noblock=1) struct policy_handle * {
112         if ($1) {
113                 struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle));
114                 memcpy(temp, $1, sizeof(struct policy_handle));
115                 $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0);
116         } else {
117                 Py_INCREF(Py_None);
118                 $result = Py_None;
119         }
120 }