… | |
… | |
4 | |
4 | |
5 | // C99 required |
5 | // C99 required |
6 | |
6 | |
7 | //#define BENCHMARK |
7 | //#define BENCHMARK |
8 | |
8 | |
|
|
9 | enum { |
9 | #define ASN_BOOLEAN 0x01 |
10 | ASN_BOOLEAN = 0x01, |
10 | #define ASN_INTEGER32 0x02 |
11 | ASN_INTEGER32 = 0x02, |
11 | #define ASN_OCTET_STRING 0x04 |
12 | ASN_OCTET_STRING = 0x04, |
12 | #define ASN_NULL 0x05 |
13 | ASN_NULL = 0x05, |
13 | #define ASN_OBJECT_IDENTIFIER 0x06 |
14 | ASN_OBJECT_IDENTIFIER = 0x06, |
14 | #define ASN_SEQUENCE 0x30 |
15 | ASN_SEQUENCE = 0x30, |
15 | #define ASN_IPADDRESS 0x40 |
16 | ASN_IPADDRESS = 0x40, |
16 | #define ASN_COUNTER32 0x41 |
17 | ASN_COUNTER32 = 0x41, |
17 | #define ASN_UNSIGNED32 0x42 |
18 | ASN_UNSIGNED32 = 0x42, |
18 | #define ASN_TIMETICKS 0x43 |
19 | ASN_TIMETICKS = 0x43, |
19 | #define ASN_OPAQUE 0x44 |
20 | ASN_OPAQUE = 0x44, |
20 | #define ASN_COUNTER64 0x46 |
21 | ASN_COUNTER64 = 0x46, |
|
|
22 | }; |
21 | |
23 | |
22 | #define MAX_OID_STRLEN 4096 |
24 | #define MAX_OID_STRLEN 4096 |
23 | |
25 | |
24 | #define HAVE_VERSIONSORT defined (_GNU_SOURCE) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 |
26 | #define HAVE_VERSIONSORT defined (_GNU_SOURCE) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 |
25 | |
27 | |
… | |
… | |
419 | } |
421 | } |
420 | |
422 | |
421 | return errflag ? &PL_sv_undef : res; |
423 | return errflag ? &PL_sv_undef : res; |
422 | } |
424 | } |
423 | |
425 | |
|
|
426 | #if 0 |
|
|
427 | |
|
|
428 | static SV * |
|
|
429 | decode_ber () |
|
|
430 | { |
|
|
431 | int type = get8 (); |
|
|
432 | |
|
|
433 | SV *res; |
|
|
434 | |
|
|
435 | printf ("type %x at %x\n", type, cur -buf);//D |
|
|
436 | |
|
|
437 | switch (type & 0x3f) |
|
|
438 | { |
|
|
439 | case ASN_OBJECT_IDENTIFIER: |
|
|
440 | res = process_object_identifier_sv (); |
|
|
441 | break; |
|
|
442 | |
|
|
443 | case ASN_INTEGER32: |
|
|
444 | res = process_integer32_sv (); |
|
|
445 | break; |
|
|
446 | |
|
|
447 | case ASN_UNSIGNED32: |
|
|
448 | case ASN_COUNTER32: |
|
|
449 | case ASN_TIMETICKS: |
|
|
450 | res = process_unsigned32_sv (); |
|
|
451 | break; |
|
|
452 | |
|
|
453 | case ASN_SEQUENCE: |
|
|
454 | { |
|
|
455 | U32 seqend = (cur - buf) + process_length (); |
|
|
456 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
457 | |
|
|
458 | while (cur < buf + seqend) |
|
|
459 | { |
|
|
460 | av_push (av, decode_ber ()); |
|
|
461 | } |
|
|
462 | |
|
|
463 | res = newRV_inc ((SV *)av); |
|
|
464 | } |
|
|
465 | break; |
|
|
466 | |
|
|
467 | case ASN_OCTET_STRING: |
|
|
468 | case ASN_OPAQUE: |
|
|
469 | res = process_octet_string_sv (); |
|
|
470 | break; |
|
|
471 | |
|
|
472 | default: |
|
|
473 | { |
|
|
474 | croak ("Unknown ASN.1 type 0x%02x at offset 0x%04x\n", type, (int)(cur - buf)); |
|
|
475 | } |
|
|
476 | } |
|
|
477 | |
|
|
478 | if (errflag) |
|
|
479 | croak ("some error"); |
|
|
480 | |
|
|
481 | AV *av = newAV (); |
|
|
482 | av_extend (av, 2); |
|
|
483 | av_push (av, newSVuv (type)); |
|
|
484 | av_push (av, res); |
|
|
485 | res = newRV_noinc ((SV *)av); |
|
|
486 | |
|
|
487 | return errflag ? &PL_sv_undef : res; |
|
|
488 | } |
|
|
489 | |
|
|
490 | #endif |
|
|
491 | |
424 | ///////////////////////////////////////////////////////////////////////////// |
492 | ///////////////////////////////////////////////////////////////////////////// |
425 | |
493 | |
426 | #if HAVE_VERSIONSORT |
494 | #if HAVE_VERSIONSORT |
427 | |
495 | |
428 | static int |
496 | static int |
… | |
… | |
450 | set_type (int type, SV *cv) |
518 | set_type (int type, SV *cv) |
451 | CODE: |
519 | CODE: |
452 | cv = x_get_cv (cv); |
520 | cv = x_get_cv (cv); |
453 | assert (SvTYPE (cv) == SVt_PVCV); |
521 | assert (SvTYPE (cv) == SVt_PVCV); |
454 | av_store (av_type, type, SvREFCNT_inc_NN (cv)); |
522 | av_store (av_type, type, SvREFCNT_inc_NN (cv)); |
|
|
523 | |
|
|
524 | #if 0 |
|
|
525 | |
|
|
526 | SV * |
|
|
527 | decode_ber (SV *ber) |
|
|
528 | CODE: |
|
|
529 | { |
|
|
530 | clear_bufobj (); |
|
|
531 | |
|
|
532 | errflag = 0; |
|
|
533 | leading_dot = 0; |
|
|
534 | |
|
|
535 | bufsv = ber; |
|
|
536 | |
|
|
537 | buf = SvPVbyte (bufsv, len); |
|
|
538 | cur = buf; |
|
|
539 | rem = len; |
|
|
540 | |
|
|
541 | RETVAL = decode_ber (); |
|
|
542 | } |
|
|
543 | OUTPUT: RETVAL |
|
|
544 | |
|
|
545 | #endif |
455 | |
546 | |
456 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::Message |
547 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::Message |
457 | |
548 | |
458 | void |
549 | void |
459 | _buffer_append (BUFOBJ self, SV *value) |
550 | _buffer_append (BUFOBJ self, SV *value) |
… | |
… | |
515 | rem = len - ndx; |
606 | rem = len - ndx; |
516 | } |
607 | } |
517 | |
608 | |
518 | RETVAL = cur - buf; |
609 | RETVAL = cur - buf; |
519 | } |
610 | } |
520 | OUTPUT: |
611 | OUTPUT: RETVAL |
521 | RETVAL |
|
|
522 | |
612 | |
523 | U32 |
613 | U32 |
524 | _process_length (BUFOBJ self, ...) |
614 | _process_length (BUFOBJ self, ...) |
525 | ALIAS: |
615 | ALIAS: |
526 | _process_sequence = 0 |
616 | _process_sequence = 0 |
527 | CODE: |
617 | CODE: |
528 | RETVAL = process_length (); |
618 | RETVAL = process_length (); |
529 | OUTPUT: |
619 | OUTPUT: RETVAL |
530 | RETVAL |
|
|
531 | |
620 | |
532 | SV * |
621 | SV * |
533 | _process_integer32 (BUFOBJ self, ...) |
622 | _process_integer32 (BUFOBJ self, ...) |
534 | CODE: |
623 | CODE: |
535 | RETVAL = process_integer32_sv (); |
624 | RETVAL = process_integer32_sv (); |
536 | OUTPUT: |
625 | OUTPUT: RETVAL |
537 | RETVAL |
|
|
538 | |
626 | |
539 | SV * |
627 | SV * |
540 | _process_counter (BUFOBJ self, ...) |
628 | _process_counter (BUFOBJ self, ...) |
541 | ALIAS: |
629 | ALIAS: |
542 | _process_gauge = 0 |
630 | _process_gauge = 0 |
543 | _process_timeticks = 0 |
631 | _process_timeticks = 0 |
544 | CODE: |
632 | CODE: |
545 | RETVAL = process_unsigned32_sv (); |
633 | RETVAL = process_unsigned32_sv (); |
546 | OUTPUT: |
634 | OUTPUT: RETVAL |
547 | RETVAL |
|
|
548 | |
635 | |
549 | #if IVSIZE >= 8 |
636 | #if IVSIZE >= 8 |
550 | |
637 | |
551 | SV * |
638 | SV * |
552 | _process_counter64 (BUFOBJ self, ...) |
639 | _process_counter64 (BUFOBJ self, ...) |
553 | CODE: |
640 | CODE: |
554 | RETVAL = process_unsigned64_sv (); |
641 | RETVAL = process_unsigned64_sv (); |
555 | OUTPUT: |
642 | OUTPUT: RETVAL |
556 | RETVAL |
|
|
557 | |
643 | |
558 | #endif |
644 | #endif |
559 | |
645 | |
560 | SV * |
646 | SV * |
561 | _process_object_identifier (BUFOBJ self, ...) |
647 | _process_object_identifier (BUFOBJ self, ...) |
562 | CODE: |
648 | CODE: |
563 | RETVAL = process_object_identifier_sv (); |
649 | RETVAL = process_object_identifier_sv (); |
564 | OUTPUT: |
650 | OUTPUT: RETVAL |
565 | RETVAL |
|
|
566 | |
651 | |
567 | SV * |
652 | SV * |
568 | _process_octet_string (BUFOBJ self, ...) |
653 | _process_octet_string (BUFOBJ self, ...) |
569 | ALIAS: |
654 | ALIAS: |
570 | _process_opaque = 0 |
655 | _process_opaque = 0 |
571 | CODE: |
656 | CODE: |
572 | RETVAL = process_octet_string_sv (); |
657 | RETVAL = process_octet_string_sv (); |
573 | OUTPUT: |
658 | OUTPUT: RETVAL |
574 | RETVAL |
|
|
575 | |
659 | |
576 | SV * |
660 | SV * |
577 | _process_ipaddress (BUFOBJ self, ...) |
661 | _process_ipaddress (BUFOBJ self, ...) |
578 | CODE: |
662 | CODE: |
579 | { |
663 | { |
… | |
… | |
585 | } |
669 | } |
586 | |
670 | |
587 | U8 *data = getn (4, "\x00\x00\x00\x00"); |
671 | U8 *data = getn (4, "\x00\x00\x00\x00"); |
588 | RETVAL = newSVpvf ("%d.%d.%d.%d", data [0], data [1], data [2], data [3]); |
672 | RETVAL = newSVpvf ("%d.%d.%d.%d", data [0], data [1], data [2], data [3]); |
589 | } |
673 | } |
590 | OUTPUT: |
674 | OUTPUT: RETVAL |
591 | RETVAL |
|
|
592 | |
675 | |
593 | SV * |
676 | SV * |
594 | process (BUFOBJ self, SV *expected = &PL_sv_undef, SV *found = 0) |
677 | process (BUFOBJ self, SV *expected = &PL_sv_undef, SV *found = 0) |
595 | CODE: |
678 | CODE: |
596 | { |
679 | { |
… | |
… | |
602 | sv_setiv (found, type); |
685 | sv_setiv (found, type); |
603 | |
686 | |
604 | if (SvOK (expected) && type != SvIV (expected)) |
687 | if (SvOK (expected) && type != SvIV (expected)) |
605 | error ("Expected a different type than found"); |
688 | error ("Expected a different type than found"); |
606 | } |
689 | } |
607 | OUTPUT: |
690 | OUTPUT: RETVAL |
608 | RETVAL |
|
|
609 | |
691 | |
610 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::PDU |
692 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::PDU |
611 | |
693 | |
612 | SV * |
694 | SV * |
613 | _process_var_bind_list (BUFOBJ self) |
695 | _process_var_bind_list (BUFOBJ self) |
… | |
… | |
657 | XSRETURN_EMPTY; |
739 | XSRETURN_EMPTY; |
658 | } |
740 | } |
659 | |
741 | |
660 | RETVAL = newRV_inc ((SV *)list); |
742 | RETVAL = newRV_inc ((SV *)list); |
661 | } |
743 | } |
662 | OUTPUT: |
744 | OUTPUT: RETVAL |
663 | RETVAL |
|
|
664 | |
745 | |
665 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP |
746 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP |
666 | |
747 | |
667 | void |
748 | void |
668 | oid_base_match (SV *base_, SV *oid_) |
749 | oid_base_match (SV *base_, SV *oid_) |
… | |
… | |
721 | int |
802 | int |
722 | _index_cmp (const char *a, const char *b) |
803 | _index_cmp (const char *a, const char *b) |
723 | PROTOTYPE: $$ |
804 | PROTOTYPE: $$ |
724 | CODE: |
805 | CODE: |
725 | RETVAL = strverscmp (a, b); |
806 | RETVAL = strverscmp (a, b); |
726 | OUTPUT: |
807 | OUTPUT: RETVAL |
727 | RETVAL |
|
|
728 | |
808 | |
729 | #endif |
809 | #endif |
730 | |
810 | |