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 2 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, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19*/ 20 21#include "python/py_spoolss.h" 22#include "python/py_conv.h" 23 24struct pyconv py_FORM[] = { 25 { "flags", PY_UINT32, offsetof(FORM, flags) }, 26 { "width", PY_UINT32, offsetof(FORM, size_x) }, 27 { "length", PY_UINT32, offsetof(FORM, size_y) }, 28 { "top", PY_UINT32, offsetof(FORM, top) }, 29 { "left", PY_UINT32, offsetof(FORM, left) }, 30 { "right", PY_UINT32, offsetof(FORM, right) }, 31 { "bottom", PY_UINT32, offsetof(FORM, bottom) }, 32 { NULL } 33}; 34 35struct pyconv py_FORM_1[] = { 36 { "flags", PY_UINT32, offsetof(FORM_1, flag) }, 37 { "width", PY_UINT32, offsetof(FORM_1, width) }, 38 { "length", PY_UINT32, offsetof(FORM_1, length) }, 39 { "top", PY_UINT32, offsetof(FORM_1, top) }, 40 { "left", PY_UINT32, offsetof(FORM_1, left) }, 41 { "right", PY_UINT32, offsetof(FORM_1, right) }, 42 { "bottom", PY_UINT32, offsetof(FORM_1, bottom) }, 43 { "name", PY_UNISTR, offsetof(FORM_1, name) }, 44 { NULL } 45}; 46 47BOOL py_from_FORM_1(PyObject **dict, FORM_1 *form) 48{ 49 *dict = from_struct(form, py_FORM_1); 50 51 PyDict_SetItemString(*dict, "level", PyInt_FromLong(1)); 52 53 return True; 54} 55 56BOOL py_to_FORM(FORM *form, PyObject *dict) 57{ 58 PyObject *obj, *dict_copy = PyDict_Copy(dict); 59 char *name; 60 BOOL result = False; 61 62 if (!(obj = PyDict_GetItemString(dict_copy, "name")) || 63 !PyString_Check(obj)) 64 goto done; 65 66 PyDict_DelItemString(dict_copy, "name"); 67 68 if (!(obj = PyDict_GetItemString(dict_copy, "level")) || 69 !PyInt_Check(obj)) 70 goto done; 71 72 PyDict_DelItemString(dict_copy, "level"); 73 74 if (!to_struct(form, dict_copy, py_FORM)) 75 goto done; 76 77 /* Careful! We can't call PyString_AsString(obj) then delete 78 obj and still expect to have our pointer pointing somewhere 79 useful. */ 80 81 obj = PyDict_GetItemString(dict, "name"); 82 name = PyString_AsString(obj); 83 84 init_unistr2(&form->name, name, UNI_STR_TERMINATE); 85 86 result = True; 87 88done: 89 Py_DECREF(dict_copy); 90 return result; 91} 92