Skip to content

Commit

Permalink
Merge pull request #38 from 8W9aG/add-xl-xcconfig
Browse files Browse the repository at this point in the history
Use incredibly strict warning set for SPTDataLoader
  • Loading branch information
8W9aG committed Jan 22, 2016
2 parents 80d487f + c205eca commit 34d309a
Show file tree
Hide file tree
Showing 49 changed files with 246 additions and 115 deletions.
6 changes: 4 additions & 2 deletions SPTDataLoader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
056E52381A11275700E8716C /* SPTDataLoaderRequest+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SPTDataLoaderRequest+Private.h"; sourceTree = "<group>"; };
056E523C1A11348800E8716C /* SPTDataLoaderRequestResponseHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTDataLoaderRequestResponseHandler.h; sourceTree = "<group>"; };
056E523E1A113A2B00E8716C /* SPTExpTime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTExpTime.m; sourceTree = "<group>"; };
05896F8A1C51F3850051CC1E /* spotify_os.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = spotify_os.xcconfig; sourceTree = "<group>"; };
059940411A14BA28006D6BE9 /* SPTDataLoaderRequestResponseHandlerMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTDataLoaderRequestResponseHandlerMock.h; sourceTree = "<group>"; };
059940421A14BA28006D6BE9 /* SPTDataLoaderRequestResponseHandlerMock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTDataLoaderRequestResponseHandlerMock.m; sourceTree = "<group>"; };
059940961A14E7F1006D6BE9 /* SPTDataLoaderFactoryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTDataLoaderFactoryTest.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -479,6 +480,7 @@
isa = PBXGroup;
children = (
056A04BB1A13D2BD00FA72AD /* README.md */,
05896F8A1C51F3850051CC1E /* spotify_os.xcconfig */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -1092,7 +1094,7 @@
/* Begin XCBuildConfiguration section */
050E069C1A10C62100A10A0E /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 993EF2331A30B1FD001E48D2 /* spotify_shared.xcconfig */;
baseConfigurationReference = 05896F8A1C51F3850051CC1E /* spotify_os.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -1139,7 +1141,7 @@
};
050E069D1A10C62100A10A0E /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 993EF2331A30B1FD001E48D2 /* spotify_shared.xcconfig */;
baseConfigurationReference = 05896F8A1C51F3850051CC1E /* spotify_os.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down
2 changes: 1 addition & 1 deletion SPTDataLoader/NSDictionary+HeaderSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@import Foundation;

/**
* A category for calculating the size of a header represented by an NSDictionary
Expand Down
2 changes: 1 addition & 1 deletion SPTDataLoader/SPTCancellationTokenFactory.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import <Foundation/Foundation.h>
@import Foundation;

@protocol SPTCancellationToken;
@protocol SPTCancellationTokenDelegate;
Expand Down
2 changes: 1 addition & 1 deletion SPTDataLoader/SPTCancellationTokenFactoryImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@import Foundation;

#import "SPTCancellationTokenFactory.h"

Expand Down
2 changes: 1 addition & 1 deletion SPTDataLoader/SPTCancellationTokenImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@import Foundation;

#import "SPTCancellationToken.h"

Expand Down
5 changes: 3 additions & 2 deletions SPTDataLoader/SPTDataLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ - (void)executeDelegateBlock:(dispatch_block_t)block
- (id<SPTCancellationToken>)performRequest:(SPTDataLoaderRequest *)request
{
SPTDataLoaderRequest *copiedRequest = [request copy];
if ([self.delegate respondsToSelector:@selector(dataLoaderShouldSupportChunks:)] && copiedRequest.chunks) {
NSAssert([self.delegate dataLoaderShouldSupportChunks:self], @"The data loader was given a request that required chunks while the delegate does not support chunks");
id<SPTDataLoaderDelegate> delegate = self.delegate;
if ([delegate respondsToSelector:@selector(dataLoaderShouldSupportChunks:)] && copiedRequest.chunks) {
NSAssert([delegate dataLoaderShouldSupportChunks:self], @"The data loader was given a request that required chunks while the delegate does not support chunks");
}
id<SPTCancellationToken> cancellationToken = [self.requestResponseHandlerDelegate requestResponseHandler:self
performRequest:copiedRequest];
Expand Down
15 changes: 9 additions & 6 deletions SPTDataLoader/SPTDataLoaderFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ - (void)authoriseRequest:(SPTDataLoaderRequest *)request
__weak __typeof(self) weakSelf = self;
__weak __typeof(request) weakRequest = request;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(request.timeout * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (!weakRequest) {
__strong __typeof(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}

Expand All @@ -185,7 +186,7 @@ - (void)authoriseRequest:(SPTDataLoaderRequest *)request
code:SPTDataLoaderRequestErrorCodeTimeout
userInfo:nil];
response.error = error;
[weakSelf failedResponse:response];
[strongSelf failedResponse:response];
});
}

Expand All @@ -197,17 +198,19 @@ - (void)authoriseRequest:(SPTDataLoaderRequest *)request
- (void)dataLoaderAuthoriser:(id<SPTDataLoaderAuthoriser>)dataLoaderAuthoriser
authorisedRequest:(SPTDataLoaderRequest *)request
{
if ([self.requestResponseHandlerDelegate respondsToSelector:@selector(requestResponseHandler:authorisedRequest:)]) {
[self.requestResponseHandlerDelegate requestResponseHandler:self authorisedRequest:request];
id<SPTDataLoaderRequestResponseHandlerDelegate> requestResponseHandlerDelegate = self.requestResponseHandlerDelegate;
if ([requestResponseHandlerDelegate respondsToSelector:@selector(requestResponseHandler:authorisedRequest:)]) {
[requestResponseHandlerDelegate requestResponseHandler:self authorisedRequest:request];
}
}

- (void)dataLoaderAuthoriser:(id<SPTDataLoaderAuthoriser>)dataLoaderAuthoriser
didFailToAuthoriseRequest:(SPTDataLoaderRequest *)request
withError:(NSError *)error
{
if ([self.requestResponseHandlerDelegate respondsToSelector:@selector(requestResponseHandler:failedToAuthoriseRequest:error:)]) {
[self.requestResponseHandlerDelegate requestResponseHandler:self failedToAuthoriseRequest:request error:error];
id<SPTDataLoaderRequestResponseHandlerDelegate> requestResponseHandlerDelegate = self.requestResponseHandlerDelegate;
if ([requestResponseHandlerDelegate respondsToSelector:@selector(requestResponseHandler:failedToAuthoriseRequest:error:)]) {
[requestResponseHandlerDelegate requestResponseHandler:self failedToAuthoriseRequest:request error:error];
}
}

Expand Down
6 changes: 3 additions & 3 deletions SPTDataLoader/SPTDataLoaderRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

NSString * const SPTDataLoaderRequestErrorDomain = @"com.spotify.dataloader.request";

static NSString * const NSStringFromSPTDataLoaderRequestMethod(SPTDataLoaderRequestMethod requestMethod);
static NSString * NSStringFromSPTDataLoaderRequestMethod(SPTDataLoaderRequestMethod requestMethod);

@interface SPTDataLoaderRequest ()

Expand Down Expand Up @@ -169,7 +169,7 @@ + (NSString *)languageHeaderValue
languageImportanceCounter -= (1.0f / languages.count);
}
if (!containsEnglish) {
[languageHeaderValues addObject:constructLanguageHeaderValue(SPTDataLoaderRequestEnglishLanguageValue, 0.01)];
[languageHeaderValues addObject:constructLanguageHeaderValue(SPTDataLoaderRequestEnglishLanguageValue, 0.01f)];
}
languageHeaderValue = [languageHeaderValues componentsJoinedByString:SPTDataLoaderRequestLanguageHeaderValuesJoiner];
});
Expand Down Expand Up @@ -203,7 +203,7 @@ - (id)copyWithZone:(NSZone *)zone
static NSString * const SPTDataLoaderRequestPostMethodString = @"POST";
static NSString * const SPTDataLoaderRequestPutMethodString = @"PUT";

static NSString * const NSStringFromSPTDataLoaderRequestMethod(SPTDataLoaderRequestMethod requestMethod)
static NSString * NSStringFromSPTDataLoaderRequestMethod(SPTDataLoaderRequestMethod requestMethod)
{
switch (requestMethod) {
case SPTDataLoaderRequestMethodDelete: return SPTDataLoaderRequestDeleteMethodString;
Expand Down
3 changes: 1 addition & 2 deletions SPTDataLoader/SPTDataLoaderRequestResponseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@import Foundation;

@class SPTDataLoaderRequest;
@class SPTDataLoaderResponse;
Expand Down Expand Up @@ -105,7 +105,6 @@
/**
* Authorise a request
* @param request The request to be authorise
* @param cancellationToken The token used to cancel this request
*/
- (void)authoriseRequest:(SPTDataLoaderRequest *)request;

