From fb22e8022954a06c9d738d4a5d231db67ce1ebf4 Mon Sep 17 00:00:00 2001 From: "ivan.penkov@gmail.com" Date: Tue, 23 Apr 2013 21:04:31 +0000 Subject: This change allows compiling sym_upload.cc and minidump_upload.cc using a global ::string class instead of std::string. For more details take a look at common/using_std_string.h A few other fixes: - getopt() returns (int)(-1) when options are exhausted. This was already sent out for code review by mattdr but only for sym_upload.cc (https://breakpad.appspot.com/561002/). I'm applying the fix for both files. - Fixed a couple of lint warning about improper usage of white-spaces. Thanks, -Ivan Review URL: https://breakpad.appspot.com/567002 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1158 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/tools/linux/symupload/minidump_upload.cc | 28 ++++++++------- src/tools/linux/symupload/sym_upload.cc | 52 +++++++++++++++------------- 2 files changed, 42 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/tools/linux/symupload/minidump_upload.cc b/src/tools/linux/symupload/minidump_upload.cc index 144c8bf6..94c3492c 100644 --- a/src/tools/linux/symupload/minidump_upload.cc +++ b/src/tools/linux/symupload/minidump_upload.cc @@ -41,28 +41,29 @@ #include #include "common/linux/http_upload.h" +#include "common/using_std_string.h" using google_breakpad::HTTPUpload; struct Options { - std::string minidumpPath; - std::string uploadURLStr; - std::string product; - std::string version; - std::string proxy; - std::string proxy_user_pwd; + string minidumpPath; + string uploadURLStr; + string product; + string version; + string proxy; + string proxy_user_pwd; bool success; }; //============================================================================= static void Start(Options *options) { - std::map parameters; + std::map parameters; // Add parameters parameters["prod"] = options->product; parameters["ver"] = options->version; // Send it - std::string response, error; + string response, error; bool success = HTTPUpload::SendRequest(options->uploadURLStr, parameters, options->minidumpPath, @@ -78,9 +79,9 @@ static void Start(Options *options) { printf("Successfully sent the minidump file.\n"); } else { printf("Failed to send minidump: %s\n", error.c_str()); - printf("Response:\n"); - printf("%s\n", response.c_str()); } + printf("Response:\n"); + printf("%s\n", response.c_str()); options->success = success; } @@ -106,7 +107,7 @@ Usage(int argc, const char *argv[]) { static void SetupOptions(int argc, const char *argv[], Options *options) { extern int optind; - char ch; + int ch; while ((ch = getopt(argc, (char * const *)argv, "p:u:v:x:h?")) != -1) { switch (ch) { @@ -124,8 +125,9 @@ SetupOptions(int argc, const char *argv[], Options *options) { break; default: + fprintf(stderr, "Invalid option '%c'\n", ch); Usage(argc, argv); - exit(0); + exit(1); break; } } @@ -141,7 +143,7 @@ SetupOptions(int argc, const char *argv[], Options *options) { } //============================================================================= -int main (int argc, const char * argv[]) { +int main(int argc, const char* argv[]) { Options options; SetupOptions(argc, argv, &options); Start(&options); diff --git a/src/tools/linux/symupload/sym_upload.cc b/src/tools/linux/symupload/sym_upload.cc index 5b1ee6f6..75ad206a 100644 --- a/src/tools/linux/symupload/sym_upload.cc +++ b/src/tools/linux/symupload/sym_upload.cc @@ -50,23 +50,24 @@ #include #include "common/linux/http_upload.h" +#include "common/using_std_string.h" using google_breakpad::HTTPUpload; typedef struct { - std::string symbolsPath; - std::string uploadURLStr; - std::string proxy; - std::string proxy_user_pwd; - std::string version; + string symbolsPath; + string uploadURLStr; + string proxy; + string proxy_user_pwd; + string version; bool success; } Options; -static void TokenizeByChar(const std::string &source_string, - int c, std::vector *results) { +static void TokenizeByChar(const string &source_string, + int c, std::vector *results) { assert(results); - std::string::size_type cur_pos = 0, next_pos = 0; - while ((next_pos = source_string.find(c, cur_pos)) != std::string::npos) { + string::size_type cur_pos = 0, next_pos = 0; + while ((next_pos = source_string.find(c, cur_pos)) != string::npos) { if (next_pos != cur_pos) results->push_back(source_string.substr(cur_pos, next_pos - cur_pos)); cur_pos = next_pos + 1; @@ -78,17 +79,17 @@ static void TokenizeByChar(const std::string &source_string, //============================================================================= // Parse out the module line which have 5 parts. // MODULE -static bool ModuleDataForSymbolFile(const std::string &file, - std::vector *module_parts) { +static bool ModuleDataForSymbolFile(const string &file, + std::vector *module_parts) { assert(module_parts); const size_t kModulePartNumber = 5; - FILE *fp = fopen(file.c_str(), "r"); + FILE* fp = fopen(file.c_str(), "r"); if (fp) { char buffer[1024]; if (fgets(buffer, sizeof(buffer), fp)) { - std::string line(buffer); - std::string::size_type line_break_pos = line.find_first_of('\n'); - if (line_break_pos == std::string::npos) { + string line(buffer); + string::size_type line_break_pos = line.find_first_of('\n'); + if (line_break_pos == string::npos) { assert(0 && "The file is invalid!"); fclose(fp); return false; @@ -106,10 +107,10 @@ static bool ModuleDataForSymbolFile(const std::string &file, } //============================================================================= -static std::string CompactIdentifier(const std::string &uuid) { - std::vector components; +static string CompactIdentifier(const string &uuid) { + std::vector components; TokenizeByChar(uuid, '-', &components); - std::string result; + string result; for (size_t i = 0; i < components.size(); ++i) result += components[i]; return result; @@ -117,15 +118,15 @@ static std::string CompactIdentifier(const std::string &uuid) { //============================================================================= static void Start(Options *options) { - std::map parameters; + std::map parameters; options->success = false; - std::vector module_parts; + std::vector module_parts; if (!ModuleDataForSymbolFile(options->symbolsPath, &module_parts)) { fprintf(stderr, "Failed to parse symbol file!\n"); return; } - std::string compacted_id = CompactIdentifier(module_parts[3]); + string compacted_id = CompactIdentifier(module_parts[3]); // Add parameters if (!options->version.empty()) @@ -138,7 +139,7 @@ static void Start(Options *options) { parameters["debug_file"] = module_parts[4]; parameters["code_file"] = module_parts[4]; parameters["debug_identifier"] = compacted_id; - std::string response, error; + string response, error; long response_code; bool success = HTTPUpload::SendRequest(options->uploadURLStr, parameters, @@ -186,7 +187,7 @@ Usage(int argc, const char *argv[]) { static void SetupOptions(int argc, const char *argv[], Options *options) { extern int optind; - char ch; + int ch; while ((ch = getopt(argc, (char * const *)argv, "u:v:x:h?")) != -1) { switch (ch) { @@ -201,8 +202,9 @@ SetupOptions(int argc, const char *argv[], Options *options) { break; default: + fprintf(stderr, "Invalid option '%c'\n", ch); Usage(argc, argv); - exit(0); + exit(1); break; } } @@ -218,7 +220,7 @@ SetupOptions(int argc, const char *argv[], Options *options) { } //============================================================================= -int main (int argc, const char * argv[]) { +int main(int argc, const char* argv[]) { Options options; SetupOptions(argc, argv, &options); Start(&options); -- cgit v1.2.1