aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-01-28 16:13:31 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-01-28 16:13:31 +0000
commit2710590c92c1ad315657de69fb2a7672d8688f80 (patch)
treee889062856f134cf62f4ab0a7e1a9c4d5d989de2 /src
parentacf1756dfae5a93e0348eae74809d343e696f44b (diff)
downloadrspamd-2710590c92c1ad315657de69fb2a7672d8688f80.tar.gz
rspamd-2710590c92c1ad315657de69fb2a7672d8688f80.zip
[Project] Css: Add some debug methods
Diffstat (limited to 'src')
-rw-r--r--src/libserver/css/css_parser.cxx5
-rw-r--r--src/libserver/css/css_tokeniser.cxx103
-rw-r--r--src/libserver/css/css_tokeniser.hxx5
3 files changed, 110 insertions, 3 deletions
diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx
index 68f03cdfa..54ccccd23 100644
--- a/src/libserver/css/css_parser.cxx
+++ b/src/libserver/css/css_parser.cxx
@@ -101,10 +101,9 @@ bool css_parser::consume_input(const std::string_view &sv)
case css_parser_token::token_type::eof_token:
eof = true;
break;
- case css_parser_token::token_type::whitespace_token:
- case css_parser_token::token_type::cdc_token:
- case css_parser_token::token_type::cdo_token:
+ default:
/* Ignore tokens */
+ msg_debug_css("got token: %s", next_token.debug_token_str().c_str());
break;
}
}
diff --git a/src/libserver/css/css_tokeniser.cxx b/src/libserver/css/css_tokeniser.cxx
index 3d1749913..60ff297b3 100644
--- a/src/libserver/css/css_tokeniser.cxx
+++ b/src/libserver/css/css_tokeniser.cxx
@@ -706,4 +706,107 @@ auto css_tokeniser::next_token(void) -> struct css_parser_token
return make_token<css_parser_token::token_type::eof_token>();
}
+constexpr auto css_parser_token::get_token_type() -> const char *
+{
+ const char *ret = "unknown";
+
+ switch(type) {
+ case token_type::whitespace_token:
+ ret = "whitespace";
+ break;
+ case token_type::ident_token:
+ ret = "ident";
+ break;
+ case token_type::function_token:
+ ret = "function";
+ break;
+ case token_type::at_keyword_token:
+ ret = "atkeyword";
+ break;
+ case token_type::hash_token:
+ ret = "hash";
+ break;
+ case token_type::string_token:
+ ret = "string";
+ break;
+ case token_type::number_token:
+ ret = "number";
+ break;
+ case token_type::url_token:
+ ret = "url";
+ break;
+ case token_type::cdo_token: /* xml open comment */
+ ret = "cdo";
+ break;
+ case token_type::cdc_token: /* xml close comment */
+ ret = "cdc";
+ break;
+ case token_type::delim_token:
+ ret = "delim";
+ break;
+ case token_type::obrace_token: /* ( */
+ ret = "obrace";
+ break;
+ case token_type::ebrace_token: /* ) */
+ ret = "ebrace";
+ break;
+ case token_type::osqbrace_token: /* [ */
+ ret = "osqbrace";
+ break;
+ case token_type::esqbrace_token: /* ] */
+ ret = "esqbrace";
+ break;
+ case token_type::ocurlbrace_token: /* { */
+ ret = "ocurlbrace";
+ break;
+ case token_type::ecurlbrace_token: /* } */
+ ret = "ecurlbrace";
+ break;
+ case token_type::comma_token:
+ ret = "comma";
+ break;
+ case token_type::colon_token:
+ ret = "colon";
+ break;
+ case token_type::semicolon_token:
+ ret = "semicolon";
+ break;
+ case token_type::eof_token:
+ ret = "eof";
+ break;
+ }
+
+ return ret;
+}
+
+
+auto css_parser_token::debug_token_str() -> std::string
+{
+ const auto *token_type_str = get_token_type();
+ std::string ret = token_type_str;
+
+ if (std::holds_alternative<std::string_view>(value)) {
+ ret += "; value=";
+ ret += std::get<std::string_view>(value);
+ }
+ else if (std::holds_alternative<double>(value)) {
+ ret += "; value=";
+ ret += std::to_string(std::get<double>(value));
+ }
+ else if (std::holds_alternative<char>(value)) {
+ ret += "; value=";
+ ret += std::get<char>(value);
+ }
+
+ if ((flags & (~number_dimension)) != default_flags) {
+ ret += "; flags=" + std::to_string(flags);
+ }
+
+ if (flags & number_dimension) {
+ ret += "; dim=" + std::to_string(static_cast<int>(dim_type));
+ }
+
+ return ret; /* Copy elision */
+}
+
} \ No newline at end of file
diff --git a/src/libserver/css/css_tokeniser.hxx b/src/libserver/css/css_tokeniser.hxx
index cd9c47cfd..b2da88500 100644
--- a/src/libserver/css/css_tokeniser.hxx
+++ b/src/libserver/css/css_tokeniser.hxx
@@ -91,6 +91,11 @@ struct css_parser_token {
explicit css_parser_token(token_type type, const value_type &value) :
value(value), type(type) {}
auto adjust_dim(const css_parser_token &dim_token) -> bool;
+
+ /* Debugging routines */
+ constexpr auto get_token_type() -> const char *;
+ /* This function might be slow */
+ auto debug_token_str() -> std::string;
};
/* Ensure that parser tokens are simple enough */