From 001765501ed5dcc9e3c29d9f662c428e2a66187a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Apr 2000 03:09:42 +0000 Subject: split out the lpq parsing code into a separate file printing/lpq_parse.c getting ready for the new printing backend (This used to be commit 0ec1072e0143952139be64e8001582eadcc9f60e) --- source3/printing/lpq_parse.c | 883 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 883 insertions(+) create mode 100644 source3/printing/lpq_parse.c (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c new file mode 100644 index 0000000000..ae8bb8398b --- /dev/null +++ b/source3/printing/lpq_parse.c @@ -0,0 +1,883 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + lpq parsing routines + Copyright (C) Andrew Tridgell 2000 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +extern int DEBUGLEVEL; + + +static char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"}; + + +/******************************************************************* +process time fields +********************************************************************/ +static time_t EntryTime(fstring tok[], int ptr, int count, int minimum) +{ + time_t jobtime,jobtime1; + + jobtime = time(NULL); /* default case: take current time */ + if (count >= minimum) { + struct tm *t; + int i, day, hour, min, sec; + char *c; + + for (i=0; i<13; i++) if (!strncmp(tok[ptr], Months[i],3)) break; /* Find month */ + if (i<12) { + t = localtime(&jobtime); + day = atoi(tok[ptr+1]); + c=(char *)(tok[ptr+2]); + *(c+2)=0; + hour = atoi(c); + *(c+5)=0; + min = atoi(c+3); + if(*(c+6) != 0)sec = atoi(c+6); + else sec=0; + + if ((t->tm_mon < i)|| + ((t->tm_mon == i)&& + ((t->tm_mday < day)|| + ((t->tm_mday == day)&& + (t->tm_hour*60+t->tm_min < hour*60+min))))) + t->tm_year--; /* last year's print job */ + + t->tm_mon = i; + t->tm_mday = day; + t->tm_hour = hour; + t->tm_min = min; + t->tm_sec = sec; + jobtime1 = mktime(t); + if (jobtime1 != (time_t)-1) + jobtime = jobtime1; + } + } + return jobtime; +} + + +/**************************************************************************** +parse a lpq line + +here is an example of lpq output under bsd + +Warning: no daemon present +Rank Owner Job Files Total Size +1st tridge 148 README 8096 bytes + +here is an example of lpq output under osf/1 + +Warning: no daemon present +Rank Pri Owner Job Files Total Size +1st 0 tridge 148 README 8096 bytes + + + June 30, 1998. +Modified to handle file names with spaces, like the parse_lpq_lprng code +further below. +****************************************************************************/ +static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first) +{ +#ifdef OSF1 +#define RANKTOK 0 +#define PRIOTOK 1 +#define USERTOK 2 +#define JOBTOK 3 +#define FILETOK 4 +#define TOTALTOK (count - 2) +#define NTOK 6 +#define MAXTOK 128 +#else /* OSF1 */ +#define RANKTOK 0 +#define USERTOK 1 +#define JOBTOK 2 +#define FILETOK 3 +#define TOTALTOK (count - 2) +#define NTOK 5 +#define MAXTOK 128 +#endif /* OSF1 */ + + char *tok[MAXTOK]; + int count = 0; + pstring line2; + + pstrcpy(line2,line); + +#ifdef OSF1 + { + size_t length; + length = strlen(line2); + if (line2[length-3] == ':') + return(False); + } +#endif /* OSF1 */ + + tok[0] = strtok(line2," \t"); + count++; + + while (((tok[count] = strtok(NULL," \t")) != NULL) && (count < MAXTOK)) { + count++; + } + + /* we must get at least NTOK tokens */ + if (count < NTOK) + return(False); + + /* the Job and Total columns must be integer */ + if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) return(False); + + buf->job = atoi(tok[JOBTOK]); + buf->size = atoi(tok[TOTALTOK]); + buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED; + buf->time = time(NULL); + StrnCpy(buf->user,tok[USERTOK],sizeof(buf->user)-1); + StrnCpy(buf->file,tok[FILETOK],sizeof(buf->file)-1); + + if ((FILETOK + 1) != TOTALTOK) { + int bufsize; + int i; + + bufsize = sizeof(buf->file) - strlen(buf->file) - 1; + + for (i = (FILETOK + 1); i < TOTALTOK; i++) { + safe_strcat(buf->file," ",bufsize); + safe_strcat(buf->file,tok[i],bufsize - 1); + bufsize = sizeof(buf->file) - strlen(buf->file) - 1; + if (bufsize <= 0) { + break; + } + } + /* Ensure null termination. */ + buf->file[sizeof(buf->file)-1] = '\0'; + } + +#ifdef PRIOTOK + buf->priority = atoi(tok[PRIOTOK]); +#else + buf->priority = 1; +#endif + return(True); +} + +/* + +LPRng_time modifies the current date by inserting the hour and minute from +the lpq output. The lpq time looks like "23:15:07" + + June 30, 1998. +Modified to work with the re-written parse_lpq_lprng routine. +*/ +static time_t LPRng_time(char *time_string) +{ + time_t jobtime; + struct tm *t; + + jobtime = time(NULL); /* default case: take current time */ + t = localtime(&jobtime); + t->tm_hour = atoi(time_string); + t->tm_min = atoi(time_string+3); + t->tm_sec = atoi(time_string+6); + jobtime = mktime(t); + + return jobtime; +} + + +/**************************************************************************** + parse a lprng lpq line + June 30, 1998. + Re-wrote this to handle file names with spaces, multiple file names on one + lpq line, etc; +****************************************************************************/ +static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) +{ +#define LPRNG_RANKTOK 0 +#define LPRNG_USERTOK 1 +#define LPRNG_PRIOTOK 2 +#define LPRNG_JOBTOK 3 +#define LPRNG_FILETOK 4 +#define LPRNG_TOTALTOK (num_tok - 2) +#define LPRNG_TIMETOK (num_tok - 1) +#define LPRNG_NTOK 7 +#define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */ + + char *tokarr[LPRNG_MAXTOK]; + char *cptr; + int num_tok = 0; + pstring line2; + + pstrcpy(line2,line); + tokarr[0] = strtok(line2," \t"); + num_tok++; + while (((tokarr[num_tok] = strtok(NULL," \t")) != NULL) + && (num_tok < LPRNG_MAXTOK)) { + num_tok++; + } + + /* We must get at least LPRNG_NTOK tokens. */ + if (num_tok < LPRNG_NTOK) { + return(False); + } + + if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) { + return(False); + } + + buf->job = atoi(tokarr[LPRNG_JOBTOK]); + buf->size = atoi(tokarr[LPRNG_TOTALTOK]); + + if (strequal(tokarr[LPRNG_RANKTOK],"active")) { + buf->status = LPQ_PRINTING; + } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) { + buf->status = LPQ_QUEUED; + } else { + buf->status = LPQ_PAUSED; + } + + buf->priority = *tokarr[LPRNG_PRIOTOK] -'A'; + + buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]); + + StrnCpy(buf->user,tokarr[LPRNG_USERTOK],sizeof(buf->user)-1); + + /* The '@hostname' prevents windows from displaying the printing icon + * for the current user on the taskbar. Plop in a null. + */ + + if ((cptr = strchr(buf->user,'@')) != NULL) { + *cptr = '\0'; + } + + StrnCpy(buf->file,tokarr[LPRNG_FILETOK],sizeof(buf->file)-1); + + if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) { + int bufsize; + int i; + + bufsize = sizeof(buf->file) - strlen(buf->file) - 1; + + for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) { + safe_strcat(buf->file," ",bufsize); + safe_strcat(buf->file,tokarr[i],bufsize - 1); + bufsize = sizeof(buf->file) - strlen(buf->file) - 1; + if (bufsize <= 0) { + break; + } + } + /* Ensure null termination. */ + buf->file[sizeof(buf->file)-1] = '\0'; + } + + return(True); +} + + + +/******************************************************************* +parse lpq on an aix system + +Queue Dev Status Job Files User PP % Blks Cp Rnk +------- ----- --------- --- ------------------ ---------- ---- -- ----- --- --- +lazer lazer READY +lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1 + QUEUED 538 C.ps root@IEDVB 124 1 2 + QUEUED 539 E.ps root@IEDVB 28 1 3 + QUEUED 540 L.ps root@IEDVB 172 1 4 + QUEUED 541 P.ps root@IEDVB 22 1 5 +********************************************************************/ +static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) +{ + fstring tok[11]; + int count=0; + + /* handle the case of "(standard input)" as a filename */ + pstring_sub(line,"standard input","STDIN"); + all_string_sub(line,"(","\"",0); + all_string_sub(line,")","\"",0); + + for (count=0; + count<10 && + next_token(&line,tok[count],NULL, sizeof(tok[count])); + count++) ; + + /* we must get 6 tokens */ + if (count < 10) + { + if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) + { + /* the 2nd and 5th columns must be integer */ + if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) return(False); + buf->size = atoi(tok[4]) * 1024; + /* if the fname contains a space then use STDIN */ + if (strchr(tok[2],' ')) + fstrcpy(tok[2],"STDIN"); + + /* only take the last part of the filename */ + { + fstring tmp; + char *p = strrchr(tok[2],'/'); + if (p) + { + fstrcpy(tmp,p+1); + fstrcpy(tok[2],tmp); + } + } + + + buf->job = atoi(tok[1]); + buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED; + buf->priority = 0; + buf->time = time(NULL); + StrnCpy(buf->user,tok[3],sizeof(buf->user)-1); + StrnCpy(buf->file,tok[2],sizeof(buf->file)-1); + } + else + { + DEBUG(6,("parse_lpq_aix count=%d\n", count)); + return(False); + } + } + else + { + /* the 4th and 9th columns must be integer */ + if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) return(False); + buf->size = atoi(tok[8]) * 1024; + /* if the fname contains a space then use STDIN */ + if (strchr(tok[4],' ')) + fstrcpy(tok[4],"STDIN"); + + /* only take the last part of the filename */ + { + fstring tmp; + char *p = strrchr(tok[4],'/'); + if (p) + { + fstrcpy(tmp,p+1); + fstrcpy(tok[4],tmp); + } + } + + + buf->job = atoi(tok[3]); + buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED; + buf->priority = 0; + buf->time = time(NULL); + StrnCpy(buf->user,tok[5],sizeof(buf->user)-1); + StrnCpy(buf->file,tok[4],sizeof(buf->file)-1); + } + + + return(True); +} + + +/**************************************************************************** +parse a lpq line +here is an example of lpq output under hpux; note there's no space after -o ! +$> lpstat -oljplus +ljplus-2153 user priority 0 Jan 19 08:14 on ljplus + util.c 125697 bytes + server.c 110712 bytes +ljplus-2154 user priority 0 Jan 19 08:14 from client + (standard input) 7551 bytes +****************************************************************************/ +static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) +{ + /* must read two lines to process, therefore keep some values static */ + static BOOL header_line_ok=False, base_prio_reset=False; + static fstring jobuser; + static int jobid; + static int jobprio; + static time_t jobtime; + static int jobstat=LPQ_QUEUED; + /* to store minimum priority to print, lpstat command should be invoked + with -p option first, to work */ + static int base_prio; + + int count; + char htab = '\011'; + fstring tok[12]; + + /* If a line begins with a horizontal TAB, it is a subline type */ + + if (line[0] == htab) { /* subline */ + /* check if it contains the base priority */ + if (!strncmp(line,"\tfence priority : ",18)) { + base_prio=atoi(&line[18]); + DEBUG(4, ("fence priority set at %d\n", base_prio)); + } + if (!header_line_ok) return (False); /* incorrect header line */ + /* handle the case of "(standard input)" as a filename */ + pstring_sub(line,"standard input","STDIN"); + all_string_sub(line,"(","\"",0); + all_string_sub(line,")","\"",0); + + for (count=0; count<2 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + /* we must get 2 tokens */ + if (count < 2) return(False); + + /* the 2nd column must be integer */ + if (!isdigit((int)*tok[1])) return(False); + + /* if the fname contains a space then use STDIN */ + if (strchr(tok[0],' ')) + fstrcpy(tok[0],"STDIN"); + + buf->size = atoi(tok[1]); + StrnCpy(buf->file,tok[0],sizeof(buf->file)-1); + + /* fill things from header line */ + buf->time = jobtime; + buf->job = jobid; + buf->status = jobstat; + buf->priority = jobprio; + StrnCpy(buf->user,jobuser,sizeof(buf->user)-1); + + return(True); + } + else { /* header line */ + header_line_ok=False; /* reset it */ + if (first) { + if (!base_prio_reset) { + base_prio=0; /* reset it */ + base_prio_reset=True; + } + } + else if (base_prio) base_prio_reset=False; + + /* handle the dash in the job id */ + pstring_sub(line,"-"," "); + + for (count=0; count<12 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + + /* we must get 8 tokens */ + if (count < 8) return(False); + + /* first token must be printer name (cannot check ?) */ + /* the 2nd, 5th & 7th column must be integer */ + if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) return(False); + jobid = atoi(tok[1]); + StrnCpy(jobuser,tok[2],sizeof(buf->user)-1); + jobprio = atoi(tok[4]); + + /* process time */ + jobtime=EntryTime(tok, 5, count, 8); + if (jobprio < base_prio) { + jobstat = LPQ_PAUSED; + DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n", jobid, jobprio, base_prio, jobstat)); + } + else { + jobstat = LPQ_QUEUED; + if ((count >8) && (((strequal(tok[8],"on")) || + ((strequal(tok[8],"from")) && + ((count > 10)&&(strequal(tok[10],"on"))))))) + jobstat = LPQ_PRINTING; + } + + header_line_ok=True; /* information is correct */ + return(False); /* need subline info to include into queuelist */ + } +} + + +/**************************************************************************** +parse a lpstat line + +here is an example of "lpstat -o dcslw" output under sysv + +dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw +dcslw-897 tridge 4712 Dec 20 10:30:30 being held + +****************************************************************************/ +static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first) +{ + fstring tok[9]; + int count=0; + char *p; + + /* + * Handle the dash in the job id, but make sure that we skip over + * the printer name in case we have a dash in that. + * Patch from Dom.Mitchell@palmerharvey.co.uk. + */ + + /* + * Move to the first space. + */ + for (p = line ; !isspace(*p) && *p; p++) + ; + + /* + * Back up until the last '-' character or + * start of line. + */ + for (; (p >= line) && (*p != '-'); p--) + ; + + if((p >= line) && (*p == '-')) + *p = ' '; + + for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) + ; + + /* we must get 7 tokens */ + if (count < 7) + return(False); + + /* the 2nd and 4th, 6th columns must be integer */ + if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) + return(False); + if (!isdigit((int)*tok[5])) + return(False); + + /* if the user contains a ! then trim the first part of it */ + if ((p=strchr(tok[2],'!'))) { + fstring tmp; + fstrcpy(tmp,p+1); + fstrcpy(tok[2],tmp); + } + + buf->job = atoi(tok[1]); + buf->size = atoi(tok[3]); + if (count > 7 && strequal(tok[7],"on")) + buf->status = LPQ_PRINTING; + else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held")) + buf->status = LPQ_PAUSED; + else + buf->status = LPQ_QUEUED; + buf->priority = 0; + buf->time = EntryTime(tok, 4, count, 7); + StrnCpy(buf->user,tok[2],sizeof(buf->user)-1); + StrnCpy(buf->file,tok[2],sizeof(buf->file)-1); + return(True); +} + +/**************************************************************************** +parse a lpq line + +here is an example of lpq output under qnx +Spooler: /qnx/spooler, on node 1 +Printer: txt (ready) +0000: root [job #1 ] active 1146 bytes /etc/profile +0001: root [job #2 ] ready 2378 bytes /etc/install +0002: root [job #3 ] ready 1146 bytes -- standard input -- +****************************************************************************/ +static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) +{ + fstring tok[7]; + int count=0; + + DEBUG(4,("antes [%s]\n", line)); + + /* handle the case of "-- standard input --" as a filename */ + pstring_sub(line,"standard input","STDIN"); + DEBUG(4,("despues [%s]\n", line)); + all_string_sub(line,"-- ","\"",0); + all_string_sub(line," --","\"",0); + DEBUG(4,("despues 1 [%s]\n", line)); + + pstring_sub(line,"[job #",""); + pstring_sub(line,"]",""); + DEBUG(4,("despues 2 [%s]\n", line)); + + + + for (count=0; count<7 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + + /* we must get 7 tokens */ + if (count < 7) + return(False); + + /* the 3rd and 5th columns must be integer */ + if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) return(False); + + /* only take the last part of the filename */ + { + fstring tmp; + char *p = strrchr(tok[6],'/'); + if (p) + { + fstrcpy(tmp,p+1); + fstrcpy(tok[6],tmp); + } + } + + + buf->job = atoi(tok[2]); + buf->size = atoi(tok[4]); + buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED; + buf->priority = 0; + buf->time = time(NULL); + StrnCpy(buf->user,tok[1],sizeof(buf->user)-1); + StrnCpy(buf->file,tok[6],sizeof(buf->file)-1); + return(True); +} + + +/**************************************************************************** + parse a lpq line for the plp printing system + Bertrand Wallrich + +redone by tridge. Here is a sample queue: + +Local Printer 'lp2' (fjall): + Printing (started at Jun 15 13:33:58, attempt 1). + Rank Owner Pr Opt Job Host Files Size Date + active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33 + 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33 + +****************************************************************************/ +static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) +{ + fstring tok[11]; + int count=0; + + /* handle the case of "(standard input)" as a filename */ + pstring_sub(line,"stdin","STDIN"); + all_string_sub(line,"(","\"",0); + all_string_sub(line,")","\"",0); + + for (count=0; count<11 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + + /* we must get 11 tokens */ + if (count < 11) + return(False); + + /* the first must be "active" or begin with an integer */ + if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) + return(False); + + /* the 5th and 8th must be integer */ + if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) + return(False); + + /* if the fname contains a space then use STDIN */ + if (strchr(tok[6],' ')) + fstrcpy(tok[6],"STDIN"); + + /* only take the last part of the filename */ + { + fstring tmp; + char *p = strrchr(tok[6],'/'); + if (p) + { + fstrcpy(tmp,p+1); + fstrcpy(tok[6],tmp); + } + } + + + buf->job = atoi(tok[4]); + + buf->size = atoi(tok[7]); + if (strchr(tok[7],'K')) + buf->size *= 1024; + if (strchr(tok[7],'M')) + buf->size *= 1024*1024; + + buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED; + buf->priority = 0; + buf->time = time(NULL); + StrnCpy(buf->user,tok[1],sizeof(buf->user)-1); + StrnCpy(buf->file,tok[6],sizeof(buf->file)-1); + return(True); +} + +/**************************************************************************** +parse a qstat line + +here is an example of "qstat -l -d qms" output under softq + +Queue qms: 2 jobs; daemon active (313); enabled; accepting; + job-ID submission-time pri size owner title +205980: H 98/03/09 13:04:05 0 15733 stephenf chap1.ps +206086:> 98/03/12 17:24:40 0 659 chris - +206087: 98/03/12 17:24:45 0 4876 chris - +Total: 21268 bytes in queue + + +****************************************************************************/ +static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first) +{ + fstring tok[10]; + int count=0; + + /* mung all the ":"s to spaces*/ + pstring_sub(line,":"," "); + + for (count=0; count<10 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + + /* we must get 9 tokens */ + if (count < 9) + return(False); + + /* the 1st and 7th columns must be integer */ + if (!isdigit((int)*tok[0]) || !isdigit((int)*tok[6])) return(False); + /* if the 2nd column is either '>' or 'H' then the 7th and 8th must be + * integer, else it's the 6th and 7th that must be + */ + if (*tok[1] == 'H' || *tok[1] == '>') + { + if (!isdigit((int)*tok[7])) + return(False); + buf->status = *tok[1] == '>' ? LPQ_PRINTING : LPQ_PAUSED; + count = 1; + } + else + { + if (!isdigit((int)*tok[5])) + return(False); + buf->status = LPQ_QUEUED; + count = 0; + } + + + buf->job = atoi(tok[0]); + buf->size = atoi(tok[count+6]); + buf->priority = atoi(tok[count+5]); + StrnCpy(buf->user,tok[count+7],sizeof(buf->user)-1); + StrnCpy(buf->file,tok[count+8],sizeof(buf->file)-1); + buf->time = time(NULL); /* default case: take current time */ + { + time_t jobtime; + struct tm *t; + + t = localtime(&buf->time); + t->tm_mday = atoi(tok[count+2]+6); + t->tm_mon = atoi(tok[count+2]+3); + switch (*tok[count+2]) + { + case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]); break; + default: t->tm_year = atoi(tok[count+2]); break; + } + + t->tm_hour = atoi(tok[count+3]); + t->tm_min = atoi(tok[count+4]); + t->tm_sec = atoi(tok[count+5]); + jobtime = mktime(t); + if (jobtime != (time_t)-1) + buf->time = jobtime; + } + + return(True); +} + + +static char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL }; +static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL }; +static char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL }; + +/**************************************************************************** +parse a lpq line. Choose printing style +****************************************************************************/ +BOOL parse_lpq_entry(int snum,char *line, + print_queue_struct *buf, + print_status_struct *status,BOOL first) +{ + BOOL ret; + + switch (lp_printing(snum)) + { + case PRINT_SYSV: + ret = parse_lpq_sysv(line,buf,first); + break; + case PRINT_AIX: + ret = parse_lpq_aix(line,buf,first); + break; + case PRINT_HPUX: + ret = parse_lpq_hpux(line,buf,first); + break; + case PRINT_QNX: + ret = parse_lpq_qnx(line,buf,first); + break; + case PRINT_LPRNG: + ret = parse_lpq_lprng(line,buf,first); + break; + case PRINT_PLP: + ret = parse_lpq_plp(line,buf,first); + break; + case PRINT_SOFTQ: + ret = parse_lpq_softq(line,buf,first); + break; + default: + ret = parse_lpq_bsd(line,buf,first); + break; + } + +#ifdef LPQ_GUEST_TO_USER + if (ret) { + extern pstring sesssetup_user; + /* change guest entries to the current logged in user to make + them appear deletable to windows */ + if (sesssetup_user[0] && strequal(buf->user,lp_guestaccount(snum))) + pstrcpy(buf->user,sesssetup_user); + } +#endif + + /* We don't want the newline in the status message. */ + { + char *p = strchr(line,'\n'); + if (p) *p = 0; + } + + /* in the LPRNG case, we skip lines starting by a space.*/ + if (line && !ret && (lp_printing(snum)==PRINT_LPRNG) ) + { + if (line[0]==' ') + return ret; + } + + + if (status && !ret) + { + /* a few simple checks to see if the line might be a + printer status line: + handle them so that most severe condition is shown */ + int i; + strlower(line); + + switch (status->status) { + case LPSTAT_OK: + for (i=0; stat0_strings[i]; i++) + if (strstr(line,stat0_strings[i])) { + StrnCpy(status->message,line,sizeof(status->message)-1); + status->status=LPSTAT_OK; + return ret; + } + case LPSTAT_STOPPED: + for (i=0; stat1_strings[i]; i++) + if (strstr(line,stat1_strings[i])) { + StrnCpy(status->message,line,sizeof(status->message)-1); + status->status=LPSTAT_STOPPED; + return ret; + } + case LPSTAT_ERROR: + for (i=0; stat2_strings[i]; i++) + if (strstr(line,stat2_strings[i])) { + StrnCpy(status->message,line,sizeof(status->message)-1); + status->status=LPSTAT_ERROR; + return ret; + } + break; + } + } + + return(ret); +} -- cgit From f3a861e04e33901c89408a9c89ebaa81fc606f97 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 May 2000 07:59:34 +0000 Subject: - use full_name instead of real_name - got rid of guest map code in lpq parser (This used to be commit 8e53f781d3cf6a7007764916a0d8e8f1abea1f66) --- source3/printing/lpq_parse.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index ae8bb8398b..42da593c8d 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -821,16 +821,6 @@ BOOL parse_lpq_entry(int snum,char *line, break; } -#ifdef LPQ_GUEST_TO_USER - if (ret) { - extern pstring sesssetup_user; - /* change guest entries to the current logged in user to make - them appear deletable to windows */ - if (sesssetup_user[0] && strequal(buf->user,lp_guestaccount(snum))) - pstrcpy(buf->user,sesssetup_user); - } -#endif - /* We don't want the newline in the status message. */ { char *p = strchr(line,'\n'); -- cgit From 5d4f5cdddc23819bfab0961a013ed5593b2b2d30 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 7 Oct 2000 00:48:27 +0000 Subject: Integrated support for NT and OS/2 lpq parsing. Code from Jim McDonough Infoprint Manager Development Linux Technology Center IBM Boulder Jeremy. (This used to be commit d9eedd5db1728be8e23d73c954db13bbbcadf3fb) --- source3/printing/lpq_parse.c | 163 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 42da593c8d..4a4cf6306b 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -779,6 +779,163 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first) return(True); } +/******************************************************************* +parse lpq on an NT system + + Windows 2000 LPD Server + Printer \\10.0.0.2\NP17PCL (Paused) + +Owner Status Jobname Job-Id Size Pages Priority +---------------------------------------------------------------------------- +root (9.99. Printing /usr/lib/rhs/rhs-pr 3 625 0 1 +root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1 +jmcd Waiting Re: Samba Open Sour 26 32476 1 1 + +********************************************************************/ +static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) +{ +#define LPRNT_OWNSIZ 11 +#define LPRNT_STATSIZ 9 +#define LPRNT_JOBSIZ 19 +#define LPRNT_IDSIZ 6 +#define LPRNT_SIZSIZ 9 + typedef struct + { + char owner[LPRNT_OWNSIZ]; + char space1; + char status[LPRNT_STATSIZ]; + char space2; + char jobname[LPRNT_JOBSIZ]; + char space3; + char jobid[LPRNT_IDSIZ]; + char space4; + char size[LPRNT_SIZSIZ]; + char terminator; + } nt_lpq_line; + + nt_lpq_line parse_line; +#define LPRNT_PRINTING "Printing" +#define LPRNT_WAITING "Waiting" +#define LPRNT_PAUSED "Paused" + + memset(&parse_line, '\0', sizeof(parse_line)); + strncpy((char *) &parse_line, line, sizeof(parse_line) -1); + + if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) + return(False); + + /* Just want the first word in the owner field - the username */ + if (strchr(parse_line.owner, ' ')) + *(strchr(parse_line.owner, ' ')) = '\0'; + else + parse_line.space1 = '\0'; + + /* Make sure we have an owner */ + if (!strlen(parse_line.owner)) + return(False); + + /* Make sure the status is valid */ + parse_line.space2 = '\0'; + trim_string(parse_line.status, NULL, " "); + if (!strequal(parse_line.status, LPRNT_PRINTING) && + !strequal(parse_line.status, LPRNT_PAUSED) && + !strequal(parse_line.status, LPRNT_WAITING)) + return(False); + + parse_line.space3 = '\0'; + trim_string(parse_line.jobname, NULL, " "); + + buf->job = atoi(parse_line.jobid); + buf->priority = 0; + buf->size = atoi(parse_line.size); + buf->time = time(NULL); + StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1); + StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1); + if (strequal(parse_line.status, LPRNT_PRINTING)) + buf->status = LPQ_PRINTING; + else if (strequal(parse_line.status, LPRNT_PAUSED)) + buf->status = LPQ_PAUSED; + else + buf->status = LPQ_QUEUED; + + return(True); +} + +/******************************************************************* +parse lpq on an OS2 system + +JobID File Name Rank Size Status Comment +----- --------------- ------ -------- ------------ ------------ + 3 Control 1 68 Queued root@psflinu + 4 /etc/motd 2 11666 Queued root@psflinu + +********************************************************************/ +static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) +{ +#define LPROS2_IDSIZ 5 +#define LPROS2_JOBSIZ 15 +#define LPROS2_SIZSIZ 8 +#define LPROS2_STATSIZ 12 +#define LPROS2_OWNSIZ 12 + typedef struct + { + char jobid[LPROS2_IDSIZ]; + char space1[2]; + char jobname[LPROS2_JOBSIZ]; + char space2[14]; + char size[LPROS2_SIZSIZ]; + char space3[4]; + char status[LPROS2_STATSIZ]; + char space4[4]; + char owner[LPROS2_OWNSIZ]; + char terminator; + } os2_lpq_line; + + os2_lpq_line parse_line; +#define LPROS2_PRINTING "Printing" +#define LPROS2_WAITING "Queued" +#define LPROS2_PAUSED "Paused" + + memset(&parse_line, '\0', sizeof(parse_line)); + strncpy((char *) &parse_line, line, sizeof(parse_line) -1); + + if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) + return(False); + + /* Get the jobid */ + buf->job = atoi(parse_line.jobid); + + /* Get the job name */ + parse_line.space2[0] = '\0'; + trim_string(parse_line.jobname, NULL, " "); + StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1); + + buf->priority = 0; + buf->size = atoi(parse_line.size); + buf->time = time(NULL); + + /* Make sure we have an owner */ + if (!strlen(parse_line.owner)) + return(False); + + /* Make sure we have a valid status */ + parse_line.space4[0] = '\0'; + trim_string(parse_line.status, NULL, " "); + if (!strequal(parse_line.status, LPROS2_PRINTING) && + !strequal(parse_line.status, LPROS2_PAUSED) && + !strequal(parse_line.status, LPROS2_WAITING)) + return(False); + + StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1); + if (strequal(parse_line.status, LPROS2_PRINTING)) + buf->status = LPQ_PRINTING; + else if (strequal(parse_line.status, LPROS2_PAUSED)) + buf->status = LPQ_PAUSED; + else + buf->status = LPQ_QUEUED; + + return(True); +} static char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL }; static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL }; @@ -816,6 +973,12 @@ BOOL parse_lpq_entry(int snum,char *line, case PRINT_SOFTQ: ret = parse_lpq_softq(line,buf,first); break; + case PRINT_LPRNT: + ret = parse_lpq_nt(line,buf,first); + break; + case PRINT_LPROS2: + ret = parse_lpq_os2(line,buf,first); + break; default: ret = parse_lpq_bsd(line,buf,first); break; -- cgit From 0b0681388d1bc2eab5daef9993ccd564825f5b9e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 25 Oct 2000 21:28:15 +0000 Subject: We already have a perfectly good next_token() function we should be using instead of strtok - this fixes a bug with NT users with spaces in their names when using winbindd. Needs to be added to the other parse_lpXX functions (currently only added to lprng parsing code). Jeremy. (This used to be commit c3e4ac9a2db32c40ce330de0eab4bc82ef4fd579) --- source3/printing/lpq_parse.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 4a4cf6306b..e0b3ed192f 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -218,18 +218,15 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) #define LPRNG_NTOK 7 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */ - char *tokarr[LPRNG_MAXTOK]; + fstring tokarr[LPRNG_MAXTOK]; char *cptr; int num_tok = 0; pstring line2; pstrcpy(line2,line); - tokarr[0] = strtok(line2," \t"); - num_tok++; - while (((tokarr[num_tok] = strtok(NULL," \t")) != NULL) - && (num_tok < LPRNG_MAXTOK)) { + cptr = line2; + while(next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring)) && (num_tok < LPRNG_MAXTOK)) num_tok++; - } /* We must get at least LPRNG_NTOK tokens. */ if (num_tok < LPRNG_NTOK) { -- cgit From f9680a444bcba72540ab5e23bb44677ef74a9f13 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Tue, 14 Nov 2000 15:26:53 +0000 Subject: Changes from APPLIANCE_HEAD: - merged Tim's vlp (virtual lp) test program. Enable it with -DDEVELOPER or by using ./configure.developer (source/include/smb.h source/configure.developer source/printing/lpq_parse.c source/param/loadparm.c testsuite/printing/.cvsignore testsuite/printing/Makefile.vlp testsuite/printing/vlp.c) (This used to be commit fbcf83140da1823e74f63227f0a95d07c6e76764) --- source3/printing/lpq_parse.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index e0b3ed192f..f6bf7f06df 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -938,6 +938,51 @@ static char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "fre static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL }; static char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL }; +#ifdef DEVELOPER + +/**************************************************************************** +parse a vlp line +****************************************************************************/ +static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) +{ + int toknum = 0; + fstring tok; + + /* First line is printer status */ + + if (!isdigit(line[0])) return False; + + /* Parse a print job entry */ + + while(next_token(&line, tok, NULL, sizeof(fstring))) { + switch (toknum) { + case 0: + buf->job = atoi(tok); + break; + case 1: + buf->size = atoi(tok); + break; + case 2: + buf->status = atoi(tok); + break; + case 3: + buf->time = atoi(tok); + break; + case 4: + fstrcpy(buf->user, tok); + break; + case 5: + fstrcpy(buf->file, tok); + break; + } + toknum++; + } + + return True; +} + +#endif /* DEVELOPER */ + /**************************************************************************** parse a lpq line. Choose printing style ****************************************************************************/ @@ -976,6 +1021,12 @@ BOOL parse_lpq_entry(int snum,char *line, case PRINT_LPROS2: ret = parse_lpq_os2(line,buf,first); break; +#ifdef DEVELOPER + case PRINT_VLP: + case PRINT_TEST: + ret = parse_lpq_vlp(line,buf,first); + break; +#endif /* DEVELOPER */ default: ret = parse_lpq_bsd(line,buf,first); break; -- cgit From 524619561a776161e4fa0d82f1de0666e8dac553 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Mar 2001 03:16:05 +0000 Subject: Patch from itegem to handle LPRng v3.16 and above. Jeremy (This used to be commit 40bccf26dbdb88c639d272d511bfce510a43de2a) --- source3/printing/lpq_parse.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index f6bf7f06df..a143709570 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -183,20 +183,39 @@ the lpq output. The lpq time looks like "23:15:07" June 30, 1998. Modified to work with the re-written parse_lpq_lprng routine. + + Dec 17,1999 +Modified to work with lprng 3.16 +With lprng 3.16 The lpq time looks like + "23:15:07" + "23:15:07.100" + "1999-12-16-23:15:07" + "1999-12-16-23:15:07.100" + */ static time_t LPRng_time(char *time_string) { - time_t jobtime; - struct tm *t; - - jobtime = time(NULL); /* default case: take current time */ - t = localtime(&jobtime); - t->tm_hour = atoi(time_string); - t->tm_min = atoi(time_string+3); - t->tm_sec = atoi(time_string+6); - jobtime = mktime(t); - - return jobtime; + time_t jobtime; + struct tm t; + + jobtime = time(NULL); /* default case: take current time */ + t = *localtime(&jobtime); + + if ( atoi(time_string) < 24 ){ + t.tm_hour = atoi(time_string); + t.tm_min = atoi(time_string+3); + t.tm_sec = atoi(time_string+6); + } else { + t.tm_year = atoi(time_string)-1900; + t.tm_mon = atoi(time_string+5)-1; + t.tm_mday = atoi(time_string+8); + t.tm_hour = atoi(time_string+11); + t.tm_min = atoi(time_string+14); + t.tm_sec = atoi(time_string+17); + } + jobtime = mktime(&t); + + return jobtime; } -- cgit From 527e824293ee934ca5da0ef5424efe5ab7757248 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:36:09 +0000 Subject: strchr and strrchr are macros when compiling with optimisation in gcc, so we can't redefine them. damn. (This used to be commit c41fc06376d1a2b83690612304e85010b5e5f3cf) --- source3/printing/lpq_parse.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index a143709570..90d8499595 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -277,7 +277,7 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) * for the current user on the taskbar. Plop in a null. */ - if ((cptr = strchr(buf->user,'@')) != NULL) { + if ((cptr = strchr_m(buf->user,'@')) != NULL) { *cptr = '\0'; } @@ -342,13 +342,13 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) return(False); buf->size = atoi(tok[4]) * 1024; /* if the fname contains a space then use STDIN */ - if (strchr(tok[2],' ')) + if (strchr_m(tok[2],' ')) fstrcpy(tok[2],"STDIN"); /* only take the last part of the filename */ { fstring tmp; - char *p = strrchr(tok[2],'/'); + char *p = strrchr_m(tok[2],'/'); if (p) { fstrcpy(tmp,p+1); @@ -376,13 +376,13 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) return(False); buf->size = atoi(tok[8]) * 1024; /* if the fname contains a space then use STDIN */ - if (strchr(tok[4],' ')) + if (strchr_m(tok[4],' ')) fstrcpy(tok[4],"STDIN"); /* only take the last part of the filename */ { fstring tmp; - char *p = strrchr(tok[4],'/'); + char *p = strrchr_m(tok[4],'/'); if (p) { fstrcpy(tmp,p+1); @@ -453,7 +453,7 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) if (!isdigit((int)*tok[1])) return(False); /* if the fname contains a space then use STDIN */ - if (strchr(tok[0],' ')) + if (strchr_m(tok[0],' ')) fstrcpy(tok[0],"STDIN"); buf->size = atoi(tok[1]); @@ -564,7 +564,7 @@ static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first) return(False); /* if the user contains a ! then trim the first part of it */ - if ((p=strchr(tok[2],'!'))) { + if ((p=strchr_m(tok[2],'!'))) { fstring tmp; fstrcpy(tmp,p+1); fstrcpy(tok[2],tmp); @@ -627,7 +627,7 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) /* only take the last part of the filename */ { fstring tmp; - char *p = strrchr(tok[6],'/'); + char *p = strrchr_m(tok[6],'/'); if (p) { fstrcpy(tmp,p+1); @@ -685,13 +685,13 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) return(False); /* if the fname contains a space then use STDIN */ - if (strchr(tok[6],' ')) + if (strchr_m(tok[6],' ')) fstrcpy(tok[6],"STDIN"); /* only take the last part of the filename */ { fstring tmp; - char *p = strrchr(tok[6],'/'); + char *p = strrchr_m(tok[6],'/'); if (p) { fstrcpy(tmp,p+1); @@ -703,9 +703,9 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) buf->job = atoi(tok[4]); buf->size = atoi(tok[7]); - if (strchr(tok[7],'K')) + if (strchr_m(tok[7],'K')) buf->size *= 1024; - if (strchr(tok[7],'M')) + if (strchr_m(tok[7],'M')) buf->size *= 1024*1024; buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED; @@ -841,8 +841,8 @@ static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) return(False); /* Just want the first word in the owner field - the username */ - if (strchr(parse_line.owner, ' ')) - *(strchr(parse_line.owner, ' ')) = '\0'; + if (strchr_m(parse_line.owner, ' ')) + *(strchr_m(parse_line.owner, ' ')) = '\0'; else parse_line.space1 = '\0'; @@ -1053,7 +1053,7 @@ BOOL parse_lpq_entry(int snum,char *line, /* We don't want the newline in the status message. */ { - char *p = strchr(line,'\n'); + char *p = strchr_m(line,'\n'); if (p) *p = 0; } -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/printing/lpq_parse.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 90d8499595..12f12fd33c 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -20,8 +20,6 @@ */ #include "includes.h" -extern int DEBUGLEVEL; - static char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"}; -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/printing/lpq_parse.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 12f12fd33c..ddad82e1b9 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. lpq parsing routines Copyright (C) Andrew Tridgell 2000 -- cgit From 570cdd8529cdc14cc8be4206ebd23c995d6954df Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 26 Feb 2002 23:22:02 +0000 Subject: FIXME: Use next_token rather than strtok! (This used to be commit d56b8a30c5ca55b718ad706875aa6579a48a0768) --- source3/printing/lpq_parse.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index ddad82e1b9..b513806473 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -126,6 +126,7 @@ static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first) } #endif /* OSF1 */ + /* FIXME: Use next_token rather than strtok! */ tok[0] = strtok(line2," \t"); count++; -- cgit From 65c007b583e2107f5ad1ba6733d3e578a143863e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 15 Mar 2002 08:14:10 +0000 Subject: syncing up printing code with SAMBA_2_2 (already done some merges in the reverse). * add in new printer change notify code from SAMBA_2_2 * add in se_map_standard() from 2.2 in _spoolss_open_printer_ex() * sync up the _print_queue_struct in smb.h (why did someone change the user/file names in fs_user/fs_file (or vice-versa) ? ) * sync up some cli_spoolss_XXX functions (This used to be commit 5760315c1de4033fdc22684c940f18010010924f) --- source3/printing/lpq_parse.c | 72 ++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index b513806473..13b87045cd 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -145,25 +145,25 @@ static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first) buf->size = atoi(tok[TOTALTOK]); buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED; buf->time = time(NULL); - StrnCpy(buf->user,tok[USERTOK],sizeof(buf->user)-1); - StrnCpy(buf->file,tok[FILETOK],sizeof(buf->file)-1); + StrnCpy(buf->fs_user,tok[USERTOK],sizeof(buf->fs_user)-1); + StrnCpy(buf->fs_file,tok[FILETOK],sizeof(buf->fs_file)-1); if ((FILETOK + 1) != TOTALTOK) { int bufsize; int i; - bufsize = sizeof(buf->file) - strlen(buf->file) - 1; + bufsize = sizeof(buf->fs_file) - strlen(buf->fs_file) - 1; for (i = (FILETOK + 1); i < TOTALTOK; i++) { - safe_strcat(buf->file," ",bufsize); - safe_strcat(buf->file,tok[i],bufsize - 1); - bufsize = sizeof(buf->file) - strlen(buf->file) - 1; + safe_strcat(buf->fs_file," ",bufsize); + safe_strcat(buf->fs_file,tok[i],bufsize - 1); + bufsize = sizeof(buf->fs_file) - strlen(buf->fs_file) - 1; if (bufsize <= 0) { break; } } /* Ensure null termination. */ - buf->file[sizeof(buf->file)-1] = '\0'; + buf->fs_file[sizeof(buf->fs_file)-1] = '\0'; } #ifdef PRIOTOK @@ -269,34 +269,34 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]); - StrnCpy(buf->user,tokarr[LPRNG_USERTOK],sizeof(buf->user)-1); + StrnCpy(buf->fs_user,tokarr[LPRNG_USERTOK],sizeof(buf->fs_user)-1); /* The '@hostname' prevents windows from displaying the printing icon * for the current user on the taskbar. Plop in a null. */ - if ((cptr = strchr_m(buf->user,'@')) != NULL) { + if ((cptr = strchr_m(buf->fs_user,'@')) != NULL) { *cptr = '\0'; } - StrnCpy(buf->file,tokarr[LPRNG_FILETOK],sizeof(buf->file)-1); + StrnCpy(buf->fs_file,tokarr[LPRNG_FILETOK],sizeof(buf->fs_file)-1); if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) { int bufsize; int i; - bufsize = sizeof(buf->file) - strlen(buf->file) - 1; + bufsize = sizeof(buf->fs_file) - strlen(buf->fs_file) - 1; for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) { - safe_strcat(buf->file," ",bufsize); - safe_strcat(buf->file,tokarr[i],bufsize - 1); - bufsize = sizeof(buf->file) - strlen(buf->file) - 1; + safe_strcat(buf->fs_file," ",bufsize); + safe_strcat(buf->fs_file,tokarr[i],bufsize - 1); + bufsize = sizeof(buf->fs_file) - strlen(buf->fs_file) - 1; if (bufsize <= 0) { break; } } /* Ensure null termination. */ - buf->file[sizeof(buf->file)-1] = '\0'; + buf->fs_file[sizeof(buf->fs_file)-1] = '\0'; } return(True); @@ -359,8 +359,8 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED; buf->priority = 0; buf->time = time(NULL); - StrnCpy(buf->user,tok[3],sizeof(buf->user)-1); - StrnCpy(buf->file,tok[2],sizeof(buf->file)-1); + StrnCpy(buf->fs_user,tok[3],sizeof(buf->fs_user)-1); + StrnCpy(buf->fs_file,tok[2],sizeof(buf->fs_file)-1); } else { @@ -393,8 +393,8 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED; buf->priority = 0; buf->time = time(NULL); - StrnCpy(buf->user,tok[5],sizeof(buf->user)-1); - StrnCpy(buf->file,tok[4],sizeof(buf->file)-1); + StrnCpy(buf->fs_user,tok[5],sizeof(buf->fs_user)-1); + StrnCpy(buf->fs_file,tok[4],sizeof(buf->fs_file)-1); } @@ -455,14 +455,14 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) fstrcpy(tok[0],"STDIN"); buf->size = atoi(tok[1]); - StrnCpy(buf->file,tok[0],sizeof(buf->file)-1); + StrnCpy(buf->fs_file,tok[0],sizeof(buf->fs_file)-1); /* fill things from header line */ buf->time = jobtime; buf->job = jobid; buf->status = jobstat; buf->priority = jobprio; - StrnCpy(buf->user,jobuser,sizeof(buf->user)-1); + StrnCpy(buf->fs_user,jobuser,sizeof(buf->fs_user)-1); return(True); } @@ -488,7 +488,7 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) /* the 2nd, 5th & 7th column must be integer */ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) return(False); jobid = atoi(tok[1]); - StrnCpy(jobuser,tok[2],sizeof(buf->user)-1); + StrnCpy(jobuser,tok[2],sizeof(buf->fs_user)-1); jobprio = atoi(tok[4]); /* process time */ @@ -578,8 +578,8 @@ static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first) buf->status = LPQ_QUEUED; buf->priority = 0; buf->time = EntryTime(tok, 4, count, 7); - StrnCpy(buf->user,tok[2],sizeof(buf->user)-1); - StrnCpy(buf->file,tok[2],sizeof(buf->file)-1); + StrnCpy(buf->fs_user,tok[2],sizeof(buf->fs_user)-1); + StrnCpy(buf->fs_file,tok[2],sizeof(buf->fs_file)-1); return(True); } @@ -639,8 +639,8 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED; buf->priority = 0; buf->time = time(NULL); - StrnCpy(buf->user,tok[1],sizeof(buf->user)-1); - StrnCpy(buf->file,tok[6],sizeof(buf->file)-1); + StrnCpy(buf->fs_user,tok[1],sizeof(buf->fs_user)-1); + StrnCpy(buf->fs_file,tok[6],sizeof(buf->fs_file)-1); return(True); } @@ -709,8 +709,8 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED; buf->priority = 0; buf->time = time(NULL); - StrnCpy(buf->user,tok[1],sizeof(buf->user)-1); - StrnCpy(buf->file,tok[6],sizeof(buf->file)-1); + StrnCpy(buf->fs_user,tok[1],sizeof(buf->fs_user)-1); + StrnCpy(buf->fs_file,tok[6],sizeof(buf->fs_file)-1); return(True); } @@ -766,8 +766,8 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first) buf->job = atoi(tok[0]); buf->size = atoi(tok[count+6]); buf->priority = atoi(tok[count+5]); - StrnCpy(buf->user,tok[count+7],sizeof(buf->user)-1); - StrnCpy(buf->file,tok[count+8],sizeof(buf->file)-1); + StrnCpy(buf->fs_user,tok[count+7],sizeof(buf->fs_user)-1); + StrnCpy(buf->fs_file,tok[count+8],sizeof(buf->fs_file)-1); buf->time = time(NULL); /* default case: take current time */ { time_t jobtime; @@ -863,8 +863,8 @@ static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) buf->priority = 0; buf->size = atoi(parse_line.size); buf->time = time(NULL); - StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1); - StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1); + StrnCpy(buf->fs_user, parse_line.owner, sizeof(buf->fs_user)-1); + StrnCpy(buf->fs_file, parse_line.jobname, sizeof(buf->fs_file)-1); if (strequal(parse_line.status, LPRNT_PRINTING)) buf->status = LPQ_PRINTING; else if (strequal(parse_line.status, LPRNT_PAUSED)) @@ -922,7 +922,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) /* Get the job name */ parse_line.space2[0] = '\0'; trim_string(parse_line.jobname, NULL, " "); - StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1); + StrnCpy(buf->fs_file, parse_line.jobname, sizeof(buf->fs_file)-1); buf->priority = 0; buf->size = atoi(parse_line.size); @@ -940,7 +940,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) !strequal(parse_line.status, LPROS2_WAITING)) return(False); - StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1); + StrnCpy(buf->fs_user, parse_line.owner, sizeof(buf->fs_user)-1); if (strequal(parse_line.status, LPROS2_PRINTING)) buf->status = LPQ_PRINTING; else if (strequal(parse_line.status, LPROS2_PAUSED)) @@ -986,10 +986,10 @@ static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) buf->time = atoi(tok); break; case 4: - fstrcpy(buf->user, tok); + fstrcpy(buf->fs_user, tok); break; case 5: - fstrcpy(buf->file, tok); + fstrcpy(buf->fs_file, tok); break; } toknum++; -- cgit From 2699f9b9df3f974a34e40761141361e997638b6c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 22 Apr 2002 18:48:45 +0000 Subject: printing merge from HEAD (This used to be commit d3aed37dd87d425f51bcdc4e5151f0b0fe8f9c6b) --- source3/printing/lpq_parse.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 13b87045cd..9d8b1cc2aa 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -149,21 +149,17 @@ static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first) StrnCpy(buf->fs_file,tok[FILETOK],sizeof(buf->fs_file)-1); if ((FILETOK + 1) != TOTALTOK) { - int bufsize; int i; - bufsize = sizeof(buf->fs_file) - strlen(buf->fs_file) - 1; - for (i = (FILETOK + 1); i < TOTALTOK; i++) { - safe_strcat(buf->fs_file," ",bufsize); - safe_strcat(buf->fs_file,tok[i],bufsize - 1); - bufsize = sizeof(buf->fs_file) - strlen(buf->fs_file) - 1; - if (bufsize <= 0) { - break; - } + /* FIXME: Using fstrcat rather than other means is a bit + * inefficient; this might be a problem for enormous queues with + * many fields. */ + fstrcat(buf->fs_file, " "); + fstrcat(buf->fs_file, tok[i]); } /* Ensure null termination. */ - buf->fs_file[sizeof(buf->fs_file)-1] = '\0'; + fstrterminate(buf->fs_file); } #ifdef PRIOTOK @@ -282,21 +278,17 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) StrnCpy(buf->fs_file,tokarr[LPRNG_FILETOK],sizeof(buf->fs_file)-1); if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) { - int bufsize; int i; - bufsize = sizeof(buf->fs_file) - strlen(buf->fs_file) - 1; - for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) { - safe_strcat(buf->fs_file," ",bufsize); - safe_strcat(buf->fs_file,tokarr[i],bufsize - 1); - bufsize = sizeof(buf->fs_file) - strlen(buf->fs_file) - 1; - if (bufsize <= 0) { - break; - } + /* FIXME: Using fstrcat rather than other means is a bit + * inefficient; this might be a problem for enormous queues with + * many fields. */ + fstrcat(buf->fs_file, " "); + fstrcat(buf->fs_file, tokarr[i]); } /* Ensure null termination. */ - buf->fs_file[sizeof(buf->fs_file)-1] = '\0'; + fstrterminate(buf->fs_file); } return(True); -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/printing/lpq_parse.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 9d8b1cc2aa..1307cdb3f8 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -255,6 +255,8 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) if (strequal(tokarr[LPRNG_RANKTOK],"active")) { buf->status = LPQ_PRINTING; + } else if (strequal(tokarr[LPRNG_RANKTOK],"done")) { + buf->status = LPQ_PRINTED; } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) { buf->status = LPQ_QUEUED; } else { @@ -314,7 +316,7 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) int count=0; /* handle the case of "(standard input)" as a filename */ - pstring_sub(line,"standard input","STDIN"); + string_sub(line,"standard input","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); @@ -431,7 +433,7 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) } if (!header_line_ok) return (False); /* incorrect header line */ /* handle the case of "(standard input)" as a filename */ - pstring_sub(line,"standard input","STDIN"); + string_sub(line,"standard input","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); @@ -469,7 +471,7 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) else if (base_prio) base_prio_reset=False; /* handle the dash in the job id */ - pstring_sub(line,"-"," "); + string_sub(line,"-"," ",0); for (count=0; count<12 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; @@ -593,14 +595,14 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) DEBUG(4,("antes [%s]\n", line)); /* handle the case of "-- standard input --" as a filename */ - pstring_sub(line,"standard input","STDIN"); + string_sub(line,"standard input","STDIN",0); DEBUG(4,("despues [%s]\n", line)); all_string_sub(line,"-- ","\"",0); all_string_sub(line," --","\"",0); DEBUG(4,("despues 1 [%s]\n", line)); - pstring_sub(line,"[job #",""); - pstring_sub(line,"]",""); + string_sub(line,"[job #","",0); + string_sub(line,"]","",0); DEBUG(4,("despues 2 [%s]\n", line)); @@ -656,7 +658,7 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) int count=0; /* handle the case of "(standard input)" as a filename */ - pstring_sub(line,"stdin","STDIN"); + string_sub(line,"stdin","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); @@ -726,7 +728,7 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first) int count=0; /* mung all the ":"s to spaces*/ - pstring_sub(line,":"," "); + string_sub(line,":"," ",0); for (count=0; count<10 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; -- cgit From 2f194322d419350f35a48dff750066894d68eccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Nov 2002 23:20:50 +0000 Subject: Removed global_myworkgroup, global_myname, global_myscope. Added liberal dashes of const. This is a rather large check-in, some things may break. It does compile though :-). Jeremy. (This used to be commit f755711df8f74f9b8e8c1a2b0d07d02a931eeb89) --- source3/printing/lpq_parse.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 1307cdb3f8..59a844689c 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -232,12 +232,11 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */ fstring tokarr[LPRNG_MAXTOK]; - char *cptr; + const char *cptr; + char *ptr; int num_tok = 0; - pstring line2; - pstrcpy(line2,line); - cptr = line2; + cptr = line; while(next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring)) && (num_tok < LPRNG_MAXTOK)) num_tok++; @@ -273,8 +272,8 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) * for the current user on the taskbar. Plop in a null. */ - if ((cptr = strchr_m(buf->fs_user,'@')) != NULL) { - *cptr = '\0'; + if ((ptr = strchr_m(buf->fs_user,'@')) != NULL) { + *ptr = '\0'; } StrnCpy(buf->fs_file,tokarr[LPRNG_FILETOK],sizeof(buf->fs_file)-1); @@ -314,6 +313,7 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) { fstring tok[11]; int count=0; + const char *cline = line; /* handle the case of "(standard input)" as a filename */ string_sub(line,"standard input","STDIN",0); @@ -322,7 +322,7 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) for (count=0; count<10 && - next_token(&line,tok[count],NULL, sizeof(tok[count])); + next_token(&cline,tok[count],NULL, sizeof(tok[count])); count++) ; /* we must get 6 tokens */ @@ -406,7 +406,7 @@ ljplus-2153 user priority 0 Jan 19 08:14 on ljplus ljplus-2154 user priority 0 Jan 19 08:14 from client (standard input) 7551 bytes ****************************************************************************/ -static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) +static BOOL parse_lpq_hpux(char *line, print_queue_struct *buf, BOOL first) { /* must read two lines to process, therefore keep some values static */ static BOOL header_line_ok=False, base_prio_reset=False; @@ -418,9 +418,9 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) /* to store minimum priority to print, lpstat command should be invoked with -p option first, to work */ static int base_prio; - int count; char htab = '\011'; + const char *cline = line; fstring tok[12]; /* If a line begins with a horizontal TAB, it is a subline type */ @@ -437,7 +437,7 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); - for (count=0; count<2 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + for (count=0; count<2 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; /* we must get 2 tokens */ if (count < 2) return(False); @@ -473,7 +473,7 @@ static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first) /* handle the dash in the job id */ string_sub(line,"-"," ",0); - for (count=0; count<12 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + for (count=0; count<12 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; /* we must get 8 tokens */ if (count < 8) return(False); @@ -519,6 +519,7 @@ static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first) fstring tok[9]; int count=0; char *p; + const char *cline = line; /* * Handle the dash in the job id, but make sure that we skip over @@ -542,7 +543,7 @@ static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first) if((p >= line) && (*p == '-')) *p = ' '; - for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) + for (count=0; count<9 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; /* we must get 7 tokens */ @@ -591,6 +592,7 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) { fstring tok[7]; int count=0; + const char *cline; DEBUG(4,("antes [%s]\n", line)); @@ -605,9 +607,7 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) string_sub(line,"]","",0); DEBUG(4,("despues 2 [%s]\n", line)); - - - for (count=0; count<7 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + for (count=0; count<7 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; /* we must get 7 tokens */ if (count < 7) @@ -656,13 +656,14 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) { fstring tok[11]; int count=0; + const char *cline = line; /* handle the case of "(standard input)" as a filename */ string_sub(line,"stdin","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); - for (count=0; count<11 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + for (count=0; count<11 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; /* we must get 11 tokens */ if (count < 11) @@ -726,11 +727,12 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first) { fstring tok[10]; int count=0; + const char *cline = line; /* mung all the ":"s to spaces*/ string_sub(line,":"," ",0); - for (count=0; count<10 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ; + for (count=0; count<10 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; /* we must get 9 tokens */ if (count < 9) @@ -958,6 +960,7 @@ static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) { int toknum = 0; fstring tok; + const char *cline = line; /* First line is printer status */ @@ -965,7 +968,7 @@ static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) /* Parse a print job entry */ - while(next_token(&line, tok, NULL, sizeof(fstring))) { + while(next_token(&cline, tok, NULL, sizeof(fstring))) { switch (toknum) { case 0: buf->job = atoi(tok); @@ -997,6 +1000,7 @@ static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) /**************************************************************************** parse a lpq line. Choose printing style ****************************************************************************/ + BOOL parse_lpq_entry(int snum,char *line, print_queue_struct *buf, print_status_struct *status,BOOL first) -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/printing/lpq_parse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 59a844689c..4b91b8ac9a 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -20,7 +20,7 @@ #include "includes.h" -static char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", +static const char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"}; @@ -947,9 +947,9 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) return(True); } -static char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL }; -static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL }; -static char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL }; +static const char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL }; +static const char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL }; +static const char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL }; #ifdef DEVELOPER -- cgit From 6626fef5d45ac5a36c5fcdac6173ea8f82ee2e02 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 5 Mar 2003 00:54:47 +0000 Subject: Fix for little-used lpq parser. Jeremy. (This used to be commit 75b36459ab1797bdff98ed91d7870bd48adebb54) --- source3/printing/lpq_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 4b91b8ac9a..0b4ce4b4ca 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -592,7 +592,7 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) { fstring tok[7]; int count=0; - const char *cline; + const char *cline = line; DEBUG(4,("antes [%s]\n", line)); -- cgit From 2a3a9f0bf43c3bf99a71f7296bb5ff6199893fea Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 23 Apr 2003 13:27:35 +0000 Subject: Merge the 'safe' parts of my StrnCpy patch - many of the users really wanted a pstrcpy/fstrcpy or at most a safe_strcpy(). These have the advantage of being compiler-verifiable. Get these out of the way, along with a rewrite of 'get_short_archi' in the spoolss client and server. (This pushes around const string pointers, rather than copied strings). Andrew Bartlett (This used to be commit 32fb801ddc035e8971e9911ed4b6e51892e9d1cc) --- source3/printing/lpq_parse.c | 64 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 0b4ce4b4ca..f7f7affc12 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -145,8 +145,8 @@ static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first) buf->size = atoi(tok[TOTALTOK]); buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED; buf->time = time(NULL); - StrnCpy(buf->fs_user,tok[USERTOK],sizeof(buf->fs_user)-1); - StrnCpy(buf->fs_file,tok[FILETOK],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_user,tok[USERTOK]); + fstrcpy(buf->fs_file,tok[FILETOK]); if ((FILETOK + 1) != TOTALTOK) { int i; @@ -266,7 +266,7 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]); - StrnCpy(buf->fs_user,tokarr[LPRNG_USERTOK],sizeof(buf->fs_user)-1); + fstrcpy(buf->fs_user,tokarr[LPRNG_USERTOK]); /* The '@hostname' prevents windows from displaying the printing icon * for the current user on the taskbar. Plop in a null. @@ -276,7 +276,7 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) *ptr = '\0'; } - StrnCpy(buf->fs_file,tokarr[LPRNG_FILETOK],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_file,tokarr[LPRNG_FILETOK]); if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) { int i; @@ -353,8 +353,8 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED; buf->priority = 0; buf->time = time(NULL); - StrnCpy(buf->fs_user,tok[3],sizeof(buf->fs_user)-1); - StrnCpy(buf->fs_file,tok[2],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_user,tok[3]); + fstrcpy(buf->fs_file,tok[2]); } else { @@ -387,8 +387,8 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED; buf->priority = 0; buf->time = time(NULL); - StrnCpy(buf->fs_user,tok[5],sizeof(buf->fs_user)-1); - StrnCpy(buf->fs_file,tok[4],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_user,tok[5]); + fstrcpy(buf->fs_file,tok[4]); } @@ -449,14 +449,14 @@ static BOOL parse_lpq_hpux(char *line, print_queue_struct *buf, BOOL first) fstrcpy(tok[0],"STDIN"); buf->size = atoi(tok[1]); - StrnCpy(buf->fs_file,tok[0],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_file,tok[0]); /* fill things from header line */ buf->time = jobtime; buf->job = jobid; buf->status = jobstat; buf->priority = jobprio; - StrnCpy(buf->fs_user,jobuser,sizeof(buf->fs_user)-1); + fstrcpy(buf->fs_user,jobuser); return(True); } @@ -482,7 +482,7 @@ static BOOL parse_lpq_hpux(char *line, print_queue_struct *buf, BOOL first) /* the 2nd, 5th & 7th column must be integer */ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) return(False); jobid = atoi(tok[1]); - StrnCpy(jobuser,tok[2],sizeof(buf->fs_user)-1); + fstrcpy(jobuser,tok[2]); jobprio = atoi(tok[4]); /* process time */ @@ -573,8 +573,8 @@ static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first) buf->status = LPQ_QUEUED; buf->priority = 0; buf->time = EntryTime(tok, 4, count, 7); - StrnCpy(buf->fs_user,tok[2],sizeof(buf->fs_user)-1); - StrnCpy(buf->fs_file,tok[2],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_user,tok[2]); + fstrcpy(buf->fs_file,tok[2]); return(True); } @@ -633,8 +633,8 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED; buf->priority = 0; buf->time = time(NULL); - StrnCpy(buf->fs_user,tok[1],sizeof(buf->fs_user)-1); - StrnCpy(buf->fs_file,tok[6],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_user,tok[1]); + fstrcpy(buf->fs_file,tok[6]); return(True); } @@ -704,8 +704,8 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED; buf->priority = 0; buf->time = time(NULL); - StrnCpy(buf->fs_user,tok[1],sizeof(buf->fs_user)-1); - StrnCpy(buf->fs_file,tok[6],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_user,tok[1]); + fstrcpy(buf->fs_file,tok[6]); return(True); } @@ -762,8 +762,8 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first) buf->job = atoi(tok[0]); buf->size = atoi(tok[count+6]); buf->priority = atoi(tok[count+5]); - StrnCpy(buf->fs_user,tok[count+7],sizeof(buf->fs_user)-1); - StrnCpy(buf->fs_file,tok[count+8],sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_user,tok[count+7]); + fstrcpy(buf->fs_file,tok[count+8]); buf->time = time(NULL); /* default case: take current time */ { time_t jobtime; @@ -859,8 +859,8 @@ static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) buf->priority = 0; buf->size = atoi(parse_line.size); buf->time = time(NULL); - StrnCpy(buf->fs_user, parse_line.owner, sizeof(buf->fs_user)-1); - StrnCpy(buf->fs_file, parse_line.jobname, sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_user, parse_line.owner); + fstrcpy(buf->fs_file, parse_line.jobname); if (strequal(parse_line.status, LPRNT_PRINTING)) buf->status = LPQ_PRINTING; else if (strequal(parse_line.status, LPRNT_PAUSED)) @@ -918,7 +918,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) /* Get the job name */ parse_line.space2[0] = '\0'; trim_string(parse_line.jobname, NULL, " "); - StrnCpy(buf->fs_file, parse_line.jobname, sizeof(buf->fs_file)-1); + fstrcpy(buf->fs_file, parse_line.jobname); buf->priority = 0; buf->size = atoi(parse_line.size); @@ -936,7 +936,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) !strequal(parse_line.status, LPROS2_WAITING)) return(False); - StrnCpy(buf->fs_user, parse_line.owner, sizeof(buf->fs_user)-1); + fstrcpy(buf->fs_user, parse_line.owner); if (strequal(parse_line.status, LPROS2_PRINTING)) buf->status = LPQ_PRINTING; else if (strequal(parse_line.status, LPROS2_PAUSED)) @@ -1073,23 +1073,23 @@ BOOL parse_lpq_entry(int snum,char *line, case LPSTAT_OK: for (i=0; stat0_strings[i]; i++) if (strstr(line,stat0_strings[i])) { - StrnCpy(status->message,line,sizeof(status->message)-1); - status->status=LPSTAT_OK; - return ret; + fstrcpy(status->message,line); + status->status=LPSTAT_OK; + return ret; } case LPSTAT_STOPPED: for (i=0; stat1_strings[i]; i++) if (strstr(line,stat1_strings[i])) { - StrnCpy(status->message,line,sizeof(status->message)-1); - status->status=LPSTAT_STOPPED; - return ret; + fstrcpy(status->message,line); + status->status=LPSTAT_STOPPED; + return ret; } case LPSTAT_ERROR: for (i=0; stat2_strings[i]; i++) if (strstr(line,stat2_strings[i])) { - StrnCpy(status->message,line,sizeof(status->message)-1); - status->status=LPSTAT_ERROR; - return ret; + fstrcpy(status->message,line); + status->status=LPSTAT_ERROR; + return ret; } break; } -- cgit From 6760896739914c292a056a9de5ed83fb111b3a66 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 29 Apr 2003 05:06:18 +0000 Subject: removing printing = SOFTQ since no one knows what it is (This used to be commit 283953472229952f7f2613a207515580cd0919c3) --- source3/printing/lpq_parse.c | 83 -------------------------------------------- 1 file changed, 83 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index f7f7affc12..b2f45ad366 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -709,86 +709,6 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) return(True); } -/**************************************************************************** -parse a qstat line - -here is an example of "qstat -l -d qms" output under softq - -Queue qms: 2 jobs; daemon active (313); enabled; accepting; - job-ID submission-time pri size owner title -205980: H 98/03/09 13:04:05 0 15733 stephenf chap1.ps -206086:> 98/03/12 17:24:40 0 659 chris - -206087: 98/03/12 17:24:45 0 4876 chris - -Total: 21268 bytes in queue - - -****************************************************************************/ -static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first) -{ - fstring tok[10]; - int count=0; - const char *cline = line; - - /* mung all the ":"s to spaces*/ - string_sub(line,":"," ",0); - - for (count=0; count<10 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; - - /* we must get 9 tokens */ - if (count < 9) - return(False); - - /* the 1st and 7th columns must be integer */ - if (!isdigit((int)*tok[0]) || !isdigit((int)*tok[6])) return(False); - /* if the 2nd column is either '>' or 'H' then the 7th and 8th must be - * integer, else it's the 6th and 7th that must be - */ - if (*tok[1] == 'H' || *tok[1] == '>') - { - if (!isdigit((int)*tok[7])) - return(False); - buf->status = *tok[1] == '>' ? LPQ_PRINTING : LPQ_PAUSED; - count = 1; - } - else - { - if (!isdigit((int)*tok[5])) - return(False); - buf->status = LPQ_QUEUED; - count = 0; - } - - - buf->job = atoi(tok[0]); - buf->size = atoi(tok[count+6]); - buf->priority = atoi(tok[count+5]); - fstrcpy(buf->fs_user,tok[count+7]); - fstrcpy(buf->fs_file,tok[count+8]); - buf->time = time(NULL); /* default case: take current time */ - { - time_t jobtime; - struct tm *t; - - t = localtime(&buf->time); - t->tm_mday = atoi(tok[count+2]+6); - t->tm_mon = atoi(tok[count+2]+3); - switch (*tok[count+2]) - { - case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]); break; - default: t->tm_year = atoi(tok[count+2]); break; - } - - t->tm_hour = atoi(tok[count+3]); - t->tm_min = atoi(tok[count+4]); - t->tm_sec = atoi(tok[count+5]); - jobtime = mktime(t); - if (jobtime != (time_t)-1) - buf->time = jobtime; - } - - return(True); -} - /******************************************************************* parse lpq on an NT system @@ -1027,9 +947,6 @@ BOOL parse_lpq_entry(int snum,char *line, case PRINT_PLP: ret = parse_lpq_plp(line,buf,first); break; - case PRINT_SOFTQ: - ret = parse_lpq_softq(line,buf,first); - break; case PRINT_LPRNT: ret = parse_lpq_nt(line,buf,first); break; -- cgit From ce72beb2b558d86fb49063c6b1fa00e07952ce56 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Jul 2003 19:11:31 +0000 Subject: Removed strupper/strlower macros that automatically map to strupper_m/strlower_m. I really want people to think about when they're using multibyte strings. Jeremy. (This used to be commit ff222716a08af65d26ad842ce4c2841cc6540959) --- source3/printing/lpq_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index b2f45ad366..0acca67b70 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -984,7 +984,7 @@ BOOL parse_lpq_entry(int snum,char *line, printer status line: handle them so that most severe condition is shown */ int i; - strlower(line); + strlower_m(line); switch (status->status) { case LPSTAT_OK: -- cgit From 94f59f54921174fc156fade575ca114d331b1bd8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Sep 2003 19:59:55 +0000 Subject: More tuning from cachegrind. Change most trim_string() calls to trim_char(0, as that's what they do. Fix string_replace() to fast-path ascii. Jeremy. (This used to be commit f35e9a8b909d3c74be47083ccc4a4e91a14938db) --- source3/printing/lpq_parse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 0acca67b70..111617e3ae 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -766,14 +766,14 @@ static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) /* Make sure the status is valid */ parse_line.space2 = '\0'; - trim_string(parse_line.status, NULL, " "); + trim_char(parse_line.status, '\0', ' '); if (!strequal(parse_line.status, LPRNT_PRINTING) && !strequal(parse_line.status, LPRNT_PAUSED) && !strequal(parse_line.status, LPRNT_WAITING)) return(False); parse_line.space3 = '\0'; - trim_string(parse_line.jobname, NULL, " "); + trim_char(parse_line.jobname, '\0', ' '); buf->job = atoi(parse_line.jobid); buf->priority = 0; @@ -837,7 +837,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) /* Get the job name */ parse_line.space2[0] = '\0'; - trim_string(parse_line.jobname, NULL, " "); + trim_char(parse_line.jobname, '\0', ' '); fstrcpy(buf->fs_file, parse_line.jobname); buf->priority = 0; @@ -850,7 +850,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) /* Make sure we have a valid status */ parse_line.space4[0] = '\0'; - trim_string(parse_line.status, NULL, " "); + trim_char(parse_line.status, '\0', ' '); if (!strequal(parse_line.status, LPROS2_PRINTING) && !strequal(parse_line.status, LPROS2_PAUSED) && !strequal(parse_line.status, LPROS2_WAITING)) -- cgit From c9b7cbbfa572512cd0348817965b99fd1df01285 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 9 Mar 2004 00:17:14 +0000 Subject: Added strstr_m() function. Use in all places where we might run into mb (should fix the mb service name problem, can't remember the bugid). Jeremy. (This used to be commit 94a272b9a881ec0004c5da2a7242b0a818da5630) --- source3/printing/lpq_parse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 111617e3ae..b7e41964f1 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -989,21 +989,21 @@ BOOL parse_lpq_entry(int snum,char *line, switch (status->status) { case LPSTAT_OK: for (i=0; stat0_strings[i]; i++) - if (strstr(line,stat0_strings[i])) { + if (strstr_m(line,stat0_strings[i])) { fstrcpy(status->message,line); status->status=LPSTAT_OK; return ret; } case LPSTAT_STOPPED: for (i=0; stat1_strings[i]; i++) - if (strstr(line,stat1_strings[i])) { + if (strstr_m(line,stat1_strings[i])) { fstrcpy(status->message,line); status->status=LPSTAT_STOPPED; return ret; } case LPSTAT_ERROR: for (i=0; stat2_strings[i]; i++) - if (strstr(line,stat2_strings[i])) { + if (strstr_m(line,stat2_strings[i])) { fstrcpy(status->message,line); status->status=LPSTAT_ERROR; return ret; -- cgit From 293136c04b7eb5293ef18273e13fca00c85bb5f0 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 19 Oct 2004 17:05:01 +0000 Subject: r3067: patch based on volker's initial work in trunk that fixes the queu update problem when using the background daemon (This used to be commit de7af09e727e744aa27af85ef7c0f73ed5c1550a) --- source3/printing/lpq_parse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index b7e41964f1..68c06ade41 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -921,13 +921,13 @@ static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) parse a lpq line. Choose printing style ****************************************************************************/ -BOOL parse_lpq_entry(int snum,char *line, +BOOL parse_lpq_entry(enum printing_types printing_type,char *line, print_queue_struct *buf, print_status_struct *status,BOOL first) { BOOL ret; - switch (lp_printing(snum)) + switch (printing_type) { case PRINT_SYSV: ret = parse_lpq_sysv(line,buf,first); @@ -971,7 +971,7 @@ BOOL parse_lpq_entry(int snum,char *line, } /* in the LPRNG case, we skip lines starting by a space.*/ - if (line && !ret && (lp_printing(snum)==PRINT_LPRNG) ) + if (line && !ret && (printing_type==PRINT_LPRNG) ) { if (line[0]==' ') return ret; -- cgit From 3527b5cc25d4177e860745b16409984610ed11df Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 8 Mar 2006 01:18:18 +0000 Subject: r14003: Clarify code that lead to Coverity report #13. Not a bug, but better to remove false positives. Jeremy. (This used to be commit f9a75d76546bc4618736f0d48646e77d7572db25) --- source3/printing/lpq_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 68c06ade41..7e81b5187c 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -971,7 +971,7 @@ BOOL parse_lpq_entry(enum printing_types printing_type,char *line, } /* in the LPRNG case, we skip lines starting by a space.*/ - if (line && !ret && (printing_type==PRINT_LPRNG) ) + if (!ret && (printing_type==PRINT_LPRNG) ) { if (line[0]==' ') return ret; -- cgit From a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Jun 2006 21:36:49 +0000 Subject: r16230: Fix Klocwork #861 and others. localtime and asctime can return NULL. Ensure we check all returns correctly. Jeremy. (This used to be commit 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc) --- source3/printing/lpq_parse.c | 119 ++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 52 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 7e81b5187c..324d0fa90d 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -25,50 +25,62 @@ static const char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", /******************************************************************* -process time fields + Process time fields ********************************************************************/ + static time_t EntryTime(fstring tok[], int ptr, int count, int minimum) { - time_t jobtime,jobtime1; - - jobtime = time(NULL); /* default case: take current time */ - if (count >= minimum) { - struct tm *t; - int i, day, hour, min, sec; - char *c; - - for (i=0; i<13; i++) if (!strncmp(tok[ptr], Months[i],3)) break; /* Find month */ - if (i<12) { - t = localtime(&jobtime); - day = atoi(tok[ptr+1]); - c=(char *)(tok[ptr+2]); - *(c+2)=0; - hour = atoi(c); - *(c+5)=0; - min = atoi(c+3); - if(*(c+6) != 0)sec = atoi(c+6); - else sec=0; - - if ((t->tm_mon < i)|| - ((t->tm_mon == i)&& - ((t->tm_mday < day)|| - ((t->tm_mday == day)&& - (t->tm_hour*60+t->tm_min < hour*60+min))))) - t->tm_year--; /* last year's print job */ - - t->tm_mon = i; - t->tm_mday = day; - t->tm_hour = hour; - t->tm_min = min; - t->tm_sec = sec; - jobtime1 = mktime(t); - if (jobtime1 != (time_t)-1) - jobtime = jobtime1; - } - } - return jobtime; -} + time_t jobtime,jobtime1; + + jobtime = time(NULL); /* default case: take current time */ + if (count >= minimum) { + struct tm *t; + int i, day, hour, min, sec; + char *c; + + for (i=0; i<13; i++) { + if (!strncmp(tok[ptr], Months[i],3)) { + break; /* Find month */ + } + } + if (i<12) { + t = localtime(&jobtime); + if (!t) { + return (time_t)-1; + } + day = atoi(tok[ptr+1]); + c=(char *)(tok[ptr+2]); + *(c+2)=0; + hour = atoi(c); + *(c+5)=0; + min = atoi(c+3); + if(*(c+6) != 0) { + sec = atoi(c+6); + } else { + sec=0; + } + + if ((t->tm_mon < i)|| ((t->tm_mon == i)&& + ((t->tm_mday < day)|| + ((t->tm_mday == day)&& + (t->tm_hour*60+t->tm_min < hour*60+min))))) { + t->tm_year--; /* last year's print job */ + } + + t->tm_mon = i; + t->tm_mday = day; + t->tm_hour = hour; + t->tm_min = min; + t->tm_sec = sec; + jobtime1 = mktime(t); + if (jobtime1 != (time_t)-1) { + jobtime = jobtime1; + } + } + } + return jobtime; +} /**************************************************************************** parse a lpq line @@ -190,24 +202,27 @@ With lprng 3.16 The lpq time looks like static time_t LPRng_time(char *time_string) { time_t jobtime; - struct tm t; + struct tm *t; jobtime = time(NULL); /* default case: take current time */ - t = *localtime(&jobtime); + t = localtime(&jobtime); + if (!t) { + return (time_t)-1; + } if ( atoi(time_string) < 24 ){ - t.tm_hour = atoi(time_string); - t.tm_min = atoi(time_string+3); - t.tm_sec = atoi(time_string+6); + t->tm_hour = atoi(time_string); + t->tm_min = atoi(time_string+3); + t->tm_sec = atoi(time_string+6); } else { - t.tm_year = atoi(time_string)-1900; - t.tm_mon = atoi(time_string+5)-1; - t.tm_mday = atoi(time_string+8); - t.tm_hour = atoi(time_string+11); - t.tm_min = atoi(time_string+14); - t.tm_sec = atoi(time_string+17); + t->tm_year = atoi(time_string)-1900; + t->tm_mon = atoi(time_string+5)-1; + t->tm_mday = atoi(time_string+8); + t->tm_hour = atoi(time_string+11); + t->tm_min = atoi(time_string+14); + t->tm_sec = atoi(time_string+17); } - jobtime = mktime(&t); + jobtime = mktime(t); return jobtime; } -- cgit From 8f2d6e4852e13769237f701564f5764361b53603 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Jun 2006 05:20:21 +0000 Subject: r16243: Fix Klocwork bugs #581 and #706, ensure we check the end of array first in the loop. Reformat to modern standards. Jeremy. (This used to be commit 66275bd3bc56e67759dbabe77cb2ba019c6f4887) --- source3/printing/lpq_parse.c | 1283 ++++++++++++++++++++++-------------------- 1 file changed, 667 insertions(+), 616 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 324d0fa90d..100585637a 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -102,6 +102,7 @@ Rank Pri Owner Job Files Total Size Modified to handle file names with spaces, like the parse_lpq_lprng code further below. ****************************************************************************/ + static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first) { #ifdef OSF1 @@ -123,63 +124,67 @@ static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first) #define MAXTOK 128 #endif /* OSF1 */ - char *tok[MAXTOK]; - int count = 0; - pstring line2; + char *tok[MAXTOK]; + int count = 0; + pstring line2; - pstrcpy(line2,line); + pstrcpy(line2,line); #ifdef OSF1 - { - size_t length; - length = strlen(line2); - if (line2[length-3] == ':') - return(False); - } + { + size_t length; + length = strlen(line2); + if (line2[length-3] == ':') { + return False; + } + } #endif /* OSF1 */ - /* FIXME: Use next_token rather than strtok! */ - tok[0] = strtok(line2," \t"); - count++; - - while (((tok[count] = strtok(NULL," \t")) != NULL) && (count < MAXTOK)) { - count++; - } - - /* we must get at least NTOK tokens */ - if (count < NTOK) - return(False); - - /* the Job and Total columns must be integer */ - if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) return(False); - - buf->job = atoi(tok[JOBTOK]); - buf->size = atoi(tok[TOTALTOK]); - buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED; - buf->time = time(NULL); - fstrcpy(buf->fs_user,tok[USERTOK]); - fstrcpy(buf->fs_file,tok[FILETOK]); - - if ((FILETOK + 1) != TOTALTOK) { - int i; - - for (i = (FILETOK + 1); i < TOTALTOK; i++) { - /* FIXME: Using fstrcat rather than other means is a bit - * inefficient; this might be a problem for enormous queues with - * many fields. */ - fstrcat(buf->fs_file, " "); - fstrcat(buf->fs_file, tok[i]); - } - /* Ensure null termination. */ - fstrterminate(buf->fs_file); - } + /* FIXME: Use next_token rather than strtok! */ + tok[0] = strtok(line2," \t"); + count++; + + while ((count < MAXTOK) && ((tok[count] = strtok(NULL," \t")) != NULL)) { + count++; + } + + /* we must get at least NTOK tokens */ + if (count < NTOK) { + return False; + } + + /* the Job and Total columns must be integer */ + if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) { + return False; + } + + buf->job = atoi(tok[JOBTOK]); + buf->size = atoi(tok[TOTALTOK]); + buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED; + buf->time = time(NULL); + fstrcpy(buf->fs_user,tok[USERTOK]); + fstrcpy(buf->fs_file,tok[FILETOK]); + + if ((FILETOK + 1) != TOTALTOK) { + int i; + + for (i = (FILETOK + 1); i < TOTALTOK; i++) { + /* FIXME: Using fstrcat rather than other means is a bit + * inefficient; this might be a problem for enormous queues with + * many fields. */ + fstrcat(buf->fs_file, " "); + fstrcat(buf->fs_file, tok[i]); + } + /* Ensure null termination. */ + fstrterminate(buf->fs_file); + } #ifdef PRIOTOK - buf->priority = atoi(tok[PRIOTOK]); + buf->priority = atoi(tok[PRIOTOK]); #else - buf->priority = 1; + buf->priority = 1; #endif - return(True); + return True; } /* @@ -227,13 +232,14 @@ static time_t LPRng_time(char *time_string) return jobtime; } - /**************************************************************************** parse a lprng lpq line June 30, 1998. Re-wrote this to handle file names with spaces, multiple file names on one lpq line, etc; + ****************************************************************************/ + static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) { #define LPRNG_RANKTOK 0 @@ -246,72 +252,71 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) #define LPRNG_NTOK 7 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */ - fstring tokarr[LPRNG_MAXTOK]; - const char *cptr; - char *ptr; - int num_tok = 0; + fstring tokarr[LPRNG_MAXTOK]; + const char *cptr; + char *ptr; + int num_tok = 0; - cptr = line; - while(next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring)) && (num_tok < LPRNG_MAXTOK)) - num_tok++; + cptr = line; + while((num_tok < LPRNG_MAXTOK) && next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring))) { + num_tok++; + } - /* We must get at least LPRNG_NTOK tokens. */ - if (num_tok < LPRNG_NTOK) { - return(False); - } + /* We must get at least LPRNG_NTOK tokens. */ + if (num_tok < LPRNG_NTOK) { + return False; + } - if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) { - return(False); - } + if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) { + return False; + } - buf->job = atoi(tokarr[LPRNG_JOBTOK]); - buf->size = atoi(tokarr[LPRNG_TOTALTOK]); + buf->job = atoi(tokarr[LPRNG_JOBTOK]); + buf->size = atoi(tokarr[LPRNG_TOTALTOK]); - if (strequal(tokarr[LPRNG_RANKTOK],"active")) { - buf->status = LPQ_PRINTING; - } else if (strequal(tokarr[LPRNG_RANKTOK],"done")) { - buf->status = LPQ_PRINTED; - } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) { - buf->status = LPQ_QUEUED; - } else { - buf->status = LPQ_PAUSED; - } + if (strequal(tokarr[LPRNG_RANKTOK],"active")) { + buf->status = LPQ_PRINTING; + } else if (strequal(tokarr[LPRNG_RANKTOK],"done")) { + buf->status = LPQ_PRINTED; + } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) { + buf->status = LPQ_QUEUED; + } else { + buf->status = LPQ_PAUSED; + } - buf->priority = *tokarr[LPRNG_PRIOTOK] -'A'; + buf->priority = *tokarr[LPRNG_PRIOTOK] -'A'; - buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]); + buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]); - fstrcpy(buf->fs_user,tokarr[LPRNG_USERTOK]); + fstrcpy(buf->fs_user,tokarr[LPRNG_USERTOK]); - /* The '@hostname' prevents windows from displaying the printing icon - * for the current user on the taskbar. Plop in a null. - */ + /* The '@hostname' prevents windows from displaying the printing icon + * for the current user on the taskbar. Plop in a null. + */ - if ((ptr = strchr_m(buf->fs_user,'@')) != NULL) { - *ptr = '\0'; - } + if ((ptr = strchr_m(buf->fs_user,'@')) != NULL) { + *ptr = '\0'; + } - fstrcpy(buf->fs_file,tokarr[LPRNG_FILETOK]); + fstrcpy(buf->fs_file,tokarr[LPRNG_FILETOK]); - if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) { - int i; + if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) { + int i; - for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) { - /* FIXME: Using fstrcat rather than other means is a bit - * inefficient; this might be a problem for enormous queues with - * many fields. */ - fstrcat(buf->fs_file, " "); - fstrcat(buf->fs_file, tokarr[i]); - } - /* Ensure null termination. */ - fstrterminate(buf->fs_file); - } + for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) { + /* FIXME: Using fstrcat rather than other means is a bit + * inefficient; this might be a problem for enormous queues with + * many fields. */ + fstrcat(buf->fs_file, " "); + fstrcat(buf->fs_file, tokarr[i]); + } + /* Ensure null termination. */ + fstrterminate(buf->fs_file); + } - return(True); + return True; } - - /******************************************************************* parse lpq on an aix system @@ -324,92 +329,87 @@ lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1 QUEUED 540 L.ps root@IEDVB 172 1 4 QUEUED 541 P.ps root@IEDVB 22 1 5 ********************************************************************/ + static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) { - fstring tok[11]; - int count=0; - const char *cline = line; - - /* handle the case of "(standard input)" as a filename */ - string_sub(line,"standard input","STDIN",0); - all_string_sub(line,"(","\"",0); - all_string_sub(line,")","\"",0); - - for (count=0; - count<10 && - next_token(&cline,tok[count],NULL, sizeof(tok[count])); - count++) ; - - /* we must get 6 tokens */ - if (count < 10) - { - if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) - { - /* the 2nd and 5th columns must be integer */ - if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) return(False); - buf->size = atoi(tok[4]) * 1024; - /* if the fname contains a space then use STDIN */ - if (strchr_m(tok[2],' ')) - fstrcpy(tok[2],"STDIN"); - - /* only take the last part of the filename */ - { - fstring tmp; - char *p = strrchr_m(tok[2],'/'); - if (p) - { - fstrcpy(tmp,p+1); - fstrcpy(tok[2],tmp); - } - } - - - buf->job = atoi(tok[1]); - buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED; - buf->priority = 0; - buf->time = time(NULL); - fstrcpy(buf->fs_user,tok[3]); - fstrcpy(buf->fs_file,tok[2]); - } - else - { - DEBUG(6,("parse_lpq_aix count=%d\n", count)); - return(False); - } - } - else - { - /* the 4th and 9th columns must be integer */ - if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) return(False); - buf->size = atoi(tok[8]) * 1024; - /* if the fname contains a space then use STDIN */ - if (strchr_m(tok[4],' ')) - fstrcpy(tok[4],"STDIN"); - - /* only take the last part of the filename */ - { - fstring tmp; - char *p = strrchr_m(tok[4],'/'); - if (p) - { - fstrcpy(tmp,p+1); - fstrcpy(tok[4],tmp); - } - } - - - buf->job = atoi(tok[3]); - buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED; - buf->priority = 0; - buf->time = time(NULL); - fstrcpy(buf->fs_user,tok[5]); - fstrcpy(buf->fs_file,tok[4]); - } - - - return(True); -} + fstring tok[11]; + int count=0; + const char *cline = line; + + /* handle the case of "(standard input)" as a filename */ + string_sub(line,"standard input","STDIN",0); + all_string_sub(line,"(","\"",0); + all_string_sub(line,")","\"",0); + + for (count=0; count<10 && next_token(&cline,tok[count],NULL, sizeof(tok[count])); count++) { + ; + } + /* we must get 6 tokens */ + if (count < 10) { + if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) { + /* the 2nd and 5th columns must be integer */ + if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) { + return False; + } + buf->size = atoi(tok[4]) * 1024; + /* if the fname contains a space then use STDIN */ + if (strchr_m(tok[2],' ')) { + fstrcpy(tok[2],"STDIN"); + } + + /* only take the last part of the filename */ + { + fstring tmp; + char *p = strrchr_m(tok[2],'/'); + if (p) { + fstrcpy(tmp,p+1); + fstrcpy(tok[2],tmp); + } + } + + buf->job = atoi(tok[1]); + buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED; + buf->priority = 0; + buf->time = time(NULL); + fstrcpy(buf->fs_user,tok[3]); + fstrcpy(buf->fs_file,tok[2]); + } else { + DEBUG(6,("parse_lpq_aix count=%d\n", count)); + return False; + } + } else { + /* the 4th and 9th columns must be integer */ + if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) { + return False; + } + + buf->size = atoi(tok[8]) * 1024; + /* if the fname contains a space then use STDIN */ + if (strchr_m(tok[4],' ')) { + fstrcpy(tok[4],"STDIN"); + } + + /* only take the last part of the filename */ + { + fstring tmp; + char *p = strrchr_m(tok[4],'/'); + if (p) { + fstrcpy(tmp,p+1); + fstrcpy(tok[4],tmp); + } + } + + buf->job = atoi(tok[3]); + buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED; + buf->priority = 0; + buf->time = time(NULL); + fstrcpy(buf->fs_user,tok[5]); + fstrcpy(buf->fs_file,tok[4]); + } + + return True; +} /**************************************************************************** parse a lpq line @@ -421,105 +421,123 @@ ljplus-2153 user priority 0 Jan 19 08:14 on ljplus ljplus-2154 user priority 0 Jan 19 08:14 from client (standard input) 7551 bytes ****************************************************************************/ + static BOOL parse_lpq_hpux(char *line, print_queue_struct *buf, BOOL first) { - /* must read two lines to process, therefore keep some values static */ - static BOOL header_line_ok=False, base_prio_reset=False; - static fstring jobuser; - static int jobid; - static int jobprio; - static time_t jobtime; - static int jobstat=LPQ_QUEUED; - /* to store minimum priority to print, lpstat command should be invoked - with -p option first, to work */ - static int base_prio; - int count; - char htab = '\011'; - const char *cline = line; - fstring tok[12]; - - /* If a line begins with a horizontal TAB, it is a subline type */ + /* must read two lines to process, therefore keep some values static */ + static BOOL header_line_ok=False, base_prio_reset=False; + static fstring jobuser; + static int jobid; + static int jobprio; + static time_t jobtime; + static int jobstat=LPQ_QUEUED; + /* to store minimum priority to print, lpstat command should be invoked + with -p option first, to work */ + static int base_prio; + int count; + char htab = '\011'; + const char *cline = line; + fstring tok[12]; + + /* If a line begins with a horizontal TAB, it is a subline type */ - if (line[0] == htab) { /* subline */ - /* check if it contains the base priority */ - if (!strncmp(line,"\tfence priority : ",18)) { - base_prio=atoi(&line[18]); - DEBUG(4, ("fence priority set at %d\n", base_prio)); - } - if (!header_line_ok) return (False); /* incorrect header line */ - /* handle the case of "(standard input)" as a filename */ - string_sub(line,"standard input","STDIN",0); - all_string_sub(line,"(","\"",0); - all_string_sub(line,")","\"",0); + if (line[0] == htab) { /* subline */ + /* check if it contains the base priority */ + if (!strncmp(line,"\tfence priority : ",18)) { + base_prio=atoi(&line[18]); + DEBUG(4, ("fence priority set at %d\n", base_prio)); + } + + if (!header_line_ok) { + return False; /* incorrect header line */ + } + + /* handle the case of "(standard input)" as a filename */ + string_sub(line,"standard input","STDIN",0); + all_string_sub(line,"(","\"",0); + all_string_sub(line,")","\"",0); - for (count=0; count<2 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; - /* we must get 2 tokens */ - if (count < 2) return(False); + for (count=0; count<2 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + ; + } + /* we must get 2 tokens */ + if (count < 2) { + return False; + } - /* the 2nd column must be integer */ - if (!isdigit((int)*tok[1])) return(False); + /* the 2nd column must be integer */ + if (!isdigit((int)*tok[1])) { + return False; + } - /* if the fname contains a space then use STDIN */ - if (strchr_m(tok[0],' ')) - fstrcpy(tok[0],"STDIN"); + /* if the fname contains a space then use STDIN */ + if (strchr_m(tok[0],' ')) { + fstrcpy(tok[0],"STDIN"); + } - buf->size = atoi(tok[1]); - fstrcpy(buf->fs_file,tok[0]); + buf->size = atoi(tok[1]); + fstrcpy(buf->fs_file,tok[0]); - /* fill things from header line */ - buf->time = jobtime; - buf->job = jobid; - buf->status = jobstat; - buf->priority = jobprio; - fstrcpy(buf->fs_user,jobuser); + /* fill things from header line */ + buf->time = jobtime; + buf->job = jobid; + buf->status = jobstat; + buf->priority = jobprio; + fstrcpy(buf->fs_user,jobuser); - return(True); - } - else { /* header line */ - header_line_ok=False; /* reset it */ - if (first) { - if (!base_prio_reset) { - base_prio=0; /* reset it */ - base_prio_reset=True; - } - } - else if (base_prio) base_prio_reset=False; + return True; + } else { /* header line */ + header_line_ok=False; /* reset it */ + if (first) { + if (!base_prio_reset) { + base_prio=0; /* reset it */ + base_prio_reset=True; + } + } else if (base_prio) { + base_prio_reset=False; + } - /* handle the dash in the job id */ - string_sub(line,"-"," ",0); + /* handle the dash in the job id */ + string_sub(line,"-"," ",0); - for (count=0; count<12 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; + for (count=0; count<12 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + ; + } - /* we must get 8 tokens */ - if (count < 8) return(False); + /* we must get 8 tokens */ + if (count < 8) { + return False; + } - /* first token must be printer name (cannot check ?) */ - /* the 2nd, 5th & 7th column must be integer */ - if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) return(False); - jobid = atoi(tok[1]); - fstrcpy(jobuser,tok[2]); - jobprio = atoi(tok[4]); + /* first token must be printer name (cannot check ?) */ + /* the 2nd, 5th & 7th column must be integer */ + if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) { + return False; + } + jobid = atoi(tok[1]); + fstrcpy(jobuser,tok[2]); + jobprio = atoi(tok[4]); - /* process time */ - jobtime=EntryTime(tok, 5, count, 8); - if (jobprio < base_prio) { - jobstat = LPQ_PAUSED; - DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n", jobid, jobprio, base_prio, jobstat)); - } - else { - jobstat = LPQ_QUEUED; - if ((count >8) && (((strequal(tok[8],"on")) || - ((strequal(tok[8],"from")) && - ((count > 10)&&(strequal(tok[10],"on"))))))) - jobstat = LPQ_PRINTING; - } + /* process time */ + jobtime=EntryTime(tok, 5, count, 8); + if (jobprio < base_prio) { + jobstat = LPQ_PAUSED; + DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n", + jobid, jobprio, base_prio, jobstat)); + } else { + jobstat = LPQ_QUEUED; + if ((count >8) && (((strequal(tok[8],"on")) || + ((strequal(tok[8],"from")) && + ((count > 10)&&(strequal(tok[10],"on"))))))) { + jobstat = LPQ_PRINTING; + } + } - header_line_ok=True; /* information is correct */ - return(False); /* need subline info to include into queuelist */ - } + header_line_ok=True; /* information is correct */ + return False; /* need subline info to include into queuelist */ + } } - /**************************************************************************** parse a lpstat line @@ -529,68 +547,77 @@ dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw dcslw-897 tridge 4712 Dec 20 10:30:30 being held ****************************************************************************/ + static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first) { - fstring tok[9]; - int count=0; - char *p; - const char *cline = line; - - /* - * Handle the dash in the job id, but make sure that we skip over - * the printer name in case we have a dash in that. - * Patch from Dom.Mitchell@palmerharvey.co.uk. - */ - - /* - * Move to the first space. - */ - for (p = line ; !isspace(*p) && *p; p++) - ; - - /* - * Back up until the last '-' character or - * start of line. - */ - for (; (p >= line) && (*p != '-'); p--) - ; - - if((p >= line) && (*p == '-')) - *p = ' '; - - for (count=0; count<9 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) - ; - - /* we must get 7 tokens */ - if (count < 7) - return(False); - - /* the 2nd and 4th, 6th columns must be integer */ - if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) - return(False); - if (!isdigit((int)*tok[5])) - return(False); - - /* if the user contains a ! then trim the first part of it */ - if ((p=strchr_m(tok[2],'!'))) { - fstring tmp; - fstrcpy(tmp,p+1); - fstrcpy(tok[2],tmp); - } - - buf->job = atoi(tok[1]); - buf->size = atoi(tok[3]); - if (count > 7 && strequal(tok[7],"on")) - buf->status = LPQ_PRINTING; - else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held")) - buf->status = LPQ_PAUSED; - else - buf->status = LPQ_QUEUED; - buf->priority = 0; - buf->time = EntryTime(tok, 4, count, 7); - fstrcpy(buf->fs_user,tok[2]); - fstrcpy(buf->fs_file,tok[2]); - return(True); + fstring tok[9]; + int count=0; + char *p; + const char *cline = line; + + /* + * Handle the dash in the job id, but make sure that we skip over + * the printer name in case we have a dash in that. + * Patch from Dom.Mitchell@palmerharvey.co.uk. + */ + + /* + * Move to the first space. + */ + for (p = line ; !isspace(*p) && *p; p++) { + ; + } + + /* + * Back up until the last '-' character or + * start of line. + */ + for (; (p >= line) && (*p != '-'); p--) { + ; + } + + if((p >= line) && (*p == '-')) { + *p = ' '; + } + + for (count=0; count<9 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + ; + } + + /* we must get 7 tokens */ + if (count < 7) { + return False; + } + + /* the 2nd and 4th, 6th columns must be integer */ + if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) { + return False; + } + if (!isdigit((int)*tok[5])) { + return False; + } + + /* if the user contains a ! then trim the first part of it */ + if ((p=strchr_m(tok[2],'!'))) { + fstring tmp; + fstrcpy(tmp,p+1); + fstrcpy(tok[2],tmp); + } + + buf->job = atoi(tok[1]); + buf->size = atoi(tok[3]); + if (count > 7 && strequal(tok[7],"on")) { + buf->status = LPQ_PRINTING; + } else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held")) { + buf->status = LPQ_PAUSED; + } else { + buf->status = LPQ_QUEUED; + } + buf->priority = 0; + buf->time = EntryTime(tok, 4, count, 7); + fstrcpy(buf->fs_user,tok[2]); + fstrcpy(buf->fs_file,tok[2]); + return True; } /**************************************************************************** @@ -603,56 +630,59 @@ Printer: txt (ready) 0001: root [job #2 ] ready 2378 bytes /etc/install 0002: root [job #3 ] ready 1146 bytes -- standard input -- ****************************************************************************/ + static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) { - fstring tok[7]; - int count=0; - const char *cline = line; - - DEBUG(4,("antes [%s]\n", line)); - - /* handle the case of "-- standard input --" as a filename */ - string_sub(line,"standard input","STDIN",0); - DEBUG(4,("despues [%s]\n", line)); - all_string_sub(line,"-- ","\"",0); - all_string_sub(line," --","\"",0); - DEBUG(4,("despues 1 [%s]\n", line)); - - string_sub(line,"[job #","",0); - string_sub(line,"]","",0); - DEBUG(4,("despues 2 [%s]\n", line)); - - for (count=0; count<7 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; - - /* we must get 7 tokens */ - if (count < 7) - return(False); - - /* the 3rd and 5th columns must be integer */ - if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) return(False); - - /* only take the last part of the filename */ - { - fstring tmp; - char *p = strrchr_m(tok[6],'/'); - if (p) - { - fstrcpy(tmp,p+1); - fstrcpy(tok[6],tmp); - } - } - + fstring tok[7]; + int count=0; + const char *cline = line; - buf->job = atoi(tok[2]); - buf->size = atoi(tok[4]); - buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED; - buf->priority = 0; - buf->time = time(NULL); - fstrcpy(buf->fs_user,tok[1]); - fstrcpy(buf->fs_file,tok[6]); - return(True); -} + DEBUG(4,("antes [%s]\n", line)); + + /* handle the case of "-- standard input --" as a filename */ + string_sub(line,"standard input","STDIN",0); + DEBUG(4,("despues [%s]\n", line)); + all_string_sub(line,"-- ","\"",0); + all_string_sub(line," --","\"",0); + DEBUG(4,("despues 1 [%s]\n", line)); + string_sub(line,"[job #","",0); + string_sub(line,"]","",0); + DEBUG(4,("despues 2 [%s]\n", line)); + + for (count=0; count<7 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + ; + } + + /* we must get 7 tokens */ + if (count < 7) { + return False; + } + + /* the 3rd and 5th columns must be integer */ + if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) { + return False; + } + + /* only take the last part of the filename */ + { + fstring tmp; + char *p = strrchr_m(tok[6],'/'); + if (p) { + fstrcpy(tmp,p+1); + fstrcpy(tok[6],tmp); + } + } + + buf->job = atoi(tok[2]); + buf->size = atoi(tok[4]); + buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED; + buf->priority = 0; + buf->time = time(NULL); + fstrcpy(buf->fs_user,tok[1]); + fstrcpy(buf->fs_file,tok[6]); + return True; +} /**************************************************************************** parse a lpq line for the plp printing system @@ -667,61 +697,68 @@ Local Printer 'lp2' (fjall): 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33 ****************************************************************************/ + static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) { - fstring tok[11]; - int count=0; - const char *cline = line; - - /* handle the case of "(standard input)" as a filename */ - string_sub(line,"stdin","STDIN",0); - all_string_sub(line,"(","\"",0); - all_string_sub(line,")","\"",0); + fstring tok[11]; + int count=0; + const char *cline = line; + + /* handle the case of "(standard input)" as a filename */ + string_sub(line,"stdin","STDIN",0); + all_string_sub(line,"(","\"",0); + all_string_sub(line,")","\"",0); - for (count=0; count<11 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) ; - - /* we must get 11 tokens */ - if (count < 11) - return(False); - - /* the first must be "active" or begin with an integer */ - if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) - return(False); - - /* the 5th and 8th must be integer */ - if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) - return(False); - - /* if the fname contains a space then use STDIN */ - if (strchr_m(tok[6],' ')) - fstrcpy(tok[6],"STDIN"); - - /* only take the last part of the filename */ - { - fstring tmp; - char *p = strrchr_m(tok[6],'/'); - if (p) - { - fstrcpy(tmp,p+1); - fstrcpy(tok[6],tmp); - } - } - - - buf->job = atoi(tok[4]); - - buf->size = atoi(tok[7]); - if (strchr_m(tok[7],'K')) - buf->size *= 1024; - if (strchr_m(tok[7],'M')) - buf->size *= 1024*1024; - - buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED; - buf->priority = 0; - buf->time = time(NULL); - fstrcpy(buf->fs_user,tok[1]); - fstrcpy(buf->fs_file,tok[6]); - return(True); + for (count=0; count<11 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + ; + } + + /* we must get 11 tokens */ + if (count < 11) { + return False; + } + + /* the first must be "active" or begin with an integer */ + if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) { + return False; + } + + /* the 5th and 8th must be integer */ + if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) { + return False; + } + + /* if the fname contains a space then use STDIN */ + if (strchr_m(tok[6],' ')) { + fstrcpy(tok[6],"STDIN"); + } + + /* only take the last part of the filename */ + { + fstring tmp; + char *p = strrchr_m(tok[6],'/'); + if (p) { + fstrcpy(tmp,p+1); + fstrcpy(tok[6],tmp); + } + } + + buf->job = atoi(tok[4]); + + buf->size = atoi(tok[7]); + if (strchr_m(tok[7],'K')) { + buf->size *= 1024; + } + if (strchr_m(tok[7],'M')) { + buf->size *= 1024*1024; + } + + buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED; + buf->priority = 0; + buf->time = time(NULL); + fstrcpy(buf->fs_user,tok[1]); + fstrcpy(buf->fs_file,tok[6]); + return True; } /******************************************************************* @@ -737,6 +774,7 @@ root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1 jmcd Waiting Re: Samba Open Sour 26 32476 1 1 ********************************************************************/ + static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) { #define LPRNT_OWNSIZ 11 @@ -744,66 +782,70 @@ static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) #define LPRNT_JOBSIZ 19 #define LPRNT_IDSIZ 6 #define LPRNT_SIZSIZ 9 - typedef struct - { - char owner[LPRNT_OWNSIZ]; - char space1; - char status[LPRNT_STATSIZ]; - char space2; - char jobname[LPRNT_JOBSIZ]; - char space3; - char jobid[LPRNT_IDSIZ]; - char space4; - char size[LPRNT_SIZSIZ]; - char terminator; - } nt_lpq_line; - - nt_lpq_line parse_line; + typedef struct { + char owner[LPRNT_OWNSIZ]; + char space1; + char status[LPRNT_STATSIZ]; + char space2; + char jobname[LPRNT_JOBSIZ]; + char space3; + char jobid[LPRNT_IDSIZ]; + char space4; + char size[LPRNT_SIZSIZ]; + char terminator; + } nt_lpq_line; + + nt_lpq_line parse_line; #define LPRNT_PRINTING "Printing" #define LPRNT_WAITING "Waiting" #define LPRNT_PAUSED "Paused" - memset(&parse_line, '\0', sizeof(parse_line)); - strncpy((char *) &parse_line, line, sizeof(parse_line) -1); - - if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) - return(False); - - /* Just want the first word in the owner field - the username */ - if (strchr_m(parse_line.owner, ' ')) - *(strchr_m(parse_line.owner, ' ')) = '\0'; - else - parse_line.space1 = '\0'; - - /* Make sure we have an owner */ - if (!strlen(parse_line.owner)) - return(False); - - /* Make sure the status is valid */ - parse_line.space2 = '\0'; - trim_char(parse_line.status, '\0', ' '); - if (!strequal(parse_line.status, LPRNT_PRINTING) && - !strequal(parse_line.status, LPRNT_PAUSED) && - !strequal(parse_line.status, LPRNT_WAITING)) - return(False); + memset(&parse_line, '\0', sizeof(parse_line)); + strncpy((char *) &parse_line, line, sizeof(parse_line) -1); + + if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) { + return False; + } + + /* Just want the first word in the owner field - the username */ + if (strchr_m(parse_line.owner, ' ')) { + *(strchr_m(parse_line.owner, ' ')) = '\0'; + } else { + parse_line.space1 = '\0'; + } + + /* Make sure we have an owner */ + if (!strlen(parse_line.owner)) { + return False; + } + + /* Make sure the status is valid */ + parse_line.space2 = '\0'; + trim_char(parse_line.status, '\0', ' '); + if (!strequal(parse_line.status, LPRNT_PRINTING) && + !strequal(parse_line.status, LPRNT_PAUSED) && + !strequal(parse_line.status, LPRNT_WAITING)) { + return False; + } - parse_line.space3 = '\0'; - trim_char(parse_line.jobname, '\0', ' '); - - buf->job = atoi(parse_line.jobid); - buf->priority = 0; - buf->size = atoi(parse_line.size); - buf->time = time(NULL); - fstrcpy(buf->fs_user, parse_line.owner); - fstrcpy(buf->fs_file, parse_line.jobname); - if (strequal(parse_line.status, LPRNT_PRINTING)) - buf->status = LPQ_PRINTING; - else if (strequal(parse_line.status, LPRNT_PAUSED)) - buf->status = LPQ_PAUSED; - else - buf->status = LPQ_QUEUED; - - return(True); + parse_line.space3 = '\0'; + trim_char(parse_line.jobname, '\0', ' '); + + buf->job = atoi(parse_line.jobid); + buf->priority = 0; + buf->size = atoi(parse_line.size); + buf->time = time(NULL); + fstrcpy(buf->fs_user, parse_line.owner); + fstrcpy(buf->fs_file, parse_line.jobname); + if (strequal(parse_line.status, LPRNT_PRINTING)) { + buf->status = LPQ_PRINTING; + } else if (strequal(parse_line.status, LPRNT_PAUSED)) { + buf->status = LPQ_PAUSED; + } else { + buf->status = LPQ_QUEUED; + } + + return True; } /******************************************************************* @@ -815,6 +857,7 @@ JobID File Name Rank Size Status Comment 4 /etc/motd 2 11666 Queued root@psflinu ********************************************************************/ + static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) { #define LPROS2_IDSIZ 5 @@ -822,64 +865,67 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) #define LPROS2_SIZSIZ 8 #define LPROS2_STATSIZ 12 #define LPROS2_OWNSIZ 12 - typedef struct - { - char jobid[LPROS2_IDSIZ]; - char space1[2]; - char jobname[LPROS2_JOBSIZ]; - char space2[14]; - char size[LPROS2_SIZSIZ]; - char space3[4]; - char status[LPROS2_STATSIZ]; - char space4[4]; - char owner[LPROS2_OWNSIZ]; - char terminator; - } os2_lpq_line; - - os2_lpq_line parse_line; + typedef struct { + char jobid[LPROS2_IDSIZ]; + char space1[2]; + char jobname[LPROS2_JOBSIZ]; + char space2[14]; + char size[LPROS2_SIZSIZ]; + char space3[4]; + char status[LPROS2_STATSIZ]; + char space4[4]; + char owner[LPROS2_OWNSIZ]; + char terminator; + } os2_lpq_line; + + os2_lpq_line parse_line; #define LPROS2_PRINTING "Printing" #define LPROS2_WAITING "Queued" #define LPROS2_PAUSED "Paused" - memset(&parse_line, '\0', sizeof(parse_line)); - strncpy((char *) &parse_line, line, sizeof(parse_line) -1); - - if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) - return(False); - - /* Get the jobid */ - buf->job = atoi(parse_line.jobid); - - /* Get the job name */ - parse_line.space2[0] = '\0'; - trim_char(parse_line.jobname, '\0', ' '); - fstrcpy(buf->fs_file, parse_line.jobname); - - buf->priority = 0; - buf->size = atoi(parse_line.size); - buf->time = time(NULL); - - /* Make sure we have an owner */ - if (!strlen(parse_line.owner)) - return(False); - - /* Make sure we have a valid status */ - parse_line.space4[0] = '\0'; - trim_char(parse_line.status, '\0', ' '); - if (!strequal(parse_line.status, LPROS2_PRINTING) && - !strequal(parse_line.status, LPROS2_PAUSED) && - !strequal(parse_line.status, LPROS2_WAITING)) - return(False); - - fstrcpy(buf->fs_user, parse_line.owner); - if (strequal(parse_line.status, LPROS2_PRINTING)) - buf->status = LPQ_PRINTING; - else if (strequal(parse_line.status, LPROS2_PAUSED)) - buf->status = LPQ_PAUSED; - else - buf->status = LPQ_QUEUED; - - return(True); + memset(&parse_line, '\0', sizeof(parse_line)); + strncpy((char *) &parse_line, line, sizeof(parse_line) -1); + + if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) { + return False; + } + + /* Get the jobid */ + buf->job = atoi(parse_line.jobid); + + /* Get the job name */ + parse_line.space2[0] = '\0'; + trim_char(parse_line.jobname, '\0', ' '); + fstrcpy(buf->fs_file, parse_line.jobname); + + buf->priority = 0; + buf->size = atoi(parse_line.size); + buf->time = time(NULL); + + /* Make sure we have an owner */ + if (!strlen(parse_line.owner)) { + return False; + } + + /* Make sure we have a valid status */ + parse_line.space4[0] = '\0'; + trim_char(parse_line.status, '\0', ' '); + if (!strequal(parse_line.status, LPROS2_PRINTING) && + !strequal(parse_line.status, LPROS2_PAUSED) && + !strequal(parse_line.status, LPROS2_WAITING)) { + return False; + } + + fstrcpy(buf->fs_user, parse_line.owner); + if (strequal(parse_line.status, LPROS2_PRINTING)) { + buf->status = LPQ_PRINTING; + } else if (strequal(parse_line.status, LPROS2_PAUSED)) { + buf->status = LPQ_PAUSED; + } else { + buf->status = LPQ_QUEUED; + } + + return True; } static const char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL }; @@ -891,6 +937,7 @@ static const char *stat2_strings[] = { "jam", "paper", "error", "responding", "n /**************************************************************************** parse a vlp line ****************************************************************************/ + static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) { int toknum = 0; @@ -940,92 +987,96 @@ BOOL parse_lpq_entry(enum printing_types printing_type,char *line, print_queue_struct *buf, print_status_struct *status,BOOL first) { - BOOL ret; - - switch (printing_type) - { - case PRINT_SYSV: - ret = parse_lpq_sysv(line,buf,first); - break; - case PRINT_AIX: - ret = parse_lpq_aix(line,buf,first); - break; - case PRINT_HPUX: - ret = parse_lpq_hpux(line,buf,first); - break; - case PRINT_QNX: - ret = parse_lpq_qnx(line,buf,first); - break; - case PRINT_LPRNG: - ret = parse_lpq_lprng(line,buf,first); - break; - case PRINT_PLP: - ret = parse_lpq_plp(line,buf,first); - break; - case PRINT_LPRNT: - ret = parse_lpq_nt(line,buf,first); - break; - case PRINT_LPROS2: - ret = parse_lpq_os2(line,buf,first); - break; + BOOL ret; + + switch (printing_type) { + case PRINT_SYSV: + ret = parse_lpq_sysv(line,buf,first); + break; + case PRINT_AIX: + ret = parse_lpq_aix(line,buf,first); + break; + case PRINT_HPUX: + ret = parse_lpq_hpux(line,buf,first); + break; + case PRINT_QNX: + ret = parse_lpq_qnx(line,buf,first); + break; + case PRINT_LPRNG: + ret = parse_lpq_lprng(line,buf,first); + break; + case PRINT_PLP: + ret = parse_lpq_plp(line,buf,first); + break; + case PRINT_LPRNT: + ret = parse_lpq_nt(line,buf,first); + break; + case PRINT_LPROS2: + ret = parse_lpq_os2(line,buf,first); + break; #ifdef DEVELOPER - case PRINT_VLP: - case PRINT_TEST: - ret = parse_lpq_vlp(line,buf,first); - break; + case PRINT_VLP: + case PRINT_TEST: + ret = parse_lpq_vlp(line,buf,first); + break; #endif /* DEVELOPER */ - default: - ret = parse_lpq_bsd(line,buf,first); - break; - } - - /* We don't want the newline in the status message. */ - { - char *p = strchr_m(line,'\n'); - if (p) *p = 0; - } - - /* in the LPRNG case, we skip lines starting by a space.*/ - if (!ret && (printing_type==PRINT_LPRNG) ) - { - if (line[0]==' ') - return ret; - } - - - if (status && !ret) - { - /* a few simple checks to see if the line might be a - printer status line: - handle them so that most severe condition is shown */ - int i; - strlower_m(line); + default: + ret = parse_lpq_bsd(line,buf,first); + break; + } + + /* We don't want the newline in the status message. */ + { + char *p = strchr_m(line,'\n'); + if (p) { + *p = 0; + } + } + + /* in the LPRNG case, we skip lines starting by a space.*/ + if (!ret && (printing_type==PRINT_LPRNG) ) { + if (line[0]==' ') { + return ret; + } + } + + if (status && !ret) { + /* a few simple checks to see if the line might be a + printer status line: + handle them so that most severe condition is shown */ + int i; + strlower_m(line); - switch (status->status) { - case LPSTAT_OK: - for (i=0; stat0_strings[i]; i++) - if (strstr_m(line,stat0_strings[i])) { - fstrcpy(status->message,line); - status->status=LPSTAT_OK; - return ret; - } - case LPSTAT_STOPPED: - for (i=0; stat1_strings[i]; i++) - if (strstr_m(line,stat1_strings[i])) { - fstrcpy(status->message,line); - status->status=LPSTAT_STOPPED; - return ret; - } - case LPSTAT_ERROR: - for (i=0; stat2_strings[i]; i++) - if (strstr_m(line,stat2_strings[i])) { - fstrcpy(status->message,line); - status->status=LPSTAT_ERROR; - return ret; - } - break; - } - } - - return(ret); + switch (status->status) { + case LPSTAT_OK: + for (i=0; stat0_strings[i]; i++) { + if (strstr_m(line,stat0_strings[i])) { + fstrcpy(status->message,line); + status->status=LPSTAT_OK; + return ret; + } + } + /* fallthrough */ + case LPSTAT_STOPPED: + for (i=0; stat1_strings[i]; i++) { + if (strstr_m(line,stat1_strings[i])) { + fstrcpy(status->message,line); + status->status=LPSTAT_STOPPED; + return ret; + } + } + /* fallthrough */ + case LPSTAT_ERROR: + for (i=0; stat2_strings[i]; i++) { + if (strstr_m(line,stat2_strings[i])) { + fstrcpy(status->message,line); + status->status=LPSTAT_ERROR; + return ret; + } + } + break; + } + } + + return ret; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/printing/lpq_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 100585637a..5118429bd7 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/printing/lpq_parse.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 5118429bd7..d5e9c795ad 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/printing/lpq_parse.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index d5e9c795ad..50fad6f946 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -102,7 +102,7 @@ Modified to handle file names with spaces, like the parse_lpq_lprng code further below. ****************************************************************************/ -static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first) { #ifdef OSF1 #define RANKTOK 0 @@ -239,7 +239,7 @@ static time_t LPRng_time(char *time_string) ****************************************************************************/ -static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_lprng(char *line,print_queue_struct *buf,bool first) { #define LPRNG_RANKTOK 0 #define LPRNG_USERTOK 1 @@ -329,7 +329,7 @@ lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1 QUEUED 541 P.ps root@IEDVB 22 1 5 ********************************************************************/ -static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) { fstring tok[11]; int count=0; @@ -421,10 +421,10 @@ ljplus-2154 user priority 0 Jan 19 08:14 from client (standard input) 7551 bytes ****************************************************************************/ -static BOOL parse_lpq_hpux(char *line, print_queue_struct *buf, BOOL first) +static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) { /* must read two lines to process, therefore keep some values static */ - static BOOL header_line_ok=False, base_prio_reset=False; + static bool header_line_ok=False, base_prio_reset=False; static fstring jobuser; static int jobid; static int jobprio; @@ -547,7 +547,7 @@ dcslw-897 tridge 4712 Dec 20 10:30:30 being held ****************************************************************************/ -static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first) { fstring tok[9]; int count=0; @@ -630,7 +630,7 @@ Printer: txt (ready) 0002: root [job #3 ] ready 1146 bytes -- standard input -- ****************************************************************************/ -static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first) { fstring tok[7]; int count=0; @@ -697,7 +697,7 @@ Local Printer 'lp2' (fjall): ****************************************************************************/ -static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first) { fstring tok[11]; int count=0; @@ -774,7 +774,7 @@ jmcd Waiting Re: Samba Open Sour 26 32476 1 1 ********************************************************************/ -static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_nt(char *line,print_queue_struct *buf,bool first) { #define LPRNT_OWNSIZ 11 #define LPRNT_STATSIZ 9 @@ -857,7 +857,7 @@ JobID File Name Rank Size Status Comment ********************************************************************/ -static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_os2(char *line,print_queue_struct *buf,bool first) { #define LPROS2_IDSIZ 5 #define LPROS2_JOBSIZ 15 @@ -937,7 +937,7 @@ static const char *stat2_strings[] = { "jam", "paper", "error", "responding", "n parse a vlp line ****************************************************************************/ -static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) +static bool parse_lpq_vlp(char *line,print_queue_struct *buf,bool first) { int toknum = 0; fstring tok; @@ -982,11 +982,11 @@ static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first) parse a lpq line. Choose printing style ****************************************************************************/ -BOOL parse_lpq_entry(enum printing_types printing_type,char *line, +bool parse_lpq_entry(enum printing_types printing_type,char *line, print_queue_struct *buf, - print_status_struct *status,BOOL first) + print_status_struct *status,bool first) { - BOOL ret; + bool ret; switch (printing_type) { case PRINT_SYSV: -- cgit From 4c6b01b0ef289bb1511c30354ed41b597288c9d7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 19 Nov 2007 18:56:22 -0800 Subject: Remove more pstring. Unify talloc_sub functions to make them a better match for replacing string_sub. Remove more unused code. Jeremy. (This used to be commit ae7885711f504f1442335f09088cbe149a7e00f9) --- source3/printing/lpq_parse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 50fad6f946..09f630e464 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -125,9 +125,13 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first) char *tok[MAXTOK]; int count = 0; - pstring line2; + TALLOC_CTX *ctx = talloc_tos(); + char *line2 = NULL; - pstrcpy(line2,line); + line2 = talloc_strdup(ctx, line); + if (!line2) { + return false; + } #ifdef OSF1 { -- cgit From a22487025d20c6683f24fe3c5bb35b555d064523 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 3 Dec 2007 15:47:30 -0800 Subject: Fix the build. fstrterminate was used in one place. Jeremy. (This used to be commit 0ccd87c56b34bdc34c73d700d21544fe269f9141) --- source3/printing/lpq_parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 09f630e464..d4520b04ba 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -179,7 +179,7 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first) fstrcat(buf->fs_file, tok[i]); } /* Ensure null termination. */ - fstrterminate(buf->fs_file); + buf->fs_file[sizeof(buf->fs_file)-1] = '\0'; } #ifdef PRIOTOK @@ -314,7 +314,7 @@ static bool parse_lpq_lprng(char *line,print_queue_struct *buf,bool first) fstrcat(buf->fs_file, tokarr[i]); } /* Ensure null termination. */ - fstrterminate(buf->fs_file); + buf->fs_file[sizeof(buf->fs_file)-1] = '\0'; } return True; -- cgit From 42cfffae80480eae4381902fff3f7c61f858a933 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Dec 2007 17:32:32 -0800 Subject: Remove next_token - all uses must now be next_token_talloc. No more temptations to use static length strings. Jeremy. (This used to be commit ec003f39369910dee852b7cafb883ddaa321c2de) --- source3/printing/lpq_parse.c | 168 +++++++++++++++++++++++++++++-------------- 1 file changed, 113 insertions(+), 55 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index d4520b04ba..56e228f219 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -27,7 +27,7 @@ static const char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", Process time fields ********************************************************************/ -static time_t EntryTime(fstring tok[], int ptr, int count, int minimum) +static time_t EntryTime(char *tok[], int ptr, int count, int minimum) { time_t jobtime,jobtime1; @@ -35,7 +35,6 @@ static time_t EntryTime(fstring tok[], int ptr, int count, int minimum) if (count >= minimum) { struct tm *t; int i, day, hour, min, sec; - char *c; for (i=0; i<13; i++) { if (!strncmp(tok[ptr], Months[i],3)) { @@ -44,12 +43,13 @@ static time_t EntryTime(fstring tok[], int ptr, int count, int minimum) } if (i<12) { + fstring c; t = localtime(&jobtime); if (!t) { return (time_t)-1; } day = atoi(tok[ptr+1]); - c=(char *)(tok[ptr+2]); + fstrcpy(c,tok[ptr+2]); *(c+2)=0; hour = atoi(c); *(c+5)=0; @@ -143,7 +143,7 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first) } #endif /* OSF1 */ - /* FIXME: Use next_token rather than strtok! */ + /* FIXME: Use next_token_talloc rather than strtok! */ tok[0] = strtok(line2," \t"); count++; @@ -255,22 +255,26 @@ static bool parse_lpq_lprng(char *line,print_queue_struct *buf,bool first) #define LPRNG_NTOK 7 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */ - fstring tokarr[LPRNG_MAXTOK]; + char *tokarr[LPRNG_MAXTOK]; const char *cptr; char *ptr; int num_tok = 0; + TALLOC_CTX *frame = talloc_stackframe(); cptr = line; - while((num_tok < LPRNG_MAXTOK) && next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring))) { + while((num_tok < LPRNG_MAXTOK) && next_token_talloc(frame, &cptr, + &tokarr[num_tok], " \t")) { num_tok++; } /* We must get at least LPRNG_NTOK tokens. */ if (num_tok < LPRNG_NTOK) { + TALLOC_FREE(frame); return False; } if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) { + TALLOC_FREE(frame); return False; } @@ -317,6 +321,7 @@ static bool parse_lpq_lprng(char *line,print_queue_struct *buf,bool first) buf->fs_file[sizeof(buf->fs_file)-1] = '\0'; } + TALLOC_FREE(frame); return True; } @@ -335,16 +340,18 @@ lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1 static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) { - fstring tok[11]; + char *tok[11]; int count=0; const char *cline = line; + TALLOC_CTX *frame = talloc_stackframe(); /* handle the case of "(standard input)" as a filename */ string_sub(line,"standard input","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); - for (count=0; count<10 && next_token(&cline,tok[count],NULL, sizeof(tok[count])); count++) { + for (count=0; count<10 && + next_token_talloc(frame,&cline,&tok[count],NULL); count++) { ; } @@ -353,21 +360,24 @@ static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) { /* the 2nd and 5th columns must be integer */ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) { + TALLOC_FREE(frame); return False; } buf->size = atoi(tok[4]) * 1024; /* if the fname contains a space then use STDIN */ if (strchr_m(tok[2],' ')) { - fstrcpy(tok[2],"STDIN"); + tok[2] = talloc_strdup(frame,"STDIN"); + if (!tok[2]) { + TALLOC_FREE(frame); + return false; + } } /* only take the last part of the filename */ { - fstring tmp; char *p = strrchr_m(tok[2],'/'); if (p) { - fstrcpy(tmp,p+1); - fstrcpy(tok[2],tmp); + tok[2] = p+1; } } @@ -379,27 +389,31 @@ static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) fstrcpy(buf->fs_file,tok[2]); } else { DEBUG(6,("parse_lpq_aix count=%d\n", count)); + TALLOC_FREE(frame); return False; } } else { /* the 4th and 9th columns must be integer */ if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) { + TALLOC_FREE(frame); return False; } buf->size = atoi(tok[8]) * 1024; /* if the fname contains a space then use STDIN */ if (strchr_m(tok[4],' ')) { - fstrcpy(tok[4],"STDIN"); + tok[4] = talloc_strdup(frame,"STDIN"); + if (!tok[4]) { + TALLOC_FREE(frame); + return false; + } } /* only take the last part of the filename */ { - fstring tmp; char *p = strrchr_m(tok[4],'/'); if (p) { - fstrcpy(tmp,p+1); - fstrcpy(tok[4],tmp); + tok[4] = p+1; } } @@ -411,6 +425,7 @@ static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) fstrcpy(buf->fs_file,tok[4]); } + TALLOC_FREE(frame); return True; } @@ -438,12 +453,13 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) with -p option first, to work */ static int base_prio; int count; - char htab = '\011'; + char htab = '\011'; const char *cline = line; - fstring tok[12]; + char *tok[12]; + TALLOC_CTX *frame = talloc_stackframe(); /* If a line begins with a horizontal TAB, it is a subline type */ - + if (line[0] == htab) { /* subline */ /* check if it contains the base priority */ if (!strncmp(line,"\tfence priority : ",18)) { @@ -452,6 +468,7 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) } if (!header_line_ok) { + TALLOC_FREE(frame); return False; /* incorrect header line */ } @@ -459,35 +476,44 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) string_sub(line,"standard input","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); - - for (count=0; count<2 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + + for (count=0; count<2 && + next_token_talloc(frame, &cline, &tok[count],NULL); + count++) { ; } /* we must get 2 tokens */ if (count < 2) { + TALLOC_FREE(frame); return False; } - + /* the 2nd column must be integer */ if (!isdigit((int)*tok[1])) { + TALLOC_FREE(frame); return False; } - + /* if the fname contains a space then use STDIN */ if (strchr_m(tok[0],' ')) { - fstrcpy(tok[0],"STDIN"); + tok[0] = talloc_strdup(frame, "STDIN"); + if (!tok[0]) { + TALLOC_FREE(frame); + return false; + } } - + buf->size = atoi(tok[1]); fstrcpy(buf->fs_file,tok[0]); - + /* fill things from header line */ buf->time = jobtime; buf->job = jobid; buf->status = jobstat; buf->priority = jobprio; fstrcpy(buf->fs_user,jobuser); - + + TALLOC_FREE(frame); return True; } else { /* header line */ header_line_ok=False; /* reset it */ @@ -499,28 +525,32 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) } else if (base_prio) { base_prio_reset=False; } - + /* handle the dash in the job id */ string_sub(line,"-"," ",0); - - for (count=0; count<12 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + + for (count=0; count<12 && + next_token_talloc(frame, &cline, &tok[count],NULL); + count++) { ; } - + /* we must get 8 tokens */ if (count < 8) { + TALLOC_FREE(frame); return False; } - + /* first token must be printer name (cannot check ?) */ /* the 2nd, 5th & 7th column must be integer */ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) { + TALLOC_FREE(frame); return False; } jobid = atoi(tok[1]); fstrcpy(jobuser,tok[2]); jobprio = atoi(tok[4]); - + /* process time */ jobtime=EntryTime(tok, 5, count, 8); if (jobprio < base_prio) { @@ -535,8 +565,9 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) jobstat = LPQ_PRINTING; } } - + header_line_ok=True; /* information is correct */ + TALLOC_FREE(frame); return False; /* need subline info to include into queuelist */ } } @@ -553,12 +584,13 @@ dcslw-897 tridge 4712 Dec 20 10:30:30 being held static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first) { - fstring tok[9]; + char *tok[9]; int count=0; char *p; const char *cline = line; + TALLOC_CTX *frame = NULL; - /* + /* * Handle the dash in the job id, but make sure that we skip over * the printer name in case we have a dash in that. * Patch from Dom.Mitchell@palmerharvey.co.uk. @@ -583,28 +615,32 @@ static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first) *p = ' '; } - for (count=0; count<9 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + frame = talloc_stackframe(); + for (count=0; count<9 && + next_token_talloc(frame, &cline, &tok[count],NULL); + count++) { ; } /* we must get 7 tokens */ if (count < 7) { + TALLOC_FREE(frame); return False; } /* the 2nd and 4th, 6th columns must be integer */ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) { + TALLOC_FREE(frame); return False; } if (!isdigit((int)*tok[5])) { + TALLOC_FREE(frame); return False; } - /* if the user contains a ! then trim the first part of it */ + /* if the user contains a ! then trim the first part of it */ if ((p=strchr_m(tok[2],'!'))) { - fstring tmp; - fstrcpy(tmp,p+1); - fstrcpy(tok[2],tmp); + tok[2] = p+1; } buf->job = atoi(tok[1]); @@ -620,6 +656,7 @@ static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first) buf->time = EntryTime(tok, 4, count, 7); fstrcpy(buf->fs_user,tok[2]); fstrcpy(buf->fs_file,tok[2]); + TALLOC_FREE(frame); return True; } @@ -628,7 +665,7 @@ parse a lpq line here is an example of lpq output under qnx Spooler: /qnx/spooler, on node 1 -Printer: txt (ready) +Printer: txt (ready) 0000: root [job #1 ] active 1146 bytes /etc/profile 0001: root [job #2 ] ready 2378 bytes /etc/install 0002: root [job #3 ] ready 1146 bytes -- standard input -- @@ -636,9 +673,10 @@ Printer: txt (ready) static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first) { - fstring tok[7]; + char *tok[7]; int count=0; const char *cline = line; + TALLOC_CTX *frame = NULL; DEBUG(4,("antes [%s]\n", line)); @@ -653,30 +691,33 @@ static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first) string_sub(line,"]","",0); DEBUG(4,("despues 2 [%s]\n", line)); - for (count=0; count<7 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + frame = talloc_stackframe(); + for (count=0; count<7 && + next_token_talloc(frame,&cline,&tok[count],NULL); + count++) { ; } /* we must get 7 tokens */ if (count < 7) { + TALLOC_FREE(frame); return False; } /* the 3rd and 5th columns must be integer */ if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) { + TALLOC_FREE(frame); return False; } /* only take the last part of the filename */ { - fstring tmp; char *p = strrchr_m(tok[6],'/'); if (p) { - fstrcpy(tmp,p+1); - fstrcpy(tok[6],tmp); + tok[6] = p+1; } } - + buf->job = atoi(tok[2]); buf->size = atoi(tok[4]); buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED; @@ -684,6 +725,7 @@ static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first) buf->time = time(NULL); fstrcpy(buf->fs_user,tok[1]); fstrcpy(buf->fs_file,tok[6]); + TALLOC_FREE(frame); return True; } @@ -703,37 +745,47 @@ Local Printer 'lp2' (fjall): static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first) { - fstring tok[11]; + char *tok[11]; int count=0; const char *cline = line; + TALLOC_CTX *frame = talloc_stackframe(); /* handle the case of "(standard input)" as a filename */ string_sub(line,"stdin","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); - - for (count=0; count<11 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + + for (count=0; count<11 && + next_token_talloc(frame,&cline,&tok[count],NULL); + count++) { ; } /* we must get 11 tokens */ if (count < 11) { + TALLOC_FREE(frame); return False; } /* the first must be "active" or begin with an integer */ if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) { + TALLOC_FREE(frame); return False; } /* the 5th and 8th must be integer */ if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) { + TALLOC_FREE(frame); return False; } /* if the fname contains a space then use STDIN */ if (strchr_m(tok[6],' ')) { - fstrcpy(tok[6],"STDIN"); + tok[6] = talloc_strdup(frame, "STDIN"); + if (!tok[6]) { + TALLOC_FREE(frame); + return false; + } } /* only take the last part of the filename */ @@ -761,6 +813,7 @@ static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first) buf->time = time(NULL); fstrcpy(buf->fs_user,tok[1]); fstrcpy(buf->fs_file,tok[6]); + TALLOC_FREE(frame); return True; } @@ -944,16 +997,20 @@ parse a vlp line static bool parse_lpq_vlp(char *line,print_queue_struct *buf,bool first) { int toknum = 0; - fstring tok; + char *tok; + TALLOC_CTX *frame = talloc_stackframe(); const char *cline = line; /* First line is printer status */ - if (!isdigit(line[0])) return False; + if (!isdigit(line[0])) { + TALLOC_FREE(frame); + return False; + } /* Parse a print job entry */ - while(next_token(&cline, tok, NULL, sizeof(fstring))) { + while(next_token_talloc(frame, &cline, &tok, NULL)) { switch (toknum) { case 0: buf->job = atoi(tok); @@ -977,6 +1034,7 @@ static bool parse_lpq_vlp(char *line,print_queue_struct *buf,bool first) toknum++; } + TALLOC_FREE(frame); return True; } -- cgit From 75ca69243019ae1f422bd0e7c336e9f92a0d941c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Dec 2007 18:01:34 -0800 Subject: Remove another static fstring. Jeremy. (This used to be commit f9182bbe628cb5f5395a08b2e09d4a282a99d7dc) --- source3/printing/lpq_parse.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 56e228f219..6dcddb6f1b 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -444,7 +444,7 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) { /* must read two lines to process, therefore keep some values static */ static bool header_line_ok=False, base_prio_reset=False; - static fstring jobuser; + static char *jobuser; static int jobid; static int jobprio; static time_t jobtime; @@ -511,7 +511,11 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) buf->job = jobid; buf->status = jobstat; buf->priority = jobprio; - fstrcpy(buf->fs_user,jobuser); + if (jobuser) { + fstrcpy(buf->fs_user,jobuser); + } else { + buf->fs_user[0] = '\0'; + } TALLOC_FREE(frame); return True; @@ -548,7 +552,8 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) return False; } jobid = atoi(tok[1]); - fstrcpy(jobuser,tok[2]); + SAFE_FREE(jobuser); + jobuser = SMB_STRDUP(tok[2]); jobprio = atoi(tok[4]); /* process time */ -- cgit From 587cf54c61c9f1f7bcae431a82035fd942716c32 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Jan 2008 11:04:10 +0100 Subject: strtok -> strtok_r (This used to be commit fd34ce437057bb34cdc37f4b066e424000d36789) --- source3/printing/lpq_parse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 6dcddb6f1b..afa3b4850a 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -127,6 +127,7 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first) int count = 0; TALLOC_CTX *ctx = talloc_tos(); char *line2 = NULL; + char *saveptr; line2 = talloc_strdup(ctx, line); if (!line2) { @@ -144,10 +145,11 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first) #endif /* OSF1 */ /* FIXME: Use next_token_talloc rather than strtok! */ - tok[0] = strtok(line2," \t"); + tok[0] = strtok_r(line2," \t", &saveptr); count++; - while ((count < MAXTOK) && ((tok[count] = strtok(NULL," \t")) != NULL)) { + while ((count < MAXTOK) + && ((tok[count] = strtok_r(NULL, " \t", &saveptr)) != NULL)) { count++; } -- cgit From f3ddf2b23f352014530513765ec35df647ca2056 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 10 Jun 2008 14:15:01 +0200 Subject: Fix some scary FC9 warnings (cherry picked from commit 6b0fed09ea34409d1c61bae9121bdb38d4c68d62) (This used to be commit f1e85ff2bc4eea2c50d7d71caca16b9051ca5e8c) --- source3/printing/lpq_parse.c | 80 +++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'source3/printing/lpq_parse.c') diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index afa3b4850a..addf2d14aa 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -858,51 +858,52 @@ static bool parse_lpq_nt(char *line,print_queue_struct *buf,bool first) char terminator; } nt_lpq_line; - nt_lpq_line parse_line; + char parse_line_char[sizeof(nt_lpq_line)]; + nt_lpq_line *parse_line = (nt_lpq_line *)parse_line_char; #define LPRNT_PRINTING "Printing" #define LPRNT_WAITING "Waiting" #define LPRNT_PAUSED "Paused" - memset(&parse_line, '\0', sizeof(parse_line)); - strncpy((char *) &parse_line, line, sizeof(parse_line) -1); + memset(parse_line_char, '\0', sizeof(parse_line_char)); + strncpy(parse_line_char, line, sizeof(parse_line_char) -1); - if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) { + if (strlen(parse_line_char) != sizeof(parse_line_char) - 1) { return False; } /* Just want the first word in the owner field - the username */ - if (strchr_m(parse_line.owner, ' ')) { - *(strchr_m(parse_line.owner, ' ')) = '\0'; + if (strchr_m(parse_line->owner, ' ')) { + *(strchr_m(parse_line->owner, ' ')) = '\0'; } else { - parse_line.space1 = '\0'; + parse_line->space1 = '\0'; } /* Make sure we have an owner */ - if (!strlen(parse_line.owner)) { + if (!strlen(parse_line->owner)) { return False; } /* Make sure the status is valid */ - parse_line.space2 = '\0'; - trim_char(parse_line.status, '\0', ' '); - if (!strequal(parse_line.status, LPRNT_PRINTING) && - !strequal(parse_line.status, LPRNT_PAUSED) && - !strequal(parse_line.status, LPRNT_WAITING)) { + parse_line->space2 = '\0'; + trim_char(parse_line->status, '\0', ' '); + if (!strequal(parse_line->status, LPRNT_PRINTING) && + !strequal(parse_line->status, LPRNT_PAUSED) && + !strequal(parse_line->status, LPRNT_WAITING)) { return False; } - parse_line.space3 = '\0'; - trim_char(parse_line.jobname, '\0', ' '); + parse_line->space3 = '\0'; + trim_char(parse_line->jobname, '\0', ' '); - buf->job = atoi(parse_line.jobid); + buf->job = atoi(parse_line->jobid); buf->priority = 0; - buf->size = atoi(parse_line.size); + buf->size = atoi(parse_line->size); buf->time = time(NULL); - fstrcpy(buf->fs_user, parse_line.owner); - fstrcpy(buf->fs_file, parse_line.jobname); - if (strequal(parse_line.status, LPRNT_PRINTING)) { + fstrcpy(buf->fs_user, parse_line->owner); + fstrcpy(buf->fs_file, parse_line->jobname); + if (strequal(parse_line->status, LPRNT_PRINTING)) { buf->status = LPQ_PRINTING; - } else if (strequal(parse_line.status, LPRNT_PAUSED)) { + } else if (strequal(parse_line->status, LPRNT_PAUSED)) { buf->status = LPQ_PAUSED; } else { buf->status = LPQ_QUEUED; @@ -941,48 +942,49 @@ static bool parse_lpq_os2(char *line,print_queue_struct *buf,bool first) char terminator; } os2_lpq_line; - os2_lpq_line parse_line; + char parse_line_char[sizeof(os2_lpq_line)]; + os2_lpq_line *parse_line = (os2_lpq_line *)parse_line_char; #define LPROS2_PRINTING "Printing" #define LPROS2_WAITING "Queued" #define LPROS2_PAUSED "Paused" - memset(&parse_line, '\0', sizeof(parse_line)); - strncpy((char *) &parse_line, line, sizeof(parse_line) -1); + memset(parse_line_char, '\0', sizeof(parse_line_char)); + strncpy(parse_line_char, line, sizeof(parse_line_char) -1); - if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) { + if (strlen(parse_line_char) != sizeof(parse_line_char) - 1) { return False; } /* Get the jobid */ - buf->job = atoi(parse_line.jobid); + buf->job = atoi(parse_line->jobid); /* Get the job name */ - parse_line.space2[0] = '\0'; - trim_char(parse_line.jobname, '\0', ' '); - fstrcpy(buf->fs_file, parse_line.jobname); + parse_line->space2[0] = '\0'; + trim_char(parse_line->jobname, '\0', ' '); + fstrcpy(buf->fs_file, parse_line->jobname); buf->priority = 0; - buf->size = atoi(parse_line.size); + buf->size = atoi(parse_line->size); buf->time = time(NULL); /* Make sure we have an owner */ - if (!strlen(parse_line.owner)) { + if (!strlen(parse_line->owner)) { return False; } /* Make sure we have a valid status */ - parse_line.space4[0] = '\0'; - trim_char(parse_line.status, '\0', ' '); - if (!strequal(parse_line.status, LPROS2_PRINTING) && - !strequal(parse_line.status, LPROS2_PAUSED) && - !strequal(parse_line.status, LPROS2_WAITING)) { + parse_line->space4[0] = '\0'; + trim_char(parse_line->status, '\0', ' '); + if (!strequal(parse_line->status, LPROS2_PRINTING) && + !strequal(parse_line->status, LPROS2_PAUSED) && + !strequal(parse_line->status, LPROS2_WAITING)) { return False; } - fstrcpy(buf->fs_user, parse_line.owner); - if (strequal(parse_line.status, LPROS2_PRINTING)) { + fstrcpy(buf->fs_user, parse_line->owner); + if (strequal(parse_line->status, LPROS2_PRINTING)) { buf->status = LPQ_PRINTING; - } else if (strequal(parse_line.status, LPROS2_PAUSED)) { + } else if (strequal(parse_line->status, LPROS2_PAUSED)) { buf->status = LPQ_PAUSED; } else { buf->status = LPQ_QUEUED; -- cgit