diff options
author | Jeremy Allison <jra@samba.org> | 2002-06-21 01:19:31 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-06-21 01:19:31 +0000 |
commit | 7ed56087329bd972c7402f710469d427c3159327 (patch) | |
tree | c122468eb2adbad093dff258ce12507f53e7b265 /source3/printing | |
parent | fdaf087daa672d8d87895d33923f34114210ae47 (diff) | |
download | samba-7ed56087329bd972c7402f710469d427c3159327.tar.gz samba-7ed56087329bd972c7402f710469d427c3159327.tar.bz2 samba-7ed56087329bd972c7402f710469d427c3159327.zip |
Format tidyup before I start working on scalability fixes (one file per
print queue).
Jeremy.
(This used to be commit 6544a500d0696c9fe1f1abc067a8b963a0e2b8da)
Diffstat (limited to 'source3/printing')
-rw-r--r-- | source3/printing/printing.c | 208 |
1 files changed, 134 insertions, 74 deletions
diff --git a/source3/printing/printing.c b/source3/printing/printing.c index d7ac1f49c7..47fc019d64 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -80,8 +80,9 @@ BOOL print_backend_init(void) } /**************************************************************************** -useful function to generate a tdb key + Useful function to generate a tdb key. ****************************************************************************/ + static TDB_DATA print_key(int jobid) { static int j; @@ -94,15 +95,17 @@ static TDB_DATA print_key(int jobid) } /**************************************************************************** -useful function to find a print job in the database + Useful function to find a print job in the database. ****************************************************************************/ + static struct printjob *print_job_find(int jobid) { static struct printjob pjob; TDB_DATA ret; ret = tdb_fetch(tdb, print_key(jobid)); - if (!ret.dptr || ret.dsize != sizeof(pjob)) return NULL; + if (!ret.dptr || ret.dsize != sizeof(pjob)) + return NULL; memcpy(&pjob, ret.dptr, sizeof(pjob)); free(ret.dptr); @@ -110,8 +113,9 @@ static struct printjob *print_job_find(int jobid) } /**************************************************************************** -store a job structure back to the database + Store a job structure back to the database. ****************************************************************************/ + static BOOL print_job_store(int jobid, struct printjob *pjob) { TDB_DATA d; @@ -124,25 +128,28 @@ static BOOL print_job_store(int jobid, struct printjob *pjob) } /**************************************************************************** -parse a file name from the system spooler to generate a jobid + Parse a file name from the system spooler to generate a jobid. ****************************************************************************/ + static int print_parse_jobid(char *fname) { int jobid; - if (strncmp(fname,PRINT_SPOOL_PREFIX,strlen(PRINT_SPOOL_PREFIX)) != 0) return -1; + if (strncmp(fname,PRINT_SPOOL_PREFIX,strlen(PRINT_SPOOL_PREFIX)) != 0) + return -1; fname += strlen(PRINT_SPOOL_PREFIX); jobid = atoi(fname); - if (jobid <= 0) return -1; + if (jobid <= 0) + return -1; return jobid; } - /**************************************************************************** -list a unix job in the print database + List a unix job in the print database. ****************************************************************************/ + static void print_unix_job(int snum, print_queue_struct *q) { int jobid = q->job + UNIX_JOB_START; @@ -176,14 +183,18 @@ struct traverse_struct { int qcount, snum, maxcount, total_jobs; }; -/* utility fn to delete any jobs that are no longer active */ +/**************************************************************************** + Utility fn to delete any jobs that are no longer active. +****************************************************************************/ + static int traverse_fn_delete(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *state) { struct traverse_struct *ts = (struct traverse_struct *)state; struct printjob pjob; int i, jobid; - if (data.dsize != sizeof(pjob) || key.dsize != sizeof(int)) return 0; + if (data.dsize != sizeof(pjob) || key.dsize != sizeof(int)) + return 0; memcpy(&jobid, key.dptr, sizeof(jobid)); memcpy(&pjob, data.dptr, sizeof(pjob)); @@ -197,7 +208,8 @@ static int traverse_fn_delete(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void /* remove a unix job if it isn't in the system queue any more */ for (i=0;i<ts->qcount;i++) { - if (jobid == ts->queue[i].job + UNIX_JOB_START) break; + if (jobid == ts->queue[i].job + UNIX_JOB_START) + break; } if (i == ts->qcount) tdb_delete(tdb, key); @@ -220,7 +232,8 @@ static int traverse_fn_delete(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void for (i=0;i<ts->qcount;i++) { int qid = print_parse_jobid(ts->queue[i].fs_file); - if (jobid == qid) break; + if (jobid == qid) + break; } /* The job isn't in the system queue - we have to assume it has @@ -249,8 +262,9 @@ static int traverse_fn_delete(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void } /**************************************************************************** -check if the print queue has been updated recently enough + Check if the print queue has been updated recently enough. ****************************************************************************/ + static void print_cache_flush(int snum) { fstring key; @@ -327,7 +341,7 @@ static void send_queue_message(const char *printer_name, uint32 high, uint32 low } /**************************************************************************** -update the internal database from the system print queue for a queue in the background + Update the internal database from the system print queue for a queue in the background ****************************************************************************/ static void print_queue_update_background(int snum) @@ -484,8 +498,9 @@ static void print_queue_update_background(int snum) } /**************************************************************************** -this is the receive function of the background lpq updater + This is the receive function of the background lpq updater. ****************************************************************************/ + static void print_queue_receive(int msg_type, pid_t src, void *buf, size_t len) { int snum; @@ -496,8 +511,9 @@ static void print_queue_receive(int msg_type, pid_t src, void *buf, size_t len) static pid_t background_lpq_updater_pid; /**************************************************************************** -main thread of the background lpq updater + Main thread of the background lpq updater. ****************************************************************************/ + void start_background_queue(void) { DEBUG(3,("start_background_queue: Starting background LPQ thread\n")); @@ -532,8 +548,9 @@ void start_background_queue(void) } /**************************************************************************** -update the internal database from the system print queue for a queue + Update the internal database from the system print queue for a queue. ****************************************************************************/ + static void print_queue_update(int snum) { if (background_lpq_updater_pid > 0) { @@ -543,8 +560,9 @@ static void print_queue_update(int snum) } /**************************************************************************** -check if a jobid is valid. It is valid if it exists in the database + Check if a jobid is valid. It is valid if it exists in the database. ****************************************************************************/ + BOOL print_job_exists(int jobid) { return tdb_exists(tdb, print_key(jobid)); @@ -552,46 +570,53 @@ BOOL print_job_exists(int jobid) /**************************************************************************** -work out which service a jobid is for -note that we have to look up by queue name to ensure that it works for -other than the process that started the job + Work out which service a jobid is for + note that we have to look up by queue name to ensure that it works for + other than the process that started the job. ****************************************************************************/ + int print_job_snum(int jobid) { struct printjob *pjob = print_job_find(jobid); - if (!pjob) return -1; + if (!pjob) + return -1; return find_service(pjob->queuename); } /**************************************************************************** -give the fd used for a jobid + Give the fd used for a jobid. ****************************************************************************/ + int print_job_fd(int jobid) { struct printjob *pjob = print_job_find(jobid); - if (!pjob) 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; + if (pjob->pid != local_pid) + return -1; return pjob->fd; } /**************************************************************************** -give the filename used for a jobid -only valid for the process doing the spooling and when the job -has not been spooled + Give the filename used for a jobid. + Only valid for the process doing the spooling and when the job + has not been spooled. ****************************************************************************/ + char *print_job_fname(int jobid) { struct printjob *pjob = print_job_find(jobid); - if (!pjob || pjob->spooled || pjob->pid != local_pid) return NULL; + if (!pjob || pjob->spooled || pjob->pid != local_pid) + return NULL; return pjob->filename; } - /**************************************************************************** -set the place in the queue for a job + Set the place in the queue for a job. ****************************************************************************/ + BOOL print_job_set_place(int jobid, int place) { DEBUG(2,("print_job_set_place not implemented yet\n")); @@ -599,27 +624,30 @@ BOOL print_job_set_place(int jobid, int place) } /**************************************************************************** -set the name of a job. Only possible for owner + Set the name of a job. Only possible for owner. ****************************************************************************/ + BOOL print_job_set_name(int jobid, char *name) { struct printjob *pjob = print_job_find(jobid); - if (!pjob || pjob->pid != local_pid) return False; + if (!pjob || pjob->pid != local_pid) + return False; fstrcpy(pjob->jobname, name); return print_job_store(jobid, pjob); } - /**************************************************************************** -delete a print job - don't update queue + Delete a print job - don't update queue. ****************************************************************************/ + static BOOL print_job_delete1(int jobid) { struct printjob *pjob = print_job_find(jobid); int snum, result = 0; - if (!pjob) return False; + if (!pjob) + return False; /* * If already deleting just return. @@ -638,8 +666,7 @@ static BOOL print_job_delete1(int jobid) has reached the spooler. */ if (pjob->sysjob == -1) { - DEBUG(5, ("attempt to delete job %d not seen by lpr\n", - jobid)); + DEBUG(5, ("attempt to delete job %d not seen by lpr\n", jobid)); } /* Set the tdb entry to be deleting. */ @@ -661,14 +688,16 @@ static BOOL print_job_delete1(int jobid) } /**************************************************************************** -return true if the current user owns the print job + Return true if the current user owns the print job. ****************************************************************************/ + static BOOL is_owner(struct current_user *user, int jobid) { struct printjob *pjob = print_job_find(jobid); user_struct *vuser; - if (!pjob || !user) return False; + if (!pjob || !user) + return False; if ((vuser = get_valid_user_struct(user->vuid)) != NULL) { return strequal(pjob->user, vuser->user.smb_name); @@ -678,8 +707,9 @@ static BOOL is_owner(struct current_user *user, int jobid) } /**************************************************************************** -delete a print job + Delete a print job. ****************************************************************************/ + BOOL print_job_delete(struct current_user *user, int jobid, WERROR *errcode) { int snum = print_job_snum(jobid); @@ -703,7 +733,8 @@ BOOL print_job_delete(struct current_user *user, int jobid, WERROR *errcode) return False; } - if (!print_job_delete1(jobid)) return False; + if (!print_job_delete1(jobid)) + return False; /* force update the database and say the delete failed if the job still exists */ @@ -719,19 +750,21 @@ BOOL print_job_delete(struct current_user *user, int jobid, WERROR *errcode) return !print_job_exists(jobid); } - /**************************************************************************** -pause a job + Pause a job. ****************************************************************************/ + BOOL print_job_pause(struct current_user *user, int jobid, WERROR *errcode) { struct printjob *pjob = print_job_find(jobid); int snum, ret = -1; char *printer_name; - if (!pjob || !user) return False; + if (!pjob || !user) + return False; - if (!pjob->spooled || pjob->sysjob == -1) return False; + if (!pjob->spooled || pjob->sysjob == -1) + return False; snum = print_job_snum(jobid); if (snum == -1) { @@ -773,17 +806,20 @@ BOOL print_job_pause(struct current_user *user, int jobid, WERROR *errcode) } /**************************************************************************** -resume a job + Resume a job. ****************************************************************************/ + BOOL print_job_resume(struct current_user *user, int jobid, WERROR *errcode) { struct printjob *pjob = print_job_find(jobid); char *printer_name; int snum, ret; - if (!pjob || !user) return False; + if (!pjob || !user) + return False; - if (!pjob->spooled || pjob->sysjob == -1) return False; + if (!pjob->spooled || pjob->sysjob == -1) + return False; snum = print_job_snum(jobid); @@ -814,8 +850,9 @@ BOOL print_job_resume(struct current_user *user, int jobid, WERROR *errcode) } /**************************************************************************** -write to a print file + Write to a print file. ****************************************************************************/ + int print_job_write(int jobid, const char *buf, int size) { int return_code; @@ -870,6 +907,7 @@ static BOOL print_cache_expired(int snum) /**************************************************************************** Get the queue status - do not update if db is out of date. ****************************************************************************/ + static int get_queue_status(int snum, print_status_struct *status) { fstring keystr; @@ -913,12 +951,14 @@ int print_queue_length(int snum, print_status_struct *pstatus) /**************************************************************************** Determine the number of jobs in all queues. ****************************************************************************/ + static int get_total_jobs(int snum) { int total_jobs; /* make sure the database is up to date */ - if (print_cache_expired(snum)) print_queue_update(snum); + if (print_cache_expired(snum)) + print_queue_update(snum); total_jobs = tdb_fetch_int32(tdb, "INFO/total_jobs"); if (total_jobs >0) @@ -930,6 +970,7 @@ static int get_total_jobs(int snum) /*************************************************************************** start spooling a job - return the jobid ***************************************************************************/ + int print_job_start(struct current_user *user, int snum, char *jobname) { int jobid; @@ -1075,7 +1116,7 @@ to open spool file %s.\n", pjob.filename)); } /**************************************************************************** - Update the number of pages spooled to jobid + Update the number of pages spooled to jobid. ****************************************************************************/ void print_job_endpage(int jobid) @@ -1169,14 +1210,18 @@ fail: return False; } -/* utility fn to enumerate the print queue */ +/**************************************************************************** + Utility fn to enumerate the print queue. +****************************************************************************/ + static int traverse_fn_queue(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *state) { struct traverse_struct *ts = (struct traverse_struct *)state; struct printjob pjob; int i, jobid; - if (data.dsize != sizeof(pjob) || key.dsize != sizeof(int)) return 0; + if (data.dsize != sizeof(pjob) || key.dsize != sizeof(int)) + return 0; memcpy(&jobid, key.dptr, sizeof(jobid)); memcpy(&pjob, data.dptr, sizeof(pjob)); @@ -1184,7 +1229,8 @@ static int traverse_fn_queue(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void * if (ts->snum != lp_servicenumber(pjob.queuename)) return 0; - if (ts->qcount >= ts->maxcount) return 0; + if (ts->qcount >= ts->maxcount) + return 0; i = ts->qcount; @@ -1206,14 +1252,18 @@ struct traverse_count_struct { int snum, count; }; -/* utility fn to count the number of entries in the print queue */ +/**************************************************************************** + Utility fn to count the number of entries in the print queue. +****************************************************************************/ + static int traverse_count_fn_queue(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *state) { struct traverse_count_struct *ts = (struct traverse_count_struct *)state; struct printjob pjob; int jobid; - if (data.dsize != sizeof(pjob) || key.dsize != sizeof(int)) return 0; + if (data.dsize != sizeof(pjob) || key.dsize != sizeof(int)) + return 0; memcpy(&jobid, key.dptr, sizeof(jobid)); memcpy(&pjob, data.dptr, sizeof(pjob)); @@ -1226,25 +1276,32 @@ static int traverse_count_fn_queue(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, return 0; } -/* Sort print jobs by submittal time */ +/**************************************************************************** + Sort print jobs by submittal time. +****************************************************************************/ static int printjob_comp(print_queue_struct *j1, print_queue_struct *j2) { /* Silly cases */ - if (!j1 && !j2) return 0; - if (!j1) return -1; - if (!j2) return 1; + if (!j1 && !j2) + return 0; + if (!j1) + return -1; + if (!j2) + return 1; /* Sort on job start time */ - if (j1->time == j2->time) return 0; + if (j1->time == j2->time) + return 0; return (j1->time > j2->time) ? 1 : -1; } /**************************************************************************** -get a printer queue listing + Get a printer queue listing. ****************************************************************************/ + int print_queue_status(int snum, print_queue_struct **queue, print_status_struct *status) @@ -1255,7 +1312,8 @@ int print_queue_status(int snum, TDB_DATA data, key; /* make sure the database is up to date */ - if (print_cache_expired(snum)) print_queue_update(snum); + if (print_cache_expired(snum)) + print_queue_update(snum); *queue = NULL; @@ -1289,8 +1347,7 @@ int print_queue_status(int snum, /* Allocate the queue size. */ if ((tstruct.queue = (print_queue_struct *) - malloc(sizeof(print_queue_struct)*tsc.count)) - == NULL) + malloc(sizeof(print_queue_struct)*tsc.count)) == NULL) return 0; /* @@ -1314,21 +1371,22 @@ int print_queue_status(int snum, return tstruct.qcount; } - /**************************************************************************** -turn a queue name into a snum + Turn a queue name into a snum. ****************************************************************************/ + int print_queue_snum(char *qname) { int snum = lp_servicenumber(qname); - if (snum == -1 || !lp_print_ok(snum)) return -1; + if (snum == -1 || !lp_print_ok(snum)) + return -1; return snum; } - /**************************************************************************** - pause a queue + Pause a queue. ****************************************************************************/ + BOOL print_queue_pause(struct current_user *user, int snum, WERROR *errcode) { char *printer_name; @@ -1359,8 +1417,9 @@ BOOL print_queue_pause(struct current_user *user, int snum, WERROR *errcode) } /**************************************************************************** - resume a queue + Resume a queue. ****************************************************************************/ + BOOL print_queue_resume(struct current_user *user, int snum, WERROR *errcode) { char *printer_name; @@ -1391,8 +1450,9 @@ BOOL print_queue_resume(struct current_user *user, int snum, WERROR *errcode) } /**************************************************************************** - purge a queue - implemented by deleting all jobs that we can delete + Purge a queue - implemented by deleting all jobs that we can delete. ****************************************************************************/ + BOOL print_queue_purge(struct current_user *user, int snum, WERROR *errcode) { print_queue_struct *queue; |