mirror of
https://git.suyu.dev/suyu/breakpad.git
synced 2026-03-12 19:46:28 +00:00
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 <olivierrobin@chromium.org> Review URL: https://breakpad.appspot.com/2764002/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1368 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
@@ -67,6 +67,10 @@ extern NSString *const kDefaultServerType;
|
||||
|
||||
- (id)initWithConfig:(NSDictionary *)config;
|
||||
|
||||
// Reads the file |configFile| and returns the corresponding NSDictionary.
|
||||
// |configFile| will be deleted after reading.
|
||||
+ (NSDictionary *)readConfigurationDataFromFile:(NSString *)configFile;
|
||||
|
||||
- (NSMutableDictionary *)parameters;
|
||||
|
||||
- (void)report;
|
||||
@@ -78,4 +82,8 @@ extern NSString *const kDefaultServerType;
|
||||
// will be uploaded to the crash server.
|
||||
- (void)addServerParameter:(id)value forKey:(NSString *)key;
|
||||
|
||||
// This method process the HTTP response and renames the minidump file with the
|
||||
// new ID.
|
||||
- (void)handleNetworkResponse:(NSData *)data withError:(NSError *)error;
|
||||
|
||||
@end
|
||||
|
||||
@@ -204,6 +204,11 @@ NSDictionary *readConfigurationData(const char *configFile) {
|
||||
return self;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
+ (NSDictionary *)readConfigurationDataFromFile:(NSString *)configFile {
|
||||
return readConfigurationData([configFile fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
- (void)translateConfigurationData:(NSDictionary *)config {
|
||||
parameters_ = [[NSMutableDictionary alloc] init];
|
||||
@@ -486,6 +491,46 @@ NSDictionary *readConfigurationData(const char *configFile) {
|
||||
[extraServerVars_ setObject:value forKey:key];
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
- (void)handleNetworkResponse:(NSData *)data withError:(NSError *)error {
|
||||
NSString *result = [[NSString alloc] initWithData:data
|
||||
encoding:NSUTF8StringEncoding];
|
||||
const char *reportID = "ERR";
|
||||
if (error) {
|
||||
fprintf(stderr, "Breakpad Uploader: Send Error: %s\n",
|
||||
[[error description] UTF8String]);
|
||||
} else {
|
||||
NSCharacterSet *trimSet =
|
||||
[NSCharacterSet whitespaceAndNewlineCharacterSet];
|
||||
reportID = [[result stringByTrimmingCharactersInSet:trimSet] UTF8String];
|
||||
[self logUploadWithID:reportID];
|
||||
}
|
||||
|
||||
// rename the minidump file according to the id returned from the server
|
||||
NSString *minidumpDir =
|
||||
[parameters_ objectForKey:@kReporterMinidumpDirectoryKey];
|
||||
NSString *minidumpID = [parameters_ objectForKey:@kReporterMinidumpIDKey];
|
||||
|
||||
NSString *srcString = [NSString stringWithFormat:@"%@/%@.dmp",
|
||||
minidumpDir, minidumpID];
|
||||
NSString *destString = [NSString stringWithFormat:@"%@/%s.dmp",
|
||||
minidumpDir, reportID];
|
||||
|
||||
const char *src = [srcString fileSystemRepresentation];
|
||||
const char *dest = [destString fileSystemRepresentation];
|
||||
|
||||
if (rename(src, dest) == 0) {
|
||||
GTMLoggerInfo(@"Breakpad Uploader: Renamed %s to %s after successful " \
|
||||
"upload",src, dest);
|
||||
}
|
||||
else {
|
||||
// can't rename - don't worry - it's not important for users
|
||||
GTMLoggerDebug(@"Breakpad Uploader: successful upload report ID = %s\n",
|
||||
reportID );
|
||||
}
|
||||
[result release];
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
- (void)report {
|
||||
NSURL *url = [NSURL URLWithString:[parameters_ objectForKey:@BREAKPAD_URL]];
|
||||
@@ -511,43 +556,16 @@ NSDictionary *readConfigurationData(const char *configFile) {
|
||||
// Send it
|
||||
NSError *error = nil;
|
||||
NSData *data = [upload send:&error];
|
||||
NSString *result = [[NSString alloc] initWithData:data
|
||||
encoding:NSUTF8StringEncoding];
|
||||
const char *reportID = "ERR";
|
||||
|
||||
if (error) {
|
||||
fprintf(stderr, "Breakpad Uploader: Send Error: %s\n",
|
||||
[[error description] UTF8String]);
|
||||
if (![url isFileURL]) {
|
||||
[self handleNetworkResponse:data withError:error];
|
||||
} else {
|
||||
NSCharacterSet *trimSet =
|
||||
[NSCharacterSet whitespaceAndNewlineCharacterSet];
|
||||
reportID = [[result stringByTrimmingCharactersInSet:trimSet] UTF8String];
|
||||
[self logUploadWithID:reportID];
|
||||
if (error) {
|
||||
fprintf(stderr, "Breakpad Uploader: Error writing request file: %s\n",
|
||||
[[error description] UTF8String]);
|
||||
}
|
||||
}
|
||||
|
||||
// rename the minidump file according to the id returned from the server
|
||||
NSString *minidumpDir =
|
||||
[parameters_ objectForKey:@kReporterMinidumpDirectoryKey];
|
||||
NSString *minidumpID = [parameters_ objectForKey:@kReporterMinidumpIDKey];
|
||||
|
||||
NSString *srcString = [NSString stringWithFormat:@"%@/%@.dmp",
|
||||
minidumpDir, minidumpID];
|
||||
NSString *destString = [NSString stringWithFormat:@"%@/%s.dmp",
|
||||
minidumpDir, reportID];
|
||||
|
||||
const char *src = [srcString fileSystemRepresentation];
|
||||
const char *dest = [destString fileSystemRepresentation];
|
||||
|
||||
if (rename(src, dest) == 0) {
|
||||
GTMLoggerInfo(@"Breakpad Uploader: Renamed %s to %s after successful " \
|
||||
"upload",src, dest);
|
||||
}
|
||||
else {
|
||||
// can't rename - don't worry - it's not important for users
|
||||
GTMLoggerDebug(@"Breakpad Uploader: successful upload report ID = %s\n",
|
||||
reportID );
|
||||
}
|
||||
[result release];
|
||||
} else {
|
||||
// Minidump is missing -- upload just the log file.
|
||||
if (logFileData_) {
|
||||
|
||||
Reference in New Issue
Block a user