Expand Down
2 changes: 1 addition & 1 deletion SPTDataLoader/SPTDataLoaderRequestTaskHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@import Foundation;

@class SPTDataLoaderRequest;
@class SPTDataLoaderRateLimiter;
Expand Down
7 changes: 4 additions & 3 deletions SPTDataLoader/SPTDataLoaderRequestTaskHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ - (void)receiveData:(NSData *)data

- (SPTDataLoaderResponse *)completeWithError:(NSError *)error
{
id<SPTDataLoaderRequestResponseHandler> requestResponseHandler = self.requestResponseHandler;
if (!self.response) {
self.response = [SPTDataLoaderResponse dataLoaderResponseWithRequest:self.request response:nil];
}

if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled) {
[self.requestResponseHandler cancelledRequest:self.request];
[requestResponseHandler cancelledRequest:self.request];
self.calledCancelledRequest = YES;
return nil;
}
Expand All @@ -140,12 +141,12 @@ - (SPTDataLoaderResponse *)completeWithError:(NSError *)error
return nil;
}
}
[self.requestResponseHandler failedResponse:self.response];
[requestResponseHandler failedResponse:self.response];
self.calledFailedResponse = YES;
return self.response;
}

[self.requestResponseHandler successfulResponse:self.response];
[requestResponseHandler successfulResponse:self.response];
self.calledSuccessfulResponse = YES;
return self.response;
}
Expand Down
2 changes: 1 addition & 1 deletion SPTDataLoader/SPTDataLoaderResolverAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
@import Foundation;

