sofia-sip/su_tagarg.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_TAGARG_H
00026 
00027 #define SU_TAGARG_H
00028 
00037 #ifndef SU_TAG_H
00038 #include <sofia-sip/su_tag.h>
00039 #endif
00040 
00041 SOFIA_BEGIN_DECLS
00042 
00079 typedef struct {
00080   tagi_t  tl[2];
00081   va_list ap;
00082 } ta_list;
00083 
00096 #if SU_HAVE_TAGSTACK
00097 /* All arguments are saved into stack (left-to-right) */
00098 #define ta_start(ta, t, v)                                              \
00099    do {                                                                 \
00100     tag_type_t ta_start__tag = (t); tag_value_t ta_start__value = (v);  \
00101     va_start((ta).ap, (v));                                             \
00102     while ((ta_start__tag) == tag_next && (ta_start__value) != 0) {     \
00103       ta_start__tag = ((tagi_t *)ta_start__value)->t_tag;               \
00104       if (ta_start__tag == tag_null || ta_start__tag == NULL)           \
00105         break;                                                          \
00106       if (ta_start__tag == tag_next) {                                  \
00107         ta_start__value = ((tagi_t *)ta_start__value)->t_value; }       \
00108       else {                                                            \
00109         ta_start__tag = tag_next;                                       \
00110         break;                                                          \
00111       }                                                                 \
00112     }                                                                   \
00113     (ta).tl->t_tag = ta_start__tag; (ta).tl->t_value = ta_start__value; \
00114     if (ta_start__tag != NULL &&                                        \
00115         ta_start__tag != tag_null &&                                    \
00116         ta_start__tag != tag_next) {                                    \
00117       (ta).tl[1].t_tag = tag_next;                                      \
00118       (ta).tl[1].t_value = (tag_value_t)(&(v) + 1);                     \
00119     } else {                                                            \
00120       (ta).tl[1].t_tag = 0; (ta).tl[1].t_value = (tag_value_t)0;        \
00121     }                                                                   \
00122   } while(0)
00123 #else
00124 /* Tagged arguments are in registers - copy all of them. */
00125 #define ta_start(ta, t, v)                                              \
00126    do {                                                                 \
00127     tag_type_t ta_start__tag = (t); tag_value_t ta_start__value = (v);  \
00128     va_start((ta).ap, (v));                                             \
00129     while ((ta_start__tag) == tag_next && (ta_start__value) != 0) {     \
00130       ta_start__tag = ((tagi_t *)ta_start__value)->t_tag;               \
00131       if (ta_start__tag == tag_null || ta_start__tag == NULL)           \
00132         break;                                                          \
00133       if (ta_start__tag == tag_next) {                                  \
00134         ta_start__value = ((tagi_t *)ta_start__value)->t_value;         \
00135       } else {                                                          \
00136         ta_start__tag = tag_next;                                       \
00137         break;                                                          \
00138       }                                                                 \
00139     }                                                                   \
00140     (ta).tl->t_tag = ta_start__tag; (ta).tl->t_value = ta_start__value; \
00141     if (ta_start__tag != NULL &&                                        \
00142         ta_start__tag != tag_null &&                                    \
00143         ta_start__tag != tag_next) {                                    \
00144       (ta).tl[1].t_tag = tag_next;                                      \
00145       (ta).tl[1].t_value = (tag_value_t)tl_vlist((ta).ap);              \
00146     } else {                                                            \
00147       (ta).tl[1].t_value = 0; (ta).tl[1].t_value = (tag_value_t)0;      \
00148     }                                                                   \
00149   } while(0)
00150 #endif
00151 
00158 #define ta_args(ta) (ta).tl
00159 
00167 #define ta_tags(ta) \
00168   (ta).tl[0].t_tag, (ta).tl[0].t_value, (ta).tl[1].t_tag, (ta).tl[1].t_value
00169 
00179 #if SU_HAVE_TAGSTACK
00180 #define ta_end(ta) (va_end((ta).ap), (ta).tl->t_tag = NULL, 0)
00181 #else
00182 #define ta_end(ta)                                         \
00183   ((((ta).tl[1].t_value) ?                                 \
00184     (tl_vfree((tagi_t *)((ta).tl[1].t_value))) : (void)0), \
00185    (ta).tl[1].t_value = 0, va_end((ta).ap), 0)
00186 #endif
00187 
00188 SOFIA_END_DECLS
00189 
00190 #endif /* !defined(SU_TAGARG_H) */

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