s3: Filenames: Add uint32_t flags parameter to synthetic_smb_fname().
[garming/samba-autobuild/.git] / source3 / printing / print_aix.c
1 /* 
2    AIX-specific printcap loading
3    Copyright (C) Jean-Pierre.Boulard@univ-rennes1.fr      1996
4
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.
9    
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.
14    
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/>.
17 */
18
19 /*
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
25  */
26
27 #include "includes.h"
28 #include "system/filesys.h"
29 #include "printing/pcap.h"
30
31 #ifdef AIX
32 bool aix_cache_reload(struct pcap_cache **_pcache)
33 {
34         int iEtat;
35         XFILE *pfile;
36         char *line = NULL, *p;
37         char *name = NULL;
38         struct pcap_cache *pcache = NULL;
39         TALLOC_CTX *ctx = talloc_init("aix_cache_reload");
40
41         if (!ctx) {
42                 return false;
43         }
44
45         DEBUG(5, ("reloading aix printcap cache\n"));
46
47         if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
48                 DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
49                 TALLOC_FREE(ctx);
50                 return false;
51         }
52
53         iEtat = 0;
54         /* scan qconfig file for searching <printername>:       */
55         for (;(line = fgets_slash(NULL, 1024, pfile)); free(line)) {
56                 bool ok;
57
58                 if (*line == '*' || *line == 0)
59                         continue;
60
61                 switch (iEtat) {
62                 case 0: /* locate an entry */
63                         if (*line == '\t' || *line == ' ')
64                                 continue;
65
66                         if ((p = strchr_m(line, ':'))) {
67                                 char *saveptr;
68                                 *p = '\0';
69                                 p = strtok_r(line, ":", &saveptr);
70                                 if (strcmp(p, "bsh") != 0) {
71                                         name = talloc_strdup(ctx, p);
72                                         if (!name) {
73                                                 pcap_cache_destroy_specific(&pcache);
74                                                 SAFE_FREE(line);
75                                                 x_fclose(pfile);
76                                                 TALLOC_FREE(ctx);
77                                                 return false;
78                                         }
79                                         iEtat = 1;
80                                         continue;
81                                 }
82                          }
83                          break;
84
85                 case 1: /* scanning device stanza */
86                         if (*line == '*' || *line == 0)
87                                 continue;
88
89                         if (*line != '\t' && *line != ' ') {
90                                 /* name is found without stanza device  */
91                                 /* probably a good printer ???          */
92                                 iEtat = 0;
93                                 ok = pcap_cache_add_specific(&pcache,
94                                                              name, NULL, NULL);
95                                 if (!ok) {
96                                         pcap_cache_destroy_specific(&pcache);
97                                         SAFE_FREE(line);
98                                         x_fclose(pfile);
99                                         TALLOC_FREE(ctx);
100                                         return false;
101                                 }
102                                 continue;
103                         }
104
105                         if (strstr_m(line, "backend")) {
106                                 /* it's a device, not a virtual printer */
107                                 iEtat = 0;
108                         } else if (strstr_m(line, "device")) {
109                                 /* it's a good virtual printer */
110                                 iEtat = 0;
111                                 ok = pcap_cache_add_specific(&pcache,
112                                                              name, NULL, NULL);
113                                 if (!ok) {
114                                         pcap_cache_destroy_specific(&pcache);
115                                         SAFE_FREE(line);
116                                         x_fclose(pfile);
117                                         TALLOC_FREE(ctx);
118                                         return false;
119                                 }
120                                 continue;
121                         }
122                         break;
123                 }
124         }
125
126         *_pcache = pcache;
127         x_fclose(pfile);
128         TALLOC_FREE(ctx);
129         return true;
130 }
131
132 #else
133 /* this keeps fussy compilers happy */
134  void print_aix_dummy(void);
135  void print_aix_dummy(void) {}
136 #endif /* AIX */