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
;
32 static char *kwlist
[] = {"level", NULL
};
35 /* Parse parameters */
37 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "|i", kwlist
, &level
))
40 /* Call rpc function */
42 werror
= rpccli_spoolss_enumjobs(
43 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, level
, 0, 1000,
50 if (!W_ERROR_IS_OK(werror
)) {
51 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
55 result
= PyList_New(num_jobs
);
59 for (i
= 0; i
< num_jobs
; i
++) {
62 py_from_JOB_INFO_1(&value
, &ctr
.job
.job_info_1
[i
]);
64 PyList_SetItem(result
, i
, value
);
69 for(i
= 0; i
< num_jobs
; i
++) {
72 py_from_JOB_INFO_2(&value
, &ctr
.job
.job_info_2
[i
]);
74 PyList_SetItem(result
, i
, value
);
87 PyObject
*spoolss_hnd_setjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
89 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
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
))
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
));
116 PyObject
*spoolss_hnd_getjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
118 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
121 uint32 level
= 1, jobid
;
122 static char *kwlist
[] = {"jobid", "level", NULL
};
125 /* Parse parameters */
127 if (!PyArg_ParseTupleAndKeywords(
128 args
, kw
, "i|i", kwlist
, &jobid
, &level
))
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
));
143 py_from_JOB_INFO_1(&result
, &ctr
.job
.job_info_1
[0]);
146 py_from_JOB_INFO_2(&result
, &ctr
.job
.job_info_2
[0]);
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
;
160 static char *kwlist
[] = { NULL
};
162 /* Parse parameters */
164 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
188 static char *kwlist
[] = { NULL
};
190 /* Parse parameters */
192 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
216 static char *kwlist
[] = { "document_info", NULL
};
217 PyObject
*info
, *obj
;
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
))
227 /* Check document_info parameter */
229 if (!get_level_value(info
, &level
)) {
230 PyErr_SetString(spoolss_error
, "invalid info level");
235 PyErr_SetString(spoolss_error
, "unsupported info level");
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");
247 if (PyString_Check(obj
))
248 document_name
= PyString_AsString(obj
);
251 PyErr_SetString(spoolss_error
, "no document_name present");
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");
263 if (PyString_Check(obj
))
264 output_file
= PyString_AsString(obj
);
267 PyErr_SetString(spoolss_error
, "no output_file present");
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");
279 if (PyString_Check(obj
))
280 data_type
= PyString_AsString(obj
);
283 PyErr_SetString(spoolss_error
, "no data_type present");
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
));
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
;
312 static char *kwlist
[] = { NULL
};
314 /* Parse parameters */
316 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "", kwlist
))
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
));
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
;
339 static char *kwlist
[] = { "data", NULL
};
343 /* Parse parameters */
345 if (!PyArg_ParseTupleAndKeywords(
346 args
, kw
, "O!", kwlist
, &PyString_Type
, &data
))
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
));
364 PyObject
*spoolss_hnd_addjob(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
366 PyErr_SetString(spoolss_error
, "Not implemented");