From 0c022e5276b526a98417b969410e9e553e8c9c1d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 14 Jan 2021 19:04:52 +0000 Subject: [PATCH] [Project] Skeleton of the css library --- src/libserver/CMakeLists.txt | 4 +- src/libserver/css/CMakeLists.txt | 4 ++ src/libserver/css/css.cxx | 18 ++++++ src/libserver/css/css.h | 20 ++++++ src/libserver/css/css.hxx | 33 ++++++++++ src/libserver/css/css_property.cxx | 30 +++++++++ src/libserver/css/css_property.hxx | 53 +++++++++++++++ src/libserver/css/css_value.cxx | 30 +++++++++ src/libserver/css/css_value.hxx | 100 +++++++++++++++++++++++++++++ src/libserver/css/parse_error.hxx | 51 +++++++++++++++ 10 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 src/libserver/css/CMakeLists.txt create mode 100644 src/libserver/css/css.cxx create mode 100644 src/libserver/css/css.h create mode 100644 src/libserver/css/css.hxx create mode 100644 src/libserver/css/css_property.cxx create mode 100644 src/libserver/css/css_property.hxx create mode 100644 src/libserver/css/css_value.cxx create mode 100644 src/libserver/css/css_value.hxx create mode 100644 src/libserver/css/parse_error.hxx diff --git a/src/libserver/CMakeLists.txt b/src/libserver/CMakeLists.txt index 635c65b13..c6d4034ed 100644 --- a/src/libserver/CMakeLists.txt +++ b/src/libserver/CMakeLists.txt @@ -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 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 + +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 +{ + 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 +#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 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 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 +#include +#include +#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 value; + + constexpr std::optional to_color (void) const { + if (type == css_value_type::CSS_VALUE_COLOR) { + return std::get(value); + } + + return std::nullopt; + } + + constexpr std::optional to_size (void) const { + if (type == css_value_type::CSS_VALUE_SIZE) { + return std::get(value); + } + + return std::nullopt; + } + + constexpr std::optional to_display (void) const { + if (type == css_value_type::CSS_VALUE_DISPLAY) { + return std::get(value); + } + + return std::nullopt; + } + + constexpr std::optional to_flag (void) const { + if (type == css_value_type::CSS_VALUE_FLAG) { + return std::get(value); + } + + return std::nullopt; + } + + constexpr bool is_valid (void) const { + return (type != css_value_type::CSS_VALUE_NYI); + } + + static tl::expected 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 +#include + +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 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 -- 2.39.5