author | Michael Krelin <hacker@klever.net> | 2004-07-05 01:53:09 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2004-07-05 01:53:09 (UTC) |
commit | 9938ea772d372ba955b7bc1f1c48a062c3a36f8a (patch) (unidiff) | |
tree | a98185df944e3a763f9557aa74bc2837b343f048 /PumpKINDlg.h | |
download | pumpkin-9938ea772d372ba955b7bc1f1c48a062c3a36f8a.zip pumpkin-9938ea772d372ba955b7bc1f1c48a062c3a36f8a.tar.gz pumpkin-9938ea772d372ba955b7bc1f1c48a062c3a36f8a.tar.bz2 |
initial commit into svn repository
git-svn-id: http://svn.klever.net/kin/pumpkin/trunk@1 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | PumpKINDlg.h | 327 |
1 files changed, 327 insertions, 0 deletions
diff --git a/PumpKINDlg.h b/PumpKINDlg.h new file mode 100644 index 0000000..42ae62d --- a/dev/null +++ b/PumpKINDlg.h | |||
@@ -0,0 +1,327 @@ | |||
1 | // PumpKINDlg.h : header file | ||
2 | // | ||
3 | |||
4 | //#define REVERSEBYTES(w)MAKEWORD(HIBYTE(w),LOBYTE(w)); | ||
5 | #defineREVERSEBYTES(w) (htons((WORD)w)) | ||
6 | #define tftpoBSize"blksize" | ||
7 | #define tftpoTSize"tsize" | ||
8 | #define tftpoTOut"timeout" | ||
9 | |||
10 | #define tftpoXResume"x-resume" | ||
11 | |||
12 | struct tftp{ | ||
13 | typedef CMapStringToString tftpOptions; | ||
14 | typedef WORD tftpLength; | ||
15 | typedef WORD tftpOpcode; | ||
16 | tftpLengthlength; | ||
17 | tftpOpcode opcode; | ||
18 | enum{ | ||
19 | opRRQ = 1, | ||
20 | opWRQ = 2, | ||
21 | opDATA = 3, | ||
22 | opACK = 4, | ||
23 | opERROR = 5, | ||
24 | opOACK = 6, | ||
25 | |||
26 | errUndefined = 0, | ||
27 | errNotFound = 1, | ||
28 | errAccessViolation = 2, | ||
29 | errDiskFull = 3, | ||
30 | errIllegalOp = 4, | ||
31 | errUnknownTID = 5, | ||
32 | errFileExists = 6, | ||
33 | errNoUser = 7, | ||
34 | errOption = 8 | ||
35 | }; | ||
36 | structtftpUNKNOWN { | ||
37 | BYTE data[1]; | ||
38 | }; | ||
39 | structtftpRQ { | ||
40 | BYTE data[1]; | ||
41 | public: | ||
42 | void Set(LPCTSTR file,LPCTSTR type,tftpOptions* ops=NULL); | ||
43 | static UINT tftpSize(LPCTSTR file,LPCTSTR type,tftpOptions* ops=NULL); | ||
44 | }; | ||
45 | structtftpRRQ { | ||
46 | BYTE data[1]; | ||
47 | public: | ||
48 | void Set(LPCTSTR file,LPCTSTR type,tftpOptions* ops=NULL); | ||
49 | static UINT tftpSize(LPCTSTR file,LPCTSTR type,tftpOptions* ops=NULL); | ||
50 | }; | ||
51 | structtftpWRQ { | ||
52 | BYTE data[1]; | ||
53 | public: | ||
54 | void Set(LPCTSTR file,LPCTSTR type,tftpOptions* ops=NULL); | ||
55 | static UINT tftpSize(LPCTSTR file,LPCTSTR type,tftpOptions* ops=NULL); | ||
56 | }; | ||
57 | structtftpDATA { | ||
58 | WORD block; | ||
59 | BYTE data[1]; | ||
60 | public: | ||
61 | WORD Block(); | ||
62 | void SetBlock(WORD b); | ||
63 | static UINT tftpSize(UINT blkSize=512); | ||
64 | }; | ||
65 | struct tftpACK { | ||
66 | WORD block; | ||
67 | public: | ||
68 | static UINT tftpSize(); | ||
69 | void SetBlock(WORD b); | ||
70 | WORD Block(); | ||
71 | }; | ||
72 | structtftpERROR { | ||
73 | typedef WORD tftpErrorCode; | ||
74 | tftpErrorCode code; | ||
75 | BYTE data[1]; | ||
76 | public: | ||
77 | void SetCode(WORD c); | ||
78 | WORD Code(); | ||
79 | static UINT tftpSize(LPCTSTR msg); | ||
80 | }; | ||
81 | struct tftpOACK { | ||
82 | BYTE data[1]; | ||
83 | public: | ||
84 | void Set(tftpOptions* ops); | ||
85 | static UINT tftpSize(tftpOptions* ops); | ||
86 | }; | ||
87 | uniontftpPacket { | ||
88 | tftpUNKNOWN m_UNKNOWN; | ||
89 | tftpRQ m_RQ; | ||
90 | tftpRRQ m_RRQ; | ||
91 | tftpWRQ m_WRQ; | ||
92 | tftpDATA m_DATA; | ||
93 | tftpACK m_ACK; | ||
94 | tftpERROR m_ERROR; | ||
95 | tftpOACK m_OACK; | ||
96 | }data; | ||
97 | |||
98 | void *udpBase(void){ return &opcode; } | ||
99 | public: | ||
100 | static tftp* Copy(tftp *src); | ||
101 | CString errMessage(); | ||
102 | void SetOpcode(WORD op); | ||
103 | void errSet(UINT code,LPCTSTR msg); | ||
104 | static tftp* Allocate(UINT tftpSize=0); | ||
105 | BOOL Send(CAsyncSocket *socket,SOCKADDR_IN* saddr); | ||
106 | CString rqType(); | ||
107 | CString rqFileName(); | ||
108 | UINT GetOptions(tftpOptions* ops); | ||
109 | tftp(); | ||
110 | UINT Opcode(); | ||
111 | BOOL Receive(CAsyncSocket* socket,UINT maxLength,SOCKADDR_IN *sin=NULL); | ||
112 | }; | ||
113 | #define tftpHdrSize(sizeof(tftp)-sizeof(tftp::tftpPacket)) | ||
114 | #definetftpSlackSize sizeof(tftp::tftpLength) | ||
115 | |||
116 | class CPumpKINDlg; | ||
117 | class CListenSocket : public CAsyncSocket{ | ||
118 | public: | ||
119 | virtual void OnReceive(int nErrorCode); | ||
120 | CPumpKINDlg* m_Daddy; | ||
121 | }; | ||
122 | |||
123 | typedef CList<tftp*,tftp*>CTFTPList; | ||
124 | class CResolver; | ||
125 | class CXferSocket : public CAsyncSocket{ | ||
126 | public: | ||
127 | UINT m__timeOut; | ||
128 | UINT m__blkSize; | ||
129 | tftp::tftpOptions m_Options; | ||
130 | LONG m_xferSize; | ||
131 | UINT m_timeOut; | ||
132 | UINT m_blkSize; | ||
133 | BOOL m_bRetry; | ||
134 | void SetTry(tftp *p=NULL); | ||
135 | tftp* m_Retry; | ||
136 | void OnRetry(); | ||
137 | BOOL CheckBadRelativeness(LPCTSTR file); | ||
138 | CString ApplyRootGently(LPCTSTR fn); | ||
139 | CString m_HostName; | ||
140 | virtual void OnResolved(); | ||
141 | virtual void OnFailedToResolve(); | ||
142 | CResolver *m_wndResolver; | ||
143 | BYTE m_ResolveBuff[MAXGETHOSTSTRUCT]; | ||
144 | virtual void Abort(); | ||
145 | void ResetTimeout(); | ||
146 | enum{ | ||
147 | stateNone, stateDeny, stateInit, stateOACK, stateXfer, stateFinish, stateClosing | ||
148 | }; | ||
149 | int state; | ||
150 | void Deny(UINT errCode,UINT errID); | ||
151 | void Deny(CFileException* e); | ||
152 | CString ApplyRoot(LPCTSTR fileName); | ||
153 | void TurnSlashes(CString& fn,BOOL bBack=TRUE); | ||
154 | virtual void Destroy(BOOL success=TRUE); | ||
155 | void PostError(CFileException* e); | ||
156 | void PostError(UINT errCode,UINT errID); | ||
157 | void PostTFTP(tftp* p,BOOL retryable=FALSE); | ||
158 | CXferSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN* sin); | ||
159 | CFile m_File; | ||
160 | virtual ULONG GetACK(); | ||
161 | CString m_Type; | ||
162 | CString m_FileName; | ||
163 | CXferSocket(); | ||
164 | void UpdateList(); | ||
165 | void SetPeer(SOCKADDR_IN *sin); | ||
166 | virtual BOOL OnTFTP(tftp* p) = 0; | ||
167 | virtual void OnReceive(int nErrorCode); | ||
168 | void DoSelect(); | ||
169 | SOCKADDR_IN m_Peer; | ||
170 | virtual void OnSend(int nErrorCode); | ||
171 | CPumpKINDlg* m_Daddy; | ||
172 | CTFTPList m_Queue; | ||
173 | |||
174 | DECLARE_DYNAMIC(CXferSocket) | ||
175 | }; | ||
176 | class CWRQSocket : public CXferSocket { | ||
177 | public: | ||
178 | BOOL m_bResume; | ||
179 | void OnHostKnown(); | ||
180 | virtual void OnResolved(); | ||
181 | UINT m_LastSlack; | ||
182 | ULONG GetACK(); | ||
183 | void DoXfer(); | ||
184 | UINT m_ACK; | ||
185 | BOOL SaveAs(CString& fn); | ||
186 | BOOL RenameFile(CString& fn); | ||
187 | BOOL m_Rename; | ||
188 | BOOL ConfirmRequest(); | ||
189 | BOOL Create(LPCTSTR localFile=NULL,LPCTSTR hostName=NULL); | ||
190 | CWRQSocket(CPumpKINDlg* daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin); | ||
191 | BOOL OnTFTP(tftp* p); | ||
192 | |||
193 | DECLARE_DYNAMIC(CWRQSocket) | ||
194 | }; | ||
195 | class CRRQSocket : public CXferSocket { | ||
196 | public: | ||
197 | void OnHostKnown(); | ||
198 | virtual void OnResolved(); | ||
199 | BOOL ConfirmRequest(); | ||
200 | WORD m_LastSlack; | ||
201 | UINT m_ACK; | ||
202 | BOOL OnTFTP(tftp* p); | ||
203 | ULONG GetACK(void); | ||
204 | void DoXfer(); | ||
205 | CRRQSocket(CPumpKINDlg *daddy,LPCTSTR fileName,LPCTSTR type,SOCKADDR_IN *sin); | ||
206 | BOOL Create(LPCTSTR localFile=NULL,LPCTSTR hostName=NULL); | ||
207 | |||
208 | DECLARE_DYNAMIC(CRRQSocket) | ||
209 | }; | ||
210 | |||
211 | typedef CMap<SOCKET,SOCKET,CXferSocket*,CXferSocket*>CTIDMap; | ||
212 | typedef CMap<CTime*,CTime*,CTime*,CTime*> CTimeMap; | ||
213 | |||
214 | ///////////////////////////////////////////////////////////////////////////// | ||
215 | // CPumpKINDlg dialog | ||
216 | |||
217 | class CTrayer; | ||
218 | class CRetrier; | ||
219 | class CPumpKINDlg : public CDialog | ||
220 | { | ||
221 | // Construction | ||
222 | public: | ||
223 | CString m_bnwRequest; | ||
224 | CString m_bnwSuccess; | ||
225 | CString m_bnwAbort; | ||
226 | CBellsNWhistles m_bnw; | ||
227 | CTrayer *m_Trayer; | ||
228 | CTimeSpan m_RetryTimeOut; | ||
229 | virtual ~CPumpKINDlg(); | ||
230 | CRetrier* m_Retrier; | ||
231 | virtual BOOL PreTranslateMessage(MSG* pMsg); | ||
232 | BOOL m_bShown; | ||
233 | BOOL m_bExiting; | ||
234 | void SaveSettings(); | ||
235 | void LoadSettings(); | ||
236 | void SetupButtons(); | ||
237 | BITMAP m_bitmapBack; | ||
238 | CBitmap m_bmpBack; | ||
239 | UINT m_PromptTimeOut; | ||
240 | UINT m_SpeakPort; | ||
241 | void LogLine(UINT msgID); | ||
242 | CTimeMap m_LogTimes; | ||
243 | void LogLine(LPCTSTR str); | ||
244 | int m_LogLength; | ||
245 | enum{ | ||
246 | subitemFile=0, subitemType, subitemPeer, subitemBytes, subitemTSize | ||
247 | }; | ||
248 | int m_iWRQ; | ||
249 | int m_iRRQ; | ||
250 | CImageList m_Images; | ||
251 | CTIDMap m_Xfers; | ||
252 | CTimeSpan m_TFTPTimeOut; | ||
253 | enum{ | ||
254 | rrqGiveAll=0, | ||
255 | rrqAlwaysConfirm, | ||
256 | rrqDenyAll | ||
257 | }; | ||
258 | enum{ | ||
259 | wrqTakeAll=0, | ||
260 | wrqConfirmIfExists, | ||
261 | wrqAlwaysConfirm, | ||
262 | wrqDenyAll | ||
263 | }; | ||
264 | UINT m_RRQMode; | ||
265 | UINT m_WRQMode; | ||
266 | BOOL m_bTFTPSubdirs; | ||
267 | CString m_TFTPRoot; | ||
268 | UINT m_ListenPort; | ||
269 | UINT m_BlockSize; | ||
270 | CListenSocket m_Listener; | ||
271 | CPumpKINDlg(CWnd* pParent = NULL);// standard constructor | ||
272 | |||
273 | // Dialog Data | ||
274 | //{{AFX_DATA(CPumpKINDlg) | ||
275 | enum { IDD = IDD_PUMPKIN_DIALOG }; | ||
276 | CButtonm_AbortCtl; | ||
277 | CButtonm_OptionsCtl; | ||
278 | CListBoxm_Log; | ||
279 | CListCtrlm_List; | ||
280 | //}}AFX_DATA | ||
281 | |||
282 | // ClassWizard generated virtual function overrides | ||
283 | //{{AFX_VIRTUAL(CPumpKINDlg) | ||
284 | protected: | ||
285 | virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV support | ||
286 | //}}AFX_VIRTUAL | ||
287 | |||
288 | // Implementation | ||
289 | protected: | ||
290 | CToolTipCtrl m_tooltip; | ||
291 | HICON m_hIcon; | ||
292 | |||
293 | // Generated message map functions | ||
294 | //{{AFX_MSG(CPumpKINDlg) | ||
295 | virtual BOOL OnInitDialog(); | ||
296 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); | ||
297 | afx_msg void OnDestroy(); | ||
298 | afx_msg void OnPaint(); | ||
299 | afx_msg HCURSOR OnQueryDragIcon(); | ||
300 | afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); | ||
301 | afx_msg void OnOptions(); | ||
302 | afx_msg void OnTimer(UINT nIDEvent); | ||
303 | afx_msg void OnExit(); | ||
304 | afx_msg void OnPut(); | ||
305 | afx_msg void OnGet(); | ||
306 | afx_msg void OnDeleteallitemsConnections(NMHDR* pNMHDR, LRESULT* pResult); | ||
307 | afx_msg void OnDeleteitemConnections(NMHDR* pNMHDR, LRESULT* pResult); | ||
308 | afx_msg void OnInsertitemConnections(NMHDR* pNMHDR, LRESULT* pResult); | ||
309 | afx_msg void OnItemchangedConnections(NMHDR* pNMHDR, LRESULT* pResult); | ||
310 | afx_msg void OnAbort(); | ||
311 | afx_msg void OnClose(); | ||
312 | afx_msg void OnTrayShowpumpkinwindow(); | ||
313 | afx_msg void OnTrayExit(); | ||
314 | afx_msg void OnTrayAboutpumpkin(); | ||
315 | afx_msg void OnTrayFetchfile(); | ||
316 | afx_msg void OnTrayHelp(); | ||
317 | afx_msg void OnTrayOptions(); | ||
318 | afx_msg void OnTraySendfile(); | ||
319 | afx_msg void OnWindowPosChanging(WINDOWPOS FAR* lpwndpos); | ||
320 | afx_msg void OnSelchangeLog(); | ||
321 | afx_msg void OnTrayOpenfilesfolder(); | ||
322 | afx_msg void OnDropFiles(HDROP hDropInfo); | ||
323 | virtual void OnCancel(); | ||
324 | afx_msg void OnHelp(); | ||
325 | //}}AFX_MSG | ||
326 | DECLARE_MESSAGE_MAP() | ||
327 | }; | ||