2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2000
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 static char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
24 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
27 /*******************************************************************
29 ********************************************************************/
30 static time_t EntryTime(fstring tok[], int ptr, int count, int minimum)
32 time_t jobtime,jobtime1;
34 jobtime = time(NULL); /* default case: take current time */
35 if (count >= minimum) {
37 int i, day, hour, min, sec;
40 for (i=0; i<13; i++) if (!strncmp(tok[ptr], Months[i],3)) break; /* Find month */
42 t = localtime(&jobtime);
43 day = atoi(tok[ptr+1]);
44 c=(char *)(tok[ptr+2]);
49 if(*(c+6) != 0)sec = atoi(c+6);
55 ((t->tm_mday == day)&&
56 (t->tm_hour*60+t->tm_min < hour*60+min)))))
57 t->tm_year--; /* last year's print job */
65 if (jobtime1 != (time_t)-1)
73 /****************************************************************************
76 here is an example of lpq output under bsd
78 Warning: no daemon present
79 Rank Owner Job Files Total Size
80 1st tridge 148 README 8096 bytes
82 here is an example of lpq output under osf/1
84 Warning: no daemon present
85 Rank Pri Owner Job Files Total Size
86 1st 0 tridge 148 README 8096 bytes
89 <allan@umich.edu> June 30, 1998.
90 Modified to handle file names with spaces, like the parse_lpq_lprng code
92 ****************************************************************************/
93 static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first)
101 #define TOTALTOK (count - 2)
109 #define TOTALTOK (count - 2)
123 length = strlen(line2);
124 if (line2[length-3] == ':')
129 tok[0] = strtok(line2," \t");
132 while (((tok[count] = strtok(NULL," \t")) != NULL) && (count < MAXTOK)) {
136 /* we must get at least NTOK tokens */
140 /* the Job and Total columns must be integer */
141 if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) return(False);
143 buf->job = atoi(tok[JOBTOK]);
144 buf->size = atoi(tok[TOTALTOK]);
145 buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED;
146 buf->time = time(NULL);
147 StrnCpy(buf->user,tok[USERTOK],sizeof(buf->user)-1);
148 StrnCpy(buf->file,tok[FILETOK],sizeof(buf->file)-1);
150 if ((FILETOK + 1) != TOTALTOK) {
154 bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
156 for (i = (FILETOK + 1); i < TOTALTOK; i++) {
157 safe_strcat(buf->file," ",bufsize);
158 safe_strcat(buf->file,tok[i],bufsize - 1);
159 bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
164 /* Ensure null termination. */
165 buf->file[sizeof(buf->file)-1] = '\0';
169 buf->priority = atoi(tok[PRIOTOK]);
178 LPRng_time modifies the current date by inserting the hour and minute from
179 the lpq output. The lpq time looks like "23:15:07"
181 <allan@umich.edu> June 30, 1998.
182 Modified to work with the re-written parse_lpq_lprng routine.
184 <J.P.M.v.Itegem@tue.nl> Dec 17,1999
185 Modified to work with lprng 3.16
186 With lprng 3.16 The lpq time looks like
189 "1999-12-16-23:15:07"
190 "1999-12-16-23:15:07.100"
193 static time_t LPRng_time(char *time_string)
198 jobtime = time(NULL); /* default case: take current time */
199 t = *localtime(&jobtime);
201 if ( atoi(time_string) < 24 ){
202 t.tm_hour = atoi(time_string);
203 t.tm_min = atoi(time_string+3);
204 t.tm_sec = atoi(time_string+6);
206 t.tm_year = atoi(time_string)-1900;
207 t.tm_mon = atoi(time_string+5)-1;
208 t.tm_mday = atoi(time_string+8);
209 t.tm_hour = atoi(time_string+11);
210 t.tm_min = atoi(time_string+14);
211 t.tm_sec = atoi(time_string+17);
213 jobtime = mktime(&t);
219 /****************************************************************************
220 parse a lprng lpq line
221 <allan@umich.edu> June 30, 1998.
222 Re-wrote this to handle file names with spaces, multiple file names on one
224 ****************************************************************************/
225 static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
227 #define LPRNG_RANKTOK 0
228 #define LPRNG_USERTOK 1
229 #define LPRNG_PRIOTOK 2
230 #define LPRNG_JOBTOK 3
231 #define LPRNG_FILETOK 4
232 #define LPRNG_TOTALTOK (num_tok - 2)
233 #define LPRNG_TIMETOK (num_tok - 1)
235 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
237 fstring tokarr[LPRNG_MAXTOK];
244 while(next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring)) && (num_tok < LPRNG_MAXTOK))
247 /* We must get at least LPRNG_NTOK tokens. */
248 if (num_tok < LPRNG_NTOK) {
252 if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
256 buf->job = atoi(tokarr[LPRNG_JOBTOK]);
257 buf->size = atoi(tokarr[LPRNG_TOTALTOK]);
259 if (strequal(tokarr[LPRNG_RANKTOK],"active")) {
260 buf->status = LPQ_PRINTING;
261 } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) {
262 buf->status = LPQ_QUEUED;
264 buf->status = LPQ_PAUSED;
267 buf->priority = *tokarr[LPRNG_PRIOTOK] -'A';
269 buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]);
271 StrnCpy(buf->user,tokarr[LPRNG_USERTOK],sizeof(buf->user)-1);
273 /* The '@hostname' prevents windows from displaying the printing icon
274 * for the current user on the taskbar. Plop in a null.
277 if ((cptr = strchr_m(buf->user,'@')) != NULL) {
281 StrnCpy(buf->file,tokarr[LPRNG_FILETOK],sizeof(buf->file)-1);
283 if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) {
287 bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
289 for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) {
290 safe_strcat(buf->file," ",bufsize);
291 safe_strcat(buf->file,tokarr[i],bufsize - 1);
292 bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
297 /* Ensure null termination. */
298 buf->file[sizeof(buf->file)-1] = '\0';
306 /*******************************************************************
307 parse lpq on an aix system
309 Queue Dev Status Job Files User PP % Blks Cp Rnk
310 ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
312 lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1
313 QUEUED 538 C.ps root@IEDVB 124 1 2
314 QUEUED 539 E.ps root@IEDVB 28 1 3
315 QUEUED 540 L.ps root@IEDVB 172 1 4
316 QUEUED 541 P.ps root@IEDVB 22 1 5
317 ********************************************************************/
318 static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first)
323 /* handle the case of "(standard input)" as a filename */
324 pstring_sub(line,"standard input","STDIN");
325 all_string_sub(line,"(","\"",0);
326 all_string_sub(line,")","\"",0);
330 next_token(&line,tok[count],NULL, sizeof(tok[count]));
333 /* we must get 6 tokens */
336 if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0)))
338 /* the 2nd and 5th columns must be integer */
339 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) return(False);
340 buf->size = atoi(tok[4]) * 1024;
341 /* if the fname contains a space then use STDIN */
342 if (strchr_m(tok[2],' '))
343 fstrcpy(tok[2],"STDIN");
345 /* only take the last part of the filename */
348 char *p = strrchr_m(tok[2],'/');
357 buf->job = atoi(tok[1]);
358 buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED;
360 buf->time = time(NULL);
361 StrnCpy(buf->user,tok[3],sizeof(buf->user)-1);
362 StrnCpy(buf->file,tok[2],sizeof(buf->file)-1);
366 DEBUG(6,("parse_lpq_aix count=%d\n", count));
372 /* the 4th and 9th columns must be integer */
373 if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) return(False);
374 buf->size = atoi(tok[8]) * 1024;
375 /* if the fname contains a space then use STDIN */
376 if (strchr_m(tok[4],' '))
377 fstrcpy(tok[4],"STDIN");
379 /* only take the last part of the filename */
382 char *p = strrchr_m(tok[4],'/');
391 buf->job = atoi(tok[3]);
392 buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED;
394 buf->time = time(NULL);
395 StrnCpy(buf->user,tok[5],sizeof(buf->user)-1);
396 StrnCpy(buf->file,tok[4],sizeof(buf->file)-1);
404 /****************************************************************************
406 here is an example of lpq output under hpux; note there's no space after -o !
408 ljplus-2153 user priority 0 Jan 19 08:14 on ljplus
410 server.c 110712 bytes
411 ljplus-2154 user priority 0 Jan 19 08:14 from client
412 (standard input) 7551 bytes
413 ****************************************************************************/
414 static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first)
416 /* must read two lines to process, therefore keep some values static */
417 static BOOL header_line_ok=False, base_prio_reset=False;
418 static fstring jobuser;
421 static time_t jobtime;
422 static int jobstat=LPQ_QUEUED;
423 /* to store minimum priority to print, lpstat command should be invoked
424 with -p option first, to work */
425 static int base_prio;
431 /* If a line begins with a horizontal TAB, it is a subline type */
433 if (line[0] == htab) { /* subline */
434 /* check if it contains the base priority */
435 if (!strncmp(line,"\tfence priority : ",18)) {
436 base_prio=atoi(&line[18]);
437 DEBUG(4, ("fence priority set at %d\n", base_prio));
439 if (!header_line_ok) return (False); /* incorrect header line */
440 /* handle the case of "(standard input)" as a filename */
441 pstring_sub(line,"standard input","STDIN");
442 all_string_sub(line,"(","\"",0);
443 all_string_sub(line,")","\"",0);
445 for (count=0; count<2 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
446 /* we must get 2 tokens */
447 if (count < 2) return(False);
449 /* the 2nd column must be integer */
450 if (!isdigit((int)*tok[1])) return(False);
452 /* if the fname contains a space then use STDIN */
453 if (strchr_m(tok[0],' '))
454 fstrcpy(tok[0],"STDIN");
456 buf->size = atoi(tok[1]);
457 StrnCpy(buf->file,tok[0],sizeof(buf->file)-1);
459 /* fill things from header line */
462 buf->status = jobstat;
463 buf->priority = jobprio;
464 StrnCpy(buf->user,jobuser,sizeof(buf->user)-1);
468 else { /* header line */
469 header_line_ok=False; /* reset it */
471 if (!base_prio_reset) {
472 base_prio=0; /* reset it */
473 base_prio_reset=True;
476 else if (base_prio) base_prio_reset=False;
478 /* handle the dash in the job id */
479 pstring_sub(line,"-"," ");
481 for (count=0; count<12 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
483 /* we must get 8 tokens */
484 if (count < 8) return(False);
486 /* first token must be printer name (cannot check ?) */
487 /* the 2nd, 5th & 7th column must be integer */
488 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) return(False);
489 jobid = atoi(tok[1]);
490 StrnCpy(jobuser,tok[2],sizeof(buf->user)-1);
491 jobprio = atoi(tok[4]);
494 jobtime=EntryTime(tok, 5, count, 8);
495 if (jobprio < base_prio) {
496 jobstat = LPQ_PAUSED;
497 DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n", jobid, jobprio, base_prio, jobstat));
500 jobstat = LPQ_QUEUED;
501 if ((count >8) && (((strequal(tok[8],"on")) ||
502 ((strequal(tok[8],"from")) &&
503 ((count > 10)&&(strequal(tok[10],"on")))))))
504 jobstat = LPQ_PRINTING;
507 header_line_ok=True; /* information is correct */
508 return(False); /* need subline info to include into queuelist */
513 /****************************************************************************
516 here is an example of "lpstat -o dcslw" output under sysv
518 dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw
519 dcslw-897 tridge 4712 Dec 20 10:30:30 being held
521 ****************************************************************************/
522 static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first)
529 * Handle the dash in the job id, but make sure that we skip over
530 * the printer name in case we have a dash in that.
531 * Patch from Dom.Mitchell@palmerharvey.co.uk.
535 * Move to the first space.
537 for (p = line ; !isspace(*p) && *p; p++)
541 * Back up until the last '-' character or
544 for (; (p >= line) && (*p != '-'); p--)
547 if((p >= line) && (*p == '-'))
550 for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++)
553 /* we must get 7 tokens */
557 /* the 2nd and 4th, 6th columns must be integer */
558 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3]))
560 if (!isdigit((int)*tok[5]))
563 /* if the user contains a ! then trim the first part of it */
564 if ((p=strchr_m(tok[2],'!'))) {
570 buf->job = atoi(tok[1]);
571 buf->size = atoi(tok[3]);
572 if (count > 7 && strequal(tok[7],"on"))
573 buf->status = LPQ_PRINTING;
574 else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held"))
575 buf->status = LPQ_PAUSED;
577 buf->status = LPQ_QUEUED;
579 buf->time = EntryTime(tok, 4, count, 7);
580 StrnCpy(buf->user,tok[2],sizeof(buf->user)-1);
581 StrnCpy(buf->file,tok[2],sizeof(buf->file)-1);
585 /****************************************************************************
588 here is an example of lpq output under qnx
589 Spooler: /qnx/spooler, on node 1
591 0000: root [job #1 ] active 1146 bytes /etc/profile
592 0001: root [job #2 ] ready 2378 bytes /etc/install
593 0002: root [job #3 ] ready 1146 bytes -- standard input --
594 ****************************************************************************/
595 static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first)
600 DEBUG(4,("antes [%s]\n", line));
602 /* handle the case of "-- standard input --" as a filename */
603 pstring_sub(line,"standard input","STDIN");
604 DEBUG(4,("despues [%s]\n", line));
605 all_string_sub(line,"-- ","\"",0);
606 all_string_sub(line," --","\"",0);
607 DEBUG(4,("despues 1 [%s]\n", line));
609 pstring_sub(line,"[job #","");
610 pstring_sub(line,"]","");
611 DEBUG(4,("despues 2 [%s]\n", line));
615 for (count=0; count<7 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
617 /* we must get 7 tokens */
621 /* the 3rd and 5th columns must be integer */
622 if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) return(False);
624 /* only take the last part of the filename */
627 char *p = strrchr_m(tok[6],'/');
636 buf->job = atoi(tok[2]);
637 buf->size = atoi(tok[4]);
638 buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
640 buf->time = time(NULL);
641 StrnCpy(buf->user,tok[1],sizeof(buf->user)-1);
642 StrnCpy(buf->file,tok[6],sizeof(buf->file)-1);
647 /****************************************************************************
648 parse a lpq line for the plp printing system
649 Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
651 redone by tridge. Here is a sample queue:
653 Local Printer 'lp2' (fjall):
654 Printing (started at Jun 15 13:33:58, attempt 1).
655 Rank Owner Pr Opt Job Host Files Size Date
656 active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
657 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
659 ****************************************************************************/
660 static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first)
665 /* handle the case of "(standard input)" as a filename */
666 pstring_sub(line,"stdin","STDIN");
667 all_string_sub(line,"(","\"",0);
668 all_string_sub(line,")","\"",0);
670 for (count=0; count<11 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
672 /* we must get 11 tokens */
676 /* the first must be "active" or begin with an integer */
677 if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0]))
680 /* the 5th and 8th must be integer */
681 if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7]))
684 /* if the fname contains a space then use STDIN */
685 if (strchr_m(tok[6],' '))
686 fstrcpy(tok[6],"STDIN");
688 /* only take the last part of the filename */
691 char *p = strrchr_m(tok[6],'/');
700 buf->job = atoi(tok[4]);
702 buf->size = atoi(tok[7]);
703 if (strchr_m(tok[7],'K'))
705 if (strchr_m(tok[7],'M'))
706 buf->size *= 1024*1024;
708 buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;
710 buf->time = time(NULL);
711 StrnCpy(buf->user,tok[1],sizeof(buf->user)-1);
712 StrnCpy(buf->file,tok[6],sizeof(buf->file)-1);
716 /****************************************************************************
719 here is an example of "qstat -l -d qms" output under softq
721 Queue qms: 2 jobs; daemon active (313); enabled; accepting;
722 job-ID submission-time pri size owner title
723 205980: H 98/03/09 13:04:05 0 15733 stephenf chap1.ps
724 206086:> 98/03/12 17:24:40 0 659 chris -
725 206087: 98/03/12 17:24:45 0 4876 chris -
726 Total: 21268 bytes in queue
729 ****************************************************************************/
730 static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first)
735 /* mung all the ":"s to spaces*/
736 pstring_sub(line,":"," ");
738 for (count=0; count<10 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
740 /* we must get 9 tokens */
744 /* the 1st and 7th columns must be integer */
745 if (!isdigit((int)*tok[0]) || !isdigit((int)*tok[6])) return(False);
746 /* if the 2nd column is either '>' or 'H' then the 7th and 8th must be
747 * integer, else it's the 6th and 7th that must be
749 if (*tok[1] == 'H' || *tok[1] == '>')
751 if (!isdigit((int)*tok[7]))
753 buf->status = *tok[1] == '>' ? LPQ_PRINTING : LPQ_PAUSED;
758 if (!isdigit((int)*tok[5]))
760 buf->status = LPQ_QUEUED;
765 buf->job = atoi(tok[0]);
766 buf->size = atoi(tok[count+6]);
767 buf->priority = atoi(tok[count+5]);
768 StrnCpy(buf->user,tok[count+7],sizeof(buf->user)-1);
769 StrnCpy(buf->file,tok[count+8],sizeof(buf->file)-1);
770 buf->time = time(NULL); /* default case: take current time */
775 t = localtime(&buf->time);
776 t->tm_mday = atoi(tok[count+2]+6);
777 t->tm_mon = atoi(tok[count+2]+3);
778 switch (*tok[count+2])
780 case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]); break;
781 default: t->tm_year = atoi(tok[count+2]); break;
784 t->tm_hour = atoi(tok[count+3]);
785 t->tm_min = atoi(tok[count+4]);
786 t->tm_sec = atoi(tok[count+5]);
788 if (jobtime != (time_t)-1)
795 /*******************************************************************
796 parse lpq on an NT system
798 Windows 2000 LPD Server
799 Printer \\10.0.0.2\NP17PCL (Paused)
801 Owner Status Jobname Job-Id Size Pages Priority
802 ----------------------------------------------------------------------------
803 root (9.99. Printing /usr/lib/rhs/rhs-pr 3 625 0 1
804 root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1
805 jmcd Waiting Re: Samba Open Sour 26 32476 1 1
807 ********************************************************************/
808 static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first)
810 #define LPRNT_OWNSIZ 11
811 #define LPRNT_STATSIZ 9
812 #define LPRNT_JOBSIZ 19
813 #define LPRNT_IDSIZ 6
814 #define LPRNT_SIZSIZ 9
817 char owner[LPRNT_OWNSIZ];
819 char status[LPRNT_STATSIZ];
821 char jobname[LPRNT_JOBSIZ];
823 char jobid[LPRNT_IDSIZ];
825 char size[LPRNT_SIZSIZ];
829 nt_lpq_line parse_line;
830 #define LPRNT_PRINTING "Printing"
831 #define LPRNT_WAITING "Waiting"
832 #define LPRNT_PAUSED "Paused"
834 memset(&parse_line, '\0', sizeof(parse_line));
835 strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
837 if (strlen((char *) &parse_line) != sizeof(parse_line) - 1)
840 /* Just want the first word in the owner field - the username */
841 if (strchr_m(parse_line.owner, ' '))
842 *(strchr_m(parse_line.owner, ' ')) = '\0';
844 parse_line.space1 = '\0';
846 /* Make sure we have an owner */
847 if (!strlen(parse_line.owner))
850 /* Make sure the status is valid */
851 parse_line.space2 = '\0';
852 trim_string(parse_line.status, NULL, " ");
853 if (!strequal(parse_line.status, LPRNT_PRINTING) &&
854 !strequal(parse_line.status, LPRNT_PAUSED) &&
855 !strequal(parse_line.status, LPRNT_WAITING))
858 parse_line.space3 = '\0';
859 trim_string(parse_line.jobname, NULL, " ");
861 buf->job = atoi(parse_line.jobid);
863 buf->size = atoi(parse_line.size);
864 buf->time = time(NULL);
865 StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1);
866 StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1);
867 if (strequal(parse_line.status, LPRNT_PRINTING))
868 buf->status = LPQ_PRINTING;
869 else if (strequal(parse_line.status, LPRNT_PAUSED))
870 buf->status = LPQ_PAUSED;
872 buf->status = LPQ_QUEUED;
877 /*******************************************************************
878 parse lpq on an OS2 system
880 JobID File Name Rank Size Status Comment
881 ----- --------------- ------ -------- ------------ ------------
882 3 Control 1 68 Queued root@psflinu
883 4 /etc/motd 2 11666 Queued root@psflinu
885 ********************************************************************/
886 static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first)
888 #define LPROS2_IDSIZ 5
889 #define LPROS2_JOBSIZ 15
890 #define LPROS2_SIZSIZ 8
891 #define LPROS2_STATSIZ 12
892 #define LPROS2_OWNSIZ 12
895 char jobid[LPROS2_IDSIZ];
897 char jobname[LPROS2_JOBSIZ];
899 char size[LPROS2_SIZSIZ];
901 char status[LPROS2_STATSIZ];
903 char owner[LPROS2_OWNSIZ];
907 os2_lpq_line parse_line;
908 #define LPROS2_PRINTING "Printing"
909 #define LPROS2_WAITING "Queued"
910 #define LPROS2_PAUSED "Paused"
912 memset(&parse_line, '\0', sizeof(parse_line));
913 strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
915 if (strlen((char *) &parse_line) != sizeof(parse_line) - 1)
919 buf->job = atoi(parse_line.jobid);
921 /* Get the job name */
922 parse_line.space2[0] = '\0';
923 trim_string(parse_line.jobname, NULL, " ");
924 StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1);
927 buf->size = atoi(parse_line.size);
928 buf->time = time(NULL);
930 /* Make sure we have an owner */
931 if (!strlen(parse_line.owner))
934 /* Make sure we have a valid status */
935 parse_line.space4[0] = '\0';
936 trim_string(parse_line.status, NULL, " ");
937 if (!strequal(parse_line.status, LPROS2_PRINTING) &&
938 !strequal(parse_line.status, LPROS2_PAUSED) &&
939 !strequal(parse_line.status, LPROS2_WAITING))
942 StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1);
943 if (strequal(parse_line.status, LPROS2_PRINTING))
944 buf->status = LPQ_PRINTING;
945 else if (strequal(parse_line.status, LPROS2_PAUSED))
946 buf->status = LPQ_PAUSED;
948 buf->status = LPQ_QUEUED;
953 static char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL };
954 static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };
955 static char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL };
959 /****************************************************************************
961 ****************************************************************************/
962 static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first)
967 /* First line is printer status */
969 if (!isdigit(line[0])) return False;
971 /* Parse a print job entry */
973 while(next_token(&line, tok, NULL, sizeof(fstring))) {
976 buf->job = atoi(tok);
979 buf->size = atoi(tok);
982 buf->status = atoi(tok);
985 buf->time = atoi(tok);
988 fstrcpy(buf->user, tok);
991 fstrcpy(buf->file, tok);
1000 #endif /* DEVELOPER */
1002 /****************************************************************************
1003 parse a lpq line. Choose printing style
1004 ****************************************************************************/
1005 BOOL parse_lpq_entry(int snum,char *line,
1006 print_queue_struct *buf,
1007 print_status_struct *status,BOOL first)
1011 switch (lp_printing(snum))
1014 ret = parse_lpq_sysv(line,buf,first);
1017 ret = parse_lpq_aix(line,buf,first);
1020 ret = parse_lpq_hpux(line,buf,first);
1023 ret = parse_lpq_qnx(line,buf,first);
1026 ret = parse_lpq_lprng(line,buf,first);
1029 ret = parse_lpq_plp(line,buf,first);
1032 ret = parse_lpq_softq(line,buf,first);
1035 ret = parse_lpq_nt(line,buf,first);
1038 ret = parse_lpq_os2(line,buf,first);
1043 ret = parse_lpq_vlp(line,buf,first);
1045 #endif /* DEVELOPER */
1047 ret = parse_lpq_bsd(line,buf,first);
1051 /* We don't want the newline in the status message. */
1053 char *p = strchr_m(line,'\n');
1057 /* in the LPRNG case, we skip lines starting by a space.*/
1058 if (line && !ret && (lp_printing(snum)==PRINT_LPRNG) )
1067 /* a few simple checks to see if the line might be a
1068 printer status line:
1069 handle them so that most severe condition is shown */
1073 switch (status->status) {
1075 for (i=0; stat0_strings[i]; i++)
1076 if (strstr(line,stat0_strings[i])) {
1077 StrnCpy(status->message,line,sizeof(status->message)-1);
1078 status->status=LPSTAT_OK;
1081 case LPSTAT_STOPPED:
1082 for (i=0; stat1_strings[i]; i++)
1083 if (strstr(line,stat1_strings[i])) {
1084 StrnCpy(status->message,line,sizeof(status->message)-1);
1085 status->status=LPSTAT_STOPPED;
1089 for (i=0; stat2_strings[i]; i++)
1090 if (strstr(line,stat2_strings[i])) {
1091 StrnCpy(status->message,line,sizeof(status->message)-1);
1092 status->status=LPSTAT_ERROR;