diff --git a/src/app/FTPServer.h b/src/app/FTPServer.h index 6153862..26e7489 100644 --- a/src/app/FTPServer.h +++ b/src/app/FTPServer.h @@ -16,18 +16,18 @@ class FTPServer : public TCPServer enum FTPClientDataTransfer {NONE = 0, LIST_DF, NLST_DF, RETR_DF, STOR_DF, APPE_DF}; enum FileTransferStatus {OK, NOT_FOUND, NO_FILE_NAME, MALLOC_ERROR}; enum BinaryFlag {OFF = 0, ON}; - enum FTPMsgCode {_150, _200, _215, _220, _221, _230, _226, _227, _250, _257, _331, _350, _451, _5_502, _504, _530, _550 }; + enum FTPMsgCode {_150, _200, _215, _220, _221, _230, _226, _227, _250, _257, _331, _350, _451, _502, _504, _530, _550 }; - FTPServer(uint16_t port = 21, SDClass *sdClass = NULL, const char *login = NULL, const char *password = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientCommandDataBufferSize = 255) : TCPServer(port, maxClient, clientCommandDataBufferSize), + FTPServer(uint16_t port = 21, SDClass *sdClass = NULL, const char *username = NULL, const char *password = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientCommandDataBufferSize = 255) : TCPServer(port, maxClient, clientCommandDataBufferSize), _dataServer(_dataPort), _sdClass(sdClass) { - if (login != NULL) + if (username != NULL) { - if (strlen(login)) + if (strlen(username)) { - _login = (char *)malloc((sizeof(char) * strlen(login)) + 1); - strcpy(_login, login); + _username = (char *)malloc((sizeof(char) * strlen(username)) + 1); + strcpy(_username, username); } } @@ -50,7 +50,7 @@ class FTPServer : public TCPServer virtual ~FTPServer() { _dataServer.stop(); - free(_login); free(_password); free(_FTPDir); + free(_username); free(_password); free(_FTPDir); } virtual void stop() @@ -68,7 +68,51 @@ class FTPServer : public TCPServer { free(_FTPDir); _FTPDir = (char *)malloc((strlen(FTPDir) * sizeof(char)) + 1); - strcpy(_FTPDir, FTPDir); + if(_FTPDir) + { + strcpy(_FTPDir, FTPDir); + } + } + else + { + free(_FTPDir); + _FTPDir = nullptr; + } + } + + virtual void setUsername(const char *username) + { + if(username) + { + free(_username); + _username = (char *)malloc((strlen(username) * sizeof(char)) + 1); + if(_username) + { + strcpy(_username, username); + } + } + else + { + free(_username); + _username = nullptr; + } + } + + virtual void setPassword(const char *password) + { + if(password) + { + free(_password); + _password = (char *)malloc((strlen(password) * sizeof(char)) + 1); + if(_password) + { + strcpy(_password, password); + } + } + else + { + free(_password); + _password = nullptr; } } @@ -334,7 +378,7 @@ class FTPServer : public TCPServer if (strcmp(client->_ftpCommand, "USER") == 0) { //We check if we set a login and a password : - if (_login != NULL && _password != NULL) + if (_username != NULL && _password != NULL) { if (client->_cmdParameters->count() > 0) { @@ -355,7 +399,7 @@ class FTPServer : public TCPServer //We now check if the username and password correspond if (client->_cmdParameters->count() > 0) { - if (strcmp(_login, client->_username) == 0 && strcmp(_password, client->_cmdParameters->getAt(0)->getString()) == 0) + if (strcmp(_username, client->_username) == 0 && strcmp(_password, client->_cmdParameters->getAt(0)->getString()) == 0) { client->_loggedIn = true; client->_client.println("230 User logged in, proceed."); @@ -792,7 +836,7 @@ class FTPServer : public TCPServer }*/ else { - client->_client.println("502 Command not implemented."); + sendInfoResponse(_502, client); #ifdef DEBUG_FTPS Serial.println("Command not implemented"); #endif @@ -1015,7 +1059,10 @@ class FTPServer : public TCPServer client->_client.printf_P(PSTR("200 Command okay. %s\r\n"), msg); break; case _221: - client->_client.printf_P(PSTR("221 Service closing control connection. %s\r\n")); + client->_client.printf_P(PSTR("221 Service closing control connection. %s\r\n"), msg); + break; + case _502: + client->_client.printf_P(PSTR("502 Command not implemented. %s\r\n"), msg); break; case _530: client->_client.printf_P(PSTR("530 Password required. %s\r\n"), msg); @@ -1028,7 +1075,7 @@ class FTPServer : public TCPServer } } - char *_login = nullptr; + char *_username = nullptr; char *_password = nullptr; char *_FTPDir = nullptr; uint16_t _dataPort = 1024; diff --git a/src/app/WEBServer.h b/src/app/WEBServer.h index 4b7a865..5338efa 100644 --- a/src/app/WEBServer.h +++ b/src/app/WEBServer.h @@ -80,12 +80,17 @@ class WEBServer : public TCPServer, public HttpConstants void setWWWDir(const char *WWWDir) { - if(WWWDir != nullptr) + if(WWWDir) { free(_WWWDir); _WWWDir = (char *)malloc((strlen(WWWDir) * sizeof(char)) + 1); strcpy(_WWWDir, WWWDir); } + else + { + free(_WWWDir); + _WWWDir = nullptr; + } } protected: private: