This commit is contained in:
fmodf 2024-12-17 09:34:44 +01:00
parent b9bf1ebfa5
commit 5510dd3900
7 changed files with 38 additions and 35 deletions

View file

@ -79,12 +79,18 @@ struct StartScreen: View {
}
}
final class TestStorage: XMPPClientStorageProtocol {
func updateCredentialsByUUID(_ uuid: UUID, _ credentials: XMPPClientCredentials) async {
print(uuid, credentials)
final class TestStorage: XMPPStorage {
private var rosterVer: [String: String] = [:]
func getRosterVersion(jid: JID) async -> String? {
rosterVer[jid.bare]
}
func getCredentialsByUUID(_ uuid: UUID) async -> XMPPClientCredentials? {
func setRosterVersion(jid: JID, ver: String) async {
rosterVer[jid.bare] = ver
}
func getCredentialsByUUID(_ uuid: UUID) async -> Credentials? {
print(uuid)
return ["password": pass]
}

View file

@ -92,7 +92,7 @@ struct ClientState: Codable & Equatable {
final class XMPPClient {
private var state = ClientState.initial
private let logger = ClientLogger()
private let storage: XMPPClientStorageProtocol
private let storage: XMPPStorage
private lazy var modules: [any XmppModule] = [
SRVResolverModule(),
ConnectionModule(self.fire),
@ -104,7 +104,7 @@ final class XMPPClient {
RosterModule()
]
init(storage: any XMPPClientStorageProtocol, userAgent: UserAgent) {
init(storage: any XMPPStorage, userAgent: UserAgent) {
self.storage = storage
state.userAgent = userAgent
}

View file

@ -1,22 +0,0 @@
import Foundation
typealias XMPPClientStorageProtocol =
AnyObject &
XMPPClientStorageCredentials &
XMPPClientStorageHistory
// For storing credentials
typealias XMPPClientCredentials = [String: String]
protocol XMPPClientStorageCredentials: AnyObject {
func updateCredentialsByUUID(_ uuid: UUID, _ credentials: XMPPClientCredentials) async
func getCredentialsByUUID(_ uuid: UUID) async -> XMPPClientCredentials?
}
// For storing stanza history
protocol XMPPClientStorageHistory:
XMPPClientStorageHistoryIqs &
XMPPClientStorageHistoryMessages &
XMPPClientStorageHistoryPresences {}
protocol XMPPClientStorageHistoryIqs: AnyObject {}
protocol XMPPClientStorageHistoryMessages: AnyObject {}
protocol XMPPClientStorageHistoryPresences: AnyObject {}

View file

@ -0,0 +1,18 @@
import Foundation
typealias Credentials = [String: String]
protocol XMPPStorage: AnyObject {
// credentials
func getCredentialsByUUID(_ uuid: UUID) async -> Credentials?
// roster
func getRosterVersion(jid: JID) async -> String?
func setRosterVersion(jid: JID, ver: String) async
// messages
// omemo
// whatever else
}

View file

@ -42,7 +42,7 @@ protocol AuthorizationMechanism {
final class AuthorizationMechanismImpl: AuthorizationMechanism {
private let type: AuthorizationMechanismType
private let jid: JID
private let credentials: XMPPClientCredentials?
private let credentials: Credentials?
private let userAgent: UserAgent
private let saslType: SaslType
private let channelBind: String?
@ -52,7 +52,7 @@ final class AuthorizationMechanismImpl: AuthorizationMechanism {
private var clientNonce = ""
private var serverSignature = ""
init(type: AuthorizationMechanismType, jid: JID, credentials: XMPPClientCredentials?, saslType: SaslType, userAgent: UserAgent, channelBind: String?, inlines: XMLElement?) {
init(type: AuthorizationMechanismType, jid: JID, credentials: Credentials?, saslType: SaslType, userAgent: UserAgent, channelBind: String?, inlines: XMLElement?) {
self.type = type
self.jid = jid
self.credentials = credentials

View file

@ -17,10 +17,10 @@ enum AuthorizationError: Error {
final class AuthorizationModule: XmppModule {
let id = "Authorization module"
private weak var storage: (any XMPPClientStorageCredentials)?
private weak var storage: (any XMPPStorage)?
private var mechanism: AuthorizationMechanism?
init(_ storage: any XMPPClientStorageCredentials) {
init(_ storage: any XMPPStorage) {
self.storage = storage
}
@ -79,7 +79,7 @@ private extension AuthorizationModule {
["tls-exporter", "tls-server-end-point"]
}
func selectBestAuthMechanism(_ xml: XMLElement, _ isPlainAllowed: Bool, _ state: ClientState, _ creds: XMPPClientCredentials?) async -> Event {
func selectBestAuthMechanism(_ xml: XMLElement, _ isPlainAllowed: Bool, _ state: ClientState, _ creds: Credentials?) async -> Event {
await withCheckedContinuation { continuation in
var sasl1: [AuthorizationMechanismType] = []
var channelBindings: [String] = []

View file

@ -3,9 +3,9 @@ import Foundation
final class StanzaModule: XmppModule {
let id = "Stanza module"
private weak var storage: XMPPClientStorageHistory?
private weak var storage: XMPPStorage?
init(_ storage: any XMPPClientStorageHistory) {
init(_ storage: any XMPPStorage) {
self.storage = storage
}
@ -43,6 +43,7 @@ final class StanzaModule: XmppModule {
// MARK: Save history
private extension StanzaModule {
func saveStanza(_ state: ClientState, _ stanza: Stanza, inbound: Bool) async {
guard let storage else { return }
print(state, stanza, inbound)
}
}