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