Message synchronisation script fixed: whitespaces stripped
[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>
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
135#define AF_INTERNAL_CA 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;
4685a2ad 451 bool m_fileUploadInProgress;
5039dede 452
a3050773
VK
453 void receiverThread();
454 static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *);
5039dede
AK
455
456protected:
7c521895
VK
457 void destroyResultData();
458 BOOL sendMessage(CSCPMessage *pMsg);
967893bb
VK
459 CSCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut) { return m_pMsgWaitQueue->waitForMessage(wCode, dwId, dwTimeOut); }
460 UINT32 waitForRCC(UINT32 dwRqId, UINT32 dwTimeOut);
461 UINT32 setupEncryption(RSA *pServerKey);
462 UINT32 authenticate(BOOL bProxyData);
463 UINT32 setupProxyConnection();
464 UINT32 getIpAddr() { return ntohl(m_dwAddr); }
465 UINT32 prepareFileDownload(const TCHAR *fileName, UINT32 rqId, bool append, void (*downloadProgressCallback)(size_t, void *), void *cbArg);
5039dede 466
af21affe 467 virtual void printMsg(const TCHAR *format, ...);
f480bdd4
VK
468 virtual void onTrap(CSCPMessage *pMsg);
469 virtual void onDataPush(CSCPMessage *msg);
9fa031cd 470 virtual void onFileMonitoringData(CSCPMessage *msg);
90284364 471 virtual bool processCustomMessage(CSCPMessage *pMsg);
f480bdd4 472 virtual void onFileDownload(BOOL success);
5039dede 473
a3050773
VK
474 void lock() { MutexLock(m_mutexDataLock); }
475 void unlock() { MutexUnlock(m_mutexDataLock); }
98abc9f1 476 NXCPEncryptionContext *acquireEncryptionContext();
5039dede
AK
477
478public:
69c6604d 479 AgentConnection(UINT32 ipAddr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL);
5039dede
AK
480 virtual ~AgentConnection();
481
967893bb 482 BOOL connect(RSA *pServerKey = NULL, BOOL bVerbose = FALSE, UINT32 *pdwError = NULL, UINT32 *pdwSocketError = NULL);
7c521895
VK
483 void disconnect();
484 BOOL isConnected() { return m_bIsConnected; }
485 int getProtocolVersion() { return m_nProtocolVersion; }
5039dede 486
45d84f8a 487 SOCKET getSocket() { return m_hSocket; }
5a9e58a3 488
4687826e 489 ARP_CACHE *getArpCache();
98762401 490 InterfaceList *getInterfaceList();
4687826e 491 ROUTING_TABLE *getRoutingTable();
967893bb
VK
492 UINT32 getParameter(const TCHAR *pszParam, UINT32 dwBufSize, TCHAR *pszBuffer);
493 UINT32 getList(const TCHAR *pszParam);
494 UINT32 getTable(const TCHAR *pszParam, Table **table);
495 UINT32 nop();
496 UINT32 execAction(const TCHAR *pszAction, int argc, TCHAR **argv);
497 UINT32 uploadFile(const TCHAR *localFile, const TCHAR *destinationFile = NULL, void (* progressCallback)(INT64, void *) = NULL, void *cbArg = NULL);
498 UINT32 startUpgrade(const TCHAR *pszPkgName);
499 UINT32 checkNetworkService(UINT32 *pdwStatus, UINT32 dwIpAddr, int iServiceType, WORD wPort = 0,
5039dede 500 WORD wProto = 0, const TCHAR *pszRequest = NULL, const TCHAR *pszResponse = NULL);
967893bb
VK
501 UINT32 getSupportedParameters(ObjectArray<AgentParameterDefinition> **paramList, ObjectArray<AgentTableDefinition> **tableList);
502 UINT32 getConfigFile(TCHAR **ppszConfig, UINT32 *pdwSize);
503 UINT32 updateConfigFile(const TCHAR *pszConfig);
504 UINT32 enableTraps();
505 UINT32 getPolicyInventory(AgentPolicyInfo **info);
506 UINT32 uninstallPolicy(uuid_t guid);
507
508 UINT32 generateRequestId() { return m_dwRequestId++; }
45d84f8a 509 CSCPMessage *customRequest(CSCPMessage *pRequest, const TCHAR *recvFile = NULL, bool appendFile = false,
f2665675 510 void (*downloadProgressCallback)(size_t, void *) = NULL, void *cbArg = NULL);
5039dede 511
967893bb
VK
512 UINT32 getNumDataLines() { return m_dwNumDataLines; }
513 const TCHAR *getDataLine(UINT32 dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); }
5039dede 514
967893bb
VK
515 void setConnectionTimeout(UINT32 dwTimeout) { m_connectionTimeout = max(dwTimeout, 1000); }
516 UINT32 getConnectionTimeout() { return m_connectionTimeout; }
517 void setCommandTimeout(UINT32 dwTimeout) { m_dwCommandTimeout = max(dwTimeout, 500); }
518 UINT32 getCommandTimeout() { return m_dwCommandTimeout; }
519 void setRecvTimeout(UINT32 dwTimeout) { m_dwRecvTimeout = max(dwTimeout, 10000); }
7c521895 520 void setEncryptionPolicy(int iPolicy) { m_iEncryptionPolicy = iPolicy; }
967893bb 521 void setProxy(UINT32 dwAddr, WORD wPort = AGENT_LISTEN_PORT,
5039dede 522 int iAuthMethod = AUTH_NONE, const TCHAR *pszSecret = NULL);
7c521895 523 void setPort(WORD wPort) { m_wPort = wPort; }
af21affe 524 void setAuthData(int method, const TCHAR *secret);
901a5a9b 525 void setDeleteFileOnDownloadFailure(bool flag) { m_deleteFileOnDownloadFailure = flag; }
5039dede
AK
526};
527
a3050773
VK
528/**
529 * Proxy SNMP transport
530 */
5039dede
AK
531class LIBNXSRV_EXPORTABLE SNMP_ProxyTransport : public SNMP_Transport
532{
533protected:
534 AgentConnection *m_pAgentConnection;
535 CSCPMessage *m_pResponse;
967893bb 536 UINT32 m_dwIpAddr;
5039dede
AK
537 WORD m_wPort;
538
539public:
967893bb 540 SNMP_ProxyTransport(AgentConnection *pConn, UINT32 dwIpAddr, WORD wPort);
5039dede
AK
541 virtual ~SNMP_ProxyTransport();
542
967893bb 543 virtual int readMessage(SNMP_PDU **ppData, UINT32 dwTimeout = INFINITE,
cd9f247e
VK
544 struct sockaddr *pSender = NULL, socklen_t *piAddrSize = NULL,
545 SNMP_SecurityContext* (*contextFinder)(struct sockaddr *, socklen_t) = NULL);
c4366266 546 virtual int sendMessage(SNMP_PDU *pdu);
967893bb 547 virtual UINT32 getPeerIpAddress();
5039dede
AK
548};
549
596dc3aa
VK
550/**
551 * ISC flags
552 */
967893bb
VK
553#define ISCF_IS_CONNECTED ((UINT32)0x00000001)
554#define ISCF_REQUIRE_ENCRYPTION ((UINT32)0x00000002)
5039dede 555
ed950274
VK
556/**
557 * Inter-server connection (ISC)
558 */
5039dede
AK
559class LIBNXSRV_EXPORTABLE ISC
560{
561private:
967893bb
VK
562 UINT32 m_flags;
563 UINT32 m_addr;
5039dede
AK
564 WORD m_port;
565 SOCKET m_socket;
566 int m_protocolVersion;
bc7767c4 567 VolatileCounter m_requestId;
967893bb 568 UINT32 m_recvTimeout;
5039dede
AK
569 MsgWaitQueue *m_msgWaitQueue;
570 MUTEX m_mutexDataLock;
7b8b337e 571 MUTEX m_socketLock;
5039dede 572 THREAD m_hReceiverThread;
98abc9f1 573 NXCPEncryptionContext *m_ctx;
967893bb 574 UINT32 m_commandTimeout;
5039dede 575
bc7767c4
VK
576 void receiverThread();
577 static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *);
5039dede
AK
578
579protected:
bc7767c4
VK
580 UINT32 setupEncryption(RSA *pServerKey);
581 UINT32 connectToService(UINT32 service);
5039dede 582
c17f6cbc
VK
583 void Lock() { MutexLock(m_mutexDataLock); }
584 void Unlock() { MutexUnlock(m_mutexDataLock); }
5039dede
AK
585
586 virtual void PrintMsg(const TCHAR *format, ...);
bc7767c4 587 virtual void onBinaryMessage(CSCP_MESSAGE *rawMsg);
5039dede
AK
588
589public:
590 ISC();
967893bb 591 ISC(UINT32 addr, WORD port = NETXMS_ISC_PORT);
5039dede
AK
592 virtual ~ISC();
593
bc7767c4
VK
594 UINT32 connect(UINT32 service, RSA *serverKey = NULL, BOOL requireEncryption = FALSE);
595 void disconnect();
e7aff566 596 bool connected() { return m_flags & ISCF_IS_CONNECTED; };
5039dede 597
bc7767c4
VK
598 BOOL sendMessage(CSCPMessage *msg);
599 CSCPMessage *waitForMessage(WORD code, UINT32 id, UINT32 timeOut) { return m_msgWaitQueue->waitForMessage(code, id, timeOut); }
600 UINT32 waitForRCC(UINT32 rqId, UINT32 timeOut);
601 UINT32 generateMessageId() { return (UINT32)InterlockedIncrement(&m_requestId); }
5039dede 602
bc7767c4 603 UINT32 nop();
5039dede
AK
604};
605
606
607//
608// Functions
609//
610
611void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache);
5039dede
AK
612void LIBNXSRV_EXPORTABLE DestroyRoutingTable(ROUTING_TABLE *pRT);
613void LIBNXSRV_EXPORTABLE SortRoutingTable(ROUTING_TABLE *pRT);
614const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(int iError);
615
616void LIBNXSRV_EXPORTABLE WriteLogOther(WORD wType, const TCHAR *format, ...);
617void LIBNXSRV_EXPORTABLE DbgPrintf(int level, const TCHAR *format, ...);
9d88cdc9 618void LIBNXSRV_EXPORTABLE DbgPrintf2(int level, const TCHAR *format, va_list args);
c20b2798 619
5039dede
AK
620void LIBNXSRV_EXPORTABLE SetAgentDEP(int iPolicy);
621
967893bb 622const TCHAR LIBNXSRV_EXPORTABLE *ISCErrorCodeToText(UINT32 code);
5039dede 623
967893bb
VK
624UINT32 LIBNXSRV_EXPORTABLE SnmpNewRequestId();
625UINT32 LIBNXSRV_EXPORTABLE SnmpGet(UINT32 dwVersion, SNMP_Transport *pTransport,
626 const TCHAR *szOidStr, const UINT32 *oidBinary, UINT32 dwOidLen, void *pValue,
627 UINT32 dwBufferSize, UINT32 dwFlags);
628UINT32 LIBNXSRV_EXPORTABLE SnmpWalk(UINT32 dwVersion, SNMP_Transport *pTransport, const TCHAR *szRootOid,
629 UINT32 (* pHandler)(UINT32, SNMP_Variable *, SNMP_Transport *, void *),
46b7166d 630 void *pUserArg, BOOL bVerbose);
5ad2167d 631
5039dede
AK
632
633//
634// Variables
635//
636
967893bb
VK
637extern UINT32 LIBNXSRV_EXPORTABLE g_dwFlags;
638extern UINT32 LIBNXSRV_EXPORTABLE g_dwSNMPTimeout;
639extern UINT32 LIBNXSRV_EXPORTABLE g_debugLevel;
5039dede 640
89135050
VK
641
642//
643// Helper finctions for checking server flags
644//
645
646inline bool IsStandalone()
647{
648 return !(g_dwFlags & AF_DAEMON) ? true : false;
649}
650
651inline bool IsZoningEnabled()
652{
653 return (g_dwFlags & AF_ENABLE_ZONING) ? true : false;
654}
655
656inline bool IsShutdownInProgress()
657{
658 return (g_dwFlags & AF_SHUTDOWN) ? true : false;
659}
660
661
5039dede 662#endif /* _nxsrvapi_h_ */