- Various improvements in libnxsnmp
[public/netxms.git] / include / nms_util.h
CommitLineData
e9246d26 1/*
7ac71e60 2** NetXMS - Network Management System
e9246d26
VK
3** Copyright (C) 2003 Victor Kirhenshtein
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** $module: nms_util.h
20**
21**/
22
23#ifndef _nms_util_h_
24#define _nms_util_h_
25
64584976
VK
26#ifdef _WIN32
27#ifdef LIBNETXMS_EXPORTS
28#define LIBNETXMS_EXPORTABLE __declspec(dllexport)
29#else
30#define LIBNETXMS_EXPORTABLE __declspec(dllimport)
31#endif
32#else /* _WIN32 */
33#define LIBNETXMS_EXPORTABLE
34#endif
35
36
e9246d26
VK
37#include <nms_common.h>
38#include <nms_cscp.h>
64584976 39#include <time.h>
e9246d26 40
f52be742
VK
41#if HAVE_BYTESWAP_H
42#include <byteswap.h>
43#endif
44
5d63b3c1
VK
45#define INVALID_INDEX 0xFFFFFFFF
46#define CSCP_TEMP_BUF_SIZE 4096
89bfdd9c 47#define MD5_DIGEST_SIZE 16
d0b249a8 48#define SHA1_DIGEST_SIZE 20
5d63b3c1
VK
49
50
66c04cc7
VK
51//
52// Return codes for IcmpPing()
53//
54
55#define ICMP_SUCCESS 0
56#define ICMP_UNREACHEABLE 1
57#define ICMP_TIMEOUT 2
58#define ICMP_RAW_SOCK_FAILED 3
59
60
dcb44c9a 61//
4826c8a5 62// Token types for configuration loader
dcb44c9a
VK
63//
64
4826c8a5
VK
65#define CT_LONG 0
66#define CT_STRING 1
67#define CT_STRING_LIST 2
68#define CT_END_OF_LIST 3
69#define CT_BOOLEAN 4
70#define CT_WORD 5
fc935a60 71#define CT_IGNORE 6
4826c8a5
VK
72
73
74//
75// Return codes for NxLoadConfig()
76//
77
78#define NXCFG_ERR_OK 0
79#define NXCFG_ERR_NOFILE 1
80#define NXCFG_ERR_SYNTAX 2
81
82
83//
84// Configuration item template for configuration loader
85//
86
87typedef struct
88{
018fda4d 89 TCHAR szToken[64];
4826c8a5
VK
90 BYTE iType;
91 BYTE cSeparator; // Separator character for lists
92 WORD wListElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
93 DWORD dwBufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
94 DWORD dwBufferPos; // Should be set to 0
95 void *pBuffer;
96} NX_CFG_TEMPLATE;
dcb44c9a
VK
97
98
3046f9a4
VK
99//
100// getopt() prototype if needed
101//
102
103#ifdef _WIN32
104#include <getopt.h>
105#endif
106
107
f2fdf1b5
VK
108//
109// Win32 API functions missing under WinCE
110//
111
112#ifdef UNDER_CE
113
114inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
115{
116 SYSTEMTIME sysTime;
117
118 GetSystemTime(&sysTime);
119 SystemTimeToFileTime(&sysTime, pFt);
120}
121
122#endif // UNDER_CE
123
124
e9246d26
VK
125//
126// Functions
127//
128
43d92b4c
VK
129
130#if __BYTE_ORDER == __LITTLE_ENDIAN
131#define htonq(x) __bswap_64(x)
132#define ntohq(x) __bswap_64(x)
9f20696e
VK
133#define htond(x) __bswap_double(x)
134#define ntohd(x) __bswap_double(x)
43d92b4c
VK
135#else
136#define htonq(x) (x)
137#define ntohq(x) (x)
9f20696e
VK
138#define htond(x) (x)
139#define ntohd(x) (x)
43d92b4c 140#endif
15929b31 141
b50f1100 142#ifdef __cplusplus
e9246d26
VK
143extern "C"
144{
b50f1100 145#endif
f52be742 146#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
64584976
VK
147 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
148#endif
9f20696e 149 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
64584976 150
076a55c4 151#if !defined(_WIN32) && !defined(_NETWARE)
018fda4d 152 void LIBNETXMS_EXPORTABLE strupr(TCHAR *in);
7e679c4b 153#endif
ab588c84 154
670c7f3d
VK
155 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
156
64584976 157 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 158 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
a1dc75b0 159
64584976 160 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
31521248 161
b50f1100
VK
162 void LIBNETXMS_EXPORTABLE BinToStr(BYTE *pData, DWORD dwSize, char *pStr);
163 DWORD LIBNETXMS_EXPORTABLE StrToBin(char *pStr, BYTE *pData, DWORD dwSize);
164
018fda4d
AK
165 void LIBNETXMS_EXPORTABLE StrStrip(TCHAR *pszStr);
166 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
167 TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer);
168 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(TCHAR *pszName);
ff5e8be5 169 void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, TCHAR *pszSubStr, TCHAR *pszReplace);
64584976
VK
170
171 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *data, DWORD nbytes);
a48063fc
VK
172 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, int nbytes, unsigned char *hash);
173 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, int nbytes, unsigned char *hash);
b40371d4
AK
174 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(TCHAR *pszFileName, BYTE *pHash);
175 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(TCHAR *pszFileName, BYTE *pHash);
66c04cc7
VK
176
177 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout, DWORD *pdwRTT);
4826c8a5 178
018fda4d 179 DWORD LIBNETXMS_EXPORTABLE NxLoadConfig(TCHAR *pszFileName, TCHAR *pszSection,
6849d9be 180 NX_CFG_TEMPLATE *pTemplateList, BOOL bPrint);
aa13cfd9 181
018fda4d 182 HMODULE LIBNETXMS_EXPORTABLE DLOpen(TCHAR *szLibName, TCHAR *pszErrorText);
aa13cfd9 183 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
018fda4d 184 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, TCHAR *szSymbol, TCHAR *pszErrorText);
aa13cfd9 185
ae9cddaf
VK
186 void LIBNETXMS_EXPORTABLE InitSubAgentsLogger(void (* pFunc)(int, TCHAR *));
187
aa13cfd9 188#ifdef _WIN32
018fda4d 189 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, int iBufSize);
aa13cfd9 190#endif
696fc54f
VK
191
192#if !(HAVE_DAEMON)
b1a57444 193 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 194#endif
4332e9d8 195
268774a0
VK
196 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(WCHAR *pszAddr);
197
4332e9d8 198#ifndef _WIN32
73118723 199#if !(HAVE_WCSLEN)
4332e9d8 200 int LIBNETXMS_EXPORTABLE wcslen(WCHAR *pStr);
73118723 201#endif
4332e9d8
VK
202 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, WCHAR *pWideCharStr,
203 int cchWideChar, char *pByteStr, int cchByteChar,
204 char *pDefaultChar, BOOL *pbUsedDefChar);
205 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, char *pByteStr,
206 int cchByteChar, WCHAR *pWideCharStr,
207 int cchWideChar);
208#endif
b50f1100
VK
209
210#if !(HAVE_STRTOLL)
211 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
212#endif
213#if !(HAVE_STRTOULL)
214 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
215#endif
216
217#ifdef __cplusplus
e9246d26 218}
b50f1100 219#endif
e9246d26
VK
220
221#endif /* _nms_util_h_ */