diff options
Diffstat (limited to 'src/tools/mac/symupload/symupload.m')
-rw-r--r-- | src/tools/mac/symupload/symupload.m | 144 |
1 files changed, 70 insertions, 74 deletions
diff --git a/src/tools/mac/symupload/symupload.m b/src/tools/mac/symupload/symupload.m index a87dd4ea..e280947b 100644 --- a/src/tools/mac/symupload/symupload.m +++ b/src/tools/mac/symupload/symupload.m @@ -48,14 +48,11 @@ #include "HTTPPutRequest.h" #include "SymbolCollectorClient.h" -typedef enum { - SymUploadProtocolV1, - SymUploadProtocolV2 -} SymUploadProtocol; +typedef enum { SymUploadProtocolV1, SymUploadProtocolV2 } SymUploadProtocol; typedef struct { - NSString *symbolsPath; - NSString *uploadURLStr; + NSString* symbolsPath; + NSString* uploadURLStr; SymUploadProtocol symUploadProtocol; NSString* apiKey; BOOL force; @@ -63,19 +60,20 @@ typedef struct { } Options; //============================================================================= -static NSArray *ModuleDataForSymbolFile(NSString *file) { - NSFileHandle *fh = [NSFileHandle fileHandleForReadingAtPath:file]; - NSData *data = [fh readDataOfLength:1024]; - NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - NSScanner *scanner = [NSScanner scannerWithString:str]; - NSString *line; - NSMutableArray *parts = nil; +static NSArray* ModuleDataForSymbolFile(NSString* file) { + NSFileHandle* fh = [NSFileHandle fileHandleForReadingAtPath:file]; + NSData* data = [fh readDataOfLength:1024]; + NSString* str = [[NSString alloc] initWithData:data + encoding:NSUTF8StringEncoding]; + NSScanner* scanner = [NSScanner scannerWithString:str]; + NSString* line; + NSMutableArray* parts = nil; const int MODULE_ID_INDEX = 3; - + if ([scanner scanUpToString:@"\n" intoString:&line]) { parts = [[NSMutableArray alloc] init]; - NSScanner *moduleInfoScanner = [NSScanner scannerWithString:line]; - NSString *moduleInfo; + NSScanner* moduleInfoScanner = [NSScanner scannerWithString:line]; + NSString* moduleInfo; // Get everything BEFORE the module name. None of these properties // can have spaces. for (int i = 0; i <= MODULE_ID_INDEX; i++) { @@ -98,9 +96,9 @@ static NSArray *ModuleDataForSymbolFile(NSString *file) { static void StartSymUploadProtocolV1(Options* options, NSArray* moduleParts, NSString* compactedID) { - NSURL *url = [NSURL URLWithString:options->uploadURLStr]; - HTTPMultipartUpload *ul = [[HTTPMultipartUpload alloc] initWithURL:url]; - NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; + NSURL* url = [NSURL URLWithString:options->uploadURLStr]; + HTTPMultipartUpload* ul = [[HTTPMultipartUpload alloc] initWithURL:url]; + NSMutableDictionary* parameters = [NSMutableDictionary dictionary]; // Add parameters [parameters setObject:compactedID forKey:@"debug_identifier"]; @@ -112,51 +110,52 @@ static void StartSymUploadProtocolV1(Options* options, [parameters setObject:[moduleParts objectAtIndex:4] forKey:@"debug_file"]; [parameters setObject:[moduleParts objectAtIndex:4] forKey:@"code_file"]; [ul setParameters:parameters]; - - NSArray *keys = [parameters allKeys]; + + NSArray* keys = [parameters allKeys]; int count = [keys count]; for (int i = 0; i < count; ++i) { - NSString *key = [keys objectAtIndex:i]; - NSString *value = [parameters objectForKey:key]; - fprintf(stdout, "'%s' = '%s'\n", [key UTF8String], - [value UTF8String]); + NSString* key = [keys objectAtIndex:i]; + NSString* value = [parameters objectForKey:key]; + fprintf(stdout, "'%s' = '%s'\n", [key UTF8String], [value UTF8String]); } // Add file [ul addFileAtPath:options->symbolsPath name:@"symbol_file"]; // Send it - NSError *error = nil; - NSData *data = [ul send:&error]; - NSString *result = [[NSString alloc] initWithData:data + NSError* error = nil; + NSData* data = [ul send:&error]; + NSString* result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; int status = [[ul response] statusCode]; - fprintf(stdout, "Send: %s\n", error ? [[error description] UTF8String] : - "No Error"); + fprintf(stdout, "Send: %s\n", + error ? [[error description] UTF8String] : "No Error"); fprintf(stdout, "Response: %d\n", status); - fprintf(stdout, "Result: %lu bytes\n%s\n", - (unsigned long)[data length], [result UTF8String]); + fprintf(stdout, "Result: %lu bytes\n%s\n", (unsigned long)[data length], + [result UTF8String]); [result release]; [ul release]; - options->success = !error && status==200; + options->success = !error && status == 200; } //============================================================================= static void StartSymUploadProtocolV2(Options* options, - NSString* debugFile, + NSArray* moduleParts, NSString* debugID) { + options->success = NO; + + NSString* debugFile = [moduleParts objectAtIndex:4]; if (!options->force) { - SymbolStatus symbolStatus = [SymbolCollectorClient - CheckSymbolStatus:options->uploadURLStr - withAPIKey:options->apiKey - withDebugFile:debugFile - withDebugID:debugID]; + SymbolStatus symbolStatus = + [SymbolCollectorClient checkSymbolStatusOnServer:options->uploadURLStr + withAPIKey:options->apiKey + withDebugFile:debugFile + withDebugID:debugID]; if (symbolStatus == SymbolStatusFound) { fprintf(stdout, "Symbol file already exists, upload aborted." - " Use \"-f\" to overwrite.\n"); - options->success = YES; + " Use \"-f\" to overwrite.\n"); return; } else if (symbolStatus == SymbolStatusUnknown) { fprintf(stdout, "Failed to get check for existing symbol.\n"); @@ -164,21 +163,20 @@ static void StartSymUploadProtocolV2(Options* options, } } - UploadURLResponse* URLResponse = [SymbolCollectorClient - CreateUploadURL:options->uploadURLStr - withAPIKey:options->apiKey]; + UploadURLResponse* URLResponse = + [SymbolCollectorClient createUploadURLOnServer:options->uploadURLStr + withAPIKey:options->apiKey]; if (URLResponse == nil) { return; } NSURL* uploadURL = [NSURL URLWithString:[URLResponse uploadURL]]; - HTTPPutRequest* putRequest = [[HTTPPutRequest alloc] - initWithURL:uploadURL]; + HTTPPutRequest* putRequest = [[HTTPPutRequest alloc] initWithURL:uploadURL]; [putRequest setFile:options->symbolsPath]; - NSError *error = nil; + NSError* error = nil; NSData* data = [putRequest send:&error]; - NSString *result = [[NSString alloc] initWithData:data + NSString* result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; int responseCode = [[putRequest response] statusCode]; [putRequest release]; @@ -191,19 +189,19 @@ static void StartSymUploadProtocolV2(Options* options, return; } - CompleteUploadResult completeUploadResult = [SymbolCollectorClient - CompleteUpload:options->uploadURLStr + CompleteUploadResult completeUploadResult = + [SymbolCollectorClient completeUploadOnServer:options->uploadURLStr withAPIKey:options->apiKey - withUploadKey:[URLResponse uploadKey] - withDebugFile:debugFile - withDebugID:debugID]; + withUploadKey:[URLResponse uploadKey] + withDebugFile:debugFile + withDebugID:debugID]; [URLResponse release]; if (completeUploadResult == CompleteUploadResultError) { fprintf(stdout, "Failed to complete upload.\n"); return; } else if (completeUploadResult == CompleteUploadResultDuplicateData) { fprintf(stdout, "Uploaded file checksum matched existing file checksum," - " no change necessary.\n"); + " no change necessary.\n"); } else { fprintf(stdout, "Successfully sent the symbol file.\n"); } @@ -211,52 +209,50 @@ static void StartSymUploadProtocolV2(Options* options, } //============================================================================= -static void Start(Options *options) { - NSArray *moduleParts = ModuleDataForSymbolFile(options->symbolsPath); - NSMutableString *compactedID = - [NSMutableString stringWithString:[moduleParts objectAtIndex:3]]; - [compactedID replaceOccurrencesOfString:@"-" withString:@"" options:0 +static void Start(Options* options) { + NSArray* moduleParts = ModuleDataForSymbolFile(options->symbolsPath); + NSMutableString* compactedID = + [NSMutableString stringWithString:[moduleParts objectAtIndex:3]]; + [compactedID replaceOccurrencesOfString:@"-" + withString:@"" + options:0 range:NSMakeRange(0, [compactedID length])]; if (options->symUploadProtocol == SymUploadProtocolV1) { StartSymUploadProtocolV1(options, moduleParts, compactedID); } else if (options->symUploadProtocol == SymUploadProtocolV2) { - StartSymUploadProtocolV2(options, - [moduleParts objectAtIndex:4], - compactedID); + StartSymUploadProtocolV2(options, moduleParts, compactedID); } } //============================================================================= -static void -Usage(int argc, const char *argv[]) { +static void Usage(int argc, const char* argv[]) { fprintf(stderr, "Submit symbol information.\n"); fprintf(stderr, "Usage: %s [options] <symbol-file> <upload-URL>\n", argv[0]); fprintf(stderr, "<symbol-file> should be created by using the dump_syms " - "tool.\n"); + "tool.\n"); fprintf(stderr, "<upload-URL> is the destination for the upload.\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, "\t-p <protocol>: protocol to use for upload, accepts " - "[\"sym-upload-v1\", \"sym-upload-v2\"]. Default is " - "\"sym-upload-v1\".\n"); + "[\"sym-upload-v1\", \"sym-upload-v2\"]. Default is " + "\"sym-upload-v1\".\n"); fprintf(stderr, "\t-k <api-key>: secret for authentication with upload " - "server. [Only in sym-upload-v2 protocol mode]\n"); + "server. [Only in sym-upload-v2 protocol mode]\n"); fprintf(stderr, "\t-f: Overwrite symbol file on server if already present. " - "[Only in sym-upload-v2 protocol mode]\n"); + "[Only in sym-upload-v2 protocol mode]\n"); fprintf(stderr, "\t-h: Usage\n"); fprintf(stderr, "\t-?: Usage\n"); } //============================================================================= -static void -SetupOptions(int argc, const char *argv[], Options *options) { +static void SetupOptions(int argc, const char* argv[], Options* options) { // Set default value of symUploadProtocol. options->symUploadProtocol = SymUploadProtocolV1; extern int optind; char ch; - while ((ch = getopt(argc, (char * const *)argv, "p:k:hf?")) != -1) { + while ((ch = getopt(argc, (char* const*)argv, "p:k:hf?")) != -1) { switch (ch) { case 'p': if (strcmp(optarg, "sym-upload-v2") == 0) { @@ -314,8 +310,8 @@ SetupOptions(int argc, const char *argv[], Options *options) { } //============================================================================= -int main (int argc, const char * argv[]) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +int main(int argc, const char* argv[]) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; Options options; bzero(&options, sizeof(Options)); |