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 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(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
++) {
42 if (!strncmp(tok
[ptr
], Months
[i
],3)) {
43 break; /* Find month */
48 t
= localtime(&jobtime
);
52 day
= atoi(tok
[ptr
+1]);
53 c
=(char *)(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)
136 length
= strlen(line2
);
137 if (line2
[length
-3] == ':') {
143 /* FIXME: Use next_token rather than strtok! */
144 tok
[0] = strtok(line2
," \t");
147 while ((count
< MAXTOK
) && ((tok
[count
] = strtok(NULL
," \t")) != NULL
)) {
151 /* we must get at least NTOK tokens */
156 /* the Job and Total columns must be integer */
157 if (!isdigit((int)*tok
[JOBTOK
]) || !isdigit((int)*tok
[TOTALTOK
])) {
161 buf
->job
= atoi(tok
[JOBTOK
]);
162 buf
->size
= atoi(tok
[TOTALTOK
]);
163 buf
->status
= strequal(tok
[RANKTOK
],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
164 buf
->time
= time(NULL
);
165 fstrcpy(buf
->fs_user
,tok
[USERTOK
]);
166 fstrcpy(buf
->fs_file
,tok
[FILETOK
]);
168 if ((FILETOK
+ 1) != TOTALTOK
) {
171 for (i
= (FILETOK
+ 1); i
< TOTALTOK
; i
++) {
172 /* FIXME: Using fstrcat rather than other means is a bit
173 * inefficient; this might be a problem for enormous queues with
175 fstrcat(buf
->fs_file
, " ");
176 fstrcat(buf
->fs_file
, tok
[i
]);
178 /* Ensure null termination. */
179 fstrterminate(buf
->fs_file
);
183 buf
->priority
= atoi(tok
[PRIOTOK
]);
192 LPRng_time modifies the current date by inserting the hour and minute from
193 the lpq output. The lpq time looks like "23:15:07"
195 <allan@umich.edu> June 30, 1998.
196 Modified to work with the re-written parse_lpq_lprng routine.
198 <J.P.M.v.Itegem@tue.nl> Dec 17,1999
199 Modified to work with lprng 3.16
200 With lprng 3.16 The lpq time looks like
203 "1999-12-16-23:15:07"
204 "1999-12-16-23:15:07.100"
207 static time_t LPRng_time(char *time_string
)
212 jobtime
= time(NULL
); /* default case: take current time */
213 t
= localtime(&jobtime
);
218 if ( atoi(time_string
) < 24 ){
219 t
->tm_hour
= atoi(time_string
);
220 t
->tm_min
= atoi(time_string
+3);
221 t
->tm_sec
= atoi(time_string
+6);
223 t
->tm_year
= atoi(time_string
)-1900;
224 t
->tm_mon
= atoi(time_string
+5)-1;
225 t
->tm_mday
= atoi(time_string
+8);
226 t
->tm_hour
= atoi(time_string
+11);
227 t
->tm_min
= atoi(time_string
+14);
228 t
->tm_sec
= atoi(time_string
+17);
235 /****************************************************************************
236 parse a lprng lpq line
237 <allan@umich.edu> June 30, 1998.
238 Re-wrote this to handle file names with spaces, multiple file names on one
241 ****************************************************************************/
243 static BOOL
parse_lpq_lprng(char *line
,print_queue_struct
*buf
,BOOL first
)
245 #define LPRNG_RANKTOK 0
246 #define LPRNG_USERTOK 1
247 #define LPRNG_PRIOTOK 2
248 #define LPRNG_JOBTOK 3
249 #define LPRNG_FILETOK 4
250 #define LPRNG_TOTALTOK (num_tok - 2)
251 #define LPRNG_TIMETOK (num_tok - 1)
253 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
255 fstring tokarr
[LPRNG_MAXTOK
];
261 while((num_tok
< LPRNG_MAXTOK
) && next_token( &cptr
, tokarr
[num_tok
], " \t", sizeof(fstring
))) {
265 /* We must get at least LPRNG_NTOK tokens. */
266 if (num_tok
< LPRNG_NTOK
) {
270 if (!isdigit((int)*tokarr
[LPRNG_JOBTOK
]) || !isdigit((int)*tokarr
[LPRNG_TOTALTOK
])) {
274 buf
->job
= atoi(tokarr
[LPRNG_JOBTOK
]);
275 buf
->size
= atoi(tokarr
[LPRNG_TOTALTOK
]);
277 if (strequal(tokarr
[LPRNG_RANKTOK
],"active")) {
278 buf
->status
= LPQ_PRINTING
;
279 } else if (strequal(tokarr
[LPRNG_RANKTOK
],"done")) {
280 buf
->status
= LPQ_PRINTED
;
281 } else if (isdigit((int)*tokarr
[LPRNG_RANKTOK
])) {
282 buf
->status
= LPQ_QUEUED
;
284 buf
->status
= LPQ_PAUSED
;
287 buf
->priority
= *tokarr
[LPRNG_PRIOTOK
] -'A';
289 buf
->time
= LPRng_time(tokarr
[LPRNG_TIMETOK
]);
291 fstrcpy(buf
->fs_user
,tokarr
[LPRNG_USERTOK
]);
293 /* The '@hostname' prevents windows from displaying the printing icon
294 * for the current user on the taskbar. Plop in a null.
297 if ((ptr
= strchr_m(buf
->fs_user
,'@')) != NULL
) {
301 fstrcpy(buf
->fs_file
,tokarr
[LPRNG_FILETOK
]);
303 if ((LPRNG_FILETOK
+ 1) != LPRNG_TOTALTOK
) {
306 for (i
= (LPRNG_FILETOK
+ 1); i
< LPRNG_TOTALTOK
; i
++) {
307 /* FIXME: Using fstrcat rather than other means is a bit
308 * inefficient; this might be a problem for enormous queues with
310 fstrcat(buf
->fs_file
, " ");
311 fstrcat(buf
->fs_file
, tokarr
[i
]);
313 /* Ensure null termination. */
314 fstrterminate(buf
->fs_file
);
320 /*******************************************************************
321 parse lpq on an aix system
323 Queue Dev Status Job Files User PP % Blks Cp Rnk
324 ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
326 lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1
327 QUEUED 538 C.ps root@IEDVB 124 1 2
328 QUEUED 539 E.ps root@IEDVB 28 1 3
329 QUEUED 540 L.ps root@IEDVB 172 1 4
330 QUEUED 541 P.ps root@IEDVB 22 1 5
331 ********************************************************************/
333 static BOOL
parse_lpq_aix(char *line
,print_queue_struct
*buf
,BOOL first
)
337 const char *cline
= line
;
339 /* handle the case of "(standard input)" as a filename */
340 string_sub(line
,"standard input","STDIN",0);
341 all_string_sub(line
,"(","\"",0);
342 all_string_sub(line
,")","\"",0);
344 for (count
=0; count
<10 && next_token(&cline
,tok
[count
],NULL
, sizeof(tok
[count
])); count
++) {
348 /* we must get 6 tokens */
350 if ((count
== 7) && ((strcmp(tok
[0],"QUEUED") == 0) || (strcmp(tok
[0],"HELD") == 0))) {
351 /* the 2nd and 5th columns must be integer */
352 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[4])) {
355 buf
->size
= atoi(tok
[4]) * 1024;
356 /* if the fname contains a space then use STDIN */
357 if (strchr_m(tok
[2],' ')) {
358 fstrcpy(tok
[2],"STDIN");
361 /* only take the last part of the filename */
364 char *p
= strrchr_m(tok
[2],'/');
371 buf
->job
= atoi(tok
[1]);
372 buf
->status
= strequal(tok
[0],"HELD")?LPQ_PAUSED
:LPQ_QUEUED
;
374 buf
->time
= time(NULL
);
375 fstrcpy(buf
->fs_user
,tok
[3]);
376 fstrcpy(buf
->fs_file
,tok
[2]);
378 DEBUG(6,("parse_lpq_aix count=%d\n", count
));
382 /* the 4th and 9th columns must be integer */
383 if (!isdigit((int)*tok
[3]) || !isdigit((int)*tok
[8])) {
387 buf
->size
= atoi(tok
[8]) * 1024;
388 /* if the fname contains a space then use STDIN */
389 if (strchr_m(tok
[4],' ')) {
390 fstrcpy(tok
[4],"STDIN");
393 /* only take the last part of the filename */
396 char *p
= strrchr_m(tok
[4],'/');
403 buf
->job
= atoi(tok
[3]);
404 buf
->status
= strequal(tok
[2],"RUNNING")?LPQ_PRINTING
:LPQ_QUEUED
;
406 buf
->time
= time(NULL
);
407 fstrcpy(buf
->fs_user
,tok
[5]);
408 fstrcpy(buf
->fs_file
,tok
[4]);
414 /****************************************************************************
416 here is an example of lpq output under hpux; note there's no space after -o !
418 ljplus-2153 user priority 0 Jan 19 08:14 on ljplus
420 server.c 110712 bytes
421 ljplus-2154 user priority 0 Jan 19 08:14 from client
422 (standard input) 7551 bytes
423 ****************************************************************************/
425 static BOOL
parse_lpq_hpux(char *line
, print_queue_struct
*buf
, BOOL first
)
427 /* must read two lines to process, therefore keep some values static */
428 static BOOL header_line_ok
=False
, base_prio_reset
=False
;
429 static fstring jobuser
;
432 static time_t jobtime
;
433 static int jobstat
=LPQ_QUEUED
;
434 /* to store minimum priority to print, lpstat command should be invoked
435 with -p option first, to work */
436 static int base_prio
;
439 const char *cline
= line
;
442 /* If a line begins with a horizontal TAB, it is a subline type */
444 if (line
[0] == htab
) { /* subline */
445 /* check if it contains the base priority */
446 if (!strncmp(line
,"\tfence priority : ",18)) {
447 base_prio
=atoi(&line
[18]);
448 DEBUG(4, ("fence priority set at %d\n", base_prio
));
451 if (!header_line_ok
) {
452 return False
; /* incorrect header line */
455 /* handle the case of "(standard input)" as a filename */
456 string_sub(line
,"standard input","STDIN",0);
457 all_string_sub(line
,"(","\"",0);
458 all_string_sub(line
,")","\"",0);
460 for (count
=0; count
<2 && next_token(&cline
,tok
[count
],NULL
,sizeof(tok
[count
])); count
++) {
463 /* we must get 2 tokens */
468 /* the 2nd column must be integer */
469 if (!isdigit((int)*tok
[1])) {
473 /* if the fname contains a space then use STDIN */
474 if (strchr_m(tok
[0],' ')) {
475 fstrcpy(tok
[0],"STDIN");
478 buf
->size
= atoi(tok
[1]);
479 fstrcpy(buf
->fs_file
,tok
[0]);
481 /* fill things from header line */
484 buf
->status
= jobstat
;
485 buf
->priority
= jobprio
;
486 fstrcpy(buf
->fs_user
,jobuser
);
489 } else { /* header line */
490 header_line_ok
=False
; /* reset it */
492 if (!base_prio_reset
) {
493 base_prio
=0; /* reset it */
494 base_prio_reset
=True
;
496 } else if (base_prio
) {
497 base_prio_reset
=False
;
500 /* handle the dash in the job id */
501 string_sub(line
,"-"," ",0);
503 for (count
=0; count
<12 && next_token(&cline
,tok
[count
],NULL
,sizeof(tok
[count
])); count
++) {
507 /* we must get 8 tokens */
512 /* first token must be printer name (cannot check ?) */
513 /* the 2nd, 5th & 7th column must be integer */
514 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[4]) || !isdigit((int)*tok
[6])) {
517 jobid
= atoi(tok
[1]);
518 fstrcpy(jobuser
,tok
[2]);
519 jobprio
= atoi(tok
[4]);
522 jobtime
=EntryTime(tok
, 5, count
, 8);
523 if (jobprio
< base_prio
) {
524 jobstat
= LPQ_PAUSED
;
525 DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n",
526 jobid
, jobprio
, base_prio
, jobstat
));
528 jobstat
= LPQ_QUEUED
;
529 if ((count
>8) && (((strequal(tok
[8],"on")) ||
530 ((strequal(tok
[8],"from")) &&
531 ((count
> 10)&&(strequal(tok
[10],"on"))))))) {
532 jobstat
= LPQ_PRINTING
;
536 header_line_ok
=True
; /* information is correct */
537 return False
; /* need subline info to include into queuelist */
541 /****************************************************************************
544 here is an example of "lpstat -o dcslw" output under sysv
546 dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw
547 dcslw-897 tridge 4712 Dec 20 10:30:30 being held
549 ****************************************************************************/
551 static BOOL
parse_lpq_sysv(char *line
,print_queue_struct
*buf
,BOOL first
)
556 const char *cline
= line
;
559 * Handle the dash in the job id, but make sure that we skip over
560 * the printer name in case we have a dash in that.
561 * Patch from Dom.Mitchell@palmerharvey.co.uk.
565 * Move to the first space.
567 for (p
= line
; !isspace(*p
) && *p
; p
++) {
572 * Back up until the last '-' character or
575 for (; (p
>= line
) && (*p
!= '-'); p
--) {
579 if((p
>= line
) && (*p
== '-')) {
583 for (count
=0; count
<9 && next_token(&cline
,tok
[count
],NULL
,sizeof(tok
[count
])); count
++) {
587 /* we must get 7 tokens */
592 /* the 2nd and 4th, 6th columns must be integer */
593 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[3])) {
596 if (!isdigit((int)*tok
[5])) {
600 /* if the user contains a ! then trim the first part of it */
601 if ((p
=strchr_m(tok
[2],'!'))) {
607 buf
->job
= atoi(tok
[1]);
608 buf
->size
= atoi(tok
[3]);
609 if (count
> 7 && strequal(tok
[7],"on")) {
610 buf
->status
= LPQ_PRINTING
;
611 } else if (count
> 8 && strequal(tok
[7],"being") && strequal(tok
[8],"held")) {
612 buf
->status
= LPQ_PAUSED
;
614 buf
->status
= LPQ_QUEUED
;
617 buf
->time
= EntryTime(tok
, 4, count
, 7);
618 fstrcpy(buf
->fs_user
,tok
[2]);
619 fstrcpy(buf
->fs_file
,tok
[2]);
623 /****************************************************************************
626 here is an example of lpq output under qnx
627 Spooler: /qnx/spooler, on node 1
629 0000: root [job #1 ] active 1146 bytes /etc/profile
630 0001: root [job #2 ] ready 2378 bytes /etc/install
631 0002: root [job #3 ] ready 1146 bytes -- standard input --
632 ****************************************************************************/
634 static BOOL
parse_lpq_qnx(char *line
,print_queue_struct
*buf
,BOOL first
)
638 const char *cline
= line
;
640 DEBUG(4,("antes [%s]\n", line
));
642 /* handle the case of "-- standard input --" as a filename */
643 string_sub(line
,"standard input","STDIN",0);
644 DEBUG(4,("despues [%s]\n", line
));
645 all_string_sub(line
,"-- ","\"",0);
646 all_string_sub(line
," --","\"",0);
647 DEBUG(4,("despues 1 [%s]\n", line
));
649 string_sub(line
,"[job #","",0);
650 string_sub(line
,"]","",0);
651 DEBUG(4,("despues 2 [%s]\n", line
));
653 for (count
=0; count
<7 && next_token(&cline
,tok
[count
],NULL
,sizeof(tok
[count
])); count
++) {
657 /* we must get 7 tokens */
662 /* the 3rd and 5th columns must be integer */
663 if (!isdigit((int)*tok
[2]) || !isdigit((int)*tok
[4])) {
667 /* only take the last part of the filename */
670 char *p
= strrchr_m(tok
[6],'/');
677 buf
->job
= atoi(tok
[2]);
678 buf
->size
= atoi(tok
[4]);
679 buf
->status
= strequal(tok
[3],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
681 buf
->time
= time(NULL
);
682 fstrcpy(buf
->fs_user
,tok
[1]);
683 fstrcpy(buf
->fs_file
,tok
[6]);
687 /****************************************************************************
688 parse a lpq line for the plp printing system
689 Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
691 redone by tridge. Here is a sample queue:
693 Local Printer 'lp2' (fjall):
694 Printing (started at Jun 15 13:33:58, attempt 1).
695 Rank Owner Pr Opt Job Host Files Size Date
696 active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
697 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
699 ****************************************************************************/
701 static BOOL
parse_lpq_plp(char *line
,print_queue_struct
*buf
,BOOL first
)
705 const char *cline
= line
;
707 /* handle the case of "(standard input)" as a filename */
708 string_sub(line
,"stdin","STDIN",0);
709 all_string_sub(line
,"(","\"",0);
710 all_string_sub(line
,")","\"",0);
712 for (count
=0; count
<11 && next_token(&cline
,tok
[count
],NULL
,sizeof(tok
[count
])); count
++) {
716 /* we must get 11 tokens */
721 /* the first must be "active" or begin with an integer */
722 if (strcmp(tok
[0],"active") && !isdigit((int)tok
[0][0])) {
726 /* the 5th and 8th must be integer */
727 if (!isdigit((int)*tok
[4]) || !isdigit((int)*tok
[7])) {
731 /* if the fname contains a space then use STDIN */
732 if (strchr_m(tok
[6],' ')) {
733 fstrcpy(tok
[6],"STDIN");
736 /* only take the last part of the filename */
739 char *p
= strrchr_m(tok
[6],'/');
746 buf
->job
= atoi(tok
[4]);
748 buf
->size
= atoi(tok
[7]);
749 if (strchr_m(tok
[7],'K')) {
752 if (strchr_m(tok
[7],'M')) {
753 buf
->size
*= 1024*1024;
756 buf
->status
= strequal(tok
[0],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
758 buf
->time
= time(NULL
);
759 fstrcpy(buf
->fs_user
,tok
[1]);
760 fstrcpy(buf
->fs_file
,tok
[6]);
764 /*******************************************************************
765 parse lpq on an NT system
767 Windows 2000 LPD Server
768 Printer \\10.0.0.2\NP17PCL (Paused)
770 Owner Status Jobname Job-Id Size Pages Priority
771 ----------------------------------------------------------------------------
772 root (9.99. Printing /usr/lib/rhs/rhs-pr 3 625 0 1
773 root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1
774 jmcd Waiting Re: Samba Open Sour 26 32476 1 1
776 ********************************************************************/
778 static BOOL
parse_lpq_nt(char *line
,print_queue_struct
*buf
,BOOL first
)
780 #define LPRNT_OWNSIZ 11
781 #define LPRNT_STATSIZ 9
782 #define LPRNT_JOBSIZ 19
783 #define LPRNT_IDSIZ 6
784 #define LPRNT_SIZSIZ 9
786 char owner
[LPRNT_OWNSIZ
];
788 char status
[LPRNT_STATSIZ
];
790 char jobname
[LPRNT_JOBSIZ
];
792 char jobid
[LPRNT_IDSIZ
];
794 char size
[LPRNT_SIZSIZ
];
798 nt_lpq_line parse_line
;
799 #define LPRNT_PRINTING "Printing"
800 #define LPRNT_WAITING "Waiting"
801 #define LPRNT_PAUSED "Paused"
803 memset(&parse_line
, '\0', sizeof(parse_line
));
804 strncpy((char *) &parse_line
, line
, sizeof(parse_line
) -1);
806 if (strlen((char *) &parse_line
) != sizeof(parse_line
) - 1) {
810 /* Just want the first word in the owner field - the username */
811 if (strchr_m(parse_line
.owner
, ' ')) {
812 *(strchr_m(parse_line
.owner
, ' ')) = '\0';
814 parse_line
.space1
= '\0';
817 /* Make sure we have an owner */
818 if (!strlen(parse_line
.owner
)) {
822 /* Make sure the status is valid */
823 parse_line
.space2
= '\0';
824 trim_char(parse_line
.status
, '\0', ' ');
825 if (!strequal(parse_line
.status
, LPRNT_PRINTING
) &&
826 !strequal(parse_line
.status
, LPRNT_PAUSED
) &&
827 !strequal(parse_line
.status
, LPRNT_WAITING
)) {
831 parse_line
.space3
= '\0';
832 trim_char(parse_line
.jobname
, '\0', ' ');
834 buf
->job
= atoi(parse_line
.jobid
);
836 buf
->size
= atoi(parse_line
.size
);
837 buf
->time
= time(NULL
);
838 fstrcpy(buf
->fs_user
, parse_line
.owner
);
839 fstrcpy(buf
->fs_file
, parse_line
.jobname
);
840 if (strequal(parse_line
.status
, LPRNT_PRINTING
)) {
841 buf
->status
= LPQ_PRINTING
;
842 } else if (strequal(parse_line
.status
, LPRNT_PAUSED
)) {
843 buf
->status
= LPQ_PAUSED
;
845 buf
->status
= LPQ_QUEUED
;
851 /*******************************************************************
852 parse lpq on an OS2 system
854 JobID File Name Rank Size Status Comment
855 ----- --------------- ------ -------- ------------ ------------
856 3 Control 1 68 Queued root@psflinu
857 4 /etc/motd 2 11666 Queued root@psflinu
859 ********************************************************************/
861 static BOOL
parse_lpq_os2(char *line
,print_queue_struct
*buf
,BOOL first
)
863 #define LPROS2_IDSIZ 5
864 #define LPROS2_JOBSIZ 15
865 #define LPROS2_SIZSIZ 8
866 #define LPROS2_STATSIZ 12
867 #define LPROS2_OWNSIZ 12
869 char jobid
[LPROS2_IDSIZ
];
871 char jobname
[LPROS2_JOBSIZ
];
873 char size
[LPROS2_SIZSIZ
];
875 char status
[LPROS2_STATSIZ
];
877 char owner
[LPROS2_OWNSIZ
];
881 os2_lpq_line parse_line
;
882 #define LPROS2_PRINTING "Printing"
883 #define LPROS2_WAITING "Queued"
884 #define LPROS2_PAUSED "Paused"
886 memset(&parse_line
, '\0', sizeof(parse_line
));
887 strncpy((char *) &parse_line
, line
, sizeof(parse_line
) -1);
889 if (strlen((char *) &parse_line
) != sizeof(parse_line
) - 1) {
894 buf
->job
= atoi(parse_line
.jobid
);
896 /* Get the job name */
897 parse_line
.space2
[0] = '\0';
898 trim_char(parse_line
.jobname
, '\0', ' ');
899 fstrcpy(buf
->fs_file
, parse_line
.jobname
);
902 buf
->size
= atoi(parse_line
.size
);
903 buf
->time
= time(NULL
);
905 /* Make sure we have an owner */
906 if (!strlen(parse_line
.owner
)) {
910 /* Make sure we have a valid status */
911 parse_line
.space4
[0] = '\0';
912 trim_char(parse_line
.status
, '\0', ' ');
913 if (!strequal(parse_line
.status
, LPROS2_PRINTING
) &&
914 !strequal(parse_line
.status
, LPROS2_PAUSED
) &&
915 !strequal(parse_line
.status
, LPROS2_WAITING
)) {
919 fstrcpy(buf
->fs_user
, parse_line
.owner
);
920 if (strequal(parse_line
.status
, LPROS2_PRINTING
)) {
921 buf
->status
= LPQ_PRINTING
;
922 } else if (strequal(parse_line
.status
, LPROS2_PAUSED
)) {
923 buf
->status
= LPQ_PAUSED
;
925 buf
->status
= LPQ_QUEUED
;
931 static const char *stat0_strings
[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL
};
932 static const char *stat1_strings
[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL
};
933 static const char *stat2_strings
[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL
};
937 /****************************************************************************
939 ****************************************************************************/
941 static BOOL
parse_lpq_vlp(char *line
,print_queue_struct
*buf
,BOOL first
)
945 const char *cline
= line
;
947 /* First line is printer status */
949 if (!isdigit(line
[0])) return False
;
951 /* Parse a print job entry */
953 while(next_token(&cline
, tok
, NULL
, sizeof(fstring
))) {
956 buf
->job
= atoi(tok
);
959 buf
->size
= atoi(tok
);
962 buf
->status
= atoi(tok
);
965 buf
->time
= atoi(tok
);
968 fstrcpy(buf
->fs_user
, tok
);
971 fstrcpy(buf
->fs_file
, tok
);
980 #endif /* DEVELOPER */
982 /****************************************************************************
983 parse a lpq line. Choose printing style
984 ****************************************************************************/
986 BOOL
parse_lpq_entry(enum printing_types printing_type
,char *line
,
987 print_queue_struct
*buf
,
988 print_status_struct
*status
,BOOL first
)
992 switch (printing_type
) {
994 ret
= parse_lpq_sysv(line
,buf
,first
);
997 ret
= parse_lpq_aix(line
,buf
,first
);
1000 ret
= parse_lpq_hpux(line
,buf
,first
);
1003 ret
= parse_lpq_qnx(line
,buf
,first
);
1006 ret
= parse_lpq_lprng(line
,buf
,first
);
1009 ret
= parse_lpq_plp(line
,buf
,first
);
1012 ret
= parse_lpq_nt(line
,buf
,first
);
1015 ret
= parse_lpq_os2(line
,buf
,first
);
1020 ret
= parse_lpq_vlp(line
,buf
,first
);
1022 #endif /* DEVELOPER */
1024 ret
= parse_lpq_bsd(line
,buf
,first
);
1028 /* We don't want the newline in the status message. */
1030 char *p
= strchr_m(line
,'\n');
1036 /* in the LPRNG case, we skip lines starting by a space.*/
1037 if (!ret
&& (printing_type
==PRINT_LPRNG
) ) {
1043 if (status
&& !ret
) {
1044 /* a few simple checks to see if the line might be a
1045 printer status line:
1046 handle them so that most severe condition is shown */
1050 switch (status
->status
) {
1052 for (i
=0; stat0_strings
[i
]; i
++) {
1053 if (strstr_m(line
,stat0_strings
[i
])) {
1054 fstrcpy(status
->message
,line
);
1055 status
->status
=LPSTAT_OK
;
1060 case LPSTAT_STOPPED
:
1061 for (i
=0; stat1_strings
[i
]; i
++) {
1062 if (strstr_m(line
,stat1_strings
[i
])) {
1063 fstrcpy(status
->message
,line
);
1064 status
->status
=LPSTAT_STOPPED
;
1070 for (i
=0; stat2_strings
[i
]; i
++) {
1071 if (strstr_m(line
,stat2_strings
[i
])) {
1072 fstrcpy(status
->message
,line
);
1073 status
->status
=LPSTAT_ERROR
;