diff --git a/src/aheader.rs b/src/aheader.rs index bfe3b385c..676ee9306 100644 --- a/src/aheader.rs +++ b/src/aheader.rs @@ -1,3 +1,7 @@ +//! # Autocrypt header module +//! +//! Parse and create [Autocrypt-headers](https://autocrypt.org/en/latest/level1.html#the-autocrypt-header). + use std::collections::BTreeMap; use std::ffi::CStr; use std::str::FromStr; @@ -46,7 +50,7 @@ impl str::FromStr for EncryptPreference { } } -/// Parse and create [Autocrypt-headers](https://autocrypt.org/en/latest/level1.html#the-autocrypt-header). +/// Autocrypt header #[derive(Debug)] pub struct Aheader { pub addr: String, @@ -55,6 +59,7 @@ pub struct Aheader { } impl Aheader { + /// Creates new autocrypt header pub fn new(addr: String, public_key: Key, prefer_encrypt: EncryptPreference) -> Self { Aheader { addr, diff --git a/src/blob.rs b/src/blob.rs index 2c6fdae81..d0c22ff08 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -1,3 +1,5 @@ +//! # Blob directory management + use std::ffi::OsStr; use std::fmt; use std::fs; diff --git a/src/chat.rs b/src/chat.rs index 54c4e8d81..6fd77cd63 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,3 +1,5 @@ +//! # Chat module + use std::path::{Path, PathBuf}; use itertools::Itertools; @@ -37,6 +39,7 @@ pub struct Chat { } impl Chat { + /// Loads chat from the database by its ID. pub fn load_from_db(context: &Context, chat_id: u32) -> Result { let res = context.sql.query_row( "SELECT c.id,c.type,c.name, c.grpid,c.param,c.archived, \ @@ -226,6 +229,7 @@ impl Chat { color } + /// Returns true if the chat is archived. pub fn is_archived(&self) -> bool { self.archived } diff --git a/src/chatlist.rs b/src/chatlist.rs index fa45561b5..275cad353 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -1,3 +1,5 @@ +//! # Chat list module + use crate::chat::*; use crate::constants::*; use crate::contact::*; @@ -233,6 +235,7 @@ impl Chatlist { self.ids.len() } + /// Returns true if chatlist is empty. pub fn is_empty(&self) -> bool { self.ids.is_empty() } @@ -329,6 +332,7 @@ impl Chatlist { } } +/// Get the number of archived chats pub fn dc_get_archived_cnt(context: &Context) -> u32 { context .sql diff --git a/src/config.rs b/src/config.rs index ab8851714..ceaac5318 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,5 @@ +//! # Key-value configuration management + use strum::{EnumProperty, IntoEnumIterator}; use strum_macros::{AsRefStr, Display, EnumIter, EnumProperty, EnumString}; diff --git a/src/configure/auto_mozilla.rs b/src/configure/auto_mozilla.rs index 56943333f..8a8f1746a 100644 --- a/src/configure/auto_mozilla.rs +++ b/src/configure/auto_mozilla.rs @@ -1,3 +1,4 @@ +//! Thunderbird's Autoconfiguration implementation use quick_xml; use quick_xml::events::{BytesEnd, BytesStart, BytesText}; diff --git a/src/configure/mod.rs b/src/configure/mod.rs index aa8e72d92..d2d43bc98 100644 --- a/src/configure/mod.rs +++ b/src/configure/mod.rs @@ -1,3 +1,5 @@ +//! Email accounts autoconfiguration process module + use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use crate::config::Config; @@ -563,9 +565,7 @@ fn try_smtp_one_param(context: &Context, param: &LoginParam) -> Option { } } -/******************************************************************************* - * Connect to configured account - ******************************************************************************/ +/// Connects to the configured account pub fn dc_connect_to_configured_imap(context: &Context, imap: &Imap) -> libc::c_int { let mut ret_connected = 0; diff --git a/src/constants.rs b/src/constants.rs index 68783837f..499975956 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,4 +1,4 @@ -//! Constants +//! # Constants #![allow(non_camel_case_types, dead_code)] use deltachat_derive::*; diff --git a/src/contact.rs b/src/contact.rs index e0d882128..8a73ddf5c 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -47,8 +47,8 @@ pub struct Contact { /// May be empty, initially set to `authname`. name: String, /// Name authorized by the contact himself. Only this name may be spread to others, - /// e.g. in To:-lists. May be empty. It is recommended to use `Contact::get_name`, - /// `Contact::get_display_name` or `Contact::get_name_n_addr` to access this field. + /// e.g. in To:-lists. May be empty. It is recommended to use `Contact::get_authname`, + /// to access this field. authname: String, /// E-Mail-Address of the contact. It is recommended to use `Contact::get_addr`` to access this field. addr: String, @@ -717,6 +717,7 @@ impl Contact { &self.addr } + /// Get name authorized by the contact. pub fn get_authname(&self) -> &str { &self.authname } @@ -899,6 +900,7 @@ impl Contact { } } +/// Extracts first name from full name. fn get_first_name<'a>(full_name: &'a str) -> &'a str { full_name.splitn(2, ' ').next().unwrap_or_default() } @@ -909,6 +911,7 @@ pub fn may_be_valid_addr(addr: &str) -> bool { res.is_ok() } +/// Returns address with whitespace trimmed and `mailto:` prefix removed. pub fn addr_normalize(addr: &str) -> &str { let norm = addr.trim(); diff --git a/src/context.rs b/src/context.rs index 2ca85e50a..13e7eec50 100644 --- a/src/context.rs +++ b/src/context.rs @@ -39,7 +39,9 @@ pub type ContextCallback = dyn Fn(&Context, Event) -> uintptr_t + Send + Sync; #[derive(DebugStub)] pub struct Context { + /// Database file path dbfile: PathBuf, + /// Blob directory path blobdir: PathBuf, pub sql: Sql, pub inbox: Arc>, @@ -93,6 +95,7 @@ pub fn get_info() -> HashMap<&'static str, String> { } impl Context { + /// Creates new context. pub fn new(cb: Box, os_name: String, dbfile: PathBuf) -> Result { let mut blob_fname = OsString::new(); blob_fname.push(dbfile.file_name().unwrap_or_default()); @@ -153,10 +156,12 @@ impl Context { Ok(ctx) } + /// Returns database file path. pub fn get_dbfile(&self) -> &Path { self.dbfile.as_path() } + /// Returns blob directory path. pub fn get_blobdir(&self) -> &Path { self.blobdir.as_path() } diff --git a/src/imex.rs b/src/imex.rs index e7fe1d81c..8248cb3a6 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -1,3 +1,5 @@ +//! # Import/export module + use core::cmp::{max, min}; use std::path::Path; diff --git a/src/key.rs b/src/key.rs index 0c0bb0a34..9679f7476 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,3 +1,5 @@ +//! Cryptographic key module + use std::collections::BTreeMap; use std::io::Cursor; use std::path::Path; @@ -11,6 +13,7 @@ use crate::context::Context; use crate::dc_tools::*; use crate::sql::{self, Sql}; +/// Cryptographic key #[derive(Debug, PartialEq, Eq, Clone)] pub enum Key { Public(SignedPublicKey), diff --git a/src/location.rs b/src/location.rs index 38f969a33..b1f7c40d7 100644 --- a/src/location.rs +++ b/src/location.rs @@ -1,3 +1,5 @@ +//! Location handling + use bitflags::bitflags; use quick_xml; use quick_xml::events::{BytesEnd, BytesStart, BytesText}; @@ -16,7 +18,7 @@ use crate::param::*; use crate::sql; use crate::stock::StockMessage; -// location handling +/// Location record #[derive(Debug, Clone, Default)] pub struct Location { pub location_id: u32, diff --git a/src/log.rs b/src/log.rs index b9c1275d3..80c47a4a6 100644 --- a/src/log.rs +++ b/src/log.rs @@ -1,3 +1,5 @@ +//! # Logging macros + #[macro_export] macro_rules! info { ($ctx:expr, $msg:expr) => { diff --git a/src/oauth2.rs b/src/oauth2.rs index edc53f785..bc11fa7c5 100644 --- a/src/oauth2.rs +++ b/src/oauth2.rs @@ -1,3 +1,5 @@ +//! OAuth 2 module + use std::collections::HashMap; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; @@ -33,12 +35,14 @@ struct Oauth2 { get_userinfo: Option<&'static str>, } +/// OAuth 2 Access Token Response #[derive(Debug, Deserialize)] struct Response { // Should always be there according to: https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/ // but previous code handled its abscense. access_token: Option, token_type: String, + /// Duration of time the token is granted for, in seconds expires_in: Option, refresh_token: Option, scope: Option, @@ -205,7 +209,7 @@ pub fn dc_get_oauth2_access_token( .ok(); let expires_in = response .expires_in - // refresh a bet before + // refresh a bit before .map(|t| time() + t as i64 - 5) .unwrap_or_else(|| 0); context diff --git a/src/peerstate.rs b/src/peerstate.rs index 54c22f150..331901f00 100644 --- a/src/peerstate.rs +++ b/src/peerstate.rs @@ -1,3 +1,4 @@ +//! # [Autocrypt Peer State](https://autocrypt.org/level1.html#peer-state-management) module use std::collections::HashSet; use std::fmt; diff --git a/src/pgp.rs b/src/pgp.rs index 757c63d5f..e2f546f4e 100644 --- a/src/pgp.rs +++ b/src/pgp.rs @@ -1,3 +1,5 @@ +//! OpenPGP helper module + use std::collections::{BTreeMap, HashSet}; use std::convert::TryInto; use std::io::Cursor; @@ -106,6 +108,8 @@ fn select_pk_for_encryption(key: &SignedPublicKey) -> Option<&SignedPublicSubKey true) } +/// Encrypts `plain` text using `public_keys_for_encryption` +/// and signs it using `private_key_for_signing`. pub fn pk_encrypt( plain: &[u8], public_keys_for_encryption: &Keyring, diff --git a/src/qr.rs b/src/qr.rs index 72f2b2d65..109af99a2 100644 --- a/src/qr.rs +++ b/src/qr.rs @@ -1,3 +1,5 @@ +//! # QR code module + use lazy_static::lazy_static; use percent_encoding::percent_decode_str; diff --git a/src/securejoin.rs b/src/securejoin.rs index 783f6f3d1..24bbfa94c 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -1,3 +1,5 @@ +//! Verified contact protocol implementation as [specified by countermitm project](https://countermitm.readthedocs.io/en/stable/new.html#setup-contact-protocol) + use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC}; use crate::aheader::EncryptPreference; diff --git a/src/sql.rs b/src/sql.rs index b1f210277..2923083b4 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -1,3 +1,5 @@ +//! # SQLite wrapper + use std::collections::HashSet; use std::sync::{Arc, RwLock}; use std::time::Duration; diff --git a/src/stock.rs b/src/stock.rs index f5d27f0ed..7bafccb58 100644 --- a/src/stock.rs +++ b/src/stock.rs @@ -1,3 +1,5 @@ +//! Module to work with translatable stock strings + use std::borrow::Cow; use strum::EnumProperty; diff --git a/src/token.rs b/src/token.rs index 0ffbe035f..ec04230ce 100644 --- a/src/token.rs +++ b/src/token.rs @@ -1,4 +1,8 @@ +//! # Token module +//! //! Functions to read/write token from/to the database. A token is any string associated with a key. +//! +//! Tokens are used in countermitm verification protocols. use deltachat_derive::*; @@ -6,7 +10,7 @@ use crate::context::Context; use crate::dc_tools::*; use crate::sql; -// Token namespaces +/// Token namespace #[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, ToSql, FromSql)] #[repr(i32)] pub enum Namespace { @@ -21,6 +25,8 @@ impl Default for Namespace { } } +/// Creates a new token and saves it into the database. +/// Returns created token. pub fn save(context: &Context, namespace: Namespace, foreign_id: u32) -> String { // foreign_id may be 0 let token = dc_create_id();