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