6 #include <hal_posix/file_tftp.h>
12 static const char* PATH_SEP =
"\\";
14 static const char* PATH_SEP =
"/";
29 TftpClientPosix::~TftpClientPosix()
37 const char* filename_local,
38 const char* filename_remote)
40 m_dst.
open(filename_local);
46 const char* filename_local,
47 const char* filename_remote)
49 m_src.
open(filename_local);
53 log::Log(log::ERROR,
"TftpClient: File not found", filename_local);
58 const char* work_folder)
60 , m_work_folder(std::string(work_folder) + PATH_SEP)
67 TftpServerPosix::~TftpServerPosix()
77 if (!filename)
return std::string();
78 std::string filename2(filename);
79 if (filename2.find(
"..") != std::string::npos)
return std::string();
80 return m_work_folder + filename2;
87 if (safe_path.empty()) {
88 log::Log(log::INFO,
"TftpServer: Rejected read", filename);
91 m_src.
open(safe_path.c_str());
93 log::Log(log::INFO,
"TftpServer: Reading", safe_path.c_str())
97 log::Log(log::INFO,
"TftpServer: File not found", filename);
107 if (safe_path.empty()) {
108 log::Log(log::INFO,
"TftpServer: Rejected write", filename);
111 m_dst.
open(safe_path.c_str());
113 log::Log(log::INFO,
"TftpServer: Writing", safe_path.c_str());
116 log::Log(log::WARNING,
"TftpServer: Unable to open", safe_path.c_str());
void open(const char *filename, unsigned len=0)
Open the specified file to read the next frame.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
unsigned get_write_space() const override
How many bytes can be written without blocking?
void open(const char *filename)
Open the specified file.
Abstract API for reading byte-streams and packets.
Abstract API for writing byte-streams and packets.
The Log class creates and formats one log message.
Log & write10(s32 val)
Print integer as a decimal value with no leading zeros.
Log & write(const char *str)
Formatting methods for various data types.
Dispatcher sorts incoming UDP messages by port index.
void begin_upload(satcat5::io::Readable *src, const satcat5::ip::Addr &server, const char *filename)
Upload data from a Readable stream to the server.
void begin_download(satcat5::io::Writeable *dst, const satcat5::ip::Addr &server, const char *filename)
Download a file from server to a Writeable stream.
A TFTP client that makes request(s) to a remote server.
void begin_upload(const satcat5::ip::Addr &server, const char *filename_local, const char *filename_remote)
Upload data from a Readable stream to the server.
void begin_download(const satcat5::ip::Addr &server, const char *filename_local, const char *filename_remote)
Download a file from server to a Writeable stream.
ServerCore is the base class that handles TFTP network functions.
A TFTP server handles requests from remote clients.
std::string check_path(const char *filename)
Check if a user-supplied path is safe to use.
satcat5::io::Readable * read(const char *filename) override
Child class MUST override these methods.
TftpServerPosix(satcat5::udp::Dispatch *iface, const char *work_folder)
Attach this TFTP server to a network interface.
Miscellaneous POSIX wrappers (e.g., heap allocation, log to console...)
IPv4 address is a 32-bit unsigned integer.