/**
* An object for tracking a resolver addresses reachability
Expand Down
5 changes: 3 additions & 2 deletions SPTDataLoader/SPTDataLoaderResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ - (NSDate *)retryAfterForHeaders:(NSDictionary *)headers
if (retryAfterSeconds != 0.0) {
return [NSDate dateWithTimeIntervalSinceNow:retryAfterSeconds];
}

return [httpDateFormatter dateFromString:headers[SPTDataLoaderResponseHeaderRetryAfter]];

NSString *retryAfterValue = headers[SPTDataLoaderResponseHeaderRetryAfter];
return [httpDateFormatter dateFromString:retryAfterValue];
}

@end
10 changes: 8 additions & 2 deletions SPTDataLoader/SPTDataLoaderService.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#import "NSDictionary+HeaderSize.h"
#import "SPTCancellationTokenFactoryImplementation.h"

#ifndef SPTDATALOADER_ALLOW_ALL_CERTS
#define SPTDATALOADER_ALLOW_ALL_CERTS 0
#endif

@interface SPTDataLoaderService () <SPTDataLoaderRequestResponseHandlerDelegate, SPTCancellationTokenDelegate, NSURLSessionDataDelegate, NSURLSessionTaskDelegate>

@property (nonatomic, strong) SPTDataLoaderRateLimiter *rateLimiter;
Expand Down Expand Up @@ -140,7 +144,8 @@ - (void)performRequest:(SPTDataLoaderRequest *)request
}

NSString *host = [self.resolver addressForHost:request.URL.host];
if (![host isEqualToString:request.URL.host] && host) {
NSString *requestHost = request.URL.host;
if (![host isEqualToString:requestHost] && host) {
NSURLComponents *requestComponents = [NSURLComponents componentsWithURL:request.URL resolvingAgainstBaseURL:NO];
requestComponents.host = host;
request.URL = requestComponents.URL;
Expand Down Expand Up @@ -331,7 +336,8 @@ - (void)URLSession:(NSURLSession *)session

// Go through SPTDataLoaderResolver dance and update the URL if needed
NSString *host = [self.resolver addressForHost:newURL.host];
if (![host isEqualToString:newURL.host] && host) {
NSString *requestHost = newURL.host;
if (![host isEqualToString:requestHost] && host) {
NSURLComponents *newRequestComponents = [NSURLComponents componentsWithURL:newURL resolvingAgainstBaseURL:NO];
newRequestComponents.host = host;
newURL = newRequestComponents.URL;
Expand Down
45 changes: 25 additions & 20 deletions SPTDataLoader/SPTExpTime.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@
*/
#import "SPTExpTime.h"

