Commit | Line | Data |
---|---|---|
76b4edb5 | 1 | /* |
5039dede AK |
2 | ** NetXMS - Network Management System |
3 | ** Server Library | |
ed950274 | 4 | ** Copyright (C) 2003-2013 Victor Kirhenshtein |
5039dede AK |
5 | ** |
6 | ** This program is free software; you can redistribute it and/or modify | |
0702ed69 VK |
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 | |
5039dede AK |
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 | ** | |
0702ed69 | 16 | ** You should have received a copy of the GNU Lesser General Public License |
5039dede AK |
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: nxsrvapi.h | |
21 | ** | |
22 | **/ | |
23 | ||
24 | #ifndef _nxsrvapi_h_ | |
25 | #define _nxsrvapi_h_ | |
26 | ||
27 | #ifdef _WIN32 | |
28 | #ifdef LIBNXSRV_EXPORTS | |
29 | #define LIBNXSRV_EXPORTABLE __declspec(dllexport) | |
30 | #else | |
31 | #define LIBNXSRV_EXPORTABLE __declspec(dllimport) | |
32 | #endif | |
33 | #else /* _WIN32 */ | |
34 | #define LIBNXSRV_EXPORTABLE | |
35 | #endif | |
36 | ||
5039dede | 37 | #include <nxcpapi.h> |
bf6fb6c3 | 38 | #include <nms_util.h> |
5039dede | 39 | #include <nms_agent.h> |
5039dede AK |
40 | #include <nxsnmp.h> |
41 | #include <netxms_isc.h> | |
bf6fb6c3 | 42 | #include <nxcldefs.h> |
5039dede | 43 | |
f1a3b4fe | 44 | #ifdef INCLUDE_LIBNXSRV_MESSAGES |
45 | #include "../libnxsrv/messages.h" | |
46 | #endif | |
47 | ||
f375019e VK |
48 | /** |
49 | * Default files | |
50 | */ | |
5039dede AK |
51 | #ifdef _WIN32 |
52 | ||
9796ce45 VK |
53 | #define DEFAULT_CONFIG_FILE _T("C:\\netxmsd.conf") |
54 | ||
55 | #define DEFAULT_SHELL _T("cmd.exe") | |
56 | #define DEFAULT_LOG_FILE _T("C:\\NetXMS.log") | |
57 | #define DEFAULT_DATA_DIR _T("C:\\NetXMS\\var") | |
58 | #define DEFAULT_LIBDIR _T("C:\\NetXMS\\lib") | |
59 | #define DEFAULT_DUMP_DIR _T("C:\\") | |
60 | ||
61 | #define LDIR_NDD _T("\\ndd") | |
8fd95c92 | 62 | #define LDIR_PDSDRV _T("\\pdsdrv") |
9796ce45 VK |
63 | |
64 | #define DDIR_MIBS _T("\\mibs") | |
65 | #define DDIR_PACKAGES _T("\\packages") | |
66 | #define DDIR_BACKGROUNDS _T("\\backgrounds") | |
67 | #define DDIR_SHARED_FILES _T("\\shared") | |
68 | #define DFILE_KEYS _T("\\server_key") | |
69 | #define DFILE_COMPILED_MIB _T("\\mibs\\netxms.mib") | |
70 | #define DDIR_IMAGES _T("\\images") | |
71 | #define DDIR_FILES _T("\\files") | |
e77e56ca | 72 | #define DDIR_REPORTS _T("\\reports") |
5039dede AK |
73 | |
74 | #else /* _WIN32 */ | |
75 | ||
9796ce45 | 76 | #define DEFAULT_CONFIG_FILE _T("{search}") |
5039dede | 77 | |
9796ce45 | 78 | #define DEFAULT_SHELL _T("/bin/sh") |
5039dede | 79 | |
9796ce45 VK |
80 | #ifndef DATADIR |
81 | #define DATADIR _T("/var/netxms") | |
82 | #endif | |
5039dede | 83 | |
9796ce45 VK |
84 | #ifndef LIBDIR |
85 | #define LIBDIR _T("/usr/lib") | |
86 | #endif | |
5039dede | 87 | |
644f97f5 VK |
88 | #ifndef PKGLIBDIR |
89 | #define PKGLIBDIR _T("/usr/lib/netxms") | |
90 | #endif | |
91 | ||
9796ce45 VK |
92 | #define DEFAULT_LOG_FILE DATADIR _T("/log/netxmsd.log") |
93 | #define DEFAULT_DATA_DIR DATADIR | |
644f97f5 | 94 | #define DEFAULT_LIBDIR PKGLIBDIR |
9796ce45 VK |
95 | #define DEFAULT_DUMP_DIR _T("/") |
96 | ||
97 | #define LDIR_NDD _T("/ndd") | |
8fd95c92 | 98 | #define LDIR_PDSDRV _T("/pdsdrv") |
9796ce45 VK |
99 | |
100 | #define DDIR_MIBS _T("/mibs") | |
101 | #define DDIR_PACKAGES _T("/packages") | |
102 | #define DDIR_BACKGROUNDS _T("/backgrounds") | |
103 | #define DDIR_SHARED_FILES _T("/shared") | |
104 | #define DFILE_KEYS _T("/.server_key") | |
105 | #define DFILE_COMPILED_MIB _T("/mibs/netxms.mib") | |
106 | #define DDIR_IMAGES _T("/images") | |
107 | #define DDIR_FILES _T("/files") | |
e77e56ca | 108 | #define DDIR_REPORTS _T("/reports") |
5039dede AK |
109 | |
110 | #endif /* _WIN32 */ | |
111 | ||
f375019e VK |
112 | /** |
113 | * Application flags | |
114 | */ | |
c8076b19 VK |
115 | #define AF_DAEMON _ULL(0x0000000000000001) |
116 | #define AF_USE_SYSLOG _ULL(0x0000000000000002) | |
117 | #define AF_ENABLE_NETWORK_DISCOVERY _ULL(0x0000000000000004) | |
118 | #define AF_ACTIVE_NETWORK_DISCOVERY _ULL(0x0000000000000008) | |
119 | #define AF_LOG_SQL_ERRORS _ULL(0x0000000000000010) | |
120 | #define AF_DELETE_EMPTY_SUBNETS _ULL(0x0000000000000020) | |
121 | #define AF_ENABLE_SNMP_TRAPD _ULL(0x0000000000000040) | |
122 | #define AF_ENABLE_ZONING _ULL(0x0000000000000080) | |
123 | #define AF_SYNC_NODE_NAMES_WITH_DNS _ULL(0x0000000000000100) | |
124 | #define AF_CHECK_TRUSTED_NODES _ULL(0x0000000000000200) | |
125 | #define AF_ENABLE_NXSL_CONTAINER_FUNCS _ULL(0x0000000000000400) | |
126 | #define AF_USE_FQDN_FOR_NODE_NAMES _ULL(0x0000000000000800) | |
127 | #define AF_APPLY_TO_DISABLED_DCI_FROM_TEMPLATE _ULL(0x0000000000001000) | |
128 | #define AF_DEBUG_CONSOLE_DISABLED _ULL(0x0000000000002000) | |
129 | #define AF_ENABLE_OBJECT_TRANSACTIONS _ULL(0x0000000000004000) | |
130 | #define AF_WRITE_FULL_DUMP _ULL(0x0000000000080000) | |
131 | #define AF_RESOLVE_NODE_NAMES _ULL(0x0000000000100000) | |
132 | #define AF_CATCH_EXCEPTIONS _ULL(0x0000000000200000) | |
133 | #define AF_HELPDESK_LINK_ACTIVE _ULL(0x0000000000400000) | |
134 | #define AF_DB_CONNECTION_POOL_READY _ULL(0x0000000000800000) | |
135 | #define AF_DB_LOCKED _ULL(0x0000000001000000) | |
136 | #define AF_ENABLE_MULTIPLE_DB_CONN _ULL(0x0000000002000000) | |
137 | #define AF_DB_CONNECTION_LOST _ULL(0x0000000004000000) | |
138 | #define AF_NO_NETWORK_CONNECTIVITY _ULL(0x0000000008000000) | |
139 | #define AF_EVENT_STORM_DETECTED _ULL(0x0000000010000000) | |
140 | #define AF_SNMP_TRAP_DISCOVERY _ULL(0x0000000020000000) | |
141 | #define AF_TRAPS_FROM_UNMANAGED_NODES _ULL(0x0000000040000000) | |
385b1f20 | 142 | #define AF_RESOLVE_IP_FOR_EACH_STATUS_POLL _ULL(0x0000000080000000) |
4e0e77e6 VK |
143 | #define AF_PERFDATA_STORAGE_DRIVER_LOADED _ULL(0x0000000100000000) |
144 | #define AF_BACKGROUND_LOG_WRITER _ULL(0x0000000200000000) | |
c8076b19 VK |
145 | #define AF_SERVER_INITIALIZED _ULL(0x4000000000000000) |
146 | #define AF_SHUTDOWN _ULL(0x8000000000000000) | |
5039dede | 147 | |
f375019e VK |
148 | /** |
149 | * Encryption usage policies | |
150 | */ | |
5039dede AK |
151 | #define ENCRYPTION_DISABLED 0 |
152 | #define ENCRYPTION_ALLOWED 1 | |
153 | #define ENCRYPTION_PREFERRED 2 | |
154 | #define ENCRYPTION_REQUIRED 3 | |
155 | ||
f375019e VK |
156 | /** |
157 | * Flags for SnmpGet | |
158 | */ | |
5ad2167d VK |
159 | #define SG_VERBOSE 0x0001 |
160 | #define SG_STRING_RESULT 0x0002 | |
161 | #define SG_RAW_RESULT 0x0004 | |
162 | #define SG_HSTRING_RESULT 0x0008 | |
4f131f2f | 163 | #define SG_PSTRING_RESULT 0x0010 |
5ad2167d | 164 | |
908d71bd VK |
165 | /** |
166 | * Agent action output callback events | |
167 | */ | |
168 | enum ActionCallbackEvent | |
169 | { | |
170 | ACE_CONNECTED = 0, | |
171 | ACE_DATA = 1, | |
172 | ACE_DISCONNECTED = 2 | |
173 | }; | |
174 | ||
f375019e VK |
175 | /** |
176 | * Win32 service and syslog constants | |
177 | */ | |
5039dede AK |
178 | #ifdef _WIN32 |
179 | ||
180 | #define CORE_SERVICE_NAME _T("NetXMSCore") | |
181 | #define CORE_EVENT_SOURCE _T("NetXMSCore") | |
182 | #define NETXMSD_SYSLOG_NAME CORE_EVENT_SOURCE | |
183 | ||
184 | #else | |
185 | ||
186 | #define NETXMSD_SYSLOG_NAME _T("netxmsd") | |
187 | ||
188 | #endif /* _WIN32 */ | |
189 | ||
f375019e VK |
190 | /** |
191 | * Single ARP cache entry | |
192 | */ | |
5039dede AK |
193 | typedef struct |
194 | { | |
967893bb VK |
195 | UINT32 dwIndex; // Interface index |
196 | UINT32 dwIpAddr; | |
5039dede AK |
197 | BYTE bMacAddr[MAC_ADDR_LENGTH]; |
198 | } ARP_ENTRY; | |
199 | ||
f375019e VK |
200 | /** |
201 | * ARP cache structure used by discovery functions and AgentConnection class | |
202 | */ | |
5039dede AK |
203 | typedef struct |
204 | { | |
967893bb | 205 | UINT32 dwNumEntries; |
5039dede AK |
206 | ARP_ENTRY *pEntries; |
207 | } ARP_CACHE; | |
208 | ||
f375019e VK |
209 | /** |
210 | * Interface information structure used by discovery functions and AgentConnection class | |
211 | */ | |
5039dede AK |
212 | typedef struct |
213 | { | |
478d4ff4 VK |
214 | TCHAR szName[MAX_DB_STRING]; // Interface display name |
215 | TCHAR szDescription[MAX_DB_STRING]; // Value of ifDescr MIB variable for SNMP agents | |
967893bb VK |
216 | UINT32 dwIndex; |
217 | UINT32 dwType; | |
218 | UINT32 dwBridgePortNumber; | |
219 | UINT32 dwSlotNumber; | |
220 | UINT32 dwPortNumber; | |
221 | UINT32 dwIpAddr; | |
222 | UINT32 dwIpNetMask; | |
5039dede AK |
223 | BYTE bMacAddr[MAC_ADDR_LENGTH]; |
224 | int iNumSecondary; // Number of secondary IP's on this interface | |
4c16cdc7 | 225 | bool isPhysicalPort; |
01152a54 | 226 | bool isSystem; |
36e44abe | 227 | } NX_INTERFACE_INFO; |
5039dede | 228 | |
f375019e VK |
229 | /** |
230 | * Interface list used by discovery functions and AgentConnection class | |
231 | */ | |
98762401 | 232 | class LIBNXSRV_EXPORTABLE InterfaceList |
5039dede | 233 | { |
98762401 VK |
234 | private: |
235 | int m_size; // Number of valid entries | |
236 | int m_allocated; // Number of allocated entries | |
237 | void *m_data; // Can be used by custom enumeration handlers | |
36e44abe | 238 | NX_INTERFACE_INFO *m_interfaces; // Interface entries |
98762401 VK |
239 | |
240 | public: | |
241 | InterfaceList(int initialAlloc = 8); | |
242 | ~InterfaceList(); | |
243 | ||
36e44abe | 244 | void add(NX_INTERFACE_INFO *iface); |
98762401 | 245 | void remove(int index); |
98762401 | 246 | |
a6312bd6 | 247 | int size() { return m_size; } |
36e44abe | 248 | NX_INTERFACE_INFO *get(int index) { return ((index >= 0) && (index < m_size)) ? &m_interfaces[index] : NULL; } |
967893bb | 249 | NX_INTERFACE_INFO *findByIfIndex(UINT32 ifIndex); |
98762401 VK |
250 | |
251 | void setData(void *data) { m_data = data; } | |
252 | void *getData() { return m_data; } | |
253 | }; | |
5039dede | 254 | |
f375019e VK |
255 | /** |
256 | * Vlan information | |
257 | */ | |
0208aa8c VK |
258 | #define VLAN_PRM_IFINDEX 0 |
259 | #define VLAN_PRM_SLOTPORT 1 | |
5eb3a790 | 260 | #define VLAN_PRM_BPORT 2 |
0208aa8c | 261 | |
77c7801c VK |
262 | class LIBNXSRV_EXPORTABLE VlanInfo |
263 | { | |
264 | private: | |
265 | int m_vlanId; | |
266 | TCHAR *m_name; | |
0208aa8c | 267 | int m_portRefMode; // Port reference mode - by ifIndex or by slot/port |
77c7801c VK |
268 | int m_allocated; |
269 | int m_numPorts; // Number of ports in VLAN | |
967893bb VK |
270 | UINT32 *m_ports; // member ports (slot/port pairs or ifIndex) |
271 | UINT32 *m_indexes; // ifIndexes for ports | |
272 | UINT32 *m_ids; // Interface object IDs for ports | |
77c7801c VK |
273 | |
274 | public: | |
0208aa8c | 275 | VlanInfo(int vlanId, int prm); |
77c7801c VK |
276 | ~VlanInfo(); |
277 | ||
278 | int getVlanId() { return m_vlanId; } | |
0208aa8c | 279 | int getPortReferenceMode() { return m_portRefMode; } |
77c7801c VK |
280 | const TCHAR *getName() { return CHECK_NULL_EX(m_name); } |
281 | int getNumPorts() { return m_numPorts; } | |
967893bb VK |
282 | UINT32 *getPorts() { return m_ports; } |
283 | UINT32 *getIfIndexes() { return m_indexes; } | |
284 | UINT32 *getIfIds() { return m_ids; } | |
77c7801c | 285 | |
967893bb VK |
286 | void add(UINT32 slot, UINT32 port); |
287 | void add(UINT32 ifIndex); | |
77c7801c | 288 | void setName(const TCHAR *name); |
b1bd1fb2 VK |
289 | |
290 | void prepareForResolve(); | |
967893bb | 291 | void resolvePort(int index, UINT32 sp, UINT32 ifIndex, UINT32 id); |
77c7801c VK |
292 | }; |
293 | ||
a3050773 VK |
294 | /** |
295 | * Vlan list | |
296 | */ | |
7f632dfe | 297 | class LIBNXSRV_EXPORTABLE VlanList : public RefCountObject |
77c7801c VK |
298 | { |
299 | private: | |
300 | int m_size; // Number of valid entries | |
301 | int m_allocated; // Number of allocated entries | |
302 | void *m_data; // Can be used by custom enumeration handlers | |
303 | VlanInfo **m_vlans; // VLAN entries | |
304 | ||
305 | public: | |
306 | VlanList(int initialAlloc = 8); | |
7f632dfe | 307 | virtual ~VlanList(); |
77c7801c VK |
308 | |
309 | void add(VlanInfo *vlan); | |
967893bb | 310 | void addMemberPort(int vlanId, UINT32 portId); |
77c7801c | 311 | |
a6312bd6 | 312 | int size() { return m_size; } |
77c7801c | 313 | VlanInfo *get(int index) { return ((index >= 0) && (index < m_size)) ? m_vlans[index] : NULL; } |
0208aa8c | 314 | VlanInfo *findById(int id); |
0239cfea | 315 | VlanInfo *findByName(const TCHAR *name); |
77c7801c VK |
316 | |
317 | void setData(void *data) { m_data = data; } | |
318 | void *getData() { return m_data; } | |
7f632dfe | 319 | |
b368969c | 320 | void fillMessage(NXCPMessage *msg); |
77c7801c VK |
321 | }; |
322 | ||
a3050773 VK |
323 | /** |
324 | * Route information | |
325 | */ | |
5039dede AK |
326 | typedef struct |
327 | { | |
967893bb VK |
328 | UINT32 dwDestAddr; |
329 | UINT32 dwDestMask; | |
330 | UINT32 dwNextHop; | |
331 | UINT32 dwIfIndex; | |
332 | UINT32 dwRouteType; | |
5039dede AK |
333 | } ROUTE; |
334 | ||
a3050773 VK |
335 | /** |
336 | * Routing table | |
337 | */ | |
5039dede AK |
338 | typedef struct |
339 | { | |
340 | int iNumEntries; // Number of entries | |
341 | ROUTE *pRoutes; // Route list | |
342 | } ROUTING_TABLE; | |
343 | ||
a3050773 VK |
344 | /** |
345 | * Information about policies installed on agent | |
346 | */ | |
1f385e47 VK |
347 | class LIBNXSRV_EXPORTABLE AgentPolicyInfo |
348 | { | |
349 | private: | |
350 | int m_size; | |
351 | BYTE *m_guidList; | |
352 | int *m_typeList; | |
353 | TCHAR **m_serverList; | |
354 | ||
355 | public: | |
b368969c | 356 | AgentPolicyInfo(NXCPMessage *msg); |
1f385e47 VK |
357 | ~AgentPolicyInfo(); |
358 | ||
a6312bd6 | 359 | int size() { return m_size; } |
1f385e47 VK |
360 | bool getGuid(int index, uuid_t guid); |
361 | int getType(int index) { return ((index >= 0) && (index < m_size)) ? m_typeList[index] : -1; } | |
362 | const TCHAR *getServer(int index) { return ((index >= 0) && (index < m_size)) ? m_serverList[index] : NULL; } | |
363 | }; | |
364 | ||
86c126f5 VK |
365 | /** |
366 | * Agent parameter definition | |
367 | */ | |
368 | class LIBNXSRV_EXPORTABLE AgentParameterDefinition | |
369 | { | |
370 | private: | |
371 | TCHAR *m_name; | |
372 | TCHAR *m_description; | |
373 | int m_dataType; | |
374 | ||
375 | public: | |
b368969c | 376 | AgentParameterDefinition(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
377 | AgentParameterDefinition(AgentParameterDefinition *src); |
378 | ~AgentParameterDefinition(); | |
379 | ||
b368969c | 380 | UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
381 | |
382 | const TCHAR *getName() { return m_name; } | |
383 | const TCHAR *getDescription() { return m_description; } | |
384 | int getDataType() { return m_dataType; } | |
385 | }; | |
386 | ||
387 | /** | |
388 | * Agent table column definition | |
389 | */ | |
390 | struct AgentTableColumnDefinition | |
391 | { | |
392 | TCHAR m_name[MAX_COLUMN_NAME]; | |
393 | int m_dataType; | |
394 | ||
395 | AgentTableColumnDefinition(AgentTableColumnDefinition *src) | |
396 | { | |
397 | nx_strncpy(m_name, src->m_name, MAX_COLUMN_NAME); | |
398 | m_dataType = src->m_dataType; | |
399 | } | |
400 | }; | |
401 | ||
402 | /** | |
403 | * Agent table definition | |
404 | */ | |
405 | class LIBNXSRV_EXPORTABLE AgentTableDefinition | |
406 | { | |
407 | private: | |
408 | TCHAR *m_name; | |
409 | TCHAR *m_description; | |
410 | StringList *m_instanceColumns; | |
411 | ObjectArray<AgentTableColumnDefinition> *m_columns; | |
412 | ||
413 | public: | |
b368969c | 414 | AgentTableDefinition(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
415 | AgentTableDefinition(AgentTableDefinition *src); |
416 | ~AgentTableDefinition(); | |
417 | ||
b368969c | 418 | UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
419 | |
420 | const TCHAR *getName() { return m_name; } | |
421 | const TCHAR *getDescription() { return m_description; } | |
422 | }; | |
423 | ||
a3050773 VK |
424 | /** |
425 | * Agent connection | |
426 | */ | |
5039dede AK |
427 | class LIBNXSRV_EXPORTABLE AgentConnection |
428 | { | |
429 | private: | |
967893bb | 430 | UINT32 m_dwAddr; |
5039dede AK |
431 | int m_nProtocolVersion; |
432 | int m_iAuthMethod; | |
08b214c6 | 433 | char m_szSecret[MAX_SECRET_LENGTH]; |
5039dede AK |
434 | time_t m_tLastCommandTime; |
435 | SOCKET m_hSocket; | |
967893bb VK |
436 | UINT32 m_dwNumDataLines; |
437 | UINT32 m_dwRequestId; | |
438 | UINT32 m_dwCommandTimeout; | |
439 | UINT32 m_connectionTimeout; | |
440 | UINT32 m_dwRecvTimeout; | |
5039dede AK |
441 | TCHAR **m_ppDataLines; |
442 | MsgWaitQueue *m_pMsgWaitQueue; | |
443 | BOOL m_bIsConnected; | |
444 | MUTEX m_mutexDataLock; | |
d3a7cf4c | 445 | MUTEX m_mutexSocketWrite; |
5039dede | 446 | THREAD m_hReceiverThread; |
98abc9f1 | 447 | NXCPEncryptionContext *m_pCtx; |
5039dede AK |
448 | int m_iEncryptionPolicy; |
449 | BOOL m_bUseProxy; | |
967893bb | 450 | UINT32 m_dwProxyAddr; |
5039dede AK |
451 | WORD m_wPort; |
452 | WORD m_wProxyPort; | |
453 | int m_iProxyAuth; | |
08b214c6 | 454 | char m_szProxySecret[MAX_SECRET_LENGTH]; |
5039dede | 455 | int m_hCurrFile; |
9f6d453a | 456 | TCHAR m_currentFileName[MAX_PATH]; |
967893bb | 457 | UINT32 m_dwDownloadRequestId; |
bb85e341 VK |
458 | CONDITION m_condFileDownload; |
459 | BOOL m_fileDownloadSucceeded; | |
460 | void (*m_downloadProgressCallback)(size_t, void *); | |
461 | void *m_downloadProgressCallbackArg; | |
901a5a9b | 462 | bool m_deleteFileOnDownloadFailure; |
b368969c | 463 | void (*m_sendToClientMessageCallback)(NXCP_MESSAGE*, void *); |
4685a2ad | 464 | bool m_fileUploadInProgress; |
5039dede | 465 | |
a3050773 VK |
466 | void receiverThread(); |
467 | static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *); | |
5039dede AK |
468 | |
469 | protected: | |
7c521895 | 470 | void destroyResultData(); |
967893bb VK |
471 | UINT32 waitForRCC(UINT32 dwRqId, UINT32 dwTimeOut); |
472 | UINT32 setupEncryption(RSA *pServerKey); | |
473 | UINT32 authenticate(BOOL bProxyData); | |
474 | UINT32 setupProxyConnection(); | |
475 | UINT32 getIpAddr() { return ntohl(m_dwAddr); } | |
b368969c | 476 | UINT32 prepareFileDownload(const TCHAR *fileName, UINT32 rqId, bool append, void (*downloadProgressCallback)(size_t, void *), void (*fileResendCallback)(NXCP_MESSAGE*, void *), void *cbArg); |
5039dede | 477 | |
af21affe | 478 | virtual void printMsg(const TCHAR *format, ...); |
b368969c VK |
479 | virtual void onTrap(NXCPMessage *pMsg); |
480 | virtual void onDataPush(NXCPMessage *msg); | |
481 | virtual void onFileMonitoringData(NXCPMessage *msg); | |
482 | virtual void onSnmpTrap(NXCPMessage *pMsg); | |
483 | virtual bool processCustomMessage(NXCPMessage *pMsg); | |
f480bdd4 | 484 | virtual void onFileDownload(BOOL success); |
5039dede | 485 | |
a3050773 VK |
486 | void lock() { MutexLock(m_mutexDataLock); } |
487 | void unlock() { MutexUnlock(m_mutexDataLock); } | |
98abc9f1 | 488 | NXCPEncryptionContext *acquireEncryptionContext(); |
5039dede AK |
489 | |
490 | public: | |
b368969c VK |
491 | BOOL sendMessage(NXCPMessage *pMsg); |
492 | NXCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut) { return m_pMsgWaitQueue->waitForMessage(wCode, dwId, dwTimeOut); } | |
69c6604d | 493 | AgentConnection(UINT32 ipAddr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL); |
5039dede AK |
494 | virtual ~AgentConnection(); |
495 | ||
967893bb | 496 | BOOL connect(RSA *pServerKey = NULL, BOOL bVerbose = FALSE, UINT32 *pdwError = NULL, UINT32 *pdwSocketError = NULL); |
7c521895 VK |
497 | void disconnect(); |
498 | BOOL isConnected() { return m_bIsConnected; } | |
499 | int getProtocolVersion() { return m_nProtocolVersion; } | |
5039dede | 500 | |
45d84f8a | 501 | SOCKET getSocket() { return m_hSocket; } |
5a9e58a3 | 502 | |
4687826e | 503 | ARP_CACHE *getArpCache(); |
98762401 | 504 | InterfaceList *getInterfaceList(); |
4687826e | 505 | ROUTING_TABLE *getRoutingTable(); |
967893bb VK |
506 | UINT32 getParameter(const TCHAR *pszParam, UINT32 dwBufSize, TCHAR *pszBuffer); |
507 | UINT32 getList(const TCHAR *pszParam); | |
508 | UINT32 getTable(const TCHAR *pszParam, Table **table); | |
509 | UINT32 nop(); | |
908d71bd | 510 | UINT32 execAction(const TCHAR *pszAction, int argc, TCHAR **argv, bool withOutput = false, void (* outputCallback)(ActionCallbackEvent, const TCHAR *, void *) = NULL, void *cbData = NULL); |
967893bb VK |
511 | UINT32 uploadFile(const TCHAR *localFile, const TCHAR *destinationFile = NULL, void (* progressCallback)(INT64, void *) = NULL, void *cbArg = NULL); |
512 | UINT32 startUpgrade(const TCHAR *pszPkgName); | |
76b4edb5 | 513 | UINT32 checkNetworkService(UINT32 *pdwStatus, UINT32 dwIpAddr, int iServiceType, WORD wPort = 0, |
b8014eee | 514 | WORD wProto = 0, const TCHAR *pszRequest = NULL, const TCHAR *pszResponse = NULL, UINT32 *responseTime = NULL); |
967893bb VK |
515 | UINT32 getSupportedParameters(ObjectArray<AgentParameterDefinition> **paramList, ObjectArray<AgentTableDefinition> **tableList); |
516 | UINT32 getConfigFile(TCHAR **ppszConfig, UINT32 *pdwSize); | |
517 | UINT32 updateConfigFile(const TCHAR *pszConfig); | |
518 | UINT32 enableTraps(); | |
519 | UINT32 getPolicyInventory(AgentPolicyInfo **info); | |
520 | UINT32 uninstallPolicy(uuid_t guid); | |
9c786c0f | 521 | UINT32 takeScreenshot(const TCHAR *sessionName, BYTE **data, size_t *size); |
967893bb VK |
522 | |
523 | UINT32 generateRequestId() { return m_dwRequestId++; } | |
b368969c VK |
524 | NXCPMessage *customRequest(NXCPMessage *pRequest, const TCHAR *recvFile = NULL, bool append = false, void (*downloadProgressCallback)(size_t, void *) = NULL, |
525 | void (*fileResendCallback)(NXCP_MESSAGE*, void *) = NULL, void *cbArg = NULL); | |
5039dede | 526 | |
967893bb VK |
527 | UINT32 getNumDataLines() { return m_dwNumDataLines; } |
528 | const TCHAR *getDataLine(UINT32 dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); } | |
5039dede | 529 | |
967893bb VK |
530 | void setConnectionTimeout(UINT32 dwTimeout) { m_connectionTimeout = max(dwTimeout, 1000); } |
531 | UINT32 getConnectionTimeout() { return m_connectionTimeout; } | |
532 | void setCommandTimeout(UINT32 dwTimeout) { m_dwCommandTimeout = max(dwTimeout, 500); } | |
533 | UINT32 getCommandTimeout() { return m_dwCommandTimeout; } | |
534 | void setRecvTimeout(UINT32 dwTimeout) { m_dwRecvTimeout = max(dwTimeout, 10000); } | |
7c521895 | 535 | void setEncryptionPolicy(int iPolicy) { m_iEncryptionPolicy = iPolicy; } |
967893bb | 536 | void setProxy(UINT32 dwAddr, WORD wPort = AGENT_LISTEN_PORT, |
5039dede | 537 | int iAuthMethod = AUTH_NONE, const TCHAR *pszSecret = NULL); |
7c521895 | 538 | void setPort(WORD wPort) { m_wPort = wPort; } |
af21affe | 539 | void setAuthData(int method, const TCHAR *secret); |
76b4edb5 | 540 | void setDeleteFileOnDownloadFailure(bool flag) { m_deleteFileOnDownloadFailure = flag; } |
b368969c | 541 | BOOL sendRawMessage(NXCP_MESSAGE *pMsg); |
5039dede AK |
542 | }; |
543 | ||
a3050773 VK |
544 | /** |
545 | * Proxy SNMP transport | |
546 | */ | |
5039dede AK |
547 | class LIBNXSRV_EXPORTABLE SNMP_ProxyTransport : public SNMP_Transport |
548 | { | |
549 | protected: | |
550 | AgentConnection *m_pAgentConnection; | |
b368969c | 551 | NXCPMessage *m_pResponse; |
967893bb | 552 | UINT32 m_dwIpAddr; |
5039dede | 553 | WORD m_wPort; |
489b117b | 554 | bool m_waitForResponse; |
5039dede AK |
555 | |
556 | public: | |
967893bb | 557 | SNMP_ProxyTransport(AgentConnection *pConn, UINT32 dwIpAddr, WORD wPort); |
5039dede AK |
558 | virtual ~SNMP_ProxyTransport(); |
559 | ||
967893bb | 560 | virtual int readMessage(SNMP_PDU **ppData, UINT32 dwTimeout = INFINITE, |
cd9f247e VK |
561 | struct sockaddr *pSender = NULL, socklen_t *piAddrSize = NULL, |
562 | SNMP_SecurityContext* (*contextFinder)(struct sockaddr *, socklen_t) = NULL); | |
c4366266 | 563 | virtual int sendMessage(SNMP_PDU *pdu); |
967893bb | 564 | virtual UINT32 getPeerIpAddress(); |
b368969c VK |
565 | |
566 | void setWaitForResponse(bool wait) { m_waitForResponse = wait; } | |
5039dede AK |
567 | }; |
568 | ||
596dc3aa VK |
569 | /** |
570 | * ISC flags | |
571 | */ | |
967893bb VK |
572 | #define ISCF_IS_CONNECTED ((UINT32)0x00000001) |
573 | #define ISCF_REQUIRE_ENCRYPTION ((UINT32)0x00000002) | |
5039dede | 574 | |
ed950274 VK |
575 | /** |
576 | * Inter-server connection (ISC) | |
577 | */ | |
5039dede AK |
578 | class LIBNXSRV_EXPORTABLE ISC |
579 | { | |
580 | private: | |
967893bb VK |
581 | UINT32 m_flags; |
582 | UINT32 m_addr; | |
5039dede AK |
583 | WORD m_port; |
584 | SOCKET m_socket; | |
585 | int m_protocolVersion; | |
bc7767c4 | 586 | VolatileCounter m_requestId; |
967893bb | 587 | UINT32 m_recvTimeout; |
5039dede AK |
588 | MsgWaitQueue *m_msgWaitQueue; |
589 | MUTEX m_mutexDataLock; | |
7b8b337e | 590 | MUTEX m_socketLock; |
5039dede | 591 | THREAD m_hReceiverThread; |
98abc9f1 | 592 | NXCPEncryptionContext *m_ctx; |
967893bb | 593 | UINT32 m_commandTimeout; |
5039dede | 594 | |
bc7767c4 VK |
595 | void receiverThread(); |
596 | static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *); | |
5039dede AK |
597 | |
598 | protected: | |
bc7767c4 VK |
599 | UINT32 setupEncryption(RSA *pServerKey); |
600 | UINT32 connectToService(UINT32 service); | |
5039dede | 601 | |
796baedf VK |
602 | void lock() { MutexLock(m_mutexDataLock); } |
603 | void unlock() { MutexUnlock(m_mutexDataLock); } | |
5039dede | 604 | |
796baedf | 605 | virtual void printMessage(const TCHAR *format, ...); |
b368969c VK |
606 | virtual void onBinaryMessage(NXCP_MESSAGE *rawMsg); |
607 | virtual bool onMessage(NXCPMessage *msg); | |
5039dede AK |
608 | |
609 | public: | |
610 | ISC(); | |
967893bb | 611 | ISC(UINT32 addr, WORD port = NETXMS_ISC_PORT); |
5039dede AK |
612 | virtual ~ISC(); |
613 | ||
bc7767c4 VK |
614 | UINT32 connect(UINT32 service, RSA *serverKey = NULL, BOOL requireEncryption = FALSE); |
615 | void disconnect(); | |
e7aff566 | 616 | bool connected() { return m_flags & ISCF_IS_CONNECTED; }; |
5039dede | 617 | |
b368969c VK |
618 | BOOL sendMessage(NXCPMessage *msg); |
619 | NXCPMessage *waitForMessage(WORD code, UINT32 id, UINT32 timeOut) { return m_msgWaitQueue->waitForMessage(code, id, timeOut); } | |
bc7767c4 VK |
620 | UINT32 waitForRCC(UINT32 rqId, UINT32 timeOut); |
621 | UINT32 generateMessageId() { return (UINT32)InterlockedIncrement(&m_requestId); } | |
5039dede | 622 | |
bc7767c4 | 623 | UINT32 nop(); |
5039dede AK |
624 | }; |
625 | ||
626 | ||
627 | // | |
628 | // Functions | |
629 | // | |
630 | ||
631 | void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache); | |
5039dede AK |
632 | void LIBNXSRV_EXPORTABLE DestroyRoutingTable(ROUTING_TABLE *pRT); |
633 | void LIBNXSRV_EXPORTABLE SortRoutingTable(ROUTING_TABLE *pRT); | |
bf6fb6c3 VK |
634 | const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(UINT32 err); |
635 | UINT32 LIBNXSRV_EXPORTABLE AgentErrorToRCC(UINT32 err); | |
5039dede | 636 | |
640b6719 | 637 | void LIBNXSRV_EXPORTABLE WriteLogOther(WORD wType, const TCHAR *format, ...) |
6e383343 | 638 | #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__)) |
640b6719 VK |
639 | __attribute__ ((format(printf, 2, 3))) |
640 | #endif | |
641 | ; | |
642 | ||
643 | void LIBNXSRV_EXPORTABLE DbgPrintf(int level, const TCHAR *format, ...) | |
6e383343 | 644 | #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__)) |
640b6719 VK |
645 | __attribute__ ((format(printf, 2, 3))) |
646 | #endif | |
647 | ; | |
648 | ||
9d88cdc9 | 649 | void LIBNXSRV_EXPORTABLE DbgPrintf2(int level, const TCHAR *format, va_list args); |
c20b2798 | 650 | |
5039dede AK |
651 | void LIBNXSRV_EXPORTABLE SetAgentDEP(int iPolicy); |
652 | ||
967893bb | 653 | const TCHAR LIBNXSRV_EXPORTABLE *ISCErrorCodeToText(UINT32 code); |
5039dede | 654 | |
967893bb | 655 | UINT32 LIBNXSRV_EXPORTABLE SnmpNewRequestId(); |
80ca5a43 | 656 | UINT32 LIBNXSRV_EXPORTABLE SnmpGet(int version, SNMP_Transport *transport, |
e0471fad VK |
657 | const TCHAR *szOidStr, const UINT32 *oidBinary, size_t oidLen, void *pValue, |
658 | size_t bufferSize, UINT32 dwFlags); | |
20c7bdf7 | 659 | UINT32 LIBNXSRV_EXPORTABLE SnmpGetEx(SNMP_Transport *pTransport, |
e0471fad VK |
660 | const TCHAR *szOidStr, const UINT32 *oidBinary, size_t oidLen, void *pValue, |
661 | size_t bufferSize, UINT32 dwFlags, UINT32 *dataLen); | |
967893bb VK |
662 | UINT32 LIBNXSRV_EXPORTABLE SnmpWalk(UINT32 dwVersion, SNMP_Transport *pTransport, const TCHAR *szRootOid, |
663 | UINT32 (* pHandler)(UINT32, SNMP_Variable *, SNMP_Transport *, void *), | |
46b7166d | 664 | void *pUserArg, BOOL bVerbose); |
5ad2167d | 665 | |
640b6719 VK |
666 | /** |
667 | * Variables | |
668 | */ | |
c8076b19 | 669 | extern UINT64 LIBNXSRV_EXPORTABLE g_flags; |
c42b4551 | 670 | extern UINT32 LIBNXSRV_EXPORTABLE g_snmpTimeout; |
967893bb | 671 | extern UINT32 LIBNXSRV_EXPORTABLE g_debugLevel; |
5039dede | 672 | |
640b6719 VK |
673 | /** |
674 | * Helper finctions for checking server flags | |
675 | */ | |
89135050 VK |
676 | inline bool IsStandalone() |
677 | { | |
c8076b19 | 678 | return !(g_flags & AF_DAEMON) ? true : false; |
89135050 VK |
679 | } |
680 | ||
681 | inline bool IsZoningEnabled() | |
682 | { | |
c8076b19 | 683 | return (g_flags & AF_ENABLE_ZONING) ? true : false; |
89135050 VK |
684 | } |
685 | ||
686 | inline bool IsShutdownInProgress() | |
687 | { | |
c8076b19 | 688 | return (g_flags & AF_SHUTDOWN) ? true : false; |
89135050 VK |
689 | } |
690 | ||
691 | ||
5039dede | 692 | #endif /* _nxsrvapi_h_ */ |