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