#include <math.h>
#include <stdlib.h>
@import Darwin.C.math;
@import Darwin.C.stdlib;

static const double kDefaultGrow = M_E;
const double kDefaultJitter = 0.11304999836;

@interface SPTExpTime ()

@property (nonatomic, assign) NSTimeInterval currTime;
@property (nonatomic, assign) double growFactor;
@property (nonatomic, assign) NSTimeInterval maxTime;
@property (nonatomic, assign) double jitter;
@property (nonatomic, assign) NSTimeInterval initialTime;

@end

@implementation SPTExpTime
{
NSTimeInterval _initialTime;
NSTimeInterval _maxTime;
NSTimeInterval _currTime;
double _growFactor;
double _jitter;
double _prevSigma;
}

Expand Down Expand Up @@ -75,37 +80,37 @@ - (instancetype)initWithInitialTime:(NSTimeInterval)time0

- (NSTimeInterval)calculateNext
{
NSTimeInterval t = _currTime * _growFactor;
NSTimeInterval t = self.currTime * self.growFactor;

if (t > _maxTime) {
t = _maxTime;
if (t > self.maxTime) {
t = self.maxTime;
}

if (_jitter < 0.0001) {
_currTime = t;
if (self.jitter < 0.0001) {
self.currTime = t;
}
else {
const double sigma = _jitter * t;
_currTime = [[self class] normalWithMu:t sigma:sigma];
const double sigma = self.jitter * t;
self.currTime = [[self class] normalWithMu:t sigma:sigma];
}

if (_currTime > _maxTime) {
_currTime = _maxTime;
if (self.currTime > self.maxTime) {
self.currTime = self.maxTime;
}

return _currTime;
return self.currTime;
}

- (NSTimeInterval)timeIntervalAndCalculateNext
{
const NSTimeInterval ret = _currTime;
const NSTimeInterval ret = self.currTime;
[self calculateNext];
return ret;
}

- (NSTimeInterval)timeInterval
{
return _currTime;
return self.currTime;
}

#define EXPT_MODULO ((u_int32_t)RAND_MAX)
Expand Down Expand Up @@ -138,7 +143,7 @@ + (NSTimeInterval)normalWithMu:(double)mu sigma:(double)sigma

- (void)reset
{
_currTime = _initialTime;
self.currTime = self.initialTime;
}

@end
2 changes: 1 addition & 1 deletion SPTDataLoaderTests/NSDictionaryHeaderSizeTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
#import <XCTest/XCTest.h>
@import XCTest;

#import "NSDictionary+HeaderSize.h"

Expand Down
10 changes: 5 additions & 5 deletions SPTDataLoaderTests/NSURLSessionDataTaskMock.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import <Foundation/Foundation.h>
@import Foundation;

@interface NSURLSessionDataTaskMock : NSURLSessionDataTask

Expand All @@ -7,10 +7,10 @@

#pragma mark NSURLSessionTask

@property (copy) NSURLRequest *currentRequest;
@property (copy) NSURLResponse *response;
@property (atomic, nullable, readonly, copy) NSURLRequest *currentRequest;
@property (atomic, nullable, readonly, copy) NSURLResponse *response;

@property int64_t countOfBytesSent;
@property int64_t countOfBytesReceived;
@property (atomic, readonly) int64_t countOfBytesSent;
@property (atomic, readonly) int64_t countOfBytesReceived;

@end
2 changes: 1 addition & 1 deletion SPTDataLoaderTests/NSURLSessionMock.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import <Foundation/Foundation.h>
@import Foundation;

@class NSURLSessionDataTaskMock;

Expand Down
2 changes: 1 addition & 1 deletion SPTDataLoaderTests/NSURLSessionTaskMock.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import <Foundation/Foundation.h>
@import Foundation;

@interface NSURLSessionTaskMock : NSURLSessionTask

Expand Down
2 changes: 1 addition & 1 deletion SPTDataLoaderTests/SPTCancellationTokenDelegateMock.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import <Foundation/Foundation.h>
@import Foundation;

#import "SPTCancellationToken.h"

Expand Down
Loading

0 comments on commit 34d309a

Please sign in to comment.