r2297: Add string conversion functions.
[gd/samba-autobuild/.git] / source / scripting / swig / dcerpc.i
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Swig interface to librpc functions.
5
6    Copyright (C) Tim Potter 2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 %module dcerpc
24
25 %{
26
27 /* This symbol is used in both includes.h and Python.h which causes an
28    annoying compiler warning. */
29
30 #ifdef HAVE_FSTAT
31 #undef HAVE_FSTAT
32 #endif
33
34 #include "includes.h"
35
36 #undef strcpy
37
38 PyObject *ntstatus_exception;
39
40 /* Set up return of a dcerpc.NTSTATUS exception */
41
42 void set_ntstatus_exception(int status)
43 {
44         PyObject *obj = Py_BuildValue("(i,s)", status, 
45                                 nt_errstr(NT_STATUS(status)));
46
47         PyErr_SetObject(ntstatus_exception, obj);
48 }
49
50 uint8 uint8_from_python(PyObject *obj)
51 {
52         return (uint8)PyInt_AsLong(obj);
53 }
54
55 PyObject *uint8_to_python(uint8 obj)
56 {
57         return PyInt_FromLong(obj);
58 }
59
60 uint16 uint16_from_python(PyObject *obj)
61 {
62         return (uint16)PyInt_AsLong(obj);
63 }
64
65 PyObject *uint16_to_python(uint16 obj)
66 {
67         return PyInt_FromLong(obj);
68 }
69
70 uint32 uint32_from_python(PyObject *obj)
71 {
72         return (uint32)PyInt_AsLong(obj);
73 }
74
75 PyObject *uint32_to_python(uint32 obj)
76 {
77         return PyInt_FromLong(obj);
78 }
79
80 int64 int64_from_python(PyObject *obj)
81 {
82         return (int64)PyLong_AsLong(obj);
83 }
84
85 PyObject *int64_to_python(int64 obj)
86 {
87         return PyLong_FromLong(obj);
88 }
89
90 uint64 uint64_from_python(PyObject *obj)
91 {
92         return (uint64)PyLong_AsLong(obj);
93 }
94
95 PyObject *uint64_to_python(uint64 obj)
96 {
97         return PyLong_FromLong(obj);
98 }
99
100 NTTIME NTTIME_from_python(PyObject *obj)
101 {
102         return (NTTIME)PyLong_AsLong(obj);
103 }
104
105 PyObject *NTTIME_to_python(NTTIME obj)
106 {
107         return PyLong_FromLong(obj);
108 }
109
110 HYPER_T HYPER_T_from_python(PyObject *obj)
111 {
112         return (HYPER_T)PyLong_AsLong(obj);
113 }
114
115 PyObject *HYPER_T_to_python(HYPER_T obj)
116 {
117         return PyLong_FromLong(obj);
118 }
119
120 struct policy_handle *policy_handle_from_python(PyObject *obj)
121 {
122         return (struct policy_handle *)PyString_AsString(obj);
123 }
124
125 PyObject *policy_handle_to_python(struct policy_handle *handle)
126 {
127         return PyString_FromStringAndSize((char *)handle, sizeof(*handle));
128 }
129
130 struct security_descriptor *security_descriptor_from_python(PyObject *obj)
131 {
132         return NULL;
133 }
134
135 char *string_from_python(PyObject *obj)
136 {
137         return PyString_AsString(obj);
138 }
139
140 PyObject *string_to_python(char *obj)
141 {
142         return PyString_FromString(obj);
143 }
144
145 %}
146
147 %include "samba.i"
148
149 %init  %{
150 /* setup_logging("python", DEBUG_STDOUT);       */
151         lp_load(dyn_CONFIGFILE, True, False, False);
152         load_interfaces();
153         ntstatus_exception = PyErr_NewException("dcerpc.NTSTATUS", NULL, NULL);
154 %}
155
156 %typemap(in, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
157         $1 = &temp_dcerpc_pipe;
158 }
159
160 %typemap(in, numinputs=0) TALLOC_CTX * {
161         $1 = talloc_init("$symname");
162 }
163
164 %typemap(freearg) TALLOC_CTX * {
165         talloc_free($1);
166 }
167
168 %typemap(argout) struct dcerpc_pipe ** {
169         long status = PyLong_AsLong(resultobj);
170
171         /* Throw exception if result was not OK */
172
173         if (status != 0) {
174                 set_ntstatus_exception(status);
175                 return NULL;
176         }
177
178         /* Set REF_ALLOC flag so we don't have to do too much extra
179            mucking around with ref variables in ndr unmarshalling. */
180
181         (*$1)->flags |= DCERPC_NDR_REF_ALLOC;
182
183         /* Return swig handle on dcerpc_pipe */
184
185         resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
186 }
187
188 %types(struct dcerpc_pipe *);
189
190 %rename(pipe_connect) dcerpc_pipe_connect;
191
192 NTSTATUS dcerpc_pipe_connect(struct dcerpc_pipe **OUT,
193                              const char *binding,
194                              const char *pipe_uuid,
195                              uint32 pipe_version,
196                              const char *domain,
197                              const char *username,
198                              const char *password);
199
200 %include "librpc/gen_ndr/samr.i"
201 %include "librpc/gen_ndr/lsa.i"