Skip to content

Commit

Permalink
XMPPFramework Swift API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Oct 10, 2017
1 parent 3857180 commit 0ef0e9e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 50 deletions.
13 changes: 0 additions & 13 deletions ChatSecure/Classes/Controllers/FileTransferManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -732,19 +732,6 @@ public extension OTRXMPPRoomMessage {

// MARK: - Extensions

fileprivate extension XMPPMessage {
/** XEP-0066: Out of Band Data jabber:x:oob */
var outOfBandURL: URL? {
guard let oob = elements(forXmlns: "jabber:x:oob").first,
let urlElement = oob.elements(forName: "url").first,
let urlString = urlElement.stringValue else {
return nil
}
let url = URL(string: urlString)
return url
}
}

fileprivate struct HTTPServer {
/// service jid for upload service
let jid: XMPPJID
Expand Down
10 changes: 6 additions & 4 deletions ChatSecure/Classes/Controllers/MessageQueueHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,9 @@ public class MessageQueueHandler:NSObject {
//Ensure protocol is connected or if not and autologin then connnect
if (accountProtocol.connectionStatus == .connected) {
// Add the buddy to our roster
let jid = XMPPJID(string: buddy.username)
accountProtocol.xmppRoster.addUser(jid, withNickname:buddy.displayName)
if let jid = XMPPJID(string: buddy.username) {
accountProtocol.xmppRoster.addUser(jid, withNickname:buddy.displayName)
}
completion(true, 0.0)
} else if (account.autologin == true) {
self.waitingForAccount(account.uniqueId, action: OutstandingActionInfo(action: addBuddyAction, timer: nil, completion: completion))
Expand Down Expand Up @@ -386,8 +387,9 @@ public class MessageQueueHandler:NSObject {
if accountProtocol.connectionStatus == .connected,
let jidStr = removeBuddyAction.buddyJid {
// Add the buddy to our roster
let jid = XMPPJID(string: jidStr)
accountProtocol.xmppRoster.removeUser(jid)
if let jid = XMPPJID(string: jidStr) {
accountProtocol.xmppRoster.removeUser(jid)
}
completion(true, 0.0)
} else if (account.autologin == true) {
self.waitingForAccount(account.uniqueId, action: OutstandingActionInfo(action: removeBuddyAction, timer: nil, completion: completion))
Expand Down
13 changes: 7 additions & 6 deletions ChatSecure/Classes/Controllers/OTROMEMOSignalCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,17 @@ import SignalProtocolObjC
}
var relatedBuddyUsername: String? = fromJID.bare
var innerMessage = message
if (message.isTrustedMessageCarbon(forMyJID: ourJID)) {
if message.isTrustedMessageCarbon(forMyJID: ourJID),
let forwarded = message.messageCarbonForwarded {
//This came from another of our devices this is really going to be an outgoing message
innerMessage = message.messageCarbonForwarded()
if (message.isReceivedMessageCarbon()) {
innerMessage = forwarded
if (message.isReceivedMessageCarbon) {
relatedBuddyUsername = innerMessage.from?.bare
} else {
relatedBuddyUsername = innerMessage.to?.bare
let outgoingMessage = OTROutgoingMessage()
outgoingMessage?.dateSent = Date()
databaseMessage = outgoingMessage!
let outgoingMessage = OTROutgoingMessage()!
outgoingMessage.dateSent = Date()
databaseMessage = outgoingMessage
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import XMPPFramework

open class OTRXMPPChangePasswordManager:NSObject {

fileprivate let completion:(_ success:Bool,_ error:NSError?) -> Void
fileprivate let completion:(_ success:Bool,_ error:Error?) -> Void
fileprivate let registrationModule:XMPPRegistration
fileprivate let password:String
fileprivate let xmppStream:XMPPStream

public init(newPassword:String, xmppStream:XMPPStream, completion:@escaping (_ success:Bool,_ error:NSError?) -> Void) {
public init(newPassword:String, xmppStream:XMPPStream, completion:@escaping (_ success:Bool,_ error:Error?) -> Void) {
self.registrationModule = XMPPRegistration()
self.xmppStream = xmppStream
self.registrationModule.activate(self.xmppStream)
Expand All @@ -39,11 +39,11 @@ open class OTRXMPPChangePasswordManager:NSObject {

extension OTRXMPPChangePasswordManager:XMPPRegistrationDelegate {

public func passwordChangeSuccessful(_ sender: XMPPRegistration!) {
public func passwordChangeSuccessful(_ sender: XMPPRegistration) {
self.completion(true,nil)
}

public func passwordChangeFailed(_ sender: XMPPRegistration!, withError error: Error!) {
self.completion(false,error as NSError)
public func passwordChangeFailed(_ sender: XMPPRegistration, withError error: Error?) {
self.completion(false,error)
}
}
10 changes: 5 additions & 5 deletions ChatSecure/Classes/Model/Yap Storage/OTRXMPPRoomMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ public extension OTRXMPPRoomMessage {
/// Marks our sent messages as delivered when we receive a matching receipt
@objc public static func handleDeliveryReceiptResponse(message: XMPPMessage, writeConnection: YapDatabaseConnection) {
guard message.isGroupChatMessage,
message.hasReceiptResponse(),
message.hasReceiptResponse,
!message.isErrorMessage,
let messageId = message.receiptResponseID() else {
let messageId = message.receiptResponseID else {
return
}
writeConnection.asyncReadWrite { (transaction) in
Expand All @@ -381,9 +381,9 @@ public extension OTRXMPPRoomMessage {

/// Sends a response receipt when receiving a delivery receipt request
@objc public static func handleDeliveryReceiptRequest(message: XMPPMessage, xmppStream:XMPPStream) {
guard message.hasReceiptRequest(),
!message.hasReceiptResponse(),
let response = message.generateReceiptResponse() else {
guard message.hasReceiptRequest,
!message.hasReceiptResponse,
let response = message.generateReceiptResponse else {
return
}
xmppStream.send(response)
Expand Down
14 changes: 8 additions & 6 deletions ChatSecureTests/OTROMEMOIntegrationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class OTROMEMOIntegrationTest: XCTestCase {
}

/** Create two user accounts and save each other as buddies */
func setupTwoAccounts(_ name:String) {
let aliceName = "\(name)-alice"
let bobName = "\(name)-bob"
func setupTwoAccounts(_ inName:String) {
let charactersToRemove = CharacterSet.alphanumerics.inverted
let name = inName.components(separatedBy: charactersToRemove).joined().lowercased()
let aliceName = "\(name).alice"
let bobName = "\(name).bob"
self.aliceUser = self.setupUserWithName(aliceName,buddyName: bobName)
self.aliceOmemoModule = OTROMEMOTestModule(omemoStorage: self.aliceUser!.signalOMEMOCoordinator, xmlNamespace: .conversationsLegacy, dispatchQueue: nil)
self.aliceOmemoModule?.addDelegate(self.aliceUser!.signalOMEMOCoordinator, delegateQueue: self.aliceUser!.signalOMEMOCoordinator.workQueue)
Expand Down Expand Up @@ -81,7 +83,7 @@ class OTROMEMOIntegrationTest: XCTestCase {
*/
func testDeviceSetup() {
self.setupTwoAccounts(#function)
self.bobOmemoModule?.xmppStreamDidAuthenticate(nil)
self.bobOmemoModule?.xmppStreamDidAuthenticate(XMPPStream())
let buddy = self.bobUser!.buddy
let connection = self.bobUser?.databaseManager.readOnlyDatabaseConnection
connection?.read({ (transaction) in
Expand All @@ -99,7 +101,7 @@ class OTROMEMOIntegrationTest: XCTestCase {
*/
func testFetchingBundleSetup() {
self.setupTwoAccounts(#function)
self.bobOmemoModule?.xmppStreamDidAuthenticate(nil)
self.bobOmemoModule?.xmppStreamDidAuthenticate(XMPPStream())
let expectation = self.expectation(description: "Sending Message")
let messageText = "This is message from Bob to Alice"
let message = OTROutgoingMessage()!
Expand Down Expand Up @@ -136,7 +138,7 @@ class OTROMEMOIntegrationTest: XCTestCase {

func testRemoveDevice() {
self.setupTwoAccounts(#function)
self.bobOmemoModule?.xmppStreamDidAuthenticate(nil)
self.bobOmemoModule?.xmppStreamDidAuthenticate(XMPPStream())
let expectation = self.expectation(description: "Remove Devices")
let deviceNumber = NSNumber(value: 5 as Int32)
let device = OTROMEMODevice(deviceId: deviceNumber, trustLevel: OMEMOTrustLevel.trustedTofu, parentKey: self.bobUser!.account.uniqueId, parentCollection: OTRAccount.collection, publicIdentityKeyData: nil, lastSeenDate: nil)
Expand Down
20 changes: 10 additions & 10 deletions ChatSecureTests/OTROMEMOTestModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ class OTROMEMOTestModule: OMEMOModule {
override var xmppStream:XMPPStream {
get {
let stream = XMPPStream()
stream?.myJID = XMPPJID(string:self.thisUser.account.username)
return stream!
stream.myJID = XMPPJID(string:self.thisUser.account.username)
return stream
}
}

/** Manually called after all the otherUser and thisUser are setup */
override func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {

override func xmppStreamDidAuthenticate(_ sender: XMPPStream) {
let bundle = otherUser?.bundle()
XCTAssertNotNil(bundle)
let device = bundle?.deviceId
XCTAssertNotNil(device)
let otherJID = XMPPJID(string:otherUser?.username())!
let otherUserStr = otherUser!.username()
let otherJID = XMPPJID(string:otherUserStr)!
let ourJID = XMPPJID(string:thisUser.account.username)!
//After authentication fake receiving devices from other buddy
self.omemoStorage.storeDeviceIds([NSNumber(value: device! as UInt32)], for: otherJID)
Expand All @@ -50,7 +50,7 @@ class OTROMEMOTestModule: OMEMOModule {
//Empty responses so not nil and have correct elementID.
let response = XMPPIQ(type: "get", to: nil, elementID: elementId, child: nil)
let outgoing = XMPPIQ(type: "get", to: nil, elementID: elementId, child: nil)
(multicastDelegate as AnyObject).omemo!(self, fetchedBundle: self.otherUser!.bundle(), from: jid, responseIq: response!, outgoingIq: outgoing!)
(multicastDelegate as AnyObject).omemo!(self, fetchedBundle: self.otherUser!.bundle(), from: jid, responseIq: response, outgoingIq: outgoing)

}
}
Expand All @@ -59,15 +59,15 @@ class OTROMEMOTestModule: OMEMOModule {
/** When we send key data we automtically route that data to the other user to decrypto*/
override func sendKeyData(_ keyData: [OMEMOKeyData], iv: Data, to toJID: XMPPJID, payload: Data?, elementId: String?) {

self.otherUser?.receiveKeyData(keyData, iv: iv, fromJID: XMPPJID(string:thisUser.account.username), senderDeviceId:(thisUser.signalOMEMOCoordinator.fetchMyBundle()?.deviceId)!, payload: payload, elementId: elementId)
self.otherUser?.receiveKeyData(keyData, iv: iv, fromJID: XMPPJID(string:thisUser.account.username)!, senderDeviceId:(thisUser.signalOMEMOCoordinator.fetchMyBundle()?.deviceId)!, payload: payload, elementId: elementId)
//self.otherUser.signalOMEMOCoordinator.omemo(self, receivedKeyData: keyData, iv: iv, senderDeviceId: (thisUser.signalOMEMOCoordinator.fetchMyBundle()?.deviceId)!, fromJID: XMPPJID.jidWithString(thisUser.account.username), payload: payload, message: dummyMessage)
}

override func removeDeviceIds(_ deviceIds: [NSNumber], elementId: String?) {
self.moduleQueue.async {
let multicastDelegate = self.value(forKey: "multicastDelegate")!
let element = XMPPIQ(type: "resutl", to: self.xmppStream.myJID, elementID: elementId)
(multicastDelegate as AnyObject).omemo!(self, deviceListUpdate: [NSNumber](), from:self.xmppStream.myJID, incomingElement:element!)
let element = XMPPIQ(type: "result", to: self.xmppStream.myJID, elementID: elementId)
(multicastDelegate as AnyObject).omemo!(self, deviceListUpdate: [NSNumber](), from:self.xmppStream.myJID!, incomingElement:element)
}
}
}
Expand All @@ -79,7 +79,7 @@ extension OTROMEMOTestModule: OTROMEMOTestModuleProtocol {

func receiveKeyData(_ keyData: [OMEMOKeyData], iv: Data, fromJID: XMPPJID, senderDeviceId:UInt32, payload: Data?, elementId: String?) {
let dummyMessage = XMPPMessage(type: "chat", elementID: "1234")
self.thisUser.signalOMEMOCoordinator.omemo(self, receivedKeyData: keyData, iv: iv, senderDeviceId: senderDeviceId, from: fromJID, payload: payload, message: dummyMessage!)
self.thisUser.signalOMEMOCoordinator.omemo(self, receivedKeyData: keyData, iv: iv, senderDeviceId: senderDeviceId, from: fromJID, payload: payload, message: dummyMessage)
}

func bundle() -> OMEMOBundle {
Expand Down
2 changes: 1 addition & 1 deletion Submodules/XMPPFramework
Submodule XMPPFramework updated 90 files
+3 −2 Authentication/Anonymous/XMPPAnonymousAuthentication.h
+2 −2 Authentication/Anonymous/XMPPAnonymousAuthentication.m
+2 −1 Authentication/Deprecated-Digest/XMPPDeprecatedDigestAuthentication.h
+2 −2 Authentication/Deprecated-Digest/XMPPDeprecatedDigestAuthentication.m
+2 −1 Authentication/Deprecated-Plain/XMPPDeprecatedPlainAuthentication.h
+2 −2 Authentication/Deprecated-Plain/XMPPDeprecatedPlainAuthentication.m
+2 −1 Authentication/Digest-MD5/XMPPDigestMD5Authentication.h
+6 −6 Authentication/Digest-MD5/XMPPDigestMD5Authentication.m
+2 −1 Authentication/Plain/XMPPPlainAuthentication.h
+2 −2 Authentication/Plain/XMPPPlainAuthentication.m
+2 −0 Authentication/SCRAM-SHA-1/XMPPSCRAMSHA1Authentication.h
+6 −6 Authentication/SCRAM-SHA-1/XMPPSCRAMSHA1Authentication.m
+4 −1 Authentication/X-OAuth2-Google/XMPPXOAuth2Google.h
+2 −2 Authentication/X-OAuth2-Google/XMPPXOAuth2Google.m
+17 −9 Authentication/XMPPCustomBinding.h
+16 −8 Authentication/XMPPSASLAuthentication.h
+9 −3 Core/XMPPInternal.h
+13 −3 Core/XMPPJID.m
+20 −3 Core/XMPPPresence.h
+14 −7 Core/XMPPPresence.m
+12 −12 Core/XMPPStream.m
+2 −2 Extensions/ProcessOne/XMPPProcessOne.m
+2 −2 Extensions/Roster/CoreDataStorage/XMPPResourceCoreDataStorageObject.h
+9 −9 Extensions/Roster/CoreDataStorage/XMPPResourceCoreDataStorageObject.m
+4 −4 Extensions/Roster/CoreDataStorage/XMPPRosterCoreDataStorage.m
+1 −1 Extensions/Roster/CoreDataStorage/XMPPUserCoreDataStorageObject.h
+4 −4 Extensions/Roster/MemoryStorage/XMPPResourceMemoryStorageObject.m
+6 −6 Extensions/Roster/MemoryStorage/XMPPRosterMemoryStorage.m
+6 −5 Extensions/Roster/XMPPResource.h
+18 −13 Extensions/Roster/XMPPRoster.h
+0 −10 Extensions/Roster/XMPPRoster.m
+10 −9 Extensions/Roster/XMPPUser.h
+1 −1 Extensions/XEP-0016/XMPPPrivacy.m
+5 −3 Extensions/XEP-0045/XMPPMUC.h
+3 −3 Extensions/XEP-0045/XMPPMessage+XEP0045.h
+25 −21 Extensions/XEP-0045/XMPPRoom.h
+0 −16 Extensions/XEP-0045/XMPPRoom.m
+10 −9 Extensions/XEP-0045/XMPPRoomMessage.h
+9 −8 Extensions/XEP-0045/XMPPRoomOccupant.h
+4 −3 Extensions/XEP-0045/XMPPRoomPrivate.h
+5 −4 Extensions/XEP-0059/NSXMLElement+XEP_0059.h
+25 −23 Extensions/XEP-0059/XMPPResultSet.h
+23 −19 Extensions/XEP-0060/XMPPPubSub.h
+0 −16 Extensions/XEP-0060/XMPPPubSub.m
+21 −19 Extensions/XEP-0066/XMPPIQ+XEP_0066.h
+8 −6 Extensions/XEP-0066/XMPPMessage+XEP_0066.h
+6 −3 Extensions/XEP-0077/XMPPRegistration.h
+8 −9 Extensions/XEP-0082/NSDate+XMPPDateTimeProfiles.h
+6 −4 Extensions/XEP-0082/XMPPDateTimeProfiles.h
+7 −7 Extensions/XEP-0085/XMPPMessage+XEP_0085.h
+2 −2 Extensions/XEP-0106/NSString+XEP_0106.h
+24 −18 Extensions/XEP-0115/XMPPCapabilities.h
+0 −16 Extensions/XEP-0115/XMPPCapabilities.m
+8 −6 Extensions/XEP-0147/XMPPURI.h
+3 −0 Extensions/XEP-0147/XMPPURI.m
+1 −1 Extensions/XEP-0172/XMPPMessage+XEP_0172.h
+1 −1 Extensions/XEP-0172/XMPPPresence+XEP_0172.h
+6 −5 Extensions/XEP-0184/XMPPMessage+XEP_0184.h
+3 −1 Extensions/XEP-0184/XMPPMessageDeliveryReceipts.h
+7 −7 Extensions/XEP-0198/XMPPStreamManagement.m
+2 −2 Extensions/XEP-0203/NSXMLElement+XEP_0203.h
+3 −2 Extensions/XEP-0223/XEP_0223.h
+3 −3 Extensions/XEP-0224/XMPPAttentionModule.h
+2 −0 Extensions/XEP-0224/XMPPAttentionModule.m
+6 −4 Extensions/XEP-0224/XMPPMessage+XEP_0224.h
+2 −0 Extensions/XEP-0224/XMPPMessage+XEP_0224.m
+9 −7 Extensions/XEP-0280/XMPPMessage+XEP_0280.h
+12 −10 Extensions/XEP-0297/NSXMLElement+XEP_0297.h
+6 −4 Extensions/XEP-0308/XMPPMessage+XEP_0308.h
+17 −6 Extensions/XEP-0313/XMPPMessageArchiveManagement.h
+2 −0 Extensions/XEP-0313/XMPPMessageArchiveManagement.m
+6 −1 Extensions/XEP-0313/XMPPRoomLightCoreDataStorage+XEP_0313.h
+9 −7 Extensions/XEP-0333/XMPPMessage+XEP_0333.h
+8 −6 Extensions/XEP-0335/NSXMLElement+XEP_0335.h
+2 −0 Extensions/XEP-0352/NSXMLElement+XEP_0352.h
+9 −0 README.md
+8 −6 Utilities/GCDMulticastDelegate.h
+18 −32 Utilities/XMPPIDTracker.h
+17 −4 Utilities/XMPPIDTracker.m
+6 −5 Utilities/XMPPStringPrep.h
+4 −0 Utilities/XMPPStringPrep.m
+2 −0 Utilities/XMPPTimer.h
+22 −10 XMPPFramework.xcodeproj/project.pbxproj
+3 −1 XMPPFramework.xcodeproj/xcshareddata/xcschemes/XMPPFramework (iOS).xcscheme
+3 −1 XMPPFramework.xcodeproj/xcshareddata/xcschemes/XMPPFramework (macOS).xcscheme
+3 −1 XMPPFramework.xcodeproj/xcshareddata/xcschemes/XMPPFramework (tvOS).xcscheme
+18 −1 Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj/project.pbxproj
+3 −1 Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj/xcshareddata/xcschemes/XMPPFrameworkTests (iOS).xcscheme
+3 −1 Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj/xcshareddata/xcschemes/XMPPFrameworkTests (macOS).xcscheme
+3 −1 Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj/xcshareddata/xcschemes/XMPPFrameworkTests (tvOS).xcscheme

0 comments on commit 0ef0e9e

Please sign in to comment.