/src/vlc/src/input/info.h
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * info.h |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2010 Laurent Aimar |
5 | | * |
6 | | * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org> |
7 | | * |
8 | | * This program is free software; you can redistribute it and/or modify it |
9 | | * under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation; either version 2.1 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU Lesser General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program; if not, write to the Free Software Foundation, |
20 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
21 | | *****************************************************************************/ |
22 | | |
23 | | #ifndef LIBVLC_INPUT_INFO_H |
24 | | #define LIBVLC_INPUT_INFO_H 1 |
25 | | |
26 | | #include "vlc_input_item.h" |
27 | | |
28 | | static inline info_t *info_New(const char *name) |
29 | 0 | { |
30 | 0 | info_t *info = malloc(sizeof(*info)); |
31 | 0 | if (!info) |
32 | 0 | return NULL; |
33 | | |
34 | 0 | info->psz_name = strdup(name); |
35 | 0 | info->psz_value = NULL; |
36 | 0 | return info; |
37 | 0 | } Unexecuted instantiation: item.c:info_New Unexecuted instantiation: parse.c:info_New Unexecuted instantiation: es_out.c:info_New |
38 | | |
39 | | static inline void info_Delete(info_t *i) |
40 | 0 | { |
41 | 0 | free(i->psz_name); |
42 | 0 | free(i->psz_value); |
43 | 0 | free(i); |
44 | 0 | } Unexecuted instantiation: item.c:info_Delete Unexecuted instantiation: parse.c:info_Delete Unexecuted instantiation: es_out.c:info_Delete |
45 | | |
46 | | static inline info_category_t *info_category_New(const char *name) |
47 | 0 | { |
48 | 0 | info_category_t *cat = malloc(sizeof(*cat)); |
49 | 0 | if (!cat) |
50 | 0 | return NULL; |
51 | 0 | cat->psz_name = strdup(name); |
52 | 0 | vlc_list_init(&cat->infos); |
53 | 0 | return cat; |
54 | 0 | } Unexecuted instantiation: item.c:info_category_New Unexecuted instantiation: parse.c:info_category_New Unexecuted instantiation: es_out.c:info_category_New |
55 | | |
56 | | static inline info_t *info_category_FindInfo(info_category_t *cat, |
57 | | const char *name) |
58 | 0 | { |
59 | 0 | info_t *info; |
60 | |
|
61 | 0 | info_foreach(info, &cat->infos) |
62 | 0 | if (!strcmp(info->psz_name, name)) |
63 | 0 | return info; |
64 | 0 | return NULL; |
65 | 0 | } Unexecuted instantiation: item.c:info_category_FindInfo Unexecuted instantiation: parse.c:info_category_FindInfo Unexecuted instantiation: es_out.c:info_category_FindInfo |
66 | | |
67 | | static inline void info_category_ReplaceInfo(info_category_t *cat, |
68 | | info_t *info) |
69 | 0 | { |
70 | 0 | info_t *old = info_category_FindInfo(cat, info->psz_name); |
71 | 0 | if (old) { |
72 | 0 | vlc_list_remove(&old->node); |
73 | 0 | info_Delete(old); |
74 | 0 | } |
75 | 0 | vlc_list_append(&info->node, &cat->infos); |
76 | 0 | } Unexecuted instantiation: item.c:info_category_ReplaceInfo Unexecuted instantiation: parse.c:info_category_ReplaceInfo Unexecuted instantiation: es_out.c:info_category_ReplaceInfo |
77 | | |
78 | | static inline info_t *info_category_VaAddInfo(info_category_t *cat, |
79 | | const char *name, |
80 | | const char *format, va_list args) |
81 | 0 | { |
82 | 0 | info_t *info = info_category_FindInfo(cat, name); |
83 | 0 | if (!info) { |
84 | 0 | info = info_New(name); |
85 | 0 | if (!info) |
86 | 0 | return NULL; |
87 | 0 | vlc_list_append(&info->node, &cat->infos); |
88 | 0 | } else |
89 | 0 | free(info->psz_value); |
90 | 0 | if (vasprintf(&info->psz_value, format, args) == -1) |
91 | 0 | info->psz_value = NULL; |
92 | 0 | return info; |
93 | 0 | } Unexecuted instantiation: item.c:info_category_VaAddInfo Unexecuted instantiation: parse.c:info_category_VaAddInfo Unexecuted instantiation: es_out.c:info_category_VaAddInfo |
94 | | |
95 | | static inline info_t *info_category_AddInfo(info_category_t *cat, |
96 | | const char *name, |
97 | | const char *format, ...) |
98 | 0 | { |
99 | 0 | va_list args; |
100 | |
|
101 | 0 | va_start(args, format); |
102 | 0 | info_t *info = info_category_VaAddInfo(cat, name, format, args); |
103 | 0 | va_end(args); |
104 | |
|
105 | 0 | return info; |
106 | 0 | } Unexecuted instantiation: item.c:info_category_AddInfo Unexecuted instantiation: parse.c:info_category_AddInfo Unexecuted instantiation: es_out.c:info_category_AddInfo |
107 | | |
108 | | static inline int info_category_DeleteInfo(info_category_t *cat, const char *name) |
109 | 0 | { |
110 | 0 | info_t *info = info_category_FindInfo(cat, name); |
111 | 0 | if (info != NULL) { |
112 | 0 | vlc_list_remove(&info->node); |
113 | 0 | info_Delete(info); |
114 | 0 | return VLC_SUCCESS; |
115 | 0 | } |
116 | 0 | return VLC_EGENERIC; |
117 | 0 | } Unexecuted instantiation: item.c:info_category_DeleteInfo Unexecuted instantiation: parse.c:info_category_DeleteInfo Unexecuted instantiation: es_out.c:info_category_DeleteInfo |
118 | | |
119 | | static inline void info_category_Delete(info_category_t *cat) |
120 | 0 | { |
121 | 0 | info_t *info; |
122 | |
|
123 | 0 | while ((info = vlc_list_first_entry_or_null(&cat->infos, info_t, node))) { |
124 | 0 | vlc_list_remove(&info->node); |
125 | 0 | info_Delete(info); |
126 | 0 | } |
127 | 0 | free(cat->psz_name); |
128 | 0 | free(cat); |
129 | 0 | } Unexecuted instantiation: item.c:info_category_Delete Unexecuted instantiation: parse.c:info_category_Delete Unexecuted instantiation: es_out.c:info_category_Delete |
130 | | |
131 | | #endif |