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