From a83de03c69138db1c5f633e20489613dcedef464 Mon Sep 17 00:00:00 2001 From: xiyoo0812 Date: Mon, 25 Sep 2023 06:11:03 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97&=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DCORE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/lualog/lualog/logger.cpp | 12 ++++++------ extend/lualog/lualog/logger.h | 6 +++--- extend/lualog/lualog/lualog.cpp | 15 ++++++++------- extend/luapb/src/luapb.cpp | 3 ++- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/extend/lualog/lualog/logger.cpp b/extend/lualog/lualog/logger.cpp index f010dd00..4f1f3581 100644 --- a/extend/lualog/lualog/logger.cpp +++ b/extend/lualog/lualog/logger.cpp @@ -26,14 +26,14 @@ namespace logger { // class log_message // -------------------------------------------------------------------------------- - void log_message::option(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line) { + void log_message::option(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line) { log_time_ = log_time::now(); - feature_ = feature; - source_ = source; + feature_ = std::move(feature); + source_ = std::move(source); + msg_ = std::move(msg); + tag_ = std::move(tag); level_ = level; line_ = line; - msg_ = msg; - tag_ = tag; } // class log_message_pool @@ -367,7 +367,7 @@ namespace logger { } } - void log_service::output(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line) { + void log_service::output(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line) { if (!log_filter_.is_filter(level)) { auto logmsg_ = message_pool_->allocate(); logmsg_->option(level, msg, tag, feature, source, line); diff --git a/extend/lualog/lualog/logger.h b/extend/lualog/lualog/logger.h index c79e4497..dd26c894 100644 --- a/extend/lualog/lualog/logger.h +++ b/extend/lualog/lualog/logger.h @@ -114,7 +114,7 @@ namespace logger { void set_grow(bool grow) { grow_ = grow; } log_level level() const { return level_; } const log_time& get_log_time()const { return log_time_; } - void option(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line); + void option(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line); private: int line_ = 0; @@ -239,7 +239,7 @@ namespace logger { virtual bool add_file_dest(vstring feature, vstring fname) = 0; virtual void set_dest_clean_time(vstring feature, size_t clean_time) = 0; virtual void option(vstring log_path, vstring service, vstring index) = 0; - virtual void output(log_level level, vstring msg, vstring tag, vstring feature = "", vstring source = "", int line = 0) = 0; + virtual void output(log_level level, cstring& msg, cstring& tag, cstring& feature = "", cstring& source = "", int line = 0) = 0; }; class log_service : public logger { @@ -268,7 +268,7 @@ namespace logger { bool is_filter(log_level lv) { return log_filter_.is_filter(lv); } void filter(log_level lv, bool on) { log_filter_.filter(lv, on); } - void output(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line); + void output(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line); protected: path build_path(vstring feature, vstring fpath); diff --git a/extend/lualog/lualog/lualog.cpp b/extend/lualog/lualog/lualog.cpp index 580ccc8d..6a2a68c1 100644 --- a/extend/lualog/lualog/lualog.cpp +++ b/extend/lualog/lualog/lualog.cpp @@ -32,17 +32,18 @@ namespace logger { return "unsuppert data type"; } - int zformat(lua_State* L, log_level lvl, vstring tag, vstring feature, vstring msg) { - get_logger()->output(lvl, msg, tag, feature); + int zformat(lua_State* L, log_level lvl, cstring& tag, cstring& feature, cstring& msg) { if (lvl == log_level::LOG_LEVEL_FATAL) { - lua_pushlstring(L, msg.data(), msg.size()); + lua_pushlstring(L, msg.c_str(), msg.size()); + get_logger()->output(lvl, msg, tag, feature); return 1; } + get_logger()->output(lvl, msg, tag, feature); return 0; } template - int tformat(lua_State* L, log_level lvl, vstring tag, vstring feature, int flag, vstring vfmt, std::index_sequence&&) { + int tformat(lua_State* L, log_level lvl, cstring& tag, cstring& feature, int flag, vstring vfmt, std::index_sequence&&) { try { auto msg = fmt::format(vfmt, read_args(L, flag, integers + 6)...); return zformat(L, lvl, tag, feature, msg); @@ -68,12 +69,12 @@ namespace logger { log_level lvl = (log_level)lua_tointeger(L, 1); if (get_logger()->is_filter(lvl)) return 0; size_t flag = lua_tointeger(L, 2); - vstring tag = lua_to_native(L, 3); - vstring feature = lua_to_native(L, 4); + sstring tag = lua_to_native(L, 3); + sstring feature = lua_to_native(L, 4); vstring vfmt = lua_to_native(L, 5); int arg_num = lua_gettop(L) - 5; switch (arg_num) { - case 0: return zformat(L, lvl, tag, feature, vfmt); + case 0: return zformat(L, lvl, tag, feature, string(vfmt.data(), vfmt.size())); case 1: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<1>{}); case 2: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<2>{}); case 3: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<3>{}); diff --git a/extend/luapb/src/luapb.cpp b/extend/luapb/src/luapb.cpp index 1cb7b861..5af4d20d 100644 --- a/extend/luapb/src/luapb.cpp +++ b/extend/luapb/src/luapb.cpp @@ -35,8 +35,9 @@ namespace luapb { pb_header* header =(pb_header*)m_slice->peek(sizeof(pb_header)); if (!header) return 0; m_packet_len = header->len; + if (m_packet_len < sizeof(pb_header)) return -1; + if (m_packet_len >= 0xffff) return -1; if (!m_slice->peek(m_packet_len)) return 0; - if (m_packet_len > 0xffff) return -1; if (m_packet_len > data_len) return 0; return m_packet_len; }