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 struct pyconv py_FORM[] = {
24 { "flags", PY_UINT32, offsetof(FORM, flags) },
25 { "width", PY_UINT32, offsetof(FORM, size_x) },
26 { "length", PY_UINT32, offsetof(FORM, size_y) },
27 { "top", PY_UINT32, offsetof(FORM, top) },
28 { "left", PY_UINT32, offsetof(FORM, left) },
29 { "right", PY_UINT32, offsetof(FORM, right) },
30 { "bottom", PY_UINT32, offsetof(FORM, bottom) },
34 struct pyconv py_FORM_1[] = {
35 { "flags", PY_UINT32, offsetof(FORM_1, flag) },
36 { "width", PY_UINT32, offsetof(FORM_1, width) },
37 { "length", PY_UINT32, offsetof(FORM_1, length) },
38 { "top", PY_UINT32, offsetof(FORM_1, top) },
39 { "left", PY_UINT32, offsetof(FORM_1, left) },
40 { "right", PY_UINT32, offsetof(FORM_1, right) },
41 { "bottom", PY_UINT32, offsetof(FORM_1, bottom) },
42 { "name", PY_UNISTR, offsetof(FORM_1, name) },
48 PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw)
50 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
55 static char *kwlist[] = {"form", "level", NULL};
57 /* Parse parameters */
59 if (!PyArg_ParseTupleAndKeywords(
60 args, kw, "O!|i", kwlist, &PyDict_Type, &py_form, &level))
63 /* Call rpc function */
67 PyObject *py_form_name;
70 to_struct(&form, py_form, py_FORM);
72 py_form_name = PyDict_GetItemString(py_form, "name");
73 form_name = PyString_AsString(py_form_name);
75 init_unistr2(&form.name, form_name, strlen(form_name) + 1);
80 PyErr_SetString(spoolss_error, "unsupported info level");
84 werror = cli_spoolss_addform(hnd->cli, hnd->mem_ctx, &hnd->pol,
88 if (!W_ERROR_IS_OK(werror)) {
89 PyErr_SetObject(spoolss_werror,
90 PyInt_FromLong(W_ERROR_V(werror)));
98 /* Get form properties */
100 PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw)
102 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
107 static char *kwlist[] = {"form_name", "level", NULL};
111 /* Parse parameters */
113 if (!PyArg_ParseTupleAndKeywords(args, kw, "s|i", kwlist,
117 /* Call rpc function */
119 werror = cli_spoolss_getform(hnd->cli, hnd->mem_ctx, 0, &needed,
120 &hnd->pol, form_name, 1, &form);
122 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
123 werror = cli_spoolss_getform(
124 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
125 form_name, 1, &form);
127 if (!W_ERROR_IS_OK(werror)) {
128 PyErr_SetObject(spoolss_werror,
129 PyInt_FromLong(W_ERROR_V(werror)));
137 result = from_struct(&form, py_FORM_1);
145 /* Set form properties */
147 PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw)
149 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
153 static char *kwlist[] = {"form_name", "form", "level", NULL};
157 /* Parse parameters */
159 if (!PyArg_ParseTupleAndKeywords(args, kw, "sO!|i", kwlist,
160 &form_name, &PyDict_Type, &py_form,
164 /* Call rpc function */
166 to_struct(&form, py_form, py_FORM);
167 init_unistr2(&form.name, form_name, strlen(form_name) + 1);
169 werror = cli_spoolss_setform(hnd->cli, hnd->mem_ctx, &hnd->pol,
170 level, form_name, &form);
172 if (!W_ERROR_IS_OK(werror)) {
173 PyErr_SetObject(spoolss_werror,
174 PyInt_FromLong(W_ERROR_V(werror)));
185 PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw)
187 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
190 static char *kwlist[] = {"form_name", "level", NULL};
193 /* Parse parameters */
195 if (!PyArg_ParseTupleAndKeywords(
196 args, kw, "s|i", kwlist, &form_name, &level))
199 /* Call rpc function */
201 werror = cli_spoolss_deleteform(
202 hnd->cli, hnd->mem_ctx, &hnd->pol, form_name);
204 if (!W_ERROR_IS_OK(werror)) {
205 PyErr_SetObject(spoolss_werror,
206 PyInt_FromLong(W_ERROR_V(werror)));
214 /* Enumerate forms */
216 PyObject *spoolss_enumforms(PyObject *self, PyObject *args, PyObject *kw)
219 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
221 uint32 level = 1, num_forms, needed, i;
222 static char *kwlist[] = {"level", NULL};
225 /* Parse parameters */
227 if (!PyArg_ParseTupleAndKeywords(
228 args, kw, "|i", kwlist, &level))
231 /* Call rpc function */
233 werror = cli_spoolss_enumforms(
234 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
237 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
238 werror = cli_spoolss_enumforms(
239 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, level,
242 if (!W_ERROR_IS_OK(werror)) {
243 PyErr_SetObject(spoolss_werror,
244 PyInt_FromLong(W_ERROR_V(werror)));
248 result = PyList_New(num_forms);
250 for (i = 0; i < num_forms; i++) {
251 PyObject *obj = NULL;
255 obj = from_struct(&forms[i], py_FORM_1);
259 PyList_SetItem(result, i, obj);