NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
ftp_protocol.hpp
1#ifndef NEFORCE_NETWORK_FTP_FTP_PROTOCOL_HPP__
2#define NEFORCE_NETWORK_FTP_FTP_PROTOCOL_HPP__
5NEFORCE_BEGIN_NAMESPACE__
6
11struct NEFORCE_API ftp_exception final : network_exception {
12 explicit ftp_exception(const char* info = "FTP Operation Failed.", const char* type = static_type,
13 const int code = 0) noexcept :
14 network_exception(info, type, code) {}
15
16 explicit ftp_exception(const exception& e) :
17 network_exception(e) {}
18
19 ~ftp_exception() override = default;
20
21 static constexpr auto static_type = "ftp_exception";
22};
23
24class NEFORCE_API ftp_protocol : public ip_socket {
25public:
26 enum class transfer_mode {
27 ascii,
28 binary
29 };
30
31 enum class passive_mode {
32 active,
33 passive
34 };
35
36 enum class tls_mode {
37 none,
38 implicit_,
39 explicit_
40 };
41
42 struct response {
43 int code;
44 string message;
45
46 NEFORCE_NODISCARD bool is_success() const noexcept { return code >= 200 && code < 400; }
47 NEFORCE_NODISCARD bool is_positive_preliminary() const noexcept { return code >= 100 && code < 200; }
48 };
49
50 struct tls_info {
51 bool active = false;
52 string cipher_name;
53 string tls_version;
54 bool peer_verified = false;
55 bool data_channel = false;
56 };
57
58 static constexpr size_t kBufferSize = 8192;
59
60protected:
61 bool tls_active_ = false;
62 ssl_stream ctrl_ssl_;
63 ssl_context* ssl_ctx_ = nullptr;
64 bool data_tls_ = false;
65
66 char buffer_[kBufferSize]{};
67 size_t buffer_pos_ = 0;
68 size_t buffer_size_ = 0;
69
70 ftp_protocol() = default;
71 ~ftp_protocol() override = default;
72
73 ftp_protocol(ftp_protocol&& other) noexcept;
74 ftp_protocol& operator=(ftp_protocol&& other) noexcept;
75
76 explicit ftp_protocol(native_handle_type fd) :
77 ip_socket(fd) {}
78
79 ssize_t ctrl_send(const char* data, size_t len);
80 ssize_t ctrl_recv(char* buf, size_t len);
81 bool ctrl_read_line(string& out);
82
83 response read_response();
84 void send_response(int code, const string& msg);
85 void send_response(const response& resp);
86
87 void clear_buffer() {
88 buffer_pos_ = 0;
89 buffer_size_ = 0;
90 }
91};
92
93NEFORCE_END_NAMESPACE__
94#endif // NEFORCE_NETWORK_FTP_FTP_PROTOCOL_HPP__
IP协议族Socket基类
int native_handle_type
系统句柄类型
NEFORCE_INLINE17 constexpr none_t none
默认空表示
int64_t ssize_t
有符号大小类型
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针
IP协议族Socket基类
SSL/TLS流封装
exception & operator=(const exception &other) noexcept
复制赋值运算符
exception(const char *info=static_type, const char *type=static_type, const int code=0)
构造函数
NEFORCE_NODISCARD int code() const noexcept
获取异常码
NEFORCE_NODISCARD const char * type() const noexcept
获取异常类型