1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010 Laurent Aimar
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
25 # error This header file can only be included from LibVLC.
29 #define _INPUT_INFO_H 1
31 #include "vlc_input_item.h"
33 static inline info_t *info_New(const char *name, const char *value )
35 info_t *info = malloc(sizeof(*info));
39 info->psz_name = strdup(name);
40 info->psz_value = value ? strdup(value) : NULL;
44 static inline void info_Delete(info_t *i)
51 static inline info_category_t *info_category_New(const char *name)
53 info_category_t *cat = malloc(sizeof(*cat));
56 cat->psz_name = strdup(name);
63 static inline info_t *info_category_FindInfo(const info_category_t *cat,
64 int *index, const char *name)
66 for (int i = 0; i < cat->i_infos; i++) {
67 if (!strcmp(cat->pp_infos[i]->psz_name, name)) {
70 return cat->pp_infos[i];
76 static inline void info_category_AddInfo(info_category_t *cat, info_t *info)
79 if (info_category_FindInfo(cat, &index, info->psz_name)) {
80 info_Delete(cat->pp_infos[index]);
81 cat->pp_infos[index] = info;
83 INSERT_ELEM(cat->pp_infos, cat->i_infos, cat->i_infos, info);
86 static inline info_t *info_category_VaAddInfo(info_category_t *cat,
88 const char *format, va_list args)
90 info_t *info = info_category_FindInfo(cat, NULL, name);
92 info = info_New(name, NULL);
95 INSERT_ELEM(cat->pp_infos, cat->i_infos, cat->i_infos, info);
97 free(info->psz_value);
99 if (vasprintf(&info->psz_value, format, args) == -1)
100 info->psz_value = NULL;
104 static inline int info_category_DeleteInfo(info_category_t *cat, const char *name)
107 if (info_category_FindInfo(cat, &index, name)) {
108 info_Delete(cat->pp_infos[index]);
109 REMOVE_ELEM(cat->pp_infos, cat->i_infos, index);
115 static inline void info_category_Delete(info_category_t *cat)
117 for (int i = 0; i < cat->i_infos; i++)
118 info_Delete(cat->pp_infos[i]);