libreport  2.1.3
A tool to inform users about various problems on the running system
problem_data.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Abrt team.
3  Copyright (C) 2009 RedHat inc.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
22 #ifndef LIBREPORT_PROBLEM_DATA_H_
23 #define LIBREPORT_PROBLEM_DATA_H_
24 
25 #include <glib.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 struct dump_dir;
32 
33 enum {
34  CD_FLAG_BIN = (1 << 0),
35  CD_FLAG_TXT = (1 << 1),
36  CD_FLAG_ISEDITABLE = (1 << 2),
37  CD_FLAG_ISNOTEDITABLE = (1 << 3),
38  /* Show this element in "short" info (report-cli -l) */
39  CD_FLAG_LIST = (1 << 4),
40  CD_FLAG_UNIXTIME = (1 << 5),
41 };
42 
43 struct problem_item {
44  char *content;
45  unsigned flags;
46  /* Used by UI for presenting "item allowed/not allowed" checkboxes: */
47  int selected_by_user; /* 0 "don't know", -1 "no", 1 "yes" */
48  int allowed_by_reporter; /* 0 "no", 1 "yes" */
49  int default_by_reporter; /* 0 "no", 1 "yes" */
50  int required_by_reporter; /* 0 "no", 1 "yes" */
51 };
52 typedef struct problem_item problem_item;
53 
54 char *problem_item_format(struct problem_item *item);
55 
56 
57 /* In-memory problem data structure and accessors */
58 
59 typedef GHashTable problem_data_t;
60 
61 problem_data_t *problem_data_new(void);
62 
63 static inline void problem_data_free(problem_data_t *problem_data)
64 {
65  //TODO: leaks problem item;
66  if (problem_data)
67  g_hash_table_destroy(problem_data);
68 }
69 
70 void problem_data_add_basics(problem_data_t *pd);
71 
72 void problem_data_add_current_process_data(problem_data_t *pd);
73 
74 void problem_data_add(problem_data_t *problem_data,
75  const char *name,
76  const char *content,
77  unsigned flags);
78 void problem_data_add_text_noteditable(problem_data_t *problem_data,
79  const char *name,
80  const char *content);
81 void problem_data_add_text_editable(problem_data_t *problem_data,
82  const char *name,
83  const char *content);
84 /* "name" can be NULL: */
85 void problem_data_add_file(problem_data_t *pd, const char *name, const char *path);
86 
87 static inline struct problem_item *problem_data_get_item_or_NULL(problem_data_t *problem_data, const char *key)
88 {
89  return (struct problem_item *)g_hash_table_lookup(problem_data, key);
90 }
91 char *problem_data_get_content_or_NULL(problem_data_t *problem_data, const char *key);
92 /* Aborts if key is not found: */
93 char *problem_data_get_content_or_die(problem_data_t *problem_data, const char *key);
94 
95 int problem_data_send_to_abrt(problem_data_t* problem_data);
96 
97 /* Conversions between in-memory and on-disk formats */
98 
99 void problem_data_load_from_dump_dir(problem_data_t *problem_data, struct dump_dir *dd, char **excluding);
100 
101 problem_data_t *create_problem_data_from_dump_dir(struct dump_dir *dd);
102 /* Helper for typical operation in reporters: */
103 problem_data_t *create_problem_data_for_reporting(const char *dump_dir_name);
104 
111 struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name);
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif