aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/css
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-01-14 19:04:52 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-01-22 15:58:05 +0000
commit0c022e5276b526a98417b969410e9e553e8c9c1d (patch)
treef0132e21f8194339144ffcac5c887f4fae311c59 /src/libserver/css
parenta87433515ee8e8edfd774fa4cca2fa863f88af7b (diff)
downloadrspamd-0c022e5276b526a98417b969410e9e553e8c9c1d.tar.gz
rspamd-0c022e5276b526a98417b969410e9e553e8c9c1d.zip
[Project] Skeleton of the css library
Diffstat (limited to 'src/libserver/css')
-rw-r--r--src/libserver/css/CMakeLists.txt4
-rw-r--r--src/libserver/css/css.cxx18
-rw-r--r--src/libserver/css/css.h20
-rw-r--r--src/libserver/css/css.hxx33
-rw-r--r--src/libserver/css/css_property.cxx30
-rw-r--r--src/libserver/css/css_property.hxx53
-rw-r--r--src/libserver/css/css_value.cxx30
-rw-r--r--src/libserver/css/css_value.hxx100
-rw-r--r--src/libserver/css/parse_error.hxx51
9 files changed, 339 insertions, 0 deletions
diff --git a/src/libserver/css/CMakeLists.txt b/src/libserver/css/CMakeLists.txt
new file mode 100644
index 000000000..429a7373f
--- /dev/null
+++ b/src/libserver/css/CMakeLists.txt
@@ -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
index 000000000..09388e739
--- /dev/null
+++ b/src/libserver/css/css.cxx
@@ -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
index 000000000..b2c820616
--- /dev/null
+++ b/src/libserver/css/css.h
@@ -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
index 000000000..86a8457ca
--- /dev/null
+++ b/src/libserver/css/css.hxx
@@ -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
index 000000000..483856a84
--- /dev/null
+++ b/src/libserver/css/css_property.cxx
@@ -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
index 000000000..36a3fee07
--- /dev/null
+++ b/src/libserver/css/css_property.hxx
@@ -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
index 000000000..29eb4aed2
--- /dev/null
+++ b/src/libserver/css/css_value.cxx
@@ -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
index 000000000..0af6a1091
--- /dev/null
+++ b/src/libserver/css/css_value.hxx
@@ -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
index 000000000..d5629fa26
--- /dev/null
+++ b/src/libserver/css/parse_error.hxx
@@ -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