00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "includes.h"
00022
00023 static const char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
00024 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Err"};
00025
00026
00027
00028
00029
00030
00031 static time_t EntryTime(fstring tok[], int ptr, int count, int minimum)
00032 {
00033 time_t jobtime,jobtime1;
00034
00035 jobtime = time(NULL);
00036 if (count >= minimum) {
00037 struct tm *t;
00038 int i, day, hour, min, sec;
00039 char *c;
00040
00041 for (i=0; i<13; i++) {
00042 if (!strncmp(tok[ptr], Months[i],3)) {
00043 break;
00044 }
00045 }
00046
00047 if (i<12) {
00048 t = localtime(&jobtime);
00049 if (!t) {
00050 return (time_t)-1;
00051 }
00052 day = atoi(tok[ptr+1]);
00053 c=(char *)(tok[ptr+2]);
00054 *(c+2)=0;
00055 hour = atoi(c);
00056 *(c+5)=0;
00057 min = atoi(c+3);
00058 if(*(c+6) != 0) {
00059 sec = atoi(c+6);
00060 } else {
00061 sec=0;
00062 }
00063
00064 if ((t->tm_mon < i)|| ((t->tm_mon == i)&&
00065 ((t->tm_mday < day)||
00066 ((t->tm_mday == day)&&
00067 (t->tm_hour*60+t->tm_min < hour*60+min))))) {
00068 t->tm_year--;
00069 }
00070
00071 t->tm_mon = i;
00072 t->tm_mday = day;
00073 t->tm_hour = hour;
00074 t->tm_min = min;
00075 t->tm_sec = sec;
00076 jobtime1 = mktime(t);
00077 if (jobtime1 != (time_t)-1) {
00078 jobtime = jobtime1;
00079 }
00080 }
00081 }
00082 return jobtime;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first)
00107 {
00108 #ifdef OSF1
00109 #define RANKTOK 0
00110 #define PRIOTOK 1
00111 #define USERTOK 2
00112 #define JOBTOK 3
00113 #define FILETOK 4
00114 #define TOTALTOK (count - 2)
00115 #define NTOK 6
00116 #define MAXTOK 128
00117 #else
00118 #define RANKTOK 0
00119 #define USERTOK 1
00120 #define JOBTOK 2
00121 #define FILETOK 3
00122 #define TOTALTOK (count - 2)
00123 #define NTOK 5
00124 #define MAXTOK 128
00125 #endif
00126
00127 char *tok[MAXTOK];
00128 int count = 0;
00129 pstring line2;
00130
00131 pstrcpy(line2,line);
00132
00133 #ifdef OSF1
00134 {
00135 size_t length;
00136 length = strlen(line2);
00137 if (line2[length-3] == ':') {
00138 return False;
00139 }
00140 }
00141 #endif
00142
00143
00144 tok[0] = strtok(line2," \t");
00145 count++;
00146
00147 while ((count < MAXTOK) && ((tok[count] = strtok(NULL," \t")) != NULL)) {
00148 count++;
00149 }
00150
00151
00152 if (count < NTOK) {
00153 return False;
00154 }
00155
00156
00157 if (!isdigit((int)*tok[JOBTOK]) || !isdigit((int)*tok[TOTALTOK])) {
00158 return False;
00159 }
00160
00161 buf->job = atoi(tok[JOBTOK]);
00162 buf->size = atoi(tok[TOTALTOK]);
00163 buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED;
00164 buf->time = time(NULL);
00165 fstrcpy(buf->fs_user,tok[USERTOK]);
00166 fstrcpy(buf->fs_file,tok[FILETOK]);
00167
00168 if ((FILETOK + 1) != TOTALTOK) {
00169 int i;
00170
00171 for (i = (FILETOK + 1); i < TOTALTOK; i++) {
00172
00173
00174
00175 fstrcat(buf->fs_file, " ");
00176 fstrcat(buf->fs_file, tok[i]);
00177 }
00178
00179 fstrterminate(buf->fs_file);
00180 }
00181
00182 #ifdef PRIOTOK
00183 buf->priority = atoi(tok[PRIOTOK]);
00184 #else
00185 buf->priority = 1;
00186 #endif
00187 return True;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 static time_t LPRng_time(char *time_string)
00208 {
00209 time_t jobtime;
00210 struct tm *t;
00211
00212 jobtime = time(NULL);
00213 t = localtime(&jobtime);
00214 if (!t) {
00215 return (time_t)-1;
00216 }
00217
00218 if ( atoi(time_string) < 24 ){
00219 t->tm_hour = atoi(time_string);
00220 t->tm_min = atoi(time_string+3);
00221 t->tm_sec = atoi(time_string+6);
00222 } else {
00223 t->tm_year = atoi(time_string)-1900;
00224 t->tm_mon = atoi(time_string+5)-1;
00225 t->tm_mday = atoi(time_string+8);
00226 t->tm_hour = atoi(time_string+11);
00227 t->tm_min = atoi(time_string+14);
00228 t->tm_sec = atoi(time_string+17);
00229 }
00230 jobtime = mktime(t);
00231
00232 return jobtime;
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
00244 {
00245 #define LPRNG_RANKTOK 0
00246 #define LPRNG_USERTOK 1
00247 #define LPRNG_PRIOTOK 2
00248 #define LPRNG_JOBTOK 3
00249 #define LPRNG_FILETOK 4
00250 #define LPRNG_TOTALTOK (num_tok - 2)
00251 #define LPRNG_TIMETOK (num_tok - 1)
00252 #define LPRNG_NTOK 7
00253 #define LPRNG_MAXTOK 128
00254
00255 fstring tokarr[LPRNG_MAXTOK];
00256 const char *cptr;
00257 char *ptr;
00258 int num_tok = 0;
00259
00260 cptr = line;
00261 while((num_tok < LPRNG_MAXTOK) && next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring))) {
00262 num_tok++;
00263 }
00264
00265
00266 if (num_tok < LPRNG_NTOK) {
00267 return False;
00268 }
00269
00270 if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) {
00271 return False;
00272 }
00273
00274 buf->job = atoi(tokarr[LPRNG_JOBTOK]);
00275 buf->size = atoi(tokarr[LPRNG_TOTALTOK]);
00276
00277 if (strequal(tokarr[LPRNG_RANKTOK],"active")) {
00278 buf->status = LPQ_PRINTING;
00279 } else if (strequal(tokarr[LPRNG_RANKTOK],"done")) {
00280 buf->status = LPQ_PRINTED;
00281 } else if (isdigit((int)*tokarr[LPRNG_RANKTOK])) {
00282 buf->status = LPQ_QUEUED;
00283 } else {
00284 buf->status = LPQ_PAUSED;
00285 }
00286
00287 buf->priority = *tokarr[LPRNG_PRIOTOK] -'A';
00288
00289 buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]);
00290
00291 fstrcpy(buf->fs_user,tokarr[LPRNG_USERTOK]);
00292
00293
00294
00295
00296
00297 if ((ptr = strchr_m(buf->fs_user,'@')) != NULL) {
00298 *ptr = '\0';
00299 }
00300
00301 fstrcpy(buf->fs_file,tokarr[LPRNG_FILETOK]);
00302
00303 if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) {
00304 int i;
00305
00306 for (i = (LPRNG_FILETOK + 1); i < LPRNG_TOTALTOK; i++) {
00307
00308
00309
00310 fstrcat(buf->fs_file, " ");
00311 fstrcat(buf->fs_file, tokarr[i]);
00312 }
00313
00314 fstrterminate(buf->fs_file);
00315 }
00316
00317 return True;
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first)
00334 {
00335 fstring tok[11];
00336 int count=0;
00337 const char *cline = line;
00338
00339
00340 string_sub(line,"standard input","STDIN",0);
00341 all_string_sub(line,"(","\"",0);
00342 all_string_sub(line,")","\"",0);
00343
00344 for (count=0; count<10 && next_token(&cline,tok[count],NULL, sizeof(tok[count])); count++) {
00345 ;
00346 }
00347
00348
00349 if (count < 10) {
00350 if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) {
00351
00352 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) {
00353 return False;
00354 }
00355 buf->size = atoi(tok[4]) * 1024;
00356
00357 if (strchr_m(tok[2],' ')) {
00358 fstrcpy(tok[2],"STDIN");
00359 }
00360
00361
00362 {
00363 fstring tmp;
00364 char *p = strrchr_m(tok[2],'/');
00365 if (p) {
00366 fstrcpy(tmp,p+1);
00367 fstrcpy(tok[2],tmp);
00368 }
00369 }
00370
00371 buf->job = atoi(tok[1]);
00372 buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED;
00373 buf->priority = 0;
00374 buf->time = time(NULL);
00375 fstrcpy(buf->fs_user,tok[3]);
00376 fstrcpy(buf->fs_file,tok[2]);
00377 } else {
00378 DEBUG(6,("parse_lpq_aix count=%d\n", count));
00379 return False;
00380 }
00381 } else {
00382
00383 if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) {
00384 return False;
00385 }
00386
00387 buf->size = atoi(tok[8]) * 1024;
00388
00389 if (strchr_m(tok[4],' ')) {
00390 fstrcpy(tok[4],"STDIN");
00391 }
00392
00393
00394 {
00395 fstring tmp;
00396 char *p = strrchr_m(tok[4],'/');
00397 if (p) {
00398 fstrcpy(tmp,p+1);
00399 fstrcpy(tok[4],tmp);
00400 }
00401 }
00402
00403 buf->job = atoi(tok[3]);
00404 buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED;
00405 buf->priority = 0;
00406 buf->time = time(NULL);
00407 fstrcpy(buf->fs_user,tok[5]);
00408 fstrcpy(buf->fs_file,tok[4]);
00409 }
00410
00411 return True;
00412 }
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 static BOOL parse_lpq_hpux(char *line, print_queue_struct *buf, BOOL first)
00426 {
00427
00428 static BOOL header_line_ok=False, base_prio_reset=False;
00429 static fstring jobuser;
00430 static int jobid;
00431 static int jobprio;
00432 static time_t jobtime;
00433 static int jobstat=LPQ_QUEUED;
00434
00435
00436 static int base_prio;
00437 int count;
00438 char htab = '\011';
00439 const char *cline = line;
00440 fstring tok[12];
00441
00442
00443
00444 if (line[0] == htab) {
00445
00446 if (!strncmp(line,"\tfence priority : ",18)) {
00447 base_prio=atoi(&line[18]);
00448 DEBUG(4, ("fence priority set at %d\n", base_prio));
00449 }
00450
00451 if (!header_line_ok) {
00452 return False;
00453 }
00454
00455
00456 string_sub(line,"standard input","STDIN",0);
00457 all_string_sub(line,"(","\"",0);
00458 all_string_sub(line,")","\"",0);
00459
00460 for (count=0; count<2 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
00461 ;
00462 }
00463
00464 if (count < 2) {
00465 return False;
00466 }
00467
00468
00469 if (!isdigit((int)*tok[1])) {
00470 return False;
00471 }
00472
00473
00474 if (strchr_m(tok[0],' ')) {
00475 fstrcpy(tok[0],"STDIN");
00476 }
00477
00478 buf->size = atoi(tok[1]);
00479 fstrcpy(buf->fs_file,tok[0]);
00480
00481
00482 buf->time = jobtime;
00483 buf->job = jobid;
00484 buf->status = jobstat;
00485 buf->priority = jobprio;
00486 fstrcpy(buf->fs_user,jobuser);
00487
00488 return True;
00489 } else {
00490 header_line_ok=False;
00491 if (first) {
00492 if (!base_prio_reset) {
00493 base_prio=0;
00494 base_prio_reset=True;
00495 }
00496 } else if (base_prio) {
00497 base_prio_reset=False;
00498 }
00499
00500
00501 string_sub(line,"-"," ",0);
00502
00503 for (count=0; count<12 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
00504 ;
00505 }
00506
00507
00508 if (count < 8) {
00509 return False;
00510 }
00511
00512
00513
00514 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) {
00515 return False;
00516 }
00517 jobid = atoi(tok[1]);
00518 fstrcpy(jobuser,tok[2]);
00519 jobprio = atoi(tok[4]);
00520
00521
00522 jobtime=EntryTime(tok, 5, count, 8);
00523 if (jobprio < base_prio) {
00524 jobstat = LPQ_PAUSED;
00525 DEBUG (4, ("job %d is paused: prio %d < %d; jobstat=%d\n",
00526 jobid, jobprio, base_prio, jobstat));
00527 } else {
00528 jobstat = LPQ_QUEUED;
00529 if ((count >8) && (((strequal(tok[8],"on")) ||
00530 ((strequal(tok[8],"from")) &&
00531 ((count > 10)&&(strequal(tok[10],"on"))))))) {
00532 jobstat = LPQ_PRINTING;
00533 }
00534 }
00535
00536 header_line_ok=True;
00537 return False;
00538 }
00539 }
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551 static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first)
00552 {
00553 fstring tok[9];
00554 int count=0;
00555 char *p;
00556 const char *cline = line;
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 for (p = line ; !isspace(*p) && *p; p++) {
00568 ;
00569 }
00570
00571
00572
00573
00574
00575 for (; (p >= line) && (*p != '-'); p--) {
00576 ;
00577 }
00578
00579 if((p >= line) && (*p == '-')) {
00580 *p = ' ';
00581 }
00582
00583 for (count=0; count<9 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
00584 ;
00585 }
00586
00587
00588 if (count < 7) {
00589 return False;
00590 }
00591
00592
00593 if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) {
00594 return False;
00595 }
00596 if (!isdigit((int)*tok[5])) {
00597 return False;
00598 }
00599
00600
00601 if ((p=strchr_m(tok[2],'!'))) {
00602 fstring tmp;
00603 fstrcpy(tmp,p+1);
00604 fstrcpy(tok[2],tmp);
00605 }
00606
00607 buf->job = atoi(tok[1]);
00608 buf->size = atoi(tok[3]);
00609 if (count > 7 && strequal(tok[7],"on")) {
00610 buf->status = LPQ_PRINTING;
00611 } else if (count > 8 && strequal(tok[7],"being") && strequal(tok[8],"held")) {
00612 buf->status = LPQ_PAUSED;
00613 } else {
00614 buf->status = LPQ_QUEUED;
00615 }
00616 buf->priority = 0;
00617 buf->time = EntryTime(tok, 4, count, 7);
00618 fstrcpy(buf->fs_user,tok[2]);
00619 fstrcpy(buf->fs_file,tok[2]);
00620 return True;
00621 }
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634 static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first)
00635 {
00636 fstring tok[7];
00637 int count=0;
00638 const char *cline = line;
00639
00640 DEBUG(4,("antes [%s]\n", line));
00641
00642
00643 string_sub(line,"standard input","STDIN",0);
00644 DEBUG(4,("despues [%s]\n", line));
00645 all_string_sub(line,"-- ","\"",0);
00646 all_string_sub(line," --","\"",0);
00647 DEBUG(4,("despues 1 [%s]\n", line));
00648
00649 string_sub(line,"[job #","",0);
00650 string_sub(line,"]","",0);
00651 DEBUG(4,("despues 2 [%s]\n", line));
00652
00653 for (count=0; count<7 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
00654 ;
00655 }
00656
00657
00658 if (count < 7) {
00659 return False;
00660 }
00661
00662
00663 if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) {
00664 return False;
00665 }
00666
00667
00668 {
00669 fstring tmp;
00670 char *p = strrchr_m(tok[6],'/');
00671 if (p) {
00672 fstrcpy(tmp,p+1);
00673 fstrcpy(tok[6],tmp);
00674 }
00675 }
00676
00677 buf->job = atoi(tok[2]);
00678 buf->size = atoi(tok[4]);
00679 buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
00680 buf->priority = 0;
00681 buf->time = time(NULL);
00682 fstrcpy(buf->fs_user,tok[1]);
00683 fstrcpy(buf->fs_file,tok[6]);
00684 return True;
00685 }
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701 static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first)
00702 {
00703 fstring tok[11];
00704 int count=0;
00705 const char *cline = line;
00706
00707
00708 string_sub(line,"stdin","STDIN",0);
00709 all_string_sub(line,"(","\"",0);
00710 all_string_sub(line,")","\"",0);
00711
00712 for (count=0; count<11 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) {
00713 ;
00714 }
00715
00716
00717 if (count < 11) {
00718 return False;
00719 }
00720
00721
00722 if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) {
00723 return False;
00724 }
00725
00726
00727 if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) {
00728 return False;
00729 }
00730
00731
00732 if (strchr_m(tok[6],' ')) {
00733 fstrcpy(tok[6],"STDIN");
00734 }
00735
00736
00737 {
00738 fstring tmp;
00739 char *p = strrchr_m(tok[6],'/');
00740 if (p) {
00741 fstrcpy(tmp,p+1);
00742 fstrcpy(tok[6],tmp);
00743 }
00744 }
00745
00746 buf->job = atoi(tok[4]);
00747
00748 buf->size = atoi(tok[7]);
00749 if (strchr_m(tok[7],'K')) {
00750 buf->size *= 1024;
00751 }
00752 if (strchr_m(tok[7],'M')) {
00753 buf->size *= 1024*1024;
00754 }
00755
00756 buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;
00757 buf->priority = 0;
00758 buf->time = time(NULL);
00759 fstrcpy(buf->fs_user,tok[1]);
00760 fstrcpy(buf->fs_file,tok[6]);
00761 return True;
00762 }
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778 static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first)
00779 {
00780 #define LPRNT_OWNSIZ 11
00781 #define LPRNT_STATSIZ 9
00782 #define LPRNT_JOBSIZ 19
00783 #define LPRNT_IDSIZ 6
00784 #define LPRNT_SIZSIZ 9
00785 typedef struct {
00786 char owner[LPRNT_OWNSIZ];
00787 char space1;
00788 char status[LPRNT_STATSIZ];
00789 char space2;
00790 char jobname[LPRNT_JOBSIZ];
00791 char space3;
00792 char jobid[LPRNT_IDSIZ];
00793 char space4;
00794 char size[LPRNT_SIZSIZ];
00795 char terminator;
00796 } nt_lpq_line;
00797
00798 nt_lpq_line parse_line;
00799 #define LPRNT_PRINTING "Printing"
00800 #define LPRNT_WAITING "Waiting"
00801 #define LPRNT_PAUSED "Paused"
00802
00803 memset(&parse_line, '\0', sizeof(parse_line));
00804 strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
00805
00806 if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) {
00807 return False;
00808 }
00809
00810
00811 if (strchr_m(parse_line.owner, ' ')) {
00812 *(strchr_m(parse_line.owner, ' ')) = '\0';
00813 } else {
00814 parse_line.space1 = '\0';
00815 }
00816
00817
00818 if (!strlen(parse_line.owner)) {
00819 return False;
00820 }
00821
00822
00823 parse_line.space2 = '\0';
00824 trim_char(parse_line.status, '\0', ' ');
00825 if (!strequal(parse_line.status, LPRNT_PRINTING) &&
00826 !strequal(parse_line.status, LPRNT_PAUSED) &&
00827 !strequal(parse_line.status, LPRNT_WAITING)) {
00828 return False;
00829 }
00830
00831 parse_line.space3 = '\0';
00832 trim_char(parse_line.jobname, '\0', ' ');
00833
00834 buf->job = atoi(parse_line.jobid);
00835 buf->priority = 0;
00836 buf->size = atoi(parse_line.size);
00837 buf->time = time(NULL);
00838 fstrcpy(buf->fs_user, parse_line.owner);
00839 fstrcpy(buf->fs_file, parse_line.jobname);
00840 if (strequal(parse_line.status, LPRNT_PRINTING)) {
00841 buf->status = LPQ_PRINTING;
00842 } else if (strequal(parse_line.status, LPRNT_PAUSED)) {
00843 buf->status = LPQ_PAUSED;
00844 } else {
00845 buf->status = LPQ_QUEUED;
00846 }
00847
00848 return True;
00849 }
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861 static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first)
00862 {
00863 #define LPROS2_IDSIZ 5
00864 #define LPROS2_JOBSIZ 15
00865 #define LPROS2_SIZSIZ 8
00866 #define LPROS2_STATSIZ 12
00867 #define LPROS2_OWNSIZ 12
00868 typedef struct {
00869 char jobid[LPROS2_IDSIZ];
00870 char space1[2];
00871 char jobname[LPROS2_JOBSIZ];
00872 char space2[14];
00873 char size[LPROS2_SIZSIZ];
00874 char space3[4];
00875 char status[LPROS2_STATSIZ];
00876 char space4[4];
00877 char owner[LPROS2_OWNSIZ];
00878 char terminator;
00879 } os2_lpq_line;
00880
00881 os2_lpq_line parse_line;
00882 #define LPROS2_PRINTING "Printing"
00883 #define LPROS2_WAITING "Queued"
00884 #define LPROS2_PAUSED "Paused"
00885
00886 memset(&parse_line, '\0', sizeof(parse_line));
00887 strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
00888
00889 if (strlen((char *) &parse_line) != sizeof(parse_line) - 1) {
00890 return False;
00891 }
00892
00893
00894 buf->job = atoi(parse_line.jobid);
00895
00896
00897 parse_line.space2[0] = '\0';
00898 trim_char(parse_line.jobname, '\0', ' ');
00899 fstrcpy(buf->fs_file, parse_line.jobname);
00900
00901 buf->priority = 0;
00902 buf->size = atoi(parse_line.size);
00903 buf->time = time(NULL);
00904
00905
00906 if (!strlen(parse_line.owner)) {
00907 return False;
00908 }
00909
00910
00911 parse_line.space4[0] = '\0';
00912 trim_char(parse_line.status, '\0', ' ');
00913 if (!strequal(parse_line.status, LPROS2_PRINTING) &&
00914 !strequal(parse_line.status, LPROS2_PAUSED) &&
00915 !strequal(parse_line.status, LPROS2_WAITING)) {
00916 return False;
00917 }
00918
00919 fstrcpy(buf->fs_user, parse_line.owner);
00920 if (strequal(parse_line.status, LPROS2_PRINTING)) {
00921 buf->status = LPQ_PRINTING;
00922 } else if (strequal(parse_line.status, LPROS2_PAUSED)) {
00923 buf->status = LPQ_PAUSED;
00924 } else {
00925 buf->status = LPQ_QUEUED;
00926 }
00927
00928 return True;
00929 }
00930
00931 static const char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL };
00932 static const char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };
00933 static const char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL };
00934
00935 #ifdef DEVELOPER
00936
00937
00938
00939
00940
00941 static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first)
00942 {
00943 int toknum = 0;
00944 fstring tok;
00945 const char *cline = line;
00946
00947
00948
00949 if (!isdigit(line[0])) return False;
00950
00951
00952
00953 while(next_token(&cline, tok, NULL, sizeof(fstring))) {
00954 switch (toknum) {
00955 case 0:
00956 buf->job = atoi(tok);
00957 break;
00958 case 1:
00959 buf->size = atoi(tok);
00960 break;
00961 case 2:
00962 buf->status = atoi(tok);
00963 break;
00964 case 3:
00965 buf->time = atoi(tok);
00966 break;
00967 case 4:
00968 fstrcpy(buf->fs_user, tok);
00969 break;
00970 case 5:
00971 fstrcpy(buf->fs_file, tok);
00972 break;
00973 }
00974 toknum++;
00975 }
00976
00977 return True;
00978 }
00979
00980 #endif
00981
00982
00983
00984
00985
00986 BOOL parse_lpq_entry(enum printing_types printing_type,char *line,
00987 print_queue_struct *buf,
00988 print_status_struct *status,BOOL first)
00989 {
00990 BOOL ret;
00991
00992 switch (printing_type) {
00993 case PRINT_SYSV:
00994 ret = parse_lpq_sysv(line,buf,first);
00995 break;
00996 case PRINT_AIX:
00997 ret = parse_lpq_aix(line,buf,first);
00998 break;
00999 case PRINT_HPUX:
01000 ret = parse_lpq_hpux(line,buf,first);
01001 break;
01002 case PRINT_QNX:
01003 ret = parse_lpq_qnx(line,buf,first);
01004 break;
01005 case PRINT_LPRNG:
01006 ret = parse_lpq_lprng(line,buf,first);
01007 break;
01008 case PRINT_PLP:
01009 ret = parse_lpq_plp(line,buf,first);
01010 break;
01011 case PRINT_LPRNT:
01012 ret = parse_lpq_nt(line,buf,first);
01013 break;
01014 case PRINT_LPROS2:
01015 ret = parse_lpq_os2(line,buf,first);
01016 break;
01017 #ifdef DEVELOPER
01018 case PRINT_VLP:
01019 case PRINT_TEST:
01020 ret = parse_lpq_vlp(line,buf,first);
01021 break;
01022 #endif
01023 default:
01024 ret = parse_lpq_bsd(line,buf,first);
01025 break;
01026 }
01027
01028
01029 {
01030 char *p = strchr_m(line,'\n');
01031 if (p) {
01032 *p = 0;
01033 }
01034 }
01035
01036
01037 if (!ret && (printing_type==PRINT_LPRNG) ) {
01038 if (line[0]==' ') {
01039 return ret;
01040 }
01041 }
01042
01043 if (status && !ret) {
01044
01045
01046
01047 int i;
01048 strlower_m(line);
01049
01050 switch (status->status) {
01051 case LPSTAT_OK:
01052 for (i=0; stat0_strings[i]; i++) {
01053 if (strstr_m(line,stat0_strings[i])) {
01054 fstrcpy(status->message,line);
01055 status->status=LPSTAT_OK;
01056 return ret;
01057 }
01058 }
01059
01060 case LPSTAT_STOPPED:
01061 for (i=0; stat1_strings[i]; i++) {
01062 if (strstr_m(line,stat1_strings[i])) {
01063 fstrcpy(status->message,line);
01064 status->status=LPSTAT_STOPPED;
01065 return ret;
01066 }
01067 }
01068
01069 case LPSTAT_ERROR:
01070 for (i=0; stat2_strings[i]; i++) {
01071 if (strstr_m(line,stat2_strings[i])) {
01072 fstrcpy(status->message,line);
01073 status->status=LPSTAT_ERROR;
01074 return ret;
01075 }
01076 }
01077 break;
01078 }
01079 }
01080
01081 return ret;
01082 }