# Librspamdserver
+ADD_SUBDIRECTORY(css)
SET(LIBRSPAMDSERVERSRC
${CMAKE_CURRENT_SOURCE_DIR}/cfg_utils.c
${CMAKE_CURRENT_SOURCE_DIR}/cfg_rcl.c
${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)
--- /dev/null
+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
--- /dev/null
+/*-
+ * 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"
--- /dev/null
+/*-
+ * 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
--- /dev/null
+/*-
+ * 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
--- /dev/null
+/*-
+ * 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
--- /dev/null
+/*-
+ * 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
--- /dev/null
+/*-
+ * 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)};
+}
+
+}
+}
--- /dev/null
+/*-
+ * 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
--- /dev/null
+/*-
+ * 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