fixed build errors
[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"
5039dede 107#include "nxcore_situations.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
159#define IDG_SITUATION 19
160#define IDG_DCT_COLUMN 20
161#define IDG_MAPPING_TABLE 21
162#define IDG_DCI_SUMMARY_TABLE 22
163#define IDG_SCHEDULED_TASK 23
6a6b96c0 164#define IDG_ALARM_CATEGORY 24
5039dede 165
0f506caa
VK
166/**
167 * Exit codes for console commands
168 */
5039dede
AK
169#define CMD_EXIT_CONTINUE 0
170#define CMD_EXIT_CLOSE_SESSION 1
171#define CMD_EXIT_SHUTDOWN 2
172
0f506caa
VK
173/**
174 * Network discovery mode
175 */
5039dede
AK
176#define DISCOVERY_DISABLED 0
177#define DISCOVERY_PASSIVE_ONLY 1
178#define DISCOVERY_ACTIVE 2
179
0f506caa
VK
180/**
181 * Client session flags
182 */
134c3d00 183#define CSF_TERMINATED ((UINT32)0x00000001)
850ce3ed
VK
184#define CSF_EPP_LOCKED ((UINT32)0x00000002)
185#define CSF_PACKAGE_DB_LOCKED ((UINT32)0x00000004)
186#define CSF_USER_DB_LOCKED ((UINT32)0x00000008)
187#define CSF_EPP_UPLOAD ((UINT32)0x00000010)
188#define CSF_CONSOLE_OPEN ((UINT32)0x00000020)
189#define CSF_AUTHENTICATED ((UINT32)0x00000080)
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
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
84ea7692
VK
396/**
397 * Client (user) session
398 */
a0e3917e 399class NXCORE_EXPORTABLE ClientSession
5039dede
AK
400{
401private:
402 SOCKET m_hSocket;
403 Queue *m_pSendQueue;
404 Queue *m_pMessageQueue;
405 Queue *m_pUpdateQueue;
2a964810
VK
406 int m_id;
407 int m_state;
5039dede 408 WORD m_wCurrentCmd;
967893bb 409 UINT32 m_dwUserId;
f4d8fe18 410 UINT64 m_dwSystemAccess; // User's system access rights
967893bb 411 UINT32 m_dwFlags; // Session flags
f8c6f10f 412 int m_clientType; // Client system type - desktop, web, mobile, etc.
98abc9f1 413 NXCPEncryptionContext *m_pCtx;
5039dede
AK
414 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
415 THREAD m_hWriteThread;
416 THREAD m_hProcessingThread;
417 THREAD m_hUpdateThread;
d3a7cf4c 418 MUTEX m_mutexSocketWrite;
5039dede
AK
419 MUTEX m_mutexSendEvents;
420 MUTEX m_mutexSendSyslog;
421 MUTEX m_mutexSendTrapLog;
422 MUTEX m_mutexSendObjects;
423 MUTEX m_mutexSendAlarms;
424 MUTEX m_mutexSendActions;
425 MUTEX m_mutexSendAuditLog;
426 MUTEX m_mutexSendSituations;
427 MUTEX m_mutexPollerInit;
60557d06 428 struct sockaddr *m_clientAddr;
91f6b72c
VK
429 TCHAR m_workstation[256]; // IP address or name of connected host in textual form
430 TCHAR m_webServerAddress[256]; // IP address or name of web server for web sessions
77a08c86
VK
431 TCHAR m_loginName[MAX_USER_NAME];
432 TCHAR m_sessionName[MAX_SESSION_NAME]; // String in form login_name@host
433 TCHAR m_clientInfo[96]; // Client app info string
2a964810 434 TCHAR m_language[8]; // Client's desired language
a51628e2 435 time_t m_loginTime;
967893bb
VK
436 UINT32 m_dwOpenDCIListSize; // Number of open DCI lists
437 UINT32 *m_pOpenDCIList; // List of nodes with DCI lists open
438 UINT32 m_dwNumRecordsToUpload; // Number of records to be uploaded
439 UINT32 m_dwRecordsUploaded;
5039dede
AK
440 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
441 int m_hCurrFile;
967893bb
VK
442 UINT32 m_dwFileRqId;
443 UINT32 m_dwUploadCommand;
444 UINT32 m_dwUploadData;
e928a6db 445 uuid_t m_uploadImageGuid;
5039dede 446 TCHAR m_szCurrFileName[MAX_PATH];
c044d4f3 447 VolatileCounter m_refCount;
967893bb
VK
448 UINT32 m_dwEncryptionRqId;
449 UINT32 m_dwEncryptionResult;
5039dede 450 CONDITION m_condEncryptionSetup;
200d662d 451 CONSOLE_CTX m_console; // Server console context
810bd8c4 452 StringList m_musicTypeList;
7cf549ad 453 ObjectIndex m_agentConn;
84ea7692 454 StringObjectMap<UINT32> *m_subscriptions;
c044d4f3 455 MUTEX m_subscriptionLock;
5039dede 456
534e1b83
VK
457 static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
458 static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
459 static THREAD_RESULT THREAD_CALL processingThreadStarter(void *);
460 static THREAD_RESULT THREAD_CALL updateThreadStarter(void *);
134c3d00 461 static void pollerThreadStarter(void *);
5039dede 462
78ccd7b4
VK
463 DECLARE_THREAD_STARTER(cancelFileMonitoring)
464 DECLARE_THREAD_STARTER(clearDCIData)
465 DECLARE_THREAD_STARTER(createObject)
466 DECLARE_THREAD_STARTER(executeAction)
467 DECLARE_THREAD_STARTER(executeScript)
e9bf9011 468 DECLARE_THREAD_STARTER(executeLibraryScript)
74d0b136 469 DECLARE_THREAD_STARTER(fileManagerControl)
78ccd7b4
VK
470 DECLARE_THREAD_STARTER(findIpAddress)
471 DECLARE_THREAD_STARTER(findMacAddress)
472 DECLARE_THREAD_STARTER(findNodeConnection)
473 DECLARE_THREAD_STARTER(forceDCIPoll)
474 DECLARE_THREAD_STARTER(forwardToReportingServer)
475 DECLARE_THREAD_STARTER(getAgentFile)
476 DECLARE_THREAD_STARTER(getAlarmEvents)
3ddc492b 477 DECLARE_THREAD_STARTER(getAlarms)
78ccd7b4 478 DECLARE_THREAD_STARTER(getCollectedData)
0cf6fcbd 479 DECLARE_THREAD_STARTER(getPredictedData)
4899db4d 480 DECLARE_THREAD_STARTER(getLocationHistory)
78ccd7b4
VK
481 DECLARE_THREAD_STARTER(getNetworkPath)
482 DECLARE_THREAD_STARTER(getRoutingTable)
483 DECLARE_THREAD_STARTER(getServerFile)
484 DECLARE_THREAD_STARTER(getServerLogQueryData)
485 DECLARE_THREAD_STARTER(getSwitchForwardingDatabase)
486 DECLARE_THREAD_STARTER(getTableCollectedData)
487 DECLARE_THREAD_STARTER(importConfiguration)
488 DECLARE_THREAD_STARTER(openHelpdeskIssue)
489 DECLARE_THREAD_STARTER(processConsoleCommand)
490 DECLARE_THREAD_STARTER(queryAgentTable)
491 DECLARE_THREAD_STARTER(queryL2Topology)
492 DECLARE_THREAD_STARTER(queryParameter)
493 DECLARE_THREAD_STARTER(queryServerLog)
494 DECLARE_THREAD_STARTER(sendEventLog)
495 DECLARE_THREAD_STARTER(sendMib)
496 DECLARE_THREAD_STARTER(sendSyslog)
497 DECLARE_THREAD_STARTER(uploadUserFileToAgent)
badd6e08
VK
498 DECLARE_THREAD_STARTER(getRepositories)
499 DECLARE_THREAD_STARTER(addRepository)
500 DECLARE_THREAD_STARTER(modifyRepository)
501 DECLARE_THREAD_STARTER(deleteRepository)
5039dede 502
62768df3
VK
503 void readThread();
504 void writeThread();
505 void processingThread();
506 void updateThread();
967893bb 507 void pollerThread(Node *pNode, int iPollType, UINT32 dwRqId);
5039dede 508
badd6e08
VK
509 void debugPrintf(int level, const TCHAR *format, ...);
510
b368969c 511 void setupEncryption(NXCPMessage *request);
967893bb 512 void respondToKeepalive(UINT32 dwRqId);
e05b1945 513 void onFileUpload(BOOL bSuccess);
967893bb 514 void sendServerInfo(UINT32 dwRqId);
b368969c
VK
515 void login(NXCPMessage *pRequest);
516 void sendAllObjects(NXCPMessage *pRequest);
517 void sendSelectedObjects(NXCPMessage *pRequest);
518 void sendEventLog(NXCPMessage *pRequest);
c85c8ef2
VK
519 void getConfigurationVariables(UINT32 dwRqId);
520 void getPublicConfigurationVariable(NXCPMessage *request);
521 void setConfigurationVariable(NXCPMessage *pRequest);
522 void deleteConfigurationVariable(NXCPMessage *pRequest);
967893bb 523 void sendUserDB(UINT32 dwRqId);
b368969c
VK
524 void createUser(NXCPMessage *pRequest);
525 void updateUser(NXCPMessage *pRequest);
2d8d8ea2 526 void detachLdapUser(NXCPMessage *pRequest);
b368969c 527 void deleteUser(NXCPMessage *pRequest);
77a08c86
VK
528 void setPassword(NXCPMessage *request);
529 void validatePassword(NXCPMessage *request);
967893bb 530 void lockUserDB(UINT32 dwRqId, BOOL bLock);
a881eafa 531 void getAlarmCategories(UINT32 requestId);
6a6b96c0 532 void modifyAlarmCategory(NXCPMessage *pRequest);
a881eafa 533 void deleteAlarmCategory(NXCPMessage *pRequest);
967893bb 534 void sendEventDB(UINT32 dwRqId);
b368969c
VK
535 void modifyEventTemplate(NXCPMessage *pRequest);
536 void deleteEventTemplate(NXCPMessage *pRequest);
967893bb 537 void generateEventCode(UINT32 dwRqId);
b368969c
VK
538 void modifyObject(NXCPMessage *pRequest);
539 void changeObjectMgmtStatus(NXCPMessage *pRequest);
7e18667a
VK
540 void enterMaintenanceMode(NXCPMessage *request);
541 void leaveMaintenanceMode(NXCPMessage *request);
b368969c
VK
542 void openNodeDCIList(NXCPMessage *pRequest);
543 void closeNodeDCIList(NXCPMessage *pRequest);
544 void modifyNodeDCI(NXCPMessage *pRequest);
545 void copyDCI(NXCPMessage *pRequest);
546 void applyTemplate(NXCPMessage *pRequest);
547 void getCollectedData(NXCPMessage *pRequest);
548 void getTableCollectedData(NXCPMessage *pRequest);
549 bool getCollectedDataFromDB(NXCPMessage *request, NXCPMessage *response, DataCollectionTarget *object, int dciType);
550 void clearDCIData(NXCPMessage *pRequest);
79633a65 551 void forceDCIPoll(NXCPMessage *pRequest);
b368969c
VK
552 void changeDCIStatus(NXCPMessage *pRequest);
553 void getLastValues(NXCPMessage *pRequest);
554 void getLastValuesByDciId(NXCPMessage *pRequest);
555 void getTableLastValues(NXCPMessage *pRequest);
556 void getThresholdSummary(NXCPMessage *request);
557 void openEPP(NXCPMessage *request);
967893bb 558 void closeEPP(UINT32 dwRqId);
b368969c
VK
559 void saveEPP(NXCPMessage *pRequest);
560 void processEPPRecord(NXCPMessage *pRequest);
967893bb 561 void sendMIBTimestamp(UINT32 dwRqId);
b368969c
VK
562 void sendMib(NXCPMessage *request);
563 void createObject(NXCPMessage *request);
564 void changeObjectBinding(NXCPMessage *request, BOOL bBind);
565 void deleteObject(NXCPMessage *request);
3ddc492b 566 void getAlarms(NXCPMessage *request);
b368969c
VK
567 void getAlarm(NXCPMessage *request);
568 void getAlarmEvents(NXCPMessage *request);
569 void acknowledgeAlarm(NXCPMessage *request);
570 void resolveAlarm(NXCPMessage *request, bool terminate);
a881eafa 571 void bulkResolveAlarms(NXCPMessage *pRequest, bool terminate);
b368969c
VK
572 void deleteAlarm(NXCPMessage *request);
573 void openHelpdeskIssue(NXCPMessage *request);
574 void getHelpdeskUrl(NXCPMessage *request);
575 void unlinkHelpdeskIssue(NXCPMessage *request);
576 void getAlarmComments(NXCPMessage *pRequest);
577 void updateAlarmComment(NXCPMessage *pRequest);
578 void deleteAlarmComment(NXCPMessage *request);
579 void updateAlarmStatusFlow(NXCPMessage *request);
580 void createAction(NXCPMessage *pRequest);
581 void updateAction(NXCPMessage *pRequest);
582 void deleteAction(NXCPMessage *pRequest);
967893bb 583 void sendAllActions(UINT32 dwRqId);
b368969c
VK
584 void forcedNodePoll(NXCPMessage *pRequest);
585 void onTrap(NXCPMessage *pRequest);
586 void onWakeUpNode(NXCPMessage *pRequest);
587 void queryParameter(NXCPMessage *pRequest);
588 void queryAgentTable(NXCPMessage *pRequest);
589 void editTrap(int iOperation, NXCPMessage *pRequest);
967893bb
VK
590 void LockTrapCfg(UINT32 dwRqId, BOOL bLock);
591 void sendAllTraps(UINT32 dwRqId);
592 void sendAllTraps2(UINT32 dwRqId);
593 void LockPackageDB(UINT32 dwRqId, BOOL bLock);
594 void SendAllPackages(UINT32 dwRqId);
b368969c
VK
595 void InstallPackage(NXCPMessage *pRequest);
596 void RemovePackage(NXCPMessage *pRequest);
597 void DeployPackage(NXCPMessage *pRequest);
598 void getParametersList(NXCPMessage *pRequest);
599 void getUserVariable(NXCPMessage *pRequest);
600 void setUserVariable(NXCPMessage *pRequest);
601 void copyUserVariable(NXCPMessage *pRequest);
602 void enumUserVariables(NXCPMessage *pRequest);
603 void deleteUserVariable(NXCPMessage *pRequest);
604 void changeObjectZone(NXCPMessage *pRequest);
605 void getAgentConfig(NXCPMessage *pRequest);
606 void updateAgentConfig(NXCPMessage *pRequest);
607 void executeAction(NXCPMessage *pRequest);
b576249a
VK
608 void getObjectTools(UINT32 requestId);
609 void getObjectToolDetails(NXCPMessage *request);
b368969c
VK
610 void updateObjectTool(NXCPMessage *pRequest);
611 void deleteObjectTool(NXCPMessage *pRequest);
612 void changeObjectToolStatus(NXCPMessage *pRequest);
967893bb 613 void generateObjectToolId(UINT32 dwRqId);
b368969c
VK
614 void execTableTool(NXCPMessage *pRequest);
615 void changeSubscription(NXCPMessage *pRequest);
616 void sendSyslog(NXCPMessage *pRequest);
967893bb
VK
617 void sendServerStats(UINT32 dwRqId);
618 void sendScriptList(UINT32 dwRqId);
b368969c
VK
619 void sendScript(NXCPMessage *pRequest);
620 void updateScript(NXCPMessage *pRequest);
621 void renameScript(NXCPMessage *pRequest);
622 void deleteScript(NXCPMessage *pRequest);
967893bb 623 void SendSessionList(UINT32 dwRqId);
b368969c
VK
624 void KillSession(NXCPMessage *pRequest);
625 void SendTrapLog(NXCPMessage *pRequest);
626 void StartSnmpWalk(NXCPMessage *pRequest);
627 void resolveDCINames(NXCPMessage *pRequest);
55a918b7 628 UINT32 resolveDCIName(UINT32 dwNode, UINT32 dwItem, TCHAR *ppszName);
b368969c 629 void sendConfigForAgent(NXCPMessage *pRequest);
967893bb 630 void sendAgentCfgList(UINT32 dwRqId);
b368969c
VK
631 void OpenAgentConfig(NXCPMessage *pRequest);
632 void SaveAgentConfig(NXCPMessage *pRequest);
633 void DeleteAgentConfig(NXCPMessage *pRequest);
634 void SwapAgentConfigs(NXCPMessage *pRequest);
635 void SendObjectComments(NXCPMessage *pRequest);
636 void updateObjectComments(NXCPMessage *pRequest);
637 void pushDCIData(NXCPMessage *pRequest);
ba889094
VK
638 void getAddrList(NXCPMessage *request);
639 void setAddrList(NXCPMessage *request);
b368969c 640 void resetComponent(NXCPMessage *pRequest);
25a1e9d0
VK
641 void getDCIEventList(NXCPMessage *request);
642 void getDCIScriptList(NXCPMessage *request);
b368969c
VK
643 void SendDCIInfo(NXCPMessage *pRequest);
644 void sendPerfTabDCIList(NXCPMessage *pRequest);
645 void exportConfiguration(NXCPMessage *pRequest);
646 void importConfiguration(NXCPMessage *pRequest);
aed41472 647 void sendGraphList(NXCPMessage *request);
b368969c
VK
648 void saveGraph(NXCPMessage *pRequest);
649 void deleteGraph(NXCPMessage *pRequest);
493beadc
VK
650 void addCACertificate(NXCPMessage *pRequest);
651 void deleteCertificate(NXCPMessage *pRequest);
652 void updateCertificateComments(NXCPMessage *pRequest);
967893bb 653 void getCertificateList(UINT32 dwRqId);
b368969c
VK
654 void queryL2Topology(NXCPMessage *pRequest);
655 void sendSMS(NXCPMessage *pRequest);
967893bb 656 void SendCommunityList(UINT32 dwRqId);
b368969c 657 void UpdateCommunityList(NXCPMessage *pRequest);
a882b714 658 void getSituationList(UINT32 dwRqId);
b368969c
VK
659 void createSituation(NXCPMessage *pRequest);
660 void updateSituation(NXCPMessage *pRequest);
661 void deleteSituation(NXCPMessage *pRequest);
662 void deleteSituationInstance(NXCPMessage *pRequest);
663 void setConfigCLOB(NXCPMessage *pRequest);
664 void getConfigCLOB(NXCPMessage *pRequest);
665 void registerAgent(NXCPMessage *pRequest);
666 void getServerFile(NXCPMessage *pRequest);
667 void cancelFileMonitoring(NXCPMessage *request);
668 void getAgentFile(NXCPMessage *pRequest);
669 void testDCITransformation(NXCPMessage *pRequest);
967893bb 670 void sendJobList(UINT32 dwRqId);
b368969c
VK
671 void cancelJob(NXCPMessage *pRequest);
672 void holdJob(NXCPMessage *pRequest);
673 void unholdJob(NXCPMessage *pRequest);
674 void deployAgentPolicy(NXCPMessage *pRequest, bool uninstallFlag);
675 void getUserCustomAttribute(NXCPMessage *request);
676 void setUserCustomAttribute(NXCPMessage *request);
677 void openServerLog(NXCPMessage *request);
678 void closeServerLog(NXCPMessage *request);
679 void queryServerLog(NXCPMessage *request);
680 void getServerLogQueryData(NXCPMessage *request);
967893bb 681 void sendUsmCredentials(UINT32 dwRqId);
b368969c
VK
682 void updateUsmCredentials(NXCPMessage *pRequest);
683 void sendDCIThresholds(NXCPMessage *request);
684 void addClusterNode(NXCPMessage *request);
685 void findNodeConnection(NXCPMessage *request);
686 void findMacAddress(NXCPMessage *request);
687 void findIpAddress(NXCPMessage *request);
688 void sendLibraryImage(NXCPMessage *request);
689 void updateLibraryImage(NXCPMessage *request);
690 void listLibraryImages(NXCPMessage *request);
691 void deleteLibraryImage(NXCPMessage *request);
692 void executeServerCommand(NXCPMessage *request);
693 void uploadFileToAgent(NXCPMessage *request);
694 void listServerFileStore(NXCPMessage *request);
695 void processConsoleCommand(NXCPMessage *msg);
967893bb
VK
696 void openConsole(UINT32 rqId);
697 void closeConsole(UINT32 rqId);
b368969c
VK
698 void getVlans(NXCPMessage *msg);
699 void receiveFile(NXCPMessage *request);
700 void deleteFile(NXCPMessage *request);
701 void getNetworkPath(NXCPMessage *request);
702 void getNodeComponents(NXCPMessage *request);
703 void getNodeSoftware(NXCPMessage *request);
704 void getWinPerfObjects(NXCPMessage *request);
705 void listMappingTables(NXCPMessage *request);
706 void getMappingTable(NXCPMessage *request);
707 void updateMappingTable(NXCPMessage *request);
708 void deleteMappingTable(NXCPMessage *request);
709 void getWirelessStations(NXCPMessage *request);
967893bb 710 void getSummaryTables(UINT32 rqId);
b368969c
VK
711 void getSummaryTableDetails(NXCPMessage *request);
712 void modifySummaryTable(NXCPMessage *request);
713 void deleteSummaryTable(NXCPMessage *request);
714 void querySummaryTable(NXCPMessage *request);
715 void queryAdHocSummaryTable(NXCPMessage *request);
716 void forwardToReportingServer(NXCPMessage *request);
717 void getSubnetAddressMap(NXCPMessage *request);
718 void getEffectiveRights(NXCPMessage *request);
719 void fileManagerControl(NXCPMessage *request);
720 void uploadUserFileToAgent(NXCPMessage *request);
721 void getSwitchForwardingDatabase(NXCPMessage *request);
722 void getRoutingTable(NXCPMessage *request);
723 void getLocationHistory(NXCPMessage *request);
724 void getScreenshot(NXCPMessage *request);
725 void executeScript(NXCPMessage *request);
e9bf9011 726 void executeLibraryScript(NXCPMessage *request);
5f573844 727 void compileScript(NXCPMessage *request);
4b535d78 728 void resyncAgentDciConfiguration(NXCPMessage *request);
729 void cleanAgentDciConfiguration(NXCPMessage *request);
ec13a467
VK
730 void getSchedulerTaskHandlers(NXCPMessage *request);
731 void getScheduledTasks(NXCPMessage *request);
732 void addScheduledTask(NXCPMessage *request);
733 void updateScheduledTask(NXCPMessage *request);
734 void removeScheduledTask(NXCPMessage *request);
badd6e08
VK
735 void getRepositories(NXCPMessage *request);
736 void addRepository(NXCPMessage *request);
737 void modifyRepository(NXCPMessage *request);
738 void deleteRepository(NXCPMessage *request);
0cf6fcbd
VK
739 void getPredictionEngines(NXCPMessage *request);
740 void getPredictedData(NXCPMessage *request);
4ef60905
AK
741#ifdef WITH_ZMQ
742 void zmqManageSubscription(NXCPMessage *request, zmq::SubscriptionType type, bool subscribe);
743 void zmqListSubscriptions(NXCPMessage *request, zmq::SubscriptionType type);
744#endif
5039dede
AK
745
746public:
60557d06 747 ClientSession(SOCKET hSocket, struct sockaddr *addr);
5039dede
AK
748 ~ClientSession();
749
c044d4f3
VK
750 void incRefCount() { InterlockedIncrement(&m_refCount); }
751 void decRefCount() { InterlockedDecrement(&m_refCount); }
e05b1945
VK
752
753 void run();
754
19dbc8ef 755 void postMessage(NXCPMessage *pMsg) { m_pSendQueue->put(pMsg->createMessage()); }
a07511b5 756 bool sendMessage(NXCPMessage *pMsg);
b368969c 757 void sendRawMessage(NXCP_MESSAGE *pMsg);
967893bb 758 void sendPollerMsg(UINT32 dwRqId, const TCHAR *pszMsg);
cc022855 759 BOOL sendFile(const TCHAR *file, UINT32 dwRqId, long offset);
e05b1945 760
9515e7b1
VK
761 void writeAuditLog(const TCHAR *subsys, bool success, UINT32 objectId, const TCHAR *format, ...);
762
c044d4f3 763 int getId() const { return m_id; }
2a964810 764 void setId(int id) { if (m_id == -1) m_id = id; }
e05b1945 765
c044d4f3
VK
766 int getState() const { return m_state; }
767 const TCHAR *getLoginName() const { return m_loginName; }
768 const TCHAR *getSessionName() const { return m_sessionName; }
769 const TCHAR *getClientInfo() const { return m_clientInfo; }
770 const TCHAR *getWorkstation() const { return m_workstation; }
771 const TCHAR *getWebServerAddress() const { return m_webServerAddress; }
772 UINT32 getUserId() const { return m_dwUserId; }
773 UINT64 getSystemRights() const { return m_dwSystemAccess; }
774 UINT32 getFlags() const { return m_dwFlags; }
775 bool isAuthenticated() const { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
776 bool isTerminated() const { return (m_dwFlags & CSF_TERMINATED) ? true : false; }
777 bool isConsoleOpen() const { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
778 WORD getCurrentCmd() const { return m_wCurrentCmd; }
779 int getCipher() const { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
780 int getClientType() const { return m_clientType; }
781 time_t getLoginTime() const { return m_loginTime; }
782 bool isSubscribedTo(const TCHAR *channel) const;
783
784 bool checkSysAccessRights(UINT64 requiredAccess) const
88f2990c 785 {
786 return (m_dwUserId == 0) ? true :
badf9a95 787 ((requiredAccess & m_dwSystemAccess) == requiredAccess);
e05b1945
VK
788 }
789
87f56b19
VK
790 void setCustomLock(UINT32 bit, bool value)
791 {
792 if (value)
793 m_dwFlags |= (bit & 0xFF000000);
794 else
795 m_dwFlags &= ~(bit & 0xFF000000);
796 }
797
f669df41 798 void kill();
967893bb 799 void notify(UINT32 dwCode, UINT32 dwData = 0);
e05b1945 800
19dbc8ef 801 void queueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->put(pUpdate); }
e05b1945 802 void onNewEvent(Event *pEvent);
e0f99bf0 803 void onSyslogMessage(NX_SYSLOG_RECORD *pRec);
b368969c 804 void onNewSNMPTrap(NXCPMessage *pMsg);
e05b1945 805 void onObjectChange(NetObj *pObject);
d727efe6 806 void onAlarmUpdate(UINT32 dwCode, const Alarm *alarm);
967893bb 807 void onActionDBUpdate(UINT32 dwCode, NXC_ACTION *pAction);
b368969c 808 void onSituationChange(NXCPMessage *msg);
72f6ece2 809 void onLibraryImageChange(uuid_t *guid, bool removed = false);
5039dede
AK
810};
811
2bac37f9
VK
812/**
813 * Delayed SQL request
814 */
7dad92fb
VK
815typedef struct
816{
817 TCHAR *query;
818 int bindCount;
819 BYTE *sqlTypes;
820 TCHAR *bindings[1]; /* actual size determined by bindCount field */
821} DELAYED_SQL_REQUEST;
822
2bac37f9
VK
823/**
824 * Delayed request for idata_ INSERT
825 */
f68d9eac
VK
826typedef struct
827{
828 time_t timestamp;
967893bb
VK
829 UINT32 nodeId;
830 UINT32 dciId;
f68d9eac
VK
831 TCHAR value[MAX_RESULT_LENGTH];
832} DELAYED_IDATA_INSERT;
833
76fcb995
VK
834/**
835 * Delayed request for raw_dci_values UPDATE
836 */
837typedef struct
838{
839 time_t timestamp;
840 UINT32 dciId;
841 TCHAR rawValue[MAX_RESULT_LENGTH];
842 TCHAR transformedValue[MAX_RESULT_LENGTH];
843} DELAYED_RAW_DATA_UPDATE;
844
7a4c94ee 845/**
846 * Graph ACL entry
847 */
848struct GRAPH_ACL_ENTRY
849{
850 UINT32 dwGraphId;
851 UINT32 dwUserId;
852 UINT32 dwAccess;
853};
854
855/**
856 * Information about graph with name existence and it's ID.
857 */
858struct GRAPH_ACL_AND_ID
859{
88f2990c 860 UINT32 graphId;
7a4c94ee 861 UINT32 status;
862};
863
9f3db00f
VK
864/**
865 * Thread pool stats
866 */
867enum ThreadPoolStat
868{
869 THREAD_POOL_CURR_SIZE,
870 THREAD_POOL_MIN_SIZE,
871 THREAD_POOL_MAX_SIZE,
872 THREAD_POOL_REQUESTS,
873 THREAD_POOL_LOAD,
874 THREAD_POOL_USAGE,
875 THREAD_POOL_LOADAVG_1,
876 THREAD_POOL_LOADAVG_5,
877 THREAD_POOL_LOADAVG_15
878};
879
234079c4
VK
880/**
881 * Server command execution data
882 */
883class ServerCommandExecData
884{
885private:
886 TCHAR *m_command;
887 bool m_sendOutput;
888 UINT32 m_requestId;
889 ClientSession *m_session;
890
891public:
892 ServerCommandExecData(TCHAR *command, bool sendOutput, UINT32 requestId, ClientSession *session);
893 ~ServerCommandExecData();
894
895 bool sendOutput() { return m_sendOutput; }
896 const TCHAR *getCommand() { return m_command; }
897 UINT32 getRequestId() { return m_requestId; }
898 ClientSession *getSession() { return m_session; }
899};
900
2bac37f9
VK
901/**
902 * Functions
903 */
35959841 904bool NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
9bd1bace 905bool NXCORE_EXPORTABLE ConfigReadStrEx(DB_HANDLE hdb, const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
35f836fe 906#ifdef UNICODE
35959841 907bool NXCORE_EXPORTABLE ConfigReadStrA(const WCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
35f836fe
VK
908#else
909#define ConfigReadStrA ConfigReadStr
910#endif
43526096 911bool NXCORE_EXPORTABLE ConfigReadStrUTF8(const TCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault);
5039dede 912int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
9bd1bace 913int NXCORE_EXPORTABLE ConfigReadIntEx(DB_HANDLE hdb, const TCHAR *szVar, int iDefault);
967893bb 914UINT32 NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, UINT32 dwDefault);
35959841
VK
915bool NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray, int nSize, int nDefault);
916bool NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, bool bCreate, bool isVisible = true, bool needRestart = false);
917bool NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, bool bCreate, bool isVisible = true, bool needRestart = false);
918bool NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, UINT32 dwValue, bool bCreate, bool isVisible = true, bool needRestart = false);
919bool NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray, int nSize, bool bCreate, bool isVisible = true, bool needRestart = false);
5039dede 920TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
35959841
VK
921bool NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, bool bCreate);
922bool NXCORE_EXPORTABLE ConfigDelete(const TCHAR *name);
5039dede 923
0fdb37c6 924void MetaDataPreLoad();
35959841 925bool NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
dba9c498 926INT32 NXCORE_EXPORTABLE MetaDataReadInt32(const TCHAR *var, INT32 defaultValue);
e9902466 927bool NXCORE_EXPORTABLE MetaDataWriteStr(const TCHAR *varName, const TCHAR *value);
dba9c498 928bool NXCORE_EXPORTABLE MetaDataWriteInt32(const TCHAR *name, INT32 value);
28f5b9a4 929
2df047f4 930bool NXCORE_EXPORTABLE LoadConfig(int *debugLevel);
5039dede 931
35f836fe
VK
932void NXCORE_EXPORTABLE Shutdown();
933void NXCORE_EXPORTABLE FastShutdown();
934BOOL NXCORE_EXPORTABLE Initialize();
5039dede 935THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
35f836fe
VK
936void NXCORE_EXPORTABLE ShutdownDB();
937void InitiateShutdown();
5039dede 938
400e55c4 939bool NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
5039dede 940
6e383343
VK
941void ConsolePrintf(CONSOLE_CTX pCtx, const TCHAR *pszFormat, ...)
942#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
943 __attribute__ ((format(printf, 2, 3)))
944#endif
945;
532990d2 946void ConsoleWrite(CONSOLE_CTX pCtx, const TCHAR *text);
35f836fe 947int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx);
5039dede
AK
948
949void SaveObjects(DB_HANDLE hdb);
ff6d2c5d
VK
950void NXCORE_EXPORTABLE ObjectTransactionStart();
951void NXCORE_EXPORTABLE ObjectTransactionEnd();
5039dede 952
ce7565e7 953void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query);
7dad92fb 954void NXCORE_EXPORTABLE QueueSQLRequest(const TCHAR *query, int bindCount, int *sqlTypes, const TCHAR **values);
967893bb 955void QueueIDataInsert(time_t timestamp, UINT32 nodeId, UINT32 dciId, const TCHAR *value);
76fcb995 956void QueueRawDciDataUpdate(time_t timestamp, UINT32 dciId, const TCHAR *rawValue, const TCHAR *transformedValue);
ce7565e7
VK
957void StartDBWriter();
958void StopDBWriter();
5039dede 959
ea50bc33
VK
960void PerfDataStorageRequest(DCItem *dci, time_t timestamp, const TCHAR *value);
961void PerfDataStorageRequest(DCTable *dci, time_t timestamp, Table *value);
962
b368969c 963void DecodeSQLStringAndSetVariable(NXCPMessage *pMsg, UINT32 dwVarId, TCHAR *pszStr);
5039dede 964
d0a2ada6 965SNMP_Transport *SnmpCheckCommSettings(UINT32 snmpProxy, const InetAddress& ipAddr, INT16 *version, UINT16 originalPort, SNMP_SecurityContext *originalContext, StringList *customTestOids);
35f836fe 966void StrToMac(const TCHAR *pszStr, BYTE *pBuffer);
5039dede 967
f42b8099 968void InitLocalNetInfo();
5039dede 969
f42b8099 970ARP_CACHE *GetLocalArpCache();
967893bb 971ARP_CACHE *SnmpGetArpCache(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 972
98762401 973InterfaceList *GetLocalInterfaceList();
5039dede 974
967893bb 975ROUTING_TABLE *SnmpGetRoutingTable(UINT32 dwVersion, SNMP_Transport *pTransport);
5039dede 976
9796ce45 977void LoadNetworkDeviceDrivers();
21254a93 978NetworkDeviceDriver *FindDriverForNode(Node *node, SNMP_Transport *pTransport);
28e1575f 979NetworkDeviceDriver *FindDriverByName(const TCHAR *name);
1f4c37ee 980void AddDriverSpecificOids(StringList *list);
9796ce45 981
5ad2167d 982void WatchdogInit();
967893bb
VK
983UINT32 WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
984void WatchdogNotify(UINT32 dwId);
5039dede
AK
985void WatchdogPrintStatus(CONSOLE_CTX pCtx);
986
5ad2167d 987void CheckForMgmtNode();
de4c3060
VK
988Node NXCORE_EXPORTABLE *PollNewNode(const InetAddress& ipAddr, UINT32 creationFlags, UINT16 agentPort,
989 UINT16 snmpPort, const TCHAR *name, UINT32 agentProxyId, UINT32 snmpProxyId,
990 UINT32 icmpProxyId, UINT32 sshProxyId, const TCHAR *sshLogin, const TCHAR *sshPassword,
991 Cluster *cluster, UINT32 zoneId, bool doConfPoll, bool discoveredNode);
5039dede 992
b1e9b6b3 993void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
967893bb 994void NXCORE_EXPORTABLE NotifyClientSessions(UINT32 dwCode, UINT32 dwData);
6da535d9 995void NXCORE_EXPORTABLE NotifyClientSession(UINT32 sessionId, UINT32 dwCode, UINT32 dwData);
32f372a5 996void NXCORE_EXPORTABLE NotifyClientGraphUpdate(NXCPMessage *update, UINT32 graphId);
64909a13 997int GetSessionCount(bool includeSystemAccount);
967893bb 998bool IsLoggedIn(UINT32 dwUserId);
5d9a9c84 999bool NXCORE_EXPORTABLE KillClientSession(int id);
27858eaa 1000void CloseOtherSessions(UINT32 userId, UINT32 thisSession);
5039dede 1001
35f836fe 1002void GetSysInfoStr(TCHAR *pszBuffer, int nMaxSize);
c30c0c0f 1003InetAddress GetLocalIpAddr();
f7694811 1004TCHAR *GetLocalHostName(TCHAR *buffer, size_t bufSize);
5039dede 1005
b4cf3199
VK
1006InetAddress NXCORE_EXPORTABLE ResolveHostName(UINT32 zoneId, const TCHAR *hostname);
1007
35f836fe 1008BOOL ExecCommand(TCHAR *pszCommand);
967893bb 1009BOOL SendMagicPacket(UINT32 dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
5039dede 1010
35f836fe 1011BOOL InitIdTable();
967893bb 1012UINT32 CreateUniqueId(int iGroup);
35f836fe 1013QWORD CreateUniqueEventId();
69bb7f47 1014void SaveCurrentFreeId();
5039dede 1015
35f836fe
VK
1016void InitMailer();
1017void ShutdownMailer();
1018void NXCORE_EXPORTABLE PostMail(const TCHAR *pszRcpt, const TCHAR *pszSubject, const TCHAR *pszText);
5039dede 1019
35f836fe
VK
1020void InitSMSSender();
1021void ShutdownSMSSender();
1022void NXCORE_EXPORTABLE PostSMS(const TCHAR *pszRcpt, const TCHAR *pszText);
5039dede 1023
35f836fe 1024void InitTraps();
967893bb 1025void SendTrapsToClient(ClientSession *pSession, UINT32 dwRqId);
b368969c 1026void CreateTrapCfgMessage(NXCPMessage &msg);
967893bb
VK
1027UINT32 CreateNewTrap(UINT32 *pdwTrapId);
1028UINT32 CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
b368969c 1029UINT32 UpdateTrapFromMsg(NXCPMessage *pMsg);
967893bb 1030UINT32 DeleteTrap(UINT32 dwId);
25a1e9d0 1031void CreateTrapExportRecord(String &xml, UINT32 id);
967893bb
VK
1032
1033BOOL IsTableTool(UINT32 dwToolId);
1034BOOL CheckObjectToolAccess(UINT32 dwToolId, UINT32 dwUserId);
1035UINT32 ExecuteTableTool(UINT32 dwToolId, Node *pNode, UINT32 dwRqId, ClientSession *pSession);
1036UINT32 DeleteObjectToolFromDB(UINT32 dwToolId);
6f8e39e5 1037UINT32 ChangeObjectToolStatus(UINT32 toolId, bool enabled);
b368969c 1038UINT32 UpdateObjectToolFromMessage(NXCPMessage *pMsg);
4c3cc965 1039void CreateObjectToolExportRecord(String &xml, UINT32 id);
271e3971 1040bool ImportObjectTool(ConfigEntry *config);
b576249a
VK
1041UINT32 GetObjectToolsIntoMessage(NXCPMessage *msg, UINT32 userId, bool fullAccess);
1042UINT32 GetObjectToolDetailsIntoMessage(UINT32 toolId, NXCPMessage *msg);
967893bb 1043
234079c4
VK
1044void ExecuteServerCommand(void *arg);
1045
b368969c 1046UINT32 ModifySummaryTable(NXCPMessage *msg, LONG *newId);
967893bb 1047UINT32 DeleteSummaryTable(LONG tableId);
5389f7b0 1048Table *QuerySummaryTable(LONG tableId, SummaryTable *adHocDefinition, UINT32 baseObjectId, UINT32 userId, UINT32 *rcc);
2096c8f0 1049bool CreateSummaryTableExportRecord(INT32 id, String &xml);
c7a9d87c 1050bool ImportSummaryTable(ConfigEntry *config);
b4c2a628 1051
b368969c 1052void CreateMessageFromSyslogMsg(NXCPMessage *pMsg, NX_SYSLOG_RECORD *pRec);
4262c0dc 1053void ReinitializeSyslogParser();
b8c8a8a7 1054void OnSyslogConfigurationChange(const TCHAR *name, const TCHAR *value);
5039dede
AK
1055
1056void EscapeString(String &str);
1057
ce7565e7 1058void InitAuditLog();
badd6e08 1059void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *subsys, bool isSuccess, UINT32 userId,
2a964810 1060 const TCHAR *workstation, int sessionId, UINT32 objectId,
ce7565e7 1061 const TCHAR *format, ...);
badd6e08
VK
1062void NXCORE_EXPORTABLE WriteAuditLog2(const TCHAR *subsys, bool isSuccess, UINT32 userId,
1063 const TCHAR *workstation, int sessionId, UINT32 objectId,
1064 const TCHAR *format, va_list args);
88f2990c 1065
967893bb
VK
1066bool ValidateConfig(Config *config, UINT32 flags, TCHAR *errorText, int errorTextLen);
1067UINT32 ImportConfig(Config *config, UINT32 flags);
5039dede
AK
1068
1069#ifdef _WITH_ENCRYPTION
b368969c 1070X509 *CertificateFromLoginMessage(NXCPMessage *pMsg);
a50eaebe 1071BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChallenge,
967893bb 1072 BYTE *pSignature, UINT32 dwSigLen, int nMappingMethod,
a50eaebe 1073 const TCHAR *pszMappingData);
9796ce45 1074void ReloadCertificates();
5039dede
AK
1075#endif
1076
1077#ifndef _WIN32
1078THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
1079#endif /* not _WIN32 */
1080
5d3459af
VK
1081void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX console);
1082void DumpClientSessions(CONSOLE_CTX console);
1083void DumpMobileDeviceSessions(CONSOLE_CTX console);
5d3459af
VK
1084void ShowServerStats(CONSOLE_CTX console);
1085void ShowQueueStats(CONSOLE_CTX console, Queue *pQueue, const TCHAR *pszName);
1086void ShowThreadPool(CONSOLE_CTX console, ThreadPool *p);
9f3db00f 1087LONG GetThreadPoolStat(ThreadPoolStat stat, const TCHAR *param, TCHAR *value);
5d3459af 1088void DumpProcess(CONSOLE_CTX console);
5039dede 1089
aed41472 1090#define GRAPH_FLAG_TEMPLATE 1
1091
bd360fd5 1092GRAPH_ACL_ENTRY *LoadGraphACL(DB_HANDLE hdb, UINT32 graphId, int *pnACLSize);
9ad921e5 1093BOOL CheckGraphAccess(GRAPH_ACL_ENTRY *pACL, int nACLSize, UINT32 graphId, UINT32 graphUserId, UINT32 graphDesiredAccess);
fff23fae 1094UINT32 GetGraphAccessCheckResult(UINT32 graphId, UINT32 graphUserId);
9ad921e5 1095GRAPH_ACL_AND_ID IsGraphNameExists(const TCHAR *graphName);
aed41472 1096void FillGraphListMsg(NXCPMessage *msg, UINT32 userId, bool templageGraphs);
1097void SaveGraph(NXCPMessage *pRequest, UINT32 userId, NXCPMessage *msg);
1098UINT32 DeleteGraph(UINT32 graphId, UINT32 userId);
7a4c94ee 1099
d00ad4c6 1100#if XMPP_SUPPORTED
098ef635 1101void SendXMPPMessage(const TCHAR *rcpt, const TCHAR *text);
d00ad4c6 1102#endif
244c65ef 1103
0de31ec3
VK
1104const TCHAR NXCORE_EXPORTABLE *CountryAlphaCode(const TCHAR *code);
1105const TCHAR NXCORE_EXPORTABLE *CountryName(const TCHAR *code);
1106const TCHAR NXCORE_EXPORTABLE *CurrencyAlphaCode(const TCHAR *numericCode);
1107int NXCORE_EXPORTABLE CurrencyExponent(const TCHAR *code);
1108const TCHAR NXCORE_EXPORTABLE *CurrencyName(const TCHAR *code);
1109
4fd0b7ca
VK
1110void NXCORE_EXPORTABLE RegisterComponent(const TCHAR *id);
1111bool NXCORE_EXPORTABLE IsComponentRegistered(const TCHAR *id);
1112
01090206
VK
1113/**
1114 * Housekeeper control
1115 */
1116void StartHouseKeeper();
1117void StopHouseKeeper();
1118void RunHouseKeeper();
1119
a881eafa
VK
1120/**
1121 * Alarm category functions
1122 */
1123void GetAlarmCategories(NXCPMessage *msg);
e30c2442 1124UINT32 UpdateAlarmCategory(const NXCPMessage *request);
a881eafa 1125UINT32 DeleteAlarmCategory(UINT32 id);
e30c2442
VK
1126bool CheckAlarmCategoryAccess(UINT32 userId, UINT32 categoryId);
1127void LoadAlarmCategories();
a881eafa 1128
9fa031cd 1129/**
1130 * File monitoring
1131 */
1132struct MONITORED_FILE
1133{
1134 TCHAR fileName[MAX_PATH];
1135 ClientSession *session;
1136 UINT32 nodeID;
1137};
1138
1139class FileMonitoringList
1140{
1141private:
1142 MUTEX m_mutex;
1143 ObjectArray<MONITORED_FILE> m_monitoredFiles;
9fa031cd 1144
1145public:
1146 FileMonitoringList();
1147 ~FileMonitoringList();
e13420c1 1148 void addMonitoringFile(MONITORED_FILE *fileForAdd, Node *obj, AgentConnection *conn);
e2338033 1149 bool checkDuplicate(MONITORED_FILE *fileForAdd);
1150 ObjectArray<ClientSession>* findClientByFNameAndNodeID(const TCHAR *fileName, UINT32 nodeID);
9fa031cd 1151 bool removeMonitoringFile(MONITORED_FILE *fileForRemove);
f9f79a93 1152 void removeDisconnectedNode(UINT32 nodeId);
9fa031cd 1153
1154private:
1155 void lock();
1156 void unlock();
1157};
1158
534e1b83
VK
1159/**
1160 * Global variables
1161 */
5039dede
AK
1162extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
1163extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
458b5d2b
VK
1164extern UINT32 g_logRotationMode;
1165extern UINT64 g_maxLogSize;
1166extern UINT32 g_logHistorySize;
4f8998ca 1167extern TCHAR g_szDailyLogFileSuffix[64];
5039dede
AK
1168extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
1169extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
1170#ifndef _WIN32
1171extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
1172#endif
db6a6b45
VK
1173extern TCHAR NXCORE_EXPORTABLE g_netxmsdDataDir[];
1174extern TCHAR NXCORE_EXPORTABLE g_netxmsdLibDir[];
967893bb 1175extern UINT32 NXCORE_EXPORTABLE g_processAffinityMask;
e9902466 1176extern UINT64 g_serverId;
5039dede 1177extern RSA *g_pServerKey;
c59466d2
VK
1178extern UINT32 g_icmpPingSize;
1179extern UINT32 g_icmpPingTimeout;
1180extern UINT32 g_auditFlags;
1181extern time_t g_serverStartTime;
1182extern UINT32 g_lockTimeout;
1183extern UINT32 g_agentCommandTimeout;
1184extern UINT32 g_thresholdRepeatInterval;
1185extern int g_requiredPolls;
1186extern UINT32 g_slmPollingInterval;
f6456d80 1187extern UINT32 g_offlineDataRelevanceTime;
5039dede 1188
b8c1ec69
VK
1189extern TCHAR g_szDbDriver[];
1190extern TCHAR g_szDbDrvParams[];
1191extern TCHAR g_szDbServer[];
1192extern TCHAR g_szDbLogin[];
1193extern TCHAR g_szDbPassword[];
1194extern TCHAR g_szDbName[];
f3c30cf5 1195extern TCHAR g_szDbSchema[];
b8c1ec69 1196extern DB_DRIVER g_dbDriver;
76fcb995
VK
1197extern Queue *g_dbWriterQueue;
1198extern Queue *g_dciDataWriterQueue;
1199extern Queue *g_dciRawDataWriterQueue;
6547a540
VK
1200extern UINT64 g_idataWriteRequests;
1201extern UINT64 g_rawDataWriteRequests;
1202extern UINT64 g_otherWriteRequests;
5039dede 1203
2a964810 1204extern int NXCORE_EXPORTABLE g_dbSyntax;
9fa031cd 1205extern FileMonitoringList g_monitoringList;
5039dede 1206
1ef6170e 1207extern ThreadPool NXCORE_EXPORTABLE *g_mainThreadPool;
5d3459af 1208
5039dede 1209#endif /* _nms_core_h_ */