libreport  2.2.3.38.ge4d4
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 "libreport_types.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  /* If element is HUGE text, it is not read into memory (it can OOM the machine).
42  * Instead, it is treated as binary (CD_FLAG_BIN), but also has CD_FLAG_BIGTXT
43  * bit set in flags. This allows to set proper MIME type when it gets attached
44  * to a bug report etc.
45  */
46  CD_FLAG_BIGTXT = (1 << 6),
47 };
48 
49 struct problem_item {
50  char *content;
51  unsigned flags;
52  /* Used by UI for presenting "item allowed/not allowed" checkboxes: */
53  int selected_by_user; /* 0 "don't know", -1 "no", 1 "yes" */
54  int allowed_by_reporter; /* 0 "no", 1 "yes" */
55  int default_by_reporter; /* 0 "no", 1 "yes" */
56  int required_by_reporter; /* 0 "no", 1 "yes" */
57 };
58 typedef struct problem_item problem_item;
59 
60 char *problem_item_format(struct problem_item *item);
61 
62 
63 /* In-memory problem data structure and accessors */
64 
65 typedef GHashTable problem_data_t;
66 
67 problem_data_t *problem_data_new(void);
68 
69 static inline void problem_data_free(problem_data_t *problem_data)
70 {
71  //TODO: leaks problem item;
72  if (problem_data)
73  g_hash_table_destroy(problem_data);
74 }
75 
76 void problem_data_add_basics(problem_data_t *pd);
77 
78 void problem_data_add_current_process_data(problem_data_t *pd);
79 
80 void problem_data_add(problem_data_t *problem_data,
81  const char *name,
82  const char *content,
83  unsigned flags);
84 void problem_data_add_text_noteditable(problem_data_t *problem_data,
85  const char *name,
86  const char *content);
87 void problem_data_add_text_editable(problem_data_t *problem_data,
88  const char *name,
89  const char *content);
90 /* "name" can be NULL: */
91 void problem_data_add_file(problem_data_t *pd, const char *name, const char *path);
92 
93 static inline struct problem_item *problem_data_get_item_or_NULL(problem_data_t *problem_data, const char *key)
94 {
95  return (struct problem_item *)g_hash_table_lookup(problem_data, key);
96 }
97 char *problem_data_get_content_or_NULL(problem_data_t *problem_data, const char *key);
98 /* Aborts if key is not found: */
99 char *problem_data_get_content_or_die(problem_data_t *problem_data, const char *key);
100 
115 void problem_data_get_osinfo(problem_data_t *problem_data, map_string_t *osinfo);
116 
117 int problem_data_send_to_abrt(problem_data_t* problem_data);
118 
119 /* Conversions between in-memory and on-disk formats */
120 
121 void problem_data_load_from_dump_dir(problem_data_t *problem_data, struct dump_dir *dd, char **excluding);
122 
123 problem_data_t *create_problem_data_from_dump_dir(struct dump_dir *dd);
124 /* Helper for typical operation in reporters: */
125 problem_data_t *create_problem_data_for_reporting(const char *dump_dir_name);
126 
133 struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif
void problem_data_get_osinfo(problem_data_t *problem_data, map_string_t *osinfo)
Loads key value pairs from os_info item in to the osinfo argument.
struct dump_dir * create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name)
Saves the problem data object.