libreport 2.13.1
A tool to inform users about various problems on the running system
libreport_types.h
1/*
2 Copyright (C) 2013 ABRT team
3 Copyright (C) 2013 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#ifndef LIBREPORT_TYPES_H_
20#define LIBREPORT_TYPES_H_
21
22#include <stdbool.h>
23#include <glib.h>
24
25typedef gchar **string_vector_ptr_t;
26typedef const gchar *const *const_string_vector_const_ptr_t;
27
28string_vector_ptr_t libreport_string_vector_new_from_string(const char *vector);
29void libreport_string_vector_free(string_vector_ptr_t vector);
30
31typedef GHashTable map_string_t;
32map_string_t *libreport_new_map_string(void);
33void libreport_free_map_string(map_string_t *ms);
34map_string_t *libreport_clone_map_string(map_string_t *ms);
35static inline
36unsigned libreport_size_map_string(map_string_t *ms)
37{
38 if (ms == NULL)
39 return 0;
40
41 return g_hash_table_size(ms);
42}
43static inline
44void insert_map_string(map_string_t *ms, char *key, char *value)
45{
46 g_hash_table_insert(ms, key, value);
47}
48static inline
49void libreport_replace_map_string_item(map_string_t *ms, char *key, char *value)
50{
51 g_hash_table_replace(ms, key, value);
52}
53static inline
54void libreport_remove_map_string_item(map_string_t *ms, const char *key)
55{
56 g_hash_table_remove(ms, key);
57}
58const char *libreport_get_map_string_item_or_empty(map_string_t *ms, const char *key);
59static inline
60const char *libreport_get_map_string_item_or_NULL(map_string_t *ms, const char *key)
61{
62 return (const char*)g_hash_table_lookup(ms, key);
63}
64
65void libreport_set_map_string_item_from_bool(map_string_t *ms, const char *key, int value);
66int libreport_try_get_map_string_item_as_bool(map_string_t *ms, const char *key, int *value);
67
68void libreport_set_map_string_item_from_int(map_string_t *ms, const char *key, int value);
69int libreport_try_get_map_string_item_as_int(map_string_t *ms, const char *key, int *value);
70
71void libreport_set_map_string_item_from_uint(map_string_t *ms, const char *key, unsigned int value);
72int libreport_try_get_map_string_item_as_uint(map_string_t *ms, const char *key, unsigned int *value);
73
74void libreport_set_map_string_item_from_string(map_string_t *ms, const char *key, const char *value);
75int libreport_try_get_map_string_item_as_string(map_string_t *ms, const char *key, char **value);
76
77void libreport_set_map_string_item_from_string_vector(map_string_t *ms, const char *key, string_vector_ptr_t value);
78int libreport_try_get_map_string_item_as_string_vector(map_string_t *ms, const char *key, string_vector_ptr_t *value);
79
80
81typedef GHashTableIter map_string_iter_t;
82static inline
83void libreport_init_map_string_iter(map_string_iter_t *iter, map_string_t *ms)
84{
85 g_hash_table_iter_init(iter, ms);
86}
87static inline
88int libreport_next_map_string_iter(map_string_iter_t *iter, const char **key, const char **value)
89{
90 return g_hash_table_iter_next(iter, (gpointer *)key, (gpointer *)value);
91}
92
93#endif /* LIBREPORT_TYPES_H_ */