Add browser download confirmation and parameterized client startup
This commit is contained in:
1 parent
028fec64be
commit
3cf197a98c
25 files changed
+568
-46
No files matched your search
@@ -89,7 +89,7 @@ std::string Serialize(const Message& fields) {
|
||||
}
|
||||
std::string Get(const Message& fields,const std::string& key) { auto it=fields.find(key); return it==fields.end()?"":it->second; }
|
||||
bool Validate(const Message& fields,std::string& error) {
|
||||
static const std::set<std::string> allowed={"action","request_id","url","referrer","user_agent","filename","method"};
|
||||
static const std::set<std::string> allowed={"action","request_id","url","referrer","user_agent","filename","method","confirmation"};
|
||||
for (const auto& [key,value]:fields) {
|
||||
if (!allowed.count(key) || value.find('\0')!=std::string::npos) { error="不支持的字段"; return false; }
|
||||
for (unsigned char c:value) if (c<32 || c==127) { error="字段不能含控制字符"; return false; }
|
||||
@@ -97,8 +97,9 @@ bool Validate(const Message& fields,std::string& error) {
|
||||
const auto action=Get(fields,"action"),id=Get(fields,"request_id");
|
||||
if (id.empty() || id.size()>80) { error="请求编号无效"; return false; }
|
||||
for (unsigned char c:id) if (!std::isalnum(c) && c!='-') { error="请求编号无效"; return false; }
|
||||
if (action=="ping" && fields.size()<=2) return true;
|
||||
if (action!="add" || Get(fields,"method")!="GET" || !HttpUrl(Get(fields,"url"))
|
||||
if ((action=="ping" || action=="query" || action=="cancel") && fields.size()<=2) return true;
|
||||
if (action!="add" || (!Get(fields,"confirmation").empty() && Get(fields,"confirmation")!="required")
|
||||
|| Get(fields,"method")!="GET" || !HttpUrl(Get(fields,"url"))
|
||||
|| (!Get(fields,"referrer").empty() && !HttpUrl(Get(fields,"referrer")))
|
||||
|| Get(fields,"user_agent").size()>2048 || Get(fields,"filename").size()>1024) {
|
||||
error="仅支持 HTTP/HTTPS GET 下载地址及合法上下文"; return false;
|
||||
|
||||
Reference in new issue
Block a user