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
This commit is contained in:
ivan.penkov@gmail.com 2013-04-23 21:04:31 +00:00
parent 40c9de4d8d
commit fb22e80229
2 changed files with 42 additions and 38 deletions

View file

@ -41,28 +41,29 @@
#include <string> #include <string>
#include "common/linux/http_upload.h" #include "common/linux/http_upload.h"
#include "common/using_std_string.h"
using google_breakpad::HTTPUpload; using google_breakpad::HTTPUpload;
struct Options { struct Options {
std::string minidumpPath; string minidumpPath;
std::string uploadURLStr; string uploadURLStr;
std::string product; string product;
std::string version; string version;
std::string proxy; string proxy;
std::string proxy_user_pwd; string proxy_user_pwd;
bool success; bool success;
}; };
//============================================================================= //=============================================================================
static void Start(Options *options) { static void Start(Options *options) {
std::map<std::string, std::string> parameters; std::map<string, string> parameters;
// Add parameters // Add parameters
parameters["prod"] = options->product; parameters["prod"] = options->product;
parameters["ver"] = options->version; parameters["ver"] = options->version;
// Send it // Send it
std::string response, error; string response, error;
bool success = HTTPUpload::SendRequest(options->uploadURLStr, bool success = HTTPUpload::SendRequest(options->uploadURLStr,
parameters, parameters,
options->minidumpPath, options->minidumpPath,
@ -78,9 +79,9 @@ static void Start(Options *options) {
printf("Successfully sent the minidump file.\n"); printf("Successfully sent the minidump file.\n");
} else { } else {
printf("Failed to send minidump: %s\n", error.c_str()); 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; options->success = success;
} }
@ -106,7 +107,7 @@ Usage(int argc, const char *argv[]) {
static void static void
SetupOptions(int argc, const char *argv[], Options *options) { SetupOptions(int argc, const char *argv[], Options *options) {
extern int optind; extern int optind;
char ch; int ch;
while ((ch = getopt(argc, (char * const *)argv, "p:u:v:x:h?")) != -1) { while ((ch = getopt(argc, (char * const *)argv, "p:u:v:x:h?")) != -1) {
switch (ch) { switch (ch) {
@ -124,8 +125,9 @@ SetupOptions(int argc, const char *argv[], Options *options) {
break; break;
default: default:
fprintf(stderr, "Invalid option '%c'\n", ch);
Usage(argc, argv); Usage(argc, argv);
exit(0); exit(1);
break; 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; Options options;
SetupOptions(argc, argv, &options); SetupOptions(argc, argv, &options);
Start(&options); Start(&options);

View file

@ -50,23 +50,24 @@
#include <vector> #include <vector>
#include "common/linux/http_upload.h" #include "common/linux/http_upload.h"
#include "common/using_std_string.h"
using google_breakpad::HTTPUpload; using google_breakpad::HTTPUpload;
typedef struct { typedef struct {
std::string symbolsPath; string symbolsPath;
std::string uploadURLStr; string uploadURLStr;
std::string proxy; string proxy;
std::string proxy_user_pwd; string proxy_user_pwd;
std::string version; string version;
bool success; bool success;
} Options; } Options;
static void TokenizeByChar(const std::string &source_string, static void TokenizeByChar(const string &source_string,
int c, std::vector<std::string> *results) { int c, std::vector<string> *results) {
assert(results); assert(results);
std::string::size_type cur_pos = 0, next_pos = 0; string::size_type cur_pos = 0, next_pos = 0;
while ((next_pos = source_string.find(c, cur_pos)) != std::string::npos) { while ((next_pos = source_string.find(c, cur_pos)) != string::npos) {
if (next_pos != cur_pos) if (next_pos != cur_pos)
results->push_back(source_string.substr(cur_pos, next_pos - cur_pos)); results->push_back(source_string.substr(cur_pos, next_pos - cur_pos));
cur_pos = next_pos + 1; 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. // Parse out the module line which have 5 parts.
// MODULE <os> <cpu> <uuid> <module-name> // MODULE <os> <cpu> <uuid> <module-name>
static bool ModuleDataForSymbolFile(const std::string &file, static bool ModuleDataForSymbolFile(const string &file,
std::vector<std::string> *module_parts) { std::vector<string> *module_parts) {
assert(module_parts); assert(module_parts);
const size_t kModulePartNumber = 5; const size_t kModulePartNumber = 5;
FILE *fp = fopen(file.c_str(), "r"); FILE* fp = fopen(file.c_str(), "r");
if (fp) { if (fp) {
char buffer[1024]; char buffer[1024];
if (fgets(buffer, sizeof(buffer), fp)) { if (fgets(buffer, sizeof(buffer), fp)) {
std::string line(buffer); string line(buffer);
std::string::size_type line_break_pos = line.find_first_of('\n'); string::size_type line_break_pos = line.find_first_of('\n');
if (line_break_pos == std::string::npos) { if (line_break_pos == string::npos) {
assert(0 && "The file is invalid!"); assert(0 && "The file is invalid!");
fclose(fp); fclose(fp);
return false; return false;
@ -106,10 +107,10 @@ static bool ModuleDataForSymbolFile(const std::string &file,
} }
//============================================================================= //=============================================================================
static std::string CompactIdentifier(const std::string &uuid) { static string CompactIdentifier(const string &uuid) {
std::vector<std::string> components; std::vector<string> components;
TokenizeByChar(uuid, '-', &components); TokenizeByChar(uuid, '-', &components);
std::string result; string result;
for (size_t i = 0; i < components.size(); ++i) for (size_t i = 0; i < components.size(); ++i)
result += components[i]; result += components[i];
return result; return result;
@ -117,15 +118,15 @@ static std::string CompactIdentifier(const std::string &uuid) {
//============================================================================= //=============================================================================
static void Start(Options *options) { static void Start(Options *options) {
std::map<std::string, std::string> parameters; std::map<string, string> parameters;
options->success = false; options->success = false;
std::vector<std::string> module_parts; std::vector<string> module_parts;
if (!ModuleDataForSymbolFile(options->symbolsPath, &module_parts)) { if (!ModuleDataForSymbolFile(options->symbolsPath, &module_parts)) {
fprintf(stderr, "Failed to parse symbol file!\n"); fprintf(stderr, "Failed to parse symbol file!\n");
return; return;
} }
std::string compacted_id = CompactIdentifier(module_parts[3]); string compacted_id = CompactIdentifier(module_parts[3]);
// Add parameters // Add parameters
if (!options->version.empty()) if (!options->version.empty())
@ -138,7 +139,7 @@ static void Start(Options *options) {
parameters["debug_file"] = module_parts[4]; parameters["debug_file"] = module_parts[4];
parameters["code_file"] = module_parts[4]; parameters["code_file"] = module_parts[4];
parameters["debug_identifier"] = compacted_id; parameters["debug_identifier"] = compacted_id;
std::string response, error; string response, error;
long response_code; long response_code;
bool success = HTTPUpload::SendRequest(options->uploadURLStr, bool success = HTTPUpload::SendRequest(options->uploadURLStr,
parameters, parameters,
@ -186,7 +187,7 @@ Usage(int argc, const char *argv[]) {
static void static void
SetupOptions(int argc, const char *argv[], Options *options) { SetupOptions(int argc, const char *argv[], Options *options) {
extern int optind; extern int optind;
char ch; int ch;
while ((ch = getopt(argc, (char * const *)argv, "u:v:x:h?")) != -1) { while ((ch = getopt(argc, (char * const *)argv, "u:v:x:h?")) != -1) {
switch (ch) { switch (ch) {
@ -201,8 +202,9 @@ SetupOptions(int argc, const char *argv[], Options *options) {
break; break;
default: default:
fprintf(stderr, "Invalid option '%c'\n", ch);
Usage(argc, argv); Usage(argc, argv);
exit(0); exit(1);
break; 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; Options options;
SetupOptions(argc, argv, &options); SetupOptions(argc, argv, &options);
Start(&options); Start(&options);