r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[vlendec/samba-autobuild/.git] / source3 / python / py_spoolss_forms_conv.c
1 /* 
2    Python wrappers for DCERPC/SMB client routines.
3
4    Copyright (C) Tim Potter, 2002
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 #include "python/py_spoolss.h"
21 #include "python/py_conv.h"
22
23 struct pyconv py_FORM[] = {
24         { "flags", PY_UINT32, offsetof(FORM, flags) },
25         { "width", PY_UINT32, offsetof(FORM, size_x) },
26         { "length", PY_UINT32, offsetof(FORM, size_y) },
27         { "top", PY_UINT32, offsetof(FORM, top) },
28         { "left", PY_UINT32, offsetof(FORM, left) },
29         { "right", PY_UINT32, offsetof(FORM, right) },
30         { "bottom", PY_UINT32, offsetof(FORM, bottom) },
31         { NULL }
32 };
33
34 struct pyconv py_FORM_1[] = {
35         { "flags", PY_UINT32, offsetof(FORM_1, flag) },
36         { "width", PY_UINT32, offsetof(FORM_1, width) },
37         { "length", PY_UINT32, offsetof(FORM_1, length) },
38         { "top", PY_UINT32, offsetof(FORM_1, top) },
39         { "left", PY_UINT32, offsetof(FORM_1, left) },
40         { "right", PY_UINT32, offsetof(FORM_1, right) },
41         { "bottom", PY_UINT32, offsetof(FORM_1, bottom) },
42         { "name", PY_UNISTR, offsetof(FORM_1, name) },
43         { NULL }
44 };
45
46 BOOL py_from_FORM_1(PyObject **dict, FORM_1 *form)
47 {
48         *dict = from_struct(form, py_FORM_1);
49
50         PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
51
52         return True;
53 }
54
55 BOOL py_to_FORM(FORM *form, PyObject *dict)
56 {
57         PyObject *obj, *dict_copy = PyDict_Copy(dict);
58         char *name;
59         BOOL result = False;
60
61         if (!(obj = PyDict_GetItemString(dict_copy, "name")) || 
62             !PyString_Check(obj))
63                 goto done;
64
65         PyDict_DelItemString(dict_copy, "name");
66
67         if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
68             !PyInt_Check(obj))
69                 goto done;
70
71         PyDict_DelItemString(dict_copy, "level");
72
73         if (!to_struct(form, dict_copy, py_FORM))
74                 goto done;
75
76         /* Careful!  We can't call PyString_AsString(obj) then delete
77            obj and still expect to have our pointer pointing somewhere
78            useful. */
79
80         obj = PyDict_GetItemString(dict, "name");
81         name = PyString_AsString(obj);
82
83         init_unistr2(&form->name, name, UNI_STR_TERMINATE);
84         
85         result = True;
86
87 done:
88         Py_DECREF(dict_copy);
89         return result;
90 }