make everything pub(crate) instead of pub
conduwuit is not a library Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
472c32f453
commit
66bb88a03a
135 changed files with 1366 additions and 1247 deletions
|
@ -15,14 +15,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;
|
||||
}
|
||||
|
@ -36,7 +36,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;
|
||||
|
@ -47,11 +47,11 @@ impl 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()
|
||||
}
|
||||
}
|
||||
|
@ -88,11 +88,11 @@ 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 TryFrom<Registration> for RegistrationInfo {
|
||||
|
@ -108,13 +108,13 @@ impl TryFrom<Registration> for RegistrationInfo {
|
|||
}
|
||||
}
|
||||
|
||||
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()? {
|
||||
|
@ -134,7 +134,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
|
||||
|
@ -151,7 +151,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
|
||||
|
@ -163,7 +163,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
|
||||
|
@ -172,7 +172,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
|
||||
|
@ -181,7 +181,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()
|
||||
|
@ -190,7 +190,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()
|
||||
|
@ -198,7 +198,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()
|
||||
|
@ -206,14 +206,16 @@ 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(&self) -> impl Future<Output = tokio::sync::RwLockReadGuard<'_, BTreeMap<String, RegistrationInfo>>> {
|
||||
pub(crate) fn read(
|
||||
&self,
|
||||
) -> impl Future<Output = tokio::sync::RwLockReadGuard<'_, BTreeMap<String, RegistrationInfo>>> {
|
||||
self.registration_info.read()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue