libnetxms changed to unicode
[public/netxms.git] / include / nms_util.h
1 /*
2 ** NetXMS - Network Management System
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
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
37 #include <nms_common.h>
38 #include <nms_cscp.h>
39 #include <nms_threads.h>
40 #include <time.h>
41
42 #if HAVE_BYTESWAP_H
43 #include <byteswap.h>
44 #endif
45
46 #define INVALID_INDEX 0xFFFFFFFF
47 #define CSCP_TEMP_BUF_SIZE 4096
48 #define MD5_DIGEST_SIZE 16
49 #define SHA1_DIGEST_SIZE 20
50
51
52 //
53 // Return codes for IcmpPing()
54 //
55
56 #define ICMP_SUCCESS 0
57 #define ICMP_UNREACHEABLE 1
58 #define ICMP_TIMEOUT 2
59 #define ICMP_RAW_SOCK_FAILED 3
60
61
62 //
63 // Token types for configuration loader
64 //
65
66 #define CT_LONG 0
67 #define CT_STRING 1
68 #define CT_STRING_LIST 2
69 #define CT_END_OF_LIST 3
70 #define CT_BOOLEAN 4
71 #define CT_WORD 5
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
87 typedef struct
88 {
89 TCHAR szToken[64];
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;
97
98
99 //
100 // getopt() prototype if needed
101 //
102
103 #ifdef _WIN32
104 #include <getopt.h>
105 #endif
106
107
108 //
109 // Functions
110 //
111
112
113 #if __BYTE_ORDER == __LITTLE_ENDIAN
114 #define htonq(x) __bswap_64(x)
115 #define ntohq(x) __bswap_64(x)
116 #define htond(x) __bswap_double(x)
117 #define ntohd(x) __bswap_double(x)
118 #else
119 #define htonq(x) (x)
120 #define ntohq(x) (x)
121 #define htond(x) (x)
122 #define ntohd(x) (x)
123 #endif
124
125 extern "C"
126 {
127 #if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
128 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
129 #endif
130 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
131
132 #if !defined(_WIN32) && !defined(_NETWARE)
133 void LIBNETXMS_EXPORTABLE strupr(TCHAR *in);
134 #endif
135
136 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
137
138 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
139 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
140
141 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
142
143 void LIBNETXMS_EXPORTABLE StrStrip(TCHAR *pszStr);
144 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
145 TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer);
146 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(TCHAR *pszName);
147
148 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *data, DWORD nbytes);
149 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, int nbytes, unsigned char *hash);
150 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, int nbytes, unsigned char *hash);
151 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(char *pszFileName, BYTE *pHash);
152 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(char *pszFileName, BYTE *pHash);
153
154 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout, DWORD *pdwRTT);
155
156 DWORD LIBNETXMS_EXPORTABLE NxLoadConfig(TCHAR *pszFileName, TCHAR *pszSection,
157 NX_CFG_TEMPLATE *pTemplateList, BOOL bPrint);
158
159 HMODULE LIBNETXMS_EXPORTABLE DLOpen(TCHAR *szLibName, TCHAR *pszErrorText);
160 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
161 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, TCHAR *szSymbol, TCHAR *pszErrorText);
162
163 #ifdef _WIN32
164 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, int iBufSize);
165 #endif
166
167 #if !(HAVE_DAEMON)
168 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
169 #endif
170 }
171
172 #endif /* _nms_util_h_ */