Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
FTPRequestHandler.h@0:61dbbee3f903, 2011-06-19 (annotated)
- Committer:
- Phlaphead
- Date:
- Sun Jun 19 13:59:16 2011 +0000
- Revision:
- 0:61dbbee3f903
- Child:
- 1:f5789613b955
Initial revision.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Phlaphead | 0:61dbbee3f903 | 1 | |
| Phlaphead | 0:61dbbee3f903 | 2 | /* |
| Phlaphead | 0:61dbbee3f903 | 3 | Copyright (c) 2011 Robert Ellis (holistic [at] robellis [dot] org [dot] uk) |
| Phlaphead | 0:61dbbee3f903 | 4 | |
| Phlaphead | 0:61dbbee3f903 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| Phlaphead | 0:61dbbee3f903 | 6 | of this software and associated documentation files (the "Software"), to deal |
| Phlaphead | 0:61dbbee3f903 | 7 | in the Software without restriction, including without limitation the rights |
| Phlaphead | 0:61dbbee3f903 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| Phlaphead | 0:61dbbee3f903 | 9 | copies of the Software, and to permit persons to whom the Software is |
| Phlaphead | 0:61dbbee3f903 | 10 | furnished to do so, subject to the following conditions: |
| Phlaphead | 0:61dbbee3f903 | 11 | |
| Phlaphead | 0:61dbbee3f903 | 12 | The above copyright notice and this permission notice shall be included in |
| Phlaphead | 0:61dbbee3f903 | 13 | all copies or substantial portions of the Software. |
| Phlaphead | 0:61dbbee3f903 | 14 | |
| Phlaphead | 0:61dbbee3f903 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| Phlaphead | 0:61dbbee3f903 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| Phlaphead | 0:61dbbee3f903 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| Phlaphead | 0:61dbbee3f903 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| Phlaphead | 0:61dbbee3f903 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| Phlaphead | 0:61dbbee3f903 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| Phlaphead | 0:61dbbee3f903 | 21 | THE SOFTWARE. |
| Phlaphead | 0:61dbbee3f903 | 22 | */ |
| Phlaphead | 0:61dbbee3f903 | 23 | |
| Phlaphead | 0:61dbbee3f903 | 24 | #ifndef FTP_REQUEST_HANDLER_H |
| Phlaphead | 0:61dbbee3f903 | 25 | #define FTP_REQUEST_HANDLER_H |
| Phlaphead | 0:61dbbee3f903 | 26 | |
| Phlaphead | 0:61dbbee3f903 | 27 | |
| Phlaphead | 0:61dbbee3f903 | 28 | #include "FTPServer.h" |
| Phlaphead | 0:61dbbee3f903 | 29 | #include "FileSystemInterface.h" |
| Phlaphead | 0:61dbbee3f903 | 30 | #include "core/netservice.h" |
| Phlaphead | 0:61dbbee3f903 | 31 | |
| Phlaphead | 0:61dbbee3f903 | 32 | #include "mbed.h" |
| Phlaphead | 0:61dbbee3f903 | 33 | |
| Phlaphead | 0:61dbbee3f903 | 34 | #define FTP_REQUEST_TIMEOUT 300000 |
| Phlaphead | 0:61dbbee3f903 | 35 | #define REQUEST_BUFFER_LENGTH 128 |
| Phlaphead | 0:61dbbee3f903 | 36 | #define START_DIRECTORY "/" |
| Phlaphead | 0:61dbbee3f903 | 37 | |
| Phlaphead | 0:61dbbee3f903 | 38 | #include <string> |
| Phlaphead | 0:61dbbee3f903 | 39 | using std::string; |
| Phlaphead | 0:61dbbee3f903 | 40 | |
| Phlaphead | 0:61dbbee3f903 | 41 | |
| Phlaphead | 0:61dbbee3f903 | 42 | /** |
| Phlaphead | 0:61dbbee3f903 | 43 | * Enumeration of FTP command which require state to be remembered. |
| Phlaphead | 0:61dbbee3f903 | 44 | */ |
| Phlaphead | 0:61dbbee3f903 | 45 | enum FtpCommand |
| Phlaphead | 0:61dbbee3f903 | 46 | { |
| Phlaphead | 0:61dbbee3f903 | 47 | NOOP, |
| Phlaphead | 0:61dbbee3f903 | 48 | MLSD |
| Phlaphead | 0:61dbbee3f903 | 49 | }; |
| Phlaphead | 0:61dbbee3f903 | 50 | |
| Phlaphead | 0:61dbbee3f903 | 51 | |
| Phlaphead | 0:61dbbee3f903 | 52 | /** |
| Phlaphead | 0:61dbbee3f903 | 53 | * Handles FTP commands comming from a client. |
| Phlaphead | 0:61dbbee3f903 | 54 | */ |
| Phlaphead | 0:61dbbee3f903 | 55 | class FTPRequestHandler : public NetService |
| Phlaphead | 0:61dbbee3f903 | 56 | { |
| Phlaphead | 0:61dbbee3f903 | 57 | public: |
| Phlaphead | 0:61dbbee3f903 | 58 | |
| Phlaphead | 0:61dbbee3f903 | 59 | FTPRequestHandler(FTPServer* pSvr, Host* pCommandClient, TCPSocket* pCommandSocket); |
| Phlaphead | 0:61dbbee3f903 | 60 | virtual ~FTPRequestHandler(); |
| Phlaphead | 0:61dbbee3f903 | 61 | |
| Phlaphead | 0:61dbbee3f903 | 62 | void acceptDataSocket(TCPSocket* pDataSocket); |
| Phlaphead | 0:61dbbee3f903 | 63 | |
| Phlaphead | 0:61dbbee3f903 | 64 | private: |
| Phlaphead | 0:61dbbee3f903 | 65 | |
| Phlaphead | 0:61dbbee3f903 | 66 | void acceptCommandSocket(TCPSocket* pCommandSocket); |
| Phlaphead | 0:61dbbee3f903 | 67 | void close(); |
| Phlaphead | 0:61dbbee3f903 | 68 | bool openDataSocket(); |
| Phlaphead | 0:61dbbee3f903 | 69 | void closeDataSocket(); |
| Phlaphead | 0:61dbbee3f903 | 70 | |
| Phlaphead | 0:61dbbee3f903 | 71 | void onCommandSocketEvent(TCPSocketEvent e); |
| Phlaphead | 0:61dbbee3f903 | 72 | void onDataSocketEvent(TCPSocketEvent e); |
| Phlaphead | 0:61dbbee3f903 | 73 | void onTimeout(); |
| Phlaphead | 0:61dbbee3f903 | 74 | |
| Phlaphead | 0:61dbbee3f903 | 75 | void sendReply(int replyCode, const char* format, ...); |
| Phlaphead | 0:61dbbee3f903 | 76 | void sendReply(const char* format, ...); |
| Phlaphead | 0:61dbbee3f903 | 77 | void sendData(const char* data, int length); |
| Phlaphead | 0:61dbbee3f903 | 78 | |
| Phlaphead | 0:61dbbee3f903 | 79 | int getRequest(); |
| Phlaphead | 0:61dbbee3f903 | 80 | void handleRequest(); |
| Phlaphead | 0:61dbbee3f903 | 81 | void handleResponse(); |
| Phlaphead | 0:61dbbee3f903 | 82 | |
| Phlaphead | 0:61dbbee3f903 | 83 | bool isAuthenticated(); |
| Phlaphead | 0:61dbbee3f903 | 84 | void sendSyntaxError(); |
| Phlaphead | 0:61dbbee3f903 | 85 | |
| Phlaphead | 0:61dbbee3f903 | 86 | |
| Phlaphead | 0:61dbbee3f903 | 87 | void cmdUser(const string& username); |
| Phlaphead | 0:61dbbee3f903 | 88 | void cmdPass(const string& password); |
| Phlaphead | 0:61dbbee3f903 | 89 | void cmdQuit(); |
| Phlaphead | 0:61dbbee3f903 | 90 | |
| Phlaphead | 0:61dbbee3f903 | 91 | void cmdFeat(); |
| Phlaphead | 0:61dbbee3f903 | 92 | |
| Phlaphead | 0:61dbbee3f903 | 93 | void cmdPort(const string& ip_port); |
| Phlaphead | 0:61dbbee3f903 | 94 | void cmdPasv(); |
| Phlaphead | 0:61dbbee3f903 | 95 | void cmdType(const string& type, const string& arg); |
| Phlaphead | 0:61dbbee3f903 | 96 | |
| Phlaphead | 0:61dbbee3f903 | 97 | void cmdPwd(); |
| Phlaphead | 0:61dbbee3f903 | 98 | void cmdCwd(const string& dir); |
| Phlaphead | 0:61dbbee3f903 | 99 | void cmdCdup(); |
| Phlaphead | 0:61dbbee3f903 | 100 | void cmdList(); |
| Phlaphead | 0:61dbbee3f903 | 101 | void cmdMlsd(); |
| Phlaphead | 0:61dbbee3f903 | 102 | |
| Phlaphead | 0:61dbbee3f903 | 103 | |
| Phlaphead | 0:61dbbee3f903 | 104 | |
| Phlaphead | 0:61dbbee3f903 | 105 | FTPServer* m_pSvr; |
| Phlaphead | 0:61dbbee3f903 | 106 | Host* m_pCommandClient; |
| Phlaphead | 0:61dbbee3f903 | 107 | Host* m_pDataClient; |
| Phlaphead | 0:61dbbee3f903 | 108 | TCPSocket* m_pCommandSocket; |
| Phlaphead | 0:61dbbee3f903 | 109 | TCPSocket* m_pDataSocket; |
| Phlaphead | 0:61dbbee3f903 | 110 | |
| Phlaphead | 0:61dbbee3f903 | 111 | FileSystemInterface fileSystem; |
| Phlaphead | 0:61dbbee3f903 | 112 | |
| Phlaphead | 0:61dbbee3f903 | 113 | string request; |
| Phlaphead | 0:61dbbee3f903 | 114 | bool m_closed; |
| Phlaphead | 0:61dbbee3f903 | 115 | FTPUser m_user; |
| Phlaphead | 0:61dbbee3f903 | 116 | bool m_authenticated; |
| Phlaphead | 0:61dbbee3f903 | 117 | FtpCommand m_command; |
| Phlaphead | 0:61dbbee3f903 | 118 | |
| Phlaphead | 0:61dbbee3f903 | 119 | string m_data_mlsd; |
| Phlaphead | 0:61dbbee3f903 | 120 | |
| Phlaphead | 0:61dbbee3f903 | 121 | }; |
| Phlaphead | 0:61dbbee3f903 | 122 | |
| Phlaphead | 0:61dbbee3f903 | 123 | #endif |