From bc44f29fcec7c6df310b4db1b70ea663f468c66e Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Mon, 17 Oct 2022 15:13:58 +0800 Subject: [PATCH 01/15] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0sessionID=E7=AD=89?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.m | 42 ++++- MSDKDns/MSDKDnsInfoTool.h | 1 + MSDKDns/MSDKDnsInfoTool.m | 45 +++++ MSDKDns/MSDKDnsPrivate.h | 8 + MSDKDns/MSDKDnsService.h | 2 + MSDKDns/MSDKDnsService.m | 237 ++++++++++++++++++-------- MSDKDns/Reporter/AttaReport.m | 9 +- MSDKDns/Resolver/HttpsDnsResolver.h | 1 + MSDKDns/Resolver/HttpsDnsResolver.m | 4 + 9 files changed, 276 insertions(+), 73 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 472bc8d..ba9ebe7 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -11,6 +11,7 @@ #import "MSDKDnsParamsManager.h" #import "MSDKDnsNetworkManager.h" #import "msdkdns_local_ip_stack.h" +#import "AttaReport.h" #if defined(__has_include) #if __has_include("httpdnsIps.h") #include "httpdnsIps.h" @@ -202,6 +203,13 @@ - (NSDictionary *)getHostsByNamesEnableExpired:(NSArray *)domains verbose:(BOOL) - (void)getHostsByNames:(NSArray *)domains verbose:(BOOL)verbose returnIps:(void (^)(NSDictionary * ipsDict))handler { + [self getHostsByNames:domains verbose:verbose from:MSDKDnsEventHttpDnsNormal returnIps:handler]; +} + +- (void)getHostsByNames:(NSArray *)domains + verbose:(BOOL)verbose + from:(NSString *)origin + returnIps:(void (^)(NSDictionary * ipsDict))handler { // 获取当前ipv4/ipv6/双栈网络环境 msdkdns::MSDKDNS_TLocalIPStack netStack = [self detectAddressType]; __block float timeOut = 2.0; @@ -247,7 +255,7 @@ - (void)getHostsByNames:(NSArray *)domains [self.serviceArray addObject:dnsService]; __weak __typeof__(self) weakSelf = self; HttpDnsEncryptType encryptType = [[MSDKDnsParamsManager shareInstance] msdkDnsGetEncryptType]; - [dnsService getHostsByNames:toCheckDomains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType returnIps:^() { + [dnsService getHostsByNames:toCheckDomains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType from:origin returnIps:^() { __strong __typeof(self) strongSelf = weakSelf; if (strongSelf) { [toCheckDomains enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { @@ -279,7 +287,7 @@ - (void)refreshCacheDelay:(NSArray *)domains clearDispatchTag:(BOOL)needClear { HttpDnsEncryptType encryptType = [[MSDKDnsParamsManager shareInstance] msdkDnsGetEncryptType]; MSDKDnsService * dnsService = [[MSDKDnsService alloc] init]; - [dnsService getHostsByNames:domains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType returnIps:^{ + [dnsService getHostsByNames:domains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType from:MSDKDnsEventHttpDnsAutoRefresh returnIps:^{ if(needClear){ // 当请求结束了需要将该域名开启的标志清除,方便下次继续开启延迟解析请求 // NSLog(@"延时更新请求结束!请求域名为%@",domains); @@ -295,7 +303,7 @@ - (void)preResolveDomains { }); if (domains && [domains count] > 0) { MSDKDNSLOG(@"preResolve domains: %@", [domains componentsJoinedByString:@","] ); - [self getHostsByNames:domains verbose:NO returnIps:^(NSDictionary *ipsDict) { + [self getHostsByNames:domains verbose:NO from:MSDKDnsEventHttpDnsPreResolved returnIps:^(NSDictionary *ipsDict) { if (ipsDict) { MSDKDNSLOG(@"preResolve domains success."); } else { @@ -569,7 +577,35 @@ - (void)clearAllCache { } #pragma mark - uploadReport +- (void)hitCacheAttaUploadReport:(NSString *)domain { + static int count = 0; + count ++; + if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableReport] && [[AttaReport sharedInstance] shoulReportDnsSpend]) { + [[AttaReport sharedInstance] reportEvent:@{ + MSDKDns_ErrorCode: MSDKDns_Success, + @"eventName": MSDKDnsEventHttpDnsCached, + @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], + @"req_dn": domain, + @"req_type": @"a", + @"req_timeout": @0, + @"req_ttl": @0, + @"req_query": @0, + @"req_ip": @"", + @"spend": @0, + @"statusCode": @0, + @"count":[NSString stringWithFormat:@"%d", count], + @"isCache": @1, + }]; + count = 0; + } +} + - (void)uploadReport:(BOOL)isFromCache Domain:(NSString *)domain NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack { + // 命中缓存进行atta上报 + if (isFromCache) { + [self hitCacheAttaUploadReport:domain]; + } + Class beaconClass = NSClassFromString(@"BeaconBaseInterface"); if (beaconClass == 0x0) { MSDKDNSLOG(@"Beacon framework is not imported"); diff --git a/MSDKDns/MSDKDnsInfoTool.h b/MSDKDns/MSDKDnsInfoTool.h index fef0b55..f2dffa6 100644 --- a/MSDKDns/MSDKDnsInfoTool.h +++ b/MSDKDns/MSDKDnsInfoTool.h @@ -20,4 +20,5 @@ + (NSString *)encryptUseAES:(NSString *)plainText key:(NSString *)key; + (NSString *)decryptUseAES:(NSString *)cipherString key:(NSString *)key; + (NSURL *) httpsUrlWithDomain:(NSString *)domain DnsId:(int)dnsId DnsKey:(NSString *)dnsKey IPType:(HttpDnsIPType)ipType encryptType:(NSInteger)encryptType; //encryptType: 0 des,1 aes ++ (NSString *)generateSessionID; @end diff --git a/MSDKDns/MSDKDnsInfoTool.m b/MSDKDns/MSDKDnsInfoTool.m index 608e276..aa23845 100644 --- a/MSDKDns/MSDKDnsInfoTool.m +++ b/MSDKDns/MSDKDnsInfoTool.m @@ -471,4 +471,49 @@ + (NSString *) wifiSSID { return wifiName; } +/** + 生成sessionId,sessionId为12位,采用base62编码 + @return 返回sessionId + */ ++ (NSString *)generateSessionID { + static NSString *sessionId = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSString *alphabet = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + NSUInteger length = alphabet.length; + if (![self isValidString:sessionId]) { + NSMutableString *mSessionId = [NSMutableString string]; + for (int i = 0; i < 12; i++) { + [mSessionId appendFormat:@"%@", [alphabet substringWithRange:NSMakeRange(arc4random() % length, 1)]]; + } + sessionId = [mSessionId copy]; + } + }); + return sessionId; +} + ++ (BOOL)isValidString:(id)notValidString { + if (!notValidString) { + return NO; + } + BOOL isKindOf = NO; + @try { + isKindOf = [notValidString isKindOfClass:[NSString class]]; + } @catch (NSException *exception) {} + if (!isKindOf) { + return NO; + } + + NSInteger stringLength = 0; + @try { + stringLength = [notValidString length]; + } @catch (NSException *exception) { + MSDKDNSLOG(@"类名与方法名:%@(在第%@行), 描述:%@", @(__PRETTY_FUNCTION__), @(__LINE__), exception); + } + if (stringLength == 0) { + return NO; + } + return YES; +} + @end diff --git a/MSDKDns/MSDKDnsPrivate.h b/MSDKDns/MSDKDnsPrivate.h index 94df37b..e4bb4b2 100644 --- a/MSDKDns/MSDKDnsPrivate.h +++ b/MSDKDns/MSDKDnsPrivate.h @@ -64,10 +64,18 @@ static NSString * const kMSDKDns_DNS_4A_IP = @"dns_4a_ips"; // 域名 /*** 域名解析错误码*/ static NSString * const MSDKDns_Fail = @"-1"; // 失败 static NSString * const MSDKDns_Success = @"0"; // 成功 +static NSString * const MSDKDns_UnResolve = @"1"; // 未解析 +static NSString * const MSDKDns_Timeout = @"2"; // 解析超时 +static NSString * const MSDKDns_NoData = @"3"; // 没有解析数据 +static NSString * const MSDKDns_ErrorCode = @"errorCode"; /** 上报事件*/ static NSString * const MSDKDnsEventHttpDnsfail = @"HttpDnsfail"; static NSString * const MSDKDnsEventHttpDnsSpend = @"HttpDnsSpend"; +static NSString * const MSDKDnsEventHttpDnsCached = @"HDNSLookupCached"; //命中缓存 +static NSString * const MSDKDnsEventHttpDnsNormal = @"HDNSGetHostByName"; //常规解析请求 +static NSString * const MSDKDnsEventHttpDnsPreResolved = @"HDNSPreLookup"; //预解析请求 +static NSString * const MSDKDnsEventHttpDnsAutoRefresh = @"HDNSLookupAsync"; //缓存自动刷新 //命中缓存的状态 static NSString * const MSDKDnsDomainCacheHit = @"domainCacheHit"; //命中缓存 diff --git a/MSDKDns/MSDKDnsService.h b/MSDKDns/MSDKDnsService.h index 423bc0a..1ed7f70 100644 --- a/MSDKDns/MSDKDnsService.h +++ b/MSDKDns/MSDKDnsService.h @@ -11,4 +11,6 @@ - (void)getHostsByNames:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType returnIps:(void (^)())handler; +- (void)getHostsByNames:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType from:(NSString *)origin returnIps:(void (^)())handler; + @end diff --git a/MSDKDns/MSDKDnsService.m b/MSDKDns/MSDKDnsService.m index b6d313a..864d0c8 100644 --- a/MSDKDns/MSDKDnsService.m +++ b/MSDKDns/MSDKDnsService.m @@ -7,6 +7,7 @@ #import "LocalDnsResolver.h" #import "MSDKDnsInfoTool.h" #import "MSDKDnsLog.h" +#import "MSDKDnsPrivate.h" #import "MSDKDnsManager.h" #import "MSDKDnsDB.h" #import "MSDKDnsNetworkManager.h" @@ -28,6 +29,7 @@ @interface MSDKDnsService () @property (nonatomic, assign) float timeOut; @property (nonatomic, assign) int dnsId; @property (nonatomic, strong) NSString* dnsKey; +@property (nonatomic, strong) NSString* origin; @property (nonatomic, assign) NSUInteger encryptType; @end @@ -48,11 +50,17 @@ - (void)getHostByName:(NSString *)domain TimeOut:(float)timeOut DnsId:(int)dnsId } - (void)getHostsByNames:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType returnIps:(void (^)())handler +{ + [self getHostsByNames:domains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType from:MSDKDnsEventHttpDnsNormal returnIps:handler]; +} + +- (void)getHostsByNames:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType from:(NSString *)origin returnIps:(void (^)())handler { self.completionHandler = handler; self.toCheckDomains = domains; self.isCallBack = NO; self.netStack = netStack; + self.origin = origin; [self startCheck:timeOut DnsId:dnsId DnsKey:dnsKey encryptType:encryptType]; } @@ -214,6 +222,68 @@ - (void)resolver:(MSDKDnsResolver *)resolver didGetDomainInfo:(NSDictionary *)do } }]; + + // 正常解析结果上报,上报解析耗时 + if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableReport]) { + NSDictionary *domainDic = [domainInfo objectForKey:[self.toCheckDomains firstObject]]; + NSString* routeip = [[MSDKDnsParamsManager shareInstance] msdkDnsGetRouteIp]; + if (!routeip) { + routeip = @""; + } + HttpsDnsResolver *httpResolver = (HttpsDnsResolver *)resolver; + NSString *timeConsuming = @""; + if (domainDic) { + if(resolver == self.httpDnsResolver_BOTH){ + NSDictionary *ipv4CacheValue = [domainDic objectForKey:@"ipv4"]; + NSDictionary *ipv6CacheValue = [domainDic objectForKey:@"ipv6"]; + if (ipv4CacheValue) { + timeConsuming = [ipv4CacheValue objectForKey:kDnsTimeConsuming]; + } + if (ipv6CacheValue) { + timeConsuming = [ipv6CacheValue objectForKey:kDnsTimeConsuming]; + } + }else{ + timeConsuming = [domainDic objectForKey:kDnsTimeConsuming]; + } + } + NSString *req_type = @"a"; + if (resolver == self.httpDnsResolver_4A) { + req_type = @"aaaa"; + }else if (resolver == self.httpDnsResolver_BOTH) { + req_type = @"addrs"; + } + + NSDictionary * dnsIPs = [self getDomainsDNSFromCache:self.toCheckDomains]; + NSString *localDnsIPs = [dnsIPs valueForKey:kMSDKDnsLDNS_IP]; + NSString *httpDnsIP_A = [dnsIPs valueForKey:kMSDKDns_A_IP]; + NSString *httpDnsIP_4A = [dnsIPs valueForKey:kMSDKDns_4A_IP]; + NSString *httpdnsIPs = @""; + + if ([httpDnsIP_A length] > 0 && [httpDnsIP_4A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@,%@", httpDnsIP_A, httpDnsIP_4A]; + } else if ([httpDnsIP_A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@", httpDnsIP_A]; + } else if ([httpDnsIP_4A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@", httpDnsIP_4A]; + } + [[AttaReport sharedInstance] reportEvent:@{ + MSDKDns_ErrorCode: MSDKDns_Success, + @"eventName": self.origin, + @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], + @"req_dn": [self.toCheckDomains componentsJoinedByString:@","], + @"req_type": req_type, + @"req_timeout": @(self.timeOut * 1000), + @"req_ttl": @1, + @"req_query": @1, + @"req_ip": routeip, + @"spend": timeConsuming, + @"statusCode": @(httpResolver.statusCode), + @"count": @1, + @"isCache": @0, + @"ldns": localDnsIPs, + @"hdns": httpdnsIPs, + }]; + } } if (resolver == self.httpDnsResolver_A || resolver == self.httpDnsResolver_BOTH) { @@ -257,51 +327,74 @@ - (void)resolver:(MSDKDnsResolver *)resolver didGetDomainInfo:(NSDictionary *)do } } }); - - // 正常解析结果上报,上报解析耗时 - if (resolver == self.httpDnsResolver_A || resolver == self.httpDnsResolver_4A || resolver == self.httpDnsResolver_BOTH) { - if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableReport] && [[AttaReport sharedInstance] shoulReportDnsSpend]) { - NSDictionary *domainDic = [domainInfo objectForKey:[self.toCheckDomains firstObject]]; - NSString* routeip = [[MSDKDnsParamsManager shareInstance] msdkDnsGetRouteIp]; - if (!routeip) { - routeip = @""; - } - HttpsDnsResolver *httpResolver = (HttpsDnsResolver *)resolver; - NSString *timeConsuming = @""; - if (domainDic) { - if(resolver == self.httpDnsResolver_BOTH){ - NSDictionary *ipv4CacheValue = [domainDic objectForKey:@"ipv4"]; - NSDictionary *ipv6CacheValue = [domainDic objectForKey:@"ipv6"]; - if (ipv4CacheValue) { - timeConsuming = [ipv4CacheValue objectForKey:kDnsTimeConsuming]; +} + +- (NSDictionary *)getDomainsDNSFromCache:(NSArray *)domains { + NSDictionary * cacheDict = [[MSDKDnsManager shareInstance] domainDict]; + NSString * localDnsIPs = @""; + NSString * httpDnsIP_A = @""; + NSString * httpDnsIP_4A = @""; + if (cacheDict) { + for (NSString *domain in domains) { + NSDictionary * cacheInfo = cacheDict[domain]; + if (cacheInfo) { + NSDictionary * localDnsCache = cacheInfo[kMSDKLocalDnsCache]; + if (localDnsCache) { + NSArray * ipsArray = localDnsCache[kIP]; + if (ipsArray && [ipsArray count] == 2) { + if ([localDnsIPs length] > 0) { + localDnsIPs = [NSString stringWithFormat:@"%@,%@", localDnsIPs, [self getIPsStringFromIPsArray:ipsArray]]; + } else { + localDnsIPs = [NSString stringWithFormat:@"%@", [self getIPsStringFromIPsArray:ipsArray]]; + } + } - if (ipv6CacheValue) { - timeConsuming = [ipv6CacheValue objectForKey:kDnsTimeConsuming]; + } + NSDictionary * httpDnsCache_A = cacheInfo[kMSDKHttpDnsCache_A]; + if (httpDnsCache_A) { + NSArray * ipsArray = httpDnsCache_A[kIP]; + if (ipsArray && [ipsArray isKindOfClass:[NSArray class]] && ipsArray.count > 0) { + if ([httpDnsIP_A length] > 0) { + httpDnsIP_A = [NSString stringWithFormat:@"%@,%@", httpDnsIP_A, [self getIPsStringFromIPsArray:ipsArray]]; + } else { + httpDnsIP_A = [NSString stringWithFormat:@"%@", [self getIPsStringFromIPsArray:ipsArray]]; + } + } + } + NSDictionary * httpDnsCache_4A = cacheInfo[kMSDKHttpDnsCache_4A]; + if (httpDnsCache_4A) { + NSArray * ipsArray = httpDnsCache_4A[kIP]; + if (ipsArray && [ipsArray isKindOfClass:[NSArray class]] && ipsArray.count > 0) { + if ([httpDnsIP_4A length] > 0) { + httpDnsIP_4A = [NSString stringWithFormat:@"%@,%@", httpDnsIP_4A, [self getIPsStringFromIPsArray:ipsArray]]; + } else { + httpDnsIP_4A = [NSString stringWithFormat:@"%@", [self getIPsStringFromIPsArray:ipsArray]]; + } } - }else{ - timeConsuming = [domainDic objectForKey:kDnsTimeConsuming]; } } - NSString *req_type = @"a"; - if (resolver == self.httpDnsResolver_4A) { - req_type = @"aaaa"; - }else if (resolver == self.httpDnsResolver_BOTH) { - req_type = @"addrs"; - } - [[AttaReport sharedInstance] reportEvent:@{ - @"eventName": MSDKDnsEventHttpDnsSpend, - @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], - @"req_dn": [self.toCheckDomains componentsJoinedByString:@","], - @"req_type": req_type, - @"req_timeout": @(self.timeOut * 1000), - @"req_ttl": @1, - @"req_query": @1, - @"req_ip": routeip, - @"spend": timeConsuming, - @"statusCode": @(httpResolver.statusCode), - }]; - } - } + } + } + return @{ + kMSDKDns_A_IP:httpDnsIP_A, + kMSDKDns_4A_IP:httpDnsIP_4A, + kMSDKDnsLDNS_IP: localDnsIPs + }; +} + +- (NSString *)getIPsStringFromIPsArray:(NSArray *)ipsArray { + NSMutableString *ipsStr = [NSMutableString stringWithString:@""]; + if (ipsArray && [ipsArray isKindOfClass:[NSArray class]] && ipsArray.count > 0) { + for (int i = 0; i < ipsArray.count; i++) { + NSString *ip = ipsArray[i]; + if (i != ipsArray.count - 1) { + [ipsStr appendFormat:@"%@,",ip]; + } else { + [ipsStr appendString:ip]; + } + } + } + return ipsStr; } - (void)aysncUpdateIPRankingWithResult:(NSArray *)IPStrings forHost:(NSString *)host { @@ -361,37 +454,16 @@ - (void)resolver:(MSDKDnsResolver *)resolver getDomainError:(NSString *)error re [self retryHttpDns:resolver]; } else { dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - NSDictionary * info = @{kDnsErrCode:MSDKDns_Fail, kDnsErrMsg:@"", kDnsRetry:@"0"}; + NSDictionary * info = @{kDnsErrCode:MSDKDns_UnResolve, kDnsErrMsg:@"", kDnsRetry:@"0"}; [self callBack:resolver Info:info]; }); + [self dnsTimeoutAttaUpload:resolver]; } } -#pragma mark - retry -- (void) retryHttpDns:(MSDKDnsResolver *)resolver { - self.httpdnsFailCount += 1; - if (self.httpdnsFailCount < [[MSDKDnsParamsManager shareInstance] msdkDnsGetRetryTimesBeforeSwitchServer]) { - if (resolver == self.httpDnsResolver_A) { - dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ - [self startHttpDns:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; - }); - } else if (resolver == self.httpDnsResolver_4A) { - dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ - [self startHttpDns_4A:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; - }); - } else if (resolver == self.httpDnsResolver_BOTH) { - dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ - [self startHttpDnsBoth:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; - }); - } - } else { - MSDKDNSLOG(@"fail %lu times, switch server!", (unsigned long)[[MSDKDnsParamsManager shareInstance] msdkDnsGetRetryTimesBeforeSwitchServer]); - // 失败超过三次,返回错误结果并切换备份ip - dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - NSDictionary * info = @{kDnsErrCode:MSDKDns_Fail, kDnsErrMsg:@"", kDnsRetry:@"0"}; - [self callBack:resolver Info:info]; - }); +- (void)dnsTimeoutAttaUpload:(MSDKDnsResolver *)resolver { + if (resolver == self.httpDnsResolver_A || resolver == self.httpDnsResolver_4A || resolver == self.httpDnsResolver_BOTH) { if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableReport]) { NSString* routeip = [[MSDKDnsParamsManager shareInstance] msdkDnsGetRouteIp]; if (!routeip) { @@ -405,7 +477,8 @@ - (void) retryHttpDns:(MSDKDnsResolver *)resolver { req_type = @"addrs"; } [[AttaReport sharedInstance] reportEvent:@{ - @"eventName": MSDKDnsEventHttpDnsfail, + MSDKDns_ErrorCode: httpResolver.errorCode, + @"eventName": self.origin, @"dnsIp": [[MSDKDnsManager shareInstance] currentDnsServer], @"req_dn": [self.toCheckDomains componentsJoinedByString:@","], @"req_type": req_type, @@ -414,8 +487,38 @@ - (void) retryHttpDns:(MSDKDnsResolver *)resolver { @"req_query": @1, @"req_ip": routeip, @"statusCode": @(httpResolver.statusCode), + @"count": @1, + @"isCache": @0, }]; } + } +} + +#pragma mark - retry +- (void) retryHttpDns:(MSDKDnsResolver *)resolver { + self.httpdnsFailCount += 1; + if (self.httpdnsFailCount < [[MSDKDnsParamsManager shareInstance] msdkDnsGetRetryTimesBeforeSwitchServer]) { + if (resolver == self.httpDnsResolver_A) { + dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ + [self startHttpDns:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; + }); + } else if (resolver == self.httpDnsResolver_4A) { + dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ + [self startHttpDns_4A:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; + }); + } else if (resolver == self.httpDnsResolver_BOTH) { + dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ + [self startHttpDnsBoth:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; + }); + } + } else { + MSDKDNSLOG(@"fail %lu times, switch server!", (unsigned long)[[MSDKDnsParamsManager shareInstance] msdkDnsGetRetryTimesBeforeSwitchServer]); + // 失败超过三次,返回错误结果并切换备份ip + dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ + NSDictionary * info = @{kDnsErrCode:MSDKDns_UnResolve, kDnsErrMsg:@"", kDnsRetry:@"0"}; + [self callBack:resolver Info:info]; + }); + [self dnsTimeoutAttaUpload:resolver]; [[MSDKDnsManager shareInstance] switchDnsServer]; } } diff --git a/MSDKDns/Reporter/AttaReport.m b/MSDKDns/Reporter/AttaReport.m index d644182..5c906b8 100644 --- a/MSDKDns/Reporter/AttaReport.m +++ b/MSDKDns/Reporter/AttaReport.m @@ -10,6 +10,7 @@ #import "MSDKDnsLog.h" #import "MSDKDnsNetworkManager.h" #import "MSDKDnsParamsManager.h" +#import "MSDKDnsInfoTool.h" #import #import #import @@ -82,6 +83,7 @@ - (NSString *)formatReportParams:(NSDictionary *)params { @"systemName": systemName, @"systemVersion": systemVersion, @"sdkVersion": MSDKDns_Version, + @"sessionId": [MSDKDnsInfoTool generateSessionID] }]; return [self paramsToUrlString:dic]; } @@ -122,9 +124,10 @@ + (NSString*)getOperatorsType{ } - (BOOL)shoulReportDnsSpend { - if (self.count >= self.limit) { - return NO; - } +// 取消上报次数上限,每5分钟上报一次 +// if (self.count >= self.limit) { +// return NO; +// } NSDate *now = [NSDate date]; if ([now timeIntervalSinceDate:self.lastReportTime] >= self.interval) { self.lastReportTime = now; diff --git a/MSDKDns/Resolver/HttpsDnsResolver.h b/MSDKDns/Resolver/HttpsDnsResolver.h index b4b59fe..8684710 100644 --- a/MSDKDns/Resolver/HttpsDnsResolver.h +++ b/MSDKDns/Resolver/HttpsDnsResolver.h @@ -10,6 +10,7 @@ @interface HttpsDnsResolver : MSDKDnsResolver @property (nonatomic, assign) NSInteger statusCode; +@property (strong, nonatomic) NSString * errorCode; - (void)startWithDomains:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType; diff --git a/MSDKDns/Resolver/HttpsDnsResolver.m b/MSDKDns/Resolver/HttpsDnsResolver.m index 306ca18..bc34ca0 100644 --- a/MSDKDns/Resolver/HttpsDnsResolver.m +++ b/MSDKDns/Resolver/HttpsDnsResolver.m @@ -32,6 +32,7 @@ - (void)startWithDomains:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dn { [super startWithDomains:domains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack]; NSString *domainStr = [domains componentsJoinedByString:@","]; + self.errorCode = MSDKDns_UnResolve; if (!domainStr || domainStr.length == 0) { MSDKDNSLOG(@"HttpDns Domain is must needed!"); self.domainInfo = nil; @@ -183,6 +184,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection { if (self.domainInfo && [self.domainInfo count] > 0) { self.isFinished = YES; + self.errorCode = MSDKDns_Success; self.isSucceed = YES; if (self.delegate && [self.delegate respondsToSelector:@selector(resolver:didGetDomainInfo:)]) { [self.delegate resolver:self didGetDomainInfo:self.domainInfo]; @@ -199,6 +201,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection { self.domainInfo = nil; self.isFinished = YES; self.isSucceed = NO; + self.errorCode = MSDKDns_NoData; self.errorInfo = errorInfo; if (self.delegate && [self.delegate respondsToSelector:@selector(resolver:getDomainError:retry:)]) { [self.delegate resolver:self getDomainError:self.errorInfo retry:NO]; @@ -210,6 +213,7 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err MSDKDNSLOG(@"HttpDns Failed:%@",[error userInfo]); self.domainInfo = nil; self.isFinished = YES; + self.errorCode = MSDKDns_Timeout; self.isSucceed = NO; self.errorInfo = error.userInfo[@"NSLocalizedDescription"]; if (self.delegate && [self.delegate respondsToSelector:@selector(resolver:getDomainError:retry:)]) { From fa885b2a546d2e729fac6f08454922a69090c9f3 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Wed, 19 Oct 2022 16:32:07 +0800 Subject: [PATCH 02/15] =?UTF-8?q?feat:=E6=9B=BF=E6=8D=A2WCDB=E4=B8=BASQLit?= =?UTF-8?q?e3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns.xcodeproj/project.pbxproj | 40 ++- MSDKDns/{WCDB => DB}/MSDKDnsDB.h | 0 MSDKDns/DB/MSDKDnsDB.m | 309 +++++++++++++++++++++++ MSDKDns/WCDB/HTTPDNSORM+WCTTableCoding.h | 29 --- MSDKDns/WCDB/HTTPDNSORM.h | 26 -- MSDKDns/WCDB/HTTPDNSORM.m | 39 --- MSDKDns/WCDB/MSDKDnsDB.m | 203 --------------- 7 files changed, 326 insertions(+), 320 deletions(-) rename MSDKDns/{WCDB => DB}/MSDKDnsDB.h (100%) create mode 100644 MSDKDns/DB/MSDKDnsDB.m delete mode 100644 MSDKDns/WCDB/HTTPDNSORM+WCTTableCoding.h delete mode 100644 MSDKDns/WCDB/HTTPDNSORM.h delete mode 100644 MSDKDns/WCDB/HTTPDNSORM.m delete mode 100644 MSDKDns/WCDB/MSDKDnsDB.m diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 67b28f9..d4a27c7 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -38,14 +38,10 @@ 54EA82232760890B005F68A9 /* AttaReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 54EA82212760890B005F68A9 /* AttaReport.m */; }; 54EA822427608A55005F68A9 /* AttaReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 54EA82202760890B005F68A9 /* AttaReport.h */; }; 54EA822527608A58005F68A9 /* AttaReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 54EA82212760890B005F68A9 /* AttaReport.m */; }; - 5F1E288028B72A7D00AD0D9F /* HTTPDNSORM.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287B28B72A7D00AD0D9F /* HTTPDNSORM.m */; }; - 5F1E288128B72A7D00AD0D9F /* HTTPDNSORM.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287B28B72A7D00AD0D9F /* HTTPDNSORM.m */; }; - 5F1E288228B72A7D00AD0D9F /* HTTPDNSORM.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287C28B72A7D00AD0D9F /* HTTPDNSORM.h */; }; - 5F1E288328B72A7D00AD0D9F /* HTTPDNSORM.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287C28B72A7D00AD0D9F /* HTTPDNSORM.h */; }; + 5F1332E928FFEC4A00A22D2A /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */; }; + 5F1332EA28FFEC5000A22D2A /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */; }; 5F1E288428B72A7D00AD0D9F /* MSDKDnsDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */; }; 5F1E288528B72A7D00AD0D9F /* MSDKDnsDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */; }; - 5F1E288628B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287E28B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h */; }; - 5F1E288728B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287E28B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h */; }; 5F1E288828B72A7D00AD0D9F /* MSDKDnsDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */; }; 5F1E288928B72A7D00AD0D9F /* MSDKDnsDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */; }; 5F5DAF4E28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F5DAF4B28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h */; }; @@ -120,12 +116,9 @@ 54EA81F1275478D1005F68A9 /* httpdnsIps.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = httpdnsIps.h; sourceTree = ""; }; 54EA82202760890B005F68A9 /* AttaReport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttaReport.h; sourceTree = ""; }; 54EA82212760890B005F68A9 /* AttaReport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AttaReport.m; sourceTree = ""; }; - 5F1E287B28B72A7D00AD0D9F /* HTTPDNSORM.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTTPDNSORM.m; sourceTree = ""; }; - 5F1E287C28B72A7D00AD0D9F /* HTTPDNSORM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTTPDNSORM.h; sourceTree = ""; }; + 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libsqlite3.tbd; sourceTree = DEVELOPER_DIR; }; 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSDKDnsDB.m; sourceTree = ""; }; - 5F1E287E28B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HTTPDNSORM+WCTTableCoding.h"; sourceTree = ""; }; 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSDKDnsDB.h; sourceTree = ""; }; - 5F1E288F28B86DFD00AD0D9F /* WCDB.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WCDB.framework; path = ../WCDB.framework; sourceTree = ""; }; 5F5DAF4B28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSDKDnsTCPSpeedTester.h; sourceTree = ""; }; 5F5DAF4C28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSDKDnsTCPSpeedTester.m; sourceTree = ""; }; 5F5DAF4D28A525E300BF5B79 /* MSDKDnsSpeedTester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSDKDnsSpeedTester.h; sourceTree = ""; }; @@ -142,6 +135,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5F1332EA28FFEC5000A22D2A /* libsqlite3.tbd in Frameworks */, C8EBE7F7256669B900BEFEEC /* libc++.tbd in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -150,6 +144,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5F1332E928FFEC4A00A22D2A /* libsqlite3.tbd in Frameworks */, C8EBE7F4256668A300BEFEEC /* libc++.tbd in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -195,7 +190,7 @@ 5F5DAF4C28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.m */, C8EBE7D1256664C400BEFEEC /* aes.h */, C8EBE7D2256664C500BEFEEC /* aes.mm */, - 5F85CBA828B4B3B1003D20D1 /* WCDB */, + 5F85CBA828B4B3B1003D20D1 /* DB */, 54EA821F2760890B005F68A9 /* Reporter */, 501001EB215E1F1D003288A5 /* Network */, 445B363D1CBBBFAF00BD4345 /* Manager */, @@ -268,22 +263,19 @@ path = Reporter; sourceTree = ""; }; - 5F85CBA828B4B3B1003D20D1 /* WCDB */ = { + 5F85CBA828B4B3B1003D20D1 /* DB */ = { isa = PBXGroup; children = ( - 5F1E287C28B72A7D00AD0D9F /* HTTPDNSORM.h */, - 5F1E287B28B72A7D00AD0D9F /* HTTPDNSORM.m */, - 5F1E287E28B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h */, 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */, 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */, ); - path = WCDB; + path = DB; sourceTree = ""; }; C8EBE7D92566675800BEFEEC /* Frameworks */ = { isa = PBXGroup; children = ( - 5F1E288F28B86DFD00AD0D9F /* WCDB.framework */, + 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */, C8EBE7DA2566675800BEFEEC /* libc++.tbd */, ); name = Frameworks; @@ -296,7 +288,6 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 5F1E288228B72A7D00AD0D9F /* HTTPDNSORM.h in Headers */, 44BFE2481CA59D9800D7FE87 /* MSDKDnsReachability.h in Headers */, 5F1E288828B72A7D00AD0D9F /* MSDKDnsDB.h in Headers */, 504F543A1ECAF89F001BD7A9 /* MSDKDnsHttpMessageTools.h in Headers */, @@ -310,7 +301,6 @@ 5F5DAF4E28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h in Headers */, 448EE4E81B329899004A2131 /* MSDKDnsResolver.h in Headers */, 54EA82222760890B005F68A9 /* AttaReport.h in Headers */, - 5F1E288628B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h in Headers */, 5F5DAF5228A525E300BF5B79 /* MSDKDnsSpeedTester.h in Headers */, 44BFE2371CA58C3A00D7FE87 /* MSDKDnsInfoTool.h in Headers */, 502422EC2140073F0094403C /* MSDKDnsParamsManager.h in Headers */, @@ -324,7 +314,6 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 5F1E288328B72A7D00AD0D9F /* HTTPDNSORM.h in Headers */, DD43F4A6231CC36D0000A89F /* MSDKDnsReachability.h in Headers */, 5F1E288928B72A7D00AD0D9F /* MSDKDnsDB.h in Headers */, DD43F4A7231CC36D0000A89F /* MSDKDnsHttpMessageTools.h in Headers */, @@ -338,7 +327,6 @@ 5F5DAF4F28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h in Headers */, DD43F4AE231CC36D0000A89F /* MSDKDnsResolver.h in Headers */, 54EA822427608A55005F68A9 /* AttaReport.h in Headers */, - 5F1E288728B72A7D00AD0D9F /* HTTPDNSORM+WCTTableCoding.h in Headers */, 5F5DAF5328A525E300BF5B79 /* MSDKDnsSpeedTester.h in Headers */, DD43F4AF231CC36D0000A89F /* MSDKDnsInfoTool.h in Headers */, DD43F4B0231CC36D0000A89F /* MSDKDnsParamsManager.h in Headers */, @@ -546,7 +534,6 @@ 448EE4E91B329899004A2131 /* MSDKDnsResolver.m in Sources */, 54EA82232760890B005F68A9 /* AttaReport.m in Sources */, 4455D15F1B3A5B90005BF126 /* MSDKDns.m in Sources */, - 5F1E288028B72A7D00AD0D9F /* HTTPDNSORM.m in Sources */, 448EE4E71B329899004A2131 /* LocalDnsResolver.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -571,7 +558,6 @@ DD43F4A0231CC36D0000A89F /* MSDKDnsResolver.m in Sources */, 54EA822527608A58005F68A9 /* AttaReport.m in Sources */, DD43F4A1231CC36D0000A89F /* MSDKDns.m in Sources */, - 5F1E288128B72A7D00AD0D9F /* HTTPDNSORM.m in Sources */, DD43F4A2231CC36D0000A89F /* LocalDnsResolver.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -708,6 +694,10 @@ INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(SYSTEM_LIBRARY_DIR)/Tcl/sqlite3", + ); LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; @@ -750,6 +740,10 @@ INFOPLIST_FILE = MSDKDns/Info.plist; INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(SYSTEM_LIBRARY_DIR)/Tcl/sqlite3", + ); LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; diff --git a/MSDKDns/WCDB/MSDKDnsDB.h b/MSDKDns/DB/MSDKDnsDB.h similarity index 100% rename from MSDKDns/WCDB/MSDKDnsDB.h rename to MSDKDns/DB/MSDKDnsDB.h diff --git a/MSDKDns/DB/MSDKDnsDB.m b/MSDKDns/DB/MSDKDnsDB.m new file mode 100644 index 0000000..9eda1f6 --- /dev/null +++ b/MSDKDns/DB/MSDKDnsDB.m @@ -0,0 +1,309 @@ +// Created by eric hu on 2022/8/23. +// Copyright © 2022 Tencent. All rights reserved. +// + +#import "MSDKDnsDB.h" +#import "MSDKDnsLog.h" +#import "MSDKDnsPrivate.h" +#import + + +@interface MSDKDnsDB () + +@property (nonatomic,assign) sqlite3 *db; +@property char *error; + + +@end + +@implementation MSDKDnsDB + +#pragma mark - init + +static MSDKDnsDB * _sharedInstance = nil; + ++ (instancetype)shareInstance { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _sharedInstance = [[MSDKDnsDB alloc] init]; + }); + return _sharedInstance; +} + +- (instancetype) init { + if (self = [super init]) { + @try { + NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); + NSString *baseDirectory = [documentPaths objectAtIndex:0]; + + // 设置数据库文件路径 + NSString *fileName = [baseDirectory stringByAppendingPathComponent:@"httpdns.sqlite"]; + NSLog(@"fileName === %@", fileName); + //打开数据库文件(如果数据库文件不存在,那么该函数会自动创建数据库文件) + int result = sqlite3_open([fileName UTF8String], &_db); + if (result == SQLITE_OK) {//打开成功 + NSLog(@"成功打开数据库"); + // NSString *createSql = @"create table if not exists myTable(id integer primary key autoincrement, name text UNIQUE, age integer, address text)"; + NSString *createSql = @"create table if not exists HttpDNSTable(id integer primary key autoincrement, domain text UNIQUE, httpDnsIPV4Channel text, httpDnsIPV4ClientIP text, httpDnsIPV4IPs text, httpDnsIPV4TimeConsuming text, httpDnsIPV4TTL text, httpDnsIPV4TTLExpried text, httpDnsIPV6Channel text, httpDnsIPV6ClientIP text, httpDnsIPV6IPs text, httpDnsIPV6TimeConsuming text, httpDnsIPV6TTL text, httpDnsIPV6TTLExpried text)"; + + if (sqlite3_exec(_db, [createSql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { + NSLog(@"create table is ok."); + } else { + NSLog(@"error: %s", _error); + + // 每次使用完毕清空 error 字符串,提供给下一次使用 + sqlite3_free(_error); + } + }else{ + NSLog(@"打开数据库失败"); + } + } @catch (NSException *exception) { + MSDKDNSLOG(@"database connection failed"); + } + } + return self; +} + +- (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *)domain { + + NSDictionary * hresultDict_A = domainInfo[kMSDKHttpDnsCache_A]; + NSDictionary * hresultDict_4A = domainInfo[kMSDKHttpDnsCache_4A]; + + NSString *hresultDict_A_kChannel = @""; + NSString *hresultDict_A_kClientIP = @""; + NSString *hresultDict_A_kIP = @""; + NSString *hresultDict_A_kDnsTimeConsuming = @""; + NSString *hresultDict_A_kTTL = @""; + NSString *hresultDict_A_kTTLExpired = @""; + NSString *hresultDict_4A_kChannel = @""; + NSString *hresultDict_4A_kClientIP = @""; + NSString *hresultDict_4A_kIP = @""; + NSString *hresultDict_4A_kDnsTimeConsuming = @""; + NSString *hresultDict_4A_kTTL = @""; + NSString *hresultDict_4A_kTTLExpired = @""; + + if(hresultDict_A){ + if(hresultDict_A[kChannel]){ + hresultDict_A_kChannel = hresultDict_A[kChannel]; + } + if(hresultDict_A[kClientIP]){ + hresultDict_A_kClientIP = hresultDict_A[kClientIP]; + } + if(hresultDict_A[kIP]){ + hresultDict_A_kIP = [hresultDict_A[kIP] componentsJoinedByString:@","]; + } + if(hresultDict_A[kDnsTimeConsuming]){ + hresultDict_A_kDnsTimeConsuming = hresultDict_A[kDnsTimeConsuming]; + } + if(hresultDict_A[kTTL]){ + hresultDict_A_kTTL = hresultDict_A[kTTL]; + } + if(hresultDict_A[kTTLExpired]){ + hresultDict_A_kTTLExpired = hresultDict_A[kTTLExpired]; + } + } + + if(hresultDict_4A){ + if(hresultDict_4A[kChannel]){ + hresultDict_4A_kChannel = hresultDict_4A[kChannel]; + } + if(hresultDict_4A[kClientIP]){ + hresultDict_4A_kClientIP = hresultDict_4A[kClientIP]; + } + if(hresultDict_4A[kIP]){ + hresultDict_4A_kIP = [hresultDict_4A[kIP] componentsJoinedByString:@","]; + } + if(hresultDict_4A[kDnsTimeConsuming]){ + hresultDict_4A_kDnsTimeConsuming = hresultDict_4A[kDnsTimeConsuming]; + } + if(hresultDict_4A[kTTL]){ + hresultDict_4A_kTTL = hresultDict_4A[kTTL]; + } + if(hresultDict_4A[kTTLExpired]){ + hresultDict_4A_kTTLExpired = hresultDict_4A[kTTLExpired]; + } + } + + // NSString *createSql = @"create table if not exists myTable(id integer primary key autoincrement, name text UNIQUE, age integer, address text)"; + NSString *insertSql = [NSString stringWithFormat:@"INSERT OR REPLACE into HttpDNSTable(domain, httpDnsIPV4Channel, httpDnsIPV4ClientIP, httpDnsIPV4IPs, httpDnsIPV4TimeConsuming, httpDnsIPV4TTL, httpDnsIPV4TTLExpried, httpDnsIPV6ClientIP, httpDnsIPV6IPs, httpDnsIPV6TimeConsuming, httpDnsIPV6TTL, httpDnsIPV6TTLExpried) values('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@')",[domain copy],hresultDict_A_kChannel,hresultDict_A_kClientIP,hresultDict_A_kIP,hresultDict_A_kDnsTimeConsuming,hresultDict_A_kTTL,hresultDict_A_kTTLExpired,hresultDict_4A_kClientIP,hresultDict_4A_kIP,hresultDict_4A_kDnsTimeConsuming,hresultDict_4A_kTTL,hresultDict_4A_kTTLExpired]; + + if (sqlite3_exec(_db, [insertSql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { + NSLog(@"insert operation is ok."); + } else { + NSLog(@"error: %s", _error); + + // 每次使用完毕清空 error 字符串,提供给下一次使用 + sqlite3_free(_error); + } +} + +- (NSDictionary *)getDataFromDB { + NSMutableDictionary *newResult = [[NSMutableDictionary alloc] init]; + + sqlite3_stmt *statement; + + // @"select * from myTable" 查询所有 key 值内容 + // NSString *selectSql = @"select id, name, age, address from myTable"; + NSString *selectSql = @"select domain, httpDnsIPV4Channel, httpDnsIPV4ClientIP, httpDnsIPV4IPs, httpDnsIPV4TimeConsuming, httpDnsIPV4TTL, httpDnsIPV4TTLExpried, httpDnsIPV6Channel, httpDnsIPV6ClientIP, httpDnsIPV6IPs, httpDnsIPV6TimeConsuming, httpDnsIPV6TTL, httpDnsIPV6TTLExpried from HttpDNSTable"; + + if (sqlite3_prepare_v2(_db, [selectSql UTF8String], -1, &statement, nil) == SQLITE_OK) { + + while(sqlite3_step(statement) == SQLITE_ROW) { + NSMutableDictionary *domainInfo = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *httpDnsIPV4Info = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *httpDnsIPV6Info = [[NSMutableDictionary alloc] init]; + + NSString *domain = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]; + + char *httpDnsIPV4Channel_char = (char *)sqlite3_column_text(statement, 1); + NSString *httpDnsIPV4Channel = httpDnsIPV4Channel_char ? [NSString stringWithUTF8String:httpDnsIPV4Channel_char] : nil; + + char *httpDnsIPV4ClientIP_char = (char *)sqlite3_column_text(statement, 2); + NSString *httpDnsIPV4ClientIP = httpDnsIPV4ClientIP_char ? [NSString stringWithUTF8String:httpDnsIPV4ClientIP_char] : nil; + + char *httpDnsIPV4IPs_char = (char *)sqlite3_column_text(statement, 3); + NSString *httpDnsIPV4IPs = httpDnsIPV4IPs_char ? [NSString stringWithUTF8String:httpDnsIPV4IPs_char] : nil; + + char *httpDnsIPV4TimeConsuming_char = (char *)sqlite3_column_text(statement, 4); + NSString *httpDnsIPV4TimeConsuming = httpDnsIPV4TimeConsuming_char ? [NSString stringWithUTF8String:httpDnsIPV4TimeConsuming_char] : nil; + + char *httpDnsIPV4TTL_char = (char *)sqlite3_column_text(statement, 5); + NSString *httpDnsIPV4TTL = httpDnsIPV4TTL_char ? [NSString stringWithUTF8String:httpDnsIPV4TTL_char] : nil; + + char *httpDnsIPV4TTLExpried_char = (char *)sqlite3_column_text(statement, 6); + NSString *httpDnsIPV4TTLExpried = httpDnsIPV4TTLExpried_char ? [NSString stringWithUTF8String:httpDnsIPV4TTLExpried_char] : nil; + + char *httpDnsIPV6Channel_char = (char *)sqlite3_column_text(statement, 7); + NSString *httpDnsIPV6Channel = httpDnsIPV6Channel_char ? [NSString stringWithUTF8String:httpDnsIPV6Channel_char] : nil; + + char *httpDnsIPV6ClientIP_char = (char *)sqlite3_column_text(statement, 8); + NSString *httpDnsIPV6ClientIP = httpDnsIPV6ClientIP_char ? [NSString stringWithUTF8String:httpDnsIPV6ClientIP_char] : nil; + + char *httpDnsIPV6IPs_char = (char *)sqlite3_column_text(statement, 9); + NSString *httpDnsIPV6IPs = httpDnsIPV6IPs_char ? [NSString stringWithUTF8String:httpDnsIPV6IPs_char] : nil; + + char *httpDnsIPV6TimeConsuming_char = (char *)sqlite3_column_text(statement, 10); + NSString *httpDnsIPV6TimeConsuming = httpDnsIPV6TimeConsuming_char ? [NSString stringWithUTF8String:httpDnsIPV6TimeConsuming_char] : nil; + + char *httpDnsIPV6TTL_char = (char *)sqlite3_column_text(statement, 11); + NSString *httpDnsIPV6TTL = httpDnsIPV6TTL_char ? [NSString stringWithUTF8String:httpDnsIPV6TTL_char] : nil; + + char *httpDnsIPV6TTLExpried_char = (char *)sqlite3_column_text(statement, 12); + NSString *httpDnsIPV6TTLExpried = httpDnsIPV6TTLExpried_char ? [NSString stringWithUTF8String:httpDnsIPV6TTLExpried_char] : nil; + + @try { + if([self isExist:httpDnsIPV4Channel]){ + [httpDnsIPV4Info setObject:httpDnsIPV4Channel forKey:kChannel]; + } + if([self isExist:httpDnsIPV4ClientIP]){ + [httpDnsIPV4Info setObject:httpDnsIPV4ClientIP forKey:kClientIP]; + } + if([self isExist:httpDnsIPV4IPs]){ + [httpDnsIPV4Info setObject:[httpDnsIPV4IPs componentsSeparatedByString:@","] forKey:kIP]; + } + if([self isExist:httpDnsIPV4TimeConsuming]){ + [httpDnsIPV4Info setObject:httpDnsIPV4TimeConsuming forKey:kDnsTimeConsuming]; + } + if([self isExist:httpDnsIPV4TTL]){ + [httpDnsIPV4Info setObject:httpDnsIPV4TTL forKey:kTTL]; + } + if([self isExist:httpDnsIPV4TTLExpried]){ + [httpDnsIPV4Info setObject:httpDnsIPV4TTLExpried forKey:kTTLExpired]; + } + + if([self isExist:httpDnsIPV6Channel]){ + [httpDnsIPV6Info setObject:httpDnsIPV6Channel forKey:kChannel]; + } + if([self isExist:httpDnsIPV6ClientIP]){ + [httpDnsIPV6Info setObject:httpDnsIPV6ClientIP forKey:kClientIP]; + } + if([self isExist:httpDnsIPV6IPs]){ + [httpDnsIPV6Info setObject:[httpDnsIPV6IPs componentsSeparatedByString:@","] forKey:kIP]; + } + if([self isExist:httpDnsIPV6TimeConsuming]){ + [httpDnsIPV6Info setObject:httpDnsIPV6TimeConsuming forKey:kDnsTimeConsuming]; + } + if([self isExist:httpDnsIPV6TTL]){ + [httpDnsIPV6Info setObject:httpDnsIPV6TTL forKey:kTTL]; + } + if([self isExist:httpDnsIPV6TTLExpried]){ + [httpDnsIPV6Info setObject:httpDnsIPV6TTLExpried forKey:kTTLExpired]; + } + + } @catch (NSException *exception) {} + [domainInfo setObject:httpDnsIPV4Info forKey:kMSDKHttpDnsCache_A]; + [domainInfo setObject:httpDnsIPV6Info forKey:kMSDKHttpDnsCache_4A]; + + [newResult setObject:domainInfo forKey:domain]; + } + NSLog(@"========newResult========%@", newResult); + } else { + NSLog(@"select operation is fail."); + } + + sqlite3_finalize(statement); + return newResult; +} + +- (BOOL)isExist: (NSString *)value { + if(value && ![value isEqual:@""]){ + return YES; + } + return NO; +} + +- (void)deleteDBData: (NSArray *)domains { + @try { + NSString *sql = [NSString stringWithFormat:@"DELETE FROM HttpDNSTable WHERE domain IN ('%@')", [domains componentsJoinedByString:@"','"]]; + if (sqlite3_exec(_db, [sql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { + NSLog(@"delete operation is ok."); + } else { + NSLog(@"Failed to delete data into database. error:%s", _error); + // 每次使用完毕清空 error 字符串,提供给下一次使用 + sqlite3_free(_error); + } + } @catch (NSException *exception) { + MSDKDNSLOG(@"Failed to delete data into database"); + } +} + +- (BOOL)close { + + if (!_db) { + return YES; + } + + int rc; + BOOL retry; + BOOL triedFinalizingOpenStatements = NO; + + do { + retry = NO; + rc = sqlite3_close(_db); + if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) { + if (!triedFinalizingOpenStatements) { + triedFinalizingOpenStatements = YES; + sqlite3_stmt *pStmt; + while ((pStmt = sqlite3_next_stmt(_db, nil)) !=0) { + NSLog(@"Closing leaked statement"); + sqlite3_finalize(pStmt); + retry = YES; + } + } + } + else if (SQLITE_OK != rc) { + NSLog(@"error closing!: %d", rc); + } + } + while (retry); + + _db = nil; + return YES; +} + +- (void)dealloc { + [self close]; +} + + +@end diff --git a/MSDKDns/WCDB/HTTPDNSORM+WCTTableCoding.h b/MSDKDns/WCDB/HTTPDNSORM+WCTTableCoding.h deleted file mode 100644 index ce48274..0000000 --- a/MSDKDns/WCDB/HTTPDNSORM+WCTTableCoding.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) Tencent. All rights reserved. - */ - -#if __cplusplus >= 201103L - #import - #import "HTTPDNSORM.h" - @interface HTTPDNSORM (WCTTableCoding) - - WCDB_PROPERTY(domain) - - WCDB_PROPERTY(httpDnsIPV4Channel) - WCDB_PROPERTY(httpDnsIPV4ClientIP) - WCDB_PROPERTY(httpDnsIPV4IPs) - WCDB_PROPERTY(httpDnsIPV4TimeConsuming) - WCDB_PROPERTY(httpDnsIPV4TTL) - WCDB_PROPERTY(httpDnsIPV4TTLExpried) - - WCDB_PROPERTY(httpDnsIPV6Channel) - WCDB_PROPERTY(httpDnsIPV6ClientIP) - WCDB_PROPERTY(httpDnsIPV6IPs) - WCDB_PROPERTY(httpDnsIPV6TimeConsuming) - WCDB_PROPERTY(httpDnsIPV6TTL) - WCDB_PROPERTY(httpDnsIPV6TTLExpried) - - @end - -#endif - diff --git a/MSDKDns/WCDB/HTTPDNSORM.h b/MSDKDns/WCDB/HTTPDNSORM.h deleted file mode 100644 index 27a811e..0000000 --- a/MSDKDns/WCDB/HTTPDNSORM.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Tencent. All rights reserved. - */ - -#import - -@interface HTTPDNSORM : NSObject - -@property(retain) NSString *domain; - -@property(retain) NSString *httpDnsIPV4Channel; -@property(retain) NSString *httpDnsIPV4ClientIP; -@property(retain) NSArray *httpDnsIPV4IPs; -@property(retain) NSString *httpDnsIPV4TimeConsuming; -@property(retain) NSString *httpDnsIPV4TTL; -@property(retain) NSString *httpDnsIPV4TTLExpried; - -@property(retain) NSString *httpDnsIPV6Channel; -@property(retain) NSString *httpDnsIPV6ClientIP; -@property(retain) NSArray *httpDnsIPV6IPs; -@property(retain) NSString *httpDnsIPV6TimeConsuming; -@property(retain) NSString *httpDnsIPV6TTL; -@property(retain) NSString *httpDnsIPV6TTLExpried; - - -@end diff --git a/MSDKDns/WCDB/HTTPDNSORM.m b/MSDKDns/WCDB/HTTPDNSORM.m deleted file mode 100644 index 88935f4..0000000 --- a/MSDKDns/WCDB/HTTPDNSORM.m +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) Tencent. All rights reserved. - */ - -#if __cplusplus >= 201103L - - #import - #import "HTTPDNSORM.h" - #import "HTTPDNSORM+WCTTableCoding.h" - - - @implementation HTTPDNSORM - - WCDB_IMPLEMENTATION(HTTPDNSORM) - - WCDB_SYNTHESIZE(HTTPDNSORM, domain) - - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4Channel) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4ClientIP) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4IPs) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4TimeConsuming) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4TTL) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV4TTLExpried) - - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6Channel) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6ClientIP) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6IPs) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6TimeConsuming) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6TTL) - WCDB_SYNTHESIZE(HTTPDNSORM, httpDnsIPV6TTLExpried) - - WCDB_PRIMARY(HTTPDNSORM, domain) - - WCDB_INDEX(HTTPDNSORM, "_index", domain) - - @end - -#endif - diff --git a/MSDKDns/WCDB/MSDKDnsDB.m b/MSDKDns/WCDB/MSDKDnsDB.m deleted file mode 100644 index 7d5427b..0000000 --- a/MSDKDns/WCDB/MSDKDnsDB.m +++ /dev/null @@ -1,203 +0,0 @@ -// Created by eric hu on 2022/8/23. -// Copyright © 2022 Tencent. All rights reserved. -// - -#import "MSDKDnsDB.h" -#import "MSDKDnsLog.h" -#import "MSDKDnsPrivate.h" - -#if __cplusplus >= 201103L - #import - #import "HTTPDNSORM.h" - #import "HTTPDNSORM+WCTTableCoding.h" -#endif - -@interface MSDKDnsDB () - -@property (strong, nonatomic, readwrite) id database; -@property (strong, nonatomic, readwrite) NSString *tableName; - -@end - -@implementation MSDKDnsDB - -#pragma mark - init - -static MSDKDnsDB * _sharedInstance = nil; -+ (instancetype)shareInstance { - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - _sharedInstance = [[MSDKDnsDB alloc] init]; - }); - return _sharedInstance; -} - -- (instancetype) init { - if (self = [super init]) { - _tableName = @"HttpDNSTable"; - // 获取WCTDatabase类 - Class databaseClass = NSClassFromString(@"WCTDatabase"); - // 获取HTTPDNSORM类 - Class HTTPDNSORMClass = NSClassFromString(@"HTTPDNSORM"); - if (databaseClass == 0x0) { - MSDKDNSLOG(@"WCTDatabase framework is not imported"); - } else if (HTTPDNSORMClass == 0x0) { - MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); - } else { - @try { - NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); - NSString *baseDirectory = [documentPaths objectAtIndex:0]; - NSString *path = [baseDirectory stringByAppendingPathComponent:_tableName]; - - _database = [[databaseClass alloc] initWithPath:path]; - // 获取方法编号 - SEL createTableAndIndexesOfNameSEL = NSSelectorFromString(@"createTableAndIndexesOfName:withClass:"); - // 调用WCTDatabase类的方法 - if (_database && [_database respondsToSelector:createTableAndIndexesOfNameSEL] ) { - IMP imp = [_database methodForSelector:createTableAndIndexesOfNameSEL]; - using connectDatabase = BOOL (*)(id, SEL, NSString *, Class); - BOOL success = ((connectDatabase) imp)(_database, createTableAndIndexesOfNameSEL, _tableName, HTTPDNSORMClass.class); - if (!success) { - MSDKDNSLOG(@"database connection failed"); - } - } - } @catch (NSException *exception) { - MSDKDNSLOG(@"database connection failed"); - } - } - } - return self; -} - -- (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *)domain { - - NSDictionary * hresultDict_A = domainInfo[kMSDKHttpDnsCache_A]; - NSDictionary * hresultDict_4A = domainInfo[kMSDKHttpDnsCache_4A]; - - // 获取HTTPDNSORM类 - Class HTTPDNSORMClass = NSClassFromString(@"HTTPDNSORM"); - - if (HTTPDNSORMClass == 0x0) { - MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); - return; - } - - id httpDnsData = [[HTTPDNSORMClass alloc] init]; - - [httpDnsData setValue:[domain copy] forKey:@"domain"]; - - if (hresultDict_A){ - [httpDnsData setValue:hresultDict_A[kChannel] forKey:@"httpDnsIPV4Channel"]; - [httpDnsData setValue:hresultDict_A[kClientIP] forKey:@"httpDnsIPV4ClientIP"]; - [httpDnsData setValue:hresultDict_A[kIP] forKey:@"httpDnsIPV4IPs"]; - [httpDnsData setValue:hresultDict_A[kDnsTimeConsuming] forKey:@"httpDnsIPV4TimeConsuming"]; - [httpDnsData setValue:hresultDict_A[kTTL] forKey:@"httpDnsIPV4TTL"]; - [httpDnsData setValue:hresultDict_A[kTTLExpired] forKey:@"httpDnsIPV4TTLExpried"]; - } - - if (hresultDict_4A) { - [httpDnsData setValue:hresultDict_4A[kChannel] forKey:@"httpDnsIPV6Channel"]; - [httpDnsData setValue:hresultDict_4A[kClientIP] forKey:@"httpDnsIPV6ClientIP"]; - [httpDnsData setValue:hresultDict_4A[kIP] forKey:@"httpDnsIPV6IPs"]; - [httpDnsData setValue:hresultDict_4A[kDnsTimeConsuming] forKey:@"httpDnsIPV6TimeConsuming"]; - [httpDnsData setValue:hresultDict_4A[kTTL] forKey:@"httpDnsIPV6TTL"]; - [httpDnsData setValue:hresultDict_4A[kTTLExpired] forKey:@"httpDnsIPV6TTLExpried"]; - } - // 获取方法编号 - SEL insertOrReplaceObjectSEL = NSSelectorFromString(@"insertOrReplaceObject:into:"); - - if (_database && [_database respondsToSelector:insertOrReplaceObjectSEL] ) { - @try { - IMP imp = [_database methodForSelector:insertOrReplaceObjectSEL]; - using insertData = BOOL (*)(id, SEL, id, NSString *); - BOOL success = ((insertData) imp)(_database, insertOrReplaceObjectSEL, httpDnsData, _tableName); - if (!success) { - MSDKDNSLOG(@"Failed to insert data into database"); - } - } @catch (NSException *exception) { - MSDKDNSLOG(@"Failed to insert data into database"); - } - } -} - -- (NSDictionary *)getDataFromDB { - // 获取HTTPDNSORM类 - Class HTTPDNSORMClass = NSClassFromString(@"HTTPDNSORM"); - SEL getAllObjectsOfClassSEL = NSSelectorFromString(@"getAllObjectsOfClass:fromTable:"); - - NSMutableDictionary *newResult = [[NSMutableDictionary alloc] init]; - - if (HTTPDNSORMClass == 0x0) { - MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); - return newResult; - } - - if (_database && [_database respondsToSelector:getAllObjectsOfClassSEL]) { - @try { - IMP imp = [_database methodForSelector:getAllObjectsOfClassSEL]; - using GetAllData = NSArray* (*)(id, SEL, Class, NSString *); - NSArray *result = ((GetAllData) imp)(_database, getAllObjectsOfClassSEL, HTTPDNSORMClass.class, _tableName); - if (!result) { - MSDKDNSLOG(@"Failed to insert data into database"); - } - for (id item in result) { - NSMutableDictionary *domainInfo = [[NSMutableDictionary alloc] init]; - NSMutableDictionary *httpDnsIPV4Info = [[NSMutableDictionary alloc] init]; - NSMutableDictionary *httpDnsIPV6Info = [[NSMutableDictionary alloc] init]; - - @try { - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4Channel"] forKey:kChannel]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4ClientIP"] forKey:kClientIP]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4IPs"] forKey:kIP]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TimeConsuming"] forKey:kDnsTimeConsuming]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TTL"] forKey:kTTL]; - [httpDnsIPV4Info setObject:[item valueForKey:@"httpDnsIPV4TTLExpried"] forKey:kTTLExpired]; - - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6Channel"] forKey:kChannel]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6ClientIP"] forKey:kClientIP]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6IPs"] forKey:kIP]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TimeConsuming"] forKey:kDnsTimeConsuming]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TTL"] forKey:kTTL]; - [httpDnsIPV6Info setObject:[item valueForKey:@"httpDnsIPV6TTLExpried"] forKey:kTTLExpired]; - } @catch (NSException *exception) {} - [domainInfo setObject:httpDnsIPV4Info forKey:kMSDKHttpDnsCache_A]; - [domainInfo setObject:httpDnsIPV6Info forKey:kMSDKHttpDnsCache_4A]; - - [newResult setObject:domainInfo forKey:[item valueForKey:@"domain"]]; - } - } @catch (NSException *exception) { - MSDKDNSLOG(@"Failed to insert data into database"); - } - } - return newResult; -} - -- (void)deleteDBData: (NSArray *)domains { - // 获取HTTPDNSORM类 - Class HTTPDNSORMClass = NSClassFromString(@"HTTPDNSORM"); - SEL deleteObjectsFromTableSEL = NSSelectorFromString(@"deleteObjectsFromTable:where:"); - - if (HTTPDNSORMClass == 0x0) { - MSDKDNSLOG(@"MSDKDns does not support persistent cache, we recommend using MSDKDns_C11"); - return; - } - - if (_database && [_database respondsToSelector:deleteObjectsFromTableSEL]) { - @try { -#if __cplusplus >= 201103L - IMP imp = [_database methodForSelector:deleteObjectsFromTableSEL]; - using deleteData = BOOL (*)(id, SEL, NSString *, WCTExpr); - // 删除表数据 - BOOL success = ((deleteData) imp)(_database, deleteObjectsFromTableSEL, _tableName, HTTPDNSORM.domain.in(domains)); - if (!success) { - MSDKDNSLOG(@"Failed to delete data into database"); - } -#endif - } @catch (NSException *exception) { - MSDKDNSLOG(@"Failed to delete data into database"); - } - } -} - - -@end From dddfdae0ba6db12d8b29bcfbc20d7a9997098dab Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Fri, 21 Oct 2022 11:40:23 +0800 Subject: [PATCH 03/15] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8D=95=E8=8E=B7=E5=92=8C=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/DB/MSDKDnsDB.m | 351 +++++++++++++++++++++-------------------- 1 file changed, 177 insertions(+), 174 deletions(-) diff --git a/MSDKDns/DB/MSDKDnsDB.m b/MSDKDns/DB/MSDKDnsDB.m index 9eda1f6..ae5fc13 100644 --- a/MSDKDns/DB/MSDKDnsDB.m +++ b/MSDKDns/DB/MSDKDnsDB.m @@ -38,102 +38,102 @@ - (instancetype) init { // 设置数据库文件路径 NSString *fileName = [baseDirectory stringByAppendingPathComponent:@"httpdns.sqlite"]; - NSLog(@"fileName === %@", fileName); //打开数据库文件(如果数据库文件不存在,那么该函数会自动创建数据库文件) int result = sqlite3_open([fileName UTF8String], &_db); if (result == SQLITE_OK) {//打开成功 - NSLog(@"成功打开数据库"); - // NSString *createSql = @"create table if not exists myTable(id integer primary key autoincrement, name text UNIQUE, age integer, address text)"; NSString *createSql = @"create table if not exists HttpDNSTable(id integer primary key autoincrement, domain text UNIQUE, httpDnsIPV4Channel text, httpDnsIPV4ClientIP text, httpDnsIPV4IPs text, httpDnsIPV4TimeConsuming text, httpDnsIPV4TTL text, httpDnsIPV4TTLExpried text, httpDnsIPV6Channel text, httpDnsIPV6ClientIP text, httpDnsIPV6IPs text, httpDnsIPV6TimeConsuming text, httpDnsIPV6TTL text, httpDnsIPV6TTLExpried text)"; if (sqlite3_exec(_db, [createSql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { - NSLog(@"create table is ok."); + NSLog(@"Successfully create table into database."); } else { - NSLog(@"error: %s", _error); + NSLog(@"Failed to create table into database, error: %s", _error); // 每次使用完毕清空 error 字符串,提供给下一次使用 sqlite3_free(_error); } }else{ - NSLog(@"打开数据库失败"); + NSLog(@"Failed to open Database"); } } @catch (NSException *exception) { - MSDKDNSLOG(@"database connection failed"); + MSDKDNSLOG(@"Failed to connect Database"); } } return self; } - (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *)domain { - - NSDictionary * hresultDict_A = domainInfo[kMSDKHttpDnsCache_A]; - NSDictionary * hresultDict_4A = domainInfo[kMSDKHttpDnsCache_4A]; - - NSString *hresultDict_A_kChannel = @""; - NSString *hresultDict_A_kClientIP = @""; - NSString *hresultDict_A_kIP = @""; - NSString *hresultDict_A_kDnsTimeConsuming = @""; - NSString *hresultDict_A_kTTL = @""; - NSString *hresultDict_A_kTTLExpired = @""; - NSString *hresultDict_4A_kChannel = @""; - NSString *hresultDict_4A_kClientIP = @""; - NSString *hresultDict_4A_kIP = @""; - NSString *hresultDict_4A_kDnsTimeConsuming = @""; - NSString *hresultDict_4A_kTTL = @""; - NSString *hresultDict_4A_kTTLExpired = @""; - - if(hresultDict_A){ - if(hresultDict_A[kChannel]){ - hresultDict_A_kChannel = hresultDict_A[kChannel]; - } - if(hresultDict_A[kClientIP]){ - hresultDict_A_kClientIP = hresultDict_A[kClientIP]; - } - if(hresultDict_A[kIP]){ - hresultDict_A_kIP = [hresultDict_A[kIP] componentsJoinedByString:@","]; - } - if(hresultDict_A[kDnsTimeConsuming]){ - hresultDict_A_kDnsTimeConsuming = hresultDict_A[kDnsTimeConsuming]; - } - if(hresultDict_A[kTTL]){ - hresultDict_A_kTTL = hresultDict_A[kTTL]; - } - if(hresultDict_A[kTTLExpired]){ - hresultDict_A_kTTLExpired = hresultDict_A[kTTLExpired]; - } - } - - if(hresultDict_4A){ - if(hresultDict_4A[kChannel]){ - hresultDict_4A_kChannel = hresultDict_4A[kChannel]; - } - if(hresultDict_4A[kClientIP]){ - hresultDict_4A_kClientIP = hresultDict_4A[kClientIP]; - } - if(hresultDict_4A[kIP]){ - hresultDict_4A_kIP = [hresultDict_4A[kIP] componentsJoinedByString:@","]; - } - if(hresultDict_4A[kDnsTimeConsuming]){ - hresultDict_4A_kDnsTimeConsuming = hresultDict_4A[kDnsTimeConsuming]; - } - if(hresultDict_4A[kTTL]){ - hresultDict_4A_kTTL = hresultDict_4A[kTTL]; + + @try { + NSDictionary * hresultDict_A = domainInfo[kMSDKHttpDnsCache_A]; + NSDictionary * hresultDict_4A = domainInfo[kMSDKHttpDnsCache_4A]; + + NSString *hresultDict_A_kChannel = @""; + NSString *hresultDict_A_kClientIP = @""; + NSString *hresultDict_A_kIP = @""; + NSString *hresultDict_A_kDnsTimeConsuming = @""; + NSString *hresultDict_A_kTTL = @""; + NSString *hresultDict_A_kTTLExpired = @""; + NSString *hresultDict_4A_kChannel = @""; + NSString *hresultDict_4A_kClientIP = @""; + NSString *hresultDict_4A_kIP = @""; + NSString *hresultDict_4A_kDnsTimeConsuming = @""; + NSString *hresultDict_4A_kTTL = @""; + NSString *hresultDict_4A_kTTLExpired = @""; + + if(hresultDict_A){ + if(hresultDict_A[kChannel]){ + hresultDict_A_kChannel = hresultDict_A[kChannel]; + } + if(hresultDict_A[kClientIP]){ + hresultDict_A_kClientIP = hresultDict_A[kClientIP]; + } + if(hresultDict_A[kIP]){ + hresultDict_A_kIP = [hresultDict_A[kIP] componentsJoinedByString:@","]; + } + if(hresultDict_A[kDnsTimeConsuming]){ + hresultDict_A_kDnsTimeConsuming = hresultDict_A[kDnsTimeConsuming]; + } + if(hresultDict_A[kTTL]){ + hresultDict_A_kTTL = hresultDict_A[kTTL]; + } + if(hresultDict_A[kTTLExpired]){ + hresultDict_A_kTTLExpired = hresultDict_A[kTTLExpired]; + } } - if(hresultDict_4A[kTTLExpired]){ - hresultDict_4A_kTTLExpired = hresultDict_4A[kTTLExpired]; + + if(hresultDict_4A){ + if(hresultDict_4A[kChannel]){ + hresultDict_4A_kChannel = hresultDict_4A[kChannel]; + } + if(hresultDict_4A[kClientIP]){ + hresultDict_4A_kClientIP = hresultDict_4A[kClientIP]; + } + if(hresultDict_4A[kIP]){ + hresultDict_4A_kIP = [hresultDict_4A[kIP] componentsJoinedByString:@","]; + } + if(hresultDict_4A[kDnsTimeConsuming]){ + hresultDict_4A_kDnsTimeConsuming = hresultDict_4A[kDnsTimeConsuming]; + } + if(hresultDict_4A[kTTL]){ + hresultDict_4A_kTTL = hresultDict_4A[kTTL]; + } + if(hresultDict_4A[kTTLExpired]){ + hresultDict_4A_kTTLExpired = hresultDict_4A[kTTLExpired]; + } } - } - - // NSString *createSql = @"create table if not exists myTable(id integer primary key autoincrement, name text UNIQUE, age integer, address text)"; - NSString *insertSql = [NSString stringWithFormat:@"INSERT OR REPLACE into HttpDNSTable(domain, httpDnsIPV4Channel, httpDnsIPV4ClientIP, httpDnsIPV4IPs, httpDnsIPV4TimeConsuming, httpDnsIPV4TTL, httpDnsIPV4TTLExpried, httpDnsIPV6ClientIP, httpDnsIPV6IPs, httpDnsIPV6TimeConsuming, httpDnsIPV6TTL, httpDnsIPV6TTLExpried) values('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@')",[domain copy],hresultDict_A_kChannel,hresultDict_A_kClientIP,hresultDict_A_kIP,hresultDict_A_kDnsTimeConsuming,hresultDict_A_kTTL,hresultDict_A_kTTLExpired,hresultDict_4A_kClientIP,hresultDict_4A_kIP,hresultDict_4A_kDnsTimeConsuming,hresultDict_4A_kTTL,hresultDict_4A_kTTLExpired]; - - if (sqlite3_exec(_db, [insertSql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { - NSLog(@"insert operation is ok."); - } else { - NSLog(@"error: %s", _error); - // 每次使用完毕清空 error 字符串,提供给下一次使用 - sqlite3_free(_error); + NSString *insertSql = [NSString stringWithFormat:@"INSERT OR REPLACE into HttpDNSTable(domain, httpDnsIPV4Channel, httpDnsIPV4ClientIP, httpDnsIPV4IPs, httpDnsIPV4TimeConsuming, httpDnsIPV4TTL, httpDnsIPV4TTLExpried, httpDnsIPV6ClientIP, httpDnsIPV6IPs, httpDnsIPV6TimeConsuming, httpDnsIPV6TTL, httpDnsIPV6TTLExpried) values('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@')",[domain copy],hresultDict_A_kChannel,hresultDict_A_kClientIP,hresultDict_A_kIP,hresultDict_A_kDnsTimeConsuming,hresultDict_A_kTTL,hresultDict_A_kTTLExpired,hresultDict_4A_kClientIP,hresultDict_4A_kIP,hresultDict_4A_kDnsTimeConsuming,hresultDict_4A_kTTL,hresultDict_4A_kTTLExpired]; + + if (sqlite3_exec(_db, [insertSql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { + NSLog(@"Successfully insert data into database, domain = %@, domainInfo = %@", domain, domainInfo); + } else { + NSLog(@"Failed to insert data into database, error: %s", _error); + + // 每次使用完毕清空 error 字符串,提供给下一次使用 + sqlite3_free(_error); + } + } @catch (NSException *exception) { + MSDKDNSLOG(@"Failed to insert data into database, error: %@", exception); } } @@ -146,117 +146,115 @@ - (NSDictionary *)getDataFromDB { // NSString *selectSql = @"select id, name, age, address from myTable"; NSString *selectSql = @"select domain, httpDnsIPV4Channel, httpDnsIPV4ClientIP, httpDnsIPV4IPs, httpDnsIPV4TimeConsuming, httpDnsIPV4TTL, httpDnsIPV4TTLExpried, httpDnsIPV6Channel, httpDnsIPV6ClientIP, httpDnsIPV6IPs, httpDnsIPV6TimeConsuming, httpDnsIPV6TTL, httpDnsIPV6TTLExpried from HttpDNSTable"; - if (sqlite3_prepare_v2(_db, [selectSql UTF8String], -1, &statement, nil) == SQLITE_OK) { - - while(sqlite3_step(statement) == SQLITE_ROW) { - NSMutableDictionary *domainInfo = [[NSMutableDictionary alloc] init]; - NSMutableDictionary *httpDnsIPV4Info = [[NSMutableDictionary alloc] init]; - NSMutableDictionary *httpDnsIPV6Info = [[NSMutableDictionary alloc] init]; - - NSString *domain = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]; - - char *httpDnsIPV4Channel_char = (char *)sqlite3_column_text(statement, 1); - NSString *httpDnsIPV4Channel = httpDnsIPV4Channel_char ? [NSString stringWithUTF8String:httpDnsIPV4Channel_char] : nil; - - char *httpDnsIPV4ClientIP_char = (char *)sqlite3_column_text(statement, 2); - NSString *httpDnsIPV4ClientIP = httpDnsIPV4ClientIP_char ? [NSString stringWithUTF8String:httpDnsIPV4ClientIP_char] : nil; - - char *httpDnsIPV4IPs_char = (char *)sqlite3_column_text(statement, 3); - NSString *httpDnsIPV4IPs = httpDnsIPV4IPs_char ? [NSString stringWithUTF8String:httpDnsIPV4IPs_char] : nil; - - char *httpDnsIPV4TimeConsuming_char = (char *)sqlite3_column_text(statement, 4); - NSString *httpDnsIPV4TimeConsuming = httpDnsIPV4TimeConsuming_char ? [NSString stringWithUTF8String:httpDnsIPV4TimeConsuming_char] : nil; - - char *httpDnsIPV4TTL_char = (char *)sqlite3_column_text(statement, 5); - NSString *httpDnsIPV4TTL = httpDnsIPV4TTL_char ? [NSString stringWithUTF8String:httpDnsIPV4TTL_char] : nil; - - char *httpDnsIPV4TTLExpried_char = (char *)sqlite3_column_text(statement, 6); - NSString *httpDnsIPV4TTLExpried = httpDnsIPV4TTLExpried_char ? [NSString stringWithUTF8String:httpDnsIPV4TTLExpried_char] : nil; - - char *httpDnsIPV6Channel_char = (char *)sqlite3_column_text(statement, 7); - NSString *httpDnsIPV6Channel = httpDnsIPV6Channel_char ? [NSString stringWithUTF8String:httpDnsIPV6Channel_char] : nil; - - char *httpDnsIPV6ClientIP_char = (char *)sqlite3_column_text(statement, 8); - NSString *httpDnsIPV6ClientIP = httpDnsIPV6ClientIP_char ? [NSString stringWithUTF8String:httpDnsIPV6ClientIP_char] : nil; - - char *httpDnsIPV6IPs_char = (char *)sqlite3_column_text(statement, 9); - NSString *httpDnsIPV6IPs = httpDnsIPV6IPs_char ? [NSString stringWithUTF8String:httpDnsIPV6IPs_char] : nil; - - char *httpDnsIPV6TimeConsuming_char = (char *)sqlite3_column_text(statement, 10); - NSString *httpDnsIPV6TimeConsuming = httpDnsIPV6TimeConsuming_char ? [NSString stringWithUTF8String:httpDnsIPV6TimeConsuming_char] : nil; - - char *httpDnsIPV6TTL_char = (char *)sqlite3_column_text(statement, 11); - NSString *httpDnsIPV6TTL = httpDnsIPV6TTL_char ? [NSString stringWithUTF8String:httpDnsIPV6TTL_char] : nil; - - char *httpDnsIPV6TTLExpried_char = (char *)sqlite3_column_text(statement, 12); - NSString *httpDnsIPV6TTLExpried = httpDnsIPV6TTLExpried_char ? [NSString stringWithUTF8String:httpDnsIPV6TTLExpried_char] : nil; + @try { + if (sqlite3_prepare_v2(_db, [selectSql UTF8String], -1, &statement, nil) == SQLITE_OK) { - @try { - if([self isExist:httpDnsIPV4Channel]){ - [httpDnsIPV4Info setObject:httpDnsIPV4Channel forKey:kChannel]; - } - if([self isExist:httpDnsIPV4ClientIP]){ - [httpDnsIPV4Info setObject:httpDnsIPV4ClientIP forKey:kClientIP]; - } - if([self isExist:httpDnsIPV4IPs]){ - [httpDnsIPV4Info setObject:[httpDnsIPV4IPs componentsSeparatedByString:@","] forKey:kIP]; - } - if([self isExist:httpDnsIPV4TimeConsuming]){ - [httpDnsIPV4Info setObject:httpDnsIPV4TimeConsuming forKey:kDnsTimeConsuming]; - } - if([self isExist:httpDnsIPV4TTL]){ - [httpDnsIPV4Info setObject:httpDnsIPV4TTL forKey:kTTL]; - } - if([self isExist:httpDnsIPV4TTLExpried]){ - [httpDnsIPV4Info setObject:httpDnsIPV4TTLExpried forKey:kTTLExpired]; - } + while(sqlite3_step(statement) == SQLITE_ROW) { + NSMutableDictionary *domainInfo = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *httpDnsIPV4Info = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *httpDnsIPV6Info = [[NSMutableDictionary alloc] init]; - if([self isExist:httpDnsIPV6Channel]){ - [httpDnsIPV6Info setObject:httpDnsIPV6Channel forKey:kChannel]; - } - if([self isExist:httpDnsIPV6ClientIP]){ - [httpDnsIPV6Info setObject:httpDnsIPV6ClientIP forKey:kClientIP]; - } - if([self isExist:httpDnsIPV6IPs]){ - [httpDnsIPV6Info setObject:[httpDnsIPV6IPs componentsSeparatedByString:@","] forKey:kIP]; - } - if([self isExist:httpDnsIPV6TimeConsuming]){ - [httpDnsIPV6Info setObject:httpDnsIPV6TimeConsuming forKey:kDnsTimeConsuming]; - } - if([self isExist:httpDnsIPV6TTL]){ - [httpDnsIPV6Info setObject:httpDnsIPV6TTL forKey:kTTL]; - } - if([self isExist:httpDnsIPV6TTLExpried]){ - [httpDnsIPV6Info setObject:httpDnsIPV6TTLExpried forKey:kTTLExpired]; - } + NSString *domain = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]; - } @catch (NSException *exception) {} - [domainInfo setObject:httpDnsIPV4Info forKey:kMSDKHttpDnsCache_A]; - [domainInfo setObject:httpDnsIPV6Info forKey:kMSDKHttpDnsCache_4A]; - - [newResult setObject:domainInfo forKey:domain]; + char *httpDnsIPV4Channel_char = (char *)sqlite3_column_text(statement, 1); + NSString *httpDnsIPV4Channel = httpDnsIPV4Channel_char ? [NSString stringWithUTF8String:httpDnsIPV4Channel_char] : nil; + + char *httpDnsIPV4ClientIP_char = (char *)sqlite3_column_text(statement, 2); + NSString *httpDnsIPV4ClientIP = httpDnsIPV4ClientIP_char ? [NSString stringWithUTF8String:httpDnsIPV4ClientIP_char] : nil; + + char *httpDnsIPV4IPs_char = (char *)sqlite3_column_text(statement, 3); + NSString *httpDnsIPV4IPs = httpDnsIPV4IPs_char ? [NSString stringWithUTF8String:httpDnsIPV4IPs_char] : nil; + + char *httpDnsIPV4TimeConsuming_char = (char *)sqlite3_column_text(statement, 4); + NSString *httpDnsIPV4TimeConsuming = httpDnsIPV4TimeConsuming_char ? [NSString stringWithUTF8String:httpDnsIPV4TimeConsuming_char] : nil; + + char *httpDnsIPV4TTL_char = (char *)sqlite3_column_text(statement, 5); + NSString *httpDnsIPV4TTL = httpDnsIPV4TTL_char ? [NSString stringWithUTF8String:httpDnsIPV4TTL_char] : nil; + + char *httpDnsIPV4TTLExpried_char = (char *)sqlite3_column_text(statement, 6); + NSString *httpDnsIPV4TTLExpried = httpDnsIPV4TTLExpried_char ? [NSString stringWithUTF8String:httpDnsIPV4TTLExpried_char] : nil; + + char *httpDnsIPV6Channel_char = (char *)sqlite3_column_text(statement, 7); + NSString *httpDnsIPV6Channel = httpDnsIPV6Channel_char ? [NSString stringWithUTF8String:httpDnsIPV6Channel_char] : nil; + + char *httpDnsIPV6ClientIP_char = (char *)sqlite3_column_text(statement, 8); + NSString *httpDnsIPV6ClientIP = httpDnsIPV6ClientIP_char ? [NSString stringWithUTF8String:httpDnsIPV6ClientIP_char] : nil; + + char *httpDnsIPV6IPs_char = (char *)sqlite3_column_text(statement, 9); + NSString *httpDnsIPV6IPs = httpDnsIPV6IPs_char ? [NSString stringWithUTF8String:httpDnsIPV6IPs_char] : nil; + + char *httpDnsIPV6TimeConsuming_char = (char *)sqlite3_column_text(statement, 10); + NSString *httpDnsIPV6TimeConsuming = httpDnsIPV6TimeConsuming_char ? [NSString stringWithUTF8String:httpDnsIPV6TimeConsuming_char] : nil; + + char *httpDnsIPV6TTL_char = (char *)sqlite3_column_text(statement, 11); + NSString *httpDnsIPV6TTL = httpDnsIPV6TTL_char ? [NSString stringWithUTF8String:httpDnsIPV6TTL_char] : nil; + + char *httpDnsIPV6TTLExpried_char = (char *)sqlite3_column_text(statement, 12); + NSString *httpDnsIPV6TTLExpried = httpDnsIPV6TTLExpried_char ? [NSString stringWithUTF8String:httpDnsIPV6TTLExpried_char] : nil; + + @try { + if([self isExist:httpDnsIPV4Channel]){ + [httpDnsIPV4Info setObject:httpDnsIPV4Channel forKey:kChannel]; + } + if([self isExist:httpDnsIPV4ClientIP]){ + [httpDnsIPV4Info setObject:httpDnsIPV4ClientIP forKey:kClientIP]; + } + if([self isExist:httpDnsIPV4IPs]){ + [httpDnsIPV4Info setObject:[httpDnsIPV4IPs componentsSeparatedByString:@","] forKey:kIP]; + } + if([self isExist:httpDnsIPV4TimeConsuming]){ + [httpDnsIPV4Info setObject:httpDnsIPV4TimeConsuming forKey:kDnsTimeConsuming]; + } + if([self isExist:httpDnsIPV4TTL]){ + [httpDnsIPV4Info setObject:httpDnsIPV4TTL forKey:kTTL]; + } + if([self isExist:httpDnsIPV4TTLExpried]){ + [httpDnsIPV4Info setObject:httpDnsIPV4TTLExpried forKey:kTTLExpired]; + } + + if([self isExist:httpDnsIPV6Channel]){ + [httpDnsIPV6Info setObject:httpDnsIPV6Channel forKey:kChannel]; + } + if([self isExist:httpDnsIPV6ClientIP]){ + [httpDnsIPV6Info setObject:httpDnsIPV6ClientIP forKey:kClientIP]; + } + if([self isExist:httpDnsIPV6IPs]){ + [httpDnsIPV6Info setObject:[httpDnsIPV6IPs componentsSeparatedByString:@","] forKey:kIP]; + } + if([self isExist:httpDnsIPV6TimeConsuming]){ + [httpDnsIPV6Info setObject:httpDnsIPV6TimeConsuming forKey:kDnsTimeConsuming]; + } + if([self isExist:httpDnsIPV6TTL]){ + [httpDnsIPV6Info setObject:httpDnsIPV6TTL forKey:kTTL]; + } + if([self isExist:httpDnsIPV6TTLExpried]){ + [httpDnsIPV6Info setObject:httpDnsIPV6TTLExpried forKey:kTTLExpired]; + } + + } @catch (NSException *exception) {} + [domainInfo setObject:httpDnsIPV4Info forKey:kMSDKHttpDnsCache_A]; + [domainInfo setObject:httpDnsIPV6Info forKey:kMSDKHttpDnsCache_4A]; + + [newResult setObject:domainInfo forKey:domain]; + } + NSLog(@"Successfully select data from database, result = %@",newResult); + } else { + NSLog(@"Failed to select data from database, error: %s", _error); } - NSLog(@"========newResult========%@", newResult); - } else { - NSLog(@"select operation is fail."); + + } @catch (NSException *exception) { + MSDKDNSLOG(@"Failed to select data from database, error: %@", exception); } sqlite3_finalize(statement); return newResult; } -- (BOOL)isExist: (NSString *)value { - if(value && ![value isEqual:@""]){ - return YES; - } - return NO; -} - - (void)deleteDBData: (NSArray *)domains { @try { NSString *sql = [NSString stringWithFormat:@"DELETE FROM HttpDNSTable WHERE domain IN ('%@')", [domains componentsJoinedByString:@"','"]]; if (sqlite3_exec(_db, [sql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { - NSLog(@"delete operation is ok."); + NSLog(@"Successfully delete data into database. domains = %@", domains); } else { NSLog(@"Failed to delete data into database. error:%s", _error); // 每次使用完毕清空 error 字符串,提供给下一次使用 @@ -267,16 +265,22 @@ - (void)deleteDBData: (NSArray *)domains { } } +// 判断数据是否存在并且不为空 +- (BOOL)isExist: (NSString *)value { + if(value && ![value isEqual:@""]){ + return YES; + } + return NO; +} + +// 关闭数据库 - (BOOL)close { - if (!_db) { return YES; } - int rc; BOOL retry; BOOL triedFinalizingOpenStatements = NO; - do { retry = NO; rc = sqlite3_close(_db); @@ -296,7 +300,6 @@ - (BOOL)close { } } while (retry); - _db = nil; return YES; } From 6e24db1bcc82cad40e5e6924da45bba21e9f0b78 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Mon, 24 Oct 2022 14:10:54 +0800 Subject: [PATCH 04/15] =?UTF-8?q?feat:=E6=9B=BF=E6=8D=A2=E4=B8=BA=E5=86=85?= =?UTF-8?q?=E9=83=A8=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/DB/MSDKDnsDB.m | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/MSDKDns/DB/MSDKDnsDB.m b/MSDKDns/DB/MSDKDnsDB.m index ae5fc13..0044dcd 100644 --- a/MSDKDns/DB/MSDKDnsDB.m +++ b/MSDKDns/DB/MSDKDnsDB.m @@ -44,15 +44,15 @@ - (instancetype) init { NSString *createSql = @"create table if not exists HttpDNSTable(id integer primary key autoincrement, domain text UNIQUE, httpDnsIPV4Channel text, httpDnsIPV4ClientIP text, httpDnsIPV4IPs text, httpDnsIPV4TimeConsuming text, httpDnsIPV4TTL text, httpDnsIPV4TTLExpried text, httpDnsIPV6Channel text, httpDnsIPV6ClientIP text, httpDnsIPV6IPs text, httpDnsIPV6TimeConsuming text, httpDnsIPV6TTL text, httpDnsIPV6TTLExpried text)"; if (sqlite3_exec(_db, [createSql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { - NSLog(@"Successfully create table into database."); + MSDKDNSLOG(@"Successfully create table into database."); } else { - NSLog(@"Failed to create table into database, error: %s", _error); + MSDKDNSLOG(@"Failed to create table into database, error: %s", _error); // 每次使用完毕清空 error 字符串,提供给下一次使用 sqlite3_free(_error); } }else{ - NSLog(@"Failed to open Database"); + MSDKDNSLOG(@"Failed to open Database"); } } @catch (NSException *exception) { MSDKDNSLOG(@"Failed to connect Database"); @@ -125,9 +125,9 @@ - (void)insertOrReplaceDomainInfo:(NSDictionary *)domainInfo Domain:(NSString *) NSString *insertSql = [NSString stringWithFormat:@"INSERT OR REPLACE into HttpDNSTable(domain, httpDnsIPV4Channel, httpDnsIPV4ClientIP, httpDnsIPV4IPs, httpDnsIPV4TimeConsuming, httpDnsIPV4TTL, httpDnsIPV4TTLExpried, httpDnsIPV6ClientIP, httpDnsIPV6IPs, httpDnsIPV6TimeConsuming, httpDnsIPV6TTL, httpDnsIPV6TTLExpried) values('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@')",[domain copy],hresultDict_A_kChannel,hresultDict_A_kClientIP,hresultDict_A_kIP,hresultDict_A_kDnsTimeConsuming,hresultDict_A_kTTL,hresultDict_A_kTTLExpired,hresultDict_4A_kClientIP,hresultDict_4A_kIP,hresultDict_4A_kDnsTimeConsuming,hresultDict_4A_kTTL,hresultDict_4A_kTTLExpired]; if (sqlite3_exec(_db, [insertSql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { - NSLog(@"Successfully insert data into database, domain = %@, domainInfo = %@", domain, domainInfo); + MSDKDNSLOG(@"Successfully insert data into database, domain = %@, domainInfo = %@", domain, domainInfo); } else { - NSLog(@"Failed to insert data into database, error: %s", _error); + MSDKDNSLOG(@"Failed to insert data into database, error: %s", _error); // 每次使用完毕清空 error 字符串,提供给下一次使用 sqlite3_free(_error); @@ -237,9 +237,9 @@ - (NSDictionary *)getDataFromDB { [newResult setObject:domainInfo forKey:domain]; } - NSLog(@"Successfully select data from database, result = %@",newResult); + MSDKDNSLOG(@"Successfully select data from database, result = %@",newResult); } else { - NSLog(@"Failed to select data from database, error: %s", _error); + MSDKDNSLOG(@"Failed to select data from database, error: %s", _error); } } @catch (NSException *exception) { @@ -254,9 +254,9 @@ - (void)deleteDBData: (NSArray *)domains { @try { NSString *sql = [NSString stringWithFormat:@"DELETE FROM HttpDNSTable WHERE domain IN ('%@')", [domains componentsJoinedByString:@"','"]]; if (sqlite3_exec(_db, [sql UTF8String], NULL, NULL, &_error) == SQLITE_OK) { - NSLog(@"Successfully delete data into database. domains = %@", domains); + MSDKDNSLOG(@"Successfully delete data into database. domains = %@", domains); } else { - NSLog(@"Failed to delete data into database. error:%s", _error); + MSDKDNSLOG(@"Failed to delete data into database. error:%s", _error); // 每次使用完毕清空 error 字符串,提供给下一次使用 sqlite3_free(_error); } @@ -289,14 +289,14 @@ - (BOOL)close { triedFinalizingOpenStatements = YES; sqlite3_stmt *pStmt; while ((pStmt = sqlite3_next_stmt(_db, nil)) !=0) { - NSLog(@"Closing leaked statement"); + MSDKDNSLOG(@"Closing leaked statement"); sqlite3_finalize(pStmt); retry = YES; } } } else if (SQLITE_OK != rc) { - NSLog(@"error closing!: %d", rc); + MSDKDNSLOG(@"Failed to close Database: %d", rc); } } while (retry); From 0ec2e7a0e27311273f689dd0b813ab647ed2d56a Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Fri, 28 Oct 2022 11:12:37 +0800 Subject: [PATCH 05/15] =?UTF-8?q?feat:=E8=A7=A3=E6=9E=90=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E5=86=85=E6=B5=8B=E7=81=B0=E5=BA=A6=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns.xcodeproj/project.pbxproj | 16 ++++++++++++---- MSDKDns/MSDKDns.h | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index d4a27c7..2e7c934 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -392,6 +392,10 @@ TargetAttributes = { 44224FBF1B312DD6003497C4 = { CreatedOnToolsVersion = 6.3; + DevelopmentTeam = 4PK94A7P3R; + }; + DD43F493231CC36D0000A89F = { + DevelopmentTeam = 4PK94A7P3R; }; }; }; @@ -683,6 +687,7 @@ CURRENT_PROJECT_VERSION = 1107; DEAD_CODE_STRIPPING = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 4PK94A7P3R; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; @@ -701,7 +706,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.0; + MARKETING_VERSION = 1.6.1; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -729,6 +734,7 @@ CURRENT_PROJECT_VERSION = 1107; DEAD_CODE_STRIPPING = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 4PK94A7P3R; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; @@ -747,7 +753,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.0; + MARKETING_VERSION = 1.6.1; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -773,6 +779,7 @@ CURRENT_PROJECT_VERSION = 1107; DEAD_CODE_STRIPPING = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 4PK94A7P3R; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; @@ -784,7 +791,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.0; + MARKETING_VERSION = 1.6.1; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -812,6 +819,7 @@ CURRENT_PROJECT_VERSION = 1107; DEAD_CODE_STRIPPING = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 4PK94A7P3R; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; ENABLE_BITCODE = YES; @@ -823,7 +831,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.0; + MARKETING_VERSION = 1.6.1; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index dff0d13..fcf5ba6 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -5,7 +5,7 @@ #ifndef __MSDKDns_H__ #define __MSDKDns_H__ -#define MSDKDns_Version @"1.6.0" +#define MSDKDns_Version @"1.6.1" #import From 4787fa5ae0079f54136dd86d3c9ab5fefd7cca56 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Wed, 23 Nov 2022 16:43:51 +0800 Subject: [PATCH 06/15] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E7=AB=99sdk=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns.xcodeproj/project.pbxproj | 539 ++++++++++++++++++ .../xcschemes/MSDKDns_C11_intl.xcscheme | 67 +++ .../xcschemes/MSDKDns_intl.xcscheme | 67 +++ MSDKDns/CacheManager/MSDKDnsParamsManager.m | 6 + MSDKDns/MSDKDns.m | 9 + MSDKDns/MSDKDnsService.m | 17 + MSDKDns/Reporter/AttaReport.m | 5 + MSDKDns_C11_intl-Info.plist | 28 + MSDKDns_intl-Info.plist | 28 + 9 files changed, 766 insertions(+) create mode 100644 MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns_C11_intl.xcscheme create mode 100644 MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns_intl.xcscheme create mode 100644 MSDKDns_C11_intl-Info.plist create mode 100644 MSDKDns_intl-Info.plist diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 2e7c934..2f5fc6a 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -38,6 +38,82 @@ 54EA82232760890B005F68A9 /* AttaReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 54EA82212760890B005F68A9 /* AttaReport.m */; }; 54EA822427608A55005F68A9 /* AttaReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 54EA82202760890B005F68A9 /* AttaReport.h */; }; 54EA822527608A58005F68A9 /* AttaReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 54EA82212760890B005F68A9 /* AttaReport.m */; }; + 5F094377292B82D50004374B /* MSDKDnsParamsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 502422EB2140073F0094403C /* MSDKDnsParamsManager.m */; }; + 5F094378292B82D50004374B /* MSDKDnsInfoTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 44BFE2361CA58C3A00D7FE87 /* MSDKDnsInfoTool.m */; }; + 5F094379292B82D50004374B /* HttpsDnsResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = DD5935541DDC56B200BF9348 /* HttpsDnsResolver.m */; }; + 5F09437A292B82D50004374B /* MSDKDnsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 445B36621CBD095C00BD4345 /* MSDKDnsManager.m */; }; + 5F09437B292B82D50004374B /* MSDKDnsService.m in Sources */ = {isa = PBXBuildFile; fileRef = 444044F81B3133A30010F5D5 /* MSDKDnsService.m */; }; + 5F09437C292B82D50004374B /* MSDKDnsTCPSpeedTester.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F5DAF4C28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.m */; }; + 5F09437D292B82D50004374B /* aes.mm in Sources */ = {isa = PBXBuildFile; fileRef = C8EBE7D2256664C500BEFEEC /* aes.mm */; }; + 5F09437E292B82D50004374B /* msdkdns_local_ip_stack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 501001EC215E1F1D003288A5 /* msdkdns_local_ip_stack.cpp */; }; + 5F09437F292B82D50004374B /* MSDKDnsReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 44BFE2471CA59D9800D7FE87 /* MSDKDnsReachability.m */; }; + 5F094380292B82D50004374B /* MSDKDnsNetworkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 445B36681CBD1D4700BD4345 /* MSDKDnsNetworkManager.m */; }; + 5F094381292B82D50004374B /* MSDKDnsLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 4497F8B71B4628F000D51391 /* MSDKDnsLog.m */; }; + 5F094382292B82D50004374B /* MSDKDnsHttpMessageTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 504F54391ECAF89F001BD7A9 /* MSDKDnsHttpMessageTools.m */; }; + 5F094383292B82D50004374B /* MSDKDnsDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */; }; + 5F094384292B82D50004374B /* MSDKDnsResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 448EE4E11B329899004A2131 /* MSDKDnsResolver.m */; }; + 5F094385292B82D50004374B /* AttaReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 54EA82212760890B005F68A9 /* AttaReport.m */; }; + 5F094386292B82D50004374B /* MSDKDns.m in Sources */ = {isa = PBXBuildFile; fileRef = 4455D15D1B3A5B90005BF126 /* MSDKDns.m */; }; + 5F094387292B82D50004374B /* LocalDnsResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 448EE4DF1B329899004A2131 /* LocalDnsResolver.m */; }; + 5F094389292B82D50004374B /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */; }; + 5F09438A292B82D50004374B /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = C8EBE7DA2566675800BEFEEC /* libc++.tbd */; }; + 5F09438D292B82D50004374B /* MSDKDnsReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 44BFE2461CA59D9800D7FE87 /* MSDKDnsReachability.h */; }; + 5F09438E292B82D50004374B /* MSDKDnsDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */; }; + 5F09438F292B82D50004374B /* MSDKDnsHttpMessageTools.h in Headers */ = {isa = PBXBuildFile; fileRef = 504F54381ECAF89F001BD7A9 /* MSDKDnsHttpMessageTools.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5F094390292B82D50004374B /* MSDKDnsNetworkManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 445B36671CBD1D4700BD4345 /* MSDKDnsNetworkManager.h */; }; + 5F094391292B82D50004374B /* aes.h in Headers */ = {isa = PBXBuildFile; fileRef = C8EBE7D1256664C400BEFEEC /* aes.h */; }; + 5F094392292B82D50004374B /* MSDKDnsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 445B36611CBD095C00BD4345 /* MSDKDnsManager.h */; }; + 5F094393292B82D50004374B /* MSDKDnsLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 4497F8B61B4628F000D51391 /* MSDKDnsLog.h */; }; + 5F094394292B82D50004374B /* MSDKDns.h in Headers */ = {isa = PBXBuildFile; fileRef = 4455D15C1B3A5B90005BF126 /* MSDKDns.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5F094395292B82D50004374B /* LocalDnsResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 448EE4DE1B329899004A2131 /* LocalDnsResolver.h */; }; + 5F094396292B82D50004374B /* HttpsDnsResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = DD5935551DDC56B200BF9348 /* HttpsDnsResolver.h */; }; + 5F094397292B82D50004374B /* MSDKDnsTCPSpeedTester.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F5DAF4B28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h */; }; + 5F094398292B82D50004374B /* MSDKDnsResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 448EE4E01B329899004A2131 /* MSDKDnsResolver.h */; }; + 5F094399292B82D50004374B /* AttaReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 54EA82202760890B005F68A9 /* AttaReport.h */; }; + 5F09439A292B82D50004374B /* MSDKDnsSpeedTester.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F5DAF4D28A525E300BF5B79 /* MSDKDnsSpeedTester.h */; }; + 5F09439B292B82D50004374B /* MSDKDnsInfoTool.h in Headers */ = {isa = PBXBuildFile; fileRef = 44BFE2351CA58C3A00D7FE87 /* MSDKDnsInfoTool.h */; }; + 5F09439C292B82D50004374B /* MSDKDnsParamsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 502422EA2140073F0094403C /* MSDKDnsParamsManager.h */; }; + 5F09439D292B82D50004374B /* MSDKDnsPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4497F8BC1B46306200D51391 /* MSDKDnsPrivate.h */; }; + 5F09439E292B82D50004374B /* MSDKDnsService.h in Headers */ = {isa = PBXBuildFile; fileRef = 444044F71B3133A30010F5D5 /* MSDKDnsService.h */; }; + 5F09439F292B82D50004374B /* msdkdns_local_ip_stack.h in Headers */ = {isa = PBXBuildFile; fileRef = 501001ED215E1F1D003288A5 /* msdkdns_local_ip_stack.h */; }; + 5F0943AA292B96CC0004374B /* MSDKDnsParamsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 502422EB2140073F0094403C /* MSDKDnsParamsManager.m */; }; + 5F0943AB292B96CC0004374B /* MSDKDnsInfoTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 44BFE2361CA58C3A00D7FE87 /* MSDKDnsInfoTool.m */; }; + 5F0943AC292B96CC0004374B /* HttpsDnsResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = DD5935541DDC56B200BF9348 /* HttpsDnsResolver.m */; }; + 5F0943AD292B96CC0004374B /* MSDKDnsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 445B36621CBD095C00BD4345 /* MSDKDnsManager.m */; }; + 5F0943AE292B96CC0004374B /* MSDKDnsService.m in Sources */ = {isa = PBXBuildFile; fileRef = 444044F81B3133A30010F5D5 /* MSDKDnsService.m */; }; + 5F0943AF292B96CC0004374B /* MSDKDnsTCPSpeedTester.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F5DAF4C28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.m */; }; + 5F0943B0292B96CC0004374B /* msdkdns_local_ip_stack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 501001EC215E1F1D003288A5 /* msdkdns_local_ip_stack.cpp */; }; + 5F0943B1292B96CC0004374B /* MSDKDnsReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 44BFE2471CA59D9800D7FE87 /* MSDKDnsReachability.m */; }; + 5F0943B2292B96CC0004374B /* aes.mm in Sources */ = {isa = PBXBuildFile; fileRef = C8EBE7D2256664C500BEFEEC /* aes.mm */; }; + 5F0943B3292B96CC0004374B /* MSDKDnsNetworkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 445B36681CBD1D4700BD4345 /* MSDKDnsNetworkManager.m */; }; + 5F0943B4292B96CC0004374B /* MSDKDnsLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 4497F8B71B4628F000D51391 /* MSDKDnsLog.m */; }; + 5F0943B5292B96CC0004374B /* MSDKDnsHttpMessageTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 504F54391ECAF89F001BD7A9 /* MSDKDnsHttpMessageTools.m */; }; + 5F0943B6292B96CC0004374B /* MSDKDnsDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */; }; + 5F0943B7292B96CC0004374B /* MSDKDnsResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 448EE4E11B329899004A2131 /* MSDKDnsResolver.m */; }; + 5F0943B8292B96CC0004374B /* AttaReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 54EA82212760890B005F68A9 /* AttaReport.m */; }; + 5F0943B9292B96CC0004374B /* MSDKDns.m in Sources */ = {isa = PBXBuildFile; fileRef = 4455D15D1B3A5B90005BF126 /* MSDKDns.m */; }; + 5F0943BA292B96CC0004374B /* LocalDnsResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 448EE4DF1B329899004A2131 /* LocalDnsResolver.m */; }; + 5F0943BC292B96CC0004374B /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */; }; + 5F0943BD292B96CC0004374B /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = C8EBE7DA2566675800BEFEEC /* libc++.tbd */; }; + 5F0943C0292B96CC0004374B /* MSDKDnsReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 44BFE2461CA59D9800D7FE87 /* MSDKDnsReachability.h */; }; + 5F0943C1292B96CC0004374B /* MSDKDnsDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */; }; + 5F0943C2292B96CC0004374B /* MSDKDnsHttpMessageTools.h in Headers */ = {isa = PBXBuildFile; fileRef = 504F54381ECAF89F001BD7A9 /* MSDKDnsHttpMessageTools.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5F0943C3292B96CC0004374B /* MSDKDnsNetworkManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 445B36671CBD1D4700BD4345 /* MSDKDnsNetworkManager.h */; }; + 5F0943C4292B96CC0004374B /* aes.h in Headers */ = {isa = PBXBuildFile; fileRef = C8EBE7D1256664C400BEFEEC /* aes.h */; }; + 5F0943C5292B96CC0004374B /* MSDKDnsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 445B36611CBD095C00BD4345 /* MSDKDnsManager.h */; }; + 5F0943C6292B96CC0004374B /* MSDKDnsLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 4497F8B61B4628F000D51391 /* MSDKDnsLog.h */; }; + 5F0943C7292B96CC0004374B /* MSDKDns.h in Headers */ = {isa = PBXBuildFile; fileRef = 4455D15C1B3A5B90005BF126 /* MSDKDns.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 5F0943C8292B96CC0004374B /* LocalDnsResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 448EE4DE1B329899004A2131 /* LocalDnsResolver.h */; }; + 5F0943C9292B96CC0004374B /* HttpsDnsResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = DD5935551DDC56B200BF9348 /* HttpsDnsResolver.h */; }; + 5F0943CA292B96CC0004374B /* MSDKDnsTCPSpeedTester.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F5DAF4B28A525E300BF5B79 /* MSDKDnsTCPSpeedTester.h */; }; + 5F0943CB292B96CC0004374B /* MSDKDnsResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 448EE4E01B329899004A2131 /* MSDKDnsResolver.h */; }; + 5F0943CC292B96CC0004374B /* AttaReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 54EA82202760890B005F68A9 /* AttaReport.h */; }; + 5F0943CD292B96CC0004374B /* MSDKDnsSpeedTester.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F5DAF4D28A525E300BF5B79 /* MSDKDnsSpeedTester.h */; }; + 5F0943CE292B96CC0004374B /* MSDKDnsInfoTool.h in Headers */ = {isa = PBXBuildFile; fileRef = 44BFE2351CA58C3A00D7FE87 /* MSDKDnsInfoTool.h */; }; + 5F0943CF292B96CC0004374B /* MSDKDnsParamsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 502422EA2140073F0094403C /* MSDKDnsParamsManager.h */; }; + 5F0943D0292B96CC0004374B /* MSDKDnsPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4497F8BC1B46306200D51391 /* MSDKDnsPrivate.h */; }; + 5F0943D1292B96CC0004374B /* MSDKDnsService.h in Headers */ = {isa = PBXBuildFile; fileRef = 444044F71B3133A30010F5D5 /* MSDKDnsService.h */; }; + 5F0943D2292B96CC0004374B /* msdkdns_local_ip_stack.h in Headers */ = {isa = PBXBuildFile; fileRef = 501001ED215E1F1D003288A5 /* msdkdns_local_ip_stack.h */; }; 5F1332E928FFEC4A00A22D2A /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */; }; 5F1332EA28FFEC5000A22D2A /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */; }; 5F1E288428B72A7D00AD0D9F /* MSDKDnsDB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */; }; @@ -116,6 +192,8 @@ 54EA81F1275478D1005F68A9 /* httpdnsIps.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = httpdnsIps.h; sourceTree = ""; }; 54EA82202760890B005F68A9 /* AttaReport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttaReport.h; sourceTree = ""; }; 54EA82212760890B005F68A9 /* AttaReport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AttaReport.m; sourceTree = ""; }; + 5F0943A5292B82D50004374B /* MSDKDns_C11_intl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MSDKDns_C11_intl.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 5F0943D8292B96CC0004374B /* MSDKDns_intl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MSDKDns_intl.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5F1332E828FFEC4600A22D2A /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/lib/libsqlite3.tbd; sourceTree = DEVELOPER_DIR; }; 5F1E287D28B72A7D00AD0D9F /* MSDKDnsDB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSDKDnsDB.m; sourceTree = ""; }; 5F1E287F28B72A7D00AD0D9F /* MSDKDnsDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSDKDnsDB.h; sourceTree = ""; }; @@ -140,6 +218,24 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5F094388292B82D50004374B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5F094389292B82D50004374B /* libsqlite3.tbd in Frameworks */, + 5F09438A292B82D50004374B /* libc++.tbd in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5F0943BB292B96CC0004374B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5F0943BC292B96CC0004374B /* libsqlite3.tbd in Frameworks */, + 5F0943BD292B96CC0004374B /* libc++.tbd in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; DD43F4A3231CC36D0000A89F /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -166,6 +262,8 @@ children = ( 44224FC01B312DD6003497C4 /* MSDKDns.framework */, DD43F4B9231CC36D0000A89F /* MSDKDns_C11.framework */, + 5F0943A5292B82D50004374B /* MSDKDns_C11_intl.framework */, + 5F0943D8292B96CC0004374B /* MSDKDns_intl.framework */, ); name = Products; sourceTree = ""; @@ -310,6 +408,58 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5F09438C292B82D50004374B /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 5F09438D292B82D50004374B /* MSDKDnsReachability.h in Headers */, + 5F09438E292B82D50004374B /* MSDKDnsDB.h in Headers */, + 5F09438F292B82D50004374B /* MSDKDnsHttpMessageTools.h in Headers */, + 5F094390292B82D50004374B /* MSDKDnsNetworkManager.h in Headers */, + 5F094391292B82D50004374B /* aes.h in Headers */, + 5F094392292B82D50004374B /* MSDKDnsManager.h in Headers */, + 5F094393292B82D50004374B /* MSDKDnsLog.h in Headers */, + 5F094394292B82D50004374B /* MSDKDns.h in Headers */, + 5F094395292B82D50004374B /* LocalDnsResolver.h in Headers */, + 5F094396292B82D50004374B /* HttpsDnsResolver.h in Headers */, + 5F094397292B82D50004374B /* MSDKDnsTCPSpeedTester.h in Headers */, + 5F094398292B82D50004374B /* MSDKDnsResolver.h in Headers */, + 5F094399292B82D50004374B /* AttaReport.h in Headers */, + 5F09439A292B82D50004374B /* MSDKDnsSpeedTester.h in Headers */, + 5F09439B292B82D50004374B /* MSDKDnsInfoTool.h in Headers */, + 5F09439C292B82D50004374B /* MSDKDnsParamsManager.h in Headers */, + 5F09439D292B82D50004374B /* MSDKDnsPrivate.h in Headers */, + 5F09439E292B82D50004374B /* MSDKDnsService.h in Headers */, + 5F09439F292B82D50004374B /* msdkdns_local_ip_stack.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5F0943BF292B96CC0004374B /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 5F0943C0292B96CC0004374B /* MSDKDnsReachability.h in Headers */, + 5F0943C1292B96CC0004374B /* MSDKDnsDB.h in Headers */, + 5F0943C2292B96CC0004374B /* MSDKDnsHttpMessageTools.h in Headers */, + 5F0943C3292B96CC0004374B /* MSDKDnsNetworkManager.h in Headers */, + 5F0943C4292B96CC0004374B /* aes.h in Headers */, + 5F0943C5292B96CC0004374B /* MSDKDnsManager.h in Headers */, + 5F0943C6292B96CC0004374B /* MSDKDnsLog.h in Headers */, + 5F0943C7292B96CC0004374B /* MSDKDns.h in Headers */, + 5F0943C8292B96CC0004374B /* LocalDnsResolver.h in Headers */, + 5F0943C9292B96CC0004374B /* HttpsDnsResolver.h in Headers */, + 5F0943CA292B96CC0004374B /* MSDKDnsTCPSpeedTester.h in Headers */, + 5F0943CB292B96CC0004374B /* MSDKDnsResolver.h in Headers */, + 5F0943CC292B96CC0004374B /* AttaReport.h in Headers */, + 5F0943CD292B96CC0004374B /* MSDKDnsSpeedTester.h in Headers */, + 5F0943CE292B96CC0004374B /* MSDKDnsInfoTool.h in Headers */, + 5F0943CF292B96CC0004374B /* MSDKDnsParamsManager.h in Headers */, + 5F0943D0292B96CC0004374B /* MSDKDnsPrivate.h in Headers */, + 5F0943D1292B96CC0004374B /* MSDKDnsService.h in Headers */, + 5F0943D2292B96CC0004374B /* msdkdns_local_ip_stack.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; DD43F4A5231CC36D0000A89F /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -360,6 +510,48 @@ productReference = 44224FC01B312DD6003497C4 /* MSDKDns.framework */; productType = "com.apple.product-type.bundle"; }; + 5F094374292B82D50004374B /* MSDKDns_C11_intl */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5F0943A2292B82D50004374B /* Build configuration list for PBXNativeTarget "MSDKDns_C11_intl" */; + buildPhases = ( + 5F094375292B82D50004374B /* ShellScript */, + 5F094376292B82D50004374B /* Sources */, + 5F094388292B82D50004374B /* Frameworks */, + 5F09438B292B82D50004374B /* Resources */, + 5F09438C292B82D50004374B /* Headers */, + 5F0943A0292B82D50004374B /* Run Script */, + 5F0943A1292B82D50004374B /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MSDKDns_C11_intl; + productName = MSDKDns; + productReference = 5F0943A5292B82D50004374B /* MSDKDns_C11_intl.framework */; + productType = "com.apple.product-type.bundle"; + }; + 5F0943A7292B96CC0004374B /* MSDKDns_intl */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5F0943D5292B96CC0004374B /* Build configuration list for PBXNativeTarget "MSDKDns_intl" */; + buildPhases = ( + 5F0943A8292B96CC0004374B /* ShellScript */, + 5F0943A9292B96CC0004374B /* Sources */, + 5F0943BB292B96CC0004374B /* Frameworks */, + 5F0943BE292B96CC0004374B /* Resources */, + 5F0943BF292B96CC0004374B /* Headers */, + 5F0943D3292B96CC0004374B /* ShellScript */, + 5F0943D4292B96CC0004374B /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MSDKDns_intl; + productName = MSDKDns; + productReference = 5F0943D8292B96CC0004374B /* MSDKDns_intl.framework */; + productType = "com.apple.product-type.bundle"; + }; DD43F493231CC36D0000A89F /* MSDKDns_C11 */ = { isa = PBXNativeTarget; buildConfigurationList = DD43F4B6231CC36D0000A89F /* Build configuration list for PBXNativeTarget "MSDKDns_C11" */; @@ -394,6 +586,12 @@ CreatedOnToolsVersion = 6.3; DevelopmentTeam = 4PK94A7P3R; }; + 5F094374292B82D50004374B = { + DevelopmentTeam = 4PK94A7P3R; + }; + 5F0943A7292B96CC0004374B = { + DevelopmentTeam = 4PK94A7P3R; + }; DD43F493231CC36D0000A89F = { DevelopmentTeam = 4PK94A7P3R; }; @@ -413,7 +611,9 @@ projectRoot = ""; targets = ( 44224FBF1B312DD6003497C4 /* MSDKDns */, + 5F0943A7292B96CC0004374B /* MSDKDns_intl */, DD43F493231CC36D0000A89F /* MSDKDns_C11 */, + 5F094374292B82D50004374B /* MSDKDns_C11_intl */, ); }; /* End PBXProject section */ @@ -426,6 +626,20 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5F09438B292B82D50004374B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5F0943BE292B96CC0004374B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; DD43F4A4231CC36D0000A89F /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -475,6 +689,85 @@ shellPath = /bin/sh; shellScript = "echo \"Run Script 3\"\nset -e\n\nset +u\nif [[ $UFW_MASTER_SCRIPT_RUNNING ]]\nthen\n# Nothing for the slave script to do\nexit 0\nfi\nset -u\nexport UFW_MASTER_SCRIPT_RUNNING=1\n\n\n# Functions\n\n## List files in the specified directory, storing to the specified array.\n#\n# @param $1 The path to list\n# @param $2 The name of the array to fill\n#\n##\nlist_files ()\n{\n filelist=$(ls \"$1\")\n while read line\n do\n eval \"$2[\\${#$2[*]}]=\\\"\\$line\\\"\"\n done <<< \"$filelist\"\n}\n\n\n# Sanity check\n\nif [[ ! -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]]\nthen\necho \"Framework target \\\"${TARGET_NAME}\\\" had no source files to build from. Make sure your source files have the correct target membership\"\nexit 1\nfi\n\n\n# Gather information\n\nif [[ \"$SDK_NAME\" =~ ([A-Za-z]+) ]]\nthen\nUFW_SDK_PLATFORM=${BASH_REMATCH[1]}\nelse\necho \"Could not find platform name from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$SDK_NAME\" =~ ([0-9]+.*$) ]]\nthen\nUFW_SDK_VERSION=${BASH_REMATCH[1]}\nelse\necho \"Could not find sdk version from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$UFW_SDK_PLATFORM\" = \"iphoneos\" ]]\nthen\nUFW_OTHER_PLATFORM=iphonesimulator\nelse\nUFW_OTHER_PLATFORM=iphoneos\nfi\n\nif [[ \"$BUILT_PRODUCTS_DIR\" =~ (.*)$UFW_SDK_PLATFORM$ ]]\nthen\nUFW_OTHER_BUILT_PRODUCTS_DIR=\"${BASH_REMATCH[1]}${UFW_OTHER_PLATFORM}\"\nelse\necho \"Could not find $UFW_SDK_PLATFORM in $BUILT_PRODUCTS_DIR\"\nexit 1\nfi\n\n\n# Short-circuit if all binaries are up to date.\n# We already checked the other platform in the prerun script.\n\n#if [[ -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]] && [[ -f \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]] && [[ ! \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -nt \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]]\n#then\n# exit 0\n#fi\n\n\n# Make sure the other platform gets built\n\necho \"Build other platform\"\n\necho xcodebuild OTHER_CFLAGS=\"-fembed-bitcode\" -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" $ACTION\nxcodebuild OTHER_CFLAGS=\"-fembed-bitcode\" -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" $ACTION\n\n\n# Build the fat static library binary\n#echo \"Create universal static library\"\n#echo \"$DT_TOOLCHAIN_DIR/usr/bin/libtool\" -static \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -o \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\"\n#\"$DT_TOOLCHAIN_DIR/usr/bin/libtool\" -static \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -o \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\"\n#echo mv \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\" \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n#mv \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\" \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n\n\n# Build framework structure\n\necho \"Build symlinks\"\n\n#echo ln -sfh A \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/Current\"\n#ln -sfh A \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/Current\"\n#echo ln -sfh Versions/Current/Headers \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Headers\"\n#ln -sfh Versions/Current/Headers \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Headers\"\n#echo ln -sfh Versions/Current/Resources \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n#ln -sfh Versions/Current/Resources \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n#echo ln -sfh \"Versions/Current/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${EXECUTABLE_NAME}\"\n#ln -sfh \"Versions/Current/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${EXECUTABLE_NAME}\"\ncp -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/A/\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/\"\n\nrm -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions\"\n\ncp -R \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/A/\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/\"\nrm -R \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions\"\n\n# Link to binary for unit tests\n\nmkdir -p \"${BUILT_PRODUCTS_DIR}/.fake_fw_testing.framework\"\nln -sfh \"../${WRAPPER_NAME}/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/.fake_fw_testing.framework/.fake_fw_testing\"\n\n\n# Build embedded framework structure\n\n#echo \"Build Embedded Framework\"\n\n#echo rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\n#rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\n#echo mkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources\"\n#mkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources\"\n#echo cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/\"\n#cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/\"\n\n#declare -a UFW_FILE_LIST\n#list_files \"${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\" UFW_FILE_LIST\n#for filename in \"${UFW_FILE_LIST[@]}\"\n#do\n# if [[ \"${filename}\" != \"Info.plist\" ]] && [[ ! \"${filename}\" =~ .*\\.lproj$ ]]\n# then\n# echo ln -sfh \"../${WRAPPER_NAME}/Resources/${filename}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/Resources/${filename}\"\n# ln -sfh \"../${WRAPPER_NAME}/Resources/${filename}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources/${filename}\"\n# fi\n#done\n#cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources/\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources/\"\n#rm -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n\n# Replace other platform's framework with a copy of this one (so that both have the same universal binary)\n\necho \"Create xcframework\"\necho xcodebuild -create-xcframework \\\n -framework \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -framework \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -output \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.xcframework\"\nxcodebuild -create-xcframework \\\n -framework \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -framework \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -output \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.xcframework\"\n\necho \"Copy from $UFW_SDK_PLATFORM to $UFW_OTHER_PLATFORM\"\n\necho rm -rf \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\nrm -rf \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\necho cp -a \"${BUILD_DIR}/${CONFIGURATION}-${UFW_SDK_PLATFORM}\" \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\ncp -a \"${BUILD_DIR}/${CONFIGURATION}-${UFW_SDK_PLATFORM}\" \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\n\n# Copy library\nif [ -d \"$PROJECT_DIR/../$PRODUCT_NAME\" ]; then\nrm -r \"$PROJECT_DIR/../$PRODUCT_NAME\"\nfi\n\nif [ ! -d \"$PROJECT_DIR/../$PRODUCT_NAME\" ]; then\nmkdir \"$PROJECT_DIR/../$PRODUCT_NAME\"\nfi\n\ncp -R \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.framework\" \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.xcframework\" \"$PROJECT_DIR/../$PRODUCT_NAME\"\n"; }; + 5F094375292B82D50004374B /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"Run Script 1\"\n\nset -e\n\nset +u\nif [[ $UFW_MASTER_SCRIPT_RUNNING ]]\nthen\n# Nothing for the slave script to do\nexit 0\nfi\nset -u\n\nif [[ \"$SDK_NAME\" =~ ([A-Za-z]+) ]]\nthen\nUFW_SDK_PLATFORM=${BASH_REMATCH[1]}\nelse\necho \"Could not find platform name from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$SDK_NAME\" =~ ([0-9]+.*$) ]]\nthen\nUFW_SDK_VERSION=${BASH_REMATCH[1]}\nelse\necho \"Could not find sdk version from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$UFW_SDK_PLATFORM\" = \"iphoneos\" ]]\nthen\nUFW_OTHER_PLATFORM=iphonesimulator\nelse\nUFW_OTHER_PLATFORM=iphoneos\nfi\n\nif [[ \"$BUILT_PRODUCTS_DIR\" =~ (.*)$UFW_SDK_PLATFORM$ ]]\nthen\nUFW_OTHER_BUILT_PRODUCTS_DIR=\"${BASH_REMATCH[1]}${UFW_OTHER_PLATFORM}\"\nelse\necho \"Could not find $UFW_SDK_PLATFORM in $BUILT_PRODUCTS_DIR\"\nexit 1\nfi\n\n\n# Short-circuit if all binaries are up to date\n\n#if [[ -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]] && \\\n# [[ -f \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]] && \\\n# [[ ! \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -nt \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]]\n# [[ -f \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]] && \\\n# [[ -f \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]] && \\\n# [[ ! \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -nt \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]]\n#then\n# exit 0\n#fi\n\n\n# Clean other platform if needed\n\nif [[ ! -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]]\nthen\necho \"Platform \\\"$UFW_SDK_PLATFORM\\\" was cleaned recently. Cleaning \\\"$UFW_OTHER_PLATFORM\\\" as well\"\necho xcodebuild -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" clean\nxcodebuild -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" clean\nfi\n\n\n# Make sure we are building from fresh binaries\n\nrm -rf \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n#rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\nrm -rf \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n#rm -rf \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\nrm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.xcframework\"\n"; + }; + 5F0943A0292B82D50004374B /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "HEADERS_ROOT=$SRCROOT/$PRODUCT_NAME\nFRAMEWORK_HEADERS_DIR=\"$BUILT_PRODUCTS_DIR/$WRAPPER_NAME/Versions/$FRAMEWORK_VERSION/Headers\"\n\necho \"Run Script 2\"\n\n## only header files expected at this point\nPUBLIC_HEADERS=$(find $FRAMEWORK_HEADERS_DIR/. -not -type d 2> /dev/null | sed -e \"s@.*/@@g\")\n\nFIND_OPTS=\"\"\nfor PUBLIC_HEADER in $PUBLIC_HEADERS; do\nif [ -n \"$FIND_OPTS\" ]; then\nFIND_OPTS=\"$FIND_OPTS -o\"\nfi\nFIND_OPTS=\"$FIND_OPTS -name '$PUBLIC_HEADER'\"\ndone\n\nif [ -n \"$FIND_OPTS\" ]; then\nfor ORIG_HEADER in $(eval \"find $HEADERS_ROOT/. $FIND_OPTS\" 2> /dev/null | sed -e \"s@^$HEADERS_ROOT/./@@g\"); do\nPUBLIC_HEADER=$(basename $ORIG_HEADER)\nRELATIVE_PATH=$(dirname $ORIG_HEADER)\nif [ -e $FRAMEWORK_HEADERS_DIR/$PUBLIC_HEADER ]; then\nmkdir -p \"$FRAMEWORK_HEADERS_DIR/$RELATIVE_PATH\"\nmv \"$FRAMEWORK_HEADERS_DIR/$PUBLIC_HEADER\" \"$FRAMEWORK_HEADERS_DIR/$RELATIVE_PATH/$PUBLIC_HEADER\"\nfi\ndone\nfi\n"; + }; + 5F0943A1292B82D50004374B /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"Run Script 3\"\nset -e\n\nset +u\nif [[ $UFW_MASTER_SCRIPT_RUNNING ]]\nthen\n# Nothing for the slave script to do\nexit 0\nfi\nset -u\nexport UFW_MASTER_SCRIPT_RUNNING=1\n\n\n# Functions\n\n## List files in the specified directory, storing to the specified array.\n#\n# @param $1 The path to list\n# @param $2 The name of the array to fill\n#\n##\nlist_files ()\n{\n filelist=$(ls \"$1\")\n while read line\n do\n eval \"$2[\\${#$2[*]}]=\\\"\\$line\\\"\"\n done <<< \"$filelist\"\n}\n\n\n# Sanity check\n\nif [[ ! -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]]\nthen\necho \"Framework target \\\"${TARGET_NAME}\\\" had no source files to build from. Make sure your source files have the correct target membership\"\nexit 1\nfi\n\n\n# Gather information\n\nif [[ \"$SDK_NAME\" =~ ([A-Za-z]+) ]]\nthen\nUFW_SDK_PLATFORM=${BASH_REMATCH[1]}\nelse\necho \"Could not find platform name from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$SDK_NAME\" =~ ([0-9]+.*$) ]]\nthen\nUFW_SDK_VERSION=${BASH_REMATCH[1]}\nelse\necho \"Could not find sdk version from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$UFW_SDK_PLATFORM\" = \"iphoneos\" ]]\nthen\nUFW_OTHER_PLATFORM=iphonesimulator\nelse\nUFW_OTHER_PLATFORM=iphoneos\nfi\n\nif [[ \"$BUILT_PRODUCTS_DIR\" =~ (.*)$UFW_SDK_PLATFORM$ ]]\nthen\nUFW_OTHER_BUILT_PRODUCTS_DIR=\"${BASH_REMATCH[1]}${UFW_OTHER_PLATFORM}\"\nelse\necho \"Could not find $UFW_SDK_PLATFORM in $BUILT_PRODUCTS_DIR\"\nexit 1\nfi\n\n\n# Short-circuit if all binaries are up to date.\n# We already checked the other platform in the prerun script.\n\n#if [[ -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]] && [[ -f \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]] && [[ ! \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -nt \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]]\n#then\n# exit 0\n#fi\n\n\n# Make sure the other platform gets built\n\necho \"Build other platform\"\n\necho xcodebuild OTHER_CFLAGS=\"-fembed-bitcode\" -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" $ACTION\nxcodebuild OTHER_CFLAGS=\"-fembed-bitcode\" -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" $ACTION\n\n\n# Build the fat static library binary\n#echo \"Create universal static library\"\n#echo \"$DT_TOOLCHAIN_DIR/usr/bin/libtool\" -static \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -o \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\"\n#\"$DT_TOOLCHAIN_DIR/usr/bin/libtool\" -static \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -o \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\"\n#echo mv \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\" \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n#mv \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\" \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n\n\n# Build framework structure\n\necho \"Build symlinks\"\n\n#echo ln -sfh A \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/Current\"\n#ln -sfh A \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/Current\"\n#echo ln -sfh Versions/Current/Headers \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Headers\"\n#ln -sfh Versions/Current/Headers \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Headers\"\n#echo ln -sfh Versions/Current/Resources \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n#ln -sfh Versions/Current/Resources \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n#echo ln -sfh \"Versions/Current/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${EXECUTABLE_NAME}\"\n#ln -sfh \"Versions/Current/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${EXECUTABLE_NAME}\"\ncp -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/A/\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/\"\n\nrm -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions\"\n\ncp -R \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/A/\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/\"\nrm -R \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions\"\n\n# Link to binary for unit tests\n\nmkdir -p \"${BUILT_PRODUCTS_DIR}/.fake_fw_testing.framework\"\nln -sfh \"../${WRAPPER_NAME}/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/.fake_fw_testing.framework/.fake_fw_testing\"\n\n# Build embedded framework structure\n\n#echo \"Build Embedded Framework\"\n\n#echo rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\n#rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\n#echo mkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources\"\n#mkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources\"\n#echo cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/\"\n#cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/\"\n\n#declare -a UFW_FILE_LIST\n#list_files \"${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\" UFW_FILE_LIST\n#for filename in \"${UFW_FILE_LIST[@]}\"\n#do\n# if [[ \"${filename}\" != \"Info.plist\" ]] && [[ ! \"${filename}\" =~ .*\\.lproj$ ]]\n# then\n# echo ln -sfh \"../${WRAPPER_NAME}/Resources/${filename}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/Resources/${filename}\"\n# ln -sfh \"../${WRAPPER_NAME}/Resources/${filename}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources/${filename}\"\n# fi\n#done\n#cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources/\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources/\"\n#rm -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n\n# Replace other platform's framework with a copy of this one (so that both have the same universal binary)\n\necho \"Create xcframework\"\necho xcodebuild -create-xcframework \\\n -framework \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -framework \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -output \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.xcframework\"\nxcodebuild -create-xcframework \\\n -framework \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -framework \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -output \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.xcframework\"\n\necho \"Copy from $UFW_SDK_PLATFORM to $UFW_OTHER_PLATFORM\"\n\necho rm -rf \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\nrm -rf \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\necho cp -a \"${BUILD_DIR}/${CONFIGURATION}-${UFW_SDK_PLATFORM}\" \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\ncp -a \"${BUILD_DIR}/${CONFIGURATION}-${UFW_SDK_PLATFORM}\" \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\n\n# Copy library\nif [ -d \"$PROJECT_DIR/../$PRODUCT_NAME\" ]; then\nrm -r \"$PROJECT_DIR/../$PRODUCT_NAME\"\nfi\n\nif [ ! -d \"$PROJECT_DIR/../$PRODUCT_NAME\" ]; then\nmkdir \"$PROJECT_DIR/../$PRODUCT_NAME\"\nfi\n\ncp -R \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.framework\" \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.xcframework\" \"$PROJECT_DIR/../$PRODUCT_NAME\"\n"; + }; + 5F0943A8292B96CC0004374B /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"Run Script 1\"\n\nset -e\n\nset +u\nif [[ $UFW_MASTER_SCRIPT_RUNNING ]]\nthen\n# Nothing for the slave script to do\nexit 0\nfi\nset -u\n\nif [[ \"$SDK_NAME\" =~ ([A-Za-z]+) ]]\nthen\nUFW_SDK_PLATFORM=${BASH_REMATCH[1]}\nelse\necho \"Could not find platform name from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$SDK_NAME\" =~ ([0-9]+.*$) ]]\nthen\nUFW_SDK_VERSION=${BASH_REMATCH[1]}\nelse\necho \"Could not find sdk version from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$UFW_SDK_PLATFORM\" = \"iphoneos\" ]]\nthen\nUFW_OTHER_PLATFORM=iphonesimulator\nelse\nUFW_OTHER_PLATFORM=iphoneos\nfi\n\nif [[ \"$BUILT_PRODUCTS_DIR\" =~ (.*)$UFW_SDK_PLATFORM$ ]]\nthen\nUFW_OTHER_BUILT_PRODUCTS_DIR=\"${BASH_REMATCH[1]}${UFW_OTHER_PLATFORM}\"\nelse\necho \"Could not find $UFW_SDK_PLATFORM in $BUILT_PRODUCTS_DIR\"\nexit 1\nfi\n\n\n# Short-circuit if all binaries are up to date\n\n#if [[ -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]] && \\\n# [[ -f \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]] && \\\n# [[ ! \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -nt \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]]\n# [[ -f \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]] && \\\n# [[ -f \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]] && \\\n# [[ ! \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -nt \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]]\n#then\n# exit 0\n#fi\n\n\n# Clean other platform if needed\n\nif [[ ! -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]]\nthen\necho \"Platform \\\"$UFW_SDK_PLATFORM\\\" was cleaned recently. Cleaning \\\"$UFW_OTHER_PLATFORM\\\" as well\"\necho xcodebuild -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" clean\nxcodebuild -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" clean\nfi\n\n\n# Make sure we are building from fresh binaries\n\nrm -rf \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n#rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\nrm -rf \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n#rm -rf \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\nrm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.xcframework\"\n"; + }; + 5F0943D3292B96CC0004374B /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "HEADERS_ROOT=$SRCROOT/$PRODUCT_NAME\nFRAMEWORK_HEADERS_DIR=\"$BUILT_PRODUCTS_DIR/$WRAPPER_NAME/Versions/$FRAMEWORK_VERSION/Headers\"\n\necho \"Run Script 2\"\n\n## only header files expected at this point\nPUBLIC_HEADERS=$(find $FRAMEWORK_HEADERS_DIR/. -not -type d 2> /dev/null | sed -e \"s@.*/@@g\")\n\nFIND_OPTS=\"\"\nfor PUBLIC_HEADER in $PUBLIC_HEADERS; do\nif [ -n \"$FIND_OPTS\" ]; then\nFIND_OPTS=\"$FIND_OPTS -o\"\nfi\nFIND_OPTS=\"$FIND_OPTS -name '$PUBLIC_HEADER'\"\ndone\n\nif [ -n \"$FIND_OPTS\" ]; then\nfor ORIG_HEADER in $(eval \"find $HEADERS_ROOT/. $FIND_OPTS\" 2> /dev/null | sed -e \"s@^$HEADERS_ROOT/./@@g\"); do\nPUBLIC_HEADER=$(basename $ORIG_HEADER)\nRELATIVE_PATH=$(dirname $ORIG_HEADER)\nif [ -e $FRAMEWORK_HEADERS_DIR/$PUBLIC_HEADER ]; then\nmkdir -p \"$FRAMEWORK_HEADERS_DIR/$RELATIVE_PATH\"\nmv \"$FRAMEWORK_HEADERS_DIR/$PUBLIC_HEADER\" \"$FRAMEWORK_HEADERS_DIR/$RELATIVE_PATH/$PUBLIC_HEADER\"\nfi\ndone\nfi\n"; + }; + 5F0943D4292B96CC0004374B /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"Run Script 3\"\nset -e\n\nset +u\nif [[ $UFW_MASTER_SCRIPT_RUNNING ]]\nthen\n# Nothing for the slave script to do\nexit 0\nfi\nset -u\nexport UFW_MASTER_SCRIPT_RUNNING=1\n\n\n# Functions\n\n## List files in the specified directory, storing to the specified array.\n#\n# @param $1 The path to list\n# @param $2 The name of the array to fill\n#\n##\nlist_files ()\n{\n filelist=$(ls \"$1\")\n while read line\n do\n eval \"$2[\\${#$2[*]}]=\\\"\\$line\\\"\"\n done <<< \"$filelist\"\n}\n\n\n# Sanity check\n\nif [[ ! -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]]\nthen\necho \"Framework target \\\"${TARGET_NAME}\\\" had no source files to build from. Make sure your source files have the correct target membership\"\nexit 1\nfi\n\n\n# Gather information\n\nif [[ \"$SDK_NAME\" =~ ([A-Za-z]+) ]]\nthen\nUFW_SDK_PLATFORM=${BASH_REMATCH[1]}\nelse\necho \"Could not find platform name from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$SDK_NAME\" =~ ([0-9]+.*$) ]]\nthen\nUFW_SDK_VERSION=${BASH_REMATCH[1]}\nelse\necho \"Could not find sdk version from SDK_NAME: $SDK_NAME\"\nexit 1\nfi\n\nif [[ \"$UFW_SDK_PLATFORM\" = \"iphoneos\" ]]\nthen\nUFW_OTHER_PLATFORM=iphonesimulator\nelse\nUFW_OTHER_PLATFORM=iphoneos\nfi\n\nif [[ \"$BUILT_PRODUCTS_DIR\" =~ (.*)$UFW_SDK_PLATFORM$ ]]\nthen\nUFW_OTHER_BUILT_PRODUCTS_DIR=\"${BASH_REMATCH[1]}${UFW_OTHER_PLATFORM}\"\nelse\necho \"Could not find $UFW_SDK_PLATFORM in $BUILT_PRODUCTS_DIR\"\nexit 1\nfi\n\n\n# Short-circuit if all binaries are up to date.\n# We already checked the other platform in the prerun script.\n\n#if [[ -f \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" ]] && [[ -f \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]] && [[ ! \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -nt \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/${EXECUTABLE_PATH}\" ]]\n#then\n# exit 0\n#fi\n\n\n# Make sure the other platform gets built\n\necho \"Build other platform\"\n\necho xcodebuild OTHER_CFLAGS=\"-fembed-bitcode\" -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" $ACTION\nxcodebuild OTHER_CFLAGS=\"-fembed-bitcode\" -project \"${PROJECT_FILE_PATH}\" -target \"${TARGET_NAME}\" -configuration \"${CONFIGURATION}\" -sdk ${UFW_OTHER_PLATFORM}${UFW_SDK_VERSION} BUILD_DIR=\"${BUILD_DIR}\" CONFIGURATION_TEMP_DIR=\"${PROJECT_TEMP_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\" $ACTION\n\n\n# Build the fat static library binary\n#echo \"Create universal static library\"\n#echo \"$DT_TOOLCHAIN_DIR/usr/bin/libtool\" -static \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -o \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\"\n#\"$DT_TOOLCHAIN_DIR/usr/bin/libtool\" -static \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\" -o \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\"\n#echo mv \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\" \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n#mv \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}.temp\" \"${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}\"\n\n\n# Build framework structure\n\necho \"Build symlinks\"\n\n#echo ln -sfh A \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/Current\"\n#ln -sfh A \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/Current\"\n#echo ln -sfh Versions/Current/Headers \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Headers\"\n#ln -sfh Versions/Current/Headers \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Headers\"\n#echo ln -sfh Versions/Current/Resources \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n#ln -sfh Versions/Current/Resources \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n#echo ln -sfh \"Versions/Current/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${EXECUTABLE_NAME}\"\n#ln -sfh \"Versions/Current/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${EXECUTABLE_NAME}\"\ncp -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/A/\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/\"\n\nrm -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions\"\n\ncp -R \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/A/\" \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/\"\nrm -R \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions\"\n\n# Link to binary for unit tests\n\nmkdir -p \"${BUILT_PRODUCTS_DIR}/.fake_fw_testing.framework\"\nln -sfh \"../${WRAPPER_NAME}/${EXECUTABLE_NAME}\" \"${BUILT_PRODUCTS_DIR}/.fake_fw_testing.framework/.fake_fw_testing\"\n\n\n# Build embedded framework structure\n\n#echo \"Build Embedded Framework\"\n\n#echo rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\n#rm -rf \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework\"\n#echo mkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources\"\n#mkdir -p \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources\"\n#echo cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/\"\n#cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/\"\n\n#declare -a UFW_FILE_LIST\n#list_files \"${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\" UFW_FILE_LIST\n#for filename in \"${UFW_FILE_LIST[@]}\"\n#do\n# if [[ \"${filename}\" != \"Info.plist\" ]] && [[ ! \"${filename}\" =~ .*\\.lproj$ ]]\n# then\n# echo ln -sfh \"../${WRAPPER_NAME}/Resources/${filename}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/Resources/${filename}\"\n# ln -sfh \"../${WRAPPER_NAME}/Resources/${filename}\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources/${filename}\"\n# fi\n#done\n#cp -a \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources/\" \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.embeddedframework/MsdkResources/\"\n#rm -R \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources\"\n\n# Replace other platform's framework with a copy of this one (so that both have the same universal binary)\n\necho \"Create xcframework\"\necho xcodebuild -create-xcframework \\\n -framework \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -framework \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -output \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.xcframework\"\nxcodebuild -create-xcframework \\\n -framework \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -framework \"${UFW_OTHER_BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework\" \\\n -output \"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.xcframework\"\n\necho \"Copy from $UFW_SDK_PLATFORM to $UFW_OTHER_PLATFORM\"\n\necho rm -rf \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\nrm -rf \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\necho cp -a \"${BUILD_DIR}/${CONFIGURATION}-${UFW_SDK_PLATFORM}\" \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\ncp -a \"${BUILD_DIR}/${CONFIGURATION}-${UFW_SDK_PLATFORM}\" \"${BUILD_DIR}/${CONFIGURATION}-${UFW_OTHER_PLATFORM}\"\n\n# Copy library\nif [ -d \"$PROJECT_DIR/../$PRODUCT_NAME\" ]; then\nrm -r \"$PROJECT_DIR/../$PRODUCT_NAME\"\nfi\n\nif [ ! -d \"$PROJECT_DIR/../$PRODUCT_NAME\" ]; then\nmkdir \"$PROJECT_DIR/../$PRODUCT_NAME\"\nfi\n\ncp -R \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.framework\" \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.xcframework\" \"$PROJECT_DIR/../$PRODUCT_NAME\"\n"; + }; DD43F494231CC36D0000A89F /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -542,6 +835,54 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5F094376292B82D50004374B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5F094377292B82D50004374B /* MSDKDnsParamsManager.m in Sources */, + 5F094378292B82D50004374B /* MSDKDnsInfoTool.m in Sources */, + 5F094379292B82D50004374B /* HttpsDnsResolver.m in Sources */, + 5F09437A292B82D50004374B /* MSDKDnsManager.m in Sources */, + 5F09437B292B82D50004374B /* MSDKDnsService.m in Sources */, + 5F09437C292B82D50004374B /* MSDKDnsTCPSpeedTester.m in Sources */, + 5F09437D292B82D50004374B /* aes.mm in Sources */, + 5F09437E292B82D50004374B /* msdkdns_local_ip_stack.cpp in Sources */, + 5F09437F292B82D50004374B /* MSDKDnsReachability.m in Sources */, + 5F094380292B82D50004374B /* MSDKDnsNetworkManager.m in Sources */, + 5F094381292B82D50004374B /* MSDKDnsLog.m in Sources */, + 5F094382292B82D50004374B /* MSDKDnsHttpMessageTools.m in Sources */, + 5F094383292B82D50004374B /* MSDKDnsDB.m in Sources */, + 5F094384292B82D50004374B /* MSDKDnsResolver.m in Sources */, + 5F094385292B82D50004374B /* AttaReport.m in Sources */, + 5F094386292B82D50004374B /* MSDKDns.m in Sources */, + 5F094387292B82D50004374B /* LocalDnsResolver.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5F0943A9292B96CC0004374B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5F0943AA292B96CC0004374B /* MSDKDnsParamsManager.m in Sources */, + 5F0943AB292B96CC0004374B /* MSDKDnsInfoTool.m in Sources */, + 5F0943AC292B96CC0004374B /* HttpsDnsResolver.m in Sources */, + 5F0943AD292B96CC0004374B /* MSDKDnsManager.m in Sources */, + 5F0943AE292B96CC0004374B /* MSDKDnsService.m in Sources */, + 5F0943AF292B96CC0004374B /* MSDKDnsTCPSpeedTester.m in Sources */, + 5F0943B0292B96CC0004374B /* msdkdns_local_ip_stack.cpp in Sources */, + 5F0943B1292B96CC0004374B /* MSDKDnsReachability.m in Sources */, + 5F0943B2292B96CC0004374B /* aes.mm in Sources */, + 5F0943B3292B96CC0004374B /* MSDKDnsNetworkManager.m in Sources */, + 5F0943B4292B96CC0004374B /* MSDKDnsLog.m in Sources */, + 5F0943B5292B96CC0004374B /* MSDKDnsHttpMessageTools.m in Sources */, + 5F0943B6292B96CC0004374B /* MSDKDnsDB.m in Sources */, + 5F0943B7292B96CC0004374B /* MSDKDnsResolver.m in Sources */, + 5F0943B8292B96CC0004374B /* AttaReport.m in Sources */, + 5F0943B9292B96CC0004374B /* MSDKDns.m in Sources */, + 5F0943BA292B96CC0004374B /* LocalDnsResolver.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; DD43F495231CC36D0000A89F /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -769,6 +1110,186 @@ }; name = Release; }; + 5F0943A3292B82D50004374B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1107; + DEAD_CODE_STRIPPING = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 4PK94A7P3R; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + ENABLE_BITCODE = YES; + FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/.."; + GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "IS_INTL=1", + ); + INFOPLIST_FILE = MSDKDns/Info.plist; + INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LINK_WITH_STANDARD_LIBRARIES = NO; + MACH_O_TYPE = mh_object; + MACOSX_DEPLOYMENT_TARGET = ""; + MARKETING_VERSION = 1.6.1; + ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_LDFLAGS = ( + "-ObjC", + "-fembed-bitcode", + ); + PRIVATE_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Versions/A/PrivateHeaders"; + PRODUCT_BUNDLE_IDENTIFIER = "com.tencent.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Versions/A/Headers"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + WRAPPER_EXTENSION = framework; + }; + name = Debug; + }; + 5F0943A4292B82D50004374B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = YES; + CURRENT_PROJECT_VERSION = 1107; + DEAD_CODE_STRIPPING = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 4PK94A7P3R; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + ENABLE_BITCODE = YES; + FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/.."; + GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; + GCC_PREPROCESSOR_DEFINITIONS = "IS_INTL=1"; + INFOPLIST_FILE = MSDKDns/Info.plist; + INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LINK_WITH_STANDARD_LIBRARIES = NO; + MACH_O_TYPE = mh_object; + MACOSX_DEPLOYMENT_TARGET = ""; + MARKETING_VERSION = 1.6.1; + OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_LDFLAGS = ( + "-ObjC", + "-fembed-bitcode", + ); + PRIVATE_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Versions/A/PrivateHeaders"; + PRODUCT_BUNDLE_IDENTIFIER = "com.tencent.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Versions/A/Headers"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + WRAPPER_EXTENSION = framework; + }; + name = Release; + }; + 5F0943D6292B96CC0004374B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1107; + DEAD_CODE_STRIPPING = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 4PK94A7P3R; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + ENABLE_BITCODE = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(PROJECT_DIR)/../**", + "$(inherited)", + ); + GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "IS_INTL=1", + ); + INFOPLIST_FILE = MSDKDns/Info.plist; + INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(SYSTEM_LIBRARY_DIR)/Tcl/sqlite3", + ); + LINK_WITH_STANDARD_LIBRARIES = NO; + MACH_O_TYPE = mh_object; + MACOSX_DEPLOYMENT_TARGET = ""; + MARKETING_VERSION = 1.6.1; + ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_LDFLAGS = ( + "-ObjC", + "-fembed-bitcode", + ); + PRIVATE_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Versions/A/PrivateHeaders"; + PRODUCT_BUNDLE_IDENTIFIER = "com.tencent.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Versions/A/Headers"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + WRAPPER_EXTENSION = framework; + }; + name = Debug; + }; + 5F0943D7292B96CC0004374B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = YES; + CURRENT_PROJECT_VERSION = 1107; + DEAD_CODE_STRIPPING = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 4PK94A7P3R; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + ENABLE_BITCODE = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(PROJECT_DIR)/../**", + "$(inherited)", + ); + GCC_INPUT_FILETYPE = sourcecode.cpp.objcpp; + GCC_PREPROCESSOR_DEFINITIONS = "IS_INTL=1"; + INFOPLIST_FILE = MSDKDns/Info.plist; + INSTALL_PATH = "$(BUILT_PRODUCTS_DIR)"; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(SYSTEM_LIBRARY_DIR)/Tcl/sqlite3", + ); + LINK_WITH_STANDARD_LIBRARIES = NO; + MACH_O_TYPE = mh_object; + MACOSX_DEPLOYMENT_TARGET = ""; + MARKETING_VERSION = 1.6.1; + OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_LDFLAGS = ( + "-ObjC", + "-fembed-bitcode", + ); + PRIVATE_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Versions/A/PrivateHeaders"; + PRODUCT_BUNDLE_IDENTIFIER = "com.tencent.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = "$(CONTENTS_FOLDER_PATH)/Versions/A/Headers"; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + WRAPPER_EXTENSION = framework; + }; + name = Release; + }; DD43F4B7231CC36D0000A89F /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -868,6 +1389,24 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 5F0943A2292B82D50004374B /* Build configuration list for PBXNativeTarget "MSDKDns_C11_intl" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5F0943A3292B82D50004374B /* Debug */, + 5F0943A4292B82D50004374B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5F0943D5292B96CC0004374B /* Build configuration list for PBXNativeTarget "MSDKDns_intl" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5F0943D6292B96CC0004374B /* Debug */, + 5F0943D7292B96CC0004374B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; DD43F4B6231CC36D0000A89F /* Build configuration list for PBXNativeTarget "MSDKDns_C11" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns_C11_intl.xcscheme b/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns_C11_intl.xcscheme new file mode 100644 index 0000000..32139eb --- /dev/null +++ b/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns_C11_intl.xcscheme @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns_intl.xcscheme b/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns_intl.xcscheme new file mode 100644 index 0000000..ca9cdcd --- /dev/null +++ b/MSDKDns.xcodeproj/xcshareddata/xcschemes/MSDKDns_intl.xcscheme @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.m b/MSDKDns/CacheManager/MSDKDnsParamsManager.m index b391bdc..2877bc0 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.m @@ -77,11 +77,17 @@ - (void)msdkDnsSetMDnsIp:(NSString *) msdkDnsIp { self.serverArray = [self.serverArray arrayByAddingObjectsFromArray:self.backupServerIps]; } else { #ifdef httpdnsIps_h + #if IS_INTL + if (self.msdkEncryptType != HttpDnsEncryptTypeHTTPS) { + self.serverArray = [self.serverArray arrayByAddingObjectsFromArray:httpServerIps_INTL]; + } + #else if (self.msdkEncryptType == HttpDnsEncryptTypeHTTPS) { self.serverArray = [self.serverArray arrayByAddingObjectsFromArray:httpsServerIps]; } else { self.serverArray = [self.serverArray arrayByAddingObjectsFromArray:httpServerIps]; } + #endif #endif } }); diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index 1383441..80ff779 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -39,6 +39,15 @@ - (instancetype) init { } - (BOOL) initConfig:(DnsConfig *)config { +#if IS_INTL + if (config->encryptType == HttpDnsEncryptTypeHTTPS) { + //开启了使用过期缓存功能,给出提示建议使用同步接口进行解析 + @throw [NSException exceptionWithName:@"MSDKDns wrong use of encryptType" + reason:@"HttpDnsEncryptTypeHTTPS cannot be used because httpdns-sdk-intl version still doesn't support, it is recommended to use HttpDnsEncryptTypeDES or HttpDnsEncryptTypeAES" + userInfo:nil]; + return NO; + } +#endif [[MSDKDnsLog sharedInstance] setEnableLog:config->debug]; [[MSDKDnsParamsManager shareInstance] msdkDnsSetMAppId:config->appId MTimeOut:config->timeout MEncryptType:config->encryptType]; [[MSDKDnsParamsManager shareInstance] msdkDnsSetMDnsId:config->dnsId MDnsKey:config->dnsKey MToken:config->token]; diff --git a/MSDKDns/MSDKDnsService.m b/MSDKDns/MSDKDnsService.m index 864d0c8..e95f1c6 100644 --- a/MSDKDns/MSDKDnsService.m +++ b/MSDKDns/MSDKDnsService.m @@ -476,6 +476,21 @@ - (void)dnsTimeoutAttaUpload:(MSDKDnsResolver *)resolver { }else if (resolver == self.httpDnsResolver_BOTH) { req_type = @"addrs"; } + + NSDictionary * dnsIPs = [self getDomainsDNSFromCache:self.toCheckDomains]; + NSString *localDnsIPs = [dnsIPs valueForKey:kMSDKDnsLDNS_IP]; + NSString *httpDnsIP_A = [dnsIPs valueForKey:kMSDKDns_A_IP]; + NSString *httpDnsIP_4A = [dnsIPs valueForKey:kMSDKDns_4A_IP]; + NSString *httpdnsIPs = @""; + + if ([httpDnsIP_A length] > 0 && [httpDnsIP_4A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@,%@", httpDnsIP_A, httpDnsIP_4A]; + } else if ([httpDnsIP_A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@", httpDnsIP_A]; + } else if ([httpDnsIP_4A length] > 0) { + httpdnsIPs = [NSString stringWithFormat:@"%@", httpDnsIP_4A]; + } + [[AttaReport sharedInstance] reportEvent:@{ MSDKDns_ErrorCode: httpResolver.errorCode, @"eventName": self.origin, @@ -489,6 +504,8 @@ - (void)dnsTimeoutAttaUpload:(MSDKDnsResolver *)resolver { @"statusCode": @(httpResolver.statusCode), @"count": @1, @"isCache": @0, + @"ldns": localDnsIPs, + @"hdns": httpdnsIPs, }]; } } diff --git a/MSDKDns/Reporter/AttaReport.m b/MSDKDns/Reporter/AttaReport.m index 5c906b8..7e3e942 100644 --- a/MSDKDns/Reporter/AttaReport.m +++ b/MSDKDns/Reporter/AttaReport.m @@ -50,8 +50,13 @@ - (instancetype) init { NSURLSessionConfiguration *defaultSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; self.session = [NSURLSession sessionWithConfiguration:defaultSessionConfiguration delegate:nil delegateQueue:nil]; #ifdef httpdnsIps_h + #if IS_INTL + self.attaid = ATTAID_INTL; + self.token = ATTAToken_INTL; + #else self.attaid = ATTAID; self.token = ATTAToken; + #endif self.reportUrl = ATTAReportUrl; self.limit = ATTAReportDnsSpendLimit; self.interval = ATTAReportDnsSpendInterval; diff --git a/MSDKDns_C11_intl-Info.plist b/MSDKDns_C11_intl-Info.plist new file mode 100644 index 0000000..b5e186d --- /dev/null +++ b/MSDKDns_C11_intl-Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + $(MARKETING_VERSION) + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSHumanReadableCopyright + Copyright (c) Tencent. All rights reserved. + NSPrincipalClass + + + diff --git a/MSDKDns_intl-Info.plist b/MSDKDns_intl-Info.plist new file mode 100644 index 0000000..b5e186d --- /dev/null +++ b/MSDKDns_intl-Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + $(MARKETING_VERSION) + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSHumanReadableCopyright + Copyright (c) Tencent. All rights reserved. + NSPrincipalClass + + + From 1ce2da8bf9fb24fd849f6d405a14fbfbee61029f Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Wed, 23 Nov 2022 16:50:36 +0800 Subject: [PATCH 07/15] =?UTF-8?q?feat:=E6=9B=B4=E6=96=B0=E5=86=85=E6=B5=8B?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns.xcodeproj/project.pbxproj | 16 ++++++++-------- MSDKDns/MSDKDns.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 2f5fc6a..2a809ae 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -1047,7 +1047,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.1; + MARKETING_VERSION = 1.6.2; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1094,7 +1094,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.1; + MARKETING_VERSION = 1.6.2; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1136,7 +1136,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.1; + MARKETING_VERSION = 1.6.2; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1177,7 +1177,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.1; + MARKETING_VERSION = 1.6.2; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1226,7 +1226,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.1; + MARKETING_VERSION = 1.6.2; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1274,7 +1274,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.1; + MARKETING_VERSION = 1.6.2; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1312,7 +1312,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.1; + MARKETING_VERSION = 1.6.2; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1352,7 +1352,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.1; + MARKETING_VERSION = 1.6.2; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index fcf5ba6..8c83802 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -5,7 +5,7 @@ #ifndef __MSDKDns_H__ #define __MSDKDns_H__ -#define MSDKDns_Version @"1.6.1" +#define MSDKDns_Version @"1.6.2" #import From de3a6d33e031ad1e60dd3be6aa7f933f849525e1 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Thu, 1 Dec 2022 16:33:52 +0800 Subject: [PATCH 08/15] =?UTF-8?q?feat:=E6=97=A5=E5=BF=97=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns.xcodeproj/project.pbxproj | 16 +++--- MSDKDns/MSDKDns.h | 2 +- MSDKDns/MSDKDns.m | 95 +++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 9 deletions(-) diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 2a809ae..8cbf173 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -1047,7 +1047,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1094,7 +1094,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1136,7 +1136,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1177,7 +1177,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1226,7 +1226,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1274,7 +1274,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1312,7 +1312,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1352,7 +1352,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index 8c83802..e03b7c4 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -5,7 +5,7 @@ #ifndef __MSDKDns_H__ #define __MSDKDns_H__ -#define MSDKDns_Version @"1.6.2" +#define MSDKDns_Version @"1.6.3" #import diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index 80ff779..8712e93 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -9,6 +9,11 @@ #import "MSDKDnsNetworkManager.h" #import "MSDKDnsInfoTool.h" #import "MSDKDnsParamsManager.h" +#if defined(__has_include) + #if __has_include("httpdnsIps.h") + #include "httpdnsIps.h" + #endif +#endif @interface MSDKDns () @@ -63,11 +68,101 @@ - (BOOL) initConfig:(DnsConfig *)config { } [[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableReport:config->enableReport]; [[MSDKDnsManager shareInstance] switchToMainServer]; + [self fetchConfig:config->dnsId MEncryptType:config->encryptType MDnsKey:config->dnsKey MToken:config->token]; self.msdkDnsReady = YES; MSDKDNSLOG(@"MSDKDns init success."); return YES; } +- (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptType MDnsKey:(NSString *)mdnsKey MToken:(NSString* )mdnsToken { + + NSString *ipAddress = @""; +#ifdef httpdnsIps_h +#if IS_INTL + ipAddress = MSDKDnsFetchConfigHttpUrl_INTL; +#else + ipAddress = MSDKDnsFetchConfigHttpUrl; +#endif +#endif + + NSString *protocol = @"http"; + NSString *alg = @"des"; + if (mdnsEncryptType == HttpDnsEncryptTypeAES) { + alg = @"aes"; + } else if (mdnsEncryptType == HttpDnsEncryptTypeHTTPS) { +#ifdef httpdnsIps_h +#if IS_INTL + ipAddress = @""; +#else + ipAddress = MSDKDnsFetchConfigHttpsUrl; +#endif +#endif + protocol = @"https"; + } + + NSString * urlStr = [NSString stringWithFormat:@"%@://%@/conf?id=%d&alg=%@", protocol, ipAddress, mdnsId, alg]; + + if (mdnsEncryptType == HttpDnsEncryptTypeHTTPS) { + urlStr = [NSString stringWithFormat:@"%@://%@/conf?token=%@", protocol, ipAddress, mdnsToken]; + } + +// NSLog(@"urlStr ==== %@", urlStr); + // NSURL *url = [NSURL URLWithString:@"http://182.254.60.40/conf?id=96157&alg=des"]; + NSURL *url = [NSURL URLWithString:urlStr]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + if (data && (error == nil)) { + // 网络访问成功,解析数据 + NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + if(![str isEqualToString:@""]){ +// NSLog(@"data is %@",str); + if (mdnsEncryptType != HttpDnsEncryptTypeHTTPS && mdnsKey && mdnsKey.length > 0) { + if (mdnsEncryptType == 0) { + str = [MSDKDnsInfoTool decryptUseDES:str key:mdnsKey]; + } else { + str = [MSDKDnsInfoTool decryptUseAES:str key:mdnsKey]; + } + } + NSDictionary *configDict = [self parseAllConfigString:str]; + if(configDict && [configDict objectForKey:@"log"]){ + NSString *logValue = [configDict objectForKey:@"log"]; + [[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableReport:[logValue isEqualToString:@"1"]?YES:NO]; + MSDKDNSLOG(@"Successfully get configuration.config data is %@, %@",str,configDict); + }else{ + MSDKDNSLOG(@"Failed to get configuration,error:%@",str); + } + }else { + // 数据为空暂时不做处理 + } + } else { + // 网络访问失败 + MSDKDNSLOG(@"Failed to get configuration,error:%@",error); + } + }]; + [dataTask resume]; +} + +//将获取到的配置string转换为数据字典格式 +- (NSDictionary *)parseAllConfigString:(NSString *)configString { + NSArray *array = [configString componentsSeparatedByString:@"|"]; + if (array && array.count >= 2) { + NSMutableDictionary *result = [NSMutableDictionary dictionary]; + for (int i = 0; i < array.count; i++) { + NSString *item = array[i]; + if(item){ + NSArray * itemArr = [item componentsSeparatedByString:@":"]; + if (itemArr && [itemArr count] == 2) { + NSString *key = itemArr[0]; + NSString *value = itemArr[1]; + [result setObject:value forKey:key]; + } + } + } + return result; + } + return nil; +} + - (BOOL) initConfigWithDictionary:(NSDictionary *)config { DnsConfig *conf = new DnsConfig(); conf->appId = [config objectForKey:@"appId"]; From 9f301367f6fe305981f14e084854423fe30f88de Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Thu, 1 Dec 2022 17:53:33 +0800 Subject: [PATCH 09/15] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0https=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=85=8D=E7=BD=AE=E8=AF=81=E4=B9=A6=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/MSDKDns.m | 64 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index 8712e93..e3df2e1 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -18,6 +18,7 @@ @interface MSDKDns () @property (assign, nonatomic) BOOL msdkDnsReady; +@property (strong, nonatomic) NSMutableURLRequest *request; @end @@ -109,8 +110,8 @@ - (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptTyp // NSLog(@"urlStr ==== %@", urlStr); // NSURL *url = [NSURL URLWithString:@"http://182.254.60.40/conf?id=96157&alg=des"]; NSURL *url = [NSURL URLWithString:urlStr]; - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; - NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + self.request = [NSMutableURLRequest requestWithURL:url]; + NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:self.request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { if (data && (error == nil)) { // 网络访问成功,解析数据 NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; @@ -129,7 +130,7 @@ - (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptTyp [[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableReport:[logValue isEqualToString:@"1"]?YES:NO]; MSDKDNSLOG(@"Successfully get configuration.config data is %@, %@",str,configDict); }else{ - MSDKDNSLOG(@"Failed to get configuration,error:%@",str); +// MSDKDNSLOG(@"Failed to get configuration,error:%@",str); } }else { // 数据为空暂时不做处理 @@ -142,6 +143,63 @@ - (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptTyp [dataTask resume]; } +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * __nullable credential))completionHandler { + if (!challenge) { + return; + } + + NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling; + NSURLCredential *credential = nil; + + //获取原始域名信息 + NSString *host = [[self.request allHTTPHeaderFields] objectForKey:@"host"]; + if (!host) { + host = self.request.URL.host; + } + if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { + if ([self evaluateServerTrust:challenge.protectionSpace.serverTrust forDomain:host]) { + disposition = NSURLSessionAuthChallengeUseCredential; + credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; + } else { + disposition = NSURLSessionAuthChallengePerformDefaultHandling; + } + } else { + disposition = NSURLSessionAuthChallengePerformDefaultHandling; + } + + // 对于其他的 challenges 直接使用默认的验证方案 + completionHandler(disposition,credential); +} + + +- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain { + /* + * 创建证书校验策略 + */ + NSMutableArray *policies = [NSMutableArray array]; + if (domain) { + [policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)]; + } else { + [policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()]; + } + + /* + * 绑定校验策略到服务端的证书上 + */ + SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies); + + /* + * 评估当前serverTrust是否可信任, + * 官方建议在result = kSecTrustResultUnspecified 或 kSecTrustResultProceed + * 的情况下serverTrust可以被验证通过,https://developer.apple.com/library/ios/technotes/tn2232/_index.html + * 关于SecTrustResultType的详细信息请参考SecTrust.h + */ + SecTrustResultType result; + SecTrustEvaluate(serverTrust, &result); + + return (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed); +} + //将获取到的配置string转换为数据字典格式 - (NSDictionary *)parseAllConfigString:(NSString *)configString { NSArray *array = [configString componentsSeparatedByString:@"|"]; From ca7be1ef7933113558c229a071def706099fec71 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Thu, 8 Dec 2022 20:07:34 +0800 Subject: [PATCH 10/15] =?UTF-8?q?feat:=E5=9F=9F=E5=90=8D=E6=8E=A5=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.h | 16 ++ MSDKDns/CacheManager/MSDKDnsManager.m | 263 ++++++++++++++++++- MSDKDns/CacheManager/MSDKDnsNetworkManager.m | 4 + MSDKDns/MSDKDns.h | 5 - MSDKDns/MSDKDns.m | 162 +----------- MSDKDns/MSDKDnsInfoTool.h | 9 +- MSDKDns/MSDKDnsInfoTool.m | 11 +- MSDKDns/MSDKDnsPrivate.h | 1 + MSDKDns/MSDKDnsService.h | 15 +- MSDKDns/MSDKDnsService.m | 111 +++++++- MSDKDns/Resolver/LocalDnsResolver.m | 2 +- 11 files changed, 404 insertions(+), 195 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.h b/MSDKDns/CacheManager/MSDKDnsManager.h index 7c8a8c3..c2795ea 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.h +++ b/MSDKDns/CacheManager/MSDKDnsManager.h @@ -5,6 +5,7 @@ #import #import #import "MSDKDnsPrivate.h" +#import "MSDKDns.h" #if defined(__has_include) #if __has_include() @@ -18,9 +19,16 @@ @class MSDKDnsService; +typedef enum { + net_undetected = 0, + net_detecting = 1, + net_detected = 2, +} HttpDnsSdkStatus; + @interface MSDKDnsManager : NSObject @property (strong, nonatomic, readonly) NSMutableDictionary * domainDict; +@property (assign, nonatomic, readonly) HttpDnsSdkStatus sdkStatus; + (instancetype)shareInstance; @@ -47,4 +55,12 @@ - (void)msdkDnsClearDomainsOpenDelayDispatch:(NSArray *)domains; - (NSMutableDictionary *)msdkDnsGetDomainISOpenDelayDispatch; - (void)loadIPsFromPersistCacheAsync; +/* + * 获取底层配置 + */ +- (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptType MDnsKey:(NSString *)mdnsKey MToken:(NSString* )mdnsToken; +/* + * 获取三网域名解析IP + */ +- (void)detectHttpDnsServers; @end diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index ba9ebe7..983aa78 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -5,7 +5,6 @@ #import "MSDKDnsManager.h" #import "MSDKDnsService.h" #import "MSDKDnsLog.h" -#import "MSDKDns.h" #import "MSDKDnsDB.h" #import "MSDKDnsInfoTool.h" #import "MSDKDnsParamsManager.h" @@ -27,6 +26,9 @@ @interface MSDKDnsManager () @property (nonatomic, assign, readwrite) BOOL waitToSwitch; // 防止连续多次切换 // 延迟记录字典,记录哪些域名已经开启了延迟解析请求 @property (strong, nonatomic, readwrite) NSMutableDictionary* domainISOpenDelayDispatch; +@property (nonatomic, assign, readwrite) HttpDnsSdkStatus sdkStatus; +@property (nonatomic, strong, readwrite) NSArray * dnsServers; +@property (strong, nonatomic) NSMutableURLRequest *request; @end @@ -59,6 +61,9 @@ - (instancetype) init { _serverIndex = 0; _firstFailTime = nil; _waitToSwitch = NO; + _serviceArray = [[NSMutableArray alloc] init]; + _sdkStatus = net_undetected; + _dnsServers = [self defaultServers]; } return self; } @@ -719,7 +724,7 @@ - (NSMutableDictionary *)formatParams:(BOOL)isFromCache Domain:(NSString *)domai NSString * localDnsTimeConsuming = @""; NSString * channel = @""; - NSDictionary * cacheDict = [[MSDKDnsManager shareInstance] domainDict]; + NSDictionary * cacheDict = [self domainDict]; if (cacheDict && domain) { NSDictionary * cacheInfo = cacheDict[domain]; if (cacheInfo) { @@ -946,12 +951,226 @@ - (BOOL)isDomainCacheExpired: (NSDictionary *)domainInfo { # pragma mark - servers + +- (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptType MDnsKey:(NSString *)mdnsKey MToken:(NSString* )mdnsToken { + + NSString *ipAddress = @""; +#ifdef httpdnsIps_h +#if IS_INTL + ipAddress = MSDKDnsFetchConfigHttpUrl_INTL; +#else + ipAddress = MSDKDnsFetchConfigHttpUrl; +#endif +#endif + + NSString *protocol = @"http"; + NSString *alg = @"des"; + if (mdnsEncryptType == HttpDnsEncryptTypeAES) { + alg = @"aes"; + } else if (mdnsEncryptType == HttpDnsEncryptTypeHTTPS) { +#ifdef httpdnsIps_h +#if IS_INTL + ipAddress = @""; +#else + ipAddress = MSDKDnsFetchConfigHttpsUrl; +#endif +#endif + protocol = @"https"; + } + + NSString * urlStr = [NSString stringWithFormat:@"%@://%@/conf?id=%d&alg=%@", protocol, ipAddress, mdnsId, alg]; + + if (mdnsEncryptType == HttpDnsEncryptTypeHTTPS) { + urlStr = [NSString stringWithFormat:@"%@://%@/conf?token=%@", protocol, ipAddress, mdnsToken]; + } + +// NSLog(@"urlStr ==== %@", urlStr); + // NSURL *url = [NSURL URLWithString:@"http://182.254.60.40/conf?id=96157&alg=des"]; + NSURL *url = [NSURL URLWithString:urlStr]; + self.request = [NSMutableURLRequest requestWithURL:url]; + NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:self.request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + if (data && (error == nil)) { + // 网络访问成功,解析数据 + NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + if(![str isEqualToString:@""]){ +// NSLog(@"data is %@",str); + if (mdnsEncryptType != HttpDnsEncryptTypeHTTPS && mdnsKey && mdnsKey.length > 0) { + if (mdnsEncryptType == 0) { + str = [MSDKDnsInfoTool decryptUseDES:str key:mdnsKey]; + } else { + str = [MSDKDnsInfoTool decryptUseAES:str key:mdnsKey]; + } + } + NSDictionary *configDict = [self parseAllConfigString:str]; + if(configDict && [configDict objectForKey:@"log"]){ + NSString *logValue = [configDict objectForKey:@"log"]; + [[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableReport:[logValue isEqualToString:@"1"]?YES:NO]; + MSDKDNSLOG(@"Successfully get configuration.config data is %@, %@",str,configDict); + }else{ +// MSDKDNSLOG(@"Failed to get configuration,error:%@",str); + } + }else { + // 数据为空暂时不做处理 + } + } else { + // 网络访问失败 + MSDKDNSLOG(@"Failed to get configuration,error:%@",error); + } + }]; + [dataTask resume]; +} + +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * __nullable credential))completionHandler { + if (!challenge) { + return; + } + + NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling; + NSURLCredential *credential = nil; + + //获取原始域名信息 + NSString *host = [[self.request allHTTPHeaderFields] objectForKey:@"host"]; + if (!host) { + host = self.request.URL.host; + } + if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { + if ([self evaluateServerTrust:challenge.protectionSpace.serverTrust forDomain:host]) { + disposition = NSURLSessionAuthChallengeUseCredential; + credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; + } else { + disposition = NSURLSessionAuthChallengePerformDefaultHandling; + } + } else { + disposition = NSURLSessionAuthChallengePerformDefaultHandling; + } + + // 对于其他的 challenges 直接使用默认的验证方案 + completionHandler(disposition,credential); +} + + +- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain { + /* + * 创建证书校验策略 + */ + NSMutableArray *policies = [NSMutableArray array]; + if (domain) { + [policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)]; + } else { + [policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()]; + } + + /* + * 绑定校验策略到服务端的证书上 + */ + SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies); + + /* + * 评估当前serverTrust是否可信任, + * 官方建议在result = kSecTrustResultUnspecified 或 kSecTrustResultProceed + * 的情况下serverTrust可以被验证通过,https://developer.apple.com/library/ios/technotes/tn2232/_index.html + * 关于SecTrustResultType的详细信息请参考SecTrust.h + */ + SecTrustResultType result; + SecTrustEvaluate(serverTrust, &result); + + return (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed); +} + +//将获取到的配置string转换为数据字典格式 +- (NSDictionary *)parseAllConfigString:(NSString *)configString { + NSArray *array = [configString componentsSeparatedByString:@"|"]; + if (array && array.count >= 2) { + NSMutableDictionary *result = [NSMutableDictionary dictionary]; + for (int i = 0; i < array.count; i++) { + NSString *item = array[i]; + if(item){ + NSArray * itemArr = [item componentsSeparatedByString:@":"]; + if (itemArr && [itemArr count] == 2) { + NSString *key = itemArr[0]; + NSString *value = itemArr[1]; + [result setObject:value forKey:key]; + } + } + } + return result; + } + return nil; +} + +- (void)detectHttpDnsServers { + // 先重置为兜底ip + [self resetDnsServers:nil]; + // https 协议下不进行三网探测 + if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEncryptType] == HttpDnsEncryptTypeHTTPS) { + return; + } + dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ + NSString *domain = @""; + int dnsId = 0; + NSString *dnsKey = @""; +#ifdef httpdnsIps_h + #if IS_INTL + domain = MSDKDnsServerDomain_INTL; + #else + domain = MSDKDnsServerDomain; + #endif + dnsId = MSDKDnsId; + dnsKey = MSDKDnsKey; +#endif + if (![domain isEqualToString:@""] && dnsId != 0 && ![dnsKey isEqualToString:@""]) { + NSArray *domains = @[domain]; + msdkdns::MSDKDNS_TLocalIPStack netStack = [self detectAddressType]; + BOOL httpOnly = true; + HttpDnsEncryptType encryptType = HttpDnsEncryptTypeDES; + MSDKDnsService * dnsService = [[MSDKDnsService alloc] init]; + __weak __typeof__(self) weakSelf = self; + self.sdkStatus = net_detecting; + [dnsService getHttpDNSDomainIPsByNames:domains + TimeOut:2000 + DnsId:dnsId + DnsKey:dnsKey + NetStack:netStack + encryptType:encryptType + httpOnly:httpOnly + from:MSDKDnsEventHttpDnsGetHTTPDNSDomainIP + returnIps:^{ + __strong __typeof(self) strongSelf = weakSelf; + if (strongSelf) { + [strongSelf uploadReport:NO Domain:domain NetStack:netStack]; + NSDictionary * result = [strongSelf fullResultDictionary:domains fromCache:self.domainDict]; + NSDictionary *ips = [result objectForKey:domain]; + NSLog(@"ips === %@", ips); + NSArray *ipv4s = [ips objectForKey:@"ipv4"]; + NSArray *ipv6s = [ips objectForKey:@"ipv6"]; + if (ipv4s && [ipv4s count] > 0) { + [self resetDnsServers:ipv4s]; + self.sdkStatus = net_detected; + } else if (ipv6s && [ipv6s count] > 0) { + [self resetDnsServers:ipv6s]; + self.sdkStatus = net_detected; + } else { + self.sdkStatus = net_undetected; + } + } + }]; + } else { + MSDKDNSLOG(@"三网解析域名、dnsId或者dnsKey配置为空."); + } + }); +} + - (NSString *)currentDnsServer { + // int index = self.serverIndex; + // if (index < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count]) { + // return [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] objectAtIndex:index]; + // } + // return [[MSDKDnsParamsManager shareInstance] msdkDnsGetMDnsIp]; int index = self.serverIndex; - if (index < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count]) { - return [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] objectAtIndex:index]; + if (index < [self.dnsServers count]) { + return [self.dnsServers objectAtIndex:index]; } - return [[MSDKDnsParamsManager shareInstance] msdkDnsGetMDnsIp]; + return [[self defaultServers] firstObject]; } - (void)switchDnsServer { @@ -960,7 +1179,7 @@ - (void)switchDnsServer { } self.waitToSwitch = YES; dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - if (self.serverIndex < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count] - 1) { + if (self.serverIndex < [self.dnsServers count] - 1) { self.serverIndex += 1; if (!self.firstFailTime) { self.firstFailTime = [NSDate date]; @@ -995,6 +1214,38 @@ - (void)switchToMainServer { }); } +- (void)resetDnsServers:(NSArray *)servers { + self.waitToSwitch = YES; + dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ + NSMutableArray *array = [[NSMutableArray alloc] init]; + if (servers && [servers count] > 0) { + [array addObjectsFromArray: servers]; + } + [array addObjectsFromArray:[self defaultServers]]; + self.serverIndex = 0; + self.dnsServers = array; + self.waitToSwitch = NO; + }); +} + +- (NSArray *)defaultServers { + NSMutableArray *servers = [[NSMutableArray alloc] init]; +#ifdef httpdnsIps_h + #if IS_INTL + if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEncryptType] != HttpDnsEncryptTypeHTTPS) { + [servers addObjectsFromArray: MSDKDnsHttpServerIps_INTL]; + } + #else + if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEncryptType] == HttpDnsEncryptTypeHTTPS) { + [servers addObjectsFromArray: MSDKDnsHttpsServerIps]; + } else { + [servers addObjectsFromArray: MSDKDnsHttpServerIps]; + } + #endif +#endif + return servers; +} + # pragma mark - operate delay tag - (void)msdkDnsAddDomainOpenDelayDispatch: (NSString *)domain { diff --git a/MSDKDns/CacheManager/MSDKDnsNetworkManager.m b/MSDKDns/CacheManager/MSDKDnsNetworkManager.m index 39ff4a2..0acefe0 100644 --- a/MSDKDns/CacheManager/MSDKDnsNetworkManager.m +++ b/MSDKDns/CacheManager/MSDKDnsNetworkManager.m @@ -79,6 +79,8 @@ - (instancetype)init [self getHostsByKeepAliveDomains]; //重置ip指针 [[MSDKDnsManager shareInstance] switchToMainServer]; + // 探测dnsIp + [[MSDKDnsManager shareInstance] detectHttpDnsServers]; }]; [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationDidEnterBackgroundNotification @@ -104,6 +106,8 @@ - (instancetype)init [self.reachability startNotifier]; //对保活域名发送解析请求 [self getHostsByKeepAliveDomains]; + // 探测dnsIp + [[MSDKDnsManager shareInstance] detectHttpDnsServers]; }]; _reachability = [MSDKDnsReachability reachabilityForInternetConnection]; diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index e03b7c4..217bf13 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -69,11 +69,6 @@ typedef struct DnsConfigStruct { */ - (BOOL) WGSetDnsOpenId:(NSString *)openId; -/** - * 设置 httpdns 备份服务器ip(无需手动设置,sdk 会自动设置) - */ -- (void) WGSetDnsBackupServerIps:(NSArray *)ips; - /** * 设置预解析的域名,设置的域名会在sdk初始化完成后自动进行解析 */ diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index e3df2e1..86f4417 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -17,9 +17,6 @@ @interface MSDKDns () -@property (assign, nonatomic) BOOL msdkDnsReady; -@property (strong, nonatomic) NSMutableURLRequest *request; - @end @implementation MSDKDns @@ -37,7 +34,6 @@ + (instancetype) sharedInstance { - (instancetype) init { if (self = [super init]) { - _msdkDnsReady = NO; //开启网络切换,及前后台切换的监听 [MSDKDnsNetworkManager start]; } @@ -47,7 +43,7 @@ - (instancetype) init { - (BOOL) initConfig:(DnsConfig *)config { #if IS_INTL if (config->encryptType == HttpDnsEncryptTypeHTTPS) { - //开启了使用过期缓存功能,给出提示建议使用同步接口进行解析 + //国际站SDK不能进行HTTPS解析,直接报错提示用户 @throw [NSException exceptionWithName:@"MSDKDns wrong use of encryptType" reason:@"HttpDnsEncryptTypeHTTPS cannot be used because httpdns-sdk-intl version still doesn't support, it is recommended to use HttpDnsEncryptTypeDES or HttpDnsEncryptTypeAES" userInfo:nil]; @@ -68,159 +64,12 @@ - (BOOL) initConfig:(DnsConfig *)config { [[MSDKDnsParamsManager shareInstance] msdkDnsSetMinutesBeforeSwitchToMain:config->minutesBeforeSwitchToMain]; } [[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableReport:config->enableReport]; - [[MSDKDnsManager shareInstance] switchToMainServer]; - [self fetchConfig:config->dnsId MEncryptType:config->encryptType MDnsKey:config->dnsKey MToken:config->token]; - self.msdkDnsReady = YES; + [[MSDKDnsManager shareInstance] detectHttpDnsServers]; + [[MSDKDnsManager shareInstance] fetchConfig:config->dnsId MEncryptType:config->encryptType MDnsKey:config->dnsKey MToken:config->token]; MSDKDNSLOG(@"MSDKDns init success."); return YES; } -- (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptType MDnsKey:(NSString *)mdnsKey MToken:(NSString* )mdnsToken { - - NSString *ipAddress = @""; -#ifdef httpdnsIps_h -#if IS_INTL - ipAddress = MSDKDnsFetchConfigHttpUrl_INTL; -#else - ipAddress = MSDKDnsFetchConfigHttpUrl; -#endif -#endif - - NSString *protocol = @"http"; - NSString *alg = @"des"; - if (mdnsEncryptType == HttpDnsEncryptTypeAES) { - alg = @"aes"; - } else if (mdnsEncryptType == HttpDnsEncryptTypeHTTPS) { -#ifdef httpdnsIps_h -#if IS_INTL - ipAddress = @""; -#else - ipAddress = MSDKDnsFetchConfigHttpsUrl; -#endif -#endif - protocol = @"https"; - } - - NSString * urlStr = [NSString stringWithFormat:@"%@://%@/conf?id=%d&alg=%@", protocol, ipAddress, mdnsId, alg]; - - if (mdnsEncryptType == HttpDnsEncryptTypeHTTPS) { - urlStr = [NSString stringWithFormat:@"%@://%@/conf?token=%@", protocol, ipAddress, mdnsToken]; - } - -// NSLog(@"urlStr ==== %@", urlStr); - // NSURL *url = [NSURL URLWithString:@"http://182.254.60.40/conf?id=96157&alg=des"]; - NSURL *url = [NSURL URLWithString:urlStr]; - self.request = [NSMutableURLRequest requestWithURL:url]; - NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:self.request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { - if (data && (error == nil)) { - // 网络访问成功,解析数据 - NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - if(![str isEqualToString:@""]){ -// NSLog(@"data is %@",str); - if (mdnsEncryptType != HttpDnsEncryptTypeHTTPS && mdnsKey && mdnsKey.length > 0) { - if (mdnsEncryptType == 0) { - str = [MSDKDnsInfoTool decryptUseDES:str key:mdnsKey]; - } else { - str = [MSDKDnsInfoTool decryptUseAES:str key:mdnsKey]; - } - } - NSDictionary *configDict = [self parseAllConfigString:str]; - if(configDict && [configDict objectForKey:@"log"]){ - NSString *logValue = [configDict objectForKey:@"log"]; - [[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableReport:[logValue isEqualToString:@"1"]?YES:NO]; - MSDKDNSLOG(@"Successfully get configuration.config data is %@, %@",str,configDict); - }else{ -// MSDKDNSLOG(@"Failed to get configuration,error:%@",str); - } - }else { - // 数据为空暂时不做处理 - } - } else { - // 网络访问失败 - MSDKDNSLOG(@"Failed to get configuration,error:%@",error); - } - }]; - [dataTask resume]; -} - -- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * __nullable credential))completionHandler { - if (!challenge) { - return; - } - - NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling; - NSURLCredential *credential = nil; - - //获取原始域名信息 - NSString *host = [[self.request allHTTPHeaderFields] objectForKey:@"host"]; - if (!host) { - host = self.request.URL.host; - } - if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { - if ([self evaluateServerTrust:challenge.protectionSpace.serverTrust forDomain:host]) { - disposition = NSURLSessionAuthChallengeUseCredential; - credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; - } else { - disposition = NSURLSessionAuthChallengePerformDefaultHandling; - } - } else { - disposition = NSURLSessionAuthChallengePerformDefaultHandling; - } - - // 对于其他的 challenges 直接使用默认的验证方案 - completionHandler(disposition,credential); -} - - -- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain { - /* - * 创建证书校验策略 - */ - NSMutableArray *policies = [NSMutableArray array]; - if (domain) { - [policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)]; - } else { - [policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()]; - } - - /* - * 绑定校验策略到服务端的证书上 - */ - SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies); - - /* - * 评估当前serverTrust是否可信任, - * 官方建议在result = kSecTrustResultUnspecified 或 kSecTrustResultProceed - * 的情况下serverTrust可以被验证通过,https://developer.apple.com/library/ios/technotes/tn2232/_index.html - * 关于SecTrustResultType的详细信息请参考SecTrust.h - */ - SecTrustResultType result; - SecTrustEvaluate(serverTrust, &result); - - return (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed); -} - -//将获取到的配置string转换为数据字典格式 -- (NSDictionary *)parseAllConfigString:(NSString *)configString { - NSArray *array = [configString componentsSeparatedByString:@"|"]; - if (array && array.count >= 2) { - NSMutableDictionary *result = [NSMutableDictionary dictionary]; - for (int i = 0; i < array.count; i++) { - NSString *item = array[i]; - if(item){ - NSArray * itemArr = [item componentsSeparatedByString:@":"]; - if (itemArr && [itemArr count] == 2) { - NSString *key = itemArr[0]; - NSString *value = itemArr[1]; - [result setObject:value forKey:key]; - } - } - } - return result; - } - return nil; -} - - (BOOL) initConfigWithDictionary:(NSDictionary *)config { DnsConfig *conf = new DnsConfig(); conf->appId = [config objectForKey:@"appId"]; @@ -252,11 +101,6 @@ - (BOOL) WGSetDnsOpenId:(NSString *)openId { return YES; } -- (void) WGSetDnsBackupServerIps:(NSArray *)ips { - [[MSDKDnsParamsManager shareInstance] msdkDnsSetBackupServerIps:ips]; - [[MSDKDnsManager shareInstance] switchToMainServer]; -} - - (void) WGSetPreResolvedDomains:(NSArray *)domains { [[MSDKDnsParamsManager shareInstance] msdkDnsSetPreResolvedDomains:domains]; [[MSDKDnsManager shareInstance] preResolveDomains]; diff --git a/MSDKDns/MSDKDnsInfoTool.h b/MSDKDns/MSDKDnsInfoTool.h index f2dffa6..06b43c8 100644 --- a/MSDKDns/MSDKDnsInfoTool.h +++ b/MSDKDns/MSDKDnsInfoTool.h @@ -10,7 +10,6 @@ + (dispatch_queue_t) msdkdns_queue; + (dispatch_queue_t) msdkdns_resolver_queue; + (dispatch_queue_t) msdkdns_local_queue; -+ (dispatch_queue_t) msdkdns_retry_queue; + (NSString *) wifiSSID; + (NSString *) encryptUseDES:(NSString *)plainText key:(NSString *)key; @@ -21,4 +20,12 @@ + (NSString *)decryptUseAES:(NSString *)cipherString key:(NSString *)key; + (NSURL *) httpsUrlWithDomain:(NSString *)domain DnsId:(int)dnsId DnsKey:(NSString *)dnsKey IPType:(HttpDnsIPType)ipType encryptType:(NSInteger)encryptType; //encryptType: 0 des,1 aes + (NSString *)generateSessionID; ++ (NSURL *) httpsUrlWithDomain:(NSString *)domain + DnsId:(int)dnsId + serverIp:(NSString*)serverIp + routeIp:(NSString*)routeIp + DnsKey:(NSString *)dnsKey + DnsToken:(NSString*)token + Use4A:(BOOL)use4A + encryptType:(NSInteger)encryptType; //encryptType: 0 des,1 aes @end diff --git a/MSDKDns/MSDKDnsInfoTool.m b/MSDKDns/MSDKDnsInfoTool.m index aa23845..a0017ba 100644 --- a/MSDKDns/MSDKDnsInfoTool.m +++ b/MSDKDns/MSDKDnsInfoTool.m @@ -45,15 +45,6 @@ + (dispatch_queue_t) msdkdns_local_queue { return msdkdns_local_queue; } -+ (dispatch_queue_t) msdkdns_retry_queue { - static dispatch_queue_t msdkdns_retry_queue; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - msdkdns_retry_queue = dispatch_queue_create("com.tencent.msdkdns.retry_queue", DISPATCH_QUEUE_SERIAL); - }); - return msdkdns_retry_queue; -} - + (NSString *) getIPv6: (const char *)mHost { if (NULL == mHost) return nil; @@ -444,6 +435,8 @@ + (NSURL *) httpsUrlWithDomain:(NSString *)domain DnsId:(int)dnsId DnsKey:(NSStr urlStr = [urlStr stringByAppendingFormat:@"&alg=aes"]; } else if (encryptType == HttpDnsEncryptTypeHTTPS) { urlStr = [urlStr stringByAppendingFormat:@"&token=%@", token]; + } else if (encryptType == HttpDnsEncryptTypeDES){ + urlStr = [urlStr stringByAppendingFormat:@"&alg=des"]; } if (routeIp && routeIp.length > 0) { urlStr = [urlStr stringByAppendingFormat:@"&ip=%@", routeIp]; diff --git a/MSDKDns/MSDKDnsPrivate.h b/MSDKDns/MSDKDnsPrivate.h index e4bb4b2..f10949a 100644 --- a/MSDKDns/MSDKDnsPrivate.h +++ b/MSDKDns/MSDKDnsPrivate.h @@ -76,6 +76,7 @@ static NSString * const MSDKDnsEventHttpDnsCached = @"HDNSLookupCached"; static NSString * const MSDKDnsEventHttpDnsNormal = @"HDNSGetHostByName"; //常规解析请求 static NSString * const MSDKDnsEventHttpDnsPreResolved = @"HDNSPreLookup"; //预解析请求 static NSString * const MSDKDnsEventHttpDnsAutoRefresh = @"HDNSLookupAsync"; //缓存自动刷新 +static NSString * const MSDKDnsEventHttpDnsGetHTTPDNSDomainIP = @"HDNSGetDomainIP"; //获取三网域名的IP //命中缓存的状态 static NSString * const MSDKDnsDomainCacheHit = @"domainCacheHit"; //命中缓存 diff --git a/MSDKDns/MSDKDnsService.h b/MSDKDns/MSDKDnsService.h index 1ed7f70..2ce1a9d 100644 --- a/MSDKDns/MSDKDnsService.h +++ b/MSDKDns/MSDKDnsService.h @@ -7,10 +7,21 @@ @interface MSDKDnsService : NSObject -- (void)getHostByName:(NSString *)domain TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType returnIps:(void (^)())handler; - - (void)getHostsByNames:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType returnIps:(void (^)())handler; - (void)getHostsByNames:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType from:(NSString *)origin returnIps:(void (^)())handler; +/** + * 获取三网域名的IP地址 + */ +- (void)getHttpDNSDomainIPsByNames:(NSArray *)domains + TimeOut:(float)timeOut + DnsId:(int)dnsId + DnsKey:(NSString *)dnsKey + NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack + encryptType:(NSInteger)encryptType + httpOnly:(BOOL)httpOnly + from:(NSString *)origin + returnIps:(void (^)())handler; + @end diff --git a/MSDKDns/MSDKDnsService.m b/MSDKDns/MSDKDnsService.m index e95f1c6..38395e1 100644 --- a/MSDKDns/MSDKDnsService.m +++ b/MSDKDns/MSDKDnsService.m @@ -28,9 +28,15 @@ @interface MSDKDnsService () @property (nonatomic, assign) int httpdnsFailCount; @property (nonatomic, assign) float timeOut; @property (nonatomic, assign) int dnsId; +@property (nonatomic, strong) NSString* dnsServer; +@property (nonatomic, strong) NSString* dnsRouter; @property (nonatomic, strong) NSString* dnsKey; @property (nonatomic, strong) NSString* origin; +@property (nonatomic, strong) NSString* dnsToken; @property (nonatomic, assign) NSUInteger encryptType; +@property (nonatomic, assign) BOOL httpOnly; +@property (nonatomic, assign) BOOL enableReport; +@property (nonatomic, assign) NSUInteger retryCount; @end @implementation MSDKDnsService @@ -43,12 +49,6 @@ - (void)dealloc { [self setCompletionHandler:nil]; } - -- (void)getHostByName:(NSString *)domain TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType returnIps:(void (^)())handler -{ - [self getHostsByNames:@[domain] TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType returnIps:handler]; -} - - (void)getHostsByNames:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack encryptType:(NSInteger)encryptType returnIps:(void (^)())handler { [self getHostsByNames:domains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType from:MSDKDnsEventHttpDnsNormal returnIps:handler]; @@ -61,9 +61,35 @@ - (void)getHostsByNames:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dns self.isCallBack = NO; self.netStack = netStack; self.origin = origin; + self.httpdnsFailCount = 0; [self startCheck:timeOut DnsId:dnsId DnsKey:dnsKey encryptType:encryptType]; } +- (void)getHttpDNSDomainIPsByNames:(NSArray *)domains + TimeOut:(float)timeOut + DnsId:(int)dnsId + DnsKey:(NSString *)dnsKey + NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack + encryptType:(NSInteger)encryptType + httpOnly:(BOOL)httpOnly + from:(NSString *)origin + returnIps:(void (^)())handler { + self.completionHandler = handler; + self.toCheckDomains = domains; + self.isCallBack = NO; + self.netStack = netStack; + self.origin = origin; + self.httpdnsFailCount = 0; + + self.timeOut = timeOut; + self.dnsId = dnsId; + self.dnsKey = dnsKey; + self.encryptType = encryptType; + self.httpOnly = httpOnly; + + [self startCheck]; +} + #pragma mark - startCheck - (void)startCheck:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey encryptType:(NSInteger)encryptType @@ -122,6 +148,55 @@ - (void)startCheck:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey enc }); } +- (void)startCheck { + MSDKDNSLOG(@"%@, MSDKDns startCheck", self.toCheckDomains); + //查询前清除缓存 + [[MSDKDnsManager shareInstance] clearCacheForDomains:self.toCheckDomains]; + + //无网络直接返回 + if (![[MSDKDnsNetworkManager shareInstance] networkAvailable]) { + MSDKDNSLOG(@"No network,please check your network setting!"); + [self callNotify]; + return; + } + + if (_netStack == msdkdns::MSDKDNS_ELocalIPStack_None) { + MSDKDNSLOG(@"No network stack, please check your network setting!"); + [self callNotify]; + return; + } + + if (_netStack == msdkdns::MSDKDNS_ELocalIPStack_IPv6) { + dispatch_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ + [self startHttpDns_4A:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; + }); + } + + if (_netStack == msdkdns::MSDKDNS_ELocalIPStack_IPv4) { + dispatch_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ + [self startHttpDns:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; + }); + } + + if (_netStack == msdkdns::MSDKDNS_ELocalIPStack_Dual) { + dispatch_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ + [self startHttpDnsBoth:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; + }); + } + + if (!self.httpOnly) { + dispatch_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ + [self startLocalDns:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey]; + }); + } + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, self.timeOut * NSEC_PER_SEC), [MSDKDnsInfoTool msdkdns_queue], ^{ + if(!self.isCallBack) { + MSDKDNSLOG(@"DnsService TimeOut!"); + [self callNotify]; + } + }); +} + //进行httpdns ipv4和ipv6合并请求 - (void)startHttpDnsBoth:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey encryptType:(NSInteger)encryptType { @@ -164,7 +239,11 @@ - (void)resolver:(MSDKDnsResolver *)resolver didGetDomainInfo:(NSDictionary *)do // 结果存缓存 dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ [self cacheDomainInfo:resolver]; - NSDictionary * info = @{kDnsErrCode:MSDKDns_Success, kDnsErrMsg:@"", kDnsRetry:@"0"}; + NSDictionary * info = @{ + kDnsErrCode:MSDKDns_Success, + kDnsErrMsg:@"", + kDnsRetry: @(self.httpdnsFailCount) + }; [self callBack:resolver Info:info]; if (resolver == self.httpDnsResolver_A || resolver == self.httpDnsResolver_4A || resolver == self.httpDnsResolver_BOTH) { NSArray *keepAliveDomains = [[MSDKDnsParamsManager shareInstance] msdkDnsGetKeepAliveDomains]; @@ -454,7 +533,11 @@ - (void)resolver:(MSDKDnsResolver *)resolver getDomainError:(NSString *)error re [self retryHttpDns:resolver]; } else { dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - NSDictionary * info = @{kDnsErrCode:MSDKDns_UnResolve, kDnsErrMsg:@"", kDnsRetry:@"0"}; + NSDictionary * info = @{ + kDnsErrCode:MSDKDns_Fail, + kDnsErrMsg:error ? error : @"", + kDnsRetry:@(self.httpdnsFailCount) + }; [self callBack:resolver Info:info]; }); [self dnsTimeoutAttaUpload:resolver]; @@ -516,15 +599,15 @@ - (void) retryHttpDns:(MSDKDnsResolver *)resolver { self.httpdnsFailCount += 1; if (self.httpdnsFailCount < [[MSDKDnsParamsManager shareInstance] msdkDnsGetRetryTimesBeforeSwitchServer]) { if (resolver == self.httpDnsResolver_A) { - dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ + dispatch_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ [self startHttpDns:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; }); } else if (resolver == self.httpDnsResolver_4A) { - dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ + dispatch_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ [self startHttpDns_4A:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; }); } else if (resolver == self.httpDnsResolver_BOTH) { - dispatch_async([MSDKDnsInfoTool msdkdns_retry_queue], ^{ + dispatch_async([MSDKDnsInfoTool msdkdns_resolver_queue], ^{ [self startHttpDnsBoth:self.timeOut DnsId:self.dnsId DnsKey:self.dnsKey encryptType:self.encryptType]; }); } @@ -532,7 +615,11 @@ - (void) retryHttpDns:(MSDKDnsResolver *)resolver { MSDKDNSLOG(@"fail %lu times, switch server!", (unsigned long)[[MSDKDnsParamsManager shareInstance] msdkDnsGetRetryTimesBeforeSwitchServer]); // 失败超过三次,返回错误结果并切换备份ip dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - NSDictionary * info = @{kDnsErrCode:MSDKDns_UnResolve, kDnsErrMsg:@"", kDnsRetry:@"0"}; + NSDictionary * info = @{ + kDnsErrCode:MSDKDns_UnResolve, + kDnsErrMsg:[NSString stringWithFormat:@"request fail %lu times", (unsigned long)[[MSDKDnsParamsManager shareInstance] msdkDnsGetRetryTimesBeforeSwitchServer]], + kDnsRetry:@(self.httpdnsFailCount) + }; [self callBack:resolver Info:info]; }); [self dnsTimeoutAttaUpload:resolver]; diff --git a/MSDKDns/Resolver/LocalDnsResolver.m b/MSDKDns/Resolver/LocalDnsResolver.m index 9db3600..43ca7ec 100644 --- a/MSDKDns/Resolver/LocalDnsResolver.m +++ b/MSDKDns/Resolver/LocalDnsResolver.m @@ -65,7 +65,7 @@ - (void)localDnsTimeout { self.isSucceed = NO; self.errorInfo = @"LocalDns timeout"; if (self.delegate && [self.delegate respondsToSelector:@selector(resolver:getDomainError:retry:)]) { - [self.delegate resolver:self getDomainError:nil retry:NO]; + [self.delegate resolver:self getDomainError:self.errorInfo retry:NO]; } } } From 42022695a9cb216b49373bdfc74d95d0820098d0 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Wed, 21 Dec 2022 15:30:06 +0800 Subject: [PATCH 11/15] =?UTF-8?q?feat:=E6=94=AF=E6=8C=81=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E4=B8=89=E7=BD=91=E5=9F=9F=E5=90=8D=E9=80=9A=E8=BF=87=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=8F=B0=E5=BC=80=E5=85=B3=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.m | 18 +++++++++++++++++- MSDKDns/CacheManager/MSDKDnsNetworkManager.m | 18 ++++++++++++++---- MSDKDns/CacheManager/MSDKDnsParamsManager.h | 2 ++ MSDKDns/CacheManager/MSDKDnsParamsManager.m | 12 ++++++++++++ MSDKDns/MSDKDns.m | 1 - MSDKDns/MSDKDnsPrivate.h | 1 + MSDKDns/Resolver/LocalDnsResolver.m | 2 +- 7 files changed, 47 insertions(+), 7 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 983aa78..cf1ca54 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -1009,6 +1009,21 @@ - (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptTyp }else{ // MSDKDNSLOG(@"Failed to get configuration,error:%@",str); } + // NSLog(@"configDict = %@",configDict); +// 暂时测试,默认开启探测三网域名IP + [[MSDKDnsManager shareInstance] detectHttpDnsServers]; + if(configDict && [configDict objectForKey:@"domain"]){ + NSString *domainValue = [configDict objectForKey:@"domain"]; + if ([domainValue isEqualToString:@"1"]) { + [[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableDetectHostServer:YES]; + [[MSDKDnsManager shareInstance] detectHttpDnsServers]; + } + // MSDKDNSLOG(@"Successfully get configuration.config data is %@, %@",str,configDict); + }else{ + // MSDKDNSLOG(@"Failed to get configuration,error:%@",str); + } + + }else { // 数据为空暂时不做处理 } @@ -1125,9 +1140,10 @@ - (void)detectHttpDnsServers { HttpDnsEncryptType encryptType = HttpDnsEncryptTypeDES; MSDKDnsService * dnsService = [[MSDKDnsService alloc] init]; __weak __typeof__(self) weakSelf = self; + __block float timeOut = 2.0; self.sdkStatus = net_detecting; [dnsService getHttpDNSDomainIPsByNames:domains - TimeOut:2000 + TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack diff --git a/MSDKDns/CacheManager/MSDKDnsNetworkManager.m b/MSDKDns/CacheManager/MSDKDnsNetworkManager.m index 0acefe0..8d2580b 100644 --- a/MSDKDns/CacheManager/MSDKDnsNetworkManager.m +++ b/MSDKDns/CacheManager/MSDKDnsNetworkManager.m @@ -79,8 +79,14 @@ - (instancetype)init [self getHostsByKeepAliveDomains]; //重置ip指针 [[MSDKDnsManager shareInstance] switchToMainServer]; - // 探测dnsIp - [[MSDKDnsManager shareInstance] detectHttpDnsServers]; + + BOOL enableDetectHostServer = [[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableDetectHostServer]; + if (!enableDetectHostServer) { + MSDKDNSLOG(@"Network did changed, detect HttpDns servers"); + // 探测dnsIp + [[MSDKDnsManager shareInstance] detectHttpDnsServers]; + } + }]; [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationDidEnterBackgroundNotification @@ -106,8 +112,12 @@ - (instancetype)init [self.reachability startNotifier]; //对保活域名发送解析请求 [self getHostsByKeepAliveDomains]; - // 探测dnsIp - [[MSDKDnsManager shareInstance] detectHttpDnsServers]; + + BOOL enableDetectHostServer = [[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableDetectHostServer]; + if (!enableDetectHostServer) { + // 探测dnsIp + [[MSDKDnsManager shareInstance] detectHttpDnsServers]; + } }]; _reachability = [MSDKDnsReachability reachabilityForInternetConnection]; diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.h b/MSDKDns/CacheManager/MSDKDnsParamsManager.h index 08bec4a..8b55a5e 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.h +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.h @@ -25,6 +25,7 @@ // 设置备份ip - (void)msdkDnsSetBackupServerIps: (NSArray *)ips; - (void)msdkDnsSetEnableReport: (BOOL)enableReport; +- (void)msdkDnsSetEnableDetectHostServer: (BOOL)enableDetectHostServer; - (void)msdkDnsSetPreResolvedDomains: (NSArray *)domains; - (void)msdkDnsSetAddressType: (HttpDnsAddressType)addressType; - (void)msdkDnsSetKeepAliveDomains: (NSArray *)domains; @@ -47,6 +48,7 @@ - (NSUInteger)msdkDnsGetRetryTimesBeforeSwitchServer; - (NSUInteger)msdkDnsGetMinutesBeforeSwitchToMain; - (BOOL)msdkDnsGetEnableReport; +- (BOOL)msdkDnsGetEnableDetectHostServer; - (NSArray *)msdkDnsGetPreResolvedDomains; - (HttpDnsAddressType)msdkDnsGetAddressType; - (NSArray *)msdkDnsGetKeepAliveDomains; diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.m b/MSDKDns/CacheManager/MSDKDnsParamsManager.m index 2877bc0..5487e72 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.m @@ -37,6 +37,7 @@ @interface MSDKDnsParamsManager() @property (assign, nonatomic, readwrite) BOOL enableKeepDomainsAlive; @property (assign, nonatomic, readwrite) BOOL expiredIPEnabled; @property (assign, nonatomic, readwrite) BOOL persistCacheIPEnabled; +@property (assign, nonatomic, readwrite) BOOL enableDetectHostServer; @end @@ -62,6 +63,7 @@ - (id) init { _msdkAddressType = HttpDnsAddressTypeAuto; _enableKeepDomainsAlive = YES; _expiredIPEnabled = NO; + _enableDetectHostServer = NO; } return self; } @@ -158,6 +160,12 @@ - (void)msdkDnsSetEnableReport: (BOOL)enableReport { }); } +- (void)msdkDnsSetEnableDetectHostServer: (BOOL)enableDetectHostServer { + dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ + self.enableDetectHostServer = enableDetectHostServer; + }); +} + - (void)msdkDnsSetPreResolvedDomains: (NSArray *)domains { dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ self.preResolvedDomains = [domains copy]; @@ -265,6 +273,10 @@ - (BOOL)msdkDnsGetEnableReport { return _enableReport; } +- (BOOL)msdkDnsGetEnableDetectHostServer { + return _enableDetectHostServer; +} + - (NSArray *)msdkDnsGetPreResolvedDomains { return _preResolvedDomains; } diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index 86f4417..a49e94c 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -64,7 +64,6 @@ - (BOOL) initConfig:(DnsConfig *)config { [[MSDKDnsParamsManager shareInstance] msdkDnsSetMinutesBeforeSwitchToMain:config->minutesBeforeSwitchToMain]; } [[MSDKDnsParamsManager shareInstance] msdkDnsSetEnableReport:config->enableReport]; - [[MSDKDnsManager shareInstance] detectHttpDnsServers]; [[MSDKDnsManager shareInstance] fetchConfig:config->dnsId MEncryptType:config->encryptType MDnsKey:config->dnsKey MToken:config->token]; MSDKDNSLOG(@"MSDKDns init success."); return YES; diff --git a/MSDKDns/MSDKDnsPrivate.h b/MSDKDns/MSDKDnsPrivate.h index f10949a..e00f2f5 100644 --- a/MSDKDns/MSDKDnsPrivate.h +++ b/MSDKDns/MSDKDnsPrivate.h @@ -76,6 +76,7 @@ static NSString * const MSDKDnsEventHttpDnsCached = @"HDNSLookupCached"; static NSString * const MSDKDnsEventHttpDnsNormal = @"HDNSGetHostByName"; //常规解析请求 static NSString * const MSDKDnsEventHttpDnsPreResolved = @"HDNSPreLookup"; //预解析请求 static NSString * const MSDKDnsEventHttpDnsAutoRefresh = @"HDNSLookupAsync"; //缓存自动刷新 +static NSString * const MSDKDnsEventHttpDnsExpiredAsync = @"HDNSLookupExpiredAsync"; //乐观DNS中缓存异步刷新请求 static NSString * const MSDKDnsEventHttpDnsGetHTTPDNSDomainIP = @"HDNSGetDomainIP"; //获取三网域名的IP //命中缓存的状态 diff --git a/MSDKDns/Resolver/LocalDnsResolver.m b/MSDKDns/Resolver/LocalDnsResolver.m index 43ca7ec..87ae31f 100644 --- a/MSDKDns/Resolver/LocalDnsResolver.m +++ b/MSDKDns/Resolver/LocalDnsResolver.m @@ -20,7 +20,7 @@ @implementation LocalDnsResolver - (void)startWithDomains:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dnsId DnsKey:(NSString *)dnsKey NetStack:(msdkdns::MSDKDNS_TLocalIPStack)netStack { [super startWithDomains:domains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack]; - MSDKDNSLOG(@"LocalDns TimeOut is %f", timeOut); + MSDKDNSLOG(@"LocalDns domain is %@, TimeOut is %f", domains, timeOut); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timeOut * NSEC_PER_SEC), [MSDKDnsInfoTool msdkdns_local_queue], ^{ [self localDnsTimeout]; }); From 5fd857498eb2f3aff34d3b41f035fdcf15a36e1e Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Mon, 27 Feb 2023 15:25:52 +0800 Subject: [PATCH 12/15] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9E=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=BC=80=E5=85=B3=EF=BC=8C=E6=9A=B4=E6=BC=8F?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=BD=91=E7=BB=9C=E6=94=AF=E6=8C=81IPv6?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns.xcodeproj/project.pbxproj | 16 ++++++++-------- MSDKDns/CacheManager/MSDKDnsManager.h | 1 + MSDKDns/CacheManager/MSDKDnsManager.m | 12 +++++++++--- MSDKDns/MSDKDns.h | 11 +++++++++-- MSDKDns/MSDKDns.m | 5 +++++ MSDKDns/Reporter/AttaReport.m | 15 +++++++++++++++ 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 8cbf173..0dcb189 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -1047,7 +1047,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.3; + MARKETING_VERSION = 1.6.4; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1094,7 +1094,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.3; + MARKETING_VERSION = 1.6.4; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1136,7 +1136,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.3; + MARKETING_VERSION = 1.6.4; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1177,7 +1177,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.3; + MARKETING_VERSION = 1.6.4; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1226,7 +1226,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.3; + MARKETING_VERSION = 1.6.4; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1274,7 +1274,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.3; + MARKETING_VERSION = 1.6.4; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1312,7 +1312,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.3; + MARKETING_VERSION = 1.6.4; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1352,7 +1352,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.3; + MARKETING_VERSION = 1.6.4; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", diff --git a/MSDKDns/CacheManager/MSDKDnsManager.h b/MSDKDns/CacheManager/MSDKDnsManager.h index c2795ea..4424dc4 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.h +++ b/MSDKDns/CacheManager/MSDKDnsManager.h @@ -63,4 +63,5 @@ typedef enum { * 获取三网域名解析IP */ - (void)detectHttpDnsServers; +- (int)getAddressType; @end diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index cf1ca54..47cf224 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -186,7 +186,7 @@ - (NSDictionary *)getHostsByNamesEnableExpired:(NSArray *)domains verbose:(BOOL) [self.serviceArray addObject:dnsService]; __weak __typeof__(self) weakSelf = self; //进行httpdns请求 - [dnsService getHostsByNames:toCheckDomains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType returnIps:^() { + [dnsService getHostsByNames:toCheckDomains TimeOut:timeOut DnsId:dnsId DnsKey:dnsKey NetStack:netStack encryptType:encryptType from:MSDKDnsEventHttpDnsExpiredAsync returnIps:^{ __strong __typeof(self) strongSelf = weakSelf; if (strongSelf) { [toCheckDomains enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { @@ -949,6 +949,10 @@ - (BOOL)isDomainCacheExpired: (NSDictionary *)domainInfo { return netStack; } +- (int)getAddressType { + return [self detectAddressType]; +} + # pragma mark - servers @@ -1011,7 +1015,7 @@ - (void)fetchConfig:(int) mdnsId MEncryptType:(HttpDnsEncryptType)mdnsEncryptTyp } // NSLog(@"configDict = %@",configDict); // 暂时测试,默认开启探测三网域名IP - [[MSDKDnsManager shareInstance] detectHttpDnsServers]; + // [[MSDKDnsManager shareInstance] detectHttpDnsServers]; if(configDict && [configDict objectForKey:@"domain"]){ NSString *domainValue = [configDict objectForKey:@"domain"]; if ([domainValue isEqualToString:@"1"]) { @@ -1127,11 +1131,13 @@ - (void)detectHttpDnsServers { #ifdef httpdnsIps_h #if IS_INTL domain = MSDKDnsServerDomain_INTL; + dnsId = MSDKDnsId_INTL; + dnsKey = MSDKDnsKey_INTL; #else domain = MSDKDnsServerDomain; - #endif dnsId = MSDKDnsId; dnsKey = MSDKDnsKey; + #endif #endif if (![domain isEqualToString:@""] && dnsId != 0 && ![dnsKey isEqualToString:@""]) { NSArray *domains = @[domain]; diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index 217bf13..5b4aa66 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -5,7 +5,7 @@ #ifndef __MSDKDns_H__ #define __MSDKDns_H__ -#define MSDKDns_Version @"1.6.3" +#define MSDKDns_Version @"1.6.4" #import @@ -186,11 +186,18 @@ typedef struct DnsConfigStruct { */ - (NSDictionary *) WGGetDnsDetail:(NSString *) domain; -#pragma mark 清除缓存 +#pragma mark-清除缓存 /** 清理本地所有缓存,除非业务明确需要,不要调用该方法 */ - (void)clearCache; +#pragma mark-查询网络栈支持情况 +/** + 查询网络栈支持情况 + @return 0: UNKNOWN, 1: IPV4_ONLY, 2: IPV6_ONLY, 3: DUAL_STACK; +*/ +- (int) WGGetNetworkStack; + @end #endif diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index a49e94c..9acc51b 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -481,6 +481,11 @@ - (NSDictionary *) WGGetDnsDetail:(NSString *) domain { return [[MSDKDnsManager shareInstance] getDnsDetail:domain]; } +- (int) WGGetNetworkStack { + int type = [[MSDKDnsManager shareInstance] getAddressType]; + return [[MSDKDnsManager shareInstance] getAddressType]; +} + #pragma mark - others - (void)clearCache { diff --git a/MSDKDns/Reporter/AttaReport.m b/MSDKDns/Reporter/AttaReport.m index 7e3e942..87ac7ff 100644 --- a/MSDKDns/Reporter/AttaReport.m +++ b/MSDKDns/Reporter/AttaReport.m @@ -78,6 +78,21 @@ - (NSString *)formatReportParams:(NSDictionary *)params { NSString *systemName = [[UIDevice currentDevice] systemName]; NSString *systemVersion = [[UIDevice currentDevice] systemVersion]; NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:params]; + NSString *eventName = [dic objectForKey:@"eventName"]; + + int _DNSID = 0; + #ifdef httpdnsIps_h + #if IS_INTL + _DNSID = MSDKDnsId_INTL; + #else + _DNSID = MSDKDnsId; + #endif + #endif + // 如果是三网解析域名的请求,dnsID就使用指定的dnsID上报 + if ([eventName isEqualToString:MSDKDnsEventHttpDnsGetHTTPDNSDomainIP]){ + dnsId = _DNSID; + } + [dic addEntriesFromDictionary:@{ @"carrier": carrier, @"networkType": networkType, From 3525ead7e9a602c5e398878b1db355f839defda6 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Thu, 16 Mar 2023 11:42:35 +0800 Subject: [PATCH 13/15] =?UTF-8?q?feat:=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E9=85=8D=E7=BD=AE1.7.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- MSDKDns.xcodeproj/project.pbxproj | 16 ++++++++-------- MSDKDns/MSDKDns.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index fe7ebaf..081f0e9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ DerivedData *.hmap *.ipa *.xcuserstate - +.idea # CocoaPods Pods/ diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 0dcb189..e700014 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -1047,7 +1047,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.7.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1094,7 +1094,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.7.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1136,7 +1136,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.7.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1177,7 +1177,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.7.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1226,7 +1226,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.7.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1274,7 +1274,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.7.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1312,7 +1312,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.7.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1352,7 +1352,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.6.4; + MARKETING_VERSION = 1.7.0; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index 5b4aa66..3753605 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -5,7 +5,7 @@ #ifndef __MSDKDns_H__ #define __MSDKDns_H__ -#define MSDKDns_Version @"1.6.4" +#define MSDKDns_Version @"1.7.0" #import From 7f5cac6f93f952a8451b52c49e5e0f986d5db4a1 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Tue, 16 May 2023 14:41:36 +0800 Subject: [PATCH 14/15] =?UTF-8?q?feat:=E8=A7=A3=E6=9E=90=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8IP=E6=8E=A2=E6=B5=8B=E5=9B=BA=E5=AE=9Av4=E5=9C=BA?= =?UTF-8?q?=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 47cf224..75832a9 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -1141,7 +1141,7 @@ - (void)detectHttpDnsServers { #endif if (![domain isEqualToString:@""] && dnsId != 0 && ![dnsKey isEqualToString:@""]) { NSArray *domains = @[domain]; - msdkdns::MSDKDNS_TLocalIPStack netStack = [self detectAddressType]; + msdkdns::MSDKDNS_TLocalIPStack netStack = msdkdns::MSDKDNS_ELocalIPStack_IPv4; BOOL httpOnly = true; HttpDnsEncryptType encryptType = HttpDnsEncryptTypeDES; MSDKDnsService * dnsService = [[MSDKDnsService alloc] init]; From d7a52f95caf7a9fdf8d3c5ce5b5ef5810a50ba03 Mon Sep 17 00:00:00 2001 From: erichuyuehu Date: Fri, 19 May 2023 15:04:30 +0800 Subject: [PATCH 15/15] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.m | 2 ++ MSDKDns/MSDKDns.m | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 75832a9..0f0f6b3 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -1256,6 +1256,8 @@ - (NSArray *)defaultServers { #if IS_INTL if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEncryptType] != HttpDnsEncryptTypeHTTPS) { [servers addObjectsFromArray: MSDKDnsHttpServerIps_INTL]; + } else { + // 国际站SDK暂不支持HTTPS解析 } #else if ([[MSDKDnsParamsManager shareInstance] msdkDnsGetEncryptType] == HttpDnsEncryptTypeHTTPS) { diff --git a/MSDKDns/MSDKDns.m b/MSDKDns/MSDKDns.m index 9acc51b..c5d889d 100644 --- a/MSDKDns/MSDKDns.m +++ b/MSDKDns/MSDKDns.m @@ -482,7 +482,6 @@ - (NSDictionary *) WGGetDnsDetail:(NSString *) domain { } - (int) WGGetNetworkStack { - int type = [[MSDKDnsManager shareInstance] getAddressType]; return [[MSDKDnsManager shareInstance] getAddressType]; }