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 #include "lib/util/string_wrappers.h"
24 static const char *Months
[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
25 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
28 /*******************************************************************
30 ********************************************************************/
32 static time_t EntryTime(char *tok
[], int ptr
, int count
, int minimum
)
34 time_t jobtime
,jobtime1
;
36 jobtime
= time(NULL
); /* default case: take current time */
37 if (count
>= minimum
) {
39 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 */
49 t
= localtime(&jobtime
);
53 day
= atoi(tok
[ptr
+1]);
54 fstrcpy(c
,tok
[ptr
+2]);
65 if ((t
->tm_mon
< i
)|| ((t
->tm_mon
== i
)&&
67 ((t
->tm_mday
== day
)&&
68 (t
->tm_hour
*60+t
->tm_min
< hour
*60+min
))))) {
69 t
->tm_year
--; /* last year's print job */
78 if (jobtime1
!= (time_t)-1) {
86 /****************************************************************************
89 here is an example of lpq output under bsd
91 Warning: no daemon present
92 Rank Owner Job Files Total Size
93 1st tridge 148 README 8096 bytes
95 here is an example of lpq output under osf/1
97 Warning: no daemon present
98 Rank Pri Owner Job Files Total Size
99 1st 0 tridge 148 README 8096 bytes
102 <allan@umich.edu> June 30, 1998.
103 Modified to handle file names with spaces, like the parse_lpq_lprng code
105 ****************************************************************************/
107 static bool parse_lpq_bsd(char *line
,print_queue_struct
*buf
,bool first
)
115 #define TOTALTOK (count - 2)
123 #define TOTALTOK (count - 2)
130 TALLOC_CTX
*ctx
= talloc_tos();
134 line2
= talloc_strdup(ctx
, line
);
142 length
= strlen(line2
);
143 if (line2
[length
-3] == ':') {
149 /* FIXME: Use next_token_talloc rather than strtok! */
150 tok
[0] = strtok_r(line2
," \t", &saveptr
);
153 while ((count
< MAXTOK
)
154 && ((tok
[count
] = strtok_r(NULL
, " \t", &saveptr
)) != NULL
)) {
158 /* we must get at least NTOK tokens */
163 /* the Job and Total columns must be integer */
164 if (!isdigit((int)*tok
[JOBTOK
]) || !isdigit((int)*tok
[TOTALTOK
])) {
168 buf
->sysjob
= atoi(tok
[JOBTOK
]);
169 buf
->size
= atoi(tok
[TOTALTOK
]);
170 buf
->status
= strequal(tok
[RANKTOK
],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
171 buf
->time
= time(NULL
);
172 fstrcpy(buf
->fs_user
,tok
[USERTOK
]);
173 fstrcpy(buf
->fs_file
,tok
[FILETOK
]);
175 if ((FILETOK
+ 1) != TOTALTOK
) {
178 for (i
= (FILETOK
+ 1); i
< TOTALTOK
; i
++) {
179 /* FIXME: Using fstrcat rather than other means is a bit
180 * inefficient; this might be a problem for enormous queues with
182 fstrcat(buf
->fs_file
, " ");
183 fstrcat(buf
->fs_file
, tok
[i
]);
185 /* Ensure null termination. */
186 buf
->fs_file
[sizeof(buf
->fs_file
)-1] = '\0';
190 buf
->priority
= atoi(tok
[PRIOTOK
]);
199 LPRng_time modifies the current date by inserting the hour and minute from
200 the lpq output. The lpq time looks like "23:15:07"
202 <allan@umich.edu> June 30, 1998.
203 Modified to work with the re-written parse_lpq_lprng routine.
205 <J.P.M.v.Itegem@tue.nl> Dec 17,1999
206 Modified to work with lprng 3.16
207 With lprng 3.16 The lpq time looks like
210 "1999-12-16-23:15:07"
211 "1999-12-16-23:15:07.100"
214 static time_t LPRng_time(char *time_string
)
219 jobtime
= time(NULL
); /* default case: take current time */
220 t
= localtime(&jobtime
);
225 if ( atoi(time_string
) < 24 ){
226 if (strlen(time_string
) < 7) {
229 t
->tm_hour
= atoi(time_string
);
230 t
->tm_min
= atoi(time_string
+3);
231 t
->tm_sec
= atoi(time_string
+6);
233 if (strlen(time_string
) < 18) {
236 t
->tm_year
= atoi(time_string
)-1900;
237 t
->tm_mon
= atoi(time_string
+5)-1;
238 t
->tm_mday
= atoi(time_string
+8);
239 t
->tm_hour
= atoi(time_string
+11);
240 t
->tm_min
= atoi(time_string
+14);
241 t
->tm_sec
= atoi(time_string
+17);
248 /****************************************************************************
249 parse a lprng lpq line
250 <allan@umich.edu> June 30, 1998.
251 Re-wrote this to handle file names with spaces, multiple file names on one
254 ****************************************************************************/
256 static bool parse_lpq_lprng(char *line
,print_queue_struct
*buf
,bool first
)
258 #define LPRNG_RANKTOK 0
259 #define LPRNG_USERTOK 1
260 #define LPRNG_PRIOTOK 2
261 #define LPRNG_JOBTOK 3
262 #define LPRNG_FILETOK 4
263 #define LPRNG_TOTALTOK (num_tok - 2)
264 #define LPRNG_TIMETOK (num_tok - 1)
266 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
268 char *tokarr
[LPRNG_MAXTOK
];
272 TALLOC_CTX
*frame
= talloc_stackframe();
275 while((num_tok
< LPRNG_MAXTOK
) && next_token_talloc(frame
, &cptr
,
276 &tokarr
[num_tok
], " \t")) {
280 /* We must get at least LPRNG_NTOK tokens. */
281 if (num_tok
< LPRNG_NTOK
) {
286 if (!isdigit((int)*tokarr
[LPRNG_JOBTOK
]) || !isdigit((int)*tokarr
[LPRNG_TOTALTOK
])) {
291 buf
->sysjob
= atoi(tokarr
[LPRNG_JOBTOK
]);
292 buf
->size
= atoi(tokarr
[LPRNG_TOTALTOK
]);
294 if (strequal(tokarr
[LPRNG_RANKTOK
],"active")) {
295 buf
->status
= LPQ_PRINTING
;
296 } else if (strequal(tokarr
[LPRNG_RANKTOK
],"done")) {
297 buf
->status
= LPQ_PRINTED
;
298 } else if (isdigit((int)*tokarr
[LPRNG_RANKTOK
])) {
299 buf
->status
= LPQ_QUEUED
;
301 buf
->status
= LPQ_PAUSED
;
304 buf
->priority
= *tokarr
[LPRNG_PRIOTOK
] -'A';
306 buf
->time
= LPRng_time(tokarr
[LPRNG_TIMETOK
]);
308 fstrcpy(buf
->fs_user
,tokarr
[LPRNG_USERTOK
]);
310 /* The '@hostname' prevents windows from displaying the printing icon
311 * for the current user on the taskbar. Plop in a null.
314 if ((ptr
= strchr_m(buf
->fs_user
,'@')) != NULL
) {
318 fstrcpy(buf
->fs_file
,tokarr
[LPRNG_FILETOK
]);
320 if ((LPRNG_FILETOK
+ 1) != LPRNG_TOTALTOK
) {
323 for (i
= (LPRNG_FILETOK
+ 1); i
< LPRNG_TOTALTOK
; i
++) {
324 /* FIXME: Using fstrcat rather than other means is a bit
325 * inefficient; this might be a problem for enormous queues with
327 fstrcat(buf
->fs_file
, " ");
328 fstrcat(buf
->fs_file
, tokarr
[i
]);
330 /* Ensure null termination. */
331 buf
->fs_file
[sizeof(buf
->fs_file
)-1] = '\0';
338 /*******************************************************************
339 parse lpq on an aix system
341 Queue Dev Status Job Files User PP % Blks Cp Rnk
342 ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
344 lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1
345 QUEUED 538 C.ps root@IEDVB 124 1 2
346 QUEUED 539 E.ps root@IEDVB 28 1 3
347 QUEUED 540 L.ps root@IEDVB 172 1 4
348 QUEUED 541 P.ps root@IEDVB 22 1 5
349 ********************************************************************/
351 static bool parse_lpq_aix(char *line
,print_queue_struct
*buf
,bool first
)
355 const char *cline
= line
;
356 TALLOC_CTX
*frame
= talloc_stackframe();
358 /* handle the case of "(standard input)" as a filename */
359 string_sub(line
,"standard input","STDIN",0);
360 all_string_sub(line
,"(","\"",0);
361 all_string_sub(line
,")","\"",0);
363 for (count
=0; count
<10 &&
364 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
); count
++) {
368 /* we must get 6 tokens */
370 if ((count
== 7) && ((strcmp(tok
[0],"QUEUED") == 0) || (strcmp(tok
[0],"HELD") == 0))) {
371 /* the 2nd and 5th columns must be integer */
372 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[4])) {
376 buf
->size
= atoi(tok
[4]) * 1024;
377 /* if the fname contains a space then use STDIN */
378 if (strchr_m(tok
[2],' ')) {
379 tok
[2] = talloc_strdup(frame
,"STDIN");
386 /* only take the last part of the filename */
388 char *p
= strrchr_m(tok
[2],'/');
394 buf
->sysjob
= atoi(tok
[1]);
395 buf
->status
= strequal(tok
[0],"HELD")?LPQ_PAUSED
:LPQ_QUEUED
;
397 buf
->time
= time(NULL
);
398 fstrcpy(buf
->fs_user
,tok
[3]);
399 fstrcpy(buf
->fs_file
,tok
[2]);
401 DEBUG(6,("parse_lpq_aix count=%d\n", count
));
406 /* the 4th and 9th columns must be integer */
407 if (!isdigit((int)*tok
[3]) || !isdigit((int)*tok
[8])) {
412 buf
->size
= atoi(tok
[8]) * 1024;
413 /* if the fname contains a space then use STDIN */
414 if (strchr_m(tok
[4],' ')) {
415 tok
[4] = talloc_strdup(frame
,"STDIN");
422 /* only take the last part of the filename */
424 char *p
= strrchr_m(tok
[4],'/');
430 buf
->sysjob
= atoi(tok
[3]);
431 buf
->status
= strequal(tok
[2],"RUNNING")?LPQ_PRINTING
:LPQ_QUEUED
;
433 buf
->time
= time(NULL
);
434 fstrcpy(buf
->fs_user
,tok
[5]);
435 fstrcpy(buf
->fs_file
,tok
[4]);
442 /****************************************************************************
444 here is an example of lpq output under hpux; note there's no space after -o !
446 ljplus-2153 user priority 0 Jan 19 08:14 on ljplus
448 server.c 110712 bytes
449 ljplus-2154 user priority 0 Jan 19 08:14 from client
450 (standard input) 7551 bytes
451 ****************************************************************************/
453 static bool parse_lpq_hpux(char *line
, print_queue_struct
*buf
, bool first
)
455 /* must read two lines to process, therefore keep some values static */
456 static bool header_line_ok
=False
, base_prio_reset
=False
;
457 static char *jobuser
;
460 static time_t jobtime
;
461 static int jobstat
=LPQ_QUEUED
;
462 /* to store minimum priority to print, lpstat command should be invoked
463 with -p option first, to work */
464 static int base_prio
;
467 const char *cline
= line
;
469 TALLOC_CTX
*frame
= talloc_stackframe();
471 /* If a line begins with a horizontal TAB, it is a subline type */
473 if (line
[0] == htab
) { /* subline */
474 /* check if it contains the base priority */
475 if (!strncmp(line
,"\tfence priority : ",18)) {
476 base_prio
=atoi(&line
[18]);
477 DEBUG(4, ("fence priority set at %d\n", base_prio
));
480 if (!header_line_ok
) {
482 return False
; /* incorrect header line */
485 /* handle the case of "(standard input)" as a filename */
486 string_sub(line
,"standard input","STDIN",0);
487 all_string_sub(line
,"(","\"",0);
488 all_string_sub(line
,")","\"",0);
490 for (count
=0; count
<2 &&
491 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
495 /* we must get 2 tokens */
501 /* the 2nd column must be integer */
502 if (!isdigit((int)*tok
[1])) {
507 /* if the fname contains a space then use STDIN */
508 if (strchr_m(tok
[0],' ')) {
509 tok
[0] = talloc_strdup(frame
, "STDIN");
516 buf
->size
= atoi(tok
[1]);
517 fstrcpy(buf
->fs_file
,tok
[0]);
519 /* fill things from header line */
522 buf
->status
= jobstat
;
523 buf
->priority
= jobprio
;
525 fstrcpy(buf
->fs_user
,jobuser
);
527 buf
->fs_user
[0] = '\0';
532 } else { /* header line */
533 header_line_ok
=False
; /* reset it */
535 if (!base_prio_reset
) {
536 base_prio
=0; /* reset it */
537 base_prio_reset
=True
;
539 } else if (base_prio
) {
540 base_prio_reset
=False
;
543 /* handle the dash in the job id */
544 string_sub(line
,"-"," ",0);
546 for (count
=0; count
<12 &&
547 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
552 /* we must get 8 tokens */
558 /* first token must be printer name (cannot check ?) */
559 /* the 2nd, 5th & 7th column must be integer */
560 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[4]) || !isdigit((int)*tok
[6])) {
564 jobid
= atoi(tok
[1]);
566 jobuser
= SMB_STRDUP(tok
[2]);
567 jobprio
= atoi(tok
[4]);
570 jobtime
=EntryTime(tok
, 5, count
, 8);
571 if (jobprio
< base_prio
) {
572 jobstat
= LPQ_PAUSED
;
573 DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n",
574 jobid
, jobprio
, base_prio
, jobstat
));
576 jobstat
= LPQ_QUEUED
;
577 if ((count
>8) && (((strequal(tok
[8],"on")) ||
578 ((strequal(tok
[8],"from")) &&
579 ((count
> 10)&&(strequal(tok
[10],"on"))))))) {
580 jobstat
= LPQ_PRINTING
;
584 header_line_ok
=True
; /* information is correct */
586 return False
; /* need subline info to include into queuelist */
590 /****************************************************************************
593 here is an example of "lpstat -o dcslw" output under sysv
595 dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw
596 dcslw-897 tridge 4712 Dec 20 10:30:30 being held
598 ****************************************************************************/
600 static bool parse_lpq_sysv(char *line
,print_queue_struct
*buf
,bool first
)
605 const char *cline
= line
;
606 TALLOC_CTX
*frame
= NULL
;
609 * Handle the dash in the job id, but make sure that we skip over
610 * the printer name in case we have a dash in that.
611 * Patch from Dom.Mitchell@palmerharvey.co.uk.
615 * Move to the first space.
617 for (p
= line
; !isspace(*p
) && *p
; p
++) {
622 * Back up until the last '-' character or
625 for (; (p
>= line
) && (*p
!= '-'); p
--) {
629 if((p
>= line
) && (*p
== '-')) {
633 frame
= talloc_stackframe();
634 for (count
=0; count
<9 &&
635 next_token_talloc(frame
, &cline
, &tok
[count
],NULL
);
640 /* we must get 7 tokens */
646 /* the 2nd and 4th, 6th columns must be integer */
647 if (!isdigit((int)*tok
[1]) || !isdigit((int)*tok
[3])) {
651 if (!isdigit((int)*tok
[5])) {
656 /* if the user contains a ! then trim the first part of it */
657 if ((p
=strchr_m(tok
[2],'!'))) {
661 buf
->sysjob
= atoi(tok
[1]);
662 buf
->size
= atoi(tok
[3]);
663 if (count
> 7 && strequal(tok
[7],"on")) {
664 buf
->status
= LPQ_PRINTING
;
665 } else if (count
> 8 && strequal(tok
[7],"being") && strequal(tok
[8],"held")) {
666 buf
->status
= LPQ_PAUSED
;
668 buf
->status
= LPQ_QUEUED
;
671 buf
->time
= EntryTime(tok
, 4, count
, 7);
672 fstrcpy(buf
->fs_user
,tok
[2]);
673 fstrcpy(buf
->fs_file
,tok
[2]);
678 /****************************************************************************
681 here is an example of lpq output under qnx
682 Spooler: /qnx/spooler, on node 1
684 0000: root [job #1 ] active 1146 bytes /etc/profile
685 0001: root [job #2 ] ready 2378 bytes /etc/install
686 0002: root [job #3 ] ready 1146 bytes -- standard input --
687 ****************************************************************************/
689 static bool parse_lpq_qnx(char *line
,print_queue_struct
*buf
,bool first
)
693 const char *cline
= line
;
694 TALLOC_CTX
*frame
= NULL
;
696 DEBUG(4,("antes [%s]\n", line
));
698 /* handle the case of "-- standard input --" as a filename */
699 string_sub(line
,"standard input","STDIN",0);
700 DEBUG(4,("despues [%s]\n", line
));
701 all_string_sub(line
,"-- ","\"",0);
702 all_string_sub(line
," --","\"",0);
703 DEBUG(4,("despues 1 [%s]\n", line
));
705 string_sub(line
,"[job #","",0);
706 string_sub(line
,"]","",0);
707 DEBUG(4,("despues 2 [%s]\n", line
));
709 frame
= talloc_stackframe();
710 for (count
=0; count
<7 &&
711 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
);
716 /* we must get 7 tokens */
722 /* the 3rd and 5th columns must be integer */
723 if (!isdigit((int)*tok
[2]) || !isdigit((int)*tok
[4])) {
728 /* only take the last part of the filename */
730 char *p
= strrchr_m(tok
[6],'/');
736 buf
->sysjob
= atoi(tok
[2]);
737 buf
->size
= atoi(tok
[4]);
738 buf
->status
= strequal(tok
[3],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
740 buf
->time
= time(NULL
);
741 fstrcpy(buf
->fs_user
,tok
[1]);
742 fstrcpy(buf
->fs_file
,tok
[6]);
747 /****************************************************************************
748 parse a lpq line for the plp printing system
749 Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
751 redone by tridge. Here is a sample queue:
753 Local Printer 'lp2' (fjall):
754 Printing (started at Jun 15 13:33:58, attempt 1).
755 Rank Owner Pr Opt Job Host Files Size Date
756 active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
757 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
759 ****************************************************************************/
761 static bool parse_lpq_plp(char *line
,print_queue_struct
*buf
,bool first
)
765 const char *cline
= line
;
766 TALLOC_CTX
*frame
= talloc_stackframe();
768 /* handle the case of "(standard input)" as a filename */
769 string_sub(line
,"stdin","STDIN",0);
770 all_string_sub(line
,"(","\"",0);
771 all_string_sub(line
,")","\"",0);
773 for (count
=0; count
<11 &&
774 next_token_talloc(frame
,&cline
,&tok
[count
],NULL
);
779 /* we must get 11 tokens */
785 /* the first must be "active" or begin with an integer */
786 if (strcmp(tok
[0],"active") && !isdigit((int)tok
[0][0])) {
791 /* the 5th and 8th must be integer */
792 if (!isdigit((int)*tok
[4]) || !isdigit((int)*tok
[7])) {
797 /* if the fname contains a space then use STDIN */
798 if (strchr_m(tok
[6],' ')) {
799 tok
[6] = talloc_strdup(frame
, "STDIN");
806 /* only take the last part of the filename */
809 char *p
= strrchr_m(tok
[6],'/');
811 size_t len
= strlen(tok
[6])+1;
813 strlcpy(tok
[6],tmp
, len
);
817 buf
->sysjob
= atoi(tok
[4]);
819 buf
->size
= atoi(tok
[7]);
820 if (strchr_m(tok
[7],'K')) {
823 if (strchr_m(tok
[7],'M')) {
824 buf
->size
*= 1024*1024;
827 buf
->status
= strequal(tok
[0],"active")?LPQ_PRINTING
:LPQ_QUEUED
;
829 buf
->time
= time(NULL
);
830 fstrcpy(buf
->fs_user
,tok
[1]);
831 fstrcpy(buf
->fs_file
,tok
[6]);
836 /*******************************************************************
837 parse lpq on an NT system
839 Windows 2000 LPD Server
840 Printer \\10.0.0.2\NP17PCL (Paused)
842 Owner Status Jobname Job-Id Size Pages Priority
843 ----------------------------------------------------------------------------
844 root (9.99. Printing /usr/lib/rhs/rhs-pr 3 625 0 1
845 root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1
846 jmcd Waiting Re: Samba Open Sour 26 32476 1 1
848 ********************************************************************/
850 static bool parse_lpq_nt(char *line
,print_queue_struct
*buf
,bool first
)
852 #define LPRNT_OWNSIZ 11
853 #define LPRNT_STATSIZ 9
854 #define LPRNT_JOBSIZ 19
855 #define LPRNT_IDSIZ 6
856 #define LPRNT_SIZSIZ 9
858 char owner
[LPRNT_OWNSIZ
];
860 char status
[LPRNT_STATSIZ
];
862 char jobname
[LPRNT_JOBSIZ
];
864 char jobid
[LPRNT_IDSIZ
];
866 char size
[LPRNT_SIZSIZ
];
870 char parse_line_char
[sizeof(nt_lpq_line
)];
871 nt_lpq_line
*parse_line
= (nt_lpq_line
*)parse_line_char
;
872 #define LPRNT_PRINTING "Printing"
873 #define LPRNT_WAITING "Waiting"
874 #define LPRNT_PAUSED "Paused"
876 memset(parse_line_char
, '\0', sizeof(parse_line_char
));
877 strncpy(parse_line_char
, line
, sizeof(parse_line_char
) -1);
879 if (strlen(parse_line_char
) != sizeof(parse_line_char
) - 1) {
883 /* Just want the first word in the owner field - the username */
884 if (strchr_m(parse_line
->owner
, ' ')) {
885 *(strchr_m(parse_line
->owner
, ' ')) = '\0';
887 parse_line
->space1
= '\0';
890 /* Make sure we have an owner */
891 if (!strlen(parse_line
->owner
)) {
895 /* Make sure the status is valid */
896 parse_line
->space2
= '\0';
897 trim_char(parse_line
->status
, '\0', ' ');
898 if (!strequal(parse_line
->status
, LPRNT_PRINTING
) &&
899 !strequal(parse_line
->status
, LPRNT_PAUSED
) &&
900 !strequal(parse_line
->status
, LPRNT_WAITING
)) {
904 parse_line
->space3
= '\0';
905 trim_char(parse_line
->jobname
, '\0', ' ');
907 buf
->sysjob
= atoi(parse_line
->jobid
);
909 buf
->size
= atoi(parse_line
->size
);
910 buf
->time
= time(NULL
);
911 fstrcpy(buf
->fs_user
, parse_line
->owner
);
912 fstrcpy(buf
->fs_file
, parse_line
->jobname
);
913 if (strequal(parse_line
->status
, LPRNT_PRINTING
)) {
914 buf
->status
= LPQ_PRINTING
;
915 } else if (strequal(parse_line
->status
, LPRNT_PAUSED
)) {
916 buf
->status
= LPQ_PAUSED
;
918 buf
->status
= LPQ_QUEUED
;
924 /*******************************************************************
925 parse lpq on an OS2 system
927 JobID File Name Rank Size Status Comment
928 ----- --------------- ------ -------- ------------ ------------
929 3 Control 1 68 Queued root@psflinu
930 4 /etc/motd 2 11666 Queued root@psflinu
932 ********************************************************************/
934 static bool parse_lpq_os2(char *line
,print_queue_struct
*buf
,bool first
)
936 #define LPROS2_IDSIZ 5
937 #define LPROS2_JOBSIZ 15
938 #define LPROS2_SIZSIZ 8
939 #define LPROS2_STATSIZ 12
940 #define LPROS2_OWNSIZ 12
942 char jobid
[LPROS2_IDSIZ
];
944 char jobname
[LPROS2_JOBSIZ
];
946 char size
[LPROS2_SIZSIZ
];
948 char status
[LPROS2_STATSIZ
];
950 char owner
[LPROS2_OWNSIZ
];
954 char parse_line_char
[sizeof(os2_lpq_line
)];
955 os2_lpq_line
*parse_line
= (os2_lpq_line
*)parse_line_char
;
956 #define LPROS2_PRINTING "Printing"
957 #define LPROS2_WAITING "Queued"
958 #define LPROS2_PAUSED "Paused"
960 memset(parse_line_char
, '\0', sizeof(parse_line_char
));
961 strncpy(parse_line_char
, line
, sizeof(parse_line_char
) -1);
963 if (strlen(parse_line_char
) != sizeof(parse_line_char
) - 1) {
968 buf
->sysjob
= atoi(parse_line
->jobid
);
970 /* Get the job name */
971 parse_line
->space2
[0] = '\0';
972 trim_char(parse_line
->jobname
, '\0', ' ');
973 fstrcpy(buf
->fs_file
, parse_line
->jobname
);
976 buf
->size
= atoi(parse_line
->size
);
977 buf
->time
= time(NULL
);
979 /* Make sure we have an owner */
980 if (!strlen(parse_line
->owner
)) {
984 /* Make sure we have a valid status */
985 parse_line
->space4
[0] = '\0';
986 trim_char(parse_line
->status
, '\0', ' ');
987 if (!strequal(parse_line
->status
, LPROS2_PRINTING
) &&
988 !strequal(parse_line
->status
, LPROS2_PAUSED
) &&
989 !strequal(parse_line
->status
, LPROS2_WAITING
)) {
993 fstrcpy(buf
->fs_user
, parse_line
->owner
);
994 if (strequal(parse_line
->status
, LPROS2_PRINTING
)) {
995 buf
->status
= LPQ_PRINTING
;
996 } else if (strequal(parse_line
->status
, LPROS2_PAUSED
)) {
997 buf
->status
= LPQ_PAUSED
;
999 buf
->status
= LPQ_QUEUED
;
1005 static const char *stat0_strings
[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL
};
1006 static const char *stat1_strings
[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL
};
1007 static const char *stat2_strings
[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL
};
1011 /****************************************************************************
1013 ****************************************************************************/
1015 static bool parse_lpq_vlp(char *line
,print_queue_struct
*buf
,bool first
)
1019 TALLOC_CTX
*frame
= talloc_stackframe();
1020 const char *cline
= line
;
1022 /* First line is printer status */
1024 if (!isdigit(line
[0])) {
1029 /* Parse a print job entry */
1031 while(next_token_talloc(frame
, &cline
, &tok
, NULL
)) {
1034 buf
->sysjob
= atoi(tok
);
1037 buf
->size
= atoi(tok
);
1040 buf
->status
= atoi(tok
);
1043 buf
->time
= atoi(tok
);
1046 fstrcpy(buf
->fs_user
, tok
);
1049 fstrcpy(buf
->fs_file
, tok
);
1059 #endif /* DEVELOPER */
1061 /****************************************************************************
1062 parse a lpq line. Choose printing style
1063 ****************************************************************************/
1065 bool parse_lpq_entry(enum printing_types printing_type
,char *line
,
1066 print_queue_struct
*buf
,
1067 print_status_struct
*status
,bool first
)
1071 switch (printing_type
) {
1073 ret
= parse_lpq_sysv(line
,buf
,first
);
1076 ret
= parse_lpq_aix(line
,buf
,first
);
1079 ret
= parse_lpq_hpux(line
,buf
,first
);
1082 ret
= parse_lpq_qnx(line
,buf
,first
);
1085 ret
= parse_lpq_lprng(line
,buf
,first
);
1088 ret
= parse_lpq_plp(line
,buf
,first
);
1091 ret
= parse_lpq_nt(line
,buf
,first
);
1094 ret
= parse_lpq_os2(line
,buf
,first
);
1099 ret
= parse_lpq_vlp(line
,buf
,first
);
1101 #endif /* DEVELOPER */
1103 ret
= parse_lpq_bsd(line
,buf
,first
);
1107 /* We don't want the newline in the status message. */
1109 char *p
= strchr_m(line
,'\n');
1115 /* in the LPRNG case, we skip lines starting by a space.*/
1116 if (!ret
&& (printing_type
==PRINT_LPRNG
) ) {
1122 if (status
&& !ret
) {
1123 /* a few simple checks to see if the line might be a
1124 printer status line:
1125 handle them so that most severe condition is shown */
1127 if (!strlower_m(line
)) {
1131 switch (status
->status
) {
1133 for (i
=0; stat0_strings
[i
]; i
++) {
1134 if (strstr_m(line
,stat0_strings
[i
])) {
1135 fstrcpy(status
->message
,line
);
1136 status
->status
=LPSTAT_OK
;
1141 case LPSTAT_STOPPED
:
1142 for (i
=0; stat1_strings
[i
]; i
++) {
1143 if (strstr_m(line
,stat1_strings
[i
])) {
1144 fstrcpy(status
->message
,line
);
1145 status
->status
=LPSTAT_STOPPED
;
1151 for (i
=0; stat2_strings
[i
]; i
++) {
1152 if (strstr_m(line
,stat2_strings
[i
])) {
1153 fstrcpy(status
->message
,line
);
1154 status
->status
=LPSTAT_ERROR
;