VLC 4.0.0-dev
Loading...
Searching...
No Matches
info.h
Go to the documentation of this file.
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
28static inline info_t *info_New(const char *name)
29{
30 info_t *info = malloc(sizeof(*info));
31 if (!info)
32 return NULL;
33
34 info->psz_name = strdup(name);
35 info->psz_value = NULL;
36 return info;
37}
38
39static inline void info_Delete(info_t *i)
40{
41 free(i->psz_name);
42 free(i->psz_value);
43 free(i);
44}
45
46static inline info_category_t *info_category_New(const char *name)
47{
48 info_category_t *cat = malloc(sizeof(*cat));
49 if (!cat)
50 return NULL;
51 cat->psz_name = strdup(name);
52 vlc_list_init(&cat->infos);
53 return cat;
54}
55
57 const char *name)
58{
59 info_t *info;
60
61 info_foreach(info, &cat->infos)
62 if (!strcmp(info->psz_name, name))
63 return info;
64 return NULL;
65}
66
68 info_t *info)
69{
70 info_t *old = info_category_FindInfo(cat, info->psz_name);
71 if (old) {
72 vlc_list_remove(&old->node);
73 info_Delete(old);
74 }
75 vlc_list_append(&info->node, &cat->infos);
76}
77
79 const char *name,
80 const char *format, va_list args)
81{
83 if (!info) {
84 info = info_New(name);
85 if (!info)
86 return NULL;
87 vlc_list_append(&info->node, &cat->infos);
88 } else
89 free(info->psz_value);
90 if (vasprintf(&info->psz_value, format, args) == -1)
91 info->psz_value = NULL;
92 return info;
93}
94
96 const char *name,
97 const char *format, ...)
98{
99 va_list args;
100
101 va_start(args, format);
102 info_t *info = info_category_VaAddInfo(cat, name, format, args);
103 va_end(args);
104
105 return info;
106}
107
108static inline int info_category_DeleteInfo(info_category_t *cat, const char *name)
109{
110 info_t *info = info_category_FindInfo(cat, name);
111 if (info != NULL) {
112 vlc_list_remove(&info->node);
113 info_Delete(info);
114 return VLC_SUCCESS;
115 }
116 return VLC_EGENERIC;
117}
118
119static inline void info_category_Delete(info_category_t *cat)
120{
121 info_t *info;
122
123 while ((info = vlc_list_first_entry_or_null(&cat->infos, info_t, node))) {
124 vlc_list_remove(&info->node);
125 info_Delete(info);
126 }
127 free(cat->psz_name);
128 free(cat);
129}
130
131#endif
#define VLC_EGENERIC
Unspecified error.
Definition vlc_common.h:480
#define VLC_SUCCESS
No error.
Definition vlc_common.h:478
static void vlc_list_append(struct vlc_list *restrict node, struct vlc_list *head)
Appends an element into a list.
Definition vlc_list.h:110
static void vlc_list_init(struct vlc_list *restrict head)
Initializes an empty list head.
Definition vlc_list.h:57
#define vlc_list_first_entry_or_null(head, type, member)
Gets the first element.
Definition vlc_list.h:369
static void vlc_list_remove(struct vlc_list *restrict node)
Removes an element from a list.
Definition vlc_list.h:135
const char name[16]
Definition httpd.c:1298
static void info_category_ReplaceInfo(info_category_t *cat, info_t *info)
Definition info.h:67
static void info_Delete(info_t *i)
Definition info.h:39
static info_t * info_category_AddInfo(info_category_t *cat, const char *name, const char *format,...)
Definition info.h:95
static info_t * info_category_FindInfo(info_category_t *cat, const char *name)
Definition info.h:56
static info_category_t * info_category_New(const char *name)
Definition info.h:46
static void info_category_Delete(info_category_t *cat)
Definition info.h:119
static info_t * info_category_VaAddInfo(info_category_t *cat, const char *name, const char *format, va_list args)
Definition info.h:78
static int info_category_DeleteInfo(info_category_t *cat, const char *name)
Definition info.h:108
static info_t * info_New(const char *name)
Definition info.h:28
Definition vlc_input_item.h:55
char * psz_name
Name of this category.
Definition vlc_input_item.h:56
struct vlc_list infos
Infos in the category.
Definition vlc_input_item.h:57
Definition vlc_input_item.h:46
struct vlc_list node
Definition vlc_input_item.h:49
char * psz_value
Value of the info.
Definition vlc_input_item.h:48
char * psz_name
Name of this info.
Definition vlc_input_item.h:47
char * strdup(const char *)
int vasprintf(char **, const char *, va_list)
This file defines functions, structures and enums for input items in vlc.
#define info_foreach(info, cat)
Definition vlc_input_item.h:52