author | Michael Krelin <hacker@klever.net> | 2011-04-27 10:10:00 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2011-04-27 10:10:00 (UTC) |
commit | d097b824b7fcad001c9581fb2e322bf3e3e5961d (patch) (unidiff) | |
tree | 5a1c55e82c4b0ff4acca276b8e1122547530cc0b | |
parent | 65981784977659461f08b48f537be9f9f77a2112 (diff) | |
download | pumpkin-d097b824b7fcad001c9581fb2e322bf3e3e5961d.zip pumpkin-d097b824b7fcad001c9581fb2e322bf3e3e5961d.tar.gz pumpkin-d097b824b7fcad001c9581fb2e322bf3e3e5961d.tar.bz2 |
fix for misleading error message about unexpected source
along with a double-freeing offense. When I fail to receive packet not only
I diagnose this unfortunate development, but also start talking about
packet from unexpected source which is kinda weird considering there's
no packet at all.
Signed-off-by: Michael Krelin <hacker@klever.net>
-rwxr-xr-x[-rw-r--r--] | PumpKINDlg.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp index f41b69f..3ff1500 100644..100755 --- a/PumpKINDlg.cpp +++ b/PumpKINDlg.cpp | |||
@@ -92,1024 +92,1025 @@ CPumpKINDlg::CPumpKINDlg(CWnd* pParent /*=NULL*/) | |||
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=2048; | 99 | m_BlockSize=2048; |
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 | ||
128 | void CPumpKINDlg::DoDataExchange(CDataExchange* pDX) | 128 | void 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 | ||
144 | BEGIN_MESSAGE_MAP(CPumpKINDlg, CDialog) | 144 | BEGIN_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 |
179 | END_MESSAGE_MAP() | 179 | END_MESSAGE_MAP() |
180 | 180 | ||
181 | ///////////////////////////////////////////////////////////////////////////// | 181 | ///////////////////////////////////////////////////////////////////////////// |
182 | // CPumpKINDlg message handlers | 182 | // CPumpKINDlg message handlers |
183 | 183 | ||
184 | BOOL CPumpKINDlg::OnInitDialog() | 184 | BOOL 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 |
221 | CRect listrc; | 221 | CRect 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 | ||
233 | CRect wrci, wrco; | 233 | CRect wrci, wrco; |
234 | GetWindowRect(&wrco); | 234 | GetWindowRect(&wrco); |
235 | GetClientRect(&wrci); | 235 | GetClientRect(&wrci); |
236 | CRect brc; | 236 | CRect 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 | ||
247 | CRect rc, drc; | 247 | CRect 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 | ||
277 | void CPumpKINDlg::OnSysCommand(UINT nID, LPARAM lParam) | 277 | void 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 | ||
290 | void CPumpKINDlg::OnDestroy() | 290 | void CPumpKINDlg::OnDestroy() |
291 | { | 291 | { |
292 | SaveSettings(); | 292 | SaveSettings(); |
293 | 293 | ||
294 | NOTIFYICONDATA nid; | 294 | NOTIFYICONDATA 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(); |
304 | POSITION p = m_LogTimes.GetStartPosition(); | 304 | POSITION 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 | ||
319 | void CPumpKINDlg::OnPaint() | 319 | void 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. |
356 | HCURSOR CPumpKINDlg::OnQueryDragIcon() | 356 | HCURSOR CPumpKINDlg::OnQueryDragIcon() |
357 | { | 357 | { |
358 | return (HCURSOR) m_hIcon; | 358 | return (HCURSOR) m_hIcon; |
359 | } | 359 | } |
360 | 360 | ||
361 | int CPumpKINDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) | 361 | int 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 | ||
377 | NOTIFYICONDATA nid; | 377 | NOTIFYICONDATA 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 | ||
392 | void CListenSocket::OnReceive(int nErrorCode) | 392 | void 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 | } |
399 | DWORD fionread = 0; | 399 | DWORD 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 |
401 | tftp *tftpRQ = tftp::Allocate(fionread); | 401 | tftp *tftpRQ = tftp::Allocate(fionread); |
402 | ASSERT(tftpRQ); | 402 | ASSERT(tftpRQ); |
403 | SOCKADDR_IN sin; | 403 | SOCKADDR_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 |
410 | CString tmp; | 410 | CString 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 |
414 | POSITION p = m_Daddy->m_Xfers.GetStartPosition(); | 414 | POSITION 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 | ||
461 | BOOL tftp::Receive(CAsyncSocket* socket,UINT maxLength,SOCKADDR_IN *sin) | 461 | BOOL tftp::Receive(CAsyncSocket* socket,UINT maxLength,SOCKADDR_IN *sin) |
462 | { | 462 | { |
463 | ASSERT(socket); | 463 | ASSERT(socket); |
464 | int saddrLen = sizeof(SOCKADDR_IN); | 464 | int 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 | ||
477 | UINT tftp::Opcode() | 477 | UINT tftp::Opcode() |
478 | { | 478 | { |
479 | return REVERSEBYTES(opcode); | 479 | return REVERSEBYTES(opcode); |
480 | } | 480 | } |
481 | 481 | ||
482 | CString tftp::rqFileName() | 482 | CString tftp::rqFileName() |
483 | { | 483 | { |
484 | ASSERT(length); | 484 | ASSERT(length); |
485 | ASSERT(Opcode()==opRRQ || Opcode()==opWRQ); | 485 | ASSERT(Opcode()==opRRQ || Opcode()==opWRQ); |
486 | CString rv; | 486 | CString 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 | ||
492 | CString tftp::rqType() | 492 | CString tftp::rqType() |
493 | { | 493 | { |
494 | ASSERT(length); | 494 | ASSERT(length); |
495 | ASSERT(Opcode()==opRRQ || Opcode()==opWRQ); | 495 | ASSERT(Opcode()==opRRQ || Opcode()==opWRQ); |
496 | CString rv; | 496 | CString rv; |
497 | char *tmp = (char*)memchr(&data.m_RQ.data,0,length-sizeof(opcode)); | 497 | char *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 | ||
503 | UINT tftp::GetOptions(tftp::tftpOptions* ops) | 503 | UINT 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); |
508 | tftpOptions& o = *ops; | 508 | tftpOptions& o = *ops; |
509 | LPSTR base = (LPSTR)&data.m_RQ.data; | 509 | LPSTR base = (LPSTR)&data.m_RQ.data; |
510 | UINT basePtr = 0; | 510 | UINT 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(); |
524 | UINT rv = 0; | 524 | UINT 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 | ||
537 | tftp::tftp() | 537 | tftp::tftp() |
538 | { | 538 | { |
539 | length=0; | 539 | length=0; |
540 | } | 540 | } |
541 | 541 | ||
542 | 542 | ||
543 | void CXferSocket::OnSend(int nErrorCode) | 543 | void 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 | ||
573 | BOOL tftp::Send(CAsyncSocket *socket,SOCKADDR_IN* saddr) | 573 | BOOL tftp::Send(CAsyncSocket *socket,SOCKADDR_IN* saddr) |
574 | { | 574 | { |
575 | ASSERT(socket); | 575 | ASSERT(socket); |
576 | int rv = socket->SendTo(udpBase(),length,(SOCKADDR*)saddr,sizeof(SOCKADDR_IN)); | 576 | int 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 | ||
582 | void CXferSocket::DoSelect(BOOL do_select) | 582 | void CXferSocket::DoSelect(BOOL do_select) |
583 | { | 583 | { |
584 | if(m_Peer.sin_addr.s_addr!=INADDR_NONE) | 584 | if(m_Peer.sin_addr.s_addr!=INADDR_NONE) |
585 | AsyncSelect(FD_CLOSE|FD_READ|((m_Queue.IsEmpty()&&!do_select)?0:FD_WRITE)); | 585 | AsyncSelect(FD_CLOSE|FD_READ|((m_Queue.IsEmpty()&&!do_select)?0:FD_WRITE)); |
586 | } | 586 | } |
587 | 587 | ||
588 | void CXferSocket::OnReceive(int nErrorCode) | 588 | void 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); |
596 | DWORD fionread = 0; | 596 | DWORD fionread = 0; |
597 | VERIFY(IOCtl(FIONREAD,&fionread)); | 597 | VERIFY(IOCtl(FIONREAD,&fionread)); |
598 | tftp *p = tftp::Allocate(fionread); | 598 | tftp *p = tftp::Allocate(fionread); |
599 | ASSERT(p); | 599 | ASSERT(p); |
600 | SOCKADDR_IN sin; | 600 | SOCKADDR_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 | return; | ||
604 | }else | 605 | }else |
605 | if(m_Peer.sin_addr.s_addr==INADDR_NONE){ | 606 | if(m_Peer.sin_addr.s_addr==INADDR_NONE){ |
606 | m_Peer.sin_addr=sin.sin_addr; | 607 | m_Peer.sin_addr=sin.sin_addr; |
607 | m_Peer.sin_port=sin.sin_port; | 608 | m_Peer.sin_port=sin.sin_port; |
608 | } | 609 | } |
609 | BOOL alive = TRUE; | 610 | BOOL alive = TRUE; |
610 | if(state==stateInit){ | 611 | if(state==stateInit){ |
611 | state=stateXfer; | 612 | state=stateXfer; |
612 | m_Peer.sin_port=sin.sin_port; | 613 | m_Peer.sin_port=sin.sin_port; |
613 | UpdateList(); | 614 | UpdateList(); |
614 | } | 615 | } |
615 | if(sin.sin_addr.s_addr!=m_Peer.sin_addr.s_addr || sin.sin_port!=m_Peer.sin_port){ | 616 | 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); | 617 | m_Daddy->LogLine(IDS_LOG_XFERSOURCETID); |
617 | // *** Bounce it! | 618 | // *** Bounce it! |
618 | }else{ | 619 | }else{ |
619 | alive = OnTFTP(p); | 620 | alive = OnTFTP(p); |
620 | } | 621 | } |
621 | delete p; | 622 | delete p; |
622 | if(alive){ | 623 | if(alive){ |
623 | DoSelect(); | 624 | DoSelect(); |
624 | ResetTimeout(); | 625 | ResetTimeout(); |
625 | } | 626 | } |
626 | } | 627 | } |
627 | 628 | ||
628 | void CXferSocket::SetPeer(SOCKADDR_IN *sin) | 629 | void CXferSocket::SetPeer(SOCKADDR_IN *sin) |
629 | { | 630 | { |
630 | ASSERT(sin); | 631 | ASSERT(sin); |
631 | memmove(&m_Peer,sin,sizeof(m_Peer)); | 632 | memmove(&m_Peer,sin,sizeof(m_Peer)); |
632 | } | 633 | } |
633 | 634 | ||
634 | void CXferSocket::UpdateList() | 635 | void CXferSocket::UpdateList() |
635 | { | 636 | { |
636 | ASSERT(m_Daddy); | 637 | ASSERT(m_Daddy); |
637 | LV_FINDINFO lvf; | 638 | LV_FINDINFO lvf; |
638 | memset(&lvf,0,sizeof(lvf)); | 639 | memset(&lvf,0,sizeof(lvf)); |
639 | lvf.flags=LVFI_PARAM; | 640 | lvf.flags=LVFI_PARAM; |
640 | lvf.lParam=(LPARAM)this; | 641 | lvf.lParam=(LPARAM)this; |
641 | int i = m_Daddy->m_List.FindItem(&lvf); | 642 | int i = m_Daddy->m_List.FindItem(&lvf); |
642 | if(i<0){ | 643 | if(i<0){ |
643 | ASSERT(IsKindOf(RUNTIME_CLASS(CRRQSocket)) || IsKindOf(RUNTIME_CLASS(CWRQSocket))); | 644 | 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); | 645 | 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)); | 646 | ASSERT(!(i<0)); |
646 | m_Daddy->m_List.SetItemData(i,(DWORD)this); | 647 | m_Daddy->m_List.SetItemData(i,(DWORD)this); |
647 | } | 648 | } |
648 | m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemFile,m_FileName); | 649 | m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemFile,m_FileName); |
649 | m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemType,m_Type); | 650 | 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)); | 651 | m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemPeer,inet_ntoa(m_Peer.sin_addr)); |
651 | CString tmp; | 652 | CString tmp; |
652 | tmp.Format(IDS_FMT_BYTES,GetACK()); | 653 | tmp.Format(IDS_FMT_BYTES,GetACK()); |
653 | m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemBytes,tmp); | 654 | m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemBytes,tmp); |
654 | if(m_xferSize>=0){ | 655 | if(m_xferSize>=0){ |
655 | tmp.Format(IDS_FMT_BYTES,m_xferSize); | 656 | tmp.Format(IDS_FMT_BYTES,m_xferSize); |
656 | m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemTSize,tmp); | 657 | m_Daddy->m_List.SetItemText(i,CPumpKINDlg::subitemTSize,tmp); |
657 | } | 658 | } |
658 | } | 659 | } |
659 | 660 | ||
660 | CXferSocket::CXferSocket() | 661 | CXferSocket::CXferSocket() |
661 | : m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE), | 662 | : m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE), |
662 | m_blkSize(512), m_timeOut(30), m_xferSize(-1), | 663 | m_blkSize(512), m_timeOut(30), m_xferSize(-1), |
663 | m__blkSize(512), m__timeOut(30) | 664 | m__blkSize(512), m__timeOut(30) |
664 | { | 665 | { |
665 | m_Daddy=NULL; | 666 | m_Daddy=NULL; |
666 | m_Peer.sin_addr.s_addr=INADDR_NONE; | 667 | m_Peer.sin_addr.s_addr=INADDR_NONE; |
667 | m_Peer.sin_family=AF_INET; | 668 | m_Peer.sin_family=AF_INET; |
668 | state=stateNone; | 669 | state=stateNone; |
669 | } | 670 | } |
670 | 671 | ||
671 | ULONG CXferSocket::GetACK() | 672 | ULONG CXferSocket::GetACK() |
672 | { | 673 | { |
673 | return 0; | 674 | return 0; |
674 | } | 675 | } |
675 | 676 | ||
676 | CXferSocket::CXferSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN* sin) | 677 | CXferSocket::CXferSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN* sin) |
677 | : m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE), | 678 | : m_wndResolver(NULL), m_Retry(NULL), m_bRetry(FALSE), |
678 | m_blkSize(512), m_timeOut(30), m_xferSize(-1), | 679 | m_blkSize(512), m_timeOut(30), m_xferSize(-1), |
679 | m__blkSize(512), m__timeOut(30) | 680 | m__blkSize(512), m__timeOut(30) |
680 | { | 681 | { |
681 | m_Peer.sin_family=AF_INET; | 682 | m_Peer.sin_family=AF_INET; |
682 | state=stateNone; | 683 | state=stateNone; |
683 | ASSERT(daddy); | 684 | ASSERT(daddy); |
684 | m_Daddy=daddy; | 685 | m_Daddy=daddy; |
685 | m_timeOut=m__timeOut=m_Daddy->m_TFTPTimeOut.GetTotalSeconds(); | 686 | m_timeOut=m__timeOut=m_Daddy->m_TFTPTimeOut.GetTotalSeconds(); |
686 | if(sin){ | 687 | if(sin){ |
687 | m_Peer.sin_addr.s_addr=sin->sin_addr.s_addr; | 688 | m_Peer.sin_addr.s_addr=sin->sin_addr.s_addr; |
688 | m_Peer.sin_port=sin->sin_port; | 689 | m_Peer.sin_port=sin->sin_port; |
689 | }else | 690 | }else |
690 | m_Peer.sin_addr.s_addr=INADDR_NONE; | 691 | m_Peer.sin_addr.s_addr=INADDR_NONE; |
691 | m_FileName=fileName; | 692 | m_FileName=fileName; |
692 | m_Type=type; | 693 | m_Type=type; |
693 | } | 694 | } |
694 | 695 | ||
695 | BOOL CRRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName) | 696 | BOOL CRRQSocket::Create(LPCTSTR localFile,LPCTSTR hostName) |
696 | { | 697 | { |
697 | if(!CAsyncSocket::Create(0,SOCK_DGRAM)) | 698 | if(!CAsyncSocket::Create(0,SOCK_DGRAM)) |
698 | return FALSE; | 699 | return FALSE; |
699 | ASSERT(m_Daddy); | 700 | ASSERT(m_Daddy); |
700 | ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName); | 701 | ASSERT(m_Peer.sin_addr.s_addr!=INADDR_NONE || hostName); |
701 | m_Daddy->m_Xfers[m_hSocket]=this; | 702 | m_Daddy->m_Xfers[m_hSocket]=this; |
702 | CString lFile = localFile?localFile:m_FileName; | 703 | CString lFile = localFile?localFile:m_FileName; |
703 | TurnSlashes(lFile,TRUE); | 704 | TurnSlashes(lFile,TRUE); |
704 | UpdateList(); | 705 | UpdateList(); |
705 | if(!localFile){// Check only for incoming requests | 706 | if(!localFile){// Check only for incoming requests |
706 | if(CheckBadRelativeness(m_FileName)){ | 707 | if(CheckBadRelativeness(m_FileName)){ |
707 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); | 708 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); |
708 | return TRUE; | 709 | return TRUE; |
709 | } | 710 | } |
710 | int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opRRQ,m_Peer.sin_addr.s_addr); | 711 | int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opRRQ,m_Peer.sin_addr.s_addr); |
711 | if(atar<0) | 712 | if(atar<0) |
712 | atar = m_Daddy->m_RRQMode; | 713 | atar = m_Daddy->m_RRQMode; |
713 | switch(atar){ | 714 | switch(atar){ |
714 | case CPumpKINDlg::rrqGiveAll: | 715 | case CPumpKINDlg::rrqGiveAll: |
715 | break; | 716 | break; |
716 | case CPumpKINDlg::rrqAlwaysConfirm: | 717 | case CPumpKINDlg::rrqAlwaysConfirm: |
717 | if(ConfirmRequest()) | 718 | if(ConfirmRequest()) |
718 | break; | 719 | break; |
719 | default: | 720 | default: |
720 | TRACE1("Unexpected access target: %d\n",atar); | 721 | TRACE1("Unexpected access target: %d\n",atar); |
721 | case CPumpKINDlg::rrqDenyAll: | 722 | case CPumpKINDlg::rrqDenyAll: |
722 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); | 723 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); |
723 | return TRUE; | 724 | return TRUE; |
724 | } | 725 | } |
725 | } | 726 | } |
726 | CString fn = localFile?ApplyRootGently(lFile):ApplyRoot(lFile); | 727 | CString fn = localFile?ApplyRootGently(lFile):ApplyRoot(lFile); |
727 | CFileException e; | 728 | CFileException e; |
728 | if(!m_File.Open(fn,CFile::modeRead|CFile::shareDenyWrite,&e)){ | 729 | if(!m_File.Open(fn,CFile::modeRead|CFile::shareDenyWrite,&e)){ |
729 | if(localFile){ | 730 | if(localFile){ |
730 | CString tmp; | 731 | CString tmp; |
731 | tmp.Format(IDS_LOG_FAILEDLOCALFILE,fn); | 732 | tmp.Format(IDS_LOG_FAILEDLOCALFILE,fn); |
732 | m_Daddy->LogLine(tmp); | 733 | m_Daddy->LogLine(tmp); |
733 | return FALSE; | 734 | return FALSE; |
734 | } | 735 | } |
735 | Deny(&e); | 736 | Deny(&e); |
736 | return TRUE; | 737 | return TRUE; |
737 | } | 738 | } |
738 | m_xferSize=m_File.GetLength();// *** HANDLE EXCEPTION | 739 | m_xferSize=m_File.GetLength();// *** HANDLE EXCEPTION |
739 | if(hostName){ | 740 | if(hostName){ |
740 | m_HostName=hostName; | 741 | m_HostName=hostName; |
741 | 742 | ||
742 | CString tmp; | 743 | CString tmp; |
743 | tmp.Format(IDS_LOG_SENDING,m_FileName,m_HostName); | 744 | tmp.Format(IDS_LOG_SENDING,m_FileName,m_HostName); |
744 | m_Daddy->LogLine(tmp); | 745 | m_Daddy->LogLine(tmp); |
745 | 746 | ||
746 | CString inAddr = hostName; | 747 | CString inAddr = hostName; |
747 | int at = inAddr.Find('@'); | 748 | int at = inAddr.Find('@'); |
748 | if(at>=0) | 749 | if(at>=0) |
749 | inAddr=inAddr.Mid(at+1); | 750 | inAddr=inAddr.Mid(at+1); |
750 | if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){ | 751 | if((m_Peer.sin_addr.s_addr=inet_addr((LPCTSTR)inAddr))==INADDR_NONE){ |
751 | ASSERT(!m_wndResolver); | 752 | ASSERT(!m_wndResolver); |
752 | m_wndResolver = new CResolver(this); | 753 | m_wndResolver = new CResolver(this); |
753 | ASSERT(m_wndResolver); | 754 | ASSERT(m_wndResolver); |
754 | return m_wndResolver->Resolve(); | 755 | return m_wndResolver->Resolve(); |
755 | } | 756 | } |
756 | else | 757 | else |
757 | OnHostKnown(); | 758 | OnHostKnown(); |
758 | }else{ | 759 | }else{ |
759 | tftp::tftpOptions o; | 760 | tftp::tftpOptions o; |
760 | CString v; | 761 | CString v; |
761 | if(m_Options.Lookup(tftpoBSize,v)){ | 762 | if(m_Options.Lookup(tftpoBSize,v)){ |
762 | m__blkSize=atoi(v); | 763 | m__blkSize=atoi(v); |
763 | if(m__blkSize){ | 764 | if(m__blkSize){ |
764 | m_blkSize=m__blkSize; | 765 | m_blkSize=m__blkSize; |
765 | v.Format("%u",m_blkSize); | 766 | v.Format("%u",m_blkSize); |
766 | o[tftpoBSize]=v; | 767 | o[tftpoBSize]=v; |
767 | } | 768 | } |
768 | } | 769 | } |
769 | if(m_Options.Lookup(tftpoTSize,v)){ | 770 | if(m_Options.Lookup(tftpoTSize,v)){ |
770 | v.Format("%lu",m_xferSize); | 771 | v.Format("%lu",m_xferSize); |
771 | o[tftpoTSize]=v; | 772 | o[tftpoTSize]=v; |
772 | } | 773 | } |
773 | if(m_Options.Lookup(tftpoTOut,v)){ | 774 | if(m_Options.Lookup(tftpoTOut,v)){ |
774 | m__timeOut=atoi(v); | 775 | m__timeOut=atoi(v); |
775 | if(m__timeOut){ | 776 | if(m__timeOut){ |
776 | m_timeOut=m__timeOut; | 777 | m_timeOut=m__timeOut; |
777 | v.Format("%u",m_timeOut); | 778 | v.Format("%u",m_timeOut); |
778 | o[tftpoTOut]=v; | 779 | o[tftpoTOut]=v; |
779 | } | 780 | } |
780 | } | 781 | } |
781 | // XXX: see if we can enforce our preference regarding block size here. | 782 | // XXX: see if we can enforce our preference regarding block size here. |
782 | if(m_xferSize >= (m_blkSize<<16)) { | 783 | if(m_xferSize >= (m_blkSize<<16)) { |
783 | Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG); | 784 | Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG); |
784 | return TRUE; | 785 | return TRUE; |
785 | } | 786 | } |
786 | state = stateXfer; | 787 | state = stateXfer; |
787 | m_ACK=0; | 788 | m_ACK=0; |
788 | if(o.GetCount()){ | 789 | if(o.GetCount()){ |
789 | tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o)); | 790 | tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&o)); |
790 | ASSERT(p); | 791 | ASSERT(p); |
791 | p->SetOpcode(tftp::opOACK); | 792 | p->SetOpcode(tftp::opOACK); |
792 | p->data.m_OACK.Set(&o); | 793 | p->data.m_OACK.Set(&o); |
793 | PostTFTP(p,TRUE); | 794 | PostTFTP(p,TRUE); |
794 | }else | 795 | }else |
795 | DoXfer(); | 796 | DoXfer(); |
796 | } | 797 | } |
797 | return TRUE; | 798 | return TRUE; |
798 | } | 799 | } |
799 | 800 | ||
800 | CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) | 801 | CRRQSocket::CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin) |
801 | : CXferSocket(daddy,fileName,type,sin) | 802 | : CXferSocket(daddy,fileName,type,sin) |
802 | { | 803 | { |
803 | m_ACK=0; | 804 | m_ACK=0; |
804 | m_LastSlack=0; | 805 | m_LastSlack=0; |
805 | } | 806 | } |
806 | 807 | ||
807 | UINT tftp::tftpERROR::tftpSize(LPCTSTR msg) | 808 | UINT tftp::tftpERROR::tftpSize(LPCTSTR msg) |
808 | { | 809 | { |
809 | return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1; | 810 | return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpERROR::tftpErrorCode)+strlen(msg)+1; |
810 | } | 811 | } |
811 | 812 | ||
812 | tftp* tftp::Allocate(UINT tftpSize) | 813 | tftp* tftp::Allocate(UINT tftpSize) |
813 | { | 814 | { |
814 | ASSERT(tftpSize); | 815 | ASSERT(tftpSize); |
815 | tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize]; | 816 | tftp* rv = (tftp*) new BYTE[tftpSlackSize+tftpSize]; |
816 | ASSERT(rv); | 817 | ASSERT(rv); |
817 | rv->length=tftpSize; | 818 | rv->length=tftpSize; |
818 | return rv; | 819 | return rv; |
819 | } | 820 | } |
820 | 821 | ||
821 | void tftp::errSet(UINT code,LPCTSTR msg) | 822 | void tftp::errSet(UINT code,LPCTSTR msg) |
822 | { | 823 | { |
823 | ASSERT(this); | 824 | ASSERT(this); |
824 | ASSERT(length>=data.m_ERROR.tftpSize(msg)); | 825 | ASSERT(length>=data.m_ERROR.tftpSize(msg)); |
825 | strcpy((char*)data.m_ERROR.data,msg); | 826 | strcpy((char*)data.m_ERROR.data,msg); |
826 | data.m_ERROR.SetCode(code); | 827 | data.m_ERROR.SetCode(code); |
827 | } | 828 | } |
828 | 829 | ||
829 | void CXferSocket::PostTFTP(tftp* p,BOOL retryable) | 830 | void CXferSocket::PostTFTP(tftp* p,BOOL retryable) |
830 | { | 831 | { |
831 | ASSERT(p); | 832 | ASSERT(p); |
832 | m_Queue.AddTail(p); | 833 | m_Queue.AddTail(p); |
833 | DoSelect(); | 834 | DoSelect(); |
834 | if(!m_bRetry){ | 835 | if(!m_bRetry){ |
835 | if(retryable) | 836 | if(retryable) |
836 | SetTry(p); | 837 | SetTry(p); |
837 | else | 838 | else |
838 | SetTry(); | 839 | SetTry(); |
839 | } | 840 | } |
840 | ResetTimeout(); | 841 | ResetTimeout(); |
841 | } | 842 | } |
842 | 843 | ||
843 | void CXferSocket::Deny(UINT errCode,UINT errID) | 844 | void CXferSocket::Deny(UINT errCode,UINT errID) |
844 | { | 845 | { |
845 | PostError(errCode,errID); | 846 | PostError(errCode,errID); |
846 | state=stateDeny; | 847 | state=stateDeny; |
847 | } | 848 | } |
848 | 849 | ||
849 | void CRRQSocket::DoXfer() | 850 | void CRRQSocket::DoXfer() |
850 | { | 851 | { |
851 | tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize)); | 852 | tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize)); |
852 | ASSERT(p); | 853 | ASSERT(p); |
853 | p->SetOpcode(tftp::opDATA); | 854 | p->SetOpcode(tftp::opDATA); |
854 | TRY{ | 855 | TRY{ |
855 | m_File.Seek(m_ACK*m_blkSize,CFile::begin); | 856 | m_File.Seek(m_ACK*m_blkSize,CFile::begin); |
856 | int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize); | 857 | int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize); |
857 | p->data.m_DATA.SetBlock(m_ACK+1); | 858 | p->data.m_DATA.SetBlock(m_ACK+1); |
858 | p->length=p->length-m_blkSize+bytes; | 859 | p->length=p->length-m_blkSize+bytes; |
859 | m_LastSlack = m_blkSize-bytes; | 860 | m_LastSlack = m_blkSize-bytes; |
860 | PostTFTP(p); | 861 | PostTFTP(p); |
861 | if(bytes<m_blkSize){ | 862 | if(bytes<m_blkSize){ |
862 | state=stateClosing; m_ACKtoClose = m_ACK+1; | 863 | state=stateClosing; m_ACKtoClose = m_ACK+1; |
863 | } | 864 | } |
864 | }CATCH(CFileException,e){ | 865 | }CATCH(CFileException,e){ |
865 | Deny(e); | 866 | Deny(e); |
866 | }END_CATCH | 867 | }END_CATCH |
867 | } | 868 | } |
868 | 869 | ||
869 | UINT tftp::tftpDATA::tftpSize(UINT blkSize) | 870 | UINT tftp::tftpDATA::tftpSize(UINT blkSize) |
870 | { | 871 | { |
871 | return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA) | 872 | return tftpHdrSize-tftpSlackSize+sizeof(tftp::tftpDATA) |
872 | -sizeof(BYTE)+blkSize; | 873 | -sizeof(BYTE)+blkSize; |
873 | } | 874 | } |
874 | 875 | ||
875 | void CXferSocket::Deny(CFileException* e) | 876 | void CXferSocket::Deny(CFileException* e) |
876 | { | 877 | { |
877 | PostError(e); | 878 | PostError(e); |
878 | state=stateDeny; | 879 | state=stateDeny; |
879 | } | 880 | } |
880 | 881 | ||
881 | void CXferSocket::PostError(UINT errCode,UINT errID) | 882 | void CXferSocket::PostError(UINT errCode,UINT errID) |
882 | { | 883 | { |
883 | CString msg; | 884 | CString msg; |
884 | msg.LoadString(errID); | 885 | msg.LoadString(errID); |
885 | ASSERT(m_Daddy); | 886 | ASSERT(m_Daddy); |
886 | CString tmp; | 887 | CString tmp; |
887 | tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg); | 888 | tmp.Format(IDS_LOG_SENTTFTPERROR,errCode,(LPCTSTR)msg); |
888 | m_Daddy->LogLine(tmp); | 889 | m_Daddy->LogLine(tmp); |
889 | tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg)); | 890 | tftp* err = tftp::Allocate(tftp::tftpERROR::tftpSize(msg)); |
890 | err->SetOpcode(tftp::opERROR); | 891 | err->SetOpcode(tftp::opERROR); |
891 | err->errSet(errCode,msg); | 892 | err->errSet(errCode,msg); |
892 | PostTFTP(err); | 893 | PostTFTP(err); |
893 | } | 894 | } |
894 | 895 | ||
895 | void CXferSocket::PostError(CFileException* e) | 896 | void CXferSocket::PostError(CFileException* e) |
896 | { | 897 | { |
897 | UINT eCode; | 898 | UINT eCode; |
898 | UINT eMsgID; | 899 | UINT eMsgID; |
899 | switch(e->m_cause){ | 900 | switch(e->m_cause){ |
900 | case CFileException::fileNotFound: | 901 | case CFileException::fileNotFound: |
901 | eCode=tftp::errNotFound; | 902 | eCode=tftp::errNotFound; |
902 | eMsgID=IDS_TFTP_ERROR_NOTFOUND; | 903 | eMsgID=IDS_TFTP_ERROR_NOTFOUND; |
903 | break; | 904 | break; |
904 | case CFileException::accessDenied: | 905 | case CFileException::accessDenied: |
905 | eCode=tftp::errAccessViolation; | 906 | eCode=tftp::errAccessViolation; |
906 | eMsgID=IDS_TFTP_ERROR_ACCESS; | 907 | eMsgID=IDS_TFTP_ERROR_ACCESS; |
907 | break; | 908 | break; |
908 | case CFileException::directoryFull: | 909 | case CFileException::directoryFull: |
909 | eCode=tftp::errDiskFull; | 910 | eCode=tftp::errDiskFull; |
910 | eMsgID=IDS_TFTP_ERROR_DIRFULL; | 911 | eMsgID=IDS_TFTP_ERROR_DIRFULL; |
911 | break; | 912 | break; |
912 | case CFileException::sharingViolation: | 913 | case CFileException::sharingViolation: |
913 | eCode=tftp::errAccessViolation; | 914 | eCode=tftp::errAccessViolation; |
914 | eMsgID=IDS_TFTP_ERROR_SHARING; | 915 | eMsgID=IDS_TFTP_ERROR_SHARING; |
915 | break; | 916 | break; |
916 | case CFileException::diskFull: | 917 | case CFileException::diskFull: |
917 | eCode=tftp::errDiskFull; | 918 | eCode=tftp::errDiskFull; |
918 | eMsgID=IDS_TFTP_ERROR_DISKFULL; | 919 | eMsgID=IDS_TFTP_ERROR_DISKFULL; |
919 | break; | 920 | break; |
920 | default: | 921 | default: |
921 | eCode=tftp::errUndefined; | 922 | eCode=tftp::errUndefined; |
922 | eMsgID=IDS_TFTP_ERROR_UNDEFINED; | 923 | eMsgID=IDS_TFTP_ERROR_UNDEFINED; |
923 | break; | 924 | break; |
924 | } | 925 | } |
925 | PostError(eCode,eMsgID); | 926 | PostError(eCode,eMsgID); |
926 | } | 927 | } |
927 | 928 | ||
928 | ULONG CRRQSocket::GetACK(void) | 929 | ULONG CRRQSocket::GetACK(void) |
929 | { | 930 | { |
930 | return (m_ACK*m_blkSize)-m_LastSlack; | 931 | return (m_ACK*m_blkSize)-m_LastSlack; |
931 | } | 932 | } |
932 | 933 | ||
933 | BOOL CRRQSocket::OnTFTP(tftp* p) | 934 | BOOL CRRQSocket::OnTFTP(tftp* p) |
934 | { | 935 | { |
935 | BOOL rv = TRUE; | 936 | BOOL rv = TRUE; |
936 | switch(p->Opcode()){ | 937 | switch(p->Opcode()){ |
937 | case tftp::opOACK: | 938 | case tftp::opOACK: |
938 | { | 939 | { |
939 | m_ACK=0; | 940 | m_ACK=0; |
940 | ASSERT(state!=stateFinish); | 941 | ASSERT(state!=stateFinish); |
941 | tftp::tftpOptions o; | 942 | tftp::tftpOptions o; |
942 | if(p->GetOptions(&o)){ | 943 | if(p->GetOptions(&o)){ |
943 | CString v; | 944 | CString v; |
944 | if(o.Lookup(tftpoBSize,v)){ | 945 | if(o.Lookup(tftpoBSize,v)){ |
945 | m_blkSize=atoi(v); | 946 | m_blkSize=atoi(v); |
946 | if(!m_blkSize){// *** More sanity checks | 947 | if(!m_blkSize){// *** More sanity checks |
947 | Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); | 948 | Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); |
948 | rv = TRUE; | 949 | rv = TRUE; |
949 | break; | 950 | break; |
950 | } | 951 | } |
951 | } | 952 | } |
952 | if(o.Lookup(tftpoTOut,v)){ | 953 | if(o.Lookup(tftpoTOut,v)){ |
953 | m_timeOut=atoi(v); | 954 | m_timeOut=atoi(v); |
954 | if(!m_timeOut){// *** More sanity checks | 955 | if(!m_timeOut){// *** More sanity checks |
955 | Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); | 956 | Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); |
956 | rv = TRUE; | 957 | rv = TRUE; |
957 | break; | 958 | break; |
958 | } | 959 | } |
959 | } | 960 | } |
960 | if(o.Lookup(tftpoXResume,v)){ | 961 | if(o.Lookup(tftpoXResume,v)){ |
961 | m_ACK=atoi(v); | 962 | m_ACK=atoi(v); |
962 | } | 963 | } |
963 | } | 964 | } |
964 | UpdateList(); | 965 | UpdateList(); |
965 | DoXfer(); | 966 | DoXfer(); |
966 | } | 967 | } |
967 | break; | 968 | break; |
968 | case tftp::opACK: | 969 | case tftp::opACK: |
969 | m_ACK=p->data.m_ACK.Block(); | 970 | m_ACK=p->data.m_ACK.Block(); |
970 | if(state==stateClosing && m_ACK==m_ACKtoClose) { | 971 | if(state==stateClosing && m_ACK==m_ACKtoClose) { |
971 | state = stateFinish; | 972 | state = stateFinish; |
972 | ASSERT(m_Daddy); | 973 | ASSERT(m_Daddy); |
973 | CString tmp; | 974 | CString tmp; |
974 | tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName); | 975 | tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName); |
975 | m_Daddy->LogLine(tmp); | 976 | m_Daddy->LogLine(tmp); |
976 | rv = FALSE; | 977 | rv = FALSE; |
977 | DoSelect(TRUE); | 978 | DoSelect(TRUE); |
978 | }else if(state!=stateFinish){ | 979 | }else if(state!=stateFinish){ |
979 | UpdateList(); | 980 | UpdateList(); |
980 | DoXfer(); | 981 | DoXfer(); |
981 | } | 982 | } |
982 | break; | 983 | break; |
983 | case tftp::opERROR: | 984 | case tftp::opERROR: |
984 | { | 985 | { |
985 | ASSERT(m_Daddy); | 986 | ASSERT(m_Daddy); |
986 | CString tmp; | 987 | CString tmp; |
987 | tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage()); | 988 | tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage()); |
988 | m_Daddy->LogLine(tmp); | 989 | m_Daddy->LogLine(tmp); |
989 | } | 990 | } |
990 | Destroy(FALSE); | 991 | Destroy(FALSE); |
991 | rv = FALSE; | 992 | rv = FALSE; |
992 | break; | 993 | break; |
993 | default: | 994 | default: |
994 | { | 995 | { |
995 | ASSERT(m_Daddy); | 996 | ASSERT(m_Daddy); |
996 | CString tmp; | 997 | CString tmp; |
997 | tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode()); | 998 | tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode()); |
998 | m_Daddy->LogLine(tmp); | 999 | m_Daddy->LogLine(tmp); |
999 | // *** Self destruct maybe?? | 1000 | // *** Self destruct maybe?? |
1000 | } | 1001 | } |
1001 | break; | 1002 | break; |
1002 | } | 1003 | } |
1003 | return rv; | 1004 | return rv; |
1004 | } | 1005 | } |
1005 | 1006 | ||
1006 | BOOL CWRQSocket::OnTFTP(tftp* p) | 1007 | BOOL CWRQSocket::OnTFTP(tftp* p) |
1007 | { | 1008 | { |
1008 | switch(p->Opcode()){ | 1009 | switch(p->Opcode()){ |
1009 | case tftp::opOACK: | 1010 | case tftp::opOACK: |
1010 | ASSERT(state!=stateFinish); | 1011 | ASSERT(state!=stateFinish); |
1011 | { | 1012 | { |
1012 | if(m_bResume) | 1013 | if(m_bResume) |
1013 | m_ACK=m_File.GetLength()/m_blkSize; | 1014 | m_ACK=m_File.GetLength()/m_blkSize; |
1014 | else | 1015 | else |
1015 | m_ACK=0; | 1016 | m_ACK=0; |
1016 | tftp::tftpOptions o; | 1017 | tftp::tftpOptions o; |
1017 | if(p->GetOptions(&o)){ | 1018 | if(p->GetOptions(&o)){ |
1018 | CString v; | 1019 | CString v; |
1019 | if(o.Lookup(tftpoBSize,v)){ | 1020 | if(o.Lookup(tftpoBSize,v)){ |
1020 | m_blkSize=atoi(v); | 1021 | m_blkSize=atoi(v); |
1021 | if(!m_blkSize){// *** More sanity checks | 1022 | if(!m_blkSize){// *** More sanity checks |
1022 | Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); | 1023 | Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); |
1023 | return TRUE; | 1024 | return TRUE; |
1024 | } | 1025 | } |
1025 | } | 1026 | } |
1026 | if(o.Lookup(tftpoTOut,v)){ | 1027 | if(o.Lookup(tftpoTOut,v)){ |
1027 | m_timeOut=atoi(v); | 1028 | m_timeOut=atoi(v); |
1028 | if(!m_timeOut){// *** More sanity checks | 1029 | if(!m_timeOut){// *** More sanity checks |
1029 | Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); | 1030 | Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); |
1030 | return TRUE; | 1031 | return TRUE; |
1031 | } | 1032 | } |
1032 | } | 1033 | } |
1033 | if(o.Lookup(tftpoTSize,v)){ | 1034 | if(o.Lookup(tftpoTSize,v)){ |
1034 | m_xferSize=atoi(v); | 1035 | m_xferSize=atoi(v); |
1035 | } | 1036 | } |
1036 | if(m_xferSize>=0 && m_xferSize>=(m_blkSize<<16)) { | 1037 | if(m_xferSize>=0 && m_xferSize>=(m_blkSize<<16)) { |
1037 | Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG); | 1038 | Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG); |
1038 | return TRUE; | 1039 | return TRUE; |
1039 | } | 1040 | } |
1040 | } | 1041 | } |
1041 | UpdateList(); | 1042 | UpdateList(); |
1042 | DoXfer(); | 1043 | DoXfer(); |
1043 | } | 1044 | } |
1044 | break; | 1045 | break; |
1045 | case tftp::opDATA: | 1046 | case tftp::opDATA: |
1046 | { | 1047 | { |
1047 | UINTblock = p->data.m_DATA.Block(); | 1048 | UINTblock = p->data.m_DATA.Block(); |
1048 | TRY{ | 1049 | TRY{ |
1049 | m_File.Seek((block-1)*m_blkSize,CFile::begin); | 1050 | m_File.Seek((block-1)*m_blkSize,CFile::begin); |
1050 | int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize); | 1051 | int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize); |
1051 | if(bytes){ | 1052 | if(bytes){ |
1052 | m_File.Write(p->data.m_DATA.data,bytes); | 1053 | m_File.Write(p->data.m_DATA.data,bytes); |
1053 | // *** Move to the other place where we can do it not that often | 1054 | // *** Move to the other place where we can do it not that often |
1054 | m_File.SetLength(m_File.GetPosition()); | 1055 | m_File.SetLength(m_File.GetPosition()); |
1055 | } | 1056 | } |
1056 | if(bytes<m_blkSize){ | 1057 | if(bytes<m_blkSize){ |
1057 | state=stateFinish; | 1058 | state=stateFinish; |
1058 | ASSERT(m_Daddy); | 1059 | ASSERT(m_Daddy); |
1059 | CString tmp; | 1060 | CString tmp; |
1060 | tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName); | 1061 | tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName); |
1061 | m_Daddy->LogLine(tmp); | 1062 | m_Daddy->LogLine(tmp); |
1062 | } | 1063 | } |
1063 | m_ACK=block; | 1064 | m_ACK=block; |
1064 | m_LastSlack=m_blkSize-bytes; | 1065 | m_LastSlack=m_blkSize-bytes; |
1065 | UpdateList(); | 1066 | UpdateList(); |
1066 | DoXfer(); | 1067 | DoXfer(); |
1067 | }CATCH(CFileException,e){ | 1068 | }CATCH(CFileException,e){ |
1068 | Deny(e); | 1069 | Deny(e); |
1069 | }END_CATCH | 1070 | }END_CATCH |
1070 | } | 1071 | } |
1071 | break; | 1072 | break; |
1072 | case tftp::opERROR: | 1073 | case tftp::opERROR: |
1073 | { | 1074 | { |
1074 | ASSERT(m_Daddy); | 1075 | ASSERT(m_Daddy); |
1075 | CString tmp; | 1076 | CString tmp; |
1076 | tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage()); | 1077 | tmp.Format(IDS_LOG_GOTTFTPERROR,p->data.m_ERROR.Code(),(LPCTSTR)p->errMessage()); |
1077 | m_Daddy->LogLine(tmp); | 1078 | m_Daddy->LogLine(tmp); |
1078 | } | 1079 | } |
1079 | Destroy(FALSE); | 1080 | Destroy(FALSE); |
1080 | return FALSE; | 1081 | return FALSE; |
1081 | default: | 1082 | default: |
1082 | { | 1083 | { |
1083 | ASSERT(m_Daddy); | 1084 | ASSERT(m_Daddy); |
1084 | CString tmp; | 1085 | CString tmp; |
1085 | tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode()); | 1086 | tmp.Format(IDS_LOG_XFEROPCODE,p->Opcode()); |
1086 | m_Daddy->LogLine(tmp); | 1087 | m_Daddy->LogLine(tmp); |
1087 | // *** Self destruct maybe?? | 1088 | // *** Self destruct maybe?? |
1088 | } | 1089 | } |
1089 | break; | 1090 | break; |
1090 | } | 1091 | } |
1091 | return TRUE; | 1092 | return TRUE; |
1092 | } | 1093 | } |
1093 | 1094 | ||
1094 | void tftp::SetOpcode(WORD op) | 1095 | void tftp::SetOpcode(WORD op) |
1095 | { | 1096 | { |
1096 | opcode = REVERSEBYTES(op); | 1097 | opcode = REVERSEBYTES(op); |
1097 | } | 1098 | } |
1098 | void tftp::tftpDATA::SetBlock(WORD b) | 1099 | void tftp::tftpDATA::SetBlock(WORD b) |
1099 | { | 1100 | { |
1100 | block=REVERSEBYTES(b); | 1101 | block=REVERSEBYTES(b); |
1101 | } | 1102 | } |
1102 | WORD tftp::tftpDATA::Block() | 1103 | WORD tftp::tftpDATA::Block() |
1103 | { | 1104 | { |
1104 | return REVERSEBYTES(block); | 1105 | return REVERSEBYTES(block); |
1105 | } | 1106 | } |
1106 | WORD tftp::tftpACK::Block() | 1107 | WORD tftp::tftpACK::Block() |
1107 | { | 1108 | { |
1108 | return REVERSEBYTES(block); | 1109 | return REVERSEBYTES(block); |
1109 | } | 1110 | } |
1110 | void tftp::tftpACK::SetBlock(WORD b) | 1111 | void tftp::tftpACK::SetBlock(WORD b) |
1111 | { | 1112 | { |
1112 | block = REVERSEBYTES(b); | 1113 | block = REVERSEBYTES(b); |
1113 | } | 1114 | } |
1114 | WORD tftp::tftpERROR::Code() | 1115 | WORD tftp::tftpERROR::Code() |
1115 | { | 1116 | { |