externalized strings
[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 */
a87ef571 449class LIBNXSRV_EXPORTABLE AgentConnection
5039dede
AK
450{
451private:
a87ef571
VK
452 VolatileCounter m_userRefCount;
453 VolatileCounter m_internalRefCount;
c11eee9b 454 InetAddress m_addr;
5039dede
AK
455 int m_nProtocolVersion;
456 int m_iAuthMethod;
08b214c6 457 char m_szSecret[MAX_SECRET_LENGTH];
5039dede
AK
458 time_t m_tLastCommandTime;
459 SOCKET m_hSocket;
967893bb 460 UINT32 m_dwNumDataLines;
e9902466 461 VolatileCounter m_requestId;
967893bb
VK
462 UINT32 m_dwCommandTimeout;
463 UINT32 m_connectionTimeout;
464 UINT32 m_dwRecvTimeout;
5039dede
AK
465 TCHAR **m_ppDataLines;
466 MsgWaitQueue *m_pMsgWaitQueue;
9fd816cc 467 bool m_isConnected;
5039dede 468 MUTEX m_mutexDataLock;
d3a7cf4c 469 MUTEX m_mutexSocketWrite;
5039dede 470 THREAD m_hReceiverThread;
98abc9f1 471 NXCPEncryptionContext *m_pCtx;
5039dede
AK
472 int m_iEncryptionPolicy;
473 BOOL m_bUseProxy;
c11eee9b 474 InetAddress m_proxyAddr;
5039dede
AK
475 WORD m_wPort;
476 WORD m_wProxyPort;
477 int m_iProxyAuth;
08b214c6 478 char m_szProxySecret[MAX_SECRET_LENGTH];
5039dede 479 int m_hCurrFile;
9f6d453a 480 TCHAR m_currentFileName[MAX_PATH];
967893bb 481 UINT32 m_dwDownloadRequestId;
bb85e341 482 CONDITION m_condFileDownload;
1693f955 483 bool m_fileDownloadSucceeded;
bb85e341
VK
484 void (*m_downloadProgressCallback)(size_t, void *);
485 void *m_downloadProgressCallbackArg;
901a5a9b 486 bool m_deleteFileOnDownloadFailure;
b368969c 487 void (*m_sendToClientMessageCallback)(NXCP_MESSAGE*, void *);
4685a2ad 488 bool m_fileUploadInProgress;
5039dede 489
a3050773
VK
490 void receiverThread();
491 static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *);
5039dede 492
1693f955
VK
493 void processCollectedDataCallback(NXCPMessage *msg);
494 void onDataPushCallback(NXCPMessage *msg);
cce2f2ef
VK
495 void onSnmpTrapCallback(NXCPMessage *msg);
496 void onTrapCallback(NXCPMessage *msg);
1693f955 497
5039dede 498protected:
7c521895 499 void destroyResultData();
967893bb
VK
500 UINT32 waitForRCC(UINT32 dwRqId, UINT32 dwTimeOut);
501 UINT32 setupEncryption(RSA *pServerKey);
502 UINT32 authenticate(BOOL bProxyData);
503 UINT32 setupProxyConnection();
c11eee9b 504 const InetAddress& getIpAddr() { return m_addr; }
b368969c 505 UINT32 prepareFileDownload(const TCHAR *fileName, UINT32 rqId, bool append, void (*downloadProgressCallback)(size_t, void *), void (*fileResendCallback)(NXCP_MESSAGE*, void *), void *cbArg);
5039dede 506
af21affe 507 virtual void printMsg(const TCHAR *format, ...);
b368969c
VK
508 virtual void onTrap(NXCPMessage *pMsg);
509 virtual void onDataPush(NXCPMessage *msg);
510 virtual void onFileMonitoringData(NXCPMessage *msg);
511 virtual void onSnmpTrap(NXCPMessage *pMsg);
1693f955 512 virtual void onFileDownload(bool success);
02d936bd 513 virtual UINT32 processCollectedData(NXCPMessage *msg);
a1273b42 514 virtual UINT32 processBulkCollectedData(NXCPMessage *request, NXCPMessage *response);
6fbaa926 515 virtual bool processCustomMessage(NXCPMessage *pMsg);
5039dede 516
a3050773
VK
517 void lock() { MutexLock(m_mutexDataLock); }
518 void unlock() { MutexUnlock(m_mutexDataLock); }
98abc9f1 519 NXCPEncryptionContext *acquireEncryptionContext();
5039dede 520
a87ef571
VK
521 void incInternalRefCount() { InterlockedIncrement(&m_internalRefCount); }
522 void decInternalRefCount() { if (InterlockedDecrement(&m_internalRefCount) == 0) delete this; }
523
7dd6369a
VK
524 virtual ~AgentConnection();
525
5039dede 526public:
c11eee9b 527 AgentConnection(InetAddress addr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL);
5039dede 528
a87ef571
VK
529 void incRefCount() { InterlockedIncrement(&m_userRefCount); }
530 void decRefCount() { if (InterlockedDecrement(&m_userRefCount) == 0) { disconnect(); decInternalRefCount(); } }
531
9fd816cc 532 bool connect(RSA *pServerKey = NULL, BOOL bVerbose = FALSE, UINT32 *pdwError = NULL, UINT32 *pdwSocketError = NULL);
7c521895 533 void disconnect();
9fd816cc 534 bool isConnected() { return m_isConnected; }
7c521895 535 int getProtocolVersion() { return m_nProtocolVersion; }
45d84f8a 536 SOCKET getSocket() { return m_hSocket; }
5a9e58a3 537
1693f955
VK
538 bool sendMessage(NXCPMessage *pMsg);
539 bool sendRawMessage(NXCP_MESSAGE *pMsg);
540 NXCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut) { return m_pMsgWaitQueue->waitForMessage(wCode, dwId, dwTimeOut); }
541
4687826e 542 ARP_CACHE *getArpCache();
98762401 543 InterfaceList *getInterfaceList();
4687826e 544 ROUTING_TABLE *getRoutingTable();
967893bb
VK
545 UINT32 getParameter(const TCHAR *pszParam, UINT32 dwBufSize, TCHAR *pszBuffer);
546 UINT32 getList(const TCHAR *pszParam);
547 UINT32 getTable(const TCHAR *pszParam, Table **table);
548 UINT32 nop();
1a5ddd2a 549 UINT32 setServerCapabilities();
e9902466 550 UINT32 setServerId(UINT64 serverId);
908d71bd 551 UINT32 execAction(const TCHAR *pszAction, int argc, TCHAR **argv, bool withOutput = false, void (* outputCallback)(ActionCallbackEvent, const TCHAR *, void *) = NULL, void *cbData = NULL);
503da871 552 UINT32 uploadFile(const TCHAR *localFile, const TCHAR *destinationFile = NULL, void (* progressCallback)(INT64, void *) = NULL, void *cbArg = NULL, NXCPCompressionMethod compMethod = NXCP_COMPRESSION_NONE);
967893bb 553 UINT32 startUpgrade(const TCHAR *pszPkgName);
c75e9ee4 554 UINT32 checkNetworkService(UINT32 *pdwStatus, const InetAddress& addr, int iServiceType, WORD wPort = 0,
b8014eee 555 WORD wProto = 0, const TCHAR *pszRequest = NULL, const TCHAR *pszResponse = NULL, UINT32 *responseTime = NULL);
967893bb
VK
556 UINT32 getSupportedParameters(ObjectArray<AgentParameterDefinition> **paramList, ObjectArray<AgentTableDefinition> **tableList);
557 UINT32 getConfigFile(TCHAR **ppszConfig, UINT32 *pdwSize);
558 UINT32 updateConfigFile(const TCHAR *pszConfig);
559 UINT32 enableTraps();
e13420c1 560 UINT32 enableFileUpdates();
967893bb 561 UINT32 getPolicyInventory(AgentPolicyInfo **info);
7dd6369a 562 UINT32 uninstallPolicy(const uuid& guid);
9c786c0f 563 UINT32 takeScreenshot(const TCHAR *sessionName, BYTE **data, size_t *size);
967893bb 564
e9902466 565 UINT32 generateRequestId() { return (UINT32)InterlockedIncrement(&m_requestId); }
b368969c
VK
566 NXCPMessage *customRequest(NXCPMessage *pRequest, const TCHAR *recvFile = NULL, bool append = false, void (*downloadProgressCallback)(size_t, void *) = NULL,
567 void (*fileResendCallback)(NXCP_MESSAGE*, void *) = NULL, void *cbArg = NULL);
5039dede 568
967893bb
VK
569 UINT32 getNumDataLines() { return m_dwNumDataLines; }
570 const TCHAR *getDataLine(UINT32 dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); }
5039dede 571
967893bb
VK
572 void setConnectionTimeout(UINT32 dwTimeout) { m_connectionTimeout = max(dwTimeout, 1000); }
573 UINT32 getConnectionTimeout() { return m_connectionTimeout; }
574 void setCommandTimeout(UINT32 dwTimeout) { m_dwCommandTimeout = max(dwTimeout, 500); }
575 UINT32 getCommandTimeout() { return m_dwCommandTimeout; }
576 void setRecvTimeout(UINT32 dwTimeout) { m_dwRecvTimeout = max(dwTimeout, 10000); }
7c521895 577 void setEncryptionPolicy(int iPolicy) { m_iEncryptionPolicy = iPolicy; }
c11eee9b 578 void setProxy(InetAddress addr, WORD wPort = AGENT_LISTEN_PORT,
5039dede 579 int iAuthMethod = AUTH_NONE, const TCHAR *pszSecret = NULL);
7c521895 580 void setPort(WORD wPort) { m_wPort = wPort; }
af21affe 581 void setAuthData(int method, const TCHAR *secret);
76b4edb5 582 void setDeleteFileOnDownloadFailure(bool flag) { m_deleteFileOnDownloadFailure = flag; }
5039dede
AK
583};
584
a3050773
VK
585/**
586 * Proxy SNMP transport
587 */
5039dede
AK
588class LIBNXSRV_EXPORTABLE SNMP_ProxyTransport : public SNMP_Transport
589{
590protected:
c75e9ee4
VK
591 AgentConnection *m_agentConnection;
592 NXCPMessage *m_response;
593 InetAddress m_ipAddr;
594 WORD m_port;
489b117b 595 bool m_waitForResponse;
5039dede
AK
596
597public:
c75e9ee4 598 SNMP_ProxyTransport(AgentConnection *conn, const InetAddress& ipAddr, WORD port);
5039dede
AK
599 virtual ~SNMP_ProxyTransport();
600
967893bb 601 virtual int readMessage(SNMP_PDU **ppData, UINT32 dwTimeout = INFINITE,
cd9f247e
VK
602 struct sockaddr *pSender = NULL, socklen_t *piAddrSize = NULL,
603 SNMP_SecurityContext* (*contextFinder)(struct sockaddr *, socklen_t) = NULL);
c4366266 604 virtual int sendMessage(SNMP_PDU *pdu);
c75e9ee4 605 virtual InetAddress getPeerIpAddress();
d0a2ada6 606 WORD getPort() { return m_port; }
b368969c
VK
607
608 void setWaitForResponse(bool wait) { m_waitForResponse = wait; }
5039dede
AK
609};
610
596dc3aa
VK
611/**
612 * ISC flags
613 */
967893bb
VK
614#define ISCF_IS_CONNECTED ((UINT32)0x00000001)
615#define ISCF_REQUIRE_ENCRYPTION ((UINT32)0x00000002)
5039dede 616
ed950274
VK
617/**
618 * Inter-server connection (ISC)
619 */
5039dede
AK
620class LIBNXSRV_EXPORTABLE ISC
621{
622private:
967893bb 623 UINT32 m_flags;
9d061c7b 624 InetAddress m_addr;
5039dede
AK
625 WORD m_port;
626 SOCKET m_socket;
627 int m_protocolVersion;
bc7767c4 628 VolatileCounter m_requestId;
967893bb 629 UINT32 m_recvTimeout;
5039dede
AK
630 MsgWaitQueue *m_msgWaitQueue;
631 MUTEX m_mutexDataLock;
7b8b337e 632 MUTEX m_socketLock;
5039dede 633 THREAD m_hReceiverThread;
98abc9f1 634 NXCPEncryptionContext *m_ctx;
967893bb 635 UINT32 m_commandTimeout;
5039dede 636
bc7767c4
VK
637 void receiverThread();
638 static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *);
5039dede
AK
639
640protected:
bc7767c4
VK
641 UINT32 setupEncryption(RSA *pServerKey);
642 UINT32 connectToService(UINT32 service);
5039dede 643
796baedf
VK
644 void lock() { MutexLock(m_mutexDataLock); }
645 void unlock() { MutexUnlock(m_mutexDataLock); }
5039dede 646
796baedf 647 virtual void printMessage(const TCHAR *format, ...);
b368969c
VK
648 virtual void onBinaryMessage(NXCP_MESSAGE *rawMsg);
649 virtual bool onMessage(NXCPMessage *msg);
5039dede
AK
650
651public:
652 ISC();
9d061c7b 653 ISC(const InetAddress& addr, WORD port = NETXMS_ISC_PORT);
5039dede
AK
654 virtual ~ISC();
655
bc7767c4
VK
656 UINT32 connect(UINT32 service, RSA *serverKey = NULL, BOOL requireEncryption = FALSE);
657 void disconnect();
e7aff566 658 bool connected() { return m_flags & ISCF_IS_CONNECTED; };
5039dede 659
b368969c
VK
660 BOOL sendMessage(NXCPMessage *msg);
661 NXCPMessage *waitForMessage(WORD code, UINT32 id, UINT32 timeOut) { return m_msgWaitQueue->waitForMessage(code, id, timeOut); }
bc7767c4
VK
662 UINT32 waitForRCC(UINT32 rqId, UINT32 timeOut);
663 UINT32 generateMessageId() { return (UINT32)InterlockedIncrement(&m_requestId); }
5039dede 664
bc7767c4 665 UINT32 nop();
5039dede
AK
666};
667
668
669//
670// Functions
671//
672
673void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache);
5039dede
AK
674void LIBNXSRV_EXPORTABLE DestroyRoutingTable(ROUTING_TABLE *pRT);
675void LIBNXSRV_EXPORTABLE SortRoutingTable(ROUTING_TABLE *pRT);
bf6fb6c3
VK
676const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(UINT32 err);
677UINT32 LIBNXSRV_EXPORTABLE AgentErrorToRCC(UINT32 err);
5039dede 678
640b6719 679void LIBNXSRV_EXPORTABLE WriteLogOther(WORD wType, const TCHAR *format, ...)
6e383343 680#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
640b6719
VK
681 __attribute__ ((format(printf, 2, 3)))
682#endif
683;
684
2df047f4
VK
685// for compatibility - new code should use nxlog_debug
686#define DbgPrintf nxlog_debug
c20b2798 687
5039dede
AK
688void LIBNXSRV_EXPORTABLE SetAgentDEP(int iPolicy);
689
967893bb 690const TCHAR LIBNXSRV_EXPORTABLE *ISCErrorCodeToText(UINT32 code);
5039dede 691
640b6719
VK
692/**
693 * Variables
694 */
c8076b19 695extern UINT64 LIBNXSRV_EXPORTABLE g_flags;
1693f955 696extern ThreadPool LIBNXSRV_EXPORTABLE *g_agentConnectionThreadPool;
5039dede 697
640b6719
VK
698/**
699 * Helper finctions for checking server flags
700 */
89135050
VK
701inline bool IsStandalone()
702{
c8076b19 703 return !(g_flags & AF_DAEMON) ? true : false;
89135050
VK
704}
705
706inline bool IsZoningEnabled()
707{
c8076b19 708 return (g_flags & AF_ENABLE_ZONING) ? true : false;
89135050
VK
709}
710
711inline bool IsShutdownInProgress()
712{
c8076b19 713 return (g_flags & AF_SHUTDOWN) ? true : false;
89135050
VK
714}
715
5039dede 716#endif /* _nxsrvapi_h_ */