Skip to content

Commit 2ffc95b

Browse files
committed
format
1 parent c0dcfaa commit 2ffc95b

24 files changed

+485
-511
lines changed

NetDiag/QNNExternalIp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
@interface QNNExternalIp : NSObject
1212

13-
+(NSString*) externalIp;
14-
+(NSString*) externalDNS;
13+
+ (NSString*)externalIp;
14+
+ (NSString*)externalDNS;
1515

16-
+(NSString*)checkExternal;
16+
+ (NSString*)checkExternal;
1717

1818
@end

NetDiag/QNNExternalIp.m

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
#import "QNNExternalIp.h"
1010

11-
1211
@implementation QNNExternalIp
1312

14-
+(NSString*) externalIp{
13+
+ (NSString *)externalIp {
1514
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://whatismyip.akamai.com"]];
1615
[urlRequest setHTTPMethod:@"GET"];
17-
16+
1817
NSHTTPURLResponse *response = nil;
1918
NSError *httpError = nil;
2019
NSData *d = [NSURLConnection sendSynchronousRequest:urlRequest
@@ -23,23 +22,23 @@ +(NSString*) externalIp{
2322
if (httpError != nil || d == nil) {
2423
return @"";
2524
}
26-
NSString* s = [[NSString alloc]initWithData:d encoding:NSUTF8StringEncoding];
25+
NSString *s = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
2726
if (s == nil) {
2827
return @"";
2928
}
3029
return s;
3130
}
3231

33-
+(NSString*) externalDNS{
32+
+ (NSString *)externalDNS {
3433
return @"";
3534
}
3635

37-
+(NSString*)getDiagUrl{
38-
NSString* fetchurl = @"http://ns.pbt.cachecn.net/fast_tools/fetch_ldns_diag_client.php";
39-
36+
+ (NSString *)getDiagUrl {
37+
NSString *fetchurl = @"http://ns.pbt.cachecn.net/fast_tools/fetch_ldns_diag_client.php";
38+
4039
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:fetchurl]];
4140
[urlRequest setHTTPMethod:@"GET"];
42-
41+
4342
NSHTTPURLResponse *response = nil;
4443
NSError *httpError = nil;
4544
NSData *d = [NSURLConnection sendSynchronousRequest:urlRequest
@@ -50,7 +49,7 @@ +(NSString*)getDiagUrl{
5049
return nil;
5150
}
5251
NSLog(@"fetch http code %ld", (long)response.statusCode);
53-
NSString* s = [[NSString alloc]initWithData:d encoding:NSUTF8StringEncoding];
52+
NSString *s = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
5453
if (s == nil || [s isEqualToString:@""]) {
5554
NSLog(@"fetch http code %ld", (long)response.statusCode);
5655
return nil;
@@ -61,10 +60,10 @@ +(NSString*)getDiagUrl{
6160
}
6261
s = [s substringFromIndex:range.location + range.length];
6362
range = [s rangeOfString:@".php\""];
64-
if (range.location>4000) {
63+
if (range.location > 4000) {
6564
return nil;
6665
}
67-
s = [s substringToIndex:range.location+4];
66+
s = [s substringToIndex:range.location + 4];
6867
return s;
6968
}
7069

@@ -85,15 +84,15 @@ +(NSString*)getDiagUrl{
8584
//</pre>
8685
//<p class="result">您的DNS配置正确! </p>
8786

88-
+(NSString*)checkExternal{
89-
NSString* url = [QNNExternalIp getDiagUrl];
87+
+ (NSString *)checkExternal {
88+
NSString *url = [QNNExternalIp getDiagUrl];
9089
if (url == nil) {
9190
return @"get fetch url failed";
9291
}
93-
92+
9493
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
9594
[urlRequest setHTTPMethod:@"GET"];
96-
95+
9796
NSHTTPURLResponse *response = nil;
9897
NSError *httpError = nil;
9998
NSData *d = [NSURLConnection sendSynchronousRequest:urlRequest
@@ -103,29 +102,29 @@ +(NSString*)checkExternal{
103102
return @"check server error";
104103
}
105104
NSLog(@"http code %ld", (long)response.statusCode);
106-
NSString* s = [[NSString alloc]initWithData:d encoding:NSUTF8StringEncoding];
105+
NSString *s = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
107106
if (s == nil || [s isEqualToString:@""]) {
108107
return @"invalid encoding";
109108
}
110-
109+
111110
NSRange range = [s rangeOfString:@"<tr>"];
112111
s = [s substringFromIndex:range.location + range.length];
113112
range = [s rangeOfString:@"</table>"];
114113
s = [s substringToIndex:range.location];
115-
114+
116115
s = [s stringByReplacingOccurrencesOfString:@"</" withString:@"<"];
117-
116+
118117
s = [s stringByReplacingOccurrencesOfString:@"<tr>" withString:@""];
119118
s = [s stringByReplacingOccurrencesOfString:@"<th>" withString:@""];
120119
s = [s stringByReplacingOccurrencesOfString:@"<td>" withString:@""];
121120
s = [s stringByReplacingOccurrencesOfString:@"<td>" withString:@""];
122121
s = [s stringByReplacingOccurrencesOfString:@"<td width=\"128\" >" withString:@""];
123-
122+
124123
s = [s stringByReplacingOccurrencesOfString:@"<table>" withString:@""];
125124
s = [s stringByReplacingOccurrencesOfString:@"<p class=\"result\">" withString:@""];
126125
s = [s stringByReplacingOccurrencesOfString:@"<pre>" withString:@""];
127126
s = [s stringByReplacingOccurrencesOfString:@"<p>" withString:@""];
128-
127+
129128
s = [s stringByReplacingOccurrencesOfString:@"\n\n" withString:@"\n"];
130129
s = [s stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
131130
return s;

NetDiag/QNNHttp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// Copyright © 2016年 Qiniu Cloud Storage. All rights reserved.
77
//
88

9-
#import <Foundation/Foundation.h>
109
#import "QNNProtocols.h"
10+
#import <Foundation/Foundation.h>
1111

1212
@interface QNNHttpResult : NSObject
1313

@@ -16,13 +16,13 @@
1616
@property (readonly) NSDictionary* headers;
1717
@property (readonly) NSData* body;
1818

19-
-(NSString*) description;
19+
- (NSString*)description;
2020

2121
@end
2222

2323
typedef void (^QNNHttpCompleteHandler)(QNNHttpResult*);
2424

25-
@interface QNNHttp : NSObject<QNNStopDelegate>
25+
@interface QNNHttp : NSObject <QNNStopDelegate>
2626

2727
/**
2828
* default port is 80
@@ -33,7 +33,7 @@ typedef void (^QNNHttpCompleteHandler)(QNNHttpResult*);
3333
*
3434
* @return QNNTcpping instance, could be stop
3535
*/
36-
+(instancetype) start:(NSString*)url
36+
+ (instancetype)start:(NSString*)url
3737
output:(id<QNNOutputDelegate>)output
3838
complete:(QNNHttpCompleteHandler)complete;
3939

NetDiag/QNNHttp.m

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
@implementation QNNHttpResult
1212

13-
-(NSString*) description{
14-
NSString* bodySummary = @"";
13+
- (NSString *)description {
14+
NSString *bodySummary = @"";
1515
if (_body != nil) {
1616
NSString *str = [[NSString alloc] initWithData:_body encoding:NSUTF8StringEncoding];
1717
if (str == nil) {
@@ -21,11 +21,11 @@ -(NSString*) description{
2121
return [NSString stringWithFormat:@"code:%ld duration:%f body:%@", (long)_code, _duration, bodySummary];
2222
}
2323

24-
-(instancetype)init:(NSInteger)code
25-
duration:(NSTimeInterval)duration
26-
headers:(NSDictionary*)headers
27-
body:(NSData*)body{
28-
if(self = [super init]){
24+
- (instancetype)init:(NSInteger)code
25+
duration:(NSTimeInterval)duration
26+
headers:(NSDictionary *)headers
27+
body:(NSData *)body {
28+
if (self = [super init]) {
2929
_code = code;
3030
_duration = duration;
3131
_headers = headers;
@@ -34,20 +34,19 @@ -(instancetype)init:(NSInteger)code
3434
return self;
3535
}
3636

37-
3837
@end
3938

4039
@interface QNNHttp ()
41-
@property (readonly) NSString* url;
40+
@property (readonly) NSString *url;
4241
@property (readonly) id<QNNOutputDelegate> output;
4342
@property (readonly) QNNHttpCompleteHandler complete;
4443
@end
4544

4645
@implementation QNNHttp
4746

48-
-(instancetype)init:(NSString*)url
49-
output:(id<QNNOutputDelegate>) output
50-
complete:(QNNHttpCompleteHandler)complete{
47+
- (instancetype)init:(NSString *)url
48+
output:(id<QNNOutputDelegate>)output
49+
complete:(QNNHttpCompleteHandler)complete {
5150
if (self = [super init]) {
5251
_url = url;
5352
_output = output;
@@ -56,28 +55,27 @@ -(instancetype)init:(NSString*)url
5655
return self;
5756
}
5857

59-
-(void)run{
58+
- (void)run {
6059
if (_output) {
6160
[_output write:[NSString stringWithFormat:@"GET %@", _url]];
6261
}
63-
NSDate* t1 = [NSDate date];
62+
NSDate *t1 = [NSDate date];
6463
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:_url]];
6564
[urlRequest setHTTPMethod:@"GET"];
66-
65+
6766
NSHTTPURLResponse *response = nil;
6867
NSError *httpError = nil;
6968
NSData *d = [NSURLConnection sendSynchronousRequest:urlRequest
7069
returningResponse:&response
7170
error:&httpError];
72-
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:t1]*1000;
71+
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:t1] * 1000;
7372
if (_output) {
7473
if (httpError != nil) {
7574
[_output write:[httpError description]];
76-
7775
}
7876
[_output write:[NSString stringWithFormat:@"complete duration:%f status %ld\n", duration, (long)response.statusCode]];
79-
if (response != nil&& response.allHeaderFields != nil) {
80-
[response.allHeaderFields enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSString *obj, BOOL *stop) {
77+
if (response != nil && response.allHeaderFields != nil) {
78+
[response.allHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
8179
[_output write:[NSString stringWithFormat:@"%@: %@\n", key, obj]];
8280
}];
8381
}
@@ -86,28 +84,25 @@ -(void)run{
8684
return;
8785
}
8886
if (httpError != nil) {
89-
QNNHttpResult* result = [[QNNHttpResult alloc]init:httpError.code duration:duration headers:nil body:nil];
87+
QNNHttpResult *result = [[QNNHttpResult alloc] init:httpError.code duration:duration headers:nil body:nil];
9088
_complete(result);
9189
return;
9290
}
93-
QNNHttpResult* result = [[QNNHttpResult alloc]init:response.statusCode duration:duration headers:response.allHeaderFields body:d];
91+
QNNHttpResult *result = [[QNNHttpResult alloc] init:response.statusCode duration:duration headers:response.allHeaderFields body:d];
9492
_complete(result);
9593
}
9694

97-
+(instancetype) start:(NSString*)url
95+
+ (instancetype)start:(NSString *)url
9896
output:(id<QNNOutputDelegate>)output
99-
complete:(QNNHttpCompleteHandler)complete{
100-
QNNHttp* http = [[QNNHttp alloc] init:url output:output complete:complete];
97+
complete:(QNNHttpCompleteHandler)complete {
98+
QNNHttp *http = [[QNNHttp alloc] init:url output:output complete:complete];
10199
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
102100
[http run];
103101
});
104102
return http;
105103
}
106104

107-
-(void)stop{
108-
105+
- (void)stop {
109106
}
110107

111-
112-
113108
@end

NetDiag/QNNNslookup.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// Copyright © 2016年 Qiniu Cloud Storage. All rights reserved.
77
//
88

9-
#import <Foundation/Foundation.h>
109
#import "QNNProtocols.h"
10+
#import <Foundation/Foundation.h>
1111

1212
/**
1313
* A 记录
@@ -19,7 +19,6 @@ extern const int kQNNTypeA;
1919
*/
2020
extern const int kQNNTypeCname;
2121

22-
2322
@interface QNNRecord : NSObject
2423
@property (nonatomic, readonly) NSString *value;
2524
@property (readonly) int ttl;
@@ -29,21 +28,20 @@ extern const int kQNNTypeCname;
2928
ttl:(int)ttl
3029
type:(int)type;
3130

32-
- (NSString*) description;
31+
- (NSString *)description;
3332

3433
@end
3534

35+
typedef void (^QNNNslookupCompleteHandler)(NSArray *);
3636

37-
typedef void (^QNNNslookupCompleteHandler)(NSArray*);
38-
39-
@interface QNNNslookup : NSObject<QNNStopDelegate>
37+
@interface QNNNslookup : NSObject <QNNStopDelegate>
4038

41-
+(instancetype) start:(NSString*)domain
39+
+ (instancetype)start:(NSString *)domain
4240
output:(id<QNNOutputDelegate>)output
4341
complete:(QNNNslookupCompleteHandler)complete;
4442

45-
+(instancetype) start:(NSString*)domain
46-
server:(NSString*)dnsServer
43+
+ (instancetype)start:(NSString *)domain
44+
server:(NSString *)dnsServer
4745
output:(id<QNNOutputDelegate>)output
4846
complete:(QNNNslookupCompleteHandler)complete;
4947

0 commit comments

Comments
 (0)