2 Unix SMB/Netbios implementation.
4 printing command routines
5 Copyright (C) Andrew Tridgell 1992-2000
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Generic printing interface definitions...
29 static int generic_job_delete(int snum, struct printjob *pjob);
30 static int generic_job_pause(int snum, struct printjob *pjob);
31 static int generic_job_resume(int snum, struct printjob *pjob);
32 static int generic_job_submit(int snum, struct printjob *pjob);
33 static int generic_queue_get(int snum, print_queue_struct **q,
34 print_status_struct *status);
35 static int generic_queue_pause(int snum);
36 static int generic_queue_resume(int snum);
39 struct printif generic_printif =
50 extern int DEBUGLEVEL;
52 /****************************************************************************
53 run a given print command
54 a null terminated list of value/substitute pairs is provided
55 for local substitution strings
56 ****************************************************************************/
59 static int print_run_command(int snum,char *command, char *outfile, ...)
61 #else /* HAVE_STDARG_H */
62 static int print_run_command(va_alist)
66 char *command, *outfile;
67 #endif /* HAVE_STDARG_H */
75 va_start(ap, outfile);
76 #else /* HAVE_STDARG_H */
78 snum = va_arg(ap,int);
79 command = va_arg(ap,char *);
80 outfile = va_arg(ap,char *);
81 #endif /* HAVE_STDARG_H */
83 if (!command || !*command) return -1;
85 if (!VALID_SNUM(snum)) {
86 DEBUG(0,("Invalid snum %d for command %s\n", snum, command));
90 pstrcpy(syscmd, command);
92 while ((arg = va_arg(ap, char *))) {
93 char *value = va_arg(ap,char *);
94 pstring_sub(syscmd, arg, value);
98 p = PRINTERNAME(snum);
100 pstring_sub(syscmd, "%p", p);
101 standard_sub_snum(snum,syscmd);
103 /* Convert script args to unix-codepage */
104 dos_to_unix(syscmd, True);
105 ret = smbrun(syscmd,outfile,False);
107 DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
113 /****************************************************************************
115 ****************************************************************************/
116 static int generic_job_delete(int snum, struct printjob *pjob)
120 /* need to delete the spooled entry */
121 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
122 return print_run_command(
124 lp_lprmcommand(snum), NULL,
126 "%T", http_timestring(pjob->starttime),
130 /****************************************************************************
132 ****************************************************************************/
133 static int generic_job_pause(int snum, struct printjob *pjob)
137 /* need to pause the spooled entry */
138 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
139 return print_run_command(snum,
140 lp_lppausecommand(snum), NULL,
145 /****************************************************************************
147 ****************************************************************************/
148 static int generic_job_resume(int snum, struct printjob *pjob)
152 /* need to pause the spooled entry */
153 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
154 return print_run_command(snum,
155 lp_lpresumecommand(snum), NULL,
160 /****************************************************************************
161 Submit a file for printing - called from print_job_end()
162 ****************************************************************************/
164 static int generic_job_submit(int snum, struct printjob *pjob)
167 pstring current_directory;
168 pstring print_directory;
172 /* we print from the directory path to give the best chance of
173 parsing the lpq output */
174 wd = sys_getwd(current_directory);
178 pstrcpy(print_directory, pjob->filename);
179 p = strrchr(print_directory,'/');
184 if (chdir(print_directory) != 0)
187 pstrcpy(jobname, pjob->jobname);
188 pstring_sub(jobname, "'", "_");
190 /* send it to the system spooler */
191 ret = print_run_command(snum,
192 lp_printcommand(snum), NULL,
204 /****************************************************************************
205 get the current list of queued jobs
206 ****************************************************************************/
207 static int generic_queue_get(int snum, print_queue_struct **q, print_status_struct *status)
209 char *path = lp_pathname(snum);
210 char *cmd = lp_lpqcommand(snum);
213 int numlines, i, qcount;
214 print_queue_struct *queue;
215 fstring printer_name;
217 /* Convert printer name (i.e. share name) to unix-codepage */
218 fstrcpy(printer_name, lp_servicename(snum));
219 dos_to_unix(printer_name, True);
221 slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smblpq.%d", path, sys_getpid());
224 print_run_command(snum, cmd, tmp_file, NULL);
227 qlines = file_lines_load(tmp_file, &numlines, True);
230 /* turn the lpq output into a series of job structures */
232 ZERO_STRUCTP(status);
234 queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(numlines+1));
237 for (i=0; i<numlines; i++) {
239 if (parse_lpq_entry(snum,qlines[i],
240 &queue[qcount],status,qcount==0)) {
245 file_lines_free(qlines);
251 /****************************************************************************
253 ****************************************************************************/
254 static int generic_queue_pause(int snum)
256 return print_run_command(snum, lp_queuepausecommand(snum), NULL,
260 /****************************************************************************
262 ****************************************************************************/
263 static int generic_queue_resume(int snum)
265 return print_run_command(snum, lp_queueresumecommand(snum), NULL,