"last value" gauges can show text values
[public/netxms.git] / src / server / include / nxsrvapi.h
CommitLineData
76b4edb5 1/*
5039dede
AK
2** NetXMS - Network Management System
3** Server Library
ed950274 4** Copyright (C) 2003-2013 Victor Kirhenshtein
5039dede
AK
5**
6** This program is free software; you can redistribute it and/or modify
0702ed69
VK
7** it under the terms of the GNU Lesser General Public License as published by
8** the Free Software Foundation; either version 3 of the License, or
5039dede
AK
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
0702ed69 16** You should have received a copy of the GNU Lesser General Public License
5039dede
AK
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
20** File: nxsrvapi.h
21**
22**/
23
24#ifndef _nxsrvapi_h_
25#define _nxsrvapi_h_
26
27#ifdef _WIN32
28#ifdef LIBNXSRV_EXPORTS
29#define LIBNXSRV_EXPORTABLE __declspec(dllexport)
30#else
31#define LIBNXSRV_EXPORTABLE __declspec(dllimport)
32#endif
33#else /* _WIN32 */
34#define LIBNXSRV_EXPORTABLE
35#endif
36
37#ifndef LIBNXCL_NO_DECLARATIONS
38#define LIBNXCL_NO_DECLARATIONS 1
39#endif
40#include <nxclapi.h>
41#include <nxcpapi.h>
42#include <nms_agent.h>
5039dede
AK
43#include <nxsnmp.h>
44#include <netxms_isc.h>
45
f1a3b4fe 46#ifdef INCLUDE_LIBNXSRV_MESSAGES
47#include "../libnxsrv/messages.h"
48#endif
49
f375019e
VK
50/**
51 * Default files
52 */
5039dede
AK
53#ifdef _WIN32
54
9796ce45
VK
55#define DEFAULT_CONFIG_FILE _T("C:\\netxmsd.conf")
56
57#define DEFAULT_SHELL _T("cmd.exe")
58#define DEFAULT_LOG_FILE _T("C:\\NetXMS.log")
59#define DEFAULT_DATA_DIR _T("C:\\NetXMS\\var")
60#define DEFAULT_LIBDIR _T("C:\\NetXMS\\lib")
712dd47d 61#define DEFAULT_JAVA_LIBDIR _T("C:\\NetXMS\\lib\\java")
9796ce45
VK
62#define DEFAULT_DUMP_DIR _T("C:\\")
63
64#define LDIR_NDD _T("\\ndd")
65
66#define DDIR_MIBS _T("\\mibs")
67#define DDIR_PACKAGES _T("\\packages")
68#define DDIR_BACKGROUNDS _T("\\backgrounds")
69#define DDIR_SHARED_FILES _T("\\shared")
70#define DFILE_KEYS _T("\\server_key")
71#define DFILE_COMPILED_MIB _T("\\mibs\\netxms.mib")
72#define DDIR_IMAGES _T("\\images")
73#define DDIR_FILES _T("\\files")
e77e56ca 74#define DDIR_REPORTS _T("\\reports")
5039dede
AK
75
76#else /* _WIN32 */
77
9796ce45 78#define DEFAULT_CONFIG_FILE _T("{search}")
5039dede 79
9796ce45 80#define DEFAULT_SHELL _T("/bin/sh")
5039dede 81
9796ce45
VK
82#ifndef DATADIR
83#define DATADIR _T("/var/netxms")
84#endif
5039dede 85
9796ce45
VK
86#ifndef LIBDIR
87#define LIBDIR _T("/usr/lib")
88#endif
5039dede 89
644f97f5
VK
90#ifndef PKGLIBDIR
91#define PKGLIBDIR _T("/usr/lib/netxms")
92#endif
93
9796ce45
VK
94#define DEFAULT_LOG_FILE DATADIR _T("/log/netxmsd.log")
95#define DEFAULT_DATA_DIR DATADIR
644f97f5 96#define DEFAULT_LIBDIR PKGLIBDIR
712dd47d 97#define DEFAULT_JAVA_LIBDIR PKGLIBDIR _T("/java")
9796ce45
VK
98#define DEFAULT_DUMP_DIR _T("/")
99
100#define LDIR_NDD _T("/ndd")
101
102#define DDIR_MIBS _T("/mibs")
103#define DDIR_PACKAGES _T("/packages")
104#define DDIR_BACKGROUNDS _T("/backgrounds")
105#define DDIR_SHARED_FILES _T("/shared")
106#define DFILE_KEYS _T("/.server_key")
107#define DFILE_COMPILED_MIB _T("/mibs/netxms.mib")
108#define DDIR_IMAGES _T("/images")
109#define DDIR_FILES _T("/files")
e77e56ca 110#define DDIR_REPORTS _T("/reports")
5039dede
AK
111
112#endif /* _WIN32 */
113
f375019e
VK
114/**
115 * Application flags
116 */
3a82d5ae
VK
117#define AF_DAEMON 0x00000001
118#define AF_USE_SYSLOG 0x00000002
119#define AF_ENABLE_NETWORK_DISCOVERY 0x00000004
120#define AF_ACTIVE_NETWORK_DISCOVERY 0x00000008
121#define AF_LOG_SQL_ERRORS 0x00000010
122#define AF_DELETE_EMPTY_SUBNETS 0x00000020
123#define AF_ENABLE_SNMP_TRAPD 0x00000040
124#define AF_ENABLE_ZONING 0x00000080
125#define AF_SYNC_NODE_NAMES_WITH_DNS 0x00000100
126#define AF_CHECK_TRUSTED_NODES 0x00000200
127#define AF_ENABLE_NXSL_CONTAINER_FUNCS 0x00000400
128#define AF_USE_FQDN_FOR_NODE_NAMES 0x00000800
129#define AF_APPLY_TO_DISABLED_DCI_FROM_TEMPLATE 0x00001000
130#define AF_DEBUG_CONSOLE_DISABLED 0x00002000
549f48b3 131#define AF_ENABLE_OBJECT_TRANSACTIONS 0x00004000
3a82d5ae
VK
132#define AF_WRITE_FULL_DUMP 0x00080000
133#define AF_RESOLVE_NODE_NAMES 0x00100000
134#define AF_CATCH_EXCEPTIONS 0x00200000
d41268ba 135#define AF_HELPDESK_LINK_ACTIVE 0x00400000
e94b29f6 136#define AF_DB_CONNECTION_POOL_READY 0x00800000
3a82d5ae
VK
137#define AF_DB_LOCKED 0x01000000
138#define AF_ENABLE_MULTIPLE_DB_CONN 0x02000000
139#define AF_DB_CONNECTION_LOST 0x04000000
140#define AF_NO_NETWORK_CONNECTIVITY 0x08000000
141#define AF_EVENT_STORM_DETECTED 0x10000000
e02953a4 142#define AF_SNMP_TRAP_DISCOVERY 0x20000000
3a82d5ae
VK
143#define AF_SERVER_INITIALIZED 0x40000000
144#define AF_SHUTDOWN 0x80000000
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
f375019e
VK
154/**
155 * Flags for SnmpGet
156 */
5ad2167d
VK
157#define SG_VERBOSE 0x0001
158#define SG_STRING_RESULT 0x0002
159#define SG_RAW_RESULT 0x0004
160#define SG_HSTRING_RESULT 0x0008
4f131f2f 161#define SG_PSTRING_RESULT 0x0010
5ad2167d 162
f375019e
VK
163/**
164 * Win32 service and syslog constants
165 */
5039dede
AK
166#ifdef _WIN32
167
168#define CORE_SERVICE_NAME _T("NetXMSCore")
169#define CORE_EVENT_SOURCE _T("NetXMSCore")
170#define NETXMSD_SYSLOG_NAME CORE_EVENT_SOURCE
171
172#else
173
174#define NETXMSD_SYSLOG_NAME _T("netxmsd")
175
176#endif /* _WIN32 */
177
f375019e
VK
178/**
179 * Single ARP cache entry
180 */
5039dede
AK
181typedef struct
182{
967893bb
VK
183 UINT32 dwIndex; // Interface index
184 UINT32 dwIpAddr;
5039dede
AK
185 BYTE bMacAddr[MAC_ADDR_LENGTH];
186} ARP_ENTRY;
187
f375019e
VK
188/**
189 * ARP cache structure used by discovery functions and AgentConnection class
190 */
5039dede
AK
191typedef struct
192{
967893bb 193 UINT32 dwNumEntries;
5039dede
AK
194 ARP_ENTRY *pEntries;
195} ARP_CACHE;
196
f375019e
VK
197/**
198 * Interface information structure used by discovery functions and AgentConnection class
199 */
5039dede
AK
200typedef struct
201{
478d4ff4
VK
202 TCHAR szName[MAX_DB_STRING]; // Interface display name
203 TCHAR szDescription[MAX_DB_STRING]; // Value of ifDescr MIB variable for SNMP agents
967893bb
VK
204 UINT32 dwIndex;
205 UINT32 dwType;
206 UINT32 dwBridgePortNumber;
207 UINT32 dwSlotNumber;
208 UINT32 dwPortNumber;
209 UINT32 dwIpAddr;
210 UINT32 dwIpNetMask;
5039dede
AK
211 BYTE bMacAddr[MAC_ADDR_LENGTH];
212 int iNumSecondary; // Number of secondary IP's on this interface
4c16cdc7 213 bool isPhysicalPort;
01152a54 214 bool isSystem;
36e44abe 215} NX_INTERFACE_INFO;
5039dede 216
f375019e
VK
217/**
218 * Interface list used by discovery functions and AgentConnection class
219 */
98762401 220class LIBNXSRV_EXPORTABLE InterfaceList
5039dede 221{
98762401
VK
222private:
223 int m_size; // Number of valid entries
224 int m_allocated; // Number of allocated entries
225 void *m_data; // Can be used by custom enumeration handlers
36e44abe 226 NX_INTERFACE_INFO *m_interfaces; // Interface entries
98762401
VK
227
228public:
229 InterfaceList(int initialAlloc = 8);
230 ~InterfaceList();
231
36e44abe 232 void add(NX_INTERFACE_INFO *iface);
98762401 233 void remove(int index);
98762401
VK
234
235 int getSize() { return m_size; }
36e44abe 236 NX_INTERFACE_INFO *get(int index) { return ((index >= 0) && (index < m_size)) ? &m_interfaces[index] : NULL; }
967893bb 237 NX_INTERFACE_INFO *findByIfIndex(UINT32 ifIndex);
98762401
VK
238
239 void setData(void *data) { m_data = data; }
240 void *getData() { return m_data; }
241};
5039dede 242
f375019e
VK
243/**
244 * Vlan information
245 */
0208aa8c
VK
246#define VLAN_PRM_IFINDEX 0
247#define VLAN_PRM_SLOTPORT 1
5eb3a790 248#define VLAN_PRM_BPORT 2
0208aa8c 249
77c7801c
VK
250class LIBNXSRV_EXPORTABLE VlanInfo
251{
252private:
253 int m_vlanId;
254 TCHAR *m_name;
0208aa8c 255 int m_portRefMode; // Port reference mode - by ifIndex or by slot/port
77c7801c
VK
256 int m_allocated;
257 int m_numPorts; // Number of ports in VLAN
967893bb
VK
258 UINT32 *m_ports; // member ports (slot/port pairs or ifIndex)
259 UINT32 *m_indexes; // ifIndexes for ports
260 UINT32 *m_ids; // Interface object IDs for ports
77c7801c
VK
261
262public:
0208aa8c 263 VlanInfo(int vlanId, int prm);
77c7801c
VK
264 ~VlanInfo();
265
266 int getVlanId() { return m_vlanId; }
0208aa8c 267 int getPortReferenceMode() { return m_portRefMode; }
77c7801c
VK
268 const TCHAR *getName() { return CHECK_NULL_EX(m_name); }
269 int getNumPorts() { return m_numPorts; }
967893bb
VK
270 UINT32 *getPorts() { return m_ports; }
271 UINT32 *getIfIndexes() { return m_indexes; }
272 UINT32 *getIfIds() { return m_ids; }
77c7801c 273
967893bb
VK
274 void add(UINT32 slot, UINT32 port);
275 void add(UINT32 ifIndex);
77c7801c 276 void setName(const TCHAR *name);
b1bd1fb2
VK
277
278 void prepareForResolve();
967893bb 279 void resolvePort(int index, UINT32 sp, UINT32 ifIndex, UINT32 id);
77c7801c
VK
280};
281
a3050773
VK
282/**
283 * Vlan list
284 */
7f632dfe 285class LIBNXSRV_EXPORTABLE VlanList : public RefCountObject
77c7801c
VK
286{
287private:
288 int m_size; // Number of valid entries
289 int m_allocated; // Number of allocated entries
290 void *m_data; // Can be used by custom enumeration handlers
291 VlanInfo **m_vlans; // VLAN entries
292
293public:
294 VlanList(int initialAlloc = 8);
7f632dfe 295 virtual ~VlanList();
77c7801c
VK
296
297 void add(VlanInfo *vlan);
967893bb 298 void addMemberPort(int vlanId, UINT32 portId);
77c7801c
VK
299
300 int getSize() { return m_size; }
301 VlanInfo *get(int index) { return ((index >= 0) && (index < m_size)) ? m_vlans[index] : NULL; }
0208aa8c 302 VlanInfo *findById(int id);
0239cfea 303 VlanInfo *findByName(const TCHAR *name);
77c7801c
VK
304
305 void setData(void *data) { m_data = data; }
306 void *getData() { return m_data; }
7f632dfe
VK
307
308 void fillMessage(CSCPMessage *msg);
77c7801c
VK
309};
310
a3050773
VK
311/**
312 * Route information
313 */
5039dede
AK
314typedef struct
315{
967893bb
VK
316 UINT32 dwDestAddr;
317 UINT32 dwDestMask;
318 UINT32 dwNextHop;
319 UINT32 dwIfIndex;
320 UINT32 dwRouteType;
5039dede
AK
321} ROUTE;
322
a3050773
VK
323/**
324 * Routing table
325 */
5039dede
AK
326typedef struct
327{
328 int iNumEntries; // Number of entries
329 ROUTE *pRoutes; // Route list
330} ROUTING_TABLE;
331
a3050773
VK
332/**
333 * Information about policies installed on agent
334 */
1f385e47
VK
335class LIBNXSRV_EXPORTABLE AgentPolicyInfo
336{
337private:
338 int m_size;
339 BYTE *m_guidList;
340 int *m_typeList;
341 TCHAR **m_serverList;
342
343public:
344 AgentPolicyInfo(CSCPMessage *msg);
345 ~AgentPolicyInfo();
346
347 int getSize() { return m_size; }
348 bool getGuid(int index, uuid_t guid);
349 int getType(int index) { return ((index >= 0) && (index < m_size)) ? m_typeList[index] : -1; }
350 const TCHAR *getServer(int index) { return ((index >= 0) && (index < m_size)) ? m_serverList[index] : NULL; }
351};
352
86c126f5
VK
353/**
354 * Agent parameter definition
355 */
356class LIBNXSRV_EXPORTABLE AgentParameterDefinition
357{
358private:
359 TCHAR *m_name;
360 TCHAR *m_description;
361 int m_dataType;
362
363public:
967893bb 364 AgentParameterDefinition(CSCPMessage *msg, UINT32 baseId);
86c126f5
VK
365 AgentParameterDefinition(AgentParameterDefinition *src);
366 ~AgentParameterDefinition();
367
967893bb 368 UINT32 fillMessage(CSCPMessage *msg, UINT32 baseId);
86c126f5
VK
369
370 const TCHAR *getName() { return m_name; }
371 const TCHAR *getDescription() { return m_description; }
372 int getDataType() { return m_dataType; }
373};
374
375/**
376 * Agent table column definition
377 */
378struct AgentTableColumnDefinition
379{
380 TCHAR m_name[MAX_COLUMN_NAME];
381 int m_dataType;
382
383 AgentTableColumnDefinition(AgentTableColumnDefinition *src)
384 {
385 nx_strncpy(m_name, src->m_name, MAX_COLUMN_NAME);
386 m_dataType = src->m_dataType;
387 }
388};
389
390/**
391 * Agent table definition
392 */
393class LIBNXSRV_EXPORTABLE AgentTableDefinition
394{
395private:
396 TCHAR *m_name;
397 TCHAR *m_description;
398 StringList *m_instanceColumns;
399 ObjectArray<AgentTableColumnDefinition> *m_columns;
400
401public:
967893bb 402 AgentTableDefinition(CSCPMessage *msg, UINT32 baseId);
86c126f5
VK
403 AgentTableDefinition(AgentTableDefinition *src);
404 ~AgentTableDefinition();
405
967893bb 406 UINT32 fillMessage(CSCPMessage *msg, UINT32 baseId);
86c126f5
VK
407
408 const TCHAR *getName() { return m_name; }
409 const TCHAR *getDescription() { return m_description; }
410};
411
a3050773
VK
412/**
413 * Agent connection
414 */
5039dede
AK
415class LIBNXSRV_EXPORTABLE AgentConnection
416{
417private:
967893bb 418 UINT32 m_dwAddr;
5039dede
AK
419 int m_nProtocolVersion;
420 int m_iAuthMethod;
08b214c6 421 char m_szSecret[MAX_SECRET_LENGTH];
5039dede
AK
422 time_t m_tLastCommandTime;
423 SOCKET m_hSocket;
967893bb
VK
424 UINT32 m_dwNumDataLines;
425 UINT32 m_dwRequestId;
426 UINT32 m_dwCommandTimeout;
427 UINT32 m_connectionTimeout;
428 UINT32 m_dwRecvTimeout;
5039dede
AK
429 TCHAR **m_ppDataLines;
430 MsgWaitQueue *m_pMsgWaitQueue;
431 BOOL m_bIsConnected;
432 MUTEX m_mutexDataLock;
d3a7cf4c 433 MUTEX m_mutexSocketWrite;
5039dede 434 THREAD m_hReceiverThread;
98abc9f1 435 NXCPEncryptionContext *m_pCtx;
5039dede
AK
436 int m_iEncryptionPolicy;
437 BOOL m_bUseProxy;
967893bb 438 UINT32 m_dwProxyAddr;
5039dede
AK
439 WORD m_wPort;
440 WORD m_wProxyPort;
441 int m_iProxyAuth;
08b214c6 442 char m_szProxySecret[MAX_SECRET_LENGTH];
5039dede 443 int m_hCurrFile;
9f6d453a 444 TCHAR m_currentFileName[MAX_PATH];
967893bb 445 UINT32 m_dwDownloadRequestId;
bb85e341
VK
446 CONDITION m_condFileDownload;
447 BOOL m_fileDownloadSucceeded;
448 void (*m_downloadProgressCallback)(size_t, void *);
449 void *m_downloadProgressCallbackArg;
901a5a9b 450 bool m_deleteFileOnDownloadFailure;
76b4edb5 451 void (*m_sendToClientMessageCallback)(CSCP_MESSAGE*, void *);
4685a2ad 452 bool m_fileUploadInProgress;
5039dede 453
a3050773
VK
454 void receiverThread();
455 static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *);
5039dede
AK
456
457protected:
7c521895 458 void destroyResultData();
967893bb
VK
459 UINT32 waitForRCC(UINT32 dwRqId, UINT32 dwTimeOut);
460 UINT32 setupEncryption(RSA *pServerKey);
461 UINT32 authenticate(BOOL bProxyData);
462 UINT32 setupProxyConnection();
463 UINT32 getIpAddr() { return ntohl(m_dwAddr); }
76b4edb5 464 UINT32 prepareFileDownload(const TCHAR *fileName, UINT32 rqId, bool append, void (*downloadProgressCallback)(size_t, void *), void (*fileResendCallback)(CSCP_MESSAGE*, void *), void *cbArg);
5039dede 465
af21affe 466 virtual void printMsg(const TCHAR *format, ...);
f480bdd4
VK
467 virtual void onTrap(CSCPMessage *pMsg);
468 virtual void onDataPush(CSCPMessage *msg);
9fa031cd 469 virtual void onFileMonitoringData(CSCPMessage *msg);
90284364 470 virtual bool processCustomMessage(CSCPMessage *pMsg);
f480bdd4 471 virtual void onFileDownload(BOOL success);
5039dede 472
a3050773
VK
473 void lock() { MutexLock(m_mutexDataLock); }
474 void unlock() { MutexUnlock(m_mutexDataLock); }
98abc9f1 475 NXCPEncryptionContext *acquireEncryptionContext();
5039dede
AK
476
477public:
7cf549ad 478 BOOL sendMessage(CSCPMessage *pMsg);
479 CSCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut) { return m_pMsgWaitQueue->waitForMessage(wCode, dwId, dwTimeOut); }
69c6604d 480 AgentConnection(UINT32 ipAddr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL);
5039dede
AK
481 virtual ~AgentConnection();
482
967893bb 483 BOOL connect(RSA *pServerKey = NULL, BOOL bVerbose = FALSE, UINT32 *pdwError = NULL, UINT32 *pdwSocketError = NULL);
7c521895
VK
484 void disconnect();
485 BOOL isConnected() { return m_bIsConnected; }
486 int getProtocolVersion() { return m_nProtocolVersion; }
5039dede 487
45d84f8a 488 SOCKET getSocket() { return m_hSocket; }
5a9e58a3 489
4687826e 490 ARP_CACHE *getArpCache();
98762401 491 InterfaceList *getInterfaceList();
4687826e 492 ROUTING_TABLE *getRoutingTable();
967893bb
VK
493 UINT32 getParameter(const TCHAR *pszParam, UINT32 dwBufSize, TCHAR *pszBuffer);
494 UINT32 getList(const TCHAR *pszParam);
495 UINT32 getTable(const TCHAR *pszParam, Table **table);
496 UINT32 nop();
497 UINT32 execAction(const TCHAR *pszAction, int argc, TCHAR **argv);
498 UINT32 uploadFile(const TCHAR *localFile, const TCHAR *destinationFile = NULL, void (* progressCallback)(INT64, void *) = NULL, void *cbArg = NULL);
499 UINT32 startUpgrade(const TCHAR *pszPkgName);
76b4edb5 500 UINT32 checkNetworkService(UINT32 *pdwStatus, UINT32 dwIpAddr, int iServiceType, WORD wPort = 0,
5039dede 501 WORD wProto = 0, const TCHAR *pszRequest = NULL, const TCHAR *pszResponse = NULL);
967893bb
VK
502 UINT32 getSupportedParameters(ObjectArray<AgentParameterDefinition> **paramList, ObjectArray<AgentTableDefinition> **tableList);
503 UINT32 getConfigFile(TCHAR **ppszConfig, UINT32 *pdwSize);
504 UINT32 updateConfigFile(const TCHAR *pszConfig);
505 UINT32 enableTraps();
506 UINT32 getPolicyInventory(AgentPolicyInfo **info);
507 UINT32 uninstallPolicy(uuid_t guid);
508
509 UINT32 generateRequestId() { return m_dwRequestId++; }
76b4edb5 510 CSCPMessage *customRequest(CSCPMessage *pRequest, const TCHAR *recvFile = NULL, bool append = false, void (*downloadProgressCallback)(size_t, void *) = NULL,
511 void (*fileResendCallback)(CSCP_MESSAGE*, void *) = NULL, void *cbArg = NULL);
5039dede 512
967893bb
VK
513 UINT32 getNumDataLines() { return m_dwNumDataLines; }
514 const TCHAR *getDataLine(UINT32 dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); }
5039dede 515
967893bb
VK
516 void setConnectionTimeout(UINT32 dwTimeout) { m_connectionTimeout = max(dwTimeout, 1000); }
517 UINT32 getConnectionTimeout() { return m_connectionTimeout; }
518 void setCommandTimeout(UINT32 dwTimeout) { m_dwCommandTimeout = max(dwTimeout, 500); }
519 UINT32 getCommandTimeout() { return m_dwCommandTimeout; }
520 void setRecvTimeout(UINT32 dwTimeout) { m_dwRecvTimeout = max(dwTimeout, 10000); }
7c521895 521 void setEncryptionPolicy(int iPolicy) { m_iEncryptionPolicy = iPolicy; }
967893bb 522 void setProxy(UINT32 dwAddr, WORD wPort = AGENT_LISTEN_PORT,
5039dede 523 int iAuthMethod = AUTH_NONE, const TCHAR *pszSecret = NULL);
7c521895 524 void setPort(WORD wPort) { m_wPort = wPort; }
af21affe 525 void setAuthData(int method, const TCHAR *secret);
76b4edb5 526 void setDeleteFileOnDownloadFailure(bool flag) { m_deleteFileOnDownloadFailure = flag; }
7cf549ad 527 BOOL sendRawMessage(CSCP_MESSAGE *pMsg);
5039dede
AK
528};
529
a3050773
VK
530/**
531 * Proxy SNMP transport
532 */
5039dede
AK
533class LIBNXSRV_EXPORTABLE SNMP_ProxyTransport : public SNMP_Transport
534{
535protected:
536 AgentConnection *m_pAgentConnection;
537 CSCPMessage *m_pResponse;
967893bb 538 UINT32 m_dwIpAddr;
5039dede
AK
539 WORD m_wPort;
540
541public:
967893bb 542 SNMP_ProxyTransport(AgentConnection *pConn, UINT32 dwIpAddr, WORD wPort);
5039dede
AK
543 virtual ~SNMP_ProxyTransport();
544
967893bb 545 virtual int readMessage(SNMP_PDU **ppData, UINT32 dwTimeout = INFINITE,
cd9f247e
VK
546 struct sockaddr *pSender = NULL, socklen_t *piAddrSize = NULL,
547 SNMP_SecurityContext* (*contextFinder)(struct sockaddr *, socklen_t) = NULL);
c4366266 548 virtual int sendMessage(SNMP_PDU *pdu);
967893bb 549 virtual UINT32 getPeerIpAddress();
5039dede
AK
550};
551
596dc3aa
VK
552/**
553 * ISC flags
554 */
967893bb
VK
555#define ISCF_IS_CONNECTED ((UINT32)0x00000001)
556#define ISCF_REQUIRE_ENCRYPTION ((UINT32)0x00000002)
5039dede 557
ed950274
VK
558/**
559 * Inter-server connection (ISC)
560 */
5039dede
AK
561class LIBNXSRV_EXPORTABLE ISC
562{
563private:
967893bb
VK
564 UINT32 m_flags;
565 UINT32 m_addr;
5039dede
AK
566 WORD m_port;
567 SOCKET m_socket;
568 int m_protocolVersion;
bc7767c4 569 VolatileCounter m_requestId;
967893bb 570 UINT32 m_recvTimeout;
5039dede
AK
571 MsgWaitQueue *m_msgWaitQueue;
572 MUTEX m_mutexDataLock;
7b8b337e 573 MUTEX m_socketLock;
5039dede 574 THREAD m_hReceiverThread;
98abc9f1 575 NXCPEncryptionContext *m_ctx;
967893bb 576 UINT32 m_commandTimeout;
5039dede 577
bc7767c4
VK
578 void receiverThread();
579 static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *);
5039dede
AK
580
581protected:
bc7767c4
VK
582 UINT32 setupEncryption(RSA *pServerKey);
583 UINT32 connectToService(UINT32 service);
5039dede 584
796baedf
VK
585 void lock() { MutexLock(m_mutexDataLock); }
586 void unlock() { MutexUnlock(m_mutexDataLock); }
5039dede 587
796baedf 588 virtual void printMessage(const TCHAR *format, ...);
bc7767c4 589 virtual void onBinaryMessage(CSCP_MESSAGE *rawMsg);
96fb011c 590 virtual bool onMessage(CSCPMessage *msg);
5039dede
AK
591
592public:
593 ISC();
967893bb 594 ISC(UINT32 addr, WORD port = NETXMS_ISC_PORT);
5039dede
AK
595 virtual ~ISC();
596
bc7767c4
VK
597 UINT32 connect(UINT32 service, RSA *serverKey = NULL, BOOL requireEncryption = FALSE);
598 void disconnect();
e7aff566 599 bool connected() { return m_flags & ISCF_IS_CONNECTED; };
5039dede 600
bc7767c4
VK
601 BOOL sendMessage(CSCPMessage *msg);
602 CSCPMessage *waitForMessage(WORD code, UINT32 id, UINT32 timeOut) { return m_msgWaitQueue->waitForMessage(code, id, timeOut); }
603 UINT32 waitForRCC(UINT32 rqId, UINT32 timeOut);
604 UINT32 generateMessageId() { return (UINT32)InterlockedIncrement(&m_requestId); }
5039dede 605
bc7767c4 606 UINT32 nop();
5039dede
AK
607};
608
609
610//
611// Functions
612//
613
614void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache);
5039dede
AK
615void LIBNXSRV_EXPORTABLE DestroyRoutingTable(ROUTING_TABLE *pRT);
616void LIBNXSRV_EXPORTABLE SortRoutingTable(ROUTING_TABLE *pRT);
617const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(int iError);
618
640b6719 619void LIBNXSRV_EXPORTABLE WriteLogOther(WORD wType, const TCHAR *format, ...)
6e383343 620#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
640b6719
VK
621 __attribute__ ((format(printf, 2, 3)))
622#endif
623;
624
625void LIBNXSRV_EXPORTABLE DbgPrintf(int level, const TCHAR *format, ...)
6e383343 626#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
640b6719
VK
627 __attribute__ ((format(printf, 2, 3)))
628#endif
629;
630
9d88cdc9 631void LIBNXSRV_EXPORTABLE DbgPrintf2(int level, const TCHAR *format, va_list args);
c20b2798 632
5039dede
AK
633void LIBNXSRV_EXPORTABLE SetAgentDEP(int iPolicy);
634
967893bb 635const TCHAR LIBNXSRV_EXPORTABLE *ISCErrorCodeToText(UINT32 code);
5039dede 636
967893bb 637UINT32 LIBNXSRV_EXPORTABLE SnmpNewRequestId();
80ca5a43 638UINT32 LIBNXSRV_EXPORTABLE SnmpGet(int version, SNMP_Transport *transport,
e0471fad
VK
639 const TCHAR *szOidStr, const UINT32 *oidBinary, size_t oidLen, void *pValue,
640 size_t bufferSize, UINT32 dwFlags);
20c7bdf7 641UINT32 LIBNXSRV_EXPORTABLE SnmpGetEx(SNMP_Transport *pTransport,
e0471fad
VK
642 const TCHAR *szOidStr, const UINT32 *oidBinary, size_t oidLen, void *pValue,
643 size_t bufferSize, UINT32 dwFlags, UINT32 *dataLen);
967893bb
VK
644UINT32 LIBNXSRV_EXPORTABLE SnmpWalk(UINT32 dwVersion, SNMP_Transport *pTransport, const TCHAR *szRootOid,
645 UINT32 (* pHandler)(UINT32, SNMP_Variable *, SNMP_Transport *, void *),
46b7166d 646 void *pUserArg, BOOL bVerbose);
5ad2167d 647
640b6719
VK
648/**
649 * Variables
650 */
967893bb
VK
651extern UINT32 LIBNXSRV_EXPORTABLE g_dwFlags;
652extern UINT32 LIBNXSRV_EXPORTABLE g_dwSNMPTimeout;
653extern UINT32 LIBNXSRV_EXPORTABLE g_debugLevel;
5039dede 654
640b6719
VK
655/**
656 * Helper finctions for checking server flags
657 */
89135050
VK
658inline bool IsStandalone()
659{
660 return !(g_dwFlags & AF_DAEMON) ? true : false;
661}
662
663inline bool IsZoningEnabled()
664{
665 return (g_dwFlags & AF_ENABLE_ZONING) ? true : false;
666}
667
668inline bool IsShutdownInProgress()
669{
670 return (g_dwFlags & AF_SHUTDOWN) ? true : false;
671}
672
673
5039dede 674#endif /* _nxsrvapi_h_ */