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