Revert "Merge branch 'charlesmchen/debugLogs' into hotfix/2.20.1"

This reverts commit de5d17a396, reversing
changes made to d32e90c3d1.
pull/1/head
Matthew Chen 7 years ago
parent e4ee3e0007
commit b1dd325ce8

@ -46,7 +46,6 @@
#import <SignalServiceKit/TSStorageManager+Calling.h> #import <SignalServiceKit/TSStorageManager+Calling.h>
#import <SignalServiceKit/TextSecureKitEnv.h> #import <SignalServiceKit/TextSecureKitEnv.h>
#import <YapDatabase/YapDatabaseCryptoUtils.h> #import <YapDatabase/YapDatabaseCryptoUtils.h>
#import <sys/sysctl.h>
@import WebRTC; @import WebRTC;
@import Intents; @import Intents;
@ -325,7 +324,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", nil) [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", nil)
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) { handler:^(UIAlertAction *_Nonnull action) {
[Pastelog submitLogsWithCompletion:^{ [Pastelog submitLogsWithShareCompletion:^{
DDLogInfo( DDLogInfo(
@"%@ exiting after sharing debug logs.", self.logTag); @"%@ exiting after sharing debug logs.", self.logTag);
[DDLog flushLog]; [DDLog flushLog];
@ -397,15 +396,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
if (languageCode.length > 0) { if (languageCode.length > 0) {
DDLogInfo(@"Language Code: %@", languageCode); DDLogInfo(@"Language Code: %@", languageCode);
} }
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
DDLogInfo(@"iPhone Version: %@", platform);
} }
- (UIViewController *)loadingRootViewController - (UIViewController *)loadingRootViewController

@ -7,6 +7,7 @@
#import "OWSTableViewController.h" #import "OWSTableViewController.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "ThreadUtil.h" #import "ThreadUtil.h"
#import <AFNetworking/AFNetworking.h>
#import <AxolotlKit/PreKeyBundle.h> #import <AxolotlKit/PreKeyBundle.h>
#import <Curve25519Kit/Randomness.h> #import <Curve25519Kit/Randomness.h>
#import <SignalMessaging/Environment.h> #import <SignalMessaging/Environment.h>

@ -10,6 +10,7 @@
#import "RegistrationViewController.h" #import "RegistrationViewController.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "ThreadUtil.h" #import "ThreadUtil.h"
#import <AFNetworking/AFNetworking.h>
#import <AxolotlKit/PreKeyBundle.h> #import <AxolotlKit/PreKeyBundle.h>
#import <SignalMessaging/AttachmentSharing.h> #import <SignalMessaging/AttachmentSharing.h>
#import <SignalMessaging/Environment.h> #import <SignalMessaging/Environment.h>

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// //
#import "DebugUISyncMessages.h" #import "DebugUISyncMessages.h"
@ -7,6 +7,7 @@
#import "OWSTableViewController.h" #import "OWSTableViewController.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "ThreadUtil.h" #import "ThreadUtil.h"
#import <AFNetworking/AFNetworking.h>
#import <AxolotlKit/PreKeyBundle.h> #import <AxolotlKit/PreKeyBundle.h>
#import <Curve25519Kit/Randomness.h> #import <Curve25519Kit/Randomness.h>
#import <SignalMessaging/Environment.h> #import <SignalMessaging/Environment.h>

@ -2,17 +2,14 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
NS_ASSUME_NONNULL_BEGIN
typedef void (^SubmitDebugLogsCompletion)(void);
@interface Pastelog : NSObject @interface Pastelog : NSObject
- (instancetype)init NS_UNAVAILABLE; typedef void (^DebugLogsUploadedBlock)(NSError *error, NSString *urlString);
typedef void (^DebugLogsSharedBlock)(void);
+ (void)submitLogs; +(void)submitLogs;
+ (void)submitLogsWithCompletion:(nullable SubmitDebugLogsCompletion)completion; + (void)submitLogsWithShareCompletion:(nullable DebugLogsSharedBlock)block;
+ (void)submitLogsWithUploadCompletion:(DebugLogsUploadedBlock)block;
+ (void)submitLogsWithUploadCompletion:(DebugLogsUploadedBlock)block forFileLogger:(DDFileLogger *)fileLogger;
@end @end
NS_ASSUME_NONNULL_END

@ -5,7 +5,6 @@
#import "Pastelog.h" #import "Pastelog.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "ThreadUtil.h" #import "ThreadUtil.h"
#import <SSZipArchive/SSZipArchive.h>
#import <SignalMessaging/DebugLogger.h> #import <SignalMessaging/DebugLogger.h>
#import <SignalMessaging/Environment.h> #import <SignalMessaging/Environment.h>
#import <SignalServiceKit/AppContext.h> #import <SignalServiceKit/AppContext.h>
@ -13,199 +12,13 @@
#import <SignalServiceKit/TSContactThread.h> #import <SignalServiceKit/TSContactThread.h>
#import <SignalServiceKit/TSStorageManager.h> #import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/Threading.h> #import <SignalServiceKit/Threading.h>
#import <sys/sysctl.h>
NS_ASSUME_NONNULL_BEGIN @interface Pastelog () <NSURLConnectionDelegate, NSURLConnectionDataDelegate, UIAlertViewDelegate>
typedef void (^UploadDebugLogsSuccess)(NSURL *url);
typedef void (^UploadDebugLogsFailure)(NSString *localizedErrorMessage);
#pragma mark -
@class DebugLogUploader;
typedef void (^DebugLogUploadSuccess)(DebugLogUploader *uploader, NSURL *url);
typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error);
@interface DebugLogUploader : NSObject <NSURLConnectionDelegate, NSURLConnectionDataDelegate>
@property (nonatomic) NSMutableData *responseData;
@property (nonatomic, nullable) DebugLogUploadSuccess success;
@property (nonatomic, nullable) DebugLogUploadFailure failure;
@end
#pragma mark -
@implementation DebugLogUploader
- (void)dealloc
{
DDLogVerbose(@"Dealloc: %@", self.logTag);
}
- (void)uploadFileWithURL:(NSURL *)fileUrl success:(DebugLogUploadSuccess)success failure:(DebugLogUploadFailure)failure
{
OWSAssert(fileUrl);
OWSAssert(success);
OWSAssert(failure);
self.success = success;
self.failure = failure;
self.responseData = [NSMutableData new];
NSURL *url = [NSURL URLWithString:@"https://filebin.net"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:30];
[request setHTTPMethod:@"POST"];
[request addValue:fileUrl.lastPathComponent forHTTPHeaderField:@"filename"];
[request addValue:@"application/zip" forHTTPHeaderField:@"Content-Type"];
NSData *_Nullable data = [NSData dataWithContentsOfURL:fileUrl];
if (!data) {
[self failWithError:[NSError errorWithDomain:@"PastelogKit"
code:10002
userInfo:@{ NSLocalizedDescriptionKey : @"Could not load data." }]];
return;
}
// TODO:
[request setHTTPBody:data];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
[connection start];
}
#pragma mark - Delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[self.responseData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
NSError *error;
NSDictionary *_Nullable dict = [NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error];
if (error) {
DDLogError(@"%@ response length: %zd", self.logTag, self.responseData.length);
[self failWithError:error];
return;
}
if (![dict isKindOfClass:[NSDictionary class]]) {
DDLogError(@"%@ response (1): %@", self.logTag, dict);
[self failWithError:[NSError errorWithDomain:@"PastelogKit"
code:10003
userInfo:@{ NSLocalizedDescriptionKey : @"Malformed response (root)." }]];
return;
}
NSArray<id> *_Nullable links = [dict objectForKey:@"links"];
if (![links isKindOfClass:[NSArray class]]) {
DDLogError(@"%@ response (2): %@", self.logTag, dict);
[self failWithError:[NSError errorWithDomain:@"PastelogKit"
code:10004
userInfo:@{ NSLocalizedDescriptionKey : @"Malformed response (links)." }]];
return;
}
NSString *_Nullable urlString = nil;
for (NSDictionary *linkMap in links) {
if (![linkMap isKindOfClass:[NSDictionary class]]) {
DDLogError(@"%@ response (2): %@", self.logTag, dict);
[self failWithError:[NSError
errorWithDomain:@"PastelogKit"
code:10005
userInfo:@{ NSLocalizedDescriptionKey : @"Malformed response (linkMap)." }]];
return;
}
NSString *_Nullable linkRel = [linkMap objectForKey:@"rel"];
if (![linkRel isKindOfClass:[NSString class]]) {
DDLogError(@"%@ response (linkRel): %@", self.logTag, dict);
continue;
}
if (![linkRel isEqualToString:@"file"]) {
DDLogError(@"%@ response (linkRel value): %@", self.logTag, dict);
continue;
}
NSString *_Nullable linkHref = [linkMap objectForKey:@"href"];
if (![linkHref isKindOfClass:[NSString class]]) {
DDLogError(@"%@ response (linkHref): %@", self.logTag, dict);
continue;
}
urlString = linkHref;
break;
}
[self succeedWithUrl:[NSURL URLWithString:urlString]];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = httpResponse.statusCode;
// We'll accept any 2xx status code.
NSInteger statusCodeClass = statusCode - (statusCode % 100);
if (statusCodeClass != 200) {
DDLogError(@"%@ statusCode: %zd, %zd", self.logTag, statusCode, statusCodeClass);
DDLogError(@"%@ headers: %@", self.logTag, httpResponse.allHeaderFields);
[self failWithError:[NSError errorWithDomain:@"PastelogKit"
code:10001
userInfo:@{ NSLocalizedDescriptionKey : @"Invalid response code." }]];
}
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[self failWithError:error];
}
- (void)failWithError:(NSError *)error
{
OWSAssert(error);
DDLogError(@"%@ %s %@", self.logTag, __PRETTY_FUNCTION__, error);
DispatchMainThreadSafe(^{
// Call the completions exactly once.
if (self.failure) {
self.failure(self, error);
}
self.success = nil;
self.failure = nil;
});
}
- (void)succeedWithUrl:(NSURL *)url
{
OWSAssert(url);
DDLogVerbose(@"%@ %s %@", self.logTag, __PRETTY_FUNCTION__, url);
DispatchMainThreadSafe(^{
// Call the completions exactly once.
if (self.success) {
self.success(self, url);
}
self.success = nil;
self.failure = nil;
});
}
@end
#pragma mark -
@interface Pastelog () <UIAlertViewDelegate>
@property (nonatomic) UIAlertController *loadingAlert; @property (nonatomic) UIAlertController *loadingAlert;
@property (nonatomic) NSMutableData *responseData;
@property (nonatomic) DebugLogUploader *currentUploader; @property (nonatomic) DebugLogsUploadedBlock block;
@end @end
@ -213,57 +26,36 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
@implementation Pastelog @implementation Pastelog
+ (instancetype)sharedManager +(void)submitLogs {
{ [self submitLogsWithShareCompletion:nil];
static Pastelog *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] initDefault];
});
return sharedMyManager;
}
- (instancetype)initDefault
{
self = [super init];
if (!self) {
return self;
}
OWSSingletonAssert();
return self;
} }
+ (void)submitLogs + (void)submitLogsWithShareCompletion:(nullable DebugLogsSharedBlock)shareCompletionParam
{ {
[self submitLogsWithCompletion:nil]; DebugLogsSharedBlock shareCompletion = ^{
} if (shareCompletionParam) {
+ (void)submitLogsWithCompletion:(nullable SubmitDebugLogsCompletion)completionParam
{
SubmitDebugLogsCompletion completion = ^{
if (completionParam) {
// Wait a moment. If PasteLog opens a URL, it needs a moment to complete. // Wait a moment. If PasteLog opens a URL, it needs a moment to complete.
dispatch_after( dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), completionParam); dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), shareCompletionParam);
} }
}; };
[self uploadLogsWithSuccess:^(NSURL *url) { [self submitLogsWithUploadCompletion:^(NSError *error, NSString *urlString) {
if (!error) {
UIAlertController *alert = [UIAlertController UIAlertController *alert = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_TITLE", @"Title of the debug log alert.") alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_TITLE", @"Title of the debug log alert.")
message:NSLocalizedString(@"DEBUG_LOG_ALERT_MESSAGE", @"Message of the debug log alert.") message:NSLocalizedString(
@"DEBUG_LOG_ALERT_MESSAGE", @"Message of the debug log alert.")
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction [alert
addAction:[UIAlertAction
actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_EMAIL", actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_EMAIL",
@"Label for the 'email debug log' option of the the debug log alert.") @"Label for the 'email debug log' option of the the debug log alert.")
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) { handler:^(UIAlertAction *_Nonnull action) {
[Pastelog.sharedManager submitEmail:url]; [Pastelog.sharedManager submitEmail:urlString];
completion(); shareCompletion();
}]]; }]];
[alert addAction:[UIAlertAction [alert addAction:[UIAlertAction
actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_COPY_LINK", actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_COPY_LINK",
@ -271,9 +63,9 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) { handler:^(UIAlertAction *_Nonnull action) {
UIPasteboard *pb = [UIPasteboard generalPasteboard]; UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:url.absoluteString]; [pb setString:urlString];
completion(); shareCompletion();
}]]; }]];
#ifdef DEBUG #ifdef DEBUG
[alert addAction:[UIAlertAction [alert addAction:[UIAlertAction
@ -281,158 +73,190 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
@"Label for the 'send to self' option of the the debug log alert.") @"Label for the 'send to self' option of the the debug log alert.")
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) { handler:^(UIAlertAction *_Nonnull action) {
[Pastelog.sharedManager sendToSelf:url]; [Pastelog.sharedManager sendToSelf:urlString];
}]]; }]];
[alert [alert addAction:[UIAlertAction
addAction:[UIAlertAction actionWithTitle:
actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_LAST_THREAD", NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_LAST_THREAD",
@"Label for the 'send to last thread' option of the the debug log alert.") @"Label for the 'send to last thread' option of the the debug log alert.")
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) { handler:^(UIAlertAction *_Nonnull action) {
[Pastelog.sharedManager sendToMostRecentThread:url]; [Pastelog.sharedManager sendToMostRecentThread:urlString];
}]]; }]];
#endif #endif
[alert [alert addAction:
addAction:[UIAlertAction [UIAlertAction
actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_BUG_REPORT", actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_BUG_REPORT",
@"Label for the 'Open a Bug Report' option of the the debug log alert.") @"Label for the 'Open a Bug Report' option of the the debug log alert.")
style:UIAlertActionStyleCancel style:UIAlertActionStyleCancel
handler:^(UIAlertAction *_Nonnull action) { handler:^(UIAlertAction *_Nonnull action) {
[Pastelog.sharedManager prepareRedirection:url completion:completion]; [Pastelog.sharedManager prepareRedirection:urlString
shareCompletion:shareCompletion];
}]]; }]];
UIViewController *presentingViewController UIViewController *presentingViewController
= UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts;
[presentingViewController presentViewController:alert animated:NO completion:nil]; [presentingViewController presentViewController:alert animated:NO completion:nil];
} else{
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DEBUG_LOG_FAILURE_ALERT_TITLE",
@"Title of the alert indicating the debug log upload failed.")
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alertView show];
}
}]; }];
} }
+ (void)uploadLogsWithSuccess:(nullable UploadDebugLogsSuccess)success + (void)submitLogsWithUploadCompletion:(DebugLogsUploadedBlock)block
{ {
OWSAssert(success); [self submitLogsWithUploadCompletion:block forFileLogger:[[DDFileLogger alloc] init]];
[[self sharedManager] uploadLogsWithSuccess:success
failure:^(NSString *localizedErrorMessage) {
[Pastelog showFailureAlertWithMessage:localizedErrorMessage];
}];
} }
- (void)uploadLogsWithSuccess:(nullable UploadDebugLogsSuccess)successParam failure:(UploadDebugLogsFailure)failureParam + (void)submitLogsWithUploadCompletion:(DebugLogsUploadedBlock)block forFileLogger:(DDFileLogger *)fileLogger
{ {
OWSAssert(successParam);
OWSAssert(failureParam);
// Ensure that we call the completions on the main thread. [self sharedManager].block = block;
UploadDebugLogsSuccess success = ^(NSURL *url) {
if (successParam) {
DispatchMainThreadSafe(^{
successParam(url);
});
}
};
UploadDebugLogsFailure failure = ^(NSString *localizedErrorMessage) {
DispatchMainThreadSafe(^{
failureParam(localizedErrorMessage);
});
};
// Phase 1. Make a local copy of all of the log files. [self sharedManager].loadingAlert =
NSDateFormatter *dateFormatter = [NSDateFormatter new]; [UIAlertController alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_ACTIVITY_INDICATOR",
[dateFormatter setLocale:[NSLocale currentLocale]]; @"Message indicating that the debug log is being uploaded.")
[dateFormatter setDateFormat:@"yyyy.MM.dd hh.mm.ss"]; message:nil
NSString *dateString = [dateFormatter stringFromDate:[NSDate new]]; preferredStyle:UIAlertControllerStyleAlert];
NSString *logsName = [[dateString stringByAppendingString:@" "] stringByAppendingString:NSUUID.UUID.UUIDString]; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts;
NSString *tempDirectory = NSTemporaryDirectory(); [presentingViewController presentViewController:[self sharedManager].loadingAlert animated:NO completion:nil];
NSString *zipFilePath =
[tempDirectory stringByAppendingPathComponent:[logsName stringByAppendingPathExtension:@"zip"]];
NSString *zipDirPath = [tempDirectory stringByAppendingPathComponent:logsName];
[OWSFileSystem ensureDirectoryExists:zipDirPath];
[OWSFileSystem protectFileOrFolderAtPath:zipDirPath];
NSArray<NSString *> *logFilePaths = DebugLogger.sharedLogger.allLogFilePaths; NSArray<NSString *> *logFilePaths = DebugLogger.sharedLogger.allLogFilePaths;
if (logFilePaths.count < 1) {
failure(NSLocalizedString(@"DEBUG_LOG_ALERT_NO_LOGS", @"Error indicating that no debug logs could be found.")); NSMutableDictionary *gistFiles = [NSMutableDictionary new];
return;
}
for (NSString *logFilePath in logFilePaths) { for (NSString *logFilePath in logFilePaths) {
NSString *copyFilePath = [zipDirPath stringByAppendingPathComponent:logFilePath.lastPathComponent];
NSError *error; NSError *error;
[[NSFileManager defaultManager] copyItemAtPath:logFilePath toPath:copyFilePath error:&error]; NSString *logContents =
[NSString stringWithContentsOfFile:logFilePath encoding:NSUTF8StringEncoding error:&error];
if (error) { if (error) {
failure(NSLocalizedString( OWSFail(@"%@ Error loading log file contents: %@", self.logTag, error);
@"DEBUG_LOG_ALERT_COULD_NOT_COPY_LOGS", @"Error indicating that the debug logs could not be copied.")); continue;
return;
} }
[OWSFileSystem protectFileOrFolderAtPath:copyFilePath]; gistFiles[logFilePath.lastPathComponent] = @{
@"content" : logContents,
};
} }
// Phase 2. Zip up the log files. NSDictionary *gistDict = @{@"description":[self gistDescription], @"files":gistFiles};
BOOL zipSuccess =
[SSZipArchive createZipFileAtPath:zipFilePath withContentsOfDirectory:zipDirPath withPassword:nil];
if (!zipSuccess) {
failure(NSLocalizedString(
@"DEBUG_LOG_ALERT_COULD_NOT_PACKAGE_LOGS", @"Error indicating that the debug logs could not be packaged."));
return;
}
[OWSFileSystem protectFileOrFolderAtPath:zipFilePath]; NSData *postData = [NSJSONSerialization dataWithJSONObject:gistDict options:0 error:nil];
[OWSFileSystem deleteFile:zipDirPath];
// Phase 3. Upload the log files. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"https://api.github.com/gists"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30];
__weak Pastelog *weakSelf = self; [[self sharedManager] setResponseData:[NSMutableData data]];
self.currentUploader = [DebugLogUploader new]; [[self sharedManager] setBlock:block];
[self.currentUploader uploadFileWithURL:[NSURL fileURLWithPath:zipFilePath]
success:^(DebugLogUploader *uploader, NSURL *url) { [request setHTTPMethod:@"POST"];
if (uploader != weakSelf.currentUploader) { [request setHTTPBody:postData];
// Ignore events from obsolete uploaders.
return; NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:[self sharedManager]];
}
[OWSFileSystem deleteFile:zipFilePath]; [connection start];
success(url);
}
+(Pastelog*)sharedManager {
static Pastelog *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
-(instancetype)init {
if (self = [super init]) {
self.responseData = [NSMutableData data];
OWSSingletonAssert();
} }
failure:^(DebugLogUploader *uploader, NSError *error) { return self;
if (uploader != weakSelf.currentUploader) { }
// Ignore events from obsolete uploaders.
return; +(NSString*)gistDescription{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
NSString *gistDesc = [NSString stringWithFormat:@"iPhone Version: %@, iOS Version: %@", platform,[UIDevice currentDevice].systemVersion];
return gistDesc;
}
#pragma mark Network delegates
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[self.responseData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self.loadingAlert
dismissViewControllerAnimated:NO
completion:^{
NSError *error;
NSDictionary *dict =
[NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error];
if (!error) {
self.block(nil, [dict objectForKey:@"html_url"]);
} else {
DDLogError(@"Error on debug response: %@", error);
self.block(error, nil);
} }
[OWSFileSystem deleteFile:zipFilePath];
failure(NSLocalizedString(
@"DEBUG_LOG_ALERT_ERROR_UPLOADING_LOG", @"Error indicating that a debug log could not be uploaded."));
}]; }];
self.loadingAlert = nil;
} }
+ (void)showFailureAlertWithMessage:(NSString *)message - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
{
UIAlertController *alert = [UIAlertController NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_TITLE",
@"Title of the alert shown for failures while uploading debug logs.") if ( [httpResponse statusCode] != 201) {
message:message DDLogError(@"Failed to submit debug log: %@", httpResponse.debugDescription);
preferredStyle:UIAlertControllerStyleAlert]; [self.loadingAlert
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"") dismissViewControllerAnimated:NO
style:UIAlertActionStyleDefault completion:^{
handler:nil]]; [connection cancel];
UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; self.block([NSError errorWithDomain:@"PastelogKit" code:10001 userInfo:@{}], nil);
[presentingViewController presentViewController:alert animated:NO completion:nil]; }];
self.loadingAlert = nil;
}
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[self.loadingAlert dismissViewControllerAnimated:NO
completion:^{
DDLogError(@"Uploading logs failed with error: %@", error);
self.block(error, nil);
}];
self.loadingAlert = nil;
} }
#pragma mark Logs submission #pragma mark Logs submission
- (void)submitEmail:(NSURL *)url - (void)submitEmail:(NSString*)url {
{
NSString *emailAddress = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"LOGS_EMAIL"]; NSString *emailAddress = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"LOGS_EMAIL"];
NSString *urlString = [NSString stringWithString: [[NSString stringWithFormat:@"mailto:%@?subject=iOS%%20Debug%%20Log&body=", emailAddress] stringByAppendingString:[[NSString stringWithFormat:@"Log URL: %@ \n Tell us about the issue: ", url]stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]]; NSString *urlString = [NSString stringWithString: [[NSString stringWithFormat:@"mailto:%@?subject=iOS%%20Debug%%20Log&body=", emailAddress] stringByAppendingString:[[NSString stringWithFormat:@"Log URL: %@ \n Tell us about the issue: ", url]stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
[UIApplication.sharedApplication openURL:[NSURL URLWithString:urlString]]; [UIApplication.sharedApplication openURL: [NSURL URLWithString: urlString]];
} }
- (void)prepareRedirection:(NSURL *)url completion:(SubmitDebugLogsCompletion)completion - (void)prepareRedirection:(NSString *)url shareCompletion:(DebugLogsSharedBlock)shareCompletion
{ {
OWSAssert(completion); OWSAssert(shareCompletion);
UIPasteboard *pb = [UIPasteboard generalPasteboard]; UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:url.absoluteString]; [pb setString:url];
UIAlertController *alert = UIAlertController *alert =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_GITHUB_ISSUE_ALERT_TITLE", [UIAlertController alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_GITHUB_ISSUE_ALERT_TITLE",
@ -448,13 +272,13 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
openURL:[NSURL URLWithString:[[NSBundle mainBundle] openURL:[NSURL URLWithString:[[NSBundle mainBundle]
objectForInfoDictionaryKey:@"LOGS_URL"]]]; objectForInfoDictionaryKey:@"LOGS_URL"]]];
completion(); shareCompletion();
}]]; }]];
UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts;
[presentingViewController presentViewController:alert animated:NO completion:nil]; [presentingViewController presentViewController:alert animated:NO completion:nil];
} }
- (void)sendToSelf:(NSURL *)url - (void)sendToSelf:(NSString *)url
{ {
if (![TSAccountManager isRegistered]) { if (![TSAccountManager isRegistered]) {
return; return;
@ -468,14 +292,14 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction]; thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
}]; }];
[ThreadUtil sendMessageWithText:url.absoluteString inThread:thread messageSender:messageSender]; [ThreadUtil sendMessageWithText:url inThread:thread messageSender:messageSender];
}); });
// Also copy to pasteboard. // Also copy to pasteboard.
[[UIPasteboard generalPasteboard] setString:url.absoluteString]; [[UIPasteboard generalPasteboard] setString:url];
} }
- (void)sendToMostRecentThread:(NSURL *)url - (void)sendToMostRecentThread:(NSString *)url
{ {
if (![TSAccountManager isRegistered]) { if (![TSAccountManager isRegistered]) {
return; return;
@ -488,13 +312,11 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
thread = [[transaction ext:TSThreadDatabaseViewExtensionName] firstObjectInGroup:[TSThread collection]]; thread = [[transaction ext:TSThreadDatabaseViewExtensionName] firstObjectInGroup:[TSThread collection]];
}]; }];
[ThreadUtil sendMessageWithText:url.absoluteString inThread:thread messageSender:messageSender]; [ThreadUtil sendMessageWithText:url inThread:thread messageSender:messageSender];
}); });
// Also copy to pasteboard. // Also copy to pasteboard.
[[UIPasteboard generalPasteboard] setString:url.absoluteString]; [[UIPasteboard generalPasteboard] setString:url];
} }
@end @end
NS_ASSUME_NONNULL_END

