1 // Copyright 2011 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // 29 // This component uses the HTTPMultipartUpload of the breakpad project to send 30 // the minidump and associated data to the crash reporting servers. 31 // It will perform throttling based on the parameters passed to it and will 32 // prompt the user to send the minidump. 33 34 #include <Foundation/Foundation.h> 35 36 #import "common/mac/GTMDefines.h" 37 38 #define kClientIdPreferenceKey @"clientid" 39 40 extern NSString *const kGoogleServerType; 41 extern NSString *const kSocorroServerType; 42 extern NSString *const kDefaultServerType; 43 44 // Optional user-defined function that will be called after a network upload 45 // of a crash report. 46 // |report_id| will be the id returned by the server, or "ERR" if an error 47 // occurred. 48 // |error| will contain the error, or nil if no error occured. 49 typedef void (^UploadCompletionBlock)(NSString *reportId, NSError *error); 50 51 @interface Uploader : NSObject { 52 @private 53 NSMutableDictionary *parameters_; // Key value pairs of data (STRONG) 54 NSData *minidumpContents_; // The data in the minidump (STRONG) 55 NSData *logFileData_; // An NSdata for the tar, 56 // bz2'd log file. 57 NSMutableDictionary *serverDictionary_; // The dictionary mapping a 58 // server type name to a 59 // dictionary of server 60 // parameter names. 61 NSMutableDictionary *socorroDictionary_; // The dictionary for 62 // Socorro. 63 NSMutableDictionary *googleDictionary_; // The dictionary for 64 // Google. 65 NSMutableDictionary *extraServerVars_; // A dictionary containing 66 // extra key/value pairs 67 // that are uploaded to the 68 // crash server with the 69 // minidump. 70 UploadCompletionBlock uploadCompletion_; // A block called on network upload 71 // completion. Parameters are: 72 // The report ID returned by the 73 // server, 74 // the NSError triggered during 75 // upload. 76 } 77 78 - (id)initWithConfigFile:(const char *)configFile; 79 80 - (id)initWithConfig:(NSDictionary *)config; 81 82 // Reads the file |configFile| and returns the corresponding NSDictionary. 83 // |configFile| will be deleted after reading. 84 + (NSDictionary *)readConfigurationDataFromFile:(NSString *)configFile; 85 86 - (NSMutableDictionary *)parameters; 87 88 - (void)report; 89 90 // Upload the given data to the crash server. 91 - (void)uploadData:(NSData *)data name:(NSString *)name; 92 93 // This method adds a key/value pair to the dictionary that 94 // will be uploaded to the crash server. 95 - (void)addServerParameter:(id)value forKey:(NSString *)key; 96 97 // This method process the HTTP response and renames the minidump file with the 98 // new ID. 99 - (void)handleNetworkResponse:(NSData *)data withError:(NSError *)error; 100 101 // Sets the callback to be called after uploading a crash report to the server. 102 // Only the latest callback registered will be called. 103 - (void)setUploadCompletionBlock:(UploadCompletionBlock)uploadCompletion; 104 105 @end 106