license changed to LGPL for libnxcl, libnxsnmp, libnxlp, libnxsl, and libnxmap
[public/netxms.git] / src / snmp / libnxsnmp / libnxsnmp.h
1 /*
2 ** NetXMS - Network Management System
3 ** SNMP support library
4 ** Copyright (C) 2003-2010 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: libnxsnmp.h
21 **
22 **/
23
24 #ifndef _libnxsnmp_h_
25 #define _libnxsnmp_h_
26
27 #include <nms_common.h>
28 #include <nms_util.h>
29 #include <nxsnmp.h>
30 #include <zlib.h>
31
32 #ifndef _WIN32
33 #include <netdb.h>
34 #endif
35
36
37 //
38 // Buffer structure for BER_DecodeContent for ASN_OBJECT_ID type
39 //
40
41 typedef struct
42 {
43 DWORD dwLength;
44 DWORD *pdwValue;
45 } SNMP_OID;
46
47
48 //
49 // Header structure for compiled MIB file
50 //
51
52 typedef struct
53 {
54 char chMagic[6];
55 BYTE bHeaderSize; // Header size in bytes
56 BYTE bVersion;
57 WORD wFlags;
58 BYTE bReserved[2];
59 DWORD dwTimeStamp; // Server's timestamp
60 } SNMP_MIB_HEADER;
61
62
63 //
64 // MIB file header constants
65 //
66
67 #define MIB_FILE_MAGIC "NXMIB "
68 #define MIB_FILE_VERSION 1
69
70
71 //
72 // Tags for compiled MIB file
73 //
74
75 #define MIB_TAG_OBJECT 0x01
76 #define MIB_TAG_NAME 0x02
77 #define MIB_TAG_DESCRIPTION 0x03
78 #define MIB_TAG_ACCESS 0x04
79 #define MIB_TAG_STATUS 0x05
80 #define MIB_TAG_TYPE 0x06
81 #define MIB_TAG_BYTE_OID 0x07 /* Used if OID < 256 */
82 #define MIB_TAG_WORD_OID 0x08 /* Used if OID < 65536 */
83 #define MIB_TAG_DWORD_OID 0x09
84
85 #define MIB_END_OF_TAG 0x80
86
87
88 //
89 // Class for compressed/uncompressed I/O
90 //
91
92 class ZFile
93 {
94 private:
95 BOOL m_bCompress;
96 BOOL m_bWrite;
97 FILE *m_pFile;
98 z_stream m_stream;
99 int m_nLastZLibError;
100 int m_nBufferSize;
101 BYTE *m_pDataBuffer;
102 BYTE *m_pCompBuffer;
103 BYTE *m_pBufferPos;
104
105 int zwrite(void *pBuf, int nLen);
106 int zputc(int ch);
107 int zread(void *pBuf, int nLen);
108 int zgetc(void);
109 int zclose(void);
110
111 BOOL FillDataBuffer(void);
112
113 public:
114 ZFile(FILE *pFile, BOOL bCompress, BOOL bWrite);
115 ~ZFile();
116
117 size_t write(void *pBuf, int nLen) { return m_bCompress ? zwrite(pBuf, nLen) : fwrite(pBuf, 1, nLen, m_pFile); }
118 int fputc(int ch) { return m_bCompress ? zputc(ch) : ::fputc(ch, m_pFile); }
119
120 size_t read(void *pBuf, int nLen) { return m_bCompress ? zread(pBuf, nLen) : fread(pBuf, 1, nLen, m_pFile); }
121 int fgetc(void) { return m_bCompress ? zgetc() : ::fgetc(m_pFile); }
122
123 int close(void) { return m_bCompress ? zclose() : fclose(m_pFile); }
124
125 int GetZLibError(void) { return m_nLastZLibError; }
126 };
127
128
129 //
130 // Functions
131 //
132
133 BOOL BER_DecodeIdentifier(BYTE *pRawData, DWORD dwRawSize, DWORD *pdwType,
134 DWORD *pdwLength, BYTE **pData, DWORD *pdwIdLength);
135 BOOL BER_DecodeContent(DWORD dwType, BYTE *pData, DWORD dwLength, BYTE *pBuffer);
136 DWORD BER_Encode(DWORD dwType, BYTE *pData, DWORD dwDataLength,
137 BYTE *pBuffer, DWORD dwBufferSize);
138
139 #endif /* _libnxsnmp_h_ */