FtpServer.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * FtpServer.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "TcpServer.h"
14 #include "WHashMap.h"
15 #include <FileSystem.h>
16 
18 
23 class CustomFtpServer : public TcpServer
24 {
25  friend class FtpServerConnection;
26 
27 public:
28  CustomFtpServer(IFS::FileSystem* fileSystem = nullptr) : fileSystem(fileSystem)
29  {
30  setTimeOut(900);
31  }
32 
39  virtual IFS::UserRole validateUser(const char* login, const char* pass) = 0;
40 
41 protected:
42  TcpConnection* createClient(tcp_pcb* clientTcp) override;
43 
51  virtual bool onCommand(String cmd, String data, FtpServerConnection& connection)
52  {
53  return false;
54  }
55 
57  {
58  return fileSystem ?: ::getFileSystem();
59  }
60 
61 private:
62  IFS::FileSystem* fileSystem;
63 };
64 
69 class FtpServer : public CustomFtpServer
70 {
71 public:
72  void addUser(const String& login, const String& pass, IFS::UserRole userRole = IFS::UserRole::Admin);
73  IFS::UserRole validateUser(const char* login, const char* pass) override;
74 
79  bool checkUser(const String& login, const String& pass) SMING_DEPRECATED
80  {
81  return validateUser(login.c_str(), pass.c_str()) != IFS::UserRole::None;
82  }
83 
84 protected:
85  bool onCommand(String cmd, String data, FtpServerConnection& connection) override;
86 
87 private:
88  struct User {
89  String password;
90  IFS::UserRole role;
91  };
93  UserList users;
94 };
95 
bool checkUser(const String &login, const String &pass)
Legacy user validation.
Definition: FtpServer.h:79
Definition: TcpConnection.h:39
The String class.
Definition: WString.h:136
Installable File System base class.
Definition: Components/IFS/src/include/IFS/FileSystem.h:39
void setTimeOut(uint16_t waitTimeOut)
#define SMING_DEPRECATED
Definition: sming_attr.h:30
CustomFtpServer(IFS::FileSystem *fileSystem=nullptr)
Definition: FtpServer.h:28
Definition: TcpServer.h:30
Definition: FtpServerConnection.h:27
virtual IFS::UserRole validateUser(const char *login, const char *pass)=0
Validate user.
UserRole
Definition: UserRole.h:36
TcpConnection * createClient(tcp_pcb *clientTcp) override
IFS::FileSystem * getFileSystem() const
Definition: FtpServer.h:56
Definition: FtpServer.h:69
Definition: FtpServer.h:23
virtual bool onCommand(String cmd, String data, FtpServerConnection &connection)
Handle an incomding command.
Definition: FtpServer.h:51