@ -499,21 +499,12 @@
/* The day before today. */ /* The day before today. */
"DATE_YESTERDAY" = "Yesterday"; "DATE_YESTERDAY" = "Yesterday";
/* Error indicating that the debug logs could not be copied. */ /* Message indicating that the debug log is being uploaded. */
"DEBUG_LOG_ALERT_COULD_NOT_COPY_LOGS" = "Could not copy logs."; "DEBUG_LOG_ACTIVITY_INDICATOR" = "Sending Debug Log...";
/* Error indicating that the debug logs could not be packaged. */
"DEBUG_LOG_ALERT_COULD_NOT_PACKAGE_LOGS" = "Could not package logs.";
/* Error indicating that a debug log could not be uploaded. */
"DEBUG_LOG_ALERT_ERROR_UPLOADING_LOG" = "Could not upload logs.";
/* Message of the debug log alert. */ /* Message of the debug log alert. */
"DEBUG_LOG_ALERT_MESSAGE" = "What would you like to do with the link to your debug log?"; "DEBUG_LOG_ALERT_MESSAGE" = "What would you like to do with the link to your debug log?";
/* Error indicating that no debug logs could be found. */
"DEBUG_LOG_ALERT_NO_LOGS" = "Could not find any logs.";
/* Label for the 'Open a Bug Report' option of the the debug log alert. */ /* Label for the 'Open a Bug Report' option of the the debug log alert. */
"DEBUG_LOG_ALERT_OPTION_BUG_REPORT" = "Open a Bug Report"; "DEBUG_LOG_ALERT_OPTION_BUG_REPORT" = "Open a Bug Report";
@ -529,10 +520,12 @@
/* Label for the 'send to self' option of the the debug log alert. */ /* Label for the 'send to self' option of the the debug log alert. */
"DEBUG_LOG_ALERT_OPTION_SEND_TO_SELF" = "Send to Self"; "DEBUG_LOG_ALERT_OPTION_SEND_TO_SELF" = "Send to Self";
/* Title of the alert shown for failures while uploading debug logs. /* Title of the debug log alert. */
Title of the debug log alert. */
"DEBUG_LOG_ALERT_TITLE" = "One More Step"; "DEBUG_LOG_ALERT_TITLE" = "One More Step";
/* Title of the alert indicating the debug log upload failed. */
"DEBUG_LOG_FAILURE_ALERT_TITLE" = "Failed to Submit Debug Log";
/* Message of the alert before redirecting to Github Issues. */ /* Message of the alert before redirecting to Github Issues. */
"DEBUG_LOG_GITHUB_ISSUE_ALERT_MESSAGE" = "The gist link was copied in your clipboard. You are about to be redirected to the GitHub issue list."; "DEBUG_LOG_GITHUB_ISSUE_ALERT_MESSAGE" = "The gist link was copied in your clipboard. You are about to be redirected to the GitHub issue list.";

