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();
131 line2 = talloc_strdup(ctx, line);
139 length = strlen(line2);
140 if (line2[length-3] == ':') {
146 /* FIXME: Use next_token_talloc rather than strtok! */
147 tok[0] = strtok(line2," \t");
150 while ((count < MAXTOK) && ((tok[count] = strtok(NULL," \t")) != NULL)) {
154 /* we must get at least NTOK tokens */
159 /* the Job and Total columns must be integer */
160 if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) {
164 buf->job = atoi(tok[JOBTOK]);
165 buf->size = atoi(tok[TOTALTOK]);
166 buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED;
167 buf->time = time(NULL);
168 fstrcpy(buf->fs_user,tok[USERTOK]);
169 fstrcpy(buf->fs_file,tok[FILETOK]);
171 if ((FILETOK + 1) != TOTALTOK) {
174 for (i = (FILETOK + 1); i < TOTALTOK; i++) {
175 /* FIXME: Using fstrcat rather than other means is a bit
176 * inefficient; this might be a problem for enormous queues with
178 fstrcat(buf->fs_file, " ");
179 fstrcat(buf->fs_file, tok[i]);
181 /* Ensure null termination. */
182 buf->fs_file[sizeof(buf->fs_file)-1] = '\0';
186 buf->priority = atoi(tok[PRIOTOK]);
195 LPRng_time modifies the current date by inserting the hour and minute from
196 the lpq output. The lpq time looks like "23:15:07"
198 <allan@umich.edu> June 30, 1998.
199 Modified to work with the re-written parse_lpq_lprng routine.
201 <J.P.M.v.Itegem@tue.nl> Dec 17,1999
202 Modified to work with lprng 3.16
203 With lprng 3.16 The lpq time looks like
206 "1999-12-16-23:15:07"
207 "1999-12-16-23:15:07.100"
210 static time_t LPRng_time(char *time_string)
215 jobtime = time(NULL); /* default case: take current time */
216 t = localtime(&jobtime);
221 if ( atoi(time_string) < 24 ){
222 t->tm_hour = atoi(time_string);
223 t->tm_min = atoi(time_string+3);
224 t->tm_sec = atoi(time_string+6);
226 t->tm_year = atoi(time_string)-1900;
227 t->tm_mon = atoi(time_string+5)-1;
228 t->tm_mday = atoi(time_string+8);
229 t->tm_hour = atoi(time_string+11);
230 t->tm_min = atoi(time_string+14);
231 t->tm_sec = atoi(time_string+17);
238 /****************************************************************************
239 parse a lprng lpq line
240 <allan@umich.edu> June 30, 1998.
241 Re-wrote this to handle file names with spaces, multiple file names on one
244 ****************************************************************************/
246 static bool parse_lpq_lprng(char *line,print_queue_struct *buf,bool first)
248 #define LPRNG_RANKTOK 0
249 #define LPRNG_USERTOK 1
250 #define LPRNG_PRIOTOK 2
251 #define LPRNG_JOBTOK 3
252 #define LPRNG_FILETOK 4
253 #define LPRNG_TOTALTOK (num_tok - 2)
254 #define LPRNG_TIMETOK (num_tok - 1)
256 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */
258 char *tokarr[LPRNG_MAXTOK];
262 TALLOC_CTX *frame = talloc_stackframe();
265 while((num_tok < LPRNG_MAXTOK) && next_token_talloc(frame, &cptr,
266 &tokarr[num_tok], " \t")) {
270 /* We must get at least LPRNG_NTOK tokens. */
271 if (num_tok < LPRNG_NTOK) {
276 if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
281 buf->job = atoi(tokarr[LPRNG_JOBTOK]);
282 buf->size = atoi(tokarr[LPRNG_TOTALTOK]);
284 if (strequal(tokarr[LPRNG_RANKTOK],"active")) {
285 buf->status = LPQ_PRINTING;
286 } else if (strequal(tokarr[LPRNG_RANKTOK],"done")) {
287 buf->status = LPQ_PRINTED;
288 } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) {
289 buf->status = LPQ_QUEUED;
291 buf->status = LPQ_PAUSED;
294 buf->priority = *tokarr[LPRNG_PRIOTOK] -'A';
296 buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]);
298 fstrcpy(buf->fs_user,tokarr[LPRNG_USERTOK]);
300 /* The '@hostname' prevents windows from displaying the printing icon
301 * for the current user on the taskbar. Plop in a null.
304 if ((ptr = strchr_m(buf->fs_user,'@')) != NULL) {
308 fstrcpy(buf->fs_file,tokarr[LPRNG_FILETOK]);
310 if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) {
313 for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) {
314 /* FIXME: Using fstrcat rather than other means is a bit
315 * inefficient; this might be a problem for enormous queues with
317 fstrcat(buf->fs_file, " ");
318 fstrcat(buf->fs_file, tokarr[i]);
320 /* Ensure null termination. */
321 buf->fs_file[sizeof(buf->fs_file)-1] = '\0';
328 /*******************************************************************
329 parse lpq on an aix system
331 Queue Dev Status Job Files User PP % Blks Cp Rnk
332 ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
334 lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1
335 QUEUED 538 C.ps root@IEDVB 124 1 2
336 QUEUED 539 E.ps root@IEDVB 28 1 3
337 QUEUED 540 L.ps root@IEDVB 172 1 4
338 QUEUED 541 P.ps root@IEDVB 22 1 5
339 ********************************************************************/
341 static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first)
345 const char *cline = line;
346 TALLOC_CTX *frame = talloc_stackframe();
348 /* handle the case of "(standard input)" as a filename */
349 string_sub(line,"standard input","STDIN",0);
350 all_string_sub(line,"(","\"",0);
351 all_string_sub(line,")","\"",0);
353 for (count=0; count<10 &&
354 next_token_talloc(frame,&cline,&tok[count],NULL); count++) {
358 /* we must get 6 tokens */
360 if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) {
361 /* the 2nd and 5th columns must be integer */
362 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) {
366 buf->size = atoi(tok[4]) * 1024;
367 /* if the fname contains a space then use STDIN */
368 if (strchr_m(tok[2],' ')) {
369 tok[2] = talloc_strdup(frame,"STDIN");
376 /* only take the last part of the filename */
378 char *p = strrchr_m(tok[2],'/');
384 buf->job = atoi(tok[1]);
385 buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED;
387 buf->time = time(NULL);
388 fstrcpy(buf->fs_user,tok[3]);
389 fstrcpy(buf->fs_file,tok[2]);
391 DEBUG(6,("parse_lpq_aix count=%d\n", count));
396 /* the 4th and 9th columns must be integer */
397 if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) {
402 buf->size = atoi(tok[8]) * 1024;
403 /* if the fname contains a space then use STDIN */
404 if (strchr_m(tok[4],' ')) {
405 tok[4] = talloc_strdup(frame,"STDIN");
412 /* only take the last part of the filename */
414 char *p = strrchr_m(tok[4],'/');
420 buf->job = atoi(tok[3]);
421 buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED;
423 buf->time = time(NULL);
424 fstrcpy(buf->fs_user,tok[5]);
425 fstrcpy(buf->fs_file,tok[4]);
432 /****************************************************************************
434 here is an example of lpq output under hpux; note there's no space after -o !
436 ljplus-2153 user priority 0 Jan 19 08:14 on ljplus
438 server.c 110712 bytes
439 ljplus-2154 user priority 0 Jan 19 08:14 from client
440 (standard input) 7551 bytes
441 ****************************************************************************/
443 static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first)
445 /* must read two lines to process, therefore keep some values static */
446 static bool header_line_ok=False, base_prio_reset=False;
447 static char *jobuser;
450 static time_t jobtime;
451 static int jobstat=LPQ_QUEUED;
452 /* to store minimum priority to print, lpstat command should be invoked
453 with -p option first, to work */
454 static int base_prio;
457 const char *cline = line;
459 TALLOC_CTX *frame = talloc_stackframe();
461 /* If a line begins with a horizontal TAB, it is a subline type */
463 if (line[0] == htab) { /* subline */
464 /* check if it contains the base priority */
465 if (!strncmp(line,"\tfence priority : ",18)) {
466 base_prio=atoi(&line[18]);
467 DEBUG(4, ("fence priority set at %d\n", base_prio));
470 if (!header_line_ok) {
472 return False; /* incorrect header line */
475 /* handle the case of "(standard input)" as a filename */
476 string_sub(line,"standard input","STDIN",0);
477 all_string_sub(line,"(","\"",0);
478 all_string_sub(line,")","\"",0);
480 for (count=0; count<2 &&
481 next_token_talloc(frame, &cline, &tok[count],NULL);
485 /* we must get 2 tokens */
491 /* the 2nd column must be integer */
492 if (!isdigit((int)*tok[1])) {
497 /* if the fname contains a space then use STDIN */
498 if (strchr_m(tok[0],' ')) {
499 tok[0] = talloc_strdup(frame, "STDIN");
506 buf->size = atoi(tok[1]);
507 fstrcpy(buf->fs_file,tok[0]);
509 /* fill things from header line */
512 buf->status = jobstat;
513 buf->priority = jobprio;
515 fstrcpy(buf->fs_user,jobuser);
517 buf->fs_user[0] = '\0';
522 } else { /* header line */
523 header_line_ok=False; /* reset it */
525 if (!base_prio_reset) {
526 base_prio=0; /* reset it */
527 base_prio_reset=True;
529 } else if (base_prio) {
530 base_prio_reset=False;
533 /* handle the dash in the job id */
534 string_sub(line,"-"," ",0);
536 for (count=0; count<12 &&
537 next_token_talloc(frame, &cline, &tok[count],NULL);
542 /* we must get 8 tokens */
548 /* first token must be printer name (cannot check ?) */
549 /* the 2nd, 5th & 7th column must be integer */
550 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) {
554 jobid = atoi(tok[1]);
556 jobuser = SMB_STRDUP(tok[2]);
557 jobprio = atoi(tok[4]);
560 jobtime=EntryTime(tok, 5, count, 8);
561 if (jobprio < base_prio) {
562 jobstat = LPQ_PAUSED;
563 DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n",
564 jobid, jobprio, base_prio, jobstat));
566 jobstat = LPQ_QUEUED;
567 if ((count >8) && (((strequal(tok[8],"on")) ||
568 ((strequal(tok[8],"from")) &&
569 ((count > 10)&&(strequal(tok[10],"on"))))))) {
570 jobstat = LPQ_PRINTING;
574 header_line_ok=True; /* information is correct */
576 return False; /* need subline info to include into queuelist */
580 /****************************************************************************
583 here is an example of "lpstat -o dcslw" output under sysv
585 dcslw-896 tridge 4712 Dec 20 10:30:30 on dcslw
586 dcslw-897 tridge 4712 Dec 20 10:30:30 being held
588 ****************************************************************************/
590 static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first)
595 const char *cline = line;
596 TALLOC_CTX *frame = NULL;
599 * Handle the dash in the job id, but make sure that we skip over
600 * the printer name in case we have a dash in that.
601 * Patch from Dom.Mitchell@palmerharvey.co.uk.
605 * Move to the first space.
607 for (p = line ; !isspace(*p) && *p; p++) {
612 * Back up until the last '-' character or
615 for (; (p >= line) && (*p != '-'); p--) {
619 if((p >= line) && (*p == '-')) {
623 frame = talloc_stackframe();
624 for (count=0; count<9 &&
625 next_token_talloc(frame, &cline, &tok[count],NULL);
630 /* we must get 7 tokens */
636 /* the 2nd and 4th, 6th columns must be integer */
637 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) {
641 if (!isdigit((int)*tok[5])) {
646 /* if the user contains a ! then trim the first part of it */
647 if ((p=strchr_m(tok[2],'!'))) {
651 buf->job = atoi(tok[1]);
652 buf->size = atoi(tok[3]);
653 if (count > 7 && strequal(tok[7],"on")) {
654 buf->status = LPQ_PRINTING;
655 } else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held")) {
656 buf->status = LPQ_PAUSED;
658 buf->status = LPQ_QUEUED;
661 buf->time = EntryTime(tok, 4, count, 7);
662 fstrcpy(buf->fs_user,tok[2]);
663 fstrcpy(buf->fs_file,tok[2]);
668 /****************************************************************************
671 here is an example of lpq output under qnx
672 Spooler: /qnx/spooler, on node 1
674 0000: root [job #1 ] active 1146 bytes /etc/profile
675 0001: root [job #2 ] ready 2378 bytes /etc/install
676 0002: root [job #3 ] ready 1146 bytes -- standard input --
677 ****************************************************************************/
679 static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first)
683 const char *cline = line;
684 TALLOC_CTX *frame = NULL;
686 DEBUG(4,("antes [%s]\n", line));
688 /* handle the case of "-- standard input --" as a filename */
689 string_sub(line,"standard input","STDIN",0);
690 DEBUG(4,("despues [%s]\n", line));
691 all_string_sub(line,"-- ","\"",0);
692 all_string_sub(line," --","\"",0);
693 DEBUG(4,("despues 1 [%s]\n", line));
695 string_sub(line,"[job #","",0);
696 string_sub(line,"]","",0);
697 DEBUG(4,("despues 2 [%s]\n", line));
699 frame = talloc_stackframe();
700 for (count=0; count<7 &&
701 next_token_talloc(frame,&cline,&tok[count],NULL);
706 /* we must get 7 tokens */
712 /* the 3rd and 5th columns must be integer */
713 if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) {
718 /* only take the last part of the filename */
720 char *p = strrchr_m(tok[6],'/');
726 buf->job = atoi(tok[2]);
727 buf->size = atoi(tok[4]);
728 buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
730 buf->time = time(NULL);
731 fstrcpy(buf->fs_user,tok[1]);
732 fstrcpy(buf->fs_file,tok[6]);
737 /****************************************************************************
738 parse a lpq line for the plp printing system
739 Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
741 redone by tridge. Here is a sample queue:
743 Local Printer 'lp2' (fjall):
744 Printing (started at Jun 15 13:33:58, attempt 1).
745 Rank Owner Pr Opt Job Host Files Size Date
746 active tridge X - 6 fjall /etc/hosts 739 Jun 15 13:33
747 3rd tridge X - 7 fjall /etc/hosts 739 Jun 15 13:33
749 ****************************************************************************/
751 static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first)
755 const char *cline = line;
756 TALLOC_CTX *frame = talloc_stackframe();
758 /* handle the case of "(standard input)" as a filename */
759 string_sub(line,"stdin","STDIN",0);
760 all_string_sub(line,"(","\"",0);
761 all_string_sub(line,")","\"",0);
763 for (count=0; count<11 &&
764 next_token_talloc(frame,&cline,&tok[count],NULL);
769 /* we must get 11 tokens */
775 /* the first must be "active" or begin with an integer */
776 if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) {
781 /* the 5th and 8th must be integer */
782 if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) {
787 /* if the fname contains a space then use STDIN */
788 if (strchr_m(tok[6],' ')) {
789 tok[6] = talloc_strdup(frame, "STDIN");
796 /* only take the last part of the filename */
799 char *p = strrchr_m(tok[6],'/');
806 buf->job = atoi(tok[4]);
808 buf->size = atoi(tok[7]);
809 if (strchr_m(tok[7],'K')) {
812 if (strchr_m(tok[7],'M')) {
813 buf->size *= 1024*1024;
816 buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;
818 buf->time = time(NULL);
819 fstrcpy(buf->fs_user,tok[1]);
820 fstrcpy(buf->fs_file,tok[6]);
825 /*******************************************************************
826 parse lpq on an NT system
828 Windows 2000 LPD Server
829 Printer \\10.0.0.2\NP17PCL (Paused)
831 Owner Status Jobname Job-Id Size Pages Priority
832 ----------------------------------------------------------------------------
833 root (9.99. Printing /usr/lib/rhs/rhs-pr 3 625 0 1
834 root (9.99. Paused /usr/lib/rhs/rhs-pr 4 625 0 1
835 jmcd Waiting Re: Samba Open Sour 26 32476 1 1
837 ********************************************************************/
839 static bool parse_lpq_nt(char *line,print_queue_struct *buf,bool first)
841 #define LPRNT_OWNSIZ 11
842 #define LPRNT_STATSIZ 9
843 #define LPRNT_JOBSIZ 19
844 #define LPRNT_IDSIZ 6
845 #define LPRNT_SIZSIZ 9
847 char owner[LPRNT_OWNSIZ];
849 char status[LPRNT_STATSIZ];
851 char jobname[LPRNT_JOBSIZ];
853 char jobid[LPRNT_IDSIZ];
855 char size[LPRNT_SIZSIZ];
859 nt_lpq_line parse_line;
860 #define LPRNT_PRINTING "Printing"
861 #define LPRNT_WAITING "Waiting"
862 #define LPRNT_PAUSED "Paused"
864 memset(&parse_line, '\0', sizeof(parse_line));
865 strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
867 if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) {
871 /* Just want the first word in the owner field - the username */
872 if (strchr_m(parse_line.owner, ' ')) {
873 *(strchr_m(parse_line.owner, ' ')) = '\0';
875 parse_line.space1 = '\0';
878 /* Make sure we have an owner */
879 if (!strlen(parse_line.owner)) {
883 /* Make sure the status is valid */
884 parse_line.space2 = '\0';
885 trim_char(parse_line.status, '\0', ' ');
886 if (!strequal(parse_line.status, LPRNT_PRINTING) &&
887 !strequal(parse_line.status, LPRNT_PAUSED) &&
888 !strequal(parse_line.status, LPRNT_WAITING)) {
892 parse_line.space3 = '\0';
893 trim_char(parse_line.jobname, '\0', ' ');
895 buf->job = atoi(parse_line.jobid);
897 buf->size = atoi(parse_line.size);
898 buf->time = time(NULL);
899 fstrcpy(buf->fs_user, parse_line.owner);
900 fstrcpy(buf->fs_file, parse_line.jobname);
901 if (strequal(parse_line.status, LPRNT_PRINTING)) {
902 buf->status = LPQ_PRINTING;
903 } else if (strequal(parse_line.status, LPRNT_PAUSED)) {
904 buf->status = LPQ_PAUSED;
906 buf->status = LPQ_QUEUED;
912 /*******************************************************************
913 parse lpq on an OS2 system
915 JobID File Name Rank Size Status Comment
916 ----- --------------- ------ -------- ------------ ------------
917 3 Control 1 68 Queued root@psflinu
918 4 /etc/motd 2 11666 Queued root@psflinu
920 ********************************************************************/
922 static bool parse_lpq_os2(char *line,print_queue_struct *buf,bool first)
924 #define LPROS2_IDSIZ 5
925 #define LPROS2_JOBSIZ 15
926 #define LPROS2_SIZSIZ 8
927 #define LPROS2_STATSIZ 12
928 #define LPROS2_OWNSIZ 12
930 char jobid[LPROS2_IDSIZ];
932 char jobname[LPROS2_JOBSIZ];
934 char size[LPROS2_SIZSIZ];
936 char status[LPROS2_STATSIZ];
938 char owner[LPROS2_OWNSIZ];
942 os2_lpq_line parse_line;
943 #define LPROS2_PRINTING "Printing"
944 #define LPROS2_WAITING "Queued"
945 #define LPROS2_PAUSED "Paused"
947 memset(&parse_line, '\0', sizeof(parse_line));
948 strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
950 if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) {
955 buf->job = atoi(parse_line.jobid);
957 /* Get the job name */
958 parse_line.space2[0] = '\0';
959 trim_char(parse_line.jobname, '\0', ' ');
960 fstrcpy(buf->fs_file, parse_line.jobname);
963 buf->size = atoi(parse_line.size);
964 buf->time = time(NULL);
966 /* Make sure we have an owner */
967 if (!strlen(parse_line.owner)) {
971 /* Make sure we have a valid status */
972 parse_line.space4[0] = '\0';
973 trim_char(parse_line.status, '\0', ' ');
974 if (!strequal(parse_line.status, LPROS2_PRINTING) &&
975 !strequal(parse_line.status, LPROS2_PAUSED) &&
976 !strequal(parse_line.status, LPROS2_WAITING)) {
980 fstrcpy(buf->fs_user, parse_line.owner);
981 if (strequal(parse_line.status, LPROS2_PRINTING)) {
982 buf->status = LPQ_PRINTING;
983 } else if (strequal(parse_line.status, LPROS2_PAUSED)) {
984 buf->status = LPQ_PAUSED;
986 buf->status = LPQ_QUEUED;
992 static const char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL };
993 static const char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };
994 static const char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL };
998 /****************************************************************************
1000 ****************************************************************************/
1002 static bool parse_lpq_vlp(char *line,print_queue_struct *buf,bool first)
1006 TALLOC_CTX *frame = talloc_stackframe();
1007 const char *cline = line;
1009 /* First line is printer status */
1011 if (!isdigit(line[0])) {
1016 /* Parse a print job entry */
1018 while(next_token_talloc(frame, &cline, &tok, NULL)) {
1021 buf->job = atoi(tok);
1024 buf->size = atoi(tok);
1027 buf->status = atoi(tok);
1030 buf->time = atoi(tok);
1033 fstrcpy(buf->fs_user, tok);
1036 fstrcpy(buf->fs_file, tok);
1046 #endif /* DEVELOPER */
1048 /****************************************************************************
1049 parse a lpq line. Choose printing style
1050 ****************************************************************************/
1052 bool parse_lpq_entry(enum printing_types printing_type,char *line,
1053 print_queue_struct *buf,
1054 print_status_struct *status,bool first)
1058 switch (printing_type) {
1060 ret = parse_lpq_sysv(line,buf,first);
1063 ret = parse_lpq_aix(line,buf,first);
1066 ret = parse_lpq_hpux(line,buf,first);
1069 ret = parse_lpq_qnx(line,buf,first);
1072 ret = parse_lpq_lprng(line,buf,first);
1075 ret = parse_lpq_plp(line,buf,first);
1078 ret = parse_lpq_nt(line,buf,first);
1081 ret = parse_lpq_os2(line,buf,first);
1086 ret = parse_lpq_vlp(line,buf,first);
1088 #endif /* DEVELOPER */
1090 ret = parse_lpq_bsd(line,buf,first);
1094 /* We don't want the newline in the status message. */
1096 char *p = strchr_m(line,'\n');
1102 /* in the LPRNG case, we skip lines starting by a space.*/
1103 if (!ret && (printing_type==PRINT_LPRNG) ) {
1109 if (status && !ret) {
1110 /* a few simple checks to see if the line might be a
1111 printer status line:
1112 handle them so that most severe condition is shown */
1116 switch (status->status) {
1118 for (i=0; stat0_strings[i]; i++) {
1119 if (strstr_m(line,stat0_strings[i])) {
1120 fstrcpy(status->message,line);
1121 status->status=LPSTAT_OK;
1126 case LPSTAT_STOPPED:
1127 for (i=0; stat1_strings[i]; i++) {
1128 if (strstr_m(line,stat1_strings[i])) {
1129 fstrcpy(status->message,line);
1130 status->status=LPSTAT_STOPPED;
1136 for (i=0; stat2_strings[i]; i++) {
1137 if (strstr_m(line,stat2_strings[i])) {
1138 fstrcpy(status->message,line);
1139 status->status=LPSTAT_ERROR;