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 
00080 typedef struct {
00081   tagi_t  tl[2];
00082   va_list ap;
00083 } ta_list;
00084 
00097 #if SU_HAVE_TAGSTACK
00098 /* All arguments are saved into stack (left-to-right) */
00099 #define ta_start(ta, t, v)                                              \
00100    do {                                                                 \
00101     tag_type_t ta_start__tag = (t); tag_value_t ta_start__value = (v);  \
00102     va_start((ta).ap, (v));                                             \
00103     while ((ta_start__tag) == tag_next && (ta_start__value) != 0) {     \
00104       ta_start__tag = ((tagi_t *)ta_start__value)->t_tag;               \
00105       if (ta_start__tag == tag_null || ta_start__tag == NULL)           \
00106         break;                                                          \
00107       if (ta_start__tag == tag_next) {                                  \
00108         ta_start__value = ((tagi_t *)ta_start__value)->t_value; }       \
00109       else {                                                            \
00110         ta_start__tag = tag_next;                                       \
00111         break;                                                          \
00112       }                                                                 \
00113     }                                                                   \
00114     (ta).tl->t_tag = ta_start__tag; (ta).tl->t_value = ta_start__value; \
00115     if (ta_start__tag != NULL &&                                        \
00116         ta_start__tag != tag_null &&                                    \
00117         ta_start__tag != tag_next) {                                    \
00118       (ta).tl[1].t_tag = tag_next;                                      \
00119       (ta).tl[1].t_value = (tag_value_t)(&(v) + 1);                     \
00120     } else {                                                            \
00121       (ta).tl[1].t_tag = 0; (ta).tl[1].t_value = (tag_value_t)0;        \
00122     }                                                                   \
00123   } while(0)
00124 #else
00125 /* Tagged arguments are in registers - copy all of them. */
00126 #define ta_start(ta, t, v)                                              \
00127    do {                                                                 \
00128     tag_type_t ta_start__tag = (t); tag_value_t ta_start__value = (v);  \
00129     va_start((ta).ap, (v));                                             \
00130     while ((ta_start__tag) == tag_next && (ta_start__value) != 0) {     \
00131       ta_start__tag = ((tagi_t *)ta_start__value)->t_tag;               \
00132       if (ta_start__tag == tag_null || ta_start__tag == NULL)           \
00133         break;                                                          \
00134       if (ta_start__tag == tag_next) {                                  \
00135         ta_start__value = ((tagi_t *)ta_start__value)->t_value;         \
00136       } else {                                                          \
00137         ta_start__tag = tag_next;                                       \
00138         break;                                                          \
00139       }                                                                 \
00140     }                                                                   \
00141     (ta).tl->t_tag = ta_start__tag; (ta).tl->t_value = ta_start__value; \
00142     if (ta_start__tag != NULL &&                                        \
00143         ta_start__tag != tag_null &&                                    \
00144         ta_start__tag != tag_next) {                                    \
00145       va_list ta_start__ap;                                             \
00146       va_copy(ta_start__ap, (ta).ap);                                   \
00147       (ta).tl[1].t_tag = tag_next;                                      \
00148       (ta).tl[1].t_value = (tag_value_t)tl_vlist(ta_start__ap);         \
00149       va_end(ta_start__ap);                                             \
00150     } else {                                                            \
00151       (ta).tl[1].t_value = 0; (ta).tl[1].t_value = (tag_value_t)0;      \
00152     }                                                                   \
00153   } while(0)
00154 #endif
00155 
00162 #define ta_args(ta) (ta).tl
00163 
00171 #define ta_tags(ta) \
00172   (ta).tl[0].t_tag, (ta).tl[0].t_value, (ta).tl[1].t_tag, (ta).tl[1].t_value
00173 
00183 #if SU_HAVE_TAGSTACK
00184 #define ta_end(ta) (va_end((ta).ap), (ta).tl->t_tag = NULL, 0)
00185 #else
00186 #define ta_end(ta)                                         \
00187   ((((ta).tl[1].t_value) ?                                 \
00188     (tl_vfree((tagi_t *)((ta).tl[1].t_value))) : (void)0), \
00189    (ta).tl[1].t_value = 0, va_end((ta).ap), 0)
00190 #endif
00191 
00192 SOFIA_END_DECLS
00193 
00194 #endif /* !defined(SU_TAGARG_H) */

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