Merge in JohnR's page count fixes.
authorJeremy Allison <jra@samba.org>
Tue, 19 Mar 2002 02:35:12 +0000 (02:35 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 19 Mar 2002 02:35:12 +0000 (02:35 +0000)
Jeremy.

source/include/printing.h
source/include/smb.h
source/printing/printing.c
source/rpc_server/srv_spoolss_nt.c

index 0a733b580a12113c709a11bbf3ac1f54db2900eb..9a0775186b3987d50634a77714b8c1cb74d5c2ae 100644 (file)
@@ -36,6 +36,7 @@ struct printjob {
        time_t starttime; /* when the job started spooling */
        int status; /* the status of this job */
        size_t size; /* the size of the job so far */
+       int page_count; /* then number of pages so far */
        BOOL spooled; /* has it been sent to the spooler yet? */
        BOOL smbjob; /* set if the job is a SMB job */
        fstring filename; /* the filename used to spool the file */
index 02645f35d3ebe9087efa5654d100a5b6f2cd1905..34832edc79c3e3e9707ffa9be03c0e14959032d1 100644 (file)
@@ -506,6 +506,7 @@ typedef struct _print_queue_struct
 {
   int job;
   int size;
+  int page_count;
   int status;
   int priority;
   time_t time;
index 97eaaebcc4953ade79af31c96cb3cdc88253be47..7e1f59f59003d4a7aa9e1b4b8de6e8eb6415543e 100644 (file)
@@ -796,12 +796,21 @@ write to a print file
 ****************************************************************************/
 int print_job_write(int jobid, const char *buf, int size)
 {
-       int fd;
+       int return_code;
+       struct printjob *pjob = print_job_find(jobid);
 
-       fd = print_job_fd(jobid);
-       if (fd == -1) return -1;
+       if (!pjob)
+               return -1;
+       /* don't allow another process to get this info - it is meaningless */
+       if (pjob->pid != local_pid)
+               return -1;
 
-       return write(fd, buf, size);
+       return_code = write(pjob->fd, buf, size);
+       if (return_code>0) {
+               pjob->size += size;
+               print_job_store(jobid, pjob);
+       }
+       return return_code;
 }
 
 /****************************************************************************
@@ -1043,6 +1052,23 @@ to open spool file %s.\n", pjob.filename));
        return -1;
 }
 
+/****************************************************************************
+ Update the number of pages spooled to jobid
+****************************************************************************/
+
+void print_job_endpage(int jobid)
+{
+       struct printjob *pjob = print_job_find(jobid);
+       if (!pjob)
+               return;
+       /* don't allow another process to get this info - it is meaningless */
+       if (pjob->pid != local_pid)
+               return;
+
+       pjob->page_count++;
+       print_job_store(jobid, pjob);
+}
+
 /****************************************************************************
  Print a file - called on closing the file. This spools the job.
  If normal close is false then we're tearing down the jobs - treat as an
@@ -1137,6 +1163,7 @@ static int traverse_fn_queue(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *
 
        ts->queue[i].job = jobid;
        ts->queue[i].size = pjob.size;
+       ts->queue[i].page_count = pjob.page_count;
        ts->queue[i].status = pjob.status;
        ts->queue[i].priority = 1;
        ts->queue[i].time = pjob.starttime;
index 850d4281659076f2ef7f953ceaac99b6655bf152..e351f125bf018fae86ade04e0a34dd798a579424 100644 (file)
@@ -2138,6 +2138,32 @@ static void spoolss_notify_job_size(int snum,
        data->notify_data.value[1]=0;
 }
 
+/*******************************************************************
+ * fill a notify_info_data with page info
+ ********************************************************************/
+static void spoolss_notify_total_pages(int snum,
+                               SPOOL_NOTIFY_INFO_DATA *data,
+                               print_queue_struct *queue,
+                               NT_PRINTER_INFO_LEVEL *printer,
+                               TALLOC_CTX *mem_ctx)
+{
+       data->notify_data.value[0]=queue->page_count;
+       data->notify_data.value[1]=0;
+}
+
+/*******************************************************************
+ * fill a notify_info_data with pages printed info.
+ ********************************************************************/
+static void spoolss_notify_pages_printed(int snum,
+                               SPOOL_NOTIFY_INFO_DATA *data,
+                               print_queue_struct *queue,
+                               NT_PRINTER_INFO_LEVEL *printer,
+                               TALLOC_CTX *mem_ctx)
+{
+       data->notify_data.value[0]=0;  /* Add code when back-end tracks this */
+       data->notify_data.value[1]=0;
+}
+
 /*******************************************************************
  Fill a notify_info_data with job position.
  ********************************************************************/
@@ -2258,8 +2284,8 @@ struct s_notify_info_data_table notify_info_data_table[] =
 { JOB_NOTIFY_TYPE,     JOB_NOTIFY_START_TIME,              "JOB_NOTIFY_START_TIME",              ONE_VALUE, spoolss_notify_start_time },
 { JOB_NOTIFY_TYPE,     JOB_NOTIFY_UNTIL_TIME,              "JOB_NOTIFY_UNTIL_TIME",              ONE_VALUE, spoolss_notify_until_time },
 { JOB_NOTIFY_TYPE,     JOB_NOTIFY_TIME,                    "JOB_NOTIFY_TIME",                    ONE_VALUE, spoolss_notify_job_time },
-{ JOB_NOTIFY_TYPE,     JOB_NOTIFY_TOTAL_PAGES,             "JOB_NOTIFY_TOTAL_PAGES",             ONE_VALUE, NULL },
-{ JOB_NOTIFY_TYPE,     JOB_NOTIFY_PAGES_PRINTED,           "JOB_NOTIFY_PAGES_PRINTED",           ONE_VALUE, NULL },
+{ JOB_NOTIFY_TYPE,     JOB_NOTIFY_TOTAL_PAGES,             "JOB_NOTIFY_TOTAL_PAGES",             ONE_VALUE, spoolss_notify_total_pages },
+{ JOB_NOTIFY_TYPE,     JOB_NOTIFY_PAGES_PRINTED,           "JOB_NOTIFY_PAGES_PRINTED",           ONE_VALUE, spoolss_notify_pages_printed },
 { JOB_NOTIFY_TYPE,     JOB_NOTIFY_TOTAL_BYTES,             "JOB_NOTIFY_TOTAL_BYTES",             ONE_VALUE, spoolss_notify_job_size },
 { JOB_NOTIFY_TYPE,     JOB_NOTIFY_BYTES_PRINTED,           "JOB_NOTIFY_BYTES_PRINTED",           ONE_VALUE, NULL },
 { END,                 END,                                "",                                   END,       NULL }
@@ -4256,6 +4282,7 @@ WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO
        }
        
        Printer->page_started=False;
+       print_job_endpage(Printer->jobid);
 
        return WERR_OK;
 }
@@ -5124,7 +5151,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue,
        job_info->status=nt_printj_status(queue->status);
        job_info->priority=queue->priority;
        job_info->position=position;
-       job_info->totalpages=0;
+       job_info->totalpages=queue->page_count;
        job_info->pagesprinted=0;
 
        make_systemtime(&job_info->submitted, t);
@@ -5168,7 +5195,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue,
        job_info->position=position;
        job_info->starttime=0;
        job_info->untiltime=0;
-       job_info->totalpages=0;
+       job_info->totalpages=queue->page_count;
        job_info->size=queue->size;
        make_systemtime(&(job_info->submitted), t);
        job_info->timeelapsed=0;