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_hnd_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
)) {
56 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
60 result
= PyList_New(num_jobs
);
64 for (i
= 0; i
< num_jobs
; i
++) {
67 py_from_JOB_INFO_1(&value
, &ctr
.job
.job_info_1
[i
]);
69 PyList_SetItem(result
, i
, value
);
74 for(i
= 0; i
< num_jobs
; i
++) {
77 py_from_JOB_INFO_2(&value
, &ctr
.job
.job_info_2
[i
]);
79 PyList_SetItem(result
, i
, value
);
92 PyObject
*spoolss_hnd_setjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
94 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
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
))
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
));
121 PyObject
*spoolss_hnd_getjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
123 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
126 uint32 level
= 1, jobid
, needed
;
127 static char *kwlist
[] = {"jobid", "level", NULL
};
130 /* Parse parameters */
132 if (!PyArg_ParseTupleAndKeywords(
133 args
, kw
, "i|i", kwlist
, &jobid
, &level
))
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
,
146 if (!W_ERROR_IS_OK(werror
)) {
147 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
153 py_from_JOB_INFO_1(&result
, ctr
.job
.job_info_1
);
156 py_from_JOB_INFO_2(&result
, ctr
.job
.job_info_2
);
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
;
170 static char *kwlist
[] = { NULL
};
172 /* Parse parameters */
174 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
198 static char *kwlist
[] = { NULL
};
200 /* Parse parameters */
202 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
226 static char *kwlist
[] = { "document_info", NULL
};
227 PyObject
*info
, *obj
;
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
))
237 /* Check document_info parameter */
239 if (!get_level_value(info
, &level
)) {
240 PyErr_SetString(spoolss_error
, "invalid info level");
245 PyErr_SetString(spoolss_error
, "unsupported info level");
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");
257 if (PyString_Check(obj
))
258 document_name
= PyString_AsString(obj
);
261 PyErr_SetString(spoolss_error
, "no document_name present");
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");
273 if (PyString_Check(obj
))
274 output_file
= PyString_AsString(obj
);
277 PyErr_SetString(spoolss_error
, "no output_file present");
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");
289 if (PyString_Check(obj
))
290 data_type
= PyString_AsString(obj
);
293 PyErr_SetString(spoolss_error
, "no data_type present");
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
));
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
;
322 static char *kwlist
[] = { NULL
};
324 /* Parse parameters */
326 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
348 static char *kwlist
[] = { "data", NULL
};
352 /* Parse parameters */
354 if (!PyArg_ParseTupleAndKeywords(
355 args
, kw
, "O!", kwlist
, &PyString_Type
, &data
))
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
));
373 PyObject
*spoolss_hnd_addjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
375 PyErr_SetString(spoolss_error
, "Not implemented");