]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Skeleton of the css library
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 14 Jan 2021 19:04:52 +0000 (19:04 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Jan 2021 15:58:05 +0000 (15:58 +0000)
src/libserver/CMakeLists.txt
src/libserver/css/CMakeLists.txt [new file with mode: 0644]
src/libserver/css/css.cxx [new file with mode: 0644]
src/libserver/css/css.h [new file with mode: 0644]
src/libserver/css/css.hxx [new file with mode: 0644]
src/libserver/css/css_property.cxx [new file with mode: 0644]
src/libserver/css/css_property.hxx [new file with mode: 0644]
src/libserver/css/css_value.cxx [new file with mode: 0644]
src/libserver/css/css_value.hxx [new file with mode: 0644]
src/libserver/css/parse_error.hxx [new file with mode: 0644]

index 635c65b1365504d75da08114dd3ca596f8f77bf8..c6d4034edb38d1548fb375f56a1c6132f3ec720c 100644 (file)
@@ -1,4 +1,5 @@
 # Librspamdserver
+ADD_SUBDIRECTORY(css)
 SET(LIBRSPAMDSERVERSRC
                                ${CMAKE_CURRENT_SOURCE_DIR}/cfg_utils.c
                                ${CMAKE_CURRENT_SOURCE_DIR}/cfg_rcl.c
@@ -33,7 +34,8 @@ SET(LIBRSPAMDSERVERSRC
                                ${CMAKE_CURRENT_SOURCE_DIR}/http/http_router.c
                                ${CMAKE_CURRENT_SOURCE_DIR}/http/http_context.c
                                ${CMAKE_CURRENT_SOURCE_DIR}/maps/map.c
-                               ${CMAKE_CURRENT_SOURCE_DIR}/maps/map_helpers.c)
+                               ${CMAKE_CURRENT_SOURCE_DIR}/maps/map_helpers.c
+                               ${LIBCSSSRC})
 
 # Librspamd-server
 SET(RSPAMD_SERVER ${LIBRSPAMDSERVERSRC} PARENT_SCOPE)
diff --git a/src/libserver/css/CMakeLists.txt b/src/libserver/css/CMakeLists.txt
new file mode 100644 (file)
index 0000000..429a737
--- /dev/null
@@ -0,0 +1,4 @@
+SET(LIBCSSSRC    "${CMAKE_CURRENT_SOURCE_DIR}/css.cxx"
+                "${CMAKE_CURRENT_SOURCE_DIR}/css_property.cxx"
+                "${CMAKE_CURRENT_SOURCE_DIR}/css_value.cxx"
+                PARENT_SCOPE)
\ No newline at end of file
diff --git a/src/libserver/css/css.cxx b/src/libserver/css/css.cxx
new file mode 100644 (file)
index 0000000..09388e7
--- /dev/null
@@ -0,0 +1,18 @@
+/*-
+ * Copyright 2021 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "css.h"
+#include "css.hxx"
diff --git a/src/libserver/css/css.h b/src/libserver/css/css.h
new file mode 100644 (file)
index 0000000..b2c8206
--- /dev/null
@@ -0,0 +1,20 @@
+/*-
+ * Copyright 2021 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RSPAMD_CSS_H
+#define RSPAMD_CSS_H
+
+#endif //RSPAMD_CSS_H
diff --git a/src/libserver/css/css.hxx b/src/libserver/css/css.hxx
new file mode 100644 (file)
index 0000000..86a8457
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * Copyright 2021 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef RSPAMD_CSS_HXX
+#define RSPAMD_CSS_HXX
+
+#include <string>
+
+namespace rspamd {
+
+namespace css {
+
+struct css_element {
+
+};
+
+}
+
+}
+
+#endif //RSPAMD_CSS_H
\ No newline at end of file
diff --git a/src/libserver/css/css_property.cxx b/src/libserver/css/css_property.cxx
new file mode 100644 (file)
index 0000000..483856a
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * Copyright 2021 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "css_property.hxx"
+
+
+namespace rspamd {
+
+namespace css {
+
+auto css_property::from_bytes (const char *input, size_t inlen) -> tl::expected<css_property,css_parse_error>
+{
+       return tl::unexpected{css_parse_error(css_parse_error_type::PARSE_ERROR_NYI)};
+}
+
+}
+}
\ No newline at end of file
diff --git a/src/libserver/css/css_property.hxx b/src/libserver/css/css_property.hxx
new file mode 100644 (file)
index 0000000..36a3fee
--- /dev/null
@@ -0,0 +1,53 @@
+/*-
+ * Copyright 2021 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RSPAMD_CSS_PROPERTY_HXX
+#define RSPAMD_CSS_PROPERTY_HXX
+
+#include <string>
+#include "parse_error.hxx"
+#include "contrib/expected/expected.hpp"
+
+namespace rspamd {
+
+namespace css {
+
+/*
+ * To be extended with properties that are interesting from the email
+ * point of view
+ */
+enum class css_property_type {
+       PROPERTY_FONT,
+       PROPERTY_COLOR,
+       PROPERTY_BGCOLOR,
+       PROPERTY_BACKGROUND,
+       PROPERTY_HEIGHT,
+       PROPERTY_WIDTH,
+       PROPERTY_DISPLAY,
+       PROPERTY_VISIBILITY,
+};
+
+struct css_property {
+       css_property_type type;
+       static tl::expected<css_property,css_parse_error> from_bytes (const char *input,
+                                                                                                                                size_t inlen);
+};
+
+}
+
+}
+
+#endif //RSPAMD_CSS_PROPERTY_HXX
diff --git a/src/libserver/css/css_value.cxx b/src/libserver/css/css_value.cxx
new file mode 100644 (file)
index 0000000..29eb4ae
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * Copyright 2021 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "css_value.hxx"
+
+namespace rspamd {
+
+namespace css {
+
+tl::expected<css_value,css_parse_error> from_bytes (const char *input,
+                                                                                                       size_t inlen)
+{
+       return tl::unexpected{css_parse_error(css_parse_error_type::PARSE_ERROR_NYI)};
+}
+
+}
+}
diff --git a/src/libserver/css/css_value.hxx b/src/libserver/css/css_value.hxx
new file mode 100644 (file)
index 0000000..0af6a10
--- /dev/null
@@ -0,0 +1,100 @@
+/*-
+ * Copyright 2021 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RSPAMD_CSS_VALUE_HXX
+#define RSPAMD_CSS_VALUE_HXX
+
+#include "libserver/html.h"
+#include <string>
+#include <variant>
+#include <optional>
+#include "parse_error.hxx"
+#include "contrib/expected/expected.hpp"
+
+namespace rspamd {
+namespace css {
+
+enum class css_display_value {
+       DISPLAY_NORMAL,
+       DISPLAY_
+};
+
+enum class css_flag_value {
+       FLAG_INHERIT,
+       FLAG_IMPORTANT,
+       FLAG_NOTIMPORTANT
+};
+
+struct css_value {
+       enum class css_value_type {
+               CSS_VALUE_COLOR,
+               CSS_VALUE_SIZE,
+               CSS_VALUE_STRING,
+               CSS_VALUE_DISPLAY,
+               CSS_VALUE_FLAG,
+               CSS_VALUE_NYI,
+       } type;
+
+       std::variant<struct html_color,
+                       double,
+                       std::string,
+                       css_display_value,
+                       css_flag_value> value;
+
+       constexpr std::optional<struct html_color> to_color (void) const {
+               if (type == css_value_type::CSS_VALUE_COLOR) {
+                       return std::get<struct html_color>(value);
+               }
+
+               return std::nullopt;
+       }
+
+       constexpr std::optional<double> to_size (void) const {
+               if (type == css_value_type::CSS_VALUE_SIZE) {
+                       return std::get<double>(value);
+               }
+
+               return std::nullopt;
+       }
+
+       constexpr std::optional<css_display_value> to_display (void) const {
+               if (type == css_value_type::CSS_VALUE_DISPLAY) {
+                       return std::get<css_display_value>(value);
+               }
+
+               return std::nullopt;
+       }
+
+       constexpr std::optional<css_flag_value> to_flag (void) const {
+               if (type == css_value_type::CSS_VALUE_FLAG) {
+                       return std::get<css_flag_value>(value);
+               }
+
+               return std::nullopt;
+       }
+
+       constexpr bool is_valid (void) const {
+               return (type != css_value_type::CSS_VALUE_NYI);
+       }
+
+       static tl::expected<css_value,css_parse_error> from_bytes (const char *input,
+                                                                                                                                 size_t inlen);
+};
+
+}
+}
+
+#endif //RSPAMD_CSS_VALUE_HXX
diff --git a/src/libserver/css/parse_error.hxx b/src/libserver/css/parse_error.hxx
new file mode 100644 (file)
index 0000000..d5629fa
--- /dev/null
@@ -0,0 +1,51 @@
+/*-
+ * Copyright 2021 Vsevolod Stakhov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef RSPAMD_PARSE_ERROR_HXX
+#define RSPAMD_PARSE_ERROR_HXX
+
+#include <string>
+#include <optional>
+
+namespace rspamd {
+
+namespace css {
+
+/*
+ * Generic parser errors
+ */
+enum class css_parse_error_type {
+       PARSE_ERROR_UNKNOWN_OPTION,
+       PARSE_ERROR_INVALID_SYNTAX,
+       PARSE_ERROR_NYI,
+       PARSE_ERROR_UNKNOWN_ERROR,
+};
+
+struct css_parse_error {
+       css_parse_error_type type;
+       std::optional<std::string> description;
+
+       explicit css_parse_error (css_parse_error_type type, const std::string &description) :
+               type(type), description(description) {}
+       explicit css_parse_error (css_parse_error_type type) :
+                       type(type) {}
+};
+
+}
+
+}
+#endif //RSPAMD_PARSE_ERROR_HXX