aboutsummaryrefslogtreecommitdiff
path: root/src/client/mac/sender
diff options
context:
space:
mode:
authornealsid <nealsid@4c0a9323-5329-0410-9bdc-e9ce6186880e>2009-06-03 21:51:33 +0000
committernealsid <nealsid@4c0a9323-5329-0410-9bdc-e9ce6186880e>2009-06-03 21:51:33 +0000
commit2eb356a68d981b87329cdbaf1ce46380b2362296 (patch)
tree525e3e5165e4d9a9181168d25a979130ebe0fcca /src/client/mac/sender
parentRemoved logging init macro from minidump_processor_unittest, since with the G... (diff)
downloadbreakpad-2eb356a68d981b87329cdbaf1ce46380b2362296.tar.xz
Support custom URL parameters. Added unit tests for Breakpad. Added
a way to specify server parameters in app plist file, as well. R=stuartmorgan, jeremy A=nealsid git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@346 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/client/mac/sender')
-rw-r--r--src/client/mac/sender/crash_report_sender.h21
-rw-r--r--src/client/mac/sender/crash_report_sender.m75
2 files changed, 73 insertions, 23 deletions
diff --git a/src/client/mac/sender/crash_report_sender.h b/src/client/mac/sender/crash_report_sender.h
index b3169538..f62e7613 100644
--- a/src/client/mac/sender/crash_report_sender.h
+++ b/src/client/mac/sender/crash_report_sender.h
@@ -69,15 +69,20 @@ extern NSString *const kDefaultServerType;
NSMutableDictionary *parameters_; // Key value pairs of data (STRONG)
NSData *minidumpContents_; // The data in the minidump (STRONG)
NSData *logFileData_; // An NSdata for the tar,
- // bz2'd log file
+ // bz2'd log file.
NSMutableDictionary *serverDictionary_; // The dictionary mapping a
// server type name to a
- // dictionary of URL
- // parameter names
+ // dictionary of server
+ // parameter names.
NSMutableDictionary *socorroDictionary_; // The dictionary for
- // Socorro
+ // Socorro.
NSMutableDictionary *googleDictionary_; // The dictionary for
- // Google
+ // Google.
+ NSMutableDictionary *extraServerVars_; // A dictionary containing
+ // extra key/value pairs
+ // that are uploaded to the
+ // crash server with the
+ // minidump.
}
// Stops the modal panel with an NSAlertDefaultReturn value. This is the action
@@ -95,9 +100,6 @@ extern NSString *const kDefaultServerType;
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView
doCommandBySelector:(SEL)commandSelector;
-// Helper method to set HTTP parameters based on server type
-- (BOOL)setPostParametersFromDictionary:(NSMutableDictionary *)crashParameters;
-
// Accessors to make bindings work
- (NSString *)commentsValue;
- (void)setCommentsValue:(NSString *)value;
@@ -105,7 +107,4 @@ extern NSString *const kDefaultServerType;
- (NSString *)emailValue;
- (void)setEmailValue:(NSString *)value;
-// Initialization helper to create dictionaries mapping Breakpad
-// parameters to URL parameters
-- (void)createServerParameterDictionaries;
@end
diff --git a/src/client/mac/sender/crash_report_sender.m b/src/client/mac/sender/crash_report_sender.m
index 43d1da08..5d76290c 100644
--- a/src/client/mac/sender/crash_report_sender.m
+++ b/src/client/mac/sender/crash_report_sender.m
@@ -115,7 +115,7 @@ NSString *const kDefaultServerType = @"google";
NSRect newFrame = NSMakeRect(oldFrame.origin.x, oldFrame.origin.y,
NSWidth(oldFrame), newSize.height);
[self setFrame:newFrame];
-
+
return newSize.height - NSHeight(oldFrame);
}
@@ -217,7 +217,24 @@ NSString *const kDefaultServerType = @"google";
// Returns a dictionary that can be used to map Breakpad parameter names to
// URL parameter names.
-- (NSDictionary *)dictionaryForServerType:(NSString *)serverType;
+- (NSMutableDictionary *)dictionaryForServerType:(NSString *)serverType;
+
+// Helper method to set HTTP parameters based on server type. This is
+// called right before the upload - crashParameters will contain, on exit,
+// URL parameters that should be sent with the minidump.
+- (BOOL)populateServerDictionary:(NSMutableDictionary *)crashParameters;
+
+// Initialization helper to create dictionaries mapping Breakpad
+// parameters to URL parameters
+- (void)createServerParameterDictionaries;
+
+// Accessor method for the URL parameter dictionary
+- (NSMutableDictionary *)urlParameterDictionary;
+
+// This method adds a key/value pair to the dictionary that
+// will be uploaded to the crash server.
+- (void)addServerParameter:(id)value forKey:(NSString *)key;
+
@end
@implementation Reporter
@@ -308,7 +325,24 @@ NSString *const kDefaultServerType = @"google";
id value = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
- [parameters_ setObject:value ? value : data forKey:key];
+ // If the keyname is prefixed by BREAKPAD_SERVER_PARAMETER_PREFIX
+ // that indicates that it should be uploaded to the server along
+ // with the minidump, so we treat it specially.
+ if ([key hasPrefix:@BREAKPAD_SERVER_PARAMETER_PREFIX]) {
+ NSString *urlParameterKey =
+ [key substringFromIndex:[@BREAKPAD_SERVER_PARAMETER_PREFIX length]];
+ if ([urlParameterKey length]) {
+ if (value) {
+ [self addServerParameter:value
+ forKey:urlParameterKey];
+ } else {
+ [self addServerParameter:data
+ forKey:urlParameterKey];
+ }
+ }
+ } else {
+ [parameters_ setObject:(value ? value : data) forKey:key];
+ }
[value release];
}
@@ -743,6 +777,7 @@ doCommandBySelector:(SEL)commandSelector {
serverDictionary_ = [[NSMutableDictionary alloc] init];
socorroDictionary_ = [[NSMutableDictionary alloc] init];
googleDictionary_ = [[NSMutableDictionary alloc] init];
+ extraServerVars_ = [[NSMutableDictionary alloc] init];
[serverDictionary_ setObject:socorroDictionary_ forKey:kSocorroServerType];
[serverDictionary_ setObject:googleDictionary_ forKey:kGoogleServerType];
@@ -752,8 +787,6 @@ doCommandBySelector:(SEL)commandSelector {
[googleDictionary_ setObject:@"comments" forKey:@BREAKPAD_COMMENTS];
[googleDictionary_ setObject:@"prod" forKey:@BREAKPAD_PRODUCT];
[googleDictionary_ setObject:@"ver" forKey:@BREAKPAD_VERSION];
- // TODO: just for testing, google's server doesn't support it
- [googleDictionary_ setObject:@"buildid" forKey:@BREAKPAD_BUILD_ID];
[socorroDictionary_ setObject:@"Comments" forKey:@BREAKPAD_COMMENTS];
[socorroDictionary_ setObject:@"CrashTime"
@@ -766,21 +799,23 @@ doCommandBySelector:(SEL)commandSelector {
forKey:@BREAKPAD_PRODUCT];
[socorroDictionary_ setObject:@"ProductName"
forKey:@BREAKPAD_PRODUCT];
- [socorroDictionary_ setObject:@"BuildID"
- forKey:@BREAKPAD_BUILD_ID];
}
-- (NSDictionary *)dictionaryForServerType:(NSString *)serverType {
+- (NSMutableDictionary *)dictionaryForServerType:(NSString *)serverType {
if (serverType == nil || [serverType length] == 0) {
return [serverDictionary_ objectForKey:kDefaultServerType];
}
return [serverDictionary_ objectForKey:serverType];
}
-// Helper method to set HTTP parameters based on server type
-- (BOOL)setPostParametersFromDictionary:(NSMutableDictionary *)crashParameters {
+- (NSMutableDictionary *)urlParameterDictionary {
NSString *serverType = [parameters_ objectForKey:@BREAKPAD_SERVER_TYPE];
- NSDictionary *urlParameterNames = [self dictionaryForServerType:serverType];
+ return [self dictionaryForServerType:serverType];
+
+}
+
+- (BOOL)populateServerDictionary:(NSMutableDictionary *)crashParameters {
+ NSDictionary *urlParameterNames = [self urlParameterDictionary];
id key;
NSEnumerator *enumerator = [parameters_ keyEnumerator];
@@ -802,16 +837,31 @@ doCommandBySelector:(SEL)commandSelector {
forKey:urlParameter];
}
}
+
+ // Now, add the parameters that were added by the application.
+ enumerator = [extraServerVars_ keyEnumerator];
+
+ while ((key = [enumerator nextObject])) {
+ NSString *urlParameterName = (NSString *)key;
+ NSString *urlParameterValue =
+ [extraServerVars_ objectForKey:urlParameterName];
+ [crashParameters setObject:urlParameterValue
+ forKey:urlParameterName];
+ }
return YES;
}
+- (void)addServerParameter:(id)value forKey:(NSString *)key {
+ [extraServerVars_ setObject:value forKey:key];
+}
+
//=============================================================================
- (void)report {
NSURL *url = [NSURL URLWithString:[parameters_ objectForKey:@BREAKPAD_URL]];
HTTPMultipartUpload *upload = [[HTTPMultipartUpload alloc] initWithURL:url];
NSMutableDictionary *uploadParameters = [NSMutableDictionary dictionary];
- if (![self setPostParametersFromDictionary:uploadParameters]) {
+ if (![self populateServerDictionary:uploadParameters]) {
return;
}
@@ -886,6 +936,7 @@ doCommandBySelector:(SEL)commandSelector {
[googleDictionary_ release];
[socorroDictionary_ release];
[serverDictionary_ release];
+ [extraServerVars_ release];
[super dealloc];
}