sofia-sip/su_tag.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
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> /* ANSI C: size_t */
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 
00071 struct tag_type_s {
00072   char const    *tt_ns;
00073   char const    *tt_name;
00074   tag_class_t   *tt_class;
00075   tag_value_t    tt_magic;
00076 };
00077 
00079 typedef struct tag_type_s const tag_typedef_t[1];
00080 
00082 SOFIAPUBVAR tag_typedef_t tag_null;
00083 
00085 SOFIAPUBVAR tag_typedef_t tag_skip;
00086 
00088 SOFIAPUBVAR tag_typedef_t tag_next;
00089 
00091 SOFIAPUBVAR tag_typedef_t tag_any;
00092 
00094 #define TAG_NULL()  (tag_type_t)0, (tag_value_t)0
00095 
00097 #define TAG_END()   (tag_type_t)0, (tag_value_t)0
00098 
00100 #define TAG_SKIP(x)    tag_skip, (tag_value_t)(x)
00101 
00103 #define TAG_NEXT(next) tag_next, (tag_value_t)(next)
00104 
00106 #define TAG_ANY()   tag_any,  (tag_value_t)0
00107 
00110 #define TAG_IF(condition, item) !(condition) ? tag_skip : item
00111 
00113 SOFIAPUBFUN int t_snprintf(tagi_t const *t, char b[], size_t size);
00114 
00116 SOFIAPUBFUN int t_scan(tag_type_t tt, su_home_t *home, char const *s, 
00117                        tag_value_t *return_value);
00118 
00119 /* Tagarg functions */
00120 SOFIAPUBFUN tagi_t *tl_tlist(su_home_t *, tag_type_t, tag_value_t, ...);
00121 SOFIAPUBFUN size_t tl_tmove(tagi_t *dst, size_t, tag_type_t, tag_value_t, ...);
00122 SOFIAPUBFUN int tl_gets(tagi_t const lst[], tag_type_t, tag_value_t, ...);
00123 SOFIAPUBFUN int tl_tgets(tagi_t lst[], tag_type_t, tag_value_t, ...);
00124 SOFIAPUBFUN tagi_t *tl_tfilter(su_home_t *, tagi_t const lst[], 
00125                                tag_type_t, tag_value_t, ...);
00126 SOFIAPUBFUN int tl_tremove(tagi_t lst[], tag_type_t, tag_value_t, ...);
00127 
00128 /* Low-level taglist manipulation functions */
00129 SOFIAPUBFUN size_t tl_len(tagi_t const lst[]);
00130 SOFIAPUBFUN size_t tl_xtra(tagi_t const lst[], size_t offset);
00131 SOFIAPUBFUN tagi_t *tl_next(tagi_t const *lst);
00132 SOFIAPUBFUN tagi_t *tl_move(tagi_t *dst, tagi_t const src[]);
00133 SOFIAPUBFUN tagi_t *tl_dup(tagi_t dst[], tagi_t const lst[], void **bb);
00134 SOFIAPUBFUN tagi_t *tl_adup(su_home_t *, tagi_t const lst[]);
00135 
00136 SOFIAPUBFUN tagi_t const *tl_find(tagi_t const lst[], tag_type_t tt);
00137 SOFIAPUBFUN tagi_t *tl_filter(tagi_t *, tagi_t const filter[],
00138                               tagi_t const lst[], void **b);
00139 SOFIAPUBFUN tagi_t *tl_afilter(su_home_t *, tagi_t const filter[],
00140                                tagi_t const lst[]);
00141 
00142 SOFIAPUBFUN tagi_t *tl_filtered_tlist(su_home_t *home, tagi_t const filter[], 
00143                                       tag_type_t, tag_value_t, ...);
00144 
00145 SOFIAPUBFUN size_t  tl_vlen(va_list ap);
00146 SOFIAPUBFUN tagi_t *tl_list(tag_type_t tag, tag_value_t value, ...);
00147 SOFIAPUBFUN tagi_t *tl_vlist2(tag_type_t tag, tag_value_t value, va_list ap);
00148 SOFIAPUBFUN tagi_t *tl_vlist(va_list ap);
00149 SOFIAPUBFUN tagi_t *tl_llist(tag_type_t tag, tag_value_t value, ...);
00150 SOFIAPUBFUN tagi_t *tl_vllist(tag_type_t tag, tag_value_t value, va_list ap);
00151 SOFIAPUBFUN void    tl_vfree(tagi_t *t);
00152 
00154 #define SU_ALIGN(x) \
00155 ((sizeof(void *) - ((intptr_t)(x) & (sizeof(void *) - 1))) & (sizeof(void *) - 1))
00156 
00157 #if SU_HAVE_INLINE
00158 su_inline tag_value_t tag_int_v(int v) { return (tag_value_t)v; }
00159 su_inline tag_value_t tag_int_vr(int *vp) { return (tag_value_t)vp; }
00160 su_inline tag_value_t tag_uint_v(unsigned v) { return (tag_value_t)v; }
00161 su_inline tag_value_t tag_uint_vr(unsigned *vp) { return (tag_value_t)vp; }
00162 su_inline tag_value_t tag_bool_v(int v) { return v != 0; }
00163 su_inline tag_value_t tag_bool_vr(int *vp) { return (tag_value_t)vp; }
00164 su_inline tag_value_t tag_ptr_v(void *v) { return (tag_value_t)v; }
00165 su_inline tag_value_t tag_ptr_vr(void *vp,
00166                                  void *v) {return(tag_value_t)vp;}
00167 su_inline tag_value_t tag_cptr_v(void const *v) { return (tag_value_t)v; }
00168 su_inline tag_value_t tag_cptr_vr(void *vp,
00169                                   void const *v) {return(tag_value_t)vp;}
00170 su_inline tag_value_t tag_cstr_v(char const *v) { return (tag_value_t)v; }
00171 su_inline tag_value_t tag_cstr_vr(char const**vp) {return(tag_value_t)vp;}
00172 su_inline tag_value_t tag_str_v(char const *v) { return (tag_value_t)v; }
00173 su_inline tag_value_t tag_str_vr(char const **vp) {return(tag_value_t)vp;}
00174 #if __cplusplus
00175 extern "C++" {
00176   static inline tag_value_t tag_ptr_v(void const *v)
00177   { return (tag_value_t)v; }
00178   static inline tag_value_t tag_ptr_vr(void *vp, void const *p) 
00179   { return(tag_value_t)vp; }
00180   static inline tag_value_t tag_str_v(char *v) { return (tag_value_t)v; }
00181   static inline tag_value_t tag_str_vr(char **vp) {return(tag_value_t)vp;}
00182 }
00183 #endif
00184 #else
00185 #define tag_int_v(v)   (tag_value_t)(v)
00186 #define tag_int_vr(v)  (tag_value_t)(v)
00187 #define tag_uint_v(v)  (tag_value_t)(v)
00188 #define tag_uint_vr(v) (tag_value_t)(v)
00189 #define tag_bool_v(v)  (tag_value_t)(v != 0)
00190 #define tag_bool_vr(v) (tag_value_t)(v)
00191 #define tag_ptr_v(v)   (tag_value_t)(v)
00192 #define tag_ptr_vr(v,x) (tag_value_t)(v)
00193 #define tag_cstr_v(v)  (tag_value_t)(v)
00194 #define tag_cstr_vr(v) (tag_value_t)(v)
00195 #define tag_str_v(v)   (tag_value_t)(v)
00196 #define tag_str_vr(v)  (tag_value_t)(v)
00197 #endif
00198 
00199 SOFIA_END_DECLS
00200 
00201 #endif 

Sofia-SIP 1.12.1 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.