libreport 2.13.1
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
28extern "C" {
29#endif
30
31struct dump_dir;
32
33enum {
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#define PROBLEM_ITEM_UNINITIALIZED_SIZE ((unsigned long)-1)
50
52 char *content;
53 unsigned flags;
54 unsigned long size;
55 /* Used by UI for presenting "item allowed/not allowed" checkboxes: */
56 int selected_by_user; /* 0 "don't know", -1 "no", 1 "yes" */
57 int allowed_by_reporter; /* 0 "no", 1 "yes" */
58 int default_by_reporter; /* 0 "no", 1 "yes" */
59 int required_by_reporter; /* 0 "no", 1 "yes" */
60};
61typedef struct problem_item problem_item;
62
63char *problem_item_format(struct problem_item *item);
64
65int problem_item_get_size(struct problem_item *item, unsigned long *size);
66
67/* In-memory problem data structure and accessors */
68
69typedef GHashTable problem_data_t;
70
71problem_data_t *problem_data_new(void);
72
73static inline void problem_data_free(problem_data_t *problem_data)
74{
75 //TODO: leaks problem item;
76 if (problem_data)
77 g_hash_table_destroy(problem_data);
78}
79
80void problem_data_add_basics(problem_data_t *pd);
81
82void problem_data_add_current_process_data(problem_data_t *pd);
83
84void problem_data_add(problem_data_t *problem_data,
85 const char *name,
86 const char *content,
87 unsigned flags);
88struct problem_item *problem_data_add_ext(problem_data_t *problem_data,
89 const char *name,
90 const char *content,
91 unsigned flags,
92 unsigned long size);
93void problem_data_add_text_noteditable(problem_data_t *problem_data,
94 const char *name,
95 const char *content);
96void problem_data_add_text_editable(problem_data_t *problem_data,
97 const char *name,
98 const char *content);
99/* "name" can be NULL: */
100void problem_data_add_file(problem_data_t *pd, const char *name, const char *path);
101
102static inline struct problem_item *problem_data_get_item_or_NULL(problem_data_t *problem_data, const char *key)
103{
104 return (struct problem_item *)g_hash_table_lookup(problem_data, key);
105}
106char *problem_data_get_content_or_NULL(problem_data_t *problem_data, const char *key);
107/* Aborts if key is not found: */
108char *problem_data_get_content_or_die(problem_data_t *problem_data, const char *key);
109
110/* Returns all element names stored in problem_data */
111static inline GList *problem_data_get_all_elements(problem_data_t *problem_data)
112{
113 return g_hash_table_get_keys(problem_data);
114}
115
130void problem_data_get_osinfo(problem_data_t *problem_data, map_string_t *osinfo);
131
132int problem_data_send_to_abrt(problem_data_t* problem_data);
133
134/* Conversions between in-memory and on-disk formats */
135
136/* Low level function reading data of dump dir elements
137 *
138 * @param dd Dump directory
139 * @param name Requested element
140 * @param content If the element is of type CD_FLAG_TXT, its contents will
141 * loaded to malloced memory and the pointer will be store here.
142 * @param type_flags One of the following : CD_FLAG_BIN, CD_FLAG_TXT, (CD_FLAG_BIGTXT + CD_FLAG_BIN)
143 * @param fd If not NULL, the file descriptor used to read data will not be
144 * closed and will be passed out of the function in this argument.
145 * @return On errors, negative number; otherwise 0.
146 */
147int problem_data_load_dump_dir_element(struct dump_dir *dd, const char *name, char **content, int *type_flags, int *fd);
148
149void problem_data_load_from_dump_dir(problem_data_t *problem_data, struct dump_dir *dd, char **excluding);
150
151problem_data_t *create_problem_data_from_dump_dir(struct dump_dir *dd);
152/* Helper for typical operation in reporters: */
153problem_data_t *create_problem_data_for_reporting(const char *dump_dir_name);
154
161struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name);
162struct dump_dir *create_dump_dir_from_problem_data_ext(problem_data_t *problem_data, const char *base_dir_name, uid_t uid);
163
171int save_problem_data_in_dump_dir(struct dump_dir *dd, problem_data_t *problem_data);
172
173enum {
174 PROBLEM_REPRODUCIBLE_UNKNOWN,
175 PROBLEM_REPRODUCIBLE_YES,
176 PROBLEM_REPRODUCIBLE_RECURRENT,
177
178 _PROBLEM_REPRODUCIBLE_MAX_,
179};
180
181int get_problem_data_reproducible(problem_data_t *problem_data);
182const char *get_problem_data_reproducible_name(int reproducible);
183
184#ifdef __cplusplus
185}
186#endif
187
188#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.
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.
struct dump_dir * create_dump_dir_from_problem_data(problem_data_t *problem_data, const char *base_dir_name)
Saves the problem data object.