nicer measurement of failures and collisions
[samba.git] / source3 / python / py_spoolss_printers_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 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
24 struct pyconv py_PRINTER_INFO_0[] = {
25         { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_0, printername) },
26         { "server_name", PY_UNISTR, offsetof(PRINTER_INFO_0, servername) },
27
28         { "cjobs", PY_UINT32, offsetof(PRINTER_INFO_0, cjobs) },
29         { "total_jobs", PY_UINT32, offsetof(PRINTER_INFO_0, total_jobs) },
30         { "total_bytes", PY_UINT32, offsetof(PRINTER_INFO_0, total_bytes) },
31
32         { "year", PY_UINT16, offsetof(PRINTER_INFO_0, year) },
33         { "month", PY_UINT16, offsetof(PRINTER_INFO_0, month) },
34         { "day_of_week", PY_UINT16, offsetof(PRINTER_INFO_0, dayofweek) },
35         { "day", PY_UINT16, offsetof(PRINTER_INFO_0, day) },
36         { "hour", PY_UINT16, offsetof(PRINTER_INFO_0, hour) },
37         { "minute", PY_UINT16, offsetof(PRINTER_INFO_0, minute) },
38         { "second", PY_UINT16, offsetof(PRINTER_INFO_0, second) },
39         { "milliseconds", PY_UINT16, offsetof(PRINTER_INFO_0, milliseconds) },
40
41         { "global_counter", PY_UINT32, offsetof(PRINTER_INFO_0, global_counter) },
42         { "total_pages", PY_UINT32, offsetof(PRINTER_INFO_0, total_pages) },
43
44         { "major_version", PY_UINT16, offsetof(PRINTER_INFO_0, major_version) },
45         { "build_version", PY_UINT16, offsetof(PRINTER_INFO_0, build_version) },
46
47         { "unknown7", PY_UINT32, offsetof(PRINTER_INFO_0, unknown7) },
48         { "unknown8", PY_UINT32, offsetof(PRINTER_INFO_0, unknown8) },
49         { "unknown9", PY_UINT32, offsetof(PRINTER_INFO_0, unknown9) },
50         { "session_counter", PY_UINT32, offsetof(PRINTER_INFO_0, session_counter)},
51         { "unknown11", PY_UINT32, offsetof(PRINTER_INFO_0, unknown11) },
52         { "printer_errors", PY_UINT32, offsetof(PRINTER_INFO_0, printer_errors) },
53         { "unknown13", PY_UINT32, offsetof(PRINTER_INFO_0, unknown13) },
54         { "unknown14", PY_UINT32, offsetof(PRINTER_INFO_0, unknown14) },
55         { "unknown15", PY_UINT32, offsetof(PRINTER_INFO_0, unknown15) },
56         { "unknown16", PY_UINT32, offsetof(PRINTER_INFO_0, unknown16) },
57         { "change_id", PY_UINT32, offsetof(PRINTER_INFO_0, change_id) },
58         { "unknown18", PY_UINT32, offsetof(PRINTER_INFO_0, unknown18) },
59         { "status", PY_UINT32, offsetof(PRINTER_INFO_0, status) },
60         { "unknown20", PY_UINT32, offsetof(PRINTER_INFO_0, unknown20) },
61         { "c_setprinter", PY_UINT32, offsetof(PRINTER_INFO_0, c_setprinter) },
62         { "unknown22", PY_UINT32, offsetof(PRINTER_INFO_0, unknown22) },
63         { "unknown23", PY_UINT32, offsetof(PRINTER_INFO_0, unknown23) },
64         { "unknown24", PY_UINT32, offsetof(PRINTER_INFO_0, unknown24) },
65         { "unknown25", PY_UINT32, offsetof(PRINTER_INFO_0, unknown25) },
66         { "unknown26", PY_UINT32, offsetof(PRINTER_INFO_0, unknown26) },
67         { "unknown27", PY_UINT32, offsetof(PRINTER_INFO_0, unknown27) },
68         { "unknown28", PY_UINT32, offsetof(PRINTER_INFO_0, unknown28) },
69         { "unknown29", PY_UINT32, offsetof(PRINTER_INFO_0, unknown29) },
70
71         { NULL }
72 };      
73
74 struct pyconv py_PRINTER_INFO_1[] = {
75         { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_1, name) },
76         { "description", PY_UNISTR, offsetof(PRINTER_INFO_1, description) },
77         { "comment", PY_UNISTR, offsetof(PRINTER_INFO_1, comment) },
78         { "flags", PY_UINT32, offsetof(PRINTER_INFO_1, flags) },
79         { NULL }
80 };      
81
82 struct pyconv py_PRINTER_INFO_2[] = {
83         { "server_name", PY_UNISTR, offsetof(PRINTER_INFO_2, servername) },
84         { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_2, printername) },
85         { "share_name", PY_UNISTR, offsetof(PRINTER_INFO_2, sharename) },
86         { "port_name", PY_UNISTR, offsetof(PRINTER_INFO_2, portname) },
87         { "driver_name", PY_UNISTR, offsetof(PRINTER_INFO_2, drivername) },
88         { "comment", PY_UNISTR, offsetof(PRINTER_INFO_2, comment) },
89         { "location", PY_UNISTR, offsetof(PRINTER_INFO_2, location) },
90         { "datatype", PY_UNISTR, offsetof(PRINTER_INFO_2, datatype) },
91         { "sepfile", PY_UNISTR, offsetof(PRINTER_INFO_2, sepfile) },
92         { "print_processor", PY_UNISTR, offsetof(PRINTER_INFO_2, printprocessor) },
93         { "parameters", PY_UNISTR, offsetof(PRINTER_INFO_2, parameters) },
94         { "attributes", PY_UINT32, offsetof(PRINTER_INFO_2, attributes) },
95         { "default_priority", PY_UINT32, offsetof(PRINTER_INFO_2, defaultpriority) },
96         { "priority", PY_UINT32, offsetof(PRINTER_INFO_2, priority) },
97         { "start_time", PY_UINT32, offsetof(PRINTER_INFO_2, starttime) },
98         { "until_time", PY_UINT32, offsetof(PRINTER_INFO_2, untiltime) },
99         { "status", PY_UINT32, offsetof(PRINTER_INFO_2, status) },
100         { "cjobs", PY_UINT32, offsetof(PRINTER_INFO_2, cjobs) },
101         { "average_ppm", PY_UINT32, offsetof(PRINTER_INFO_2, averageppm) },
102         { NULL }
103 };      
104
105 struct pyconv py_PRINTER_INFO_3[] = {
106         { "flags", PY_UINT32, offsetof(PRINTER_INFO_3, flags) },
107         { NULL }
108 };      
109
110 struct pyconv py_DEVICEMODE[] = {
111         { "device_name", PY_UNISTR, offsetof(DEVICEMODE, devicename) },
112         { "spec_version", PY_UINT16, offsetof(DEVICEMODE, specversion) },
113         { "driver_version", PY_UINT16, offsetof(DEVICEMODE, driverversion) },
114         { "size", PY_UINT16, offsetof(DEVICEMODE, size) },
115         { "fields", PY_UINT16, offsetof(DEVICEMODE, fields) },
116         { "orientation", PY_UINT16, offsetof(DEVICEMODE, orientation) },
117         { "paper_size", PY_UINT16, offsetof(DEVICEMODE, papersize) },
118         { "paper_width", PY_UINT16, offsetof(DEVICEMODE, paperwidth) },
119         { "paper_length", PY_UINT16, offsetof(DEVICEMODE, paperlength) },
120         { "scale", PY_UINT16, offsetof(DEVICEMODE, scale) },
121         { "copies", PY_UINT16, offsetof(DEVICEMODE, copies) },
122         { "default_source", PY_UINT16, offsetof(DEVICEMODE, defaultsource) },
123         { "print_quality", PY_UINT16, offsetof(DEVICEMODE, printquality) },
124         { "color", PY_UINT16, offsetof(DEVICEMODE, color) },
125         { "duplex", PY_UINT16, offsetof(DEVICEMODE, duplex) },
126         { "y_resolution", PY_UINT16, offsetof(DEVICEMODE, yresolution) },
127         { "tt_option", PY_UINT16, offsetof(DEVICEMODE, ttoption) },
128         { "collate", PY_UINT16, offsetof(DEVICEMODE, collate) },
129         { "form_name", PY_UNISTR, offsetof(DEVICEMODE, formname) },
130         { "log_pixels", PY_UINT16, offsetof(DEVICEMODE, logpixels) },
131         { "bits_per_pel", PY_UINT32, offsetof(DEVICEMODE, bitsperpel) },
132         { "pels_width", PY_UINT32, offsetof(DEVICEMODE, pelswidth) },
133         { "pels_height", PY_UINT32, offsetof(DEVICEMODE, pelsheight) },
134         { "display_flags", PY_UINT32, offsetof(DEVICEMODE, displayflags) },
135         { "display_frequency", PY_UINT32, offsetof(DEVICEMODE, displayfrequency) },
136         { "icm_method", PY_UINT32, offsetof(DEVICEMODE, icmmethod) },
137         { "icm_intent", PY_UINT32, offsetof(DEVICEMODE, icmintent) },
138         { "media_type", PY_UINT32, offsetof(DEVICEMODE, mediatype) },
139         { "dither_type", PY_UINT32, offsetof(DEVICEMODE, dithertype) },
140         { "reserved1", PY_UINT32, offsetof(DEVICEMODE, reserved1) },
141         { "reserved2", PY_UINT32, offsetof(DEVICEMODE, reserved2) },
142         { "panning_width", PY_UINT32, offsetof(DEVICEMODE, panningwidth) },
143         { "panning_height", PY_UINT32, offsetof(DEVICEMODE, panningheight) },
144         { NULL }
145 };
146
147 /* Convert a security descriptor to a Python dict */
148
149 BOOL py_from_SID(PyObject **obj, DOM_SID *sid)
150 {
151         fstring sidstr;
152
153         if (!sid) {
154                 Py_INCREF(Py_None);
155                 *obj = Py_None;
156                 return True;
157         }
158
159         if (!sid_to_string(sidstr, sid))
160                 return False;
161
162         *obj = PyString_FromString(sidstr);
163
164         return True;
165 }
166
167 BOOL py_to_SID(DOM_SID *sid, PyObject *dict)
168 {
169         return False;
170 }
171
172 BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace)
173 {
174         PyObject *obj;
175
176         if (!ace) {
177                 Py_INCREF(Py_None);
178                 *dict = Py_None;
179                 return True;
180         }
181
182         *dict = PyDict_New();
183
184         PyDict_SetItemString(*dict, "type", PyInt_FromLong(ace->type));
185         PyDict_SetItemString(*dict, "flags", PyInt_FromLong(ace->flags));
186         PyDict_SetItemString(*dict, "mask", PyInt_FromLong(ace->info.mask));
187
188         if (py_from_SID(&obj, &ace->trustee))
189                 PyDict_SetItemString(*dict, "trustee", obj);
190
191         return True;
192 }
193
194 BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict)
195 {
196         return False;
197 }
198
199 BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl)
200 {
201         PyObject *ace_list;
202         int i;
203
204         if (!acl) {
205                 Py_INCREF(Py_None);
206                 *dict = Py_None;
207                 return True;
208         }
209
210         *dict = PyDict_New();
211
212         PyDict_SetItemString(*dict, "revision", PyInt_FromLong(acl->revision));
213
214         ace_list = PyList_New(acl->num_aces);
215
216         for (i = 0; i < acl->num_aces; i++) {
217                 PyObject *obj;
218
219                 if (py_from_ACE(&obj, &acl->ace[i]))
220                         PyList_SetItem(ace_list, i, obj);
221         }
222
223         PyDict_SetItemString(*dict, "ace_list", ace_list);
224
225         return True;
226 }
227
228 BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict)
229 {
230         return False;
231 }
232
233 BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd)
234 {
235         PyObject *obj;
236
237         *dict = PyDict_New();
238
239         PyDict_SetItemString(*dict, "revision", PyInt_FromLong(sd->revision));
240         PyDict_SetItemString(*dict, "type", PyInt_FromLong(sd->type));
241
242         if (py_from_SID(&obj, sd->owner_sid))
243                 PyDict_SetItemString(*dict, "owner_sid", obj);
244
245         if (py_from_SID(&obj, sd->grp_sid))
246                 PyDict_SetItemString(*dict, "group_sid", obj);
247
248         if (py_from_ACL(&obj, sd->dacl))
249                 PyDict_SetItemString(*dict, "dacl", obj);
250
251         if (py_from_ACL(&obj, sd->sacl))
252                 PyDict_SetItemString(*dict, "sacl", obj);
253
254         return True;
255 }
256
257 BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict)
258 {
259         return False;
260 }
261
262 /*
263  * Convert between DEVICEMODE and Python
264  */
265
266 BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode)
267 {
268         *dict = from_struct(devmode, py_DEVICEMODE);
269
270         PyDict_SetItemString(*dict, "private",
271                              PyString_FromStringAndSize(
272                                      devmode->private, devmode->driverextra));
273
274         return True;
275 }
276
277 BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict)
278 {
279         PyObject *obj;
280
281         to_struct(devmode, dict, py_DEVICEMODE);
282
283         obj = PyDict_GetItemString(dict, "private");
284
285         if (!obj)
286                 return False;
287
288         devmode->private = PyString_AsString(obj);
289         devmode->driverextra = PyString_Size(obj);
290
291         return True;
292 }
293
294 /*
295  * Convert between PRINTER_INFO_0 and Python 
296  */
297
298 BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info)
299 {
300         *dict = from_struct(info, py_PRINTER_INFO_0);
301         return True;
302 }
303
304 BOOL py_to_PRINTER_INFO_0(PRINTER_INFO_0 *info, PyObject *dict)
305 {
306         return False;
307 }
308
309 /*
310  * Convert between PRINTER_INFO_1 and Python 
311  */
312
313 BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info)
314 {
315         *dict = from_struct(info, py_PRINTER_INFO_1);
316         return True;
317 }
318
319 BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict)
320 {
321         return False;
322 }
323
324 /*
325  * Convert between PRINTER_INFO_2 and Python 
326  */
327
328 BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info)
329 {
330         PyObject *obj;
331
332         *dict = from_struct(info, py_PRINTER_INFO_2);
333
334         if (py_from_SECDESC(&obj, info->secdesc))
335                 PyDict_SetItemString(*dict, "security_descriptor", obj);
336
337         if (py_from_DEVICEMODE(&obj, info->devmode))
338                 PyDict_SetItemString(*dict, "device_mode", obj);
339
340         return True;
341 }
342
343 BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict)
344 {
345         return False;
346 }
347
348 /*
349  * Convert between PRINTER_INFO_1 and Python 
350  */
351
352 BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info)
353 {
354         PyObject *obj;
355
356         *dict = from_struct(info, py_PRINTER_INFO_3);
357
358         if (py_from_SECDESC(&obj, info->secdesc))
359                 PyDict_SetItemString(*dict, "security_descriptor", obj);
360
361         return True;
362 }
363
364 BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict)
365 {
366         return False;
367 }