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