1fcde04c8537a19538b5c7e9252a644314400eda
[jra/samba/.git] / source4 / 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 %{
22 #include "libcli/util/pyerrors.h"
23 %}
24
25 %typemap(out,noblock=1) WERROR {
26     if (!W_ERROR_IS_OK($1)) {
27         PyErr_SetWERROR($1);
28         SWIG_fail;
29     } else if ($result == NULL) {
30         $result = Py_None;
31     }
32 };
33
34 %typemap(out,noblock=1) NTSTATUS {
35     if (NT_STATUS_IS_ERR($1)) {
36         PyErr_SetNTSTATUS($1);
37         SWIG_fail;
38     } else if ($result == NULL) {
39         $result = Py_None;
40     }
41 };
42
43 %typemap(in,noblock=1) NTSTATUS {
44         if (PyLong_Check($input))
45                 $1 = NT_STATUS(PyLong_AsUnsignedLong($input));
46         else if (PyInt_Check($input))
47                 $1 = NT_STATUS(PyInt_AsLong($input));
48         else {
49                 PyErr_SetString(PyExc_TypeError, "Expected a long or an int");
50                 return NULL;
51         }
52 }
53
54 #endif