summaryrefslogtreecommitdiffabout
path: root/PumpKINDlg.cpp
authorMichael Krelin <hacker@klever.net>2006-07-02 22:16:25 (UTC)
committer Michael Krelin <hacker@klever.net>2006-07-02 22:16:25 (UTC)
commit577427e68ef10a4d2b75d28e42b22952ae3bcf23 (patch) (unidiff)
tree24c8fc94ea6524059cab7927ef76639bb1a1a98d /PumpKINDlg.cpp
parent24e693797daef020ece3fa19bb5acce000e37165 (diff)
downloadpumpkin-577427e68ef10a4d2b75d28e42b22952ae3bcf23.zip
pumpkin-577427e68ef10a4d2b75d28e42b22952ae3bcf23.tar.gz
pumpkin-577427e68ef10a4d2b75d28e42b22952ae3bcf23.tar.bz2
Do not close RRQ socket until the last ACK is received.
git-svn-id: http://svn.klever.net/kin/pumpkin/trunk@152 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'PumpKINDlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--PumpKINDlg.cpp70
1 files changed, 37 insertions, 33 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp
index 070f3e8..2a01918 100644
--- a/PumpKINDlg.cpp
+++ b/PumpKINDlg.cpp
@@ -1,2159 +1,2163 @@
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() 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()?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 state = stateXfer; 781 state = stateXfer;
782 m_ACK=0; 782 m_ACK=0;
783 if(o.GetCount()){ 783 if(o.GetCount()){
784 tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o)); 784 tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o));
785 ASSERT(p); 785 ASSERT(p);
786 p->SetOpcode(tftp::opOACK); 786 p->SetOpcode(tftp::opOACK);
787 p->data.m_OACK.Set(&o); 787 p->data.m_OACK.Set(&o);
788 PostTFTP(p,TRUE); 788 PostTFTP(p,TRUE);
789 }else 789 }else
790 DoXfer(); 790 DoXfer();
791 } 791 }
792 return TRUE; 792 return TRUE;
793} 793}
794 794
795CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) 795CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin)
796 : CXferSocket(daddy,fileName,type,sin) 796 : CXferSocket(daddy,fileName,type,sin)
797{ 797{
798 m_ACK=0; 798 m_ACK=0;
799 m_LastSlack=0; 799 m_LastSlack=0;
800} 800}
801 801
802UINT tftp::tftpERROR::tftpSize(LPCTSTR msg) 802UINT tftp::tftpERROR::tftpSize(LPCTSTR msg)
803{ 803{
804 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1; 804 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1;
805} 805}
806 806
807tftp* tftp::Allocate(UINT tftpSize) 807tftp* tftp::Allocate(UINT tftpSize)
808{ 808{
809 ASSERT(tftpSize); 809 ASSERT(tftpSize);
810tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize]; 810tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize];
811 ASSERT(rv); 811 ASSERT(rv);
812 rv->length=tftpSize; 812 rv->length=tftpSize;
813 return rv; 813 return rv;
814} 814}
815 815
816void tftp::errSet(UINT code,LPCTSTR msg) 816void tftp::errSet(UINT code,LPCTSTR msg)
817{ 817{
818 ASSERT(this); 818 ASSERT(this);
819 ASSERT(length>=data.m_ERROR.tftpSize(msg)); 819 ASSERT(length>=data.m_ERROR.tftpSize(msg));
820 strcpy((char*)data.m_ERROR.data,msg); 820 strcpy((char*)data.m_ERROR.data,msg);
821 data.m_ERROR.SetCode(code); 821 data.m_ERROR.SetCode(code);
822} 822}
823 823
824void CXferSocket::PostTFTP(tftp* p,BOOL retryable) 824void CXferSocket::PostTFTP(tftp* p,BOOL retryable)
825{ 825{
826 ASSERT(p); 826 ASSERT(p);
827 m_Queue.AddTail(p); 827 m_Queue.AddTail(p);
828 DoSelect(); 828 DoSelect();
829 if(!m_bRetry){ 829 if(!m_bRetry){
830 if(retryable) 830 if(retryable)
831 SetTry(p); 831 SetTry(p);
832 else 832 else
833 SetTry(); 833 SetTry();
834 } 834 }
835 ResetTimeout(); 835 ResetTimeout();
836} 836}
837 837
838void CXferSocket::Deny(UINT errCode,UINT errID) 838void CXferSocket::Deny(UINT errCode,UINT errID)
839{ 839{
840 PostError(errCode,errID); 840 PostError(errCode,errID);
841 state=stateDeny; 841 state=stateDeny;
842} 842}
843 843
844void CRRQSocket::DoXfer() 844void CRRQSocket::DoXfer()
845{ 845{
846tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize)); 846tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize));
847 ASSERT(p); 847 ASSERT(p);
848 p->SetOpcode(tftp::opDATA); 848 p->SetOpcode(tftp::opDATA);
849 TRY{ 849 TRY{
850 m_File.Seek(m_ACK*m_blkSize,CFile::begin); 850 m_File.Seek(m_ACK*m_blkSize,CFile::begin);
851 int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize); 851 int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize);
852 p->data.m_DATA.SetBlock(m_ACK+1); 852 p->data.m_DATA.SetBlock(m_ACK+1);
853 p->length=p->length-m_blkSize+bytes; 853 p->length=p->length-m_blkSize+bytes;
854 m_LastSlack = m_blkSize-bytes; 854 m_LastSlack = m_blkSize-bytes;
855 PostTFTP(p); 855 PostTFTP(p);
856 if(bytes<m_blkSize){ 856 if(bytes<m_blkSize){
857 state=stateFinish; 857 state=stateClosing; m_ACKtoClose = m_ACK+1;
858 ASSERT(m_Daddy);
859 CString tmp;
860 tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName);
861 m_Daddy->LogLine(tmp);
862 } 858 }
863 }CATCH(CFileException,e){ 859 }CATCH(CFileException,e){
864 Deny(e); 860 Deny(e);
865 }END_CATCH 861 }END_CATCH
866} 862}
867 863
868UINT tftp::tftpDATA::tftpSize(UINT blkSize) 864UINT tftp::tftpDATA::tftpSize(UINT blkSize)
869{ 865{
870 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA) 866 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA)
871 -sizeof(BYTE)+blkSize; 867 -sizeof(BYTE)+blkSize;
872} 868}
873 869
874void CXferSocket::Deny(CFileException* e) 870void CXferSocket::Deny(CFileException* e)
875{ 871{
876 PostError(e); 872 PostError(e);
877 state=stateDeny; 873 state=stateDeny;
878} 874}
879 875
880void CXferSocket::PostError(UINT errCode,UINT errID) 876void CXferSocket::PostError(UINT errCode,UINT errID)
881{ 877{
882CString msg; 878CString msg;
883 msg.LoadString(errID); 879 msg.LoadString(errID);
884 ASSERT(m_Daddy); 880 ASSERT(m_Daddy);
885 /*// *** 881 /*// ***
886CString tmp; 882CString tmp;
887 tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg); 883 tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg);
888 m_Daddy->LogLine(tmp); 884 m_Daddy->LogLine(tmp);
889 */ 885 */
890tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg)); 886tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg));
891err->SetOpcode(tftp::opERROR); 887err->SetOpcode(tftp::opERROR);
892 err->errSet(errCode,msg); 888 err->errSet(errCode,msg);
893 PostTFTP(err); 889 PostTFTP(err);
894} 890}
895 891
896void CXferSocket::PostError(CFileException* e) 892void CXferSocket::PostError(CFileException* e)
897{ 893{
898UINT eCode; 894UINT eCode;
899UINT eMsgID; 895UINT eMsgID;
900 switch(e->m_cause){ 896 switch(e->m_cause){
901 case CFileException::fileNotFound: 897 case CFileException::fileNotFound:
902 eCode=tftp::errNotFound; 898 eCode=tftp::errNotFound;
903 eMsgID=IDS_TFTP_ERROR_NOTFOUND; 899 eMsgID=IDS_TFTP_ERROR_NOTFOUND;
904 break; 900 break;
905 case CFileException::accessDenied: 901 case CFileException::accessDenied:
906 eCode=tftp::errAccessViolation; 902 eCode=tftp::errAccessViolation;
907 eMsgID=IDS_TFTP_ERROR_ACCESS; 903 eMsgID=IDS_TFTP_ERROR_ACCESS;
908 break; 904 break;
909 case CFileException::directoryFull: 905 case CFileException::directoryFull:
910 eCode=tftp::errDiskFull; 906 eCode=tftp::errDiskFull;
911 eMsgID=IDS_TFTP_ERROR_DIRFULL; 907 eMsgID=IDS_TFTP_ERROR_DIRFULL;
912 break; 908 break;
913 case CFileException::sharingViolation: 909 case CFileException::sharingViolation:
914 eCode=tftp::errAccessViolation; 910 eCode=tftp::errAccessViolation;
915 eMsgID=IDS_TFTP_ERROR_SHARING; 911 eMsgID=IDS_TFTP_ERROR_SHARING;
916 break; 912 break;
917 case CFileException::diskFull: 913 case CFileException::diskFull:
918 eCode=tftp::errDiskFull; 914 eCode=tftp::errDiskFull;
919 eMsgID=IDS_TFTP_ERROR_DISKFULL; 915 eMsgID=IDS_TFTP_ERROR_DISKFULL;
920 break; 916 break;
921 default: 917 default:
922 eCode=tftp::errUndefined; 918 eCode=tftp::errUndefined;
923 eMsgID=IDS_TFTP_ERROR_UNDEFINED; 919 eMsgID=IDS_TFTP_ERROR_UNDEFINED;
924 break; 920 break;
925 } 921 }
926 PostError(eCode,eMsgID); 922 PostError(eCode,eMsgID);
927} 923}
928 924
929ULONG CRRQSocket::GetACK(void) 925ULONG CRRQSocket::GetACK(void)
930{ 926{
931 return (m_ACK*m_blkSize)-m_LastSlack; 927 return (m_ACK*m_blkSize)-m_LastSlack;
932} 928}
933 929
934BOOL CRRQSocket::OnTFTP(tftp* p) 930BOOL CRRQSocket::OnTFTP(tftp* p)
935{ 931{
936BOOL rv = TRUE; 932BOOL rv = TRUE;
937 switch(p->Opcode()){ 933 switch(p->Opcode()){
938 case tftp::opOACK: 934 case tftp::opOACK:
939 m_ACK=0; 935 {
940 ASSERT(state!=stateFinish); 936 m_ACK=0;
941 { 937 ASSERT(state!=stateFinish);
942 tftp::tftpOptions o; 938 tftp::tftpOptions o;
943 if(p->GetOptions(&o)){ 939 if(p->GetOptions(&o)){
944 CString v; 940 CString v;
945 if(o.Lookup(tftpoBSize,v)){ 941 if(o.Lookup(tftpoBSize,v)){
946 m_blkSize=atoi(v); 942 m_blkSize=atoi(v);
947 if(!m_blkSize){// *** More sanity checks 943 if(!m_blkSize){// *** More sanity checks
948 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); 944 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
949 rv = TRUE; 945 rv = TRUE;
950 break; 946 break;
947 }
951 } 948 }
952 } 949 if(o.Lookup(tftpoTOut,v)){
953 if(o.Lookup(tftpoTOut,v)){ 950 m_timeOut=atoi(v);
954 m_timeOut=atoi(v); 951 if(!m_timeOut){// *** More sanity checks
955 if(!m_timeOut){// *** More sanity checks 952 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
956 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); 953 rv = TRUE;
957 rv = TRUE; 954 break;
958 break; 955 }
956 }
957 if(o.Lookup(tftpoXResume,v)){
958 m_ACK=atoi(v);
959 } 959 }
960 } 960 }
961 if(o.Lookup(tftpoXResume,v)){ 961 UpdateList();
962 m_ACK=atoi(v); 962 DoXfer();
963 }
964 } 963 }
965 UpdateList();
966 DoXfer();
967 }
968 break; 964 break;
969 case tftp::opACK: 965 case tftp::opACK:
970 m_ACK=p->data.m_ACK.Block(); 966 m_ACK=p->data.m_ACK.Block();
971 if(state!=stateFinish){ 967 if(state==stateClosing && m_ACK==m_ACKtoClose) {
968 state = stateFinish;
969 ASSERT(m_Daddy);
970 CString tmp;
971 tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName);
972 m_Daddy->LogLine(tmp);
973 rv = FALSE;
974 DoSelect(TRUE);
975 }else if(state!=stateFinish){
972 UpdateList(); 976 UpdateList();
973 DoXfer(); 977 DoXfer();
974 } 978 }
975 break; 979 break;
976 case tftp::opERROR: 980 case tftp::opERROR:
977 { 981 {
978 ASSERT(m_Daddy); 982 ASSERT(m_Daddy);
979 CString tmp; 983 CString tmp;
980 tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage()); 984 tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage());
981 m_Daddy->LogLine(tmp); 985 m_Daddy->LogLine(tmp);
982 } 986 }
983 Destroy(FALSE); 987 Destroy(FALSE);
984 rv = FALSE; 988 rv = FALSE;
985 break; 989 break;
986 default: 990 default:
987 { 991 {
988 ASSERT(m_Daddy); 992 ASSERT(m_Daddy);
989 CString tmp; 993 CString tmp;
990 tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode()); 994 tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode());
991 m_Daddy->LogLine(tmp); 995 m_Daddy->LogLine(tmp);
992 // *** Self destruct maybe?? 996 // *** Self destruct maybe??
993 } 997 }
994 break; 998 break;
995 } 999 }
996 return rv; 1000 return rv;
997} 1001}
998 1002
999BOOL CWRQSocket::OnTFTP(tftp* p) 1003BOOL CWRQSocket::OnTFTP(tftp* p)
1000{ 1004{
1001 switch(p->Opcode()){ 1005 switch(p->Opcode()){
1002 case tftp::opOACK: 1006 case tftp::opOACK:
1003 ASSERT(state!=stateFinish); 1007 ASSERT(state!=stateFinish);
1004 { 1008 {
1005 if(m_bResume) 1009 if(m_bResume)
1006 m_ACK=m_File.GetLength()/m_blkSize; 1010 m_ACK=m_File.GetLength()/m_blkSize;
1007 else 1011 else
1008 m_ACK=0; 1012 m_ACK=0;
1009 tftp::tftpOptions o; 1013 tftp::tftpOptions o;
1010 if(p->GetOptions(&o)){ 1014 if(p->GetOptions(&o)){
1011 CString v; 1015 CString v;
1012 if(o.Lookup(tftpoBSize,v)){ 1016 if(o.Lookup(tftpoBSize,v)){
1013 m_blkSize=atoi(v); 1017 m_blkSize=atoi(v);
1014 if(!m_blkSize){// *** More sanity checks 1018 if(!m_blkSize){// *** More sanity checks
1015 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); 1019 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
1016 return TRUE; 1020 return TRUE;
1017 } 1021 }
1018 } 1022 }
1019 if(o.Lookup(tftpoTOut,v)){ 1023 if(o.Lookup(tftpoTOut,v)){
1020 m_timeOut=atoi(v); 1024 m_timeOut=atoi(v);
1021 if(!m_timeOut){// *** More sanity checks 1025 if(!m_timeOut){// *** More sanity checks
1022 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); 1026 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
1023 return TRUE; 1027 return TRUE;
1024 } 1028 }
1025 } 1029 }
1026 if(o.Lookup(tftpoTSize,v)){ 1030 if(o.Lookup(tftpoTSize,v)){
1027 m_xferSize=atoi(v); 1031 m_xferSize=atoi(v);
1028 } 1032 }
1029 } 1033 }
1030 UpdateList(); 1034 UpdateList();
1031 DoXfer(); 1035 DoXfer();
1032 } 1036 }
1033 break; 1037 break;
1034 case tftp::opDATA: 1038 case tftp::opDATA:
1035 { 1039 {
1036 UINTblock = p->data.m_DATA.Block(); 1040 UINTblock = p->data.m_DATA.Block();
1037 TRY{ 1041 TRY{
1038 m_File.Seek((block-1)*m_blkSize,CFile::begin); 1042 m_File.Seek((block-1)*m_blkSize,CFile::begin);
1039 int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize); 1043 int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize);
1040 if(bytes){ 1044 if(bytes){
1041 m_File.Write(p->data.m_DATA.data,bytes); 1045 m_File.Write(p->data.m_DATA.data,bytes);
1042 // *** Move to the other place where we can do it not that often 1046 // *** Move to the other place where we can do it not that often
1043 m_File.SetLength(m_File.GetPosition()); 1047 m_File.SetLength(m_File.GetPosition());
1044 } 1048 }
1045 if(bytes<m_blkSize){ 1049 if(bytes<m_blkSize){
1046 state=stateFinish; 1050 state=stateFinish;
1047 ASSERT(m_Daddy); 1051 ASSERT(m_Daddy);
1048 CString tmp; 1052 CString tmp;
1049 tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName); 1053 tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName);
1050 m_Daddy->LogLine(tmp); 1054 m_Daddy->LogLine(tmp);
1051 } 1055 }
1052 m_ACK=block; 1056 m_ACK=block;
1053 m_LastSlack=m_blkSize-bytes; 1057 m_LastSlack=m_blkSize-bytes;
1054 UpdateList(); 1058 UpdateList();
1055 DoXfer(); 1059 DoXfer();
1056 }CATCH(CFileException,e){ 1060 }CATCH(CFileException,e){
1057 Deny(e); 1061 Deny(e);
1058 }END_CATCH 1062 }END_CATCH
1059 } 1063 }
1060 break; 1064 break;
1061 case tftp::opERROR: 1065 case tftp::opERROR:
1062 { 1066 {
1063 ASSERT(m_Daddy); 1067 ASSERT(m_Daddy);
1064 CString tmp; 1068 CString tmp;
1065 tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage()); 1069 tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage());
1066 m_Daddy->LogLine(tmp); 1070 m_Daddy->LogLine(tmp);
1067 } 1071 }
1068 Destroy(FALSE); 1072 Destroy(FALSE);
1069 return FALSE; 1073 return FALSE;
1070 default: 1074 default:
1071 { 1075 {
1072 ASSERT(m_Daddy); 1076 ASSERT(m_Daddy);
1073 CString tmp; 1077 CString tmp;
1074 tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode()); 1078 tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode());
1075 m_Daddy->LogLine(tmp); 1079 m_Daddy->LogLine(tmp);
1076 // *** Self destruct maybe?? 1080 // *** Self destruct maybe??
1077 } 1081 }
1078 break; 1082 break;
1079 } 1083 }
1080 return TRUE; 1084 return TRUE;
1081} 1085}
1082 1086
1083void tftp::SetOpcode(WORD op) 1087void tftp::SetOpcode(WORD op)
1084{ 1088{
1085 opcode = REVERSEBYTES(op); 1089 opcode = REVERSEBYTES(op);
1086} 1090}
1087void tftp::tftpDATA::SetBlock(WORD b) 1091void tftp::tftpDATA::SetBlock(WORD b)
1088{ 1092{
1089 block=REVERSEBYTES(b); 1093 block=REVERSEBYTES(b);
1090} 1094}
1091WORD tftp::tftpDATA::Block() 1095WORD tftp::tftpDATA::Block()
1092{ 1096{
1093 return REVERSEBYTES(block); 1097 return REVERSEBYTES(block);
1094} 1098}
1095WORD tftp::tftpACK::Block() 1099WORD tftp::tftpACK::Block()
1096{ 1100{
1097 return REVERSEBYTES(block); 1101 return REVERSEBYTES(block);
1098} 1102}
1099void tftp::tftpACK::SetBlock(WORD b) 1103void tftp::tftpACK::SetBlock(WORD b)
1100{ 1104{
1101 block = REVERSEBYTES(b); 1105 block = REVERSEBYTES(b);
1102} 1106}
1103WORD tftp::tftpERROR::Code() 1107WORD tftp::tftpERROR::Code()
1104{ 1108{
1105 return REVERSEBYTES(code); 1109 return REVERSEBYTES(code);
1106} 1110}
1107void tftp::tftpERROR::SetCode(WORD c) 1111void tftp::tftpERROR::SetCode(WORD c)
1108{ 1112{
1109 code = REVERSEBYTES(c); 1113 code = REVERSEBYTES(c);
1110} 1114}
1111 1115
1112 1116
1113CString tftp::errMessage() 1117CString tftp::errMessage()
1114{ 1118{
1115CString rv; 1119CString rv;
1116 if(memchr(data.m_ERROR.data,0,length-(tftpHdrSize-tftpSlackSize)-sizeof(data.m_ERROR.code))) 1120 if(memchr(data.m_ERROR.data,0,length-(tftpHdrSize-tftpSlackSize)-sizeof(data.m_ERROR.code)))
1117 rv = (LPCTSTR)data.m_ERROR.data; 1121 rv = (LPCTSTR)data.m_ERROR.data;
1118 return rv; 1122 return rv;
1119} 1123}
1120 1124
1121void CXferSocket::Destroy(BOOL success) 1125void CXferSocket::Destroy(BOOL success)
1122{ 1126{
1123 if(m_wndResolver){ 1127 if(m_wndResolver){
1124 delete m_wndResolver; 1128 delete m_wndResolver;
1125 m_wndResolver=NULL; 1129 m_wndResolver=NULL;
1126 } 1130 }
1127 SetTry(); 1131 SetTry();
1128 m_Daddy->m_bnw.StartSound( 1132 m_Daddy->m_bnw.StartSound(
1129 success 1133 success
1130 ? m_Daddy->m_bnwSuccess 1134 ? m_Daddy->m_bnwSuccess
1131 : m_Daddy->m_bnwAbort 1135 : m_Daddy->m_bnwAbort
1132 ); 1136 );
1133 if(m_File.m_hFile!=CFile::hFileNull){ 1137 if(m_File.m_hFile!=CFile::hFileNull){
1134 TRY{ 1138 TRY{
1135 m_File.Close(); 1139 m_File.Close();
1136 }CATCH(CFileException,e){ 1140 }CATCH(CFileException,e){
1137 TRACE0("Error closing file\n"); 1141 TRACE0("Error closing file\n");
1138 }END_CATCH 1142 }END_CATCH
1139 } 1143 }
1140 ASSERT(m_Daddy); 1144 ASSERT(m_Daddy);
1141 m_Daddy->KillTimer(m_hSocket); 1145 m_Daddy->KillTimer(m_hSocket);
1142 m_Daddy->m_Xfers.RemoveKey(m_hSocket); 1146 m_Daddy->m_Xfers.RemoveKey(m_hSocket);
1143LV_FINDINFO lvf; 1147LV_FINDINFO lvf;
1144 memset(&lvf,0,sizeof(lvf)); 1148 memset(&lvf,0,sizeof(lvf));
1145 lvf.flags=LVFI_PARAM; 1149 lvf.flags=LVFI_PARAM;
1146 lvf.lParam=(LPARAM)this; 1150 lvf.lParam=(LPARAM)this;
1147int i = m_Daddy->m_List.FindItem(&lvf); 1151int i = m_Daddy->m_List.FindItem(&lvf);
1148 if(i>=0) 1152 if(i>=0)
1149 m_Daddy->m_List.DeleteItem(i); 1153 m_Daddy->m_List.DeleteItem(i);
1150 delete this; 1154 delete this;
1151} 1155}
1152 1156
1153void CPumpKINDlg::LogLineToScreen(LPCTSTR str) 1157void CPumpKINDlg::LogLineToScreen(LPCTSTR str)
1154{ 1158{
1155 ASSERT(m_LogLength); 1159 ASSERT(m_LogLength);
1156 while(m_Log.GetCount()>m_LogLength && m_Log.GetCount()!=LB_ERR){ 1160 while(m_Log.GetCount()>m_LogLength && m_Log.GetCount()!=LB_ERR){
1157 CTime *t = (CTime*)m_Log.GetItemData(0); 1161 CTime *t = (CTime*)m_Log.GetItemData(0);
1158 if(((DWORD)t)!=LB_ERR){ 1162 if(((DWORD)t)!=LB_ERR){
1159 ASSERT(t); 1163 ASSERT(t);
1160 m_LogTimes.RemoveKey(t); 1164 m_LogTimes.RemoveKey(t);
1161 delete t; 1165 delete t;
1162 } 1166 }
1163 m_Log.DeleteString(0); 1167 m_Log.DeleteString(0);
1164 } 1168 }
1165int i = m_Log.AddString(str); 1169int i = m_Log.AddString(str);
1166 ASSERT(i!=LB_ERR); 1170 ASSERT(i!=LB_ERR);
1167CTime *t = new CTime(CTime::GetCurrentTime()); 1171CTime *t = new CTime(CTime::GetCurrentTime());
1168 m_Log.SetItemData(i,(DWORD)(m_LogTimes[t]=t)); 1172 m_Log.SetItemData(i,(DWORD)(m_LogTimes[t]=t));
1169 m_Log.SetCurSel(i); 1173 m_Log.SetCurSel(i);
1170} 1174}
1171 1175
1172void CPumpKINDlg::LogLine(UINT msgID) 1176void CPumpKINDlg::LogLine(UINT msgID)
1173{ 1177{
1174CString tmp; 1178CString tmp;
1175 tmp.Format(msgID); 1179 tmp.Format(msgID);
1176 LogLine(tmp); 1180 LogLine(tmp);
1177} 1181}
1178 1182
1179void CXferSocket::TurnSlashes(CString& fn,BOOL bBack) 1183void CXferSocket::TurnSlashes(CString& fn,BOOL bBack)
1180{ 1184{
1181 ints = fn.Find(bBack?'/':'\\'); 1185 ints = fn.Find(bBack?'/':'\\');
1182 while(s>=0){ 1186 while(s>=0){
1183 fn.SetAt(s,bBack?'\\':'/'); 1187 fn.SetAt(s,bBack?'\\':'/');
1184 s = fn.Find(bBack?'/':'\\'); 1188 s = fn.Find(bBack?'/':'\\');
1185 } 1189 }
1186} 1190}
1187 1191
1188CString CXferSocket::ApplyRoot(LPCTSTR fileName) 1192CString CXferSocket::ApplyRoot(LPCTSTR fileName)
1189{ 1193{
1190 ASSERT(m_Daddy); 1194 ASSERT(m_Daddy);
1191CString fn = fileName; 1195CString fn = fileName;
1192CString rv = m_Daddy->m_TFTPRoot; 1196CString rv = m_Daddy->m_TFTPRoot;
1193 if(rv.IsEmpty()) 1197 if(rv.IsEmpty())
1194 rv = "."; 1198 rv = ".";
1195 if(rv[rv.GetLength()-1]!='\\') 1199 if(rv[rv.GetLength()-1]!='\\')
1196 rv+="\\"; 1200 rv+="\\";
1197 while((!fn.IsEmpty()) && fn[0]=='\\') 1201 while((!fn.IsEmpty()) && fn[0]=='\\')
1198 fn=fn.Mid(1); 1202 fn=fn.Mid(1);
1199 rv+=fn; 1203 rv+=fn;
1200 return rv; 1204 return rv;
1201} 1205}
1202 1206
1203void CPumpKINDlg::OnOptions() 1207void CPumpKINDlg::OnOptions()
1204{ 1208{
1205CPropertySheet cps(IDS_TITLE_OPTIONS,this); 1209CPropertySheet cps(IDS_TITLE_OPTIONS,this);
1206CPropsServer server; 1210CPropsServer server;
1207CPropsNetwork network; 1211CPropsNetwork network;
1208CPropsSounds sounds; 1212CPropsSounds sounds;
1209CPropsACL acl; 1213CPropsACL acl;
1210 1214
1211 server.m_RRQMode=m_RRQMode; 1215 server.m_RRQMode=m_RRQMode;
1212 server.m_TFTPRoot=m_TFTPRoot; 1216 server.m_TFTPRoot=m_TFTPRoot;
1213 server.m_TFTPSubdirs=m_bTFTPSubdirs; 1217 server.m_TFTPSubdirs=m_bTFTPSubdirs;
1214 server.m_WRQMode=m_WRQMode; 1218 server.m_WRQMode=m_WRQMode;
1215 server.m_PromptTimeOut=m_PromptTimeOut; 1219 server.m_PromptTimeOut=m_PromptTimeOut;
1216 server.m_LogFile=m_LogFile; 1220 server.m_LogFile=m_LogFile;
1217 1221
1218 network.m_ListenPort=m_ListenPort; 1222 network.m_ListenPort=m_ListenPort;
1219 network.m_SpeakPort=m_SpeakPort; 1223 network.m_SpeakPort=m_SpeakPort;
1220 network.m_TimeOut=m_TFTPTimeOut.GetTotalSeconds(); 1224 network.m_TimeOut=m_TFTPTimeOut.GetTotalSeconds();
1221 network.m_BlockSize=m_BlockSize; 1225 network.m_BlockSize=m_BlockSize;
1222 1226
1223 sounds.m_Request = m_bnwRequest; 1227 sounds.m_Request = m_bnwRequest;
1224 sounds.m_Success = m_bnwSuccess; 1228 sounds.m_Success = m_bnwSuccess;
1225 sounds.m_Abort = m_bnwAbort; 1229 sounds.m_Abort = m_bnwAbort;
1226 1230
1227 acl.m_rulist = m_aclRules; 1231 acl.m_rulist = m_aclRules;
1228 1232
1229 cps.AddPage(&server); 1233 cps.AddPage(&server);
1230 cps.AddPage(&network); 1234 cps.AddPage(&network);
1231 cps.AddPage(&sounds); 1235 cps.AddPage(&sounds);
1232 cps.AddPage(&acl); 1236 cps.AddPage(&acl);
1233 if(cps.DoModal()==IDOK){ 1237 if(cps.DoModal()==IDOK){
1234 m_RRQMode=server.m_RRQMode; 1238 m_RRQMode=server.m_RRQMode;
1235 m_TFTPRoot=server.m_TFTPRoot; 1239 m_TFTPRoot=server.m_TFTPRoot;
1236 m_bTFTPSubdirs=server.m_TFTPSubdirs; 1240 m_bTFTPSubdirs=server.m_TFTPSubdirs;
1237 m_WRQMode=server.m_WRQMode; 1241 m_WRQMode=server.m_WRQMode;
1238 m_PromptTimeOut=server.m_PromptTimeOut; 1242 m_PromptTimeOut=server.m_PromptTimeOut;
1239 m_LogFile=server.m_LogFile; 1243 m_LogFile=server.m_LogFile;
1240 1244
1241 m_ListenPort=network.m_ListenPort; 1245 m_ListenPort=network.m_ListenPort;
1242 m_SpeakPort=network.m_SpeakPort; 1246 m_SpeakPort=network.m_SpeakPort;
1243 m_TFTPTimeOut=CTimeSpan(network.m_TimeOut); 1247 m_TFTPTimeOut=CTimeSpan(network.m_TimeOut);
1244 m_BlockSize=network.m_BlockSize; 1248 m_BlockSize=network.m_BlockSize;
1245 1249
1246 m_bnwRequest = sounds.m_Request; 1250 m_bnwRequest = sounds.m_Request;
1247 m_bnwSuccess = sounds.m_Success; 1251 m_bnwSuccess = sounds.m_Success;
1248 m_bnwAbort = sounds.m_Abort; 1252 m_bnwAbort = sounds.m_Abort;
1249 1253
1250 m_aclRules = acl.m_rulist; 1254 m_aclRules = acl.m_rulist;
1251 1255
1252 m_lastlogerr.Empty(); 1256 m_lastlogerr.Empty();
1253 } 1257 }
1254} 1258}
1255 1259
1256BOOL CRRQSocket::ConfirmRequest() 1260BOOL CRRQSocket::ConfirmRequest()
1257{ 1261{
1258CConfirmRRQDlg cd(NULL); 1262CConfirmRRQDlg cd(NULL);
1259 cd.m_Daddy=this; 1263 cd.m_Daddy=this;
1260 cd.m_File=m_FileName; 1264 cd.m_File=m_FileName;
1261 cd.m_Host=inet_ntoa(m_Peer.sin_addr); 1265 cd.m_Host=inet_ntoa(m_Peer.sin_addr);
1262 if(cd.DoModal()==IDOK) 1266 if(cd.DoModal()==IDOK)
1263 return TRUE; 1267 return TRUE;
1264 return FALSE; 1268 return FALSE;
1265} 1269}
1266 1270
1267CWRQSocket::CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) 1271CWRQSocket::CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin)
1268 : CXferSocket(daddy,fileName,type,sin) 1272 : CXferSocket(daddy,fileName,type,sin)
1269{ 1273{
1270 state=stateNone; 1274 state=stateNone;
1271 m_ACK=0; 1275 m_ACK=0;
1272 m_LastSlack=0; 1276 m_LastSlack=0;
1273 m_bResume=FALSE; 1277 m_bResume=FALSE;
1274} 1278}
1275 1279
1276BOOL CWRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName) 1280BOOL CWRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName)
1277{ 1281{
1278 if(!CAsyncSocket::Create(0,SOCK_DGRAM)) 1282 if(!CAsyncSocket::Create(0,SOCK_DGRAM))
1279 return FALSE; 1283 return FALSE;
1280 ASSERT(m_Daddy); 1284 ASSERT(m_Daddy);
1281 ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName); 1285 ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName);
1282 m_Daddy->m_Xfers[m_hSocket]=this; 1286 m_Daddy->m_Xfers[m_hSocket]=this;
1283 UpdateList(); 1287 UpdateList();
1284CString lf; 1288CString lf;
1285 if(!localFile) { 1289 if(!localFile) {
1286 lf = m_FileName; 1290 lf = m_FileName;
1287 TurnSlashes(lf,TRUE); 1291 TurnSlashes(lf,TRUE);
1288 } 1292 }
1289CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf); 1293CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf);
1290 if(!localFile){// This is an incoming request.. 1294 if(!localFile){// This is an incoming request..
1291 if(CheckBadRelativeness(m_FileName)){ 1295 if(CheckBadRelativeness(m_FileName)){
1292 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); 1296 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
1293 return TRUE; 1297 return TRUE;
1294 } 1298 }
1295 BOOL exists; 1299 BOOL exists;
1296 if(!_access((LPCTSTR)fn,0)) 1300 if(!_access((LPCTSTR)fn,0))
1297 m_Rename=exists=TRUE; 1301 m_Rename=exists=TRUE;
1298 else 1302 else
1299 m_Rename=exists=FALSE; 1303 m_Rename=exists=FALSE;
1300 int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opWRQ,m_Peer.sin_addr.s_addr); 1304 int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opWRQ,m_Peer.sin_addr.s_addr);
1301 if(atar<0) 1305 if(atar<0)
1302 atar=m_Daddy->m_WRQMode; 1306 atar=m_Daddy->m_WRQMode;
1303 switch(atar){ 1307 switch(atar){
1304 case CPumpKINDlg::wrqTakeAll: 1308 case CPumpKINDlg::wrqTakeAll:
1305 if(exists){ 1309 if(exists){
1306 if(!RenameFile(fn)){ 1310 if(!RenameFile(fn)){
1307 Deny(tftp::errDiskFull,IDS_TFTP_ERROR_FAILEDTORENAME); 1311 Deny(tftp::errDiskFull,IDS_TFTP_ERROR_FAILEDTORENAME);
1308 return TRUE; 1312 return TRUE;
1309 } 1313 }
1310 } 1314 }
1311 break; 1315 break;
1312 case CPumpKINDlg::wrqConfirmIfExists: 1316 case CPumpKINDlg::wrqConfirmIfExists:
1313 if(!exists) 1317 if(!exists)
1314 break; 1318 break;
1315 case CPumpKINDlg::wrqAlwaysConfirm: 1319 case CPumpKINDlg::wrqAlwaysConfirm:
1316 if(exists) 1320 if(exists)
1317 m_bResume=TRUE; 1321 m_bResume=TRUE;
1318 if(ConfirmRequest()){ 1322 if(ConfirmRequest()){
1319 if(m_Rename){ 1323 if(m_Rename){
1320 RenameFile(fn); 1324 RenameFile(fn);
1321 if(SaveAs(fn)) 1325 if(SaveAs(fn))
1322 break; 1326 break;
1323 }else 1327 }else
1324 break; 1328 break;
1325 } 1329 }
1326 default: 1330 default:
1327 TRACE1("Unexpected access target: %d\n",atar); 1331 TRACE1("Unexpected access target: %d\n",atar);
1328 case CPumpKINDlg::wrqDenyAll: 1332 case CPumpKINDlg::wrqDenyAll:
1329 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); 1333 Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS);
1330 return TRUE; 1334 return TRUE;
1331 } 1335 }
1332 } 1336 }
1333CFileException e; 1337CFileException e;
1334 if(!m_File.Open( 1338 if(!m_File.Open(
1335 fn, 1339 fn,
1336 m_bResume 1340 m_bResume
1337 ?(CFile::modeWrite|CFile::shareDenyWrite) 1341 ?(CFile::modeWrite|CFile::shareDenyWrite)
1338 :(CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite), 1342 :(CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite),
1339 &e 1343 &e
1340 )){ 1344 )){
1341 if(localFile){// Outgoing request 1345 if(localFile){// Outgoing request
1342 CString tmp; 1346 CString tmp;
1343 tmp.Format(IDS_LOG_FAILEDTOOPEN,fn); 1347 tmp.Format(IDS_LOG_FAILEDTOOPEN,fn);
1344 m_Daddy->LogLine(tmp); 1348 m_Daddy->LogLine(tmp);
1345 return FALSE; 1349 return FALSE;
1346 }else{ 1350 }else{
1347 Deny(&e); 1351 Deny(&e);
1348 return TRUE; 1352 return TRUE;
1349 } 1353 }
1350 } 1354 }
1351 if(hostName){ 1355 if(hostName){
1352 m_HostName=hostName; 1356 m_HostName=hostName;
1353 1357
1354 CString tmp; 1358 CString tmp;
1355 tmp.Format(IDS_LOG_REQUESTING,m_FileName,m_HostName); 1359 tmp.Format(IDS_LOG_REQUESTING,m_FileName,m_HostName);
1356 m_Daddy->LogLine(tmp); 1360 m_Daddy->LogLine(tmp);
1357 1361
1358 CString inAddr = hostName; 1362 CString inAddr = hostName;
1359 int at = inAddr.Find('@'); 1363 int at = inAddr.Find('@');
1360 if(at>=0) 1364 if(at>=0)
1361 inAddr=inAddr.Mid(at+1); 1365 inAddr=inAddr.Mid(at+1);
1362 if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){ 1366 if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){
1363 ASSERT(!m_wndResolver); 1367 ASSERT(!m_wndResolver);
1364 m_wndResolver = new CResolver(this); 1368 m_wndResolver = new CResolver(this);
1365 ASSERT(m_wndResolver); 1369 ASSERT(m_wndResolver);
1366 return m_wndResolver->Resolve(); 1370 return m_wndResolver->Resolve();
1367 }else{ 1371 }else{
1368 OnHostKnown(); 1372 OnHostKnown();
1369 return TRUE; 1373 return TRUE;
1370 } 1374 }
1371 } 1375 }
1372CString v; 1376CString v;
1373tftp::tftpOptions oack; 1377tftp::tftpOptions oack;
1374 if(m_Options.Lookup(tftpoTSize,v)){ 1378 if(m_Options.Lookup(tftpoTSize,v)){
1375 m_xferSize=atol(v); 1379 m_xferSize=atol(v);
1376 if(!m_xferSize){ 1380 if(!m_xferSize){
1377 Deny(tftp::errOption,IDS_TFTP_ERROR_TSIZE); 1381 Deny(tftp::errOption,IDS_TFTP_ERROR_TSIZE);
1378 return TRUE; 1382 return TRUE;
1379 } 1383 }
1380 } 1384 }
1381 if(m_Options.Lookup(tftpoBSize,v)){ 1385 if(m_Options.Lookup(tftpoBSize,v)){
1382 m_blkSize=atoi(v); 1386 m_blkSize=atoi(v);
1383 if(!m_blkSize){// *** Do more about sanity check 1387 if(!m_blkSize){// *** Do more about sanity check
1384 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); 1388 Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
1385 return TRUE; 1389 return TRUE;
1386 } 1390 }
1387 v.Format("%u",m_blkSize); 1391 v.Format("%u",m_blkSize);
1388 oack[tftpoBSize]=v; 1392 oack[tftpoBSize]=v;
1389 } 1393 }
1390 if(m_Options.Lookup(tftpoTOut,v)){ 1394 if(m_Options.Lookup(tftpoTOut,v)){
1391 m_timeOut=atoi(v); 1395 m_timeOut=atoi(v);
1392 if(!m_timeOut){// *** Do more about sanity check 1396 if(!m_timeOut){// *** Do more about sanity check
1393 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); 1397 Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
1394 return TRUE; 1398 return TRUE;
1395 } 1399 }
1396 v.Format("%u",m_timeOut); 1400 v.Format("%u",m_timeOut);
1397 oack[tftpoTOut]=v; 1401 oack[tftpoTOut]=v;
1398 } 1402 }
1399 if(m_Options.Lookup(tftpoXResume,v) && m_bResume){ 1403 if(m_Options.Lookup(tftpoXResume,v) && m_bResume){
1400 m_ACK=m_File.GetLength()/m_blkSize; 1404 m_ACK=m_File.GetLength()/m_blkSize;
1401 v.Format("%u",m_ACK); 1405 v.Format("%u",m_ACK);
1402 oack[tftpoXResume]=v; 1406 oack[tftpoXResume]=v;
1403 }else 1407 }else
1404 m_ACK=0; 1408 m_ACK=0;
1405 state=stateXfer; 1409 state=stateXfer;
1406 if(oack.GetCount()){ 1410 if(oack.GetCount()){
1407 tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&oack)); 1411 tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&oack));
1408 ASSERT(p); 1412 ASSERT(p);
1409 p->SetOpcode(tftp::opOACK); 1413 p->SetOpcode(tftp::opOACK);
1410 p->data.m_OACK.Set(&oack); 1414 p->data.m_OACK.Set(&oack);
1411 PostTFTP(p,TRUE); 1415 PostTFTP(p,TRUE);
1412 }else 1416 }else
1413 DoXfer(); 1417 DoXfer();
1414 return TRUE; 1418 return TRUE;
1415} 1419}
1416 1420
1417BOOL CWRQSocket::ConfirmRequest() 1421BOOL CWRQSocket::ConfirmRequest()
1418{ 1422{
1419CConfirmWRQDlg cd(NULL); 1423CConfirmWRQDlg cd(NULL);
1420 cd.m_Daddy=this; 1424 cd.m_Daddy=this;
1421 cd.m_File=m_FileName; 1425 cd.m_File=m_FileName;
1422 cd.m_Host=inet_ntoa(m_Peer.sin_addr); 1426 cd.m_Host=inet_ntoa(m_Peer.sin_addr);
1423 switch(cd.DoModal()){ 1427 switch(cd.DoModal()){
1424 case IDOK: 1428 case IDOK:
1425 m_Rename=FALSE; 1429 m_Rename=FALSE;
1426 m_bResume=FALSE; 1430 m_bResume=FALSE;
1427 return TRUE; 1431 return TRUE;
1428 case IDC_RENAME: 1432 case IDC_RENAME:
1429 m_bResume=FALSE; 1433 m_bResume=FALSE;
1430 m_Rename=TRUE; 1434 m_Rename=TRUE;
1431 return TRUE; 1435 return TRUE;
1432 case IDC_RESUME: 1436 case IDC_RESUME:
1433 m_Rename=FALSE; 1437 m_Rename=FALSE;
1434 m_bResume=TRUE; 1438 m_bResume=TRUE;
1435 return TRUE; 1439 return TRUE;
1436 case IDCANCEL: 1440 case IDCANCEL:
1437 return FALSE; 1441 return FALSE;
1438 } 1442 }
1439 return FALSE; 1443 return FALSE;
1440} 1444}
1441 1445
1442BOOL CWRQSocket::RenameFile(CString& fn) 1446BOOL CWRQSocket::RenameFile(CString& fn)
1443{ 1447{
1444CString renamed = fn; 1448CString renamed = fn;
1445 if(fn.IsEmpty()) 1449 if(fn.IsEmpty())
1446 return FALSE; 1450 return FALSE;
1447 if(fn[fn.GetLength()-1]==')'){ 1451 if(fn[fn.GetLength()-1]==')'){
1448 int op = fn.ReverseFind('('); 1452 int op = fn.ReverseFind('(');
1449 if(op>0 && fn[op-1]==' '){ 1453 if(op>0 && fn[op-1]==' '){
1450 if(fn.Mid(op+1,fn.GetLength()-op-2).SpanExcluding("0123456789").IsEmpty()) 1454 if(fn.Mid(op+1,fn.GetLength()-op-2).SpanExcluding("0123456789").IsEmpty())
1451 renamed = renamed.Left(op-1); 1455 renamed = renamed.Left(op-1);
1452 } 1456 }
1453 } 1457 }
1454CString testFN; 1458CString testFN;
1455 for(UINT tmp=0;tmp<32768;tmp++){ 1459 for(UINT tmp=0;tmp<32768;tmp++){
1456 testFN.Format("%s (%u)",(LPCTSTR)renamed,tmp); 1460 testFN.Format("%s (%u)",(LPCTSTR)renamed,tmp);
1457 if(!_access((LPCTSTR)testFN,0)) 1461 if(!_access((LPCTSTR)testFN,0))
1458 continue; 1462 continue;
1459 fn=testFN; 1463 fn=testFN;
1460 return TRUE; 1464 return TRUE;
1461 } 1465 }
1462 return FALSE; 1466 return FALSE;
1463} 1467}
1464 1468
1465BOOL CWRQSocket::SaveAs(CString& fn) 1469BOOL CWRQSocket::SaveAs(CString& fn)
1466{ 1470{
1467CFileDialog cfd(FALSE,NULL,fn,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST,NULL,m_Daddy); 1471CFileDialog cfd(FALSE,NULL,fn,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST,NULL,m_Daddy);
1468CString title; 1472CString title;
1469 title.LoadString(IDS_RENAME_TITLE); 1473 title.LoadString(IDS_RENAME_TITLE);
1470 cfd.m_ofn.lpstrTitle=(LPCTSTR)title; 1474 cfd.m_ofn.lpstrTitle=(LPCTSTR)title;
1471 if(cfd.DoModal()!=IDOK) 1475 if(cfd.DoModal()!=IDOK)
1472 return FALSE; 1476 return FALSE;
1473 fn = cfd.GetPathName(); 1477 fn = cfd.GetPathName();
1474 return TRUE; 1478 return TRUE;
1475} 1479}
1476 1480
1477void CWRQSocket::DoXfer() 1481void CWRQSocket::DoXfer()
1478{ 1482{
1479tftp *p = tftp::Allocate(tftp::tftpACK::tftpSize()); 1483tftp *p = tftp::Allocate(tftp::tftpACK::tftpSize());
1480 ASSERT(p); 1484 ASSERT(p);
1481 p->SetOpcode(tftp::opACK); 1485 p->SetOpcode(tftp::opACK);
1482 p->data.m_ACK.SetBlock(m_ACK); 1486 p->data.m_ACK.SetBlock(m_ACK);
1483 TRACE1("WRQ-ACK-%u\n",m_ACK); 1487 TRACE1("WRQ-ACK-%u\n",m_ACK);
1484 PostTFTP(p,TRUE);// *** ??? Hope this is right 1488 PostTFTP(p,TRUE);// *** ??? Hope this is right
1485} 1489}
1486 1490
1487UINT tftp::tftpACK::tftpSize() 1491UINT tftp::tftpACK::tftpSize()
1488{ 1492{
1489 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpACK); 1493 return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpACK);
1490} 1494}
1491 1495
1492ULONG CWRQSocket::GetACK() 1496ULONG CWRQSocket::GetACK()
1493{ 1497{
1494 return (m_ACK*m_blkSize)-m_LastSlack; 1498 return (m_ACK*m_blkSize)-m_LastSlack;
1495} 1499}
1496 1500
1497void CXferSocket::ResetTimeout() 1501void CXferSocket::ResetTimeout()
1498{ 1502{
1499 ASSERT(m_Daddy); 1503 ASSERT(m_Daddy);
1500 m_Daddy->m_Retrier->KillTimer(m_hSocket); 1504 m_Daddy->m_Retrier->KillTimer(m_hSocket);
1501 if(m_Retry) 1505 if(m_Retry)
1502 m_Daddy->m_Retrier->SetTimer(m_hSocket,min(60,m_Daddy->m_RetryTimeOut.GetTotalSeconds())*1000,NULL); 1506 m_Daddy->m_Retrier->SetTimer(m_hSocket,min(60,m_Daddy->m_RetryTimeOut.GetTotalSeconds())*1000,NULL);
1503 if(!m_bRetry){ 1507 if(!m_bRetry){
1504 m_Daddy->KillTimer(m_hSocket); 1508 m_Daddy->KillTimer(m_hSocket);
1505 m_Daddy->SetTimer(m_hSocket,min(60,m_timeOut)*1000,NULL); 1509 m_Daddy->SetTimer(m_hSocket,min(60,m_timeOut)*1000,NULL);
1506 } 1510 }
1507} 1511}
1508 1512
1509void CXferSocket::Abort() 1513void CXferSocket::Abort()
1510{ 1514{
1511 ASSERT(m_Daddy); 1515 ASSERT(m_Daddy);
1512CString tmp; 1516CString tmp;
1513 tmp.Format(IDS_LOG_XFERABORTED,(LPCTSTR)m_FileName); 1517 tmp.Format(IDS_LOG_XFERABORTED,(LPCTSTR)m_FileName);
1514 m_Daddy->LogLine(tmp); 1518 m_Daddy->LogLine(tmp);
1515 Destroy(FALSE); 1519 Destroy(FALSE);
1516} 1520}
1517 1521
1518void CPumpKINDlg::OnTimer(UINT nIDEvent) 1522void CPumpKINDlg::OnTimer(UINT nIDEvent)
1519{ 1523{
1520CXferSocket *socket; 1524CXferSocket *socket;
1521 if(m_Xfers.Lookup(nIDEvent,socket)){ 1525 if(m_Xfers.Lookup(nIDEvent,socket)){
1522 CString tmp; 1526 CString tmp;
1523 tmp.Format(IDS_LOG_TIMEDOUT,socket->m_FileName); 1527 tmp.Format(IDS_LOG_TIMEDOUT,socket->m_FileName);
1524 LogLine(tmp); 1528 LogLine(tmp);
1525 socket->Abort(); 1529 socket->Abort();
1526 }else{ 1530 }else{
1527 TRACE0("Failed to find timed out socket!\n"); 1531 TRACE0("Failed to find timed out socket!\n");
1528 } 1532 }
1529 CDialog::OnTimer(nIDEvent); 1533 CDialog::OnTimer(nIDEvent);
1530} 1534}
1531 1535
1532void CPumpKINDlg::OnExit() 1536void CPumpKINDlg::OnExit()
1533{ 1537{
1534 if(!m_Xfers.IsEmpty()){ 1538 if(!m_Xfers.IsEmpty()){
1535 CString title,text; 1539 CString title,text;
1536 title.LoadString(IDS_CONFIRMEXIT_TITLE); 1540 title.LoadString(IDS_CONFIRMEXIT_TITLE);
1537 text.LoadString(IDS_CONFIRMEXIT_TEXT); 1541 text.LoadString(IDS_CONFIRMEXIT_TEXT);
1538 if(MessageBox(text,title,MB_ICONQUESTION|MB_YESNO)!=IDYES) 1542 if(MessageBox(text,title,MB_ICONQUESTION|MB_YESNO)!=IDYES)
1539 return; 1543 return;
1540 } 1544 }
1541 m_bExiting=TRUE; 1545 m_bExiting=TRUE;
1542 EndDialog(IDOK); 1546 EndDialog(IDOK);
1543} 1547}
1544 1548
1545void CPumpKINDlg::OnPut() 1549void CPumpKINDlg::OnPut()
1546{ 1550{
1547CRequestDlg crd(NULL); 1551CRequestDlg crd(NULL);
1548 crd.m_Put=TRUE; 1552 crd.m_Put=TRUE;
1549 crd.m_BSize=m_BlockSize; 1553 crd.m_BSize=m_BlockSize;
1550 if(crd.DoModal()==IDOK){ 1554 if(crd.DoModal()==IDOK){
1551 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL); 1555 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
1552 if(crd.m_BSize) 1556 if(crd.m_BSize)
1553 socket->m__blkSize=crd.m_BSize; 1557 socket->m__blkSize=crd.m_BSize;
1554 if(!socket->Create(crd.m_LocalFile,crd.m_Host)) 1558 if(!socket->Create(crd.m_LocalFile,crd.m_Host))
1555 socket->Destroy(); 1559 socket->Destroy();
1556 } 1560 }
1557} 1561}
1558 1562
1559void CPumpKINDlg::OnGet() 1563void CPumpKINDlg::OnGet()
1560{ 1564{
1561CRequestDlg crd(NULL); 1565CRequestDlg crd(NULL);
1562 crd.m_Put=FALSE; 1566 crd.m_Put=FALSE;
1563 crd.m_BSize=m_BlockSize; 1567 crd.m_BSize=m_BlockSize;
1564 if(crd.DoModal()==IDOK){ 1568 if(crd.DoModal()==IDOK){
1565 CWRQSocket *socket = new CWRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL); 1569 CWRQSocket *socket = new CWRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
1566 if(crd.m_BSize) 1570 if(crd.m_BSize)
1567 socket->m__blkSize=crd.m_BSize; 1571 socket->m__blkSize=crd.m_BSize;
1568 if(!socket->Create(crd.m_LocalFile,crd.m_Host)) 1572 if(!socket->Create(crd.m_LocalFile,crd.m_Host))
1569 socket->Destroy(); 1573 socket->Destroy();
1570 } 1574 }
1571} 1575}
1572 1576
1573void CPumpKINDlg::SetupButtons() 1577void CPumpKINDlg::SetupButtons()
1574{ 1578{
1575 m_AbortCtl.EnableWindow(m_List.GetSelectedCount()>0); 1579 m_AbortCtl.EnableWindow(m_List.GetSelectedCount()>0);
1576} 1580}
1577 1581
1578void CPumpKINDlg::OnDeleteallitemsConnections(NMHDR* pNMHDR, LRESULT* pResult) 1582void CPumpKINDlg::OnDeleteallitemsConnections(NMHDR* pNMHDR, LRESULT* pResult)
1579{ 1583{
1580 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 1584 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
1581 SetupButtons(); 1585 SetupButtons();
1582 *pResult = 0; 1586 *pResult = 0;
1583} 1587}
1584 1588
1585void CPumpKINDlg::OnDeleteitemConnections(NMHDR* pNMHDR, LRESULT* pResult) 1589void CPumpKINDlg::OnDeleteitemConnections(NMHDR* pNMHDR, LRESULT* pResult)
1586{ 1590{
1587 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 1591 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
1588 SetupButtons(); 1592 SetupButtons();
1589 *pResult = 0; 1593 *pResult = 0;
1590} 1594}
1591 1595
1592void CPumpKINDlg::OnInsertitemConnections(NMHDR* pNMHDR, LRESULT* pResult) 1596void CPumpKINDlg::OnInsertitemConnections(NMHDR* pNMHDR, LRESULT* pResult)
1593{ 1597{
1594 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 1598 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
1595 SetupButtons(); 1599 SetupButtons();
1596 *pResult = 0; 1600 *pResult = 0;
1597} 1601}
1598 1602
1599void CPumpKINDlg::OnItemchangedConnections(NMHDR* pNMHDR, LRESULT* pResult) 1603void CPumpKINDlg::OnItemchangedConnections(NMHDR* pNMHDR, LRESULT* pResult)
1600{ 1604{
1601 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 1605 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
1602 SetupButtons(); 1606 SetupButtons();
1603 *pResult = 0; 1607 *pResult = 0;
1604} 1608}
1605 1609
1606void CPumpKINDlg::OnAbort() 1610void CPumpKINDlg::OnAbort()
1607{ 1611{
1608 if(!m_List.GetSelectedCount()) 1612 if(!m_List.GetSelectedCount())
1609 return; 1613 return;
1610 intitems = m_List.GetItemCount(); 1614 intitems = m_List.GetItemCount();
1611 for(int tmp=0;tmp<items;tmp++){ 1615 for(int tmp=0;tmp<items;tmp++){
1612 if(!(m_List.GetItemState(tmp,LVIS_SELECTED)&LVIS_SELECTED)) 1616 if(!(m_List.GetItemState(tmp,LVIS_SELECTED)&LVIS_SELECTED))
1613 continue; 1617 continue;
1614 CXferSocket *xfer = (CXferSocket*) m_List.GetItemData(tmp); 1618 CXferSocket *xfer = (CXferSocket*) m_List.GetItemData(tmp);
1615 ASSERT(xfer); 1619 ASSERT(xfer);
1616 xfer->Abort(); 1620 xfer->Abort();
1617 } 1621 }
1618} 1622}
1619 1623
1620void CXferSocket::OnFailedToResolve() 1624void CXferSocket::OnFailedToResolve()
1621{ 1625{
1622 TRACE0("Resolve failed\n"); 1626 TRACE0("Resolve failed\n");
1623 delete m_wndResolver; 1627 delete m_wndResolver;
1624 m_wndResolver=NULL; 1628 m_wndResolver=NULL;
1625 ASSERT(m_Daddy); 1629 ASSERT(m_Daddy);
1626CString tmp; 1630CString tmp;
1627 tmp.Format(IDS_LOG_RESOLVEFAILED,m_HostName); 1631 tmp.Format(IDS_LOG_RESOLVEFAILED,m_HostName);
1628 m_Daddy->LogLine(tmp); 1632 m_Daddy->LogLine(tmp);
1629 Abort(); 1633 Abort();
1630} 1634}
1631 1635
1632void CXferSocket::OnResolved() 1636void CXferSocket::OnResolved()
1633{ 1637{
1634 delete m_wndResolver; 1638 delete m_wndResolver;
1635 m_wndResolver=NULL; 1639 m_wndResolver=NULL;
1636 TRACE0("Resolved\n"); 1640 TRACE0("Resolved\n");
1637 m_Peer.sin_addr.s_addr = *(DWORD*)(((hostent*)m_ResolveBuff)->h_addr); 1641 m_Peer.sin_addr.s_addr = *(DWORD*)(((hostent*)m_ResolveBuff)->h_addr);
1638} 1642}
1639 1643
1640void CRRQSocket::OnResolved() 1644void CRRQSocket::OnResolved()
1641{ 1645{
1642 CXferSocket::OnResolved(); 1646 CXferSocket::OnResolved();
1643 OnHostKnown(); 1647 OnHostKnown();
1644} 1648}
1645 1649
1646void CRRQSocket::OnHostKnown() 1650void CRRQSocket::OnHostKnown()
1647{ 1651{
1648 ASSERT(m_Daddy); 1652 ASSERT(m_Daddy);
1649 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort); 1653 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort);
1650tftp::tftpOptions o; 1654tftp::tftpOptions o;
1651CString v; 1655CString v;
1652 ASSERT(m_xferSize>=0); 1656 ASSERT(m_xferSize>=0);
1653 v.Format("%lu",m_xferSize); 1657 v.Format("%lu",m_xferSize);
1654 o[tftpoTSize] = v; 1658 o[tftpoTSize] = v;
1655 ASSERT(m__blkSize); 1659 ASSERT(m__blkSize);
1656 v.Format("%u",m__blkSize); 1660 v.Format("%u",m__blkSize);
1657 o[tftpoBSize] = v; 1661 o[tftpoBSize] = v;
1658 ASSERT(m__timeOut); 1662 ASSERT(m__timeOut);
1659 v.Format("%u",m__timeOut); 1663 v.Format("%u",m__timeOut);
1660 o[tftpoTOut] = v; 1664 o[tftpoTOut] = v;
1661 o[tftpoXResume] = "0"; 1665 o[tftpoXResume] = "0";
1662 tftp*p = tftp::Allocate(tftp::tftpWRQ::tftpSize(m_FileName,m_Type,&o)); 1666 tftp*p = tftp::Allocate(tftp::tftpWRQ::tftpSize(m_FileName,m_Type,&o));
1663 ASSERT(p); 1667 ASSERT(p);
1664 p->SetOpcode(tftp::opWRQ); 1668 p->SetOpcode(tftp::opWRQ);
1665 p->data.m_WRQ.Set(m_FileName,m_Type,&o); 1669 p->data.m_WRQ.Set(m_FileName,m_Type,&o);
1666 PostTFTP(p,TRUE); 1670 PostTFTP(p,TRUE);
1667 state=stateInit; 1671 state=stateInit;
1668 UpdateList(); 1672 UpdateList();
1669} 1673}
1670 1674
1671UINT tftp::tftpRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1675UINT tftp::tftpRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1672{ 1676{
1673UINT rv = tftpHdrSize-tftpSlackSize+strlen(file)+1+strlen(type)+1; 1677UINT rv = tftpHdrSize-tftpSlackSize+strlen(file)+1+strlen(type)+1;
1674 if(ops){ 1678 if(ops){
1675 tftpOptions& o = *ops; 1679 tftpOptions& o = *ops;
1676 POSITION p = o.GetStartPosition(); 1680 POSITION p = o.GetStartPosition();
1677 while(p){ 1681 while(p){
1678 CString n,v; 1682 CString n,v;
1679 o.GetNextAssoc(p,n,v); 1683 o.GetNextAssoc(p,n,v);
1680 rv+=n.GetLength()+1+v.GetLength()+1; 1684 rv+=n.GetLength()+1+v.GetLength()+1;
1681 } 1685 }
1682 } 1686 }
1683 return rv; 1687 return rv;
1684} 1688}
1685UINT tftp::tftpRRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1689UINT tftp::tftpRRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1686{ 1690{
1687 return tftp::tftpRQ::tftpSize(file,type,ops); 1691 return tftp::tftpRQ::tftpSize(file,type,ops);
1688} 1692}
1689UINT tftp::tftpWRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1693UINT tftp::tftpWRQ::tftpSize(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1690{ 1694{
1691 return tftp::tftpRQ::tftpSize(file,type,ops); 1695 return tftp::tftpRQ::tftpSize(file,type,ops);
1692} 1696}
1693UINT tftp::tftpOACK::tftpSize(tftp::tftpOptions* ops) 1697UINT tftp::tftpOACK::tftpSize(tftp::tftpOptions* ops)
1694{ 1698{
1695UINT rv = tftpHdrSize-tftpSlackSize; 1699UINT rv = tftpHdrSize-tftpSlackSize;
1696 if(ops){ 1700 if(ops){
1697 tftpOptions& o = *ops; 1701 tftpOptions& o = *ops;
1698 POSITION p = o.GetStartPosition(); 1702 POSITION p = o.GetStartPosition();
1699 while(p){ 1703 while(p){
1700 CString n,v; 1704 CString n,v;
1701 o.GetNextAssoc(p,n,v); 1705 o.GetNextAssoc(p,n,v);
1702 rv+=n.GetLength()+1+v.GetLength()+1; 1706 rv+=n.GetLength()+1+v.GetLength()+1;
1703 } 1707 }
1704 } 1708 }
1705 return rv; 1709 return rv;
1706} 1710}
1707void tftp::tftpRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1711void tftp::tftpRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1708{ 1712{
1709 // MAY BE DANGEROUS! 1713 // MAY BE DANGEROUS!
1710UINT ptr = 0; 1714UINT ptr = 0;
1711 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1; 1715 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
1712 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1; 1716 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
1713 if(ops){ 1717 if(ops){
1714 tftpOptions& o = *ops; 1718 tftpOptions& o = *ops;
1715 POSITION p = o.GetStartPosition(); 1719 POSITION p = o.GetStartPosition();
1716 while(p){ 1720 while(p){
1717 CString n,v; 1721 CString n,v;
1718 o.GetNextAssoc(p,n,v); 1722 o.GetNextAssoc(p,n,v);
1719 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1723 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1720 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1724 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1721 } 1725 }
1722 } 1726 }
1723} 1727}
1724void tftp::tftpRRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1728void tftp::tftpRRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1725{ 1729{
1726 // MAY BE DANGEROUS! 1730 // MAY BE DANGEROUS!
1727UINT ptr = 0; 1731UINT ptr = 0;
1728 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1; 1732 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
1729 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1; 1733 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
1730 if(ops){ 1734 if(ops){
1731 tftpOptions& o = *ops; 1735 tftpOptions& o = *ops;
1732 POSITION p = o.GetStartPosition(); 1736 POSITION p = o.GetStartPosition();
1733 while(p){ 1737 while(p){
1734 CString n,v; 1738 CString n,v;
1735 o.GetNextAssoc(p,n,v); 1739 o.GetNextAssoc(p,n,v);
1736 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1740 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1737 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1741 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1738 } 1742 }
1739 } 1743 }
1740} 1744}
1741void tftp::tftpWRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops) 1745void tftp::tftpWRQ::Set(LPCTSTR file,LPCTSTR type,tftp::tftpOptions* ops)
1742{ 1746{
1743 // MAY BE DANGEROUS! 1747 // MAY BE DANGEROUS!
1744UINT ptr = 0; 1748UINT ptr = 0;
1745 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1; 1749 strcpy((LPTSTR)&data[ptr],file); ptr+=strlen(file)+1;
1746 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1; 1750 strcpy((LPTSTR)&data[ptr],type); ptr+=strlen(type)+1;
1747 if(ops){ 1751 if(ops){
1748 tftpOptions& o = *ops; 1752 tftpOptions& o = *ops;
1749 POSITION p = o.GetStartPosition(); 1753 POSITION p = o.GetStartPosition();
1750 while(p){ 1754 while(p){
1751 CString n,v; 1755 CString n,v;
1752 o.GetNextAssoc(p,n,v); 1756 o.GetNextAssoc(p,n,v);
1753 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1757 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1754 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1758 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1755 } 1759 }
1756 } 1760 }
1757} 1761}
1758void tftp::tftpOACK::Set(tftpOptions* ops) 1762void tftp::tftpOACK::Set(tftpOptions* ops)
1759{ 1763{
1760 ASSERT(ops); 1764 ASSERT(ops);
1761UINT ptr = 0; 1765UINT ptr = 0;
1762tftpOptions& o = *ops; 1766tftpOptions& o = *ops;
1763POSITION p = o.GetStartPosition(); 1767POSITION p = o.GetStartPosition();
1764 while(p){ 1768 while(p){
1765 CString n,v; 1769 CString n,v;
1766 o.GetNextAssoc(p,n,v); 1770 o.GetNextAssoc(p,n,v);
1767 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1; 1771 strcpy((LPTSTR)&data[ptr],(LPCTSTR)n); ptr+=n.GetLength()+1;
1768 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1; 1772 strcpy((LPTSTR)&data[ptr],(LPCTSTR)v); ptr+=v.GetLength()+1;
1769 } 1773 }
1770} 1774}
1771 1775
1772void CWRQSocket::OnResolved() 1776void CWRQSocket::OnResolved()
1773{ 1777{
1774 CXferSocket::OnResolved(); 1778 CXferSocket::OnResolved();
1775 OnHostKnown(); 1779 OnHostKnown();
1776} 1780}
1777 1781
1778void CWRQSocket::OnHostKnown() 1782void CWRQSocket::OnHostKnown()
1779{ 1783{
1780 ASSERT(m_Daddy); 1784 ASSERT(m_Daddy);
1781 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort); 1785 m_Peer.sin_port=htons(m_Daddy->m_SpeakPort);
1782tftp::tftpOptions o; 1786tftp::tftpOptions o;
1783CString v; 1787CString v;
1784 o[tftpoTSize]="0"; 1788 o[tftpoTSize]="0";
1785 if(m__blkSize){ 1789 if(m__blkSize){
1786 v.Format("%u",m__blkSize); 1790 v.Format("%u",m__blkSize);
1787 o[tftpoBSize]=v; 1791 o[tftpoBSize]=v;
1788 } 1792 }
1789 if(m__timeOut){ 1793 if(m__timeOut){
1790 v.Format("%u",m__timeOut); 1794 v.Format("%u",m__timeOut);
1791 o[tftpoTOut]=v; 1795 o[tftpoTOut]=v;
1792 } 1796 }
1793 tftp*p = tftp::Allocate(tftp::tftpRRQ::tftpSize(m_FileName,m_Type,&o)); 1797 tftp*p = tftp::Allocate(tftp::tftpRRQ::tftpSize(m_FileName,m_Type,&o));
1794 ASSERT(p); 1798 ASSERT(p);
1795 p->SetOpcode(tftp::opRRQ); 1799 p->SetOpcode(tftp::opRRQ);
1796 p->data.m_RRQ.Set(m_FileName,m_Type,&o); 1800 p->data.m_RRQ.Set(m_FileName,m_Type,&o);
1797 PostTFTP(p,TRUE); 1801 PostTFTP(p,TRUE);
1798 state=stateInit; 1802 state=stateInit;
1799 UpdateList(); 1803 UpdateList();
1800} 1804}
1801 1805
1802void CPumpKINDlg::OnClose() 1806void CPumpKINDlg::OnClose()
1803{ 1807{
1804 OnTrayShowpumpkinwindow(); 1808 OnTrayShowpumpkinwindow();
1805} 1809}
1806 1810
1807void CPumpKINDlg::OnTrayShowpumpkinwindow() 1811void CPumpKINDlg::OnTrayShowpumpkinwindow()
1808{ 1812{
1809 if(IsWindowVisible()){ 1813 if(IsWindowVisible()){
1810 m_bShown=FALSE; 1814 m_bShown=FALSE;
1811 ShowWindow(SW_HIDE); 1815 ShowWindow(SW_HIDE);
1812 }else{ 1816 }else{
1813 m_bShown=TRUE; 1817 m_bShown=TRUE;
1814 ShowWindow(SW_SHOW); 1818 ShowWindow(SW_SHOW);
1815 SetForegroundWindow(); 1819 SetForegroundWindow();
1816 SetFocus(); 1820 SetFocus();
1817 } 1821 }
1818} 1822}
1819 1823
1820void CPumpKINDlg::OnTrayExit() 1824void CPumpKINDlg::OnTrayExit()
1821{ 1825{
1822 OnExit(); 1826 OnExit();
1823} 1827}
1824 1828
1825void CPumpKINDlg::OnTrayAboutpumpkin() 1829void CPumpKINDlg::OnTrayAboutpumpkin()
1826{ 1830{
1827CAboutDlg dlgAbout; 1831CAboutDlg dlgAbout;
1828 dlgAbout.DoModal(); 1832 dlgAbout.DoModal();
1829} 1833}
1830 1834
1831void CPumpKINDlg::OnTrayFetchfile() 1835void CPumpKINDlg::OnTrayFetchfile()
1832{ 1836{
1833 OnGet(); 1837 OnGet();
1834} 1838}
1835 1839
1836void CPumpKINDlg::OnTrayHelp() 1840void CPumpKINDlg::OnTrayHelp()
1837{ 1841{
1838 OnHelp(); 1842 OnHelp();
1839} 1843}
1840 1844
1841void CPumpKINDlg::OnTrayOptions() 1845void CPumpKINDlg::OnTrayOptions()
1842{ 1846{
1843 OnOptions(); 1847 OnOptions();
1844} 1848}
1845 1849
1846void CPumpKINDlg::OnTraySendfile() 1850void CPumpKINDlg::OnTraySendfile()
1847{ 1851{
1848 OnPut(); 1852 OnPut();
1849} 1853}
1850 1854
1851void CPumpKINDlg::LoadSettings() 1855void CPumpKINDlg::LoadSettings()
1852{ 1856{
1853CWinApp *app = AfxGetApp(); 1857CWinApp *app = AfxGetApp();
1854 ASSERT(app); 1858 ASSERT(app);
1855 m_bListen=app->GetProfileInt("TFTPSettings","Listen",m_bListen); 1859 m_bListen=app->GetProfileInt("TFTPSettings","Listen",m_bListen);
1856 m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest); 1860 m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest);
1857 m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess); 1861 m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess);
1858 m_bnwAbort=app->GetProfileString("BellsNWhistles","Abort",m_bnwAbort); 1862 m_bnwAbort=app->GetProfileString("BellsNWhistles","Abort",m_bnwAbort);
1859 m_bTFTPSubdirs=app->GetProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs); 1863 m_bTFTPSubdirs=app->GetProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs);
1860 m_ListenPort=app->GetProfileInt("TFTPSettings","ListenPort",m_ListenPort); 1864 m_ListenPort=app->GetProfileInt("TFTPSettings","ListenPort",m_ListenPort);
1861 m_LogLength=app->GetProfileInt("UISettings","LogLength",m_LogLength); 1865 m_LogLength=app->GetProfileInt("UISettings","LogLength",m_LogLength);
1862 m_PromptTimeOut=app->GetProfileInt("UISettings","PromptTimeout",m_PromptTimeOut); 1866 m_PromptTimeOut=app->GetProfileInt("UISettings","PromptTimeout",m_PromptTimeOut);
1863 m_RRQMode=app->GetProfileInt("TFTPSettings","RRQMode",m_RRQMode); 1867 m_RRQMode=app->GetProfileInt("TFTPSettings","RRQMode",m_RRQMode);
1864 m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); 1868 m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort);
1865 m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); 1869 m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot);
1866 m_LogFile=app->GetProfileString("General","LogFile",m_LogFile); 1870 m_LogFile=app->GetProfileString("General","LogFile",m_LogFile);
1867 m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds())); 1871 m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()));
1868 m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); 1872 m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize);
1869 m_RetryTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds())); 1873 m_RetryTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds()));
1870 m_WRQMode=app->GetProfileInt("TFTPSettings","WRQMode",m_WRQMode); 1874 m_WRQMode=app->GetProfileInt("TFTPSettings","WRQMode",m_WRQMode);
1871 m_bShown=app->GetProfileInt("UISettings","Visble",m_bShown); 1875 m_bShown=app->GetProfileInt("UISettings","Visble",m_bShown);
1872 if(m_TFTPRoot.IsEmpty()){ 1876 if(m_TFTPRoot.IsEmpty()){
1873 DWORD dL = ::GetCurrentDirectory(0,NULL); 1877 DWORD dL = ::GetCurrentDirectory(0,NULL);
1874 VERIFY(::GetCurrentDirectory(dL,m_TFTPRoot.GetBuffer(dL))); 1878 VERIFY(::GetCurrentDirectory(dL,m_TFTPRoot.GetBuffer(dL)));
1875 m_TFTPRoot.ReleaseBuffer(); 1879 m_TFTPRoot.ReleaseBuffer();
1876 } 1880 }
1877 ::SetCurrentDirectory(m_TFTPRoot); 1881 ::SetCurrentDirectory(m_TFTPRoot);
1878 m_aclRules.LoadProfile(app); 1882 m_aclRules.LoadProfile(app);
1879} 1883}
1880 1884
1881void CPumpKINDlg::SaveSettings() 1885void CPumpKINDlg::SaveSettings()
1882{ 1886{
1883CWinApp *app = AfxGetApp(); 1887CWinApp *app = AfxGetApp();
1884 ASSERT(app); 1888 ASSERT(app);
1885 app->WriteProfileInt("TFTPSettings","Listen",m_bListen); 1889 app->WriteProfileInt("TFTPSettings","Listen",m_bListen);
1886 app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest); 1890 app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest);
1887 app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess); 1891 app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess);
1888 app->WriteProfileString("BellsNWhistles","Abort",m_bnwAbort); 1892 app->WriteProfileString("BellsNWhistles","Abort",m_bnwAbort);
1889 app->WriteProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs); 1893 app->WriteProfileInt("TFTPSettings","Subdirs",m_bTFTPSubdirs);
1890 app->WriteProfileInt("TFTPSettings","ListenPort",m_ListenPort); 1894 app->WriteProfileInt("TFTPSettings","ListenPort",m_ListenPort);
1891 app->WriteProfileInt("UISettings","LogLength",m_LogLength); 1895 app->WriteProfileInt("UISettings","LogLength",m_LogLength);
1892 app->WriteProfileInt("UISettings","PromptTimeout",m_PromptTimeOut); 1896 app->WriteProfileInt("UISettings","PromptTimeout",m_PromptTimeOut);
1893 app->WriteProfileInt("TFTPSettings","RRQMode",m_RRQMode); 1897 app->WriteProfileInt("TFTPSettings","RRQMode",m_RRQMode);
1894 app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); 1898 app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort);
1895 app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); 1899 app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot);
1896 app->WriteProfileString("General","LogFile",m_LogFile); 1900 app->WriteProfileString("General","LogFile",m_LogFile);
1897 app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()); 1901 app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds());
1898 app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); 1902 app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize);
1899 app->WriteProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds()); 1903 app->WriteProfileInt("TFTPSettings","RetryTimeout",m_RetryTimeOut.GetTotalSeconds());
1900 app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode); 1904 app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode);
1901 app->WriteProfileInt("UISettings","Visble",m_bShown); 1905 app->WriteProfileInt("UISettings","Visble",m_bShown);
1902 m_aclRules.SaveProfile(app); 1906 m_aclRules.SaveProfile(app);
1903} 1907}
1904 1908
1905void CPumpKINDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 1909void CPumpKINDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
1906{ 1910{
1907 CDialog::OnWindowPosChanging(lpwndpos); 1911 CDialog::OnWindowPosChanging(lpwndpos);
1908 if(!m_bExiting){ 1912 if(!m_bExiting){
1909 if(m_bShown){ 1913 if(m_bShown){
1910 lpwndpos->flags&=~SWP_HIDEWINDOW; 1914 lpwndpos->flags&=~SWP_HIDEWINDOW;
1911 lpwndpos->flags|=SWP_SHOWWINDOW; 1915 lpwndpos->flags|=SWP_SHOWWINDOW;
1912 }else{ 1916 }else{
1913 lpwndpos->flags&=~SWP_SHOWWINDOW; 1917 lpwndpos->flags&=~SWP_SHOWWINDOW;
1914 lpwndpos->flags|=SWP_HIDEWINDOW; 1918 lpwndpos->flags|=SWP_HIDEWINDOW;
1915 if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu)) 1919 if(::GetForegroundWindow()==m_hWnd && (m_Trayer && !m_Trayer->m_inMenu))
1916 GetDesktopWindow()->SetForegroundWindow(); 1920 GetDesktopWindow()->SetForegroundWindow();
1917 } 1921 }
1918 } 1922 }
1919} 1923}
1920 1924
1921CString CXferSocket::ApplyRootGently(LPCTSTR fn) 1925CString CXferSocket::ApplyRootGently(LPCTSTR fn)
1922{ 1926{
1923CString f = fn; 1927CString f = fn;
1924CString rv = f; 1928CString rv = f;
1925 if((!f.IsEmpty()) && f[0]!='\\' && f.Find(":")<0 && f.Find("\\")<0) 1929 if((!f.IsEmpty()) && f[0]!='\\' && f.Find(":")<0 && f.Find("\\")<0)
1926 rv = ApplyRoot(f); 1930 rv = ApplyRoot(f);
1927 return rv; 1931 return rv;
1928} 1932}
1929 1933
1930BOOL CXferSocket::CheckBadRelativeness(LPCTSTR file) 1934BOOL CXferSocket::CheckBadRelativeness(LPCTSTR file)
1931{ 1935{
1932CString tmp = file; 1936CString tmp = file;
1933 if(tmp.IsEmpty()) 1937 if(tmp.IsEmpty())
1934 return FALSE; 1938 return FALSE;
1935 if(tmp.Find("..")>=0) 1939 if(tmp.Find("..")>=0)
1936 return TRUE; 1940 return TRUE;
1937 if(tmp.Find(":")>=0) 1941 if(tmp.Find(":")>=0)
1938 return TRUE; 1942 return TRUE;
1939 if((!m_Daddy->m_bTFTPSubdirs) && m_FileName.Find('\\')>=0) 1943 if((!m_Daddy->m_bTFTPSubdirs) && m_FileName.Find('\\')>=0)
1940 return TRUE; 1944 return TRUE;
1941 return FALSE; 1945 return FALSE;
1942} 1946}
1943 1947
1944void CAboutDlg::OnKlevernet() 1948void CAboutDlg::OnKlevernet()
1945{ 1949{
1946CString url; 1950CString url;
1947 url.LoadString(IDS_KLEVERNET_URL); 1951 url.LoadString(IDS_KLEVERNET_URL);
1948 ShellExecute(::GetDesktopWindow(),"open",url,NULL,NULL,SW_SHOWMAXIMIZED); 1952 ShellExecute(::GetDesktopWindow(),"open",url,NULL,NULL,SW_SHOWMAXIMIZED);
1949} 1953}
1950 1954
1951BOOL CPumpKINDlg::PreTranslateMessage(MSG* pMsg) 1955BOOL CPumpKINDlg::PreTranslateMessage(MSG* pMsg)
1952{ 1956{
1953 // CG: The following block was added by the ToolTips component. 1957 // CG: The following block was added by the ToolTips component.
1954 { 1958 {
1955 // Let the ToolTip process this message. 1959 // Let the ToolTip process this message.
1956 m_tooltip.RelayEvent(pMsg); 1960 m_tooltip.RelayEvent(pMsg);
1957 1961
1958 return CDialog::PreTranslateMessage(pMsg); 1962 return CDialog::PreTranslateMessage(pMsg);
1959 } 1963 }
1960} 1964}
1961 1965
1962void CPumpKINDlg::OnSelchangeLog() 1966void CPumpKINDlg::OnSelchangeLog()
1963{ 1967{
1964int sel = m_Log.GetCurSel(); 1968int sel = m_Log.GetCurSel();
1965 if(sel==LB_ERR){ 1969 if(sel==LB_ERR){
1966 TRACE0("Error retrieving selection\n"); 1970 TRACE0("Error retrieving selection\n");
1967 }else{ 1971 }else{
1968 CTime *t = (CTime*)m_Log.GetItemData(sel); 1972 CTime *t = (CTime*)m_Log.GetItemData(sel);
1969 ASSERT(t); 1973 ASSERT(t);
1970 m_tooltip.UpdateTipText(t->Format(IDS_LOGTIMEFORMAT),&m_Log); 1974 m_tooltip.UpdateTipText(t->Format(IDS_LOGTIMEFORMAT),&m_Log);
1971 } 1975 }
1972} 1976}
1973 1977
1974void CPumpKINDlg::OnTrayOpenfilesfolder() 1978void CPumpKINDlg::OnTrayOpenfilesfolder()
1975{ 1979{
1976 ShellExecute(::GetDesktopWindow(),NULL,m_TFTPRoot,NULL,NULL,SW_SHOWDEFAULT); 1980 ShellExecute(::GetDesktopWindow(),NULL,m_TFTPRoot,NULL,NULL,SW_SHOWDEFAULT);
1977} 1981}
1978 1982
1979void CPumpKINDlg::OnDropFiles(HDROP hDropInfo) 1983void CPumpKINDlg::OnDropFiles(HDROP hDropInfo)
1980{ 1984{
1981UINT files = ::DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,0); 1985UINT files = ::DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,0);
1982 ASSERT(files); 1986 ASSERT(files);
1983 for(UINT file=0;file<files;file++){ 1987 for(UINT file=0;file<files;file++){
1984 CString theFile; 1988 CString theFile;
1985 UINT fileNameLength = ::DragQueryFile(hDropInfo,file,NULL,0); 1989 UINT fileNameLength = ::DragQueryFile(hDropInfo,file,NULL,0);
1986 ASSERT(fileNameLength); 1990 ASSERT(fileNameLength);
1987 VERIFY(::DragQueryFile(hDropInfo,file,theFile.GetBuffer(fileNameLength+5),fileNameLength+4)<=fileNameLength); 1991 VERIFY(::DragQueryFile(hDropInfo,file,theFile.GetBuffer(fileNameLength+5),fileNameLength+4)<=fileNameLength);
1988 theFile.ReleaseBuffer(); 1992 theFile.ReleaseBuffer();
1989 // Send it over! 1993 // Send it over!
1990 CRequestDlg crd(NULL); 1994 CRequestDlg crd(NULL);
1991 crd.m_Drop=TRUE; 1995 crd.m_Drop=TRUE;
1992 crd.m_Put=TRUE; 1996 crd.m_Put=TRUE;
1993 crd.m_BSize=m_BlockSize; 1997 crd.m_BSize=m_BlockSize;
1994 crd.m_LocalFile=theFile; 1998 crd.m_LocalFile=theFile;
1995 if(crd.DoModal()==IDOK){ 1999 if(crd.DoModal()==IDOK){
1996 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL); 2000 CRRQSocket *socket = new CRRQSocket(this,crd.m_RemoteFile,crd.m_Type,NULL);
1997 if(crd.m_BSize) 2001 if(crd.m_BSize)
1998 socket->m__blkSize=crd.m_BSize; 2002 socket->m__blkSize=crd.m_BSize;
1999 if(!socket->Create(crd.m_LocalFile,crd.m_Host)) 2003 if(!socket->Create(crd.m_LocalFile,crd.m_Host))
2000 socket->Destroy(); 2004 socket->Destroy();
2001 } 2005 }
2002 } 2006 }
2003 ::DragFinish(hDropInfo); 2007 ::DragFinish(hDropInfo);
2004} 2008}
2005 2009
2006void CPumpKINDlg::OnCancel() 2010void CPumpKINDlg::OnCancel()
2007{ 2011{
2008 OnClose(); 2012 OnClose();
2009} 2013}
2010 2014
2011CPumpKINDlg::~CPumpKINDlg() 2015CPumpKINDlg::~CPumpKINDlg()
2012{ 2016{
2013 delete m_Trayer; 2017 delete m_Trayer;
2014 delete m_Retrier; 2018 delete m_Retrier;
2015} 2019}
2016 2020
2017void CXferSocket::OnRetry() 2021void CXferSocket::OnRetry()
2018{ 2022{
2019 if(!m_Retry){ 2023 if(!m_Retry){
2020 TRACE("Retrying unretriable..\n"); 2024 TRACE("Retrying unretriable..\n");
2021 return; 2025 return;
2022 } 2026 }
2023 TRACE0("Retrying..\n"); 2027 TRACE0("Retrying..\n");
2024 m_bRetry=TRUE; 2028 m_bRetry=TRUE;
2025 PostTFTP(tftp::Copy(m_Retry)); 2029 PostTFTP(tftp::Copy(m_Retry));
2026 m_bRetry=FALSE; 2030 m_bRetry=FALSE;
2027} 2031}
2028 2032
2029tftp* tftp::Copy(tftp *src) 2033tftp* tftp::Copy(tftp *src)
2030{ 2034{
2031 ASSERT(src); 2035 ASSERT(src);
2032 ASSERT(src->length); 2036 ASSERT(src->length);
2033tftp* rv = Allocate(src->length); 2037tftp* rv = Allocate(src->length);
2034 ASSERT(rv); 2038 ASSERT(rv);
2035 memmove(rv,src,tftpSlackSize+src->length); 2039 memmove(rv,src,tftpSlackSize+src->length);
2036 return rv; 2040 return rv;
2037} 2041}
2038 2042
2039void CXferSocket::SetTry(tftp *p) 2043void CXferSocket::SetTry(tftp *p)
2040{ 2044{
2041 if(m_Retry) 2045 if(m_Retry)
2042 delete m_Retry; 2046 delete m_Retry;
2043 m_Retry=p?tftp::Copy(p):NULL; 2047 m_Retry=p?tftp::Copy(p):NULL;
2044} 2048}
2045 2049
2046void CPumpKINDlg::OnHelp() 2050void CPumpKINDlg::OnHelp()
2047{ 2051{
2048 AfxGetApp()->WinHelp(0,HELP_FINDER); 2052 AfxGetApp()->WinHelp(0,HELP_FINDER);
2049} 2053}
2050 2054
2051BOOL CListenSocket::SetListen(BOOL b) { 2055BOOL CListenSocket::SetListen(BOOL b) {
2052 ASSERT(m_Daddy); 2056 ASSERT(m_Daddy);
2053 if(b==m_bListen) 2057 if(b==m_bListen)
2054 return TRUE; 2058 return TRUE;
2055 if(b) { 2059 if(b) {
2056 if(!Create(m_Daddy->m_ListenPort,SOCK_DGRAM)) 2060 if(!Create(m_Daddy->m_ListenPort,SOCK_DGRAM))
2057 return FALSE; 2061 return FALSE;
2058 return m_bListen=TRUE; 2062 return m_bListen=TRUE;
2059 }else{ 2063 }else{
2060 Close(); m_bListen=FALSE; 2064 Close(); m_bListen=FALSE;
2061 return TRUE; 2065 return TRUE;
2062 } 2066 }
2063} 2067}
2064 2068
2065void CPumpKINDlg::OnListening() 2069void CPumpKINDlg::OnListening()
2066{ 2070{
2067 if(!m_Listener.SetListen(m_ListenCtl.GetCheck()==1)) { 2071 if(!m_Listener.SetListen(m_ListenCtl.GetCheck()==1)) {
2068 TRACE0("Failed to create socket\n"); 2072 TRACE0("Failed to create socket\n");
2069 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); 2073 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
2070 } 2074 }
2071 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); 2075 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
2072 m_bListen=m_Listener.m_bListen; 2076 m_bListen=m_Listener.m_bListen;
2073} 2077}
2074 2078
2075void CPumpKINDlg::OnTrayListen() 2079void CPumpKINDlg::OnTrayListen()
2076{ 2080{
2077 if(!m_Listener.SetListen(!m_Listener.m_bListen)) { 2081 if(!m_Listener.SetListen(!m_Listener.m_bListen)) {
2078 TRACE0("Failed to create socket\n"); 2082 TRACE0("Failed to create socket\n");
2079 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); 2083 AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION);
2080 } 2084 }
2081 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); 2085 m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0);
2082 m_bListen=m_Listener.m_bListen; 2086 m_bListen=m_Listener.m_bListen;
2083} 2087}
2084 2088
2085void CPumpKINDlg::LogLine(LPCTSTR str) 2089void CPumpKINDlg::LogLine(LPCTSTR str)
2086{ 2090{
2087 LogLineToScreen(str); 2091 LogLineToScreen(str);
2088 if(!m_LogFile.IsEmpty()) { 2092 if(!m_LogFile.IsEmpty()) {
2089 if(!Klever::LogRecord((LPCTSTR)m_LogFile,str)) { 2093 if(!Klever::LogRecord((LPCTSTR)m_LogFile,str)) {
2090 if(m_lastlogerr!=m_LogFile) { 2094 if(m_lastlogerr!=m_LogFile) {
2091 CString tmp; 2095 CString tmp;
2092 tmp.Format(IDS_LOG_LOGERROR,m_LogFile); 2096 tmp.Format(IDS_LOG_LOGERROR,m_LogFile);
2093 LogLineToScreen(tmp); 2097 LogLineToScreen(tmp);
2094 m_lastlogerr=m_LogFile; 2098 m_lastlogerr=m_LogFile;
2095 } 2099 }
2096 } 2100 }
2097 } 2101 }
2098} 2102}
2099 2103
2100void CPumpKINDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 2104void CPumpKINDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
2101{ 2105{
2102 CDialog::OnGetMinMaxInfo(lpMMI); 2106 CDialog::OnGetMinMaxInfo(lpMMI);
2103 if(m_MinSize.cx>0 && m_MinSize.cy>0){ 2107 if(m_MinSize.cx>0 && m_MinSize.cy>0){
2104 lpMMI->ptMinTrackSize.x = m_MinSize.cx; 2108 lpMMI->ptMinTrackSize.x = m_MinSize.cx;
2105 lpMMI->ptMinTrackSize.y = m_MinSize.cy; 2109 lpMMI->ptMinTrackSize.y = m_MinSize.cy;
2106 } 2110 }
2107} 2111}
2108 2112
2109void CPumpKINDlg::OnSize(UINT nType, int cx, int cy) 2113void CPumpKINDlg::OnSize(UINT nType, int cx, int cy)
2110{ 2114{
2111 CDialog::OnSize(nType, cx, cy); 2115 CDialog::OnSize(nType, cx, cy);
2112 if(nType==SIZE_RESTORED) 2116 if(nType==SIZE_RESTORED)
2113 RecalcLayout(cx,cy); 2117 RecalcLayout(cx,cy);
2114} 2118}
2115 2119
2116void CPumpKINDlg::RecalcLayout(int,int) 2120void CPumpKINDlg::RecalcLayout(int,int)
2117{ 2121{
2118 CRect wrc; 2122 CRect wrc;
2119 GetClientRect(&wrc); 2123 GetClientRect(&wrc);
2120 AdjustButton(m_GetCtl,wrc); 2124 AdjustButton(m_GetCtl,wrc);
2121 AdjustButton(m_PutCtl,wrc); 2125 AdjustButton(m_PutCtl,wrc);
2122 AdjustButton(m_AbortCtl,wrc); 2126 AdjustButton(m_AbortCtl,wrc);
2123 AdjustButton(m_HelpCtl,wrc); 2127 AdjustButton(m_HelpCtl,wrc);
2124 AdjustButton(m_ExitCtl,wrc); 2128 AdjustButton(m_ExitCtl,wrc);
2125 AdjustButton(m_OptionsCtl,wrc); 2129 AdjustButton(m_OptionsCtl,wrc);
2126 CRect brc; 2130 CRect brc;
2127 m_List.GetWindowRect(&brc); ScreenToClient(&brc); 2131 m_List.GetWindowRect(&brc); ScreenToClient(&brc);
2128 m_List.SetWindowPos( 2132 m_List.SetWindowPos(
2129 0, 2133 0,
2130 brc.left, brc.top, 2134 brc.left, brc.top,
2131 wrc.right-m_rightGapList-brc.left, brc.bottom-brc.top, 2135 wrc.right-m_rightGapList-brc.left, brc.bottom-brc.top,
2132 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS ); 2136 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS );
2133 m_Log.GetWindowRect(&brc); ScreenToClient(&brc); 2137 m_Log.GetWindowRect(&brc); ScreenToClient(&brc);
2134 m_Log.SetWindowPos( 2138 m_Log.SetWindowPos(
2135 0, 2139 0,
2136 brc.left, brc.top, 2140 brc.left, brc.top,
2137 wrc.right-m_rightGapButtons-brc.left, wrc.bottom-m_bottomGapLog-brc.top, 2141 wrc.right-m_rightGapButtons-brc.left, wrc.bottom-m_bottomGapLog-brc.top,
2138 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS ); 2142 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOCOPYBITS );
2139 m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc); 2143 m_ListenCtl.GetWindowRect(&brc); ScreenToClient(&brc);
2140 m_ListenCtl.SetWindowPos( 2144 m_ListenCtl.SetWindowPos(
2141 0, 2145 0,
2142 wrc.right-brc.Width()-m_rightGapButtons, wrc.bottom-brc.Height()-m_bottomGapListen, 2146 wrc.right-brc.Width()-m_rightGapButtons, wrc.bottom-brc.Height()-m_bottomGapListen,
2143 0,0, 2147 0,0,
2144 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS ); 2148 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS );
2145 int i = m_Log.GetCount(); 2149 int i = m_Log.GetCount();
2146 if(i!=LB_ERR) 2150 if(i!=LB_ERR)
2147 m_Log.SetCurSel(i-1); 2151 m_Log.SetCurSel(i-1);
2148} 2152}
2149 2153
2150void CPumpKINDlg::AdjustButton(CWnd& w,CRect& wrc) 2154void CPumpKINDlg::AdjustButton(CWnd& w,CRect& wrc)
2151{ 2155{
2152 CRect brc; 2156 CRect brc;
2153 w.GetWindowRect(&brc); ScreenToClient(&brc); 2157 w.GetWindowRect(&brc); ScreenToClient(&brc);
2154 w.SetWindowPos( 2158 w.SetWindowPos(
2155 0, 2159 0,
2156 wrc.right-brc.Width()-m_rightGapButtons, brc.top, 2160 wrc.right-brc.Width()-m_rightGapButtons, brc.top,
2157 0, 0, 2161 0, 0,
2158 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS ); 2162 SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS );
2159} 2163}