Only copy sharename up from rap_to_pjobid
[ira/wip.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
29 #ifdef AIX
30 bool aix_cache_reload(void)
31 {
32         int iEtat;
33         XFILE *pfile;
34         char *line = NULL, *p;
35         char *name = NULL;
36         TALLOC_CTX *ctx = talloc_init("aix_cache_reload");
37
38         if (!ctx) {
39                 return false;
40         }
41
42         DEBUG(5, ("reloading aix printcap cache\n"));
43
44         if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
45                 DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
46                 TALLOC_FREE(ctx);
47                 return false;
48         }
49
50         iEtat = 0;
51         /* scan qconfig file for searching <printername>:       */
52         for (;(line = fgets_slash(NULL, 1024, pfile)); free(line)) {
53                 if (*line == '*' || *line == 0)
54                         continue;
55
56                 switch (iEtat) {
57                 case 0: /* locate an entry */
58                         if (*line == '\t' || *line == ' ')
59                                 continue;
60
61                         if ((p = strchr_m(line, ':'))) {
62                                 char *saveptr;
63                                 *p = '\0';
64                                 p = strtok_r(line, ":", &saveptr);
65                                 if (strcmp(p, "bsh") != 0) {
66                                         name = talloc_strdup(ctx, p);
67                                         if (!name) {
68                                                 SAFE_FREE(line);
69                                                 x_fclose(pfile);
70                                                 TALLOC_FREE(ctx);
71                                                 return false;
72                                         }
73                                         iEtat = 1;
74                                         continue;
75                                 }
76                          }
77                          break;
78
79                 case 1: /* scanning device stanza */
80                         if (*line == '*' || *line == 0)
81                                 continue;
82
83                         if (*line != '\t' && *line != ' ') {
84                                 /* name is found without stanza device  */
85                                 /* probably a good printer ???          */
86                                 iEtat = 0;
87                                 if (!pcap_cache_add(name, NULL)) {
88                                         SAFE_FREE(line);
89                                         x_fclose(pfile);
90                                         TALLOC_FREE(ctx);
91                                         return false;
92                                 }
93                                 continue;
94                         }
95
96                         if (strstr_m(line, "backend")) {
97                                 /* it's a device, not a virtual printer */
98                                 iEtat = 0;
99                         } else if (strstr_m(line, "device")) {
100                                 /* it's a good virtual printer */
101                                 iEtat = 0;
102                                 if (!pcap_cache_add(name, NULL)) {
103                                         SAFE_FREE(line);
104                                         x_fclose(pfile);
105                                         TALLOC_FREE(ctx);
106                                         return false;
107                                 }
108                                 continue;
109                         }
110                         break;
111                 }
112         }
113
114         x_fclose(pfile);
115         TALLOC_FREE(ctx);
116         return true;
117 }
118
119 #else
120 /* this keeps fussy compilers happy */
121  void print_aix_dummy(void);
122  void print_aix_dummy(void) {}
123 #endif /* AIX */