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"
23 static BOOL py_from_printerdata(PyObject **dict, char *value,
24 uint32 data_type, char *data,
29 PyDict_SetItemString(*dict, "type", Py_BuildValue("i", data_type));
30 PyDict_SetItemString(*dict, "value", Py_BuildValue("s", value));
32 PyDict_SetItemString(*dict, "data",
33 Py_BuildValue("s#", data, data_size));
38 static BOOL py_to_printerdata(char **value, uint32 *data_type,
39 char **data, uint32 *data_size,
44 if ((obj = PyDict_GetItemString(dict, "type"))) {
46 if (!PyInt_Check(obj)) {
47 PyErr_SetString(spoolss_error,
48 "type not an integer");
52 *data_type = PyInt_AsLong(obj);
54 PyErr_SetString(spoolss_error, "no type present");
58 if ((obj = PyDict_GetItemString(dict, "value"))) {
60 if (!PyString_Check(obj)) {
61 PyErr_SetString(spoolss_error,
62 "value not a string");
66 *value = PyString_AsString(obj);
68 PyErr_SetString(spoolss_error, "no value present");
72 if ((obj = PyDict_GetItemString(dict, "data"))) {
74 if (!PyString_Check(obj)) {
75 PyErr_SetString(spoolss_error,
80 *data = PyString_AsString(obj);
81 *data_size = PyString_Size(obj);
83 PyErr_SetString(spoolss_error, "no data present");
90 PyObject *spoolss_getprinterdata(PyObject *self, PyObject *args, PyObject *kw)
92 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
93 static char *kwlist[] = { "value", NULL };
96 uint32 needed, data_type, data_size;
100 /* Parse parameters */
102 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value))
105 /* Call rpc function */
107 werror = cli_spoolss_getprinterdata(
108 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, value,
109 &data_type, &data, &data_size);
111 if (W_ERROR_V(werror) == ERRmoredata)
112 werror = cli_spoolss_getprinterdata(
113 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, value,
114 &data_type, &data, &data_size);
116 if (!W_ERROR_IS_OK(werror)) {
117 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
121 py_from_printerdata(&result, value, data_type, data, needed);
126 PyObject *spoolss_setprinterdata(PyObject *self, PyObject *args, PyObject *kw)
128 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
129 static char *kwlist[] = { "data", NULL };
132 uint32 data_size, data_type;
135 if (!PyArg_ParseTupleAndKeywords(args, kw, "O!", kwlist,
136 &PyDict_Type, &py_data))
139 if (!py_to_printerdata(&value, &data_type, &data, &data_size, py_data))
142 /* Call rpc function */
144 werror = cli_spoolss_setprinterdata(
145 hnd->cli, hnd->mem_ctx, &hnd->pol, value, data_type,
148 if (!W_ERROR_IS_OK(werror)) {
149 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
157 PyObject *spoolss_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw)