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 #define DEFAULT_WRITE_COMMUNITY "public"
00101 #define DEFAULT_READ_COMMUNITY "public"
00102
00103 #define PHASE_DEFAULT 0
00104 #define PHASE_PREPARE 1
00105 #define PHASE_COMMIT 2
00106 #define PHASE_UNDO 3
00107 #define PHASE_CLEANUP 4
00108
00109 #ifdef AGENTPP_NAMESPACE
00110 namespace Agentpp {
00111 #endif
00112
00113 #ifdef _SNMPv3
00114 class Vacm;
00115 #endif
00116
00117
00118
00141 #if !defined (AGENTPP_DECL_TEMPL_ARRAY_MIBENTRY)
00142 #define AGENTPP_DECL_TEMPL_ARRAY_MIBENTRY
00143 AGENTPP_DECL_TEMPL template class AGENTPP_DECL Array<MibEntry>;
00144 #endif
00145
00146 #ifdef _THREADS
00147 class AGENTPP_DECL Request: public Synchronized {
00148 #else
00149 class AGENTPP_DECL Request {
00150 #endif
00151 friend class RequestList;
00152 friend class Mib;
00153 public:
00154
00155 #ifdef _SNMPv3
00156
00164 Request(const Pdux&, const NS_SNMP UTarget&);
00165 #else
00166
00174 Request(const Pdux&, const NS_SNMP CTarget&);
00175 #endif
00176
00183 Request(const Request&);
00184
00188 virtual ~Request();
00189
00197 virtual boolean contains(const Vbx&);
00198
00207 virtual int position(const Vbx&);
00208
00215 virtual boolean finished() const;
00216
00225 virtual boolean is_done(int) const;
00226
00235 virtual void finish(int, const Vbx&);
00236
00243 virtual void finish(int);
00244
00250 virtual void set_ready(int);
00251
00258 virtual void unset_ready(int);
00259
00268 virtual boolean is_ready(int) const;
00269
00277 virtual int first_pending() const;
00278
00285 virtual void error(int, int);
00286
00287 #ifdef _SNMPv3
00288
00294 virtual void vacmError(int, int);
00295 #endif
00296
00303 virtual Vbx get_value(int);
00304
00317 Vbx* search_value(const Oidx&) const;
00318
00327 Vbx get_original_value(unsigned int i)
00328 { return originalVbs[i]; }
00329
00336 virtual NS_SNMP SnmpInt32 get_syntax(int);
00337
00345 virtual Oidx get_oid(int);
00346
00353 virtual void set_oid(const Oidx&, int);
00354
00355
00361 unsigned short get_type() { return pdu->get_type(); }
00362
00368 unsigned long get_request_id() { return pdu->get_request_id(); }
00369
00375 unsigned long get_transaction_id() { return transaction_id; }
00376
00382 int get_error_status() { return pdu->get_error_status(); }
00383
00390 int get_error_index() { return pdu->get_error_index(); }
00391
00397 void set_error_status(int s) { pdu->set_error_status(s); }
00398
00405 void set_error_index(int i) { pdu->set_error_index(i); }
00406
00412 void set_transaction_id(unsigned long id)
00413 { transaction_id = id; }
00414
00420 int subrequests() { return size; }
00421
00422
00429 int get_non_rep() { return non_rep; }
00430
00437 int get_rep() { return repeater; }
00438
00445 int get_max_rep() { return max_rep; }
00446
00447
00454 virtual boolean add_rep_row();
00455
00465 virtual boolean init_rep_row(int);
00466
00474 virtual void trim_request(int);
00475
00479 void inc_outstanding();
00483 void dec_outstanding();
00484
00488 void no_outstanding();
00489
00496 Pdux* get_pdu() { return pdu; }
00497
00498 #ifdef _SNMPv3
00499
00506 void get_security_name(NS_SNMP OctetStr& s);
00507
00514 unsigned int get_security_model() { return version; }
00515
00522 void init_vacm(Vacm*, const NS_SNMP OctetStr&);
00523
00531 NS_SNMP OctetStr get_view_name() const { return viewName; }
00532
00539 NS_SNMP OctetStr get_context() const { return pdu->get_context_name(); }
00540
00548 NS_SNMP UTarget* get_address() { return ⌖ }
00549
00550 #else
00551
00559 NS_SNMP CTarget* get_address() { return ⌖ }
00560 #endif
00561
00568 NS_SNMP snmp_version get_snmp_version() { return version; }
00569
00570 u_char phase;
00571
00583 MibEntry* get_locked(int);
00584
00594 void set_locked(int, MibEntry*);
00595
00602 void set_unlocked(int);
00603
00616 int lock_index(MibEntry*);
00617
00627 void trim_bulk_response();
00628
00629 #ifdef NO_FAST_MUTEXES
00630
00633 void init_lock_queue();
00634
00639 void delete_lock_queue()
00640 { if (lockQueue) { delete lockQueue; lockQueue = 0; } }
00641 #endif
00642
00643 protected:
00644
00645 Request();
00646
00647 virtual void init_from_pdu();
00648
00649 void check_exception(int, Vbx&);
00650
00651 int get_max_response_length();
00652
00653 Pdux* pdu;
00654 Vbx* originalVbs;
00655 int originalSize;
00656
00657 NS_SNMP UdpAddress from;
00658 boolean* done;
00659 boolean* ready;
00660 int outstanding;
00661 int size;
00662
00663 int non_rep;
00664 int max_rep;
00665 int repeater;
00666
00667 NS_SNMP snmp_version version;
00668 unsigned long transaction_id;
00669
00670
00671 Array<MibEntry> locks;
00672
00673 #ifdef _SNMPv3
00674 NS_SNMP OctetStr viewName;
00675 Vacm* vacm;
00676 NS_SNMP UTarget target;
00677 #else
00678 NS_SNMP CTarget target;
00679 #endif
00680 #ifdef NO_FAST_MUTEXES
00681 static LockQueue* lockQueue;
00682 #endif
00683 };
00684
00685
00686
00687
00735 class AGENTPP_DECL RequestList: public ThreadManager {
00736 public:
00740 RequestList();
00741
00746 virtual ~RequestList();
00747
00757 virtual void set_address_validation(boolean);
00758
00766 boolean get_address_validation()
00767 { return sourceAddressValidation; }
00768
00774 virtual void set_snmp(Snmpx* session) { snmp = session; }
00775
00782 Snmpx* get_snmp() { return snmp; }
00783
00784 #ifdef _SNMPv3
00785
00790 virtual void set_v3mp(NS_SNMP v3MP* mp) { v3mp = mp; }
00791
00792
00798 virtual void set_vacm(Vacm* v) { vacm = v; }
00799
00806 virtual Vacm* get_vacm() { return vacm; }
00807
00814 virtual NS_SNMP v3MP* get_v3mp() { return v3mp; }
00815 #else
00816
00822 void set_read_community(const NS_SNMP OctetStr&);
00823
00830 void set_write_community(const NS_SNMP OctetStr&);
00831
00832 #endif
00833
00843 virtual Request* receive(int);
00844
00855 virtual unsigned long get_request_id(const Vbx&);
00856
00871 virtual boolean done(unsigned long, int, const Vbx&);
00872
00885 virtual void error(unsigned long, int, int);
00886
00897 virtual Request* get_request(unsigned long);
00898
00907 virtual Request* find_request_on_id(unsigned long);
00908
00915 virtual void answer(Request*);
00916
00917 #ifdef _SNMPv3
00918
00926 virtual void report(Request*);
00927 #endif
00928
00935 unsigned long create_transaction_id()
00936 { return next_transaction_id++; }
00937
00944 boolean is_empty() { return requests->empty();}
00945
00952 unsigned long size() { return requests->size(); }
00953
00960 virtual void remove_request(Request* req);
00961
00962 protected:
00970 virtual Request* add_request(Request*);
00971
00981 virtual boolean community_ok(int, const NS_SNMP OctetStr&);
00982
00997 virtual void authenticationFailure(const NS_SNMP OctetStr& context,
00998 const NS_SNMP GenAddress& sourceAddress,
00999 int status);
01000
01006 static void null_vbs(Request* req);
01007
01008 List<Request>* requests;
01009 Snmpx* snmp;
01010 #ifdef _SNMPv3
01011 Vacm* vacm;
01012 NS_SNMP v3MP* v3mp;
01013 #endif
01014 NS_SNMP OctetStr* write_community;
01015 NS_SNMP OctetStr* read_community;
01016
01017 unsigned long next_transaction_id;
01018
01019 boolean sourceAddressValidation;
01020 };
01021
01022 #ifdef AGENTPP_NAMESPACE
01023 }
01024 #endif
01025
01026
01027 #endif