51 lines
1.9 KiB
C++
51 lines
1.9 KiB
C++
#pragma once
|
|
#include "Export.h"
|
|
#include "Global.h"
|
|
#include "IPTable.h"
|
|
#include "HTTPObjects.h"
|
|
#include "TempFileManager.h"
|
|
|
|
using SFR_FileMap = std::map<std::string, std::string>;
|
|
|
|
class UNSWSC_DLL_EXPORT SyncFileReceiver
|
|
{
|
|
protected:
|
|
class Impl;
|
|
std::unique_ptr<Impl> pimpl;
|
|
|
|
public:
|
|
SyncFileReceiver();
|
|
virtual ~SyncFileReceiver();
|
|
|
|
public:
|
|
void SetResponseMode(bool html);
|
|
void SetCORSEnable(bool enable);
|
|
std::string EncodeUploadResult();
|
|
std::string EncodeUploadResultHTML();
|
|
void UpdateBlockedIPs(IPTablePtr ip);
|
|
void SetTempRoot(std::string temp_root);
|
|
uns::HTTPMethod GetMethod(uns::RequestPtr request);
|
|
void AppenedBlockedIP(DateTime::Span block_time, std::string ip);
|
|
bool WriteFile(const std::string& path, const std::string& bytes);
|
|
void SetFileTimeout(std::chrono::seconds timeout = 0s, std::chrono::seconds max_proc_timeout = 0s) noexcept;
|
|
|
|
public:
|
|
// 请求信息预检,重载以在保存文件之前检查请求体
|
|
virtual uns::Status PreCheckRequest(uns::RequestPtr request) = 0;
|
|
// 表单预检,重载以在处理表单前检查表单
|
|
virtual bool PreCheckForm(uns::FormPartPtr form) = 0;
|
|
// 路径穿越配置,重载以配置允许的路径穿越类型
|
|
virtual uns::PathTraversalDefenceLevel PTDefence();
|
|
// 路径穿越防护,重载以实现路径穿越检查,配置为AutoNormalize或AllowNormal时必须,否则自动退化为DenyAll
|
|
virtual bool IsPathSafe(const std::string& raw_path);
|
|
// 请求头预检,重载以实现在接收请求体之前检查请求头,返回false则服务器将强制关闭连接
|
|
virtual bool IsHeaderValid(uns::RequestPtr request);
|
|
|
|
// 主接口,重载以接收并处理文件
|
|
virtual uns::ResponsePtr ProcessFiles(TempFileManager& file_info, SFR_FileMap file_map, const std::string& tmp_root, uns::RequestPtr request);
|
|
|
|
public:
|
|
uns::ResponsePtr Execute(uns::RequestPtr request);
|
|
};
|
|
|
|
using SyncFileReceiverPtr = std::shared_ptr<SyncFileReceiver>; |