… | |
… | |
21 | |
21 | |
22 | #define MAX_OID_STRLEN 4096 |
22 | #define MAX_OID_STRLEN 4096 |
23 | |
23 | |
24 | #define HAVE_VERSIONSORT defined (_GNU_SOURCE) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 |
24 | #define HAVE_VERSIONSORT defined (_GNU_SOURCE) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 |
25 | |
25 | |
|
|
26 | static SV *cur_bufobj; |
26 | static SV *msg; |
27 | static SV *msg; |
27 | static int errflag, leading_dot; |
28 | static int errflag, leading_dot; |
28 | static U8 *buf, *cur; |
29 | static U8 *buf, *cur; |
29 | static STRLEN len, rem; |
30 | static STRLEN len, rem; |
|
|
31 | |
|
|
32 | typedef SV *BUFOBJ; |
|
|
33 | |
|
|
34 | ///////////////////////////////////////////////////////////////////////////// |
|
|
35 | |
|
|
36 | #if 0 |
|
|
37 | if (msg) |
|
|
38 | croak ("recursive invocation of Net::SNMP::XS parser is not supported"); |
|
|
39 | |
|
|
40 | |
|
|
41 | void |
|
|
42 | clr_msg () |
|
|
43 | CODE: |
|
|
44 | SvREFCNT_dec (msg); msg = 0; |
|
|
45 | buf = cur = (U8 *)""; |
|
|
46 | len = rem = 0; |
|
|
47 | #endif |
|
|
48 | |
|
|
49 | static void |
|
|
50 | switch_bufobj (BUFOBJ neu) |
|
|
51 | { |
|
|
52 | // serialise our state back |
|
|
53 | if (msg && SvROK (msg)) |
|
|
54 | { |
|
|
55 | SV *idx_sv = *hv_fetch ((HV *)cur_bufobj, "_index" , sizeof ("_index" ) - 1, 1); |
|
|
56 | sv_setiv (idx_sv, cur - buf); |
|
|
57 | } |
|
|
58 | |
|
|
59 | SvREFCNT_dec (msg); |
|
|
60 | msg = newSVsv (neu); |
|
|
61 | cur_bufobj = SvRV (msg); |
|
|
62 | sv_rvweaken (msg); |
|
|
63 | |
|
|
64 | SV *bufsv = *hv_fetch ((HV *)cur_bufobj, "_buffer", sizeof ("_buffer") - 1, 1); |
|
|
65 | IV index = SvIV (*hv_fetch ((HV *)cur_bufobj, "_index" , sizeof ("_index" ) - 1, 1)); |
|
|
66 | |
|
|
67 | errflag = 0; |
|
|
68 | leading_dot = -1; |
|
|
69 | buf = SvPVbyte (bufsv, len); |
|
|
70 | cur = buf + index; |
|
|
71 | rem = len - index; |
|
|
72 | } |
|
|
73 | |
|
|
74 | ///////////////////////////////////////////////////////////////////////////// |
30 | |
75 | |
31 | static SV * |
76 | static SV * |
32 | x_get_cv (SV *cb_sv) |
77 | x_get_cv (SV *cb_sv) |
33 | { |
78 | { |
34 | HV *st; |
79 | HV *st; |
… | |
… | |
283 | U8 *end = cur + length; |
328 | U8 *end = cur + length; |
284 | U32 w = getb (); |
329 | U32 w = getb (); |
285 | |
330 | |
286 | static char oid[MAX_OID_STRLEN]; // must be static |
331 | static char oid[MAX_OID_STRLEN]; // must be static |
287 | char *app = oid; |
332 | char *app = oid; |
|
|
333 | |
|
|
334 | if (leading_dot < 0) |
|
|
335 | leading_dot = SvTRUE (*hv_fetch ((HV *)SvRV (msg), "_leading_dot", sizeof ("_leading_dot") - 1, 1)); |
288 | |
336 | |
289 | *app = '.'; app += ! ! leading_dot; |
337 | *app = '.'; app += ! ! leading_dot; |
290 | app = write_uv (app, (U8)w / 40); |
338 | app = write_uv (app, (U8)w / 40); |
291 | *app++ = '.'; |
339 | *app++ = '.'; |
292 | app = write_uv (app, (U8)w % 40); |
340 | app = write_uv (app, (U8)w % 40); |
… | |
… | |
392 | av_store (av_type, type, SvREFCNT_inc (x_get_cv (cv))); |
440 | av_store (av_type, type, SvREFCNT_inc (x_get_cv (cv))); |
393 | |
441 | |
394 | void |
442 | void |
395 | set_msg (SV *msg_, SV *buf_) |
443 | set_msg (SV *msg_, SV *buf_) |
396 | CODE: |
444 | CODE: |
397 | { |
|
|
398 | if (msg) |
|
|
399 | croak ("recursive invocation of Net::SNMP::XS parser is not supported"); |
|
|
400 | |
|
|
401 | errflag = 0; |
|
|
402 | leading_dot = -1; |
|
|
403 | msg = SvREFCNT_inc (msg_); |
|
|
404 | buf = SvPVbyte (buf_, len); |
|
|
405 | cur = buf; |
|
|
406 | rem = len; |
|
|
407 | #ifdef BENCHMARK |
|
|
408 | t1 = tstamp (); |
|
|
409 | #endif |
|
|
410 | } |
|
|
411 | |
445 | |
412 | void |
446 | void |
413 | clr_msg () |
447 | clr_msg () |
414 | CODE: |
448 | CODE: |
415 | SvREFCNT_dec (msg); msg = 0; |
|
|
416 | buf = cur = (U8 *)""; |
|
|
417 | len = rem = 0; |
|
|
418 | #ifdef BENCHMARK |
|
|
419 | printf ("%f\n", tstamp () - t1);//D |
|
|
420 | #endif |
|
|
421 | |
449 | |
422 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::Message |
450 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::Message |
423 | |
451 | |
424 | void |
452 | void |
425 | _buffer_get (SV *self, int count = -1) |
453 | _buffer_get (BUFOBJ self, int count = -1) |
426 | PPCODE: |
454 | PPCODE: |
427 | { |
455 | { |
428 | // grrr. |
456 | // grrr. |
429 | if (count < 0) |
457 | if (count < 0) |
430 | { |
458 | { |
… | |
… | |
441 | if (data) |
469 | if (data) |
442 | XPUSHs (sv_2mortal (newSVpvn (data, count))); |
470 | XPUSHs (sv_2mortal (newSVpvn (data, count))); |
443 | } |
471 | } |
444 | |
472 | |
445 | U32 |
473 | U32 |
446 | index (SV *self, int ndx = -1) |
474 | index (BUFOBJ self, int ndx = -1) |
447 | CODE: |
475 | CODE: |
448 | { |
476 | { |
449 | if (ndx >= 0 && ndx < len) |
477 | if (ndx >= 0 && ndx < len) |
450 | { |
478 | { |
451 | cur = buf + ndx; |
479 | cur = buf + ndx; |
… | |
… | |
456 | } |
484 | } |
457 | OUTPUT: |
485 | OUTPUT: |
458 | RETVAL |
486 | RETVAL |
459 | |
487 | |
460 | U32 |
488 | U32 |
461 | _process_length (SV *self, ...) |
489 | _process_length (BUFOBJ self, ...) |
462 | ALIAS: |
490 | ALIAS: |
463 | _process_sequence = 0 |
491 | _process_sequence = 0 |
464 | CODE: |
492 | CODE: |
465 | RETVAL = process_length (); |
493 | RETVAL = process_length (); |
466 | OUTPUT: |
494 | OUTPUT: |
467 | RETVAL |
495 | RETVAL |
468 | |
496 | |
469 | SV * |
497 | SV * |
470 | _process_integer32 (SV *self, ...) |
498 | _process_integer32 (BUFOBJ self, ...) |
471 | CODE: |
499 | CODE: |
472 | RETVAL = process_integer32_sv (); |
500 | RETVAL = process_integer32_sv (); |
473 | OUTPUT: |
501 | OUTPUT: |
474 | RETVAL |
502 | RETVAL |
475 | |
503 | |
476 | SV * |
504 | SV * |
477 | _process_counter (SV *self, ...) |
505 | _process_counter (BUFOBJ self, ...) |
478 | ALIAS: |
506 | ALIAS: |
479 | _process_gauge = 0 |
507 | _process_gauge = 0 |
480 | _process_timeticks = 0 |
508 | _process_timeticks = 0 |
481 | CODE: |
509 | CODE: |
482 | RETVAL = process_unsigned32_sv (); |
510 | RETVAL = process_unsigned32_sv (); |
… | |
… | |
484 | RETVAL |
512 | RETVAL |
485 | |
513 | |
486 | #if IVSIZE >= 8 |
514 | #if IVSIZE >= 8 |
487 | |
515 | |
488 | SV * |
516 | SV * |
489 | _process_counter64 (SV *self, ...) |
517 | _process_counter64 (BUFOBJ self, ...) |
490 | CODE: |
518 | CODE: |
491 | RETVAL = process_unsigned64_sv (); |
519 | RETVAL = process_unsigned64_sv (); |
492 | OUTPUT: |
520 | OUTPUT: |
493 | RETVAL |
521 | RETVAL |
494 | |
522 | |
495 | #endif |
523 | #endif |
496 | |
524 | |
497 | SV * |
525 | SV * |
498 | _process_object_identifier (SV *self, ...) |
526 | _process_object_identifier (BUFOBJ self, ...) |
499 | CODE: |
527 | CODE: |
500 | RETVAL = process_object_identifier_sv (); |
528 | RETVAL = process_object_identifier_sv (); |
501 | OUTPUT: |
529 | OUTPUT: |
502 | RETVAL |
530 | RETVAL |
503 | |
531 | |
504 | SV * |
532 | SV * |
505 | _process_octet_string (SV *self, ...) |
533 | _process_octet_string (BUFOBJ self, ...) |
506 | ALIAS: |
534 | ALIAS: |
507 | _process_opaque = 0 |
535 | _process_opaque = 0 |
508 | CODE: |
536 | CODE: |
509 | RETVAL = process_octet_string_sv (); |
537 | RETVAL = process_octet_string_sv (); |
510 | OUTPUT: |
538 | OUTPUT: |
511 | RETVAL |
539 | RETVAL |
512 | |
540 | |
513 | SV * |
541 | SV * |
514 | _process_ipaddress (SV *self, ...) |
542 | _process_ipaddress (BUFOBJ self, ...) |
515 | CODE: |
543 | CODE: |
516 | { |
544 | { |
517 | U32 length = process_length (); |
545 | U32 length = process_length (); |
518 | if (length != 4) |
546 | if (length != 4) |
519 | { |
547 | { |
… | |
… | |
526 | } |
554 | } |
527 | OUTPUT: |
555 | OUTPUT: |
528 | RETVAL |
556 | RETVAL |
529 | |
557 | |
530 | SV * |
558 | SV * |
531 | process (SV *self, SV *expected = &PL_sv_undef, SV *found = 0) |
559 | process (BUFOBJ self, SV *expected = &PL_sv_undef, SV *found = 0) |
532 | CODE: |
560 | CODE: |
533 | { |
561 | { |
534 | int type; |
562 | int type; |
535 | |
563 | |
536 | RETVAL = process_sv (&type); |
564 | RETVAL = process_sv (&type); |
… | |
… | |
545 | RETVAL |
573 | RETVAL |
546 | |
574 | |
547 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::PDU |
575 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::PDU |
548 | |
576 | |
549 | SV * |
577 | SV * |
550 | _process_var_bind_list (SV *self) |
578 | _process_var_bind_list (BUFOBJ self) |
551 | CODE: |
579 | CODE: |
552 | { |
580 | { |
553 | if (get8 () != ASN_SEQUENCE) |
581 | if (get8 () != ASN_SEQUENCE) |
554 | error ("SEQUENCE expected at beginning of VarBindList"); |
582 | error ("SEQUENCE expected at beginning of VarBindList"); |
555 | int seqlen = process_length (); |
583 | int seqlen = process_length (); |
… | |
… | |
557 | |
585 | |
558 | HV *list = newHV (); |
586 | HV *list = newHV (); |
559 | AV *names = newAV (); |
587 | AV *names = newAV (); |
560 | HV *types = newHV (); |
588 | HV *types = newHV (); |
561 | |
589 | |
562 | hv_store ((HV *)SvRV (self), "_var_bind_list" , sizeof ("_var_bind_list" ) - 1, newRV_noinc ((SV *)list ), 0); |
590 | hv_store ((HV *)cur_bufobj, "_var_bind_list" , sizeof ("_var_bind_list" ) - 1, newRV_noinc ((SV *)list ), 0); |
563 | hv_store ((HV *)SvRV (self), "_var_bind_names", sizeof ("_var_bind_names") - 1, newRV_noinc ((SV *)names), 0); |
591 | hv_store ((HV *)cur_bufobj, "_var_bind_names", sizeof ("_var_bind_names") - 1, newRV_noinc ((SV *)names), 0); |
564 | hv_store ((HV *)SvRV (self), "_var_bind_types", sizeof ("_var_bind_types") - 1, newRV_noinc ((SV *)types), 0); |
592 | hv_store ((HV *)cur_bufobj, "_var_bind_types", sizeof ("_var_bind_types") - 1, newRV_noinc ((SV *)types), 0); |
565 | |
593 | |
566 | while (cur < end && !errflag) |
594 | while (cur < end && !errflag) |
567 | { |
595 | { |
568 | // SEQUENCE ObjectName ObjectSyntax |
596 | // SEQUENCE ObjectName ObjectSyntax |
569 | if (get8 () != ASN_SEQUENCE) |
597 | if (get8 () != ASN_SEQUENCE) |
… | |
… | |
579 | hv_store_ent (types, oid, newSViv (type), 0); |
607 | hv_store_ent (types, oid, newSViv (type), 0); |
580 | hv_store_ent (list , oid, val, 0); |
608 | hv_store_ent (list , oid, val, 0); |
581 | av_push (names, oid); |
609 | av_push (names, oid); |
582 | } |
610 | } |
583 | |
611 | |
584 | //return $this->_report_pdu_error if ($this->{_pdu_type} == REPORT); |
612 | // sigh - great design to do it here |
|
|
613 | SV *pdu_type = *hv_fetch ((HV *)cur_bufobj, "_pdu_type" , sizeof ("_pdu_type" ) - 1, 1); |
|
|
614 | |
|
|
615 | if (SvIV (pdu_type) == 0xa8) // REPORT |
|
|
616 | { |
|
|
617 | PUSHMARK (SP); |
|
|
618 | XPUSHs (msg); |
|
|
619 | PUTBACK; |
|
|
620 | call_method ("_report_pdu_error", G_VOID | G_DISCARD); |
|
|
621 | SPAGAIN; |
|
|
622 | XSRETURN_EMPTY; |
|
|
623 | } |
585 | |
624 | |
586 | RETVAL = newRV_inc ((SV *)list); |
625 | RETVAL = newRV_inc ((SV *)list); |
587 | } |
626 | } |
588 | OUTPUT: |
627 | OUTPUT: |
589 | RETVAL |
628 | RETVAL |