fixed Windows build errors; minor refactoring
[public/netxms.git] / src / server / include / nms_core.h
CommitLineData
88f2990c 1/*
5039dede 2** NetXMS - Network Management System
d727efe6 3** Copyright (C) 2003-2016 Victor Kirhenshtein
5039dede
AK
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: nms_core.h
20**
21**/
22
23#ifndef _nms_core_h_
24#define _nms_core_h_
25
26#ifdef _WIN32
27#ifdef NXCORE_EXPORTS
28#define NXCORE_EXPORTABLE __declspec(dllexport)
29#else
30#define NXCORE_EXPORTABLE __declspec(dllimport)
31#endif
32#else /* _WIN32 */
33#define NXCORE_EXPORTABLE
34#endif
35
36#define LIBNXCL_NO_DECLARATIONS 1
37
38#include <nms_common.h>
39
40#ifndef _WIN32
41
42#if HAVE_SYS_TYPES_H
43# include <sys/types.h>
44#endif
45
46#if HAVE_DLFCN_H
47#include <dlfcn.h>
48#endif
49
d9177dd1 50
5039dede
AK
51#define WSAGetLastError() (errno)
52
53#endif /* _WIN32 */
54
55#include <time.h>
56#include <stdio.h>
57#include <string.h>
58#include <stdarg.h>
59
958a9397
VK
60#ifdef _WITH_ENCRYPTION
61#include <openssl/ssl.h>
62#endif
63
5039dede
AK
64//
65// Common includes
66//
67
68#include <nms_util.h>
69#include <dbdrv.h>
70#include <nms_cscp.h>
71#include <uuid.h>
72#include <nxsrvapi.h>
5039dede
AK
73#include <nxqueue.h>
74#include <nxsnmp.h>
75#include <nxmodule.h>
76#include <nxsl.h>
9d88cdc9 77#include <nxdbapi.h>
9796ce45 78#include <nddrv.h>
288a0046 79#include <npe.h>
d41edbd3 80#include <nxcore_smclp.h>
5039dede 81
46ee6286
VK
82/**
83 * Console context
84 */
5039dede
AK
85struct __console_ctx
86{
87 SOCKET hSocket;
d3a7cf4c 88 MUTEX socketMutex;
b368969c 89 NXCPMessage *pMsg;
200d662d 90 ClientSession *session;
244c65ef 91 String *output;
5039dede
AK
92};
93
94typedef __console_ctx * CONSOLE_CTX;
95
2bac37f9
VK
96/**
97 * Server includes
98 */
5039dede
AK
99#include "nms_dcoll.h"
100#include "nms_users.h"
46ee6286 101#include "nxcore_winperf.h"
5039dede 102#include "nms_objects.h"
5039dede
AK
103#include "nms_locks.h"
104#include "nms_pkg.h"
105#include "nms_topo.h"
106#include "nms_script.h"
00420032 107#include "nxcore_ps.h"
ab621f39 108#include "nxcore_jobs.h"
e05b1945 109#include "nxcore_logs.h"
fd72d846 110#include "nxcore_schedule.h"
4ef60905
AK
111#ifdef WITH_ZMQ
112#include "zeromq.h"
113#endif
5039dede 114
2bac37f9
VK
115/**
116 * Common constants and macros
117 */
73869331 118#define MAX_LINE_SIZE 4096
967893bb 119#define GROUP_FLAG_BIT ((UINT32)0x80000000)
73869331
VK
120#define CHECKPOINT_SNMP_PORT 260
121#define DEFAULT_AFFINITY_MASK 0xFFFFFFFF
5039dede 122
2a964810
VK
123#define MAX_CLIENT_SESSIONS 128
124#define MAX_DEVICE_SESSIONS 256
125
ebb2dc70
VK
126#define PING_TIME_TIMEOUT 10000
127
5039dede
AK
128typedef void * HSNMPSESSION;
129
0f506caa
VK
130/**
131 * Prefixes for poller messages
132 */
df8a4ca2
VK
133#define POLLER_ERROR _T("\x7F") _T("e")
134#define POLLER_WARNING _T("\x7Fw")
135#define POLLER_INFO _T("\x7Fi")
136
0f506caa
VK
137/**
138 * Unique identifier group codes
139 */
5039dede 140#define IDG_NETWORK_OBJECT 0
23464115
VK
141#define IDG_EVENT 1
142#define IDG_ITEM 2
143#define IDG_SNMP_TRAP 3
144#define IDG_JOB 4
145#define IDG_ACTION 5
146#define IDG_EVENT_GROUP 6
147#define IDG_THRESHOLD 7
148#define IDG_USER 8
149#define IDG_USER_GROUP 9
150#define IDG_ALARM 10
151#define IDG_ALARM_NOTE 11
152#define IDG_PACKAGE 12
153#define IDG_SLM_TICKET 13
154#define IDG_OBJECT_TOOL 14
155#define IDG_SCRIPT 15
156#define IDG_AGENT_CONFIG 16
157#define IDG_GRAPH 17
158#define IDG_CERTIFICATE 18
00420032 159#define IDG_DCT_COLUMN 19
160#define IDG_MAPPING_TABLE 20
161#define IDG_DCI_SUMMARY_TABLE 21
162#define IDG_SCHEDULED_TASK 22
163#define IDG_ALARM_CATEGORY 23
5039dede 164
0f506caa
VK
165/**
166 * Exit codes for console commands
167 */
5039dede
AK
168#define CMD_EXIT_CONTINUE 0
169#define CMD_EXIT_CLOSE_SESSION 1
170#define CMD_EXIT_SHUTDOWN 2
171
0f506caa
VK
172/**
173 * Network discovery mode
174 */
5039dede
AK
175#define DISCOVERY_DISABLED 0
176#define DISCOVERY_PASSIVE_ONLY 1
177#define DISCOVERY_ACTIVE 2
178
0f506caa
VK
179/**
180 * Client session flags
181 */
134c3d00 182#define CSF_TERMINATED ((UINT32)0x00000001)
850ce3ed
VK
183#define CSF_EPP_LOCKED ((UINT32)0x00000002)
184#define CSF_PACKAGE_DB_LOCKED ((UINT32)0x00000004)
185#define CSF_USER_DB_LOCKED ((UINT32)0x00000008)
186#define CSF_EPP_UPLOAD ((UINT32)0x00000010)
187#define CSF_CONSOLE_OPEN ((UINT32)0x00000020)
188#define CSF_AUTHENTICATED ((UINT32)0x00000080)
4970ef34 189#define CSF_COMPRESSION_ENABLED ((UINT32)0x00000100)
850ce3ed
VK
190#define CSF_RECEIVING_MAP_DATA ((UINT32)0x00000200)
191#define CSF_SYNC_OBJECT_COMMENTS ((UINT32)0x00000400)
678fe569
VK
192#define CSF_CUSTOM_LOCK_1 ((UINT32)0x01000000)
193#define CSF_CUSTOM_LOCK_2 ((UINT32)0x02000000)
194#define CSF_CUSTOM_LOCK_3 ((UINT32)0x04000000)
195#define CSF_CUSTOM_LOCK_4 ((UINT32)0x08000000)
196#define CSF_CUSTOM_LOCK_5 ((UINT32)0x10000000)
197#define CSF_CUSTOM_LOCK_6 ((UINT32)0x20000000)
198#define CSF_CUSTOM_LOCK_7 ((UINT32)0x40000000)
199#define CSF_CUSTOM_LOCK_8 ((UINT32)0x80000000)
5039dede 200
0f506caa
VK
201/**
202 * Client session states
203 */
5039dede
AK
204#define SESSION_STATE_INIT 0
205#define SESSION_STATE_IDLE 1
206#define SESSION_STATE_PROCESSING 2
207
0f506caa
VK
208/**
209 * Information categories for UPDATE_INFO structure
210 */
5039dede
AK
211#define INFO_CAT_EVENT 1
212#define INFO_CAT_OBJECT_CHANGE 2
213#define INFO_CAT_ALARM 3
214#define INFO_CAT_ACTION 4
215#define INFO_CAT_SYSLOG_MSG 5
216#define INFO_CAT_SNMP_TRAP 6
217#define INFO_CAT_AUDIT_RECORD 7
00420032 218//#define INFO_CAT_SITUATION 8
624f1165 219#define INFO_CAT_LIBRARY_IMAGE 9
5039dede 220
0f506caa
VK
221/**
222 * Certificate types
223 */
5039dede
AK
224#define CERT_TYPE_TRUSTED_CA 0
225#define CERT_TYPE_USER 1
226
0f506caa
VK
227/**
228 * Audit subsystems
229 */
5039dede
AK
230#define AUDIT_SECURITY _T("SECURITY")
231#define AUDIT_OBJECTS _T("OBJECTS")
232#define AUDIT_SYSCFG _T("SYSCFG")
233#define AUDIT_CONSOLE _T("CONSOLE")
234
2a964810
VK
235#define AUDIT_SYSTEM_SID (-1)
236
0f506caa
VK
237/**
238 * Event handling subsystem definitions
239 */
5039dede
AK
240#include "nms_events.h"
241#include "nms_actions.h"
242#include "nms_alarm.h"
243
0f506caa
VK
244/**
245 * New node information
246 */
5039dede
AK
247typedef struct
248{
c75e9ee4 249 InetAddress ipAddr;
967893bb 250 UINT32 zoneId;
5039dede 251 BOOL ignoreFilter;
baa5324c 252 BYTE bMacAddr[MAC_ADDR_LENGTH];
5039dede
AK
253} NEW_NODE;
254
0f506caa
VK
255/**
256 * New node flags
257 */
5039dede
AK
258#define NNF_IS_SNMP 0x0001
259#define NNF_IS_AGENT 0x0002
260#define NNF_IS_ROUTER 0x0004
261#define NNF_IS_BRIDGE 0x0008
262#define NNF_IS_PRINTER 0x0010
263#define NNF_IS_CDP 0x0020
264#define NNF_IS_SONMP 0x0040
265#define NNF_IS_LLDP 0x0080
266
ba889094
VK
267/**
268 * Address list element types
269 */
270#define InetAddressListElement_SUBNET 0
271#define InetAddressListElement_RANGE 1
272
273/**
274 * IP address list element
275 */
276class NXCORE_EXPORTABLE InetAddressListElement
277{
278private:
279 int m_type;
280 InetAddress m_baseAddress;
281 InetAddress m_endAddress;
282
283public:
284 InetAddressListElement(NXCPMessage *msg, UINT32 baseId);
285 InetAddressListElement(const InetAddress& baseAddr, const InetAddress& endAddr);
286 InetAddressListElement(const InetAddress& baseAddr, int maskBits);
287 InetAddressListElement(DB_RESULT hResult, int row);
288
289 void fillMessage(NXCPMessage *msg, UINT32 baseId) const;
290
291 bool contains(const InetAddress& addr) const;
292
293 int getType() const { return m_type; }
294 const InetAddress& getBaseAddress() const { return m_baseAddress; }
295 const InetAddress& getEndAddress() const { return m_endAddress; }
296
297 String toString() const;
298};
299
0f506caa
VK
300/**
301 * Node information for autodiscovery filter
302 */
5039dede
AK
303typedef struct
304{
c75e9ee4 305 InetAddress ipAddr;
967893bb 306 UINT32 dwFlags;
5039dede 307 int nSNMPVersion;
35f836fe
VK
308 TCHAR szObjectId[MAX_OID_LEN * 4]; // SNMP OID
309 TCHAR szAgentVersion[MAX_AGENT_VERSION_LEN];
310 TCHAR szPlatform[MAX_PLATFORM_NAME_LEN];
5039dede
AK
311} DISCOVERY_FILTER_DATA;
312
0f506caa
VK
313/**
314 * Data update structure for client sessions
315 */
5039dede
AK
316typedef struct
317{
967893bb
VK
318 UINT32 dwCategory; // Data category - event, network object, etc.
319 UINT32 dwCode; // Data-specific update code
5039dede
AK
320 void *pData; // Pointer to data block
321} UPDATE_INFO;
322
534e1b83
VK
323/**
324 * Mobile device session
325 */
326class NXCORE_EXPORTABLE MobileDeviceSession
327{
328private:
329 SOCKET m_hSocket;
330 Queue *m_pSendQueue;
331 Queue *m_pMessageQueue;
2a964810
VK
332 int m_id;
333 int m_state;
534e1b83 334 WORD m_wCurrentCmd;
967893bb
VK
335 UINT32 m_dwUserId;
336 UINT32 m_deviceObjectId;
b368969c 337 NXCP_BUFFER *m_pMsgBuffer;
534e1b83
VK
338 NXCPEncryptionContext *m_pCtx;
339 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
340 THREAD m_hWriteThread;
341 THREAD m_hProcessingThread;
342 MUTEX m_mutexSocketWrite;
343 struct sockaddr *m_clientAddr;
344 TCHAR m_szHostName[256]; // IP address of name of conneced host in textual form
345 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
346 TCHAR m_szClientInfo[96]; // Client app info string
967893bb
VK
347 UINT32 m_dwEncryptionRqId;
348 UINT32 m_dwEncryptionResult;
534e1b83 349 CONDITION m_condEncryptionSetup;
967893bb 350 UINT32 m_dwRefCount;
534e1b83
VK
351 bool m_isAuthenticated;
352
353 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
354 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
355 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
5039dede 356
534e1b83
VK
357 void readThread();
358 void writeThread();
359 void processingThread();
360
b368969c 361 void setupEncryption(NXCPMessage *request);
967893bb 362 void respondToKeepalive(UINT32 dwRqId);
534e1b83 363 void debugPrintf(int level, const TCHAR *format, ...);
967893bb 364 void sendServerInfo(UINT32 dwRqId);
b368969c
VK
365 void login(NXCPMessage *pRequest);
366 void updateDeviceInfo(NXCPMessage *pRequest);
367 void updateDeviceStatus(NXCPMessage *pRequest);
368 void pushData(NXCPMessage *request);
534e1b83
VK
369
370public:
371 MobileDeviceSession(SOCKET hSocket, struct sockaddr *addr);
372 ~MobileDeviceSession();
373
534e1b83
VK
374 void run();
375
19dbc8ef 376 void postMessage(NXCPMessage *pMsg) { m_pSendQueue->put(pMsg->createMessage()); }
b368969c 377 void sendMessage(NXCPMessage *pMsg);
5039dede 378
2a964810
VK
379 int getId() { return m_id; }
380 void setId(int id) { if (m_id == -1) m_id = id; }
381 int getState() { return m_state; }
534e1b83
VK
382 const TCHAR *getUserName() { return m_szUserName; }
383 const TCHAR *getClientInfo() { return m_szClientInfo; }
384 const TCHAR *getHostName() { return m_szHostName; }
967893bb 385 UINT32 getUserId() { return m_dwUserId; }
534e1b83
VK
386 bool isAuthenticated() { return m_isAuthenticated; }
387 WORD getCurrentCmd() { return m_wCurrentCmd; }
388 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
389};
390
391/**
84ea7692 392 * Processing thread starter declaration for client session
534e1b83 393 */
134c3d00 394#define DECLARE_THREAD_STARTER(func) static void ThreadStarter_##func(void *);
5039dede 395
7b45b90d 396/**
397 * Class that stores information about file that will be received
398 */
b8b6cd2f 399class ServerDownloadFileInfo : public DownloadFileInfo
7b45b90d 400{
b8b6cd2f 401protected:
7b45b90d 402 UINT32 m_uploadCommand;
403 UINT32 m_uploadData;
b8b6cd2f 404 uuid m_uploadImageGuid;
7b45b90d 405
406public:
b8b6cd2f
VK
407 ServerDownloadFileInfo(const TCHAR *name, UINT32 uploadCommand, time_t lastModTime = 0);
408 virtual ~ServerDownloadFileInfo();
409
410 virtual void close(bool success);
411
412 void setUploadData(UINT32 data) { m_uploadData = data; }
413 void setImageGuid(const uuid& guid) { m_uploadImageGuid = guid; }
7b45b90d 414 void updateAgentPkgDBInfo(const TCHAR *description, const TCHAR *pkgName, const TCHAR *pkgVersion, const TCHAR *platform, const TCHAR *cleanFileName);
7b45b90d 415};
416
84ea7692
VK
417/**
418 * Client (user) session
419 */
a0e3917e 420class NXCORE_EXPORTABLE ClientSession
5039dede
AK
421{
422private:
423 SOCKET m_hSocket;
424 Queue *m_pSendQueue;
425 Queue *m_pMessageQueue;
426 Queue *m_pUpdateQueue;
2a964810
VK
427 int m_id;
428 int m_state;
5039dede 429 WORD m_wCurrentCmd;
967893bb 430 UINT32 m_dwUserId;
f4d8fe18 431 UINT64 m_dwSystemAccess; // User's system access rights
967893bb 432 UINT32 m_dwFlags; // Session flags
f8c6f10f 433 int m_clientType; // Client system type - desktop, web, mobile, etc.
98abc9f1 434 NXCPEncryptionContext *m_pCtx;
5039dede
AK
435 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
436 THREAD m_hWriteThread;
437 THREAD m_hProcessingThread;
438 THREAD m_hUpdateThread;
d3a7cf4c 439 MUTEX m_mutexSocketWrite;
5039dede
AK
440 MUTEX m_mutexSendEvents;
441 MUTEX m_mutexSendSyslog;
442 MUTEX m_mutexSendTrapLog;
443 MUTEX m_mutexSendObjects;
444 MUTEX m_mutexSendAlarms;
445 MUTEX m_mutexSendActions;
446 MUTEX m_mutexSendAuditLog;
5039dede 447 MUTEX m_mutexPollerInit;
60557d06 448 struct sockaddr *m_clientAddr;
91f6b72c
VK
449 TCHAR m_workstation[256]; // IP address or name of connected host in textual form
450 TCHAR m_webServerAddress[256]; // IP address or name of web server for web sessions
77a08c86
VK
451 TCHAR m_loginName[MAX_USER_NAME];
452 TCHAR m_sessionName[MAX_SESSION_NAME]; // String in form login_name@host
453 TCHAR m_clientInfo[96]; // Client app info string
2a964810 454 TCHAR m_language[8]; // Client's desired language
a51628e2 455 time_t m_loginTime;
967893bb
VK
456 UINT32 m_dwOpenDCIListSize; // Number of open DCI lists
457 UINT32 *m_pOpenDCIList; // List of nodes with DCI lists open
458 UINT32 m_dwNumRecordsToUpload; // Number of records to be uploaded
459 UINT32 m_dwRecordsUploaded;
5039dede 460 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
b8b6cd2f 461 HashMap<UINT32, ServerDownloadFileInfo> *m_downloadFileMap;
c044d4f3 462 VolatileCounter m_refCount;
967893bb
VK
463 UINT32 m_dwEncryptionRqId;
464 UINT32 m_dwEncryptionResult;
5039dede 465 CONDITION m_condEncryptionSetup;
200d662d 466 CONSOLE_CTX m_console; // Server console context
810bd8c4 467 StringList m_musicTypeList;
7cf549ad 468 ObjectIndex m_agentConn;
84ea7692 469 StringObjectMap<UINT32> *m_subscriptions;
c044d4f3 470 MUTEX m_subscriptionLock;
45ac5dd0 471 HashMap<UINT32, CommandExec> *m_serverCommands;
5039dede 472
534e1b83
VK
473 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
474 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
475 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
476 static THREAD_RESULT THREAD_CALL updateThreadStarter(void *);
134c3d00 477 static void pollerThreadStarter(void *);
5039dede 478
78ccd7b4
VK
479 DECLARE_THREAD_STARTER(cancelFileMonitoring)
480 DECLARE_THREAD_STARTER(clearDCIData)
481 DECLARE_THREAD_STARTER(createObject)
482 DECLARE_THREAD_STARTER(executeAction)
483 DECLARE_THREAD_STARTER(executeScript)
e9bf9011 484 DECLARE_THREAD_STARTER(executeLibraryScript)
74d0b136 485 DECLARE_THREAD_STARTER(fileManagerControl)
78ccd7b4
VK
486 DECLARE_THREAD_STARTER(findIpAddress)
487 DECLARE_THREAD_STARTER(findMacAddress)
f1984eb9 488 DECLARE_THREAD_STARTER(findHostname)
78ccd7b4
VK
489 DECLARE_THREAD_STARTER(findNodeConnection)
490 DECLARE_THREAD_STARTER(forceDCIPoll)
491 DECLARE_THREAD_STARTER(forwardToReportingServer)
492 DECLARE_THREAD_STARTER(getAgentFile)
493 DECLARE_THREAD_STARTER(getAlarmEvents)
3ddc492b 494 DECLARE_THREAD_STARTER(getAlarms)
78ccd7b4 495 DECLARE_THREAD_STARTER(getCollectedData)
0cf6fcbd 496 DECLARE_THREAD_STARTER(getPredictedData)
4899db4d 497 DECLARE_THREAD_STARTER(getLocationHistory)
78ccd7b4
VK
498 DECLARE_THREAD_STARTER(getNetworkPath)
499 DECLARE_THREAD_STARTER(getRoutingTable)
500 DECLARE_THREAD_STARTER(getServerFile)
501 DECLARE_THREAD_STARTER(getServerLogQueryData)
502 DECLARE_THREAD_STARTER(getSwitchForwardingDatabase)
503 DECLARE_THREAD_STARTER(getTableCollectedData)
504 DECLARE_THREAD_STARTER(importConfiguration)
505 DECLARE_THREAD_STARTER(openHelpdeskIssue)
506 DECLARE_THREAD_STARTER(processConsoleCommand)
507 DECLARE_THREAD_STARTER(queryAgentTable)
508 DECLARE_THREAD_STARTER(queryL2Topology)
509 DECLARE_THREAD_STARTER(queryParameter)
510 DECLARE_THREAD_STARTER(queryServerLog)
511 DECLARE_THREAD_STARTER(sendEventLog)
512 DECLARE_THREAD_STARTER(sendMib)
513 DECLARE_THREAD_STARTER(sendSyslog)
514 DECLARE_THREAD_STARTER(uploadUserFileToAgent)
badd6e08
VK
515 DECLARE_THREAD_STARTER(getRepositories)
516 DECLARE_THREAD_STARTER(addRepository)
517 DECLARE_THREAD_STARTER(modifyRepository)
518 DECLARE_THREAD_STARTER(deleteRepository)
5039dede 519
62768df3
VK
520 void readThread();
521 void writeThread();
522 void processingThread();
523 void updateThread();
967893bb 524 void pollerThread(Node *pNode, int iPollType, UINT32 dwRqId);
5039dede 525
badd6e08
VK
526 void debugPrintf(int level, const TCHAR *format, ...);
527
b368969c 528 void setupEncryption(NXCPMessage *request);
967893bb 529 void respondToKeepalive(UINT32 dwRqId);
e05b1945 530 void onFileUpload(BOOL bSuccess);
967893bb 531 void sendServerInfo(UINT32 dwRqId);
b368969c
VK
532 void login(NXCPMessage *pRequest);
533 void sendAllObjects(NXCPMessage *pRequest);
534 void sendSelectedObjects(NXCPMessage *pRequest);
535 void sendEventLog(NXCPMessage *pRequest);
c85c8ef2
VK
536 void getConfigurationVariables(UINT32 dwRqId);
537 void getPublicConfigurationVariable(NXCPMessage *request);
538 void setConfigurationVariable(NXCPMessage *pRequest);
539 void deleteConfigurationVariable(NXCPMessage *pRequest);
967893bb 540 void sendUserDB(UINT32 dwRqId);
b368969c
VK
541 void createUser(NXCPMessage *pRequest);
542 void updateUser(NXCPMessage *pRequest);
2d8d8ea2 543 void detachLdapUser(NXCPMessage *pRequest);
b368969c 544 void deleteUser(NXCPMessage *pRequest);
77a08c86
VK
545 void setPassword(NXCPMessage *request);
546 void validatePassword(NXCPMessage *request);
967893bb 547 void lockUserDB(UINT32 dwRqId, BOOL bLock);
a881eafa 548 void getAlarmCategories(UINT32 requestId);
6a6b96c0 549 void modifyAlarmCategory(NXCPMessage *pRequest);
a881eafa 550 void deleteAlarmCategory(NXCPMessage *pRequest);
967893bb 551 void sendEventDB(UINT32 dwRqId);
b368969c
VK
552 void modifyEventTemplate(NXCPMessage *pRequest);
553 void deleteEventTemplate(NXCPMessage *pRequest);
967893bb 554 void generateEventCode(UINT32 dwRqId);
b368969c
VK
555 void modifyObject(NXCPMessage *pRequest);
556 void changeObjectMgmtStatus(NXCPMessage *pRequest);
7e18667a
VK
557 void enterMaintenanceMode(NXCPMessage *request);
558 void leaveMaintenanceMode(NXCPMessage *request);
b368969c
VK
559 void openNodeDCIList(NXCPMessage *pRequest);
560 void closeNodeDCIList(NXCPMessage *pRequest);
561 void modifyNodeDCI(NXCPMessage *pRequest);
562 void copyDCI(NXCPMessage *pRequest);
563 void applyTemplate(NXCPMessage *pRequest);
564 void getCollectedData(NXCPMessage *pRequest);
565 void getTableCollectedData(NXCPMessage *pRequest);
566 bool getCollectedDataFromDB(NXCPMessage *request, NXCPMessage *response, DataCollectionTarget *object, int dciType);
567 void clearDCIData(NXCPMessage *pRequest);
79633a65 568 void forceDCIPoll(NXCPMessage *pRequest);
b368969c
VK
569 void changeDCIStatus(NXCPMessage *pRequest);
570 void getLastValues(NXCPMessage *pRequest);
571 void getLastValuesByDciId(NXCPMessage *pRequest);
572 void getTableLastValues(NXCPMessage *pRequest);
573 void getThresholdSummary(NXCPMessage *request);
574 void openEPP(NXCPMessage *request);
967893bb 575 void closeEPP(UINT32 dwRqId);
b368969c
VK
576 void saveEPP(NXCPMessage *pRequest);
577 void processEPPRecord(NXCPMessage *pRequest);
967893bb 578 void sendMIBTimestamp(UINT32 dwRqId);
b368969c
VK
579 void sendMib(NXCPMessage *request);
580 void createObject(NXCPMessage *request);
581 void changeObjectBinding(NXCPMessage *request, BOOL bBind);
582 void deleteObject(NXCPMessage *request);
3ddc492b 583 void getAlarms(NXCPMessage *request);
b368969c
VK
584 void getAlarm(NXCPMessage *request);
585 void getAlarmEvents(NXCPMessage *request);
586 void acknowledgeAlarm(NXCPMessage *request);
587 void resolveAlarm(NXCPMessage *request, bool terminate);
a881eafa 588 void bulkResolveAlarms(NXCPMessage *pRequest, bool terminate);
b368969c
VK
589 void deleteAlarm(NXCPMessage *request);
590 void openHelpdeskIssue(NXCPMessage *request);
591 void getHelpdeskUrl(NXCPMessage *request);
592 void unlinkHelpdeskIssue(NXCPMessage *request);
593 void getAlarmComments(NXCPMessage *pRequest);
594 void updateAlarmComment(NXCPMessage *pRequest);
595 void deleteAlarmComment(NXCPMessage *request);
596 void updateAlarmStatusFlow(NXCPMessage *request);
597 void createAction(NXCPMessage *pRequest);
598 void updateAction(NXCPMessage *pRequest);
599 void deleteAction(NXCPMessage *pRequest);
967893bb 600 void sendAllActions(UINT32 dwRqId);
b368969c
VK
601 void forcedNodePoll(NXCPMessage *pRequest);
602 void onTrap(NXCPMessage *pRequest);
603 void onWakeUpNode(NXCPMessage *pRequest);
604 void queryParameter(NXCPMessage *pRequest);
605 void queryAgentTable(NXCPMessage *pRequest);
606 void editTrap(int iOperation, NXCPMessage *pRequest);
967893bb
VK
607 void LockTrapCfg(UINT32 dwRqId, BOOL bLock);
608 void sendAllTraps(UINT32 dwRqId);
609 void sendAllTraps2(UINT32 dwRqId);
610 void LockPackageDB(UINT32 dwRqId, BOOL bLock);
611 void SendAllPackages(UINT32 dwRqId);
b368969c
VK
612 void InstallPackage(NXCPMessage *pRequest);
613 void RemovePackage(NXCPMessage *pRequest);
614 void DeployPackage(NXCPMessage *pRequest);
615 void getParametersList(NXCPMessage *pRequest);
616 void getUserVariable(NXCPMessage *pRequest);
617 void setUserVariable(NXCPMessage *pRequest);
618 void copyUserVariable(NXCPMessage *pRequest);
619 void enumUserVariables(NXCPMessage *pRequest);
620 void deleteUserVariable(NXCPMessage *pRequest);
621 void changeObjectZone(NXCPMessage *pRequest);
622 void getAgentConfig(NXCPMessage *pRequest);
623 void updateAgentConfig(NXCPMessage *pRequest);
624 void executeAction(NXCPMessage *pRequest);
b576249a
VK
625 void getObjectTools(UINT32 requestId);
626 void getObjectToolDetails(NXCPMessage *request);
b368969c
VK
627 void updateObjectTool(NXCPMessage *pRequest);
628 void deleteObjectTool(NXCPMessage *pRequest);
629 void changeObjectToolStatus(NXCPMessage *pRequest);
967893bb 630 void generateObjectToolId(UINT32 dwRqId);
b368969c
VK
631 void execTableTool(NXCPMessage *pRequest);
632 void changeSubscription(NXCPMessage *pRequest);
633 void sendSyslog(NXCPMessage *pRequest);
967893bb
VK
634 void sendServerStats(UINT32 dwRqId);
635 void sendScriptList(UINT32 dwRqId);
b368969c
VK
636 void sendScript(NXCPMessage *pRequest);
637 void updateScript(NXCPMessage *pRequest);
638 void renameScript(NXCPMessage *pRequest);
639 void deleteScript(NXCPMessage *pRequest);
967893bb 640 void SendSessionList(UINT32 dwRqId);
b368969c
VK
641 void KillSession(NXCPMessage *pRequest);
642 void SendTrapLog(NXCPMessage *pRequest);
643 void StartSnmpWalk(NXCPMessage *pRequest);
644 void resolveDCINames(NXCPMessage *pRequest);
55a918b7 645 UINT32 resolveDCIName(UINT32 dwNode, UINT32 dwItem, TCHAR *ppszName);
b368969c 646 void sendConfigForAgent(NXCPMessage *pRequest);
967893bb 647 void sendAgentCfgList(UINT32 dwRqId);
b368969c
VK
648 void OpenAgentConfig(NXCPMessage *pRequest);
649 void SaveAgentConfig(NXCPMessage *pRequest);
650 void DeleteAgentConfig(NXCPMessage *pRequest);
651 void SwapAgentConfigs(NXCPMessage *pRequest);
652 void SendObjectComments(NXCPMessage *pRequest);
653 void updateObjectComments(NXCPMessage *pRequest);
654 void pushDCIData(NXCPMessage *pRequest);
ba889094
VK
655 void getAddrList(NXCPMessage *request);
656 void setAddrList(NXCPMessage *request);
b368969c 657 void resetComponent(NXCPMessage *pRequest);
25a1e9d0
VK
658 void getDCIEventList(NXCPMessage *request);
659 void getDCIScriptList(NXCPMessage *request);
b368969c
VK
660 void SendDCIInfo(NXCPMessage *pRequest);
661 void sendPerfTabDCIList(NXCPMessage *pRequest);
662 void exportConfiguration(NXCPMessage *pRequest);
663 void importConfiguration(NXCPMessage *pRequest);
aed41472 664 void sendGraphList(NXCPMessage *request);
b368969c
VK
665 void saveGraph(NXCPMessage *pRequest);
666 void deleteGraph(NXCPMessage *pRequest);
493beadc
VK
667 void addCACertificate(NXCPMessage *pRequest);
668 void deleteCertificate(NXCPMessage *pRequest);
669 void updateCertificateComments(NXCPMessage *pRequest);
967893bb 670 void getCertificateList(UINT32 dwRqId);
b368969c
VK
671 void queryL2Topology(NXCPMessage *pRequest);
672 void sendSMS(NXCPMessage *pRequest);
967893bb 673 void SendCommunityList(UINT32 dwRqId);
b368969c 674 void UpdateCommunityList(NXCPMessage *pRequest);
00420032 675 void getPersistantStorage(UINT32 dwRqId);
676 void setPstorageValue(NXCPMessage *pRequest);
677 void deletePstorageValue(NXCPMessage *pRequest);
b368969c
VK
678 void setConfigCLOB(NXCPMessage *pRequest);
679 void getConfigCLOB(NXCPMessage *pRequest);
680 void registerAgent(NXCPMessage *pRequest);
681 void getServerFile(NXCPMessage *pRequest);
682 void cancelFileMonitoring(NXCPMessage *request);
683 void getAgentFile(NXCPMessage *pRequest);
684 void testDCITransformation(NXCPMessage *pRequest);
967893bb 685 void sendJobList(UINT32 dwRqId);
b368969c
VK
686 void cancelJob(NXCPMessage *pRequest);
687 void holdJob(NXCPMessage *pRequest);
688 void unholdJob(NXCPMessage *pRequest);
689 void deployAgentPolicy(NXCPMessage *pRequest, bool uninstallFlag);
690 void getUserCustomAttribute(NXCPMessage *request);
691 void setUserCustomAttribute(NXCPMessage *request);
692 void openServerLog(NXCPMessage *request);
693 void closeServerLog(NXCPMessage *request);
694 void queryServerLog(NXCPMessage *request);
695 void getServerLogQueryData(NXCPMessage *request);
967893bb 696 void sendUsmCredentials(UINT32 dwRqId);
b368969c
VK
697 void updateUsmCredentials(NXCPMessage *pRequest);
698 void sendDCIThresholds(NXCPMessage *request);
699 void addClusterNode(NXCPMessage *request);
700 void findNodeConnection(NXCPMessage *request);
701 void findMacAddress(NXCPMessage *request);
702 void findIpAddress(NXCPMessage *request);
f1984eb9 703 void findHostname(NXCPMessage *request);
b368969c
VK
704 void sendLibraryImage(NXCPMessage *request);
705 void updateLibraryImage(NXCPMessage *request);
706 void listLibraryImages(NXCPMessage *request);
707 void deleteLibraryImage(NXCPMessage *request);
708 void executeServerCommand(NXCPMessage *request);
45ac5dd0 709 void stopServerCommand(NXCPMessage *request);
b368969c
VK
710 void uploadFileToAgent(NXCPMessage *request);
711 void listServerFileStore(NXCPMessage *request);
712 void processConsoleCommand(NXCPMessage *msg);
967893bb
VK
713 void openConsole(UINT32 rqId);
714 void closeConsole(UINT32 rqId);
b368969c
VK
715 void getVlans(NXCPMessage *msg);
716 void receiveFile(NXCPMessage *request);
717 void deleteFile(NXCPMessage *request);
718 void getNetworkPath(NXCPMessage *request);
719 void getNodeComponents(NXCPMessage *request);
720 void getNodeSoftware(NXCPMessage *request);
721 void getWinPerfObjects(NXCPMessage *request);
722 void listMappingTables(NXCPMessage *request);
723 void getMappingTable(NXCPMessage *request);
724 void updateMappingTable(NXCPMessage *request);
725 void deleteMappingTable(NXCPMessage *request);
726 void getWirelessStations(NXCPMessage *request);
967893bb 727 void getSummaryTables(UINT32 rqId);
b368969c
VK
728 void getSummaryTableDetails(NXCPMessage *request);
729 void modifySummaryTable(NXCPMessage *request);
730 void deleteSummaryTable(NXCPMessage *request);
731 void querySummaryTable(NXCPMessage *request);
732 void queryAdHocSummaryTable(NXCPMessage *request);
733 void forwardToReportingServer(NXCPMessage *request);
734 void getSubnetAddressMap(NXCPMessage *request);
735 void getEffectiveRights(NXCPMessage *request);
736 void fileManagerControl(NXCPMessage *request);
737 void uploadUserFileToAgent(NXCPMessage *request);
738 void getSwitchForwardingDatabase(NXCPMessage *request);
739 void getRoutingTable(NXCPMessage *request);
740 void getLocationHistory(NXCPMessage *request);
741 void getScreenshot(NXCPMessage *request);
742 void executeScript(NXCPMessage *request);
e9bf9011 743 void executeLibraryScript(NXCPMessage *request);
5f573844 744 void compileScript(NXCPMessage *request);
4b535d78 745 void resyncAgentDciConfiguration(NXCPMessage *request);
746 void cleanAgentDciConfiguration(NXCPMessage *request);
ec13a467
VK
747 void getSchedulerTaskHandlers(NXCPMessage *request);
748 void getScheduledTasks(NXCPMessage *request);
749 void addScheduledTask(NXCPMessage *request);
750 void updateScheduledTask(NXCPMessage *request);
751 void removeScheduledTask(NXCPMessage *request);
badd6e08
VK
752 void getRepositories(NXCPMessage *request);
753 void addRepository(NXCPMessage *request);
754 void modifyRepository(NXCPMessage *request);
755 void deleteRepository(NXCPMessage *request);
0cf6fcbd
VK
756 void getPredictionEngines(NXCPMessage *request);
757 void getPredictedData(NXCPMessage *request);
4ef60905
AK
758#ifdef WITH_ZMQ
759 void zmqManageSubscription(NXCPMessage *request, zmq::SubscriptionType type, bool subscribe);
760 void zmqListSubscriptions(NXCPMessage *request, zmq::SubscriptionType type);
761#endif
45ac5dd0 762 void registerServerCommand(CommandExec *command) { m_serverCommands->set(command->getStreamId(), command); }
5039dede
AK
763
764public:
60557d06 765 ClientSession(SOCKET hSocket, struct sockaddr *addr);
5039dede
AK
766 ~ClientSession();
767
c044d4f3
VK
768 void incRefCount() { InterlockedIncrement(&m_refCount); }
769 void decRefCount() { InterlockedDecrement(&m_refCount); }
e05b1945
VK
770
771 void run();
772
4970ef34 773 void postMessage(NXCPMessage *pMsg) { m_pSendQueue->put(pMsg->createMessage((m_dwFlags & CSF_COMPRESSION_ENABLED) != 0)); }
a07511b5 774 bool sendMessage(NXCPMessage *pMsg);
b368969c 775 void sendRawMessage(NXCP_MESSAGE *pMsg);
967893bb 776 void sendPollerMsg(UINT32 dwRqId, const TCHAR *pszMsg);
cc022855 777 BOOL sendFile(const TCHAR *file, UINT32 dwRqId, long offset);
e05b1945 778
9515e7b1
VK
779 void writeAuditLog(const TCHAR *subsys, bool success, UINT32 objectId, const TCHAR *format, ...);
780
c044d4f3 781 int getId() const { return m_id; }
2a964810 782 void setId(int id) { if (m_id == -1) m_id = id; }
e05b1945 783
c044d4f3
VK
784 int getState() const { return m_state; }
785 const TCHAR *getLoginName() const { return m_loginName; }
786 const TCHAR *getSessionName() const { return m_sessionName; }
787 const TCHAR *getClientInfo() const { return m_clientInfo; }
788 const TCHAR *getWorkstation() const { return m_workstation; }
789 const TCHAR *getWebServerAddress() const { return m_webServerAddress; }
790 UINT32 getUserId() const { return m_dwUserId; }
791 UINT64 getSystemRights() const { return m_dwSystemAccess; }
792 UINT32 getFlags() const { return m_dwFlags; }
793 bool isAuthenticated() const { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
794 bool isTerminated() const { return (m_dwFlags & CSF_TERMINATED) ? true : false; }
795 bool isConsoleOpen() const { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
d3a20572
VK
796 bool isCompressionEnabled() const { return (m_dwFlags & CSF_COMPRESSION_ENABLED) ? true : false; }
797 UINT16 getCurrentCmd() const { return m_wCurrentCmd; }
c044d4f3
VK
798 int getCipher() const { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
799 int getClientType() const { return m_clientType; }
800 time_t getLoginTime() const { return m_loginTime; }
801 bool isSubscribedTo(const TCHAR *channel) const;
802
803 bool checkSysAccessRights(UINT64 requiredAccess) const
88f2990c 804 {
805 return (m_dwUserId == 0) ? true :
badf9a95 806 ((requiredAccess & m_dwSystemAccess) == requiredAccess);
e05b1945
VK
807 }
808
87f56b19
VK
809 void setCustomLock(UINT32 bit, bool value)
810 {
811 if (value)
812 m_dwFlags |= (bit & 0xFF000000);
813 else
814 m_dwFlags &= ~(bit & 0xFF000000);
815 }
816
f669df41 817 void kill();
967893bb 818 void notify(UINT32 dwCode, UINT32 dwData = 0);
e05b1945 819
19dbc8ef 820 void queueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->put(pUpdate); }
e05b1945 821 void onNewEvent(Event *pEvent);
e0f99bf0 822 void onSyslogMessage(NX_SYSLOG_RECORD *pRec);
b368969c 823 void onNewSNMPTrap(NXCPMessage *pMsg);
e05b1945 824 void onObjectChange(NetObj *pObject);
d727efe6 825 void onAlarmUpdate(UINT32 dwCode, const Alarm *alarm);
967893bb 826 void onActionDBUpdate(UINT32 dwCode, NXC_ACTION *pAction);
b8b6cd2f 827 void onLibraryImageChange(const uuid& guid, bool removed = false);
5039dede
AK
828};
829
2bac37f9
VK
830/**
831 * Delayed SQL request
832 */
7dad92fb
VK
833typedef struct
834{
835 TCHAR *query;
836 int bindCount;
837 BYTE *sqlTypes;
838 TCHAR *bindings[1]; /* actual size determined by bindCount field */
839} DELAYED_SQL_REQUEST;
840
2bac37f9
VK
841/**
842 * Delayed request for idata_ INSERT
843 */
f68d9eac
VK
844typedef struct
845{
846 time_t timestamp;
967893bb
VK
847 UINT32 nodeId;
848 UINT32 dciId;
f68d9eac
VK
849 TCHAR value[MAX_RESULT_LENGTH];
850} DELAYED_IDATA_INSERT;
851
76fcb995
VK
852/**
853 * Delayed request for raw_dci_values UPDATE
854 */
855typedef struct
856{
857 time_t timestamp;
858 UINT32 dciId;
859 TCHAR rawValue[MAX_RESULT_LENGTH];
860 TCHAR transformedValue[MAX_RESULT_LENGTH];
861} DELAYED_RAW_DATA_UPDATE;
862
7a4c94ee 863/**
864 * Graph ACL entry
865 */
866struct GRAPH_ACL_ENTRY
867{
868 UINT32 dwGraphId;
869 UINT32 dwUserId;
870 UINT32 dwAccess;
871};
872
873/**
874 * Information about graph with name existence and it's ID.
875 */
876struct GRAPH_ACL_AND_ID
877{
88f2990c 878 UINT32 graphId;
7a4c94ee 879 UINT32 status;
880};
881
9f3db00f
VK
882/**
883 * Thread pool stats
884 */
885enum ThreadPoolStat
886{
887 THREAD_POOL_CURR_SIZE,
888 THREAD_POOL_MIN_SIZE,
889 THREAD_POOL_MAX_SIZE,
890 THREAD_POOL_REQUESTS,
891 THREAD_POOL_LOAD,
892 THREAD_POOL_USAGE,
893 THREAD_POOL_LOADAVG_1,
894 THREAD_POOL_LOADAVG_5,
895 THREAD_POOL_LOADAVG_15
896};
897
234079c4
VK
898/**
899 * Server command execution data
900 */
45ac5dd0 901class ServerCommandExec : public CommandExec
234079c4
VK
902{
903private:
234079c4
VK
904 UINT32 m_requestId;
905 ClientSession *m_session;
906
45ac5dd0
EJ
907 virtual void onOutput(const char *text);
908 virtual void endOfOutput();
234079c4 909
45ac5dd0
EJ
910public:
911 ServerCommandExec(NXCPMessage *msg, ClientSession *session);
912 ~ServerCommandExec();
234079c4
VK
913};
914
0207b7dd
EJ
915/**
916 * SNMP Trap parameter map object
917 */
ed4d6982 918class NXCORE_EXPORTABLE SNMP_TrapParamMap
0207b7dd
EJ
919{
920private:
921 SNMP_ObjectId *m_objectId; // Trap OID
922 UINT32 m_position; // Trap position
923 UINT32 m_flags;
924 TCHAR m_description[MAX_DB_STRING];
925
926public:
927 SNMP_TrapParamMap();
928 SNMP_TrapParamMap(DB_RESULT mapResult, int row);
929 SNMP_TrapParamMap(ConfigEntry *entry);
930 SNMP_TrapParamMap(SNMP_ObjectId *oid, UINT32 flags, TCHAR *description);
931 SNMP_TrapParamMap(NXCPMessage *msg, UINT32 base);
932 ~SNMP_TrapParamMap();
933
ed4d6982 934 void fillMessage(NXCPMessage *msg, UINT32 base) const;
0207b7dd 935
ed4d6982
VK
936 SNMP_ObjectId *getOid() const { return m_objectId; }
937 UINT32 getOidLength() const { return (m_objectId == NULL) ? m_position : (UINT32)m_objectId->length(); }
938 bool isPosition() const { return m_objectId == NULL; }
0207b7dd 939
ed4d6982 940 UINT32 getFlags() const { return m_flags; }
0207b7dd 941
ed4d6982 942 const TCHAR *getDescription() const { return m_description; }
0207b7dd
EJ
943};
944
945/**
946 * SNMP Trap configuration object
947 */
ed4d6982 948class NXCORE_EXPORTABLE SNMP_TrapCfg
0207b7dd
EJ
949{
950private:
951 uuid m_guid; // Trap guid
952 UINT32 m_id; // Entry ID
953 SNMP_ObjectId *m_objectId; // Trap OID
954 UINT32 m_eventCode; // Event code
955 ObjectArray<SNMP_TrapParamMap> *m_pMaps;
956 TCHAR m_description[MAX_DB_STRING];
957 TCHAR m_userTag[MAX_USERTAG_LENGTH];
958
959public:
960 SNMP_TrapCfg();
961 SNMP_TrapCfg(DB_RESULT trapResult, DB_STATEMENT stmt, int row);
962 SNMP_TrapCfg(ConfigEntry *entry, const uuid& guid, UINT32 id, UINT32 eventCode);
963 SNMP_TrapCfg(NXCPMessage *msg);
964 ~SNMP_TrapCfg();
965
ed4d6982
VK
966 void fillMessage(NXCPMessage *msg) const;
967 void fillMessage(NXCPMessage *msg, UINT32 base) const;
0207b7dd
EJ
968 bool saveParameterMapping(DB_HANDLE hdb);
969 void notifyOnTrapCfgChange(UINT32 code);
970
ed4d6982
VK
971 const uuid& getGuid() const { return m_guid; }
972 UINT32 getId() const { return m_id; }
0207b7dd 973
ed4d6982
VK
974 SNMP_ObjectId *getOid() const { return m_objectId; }
975 UINT32 getOidLength() const { return (UINT32)m_objectId->length(); }
0207b7dd
EJ
976
977 SNMP_TrapParamMap *getMap(int index) { return m_pMaps->get(index); }
978 UINT32 getNumMaps() { return m_pMaps->size(); }
979
ed4d6982 980 UINT32 getEventCode() const { return m_eventCode; }
0207b7dd 981
ed4d6982
VK
982 const TCHAR *getDescription() const { return m_description; }
983 const TCHAR *getUserTag() const { return m_userTag; }
0207b7dd
EJ
984};
985
83b1c107
VK
986/**
987 * Watchdog thread state codes
988 */
989enum WatchdogState
990{
991 WATCHDOG_UNKNOWN = -1,
992 WATCHDOG_RUNNING = 0,
993 WATCHDOG_SLEEPING = 1,
994 WATCHDOG_NOT_RESPONDING = 2
995};
996
2bac37f9
VK
997/**
998 * Functions
999 */
35959841 1000bool NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
9bd1bace 1001bool NXCORE_EXPORTABLE ConfigReadStrEx(DB_HANDLE hdb, const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
35f836fe 1002#ifdef UNICODE
35959841 1003bool NXCORE_EXPORTABLE ConfigReadStrA(const WCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
35f836fe
VK
1004#else
1005#define ConfigReadStrA ConfigReadStr
1006#endif
43526096 1007bool NXCORE_EXPORTABLE ConfigReadStrUTF8(const TCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
5039dede 1008int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
9bd1bace 1009int NXCORE_EXPORTABLE ConfigReadIntEx(DB_HANDLE hdb, const TCHAR *szVar, int iDefault);
967893bb 1010UINT32 NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, UINT32 dwDefault);
35959841
VK
1011bool NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray, int nSize, int nDefault);
1012bool NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, bool bCreate, bool isVisible = true, bool needRestart = false);
1013bool NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, bool bCreate, bool isVisible = true, bool needRestart = false);
1014bool NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, UINT32 dwValue, bool bCreate, bool isVisible = true, bool needRestart = false);
1015bool NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray, int nSize, bool bCreate, bool isVisible = true, bool needRestart = false);
5039dede 1016TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
35959841
VK
1017bool NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, bool bCreate);
1018bool NXCORE_EXPORTABLE ConfigDelete(const TCHAR *name);
5039dede 1019
0fdb37c6 1020void MetaDataPreLoad();
35959841 1021bool NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
dba9c498 1022INT32 NXCORE_EXPORTABLE MetaDataReadInt32(const TCHAR *var, INT32 defaultValue);
e9902466 1023bool NXCORE_EXPORTABLE MetaDataWriteStr(const TCHAR *varName, const TCHAR *value);
dba9c498 1024bool NXCORE_EXPORTABLE MetaDataWriteInt32(const TCHAR *name, INT32 value);
28f5b9a4 1025
2df047f4 1026bool NXCORE_EXPORTABLE LoadConfig(int *debugLevel);
5039dede 1027
35f836fe
VK
1028void NXCORE_EXPORTABLE Shutdown();
1029void NXCORE_EXPORTABLE FastShutdown();
1030BOOL NXCORE_EXPORTABLE Initialize();
5039dede 1031THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
35f836fe
VK
1032void NXCORE_EXPORTABLE ShutdownDB();
1033void InitiateShutdown();
5039dede 1034
400e55c4 1035bool NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
5039dede 1036
6e383343
VK
1037void ConsolePrintf(CONSOLE_CTX pCtx, const TCHAR *pszFormat, ...)
1038#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
1039 __attribute__ ((format(printf, 2, 3)))
1040#endif
1041;
532990d2 1042void ConsoleWrite(CONSOLE_CTX pCtx, const TCHAR *text);
35f836fe 1043int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx);
5039dede 1044
83b1c107 1045void SaveObjects(DB_HANDLE hdb, UINT32 watchdogId);
ff6d2c5d
VK
1046void NXCORE_EXPORTABLE ObjectTransactionStart();
1047void NXCORE_EXPORTABLE ObjectTransactionEnd();
5039dede 1048
ce7565e7 1049void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query);
7dad92fb 1050void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query, int bindCount, int *sqlTypes, const TCHAR **values);
967893bb 1051void QueueIDataInsert(time_t timestamp, UINT32 nodeId, UINT32 dciId, const TCHAR *value);
76fcb995 1052void QueueRawDciDataUpdate(time_t timestamp, UINT32 dciId, const TCHAR *rawValue, const TCHAR *transformedValue);
ce7565e7
VK
1053void StartDBWriter();
1054void StopDBWriter();
5039dede 1055
ea50bc33
VK
1056void PerfDataStorageRequest(DCItem *dci, time_t timestamp, const TCHAR *value);
1057void PerfDataStorageRequest(DCTable *dci, time_t timestamp, Table *value);
1058
b368969c 1059void DecodeSQLStringAndSetVariable(NXCPMessage *pMsg, UINT32 dwVarId, TCHAR *pszStr);
5039dede 1060
d0a2ada6 1061SNMP_Transport *SnmpCheckCommSettings(UINT32 snmpProxy, const InetAddress& ipAddr, INT16 *version, UINT16 originalPort, SNMP_SecurityContext *originalContext, StringList *customTestOids);
35f836fe 1062void StrToMac(const TCHAR *pszStr, BYTE *pBuffer);
5039dede 1063
f42b8099 1064void InitLocalNetInfo();
5039dede 1065
f42b8099 1066ARP_CACHE *GetLocalArpCache();
967893bb 1067ARP_CACHE *SnmpGetArpCache(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 1068
98762401 1069InterfaceList *GetLocalInterfaceList();
5039dede 1070
967893bb 1071ROUTING_TABLE *SnmpGetRoutingTable(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 1072
9796ce45 1073void LoadNetworkDeviceDrivers();
21254a93 1074NetworkDeviceDriver *FindDriverForNode(Node *node, SNMP_Transport *pTransport);
28e1575f 1075NetworkDeviceDriver *FindDriverByName(const TCHAR *name);
1f4c37ee 1076void AddDriverSpecificOids(StringList *list);
9796ce45 1077
5ad2167d 1078void CheckForMgmtNode();
de4c3060
VK
1079Node NXCORE_EXPORTABLE *PollNewNode(const InetAddress& ipAddr, UINT32 creationFlags, UINT16 agentPort,
1080 UINT16 snmpPort, const TCHAR *name, UINT32 agentProxyId, UINT32 snmpProxyId,
1081 UINT32 icmpProxyId, UINT32 sshProxyId, const TCHAR *sshLogin, const TCHAR *sshPassword,
1082 Cluster *cluster, UINT32 zoneId, bool doConfPoll, bool discoveredNode);
5039dede 1083
b1e9b6b3 1084void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
967893bb 1085void NXCORE_EXPORTABLE NotifyClientSessions(UINT32 dwCode, UINT32 dwData);
6da535d9 1086void NXCORE_EXPORTABLE NotifyClientSession(UINT32 sessionId, UINT32 dwCode, UINT32 dwData);
32f372a5 1087void NXCORE_EXPORTABLE NotifyClientGraphUpdate(NXCPMessage *update, UINT32 graphId);
64909a13 1088int GetSessionCount(bool includeSystemAccount);
967893bb 1089bool IsLoggedIn(UINT32 dwUserId);
5d9a9c84 1090bool NXCORE_EXPORTABLE KillClientSession(int id);
27858eaa 1091void CloseOtherSessions(UINT32 userId, UINT32 thisSession);
5039dede 1092
35f836fe 1093void GetSysInfoStr(TCHAR *pszBuffer, int nMaxSize);
c30c0c0f 1094InetAddress GetLocalIpAddr();
f7694811 1095TCHAR *GetLocalHostName(TCHAR *buffer, size_t bufSize);
5039dede 1096
b4cf3199
VK
1097InetAddress NXCORE_EXPORTABLE ResolveHostName(UINT32 zoneId, const TCHAR *hostname);
1098
35f836fe 1099BOOL ExecCommand(TCHAR *pszCommand);
967893bb 1100BOOL SendMagicPacket(UINT32 dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
5039dede 1101
35f836fe 1102BOOL InitIdTable();
967893bb 1103UINT32 CreateUniqueId(int iGroup);
35f836fe 1104QWORD CreateUniqueEventId();
69bb7f47 1105void SaveCurrentFreeId();
5039dede 1106
35f836fe
VK
1107void InitMailer();
1108void ShutdownMailer();
f14e669f 1109void NXCORE_EXPORTABLE PostMail(const TCHAR *pszRcpt, const TCHAR *pszSubject, const TCHAR *pszText, bool isHtml = false);
5039dede 1110
35f836fe
VK
1111void InitSMSSender();
1112void ShutdownSMSSender();
1113void NXCORE_EXPORTABLE PostSMS(const TCHAR *pszRcpt, const TCHAR *pszText);
5039dede 1114
35f836fe 1115void InitTraps();
967893bb 1116void SendTrapsToClient(ClientSession *pSession, UINT32 dwRqId);
0207b7dd 1117void CreateTrapCfgMessage(NXCPMessage *msg);
967893bb 1118UINT32 CreateNewTrap(UINT32 *pdwTrapId);
b368969c 1119UINT32 UpdateTrapFromMsg(NXCPMessage *pMsg);
967893bb 1120UINT32 DeleteTrap(UINT32 dwId);
25a1e9d0 1121void CreateTrapExportRecord(String &xml, UINT32 id);
0207b7dd
EJ
1122UINT32 ResolveTrapGuid(const uuid& guid);
1123void AddTrapCfgToList(SNMP_TrapCfg *trapCfg);
967893bb
VK
1124
1125BOOL IsTableTool(UINT32 dwToolId);
1126BOOL CheckObjectToolAccess(UINT32 dwToolId, UINT32 dwUserId);
1127UINT32 ExecuteTableTool(UINT32 dwToolId, Node *pNode, UINT32 dwRqId, ClientSession *pSession);
1128UINT32 DeleteObjectToolFromDB(UINT32 dwToolId);
6f8e39e5 1129UINT32 ChangeObjectToolStatus(UINT32 toolId, bool enabled);
b368969c 1130UINT32 UpdateObjectToolFromMessage(NXCPMessage *pMsg);
4c3cc965 1131void CreateObjectToolExportRecord(String &xml, UINT32 id);
271e3971 1132bool ImportObjectTool(ConfigEntry *config);
b576249a
VK
1133UINT32 GetObjectToolsIntoMessage(NXCPMessage *msg, UINT32 userId, bool fullAccess);
1134UINT32 GetObjectToolDetailsIntoMessage(UINT32 toolId, NXCPMessage *msg);
967893bb 1135
b368969c 1136UINT32 ModifySummaryTable(NXCPMessage *msg, LONG *newId);
967893bb 1137UINT32 DeleteSummaryTable(LONG tableId);
5389f7b0 1138Table *QuerySummaryTable(LONG tableId, SummaryTable *adHocDefinition, UINT32 baseObjectId, UINT32 userId, UINT32 *rcc);
2096c8f0 1139bool CreateSummaryTableExportRecord(INT32 id, String &xml);
c7a9d87c 1140bool ImportSummaryTable(ConfigEntry *config);
b4c2a628 1141
b368969c 1142void CreateMessageFromSyslogMsg(NXCPMessage *pMsg, NX_SYSLOG_RECORD *pRec);
4262c0dc 1143void ReinitializeSyslogParser();
b8c8a8a7 1144void OnSyslogConfigurationChange(const TCHAR *name, const TCHAR *value);
5039dede
AK
1145
1146void EscapeString(String &str);
1147
ce7565e7 1148void InitAuditLog();
badd6e08 1149void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, bool isSuccess, UINT32 userId,
2a964810 1150 const TCHAR *workstation, int sessionId, UINT32 objectId,
ce7565e7 1151 const TCHAR *format, ...);
badd6e08
VK
1152void NXCORE_EXPORTABLE WriteAuditLog2(const TCHAR *subsys, bool isSuccess, UINT32 userId,
1153 const TCHAR *workstation, int sessionId, UINT32 objectId,
1154 const TCHAR *format, va_list args);
88f2990c 1155
967893bb
VK
1156bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTextLen);
1157UINT32 ImportConfig(Config *config, UINT32 flags);
5039dede
AK
1158
1159#ifdef _WITH_ENCRYPTION
b368969c 1160X509 *CertificateFromLoginMessage(NXCPMessage *pMsg);
a50eaebe 1161BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
967893bb 1162 BYTE *pSignature, UINT32 dwSigLen, int nMappingMethod,
a50eaebe 1163 const TCHAR *pszMappingData);
9796ce45 1164void ReloadCertificates();
5039dede
AK
1165#endif
1166
1167#ifndef _WIN32
1168THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
1169#endif /* not _WIN32 */
1170
5d3459af
VK
1171void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX console);
1172void DumpClientSessions(CONSOLE_CTX console);
1173void DumpMobileDeviceSessions(CONSOLE_CTX console);
5d3459af
VK
1174void ShowServerStats(CONSOLE_CTX console);
1175void ShowQueueStats(CONSOLE_CTX console, Queue *pQueue, const TCHAR *pszName);
1176void ShowThreadPool(CONSOLE_CTX console, ThreadPool *p);
9f3db00f 1177LONG GetThreadPoolStat(ThreadPoolStat stat, const TCHAR *param, TCHAR *value);
5d3459af 1178void DumpProcess(CONSOLE_CTX console);
5039dede 1179
aed41472 1180#define GRAPH_FLAG_TEMPLATE 1
1181
bd360fd5 1182GRAPH_ACL_ENTRY *LoadGraphACL(DB_HANDLE hdb, UINT32 graphId, int *pnACLSize);
48abffaa 1183GRAPH_ACL_ENTRY *LoadAllGraphACL(DB_HANDLE hdb, int *pnACLSize);
9ad921e5 1184BOOL CheckGraphAccess(GRAPH_ACL_ENTRY *pACL, int nACLSize, UINT32 graphId, UINT32 graphUserId, UINT32 graphDesiredAccess);
fff23fae 1185UINT32 GetGraphAccessCheckResult(UINT32 graphId, UINT32 graphUserId);
9ad921e5 1186GRAPH_ACL_AND_ID IsGraphNameExists(const TCHAR *graphName);
aed41472 1187void FillGraphListMsg(NXCPMessage *msg, UINT32 userId, bool templageGraphs);
1188void SaveGraph(NXCPMessage *pRequest, UINT32 userId, NXCPMessage *msg);
1189UINT32 DeleteGraph(UINT32 graphId, UINT32 userId);
7a4c94ee 1190
d00ad4c6 1191#if XMPP_SUPPORTED
098ef635 1192void SendXMPPMessage(const TCHAR *rcpt, const TCHAR *text);
d00ad4c6 1193#endif
244c65ef 1194
0de31ec3
VK
1195const TCHAR NXCORE_EXPORTABLE *CountryAlphaCode(const TCHAR *code);
1196const TCHAR NXCORE_EXPORTABLE *CountryName(const TCHAR *code);
1197const TCHAR NXCORE_EXPORTABLE *CurrencyAlphaCode(const TCHAR *numericCode);
1198int NXCORE_EXPORTABLE CurrencyExponent(const TCHAR *code);
1199const TCHAR NXCORE_EXPORTABLE *CurrencyName(const TCHAR *code);
1200
4fd0b7ca
VK
1201void NXCORE_EXPORTABLE RegisterComponent(const TCHAR *id);
1202bool NXCORE_EXPORTABLE IsComponentRegistered(const TCHAR *id);
1203
83b1c107
VK
1204/**
1205 * Watchdog API
1206 */
1207void WatchdogInit();
1208void WatchdogShutdown();
1209UINT32 WatchdogAddThread(const TCHAR *name, time_t notifyInterval);
1210void WatchdogNotify(UINT32 id);
1211void WatchdogStartSleep(UINT32 id);
1212void WatchdogPrintStatus(CONSOLE_CTX console);
1213WatchdogState WatchdogGetState(const TCHAR *name);
1214void WatchdogGetThreads(StringList *out);
1215
01090206
VK
1216/**
1217 * Housekeeper control
1218 */
1219void StartHouseKeeper();
1220void StopHouseKeeper();
1221void RunHouseKeeper();
1222
a881eafa
VK
1223/**
1224 * Alarm category functions
1225 */
1226void GetAlarmCategories(NXCPMessage *msg);
f5050daf 1227UINT32 UpdateAlarmCategory(const NXCPMessage *request, UINT32 *returnId);
a881eafa 1228UINT32 DeleteAlarmCategory(UINT32 id);
e30c2442
VK
1229bool CheckAlarmCategoryAccess(UINT32 userId, UINT32 categoryId);
1230void LoadAlarmCategories();
a881eafa 1231
f14e669f
EJ
1232/**
1233 * Alarm summary emails
1234 */
1235void SendAlarmSummaryEmail(const ScheduledTaskParameters *params);
1236void EnableAlarmSummaryEmails();
1237
0207b7dd
EJ
1238/**
1239 * NXSL script functions
1240 */
1241UINT32 UpdateScript(const NXCPMessage *request, UINT32 *scriptId);
1242UINT32 RenameScript(const NXCPMessage *request);
1243UINT32 DeleteScript(const NXCPMessage *request);
1244
9fa031cd 1245/**
1246 * File monitoring
1247 */
1248struct MONITORED_FILE
1249{
1250 TCHAR fileName[MAX_PATH];
1251 ClientSession *session;
1252 UINT32 nodeID;
1253};
1254
1255class FileMonitoringList
1256{
1257private:
1258 MUTEX m_mutex;
1259 ObjectArray<MONITORED_FILE> m_monitoredFiles;
9fa031cd 1260
1261public:
1262 FileMonitoringList();
1263 ~FileMonitoringList();
e13420c1 1264 void addMonitoringFile(MONITORED_FILE *fileForAdd, Node *obj, AgentConnection *conn);
e2338033 1265 bool checkDuplicate(MONITORED_FILE *fileForAdd);
1266 ObjectArray<ClientSession>* findClientByFNameAndNodeID(const TCHAR *fileName, UINT32 nodeID);
9fa031cd 1267 bool removeMonitoringFile(MONITORED_FILE *fileForRemove);
f9f79a93 1268 void removeDisconnectedNode(UINT32 nodeId);
9fa031cd 1269
1270private:
1271 void lock();
1272 void unlock();
1273};
1274
534e1b83
VK
1275/**
1276 * Global variables
1277 */
5039dede
AK
1278extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
1279extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
458b5d2b
VK
1280extern UINT32 g_logRotationMode;
1281extern UINT64 g_maxLogSize;
1282extern UINT32 g_logHistorySize;
4f8998ca 1283extern TCHAR g_szDailyLogFileSuffix[64];
5039dede
AK
1284extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
1285extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
1286#ifndef _WIN32
1287extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
1288#endif
db6a6b45
VK
1289extern TCHAR NXCORE_EXPORTABLE g_netxmsdDataDir[];
1290extern TCHAR NXCORE_EXPORTABLE g_netxmsdLibDir[];
967893bb 1291extern UINT32 NXCORE_EXPORTABLE g_processAffinityMask;
e9902466 1292extern UINT64 g_serverId;
5039dede 1293extern RSA *g_pServerKey;
c59466d2
VK
1294extern UINT32 g_icmpPingSize;
1295extern UINT32 g_icmpPingTimeout;
1296extern UINT32 g_auditFlags;
1297extern time_t g_serverStartTime;
1298extern UINT32 g_lockTimeout;
1299extern UINT32 g_agentCommandTimeout;
1300extern UINT32 g_thresholdRepeatInterval;
1301extern int g_requiredPolls;
1302extern UINT32 g_slmPollingInterval;
f6456d80 1303extern UINT32 g_offlineDataRelevanceTime;
5039dede 1304
b8c1ec69
VK
1305extern TCHAR g_szDbDriver[];
1306extern TCHAR g_szDbDrvParams[];
1307extern TCHAR g_szDbServer[];
1308extern TCHAR g_szDbLogin[];
1309extern TCHAR g_szDbPassword[];
1310extern TCHAR g_szDbName[];
f3c30cf5 1311extern TCHAR g_szDbSchema[];
b8c1ec69 1312extern DB_DRIVER g_dbDriver;
76fcb995
VK
1313extern Queue *g_dbWriterQueue;
1314extern Queue *g_dciDataWriterQueue;
1315extern Queue *g_dciRawDataWriterQueue;
6547a540
VK
1316extern UINT64 g_idataWriteRequests;
1317extern UINT64 g_rawDataWriteRequests;
1318extern UINT64 g_otherWriteRequests;
5039dede 1319
2a964810 1320extern int NXCORE_EXPORTABLE g_dbSyntax;
9fa031cd 1321extern FileMonitoringList g_monitoringList;
5039dede 1322
1ef6170e 1323extern ThreadPool NXCORE_EXPORTABLE *g_mainThreadPool;
5d3459af 1324
5039dede 1325#endif /* _nms_core_h_ */