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 | { | |
e95680e5 VK |
214 | TCHAR name[MAX_DB_STRING]; // Interface display name |
215 | TCHAR description[MAX_DB_STRING]; // Value of ifDescr MIB variable for SNMP agents | |
216 | TCHAR alias[MAX_DB_STRING]; // Value of ifDescr MIB variable for SNMP agents | |
217 | UINT32 index; | |
218 | UINT32 type; | |
219 | UINT32 mtu; | |
220 | UINT32 bridgePort; | |
221 | UINT32 slot; | |
222 | UINT32 port; | |
223 | UINT32 ipAddr; | |
224 | UINT32 ipNetMask; | |
225 | BYTE macAddr[MAC_ADDR_LENGTH]; | |
226 | int numSecondary; // Number of secondary IP's on this interface | |
4c16cdc7 | 227 | bool isPhysicalPort; |
01152a54 | 228 | bool isSystem; |
36e44abe | 229 | } NX_INTERFACE_INFO; |
5039dede | 230 | |
f375019e VK |
231 | /** |
232 | * Interface list used by discovery functions and AgentConnection class | |
233 | */ | |
98762401 | 234 | class LIBNXSRV_EXPORTABLE InterfaceList |
5039dede | 235 | { |
98762401 VK |
236 | private: |
237 | int m_size; // Number of valid entries | |
238 | int m_allocated; // Number of allocated entries | |
239 | void *m_data; // Can be used by custom enumeration handlers | |
36e44abe | 240 | NX_INTERFACE_INFO *m_interfaces; // Interface entries |
f34e7a6e | 241 | bool m_needPrefixWalk; |
98762401 VK |
242 | |
243 | public: | |
244 | InterfaceList(int initialAlloc = 8); | |
245 | ~InterfaceList(); | |
246 | ||
36e44abe | 247 | void add(NX_INTERFACE_INFO *iface); |
98762401 | 248 | void remove(int index); |
98762401 | 249 | |
a6312bd6 | 250 | int size() { return m_size; } |
36e44abe | 251 | NX_INTERFACE_INFO *get(int index) { return ((index >= 0) && (index < m_size)) ? &m_interfaces[index] : NULL; } |
967893bb | 252 | NX_INTERFACE_INFO *findByIfIndex(UINT32 ifIndex); |
98762401 VK |
253 | |
254 | void setData(void *data) { m_data = data; } | |
255 | void *getData() { return m_data; } | |
f34e7a6e VK |
256 | |
257 | bool isPrefixWalkNeeded() { return m_needPrefixWalk; } | |
258 | void setPrefixWalkNeeded() { m_needPrefixWalk = true; } | |
98762401 | 259 | }; |
5039dede | 260 | |
f375019e VK |
261 | /** |
262 | * Vlan information | |
263 | */ | |
0208aa8c VK |
264 | #define VLAN_PRM_IFINDEX 0 |
265 | #define VLAN_PRM_SLOTPORT 1 | |
5eb3a790 | 266 | #define VLAN_PRM_BPORT 2 |
0208aa8c | 267 | |
77c7801c VK |
268 | class LIBNXSRV_EXPORTABLE VlanInfo |
269 | { | |
270 | private: | |
271 | int m_vlanId; | |
272 | TCHAR *m_name; | |
0208aa8c | 273 | int m_portRefMode; // Port reference mode - by ifIndex or by slot/port |
77c7801c VK |
274 | int m_allocated; |
275 | int m_numPorts; // Number of ports in VLAN | |
967893bb VK |
276 | UINT32 *m_ports; // member ports (slot/port pairs or ifIndex) |
277 | UINT32 *m_indexes; // ifIndexes for ports | |
278 | UINT32 *m_ids; // Interface object IDs for ports | |
77c7801c VK |
279 | |
280 | public: | |
0208aa8c | 281 | VlanInfo(int vlanId, int prm); |
77c7801c VK |
282 | ~VlanInfo(); |
283 | ||
284 | int getVlanId() { return m_vlanId; } | |
0208aa8c | 285 | int getPortReferenceMode() { return m_portRefMode; } |
77c7801c VK |
286 | const TCHAR *getName() { return CHECK_NULL_EX(m_name); } |
287 | int getNumPorts() { return m_numPorts; } | |
967893bb VK |
288 | UINT32 *getPorts() { return m_ports; } |
289 | UINT32 *getIfIndexes() { return m_indexes; } | |
290 | UINT32 *getIfIds() { return m_ids; } | |
77c7801c | 291 | |
967893bb VK |
292 | void add(UINT32 slot, UINT32 port); |
293 | void add(UINT32 ifIndex); | |
77c7801c | 294 | void setName(const TCHAR *name); |
b1bd1fb2 VK |
295 | |
296 | void prepareForResolve(); | |
967893bb | 297 | void resolvePort(int index, UINT32 sp, UINT32 ifIndex, UINT32 id); |
77c7801c VK |
298 | }; |
299 | ||
a3050773 VK |
300 | /** |
301 | * Vlan list | |
302 | */ | |
7f632dfe | 303 | class LIBNXSRV_EXPORTABLE VlanList : public RefCountObject |
77c7801c VK |
304 | { |
305 | private: | |
306 | int m_size; // Number of valid entries | |
307 | int m_allocated; // Number of allocated entries | |
308 | void *m_data; // Can be used by custom enumeration handlers | |
309 | VlanInfo **m_vlans; // VLAN entries | |
310 | ||
311 | public: | |
312 | VlanList(int initialAlloc = 8); | |
7f632dfe | 313 | virtual ~VlanList(); |
77c7801c VK |
314 | |
315 | void add(VlanInfo *vlan); | |
967893bb | 316 | void addMemberPort(int vlanId, UINT32 portId); |
77c7801c | 317 | |
a6312bd6 | 318 | int size() { return m_size; } |
77c7801c | 319 | VlanInfo *get(int index) { return ((index >= 0) && (index < m_size)) ? m_vlans[index] : NULL; } |
0208aa8c | 320 | VlanInfo *findById(int id); |
0239cfea | 321 | VlanInfo *findByName(const TCHAR *name); |
77c7801c VK |
322 | |
323 | void setData(void *data) { m_data = data; } | |
324 | void *getData() { return m_data; } | |
7f632dfe | 325 | |
b368969c | 326 | void fillMessage(NXCPMessage *msg); |
77c7801c VK |
327 | }; |
328 | ||
a3050773 VK |
329 | /** |
330 | * Route information | |
331 | */ | |
5039dede AK |
332 | typedef struct |
333 | { | |
967893bb VK |
334 | UINT32 dwDestAddr; |
335 | UINT32 dwDestMask; | |
336 | UINT32 dwNextHop; | |
337 | UINT32 dwIfIndex; | |
338 | UINT32 dwRouteType; | |
5039dede AK |
339 | } ROUTE; |
340 | ||
a3050773 VK |
341 | /** |
342 | * Routing table | |
343 | */ | |
5039dede AK |
344 | typedef struct |
345 | { | |
346 | int iNumEntries; // Number of entries | |
347 | ROUTE *pRoutes; // Route list | |
348 | } ROUTING_TABLE; | |
349 | ||
a3050773 VK |
350 | /** |
351 | * Information about policies installed on agent | |
352 | */ | |
1f385e47 VK |
353 | class LIBNXSRV_EXPORTABLE AgentPolicyInfo |
354 | { | |
355 | private: | |
356 | int m_size; | |
357 | BYTE *m_guidList; | |
358 | int *m_typeList; | |
359 | TCHAR **m_serverList; | |
360 | ||
361 | public: | |
b368969c | 362 | AgentPolicyInfo(NXCPMessage *msg); |
1f385e47 VK |
363 | ~AgentPolicyInfo(); |
364 | ||
a6312bd6 | 365 | int size() { return m_size; } |
1f385e47 VK |
366 | bool getGuid(int index, uuid_t guid); |
367 | int getType(int index) { return ((index >= 0) && (index < m_size)) ? m_typeList[index] : -1; } | |
368 | const TCHAR *getServer(int index) { return ((index >= 0) && (index < m_size)) ? m_serverList[index] : NULL; } | |
369 | }; | |
370 | ||
86c126f5 VK |
371 | /** |
372 | * Agent parameter definition | |
373 | */ | |
374 | class LIBNXSRV_EXPORTABLE AgentParameterDefinition | |
375 | { | |
376 | private: | |
377 | TCHAR *m_name; | |
378 | TCHAR *m_description; | |
379 | int m_dataType; | |
380 | ||
381 | public: | |
b368969c | 382 | AgentParameterDefinition(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
383 | AgentParameterDefinition(AgentParameterDefinition *src); |
384 | ~AgentParameterDefinition(); | |
385 | ||
b368969c | 386 | UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
387 | |
388 | const TCHAR *getName() { return m_name; } | |
389 | const TCHAR *getDescription() { return m_description; } | |
390 | int getDataType() { return m_dataType; } | |
391 | }; | |
392 | ||
393 | /** | |
394 | * Agent table column definition | |
395 | */ | |
396 | struct AgentTableColumnDefinition | |
397 | { | |
398 | TCHAR m_name[MAX_COLUMN_NAME]; | |
399 | int m_dataType; | |
400 | ||
401 | AgentTableColumnDefinition(AgentTableColumnDefinition *src) | |
402 | { | |
403 | nx_strncpy(m_name, src->m_name, MAX_COLUMN_NAME); | |
404 | m_dataType = src->m_dataType; | |
405 | } | |
406 | }; | |
407 | ||
408 | /** | |
409 | * Agent table definition | |
410 | */ | |
411 | class LIBNXSRV_EXPORTABLE AgentTableDefinition | |
412 | { | |
413 | private: | |
414 | TCHAR *m_name; | |
415 | TCHAR *m_description; | |
416 | StringList *m_instanceColumns; | |
417 | ObjectArray<AgentTableColumnDefinition> *m_columns; | |
418 | ||
419 | public: | |
b368969c | 420 | AgentTableDefinition(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
421 | AgentTableDefinition(AgentTableDefinition *src); |
422 | ~AgentTableDefinition(); | |
423 | ||
b368969c | 424 | UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
425 | |
426 | const TCHAR *getName() { return m_name; } | |
427 | const TCHAR *getDescription() { return m_description; } | |
428 | }; | |
429 | ||
a3050773 VK |
430 | /** |
431 | * Agent connection | |
432 | */ | |
5039dede AK |
433 | class LIBNXSRV_EXPORTABLE AgentConnection |
434 | { | |
435 | private: | |
c11eee9b | 436 | InetAddress m_addr; |
5039dede AK |
437 | int m_nProtocolVersion; |
438 | int m_iAuthMethod; | |
08b214c6 | 439 | char m_szSecret[MAX_SECRET_LENGTH]; |
5039dede AK |
440 | time_t m_tLastCommandTime; |
441 | SOCKET m_hSocket; | |
967893bb VK |
442 | UINT32 m_dwNumDataLines; |
443 | UINT32 m_dwRequestId; | |
444 | UINT32 m_dwCommandTimeout; | |
445 | UINT32 m_connectionTimeout; | |
446 | UINT32 m_dwRecvTimeout; | |
5039dede AK |
447 | TCHAR **m_ppDataLines; |
448 | MsgWaitQueue *m_pMsgWaitQueue; | |
449 | BOOL m_bIsConnected; | |
450 | MUTEX m_mutexDataLock; | |
d3a7cf4c | 451 | MUTEX m_mutexSocketWrite; |
5039dede | 452 | THREAD m_hReceiverThread; |
98abc9f1 | 453 | NXCPEncryptionContext *m_pCtx; |
5039dede AK |
454 | int m_iEncryptionPolicy; |
455 | BOOL m_bUseProxy; | |
c11eee9b | 456 | InetAddress m_proxyAddr; |
5039dede AK |
457 | WORD m_wPort; |
458 | WORD m_wProxyPort; | |
459 | int m_iProxyAuth; | |
08b214c6 | 460 | char m_szProxySecret[MAX_SECRET_LENGTH]; |
5039dede | 461 | int m_hCurrFile; |
9f6d453a | 462 | TCHAR m_currentFileName[MAX_PATH]; |
967893bb | 463 | UINT32 m_dwDownloadRequestId; |
bb85e341 VK |
464 | CONDITION m_condFileDownload; |
465 | BOOL m_fileDownloadSucceeded; | |
466 | void (*m_downloadProgressCallback)(size_t, void *); | |
467 | void *m_downloadProgressCallbackArg; | |
901a5a9b | 468 | bool m_deleteFileOnDownloadFailure; |
b368969c | 469 | void (*m_sendToClientMessageCallback)(NXCP_MESSAGE*, void *); |
4685a2ad | 470 | bool m_fileUploadInProgress; |
5039dede | 471 | |
a3050773 VK |
472 | void receiverThread(); |
473 | static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *); | |
5039dede AK |
474 | |
475 | protected: | |
7c521895 | 476 | void destroyResultData(); |
967893bb VK |
477 | UINT32 waitForRCC(UINT32 dwRqId, UINT32 dwTimeOut); |
478 | UINT32 setupEncryption(RSA *pServerKey); | |
479 | UINT32 authenticate(BOOL bProxyData); | |
480 | UINT32 setupProxyConnection(); | |
c11eee9b | 481 | const InetAddress& getIpAddr() { return m_addr; } |
b368969c | 482 | UINT32 prepareFileDownload(const TCHAR *fileName, UINT32 rqId, bool append, void (*downloadProgressCallback)(size_t, void *), void (*fileResendCallback)(NXCP_MESSAGE*, void *), void *cbArg); |
5039dede | 483 | |
af21affe | 484 | virtual void printMsg(const TCHAR *format, ...); |
b368969c VK |
485 | virtual void onTrap(NXCPMessage *pMsg); |
486 | virtual void onDataPush(NXCPMessage *msg); | |
487 | virtual void onFileMonitoringData(NXCPMessage *msg); | |
488 | virtual void onSnmpTrap(NXCPMessage *pMsg); | |
489 | virtual bool processCustomMessage(NXCPMessage *pMsg); | |
f480bdd4 | 490 | virtual void onFileDownload(BOOL success); |
5039dede | 491 | |
a3050773 VK |
492 | void lock() { MutexLock(m_mutexDataLock); } |
493 | void unlock() { MutexUnlock(m_mutexDataLock); } | |
98abc9f1 | 494 | NXCPEncryptionContext *acquireEncryptionContext(); |
5039dede AK |
495 | |
496 | public: | |
b368969c VK |
497 | BOOL sendMessage(NXCPMessage *pMsg); |
498 | NXCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut) { return m_pMsgWaitQueue->waitForMessage(wCode, dwId, dwTimeOut); } | |
c11eee9b | 499 | AgentConnection(InetAddress addr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL); |
5039dede AK |
500 | virtual ~AgentConnection(); |
501 | ||
967893bb | 502 | BOOL connect(RSA *pServerKey = NULL, BOOL bVerbose = FALSE, UINT32 *pdwError = NULL, UINT32 *pdwSocketError = NULL); |
7c521895 VK |
503 | void disconnect(); |
504 | BOOL isConnected() { return m_bIsConnected; } | |
505 | int getProtocolVersion() { return m_nProtocolVersion; } | |
5039dede | 506 | |
45d84f8a | 507 | SOCKET getSocket() { return m_hSocket; } |
5a9e58a3 | 508 | |
4687826e | 509 | ARP_CACHE *getArpCache(); |
98762401 | 510 | InterfaceList *getInterfaceList(); |
4687826e | 511 | ROUTING_TABLE *getRoutingTable(); |
967893bb VK |
512 | UINT32 getParameter(const TCHAR *pszParam, UINT32 dwBufSize, TCHAR *pszBuffer); |
513 | UINT32 getList(const TCHAR *pszParam); | |
514 | UINT32 getTable(const TCHAR *pszParam, Table **table); | |
515 | UINT32 nop(); | |
908d71bd | 516 | UINT32 execAction(const TCHAR *pszAction, int argc, TCHAR **argv, bool withOutput = false, void (* outputCallback)(ActionCallbackEvent, const TCHAR *, void *) = NULL, void *cbData = NULL); |
967893bb VK |
517 | UINT32 uploadFile(const TCHAR *localFile, const TCHAR *destinationFile = NULL, void (* progressCallback)(INT64, void *) = NULL, void *cbArg = NULL); |
518 | UINT32 startUpgrade(const TCHAR *pszPkgName); | |
76b4edb5 | 519 | UINT32 checkNetworkService(UINT32 *pdwStatus, UINT32 dwIpAddr, int iServiceType, WORD wPort = 0, |
b8014eee | 520 | WORD wProto = 0, const TCHAR *pszRequest = NULL, const TCHAR *pszResponse = NULL, UINT32 *responseTime = NULL); |
967893bb VK |
521 | UINT32 getSupportedParameters(ObjectArray<AgentParameterDefinition> **paramList, ObjectArray<AgentTableDefinition> **tableList); |
522 | UINT32 getConfigFile(TCHAR **ppszConfig, UINT32 *pdwSize); | |
523 | UINT32 updateConfigFile(const TCHAR *pszConfig); | |
524 | UINT32 enableTraps(); | |
525 | UINT32 getPolicyInventory(AgentPolicyInfo **info); | |
526 | UINT32 uninstallPolicy(uuid_t guid); | |
9c786c0f | 527 | UINT32 takeScreenshot(const TCHAR *sessionName, BYTE **data, size_t *size); |
967893bb VK |
528 | |
529 | UINT32 generateRequestId() { return m_dwRequestId++; } | |
b368969c VK |
530 | NXCPMessage *customRequest(NXCPMessage *pRequest, const TCHAR *recvFile = NULL, bool append = false, void (*downloadProgressCallback)(size_t, void *) = NULL, |
531 | void (*fileResendCallback)(NXCP_MESSAGE*, void *) = NULL, void *cbArg = NULL); | |
5039dede | 532 | |
967893bb VK |
533 | UINT32 getNumDataLines() { return m_dwNumDataLines; } |
534 | const TCHAR *getDataLine(UINT32 dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); } | |
5039dede | 535 | |
967893bb VK |
536 | void setConnectionTimeout(UINT32 dwTimeout) { m_connectionTimeout = max(dwTimeout, 1000); } |
537 | UINT32 getConnectionTimeout() { return m_connectionTimeout; } | |
538 | void setCommandTimeout(UINT32 dwTimeout) { m_dwCommandTimeout = max(dwTimeout, 500); } | |
539 | UINT32 getCommandTimeout() { return m_dwCommandTimeout; } | |
540 | void setRecvTimeout(UINT32 dwTimeout) { m_dwRecvTimeout = max(dwTimeout, 10000); } | |
7c521895 | 541 | void setEncryptionPolicy(int iPolicy) { m_iEncryptionPolicy = iPolicy; } |
c11eee9b | 542 | void setProxy(InetAddress addr, WORD wPort = AGENT_LISTEN_PORT, |
5039dede | 543 | int iAuthMethod = AUTH_NONE, const TCHAR *pszSecret = NULL); |
7c521895 | 544 | void setPort(WORD wPort) { m_wPort = wPort; } |
af21affe | 545 | void setAuthData(int method, const TCHAR *secret); |
76b4edb5 | 546 | void setDeleteFileOnDownloadFailure(bool flag) { m_deleteFileOnDownloadFailure = flag; } |
b368969c | 547 | BOOL sendRawMessage(NXCP_MESSAGE *pMsg); |
5039dede AK |
548 | }; |
549 | ||
a3050773 VK |
550 | /** |
551 | * Proxy SNMP transport | |
552 | */ | |
5039dede AK |
553 | class LIBNXSRV_EXPORTABLE SNMP_ProxyTransport : public SNMP_Transport |
554 | { | |
555 | protected: | |
556 | AgentConnection *m_pAgentConnection; | |
b368969c | 557 | NXCPMessage *m_pResponse; |
967893bb | 558 | UINT32 m_dwIpAddr; |
5039dede | 559 | WORD m_wPort; |
489b117b | 560 | bool m_waitForResponse; |
5039dede AK |
561 | |
562 | public: | |
967893bb | 563 | SNMP_ProxyTransport(AgentConnection *pConn, UINT32 dwIpAddr, WORD wPort); |
5039dede AK |
564 | virtual ~SNMP_ProxyTransport(); |
565 | ||
967893bb | 566 | virtual int readMessage(SNMP_PDU **ppData, UINT32 dwTimeout = INFINITE, |
cd9f247e VK |
567 | struct sockaddr *pSender = NULL, socklen_t *piAddrSize = NULL, |
568 | SNMP_SecurityContext* (*contextFinder)(struct sockaddr *, socklen_t) = NULL); | |
c4366266 | 569 | virtual int sendMessage(SNMP_PDU *pdu); |
967893bb | 570 | virtual UINT32 getPeerIpAddress(); |
b368969c VK |
571 | |
572 | void setWaitForResponse(bool wait) { m_waitForResponse = wait; } | |
5039dede AK |
573 | }; |
574 | ||
596dc3aa VK |
575 | /** |
576 | * ISC flags | |
577 | */ | |
967893bb VK |
578 | #define ISCF_IS_CONNECTED ((UINT32)0x00000001) |
579 | #define ISCF_REQUIRE_ENCRYPTION ((UINT32)0x00000002) | |
5039dede | 580 | |
ed950274 VK |
581 | /** |
582 | * Inter-server connection (ISC) | |
583 | */ | |
5039dede AK |
584 | class LIBNXSRV_EXPORTABLE ISC |
585 | { | |
586 | private: | |
967893bb VK |
587 | UINT32 m_flags; |
588 | UINT32 m_addr; | |
5039dede AK |
589 | WORD m_port; |
590 | SOCKET m_socket; | |
591 | int m_protocolVersion; | |
bc7767c4 | 592 | VolatileCounter m_requestId; |
967893bb | 593 | UINT32 m_recvTimeout; |
5039dede AK |
594 | MsgWaitQueue *m_msgWaitQueue; |
595 | MUTEX m_mutexDataLock; | |
7b8b337e | 596 | MUTEX m_socketLock; |
5039dede | 597 | THREAD m_hReceiverThread; |
98abc9f1 | 598 | NXCPEncryptionContext *m_ctx; |
967893bb | 599 | UINT32 m_commandTimeout; |
5039dede | 600 | |
bc7767c4 VK |
601 | void receiverThread(); |
602 | static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *); | |
5039dede AK |
603 | |
604 | protected: | |
bc7767c4 VK |
605 | UINT32 setupEncryption(RSA *pServerKey); |
606 | UINT32 connectToService(UINT32 service); | |
5039dede | 607 | |
796baedf VK |
608 | void lock() { MutexLock(m_mutexDataLock); } |
609 | void unlock() { MutexUnlock(m_mutexDataLock); } | |
5039dede | 610 | |
796baedf | 611 | virtual void printMessage(const TCHAR *format, ...); |
b368969c VK |
612 | virtual void onBinaryMessage(NXCP_MESSAGE *rawMsg); |
613 | virtual bool onMessage(NXCPMessage *msg); | |
5039dede AK |
614 | |
615 | public: | |
616 | ISC(); | |
967893bb | 617 | ISC(UINT32 addr, WORD port = NETXMS_ISC_PORT); |
5039dede AK |
618 | virtual ~ISC(); |
619 | ||
bc7767c4 VK |
620 | UINT32 connect(UINT32 service, RSA *serverKey = NULL, BOOL requireEncryption = FALSE); |
621 | void disconnect(); | |
e7aff566 | 622 | bool connected() { return m_flags & ISCF_IS_CONNECTED; }; |
5039dede | 623 | |
b368969c VK |
624 | BOOL sendMessage(NXCPMessage *msg); |
625 | NXCPMessage *waitForMessage(WORD code, UINT32 id, UINT32 timeOut) { return m_msgWaitQueue->waitForMessage(code, id, timeOut); } | |
bc7767c4 VK |
626 | UINT32 waitForRCC(UINT32 rqId, UINT32 timeOut); |
627 | UINT32 generateMessageId() { return (UINT32)InterlockedIncrement(&m_requestId); } | |
5039dede | 628 | |
bc7767c4 | 629 | UINT32 nop(); |
5039dede AK |
630 | }; |
631 | ||
632 | ||
633 | // | |
634 | // Functions | |
635 | // | |
636 | ||
637 | void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache); | |
5039dede AK |
638 | void LIBNXSRV_EXPORTABLE DestroyRoutingTable(ROUTING_TABLE *pRT); |
639 | void LIBNXSRV_EXPORTABLE SortRoutingTable(ROUTING_TABLE *pRT); | |
bf6fb6c3 VK |
640 | const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(UINT32 err); |
641 | UINT32 LIBNXSRV_EXPORTABLE AgentErrorToRCC(UINT32 err); | |
5039dede | 642 | |
640b6719 | 643 | void LIBNXSRV_EXPORTABLE WriteLogOther(WORD wType, const TCHAR *format, ...) |
6e383343 | 644 | #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__)) |
640b6719 VK |
645 | __attribute__ ((format(printf, 2, 3))) |
646 | #endif | |
647 | ; | |
648 | ||
649 | void LIBNXSRV_EXPORTABLE DbgPrintf(int level, const TCHAR *format, ...) | |
6e383343 | 650 | #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__)) |
640b6719 VK |
651 | __attribute__ ((format(printf, 2, 3))) |
652 | #endif | |
653 | ; | |
654 | ||
9d88cdc9 | 655 | void LIBNXSRV_EXPORTABLE DbgPrintf2(int level, const TCHAR *format, va_list args); |
c20b2798 | 656 | |
5039dede AK |
657 | void LIBNXSRV_EXPORTABLE SetAgentDEP(int iPolicy); |
658 | ||
967893bb | 659 | const TCHAR LIBNXSRV_EXPORTABLE *ISCErrorCodeToText(UINT32 code); |
5039dede | 660 | |
967893bb | 661 | UINT32 LIBNXSRV_EXPORTABLE SnmpNewRequestId(); |
80ca5a43 | 662 | UINT32 LIBNXSRV_EXPORTABLE SnmpGet(int version, SNMP_Transport *transport, |
e0471fad VK |
663 | const TCHAR *szOidStr, const UINT32 *oidBinary, size_t oidLen, void *pValue, |
664 | size_t bufferSize, UINT32 dwFlags); | |
20c7bdf7 | 665 | UINT32 LIBNXSRV_EXPORTABLE SnmpGetEx(SNMP_Transport *pTransport, |
e0471fad VK |
666 | const TCHAR *szOidStr, const UINT32 *oidBinary, size_t oidLen, void *pValue, |
667 | size_t bufferSize, UINT32 dwFlags, UINT32 *dataLen); | |
967893bb VK |
668 | UINT32 LIBNXSRV_EXPORTABLE SnmpWalk(UINT32 dwVersion, SNMP_Transport *pTransport, const TCHAR *szRootOid, |
669 | UINT32 (* pHandler)(UINT32, SNMP_Variable *, SNMP_Transport *, void *), | |
46b7166d | 670 | void *pUserArg, BOOL bVerbose); |
5ad2167d | 671 | |
640b6719 VK |
672 | /** |
673 | * Variables | |
674 | */ | |
c8076b19 | 675 | extern UINT64 LIBNXSRV_EXPORTABLE g_flags; |
c42b4551 | 676 | extern UINT32 LIBNXSRV_EXPORTABLE g_snmpTimeout; |
967893bb | 677 | extern UINT32 LIBNXSRV_EXPORTABLE g_debugLevel; |
5039dede | 678 | |
640b6719 VK |
679 | /** |
680 | * Helper finctions for checking server flags | |
681 | */ | |
89135050 VK |
682 | inline bool IsStandalone() |
683 | { | |
c8076b19 | 684 | return !(g_flags & AF_DAEMON) ? true : false; |
89135050 VK |
685 | } |
686 | ||
687 | inline bool IsZoningEnabled() | |
688 | { | |
c8076b19 | 689 | return (g_flags & AF_ENABLE_ZONING) ? true : false; |
89135050 VK |
690 | } |
691 | ||
692 | inline bool IsShutdownInProgress() | |
693 | { | |
c8076b19 | 694 | return (g_flags & AF_SHUTDOWN) ? true : false; |
89135050 VK |
695 | } |
696 | ||
697 | ||
5039dede | 698 | #endif /* _nxsrvapi_h_ */ |