summaryrefslogtreecommitdiffstats
path: root/lib/utils/make_descr.cpp
diff options
context:
space:
mode:
authorNikola Pajkovsky <npajkovs@redhat.com>2010-06-07 13:37:26 +0200
committerNikola Pajkovsky <npajkovs@redhat.com>2010-08-17 15:07:35 +0200
commitab5ee6c07719d6bb6a3d387f88f96ab783d8b8c7 (patch)
treed9616eca4d20bf428b8ddbc47b0d70fea5da106b /lib/utils/make_descr.cpp
parent5627160040467c39641f77886e90ff6695fb120c (diff)
downloadabrt-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>
Diffstat (limited to 'lib/utils/make_descr.cpp')
-rw-r--r--lib/utils/make_descr.cpp180
1 files changed, 100 insertions, 80 deletions
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);
}