su_tag_inline.h 3.26 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

Pekka Pessi's avatar
Pekka Pessi committed
25 26
#ifndef SU_TAG_INLINE_H
/** Defined when <sofia-sip/su_tag_inline.h> has been included */
27
#define SU_TAG_INLINE_H
Pekka Pessi's avatar
Pekka Pessi committed
28
/**@SU_TAG
Pekka Pessi's avatar
Pekka Pessi committed
29 30
 * @file sofia-sip/su_tag_inline.h
 * Inline functions for object tags and tag lists.
Pekka Pessi's avatar
Pekka Pessi committed
31 32
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
33
 *
Pekka Pessi's avatar
Pekka Pessi committed
34 35 36
 * @date Created: Tue Feb 20 19:48:18 2001 ppessi
 */

37
#ifndef SU_TAG_H
38
#include <sofia-sip/su_tag.h>
39 40
#endif
#ifndef SU_TAG_CLASS_H
41
#include <sofia-sip/su_tag_class.h>
42 43 44 45
#endif

SOFIA_BEGIN_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
46 47 48 49 50 51 52 53 54 55 56 57 58
#define tt_next     tt_class->tc_next
#define tt_len      tt_class->tc_len
#define tt_move     tt_class->tc_move
#define tt_xtra     tt_class->tc_xtra
#define tt_dup      tt_class->tc_dup
#define tt_free     tt_class->tc_free
#define tt_find     tt_class->tc_find
#define tt_snprintf tt_class->tc_snprintf
#define tt_filter   tt_class->tc_filter

#define TAG_TYPE_OF(t) ((t) && (t)->t_tag ? (t)->t_tag : tag_null)

/** Check if the tag item is last in current list */
59
su_inline int t_end(tagi_t const *t)
Pekka Pessi's avatar
Pekka Pessi committed
60 61 62
{
  tag_type_t tt = TAG_TYPE_OF(t);

Pekka Pessi's avatar
Pekka Pessi committed
63
  /* XXX - virtualize this */
Pekka Pessi's avatar
Pekka Pessi committed
64 65 66 67

  return tt == tag_null || tt == tag_next;
}

68
su_inline tagi_t const *t_next(tagi_t const *t)
Pekka Pessi's avatar
Pekka Pessi committed
69 70 71
{
  tag_type_t tt = TAG_TYPE_OF(t);

72
  if (tt->tt_next)
Pekka Pessi's avatar
Pekka Pessi committed
73 74 75 76 77
    return tt->tt_next(t);
  else
    return t + 1;
}

78
su_inline tagi_t *t_move(tagi_t *dst, tagi_t const *src)
Pekka Pessi's avatar
Pekka Pessi committed
79 80 81
{
  tag_type_t tt = TAG_TYPE_OF(src);

82
  if (tt->tt_move)
Pekka Pessi's avatar
Pekka Pessi committed
83 84 85 86 87 88
    return tt->tt_move(dst, src);

  *dst = *src;
  return dst + 1;
}

89
su_inline size_t t_xtra(tagi_t const *t, size_t offset)
Pekka Pessi's avatar
Pekka Pessi committed
90 91 92
{
  tag_type_t tt = TAG_TYPE_OF(t);

93
  if (tt->tt_xtra)
Pekka Pessi's avatar
Pekka Pessi committed
94 95 96 97 98
    return tt->tt_xtra(t, offset);

  return 0;
}

99
su_inline tagi_t *t_dup(tagi_t *dst, tagi_t const *src, void **bb)
Pekka Pessi's avatar
Pekka Pessi committed
100 101 102
{
  tag_type_t tt = TAG_TYPE_OF(src);

103
  if (tt->tt_dup)
Pekka Pessi's avatar
Pekka Pessi committed
104 105 106 107 108 109
    return tt->tt_dup(dst, src, bb);

  *dst = *src;
  return dst + 1;
}

110
su_inline tagi_t const *t_find(tag_type_t tt, tagi_t const *lst)
Pekka Pessi's avatar
Pekka Pessi committed
111 112 113 114
{
  if (!tt)
    return NULL;

115
  if (tt->tt_find)
Pekka Pessi's avatar
Pekka Pessi committed
116 117 118 119 120 121 122 123 124 125
    return tt->tt_find(tt, lst);

  for (; lst; lst = t_next(lst)) {
    if (tt == lst->t_tag)
      return lst;
  }

  return NULL;
}

126
su_inline tagi_t *t_free(tagi_t *t)
Pekka Pessi's avatar
Pekka Pessi committed
127 128 129
{
  tag_type_t tt = TAG_TYPE_OF(t);

130
  if (tt->tt_free)
Pekka Pessi's avatar
Pekka Pessi committed
131 132 133 134 135 136 137
    return tt->tt_free(t);
  else if (tt->tt_next)
    return (tagi_t *)tt->tt_next(t);
  else
    return t + 1;
}

138
su_inline size_t t_len(tagi_t const *t)
Pekka Pessi's avatar
Pekka Pessi committed
139 140 141
{
  tag_type_t tt = TAG_TYPE_OF(t);

142
  if (tt->tt_len)
Pekka Pessi's avatar
Pekka Pessi committed
143 144 145 146 147
    return tt->tt_len(t);

  return sizeof(*t);
}

148 149
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
150
#endif /* !defined(SU_TAG_INLINE_H) */