• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/samba-3.0.25b/source/python/
1/*
2   Python wrappers for DCERPC/SMB client routines.
3
4   Copyright (C) Tim Potter, 2002
5
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.
10
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.
15
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.
19*/
20
21#include "python/py_spoolss.h"
22
23/* Enumerate jobs */
24
25PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw)
26{
27	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
28	WERROR werror;
29	PyObject *result;
30	int level = 1;
31	uint32 i, num_jobs;
32	static char *kwlist[] = {"level", NULL};
33	JOB_INFO_CTR ctr;
34
35	/* Parse parameters */
36
37	if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level))
38		return NULL;
39
40	/* Call rpc function */
41
42	werror = rpccli_spoolss_enumjobs(
43		hnd->cli, hnd->mem_ctx, &hnd->pol, level, 0, 1000,
44		&num_jobs, &ctr);
45
46	/* Return value */
47
48	result = Py_None;
49
50	if (!W_ERROR_IS_OK(werror)) {
51		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
52		goto done;
53	}
54
55	result = PyList_New(num_jobs);
56
57	switch (level) {
58	case 1:
59		for (i = 0; i < num_jobs; i++) {
60			PyObject *value;
61
62			py_from_JOB_INFO_1(&value, &ctr.job.job_info_1[i]);
63
64			PyList_SetItem(result, i, value);
65		}
66
67		break;
68	case 2:
69		for(i = 0; i < num_jobs; i++) {
70			PyObject *value;
71
72			py_from_JOB_INFO_2(&value, &ctr.job.job_info_2[i]);
73
74			PyList_SetItem(result, i, value);
75		}
76
77		break;
78	}
79
80 done:
81	Py_INCREF(result);
82	return result;
83}
84
85/* Set job command */
86
87PyObject *spoolss_hnd_setjob(PyObject *self, PyObject *args, PyObject *kw)
88{
89	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
90	WERROR werror;
91	uint32 level = 0, command, jobid;
92	static char *kwlist[] = {"jobid", "command", "level", NULL};
93
94	/* Parse parameters */
95
96	if (!PyArg_ParseTupleAndKeywords(
97		    args, kw, "ii|i", kwlist, &jobid, &command, &level))
98		return NULL;
99
100	/* Call rpc function */
101
102	werror = rpccli_spoolss_setjob(
103		hnd->cli, hnd->mem_ctx, &hnd->pol, jobid, level, command);
104
105	if (!W_ERROR_IS_OK(werror)) {
106		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
107		return NULL;
108	}
109
110	Py_INCREF(Py_None);
111	return Py_None;
112}
113
114/* Get job */
115
116PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw)
117{
118	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
119	WERROR werror;
120	PyObject *result;
121	uint32 level = 1, jobid;
122	static char *kwlist[] = {"jobid", "level", NULL};
123	JOB_INFO_CTR ctr;
124
125	/* Parse parameters */
126
127	if (!PyArg_ParseTupleAndKeywords(
128		    args, kw, "i|i", kwlist, &jobid, &level))
129		return NULL;
130
131	/* Call rpc function */
132
133	werror = rpccli_spoolss_getjob(
134		hnd->cli, hnd->mem_ctx, &hnd->pol, jobid, level, &ctr);
135
136	if (!W_ERROR_IS_OK(werror)) {
137		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
138		return NULL;
139	}
140
141	switch(level) {
142	case 1:
143		py_from_JOB_INFO_1(&result, &ctr.job.job_info_1[0]);
144		break;
145	case 2:
146		py_from_JOB_INFO_2(&result, &ctr.job.job_info_2[0]);
147		break;
148	}
149
150	return result;
151}
152
153/* Start page printer.  This notifies the spooler that a page is about to be
154   printed on the specified printer. */
155
156PyObject *spoolss_hnd_startpageprinter(PyObject *self, PyObject *args, PyObject *kw)
157{
158	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
159	WERROR werror;
160	static char *kwlist[] = { NULL };
161
162	/* Parse parameters */
163
164	if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
165		return NULL;
166
167	/* Call rpc function */
168
169	werror = rpccli_spoolss_startpageprinter(
170		hnd->cli, hnd->mem_ctx, &hnd->pol);
171
172	if (!W_ERROR_IS_OK(werror)) {
173		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
174		return NULL;
175	}
176
177	Py_INCREF(Py_None);
178	return Py_None;
179}
180
181/* End page printer.  This notifies the spooler that a page has finished
182   being printed on the specified printer. */
183
184PyObject *spoolss_hnd_endpageprinter(PyObject *self, PyObject *args, PyObject *kw)
185{
186	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
187	WERROR werror;
188	static char *kwlist[] = { NULL };
189
190	/* Parse parameters */
191
192	if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
193		return NULL;
194
195	/* Call rpc function */
196
197	werror = rpccli_spoolss_endpageprinter(
198		hnd->cli, hnd->mem_ctx, &hnd->pol);
199
200	if (!W_ERROR_IS_OK(werror)) {
201		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
202		return NULL;
203	}
204
205	Py_INCREF(Py_None);
206	return Py_None;
207}
208
209/* Start doc printer.  This notifies the spooler that a document is about to be
210   printed on the specified printer. */
211
212PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject *kw)
213{
214	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
215	WERROR werror;
216	static char *kwlist[] = { "document_info", NULL };
217	PyObject *info, *obj;
218	uint32 level, jobid;
219	char *document_name = NULL, *output_file = NULL, *data_type = NULL;
220
221	/* Parse parameters */
222
223	if (!PyArg_ParseTupleAndKeywords(
224		    args, kw, "O!", kwlist, &PyDict_Type, &info))
225		return NULL;
226
227	/* Check document_info parameter */
228
229	if (!get_level_value(info, &level)) {
230		PyErr_SetString(spoolss_error, "invalid info level");
231		return NULL;
232	}
233
234	if (level != 1) {
235		PyErr_SetString(spoolss_error, "unsupported info level");
236		return NULL;
237	}
238
239	if ((obj = PyDict_GetItemString(info, "document_name"))) {
240
241		if (!PyString_Check(obj) && obj != Py_None) {
242			PyErr_SetString(spoolss_error,
243					"document_name not a string");
244			return NULL;
245		}
246
247		if (PyString_Check(obj))
248			document_name = PyString_AsString(obj);
249
250	} else {
251		PyErr_SetString(spoolss_error, "no document_name present");
252		return NULL;
253	}
254
255	if ((obj = PyDict_GetItemString(info, "output_file"))) {
256
257		if (!PyString_Check(obj) && obj != Py_None) {
258			PyErr_SetString(spoolss_error,
259					"output_file not a string");
260			return NULL;
261		}
262
263		if (PyString_Check(obj))
264			output_file = PyString_AsString(obj);
265
266	} else {
267		PyErr_SetString(spoolss_error, "no output_file present");
268		return NULL;
269	}
270
271	if ((obj = PyDict_GetItemString(info, "data_type"))) {
272
273		if (!PyString_Check(obj) && obj != Py_None) {
274			PyErr_SetString(spoolss_error,
275					"data_type not a string");
276			return NULL;
277		}
278
279		if (PyString_Check(obj))
280			data_type = PyString_AsString(obj);
281
282	} else {
283		PyErr_SetString(spoolss_error, "no data_type present");
284		return NULL;
285	}
286
287	/* Call rpc function */
288
289	werror = rpccli_spoolss_startdocprinter(
290		hnd->cli, hnd->mem_ctx, &hnd->pol, document_name,
291		output_file, data_type, &jobid);
292
293	if (!W_ERROR_IS_OK(werror)) {
294		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
295		return NULL;
296	}
297
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. */
301
302	return Py_BuildValue("i", jobid);
303}
304
305/* End doc printer.  This notifies the spooler that a document has finished
306   being printed on the specified printer. */
307
308PyObject *spoolss_hnd_enddocprinter(PyObject *self, PyObject *args, PyObject *kw)
309{
310	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
311	WERROR werror;
312	static char *kwlist[] = { NULL };
313
314	/* Parse parameters */
315
316	if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
317		return NULL;
318
319	/* Call rpc function */
320
321	werror = rpccli_spoolss_enddocprinter(
322		hnd->cli, hnd->mem_ctx, &hnd->pol);
323
324	if (!W_ERROR_IS_OK(werror)) {
325		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
326		return NULL;
327	}
328
329	Py_INCREF(Py_None);
330	return Py_None;
331}
332
333/* Write data to a printer */
334
335PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw)
336{
337	spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
338	WERROR werror;
339	static char *kwlist[] = { "data", NULL };
340	PyObject *data;
341	uint32 num_written;
342
343	/* Parse parameters */
344
345	if (!PyArg_ParseTupleAndKeywords(
346		    args, kw, "O!", kwlist, &PyString_Type, &data))
347		return NULL;
348
349	/* Call rpc function */
350
351	werror = rpccli_spoolss_writeprinter(
352		hnd->cli, hnd->mem_ctx, &hnd->pol, PyString_Size(data),
353		PyString_AsString(data), &num_written);
354
355	if (!W_ERROR_IS_OK(werror)) {
356		PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
357		return NULL;
358	}
359
360	Py_INCREF(Py_None);
361	return Py_None;
362}
363
364PyObject *spoolss_hnd_addjob(PyObject *self, PyObject *args, PyObject *kw)
365{
366	PyErr_SetString(spoolss_error, "Not implemented");
367	return NULL;
368}
369