From 6fb9ff48bd2c85534186527658a5d93686c49242 Mon Sep 17 00:00:00 2001 From: Petr Semiletov Date: Mon, 10 Apr 2023 11:53:29 +0300 Subject: [PATCH] --- CMakeLists.txt | 2 +- ChangeLog | 5 +++++ NEWS | 4 ++++ docs/templates.md | 6 +++--- macro.cpp | 19 ++++++++++++++++++- main.cpp | 2 +- tpl.cpp | 2 +- 7 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9996d46..97171e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ if(USE_CLANG) endif(USE_CLANG) -project (logfilegen VERSION 3.0.1 LANGUAGES CXX) +project (logfilegen VERSION 3.0.2 LANGUAGES CXX) add_definitions(-DVERSION_NUMBER="\\"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}\\"") diff --git a/ChangeLog b/ChangeLog index 601085f..d294f73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +3.0.2 +* @seq macros fix. Syntax change! +Was: @seq:param1:param2:etc +Now: @seq:param1|param2|etc + 3.0.1 * @meta fix * randomizer rewrote diff --git a/NEWS b/NEWS index 3af22eb..224263a 100644 --- a/NEWS +++ b/NEWS @@ -5,3 +5,7 @@ This release introduces the multithread support (performance improved), fixes ma upd 3.0.1 * @meta macro fixes * randomizer code has been rewritten +upd 3.0.2 +* @seq macros fix. Syntax change! +Was: @seq:param1:param2:etc +Now: @seq:param1|param2|etc diff --git a/docs/templates.md b/docs/templates.md index 491ec3f..17d3439 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -267,14 +267,14 @@ Please note, the file name after ```@file``` must be an absolute file path, or, #### @seq -Works like **sequence** variable values. Each value is separated by ```:```. +Works like **sequence** variable values. Each value is separated by ```|```. -Syntax: ```@seq:param1:param2:etc``` +Syntax: ```@seq:param1|param2|etc``` Example: ``` -$test=@seq:GET:PUT +$test=@seq:GET|PUT $logstring=hello, $test ``` diff --git a/macro.cpp b/macro.cpp index ca2af2d..2ddfa2d 100644 --- a/macro.cpp +++ b/macro.cpp @@ -495,10 +495,24 @@ void CMacroSeq::parse (const string &s) length = 0; text = ""; + size_t pos = s.find_first_of ("|"); + if (pos == std::string::npos) + return; + + // vt = split_string_to_vector_a (s, ':', '/'); - vt = split_string_to_vector (s, ":"); + pos = s.find_first_of (":"); + if (pos == std::string::npos) + return; + + std::string t = s.substr (pos); + // cout << "t: " << t << endl; + + vt = split_string_to_vector (t, "|"); + +// vt = split_string_to_vector (s, ":"); } @@ -508,6 +522,9 @@ string CMacroSeq::process() //cout << "vt.size(): " << vt.size() << endl; + if (vt.size() == 0) + return string(); + size_t i = get_rnd (1, vt.size() - 1); // cout << "CMacroSeq::process() 2:" << i << endl; diff --git a/main.cpp b/main.cpp index 88dd752..d6418c5 100644 --- a/main.cpp +++ b/main.cpp @@ -41,7 +41,7 @@ #ifndef VERSION_NUMBER -#define VERSION_NUMBER "3.0.1" +#define VERSION_NUMBER "3.0.2" #endif diff --git a/tpl.cpp b/tpl.cpp index 08d7608..f16adaa 100644 --- a/tpl.cpp +++ b/tpl.cpp @@ -88,7 +88,7 @@ CTpl::CTpl (const string &fname, const string &amode) vars.insert (std::make_pair ("%t", new CVar ("%t", "@datetime:%d/%b/%Y:%H:%M:%S %z"))); //$request $uri $protocol - vars.insert (std::make_pair ("%r", new CVar ("%r", "@meta:(@seq:/GET:/PUT) (@path:1:5:3) (@seq:HTTP/1.1:/HTTP/2.0)"))); + vars.insert (std::make_pair ("%r", new CVar ("%r", "@meta:(@seq:/GET|/PUT) (@path:1:5:3) (@seq:HTTP/1.1|/HTTP/2.0)"))); vars.insert (std::make_pair ("%>s", new CVar ("%>s", "200|400"))); vars.insert (std::make_pair ("%b", new CVar ("%b", "1..9999")));