New routines to convert between structures and python dictionaries. We now
authorTim Potter <tpot@samba.org>
Fri, 5 Apr 2002 04:54:48 +0000 (04:54 +0000)
committerTim Potter <tpot@samba.org>
Fri, 5 Apr 2002 04:54:48 +0000 (04:54 +0000)
hide to_struct() and from_struct() from the caller so we can add custom
fields nicely.
(This used to be commit 07d79f4aa8de8e7a08555a62faafd79573a95e74)

source3/python/py_spoolss_printers_conv.c [new file with mode: 0644]

diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c
new file mode 100644 (file)
index 0000000..c86b70d
--- /dev/null
@@ -0,0 +1,367 @@
+/* 
+   Python wrappers for DCERPC/SMB client routines.
+
+   Copyright (C) Tim Potter, 2002
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "python/py_spoolss.h"
+#include "python/py_conv.h"
+
+struct pyconv py_PRINTER_INFO_0[] = {
+       { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_0, printername) },
+       { "server_name", PY_UNISTR, offsetof(PRINTER_INFO_0, servername) },
+
+       { "cjobs", PY_UINT32, offsetof(PRINTER_INFO_0, cjobs) },
+       { "total_jobs", PY_UINT32, offsetof(PRINTER_INFO_0, total_jobs) },
+       { "total_bytes", PY_UINT32, offsetof(PRINTER_INFO_0, total_bytes) },
+
+       { "year", PY_UINT16, offsetof(PRINTER_INFO_0, year) },
+       { "month", PY_UINT16, offsetof(PRINTER_INFO_0, month) },
+       { "day_of_week", PY_UINT16, offsetof(PRINTER_INFO_0, dayofweek) },
+       { "day", PY_UINT16, offsetof(PRINTER_INFO_0, day) },
+       { "hour", PY_UINT16, offsetof(PRINTER_INFO_0, hour) },
+       { "minute", PY_UINT16, offsetof(PRINTER_INFO_0, minute) },
+       { "second", PY_UINT16, offsetof(PRINTER_INFO_0, second) },
+       { "milliseconds", PY_UINT16, offsetof(PRINTER_INFO_0, milliseconds) },
+
+       { "global_counter", PY_UINT32, offsetof(PRINTER_INFO_0, global_counter) },
+       { "total_pages", PY_UINT32, offsetof(PRINTER_INFO_0, total_pages) },
+
+       { "major_version", PY_UINT16, offsetof(PRINTER_INFO_0, major_version) },
+       { "build_version", PY_UINT16, offsetof(PRINTER_INFO_0, build_version) },
+
+       { "unknown7", PY_UINT32, offsetof(PRINTER_INFO_0, unknown7) },
+       { "unknown8", PY_UINT32, offsetof(PRINTER_INFO_0, unknown8) },
+       { "unknown9", PY_UINT32, offsetof(PRINTER_INFO_0, unknown9) },
+       { "session_counter", PY_UINT32, offsetof(PRINTER_INFO_0, session_counter)},
+       { "unknown11", PY_UINT32, offsetof(PRINTER_INFO_0, unknown11) },
+       { "printer_errors", PY_UINT32, offsetof(PRINTER_INFO_0, printer_errors) },
+       { "unknown13", PY_UINT32, offsetof(PRINTER_INFO_0, unknown13) },
+       { "unknown14", PY_UINT32, offsetof(PRINTER_INFO_0, unknown14) },
+       { "unknown15", PY_UINT32, offsetof(PRINTER_INFO_0, unknown15) },
+       { "unknown16", PY_UINT32, offsetof(PRINTER_INFO_0, unknown16) },
+       { "change_id", PY_UINT32, offsetof(PRINTER_INFO_0, change_id) },
+       { "unknown18", PY_UINT32, offsetof(PRINTER_INFO_0, unknown18) },
+       { "status", PY_UINT32, offsetof(PRINTER_INFO_0, status) },
+       { "unknown20", PY_UINT32, offsetof(PRINTER_INFO_0, unknown20) },
+       { "c_setprinter", PY_UINT32, offsetof(PRINTER_INFO_0, c_setprinter) },
+       { "unknown22", PY_UINT32, offsetof(PRINTER_INFO_0, unknown22) },
+       { "unknown23", PY_UINT32, offsetof(PRINTER_INFO_0, unknown23) },
+       { "unknown24", PY_UINT32, offsetof(PRINTER_INFO_0, unknown24) },
+       { "unknown25", PY_UINT32, offsetof(PRINTER_INFO_0, unknown25) },
+       { "unknown26", PY_UINT32, offsetof(PRINTER_INFO_0, unknown26) },
+       { "unknown27", PY_UINT32, offsetof(PRINTER_INFO_0, unknown27) },
+       { "unknown28", PY_UINT32, offsetof(PRINTER_INFO_0, unknown28) },
+       { "unknown29", PY_UINT32, offsetof(PRINTER_INFO_0, unknown29) },
+
+       { NULL }
+};     
+
+struct pyconv py_PRINTER_INFO_1[] = {
+       { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_1, name) },
+       { "description", PY_UNISTR, offsetof(PRINTER_INFO_1, description) },
+       { "comment", PY_UNISTR, offsetof(PRINTER_INFO_1, comment) },
+       { "flags", PY_UINT32, offsetof(PRINTER_INFO_1, flags) },
+       { NULL }
+};     
+
+struct pyconv py_PRINTER_INFO_2[] = {
+       { "server_name", PY_UNISTR, offsetof(PRINTER_INFO_2, servername) },
+       { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_2, printername) },
+       { "share_name", PY_UNISTR, offsetof(PRINTER_INFO_2, sharename) },
+       { "port_name", PY_UNISTR, offsetof(PRINTER_INFO_2, portname) },
+       { "driver_name", PY_UNISTR, offsetof(PRINTER_INFO_2, drivername) },
+       { "comment", PY_UNISTR, offsetof(PRINTER_INFO_2, comment) },
+       { "location", PY_UNISTR, offsetof(PRINTER_INFO_2, location) },
+       { "datatype", PY_UNISTR, offsetof(PRINTER_INFO_2, datatype) },
+       { "sepfile", PY_UNISTR, offsetof(PRINTER_INFO_2, sepfile) },
+       { "print_processor", PY_UNISTR, offsetof(PRINTER_INFO_2, printprocessor) },
+       { "parameters", PY_UNISTR, offsetof(PRINTER_INFO_2, parameters) },
+       { "attributes", PY_UINT32, offsetof(PRINTER_INFO_2, attributes) },
+       { "default_priority", PY_UINT32, offsetof(PRINTER_INFO_2, defaultpriority) },
+       { "priority", PY_UINT32, offsetof(PRINTER_INFO_2, priority) },
+       { "start_time", PY_UINT32, offsetof(PRINTER_INFO_2, starttime) },
+       { "until_time", PY_UINT32, offsetof(PRINTER_INFO_2, untiltime) },
+       { "status", PY_UINT32, offsetof(PRINTER_INFO_2, status) },
+       { "cjobs", PY_UINT32, offsetof(PRINTER_INFO_2, cjobs) },
+       { "average_ppm", PY_UINT32, offsetof(PRINTER_INFO_2, averageppm) },
+       { NULL }
+};     
+
+struct pyconv py_PRINTER_INFO_3[] = {
+       { "flags", PY_UINT32, offsetof(PRINTER_INFO_3, flags) },
+       { NULL }
+};     
+
+struct pyconv py_DEVICEMODE[] = {
+       { "device_name", PY_UNISTR, offsetof(DEVICEMODE, devicename) },
+       { "spec_version", PY_UINT16, offsetof(DEVICEMODE, specversion) },
+       { "driver_version", PY_UINT16, offsetof(DEVICEMODE, driverversion) },
+       { "size", PY_UINT16, offsetof(DEVICEMODE, size) },
+       { "fields", PY_UINT16, offsetof(DEVICEMODE, fields) },
+       { "orientation", PY_UINT16, offsetof(DEVICEMODE, orientation) },
+       { "paper_size", PY_UINT16, offsetof(DEVICEMODE, papersize) },
+       { "paper_width", PY_UINT16, offsetof(DEVICEMODE, paperwidth) },
+       { "paper_length", PY_UINT16, offsetof(DEVICEMODE, paperlength) },
+       { "scale", PY_UINT16, offsetof(DEVICEMODE, scale) },
+       { "copies", PY_UINT16, offsetof(DEVICEMODE, copies) },
+       { "default_source", PY_UINT16, offsetof(DEVICEMODE, defaultsource) },
+       { "print_quality", PY_UINT16, offsetof(DEVICEMODE, printquality) },
+       { "color", PY_UINT16, offsetof(DEVICEMODE, color) },
+       { "duplex", PY_UINT16, offsetof(DEVICEMODE, duplex) },
+       { "y_resolution", PY_UINT16, offsetof(DEVICEMODE, yresolution) },
+       { "tt_option", PY_UINT16, offsetof(DEVICEMODE, ttoption) },
+       { "collate", PY_UINT16, offsetof(DEVICEMODE, collate) },
+       { "form_name", PY_UNISTR, offsetof(DEVICEMODE, formname) },
+       { "log_pixels", PY_UINT16, offsetof(DEVICEMODE, logpixels) },
+       { "bits_per_pel", PY_UINT32, offsetof(DEVICEMODE, bitsperpel) },
+       { "pels_width", PY_UINT32, offsetof(DEVICEMODE, pelswidth) },
+       { "pels_height", PY_UINT32, offsetof(DEVICEMODE, pelsheight) },
+       { "display_flags", PY_UINT32, offsetof(DEVICEMODE, displayflags) },
+       { "display_frequency", PY_UINT32, offsetof(DEVICEMODE, displayfrequency) },
+       { "icm_method", PY_UINT32, offsetof(DEVICEMODE, icmmethod) },
+       { "icm_intent", PY_UINT32, offsetof(DEVICEMODE, icmintent) },
+       { "media_type", PY_UINT32, offsetof(DEVICEMODE, mediatype) },
+       { "dither_type", PY_UINT32, offsetof(DEVICEMODE, dithertype) },
+       { "reserved1", PY_UINT32, offsetof(DEVICEMODE, reserved1) },
+       { "reserved2", PY_UINT32, offsetof(DEVICEMODE, reserved2) },
+       { "panning_width", PY_UINT32, offsetof(DEVICEMODE, panningwidth) },
+       { "panning_height", PY_UINT32, offsetof(DEVICEMODE, panningheight) },
+       { NULL }
+};
+
+/* Convert a security descriptor to a Python dict */
+
+BOOL py_from_SID(PyObject **obj, DOM_SID *sid)
+{
+       fstring sidstr;
+
+       if (!sid) {
+               Py_INCREF(Py_None);
+               *obj = Py_None;
+               return True;
+       }
+
+       if (!sid_to_string(sidstr, sid))
+               return False;
+
+       *obj = PyString_FromString(sidstr);
+
+       return True;
+}
+
+BOOL py_to_SID(DOM_SID **sid, PyObject *dict)
+{
+       return False;
+}
+
+BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace)
+{
+       PyObject *obj;
+
+       if (!ace) {
+               Py_INCREF(Py_None);
+               *dict = Py_None;
+               return True;
+       }
+
+       *dict = PyDict_New();
+
+       PyDict_SetItemString(*dict, "type", PyInt_FromLong(ace->type));
+       PyDict_SetItemString(*dict, "flags", PyInt_FromLong(ace->flags));
+       PyDict_SetItemString(*dict, "mask", PyInt_FromLong(ace->info.mask));
+
+       if (py_from_SID(&obj, &ace->trustee))
+               PyDict_SetItemString(*dict, "trustee", obj);
+
+       return True;
+}
+
+BOOL py_to_ACE(SEC_ACE **ace, PyObject *dict)
+{
+       return False;
+}
+
+BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl)
+{
+       PyObject *ace_list;
+       int i;
+
+       if (!acl) {
+               Py_INCREF(Py_None);
+               *dict = Py_None;
+               return True;
+       }
+
+       *dict = PyDict_New();
+
+       PyDict_SetItemString(*dict, "revision", PyInt_FromLong(acl->revision));
+
+       ace_list = PyList_New(acl->num_aces);
+
+       for (i = 0; i < acl->num_aces; i++) {
+               PyObject *obj;
+
+               if (py_from_ACE(&obj, &acl->ace[i]))
+                       PyList_SetItem(ace_list, i, obj);
+       }
+
+       PyDict_SetItemString(*dict, "ace_list", ace_list);
+
+       return True;
+}
+
+BOOL py_to_ACL(SEC_ACL **acl, PyObject *dict)
+{
+       return False;
+}
+
+BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd)
+{
+       PyObject *obj;
+
+       *dict = PyDict_New();
+
+       PyDict_SetItemString(*dict, "revision", PyInt_FromLong(sd->revision));
+       PyDict_SetItemString(*dict, "type", PyInt_FromLong(sd->type));
+
+       if (py_from_SID(&obj, sd->owner_sid))
+               PyDict_SetItemString(*dict, "owner_sid", obj);
+
+       if (py_from_SID(&obj, sd->grp_sid))
+               PyDict_SetItemString(*dict, "group_sid", obj);
+
+       if (py_from_ACL(&obj, sd->dacl))
+               PyDict_SetItemString(*dict, "dacl", obj);
+
+       if (py_from_ACL(&obj, sd->sacl))
+               PyDict_SetItemString(*dict, "sacl", obj);
+
+       return True;
+}
+
+BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict)
+{
+       return False;
+}
+
+/*
+ * Convert between DEVICEMODE and Python
+ */
+
+BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode)
+{
+       *dict = from_struct(devmode, py_DEVICEMODE);
+
+       PyDict_SetItemString(*dict, "private",
+                            PyString_FromStringAndSize(
+                                    devmode->private, devmode->driverextra));
+
+       return True;
+}
+
+BOOL py_to_DEVICEMODE(DEVICEMODE **devmode, PyObject *dict)
+{
+       PyObject *obj;
+
+       to_struct(*devmode, dict, py_DEVICEMODE);
+
+       obj = PyDict_GetItemString(dict, "private");
+
+       if (!obj)
+               return False;
+
+       (*devmode)->private = PyString_AsString(obj);
+       (*devmode)->driverextra = PyString_Size(obj);
+
+       return True;
+}
+
+/*
+ * Convert between PRINTER_INFO_0 and Python 
+ */
+
+BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info)
+{
+       *dict = from_struct(info, py_PRINTER_INFO_0);
+       return True;
+}
+
+BOOL py_to_PRINTER_INFO_0(PRINTER_INFO_0 *info, PyObject **dict)
+{
+       return False;
+}
+
+/*
+ * Convert between PRINTER_INFO_1 and Python 
+ */
+
+BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info)
+{
+       *dict = from_struct(info, py_PRINTER_INFO_1);
+       return True;
+}
+
+BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject **dict)
+{
+       return False;
+}
+
+/*
+ * Convert between PRINTER_INFO_2 and Python 
+ */
+
+BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info)
+{
+       PyObject *obj;
+
+       *dict = from_struct(info, py_PRINTER_INFO_2);
+
+       if (py_from_SECDESC(&obj, info->secdesc))
+               PyDict_SetItemString(*dict, "security_descriptor", obj);
+
+       if (py_from_DEVICEMODE(&obj, info->devmode))
+               PyDict_SetItemString(*dict, "device_mode", obj);
+
+       return True;
+}
+
+BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject **dict)
+{
+       return False;
+}
+
+/*
+ * Convert between PRINTER_INFO_1 and Python 
+ */
+
+BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info)
+{
+       PyObject *obj;
+
+       *dict = from_struct(info, py_PRINTER_INFO_3);
+
+       if (py_from_SECDESC(&obj, info->secdesc))
+               PyDict_SetItemString(*dict, "security_descriptor", obj);
+
+       return True;
+}
+
+BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject **dict)
+{
+       return False;
+}