2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 2000
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 static char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
25 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
28 /*******************************************************************
30 ********************************************************************/
31 static time_t EntryTime(fstring tok[], int ptr, int count, int minimum)
33 time_t jobtime,jobtime1;
35 jobtime = time(NULL); /* default case: take current time */
36 if (count >= minimum) {
38 int i, day, hour, min, sec;
41 for (i=0; i<13; i++) if (!strncmp(tok[ptr], Months[i],3)) break; /* Find month */
43 t = localtime(&jobtime);
44 day = atoi(tok[ptr+1]);
45 c=(char *)(tok[ptr+2]);
50 if(*(c+6) != 0)sec = atoi(c+6);
56 ((t->tm_mday == day)&&
57 (t->tm_hour*60+t->tm_min < hour*60+min)))))
58 t->tm_year--; /* last year's print job */
66 if (jobtime1 != (time_t)-1)
74 /****************************************************************************
77 here is an example of lpq output under bsd
79 Warning: no daemon present
80 Rank Owner Job Files Total Size
81 1st tridge 148 README 8096 bytes
83 here is an example of lpq output under osf/1
85 Warning: no daemon present
86 Rank Pri Owner Job Files Total Size
87 1st 0 tridge 148 README 8096 bytes
90 <allan@umich.edu> June 30, 1998.
91 Modified to handle file names with spaces, like the parse_lpq_lprng code
93 ****************************************************************************/
94 static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first)
102 #define TOTALTOK (count - 2)
110 #define TOTALTOK (count - 2)
124 length = strlen(line2);
125 if (line2[length-3] == ':')
130 tok[0] = strtok(line2," \t");
133 while (((tok[count] = strtok(NULL," \t")) != NULL) && (count < MAXTOK)) {
137 /* we must get at least NTOK tokens */
141 /* the Job and Total columns must be integer */
142 if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) return(False);
144 buf->job = atoi(tok[JOBTOK]);
145 buf->size = atoi(tok[TOTALTOK]);
146 buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED;
147 buf->time = time(NULL);
148 StrnCpy(buf->user,tok[USERTOK],sizeof(buf->user)-1);
149 StrnCpy(buf->file,tok[FILETOK],sizeof(buf->file)-1);
151 if ((FILETOK + 1) != TOTALTOK) {
155 bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
157 for (i = (FILETOK + 1); i < TOTALTOK; i++) {
158 safe_strcat(buf->file," ",bufsize);
159 safe_strcat(buf->file,tok[i],bufsize - 1);
160 bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
165 /* Ensure null termination. */
166 buf->file[sizeof(buf->file)-1] = '\0';
170 buf->priority = atoi(tok[PRIOTOK]);
179 LPRng_time modifies the current date by inserting the hour and minute from
180 the lpq output. The lpq time looks like "23:15:07"
182 <allan@umich.edu> June 30, 1998.
183 Modified to work with the re-written parse_lpq_lprng routine.
185 <J.P.M.v.Itegem@tue.nl> Dec 17,1999
186 Modified to work with lprng 3.16
187 With lprng 3.16 The lpq time looks like
190 "1999-12-16-23:15:07"
191 "1999-12-16-23:15:07.100"
194 static time_t LPRng_time(char *time_string)
199 jobtime = time(NULL); /* default case: take current time */
200 t = *localtime(&jobtime);
202 if ( atoi(time_string) < 24 ){
203 t.tm_hour = atoi(time_string);
204 t.tm_min = atoi(time_string+3);
205 t.tm_sec = atoi(time_string+6);
207 t.tm_year = atoi(time_string)-1900;
208 t.tm_mon = atoi(time_string+5)-1;
209 t.tm_mday = atoi(time_string+8);
210 t.tm_hour = atoi(time_string+11);
211 t.tm_min = atoi(time_string+14);
212 t.tm_sec = atoi(time_string+17);
214 jobtime = mktime(&t);
220 /****************************************************************************
221 parse a lprng lpq line
222 <allan@umich.edu> June 30, 1998.
223 Re-wrote this to handle file names with spaces, multiple file names on one
225 ****************************************************************************/
226 static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
228 #define LPRNG_RANKTOK 0
229 #define LPRNG_USERTOK 1
230 #define LPRNG_PRIOTOK 2
231 #define LPRNG_JOBTOK 3
232 #define LPRNG_FILETOK 4
233 #define LPRNG_TOTALTOK (num_tok - 2)
234 #define LPRNG_TIMETOK (num_tok - 1)
236 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
238 fstring tokarr[LPRNG_MAXTOK];
245 while(next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring)) && (num_tok < LPRNG_MAXTOK))
248 /* We must get at least LPRNG_NTOK tokens. */
249 if (num_tok < LPRNG_NTOK) {
253 if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
257 buf->job = atoi(tokarr[LPRNG_JOBTOK]);
258 buf->size = atoi(tokarr[LPRNG_TOTALTOK]);
260 if (strequal(tokarr[LPRNG_RANKTOK],"active")) {
261 buf->status = LPQ_PRINTING;
262 } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) {
263 buf->status = LPQ_QUEUED;
265 buf->status = LPQ_PAUSED;
268 buf->priority = *tokarr[LPRNG_PRIOTOK] -'A';
270 buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]);
272 StrnCpy(buf->user,tokarr[LPRNG_USERTOK],sizeof(buf->user)-1);
274 /* The '@hostname' prevents windows from displaying the printing icon
275 * for the current user on the taskbar. Plop in a null.
278 if ((cptr = strchr_m(buf->user,'@')) != NULL) {
282 StrnCpy(buf->file,tokarr[LPRNG_FILETOK],sizeof(buf->file)-1);
284 if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) {
288 bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
290 for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) {
291 safe_strcat(buf->file," ",bufsize);
292 safe_strcat(buf->file,tokarr[i],bufsize - 1);
293 bufsize = sizeof(buf->file) - strlen(buf->file) - 1;
298 /* Ensure null termination. */
299 buf->file[sizeof(buf->file)-1] = '\0';
307 /*******************************************************************
308 parse lpq on an aix system
310 Queue Dev Status Job Files User PP % Blks Cp Rnk
311 ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
313 lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1
314 QUEUED 538 C.ps root@IEDVB 124 1 2
315 QUEUED 539 E.ps root@IEDVB 28 1 3
316 QUEUED 540 L.ps root@IEDVB 172 1 4
317 QUEUED 541 P.ps root@IEDVB 22 1 5
318 ********************************************************************/
319 static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first)
324 /* handle the case of "(standard input)" as a filename */
325 pstring_sub(line,"standard input","STDIN");
326 all_string_sub(line,"(","\"",0);
327 all_string_sub(line,")","\"",0);
331 next_token(&line,tok[count],NULL, sizeof(tok[count]));
334 /* we must get 6 tokens */
337 if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0)))
339 /* the 2nd and 5th columns must be integer */
340 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) return(False);
341 buf->size = atoi(tok[4]) * 1024;
342 /* if the fname contains a space then use STDIN */
343 if (strchr_m(tok[2],' '))
344 fstrcpy(tok[2],"STDIN");
346 /* only take the last part of the filename */
349 char *p = strrchr_m(tok[2],'/');
358 buf->job = atoi(tok[1]);
359 buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED;
361 buf->time = time(NULL);
362 StrnCpy(buf->user,tok[3],sizeof(buf->user)-1);
363 StrnCpy(buf->file,tok[2],sizeof(buf->file)-1);
367 DEBUG(6,("parse_lpq_aix count=%d\n", count));
373 /* the 4th and 9th columns must be integer */
374 if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) return(False);
375 buf->size = atoi(tok[8]) * 1024;
376 /* if the fname contains a space then use STDIN */
377 if (strchr_m(tok[4],' '))
378 fstrcpy(tok[4],"STDIN");
380 /* only take the last part of the filename */
383 char *p = strrchr_m(tok[4],'/');
392 buf->job = atoi(tok[3]);
393 buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED;
395 buf->time = time(NULL);
396 StrnCpy(buf->user,tok[5],sizeof(buf->user)-1);
397 StrnCpy(buf->file,tok[4],sizeof(buf->file)-1);
405 /****************************************************************************
407 here is an example of lpq output under hpux; note there's no space after -o !
409 ljplus-2153 user priority 0 Jan 19 08:14 on ljplus
411 server.c 110712 bytes
412 ljplus-2154 user priority 0 Jan 19 08:14 from client
413 (standard input) 7551 bytes
414 ****************************************************************************/
415 static BOOL parse_lpq_hpux(char * line, print_queue_struct *buf, BOOL first)
417 /* must read two lines to process, therefore keep some values static */
418 static BOOL header_line_ok=False, base_prio_reset=False;
419 static fstring jobuser;
422 static time_t jobtime;
423 static int jobstat=LPQ_QUEUED;
424 /* to store minimum priority to print, lpstat command should be invoked
425 with -p option first, to work */
426 static int base_prio;
432 /* If a line begins with a horizontal TAB, it is a subline type */
434 if (line[0] == htab) { /* subline */
435 /* check if it contains the base priority */
436 if (!strncmp(line,"\tfence priority : ",18)) {
437 base_prio=atoi(&line[18]);
438 DEBUG(4, ("fence priority set at %d\n", base_prio));
440 if (!header_line_ok) return (False); /* incorrect header line */
441 /* handle the case of "(standard input)" as a filename */
442 pstring_sub(line,"standard input","STDIN");
443 all_string_sub(line,"(","\"",0);
444 all_string_sub(line,")","\"",0);
446 for (count=0; count<2 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
447 /* we must get 2 tokens */
448 if (count < 2) return(False);
450 /* the 2nd column must be integer */
451 if (!isdigit((int)*tok[1])) return(False);
453 /* if the fname contains a space then use STDIN */
454 if (strchr_m(tok[0],' '))
455 fstrcpy(tok[0],"STDIN");
457 buf->size = atoi(tok[1]);
458 StrnCpy(buf->file,tok[0],sizeof(buf->file)-1);
460 /* fill things from header line */
463 buf->status = jobstat;
464 buf->priority = jobprio;
465 StrnCpy(buf->user,jobuser,sizeof(buf->user)-1);
469 else { /* header line */
470 header_line_ok=False; /* reset it */
472 if (!base_prio_reset) {
473 base_prio=0; /* reset it */
474 base_prio_reset=True;
477 else if (base_prio) base_prio_reset=False;
479 /* handle the dash in the job id */
480 pstring_sub(line,"-"," ");
482 for (count=0; count<12 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
484 /* we must get 8 tokens */
485 if (count < 8) return(False);
487 /* first token must be printer name (cannot check ?) */
488 /* the 2nd, 5th & 7th column must be integer */
489 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) return(False);
490 jobid = atoi(tok[1]);
491 StrnCpy(jobuser,tok[2],sizeof(buf->user)-1);
492 jobprio = atoi(tok[4]);
495 jobtime=EntryTime(tok, 5, count, 8);
496 if (jobprio < base_prio) {
497 jobstat = LPQ_PAUSED;
498 DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n", jobid, jobprio, base_prio, jobstat));
501 jobstat = LPQ_QUEUED;
502 if ((count >8) && (((strequal(tok[8],"on")) ||
503 ((strequal(tok[8],"from")) &&
504 ((count > 10)&&(strequal(tok[10],"on")))))))
505 jobstat = LPQ_PRINTING;
508 header_line_ok=True; /* information is correct */
509 return(False); /* need subline info to include into queuelist */
514 /****************************************************************************
517 here is an example of "lpstat -o dcslw" output under sysv
519 dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw
520 dcslw-897 tridge 4712 Dec 20 10:30:30 being held
522 ****************************************************************************/
523 static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first)
530 * Handle the dash in the job id, but make sure that we skip over
531 * the printer name in case we have a dash in that.
532 * Patch from Dom.Mitchell@palmerharvey.co.uk.
536 * Move to the first space.
538 for (p = line ; !isspace(*p) && *p; p++)
542 * Back up until the last '-' character or
545 for (; (p >= line) && (*p != '-'); p--)
548 if((p >= line) && (*p == '-'))
551 for (count=0; count<9 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++)
554 /* we must get 7 tokens */
558 /* the 2nd and 4th, 6th columns must be integer */
559 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3]))
561 if (!isdigit((int)*tok[5]))
564 /* if the user contains a ! then trim the first part of it */
565 if ((p=strchr_m(tok[2],'!'))) {
571 buf->job = atoi(tok[1]);
572 buf->size = atoi(tok[3]);
573 if (count > 7 && strequal(tok[7],"on"))
574 buf->status = LPQ_PRINTING;
575 else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held"))
576 buf->status = LPQ_PAUSED;
578 buf->status = LPQ_QUEUED;
580 buf->time = EntryTime(tok, 4, count, 7);
581 StrnCpy(buf->user,tok[2],sizeof(buf->user)-1);
582 StrnCpy(buf->file,tok[2],sizeof(buf->file)-1);
586 /****************************************************************************
589 here is an example of lpq output under qnx
590 Spooler: /qnx/spooler, on node 1
592 0000: root [job #1 ] active 1146 bytes /etc/profile
593 0001: root [job #2 ] ready 2378 bytes /etc/install
594 0002: root [job #3 ] ready 1146 bytes -- standard input --
595 ****************************************************************************/
596 static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first)
601 DEBUG(4,("antes [%s]\n", line));
603 /* handle the case of "-- standard input --" as a filename */
604 pstring_sub(line,"standard input","STDIN");
605 DEBUG(4,("despues [%s]\n", line));
606 all_string_sub(line,"-- ","\"",0);
607 all_string_sub(line," --","\"",0);
608 DEBUG(4,("despues 1 [%s]\n", line));
610 pstring_sub(line,"[job #","");
611 pstring_sub(line,"]","");
612 DEBUG(4,("despues 2 [%s]\n", line));
616 for (count=0; count<7 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
618 /* we must get 7 tokens */
622 /* the 3rd and 5th columns must be integer */
623 if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) return(False);
625 /* only take the last part of the filename */
628 char *p = strrchr_m(tok[6],'/');
637 buf->job = atoi(tok[2]);
638 buf->size = atoi(tok[4]);
639 buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
641 buf->time = time(NULL);
642 StrnCpy(buf->user,tok[1],sizeof(buf->user)-1);
643 StrnCpy(buf->file,tok[6],sizeof(buf->file)-1);
648 /****************************************************************************
649 parse a lpq line for the plp printing system
650 Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
652 redone by tridge. Here is a sample queue:
654 Local Printer 'lp2' (fjall):
655 Printing (started at Jun 15 13:33:58, attempt 1).
656 Rank Owner Pr Opt Job Host Files Size Date
657 active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
658 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
660 ****************************************************************************/
661 static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first)
666 /* handle the case of "(standard input)" as a filename */
667 pstring_sub(line,"stdin","STDIN");
668 all_string_sub(line,"(","\"",0);
669 all_string_sub(line,")","\"",0);
671 for (count=0; count<11 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
673 /* we must get 11 tokens */
677 /* the first must be "active" or begin with an integer */
678 if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0]))
681 /* the 5th and 8th must be integer */
682 if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7]))
685 /* if the fname contains a space then use STDIN */
686 if (strchr_m(tok[6],' '))
687 fstrcpy(tok[6],"STDIN");
689 /* only take the last part of the filename */
692 char *p = strrchr_m(tok[6],'/');
701 buf->job = atoi(tok[4]);
703 buf->size = atoi(tok[7]);
704 if (strchr_m(tok[7],'K'))
706 if (strchr_m(tok[7],'M'))
707 buf->size *= 1024*1024;
709 buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;
711 buf->time = time(NULL);
712 StrnCpy(buf->user,tok[1],sizeof(buf->user)-1);
713 StrnCpy(buf->file,tok[6],sizeof(buf->file)-1);
717 /****************************************************************************
720 here is an example of "qstat -l -d qms" output under softq
722 Queue qms: 2 jobs; daemon active (313); enabled; accepting;
723 job-ID submission-time pri size owner title
724 205980: H 98/03/09 13:04:05 0 15733 stephenf chap1.ps
725 206086:> 98/03/12 17:24:40 0 659 chris -
726 206087: 98/03/12 17:24:45 0 4876 chris -
727 Total: 21268 bytes in queue
730 ****************************************************************************/
731 static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first)
736 /* mung all the ":"s to spaces*/
737 pstring_sub(line,":"," ");
739 for (count=0; count<10 && next_token(&line,tok[count],NULL,sizeof(tok[count])); count++) ;
741 /* we must get 9 tokens */
745 /* the 1st and 7th columns must be integer */
746 if (!isdigit((int)*tok[0]) || !isdigit((int)*tok[6])) return(False);
747 /* if the 2nd column is either '>' or 'H' then the 7th and 8th must be
748 * integer, else it's the 6th and 7th that must be
750 if (*tok[1] == 'H' || *tok[1] == '>')
752 if (!isdigit((int)*tok[7]))
754 buf->status = *tok[1] == '>' ? LPQ_PRINTING : LPQ_PAUSED;
759 if (!isdigit((int)*tok[5]))
761 buf->status = LPQ_QUEUED;
766 buf->job = atoi(tok[0]);
767 buf->size = atoi(tok[count+6]);
768 buf->priority = atoi(tok[count+5]);
769 StrnCpy(buf->user,tok[count+7],sizeof(buf->user)-1);
770 StrnCpy(buf->file,tok[count+8],sizeof(buf->file)-1);
771 buf->time = time(NULL); /* default case: take current time */
776 t = localtime(&buf->time);
777 t->tm_mday = atoi(tok[count+2]+6);
778 t->tm_mon = atoi(tok[count+2]+3);
779 switch (*tok[count+2])
781 case 7: case 8: case 9: t->tm_year = atoi(tok[count+2]); break;
782 default: t->tm_year = atoi(tok[count+2]); break;
785 t->tm_hour = atoi(tok[count+3]);
786 t->tm_min = atoi(tok[count+4]);
787 t->tm_sec = atoi(tok[count+5]);
789 if (jobtime != (time_t)-1)
796 /*******************************************************************
797 parse lpq on an NT system
799 Windows 2000 LPD Server
800 Printer \\10.0.0.2\NP17PCL (Paused)
802 Owner Status Jobname Job-Id Size Pages Priority
803 ----------------------------------------------------------------------------
804 root (9.99. Printing /usr/lib/rhs/rhs-pr 3 625 0 1
805 root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1
806 jmcd Waiting Re: Samba Open Sour 26 32476 1 1
808 ********************************************************************/
809 static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first)
811 #define LPRNT_OWNSIZ 11
812 #define LPRNT_STATSIZ 9
813 #define LPRNT_JOBSIZ 19
814 #define LPRNT_IDSIZ 6
815 #define LPRNT_SIZSIZ 9
818 char owner[LPRNT_OWNSIZ];
820 char status[LPRNT_STATSIZ];
822 char jobname[LPRNT_JOBSIZ];
824 char jobid[LPRNT_IDSIZ];
826 char size[LPRNT_SIZSIZ];
830 nt_lpq_line parse_line;
831 #define LPRNT_PRINTING "Printing"
832 #define LPRNT_WAITING "Waiting"
833 #define LPRNT_PAUSED "Paused"
835 memset(&parse_line, '\0', sizeof(parse_line));
836 strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
838 if (strlen((char *) &parse_line) != sizeof(parse_line) - 1)
841 /* Just want the first word in the owner field - the username */
842 if (strchr_m(parse_line.owner, ' '))
843 *(strchr_m(parse_line.owner, ' ')) = '\0';
845 parse_line.space1 = '\0';
847 /* Make sure we have an owner */
848 if (!strlen(parse_line.owner))
851 /* Make sure the status is valid */
852 parse_line.space2 = '\0';
853 trim_string(parse_line.status, NULL, " ");
854 if (!strequal(parse_line.status, LPRNT_PRINTING) &&
855 !strequal(parse_line.status, LPRNT_PAUSED) &&
856 !strequal(parse_line.status, LPRNT_WAITING))
859 parse_line.space3 = '\0';
860 trim_string(parse_line.jobname, NULL, " ");
862 buf->job = atoi(parse_line.jobid);
864 buf->size = atoi(parse_line.size);
865 buf->time = time(NULL);
866 StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1);
867 StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1);
868 if (strequal(parse_line.status, LPRNT_PRINTING))
869 buf->status = LPQ_PRINTING;
870 else if (strequal(parse_line.status, LPRNT_PAUSED))
871 buf->status = LPQ_PAUSED;
873 buf->status = LPQ_QUEUED;
878 /*******************************************************************
879 parse lpq on an OS2 system
881 JobID File Name Rank Size Status Comment
882 ----- --------------- ------ -------- ------------ ------------
883 3 Control 1 68 Queued root@psflinu
884 4 /etc/motd 2 11666 Queued root@psflinu
886 ********************************************************************/
887 static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first)
889 #define LPROS2_IDSIZ 5
890 #define LPROS2_JOBSIZ 15
891 #define LPROS2_SIZSIZ 8
892 #define LPROS2_STATSIZ 12
893 #define LPROS2_OWNSIZ 12
896 char jobid[LPROS2_IDSIZ];
898 char jobname[LPROS2_JOBSIZ];
900 char size[LPROS2_SIZSIZ];
902 char status[LPROS2_STATSIZ];
904 char owner[LPROS2_OWNSIZ];
908 os2_lpq_line parse_line;
909 #define LPROS2_PRINTING "Printing"
910 #define LPROS2_WAITING "Queued"
911 #define LPROS2_PAUSED "Paused"
913 memset(&parse_line, '\0', sizeof(parse_line));
914 strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
916 if (strlen((char *) &parse_line) != sizeof(parse_line) - 1)
920 buf->job = atoi(parse_line.jobid);
922 /* Get the job name */
923 parse_line.space2[0] = '\0';
924 trim_string(parse_line.jobname, NULL, " ");
925 StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1);
928 buf->size = atoi(parse_line.size);
929 buf->time = time(NULL);
931 /* Make sure we have an owner */
932 if (!strlen(parse_line.owner))
935 /* Make sure we have a valid status */
936 parse_line.space4[0] = '\0';
937 trim_string(parse_line.status, NULL, " ");
938 if (!strequal(parse_line.status, LPROS2_PRINTING) &&
939 !strequal(parse_line.status, LPROS2_PAUSED) &&
940 !strequal(parse_line.status, LPROS2_WAITING))
943 StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1);
944 if (strequal(parse_line.status, LPROS2_PRINTING))
945 buf->status = LPQ_PRINTING;
946 else if (strequal(parse_line.status, LPROS2_PAUSED))
947 buf->status = LPQ_PAUSED;
949 buf->status = LPQ_QUEUED;
954 static char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL };
955 static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };
956 static char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL };
960 /****************************************************************************
962 ****************************************************************************/
963 static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first)
968 /* First line is printer status */
970 if (!isdigit(line[0])) return False;
972 /* Parse a print job entry */
974 while(next_token(&line, tok, NULL, sizeof(fstring))) {
977 buf->job = atoi(tok);
980 buf->size = atoi(tok);
983 buf->status = atoi(tok);
986 buf->time = atoi(tok);
989 fstrcpy(buf->user, tok);
992 fstrcpy(buf->file, tok);
1001 #endif /* DEVELOPER */
1003 /****************************************************************************
1004 parse a lpq line. Choose printing style
1005 ****************************************************************************/
1006 BOOL parse_lpq_entry(int snum,char *line,
1007 print_queue_struct *buf,
1008 print_status_struct *status,BOOL first)
1012 switch (lp_printing(snum))
1015 ret = parse_lpq_sysv(line,buf,first);
1018 ret = parse_lpq_aix(line,buf,first);
1021 ret = parse_lpq_hpux(line,buf,first);
1024 ret = parse_lpq_qnx(line,buf,first);
1027 ret = parse_lpq_lprng(line,buf,first);
1030 ret = parse_lpq_plp(line,buf,first);
1033 ret = parse_lpq_softq(line,buf,first);
1036 ret = parse_lpq_nt(line,buf,first);
1039 ret = parse_lpq_os2(line,buf,first);
1044 ret = parse_lpq_vlp(line,buf,first);
1046 #endif /* DEVELOPER */
1048 ret = parse_lpq_bsd(line,buf,first);
1052 /* We don't want the newline in the status message. */
1054 char *p = strchr_m(line,'\n');
1058 /* in the LPRNG case, we skip lines starting by a space.*/
1059 if (line && !ret && (lp_printing(snum)==PRINT_LPRNG) )
1068 /* a few simple checks to see if the line might be a
1069 printer status line:
1070 handle them so that most severe condition is shown */
1074 switch (status->status) {
1076 for (i=0; stat0_strings[i]; i++)
1077 if (strstr(line,stat0_strings[i])) {
1078 StrnCpy(status->message,line,sizeof(status->message)-1);
1079 status->status=LPSTAT_OK;
1082 case LPSTAT_STOPPED:
1083 for (i=0; stat1_strings[i]; i++)
1084 if (strstr(line,stat1_strings[i])) {
1085 StrnCpy(status->message,line,sizeof(status->message)-1);
1086 status->status=LPSTAT_STOPPED;
1090 for (i=0; stat2_strings[i]; i++)
1091 if (strstr(line,stat2_strings[i])) {
1092 StrnCpy(status->message,line,sizeof(status->message)-1);
1093 status->status=LPSTAT_ERROR;