man pages: Fix synonyms.
[Samba.git] / source / python / py_spoolss_jobs.c
blob8a76d247c67ca4be663dd15121bab168a1bdbe41
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 /* Enumerate jobs */
25 PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw)
27 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
28 WERROR werror;
29 PyObject *result;
30 int level = 1;
31 uint32 i, num_jobs;
32 static char *kwlist[] = {"level", NULL};
33 JOB_INFO_CTR ctr;
35 /* Parse parameters */
37 if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level))
38 return NULL;
40 /* Call rpc function */
42 werror = rpccli_spoolss_enumjobs(
43 hnd->cli, hnd->mem_ctx, &hnd->pol, level, 0, 1000,
44 &num_jobs, &ctr);
46 /* Return value */
48 result = Py_None;
50 if (!W_ERROR_IS_OK(werror)) {
51 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
52 goto done;
55 result = PyList_New(num_jobs);
57 switch (level) {
58 case 1:
59 for (i = 0; i < num_jobs; i++) {
60 PyObject *value;
62 py_from_JOB_INFO_1(&value, &ctr.job.job_info_1[i]);
64 PyList_SetItem(result, i, value);
67 break;
68 case 2:
69 for(i = 0; i < num_jobs; i++) {
70 PyObject *value;
72 py_from_JOB_INFO_2(&value, &ctr.job.job_info_2[i]);
74 PyList_SetItem(result, i, value);
77 break;
80 done:
81 Py_INCREF(result);
82 return result;
85 /* Set job command */
87 PyObject *spoolss_hnd_setjob(PyObject *self, PyObject *args, PyObject *kw)
89 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
90 WERROR werror;
91 uint32 level = 0, command, jobid;
92 static char *kwlist[] = {"jobid", "command", "level", NULL};
94 /* Parse parameters */
96 if (!PyArg_ParseTupleAndKeywords(
97 args, kw, "ii|i", kwlist, &jobid, &command, &level))
98 return NULL;
100 /* Call rpc function */
102 werror = rpccli_spoolss_setjob(
103 hnd->cli, hnd->mem_ctx, &hnd->pol, jobid, level, command);
105 if (!W_ERROR_IS_OK(werror)) {
106 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
107 return NULL;
110 Py_INCREF(Py_None);
111 return Py_None;
114 /* Get job */
116 PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw)
118 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
119 WERROR werror;
120 PyObject *result;
121 uint32 level = 1, jobid;
122 static char *kwlist[] = {"jobid", "level", NULL};
123 JOB_INFO_CTR ctr;
125 /* Parse parameters */
127 if (!PyArg_ParseTupleAndKeywords(
128 args, kw, "i|i", kwlist, &jobid, &level))
129 return NULL;
131 /* Call rpc function */
133 werror = rpccli_spoolss_getjob(
134 hnd->cli, hnd->mem_ctx, &hnd->pol, jobid, level, &ctr);
136 if (!W_ERROR_IS_OK(werror)) {
137 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
138 return NULL;
141 switch(level) {
142 case 1:
143 py_from_JOB_INFO_1(&result, &ctr.job.job_info_1[0]);
144 break;
145 case 2:
146 py_from_JOB_INFO_2(&result, &ctr.job.job_info_2[0]);
147 break;
150 return result;
153 /* Start page printer. This notifies the spooler that a page is about to be
154 printed on the specified printer. */
156 PyObject *spoolss_hnd_startpageprinter(PyObject *self, PyObject *args, PyObject *kw)
158 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
159 WERROR werror;
160 static char *kwlist[] = { NULL };
162 /* Parse parameters */
164 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
165 return NULL;
167 /* Call rpc function */
169 werror = rpccli_spoolss_startpageprinter(
170 hnd->cli, hnd->mem_ctx, &hnd->pol);
172 if (!W_ERROR_IS_OK(werror)) {
173 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
174 return NULL;
177 Py_INCREF(Py_None);
178 return Py_None;
181 /* End page printer. This notifies the spooler that a page has finished
182 being printed on the specified printer. */
184 PyObject *spoolss_hnd_endpageprinter(PyObject *self, PyObject *args, PyObject *kw)
186 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
187 WERROR werror;
188 static char *kwlist[] = { NULL };
190 /* Parse parameters */
192 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
193 return NULL;
195 /* Call rpc function */
197 werror = rpccli_spoolss_endpageprinter(
198 hnd->cli, hnd->mem_ctx, &hnd->pol);
200 if (!W_ERROR_IS_OK(werror)) {
201 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
202 return NULL;
205 Py_INCREF(Py_None);
206 return Py_None;
209 /* Start doc printer. This notifies the spooler that a document is about to be
210 printed on the specified printer. */
212 PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject *kw)
214 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
215 WERROR werror;
216 static char *kwlist[] = { "document_info", NULL };
217 PyObject *info, *obj;
218 uint32 level, jobid;
219 char *document_name = NULL, *output_file = NULL, *data_type = NULL;
221 /* Parse parameters */
223 if (!PyArg_ParseTupleAndKeywords(
224 args, kw, "O!", kwlist, &PyDict_Type, &info))
225 return NULL;
227 /* Check document_info parameter */
229 if (!get_level_value(info, &level)) {
230 PyErr_SetString(spoolss_error, "invalid info level");
231 return NULL;
234 if (level != 1) {
235 PyErr_SetString(spoolss_error, "unsupported info level");
236 return NULL;
239 if ((obj = PyDict_GetItemString(info, "document_name"))) {
241 if (!PyString_Check(obj) && obj != Py_None) {
242 PyErr_SetString(spoolss_error,
243 "document_name not a string");
244 return NULL;
247 if (PyString_Check(obj))
248 document_name = PyString_AsString(obj);
250 } else {
251 PyErr_SetString(spoolss_error, "no document_name present");
252 return NULL;
255 if ((obj = PyDict_GetItemString(info, "output_file"))) {
257 if (!PyString_Check(obj) && obj != Py_None) {
258 PyErr_SetString(spoolss_error,
259 "output_file not a string");
260 return NULL;
263 if (PyString_Check(obj))
264 output_file = PyString_AsString(obj);
266 } else {
267 PyErr_SetString(spoolss_error, "no output_file present");
268 return NULL;
271 if ((obj = PyDict_GetItemString(info, "data_type"))) {
273 if (!PyString_Check(obj) && obj != Py_None) {
274 PyErr_SetString(spoolss_error,
275 "data_type not a string");
276 return NULL;
279 if (PyString_Check(obj))
280 data_type = PyString_AsString(obj);
282 } else {
283 PyErr_SetString(spoolss_error, "no data_type present");
284 return NULL;
287 /* Call rpc function */
289 werror = rpccli_spoolss_startdocprinter(
290 hnd->cli, hnd->mem_ctx, &hnd->pol, document_name,
291 output_file, data_type, &jobid);
293 if (!W_ERROR_IS_OK(werror)) {
294 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
295 return NULL;
298 /* The return value is zero for an error (where does the status
299 code come from now??) and the return value is the jobid
300 allocated for the new job. */
302 return Py_BuildValue("i", jobid);
305 /* End doc printer. This notifies the spooler that a document has finished
306 being printed on the specified printer. */
308 PyObject *spoolss_hnd_enddocprinter(PyObject *self, PyObject *args, PyObject *kw)
310 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
311 WERROR werror;
312 static char *kwlist[] = { NULL };
314 /* Parse parameters */
316 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
317 return NULL;
319 /* Call rpc function */
321 werror = rpccli_spoolss_enddocprinter(
322 hnd->cli, hnd->mem_ctx, &hnd->pol);
324 if (!W_ERROR_IS_OK(werror)) {
325 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
326 return NULL;
329 Py_INCREF(Py_None);
330 return Py_None;
333 /* Write data to a printer */
335 PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw)
337 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
338 WERROR werror;
339 static char *kwlist[] = { "data", NULL };
340 PyObject *data;
341 uint32 num_written;
343 /* Parse parameters */
345 if (!PyArg_ParseTupleAndKeywords(
346 args, kw, "O!", kwlist, &PyString_Type, &data))
347 return NULL;
349 /* Call rpc function */
351 werror = rpccli_spoolss_writeprinter(
352 hnd->cli, hnd->mem_ctx, &hnd->pol, PyString_Size(data),
353 PyString_AsString(data), &num_written);
355 if (!W_ERROR_IS_OK(werror)) {
356 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
357 return NULL;
360 Py_INCREF(Py_None);
361 return Py_None;
364 PyObject *spoolss_hnd_addjob(PyObject *self, PyObject *args, PyObject *kw)
366 PyErr_SetString(spoolss_error, "Not implemented");
367 return NULL;