If signing starts successfully, don't just turn it off automatically if
[jra/samba/.git] / source3 / printing / print_generic.c
index af73088d1f652d39a95886155bd49d042ec17d55..9e0ea85bb9adcb6b0ad46e1ccd844649a9943fe0 100644 (file)
@@ -1,6 +1,5 @@
 /* 
-   Unix SMB/Netbios implementation.
-   Version 3.0
+   Unix SMB/CIFS implementation.
    printing command routines
    Copyright (C) Andrew Tridgell 1992-2000
    
@@ -19,6 +18,7 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include "includes.h"
 #include "printing.h"
 
 
@@ -47,38 +47,19 @@ struct printif      generic_printif =
                  generic_job_submit,
                };
 
-extern int DEBUGLEVEL;
-
 /****************************************************************************
 run a given print command 
 a null terminated list of value/substitute pairs is provided
 for local substitution strings
 ****************************************************************************/
-
-#ifdef HAVE_STDARG_H
-static int print_run_command(int snum,char *command, char *outfile, ...)
-{
-#else /* HAVE_STDARG_H */
-static int print_run_command(va_alist)
-va_dcl
+static int print_run_command(int snum,char *command, int *outfd, ...)
 {
-       int snum;
-       char *command, *outfile;
-#endif /* HAVE_STDARG_H */
 
        pstring syscmd;
-       char *p, *arg;
+       char *arg;
        int ret;
        va_list ap;
-
-#ifdef HAVE_STDARG_H
-       va_start(ap, outfile);
-#else /* HAVE_STDARG_H */
-       va_start(ap);
-       snum = va_arg(ap,int);
-       command = va_arg(ap,char *);
-       outfile = va_arg(ap,char *);
-#endif /* HAVE_STDARG_H */
+       va_start(ap, outfd);
 
        if (!command || !*command) return -1;
 
@@ -95,14 +76,10 @@ va_dcl
        }
        va_end(ap);
   
-       p = PRINTERNAME(snum);
-  
-       pstring_sub(syscmd, "%p", p);
-       standard_sub_snum(snum,syscmd);
+       pstring_sub(syscmd, "%p", PRINTERNAME(snum));
+       standard_sub_snum(snum,syscmd,sizeof(syscmd));
 
-       /* Convert script args to unix-codepage */
-       dos_to_unix(syscmd, True);
-       ret = smbrun(syscmd,outfile,False);
+       ret = smbrun(syscmd,outfd);
 
        DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
 
@@ -168,6 +145,7 @@ static int generic_job_submit(int snum, struct printjob *pjob)
        pstring print_directory;
        char *wd, *p;
        pstring jobname;
+       fstring job_page_count, job_size;
 
        /* we print from the directory path to give the best chance of
            parsing the lpq output */
@@ -176,7 +154,7 @@ static int generic_job_submit(int snum, struct printjob *pjob)
                return 0;
 
        pstrcpy(print_directory, pjob->filename);
-       p = strrchr(print_directory,'/');
+       p = strrchr_m(print_directory,'/');
        if (!p)
                return 0;
        *p++ = 0;
@@ -186,14 +164,18 @@ static int generic_job_submit(int snum, struct printjob *pjob)
 
        pstrcpy(jobname, pjob->jobname);
        pstring_sub(jobname, "'", "_");
+       slprintf(job_page_count, sizeof(job_page_count)-1, "%d", pjob->page_count);
+       slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size);
 
        /* send it to the system spooler */
        ret = print_run_command(snum, 
-                         lp_printcommand(snum), NULL,
-                         "%s", p,
-                         "%J", jobname,
-                         "%f", p,
-                         NULL);
+                       lp_printcommand(snum), NULL,
+                       "%s", p,
+                       "%J", jobname,
+                       "%f", p,
+                       "%z", job_size,
+                       "%c", job_page_count,
+                       NULL);
 
        chdir(wd);
 
@@ -206,26 +188,25 @@ get the current list of queued jobs
 ****************************************************************************/
 static int generic_queue_get(int snum, print_queue_struct **q, print_status_struct *status)
 {
-       char *path = lp_pathname(snum);
-       char *cmd = lp_lpqcommand(snum);
        char **qlines;
-       pstring tmp_file;
+       int fd;
        int numlines, i, qcount;
-       print_queue_struct *queue;
+       print_queue_struct *queue = NULL;
        fstring printer_name;
               
-       /* Convert printer name (i.e. share name) to unix-codepage */
        fstrcpy(printer_name, lp_servicename(snum));
-       dos_to_unix(printer_name, True);
        
-       slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smblpq.%d", path, sys_getpid());
-
-       unlink(tmp_file);
-       print_run_command(snum, cmd, tmp_file, NULL);
+       print_run_command(snum, lp_lpqcommand(snum), &fd, NULL);
 
+       if (fd == -1) {
+               DEBUG(5,("generic_queue_get: Can't read print queue status for printer %s\n",
+                       printer_name ));
+               return 0;
+       }
+       
        numlines = 0;
-       qlines = file_lines_load(tmp_file, &numlines, True);
-       unlink(tmp_file);
+       qlines = fd_lines_load(fd, &numlines);
+       close(fd);
 
        /* turn the lpq output into a series of job structures */
        qcount = 0;
@@ -234,6 +215,7 @@ static int generic_queue_get(int snum, print_queue_struct **q, print_status_stru
                queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(numlines+1));
 
        if (queue) {
+               memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
                for (i=0; i<numlines; i++) {
                        /* parse the line */
                        if (parse_lpq_entry(snum,qlines[i],
@@ -253,8 +235,7 @@ static int generic_queue_get(int snum, print_queue_struct **q, print_status_stru
 ****************************************************************************/
 static int generic_queue_pause(int snum)
 {
-       return print_run_command(snum, lp_queuepausecommand(snum), NULL, 
-                                NULL);
+       return print_run_command(snum, lp_queuepausecommand(snum), NULL, NULL);
 }
 
 /****************************************************************************
@@ -262,6 +243,5 @@ static int generic_queue_pause(int snum)
 ****************************************************************************/
 static int generic_queue_resume(int snum)
 {
-       return print_run_command(snum, lp_queueresumecommand(snum), NULL, 
-                                NULL);
+       return print_run_command(snum, lp_queueresumecommand(snum), NULL, NULL);
 }