LCOV - code coverage report
Current view: top level - source3/printing - lpq_parse.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 53 542 9.8 %
Date: 2024-04-21 15:09:00 Functions: 2 13 15.4 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    lpq parsing routines
       4             :    Copyright (C) Andrew Tridgell 2000
       5             :    
       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.
      10             :    
      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.
      15             :    
      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/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "printing.h"
      22             : #include "lib/util/string_wrappers.h"
      23             : 
      24             : static const char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
      25             :                               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
      26             : 
      27             : 
      28             : /*******************************************************************
      29             :  Process time fields
      30             : ********************************************************************/
      31             : 
      32           0 : static time_t EntryTime(char *tok[], int ptr, int count, int minimum)
      33             : {
      34           0 :         time_t jobtime,jobtime1;
      35             : 
      36           0 :         jobtime = time(NULL);           /* default case: take current time */
      37           0 :         if (count >= minimum) {
      38             :                 struct tm *t;
      39             :                 int i, day, hour, min, sec;
      40             : 
      41           0 :                 for (i=0; i<13; i++) {
      42           0 :                         if (!strncmp(tok[ptr], Months[i],3)) {
      43           0 :                                 break; /* Find month */
      44             :                         }
      45             :                 }
      46             : 
      47           0 :                 if (i<12) {
      48           0 :                         fstring c;
      49           0 :                         t = localtime(&jobtime);
      50           0 :                         if (!t) {
      51           0 :                                 return (time_t)-1;
      52             :                         }
      53           0 :                         day = atoi(tok[ptr+1]);
      54           0 :                         fstrcpy(c,tok[ptr+2]);
      55           0 :                         *(c+2)=0;
      56           0 :                         hour = atoi(c);
      57           0 :                         *(c+5)=0;
      58           0 :                         min = atoi(c+3);
      59           0 :                         if(*(c+6) != 0) {
      60           0 :                                 sec = atoi(c+6);
      61             :                         } else {
      62           0 :                                 sec=0;
      63             :                         }
      64             : 
      65           0 :                         if ((t->tm_mon < i)|| ((t->tm_mon == i)&&
      66           0 :                                         ((t->tm_mday < day)||
      67           0 :                                         ((t->tm_mday == day)&&
      68           0 :                                         (t->tm_hour*60+t->tm_min < hour*60+min))))) {
      69           0 :                                 t->tm_year--;                /* last year's print job */
      70             :                         }
      71             : 
      72           0 :                         t->tm_mon = i;
      73           0 :                         t->tm_mday = day;
      74           0 :                         t->tm_hour = hour;
      75           0 :                         t->tm_min = min;
      76           0 :                         t->tm_sec = sec;
      77           0 :                         jobtime1 = mktime(t);
      78           0 :                         if (jobtime1 != (time_t)-1) {
      79           0 :                                 jobtime = jobtime1;
      80             :                         }
      81             :                 }
      82             :         }
      83           0 :         return jobtime;
      84             : }
      85             : 
      86             : /****************************************************************************
      87             : parse a lpq line
      88             : 
      89             : here is an example of lpq output under bsd
      90             : 
      91             : Warning: no daemon present
      92             : Rank   Owner      Job  Files                                 Total Size
      93             : 1st    tridge     148  README                                8096 bytes
      94             : 
      95             : here is an example of lpq output under osf/1
      96             : 
      97             : Warning: no daemon present
      98             : Rank   Pri Owner      Job  Files                             Total Size
      99             : 1st    0   tridge     148  README                            8096 bytes
     100             : 
     101             : 
     102             : <allan@umich.edu> June 30, 1998.
     103             : Modified to handle file names with spaces, like the parse_lpq_lprng code
     104             : further below.
     105             : ****************************************************************************/
     106             : 
     107           0 : static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first)
     108             : {
     109             : #ifdef  OSF1
     110             : #define RANKTOK 0
     111             : #define PRIOTOK 1
     112             : #define USERTOK 2
     113             : #define JOBTOK  3
     114             : #define FILETOK 4
     115             : #define TOTALTOK (count - 2)
     116             : #define NTOK    6
     117             : #define MAXTOK  128
     118             : #else   /* OSF1 */
     119             : #define RANKTOK 0
     120             : #define USERTOK 1
     121             : #define JOBTOK  2
     122             : #define FILETOK 3
     123             : #define TOTALTOK (count - 2)
     124             : #define NTOK    5
     125             : #define MAXTOK  128
     126             : #endif  /* OSF1 */
     127             : 
     128           0 :         char *tok[MAXTOK];
     129           0 :         int  count = 0;
     130           0 :         TALLOC_CTX *ctx = talloc_tos();
     131           0 :         char *line2 = NULL;
     132           0 :         char *saveptr;
     133             : 
     134           0 :         line2 = talloc_strdup(ctx, line);
     135           0 :         if (!line2) {
     136           0 :                 return false;
     137             :         }
     138             : 
     139             : #ifdef  OSF1
     140             :         {
     141             :                 size_t length;
     142             :                 length = strlen(line2);
     143             :                 if (line2[length-3] == ':') {
     144             :                         return False;
     145             :                 }
     146             :         }
     147             : #endif  /* OSF1 */
     148             : 
     149             :         /* FIXME: Use next_token_talloc rather than strtok! */
     150           0 :         tok[0] = strtok_r(line2," \t", &saveptr);
     151           0 :         count++;
     152             : 
     153           0 :         while ((count < MAXTOK)
     154           0 :                && ((tok[count] = strtok_r(NULL, " \t", &saveptr)) != NULL)) {
     155           0 :                 count++;
     156             :         }
     157             : 
     158             :         /* we must get at least NTOK tokens */
     159           0 :         if (count < NTOK) {
     160           0 :                 return False;
     161             :         }
     162             : 
     163             :         /* the Job and Total columns must be integer */
     164           0 :         if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) {
     165           0 :                 return False;
     166             :         }
     167             : 
     168           0 :         buf->sysjob = atoi(tok[JOBTOK]);
     169           0 :         buf->size = atoi(tok[TOTALTOK]);
     170           0 :         buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED;
     171           0 :         buf->time = time(NULL);
     172           0 :         fstrcpy(buf->fs_user,tok[USERTOK]);
     173           0 :         fstrcpy(buf->fs_file,tok[FILETOK]);
     174             : 
     175           0 :         if ((FILETOK + 1) != TOTALTOK) {
     176             :                 int i;
     177             : 
     178           0 :                 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
     181             :                          * many fields. */
     182           0 :                         fstrcat(buf->fs_file, " ");
     183           0 :                         fstrcat(buf->fs_file, tok[i]);
     184             :                 }
     185             :                 /* Ensure null termination. */
     186           0 :                 buf->fs_file[sizeof(buf->fs_file)-1] = '\0';
     187             :         }
     188             : 
     189             : #ifdef PRIOTOK
     190             :         buf->priority = atoi(tok[PRIOTOK]);
     191             : #else
     192           0 :         buf->priority = 1;
     193             : #endif
     194           0 :         return True;
     195             : }
     196             : 
     197             : /*
     198             : <magnus@hum.auc.dk>
     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"
     201             : 
     202             : <allan@umich.edu> June 30, 1998.
     203             : Modified to work with the re-written parse_lpq_lprng routine.
     204             : 
     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
     208             :                        "23:15:07"
     209             :                        "23:15:07.100"
     210             :                        "1999-12-16-23:15:07"
     211             :                        "1999-12-16-23:15:07.100"
     212             : 
     213             : */
     214           0 : static time_t LPRng_time(char *time_string)
     215             : {
     216           0 :         time_t jobtime;
     217           0 :         struct tm *t;
     218             : 
     219           0 :         jobtime = time(NULL);         /* default case: take current time */
     220           0 :         t = localtime(&jobtime);
     221           0 :         if (!t) {
     222           0 :                 return (time_t)-1;
     223             :         }
     224             : 
     225           0 :         if ( atoi(time_string) < 24 ){
     226           0 :                 if (strlen(time_string) < 7) {
     227           0 :                         return (time_t)-1;
     228             :                 }
     229           0 :                 t->tm_hour = atoi(time_string);
     230           0 :                 t->tm_min = atoi(time_string+3);
     231           0 :                 t->tm_sec = atoi(time_string+6);
     232             :         } else {
     233           0 :                 if (strlen(time_string) < 18) {
     234           0 :                         return (time_t)-1;
     235             :                 }
     236           0 :                 t->tm_year = atoi(time_string)-1900;
     237           0 :                 t->tm_mon = atoi(time_string+5)-1;
     238           0 :                 t->tm_mday = atoi(time_string+8);
     239           0 :                 t->tm_hour = atoi(time_string+11);
     240           0 :                 t->tm_min = atoi(time_string+14);
     241           0 :                 t->tm_sec = atoi(time_string+17);
     242             :         }    
     243           0 :         jobtime = mktime(t);
     244             : 
     245           0 :         return jobtime;
     246             : }
     247             : 
     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
     252             :   lpq line, etc;
     253             : 
     254             : ****************************************************************************/
     255             : 
     256           0 : static bool parse_lpq_lprng(char *line,print_queue_struct *buf,bool first)
     257             : {
     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)
     265             : #define LPRNG_NTOK      7
     266             : #define LPRNG_MAXTOK    128 /* PFMA just to keep us from running away. */
     267             : 
     268           0 :         char *tokarr[LPRNG_MAXTOK];
     269           0 :         const char *cptr;
     270           0 :         char *ptr;
     271           0 :         int num_tok = 0;
     272           0 :         TALLOC_CTX *frame = talloc_stackframe();
     273             : 
     274           0 :         cptr = line;
     275           0 :         while((num_tok < LPRNG_MAXTOK) && next_token_talloc(frame, &cptr,
     276             :                                 &tokarr[num_tok], " \t")) {
     277           0 :                 num_tok++;
     278             :         }
     279             : 
     280             :         /* We must get at least LPRNG_NTOK tokens. */
     281           0 :         if (num_tok < LPRNG_NTOK) {
     282           0 :                 TALLOC_FREE(frame);
     283           0 :                 return False;
     284             :         }
     285             : 
     286           0 :         if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
     287           0 :                 TALLOC_FREE(frame);
     288           0 :                 return False;
     289             :         }
     290             : 
     291           0 :         buf->sysjob = atoi(tokarr[LPRNG_JOBTOK]);
     292           0 :         buf->size = atoi(tokarr[LPRNG_TOTALTOK]);
     293             : 
     294           0 :         if (strequal(tokarr[LPRNG_RANKTOK],"active")) {
     295           0 :                 buf->status = LPQ_PRINTING;
     296           0 :         } else if (strequal(tokarr[LPRNG_RANKTOK],"done")) {
     297           0 :                 buf->status = LPQ_PRINTED;
     298           0 :         } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) {
     299           0 :                 buf->status = LPQ_QUEUED;
     300             :         } else {
     301           0 :                 buf->status = LPQ_PAUSED;
     302             :         }
     303             : 
     304           0 :         buf->priority = *tokarr[LPRNG_PRIOTOK] -'A';
     305             : 
     306           0 :         buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]);
     307             : 
     308           0 :         fstrcpy(buf->fs_user,tokarr[LPRNG_USERTOK]);
     309             : 
     310             :         /* The '@hostname' prevents windows from displaying the printing icon
     311             :          * for the current user on the taskbar.  Plop in a null.
     312             :          */
     313             : 
     314           0 :         if ((ptr = strchr_m(buf->fs_user,'@')) != NULL) {
     315           0 :                 *ptr = '\0';
     316             :         }
     317             : 
     318           0 :         fstrcpy(buf->fs_file,tokarr[LPRNG_FILETOK]);
     319             : 
     320           0 :         if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) {
     321             :                 int i;
     322             : 
     323           0 :                 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
     326             :                          * many fields. */
     327           0 :                         fstrcat(buf->fs_file, " ");
     328           0 :                         fstrcat(buf->fs_file, tokarr[i]);
     329             :                 }
     330             :                 /* Ensure null termination. */
     331           0 :                 buf->fs_file[sizeof(buf->fs_file)-1] = '\0';
     332             :         }
     333             : 
     334           0 :         TALLOC_FREE(frame);
     335           0 :         return True;
     336             : }
     337             : 
     338             : /*******************************************************************
     339             : parse lpq on an aix system
     340             : 
     341             : Queue   Dev   Status    Job Files              User         PP %   Blks  Cp Rnk
     342             : ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
     343             : laser   laser READY
     344             : laser   laser 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             : ********************************************************************/
     350             : 
     351           0 : static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first)
     352             : {
     353           0 :         char *tok[11];
     354           0 :         int count=0;
     355           0 :         const char *cline = line;
     356           0 :         TALLOC_CTX *frame = talloc_stackframe();
     357             : 
     358             :         /* handle the case of "(standard input)" as a filename */
     359           0 :         string_sub(line,"standard input","STDIN",0);
     360           0 :         all_string_sub(line,"(","\"",0);
     361           0 :         all_string_sub(line,")","\"",0);
     362             : 
     363           0 :         for (count=0; count<10 &&
     364           0 :                         next_token_talloc(frame,&cline,&tok[count],NULL); count++) {
     365           0 :                 ;
     366             :         }
     367             : 
     368             :         /* we must get 6 tokens */
     369           0 :         if (count < 10) {
     370           0 :                 if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) {
     371             :                         /* the 2nd and 5th columns must be integer */
     372           0 :                         if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) {
     373           0 :                                 TALLOC_FREE(frame);
     374           0 :                                 return False;
     375             :                         }
     376           0 :                         buf->size = atoi(tok[4]) * 1024;
     377             :                         /* if the fname contains a space then use STDIN */
     378           0 :                         if (strchr_m(tok[2],' ')) {
     379           0 :                                 tok[2] = talloc_strdup(frame,"STDIN");
     380           0 :                                 if (!tok[2]) {
     381           0 :                                         TALLOC_FREE(frame);
     382           0 :                                         return false;
     383             :                                 }
     384             :                         }
     385             : 
     386             :                         /* only take the last part of the filename */
     387             :                         {
     388           0 :                                 char *p = strrchr_m(tok[2],'/');
     389           0 :                                 if (p) {
     390           0 :                                         tok[2] = p+1;
     391             :                                 }
     392             :                         }
     393             : 
     394           0 :                         buf->sysjob = atoi(tok[1]);
     395           0 :                         buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED;
     396           0 :                         buf->priority = 0;
     397           0 :                         buf->time = time(NULL);
     398           0 :                         fstrcpy(buf->fs_user,tok[3]);
     399           0 :                         fstrcpy(buf->fs_file,tok[2]);
     400             :                 } else {
     401           0 :                         DEBUG(6,("parse_lpq_aix count=%d\n", count));
     402           0 :                         TALLOC_FREE(frame);
     403           0 :                         return False;
     404             :                 }
     405             :         } else {
     406             :                 /* the 4th and 9th columns must be integer */
     407           0 :                 if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) {
     408           0 :                         TALLOC_FREE(frame);
     409           0 :                         return False;
     410             :                 }
     411             : 
     412           0 :                 buf->size = atoi(tok[8]) * 1024;
     413             :                 /* if the fname contains a space then use STDIN */
     414           0 :                 if (strchr_m(tok[4],' ')) {
     415           0 :                         tok[4] = talloc_strdup(frame,"STDIN");
     416           0 :                         if (!tok[4]) {
     417           0 :                                 TALLOC_FREE(frame);
     418           0 :                                 return false;
     419             :                         }
     420             :                 }
     421             : 
     422             :                 /* only take the last part of the filename */
     423             :                 {
     424           0 :                         char *p = strrchr_m(tok[4],'/');
     425           0 :                         if (p) {
     426           0 :                                 tok[4] = p+1;
     427             :                         }
     428             :                 }
     429             : 
     430           0 :                 buf->sysjob = atoi(tok[3]);
     431           0 :                 buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED;
     432           0 :                 buf->priority = 0;
     433           0 :                 buf->time = time(NULL);
     434           0 :                 fstrcpy(buf->fs_user,tok[5]);
     435           0 :                 fstrcpy(buf->fs_file,tok[4]);
     436             :         }
     437             : 
     438           0 :         TALLOC_FREE(frame);
     439           0 :         return True;
     440             : }
     441             : 
     442             : /****************************************************************************
     443             : parse a lpq line
     444             : here is an example of lpq output under hpux; note there's no space after -o !
     445             : $> lpstat -oljplus
     446             : ljplus-2153         user           priority 0  Jan 19 08:14 on ljplus
     447             :       util.c                                  125697 bytes
     448             :       server.c                                110712 bytes
     449             : ljplus-2154         user           priority 0  Jan 19 08:14 from client
     450             :       (standard input)                          7551 bytes
     451             : ****************************************************************************/
     452             : 
     453           0 : static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first)
     454             : {
     455             :         /* must read two lines to process, therefore keep some values static */
     456           0 :         static bool header_line_ok=False, base_prio_reset=False;
     457           0 :         static char *jobuser;
     458           0 :         static int jobid;
     459           0 :         static int jobprio;
     460           0 :         static time_t jobtime;
     461           0 :         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           0 :         static int base_prio;
     465           0 :         int count;
     466           0 :         char htab = '\011';
     467           0 :         const char *cline = line;
     468           0 :         char *tok[12];
     469           0 :         TALLOC_CTX *frame = talloc_stackframe();
     470             : 
     471             :         /* If a line begins with a horizontal TAB, it is a subline type */
     472             : 
     473           0 :         if (line[0] == htab) { /* subline */
     474             :                 /* check if it contains the base priority */
     475           0 :                 if (!strncmp(line,"\tfence priority : ",18)) {
     476           0 :                         base_prio=atoi(&line[18]);
     477           0 :                         DEBUG(4, ("fence priority set at %d\n", base_prio));
     478             :                 }
     479             : 
     480           0 :                 if (!header_line_ok) {
     481           0 :                         TALLOC_FREE(frame);
     482           0 :                         return  False; /* incorrect header line */
     483             :                 }
     484             : 
     485             :                 /* handle the case of "(standard input)" as a filename */
     486           0 :                 string_sub(line,"standard input","STDIN",0);
     487           0 :                 all_string_sub(line,"(","\"",0);
     488           0 :                 all_string_sub(line,")","\"",0);
     489             : 
     490           0 :                 for (count=0; count<2 &&
     491           0 :                                 next_token_talloc(frame, &cline, &tok[count],NULL);
     492           0 :                                 count++) {
     493           0 :                         ;
     494             :                 }
     495             :                 /* we must get 2 tokens */
     496           0 :                 if (count < 2) {
     497           0 :                         TALLOC_FREE(frame);
     498           0 :                         return False;
     499             :                 }
     500             : 
     501             :                 /* the 2nd column must be integer */
     502           0 :                 if (!isdigit((int)*tok[1])) {
     503           0 :                         TALLOC_FREE(frame);
     504           0 :                         return False;
     505             :                 }
     506             : 
     507             :                 /* if the fname contains a space then use STDIN */
     508           0 :                 if (strchr_m(tok[0],' ')) {
     509           0 :                         tok[0] = talloc_strdup(frame, "STDIN");
     510           0 :                         if (!tok[0]) {
     511           0 :                                 TALLOC_FREE(frame);
     512           0 :                                 return false;
     513             :                         }
     514             :                 }
     515             : 
     516           0 :                 buf->size = atoi(tok[1]);
     517           0 :                 fstrcpy(buf->fs_file,tok[0]);
     518             : 
     519             :                 /* fill things from header line */
     520           0 :                 buf->time = jobtime;
     521           0 :                 buf->sysjob = jobid;
     522           0 :                 buf->status = jobstat;
     523           0 :                 buf->priority = jobprio;
     524           0 :                 if (jobuser) {
     525           0 :                         fstrcpy(buf->fs_user,jobuser);
     526             :                 } else {
     527           0 :                         buf->fs_user[0] = '\0';
     528             :                 }
     529             : 
     530           0 :                 TALLOC_FREE(frame);
     531           0 :                 return True;
     532             :         } else { /* header line */
     533           0 :                 header_line_ok=False; /* reset it */
     534           0 :                 if (first) {
     535           0 :                         if (!base_prio_reset) {
     536           0 :                                 base_prio=0; /* reset it */
     537           0 :                                 base_prio_reset=True;
     538             :                         }
     539           0 :                 } else if (base_prio) {
     540           0 :                         base_prio_reset=False;
     541             :                 }
     542             : 
     543             :                 /* handle the dash in the job id */
     544           0 :                 string_sub(line,"-"," ",0);
     545             : 
     546           0 :                 for (count=0; count<12 &&
     547           0 :                                 next_token_talloc(frame, &cline, &tok[count],NULL);
     548           0 :                                 count++) {
     549           0 :                         ;
     550             :                 }
     551             : 
     552             :                 /* we must get 8 tokens */
     553           0 :                 if (count < 8) {
     554           0 :                         TALLOC_FREE(frame);
     555           0 :                         return False;
     556             :                 }
     557             : 
     558             :                 /* first token must be printer name (cannot check ?) */
     559             :                 /* the 2nd, 5th & 7th column must be integer */
     560           0 :                 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) {
     561           0 :                         TALLOC_FREE(frame);
     562           0 :                         return False;
     563             :                 }
     564           0 :                 jobid = atoi(tok[1]);
     565           0 :                 SAFE_FREE(jobuser);
     566           0 :                 jobuser = SMB_STRDUP(tok[2]);
     567           0 :                 jobprio = atoi(tok[4]);
     568             : 
     569             :                 /* process time */
     570           0 :                 jobtime=EntryTime(tok, 5, count, 8);
     571           0 :                 if (jobprio < base_prio) {
     572           0 :                         jobstat = LPQ_PAUSED;
     573           0 :                         DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n",
     574             :                                 jobid, jobprio, base_prio, jobstat));
     575             :                 } else {
     576           0 :                         jobstat = LPQ_QUEUED;
     577           0 :                         if ((count >8) && (((strequal(tok[8],"on")) ||
     578           0 :                                         ((strequal(tok[8],"from")) && 
     579           0 :                                         ((count > 10)&&(strequal(tok[10],"on"))))))) {
     580           0 :                                 jobstat = LPQ_PRINTING;
     581             :                         }
     582             :                 }
     583             : 
     584           0 :                 header_line_ok=True; /* information is correct */
     585           0 :                 TALLOC_FREE(frame);
     586           0 :                 return False; /* need subline info to include into queuelist */
     587             :         }
     588             : }
     589             : 
     590             : /****************************************************************************
     591             : parse a lpstat line
     592             : 
     593             : here is an example of "lpstat -o dcslw" output under sysv
     594             : 
     595             : dcslw-896               tridge            4712   Dec 20 10:30:30 on dcslw
     596             : dcslw-897               tridge            4712   Dec 20 10:30:30 being held
     597             : 
     598             : ****************************************************************************/
     599             : 
     600           0 : static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first)
     601             : {
     602           0 :         char *tok[9];
     603           0 :         int count=0;
     604           0 :         char *p;
     605           0 :         const char *cline = line;
     606           0 :         TALLOC_CTX *frame = NULL;
     607             : 
     608             :         /*
     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.
     612             :          */
     613             : 
     614             :         /*
     615             :          * Move to the first space.
     616             :          */
     617           0 :         for (p = line ; !isspace(*p) && *p; p++) {
     618           0 :                 ;
     619             :         }
     620             : 
     621             :         /*
     622             :          * Back up until the last '-' character or
     623             :          * start of line.
     624             :          */
     625           0 :         for (; (p >= line) && (*p != '-'); p--) {
     626           0 :                 ;
     627             :         }
     628             : 
     629           0 :         if((p >= line) && (*p == '-')) {
     630           0 :                 *p = ' ';
     631             :         }
     632             : 
     633           0 :         frame = talloc_stackframe();
     634           0 :         for (count=0; count<9 &&
     635           0 :                         next_token_talloc(frame, &cline, &tok[count],NULL);
     636           0 :                         count++) {
     637           0 :                 ;
     638             :         }
     639             : 
     640             :         /* we must get 7 tokens */
     641           0 :         if (count < 7) {
     642           0 :                 TALLOC_FREE(frame);
     643           0 :                 return False;
     644             :         }
     645             : 
     646             :         /* the 2nd and 4th, 6th columns must be integer */
     647           0 :         if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) {
     648           0 :                 TALLOC_FREE(frame);
     649           0 :                 return False;
     650             :         }
     651           0 :         if (!isdigit((int)*tok[5])) {
     652           0 :                 TALLOC_FREE(frame);
     653           0 :                 return False;
     654             :         }
     655             : 
     656             :         /* if the user contains a ! then trim the first part of it */
     657           0 :         if ((p=strchr_m(tok[2],'!'))) {
     658           0 :                 tok[2] = p+1;
     659             :         }
     660             : 
     661           0 :         buf->sysjob = atoi(tok[1]);
     662           0 :         buf->size = atoi(tok[3]);
     663           0 :         if (count > 7 && strequal(tok[7],"on")) {
     664           0 :                 buf->status = LPQ_PRINTING;
     665           0 :         } else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held")) {
     666           0 :                 buf->status = LPQ_PAUSED;
     667             :         } else {
     668           0 :                 buf->status = LPQ_QUEUED;
     669             :         }
     670           0 :         buf->priority = 0;
     671           0 :         buf->time = EntryTime(tok, 4, count, 7);
     672           0 :         fstrcpy(buf->fs_user,tok[2]);
     673           0 :         fstrcpy(buf->fs_file,tok[2]);
     674           0 :         TALLOC_FREE(frame);
     675           0 :         return True;
     676             : }
     677             : 
     678             : /****************************************************************************
     679             : parse a lpq line
     680             : 
     681             : here is an example of lpq output under qnx
     682             : Spooler: /qnx/spooler, on node 1
     683             : Printer: txt        (ready)
     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             : ****************************************************************************/
     688             : 
     689           0 : static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first)
     690             : {
     691           0 :         char *tok[7];
     692           0 :         int count=0;
     693           0 :         const char *cline = line;
     694           0 :         TALLOC_CTX *frame = NULL;
     695             : 
     696           0 :         DEBUG(4,("antes [%s]\n", line));
     697             : 
     698             :         /* handle the case of "-- standard input --" as a filename */
     699           0 :         string_sub(line,"standard input","STDIN",0);
     700           0 :         DEBUG(4,("despues [%s]\n", line));
     701           0 :         all_string_sub(line,"-- ","\"",0);
     702           0 :         all_string_sub(line," --","\"",0);
     703           0 :         DEBUG(4,("despues 1 [%s]\n", line));
     704             : 
     705           0 :         string_sub(line,"[job #","",0);
     706           0 :         string_sub(line,"]","",0);
     707           0 :         DEBUG(4,("despues 2 [%s]\n", line));
     708             : 
     709           0 :         frame = talloc_stackframe();
     710           0 :         for (count=0; count<7 &&
     711           0 :                         next_token_talloc(frame,&cline,&tok[count],NULL);
     712           0 :                         count++) {
     713           0 :                 ;
     714             :         }
     715             : 
     716             :         /* we must get 7 tokens */
     717           0 :         if (count < 7) {
     718           0 :                 TALLOC_FREE(frame);
     719           0 :                 return False;
     720             :         }
     721             : 
     722             :         /* the 3rd and 5th columns must be integer */
     723           0 :         if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) {
     724           0 :                 TALLOC_FREE(frame);
     725           0 :                 return False;
     726             :         }
     727             : 
     728             :         /* only take the last part of the filename */
     729             :         {
     730           0 :                 char *p = strrchr_m(tok[6],'/');
     731           0 :                 if (p) {
     732           0 :                         tok[6] = p+1;
     733             :                 }
     734             :         }
     735             : 
     736           0 :         buf->sysjob = atoi(tok[2]);
     737           0 :         buf->size = atoi(tok[4]);
     738           0 :         buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
     739           0 :         buf->priority = 0;
     740           0 :         buf->time = time(NULL);
     741           0 :         fstrcpy(buf->fs_user,tok[1]);
     742           0 :         fstrcpy(buf->fs_file,tok[6]);
     743           0 :         TALLOC_FREE(frame);
     744           0 :         return True;
     745             : }
     746             : 
     747             : /****************************************************************************
     748             :   parse a lpq line for the plp printing system
     749             :   Bertrand Wallrich <Bertrand.Wallrich@loria.fr>
     750             : 
     751             : redone by tridge. Here is a sample queue:
     752             : 
     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
     758             : 
     759             : ****************************************************************************/
     760             : 
     761           0 : static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first)
     762             : {
     763           0 :         char *tok[11];
     764           0 :         int count=0;
     765           0 :         const char *cline = line;
     766           0 :         TALLOC_CTX *frame = talloc_stackframe();
     767             : 
     768             :         /* handle the case of "(standard input)" as a filename */
     769           0 :         string_sub(line,"stdin","STDIN",0);
     770           0 :         all_string_sub(line,"(","\"",0);
     771           0 :         all_string_sub(line,")","\"",0);
     772             : 
     773           0 :         for (count=0; count<11 &&
     774           0 :                         next_token_talloc(frame,&cline,&tok[count],NULL);
     775           0 :                         count++) {
     776           0 :                 ;
     777             :         }
     778             : 
     779             :         /* we must get 11 tokens */
     780           0 :         if (count < 11) {
     781           0 :                 TALLOC_FREE(frame);
     782           0 :                 return False;
     783             :         }
     784             : 
     785             :         /* the first must be "active" or begin with an integer */
     786           0 :         if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) {
     787           0 :                 TALLOC_FREE(frame);
     788           0 :                 return False;
     789             :         }
     790             : 
     791             :         /* the 5th and 8th must be integer */
     792           0 :         if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) {
     793           0 :                 TALLOC_FREE(frame);
     794           0 :                 return False;
     795             :         }
     796             : 
     797             :         /* if the fname contains a space then use STDIN */
     798           0 :         if (strchr_m(tok[6],' ')) {
     799           0 :                 tok[6] = talloc_strdup(frame, "STDIN");
     800           0 :                 if (!tok[6]) {
     801           0 :                         TALLOC_FREE(frame);
     802           0 :                         return false;
     803             :                 }
     804             :         }
     805             : 
     806             :         /* only take the last part of the filename */
     807             :         {
     808           0 :                 fstring tmp;
     809           0 :                 char *p = strrchr_m(tok[6],'/');
     810           0 :                 if (p) {
     811           0 :                         size_t len = strlen(tok[6])+1;
     812           0 :                         fstrcpy(tmp,p+1);
     813           0 :                         strlcpy(tok[6],tmp, len);
     814             :                 }
     815             :         }
     816             : 
     817           0 :         buf->sysjob = atoi(tok[4]);
     818             : 
     819           0 :         buf->size = atoi(tok[7]);
     820           0 :         if (strchr_m(tok[7],'K')) {
     821           0 :                 buf->size *= 1024;
     822             :         }
     823           0 :         if (strchr_m(tok[7],'M')) {
     824           0 :                 buf->size *= 1024*1024;
     825             :         }
     826             : 
     827           0 :         buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;
     828           0 :         buf->priority = 0;
     829           0 :         buf->time = time(NULL);
     830           0 :         fstrcpy(buf->fs_user,tok[1]);
     831           0 :         fstrcpy(buf->fs_file,tok[6]);
     832           0 :         TALLOC_FREE(frame);
     833           0 :         return True;
     834             : }
     835             : 
     836             : /*******************************************************************
     837             : parse lpq on an NT system
     838             : 
     839             :                          Windows 2000 LPD Server
     840             :                               Printer \\10.0.0.2\NP17PCL (Paused)
     841             : 
     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
     847             : 
     848             : ********************************************************************/
     849             : 
     850           0 : static bool parse_lpq_nt(char *line,print_queue_struct *buf,bool first)
     851             : {
     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
     857           0 :         typedef struct {
     858             :                 char owner[LPRNT_OWNSIZ];
     859             :                 char space1;
     860             :                 char status[LPRNT_STATSIZ];
     861             :                 char space2;
     862             :                 char jobname[LPRNT_JOBSIZ];
     863             :                 char space3;
     864             :                 char jobid[LPRNT_IDSIZ];
     865             :                 char space4;
     866             :                 char size[LPRNT_SIZSIZ];
     867             :                 char terminator;
     868             :         } nt_lpq_line;
     869             : 
     870           0 :         char parse_line_char[sizeof(nt_lpq_line)];
     871           0 :         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"
     875             : 
     876           0 :         memset(parse_line_char, '\0', sizeof(parse_line_char));
     877           0 :         strncpy(parse_line_char, line, sizeof(parse_line_char) -1);
     878             : 
     879           0 :         if (strlen(parse_line_char) != sizeof(parse_line_char) - 1) {
     880           0 :                 return False;
     881             :         }
     882             : 
     883             :         /* Just want the first word in the owner field - the username */
     884           0 :         if (strchr_m(parse_line->owner, ' ')) {
     885           0 :                 *(strchr_m(parse_line->owner, ' ')) = '\0';
     886             :         } else {
     887           0 :                 parse_line->space1 = '\0';
     888             :         }
     889             : 
     890             :         /* Make sure we have an owner */
     891           0 :         if (!strlen(parse_line->owner)) {
     892           0 :                 return False;
     893             :         }
     894             : 
     895             :         /* Make sure the status is valid */
     896           0 :         parse_line->space2 = '\0';
     897           0 :         trim_char(parse_line->status, '\0', ' ');
     898           0 :         if (!strequal(parse_line->status, LPRNT_PRINTING) &&
     899           0 :                         !strequal(parse_line->status, LPRNT_PAUSED) &&
     900           0 :                         !strequal(parse_line->status, LPRNT_WAITING)) {
     901           0 :                 return False;
     902             :         }
     903             :   
     904           0 :         parse_line->space3 = '\0';
     905           0 :         trim_char(parse_line->jobname, '\0', ' ');
     906             : 
     907           0 :         buf->sysjob = atoi(parse_line->jobid);
     908           0 :         buf->priority = 0;
     909           0 :         buf->size = atoi(parse_line->size);
     910           0 :         buf->time = time(NULL);
     911           0 :         fstrcpy(buf->fs_user, parse_line->owner);
     912           0 :         fstrcpy(buf->fs_file, parse_line->jobname);
     913           0 :         if (strequal(parse_line->status, LPRNT_PRINTING)) {
     914           0 :                 buf->status = LPQ_PRINTING;
     915           0 :         } else if (strequal(parse_line->status, LPRNT_PAUSED)) {
     916           0 :                 buf->status = LPQ_PAUSED;
     917             :         } else {
     918           0 :                 buf->status = LPQ_QUEUED;
     919             :         }
     920             : 
     921           0 :         return True;
     922             : }
     923             : 
     924             : /*******************************************************************
     925             : parse lpq on an OS2 system
     926             : 
     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  
     931             : 
     932             : ********************************************************************/
     933             : 
     934           0 : static bool parse_lpq_os2(char *line,print_queue_struct *buf,bool first)
     935             : {
     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
     941           0 :         typedef struct {
     942             :                 char jobid[LPROS2_IDSIZ];
     943             :                 char space1[2];
     944             :                 char jobname[LPROS2_JOBSIZ];
     945             :                 char space2[14];
     946             :                 char size[LPROS2_SIZSIZ];
     947             :                 char space3[4];
     948             :                 char status[LPROS2_STATSIZ];
     949             :                 char space4[4];
     950             :                 char owner[LPROS2_OWNSIZ];
     951             :                 char terminator;
     952             :         } os2_lpq_line;
     953             : 
     954           0 :         char parse_line_char[sizeof(os2_lpq_line)];
     955           0 :         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"
     959             : 
     960           0 :         memset(parse_line_char, '\0', sizeof(parse_line_char));
     961           0 :         strncpy(parse_line_char, line, sizeof(parse_line_char) -1);
     962             : 
     963           0 :         if (strlen(parse_line_char) != sizeof(parse_line_char) - 1) {
     964           0 :                 return False;
     965             :         }
     966             : 
     967             :         /* Get the jobid */
     968           0 :         buf->sysjob = atoi(parse_line->jobid);
     969             : 
     970             :         /* Get the job name */
     971           0 :         parse_line->space2[0] = '\0';
     972           0 :         trim_char(parse_line->jobname, '\0', ' ');
     973           0 :         fstrcpy(buf->fs_file, parse_line->jobname);
     974             : 
     975           0 :         buf->priority = 0;
     976           0 :         buf->size = atoi(parse_line->size);
     977           0 :         buf->time = time(NULL);
     978             : 
     979             :         /* Make sure we have an owner */
     980           0 :         if (!strlen(parse_line->owner)) {
     981           0 :                 return False;
     982             :         }
     983             : 
     984             :         /* Make sure we have a valid status */
     985           0 :         parse_line->space4[0] = '\0';
     986           0 :         trim_char(parse_line->status, '\0', ' ');
     987           0 :         if (!strequal(parse_line->status, LPROS2_PRINTING) &&
     988           0 :                         !strequal(parse_line->status, LPROS2_PAUSED) &&
     989           0 :                         !strequal(parse_line->status, LPROS2_WAITING)) {
     990           0 :                 return False;
     991             :         }
     992             : 
     993           0 :         fstrcpy(buf->fs_user, parse_line->owner);
     994           0 :         if (strequal(parse_line->status, LPROS2_PRINTING)) {
     995           0 :                 buf->status = LPQ_PRINTING;
     996           0 :         } else if (strequal(parse_line->status, LPROS2_PAUSED)) {
     997           0 :                 buf->status = LPQ_PAUSED;
     998             :         } else {
     999           0 :                 buf->status = LPQ_QUEUED;
    1000             :         }
    1001             : 
    1002           0 :         return True;
    1003             : }
    1004             : 
    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 };
    1008             : 
    1009             : #ifdef DEVELOPER
    1010             : 
    1011             : /****************************************************************************
    1012             : parse a vlp line
    1013             : ****************************************************************************/
    1014             : 
    1015        5866 : static bool parse_lpq_vlp(char *line,print_queue_struct *buf,bool first)
    1016             : {
    1017        5866 :         int toknum = 0;
    1018           0 :         char *tok;
    1019        5866 :         TALLOC_CTX *frame = talloc_stackframe();
    1020        5866 :         const char *cline = line;
    1021             : 
    1022             :         /* First line is printer status */
    1023             : 
    1024        5866 :         if (!isdigit(line[0])) {
    1025        2004 :                 TALLOC_FREE(frame);
    1026        2004 :                 return False;
    1027             :         }
    1028             : 
    1029             :         /* Parse a print job entry */
    1030             : 
    1031       27034 :         while(next_token_talloc(frame, &cline, &tok, NULL)) {
    1032       23172 :                 switch (toknum) {
    1033        3862 :                 case 0:
    1034        3862 :                         buf->sysjob = atoi(tok);
    1035        3862 :                         break;
    1036        3862 :                 case 1:
    1037        3862 :                         buf->size = atoi(tok);
    1038        3862 :                         break;
    1039        3862 :                 case 2:
    1040        3862 :                         buf->status = atoi(tok);
    1041        3862 :                         break;
    1042        3862 :                 case 3:
    1043        3862 :                         buf->time = atoi(tok);
    1044        3862 :                         break;
    1045        3862 :                 case 4:
    1046        3862 :                         fstrcpy(buf->fs_user, tok);
    1047        3862 :                         break;
    1048        3862 :                 case 5:
    1049        3862 :                         fstrcpy(buf->fs_file, tok);
    1050        3862 :                         break;
    1051             :                 }
    1052       23172 :                 toknum++;
    1053             :         }
    1054             : 
    1055        3862 :         TALLOC_FREE(frame);
    1056        3862 :         return True;
    1057             : }
    1058             : 
    1059             : #endif /* DEVELOPER */
    1060             : 
    1061             : /****************************************************************************
    1062             : parse a lpq line. Choose printing style
    1063             : ****************************************************************************/
    1064             : 
    1065        5866 : bool parse_lpq_entry(enum printing_types printing_type,char *line,
    1066             :                      print_queue_struct *buf,
    1067             :                      print_status_struct *status,bool first)
    1068             : {
    1069           0 :         bool ret;
    1070             : 
    1071        5866 :         switch (printing_type) {
    1072           0 :                 case PRINT_SYSV:
    1073           0 :                         ret = parse_lpq_sysv(line,buf,first);
    1074           0 :                         break;
    1075           0 :                 case PRINT_AIX:      
    1076           0 :                         ret = parse_lpq_aix(line,buf,first);
    1077           0 :                         break;
    1078           0 :                 case PRINT_HPUX:
    1079           0 :                         ret = parse_lpq_hpux(line,buf,first);
    1080           0 :                         break;
    1081           0 :                 case PRINT_QNX:
    1082           0 :                         ret = parse_lpq_qnx(line,buf,first);
    1083           0 :                         break;
    1084           0 :                 case PRINT_LPRNG:
    1085           0 :                         ret = parse_lpq_lprng(line,buf,first);
    1086           0 :                         break;
    1087           0 :                 case PRINT_PLP:
    1088           0 :                         ret = parse_lpq_plp(line,buf,first);
    1089           0 :                         break;
    1090           0 :                 case PRINT_LPRNT:
    1091           0 :                         ret = parse_lpq_nt(line,buf,first);
    1092           0 :                         break;
    1093           0 :                 case PRINT_LPROS2:
    1094           0 :                         ret = parse_lpq_os2(line,buf,first);
    1095           0 :                         break;
    1096             : #ifdef DEVELOPER
    1097        5866 :                 case PRINT_VLP:
    1098             :                 case PRINT_TEST:
    1099        5866 :                         ret = parse_lpq_vlp(line,buf,first);
    1100        5866 :                         break;
    1101             : #endif /* DEVELOPER */
    1102           0 :                 default:
    1103           0 :                         ret = parse_lpq_bsd(line,buf,first);
    1104           0 :                         break;
    1105             :         }
    1106             : 
    1107             :         /* We don't want the newline in the status message. */
    1108             :         {
    1109        5866 :                 char *p = strchr_m(line,'\n');
    1110        5866 :                 if (p) {
    1111           0 :                         *p = 0;
    1112             :                 }
    1113             :         }
    1114             : 
    1115             :         /* in the LPRNG case, we skip lines starting by a space.*/
    1116        5866 :         if (!ret && (printing_type==PRINT_LPRNG) ) {
    1117           0 :                 if (line[0]==' ') {
    1118           0 :                         return ret;
    1119             :                 }
    1120             :         }
    1121             : 
    1122        5866 :         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 */
    1126           0 :                 int i;
    1127        2004 :                 if (!strlower_m(line)) {
    1128           0 :                         return false;
    1129             :                 }
    1130             :       
    1131        2004 :                 switch (status->status) {
    1132        2004 :                         case LPSTAT_OK:
    1133       10446 :                                 for (i=0; stat0_strings[i]; i++) {
    1134        9039 :                                         if (strstr_m(line,stat0_strings[i])) {
    1135         597 :                                                 fstrcpy(status->message,line);
    1136         597 :                                                 status->status=LPSTAT_OK;
    1137         597 :                                                 return ret;
    1138             :                                         }
    1139             :                                 }
    1140             :                                 FALL_THROUGH;
    1141             :                         case LPSTAT_STOPPED:
    1142        2814 :                                 for (i=0; stat1_strings[i]; i++) {
    1143        2814 :                                         if (strstr_m(line,stat1_strings[i])) {
    1144        1407 :                                                 fstrcpy(status->message,line);
    1145        1407 :                                                 status->status=LPSTAT_STOPPED;
    1146        1407 :                                                 return ret;
    1147             :                                         }
    1148             :                                 }
    1149             :                                 FALL_THROUGH;
    1150             :                         case LPSTAT_ERROR:
    1151           0 :                                 for (i=0; stat2_strings[i]; i++) {
    1152           0 :                                         if (strstr_m(line,stat2_strings[i])) {
    1153           0 :                                                 fstrcpy(status->message,line);
    1154           0 :                                                 status->status=LPSTAT_ERROR;
    1155           0 :                                                 return ret;
    1156             :                                         }
    1157             :                                 }
    1158           0 :                                 break;
    1159             :                 }
    1160             :         }
    1161             : 
    1162        3862 :         return ret;
    1163             : }
    1164             : 

Generated by: LCOV version 1.14