ios/Mobile/AppDelegate.mm | 119 ++++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 41 deletions(-)
New commits: commit bf520d5fa5d0595ddc3d06402861a9ac3bf51f95 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Fri Apr 26 12:01:25 2019 +0300 Commit: Tor Lillqvist <t...@collabora.com> CommitDate: Fri Apr 26 12:04:28 2019 +0300 Log the timestamp of the template file at its site and of its cached version diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm index d1ec58119..5cbc51da3 100644 --- a/ios/Mobile/AppDelegate.mm +++ b/ios/Mobile/AppDelegate.mm @@ -130,6 +130,10 @@ static void updateTemplates(NSData *data, NSURLResponse *response) NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate]; + LOG_INF("Template at " << [[url absoluteString] UTF8String] << " timestamp: " + << [[templateDate descriptionWithLocale:nil] UTF8String] << ", cached template timestamp: " + << [[cachedTemplateDate descriptionWithLocale:nil] UTF8String]); + if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) { downloadTemplate(url, fileForTemplate); } commit db9208d36417490ea1a0a536c701233279a49e0d Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Fri Apr 26 11:44:28 2019 +0300 Commit: Tor Lillqvist <t...@collabora.com> CommitDate: Fri Apr 26 12:04:20 2019 +0300 tdf#124918: Don't crash on invalid URLs in the template list file diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm index d01712931..d1ec58119 100644 --- a/ios/Mobile/AppDelegate.mm +++ b/ios/Mobile/AppDelegate.mm @@ -102,51 +102,55 @@ static void updateTemplates(NSData *data, NSURLResponse *response) NSString *line = [NSString stringWithUTF8String:buf.data()]; NSURL *url = [NSURL URLWithString:line]; - NSString *baseName = [url lastPathComponent]; - - NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0]; - [urlHashes addObject:hash]; - - NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash]; - - NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]]; - - // If we have that template, check whether it is up-to-date - BOOL isDirectory; - if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] && - isDirectory) { - NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy]; - [req setHTTPMethod:@"HEAD"]; - [[[NSURLSession sharedSession] dataTaskWithRequest:req - completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) { - NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"]; - NSDateFormatter *df = [[NSDateFormatter alloc] init]; - df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z"; - NSDate *templateDate = [df dateFromString:lastModified]; - - NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate]; - - if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) { - downloadTemplate(url, fileForTemplate); + if (url == nil) + LOG_ERR("Invalid URL in template file: " << [line UTF8String]); + else { + NSString *baseName = [url lastPathComponent]; + + NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0]; + [urlHashes addObject:hash]; + + NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash]; + + NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]]; + + // If we have that template, check whether it is up-to-date + BOOL isDirectory; + if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] && + isDirectory) { + NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy]; + [req setHTTPMethod:@"HEAD"]; + [[[NSURLSession sharedSession] dataTaskWithRequest:req + completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) { + NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"]; + NSDateFormatter *df = [[NSDateFormatter alloc] init]; + df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z"; + NSDate *templateDate = [df dateFromString:lastModified]; + + NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate]; + + if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) { + downloadTemplate(url, fileForTemplate); + } + } else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) { + LOG_ERR("Failed to get HEAD of " << + [[url absoluteString] UTF8String] << + ": response code " << [(NSHTTPURLResponse*)response statusCode]); + } else if (error != nil) { + LOG_ERR("Failed to get HEAD of " << + [[url absoluteString] UTF8String] << + ": " << [[error description] UTF8String]); + } else { + LOG_ERR("Failed to get HEAD of " << + [[url absoluteString] UTF8String]); } - } else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) { - LOG_ERR("Failed to get HEAD of " << - [[url absoluteString] UTF8String] << - ": response code " << [(NSHTTPURLResponse*)response statusCode]); - } else if (error != nil) { - LOG_ERR("Failed to get HEAD of " << - [[url absoluteString] UTF8String] << - ": " << [[error description] UTF8String]); - } else { - LOG_ERR("Failed to get HEAD of " << - [[url absoluteString] UTF8String]); - } - }] resume]; - } else { - // Else download it. - [[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil]; - downloadTemplate(url, fileForTemplate); + }] resume]; + } else { + // Else download it. + [[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil]; + downloadTemplate(url, fileForTemplate); + } } } } commit d550944053cca481e3bae1e981b16a23132c0126 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Fri Apr 26 11:28:39 2019 +0300 Commit: Tor Lillqvist <t...@collabora.com> CommitDate: Fri Apr 26 12:04:09 2019 +0300 tdf#124918: More logging in template download error situations diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm index a9aecf080..d01712931 100644 --- a/ios/Mobile/AppDelegate.mm +++ b/ios/Mobile/AppDelegate.mm @@ -49,6 +49,10 @@ static void download(NSURL *source, NSURL *destination) { " with " << [[location absoluteString] UTF8String] << ": " << [[error description] UTF8String]); } + } else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) { + LOG_ERR("Failed to download " << + [[source absoluteString] UTF8String] << + ": response code " << [(NSHTTPURLResponse*)response statusCode]); } else if (error != nil) { LOG_ERR("Failed to download " << [[source absoluteString] UTF8String] << @@ -126,6 +130,17 @@ static void updateTemplates(NSData *data, NSURLResponse *response) if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) { downloadTemplate(url, fileForTemplate); } + } else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) { + LOG_ERR("Failed to get HEAD of " << + [[url absoluteString] UTF8String] << + ": response code " << [(NSHTTPURLResponse*)response statusCode]); + } else if (error != nil) { + LOG_ERR("Failed to get HEAD of " << + [[url absoluteString] UTF8String] << + ": " << [[error description] UTF8String]); + } else { + LOG_ERR("Failed to get HEAD of " << + [[url absoluteString] UTF8String]); } }] resume]; } else { @@ -184,6 +199,17 @@ static void updateTemplates(NSData *data, NSURLResponse *response) completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) updateTemplates(data, response); + else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) + LOG_ERR("Failed to download " << + [[url absoluteString] UTF8String] << + ": response code " << [(NSHTTPURLResponse*)response statusCode]); + else if (error != nil) + LOG_ERR("Failed to download " << + [[url absoluteString] UTF8String] << + ": " << [[error description] UTF8String]); + else + LOG_ERR("Failed to download " << + [[url absoluteString] UTF8String]); }] resume]; } } commit 4e2ad4d2bc018584c074d91b6d5927c5c2b905bf Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Fri Apr 26 10:46:12 2019 +0300 Commit: Tor Lillqvist <t...@collabora.com> CommitDate: Fri Apr 26 12:04:01 2019 +0300 tdf#124918: Allow empty lines in the template list file diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm index a6b1827d3..a9aecf080 100644 --- a/ios/Mobile/AppDelegate.mm +++ b/ios/Mobile/AppDelegate.mm @@ -89,47 +89,50 @@ static void updateTemplates(NSData *data, NSURLResponse *response) // Allow comment lines staring with a hash sign. if (*p != '#') { const int length = endOfLine - p; - std::vector<char> buf(length+1); - std::memcpy(buf.data(), p, length); - buf[length] = 0; - - NSString *line = [NSString stringWithUTF8String:buf.data()]; - - NSURL *url = [NSURL URLWithString:line]; - NSString *baseName = [url lastPathComponent]; - - NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0]; - [urlHashes addObject:hash]; - - NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash]; - - NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]]; - - // If we have that template, check whether it is up-to-date - BOOL isDirectory; - if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] && - isDirectory) { - NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy]; - [req setHTTPMethod:@"HEAD"]; - [[[NSURLSession sharedSession] dataTaskWithRequest:req - completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) { - NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"]; - NSDateFormatter *df = [[NSDateFormatter alloc] init]; - df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z"; - NSDate *templateDate = [df dateFromString:lastModified]; - - NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate]; - - if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) { - downloadTemplate(url, fileForTemplate); + // Allow empty lines + if (length > 0) { + std::vector<char> buf(length+1); + std::memcpy(buf.data(), p, length); + buf[length] = 0; + + NSString *line = [NSString stringWithUTF8String:buf.data()]; + + NSURL *url = [NSURL URLWithString:line]; + NSString *baseName = [url lastPathComponent]; + + NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0]; + [urlHashes addObject:hash]; + + NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash]; + + NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]]; + + // If we have that template, check whether it is up-to-date + BOOL isDirectory; + if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] && + isDirectory) { + NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy]; + [req setHTTPMethod:@"HEAD"]; + [[[NSURLSession sharedSession] dataTaskWithRequest:req + completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) { + NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"]; + NSDateFormatter *df = [[NSDateFormatter alloc] init]; + df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z"; + NSDate *templateDate = [df dateFromString:lastModified]; + + NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate]; + + if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) { + downloadTemplate(url, fileForTemplate); + } } - } - }] resume]; - } else { - // Else download it. - [[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil]; - downloadTemplate(url, fileForTemplate); + }] resume]; + } else { + // Else download it. + [[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil]; + downloadTemplate(url, fileForTemplate); + } } } if (endOfLine < endOfData) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits