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