summaryrefslogtreecommitdiff
path: root/src/logTypes.hpp
blob: 687f43b3e5f8a42dc196ce9f0665c4b229fc907f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include <optional>
#include <scn/scan.h>
#include <string>

namespace WebStat {
	struct QuotedString : std::string {
		using std::string::string;
		using std::string::operator=;
	};

	struct QueryString : std::optional<std::string> {
		using std::optional<std::string>::optional;
		using std::optional<std::string>::operator=;
		bool operator<=>(const QueryString &) const = default;
	};

	struct CLFString : std::optional<std::string> {
		using std::optional<std::string>::optional;
		using std::optional<std::string>::operator=;
		bool operator<=>(const CLFString &) const = default;
	};

	enum class EntityType : std::uint8_t {
		Host,
		VirtualHost,
		Path,
		QueryString,
		Referrer,
		UserAgent,
	};

	using Crc32Value = uint32_t;
	using Entity = std::tuple<Crc32Value, EntityType, std::string_view>;
}

namespace scn {
	using ContextType = scn::v4::basic_scan_context<scn::v4::detail::buffer_range_tag, char>;

	template<> struct scanner<WebStat::QuotedString> : scanner<std::string, char> {
		static scan_expected<typename ContextType::iterator> scan(WebStat::QuotedString & value, ContextType & ctx);
	};

	template<> struct scanner<WebStat::QueryString> : scanner<std::string, char> {
		static scan_expected<typename ContextType::iterator> scan(WebStat::QueryString & value, ContextType & ctx);
	};

	template<> struct scanner<WebStat::CLFString> : scanner<std::string, char> {
		static scan_expected<typename ContextType::iterator> scan(WebStat::CLFString & value, ContextType & ctx);

		static void decode(std::string &);
	};
}