-rw-r--r-- | KLogDlg.cpp | 1367 |
1 files changed, 1367 insertions, 0 deletions
diff --git a/KLogDlg.cpp b/KLogDlg.cpp new file mode 100644 index 0000000..5f1c6c0 --- a/dev/null +++ b/KLogDlg.cpp | |||
@@ -0,0 +1,1367 @@ | |||
1 | // KLogDlg.cpp : implementation file | ||
2 | // | ||
3 | |||
4 | #include "stdafx.h" | ||
5 | #include "KLog.h" | ||
6 | #include "SyslogSocket.h" | ||
7 | #include "KLogDlg.h" | ||
8 | |||
9 | #include "Trayer.h" | ||
10 | #include "LogPattern.h" | ||
11 | #include "WarnBlocking.h" | ||
12 | |||
13 | #ifdef _DEBUG | ||
14 | #define new DEBUG_NEW | ||
15 | #undef THIS_FILE | ||
16 | static char THIS_FILE[] = __FILE__; | ||
17 | #endif | ||
18 | |||
19 | IMPLEMENT_SERIAL( CKLogDlg, CDialog, VERSIONABLE_SCHEMA|1 ); | ||
20 | IMPLEMENT_SERIAL( CLogger, CObject, VERSIONABLE_SCHEMA|1 ); | ||
21 | IMPLEMENT_SERIAL( CLogEntry, CObject, VERSIONABLE_SCHEMA|1 ); | ||
22 | IMPLEMENT_SERIAL( CHostMask, CObject, VERSIONABLE_SCHEMA|1 ); | ||
23 | |||
24 | ///////////////////////////////////////////////////////////////////////////// | ||
25 | // CAboutDlg dialog used for App About | ||
26 | |||
27 | class CAboutDlg : public CDialog | ||
28 | { | ||
29 | public: | ||
30 | CAboutDlg(); | ||
31 | |||
32 | // Dialog Data | ||
33 | //{{AFX_DATA(CAboutDlg) | ||
34 | enum { IDD = IDD_ABOUTBOX }; | ||
35 | //}}AFX_DATA | ||
36 | |||
37 | // ClassWizard generated virtual function overrides | ||
38 | //{{AFX_VIRTUAL(CAboutDlg) | ||
39 | protected: | ||
40 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support | ||
41 | //}}AFX_VIRTUAL | ||
42 | |||
43 | // Implementation | ||
44 | protected: | ||
45 | //{{AFX_MSG(CAboutDlg) | ||
46 | afx_msg void OnKlevernet(); | ||
47 | //}}AFX_MSG | ||
48 | DECLARE_MESSAGE_MAP() | ||
49 | }; | ||
50 | |||
51 | CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) | ||
52 | { | ||
53 | //{{AFX_DATA_INIT(CAboutDlg) | ||
54 | //}}AFX_DATA_INIT | ||
55 | } | ||
56 | |||
57 | void CAboutDlg::DoDataExchange(CDataExchange* pDX) | ||
58 | { | ||
59 | CDialog::DoDataExchange(pDX); | ||
60 | //{{AFX_DATA_MAP(CAboutDlg) | ||
61 | //}}AFX_DATA_MAP | ||
62 | } | ||
63 | |||
64 | BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) | ||
65 | //{{AFX_MSG_MAP(CAboutDlg) | ||
66 | ON_BN_CLICKED(IDC_KLEVERNET, OnKlevernet) | ||
67 | //}}AFX_MSG_MAP | ||
68 | END_MESSAGE_MAP() | ||
69 | |||
70 | ///////////////////////////////////////////////////////////////////////////// | ||
71 | // CKLogDlg dialog | ||
72 | |||
73 | CKLogDlg::CKLogDlg(CWnd* pParent /*=NULL*/) | ||
74 | : CDialog(CKLogDlg::IDD, pParent) | ||
75 | { | ||
76 | m_Logger=NULL; | ||
77 | m_LogItems=15; | ||
78 | m_bShown=TRUE; | ||
79 | m_bExiting=FALSE; | ||
80 | m_bWarnBlocking=TRUE; | ||
81 | m_bDontWarn=TRUE; | ||
82 | //{{AFX_DATA_INIT(CKLogDlg) | ||
83 | m_Logto = -1; | ||
84 | m_Desc = _T(""); | ||
85 | m_Facility = _T(""); | ||
86 | m_HFName = _T(""); | ||
87 | m_HFNameCaption = _T(""); | ||
88 | m_hlIP = _T(""); | ||
89 | m_hlMask = _T(""); | ||
90 | m_Sound = _T(""); | ||
91 | //}}AFX_DATA_INIT | ||
92 | // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 | ||
93 | m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); | ||
94 | m_bmpBack.LoadBitmap(IDB_BACKGROUND); | ||
95 | m_bmpBack.GetBitmap(&m_bitmapBack); | ||
96 | m_Trayer = new CTrayer(this); | ||
97 | ASSERT(m_Trayer); | ||
98 | LoadSettings(); | ||
99 | } | ||
100 | |||
101 | void CKLogDlg::DoDataExchange(CDataExchange* pDX) | ||
102 | { | ||
103 | CDialog::DoDataExchange(pDX); | ||
104 | //{{AFX_DATA_MAP(CKLogDlg) | ||
105 | DDX_Control(pDX, IDC_LOGPATTERN, m_LogPatternCtl); | ||
106 | DDX_Control(pDX, IDC_FILES, m_FilesCtl); | ||
107 | DDX_Control(pDX, IDC_LOGLENSPIN, m_LogLenSpinCtl); | ||
108 | DDX_Control(pDX, IDC_LOGLENGTH, m_LogLengthCtl); | ||
109 | DDX_Control(pDX, IDC_INVERT, m_PriInvertCtl); | ||
110 | DDX_Control(pDX, IDC_TYPE_FILE, m_LogtoFileCtl); | ||
111 | DDX_Control(pDX, IDC_TYPE_HOST, m_LogtoHostCtl); | ||
112 | DDX_Control(pDX, IDC_TYPE_NONE, m_LogtoNoneCtl); | ||
113 | DDX_Control(pDX, IDC_HOSTORFILE, m_HFNameCaptionCtl); | ||
114 | DDX_Control(pDX, IDC_HOSTS, m_hlCtl); | ||
115 | DDX_Control(pDX, IDC_BROWSESOUND, m_BrowseSoundCtl); | ||
116 | DDX_Control(pDX, IDC_NONE, m_PriNoneCtl); | ||
117 | DDX_Control(pDX, IDC_HL_REMOVE, m_hlRemoveCtl); | ||
118 | DDX_Control(pDX, IDC_HL_MASK, m_hlMaskCtl); | ||
119 | DDX_Control(pDX, IDC_HL_IP, m_hlIPCtl); | ||
120 | DDX_Control(pDX, IDC_HL_ADD, m_hlAddCtl); | ||
121 | DDX_Control(pDX, IDC_ALL, m_PriAllCtl); | ||
122 | DDX_Control(pDX, IDC_SOUND, m_SoundCtl); | ||
123 | DDX_Control(pDX, IDC_REMOVE, m_RemoveCtl); | ||
124 | DDX_Control(pDX, IDC_PLAYSOUND, m_PlaySoundCtl); | ||
125 | DDX_Control(pDX, IDC_LOG, m_Log); | ||
126 | DDX_Control(pDX, IDC_HOSTFILE, m_HFNameCtl); | ||
127 | DDX_Control(pDX, IDC_FACILITY, m_FacilityCtl); | ||
128 | DDX_Control(pDX, IDC_BROWSE, m_BrowseCtl); | ||
129 | DDX_Control(pDX, IDC_DESC, m_DescCtl); | ||
130 | DDX_Control(pDX, IDC_TABS, m_Tabs); | ||
131 | DDX_Radio(pDX, IDC_TYPE_FILE, m_Logto); | ||
132 | DDX_Text(pDX, IDC_DESC, m_Desc); | ||
133 | DDV_MaxChars(pDX, m_Desc, 50); | ||
134 | DDX_CBString(pDX, IDC_FACILITY, m_Facility); | ||
135 | DDX_Text(pDX, IDC_HOSTFILE, m_HFName); | ||
136 | DDX_Text(pDX, IDC_HOSTORFILE, m_HFNameCaption); | ||
137 | DDX_Text(pDX, IDC_HL_IP, m_hlIP); | ||
138 | DDV_MaxChars(pDX, m_hlIP, 15); | ||
139 | DDX_Text(pDX, IDC_HL_MASK, m_hlMask); | ||
140 | DDV_MaxChars(pDX, m_hlMask, 15); | ||
141 | DDX_CBString(pDX, IDC_SOUND, m_Sound); | ||
142 | //}}AFX_DATA_MAP | ||
143 | } | ||
144 | |||
145 | BEGIN_MESSAGE_MAP(CKLogDlg, CDialog) | ||
146 | //{{AFX_MSG_MAP(CKLogDlg) | ||
147 | ON_WM_SYSCOMMAND() | ||
148 | ON_WM_DESTROY() | ||
149 | ON_WM_PAINT() | ||
150 | ON_WM_QUERYDRAGICON() | ||
151 | ON_BN_CLICKED(IDC_ADD, OnAdd) | ||
152 | ON_NOTIFY(TCN_SELCHANGE, IDC_TABS, OnSelchangeTabs) | ||
153 | ON_CBN_SELCHANGE(IDC_FACILITY, OnSelchangeFacility) | ||
154 | ON_BN_CLICKED(IDC_ALERT, OnPriority) | ||
155 | ON_BN_CLICKED(IDC_TYPE_FILE, OnLogto) | ||
156 | ON_BN_CLICKED(IDC_ALL, OnPriAll) | ||
157 | ON_BN_CLICKED(IDC_NONE, OnPriNone) | ||
158 | ON_EN_CHANGE(IDC_DESC, OnChangeDesc) | ||
159 | ON_BN_CLICKED(IDC_INVERT, OnPriInvert) | ||
160 | ON_BN_CLICKED(IDC_HL_ADD, OnHlAdd) | ||
161 | ON_LBN_SELCHANGE(IDC_HOSTS, OnSelchangeHosts) | ||
162 | ON_BN_CLICKED(IDC_HL_REMOVE, OnHlRemove) | ||
163 | ON_BN_CLICKED(IDC_REMOVE, OnRemove) | ||
164 | ON_BN_CLICKED(IDC_PLAYSOUND, OnPlaysound) | ||
165 | ON_CBN_EDITCHANGE(IDC_SOUND, OnEditchangeSound) | ||
166 | ON_CBN_KILLFOCUS(IDC_SOUND, OnKillfocusSound) | ||
167 | ON_NOTIFY(UDN_DELTAPOS, IDC_LOGLENSPIN, OnDeltaposLoglenspin) | ||
168 | ON_BN_CLICKED(IDC_EXIT, OnExit) | ||
169 | ON_BN_CLICKED(IDC_FILES, OnFiles) | ||
170 | ON_COMMAND(ID_FILES_EXPORT, OnFilesExport) | ||
171 | ON_COMMAND(ID_FILES_IMPORT, OnFilesImport) | ||
172 | ON_BN_CLICKED(IDC_BROWSESOUND, OnBrowsesound) | ||
173 | ON_EN_KILLFOCUS(IDC_HOSTFILE, OnKillfocusHostfile) | ||
174 | ON_BN_CLICKED(IDC_BROWSE, OnBrowse) | ||
175 | ON_COMMAND(ID_FILES_RESET, OnFilesReset) | ||
176 | ON_LBN_SELCHANGE(IDC_LOG, OnSelchangeLog) | ||
177 | ON_WM_CREATE() | ||
178 | ON_WM_CLOSE() | ||
179 | ON_COMMAND(ID_TRAY_ABOUTKLOG, OnTrayAboutklog) | ||
180 | ON_COMMAND(ID_TRAY_EXIT, OnTrayExit) | ||
181 | ON_COMMAND(ID_TRAY_SHOWKLOGWINDOW, OnTrayShowklogwindow) | ||
182 | ON_WM_WINDOWPOSCHANGING() | ||
183 | ON_BN_CLICKED(IDC_LOGPATTERN, OnLogpattern) | ||
184 | ON_BN_CLICKED(IDC_CRIT, OnPriority) | ||
185 | ON_BN_CLICKED(IDC_DEBUG, OnPriority) | ||
186 | ON_BN_CLICKED(IDC_EMERG, OnPriority) | ||
187 | ON_BN_CLICKED(IDC_ERR, OnPriority) | ||
188 | ON_BN_CLICKED(IDC_INFO, OnPriority) | ||
189 | ON_BN_CLICKED(IDC_NOTICE, OnPriority) | ||
190 | ON_BN_CLICKED(IDC_WARNING, OnPriority) | ||
191 | ON_BN_CLICKED(IDC_TYPE_HOST, OnLogto) | ||
192 | ON_BN_CLICKED(IDC_TYPE_NONE, OnLogto) | ||
193 | //}}AFX_MSG_MAP | ||
194 | END_MESSAGE_MAP() | ||
195 | |||
196 | ///////////////////////////////////////////////////////////////////////////// | ||
197 | // CKLogDlg message handlers | ||
198 | |||
199 | BOOL CKLogDlg::OnInitDialog() | ||
200 | { | ||
201 | CDialog::OnInitDialog(); | ||
202 | |||
203 | // Add "About..." menu item to system menu. | ||
204 | |||
205 | // IDM_ABOUTBOX must be in the system command range. | ||
206 | ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); | ||
207 | ASSERT(IDM_ABOUTBOX < 0xF000); | ||
208 | |||
209 | CMenu* pSysMenu = GetSystemMenu(FALSE); | ||
210 | CString strAboutMenu; | ||
211 | strAboutMenu.LoadString(IDS_ABOUTBOX); | ||
212 | if (!strAboutMenu.IsEmpty()) | ||
213 | { | ||
214 | pSysMenu->AppendMenu(MF_SEPARATOR); | ||
215 | pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); | ||
216 | } | ||
217 | |||
218 | // Set the icon for this dialog. The framework does this automatically | ||
219 | // when the application's main window is not a dialog | ||
220 | SetIcon(m_hIcon, TRUE); // Set big icon | ||
221 | SetIcon(m_hIcon, FALSE); // Set small icon | ||
222 | |||
223 | m_KLS.m_Daddy=this; | ||
224 | VERIFY(m_KLS.CreateListen()); | ||
225 | m_SLS.Create(0,SOCK_DGRAM); | ||
226 | |||
227 | m_LogLenSpinCtl.SetRange(5,50); | ||
228 | UpdateLogLength(FALSE,FALSE); | ||
229 | |||
230 | // Adjust Tab control rectangle size and padding | ||
231 | CRect rbrc,tcrc; | ||
232 | m_DescCtl.GetWindowRect(&rbrc); | ||
233 | m_Tabs.GetClientRect(&tcrc); | ||
234 | m_Tabs.ClientToScreen(&tcrc); | ||
235 | m_Tabs.SetItemSize(CSize(0,rbrc.top-tcrc.top-4)); | ||
236 | m_Tabs.SetPadding(CSize(5,5)); | ||
237 | |||
238 | // Load Image List | ||
239 | m_Images.Create(16,16,TRUE,2,1); | ||
240 | m_iNormal=m_Images.Add(AfxGetApp()->LoadIcon(IDI_KLOG)); | ||
241 | m_iTriggered=m_Images.Add(AfxGetApp()->LoadIcon(IDI_KLOG_TRIGGERED)); | ||
242 | m_Tabs.SetImageList(&m_Images); | ||
243 | |||
244 | // Set Icons | ||
245 | m_BrowseSoundCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_BROWSE)); | ||
246 | m_PlaySoundCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_PREPLAY)); | ||
247 | m_LogPatternCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_LOGPATTERN)); | ||
248 | |||
249 | // Create ToolTip Control | ||
250 | m_tooltip.Create(this); | ||
251 | m_tooltip.Activate(TRUE); | ||
252 | |||
253 | // Restore Layout | ||
254 | OnFilesReset(); | ||
255 | |||
256 | SetWindowPos(NULL,6,6,0,0,SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE); | ||
257 | |||
258 | if(m_bShown) | ||
259 | ShowWindow(SW_SHOW); | ||
260 | else | ||
261 | ShowWindow(SW_HIDE); | ||
262 | |||
263 | // Add Tips captions | ||
264 | m_tooltip.AddTool(GetDlgItem(IDC_ADD),IDC_ADD); | ||
265 | m_tooltip.AddTool(&m_RemoveCtl,IDC_REMOVE); | ||
266 | m_tooltip.AddTool(&m_LogLengthCtl,IDC_LOGLENGTH); | ||
267 | m_tooltip.AddTool(&m_LogLenSpinCtl,IDC_LOGLENGTH); | ||
268 | m_tooltip.AddTool(GetDlgItem(IDC_STATIC_LOGLENGTH),IDC_LOGLENGTH); | ||
269 | m_tooltip.AddTool(GetDlgItem(IDC_FILES),IDC_FILES); | ||
270 | m_tooltip.AddTool(GetDlgItem(IDC_EXIT),IDC_EXIT); | ||
271 | m_tooltip.AddTool(&m_LogtoFileCtl,IDC_TYPE_FILE); | ||
272 | m_tooltip.AddTool(&m_LogtoHostCtl,IDC_TYPE_HOST); | ||
273 | m_tooltip.AddTool(&m_LogtoNoneCtl,IDC_TYPE_NONE); | ||
274 | m_tooltip.AddTool(&m_hlCtl,IDC_HOSTS); | ||
275 | m_tooltip.AddTool(&m_Log,IDC_LOG); | ||
276 | m_tooltip.AddTool(&m_LogPatternCtl,IDC_LOGPATTERN); | ||
277 | |||
278 | return TRUE; // return TRUE unless you set the focus to a control | ||
279 | } | ||
280 | |||
281 | void CKLogDlg::OnSysCommand(UINT nID, LPARAM lParam) | ||
282 | { | ||
283 | switch(nID&0xFFF0){ | ||
284 | case IDM_ABOUTBOX: | ||
285 | { | ||
286 | OnTrayAboutklog(); | ||
287 | } | ||
288 | break; | ||
289 | case SC_CONTEXTHELP: | ||
290 | AfxGetApp()->WinHelp(0,HELP_FINDER); | ||
291 | break; | ||
292 | default: | ||
293 | CDialog::OnSysCommand(nID, lParam); | ||
294 | break; | ||
295 | } | ||
296 | } | ||
297 | |||
298 | void CKLogDlg::OnDestroy() | ||
299 | { | ||
300 | NOTIFYICONDATA nid; | ||
301 | memset(&nid,0,sizeof(nid)); | ||
302 | nid.cbSize=sizeof(nid); | ||
303 | nid.hWnd=m_Trayer->m_hWnd; | ||
304 | nid.uID=IDC_TRAYICON; | ||
305 | nid.uFlags=0; | ||
306 | VERIFY(Shell_NotifyIcon(NIM_DELETE,&nid)); | ||
307 | |||
308 | WinHelp(0L, HELP_QUIT); | ||
309 | CDialog::OnDestroy(); | ||
310 | } | ||
311 | |||
312 | // If you add a minimize button to your dialog, you will need the code below | ||
313 | // to draw the icon. For MFC applications using the document/view model, | ||
314 | // this is automatically done for you by the framework. | ||
315 | |||
316 | void CKLogDlg::OnPaint() | ||
317 | { | ||
318 | if (IsIconic()) | ||
319 | { | ||
320 | CPaintDC dc(this); // device context for painting | ||
321 | |||
322 | SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); | ||
323 | |||
324 | // Center icon in client rectangle | ||
325 | int cxIcon = GetSystemMetrics(SM_CXICON); | ||
326 | int cyIcon = GetSystemMetrics(SM_CYICON); | ||
327 | CRect rect; | ||
328 | GetClientRect(&rect); | ||
329 | int x = (rect.Width() - cxIcon + 1) / 2; | ||
330 | int y = (rect.Height() - cyIcon + 1) / 2; | ||
331 | |||
332 | // Draw the icon | ||
333 | dc.DrawIcon(x, y, m_hIcon); | ||
334 | } | ||
335 | else | ||
336 | { | ||
337 | CPaintDC pDC(this); | ||
338 | CDC bmpDC; | ||
339 | bmpDC.CreateCompatibleDC(&pDC); | ||
340 | bmpDC.SelectObject(&m_bmpBack); | ||
341 | CRect rc; | ||
342 | GetClientRect(&rc); | ||
343 | for(int x=-m_bitmapBack.bmWidth*2/4;x<rc.Width();x+=m_bitmapBack.bmWidth) | ||
344 | for(int y=-m_bitmapBack.bmHeight*2/4;y<rc.Height();y+=m_bitmapBack.bmHeight) | ||
345 | pDC.BitBlt(x,y,m_bitmapBack.bmWidth,m_bitmapBack.bmHeight,&bmpDC,0,0,SRCCOPY); | ||
346 | bmpDC.DeleteDC(); | ||
347 | CDialog::OnPaint(); | ||
348 | } | ||
349 | } | ||
350 | |||
351 | // The system calls this to obtain the cursor to display while the user drags | ||
352 | // the minimized window. | ||
353 | HCURSOR CKLogDlg::OnQueryDragIcon() | ||
354 | { | ||
355 | return (HCURSOR) m_hIcon; | ||
356 | } | ||
357 | |||
358 | void CKLogDlg::OnAdd() | ||
359 | { | ||
360 | CLogger *l = new CLogger(m_Tabs.GetItemCount()?FALSE:TRUE); | ||
361 | ASSERT(l); | ||
362 | m_Logs[l]=l; | ||
363 | TC_ITEM ptc; | ||
364 | memset(&ptc,0,sizeof(ptc)); | ||
365 | ptc.mask=TCIF_TEXT|TCIF_IMAGE|TCIF_PARAM; | ||
366 | ptc.pszText=(LPTSTR)(LPCTSTR)l->m_Desc; | ||
367 | ptc.iImage=m_iNormal; | ||
368 | ptc.lParam=(LPARAM)l; | ||
369 | int tmp=m_Tabs.InsertItem(m_Tabs.GetItemCount(),&ptc); | ||
370 | m_Tabs.SetCurSel(tmp); | ||
371 | SetTab(l); | ||
372 | m_RemoveCtl.EnableWindow(m_Tabs.GetItemCount()>1); | ||
373 | } | ||
374 | |||
375 | void CKLogDlg::OnSelchangeTabs(NMHDR* pNMHDR, LRESULT* pResult) | ||
376 | { | ||
377 | int cs = m_Tabs.GetCurSel(); | ||
378 | ASSERT(cs>=0); | ||
379 | TC_ITEM ptci; | ||
380 | memset(&ptci,0,sizeof(ptci)); | ||
381 | ptci.mask=TCIF_PARAM; | ||
382 | VERIFY(m_Tabs.GetItem(cs,&ptci)); | ||
383 | CLogger *l = (CLogger*)ptci.lParam; | ||
384 | memset(&ptci,0,sizeof(ptci)); | ||
385 | ptci.mask=TCIF_IMAGE; | ||
386 | ptci.iImage=m_iNormal; | ||
387 | VERIFY(m_Tabs.SetItem(cs,&ptci)); | ||
388 | ASSERT(l); | ||
389 | SetTab(l); | ||
390 | if(pResult) | ||
391 | *pResult = 0; | ||
392 | } | ||
393 | |||
394 | UINTCKLogDlg::m_PriorityCtls[CSyslogSocket::totalPriorities] = { | ||
395 | IDC_EMERG,IDC_ALERT,IDC_CRIT,IDC_ERR,IDC_WARNING,IDC_NOTICE,IDC_INFO,IDC_DEBUG | ||
396 | }; | ||
397 | void CKLogDlg::SetTab(CLogger* l) | ||
398 | { | ||
399 | ASSERT(l); | ||
400 | m_Logger=l; | ||
401 | m_Desc=m_Logger->m_Desc; | ||
402 | UpdateLogto(FALSE,FALSE); | ||
403 | UpdatePriface(FALSE,FALSE); | ||
404 | // HOST LIST | ||
405 | m_hlCtl.ResetContent(); | ||
406 | m_hlRemoveCtl.EnableWindow(FALSE); | ||
407 | POSITION p = m_Logger->m_Hosts.GetHeadPosition(); | ||
408 | while(p){ | ||
409 | CHostMask *hm = m_Logger->m_Hosts.GetNext(p); | ||
410 | ASSERT(hm); | ||
411 | CString hms = hm->String(); | ||
412 | int i = m_hlCtl.AddString(hms); | ||
413 | ASSERT(i>=0); | ||
414 | m_hlCtl.SetItemData(i,(DWORD)hm); | ||
415 | } | ||
416 | // SOUND | ||
417 | m_Sound=m_Logger->m_Sound; | ||
418 | // EVENTS | ||
419 | m_Log.ResetContent(); | ||
420 | p = m_Logger->m_Log.GetHeadPosition(); | ||
421 | while(p){ | ||
422 | CLogEntry *le = m_Logger->m_Log.GetNext(p); | ||
423 | ASSERT(le); | ||
424 | AddLogLine(le); | ||
425 | } | ||
426 | |||
427 | UpdateData(FALSE); | ||
428 | } | ||
429 | |||
430 | CLogger::CLogger(BOOL bAll) | ||
431 | { | ||
432 | m_Desc=bAll?"All events":"New"; | ||
433 | memset(m_LogPattern,bAll,sizeof(m_LogPattern)); | ||
434 | m_LogTo=logToNone; | ||
435 | m_LogToHost.sin_addr.s_addr = INADDR_NONE; | ||
436 | } | ||
437 | |||
438 | void CKLogDlg::UpdatePriface(BOOL bSave,BOOL update) | ||
439 | { | ||
440 | ASSERT(m_Logger); | ||
441 | int f = CSyslogSocket::Facility(m_Facility); | ||
442 | if(bSave){ | ||
443 | if(f==CSyslogSocket::facNone) | ||
444 | return; | ||
445 | for(int tmp=0;tmp<CSyslogSocket::totalPriorities;tmp++) | ||
446 | m_Logger->m_LogPattern[f][tmp]=(IsDlgButtonChecked(m_PriorityCtls[tmp])!=0); | ||
447 | }else{ | ||
448 | if(f==CSyslogSocket::facNone){ | ||
449 | for(int tmp=0;tmp<CSyslogSocket::totalPriorities;tmp++){ | ||
450 | CheckDlgButton(m_PriorityCtls[tmp],0); | ||
451 | GetDlgItem(m_PriorityCtls[tmp])->EnableWindow(FALSE); | ||
452 | } | ||
453 | m_PriAllCtl.EnableWindow(FALSE); | ||
454 | m_PriNoneCtl.EnableWindow(FALSE); | ||
455 | m_PriInvertCtl.EnableWindow(FALSE); | ||
456 | }else{ | ||
457 | for(int tmp=0;tmp<CSyslogSocket::totalPriorities;tmp++){ | ||
458 | CheckDlgButton(m_PriorityCtls[tmp],m_Logger->m_LogPattern[f][tmp]?1:0); | ||
459 | GetDlgItem(m_PriorityCtls[tmp])->EnableWindow(TRUE); | ||
460 | } | ||
461 | m_PriAllCtl.EnableWindow(TRUE); | ||
462 | m_PriNoneCtl.EnableWindow(TRUE); | ||
463 | m_PriInvertCtl.EnableWindow(TRUE); | ||
464 | if(update) | ||
465 | UpdateData(FALSE); | ||
466 | } | ||
467 | } | ||
468 | } | ||
469 | |||
470 | void CKLogDlg::OnSelchangeFacility() | ||
471 | { | ||
472 | ASSERT(m_Logger); | ||
473 | UpdatePriface(TRUE,FALSE); | ||
474 | UpdateData(TRUE); | ||
475 | UpdatePriface(FALSE,TRUE); | ||
476 | } | ||
477 | |||
478 | void CKLogDlg::OnPriority() | ||
479 | { | ||
480 | UpdatePriface(TRUE,FALSE); | ||
481 | } | ||
482 | |||
483 | void CKLogDlg::UpdateLogto(BOOL bSave,BOOL update) | ||
484 | { | ||
485 | if(bSave){ | ||
486 | m_Logger->m_LogTo=m_Logto; | ||
487 | if(m_Logto!=CLogger::logToNone){ | ||
488 | m_Logger->m_LogToName=m_HFName; | ||
489 | switch(m_Logto){ | ||
490 | case CLogger::logToFile: | ||
491 | // ??? Do nothing | ||
492 | break; | ||
493 | case CLogger::logToHost: | ||
494 | m_Logger->LookupHost(this); | ||
495 | break; | ||
496 | #ifndefNDEBUG | ||
497 | default: | ||
498 | ASSERT(FALSE); | ||
499 | break; | ||
500 | #endif | ||
501 | } | ||
502 | } | ||
503 | }else{ | ||
504 | m_Logto=m_Logger->m_LogTo; | ||
505 | m_HFNameCaption.Empty(); | ||
506 | m_HFName=m_Logger->m_LogToName; | ||
507 | BOOL doLog = TRUE; | ||
508 | BOOL doBrowse = FALSE; | ||
509 | switch(m_Logger->m_LogTo){ | ||
510 | case CLogger::logToNone: | ||
511 | doLog=FALSE; | ||
512 | m_HFName.Empty(); | ||
513 | break; | ||
514 | case CLogger::logToFile: | ||
515 | m_HFNameCaption.LoadString(IDS_LOGTO_FILE); | ||
516 | doBrowse=TRUE; | ||
517 | break; | ||
518 | case CLogger::logToHost: | ||
519 | m_HFNameCaption.LoadString(IDS_LOGTO_HOST); | ||
520 | break; | ||
521 | default: | ||
522 | ASSERT(FALSE); | ||
523 | break; | ||
524 | } | ||
525 | m_HFNameCtl.EnableWindow(doLog); | ||
526 | m_HFNameCaptionCtl.EnableWindow(doLog); | ||
527 | m_BrowseCtl.EnableWindow(doBrowse); | ||
528 | if(update) | ||
529 | UpdateData(FALSE); | ||
530 | } | ||
531 | } | ||
532 | |||
533 | void CKLogDlg::OnLogto() | ||
534 | { | ||
535 | ASSERT(m_Logger); | ||
536 | UpdateData(TRUE); | ||
537 | m_HFName=m_Logger->m_LogToName; | ||
538 | UpdateLogto(TRUE,FALSE); | ||
539 | UpdateLogto(FALSE,TRUE); | ||
540 | } | ||
541 | |||
542 | void CKLogDlg::OnPriAll() | ||
543 | { | ||
544 | ASSERT(m_Logger); | ||
545 | UpdateData(TRUE); | ||
546 | UpdatePriface(TRUE,FALSE); | ||
547 | int f = CSyslogSocket::Facility(m_Facility); | ||
548 | for(int tmp=0;tmp<CSyslogSocket::totalPriorities;tmp++) | ||
549 | m_Logger->m_LogPattern[f][tmp]=TRUE; | ||
550 | UpdatePriface(FALSE,TRUE); | ||
551 | } | ||
552 | |||
553 | void CKLogDlg::OnPriNone() | ||
554 | { | ||
555 | ASSERT(m_Logger); | ||
556 | UpdateData(TRUE); | ||
557 | UpdatePriface(TRUE,FALSE); | ||
558 | int f = CSyslogSocket::Facility(m_Facility); | ||
559 | for(int tmp=0;tmp<CSyslogSocket::totalPriorities;tmp++) | ||
560 | m_Logger->m_LogPattern[f][tmp]=FALSE; | ||
561 | UpdatePriface(FALSE,TRUE); | ||
562 | } | ||
563 | |||
564 | void CKLogDlg::OnPriInvert() | ||
565 | { | ||
566 | ASSERT(m_Logger); | ||
567 | UpdateData(TRUE); | ||
568 | UpdatePriface(TRUE,FALSE); | ||
569 | int f = CSyslogSocket::Facility(m_Facility); | ||
570 | for(int tmp=0;tmp<CSyslogSocket::totalPriorities;tmp++) | ||
571 | m_Logger->m_LogPattern[f][tmp]=!m_Logger->m_LogPattern[f][tmp]; | ||
572 | UpdatePriface(FALSE,TRUE); | ||
573 | } | ||
574 | |||
575 | void CKLogDlg::OnChangeDesc() | ||
576 | { | ||
577 | ASSERT(m_Logger); | ||
578 | UpdateData(TRUE); | ||
579 | m_Logger->m_Desc=m_Desc; | ||
580 | intcs = m_Tabs.GetCurSel(); | ||
581 | ASSERT(cs>=0); | ||
582 | TC_ITEM ptci; | ||
583 | memset(&ptci,0,sizeof(ptci)); | ||
584 | ptci.mask=TCIF_TEXT; | ||
585 | ptci.pszText=(LPTSTR)(LPCTSTR)m_Logger->m_Desc; | ||
586 | VERIFY(m_Tabs.SetItem(cs,&ptci)); | ||
587 | } | ||
588 | |||
589 | CString CHostMask::String() | ||
590 | { | ||
591 | CString rv; | ||
592 | rv = inet_ntoa(*(in_addr*)&m_Host); | ||
593 | rv+=" / "; | ||
594 | rv+= inet_ntoa(*(in_addr*)&m_Mask); | ||
595 | return rv; | ||
596 | } | ||
597 | |||
598 | void CKLogDlg::OnHlAdd() | ||
599 | { | ||
600 | ASSERT(m_Logger); | ||
601 | UpdateData(TRUE); | ||
602 | DWORD h = (DWORD)inet_addr(m_hlIP); | ||
603 | DWORD m = (DWORD)inet_addr(m_hlMask); | ||
604 | if(h==INADDR_NONE){ | ||
605 | TRACE0("Bad host address\n"); | ||
606 | m_hlIPCtl.SetFocus(); | ||
607 | return; | ||
608 | } | ||
609 | if(m==INADDR_NONE && m_hlMask!="255.255.255.255"){ // 255.255.255.255 stands for INADDR_NONE | ||
610 | TRACE0("Bad host mask\n"); | ||
611 | m_hlMaskCtl.SetFocus(); | ||
612 | return; | ||
613 | } | ||
614 | if(!(m && h)){ | ||
615 | TRACE0("Both zeros\n"); | ||
616 | m_hlIPCtl.SetFocus(); | ||
617 | return; | ||
618 | } | ||
619 | CHostMask *hm = new CHostMask(h,m); | ||
620 | ASSERT(hm); | ||
621 | m_Logger->m_Hosts.AddTail(hm); | ||
622 | CString hms = hm->String(); | ||
623 | int i = m_hlCtl.AddString(hms); | ||
624 | ASSERT(i>=0); | ||
625 | m_hlCtl.SetItemData(i,(DWORD)hm); | ||
626 | } | ||
627 | |||
628 | void CKLogDlg::OnSelchangeHosts() | ||
629 | { | ||
630 | int i = m_hlCtl.GetCurSel(); | ||
631 | if(i<0){ | ||
632 | m_hlRemoveCtl.EnableWindow(FALSE); | ||
633 | return; | ||
634 | } | ||
635 | CHostMask *hm = (CHostMask*)m_hlCtl.GetItemData(i); | ||
636 | ASSERT(hm); | ||
637 | m_hlIP=inet_ntoa(*(in_addr*)&hm->m_Host); | ||
638 | m_hlMask=inet_ntoa(*(in_addr*)&hm->m_Mask); | ||
639 | UpdateData(FALSE); | ||
640 | m_hlRemoveCtl.EnableWindow(TRUE); | ||
641 | } | ||
642 | |||
643 | void CKLogDlg::OnHlRemove() | ||
644 | { | ||
645 | int i = m_hlCtl.GetCurSel(); | ||
646 | if(i<0){ | ||
647 | m_hlRemoveCtl.EnableWindow(FALSE); | ||
648 | return; | ||
649 | } | ||
650 | CHostMask *hm = (CHostMask*)m_hlCtl.GetItemData(i); | ||
651 | m_hlCtl.DeleteString(i); | ||
652 | ASSERT(hm); | ||
653 | ASSERT(m_Logger); | ||
654 | POSITION p = m_Logger->m_Hosts.Find(hm); | ||
655 | ASSERT(p); | ||
656 | m_Logger->m_Hosts.RemoveAt(p); | ||
657 | delete hm; | ||
658 | m_hlRemoveCtl.EnableWindow(m_hlCtl.GetCurSel()>=0); | ||
659 | } | ||
660 | |||
661 | void CKLogDlg::OnRemove() | ||
662 | { | ||
663 | ASSERT(m_Tabs.GetItemCount()>1); | ||
664 | int t = m_Tabs.GetCurSel(); | ||
665 | ASSERT(t>=0); | ||
666 | ASSERT(m_Logger); | ||
667 | TC_ITEM tci; | ||
668 | memset(&tci,0,sizeof(tci)); | ||
669 | tci.mask=TCIF_PARAM; | ||
670 | VERIFY(m_Tabs.GetItem(t,&tci)); | ||
671 | ASSERT(tci.lParam==(LPARAM)m_Logger); | ||
672 | VERIFY(m_Tabs.DeleteItem(t)); | ||
673 | VERIFY(m_Logs.RemoveKey(m_Logger)); | ||
674 | delete m_Logger; | ||
675 | m_Logger=NULL; | ||
676 | m_Tabs.SetCurSel(t); | ||
677 | t=m_Tabs.GetCurSel(); | ||
678 | if(t<0) | ||
679 | VERIFY(m_Tabs.SetCurSel(t=0)); | ||
680 | memset(&tci,0,sizeof(tci)); | ||
681 | tci.mask=TCIF_PARAM; | ||
682 | VERIFY(m_Tabs.GetItem(t,&tci)); | ||
683 | CLogger *l = (CLogger*)tci.lParam; | ||
684 | ASSERT(l); | ||
685 | SetTab(l); | ||
686 | m_RemoveCtl.EnableWindow(m_Tabs.GetItemCount()>1); | ||
687 | } | ||
688 | |||
689 | void CLogger::PlayWave() | ||
690 | { | ||
691 | if(m_Sound.IsEmpty()) | ||
692 | return; | ||
693 | CString tmp; | ||
694 | tmp.LoadString(IDS_SOUND_MEOW); | ||
695 | if(!tmp.CompareNoCase(m_Sound)){ | ||
696 | ::PlaySound((LPCTSTR)IDW_SOUND_MEOW,AfxGetApp()->m_hInstance,SND_ASYNC|SND_NODEFAULT|SND_NOSTOP|SND_NOWAIT|SND_RESOURCE); | ||
697 | return; | ||
698 | } | ||
699 | tmp.LoadString(IDS_SOUND_GLASS); | ||
700 | if(!tmp.CompareNoCase(m_Sound)){ | ||
701 | ::PlaySound((LPCTSTR)IDW_SOUND_GLASS,AfxGetApp()->m_hInstance,SND_ASYNC|SND_NODEFAULT|SND_NOSTOP|SND_NOWAIT|SND_RESOURCE); | ||
702 | return; | ||
703 | } | ||
704 | tmp.LoadString(IDS_SOUND_FEAR); | ||
705 | if(!tmp.CompareNoCase(m_Sound)){ | ||
706 | ::PlaySound((LPCTSTR)IDW_SOUND_FEAR,AfxGetApp()->m_hInstance,SND_ASYNC|SND_NODEFAULT|SND_NOSTOP|SND_NOWAIT|SND_RESOURCE); | ||
707 | return; | ||
708 | } | ||
709 | tmp.LoadString(IDS_SOUND_KICK); | ||
710 | if(!tmp.CompareNoCase(m_Sound)){ | ||
711 | ::PlaySound((LPCTSTR)IDW_SOUND_KICK,AfxGetApp()->m_hInstance,SND_ASYNC|SND_NODEFAULT|SND_NOSTOP|SND_NOWAIT|SND_RESOURCE); | ||
712 | return; | ||
713 | } | ||
714 | ::PlaySound(m_Sound,AfxGetApp()->m_hInstance,SND_ASYNC|SND_NODEFAULT|SND_NOSTOP|SND_NOWAIT|SND_FILENAME); | ||
715 | } | ||
716 | |||
717 | void CKLogDlg::OnPlaysound() | ||
718 | { | ||
719 | ASSERT(m_Logger); | ||
720 | m_Logger->PlayWave(); | ||
721 | } | ||
722 | |||
723 | void CKLogDlg::OnEditchangeSound() | ||
724 | { | ||
725 | ASSERT(m_Logger); | ||
726 | UpdateData(TRUE); | ||
727 | m_Logger->m_Sound=m_Sound; | ||
728 | } | ||
729 | |||
730 | void CKLogDlg::OnKillfocusSound() | ||
731 | { | ||
732 | ASSERT(m_Logger); | ||
733 | UpdateData(TRUE); | ||
734 | m_Logger->m_Sound=m_Sound; | ||
735 | } | ||
736 | |||
737 | void CKLogDlg::UpdateLogLength(BOOL bSave,BOOL update) | ||
738 | { | ||
739 | if(bSave){ | ||
740 | int sbp = m_LogLenSpinCtl.GetPos(); | ||
741 | if(sbp&(0xFFFFl<<16)){ | ||
742 | sbp = 15; | ||
743 | m_LogLenSpinCtl.SetPos(sbp); | ||
744 | } | ||
745 | m_LogItems=sbp; | ||
746 | }else{ | ||
747 | m_LogLenSpinCtl.SetPos(m_LogItems); | ||
748 | } | ||
749 | } | ||
750 | |||
751 | void CKLogDlg::OnDeltaposLoglenspin(NMHDR* pNMHDR, LRESULT* pResult) | ||
752 | { | ||
753 | NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR; | ||
754 | UpdateLogLength(TRUE,FALSE); | ||
755 | *pResult = 0; | ||
756 | } | ||
757 | |||
758 | void CKLogDlg::OnExit() | ||
759 | { | ||
760 | SaveSettings(); | ||
761 | TotalCleanUp(); | ||
762 | m_bExiting=TRUE; | ||
763 | EndDialog(IDOK); | ||
764 | } | ||
765 | |||
766 | void CKLogDlg::TotalCleanUp() | ||
767 | { | ||
768 | POSITION p = m_Logs.GetStartPosition(); | ||
769 | while(p){ | ||
770 | CLogger *l, *ll; | ||
771 | m_Logs.GetNextAssoc(p,l,ll); | ||
772 | ASSERT(l); | ||
773 | ASSERT(l==ll); | ||
774 | delete l; | ||
775 | } | ||
776 | m_Logs.RemoveAll(); | ||
777 | m_Tabs.DeleteAllItems(); | ||
778 | RedrawWindow(); | ||
779 | } | ||
780 | |||
781 | CLogger::~CLogger() | ||
782 | { | ||
783 | POSITION p = m_Hosts.GetHeadPosition(); | ||
784 | while(p){ | ||
785 | CHostMask *hm = m_Hosts.GetNext(p); | ||
786 | ASSERT(hm); | ||
787 | delete hm; | ||
788 | } | ||
789 | m_Hosts.RemoveAll(); | ||
790 | p = m_Log.GetHeadPosition(); | ||
791 | while(p){ | ||
792 | CLogEntry *le = m_Log.GetNext(p); | ||
793 | ASSERT(le); | ||
794 | delete le; | ||
795 | } | ||
796 | m_Log.RemoveAll(); | ||
797 | } | ||
798 | |||
799 | void CKLogDlg::OnFiles() | ||
800 | { | ||
801 | CRect rc; | ||
802 | m_FilesCtl.GetWindowRect(&rc); | ||
803 | CPoint pt = rc.TopLeft(); | ||
804 | CMenu menu; | ||
805 | VERIFY(menu.LoadMenu(IDD)); | ||
806 | CMenu *filesMenu = menu.GetSubMenu(0); | ||
807 | ASSERT(filesMenu); | ||
808 | filesMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,pt.x,pt.y,this); | ||
809 | } | ||
810 | |||
811 | void CKLogDlg::OnFilesExport() | ||
812 | { | ||
813 | TRACE0("Export\n"); | ||
814 | CString filter; | ||
815 | filter.LoadString(IDS_KLOGFILTER); | ||
816 | CString title, ext; | ||
817 | title.LoadString(IDS_KLOG_EXPORT); | ||
818 | ext.LoadString(IDS_KLOG_EXT); | ||
819 | CFileDialog cfd(FALSE,ext,NULL,OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,filter,this); | ||
820 | cfd.m_ofn.lpstrTitle=title; | ||
821 | if(cfd.DoModal()==IDOK){ | ||
822 | CFile klo; | ||
823 | if(klo.Open(cfd.GetPathName(),CFile::modeCreate|CFile::modeWrite)){ | ||
824 | TRY{ | ||
825 | CArchive ar(&klo,CArchive::store); | ||
826 | Serialize(ar); | ||
827 | ar.Close(); | ||
828 | }CATCH(CException, e){ | ||
829 | CString tmp; | ||
830 | tmp.LoadString(IDS_MSG_FAILEDTOEXPORT); | ||
831 | MessageBox(tmp,NULL,MB_ICONHAND|MB_OK); | ||
832 | }END_CATCH | ||
833 | }else{ | ||
834 | CString tmp; | ||
835 | tmp.LoadString(IDS_MSG_FAILEDTOEXPORT); | ||
836 | MessageBox(tmp,NULL,MB_ICONHAND|MB_OK); | ||
837 | } | ||
838 | } | ||
839 | } | ||
840 | |||
841 | void CKLogDlg::OnFilesImport() | ||
842 | { | ||
843 | TRACE0("Import\n"); | ||
844 | CString filter; | ||
845 | filter.LoadString(IDS_KLOGFILTER); | ||
846 | CString title; | ||
847 | title.LoadString(IDS_KLOG_IMPORT); | ||
848 | CFileDialog cfd(TRUE,NULL,NULL,OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,filter,this); | ||
849 | cfd.m_ofn.lpstrTitle=title; | ||
850 | if(cfd.DoModal()==IDOK){ | ||
851 | CFile klo; | ||
852 | if(klo.Open(cfd.GetPathName(),CFile::modeRead)){ | ||
853 | TRY{ | ||
854 | CArchive ar(&klo,CArchive::load); | ||
855 | Serialize(ar); | ||
856 | ar.Close(); | ||
857 | }CATCH(CException, e){ | ||
858 | CString tmp; | ||
859 | tmp.LoadString(IDS_MSG_FAILEDTOIMPORT); | ||
860 | MessageBox(tmp,NULL,MB_ICONHAND|MB_OK); | ||
861 | }END_CATCH | ||
862 | }else{ | ||
863 | CString tmp; | ||
864 | tmp.LoadString(IDS_MSG_FAILEDTOIMPORT); | ||
865 | MessageBox(tmp,NULL,MB_ICONHAND|MB_OK); | ||
866 | } | ||
867 | } | ||
868 | } | ||
869 | |||
870 | void CKLogDlg::OnBrowsesound() | ||
871 | { | ||
872 | CString filter; | ||
873 | filter.LoadString(IDS_WAVFILTER); | ||
874 | CString title; | ||
875 | title.LoadString(IDS_SOUND_SELECT); | ||
876 | CFileDialog cfd(TRUE,NULL,NULL,OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,filter,this); | ||
877 | cfd.m_ofn.lpstrTitle=title; | ||
878 | if(cfd.DoModal()==IDOK){ | ||
879 | m_Sound=cfd.GetPathName(); | ||
880 | ASSERT(m_Logger); | ||
881 | UpdateData(FALSE); | ||
882 | m_Logger->m_Sound=m_Sound; | ||
883 | } | ||
884 | } | ||
885 | |||
886 | void CKLogDlg::OnKillfocusHostfile() | ||
887 | { | ||
888 | UpdateData(TRUE); | ||
889 | if(m_HFName.Compare(m_Logger->m_LogToName)) | ||
890 | UpdateLogto(TRUE,FALSE); | ||
891 | } | ||
892 | |||
893 | void CKLogDlg::OnOK() | ||
894 | { | ||
895 | UpdateData(TRUE); | ||
896 | UpdateLogto(TRUE,FALSE); | ||
897 | } | ||
898 | |||
899 | void CKLogDlg::OnBrowse() | ||
900 | { | ||
901 | CString filter; | ||
902 | filter.LoadString(IDS_LOGFILTER); | ||
903 | CString title, ext; | ||
904 | title.LoadString(IDS_LOG_SELECT); | ||
905 | ext.LoadString(IDS_LOG_EXT); | ||
906 | CFileDialog cfd(FALSE,ext,NULL,OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,filter,this); | ||
907 | cfd.m_ofn.lpstrTitle=title; | ||
908 | if(cfd.DoModal()==IDOK){ | ||
909 | m_HFName=cfd.GetPathName(); | ||
910 | ASSERT(m_Logger); | ||
911 | UpdateData(FALSE); | ||
912 | m_Logger->m_LogToName=m_HFName; | ||
913 | } | ||
914 | } | ||
915 | |||
916 | void CKLogDlg::Serialize(CArchive& ar) | ||
917 | { | ||
918 | ASSERT_VALID(this); | ||
919 | |||
920 | ar.MapObject(this); | ||
921 | ar.SerializeClass(RUNTIME_CLASS(CKLogDlg)); | ||
922 | |||
923 | if(ar.IsStoring()){ | ||
924 | // Store | ||
925 | TRACE0("Store Klog\n"); | ||
926 | intnCount = m_Tabs.GetItemCount(); | ||
927 | ar << nCount; | ||
928 | for(int tmp=0;tmp<nCount;tmp++){ | ||
929 | TC_ITEM ptci; | ||
930 | memset(&ptci,0,sizeof(ptci)); | ||
931 | ptci.mask=TCIF_PARAM; | ||
932 | VERIFY(m_Tabs.GetItem(tmp,&ptci)); | ||
933 | CLogger *l = (CLogger*)ptci.lParam; | ||
934 | ASSERT(l); | ||
935 | l->Serialize(ar); | ||
936 | } | ||
937 | }else{ | ||
938 | // Retrieve | ||
939 | UINT schema = ar.GetObjectSchema(); | ||
940 | #ifndef NDEBUG | ||
941 | { | ||
942 | CString tmp; | ||
943 | tmp.Format("Doc-OSchema: %u\n",schema); | ||
944 | TRACE0(tmp); | ||
945 | } | ||
946 | #endif | ||
947 | // Do the cleanup | ||
948 | TotalCleanUp(); | ||
949 | int nCount; | ||
950 | ar >> nCount; | ||
951 | ASSERT(nCount); | ||
952 | for(int tmp=0;tmp<nCount;tmp++){ | ||
953 | CLogger *l = new CLogger(); | ||
954 | l->Serialize(ar); | ||
955 | m_Logs[l]=l; | ||
956 | TC_ITEM ptc; | ||
957 | memset(&ptc,0,sizeof(ptc)); | ||
958 | ptc.mask=TCIF_TEXT|TCIF_IMAGE|TCIF_PARAM; | ||
959 | ptc.pszText=(LPTSTR)(LPCTSTR)l->m_Desc; | ||
960 | ptc.iImage=m_iNormal; | ||
961 | ptc.lParam=(LPARAM)l; | ||
962 | int tmp=m_Tabs.InsertItem(m_Tabs.GetItemCount(),&ptc); | ||
963 | if(l->m_LogTo==CLogger::logToHost) | ||
964 | l->LookupHost(this); | ||
965 | } | ||
966 | m_Tabs.SetCurSel(0); | ||
967 | OnSelchangeTabs(NULL,NULL); | ||
968 | m_RemoveCtl.EnableWindow(nCount>1); | ||
969 | } | ||
970 | } | ||
971 | |||
972 | void CLogger::Serialize(CArchive& ar) | ||
973 | { | ||
974 | ASSERT_VALID(this); | ||
975 | |||
976 | ar.MapObject(this); | ||
977 | ar.SerializeClass(RUNTIME_CLASS(CLogger)); | ||
978 | |||
979 | if(ar.IsStoring()){ | ||
980 | // Store | ||
981 | TRACE0("Store Klogger\n"); | ||
982 | ar << m_Desc; | ||
983 | ar.Write(&m_LogPattern,sizeof(m_LogPattern)); | ||
984 | ar << m_LogTo; | ||
985 | ar << m_LogToName; | ||
986 | ar << m_Sound; | ||
987 | m_Hosts.Serialize(ar); | ||
988 | }else{ | ||
989 | // Retrieve | ||
990 | UINT schema = ar.GetObjectSchema(); | ||
991 | #ifndef NDEBUG | ||
992 | { | ||
993 | CString tmp; | ||
994 | tmp.Format("Doc-OSchema: %u\n",schema); | ||
995 | TRACE0(tmp); | ||
996 | } | ||
997 | #endif | ||
998 | ar >> m_Desc; | ||
999 | ar.Read(&m_LogPattern,sizeof(m_LogPattern)); | ||
1000 | ar >> m_LogTo; | ||
1001 | ar >> m_LogToName; | ||
1002 | ar >> m_Sound; | ||
1003 | m_Hosts.Serialize(ar); | ||
1004 | } | ||
1005 | } | ||
1006 | |||
1007 | void CHostMask::Serialize(CArchive& ar) | ||
1008 | { | ||
1009 | ASSERT_VALID(this); | ||
1010 | |||
1011 | if(ar.IsStoring()){ | ||
1012 | // Store | ||
1013 | ar << m_Host; | ||
1014 | ar << m_Mask; | ||
1015 | }else{ | ||
1016 | // Retrieve | ||
1017 | ar >> m_Host; | ||
1018 | ar >> m_Mask; | ||
1019 | } | ||
1020 | } | ||
1021 | |||
1022 | void CKLogDlg::OnFilesReset() | ||
1023 | { | ||
1024 | TotalCleanUp(); | ||
1025 | BYTE *pData = NULL; | ||
1026 | UINT dataLength = 0; | ||
1027 | if(AfxGetApp()->GetProfileBinary("Layout","Destinations",&pData,&dataLength)){ | ||
1028 | CMemFile mf(pData,dataLength); | ||
1029 | CArchive ar(&mf,CArchive::load); | ||
1030 | Serialize(ar); | ||
1031 | ar.Close(); | ||
1032 | delete mf.Detach(); | ||
1033 | }else | ||
1034 | OnAdd(); | ||
1035 | } | ||
1036 | |||
1037 | void CAboutDlg::OnKlevernet() | ||
1038 | { | ||
1039 | CString url; | ||
1040 | url.LoadString(IDS_KLEVERNET_URL); | ||
1041 | ShellExecute(::GetDesktopWindow(),"open",url,NULL,NULL,SW_SHOWMAXIMIZED); | ||
1042 | } | ||
1043 | |||
1044 | void CKLogSocket::Log(UINT pri,UINT fac,LPCTSTR line,SOCKADDR_IN *sin) | ||
1045 | { | ||
1046 | CString str = Escape(line); | ||
1047 | m_Daddy->LogMessage(pri,fac,str,sin); | ||
1048 | } | ||
1049 | |||
1050 | void CKLogDlg::LogMessage(UINT pri,UINT fac,LPCTSTR line,SOCKADDR_IN *sin) | ||
1051 | { | ||
1052 | // Setting up defaults: | ||
1053 | UINT ap = pri, af = fac; | ||
1054 | if(ap>=CSyslogSocket::totalPriorities) | ||
1055 | ap=CSyslogSocket::priInfo; | ||
1056 | if(af>=CSyslogSocket::totalFacilities) | ||
1057 | af=CSyslogSocket::facUser; | ||
1058 | POSITION p = m_Logs.GetStartPosition(); | ||
1059 | while(p){ | ||
1060 | CLogger *l,*ll; | ||
1061 | m_Logs.GetNextAssoc(p,l,ll); | ||
1062 | ASSERT(l); | ||
1063 | ASSERT(l==ll); | ||
1064 | if(l->m_LogPattern[af][ap] && l->IsHostFine(sin->sin_addr.s_addr)) | ||
1065 | l->LogLine(this,ap,af,line,sin); | ||
1066 | } | ||
1067 | } | ||
1068 | |||
1069 | CLogEntry::CLogEntry() | ||
1070 | { | ||
1071 | m_Time==CTime::GetCurrentTime(); | ||
1072 | m_Priority=CSyslogSocket::priNone; | ||
1073 | m_Facility=CSyslogSocket::facNone; | ||
1074 | } | ||
1075 | |||
1076 | BOOL CLogger::IsHostFine(DWORD saddr) | ||
1077 | { | ||
1078 | if(m_Hosts.IsEmpty()) | ||
1079 | return TRUE; | ||
1080 | POSITION p = m_Hosts.GetHeadPosition(); | ||
1081 | while(p){ | ||
1082 | CHostMask *hm = m_Hosts.GetNext(p); | ||
1083 | ASSERT(hm); | ||
1084 | if(hm->IsThis(saddr)) | ||
1085 | return TRUE; | ||
1086 | } | ||
1087 | return FALSE; | ||
1088 | } | ||
1089 | |||
1090 | void CLogger::LogLine(CKLogDlg *dad,UINT pri,UINT fac,LPCTSTR line,SOCKADDR_IN *sin) | ||
1091 | { | ||
1092 | CLogEntry *le = NULL; | ||
1093 | while(m_Log.GetCount()>=dad->m_LogItems){ | ||
1094 | le = m_Log.GetHead(); | ||
1095 | ASSERT(le); | ||
1096 | if(dad->m_Logger==this){ | ||
1097 | ASSERT((CLogEntry*)dad->m_Log.GetItemData(0)==le); | ||
1098 | dad->m_Log.DeleteString(0); | ||
1099 | } | ||
1100 | m_Log.RemoveHead(); | ||
1101 | if(m_Log.GetCount()>dad->m_LogItems){ | ||
1102 | delete le; | ||
1103 | le=NULL; | ||
1104 | } | ||
1105 | } | ||
1106 | if(!le) | ||
1107 | le = new CLogEntry(); | ||
1108 | ASSERT(le); | ||
1109 | le->m_Time=CTime::GetCurrentTime(); | ||
1110 | le->m_Priority=pri; | ||
1111 | le->m_Facility=fac; | ||
1112 | le->m_Data=line; | ||
1113 | le->m_Source=inet_ntoa(sin->sin_addr); | ||
1114 | m_Log.AddTail(le); | ||
1115 | if(dad->m_Logger==this){ | ||
1116 | dad->AddLogLine(le); | ||
1117 | }else{ | ||
1118 | int c = dad->m_Tabs.GetItemCount(); | ||
1119 | ASSERT(c>0); | ||
1120 | for(int i=0;i<c;i++){ | ||
1121 | TC_ITEM ptci; | ||
1122 | memset(&ptci,0,sizeof(ptci)); | ||
1123 | ptci.mask=TCIF_PARAM; | ||
1124 | VERIFY(dad->m_Tabs.GetItem(i,&ptci)); | ||
1125 | CLogger *l = (CLogger*)ptci.lParam; | ||
1126 | if(l==this){ | ||
1127 | memset(&ptci,0,sizeof(ptci)); | ||
1128 | ptci.mask=TCIF_IMAGE; | ||
1129 | ptci.iImage=dad->m_iTriggered; | ||
1130 | VERIFY(dad->m_Tabs.SetItem(i,&ptci)); | ||
1131 | } | ||
1132 | } | ||
1133 | } | ||
1134 | PlayWave(); | ||
1135 | switch(m_LogTo){ | ||
1136 | case logToFile: | ||
1137 | if(!m_LogToName.IsEmpty()){ | ||
1138 | TRY{ | ||
1139 | CFile file(m_LogToName,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite|CFile::shareDenyWrite|CFile::typeBinary); | ||
1140 | file.SeekToEnd(); | ||
1141 | CString tmp = le->m_Time.Format(IDS_LOGFILETIMEFORMAT); | ||
1142 | file.Write((LPCTSTR)tmp,tmp.GetLength()); | ||
1143 | tmp.Format(IDS_LOGFILESOURCEFORMAT,le->m_Source); | ||
1144 | file.Write((LPCTSTR)tmp,tmp.GetLength()); | ||
1145 | tmp.Format(IDS_LOGFILEPRIFACEFORMAT,CSyslogSocket::m_Facilities[fac],CSyslogSocket::m_Priorities[pri]); | ||
1146 | file.Write((LPCTSTR)tmp,tmp.GetLength()); | ||
1147 | file.Write(line,strlen(line)); | ||
1148 | file.Write("\r\n",2); | ||
1149 | file.Close(); | ||
1150 | }CATCH(CFileException, e){ | ||
1151 | #ifndefNDEBUG | ||
1152 | afxDump << "Logging error: " << e->m_cause << "\n"; | ||
1153 | #endif | ||
1154 | }END_CATCH | ||
1155 | } | ||
1156 | break; | ||
1157 | case logToHost: | ||
1158 | if(m_LogToHost.sin_addr.s_addr!=INADDR_NONE){ | ||
1159 | CString tmp; | ||
1160 | tmp.Format(IDS_LOGHOSTSOURCEFORMAT,le->m_Source); | ||
1161 | tmp+=line; | ||
1162 | dad->m_SLS.LogTo(m_LogToHost.sin_addr.s_addr,pri,fac,tmp); | ||
1163 | } | ||
1164 | break; | ||
1165 | } | ||
1166 | } | ||
1167 | |||
1168 | CLogEntry& CLogEntry::operator=(CLogEntry& src) | ||
1169 | { | ||
1170 | m_Data=src.m_Data; | ||
1171 | m_Facility=src.m_Facility; | ||
1172 | m_Priority=src.m_Priority; | ||
1173 | m_Source=src.m_Source; | ||
1174 | m_Time=src.m_Time; | ||
1175 | return *this; | ||
1176 | } | ||
1177 | |||
1178 | CLogEntry::CLogEntry(CLogEntry& src) | ||
1179 | { | ||
1180 | (*this)=src; | ||
1181 | } | ||
1182 | |||
1183 | void CKLogDlg::AddLogLine(CLogEntry *le) | ||
1184 | { | ||
1185 | ASSERT(le); | ||
1186 | int i = m_Log.AddString(le->m_Data); | ||
1187 | m_Log.SetItemData(i,(DWORD)le); | ||
1188 | m_Log.SetCurSel(i); | ||
1189 | } | ||
1190 | |||
1191 | BOOL CKLogDlg::PreTranslateMessage(MSG* pMsg) | ||
1192 | { | ||
1193 | // CG: The following block was added by the ToolTips component. | ||
1194 | { | ||
1195 | // Let the ToolTip process this message. | ||
1196 | m_tooltip.RelayEvent(pMsg); | ||
1197 | |||
1198 | return CDialog::PreTranslateMessage(pMsg); | ||
1199 | } | ||
1200 | } | ||
1201 | |||
1202 | void CKLogDlg::OnSelchangeLog() | ||
1203 | { | ||
1204 | int i = m_Log.GetCurSel(); | ||
1205 | if(i==LB_ERR) | ||
1206 | return; | ||
1207 | CLogEntry *le = (CLogEntry*)m_Log.GetItemData(i); | ||
1208 | ASSERT(le); | ||
1209 | CString tmp; | ||
1210 | tmp.Format(IDS_TIP_LOG, | ||
1211 | (LPCTSTR)le->m_Time.Format(IDS_LOGTIMEFORMAT), | ||
1212 | (LPCTSTR)le->m_Source, | ||
1213 | CSyslogSocket::m_Facilities[le->m_Facility], | ||
1214 | CSyslogSocket::m_Priorities[le->m_Priority] | ||
1215 | ); | ||
1216 | m_tooltip.UpdateTipText(tmp,&m_Log); | ||
1217 | } | ||
1218 | |||
1219 | int CKLogDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) | ||
1220 | { | ||
1221 | if (CDialog::OnCreate(lpCreateStruct) == -1) | ||
1222 | return -1; | ||
1223 | |||
1224 | if(!m_Trayer->Create(NULL,"PumpKIN TrayIcon",WS_CHILD,CRect(0,0,0,0),this,0)){ | ||
1225 | TRACE0("Failed to create trayer\n"); | ||
1226 | return -1; | ||
1227 | } | ||
1228 | |||
1229 | NOTIFYICONDATA nid; | ||
1230 | memset(&nid,0,sizeof(nid)); | ||
1231 | nid.cbSize=sizeof(nid); | ||
1232 | nid.hWnd=m_Trayer->m_hWnd; | ||
1233 | nid.uID=IDC_TRAYICON; | ||
1234 | nid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; | ||
1235 | nid.uCallbackMessage=WM_TRAYICON; | ||
1236 | nid.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); | ||
1237 | // *** Load from resource | ||
1238 | strcpy(nid.szTip,"KLog"); | ||
1239 | VERIFY(Shell_NotifyIcon(NIM_ADD,&nid)); | ||
1240 | |||
1241 | return 0; | ||
1242 | } | ||
1243 | |||
1244 | void CKLogDlg::OnClose() | ||
1245 | { | ||
1246 | OnTrayShowklogwindow(); | ||
1247 | } | ||
1248 | |||
1249 | void CKLogDlg::OnTrayAboutklog() | ||
1250 | { | ||
1251 | CAboutDlg dlgAbout; | ||
1252 | dlgAbout.DoModal(); | ||
1253 | } | ||
1254 | |||
1255 | void CKLogDlg::OnTrayExit() | ||
1256 | { | ||
1257 | OnExit(); | ||
1258 | } | ||
1259 | |||
1260 | void CKLogDlg::OnTrayShowklogwindow() | ||
1261 | { | ||
1262 | if(IsWindowVisible()){ | ||
1263 | m_bShown=FALSE; | ||
1264 | ShowWindow(SW_HIDE); | ||
1265 | }else{ | ||
1266 | m_bShown=TRUE; | ||
1267 | ShowWindow(SW_SHOW); | ||
1268 | SetForegroundWindow(); | ||
1269 | SetFocus(); | ||
1270 | } | ||
1271 | } | ||
1272 | |||
1273 | void CKLogDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) | ||
1274 | { | ||
1275 | CDialog::OnWindowPosChanging(lpwndpos); | ||
1276 | |||
1277 | if(!m_bExiting){ | ||
1278 | if(m_bShown){ | ||
1279 | lpwndpos->flags&=~SWP_HIDEWINDOW; | ||
1280 | lpwndpos->flags|=SWP_SHOWWINDOW; | ||
1281 | }else{ | ||
1282 | lpwndpos->flags&=~SWP_SHOWWINDOW; | ||
1283 | lpwndpos->flags|=SWP_HIDEWINDOW; | ||
1284 | if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu)) | ||
1285 | GetDesktopWindow()->SetForegroundWindow(); | ||
1286 | } | ||
1287 | } | ||
1288 | } | ||
1289 | |||
1290 | void CKLogDlg::LoadSettings() | ||
1291 | { | ||
1292 | CWinApp *app = AfxGetApp(); | ||
1293 | ASSERT(app); | ||
1294 | m_LogItems=app->GetProfileInt("UISettings","LogLength",m_LogItems); | ||
1295 | m_bShown=app->GetProfileInt("UISettings","Visible",m_bShown); | ||
1296 | m_bWarnBlocking=app->GetProfileInt("Resolve","WarnBlocking",m_bWarnBlocking); | ||
1297 | m_bDontWarn=app->GetProfileInt("Resolve","DontWarn",m_bDontWarn); | ||
1298 | } | ||
1299 | |||
1300 | void CKLogDlg::SaveSettings() | ||
1301 | { | ||
1302 | CWinApp *app = AfxGetApp(); | ||
1303 | ASSERT(app); | ||
1304 | app->WriteProfileInt("UISettings","LogLength",m_LogItems); | ||
1305 | app->WriteProfileInt("UISettings","Visible",m_bShown); | ||
1306 | app->WriteProfileInt("Resolve","WarnBlocking",m_bWarnBlocking); | ||
1307 | app->WriteProfileInt("Resolve","DontWarn",m_bDontWarn); | ||
1308 | CMemFile mf(4096); | ||
1309 | CArchive ar(&mf,CArchive::store); | ||
1310 | Serialize(ar); | ||
1311 | ar.Close(); | ||
1312 | DWORD dataLength = mf.GetLength(); | ||
1313 | if(dataLength&0xFFFF0000l){ | ||
1314 | CString tmp; | ||
1315 | tmp.LoadString(IDS_MSG_FAILEDTOSTORE); | ||
1316 | MessageBox(tmp,NULL,MB_ICONHAND|MB_OK); | ||
1317 | }else{ | ||
1318 | UINT dl = (UINT)dataLength; | ||
1319 | BYTE *data = mf.Detach(); | ||
1320 | app->WriteProfileBinary("Layout","Destinations",data,dl); | ||
1321 | delete data; | ||
1322 | } | ||
1323 | } | ||
1324 | |||
1325 | CKLogDlg::~CKLogDlg() | ||
1326 | { | ||
1327 | delete m_Trayer; | ||
1328 | } | ||
1329 | |||
1330 | void CKLogDlg::OnLogpattern() | ||
1331 | { | ||
1332 | CLogPattern lp(IDS_LOGPATTERN_TITLE,this); | ||
1333 | memmove(lp.m_Pattern,m_Logger->m_LogPattern,sizeof(lp.m_Pattern)); | ||
1334 | if(lp.DoModal()==IDOK){ | ||
1335 | memmove(m_Logger->m_LogPattern,lp.m_Pattern,sizeof(m_Logger->m_LogPattern)); | ||
1336 | UpdatePriface(FALSE,TRUE); | ||
1337 | } | ||
1338 | } | ||
1339 | |||
1340 | void CLogger::LookupHost(CKLogDlg *daddy) | ||
1341 | { | ||
1342 | m_LogToHost.sin_addr.s_addr=inet_addr((LPCTSTR)m_LogToName); | ||
1343 | if(m_LogToHost.sin_addr.s_addr==INADDR_NONE){ | ||
1344 | if(daddy->m_bWarnBlocking){ | ||
1345 | CWarnBlocking wb(::IsWindow(daddy->m_hWnd)?daddy:NULL); | ||
1346 | wb.m_bDontWarn = daddy->m_bDontWarn; | ||
1347 | if(wb.DoModal()!=IDOK) | ||
1348 | return; | ||
1349 | daddy->m_bDontWarn=wb.m_bDontWarn; | ||
1350 | daddy->m_bWarnBlocking=!wb.m_bDontWarn; | ||
1351 | } | ||
1352 | daddy->BeginWaitCursor(); | ||
1353 | hostent *he = gethostbyname(m_LogToName); | ||
1354 | daddy->EndWaitCursor(); | ||
1355 | if(he){ | ||
1356 | m_LogToHost.sin_addr.s_addr = *(DWORD*)he->h_addr; | ||
1357 | }else{ | ||
1358 | m_LogToHost.sin_addr.s_addr = INADDR_NONE; | ||
1359 | if(daddy->m_bWarnBlocking){ | ||
1360 | CString sux; | ||
1361 | sux.Format(IDS_MSG_LOOKUPFAILED,(LPCTSTR)m_LogToName); | ||
1362 | daddy->MessageBox(sux,NULL,MB_ICONSTOP|MB_OK); | ||
1363 | }else | ||
1364 | MessageBeep(MB_ICONHAND); | ||
1365 | } | ||
1366 | } | ||
1367 | } | ||