upload
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#include "IPTable.h"
|
||||
#include <webcc/view.h>
|
||||
#include "FileReceiver.h"
|
||||
#include "ServerProcessor.h"
|
||||
#include "HTTPObjectsBridge.h" // 确保能看到 Request::Impl 结构体
|
||||
|
||||
namespace uns
|
||||
{
|
||||
class IBlockedIpUpdatable
|
||||
{
|
||||
public:
|
||||
virtual ~IBlockedIpUpdatable() = default;
|
||||
|
||||
// 统一的库内更新接口(这里的 YourIPContainerType 请替换为你 BlockedIPs 的实际类型)
|
||||
virtual void ApplyIpUpdate(IPTablePtr blocked_ips) = 0;
|
||||
};
|
||||
|
||||
// 隐藏在动态库内部的适配器,对外部不可见
|
||||
|
||||
class ServerProcessorAdapter : public webcc::View, public IBlockedIpUpdatable
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<ServerProcessor> user_processor;
|
||||
|
||||
public:
|
||||
explicit ServerProcessorAdapter(std::shared_ptr<ServerProcessor> processor) : user_processor(processor)
|
||||
{
|
||||
}
|
||||
|
||||
// 完美的把 webcc 的驱动流,翻译给用户的纯净业务类
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) final
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_processor->Handle(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
}
|
||||
|
||||
bool Stream(const std::string& method) final
|
||||
{
|
||||
return user_processor->Stream(method);
|
||||
}
|
||||
|
||||
void ApplyIpUpdate(IPTablePtr blocked_ips) override
|
||||
{
|
||||
user_processor->UpdateBlockedIPList(blocked_ips);
|
||||
}
|
||||
};
|
||||
|
||||
class FileReceiverAdapter : public webcc::View, public IBlockedIpUpdatable
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<::FileReceiver> user_reciver; // 持有用户的派生类对象
|
||||
|
||||
public:
|
||||
explicit FileReceiverAdapter(std::shared_ptr<FileReceiver> reciver) : user_reciver(reciver)
|
||||
{
|
||||
}
|
||||
|
||||
// 完美的把 webcc 的驱动流,翻译给用户的纯净业务类
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) final
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_reciver->Execute(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
}
|
||||
|
||||
bool Stream(const std::string& method) final
|
||||
{
|
||||
// 所有数据都不能由webcc进行串流,否则将无法从request中获取文件
|
||||
return false;
|
||||
}
|
||||
|
||||
void ApplyIpUpdate(IPTablePtr blocked_ips) override
|
||||
{
|
||||
user_reciver->UpdateBlockedIPs(blocked_ips);
|
||||
}
|
||||
};
|
||||
|
||||
class SyncFileReceiverAdapter : public webcc::View, public IBlockedIpUpdatable
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<SyncFileReceiver> user_reciver; // 持有用户的派生类对象
|
||||
|
||||
public:
|
||||
explicit SyncFileReceiverAdapter(std::shared_ptr<SyncFileReceiver> reciver) : user_reciver(reciver)
|
||||
{
|
||||
}
|
||||
|
||||
// 完美的把 webcc 的驱动流,翻译给用户的纯净业务类
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) final
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_reciver->Execute(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
}
|
||||
|
||||
bool Stream(const std::string& method) final
|
||||
{
|
||||
// 所有数据都不能由webcc进行串流,否则将无法从request中获取文件
|
||||
return false;
|
||||
}
|
||||
|
||||
void ApplyIpUpdate(IPTablePtr blocked_ips) override
|
||||
{
|
||||
user_reciver->UpdateBlockedIPs(blocked_ips);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user