summaryrefslogtreecommitdiffstats
path: root/lib/utils/make_descr.cpp
diff options
context:
space:
mode:
authorNikola Pajkovsky <npajkovs@redhat.com>2010-08-17 16:17:36 +0200
committerNikola Pajkovsky <npajkovs@redhat.com>2010-08-17 16:17:36 +0200
commit3fcf8e4fc0e281e1b250ed46fa201cb9ac8bb961 (patch)
tree4024ce5d6f180b7568f132c813a87b4f7a1ea64c /lib/utils/make_descr.cpp
parent3deba44dc3b080d214736f3dd0751d15e8aaeae2 (diff)
parent2297cb37e130d90d56d878b18270bd72295495ca (diff)
downloadabrt-3fcf8e4fc0e281e1b250ed46fa201cb9ac8bb961.tar.gz
abrt-3fcf8e4fc0e281e1b250ed46fa201cb9ac8bb961.tar.xz
abrt-3fcf8e4fc0e281e1b250ed46fa201cb9ac8bb961.zip
Merge branch 'string'
Diffstat (limited to 'lib/utils/make_descr.cpp')
-rw-r--r--lib/utils/make_descr.cpp222
1 files changed, 142 insertions, 80 deletions
diff --git a/lib/utils/make_descr.cpp b/lib/utils/make_descr.cpp
index 46d9644d..8569100f 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,133 @@ static const char *const blacklisted_items[] = {
NULL
};
-string make_description_bz(const map_crash_data_t& pCrashData)
+char* make_dsc_mailx(const map_crash_data_t & crash_data)
+{
+ struct strbuf *buf_dsc = strbuf_new();
+ struct strbuf *buf_additional_files = strbuf_new();
+ struct strbuf *buf_duphash_file = strbuf_new();
+ struct strbuf *buf_common_files = strbuf_new();
+
+ map_crash_data_t::const_iterator it;
+ for (it = crash_data.begin(); it != crash_data.end(); it++)
+ {
+ if (it->second[CD_TYPE] == CD_TXT)
+ {
+ const char *itemname = it->first.c_str();
+ if ((strcmp(itemname, CD_DUPHASH) != 0)
+ && (strcmp(itemname, FILENAME_ARCHITECTURE) != 0)
+ && (strcmp(itemname, FILENAME_KERNEL) != 0)
+ && (strcmp(itemname, FILENAME_PACKAGE) != 0)
+ ) {
+ strbuf_append_strf(buf_additional_files, "%s\n-----\n%s\n\n", itemname, it->second[CD_CONTENT].c_str());
+ }
+ else if (strcmp(itemname, CD_DUPHASH) == 0)
+ strbuf_append_strf(buf_duphash_file, "%s\n-----\n%s\n\n", itemname, it->second[CD_CONTENT].c_str());
+ else
+ strbuf_append_strf(buf_common_files, "%s\n-----\n%s\n\n", itemname, it->second[CD_CONTENT].c_str());
+ }
+ }
+
+ char *common_files = strbuf_free_nobuf(buf_common_files);
+ char *duphash_file = strbuf_free_nobuf(buf_duphash_file);
+ char *additional_files = strbuf_free_nobuf(buf_additional_files);
+
+ strbuf_append_strf(buf_dsc, "Duplicate check\n=====\n%s\n\n", duphash_file);
+ strbuf_append_strf(buf_dsc, "Common information\n=====\n%s\n\n", common_files);
+ strbuf_append_strf(buf_dsc, "Additional information\n=====\n%s\n", additional_files);
+
+ free(common_files);
+ free(duphash_file);
+ free(additional_files);
+
+ return strbuf_free_nobuf(buf_dsc);
+}
+
+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 +226,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);
}