00001 /*_############################################################################ 00002 _## 00003 _## v3.h 00004 _## 00005 _## SNMP++v3.2.15 00006 _## ----------------------------------------------- 00007 _## Copyright (c) 2001-2004 Jochen Katz, Frank Fock 00008 _## 00009 _## This software is based on SNMP++2.6 from Hewlett Packard: 00010 _## 00011 _## Copyright (c) 1996 00012 _## Hewlett-Packard Company 00013 _## 00014 _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. 00015 _## Permission to use, copy, modify, distribute and/or sell this software 00016 _## and/or its documentation is hereby granted without fee. User agrees 00017 _## to display the above copyright notice and this license notice in all 00018 _## copies of the software and any documentation of the software. User 00019 _## agrees to assume all liability for the use of the software; 00020 _## Hewlett-Packard and Jochen Katz make no representations about the 00021 _## suitability of this software for any purpose. It is provided 00022 _## "AS-IS" without warranty of any kind, either express or implied. User 00023 _## hereby grants a royalty-free license to any and all derivatives based 00024 _## upon this software code base. 00025 _## 00026 _## Stuttgart, Germany, Tue Jan 4 21:42:42 CET 2005 00027 _## 00028 _##########################################################################*/ 00029 // $Id: v3.h,v 1.7 2004/07/04 19:06:13 katz Exp $ 00030 00031 #ifndef _V3_H 00032 #define _V3_H 00033 00034 #include <stdio.h> 00035 #include <stdarg.h> 00036 00037 #include "snmp_pp/config_snmp_pp.h" 00038 00039 #ifdef SNMP_PP_NAMESPACE 00040 namespace Snmp_pp { 00041 #endif 00042 00043 class OctetStr; 00044 00045 #ifndef TRUE 00046 #define TRUE 1 00047 #endif 00048 00049 #ifndef FALSE 00050 #define FALSE 0 00051 #endif 00052 00053 /** @name SNMPv3 Security Model values 00054 */ 00055 //@{ 00056 #define SNMP_SECURITY_MODEL_ANY 0 //!< Not used in SNMP++. 00057 #define SNMP_SECURITY_MODEL_V1 1 //!< Can be used for SNMPv1 only. 00058 #define SNMP_SECURITY_MODEL_V2 2 //!< Can be used for SNMPv2 only. 00059 #define SNMP_SECURITY_MODEL_USM 3 //!< Can be used for SNMPv3 only. 00060 //@} 00061 00062 /** 00063 * Set the logfile for logging output. 00064 * 00065 * @param filename - Complete path and name of the logfile. 00066 * 00067 * @note The string may not be deleted after the call. 00068 */ 00069 DLLOPT void debug_set_logfile(const char *filename); 00070 00071 /** 00072 * Set the amount of log messages you want to get. To disable all 00073 * messages, set the level to -1 00074 * 00075 * @param db_level - New level 00076 */ 00077 DLLOPT void debug_set_level(const int db_level); 00078 00079 #ifdef _DEBUG 00080 00081 /** 00082 * SNMP++ logging function. 00083 * 00084 * The default is to log all messages with a level < 19. To change 00085 * that either edit v3.cpp or use a "extern unsigned int debug_level" 00086 * to change the level. 00087 * 00088 * @param db_level - Priority of the message (0 = high) 00089 * @param format - Just like printf 00090 */ 00091 DLLOPT void debugprintf(int db_level, const char *format, ...); 00092 00093 /** 00094 * SNMP++ logging function for hex strings. 00095 * 00096 * @param db_level - Priority of the message (0 = high) 00097 * @param comment - Comment printed before the hex dump (may be 0) 00098 * @param data - pointer to the hex data 00099 * @param len - length of the hex data 00100 */ 00101 DLLOPT void debughexcprintf(int db_level, const char* comment, 00102 const unsigned char *data, const unsigned int len); 00103 00104 //! Wrapper for debughexcprintf() without comment. 00105 #define debughexprintf(db_level, data, len) \ 00106 debughexcprintf(db_level, NULL, data, len); 00107 00108 #else 00109 00110 #ifndef _MSC_VER 00111 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 00112 #define debugprintf(db_level,format...) 00113 #else 00114 void debugprintf(int db_level, const char *format, ...); 00115 #endif 00116 #else 00117 // disable any warning for wrong number of arguments in macro 00118 #pragma warning(disable:4002) 00119 #define debugprintf(db_level,format) 00120 #endif //_MSC_VER 00121 00122 #define debughexprintf( db_level, data, len) 00123 #define debughexcprintf(db_level, comment, data, len) 00124 00125 #endif 00126 00127 #ifdef _SNMPv3 00128 00129 #define V3MAXMESSAGESIZE SNMP_MSG_LENGTH 00130 #define MAXLENGTH_ENGINEID 32 00131 #define MAXLENGTH_CONTEXT_NAME 32 00132 #define MAXLENGTH_FILENAME 255 00133 #define MAXLENGTH_GLOBALDATA 42 // (2 + 1) + 7 + 7 + 3 + 7 + security 00134 00135 #define oidV3SnmpEngine "1.3.6.1.6.3.10.2.1" 00136 #define oidV3SnmpEngineID "1.3.6.1.6.3.10.2.1.1.0" 00137 #define oidV3SnmpEngineBoots "1.3.6.1.6.3.10.2.1.2.0" 00138 #define oidV3SnmpEngineTime "1.3.6.1.6.3.10.2.1.3.0" 00139 #define oidV3SnmpEngineMaxMessageSize "1.3.6.1.6.3.10.2.1.4.0" 00140 00141 // also defined in agent++/include/vacm.h 00142 #ifndef oidSnmpUnavailableContexts 00143 #define oidSnmpUnavailableContexts "1.3.6.1.6.3.12.1.4.0" 00144 #define oidSnmpUnknownContexts "1.3.6.1.6.3.12.1.5.0" 00145 #endif 00146 00147 /** @name Error codes (storing engineBoots) 00148 * 00149 * These values are returned by getBootCounter() and saveBootCounter(). 00150 */ 00151 //@{ 00152 #define SNMPv3_OK 0 //!< No error 00153 #define SNMPv3_NO_ENTRY_ERROR -1 //!< No line for the engine id found 00154 #define SNMPv3_FILEOPEN_ERROR -2 //!< Unable to open file 00155 #define SNMPv3_TOO_LONG_ERROR -3 //!< The given engineID is too long 00156 #define SNMPv3_FILE_ERROR -4 //!< The given file contains a wrong line 00157 #define SNMPv3_FILECREATE_ERROR -5 //!< The File could not be created 00158 #define SNMPv3_FILERENAME_ERROR -6 //!< Error renaming the temporary file 00159 //@} 00160 00161 /** 00162 * Compare two strings. 00163 * 00164 * @param str1 - The first byte array 00165 * @param ptr1len - Length of first array 00166 * @param str2 - The second byte array 00167 * @param ptr2len - Length of second array 00168 * 00169 * @return 1 if the strings are identical, 0 if not. 00170 */ 00171 DLLOPT int unsignedCharCompare(const unsigned char *str1, 00172 const long int ptr1len, 00173 const unsigned char *str2, 00174 const long int ptr2len); 00175 00176 /** 00177 * String copy function. 00178 * 00179 * @note The returned string has to be deleted with "delete []". 00180 * 00181 * @param src - Source string 00182 * @param srclen - Length of source string 00183 * 00184 * @return Pointer to a null terminated copy of src (or 0 on error). 00185 */ 00186 DLLOPT unsigned char *v3strcpy(const unsigned char *src, const int srclen); 00187 00188 /** 00189 * Encode the given string into the output buffer. For each byte 00190 * of the string two bytes in the output buffer are used. The 00191 * output buffer will contain chars from 0x64 to 0x79. 00192 * 00193 * @param in - The string (for example engine id) to encode 00194 * @param in_length - The length of the engineID 00195 * @param out - The output buffer for the encoded string, must have 00196 * lenth 2 * in_length 00197 */ 00198 DLLOPT void encodeString(const unsigned char* in, const int in_length, 00199 char* out); 00200 00201 /** 00202 * Decode the given encoded string into the output buffer. 00203 * 00204 * @param in - The encoded string 00205 * @param in_length - The length of the encoded string 00206 * @param out - Buffer for the decoded string (half size of input 00207 * string). The String will be null terminated. 00208 */ 00209 DLLOPT void decodeString(const unsigned char* in, const int in_length, 00210 char* out); 00211 00212 /** 00213 * Read the bootCounter of the given engineID stored in the given file. 00214 * 00215 * @param fileName - The name of the file 00216 * @param engineId - Read the bootCounter for this enigneID 00217 * @param boot - OUT: the bootCounter that was read 00218 * 00219 * @return One of SNMPv3_OK, SNMPv3_TOO_LONG_ERROR, SNMPv3_FILE_ERROR, 00220 * SNMPv3_NO_ENTRY_ERROR, SNMPv3_FILEOPEN_ERROR 00221 * 00222 */ 00223 DLLOPT int getBootCounter(const char *fileName, 00224 const OctetStr &engineId, unsigned int &boot); 00225 00226 /** 00227 * Store the bootCounter of the given engineID in the given file. 00228 * 00229 * @param fileName - The name of the file 00230 * @param engineId - Store the bootCounter for this enigneID 00231 * @param boot - The bootCounter 00232 * 00233 * @return One of SNMPv3_OK, SNMPv3_FILEOPEN_ERROR, SNMPv3_FILECREATE_ERROR, 00234 * SNMPv3_FILERENAME_ERROR. 00235 * 00236 */ 00237 DLLOPT int saveBootCounter(const char *fileName, 00238 const OctetStr &engineId, const unsigned int boot); 00239 00240 00241 #endif // _SNMPv3 00242 00243 // only for compatibility do not use these values: 00244 #define SecurityModel_any SNMP_SECURITY_MODEL_ANY 00245 #define SecurityModel_v1 SNMP_SECURITY_MODEL_V1 00246 #define SecurityModel_v2 SNMP_SECURITY_MODEL_V2 00247 #define SecurityModel_USM SNMP_SECURITY_MODEL_USM 00248 00249 #ifdef SNMP_PP_NAMESPACE 00250 }; // end of namespace Snmp_pp 00251 #endif 00252 00253 #endif // _V3_H
1.3.2