From 1335417f9feefd20e5b0e4b1e18e9010edb87043 Mon Sep 17 00:00:00 2001 From: "blundell@chromium.org" Date: Mon, 1 Sep 2014 11:02:57 +0000 Subject: Adding possibility for client to upload the file This CL adds three features that will allow the client to upload the report file. Three main modifications are made : - Allow upload url to have a file:// scheme, and write the HTTP request to file in that case - Split the request in two parts in case of a file:// scheme, the request time and the response time. A new API [handleNetworkResponse] is added. - Give the opportunity to the client to get the configuration NSDictionary to be able to recreate the breakpad context at response time. Patch by Olivier Robin Review URL: https://breakpad.appspot.com/2764002/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1368 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/client/ios/Breakpad.mm | 103 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 15 deletions(-) (limited to 'src/client/ios/Breakpad.mm') diff --git a/src/client/ios/Breakpad.mm b/src/client/ios/Breakpad.mm index 5c4043c4..ca856f8f 100644 --- a/src/client/ios/Breakpad.mm +++ b/src/client/ios/Breakpad.mm @@ -152,9 +152,15 @@ class Breakpad { void RemoveKeyValue(NSString *key); NSArray *CrashReportsToUpload(); NSString *NextCrashReportToUpload(); + NSDictionary *NextCrashReportConfiguration(); void UploadNextReport(NSDictionary *server_parameters); + void UploadReportWithConfiguration(NSDictionary *configuration, + NSDictionary *server_parameters); void UploadData(NSData *data, NSString *name, NSDictionary *server_parameters); + void HandleNetworkResponse(NSDictionary *configuration, + NSData *data, + NSError *error); NSDictionary *GenerateReport(NSDictionary *server_parameters); private: @@ -448,19 +454,39 @@ NSString *Breakpad::NextCrashReportToUpload() { return [NSString stringWithFormat:@"%@/%@", directory, config]; } +//============================================================================= +NSDictionary *Breakpad::NextCrashReportConfiguration() { + return [Uploader readConfigurationDataFromFile:NextCrashReportToUpload()]; +} + +//============================================================================= +void Breakpad::HandleNetworkResponse(NSDictionary *configuration, + NSData *data, + NSError *error) { + Uploader *uploader = [[[Uploader alloc] + initWithConfig:configuration] autorelease]; + [uploader handleNetworkResponse:data withError:error]; +} + +//============================================================================= +void Breakpad::UploadReportWithConfiguration(NSDictionary *configuration, + NSDictionary *server_parameters) { + Uploader *uploader = [[[Uploader alloc] + initWithConfig:configuration] autorelease]; + if (!uploader) + return; + for (NSString *key in server_parameters) { + [uploader addServerParameter:[server_parameters objectForKey:key] + forKey:key]; + } + [uploader report]; +} + //============================================================================= void Breakpad::UploadNextReport(NSDictionary *server_parameters) { - NSString *configFile = NextCrashReportToUpload(); - if (configFile) { - Uploader *uploader = [[[Uploader alloc] - initWithConfigFile:[configFile UTF8String]] autorelease]; - if (uploader) { - for (NSString *key in server_parameters) { - [uploader addServerParameter:[server_parameters objectForKey:key] - forKey:key]; - } - [uploader report]; - } + NSDictionary *configuration = NextCrashReportConfiguration(); + if (configuration) { + return UploadReportWithConfiguration(configuration, server_parameters); } } @@ -794,18 +820,65 @@ void BreakpadUploadNextReport(BreakpadRef ref) { BreakpadUploadNextReportWithParameters(ref, nil); } +//============================================================================= +NSDictionary *BreakpadGetNextReportConfiguration(BreakpadRef ref) { + try { + Breakpad *breakpad = (Breakpad *)ref; + if (breakpad) + return breakpad->NextCrashReportConfiguration(); + } catch(...) { // don't let exceptions leave this C API + fprintf(stderr, "BreakpadGetNextReportConfiguration() : error\n"); + } + return nil; +} + +//============================================================================= +void BreakpadUploadReportWithParametersAndConfiguration( + BreakpadRef ref, + NSDictionary *server_parameters, + NSDictionary *configuration) { + try { + Breakpad *breakpad = (Breakpad *)ref; + if (!breakpad || !configuration) + return; + breakpad->UploadReportWithConfiguration(configuration, server_parameters); + } catch(...) { // don't let exceptions leave this C API + fprintf(stderr, + "BreakpadUploadReportWithParametersAndConfiguration() : error\n"); + } + +} + //============================================================================= void BreakpadUploadNextReportWithParameters(BreakpadRef ref, NSDictionary *server_parameters) { + try { + Breakpad *breakpad = (Breakpad *)ref; + if (!breakpad) + return; + NSDictionary *configuration = breakpad->NextCrashReportConfiguration(); + if (!configuration) + return; + return BreakpadUploadReportWithParametersAndConfiguration(ref, + server_parameters, + configuration); + } catch(...) { // don't let exceptions leave this C API + fprintf(stderr, "BreakpadUploadNextReportWithParameters() : error\n"); + } +} + +void BreakpadHandleNetworkResponse(BreakpadRef ref, + NSDictionary *configuration, + NSData *data, + NSError *error) { try { // Not called at exception time Breakpad *breakpad = (Breakpad *)ref; + if (breakpad && configuration) + breakpad->HandleNetworkResponse(configuration,data, error); - if (breakpad) { - breakpad->UploadNextReport(server_parameters); - } } catch(...) { // don't let exceptions leave this C API - fprintf(stderr, "BreakpadUploadNextReport() : error\n"); + fprintf(stderr, "BreakpadHandleNetworkResponse() : error\n"); } } -- cgit v1.2.1