1 /*_############################################################################
6 _## -----------------------------------------------
7 _## Copyright (c) 2001-2010 Jochen Katz, Frank Fock
9 _## This software is based on SNMP++2.6 from Hewlett Packard:
11 _## Copyright (c) 1996
12 _## Hewlett-Packard Company
14 _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
15 _## Permission to use, copy, modify, distribute and/or sell this software
16 _## and/or its documentation is hereby granted without fee. User agrees
17 _## to display the above copyright notice and this license notice in all
18 _## copies of the software and any documentation of the software. User
19 _## agrees to assume all liability for the use of the software;
20 _## Hewlett-Packard and Jochen Katz make no representations about the
21 _## suitability of this software for any purpose. It is provided
22 _## "AS-IS" without warranty of any kind, either express or implied. User
23 _## hereby grants a royalty-free license to any and all derivatives based
24 _## upon this software code base.
26 _## Stuttgart, Germany, Thu Sep 2 00:07:47 CEST 2010
28 _##########################################################################*/
29 // $Id: v3.h 288 2007-03-22 22:37:09Z katz $
37 #include "snmp_pp/config_snmp_pp.h"
39 #ifdef SNMP_PP_NAMESPACE
53 /** @name SNMPv3 Security Model values
56 #define SNMP_SECURITY_MODEL_ANY 0 //!< Not used in SNMP++.
57 #define SNMP_SECURITY_MODEL_V1 1 //!< Can be used for SNMPv1 only.
58 #define SNMP_SECURITY_MODEL_V2 2 //!< Can be used for SNMPv2 only.
59 #define SNMP_SECURITY_MODEL_USM 3 //!< Can be used for SNMPv3 only.
63 * Set the amount of log messages you want to get. To disable all
64 * messages, set the level to -1
66 * @param db_level - New level
68 DLLOPT void debug_set_level(const int db_level);
73 * SNMP++ logging function.
75 * The default is to log all messages with a level < 19. To change
76 * that either edit v3.cpp or use a "extern unsigned int debug_level"
77 * to change the level.
79 * @param db_level - Priority of the message (0 = high)
80 * @param format - Just like printf
82 DLLOPT void debugprintf(int db_level, const char *format, ...);
85 * SNMP++ logging function for hex strings.
87 * @param db_level - Priority of the message (0 = high)
88 * @param comment - Comment printed before the hex dump (may be 0)
89 * @param data - pointer to the hex data
90 * @param len - length of the hex data
92 DLLOPT void debughexcprintf(int db_level, const char* comment,
93 const unsigned char *data, const unsigned int len);
95 //! Wrapper for debughexcprintf() without comment.
96 #define debughexprintf(db_level, data, len) \
97 debughexcprintf(db_level, NULL, data, len);
102 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
103 #define debugprintf(db_level,format...)
105 void debugprintf(int db_level, const char *format, ...);
108 // disable any warning for wrong number of arguments in macro
109 #pragma warning(disable:4002)
110 #define debugprintf(db_level,format)
113 #define debughexprintf( db_level, data, len)
114 #define debughexcprintf(db_level, comment, data, len)
120 #define MAXLENGTH_ENGINEID 32
121 #define MAXLENGTH_CONTEXT_NAME 32
122 #define MAXLENGTH_FILENAME 255
123 #define MAXLENGTH_GLOBALDATA 42 // (2 + 1) + 7 + 7 + 3 + 7 + security
125 #define oidV3SnmpEngine "1.3.6.1.6.3.10.2.1"
126 #define oidV3SnmpEngineID "1.3.6.1.6.3.10.2.1.1.0"
127 #define oidV3SnmpEngineBoots "1.3.6.1.6.3.10.2.1.2.0"
128 #define oidV3SnmpEngineTime "1.3.6.1.6.3.10.2.1.3.0"
129 #define oidV3SnmpEngineMaxMessageSize "1.3.6.1.6.3.10.2.1.4.0"
131 // also defined in agent++/include/vacm.h
132 #ifndef oidSnmpUnavailableContexts
133 #define oidSnmpUnavailableContexts "1.3.6.1.6.3.12.1.4.0"
134 #define oidSnmpUnknownContexts "1.3.6.1.6.3.12.1.5.0"
137 /** @name Error codes (storing engineBoots)
139 * These values are returned by getBootCounter() and saveBootCounter().
142 #define SNMPv3_OK 0 //!< No error
143 #define SNMPv3_NO_ENTRY_ERROR -1 //!< No line for the engine id found
144 #define SNMPv3_FILEOPEN_ERROR -2 //!< Unable to open file
145 #define SNMPv3_TOO_LONG_ERROR -3 //!< The given engineID is too long
146 #define SNMPv3_FILE_ERROR -4 //!< The given file contains a wrong line
147 #define SNMPv3_FILECREATE_ERROR -5 //!< The File could not be created
148 #define SNMPv3_FILERENAME_ERROR -6 //!< Error renaming the temporary file
152 * Compare two strings.
154 * @param str1 - The first byte array
155 * @param ptr1len - Length of first array
156 * @param str2 - The second byte array
157 * @param ptr2len - Length of second array
159 * @return 1 if the strings are identical, 0 if not.
161 DLLOPT int unsignedCharCompare(const unsigned char *str1,
162 const long int ptr1len,
163 const unsigned char *str2,
164 const long int ptr2len);
167 * String copy function.
169 * @note The returned string has to be deleted with "delete []".
171 * @param src - Source string
172 * @param srclen - Length of source string
174 * @return Pointer to a null terminated copy of src (or 0 on error).
176 DLLOPT unsigned char *v3strcpy(const unsigned char *src, const int srclen);
179 * Encode the given string into the output buffer. For each byte
180 * of the string two bytes in the output buffer are used. The
181 * output buffer will contain chars from 0x64 to 0x79.
183 * @param in - The string (for example engine id) to encode
184 * @param in_length - The length of the engineID
185 * @param out - The output buffer for the encoded string, must have
186 * lenth 2 * in_length
188 DLLOPT void encodeString(const unsigned char* in, const int in_length,
192 * Decode the given encoded string into the output buffer.
194 * @param in - The encoded string
195 * @param in_length - The length of the encoded string
196 * @param out - Buffer for the decoded string (half size of input
197 * string). The String will be null terminated.
199 DLLOPT void decodeString(const unsigned char* in, const int in_length,
203 * Read the bootCounter of the given engineID stored in the given file.
205 * @param fileName - The name of the file
206 * @param engineId - Read the bootCounter for this enigneID
207 * @param boot - OUT: the bootCounter that was read
209 * @return One of SNMPv3_OK, SNMPv3_TOO_LONG_ERROR, SNMPv3_FILE_ERROR,
210 * SNMPv3_NO_ENTRY_ERROR, SNMPv3_FILEOPEN_ERROR
213 DLLOPT int getBootCounter(const char *fileName,
214 const OctetStr &engineId, unsigned int &boot);
217 * Store the bootCounter of the given engineID in the given file.
219 * @param fileName - The name of the file
220 * @param engineId - Store the bootCounter for this enigneID
221 * @param boot - The bootCounter
223 * @return One of SNMPv3_OK, SNMPv3_FILEOPEN_ERROR, SNMPv3_FILECREATE_ERROR,
224 * SNMPv3_FILERENAME_ERROR.
227 DLLOPT int saveBootCounter(const char *fileName,
228 const OctetStr &engineId, const unsigned int boot);
234 * Tool class for easy allocation of buffer space.
236 template <class T> class Buffer
239 /// Constructor: Allocate a buffer for size objects.
240 Buffer(const unsigned int size)
249 /// Destructor: Free allocated buffer
252 if (ptr) delete [] ptr;
255 /// Get the buffer pointer
261 /// Overwrite the buffer space with zero.
265 memset(ptr, 0, len * sizeof(T));
273 // only for compatibility do not use these values:
274 #define SecurityModel_any SNMP_SECURITY_MODEL_ANY
275 #define SecurityModel_v1 SNMP_SECURITY_MODEL_V1
276 #define SecurityModel_v2 SNMP_SECURITY_MODEL_V2
277 #define SecurityModel_USM SNMP_SECURITY_MODEL_USM
279 #ifdef SNMP_PP_NAMESPACE
280 } // end of namespace Snmp_pp