Skip to content

Commit

Permalink
功能更新:新增一个listener的兼容模式开关,可以允许设备使用不带回车换行(\r\n)的请求来实现登录,以兼容某些采用第三方设备进行N…
Browse files Browse the repository at this point in the history
…trip验证操作(这些第三方设备不支持发送带回车换行的请求,过于辣鸡,工业废料了属于是T_T)
  • Loading branch information
KOROyo123 committed Jun 5, 2024
1 parent 9f36cd2 commit b5444a2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/Koro_Caster_Service/conf/Service_Setting.yml.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Koro_Caster_Service 主体配置文件
# 适用版本:1.1.3.1或更高
# 适用版本:1.1.3.3或更高

# 监听端口设置
Ntrip_Listener_Setting:
Listen_Port: 4202 #监听的端口
Connect_Timeout: 30 #连接无响应超时时间(建立了TCP连接但是并不发送验证信息)(/秒)(≤0 :关闭)
Header_No_CRLF: true #兼容模式,允许用户仅发送Header头登录,且不必发送回车换行,但是同时由于没有回车换行,也不能携带除挂载点之外的任何信息

#基站相关设置
Server_Setting:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ntrip_compat_listener
private:
int _listen_port;
int _connect_timeout = 0;
bool _enable_no_CRLF = true;

event_base *_base;
evconnlistener *_listener;
Expand Down
20 changes: 17 additions & 3 deletions app/Koro_Caster_Service/src/Connector/ntrip_compat_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ntrip_compat_listener::ntrip_compat_listener(json conf, event_base *base, std::u
{
_listen_port = conf["Port"];
_connect_timeout = conf["Timeout"];
_enable_no_CRLF=conf["Enable_No_CRLF"];

_base = base;
_connect_map = connect_map;
Expand Down Expand Up @@ -135,6 +136,19 @@ void ntrip_compat_listener::Ntrip_Decode_Request_cb(bufferevent *bev, void *ctx)
size_t header_len = 0;
char *header = evbuffer_readln(evbuf, &header_len, EVBUFFER_EOL_CRLF);

if (header == NULL && svr->_enable_no_CRLF) // 允许不带回车换行的请求登录
{
auto len = evbuffer_get_length(evbuf);
if (len < 255)
{
spdlog::warn("[{}:{}]: header dont'have CRLF, but Set [Header_No_CRLF], accept this header", __class__, __func__);
header = new char[len + 1];
header[len] = '\0';
header_len = len;
evbuffer_remove(evbuf, header, header_len);
}
}

try
{
if (header == NULL | header_len > 255 | header_len < 9) // HTTP请求最短长度也要15 "GET / HTTP/1.0" NTRIP1.0请求最短长度为9 "SOURCE 1"
Expand Down Expand Up @@ -532,11 +546,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))
if (!check_mount_is_valid(mount))
{
throw std::invalid_argument("MountPoint Name invalid");
}

return mount;
}

Expand Down Expand Up @@ -595,7 +609,7 @@ int ntrip_compat_listener::erase_and_free_bev(bufferevent *bev, std::string Conn

bool ntrip_compat_listener::check_mount_is_valid(const std::string &str)
{
if(str.empty()) //针对获取源列表的情况
if (str.empty()) // 针对获取源列表的情况
{
return true;
}
Expand Down
1 change: 1 addition & 0 deletions app/Koro_Caster_Service/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ json load_Caster_Conf(const char *conf_directory)
auto Ntrip_Listener_Setting = Conf["Ntrip_Listener_Setting"];
conf["Ntrip_Listener"]["Port"] = Ntrip_Listener_Setting["Listen_Port"].as<int>();
conf["Ntrip_Listener"]["Timeout"] = Ntrip_Listener_Setting["Connect_Timeout"].as<int>();
conf["Ntrip_Listener"]["Enable_No_CRLF"]=Ntrip_Listener_Setting["Header_No_CRLF"].as<bool>();

auto Server_Setting = Conf["Server_Setting"];
conf["Server_Setting"]["Timeout"] = Server_Setting["Connect_Timeout"].as<int>();
Expand Down

0 comments on commit b5444a2

Please sign in to comment.