summaryrefslogtreecommitdiff
path: root/ACE/ASNMP/asnmp/pdu.h
blob: a2d84388da0ee34032c803fdcb3ff30664e1ae6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* -*-C++-*- */
#ifndef PDU_CLS_
#define PDU_CLS_
//=============================================================================
/**
 *  @file     pdu.h
 *
 *  $Id$
 *
 * Pdu class definition. Encapsulation of an SMI Protocol
 * Data Unit (PDU) aka Packet in C++.
 *
 *
 *  @author Peter E Mellquist  original code Michael MacFaden  mrm@cisco.com  ACE port
 *  @author add iterator class for pdus
 */
//=============================================================================

/*===================================================================
  Copyright (c) 1996
  Hewlett-Packard Company

  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  Permission to use, copy, modify, distribute and/or sell this software
  and/or its documentation is hereby granted without fee. User agrees
  to display the above copyright notice and this license notice in all
  copies of the software and any documentation of the software. User
  agrees to assume all liability for the use of the software; Hewlett-Packard
  makes no representations about the suitability of this software for any
  purpose. It is provided "AS-IS without warranty of any kind,either express
  or implied. User hereby grants a royalty-free license to any and all
  derivatives based upon this software code base.
=====================================================================*/

// TODO: this needs to be moved into the CLASS and modifyable at runtime
// TODO: define an iterator object to traverse the vbs in a pdu

#define MAX_VBS 25
#include "asnmp/vb.h"         // include Vb class definition

/**
 * @class Pdu
 *
 * @brief Protocol Data Unit (PDU) concrete class. An abstraction of the
 * data packet used to by two SNMP sessions to communicate.
 */
class ASNMP_Export Pdu
{
public:
  /// constructor no args
  Pdu( void);

  /// constructor with vbs and count
  Pdu( Vb* pvbs, const int pvb_count);

  /// constructor with another Pdu instance
  Pdu( const Pdu &pdu);

  /// destructor
  ~Pdu();

  /// assignment to another Pdu object overloaded
  Pdu& operator=( const Pdu &pdu);

  /// append a vb to the pdu
  Pdu& operator+=( Vb &vb);

  // TODO: add Pdu& operator-=(const Vb &vb);

  /// extract all Vbs from Pdu
  int get_vblist( Vb* pvbs, const int pvb_count);

  /// deposit all Vbs to Pdu
  int set_vblist( Vb* pvbs, const int pvb_count);

  /// get a particular vb
  /// where 0 is the first vb
  int get_vb( Vb &vb, const int index = 0) const;

  /// set a particular vb
  /// where 0 is the first vb
  int set_vb( Vb &vb, const int index);

  /// return number of vbs
  int get_vb_count() const;

  /// return the error status
  int get_error_status() const;

  /// return the complete error info from this pdu
  const char *agent_error_reason();

  /// set the error status
  friend ASNMP_Export void set_error_status( Pdu *pdu, const int status);

  /// return the error index
  int get_error_index() const;

  /// set the error index
  friend ASNMP_Export void set_error_index( Pdu *pdu, const int index);

  /// clear error status
  friend ASNMP_Export void clear_error_status( Pdu *pdu);

  /// clear error index
  friend ASNMP_Export void clear_error_index( Pdu *pdu);

  /// return the request id
  unsigned long get_request_id() const;

  /// set the request id
  friend void set_request_id( Pdu *pdu, const unsigned long rid);

  /// get the pdu type
  unsigned short get_type() const;

  /// set the pdu type
  void set_type( unsigned short type);

  /// returns validity of Pdu instance
  int valid() const;

  /// trim off count vbs from the end of the vb list
  int trim(const int count=1);

  /// delete a Vb anywhere within the Pdu
  int delete_vb( const int position);

  /// delete_all vbs in pdu
  void delete_all_vbs();

  /// set notify timestamp
  void set_notify_timestamp( const TimeTicks & timestamp);

  /// get notify timestamp
  void get_notify_timestamp( TimeTicks & timestamp) const;

  /// set the notify id
  void set_notify_id( const Oid id);

  /// get the notify id
  void get_notify_id( Oid &id) const;

  /// set the notify enterprise
  void set_notify_enterprise( const Oid &enterprise);

  /// get the notify enterprise
  void get_notify_enterprise( Oid & enterprise) const;

  /// return fomatted version of this object
  const char *to_string();


  protected:
    /// pointer to array of Vbs
    Vb *vbs_[MAX_VBS];

    /// count of Vbs
    int vb_count_;

    /// SMI error status
    int error_status_;

    /// SMI error index
    int error_index_;

    /// valid boolean status of object construction
    /// SMI request id
    int validity_;
    unsigned long request_id_;

    /// derived at run time based on request type
    unsigned short pdu_type_;

    /**
     * a timestamp associated with an infor
     * for notify Pdu objects only
     * traps & notifies
     */
    TimeTicks notify_timestamp_;

    /// an id
    Oid notify_id_;

    Oid notify_enterprise_;

   private:
   /// buffer for to_string()
   char *output_;
};


/**
 * @class VbIter
 *
 * @brief Utility class to iterate once through a PDU varbind list
 */
class ASNMP_Export VbIter
{
   public:
   /// default constructor
   VbIter(Pdu& pdu);

   /// returns 1 if ok, else 0 if none left
   int next(Vb& vb);

  private:
   /// disallow copy constructor use
   VbIter(const VbIter&);

   /// current object in list
   int idx_;

   /// ptr to pdu being interated over
   Pdu *pdu_;
};

#endif //PDU_CLS_