toolkit/crashreporter/google-breakpad/src/tools/mac/symupload/minidump_upload.m

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // Copyright (c) 2006, Google Inc.
michael@0 2 // All rights reserved.
michael@0 3 //
michael@0 4 // Redistribution and use in source and binary forms, with or without
michael@0 5 // modification, are permitted provided that the following conditions are
michael@0 6 // met:
michael@0 7 //
michael@0 8 // * Redistributions of source code must retain the above copyright
michael@0 9 // notice, this list of conditions and the following disclaimer.
michael@0 10 // * Redistributions in binary form must reproduce the above
michael@0 11 // copyright notice, this list of conditions and the following disclaimer
michael@0 12 // in the documentation and/or other materials provided with the
michael@0 13 // distribution.
michael@0 14 // * Neither the name of Google Inc. nor the names of its
michael@0 15 // contributors may be used to endorse or promote products derived from
michael@0 16 // this software without specific prior written permission.
michael@0 17 //
michael@0 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29
michael@0 30 // minidump_upload.m: Upload a minidump to a HTTP server. The upload is sent as
michael@0 31 // a multipart/form-data POST request with the following parameters:
michael@0 32 // prod: the product name
michael@0 33 // ver: the product version
michael@0 34 // symbol_file: the breakpad format symbol file
michael@0 35
michael@0 36 #import <unistd.h>
michael@0 37
michael@0 38 #import <Foundation/Foundation.h>
michael@0 39
michael@0 40 #import "common/mac/HTTPMultipartUpload.h"
michael@0 41
michael@0 42 typedef struct {
michael@0 43 NSString *minidumpPath;
michael@0 44 NSString *uploadURLStr;
michael@0 45 NSString *product;
michael@0 46 NSString *version;
michael@0 47 BOOL success;
michael@0 48 } Options;
michael@0 49
michael@0 50 //=============================================================================
michael@0 51 static void Start(Options *options) {
michael@0 52 NSURL *url = [NSURL URLWithString:options->uploadURLStr];
michael@0 53 HTTPMultipartUpload *ul = [[HTTPMultipartUpload alloc] initWithURL:url];
michael@0 54 NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
michael@0 55
michael@0 56 // Add parameters
michael@0 57 [parameters setObject:options->product forKey:@"prod"];
michael@0 58 [parameters setObject:options->version forKey:@"ver"];
michael@0 59 [ul setParameters:parameters];
michael@0 60
michael@0 61 // Add file
michael@0 62 [ul addFileAtPath:options->minidumpPath name:@"upload_file_minidump"];
michael@0 63
michael@0 64 // Send it
michael@0 65 NSError *error = nil;
michael@0 66 NSData *data = [ul send:&error];
michael@0 67 NSString *result = [[NSString alloc] initWithData:data
michael@0 68 encoding:NSUTF8StringEncoding];
michael@0 69
michael@0 70 NSLog(@"Send: %@", error ? [error description] : @"No Error");
michael@0 71 NSLog(@"Response: %d", [[ul response] statusCode]);
michael@0 72 NSLog(@"Result: %d bytes\n%@", [data length], result);
michael@0 73
michael@0 74 [result release];
michael@0 75 [ul release];
michael@0 76 options->success = !error;
michael@0 77 }
michael@0 78
michael@0 79 //=============================================================================
michael@0 80 static void
michael@0 81 Usage(int argc, const char *argv[]) {
michael@0 82 fprintf(stderr, "Submit minidump information.\n");
michael@0 83 fprintf(stderr, "Usage: %s -p <product> -v <version> <minidump> "
michael@0 84 "<upload-URL>\n", argv[0]);
michael@0 85 fprintf(stderr, "<minidump> should be a minidump.\n");
michael@0 86 fprintf(stderr, "<upload-URL> is the destination for the upload\n");
michael@0 87
michael@0 88 fprintf(stderr, "\t-h: Usage\n");
michael@0 89 fprintf(stderr, "\t-?: Usage\n");
michael@0 90 }
michael@0 91
michael@0 92 //=============================================================================
michael@0 93 static void
michael@0 94 SetupOptions(int argc, const char *argv[], Options *options) {
michael@0 95 extern int optind;
michael@0 96 char ch;
michael@0 97
michael@0 98 while ((ch = getopt(argc, (char * const *)argv, "p:v:h?")) != -1) {
michael@0 99 switch (ch) {
michael@0 100 case 'p':
michael@0 101 options->product = [NSString stringWithUTF8String:optarg];
michael@0 102 break;
michael@0 103 case 'v':
michael@0 104 options->version = [NSString stringWithUTF8String:optarg];
michael@0 105 break;
michael@0 106
michael@0 107 default:
michael@0 108 Usage(argc, argv);
michael@0 109 exit(0);
michael@0 110 break;
michael@0 111 }
michael@0 112 }
michael@0 113
michael@0 114 if ((argc - optind) != 2) {
michael@0 115 fprintf(stderr, "%s: Missing symbols file and/or upload-URL\n", argv[0]);
michael@0 116 Usage(argc, argv);
michael@0 117 exit(1);
michael@0 118 }
michael@0 119
michael@0 120 options->minidumpPath = [NSString stringWithUTF8String:argv[optind]];
michael@0 121 options->uploadURLStr = [NSString stringWithUTF8String:argv[optind + 1]];
michael@0 122 }
michael@0 123
michael@0 124 //=============================================================================
michael@0 125 int main (int argc, const char * argv[]) {
michael@0 126 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
michael@0 127 Options options;
michael@0 128
michael@0 129 bzero(&options, sizeof(Options));
michael@0 130 SetupOptions(argc, argv, &options);
michael@0 131 Start(&options);
michael@0 132
michael@0 133 [pool release];
michael@0 134 return options.success ? 0 : 1;
michael@0 135 }

mercurial