r18754: Get rid of some more invalid time sets
[Samba/bb.git] / source3 / python / py_spoolss_drivers_conv.c
blob8ad6d8849343992b6a599c236d8b3b255829765f
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "python/py_spoolss.h"
22 #include "python/py_conv.h"
24 /* Structure/hash conversions */
26 struct pyconv py_DRIVER_INFO_1[] = {
27 { "name", PY_UNISTR, offsetof(DRIVER_INFO_1, name) },
28 { NULL }
31 struct pyconv py_DRIVER_INFO_2[] = {
32 { "version", PY_UINT32, offsetof(DRIVER_INFO_2, version) },
33 { "name", PY_UNISTR, offsetof(DRIVER_INFO_2, name) },
34 { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_2, architecture) },
35 { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_2, driverpath) },
36 { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_2, datafile) },
37 { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_2, configfile) },
38 { NULL }
41 struct pyconv py_DRIVER_INFO_3[] = {
42 { "version", PY_UINT32, offsetof(DRIVER_INFO_3, version) },
43 { "name", PY_UNISTR, offsetof(DRIVER_INFO_3, name) },
44 { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_3, architecture) },
45 { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_3, driverpath) },
46 { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_3, datafile) },
47 { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_3, configfile) },
48 { "help_file", PY_UNISTR, offsetof(DRIVER_INFO_3, helpfile) },
49 { "monitor_name", PY_UNISTR, offsetof(DRIVER_INFO_3, monitorname) },
50 { "default_datatype", PY_UNISTR, offsetof(DRIVER_INFO_3, defaultdatatype) },
51 { NULL }
54 struct pyconv py_DRIVER_INFO_6[] = {
55 { "version", PY_UINT32, offsetof(DRIVER_INFO_6, version) },
56 { "name", PY_UNISTR, offsetof(DRIVER_INFO_6, name) },
57 { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_6, architecture) },
58 { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_6, driverpath) },
59 { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_6, datafile) },
60 { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_6, configfile) },
61 { "help_file", PY_UNISTR, offsetof(DRIVER_INFO_6, helpfile) },
62 { "monitor_name", PY_UNISTR, offsetof(DRIVER_INFO_6, monitorname) },
63 { "default_datatype", PY_UNISTR, offsetof(DRIVER_INFO_6, defaultdatatype) },
64 /* driver_date */
65 { "padding", PY_UINT32, offsetof(DRIVER_INFO_6, padding) },
66 { "driver_version_low", PY_UINT32, offsetof(DRIVER_INFO_6, driver_version_low) },
67 { "driver_version_high", PY_UINT32, offsetof(DRIVER_INFO_6, driver_version_high) },
68 { "mfg_name", PY_UNISTR, offsetof(DRIVER_INFO_6, mfgname) },
69 { "oem_url", PY_UNISTR, offsetof(DRIVER_INFO_6, oem_url) },
70 { "hardware_id", PY_UNISTR, offsetof(DRIVER_INFO_6, hardware_id) },
71 { "provider", PY_UNISTR, offsetof(DRIVER_INFO_6, provider) },
73 { NULL }
76 struct pyconv py_DRIVER_DIRECTORY_1[] = {
77 { "name", PY_UNISTR, offsetof(DRIVER_DIRECTORY_1, name) },
78 { NULL }
81 static uint16 *to_dependentfiles(PyObject *list, TALLOC_CTX *mem_ctx)
83 uint32 elements, size=0, pos=0, i;
84 char *str;
85 uint16 *ret = NULL;
86 PyObject *borrowedRef;
88 if (!PyList_Check(list)) {
89 goto done;
92 /* calculate size for dependentfiles */
93 elements=PyList_Size(list);
94 for (i = 0; i < elements; i++) {
95 borrowedRef=PyList_GetItem(list, i);
96 if (!PyString_Check(borrowedRef))
97 /* non string found, return error */
98 goto done;
99 size+=PyString_Size(borrowedRef)+1;
102 if (!(ret = (uint16*)_talloc(mem_ctx,((size+1)*sizeof(uint16)))))
103 goto done;
105 /* create null terminated sequence of null terminated strings */
106 for (i = 0; i < elements; i++) {
107 borrowedRef=PyList_GetItem(list, i);
108 str=PyString_AsString(borrowedRef);
109 do {
110 if (pos >= size) {
111 /* dependentfiles too small. miscalculated? */
112 ret = NULL;
113 goto done;
115 SSVAL(&ret[pos], 0, str[0]);
116 pos++;
117 } while (*(str++));
119 /* final null */
120 ret[pos]='\0';
122 done:
123 return ret;
126 BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info)
128 *dict = from_struct(info, py_DRIVER_INFO_1);
129 PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
131 return True;
134 BOOL py_to_DRIVER_INFO_1(DRIVER_INFO_1 *info, PyObject *dict)
136 return False;
139 BOOL py_from_DRIVER_INFO_2(PyObject **dict, DRIVER_INFO_2 *info)
141 *dict = from_struct(info, py_DRIVER_INFO_2);
142 PyDict_SetItemString(*dict, "level", PyInt_FromLong(2));
144 return True;
147 BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict)
149 return False;
152 BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info)
154 *dict = from_struct(info, py_DRIVER_INFO_3);
156 PyDict_SetItemString(*dict, "level", PyInt_FromLong(3));
158 PyDict_SetItemString(
159 *dict, "dependent_files",
160 from_unistr_list(info->dependentfiles));
162 return True;
165 BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict,
166 TALLOC_CTX *mem_ctx)
168 PyObject *obj, *dict_copy = PyDict_Copy(dict);
169 BOOL result = False;
171 if (!(obj = PyDict_GetItemString(dict_copy, "dependent_files")))
172 goto done;
174 if (!(info->dependentfiles = to_dependentfiles(obj, mem_ctx)))
175 goto done;
177 PyDict_DelItemString(dict_copy, "dependent_files");
179 if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
180 !PyInt_Check(obj))
181 goto done;
183 PyDict_DelItemString(dict_copy, "level");
185 if (!to_struct(info, dict_copy, py_DRIVER_INFO_3))
186 goto done;
188 result = True;
190 done:
191 Py_DECREF(dict_copy);
192 return result;
195 BOOL py_from_DRIVER_INFO_6(PyObject **dict, DRIVER_INFO_6 *info)
197 *dict = from_struct(info, py_DRIVER_INFO_6);
198 PyDict_SetItemString(*dict, "level", PyInt_FromLong(6));
199 PyDict_SetItemString(
200 *dict, "dependent_files",
201 from_unistr_list(info->dependentfiles));
202 return True;
205 BOOL py_to_DRIVER_INFO_6(DRIVER_INFO_6 *info, PyObject *dict)
207 return False;
210 BOOL py_from_DRIVER_DIRECTORY_1(PyObject **dict, DRIVER_DIRECTORY_1 *info)
212 *dict = from_struct(info, py_DRIVER_DIRECTORY_1);
213 PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
214 return True;
217 BOOL py_to_DRIVER_DIRECTORY_1(DRIVER_DIRECTORY_1 *info, PyObject *dict)
219 return False;