00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SU_TAG_H
00026
00027 #define SU_TAG_H
00028
00037 #ifndef SU_CONFIG_H
00038 #include <sofia-sip/su_config.h>
00039 #endif
00040
00041 #ifndef SU_TYPES_H
00042 #include <sofia-sip/su_types.h>
00043 #endif
00044
00045 #ifndef SU_ALLOC_H
00046 #include <sofia-sip/su_alloc.h>
00047 #endif
00048
00049 #include <stdarg.h>
00050 #include <stddef.h>
00051
00052 SOFIA_BEGIN_DECLS
00053
00055 typedef struct tag_type_s const *tag_type_t;
00057 typedef intptr_t tag_value_t;
00058
00060 #define TAG_LIST tag_type_t tag, tag_value_t value, ...
00061
00063 typedef struct {
00064 tag_type_t t_tag;
00065 tag_value_t t_value;
00066 } tagi_t;
00067
00069 typedef struct tag_class_s const tag_class_t;
00070
00076 struct tag_type_s {
00077 char const *tt_ns;
00078 char const *tt_name;
00079 tag_class_t *tt_class;
00080 tag_value_t tt_magic;
00082 };
00083
00085 typedef struct tag_type_s const tag_typedef_t[1];
00086
00088 SOFIAPUBVAR tag_typedef_t tag_null;
00089
00091 SOFIAPUBVAR tag_typedef_t tag_skip;
00092
00094 SOFIAPUBVAR tag_typedef_t tag_next;
00095
00097 SOFIAPUBVAR tag_typedef_t tag_any;
00098
00102 SOFIAPUBVAR tag_typedef_t tag_filter;
00103
00107 typedef int tag_filter_f(tagi_t const *filter, tagi_t const *dest);
00108
00110 #define TAG_NULL() (tag_type_t)0, (tag_value_t)0
00111
00113 #define TAG_END() (tag_type_t)0, (tag_value_t)0
00114
00116 #define TAG_SKIP(x) tag_skip, (tag_value_t)(x)
00117
00119 #define TAG_NEXT(next) tag_next, (tag_value_t)(next)
00120
00122 #define TAG_ANY() tag_any, (tag_value_t)0
00123
00126 #define TAG_IF(condition, item) !(condition) ? tag_skip : item
00127
00131 #define TAG_FILTER(function) tag_filter, tag_filter_v(function)
00132
00134 SOFIAPUBFUN int t_snprintf(tagi_t const *t, char b[], size_t size);
00135
00137 SOFIAPUBFUN int t_scan(tag_type_t tt, su_home_t *home, char const *s,
00138 tag_value_t *return_value);
00139
00140
00141 SOFIAPUBFUN tagi_t *tl_tlist(su_home_t *, tag_type_t, tag_value_t, ...);
00142 SOFIAPUBFUN size_t tl_tmove(tagi_t *dst, size_t, tag_type_t, tag_value_t, ...);
00143 SOFIAPUBFUN int tl_gets(tagi_t const lst[], tag_type_t, tag_value_t, ...);
00144 SOFIAPUBFUN int tl_tgets(tagi_t lst[], tag_type_t, tag_value_t, ...);
00145 SOFIAPUBFUN tagi_t *tl_tfilter(su_home_t *, tagi_t const lst[],
00146 tag_type_t, tag_value_t, ...);
00147 SOFIAPUBFUN int tl_tremove(tagi_t lst[], tag_type_t, tag_value_t, ...);
00148
00149
00150 SOFIAPUBFUN size_t tl_len(tagi_t const lst[]);
00151 SOFIAPUBFUN size_t tl_vllen(tag_type_t tag, tag_value_t value, va_list ap);
00152 SOFIAPUBFUN size_t tl_xtra(tagi_t const lst[], size_t offset);
00153 SOFIAPUBFUN tagi_t *tl_next(tagi_t const *lst);
00154 SOFIAPUBFUN tagi_t *tl_move(tagi_t *dst, tagi_t const src[]);
00155 SOFIAPUBFUN tagi_t *tl_dup(tagi_t dst[], tagi_t const lst[], void **bb);
00156 SOFIAPUBFUN tagi_t *tl_adup(su_home_t *, tagi_t const lst[]);
00157 SOFIAPUBFUN void tl_free(tagi_t list[]);
00158
00159 SOFIAPUBFUN tagi_t *tl_find(tagi_t const lst[], tag_type_t tt);
00160 SOFIAPUBFUN tagi_t *tl_find_last(tagi_t const lst[], tag_type_t tt);
00161 SOFIAPUBFUN tagi_t *tl_filter(tagi_t *, tagi_t const filter[],
00162 tagi_t const lst[], void **b);
00163 SOFIAPUBFUN tagi_t *tl_afilter(su_home_t *, tagi_t const filter[],
00164 tagi_t const lst[]);
00165
00166 SOFIAPUBFUN tagi_t *tl_filtered_tlist(su_home_t *home, tagi_t const filter[],
00167 tag_type_t, tag_value_t, ...);
00168
00169 SOFIAPUBFUN size_t tl_vlen(va_list ap);
00170 SOFIAPUBFUN tagi_t *tl_list(tag_type_t tag, tag_value_t value, ...);
00171 SOFIAPUBFUN tagi_t *tl_vlist2(tag_type_t tag, tag_value_t value, va_list ap);
00172 SOFIAPUBFUN tagi_t *tl_vlist(va_list ap);
00173 SOFIAPUBFUN tagi_t *tl_llist(tag_type_t tag, tag_value_t value, ...);
00174 SOFIAPUBFUN tagi_t *tl_vllist(tag_type_t tag, tag_value_t value, va_list ap);
00175 SOFIAPUBFUN void tl_vfree(tagi_t *t);
00176
00178 #define SU_ALIGN(x) \
00179 ((sizeof(void *) - ((intptr_t)(x) & (sizeof(void *) - 1))) & (sizeof(void *) - 1))
00180
00181 #if SU_INLINE_TAG_CAST
00182 su_inline tag_value_t tag_int_v(int v) { return (tag_value_t)v; }
00183 su_inline tag_value_t tag_int_vr(int *vp) { return (tag_value_t)vp; }
00184 su_inline tag_value_t tag_uint_v(unsigned v) { return (tag_value_t)v; }
00185 su_inline tag_value_t tag_uint_vr(unsigned *vp) { return (tag_value_t)vp; }
00186 su_inline tag_value_t tag_usize_v(usize_t v) { return (tag_value_t)v; }
00187 su_inline tag_value_t tag_usize_vr(usize_t *vp) { return (tag_value_t)vp; }
00188 su_inline tag_value_t tag_size_v(size_t v) { return (tag_value_t)v; }
00189 su_inline tag_value_t tag_size_vr(size_t *vp) { return (tag_value_t)vp; }
00190 su_inline tag_value_t tag_bool_v(int v) { return v != 0; }
00191 su_inline tag_value_t tag_bool_vr(int *vp) { return (tag_value_t)vp; }
00192 su_inline tag_value_t tag_ptr_v(void *v) { return (tag_value_t)v; }
00193 su_inline tag_value_t tag_ptr_vr(void *vp, void *v)
00194 { (void)v; return(tag_value_t)vp; }
00195 su_inline tag_value_t tag_cptr_v(void const *v) { return (tag_value_t)v; }
00196 su_inline tag_value_t tag_cptr_vr(void *vp, void const *v)
00197 { (void)v; return(tag_value_t)vp; }
00198 su_inline tag_value_t tag_cstr_v(char const *v) { return (tag_value_t)v; }
00199 su_inline tag_value_t tag_cstr_vr(char const**vp) {return(tag_value_t)vp;}
00200 su_inline tag_value_t tag_str_v(char const *v) { return (tag_value_t)v; }
00201 su_inline tag_value_t tag_str_vr(char const **vp) {return(tag_value_t)vp;}
00202 #if __cplusplus
00203 extern "C++" {
00204 su_inline tag_value_t tag_ptr_v(void const *v)
00205 { return (tag_value_t)v; }
00206 su_inline tag_value_t tag_ptr_vr(void *vp, void const *p)
00207 { return (tag_value_t)vp; }
00208 su_inline tag_value_t tag_str_v(char *v) { return (tag_value_t)v; }
00209 su_inline tag_value_t tag_str_vr(char **vp) {return (tag_value_t)vp;}
00210 }
00211 #endif
00212 su_inline tag_value_t tag_filter_v(tag_filter_f *v) {return(tag_value_t)v;}
00213 #else
00214 #define tag_int_v(v) (tag_value_t)(v)
00215 #define tag_int_vr(v) (tag_value_t)(v)
00216 #define tag_uint_v(v) (tag_value_t)(v)
00217 #define tag_uint_vr(v) (tag_value_t)(v)
00218 #define tag_usize_v(v) (tag_value_t)(v)
00219 #define tag_usize_vr(v) (tag_value_t)(v)
00220 #define tag_size_v(v) (tag_value_t)(v)
00221 #define tag_size_vr(v) (tag_value_t)(v)
00222 #define tag_bool_v(v) (tag_value_t)(v != 0)
00223 #define tag_bool_vr(v) (tag_value_t)(v)
00224 #define tag_ptr_v(v) (tag_value_t)(v)
00225 #define tag_ptr_vr(v,x) (tag_value_t)(v)
00226 #define tag_cptr_v(v) (tag_value_t)(v)
00227 #define tag_cptr_vr(v,x) (tag_value_t)(v)
00228 #define tag_cstr_v(v) (tag_value_t)(v)
00229 #define tag_cstr_vr(v) (tag_value_t)(v)
00230 #define tag_str_v(v) (tag_value_t)(v)
00231 #define tag_str_vr(v) (tag_value_t)(v)
00232 #define tag_filter_v(v) (tag_value_t)(v)
00233 #endif
00234
00235 SOFIA_END_DECLS
00236
00237 #endif