commit e7da191: [Project] Add parsers skeleton
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jan 22 16:00:28 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-01-20 21:18:25 +0000
URL: https://github.com/rspamd/rspamd/commit/e7da191495fe9327700900bbd81a8629af8430f5
[Project] Add parsers skeleton
---
src/CMakeLists.txt | 8 ++++++++
src/libserver/CMakeLists.txt | 2 ++
src/libserver/css/CMakeLists.txt | 19 ++++++++++++++++++-
src/libserver/css/css.cxx | 21 +++++++++++++++++++++
src/libserver/css/css.h | 12 ++++++++++++
src/libserver/css/css.hxx | 10 ++++++++--
src/libserver/css/css_property.hxx | 1 +
src/libserver/css/css_rule.hxx | 2 +-
src/libserver/css/css_rule_parser.rl | 27 +++++++++++++++++++++++++++
src/libserver/css/css_selector_parser.rl | 27 +++++++++++++++++++++++++++
src/libserver/css/css_style.hxx | 11 +++++++----
11 files changed, 132 insertions(+), 8 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7285d8e7b..9b3f0b7b4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -143,6 +143,10 @@ RAGEL_TARGET(ragel_smtp_ip
DEPENDS ${RAGEL_DEPENDS}
COMPILE_FLAGS -G2
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ip_parser.rl.c)
+# Fucking cmake...
+FOREACH(_GEN ${LIBSERVER_GENERATED})
+ set_source_files_properties(${_GEN} PROPERTIES GENERATED TRUE)
+ENDFOREACH()
######################### LINK SECTION ###############################
IF(ENABLE_STATIC MATCHES "ON")
@@ -181,6 +185,10 @@ ELSE()
"${RAGEL_ragel_smtp_ip_OUTPUTS}")
ENDIF()
+FOREACH(_DEP ${LIBSERVER_DEPENDS})
+ ADD_DEPENDENCIES(rspamd-server "${_DEP}")
+ENDFOREACH()
+
TARGET_LINK_LIBRARIES(rspamd-server rspamd-http-parser)
TARGET_LINK_LIBRARIES(rspamd-server rspamd-fpconv)
TARGET_LINK_LIBRARIES(rspamd-server rspamd-cdb)
diff --git a/src/libserver/CMakeLists.txt b/src/libserver/CMakeLists.txt
index c6d4034ed..21c0e789a 100644
--- a/src/libserver/CMakeLists.txt
+++ b/src/libserver/CMakeLists.txt
@@ -39,3 +39,5 @@ SET(LIBRSPAMDSERVERSRC
# Librspamd-server
SET(RSPAMD_SERVER ${LIBRSPAMDSERVERSRC} PARENT_SCOPE)
+SET(LIBSERVER_DEPENDS "${LIBCSS_DEPENDS}" PARENT_SCOPE)
+SET(LIBSERVER_GENERATED "${LIBCSS_GENERATED}" PARENT_SCOPE)
diff --git a/src/libserver/css/CMakeLists.txt b/src/libserver/css/CMakeLists.txt
index 84d3c3038..f5d5affdb 100644
--- a/src/libserver/css/CMakeLists.txt
+++ b/src/libserver/css/CMakeLists.txt
@@ -1,5 +1,22 @@
+SET(RAGEL_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/css_syntax.rl")
+RAGEL_TARGET(ragel_css_selector_parser
+ INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/css_selector_parser.rl
+ DEPENDS ${RAGEL_DEPENDS}
+ COMPILE_FLAGS -G2
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/css_selector_parser.rl.cxx)
+RAGEL_TARGET(ragel_css_rule_parser
+ INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/css_rule_parser.rl
+ DEPENDS ${RAGEL_DEPENDS}
+ COMPILE_FLAGS -G2
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/css_rule_parser.rl.cxx)
+
SET(LIBCSSSRC "${CMAKE_CURRENT_SOURCE_DIR}/css.cxx"
"${CMAKE_CURRENT_SOURCE_DIR}/css_property.cxx"
"${CMAKE_CURRENT_SOURCE_DIR}/css_value.cxx"
"${CMAKE_CURRENT_SOURCE_DIR}/css_selector.cxx"
- PARENT_SCOPE)
\ No newline at end of file
+ "${RAGEL_ragel_css_selector_parser_OUTPUTS}"
+ "${RAGEL_ragel_css_rule_parser_OUTPUTS}"
+ PARENT_SCOPE)
+SET(LIBCSS_DEPENDS "ragel_css_selector_parser;ragel_css_rule_parser" PARENT_SCOPE)
+SET(LIBCSS_GENERATED
+ "${RAGEL_ragel_css_selector_parser_OUTPUTS};${RAGEL_ragel_css_rule_parser_OUTPUTS}" PARENT_SCOPE)
\ No newline at end of file
diff --git a/src/libserver/css/css.cxx b/src/libserver/css/css.cxx
index 09388e739..68ebfeefa 100644
--- a/src/libserver/css/css.cxx
+++ b/src/libserver/css/css.cxx
@@ -16,3 +16,24 @@
#include "css.h"
#include "css.hxx"
+#include "css_style.hxx"
+
+rspamd_css
+rspamd_css_parse_style (const guchar *begin, gsize len, GError **err)
+{
+ rspamd::css::css_style_sheet *style = nullptr;
+
+
+ return reinterpret_cast<rspamd_css>(style);
+}
+
+namespace rspamd::css {
+
+class css_style_sheet::impl {
+
+};
+
+css_style_sheet::css_style_sheet () : pimpl(new impl) {}
+css_style_sheet::~css_style_sheet () {}
+
+}
\ No newline at end of file
diff --git a/src/libserver/css/css.h b/src/libserver/css/css.h
index b2c820616..a87f4424d 100644
--- a/src/libserver/css/css.h
+++ b/src/libserver/css/css.h
@@ -17,4 +17,16 @@
#ifndef RSPAMD_CSS_H
#define RSPAMD_CSS_H
+#include "config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef void * rspamd_css;
+
+rspamd_css rspamd_css_parse_style (const guchar *begin, gsize len, GError **err);
+#ifdef __cplusplus
+}
+#endif
+
#endif //RSPAMD_CSS_H
diff --git a/src/libserver/css/css.hxx b/src/libserver/css/css.hxx
index 0b6e57e1a..78e0d0f73 100644
--- a/src/libserver/css/css.hxx
+++ b/src/libserver/css/css.hxx
@@ -17,11 +17,17 @@
#define RSPAMD_CSS_HXX
#include <string>
+#include <memory>
namespace rspamd::css {
-struct css_element {
-
+class css_style_sheet {
+public:
+ css_style_sheet();
+ ~css_style_sheet(); /* must be declared separately due to pimpl */
+private:
+ class impl;
+ std::unique_ptr<impl> pimpl;
};
}
diff --git a/src/libserver/css/css_property.hxx b/src/libserver/css/css_property.hxx
index 788f4554b..06a345ad4 100644
--- a/src/libserver/css/css_property.hxx
+++ b/src/libserver/css/css_property.hxx
@@ -44,6 +44,7 @@ struct css_property {
size_t inlen);
};
+
}
/* Make properties hashable */
diff --git a/src/libserver/css/css_rule.hxx b/src/libserver/css/css_rule.hxx
index 596e246b3..878322f78 100644
--- a/src/libserver/css/css_rule.hxx
+++ b/src/libserver/css/css_rule.hxx
@@ -35,7 +35,7 @@ public:
/* Constructors */
css_rule(css_rule &&other) = default;
explicit css_rule(css_property &&prop, css_values_vec &&values) :
- prop(prop), values(values) {}
+ prop(prop), values(std::forward<css_values_vec>(values)) {}
explicit css_rule(css_property &&prop) : prop(prop), values{} {}
/* Methods */
void add_value(std::unique_ptr<css_value> &&value) {
diff --git a/src/libserver/css/css_rule_parser.rl b/src/libserver/css/css_rule_parser.rl
new file mode 100644
index 000000000..e3b1876c6
--- /dev/null
+++ b/src/libserver/css/css_rule_parser.rl
@@ -0,0 +1,27 @@
+%%{
+ machine css_parser;
+ alphtype unsigned char;
+ include css_syntax "css_syntax.rl";
+
+ main := declaration;
+}%%
+
+%% write data;
+
+#include <cstddef>
+
+namespace rspamd::css {
+
+int
+foo (const unsigned char *data, std::size_t len)
+{
+ const unsigned char *p = data, *pe = data + len, *eof;
+ int cs;
+
+ %% write init;
+ %% write exec;
+
+ return cs;
+}
+
+}
\ No newline at end of file
diff --git a/src/libserver/css/css_selector_parser.rl b/src/libserver/css/css_selector_parser.rl
new file mode 100644
index 000000000..f5ae93642
--- /dev/null
+++ b/src/libserver/css/css_selector_parser.rl
@@ -0,0 +1,27 @@
+%%{
+ machine css_parser;
+ alphtype unsigned char;
+ include css_syntax "css_syntax.rl";
+
+ main := selectors_group;
+}%%
+
+%% write data;
+
+#include <cstddef>
+
+namespace rspamd::css {
+
+int
+parse_css_selector (const unsigned char *data, std::size_t len)
+{
+ const unsigned char *p = data, *pe = data + len, *eof;
+ int cs;
+
+ %% write init;
+ %% write exec;
+
+ return cs;
+}
+
+}
\ No newline at end of file
diff --git a/src/libserver/css/css_style.hxx b/src/libserver/css/css_style.hxx
index 282eb5a7d..f3d1e664d 100644
--- a/src/libserver/css/css_style.hxx
+++ b/src/libserver/css/css_style.hxx
@@ -29,15 +29,18 @@ namespace rspamd::css {
*/
class css_style {
public:
- css_style(const std::shared_ptr<css_style> &_parent) : parent(_parent) {
+ /* Make class trivial */
+ css_style (const css_style &other) = default;
+
+ css_style (const std::shared_ptr<css_style> &_parent) : parent(_parent) {
propagate_from_parent ();
}
- css_style(const std::shared_ptr<css_style> &_parent,
+ css_style (const std::shared_ptr<css_style> &_parent,
const std::vector<std::shared_ptr<css_selector> > &_selectors) : parent(_parent) {
- selectors.reserve(_selectors.size());
+ selectors.reserve (_selectors.size ());
for (const auto &sel_ptr : _selectors) {
- selectors.emplace_back(sel_ptr);
+ selectors.emplace_back (sel_ptr);
}
propagate_from_parent ();
More information about the Commits
mailing list