/* * SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd * * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL */ pub mod conv; pub mod imple; pub mod macros; use std::{ io::ErrorKind, net::{IpAddr, Ipv4Addr, Ipv6Addr}, }; pub type Result = std::result::Result; pub type Error = Context; pub type Trace = Context; const ERROR_CONTEXT_SIZE: usize = 5; const TRACE_CONTEXT_SIZE: usize = 10; #[derive(Debug, Default, Clone)] pub enum Value { Static(&'static str), String(String), UInt(u64), Int(i64), Float(f64), Bytes(Vec), Bool(bool), Ipv4(Ipv4Addr), Ipv6(Box), Protocol(Protocol), Error(Box), ErrorKind(ErrorKind), Array(Vec), #[default] None, } #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] pub enum Key { RemoteIp, #[default] CausedBy, Reason, Details, Query, Result, Parameters, Type, Id, Code, Key, Value, Size, Status, Protocol, Property, Path, Url, DocumentId, Collection, AccountId, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Event { NewConnection, Error(Cause), SqlQuery, LdapQuery, PurgeTaskStarted, PurgeTaskRunning, PurgeTaskFinished, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Cause { FoundationDB, MySQL, PostgreSQL, RocksDB, SQLite, ElasticSearch, Redis, S3, Io, Imap, Smtp, Ldap, BlobMissingMarker, Unknown, Purge, AssertValue, Timeout, Thread, Pool, DataCorruption, Decompress, Deserialize, NotConfigured, Unsupported, Unexpected, MissingParameter, Invalid, AlreadyExists, NotFound, Configuration, Fetch, Acme, Http, Crypto, Dns, Authentication, Jmap, OverQuota, Ingest, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Protocol { Jmap, Imap, Smtp, ManageSieve, Ldap, Sql, } #[derive(Debug, Clone)] pub struct Context { inner: T, keys: [(Key, Value); N], keys_size: usize, } pub trait AddContext { fn caused_by(self, location: &'static str) -> Result; fn add_context(self, f: F) -> Result where F: FnOnce(Error) -> Error; }