libreport  2.5.0
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 int problem_item_get_size(struct problem_item *item, unsigned long *size);
63 
64 /* In-memory problem data structure and accessors */
65 
66 typedef GHashTable problem_data_t;
67 
68 problem_data_t *problem_data_new(void);
69 
70 static inline void problem_data_free(problem_data_t *problem_data)
71 {
72  //TODO: leaks problem item;
73  if (problem_data)
74  g_hash_table_destroy(problem_data);
75 }
76 
77 void problem_data_add_basics(problem_data_t *pd);
78 
79 void problem_data_add_current_process_data(problem_data_t *pd);
80 
81 void problem_data_add(problem_data_t *problem_data,
82  const char *name,
83  const char *content,
84  unsigned flags);
85 void problem_data_add_text_noteditable(problem_data_t *problem_data,
86  const char *name,
87  const char *content);
88 void problem_data_add_text_editable(problem_data_t *problem_data,
89  const char *name,
90  const char *content);
91 /* "name" can be NULL: */
92 void problem_data_add_file(problem_data_t *pd, const char *name, const char *path);
93 
94 static inline struct problem_item *problem_data_get_item_or_NULL(problem_data_t *problem_data, const char *key)
95 {
96  return (struct problem_item *)g_hash_table_lookup(problem_data, key);
97 }
98 char *problem_data_get_content_or_NULL(problem_data_t *problem_data, const char *key);
99 /* Aborts if key is not found: */
100 char *problem_data_get_content_or_die(problem_data_t *problem_data, const char *key);
101 
116 void problem_data_get_osinfo(problem_data_t *problem_data, map_string_t *osinfo);
117 
118 int problem_data_send_to_abrt(problem_data_t* problem_data);
119 
120 /* Conversions between in-memory and on-disk formats */
121 
122 void problem_data_load_from_dump_dir(problem_data_t *problem_data, struct dump_dir *dd, char **excluding);
123 
124 problem_data_t *create_problem_data_from_dump_dir(struct dump_dir *dd);
125 /* Helper for typical operation in reporters: */
126 problem_data_t *create_problem_data_for_reporting(const char *dump_dir_name);
127 
134 struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name);
135 
143 int save_problem_data_in_dump_dir(struct dump_dir *dd, problem_data_t *problem_data);
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #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.
int save_problem_data_in_dump_dir(struct dump_dir *dd, problem_data_t *problem_data)
Saves the problem data object in opened dump directory.