1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (C) 1997-1998 by Norm Jacobs, Colorado Springs, Colorado, USA
* Copyright (C) 1997-1998 by Sun Microsystem, Inc.
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* This module implements support for gathering and comparing available
* printer information on a SVID or XPG4 compliant system. It does this
* through the use of the SVID/XPG4 command "lpstat(1)".
*
* The expectations is that execution of the command "lpstat -v" will
* generate responses in the form of:
*
* device for serial: /dev/term/b
* system for fax: server
* system for color: server (as printer chroma)
*/
#include "includes.h"
#include "printing/pcap.h"
#if defined(SYSV) || defined(HPUX)
bool sysv_cache_reload(void)
{
char **lines;
int i;
#if defined(HPUX)
DEBUG(5, ("reloading hpux printcap cache\n"));
#else
DEBUG(5, ("reloading sysv printcap cache\n"));
#endif
if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL)
{
#if defined(HPUX)
/*
* if "lpstat -v" is NULL then we check if schedular is running if it is
* that means no printers are added on the HP-UX system, if schedular is not
* running we display reload error.
*/
char **scheduler;
scheduler = file_lines_pload("/usr/bin/lpstat -r", NULL);
if(!strcmp(*scheduler,"scheduler is running")){
DEBUG(3,("No Printers found!!!\n"));
TALLOC_FREE(scheduler);
return True;
}
else{
DEBUG(3,("Scheduler is not running!!!\n"));
TALLOC_FREE(scheduler);
return False;
}
#else
DEBUG(3,("No Printers found!!!\n"));
return False;
#endif
}
for (i = 0; lines[i]; i++) {
char *name, *tmp;
char *buf = lines[i];
/* eat "system/device for " */
if (((tmp = strchr_m(buf, ' ')) == NULL) ||
((tmp = strchr_m(++tmp, ' ')) == NULL))
continue;
/*
* In case we're only at the "for ".
*/
if(!strncmp("for ", ++tmp, 4)) {
tmp=strchr_m(tmp, ' ');
tmp++;
}
/* Eat whitespace. */
while(*tmp == ' ')
++tmp;
/*
* On HPUX there is an extra line that can be ignored.
* d.thibadeau 2001/08/09
*/
if(!strncmp("remote to", tmp, 9))
continue;
name = tmp;
/* truncate the ": ..." */
if ((tmp = strchr_m(name, ':')) != NULL)
*tmp = '\0';
/* add it to the cache */
if (!pcap_cache_add(name, NULL)) {
TALLOC_FREE(lines);
return False;
}
}
TALLOC_FREE(lines);
return True;
}
#else
/* this keeps fussy compilers happy */
void print_svid_dummy(void);
void print_svid_dummy(void) {}
#endif
|