r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / source3 / python / py_spoolss_jobs.c
blob3c160025bab48ad50a9b8f6ea8499de74dc8f648
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 /* Enumerate jobs */
24 PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw)
26 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
27 WERROR werror;
28 PyObject *result;
29 int level = 1;
30 uint32 i, num_jobs;
31 static char *kwlist[] = {"level", NULL};
32 JOB_INFO_CTR ctr;
34 /* Parse parameters */
36 if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level))
37 return NULL;
39 /* Call rpc function */
41 werror = rpccli_spoolss_enumjobs(
42 hnd->cli, hnd->mem_ctx, &hnd->pol, level, 0, 1000,
43 &num_jobs, &ctr);
45 /* Return value */
47 result = Py_None;
49 if (!W_ERROR_IS_OK(werror)) {
50 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
51 goto done;
54 result = PyList_New(num_jobs);
56 switch (level) {
57 case 1:
58 for (i = 0; i < num_jobs; i++) {
59 PyObject *value;
61 py_from_JOB_INFO_1(&value, &ctr.job.job_info_1[i]);
63 PyList_SetItem(result, i, value);
66 break;
67 case 2:
68 for(i = 0; i < num_jobs; i++) {
69 PyObject *value;
71 py_from_JOB_INFO_2(&value, &ctr.job.job_info_2[i]);
73 PyList_SetItem(result, i, value);
76 break;
79 done:
80 Py_INCREF(result);
81 return result;
84 /* Set job command */
86 PyObject *spoolss_hnd_setjob(PyObject *self, PyObject *args, PyObject *kw)
88 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
89 WERROR werror;
90 uint32 level = 0, command, jobid;
91 static char *kwlist[] = {"jobid", "command", "level", NULL};
93 /* Parse parameters */
95 if (!PyArg_ParseTupleAndKeywords(
96 args, kw, "ii|i", kwlist, &jobid, &command, &level))
97 return NULL;
99 /* Call rpc function */
101 werror = rpccli_spoolss_setjob(
102 hnd->cli, hnd->mem_ctx, &hnd->pol, jobid, level, command);
104 if (!W_ERROR_IS_OK(werror)) {
105 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
106 return NULL;
109 Py_INCREF(Py_None);
110 return Py_None;
113 /* Get job */
115 PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw)
117 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
118 WERROR werror;
119 PyObject *result;
120 uint32 level = 1, jobid;
121 static char *kwlist[] = {"jobid", "level", NULL};
122 JOB_INFO_CTR ctr;
124 /* Parse parameters */
126 if (!PyArg_ParseTupleAndKeywords(
127 args, kw, "i|i", kwlist, &jobid, &level))
128 return NULL;
130 /* Call rpc function */
132 werror = rpccli_spoolss_getjob(
133 hnd->cli, hnd->mem_ctx, &hnd->pol, jobid, level, &ctr);
135 if (!W_ERROR_IS_OK(werror)) {
136 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
137 return NULL;
140 switch(level) {
141 case 1:
142 py_from_JOB_INFO_1(&result, &ctr.job.job_info_1[0]);
143 break;
144 case 2:
145 py_from_JOB_INFO_2(&result, &ctr.job.job_info_2[0]);
146 break;
149 return result;
152 /* Start page printer. This notifies the spooler that a page is about to be
153 printed on the specified printer. */
155 PyObject *spoolss_hnd_startpageprinter(PyObject *self, PyObject *args, PyObject *kw)
157 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
158 WERROR werror;
159 static char *kwlist[] = { NULL };
161 /* Parse parameters */
163 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
164 return NULL;
166 /* Call rpc function */
168 werror = rpccli_spoolss_startpageprinter(
169 hnd->cli, hnd->mem_ctx, &hnd->pol);
171 if (!W_ERROR_IS_OK(werror)) {
172 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
173 return NULL;
176 Py_INCREF(Py_None);
177 return Py_None;
180 /* End page printer. This notifies the spooler that a page has finished
181 being printed on the specified printer. */
183 PyObject *spoolss_hnd_endpageprinter(PyObject *self, PyObject *args, PyObject *kw)
185 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
186 WERROR werror;
187 static char *kwlist[] = { NULL };
189 /* Parse parameters */
191 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
192 return NULL;
194 /* Call rpc function */
196 werror = rpccli_spoolss_endpageprinter(
197 hnd->cli, hnd->mem_ctx, &hnd->pol);
199 if (!W_ERROR_IS_OK(werror)) {
200 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
201 return NULL;
204 Py_INCREF(Py_None);
205 return Py_None;
208 /* Start doc printer. This notifies the spooler that a document is about to be
209 printed on the specified printer. */
211 PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject *kw)
213 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
214 WERROR werror;
215 static char *kwlist[] = { "document_info", NULL };
216 PyObject *info, *obj;
217 uint32 level, jobid;
218 char *document_name = NULL, *output_file = NULL, *data_type = NULL;
220 /* Parse parameters */
222 if (!PyArg_ParseTupleAndKeywords(
223 args, kw, "O!", kwlist, &PyDict_Type, &info))
224 return NULL;
226 /* Check document_info parameter */
228 if (!get_level_value(info, &level)) {
229 PyErr_SetString(spoolss_error, "invalid info level");
230 return NULL;
233 if (level != 1) {
234 PyErr_SetString(spoolss_error, "unsupported info level");
235 return NULL;
238 if ((obj = PyDict_GetItemString(info, "document_name"))) {
240 if (!PyString_Check(obj) && obj != Py_None) {
241 PyErr_SetString(spoolss_error,
242 "document_name not a string");
243 return NULL;
246 if (PyString_Check(obj))
247 document_name = PyString_AsString(obj);
249 } else {
250 PyErr_SetString(spoolss_error, "no document_name present");
251 return NULL;
254 if ((obj = PyDict_GetItemString(info, "output_file"))) {
256 if (!PyString_Check(obj) && obj != Py_None) {
257 PyErr_SetString(spoolss_error,
258 "output_file not a string");
259 return NULL;
262 if (PyString_Check(obj))
263 output_file = PyString_AsString(obj);
265 } else {
266 PyErr_SetString(spoolss_error, "no output_file present");
267 return NULL;
270 if ((obj = PyDict_GetItemString(info, "data_type"))) {
272 if (!PyString_Check(obj) && obj != Py_None) {
273 PyErr_SetString(spoolss_error,
274 "data_type not a string");
275 return NULL;
278 if (PyString_Check(obj))
279 data_type = PyString_AsString(obj);
281 } else {
282 PyErr_SetString(spoolss_error, "no data_type present");
283 return NULL;
286 /* Call rpc function */
288 werror = rpccli_spoolss_startdocprinter(
289 hnd->cli, hnd->mem_ctx, &hnd->pol, document_name,
290 output_file, data_type, &jobid);
292 if (!W_ERROR_IS_OK(werror)) {
293 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
294 return NULL;
297 /* The return value is zero for an error (where does the status
298 code come from now??) and the return value is the jobid
299 allocated for the new job. */
301 return Py_BuildValue("i", jobid);
304 /* End doc printer. This notifies the spooler that a document has finished
305 being printed on the specified printer. */
307 PyObject *spoolss_hnd_enddocprinter(PyObject *self, PyObject *args, PyObject *kw)
309 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
310 WERROR werror;
311 static char *kwlist[] = { NULL };
313 /* Parse parameters */
315 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
316 return NULL;
318 /* Call rpc function */
320 werror = rpccli_spoolss_enddocprinter(
321 hnd->cli, hnd->mem_ctx, &hnd->pol);
323 if (!W_ERROR_IS_OK(werror)) {
324 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
325 return NULL;
328 Py_INCREF(Py_None);
329 return Py_None;
332 /* Write data to a printer */
334 PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw)
336 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
337 WERROR werror;
338 static char *kwlist[] = { "data", NULL };
339 PyObject *data;
340 uint32 num_written;
342 /* Parse parameters */
344 if (!PyArg_ParseTupleAndKeywords(
345 args, kw, "O!", kwlist, &PyString_Type, &data))
346 return NULL;
348 /* Call rpc function */
350 werror = rpccli_spoolss_writeprinter(
351 hnd->cli, hnd->mem_ctx, &hnd->pol, PyString_Size(data),
352 PyString_AsString(data), &num_written);
354 if (!W_ERROR_IS_OK(werror)) {
355 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
356 return NULL;
359 Py_INCREF(Py_None);
360 return Py_None;
363 PyObject *spoolss_hnd_addjob(PyObject *self, PyObject *args, PyObject *kw)
365 PyErr_SetString(spoolss_error, "Not implemented");
366 return NULL;