]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Add parsers skeleton
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 Jan 2021 21:18:25 +0000 (21:18 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Jan 2021 15:58:05 +0000 (15:58 +0000)
src/CMakeLists.txt
src/libserver/CMakeLists.txt
src/libserver/css/CMakeLists.txt
src/libserver/css/css.cxx
src/libserver/css/css.h
src/libserver/css/css.hxx
src/libserver/css/css_property.hxx
src/libserver/css/css_rule.hxx
src/libserver/css/css_rule_parser.rl [new file with mode: 0644]
src/libserver/css/css_selector_parser.rl [new file with mode: 0644]
src/libserver/css/css_style.hxx

index 7285d8e7bbb9a2b9dcd55bbcf17da3c5595b46b1..9b3f0b7b490d87c6545f7f7b61847c1d11b26e83 100644 (file)
@@ -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)
index c6d4034edb38d1548fb375f56a1c6132f3ec720c..21c0e789a08a59e6f52c02930703a666de0922f4 100644 (file)
@@ -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)
index 84d3c303873ab3c1dd8b3b29c2bbd62c70c98fbe..f5d5affdb6bee4f8c93f8ff619e283fb287b4238 100644 (file)
@@ -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
index 09388e73952c8e082644c75a52b81c0f9d9ecfe0..68ebfeefa6729bb5555abecca9cb836a8ca37fb3 100644 (file)
 
 #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
index b2c8206161828625c977dcf2ee211a47fc7a6db4..a87f4424d36b21369d025eba290f391a82e7b735 100644 (file)
 #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
index 0b6e57e1a0aadce13207fc6455c7f8b66dd9190e..78e0d0f732477cf45dfb74942eb79586d56c6504 100644 (file)
 #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;
 };
 
 }
index 788f4554b6a978472cfe7c456ea512d62859d238..06a345ad45091364c5761fe9ecff85415e29d410 100644 (file)
@@ -44,6 +44,7 @@ struct css_property {
                                                                                                                                 size_t inlen);
 };
 
+
 }
 
 /* Make properties hashable */
index 596e246b3c6cdb2e316d03e6918c547dc67b9a85..878322f78af7ea76297640229fae2e71eb24cb81 100644 (file)
@@ -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 (file)
index 0000000..e3b1876
--- /dev/null
@@ -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 (file)
index 0000000..f5ae936
--- /dev/null
@@ -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
index 282eb5a7d2f9f2c2b433e187f466e8b0371805bd..f3d1e664d4098eebb219d5286c7825d0c7200bd0 100644 (file)
@@ -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 ();