From 11f6c600e55ca5677f93624efe44d2605cdd908d Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 21 五月 2021 20:18:38 +0800 Subject: [PATCH] reserve #,@ prefix for internal proc id and topic. --- src/topic_node.cpp | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/topic_node.cpp b/src/topic_node.cpp index fce7ed6..3c38121 100644 --- a/src/topic_node.cpp +++ b/src/topic_node.cpp @@ -29,6 +29,11 @@ namespace { +bool ValidUserSymbol(const std::string &s) +{ + return !s.empty() && s[0] != '#' && s[0] != '@'; +} + inline void AddRoute(BHMsgHead &head, const ShmSocket &sock) { auto route = head.add_route(); @@ -143,8 +148,13 @@ for (auto &p : sockets_) { p->Stop(); } } -bool TopicNode::Register(ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms) +bool TopicNode::DoRegister(const bool internal, ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms) { + if (!internal && !ValidUserSymbol(proc.proc_id())) { + SetLastError(eInvalidInput, "invalid proc id :'" + proc.proc_id() + "'"); + return false; + } + { std::lock_guard<std::mutex> lk(mutex_); info_ = proc; @@ -309,8 +319,17 @@ reply.ParseBody(reply_body)); } -bool TopicNode::ServerRegisterRPC(MsgTopicList &topics, MsgCommonReply &reply_body, const int timeout_ms) +bool TopicNode::DoServerRegisterRPC(const bool internal, MsgTopicList &topics, MsgCommonReply &reply_body, const int timeout_ms) { + if (!internal) { + for (auto &&topic : topics.topic_list()) { + if (!ValidUserSymbol(topic)) { + SetLastError(eInvalidInput, "invalid user topic :'" + topic + "'"); + return false; + } + } + } + if (!IsOnline()) { SetLastError(eNotRegistered, kErrMsgNotRegistered); return false; -- Gitblit v1.8.0