From c77c51fae6796fbe86ecafd6136ef9503251c035 Mon Sep 17 00:00:00 2001 From: Li Yan Date: Wed, 30 Mar 2016 13:46:21 -0700 Subject: Refactor sym_upload in tools to extract code into common/linux, and minor fixes to code calling libcurl. This change may be used to build a tool to dump and upload symbols with multi-thread. BUG= R=mmandlis@chromium.org CC=google-breakpad-dev@googlegroups.com Review URL: https://codereview.chromium.org/1842113002 . --- src/tools/linux/symupload/sym_upload.cc | 131 +------------------------------- 1 file changed, 3 insertions(+), 128 deletions(-) (limited to 'src/tools') diff --git a/src/tools/linux/symupload/sym_upload.cc b/src/tools/linux/symupload/sym_upload.cc index 2f9a73c3..9eeb2d44 100644 --- a/src/tools/linux/symupload/sym_upload.cc +++ b/src/tools/linux/symupload/sym_upload.cc @@ -39,138 +39,13 @@ // cpu: the CPU that the module was built for // symbol_file: the contents of the breakpad-format symbol file -#include #include #include #include -#include -#include -#include -#include +#include "common/linux/symbol_upload.h" -#include "common/linux/http_upload.h" -#include "common/using_std_string.h" - -using google_breakpad::HTTPUpload; - -typedef struct { - string symbolsPath; - string uploadURLStr; - string proxy; - string proxy_user_pwd; - string version; - bool success; -} Options; - -static void TokenizeByChar(const string &source_string, - int c, std::vector *results) { - assert(results); - 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; - } - if (cur_pos < source_string.size() && next_pos != cur_pos) - results->push_back(source_string.substr(cur_pos)); -} - -//============================================================================= -// Parse out the module line which have 5 parts. -// MODULE -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"); - if (fp) { - char buffer[1024]; - if (fgets(buffer, sizeof(buffer), fp)) { - 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; - } - line.resize(line_break_pos); - const char kDelimiter = ' '; - TokenizeByChar(line, kDelimiter, module_parts); - if (module_parts->size() != kModulePartNumber) - module_parts->clear(); - } - fclose(fp); - } - - return module_parts->size() == kModulePartNumber; -} - -//============================================================================= -static string CompactIdentifier(const string &uuid) { - std::vector components; - TokenizeByChar(uuid, '-', &components); - string result; - for (size_t i = 0; i < components.size(); ++i) - result += components[i]; - return result; -} - -//============================================================================= -static void Start(Options *options) { - std::map parameters; - options->success = false; - std::vector module_parts; - if (!ModuleDataForSymbolFile(options->symbolsPath, &module_parts)) { - fprintf(stderr, "Failed to parse symbol file!\n"); - return; - } - - string compacted_id = CompactIdentifier(module_parts[3]); - - // Add parameters - if (!options->version.empty()) - parameters["version"] = options->version; - - // MODULE - // 0 1 2 3 4 - parameters["os"] = module_parts[1]; - parameters["cpu"] = module_parts[2]; - parameters["debug_file"] = module_parts[4]; - parameters["code_file"] = module_parts[4]; - parameters["debug_identifier"] = compacted_id; - - std::map files; - files["symbol_file"] = options->symbolsPath; - - string response, error; - long response_code; - bool success = HTTPUpload::SendRequest(options->uploadURLStr, - parameters, - files, - options->proxy, - options->proxy_user_pwd, - "", - &response, - &response_code, - &error); - - if (!success) { - printf("Failed to send symbol file: %s\n", error.c_str()); - printf("Response code: %ld\n", response_code); - printf("Response:\n"); - printf("%s\n", response.c_str()); - } else if (response_code == 0) { - printf("Failed to send symbol file: No response code\n"); - } else if (response_code != 200) { - printf("Failed to send symbol file: Response code %ld\n", response_code); - printf("Response:\n"); - printf("%s\n", response.c_str()); - } else { - printf("Successfully sent the symbol file.\n"); - } - options->success = success; -} +using google_breakpad::sym_upload::Options; //============================================================================= static void @@ -232,6 +107,6 @@ SetupOptions(int argc, const char *argv[], Options *options) { int main(int argc, const char* argv[]) { Options options; SetupOptions(argc, argv, &options); - Start(&options); + google_breakpad::sym_upload::Start(&options); return options.success ? 0 : 1; } -- cgit v1.2.1