1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 
5 #include <cups/cups.h>
6 #include <cups/http.h>
7 #include <cups/ipp.h>
8 #include <cups/language.h>
9 #include <cups/ppd.h>
10 
11 static int
not_here(char * s)12 not_here(char *s)
13 {
14     croak("%s not implemented on this architecture", s);
15     return -1;
16 }
17 
18 static double
constant_PPD_M(char * name,int len,int arg)19 constant_PPD_M(char *name, int len, int arg)
20 {
21     if (5 + 3 >= len ) {
22 	errno = EINVAL;
23 	return 0;
24     }
25     switch (name[5 + 3]) {
26     case 'L':
27 	if (strEQ(name + 5, "AX_LINE")) {	/* PPD_M removed */
28 #ifdef PPD_MAX_LINE
29 	    return PPD_MAX_LINE;
30 #else
31 	    goto not_there;
32 #endif
33 	}
34     case 'N':
35 	if (strEQ(name + 5, "AX_NAME")) {	/* PPD_M removed */
36 #ifdef PPD_MAX_NAME
37 	    return PPD_MAX_NAME;
38 #else
39 	    goto not_there;
40 #endif
41 	}
42     case 'T':
43 	if (strEQ(name + 5, "AX_TEXT")) {	/* PPD_M removed */
44 #ifdef PPD_MAX_TEXT
45 	    return PPD_MAX_TEXT;
46 #else
47 	    goto not_there;
48 #endif
49 	}
50     }
51     errno = EINVAL;
52     return 0;
53 
54 not_there:
55     errno = ENOENT;
56     return 0;
57 }
58 
59 static double
constant_P(char * name,int len,int arg)60 constant_P(char *name, int len, int arg)
61 {
62     if (1 + 3 >= len ) {
63 	errno = EINVAL;
64 	return 0;
65     }
66     switch (name[1 + 3]) {
67     case 'M':
68 	if (!strnEQ(name + 1,"PD_", 3))
69 	    break;
70 	return constant_PPD_M(name, len, arg);
71     case 'V':
72 	if (strEQ(name + 1, "PD_VERSION")) {	/* P removed */
73 #ifdef PPD_VERSION
74 	    return PPD_VERSION;
75 #else
76 	    goto not_there;
77 #endif
78 	}
79     }
80     errno = EINVAL;
81     return 0;
82 
83 not_there:
84     errno = ENOENT;
85     return 0;
86 }
87 
88 static double
constant_H(char * name,int len,int arg)89 constant_H(char *name, int len, int arg)
90 {
91     if (1 + 8 >= len ) {
92 	errno = EINVAL;
93 	return 0;
94     }
95     switch (name[1 + 8]) {
96     case 'B':
97 	if (strEQ(name + 1, "TTP_MAX_BUFFER")) {	/* H removed */
98 #ifdef HTTP_MAX_BUFFER
99 	    return HTTP_MAX_BUFFER;
100 #else
101 	    goto not_there;
102 #endif
103 	}
104     case 'H':
105 	if (strEQ(name + 1, "TTP_MAX_HOST")) {	/* H removed */
106 #ifdef HTTP_MAX_HOST
107 	    return HTTP_MAX_HOST;
108 #else
109 	    goto not_there;
110 #endif
111 	}
112     case 'U':
113 	if (strEQ(name + 1, "TTP_MAX_URI")) {	/* H removed */
114 #ifdef HTTP_MAX_URI
115 	    return HTTP_MAX_URI;
116 #else
117 	    goto not_there;
118 #endif
119 	}
120     case 'V':
121 	if (strEQ(name + 1, "TTP_MAX_VALUE")) {	/* H removed */
122 #ifdef HTTP_MAX_VALUE
123 	    return HTTP_MAX_VALUE;
124 #else
125 	    goto not_there;
126 #endif
127 	}
128     }
129     errno = EINVAL;
130     return 0;
131 
132 not_there:
133     errno = ENOENT;
134     return 0;
135 }
136 
137 static double
constant_IPP_M(char * name,int len,int arg)138 constant_IPP_M(char *name, int len, int arg)
139 {
140     if (5 + 3 >= len ) {
141 	errno = EINVAL;
142 	return 0;
143     }
144     switch (name[5 + 3]) {
145     case 'N':
146 	if (strEQ(name + 5, "AX_NAME")) {	/* IPP_M removed */
147 #ifdef IPP_MAX_NAME
148 	    return IPP_MAX_NAME;
149 #else
150 	    goto not_there;
151 #endif
152 	}
153     case 'V':
154 	if (strEQ(name + 5, "AX_VALUES")) {	/* IPP_M removed */
155 #ifdef IPP_MAX_VALUES
156 	    return IPP_MAX_VALUES;
157 #else
158 	    goto not_there;
159 #endif
160 	}
161     }
162     errno = EINVAL;
163     return 0;
164 
165 not_there:
166     errno = ENOENT;
167     return 0;
168 }
169 
170 static double
constant_I(char * name,int len,int arg)171 constant_I(char *name, int len, int arg)
172 {
173     if (1 + 3 >= len ) {
174 	errno = EINVAL;
175 	return 0;
176     }
177     switch (name[1 + 3]) {
178     case 'M':
179 	if (!strnEQ(name + 1,"PP_", 3))
180 	    break;
181 	return constant_IPP_M(name, len, arg);
182     case 'P':
183 	if (strEQ(name + 1, "PP_PORT")) {	/* I removed */
184 #ifdef IPP_PORT
185 	    return IPP_PORT;
186 #else
187 	    goto not_there;
188 #endif
189 	}
190     }
191     errno = EINVAL;
192     return 0;
193 
194 not_there:
195     errno = ENOENT;
196     return 0;
197 }
198 
199 static double
constant_C(char * name,int len,int arg)200 constant_C(char *name, int len, int arg)
201 {
202     if (1 + 4 >= len ) {
203 	errno = EINVAL;
204 	return 0;
205     }
206     switch (name[1 + 4]) {
207     case 'D':
208 	if (strEQ(name + 1, "UPS_DATE_ANY")) {	/* C removed */
209 #ifdef CUPS_DATE_ANY
210 	    return CUPS_DATE_ANY;
211 #else
212 	    goto not_there;
213 #endif
214 	}
215     case 'V':
216 	if (strEQ(name + 1, "UPS_VERSION")) {	/* C removed */
217 #ifdef CUPS_VERSION
218 	    return CUPS_VERSION;
219 #else
220 	    goto not_there;
221 #endif
222 	}
223     }
224     errno = EINVAL;
225     return 0;
226 
227 not_there:
228     errno = ENOENT;
229     return 0;
230 }
231 
232 static double
constant(char * name,int len,int arg)233 constant(char *name, int len, int arg)
234 {
235     errno = 0;
236     switch (name[0 + 0]) {
237     case 'C':
238 	return constant_C(name, len, arg);
239     case 'H':
240 	return constant_H(name, len, arg);
241     case 'I':
242 	return constant_I(name, len, arg);
243     case 'P':
244 	return constant_P(name, len, arg);
245     }
246     errno = EINVAL;
247     return 0;
248 
249 not_there:
250     errno = ENOENT;
251     return 0;
252 }
253 
254 
255 MODULE = CUPS		PACKAGE = CUPS
256 
257 
258 double
259 constant(sv,arg)
260     PREINIT:
261 	STRLEN		len;
262     INPUT:
263 	SV *		sv
264 	char *		s = SvPV(sv, len);
265 	int		arg
266     CODE:
267 	RETVAL = constant(s,len,arg);
268     OUTPUT:
269 	RETVAL
270 
271