su 1.12.10
|
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_INLINE_H 00026 00027 #define SU_TAG_INLINE_H 00028 00037 #ifndef SU_TAG_H 00038 #include <sofia-sip/su_tag.h> 00039 #endif 00040 #ifndef SU_TAG_CLASS_H 00041 #include <sofia-sip/su_tag_class.h> 00042 #endif 00043 00044 SOFIA_BEGIN_DECLS 00045 00046 #define tt_next tt_class->tc_next 00047 #define tt_len tt_class->tc_len 00048 #define tt_move tt_class->tc_move 00049 #define tt_xtra tt_class->tc_xtra 00050 #define tt_dup tt_class->tc_dup 00051 #define tt_free tt_class->tc_free 00052 #define tt_find tt_class->tc_find 00053 #define tt_snprintf tt_class->tc_snprintf 00054 #define tt_filter tt_class->tc_filter 00055 00056 #define TAG_TYPE_OF(t) ((t) && (t)->t_tag ? (t)->t_tag : tag_null) 00057 00059 su_inline int t_end(tagi_t const *t) 00060 { 00061 tag_type_t tt = TAG_TYPE_OF(t); 00062 00063 /* XXX - virtualize this */ 00064 00065 return tt == tag_null || tt == tag_next; 00066 } 00067 00068 su_inline tagi_t const *t_next(tagi_t const *t) 00069 { 00070 tag_type_t tt = TAG_TYPE_OF(t); 00071 00072 if (tt->tt_next) 00073 return tt->tt_next(t); 00074 else 00075 return t + 1; 00076 } 00077 00078 su_inline tagi_t *t_move(tagi_t *dst, tagi_t const *src) 00079 { 00080 tag_type_t tt = TAG_TYPE_OF(src); 00081 00082 if (tt->tt_move) 00083 return tt->tt_move(dst, src); 00084 00085 *dst = *src; 00086 return dst + 1; 00087 } 00088 00089 su_inline size_t t_xtra(tagi_t const *t, size_t offset) 00090 { 00091 tag_type_t tt = TAG_TYPE_OF(t); 00092 00093 if (tt->tt_xtra) 00094 return tt->tt_xtra(t, offset); 00095 00096 return 0; 00097 } 00098 00099 su_inline tagi_t *t_dup(tagi_t *dst, tagi_t const *src, void **bb) 00100 { 00101 tag_type_t tt = TAG_TYPE_OF(src); 00102 00103 if (tt->tt_dup) 00104 return tt->tt_dup(dst, src, bb); 00105 00106 *dst = *src; 00107 return dst + 1; 00108 } 00109 00110 su_inline tagi_t const *t_find(tag_type_t tt, tagi_t const *lst) 00111 { 00112 if (!tt) 00113 return NULL; 00114 00115 if (tt->tt_find) 00116 return tt->tt_find(tt, lst); 00117 00118 for (; lst; lst = t_next(lst)) { 00119 if (tt == lst->t_tag) 00120 return lst; 00121 } 00122 00123 return NULL; 00124 } 00125 00126 su_inline tagi_t *t_free(tagi_t *t) 00127 { 00128 tag_type_t tt = TAG_TYPE_OF(t); 00129 00130 if (tt->tt_free) 00131 return tt->tt_free(t); 00132 else if (tt->tt_next) 00133 return (tagi_t *)tt->tt_next(t); 00134 else 00135 return t + 1; 00136 } 00137 00138 su_inline size_t t_len(tagi_t const *t) 00139 { 00140 tag_type_t tt = TAG_TYPE_OF(t); 00141 00142 if (tt->tt_len) 00143 return tt->tt_len(t); 00144 00145 return sizeof(*t); 00146 } 00147 00148 SOFIA_END_DECLS 00149 00150 #endif /* !defined(SU_TAG_INLINE_H) */