r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[Samba/bb.git] / source / python / py_spoolss_forms.c
blobdf2067aa8bee8c9fa3a8092e2fa00534bac07281
1 /*
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 3 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, see <http://www.gnu.org/licenses/>.
20 #include "python/py_spoolss.h"
22 /* Add a form */
24 PyObject *spoolss_hnd_addform(PyObject *self, PyObject *args, PyObject *kw)
26 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
27 WERROR werror;
28 PyObject *info;
29 FORM form;
30 int level;
31 static char *kwlist[] = {"form", NULL};
33 /* Parse parameters */
35 if (!PyArg_ParseTupleAndKeywords(
36 args, kw, "O!", kwlist, &PyDict_Type, &info))
37 return NULL;
39 /* Call rpc function */
41 if (!py_to_FORM(&form, info)) {
42 PyErr_SetString(spoolss_error, "invalid form");
43 return NULL;
46 if (!get_level_value(info, &level)) {
47 PyErr_SetString(spoolss_error, "invalid info level");
48 return NULL;
51 if (level != 1) {
52 PyErr_SetString(spoolss_error, "unsupported info level");
53 return NULL;
56 switch (level) {
57 case 1: {
58 PyObject *obj = PyDict_GetItemString(info, "name");
59 char *form_name = PyString_AsString(obj);
61 init_unistr2(&form.name, form_name, UNI_STR_TERMINATE);
62 break;
64 default:
65 PyErr_SetString(spoolss_error, "unsupported info level");
66 return NULL;
69 werror = rpccli_spoolss_addform(hnd->cli, hnd->mem_ctx, &hnd->pol,
70 level, &form);
73 if (!W_ERROR_IS_OK(werror)) {
74 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
75 return NULL;
78 Py_INCREF(Py_None);
79 return Py_None;
82 /* Get form properties */
84 PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw)
86 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
87 WERROR werror;
88 PyObject *result;
89 char *form_name;
90 int level = 1;
91 static char *kwlist[] = {"form_name", "level", NULL};
92 FORM_1 form;
94 /* Parse parameters */
96 if (!PyArg_ParseTupleAndKeywords(
97 args, kw, "s|i", kwlist, &form_name, &level))
98 return NULL;
100 /* Call rpc function */
102 werror = rpccli_spoolss_getform(
103 hnd->cli, hnd->mem_ctx, &hnd->pol, form_name, level, &form);
105 if (!W_ERROR_IS_OK(werror)) {
106 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
107 return NULL;
110 result = Py_None;
112 switch(level) {
113 case 1:
114 py_from_FORM_1(&result, &form);
115 break;
118 Py_INCREF(result);
119 return result;
122 /* Set form properties */
124 PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw)
126 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
127 WERROR werror;
128 PyObject *info, *form_name;
129 int level;
130 static char *kwlist[] = { "form", NULL};
131 FORM form;
133 /* Parse parameters */
135 if (!PyArg_ParseTupleAndKeywords(
136 args, kw, "O!", kwlist, &PyDict_Type, &info))
137 return NULL;
139 if (!get_level_value(info, &level)) {
140 PyErr_SetString(spoolss_error, "invalid info level");
141 return NULL;
144 if (level != 1) {
145 PyErr_SetString(spoolss_error, "unsupported info level");
146 return NULL;
149 /* Call rpc function */
151 if (!py_to_FORM(&form, info)) {
152 PyErr_SetString(spoolss_error, "invalid form");
153 return NULL;
156 form_name = PyDict_GetItemString(info, "name");
158 werror = rpccli_spoolss_setform(
159 hnd->cli, hnd->mem_ctx, &hnd->pol, level,
160 PyString_AsString(form_name), &form);
162 if (!W_ERROR_IS_OK(werror)) {
163 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
164 return NULL;
167 Py_INCREF(Py_None);
168 return Py_None;
171 /* Delete a form */
173 PyObject *spoolss_hnd_deleteform(PyObject *self, PyObject *args, PyObject *kw)
175 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
176 WERROR werror;
177 static char *kwlist[] = {"form_name", NULL};
178 char *form_name;
180 /* Parse parameters */
182 if (!PyArg_ParseTupleAndKeywords(
183 args, kw, "s", kwlist, &form_name))
184 return NULL;
186 /* Call rpc function */
188 werror = rpccli_spoolss_deleteform(
189 hnd->cli, hnd->mem_ctx, &hnd->pol, form_name);
191 if (!W_ERROR_IS_OK(werror)) {
192 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
193 return NULL;
196 Py_INCREF(Py_None);
197 return Py_None;
200 /* Enumerate forms */
202 PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw)
204 PyObject *result;
205 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
206 WERROR werror;
207 uint32 level = 1, num_forms, i;
208 static char *kwlist[] = {"level", NULL};
209 FORM_1 *forms;
211 /* Parse parameters */
213 if (!PyArg_ParseTupleAndKeywords(
214 args, kw, "|i", kwlist, &level))
215 return NULL;
217 /* Call rpc function */
219 werror = rpccli_spoolss_enumforms(
220 hnd->cli, hnd->mem_ctx, &hnd->pol, level, &num_forms, &forms);
222 if (!W_ERROR_IS_OK(werror)) {
223 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
224 return NULL;
227 switch(level) {
228 case 1:
229 result = PyDict_New();
231 for (i = 0; i < num_forms; i++) {
232 PyObject *value;
233 fstring name;
235 rpcstr_pull(name, forms[i].name.buffer,
236 sizeof(fstring), -1, STR_TERMINATE);
238 py_from_FORM_1(&value, &forms[i]);
240 PyDict_SetItemString(
241 value, "level", PyInt_FromLong(1));
243 PyDict_SetItemString(result, name, value);
246 break;
247 default:
248 PyErr_SetString(spoolss_error, "unknown info level");
249 return NULL;
252 return result;