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
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
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.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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) },
+ { "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) },
};
struct pyconv py_PRINTER_INFO_1[] = {
- { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_1, name) },
+ { "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) },
struct pyconv py_PRINTER_INFO_2[] = {
{ "server_name", PY_UNISTR, offsetof(PRINTER_INFO_2, servername) },
- { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_2, printername) },
+ { "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) },
PyDict_SetItemString(*dict, "private",
PyString_FromStringAndSize(
- devmode->private, devmode->driverextra));
+ devmode->dev_private, devmode->driverextra));
return True;
}
BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict)
{
- PyObject *obj;
-
- to_struct(devmode, dict, py_DEVICEMODE);
+ PyObject *obj, *dict_copy = PyDict_Copy(dict);
+ BOOL result = False;
- obj = PyDict_GetItemString(dict, "private");
+ if (!(obj = PyDict_GetItemString(dict_copy, "private")))
+ goto done;
- if (!obj)
- return False;
+ if (!PyString_Check(obj))
+ goto done;
- devmode->private = PyString_AsString(obj);
+ devmode->dev_private = PyString_AsString(obj);
devmode->driverextra = PyString_Size(obj);
- return True;
+ PyDict_DelItemString(dict_copy, "private");
+
+ if (!to_struct(devmode, dict_copy, py_DEVICEMODE))
+ goto done;
+
+ result = True;
+
+done:
+ Py_DECREF(dict_copy);
+ return result;
}
/*
BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info)
{
*dict = from_struct(info, py_PRINTER_INFO_0);
+ PyDict_SetItemString(*dict, "level", PyInt_FromLong(0));
return True;
}
BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info)
{
*dict = from_struct(info, py_PRINTER_INFO_1);
+ PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
return True;
}
BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict)
{
- return False;
+ PyObject *obj, *dict_copy = PyDict_Copy(dict);
+ BOOL result = False;
+
+ if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
+ !PyInt_Check(obj))
+ goto done;
+
+ PyDict_DelItemString(dict_copy, "level");
+
+ if (!to_struct(info, dict_copy, py_PRINTER_INFO_1))
+ goto done;
+
+ result = True;
+
+done:
+ Py_DECREF(dict_copy);
+ return result;
}
/*
*dict = from_struct(info, py_PRINTER_INFO_2);
- if (py_from_SECDESC(&obj, info->secdesc))
- PyDict_SetItemString(*dict, "security_descriptor", obj);
+ /* The security descriptor could be NULL */
+
+ if (info->secdesc) {
+ if (py_from_SECDESC(&obj, info->secdesc))
+ PyDict_SetItemString(*dict, "security_descriptor", obj);
+ }
+
+ /* Bong! The devmode could be NULL */
+
+ if (info->devmode)
+ py_from_DEVICEMODE(&obj, info->devmode);
+ else
+ obj = PyDict_New();
+
+ PyDict_SetItemString(*dict, "device_mode", obj);
- if (py_from_DEVICEMODE(&obj, info->devmode))
- PyDict_SetItemString(*dict, "device_mode", obj);
+ PyDict_SetItemString(*dict, "level", PyInt_FromLong(2));
return True;
}
-BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict)
+BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict,
+ TALLOC_CTX *mem_ctx)
{
- return False;
+ PyObject *obj, *dict_copy = PyDict_Copy(dict);
+ BOOL result = False;
+
+ /* Convert security descriptor - may be NULL */
+
+ info->secdesc = NULL;
+
+ if ((obj = PyDict_GetItemString(dict_copy, "security_descriptor"))) {
+
+ if (!PyDict_Check(obj))
+ goto done;
+
+ if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx))
+ goto done;
+
+ PyDict_DelItemString(dict_copy, "security_descriptor");
+ }
+
+ /* Convert device mode */
+
+ if (!(obj = PyDict_GetItemString(dict_copy, "device_mode"))
+ || !PyDict_Check(obj))
+ goto done;
+
+ info->devmode = _talloc(mem_ctx, sizeof(DEVICEMODE));
+
+ if (!py_to_DEVICEMODE(info->devmode, obj))
+ goto done;
+
+ PyDict_DelItemString(dict_copy, "device_mode");
+
+ /* Check info level */
+
+ if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
+ !PyInt_Check(obj))
+ goto done;
+
+ PyDict_DelItemString(dict_copy, "level");
+
+ /* Convert remaining elements of dictionary */
+
+ if (!to_struct(info, dict_copy, py_PRINTER_INFO_2))
+ goto done;
+
+ result = True;
+
+done:
+ Py_DECREF(dict_copy);
+ return result;
}
/*
BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info)
{
- PyObject *obj;
+ PyObject *obj;
*dict = from_struct(info, py_PRINTER_INFO_3);
if (py_from_SECDESC(&obj, info->secdesc))
PyDict_SetItemString(*dict, "security_descriptor", obj);
+ PyDict_SetItemString(*dict, "level", PyInt_FromLong(3));
+
return True;
}
-BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict)
+BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict,
+ TALLOC_CTX *mem_ctx)
{
- return False;
+ PyObject *obj;
+
+ if (!to_struct(info, dict, py_PRINTER_INFO_3))
+ return False;
+
+ if (!(obj = PyDict_GetItemString(dict, "security_descriptor")))
+ return False;
+
+ if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx))
+ return False;
+
+ return True;
}