enable unreachable_pub lint

This causes some other lints to start firing too (which is good), but
I'm going to fix them in follow-up commits to keep things organized.
This commit is contained in:
Charles Hall 2024-05-01 22:26:21 -07:00
parent a626e7b0f0
commit d748544f0e
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
111 changed files with 1007 additions and 876 deletions

View file

@ -2,7 +2,7 @@ mod data;
use std::collections::BTreeMap;
pub use data::Data;
pub(crate) use data::Data;
use futures_util::Future;
use regex::RegexSet;
@ -16,14 +16,14 @@ use crate::{services, Result};
/// Compiled regular expressions for a namespace.
#[derive(Clone, Debug)]
pub struct NamespaceRegex {
pub exclusive: Option<RegexSet>,
pub non_exclusive: Option<RegexSet>,
pub(crate) struct NamespaceRegex {
pub(crate) exclusive: Option<RegexSet>,
pub(crate) non_exclusive: Option<RegexSet>,
}
impl NamespaceRegex {
/// Checks if this namespace has rights to a namespace
pub fn is_match(&self, heystack: &str) -> bool {
pub(crate) fn is_match(&self, heystack: &str) -> bool {
if self.is_exclusive_match(heystack) {
return true;
}
@ -37,7 +37,7 @@ impl NamespaceRegex {
}
/// Checks if this namespace has exlusive rights to a namespace
pub fn is_exclusive_match(&self, heystack: &str) -> bool {
pub(crate) fn is_exclusive_match(&self, heystack: &str) -> bool {
if let Some(exclusive) = &self.exclusive {
if exclusive.is_match(heystack) {
return true;
@ -79,20 +79,20 @@ impl TryFrom<Vec<Namespace>> for NamespaceRegex {
/// Appservice registration combined with its compiled regular expressions.
#[derive(Clone, Debug)]
pub struct RegistrationInfo {
pub registration: Registration,
pub users: NamespaceRegex,
pub aliases: NamespaceRegex,
pub rooms: NamespaceRegex,
pub(crate) struct RegistrationInfo {
pub(crate) registration: Registration,
pub(crate) users: NamespaceRegex,
pub(crate) aliases: NamespaceRegex,
pub(crate) rooms: NamespaceRegex,
}
impl RegistrationInfo {
pub fn is_user_match(&self, user_id: &UserId) -> bool {
pub(crate) fn is_user_match(&self, user_id: &UserId) -> bool {
self.users.is_match(user_id.as_str())
|| self.registration.sender_localpart == user_id.localpart()
}
pub fn is_exclusive_user_match(&self, user_id: &UserId) -> bool {
pub(crate) fn is_exclusive_user_match(&self, user_id: &UserId) -> bool {
self.users.is_exclusive_match(user_id.as_str())
|| self.registration.sender_localpart == user_id.localpart()
}
@ -111,13 +111,13 @@ impl TryFrom<Registration> for RegistrationInfo {
type Error = regex::Error;
}
pub struct Service {
pub db: &'static dyn Data,
pub(crate) struct Service {
pub(crate) db: &'static dyn Data,
registration_info: RwLock<BTreeMap<String, RegistrationInfo>>,
}
impl Service {
pub fn build(db: &'static dyn Data) -> Result<Self> {
pub(crate) fn build(db: &'static dyn Data) -> Result<Self> {
let mut registration_info = BTreeMap::new();
// Inserting registrations into cache
for appservice in db.all()? {
@ -136,7 +136,7 @@ impl Service {
})
}
/// Registers an appservice and returns the ID to the caller.
pub async fn register_appservice(&self, yaml: Registration) -> Result<String> {
pub(crate) async fn register_appservice(&self, yaml: Registration) -> Result<String> {
//TODO: Check for collisions between exclusive appservice namespaces
services()
.appservice
@ -153,7 +153,7 @@ impl Service {
/// # Arguments
///
/// * `service_name` - the name you send to register the service previously
pub async fn unregister_appservice(&self, service_name: &str) -> Result<()> {
pub(crate) async fn unregister_appservice(&self, service_name: &str) -> Result<()> {
services()
.appservice
.registration_info
@ -165,7 +165,7 @@ impl Service {
self.db.unregister_appservice(service_name)
}
pub async fn get_registration(&self, id: &str) -> Option<Registration> {
pub(crate) async fn get_registration(&self, id: &str) -> Option<Registration> {
self.registration_info
.read()
.await
@ -174,7 +174,7 @@ impl Service {
.map(|info| info.registration)
}
pub async fn iter_ids(&self) -> Vec<String> {
pub(crate) async fn iter_ids(&self) -> Vec<String> {
self.registration_info
.read()
.await
@ -183,7 +183,7 @@ impl Service {
.collect()
}
pub async fn find_from_token(&self, token: &str) -> Option<RegistrationInfo> {
pub(crate) async fn find_from_token(&self, token: &str) -> Option<RegistrationInfo> {
self.read()
.await
.values()
@ -192,7 +192,7 @@ impl Service {
}
// Checks if a given user id matches any exclusive appservice regex
pub async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool {
pub(crate) async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool {
self.read()
.await
.values()
@ -200,7 +200,7 @@ impl Service {
}
// Checks if a given room alias matches any exclusive appservice regex
pub async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool {
pub(crate) async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool {
self.read()
.await
.values()
@ -208,14 +208,14 @@ impl Service {
}
// Checks if a given room id matches any exclusive appservice regex
pub async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool {
pub(crate) async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool {
self.read()
.await
.values()
.any(|info| info.rooms.is_exclusive_match(room_id.as_str()))
}
pub fn read(
pub(crate) fn read(
&self,
) -> impl Future<Output = tokio::sync::RwLockReadGuard<'_, BTreeMap<String, RegistrationInfo>>>
{