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 3 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, see <http://www.gnu.org/licenses/>.
23 static const char *Months
[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
24 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
27 /*******************************************************************
29 ********************************************************************/
31 static time_t EntryTime(char *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
;
40 for (i
=0; i
<13; i
++) {
41 if (!strncmp(tok
[ptr
], Months
[i
],3)) {
42 break; /* Find month */
48 t
= localtime(&jobtime
);
52 day
= atoi(tok
[ptr
+1]);
53 fstrcpy(c
,tok
[ptr
+2]);
64 if ((t
->tm_mon
< i
)|| ((t
->tm_mon
== i
)&&
66 ((t
->tm_mday
== day
)&&
67 (t
->tm_hour
*60+t
->tm_min
< hour
*60+min
))))) {
68 t
->tm_year
--; /* last year's print job */
77 if (jobtime1
!= (time_t)-1) {
85 /****************************************************************************
88 here is an example of lpq output under bsd
90 Warning: no daemon present
91 Rank Owner Job Files Total Size
92 1st tridge 148 README 8096 bytes
94 here is an example of lpq output under osf/1
96 Warning: no daemon present
97 Rank Pri Owner Job Files Total Size
98 1st 0 tridge 148 README 8096 bytes
101 <allan@umich.edu> June 30, 1998.
102 Modified to handle file names with spaces, like the parse_lpq_lprng code
104 ****************************************************************************/
106 static bool parse_lpq_bsd(char *line
,print_queue_struct
*buf
,bool first
)
114 #define TOTALTOK (count - 2)
122 #define TOTALTOK (count - 2)
129 TALLOC_CTX
*ctx
= talloc_tos();
133 line2
= talloc_strdup(ctx
, line
);
141 length
= strlen(line2
);
142 if (line2
[length
-3] == ':') {
148 /* FIXME: Use next_token_talloc rather than strtok! */
149 tok
[0] = strtok_r(line2
," \t", &saveptr
);
152 while ((count
< MAXTOK
)
153 && ((tok
[count
] = strtok_r(NULL
, " \t", &saveptr
)) != NULL
)) {
157 /* we must get at least NTOK tokens */
162 /* the Job and Total columns must be integer */
163 if (!isdigit((int)*tok
[JOBTOK
]) || !isdigit((int)*tok
[TOTALTOK
])) {
167 buf
->sysjob
= atoi(tok
[JOBTOK
]);
168 buf
->size
= atoi(tok
[TOTALTOK
]);
169 buf
->status
= strequal(tok
[RANKTOK
],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
170 buf
->time
= time(NULL
);
171 fstrcpy(buf
->fs_user
,tok
[USERTOK
]);
172 fstrcpy(buf
->fs_file
,tok
[FILETOK
]);
174 if ((FILETOK
+ 1) != TOTALTOK
) {
177 for (i
= (FILETOK
+ 1); i
< TOTALTOK
; i
++) {
178 /* FIXME: Using fstrcat rather than other means is a bit
179 * inefficient; this might be a problem for enormous queues with
181 fstrcat(buf
->fs_file
, " ");
182 fstrcat(buf
->fs_file
, tok
[i
]);
184 /* Ensure null termination. */
185 buf
->fs_file
[sizeof(buf
->fs_file
)-1] = '\0';
189 buf
->priority
= atoi(tok
[PRIOTOK
]);
198 LPRng_time modifies the current date by inserting the hour and minute from
199 the lpq output. The lpq time looks like "23:15:07"
201 <allan@umich.edu> June 30, 1998.
202 Modified to work with the re-written parse_lpq_lprng routine.
204 <J.P.M.v.Itegem@tue.nl> Dec 17,1999
205 Modified to work with lprng 3.16
206 With lprng 3.16 The lpq time looks like
209 "1999-12-16-23:15:07"
210 "1999-12-16-23:15:07.100"
213 static time_t LPRng_time(char *time_string
)
218 jobtime
= time(NULL
); /* default case: take current time */
219 t
= localtime(&jobtime
);
224 if ( atoi(time_string
) < 24 ){
225 t
->tm_hour
= atoi(time_string
);
226 t
->tm_min
= atoi(time_string
+3);
227 t
->tm_sec
= atoi(time_string
+6);
229 t
->tm_year
= atoi(time_string
)-1900;
230 t
->tm_mon
= atoi(time_string
+5)-1;
231 t
->tm_mday
= atoi(time_string
+8);
232 t
->tm_hour
= atoi(time_string
+11);
233 t
->tm_min
= atoi(time_string
+14);
234 t
->tm_sec
= atoi(time_string
+17);
241 /****************************************************************************
242 parse a lprng lpq line
243 <allan@umich.edu> June 30, 1998.
244 Re-wrote this to handle file names with spaces, multiple file names on one
247 ****************************************************************************/
249 static bool parse_lpq_lprng(char *line
,print_queue_struct
*buf
,bool first
)
251 #define LPRNG_RANKTOK 0
252 #define LPRNG_USERTOK 1
253 #define LPRNG_PRIOTOK 2
254 #define LPRNG_JOBTOK 3
255 #define LPRNG_FILETOK 4
256 #define LPRNG_TOTALTOK (num_tok - 2)
257 #define LPRNG_TIMETOK (num_tok - 1)
259 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
261 char *tokarr
[LPRNG_MAXTOK
];
265 TALLOC_CTX
*frame
= talloc_stackframe();
268 while((num_tok
< LPRNG_MAXTOK
) && next_token_talloc(frame
, &cptr
,
269 &tokarr
[num_tok
], " \t")) {
273 /* We must get at least LPRNG_NTOK tokens. */
274 if (num_tok
< LPRNG_NTOK
) {
279 if (!isdigit((int)*tokarr
[LPRNG_JOBTOK
]) || !isdigit((int)*tokarr
[LPRNG_TOTALTOK
])) {
284 buf
->sysjob
= atoi(tokarr
[LPRNG_JOBTOK
]);
285 buf
->size
= atoi(tokarr
[LPRNG_TOTALTOK
]);
287 if (strequal(tokarr
[LPRNG_RANKTOK
],"active")) {
288 buf
->status
= LPQ_PRINTING
;
289 } else if (strequal(tokarr
[LPRNG_RANKTOK
],"done")) {
290 buf
->status
= LPQ_PRINTED
;
291 } else if (isdigit((int)*tokarr
[LPRNG_RANKTOK
])) {
292 buf
->status
= LPQ_QUEUED
;
294 buf
->status
= LPQ_PAUSED
;
297 buf
->priority
= *tokarr
[LPRNG_PRIOTOK
] -'A';
299 buf
->time
= LPRng_time(tokarr
[LPRNG_TIMETOK
]);
301 fstrcpy(buf
->fs_user
,tokarr
[LPRNG_USERTOK
]);
303 /* The '@hostname' prevents windows from displaying the printing icon
304 * for the current user on the taskbar. Plop in a null.
307 if ((ptr
= strchr_m(buf
->fs_user
,'@')) != NULL
) {
311 fstrcpy(buf
->fs_file
,tokarr
[LPRNG_FILETOK
]);
313 if ((LPRNG_FILETOK
+ 1) != LPRNG_TOTALTOK
) {
316 for (i
= (LPRNG_FILETOK
+ 1); i
< LPRNG_TOTALTOK
; i
++) {
317 /* FIXME: Using fstrcat rather than other means is a bit
318 * inefficient; this might be a problem for enormous queues with
320 fstrcat(buf
->fs_file
, " ");
321 fstrcat(buf
->fs_file
, tokarr
[i
]);
323 /* Ensure null termination. */
324 buf
->fs_file
[sizeof(buf
->fs_file
)-1] = '\0';
331 /*******************************************************************
332 parse lpq on an aix system
334 Queue Dev Status Job Files User PP % Blks Cp Rnk
335 ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
337 lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1
338 QUEUED 538 C.ps root@IEDVB 124 1 2
339 QUEUED 539 E.ps root@IEDVB 28 1 3
340 QUEUED 540 L.ps root@IEDVB 172 1 4
341 QUEUED 541 P.ps root@IEDVB 22 1 5
342 ********************************************************************/
344 static bool parse_lpq_aix(char *line
,print_queue_struct
*buf
,bool first
)
348 const char *cline
= line
;
349 TALLOC_CTX
*frame
= talloc_stackframe();
351 /* handle the case of "(standard input)" as a filename */
352 string_sub(line
,"standard input","STDIN",0);
353 all_string_sub(line
,"(","\"",0);
354 all_string_sub(line
,")","\"",0);
356 for (count
=0; count
<10 &&
357 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
); count
++) {
361 /* we must get 6 tokens */
363 if ((count
== 7) && ((strcmp(tok
[0],"QUEUED") == 0) || (strcmp(tok
[0],"HELD") == 0))) {
364 /* the 2nd and 5th columns must be integer */
365 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[4])) {
369 buf
->size
= atoi(tok
[4]) * 1024;
370 /* if the fname contains a space then use STDIN */
371 if (strchr_m(tok
[2],' ')) {
372 tok
[2] = talloc_strdup(frame
,"STDIN");
379 /* only take the last part of the filename */
381 char *p
= strrchr_m(tok
[2],'/');
387 buf
->sysjob
= atoi(tok
[1]);
388 buf
->status
= strequal(tok
[0],"HELD")?LPQ_PAUSED
:LPQ_QUEUED
;
390 buf
->time
= time(NULL
);
391 fstrcpy(buf
->fs_user
,tok
[3]);
392 fstrcpy(buf
->fs_file
,tok
[2]);
394 DEBUG(6,("parse_lpq_aix count=%d\n", count
));
399 /* the 4th and 9th columns must be integer */
400 if (!isdigit((int)*tok
[3]) || !isdigit((int)*tok
[8])) {
405 buf
->size
= atoi(tok
[8]) * 1024;
406 /* if the fname contains a space then use STDIN */
407 if (strchr_m(tok
[4],' ')) {
408 tok
[4] = talloc_strdup(frame
,"STDIN");
415 /* only take the last part of the filename */
417 char *p
= strrchr_m(tok
[4],'/');
423 buf
->sysjob
= atoi(tok
[3]);
424 buf
->status
= strequal(tok
[2],"RUNNING")?LPQ_PRINTING
:LPQ_QUEUED
;
426 buf
->time
= time(NULL
);
427 fstrcpy(buf
->fs_user
,tok
[5]);
428 fstrcpy(buf
->fs_file
,tok
[4]);
435 /****************************************************************************
437 here is an example of lpq output under hpux; note there's no space after -o !
439 ljplus-2153 user priority 0 Jan 19 08:14 on ljplus
441 server.c 110712 bytes
442 ljplus-2154 user priority 0 Jan 19 08:14 from client
443 (standard input) 7551 bytes
444 ****************************************************************************/
446 static bool parse_lpq_hpux(char *line
, print_queue_struct
*buf
, bool first
)
448 /* must read two lines to process, therefore keep some values static */
449 static bool header_line_ok
=False
, base_prio_reset
=False
;
450 static char *jobuser
;
453 static time_t jobtime
;
454 static int jobstat
=LPQ_QUEUED
;
455 /* to store minimum priority to print, lpstat command should be invoked
456 with -p option first, to work */
457 static int base_prio
;
460 const char *cline
= line
;
462 TALLOC_CTX
*frame
= talloc_stackframe();
464 /* If a line begins with a horizontal TAB, it is a subline type */
466 if (line
[0] == htab
) { /* subline */
467 /* check if it contains the base priority */
468 if (!strncmp(line
,"\tfence priority : ",18)) {
469 base_prio
=atoi(&line
[18]);
470 DEBUG(4, ("fence priority set at %d\n", base_prio
));
473 if (!header_line_ok
) {
475 return False
; /* incorrect header line */
478 /* handle the case of "(standard input)" as a filename */
479 string_sub(line
,"standard input","STDIN",0);
480 all_string_sub(line
,"(","\"",0);
481 all_string_sub(line
,")","\"",0);
483 for (count
=0; count
<2 &&
484 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
488 /* we must get 2 tokens */
494 /* the 2nd column must be integer */
495 if (!isdigit((int)*tok
[1])) {
500 /* if the fname contains a space then use STDIN */
501 if (strchr_m(tok
[0],' ')) {
502 tok
[0] = talloc_strdup(frame
, "STDIN");
509 buf
->size
= atoi(tok
[1]);
510 fstrcpy(buf
->fs_file
,tok
[0]);
512 /* fill things from header line */
515 buf
->status
= jobstat
;
516 buf
->priority
= jobprio
;
518 fstrcpy(buf
->fs_user
,jobuser
);
520 buf
->fs_user
[0] = '\0';
525 } else { /* header line */
526 header_line_ok
=False
; /* reset it */
528 if (!base_prio_reset
) {
529 base_prio
=0; /* reset it */
530 base_prio_reset
=True
;
532 } else if (base_prio
) {
533 base_prio_reset
=False
;
536 /* handle the dash in the job id */
537 string_sub(line
,"-"," ",0);
539 for (count
=0; count
<12 &&
540 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
545 /* we must get 8 tokens */
551 /* first token must be printer name (cannot check ?) */
552 /* the 2nd, 5th & 7th column must be integer */
553 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[4]) || !isdigit((int)*tok
[6])) {
557 jobid
= atoi(tok
[1]);
559 jobuser
= SMB_STRDUP(tok
[2]);
560 jobprio
= atoi(tok
[4]);
563 jobtime
=EntryTime(tok
, 5, count
, 8);
564 if (jobprio
< base_prio
) {
565 jobstat
= LPQ_PAUSED
;
566 DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n",
567 jobid
, jobprio
, base_prio
, jobstat
));
569 jobstat
= LPQ_QUEUED
;
570 if ((count
>8) && (((strequal(tok
[8],"on")) ||
571 ((strequal(tok
[8],"from")) &&
572 ((count
> 10)&&(strequal(tok
[10],"on"))))))) {
573 jobstat
= LPQ_PRINTING
;
577 header_line_ok
=True
; /* information is correct */
579 return False
; /* need subline info to include into queuelist */
583 /****************************************************************************
586 here is an example of "lpstat -o dcslw" output under sysv
588 dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw
589 dcslw-897 tridge 4712 Dec 20 10:30:30 being held
591 ****************************************************************************/
593 static bool parse_lpq_sysv(char *line
,print_queue_struct
*buf
,bool first
)
598 const char *cline
= line
;
599 TALLOC_CTX
*frame
= NULL
;
602 * Handle the dash in the job id, but make sure that we skip over
603 * the printer name in case we have a dash in that.
604 * Patch from Dom.Mitchell@palmerharvey.co.uk.
608 * Move to the first space.
610 for (p
= line
; !isspace(*p
) && *p
; p
++) {
615 * Back up until the last '-' character or
618 for (; (p
>= line
) && (*p
!= '-'); p
--) {
622 if((p
>= line
) && (*p
== '-')) {
626 frame
= talloc_stackframe();
627 for (count
=0; count
<9 &&
628 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
633 /* we must get 7 tokens */
639 /* the 2nd and 4th, 6th columns must be integer */
640 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[3])) {
644 if (!isdigit((int)*tok
[5])) {
649 /* if the user contains a ! then trim the first part of it */
650 if ((p
=strchr_m(tok
[2],'!'))) {
654 buf
->sysjob
= atoi(tok
[1]);
655 buf
->size
= atoi(tok
[3]);
656 if (count
> 7 && strequal(tok
[7],"on")) {
657 buf
->status
= LPQ_PRINTING
;
658 } else if (count
> 8 && strequal(tok
[7],"being") && strequal(tok
[8],"held")) {
659 buf
->status
= LPQ_PAUSED
;
661 buf
->status
= LPQ_QUEUED
;
664 buf
->time
= EntryTime(tok
, 4, count
, 7);
665 fstrcpy(buf
->fs_user
,tok
[2]);
666 fstrcpy(buf
->fs_file
,tok
[2]);
671 /****************************************************************************
674 here is an example of lpq output under qnx
675 Spooler: /qnx/spooler, on node 1
677 0000: root [job #1 ] active 1146 bytes /etc/profile
678 0001: root [job #2 ] ready 2378 bytes /etc/install
679 0002: root [job #3 ] ready 1146 bytes -- standard input --
680 ****************************************************************************/
682 static bool parse_lpq_qnx(char *line
,print_queue_struct
*buf
,bool first
)
686 const char *cline
= line
;
687 TALLOC_CTX
*frame
= NULL
;
689 DEBUG(4,("antes [%s]\n", line
));
691 /* handle the case of "-- standard input --" as a filename */
692 string_sub(line
,"standard input","STDIN",0);
693 DEBUG(4,("despues [%s]\n", line
));
694 all_string_sub(line
,"-- ","\"",0);
695 all_string_sub(line
," --","\"",0);
696 DEBUG(4,("despues 1 [%s]\n", line
));
698 string_sub(line
,"[job #","",0);
699 string_sub(line
,"]","",0);
700 DEBUG(4,("despues 2 [%s]\n", line
));
702 frame
= talloc_stackframe();
703 for (count
=0; count
<7 &&
704 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
);
709 /* we must get 7 tokens */
715 /* the 3rd and 5th columns must be integer */
716 if (!isdigit((int)*tok
[2]) || !isdigit((int)*tok
[4])) {
721 /* only take the last part of the filename */
723 char *p
= strrchr_m(tok
[6],'/');
729 buf
->sysjob
= atoi(tok
[2]);
730 buf
->size
= atoi(tok
[4]);
731 buf
->status
= strequal(tok
[3],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
733 buf
->time
= time(NULL
);
734 fstrcpy(buf
->fs_user
,tok
[1]);
735 fstrcpy(buf
->fs_file
,tok
[6]);
740 /****************************************************************************
741 parse a lpq line for the plp printing system
742 Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
744 redone by tridge. Here is a sample queue:
746 Local Printer 'lp2' (fjall):
747 Printing (started at Jun 15 13:33:58, attempt 1).
748 Rank Owner Pr Opt Job Host Files Size Date
749 active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
750 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
752 ****************************************************************************/
754 static bool parse_lpq_plp(char *line
,print_queue_struct
*buf
,bool first
)
758 const char *cline
= line
;
759 TALLOC_CTX
*frame
= talloc_stackframe();
761 /* handle the case of "(standard input)" as a filename */
762 string_sub(line
,"stdin","STDIN",0);
763 all_string_sub(line
,"(","\"",0);
764 all_string_sub(line
,")","\"",0);
766 for (count
=0; count
<11 &&
767 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
);
772 /* we must get 11 tokens */
778 /* the first must be "active" or begin with an integer */
779 if (strcmp(tok
[0],"active") && !isdigit((int)tok
[0][0])) {
784 /* the 5th and 8th must be integer */
785 if (!isdigit((int)*tok
[4]) || !isdigit((int)*tok
[7])) {
790 /* if the fname contains a space then use STDIN */
791 if (strchr_m(tok
[6],' ')) {
792 tok
[6] = talloc_strdup(frame
, "STDIN");
799 /* only take the last part of the filename */
802 char *p
= strrchr_m(tok
[6],'/');
804 size_t len
= strlen(tok
[6])+1;
806 strlcpy(tok
[6],tmp
, len
);
810 buf
->sysjob
= atoi(tok
[4]);
812 buf
->size
= atoi(tok
[7]);
813 if (strchr_m(tok
[7],'K')) {
816 if (strchr_m(tok
[7],'M')) {
817 buf
->size
*= 1024*1024;
820 buf
->status
= strequal(tok
[0],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
822 buf
->time
= time(NULL
);
823 fstrcpy(buf
->fs_user
,tok
[1]);
824 fstrcpy(buf
->fs_file
,tok
[6]);
829 /*******************************************************************
830 parse lpq on an NT system
832 Windows 2000 LPD Server
833 Printer \\10.0.0.2\NP17PCL (Paused)
835 Owner Status Jobname Job-Id Size Pages Priority
836 ----------------------------------------------------------------------------
837 root (9.99. Printing /usr/lib/rhs/rhs-pr 3 625 0 1
838 root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1
839 jmcd Waiting Re: Samba Open Sour 26 32476 1 1
841 ********************************************************************/
843 static bool parse_lpq_nt(char *line
,print_queue_struct
*buf
,bool first
)
845 #define LPRNT_OWNSIZ 11
846 #define LPRNT_STATSIZ 9
847 #define LPRNT_JOBSIZ 19
848 #define LPRNT_IDSIZ 6
849 #define LPRNT_SIZSIZ 9
851 char owner
[LPRNT_OWNSIZ
];
853 char status
[LPRNT_STATSIZ
];
855 char jobname
[LPRNT_JOBSIZ
];
857 char jobid
[LPRNT_IDSIZ
];
859 char size
[LPRNT_SIZSIZ
];
863 char parse_line_char
[sizeof(nt_lpq_line
)];
864 nt_lpq_line
*parse_line
= (nt_lpq_line
*)parse_line_char
;
865 #define LPRNT_PRINTING "Printing"
866 #define LPRNT_WAITING "Waiting"
867 #define LPRNT_PAUSED "Paused"
869 memset(parse_line_char
, '\0', sizeof(parse_line_char
));
870 strncpy(parse_line_char
, line
, sizeof(parse_line_char
) -1);
872 if (strlen(parse_line_char
) != sizeof(parse_line_char
) - 1) {
876 /* Just want the first word in the owner field - the username */
877 if (strchr_m(parse_line
->owner
, ' ')) {
878 *(strchr_m(parse_line
->owner
, ' ')) = '\0';
880 parse_line
->space1
= '\0';
883 /* Make sure we have an owner */
884 if (!strlen(parse_line
->owner
)) {
888 /* Make sure the status is valid */
889 parse_line
->space2
= '\0';
890 trim_char(parse_line
->status
, '\0', ' ');
891 if (!strequal(parse_line
->status
, LPRNT_PRINTING
) &&
892 !strequal(parse_line
->status
, LPRNT_PAUSED
) &&
893 !strequal(parse_line
->status
, LPRNT_WAITING
)) {
897 parse_line
->space3
= '\0';
898 trim_char(parse_line
->jobname
, '\0', ' ');
900 buf
->sysjob
= atoi(parse_line
->jobid
);
902 buf
->size
= atoi(parse_line
->size
);
903 buf
->time
= time(NULL
);
904 fstrcpy(buf
->fs_user
, parse_line
->owner
);
905 fstrcpy(buf
->fs_file
, parse_line
->jobname
);
906 if (strequal(parse_line
->status
, LPRNT_PRINTING
)) {
907 buf
->status
= LPQ_PRINTING
;
908 } else if (strequal(parse_line
->status
, LPRNT_PAUSED
)) {
909 buf
->status
= LPQ_PAUSED
;
911 buf
->status
= LPQ_QUEUED
;
917 /*******************************************************************
918 parse lpq on an OS2 system
920 JobID File Name Rank Size Status Comment
921 ----- --------------- ------ -------- ------------ ------------
922 3 Control 1 68 Queued root@psflinu
923 4 /etc/motd 2 11666 Queued root@psflinu
925 ********************************************************************/
927 static bool parse_lpq_os2(char *line
,print_queue_struct
*buf
,bool first
)
929 #define LPROS2_IDSIZ 5
930 #define LPROS2_JOBSIZ 15
931 #define LPROS2_SIZSIZ 8
932 #define LPROS2_STATSIZ 12
933 #define LPROS2_OWNSIZ 12
935 char jobid
[LPROS2_IDSIZ
];
937 char jobname
[LPROS2_JOBSIZ
];
939 char size
[LPROS2_SIZSIZ
];
941 char status
[LPROS2_STATSIZ
];
943 char owner
[LPROS2_OWNSIZ
];
947 char parse_line_char
[sizeof(os2_lpq_line
)];
948 os2_lpq_line
*parse_line
= (os2_lpq_line
*)parse_line_char
;
949 #define LPROS2_PRINTING "Printing"
950 #define LPROS2_WAITING "Queued"
951 #define LPROS2_PAUSED "Paused"
953 memset(parse_line_char
, '\0', sizeof(parse_line_char
));
954 strncpy(parse_line_char
, line
, sizeof(parse_line_char
) -1);
956 if (strlen(parse_line_char
) != sizeof(parse_line_char
) - 1) {
961 buf
->sysjob
= atoi(parse_line
->jobid
);
963 /* Get the job name */
964 parse_line
->space2
[0] = '\0';
965 trim_char(parse_line
->jobname
, '\0', ' ');
966 fstrcpy(buf
->fs_file
, parse_line
->jobname
);
969 buf
->size
= atoi(parse_line
->size
);
970 buf
->time
= time(NULL
);
972 /* Make sure we have an owner */
973 if (!strlen(parse_line
->owner
)) {
977 /* Make sure we have a valid status */
978 parse_line
->space4
[0] = '\0';
979 trim_char(parse_line
->status
, '\0', ' ');
980 if (!strequal(parse_line
->status
, LPROS2_PRINTING
) &&
981 !strequal(parse_line
->status
, LPROS2_PAUSED
) &&
982 !strequal(parse_line
->status
, LPROS2_WAITING
)) {
986 fstrcpy(buf
->fs_user
, parse_line
->owner
);
987 if (strequal(parse_line
->status
, LPROS2_PRINTING
)) {
988 buf
->status
= LPQ_PRINTING
;
989 } else if (strequal(parse_line
->status
, LPROS2_PAUSED
)) {
990 buf
->status
= LPQ_PAUSED
;
992 buf
->status
= LPQ_QUEUED
;
998 static const char *stat0_strings
[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL
};
999 static const char *stat1_strings
[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL
};
1000 static const char *stat2_strings
[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL
};
1004 /****************************************************************************
1006 ****************************************************************************/
1008 static bool parse_lpq_vlp(char *line
,print_queue_struct
*buf
,bool first
)
1012 TALLOC_CTX
*frame
= talloc_stackframe();
1013 const char *cline
= line
;
1015 /* First line is printer status */
1017 if (!isdigit(line
[0])) {
1022 /* Parse a print job entry */
1024 while(next_token_talloc(frame
, &cline
, &tok
, NULL
)) {
1027 buf
->sysjob
= atoi(tok
);
1030 buf
->size
= atoi(tok
);
1033 buf
->status
= atoi(tok
);
1036 buf
->time
= atoi(tok
);
1039 fstrcpy(buf
->fs_user
, tok
);
1042 fstrcpy(buf
->fs_file
, tok
);
1052 #endif /* DEVELOPER */
1054 /****************************************************************************
1055 parse a lpq line. Choose printing style
1056 ****************************************************************************/
1058 bool parse_lpq_entry(enum printing_types printing_type
,char *line
,
1059 print_queue_struct
*buf
,
1060 print_status_struct
*status
,bool first
)
1064 switch (printing_type
) {
1066 ret
= parse_lpq_sysv(line
,buf
,first
);
1069 ret
= parse_lpq_aix(line
,buf
,first
);
1072 ret
= parse_lpq_hpux(line
,buf
,first
);
1075 ret
= parse_lpq_qnx(line
,buf
,first
);
1078 ret
= parse_lpq_lprng(line
,buf
,first
);
1081 ret
= parse_lpq_plp(line
,buf
,first
);
1084 ret
= parse_lpq_nt(line
,buf
,first
);
1087 ret
= parse_lpq_os2(line
,buf
,first
);
1092 ret
= parse_lpq_vlp(line
,buf
,first
);
1094 #endif /* DEVELOPER */
1096 ret
= parse_lpq_bsd(line
,buf
,first
);
1100 /* We don't want the newline in the status message. */
1102 char *p
= strchr_m(line
,'\n');
1108 /* in the LPRNG case, we skip lines starting by a space.*/
1109 if (!ret
&& (printing_type
==PRINT_LPRNG
) ) {
1115 if (status
&& !ret
) {
1116 /* a few simple checks to see if the line might be a
1117 printer status line:
1118 handle them so that most severe condition is shown */
1120 if (!strlower_m(line
)) {
1124 switch (status
->status
) {
1126 for (i
=0; stat0_strings
[i
]; i
++) {
1127 if (strstr_m(line
,stat0_strings
[i
])) {
1128 fstrcpy(status
->message
,line
);
1129 status
->status
=LPSTAT_OK
;
1134 case LPSTAT_STOPPED
:
1135 for (i
=0; stat1_strings
[i
]; i
++) {
1136 if (strstr_m(line
,stat1_strings
[i
])) {
1137 fstrcpy(status
->message
,line
);
1138 status
->status
=LPSTAT_STOPPED
;
1144 for (i
=0; stat2_strings
[i
]; i
++) {
1145 if (strstr_m(line
,stat2_strings
[i
])) {
1146 fstrcpy(status
->message
,line
);
1147 status
->status
=LPSTAT_ERROR
;