r8654: merging cli_spoolss_XX() updates from trunk
[Samba.git] / source / python / py_spoolss_forms.c
blob00c5b18e18d39b01c09b8da578e497027d27cbe0
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 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 /* Add a form */
25 PyObject *spoolss_hnd_addform(PyObject *self, PyObject *args, PyObject *kw)
27 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
28 WERROR werror;
29 PyObject *info;
30 FORM form;
31 int level;
32 static char *kwlist[] = {"form", NULL};
34 /* Parse parameters */
36 if (!PyArg_ParseTupleAndKeywords(
37 args, kw, "O!", kwlist, &PyDict_Type, &info))
38 return NULL;
40 /* Call rpc function */
42 if (!py_to_FORM(&form, info)) {
43 PyErr_SetString(spoolss_error, "invalid form");
44 return NULL;
47 if (!get_level_value(info, &level)) {
48 PyErr_SetString(spoolss_error, "invalid info level");
49 return NULL;
52 if (level != 1) {
53 PyErr_SetString(spoolss_error, "unsupported info level");
54 return NULL;
57 switch (level) {
58 case 1: {
59 PyObject *obj = PyDict_GetItemString(info, "name");
60 char *form_name = PyString_AsString(obj);
62 init_unistr2(&form.name, form_name, UNI_STR_TERMINATE);
63 break;
65 default:
66 PyErr_SetString(spoolss_error, "unsupported info level");
67 return NULL;
70 werror = cli_spoolss_addform(hnd->cli, hnd->mem_ctx, &hnd->pol,
71 level, &form);
74 if (!W_ERROR_IS_OK(werror)) {
75 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
76 return NULL;
79 Py_INCREF(Py_None);
80 return Py_None;
83 /* Get form properties */
85 PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw)
87 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
88 WERROR werror;
89 PyObject *result;
90 char *form_name;
91 int level = 1;
92 static char *kwlist[] = {"form_name", "level", NULL};
93 uint32 needed;
94 FORM_1 form;
96 /* Parse parameters */
98 if (!PyArg_ParseTupleAndKeywords(
99 args, kw, "s|i", kwlist, &form_name, &level))
100 return NULL;
102 /* Call rpc function */
104 werror = cli_spoolss_getform(hnd->cli, hnd->mem_ctx,
105 &hnd->pol, form_name, level, &form);
107 if (!W_ERROR_IS_OK(werror)) {
108 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
109 return NULL;
112 result = Py_None;
114 switch(level) {
115 case 1:
116 py_from_FORM_1(&result, &form);
117 break;
120 Py_INCREF(result);
121 return result;
124 /* Set form properties */
126 PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw)
128 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
129 WERROR werror;
130 PyObject *info, *form_name;
131 int level;
132 static char *kwlist[] = { "form", NULL};
133 FORM form;
135 /* Parse parameters */
137 if (!PyArg_ParseTupleAndKeywords(
138 args, kw, "O!", kwlist, &PyDict_Type, &info))
139 return NULL;
141 if (!get_level_value(info, &level)) {
142 PyErr_SetString(spoolss_error, "invalid info level");
143 return NULL;
146 if (level != 1) {
147 PyErr_SetString(spoolss_error, "unsupported info level");
148 return NULL;
151 /* Call rpc function */
153 if (!py_to_FORM(&form, info)) {
154 PyErr_SetString(spoolss_error, "invalid form");
155 return NULL;
158 form_name = PyDict_GetItemString(info, "name");
160 werror = cli_spoolss_setform(
161 hnd->cli, hnd->mem_ctx, &hnd->pol, level,
162 PyString_AsString(form_name), &form);
164 if (!W_ERROR_IS_OK(werror)) {
165 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
166 return NULL;
169 Py_INCREF(Py_None);
170 return Py_None;
173 /* Delete a form */
175 PyObject *spoolss_hnd_deleteform(PyObject *self, PyObject *args, PyObject *kw)
177 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
178 WERROR werror;
179 static char *kwlist[] = {"form_name", NULL};
180 char *form_name;
182 /* Parse parameters */
184 if (!PyArg_ParseTupleAndKeywords(
185 args, kw, "s", kwlist, &form_name))
186 return NULL;
188 /* Call rpc function */
190 werror = cli_spoolss_deleteform(
191 hnd->cli, hnd->mem_ctx, &hnd->pol, form_name);
193 if (!W_ERROR_IS_OK(werror)) {
194 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
195 return NULL;
198 Py_INCREF(Py_None);
199 return Py_None;
202 /* Enumerate forms */
204 PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw)
206 PyObject *result;
207 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
208 WERROR werror;
209 uint32 level = 1, num_forms, i;
210 static char *kwlist[] = {"level", NULL};
211 FORM_1 *forms;
213 /* Parse parameters */
215 if (!PyArg_ParseTupleAndKeywords(
216 args, kw, "|i", kwlist, &level))
217 return NULL;
219 /* Call rpc function */
221 werror = cli_spoolss_enumforms(
222 hnd->cli, hnd->mem_ctx, &hnd->pol, level,
223 &num_forms, &forms);
225 if (!W_ERROR_IS_OK(werror)) {
226 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
227 return NULL;
230 switch(level) {
231 case 1:
232 result = PyDict_New();
234 for (i = 0; i < num_forms; i++) {
235 PyObject *value;
236 fstring name;
238 rpcstr_pull(name, forms[i].name.buffer,
239 sizeof(fstring), -1, STR_TERMINATE);
241 py_from_FORM_1(&value, &forms[i]);
243 PyDict_SetItemString(
244 value, "level", PyInt_FromLong(1));
246 PyDict_SetItemString(result, name, value);
249 break;
250 default:
251 PyErr_SetString(spoolss_error, "unknown info level");
252 return NULL;
255 return result;