summaryrefslogtreecommitdiffabout
path: root/PumpKINDlg.cpp
authorMichael Krelin <hacker@klever.net>2006-10-13 19:13:18 (UTC)
committer Michael Krelin <hacker@klever.net>2006-10-13 19:13:18 (UTC)
commit325e7fc43721df3efaa8539190fada6e6e3aa8fa (patch) (unidiff)
treeec03bf74e17eb497e0fcd31b521192b0b14bd83e /PumpKINDlg.cpp
parent577427e68ef10a4d2b75d28e42b22952ae3bcf23 (diff)
downloadpumpkin-325e7fc43721df3efaa8539190fada6e6e3aa8fa.zip
pumpkin-325e7fc43721df3efaa8539190fada6e6e3aa8fa.tar.gz
pumpkin-325e7fc43721df3efaa8539190fada6e6e3aa8fa.tar.bz2
Enabled logging of outgoing errors, added reject with explicit error message
when file is too large for the block size set. git-svn-id: http://svn.klever.net/kin/pumpkin/trunk@192 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'PumpKINDlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--PumpKINDlg.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp
index 2a01918..bb15211 100644
--- a/PumpKINDlg.cpp
+++ b/PumpKINDlg.cpp
@@ -1,2163 +1,2166 @@
1// PumpKINDlg.cpp : implementation file 1// PumpKINDlg.cpp : implementation file
2// 2//
3 3
4#include "stdafx.h" 4#include "stdafx.h"
5#include "PumpKIN.h" 5#include "PumpKIN.h"
6#include "PumpKINDlg.h" 6#include "PumpKINDlg.h"
7 7
8#include "ACLTargetCombo.h" 8#include "ACLTargetCombo.h"
9#include "PropsServer.h" 9#include "PropsServer.h"
10#include "PropsNetwork.h" 10#include "PropsNetwork.h"
11#include "PropsSounds.h" 11#include "PropsSounds.h"
12#include "PropsACL.h" 12#include "PropsACL.h"
13#include "ConfirmRRQDlg.h" 13#include "ConfirmRRQDlg.h"
14#include "ConfirmWRQDlg.h" 14#include "ConfirmWRQDlg.h"
15#include "RequestDlg.h" 15#include "RequestDlg.h"
16#include "Resolver.h" 16#include "Resolver.h"
17#include "Retrier.h" 17#include "Retrier.h"
18#include "Trayer.h" 18#include "Trayer.h"
19 19
20#include <io.h> 20#include <io.h>
21 21
22#ifdef _DEBUG 22#ifdef _DEBUG
23#define new DEBUG_NEW 23#define new DEBUG_NEW
24#undef THIS_FILE 24#undef THIS_FILE
25static char THIS_FILE[] = __FILE__; 25static char THIS_FILE[] = __FILE__;
26#endif 26#endif
27 27
28IMPLEMENT_DYNAMIC(CXferSocket, CAsyncSocket) 28IMPLEMENT_DYNAMIC(CXferSocket, CAsyncSocket)
29IMPLEMENT_DYNAMIC(CWRQSocket, CXferSocket) 29IMPLEMENT_DYNAMIC(CWRQSocket, CXferSocket)
30IMPLEMENT_DYNAMIC(CRRQSocket, CXferSocket) 30IMPLEMENT_DYNAMIC(CRRQSocket, CXferSocket)
31 31
32///////////////////////////////////////////////////////////////////////////// 32/////////////////////////////////////////////////////////////////////////////
33// CAboutDlg dialog used for App About 33// CAboutDlg dialog used for App About
34 34
35class CAboutDlg : public CDialog 35class CAboutDlg : public CDialog
36{ 36{
37public: 37public:
38 CAboutDlg(); 38 CAboutDlg();
39 39
40// Dialog Data 40// Dialog Data
41 //{{AFX_DATA(CAboutDlg) 41 //{{AFX_DATA(CAboutDlg)
42 enum { IDD = IDD_ABOUTBOX }; 42 enum { IDD = IDD_ABOUTBOX };
43 //}}AFX_DATA 43 //}}AFX_DATA
44 44
45 // ClassWizard generated virtual function overrides 45 // ClassWizard generated virtual function overrides
46 //{{AFX_VIRTUAL(CAboutDlg) 46 //{{AFX_VIRTUAL(CAboutDlg)
47 protected: 47 protected:
48 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 48 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
49 //}}AFX_VIRTUAL 49 //}}AFX_VIRTUAL
50 50
51// Implementation 51// Implementation
52protected: 52protected:
53 //{{AFX_MSG(CAboutDlg) 53 //{{AFX_MSG(CAboutDlg)
54 afx_msg void OnKlevernet(); 54 afx_msg void OnKlevernet();
55 //}}AFX_MSG 55 //}}AFX_MSG
56 DECLARE_MESSAGE_MAP() 56 DECLARE_MESSAGE_MAP()
57}; 57};
58 58
59CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 59CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
60{ 60{
61 //{{AFX_DATA_INIT(CAboutDlg) 61 //{{AFX_DATA_INIT(CAboutDlg)
62 //}}AFX_DATA_INIT 62 //}}AFX_DATA_INIT
63} 63}
64 64
65void CAboutDlg::DoDataExchange(CDataExchange* pDX) 65void CAboutDlg::DoDataExchange(CDataExchange* pDX)
66{ 66{
67 CDialog::DoDataExchange(pDX); 67 CDialog::DoDataExchange(pDX);
68 //{{AFX_DATA_MAP(CAboutDlg) 68 //{{AFX_DATA_MAP(CAboutDlg)
69 //}}AFX_DATA_MAP 69 //}}AFX_DATA_MAP
70} 70}
71 71
72BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 72BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
73 //{{AFX_MSG_MAP(CAboutDlg) 73 //{{AFX_MSG_MAP(CAboutDlg)
74 ON_BN_CLICKED(IDC_KLEVERNET, OnKlevernet) 74 ON_BN_CLICKED(IDC_KLEVERNET, OnKlevernet)
75 //}}AFX_MSG_MAP 75 //}}AFX_MSG_MAP
76END_MESSAGE_MAP() 76END_MESSAGE_MAP()
77 77
78///////////////////////////////////////////////////////////////////////////// 78/////////////////////////////////////////////////////////////////////////////
79// CPumpKINDlg dialog 79// CPumpKINDlg dialog
80 80
81CPumpKINDlg::CPumpKINDlg(CWnd* pParent /*=NULL*/) 81CPumpKINDlg::CPumpKINDlg(CWnd* pParent /*=NULL*/)
82 : CDialog(CPumpKINDlg::IDD, pParent), m_MinSize(0,0) 82 : CDialog(CPumpKINDlg::IDD, pParent), m_MinSize(0,0)
83{ 83{
84 m_Listener.m_Daddy = this; 84 m_Listener.m_Daddy = this;
85 85
86 m_bListen = TRUE; 86 m_bListen = TRUE;
87 87
88 m_ListenPort = 69; 88 m_ListenPort = 69;
89 m_bTFTPSubdirs = TRUE; 89 m_bTFTPSubdirs = TRUE;
90 m_RRQMode = rrqAlwaysConfirm; 90 m_RRQMode = rrqAlwaysConfirm;
91 m_WRQMode = wrqAlwaysConfirm; 91 m_WRQMode = wrqAlwaysConfirm;
92 m_TFTPTimeOut = CTimeSpan(0,0,0,30); 92 m_TFTPTimeOut = CTimeSpan(0,0,0,30);
93 m_RetryTimeOut = CTimeSpan(0,0,0,10); 93 m_RetryTimeOut = CTimeSpan(0,0,0,10);
94 m_LogLength = 100; 94 m_LogLength = 100;
95 m_SpeakPort = 69; 95 m_SpeakPort = 69;
96 m_PromptTimeOut=30; 96 m_PromptTimeOut=30;
97 m_bShown=TRUE; 97 m_bShown=TRUE;
98 m_bExiting=FALSE; 98 m_bExiting=FALSE;
99 m_BlockSize=1024; 99 m_BlockSize=1024;
100 m_bnw.AssignSound("(bang)",IDR_WAVE_RING,CBellsNWhistles::CBang::bangResource); 100 m_bnw.AssignSound("(bang)",IDR_WAVE_RING,CBellsNWhistles::CBang::bangResource);
101 m_bnw.AssignSound("(done)",IDR_WAVE_FINISHED,CBellsNWhistles::CBang::bangResource); 101 m_bnw.AssignSound("(done)",IDR_WAVE_FINISHED,CBellsNWhistles::CBang::bangResource);
102 m_bnw.AssignSound("(oops)",IDR_WAVE_ABORTED,CBellsNWhistles::CBang::bangResource); 102 m_bnw.AssignSound("(oops)",IDR_WAVE_ABORTED,CBellsNWhistles::CBang::bangResource);
103 m_bnw.AssignSound("(none)",(int)0,CBellsNWhistles::CBang::bangNone); 103 m_bnw.AssignSound("(none)",(int)0,CBellsNWhistles::CBang::bangNone);
104 m_bnwRequest="(bang)"; m_bnwSuccess="(done)"; 104 m_bnwRequest="(bang)"; m_bnwSuccess="(done)";
105 m_bnwAbort="(oops)"; 105 m_bnwAbort="(oops)";
106 //{{AFX_DATA_INIT(CPumpKINDlg) 106 //{{AFX_DATA_INIT(CPumpKINDlg)
107 //}}AFX_DATA_INIT 107 //}}AFX_DATA_INIT
108 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 108 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
109 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 109 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
110 m_bmpBack.LoadBitmap(IDB_BACKGROUND); 110 m_bmpBack.LoadBitmap(IDB_BACKGROUND);
111 m_bmpBack.GetBitmap(&m_bitmapBack); 111 m_bmpBack.GetBitmap(&m_bitmapBack);
112 m_Retrier = new CRetrier(this); 112 m_Retrier = new CRetrier(this);
113 ASSERT(m_Retrier); 113 ASSERT(m_Retrier);
114 m_Trayer = new CTrayer(this); 114 m_Trayer = new CTrayer(this);
115 ASSERT(m_Trayer); 115 ASSERT(m_Trayer);
116 /* Ensure we're backwards compatible */ 116 /* Ensure we're backwards compatible */
117 ASSERT(CPumpKINDlg::rrqGiveAll==0); 117 ASSERT(CPumpKINDlg::rrqGiveAll==0);
118 ASSERT(CPumpKINDlg::rrqAlwaysConfirm==1); 118 ASSERT(CPumpKINDlg::rrqAlwaysConfirm==1);
119 ASSERT(CPumpKINDlg::rrqDenyAll==2); 119 ASSERT(CPumpKINDlg::rrqDenyAll==2);
120 ASSERT(CPumpKINDlg::wrqTakeAll==0); 120 ASSERT(CPumpKINDlg::wrqTakeAll==0);
121 ASSERT(CPumpKINDlg::wrqConfirmIfExists==1); 121 ASSERT(CPumpKINDlg::wrqConfirmIfExists==1);
122 ASSERT(CPumpKINDlg::wrqAlwaysConfirm==2); 122 ASSERT(CPumpKINDlg::wrqAlwaysConfirm==2);
123 ASSERT(CPumpKINDlg::wrqDenyAll==3); 123 ASSERT(CPumpKINDlg::wrqDenyAll==3);
124 /* -- */ 124 /* -- */
125 LoadSettings(); 125 LoadSettings();
126} 126}
127 127
128void CPumpKINDlg::DoDataExchange(CDataExchange* pDX) 128void CPumpKINDlg::DoDataExchange(CDataExchange* pDX)
129{ 129{
130 CDialog::DoDataExchange(pDX); 130 CDialog::DoDataExchange(pDX);
131 //{{AFX_DATA_MAP(CPumpKINDlg) 131 //{{AFX_DATA_MAP(CPumpKINDlg)
132 DDX_Control(pDX, ID_HELP, m_HelpCtl); 132 DDX_Control(pDX, ID_HELP, m_HelpCtl);
133 DDX_Control(pDX, IDC_PUT, m_PutCtl); 133 DDX_Control(pDX, IDC_PUT, m_PutCtl);
134 DDX_Control(pDX, IDC_GET, m_GetCtl); 134 DDX_Control(pDX, IDC_GET, m_GetCtl);
135 DDX_Control(pDX, IDC_EXIT, m_ExitCtl); 135 DDX_Control(pDX, IDC_EXIT, m_ExitCtl);
136 DDX_Control(pDX, IDC_LISTENING, m_ListenCtl); 136 DDX_Control(pDX, IDC_LISTENING, m_ListenCtl);
137 DDX_Control(pDX, IDC_ABORT, m_AbortCtl); 137 DDX_Control(pDX, IDC_ABORT, m_AbortCtl);
138 DDX_Control(pDX, IDC_OPTIONS, m_OptionsCtl); 138 DDX_Control(pDX, IDC_OPTIONS, m_OptionsCtl);
139 DDX_Control(pDX, IDC_LOG, m_Log); 139 DDX_Control(pDX, IDC_LOG, m_Log);
140 DDX_Control(pDX, IDC_CONNECTIONS, m_List); 140 DDX_Control(pDX, IDC_CONNECTIONS, m_List);
141 //}}AFX_DATA_MAP 141 //}}AFX_DATA_MAP
142} 142}
143 143
144BEGIN_MESSAGE_MAP(CPumpKINDlg, CDialog) 144BEGIN_MESSAGE_MAP(CPumpKINDlg, CDialog)
145 //{{AFX_MSG_MAP(CPumpKINDlg) 145 //{{AFX_MSG_MAP(CPumpKINDlg)
146 ON_WM_SYSCOMMAND() 146 ON_WM_SYSCOMMAND()
147 ON_WM_DESTROY() 147 ON_WM_DESTROY()
148 ON_WM_PAINT() 148 ON_WM_PAINT()
149 ON_WM_QUERYDRAGICON() 149 ON_WM_QUERYDRAGICON()
150 ON_WM_CREATE() 150 ON_WM_CREATE()
151 ON_BN_CLICKED(IDC_OPTIONS, OnOptions) 151 ON_BN_CLICKED(IDC_OPTIONS, OnOptions)
152 ON_WM_TIMER() 152 ON_WM_TIMER()
153 ON_BN_CLICKED(IDC_EXIT, OnExit) 153 ON_BN_CLICKED(IDC_EXIT, OnExit)
154 ON_BN_CLICKED(IDC_PUT, OnPut) 154 ON_BN_CLICKED(IDC_PUT, OnPut)
155 ON_BN_CLICKED(IDC_GET, OnGet) 155 ON_BN_CLICKED(IDC_GET, OnGet)
156 ON_NOTIFY(LVN_DELETEALLITEMS, IDC_CONNECTIONS, OnDeleteallitemsConnections) 156 ON_NOTIFY(LVN_DELETEALLITEMS, IDC_CONNECTIONS, OnDeleteallitemsConnections)
157 ON_NOTIFY(LVN_DELETEITEM, IDC_CONNECTIONS, OnDeleteitemConnections) 157 ON_NOTIFY(LVN_DELETEITEM, IDC_CONNECTIONS, OnDeleteitemConnections)
158 ON_NOTIFY(LVN_INSERTITEM, IDC_CONNECTIONS, OnInsertitemConnections) 158 ON_NOTIFY(LVN_INSERTITEM, IDC_CONNECTIONS, OnInsertitemConnections)
159 ON_NOTIFY(LVN_ITEMCHANGED, IDC_CONNECTIONS, OnItemchangedConnections) 159 ON_NOTIFY(LVN_ITEMCHANGED, IDC_CONNECTIONS, OnItemchangedConnections)
160 ON_BN_CLICKED(IDC_ABORT, OnAbort) 160 ON_BN_CLICKED(IDC_ABORT, OnAbort)
161 ON_WM_CLOSE() 161 ON_WM_CLOSE()
162 ON_COMMAND(ID_TRAY_SHOWPUMPKINWINDOW, OnTrayShowpumpkinwindow) 162 ON_COMMAND(ID_TRAY_SHOWPUMPKINWINDOW, OnTrayShowpumpkinwindow)
163 ON_COMMAND(ID_TRAY_LISTEN, OnTrayListen) 163 ON_COMMAND(ID_TRAY_LISTEN, OnTrayListen)
164 ON_COMMAND(ID_TRAY_EXIT, OnTrayExit) 164 ON_COMMAND(ID_TRAY_EXIT, OnTrayExit)
165 ON_COMMAND(ID_TRAY_ABOUTPUMPKIN, OnTrayAboutpumpkin) 165 ON_COMMAND(ID_TRAY_ABOUTPUMPKIN, OnTrayAboutpumpkin)
166 ON_COMMAND(ID_TRAY_FETCHFILE, OnTrayFetchfile) 166 ON_COMMAND(ID_TRAY_FETCHFILE, OnTrayFetchfile)
167 ON_COMMAND(ID_TRAY_HELP, OnTrayHelp) 167 ON_COMMAND(ID_TRAY_HELP, OnTrayHelp)
168 ON_COMMAND(ID_TRAY_OPTIONS, OnTrayOptions) 168 ON_COMMAND(ID_TRAY_OPTIONS, OnTrayOptions)
169 ON_COMMAND(ID_TRAY_SENDFILE, OnTraySendfile) 169 ON_COMMAND(ID_TRAY_SENDFILE, OnTraySendfile)
170 ON_WM_WINDOWPOSCHANGING() 170 ON_WM_WINDOWPOSCHANGING()
171 ON_LBN_SELCHANGE(IDC_LOG, OnSelchangeLog) 171 ON_LBN_SELCHANGE(IDC_LOG, OnSelchangeLog)
172 ON_COMMAND(ID_TRAY_OPENFILESFOLDER, OnTrayOpenfilesfolder) 172 ON_COMMAND(ID_TRAY_OPENFILESFOLDER, OnTrayOpenfilesfolder)
173 ON_WM_DROPFILES() 173 ON_WM_DROPFILES()
174 ON_BN_CLICKED(ID_HELP, OnHelp) 174 ON_BN_CLICKED(ID_HELP, OnHelp)
175 ON_BN_CLICKED(IDC_LISTENING, OnListening) 175 ON_BN_CLICKED(IDC_LISTENING, OnListening)
176 ON_WM_GETMINMAXINFO() 176 ON_WM_GETMINMAXINFO()
177 ON_WM_SIZE() 177 ON_WM_SIZE()
178 //}}AFX_MSG_MAP 178 //}}AFX_MSG_MAP
179END_MESSAGE_MAP() 179END_MESSAGE_MAP()
180 180
181///////////////////////////////////////////////////////////////////////////// 181/////////////////////////////////////////////////////////////////////////////
182// CPumpKINDlg message handlers 182// CPumpKINDlg message handlers
183 183
184BOOL CPumpKINDlg::OnInitDialog() 184BOOL CPumpKINDlg::OnInitDialog()
185{ 185{
186 CDialog::OnInitDialog(); 186 CDialog::OnInitDialog();
187 187
188 // Add "About..." menu item to system menu. 188 // Add "About..." menu item to system menu.
189 189
190 // IDM_ABOUTBOX must be in the system command range. 190 // IDM_ABOUTBOX must be in the system command range.
191 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 191 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
192 ASSERT(IDM_ABOUTBOX < 0xF000); 192 ASSERT(IDM_ABOUTBOX < 0xF000);
193 193
194 CMenu* pSysMenu = GetSystemMenu(FALSE); 194 CMenu* pSysMenu = GetSystemMenu(FALSE);
195 CString strAboutMenu; 195 CString strAboutMenu;
196 strAboutMenu.LoadString(IDS_ABOUTBOX); 196 strAboutMenu.LoadString(IDS_ABOUTBOX);
197 if (!strAboutMenu.IsEmpty()) 197 if (!strAboutMenu.IsEmpty())
198 { 198 {
199 pSysMenu->AppendMenu(MF_SEPARATOR); 199 pSysMenu->AppendMenu(MF_SEPARATOR);
200 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 200 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
201 } 201 }
202 202
203 // Set the icon for this dialog. The framework does this automatically 203 // Set the icon for this dialog. The framework does this automatically
204 // when the application's main window is not a dialog 204 // when the application's main window is not a dialog
205 SetIcon(m_hIcon, TRUE); // Set big icon 205 SetIcon(m_hIcon, TRUE); // Set big icon
206 SetIcon(m_hIcon, FALSE); // Set small icon 206 SetIcon(m_hIcon, FALSE); // Set small icon
207 207
208 VERIFY(m_Retrier->Create(NULL,"PumpKIN-Retrier",WS_CHILD,CRect(0,0,0,0),this,0)); 208 VERIFY(m_Retrier->Create(NULL,"PumpKIN-Retrier",WS_CHILD,CRect(0,0,0,0),this,0));
209 209
210 m_Images.Create(16,16,TRUE,2,1); 210 m_Images.Create(16,16,TRUE,2,1);
211 m_iRRQ = m_Images.Add(AfxGetApp()->LoadIcon(IDI_RRQ)); 211 m_iRRQ = m_Images.Add(AfxGetApp()->LoadIcon(IDI_RRQ));
212 m_iWRQ = m_Images.Add(AfxGetApp()->LoadIcon(IDI_WRQ)); 212 m_iWRQ = m_Images.Add(AfxGetApp()->LoadIcon(IDI_WRQ));
213 ASSERT(m_iRRQ>=0); 213 ASSERT(m_iRRQ>=0);
214 ASSERT(m_iWRQ>=0); 214 ASSERT(m_iWRQ>=0);
215 m_List.SetImageList(&m_Images,LVSIL_NORMAL); 215 m_List.SetImageList(&m_Images,LVSIL_NORMAL);
216 m_List.SetImageList(&m_Images,LVSIL_SMALL); 216 m_List.SetImageList(&m_Images,LVSIL_SMALL);
217 m_List.SetImageList(&m_Images,LVSIL_STATE); 217 m_List.SetImageList(&m_Images,LVSIL_STATE);
218 m_List.SetTextColor(RGB(255,255,0));// Yellow 218 m_List.SetTextColor(RGB(255,255,0));// Yellow
219 m_List.SetTextBkColor(RGB(12,167,0));// Green 219 m_List.SetTextBkColor(RGB(12,167,0));// Green
220 m_List.SetBkColor(RGB(12,167,0));// Green 220 m_List.SetBkColor(RGB(12,167,0));// Green
221CRect listrc; 221CRect listrc;
222 m_List.GetClientRect(&listrc); 222 m_List.GetClientRect(&listrc);
223 m_List.InsertColumn(0,"File",LVCFMT_LEFT,listrc.Width()-((listrc.Width()/7)*3+listrc.Width()*2/7),subitemFile); 223 m_List.InsertColumn(0,"File",LVCFMT_LEFT,listrc.Width()-((listrc.Width()/7)*3+listrc.Width()*2/7),subitemFile);
224 m_List.InsertColumn(1,"type",LVCFMT_CENTER,listrc.Width()/7,subitemType); 224 m_List.InsertColumn(1,"type",LVCFMT_CENTER,listrc.Width()/7,subitemType);
225 m_List.InsertColumn(2,"peer",LVCFMT_LEFT,listrc.Width()*2/7,subitemPeer); 225 m_List.InsertColumn(2,"peer",LVCFMT_LEFT,listrc.Width()*2/7,subitemPeer);
226 m_List.InsertColumn(3,"ACK",LVCFMT_RIGHT,listrc.Width()/7,subitemBytes); 226 m_List.InsertColumn(3,"ACK",LVCFMT_RIGHT,listrc.Width()/7,subitemBytes);
227 m_List.InsertColumn(4,"tsize",LVCFMT_RIGHT,listrc.Width()/7,subitemTSize); 227 m_List.InsertColumn(4,"tsize",LVCFMT_RIGHT,listrc.Width()/7,subitemTSize);
228 228
229 LogLine(IDS_LOG_START); 229 LogLine(IDS_LOG_START);
230 230
231 SetupButtons(); 231 SetupButtons();
232 232
233CRect wrci, wrco; 233CRect wrci, wrco;
234 GetWindowRect(&wrco); 234 GetWindowRect(&wrco);
235 GetClientRect(&wrci); 235 GetClientRect(&wrci);
236CRect brc; 236CRect brc;
237 m_GetCtl.GetWindowRect(&brc); ScreenToClient(&brc); 237 m_GetCtl.GetWindowRect(&brc); ScreenToClient(&brc);
238 m_rightGapButtons = wrci.right-brc.right; 238 m_rightGapButtons = wrci.right-brc.right;
239 m_List.GetWindowRect(&brc); ScreenToClient(&brc); 239 m_List.GetWindowRect(&brc); ScreenToClient(&brc);
240 m_rightGapList = wrci.right-brc.right; 240 m_rightGapList = wrci.right-brc.right;
241 m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc); 241 m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc);
242 m_bottomGapListen = wrci.bottom-brc.bottom; 242 m_bottomGapListen = wrci.bottom-brc.bottom;
243 m_Log.GetWindowRect(&brc);ScreenToClient(&brc); 243 m_Log.GetWindowRect(&brc);ScreenToClient(&brc);
244 m_bottomGapLog = wrci.bottom-brc.bottom; 244 m_bottomGapLog = wrci.bottom-brc.bottom;
245 m_MinSize.cx = wrco.Width(); m_MinSize.cy=wrco.Height(); 245 m_MinSize.cx = wrco.Width(); m_MinSize.cy=wrco.Height();
246 246
247CRect rc, drc; 247CRect rc, drc;
248 GetWindowRect(rc); 248 GetWindowRect(rc);
249 GetDesktopWindow()->GetWindowRect(drc); 249 GetDesktopWindow()->GetWindowRect(drc);
250 SetWindowPos(NULL,drc.right-6-rc.Width(),6,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER); 250 SetWindowPos(NULL,drc.right-6-rc.Width(),6,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
251 251
252 if(m_bShown) 252 if(m_bShown)
253 ShowWindow(SW_SHOW); 253 ShowWindow(SW_SHOW);
254 else 254 else
255 ShowWindow(SW_HIDE); 255 ShowWindow(SW_HIDE);
256 256
257 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); 257 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
258 258
259 // CG: The following block was added by the ToolTips component. 259 // CG: The following block was added by the ToolTips component.
260 { 260 {
261 // Create the ToolTip control. 261 // Create the ToolTip control.
262 m_tooltip.Create(this); 262 m_tooltip.Create(this);
263 m_tooltip.Activate(TRUE); 263 m_tooltip.Activate(TRUE);
264 264
265 m_tooltip.AddTool(&m_List,IDC_CONNECTIONS); 265 m_tooltip.AddTool(&m_List,IDC_CONNECTIONS);
266 m_tooltip.AddTool(GetDlgItem(IDC_PUT),IDC_PUT); 266 m_tooltip.AddTool(GetDlgItem(IDC_PUT),IDC_PUT);
267 m_tooltip.AddTool(GetDlgItem(IDC_GET),IDC_GET); 267 m_tooltip.AddTool(GetDlgItem(IDC_GET),IDC_GET);
268 m_tooltip.AddTool(&m_AbortCtl,IDC_ABORT); 268 m_tooltip.AddTool(&m_AbortCtl,IDC_ABORT);
269 m_tooltip.AddTool(GetDlgItem(IDC_OPTIONS),IDC_OPTIONS); 269 m_tooltip.AddTool(GetDlgItem(IDC_OPTIONS),IDC_OPTIONS);
270 m_tooltip.AddTool(GetDlgItem(IDC_EXIT),IDC_EXIT); 270 m_tooltip.AddTool(GetDlgItem(IDC_EXIT),IDC_EXIT);
271 m_tooltip.AddTool(GetDlgItem(ID_HELP),ID_HELP); 271 m_tooltip.AddTool(GetDlgItem(ID_HELP),ID_HELP);
272 m_tooltip.AddTool(GetDlgItem(IDC_LOG),IDC_LOG); 272 m_tooltip.AddTool(GetDlgItem(IDC_LOG),IDC_LOG);
273 } 273 }
274 return TRUE; // return TRUE unless you set the focus to a control 274 return TRUE; // return TRUE unless you set the focus to a control
275} 275}
276 276
277void CPumpKINDlg::OnSysCommand(UINT nID, LPARAM lParam) 277void CPumpKINDlg::OnSysCommand(UINT nID, LPARAM lParam)
278{ 278{
279 if ((nID & 0xFFF0) == IDM_ABOUTBOX) 279 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
280 { 280 {
281 CAboutDlg dlgAbout; 281 CAboutDlg dlgAbout;
282 dlgAbout.DoModal(); 282 dlgAbout.DoModal();
283 } 283 }
284 else 284 else
285 { 285 {
286 CDialog::OnSysCommand(nID, lParam); 286 CDialog::OnSysCommand(nID, lParam);
287 } 287 }
288} 288}
289 289
290void CPumpKINDlg::OnDestroy() 290void CPumpKINDlg::OnDestroy()
291{ 291{
292 SaveSettings(); 292 SaveSettings();
293 293
294NOTIFYICONDATA nid; 294NOTIFYICONDATA nid;
295 memset(&nid,0,sizeof(nid)); 295 memset(&nid,0,sizeof(nid));
296 nid.cbSize=sizeof(nid); 296 nid.cbSize=sizeof(nid);
297 nid.hWnd=m_Trayer->m_hWnd; 297 nid.hWnd=m_Trayer->m_hWnd;
298 nid.uID=IDC_TRAYICON; 298 nid.uID=IDC_TRAYICON;
299 nid.uFlags=0; 299 nid.uFlags=0;
300 VERIFY(Shell_NotifyIcon(NIM_DELETE,&nid)); 300 VERIFY(Shell_NotifyIcon(NIM_DELETE,&nid));
301 301
302 WinHelp(0L, HELP_QUIT); 302 WinHelp(0L, HELP_QUIT);
303 CDialog::OnDestroy(); 303 CDialog::OnDestroy();
304POSITION p = m_LogTimes.GetStartPosition(); 304POSITION p = m_LogTimes.GetStartPosition();
305 while(p){ 305 while(p){
306 CTime *t,*tt; 306 CTime *t,*tt;
307 m_LogTimes.GetNextAssoc(p,t,tt); 307 m_LogTimes.GetNextAssoc(p,t,tt);
308 ASSERT(t && tt && t==tt); 308 ASSERT(t && tt && t==tt);
309 delete t; 309 delete t;
310 } 310 }
311 // *** Abort and cleanup transfers 311 // *** Abort and cleanup transfers
312 m_LogTimes.RemoveAll(); 312 m_LogTimes.RemoveAll();
313} 313}
314 314
315// 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
316// 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,
317// this is automatically done for you by the framework. 317// this is automatically done for you by the framework.
318 318
319void CPumpKINDlg::OnPaint() 319void CPumpKINDlg::OnPaint()
320{ 320{
321 if (IsIconic()) 321 if (IsIconic())
322 { 322 {
323 CPaintDC dc(this); // device context for painting 323 CPaintDC dc(this); // device context for painting
324 324
325 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 325 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
326 326
327 // Center icon in client rectangle 327 // Center icon in client rectangle
328 int cxIcon = GetSystemMetrics(SM_CXICON); 328 int cxIcon = GetSystemMetrics(SM_CXICON);
329 int cyIcon = GetSystemMetrics(SM_CYICON); 329 int cyIcon = GetSystemMetrics(SM_CYICON);
330 CRect rect; 330 CRect rect;
331 GetClientRect(&rect); 331 GetClientRect(&rect);
332 int x = (rect.Width() - cxIcon + 1) / 2; 332 int x = (rect.Width() - cxIcon + 1) / 2;
333 int y = (rect.Height() - cyIcon + 1) / 2; 333 int y = (rect.Height() - cyIcon + 1) / 2;
334 334
335 // Draw the icon 335 // Draw the icon
336 dc.DrawIcon(x, y, m_hIcon); 336 dc.DrawIcon(x, y, m_hIcon);
337 } 337 }
338 else 338 else
339 { 339 {
340 CPaintDC pDC(this); 340 CPaintDC pDC(this);
341 CDC bmpDC; 341 CDC bmpDC;
342 bmpDC.CreateCompatibleDC(&pDC); 342 bmpDC.CreateCompatibleDC(&pDC);
343 bmpDC.SelectObject(&m_bmpBack); 343 bmpDC.SelectObject(&m_bmpBack);
344 CRect rc; 344 CRect rc;
345 GetClientRect(&rc); 345 GetClientRect(&rc);
346 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)
347 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)
348 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);
349 bmpDC.DeleteDC(); 349 bmpDC.DeleteDC();
350 CDialog::OnPaint(); 350 CDialog::OnPaint();
351 } 351 }
352} 352}
353 353
354// 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
355// the minimized window. 355// the minimized window.
356HCURSOR CPumpKINDlg::OnQueryDragIcon() 356HCURSOR CPumpKINDlg::OnQueryDragIcon()
357{ 357{
358 return (HCURSOR) m_hIcon; 358 return (HCURSOR) m_hIcon;
359} 359}
360 360
361int CPumpKINDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 361int CPumpKINDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
362{ 362{
363 if (CDialog::OnCreate(lpCreateStruct) == -1) 363 if (CDialog::OnCreate(lpCreateStruct) == -1)
364 return -1; 364 return -1;
365 365
366 if(!m_Listener.SetListen(m_bListen)) { 366 if(!m_Listener.SetListen(m_bListen)) {
367 m_bListen=FALSE; 367 m_bListen=FALSE;
368 TRACE0("Failed to create socket\n"); 368 TRACE0("Failed to create socket\n");
369 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); 369 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
370 } 370 }
371 371
372 if(!m_Trayer->Create(NULL,"PumpKIN TrayIcon",WS_CHILD,CRect(0,0,0,0),this,0)){ 372 if(!m_Trayer->Create(NULL,"PumpKIN TrayIcon",WS_CHILD,CRect(0,0,0,0),this,0)){
373 TRACE0("Failed to create trayer\n"); 373 TRACE0("Failed to create trayer\n");
374 return -1; 374 return -1;
375 } 375 }
376 376
377NOTIFYICONDATA nid; 377NOTIFYICONDATA nid;
378 memset(&nid,0,sizeof(nid)); 378 memset(&nid,0,sizeof(nid));
379 nid.cbSize=sizeof(nid); 379 nid.cbSize=sizeof(nid);
380 nid.hWnd=m_Trayer->m_hWnd; 380 nid.hWnd=m_Trayer->m_hWnd;
381 nid.uID=IDC_TRAYICON; 381 nid.uID=IDC_TRAYICON;
382 nid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; 382 nid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
383 nid.uCallbackMessage=WM_TRAYICON; 383 nid.uCallbackMessage=WM_TRAYICON;
384 nid.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); 384 nid.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
385 // *** Load from resource 385 // *** Load from resource
386 strcpy(nid.szTip,"PumpKIN"); 386 strcpy(nid.szTip,"PumpKIN");
387 VERIFY(Shell_NotifyIcon(NIM_ADD,&nid)); 387 VERIFY(Shell_NotifyIcon(NIM_ADD,&nid));
388 388
389 return 0; 389 return 0;
390} 390}
391 391
392void CListenSocket::OnReceive(int nErrorCode) 392void CListenSocket::OnReceive(int nErrorCode)
393{ 393{
394 ASSERT(m_Daddy); 394 ASSERT(m_Daddy);
395 if(nErrorCode){ 395 if(nErrorCode){
396 m_Daddy->LogLine(IDS_LOG_LISTENRECEIVEERROR); 396 m_Daddy->LogLine(IDS_LOG_LISTENRECEIVEERROR);
397 return; 397 return;
398 } 398 }
399DWORD fionread = 0; 399DWORD fionread = 0;
400 VERIFY(IOCtl(FIONREAD,&fionread));// *** Do some checking on the value acquired 400 VERIFY(IOCtl(FIONREAD,&fionread));// *** Do some checking on the value acquired
401tftp *tftpRQ = tftp::Allocate(fionread); 401tftp *tftpRQ = tftp::Allocate(fionread);
402 ASSERT(tftpRQ); 402 ASSERT(tftpRQ);
403SOCKADDR_IN sin; 403SOCKADDR_IN sin;
404 if(!tftpRQ->Receive(this,fionread,&sin)){ 404 if(!tftpRQ->Receive(this,fionread,&sin)){
405 m_Daddy->LogLine(IDS_LOG_LISTENACCEPTERROR); 405 m_Daddy->LogLine(IDS_LOG_LISTENACCEPTERROR);
406 delete tftpRQ; 406 delete tftpRQ;
407 return; 407 return;
408 } 408 }
409 #ifndefNDEBUG 409 #ifndefNDEBUG
410CString tmp; 410CString tmp;
411 tmp.Format("%u - %s - %u\n",tftpRQ->Opcode(),inet_ntoa(sin.sin_addr),sin.sin_port); 411 tmp.Format("%u - %s - %u\n",tftpRQ->Opcode(),inet_ntoa(sin.sin_addr),sin.sin_port);
412 TRACE0(tmp); 412 TRACE0(tmp);
413#endif 413#endif
414POSITION p = m_Daddy->m_Xfers.GetStartPosition(); 414POSITION p = m_Daddy->m_Xfers.GetStartPosition();
415 while(p){ 415 while(p){
416 SOCKET key; 416 SOCKET key;
417 CXferSocket *sock; 417 CXferSocket *sock;
418 m_Daddy->m_Xfers.GetNextAssoc(p,key,sock); 418 m_Daddy->m_Xfers.GetNextAssoc(p,key,sock);
419 ASSERT(sock); 419 ASSERT(sock);
420 if(sock->m_Peer.sin_addr.s_addr==sin.sin_addr.s_addr && sock->m_Peer.sin_port==sin.sin_port){ 420 if(sock->m_Peer.sin_addr.s_addr==sin.sin_addr.s_addr && sock->m_Peer.sin_port==sin.sin_port){
421 TRACE0("Ignoring request which we are already processing\n"); 421 TRACE0("Ignoring request which we are already processing\n");
422 delete tftpRQ; 422 delete tftpRQ;
423 return; 423 return;
424 } 424 }
425 } 425 }
426 switch(tftpRQ->Opcode()){ 426 switch(tftpRQ->Opcode()){
427 case tftp::opRRQ: 427 case tftp::opRRQ:
428 // Read Request 428 // Read Request
429 { 429 {
430 CString tmp; 430 CString tmp;
431 tmp.Format(IDS_LOG_RRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr)); 431 tmp.Format(IDS_LOG_RRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr));
432 m_Daddy->LogLine(tmp); 432 m_Daddy->LogLine(tmp);
433 CRRQSocket *s = new CRRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin); 433 CRRQSocket *s = new CRRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin);
434 ASSERT(s); 434 ASSERT(s);
435 tftpRQ->GetOptions(&s->m_Options); 435 tftpRQ->GetOptions(&s->m_Options);
436 if(!s->Create()) 436 if(!s->Create())
437 s->Destroy(FALSE); 437 s->Destroy(FALSE);
438 } 438 }
439 break; 439 break;
440 case tftp::opWRQ: 440 case tftp::opWRQ:
441 // Write Request 441 // Write Request
442 { 442 {
443 CString tmp; 443 CString tmp;
444 tmp.Format(IDS_LOG_WRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr)); 444 tmp.Format(IDS_LOG_WRQSERVE,tftpRQ->rqFileName(),tftpRQ->rqType(),inet_ntoa(sin.sin_addr));
445 m_Daddy->LogLine(tmp); 445 m_Daddy->LogLine(tmp);
446 CWRQSocket *s = new CWRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin); 446 CWRQSocket *s = new CWRQSocket(m_Daddy,tftpRQ->rqFileName(),tftpRQ->rqType(),&sin);
447 ASSERT(s); 447 ASSERT(s);
448 tftpRQ->GetOptions(&s->m_Options); 448 tftpRQ->GetOptions(&s->m_Options);
449 if(!s->Create(NULL,NULL)) 449 if(!s->Create(NULL,NULL))
450 s->Destroy(FALSE); 450 s->Destroy(FALSE);
451 } 451 }
452 break; 452 break;
453 default: 453 default:
454 m_Daddy->LogLine(IDS_LOG_LISTENOPCODE); 454 m_Daddy->LogLine(IDS_LOG_LISTENOPCODE);
455 delete tftpRQ; 455 delete tftpRQ;
456 return; 456 return;
457 } 457 }
458 delete tftpRQ; 458 delete tftpRQ;
459} 459}
460 460
461BOOL tftp::Receive(CAsyncSocket* socket,UINT maxLength,SOCKADDR_IN *sin) 461BOOL tftp::Receive(CAsyncSocket* socket,UINT maxLength,SOCKADDR_IN *sin)
462{ 462{
463 ASSERT(socket); 463 ASSERT(socket);
464int saddrLen = sizeof(SOCKADDR_IN); 464int saddrLen = sizeof(SOCKADDR_IN);
465 length = sin ? 465 length = sin ?
466 socket->ReceiveFrom(udpBase(),maxLength,(SOCKADDR*)sin,&saddrLen) 466 socket->ReceiveFrom(udpBase(),maxLength,(SOCKADDR*)sin,&saddrLen)
467 : 467 :
468 socket->Receive(udpBase(),maxLength) 468 socket->Receive(udpBase(),maxLength)
469 ; 469 ;
470 if(!length) 470 if(!length)
471 return FALSE; 471 return FALSE;
472 if(length==(tftpLength)SOCKET_ERROR) 472 if(length==(tftpLength)SOCKET_ERROR)
473 return FALSE; 473 return FALSE;
474 return TRUE; 474 return TRUE;
475} 475}
476 476
477UINT tftp::Opcode() 477UINT tftp::Opcode()
478{ 478{
479 return REVERSEBYTES(opcode); 479 return REVERSEBYTES(opcode);
480} 480}
481 481
482CString tftp::rqFileName() 482CString tftp::rqFileName()
483{ 483{
484 ASSERT(length); 484 ASSERT(length);
485 ASSERT(Opcode()==opRRQ || Opcode()==opWRQ); 485 ASSERT(Opcode()==opRRQ || Opcode()==opWRQ);
486CString rv; 486CString rv;
487 if(memchr(&data.m_RQ.data,0,length-sizeof(opcode))) 487 if(memchr(&data.m_RQ.data,0,length-sizeof(opcode)))
488 rv = (LPCTSTR)data.m_RQ.data; 488 rv = (LPCTSTR)data.m_RQ.data;
489 return rv; 489 return rv;
490} 490}
491 491
492CString tftp::rqType() 492CString tftp::rqType()
493{ 493{
494 ASSERT(length); 494 ASSERT(length);
495 ASSERT(Opcode()==opRRQ || Opcode()==opWRQ); 495 ASSERT(Opcode()==opRRQ || Opcode()==opWRQ);
496CString rv; 496CString rv;
497char *tmp = (char*)memchr(&data.m_RQ.data,0,length-sizeof(opcode)); 497char *tmp = (char*)memchr(&data.m_RQ.data,0,length-sizeof(opcode));
498 if(tmp++) 498 if(tmp++)
499 rv = (LPCTSTR)tmp; 499 rv = (LPCTSTR)tmp;
500 return rv; 500 return rv;
501} 501}
502 502
503UINT tftp::GetOptions(tftp::tftpOptions* ops) 503UINT tftp::GetOptions(tftp::tftpOptions* ops)
504{ 504{
505 ASSERT(length); 505 ASSERT(length);
506 ASSERT(Opcode()==opRRQ || Opcode()==opWRQ || Opcode()==opOACK); 506 ASSERT(Opcode()==opRRQ || Opcode()==opWRQ || Opcode()==opOACK);
507 ASSERT(ops); 507 ASSERT(ops);
508tftpOptions& o = *ops; 508tftpOptions& o = *ops;
509LPSTR base = (LPSTR)&data.m_RQ.data; 509LPSTR base = (LPSTR)&data.m_RQ.data;
510UINT basePtr = 0; 510UINT basePtr = 0;
511 if(Opcode()==opRRQ || Opcode()==opWRQ){ 511 if(Opcode()==opRRQ || Opcode()==opWRQ){
512 base = (LPSTR)memchr(&data.m_RQ.data,0,length-sizeof(opcode)); 512 base = (LPSTR)memchr(&data.m_RQ.data,0,length-sizeof(opcode));
513 if(!base) 513 if(!base)
514 return 0; 514 return 0;
515 base++; 515 base++;
516 basePtr = (base-(LPSTR)&data.m_RQ.data); 516 basePtr = (base-(LPSTR)&data.m_RQ.data);
517 base = (LPSTR)memchr(base,0,length-basePtr); 517 base = (LPSTR)memchr(base,0,length-basePtr);
518 if(!base) 518 if(!base)
519 return 0; 519 return 0;
520 base++; 520 base++;
521 basePtr = (base-(LPSTR)&data.m_RQ.data); 521 basePtr = (base-(LPSTR)&data.m_RQ.data);
522 } 522 }
523 ops->RemoveAll(); 523 ops->RemoveAll();
524UINT rv = 0; 524UINT rv = 0;
525 while(basePtr<(length-sizeof(opcode))){ 525 while(basePtr<(length-sizeof(opcode))){
526 CString onam = (LPSTR)&data.m_RQ.data[basePtr]; 526 CString onam = (LPSTR)&data.m_RQ.data[basePtr];
527 basePtr+=onam.GetLength()+1; 527 basePtr+=onam.GetLength()+1;
528 CString oval = (LPSTR)&data.m_RQ.data[basePtr]; 528 CString oval = (LPSTR)&data.m_RQ.data[basePtr];
529 basePtr+=oval.GetLength()+1; 529 basePtr+=oval.GetLength()+1;
530 onam.MakeLower(); 530 onam.MakeLower();
531 o[onam]=oval; 531 o[onam]=oval;
532 rv++; 532 rv++;
533 } 533 }
534 return rv; 534 return rv;
535} 535}
536 536
537tftp::tftp() 537tftp::tftp()
538{ 538{
539 length=0; 539 length=0;
540} 540}
541 541
542 542
543void CXferSocket::OnSend(int nErrorCode) 543void CXferSocket::OnSend(int nErrorCode)
544{ 544{
545 if(nErrorCode){ 545 if(nErrorCode){
546 ASSERT(m_Daddy); 546 ASSERT(m_Daddy);
547 m_Daddy->LogLine(IDS_LOG_XFERSEND); 547 m_Daddy->LogLine(IDS_LOG_XFERSEND);
548 return; 548 return;
549 } 549 }
550 if(!m_Queue.IsEmpty()){ 550 if(!m_Queue.IsEmpty()){
551 tftp *p = m_Queue.GetHead(); 551 tftp *p = m_Queue.GetHead();
552 ASSERT(p); 552 ASSERT(p);
553 m_Queue.RemoveHead(); 553 m_Queue.RemoveHead();
554 if(!p->Send(this,&m_Peer)){ 554 if(!p->Send(this,&m_Peer)){
555 ASSERT(m_Daddy); 555 ASSERT(m_Daddy);
556 m_Daddy->LogLine(IDS_LOG_XFERUDPSEND); 556 m_Daddy->LogLine(IDS_LOG_XFERUDPSEND);
557 } 557 }
558 delete p; 558 delete p;
559 } 559 }
560 DoSelect(); 560 DoSelect();
561 if(m_Queue.IsEmpty()){ 561 if(m_Queue.IsEmpty()){
562 switch(state){ 562 switch(state){
563 case stateDeny: 563 case stateDeny:
564 Destroy(FALSE); 564 Destroy(FALSE);
565 break; 565 break;
566 case stateFinish: 566 case stateFinish:
567 Destroy(TRUE); 567 Destroy(TRUE);
568 break; 568 break;
569 } 569 }
570 } 570 }
571} 571}
572 572
573BOOL tftp::Send(CAsyncSocket *socket,SOCKADDR_IN* saddr) 573BOOL tftp::Send(CAsyncSocket *socket,SOCKADDR_IN* saddr)
574{ 574{
575 ASSERT(socket); 575 ASSERT(socket);
576int rv = socket->SendTo(udpBase(),length,(SOCKADDR*)saddr,sizeof(SOCKADDR_IN)); 576int rv = socket->SendTo(udpBase(),length,(SOCKADDR*)saddr,sizeof(SOCKADDR_IN));
577 if(rv!=length) 577 if(rv!=length)
578 return FALSE; 578 return FALSE;
579 return TRUE; 579 return TRUE;
580} 580}
581 581
582void CXferSocket::DoSelect(BOOL do_select) 582void CXferSocket::DoSelect(BOOL do_select)
583{ 583{
584 if(m_Peer.sin_addr.s_addr!=INADDR_NONE) 584 if(m_Peer.sin_addr.s_addr!=INADDR_NONE)
585 AsyncSelect(FD_CLOSE|FD_READ|((m_Queue.IsEmpty()&&!do_select)?0:FD_WRITE)); 585 AsyncSelect(FD_CLOSE|FD_READ|((m_Queue.IsEmpty()&&!do_select)?0:FD_WRITE));
586} 586}
587 587
588void CXferSocket::OnReceive(int nErrorCode) 588void CXferSocket::OnReceive(int nErrorCode)
589{ 589{
590 if(nErrorCode){ 590 if(nErrorCode){
591 ASSERT(m_Daddy); 591 ASSERT(m_Daddy);
592 m_Daddy->LogLine(IDS_LOG_XFERRECEIVE); 592 m_Daddy->LogLine(IDS_LOG_XFERRECEIVE);
593 return; 593 return;
594 } 594 }
595 ASSERT(m_Daddy); 595 ASSERT(m_Daddy);
596DWORD fionread = 0; 596DWORD fionread = 0;
597 VERIFY(IOCtl(FIONREAD,&fionread)); 597 VERIFY(IOCtl(FIONREAD,&fionread));
598tftp *p = tftp::Allocate(fionread); 598tftp *p = tftp::Allocate(fionread);
599 ASSERT(p); 599 ASSERT(p);
600SOCKADDR_IN sin; 600SOCKADDR_IN sin;
601 if(!p->Receive(this,fionread,&sin)){ 601 if(!p->Receive(this,fionread,&sin)){
602 m_Daddy->LogLine(IDS_LOG_XFERUDPRECEIVE); 602 m_Daddy->LogLine(IDS_LOG_XFERUDPRECEIVE);
603 delete p; 603 delete p;
604 }else 604 }else
605 if(m_Peer.sin_addr.s_addr==INADDR_NONE){ 605 if(m_Peer.sin_addr.s_addr==INADDR_NONE){
606 m_Peer.sin_addr=sin.sin_addr; 606 m_Peer.sin_addr=sin.sin_addr;
607 m_Peer.sin_port=sin.sin_port; 607 m_Peer.sin_port=sin.sin_port;
608 } 608 }
609BOOL alive = TRUE; 609BOOL alive = TRUE;
610 if(state==stateInit){ 610 if(state==stateInit){
611 state=stateXfer; 611 state=stateXfer;
612 m_Peer.sin_port=sin.sin_port; 612 m_Peer.sin_port=sin.sin_port;
613 UpdateList(); 613 UpdateList();
614 } 614 }
615 if(sin.sin_addr.s_addr!=m_Peer.sin_addr.s_addr || sin.sin_port!=m_Peer.sin_port){ 615 if(sin.sin_addr.s_addr!=m_Peer.sin_addr.s_addr || sin.sin_port!=m_Peer.sin_port){
616 m_Daddy->LogLine(IDS_LOG_XFERSOURCETID); 616 m_Daddy->LogLine(IDS_LOG_XFERSOURCETID);
617 // *** Bounce it! 617 // *** Bounce it!
618 }else{ 618 }else{
619 alive = OnTFTP(p); 619 alive = OnTFTP(p);
620 } 620 }
621 delete p; 621 delete p;
622 if(alive){ 622 if(alive){
623 DoSelect(); 623 DoSelect();
624 ResetTimeout(); 624 ResetTimeout();
625 } 625 }
626} 626}
627 627
628void CXferSocket::SetPeer(SOCKADDR_IN *sin) 628void CXferSocket::SetPeer(SOCKADDR_IN *sin)
629{ 629{
630 ASSERT(sin); 630 ASSERT(sin);
631 memmove(&m_Peer,sin,sizeof(m_Peer)); 631 memmove(&m_Peer,sin,sizeof(m_Peer));
632} 632}
633 633
634void CXferSocket::UpdateList() 634void CXferSocket::UpdateList()
635{ 635{
636 ASSERT(m_Daddy); 636 ASSERT(m_Daddy);
637LV_FINDINFO lvf; 637LV_FINDINFO lvf;
638 memset(&lvf,0,sizeof(lvf)); 638 memset(&lvf,0,sizeof(lvf));
639 lvf.flags=LVFI_PARAM; 639 lvf.flags=LVFI_PARAM;
640 lvf.lParam=(LPARAM)this; 640 lvf.lParam=(LPARAM)this;
641int i = m_Daddy->m_List.FindItem(&lvf); 641int i = m_Daddy->m_List.FindItem(&lvf);
642 if(i<0){ 642 if(i<0){
643 ASSERT(IsKindOf(RUNTIME_CLASS(CRRQSocket)) || IsKindOf(RUNTIME_CLASS(CWRQSocket))); 643 ASSERT(IsKindOf(RUNTIME_CLASS(CRRQSocket)) || IsKindOf(RUNTIME_CLASS(CWRQSocket)));
644 i=m_Daddy->m_List.InsertItem(0,m_FileName,IsKindOf(RUNTIME_CLASS(CRRQSocket))?m_Daddy->m_iRRQ:m_Daddy->m_iWRQ); 644 i=m_Daddy->m_List.InsertItem(0,m_FileName,IsKindOf(RUNTIME_CLASS(CRRQSocket))?m_Daddy->m_iRRQ:m_Daddy->m_iWRQ);
645 ASSERT(!(i<0)); 645 ASSERT(!(i<0));
646 m_Daddy->m_List.SetItemData(i,(DWORD)this); 646 m_Daddy->m_List.SetItemData(i,(DWORD)this);
647 } 647 }
648 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemFile,m_FileName); 648 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemFile,m_FileName);
649 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemType,m_Type); 649 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemType,m_Type);
650 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemPeer,inet_ntoa(m_Peer.sin_addr)); 650 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemPeer,inet_ntoa(m_Peer.sin_addr));
651CString tmp; 651CString tmp;
652 tmp.Format(IDS_FMT_BYTES,GetACK()); 652 tmp.Format(IDS_FMT_BYTES,GetACK());
653 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemBytes,tmp); 653 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemBytes,tmp);
654 if(m_xferSize>=0){ 654 if(m_xferSize>=0){
655 tmp.Format(IDS_FMT_BYTES,m_xferSize); 655 tmp.Format(IDS_FMT_BYTES,m_xferSize);
656 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemTSize,tmp); 656 m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemTSize,tmp);
657 } 657 }
658} 658}
659 659
660CXferSocket::CXferSocket() 660CXferSocket::CXferSocket()
661 : m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE), 661 : m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE),
662 m_blkSize(512), m_timeOut(30), m_xferSize(-1), 662 m_blkSize(512), m_timeOut(30), m_xferSize(-1),
663 m__blkSize(512), m__timeOut(30) 663 m__blkSize(512), m__timeOut(30)
664{ 664{
665 m_Daddy=NULL; 665 m_Daddy=NULL;
666 m_Peer.sin_addr.s_addr=INADDR_NONE; 666 m_Peer.sin_addr.s_addr=INADDR_NONE;
667 m_Peer.sin_family=AF_INET; 667 m_Peer.sin_family=AF_INET;
668 state=stateNone; 668 state=stateNone;
669} 669}
670 670
671ULONG CXferSocket::GetACK() 671ULONG CXferSocket::GetACK()
672{ 672{
673 return 0; 673 return 0;
674} 674}
675 675
676CXferSocket::CXferSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN* sin) 676CXferSocket::CXferSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN* sin)
677 : m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE), 677 : m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE),
678 m_blkSize(512), m_timeOut(30), m_xferSize(-1), 678 m_blkSize(512), m_timeOut(30), m_xferSize(-1),
679 m__blkSize(512), m__timeOut(30) 679 m__blkSize(512), m__timeOut(30)
680{ 680{
681 m_Peer.sin_family=AF_INET; 681 m_Peer.sin_family=AF_INET;
682 state=stateNone; 682 state=stateNone;
683 ASSERT(daddy); 683 ASSERT(daddy);
684 m_Daddy=daddy; 684 m_Daddy=daddy;
685 m_timeOut=m__timeOut=m_Daddy->m_TFTPTimeOut.GetTotalSeconds(); 685 m_timeOut=m__timeOut=m_Daddy->m_TFTPTimeOut.GetTotalSeconds();
686 if(sin){ 686 if(sin){
687 m_Peer.sin_addr.s_addr=sin->sin_addr.s_addr; 687 m_Peer.sin_addr.s_addr=sin->sin_addr.s_addr;
688 m_Peer.sin_port=sin->sin_port; 688 m_Peer.sin_port=sin->sin_port;
689 }else 689 }else
690 m_Peer.sin_addr.s_addr=INADDR_NONE; 690 m_Peer.sin_addr.s_addr=INADDR_NONE;
691 m_FileName=fileName; 691 m_FileName=fileName;
692 m_Type=type; 692 m_Type=type;
693} 693}
694 694
695BOOL CRRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName) 695BOOL CRRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName)
696{ 696{
697 if(!CAsyncSocket::Create(0,SOCK_DGRAM)) 697 if(!CAsyncSocket::Create(0,SOCK_DGRAM))
698 return FALSE; 698 return FALSE;
699 ASSERT(m_Daddy); 699 ASSERT(m_Daddy);
700 ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName); 700 ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName);
701 m_Daddy->m_Xfers[m_hSocket]=this; 701 m_Daddy->m_Xfers[m_hSocket]=this;
702CString lFile = localFile?localFile:m_FileName; 702CString lFile = localFile?localFile:m_FileName;
703 TurnSlashes(lFile,TRUE); 703 TurnSlashes(lFile,TRUE);
704 UpdateList(); 704 UpdateList();
705 if(!localFile){// Check only for incoming requests 705 if(!localFile){// Check only for incoming requests
706 if(CheckBadRelativeness(m_FileName)){ 706 if(CheckBadRelativeness(m_FileName)){
707 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); 707 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
708 return TRUE; 708 return TRUE;
709 } 709 }
710 int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opRRQ,m_Peer.sin_addr.s_addr); 710 int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opRRQ,m_Peer.sin_addr.s_addr);
711 if(atar<0) 711 if(atar<0)
712 atar = m_Daddy->m_RRQMode; 712 atar = m_Daddy->m_RRQMode;
713 switch(atar){ 713 switch(atar){
714 case CPumpKINDlg::rrqGiveAll: 714 case CPumpKINDlg::rrqGiveAll:
715 break; 715 break;
716 case CPumpKINDlg::rrqAlwaysConfirm: 716 case CPumpKINDlg::rrqAlwaysConfirm:
717 if(ConfirmRequest()) 717 if(ConfirmRequest())
718 break; 718 break;
719 default: 719 default:
720 TRACE1("Unexpected access target: %d\n",atar); 720 TRACE1("Unexpected access target: %d\n",atar);
721 case CPumpKINDlg::rrqDenyAll: 721 case CPumpKINDlg::rrqDenyAll:
722 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); 722 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
723 return TRUE; 723 return TRUE;
724 } 724 }
725 } 725 }
726CString fn = localFile?ApplyRootGently(lFile):ApplyRoot(lFile); 726CString fn = localFile?ApplyRootGently(lFile):ApplyRoot(lFile);
727CFileException e; 727CFileException e;
728 if(!m_File.Open(fn,CFile::modeRead|CFile::shareDenyWrite,&e)){ 728 if(!m_File.Open(fn,CFile::modeRead|CFile::shareDenyWrite,&e)){
729 if(localFile){ 729 if(localFile){
730 CString tmp; 730 CString tmp;
731 tmp.Format(IDS_LOG_FAILEDLOCALFILE,fn); 731 tmp.Format(IDS_LOG_FAILEDLOCALFILE,fn);
732 m_Daddy->LogLine(tmp); 732 m_Daddy->LogLine(tmp);
733 return FALSE; 733 return FALSE;
734 } 734 }
735 Deny(&e); 735 Deny(&e);
736 return TRUE; 736 return TRUE;
737 } 737 }
738 m_xferSize=m_File.GetLength();// *** HANDLE EXCEPTION 738 m_xferSize=m_File.GetLength();// *** HANDLE EXCEPTION
739 if(hostName){ 739 if(hostName){
740 m_HostName=hostName; 740 m_HostName=hostName;
741 741
742 CString tmp; 742 CString tmp;
743 tmp.Format(IDS_LOG_SENDING,m_FileName,m_HostName); 743 tmp.Format(IDS_LOG_SENDING,m_FileName,m_HostName);
744 m_Daddy->LogLine(tmp); 744 m_Daddy->LogLine(tmp);
745 745
746 CString inAddr = hostName; 746 CString inAddr = hostName;
747 int at = inAddr.Find('@'); 747 int at = inAddr.Find('@');
748 if(at>=0) 748 if(at>=0)
749 inAddr=inAddr.Mid(at+1); 749 inAddr=inAddr.Mid(at+1);
750 if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){ 750 if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){
751 ASSERT(!m_wndResolver); 751 ASSERT(!m_wndResolver);
752 m_wndResolver = new CResolver(this); 752 m_wndResolver = new CResolver(this);
753 ASSERT(m_wndResolver); 753 ASSERT(m_wndResolver);
754 return m_wndResolver->Resolve(); 754 return m_wndResolver->Resolve();
755 } 755 }
756 else 756 else
757 OnHostKnown(); 757 OnHostKnown();
758 }else{ 758 }else{
759 tftp::tftpOptions o; 759 tftp::tftpOptions o;
760 CString v; 760 CString v;
761 if(m_Options.Lookup(tftpoBSize,v)){ 761 if(m_Options.Lookup(tftpoBSize,v)){
762 m__blkSize=atoi(v); 762 m__blkSize=atoi(v);
763 if(m__blkSize){ 763 if(m__blkSize){
764 m_blkSize=m__blkSize; 764 m_blkSize=m__blkSize;
765 v.Format("%u",m_blkSize); 765 v.Format("%u",m_blkSize);
766 o[tftpoBSize]=v; 766 o[tftpoBSize]=v;
767 } 767 }
768 } 768 }
769 if(m_Options.Lookup(tftpoTSize,v)){ 769 if(m_Options.Lookup(tftpoTSize,v)){
770 v.Format("%lu",m_xferSize); 770 v.Format("%lu",m_xferSize);
771 o[tftpoTSize]=v; 771 o[tftpoTSize]=v;
772 } 772 }
773 if(m_Options.Lookup(tftpoTOut,v)){ 773 if(m_Options.Lookup(tftpoTOut,v)){
774 m__timeOut=atoi(v); 774 m__timeOut=atoi(v);
775 if(m__timeOut){ 775 if(m__timeOut){
776 m_timeOut=m__timeOut; 776 m_timeOut=m__timeOut;
777 v.Format("%u",m_timeOut); 777 v.Format("%u",m_timeOut);
778 o[tftpoTOut]=v; 778 o[tftpoTOut]=v;
779 } 779 }
780 } 780 }
781 // XXX: see if we can enforce our preference regarding block size here.
782 if(m_xferSize >= (m_blkSize<<16)) {
783 Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG);
784 return TRUE;
785 }
781 state = stateXfer; 786 state = stateXfer;
782 m_ACK=0; 787 m_ACK=0;
783 if(o.GetCount()){ 788 if(o.GetCount()){
784 tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o)); 789 tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o));
785 ASSERT(p); 790 ASSERT(p);
786 p->SetOpcode(tftp::opOACK); 791 p->SetOpcode(tftp::opOACK);
787 p->data.m_OACK.Set(&o); 792 p->data.m_OACK.Set(&o);
788 PostTFTP(p,TRUE); 793 PostTFTP(p,TRUE);
789 }else 794 }else
790 DoXfer(); 795 DoXfer();
791 } 796 }
792 return TRUE; 797 return TRUE;
793} 798}
794 799
795CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) 800CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin)
796 : CXferSocket(daddy,fileName,type,sin) 801 : CXferSocket(daddy,fileName,type,sin)
797{ 802{
798 m_ACK=0; 803 m_ACK=0;
799 m_LastSlack=0; 804 m_LastSlack=0;
800} 805}
801 806
802UINT tftp::tftpERROR::tftpSize(LPCTSTR msg) 807UINT tftp::tftpERROR::tftpSize(LPCTSTR msg)
803{ 808{
804 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1; 809 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1;
805} 810}
806 811
807tftp* tftp::Allocate(UINT tftpSize) 812tftp* tftp::Allocate(UINT tftpSize)
808{ 813{
809 ASSERT(tftpSize); 814 ASSERT(tftpSize);
810tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize]; 815tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize];
811 ASSERT(rv); 816 ASSERT(rv);
812 rv->length=tftpSize; 817 rv->length=tftpSize;
813 return rv; 818 return rv;
814} 819}
815 820
816void tftp::errSet(UINT code,LPCTSTR msg) 821void tftp::errSet(UINT code,LPCTSTR msg)
817{ 822{
818 ASSERT(this); 823 ASSERT(this);
819 ASSERT(length>=data.m_ERROR.tftpSize(msg)); 824 ASSERT(length>=data.m_ERROR.tftpSize(msg));
820 strcpy((char*)data.m_ERROR.data,msg); 825 strcpy((char*)data.m_ERROR.data,msg);
821 data.m_ERROR.SetCode(code); 826 data.m_ERROR.SetCode(code);
822} 827}
823 828
824void CXferSocket::PostTFTP(tftp* p,BOOL retryable) 829void CXferSocket::PostTFTP(tftp* p,BOOL retryable)
825{ 830{
826 ASSERT(p); 831 ASSERT(p);
827 m_Queue.AddTail(p); 832 m_Queue.AddTail(p);
828 DoSelect(); 833 DoSelect();
829 if(!m_bRetry){ 834 if(!m_bRetry){
830 if(retryable) 835 if(retryable)
831 SetTry(p); 836 SetTry(p);
832 else 837 else
833 SetTry(); 838 SetTry();
834 } 839 }
835 ResetTimeout(); 840 ResetTimeout();
836} 841}
837 842
838void CXferSocket::Deny(UINT errCode,UINT errID) 843void CXferSocket::Deny(UINT errCode,UINT errID)
839{ 844{
840 PostError(errCode,errID); 845 PostError(errCode,errID);
841 state=stateDeny; 846 state=stateDeny;
842} 847}
843 848
844void CRRQSocket::DoXfer() 849void CRRQSocket::DoXfer()
845{ 850{
846tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize)); 851tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize));
847 ASSERT(p); 852 ASSERT(p);
848 p->SetOpcode(tftp::opDATA); 853 p->SetOpcode(tftp::opDATA);
849 TRY{ 854 TRY{
850 m_File.Seek(m_ACK*m_blkSize,CFile::begin); 855 m_File.Seek(m_ACK*m_blkSize,CFile::begin);
851 int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize); 856 int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize);
852 p->data.m_DATA.SetBlock(m_ACK+1); 857 p->data.m_DATA.SetBlock(m_ACK+1);
853 p->length=p->length-m_blkSize+bytes; 858 p->length=p->length-m_blkSize+bytes;
854 m_LastSlack = m_blkSize-bytes; 859 m_LastSlack = m_blkSize-bytes;
855 PostTFTP(p); 860 PostTFTP(p);
856 if(bytes<m_blkSize){ 861 if(bytes<m_blkSize){
857 state=stateClosing; m_ACKtoClose = m_ACK+1; 862 state=stateClosing; m_ACKtoClose = m_ACK+1;
858 } 863 }
859 }CATCH(CFileException,e){ 864 }CATCH(CFileException,e){
860 Deny(e); 865 Deny(e);
861 }END_CATCH 866 }END_CATCH
862} 867}
863 868
864UINT tftp::tftpDATA::tftpSize(UINT blkSize) 869UINT tftp::tftpDATA::tftpSize(UINT blkSize)
865{ 870{
866 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA) 871 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA)
867 -sizeof(BYTE)+blkSize; 872 -sizeof(BYTE)+blkSize;
868} 873}
869 874
870void CXferSocket::Deny(CFileException* e) 875void CXferSocket::Deny(CFileException* e)
871{ 876{
872 PostError(e); 877 PostError(e);
873 state=stateDeny; 878 state=stateDeny;
874} 879}
875 880
876void CXferSocket::PostError(UINT errCode,UINT errID) 881void CXferSocket::PostError(UINT errCode,UINT errID)
877{ 882{
878CString msg; 883CString msg;
879 msg.LoadString(errID); 884 msg.LoadString(errID);
880 ASSERT(m_Daddy); 885 ASSERT(m_Daddy);
881 /*// ***
882CString tmp; 886CString tmp;
883 tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg); 887 tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg);
884 m_Daddy->LogLine(tmp); 888 m_Daddy->LogLine(tmp);
885 */
886tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg)); 889tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg));
887err->SetOpcode(tftp::opERROR); 890err->SetOpcode(tftp::opERROR);
888 err->errSet(errCode,msg); 891 err->errSet(errCode,msg);
889 PostTFTP(err); 892 PostTFTP(err);
890} 893}
891 894
892void CXferSocket::PostError(CFileException* e) 895void CXferSocket::PostError(CFileException* e)
893{ 896{
894UINT eCode; 897UINT eCode;
895UINT eMsgID; 898UINT eMsgID;
896 switch(e->m_cause){ 899 switch(e->m_cause){
897 case CFileException::fileNotFound: 900 case CFileException::fileNotFound:
898 eCode=tftp::errNotFound; 901 eCode=tftp::errNotFound;
899 eMsgID=IDS_TFTP_ERROR_NOTFOUND; 902 eMsgID=IDS_TFTP_ERROR_NOTFOUND;
900 break; 903 break;
901 case CFileException::accessDenied: 904 case CFileException::accessDenied:
902 eCode=tftp::errAccessViolation; 905 eCode=tftp::errAccessViolation;
903 eMsgID=IDS_TFTP_ERROR_ACCESS; 906 eMsgID=IDS_TFTP_ERROR_ACCESS;
904 break; 907 break;
905 case CFileException::directoryFull: 908 case CFileException::directoryFull:
906 eCode=tftp::errDiskFull; 909 eCode=tftp::errDiskFull;
907 eMsgID=IDS_TFTP_ERROR_DIRFULL; 910 eMsgID=IDS_TFTP_ERROR_DIRFULL;
908 break; 911 break;
909 case CFileException::sharingViolation: 912 case CFileException::sharingViolation:
910 eCode=tftp::errAccessViolation; 913 eCode=tftp::errAccessViolation;
911 eMsgID=IDS_TFTP_ERROR_SHARING; 914 eMsgID=IDS_TFTP_ERROR_SHARING;
912 break; 915 break;
913 case CFileException::diskFull: 916 case CFileException::diskFull:
914 eCode=tftp::errDiskFull; 917 eCode=tftp::errDiskFull;
915 eMsgID=IDS_TFTP_ERROR_DISKFULL; 918 eMsgID=IDS_TFTP_ERROR_DISKFULL;
916 break; 919 break;
917 default: 920 default:
918 eCode=tftp::errUndefined; 921 eCode=tftp::errUndefined;
919 eMsgID=IDS_TFTP_ERROR_UNDEFINED; 922 eMsgID=IDS_TFTP_ERROR_UNDEFINED;
920 break; 923 break;
921 } 924 }
922 PostError(eCode,eMsgID); 925 PostError(eCode,eMsgID);
923} 926}
924 927
925ULONG CRRQSocket::GetACK(void) 928ULONG CRRQSocket::GetACK(void)
926{ 929{
927 return (m_ACK*m_blkSize)-m_LastSlack; 930 return (m_ACK*m_blkSize)-m_LastSlack;
928} 931}
929 932
930BOOL CRRQSocket::OnTFTP(tftp* p) 933BOOL CRRQSocket::OnTFTP(tftp* p)
931{ 934{
932BOOL rv = TRUE; 935BOOL rv = TRUE;
933 switch(p->Opcode()){ 936 switch(p->Opcode()){
934 case tftp::opOACK: 937 case tftp::opOACK:
935 { 938 {
936 m_ACK=0; 939 m_ACK=0;
937 ASSERT(state!=stateFinish); 940 ASSERT(state!=stateFinish);
938 tftp::tftpOptions o; 941 tftp::tftpOptions o;
939 if(p->GetOptions(&o)){ 942 if(p->GetOptions(&o)){
940 CString v; 943 CString v;
941 if(o.Lookup(tftpoBSize,v)){ 944 if(o.Lookup(tftpoBSize,v)){
942 m_blkSize=atoi(v); 945 m_blkSize=atoi(v);
943 if(!m_blkSize){// *** More sanity checks 946 if(!m_blkSize){// *** More sanity checks
944 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); 947 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
945 rv = TRUE; 948 rv = TRUE;
946 break; 949 break;
947 } 950 }
948 } 951 }
949 if(o.Lookup(tftpoTOut,v)){ 952 if(o.Lookup(tftpoTOut,v)){
950 m_timeOut=atoi(v); 953 m_timeOut=atoi(v);
951 if(!m_timeOut){// *** More sanity checks 954 if(!m_timeOut){// *** More sanity checks
952 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); 955 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
953 rv = TRUE; 956 rv = TRUE;
954 break; 957 break;
955 } 958 }
956 } 959 }
957 if(o.Lookup(tftpoXResume,v)){ 960 if(o.Lookup(tftpoXResume,v)){
958 m_ACK=atoi(v); 961 m_ACK=atoi(v);
959 } 962 }
960 } 963 }
961 UpdateList(); 964 UpdateList();
962 DoXfer(); 965 DoXfer();
963 } 966 }
964 break; 967 break;
965 case tftp::opACK: 968 case tftp::opACK:
966 m_ACK=p->data.m_ACK.Block(); 969 m_ACK=p->data.m_ACK.Block();
967 if(state==stateClosing && m_ACK==m_ACKtoClose) { 970 if(state==stateClosing && m_ACK==m_ACKtoClose) {
968 state = stateFinish; 971 state = stateFinish;
969 ASSERT(m_Daddy); 972 ASSERT(m_Daddy);
970 CString tmp; 973 CString tmp;
971 tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName); 974 tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName);
972 m_Daddy->LogLine(tmp); 975 m_Daddy->LogLine(tmp);
973 rv = FALSE; 976 rv = FALSE;
974 DoSelect(TRUE); 977 DoSelect(TRUE);
975 }else if(state!=stateFinish){ 978 }else if(state!=stateFinish){
976 UpdateList(); 979 UpdateList();
977 DoXfer(); 980 DoXfer();
978 } 981 }
979 break; 982 break;
980 case tftp::opERROR: 983 case tftp::opERROR:
981 { 984 {
982 ASSERT(m_Daddy); 985 ASSERT(m_Daddy);
983 CString tmp; 986 CString tmp;
984 tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage()); 987 tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage());
985 m_Daddy->LogLine(tmp); 988 m_Daddy->LogLine(tmp);
986 } 989 }
987 Destroy(FALSE); 990 Destroy(FALSE);
988 rv = FALSE; 991 rv = FALSE;
989 break; 992 break;
990 default: 993 default:
991 { 994 {
992 ASSERT(m_Daddy); 995 ASSERT(m_Daddy);
993 CString tmp; 996 CString tmp;
994 tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode()); 997 tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode());
995 m_Daddy->LogLine(tmp); 998 m_Daddy->LogLine(tmp);
996 // *** Self destruct maybe?? 999 // *** Self destruct maybe??
997 } 1000 }
998 break; 1001 break;
999 } 1002 }
1000 return rv; 1003 return rv;
1001} 1004}
1002 1005
1003BOOL CWRQSocket::OnTFTP(tftp* p) 1006BOOL CWRQSocket::OnTFTP(tftp* p)
1004{ 1007{
1005 switch(p->Opcode()){ 1008 switch(p->Opcode()){
1006 case tftp::opOACK: 1009 case tftp::opOACK:
1007 ASSERT(state!=stateFinish); 1010 ASSERT(state!=stateFinish);
1008 { 1011 {
1009 if(m_bResume) 1012 if(m_bResume)
1010 m_ACK=m_File.GetLength()/m_blkSize; 1013 m_ACK=m_File.GetLength()/m_blkSize;
1011 else 1014 else
1012 m_ACK=0; 1015 m_ACK=0;
1013 tftp::tftpOptions o; 1016 tftp::tftpOptions o;
1014 if(p->GetOptions(&o)){ 1017 if(p->GetOptions(&o)){
1015 CString v; 1018 CString v;
1016 if(o.Lookup(tftpoBSize,v)){ 1019 if(o.Lookup(tftpoBSize,v)){
1017 m_blkSize=atoi(v); 1020 m_blkSize=atoi(v);
1018 if(!m_blkSize){// *** More sanity checks 1021 if(!m_blkSize){// *** More sanity checks
1019 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); 1022 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
1020 return TRUE; 1023 return TRUE;
1021 } 1024 }
1022 } 1025 }
1023 if(o.Lookup(tftpoTOut,v)){ 1026 if(o.Lookup(tftpoTOut,v)){
1024 m_timeOut=atoi(v); 1027 m_timeOut=atoi(v);
1025 if(!m_timeOut){// *** More sanity checks 1028 if(!m_timeOut){// *** More sanity checks
1026 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); 1029 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
1027 return TRUE; 1030 return TRUE;
1028 } 1031 }
1029 } 1032 }
1030 if(o.Lookup(tftpoTSize,v)){ 1033 if(o.Lookup(tftpoTSize,v)){
1031 m_xferSize=atoi(v); 1034 m_xferSize=atoi(v);
1032 } 1035 }
1033 } 1036 }
1034 UpdateList(); 1037 UpdateList();
1035 DoXfer(); 1038 DoXfer();
1036 } 1039 }
1037 break; 1040 break;
1038 case tftp::opDATA: 1041 case tftp::opDATA:
1039 { 1042 {
1040 UINTblock = p->data.m_DATA.Block(); 1043 UINTblock = p->data.m_DATA.Block();
1041 TRY{ 1044 TRY{
1042 m_File.Seek((block-1)*m_blkSize,CFile::begin); 1045 m_File.Seek((block-1)*m_blkSize,CFile::begin);
1043 int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize); 1046 int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize);
1044 if(bytes){ 1047 if(bytes){
1045 m_File.Write(p->data.m_DATA.data,bytes); 1048 m_File.Write(p->data.m_DATA.data,bytes);
1046 // *** Move to the other place where we can do it not that often 1049 // *** Move to the other place where we can do it not that often
1047 m_File.SetLength(m_File.GetPosition()); 1050 m_File.SetLength(m_File.GetPosition());
1048 } 1051 }
1049 if(bytes<m_blkSize){ 1052 if(bytes<m_blkSize){
1050 state=stateFinish; 1053 state=stateFinish;
1051 ASSERT(m_Daddy); 1054 ASSERT(m_Daddy);
1052 CString tmp; 1055 CString tmp;
1053 tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName); 1056 tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName);
1054 m_Daddy->LogLine(tmp); 1057 m_Daddy->LogLine(tmp);
1055 } 1058 }
1056 m_ACK=block; 1059 m_ACK=block;
1057 m_LastSlack=m_blkSize-bytes; 1060 m_LastSlack=m_blkSize-bytes;
1058 UpdateList(); 1061 UpdateList();
1059 DoXfer(); 1062 DoXfer();
1060 }CATCH(CFileException,e){ 1063 }CATCH(CFileException,e){
1061 Deny(e); 1064 Deny(e);
1062 }END_CATCH 1065 }END_CATCH
1063 } 1066 }
1064 break; 1067 break;
1065 case tftp::opERROR: 1068 case tftp::opERROR:
1066 { 1069 {
1067 ASSERT(m_Daddy); 1070 ASSERT(m_Daddy);
1068 CString tmp; 1071 CString tmp;
1069 tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage()); 1072 tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage());
1070 m_Daddy->LogLine(tmp); 1073 m_Daddy->LogLine(tmp);
1071 } 1074 }
1072 Destroy(FALSE); 1075 Destroy(FALSE);
1073 return FALSE; 1076 return FALSE;
1074 default: 1077 default:
1075 { 1078 {
1076 ASSERT(m_Daddy); 1079 ASSERT(m_Daddy);
1077 CString tmp; 1080 CString tmp;
1078 tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode()); 1081 tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode());
1079 m_Daddy->LogLine(tmp); 1082 m_Daddy->LogLine(tmp);
1080 // *** Self destruct maybe?? 1083 // *** Self destruct maybe??
1081 } 1084 }
1082 break; 1085 break;
1083 } 1086 }
1084 return TRUE; 1087 return TRUE;
1085} 1088}
1086 1089
1087void tftp::SetOpcode(WORD op) 1090void tftp::SetOpcode(WORD op)
1088{ 1091{
1089 opcode = REVERSEBYTES(op); 1092 opcode = REVERSEBYTES(op);
1090} 1093}
1091void tftp::tftpDATA::SetBlock(WORD b) 1094void tftp::tftpDATA::SetBlock(WORD b)
1092{ 1095{
1093 block=REVERSEBYTES(b); 1096 block=REVERSEBYTES(b);
1094} 1097}
1095WORD tftp::tftpDATA::Block() 1098WORD tftp::tftpDATA::Block()
1096{ 1099{
1097 return REVERSEBYTES(block); 1100 return REVERSEBYTES(block);
1098} 1101}
1099WORD tftp::tftpACK::Block() 1102WORD tftp::tftpACK::Block()
1100{ 1103{
1101 return REVERSEBYTES(block); 1104 return REVERSEBYTES(block);
1102} 1105}
1103void tftp::tftpACK::SetBlock(WORD b) 1106void tftp::tftpACK::SetBlock(WORD b)
1104{ 1107{
1105 block = REVERSEBYTES(b); 1108 block = REVERSEBYTES(b);
1106} 1109}
1107WORD tftp::tftpERROR::Code() 1110WORD tftp::tftpERROR::Code()
1108{ 1111{
1109 return REVERSEBYTES(code); 1112 return REVERSEBYTES(code);
1110} 1113}
1111void tftp::tftpERROR::SetCode(WORD c) 1114void tftp::tftpERROR::SetCode(WORD c)
1112{ 1115{
1113 code = REVERSEBYTES(c); 1116 code = REVERSEBYTES(c);
1114} 1117}
1115 1118
1116 1119
1117CString tftp::errMessage() 1120CString tftp::errMessage()
1118{ 1121{
1119CString rv; 1122CString rv;
1120 if(memchr(data.m_ERROR.data,0,length-(tftpHdrSize-tftpSlackSize)-sizeof(data.m_ERROR.code))) 1123 if(memchr(data.m_ERROR.data,0,length-(tftpHdrSize-tftpSlackSize)-sizeof(data.m_ERROR.code)))
1121 rv = (LPCTSTR)data.m_ERROR.data; 1124 rv = (LPCTSTR)data.m_ERROR.data;
1122 return rv; 1125 return rv;
1123} 1126}
1124 1127
1125void CXferSocket::Destroy(BOOL success) 1128void CXferSocket::Destroy(BOOL success)
1126{ 1129{
1127 if(m_wndResolver){ 1130 if(m_wndResolver){
1128 delete m_wndResolver; 1131 delete m_wndResolver;
1129 m_wndResolver=NULL; 1132 m_wndResolver=NULL;
1130 } 1133 }
1131 SetTry(); 1134 SetTry();
1132 m_Daddy->m_bnw.StartSound( 1135 m_Daddy->m_bnw.StartSound(
1133 success 1136 success
1134 ? m_Daddy->m_bnwSuccess 1137 ? m_Daddy->m_bnwSuccess
1135 : m_Daddy->m_bnwAbort 1138 : m_Daddy->m_bnwAbort
1136 ); 1139 );
1137 if(m_File.m_hFile!=CFile::hFileNull){ 1140 if(m_File.m_hFile!=CFile::hFileNull){
1138 TRY{ 1141 TRY{
1139 m_File.Close(); 1142 m_File.Close();
1140 }CATCH(CFileException,e){ 1143 }CATCH(CFileException,e){
1141 TRACE0("Error closing file\n"); 1144 TRACE0("Error closing file\n");
1142 }END_CATCH 1145 }END_CATCH
1143 } 1146 }
1144 ASSERT(m_Daddy); 1147 ASSERT(m_Daddy);
1145 m_Daddy->KillTimer(m_hSocket); 1148 m_Daddy->KillTimer(m_hSocket);
1146 m_Daddy->m_Xfers.RemoveKey(m_hSocket); 1149 m_Daddy->m_Xfers.RemoveKey(m_hSocket);
1147LV_FINDINFO lvf; 1150LV_FINDINFO lvf;
1148 memset(&lvf,0,sizeof(lvf)); 1151 memset(&lvf,0,sizeof(lvf));
1149 lvf.flags=LVFI_PARAM; 1152 lvf.flags=LVFI_PARAM;
1150 lvf.lParam=(LPARAM)this; 1153 lvf.lParam=(LPARAM)this;
1151int i = m_Daddy->m_List.FindItem(&lvf); 1154int i = m_Daddy->m_List.FindItem(&lvf);
1152 if(i>=0) 1155 if(i>=0)
1153 m_Daddy->m_List.DeleteItem(i); 1156 m_Daddy->m_List.DeleteItem(i);
1154 delete this; 1157 delete this;
1155} 1158}
1156 1159
1157void CPumpKINDlg::LogLineToScreen(LPCTSTR str) 1160void CPumpKINDlg::LogLineToScreen(LPCTSTR str)
1158{ 1161{
1159 ASSERT(m_LogLength); 1162 ASSERT(m_LogLength);
1160 while(m_Log.GetCount()>m_LogLength && m_Log.GetCount()!=LB_ERR){ 1163 while(m_Log.GetCount()>m_LogLength && m_Log.GetCount()!=LB_ERR){
1161 CTime *t = (CTime*)m_Log.GetItemData(0); 1164 CTime *t = (CTime*)m_Log.GetItemData(0);
1162 if(((DWORD)t)!=LB_ERR){ 1165 if(((DWORD)t)!=LB_ERR){
1163 ASSERT(t); 1166 ASSERT(t);
1164 m_LogTimes.RemoveKey(t); 1167 m_LogTimes.RemoveKey(t);
1165 delete t; 1168 delete t;
1166 } 1169 }
1167 m_Log.DeleteString(0); 1170 m_Log.DeleteString(0);
1168 } 1171 }
1169int i = m_Log.AddString(str); 1172int i = m_Log.AddString(str);
1170 ASSERT(i!=LB_ERR); 1173 ASSERT(i!=LB_ERR);
1171CTime *t = new CTime(CTime::GetCurrentTime()); 1174CTime *t = new CTime(CTime::GetCurrentTime());
1172 m_Log.SetItemData(i,(DWORD)(m_LogTimes[t]=t)); 1175 m_Log.SetItemData(i,(DWORD)(m_LogTimes[t]=t));
1173 m_Log.SetCurSel(i); 1176 m_Log.SetCurSel(i);
1174} 1177}
1175 1178
1176void CPumpKINDlg::LogLine(UINT msgID) 1179void CPumpKINDlg::LogLine(UINT msgID)
1177{ 1180{
1178CString tmp; 1181CString tmp;
1179 tmp.Format(msgID); 1182 tmp.Format(msgID);
1180 LogLine(tmp); 1183 LogLine(tmp);
1181} 1184}
1182 1185
1183void CXferSocket::TurnSlashes(CString& fn,BOOL bBack) 1186void CXferSocket::TurnSlashes(CString& fn,BOOL bBack)
1184{ 1187{
1185 ints = fn.Find(bBack?'/':'\\'); 1188 ints = fn.Find(bBack?'/':'\\');
1186 while(s>=0){ 1189 while(s>=0){
1187 fn.SetAt(s,bBack?'\\':'/'); 1190 fn.SetAt(s,bBack?'\\':'/');
1188 s = fn.Find(bBack?'/':'\\'); 1191 s = fn.Find(bBack?'/':'\\');
1189 } 1192 }
1190} 1193}
1191 1194
1192CString CXferSocket::ApplyRoot(LPCTSTR fileName) 1195CString CXferSocket::ApplyRoot(LPCTSTR fileName)
1193{ 1196{
1194 ASSERT(m_Daddy); 1197 ASSERT(m_Daddy);
1195CString fn = fileName; 1198CString fn = fileName;
1196CString rv = m_Daddy->m_TFTPRoot; 1199CString rv = m_Daddy->m_TFTPRoot;
1197 if(rv.IsEmpty()) 1200 if(rv.IsEmpty())
1198 rv = "."; 1201 rv = ".";
1199 if(rv[rv.GetLength()-1]!='\\') 1202 if(rv[rv.GetLength()-1]!='\\')
1200 rv+="\\"; 1203 rv+="\\";
1201 while((!fn.IsEmpty()) && fn[0]=='\\') 1204 while((!fn.IsEmpty()) && fn[0]=='\\')
1202 fn=fn.Mid(1); 1205 fn=fn.Mid(1);
1203 rv+=fn; 1206 rv+=fn;
1204 return rv; 1207 return rv;
1205} 1208}
1206 1209
1207void CPumpKINDlg::OnOptions() 1210void CPumpKINDlg::OnOptions()
1208{ 1211{
1209CPropertySheet cps(IDS_TITLE_OPTIONS,this); 1212CPropertySheet cps(IDS_TITLE_OPTIONS,this);
1210CPropsServer server; 1213CPropsServer server;
1211CPropsNetwork network; 1214CPropsNetwork network;
1212CPropsSounds sounds; 1215CPropsSounds sounds;
1213CPropsACL acl; 1216CPropsACL acl;
1214 1217
1215 server.m_RRQMode=m_RRQMode; 1218 server.m_RRQMode=m_RRQMode;
1216 server.m_TFTPRoot=m_TFTPRoot; 1219 server.m_TFTPRoot=m_TFTPRoot;
1217 server.m_TFTPSubdirs=m_bTFTPSubdirs; 1220 server.m_TFTPSubdirs=m_bTFTPSubdirs;
1218 server.m_WRQMode=m_WRQMode; 1221 server.m_WRQMode=m_WRQMode;
1219 server.m_PromptTimeOut=m_PromptTimeOut; 1222 server.m_PromptTimeOut=m_PromptTimeOut;
1220 server.m_LogFile=m_LogFile; 1223 server.m_LogFile=m_LogFile;
1221 1224
1222 network.m_ListenPort=m_ListenPort; 1225 network.m_ListenPort=m_ListenPort;
1223 network.m_SpeakPort=m_SpeakPort; 1226 network.m_SpeakPort=m_SpeakPort;
1224 network.m_TimeOut=m_TFTPTimeOut.GetTotalSeconds(); 1227 network.m_TimeOut=m_TFTPTimeOut.GetTotalSeconds();
1225 network.m_BlockSize=m_BlockSize; 1228 network.m_BlockSize=m_BlockSize;
1226 1229
1227 sounds.m_Request = m_bnwRequest; 1230 sounds.m_Request = m_bnwRequest;
1228 sounds.m_Success = m_bnwSuccess; 1231 sounds.m_Success = m_bnwSuccess;
1229 sounds.m_Abort = m_bnwAbort; 1232 sounds.m_Abort = m_bnwAbort;
1230 1233
1231 acl.m_rulist = m_aclRules; 1234 acl.m_rulist = m_aclRules;
1232 1235
1233 cps.AddPage(&server); 1236 cps.AddPage(&server);
1234 cps.AddPage(&network); 1237 cps.AddPage(&network);
1235 cps.AddPage(&sounds); 1238 cps.AddPage(&sounds);
1236 cps.AddPage(&acl); 1239 cps.AddPage(&acl);
1237 if(cps.DoModal()==IDOK){ 1240 if(cps.DoModal()==IDOK){
1238 m_RRQMode=server.m_RRQMode; 1241 m_RRQMode=server.m_RRQMode;
1239 m_TFTPRoot=server.m_TFTPRoot; 1242 m_TFTPRoot=server.m_TFTPRoot;
1240 m_bTFTPSubdirs=server.m_TFTPSubdirs; 1243 m_bTFTPSubdirs=server.m_TFTPSubdirs;
1241 m_WRQMode=server.m_WRQMode; 1244 m_WRQMode=server.m_WRQMode;
1242 m_PromptTimeOut=server.m_PromptTimeOut; 1245 m_PromptTimeOut=server.m_PromptTimeOut;
1243 m_LogFile=server.m_LogFile; 1246 m_LogFile=server.m_LogFile;
1244 1247
1245 m_ListenPort=network.m_ListenPort; 1248 m_ListenPort=network.m_ListenPort;
1246 m_SpeakPort=network.m_SpeakPort; 1249 m_SpeakPort=network.m_SpeakPort;
1247 m_TFTPTimeOut=CTimeSpan(network.m_TimeOut); 1250 m_TFTPTimeOut=CTimeSpan(network.m_TimeOut);
1248 m_BlockSize=network.m_BlockSize; 1251 m_BlockSize=network.m_BlockSize;
1249 1252
1250 m_bnwRequest = sounds.m_Request; 1253 m_bnwRequest = sounds.m_Request;
1251 m_bnwSuccess = sounds.m_Success; 1254 m_bnwSuccess = sounds.m_Success;
1252 m_bnwAbort = sounds.m_Abort; 1255 m_bnwAbort = sounds.m_Abort;
1253 1256
1254 m_aclRules = acl.m_rulist; 1257 m_aclRules = acl.m_rulist;
1255 1258
1256 m_lastlogerr.Empty(); 1259 m_lastlogerr.Empty();
1257 } 1260 }
1258} 1261}
1259 1262
1260BOOL CRRQSocket::ConfirmRequest() 1263BOOL CRRQSocket::ConfirmRequest()
1261{ 1264{
1262CConfirmRRQDlg cd(NULL); 1265CConfirmRRQDlg cd(NULL);
1263 cd.m_Daddy=this; 1266 cd.m_Daddy=this;
1264 cd.m_File=m_FileName; 1267 cd.m_File=m_FileName;
1265 cd.m_Host=inet_ntoa(m_Peer.sin_addr); 1268 cd.m_Host=inet_ntoa(m_Peer.sin_addr);
1266 if(cd.DoModal()==IDOK) 1269 if(cd.DoModal()==IDOK)
1267 return TRUE; 1270 return TRUE;
1268 return FALSE; 1271 return FALSE;
1269} 1272}
1270 1273
1271CWRQSocket::CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) 1274CWRQSocket::CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin)
1272 : CXferSocket(daddy,fileName,type,sin) 1275 : CXferSocket(daddy,fileName,type,sin)
1273{ 1276{
1274 state=stateNone; 1277 state=stateNone;
1275 m_ACK=0; 1278 m_ACK=0;
1276 m_LastSlack=0; 1279 m_LastSlack=0;
1277 m_bResume=FALSE; 1280 m_bResume=FALSE;
1278} 1281}
1279 1282
1280BOOL CWRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName) 1283BOOL CWRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName)
1281{ 1284{
1282 if(!CAsyncSocket::Create(0,SOCK_DGRAM)) 1285 if(!CAsyncSocket::Create(0,SOCK_DGRAM))
1283 return FALSE; 1286 return FALSE;
1284 ASSERT(m_Daddy); 1287 ASSERT(m_Daddy);
1285 ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName); 1288 ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName);
1286 m_Daddy->m_Xfers[m_hSocket]=this; 1289 m_Daddy->m_Xfers[m_hSocket]=this;
1287 UpdateList(); 1290 UpdateList();
1288CString lf; 1291CString lf;
1289 if(!localFile) { 1292 if(!localFile) {
1290 lf = m_FileName; 1293 lf = m_FileName;
1291 TurnSlashes(lf,TRUE); 1294 TurnSlashes(lf,TRUE);
1292 } 1295 }
1293CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf); 1296CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf);
1294 if(!localFile){// This is an incoming request.. 1297 if(!localFile){// This is an incoming request..
1295 if(CheckBadRelativeness(m_FileName)){ 1298 if(CheckBadRelativeness(m_FileName)){
1296 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); 1299 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
1297 return TRUE; 1300 return TRUE;
1298 } 1301 }
1299 BOOL exists; 1302 BOOL exists;
1300 if(!_access((LPCTSTR)fn,0)) 1303 if(!_access((LPCTSTR)fn,0))
1301 m_Rename=exists=TRUE; 1304 m_Rename=exists=TRUE;
1302 else 1305 else
1303 m_Rename=exists=FALSE; 1306 m_Rename=exists=FALSE;
1304 int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opWRQ,m_Peer.sin_addr.s_addr); 1307 int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opWRQ,m_Peer.sin_addr.s_addr);
1305 if(atar<0) 1308 if(atar<0)
1306 atar=m_Daddy->m_WRQMode; 1309 atar=m_Daddy->m_WRQMode;
1307 switch(atar){ 1310 switch(atar){
1308 case CPumpKINDlg::wrqTakeAll: 1311 case CPumpKINDlg::wrqTakeAll:
1309 if(exists){ 1312 if(exists){
1310 if(!RenameFile(fn)){ 1313 if(!RenameFile(fn)){
1311 Deny(tftp::errDiskFull,IDS_TFTP_ERROR_FAILEDTORENAME); 1314 Deny(tftp::errDiskFull,IDS_TFTP_ERROR_FAILEDTORENAME);
1312 return TRUE; 1315 return TRUE;
1313 } 1316 }
1314 } 1317 }
1315 break; 1318 break;
1316 case CPumpKINDlg::wrqConfirmIfExists: 1319 case CPumpKINDlg::wrqConfirmIfExists:
1317 if(!exists) 1320 if(!exists)
1318 break; 1321 break;
1319 case CPumpKINDlg::wrqAlwaysConfirm: 1322 case CPumpKINDlg::wrqAlwaysConfirm:
1320 if(exists) 1323 if(exists)
1321 m_bResume=TRUE; 1324 m_bResume=TRUE;
1322 if(ConfirmRequest()){ 1325 if(ConfirmRequest()){
1323 if(m_Rename){ 1326 if(m_Rename){
1324 RenameFile(fn); 1327 RenameFile(fn);
1325 if(SaveAs(fn)) 1328 if(SaveAs(fn))
1326 break; 1329 break;
1327 }else 1330 }else
1328 break; 1331 break;
1329 } 1332 }
1330 default: 1333 default:
1331 TRACE1("Unexpected access target: %d\n",atar); 1334 TRACE1("Unexpected access target: %d\n",atar);
1332 case CPumpKINDlg::wrqDenyAll: 1335 case CPumpKINDlg::wrqDenyAll:
1333 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); 1336 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
1334 return TRUE; 1337 return TRUE;
1335 } 1338 }
1336 } 1339 }
1337CFileException e; 1340CFileException e;
1338 if(!m_File.Open( 1341 if(!m_File.Open(
1339 fn, 1342 fn,
1340 m_bResume 1343 m_bResume
1341 ?(CFile::modeWrite|CFile::shareDenyWrite) 1344 ?(CFile::modeWrite|CFile::shareDenyWrite)
1342 :(CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite), 1345 :(CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite),
1343 &e 1346 &e
1344 )){ 1347 )){
1345 if(localFile){// Outgoing request 1348 if(localFile){// Outgoing request
1346 CString tmp; 1349 CString tmp;
1347 tmp.Format(IDS_LOG_FAILEDTOOPEN,fn); 1350 tmp.Format(IDS_LOG_FAILEDTOOPEN,fn);
1348 m_Daddy->LogLine(tmp); 1351 m_Daddy->LogLine(tmp);
1349 return FALSE; 1352 return FALSE;
1350 }else{ 1353 }else{
1351 Deny(&e); 1354 Deny(&e);
1352 return TRUE; 1355 return TRUE;
1353 } 1356 }
1354 } 1357 }
1355 if(hostName){ 1358 if(hostName){
1356 m_HostName=hostName; 1359 m_HostName=hostName;
1357 1360
1358 CString tmp; 1361 CString tmp;
1359 tmp.Format(IDS_LOG_REQUESTING,m_FileName,m_HostName); 1362 tmp.Format(IDS_LOG_REQUESTING,m_FileName,m_HostName);
1360 m_Daddy->LogLine(tmp); 1363 m_Daddy->LogLine(tmp);
1361 1364
1362 CString inAddr = hostName; 1365 CString inAddr = hostName;
1363 int at = inAddr.Find('@'); 1366 int at = inAddr.Find('@');
1364 if(at>=0) 1367 if(at>=0)
1365 inAddr=inAddr.Mid(at+1); 1368 inAddr=inAddr.Mid(at+1);
1366 if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){ 1369 if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){
1367 ASSERT(!m_wndResolver); 1370 ASSERT(!m_wndResolver);
1368 m_wndResolver = new CResolver(this); 1371 m_wndResolver = new CResolver(this);
1369 ASSERT(m_wndResolver); 1372 ASSERT(m_wndResolver);
1370 return m_wndResolver->Resolve(); 1373 return m_wndResolver->Resolve();
1371 }else{ 1374 }else{
1372 OnHostKnown(); 1375 OnHostKnown();
1373 return TRUE; 1376 return TRUE;
1374 } 1377 }
1375 } 1378 }
1376CString v; 1379CString v;
1377tftp::tftpOptions oack; 1380tftp::tftpOptions oack;
1378 if(m_Options.Lookup(tftpoTSize,v)){ 1381 if(m_Options.Lookup(tftpoTSize,v)){
1379 m_xferSize=atol(v); 1382 m_xferSize=atol(v);
1380 if(!m_xferSize){ 1383 if(!m_xferSize){
1381 Deny(tftp::errOption,IDS_TFTP_ERROR_TSIZE); 1384 Deny(tftp::errOption,IDS_TFTP_ERROR_TSIZE);
1382 return TRUE; 1385 return TRUE;
1383 } 1386 }
1384 } 1387 }
1385 if(m_Options.Lookup(tftpoBSize,v)){ 1388 if(m_Options.Lookup(tftpoBSize,v)){
1386 m_blkSize=atoi(v); 1389 m_blkSize=atoi(v);
1387 if(!m_blkSize){// *** Do more about sanity check 1390 if(!m_blkSize){// *** Do more about sanity check
1388 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); 1391 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
1389 return TRUE; 1392 return TRUE;
1390 } 1393 }
1391 v.Format("%u",m_blkSize); 1394 v.Format("%u",m_blkSize);
1392 oack[tftpoBSize]=v; 1395 oack[tftpoBSize]=v;
1393 } 1396 }
1394 if(m_Options.Lookup(tftpoTOut,v)){ 1397 if(m_Options.Lookup(tftpoTOut,v)){
1395 m_timeOut=atoi(v); 1398 m_timeOut=atoi(v);
1396 if(!m_timeOut){// *** Do more about sanity check 1399 if(!m_timeOut){// *** Do more about sanity check
1397 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); 1400 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
1398 return TRUE; 1401 return TRUE;
1399 } 1402 }
1400 v.Format("%u",m_timeOut); 1403 v.Format("%u",m_timeOut);
1401 oack[tftpoTOut]=v; 1404 oack[tftpoTOut]=v;
1402 } 1405 }
1403 if(m_Options.Lookup(tftpoXResume,v) && m_bResume){ 1406 if(m_Options.Lookup(tftpoXResume,v) && m_bResume){
1404 m_ACK=m_File.GetLength()/m_blkSize; 1407 m_ACK=m_File.GetLength()/m_blkSize;
1405 v.Format("%u",m_ACK); 1408 v.Format("%u",m_ACK);
1406 oack[tftpoXResume]=v; 1409 oack[tftpoXResume]=v;
1407 }else 1410 }else
1408 m_ACK=0; 1411 m_ACK=0;
1409 state=stateXfer; 1412 state=stateXfer;
1410 if(oack.GetCount()){ 1413 if(oack.GetCount()){
1411 tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&oack)); 1414 tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&oack));
1412 ASSERT(p); 1415 ASSERT(p);
1413 p->SetOpcode(tftp::opOACK); 1416 p->SetOpcode(tftp::opOACK);
1414 p->data.m_OACK.Set(&oack); 1417 p->data.m_OACK.Set(&oack);
1415 PostTFTP(p,TRUE); 1418 PostTFTP(p,TRUE);
1416 }else 1419 }else
1417 DoXfer(); 1420 DoXfer();
1418 return TRUE; 1421 return TRUE;
1419} 1422}
1420 1423
1421BOOL CWRQSocket::ConfirmRequest() 1424BOOL CWRQSocket::ConfirmRequest()
1422{ 1425{
1423CConfirmWRQDlg cd(NULL); 1426CConfirmWRQDlg cd(NULL);
1424 cd.m_Daddy=this; 1427 cd.m_Daddy=this;
1425 cd.m_File=m_FileName; 1428 cd.m_File=m_FileName;
1426 cd.m_Host=inet_ntoa(m_Peer.sin_addr); 1429 cd.m_Host=inet_ntoa(m_Peer.sin_addr);
1427 switch(cd.DoModal()){ 1430 switch(cd.DoModal()){
1428 case IDOK: 1431 case IDOK:
1429 m_Rename=FALSE; 1432 m_Rename=FALSE;
1430 m_bResume=FALSE; 1433 m_bResume=FALSE;
1431 return TRUE; 1434 return TRUE;
1432 case IDC_RENAME: 1435 case IDC_RENAME:
1433 m_bResume=FALSE; 1436 m_bResume=FALSE;
1434 m_Rename=TRUE; 1437 m_Rename=TRUE;
1435 return TRUE; 1438 return TRUE;
1436 case IDC_RESUME: 1439 case IDC_RESUME:
1437 m_Rename=FALSE; 1440 m_Rename=FALSE;
1438 m_bResume=TRUE; 1441 m_bResume=TRUE;
1439 return TRUE; 1442 return TRUE;
1440 case IDCANCEL: 1443 case IDCANCEL:
1441 return FALSE; 1444 return FALSE;
1442 } 1445 }
1443 return FALSE; 1446 return FALSE;
1444} 1447}
1445 1448
1446BOOL CWRQSocket::RenameFile(CString& fn) 1449BOOL CWRQSocket::RenameFile(CString& fn)
1447{ 1450{
1448CString renamed = fn; 1451CString renamed = fn;
1449 if(fn.IsEmpty()) 1452 if(fn.IsEmpty())
1450 return FALSE; 1453 return FALSE;
1451 if(fn[fn.GetLength()-1]==')'){ 1454 if(fn[fn.GetLength()-1]==')'){
1452 int op = fn.ReverseFind('('); 1455 int op = fn.ReverseFind('(');
1453 if(op>0 && fn[op-1]==' '){ 1456 if(op>0 && fn[op-1]==' '){
1454 if(fn.Mid(op+1,fn.GetLength()-op-2).SpanExcluding("0123456789").IsEmpty()) 1457 if(fn.Mid(op+1,fn.GetLength()-op-2).SpanExcluding("0123456789").IsEmpty())
1455 renamed = renamed.Left(op-1); 1458 renamed = renamed.Left(op-1);
1456 } 1459 }
1457 } 1460 }
1458CString testFN; 1461CString testFN;
1459 for(UINT tmp=0;tmp<32768;tmp++){ 1462 for(UINT tmp=0;tmp<32768;tmp++){
1460 testFN.Format("%s (%u)",(LPCTSTR)renamed,tmp); 1463 testFN.Format("%s (%u)",(LPCTSTR)renamed,tmp);
1461 if(!_access((LPCTSTR)testFN,0)) 1464 if(!_access((LPCTSTR)testFN,0))
1462 continue; 1465 continue;
1463 fn=testFN; 1466 fn=testFN;
1464 return TRUE; 1467 return TRUE;
1465 } 1468 }
1466 return FALSE; 1469 return FALSE;
1467} 1470}
1468 1471
1469BOOL CWRQSocket::SaveAs(CString& fn) 1472BOOL CWRQSocket::SaveAs(CString& fn)
1470{ 1473{
1471CFileDialog cfd(FALSE,NULL,fn,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST,NULL,m_Daddy); 1474CFileDialog cfd(FALSE,NULL,fn,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST,NULL,m_Daddy);
1472CString title; 1475CString title;
1473 title.LoadString(IDS_RENAME_TITLE); 1476 title.LoadString(IDS_RENAME_TITLE);
1474 cfd.m_ofn.lpstrTitle=(LPCTSTR)title; 1477 cfd.m_ofn.lpstrTitle=(LPCTSTR)title;
1475 if(cfd.DoModal()!=IDOK) 1478 if(cfd.DoModal()!=IDOK)
1476 return FALSE; 1479 return FALSE;
1477 fn = cfd.GetPathName(); 1480 fn = cfd.GetPathName();
1478 return TRUE; 1481 return TRUE;
1479} 1482}
1480 1483
1481void CWRQSocket::DoXfer() 1484void CWRQSocket::DoXfer()
1482{ 1485{
1483tftp *p = tftp::Allocate(tftp::tftpACK::tftpSize()); 1486tftp *p = tftp::Allocate(tftp::tftpACK::tftpSize());
1484 ASSERT(p); 1487 ASSERT(p);
1485 p->SetOpcode(tftp::opACK); 1488 p->SetOpcode(tftp::opACK);
1486 p->data.m_ACK.SetBlock(m_ACK); 1489 p->data.m_ACK.SetBlock(m_ACK);
1487 TRACE1("WRQ-ACK-%u\n",m_ACK); 1490 TRACE1("WRQ-ACK-%u\n",m_ACK);
1488 PostTFTP(p,TRUE);// *** ??? Hope this is right 1491 PostTFTP(p,TRUE);// *** ??? Hope this is right
1489} 1492}
1490 1493
1491UINT tftp::tftpACK::tftpSize() 1494UINT tftp::tftpACK::tftpSize()
1492{ 1495{
1493 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpACK); 1496 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpACK);
1494} 1497}
1495 1498
1496ULONG CWRQSocket::GetACK() 1499ULONG CWRQSocket::GetACK()
1497{ 1500{
1498 return (m_ACK*m_blkSize)-m_LastSlack; 1501 return (m_ACK*m_blkSize)-m_LastSlack;
1499} 1502}
1500 1503
1501void CXferSocket::ResetTimeout() 1504void CXferSocket::ResetTimeout()
1502{ 1505{
1503 ASSERT(m_Daddy); 1506 ASSERT(m_Daddy);
1504 m_Daddy->m_Retrier->KillTimer(m_hSocket); 1507 m_Daddy->m_Retrier->KillTimer(m_hSocket);
1505 if(m_Retry) 1508 if(m_Retry)
1506 m_Daddy->m_Retrier->SetTimer(m_hSocket,min(60,m_Daddy->m_RetryTimeOut.GetTotalSeconds())*1000,NULL); 1509 m_Daddy->m_Retrier->SetTimer(m_hSocket,min(60,m_Daddy->m_RetryTimeOut.GetTotalSeconds())*1000,NULL);
1507 if(!m_bRetry){ 1510 if(!m_bRetry){
1508 m_Daddy->KillTimer(m_hSocket); 1511 m_Daddy->KillTimer(m_hSocket);
1509 m_Daddy->SetTimer(m_hSocket,min(60,m_timeOut)*1000,NULL); 1512 m_Daddy->SetTimer(m_hSocket,min(60,m_timeOut)*1000,NULL);
1510 } 1513 }
1511} 1514}
1512 1515
1513void CXferSocket::Abort() 1516void CXferSocket::Abort()
1514{ 1517{
1515 ASSERT(m_Daddy); 1518 ASSERT(m_Daddy);
1516CString tmp; 1519CString tmp;
1517 tmp.Format(IDS_LOG_XFERABORTED,(LPCTSTR)m_FileName); 1520 tmp.Format(IDS_LOG_XFERABORTED,(LPCTSTR)m_FileName);
1518 m_Daddy->LogLine(tmp); 1521 m_Daddy->LogLine(tmp);
1519 Destroy(FALSE); 1522 Destroy(FALSE);
1520} 1523}
1521 1524
1522void CPumpKINDlg::OnTimer(UINT nIDEvent) 1525void CPumpKINDlg::OnTimer(UINT nIDEvent)
1523{ 1526{
1524CXferSocket *socket; 1527CXferSocket *socket;
1525 if(m_Xfers.Lookup(nIDEvent,socket)){ 1528 if(m_Xfers.Lookup(nIDEvent,socket)){
1526 CString tmp; 1529 CString tmp;
1527 tmp.Format(IDS_LOG_TIMEDOUT,socket->m_FileName); 1530 tmp.Format(IDS_LOG_TIMEDOUT,socket->m_FileName);
1528 LogLine(tmp); 1531 LogLine(tmp);
1529 socket->Abort(); 1532 socket->Abort();
1530 }else{ 1533 }else{
1531 TRACE0("Failed to find timed out socket!\n"); 1534 TRACE0("Failed to find timed out socket!\n");
1532 } 1535 }
1533 CDialog::OnTimer(nIDEvent); 1536 CDialog::OnTimer(nIDEvent);
1534} 1537}
1535 1538
1536void CPumpKINDlg::OnExit() 1539void CPumpKINDlg::OnExit()
1537{ 1540{
1538 if(!m_Xfers.IsEmpty()){ 1541 if(!m_Xfers.IsEmpty()){
1539 CString title,text; 1542 CString title,text;
1540 title.LoadString(IDS_CONFIRMEXIT_TITLE); 1543 title.LoadString(IDS_CONFIRMEXIT_TITLE);
1541 text.LoadString(IDS_CONFIRMEXIT_TEXT); 1544 text.LoadString(IDS_CONFIRMEXIT_TEXT);
1542 if(MessageBox(text,title,MB_ICONQUESTION|MB_YESNO)!=IDYES) 1545 if(MessageBox(text,title,MB_ICONQUESTION|MB_YESNO)!=IDYES)
1543 return; 1546 return;
1544 } 1547 }
1545 m_bExiting=TRUE; 1548 m_bExiting=TRUE;
1546 EndDialog(IDOK); 1549 EndDialog(IDOK);
1547} 1550}
1548 1551
1549void CPumpKINDlg::OnPut() 1552void CPumpKINDlg::OnPut()
1550{ 1553{
1551CRequestDlg crd(NULL); 1554CRequestDlg crd(NULL);
1552 crd.m_Put=TRUE; 1555 crd.m_Put=TRUE;
1553 crd.m_BSize=m_BlockSize; 1556 crd.m_BSize=m_BlockSize;
1554 if(crd.DoModal()==IDOK){ 1557 if(crd.DoModal()==IDOK){
1555 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL); 1558 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
1556 if(crd.m_BSize) 1559 if(crd.m_BSize)
1557 socket->m__blkSize=crd.m_BSize; 1560 socket->m__blkSize=crd.m_BSize;
1558 if(!socket->Create(crd.m_LocalFile,crd.m_Host)) 1561 if(!socket->Create(crd.m_LocalFile,crd.m_Host))
1559 socket->Destroy(); 1562 socket->Destroy();
1560 } 1563 }
1561} 1564}
1562 1565
1563void CPumpKINDlg::OnGet() 1566void CPumpKINDlg::OnGet()
1564{ 1567{
1565CRequestDlg crd(NULL); 1568CRequestDlg crd(NULL);
1566 crd.m_Put=FALSE; 1569 crd.m_Put=FALSE;
1567 crd.m_BSize=m_BlockSize; 1570 crd.m_BSize=m_BlockSize;
1568 if(crd.DoModal()==IDOK){ 1571 if(crd.DoModal()==IDOK){
1569 CWRQSocket *socket = new CWRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL); 1572 CWRQSocket *socket = new CWRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
1570 if(crd.m_BSize) 1573 if(crd.m_BSize)
1571 socket->m__blkSize=crd.m_BSize; 1574 socket->m__blkSize=crd.m_BSize;
1572 if(!socket->Create(crd.m_LocalFile,crd.m_Host)) 1575 if(!socket->Create(crd.m_LocalFile,crd.m_Host))
1573 socket->Destroy(); 1576 socket->Destroy();
1574 } 1577 }
1575} 1578}
1576 1579
1577void CPumpKINDlg::SetupButtons() 1580void CPumpKINDlg::SetupButtons()
1578{ 1581{
1579 m_AbortCtl.EnableWindow(m_List.GetSelectedCount()>0); 1582 m_AbortCtl.EnableWindow(m_List.GetSelectedCount()>0);
1580} 1583}
1581 1584
1582void CPumpKINDlg::OnDeleteallitemsConnections(NMHDR* pNMHDR, LRESULT* pResult) 1585void CPumpKINDlg::OnDeleteallitemsConnections(NMHDR* pNMHDR, LRESULT* pResult)
1583{ 1586{
1584 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 1587 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
1585 SetupButtons(); 1588 SetupButtons();
1586 *pResult = 0; 1589 *pResult = 0;
1587} 1590}
1588 1591
1589void CPumpKINDlg::OnDeleteitemConnections(NMHDR* pNMHDR, LRESULT* pResult) 1592void CPumpKINDlg::OnDeleteitemConnections(NMHDR* pNMHDR, LRESULT* pResult)
1590{ 1593{
1591 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 1594 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
1592 SetupButtons(); 1595 SetupButtons();
1593 *pResult = 0; 1596 *pResult = 0;
1594} 1597}
1595 1598
1596void CPumpKINDlg::OnInsertitemConnections(NMHDR* pNMHDR, LRESULT* pResult) 1599void CPumpKINDlg::OnInsertitemConnections(NMHDR* pNMHDR, LRESULT* pResult)
1597{ 1600{
1598 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 1601 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
1599 SetupButtons(); 1602 SetupButtons();
1600 *pResult = 0; 1603 *pResult = 0;
1601} 1604}
1602 1605
1603void CPumpKINDlg::OnItemchangedConnections(NMHDR* pNMHDR, LRESULT* pResult) 1606void CPumpKINDlg::OnItemchangedConnections(NMHDR* pNMHDR, LRESULT* pResult)
1604{ 1607{
1605 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 1608 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
1606 SetupButtons(); 1609 SetupButtons();
1607 *pResult = 0; 1610 *pResult = 0;
1608} 1611}
1609 1612
1610void CPumpKINDlg::OnAbort() 1613void CPumpKINDlg::OnAbort()
1611{ 1614{
1612 if(!m_List.GetSelectedCount()) 1615 if(!m_List.GetSelectedCount())
1613 return; 1616 return;
1614 intitems = m_List.GetItemCount(); 1617 intitems = m_List.GetItemCount();
1615 for(int tmp=0;tmp<items;tmp++){ 1618 for(int tmp=0;tmp<items;tmp++){
1616 if(!(m_List.GetItemState(tmp,LVIS_SELECTED)&LVIS_SELECTED)) 1619 if(!(m_List.GetItemState(tmp,LVIS_SELECTED)&LVIS_SELECTED))
1617 continue; 1620 continue;
1618 CXferSocket *xfer = (CXferSocket*) m_List.GetItemData(tmp); 1621 CXferSocket *xfer = (CXferSocket*) m_List.GetItemData(tmp);
1619 ASSERT(xfer); 1622 ASSERT(xfer);
1620 xfer->Abort(); 1623 xfer->Abort();
1621 } 1624 }
1622} 1625}
1623 1626
1624void CXferSocket::OnFailedToResolve() 1627void CXferSocket::OnFailedToResolve()
1625{ 1628{
1626 TRACE0("Resolve failed\n"); 1629 TRACE0("Resolve failed\n");
1627 delete m_wndResolver; 1630 delete m_wndResolver;
1628 m_wndResolver=NULL; 1631 m_wndResolver=NULL;
1629 ASSERT(m_Daddy); 1632 ASSERT(m_Daddy);
1630CString tmp; 1633CString tmp;
1631 tmp.Format(IDS_LOG_RESOLVEFAILED,m_HostName); 1634 tmp.Format(IDS_LOG_RESOLVEFAILED,m_HostName);
1632 m_Daddy->LogLine(tmp); 1635 m_Daddy->LogLine(tmp);
1633 Abort(); 1636 Abort();
1634} 1637}
1635 1638
1636void CXferSocket::OnResolved() 1639void CXferSocket::OnResolved()
1637{ 1640{
1638 delete m_wndResolver; 1641 delete m_wndResolver;
1639 m_wndResolver=NULL; 1642 m_wndResolver=NULL;
1640 TRACE0("Resolved\n"); 1643 TRACE0("Resolved\n");
1641 m_Peer.sin_addr.s_addr = *(DWORD*)(((hostent*)m_ResolveBuff)->h_addr); 1644 m_Peer.sin_addr.s_addr = *(DWORD*)(((hostent*)m_ResolveBuff)->h_addr);
1642} 1645}
1643 1646
1644void CRRQSocket::OnResolved() 1647void CRRQSocket::OnResolved()
1645{ 1648{
1646 CXferSocket::OnResolved(); 1649 CXferSocket::OnResolved();
1647 OnHostKnown(); 1650 OnHostKnown();
1648} 1651}
1649 1652
1650void CRRQSocket::OnHostKnown() 1653void CRRQSocket::OnHostKnown()
1651{ 1654{
1652 ASSERT(m_Daddy); 1655 ASSERT(m_Daddy);
1653 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort); 1656 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort);
1654tftp::tftpOptions o; 1657tftp::tftpOptions o;
1655CString v; 1658CString v;
1656 ASSERT(m_xferSize>=0); 1659 ASSERT(m_xferSize>=0);
1657 v.Format("%lu",m_xferSize); 1660 v.Format("%lu",m_xferSize);
1658 o[tftpoTSize] = v; 1661 o[tftpoTSize] = v;
1659 ASSERT(m__blkSize); 1662 ASSERT(m__blkSize);
1660 v.Format("%u",m__blkSize); 1663 v.Format("%u",m__blkSize);
1661 o[tftpoBSize] = v; 1664 o[tftpoBSize] = v;
1662 ASSERT(m__timeOut); 1665 ASSERT(m__timeOut);
1663 v.Format("%u",m__timeOut); 1666 v.Format("%u",m__timeOut);
1664 o[tftpoTOut] = v; 1667 o[tftpoTOut] = v;
1665 o[tftpoXResume] = "0"; 1668 o[tftpoXResume] = "0";
1666 tftp*p = tftp::Allocate(tftp::tftpWRQ::tftpSize(m_FileName,m_Type,&o)); 1669 tftp*p = tftp::Allocate(tftp::tftpWRQ::tftpSize(m_FileName,m_Type,&o));
1667 ASSERT(p); 1670 ASSERT(p);
1668 p->SetOpcode(tftp::opWRQ); 1671 p->SetOpcode(tftp::opWRQ);
1669 p->data.m_WRQ.Set(m_FileName,m_Type,&o); 1672 p->data.m_WRQ.Set(m_FileName,m_Type,&o);
1670 PostTFTP(p,TRUE); 1673 PostTFTP(p,TRUE);
1671 state=stateInit; 1674 state=stateInit;
1672 UpdateList(); 1675 UpdateList();
1673} 1676}
1674 1677
1675UINT tftp::tftpRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1678UINT tftp::tftpRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1676{ 1679{
1677UINT rv = tftpHdrSize-tftpSlackSize+strlen(file)+1+strlen(type)+1; 1680UINT rv = tftpHdrSize-tftpSlackSize+strlen(file)+1+strlen(type)+1;
1678 if(ops){ 1681 if(ops){
1679 tftpOptions& o = *ops; 1682 tftpOptions& o = *ops;
1680 POSITION p = o.GetStartPosition(); 1683 POSITION p = o.GetStartPosition();
1681 while(p){ 1684 while(p){
1682 CString n,v; 1685 CString n,v;
1683 o.GetNextAssoc(p,n,v); 1686 o.GetNextAssoc(p,n,v);
1684 rv+=n.GetLength()+1+v.GetLength()+1; 1687 rv+=n.GetLength()+1+v.GetLength()+1;
1685 } 1688 }
1686 } 1689 }
1687 return rv; 1690 return rv;
1688} 1691}
1689UINT tftp::tftpRRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1692UINT tftp::tftpRRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1690{ 1693{
1691 return tftp::tftpRQ::tftpSize(file,type,ops); 1694 return tftp::tftpRQ::tftpSize(file,type,ops);
1692} 1695}
1693UINT tftp::tftpWRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1696UINT tftp::tftpWRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1694{ 1697{
1695 return tftp::tftpRQ::tftpSize(file,type,ops); 1698 return tftp::tftpRQ::tftpSize(file,type,ops);
1696} 1699}
1697UINT tftp::tftpOACK::tftpSize(tftp::tftpOptions* ops) 1700UINT tftp::tftpOACK::tftpSize(tftp::tftpOptions* ops)
1698{ 1701{
1699UINT rv = tftpHdrSize-tftpSlackSize; 1702UINT rv = tftpHdrSize-tftpSlackSize;
1700 if(ops){ 1703 if(ops){
1701 tftpOptions& o = *ops; 1704 tftpOptions& o = *ops;
1702 POSITION p = o.GetStartPosition(); 1705 POSITION p = o.GetStartPosition();
1703 while(p){ 1706 while(p){
1704 CString n,v; 1707 CString n,v;
1705 o.GetNextAssoc(p,n,v); 1708 o.GetNextAssoc(p,n,v);
1706 rv+=n.GetLength()+1+v.GetLength()+1; 1709 rv+=n.GetLength()+1+v.GetLength()+1;
1707 } 1710 }
1708 } 1711 }
1709 return rv; 1712 return rv;
1710} 1713}
1711void tftp::tftpRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1714void tftp::tftpRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1712{ 1715{
1713 // MAY BE DANGEROUS! 1716 // MAY BE DANGEROUS!
1714UINT ptr = 0; 1717UINT ptr = 0;
1715 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1; 1718 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
1716 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1; 1719 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
1717 if(ops){ 1720 if(ops){
1718 tftpOptions& o = *ops; 1721 tftpOptions& o = *ops;
1719 POSITION p = o.GetStartPosition(); 1722 POSITION p = o.GetStartPosition();
1720 while(p){ 1723 while(p){
1721 CString n,v; 1724 CString n,v;
1722 o.GetNextAssoc(p,n,v); 1725 o.GetNextAssoc(p,n,v);
1723 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1726 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1724 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1727 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1725 } 1728 }
1726 } 1729 }
1727} 1730}
1728void tftp::tftpRRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1731void tftp::tftpRRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1729{ 1732{
1730 // MAY BE DANGEROUS! 1733 // MAY BE DANGEROUS!
1731UINT ptr = 0; 1734UINT ptr = 0;
1732 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1; 1735 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
1733 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1; 1736 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
1734 if(ops){ 1737 if(ops){
1735 tftpOptions& o = *ops; 1738 tftpOptions& o = *ops;
1736 POSITION p = o.GetStartPosition(); 1739 POSITION p = o.GetStartPosition();
1737 while(p){ 1740 while(p){
1738 CString n,v; 1741 CString n,v;
1739 o.GetNextAssoc(p,n,v); 1742 o.GetNextAssoc(p,n,v);
1740 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1743 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1741 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1744 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1742 } 1745 }
1743 } 1746 }
1744} 1747}
1745void tftp::tftpWRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1748void tftp::tftpWRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1746{ 1749{
1747 // MAY BE DANGEROUS! 1750 // MAY BE DANGEROUS!
1748UINT ptr = 0; 1751UINT ptr = 0;
1749 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1; 1752 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
1750 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1; 1753 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
1751 if(ops){ 1754 if(ops){
1752 tftpOptions& o = *ops; 1755 tftpOptions& o = *ops;
1753 POSITION p = o.GetStartPosition(); 1756 POSITION p = o.GetStartPosition();
1754 while(p){ 1757 while(p){
1755 CString n,v; 1758 CString n,v;
1756 o.GetNextAssoc(p,n,v); 1759 o.GetNextAssoc(p,n,v);
1757 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1760 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1758 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1761 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1759 } 1762 }
1760 } 1763 }
1761} 1764}
1762void tftp::tftpOACK::Set(tftpOptions* ops) 1765void tftp::tftpOACK::Set(tftpOptions* ops)
1763{ 1766{
1764 ASSERT(ops); 1767 ASSERT(ops);
1765UINT ptr = 0; 1768UINT ptr = 0;
1766tftpOptions& o = *ops; 1769tftpOptions& o = *ops;
1767POSITION p = o.GetStartPosition(); 1770POSITION p = o.GetStartPosition();
1768 while(p){ 1771 while(p){
1769 CString n,v; 1772 CString n,v;
1770 o.GetNextAssoc(p,n,v); 1773 o.GetNextAssoc(p,n,v);
1771 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1774 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1772 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1775 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1773 } 1776 }
1774} 1777}
1775 1778
1776void CWRQSocket::OnResolved() 1779void CWRQSocket::OnResolved()
1777{ 1780{
1778 CXferSocket::OnResolved(); 1781 CXferSocket::OnResolved();
1779 OnHostKnown(); 1782 OnHostKnown();
1780} 1783}
1781 1784
1782void CWRQSocket::OnHostKnown() 1785void CWRQSocket::OnHostKnown()
1783{ 1786{
1784 ASSERT(m_Daddy); 1787 ASSERT(m_Daddy);
1785 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort); 1788 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort);
1786tftp::tftpOptions o; 1789tftp::tftpOptions o;
1787CString v; 1790CString v;
1788 o[tftpoTSize]="0"; 1791 o[tftpoTSize]="0";
1789 if(m__blkSize){ 1792 if(m__blkSize){
1790 v.Format("%u",m__blkSize); 1793 v.Format("%u",m__blkSize);
1791 o[tftpoBSize]=v; 1794 o[tftpoBSize]=v;
1792 } 1795 }
1793 if(m__timeOut){ 1796 if(m__timeOut){
1794 v.Format("%u",m__timeOut); 1797 v.Format("%u",m__timeOut);
1795 o[tftpoTOut]=v; 1798 o[tftpoTOut]=v;
1796 } 1799 }
1797 tftp*p = tftp::Allocate(tftp::tftpRRQ::tftpSize(m_FileName,m_Type,&o)); 1800 tftp*p = tftp::Allocate(tftp::tftpRRQ::tftpSize(m_FileName,m_Type,&o));
1798 ASSERT(p); 1801 ASSERT(p);
1799 p->SetOpcode(tftp::opRRQ); 1802 p->SetOpcode(tftp::opRRQ);
1800 p->data.m_RRQ.Set(m_FileName,m_Type,&o); 1803 p->data.m_RRQ.Set(m_FileName,m_Type,&o);
1801 PostTFTP(p,TRUE); 1804 PostTFTP(p,TRUE);
1802 state=stateInit; 1805 state=stateInit;
1803 UpdateList(); 1806 UpdateList();
1804} 1807}
1805 1808
1806void CPumpKINDlg::OnClose() 1809void CPumpKINDlg::OnClose()
1807{ 1810{
1808 OnTrayShowpumpkinwindow(); 1811 OnTrayShowpumpkinwindow();
1809} 1812}
1810 1813
1811void CPumpKINDlg::OnTrayShowpumpkinwindow() 1814void CPumpKINDlg::OnTrayShowpumpkinwindow()
1812{ 1815{
1813 if(IsWindowVisible()){ 1816 if(IsWindowVisible()){
1814 m_bShown=FALSE; 1817 m_bShown=FALSE;
1815 ShowWindow(SW_HIDE); 1818 ShowWindow(SW_HIDE);
1816 }else{ 1819 }else{
1817 m_bShown=TRUE; 1820 m_bShown=TRUE;
1818 ShowWindow(SW_SHOW); 1821 ShowWindow(SW_SHOW);
1819 SetForegroundWindow(); 1822 SetForegroundWindow();
1820 SetFocus(); 1823 SetFocus();
1821 } 1824 }
1822} 1825}
1823 1826
1824void CPumpKINDlg::OnTrayExit() 1827void CPumpKINDlg::OnTrayExit()
1825{ 1828{
1826 OnExit(); 1829 OnExit();
1827} 1830}
1828 1831
1829void CPumpKINDlg::OnTrayAboutpumpkin() 1832void CPumpKINDlg::OnTrayAboutpumpkin()
1830{ 1833{
1831CAboutDlg dlgAbout; 1834CAboutDlg dlgAbout;
1832 dlgAbout.DoModal(); 1835 dlgAbout.DoModal();
1833} 1836}
1834 1837
1835void CPumpKINDlg::OnTrayFetchfile() 1838void CPumpKINDlg::OnTrayFetchfile()
1836{ 1839{
1837 OnGet(); 1840 OnGet();
1838} 1841}
1839 1842
1840void CPumpKINDlg::OnTrayHelp() 1843void CPumpKINDlg::OnTrayHelp()
1841{ 1844{
1842 OnHelp(); 1845 OnHelp();
1843} 1846}
1844 1847
1845void CPumpKINDlg::OnTrayOptions() 1848void CPumpKINDlg::OnTrayOptions()
1846{ 1849{
1847 OnOptions(); 1850 OnOptions();
1848} 1851}
1849 1852
1850void CPumpKINDlg::OnTraySendfile() 1853void CPumpKINDlg::OnTraySendfile()
1851{ 1854{
1852 OnPut(); 1855 OnPut();
1853} 1856}
1854 1857
1855void CPumpKINDlg::LoadSettings() 1858void CPumpKINDlg::LoadSettings()
1856{ 1859{
1857CWinApp *app = AfxGetApp(); 1860CWinApp *app = AfxGetApp();
1858 ASSERT(app); 1861 ASSERT(app);
1859 m_bListen=app->GetProfileInt("TFTPSettings","Listen",m_bListen); 1862 m_bListen=app->GetProfileInt("TFTPSettings","Listen",m_bListen);
1860 m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest); 1863 m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest);
1861 m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess); 1864 m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess);
1862 m_bnwAbort=app->GetProfileString("BellsNWhistles","Abort",m_bnwAbort); 1865 m_bnwAbort=app->GetProfileString("BellsNWhistles","Abort",m_bnwAbort);
1863 m_bTFTPSubdirs=app->GetProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs); 1866 m_bTFTPSubdirs=app->GetProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs);
1864 m_ListenPort=app->GetProfileInt("TFTPSettings","ListenPort",m_ListenPort); 1867 m_ListenPort=app->GetProfileInt("TFTPSettings","ListenPort",m_ListenPort);
1865 m_LogLength=app->GetProfileInt("UISettings","LogLength",m_LogLength); 1868 m_LogLength=app->GetProfileInt("UISettings","LogLength",m_LogLength);
1866 m_PromptTimeOut=app->GetProfileInt("UISettings","PromptTimeout",m_PromptTimeOut); 1869 m_PromptTimeOut=app->GetProfileInt("UISettings","PromptTimeout",m_PromptTimeOut);
1867 m_RRQMode=app->GetProfileInt("TFTPSettings","RRQMode",m_RRQMode); 1870 m_RRQMode=app->GetProfileInt("TFTPSettings","RRQMode",m_RRQMode);
1868 m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); 1871 m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort);
1869 m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); 1872 m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot);
1870 m_LogFile=app->GetProfileString("General","LogFile",m_LogFile); 1873 m_LogFile=app->GetProfileString("General","LogFile",m_LogFile);
1871 m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds())); 1874 m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()));
1872 m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); 1875 m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize);
1873 m_RetryTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds())); 1876 m_RetryTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds()));
1874 m_WRQMode=app->GetProfileInt("TFTPSettings","WRQMode",m_WRQMode); 1877 m_WRQMode=app->GetProfileInt("TFTPSettings","WRQMode",m_WRQMode);
1875 m_bShown=app->GetProfileInt("UISettings","Visble",m_bShown); 1878 m_bShown=app->GetProfileInt("UISettings","Visble",m_bShown);
1876 if(m_TFTPRoot.IsEmpty()){ 1879 if(m_TFTPRoot.IsEmpty()){
1877 DWORD dL = ::GetCurrentDirectory(0,NULL); 1880 DWORD dL = ::GetCurrentDirectory(0,NULL);
1878 VERIFY(::GetCurrentDirectory(dL,m_TFTPRoot.GetBuffer(dL))); 1881 VERIFY(::GetCurrentDirectory(dL,m_TFTPRoot.GetBuffer(dL)));
1879 m_TFTPRoot.ReleaseBuffer(); 1882 m_TFTPRoot.ReleaseBuffer();
1880 } 1883 }
1881 ::SetCurrentDirectory(m_TFTPRoot); 1884 ::SetCurrentDirectory(m_TFTPRoot);
1882 m_aclRules.LoadProfile(app); 1885 m_aclRules.LoadProfile(app);
1883} 1886}
1884 1887
1885void CPumpKINDlg::SaveSettings() 1888void CPumpKINDlg::SaveSettings()
1886{ 1889{
1887CWinApp *app = AfxGetApp(); 1890CWinApp *app = AfxGetApp();
1888 ASSERT(app); 1891 ASSERT(app);
1889 app->WriteProfileInt("TFTPSettings","Listen",m_bListen); 1892 app->WriteProfileInt("TFTPSettings","Listen",m_bListen);
1890 app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest); 1893 app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest);
1891 app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess); 1894 app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess);
1892 app->WriteProfileString("BellsNWhistles","Abort",m_bnwAbort); 1895 app->WriteProfileString("BellsNWhistles","Abort",m_bnwAbort);
1893 app->WriteProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs); 1896 app->WriteProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs);
1894 app->WriteProfileInt("TFTPSettings","ListenPort",m_ListenPort); 1897 app->WriteProfileInt("TFTPSettings","ListenPort",m_ListenPort);
1895 app->WriteProfileInt("UISettings","LogLength",m_LogLength); 1898 app->WriteProfileInt("UISettings","LogLength",m_LogLength);
1896 app->WriteProfileInt("UISettings","PromptTimeout",m_PromptTimeOut); 1899 app->WriteProfileInt("UISettings","PromptTimeout",m_PromptTimeOut);
1897 app->WriteProfileInt("TFTPSettings","RRQMode",m_RRQMode); 1900 app->WriteProfileInt("TFTPSettings","RRQMode",m_RRQMode);
1898 app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); 1901 app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort);
1899 app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); 1902 app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot);
1900 app->WriteProfileString("General","LogFile",m_LogFile); 1903 app->WriteProfileString("General","LogFile",m_LogFile);
1901 app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()); 1904 app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds());
1902 app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); 1905 app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize);
1903 app->WriteProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds()); 1906 app->WriteProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds());
1904 app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode); 1907 app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode);
1905 app->WriteProfileInt("UISettings","Visble",m_bShown); 1908 app->WriteProfileInt("UISettings","Visble",m_bShown);
1906 m_aclRules.SaveProfile(app); 1909 m_aclRules.SaveProfile(app);
1907} 1910}
1908 1911
1909void CPumpKINDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 1912void CPumpKINDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
1910{ 1913{
1911 CDialog::OnWindowPosChanging(lpwndpos); 1914 CDialog::OnWindowPosChanging(lpwndpos);
1912 if(!m_bExiting){ 1915 if(!m_bExiting){
1913 if(m_bShown){ 1916 if(m_bShown){
1914 lpwndpos->flags&=~SWP_HIDEWINDOW; 1917 lpwndpos->flags&=~SWP_HIDEWINDOW;
1915 lpwndpos->flags|=SWP_SHOWWINDOW; 1918 lpwndpos->flags|=SWP_SHOWWINDOW;
1916 }else{ 1919 }else{
1917 lpwndpos->flags&=~SWP_SHOWWINDOW; 1920 lpwndpos->flags&=~SWP_SHOWWINDOW;
1918 lpwndpos->flags|=SWP_HIDEWINDOW; 1921 lpwndpos->flags|=SWP_HIDEWINDOW;
1919 if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu)) 1922 if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu))
1920 GetDesktopWindow()->SetForegroundWindow(); 1923 GetDesktopWindow()->SetForegroundWindow();
1921 } 1924 }
1922 } 1925 }
1923} 1926}
1924 1927
1925CString CXferSocket::ApplyRootGently(LPCTSTR fn) 1928CString CXferSocket::ApplyRootGently(LPCTSTR fn)
1926{ 1929{
1927CString f = fn; 1930CString f = fn;
1928CString rv = f; 1931CString rv = f;
1929 if((!f.IsEmpty()) && f[0]!='\\' && f.Find(":")<0 && f.Find("\\")<0) 1932 if((!f.IsEmpty()) && f[0]!='\\' && f.Find(":")<0 && f.Find("\\")<0)
1930 rv = ApplyRoot(f); 1933 rv = ApplyRoot(f);
1931 return rv; 1934 return rv;
1932} 1935}
1933 1936
1934BOOL CXferSocket::CheckBadRelativeness(LPCTSTR file) 1937BOOL CXferSocket::CheckBadRelativeness(LPCTSTR file)
1935{ 1938{
1936CString tmp = file; 1939CString tmp = file;
1937 if(tmp.IsEmpty()) 1940 if(tmp.IsEmpty())
1938 return FALSE; 1941 return FALSE;
1939 if(tmp.Find("..")>=0) 1942 if(tmp.Find("..")>=0)
1940 return TRUE; 1943 return TRUE;
1941 if(tmp.Find(":")>=0) 1944 if(tmp.Find(":")>=0)
1942 return TRUE; 1945 return TRUE;
1943 if((!m_Daddy->m_bTFTPSubdirs) && m_FileName.Find('\\')>=0) 1946 if((!m_Daddy->m_bTFTPSubdirs) && m_FileName.Find('\\')>=0)
1944 return TRUE; 1947 return TRUE;
1945 return FALSE; 1948 return FALSE;
1946} 1949}
1947 1950
1948void CAboutDlg::OnKlevernet() 1951void CAboutDlg::OnKlevernet()
1949{ 1952{
1950CString url; 1953CString url;
1951 url.LoadString(IDS_KLEVERNET_URL); 1954 url.LoadString(IDS_KLEVERNET_URL);
1952 ShellExecute(::GetDesktopWindow(),"open",url,NULL,NULL,SW_SHOWMAXIMIZED); 1955 ShellExecute(::GetDesktopWindow(),"open",url,NULL,NULL,SW_SHOWMAXIMIZED);
1953} 1956}
1954 1957
1955BOOL CPumpKINDlg::PreTranslateMessage(MSG* pMsg) 1958BOOL CPumpKINDlg::PreTranslateMessage(MSG* pMsg)
1956{ 1959{
1957 // CG: The following block was added by the ToolTips component. 1960 // CG: The following block was added by the ToolTips component.
1958 { 1961 {
1959 // Let the ToolTip process this message. 1962 // Let the ToolTip process this message.
1960 m_tooltip.RelayEvent(pMsg); 1963 m_tooltip.RelayEvent(pMsg);
1961 1964
1962 return CDialog::PreTranslateMessage(pMsg); 1965 return CDialog::PreTranslateMessage(pMsg);
1963 } 1966 }
1964} 1967}
1965 1968
1966void CPumpKINDlg::OnSelchangeLog() 1969void CPumpKINDlg::OnSelchangeLog()
1967{ 1970{
1968int sel = m_Log.GetCurSel(); 1971int sel = m_Log.GetCurSel();
1969 if(sel==LB_ERR){ 1972 if(sel==LB_ERR){
1970 TRACE0("Error retrieving selection\n"); 1973 TRACE0("Error retrieving selection\n");
1971 }else{ 1974 }else{
1972 CTime *t = (CTime*)m_Log.GetItemData(sel); 1975 CTime *t = (CTime*)m_Log.GetItemData(sel);
1973 ASSERT(t); 1976 ASSERT(t);
1974 m_tooltip.UpdateTipText(t->Format(IDS_LOGTIMEFORMAT),&m_Log); 1977 m_tooltip.UpdateTipText(t->Format(IDS_LOGTIMEFORMAT),&m_Log);
1975 } 1978 }
1976} 1979}
1977 1980
1978void CPumpKINDlg::OnTrayOpenfilesfolder() 1981void CPumpKINDlg::OnTrayOpenfilesfolder()
1979{ 1982{
1980 ShellExecute(::GetDesktopWindow(),NULL,m_TFTPRoot,NULL,NULL,SW_SHOWDEFAULT); 1983 ShellExecute(::GetDesktopWindow(),NULL,m_TFTPRoot,NULL,NULL,SW_SHOWDEFAULT);
1981} 1984}
1982 1985
1983void CPumpKINDlg::OnDropFiles(HDROP hDropInfo) 1986void CPumpKINDlg::OnDropFiles(HDROP hDropInfo)
1984{ 1987{
1985UINT files = ::DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,0); 1988UINT files = ::DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,0);
1986 ASSERT(files); 1989 ASSERT(files);
1987 for(UINT file=0;file<files;file++){ 1990 for(UINT file=0;file<files;file++){
1988 CString theFile; 1991 CString theFile;
1989 UINT fileNameLength = ::DragQueryFile(hDropInfo,file,NULL,0); 1992 UINT fileNameLength = ::DragQueryFile(hDropInfo,file,NULL,0);
1990 ASSERT(fileNameLength); 1993 ASSERT(fileNameLength);
1991 VERIFY(::DragQueryFile(hDropInfo,file,theFile.GetBuffer(fileNameLength+5),fileNameLength+4)<=fileNameLength); 1994 VERIFY(::DragQueryFile(hDropInfo,file,theFile.GetBuffer(fileNameLength+5),fileNameLength+4)<=fileNameLength);
1992 theFile.ReleaseBuffer(); 1995 theFile.ReleaseBuffer();
1993 // Send it over! 1996 // Send it over!
1994 CRequestDlg crd(NULL); 1997 CRequestDlg crd(NULL);
1995 crd.m_Drop=TRUE; 1998 crd.m_Drop=TRUE;
1996 crd.m_Put=TRUE; 1999 crd.m_Put=TRUE;
1997 crd.m_BSize=m_BlockSize; 2000 crd.m_BSize=m_BlockSize;
1998 crd.m_LocalFile=theFile; 2001 crd.m_LocalFile=theFile;
1999 if(crd.DoModal()==IDOK){ 2002 if(crd.DoModal()==IDOK){
2000 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL); 2003 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
2001 if(crd.m_BSize) 2004 if(crd.m_BSize)
2002 socket->m__blkSize=crd.m_BSize; 2005 socket->m__blkSize=crd.m_BSize;
2003 if(!socket->Create(crd.m_LocalFile,crd.m_Host)) 2006 if(!socket->Create(crd.m_LocalFile,crd.m_Host))
2004 socket->Destroy(); 2007 socket->Destroy();
2005 } 2008 }
2006 } 2009 }
2007 ::DragFinish(hDropInfo); 2010 ::DragFinish(hDropInfo);
2008} 2011}
2009 2012
2010void CPumpKINDlg::OnCancel() 2013void CPumpKINDlg::OnCancel()
2011{ 2014{
2012 OnClose(); 2015 OnClose();
2013} 2016}
2014 2017
2015CPumpKINDlg::~CPumpKINDlg() 2018CPumpKINDlg::~CPumpKINDlg()
2016{ 2019{
2017 delete m_Trayer; 2020 delete m_Trayer;
2018 delete m_Retrier; 2021 delete m_Retrier;
2019} 2022}
2020 2023
2021void CXferSocket::OnRetry() 2024void CXferSocket::OnRetry()
2022{ 2025{
2023 if(!m_Retry){ 2026 if(!m_Retry){
2024 TRACE("Retrying unretriable..\n"); 2027 TRACE("Retrying unretriable..\n");
2025 return; 2028 return;
2026 } 2029 }
2027 TRACE0("Retrying..\n"); 2030 TRACE0("Retrying..\n");
2028 m_bRetry=TRUE; 2031 m_bRetry=TRUE;
2029 PostTFTP(tftp::Copy(m_Retry)); 2032 PostTFTP(tftp::Copy(m_Retry));
2030 m_bRetry=FALSE; 2033 m_bRetry=FALSE;
2031} 2034}
2032 2035
2033tftp* tftp::Copy(tftp *src) 2036tftp* tftp::Copy(tftp *src)
2034{ 2037{
2035 ASSERT(src); 2038 ASSERT(src);
2036 ASSERT(src->length); 2039 ASSERT(src->length);
2037tftp* rv = Allocate(src->length); 2040tftp* rv = Allocate(src->length);
2038 ASSERT(rv); 2041 ASSERT(rv);
2039 memmove(rv,src,tftpSlackSize+src->length); 2042 memmove(rv,src,tftpSlackSize+src->length);
2040 return rv; 2043 return rv;
2041} 2044}
2042 2045
2043void CXferSocket::SetTry(tftp *p) 2046void CXferSocket::SetTry(tftp *p)
2044{ 2047{
2045 if(m_Retry) 2048 if(m_Retry)
2046 delete m_Retry; 2049 delete m_Retry;
2047 m_Retry=p?tftp::Copy(p):NULL; 2050 m_Retry=p?tftp::Copy(p):NULL;
2048} 2051}
2049 2052
2050void CPumpKINDlg::OnHelp() 2053void CPumpKINDlg::OnHelp()
2051{ 2054{
2052 AfxGetApp()->WinHelp(0,HELP_FINDER); 2055 AfxGetApp()->WinHelp(0,HELP_FINDER);
2053} 2056}
2054 2057
2055BOOL CListenSocket::SetListen(BOOL b) { 2058BOOL CListenSocket::SetListen(BOOL b) {
2056 ASSERT(m_Daddy); 2059 ASSERT(m_Daddy);
2057 if(b==m_bListen) 2060 if(b==m_bListen)
2058 return TRUE; 2061 return TRUE;
2059 if(b) { 2062 if(b) {
2060 if(!Create(m_Daddy->m_ListenPort,SOCK_DGRAM)) 2063 if(!Create(m_Daddy->m_ListenPort,SOCK_DGRAM))
2061 return FALSE; 2064 return FALSE;
2062 return m_bListen=TRUE; 2065 return m_bListen=TRUE;
2063 }else{ 2066 }else{
2064 Close(); m_bListen=FALSE; 2067 Close(); m_bListen=FALSE;
2065 return TRUE; 2068 return TRUE;
2066 } 2069 }
2067} 2070}
2068 2071
2069void CPumpKINDlg::OnListening() 2072void CPumpKINDlg::OnListening()
2070{ 2073{
2071 if(!m_Listener.SetListen(m_ListenCtl.GetCheck()==1)) { 2074 if(!m_Listener.SetListen(m_ListenCtl.GetCheck()==1)) {
2072 TRACE0("Failed to create socket\n"); 2075 TRACE0("Failed to create socket\n");
2073 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); 2076 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
2074 } 2077 }
2075 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); 2078 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
2076 m_bListen=m_Listener.m_bListen; 2079 m_bListen=m_Listener.m_bListen;
2077} 2080}
2078 2081
2079void CPumpKINDlg::OnTrayListen() 2082void CPumpKINDlg::OnTrayListen()
2080{ 2083{
2081 if(!m_Listener.SetListen(!m_Listener.m_bListen)) { 2084 if(!m_Listener.SetListen(!m_Listener.m_bListen)) {
2082 TRACE0("Failed to create socket\n"); 2085 TRACE0("Failed to create socket\n");
2083 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); 2086 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
2084 } 2087 }
2085 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); 2088 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
2086 m_bListen=m_Listener.m_bListen; 2089 m_bListen=m_Listener.m_bListen;
2087} 2090}
2088 2091
2089void CPumpKINDlg::LogLine(LPCTSTR str) 2092void CPumpKINDlg::LogLine(LPCTSTR str)
2090{ 2093{
2091 LogLineToScreen(str); 2094 LogLineToScreen(str);
2092 if(!m_LogFile.IsEmpty()) { 2095 if(!m_LogFile.IsEmpty()) {
2093 if(!Klever::LogRecord((LPCTSTR)m_LogFile,str)) { 2096 if(!Klever::LogRecord((LPCTSTR)m_LogFile,str)) {
2094 if(m_lastlogerr!=m_LogFile) { 2097 if(m_lastlogerr!=m_LogFile) {
2095 CString tmp; 2098 CString tmp;
2096 tmp.Format(IDS_LOG_LOGERROR,m_LogFile); 2099 tmp.Format(IDS_LOG_LOGERROR,m_LogFile);
2097 LogLineToScreen(tmp); 2100 LogLineToScreen(tmp);
2098 m_lastlogerr=m_LogFile; 2101 m_lastlogerr=m_LogFile;
2099 } 2102 }
2100 } 2103 }
2101 } 2104 }
2102} 2105}
2103 2106
2104void CPumpKINDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 2107void CPumpKINDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
2105{ 2108{
2106 CDialog::OnGetMinMaxInfo(lpMMI); 2109 CDialog::OnGetMinMaxInfo(lpMMI);
2107 if(m_MinSize.cx>0 && m_MinSize.cy>0){ 2110 if(m_MinSize.cx>0 && m_MinSize.cy>0){
2108 lpMMI->ptMinTrackSize.x = m_MinSize.cx; 2111 lpMMI->ptMinTrackSize.x = m_MinSize.cx;
2109 lpMMI->ptMinTrackSize.y = m_MinSize.cy; 2112 lpMMI->ptMinTrackSize.y = m_MinSize.cy;
2110 } 2113 }
2111} 2114}
2112 2115
2113void CPumpKINDlg::OnSize(UINT nType, int cx, int cy) 2116void CPumpKINDlg::OnSize(UINT nType, int cx, int cy)
2114{ 2117{
2115 CDialog::OnSize(nType, cx, cy); 2118 CDialog::OnSize(nType, cx, cy);
2116 if(nType==SIZE_RESTORED) 2119 if(nType==SIZE_RESTORED)
2117 RecalcLayout(cx,cy); 2120 RecalcLayout(cx,cy);
2118} 2121}
2119 2122
2120void CPumpKINDlg::RecalcLayout(int,int) 2123void CPumpKINDlg::RecalcLayout(int,int)
2121{ 2124{
2122 CRect wrc; 2125 CRect wrc;
2123 GetClientRect(&wrc); 2126 GetClientRect(&wrc);
2124 AdjustButton(m_GetCtl,wrc); 2127 AdjustButton(m_GetCtl,wrc);
2125 AdjustButton(m_PutCtl,wrc); 2128 AdjustButton(m_PutCtl,wrc);
2126 AdjustButton(m_AbortCtl,wrc); 2129 AdjustButton(m_AbortCtl,wrc);
2127 AdjustButton(m_HelpCtl,wrc); 2130 AdjustButton(m_HelpCtl,wrc);
2128 AdjustButton(m_ExitCtl,wrc); 2131 AdjustButton(m_ExitCtl,wrc);
2129 AdjustButton(m_OptionsCtl,wrc); 2132 AdjustButton(m_OptionsCtl,wrc);
2130 CRect brc; 2133 CRect brc;
2131 m_List.GetWindowRect(&brc); ScreenToClient(&brc); 2134 m_List.GetWindowRect(&brc); ScreenToClient(&brc);
2132 m_List.SetWindowPos( 2135 m_List.SetWindowPos(
2133 0, 2136 0,
2134 brc.left, brc.top, 2137 brc.left, brc.top,
2135 wrc.right-m_rightGapList-brc.left, brc.bottom-brc.top, 2138 wrc.right-m_rightGapList-brc.left, brc.bottom-brc.top,
2136 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS ); 2139 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS );
2137 m_Log.GetWindowRect(&brc); ScreenToClient(&brc); 2140 m_Log.GetWindowRect(&brc); ScreenToClient(&brc);
2138 m_Log.SetWindowPos( 2141 m_Log.SetWindowPos(
2139 0, 2142 0,
2140 brc.left, brc.top, 2143 brc.left, brc.top,
2141 wrc.right-m_rightGapButtons-brc.left, wrc.bottom-m_bottomGapLog-brc.top, 2144 wrc.right-m_rightGapButtons-brc.left, wrc.bottom-m_bottomGapLog-brc.top,
2142 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS ); 2145 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS );
2143 m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc); 2146 m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc);
2144 m_ListenCtl.SetWindowPos( 2147 m_ListenCtl.SetWindowPos(
2145 0, 2148 0,
2146 wrc.right-brc.Width()-m_rightGapButtons, wrc.bottom-brc.Height()-m_bottomGapListen, 2149 wrc.right-brc.Width()-m_rightGapButtons, wrc.bottom-brc.Height()-m_bottomGapListen,
2147 0,0, 2150 0,0,
2148 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS ); 2151 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS );
2149 int i = m_Log.GetCount(); 2152 int i = m_Log.GetCount();
2150 if(i!=LB_ERR) 2153 if(i!=LB_ERR)
2151 m_Log.SetCurSel(i-1); 2154 m_Log.SetCurSel(i-1);
2152} 2155}
2153 2156
2154void CPumpKINDlg::AdjustButton(CWnd& w,CRect& wrc) 2157void CPumpKINDlg::AdjustButton(CWnd& w,CRect& wrc)
2155{ 2158{
2156 CRect brc; 2159 CRect brc;
2157 w.GetWindowRect(&brc); ScreenToClient(&brc); 2160 w.GetWindowRect(&brc); ScreenToClient(&brc);
2158 w.SetWindowPos( 2161 w.SetWindowPos(
2159 0, 2162 0,
2160 wrc.right-brc.Width()-m_rightGapButtons, brc.top, 2163 wrc.right-brc.Width()-m_rightGapButtons, brc.top,
2161 0, 0, 2164 0, 0,
2162 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS ); 2165 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS );
2163} 2166}