diff --git a/NetDiag.xcodeproj/project.pbxproj b/NetDiag.xcodeproj/project.pbxproj index 9683d66..28cba04 100644 --- a/NetDiag.xcodeproj/project.pbxproj +++ b/NetDiag.xcodeproj/project.pbxproj @@ -205,8 +205,6 @@ DF8DFFCB1C61DA1B00174DA9 /* Sources */, DF8DFFCC1C61DA1B00174DA9 /* Frameworks */, DF8DFFCD1C61DA1B00174DA9 /* Resources */, - 6360AC3809EC45C17B6B9A39 /* [CP] Embed Pods Frameworks */, - 7EB1F7F29D34632701B40C83 /* [CP] Copy Pods Resources */, D1E68BCE0991EB5A44C81ED8 /* Embed Pods Frameworks */, 3317CC6757C386790A56DF6E /* Copy Pods Resources */, ); @@ -243,7 +241,7 @@ DFCEC63D1C2EC01D0058EE65 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0920; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Qiniu Cloud Storage"; TargetAttributes = { DF8DFFCE1C61DA1B00174DA9 = { @@ -257,10 +255,11 @@ }; buildConfigurationList = DFCEC6401C2EC01D0058EE65 /* Build configuration list for PBXProject "NetDiag" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = DFCEC63C1C2EC01D0058EE65; productRefGroup = DFCEC6461C2EC01D0058EE65 /* Products */; @@ -317,36 +316,6 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-NetDiagTests/Pods-NetDiagTests-resources.sh\"\n"; showEnvVarsInLog = 0; }; - 6360AC3809EC45C17B6B9A39 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-NetDiagTests/Pods-NetDiagTests-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - 7EB1F7F29D34632701B40C83 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-NetDiagTests/Pods-NetDiagTests-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; 9F9B0470989AE72C26C6B154 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -458,6 +427,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -466,12 +436,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -509,6 +481,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -517,12 +490,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; diff --git a/NetDiag.xcodeproj/xcshareddata/xcschemes/NetDiag.xcscheme b/NetDiag.xcodeproj/xcshareddata/xcschemes/NetDiag.xcscheme index bfc53bc..137577f 100644 --- a/NetDiag.xcodeproj/xcshareddata/xcschemes/NetDiag.xcscheme +++ b/NetDiag.xcodeproj/xcshareddata/xcschemes/NetDiag.xcscheme @@ -1,6 +1,6 @@ + + + + IDEDidComputeMac32BitWarning + + + diff --git a/NetDiag/QNNHttp.h b/NetDiag/QNNHttp.h index f21ca2b..2c11f0c 100644 --- a/NetDiag/QNNHttp.h +++ b/NetDiag/QNNHttp.h @@ -35,7 +35,8 @@ typedef void (^QNNHttpCompleteHandler)(QNNHttpResult*); * @return QNNTcpping instance, could be stop */ + (instancetype)start:(NSString*)url + headers:(NSDictionary *)headers output:(id)output complete:(QNNHttpCompleteHandler)complete; -@end \ No newline at end of file +@end diff --git a/NetDiag/QNNHttp.m b/NetDiag/QNNHttp.m index 1c86316..e0b43cd 100644 --- a/NetDiag/QNNHttp.m +++ b/NetDiag/QNNHttp.m @@ -43,6 +43,7 @@ - (instancetype)init:(NSInteger)code @interface QNNHttp () @property (readonly) NSString *url; +@property (readonly) NSDictionary *headers; @property (readonly) id output; @property (readonly) QNNHttpCompleteHandler complete; @end @@ -50,12 +51,14 @@ @interface QNNHttp () @implementation QNNHttp - (instancetype)init:(NSString *)url + headers:(NSDictionary *)headers output:(id)output complete:(QNNHttpCompleteHandler)complete { if (self = [super init]) { _url = url == nil ? @"" : url; _output = output; _complete = complete; + _headers = headers; } return self; } @@ -96,6 +99,9 @@ - (void)run { NSDate *t1 = [NSDate date]; NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:_url]]; [urlRequest setHTTPMethod:@"GET"]; + [_headers enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { + [urlRequest setValue:value forHTTPHeaderField:key]; + }]; NSHTTPURLResponse *response = nil; NSError *httpError = nil; @@ -110,7 +116,7 @@ - (void)run { [_output write:[NSString stringWithFormat:@"complete duration:%f status %ld\n", duration, (long)response.statusCode]]; if (response != nil && response.allHeaderFields != nil) { [response.allHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) { - [_output write:[NSString stringWithFormat:@"%@: %@\n", key, obj]]; + [self->_output write:[NSString stringWithFormat:@"%@: %@\n", key, obj]]; }]; } } @@ -128,12 +134,13 @@ - (void)run { } + (instancetype)start:(NSString *)url + headers:(NSDictionary *) headers output:(id)output complete:(QNNHttpCompleteHandler)complete { if (url == nil) { url = @""; } - QNNHttp *http = [[QNNHttp alloc] init:url output:output complete:complete]; + QNNHttp *http = [[QNNHttp alloc] init:url headers:headers output:output complete:complete]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { [http run]; }); diff --git a/NetDiag/QNNPing.m b/NetDiag/QNNPing.m index 19cfa56..0482cbb 100644 --- a/NetDiag/QNNPing.m +++ b/NetDiag/QNNPing.m @@ -331,8 +331,8 @@ - (void)run { [self.output write:@"Problem accessing the DNS"]; if (_complete != nil) { [QNNQue async_run_main:^(void) { - QNNPingResult *result = [[QNNPingResult alloc] init:-1006 ip:nil size:_size max:0 min:0 avg:0 loss:0 count:0 totalTime:0 stddev:0]; - _complete(result); + QNNPingResult *result = [[QNNPingResult alloc] init:-1006 ip:nil size:self->_size max:0 min:0 avg:0 loss:0 count:0 totalTime:0 stddev:0]; + self->_complete(result); }]; } return; @@ -385,7 +385,7 @@ - (void)run { totalTime:[[NSDate date] timeIntervalSinceDate:begin] * 1000]; [self.output write:result.description]; [QNNQue async_run_main:^(void) { - _complete(result); + self->_complete(result); }]; } free(durations); diff --git a/NetDiag/QNNRtmp.m b/NetDiag/QNNRtmp.m index 5bdbd42..d9b46ea 100644 --- a/NetDiag/QNNRtmp.m +++ b/NetDiag/QNNRtmp.m @@ -228,7 +228,7 @@ - (void)run { [self.output write:@"Problem accessing the DNS"]; if (_complete != nil) { dispatch_async(dispatch_get_main_queue(), ^(void) { - _complete([self buildResult:-1006 durations:nil count:0]); + self->_complete([self buildResult:-1006 durations:nil count:0]); }); } return; @@ -264,7 +264,7 @@ - (void)run { code = kQNNRequestStoped; } dispatch_async(dispatch_get_main_queue(), ^(void) { - _complete([self buildResult:code durations:intervals count:index]); + self->_complete([self buildResult:code durations:intervals count:index]); }); } free(intervals); diff --git a/NetDiag/QNNTcpPing.m b/NetDiag/QNNTcpPing.m index 6621501..ef4ad32 100644 --- a/NetDiag/QNNTcpPing.m +++ b/NetDiag/QNNTcpPing.m @@ -112,7 +112,7 @@ - (void)run { [self.output write:@"Problem accessing the DNS"]; if (_complete != nil) { dispatch_async(dispatch_get_main_queue(), ^(void) { - _complete([self buildResult:-1006 ip:nil durations:nil loss:0 count:0 totalTime:0]); + self->_complete([self buildResult:-1006 ip:nil durations:nil loss:0 count:0 totalTime:0]); }); } return; @@ -149,7 +149,7 @@ - (void)run { } __block NSDate *startDate = begin; dispatch_async(dispatch_get_main_queue(), ^(void) { - _complete([self buildResult:code ip:ip durations:intervals loss:loss count:index totalTime:[[NSDate date] timeIntervalSinceDate:startDate] * 1000]); + self->_complete([self buildResult:code ip:ip durations:intervals loss:loss count:index totalTime:[[NSDate date] timeIntervalSinceDate:startDate] * 1000]); free(intervals); }); } diff --git a/NetDiag/QNNTraceRoute.m b/NetDiag/QNNTraceRoute.m index 691c695..804dfd2 100644 --- a/NetDiag/QNNTraceRoute.m +++ b/NetDiag/QNNTraceRoute.m @@ -184,7 +184,7 @@ - (void)run { if (_complete != nil) { [QNNQue async_run_main:^(void) { QNNTraceRouteResult* result = [[QNNTraceRouteResult alloc] init:-1006 ip:nil content:nil]; - _complete(result); + self->_complete(result); }]; } return; @@ -199,7 +199,7 @@ - (void)run { if (_complete != nil) { [QNNQue async_run_main:^(void) { QNNTraceRouteResult* result = [[QNNTraceRouteResult alloc] init:-1 ip:[NSString stringWithUTF8String:inet_ntoa(addr.sin_addr)] content:nil]; - _complete(result); + self->_complete(result); }]; } close(recv_sock); @@ -227,8 +227,8 @@ - (void)run { code = kQNNRequestStoped; } [QNNQue async_run_main:^(void) { - QNNTraceRouteResult* result = [[QNNTraceRouteResult alloc] init:code ip:[NSString stringWithUTF8String:inet_ntoa(addr.sin_addr)] content:_contentString]; - _complete(result); + QNNTraceRouteResult* result = [[QNNTraceRouteResult alloc] init:code ip:[NSString stringWithUTF8String:inet_ntoa(addr.sin_addr)] content:self->_contentString]; + self->_complete(result); }]; } diff --git a/NetDiagTests/QNNHttpTest.m b/NetDiagTests/QNNHttpTest.m index cdb95aa..3c44098 100644 --- a/NetDiagTests/QNNHttpTest.m +++ b/NetDiagTests/QNNHttpTest.m @@ -31,7 +31,8 @@ - (void)tearDown { - (void)testOK { __block BOOL run = NO; - [QNNHttp start:@"http://www.baidu.com" output:[[QNNTestLogger alloc] init] complete:^(QNNHttpResult* r) { + + [QNNHttp start:@"http://www.baidu.com" headers:nil output:[[QNNTestLogger alloc] init] complete:^(QNNHttpResult* r) { XCTAssertNotNil(r, @"need result"); XCTAssertNotNil(r.ip, @"need ip"); XCTAssertNotNil(r.headers, @"need headers");