Repository: incubator-milagro-mfa-sdk-ios Updated Branches: refs/heads/master 4b4c745b4 -> e8ae71d4a
Added capability to init SDK with custom HTTP Headers Project: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-ios/commit/57c294e4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-ios/tree/57c294e4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-ios/diff/57c294e4 Branch: refs/heads/master Commit: 57c294e4c9c3b2dafa27a36bfc10cd0f390bc2ec Parents: 4b4c745 Author: Tihomir Ganev <[email protected]> Authored: Mon Oct 31 14:57:10 2016 +0200 Committer: Tihomir Ganev <[email protected]> Committed: Mon Oct 31 14:57:10 2016 +0200 ---------------------------------------------------------------------- MPinSDK/MPinSDK.xcodeproj/project.pbxproj | 10 +++++----- src/HTTPConnector.mm | 25 +++++++++++++++++++++---- src/MPin.h | 1 + src/MPin.mm | 20 +++++++++++++++++++- 4 files changed, 46 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-ios/blob/57c294e4/MPinSDK/MPinSDK.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/MPinSDK/MPinSDK.xcodeproj/project.pbxproj b/MPinSDK/MPinSDK.xcodeproj/project.pbxproj index 6b28fc6..5fb75e9 100644 --- a/MPinSDK/MPinSDK.xcodeproj/project.pbxproj +++ b/MPinSDK/MPinSDK.xcodeproj/project.pbxproj @@ -394,7 +394,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; USER_HEADER_SEARCH_PATHS = "../../mpin-sdk-core/ext/cvshared/cpp/include/**"; VALIDATE_PRODUCT = YES; @@ -440,7 +440,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; USER_HEADER_SEARCH_PATHS = "../../mpin-sdk-core/ext/cvshared/cpp/include/**"; VALIDATE_PRODUCT = YES; @@ -486,7 +486,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; USER_HEADER_SEARCH_PATHS = "../../mpin-sdk-core/ext/cvshared/cpp/include/**"; VALIDATE_PRODUCT = YES; @@ -538,7 +538,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; USER_HEADER_SEARCH_PATHS = "../../mpin-sdk-core/ext/cvshared/cpp/include/**"; @@ -570,7 +570,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; USER_HEADER_SEARCH_PATHS = "../../mpin-sdk-core/ext/cvshared/cpp/include/**"; VALIDATE_PRODUCT = YES; http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-ios/blob/57c294e4/src/HTTPConnector.mm ---------------------------------------------------------------------- diff --git a/src/HTTPConnector.mm b/src/HTTPConnector.mm index 7acb724..509bbc9 100644 --- a/src/HTTPConnector.mm +++ b/src/HTTPConnector.mm @@ -94,14 +94,30 @@ namespace net { [request setTimeoutInterval:constIntTimeoutInterval]; - if(!m_requestHeaders.empty()) { - for (StringMap::const_iterator it=m_requestHeaders.begin(); it!=m_requestHeaders.end(); ++it) { - [request addValue:[NSString stringWithUTF8String:it->second.c_str()] forHTTPHeaderField:[NSString stringWithUTF8String:it->first.c_str()]]; + NSDictionary *dictionary = [request allHTTPHeaderFields]; + + if(!m_requestHeaders.empty()) + { + for (StringMap::const_iterator it=m_requestHeaders.begin(); it!=m_requestHeaders.end(); ++it) + { + NSString *strValue = [NSString stringWithUTF8String:it->second.c_str()]; + NSString *strKey = [NSString stringWithUTF8String:it->first.c_str()]; + + if ([[dictionary allKeys] containsObject:strKey]) + { + [request setValue:strValue forHTTPHeaderField:strKey]; + } + else + { + [request addValue:strValue forHTTPHeaderField:strKey]; + } } } [request addValue:@"ios" forHTTPHeaderField:@"X-MIRACL-OS-Class"]; + /* + // Deprecated Code Starting Here NSDictionary *dictInfo = [[NSBundle mainBundle] infoDictionary]; NSString *strBundleID = dictInfo[@"CFBundleIdentifier"]; NSString *strAppVersion = dictInfo[@"CFBundleShortVersionString"]; @@ -111,7 +127,8 @@ namespace net { NSString *strUserAgent = [NSString stringWithFormat:@"%@/%@ (ios/%@) build/%@",strBundleID,strAppVersion,strOSVersion, strBuildNumber]; [request setValue:strUserAgent forHTTPHeaderField:@"User-Agent"]; - + // Deprecated Code Ends Here + */ if(!m_bodyData.empty()) { request.HTTPBody = [[NSString stringWithUTF8String:m_bodyData.c_str()] dataUsingEncoding:NSUTF8StringEncoding]; http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-ios/blob/57c294e4/src/MPin.h ---------------------------------------------------------------------- diff --git a/src/MPin.h b/src/MPin.h index 9a9142d..395d22b 100644 --- a/src/MPin.h +++ b/src/MPin.h @@ -26,6 +26,7 @@ @interface MPin : NSObject + (void) initSDK; ++ (void) initSDKWithUserAgent:(NSDictionary *)dictHeaders; + (MpinStatus*) TestBackend:(const NSString*)url; + (MpinStatus*) SetBackend:(const NSString*)url; + (MpinStatus*) TestBackend:(const NSString*)url rpsPrefix:(NSString*)rpsPrefix; http://git-wip-us.apache.org/repos/asf/incubator-milagro-mfa-sdk-ios/blob/57c294e4/src/MPin.mm ---------------------------------------------------------------------- diff --git a/src/MPin.mm b/src/MPin.mm index 28225d4..91e8804 100644 --- a/src/MPin.mm +++ b/src/MPin.mm @@ -51,6 +51,24 @@ typedef sdk_non_tee::Context Context; isInitialized = true; } ++ (void) initSDKWithUserAgent:(NSDictionary *)dictHeaders{ + + if (isInitialized) return; + + StringMap sm; + StringMap sm_CustomHeaders; + + for( id headerName in dictHeaders) + { + sm_CustomHeaders.Put( [headerName UTF8String], [dictHeaders[headerName] UTF8String] ); + } + + [lock lock]; + mpin.Init(sm, sdk_non_tee::Context::Instance(), sm_CustomHeaders); + [lock unlock]; + isInitialized = true; +} + +(MpinStatus *) TestBackend:(const NSString * ) url { [lock lock]; Status s = mpin.TestBackend((url == nil)?(""):([url UTF8String])); @@ -291,4 +309,4 @@ typedef sdk_non_tee::Context Context; [lock unlock]; } -@end \ No newline at end of file +@end
