… | |
… | |
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; |
… | |
… | |
395 | av_store (av_type, type, SvREFCNT_inc (x_get_cv (cv))); |
440 | av_store (av_type, type, SvREFCNT_inc (x_get_cv (cv))); |
396 | |
441 | |
397 | void |
442 | void |
398 | set_msg (SV *msg_, SV *buf_) |
443 | set_msg (SV *msg_, SV *buf_) |
399 | CODE: |
444 | CODE: |
400 | { |
|
|
401 | if (msg) |
|
|
402 | croak ("recursive invocation of Net::SNMP::XS parser is not supported"); |
|
|
403 | |
|
|
404 | errflag = 0; |
|
|
405 | leading_dot = -1; |
|
|
406 | msg = SvREFCNT_inc (msg_); |
|
|
407 | buf = SvPVbyte (buf_, len); |
|
|
408 | cur = buf; |
|
|
409 | rem = len; |
|
|
410 | #ifdef BENCHMARK |
|
|
411 | t1 = tstamp (); |
|
|
412 | #endif |
|
|
413 | } |
|
|
414 | |
445 | |
415 | void |
446 | void |
416 | clr_msg () |
447 | clr_msg () |
417 | CODE: |
448 | CODE: |
418 | SvREFCNT_dec (msg); msg = 0; |
|
|
419 | buf = cur = (U8 *)""; |
|
|
420 | len = rem = 0; |
|
|
421 | #ifdef BENCHMARK |
|
|
422 | printf ("%f\n", tstamp () - t1);//D |
|
|
423 | #endif |
|
|
424 | |
449 | |
425 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::Message |
450 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::Message |
426 | |
451 | |
427 | void |
452 | void |
428 | _buffer_get (SV *self, int count = -1) |
453 | _buffer_get (BUFOBJ self, int count = -1) |
429 | PPCODE: |
454 | PPCODE: |
430 | { |
455 | { |
431 | // grrr. |
456 | // grrr. |
432 | if (count < 0) |
457 | if (count < 0) |
433 | { |
458 | { |
… | |
… | |
444 | if (data) |
469 | if (data) |
445 | XPUSHs (sv_2mortal (newSVpvn (data, count))); |
470 | XPUSHs (sv_2mortal (newSVpvn (data, count))); |
446 | } |
471 | } |
447 | |
472 | |
448 | U32 |
473 | U32 |
449 | index (SV *self, int ndx = -1) |
474 | index (BUFOBJ self, int ndx = -1) |
450 | CODE: |
475 | CODE: |
451 | { |
476 | { |
452 | if (ndx >= 0 && ndx < len) |
477 | if (ndx >= 0 && ndx < len) |
453 | { |
478 | { |
454 | cur = buf + ndx; |
479 | cur = buf + ndx; |
… | |
… | |
459 | } |
484 | } |
460 | OUTPUT: |
485 | OUTPUT: |
461 | RETVAL |
486 | RETVAL |
462 | |
487 | |
463 | U32 |
488 | U32 |
464 | _process_length (SV *self, ...) |
489 | _process_length (BUFOBJ self, ...) |
465 | ALIAS: |
490 | ALIAS: |
466 | _process_sequence = 0 |
491 | _process_sequence = 0 |
467 | CODE: |
492 | CODE: |
468 | RETVAL = process_length (); |
493 | RETVAL = process_length (); |
469 | OUTPUT: |
494 | OUTPUT: |
470 | RETVAL |
495 | RETVAL |
471 | |
496 | |
472 | SV * |
497 | SV * |
473 | _process_integer32 (SV *self, ...) |
498 | _process_integer32 (BUFOBJ self, ...) |
474 | CODE: |
499 | CODE: |
475 | RETVAL = process_integer32_sv (); |
500 | RETVAL = process_integer32_sv (); |
476 | OUTPUT: |
501 | OUTPUT: |
477 | RETVAL |
502 | RETVAL |
478 | |
503 | |
479 | SV * |
504 | SV * |
480 | _process_counter (SV *self, ...) |
505 | _process_counter (BUFOBJ self, ...) |
481 | ALIAS: |
506 | ALIAS: |
482 | _process_gauge = 0 |
507 | _process_gauge = 0 |
483 | _process_timeticks = 0 |
508 | _process_timeticks = 0 |
484 | CODE: |
509 | CODE: |
485 | RETVAL = process_unsigned32_sv (); |
510 | RETVAL = process_unsigned32_sv (); |
… | |
… | |
487 | RETVAL |
512 | RETVAL |
488 | |
513 | |
489 | #if IVSIZE >= 8 |
514 | #if IVSIZE >= 8 |
490 | |
515 | |
491 | SV * |
516 | SV * |
492 | _process_counter64 (SV *self, ...) |
517 | _process_counter64 (BUFOBJ self, ...) |
493 | CODE: |
518 | CODE: |
494 | RETVAL = process_unsigned64_sv (); |
519 | RETVAL = process_unsigned64_sv (); |
495 | OUTPUT: |
520 | OUTPUT: |
496 | RETVAL |
521 | RETVAL |
497 | |
522 | |
498 | #endif |
523 | #endif |
499 | |
524 | |
500 | SV * |
525 | SV * |
501 | _process_object_identifier (SV *self, ...) |
526 | _process_object_identifier (BUFOBJ self, ...) |
502 | CODE: |
527 | CODE: |
503 | RETVAL = process_object_identifier_sv (); |
528 | RETVAL = process_object_identifier_sv (); |
504 | OUTPUT: |
529 | OUTPUT: |
505 | RETVAL |
530 | RETVAL |
506 | |
531 | |
507 | SV * |
532 | SV * |
508 | _process_octet_string (SV *self, ...) |
533 | _process_octet_string (BUFOBJ self, ...) |
509 | ALIAS: |
534 | ALIAS: |
510 | _process_opaque = 0 |
535 | _process_opaque = 0 |
511 | CODE: |
536 | CODE: |
512 | RETVAL = process_octet_string_sv (); |
537 | RETVAL = process_octet_string_sv (); |
513 | OUTPUT: |
538 | OUTPUT: |
514 | RETVAL |
539 | RETVAL |
515 | |
540 | |
516 | SV * |
541 | SV * |
517 | _process_ipaddress (SV *self, ...) |
542 | _process_ipaddress (BUFOBJ self, ...) |
518 | CODE: |
543 | CODE: |
519 | { |
544 | { |
520 | U32 length = process_length (); |
545 | U32 length = process_length (); |
521 | if (length != 4) |
546 | if (length != 4) |
522 | { |
547 | { |
… | |
… | |
529 | } |
554 | } |
530 | OUTPUT: |
555 | OUTPUT: |
531 | RETVAL |
556 | RETVAL |
532 | |
557 | |
533 | SV * |
558 | SV * |
534 | process (SV *self, SV *expected = &PL_sv_undef, SV *found = 0) |
559 | process (BUFOBJ self, SV *expected = &PL_sv_undef, SV *found = 0) |
535 | CODE: |
560 | CODE: |
536 | { |
561 | { |
537 | int type; |
562 | int type; |
538 | |
563 | |
539 | RETVAL = process_sv (&type); |
564 | RETVAL = process_sv (&type); |
… | |
… | |
548 | RETVAL |
573 | RETVAL |
549 | |
574 | |
550 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::PDU |
575 | MODULE = Net::SNMP::XS PACKAGE = Net::SNMP::PDU |
551 | |
576 | |
552 | SV * |
577 | SV * |
553 | _process_var_bind_list (SV *self) |
578 | _process_var_bind_list (BUFOBJ self) |
554 | CODE: |
579 | CODE: |
555 | { |
580 | { |
556 | if (get8 () != ASN_SEQUENCE) |
581 | if (get8 () != ASN_SEQUENCE) |
557 | error ("SEQUENCE expected at beginning of VarBindList"); |
582 | error ("SEQUENCE expected at beginning of VarBindList"); |
558 | int seqlen = process_length (); |
583 | int seqlen = process_length (); |
… | |
… | |
560 | |
585 | |
561 | HV *list = newHV (); |
586 | HV *list = newHV (); |
562 | AV *names = newAV (); |
587 | AV *names = newAV (); |
563 | HV *types = newHV (); |
588 | HV *types = newHV (); |
564 | |
589 | |
565 | 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); |
566 | 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); |
567 | 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); |
568 | |
593 | |
569 | while (cur < end && !errflag) |
594 | while (cur < end && !errflag) |
570 | { |
595 | { |
571 | // SEQUENCE ObjectName ObjectSyntax |
596 | // SEQUENCE ObjectName ObjectSyntax |
572 | if (get8 () != ASN_SEQUENCE) |
597 | if (get8 () != ASN_SEQUENCE) |
… | |
… | |
582 | hv_store_ent (types, oid, newSViv (type), 0); |
607 | hv_store_ent (types, oid, newSViv (type), 0); |
583 | hv_store_ent (list , oid, val, 0); |
608 | hv_store_ent (list , oid, val, 0); |
584 | av_push (names, oid); |
609 | av_push (names, oid); |
585 | } |
610 | } |
586 | |
611 | |
587 | //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 | } |
588 | |
624 | |
589 | RETVAL = newRV_inc ((SV *)list); |
625 | RETVAL = newRV_inc ((SV *)list); |
590 | } |
626 | } |
591 | OUTPUT: |
627 | OUTPUT: |
592 | RETVAL |
628 | RETVAL |