s3: Lift the smbd_messaging_context from check_published_printers
[Samba/gbeck.git] / source3 / printing / print_aix.c
blob1b236106280cc98dca6184b7b3b5500884c705c4
1 /*
2 AIX-specific printcap loading
3 Copyright (C) Jean-Pierre.Boulard@univ-rennes1.fr 1996
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * This module implements AIX-specific printcap loading. Most of the code
21 * here was originally provided by Jean-Pierre.Boulard@univ-rennes1.fr in
22 * the Samba 1.9.14 release, and was formerly contained in pcap.c. It has
23 * been moved here and condensed as part of a larger effort to clean up and
24 * simplify the printcap code. -- Rob Foehl, 2004/12/06
27 #include "includes.h"
28 #include "printing/pcap.h"
30 #ifdef AIX
31 bool aix_cache_reload(void)
33 int iEtat;
34 XFILE *pfile;
35 char *line = NULL, *p;
36 char *name = NULL;
37 TALLOC_CTX *ctx = talloc_init("aix_cache_reload");
39 if (!ctx) {
40 return false;
43 DEBUG(5, ("reloading aix printcap cache\n"));
45 if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
46 DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
47 TALLOC_FREE(ctx);
48 return false;
51 iEtat = 0;
52 /* scan qconfig file for searching <printername>: */
53 for (;(line = fgets_slash(NULL, 1024, pfile)); free(line)) {
54 if (*line == '*' || *line == 0)
55 continue;
57 switch (iEtat) {
58 case 0: /* locate an entry */
59 if (*line == '\t' || *line == ' ')
60 continue;
62 if ((p = strchr_m(line, ':'))) {
63 char *saveptr;
64 *p = '\0';
65 p = strtok_r(line, ":", &saveptr);
66 if (strcmp(p, "bsh") != 0) {
67 name = talloc_strdup(ctx, p);
68 if (!name) {
69 SAFE_FREE(line);
70 x_fclose(pfile);
71 TALLOC_FREE(ctx);
72 return false;
74 iEtat = 1;
75 continue;
78 break;
80 case 1: /* scanning device stanza */
81 if (*line == '*' || *line == 0)
82 continue;
84 if (*line != '\t' && *line != ' ') {
85 /* name is found without stanza device */
86 /* probably a good printer ??? */
87 iEtat = 0;
88 if (!pcap_cache_add(name, NULL)) {
89 SAFE_FREE(line);
90 x_fclose(pfile);
91 TALLOC_FREE(ctx);
92 return false;
94 continue;
97 if (strstr_m(line, "backend")) {
98 /* it's a device, not a virtual printer */
99 iEtat = 0;
100 } else if (strstr_m(line, "device")) {
101 /* it's a good virtual printer */
102 iEtat = 0;
103 if (!pcap_cache_add(name, NULL)) {
104 SAFE_FREE(line);
105 x_fclose(pfile);
106 TALLOC_FREE(ctx);
107 return false;
109 continue;
111 break;
115 x_fclose(pfile);
116 TALLOC_FREE(ctx);
117 return true;
120 #else
121 /* this keeps fussy compilers happy */
122 void print_aix_dummy(void);
123 void print_aix_dummy(void) {}
124 #endif /* AIX */