implemented lock and mknod
[Samba.git] / source / python / py_spoolss_jobs.c
blobcc5d42e0eefe28dd8a11d1a0cb4065b0dbe0a3c0
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, needed, 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 = cli_spoolss_enumjobs(
43 hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, 0,
44 1000, &num_jobs, &ctr);
46 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
47 werror = cli_spoolss_enumjobs(
48 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
49 level, 0, 1000, &num_jobs, &ctr);
51 /* Return value */
53 result = Py_None;
55 if (!W_ERROR_IS_OK(werror)) {
56 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
57 goto done;
60 result = PyList_New(num_jobs);
62 switch (level) {
63 case 1:
64 for (i = 0; i < num_jobs; i++) {
65 PyObject *value;
67 py_from_JOB_INFO_1(&value, &ctr.job.job_info_1[i]);
69 PyList_SetItem(result, i, value);
72 break;
73 case 2:
74 for(i = 0; i < num_jobs; i++) {
75 PyObject *value;
77 py_from_JOB_INFO_2(&value, &ctr.job.job_info_2[i]);
79 PyList_SetItem(result, i, value);
82 break;
85 done:
86 Py_INCREF(result);
87 return result;
90 /* Set job command */
92 PyObject *spoolss_hnd_setjob(PyObject *self, PyObject *args, PyObject *kw)
94 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
95 WERROR werror;
96 uint32 level = 0, command, jobid;
97 static char *kwlist[] = {"jobid", "command", "level", NULL};
99 /* Parse parameters */
101 if (!PyArg_ParseTupleAndKeywords(
102 args, kw, "ii|i", kwlist, &jobid, &command, &level))
103 return NULL;
105 /* Call rpc function */
107 werror = cli_spoolss_setjob(hnd->cli, hnd->mem_ctx, &hnd->pol,
108 jobid, level, command);
110 if (!W_ERROR_IS_OK(werror)) {
111 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
112 return NULL;
115 Py_INCREF(Py_None);
116 return Py_None;
119 /* Get job */
121 PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw)
123 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
124 WERROR werror;
125 PyObject *result;
126 uint32 level = 1, jobid, needed;
127 static char *kwlist[] = {"jobid", "level", NULL};
128 JOB_INFO_CTR ctr;
130 /* Parse parameters */
132 if (!PyArg_ParseTupleAndKeywords(
133 args, kw, "i|i", kwlist, &jobid, &level))
134 return NULL;
136 /* Call rpc function */
138 werror = cli_spoolss_getjob(hnd->cli, hnd->mem_ctx, 0, &needed,
139 &hnd->pol, jobid, level, &ctr);
141 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
142 werror = cli_spoolss_getjob(
143 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
144 jobid, level, &ctr);
146 if (!W_ERROR_IS_OK(werror)) {
147 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
148 return NULL;
151 switch(level) {
152 case 1:
153 py_from_JOB_INFO_1(&result, ctr.job.job_info_1);
154 break;
155 case 2:
156 py_from_JOB_INFO_2(&result, ctr.job.job_info_2);
157 break;
160 return result;
163 /* Start page printer. This notifies the spooler that a page is about to be
164 printed on the specified printer. */
166 PyObject *spoolss_hnd_startpageprinter(PyObject *self, PyObject *args, PyObject *kw)
168 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
169 WERROR werror;
170 static char *kwlist[] = { NULL };
172 /* Parse parameters */
174 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
175 return NULL;
177 /* Call rpc function */
179 werror = cli_spoolss_startpageprinter(
180 hnd->cli, hnd->mem_ctx, &hnd->pol);
182 if (!W_ERROR_IS_OK(werror)) {
183 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
184 return NULL;
187 Py_INCREF(Py_None);
188 return Py_None;
191 /* End page printer. This notifies the spooler that a page has finished
192 being printed on the specified printer. */
194 PyObject *spoolss_hnd_endpageprinter(PyObject *self, PyObject *args, PyObject *kw)
196 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
197 WERROR werror;
198 static char *kwlist[] = { NULL };
200 /* Parse parameters */
202 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
203 return NULL;
205 /* Call rpc function */
207 werror = cli_spoolss_endpageprinter(
208 hnd->cli, hnd->mem_ctx, &hnd->pol);
210 if (!W_ERROR_IS_OK(werror)) {
211 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
212 return NULL;
215 Py_INCREF(Py_None);
216 return Py_None;
219 /* Start doc printer. This notifies the spooler that a document is about to be
220 printed on the specified printer. */
222 PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject *kw)
224 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
225 WERROR werror;
226 static char *kwlist[] = { "document_info", NULL };
227 PyObject *info, *obj;
228 uint32 level, jobid;
229 char *document_name = NULL, *output_file = NULL, *data_type = NULL;
231 /* Parse parameters */
233 if (!PyArg_ParseTupleAndKeywords(
234 args, kw, "O!", kwlist, &PyDict_Type, &info))
235 return NULL;
237 /* Check document_info parameter */
239 if (!get_level_value(info, &level)) {
240 PyErr_SetString(spoolss_error, "invalid info level");
241 return NULL;
244 if (level != 1) {
245 PyErr_SetString(spoolss_error, "unsupported info level");
246 return NULL;
249 if ((obj = PyDict_GetItemString(info, "document_name"))) {
251 if (!PyString_Check(obj) && obj != Py_None) {
252 PyErr_SetString(spoolss_error,
253 "document_name not a string");
254 return NULL;
257 if (PyString_Check(obj))
258 document_name = PyString_AsString(obj);
260 } else {
261 PyErr_SetString(spoolss_error, "no document_name present");
262 return NULL;
265 if ((obj = PyDict_GetItemString(info, "output_file"))) {
267 if (!PyString_Check(obj) && obj != Py_None) {
268 PyErr_SetString(spoolss_error,
269 "output_file not a string");
270 return NULL;
273 if (PyString_Check(obj))
274 output_file = PyString_AsString(obj);
276 } else {
277 PyErr_SetString(spoolss_error, "no output_file present");
278 return NULL;
281 if ((obj = PyDict_GetItemString(info, "data_type"))) {
283 if (!PyString_Check(obj) && obj != Py_None) {
284 PyErr_SetString(spoolss_error,
285 "data_type not a string");
286 return NULL;
289 if (PyString_Check(obj))
290 data_type = PyString_AsString(obj);
292 } else {
293 PyErr_SetString(spoolss_error, "no data_type present");
294 return NULL;
297 /* Call rpc function */
299 werror = cli_spoolss_startdocprinter(
300 hnd->cli, hnd->mem_ctx, &hnd->pol, document_name,
301 output_file, data_type, &jobid);
303 if (!W_ERROR_IS_OK(werror)) {
304 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
305 return NULL;
308 /* The return value is zero for an error (where does the status
309 code come from now??) and the return value is the jobid
310 allocated for the new job. */
312 return Py_BuildValue("i", jobid);
315 /* End doc printer. This notifies the spooler that a document has finished
316 being printed on the specified printer. */
318 PyObject *spoolss_hnd_enddocprinter(PyObject *self, PyObject *args, PyObject *kw)
320 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
321 WERROR werror;
322 static char *kwlist[] = { NULL };
324 /* Parse parameters */
326 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
327 return NULL;
329 /* Call rpc function */
331 werror = cli_spoolss_enddocprinter(hnd->cli, hnd->mem_ctx, &hnd->pol);
333 if (!W_ERROR_IS_OK(werror)) {
334 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
335 return NULL;
338 Py_INCREF(Py_None);
339 return Py_None;
342 /* Write data to a printer */
344 PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw)
346 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
347 WERROR werror;
348 static char *kwlist[] = { "data", NULL };
349 PyObject *data;
350 uint32 num_written;
352 /* Parse parameters */
354 if (!PyArg_ParseTupleAndKeywords(
355 args, kw, "O!", kwlist, &PyString_Type, &data))
356 return NULL;
358 /* Call rpc function */
360 werror = cli_spoolss_writeprinter(
361 hnd->cli, hnd->mem_ctx, &hnd->pol, PyString_Size(data),
362 PyString_AsString(data), &num_written);
364 if (!W_ERROR_IS_OK(werror)) {
365 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
366 return NULL;
369 Py_INCREF(Py_None);
370 return Py_None;
373 PyObject *spoolss_hnd_addjob(PyObject *self, PyObject *args, PyObject *kw)
375 PyErr_SetString(spoolss_error, "Not implemented");
376 return NULL;