all pollers converted to single thread pool
[public/netxms.git] / src / server / include / nms_core.h
CommitLineData
88f2990c 1/*
5039dede 2** NetXMS - Network Management System
7806c906 3** Copyright (C) 2003-2014 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>
d41edbd3 79#include <nxcore_smclp.h>
5039dede 80
46ee6286
VK
81/**
82 * Console context
83 */
5039dede
AK
84struct __console_ctx
85{
86 SOCKET hSocket;
d3a7cf4c 87 MUTEX socketMutex;
b368969c 88 NXCPMessage *pMsg;
200d662d 89 ClientSession *session;
244c65ef 90 String *output;
5039dede
AK
91};
92
93typedef __console_ctx * CONSOLE_CTX;
94
2bac37f9
VK
95/**
96 * Server includes
97 */
7806c906 98#include "server_timers.h"
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"
5039dede 107#include "nxcore_situations.h"
ab621f39 108#include "nxcore_jobs.h"
e05b1945 109#include "nxcore_logs.h"
5039dede 110
2bac37f9
VK
111/**
112 * Common constants and macros
113 */
73869331 114#define MAX_LINE_SIZE 4096
967893bb 115#define GROUP_FLAG_BIT ((UINT32)0x80000000)
73869331
VK
116#define CHECKPOINT_SNMP_PORT 260
117#define DEFAULT_AFFINITY_MASK 0xFFFFFFFF
5039dede 118
2a964810
VK
119#define MAX_CLIENT_SESSIONS 128
120#define MAX_DEVICE_SESSIONS 256
121
ebb2dc70
VK
122#define PING_TIME_TIMEOUT 10000
123
5039dede
AK
124typedef void * HSNMPSESSION;
125
0f506caa
VK
126/**
127 * Prefixes for poller messages
128 */
df8a4ca2
VK
129#define POLLER_ERROR _T("\x7F") _T("e")
130#define POLLER_WARNING _T("\x7Fw")
131#define POLLER_INFO _T("\x7Fi")
132
0f506caa
VK
133/**
134 * Unique identifier group codes
135 */
5039dede
AK
136#define IDG_NETWORK_OBJECT 0
137#define IDG_CONTAINER_CAT 1
138#define IDG_EVENT 2
139#define IDG_ITEM 3
140#define IDG_SNMP_TRAP 4
24dc5346 141#define IDG_JOB 5
5039dede
AK
142#define IDG_ACTION 6
143#define IDG_EVENT_GROUP 7
144#define IDG_THRESHOLD 8
145#define IDG_USER 9
146#define IDG_USER_GROUP 10
147#define IDG_ALARM 11
148#define IDG_ALARM_NOTE 12
149#define IDG_PACKAGE 13
636e0c72 150#define IDG_SLM_TICKET 14
5039dede
AK
151#define IDG_OBJECT_TOOL 15
152#define IDG_SCRIPT 16
153#define IDG_AGENT_CONFIG 17
154#define IDG_GRAPH 18
155#define IDG_CERTIFICATE 19
156#define IDG_SITUATION 20
ba89fed2 157#define IDG_DCT_COLUMN 21
0f506caa 158#define IDG_MAPPING_TABLE 22
b4c2a628 159#define IDG_DCI_SUMMARY_TABLE 23
5039dede 160
0f506caa
VK
161/**
162 * Exit codes for console commands
163 */
5039dede
AK
164#define CMD_EXIT_CONTINUE 0
165#define CMD_EXIT_CLOSE_SESSION 1
166#define CMD_EXIT_SHUTDOWN 2
167
0f506caa
VK
168/**
169 * Network discovery mode
170 */
5039dede
AK
171#define DISCOVERY_DISABLED 0
172#define DISCOVERY_PASSIVE_ONLY 1
173#define DISCOVERY_ACTIVE 2
174
0f506caa
VK
175/**
176 * Client session flags
177 */
134c3d00 178#define CSF_TERMINATED ((UINT32)0x00000001)
850ce3ed
VK
179#define CSF_EPP_LOCKED ((UINT32)0x00000002)
180#define CSF_PACKAGE_DB_LOCKED ((UINT32)0x00000004)
181#define CSF_USER_DB_LOCKED ((UINT32)0x00000008)
182#define CSF_EPP_UPLOAD ((UINT32)0x00000010)
183#define CSF_CONSOLE_OPEN ((UINT32)0x00000020)
184#define CSF_AUTHENTICATED ((UINT32)0x00000080)
185#define CSF_RECEIVING_MAP_DATA ((UINT32)0x00000200)
186#define CSF_SYNC_OBJECT_COMMENTS ((UINT32)0x00000400)
678fe569
VK
187#define CSF_CUSTOM_LOCK_1 ((UINT32)0x01000000)
188#define CSF_CUSTOM_LOCK_2 ((UINT32)0x02000000)
189#define CSF_CUSTOM_LOCK_3 ((UINT32)0x04000000)
190#define CSF_CUSTOM_LOCK_4 ((UINT32)0x08000000)
191#define CSF_CUSTOM_LOCK_5 ((UINT32)0x10000000)
192#define CSF_CUSTOM_LOCK_6 ((UINT32)0x20000000)
193#define CSF_CUSTOM_LOCK_7 ((UINT32)0x40000000)
194#define CSF_CUSTOM_LOCK_8 ((UINT32)0x80000000)
5039dede 195
0f506caa
VK
196/**
197 * Client session states
198 */
5039dede
AK
199#define SESSION_STATE_INIT 0
200#define SESSION_STATE_IDLE 1
201#define SESSION_STATE_PROCESSING 2
202
0f506caa
VK
203/**
204 * Information categories for UPDATE_INFO structure
205 */
5039dede
AK
206#define INFO_CAT_EVENT 1
207#define INFO_CAT_OBJECT_CHANGE 2
208#define INFO_CAT_ALARM 3
209#define INFO_CAT_ACTION 4
210#define INFO_CAT_SYSLOG_MSG 5
211#define INFO_CAT_SNMP_TRAP 6
212#define INFO_CAT_AUDIT_RECORD 7
213#define INFO_CAT_SITUATION 8
624f1165 214#define INFO_CAT_LIBRARY_IMAGE 9
5039dede 215
0f506caa
VK
216/**
217 * Certificate types
218 */
5039dede
AK
219#define CERT_TYPE_TRUSTED_CA 0
220#define CERT_TYPE_USER 1
221
0f506caa
VK
222/**
223 * Audit subsystems
224 */
5039dede
AK
225#define AUDIT_SECURITY _T("SECURITY")
226#define AUDIT_OBJECTS _T("OBJECTS")
227#define AUDIT_SYSCFG _T("SYSCFG")
228#define AUDIT_CONSOLE _T("CONSOLE")
229
2a964810
VK
230#define AUDIT_SYSTEM_SID (-1)
231
0f506caa
VK
232/**
233 * Event handling subsystem definitions
234 */
5039dede
AK
235#include "nms_events.h"
236#include "nms_actions.h"
237#include "nms_alarm.h"
238
0f506caa
VK
239/**
240 * New node information
241 */
5039dede
AK
242typedef struct
243{
c75e9ee4 244 InetAddress ipAddr;
967893bb 245 UINT32 zoneId;
5039dede 246 BOOL ignoreFilter;
baa5324c 247 BYTE bMacAddr[MAC_ADDR_LENGTH];
5039dede
AK
248} NEW_NODE;
249
0f506caa
VK
250/**
251 * New node flags
252 */
5039dede
AK
253#define NNF_IS_SNMP 0x0001
254#define NNF_IS_AGENT 0x0002
255#define NNF_IS_ROUTER 0x0004
256#define NNF_IS_BRIDGE 0x0008
257#define NNF_IS_PRINTER 0x0010
258#define NNF_IS_CDP 0x0020
259#define NNF_IS_SONMP 0x0040
260#define NNF_IS_LLDP 0x0080
261
0f506caa
VK
262/**
263 * Node information for autodiscovery filter
264 */
5039dede
AK
265typedef struct
266{
c75e9ee4 267 InetAddress ipAddr;
967893bb 268 UINT32 dwFlags;
5039dede 269 int nSNMPVersion;
35f836fe
VK
270 TCHAR szObjectId[MAX_OID_LEN * 4]; // SNMP OID
271 TCHAR szAgentVersion[MAX_AGENT_VERSION_LEN];
272 TCHAR szPlatform[MAX_PLATFORM_NAME_LEN];
5039dede
AK
273} DISCOVERY_FILTER_DATA;
274
0f506caa
VK
275/**
276 * Data update structure for client sessions
277 */
5039dede
AK
278typedef struct
279{
967893bb
VK
280 UINT32 dwCategory; // Data category - event, network object, etc.
281 UINT32 dwCode; // Data-specific update code
5039dede
AK
282 void *pData; // Pointer to data block
283} UPDATE_INFO;
284
534e1b83
VK
285/**
286 * Extended agent connection
287 */
5039dede
AK
288class AgentConnectionEx : public AgentConnection
289{
290protected:
967893bb 291 UINT32 m_nodeId;
d1c1c522 292
af21affe 293 virtual void printMsg(const TCHAR *format, ...);
b368969c
VK
294 virtual void onTrap(NXCPMessage *msg);
295 virtual void onDataPush(NXCPMessage *msg);
296 virtual void onFileMonitoringData(NXCPMessage *msg);
297 virtual void onSnmpTrap(NXCPMessage *pMsg);
02d936bd 298 virtual UINT32 processCollectedData(NXCPMessage *msg);
e9902466 299 virtual bool processCustomMessage(NXCPMessage *msg);
5039dede
AK
300
301public:
c11eee9b 302 AgentConnectionEx(UINT32 nodeId, InetAddress ipAddr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL) :
69c6604d 303 AgentConnection(ipAddr, port, authMethod, secret) { m_nodeId = nodeId; }
5039dede 304 virtual ~AgentConnectionEx();
45d84f8a 305
967893bb
VK
306 UINT32 deployPolicy(AgentPolicy *policy);
307 UINT32 uninstallPolicy(AgentPolicy *policy);
5039dede
AK
308};
309
534e1b83
VK
310/**
311 * Mobile device session
312 */
313class NXCORE_EXPORTABLE MobileDeviceSession
314{
315private:
316 SOCKET m_hSocket;
317 Queue *m_pSendQueue;
318 Queue *m_pMessageQueue;
2a964810
VK
319 int m_id;
320 int m_state;
534e1b83 321 WORD m_wCurrentCmd;
967893bb
VK
322 UINT32 m_dwUserId;
323 UINT32 m_deviceObjectId;
b368969c 324 NXCP_BUFFER *m_pMsgBuffer;
534e1b83
VK
325 NXCPEncryptionContext *m_pCtx;
326 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
327 THREAD m_hWriteThread;
328 THREAD m_hProcessingThread;
329 MUTEX m_mutexSocketWrite;
330 struct sockaddr *m_clientAddr;
331 TCHAR m_szHostName[256]; // IP address of name of conneced host in textual form
332 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
333 TCHAR m_szClientInfo[96]; // Client app info string
967893bb
VK
334 UINT32 m_dwEncryptionRqId;
335 UINT32 m_dwEncryptionResult;
534e1b83 336 CONDITION m_condEncryptionSetup;
967893bb 337 UINT32 m_dwRefCount;
534e1b83
VK
338 bool m_isAuthenticated;
339
340 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
341 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
342 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
5039dede 343
534e1b83
VK
344 void readThread();
345 void writeThread();
346 void processingThread();
347
b368969c 348 void setupEncryption(NXCPMessage *request);
967893bb 349 void respondToKeepalive(UINT32 dwRqId);
534e1b83 350 void debugPrintf(int level, const TCHAR *format, ...);
967893bb 351 void sendServerInfo(UINT32 dwRqId);
b368969c
VK
352 void login(NXCPMessage *pRequest);
353 void updateDeviceInfo(NXCPMessage *pRequest);
354 void updateDeviceStatus(NXCPMessage *pRequest);
355 void pushData(NXCPMessage *request);
534e1b83
VK
356
357public:
358 MobileDeviceSession(SOCKET hSocket, struct sockaddr *addr);
359 ~MobileDeviceSession();
360
534e1b83
VK
361 void run();
362
19dbc8ef 363 void postMessage(NXCPMessage *pMsg) { m_pSendQueue->put(pMsg->createMessage()); }
b368969c 364 void sendMessage(NXCPMessage *pMsg);
5039dede 365
2a964810
VK
366 int getId() { return m_id; }
367 void setId(int id) { if (m_id == -1) m_id = id; }
368 int getState() { return m_state; }
534e1b83
VK
369 const TCHAR *getUserName() { return m_szUserName; }
370 const TCHAR *getClientInfo() { return m_szClientInfo; }
371 const TCHAR *getHostName() { return m_szHostName; }
967893bb 372 UINT32 getUserId() { return m_dwUserId; }
534e1b83
VK
373 bool isAuthenticated() { return m_isAuthenticated; }
374 WORD getCurrentCmd() { return m_wCurrentCmd; }
375 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
376};
377
378/**
379 * Client (user) session
380 */
134c3d00 381#define DECLARE_THREAD_STARTER(func) static void ThreadStarter_##func(void *);
5039dede 382
a0e3917e 383class NXCORE_EXPORTABLE ClientSession
5039dede
AK
384{
385private:
386 SOCKET m_hSocket;
387 Queue *m_pSendQueue;
388 Queue *m_pMessageQueue;
389 Queue *m_pUpdateQueue;
2a964810
VK
390 int m_id;
391 int m_state;
5039dede 392 WORD m_wCurrentCmd;
967893bb 393 UINT32 m_dwUserId;
f4d8fe18 394 UINT64 m_dwSystemAccess; // User's system access rights
967893bb 395 UINT32 m_dwFlags; // Session flags
f8c6f10f 396 int m_clientType; // Client system type - desktop, web, mobile, etc.
b368969c 397 NXCP_BUFFER *m_pMsgBuffer;
98abc9f1 398 NXCPEncryptionContext *m_pCtx;
5039dede
AK
399 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
400 THREAD m_hWriteThread;
401 THREAD m_hProcessingThread;
402 THREAD m_hUpdateThread;
d3a7cf4c 403 MUTEX m_mutexSocketWrite;
5039dede
AK
404 MUTEX m_mutexSendEvents;
405 MUTEX m_mutexSendSyslog;
406 MUTEX m_mutexSendTrapLog;
407 MUTEX m_mutexSendObjects;
408 MUTEX m_mutexSendAlarms;
409 MUTEX m_mutexSendActions;
410 MUTEX m_mutexSendAuditLog;
411 MUTEX m_mutexSendSituations;
412 MUTEX m_mutexPollerInit;
60557d06 413 struct sockaddr *m_clientAddr;
91f6b72c
VK
414 TCHAR m_workstation[256]; // IP address or name of connected host in textual form
415 TCHAR m_webServerAddress[256]; // IP address or name of web server for web sessions
5039dede
AK
416 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
417 TCHAR m_szClientInfo[96]; // Client app info string
2a964810 418 TCHAR m_language[8]; // Client's desired language
a51628e2 419 time_t m_loginTime;
967893bb
VK
420 UINT32 m_dwOpenDCIListSize; // Number of open DCI lists
421 UINT32 *m_pOpenDCIList; // List of nodes with DCI lists open
422 UINT32 m_dwNumRecordsToUpload; // Number of records to be uploaded
423 UINT32 m_dwRecordsUploaded;
5039dede
AK
424 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
425 int m_hCurrFile;
967893bb
VK
426 UINT32 m_dwFileRqId;
427 UINT32 m_dwUploadCommand;
428 UINT32 m_dwUploadData;
e928a6db 429 uuid_t m_uploadImageGuid;
5039dede 430 TCHAR m_szCurrFileName[MAX_PATH];
967893bb
VK
431 UINT32 m_dwRefCount;
432 UINT32 m_dwEncryptionRqId;
433 UINT32 m_dwEncryptionResult;
5039dede 434 CONDITION m_condEncryptionSetup;
967893bb 435 UINT32 m_dwActiveChannels; // Active data channels
200d662d 436 CONSOLE_CTX m_console; // Server console context
810bd8c4 437 StringList m_musicTypeList;
7cf549ad 438 ObjectIndex m_agentConn;
5039dede 439
534e1b83
VK
440 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
441 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
442 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
443 static THREAD_RESULT THREAD_CALL updateThreadStarter(void *);
134c3d00 444 static void pollerThreadStarter(void *);
5039dede 445
92c51b1d
VK
446 DECLARE_THREAD_STARTER(getCollectedData)
447 DECLARE_THREAD_STARTER(getTableCollectedData)
448 DECLARE_THREAD_STARTER(clearDCIData)
79633a65 449 DECLARE_THREAD_STARTER(forceDCIPoll)
adac28be
VK
450 DECLARE_THREAD_STARTER(queryParameter)
451 DECLARE_THREAD_STARTER(queryAgentTable)
84880c89 452 DECLARE_THREAD_STARTER(queryL2Topology)
b1e9b6b3
VK
453 DECLARE_THREAD_STARTER(sendEventLog)
454 DECLARE_THREAD_STARTER(sendSyslog)
1da08bc6
VK
455 DECLARE_THREAD_STARTER(createObject)
456 DECLARE_THREAD_STARTER(getServerFile)
6f16f12d 457 DECLARE_THREAD_STARTER(getAgentFile)
9fa031cd 458 DECLARE_THREAD_STARTER(cancelFileMonitoring)
e05b1945
VK
459 DECLARE_THREAD_STARTER(queryServerLog)
460 DECLARE_THREAD_STARTER(getServerLogQueryData)
e31c8e60 461 DECLARE_THREAD_STARTER(executeAction)
630e15d6 462 DECLARE_THREAD_STARTER(findNodeConnection)
06a93345 463 DECLARE_THREAD_STARTER(findMacAddress)
80e0db05 464 DECLARE_THREAD_STARTER(findIpAddress)
200d662d 465 DECLARE_THREAD_STARTER(processConsoleCommand)
b08d31f4 466 DECLARE_THREAD_STARTER(sendMib)
6d069676 467 DECLARE_THREAD_STARTER(getNetworkPath)
2bac37f9 468 DECLARE_THREAD_STARTER(getAlarmEvents)
3c35018e 469 DECLARE_THREAD_STARTER(openHelpdeskIssue)
d75003e1 470 DECLARE_THREAD_STARTER(forwardToReportingServer)
74d0b136 471 DECLARE_THREAD_STARTER(fileManagerControl)
7cf549ad 472 DECLARE_THREAD_STARTER(uploadUserFileToAgent)
c44cf458
VK
473 DECLARE_THREAD_STARTER(getSwitchForwardingDatabase)
474 DECLARE_THREAD_STARTER(getRoutingTable)
4899db4d 475 DECLARE_THREAD_STARTER(getLocationHistory)
529956a0 476 DECLARE_THREAD_STARTER(executeScript)
5039dede 477
62768df3
VK
478 void readThread();
479 void writeThread();
480 void processingThread();
481 void updateThread();
967893bb 482 void pollerThread(Node *pNode, int iPollType, UINT32 dwRqId);
5039dede 483
b368969c 484 void setupEncryption(NXCPMessage *request);
967893bb 485 void respondToKeepalive(UINT32 dwRqId);
e05b1945 486 void onFileUpload(BOOL bSuccess);
534e1b83 487 void debugPrintf(int level, const TCHAR *format, ...);
967893bb 488 void sendServerInfo(UINT32 dwRqId);
b368969c
VK
489 void login(NXCPMessage *pRequest);
490 void sendAllObjects(NXCPMessage *pRequest);
491 void sendSelectedObjects(NXCPMessage *pRequest);
492 void sendEventLog(NXCPMessage *pRequest);
967893bb 493 void sendAllConfigVars(UINT32 dwRqId);
b368969c
VK
494 void setConfigVariable(NXCPMessage *pRequest);
495 void deleteConfigVariable(NXCPMessage *pRequest);
967893bb
VK
496 void sendUserDB(UINT32 dwRqId);
497 void sendAllAlarms(UINT32 dwRqId);
b368969c
VK
498 void createUser(NXCPMessage *pRequest);
499 void updateUser(NXCPMessage *pRequest);
500 void deleteUser(NXCPMessage *pRequest);
501 void setPassword(NXCPMessage *pRequest);
967893bb
VK
502 void lockUserDB(UINT32 dwRqId, BOOL bLock);
503 void sendEventDB(UINT32 dwRqId);
b368969c
VK
504 void modifyEventTemplate(NXCPMessage *pRequest);
505 void deleteEventTemplate(NXCPMessage *pRequest);
967893bb 506 void generateEventCode(UINT32 dwRqId);
b368969c
VK
507 void modifyObject(NXCPMessage *pRequest);
508 void changeObjectMgmtStatus(NXCPMessage *pRequest);
509 void openNodeDCIList(NXCPMessage *pRequest);
510 void closeNodeDCIList(NXCPMessage *pRequest);
511 void modifyNodeDCI(NXCPMessage *pRequest);
512 void copyDCI(NXCPMessage *pRequest);
513 void applyTemplate(NXCPMessage *pRequest);
514 void getCollectedData(NXCPMessage *pRequest);
515 void getTableCollectedData(NXCPMessage *pRequest);
516 bool getCollectedDataFromDB(NXCPMessage *request, NXCPMessage *response, DataCollectionTarget *object, int dciType);
517 void clearDCIData(NXCPMessage *pRequest);
79633a65 518 void forceDCIPoll(NXCPMessage *pRequest);
b368969c
VK
519 void changeDCIStatus(NXCPMessage *pRequest);
520 void getLastValues(NXCPMessage *pRequest);
521 void getLastValuesByDciId(NXCPMessage *pRequest);
522 void getTableLastValues(NXCPMessage *pRequest);
523 void getThresholdSummary(NXCPMessage *request);
524 void openEPP(NXCPMessage *request);
967893bb 525 void closeEPP(UINT32 dwRqId);
b368969c
VK
526 void saveEPP(NXCPMessage *pRequest);
527 void processEPPRecord(NXCPMessage *pRequest);
967893bb 528 void sendMIBTimestamp(UINT32 dwRqId);
b368969c
VK
529 void sendMib(NXCPMessage *request);
530 void createObject(NXCPMessage *request);
531 void changeObjectBinding(NXCPMessage *request, BOOL bBind);
532 void deleteObject(NXCPMessage *request);
533 void getAlarm(NXCPMessage *request);
534 void getAlarmEvents(NXCPMessage *request);
535 void acknowledgeAlarm(NXCPMessage *request);
536 void resolveAlarm(NXCPMessage *request, bool terminate);
537 void deleteAlarm(NXCPMessage *request);
538 void openHelpdeskIssue(NXCPMessage *request);
539 void getHelpdeskUrl(NXCPMessage *request);
540 void unlinkHelpdeskIssue(NXCPMessage *request);
541 void getAlarmComments(NXCPMessage *pRequest);
542 void updateAlarmComment(NXCPMessage *pRequest);
543 void deleteAlarmComment(NXCPMessage *request);
544 void updateAlarmStatusFlow(NXCPMessage *request);
545 void createAction(NXCPMessage *pRequest);
546 void updateAction(NXCPMessage *pRequest);
547 void deleteAction(NXCPMessage *pRequest);
967893bb
VK
548 void sendAllActions(UINT32 dwRqId);
549 void SendContainerCategories(UINT32 dwRqId);
b368969c
VK
550 void forcedNodePoll(NXCPMessage *pRequest);
551 void onTrap(NXCPMessage *pRequest);
552 void onWakeUpNode(NXCPMessage *pRequest);
553 void queryParameter(NXCPMessage *pRequest);
554 void queryAgentTable(NXCPMessage *pRequest);
555 void editTrap(int iOperation, NXCPMessage *pRequest);
967893bb
VK
556 void LockTrapCfg(UINT32 dwRqId, BOOL bLock);
557 void sendAllTraps(UINT32 dwRqId);
558 void sendAllTraps2(UINT32 dwRqId);
559 void LockPackageDB(UINT32 dwRqId, BOOL bLock);
560 void SendAllPackages(UINT32 dwRqId);
b368969c
VK
561 void InstallPackage(NXCPMessage *pRequest);
562 void RemovePackage(NXCPMessage *pRequest);
563 void DeployPackage(NXCPMessage *pRequest);
564 void getParametersList(NXCPMessage *pRequest);
565 void getUserVariable(NXCPMessage *pRequest);
566 void setUserVariable(NXCPMessage *pRequest);
567 void copyUserVariable(NXCPMessage *pRequest);
568 void enumUserVariables(NXCPMessage *pRequest);
569 void deleteUserVariable(NXCPMessage *pRequest);
570 void changeObjectZone(NXCPMessage *pRequest);
571 void getAgentConfig(NXCPMessage *pRequest);
572 void updateAgentConfig(NXCPMessage *pRequest);
573 void executeAction(NXCPMessage *pRequest);
967893bb 574 void sendObjectTools(UINT32 dwRqId);
b368969c
VK
575 void sendObjectToolDetails(NXCPMessage *pRequest);
576 void updateObjectTool(NXCPMessage *pRequest);
577 void deleteObjectTool(NXCPMessage *pRequest);
578 void changeObjectToolStatus(NXCPMessage *pRequest);
967893bb 579 void generateObjectToolId(UINT32 dwRqId);
b368969c
VK
580 void execTableTool(NXCPMessage *pRequest);
581 void changeSubscription(NXCPMessage *pRequest);
582 void sendSyslog(NXCPMessage *pRequest);
967893bb
VK
583 void sendServerStats(UINT32 dwRqId);
584 void sendScriptList(UINT32 dwRqId);
b368969c
VK
585 void sendScript(NXCPMessage *pRequest);
586 void updateScript(NXCPMessage *pRequest);
587 void renameScript(NXCPMessage *pRequest);
588 void deleteScript(NXCPMessage *pRequest);
967893bb 589 void SendSessionList(UINT32 dwRqId);
b368969c
VK
590 void KillSession(NXCPMessage *pRequest);
591 void SendTrapLog(NXCPMessage *pRequest);
592 void StartSnmpWalk(NXCPMessage *pRequest);
593 void resolveDCINames(NXCPMessage *pRequest);
967893bb 594 UINT32 resolveDCIName(UINT32 dwNode, UINT32 dwItem, TCHAR **ppszName);
b368969c 595 void sendConfigForAgent(NXCPMessage *pRequest);
967893bb 596 void sendAgentCfgList(UINT32 dwRqId);
b368969c
VK
597 void OpenAgentConfig(NXCPMessage *pRequest);
598 void SaveAgentConfig(NXCPMessage *pRequest);
599 void DeleteAgentConfig(NXCPMessage *pRequest);
600 void SwapAgentConfigs(NXCPMessage *pRequest);
601 void SendObjectComments(NXCPMessage *pRequest);
602 void updateObjectComments(NXCPMessage *pRequest);
603 void pushDCIData(NXCPMessage *pRequest);
604 void getAddrList(NXCPMessage *pRequest);
605 void setAddrList(NXCPMessage *pRequest);
606 void resetComponent(NXCPMessage *pRequest);
25a1e9d0
VK
607 void getDCIEventList(NXCPMessage *request);
608 void getDCIScriptList(NXCPMessage *request);
b368969c
VK
609 void SendDCIInfo(NXCPMessage *pRequest);
610 void sendPerfTabDCIList(NXCPMessage *pRequest);
611 void exportConfiguration(NXCPMessage *pRequest);
612 void importConfiguration(NXCPMessage *pRequest);
6f8e39e5 613 void sendGraphList(UINT32 dwRqId);
b368969c
VK
614 void saveGraph(NXCPMessage *pRequest);
615 void deleteGraph(NXCPMessage *pRequest);
616 void AddCACertificate(NXCPMessage *pRequest);
617 void DeleteCertificate(NXCPMessage *pRequest);
618 void UpdateCertificateComments(NXCPMessage *pRequest);
967893bb 619 void getCertificateList(UINT32 dwRqId);
b368969c
VK
620 void queryL2Topology(NXCPMessage *pRequest);
621 void sendSMS(NXCPMessage *pRequest);
967893bb 622 void SendCommunityList(UINT32 dwRqId);
b368969c 623 void UpdateCommunityList(NXCPMessage *pRequest);
a882b714 624 void getSituationList(UINT32 dwRqId);
b368969c
VK
625 void createSituation(NXCPMessage *pRequest);
626 void updateSituation(NXCPMessage *pRequest);
627 void deleteSituation(NXCPMessage *pRequest);
628 void deleteSituationInstance(NXCPMessage *pRequest);
629 void setConfigCLOB(NXCPMessage *pRequest);
630 void getConfigCLOB(NXCPMessage *pRequest);
631 void registerAgent(NXCPMessage *pRequest);
632 void getServerFile(NXCPMessage *pRequest);
633 void cancelFileMonitoring(NXCPMessage *request);
634 void getAgentFile(NXCPMessage *pRequest);
635 void testDCITransformation(NXCPMessage *pRequest);
967893bb 636 void sendJobList(UINT32 dwRqId);
b368969c
VK
637 void cancelJob(NXCPMessage *pRequest);
638 void holdJob(NXCPMessage *pRequest);
639 void unholdJob(NXCPMessage *pRequest);
640 void deployAgentPolicy(NXCPMessage *pRequest, bool uninstallFlag);
641 void getUserCustomAttribute(NXCPMessage *request);
642 void setUserCustomAttribute(NXCPMessage *request);
643 void openServerLog(NXCPMessage *request);
644 void closeServerLog(NXCPMessage *request);
645 void queryServerLog(NXCPMessage *request);
646 void getServerLogQueryData(NXCPMessage *request);
967893bb 647 void sendUsmCredentials(UINT32 dwRqId);
b368969c
VK
648 void updateUsmCredentials(NXCPMessage *pRequest);
649 void sendDCIThresholds(NXCPMessage *request);
650 void addClusterNode(NXCPMessage *request);
651 void findNodeConnection(NXCPMessage *request);
652 void findMacAddress(NXCPMessage *request);
653 void findIpAddress(NXCPMessage *request);
654 void sendLibraryImage(NXCPMessage *request);
655 void updateLibraryImage(NXCPMessage *request);
656 void listLibraryImages(NXCPMessage *request);
657 void deleteLibraryImage(NXCPMessage *request);
658 void executeServerCommand(NXCPMessage *request);
659 void uploadFileToAgent(NXCPMessage *request);
660 void listServerFileStore(NXCPMessage *request);
661 void processConsoleCommand(NXCPMessage *msg);
967893bb
VK
662 void openConsole(UINT32 rqId);
663 void closeConsole(UINT32 rqId);
b368969c
VK
664 void getVlans(NXCPMessage *msg);
665 void receiveFile(NXCPMessage *request);
666 void deleteFile(NXCPMessage *request);
667 void getNetworkPath(NXCPMessage *request);
668 void getNodeComponents(NXCPMessage *request);
669 void getNodeSoftware(NXCPMessage *request);
670 void getWinPerfObjects(NXCPMessage *request);
671 void listMappingTables(NXCPMessage *request);
672 void getMappingTable(NXCPMessage *request);
673 void updateMappingTable(NXCPMessage *request);
674 void deleteMappingTable(NXCPMessage *request);
675 void getWirelessStations(NXCPMessage *request);
967893bb 676 void getSummaryTables(UINT32 rqId);
b368969c
VK
677 void getSummaryTableDetails(NXCPMessage *request);
678 void modifySummaryTable(NXCPMessage *request);
679 void deleteSummaryTable(NXCPMessage *request);
680 void querySummaryTable(NXCPMessage *request);
681 void queryAdHocSummaryTable(NXCPMessage *request);
682 void forwardToReportingServer(NXCPMessage *request);
683 void getSubnetAddressMap(NXCPMessage *request);
684 void getEffectiveRights(NXCPMessage *request);
685 void fileManagerControl(NXCPMessage *request);
686 void uploadUserFileToAgent(NXCPMessage *request);
687 void getSwitchForwardingDatabase(NXCPMessage *request);
688 void getRoutingTable(NXCPMessage *request);
689 void getLocationHistory(NXCPMessage *request);
690 void getScreenshot(NXCPMessage *request);
691 void executeScript(NXCPMessage *request);
5039dede
AK
692
693public:
60557d06 694 ClientSession(SOCKET hSocket, struct sockaddr *addr);
5039dede
AK
695 ~ClientSession();
696
e05b1945
VK
697 void incRefCount() { m_dwRefCount++; }
698 void decRefCount() { if (m_dwRefCount > 0) m_dwRefCount--; }
699
700 void run();
701
19dbc8ef 702 void postMessage(NXCPMessage *pMsg) { m_pSendQueue->put(pMsg->createMessage()); }
b368969c
VK
703 void sendMessage(NXCPMessage *pMsg);
704 void sendRawMessage(NXCP_MESSAGE *pMsg);
967893bb 705 void sendPollerMsg(UINT32 dwRqId, const TCHAR *pszMsg);
cc022855 706 BOOL sendFile(const TCHAR *file, UINT32 dwRqId, long offset);
e05b1945 707
2a964810
VK
708 int getId() { return m_id; }
709 void setId(int id) { if (m_id == -1) m_id = id; }
710 int getState() { return m_state; }
889d7ff7
VK
711 const TCHAR *getUserName() { return m_szUserName; }
712 const TCHAR *getClientInfo() { return m_szClientInfo; }
91f6b72c
VK
713 const TCHAR *getWorkstation() { return m_workstation; }
714 const TCHAR *getWebServerAddress() { return m_webServerAddress; }
967893bb 715 UINT32 getUserId() { return m_dwUserId; }
f4d8fe18 716 UINT64 getSystemRights() { return m_dwSystemAccess; }
87f56b19 717 UINT32 getFlags() { return m_dwFlags; }
f669df41 718 bool isAuthenticated() { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
134c3d00 719 bool isTerminated() { return (m_dwFlags & CSF_TERMINATED) ? true : false; }
f669df41 720 bool isConsoleOpen() { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
967893bb 721 bool isSubscribed(UINT32 dwChannel) { return (m_dwActiveChannels & dwChannel) ? true : false; }
f669df41 722 WORD getCurrentCmd() { return m_wCurrentCmd; }
98abc9f1 723 int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
f8c6f10f 724 int getClientType() { return m_clientType; }
a51628e2 725 time_t getLoginTime() { return m_loginTime; }
e05b1945 726
3fd05687 727 bool checkSysAccessRights(UINT64 requiredAccess)
88f2990c 728 {
729 return (m_dwUserId == 0) ? true :
badf9a95 730 ((requiredAccess & m_dwSystemAccess) == requiredAccess);
e05b1945
VK
731 }
732
87f56b19
VK
733 void setCustomLock(UINT32 bit, bool value)
734 {
735 if (value)
736 m_dwFlags |= (bit & 0xFF000000);
737 else
738 m_dwFlags &= ~(bit & 0xFF000000);
739 }
740
f669df41 741 void kill();
967893bb 742 void notify(UINT32 dwCode, UINT32 dwData = 0);
e05b1945 743
19dbc8ef 744 void queueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->put(pUpdate); }
e05b1945 745 void onNewEvent(Event *pEvent);
e0f99bf0 746 void onSyslogMessage(NX_SYSLOG_RECORD *pRec);
b368969c 747 void onNewSNMPTrap(NXCPMessage *pMsg);
e05b1945 748 void onObjectChange(NetObj *pObject);
967893bb
VK
749 void onUserDBUpdate(int code, UINT32 id, UserDatabaseObject *user);
750 void onAlarmUpdate(UINT32 dwCode, NXC_ALARM *pAlarm);
751 void onActionDBUpdate(UINT32 dwCode, NXC_ACTION *pAction);
b368969c 752 void onSituationChange(NXCPMessage *msg);
72f6ece2 753 void onLibraryImageChange(uuid_t *guid, bool removed = false);
5039dede
AK
754};
755
2bac37f9
VK
756/**
757 * Delayed SQL request
758 */
7dad92fb
VK
759typedef struct
760{
761 TCHAR *query;
762 int bindCount;
763 BYTE *sqlTypes;
764 TCHAR *bindings[1]; /* actual size determined by bindCount field */
765} DELAYED_SQL_REQUEST;
766
2bac37f9
VK
767/**
768 * Delayed request for idata_ INSERT
769 */
f68d9eac
VK
770typedef struct
771{
772 time_t timestamp;
967893bb
VK
773 UINT32 nodeId;
774 UINT32 dciId;
f68d9eac
VK
775 TCHAR value[MAX_RESULT_LENGTH];
776} DELAYED_IDATA_INSERT;
777
76fcb995
VK
778/**
779 * Delayed request for raw_dci_values UPDATE
780 */
781typedef struct
782{
783 time_t timestamp;
784 UINT32 dciId;
785 TCHAR rawValue[MAX_RESULT_LENGTH];
786 TCHAR transformedValue[MAX_RESULT_LENGTH];
787} DELAYED_RAW_DATA_UPDATE;
788
7a4c94ee 789/**
790 * Graph ACL entry
791 */
792struct GRAPH_ACL_ENTRY
793{
794 UINT32 dwGraphId;
795 UINT32 dwUserId;
796 UINT32 dwAccess;
797};
798
799/**
800 * Information about graph with name existence and it's ID.
801 */
802struct GRAPH_ACL_AND_ID
803{
88f2990c 804 UINT32 graphId;
7a4c94ee 805 UINT32 status;
806};
807
2bac37f9
VK
808/**
809 * Functions
810 */
35959841 811bool NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
35f836fe 812#ifdef UNICODE
35959841 813bool NXCORE_EXPORTABLE ConfigReadStrA(const WCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
35f836fe
VK
814#else
815#define ConfigReadStrA ConfigReadStr
816#endif
43526096 817bool NXCORE_EXPORTABLE ConfigReadStrUTF8(const TCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
5039dede 818int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
967893bb 819UINT32 NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, UINT32 dwDefault);
35959841
VK
820bool NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray, int nSize, int nDefault);
821bool NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, bool bCreate, bool isVisible = true, bool needRestart = false);
822bool NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, bool bCreate, bool isVisible = true, bool needRestart = false);
823bool NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, UINT32 dwValue, bool bCreate, bool isVisible = true, bool needRestart = false);
824bool NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray, int nSize, bool bCreate, bool isVisible = true, bool needRestart = false);
5039dede 825TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
35959841
VK
826bool NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, bool bCreate);
827bool NXCORE_EXPORTABLE ConfigDelete(const TCHAR *name);
5039dede 828
35959841 829bool NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
40dedf5d 830INT32 NXCORE_EXPORTABLE MetaDataReadInt(const TCHAR *var, UINT32 defaultValue);
e9902466 831bool NXCORE_EXPORTABLE MetaDataWriteStr(const TCHAR *varName, const TCHAR *value);
28f5b9a4 832
35959841 833bool NXCORE_EXPORTABLE LoadConfig();
5039dede 834
35f836fe
VK
835void NXCORE_EXPORTABLE Shutdown();
836void NXCORE_EXPORTABLE FastShutdown();
837BOOL NXCORE_EXPORTABLE Initialize();
5039dede 838THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
35f836fe
VK
839void NXCORE_EXPORTABLE ShutdownDB();
840void InitiateShutdown();
5039dede 841
400e55c4 842bool NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
5039dede 843
6e383343
VK
844void ConsolePrintf(CONSOLE_CTX pCtx, const TCHAR *pszFormat, ...)
845#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
846 __attribute__ ((format(printf, 2, 3)))
847#endif
848;
532990d2 849void ConsoleWrite(CONSOLE_CTX pCtx, const TCHAR *text);
35f836fe 850int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx);
5039dede
AK
851
852void SaveObjects(DB_HANDLE hdb);
ff6d2c5d
VK
853void NXCORE_EXPORTABLE ObjectTransactionStart();
854void NXCORE_EXPORTABLE ObjectTransactionEnd();
5039dede 855
ce7565e7 856void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query);
7dad92fb 857void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query, int bindCount, int *sqlTypes, const TCHAR **values);
967893bb 858void QueueIDataInsert(time_t timestamp, UINT32 nodeId, UINT32 dciId, const TCHAR *value);
76fcb995 859void QueueRawDciDataUpdate(time_t timestamp, UINT32 dciId, const TCHAR *rawValue, const TCHAR *transformedValue);
ce7565e7
VK
860void StartDBWriter();
861void StopDBWriter();
5039dede 862
ea50bc33
VK
863void PerfDataStorageRequest(DCItem *dci, time_t timestamp, const TCHAR *value);
864void PerfDataStorageRequest(DCTable *dci, time_t timestamp, Table *value);
865
b368969c 866void DecodeSQLStringAndSetVariable(NXCPMessage *pMsg, UINT32 dwVarId, TCHAR *pszStr);
5039dede 867
9708eff4 868SNMP_SecurityContext *SnmpCheckCommSettings(SNMP_Transport *pTransport, INT16 *version, SNMP_SecurityContext *originalContext, StringList *customTestOids);
35f836fe 869void StrToMac(const TCHAR *pszStr, BYTE *pBuffer);
5039dede 870
f42b8099 871void InitLocalNetInfo();
5039dede 872
f42b8099 873ARP_CACHE *GetLocalArpCache();
967893bb 874ARP_CACHE *SnmpGetArpCache(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 875
98762401 876InterfaceList *GetLocalInterfaceList();
5039dede 877
967893bb 878ROUTING_TABLE *SnmpGetRoutingTable(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 879
9796ce45 880void LoadNetworkDeviceDrivers();
21254a93 881NetworkDeviceDriver *FindDriverForNode(Node *node, SNMP_Transport *pTransport);
28e1575f 882NetworkDeviceDriver *FindDriverByName(const TCHAR *name);
1f4c37ee 883void AddDriverSpecificOids(StringList *list);
9796ce45 884
5ad2167d 885void WatchdogInit();
967893bb
VK
886UINT32 WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
887void WatchdogNotify(UINT32 dwId);
5039dede
AK
888void WatchdogPrintStatus(CONSOLE_CTX pCtx);
889
5ad2167d 890void CheckForMgmtNode();
c75e9ee4 891Node NXCORE_EXPORTABLE *PollNewNode(const InetAddress& ipAddr, UINT32 dwCreationFlags, WORD agentPort,
1050c826
VK
892 WORD snmpPort, const TCHAR *pszName, UINT32 dwProxyNode, UINT32 dwSNMPProxy, Cluster *pCluster,
893 UINT32 zoneId, bool doConfPoll, bool discoveredNode);
5039dede 894
b1e9b6b3 895void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
967893bb 896void NXCORE_EXPORTABLE NotifyClientSessions(UINT32 dwCode, UINT32 dwData);
32f372a5 897void NXCORE_EXPORTABLE NotifyClientGraphUpdate(NXCPMessage *update, UINT32 graphId);
e1ebbfc2 898int GetSessionCount(bool withRoot = true);
967893bb 899bool IsLoggedIn(UINT32 dwUserId);
5d9a9c84 900bool NXCORE_EXPORTABLE KillClientSession(int id);
5039dede 901
35f836fe 902void GetSysInfoStr(TCHAR *pszBuffer, int nMaxSize);
c30c0c0f 903InetAddress GetLocalIpAddr();
f7694811 904TCHAR *GetLocalHostName(TCHAR *buffer, size_t bufSize);
5039dede 905
35f836fe 906BOOL ExecCommand(TCHAR *pszCommand);
967893bb 907BOOL SendMagicPacket(UINT32 dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
5039dede 908
35f836fe 909BOOL InitIdTable();
967893bb 910UINT32 CreateUniqueId(int iGroup);
35f836fe 911QWORD CreateUniqueEventId();
69bb7f47 912void SaveCurrentFreeId();
5039dede 913
35f836fe
VK
914void InitMailer();
915void ShutdownMailer();
916void NXCORE_EXPORTABLE PostMail(const TCHAR *pszRcpt, const TCHAR *pszSubject, const TCHAR *pszText);
5039dede 917
35f836fe
VK
918void InitSMSSender();
919void ShutdownSMSSender();
920void NXCORE_EXPORTABLE PostSMS(const TCHAR *pszRcpt, const TCHAR *pszText);
5039dede 921
35f836fe 922void InitTraps();
967893bb 923void SendTrapsToClient(ClientSession *pSession, UINT32 dwRqId);
b368969c 924void CreateTrapCfgMessage(NXCPMessage &msg);
967893bb
VK
925UINT32 CreateNewTrap(UINT32 *pdwTrapId);
926UINT32 CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
b368969c 927UINT32 UpdateTrapFromMsg(NXCPMessage *pMsg);
967893bb 928UINT32 DeleteTrap(UINT32 dwId);
25a1e9d0 929void CreateTrapExportRecord(String &xml, UINT32 id);
967893bb
VK
930
931BOOL IsTableTool(UINT32 dwToolId);
932BOOL CheckObjectToolAccess(UINT32 dwToolId, UINT32 dwUserId);
933UINT32 ExecuteTableTool(UINT32 dwToolId, Node *pNode, UINT32 dwRqId, ClientSession *pSession);
934UINT32 DeleteObjectToolFromDB(UINT32 dwToolId);
6f8e39e5 935UINT32 ChangeObjectToolStatus(UINT32 toolId, bool enabled);
b368969c 936UINT32 UpdateObjectToolFromMessage(NXCPMessage *pMsg);
4c3cc965 937void CreateObjectToolExportRecord(String &xml, UINT32 id);
271e3971 938bool ImportObjectTool(ConfigEntry *config);
967893bb 939
b368969c 940UINT32 ModifySummaryTable(NXCPMessage *msg, LONG *newId);
967893bb 941UINT32 DeleteSummaryTable(LONG tableId);
5389f7b0 942Table *QuerySummaryTable(LONG tableId, SummaryTable *adHocDefinition, UINT32 baseObjectId, UINT32 userId, UINT32 *rcc);
2096c8f0 943bool CreateSummaryTableExportRecord(INT32 id, String &xml);
c7a9d87c 944bool ImportSummaryTable(ConfigEntry *config);
b4c2a628 945
b368969c 946void CreateMessageFromSyslogMsg(NXCPMessage *pMsg, NX_SYSLOG_RECORD *pRec);
4262c0dc 947void ReinitializeSyslogParser();
5039dede
AK
948
949void EscapeString(String &str);
950
ce7565e7 951void InitAuditLog();
967893bb 952void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, BOOL isSuccess, UINT32 userId,
2a964810 953 const TCHAR *workstation, int sessionId, UINT32 objectId,
ce7565e7 954 const TCHAR *format, ...);
88f2990c 955
967893bb
VK
956bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTextLen);
957UINT32 ImportConfig(Config *config, UINT32 flags);
5039dede
AK
958
959#ifdef _WITH_ENCRYPTION
b368969c 960X509 *CertificateFromLoginMessage(NXCPMessage *pMsg);
a50eaebe 961BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
967893bb 962 BYTE *pSignature, UINT32 dwSigLen, int nMappingMethod,
a50eaebe 963 const TCHAR *pszMappingData);
9796ce45 964void ReloadCertificates();
5039dede
AK
965#endif
966
967#ifndef _WIN32
968THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
969#endif /* not _WIN32 */
970
5d3459af
VK
971void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX console);
972void DumpClientSessions(CONSOLE_CTX console);
973void DumpMobileDeviceSessions(CONSOLE_CTX console);
5d3459af
VK
974void ShowServerStats(CONSOLE_CTX console);
975void ShowQueueStats(CONSOLE_CTX console, Queue *pQueue, const TCHAR *pszName);
976void ShowThreadPool(CONSOLE_CTX console, ThreadPool *p);
977void DumpProcess(CONSOLE_CTX console);
5039dede 978
bd360fd5 979GRAPH_ACL_ENTRY *LoadGraphACL(DB_HANDLE hdb, UINT32 graphId, int *pnACLSize);
9ad921e5 980BOOL CheckGraphAccess(GRAPH_ACL_ENTRY *pACL, int nACLSize, UINT32 graphId, UINT32 graphUserId, UINT32 graphDesiredAccess);
fff23fae 981UINT32 GetGraphAccessCheckResult(UINT32 graphId, UINT32 graphUserId);
9ad921e5 982GRAPH_ACL_AND_ID IsGraphNameExists(const TCHAR *graphName);
7a4c94ee 983
d00ad4c6 984#if XMPP_SUPPORTED
244c65ef 985bool SendXMPPMessage(const TCHAR *rcpt, const TCHAR *message);
d00ad4c6 986#endif
244c65ef 987
9fa031cd 988/**
989 * File monitoring
990 */
991struct MONITORED_FILE
992{
993 TCHAR fileName[MAX_PATH];
994 ClientSession *session;
995 UINT32 nodeID;
996};
997
998class FileMonitoringList
999{
1000private:
1001 MUTEX m_mutex;
1002 ObjectArray<MONITORED_FILE> m_monitoredFiles;
1003 MONITORED_FILE* m_monitoredFile;
1004
1005public:
1006 FileMonitoringList();
1007 ~FileMonitoringList();
1008 void addMonitoringFile(MONITORED_FILE *fileForAdd);
e2338033 1009 bool checkDuplicate(MONITORED_FILE *fileForAdd);
1010 ObjectArray<ClientSession>* findClientByFNameAndNodeID(const TCHAR *fileName, UINT32 nodeID);
9fa031cd 1011 bool removeMonitoringFile(MONITORED_FILE *fileForRemove);
1012 void removeDisconectedNode(UINT32 nodeId);
1013
1014private:
1015 void lock();
1016 void unlock();
1017};
1018
534e1b83
VK
1019/**
1020 * Global variables
1021 */
5039dede
AK
1022extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
1023extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
967893bb
VK
1024extern UINT32 g_dwLogRotationMode;
1025extern UINT32 g_dwMaxLogSize;
1026extern UINT32 g_dwLogHistorySize;
4f8998ca 1027extern TCHAR g_szDailyLogFileSuffix[64];
5039dede
AK
1028extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
1029extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
1030#ifndef _WIN32
1031extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
1032#endif
db6a6b45
VK
1033extern TCHAR NXCORE_EXPORTABLE g_netxmsdDataDir[];
1034extern TCHAR NXCORE_EXPORTABLE g_netxmsdLibDir[];
967893bb 1035extern UINT32 NXCORE_EXPORTABLE g_processAffinityMask;
e9902466 1036extern UINT64 g_serverId;
5039dede 1037extern RSA *g_pServerKey;
c59466d2
VK
1038extern UINT32 g_icmpPingSize;
1039extern UINT32 g_icmpPingTimeout;
1040extern UINT32 g_auditFlags;
1041extern time_t g_serverStartTime;
1042extern UINT32 g_lockTimeout;
1043extern UINT32 g_agentCommandTimeout;
1044extern UINT32 g_thresholdRepeatInterval;
1045extern int g_requiredPolls;
1046extern UINT32 g_slmPollingInterval;
5039dede 1047
b8c1ec69
VK
1048extern TCHAR g_szDbDriver[];
1049extern TCHAR g_szDbDrvParams[];
1050extern TCHAR g_szDbServer[];
1051extern TCHAR g_szDbLogin[];
1052extern TCHAR g_szDbPassword[];
1053extern TCHAR g_szDbName[];
f3c30cf5 1054extern TCHAR g_szDbSchema[];
b8c1ec69 1055extern DB_DRIVER g_dbDriver;
5039dede 1056extern DB_HANDLE NXCORE_EXPORTABLE g_hCoreDB;
76fcb995
VK
1057extern Queue *g_dbWriterQueue;
1058extern Queue *g_dciDataWriterQueue;
1059extern Queue *g_dciRawDataWriterQueue;
5039dede 1060
2a964810 1061extern int NXCORE_EXPORTABLE g_dbSyntax;
9fa031cd 1062extern FileMonitoringList g_monitoringList;
5039dede 1063
5d3459af
VK
1064extern ThreadPool *g_mainThreadPool;
1065
5039dede 1066#endif /* _nms_core_h_ */