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