Skip to content

Commit

Permalink
Merge branch 'theo/log_handler' into 'master'
Browse files Browse the repository at this point in the history
feat: expose connectLogHandler

See merge request TankerHQ/sdk-ios!159
  • Loading branch information
theodelrieu committed Apr 20, 2021
2 parents 9b472a1 + e4a08a5 commit ad39e30
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 44 deletions.
52 changes: 26 additions & 26 deletions Tanker/Example/Tanker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
27159275A4876594F9355F74 /* Pods_Tanker_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9054B99FBDC5328ED0C7F9A /* Pods_Tanker_Example.framework */; };
2D63A3EFA7B80A4231E52577 /* Pods_Tanker_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A49F2D2B695ED0A13CEF1400 /* Pods_Tanker_Tests.framework */; };
484E3C8D20DA4ECC0046812D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 484E3C8B20DA4ECC0046812D /* LaunchScreen.storyboard */; };
484E3C9020DA4F7D0046812D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 484E3C8E20DA4F7D0046812D /* Main.storyboard */; };
6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
Expand All @@ -22,8 +24,6 @@
6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
940FDB9DDBD37A60A0EB0E37 /* Pods_Tanker_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6704482F86F2471FCAA81CB3 /* Pods_Tanker_Tests.framework */; };
D2A75913FFBA9D86D0D322A1 /* Pods_Tanker_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88D4A64EE399D226CF896EB2 /* Pods_Tanker_Example.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -38,8 +38,7 @@

/* Begin PBXFileReference section */
0C75F15D2718BE70837D37F6 /* Tanker.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Tanker.podspec; path = ../Tanker.podspec; sourceTree = "<group>"; };
247B0CFEEAD7E0AE00BA76BE /* Pods-Tanker_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tanker_Tests.release.xcconfig"; path = "Target Support Files/Pods-Tanker_Tests/Pods-Tanker_Tests.release.xcconfig"; sourceTree = "<group>"; };
3FDD44FEC85A9C1EEBE81360 /* Pods-Tanker_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tanker_Tests.debug.xcconfig"; path = "Target Support Files/Pods-Tanker_Tests/Pods-Tanker_Tests.debug.xcconfig"; sourceTree = "<group>"; };
459EA1459456E3883B0EF255 /* Pods-Tanker_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tanker_Tests.debug.xcconfig"; path = "Target Support Files/Pods-Tanker_Tests/Pods-Tanker_Tests.debug.xcconfig"; sourceTree = "<group>"; };
484E3C8C20DA4ECC0046812D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
484E3C8F20DA4F7D0046812D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
6003F58A195388D20070C39A /* Tanker_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tanker_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -61,10 +60,11 @@
6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = "<group>"; };
606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = "<group>"; };
6370262494985AF8C3717554 /* Pods-Tanker_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tanker_Example.debug.xcconfig"; path = "Target Support Files/Pods-Tanker_Example/Pods-Tanker_Example.debug.xcconfig"; sourceTree = "<group>"; };
6704482F86F2471FCAA81CB3 /* Pods_Tanker_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Tanker_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
67BAB3B1D8B4084C3443D5FF /* Pods-Tanker_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tanker_Example.release.xcconfig"; path = "Target Support Files/Pods-Tanker_Example/Pods-Tanker_Example.release.xcconfig"; sourceTree = "<group>"; };
88D4A64EE399D226CF896EB2 /* Pods_Tanker_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Tanker_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8948014BB4199FE80019115C /* Pods-Tanker_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tanker_Example.debug.xcconfig"; path = "Target Support Files/Pods-Tanker_Example/Pods-Tanker_Example.debug.xcconfig"; sourceTree = "<group>"; };
A22BBC9836A9C6878D1227F7 /* Pods-Tanker_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tanker_Tests.release.xcconfig"; path = "Target Support Files/Pods-Tanker_Tests/Pods-Tanker_Tests.release.xcconfig"; sourceTree = "<group>"; };
A49F2D2B695ED0A13CEF1400 /* Pods_Tanker_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Tanker_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C9054B99FBDC5328ED0C7F9A /* Pods_Tanker_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Tanker_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E5158C25B63713788BFC5B86 /* Pods-Tanker_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tanker_Example.release.xcconfig"; path = "Target Support Files/Pods-Tanker_Example/Pods-Tanker_Example.release.xcconfig"; sourceTree = "<group>"; };
E66D8A66BE6B693818E69BBF /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
FB6CAAE17FC374F9923EBEF3 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -77,7 +77,7 @@
6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */,
6003F592195388D20070C39A /* UIKit.framework in Frameworks */,
6003F58E195388D20070C39A /* Foundation.framework in Frameworks */,
D2A75913FFBA9D86D0D322A1 /* Pods_Tanker_Example.framework in Frameworks */,
27159275A4876594F9355F74 /* Pods_Tanker_Example.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -88,7 +88,7 @@
6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */,
6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */,
6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */,
940FDB9DDBD37A60A0EB0E37 /* Pods_Tanker_Tests.framework in Frameworks */,
2D63A3EFA7B80A4231E52577 /* Pods_Tanker_Tests.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -123,8 +123,8 @@
6003F58F195388D20070C39A /* CoreGraphics.framework */,
6003F591195388D20070C39A /* UIKit.framework */,
6003F5AF195388D20070C39A /* XCTest.framework */,
88D4A64EE399D226CF896EB2 /* Pods_Tanker_Example.framework */,
6704482F86F2471FCAA81CB3 /* Pods_Tanker_Tests.framework */,
C9054B99FBDC5328ED0C7F9A /* Pods_Tanker_Example.framework */,
A49F2D2B695ED0A13CEF1400 /* Pods_Tanker_Tests.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -188,10 +188,10 @@
A7CC3382A336F352B1EED7EF /* Pods */ = {
isa = PBXGroup;
children = (
6370262494985AF8C3717554 /* Pods-Tanker_Example.debug.xcconfig */,
67BAB3B1D8B4084C3443D5FF /* Pods-Tanker_Example.release.xcconfig */,
3FDD44FEC85A9C1EEBE81360 /* Pods-Tanker_Tests.debug.xcconfig */,
247B0CFEEAD7E0AE00BA76BE /* Pods-Tanker_Tests.release.xcconfig */,
8948014BB4199FE80019115C /* Pods-Tanker_Example.debug.xcconfig */,
E5158C25B63713788BFC5B86 /* Pods-Tanker_Example.release.xcconfig */,
459EA1459456E3883B0EF255 /* Pods-Tanker_Tests.debug.xcconfig */,
A22BBC9836A9C6878D1227F7 /* Pods-Tanker_Tests.release.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
Expand All @@ -203,11 +203,11 @@
isa = PBXNativeTarget;
buildConfigurationList = 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "Tanker_Example" */;
buildPhases = (
E217E24426632A3307AD67E7 /* [CP] Check Pods Manifest.lock */,
C2F0300A1301DCDFC4594B53 /* [CP] Check Pods Manifest.lock */,
6003F586195388D20070C39A /* Sources */,
6003F587195388D20070C39A /* Frameworks */,
6003F588195388D20070C39A /* Resources */,
430E7A0889443ECA66FFB7F7 /* [CP] Embed Pods Frameworks */,
A171864BB9D53079034A0AFF /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -222,7 +222,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "Tanker_Tests" */;
buildPhases = (
B3F2F5E9A8D53E3912289FBE /* [CP] Check Pods Manifest.lock */,
AC95A9E3DE686DB618559022 /* [CP] Check Pods Manifest.lock */,
6003F5AA195388D20070C39A /* Sources */,
6003F5AB195388D20070C39A /* Frameworks */,
6003F5AC195388D20070C39A /* Resources */,
Expand Down Expand Up @@ -298,7 +298,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
430E7A0889443ECA66FFB7F7 /* [CP] Embed Pods Frameworks */ = {
A171864BB9D53079034A0AFF /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -318,7 +318,7 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Tanker_Example/Pods-Tanker_Example-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
B3F2F5E9A8D53E3912289FBE /* [CP] Check Pods Manifest.lock */ = {
AC95A9E3DE686DB618559022 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -340,7 +340,7 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
E217E24426632A3307AD67E7 /* [CP] Check Pods Manifest.lock */ = {
C2F0300A1301DCDFC4594B53 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down Expand Up @@ -504,7 +504,7 @@
};
6003F5C0195388D20070C39A /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 6370262494985AF8C3717554 /* Pods-Tanker_Example.debug.xcconfig */;
baseConfigurationReference = 8948014BB4199FE80019115C /* Pods-Tanker_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5XDTLBME2P;
Expand All @@ -520,7 +520,7 @@
};
6003F5C1195388D20070C39A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 67BAB3B1D8B4084C3443D5FF /* Pods-Tanker_Example.release.xcconfig */;
baseConfigurationReference = E5158C25B63713788BFC5B86 /* Pods-Tanker_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5XDTLBME2P;
Expand All @@ -536,7 +536,7 @@
};
6003F5C3195388D20070C39A /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 3FDD44FEC85A9C1EEBE81360 /* Pods-Tanker_Tests.debug.xcconfig */;
baseConfigurationReference = 459EA1459456E3883B0EF255 /* Pods-Tanker_Tests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_IDENTITY = "iPhone Developer";
Expand Down Expand Up @@ -564,7 +564,7 @@
};
6003F5C4195388D20070C39A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 247B0CFEEAD7E0AE00BA76BE /* Pods-Tanker_Tests.release.xcconfig */;
baseConfigurationReference = A22BBC9836A9C6878D1227F7 /* Pods-Tanker_Tests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_IDENTITY = "iPhone Developer";
Expand Down
3 changes: 3 additions & 0 deletions Tanker/Headers/TKRCompletionHandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@class TKRVerificationMethod;
@class TKRAttachResult;
@class TKREncryptionSession;
@class TKRLogEntry;

/*!
@typedef TKRStartHandler
Expand Down Expand Up @@ -133,3 +134,5 @@ typedef void (^TKRInputStreamHandler)(NSInputStream* _Nullable stream,
*/
typedef void (^TKREncryptionSessionHandler)(
TKREncryptionSession* _Nullable session, NSError* _Nullable err);

typedef void (^TKRLogHandler)(TKRLogEntry* _Nonnull entry);
18 changes: 18 additions & 0 deletions Tanker/Headers/TKRLogEntry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, TKRLogLevel) {
TKRLogLevelDebug = 1,
TKRLogLevelInfo,
TKRLogLevelWarning,
TKRLogLevelError
};

@interface TKRLogEntry : NSObject

@property NSString* category;
@property TKRLogLevel level;
@property NSString* file;
@property NSUInteger line;
@property NSString* message;

@end
3 changes: 2 additions & 1 deletion Tanker/Headers/TKRTanker.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

+ (nonnull NSString*)prehashPassword:(nonnull NSString*)password;

+ (void)connectLogHandler:(nonnull TKRLogHandler)handler;

// MARK: Instance methods

/*!
Expand All @@ -57,7 +59,6 @@
*/
- (void)connectDeviceRevokedHandler:(nonnull TKRDeviceRevokedHandler)handler
DEPRECATED_MSG_ATTRIBUTE("the DeviceRevoked event is deprecated, it will be removed in the future");
;

/*!
@brief Get the list of the registered verification methods.
Expand Down
5 changes: 5 additions & 0 deletions Tanker/Sources/TKRLogEntry.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <TKRLogEntry.h>

@implementation TKRLogEntry

@end
50 changes: 33 additions & 17 deletions Tanker/Sources/TKRTanker.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "TKRVerification+Private.h"
#import "TKRVerificationKey+Private.h"
#import "TKRVerificationMethod+Private.h"
#import "TKRLogEntry.h"

#include <assert.h>
#include <string.h>
Expand All @@ -21,6 +22,23 @@

#define TANKER_IOS_VERSION @"9999"

TKRLogHandler globalLogHandler = ^(TKRLogEntry* _Nonnull entry){
switch (entry.level)
{
case TKRLogLevelDebug:
break;
case TKRLogLevelInfo:
break;
case TKRLogLevelWarning:
break;
case TKRLogLevelError:
NSLog(@"Tanker Error: [%@] %@", entry.category, entry.message);
break;
default:
NSLog(@"Unknown Tanker log level: %c: [%@] %@", (int)entry.level, entry.category, entry.message);
}
};

static void verificationToCVerification(TKRVerification* _Nonnull verification, tanker_verification_t* c_verification)
{
c_verification->verification_method_type = verification.type;
Expand All @@ -39,7 +57,6 @@ static void verificationToCVerification(TKRVerification* _Nonnull verification,
break;
case TKRVerificationMethodTypeOIDCIDToken:
c_verification->oidc_id_token = [verification.oidcIDToken cStringUsingEncoding:NSUTF8StringEncoding];
;
break;
default:
NSLog(@"Unreachable code: unknown verification method type: %lu", (unsigned long)verification.type);
Expand Down Expand Up @@ -74,22 +91,15 @@ static void dispatchInBackground(id block)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
}

static void logHandler(tanker_log_record_t const* record)
static void defaultLogHandler(tanker_log_record_t const* record)
{
switch (record->level)
{
case TANKER_LOG_DEBUG:
break;
case TANKER_LOG_INFO:
break;
case TANKER_LOG_WARNING:
break;
case TANKER_LOG_ERROR:
NSLog(@"Tanker Error: [%s] %s", record->category, record->message);
break;
default:
NSLog(@"Unknown Tanker log level: %c: [%s] %s", record->level, record->category, record->message);
}
TKRLogEntry* entry = [[TKRLogEntry alloc] init];
entry.category = [NSString stringWithCString:record->category encoding:NSUTF8StringEncoding];
entry.file = [NSString stringWithCString:record->file encoding:NSUTF8StringEncoding];
entry.message = [NSString stringWithCString:record->message encoding:NSUTF8StringEncoding];
entry.level = (TKRLogLevel)record->level;
entry.line = record->line;
globalLogHandler(entry);
}

static void onDeviceRevoked(void* unused, void* extra_arg)
Expand Down Expand Up @@ -131,9 +141,9 @@ @implementation TKRTanker
+ (nonnull TKRTanker*)tankerWithOptions:(nonnull TKRTankerOptions*)options
{
__block TKRTanker* tanker = [[[self class] alloc] init];
tanker_set_log_handler(&defaultLogHandler);
tanker.options = options;
tanker.callbacks = [NSMutableDictionary dictionary];
tanker_set_log_handler(&logHandler);

tanker_options_t cOptions = TANKER_OPTIONS_INIT;
convertOptions(options, &cOptions);
Expand Down Expand Up @@ -172,6 +182,12 @@ + (nonnull NSString*)prehashPassword:(nonnull NSString*)password
NSString* hashed = [NSString stringWithCString:c_hashed encoding:NSUTF8StringEncoding];
return hashed;
}

+ (void)connectLogHandler:(nonnull TKRLogHandler)handler
{
globalLogHandler = handler;
}

// MARK: Instance methods

- (void)startWithIdentity:(nonnull NSString*)identity completionHandler:(nonnull TKRStartHandler)handler
Expand Down
1 change: 1 addition & 0 deletions Tanker/export_symbols.list
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
_OBJC_CLASS_$_TKREncryptionOptions
_OBJC_CLASS_$_TKRTanker
_OBJC_CLASS_$_TKRLogEntry
_OBJC_CLASS_$_TKRTankerOptions
_OBJC_CLASS_$_TKRVerificationKey
_OBJC_CLASS_$_TKRVerification
Expand Down

0 comments on commit ad39e30

Please sign in to comment.