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
+ "${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
#include <string>
-namespace rspamd {
-
-namespace css {
+namespace rspamd::css {
struct css_element {
}
-}
-
#endif //RSPAMD_CSS_H
\ No newline at end of file
#include "css_property.hxx"
-namespace rspamd {
-
-namespace css {
+namespace rspamd::css {
auto css_property::from_bytes (const char *input, size_t inlen) -> tl::expected<css_property,css_parse_error>
{
}
}
-}
\ No newline at end of file
#include "parse_error.hxx"
#include "contrib/expected/expected.hpp"
-namespace rspamd {
-
-namespace css {
+namespace rspamd::css {
/*
* To be extended with properties that are interesting from the email
}
-}
-
#endif //RSPAMD_CSS_PROPERTY_HXX
#include <vector>
#include <memory>
-namespace rspamd {
-
-namespace css {
+namespace rspamd::css {
class css_rule {
css_property prop;
}
-}
-
#endif //RSPAMD_CSS_RULE_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_selector.hxx"
+
+namespace rspamd::css {
+
+tl::expected<css_selector,css_parse_error> css_selector::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_SELECTOR_HXX
+#define RSPAMD_CSS_SELECTOR_HXX
+
+#include <variant>
+#include <string>
+#include <optional>
+#include "contrib/expected/expected.hpp"
+#include "parse_error.hxx"
+#include "html_tags.h"
+
+namespace rspamd::css {
+
+/*
+ * Holds a value for css selector, internal is handled by variant
+ */
+struct css_selector {
+ enum class selector_type {
+ SELECTOR_ELEMENT, /* e.g. .tr, for this value we use tag_id_t */
+ SELECTOR_CLASS, /* generic class */
+ SELECTOR_ID /* e.g. #id */
+ };
+
+ selector_type type;
+ std::variant<tag_id_t, std::string> value;
+
+ constexpr std::optional<tag_id_t> to_tag (void) const {
+ if (type == selector_type::SELECTOR_ELEMENT) {
+ return std::get<tag_id_t>(value);
+ }
+ return std::nullopt;
+ }
+
+ std::optional<const std::string> to_string (void) const {
+ if (type == selector_type::SELECTOR_ELEMENT) {
+ return std::get<std::string>(value);
+ }
+ return std::nullopt;
+ }
+
+ static tl::expected<css_selector,css_parse_error> from_bytes (const char *input,
+ size_t inlen);
+};
+
+}
+
+#endif //RSPAMD_CSS_SELECTOR_HXX
#include "css_value.hxx"
-namespace rspamd {
+namespace rspamd::css {
-namespace css {
-
-tl::expected<css_value,css_parse_error> from_bytes (const char *input,
+tl::expected<css_value,css_parse_error> css_value::from_bytes (const char *input,
size_t inlen)
{
return tl::unexpected{css_parse_error(css_parse_error_type::PARSE_ERROR_NYI)};
}
}
-}
#include "parse_error.hxx"
#include "contrib/expected/expected.hpp"
-namespace rspamd {
-namespace css {
+namespace rspamd::css {
+/*
+ * Simple enum class for display stuff
+ */
enum class css_display_value {
DISPLAY_NORMAL,
DISPLAY_
};
+/*
+ * CSS flags
+ */
enum class css_flag_value {
FLAG_INHERIT,
FLAG_IMPORTANT,
FLAG_NOTIMPORTANT
};
+/*
+ * Value handler, uses std::variant instead of polymorphic classes for now
+ * for simplicity
+ */
struct css_value {
enum class css_value_type {
CSS_VALUE_COLOR,
return std::nullopt;
}
+ std::optional<const std::string> to_string (void) const {
+ if (type == css_value_type::CSS_VALUE_STRING) {
+ return std::get<std::string>(value);
+ }
+
+ return std::nullopt;
+ }
+
constexpr bool is_valid (void) const {
return (type != css_value_type::CSS_VALUE_NYI);
}
size_t inlen);
};
-}
}
#endif //RSPAMD_CSS_VALUE_HXX
#include <string>
#include <optional>
-namespace rspamd {
-
-namespace css {
+namespace rspamd::css {
/*
* Generic parser errors
type(type) {}
};
-}
-
}
#endif //RSPAMD_PARSE_ERROR_HXX