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