info.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
00025 # error This header file can only be included from LibVLC.
00026 #endif
00027
00028 #ifndef _INPUT_INFO_H
00029 #define _INPUT_INFO_H 1
00030
00031 #include "vlc_input_item.h"
00032
00033 static inline info_t *info_New(const char *name, const char *value )
00034 {
00035 info_t *info = malloc(sizeof(*info));
00036 if (!info)
00037 return NULL;
00038
00039 info->psz_name = strdup(name);
00040 info->psz_value = value ? strdup(value) : NULL;
00041 return info;
00042 }
00043
00044 static inline void info_Delete(info_t *i)
00045 {
00046 free(i->psz_name);
00047 free(i->psz_value);
00048 free(i);
00049 }
00050
00051 static inline info_category_t *info_category_New(const char *name)
00052 {
00053 info_category_t *cat = malloc(sizeof(*cat));
00054 if (!cat)
00055 return NULL;
00056 cat->psz_name = strdup(name);
00057 cat->i_infos = 0;
00058 cat->pp_infos = NULL;
00059
00060 return cat;
00061 }
00062
00063 static inline info_t *info_category_FindInfo(const info_category_t *cat,
00064 int *index, const char *name)
00065 {
00066 for (int i = 0; i < cat->i_infos; i++) {
00067 if (!strcmp(cat->pp_infos[i]->psz_name, name)) {
00068 if (index)
00069 *index = i;
00070 return cat->pp_infos[i];
00071 }
00072 }
00073 return NULL;
00074 }
00075
00076 static inline void info_category_ReplaceInfo(info_category_t *cat,
00077 info_t *info)
00078 {
00079 int index;
00080 info_t *old = info_category_FindInfo(cat, &index, info->psz_name);
00081 if (old) {
00082 info_Delete(cat->pp_infos[index]);
00083 cat->pp_infos[index] = info;
00084 } else {
00085 INSERT_ELEM(cat->pp_infos, cat->i_infos, cat->i_infos, info);
00086 }
00087 }
00088
00089 static inline info_t *info_category_VaAddInfo(info_category_t *cat,
00090 const char *name,
00091 const char *format, va_list args)
00092 {
00093 info_t *info = info_category_FindInfo(cat, NULL, name);
00094 if (!info) {
00095 info = info_New(name, NULL);
00096 if (!info)
00097 return NULL;
00098 INSERT_ELEM(cat->pp_infos, cat->i_infos, cat->i_infos, info);
00099 } else {
00100 free(info->psz_value);
00101 }
00102 if (vasprintf(&info->psz_value, format, args) == -1)
00103 info->psz_value = NULL;
00104 return info;
00105 }
00106
00107 static inline info_t *info_category_AddInfo(info_category_t *cat,
00108 const char *name,
00109 const char *format, ...)
00110 {
00111 va_list args;
00112
00113 va_start(args, format);
00114 info_t *info = info_category_VaAddInfo(cat, name, format, args);
00115 va_end(args);
00116
00117 return info;
00118 }
00119
00120 static inline int info_category_DeleteInfo(info_category_t *cat, const char *name)
00121 {
00122 int index;
00123 if (info_category_FindInfo(cat, &index, name)) {
00124 info_Delete(cat->pp_infos[index]);
00125 REMOVE_ELEM(cat->pp_infos, cat->i_infos, index);
00126 return VLC_SUCCESS;
00127 }
00128 return VLC_EGENERIC;
00129 }
00130
00131 static inline void info_category_Delete(info_category_t *cat)
00132 {
00133 for (int i = 0; i < cat->i_infos; i++)
00134 info_Delete(cat->pp_infos[i]);
00135 free(cat->pp_infos);
00136 free(cat->psz_name);
00137 free(cat);
00138 }
00139
00140 #endif