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"
24 PyObject
*spoolss_hnd_enumjobs(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
26 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
31 static char *kwlist
[] = {"level", NULL
};
34 /* Parse parameters */
36 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "|i", kwlist
, &level
))
39 /* Call rpc function */
41 werror
= rpccli_spoolss_enumjobs(
42 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, level
, 0, 1000,
49 if (!W_ERROR_IS_OK(werror
)) {
50 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
54 result
= PyList_New(num_jobs
);
58 for (i
= 0; i
< num_jobs
; i
++) {
61 py_from_JOB_INFO_1(&value
, &ctr
.job
.job_info_1
[i
]);
63 PyList_SetItem(result
, i
, value
);
68 for(i
= 0; i
< num_jobs
; i
++) {
71 py_from_JOB_INFO_2(&value
, &ctr
.job
.job_info_2
[i
]);
73 PyList_SetItem(result
, i
, value
);
86 PyObject
*spoolss_hnd_setjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
88 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
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
))
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
));
115 PyObject
*spoolss_hnd_getjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
117 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
120 uint32 level
= 1, jobid
;
121 static char *kwlist
[] = {"jobid", "level", NULL
};
124 /* Parse parameters */
126 if (!PyArg_ParseTupleAndKeywords(
127 args
, kw
, "i|i", kwlist
, &jobid
, &level
))
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
));
142 py_from_JOB_INFO_1(&result
, &ctr
.job
.job_info_1
[0]);
145 py_from_JOB_INFO_2(&result
, &ctr
.job
.job_info_2
[0]);
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
;
159 static char *kwlist
[] = { NULL
};
161 /* Parse parameters */
163 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
187 static char *kwlist
[] = { NULL
};
189 /* Parse parameters */
191 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
215 static char *kwlist
[] = { "document_info", NULL
};
216 PyObject
*info
, *obj
;
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
))
226 /* Check document_info parameter */
228 if (!get_level_value(info
, &level
)) {
229 PyErr_SetString(spoolss_error
, "invalid info level");
234 PyErr_SetString(spoolss_error
, "unsupported info level");
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");
246 if (PyString_Check(obj
))
247 document_name
= PyString_AsString(obj
);
250 PyErr_SetString(spoolss_error
, "no document_name present");
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");
262 if (PyString_Check(obj
))
263 output_file
= PyString_AsString(obj
);
266 PyErr_SetString(spoolss_error
, "no output_file present");
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");
278 if (PyString_Check(obj
))
279 data_type
= PyString_AsString(obj
);
282 PyErr_SetString(spoolss_error
, "no data_type present");
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
));
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
;
311 static char *kwlist
[] = { NULL
};
313 /* Parse parameters */
315 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
338 static char *kwlist
[] = { "data", NULL
};
342 /* Parse parameters */
344 if (!PyArg_ParseTupleAndKeywords(
345 args
, kw
, "O!", kwlist
, &PyString_Type
, &data
))
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
));
363 PyObject
*spoolss_hnd_addjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
365 PyErr_SetString(spoolss_error
, "Not implemented");