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