wip
This commit is contained in:
parent
b9bf1ebfa5
commit
5510dd3900
|
@ -79,12 +79,18 @@ struct StartScreen: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class TestStorage: XMPPClientStorageProtocol {
|
final class TestStorage: XMPPStorage {
|
||||||
func updateCredentialsByUUID(_ uuid: UUID, _ credentials: XMPPClientCredentials) async {
|
private var rosterVer: [String: String] = [:]
|
||||||
print(uuid, credentials)
|
|
||||||
|
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)
|
print(uuid)
|
||||||
return ["password": pass]
|
return ["password": pass]
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ struct ClientState: Codable & Equatable {
|
||||||
final class XMPPClient {
|
final class XMPPClient {
|
||||||
private var state = ClientState.initial
|
private var state = ClientState.initial
|
||||||
private let logger = ClientLogger()
|
private let logger = ClientLogger()
|
||||||
private let storage: XMPPClientStorageProtocol
|
private let storage: XMPPStorage
|
||||||
private lazy var modules: [any XmppModule] = [
|
private lazy var modules: [any XmppModule] = [
|
||||||
SRVResolverModule(),
|
SRVResolverModule(),
|
||||||
ConnectionModule(self.fire),
|
ConnectionModule(self.fire),
|
||||||
|
@ -104,7 +104,7 @@ final class XMPPClient {
|
||||||
RosterModule()
|
RosterModule()
|
||||||
]
|
]
|
||||||
|
|
||||||
init(storage: any XMPPClientStorageProtocol, userAgent: UserAgent) {
|
init(storage: any XMPPStorage, userAgent: UserAgent) {
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
state.userAgent = userAgent
|
state.userAgent = userAgent
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {}
|
|
18
AnotherIM/xmpp/XMPPStorage.swift
Normal file
18
AnotherIM/xmpp/XMPPStorage.swift
Normal 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
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ protocol AuthorizationMechanism {
|
||||||
final class AuthorizationMechanismImpl: AuthorizationMechanism {
|
final class AuthorizationMechanismImpl: AuthorizationMechanism {
|
||||||
private let type: AuthorizationMechanismType
|
private let type: AuthorizationMechanismType
|
||||||
private let jid: JID
|
private let jid: JID
|
||||||
private let credentials: XMPPClientCredentials?
|
private let credentials: Credentials?
|
||||||
private let userAgent: UserAgent
|
private let userAgent: UserAgent
|
||||||
private let saslType: SaslType
|
private let saslType: SaslType
|
||||||
private let channelBind: String?
|
private let channelBind: String?
|
||||||
|
@ -52,7 +52,7 @@ final class AuthorizationMechanismImpl: AuthorizationMechanism {
|
||||||
private var clientNonce = ""
|
private var clientNonce = ""
|
||||||
private var serverSignature = ""
|
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.type = type
|
||||||
self.jid = jid
|
self.jid = jid
|
||||||
self.credentials = credentials
|
self.credentials = credentials
|
||||||
|
|
|
@ -17,10 +17,10 @@ enum AuthorizationError: Error {
|
||||||
final class AuthorizationModule: XmppModule {
|
final class AuthorizationModule: XmppModule {
|
||||||
let id = "Authorization module"
|
let id = "Authorization module"
|
||||||
|
|
||||||
private weak var storage: (any XMPPClientStorageCredentials)?
|
private weak var storage: (any XMPPStorage)?
|
||||||
private var mechanism: AuthorizationMechanism?
|
private var mechanism: AuthorizationMechanism?
|
||||||
|
|
||||||
init(_ storage: any XMPPClientStorageCredentials) {
|
init(_ storage: any XMPPStorage) {
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ private extension AuthorizationModule {
|
||||||
["tls-exporter", "tls-server-end-point"]
|
["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
|
await withCheckedContinuation { continuation in
|
||||||
var sasl1: [AuthorizationMechanismType] = []
|
var sasl1: [AuthorizationMechanismType] = []
|
||||||
var channelBindings: [String] = []
|
var channelBindings: [String] = []
|
||||||
|
|
|
@ -3,9 +3,9 @@ import Foundation
|
||||||
final class StanzaModule: XmppModule {
|
final class StanzaModule: XmppModule {
|
||||||
let id = "Stanza module"
|
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
|
self.storage = storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ final class StanzaModule: XmppModule {
|
||||||
// MARK: Save history
|
// MARK: Save history
|
||||||
private extension StanzaModule {
|
private extension StanzaModule {
|
||||||
func saveStanza(_ state: ClientState, _ stanza: Stanza, inbound: Bool) async {
|
func saveStanza(_ state: ClientState, _ stanza: Stanza, inbound: Bool) async {
|
||||||
|
guard let storage else { return }
|
||||||
print(state, stanza, inbound)
|
print(state, stanza, inbound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue