8d97daf537f46361b7307112111ee637ce9a1b95
[ira/wip.git] / source / libcli / util / errors.i
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
4    Copyright (C) Tim Potter 2004
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifdef SWIGPYTHON
21 %typemap(out) WERROR {
22     if (!W_ERROR_IS_OK($1)) {
23         PyObject *obj = Py_BuildValue("(i,s)", $1.v, win_errstr($1));
24         PyErr_SetObject(PyExc_RuntimeError, obj);
25         SWIG_fail;
26     } else if ($result == NULL) {
27         $result = Py_None;
28     }
29 };
30
31 %typemap(out) NTSTATUS {
32     if (NT_STATUS_IS_ERR($1)) {
33         PyObject *obj = Py_BuildValue("(i,s)", $1.v, nt_errstr($1));
34         PyErr_SetObject(PyExc_RuntimeError, obj);
35         SWIG_fail;
36     } else if ($result == NULL) {
37         $result = Py_None;
38     }
39 };
40
41 %typemap(in) NTSTATUS {
42         if (PyLong_Check($input))
43                 $1 = NT_STATUS(PyLong_AsUnsignedLong($input));
44         else if (PyInt_Check($input))
45                 $1 = NT_STATUS(PyInt_AsLong($input));
46         else {
47                 PyErr_SetString(PyExc_TypeError, "Expected a long or an int");
48                 return NULL;
49         }
50 }
51
52 #endif