/*
- Unix SMB/Netbios implementation.
- Version 3.0
+ Unix SMB/CIFS implementation.
lpq parsing routines
Copyright (C) Andrew Tridgell 2000
#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"};
}
#endif /* OSF1 */
+ /* FIXME: Use next_token rather than strtok! */
tok[0] = strtok(line2," \t");
count++;
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);
+ fstrcpy(buf->fs_user,tok[USERTOK]);
+ fstrcpy(buf->fs_file,tok[FILETOK]);
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;
- }
+ /* 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->file[sizeof(buf->file)-1] = '\0';
+ fstrterminate(buf->fs_file);
}
#ifdef PRIOTOK
#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++;
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->time = LPRng_time(tokarr[LPRNG_TIMETOK]);
- StrnCpy(buf->user,tokarr[LPRNG_USERTOK],sizeof(buf->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.
*/
- if ((cptr = strchr_m(buf->user,'@')) != NULL) {
- *cptr = '\0';
+ if ((ptr = strchr_m(buf->fs_user,'@')) != NULL) {
+ *ptr = '\0';
}
- StrnCpy(buf->file,tokarr[LPRNG_FILETOK],sizeof(buf->file)-1);
+ fstrcpy(buf->fs_file,tokarr[LPRNG_FILETOK]);
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;
- }
+ /* 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->file[sizeof(buf->file)-1] = '\0';
+ fstrterminate(buf->fs_file);
}
return(True);
{
fstring tok[11];
int count=0;
+ const char *cline = 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);
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 */
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);
+ fstrcpy(buf->fs_user,tok[3]);
+ fstrcpy(buf->fs_file,tok[2]);
}
else
{
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);
+ fstrcpy(buf->fs_user,tok[5]);
+ fstrcpy(buf->fs_file,tok[4]);
}
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;
/* 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 (!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);
- 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);
fstrcpy(tok[0],"STDIN");
buf->size = atoi(tok[1]);
- StrnCpy(buf->file,tok[0],sizeof(buf->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->user,jobuser,sizeof(buf->user)-1);
+ fstrcpy(buf->fs_user,jobuser);
return(True);
}
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++) ;
+ 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);
/* 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);
+ fstrcpy(jobuser,tok[2]);
jobprio = atoi(tok[4]);
/* process time */
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
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 */
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);
+ fstrcpy(buf->fs_user,tok[2]);
+ fstrcpy(buf->fs_file,tok[2]);
return(True);
}
{
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 */
- 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));
-
-
- 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)
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);
+ fstrcpy(buf->fs_user,tok[1]);
+ fstrcpy(buf->fs_file,tok[6]);
return(True);
}
{
fstring tok[11];
int count=0;
+ const char *cline = line;
/* 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);
- 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)
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;
- }
-
+ fstrcpy(buf->fs_user,tok[1]);
+ fstrcpy(buf->fs_file,tok[6]);
return(True);
}
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);
+ 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))
/* 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);
+ fstrcpy(buf->fs_file, parse_line.jobname);
buf->priority = 0;
buf->size = atoi(parse_line.size);
!strequal(parse_line.status, LPROS2_WAITING))
return(False);
- StrnCpy(buf->user, parse_line.owner, sizeof(buf->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))
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
{
int toknum = 0;
fstring tok;
+ const char *cline = line;
/* First line is printer status */
/* 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);
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++;
/****************************************************************************
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)
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;
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;
}