Skip to content

Commit

Permalink
新增了针对挂载点名称合法性的检验,检验规则("^[a-zA-Z0-9_/.-]+$")支持字母、数字、”. "、”-“。
Browse files Browse the repository at this point in the history
  • Loading branch information
KOROyo123 committed Jun 4, 2024
1 parent ea06999 commit 1a3260d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/Koro_Caster_Service/conf/Service_Setting.yml.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Koro_Caster_Service 主体配置文件
# 适用版本:1.1.2.2或更高
# 适用版本:1.1.3.1或更高

# 监听端口设置
Ntrip_Listener_Setting:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <unordered_map>
#include <set>

#include <regex>

class ntrip_compat_listener
{
private:
Expand Down Expand Up @@ -85,4 +87,6 @@ class ntrip_compat_listener
std::string extract_para(std::string path);
std::string decode_basic_authentication(std::string authentication);
int erase_and_free_bev(bufferevent *bev, std::string Connect_Key);

bool check_mount_is_valid(const std::string& str);
};
45 changes: 14 additions & 31 deletions app/Koro_Caster_Service/src/Connector/ntrip_compat_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,36 +230,6 @@ void ntrip_compat_listener::Ntrip_Decode_Request_cb(bufferevent *bev, void *ctx)
// 不支持的方法
throw 1;
}

// // 判断是否是Server还是Client
// if (strcmp(ele[0], "GET") == 0)
// {
// svr->Process_GET_Request(bev, connect_key, ele[1]);
// }
// else if (strcmp(ele[0], "POST") == 0)
// {
// svr->Process_POST_Request(bev, connect_key, ele[1]);
// }
// else if (strcmp(ele[0], "SOURCE") == 0)
// {
// if (strcmp(ele[2], "HTTP/1.1") == 0 | strcmp(ele[2], "HTTP/1.0") == 0) // 针对报文: SOURCE KOROYO2 HTTP/1.1
// {
// svr->Process_SOURCE_Request(bev, connect_key, ele[1], "");
// }
// else if (ele[2][0] == '\0') // 针对报文: SOURCE KOROYO2
// {
// svr->Process_SOURCE_Request(bev, connect_key, ele[1], "");
// }
// else // 针对报文: SOURCE 42411 KOROYO2 HTTP/1.1 | SOURCE 42411 KOROYO2
// {
// svr->Process_SOURCE_Request(bev, connect_key, ele[2], ele[1]);
// }
// }
// else
// {
// // 不支持的方法
// throw 1;
// }
}
catch (int i)
{
Expand All @@ -268,7 +238,7 @@ void ntrip_compat_listener::Ntrip_Decode_Request_cb(bufferevent *bev, void *ctx)
}
catch (std::exception &e)
{
spdlog::warn("[{}:{}]: process error request, from: [ip: {} port: {}] ,what:{}", __class__, __func__, ip, port, e.what());
spdlog::warn("[{}:{}]: process error request, from: [ip: {} port: {}] ,what: {}", __class__, __func__, ip, port, e.what());
svr->Process_Unknow_Request(bev, connect_key);
}

Expand Down Expand Up @@ -562,6 +532,11 @@ std::string ntrip_compat_listener::extract_path(std::string path)
mount = path.substr(1, x - 1);
search = path.substr(x + 1);
}
if(!check_mount_is_valid(mount))
{
throw std::invalid_argument("MountPoint Name invalid");
}

return mount;
}

Expand Down Expand Up @@ -617,3 +592,11 @@ int ntrip_compat_listener::erase_and_free_bev(bufferevent *bev, std::string Conn

return 0;
}

bool ntrip_compat_listener::check_mount_is_valid(const std::string &str)
{
// 定义一个正则表达式,匹配仅由大小写字母、数字和下划线组成的字符串
std::regex pattern("^[a-zA-Z0-9_.-]+$");
// 使用 std::regex_match 进行匹配检查
return std::regex_match(str, pattern);
}

0 comments on commit 1a3260d

Please sign in to comment.