Merge branch 'charlesmchen/requestFactory'

This commit is contained in:
Matthew Chen 2018-03-02 16:59:59 -05:00
commit b023e77d0e
80 changed files with 473 additions and 1091 deletions

2
Pods

@ -1 +1 @@
Subproject commit 54aac3475a78b5633781c440f2596da4c66ec6d9
Subproject commit aae15b5fb1fc718f19b862390b61f540e45a36ee

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -118,7 +118,7 @@ class MessageFetcherJob: NSObject {
return nil
}
guard let type = OWSSignalServiceProtosEnvelopeType(rawValue:typeInt) else {
guard let type = OWSSignalServiceProtosEnvelopeType(rawValue: typeInt) else {
Logger.error("\(self.logTag) message body type was invalid")
return nil
}
@ -165,10 +165,9 @@ class MessageFetcherJob: NSObject {
private func fetchUndeliveredMessages() -> Promise<(envelopes: [OWSSignalServiceProtosEnvelope], more: Bool)> {
return Promise { fulfill, reject in
let messagesRequest = OWSGetMessagesRequest()
let request = OWSRequestFactory.getMessagesRequest()
self.networkManager.makeRequest(
messagesRequest,
request,
success: { (_: URLSessionDataTask?, responseObject: Any?) -> Void in
guard let (envelopes, more) = self.parseMessagesResponse(responseObject: responseObject) else {
Logger.error("\(self.logTag) response object had unexpected content")
@ -189,7 +188,7 @@ class MessageFetcherJob: NSObject {
}
private func acknowledgeDelivery(envelope: OWSSignalServiceProtosEnvelope) {
let request = OWSAcknowledgeMessageDeliveryRequest(source: envelope.source, timestamp: envelope.timestamp)
let request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: envelope.source, timestamp: envelope.timestamp)
self.networkManager.makeRequest(request,
success: { (_: URLSessionDataTask?, _: Any?) -> Void in
Logger.debug("\(self.logTag) acknowledged delivery for message at timestamp: \(envelope.timestamp)")

View File

@ -116,7 +116,7 @@ class AccountManager: NSObject {
func getTurnServerInfo() -> Promise<TurnServerInfo> {
return Promise { fulfill, reject in
self.networkManager.makeRequest(TurnServerInfoRequest(),
self.networkManager.makeRequest(OWSRequestFactory.turnServerInfoRequest(),
success: { (_: URLSessionDataTask, responseObject: Any?) in
guard responseObject != nil else {
return reject(OWSErrorMakeUnableToProcessServerResponseError())

View File

@ -73,7 +73,6 @@
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
#import <SignalServiceKit/NSString+SSK.h>
#import <SignalServiceKit/NSTimer+OWS.h>
#import <SignalServiceKit/OWSAcknowledgeMessageDeliveryRequest.h>
#import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/OWSAnalyticsEvents.h>
#import <SignalServiceKit/OWSAsserts.h>
@ -90,8 +89,6 @@
#import <SignalServiceKit/OWSEndSessionMessage.h>
#import <SignalServiceKit/OWSError.h>
#import <SignalServiceKit/OWSFileSystem.h>
#import <SignalServiceKit/OWSGetMessagesRequest.h>
#import <SignalServiceKit/OWSGetProfileRequest.h>
#import <SignalServiceKit/OWSIdentityManager.h>
#import <SignalServiceKit/OWSMessageManager.h>
#import <SignalServiceKit/OWSMessageReceiver.h>
@ -99,9 +96,9 @@
#import <SignalServiceKit/OWSOutgoingCallMessage.h>
#import <SignalServiceKit/OWSProfileKeyMessage.h>
#import <SignalServiceKit/OWSRecipientIdentity.h>
#import <SignalServiceKit/OWSRequestFactory.h>
#import <SignalServiceKit/OWSSignalService.h>
#import <SignalServiceKit/OWSSyncContactsMessage.h>
#import <SignalServiceKit/OWSTurnServerInfoRequest.h>
#import <SignalServiceKit/PhoneNumber.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/SignalRecipient.h>

View File

@ -714,7 +714,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Presentation
- (void)presentFromViewController:(UIViewController *)viewController replacingView:(UIView *)view;
- (void)presentFromViewController:(UIViewController *)viewController replacingView:(UIView *)view
{
self.replacingView = view;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self];

View File

@ -147,7 +147,7 @@ NS_ASSUME_NONNULL_BEGIN
[UIApplication.sharedApplication endBackgroundTask:backgroundTaskIdentifier];
}
- (void)ensureSleepBlocking:(BOOL)shouldBeBlocking blockingObjects:(NSArray<id> *)blockingObjects;
- (void)ensureSleepBlocking:(BOOL)shouldBeBlocking blockingObjects:(NSArray<id> *)blockingObjects
{
if (UIApplication.sharedApplication.isIdleTimerDisabled != shouldBeBlocking) {
if (shouldBeBlocking) {

View File

@ -38,7 +38,7 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
@implementation SharingThreadPickerViewController
- (instancetype)initWithShareViewDelegate:(id<ShareViewDelegate>)shareViewDelegate;
- (instancetype)initWithShareViewDelegate:(id<ShareViewDelegate>)shareViewDelegate
{
self = [super init];
if (!self) {

View File

@ -223,7 +223,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
});
}
- (void)buildSignalAccountsAndClearStaleCache:(BOOL)shouldClearStaleCache;
- (void)buildSignalAccountsAndClearStaleCache:(BOOL)shouldClearStaleCache
{
dispatch_async(self.serialQueue, ^{
NSMutableArray<SignalAccount *> *signalAccounts = [NSMutableArray new];

View File

@ -10,6 +10,7 @@
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/AppVersion.h>
#import <SignalServiceKit/NSUserDefaults+OWS.h>
#import <SignalServiceKit/OWSRequestFactory.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSNetworkManager.h>
#import <YapDatabase/YapDatabase.h>
@ -137,7 +138,7 @@ NS_ASSUME_NONNULL_BEGIN
__block BOOL success;
TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc] initWithManualMessageFetching:NO];
TSRequest *request = [OWSRequestFactory updateAttributesRequestWithManualMessageFetching:NO];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
success = YES;

View File

@ -3,9 +3,9 @@
//
#import "OWS103EnableVideoCalling.h"
#import <SignalServiceKit/OWSRequestFactory.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSNetworkManager.h>
#import <SignalServiceKit/TSUpdateAttributesRequest.h>
// Increment a similar constant for every future DBMigration
static NSString *const OWS103EnableVideoCallingMigrationId = @"103";
@ -25,7 +25,7 @@ static NSString *const OWS103EnableVideoCallingMigrationId = @"103";
DDLogWarn(@"%@ running migration...", self.logTag);
if ([TSAccountManager isRegistered]) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc] initWithManualMessageFetching:NO];
TSRequest *request = [OWSRequestFactory updateAttributesRequestWithManualMessageFetching:NO];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
DDLogInfo(@"%@ successfully ran", self.logTag);

View File

@ -25,7 +25,6 @@
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSNetworkManager.h>
#import <SignalServiceKit/TSProfileAvatarUploadFormRequest.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
#import <SignalServiceKit/TSYapDatabaseObject.h>
@ -364,7 +363,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// See: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html
TSProfileAvatarUploadFormRequest *formRequest = [TSProfileAvatarUploadFormRequest new];
TSRequest *formRequest = [OWSRequestFactory profileAvatarUploadFormRequest];
// TODO: Since this form request causes the server to reset my avatar URL, if the update fails
// at some point from here on out, we want the user to understand they probably no longer have
@ -711,7 +710,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
}];
}
- (void)setProfileKeyData:(NSData *)profileKeyData forRecipientId:(NSString *)recipientId;
- (void)setProfileKeyData:(NSData *)profileKeyData forRecipientId:(NSString *)recipientId
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
OWSAES256Key *_Nullable profileKey = [OWSAES256Key keyWithData:profileKeyData];
@ -896,7 +895,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
- (void)updateProfileForRecipientId:(NSString *)recipientId
profileNameEncrypted:(nullable NSData *)profileNameEncrypted
avatarUrlPath:(nullable NSString *)avatarUrlPath;
avatarUrlPath:(nullable NSString *)avatarUrlPath
{
OWSAssert(recipientId.length > 0);

View File

@ -262,7 +262,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
- (void)clearWithProfileKey:(OWSAES256Key *)profileKey
dbConnection:(YapDatabaseConnection *)dbConnection
completion:(nullable OWSUserProfileCompletion)completion;
completion:(nullable OWSUserProfileCompletion)completion
{
[self applyChanges:^(OWSUserProfile *userProfile) {
[userProfile setProfileKey:profileKey];
@ -279,7 +279,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
- (void)updateWithProfileKey:(OWSAES256Key *)profileKey
dbConnection:(YapDatabaseConnection *)dbConnection
completion:(nullable OWSUserProfileCompletion)completion;
completion:(nullable OWSUserProfileCompletion)completion
{
OWSAssert(profileKey);

View File

@ -26,7 +26,7 @@ public class ProfileFetcherJob: NSObject {
@objc
public class func run(recipientId: String, networkManager: TSNetworkManager, ignoreThrottling: Bool) {
ProfileFetcherJob(networkManager: networkManager, ignoreThrottling:ignoreThrottling).run(recipientIds: [recipientId])
ProfileFetcherJob(networkManager: networkManager, ignoreThrottling: ignoreThrottling).run(recipientIds: [recipientId])
}
public init(networkManager: TSNetworkManager, ignoreThrottling: Bool = false) {
@ -95,7 +95,7 @@ public class ProfileFetcherJob: NSObject {
Logger.error("\(self.TAG) getProfile: \(recipientId)")
let request = OWSGetProfileRequest(recipientId: recipientId)
let request = OWSRequestFactory.getProfileRequest(withRecipientId: recipientId)
let (promise, fulfill, reject) = Promise<SignalServiceProfile>.pending()

View File

@ -9,11 +9,12 @@
#import "NSNotificationCenter+OWS.h"
#import "NSURLSessionDataTask+StatusCode.h"
#import "OWSError.h"
#import "OWSRequestFactory.h"
#import "SecurityUtils.h"
#import "TSNetworkManager.h"
#import "TSPreKeyManager.h"
#import "TSSocketManager.h"
#import "TSStorageManager+SessionStore.h"
#import "TSVerifyCodeRequest.h"
#import "YapDatabaseConnection+OWS.h"
#import <YapDatabase/YapDatabase.h>
@ -244,9 +245,8 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
failure:(void (^)(NSError *))failureHandler
remainingRetries:(int)remainingRetries
{
TSRegisterForPushRequest *request =
[[TSRegisterForPushRequest alloc] initWithPushIdentifier:pushToken voipIdentifier:voipToken];
TSRequest *request =
[OWSRequestFactory registerForPushRequestWithPushIdentifier:pushToken voipIdentifier:voipToken];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
successHandler();
@ -284,10 +284,11 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
TSAccountManager *manager = [self sharedInstance];
manager.phoneNumberAwaitingVerification = phoneNumber;
[[TSNetworkManager sharedManager]
makeRequest:[[TSRequestVerificationCodeRequest alloc]
initWithPhoneNumber:phoneNumber
transport:isSMS ? TSVerificationTransportSMS : TSVerificationTransportVoice]
TSRequest *request =
[OWSRequestFactory requestVerificationCodeRequestWithPhoneNumber:phoneNumber
transport:(isSMS ? TSVerificationTransportSMS
: TSVerificationTransportVoice)];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
DDLogInfo(@"%@ Successfully requested verification code request for number: %@ method:%@",
self.logTag,
@ -327,7 +328,7 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
- (void)registerForManualMessageFetchingWithSuccess:(void (^)(void))successBlock
failure:(void (^)(NSError *error))failureBlock
{
TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc] initWithManualMessageFetching:YES];
TSRequest *request = [OWSRequestFactory updateAttributesRequestWithManualMessageFetching:YES];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *_Nonnull task, id _Nonnull responseObject) {
DDLogInfo(@"%@ updated server with account attributes to enableManualFetching", self.logTag);
@ -464,7 +465,8 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
+ (void)unregisterTextSecureWithSuccess:(void (^)(void))success failure:(void (^)(NSError *error))failureBlock
{
[[TSNetworkManager sharedManager] makeRequest:[[TSUnregisterAccountRequest alloc] init]
TSRequest *request = [OWSRequestFactory unregisterAccountRequest];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
DDLogInfo(@"%@ Successfully unregistered", self.logTag);
success();

View File

@ -7,8 +7,8 @@
#import "NSDate+OWS.h"
#import "NSURLSessionDataTask+StatusCode.h"
#import "OWSIdentityManager.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
#import "TSRegisterSignedPrekeyRequest.h"
#import "TSStorageHeaders.h"
#import "TSStorageManager+SignedPreKeyStore.h"
@ -160,14 +160,13 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
// service to prevent race conditions and other edge cases.
[storageManager storePreKeyRecords:preKeys];
request = [[TSRegisterPrekeysRequest alloc]
initWithPrekeyArray:preKeys
identityKey:identityKeyPair.publicKey
signedPreKeyRecord:signedPreKey
preKeyLastResort:lastResortPreKey];
request = [OWSRequestFactory registerPrekeysRequestWithPrekeyArray:preKeys
identityKey:identityKeyPair.publicKey
signedPreKey:signedPreKey
preKeyLastResort:lastResortPreKey];
} else {
description = @"just signed prekey";
request = [[TSRegisterSignedPrekeyRequest alloc] initWithSignedPreKeyRecord:signedPreKey];
request = [OWSRequestFactory registerSignedPrekeyRequestWithSignedPreKeyRecord:signedPreKey];
}
[[TSNetworkManager sharedManager] makeRequest:request
@ -236,7 +235,7 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
// one-time keys in this case.
//
// We do not need a "one-time only" mode.
TSAvailablePreKeysCountRequest *preKeyCountRequest = [[TSAvailablePreKeysCountRequest alloc] init];
TSRequest *preKeyCountRequest = [OWSRequestFactory availablePreKeysCountRequest];
[[TSNetworkManager sharedManager] makeRequest:preKeyCountRequest
success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) {
NSString *preKeyCountKey = @"count";
@ -295,7 +294,7 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5;
// If we didn't update the prekeys, our local "current signed key" state should
// agree with the service's "current signed key" state. Let's verify that,
// since it's closely related to the issues we saw with the 2.7.0.10 release.
TSRequest *currentSignedPreKey = [[TSCurrentSignedPreKeyRequest alloc] init];
TSRequest *currentSignedPreKey = [OWSRequestFactory currentSignedPreKeyRequest];
[[TSNetworkManager sharedManager] makeRequest:currentSignedPreKey
success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) {
NSString *keyIdDictKey = @"keyId";

View File

@ -1,13 +1,13 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "ContactsUpdater.h"
#import "Contact.h"
#import "Cryptography.h"
#import "OWSError.h"
#import "OWSRequestFactory.h"
#import "PhoneNumber.h"
#import "TSContactsIntersectionRequest.h"
#import "TSNetworkManager.h"
#import "TSStorageManager.h"
#import <YapDatabase/YapDatabase.h>
@ -163,7 +163,7 @@ NS_ASSUME_NONNULL_BEGIN
}
NSArray *hashes = [phoneNumbersByHashes allKeys];
TSRequest *request = [[TSContactsIntersectionRequest alloc] initWithHashesArray:hashes];
TSRequest *request = [OWSRequestFactory contactsIntersectionRequestWithHashesArray:hashes];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *tsTask, id responseDict) {
NSMutableDictionary *attributesForIdentifier = [NSMutableDictionary dictionary];

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSLinkedDeviceReadReceipt.h"
@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSLinkedDeviceReadReceipt
- (instancetype)initWithSenderId:(NSString *)senderId timestamp:(uint64_t)timestamp;
- (instancetype)initWithSenderId:(NSString *)senderId timestamp:(uint64_t)timestamp
{
OWSAssert(senderId.length > 0 && timestamp > 0);

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSReadReceiptsForSenderMessage.h"
@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSReadReceiptsForSenderMessage
- (instancetype)initWithThread:(nullable TSThread *)thread messageTimestamps:(NSArray<NSNumber *> *)messageTimestamps;
- (instancetype)initWithThread:(nullable TSThread *)thread messageTimestamps:(NSArray<NSNumber *> *)messageTimestamps
{
self = [super initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread];
if (!self) {

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSAttachmentsProcessor.h"
@ -9,9 +9,9 @@
#import "NSNotificationCenter+OWS.h"
#import "OWSBackgroundTask.h"
#import "OWSError.h"
#import "OWSRequestFactory.h"
#import "OWSSignalServiceProtos.pb.h"
#import "TSAttachmentPointer.h"
#import "TSAttachmentRequest.h"
#import "TSAttachmentStream.h"
#import "TSGroupModel.h"
#import "TSGroupThread.h"
@ -186,9 +186,10 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
if (attachment.serverId < 100) {
DDLogError(@"%@ Suspicious attachment id: %llu", self.logTag, (unsigned long long)attachment.serverId);
}
TSAttachmentRequest *attachmentRequest = [[TSAttachmentRequest alloc] initWithId:attachment.serverId relay:attachment.relay];
TSRequest *request =
[OWSRequestFactory attachmentRequestWithAttachmentId:attachment.serverId relay:attachment.relay];
[self.networkManager makeRequest:attachmentRequest
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
if (![responseObject isKindOfClass:[NSDictionary class]]) {
DDLogError(@"%@ Failed retrieval of attachment. Response had unexpected format.", self.logTag);

View File

@ -1,9 +1,10 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSOutgoingSyncMessage.h"
#import "Cryptography.h"
#import "NSDate+OWS.h"
#import "OWSSignalServiceProtos.pb.h"
#import "ProtoBuf+OWS.h"
@ -11,6 +12,16 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSOutgoingSyncMessage
- (instancetype)init
{
self = [super initWithTimestamp:[NSDate ows_millisecondTimeStamp]];
if (!self) {
return self;
}
return self;
}
- (BOOL)shouldBeSaved
{
return NO;

View File

@ -16,6 +16,7 @@
#import "OWSMessageServiceParams.h"
#import "OWSOutgoingSentMessageTranscript.h"
#import "OWSOutgoingSyncMessage.h"
#import "OWSRequestFactory.h"
#import "OWSUploadingService.h"
#import "PreKeyBundle+jsonDict.h"
#import "SignalRecipient.h"
@ -958,6 +959,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// 2. Check SignalRecipient's state.
BOOL hasDeviceMessages = deviceMessages.count > 0;
DDLogInfo(@"%@ mayHaveLinkedDevices: %d, hasDeviceMessages: %d",
self.logTag,
mayHaveLinkedDevices,
hasDeviceMessages);
if (!mayHaveLinkedDevices && !hasDeviceMessages) {
DDLogInfo(@"%@ Ignoring sync message without secondary devices: %@", self.logTag, [message class]);
OWSAssert([message isKindOfClass:[OWSOutgoingSyncMessage class]]);
@ -997,10 +1003,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
DDLogWarn(@"%@ Sending a message with no device messages.", self.logTag);
}
TSSubmitMessageRequest *request = [[TSSubmitMessageRequest alloc] initWithRecipient:recipient.uniqueId
messages:deviceMessages
relay:recipient.relay
timeStamp:message.timestamp];
TSRequest *request = [OWSRequestFactory submitMessageRequestWithRecipient:recipient.uniqueId
messages:deviceMessages
relay:recipient.relay
timeStamp:message.timestamp];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
if (isLocalNumber && deviceMessages.count == 0) {
@ -1339,7 +1345,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// are called _off_ the main thread. Otherwise we'll deadlock if the main
// thread is blocked on opening a transaction.
TSRequest *request =
[[TSRecipientPrekeyRequest alloc] initWithRecipient:identifier deviceId:[deviceNumber stringValue]];
[OWSRequestFactory recipientPrekeyRequestWithRecipient:identifier deviceId:[deviceNumber stringValue]];
[self.networkManager makeRequest:request
completionQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
success:^(NSURLSessionDataTask *task, id responseObject) {

View File

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningCodeService.h"
#import "OWSDeviceProvisioningCodeRequest.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
NS_ASSUME_NONNULL_BEGIN
@ -39,7 +39,8 @@ NSString *const OWSDeviceProvisioningCodeServiceProvisioningCodeKey = @"verifica
- (void)requestProvisioningCodeWithSuccess:(void (^)(NSString *))successCallback
failure:(void (^)(NSError *))failureCallback
{
[self.networkManager makeRequest:[OWSDeviceProvisioningCodeRequest new]
TSRequest *request = [OWSRequestFactory deviceProvisioningCodeRequest];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
DDLogVerbose(@"ProvisioningCode request succeeded");
if ([(NSObject *)responseObject isKindOfClass:[NSDictionary class]]) {

View File

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningService.h"
#import "OWSDeviceProvisioningRequest.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
NS_ASSUME_NONNULL_BEGIN
@ -38,9 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
success:(void (^)(void))successCallback
failure:(void (^)(NSError *))failureCallback
{
OWSDeviceProvisioningRequest *request =
[[OWSDeviceProvisioningRequest alloc] initWithMessageBody:messageBody ephemeralDeviceId:deviceId];
TSRequest *request =
[OWSRequestFactory deviceProvisioningRequestWithMessageBody:messageBody ephemeralDeviceId:deviceId];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
DDLogVerbose(@"Provisioning request succeeded");

View File

@ -1,12 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDevicesService.h"
#import "OWSDeleteDeviceRequest.h"
#import "OWSDevice.h"
#import "OWSError.h"
#import "OWSGetDevicesRequest.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
#import <Mantle/MTLJSONAdapter.h>
@ -17,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)getDevicesWithSuccess:(void (^)(NSArray<OWSDevice *> *))successCallback
failure:(void (^)(NSError *))failureCallback
{
OWSGetDevicesRequest *request = [OWSGetDevicesRequest new];
TSRequest *request = [OWSRequestFactory getDevicesRequest];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
DDLogVerbose(@"Get devices request succeeded");
@ -44,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
success:(void (^)(void))successCallback
failure:(void (^)(NSError *))failureCallback
{
OWSDeleteDeviceRequest *request = [[OWSDeleteDeviceRequest alloc] initWithDevice:device];
TSRequest *request = [OWSRequestFactory deleteDeviceRequestWithDevice:device];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSUploadingService.h"
@ -8,6 +8,7 @@
#import "NSNotificationCenter+OWS.h"
#import "OWSError.h"
#import "OWSMessageSender.h"
#import "OWSRequestFactory.h"
#import "TSAttachmentStream.h"
#import "TSNetworkManager.h"
#import "TSOutgoingMessage.h"
@ -67,8 +68,8 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f;
[self fireProgressNotification:kAttachmentUploadProgressTheta attachmentId:attachmentStream.uniqueId];
TSRequest *allocateAttachment = [[TSAllocAttachmentRequest alloc] init];
[self.networkManager makeRequest:allocateAttachment
TSRequest *request = [OWSRequestFactory allocAttachmentRequest];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
dispatch_async([OWSDispatch attachmentsQueue], ^{ // TODO can we move this queue specification up a level?
if (![responseObject isKindOfClass:[NSDictionary class]]) {

View File

@ -1,14 +0,0 @@
// Created by Michael Kirk on 12/19/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSAcknowledgeMessageDeliveryRequest : TSRequest
- (instancetype)initWithSource:(NSString *)source timestamp:(UInt64)timestamp;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,23 +0,0 @@
// Created by Michael Kirk on 12/19/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "OWSAcknowledgeMessageDeliveryRequest.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSAcknowledgeMessageDeliveryRequest
- (instancetype)initWithSource:(NSString *)source timestamp:(UInt64)timestamp
{
NSString *path = [NSString stringWithFormat:@"v1/messages/%@/%llu", source, timestamp];
NSURL *url = [NSURL URLWithString:path];
self = [super initWithURL:url];
self.HTTPMethod = @"DELETE";
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,17 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@class OWSDevice;
@interface OWSDeleteDeviceRequest : TSRequest
- (instancetype)initWithDevice:(OWSDevice *)device;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,27 +0,0 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "OWSDeleteDeviceRequest.h"
#import "OWSDevice.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSDeleteDeviceRequest
- (instancetype)initWithDevice:(OWSDevice *)device
{
NSString *deleteDevicePath = [NSString
stringWithFormat:textSecureDevicesAPIFormat, [NSString stringWithFormat:@"%ld", (long)device.deviceId]];
self = [super initWithURL:[NSURL URLWithString:deleteDevicePath]];
if (!self) {
return self;
}
[self setHTTPMethod:@"DELETE"];
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,11 +0,0 @@
// Copyright (c) 2016 Open Whisper Systems. All rights reserved.
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSDeviceProvisioningCodeRequest : TSRequest
@end
NS_ASSUME_NONNULL_END

View File

@ -1,24 +0,0 @@
// Copyright (c) 2016 Open Whisper Systems. All rights reserved.
#import "OWSDeviceProvisioningCodeRequest.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSDeviceProvisioningCodeRequest
- (instancetype)init
{
self = [super initWithURL:[NSURL URLWithString:textSecureDeviceProvisioningCodeAPI]];
if (!self) {
return self;
}
[self setHTTPMethod:@"GET"];
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,13 +0,0 @@
// Copyright (c) 2016 Open Whisper Systems. All rights reserved.
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSDeviceProvisioningRequest : TSRequest
- (instancetype)initWithMessageBody:(NSData *)messageBody ephemeralDeviceId:(NSString *)deviceId;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,32 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningRequest.h"
#import "TSConstants.h"
#import <SignalServiceKit/NSData+Base64.h>
NS_ASSUME_NONNULL_BEGIN
@implementation OWSDeviceProvisioningRequest
- (instancetype)initWithMessageBody:(NSData *)messageBody ephemeralDeviceId:(NSString *)deviceId
{
NSString *path = [NSString stringWithFormat:textSecureDeviceProvisioningAPIFormat, deviceId];
self = [super initWithURL:[NSURL URLWithString:path]];
if (!self) {
return self;
}
self.HTTPMethod = @"PUT";
self.parameters = @{
@"body" : [messageBody base64EncodedString],
};
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,11 +0,0 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSGetDevicesRequest : TSRequest
@end
NS_ASSUME_NONNULL_END

View File

@ -1,25 +0,0 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "OWSGetDevicesRequest.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSGetDevicesRequest
- (instancetype)init
{
NSString *getDevicesPath = [NSString stringWithFormat:textSecureDevicesAPIFormat, @""];
self = [super initWithURL:[NSURL URLWithString:getDevicesPath]];
if (!self) {
return self;
}
[self setHTTPMethod:@"GET"];
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,12 +0,0 @@
// Created by Michael Kirk on 12/19/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSGetMessagesRequest : TSRequest
@end
NS_ASSUME_NONNULL_END

View File

@ -1,18 +0,0 @@
// Created by Michael Kirk on 12/19/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "OWSGetMessagesRequest.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSGetMessagesRequest
- (instancetype)init
{
NSURL *url = [NSURL URLWithString:@"v1/messages"];
return [super initWithURL:url];
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,15 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSGetProfileRequest : TSRequest
- (instancetype)initWithRecipientId:(NSString *)recipientId;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,30 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSGetProfileRequest.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSGetProfileRequest
- (instancetype)initWithRecipientId:(NSString *)recipientId
{
OWSAssert(recipientId.length > 0);
NSString *path = [NSString stringWithFormat:textSecureProfileAPIFormat, recipientId];
self = [super initWithURL:[NSURL URLWithString:path]];
if (!self) {
return self;
}
self.HTTPMethod = @"GET";
self.parameters = nil;
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -4,8 +4,13 @@
NS_ASSUME_NONNULL_BEGIN
@class OWSDevice;
@class PreKeyRecord;
@class SignedPreKeyRecord;
@class TSRequest;
typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVoice = 1, TSVerificationTransportSMS };
@interface OWSRequestFactory : NSObject
- (instancetype)init NS_UNAVAILABLE;
@ -14,6 +19,57 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSRequest *)disable2FARequest;
+ (TSRequest *)acknowledgeMessageDeliveryRequestWithSource:(NSString *)source timestamp:(UInt64)timestamp;
+ (TSRequest *)deleteDeviceRequestWithDevice:(OWSDevice *)device;
+ (TSRequest *)deviceProvisioningCodeRequest;
+ (TSRequest *)deviceProvisioningRequestWithMessageBody:(NSData *)messageBody ephemeralDeviceId:(NSString *)deviceId;
+ (TSRequest *)getDevicesRequest;
+ (TSRequest *)getMessagesRequest;
+ (TSRequest *)getProfileRequestWithRecipientId:(NSString *)recipientId;
+ (TSRequest *)turnServerInfoRequest;
+ (TSRequest *)allocAttachmentRequest;
+ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId relay:(nullable NSString *)relay;
+ (TSRequest *)availablePreKeysCountRequest;
+ (TSRequest *)contactsIntersectionRequestWithHashesArray:(NSArray *)hashes;
+ (TSRequest *)currentSignedPreKeyRequest;
+ (TSRequest *)profileAvatarUploadFormRequest;
+ (TSRequest *)recipientPrekeyRequestWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId;
+ (TSRequest *)registerForPushRequestWithPushIdentifier:(NSString *)identifier voipIdentifier:(NSString *)voipId;
+ (TSRequest *)updateAttributesRequestWithManualMessageFetching:(BOOL)enableManualMessageFetching;
+ (TSRequest *)unregisterAccountRequest;
+ (TSRequest *)requestVerificationCodeRequestWithPhoneNumber:(NSString *)phoneNumber
transport:(TSVerificationTransport)transport;
+ (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId
messages:(NSArray *)messages
relay:(nullable NSString *)relay
timeStamp:(uint64_t)timeStamp;
+ (TSRequest *)registerSignedPrekeyRequestWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedPreKey;
+ (TSRequest *)registerPrekeysRequestWithPrekeyArray:(NSArray *)prekeys
identityKey:(NSData *)identityKeyPublic
signedPreKey:(SignedPreKeyRecord *)signedPreKey
preKeyLastResort:(PreKeyRecord *)preKeyLastResort;
@end
NS_ASSUME_NONNULL_END

View File

@ -3,14 +3,19 @@
//
#import "OWSRequestFactory.h"
#import "OWSDevice.h"
#import "TSAttributes.h"
#import "TSConstants.h"
#import "TSRequest.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <AxolotlKit/SignedPreKeyRecord.h>
#import <SignalServiceKit/NSData+Base64.h>
NS_ASSUME_NONNULL_BEGIN
@implementation OWSRequestFactory
+ (TSRequest *)enable2FARequestWithPin:(NSString *)pin;
+ (TSRequest *)enable2FARequestWithPin:(NSString *)pin
{
OWSAssert(pin.length > 0);
@ -26,6 +31,255 @@ NS_ASSUME_NONNULL_BEGIN
return [TSRequest requestWithUrl:[NSURL URLWithString:textSecure2FAAPI] method:@"DELETE" parameters:@{}];
}
+ (TSRequest *)acknowledgeMessageDeliveryRequestWithSource:(NSString *)source timestamp:(UInt64)timestamp
{
OWSAssert(source.length > 0);
OWSAssert(timestamp > 0);
NSString *path = [NSString stringWithFormat:@"v1/messages/%@/%llu", source, timestamp];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"DELETE" parameters:@{}];
}
+ (TSRequest *)deleteDeviceRequestWithDevice:(OWSDevice *)device
{
OWSAssert(device);
NSString *path = [NSString stringWithFormat:textSecureDevicesAPIFormat, @(device.deviceId)];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"DELETE" parameters:@{}];
}
+ (TSRequest *)deviceProvisioningCodeRequest
{
return [TSRequest requestWithUrl:[NSURL URLWithString:textSecureDeviceProvisioningCodeAPI]
method:@"GET"
parameters:@{}];
}
+ (TSRequest *)deviceProvisioningRequestWithMessageBody:(NSData *)messageBody ephemeralDeviceId:(NSString *)deviceId
{
OWSAssert(messageBody.length > 0);
OWSAssert(deviceId.length > 0);
NSString *path = [NSString stringWithFormat:textSecureDeviceProvisioningAPIFormat, deviceId];
return [TSRequest requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:@{
@"body" : [messageBody base64EncodedString],
}];
}
+ (TSRequest *)getDevicesRequest
{
NSString *path = [NSString stringWithFormat:textSecureDevicesAPIFormat, @""];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)getMessagesRequest
{
return [TSRequest requestWithUrl:[NSURL URLWithString:@"v1/messages"] method:@"GET" parameters:@{}];
}
+ (TSRequest *)getProfileRequestWithRecipientId:(NSString *)recipientId
{
OWSAssert(recipientId.length > 0);
NSString *path = [NSString stringWithFormat:textSecureProfileAPIFormat, recipientId];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)turnServerInfoRequest
{
return [TSRequest requestWithUrl:[NSURL URLWithString:@"v1/accounts/turn"] method:@"GET" parameters:@{}];
}
+ (TSRequest *)allocAttachmentRequest
{
NSString *path = [NSString stringWithFormat:@"%@", textSecureAttachmentsAPI];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId relay:(nullable NSString *)relay
{
OWSAssert(attachmentId > 0);
NSString *path = [NSString stringWithFormat:@"%@/%llu", textSecureAttachmentsAPI, attachmentId];
// TODO: Should this be in the parameters?
if (relay.length > 0) {
path = [path stringByAppendingFormat:@"?relay=%@", relay];
}
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)availablePreKeysCountRequest
{
NSString *path = [NSString stringWithFormat:@"%@", textSecureKeysAPI];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)contactsIntersectionRequestWithHashesArray:(NSArray *)hashes
{
OWSAssert(hashes.count > 0);
NSString *path = [NSString stringWithFormat:@"%@/%@", textSecureDirectoryAPI, @"tokens"];
return [TSRequest requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:@{
@"contacts" : hashes,
}];
}
+ (TSRequest *)currentSignedPreKeyRequest
{
NSString *path = textSecureSignedKeysAPI;
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)profileAvatarUploadFormRequest
{
NSString *path = textSecureProfileAvatarFormAPI;
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)recipientPrekeyRequestWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId
{
OWSAssert(recipientNumber.length > 0);
OWSAssert(deviceId.length > 0);
NSString *path = [NSString stringWithFormat:@"%@/%@/%@", textSecureKeysAPI, recipientNumber, deviceId];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
}
+ (TSRequest *)registerForPushRequestWithPushIdentifier:(NSString *)identifier voipIdentifier:(NSString *)voipId
{
OWSAssert(identifier.length > 0);
OWSAssert(voipId.length > 0);
NSString *path = [NSString stringWithFormat:@"%@/%@", textSecureAccountsAPI, @"apn"];
OWSAssert(voipId);
return [TSRequest requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:@{
@"apnRegistrationId" : identifier,
@"voipRegistrationId" : voipId ?: @"",
}];
}
+ (TSRequest *)updateAttributesRequestWithManualMessageFetching:(BOOL)enableManualMessageFetching
{
NSString *path = [textSecureAccountsAPI stringByAppendingString:textSecureAttributesAPI];
return [TSRequest
requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:[TSAttributes attributesFromStorageWithManualMessageFetching:enableManualMessageFetching]];
}
+ (TSRequest *)unregisterAccountRequest
{
NSString *path = [NSString stringWithFormat:@"%@/%@", textSecureAccountsAPI, @"apn"];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"DELETE" parameters:@{}];
}
+ (TSRequest *)requestVerificationCodeRequestWithPhoneNumber:(NSString *)phoneNumber
transport:(TSVerificationTransport)transport
{
OWSAssert(phoneNumber.length > 0);
NSString *path = [NSString stringWithFormat:@"%@/%@/code/%@?client=ios",
textSecureAccountsAPI,
[self stringForTransport:transport],
phoneNumber];
TSRequest *request = [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
request.shouldHaveAuthorizationHeaders = NO;
return request;
}
+ (NSString *)stringForTransport:(TSVerificationTransport)transport
{
switch (transport) {
case TSVerificationTransportSMS:
return @"sms";
case TSVerificationTransportVoice:
return @"voice";
}
}
+ (TSRequest *)submitMessageRequestWithRecipient:(NSString *)recipientId
messages:(NSArray *)messages
relay:(nullable NSString *)relay
timeStamp:(uint64_t)timeStamp
{
// NOTE: messages may be empty; See comments in OWSDeviceManager.
OWSAssert(recipientId.length > 0);
OWSAssert(timeStamp > 0);
NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId];
NSMutableDictionary *parameters = [@{
@"messages" : messages,
@"timestamp" : @(timeStamp),
} mutableCopy];
if (relay) {
parameters[@"relay"] = relay;
}
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:parameters];
}
+ (TSRequest *)registerSignedPrekeyRequestWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedPreKey
{
OWSAssert(signedPreKey);
NSString *path = textSecureSignedKeysAPI;
return [TSRequest requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:[self dictionaryFromSignedPreKey:signedPreKey]];
}
+ (TSRequest *)registerPrekeysRequestWithPrekeyArray:(NSArray *)prekeys
identityKey:(NSData *)identityKeyPublic
signedPreKey:(SignedPreKeyRecord *)signedPreKey
preKeyLastResort:(PreKeyRecord *)preKeyLastResort
{
OWSAssert(prekeys.count > 0);
OWSAssert(identityKeyPublic.length > 0);
OWSAssert(signedPreKey);
OWSAssert(preKeyLastResort);
NSString *path = textSecureKeysAPI;
NSString *publicIdentityKey = [[identityKeyPublic prependKeyType] base64EncodedStringWithOptions:0];
NSMutableArray *serializedPrekeyList = [NSMutableArray array];
for (PreKeyRecord *preKey in prekeys) {
[serializedPrekeyList addObject:[self dictionaryFromPreKey:preKey]];
}
return [TSRequest requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:@{
@"preKeys" : serializedPrekeyList,
@"lastResortKey" : [self dictionaryFromPreKey:preKeyLastResort],
@"signedPreKey" : [self dictionaryFromSignedPreKey:signedPreKey],
@"identityKey" : publicIdentityKey
}];
}
+ (NSDictionary *)dictionaryFromPreKey:(PreKeyRecord *)preKey
{
return @{
@"keyId" : @(preKey.Id),
@"publicKey" : [[preKey.keyPair.publicKey prependKeyType] base64EncodedStringWithOptions:0],
};
}
+ (NSDictionary *)dictionaryFromSignedPreKey:(SignedPreKeyRecord *)preKey
{
return @{
@"keyId" : @(preKey.Id),
@"publicKey" : [[preKey.keyPair.publicKey prependKeyType] base64EncodedStringWithOptions:0],
@"signature" : [preKey.signature base64EncodedStringWithOptions:0]
};
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,17 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Fetch a list of viable ICE candidates (including TURN and STUN) used for the WebRTC call signaling process.
*/
NS_SWIFT_NAME(TurnServerInfoRequest)
@interface OWSTurnServerInfoRequest : TSRequest
@end
NS_ASSUME_NONNULL_END

View File

@ -1,26 +0,0 @@
// Created by Michael Kirk on 11/12/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "OWSTurnServerInfoRequest.h"
NS_ASSUME_NONNULL_BEGIN
NSString *const OWSTurnServerInfoRequestPath = @"v1/accounts/turn";
@implementation OWSTurnServerInfoRequest
- (instancetype)init
{
self = [super initWithURL:[NSURL URLWithString:OWSTurnServerInfoRequestPath]];
if (!self) {
return self;
}
[self setHTTPMethod:@"GET"];
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,13 +0,0 @@
//
// TSAllocAttachmentRequest.h
// Signal
//
// Created by Frederic Jacobs on 21/12/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSAllocAttachmentRequest : TSRequest
@end

View File

@ -1,26 +0,0 @@
//
// TSAllocAttachmentRequest.m
// Signal
//
// Created by Frederic Jacobs on 21/12/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import "TSAllocAttachmentRequest.h"
#import "TSConstants.h"
@implementation TSAllocAttachmentRequest
- (instancetype)init {
NSString *path = [NSString stringWithFormat:@"%@", textSecureAttachmentsAPI];
self = [super initWithURL:[NSURL URLWithString:path]];
if (self) {
[self setHTTPMethod:@"GET"];
}
return self;
}
@end

View File

@ -1,15 +0,0 @@
//
// TSRequestAttachment.h
// TextSecureiOS
//
// Created by Christine Corbett Moran on 12/1/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSAttachmentRequest : TSRequest
- (TSRequest *)initWithId:(UInt64)attachmentId relay:(NSString *)relay;
@end

View File

@ -1,28 +0,0 @@
//
// TSRequestAttachment.m
// TextSecureiOS
//
// Created by Christine Corbett Moran on 12/1/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSAttachmentRequest.h"
#import "TSConstants.h"
@implementation TSAttachmentRequest
- (TSRequest *)initWithId:(UInt64)attachmentId relay:(NSString *)relay
{
NSString *path = [NSString stringWithFormat:@"%@/%llu", textSecureAttachmentsAPI, attachmentId];
if (relay && ![relay isEqualToString:@""]) {
path = [path stringByAppendingFormat:@"?relay=%@", relay];
}
self = [super initWithURL:[NSURL URLWithString:path]];
self.HTTPMethod = @"GET";
return self;
}
@end

View File

@ -1,13 +0,0 @@
//
// TSAvailablePreKeysCountRequest.h
// Signal
//
// Created by Frederic Jacobs on 27/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSAvailablePreKeysCountRequest : TSRequest
@end

View File

@ -1,27 +0,0 @@
//
// TSAvailablePreKeysCountRequest.m
// Signal
//
// Created by Frederic Jacobs on 27/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "TSAvailablePreKeysCountRequest.h"
#import "TSConstants.h"
@implementation TSAvailablePreKeysCountRequest
- (instancetype)init {
NSString *path = [NSString stringWithFormat:@"%@", textSecureKeysAPI];
self = [super initWithURL:[NSURL URLWithString:path]];
if (self) {
[self setHTTPMethod:@"GET"];
}
return self;
}
@end

View File

@ -1,15 +0,0 @@
//
// TSContactsIntersection.h
// TextSecureiOS
//
// Created by Frederic Jacobs on 10/12/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSContactsIntersectionRequest : TSRequest
- (id)initWithHashesArray:(NSArray *)hashes;
@end

View File

@ -1,27 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSContactsIntersectionRequest.h"
#import "TSConstants.h"
@implementation TSContactsIntersectionRequest
- (id)initWithHashesArray:(NSArray *)hashes {
self = [self
initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", textSecureDirectoryAPI, @"tokens"]]];
if (!self) {
return nil;
}
self.HTTPMethod = @"PUT";
self.parameters = @{
@"contacts" : hashes,
};
return self;
}
@end

View File

@ -1,13 +0,0 @@
//
// TSCurrentSignedPreKeyRequest.h
// Signal
//
// Created by Frederic Jacobs on 27/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSCurrentSignedPreKeyRequest : TSRequest
@end

View File

@ -1,22 +0,0 @@
//
// TSCurrentSignedPreKeyRequest.m
// Signal
//
// Created by Frederic Jacobs on 27/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
#import "TSCurrentSignedPreKeyRequest.h"
@implementation TSCurrentSignedPreKeyRequest
- (instancetype)init {
self = [super initWithURL:[NSURL URLWithString:textSecureSignedKeysAPI]];
self.HTTPMethod = @"GET";
return self;
}
@end

View File

@ -1,15 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface TSProfileAvatarUploadFormRequest : TSRequest
- (instancetype)init;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,23 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSProfileAvatarUploadFormRequest.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation TSProfileAvatarUploadFormRequest
- (instancetype)init
{
self = [super initWithURL:[NSURL URLWithString:textSecureProfileAvatarFormAPI]];
self.HTTPMethod = @"GET";
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,15 +0,0 @@
//
// TSGetRecipientPrekey.h
// TextSecureiOS
//
// Created by Christine Corbett Moran on 11/30/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@class TSContact;
@interface TSRecipientPrekeyRequest : TSRequest
- (TSRequest *)initWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId;
@end

View File

@ -1,26 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRecipientPrekeyRequest.h"
#import "TSConstants.h"
@implementation TSRecipientPrekeyRequest
- (TSRequest *)initWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId {
self = [super
initWithURL:[NSURL
URLWithString:[NSString
stringWithFormat:@"%@/%@/%@", textSecureKeysAPI, recipientNumber, deviceId]]];
if (!self) {
return nil;
}
self.HTTPMethod = @"GET";
self.parameters = nil;
return self;
}
@end

View File

@ -1,15 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface TSRegisterForPushRequest : TSRequest
- (id)initWithPushIdentifier:(NSString *)identifier voipIdentifier:(NSString *)voipId;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,33 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRegisterForPushRequest.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation TSRegisterForPushRequest
- (id)initWithPushIdentifier:(NSString *)identifier voipIdentifier:(NSString *)voipId {
self =
[super initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", textSecureAccountsAPI, @"apn"]]];
if (!self) {
return nil;
}
self.HTTPMethod = @"PUT";
OWSAssert(voipId);
self.parameters = @{
@"apnRegistrationId" : identifier,
@"voipRegistrationId" : voipId ?: @"",
};
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,21 +0,0 @@
//
// TSRegisterPrekeys.h
// TextSecureiOS
//
// Created by Christine Corbett Moran on 10/17/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@class TSECKeyPair;
@class SignedPreKeyRecord;
@class PreKeyRecord;
@interface TSRegisterPrekeysRequest : TSRequest
- (id)initWithPrekeyArray:(NSArray *)prekeys
identityKey:(NSData *)identityKeyPublic
signedPreKeyRecord:(SignedPreKeyRecord *)signedRecord
preKeyLastResort:(PreKeyRecord *)lastResort;
@end

View File

@ -1,60 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRegisterPrekeysRequest.h"
#import "TSConstants.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <AxolotlKit/PreKeyRecord.h>
#import <AxolotlKit/SignedPreKeyStore.h>
#import <Curve25519Kit/Curve25519.h>
@implementation TSRegisterPrekeysRequest
- (id)initWithPrekeyArray:(NSArray *)prekeys
identityKey:(NSData *)identityKeyPublic
signedPreKeyRecord:(SignedPreKeyRecord *)signedRecord
preKeyLastResort:(PreKeyRecord *)lastResort {
self = [super initWithURL:[NSURL URLWithString:textSecureKeysAPI]];
if (!self) {
return nil;
}
self.HTTPMethod = @"PUT";
NSString *publicIdentityKey = [[identityKeyPublic prependKeyType] base64EncodedStringWithOptions:0];
NSMutableArray *serializedPrekeyList = [NSMutableArray array];
for (PreKeyRecord *preKey in prekeys) {
[serializedPrekeyList addObject:[self dictionaryFromPreKey:preKey]];
}
NSDictionary *serializedKeyRegistrationParameters = @{
@"preKeys" : serializedPrekeyList,
@"lastResortKey" : [self dictionaryFromPreKey:lastResort],
@"signedPreKey" : [self dictionaryFromSignedPreKey:signedRecord],
@"identityKey" : publicIdentityKey
};
self.parameters = [serializedKeyRegistrationParameters mutableCopy];
return self;
}
- (NSDictionary *)dictionaryFromPreKey:(PreKeyRecord *)preKey {
return @{
@"keyId" : [NSNumber numberWithInt:preKey.Id],
@"publicKey" : [[preKey.keyPair.publicKey prependKeyType] base64EncodedStringWithOptions:0],
};
}
- (NSDictionary *)dictionaryFromSignedPreKey:(SignedPreKeyRecord *)preKey {
return @{
@"keyId" : [NSNumber numberWithInt:preKey.Id],
@"publicKey" : [[preKey.keyPair.publicKey prependKeyType] base64EncodedStringWithOptions:0],
@"signature" : [preKey.signature base64EncodedStringWithOptions:0]
};
}
@end

View File

@ -1,14 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@class SignedPreKeyRecord;
@class PreKeyRecord;
@interface TSRegisterSignedPrekeyRequest : TSRequest
- (id)initWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedRecord;
@end

View File

@ -1,39 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRegisterSignedPrekeyRequest.h"
#import "TSConstants.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import <AxolotlKit/PreKeyRecord.h>
#import <AxolotlKit/SignedPreKeyStore.h>
#import <Curve25519Kit/Curve25519.h>
@implementation TSRegisterSignedPrekeyRequest
- (id)initWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedRecord
{
self = [super initWithURL:[NSURL URLWithString:textSecureSignedKeysAPI]];
if (!self) {
return nil;
}
self.HTTPMethod = @"PUT";
NSDictionary *serializedKeyRegistrationParameters = [self dictionaryFromSignedPreKey:signedRecord];
self.parameters = [serializedKeyRegistrationParameters mutableCopy];
return self;
}
- (NSDictionary *)dictionaryFromSignedPreKey:(SignedPreKeyRecord *)preKey
{
return @{
@"keyId" : [NSNumber numberWithInt:preKey.Id],
@"publicKey" : [[preKey.keyPair.publicKey prependKeyType] base64EncodedStringWithOptions:0],
@"signature" : [preKey.signature base64EncodedStringWithOptions:0]
};
}
@end

View File

@ -4,10 +4,24 @@
@interface TSRequest : NSMutableURLRequest
@property (nonatomic) NSDictionary *parameters;
@property (nonatomic) BOOL shouldHaveAuthorizationHeaders;
@property (nonatomic, readonly) NSDictionary *parameters;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithURL:(NSURL *)URL;
- (instancetype)initWithURL:(NSURL *)URL
cachePolicy:(NSURLRequestCachePolicy)cachePolicy
timeoutInterval:(NSTimeInterval)timeoutInterval NS_UNAVAILABLE;
- (instancetype)initWithURL:(NSURL *)URL
method:(NSString *)method
parameters:(nullable NSDictionary<NSString *, id> *)parameters;
+ (instancetype)requestWithUrl:(NSURL *)url
method:(NSString *)method
parameters:(NSDictionary<NSString *, id> *)parameters;
parameters:(nullable NSDictionary<NSString *, id> *)parameters;
@end

View File

@ -17,12 +17,14 @@
return nil;
}
self.parameters = @{};
_parameters = @{};
self.shouldHaveAuthorizationHeaders = YES;
return self;
}
- (id)init {
- (instancetype)init
{
OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL: method");
return nil;
}
@ -30,21 +32,41 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (id)initWithURL:(NSURL *)URL
cachePolicy:(NSURLRequestCachePolicy)cachePolicy
timeoutInterval:(NSTimeInterval)timeoutInterval {
- (instancetype)initWithURL:(NSURL *)URL
cachePolicy:(NSURLRequestCachePolicy)cachePolicy
timeoutInterval:(NSTimeInterval)timeoutInterval
{
OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL method");
return nil;
}
- (instancetype)initWithURL:(NSURL *)URL
method:(NSString *)method
parameters:(nullable NSDictionary<NSString *, id> *)parameters
{
OWSAssert(URL);
OWSAssert(method.length > 0);
OWSAssert(parameters);
self = [super initWithURL:URL
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:textSecureHTTPTimeOut];
if (!self) {
return nil;
}
_parameters = parameters ?: @{};
[self setHTTPMethod:method];
self.shouldHaveAuthorizationHeaders = YES;
return self;
}
+ (instancetype)requestWithUrl:(NSURL *)url
method:(NSString *)method
parameters:(NSDictionary<NSString *, id> *)parameters
parameters:(nullable NSDictionary<NSString *, id> *)parameters
{
TSRequest *request = [[TSRequest alloc] initWithURL:url];
[request setHTTPMethod:method];
request.parameters = parameters;
return request;
return [[TSRequest alloc] initWithURL:url method:method parameters:parameters];
}
@end

View File

@ -1,17 +0,0 @@
//
// TSRequestVerificationCodeRequest.h
// Signal
//
// Created by Frederic Jacobs on 02/12/15.
// Copyright © 2015 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSRequestVerificationCodeRequest : TSRequest
typedef enum { TSVerificationTransportVoice, TSVerificationTransportSMS } TSVerificationTransport;
- (TSRequest *)initWithPhoneNumber:(NSString *)phoneNumber transport:(TSVerificationTransport)transport;
@end

View File

@ -1,36 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSRequestVerificationCodeRequest.h"
#import "TSConstants.h"
@implementation TSRequestVerificationCodeRequest
- (TSRequest *)initWithPhoneNumber:(NSString *)phoneNumber transport:(TSVerificationTransport)transport {
self = [super initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/code/%@?client=ios",
textSecureAccountsAPI,
[self stringForTransport:transport],
phoneNumber]]];
if (!self) {
return nil;
}
self.parameters = nil;
[self setHTTPMethod:@"GET"];
return self;
}
- (NSString *)stringForTransport:(TSVerificationTransport)transport {
switch (transport) {
case TSVerificationTransportSMS:
return @"sms";
case TSVerificationTransportVoice:
return @"voice";
default:
OWSRaiseException(@"Unsupported transport exception", @"Transport %u in enum is not supported.", transport);
}
}
@end

View File

@ -1,19 +0,0 @@
//
// TSSubmitMessageRequest.h
// TextSecureiOS
//
// Created by Christine Corbett Moran on 11/30/13.
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
#import "TSRequest.h"
@interface TSSubmitMessageRequest : TSRequest
- (TSRequest *)initWithRecipient:(NSString *)contactRegisteredID
messages:(NSArray *)messages
relay:(NSString *)relay
timeStamp:(uint64_t)timeStamp;
@end

View File

@ -1,34 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSSubmitMessageRequest.h"
#import "TSConstants.h"
@implementation TSSubmitMessageRequest
- (TSRequest *)initWithRecipient:(NSString *)contactRegisteredID
messages:(NSArray *)messages
relay:(NSString *)relay
timeStamp:(uint64_t)timeStamp {
self =
[super initWithURL:[NSURL URLWithString:[textSecureMessagesAPI stringByAppendingString:contactRegisteredID]]];
if (!self) {
return nil;
}
NSMutableDictionary *parameters = [@{
@"messages" : messages,
@"timestamp" : @(timeStamp),
} mutableCopy];
if (relay) {
parameters[@"relay"] = relay;
}
[self setHTTPMethod:@"PUT"];
self.parameters = parameters;
return self;
}
@end

View File

@ -1,12 +0,0 @@
//
// TSDeregisterAccountRequest.h
// TextSecureiOS
//
// Created by Christine Corbett Moran on 3/16/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSUnregisterAccountRequest : TSRequest
@end

View File

@ -1,21 +0,0 @@
//
// TSDeregisterAccountRequest.m
// TextSecureiOS
//
// Created by Christine Corbett Moran on 3/16/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import "TSConstants.h"
#import "TSUnregisterAccountRequest.h"
@implementation TSUnregisterAccountRequest
- (id)init {
self =
[super initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", textSecureAccountsAPI, @"apn"]]];
self.HTTPMethod = @"DELETE";
return self;
}
@end

View File

@ -1,11 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
@interface TSUpdateAttributesRequest : TSRequest
- (instancetype)initWithManualMessageFetching:(BOOL)isEnabled;
@end

View File

@ -1,28 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSUpdateAttributesRequest.h"
#import "TSAttributes.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation TSUpdateAttributesRequest
- (instancetype)initWithManualMessageFetching:(BOOL)enableManualMessageFetching
{
NSString *endPoint = [textSecureAccountsAPI stringByAppendingString:textSecureAttributesAPI];
self = [super initWithURL:[NSURL URLWithString:endPoint]];
if (self) {
[self setHTTPMethod:@"PUT"];
self.parameters = [TSAttributes attributesFromStorageWithManualMessageFetching:enableManualMessageFetching];
}
return self;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -8,14 +8,16 @@ NS_ASSUME_NONNULL_BEGIN
@interface TSVerifyCodeRequest : TSRequest
@property (nonatomic, readonly) NSString *numberToValidate;
- (instancetype)init NS_UNAVAILABLE;
- (TSRequest *)initWithVerificationCode:(NSString *)verificationCode
forNumber:(NSString *)phoneNumber
pin:(nullable NSString *)pin
signalingKey:(NSString *)signalingKey
authKey:(NSString *)authKey;
@property (nonatomic, readonly) NSString *numberToValidate;
@end
NS_ASSUME_NONNULL_END

View File

@ -17,12 +17,13 @@ NS_ASSUME_NONNULL_BEGIN
signalingKey:(NSString *)signalingKey
authKey:(NSString *)authKey
{
self = [super
initWithURL:[NSURL URLWithString:[NSString
stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]]];
_numberToValidate = phoneNumber;
OWSAssert(verificationCode.length > 0);
OWSAssert(phoneNumber.length > 0);
OWSAssert(signalingKey.length > 0);
OWSAssert(authKey.length > 0);
NSURL *url =
[NSURL URLWithString:[NSString stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]];
NSMutableDictionary *parameters =
[[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey manualMessageFetching:NO]
mutableCopy];
@ -30,9 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(pin.length > 0);
parameters[@"pin"] = pin;
}
self.parameters = parameters;
self = [super initWithURL:url method:@"PUT" parameters:parameters];
[self setHTTPMethod:@"PUT"];
_numberToValidate = phoneNumber;
return self;
}

View File

@ -2,23 +2,6 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
/**
* TSNetworkManager imports all TSRequests to prevent massive imports
in classes that call TSNetworkManager
*/
#import "TSAllocAttachmentRequest.h"
#import "TSAttachmentRequest.h"
#import "TSAvailablePreKeysCountRequest.h"
#import "TSContactsIntersectionRequest.h"
#import "TSCurrentSignedPreKeyRequest.h"
#import "TSRecipientPrekeyRequest.h"
#import "TSRegisterForPushRequest.h"
#import "TSRegisterPrekeysRequest.h"
#import "TSRequestVerificationCodeRequest.h"
#import "TSSubmitMessageRequest.h"
#import "TSUnregisterAccountRequest.h"
#import "TSUpdateAttributesRequest.h"
#import "TSVerifyCodeRequest.h"
#import <AFNetworking/AFHTTPSessionManager.h>
NS_ASSUME_NONNULL_BEGIN
@ -30,6 +13,8 @@ BOOL IsNSErrorNetworkFailure(NSError *_Nullable error);
typedef void (^TSNetworkManagerSuccess)(NSURLSessionDataTask *task, id responseObject);
typedef void (^TSNetworkManagerFailure)(NSURLSessionDataTask *task, NSError *error);
@class TSRequest;
@interface TSNetworkManager : NSObject
- (instancetype)init NS_UNAVAILABLE;
@ -43,10 +28,7 @@ typedef void (^TSNetworkManagerFailure)(NSURLSessionDataTask *task, NSError *err
- (void)makeRequest:(TSRequest *)request
completionQueue:(dispatch_queue_t)completionQueue
success:(TSNetworkManagerSuccess)success
failure:(TSNetworkManagerFailure)failure NS_SWIFT_NAME(makeRequest(_:shouldCompleteOnMainQueue
:success
:failure
:));
failure:(TSNetworkManagerFailure)failure NS_SWIFT_NAME(makeRequest(_:shouldCompleteOnMainQueue:success:failure:));
@end

View File

@ -7,8 +7,6 @@
#import "NSURLSessionDataTask+StatusCode.h"
#import "OWSSignalService.h"
#import "TSAccountManager.h"
#import "TSRecipientPrekeyRequest.h"
#import "TSSubmitMessageRequest.h"
#import "TSVerifyCodeRequest.h"
#import <AFNetworking/AFNetworking.h>
@ -71,15 +69,6 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
OWSAssert(failureBlock);
DDLogInfo(@"%@ Making request: %@", self.logTag, request);
if (!CurrentAppContext().isMainApp) {
if (![request isKindOfClass:[TSRecipientPrekeyRequest class]]
&& ![request isKindOfClass:[TSSubmitMessageRequest class]]
&& ![request isKindOfClass:[TSContactsIntersectionRequest class]]
&& ![request isKindOfClass:[TSAllocAttachmentRequest class]]) {
// The SAE should only make requests directly related to message sending.
OWSFail(@"%@ Making unexpected request: %@", self.logTag, request);
}
}
// TODO: Remove this logging when the call connection issues have been resolved.
TSNetworkManagerSuccess success = ^(NSURLSessionDataTask *task, id responseObject) {
@ -102,7 +91,7 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
[parameters removeObjectForKey:@"AuthKey"];
[sessionManager PUT:request.URL.absoluteString parameters:parameters success:success failure:failure];
} else {
if (![request isKindOfClass:[TSRequestVerificationCodeRequest class]]) {
if (request.shouldHaveAuthorizationHeaders) {
[sessionManager.requestSerializer
setAuthorizationHeaderFieldWithUsername:[TSAccountManager localNumber]
password:[TSAccountManager serverAuthToken]];

View File

@ -101,7 +101,7 @@ NSString *const TSStorageManagerKeyPrekeyCurrentSignedPrekeyId = @"currentSigned
#pragma mark - Prekey update failures
- (int)prekeyUpdateFailureCount;
- (int)prekeyUpdateFailureCount
{
NSNumber *value = [self.dbReadConnection objectForKey:TSStorageManagerKeyPrekeyUpdateFailureCount
inCollection:TSStorageManagerSignedPreKeyMetadataCollection];

View File

@ -303,7 +303,7 @@ const NSUInteger kAES256_KeyByteLength = 32;
withKey:(NSData *)key
digest:(nullable NSData *)digest
unpaddedSize:(UInt32)unpaddedSize
error:(NSError **)error;
error:(NSError **)error
{
if (digest.length <= 0) {
// This *could* happen with sufficiently outdated clients.

View File

@ -256,7 +256,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}
+ (nullable DataSource *)dataSourceWithURL:(NSURL *)fileUrl;
+ (nullable DataSource *)dataSourceWithURL:(NSURL *)fileUrl
{
OWSAssert(fileUrl);
@ -268,7 +268,7 @@ NS_ASSUME_NONNULL_BEGIN
return instance;
}
+ (nullable DataSource *)dataSourceWithFilePath:(NSString *)filePath;
+ (nullable DataSource *)dataSourceWithFilePath:(NSString *)filePath
{
OWSAssert(filePath);