r23798: updated old Temple Place FSF addresses to new URL
[kamenim/samba.git] / source4 / scripting / swig / samba.i
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Common swig definitions
5    
6    Copyright (C) 2004 Tim Potter <tpot@samba.org>
7
8      ** NOTE! The following LGPL license applies to the swig
9      ** definitions. This does NOT imply that all of Samba is released
10      ** under the LGPL
11    
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 3 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, see <http://www.gnu.org/licenses/>.
24 */
25
26 %apply int { uint8_t };
27 %apply int { int8_t };
28 %apply unsigned int { uint16_t };
29 %apply int { int16_t };
30 %apply unsigned long long { uint64_t };
31 %apply long long { int64_t };
32
33 %typemap(in) uint32_t {
34         if (PyLong_Check($input))
35                 $1 = PyLong_AsUnsignedLong($input);
36         else if (PyInt_Check($input))
37                 $1 = PyInt_AsLong($input);
38         else {
39                 PyErr_SetString(PyExc_TypeError,"Expected a long or an int");
40                 return NULL;
41         }
42 }
43
44 %typemap(out) uint32_t {
45         $result = PyLong_FromUnsignedLong($1);
46 }
47
48 %typemap(in) NTSTATUS {
49         if (PyLong_Check($input))
50                 $1 = NT_STATUS(PyLong_AsUnsignedLong($input));
51         else if (PyInt_Check($input))
52                 $1 = NT_STATUS(PyInt_AsLong($input));
53         else {
54                 PyErr_SetString(PyExc_TypeError, "Expected a long or an int");
55                 return NULL;
56         }
57 }
58
59 %typemap(out) NTSTATUS {
60         $result = PyLong_FromUnsignedLong(NT_STATUS_V($1));
61 }
62
63 %typemap(in) struct cli_credentials * {
64         $1 = cli_credentials_init(arg1);
65         cli_credentials_set_conf($1);
66         if ($input == Py_None) {
67                 cli_credentials_set_anonymous($1);
68         } else {
69                 if (!PyTuple_Check($input) ||
70                     PyTuple_Size($input) != 3) {
71                         PyErr_SetString(PyExc_TypeError, "Expecting three element tuple");
72                         return NULL;
73                 }
74                 if (!PyString_Check(PyTuple_GetItem($input, 0)) ||
75                     !PyString_Check(PyTuple_GetItem($input, 1)) ||
76                     !PyString_Check(PyTuple_GetItem($input, 2))) {
77                         PyErr_SetString(PyExc_TypeError, "Expecting string elements");
78                         return NULL;
79                 }
80                 cli_credentials_set_domain($1, PyString_AsString(PyTuple_GetItem($input, 0)), CRED_SPECIFIED);
81                 cli_credentials_set_username($1, PyString_AsString(PyTuple_GetItem($input, 1)), CRED_SPECIFIED);
82                 cli_credentials_set_password($1, PyString_AsString(PyTuple_GetItem($input, 2)), CRED_SPECIFIED);
83         }
84 }