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.
23 #include "python/py_spoolss.h"
25 struct pyconv py_FORM[] = {
26 { "flags", PY_UINT32, offsetof(FORM, flags) },
27 { "width", PY_UINT32, offsetof(FORM, size_x) },
28 { "length", PY_UINT32, offsetof(FORM, size_y) },
29 { "top", PY_UINT32, offsetof(FORM, top) },
30 { "left", PY_UINT32, offsetof(FORM, left) },
31 { "right", PY_UINT32, offsetof(FORM, right) },
32 { "bottom", PY_UINT32, offsetof(FORM, bottom) },
36 struct pyconv py_FORM_1[] = {
37 { "flags", PY_UINT32, offsetof(FORM_1, flag) },
38 { "width", PY_UINT32, offsetof(FORM_1, width) },
39 { "length", PY_UINT32, offsetof(FORM_1, length) },
40 { "top", PY_UINT32, offsetof(FORM_1, top) },
41 { "left", PY_UINT32, offsetof(FORM_1, left) },
42 { "right", PY_UINT32, offsetof(FORM_1, right) },
43 { "bottom", PY_UINT32, offsetof(FORM_1, bottom) },
44 { "name", PY_UNISTR, offsetof(FORM_1, name) },
50 PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw)
52 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
57 static char *kwlist[] = {"form", "level", NULL};
59 /* Parse parameters */
61 if (!PyArg_ParseTupleAndKeywords(
62 args, kw, "O!|i", kwlist, &PyDict_Type, &py_form, &level))
65 /* Call rpc function */
69 PyObject *py_form_name;
72 to_struct(&form, py_form, py_FORM);
74 py_form_name = PyDict_GetItemString(py_form, "name");
75 form_name = PyString_AsString(py_form_name);
77 init_unistr2(&form.name, form_name, strlen(form_name) + 1);
82 PyErr_SetString(spoolss_error, "unsupported info level");
86 werror = cli_spoolss_addform(hnd->cli, hnd->mem_ctx, &hnd->pol,
90 if (!W_ERROR_IS_OK(werror)) {
91 PyErr_SetObject(spoolss_werror,
92 PyInt_FromLong(W_ERROR_V(werror)));
100 /* Get form properties */
102 PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw)
104 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
109 static char *kwlist[] = {"form_name", "level", NULL};
113 /* Parse parameters */
115 if (!PyArg_ParseTupleAndKeywords(args, kw, "s|i", kwlist, &form_name, &level))
118 /* Call rpc function */
120 werror = cli_spoolss_getform(hnd->cli, hnd->mem_ctx, 0, &needed,
121 &hnd->pol, form_name, 1, &form);
123 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
124 werror = cli_spoolss_getform(
125 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
126 form_name, 1, &form);
128 if (!W_ERROR_IS_OK(werror)) {
129 PyErr_SetObject(spoolss_werror,
130 PyInt_FromLong(W_ERROR_V(werror)));
138 result = from_struct(&form, py_FORM_1);
146 /* Set form properties */
148 PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw)
150 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
154 static char *kwlist[] = {"form_name", "form", "level", NULL};
158 /* Parse parameters */
160 if (!PyArg_ParseTupleAndKeywords(args, kw, "sO!|i", kwlist,
161 &form_name, &PyDict_Type, &py_form, &level))
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);