added files
[bcm963xx.git] / userapps / opensource / net-snmp / perl / ASN / ASN.xs
1 /* -*- C -*- */
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/library/asn1.h>
8 #include <net-snmp/library/snmp_impl.h>
9
10 static int
11 not_here(char *s)
12 {
13     croak("%s not implemented on this architecture", s);
14     return -1;
15 }
16
17 static double
18 constant_ASN_O(char *name, int len, int arg)
19 {
20     switch (name[5 + 0]) {
21     case 'B':
22         if (strEQ(name + 5, "BJECT_ID")) {      /* ASN_O removed */
23 #ifdef ASN_OBJECT_ID
24             return ASN_OBJECT_ID;
25 #else
26             goto not_there;
27 #endif
28         }
29     case 'C':
30         if (strEQ(name + 5, "CTET_STR")) {      /* ASN_O removed */
31 #ifdef ASN_OCTET_STR
32             return ASN_OCTET_STR;
33 #else
34             goto not_there;
35 #endif
36         }
37     case 'P':
38         if (strEQ(name + 5, "PAQUE")) { /* ASN_O removed */
39 #ifdef ASN_OPAQUE
40             return ASN_OPAQUE;
41 #else
42             goto not_there;
43 #endif
44         }
45     }
46     errno = EINVAL;
47     return 0;
48
49 not_there:
50     errno = ENOENT;
51     return 0;
52 }
53
54 static double
55 constant_ASN_B(char *name, int len, int arg)
56 {
57     switch (name[5 + 0]) {
58     case 'I':
59         if (strEQ(name + 5, "IT_STR")) {        /* ASN_B removed */
60 #ifdef ASN_BIT_STR
61             return ASN_BIT_STR;
62 #else
63             goto not_there;
64 #endif
65         }
66     case 'O':
67         if (strEQ(name + 5, "OOLEAN")) {        /* ASN_B removed */
68 #ifdef ASN_BOOLEAN
69             return ASN_BOOLEAN;
70 #else
71             goto not_there;
72 #endif
73         }
74     }
75     errno = EINVAL;
76     return 0;
77
78 not_there:
79     errno = ENOENT;
80     return 0;
81 }
82
83 static double
84 constant_ASN_S(char *name, int len, int arg)
85 {
86     if (5 + 1 >= len ) {
87         errno = EINVAL;
88         return 0;
89     }
90     switch (name[5 + 1]) {
91     case 'Q':
92         if (strEQ(name + 5, "EQUENCE")) {       /* ASN_S removed */
93 #ifdef ASN_SEQUENCE
94             return ASN_SEQUENCE;
95 #else
96             goto not_there;
97 #endif
98         }
99     case 'T':
100         if (strEQ(name + 5, "ET")) {    /* ASN_S removed */
101 #ifdef ASN_SET
102             return ASN_SET;
103 #else
104             goto not_there;
105 #endif
106         }
107     }
108     errno = EINVAL;
109     return 0;
110
111 not_there:
112     errno = ENOENT;
113     return 0;
114 }
115
116 static double
117 constant_ASN_C(char *name, int len, int arg)
118 {
119     if (5 + 6 > len ) {
120         errno = EINVAL;
121         return 0;
122     }
123     switch (name[5 + 6]) {
124     case '\0':
125         if (strEQ(name + 5, "OUNTER")) {        /* ASN_C removed */
126 #ifdef ASN_COUNTER
127             return ASN_COUNTER;
128 #else
129             goto not_there;
130 #endif
131         }
132     case '6':
133         if (strEQ(name + 5, "OUNTER64")) {      /* ASN_C removed */
134 #ifdef ASN_COUNTER64
135             return ASN_COUNTER64;
136 #else
137             goto not_there;
138 #endif
139         }
140     }
141     errno = EINVAL;
142     return 0;
143
144 not_there:
145     errno = ENOENT;
146     return 0;
147 }
148
149 static double
150 constant_ASN_U(char *name, int len, int arg)
151 {
152     if (5 + 7 > len ) {
153         errno = EINVAL;
154         return 0;
155     }
156     switch (name[5 + 7]) {
157     case '\0':
158         if (strEQ(name + 5, "NSIGNED")) {       /* ASN_U removed */
159 #ifdef ASN_UNSIGNED
160             return ASN_UNSIGNED;
161 #else
162             goto not_there;
163 #endif
164         }
165     case '6':
166         if (strEQ(name + 5, "NSIGNED64")) {     /* ASN_U removed */
167 #ifdef ASN_UNSIGNED64
168             return ASN_UNSIGNED64;
169 #else
170             goto not_there;
171 #endif
172         }
173     }
174     errno = EINVAL;
175     return 0;
176
177 not_there:
178     errno = ENOENT;
179     return 0;
180 }
181
182 static double
183 constant_ASN_IN(char *name, int len, int arg)
184 {
185     if (6 + 5 > len ) {
186         errno = EINVAL;
187         return 0;
188     }
189     switch (name[6 + 5]) {
190     case '\0':
191         if (strEQ(name + 6, "TEGER")) { /* ASN_IN removed */
192 #ifdef ASN_INTEGER
193             return ASN_INTEGER;
194 #else
195             goto not_there;
196 #endif
197         }
198     case '6':
199         if (strEQ(name + 6, "TEGER64")) {       /* ASN_IN removed */
200 #ifdef ASN_INTEGER64
201             return ASN_INTEGER64;
202 #else
203             goto not_there;
204 #endif
205         }
206     }
207     errno = EINVAL;
208     return 0;
209
210 not_there:
211     errno = ENOENT;
212     return 0;
213 }
214
215 static double
216 constant_ASN_I(char *name, int len, int arg)
217 {
218     switch (name[5 + 0]) {
219     case 'N':
220         return constant_ASN_IN(name, len, arg);
221     case 'P':
222         if (strEQ(name + 5, "PADDRESS")) {      /* ASN_I removed */
223 #ifdef ASN_IPADDRESS
224             return ASN_IPADDRESS;
225 #else
226             goto not_there;
227 #endif
228         }
229     }
230     errno = EINVAL;
231     return 0;
232
233 not_there:
234     errno = ENOENT;
235     return 0;
236 }
237
238 static double
239 constant(char *name, int len, int arg)
240 {
241     errno = 0;
242     if (0 + 4 >= len ) {
243         errno = EINVAL;
244         return 0;
245     }
246     switch (name[0 + 4]) {
247     case 'A':
248         if (strEQ(name + 0, "ASN_APPLICATION")) {       /*  removed */
249 #ifdef ASN_APPLICATION
250             return ASN_APPLICATION;
251 #else
252             goto not_there;
253 #endif
254         }
255     case 'B':
256         if (!strnEQ(name + 0,"ASN_", 4))
257             break;
258         return constant_ASN_B(name, len, arg);
259     case 'C':
260         if (!strnEQ(name + 0,"ASN_", 4))
261             break;
262         return constant_ASN_C(name, len, arg);
263     case 'D':
264         if (strEQ(name + 0, "ASN_DOUBLE")) {    /*  removed */
265 #ifdef ASN_DOUBLE
266             return ASN_DOUBLE;
267 #else
268             goto not_there;
269 #endif
270         }
271     case 'F':
272         if (strEQ(name + 0, "ASN_FLOAT")) {     /*  removed */
273 #ifdef ASN_FLOAT
274             return ASN_FLOAT;
275 #else
276             goto not_there;
277 #endif
278         }
279     case 'G':
280         if (strEQ(name + 0, "ASN_GAUGE")) {     /*  removed */
281 #ifdef ASN_GAUGE
282             return ASN_GAUGE;
283 #else
284             goto not_there;
285 #endif
286         }
287     case 'I':
288         if (!strnEQ(name + 0,"ASN_", 4))
289             break;
290         return constant_ASN_I(name, len, arg);
291     case 'N':
292         if (strEQ(name + 0, "ASN_NULL")) {      /*  removed */
293 #ifdef ASN_NULL
294             return ASN_NULL;
295 #else
296             goto not_there;
297 #endif
298         }
299     case 'O':
300         if (!strnEQ(name + 0,"ASN_", 4))
301             break;
302         return constant_ASN_O(name, len, arg);
303     case 'S':
304         if (!strnEQ(name + 0,"ASN_", 4))
305             break;
306         return constant_ASN_S(name, len, arg);
307     case 'T':
308         if (strEQ(name + 0, "ASN_TIMETICKS")) { /*  removed */
309 #ifdef ASN_TIMETICKS
310             return ASN_TIMETICKS;
311 #else
312             goto not_there;
313 #endif
314         }
315     case 'U':
316         if (!strnEQ(name + 0,"ASN_", 4))
317             break;
318         return constant_ASN_U(name, len, arg);
319     }
320     errno = EINVAL;
321     return 0;
322
323 not_there:
324     errno = ENOENT;
325     return 0;
326 }
327
328
329 MODULE = NetSNMP::ASN           PACKAGE = NetSNMP::ASN          
330
331
332 double
333 constant(sv,arg)
334     PREINIT:
335         STRLEN          len;
336     INPUT:
337         SV *            sv
338         char *          s = SvPV(sv, len);
339         int             arg
340     CODE:
341         RETVAL = constant(s,len,arg);
342     OUTPUT:
343         RETVAL
344