… | |
… | |
19 | #define ASN_OPAQUE 0x44 |
19 | #define ASN_OPAQUE 0x44 |
20 | #define ASN_COUNTER64 0x46 |
20 | #define ASN_COUNTER64 0x46 |
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 |
|
|
25 | |
24 | static SV *msg; |
26 | static SV *msg; |
25 | static int errflag, leading_dot; |
27 | static int errflag, leading_dot; |
26 | static U8 *buf, *cur; |
28 | static U8 *buf, *cur; |
27 | static STRLEN len, rem; |
29 | static STRLEN len, rem; |
28 | |
30 | |
… | |
… | |
356 | } |
358 | } |
357 | } |
359 | } |
358 | |
360 | |
359 | return errflag ? &PL_sv_undef : res; |
361 | return errflag ? &PL_sv_undef : res; |
360 | } |
362 | } |
|
|
363 | |
|
|
364 | ///////////////////////////////////////////////////////////////////////////// |
|
|
365 | |
|
|
366 | #if HAVE_VERSIONSORT |
|
|
367 | |
|
|
368 | static int |
|
|
369 | oid_lex_cmp (const void *a_, const void *b_) |
|
|
370 | { |
|
|
371 | const char *a = SvPVX (*(SV **)a_); |
|
|
372 | const char *b = SvPVX (*(SV **)b_); |
|
|
373 | |
|
|
374 | a += *a == '.'; |
|
|
375 | b += *b == '.'; |
|
|
376 | |
|
|
377 | return strverscmp (a, b); |
|
|
378 | } |
|
|
379 | |
|
|
380 | #endif |
361 | |
381 | |
362 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::XS |
382 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::XS |
363 | |
383 | |
364 | PROTOTYPES: ENABLE |
384 | PROTOTYPES: ENABLE |
365 | |
385 | |
… | |
… | |
566 | RETVAL = newRV_inc ((SV *)list); |
586 | RETVAL = newRV_inc ((SV *)list); |
567 | } |
587 | } |
568 | OUTPUT: |
588 | OUTPUT: |
569 | RETVAL |
589 | RETVAL |
570 | |
590 | |
|
|
591 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP |
571 | |
592 | |
|
|
593 | void |
|
|
594 | oid_base_match (SV *base_, SV *oid_) |
|
|
595 | PROTOTYPE: $$ |
|
|
596 | ALIAS: |
|
|
597 | oid_context_match = 0 |
|
|
598 | PPCODE: |
|
|
599 | { |
|
|
600 | if (!SvOK (base_) || !SvOK (oid_)) |
|
|
601 | XSRETURN_NO; |
|
|
602 | |
|
|
603 | STRLEN blen, olen; |
|
|
604 | char *base = SvPV (base_, blen); |
|
|
605 | char *oid = SvPV (oid_ , olen); |
|
|
606 | |
|
|
607 | blen -= *base == '.'; base += *base == '.'; |
|
|
608 | olen -= *base == '.'; oid += *oid == '.'; |
|
|
609 | |
|
|
610 | if (olen < blen) |
|
|
611 | XSRETURN_NO; |
|
|
612 | |
|
|
613 | if (memcmp (base, oid, blen)) |
|
|
614 | XSRETURN_NO; |
|
|
615 | |
|
|
616 | if (oid [blen] && oid [blen] != '.') |
|
|
617 | XSRETURN_NO; |
|
|
618 | |
|
|
619 | XSRETURN_YES; |
|
|
620 | } |
|
|
621 | |
|
|
622 | #if HAVE_VERSIONSORT |
|
|
623 | |
|
|
624 | void |
|
|
625 | oid_lex_sort (...) |
|
|
626 | PROTOTYPE: @ |
|
|
627 | PPCODE: |
|
|
628 | { |
|
|
629 | // make sure SvPVX is valid |
|
|
630 | int i; |
|
|
631 | for (i = items; i--; ) |
|
|
632 | { |
|
|
633 | SV *sv = ST (i); |
|
|
634 | |
|
|
635 | if (SvTYPE (sv) < SVt_PV || SvTYPE (sv) == SVt_PVAV && SvTYPE (sv) == SVt_PVHV) |
|
|
636 | SvPV_force_nolen (sv); |
|
|
637 | } |
|
|
638 | |
|
|
639 | qsort (&ST (0), items, sizeof (SV *), oid_lex_cmp); |
|
|
640 | |
|
|
641 | EXTEND (SP, items); |
|
|
642 | // we cheat somewhat by not returning copies here |
|
|
643 | for (i = 0; i < items; ++i) |
|
|
644 | PUSHs (sv_2mortal (SvREFCNT_inc (ST (i)))); |
|
|
645 | } |
|
|
646 | |
|
|
647 | int |
|
|
648 | _index_cmp (const char *a, const char *b) |
|
|
649 | PROTOTYPE: $$ |
|
|
650 | CODE: |
|
|
651 | RETVAL = strverscmp (a, b); |
|
|
652 | OUTPUT: |
|
|
653 | RETVAL |
|
|
654 | |
|
|
655 | #endif |
|
|
656 | |