Added request for service status to AgentConnection class
[public/netxms.git] / src / server / include / nxsrvapi.h
CommitLineData
df33b6f7
VK
1/*
2** NetXMS - Network Management System
3** Server Library
4** Copyright (C) 2003, 2004 Victor Kirhenshtein
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
20** $module: nxsrvapi.h
21**
22**/
23
24#ifndef _nxsrvapi_h_
25#define _nxsrvapi_h_
26
27#ifdef _WIN32
28#ifdef LIBNXSRV_EXPORTS
29#define LIBNXSRV_EXPORTABLE __declspec(dllexport)
30#else
31#define LIBNXSRV_EXPORTABLE __declspec(dllimport)
32#endif
33#else /* _WIN32 */
34#define LIBNXSRV_EXPORTABLE
35#endif
36
37#ifndef LIBNXCL_NO_DECLARATIONS
38#define LIBNXCL_NO_DECLARATIONS 1
39#endif
40#include <nxclapi.h>
6c426e3a 41#include <nxcscpapi.h>
df33b6f7 42#include <nms_agent.h>
b8191466 43#include <rwlock.h>
9cc9ea72 44#include <messages.h>
9bb31635 45#include <dbdrv.h>
9cc9ea72
VK
46
47
fc935a60
VK
48//
49// Default files
50//
51
52#ifdef _WIN32
53#define DEFAULT_CONFIG_FILE _T("C:\\NetXMS.conf")
54#else
55#define DEFAULT_CONFIG_FILE _T("/etc/netxmsd.conf")
56#endif
57
58
9cc9ea72
VK
59//
60// DB-related constants
61//
62
63#define MAX_DB_LOGIN 64
64#define MAX_DB_PASSWORD 64
65#define MAX_DB_NAME 32
66
67
68//
69// Win32 service constants
70//
71
72#ifdef _WIN32
73
74#define CORE_SERVICE_NAME _T("NetXMSCore")
75#define CORE_EVENT_SOURCE _T("NetXMSCore")
76
77#endif /* _WIN32 */
df33b6f7
VK
78
79
80//
81// Single ARP cache entry
82//
83
84typedef struct
85{
86 DWORD dwIndex; // Interface index
87 DWORD dwIpAddr;
b50f1100 88 BYTE bMacAddr[MAC_ADDR_LENGTH];
df33b6f7
VK
89} ARP_ENTRY;
90
91
92//
93// ARP cache structure used by discovery functions and AgentConnection class
94//
95
96typedef struct
97{
98 DWORD dwNumEntries;
99 ARP_ENTRY *pEntries;
100} ARP_CACHE;
101
102
103//
104// Interface information structure used by discovery functions and AgentConnection class
105//
106
107typedef struct
108{
268774a0 109 TCHAR szName[MAX_OBJECT_NAME];
df33b6f7
VK
110 DWORD dwIndex;
111 DWORD dwType;
112 DWORD dwIpAddr;
113 DWORD dwIpNetMask;
b50f1100 114 BYTE bMacAddr[MAC_ADDR_LENGTH];
df33b6f7
VK
115 int iNumSecondary; // Number of secondary IP's on this interface
116} INTERFACE_INFO;
117
118
119//
120// Interface list used by discovery functions and AgentConnection class
121//
122
123typedef struct
124{
125 int iNumEntries; // Number of entries in pInterfaces
126 int iEnumPos; // Used by index enumeration handler
18e26ff8 127 void *pArg; // Can be used by custom enumeration handlers
df33b6f7
VK
128 INTERFACE_INFO *pInterfaces; // Interface entries
129} INTERFACE_LIST;
130
131
132//
133// Agent connection
134//
135
136class LIBNXSRV_EXPORTABLE AgentConnection
137{
df33b6f7
VK
138private:
139 DWORD m_dwAddr;
140 int m_iAuthMethod;
141 char m_szSecret[MAX_SECRET_LENGTH];
142 time_t m_tLastCommandTime;
143 SOCKET m_hSocket;
144 WORD m_wPort;
145 DWORD m_dwNumDataLines;
6c426e3a
VK
146 DWORD m_dwRequestId;
147 DWORD m_dwCommandTimeout;
268774a0 148 TCHAR **m_ppDataLines;
6c426e3a 149 MsgWaitQueue *m_pMsgWaitQueue;
1c62be36 150 BOOL m_bIsConnected;
38e832d6 151 MUTEX m_mutexDataLock;
ccdbbb52 152 THREAD m_hReceiverThread;
df33b6f7
VK
153
154 void ReceiverThread(void);
ccdbbb52 155 static THREAD_RESULT THREAD_CALL ReceiverThreadStarter(void *);
df33b6f7
VK
156
157protected:
158 void DestroyResultData(void);
6c426e3a
VK
159 BOOL SendMessage(CSCPMessage *pMsg);
160 CSCPMessage *WaitForMessage(WORD wCode, DWORD dwId, DWORD dwTimeOut) { return m_pMsgWaitQueue->WaitForMessage(wCode, dwId, dwTimeOut); }
161 DWORD WaitForRCC(DWORD dwRqId, DWORD dwTimeOut);
d1d0b3be 162 DWORD Authenticate(void);
df33b6f7 163
268774a0 164 virtual void PrintMsg(TCHAR *pszFormat, ...);
901c96c7 165 virtual void OnTrap(CSCPMessage *pMsg);
df33b6f7 166
38e832d6
VK
167 void Lock(void) { MutexLock(m_mutexDataLock, INFINITE); }
168 void Unlock(void) { MutexUnlock(m_mutexDataLock); }
1c62be36 169
df33b6f7
VK
170public:
171 AgentConnection();
268774a0 172 AgentConnection(DWORD dwAddr, WORD wPort = AGENT_LISTEN_PORT, int iAuthMethod = AUTH_NONE, TCHAR *szSecret = NULL);
df33b6f7
VK
173 ~AgentConnection();
174
175 BOOL Connect(BOOL bVerbose = FALSE);
176 void Disconnect(void);
1c62be36 177 BOOL IsConnected(void) { return m_bIsConnected; }
df33b6f7
VK
178
179 ARP_CACHE *GetArpCache(void);
180 INTERFACE_LIST *GetInterfaceList(void);
268774a0
VK
181 DWORD GetParameter(TCHAR *pszParam, DWORD dwBufSize, TCHAR *pszBuffer);
182 DWORD GetList(TCHAR *pszParam);
df33b6f7 183 DWORD Nop(void);
268774a0 184 DWORD ExecAction(TCHAR *pszAction, int argc, TCHAR **argv);
d096bcdd 185 DWORD UploadFile(TCHAR *pszFile);
e925a5fc 186 DWORD StartUpgrade(TCHAR *pszPkgName);
3f0ca036
VK
187 DWORD CheckNetworkService(DWORD *pdwStatus, DWORD dwIpAddr, int iServiceType, WORD wPort = 0,
188 WORD wProto = 0, TCHAR *pszRequest = NULL, TCHAR *pszResponce = NULL);
901c96c7
VK
189
190 DWORD GetNumDataLines(void) { return m_dwNumDataLines; }
268774a0 191 const TCHAR *GetDataLine(DWORD dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); }
962b3915
VK
192
193 void SetCommandTimeout(DWORD dwTimeout) { if (dwTimeout > 500) m_dwCommandTimeout = dwTimeout; }
df33b6f7
VK
194};
195
196
197//
198// Functions
199//
200
201void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache);
202void LIBNXSRV_EXPORTABLE DestroyInterfaceList(INTERFACE_LIST *pIfList);
268774a0 203const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(int iError);
df33b6f7 204
9cc9ea72
VK
205void LIBNXSRV_EXPORTABLE InitLog(BOOL bUseSystemLog, char *pszLogFile, BOOL bPrintToScreen);
206void LIBNXSRV_EXPORTABLE CloseLog(void);
207void LIBNXSRV_EXPORTABLE WriteLog(DWORD msg, WORD wType, char *format, ...);
208
209BOOL LIBNXSRV_EXPORTABLE DBInit(BOOL bWriteLog, BOOL bLogErrors);
210DB_HANDLE LIBNXSRV_EXPORTABLE DBConnect(void);
211void LIBNXSRV_EXPORTABLE DBDisconnect(DB_HANDLE hConn);
212BOOL LIBNXSRV_EXPORTABLE DBQuery(DB_HANDLE hConn, char *szQuery);
213DB_RESULT LIBNXSRV_EXPORTABLE DBSelect(DB_HANDLE hConn, char *szQuery);
214DB_ASYNC_RESULT LIBNXSRV_EXPORTABLE DBAsyncSelect(DB_HANDLE hConn, char *szQuery);
215BOOL LIBNXSRV_EXPORTABLE DBFetch(DB_ASYNC_RESULT hResult);
216char LIBNXSRV_EXPORTABLE *DBGetField(DB_RESULT hResult, int iRow, int iColumn);
217long LIBNXSRV_EXPORTABLE DBGetFieldLong(DB_RESULT hResult, int iRow, int iColumn);
218DWORD LIBNXSRV_EXPORTABLE DBGetFieldULong(DB_RESULT hResult, int iRow, int iColumn);
0c6014e4
VK
219INT64 LIBNXSRV_EXPORTABLE DBGetFieldInt64(DB_RESULT hResult, int iRow, int iColumn);
220QWORD LIBNXSRV_EXPORTABLE DBGetFieldUInt64(DB_RESULT hResult, int iRow, int iColumn);
9cc9ea72
VK
221double LIBNXSRV_EXPORTABLE DBGetFieldDouble(DB_RESULT hResult, int iRow, int iColumn);
222DWORD LIBNXSRV_EXPORTABLE DBGetFieldIPAddr(DB_RESULT hResult, int iRow, int iColumn);
223char LIBNXSRV_EXPORTABLE *DBGetFieldAsync(DB_ASYNC_RESULT hResult, int iColumn, char *pBuffer, int iBufSize);
224long LIBNXSRV_EXPORTABLE DBGetFieldAsyncLong(DB_RESULT hResult, int iColumn);
225DWORD LIBNXSRV_EXPORTABLE DBGetFieldAsyncULong(DB_ASYNC_RESULT hResult, int iColumn);
0c6014e4
VK
226INT64 LIBNXSRV_EXPORTABLE DBGetFieldAsyncInt64(DB_RESULT hResult, int iColumn);
227QWORD LIBNXSRV_EXPORTABLE DBGetFieldAsyncUInt64(DB_ASYNC_RESULT hResult, int iColumn);
9cc9ea72
VK
228double LIBNXSRV_EXPORTABLE DBGetFieldAsyncDouble(DB_RESULT hResult, int iColumn);
229DWORD LIBNXSRV_EXPORTABLE DBGetFieldAsyncIPAddr(DB_RESULT hResult, int iColumn);
230int LIBNXSRV_EXPORTABLE DBGetNumRows(DB_RESULT hResult);
231void LIBNXSRV_EXPORTABLE DBFreeResult(DB_RESULT hResult);
232void LIBNXSRV_EXPORTABLE DBFreeAsyncResult(DB_ASYNC_RESULT hResult);
233void LIBNXSRV_EXPORTABLE DBUnloadDriver(void);
234
235
236//
237// Variables
238//
239
240extern char LIBNXSRV_EXPORTABLE g_szDbDriver[];
241extern char LIBNXSRV_EXPORTABLE g_szDbDriver[];
242extern char LIBNXSRV_EXPORTABLE g_szDbDrvParams[];
243extern char LIBNXSRV_EXPORTABLE g_szDbServer[];
244extern char LIBNXSRV_EXPORTABLE g_szDbLogin[];
245extern char LIBNXSRV_EXPORTABLE g_szDbPassword[];
246extern char LIBNXSRV_EXPORTABLE g_szDbName[];
df33b6f7
VK
247
248#endif /* _nxsrvapi_h_ */