ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-BER-XS/XS.pm
(Generate patch)

Comparing Convert-BER-XS/XS.pm (file contents):
Revision 1.55 by root, Tue Apr 23 21:20:25 2019 UTC vs.
Revision 1.57 by root, Thu Apr 25 22:30:21 2019 UTC

409use common::sense; 409use common::sense;
410 410
411use XSLoader (); 411use XSLoader ();
412use Exporter qw(import); 412use Exporter qw(import);
413 413
414use Carp ();
415
414our $VERSION; 416our $VERSION;
415 417
416BEGIN { 418BEGIN {
417 $VERSION = 1.11; 419 $VERSION = 1.2;
418 XSLoader::load __PACKAGE__, $VERSION; 420 XSLoader::load __PACKAGE__, $VERSION;
419} 421}
420 422
421our %EXPORT_TAGS = ( 423our %EXPORT_TAGS = (
422 const_index => [qw( 424 const_index => [qw(
469$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); 471$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS);
470$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); 472$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT);
471$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); 473$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT);
472$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); 474$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT);
473 475
476# decodes REAL values according to ECMA-63
477# this is pretty strict, except it doesn't catch -0.
478sub _decode_real_decimal {
479 my ($format, $val) = @_;
480
481 $val =~ y/,/./;
482
483 if ($format == 1) {
484 $val =~ /^ \ * [+-]? [0-9]+ \z/x
485 or Carp::croak "BER_TYPE_REAL NR1 value not in NR1 format ($val) (X.690 8.5.8, ECMA-63)";
486 } elsif ($format == 2) {
487 $val =~ /^ \ * [+-]? (?: [0-9]+\.[0-9]* | [0-9]*\.[0-9]+ ) \z/x
488 or Carp::croak "BER_TYPE_REAL NR2 value not in NR2 format ($val) (X.690 8.5.8, ECMA-63)";
489 } elsif ($format == 3) {
490 $val =~ /^ \ * [+-] (?: [0-9]+\.[0-9]* | [0-9]*\.[0-9]+ ) E [+-][0-9]+ \z/x
491 or Carp::croak "BER_TYPE_REAL NR3 value not in NR3 format ($val) (X.690 8.5.8, ECMA-63)";
492 } else {
493 Carp::croak "BER_TYPE_REAL illegal decimal numerical representation format $format";
494 }
495
496 $val
497}
498
499# this is a mess, but perl's support for floating point formatting is nearly nonexistant
500sub _encode_real_decimal {
501 my ($val, $nvdig) = @_;
502
503 $val = sprintf "%.*G", $nvdig + 1, $val;
504
505 if ($val =~ /E/) {
506 $val =~ s/E(?=[^+-])/E+/;
507 $val =~ s/E/.E/ if $val !~ /\./;
508 $val =~ s/^/+/ unless $val =~ /^-/;
509
510 return "\x03$val" # NR3
511 }
512
513 $val =~ /\./
514 ? "\x02$val" # NR2
515 : "\x01$val" # NR1
516}
517
474=head2 DEBUGGING 518=head2 DEBUGGING
475 519
476To aid debugging, you cna call the C<ber_dump> function to print a "nice" 520To aid debugging, you can call the C<ber_dump> function to print a "nice"
477representation to STDOUT. 521representation to STDOUT.
478 522
479=over 523=over
480 524
481=item ber_dump $tuple[, $profile[, $prefix]] 525=item ber_dump $tuple[, $profile[, $prefix]]
737 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_BYTES); 781 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_BYTES);
738 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); 782 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT);
739 783
740=head2 LIMITATIONS/NOTES 784=head2 LIMITATIONS/NOTES
741 785
742This module can only en-/decode 64 bit signed and unsigned integers, and 786This module can only en-/decode 64 bit signed and unsigned
743only when your perl supports those. So no UUID OIDs for now (unless you 787integers/tags/lengths, and only when your perl supports those. So no UUID
744map the C<OBJECT IDENTIFIER> tag to something other than C<BER_TYPE_OID>). 788OIDs for now (unless you map the C<OBJECT IDENTIFIER> tag to something
789other than C<BER_TYPE_OID>).
745 790
746This module does not generally care about ranges, i.e. it will happily 791This module does not generally care about ranges, i.e. it will happily
747de-/encode 64 bit integers into an C<SNMP_UNSIGNED32> value, or a negative 792de-/encode 64 bit integers into an C<SNMP_UNSIGNED32> value, or a negative
748number into an C<SNMP_COUNTER64>. 793number into an C<SNMP_COUNTER64>.
749 794
752about 4kB. 797about 4kB.
753 798
754Constructed strings are decoded just fine, but there should be a way to 799Constructed strings are decoded just fine, but there should be a way to
755join them for convenience. 800join them for convenience.
756 801
757REAL values are not supported and will currently croak. 802REAL values will always be encoded in decimal form and ssometimes is
803forced into a perl "NV" type, potentially losing precision.
758 804
759=head2 ITHREADS SUPPORT 805=head2 ITHREADS SUPPORT
760 806
761This module is unlikely to work when the (officially discouraged) ithreads 807This module is unlikely to work in any other than the loading thread when
762are in use. 808the (officially discouraged) ithreads are in use.
763 809
764=head1 AUTHOR 810=head1 AUTHOR
765 811
766 Marc Lehmann <schmorp@schmorp.de> 812 Marc Lehmann <schmorp@schmorp.de>
767 http://software.schmorp.de/pkg/Convert-BER-XS 813 http://software.schmorp.de/pkg/Convert-BER-XS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines