r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[Samba/bb.git] / source / python / py_spoolss_forms_conv.c
blobae990a50d6c3decf06551911a76523c865811215
1 /*
2 Python wrappers for DCERPC/SMB client routines.
4 Copyright (C) Tim Potter, 2002
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.
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.
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/>.
20 #include "python/py_spoolss.h"
21 #include "python/py_conv.h"
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 }
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 }
46 BOOL py_from_FORM_1(PyObject **dict, FORM_1 *form)
48 *dict = from_struct(form, py_FORM_1);
50 PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
52 return True;
55 BOOL py_to_FORM(FORM *form, PyObject *dict)
57 PyObject *obj, *dict_copy = PyDict_Copy(dict);
58 char *name;
59 BOOL result = False;
61 if (!(obj = PyDict_GetItemString(dict_copy, "name")) ||
62 !PyString_Check(obj))
63 goto done;
65 PyDict_DelItemString(dict_copy, "name");
67 if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
68 !PyInt_Check(obj))
69 goto done;
71 PyDict_DelItemString(dict_copy, "level");
73 if (!to_struct(form, dict_copy, py_FORM))
74 goto done;
76 /* Careful! We can't call PyString_AsString(obj) then delete
77 obj and still expect to have our pointer pointing somewhere
78 useful. */
80 obj = PyDict_GetItemString(dict, "name");
81 name = PyString_AsString(obj);
83 init_unistr2(&form->name, name, UNI_STR_TERMINATE);
85 result = True;
87 done:
88 Py_DECREF(dict_copy);
89 return result;