AGENT++  4.0.3
request.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## AGENT++ 4.0 - request.h
4  _##
5  _## Copyright (C) 2000-2013 Frank Fock and Jochen Katz (agentpp.com)
6  _##
7  _## Licensed under the Apache License, Version 2.0 (the "License");
8  _## you may not use this file except in compliance with the License.
9  _## You may obtain a copy of the License at
10  _##
11  _## http://www.apache.org/licenses/LICENSE-2.0
12  _##
13  _## Unless required by applicable law or agreed to in writing, software
14  _## distributed under the License is distributed on an "AS IS" BASIS,
15  _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  _## See the License for the specific language governing permissions and
17  _## limitations under the License.
18  _##
19  _##########################################################################*/
20 
21 #ifndef request_h_
22 #define request_h_
23 
24 #include <agent_pp/agent++.h>
25 #include <agent_pp/threads.h>
26 #include <agent_pp/snmp_pp_ext.h>
27 #include <agent_pp/List.h>
28 #include <agent_pp/mib_entry.h>
29 
30 #define DEFAULT_WRITE_COMMUNITY "public"
31 #define DEFAULT_READ_COMMUNITY "public"
32 
33 #define PHASE_DEFAULT 0
34 #define PHASE_PREPARE 1
35 #define PHASE_COMMIT 2
36 #define PHASE_UNDO 3
37 #define PHASE_CLEANUP 4
38 
39 #ifdef AGENTPP_NAMESPACE
40 namespace Agentpp {
41 #endif
42 
43 #ifdef _SNMPv3
44 class Vacm;
45 #endif
46 
47 /*--------------------------- class Request --------------------------*/
48 
71 #if !defined (AGENTPP_DECL_TEMPL_ARRAY_MIBENTRY)
72 #define AGENTPP_DECL_TEMPL_ARRAY_MIBENTRY
74 #endif
75 
76 #ifdef _THREADS
78 #else
79 class AGENTPP_DECL Request {
80 #endif
81 friend class RequestList;
82 friend class Mib;
83 public:
84 
85 #ifdef _SNMPv3
86 
89  typedef NS_SNMP UTarget TargetType;
90 #else
91 
94  typedef NS_SNMP CTarget TargetType;
95 #endif
96 
104  Request(const Pdux&, const TargetType &);
105 
112  Request(const Request&);
113 
117  virtual ~Request();
118 
126  virtual bool contains(const Vbx&);
127 
136  virtual int position(const Vbx&);
137 
144  virtual bool finished() const;
145 
154  virtual bool is_done(int) const;
155 
164  virtual void finish(int, const Vbx&);
165 
172  virtual void finish(int);
173 
179  virtual void set_ready(int);
180 
187  virtual void unset_ready(int);
188 
197  virtual bool is_ready(int) const;
198 
206  virtual int first_pending() const;
207 
214  virtual void error(int, int);
215 
216 #ifdef _SNMPv3
217 
223  virtual void vacmError(int, int);
224 #endif
225 
232  virtual Vbx get_value(int);
233 
246  Vbx* search_value(const Oidx&) const;
247 
256  Vbx get_original_value(unsigned int i)
257  { return originalVbs[i]; }
258 
265  virtual NS_SNMP SnmpInt32 get_syntax(int);
266 
274  virtual Oidx get_oid(int);
275 
282  virtual void set_oid(const Oidx&, int);
283 
284 
290  unsigned short get_type() { return pdu->get_type(); }
291 
297  unsigned long get_request_id() { return pdu->get_request_id(); }
298 
304  unsigned long get_transaction_id() { return transaction_id; }
305 
311  int get_error_status() { return pdu->get_error_status(); }
312 
319  int get_error_index() { return pdu->get_error_index(); }
320 
326  void set_error_status(int s) { pdu->set_error_status(s); }
327 
334  void set_error_index(int i) { pdu->set_error_index(i); }
335 
341  void set_transaction_id(unsigned long id)
342  { transaction_id = id; }
343 
349  int subrequests() { return size; }
350 
351 
358  int get_non_rep() { return non_rep; }
359 
366  int get_rep() { return repeater; }
367 
374  int get_max_rep() { return max_rep; }
375 
376 
383  virtual bool add_rep_row();
384 
394  virtual bool init_rep_row(int);
395 
403  virtual void trim_request(int);
404 
408  void inc_outstanding();
412  void dec_outstanding();
413 
417  void no_outstanding();
418 
425  Pdux* get_pdu() { return pdu; }
426 
427 #ifdef _SNMPv3
428 
435  void get_security_name(NS_SNMP OctetStr& s);
436 
443  unsigned int get_security_model() { return version; }
444 
451  void init_vacm(Vacm*, const NS_SNMP OctetStr&);
452 
460  NS_SNMP OctetStr get_view_name() const { return viewName; }
461 
468  NS_SNMP OctetStr get_context() const { return pdu->get_context_name(); }
469 
477  NS_SNMP UTarget* get_address() { return &target; }
478 
479 #else
480 
488  NS_SNMP CTarget* get_address() { return &target; }
489 #endif
490 
497  NS_SNMP snmp_version get_snmp_version() { return version; }
498 
499  u_char phase;
500 
512  MibEntry* get_locked(int);
513 
523  void set_locked(int, MibEntry*);
524 
531  void set_unlocked(int);
532 
545  int lock_index(MibEntry*);
546 
556  void trim_bulk_response();
557 
558 #ifdef NO_FAST_MUTEXES
559 
562  static void init_lock_queue();
563 
568  static void delete_lock_queue()
569  { if (lockQueue) { delete lockQueue; lockQueue = 0; } }
570 #endif
571 
572 protected:
573 
574  Request();
575 
576  virtual void init_from_pdu();
577 
578  void check_exception(int, Vbx&);
579 
580  int get_max_response_length();
581 
585 
586  NS_SNMP UdpAddress from;
587  bool* done;
588  bool* ready;
590  int size;
591 
592  int non_rep;
593  int max_rep;
594  int repeater;
595 
596  NS_SNMP snmp_version version;
597  unsigned long transaction_id;
598 
599  // Locks hold by a mulit-phase (SET) request
601 
602 #ifdef _SNMPv3
603  NS_SNMP OctetStr viewName;
604  Vacm* vacm;
605 #endif
606  TargetType target;
607 #ifdef NO_FAST_MUTEXES
608  static LockQueue* lockQueue;
609 #endif
610 };
611 
612 
613 /*------------------------ class RequestList --------------------------*/
614 
663 public:
667  RequestList();
668 
673  virtual ~RequestList();
674 
684  virtual void set_address_validation(bool);
685 
693  bool get_address_validation()
694  { return sourceAddressValidation; }
695 
701  virtual void set_snmp(Snmpx* session) { snmp = session; }
702 
709  Snmpx* get_snmp() { return snmp; }
710 
711 #ifdef _SNMPv3
712 
717  virtual void set_v3mp(NS_SNMP v3MP* mp) { v3mp = mp; }
718 
719 
725  virtual void set_vacm(Vacm* v) { vacm = v; }
726 
733  virtual Vacm* get_vacm() { return vacm; }
734 
741  virtual NS_SNMP v3MP* get_v3mp() { return v3mp; }
742 #else
743 
749  void set_read_community(const NS_SNMP OctetStr&);
750 
757  void set_write_community(const NS_SNMP OctetStr&);
758 
759 #endif
760 
770  virtual Request* receive(int);
771 
782  virtual unsigned long get_request_id(const Vbx&);
783 
798  virtual bool done(unsigned long, int, const Vbx&);
799 
812  virtual void error(unsigned long, int, int);
813 
824  virtual Request* get_request(unsigned long);
825 
834  virtual Request* find_request_on_id(unsigned long);
835 
842  virtual void answer(Request*);
843 
844 #ifdef _SNMPv3
845 
854  virtual void report(Request*);
855 #endif
856 
863  unsigned long create_transaction_id()
864  { return next_transaction_id++; }
865 
872  bool is_empty() { return requests->empty();}
873 
880  unsigned long size() { return requests->size(); }
881 
888  virtual void remove_request(Request* req);
889 
890 protected:
898  virtual Request* add_request(Request*);
899 
909  virtual bool community_ok(int, const NS_SNMP OctetStr&);
910 
925  virtual void authenticationFailure(const NS_SNMP OctetStr& context,
926  const NS_SNMP GenAddress& sourceAddress,
927  int status);
928 
934  static void null_vbs(Request* req);
935 
938 #ifdef _SNMPv3
939  Vacm* vacm;
940  NS_SNMP v3MP* v3mp;
941 #endif
944 
945  unsigned long next_transaction_id;
946 
948 };
949 
950 /*------------------------ class RequestID --------------------------*/
951 
961  public:
962  RequestID(unsigned long req_id, const Oidx& r_key): id(r_key)
963  { request_id = req_id; }
964 
965  unsigned long get_request_id() const { return request_id; }
966  Oidx* key() { return &id; }
967 
968  protected:
969  unsigned long request_id;
971 };
972 
973 #ifdef AGENTPP_NAMESPACE
974 }
975 #endif
976 
977 
978 #endif