1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010 Laurent Aimar
6 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
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.
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.
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 *****************************************************************************/
23 #ifndef LIBVLC_INPUT_INFO_H
24 #define LIBVLC_INPUT_INFO_H 1
26 #include "vlc_input_item.h"
28 static inline info_t
*info_New(const char *name
)
30 info_t
*info
= malloc(sizeof(*info
));
34 info
->psz_name
= strdup(name
);
35 info
->psz_value
= NULL
;
39 static inline void info_Delete(info_t
*i
)
46 static inline info_category_t
*info_category_New(const char *name
)
48 info_category_t
*cat
= malloc(sizeof(*cat
));
51 cat
->psz_name
= strdup(name
);
52 vlc_list_init(&cat
->infos
);
56 static inline info_t
*info_category_FindInfo(const info_category_t
*cat
,
61 info_foreach(info
, &cat
->infos
)
62 if (!strcmp(info
->psz_name
, name
))
67 static inline void info_category_ReplaceInfo(info_category_t
*cat
,
70 info_t
*old
= info_category_FindInfo(cat
, info
->psz_name
);
72 vlc_list_remove(&old
->node
);
75 vlc_list_append(&info
->node
, &cat
->infos
);
78 static inline info_t
*info_category_VaAddInfo(info_category_t
*cat
,
80 const char *format
, va_list args
)
82 info_t
*info
= info_category_FindInfo(cat
, name
);
84 info
= info_New(name
);
87 vlc_list_append(&info
->node
, &cat
->infos
);
89 free(info
->psz_value
);
90 if (vasprintf(&info
->psz_value
, format
, args
) == -1)
91 info
->psz_value
= NULL
;
95 static inline info_t
*info_category_AddInfo(info_category_t
*cat
,
97 const char *format
, ...)
101 va_start(args
, format
);
102 info_t
*info
= info_category_VaAddInfo(cat
, name
, format
, args
);
108 static inline int info_category_DeleteInfo(info_category_t
*cat
, const char *name
)
110 info_t
*info
= info_category_FindInfo(cat
, name
);
112 vlc_list_remove(&info
->node
);
119 static inline void info_category_Delete(info_category_t
*cat
)
123 while ((info
= vlc_list_first_entry_or_null(&cat
->infos
, info_t
, node
))) {
124 vlc_list_remove(&info
->node
);