00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 #ifndef request_h_
00092 #define request_h_
00093
00094 #include <agent_pp/agent++.h>
00095 #include <agent_pp/threads.h>
00096 #include <agent_pp/snmp_pp_ext.h>
00097 #include <agent_pp/List.h>
00098 #include <agent_pp/mib_entry.h>
00099
00100 #ifdef _SNMPv3
00101
00102 #include <agent_pp/vacm_class.h>
00103 #endif
00104
00105 #define DEFAULT_WRITE_COMMUNITY "public"
00106 #define DEFAULT_READ_COMMUNITY "public"
00107
00108 #define PHASE_DEFAULT 0
00109 #define PHASE_PREPARE 1
00110 #define PHASE_COMMIT 2
00111 #define PHASE_UNDO 3
00112 #define PHASE_CLEANUP 4
00113
00114 #ifdef AGENTPP_NAMESPACE
00115 namespace Agentpp {
00116 #endif
00117
00118
00119
00120
00143 #if !defined (AGENTPP_DECL_TEMPL_ARRAY_MIBENTRY)
00144 #define AGENTPP_DECL_TEMPL_ARRAY_MIBENTRY
00145 AGENTPP_DECL_TEMPL template class AGENTPP_DECL Array<MibEntry>;
00146 #endif
00147
00148 #ifdef _THREADS
00149 class AGENTPP_DECL Request: public Synchronized {
00150 #else
00151 class AGENTPP_DECL Request {
00152 #endif
00153 friend class RequestList;
00154 friend class Mib;
00155 public:
00156
00157 #ifdef _SNMPv3
00158
00166 Request(const Pdux&, const NS_SNMP UTarget&);
00167 #else
00168
00176 Request(const Pdux&, const NS_SNMP CTarget&);
00177 #endif
00178
00185 Request(const Request&);
00186
00190 virtual ~Request();
00191
00199 virtual boolean contains(const Vbx&);
00200
00209 virtual int position(const Vbx&);
00210
00217 virtual boolean finished() const;
00218
00227 virtual boolean is_done(int) const;
00228
00237 virtual void finish(int, const Vbx&);
00238
00245 virtual void finish(int);
00246
00252 virtual void set_ready(int);
00253
00260 virtual void unset_ready(int);
00261
00270 virtual boolean is_ready(int) const;
00271
00279 virtual int first_pending() const;
00280
00287 virtual void error(int, int);
00288
00289 #ifdef _SNMPv3
00290
00296 virtual void vacmError(int, int);
00297 #endif
00298
00305 virtual Vbx get_value(int);
00306
00319 Vbx* search_value(const Oidx&) const;
00320
00329 Vbx get_original_value(unsigned int i)
00330 { return originalVbs[i]; }
00331
00338 virtual NS_SNMP SnmpInt32 get_syntax(int);
00339
00347 virtual Oidx get_oid(int);
00348
00355 virtual void set_oid(const Oidx&, int);
00356
00357
00363 unsigned short get_type() { return pdu->get_type(); }
00364
00370 unsigned long get_request_id() { return pdu->get_request_id(); }
00371
00377 unsigned long get_transaction_id() { return transaction_id; }
00378
00384 int get_error_status() { return pdu->get_error_status(); }
00385
00392 int get_error_index() { return pdu->get_error_index(); }
00393
00399 void set_error_status(int s) { pdu->set_error_status(s); }
00400
00407 void set_error_index(int i) { pdu->set_error_index(i); }
00408
00414 void set_transaction_id(unsigned long id)
00415 { transaction_id = id; }
00416
00422 int subrequests() { return size; }
00423
00424
00431 int get_non_rep() { return non_rep; }
00432
00439 int get_rep() { return repeater; }
00440
00447 int get_max_rep() { return max_rep; }
00448
00449
00456 virtual boolean add_rep_row();
00457
00467 virtual boolean init_rep_row(int);
00468
00476 virtual void trim_request(int);
00477
00481 void inc_outstanding();
00485 void dec_outstanding();
00486
00490 void no_outstanding();
00491
00498 Pdux* get_pdu() { return pdu; }
00499
00500 #ifdef _SNMPv3
00501
00508 void get_security_name(NS_SNMP OctetStr& s);
00509
00516 unsigned int get_security_model() { return version; }
00517
00524 void init_vacm(Vacm*, const NS_SNMP OctetStr&);
00525
00533 NS_SNMP OctetStr get_view_name() const { return viewName; }
00534
00541 NS_SNMP OctetStr get_context() const { return pdu->get_context_name(); }
00542
00550 NS_SNMP UTarget* get_address() { return ⌖ }
00551
00552 #else
00553
00561 NS_SNMP CTarget* get_address() { return ⌖ }
00562 #endif
00563
00570 NS_SNMP snmp_version get_snmp_version() { return version; }
00571
00572 u_char phase;
00573
00585 MibEntry* get_locked(int);
00586
00596 void set_locked(int, MibEntry*);
00597
00604 void set_unlocked(int);
00605
00618 int lock_index(MibEntry*);
00619
00629 void trim_bulk_response();
00630
00631 #ifdef NO_FAST_MUTEXES
00632
00635 void init_lock_queue();
00636
00641 void delete_lock_queue()
00642 { if (lockQueue) { delete lockQueue; lockQueue = 0; } }
00643 #endif
00644
00645 protected:
00646
00647 Request();
00648
00649 virtual void init_from_pdu();
00650
00651 void check_exception(int, Vbx&);
00652
00653 int get_max_response_length();
00654
00655 Pdux* pdu;
00656 Vbx* originalVbs;
00657 int originalSize;
00658
00659 NS_SNMP UdpAddress from;
00660 boolean* done;
00661 boolean* ready;
00662 int outstanding;
00663 int size;
00664
00665 int non_rep;
00666 int max_rep;
00667 int repeater;
00668
00669 NS_SNMP snmp_version version;
00670 unsigned long transaction_id;
00671
00672
00673 Array<MibEntry> locks;
00674
00675 #ifdef _SNMPv3
00676 NS_SNMP OctetStr viewName;
00677 Vacm* vacm;
00678 NS_SNMP UTarget target;
00679 #else
00680 NS_SNMP CTarget target;
00681 #endif
00682 #ifdef NO_FAST_MUTEXES
00683 static LockQueue* lockQueue;
00684 #endif
00685 };
00686
00687
00688
00689
00737 class AGENTPP_DECL RequestList: public ThreadManager {
00738 public:
00742 RequestList();
00743
00748 virtual ~RequestList();
00749
00759 virtual void set_address_validation(boolean);
00760
00768 boolean get_address_validation()
00769 { return sourceAddressValidation; }
00770
00776 virtual void set_snmp(Snmpx* session) { snmp = session; }
00777
00784 Snmpx* get_snmp() { return snmp; }
00785
00786 #ifdef _SNMPv3
00787
00792 virtual void set_v3mp(NS_SNMP v3MP* mp) { v3mp = mp; }
00793
00794
00800 virtual void set_vacm(Vacm* v) { vacm = v; }
00801
00808 virtual Vacm* get_vacm() { return vacm; }
00809
00816 virtual NS_SNMP v3MP* get_v3mp() { return v3mp; }
00817 #else
00818
00824 void set_read_community(const NS_SNMP OctetStr&);
00825
00832 void set_write_community(const NS_SNMP OctetStr&);
00833
00834 #endif
00835
00845 virtual Request* receive(int);
00846
00857 virtual unsigned long get_request_id(const Vbx&);
00858
00873 virtual boolean done(unsigned long, int, const Vbx&);
00874
00887 virtual void error(unsigned long, int, int);
00888
00899 virtual Request* get_request(unsigned long);
00900
00909 virtual Request* find_request_on_id(unsigned long);
00910
00917 virtual void answer(Request*);
00918
00919 #ifdef _SNMPv3
00920
00928 virtual void report(Request*);
00929 #endif
00930
00937 unsigned long create_transaction_id()
00938 { return next_transaction_id++; }
00939
00946 boolean is_empty() { return requests->empty();}
00947
00954 unsigned long size() { return requests->size(); }
00955
00962 virtual void remove_request(Request* req);
00963
00964 protected:
00972 virtual Request* add_request(Request*);
00973
00983 virtual boolean community_ok(int, const NS_SNMP OctetStr&);
00984
00999 virtual void authenticationFailure(const NS_SNMP OctetStr& context,
01000 const NS_SNMP GenAddress& sourceAddress,
01001 int status);
01002
01008 static void null_vbs(Request* req);
01009
01010 List<Request>* requests;
01011 Snmpx* snmp;
01012 #ifdef _SNMPv3
01013 Vacm* vacm;
01014 NS_SNMP v3MP* v3mp;
01015 #endif
01016 NS_SNMP OctetStr* write_community;
01017 NS_SNMP OctetStr* read_community;
01018
01019 unsigned long next_transaction_id;
01020
01021 boolean sourceAddressValidation;
01022 };
01023
01024 #ifdef AGENTPP_NAMESPACE
01025 }
01026 #endif
01027
01028
01029 #endif