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 /* Structure/hash conversions */
25 struct pyconv py_DRIVER_INFO_1[] = {
26 { "name", PY_UNISTR, offsetof(DRIVER_INFO_1, name) },
30 struct pyconv py_DRIVER_INFO_2[] = {
31 { "version", PY_UINT32, offsetof(DRIVER_INFO_2, version) },
32 { "name", PY_UNISTR, offsetof(DRIVER_INFO_2, name) },
33 { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_2, architecture) },
34 { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_2, driverpath) },
35 { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_2, datafile) },
36 { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_2, configfile) },
40 struct pyconv py_DRIVER_INFO_3[] = {
41 { "version", PY_UINT32, offsetof(DRIVER_INFO_3, version) },
42 { "name", PY_UNISTR, offsetof(DRIVER_INFO_3, name) },
43 { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_3, architecture) },
44 { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_3, driverpath) },
45 { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_3, datafile) },
46 { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_3, configfile) },
47 { "help_file", PY_UNISTR, offsetof(DRIVER_INFO_3, helpfile) },
48 { "monitor_name", PY_UNISTR, offsetof(DRIVER_INFO_3, monitorname) },
49 { "default_datatype", PY_UNISTR, offsetof(DRIVER_INFO_3, defaultdatatype) },
53 struct pyconv py_DRIVER_INFO_6[] = {
54 { "version", PY_UINT32, offsetof(DRIVER_INFO_6, version) },
55 { "name", PY_UNISTR, offsetof(DRIVER_INFO_6, name) },
56 { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_6, architecture) },
57 { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_6, driverpath) },
58 { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_6, datafile) },
59 { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_6, configfile) },
60 { "help_file", PY_UNISTR, offsetof(DRIVER_INFO_6, helpfile) },
61 { "monitor_name", PY_UNISTR, offsetof(DRIVER_INFO_6, monitorname) },
62 { "default_datatype", PY_UNISTR, offsetof(DRIVER_INFO_6, defaultdatatype) },
64 { "padding", PY_UINT32, offsetof(DRIVER_INFO_6, padding) },
65 { "driver_version_low", PY_UINT32, offsetof(DRIVER_INFO_6, driver_version_low) },
66 { "driver_version_high", PY_UINT32, offsetof(DRIVER_INFO_6, driver_version_high) },
67 { "mfg_name", PY_UNISTR, offsetof(DRIVER_INFO_6, mfgname) },
68 { "oem_url", PY_UNISTR, offsetof(DRIVER_INFO_6, oem_url) },
69 { "hardware_id", PY_UNISTR, offsetof(DRIVER_INFO_6, hardware_id) },
70 { "provider", PY_UNISTR, offsetof(DRIVER_INFO_6, provider) },
75 struct pyconv py_DRIVER_DIRECTORY_1[] = {
76 { "name", PY_UNISTR, offsetof(DRIVER_DIRECTORY_1, name) },
80 static uint16 *to_dependentfiles(PyObject *list, TALLOC_CTX *mem_ctx)
82 uint32 elements, size=0, pos=0, i;
85 PyObject *borrowedRef;
87 if (!PyList_Check(list)) {
91 /* calculate size for dependentfiles */
92 elements=PyList_Size(list);
93 for (i = 0; i < elements; i++) {
94 borrowedRef=PyList_GetItem(list, i);
95 if (!PyString_Check(borrowedRef))
96 /* non string found, return error */
98 size+=PyString_Size(borrowedRef)+1;
101 if (!(ret = (uint16*)_talloc(mem_ctx,((size+1)*sizeof(uint16)))))
104 /* create null terminated sequence of null terminated strings */
105 for (i = 0; i < elements; i++) {
106 borrowedRef=PyList_GetItem(list, i);
107 str=PyString_AsString(borrowedRef);
110 /* dependentfiles too small. miscalculated? */
114 SSVAL(&ret[pos], 0, str[0]);
125 BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info)
127 *dict = from_struct(info, py_DRIVER_INFO_1);
128 PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
133 BOOL py_to_DRIVER_INFO_1(DRIVER_INFO_1 *info, PyObject *dict)
138 BOOL py_from_DRIVER_INFO_2(PyObject **dict, DRIVER_INFO_2 *info)
140 *dict = from_struct(info, py_DRIVER_INFO_2);
141 PyDict_SetItemString(*dict, "level", PyInt_FromLong(2));
146 BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict)
151 BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info)
153 *dict = from_struct(info, py_DRIVER_INFO_3);
155 PyDict_SetItemString(*dict, "level", PyInt_FromLong(3));
157 PyDict_SetItemString(
158 *dict, "dependent_files",
159 from_unistr_list(info->dependentfiles));
164 BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict,
167 PyObject *obj, *dict_copy = PyDict_Copy(dict);
170 if (!(obj = PyDict_GetItemString(dict_copy, "dependent_files")))
173 if (!(info->dependentfiles = to_dependentfiles(obj, mem_ctx)))
176 PyDict_DelItemString(dict_copy, "dependent_files");
178 if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
182 PyDict_DelItemString(dict_copy, "level");
184 if (!to_struct(info, dict_copy, py_DRIVER_INFO_3))
190 Py_DECREF(dict_copy);
194 BOOL py_from_DRIVER_INFO_6(PyObject **dict, DRIVER_INFO_6 *info)
196 *dict = from_struct(info, py_DRIVER_INFO_6);
197 PyDict_SetItemString(*dict, "level", PyInt_FromLong(6));
198 PyDict_SetItemString(
199 *dict, "dependent_files",
200 from_unistr_list(info->dependentfiles));
204 BOOL py_to_DRIVER_INFO_6(DRIVER_INFO_6 *info, PyObject *dict)
209 BOOL py_from_DRIVER_DIRECTORY_1(PyObject **dict, DRIVER_DIRECTORY_1 *info)
211 *dict = from_struct(info, py_DRIVER_DIRECTORY_1);
212 PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
216 BOOL py_to_DRIVER_DIRECTORY_1(DRIVER_DIRECTORY_1 *info, PyObject *dict)