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/>.
22 static const char *Months
[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
23 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
26 /*******************************************************************
28 ********************************************************************/
30 static time_t EntryTime(char *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
;
39 for (i
=0; i
<13; i
++) {
40 if (!strncmp(tok
[ptr
], Months
[i
],3)) {
41 break; /* Find month */
47 t
= localtime(&jobtime
);
51 day
= atoi(tok
[ptr
+1]);
52 fstrcpy(c
,tok
[ptr
+2]);
63 if ((t
->tm_mon
< i
)|| ((t
->tm_mon
== i
)&&
65 ((t
->tm_mday
== day
)&&
66 (t
->tm_hour
*60+t
->tm_min
< hour
*60+min
))))) {
67 t
->tm_year
--; /* last year's print job */
76 if (jobtime1
!= (time_t)-1) {
84 /****************************************************************************
87 here is an example of lpq output under bsd
89 Warning: no daemon present
90 Rank Owner Job Files Total Size
91 1st tridge 148 README 8096 bytes
93 here is an example of lpq output under osf/1
95 Warning: no daemon present
96 Rank Pri Owner Job Files Total Size
97 1st 0 tridge 148 README 8096 bytes
100 <allan@umich.edu> June 30, 1998.
101 Modified to handle file names with spaces, like the parse_lpq_lprng code
103 ****************************************************************************/
105 static bool parse_lpq_bsd(char *line
,print_queue_struct
*buf
,bool first
)
113 #define TOTALTOK (count - 2)
121 #define TOTALTOK (count - 2)
128 TALLOC_CTX
*ctx
= talloc_tos();
132 line2
= talloc_strdup(ctx
, line
);
140 length
= strlen(line2
);
141 if (line2
[length
-3] == ':') {
147 /* FIXME: Use next_token_talloc rather than strtok! */
148 tok
[0] = strtok_r(line2
," \t", &saveptr
);
151 while ((count
< MAXTOK
)
152 && ((tok
[count
] = strtok_r(NULL
, " \t", &saveptr
)) != NULL
)) {
156 /* we must get at least NTOK tokens */
161 /* the Job and Total columns must be integer */
162 if (!isdigit((int)*tok
[JOBTOK
]) || !isdigit((int)*tok
[TOTALTOK
])) {
166 buf
->job
= atoi(tok
[JOBTOK
]);
167 buf
->size
= atoi(tok
[TOTALTOK
]);
168 buf
->status
= strequal(tok
[RANKTOK
],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
169 buf
->time
= time(NULL
);
170 fstrcpy(buf
->fs_user
,tok
[USERTOK
]);
171 fstrcpy(buf
->fs_file
,tok
[FILETOK
]);
173 if ((FILETOK
+ 1) != TOTALTOK
) {
176 for (i
= (FILETOK
+ 1); i
< TOTALTOK
; i
++) {
177 /* FIXME: Using fstrcat rather than other means is a bit
178 * inefficient; this might be a problem for enormous queues with
180 fstrcat(buf
->fs_file
, " ");
181 fstrcat(buf
->fs_file
, tok
[i
]);
183 /* Ensure null termination. */
184 buf
->fs_file
[sizeof(buf
->fs_file
)-1] = '\0';
188 buf
->priority
= atoi(tok
[PRIOTOK
]);
197 LPRng_time modifies the current date by inserting the hour and minute from
198 the lpq output. The lpq time looks like "23:15:07"
200 <allan@umich.edu> June 30, 1998.
201 Modified to work with the re-written parse_lpq_lprng routine.
203 <J.P.M.v.Itegem@tue.nl> Dec 17,1999
204 Modified to work with lprng 3.16
205 With lprng 3.16 The lpq time looks like
208 "1999-12-16-23:15:07"
209 "1999-12-16-23:15:07.100"
212 static time_t LPRng_time(char *time_string
)
217 jobtime
= time(NULL
); /* default case: take current time */
218 t
= localtime(&jobtime
);
223 if ( atoi(time_string
) < 24 ){
224 t
->tm_hour
= atoi(time_string
);
225 t
->tm_min
= atoi(time_string
+3);
226 t
->tm_sec
= atoi(time_string
+6);
228 t
->tm_year
= atoi(time_string
)-1900;
229 t
->tm_mon
= atoi(time_string
+5)-1;
230 t
->tm_mday
= atoi(time_string
+8);
231 t
->tm_hour
= atoi(time_string
+11);
232 t
->tm_min
= atoi(time_string
+14);
233 t
->tm_sec
= atoi(time_string
+17);
240 /****************************************************************************
241 parse a lprng lpq line
242 <allan@umich.edu> June 30, 1998.
243 Re-wrote this to handle file names with spaces, multiple file names on one
246 ****************************************************************************/
248 static bool parse_lpq_lprng(char *line
,print_queue_struct
*buf
,bool first
)
250 #define LPRNG_RANKTOK 0
251 #define LPRNG_USERTOK 1
252 #define LPRNG_PRIOTOK 2
253 #define LPRNG_JOBTOK 3
254 #define LPRNG_FILETOK 4
255 #define LPRNG_TOTALTOK (num_tok - 2)
256 #define LPRNG_TIMETOK (num_tok - 1)
258 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
260 char *tokarr
[LPRNG_MAXTOK
];
264 TALLOC_CTX
*frame
= talloc_stackframe();
267 while((num_tok
< LPRNG_MAXTOK
) && next_token_talloc(frame
, &cptr
,
268 &tokarr
[num_tok
], " \t")) {
272 /* We must get at least LPRNG_NTOK tokens. */
273 if (num_tok
< LPRNG_NTOK
) {
278 if (!isdigit((int)*tokarr
[LPRNG_JOBTOK
]) || !isdigit((int)*tokarr
[LPRNG_TOTALTOK
])) {
283 buf
->job
= atoi(tokarr
[LPRNG_JOBTOK
]);
284 buf
->size
= atoi(tokarr
[LPRNG_TOTALTOK
]);
286 if (strequal(tokarr
[LPRNG_RANKTOK
],"active")) {
287 buf
->status
= LPQ_PRINTING
;
288 } else if (strequal(tokarr
[LPRNG_RANKTOK
],"done")) {
289 buf
->status
= LPQ_PRINTED
;
290 } else if (isdigit((int)*tokarr
[LPRNG_RANKTOK
])) {
291 buf
->status
= LPQ_QUEUED
;
293 buf
->status
= LPQ_PAUSED
;
296 buf
->priority
= *tokarr
[LPRNG_PRIOTOK
] -'A';
298 buf
->time
= LPRng_time(tokarr
[LPRNG_TIMETOK
]);
300 fstrcpy(buf
->fs_user
,tokarr
[LPRNG_USERTOK
]);
302 /* The '@hostname' prevents windows from displaying the printing icon
303 * for the current user on the taskbar. Plop in a null.
306 if ((ptr
= strchr_m(buf
->fs_user
,'@')) != NULL
) {
310 fstrcpy(buf
->fs_file
,tokarr
[LPRNG_FILETOK
]);
312 if ((LPRNG_FILETOK
+ 1) != LPRNG_TOTALTOK
) {
315 for (i
= (LPRNG_FILETOK
+ 1); i
< LPRNG_TOTALTOK
; i
++) {
316 /* FIXME: Using fstrcat rather than other means is a bit
317 * inefficient; this might be a problem for enormous queues with
319 fstrcat(buf
->fs_file
, " ");
320 fstrcat(buf
->fs_file
, tokarr
[i
]);
322 /* Ensure null termination. */
323 buf
->fs_file
[sizeof(buf
->fs_file
)-1] = '\0';
330 /*******************************************************************
331 parse lpq on an aix system
333 Queue Dev Status Job Files User PP % Blks Cp Rnk
334 ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
336 lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1
337 QUEUED 538 C.ps root@IEDVB 124 1 2
338 QUEUED 539 E.ps root@IEDVB 28 1 3
339 QUEUED 540 L.ps root@IEDVB 172 1 4
340 QUEUED 541 P.ps root@IEDVB 22 1 5
341 ********************************************************************/
343 static bool parse_lpq_aix(char *line
,print_queue_struct
*buf
,bool first
)
347 const char *cline
= line
;
348 TALLOC_CTX
*frame
= talloc_stackframe();
350 /* handle the case of "(standard input)" as a filename */
351 string_sub(line
,"standard input","STDIN",0);
352 all_string_sub(line
,"(","\"",0);
353 all_string_sub(line
,")","\"",0);
355 for (count
=0; count
<10 &&
356 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
); count
++) {
360 /* we must get 6 tokens */
362 if ((count
== 7) && ((strcmp(tok
[0],"QUEUED") == 0) || (strcmp(tok
[0],"HELD") == 0))) {
363 /* the 2nd and 5th columns must be integer */
364 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[4])) {
368 buf
->size
= atoi(tok
[4]) * 1024;
369 /* if the fname contains a space then use STDIN */
370 if (strchr_m(tok
[2],' ')) {
371 tok
[2] = talloc_strdup(frame
,"STDIN");
378 /* only take the last part of the filename */
380 char *p
= strrchr_m(tok
[2],'/');
386 buf
->job
= atoi(tok
[1]);
387 buf
->status
= strequal(tok
[0],"HELD")?LPQ_PAUSED
:LPQ_QUEUED
;
389 buf
->time
= time(NULL
);
390 fstrcpy(buf
->fs_user
,tok
[3]);
391 fstrcpy(buf
->fs_file
,tok
[2]);
393 DEBUG(6,("parse_lpq_aix count=%d\n", count
));
398 /* the 4th and 9th columns must be integer */
399 if (!isdigit((int)*tok
[3]) || !isdigit((int)*tok
[8])) {
404 buf
->size
= atoi(tok
[8]) * 1024;
405 /* if the fname contains a space then use STDIN */
406 if (strchr_m(tok
[4],' ')) {
407 tok
[4] = talloc_strdup(frame
,"STDIN");
414 /* only take the last part of the filename */
416 char *p
= strrchr_m(tok
[4],'/');
422 buf
->job
= atoi(tok
[3]);
423 buf
->status
= strequal(tok
[2],"RUNNING")?LPQ_PRINTING
:LPQ_QUEUED
;
425 buf
->time
= time(NULL
);
426 fstrcpy(buf
->fs_user
,tok
[5]);
427 fstrcpy(buf
->fs_file
,tok
[4]);
434 /****************************************************************************
436 here is an example of lpq output under hpux; note there's no space after -o !
438 ljplus-2153 user priority 0 Jan 19 08:14 on ljplus
440 server.c 110712 bytes
441 ljplus-2154 user priority 0 Jan 19 08:14 from client
442 (standard input) 7551 bytes
443 ****************************************************************************/
445 static bool parse_lpq_hpux(char *line
, print_queue_struct
*buf
, bool first
)
447 /* must read two lines to process, therefore keep some values static */
448 static bool header_line_ok
=False
, base_prio_reset
=False
;
449 static char *jobuser
;
452 static time_t jobtime
;
453 static int jobstat
=LPQ_QUEUED
;
454 /* to store minimum priority to print, lpstat command should be invoked
455 with -p option first, to work */
456 static int base_prio
;
459 const char *cline
= line
;
461 TALLOC_CTX
*frame
= talloc_stackframe();
463 /* If a line begins with a horizontal TAB, it is a subline type */
465 if (line
[0] == htab
) { /* subline */
466 /* check if it contains the base priority */
467 if (!strncmp(line
,"\tfence priority : ",18)) {
468 base_prio
=atoi(&line
[18]);
469 DEBUG(4, ("fence priority set at %d\n", base_prio
));
472 if (!header_line_ok
) {
474 return False
; /* incorrect header line */
477 /* handle the case of "(standard input)" as a filename */
478 string_sub(line
,"standard input","STDIN",0);
479 all_string_sub(line
,"(","\"",0);
480 all_string_sub(line
,")","\"",0);
482 for (count
=0; count
<2 &&
483 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
487 /* we must get 2 tokens */
493 /* the 2nd column must be integer */
494 if (!isdigit((int)*tok
[1])) {
499 /* if the fname contains a space then use STDIN */
500 if (strchr_m(tok
[0],' ')) {
501 tok
[0] = talloc_strdup(frame
, "STDIN");
508 buf
->size
= atoi(tok
[1]);
509 fstrcpy(buf
->fs_file
,tok
[0]);
511 /* fill things from header line */
514 buf
->status
= jobstat
;
515 buf
->priority
= jobprio
;
517 fstrcpy(buf
->fs_user
,jobuser
);
519 buf
->fs_user
[0] = '\0';
524 } else { /* header line */
525 header_line_ok
=False
; /* reset it */
527 if (!base_prio_reset
) {
528 base_prio
=0; /* reset it */
529 base_prio_reset
=True
;
531 } else if (base_prio
) {
532 base_prio_reset
=False
;
535 /* handle the dash in the job id */
536 string_sub(line
,"-"," ",0);
538 for (count
=0; count
<12 &&
539 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
544 /* we must get 8 tokens */
550 /* first token must be printer name (cannot check ?) */
551 /* the 2nd, 5th & 7th column must be integer */
552 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[4]) || !isdigit((int)*tok
[6])) {
556 jobid
= atoi(tok
[1]);
558 jobuser
= SMB_STRDUP(tok
[2]);
559 jobprio
= atoi(tok
[4]);
562 jobtime
=EntryTime(tok
, 5, count
, 8);
563 if (jobprio
< base_prio
) {
564 jobstat
= LPQ_PAUSED
;
565 DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n",
566 jobid
, jobprio
, base_prio
, jobstat
));
568 jobstat
= LPQ_QUEUED
;
569 if ((count
>8) && (((strequal(tok
[8],"on")) ||
570 ((strequal(tok
[8],"from")) &&
571 ((count
> 10)&&(strequal(tok
[10],"on"))))))) {
572 jobstat
= LPQ_PRINTING
;
576 header_line_ok
=True
; /* information is correct */
578 return False
; /* need subline info to include into queuelist */
582 /****************************************************************************
585 here is an example of "lpstat -o dcslw" output under sysv
587 dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw
588 dcslw-897 tridge 4712 Dec 20 10:30:30 being held
590 ****************************************************************************/
592 static bool parse_lpq_sysv(char *line
,print_queue_struct
*buf
,bool first
)
597 const char *cline
= line
;
598 TALLOC_CTX
*frame
= NULL
;
601 * Handle the dash in the job id, but make sure that we skip over
602 * the printer name in case we have a dash in that.
603 * Patch from Dom.Mitchell@palmerharvey.co.uk.
607 * Move to the first space.
609 for (p
= line
; !isspace(*p
) && *p
; p
++) {
614 * Back up until the last '-' character or
617 for (; (p
>= line
) && (*p
!= '-'); p
--) {
621 if((p
>= line
) && (*p
== '-')) {
625 frame
= talloc_stackframe();
626 for (count
=0; count
<9 &&
627 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
632 /* we must get 7 tokens */
638 /* the 2nd and 4th, 6th columns must be integer */
639 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[3])) {
643 if (!isdigit((int)*tok
[5])) {
648 /* if the user contains a ! then trim the first part of it */
649 if ((p
=strchr_m(tok
[2],'!'))) {
653 buf
->job
= atoi(tok
[1]);
654 buf
->size
= atoi(tok
[3]);
655 if (count
> 7 && strequal(tok
[7],"on")) {
656 buf
->status
= LPQ_PRINTING
;
657 } else if (count
> 8 && strequal(tok
[7],"being") && strequal(tok
[8],"held")) {
658 buf
->status
= LPQ_PAUSED
;
660 buf
->status
= LPQ_QUEUED
;
663 buf
->time
= EntryTime(tok
, 4, count
, 7);
664 fstrcpy(buf
->fs_user
,tok
[2]);
665 fstrcpy(buf
->fs_file
,tok
[2]);
670 /****************************************************************************
673 here is an example of lpq output under qnx
674 Spooler: /qnx/spooler, on node 1
676 0000: root [job #1 ] active 1146 bytes /etc/profile
677 0001: root [job #2 ] ready 2378 bytes /etc/install
678 0002: root [job #3 ] ready 1146 bytes -- standard input --
679 ****************************************************************************/
681 static bool parse_lpq_qnx(char *line
,print_queue_struct
*buf
,bool first
)
685 const char *cline
= line
;
686 TALLOC_CTX
*frame
= NULL
;
688 DEBUG(4,("antes [%s]\n", line
));
690 /* handle the case of "-- standard input --" as a filename */
691 string_sub(line
,"standard input","STDIN",0);
692 DEBUG(4,("despues [%s]\n", line
));
693 all_string_sub(line
,"-- ","\"",0);
694 all_string_sub(line
," --","\"",0);
695 DEBUG(4,("despues 1 [%s]\n", line
));
697 string_sub(line
,"[job #","",0);
698 string_sub(line
,"]","",0);
699 DEBUG(4,("despues 2 [%s]\n", line
));
701 frame
= talloc_stackframe();
702 for (count
=0; count
<7 &&
703 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
);
708 /* we must get 7 tokens */
714 /* the 3rd and 5th columns must be integer */
715 if (!isdigit((int)*tok
[2]) || !isdigit((int)*tok
[4])) {
720 /* only take the last part of the filename */
722 char *p
= strrchr_m(tok
[6],'/');
728 buf
->job
= atoi(tok
[2]);
729 buf
->size
= atoi(tok
[4]);
730 buf
->status
= strequal(tok
[3],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
732 buf
->time
= time(NULL
);
733 fstrcpy(buf
->fs_user
,tok
[1]);
734 fstrcpy(buf
->fs_file
,tok
[6]);
739 /****************************************************************************
740 parse a lpq line for the plp printing system
741 Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
743 redone by tridge. Here is a sample queue:
745 Local Printer 'lp2' (fjall):
746 Printing (started at Jun 15 13:33:58, attempt 1).
747 Rank Owner Pr Opt Job Host Files Size Date
748 active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
749 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
751 ****************************************************************************/
753 static bool parse_lpq_plp(char *line
,print_queue_struct
*buf
,bool first
)
757 const char *cline
= line
;
758 TALLOC_CTX
*frame
= talloc_stackframe();
760 /* handle the case of "(standard input)" as a filename */
761 string_sub(line
,"stdin","STDIN",0);
762 all_string_sub(line
,"(","\"",0);
763 all_string_sub(line
,")","\"",0);
765 for (count
=0; count
<11 &&
766 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
);
771 /* we must get 11 tokens */
777 /* the first must be "active" or begin with an integer */
778 if (strcmp(tok
[0],"active") && !isdigit((int)tok
[0][0])) {
783 /* the 5th and 8th must be integer */
784 if (!isdigit((int)*tok
[4]) || !isdigit((int)*tok
[7])) {
789 /* if the fname contains a space then use STDIN */
790 if (strchr_m(tok
[6],' ')) {
791 tok
[6] = talloc_strdup(frame
, "STDIN");
798 /* only take the last part of the filename */
801 char *p
= strrchr_m(tok
[6],'/');
808 buf
->job
= atoi(tok
[4]);
810 buf
->size
= atoi(tok
[7]);
811 if (strchr_m(tok
[7],'K')) {
814 if (strchr_m(tok
[7],'M')) {
815 buf
->size
*= 1024*1024;
818 buf
->status
= strequal(tok
[0],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
820 buf
->time
= time(NULL
);
821 fstrcpy(buf
->fs_user
,tok
[1]);
822 fstrcpy(buf
->fs_file
,tok
[6]);
827 /*******************************************************************
828 parse lpq on an NT system
830 Windows 2000 LPD Server
831 Printer \\10.0.0.2\NP17PCL (Paused)
833 Owner Status Jobname Job-Id Size Pages Priority
834 ----------------------------------------------------------------------------
835 root (9.99. Printing /usr/lib/rhs/rhs-pr 3 625 0 1
836 root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1
837 jmcd Waiting Re: Samba Open Sour 26 32476 1 1
839 ********************************************************************/
841 static bool parse_lpq_nt(char *line
,print_queue_struct
*buf
,bool first
)
843 #define LPRNT_OWNSIZ 11
844 #define LPRNT_STATSIZ 9
845 #define LPRNT_JOBSIZ 19
846 #define LPRNT_IDSIZ 6
847 #define LPRNT_SIZSIZ 9
849 char owner
[LPRNT_OWNSIZ
];
851 char status
[LPRNT_STATSIZ
];
853 char jobname
[LPRNT_JOBSIZ
];
855 char jobid
[LPRNT_IDSIZ
];
857 char size
[LPRNT_SIZSIZ
];
861 nt_lpq_line parse_line
;
862 #define LPRNT_PRINTING "Printing"
863 #define LPRNT_WAITING "Waiting"
864 #define LPRNT_PAUSED "Paused"
866 memset(&parse_line
, '\0', sizeof(parse_line
));
867 strncpy((char *) &parse_line
, line
, sizeof(parse_line
) -1);
869 if (strlen((char *) &parse_line
) != sizeof(parse_line
) - 1) {
873 /* Just want the first word in the owner field - the username */
874 if (strchr_m(parse_line
.owner
, ' ')) {
875 *(strchr_m(parse_line
.owner
, ' ')) = '\0';
877 parse_line
.space1
= '\0';
880 /* Make sure we have an owner */
881 if (!strlen(parse_line
.owner
)) {
885 /* Make sure the status is valid */
886 parse_line
.space2
= '\0';
887 trim_char(parse_line
.status
, '\0', ' ');
888 if (!strequal(parse_line
.status
, LPRNT_PRINTING
) &&
889 !strequal(parse_line
.status
, LPRNT_PAUSED
) &&
890 !strequal(parse_line
.status
, LPRNT_WAITING
)) {
894 parse_line
.space3
= '\0';
895 trim_char(parse_line
.jobname
, '\0', ' ');
897 buf
->job
= atoi(parse_line
.jobid
);
899 buf
->size
= atoi(parse_line
.size
);
900 buf
->time
= time(NULL
);
901 fstrcpy(buf
->fs_user
, parse_line
.owner
);
902 fstrcpy(buf
->fs_file
, parse_line
.jobname
);
903 if (strequal(parse_line
.status
, LPRNT_PRINTING
)) {
904 buf
->status
= LPQ_PRINTING
;
905 } else if (strequal(parse_line
.status
, LPRNT_PAUSED
)) {
906 buf
->status
= LPQ_PAUSED
;
908 buf
->status
= LPQ_QUEUED
;
914 /*******************************************************************
915 parse lpq on an OS2 system
917 JobID File Name Rank Size Status Comment
918 ----- --------------- ------ -------- ------------ ------------
919 3 Control 1 68 Queued root@psflinu
920 4 /etc/motd 2 11666 Queued root@psflinu
922 ********************************************************************/
924 static bool parse_lpq_os2(char *line
,print_queue_struct
*buf
,bool first
)
926 #define LPROS2_IDSIZ 5
927 #define LPROS2_JOBSIZ 15
928 #define LPROS2_SIZSIZ 8
929 #define LPROS2_STATSIZ 12
930 #define LPROS2_OWNSIZ 12
932 char jobid
[LPROS2_IDSIZ
];
934 char jobname
[LPROS2_JOBSIZ
];
936 char size
[LPROS2_SIZSIZ
];
938 char status
[LPROS2_STATSIZ
];
940 char owner
[LPROS2_OWNSIZ
];
944 os2_lpq_line parse_line
;
945 #define LPROS2_PRINTING "Printing"
946 #define LPROS2_WAITING "Queued"
947 #define LPROS2_PAUSED "Paused"
949 memset(&parse_line
, '\0', sizeof(parse_line
));
950 strncpy((char *) &parse_line
, line
, sizeof(parse_line
) -1);
952 if (strlen((char *) &parse_line
) != sizeof(parse_line
) - 1) {
957 buf
->job
= atoi(parse_line
.jobid
);
959 /* Get the job name */
960 parse_line
.space2
[0] = '\0';
961 trim_char(parse_line
.jobname
, '\0', ' ');
962 fstrcpy(buf
->fs_file
, parse_line
.jobname
);
965 buf
->size
= atoi(parse_line
.size
);
966 buf
->time
= time(NULL
);
968 /* Make sure we have an owner */
969 if (!strlen(parse_line
.owner
)) {
973 /* Make sure we have a valid status */
974 parse_line
.space4
[0] = '\0';
975 trim_char(parse_line
.status
, '\0', ' ');
976 if (!strequal(parse_line
.status
, LPROS2_PRINTING
) &&
977 !strequal(parse_line
.status
, LPROS2_PAUSED
) &&
978 !strequal(parse_line
.status
, LPROS2_WAITING
)) {
982 fstrcpy(buf
->fs_user
, parse_line
.owner
);
983 if (strequal(parse_line
.status
, LPROS2_PRINTING
)) {
984 buf
->status
= LPQ_PRINTING
;
985 } else if (strequal(parse_line
.status
, LPROS2_PAUSED
)) {
986 buf
->status
= LPQ_PAUSED
;
988 buf
->status
= LPQ_QUEUED
;
994 static const char *stat0_strings
[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL
};
995 static const char *stat1_strings
[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL
};
996 static const char *stat2_strings
[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL
};
1000 /****************************************************************************
1002 ****************************************************************************/
1004 static bool parse_lpq_vlp(char *line
,print_queue_struct
*buf
,bool first
)
1008 TALLOC_CTX
*frame
= talloc_stackframe();
1009 const char *cline
= line
;
1011 /* First line is printer status */
1013 if (!isdigit(line
[0])) {
1018 /* Parse a print job entry */
1020 while(next_token_talloc(frame
, &cline
, &tok
, NULL
)) {
1023 buf
->job
= atoi(tok
);
1026 buf
->size
= atoi(tok
);
1029 buf
->status
= atoi(tok
);
1032 buf
->time
= atoi(tok
);
1035 fstrcpy(buf
->fs_user
, tok
);
1038 fstrcpy(buf
->fs_file
, tok
);
1048 #endif /* DEVELOPER */
1050 /****************************************************************************
1051 parse a lpq line. Choose printing style
1052 ****************************************************************************/
1054 bool parse_lpq_entry(enum printing_types printing_type
,char *line
,
1055 print_queue_struct
*buf
,
1056 print_status_struct
*status
,bool first
)
1060 switch (printing_type
) {
1062 ret
= parse_lpq_sysv(line
,buf
,first
);
1065 ret
= parse_lpq_aix(line
,buf
,first
);
1068 ret
= parse_lpq_hpux(line
,buf
,first
);
1071 ret
= parse_lpq_qnx(line
,buf
,first
);
1074 ret
= parse_lpq_lprng(line
,buf
,first
);
1077 ret
= parse_lpq_plp(line
,buf
,first
);
1080 ret
= parse_lpq_nt(line
,buf
,first
);
1083 ret
= parse_lpq_os2(line
,buf
,first
);
1088 ret
= parse_lpq_vlp(line
,buf
,first
);
1090 #endif /* DEVELOPER */
1092 ret
= parse_lpq_bsd(line
,buf
,first
);
1096 /* We don't want the newline in the status message. */
1098 char *p
= strchr_m(line
,'\n');
1104 /* in the LPRNG case, we skip lines starting by a space.*/
1105 if (!ret
&& (printing_type
==PRINT_LPRNG
) ) {
1111 if (status
&& !ret
) {
1112 /* a few simple checks to see if the line might be a
1113 printer status line:
1114 handle them so that most severe condition is shown */
1118 switch (status
->status
) {
1120 for (i
=0; stat0_strings
[i
]; i
++) {
1121 if (strstr_m(line
,stat0_strings
[i
])) {
1122 fstrcpy(status
->message
,line
);
1123 status
->status
=LPSTAT_OK
;
1128 case LPSTAT_STOPPED
:
1129 for (i
=0; stat1_strings
[i
]; i
++) {
1130 if (strstr_m(line
,stat1_strings
[i
])) {
1131 fstrcpy(status
->message
,line
);
1132 status
->status
=LPSTAT_STOPPED
;
1138 for (i
=0; stat2_strings
[i
]; i
++) {
1139 if (strstr_m(line
,stat2_strings
[i
])) {
1140 fstrcpy(status
->message
,line
);
1141 status
->status
=LPSTAT_ERROR
;