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 |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/topic_node.cpp b/src/topic_node.cpp
index 124d329..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,10 +148,9 @@
 	for (auto &p : sockets_) { p->Stop(); }
 }
 
-bool TopicNode::UniRegister(const bool internal, ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms)
+bool TopicNode::DoRegister(const bool internal, ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms)
 {
-	auto ValidUserProcId = [](const std::string &id) { return !id.empty() && id[0] != '#'; };
-	if (!internal && !ValidUserProcId(proc.proc_id())) {
+	if (!internal && !ValidUserSymbol(proc.proc_id())) {
 		SetLastError(eInvalidInput, "invalid proc id :'" + proc.proc_id() + "'");
 		return false;
 	}
@@ -315,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