|
Matej Habrnal |
5c8df3 |
From 4dd20b271a2e0bf7497654cec97541898b3bae31 Mon Sep 17 00:00:00 2001
|
|
Matej Habrnal |
5c8df3 |
From: Jakub Filak <jfilak@redhat.com>
|
|
Matej Habrnal |
5c8df3 |
Date: Thu, 4 Dec 2014 08:45:07 +0100
|
|
Matej Habrnal |
5c8df3 |
Subject: [PATCH 128/136] bugzilla: port to Problem Format API
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
Related to #303
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
Matej Habrnal |
5c8df3 |
---
|
|
Matej Habrnal |
5c8df3 |
src/plugins/reporter-bugzilla.c | 691 ++++------------------------------------
|
|
Matej Habrnal |
5c8df3 |
1 file changed, 59 insertions(+), 632 deletions(-)
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
|
|
Matej Habrnal |
5c8df3 |
index 097924e..38f48ef 100644
|
|
Matej Habrnal |
5c8df3 |
--- a/src/plugins/reporter-bugzilla.c
|
|
Matej Habrnal |
5c8df3 |
+++ b/src/plugins/reporter-bugzilla.c
|
|
Matej Habrnal |
5c8df3 |
@@ -17,515 +17,11 @@
|
|
Matej Habrnal |
5c8df3 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Matej Habrnal |
5c8df3 |
*/
|
|
Matej Habrnal |
5c8df3 |
#include "internal_libreport.h"
|
|
Matej Habrnal |
5c8df3 |
+#include "problem_report.h"
|
|
Matej Habrnal |
5c8df3 |
#include "client.h"
|
|
Matej Habrnal |
5c8df3 |
#include "abrt_xmlrpc.h"
|
|
Matej Habrnal |
5c8df3 |
#include "rhbz.h"
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
-#include <satyr/stacktrace.h>
|
|
Matej Habrnal |
5c8df3 |
-#include <satyr/abrt.h>
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-struct section_t {
|
|
Matej Habrnal |
5c8df3 |
- char *name;
|
|
Matej Habrnal |
5c8df3 |
- GList *items;
|
|
Matej Habrnal |
5c8df3 |
-};
|
|
Matej Habrnal |
5c8df3 |
-typedef struct section_t section_t;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-/* Utility functions */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-GList* split_string_on_char(const char *str, char ch)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- GList *list = NULL;
|
|
Matej Habrnal |
5c8df3 |
- for (;;)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- const char *delim = strchrnul(str, ch);
|
|
Matej Habrnal |
5c8df3 |
- list = g_list_prepend(list, xstrndup(str, delim - str));
|
|
Matej Habrnal |
5c8df3 |
- if (*delim == '\0')
|
|
Matej Habrnal |
5c8df3 |
- break;
|
|
Matej Habrnal |
5c8df3 |
- str = delim + 1;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- return g_list_reverse(list);
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-int compare_item_name(const char *lookup, const char *name)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- if (lookup[0] == '-')
|
|
Matej Habrnal |
5c8df3 |
- lookup++;
|
|
Matej Habrnal |
5c8df3 |
- else if (strncmp(lookup, "%bare_", 6) == 0)
|
|
Matej Habrnal |
5c8df3 |
- lookup += 6;
|
|
Matej Habrnal |
5c8df3 |
- return strcmp(lookup, name);
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-int is_item_name_in_section(const section_t *lookup, const char *name)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- if (g_list_find_custom(lookup->items, name, (GCompareFunc)compare_item_name))
|
|
Matej Habrnal |
5c8df3 |
- return 0; /* "found it!" */
|
|
Matej Habrnal |
5c8df3 |
- return 1;
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-bool is_explicit_or_forbidden(const char *name, GList *comment_fmt_spec)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- return g_list_find_custom(comment_fmt_spec, name, (GCompareFunc)is_item_name_in_section);
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-GList* load_bzrep_conf_file(const char *path)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- FILE *fp = stdin;
|
|
Matej Habrnal |
5c8df3 |
- if (strcmp(path, "-") != 0)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- fp = fopen(path, "r");
|
|
Matej Habrnal |
5c8df3 |
- if (!fp)
|
|
Matej Habrnal |
5c8df3 |
- return NULL;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- GList *sections = NULL;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- char *line;
|
|
Matej Habrnal |
5c8df3 |
- while ((line = xmalloc_fgetline(fp)) != NULL)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- /* Skip comments */
|
|
Matej Habrnal |
5c8df3 |
- char first = *skip_whitespace(line);
|
|
Matej Habrnal |
5c8df3 |
- if (first == '#')
|
|
Matej Habrnal |
5c8df3 |
- goto free_line;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Handle trailing backslash continuation */
|
|
Matej Habrnal |
5c8df3 |
- check_continuation: ;
|
|
Matej Habrnal |
5c8df3 |
- unsigned len = strlen(line);
|
|
Matej Habrnal |
5c8df3 |
- if (len && line[len-1] == '\\')
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- line[len-1] = '\0';
|
|
Matej Habrnal |
5c8df3 |
- char *next_line = xmalloc_fgetline(fp);
|
|
Matej Habrnal |
5c8df3 |
- if (next_line)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- line = append_to_malloced_string(line, next_line);
|
|
Matej Habrnal |
5c8df3 |
- free(next_line);
|
|
Matej Habrnal |
5c8df3 |
- goto check_continuation;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* We are reusing line buffer to form temporary
|
|
Matej Habrnal |
5c8df3 |
- * "key\0values\0..." in its beginning
|
|
Matej Habrnal |
5c8df3 |
- */
|
|
Matej Habrnal |
5c8df3 |
- bool summary_line = false;
|
|
Matej Habrnal |
5c8df3 |
- char *value = NULL;
|
|
Matej Habrnal |
5c8df3 |
- char *src;
|
|
Matej Habrnal |
5c8df3 |
- char *dst;
|
|
Matej Habrnal |
5c8df3 |
- for (src = dst = line; *src; src++)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- char c = *src;
|
|
Matej Habrnal |
5c8df3 |
- /* did we reach the value list? */
|
|
Matej Habrnal |
5c8df3 |
- if (!value && c == ':' && src[1] == ':')
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- *dst++ = '\0'; /* terminate key */
|
|
Matej Habrnal |
5c8df3 |
- src += 2;
|
|
Matej Habrnal |
5c8df3 |
- value = dst; /* remember where value starts */
|
|
Matej Habrnal |
5c8df3 |
- summary_line = (strcmp(line, "%summary") == 0);
|
|
Matej Habrnal |
5c8df3 |
- if (summary_line)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- value = src;
|
|
Matej Habrnal |
5c8df3 |
- break;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- /* skip whitespace in value list */
|
|
Matej Habrnal |
5c8df3 |
- if (value && isspace(c))
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
- *dst++ = c; /* store next key or value char */
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- GList *item_list = NULL;
|
|
Matej Habrnal |
5c8df3 |
- if (summary_line)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- /* %summary is special */
|
|
Matej Habrnal |
5c8df3 |
- item_list = g_list_append(NULL, xstrdup(skip_whitespace(value)));
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- else
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- *dst = '\0'; /* terminate value (or key) */
|
|
Matej Habrnal |
5c8df3 |
- if (value)
|
|
Matej Habrnal |
5c8df3 |
- item_list = split_string_on_char(value, ',');
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- section_t *sec = xzalloc(sizeof(*sec));
|
|
Matej Habrnal |
5c8df3 |
- sec->name = xstrdup(line);
|
|
Matej Habrnal |
5c8df3 |
- sec->items = item_list;
|
|
Matej Habrnal |
5c8df3 |
- sections = g_list_prepend(sections, sec);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- free_line:
|
|
Matej Habrnal |
5c8df3 |
- free(line);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (fp != stdin)
|
|
Matej Habrnal |
5c8df3 |
- fclose(fp);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- return g_list_reverse(sections);
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-/* Summary generation */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-#define MAX_OPT_DEPTH 10
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-char *format_percented_string(const char *str, problem_data_t *pd)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- size_t old_pos[MAX_OPT_DEPTH] = { 0 };
|
|
Matej Habrnal |
5c8df3 |
- int okay[MAX_OPT_DEPTH] = { 1 };
|
|
Matej Habrnal |
5c8df3 |
- int opt_depth = 1;
|
|
Matej Habrnal |
5c8df3 |
- struct strbuf *result = strbuf_new();
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- while (*str) {
|
|
Matej Habrnal |
5c8df3 |
- switch (*str) {
|
|
Matej Habrnal |
5c8df3 |
- default:
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_char(result, *str);
|
|
Matej Habrnal |
5c8df3 |
- str++;
|
|
Matej Habrnal |
5c8df3 |
- break;
|
|
Matej Habrnal |
5c8df3 |
- case '\\':
|
|
Matej Habrnal |
5c8df3 |
- if (str[1])
|
|
Matej Habrnal |
5c8df3 |
- str++;
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_char(result, *str);
|
|
Matej Habrnal |
5c8df3 |
- str++;
|
|
Matej Habrnal |
5c8df3 |
- break;
|
|
Matej Habrnal |
5c8df3 |
- case '[':
|
|
Matej Habrnal |
5c8df3 |
- if (str[1] == '[' && opt_depth < MAX_OPT_DEPTH)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- old_pos[opt_depth] = result->len;
|
|
Matej Habrnal |
5c8df3 |
- okay[opt_depth] = 1;
|
|
Matej Habrnal |
5c8df3 |
- opt_depth++;
|
|
Matej Habrnal |
5c8df3 |
- str += 2;
|
|
Matej Habrnal |
5c8df3 |
- } else {
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_char(result, *str);
|
|
Matej Habrnal |
5c8df3 |
- str++;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- break;
|
|
Matej Habrnal |
5c8df3 |
- case ']':
|
|
Matej Habrnal |
5c8df3 |
- if (str[1] == ']' && opt_depth > 1)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- opt_depth--;
|
|
Matej Habrnal |
5c8df3 |
- if (!okay[opt_depth])
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- result->len = old_pos[opt_depth];
|
|
Matej Habrnal |
5c8df3 |
- result->buf[result->len] = '\0';
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- str += 2;
|
|
Matej Habrnal |
5c8df3 |
- } else {
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_char(result, *str);
|
|
Matej Habrnal |
5c8df3 |
- str++;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- break;
|
|
Matej Habrnal |
5c8df3 |
- case '%': ;
|
|
Matej Habrnal |
5c8df3 |
- char *nextpercent = strchr(++str, '%');
|
|
Matej Habrnal |
5c8df3 |
- if (!nextpercent)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- error_msg_and_die("Unterminated %%element%%: '%s'", str - 1);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- *nextpercent = '\0';
|
|
Matej Habrnal |
5c8df3 |
- const problem_item *item = problem_data_get_item_or_NULL(pd, str);
|
|
Matej Habrnal |
5c8df3 |
- *nextpercent = '%';
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (item && (item->flags & CD_FLAG_TXT))
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_str(result, item->content);
|
|
Matej Habrnal |
5c8df3 |
- else
|
|
Matej Habrnal |
5c8df3 |
- okay[opt_depth - 1] = 0;
|
|
Matej Habrnal |
5c8df3 |
- str = nextpercent + 1;
|
|
Matej Habrnal |
5c8df3 |
- break;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (opt_depth > 1)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- error_msg_and_die("Unbalanced [[ ]] bracket");
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (!okay[0])
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- error_msg("Undefined variable outside of [[ ]] bracket");
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- return strbuf_free_nobuf(result);
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-char *create_summary_string(problem_data_t *pd, GList *comment_fmt_spec)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- GList *l = comment_fmt_spec;
|
|
Matej Habrnal |
5c8df3 |
- while (l)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- section_t *sec = l->data;
|
|
Matej Habrnal |
5c8df3 |
- l = l->next;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Find %summary" */
|
|
Matej Habrnal |
5c8df3 |
- if (strcmp(sec->name, "%summary") != 0)
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- GList *item = sec->items;
|
|
Matej Habrnal |
5c8df3 |
- if (!item)
|
|
Matej Habrnal |
5c8df3 |
- /* not supposed to happen, there will be at least "" */
|
|
Matej Habrnal |
5c8df3 |
- error_msg_and_die("BUG in %%summary parser");
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- const char *str = item->data;
|
|
Matej Habrnal |
5c8df3 |
- return format_percented_string(str, pd);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- return format_percented_string("%reason%", pd);
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-/* BZ comment generation */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-int append_text(struct strbuf *result, const char *item_name, const char *content, bool print_item_name)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- char *eol = strchrnul(content, '\n');
|
|
Matej Habrnal |
5c8df3 |
- if (eol[0] == '\0' || eol[1] == '\0')
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- /* one-liner */
|
|
Matej Habrnal |
5c8df3 |
- int pad = 16 - (strlen(item_name) + 2);
|
|
Matej Habrnal |
5c8df3 |
- if (pad < 0)
|
|
Matej Habrnal |
5c8df3 |
- pad = 0;
|
|
Matej Habrnal |
5c8df3 |
- if (print_item_name)
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_strf(result,
|
|
Matej Habrnal |
5c8df3 |
- eol[0] == '\0' ? "%s: %*s%s\n" : "%s: %*s%s",
|
|
Matej Habrnal |
5c8df3 |
- item_name, pad, "", content
|
|
Matej Habrnal |
5c8df3 |
- );
|
|
Matej Habrnal |
5c8df3 |
- else
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_strf(result,
|
|
Matej Habrnal |
5c8df3 |
- eol[0] == '\0' ? "%s\n" : "%s",
|
|
Matej Habrnal |
5c8df3 |
- content
|
|
Matej Habrnal |
5c8df3 |
- );
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- else
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- /* multi-line item */
|
|
Matej Habrnal |
5c8df3 |
- if (print_item_name)
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_strf(result, "%s:\n", item_name);
|
|
Matej Habrnal |
5c8df3 |
- for (;;)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- eol = strchrnul(content, '\n');
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_strf(result,
|
|
Matej Habrnal |
5c8df3 |
- /* For %bare_multiline_item, we don't want to print colons */
|
|
Matej Habrnal |
5c8df3 |
- (print_item_name ? ":%.*s\n" : "%.*s\n"),
|
|
Matej Habrnal |
5c8df3 |
- (int)(eol - content), content
|
|
Matej Habrnal |
5c8df3 |
- );
|
|
Matej Habrnal |
5c8df3 |
- if (eol[0] == '\0' || eol[1] == '\0')
|
|
Matej Habrnal |
5c8df3 |
- break;
|
|
Matej Habrnal |
5c8df3 |
- content = eol + 1;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- return 1;
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-int append_short_backtrace(struct strbuf *result, problem_data_t *problem_data, size_t max_text_size, bool print_item_name)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- const problem_item *item = problem_data_get_item_or_NULL(problem_data,
|
|
Matej Habrnal |
5c8df3 |
- FILENAME_BACKTRACE);
|
|
Matej Habrnal |
5c8df3 |
- if (!item)
|
|
Matej Habrnal |
5c8df3 |
- return 0; /* "I did not print anything" */
|
|
Matej Habrnal |
5c8df3 |
- if (!(item->flags & CD_FLAG_TXT))
|
|
Matej Habrnal |
5c8df3 |
- return 0; /* "I did not print anything" */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- char *truncated = NULL;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (strlen(item->content) >= max_text_size)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- char *error_msg = NULL;
|
|
Matej Habrnal |
5c8df3 |
- const char *analyzer = problem_data_get_content_or_NULL(problem_data, FILENAME_ANALYZER);
|
|
Matej Habrnal |
5c8df3 |
- if (!analyzer)
|
|
Matej Habrnal |
5c8df3 |
- return 0;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* For CCpp crashes, use the GDB-produced backtrace which should be
|
|
Matej Habrnal |
5c8df3 |
- * available by now. sr_abrt_type_from_analyzer returns SR_REPORT_CORE
|
|
Matej Habrnal |
5c8df3 |
- * by default for CCpp crashes.
|
|
Matej Habrnal |
5c8df3 |
- */
|
|
Matej Habrnal |
5c8df3 |
- enum sr_report_type report_type = sr_abrt_type_from_analyzer(analyzer);
|
|
Matej Habrnal |
5c8df3 |
- if (strcmp(analyzer, "CCpp") == 0)
|
|
Matej Habrnal |
5c8df3 |
- report_type = SR_REPORT_GDB;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- struct sr_stacktrace *backtrace = sr_stacktrace_parse(report_type,
|
|
Matej Habrnal |
5c8df3 |
- item->content, &error_msg);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (!backtrace)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- log(_("Can't parse backtrace: %s"), error_msg);
|
|
Matej Habrnal |
5c8df3 |
- free(error_msg);
|
|
Matej Habrnal |
5c8df3 |
- return 0;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Get optimized thread stack trace for 10 top most frames */
|
|
Matej Habrnal |
5c8df3 |
- truncated = sr_stacktrace_to_short_text(backtrace, 10);
|
|
Matej Habrnal |
5c8df3 |
- sr_stacktrace_free(backtrace);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (!truncated)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- log(_("Can't generate stacktrace description (no crash thread?)"));
|
|
Matej Habrnal |
5c8df3 |
- return 0;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- append_text(result,
|
|
Matej Habrnal |
5c8df3 |
- /*item_name:*/ truncated ? "truncated_backtrace" : FILENAME_BACKTRACE,
|
|
Matej Habrnal |
5c8df3 |
- /*content:*/ truncated ? truncated : item->content,
|
|
Matej Habrnal |
5c8df3 |
- print_item_name
|
|
Matej Habrnal |
5c8df3 |
- );
|
|
Matej Habrnal |
5c8df3 |
- free(truncated);
|
|
Matej Habrnal |
5c8df3 |
- return 1;
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-int append_item(struct strbuf *result, const char *item_name, problem_data_t *pd, GList *comment_fmt_spec)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- bool print_item_name = (strncmp(item_name, "%bare_", strlen("%bare_")) != 0);
|
|
Matej Habrnal |
5c8df3 |
- if (!print_item_name)
|
|
Matej Habrnal |
5c8df3 |
- item_name += strlen("%bare_");
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (item_name[0] != '%')
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- struct problem_item *item = problem_data_get_item_or_NULL(pd, item_name);
|
|
Matej Habrnal |
5c8df3 |
- if (!item)
|
|
Matej Habrnal |
5c8df3 |
- return 0; /* "I did not print anything" */
|
|
Matej Habrnal |
5c8df3 |
- if (!(item->flags & CD_FLAG_TXT))
|
|
Matej Habrnal |
5c8df3 |
- return 0; /* "I did not print anything" */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- char *formatted = problem_item_format(item);
|
|
Matej Habrnal |
5c8df3 |
- char *content = formatted ? formatted : item->content;
|
|
Matej Habrnal |
5c8df3 |
- append_text(result, item_name, content, print_item_name);
|
|
Matej Habrnal |
5c8df3 |
- free(formatted);
|
|
Matej Habrnal |
5c8df3 |
- return 1; /* "I printed something" */
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Special item name */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Compat with previously-existed ad-hockery: %short_backtrace */
|
|
Matej Habrnal |
5c8df3 |
- if (strcmp(item_name, "%short_backtrace") == 0)
|
|
Matej Habrnal |
5c8df3 |
- return append_short_backtrace(result, pd, CD_TEXT_ATT_SIZE_BZ, print_item_name);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Compat with previously-existed ad-hockery: %reporter */
|
|
Matej Habrnal |
5c8df3 |
- if (strcmp(item_name, "%reporter") == 0)
|
|
Matej Habrnal |
5c8df3 |
- return append_text(result, "reporter", PACKAGE"-"VERSION, print_item_name);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* %oneline,%multiline,%text */
|
|
Matej Habrnal |
5c8df3 |
- bool oneline = (strcmp(item_name+1, "oneline" ) == 0);
|
|
Matej Habrnal |
5c8df3 |
- bool multiline = (strcmp(item_name+1, "multiline") == 0);
|
|
Matej Habrnal |
5c8df3 |
- bool text = (strcmp(item_name+1, "text" ) == 0);
|
|
Matej Habrnal |
5c8df3 |
- if (!oneline && !multiline && !text)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- log("Unknown or unsupported element specifier '%s'", item_name);
|
|
Matej Habrnal |
5c8df3 |
- return 0; /* "I did not print anything" */
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- int printed = 0;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Iterate over _sorted_ items */
|
|
Matej Habrnal |
5c8df3 |
- GList *sorted_names = g_hash_table_get_keys(pd);
|
|
Matej Habrnal |
5c8df3 |
- sorted_names = g_list_sort(sorted_names, (GCompareFunc)strcmp);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* %text => do as if %oneline, then repeat as if %multiline */
|
|
Matej Habrnal |
5c8df3 |
- if (text)
|
|
Matej Habrnal |
5c8df3 |
- oneline = 1;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- again: ;
|
|
Matej Habrnal |
5c8df3 |
- GList *l = sorted_names;
|
|
Matej Habrnal |
5c8df3 |
- while (l)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- const char *name = l->data;
|
|
Matej Habrnal |
5c8df3 |
- l = l->next;
|
|
Matej Habrnal |
5c8df3 |
- struct problem_item *item = g_hash_table_lookup(pd, name);
|
|
Matej Habrnal |
5c8df3 |
- if (!item)
|
|
Matej Habrnal |
5c8df3 |
- continue; /* paranoia, won't happen */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (!(item->flags & CD_FLAG_TXT))
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (is_explicit_or_forbidden(name, comment_fmt_spec))
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- char *formatted = problem_item_format(item);
|
|
Matej Habrnal |
5c8df3 |
- char *content = formatted ? formatted : item->content;
|
|
Matej Habrnal |
5c8df3 |
- char *eol = strchrnul(content, '\n');
|
|
Matej Habrnal |
5c8df3 |
- bool is_oneline = (eol[0] == '\0' || eol[1] == '\0');
|
|
Matej Habrnal |
5c8df3 |
- if (oneline == is_oneline)
|
|
Matej Habrnal |
5c8df3 |
- printed |= append_text(result, name, content, print_item_name);
|
|
Matej Habrnal |
5c8df3 |
- free(formatted);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- if (text && oneline)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- /* %text, and we just did %oneline. Repeat as if %multiline */
|
|
Matej Habrnal |
5c8df3 |
- oneline = 0;
|
|
Matej Habrnal |
5c8df3 |
- /*multiline = 1; - not checked in fact, so why bother setting? */
|
|
Matej Habrnal |
5c8df3 |
- goto again;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- g_list_free(sorted_names); /* names themselves are not freed */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- return printed;
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-void generate_bz_comment(struct strbuf *result, problem_data_t *pd, GList *comment_fmt_spec)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- bool last_line_is_empty = true;
|
|
Matej Habrnal |
5c8df3 |
- GList *l = comment_fmt_spec;
|
|
Matej Habrnal |
5c8df3 |
- while (l)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- section_t *sec = l->data;
|
|
Matej Habrnal |
5c8df3 |
- l = l->next;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Skip special sections such as "%attach" */
|
|
Matej Habrnal |
5c8df3 |
- if (sec->name[0] == '%')
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (sec->items)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- /* "Text: item[,item]..." */
|
|
Matej Habrnal |
5c8df3 |
- struct strbuf *output = strbuf_new();
|
|
Matej Habrnal |
5c8df3 |
- GList *item = sec->items;
|
|
Matej Habrnal |
5c8df3 |
- while (item)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- const char *str = item->data;
|
|
Matej Habrnal |
5c8df3 |
- item = item->next;
|
|
Matej Habrnal |
5c8df3 |
- if (str[0] == '-') /* "-name", ignore it */
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
- append_item(output, str, pd, comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (output->len != 0)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_strf(result,
|
|
Matej Habrnal |
5c8df3 |
- sec->name[0] ? "%s:\n%s" : "%s%s",
|
|
Matej Habrnal |
5c8df3 |
- sec->name,
|
|
Matej Habrnal |
5c8df3 |
- output->buf
|
|
Matej Habrnal |
5c8df3 |
- );
|
|
Matej Habrnal |
5c8df3 |
- last_line_is_empty = false;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- strbuf_free(output);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- else
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- /* Just "Text" (can be "") */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Filter out consecutive empty lines */
|
|
Matej Habrnal |
5c8df3 |
- if (sec->name[0] != '\0' || !last_line_is_empty)
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_strf(result, "%s\n", sec->name);
|
|
Matej Habrnal |
5c8df3 |
- last_line_is_empty = (sec->name[0] == '\0');
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Nuke any trailing empty lines */
|
|
Matej Habrnal |
5c8df3 |
- while (result->len >= 1
|
|
Matej Habrnal |
5c8df3 |
- && result->buf[result->len-1] == '\n'
|
|
Matej Habrnal |
5c8df3 |
- && (result->len == 1 || result->buf[result->len-2] == '\n')
|
|
Matej Habrnal |
5c8df3 |
- ) {
|
|
Matej Habrnal |
5c8df3 |
- result->buf[--result->len] = '\0';
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
/* BZ attachments */
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
static
|
|
Matej Habrnal |
5c8df3 |
@@ -573,104 +69,6 @@ int attach_file_item(struct abrt_xmlrpc *ax, const char *bug_id,
|
|
Matej Habrnal |
5c8df3 |
return (r == 0);
|
|
Matej Habrnal |
5c8df3 |
}
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-int attach_item(struct abrt_xmlrpc *ax, const char *bug_id,
|
|
Matej Habrnal |
5c8df3 |
- const char *item_name, problem_data_t *pd, GList *comment_fmt_spec)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- if (item_name[0] != '%')
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- struct problem_item *item = problem_data_get_item_or_NULL(pd, item_name);
|
|
Matej Habrnal |
5c8df3 |
- if (!item)
|
|
Matej Habrnal |
5c8df3 |
- return 0;
|
|
Matej Habrnal |
5c8df3 |
- if (item->flags & CD_FLAG_TXT)
|
|
Matej Habrnal |
5c8df3 |
- return attach_text_item(ax, bug_id, item_name, item);
|
|
Matej Habrnal |
5c8df3 |
- if (item->flags & CD_FLAG_BIN)
|
|
Matej Habrnal |
5c8df3 |
- return attach_file_item(ax, bug_id, item_name, item);
|
|
Matej Habrnal |
5c8df3 |
- return 0;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Special item name */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* %oneline,%multiline,%text,%binary */
|
|
Matej Habrnal |
5c8df3 |
- bool oneline = (strcmp(item_name+1, "oneline" ) == 0);
|
|
Matej Habrnal |
5c8df3 |
- bool multiline = (strcmp(item_name+1, "multiline") == 0);
|
|
Matej Habrnal |
5c8df3 |
- bool text = (strcmp(item_name+1, "text" ) == 0);
|
|
Matej Habrnal |
5c8df3 |
- bool binary = (strcmp(item_name+1, "binary" ) == 0);
|
|
Matej Habrnal |
5c8df3 |
- if (!oneline && !multiline && !text && !binary)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- log("Unknown or unsupported element specifier '%s'", item_name);
|
|
Matej Habrnal |
5c8df3 |
- return 0;
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- log_debug("Special item_name '%s', iterating for attach...", item_name);
|
|
Matej Habrnal |
5c8df3 |
- int done = 0;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Iterate over _sorted_ items */
|
|
Matej Habrnal |
5c8df3 |
- GList *sorted_names = g_hash_table_get_keys(pd);
|
|
Matej Habrnal |
5c8df3 |
- sorted_names = g_list_sort(sorted_names, (GCompareFunc)strcmp);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- GList *l = sorted_names;
|
|
Matej Habrnal |
5c8df3 |
- while (l)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- const char *name = l->data;
|
|
Matej Habrnal |
5c8df3 |
- l = l->next;
|
|
Matej Habrnal |
5c8df3 |
- struct problem_item *item = g_hash_table_lookup(pd, name);
|
|
Matej Habrnal |
5c8df3 |
- if (!item)
|
|
Matej Habrnal |
5c8df3 |
- continue; /* paranoia, won't happen */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if (is_explicit_or_forbidden(name, comment_fmt_spec))
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- if ((item->flags & CD_FLAG_TXT) && !binary)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- char *content = item->content;
|
|
Matej Habrnal |
5c8df3 |
- char *eol = strchrnul(content, '\n');
|
|
Matej Habrnal |
5c8df3 |
- bool is_oneline = (eol[0] == '\0' || eol[1] == '\0');
|
|
Matej Habrnal |
5c8df3 |
- if (text || oneline == is_oneline)
|
|
Matej Habrnal |
5c8df3 |
- done |= attach_text_item(ax, bug_id, name, item);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- if ((item->flags & CD_FLAG_BIN) && binary)
|
|
Matej Habrnal |
5c8df3 |
- done |= attach_file_item(ax, bug_id, name, item);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- g_list_free(sorted_names); /* names themselves are not freed */
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- log_debug("...Done iterating over '%s' for attach", item_name);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- return done;
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-static
|
|
Matej Habrnal |
5c8df3 |
-int attach_files(struct abrt_xmlrpc *ax, const char *bug_id,
|
|
Matej Habrnal |
5c8df3 |
- problem_data_t *pd, GList *comment_fmt_spec)
|
|
Matej Habrnal |
5c8df3 |
-{
|
|
Matej Habrnal |
5c8df3 |
- int done = 0;
|
|
Matej Habrnal |
5c8df3 |
- GList *l = comment_fmt_spec;
|
|
Matej Habrnal |
5c8df3 |
- while (l)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- section_t *sec = l->data;
|
|
Matej Habrnal |
5c8df3 |
- l = l->next;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- /* Find %attach" */
|
|
Matej Habrnal |
5c8df3 |
- if (strcmp(sec->name, "%attach") != 0)
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- GList *item = sec->items;
|
|
Matej Habrnal |
5c8df3 |
- while (item)
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- const char *str = item->data;
|
|
Matej Habrnal |
5c8df3 |
- item = item->next;
|
|
Matej Habrnal |
5c8df3 |
- if (str[0] == '-') /* "-name", ignore it */
|
|
Matej Habrnal |
5c8df3 |
- continue;
|
|
Matej Habrnal |
5c8df3 |
- done |= attach_item(ax, bug_id, str, pd, comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
- return done;
|
|
Matej Habrnal |
5c8df3 |
-}
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
/* Main */
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
struct bugzilla_struct {
|
|
Matej Habrnal |
5c8df3 |
@@ -1102,18 +500,29 @@ int main(int argc, char **argv)
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
if (opts & OPT_D)
|
|
Matej Habrnal |
5c8df3 |
{
|
|
Matej Habrnal |
5c8df3 |
- GList *comment_fmt_spec = load_bzrep_conf_file(fmt_file);
|
|
Matej Habrnal |
5c8df3 |
- struct strbuf *bzcomment_buf = strbuf_new();
|
|
Matej Habrnal |
5c8df3 |
- generate_bz_comment(bzcomment_buf, problem_data, comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
- char *bzcomment = strbuf_free_nobuf(bzcomment_buf);
|
|
Matej Habrnal |
5c8df3 |
- char *summary = create_summary_string(problem_data, comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
+ problem_formatter_t *pf = problem_formatter_new();
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ if (problem_formatter_load_file(pf, fmt_file))
|
|
Matej Habrnal |
5c8df3 |
+ error_msg_and_die("Invalid format file: %s", fmt_file);
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_t *pr = NULL;
|
|
Matej Habrnal |
5c8df3 |
+ if (problem_formatter_generate_report(pf, problem_data, &pr))
|
|
Matej Habrnal |
5c8df3 |
+ error_msg_and_die("Failed to format bug report from problem data");
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
printf("summary: %s\n"
|
|
Matej Habrnal |
5c8df3 |
"\n"
|
|
Matej Habrnal |
5c8df3 |
"%s"
|
|
Matej Habrnal |
5c8df3 |
- , summary, bzcomment
|
|
Matej Habrnal |
5c8df3 |
+ "\n"
|
|
Matej Habrnal |
5c8df3 |
+ , problem_report_get_summary(pr)
|
|
Matej Habrnal |
5c8df3 |
+ , problem_report_get_description(pr)
|
|
Matej Habrnal |
5c8df3 |
);
|
|
Matej Habrnal |
5c8df3 |
- free(bzcomment);
|
|
Matej Habrnal |
5c8df3 |
- free(summary);
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ puts("attachments:");
|
|
Matej Habrnal |
5c8df3 |
+ for (GList *a = problem_report_get_attachments(pr); a != NULL; a = g_list_next(a))
|
|
Matej Habrnal |
5c8df3 |
+ printf(" %s\n", (const char *)a->data);
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_free(pr);
|
|
Matej Habrnal |
5c8df3 |
+ problem_formatter_free(pf);
|
|
Matej Habrnal |
5c8df3 |
exit(0);
|
|
Matej Habrnal |
5c8df3 |
}
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
@@ -1196,22 +605,29 @@ int main(int argc, char **argv)
|
|
Matej Habrnal |
5c8df3 |
/* Create new bug */
|
|
Matej Habrnal |
5c8df3 |
log(_("Creating a new bug"));
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
- GList *comment_fmt_spec = load_bzrep_conf_file(fmt_file);
|
|
Matej Habrnal |
5c8df3 |
+ problem_formatter_t *pf = problem_formatter_new();
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ if (problem_formatter_load_file(pf, fmt_file))
|
|
Matej Habrnal |
5c8df3 |
+ error_msg_and_die("Invalid format file: %s", fmt_file);
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_t *pr = NULL;
|
|
Matej Habrnal |
5c8df3 |
+ if (problem_formatter_generate_report(pf, problem_data, &pr))
|
|
Matej Habrnal |
5c8df3 |
+ error_msg_and_die("Failed to format problem data");
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
- struct strbuf *bzcomment_buf = strbuf_new();
|
|
Matej Habrnal |
5c8df3 |
- generate_bz_comment(bzcomment_buf, problem_data, comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
if (crossver_id >= 0)
|
|
Matej Habrnal |
5c8df3 |
- strbuf_append_strf(bzcomment_buf, "\nPotential duplicate: bug %u\n", crossver_id);
|
|
Matej Habrnal |
5c8df3 |
- char *bzcomment = strbuf_free_nobuf(bzcomment_buf);
|
|
Matej Habrnal |
5c8df3 |
- char *summary = create_summary_string(problem_data, comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_buffer_printf(
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_get_buffer(pr, PR_SEC_DESCRIPTION),
|
|
Matej Habrnal |
5c8df3 |
+ "\nPotential duplicate: bug %u\n", crossver_id);
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ problem_formatter_free(pf);
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
int new_id = rhbz_new_bug(client,
|
|
Matej Habrnal |
5c8df3 |
problem_data, rhbz.b_product, rhbz.b_product_version,
|
|
Matej Habrnal |
5c8df3 |
- summary, bzcomment,
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_get_summary(pr),
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_get_description(pr),
|
|
Matej Habrnal |
5c8df3 |
(rhbz.b_create_private | (opts & OPT_g)), // either we got Bugzilla_CreatePrivate from settings or -g was specified on cmdline
|
|
Matej Habrnal |
5c8df3 |
rhbz.b_private_groups
|
|
Matej Habrnal |
5c8df3 |
);
|
|
Matej Habrnal |
5c8df3 |
- free(bzcomment);
|
|
Matej Habrnal |
5c8df3 |
- free(summary);
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
if (new_id == -1)
|
|
Matej Habrnal |
5c8df3 |
{
|
|
Matej Habrnal |
5c8df3 |
@@ -1236,9 +652,17 @@ int main(int argc, char **argv)
|
|
Matej Habrnal |
5c8df3 |
char new_id_str[sizeof(int)*3 + 2];
|
|
Matej Habrnal |
5c8df3 |
sprintf(new_id_str, "%i", new_id);
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
- attach_files(client, new_id_str, problem_data, comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
-
|
|
Matej Habrnal |
5c8df3 |
-//TODO: free_comment_fmt_spec(comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
+ for (GList *a = problem_report_get_attachments(pr); a != NULL; a = g_list_next(a))
|
|
Matej Habrnal |
5c8df3 |
+ {
|
|
Matej Habrnal |
5c8df3 |
+ const char *item_name = (const char *)a->data;
|
|
Matej Habrnal |
5c8df3 |
+ struct problem_item *item = problem_data_get_item_or_NULL(problem_data, item_name);
|
|
Matej Habrnal |
5c8df3 |
+ if (!item)
|
|
Matej Habrnal |
5c8df3 |
+ continue;
|
|
Matej Habrnal |
5c8df3 |
+ else if (item->flags & CD_FLAG_TXT)
|
|
Matej Habrnal |
5c8df3 |
+ attach_text_item(client, new_id_str, item_name, item);
|
|
Matej Habrnal |
5c8df3 |
+ else if (item->flags & CD_FLAG_BIN)
|
|
Matej Habrnal |
5c8df3 |
+ attach_file_item(client, new_id_str, item_name, item);
|
|
Matej Habrnal |
5c8df3 |
+ }
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
bz = new_bug_info();
|
|
Matej Habrnal |
5c8df3 |
bz->bi_status = xstrdup("NEW");
|
|
Matej Habrnal |
5c8df3 |
@@ -1302,18 +726,21 @@ int main(int argc, char **argv)
|
|
Matej Habrnal |
5c8df3 |
const char *comment = problem_data_get_content_or_NULL(problem_data, FILENAME_COMMENT);
|
|
Matej Habrnal |
5c8df3 |
if (comment && comment[0])
|
|
Matej Habrnal |
5c8df3 |
{
|
|
Matej Habrnal |
5c8df3 |
- GList *comment_fmt_spec = load_bzrep_conf_file(fmt_file2);
|
|
Matej Habrnal |
5c8df3 |
- struct strbuf *bzcomment_buf = strbuf_new();
|
|
Matej Habrnal |
5c8df3 |
- generate_bz_comment(bzcomment_buf, problem_data, comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
- char *bzcomment = strbuf_free_nobuf(bzcomment_buf);
|
|
Matej Habrnal |
5c8df3 |
-//TODO: free_comment_fmt_spec(comment_fmt_spec);
|
|
Matej Habrnal |
5c8df3 |
+ problem_formatter_t *pf = problem_formatter_new();
|
|
Matej Habrnal |
5c8df3 |
+ if (problem_formatter_load_file(pf, fmt_file2))
|
|
Matej Habrnal |
5c8df3 |
+ error_msg_and_die("Invalid duplicate format file: '%s", fmt_file2);
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_t *pr;
|
|
Matej Habrnal |
5c8df3 |
+ if (problem_formatter_generate_report(pf, problem_data, &pr))
|
|
Matej Habrnal |
5c8df3 |
+ error_msg_and_die("Failed to format duplicate comment from problem data");
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ const char *bzcomment = problem_report_get_description(pr);
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
int dup_comment = is_comment_dup(bz->bi_comments, bzcomment);
|
|
Matej Habrnal |
5c8df3 |
if (!dup_comment)
|
|
Matej Habrnal |
5c8df3 |
{
|
|
Matej Habrnal |
5c8df3 |
log(_("Adding new comment to bug %d"), bz->bi_id);
|
|
Matej Habrnal |
5c8df3 |
rhbz_add_comment(client, bz->bi_id, bzcomment, 0);
|
|
Matej Habrnal |
5c8df3 |
- free(bzcomment);
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
const char *bt = problem_data_get_content_or_NULL(problem_data, FILENAME_BACKTRACE);
|
|
Matej Habrnal |
5c8df3 |
unsigned rating = 0;
|
|
Matej Habrnal |
5c8df3 |
@@ -1331,10 +758,10 @@ int main(int argc, char **argv)
|
|
Matej Habrnal |
5c8df3 |
}
|
|
Matej Habrnal |
5c8df3 |
}
|
|
Matej Habrnal |
5c8df3 |
else
|
|
Matej Habrnal |
5c8df3 |
- {
|
|
Matej Habrnal |
5c8df3 |
- free(bzcomment);
|
|
Matej Habrnal |
5c8df3 |
log(_("Found the same comment in the bug history, not adding a new one"));
|
|
Matej Habrnal |
5c8df3 |
- }
|
|
Matej Habrnal |
5c8df3 |
+
|
|
Matej Habrnal |
5c8df3 |
+ problem_report_free(pr);
|
|
Matej Habrnal |
5c8df3 |
+ problem_formatter_free(pf);
|
|
Matej Habrnal |
5c8df3 |
}
|
|
Matej Habrnal |
5c8df3 |
|
|
Matej Habrnal |
5c8df3 |
log_out:
|
|
Matej Habrnal |
5c8df3 |
--
|
|
Matej Habrnal |
5c8df3 |
1.8.3.1
|
|
Matej Habrnal |
5c8df3 |
|