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"
25 PyObject *spoolss_enumjobs(PyObject *self, PyObject *args, PyObject *kw)
27 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
31 uint32 i, needed, num_jobs;
32 static char *kwlist[] = {"level", NULL};
35 /* Parse parameters */
37 if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level))
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);
55 if (!W_ERROR_IS_OK(werror))
58 result = PyList_New(num_jobs);
62 for (i = 0; i < num_jobs; i++) {
65 py_from_JOB_INFO_1(&value, &ctr.job.job_info_1[i]);
67 PyList_SetItem(result, i, value);
72 for(i = 0; i < num_jobs; i++) {
75 py_from_JOB_INFO_2(&value, &ctr.job.job_info_2[i]);
77 PyList_SetItem(result, i, value);
90 PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw)
92 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
94 uint32 level = 0, command, jobid;
95 static char *kwlist[] = {"jobid", "command", "level", NULL};
97 /* Parse parameters */
99 if (!PyArg_ParseTupleAndKeywords(args, kw, "ii|i", kwlist, &jobid,
103 /* Call rpc function */
105 werror = cli_spoolss_setjob(hnd->cli, hnd->mem_ctx, &hnd->pol,
106 jobid, level, command);
108 if (!W_ERROR_IS_OK(werror)) {
109 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
119 PyObject *spoolss_getjob(PyObject *self, PyObject *args, PyObject *kw)
121 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
124 uint32 level = 1, jobid, needed;
125 static char *kwlist[] = {"jobid", "level", NULL};
128 /* Parse parameters */
130 if (!PyArg_ParseTupleAndKeywords(args, kw, "i|i", kwlist, &jobid,
134 /* Call rpc function */
136 werror = cli_spoolss_getjob(hnd->cli, hnd->mem_ctx, 0, &needed,
137 &hnd->pol, jobid, level, &ctr);
139 if (W_ERROR_V(werror) == ERRinsufficientbuffer)
140 werror = cli_spoolss_getjob(
141 hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
144 if (!W_ERROR_IS_OK(werror)) {
145 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
151 py_from_JOB_INFO_1(&result, ctr.job.job_info_1);
154 py_from_JOB_INFO_2(&result, ctr.job.job_info_2);
161 /* Start page printer. This notifies the spooler that a page is about to be
162 printed on the specified printer. */
164 PyObject *spoolss_startpageprinter(PyObject *self, PyObject *args, PyObject *kw)
166 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
168 static char *kwlist[] = { NULL };
170 /* Parse parameters */
172 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
175 /* Call rpc function */
177 werror = cli_spoolss_startpageprinter(
178 hnd->cli, hnd->mem_ctx, &hnd->pol);
180 if (!W_ERROR_IS_OK(werror)) {
181 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
189 /* End page printer. This notifies the spooler that a page has finished
190 being printed on the specified printer. */
192 PyObject *spoolss_endpageprinter(PyObject *self, PyObject *args, PyObject *kw)
194 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
196 static char *kwlist[] = { NULL };
198 /* Parse parameters */
200 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
203 /* Call rpc function */
205 werror = cli_spoolss_endpageprinter(
206 hnd->cli, hnd->mem_ctx, &hnd->pol);
208 if (!W_ERROR_IS_OK(werror)) {
209 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
217 /* Start doc printer. This notifies the spooler that a document is about to be
218 printed on the specified printer. */
220 PyObject *spoolss_startdocprinter(PyObject *self, PyObject *args, PyObject *kw)
222 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
224 static char *kwlist[] = { "document_info", NULL };
225 PyObject *doc_info, *obj;
227 char *document_name = NULL, *output_file = NULL, *data_type = NULL;
229 /* Parse parameters */
231 if (!PyArg_ParseTupleAndKeywords(args, kw, "O!", kwlist,
232 &PyDict_Type, &doc_info))
235 /* Check document_info parameter */
237 if ((obj = PyDict_GetItemString(doc_info, "level"))) {
239 if (!PyInt_Check(obj)) {
240 PyErr_SetString(spoolss_error,
241 "level not an integer");
245 level = PyInt_AsLong(obj);
247 /* Only level 1 supported by Samba! */
250 PyErr_SetString(spoolss_error,
251 "unsupported info level");
256 PyErr_SetString(spoolss_error, "no info level present");
260 if ((obj = PyDict_GetItemString(doc_info, "document_name"))) {
262 if (!PyString_Check(obj) && obj != Py_None) {
263 PyErr_SetString(spoolss_error,
264 "document_name not a string");
268 if (PyString_Check(obj))
269 document_name = PyString_AsString(obj);
272 PyErr_SetString(spoolss_error, "no document_name present");
276 if ((obj = PyDict_GetItemString(doc_info, "output_file"))) {
278 if (!PyString_Check(obj) && obj != Py_None) {
279 PyErr_SetString(spoolss_error,
280 "output_file not a string");
284 if (PyString_Check(obj))
285 output_file = PyString_AsString(obj);
288 PyErr_SetString(spoolss_error, "no output_file present");
292 if ((obj = PyDict_GetItemString(doc_info, "data_type"))) {
294 if (!PyString_Check(obj) && obj != Py_None) {
295 PyErr_SetString(spoolss_error,
296 "data_type not a string");
300 if (PyString_Check(obj))
301 data_type = PyString_AsString(obj);
304 PyErr_SetString(spoolss_error, "no data_type present");
308 /* Call rpc function */
310 werror = cli_spoolss_startdocprinter(
311 hnd->cli, hnd->mem_ctx, &hnd->pol, document_name,
312 output_file, data_type, &jobid);
314 if (!W_ERROR_IS_OK(werror)) {
315 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
319 /* The return value is zero for an error (where does the status
320 code come from now??) and the return value is the jobid
321 allocated for the new job. */
323 return Py_BuildValue("i", jobid);
326 /* End doc printer. This notifies the spooler that a document has finished
327 being printed on the specified printer. */
329 PyObject *spoolss_enddocprinter(PyObject *self, PyObject *args, PyObject *kw)
331 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
333 static char *kwlist[] = { NULL };
335 /* Parse parameters */
337 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
340 /* Call rpc function */
342 werror = cli_spoolss_enddocprinter(hnd->cli, hnd->mem_ctx, &hnd->pol);
344 if (!W_ERROR_IS_OK(werror)) {
345 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));