… | |
… | |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | // C99 required |
5 | // C99 required |
6 | |
6 | |
7 | #define BENCHMARK |
7 | //#define BENCHMARK |
8 | |
8 | |
9 | #define ASN_BOOLEAN 0x01 |
9 | #define ASN_BOOLEAN 0x01 |
10 | #define ASN_INTEGER32 0x02 |
10 | #define ASN_INTEGER32 0x02 |
11 | #define ASN_OCTET_STRING 0x04 |
11 | #define ASN_OCTET_STRING 0x04 |
12 | #define ASN_NULL 0x05 |
12 | #define ASN_NULL 0x05 |
… | |
… | |
38 | |
38 | |
39 | return (SV *)cv; |
39 | return (SV *)cv; |
40 | } |
40 | } |
41 | |
41 | |
42 | static void |
42 | static void |
43 | error (const char *msg) |
43 | error (const char *errmsg) |
44 | { |
44 | { |
45 | errflag = 1; |
45 | errflag = 1; |
46 | |
46 | |
47 | printf ("<<<%s>>>\n", msg);//D |
47 | dSP; |
|
|
48 | PUSHMARK (SP); |
|
|
49 | EXTEND (SP, 2); |
|
|
50 | PUSHs (msg); |
|
|
51 | PUSHs (sv_2mortal (newSVpv (errmsg, 0))); |
|
|
52 | PUTBACK; |
|
|
53 | call_method ("_error", G_VOID | G_DISCARD); |
48 | } |
54 | } |
49 | |
55 | |
50 | static int |
56 | static int |
51 | need (int count) |
57 | need (int count) |
52 | { |
58 | { |
… | |
… | |
183 | process_unsigned32_sv (void) |
189 | process_unsigned32_sv (void) |
184 | { |
190 | { |
185 | return newSVuv ((U32)process_integer32 ()); |
191 | return newSVuv ((U32)process_integer32 ()); |
186 | } |
192 | } |
187 | |
193 | |
|
|
194 | #if IVSIZE >= 8 |
|
|
195 | |
|
|
196 | static U64TYPE |
|
|
197 | process_integer64 (void) |
|
|
198 | { |
|
|
199 | U32 length = process_length (); |
|
|
200 | |
|
|
201 | if (length <= 0) |
|
|
202 | { |
|
|
203 | error ("INTEGER64 length equal to zero"); |
|
|
204 | return 0; |
|
|
205 | } |
|
|
206 | |
|
|
207 | U8 *data = getn (length, 0); |
|
|
208 | |
|
|
209 | if (!data) |
|
|
210 | return 0; |
|
|
211 | |
|
|
212 | if (length > 9 || (length > 8 && data [0])) |
|
|
213 | { |
|
|
214 | error ("INTEGER64 length too long"); |
|
|
215 | return 0; |
|
|
216 | } |
|
|
217 | |
|
|
218 | U64TYPE res = data [0] & 0x80 ? 0xffffffffffffffff : 0; |
|
|
219 | |
|
|
220 | while (length--) |
|
|
221 | res = (res << 8) | *data++; |
|
|
222 | |
|
|
223 | return res; |
|
|
224 | } |
|
|
225 | |
|
|
226 | static SV * |
|
|
227 | process_integer64_sv (void) |
|
|
228 | { |
|
|
229 | return newSViv ((I64TYPE)process_integer64 ()); |
|
|
230 | } |
|
|
231 | |
|
|
232 | static SV * |
|
|
233 | process_unsigned64_sv (void) |
|
|
234 | { |
|
|
235 | return newSVuv ((U64TYPE)process_integer64 ()); |
|
|
236 | } |
|
|
237 | |
|
|
238 | #endif |
|
|
239 | |
188 | static SV * |
240 | static SV * |
189 | process_octet_string_sv (void) |
241 | process_octet_string_sv (void) |
190 | { |
242 | { |
191 | U32 length = process_length (); |
243 | U32 length = process_length (); |
192 | |
244 | |
… | |
… | |
218 | U32 length = process_length (); |
270 | U32 length = process_length (); |
219 | |
271 | |
220 | if (length <= 0) |
272 | if (length <= 0) |
221 | { |
273 | { |
222 | error ("OBJECT IDENTIFIER length equal to zero"); |
274 | error ("OBJECT IDENTIFIER length equal to zero"); |
223 | return ""; |
275 | return &PL_sv_undef; |
224 | } |
276 | } |
225 | |
277 | |
226 | U8 *end = cur + length; |
278 | U8 *end = cur + length; |
227 | U32 w = getb (); |
279 | U32 w = getb (); |
228 | |
280 | |
… | |
… | |
317 | av_store (av_type, type, SvREFCNT_inc (x_get_cv (cv))); |
369 | av_store (av_type, type, SvREFCNT_inc (x_get_cv (cv))); |
318 | |
370 | |
319 | void |
371 | void |
320 | set_msg (SV *msg_, SV *buf_) |
372 | set_msg (SV *msg_, SV *buf_) |
321 | CODE: |
373 | CODE: |
|
|
374 | { |
|
|
375 | if (msg) |
|
|
376 | croak ("recursive invocation of Net::SNMP::XS parser is not supported"); |
|
|
377 | |
322 | errflag = 0; |
378 | errflag = 0; |
323 | leading_dot = -1; |
379 | leading_dot = -1; |
324 | msg = SvREFCNT_inc (msg_); |
380 | msg = SvREFCNT_inc (msg_); |
325 | buf = SvPVbyte (buf_, len); |
381 | buf = SvPVbyte (buf_, len); |
326 | cur = buf; |
382 | cur = buf; |
327 | rem = len; |
383 | rem = len; |
328 | #ifdef BENCHMARK |
384 | #ifdef BENCHMARK |
329 | t1 = tstamp (); |
385 | t1 = tstamp (); |
330 | #endif |
386 | #endif |
|
|
387 | } |
331 | |
388 | |
332 | void |
389 | void |
333 | clr_msg () |
390 | clr_msg () |
334 | CODE: |
391 | CODE: |
335 | SvREFCNT_dec (msg); |
392 | SvREFCNT_dec (msg); msg = 0; |
336 | buf = cur = ""; |
393 | buf = cur = (U8 *)""; |
337 | len = rem = 0; |
394 | len = rem = 0; |
338 | #ifdef BENCHMARK |
395 | #ifdef BENCHMARK |
339 | printf ("%f\n", tstamp () - t1);//D |
396 | printf ("%f\n", tstamp () - t1);//D |
340 | #endif |
397 | #endif |
341 | |
398 | |
… | |
… | |
400 | _process_timeticks = 0 |
457 | _process_timeticks = 0 |
401 | CODE: |
458 | CODE: |
402 | RETVAL = process_unsigned32_sv (); |
459 | RETVAL = process_unsigned32_sv (); |
403 | OUTPUT: |
460 | OUTPUT: |
404 | RETVAL |
461 | RETVAL |
|
|
462 | |
|
|
463 | #if IVSIZE >= 8 |
|
|
464 | |
|
|
465 | SV * |
|
|
466 | _process_counter64 (SV *self, ...) |
|
|
467 | CODE: |
|
|
468 | RETVAL = process_unsigned64_sv (); |
|
|
469 | OUTPUT: |
|
|
470 | RETVAL |
|
|
471 | |
|
|
472 | #endif |
405 | |
473 | |
406 | SV * |
474 | SV * |
407 | _process_object_identifier (SV *self, ...) |
475 | _process_object_identifier (SV *self, ...) |
408 | CODE: |
476 | CODE: |
409 | RETVAL = process_object_identifier_sv (); |
477 | RETVAL = process_object_identifier_sv (); |