diff options
author | Nikola Pajkovsky <npajkovs@redhat.com> | 2010-06-07 13:37:26 +0200 |
---|---|---|
committer | Nikola Pajkovsky <npajkovs@redhat.com> | 2010-08-17 15:07:35 +0200 |
commit | ab5ee6c07719d6bb6a3d387f88f96ab783d8b8c7 (patch) | |
tree | d9616eca4d20bf428b8ddbc47b0d70fea5da106b | |
parent | 5627160040467c39641f77886e90ff6695fb120c (diff) | |
download | abrt-ab5ee6c07719d6bb6a3d387f88f96ab783d8b8c7.tar.gz abrt-ab5ee6c07719d6bb6a3d387f88f96ab783d8b8c7.tar.xz abrt-ab5ee6c07719d6bb6a3d387f88f96ab783d8b8c7.zip |
get rid of std::string from bugzilla
Signed-off-by: Nikola Pajkovsky <npajkovs@redhat.com>
-rw-r--r-- | inc/plugin.h | 6 | ||||
-rw-r--r-- | lib/plugins/Bugzilla.cpp | 244 | ||||
-rw-r--r-- | lib/plugins/Bugzilla.h | 12 | ||||
-rw-r--r-- | lib/plugins/Logger.cpp | 10 | ||||
-rw-r--r-- | lib/utils/make_descr.cpp | 180 |
5 files changed, 245 insertions, 207 deletions
diff --git a/inc/plugin.h b/inc/plugin.h index 34d5743f..d7772b5a 100644 --- a/inc/plugin.h +++ b/inc/plugin.h @@ -119,9 +119,9 @@ typedef struct SPluginInfo }; /* helper functions */ -std::string make_description_bz(const map_crash_data_t& pCrashData); -std::string make_description_reproduce_comment(const map_crash_data_t& pCrashData); -std::string make_description_logger(const map_crash_data_t& pCrashData); +char* make_description_bz(const map_crash_data_t& pCrashData); +char* make_description_reproduce_comment(const map_crash_data_t& pCrashData); +char* make_description_logger(const map_crash_data_t& pCrashData); /** * Loads settings and stores it in second parameter. On success it diff --git a/lib/plugins/Bugzilla.cpp b/lib/plugins/Bugzilla.cpp index f3967cdf..e494f082 100644 --- a/lib/plugins/Bugzilla.cpp +++ b/lib/plugins/Bugzilla.cpp @@ -24,6 +24,7 @@ #include "debug_dump.h" #include "abrt_exception.h" #include "comm_layer_inner.h" +#include "strbuf.h" #ifdef HAVE_CONFIG_H # include <config.h> #endif @@ -31,6 +32,7 @@ #define XML_RPC_SUFFIX "/xmlrpc.cgi" #define MAX_HOPS 5 + /* * TODO: npajkovs: better deallocation of xmlrpc value * npajkovs: better gathering function which collects all information from bugzilla @@ -389,46 +391,45 @@ int ctx::add_comment(xmlrpc_int32 bug_id, const char* comment, bool is_private) xmlrpc_int32 ctx::new_bug(const map_crash_data_t& pCrashData, int depend_on_bugno) { - const std::string& package = get_crash_data_item_content(pCrashData, FILENAME_PACKAGE); - const std::string& component = get_crash_data_item_content(pCrashData, FILENAME_COMPONENT); - const std::string& release = get_crash_data_item_content(pCrashData, FILENAME_RELEASE); - const std::string& arch = get_crash_data_item_content(pCrashData, FILENAME_ARCHITECTURE); - const std::string& duphash = get_crash_data_item_content(pCrashData, CD_DUPHASH); - const char *reason = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_REASON); - const char *function = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_CRASH_FUNCTION); - - std::string summary = "[abrt] " + package; + const char *package = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_PACKAGE); + const char *component = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_COMPONENT); + const char *release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE); + const char *arch = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_ARCHITECTURE); + const char *duphash = get_crash_data_item_content_or_NULL(pCrashData, CD_DUPHASH); + const char *reason = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_REASON); + const char *function = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_CRASH_FUNCTION); + + struct strbuf *buf_summary = strbuf_new(); + strbuf_append_strf(buf_summary, "[abrt] %s", package); + if (function != NULL && strlen(function) < 30) - { - summary += ": "; - summary += function; - } + strbuf_append_strf(buf_summary, ": %s", function); if (reason != NULL) - { - summary += ": "; - summary += reason; - } - std::string status_whiteboard = "abrt_hash:" + duphash; + strbuf_append_strf(buf_summary, ": %s", reason); + + char *status_whiteboard = xasprintf("abrt_hash:%s", duphash); - std::string description = "abrt version: "VERSION"\n"; - description += make_description_bz(pCrashData); + char *bz_dsc = make_description_bz(pCrashData); + char *full_dsc = xasprintf("abrt version: "VERSION"\n%s", bz_dsc); + free(bz_dsc); char *product = NULL; char *version = NULL; - parse_release(release.c_str(), &product, &version); + parse_release(release, &product, &version); xmlrpc_value* result = NULL; + char *summary = strbuf_free_nobuf(buf_summary); if (depend_on_bugno > -1) { result = call("Bug.create", "({s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:i})", "product", product, - "component", component.c_str(), + "component", component, "version", version, - "summary", summary.c_str(), - "description", description.c_str(), - "status_whiteboard", status_whiteboard.c_str(), - "platform", arch.c_str(), + "summary", summary, + "description", full_dsc, + "status_whiteboard", status_whiteboard, + "platform", arch, "dependson", depend_on_bugno ); } @@ -436,17 +437,19 @@ xmlrpc_int32 ctx::new_bug(const map_crash_data_t& pCrashData, int depend_on_bugn { result = call("Bug.create", "({s:s,s:s,s:s,s:s,s:s,s:s,s:s})", "product", product, - "component", component.c_str(), + "component", component, "version", version, - "summary", summary.c_str(), - "description", description.c_str(), - "status_whiteboard", status_whiteboard.c_str(), - "platform", arch.c_str() + "summary", summary, + "description", full_dsc, + "status_whiteboard", status_whiteboard, + "platform", arch ); - } + free(status_whiteboard); free(product); free(version); + free(summary); + free(full_dsc); if (!result) return -1; @@ -473,21 +476,23 @@ int ctx::add_attachments(const char* bug_id_str, const map_crash_data_t& pCrashD map_crash_data_t::const_iterator it = pCrashData.begin(); for (; it != pCrashData.end(); it++) { - const std::string &itemname = it->first; - const std::string &type = it->second[CD_TYPE]; - const std::string &content = it->second[CD_CONTENT]; + const char *itemname = it->first.c_str(); + const char *type = it->second[CD_TYPE].c_str(); + const char *content = it->second[CD_CONTENT].c_str(); - if (type == CD_TXT - && (content.length() > CD_TEXT_ATT_SIZE || itemname == FILENAME_BACKTRACE) + if ((strcmp(type, CD_TXT) == 0) + && (strlen(content) > CD_TEXT_ATT_SIZE || (strcmp(itemname, FILENAME_BACKTRACE) == 0)) ) { - char *encoded64 = encode_base64(content.c_str(), content.length()); + char *encoded64 = encode_base64(content, strlen(content)); + char *filename = xasprintf("File: %s", itemname); xmlrpc_value* result = call("bugzilla.addAttachment", "(s{s:s,s:s,s:s,s:s})", bug_id_str, - "description", ("File: " + itemname).c_str(), - "filename", itemname.c_str(), + "description", filename, + "filename", itemname, "contenttype", "text/plain", "data", encoded64 ); free(encoded64); + free(filename); if (!result) return -1; @@ -558,9 +563,11 @@ void ctx::login(const char* login, const char* passwd) if (!result) { - std::string errmsg = ssprintf(_("Cannot login. Check Edit->Plugins->Bugzilla and /etc/abrt/plugins/Bugzilla.conf. Server said: %s"), env.fault_string); - error_msg("%s", errmsg.c_str()); // show error in daemon log - throw CABRTException(EXCEP_PLUGIN, "%s", errmsg.c_str()); + char *errmsg = xasprintf("Can't login. Check Edit->Plugins->Bugzilla and /etc/abrt/plugins/Bugzilla.conf. Server said: %s", env.fault_string); + error_msg("%s", errmsg); // show error in daemon log + CABRTException e(EXCEP_PLUGIN, errmsg); + free(errmsg); + throw e; } xmlrpc_DECREF(result); } @@ -636,59 +643,68 @@ static map_plugin_settings_t parse_settings(const map_plugin_settings_t& pSettin return plugin_settings; } -CReporterBugzilla::CReporterBugzilla() : - m_bSSLVerify(true), - m_sBugzillaURL("https://bugzilla.redhat.com"), - m_sBugzillaXMLRPC("https://bugzilla.redhat.com"XML_RPC_SUFFIX), - m_bRatingRequired(true) -{} +CReporterBugzilla::CReporterBugzilla() +{ + m_ssl_verify = true; + m_rating_required = true; + m_login = NULL; + m_password = NULL; + m_bugzilla_url = xstrdup("https://bugzilla.redhat.com"); + m_bugzilla_xmlrpc = xstrdup("https://bugzilla.redhat.com"XML_RPC_SUFFIX); +} CReporterBugzilla::~CReporterBugzilla() -{} +{ + free(m_login); + free(m_password); + free(m_bugzilla_url); + free(m_bugzilla_xmlrpc); +} std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { xmlrpc_int32 bug_id = -1; - std::string Login; - std::string Password; - std::string BugzillaXMLRPC; - std::string BugzillaURL; - bool SSLVerify; + const char *login = NULL; + const char *password = NULL; + const char *bugzilla_xmlrpc = NULL; + const char *bugzilla_url = NULL; + bool ssl_verify; + map_plugin_settings_t settings = parse_settings(pSettings); /* if parse_settings fails it returns an empty map so we need to use defaults */ if (!settings.empty()) { - Login = settings["Login"]; - Password = settings["Password"]; - BugzillaXMLRPC = settings["BugzillaXMLRPC"]; - BugzillaURL = settings["BugzillaURL"]; - SSLVerify = string_to_bool(settings["SSLVerify"].c_str()); + login = settings["Login"].c_str(); + password = settings["Password"].c_str(); + bugzilla_xmlrpc = settings["BugzillaXMLRPC"].c_str(); + bugzilla_url = settings["BugzillaURL"].c_str(); + ssl_verify = string_to_bool(settings["NoSSLVerify"].c_str()); } else { - Login = m_sLogin; - Password = m_sPassword; - BugzillaXMLRPC = m_sBugzillaXMLRPC; - BugzillaURL = m_sBugzillaURL; - SSLVerify = m_bSSLVerify; + login = m_login; + password = m_password; + bugzilla_xmlrpc = m_bugzilla_xmlrpc; + bugzilla_url = m_bugzilla_url; + ssl_verify = m_ssl_verify; } - if ((Login == "") || (Password == "")) + if (!login[0] || !password[0]) { VERB3 log("Empty login and password"); throw CABRTException(EXCEP_PLUGIN, _("Empty login or password.\nPlease check "PLUGINS_CONF_DIR"/Bugzilla.conf.")); } - const std::string& component = get_crash_data_item_content(pCrashData, FILENAME_COMPONENT); - const std::string& duphash = get_crash_data_item_content(pCrashData, CD_DUPHASH); - const char *release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE); + const char *component = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_COMPONENT); + const char *duphash = get_crash_data_item_content_or_NULL(pCrashData, CD_DUPHASH); + const char *release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE); - ctx bz_server(BugzillaXMLRPC.c_str(), SSLVerify); + ctx bz_server(bugzilla_xmlrpc, ssl_verify); update_client(_("Logging into bugzilla...")); - bz_server.login(Login.c_str(), Password.c_str()); + bz_server.login(login, password); update_client(_("Checking for duplicates...")); @@ -698,9 +714,9 @@ std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, xmlrpc_value *result; if (strcmp(product, "Fedora") == 0) - result = bz_server.call_quicksearch_duphash(component.c_str(), product, duphash.c_str()); + result = bz_server.call_quicksearch_duphash(component, product, duphash); else - result = bz_server.call_quicksearch_duphash(component.c_str(), NULL, duphash.c_str()); + result = bz_server.call_quicksearch_duphash(component, NULL, duphash); if (!result) throw_if_xml_fault_occurred(&bz_server.env); @@ -736,7 +752,7 @@ std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, { depend_on_bugno = bug_id; bug_info_destroy(&bz); - result = bz_server.call_quicksearch_duphash(component.c_str(), release, duphash.c_str()); + result = bz_server.call_quicksearch_duphash(component, release, duphash); if (!result) throw_if_xml_fault_occurred(&bz_server.env); @@ -799,7 +815,7 @@ std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, std::string bug_status = ssprintf( "Status: NEW\n" "%s/show_bug.cgi?id=%u", - BugzillaURL.c_str(), + bugzilla_url, (int)bug_id ); return bug_status; @@ -808,7 +824,7 @@ std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, { // When someone clones bug it has same duphash, so we can find more than 1. // Need to be checked if component is same. - VERB3 log("Bugzilla has %u reports with same duphash '%s'", all_bugs_size, duphash.c_str()); + VERB3 log("Bugzilla has %u reports with same duphash '%s'", all_bugs_size, duphash); } // decision based on state @@ -850,11 +866,11 @@ std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, if (strcmp(bz.bug_status, "CLOSED") != 0) { int status = 0; - if ((strcmp(bz.bug_reporter, Login.c_str()) != 0) && (am_i_in_cc(&bz, Login.c_str()))) + if ((strcmp(bz.bug_reporter, login) != 0) && (am_i_in_cc(&bz, login))) { - VERB2 log(_("Adding %s to CC list"), Login.c_str()); - update_client(_("Adding %s to CC list"), Login.c_str()); - status = bz_server.add_plus_one_cc(bug_id, Login.c_str()); + VERB2 log(_("Add %s to CC list"), login); + update_client(_("Add %s to CC list"), login); + status = bz_server.add_plus_one_cc(bug_id, login); } if (status == -1) @@ -863,28 +879,32 @@ std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, throw_if_xml_fault_occurred(&bz_server.env); } - std::string description = make_description_reproduce_comment(pCrashData); - if (!description.empty()) + char *dsc = make_description_reproduce_comment(pCrashData); + if (dsc) { const char* package = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_PACKAGE); const char* release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE); const char* arch = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_ARCHITECTURE); const char* is_private = get_crash_data_item_content_or_NULL(pCrashData, "is_private"); - description = ssprintf("Package: %s\n" + char *full_dsc = xasprintf("Package: %s\n" "Architecture: %s\n" "OS Release: %s\n" - "%s", package, arch, release, description.c_str() + "%s", package, arch, release, dsc ); update_client(_("Adding new comment to bug %d"), (int)bug_id); + free(dsc); + bool is_priv = is_private && (is_private[0] == '1'); - if (bz_server.add_comment(bug_id, description.c_str(), is_priv) == -1) + if (bz_server.add_comment(bug_id, full_dsc, is_priv) == -1) { + free(full_dsc); bug_info_destroy(&bz); throw_if_xml_fault_occurred(&bz_server.env); } + free(full_dsc); } } @@ -897,7 +917,7 @@ std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, bz.bug_status, bz.bug_resolution ? " " : "", bz.bug_resolution ? bz.bug_resolution : "", - BugzillaURL.c_str(), + bugzilla_url, (int)bug_id ); @@ -922,52 +942,48 @@ void CReporterBugzilla::SetSettings(const map_plugin_settings_t& pSettings) it = pSettings.find("BugzillaURL"); if (it != end) { - m_sBugzillaURL = it->second; - //remove the /xmlrpc.cgi part from old settings - //FIXME: can be removed after users are informed about new config format - std::string::size_type pos = m_sBugzillaURL.find(XML_RPC_SUFFIX); - if (pos != std::string::npos) - { - m_sBugzillaURL.erase(pos); - } - //remove the trailing '/' - while (m_sBugzillaURL[m_sBugzillaURL.length() - 1] == '/') - { - m_sBugzillaURL.erase(m_sBugzillaURL.length() - 1); - } - /* - if (*(--m_sBugzillaURL.end()) == '/') - { - m_sBugzillaURL.erase(--m_sBugzillaURL.end()); - } - */ - m_sBugzillaXMLRPC = m_sBugzillaURL + XML_RPC_SUFFIX; + free(m_bugzilla_url); + free(m_bugzilla_xmlrpc); + + m_bugzilla_url = xstrdup(it->second.c_str()); + + int cnt = strlen(m_bugzilla_url); + while (m_bugzilla_url[cnt--] == '/') + m_bugzilla_url[cnt] = '\0'; + + int ret = suffixcmp(m_bugzilla_url, XML_RPC_SUFFIX); + if (ret != 0) + m_bugzilla_xmlrpc = xasprintf("%s%s", m_bugzilla_url, XML_RPC_SUFFIX); + else + m_bugzilla_xmlrpc = xstrdup(m_bugzilla_url); } it = pSettings.find("Login"); if (it != end) { - m_sLogin = it->second; + free(m_login); + m_login = xstrdup(it->second.c_str()); } it = pSettings.find("Password"); if (it != end) { - m_sPassword = it->second; + free(m_password); + m_password = xstrdup(it->second.c_str()); } it = pSettings.find("SSLVerify"); if (it != end) { - m_bSSLVerify = string_to_bool(it->second.c_str()); + m_ssl_verify = string_to_bool(it->second.c_str()); } } /* Should not be deleted (why?) */ const map_plugin_settings_t& CReporterBugzilla::GetSettings() { - m_pSettings["BugzillaURL"] = m_sBugzillaURL; - m_pSettings["Login"] = m_sLogin; - m_pSettings["Password"] = m_sPassword; - m_pSettings["SSLVerify"] = m_bSSLVerify ? "yes" : "no"; - m_pSettings["RatingRequired"] = m_bRatingRequired ? "yes" : "no"; + m_pSettings["BugzillaURL"] = m_bugzilla_url; + m_pSettings["Login"] = (m_login)? m_login: ""; + m_pSettings["Password"] = (m_password)? m_password: ""; + m_pSettings["SSLVerify"] = m_ssl_verify ? "yes" : "no"; + m_pSettings["RatingRequired"] = m_rating_required ? "yes" : "no"; return m_pSettings; } diff --git a/lib/plugins/Bugzilla.h b/lib/plugins/Bugzilla.h index a4c9a01e..2b32a701 100644 --- a/lib/plugins/Bugzilla.h +++ b/lib/plugins/Bugzilla.h @@ -25,12 +25,12 @@ class CReporterBugzilla : public CReporter { private: - bool m_bSSLVerify; - std::string m_sBugzillaURL; - std::string m_sBugzillaXMLRPC; - std::string m_sLogin; - std::string m_sPassword; - bool m_bRatingRequired; + bool m_ssl_verify; + char *m_bugzilla_url; + char *m_bugzilla_xmlrpc; + char *m_login; + char *m_password; + bool m_rating_required; public: CReporterBugzilla(); diff --git a/lib/plugins/Logger.cpp b/lib/plugins/Logger.cpp index ece450d4..a02845fe 100644 --- a/lib/plugins/Logger.cpp +++ b/lib/plugins/Logger.cpp @@ -60,7 +60,9 @@ std::string CLogger::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { - std::string description = make_description_logger(pCrashData); + char *dsc = make_description_logger(pCrashData); + char *full_dsc = xasprintf("%s\n\n\n", dsc); + free(dsc); /* open, not fopen - want to set mode if we create the file, not just open */ const char *fname = m_sLogPath.c_str(); @@ -71,9 +73,9 @@ std::string CLogger::Report(const map_crash_data_t& pCrashData, throw CABRTException(EXCEP_PLUGIN, "Can't open '%s'", fname); update_client(_("Writing report to '%s'"), fname); - description += "\n\n\n"; - const char *desc = description.c_str(); - full_write(fd, desc, strlen(desc)); + full_write(fd, full_dsc, strlen(full_dsc)); + free(full_dsc); + close(fd); const char *format = m_bAppendLogs ? _("The report was appended to %s") : _("The report was stored to %s"); diff --git a/lib/utils/make_descr.cpp b/lib/utils/make_descr.cpp index 46d9644d..93ae2925 100644 --- a/lib/utils/make_descr.cpp +++ b/lib/utils/make_descr.cpp @@ -19,6 +19,7 @@ #include "abrtlib.h" #include "crash_types.h" #include "debug_dump.h" /* FILENAME_ARCHITECTURE etc */ +#include "strbuf.h" #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -29,13 +30,15 @@ # define _(S) (S) #endif + using namespace std; -static void add_content(bool &was_multiline, string& description, const char *header, const char *content) +// caller is responsible for freeing **dsc +static void add_content(bool *was_multiline, char **dsc, const char *header, const char *content) { - /* We separate multiline contents with emply line */ - if (was_multiline) - description += '\n'; + struct strbuf *buf_description = strbuf_new(); + if (*was_multiline) + strbuf_append_char(buf_description, '\n'); while (content[0] == '\n') content++; @@ -45,27 +48,27 @@ static void add_content(bool &was_multiline, string& description, const char *he if (skip_whitespace(content)[0] == '\0') { /* empty, dont report at all */ + *dsc = strbuf_free_nobuf(buf_description); return; } /* one string value, like OS release */ - description += header; - description += ": "; - description += content; - description += '\n'; - was_multiline = 0; + strbuf_append_strf(buf_description, "%s: %s\n", header, content); + *was_multiline = 0; } else { /* multi-string value, like backtrace */ - if (!was_multiline && description.size() != 0) /* if wasn't yet separated */ - description += '\n'; /* do it now */ - description += header; - description += "\n-----\n"; - description += content; + if (!*was_multiline && (buf_description->len != 0)) /* if wasn't yet separated */ + strbuf_append_char(buf_description, '\n'); + + strbuf_append_strf(buf_description, "%s\n-----\n%s", header, content); if (content[strlen(content) - 1] != '\n') - description += '\n'; - was_multiline = 1; + strbuf_append_char(buf_description, '\n'); + + *was_multiline = 1; } + + *dsc = strbuf_free_nobuf(buf_description); } /* Items we don't want to include */ @@ -85,85 +88,91 @@ static const char *const blacklisted_items[] = { NULL }; -string make_description_bz(const map_crash_data_t& pCrashData) +char* make_description_bz(const map_crash_data_t& pCrashData) { - string description; - string long_description; + struct strbuf *buf_dsc = strbuf_new(); + struct strbuf *buf_long_dsc = strbuf_new(); map_crash_data_t::const_iterator it = pCrashData.begin(); for (; it != pCrashData.end(); it++) { - const string& itemname = it->first; - const string& type = it->second[CD_TYPE]; - const string& content = it->second[CD_CONTENT]; - if (type == CD_TXT) + const char *itemname = it->first.c_str(); + const char *type = it->second[CD_TYPE].c_str(); + const char *content = it->second[CD_CONTENT].c_str(); + if (strcmp(type, CD_TXT) == 0) { /* Skip items we are not interested in */ const char *const *bl = blacklisted_items; while (*bl) { - if (itemname == *bl) + if (strcmp(itemname, *bl) == 0) break; bl++; } if (*bl) continue; /* blacklisted */ - if (content == "1.\n2.\n3.\n") + if (strcmp(content, "1.\n2.\n3.\n") == 0) continue; /* user did not change default "How to reproduce" */ - if (content.size() <= CD_TEXT_ATT_SIZE) + if (strlen(content) <= CD_TEXT_ATT_SIZE) { /* Add small (less than few kb) text items inline */ bool was_multiline = 0; - string tmp; - add_content(was_multiline, - tmp, - /* "reproduce: blah" looks ugly, fixing: */ - itemname == FILENAME_REPRODUCE ? "How to reproduce" : itemname.c_str(), - content.c_str() + char *tmp = NULL; + add_content(&was_multiline, + &tmp, + /* "reproduce: blah" looks ugly, fixing: */ + (strcmp(itemname, FILENAME_REPRODUCE) == 0) ? "How to reproduce" : itemname, + content ); if (was_multiline) { /* Not one-liner */ - if (long_description.size() != 0) - long_description += '\n'; - long_description += tmp; + if (buf_long_dsc->len != 0) + strbuf_append_char(buf_long_dsc, '\n'); + + strbuf_append_str(buf_long_dsc, tmp); } else - { - description += tmp; - } + strbuf_append_str(buf_dsc, tmp); + + free(tmp); } else { bool was_multiline = 0; - add_content(was_multiline, description, "Attached file", itemname.c_str()); + char *dsc = NULL; + add_content(&was_multiline, &dsc, "Attached file", itemname); + strbuf_append_str(buf_dsc, dsc); + free(dsc); } } } /* One-liners go first, then multi-line items */ - if (description.size() != 0 && long_description.size() != 0) - { - description += '\n'; - } - description += long_description; + if (buf_dsc->len != 0 && buf_long_dsc->len != 0) + strbuf_append_char(buf_dsc, '\n'); + - return description; + char *long_dsc = strbuf_free_nobuf(buf_long_dsc); + strbuf_append_str(buf_dsc, long_dsc); + free(long_dsc); + + return strbuf_free_nobuf(buf_dsc); } -string make_description_logger(const map_crash_data_t& pCrashData) +char* make_description_logger(const map_crash_data_t& pCrashData) { - string description; - string long_description; + struct strbuf *buf_dsc = strbuf_new(); + struct strbuf *buf_long_dsc = strbuf_new(); map_crash_data_t::const_iterator it = pCrashData.begin(); for (; it != pCrashData.end(); it++) { - const string &filename = it->first; - const string &type = it->second[CD_TYPE]; - const string &content = it->second[CD_CONTENT]; - if (type == CD_TXT - || type == CD_BIN + const char *filename = it->first.c_str(); + const char *type = it->second[CD_TYPE].c_str(); + const char *content = it->second[CD_CONTENT].c_str(); + if ((strcmp(type, CD_TXT) == 0) + || (strcmp(type, CD_BIN) == 0) ) { /* Skip items we are not interested in */ const char *const *bl = blacklisted_items; @@ -175,62 +184,73 @@ string make_description_logger(const map_crash_data_t& pCrashData) } if (*bl) continue; /* blacklisted */ - if (content == "1.\n2.\n3.\n") + if (strcmp(content, "1.\n2.\n3.\n") == 0) continue; /* user did not change default "How to reproduce" */ bool was_multiline = 0; - string tmp; - add_content(was_multiline, tmp, filename.c_str(), content.c_str()); + char *tmp = NULL; + add_content(&was_multiline, &tmp, filename, content); if (was_multiline) { - if (long_description.size() != 0) - long_description += '\n'; - long_description += tmp; + if (buf_long_dsc->len != 0) + strbuf_append_char(buf_long_dsc,'\n'); + + strbuf_append_str(buf_long_dsc, tmp); } else - { - description += tmp; - } + strbuf_append_str(buf_dsc, tmp); } } - if (description.size() != 0 && long_description.size() != 0) - { - description += '\n'; - } - description += long_description; + if (buf_dsc->len != 0 && buf_long_dsc->len != 0) + strbuf_append_char(buf_dsc, '\n'); + + char *long_dsc = strbuf_free_nobuf(buf_long_dsc); + strbuf_append_str(buf_dsc, long_dsc); + free(long_dsc); - return description; + return strbuf_free_nobuf(buf_dsc); } -string make_description_reproduce_comment(const map_crash_data_t& pCrashData) +char* make_description_reproduce_comment(const map_crash_data_t& pCrashData) { + char *repro = NULL; + char *comment = NULL; + map_crash_data_t::const_iterator end = pCrashData.end(); map_crash_data_t::const_iterator it; - string howToReproduce; it = pCrashData.find(FILENAME_REPRODUCE); if (it != end) { if ((it->second[CD_CONTENT].size() > 0) && (it->second[CD_CONTENT] != "1.\n2.\n3.\n")) { - howToReproduce = "\n\nHow to reproduce\n" - "-----\n"; - howToReproduce += it->second[CD_CONTENT]; + repro = xasprintf("\n\nHow to reproduce\n-----\n%s", it->second[CD_CONTENT].c_str()); } } - string comment; + it = pCrashData.find(FILENAME_COMMENT); if (it != end) { if (it->second[CD_CONTENT].size() > 0) - { - comment = "\n\nComment\n" - "-----\n"; - comment += it->second[CD_CONTENT]; - } + comment = xasprintf("\n\nComment\n-----\n%s", it->second[CD_CONTENT].c_str()); } - return howToReproduce + comment; + + if (!repro && !comment) + return NULL; + + struct strbuf *buf_dsc = strbuf_new(); + + if (repro) + strbuf_append_str(buf_dsc, repro); + + if (comment) + strbuf_append_str(buf_dsc, comment); + + free(repro); + free(comment); + + return strbuf_free_nobuf(buf_dsc); } |