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"
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;
+ PyObject *obj, *dict_copy = PyDict_Copy(dict);
+ BOOL result = False;
- if (!to_struct(devmode, dict, py_DEVICEMODE))
- return False;
+ if (!(obj = PyDict_GetItemString(dict_copy, "private")))
+ goto done;
- if (!(obj = PyDict_GetItemString(dict, "private")))
- 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_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict)
{
- PyObject *dict_copy = PyDict_Copy(dict);
- BOOL result;
+ 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");
- result = to_struct(info, dict_copy, py_PRINTER_INFO_1);
+ if (!to_struct(info, dict_copy, py_PRINTER_INFO_1))
+ goto done;
+
+ result = True;
+
+done:
Py_DECREF(dict_copy);
return result;
}
BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict,
TALLOC_CTX *mem_ctx)
{
- PyObject *obj;
+ PyObject *obj, *dict_copy = PyDict_Copy(dict);
+ BOOL result = False;
- if (!to_struct(info, dict, py_PRINTER_INFO_2))
- return False;
+ /* Convert security descriptor - may be NULL */
- if (!(obj = PyDict_GetItemString(dict, "security_descriptor")))
- return False;
+ info->secdesc = NULL;
- if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx))
- return False;
+ if ((obj = PyDict_GetItemString(dict_copy, "security_descriptor"))) {
- if (!(obj = PyDict_GetItemString(dict, "device_mode")))
- return False;
+ 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 */
- info->devmode = talloc(mem_ctx, sizeof(DEVICEMODE));
+ 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))
- return False;
+ goto done;
- return True;
+ 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;
}
/*