2 Unix SMB/CIFS implementation.
3 printing command routines
4 Copyright (C) Andrew Tridgell 1992-2000
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/>.
23 extern struct current_user current_user;
24 extern userdom_struct current_user_info;
26 /****************************************************************************
27 run a given print command
28 a null terminated list of value/substitute pairs is provided
29 for local substitution strings
30 ****************************************************************************/
31 static int print_run_command(int snum, const char* printername, BOOL do_sub,
32 const char *command, int *outfd, ...)
40 /* check for a valid system printername and valid command to run */
42 if ( !printername || !*printername )
45 if (!command || !*command)
48 pstrcpy(syscmd, command);
50 while ((arg = va_arg(ap, char *))) {
51 char *value = va_arg(ap,char *);
52 pstring_sub(syscmd, arg, value);
56 pstring_sub( syscmd, "%p", printername );
58 if ( do_sub && snum != -1 )
59 standard_sub_advanced(lp_servicename(snum),
60 current_user_info.unix_name, "",
62 get_current_username(),
63 current_user_info.domain,
64 syscmd, sizeof(syscmd));
66 ret = smbrun_no_sanitize(syscmd,outfd);
68 DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
74 /****************************************************************************
76 ****************************************************************************/
77 static int generic_job_delete( const char *sharename, const char *lprm_command, struct printjob *pjob)
81 /* need to delete the spooled entry */
82 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
83 return print_run_command( -1, sharename, False, lprm_command, NULL,
85 "%T", http_timestring(pjob->starttime),
89 /****************************************************************************
91 ****************************************************************************/
92 static int generic_job_pause(int snum, struct printjob *pjob)
96 /* need to pause the spooled entry */
97 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
98 return print_run_command(snum, PRINTERNAME(snum), True,
99 lp_lppausecommand(snum), NULL,
104 /****************************************************************************
106 ****************************************************************************/
107 static int generic_job_resume(int snum, struct printjob *pjob)
111 /* need to pause the spooled entry */
112 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
113 return print_run_command(snum, PRINTERNAME(snum), True,
114 lp_lpresumecommand(snum), NULL,
119 /****************************************************************************
120 Submit a file for printing - called from print_job_end()
121 ****************************************************************************/
123 static int generic_job_submit(int snum, struct printjob *pjob)
126 pstring current_directory;
127 pstring print_directory;
130 fstring job_page_count, job_size;
132 /* we print from the directory path to give the best chance of
133 parsing the lpq output */
134 wd = sys_getwd(current_directory);
138 pstrcpy(print_directory, pjob->filename);
139 p = strrchr_m(print_directory,'/');
144 if (chdir(print_directory) != 0)
147 pstrcpy(jobname, pjob->jobname);
148 pstring_sub(jobname, "'", "_");
149 slprintf(job_page_count, sizeof(job_page_count)-1, "%d", pjob->page_count);
150 slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size);
152 /* send it to the system spooler */
153 ret = print_run_command(snum, PRINTERNAME(snum), True,
154 lp_printcommand(snum), NULL,
159 "%c", job_page_count,
168 /****************************************************************************
169 get the current list of queued jobs
170 ****************************************************************************/
171 static int generic_queue_get(const char *printer_name,
172 enum printing_types printing_type,
174 print_queue_struct **q,
175 print_status_struct *status)
179 int numlines, i, qcount;
180 print_queue_struct *queue = NULL;
182 /* never do substitution when running the 'lpq command' since we can't
183 get it rigt when using the background update daemon. Make the caller
184 do it before passing off the command string to us here. */
186 print_run_command(-1, printer_name, False, lpq_command, &fd, NULL);
189 DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
195 qlines = fd_lines_load(fd, &numlines,0);
198 /* turn the lpq output into a series of job structures */
200 ZERO_STRUCTP(status);
201 if (numlines && qlines) {
202 queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
204 file_lines_free(qlines);
208 memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
210 for (i=0; i<numlines; i++) {
212 if (parse_lpq_entry(printing_type,qlines[i],
213 &queue[qcount],status,qcount==0)) {
219 file_lines_free(qlines);
224 /****************************************************************************
226 ****************************************************************************/
227 static int generic_queue_pause(int snum)
229 return print_run_command(snum, PRINTERNAME(snum), True, lp_queuepausecommand(snum), NULL, NULL);
232 /****************************************************************************
234 ****************************************************************************/
235 static int generic_queue_resume(int snum)
237 return print_run_command(snum, PRINTERNAME(snum), True, lp_queueresumecommand(snum), NULL, NULL);
240 /****************************************************************************
241 * Generic printing interface definitions...
242 ***************************************************************************/
244 struct printif generic_printif =
249 generic_queue_resume,