@ -7,6 +7,7 @@
#import "NSString+OWS.h" #import "NSString+OWS.h"
#import "OWSUserProfile.h" #import "OWSUserProfile.h"
#import "UIImage+OWS.h" #import "UIImage+OWS.h"
#import <AFNetworking/AFNetworking.h>
#import <SignalMessaging/SignalMessaging-Swift.h> #import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/AppContext.h> #import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/Cryptography.h> #import <SignalServiceKit/Cryptography.h>

@ -1,11 +1,9 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// //
#import <CocoaLumberjack/DDFileLogger.h> #import <CocoaLumberjack/DDFileLogger.h>
NS_ASSUME_NONNULL_BEGIN
@interface DebugLogger : NSObject @interface DebugLogger : NSObject
+ (instancetype)sharedLogger; + (instancetype)sharedLogger;
@ -21,5 +19,3 @@ NS_ASSUME_NONNULL_BEGIN
- (NSArray<NSString *> *)allLogFilePaths; - (NSArray<NSString *> *)allLogFilePaths;
@end @end
NS_ASSUME_NONNULL_END

@ -11,13 +11,9 @@
#pragma mark Logging - Production logging wants us to write some logs to a file in case we need it for debugging. #pragma mark Logging - Production logging wants us to write some logs to a file in case we need it for debugging.
#import <CocoaLumberjack/DDTTYLogger.h> #import <CocoaLumberjack/DDTTYLogger.h>
NS_ASSUME_NONNULL_BEGIN
const NSUInteger kMaxDebugLogFileSize = 1024 * 1024 * 3;
@interface DebugLogger () @interface DebugLogger ()
@property (nonatomic, nullable) DDFileLogger *fileLogger; @property (nonatomic) DDFileLogger *fileLogger;
@end @end
@ -70,8 +66,9 @@ const NSUInteger kMaxDebugLogFileSize = 1024 * 1024 * 3;
// 24 hour rolling. // 24 hour rolling.
self.fileLogger.rollingFrequency = kDayInterval; self.fileLogger.rollingFrequency = kDayInterval;
// Keep last 3 days of logs - or last 3 logs (if logs rollover due to max file size). // Keep last 3 days of logs - or last 3 logs (if logs rollover due to max file size).
self.fileLogger.logFileManager.maximumNumberOfLogFiles = 24; self.fileLogger.logFileManager.maximumNumberOfLogFiles = 3;
self.fileLogger.maximumFileSize = kMaxDebugLogFileSize; // Raise the max file size per log file to 3 MB.
self.fileLogger.maximumFileSize = 1024 * 1024 * 3;
self.fileLogger.logFormatter = [OWSScrubbingLogFormatter new]; self.fileLogger.logFormatter = [OWSScrubbingLogFormatter new];
[DDLog addLogger:self.fileLogger]; [DDLog addLogger:self.fileLogger];
@ -136,5 +133,3 @@ const NSUInteger kMaxDebugLogFileSize = 1024 * 1024 * 3;
} }
@end @end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save