XMMS2
|
00001 /* XMMS2 - X Music Multiplexer System 00002 * Copyright (C) 2003-2009 XMMS2 Team 00003 * 00004 * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!! 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 */ 00016 00017 #ifndef __XMMSV_H__ 00018 #define __XMMSV_H__ 00019 00020 #include <stdarg.h> 00021 #include "xmmsc/xmmsc_compiler.h" 00022 #include "xmmsc/xmmsc_stdint.h" 00023 #include "xmmsc/xmmsv_coll.h" 00024 00025 #ifdef __cplusplus 00026 extern "C" { 00027 #endif 00028 00029 typedef enum { 00030 XMMSV_TYPE_NONE, 00031 XMMSV_TYPE_ERROR, 00032 XMMSV_TYPE_INT32, 00033 XMMSV_TYPE_STRING, 00034 XMMSV_TYPE_COLL, 00035 XMMSV_TYPE_BIN, 00036 XMMSV_TYPE_LIST, 00037 XMMSV_TYPE_DICT, 00038 XMMSV_TYPE_END 00039 } xmmsv_type_t; 00040 00041 static inline xmmsv_type_t XMMSV_TYPE_UINT32_IS_DEPRECATED(void) XMMS_DEPRECATED; 00042 static inline xmmsv_type_t 00043 XMMSV_TYPE_UINT32_IS_DEPRECATED (void) 00044 { 00045 return XMMSV_TYPE_INT32; 00046 } 00047 #define XMMSV_TYPE_UINT32 XMMSV_TYPE_UINT32_IS_DEPRECATED() 00048 00049 00050 00051 typedef struct xmmsv_St xmmsv_t; 00052 00053 typedef struct xmmsv_list_iter_St xmmsv_list_iter_t; 00054 typedef struct xmmsv_dict_iter_St xmmsv_dict_iter_t; 00055 00056 xmmsv_t *xmmsv_new_none (void); 00057 xmmsv_t *xmmsv_new_error (const char *errstr); /* FIXME: err id? */ 00058 xmmsv_t *xmmsv_new_int (int32_t i); 00059 xmmsv_t *xmmsv_new_string (const char *s); 00060 xmmsv_t *xmmsv_new_coll (xmmsv_coll_t *coll); 00061 xmmsv_t *xmmsv_new_bin (unsigned char *data, unsigned int len); 00062 00063 xmmsv_t *xmmsv_new_list (void); 00064 xmmsv_t *xmmsv_new_dict (void); 00065 00066 xmmsv_t *xmmsv_ref (xmmsv_t *val); 00067 void xmmsv_unref (xmmsv_t *val); 00068 00069 xmmsv_type_t xmmsv_get_type (const xmmsv_t *val); 00070 int xmmsv_is_type (const xmmsv_t *val, xmmsv_type_t t); 00071 00072 /* legacy aliases */ 00073 int xmmsv_is_error (const xmmsv_t *val); 00074 int xmmsv_is_list (const xmmsv_t *val) XMMS_DEPRECATED; 00075 int xmmsv_is_dict (const xmmsv_t *val) XMMS_DEPRECATED; 00076 00077 const char * xmmsv_get_error_old (const xmmsv_t *val) XMMS_DEPRECATED; 00078 xmmsv_t *xmmsv_make_stringlist (char *array[], int num); 00079 00080 typedef void (*xmmsv_list_foreach_func) (xmmsv_t *value, void *user_data); 00081 typedef void (*xmmsv_dict_foreach_func) (const char *key, xmmsv_t *value, void *user_data); 00082 00083 /* legacy transitional utilities */ 00084 xmmsv_type_t xmmsv_dict_entry_get_type (xmmsv_t *val, const char *key); 00085 xmmsv_t *xmmsv_propdict_to_dict (xmmsv_t *propdict, const char **src_prefs); 00086 00087 int xmmsv_get_error (const xmmsv_t *val, const char **r); 00088 int xmmsv_get_int (const xmmsv_t *val, int32_t *r); 00089 int xmmsv_get_uint (const xmmsv_t *val, uint32_t *r) XMMS_DEPRECATED; 00090 int xmmsv_get_string (const xmmsv_t *val, const char **r); 00091 int xmmsv_get_coll (const xmmsv_t *val, xmmsv_coll_t **coll); 00092 int xmmsv_get_bin (const xmmsv_t *val, const unsigned char **r, unsigned int *rlen); 00093 00094 int xmmsv_get_list_iter (const xmmsv_t *val, xmmsv_list_iter_t **it); 00095 int xmmsv_get_dict_iter (const xmmsv_t *val, xmmsv_dict_iter_t **it); 00096 00097 void xmmsv_list_iter_explicit_destroy (xmmsv_list_iter_t *it); 00098 void xmmsv_dict_iter_explicit_destroy (xmmsv_dict_iter_t *it); 00099 00100 00101 /* List */ 00102 int xmmsv_list_get (xmmsv_t *listv, int pos, xmmsv_t **val); 00103 int xmmsv_list_set (xmmsv_t *listv, int pos, xmmsv_t *val); 00104 int xmmsv_list_append (xmmsv_t *listv, xmmsv_t *val); 00105 int xmmsv_list_insert (xmmsv_t *listv, int pos, xmmsv_t *val); 00106 int xmmsv_list_remove (xmmsv_t *listv, int pos); 00107 int xmmsv_list_move (xmmsv_t *listv, int old_pos, int new_pos); 00108 int xmmsv_list_clear (xmmsv_t *listv); 00109 int xmmsv_list_foreach (xmmsv_t *listv, xmmsv_list_foreach_func func, void* user_data); 00110 int xmmsv_list_get_size (xmmsv_t *listv); 00111 int xmmsv_list_restrict_type (xmmsv_t *listv, xmmsv_type_t type); 00112 00113 int xmmsv_list_get_string (xmmsv_t *v, int pos, const char **val); 00114 int xmmsv_list_get_int (xmmsv_t *v, int pos, int32_t *val); 00115 int xmmsv_list_get_coll (xmmsv_t *v, int pos, xmmsv_coll_t **val); 00116 00117 int xmmsv_list_set_string (xmmsv_t *v, int pos, const char *val); 00118 int xmmsv_list_set_int (xmmsv_t *v, int pos, int32_t val); 00119 int xmmsv_list_set_coll (xmmsv_t *v, int pos, xmmsv_coll_t *val); 00120 00121 int xmmsv_list_insert_string (xmmsv_t *v, int pos, const char *val); 00122 int xmmsv_list_insert_int (xmmsv_t *v, int pos, int32_t val); 00123 int xmmsv_list_insert_coll (xmmsv_t *v, int pos, xmmsv_coll_t *val); 00124 00125 int xmmsv_list_append_string (xmmsv_t *v, const char *val); 00126 int xmmsv_list_append_int (xmmsv_t *v, int32_t val); 00127 int xmmsv_list_append_coll (xmmsv_t *v, xmmsv_coll_t *val); 00128 00129 int xmmsv_list_iter_entry (xmmsv_list_iter_t *it, xmmsv_t **val); 00130 int xmmsv_list_iter_valid (xmmsv_list_iter_t *it); 00131 void xmmsv_list_iter_first (xmmsv_list_iter_t *it); 00132 void xmmsv_list_iter_last (xmmsv_list_iter_t *it); 00133 void xmmsv_list_iter_next (xmmsv_list_iter_t *it); 00134 void xmmsv_list_iter_prev (xmmsv_list_iter_t *it); 00135 int xmmsv_list_iter_seek (xmmsv_list_iter_t *it, int pos); 00136 int xmmsv_list_iter_tell (const xmmsv_list_iter_t *it); 00137 xmmsv_t *xmmsv_list_iter_get_parent (const xmmsv_list_iter_t *it); 00138 00139 int xmmsv_list_iter_insert (xmmsv_list_iter_t *it, xmmsv_t *val); 00140 int xmmsv_list_iter_remove (xmmsv_list_iter_t *it); 00141 00142 int xmmsv_list_iter_entry_string (xmmsv_list_iter_t *it, const char **val); 00143 int xmmsv_list_iter_entry_int (xmmsv_list_iter_t *it, int32_t *val); 00144 int xmmsv_list_iter_entry_coll (xmmsv_list_iter_t *it, xmmsv_coll_t **val); 00145 00146 int xmmsv_list_iter_insert_string (xmmsv_list_iter_t *it, const char *val); 00147 int xmmsv_list_iter_insert_int (xmmsv_list_iter_t *it, int32_t val); 00148 int xmmsv_list_iter_insert_coll (xmmsv_list_iter_t *it, xmmsv_coll_t *val); 00149 00150 00151 /* Dict */ 00152 int xmmsv_dict_get (xmmsv_t *dictv, const char *key, xmmsv_t **val); 00153 int xmmsv_dict_set (xmmsv_t *dictv, const char *key, xmmsv_t *val); 00154 int xmmsv_dict_remove (xmmsv_t *dictv, const char *key); 00155 int xmmsv_dict_clear (xmmsv_t *dictv); 00156 int xmmsv_dict_foreach (xmmsv_t *dictv, xmmsv_dict_foreach_func func, void *user_data); 00157 int xmmsv_dict_get_size (xmmsv_t *dictv); 00158 int xmmsv_dict_has_key (xmmsv_t *dictv, const char *key); 00159 00160 int xmmsv_dict_entry_get_string (xmmsv_t *val, const char *key, const char **r); 00161 int xmmsv_dict_entry_get_int (xmmsv_t *val, const char *key, int32_t *r); 00162 int xmmsv_dict_entry_get_coll (xmmsv_t *val, const char *key, xmmsv_coll_t **coll); 00163 00164 int xmmsv_dict_set_string (xmmsv_t *val, const char *key, const char *el); 00165 int xmmsv_dict_set_int (xmmsv_t *val, const char *key, int32_t el); 00166 int xmmsv_dict_set_coll (xmmsv_t *val, const char *key, xmmsv_coll_t *el); 00167 00168 int xmmsv_dict_iter_pair (xmmsv_dict_iter_t *it, const char **key, xmmsv_t **val); 00169 int xmmsv_dict_iter_valid (xmmsv_dict_iter_t *it); 00170 void xmmsv_dict_iter_first (xmmsv_dict_iter_t *it); 00171 void xmmsv_dict_iter_next (xmmsv_dict_iter_t *it); 00172 int xmmsv_dict_iter_find (xmmsv_dict_iter_t *it, const char *key); 00173 00174 int xmmsv_dict_iter_set (xmmsv_dict_iter_t *it, xmmsv_t *val); 00175 int xmmsv_dict_iter_remove (xmmsv_dict_iter_t *it); 00176 00177 int xmmsv_dict_iter_pair_string (xmmsv_dict_iter_t *it, const char **key, const char **r); 00178 int xmmsv_dict_iter_pair_int (xmmsv_dict_iter_t *it, const char **key, int32_t *r); 00179 int xmmsv_dict_iter_pair_coll (xmmsv_dict_iter_t *it, const char **key, xmmsv_coll_t **r); 00180 00181 int xmmsv_dict_iter_set_string (xmmsv_dict_iter_t *it, const char *elem); 00182 int xmmsv_dict_iter_set_int (xmmsv_dict_iter_t *it, int32_t elem); 00183 int xmmsv_dict_iter_set_coll (xmmsv_dict_iter_t *it, xmmsv_coll_t *elem); 00184 00185 /* Utils */ 00186 00187 #define xmmsv_check_type(type) ((type) > XMMSV_TYPE_NONE && (type) < XMMSV_TYPE_END) 00188 00189 00190 xmmsv_t *xmmsv_decode_url (const xmmsv_t *url); 00191 int xmmsv_dict_format (char *target, int len, const char *fmt, xmmsv_t *val); 00192 00193 int xmmsv_utf8_validate (const char *str); 00194 00195 00196 /* These helps us doing compiletime typechecking */ 00197 static inline const char *__xmmsv_identity_const_charp (const char *v) {return v;} 00198 static inline xmmsv_t *__xmmsv_identity_xmmsv (xmmsv_t *v) {return v;} 00199 #define XMMSV_DICT_ENTRY(k, v) __xmmsv_identity_const_charp (k), __xmmsv_identity_xmmsv (v) 00200 #define XMMSV_DICT_ENTRY_STR(k, v) XMMSV_DICT_ENTRY (k, xmmsv_new_string (v)) 00201 #define XMMSV_DICT_ENTRY_INT(k, v) XMMSV_DICT_ENTRY (k, xmmsv_new_int (v)) 00202 #define XMMSV_DICT_END NULL 00203 xmmsv_t *xmmsv_build_dict (const char *firstkey, ...); 00204 00205 #define XMMSV_LIST_ENTRY(v) __xmmsv_identity_xmmsv (v) 00206 #define XMMSV_LIST_ENTRY_STR(v) XMMSV_LIST_ENTRY (xmmsv_new_string (v)) 00207 #define XMMSV_LIST_ENTRY_INT(v) XMMSV_LIST_ENTRY (xmmsv_new_int (v)) 00208 #define XMMSV_LIST_ENTRY_COLL(v) XMMSV_LIST_ENTRY (xmmsv_new_coll (v)) 00209 #define XMMSV_LIST_END NULL 00210 00211 xmmsv_t *xmmsv_build_list (xmmsv_t *first_entry, ...); 00212 xmmsv_t *xmmsv_build_list_va (xmmsv_t *first_entry, va_list ap); 00213 00214 #ifdef __cplusplus 00215 } 00216 #endif 00217 00218 #endif