test_protos.h.in 10.1 KB
Newer Older
1 2 3 4 5 6 7
/**-*- c -*- 
 * @ingroup msg
 * @internal @file test_protos.h.in
 *
 * Template for "test_protos.h".
 */

Pekka Pessi's avatar
Pekka Pessi committed
8 9 10 11 12 13 14
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
15
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 * 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
 *
 */

32 33
#ifndef TEST_PROTOS_H
/** Defined when <test_protos.h> has been included. */
34
#define TEST_PROTOS_H 
35

36 37
/**@ingroup test_msg
 * @file test_protos.h
Pekka Pessi's avatar
Pekka Pessi committed
38 39 40 41 42 43 44 45
 *
 * Prototypes and macros for dummy testing protocol headers.
 * 
 * #AUTO#
 * 
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 */

46 47 48
#include <sofia-sip/su_config.h>
#include <sofia-sip/su_tag.h>
#include <sofia-sip/su_tag_class.h>
Pekka Pessi's avatar
Pekka Pessi committed
49 50

#ifndef MSG_HEADER_H
51
#include <sofia-sip/msg_header.h>
Pekka Pessi's avatar
Pekka Pessi committed
52 53 54
#endif

#ifndef MSG_MIME_PROTOS_H
55
#include <sofia-sip/msg_mime_protos.h>
Pekka Pessi's avatar
Pekka Pessi committed
56 57
#endif

58 59 60 61 62 63
#ifndef TEST_CLASS_H
#include <test_class.h>
#endif

SOFIA_BEGIN_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
/** Test if tag type marks a msg_test_t structure. @HIDE */
#define TSTTAG_P(tt)     ((tt)->tt_class == tsthdrtag_class)
/** Test if tag type marks a TST header string. @HIDE */
#define TSTTAG_STR_P(tt) ((tt)->tt_class == tststrtag_class)
/** Test if tag type marks a TST header structure. @HIDE */
#define TSTTAG_TST_P(tt) ((tt)->tt_class == tstmsgtag_class)

/** Test if tag item contains msg_test_t structure. @HIDE */
#define TSTTAGI_P(t)     (TSTTAG_P((t)->t_tag))
/** Test if tag item contains a TST header string. @HIDE */
#define TSTTAGI_STR_P(t) (TSTTAG_STR_P((t)->t_tag))
/** Test if tag item contains a TST header structure. @HIDE */
#define TSTTAGI_TST_P(t) (TSTTAG_TST_P((t)->t_tag))

/** Tag class for TST headers */
Pekka Pessi's avatar
Pekka Pessi committed
79
extern tag_class_t tsthdrtag_class[1];
Pekka Pessi's avatar
Pekka Pessi committed
80
/** Tag class for string values of TST headers */
Pekka Pessi's avatar
Pekka Pessi committed
81
extern tag_class_t tststrtag_class[1];
Pekka Pessi's avatar
Pekka Pessi committed
82
/** Tag class for TST message */
Pekka Pessi's avatar
Pekka Pessi committed
83
extern tag_class_t tstmsgtag_class[1];
Pekka Pessi's avatar
Pekka Pessi committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

/**Tag list item for header string.
 *
 * The TSTTAG_HEADER_STR() macro is used to include a tag item containing a
 * header string in the tag list, e.g., 
 * @code 
 * TSTTAG_HEADER_STR("Priority: urgent").
 * @endcode
 *
 * @param x pointer to a string, or NULL.
 *
 * @HIDE
 */
#define TSTTAG_HEADER(x)       tsttag_header, tsttag_header_v((x))

/** Tag for header string */
Pekka Pessi's avatar
Pekka Pessi committed
100
extern tag_typedef_t tsttag_header;
Pekka Pessi's avatar
Pekka Pessi committed
101 102

#define TSTTAG_HEADER_REF(x)   tsttag_header_ref, tsttag_header_vr(&(x))
Pekka Pessi's avatar
Pekka Pessi committed
103
extern tag_typedef_t tsttag_header_ref;
Pekka Pessi's avatar
Pekka Pessi committed
104 105

#if HAVE_INLINE
106
su_inline tag_value_t
Pekka Pessi's avatar
Pekka Pessi committed
107 108
tsttag_header_v(msg_header_t const *v)
{ return (tag_value_t)v; }
109
su_inline tag_value_t
Pekka Pessi's avatar
Pekka Pessi committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
tsttag_header_vr(msg_header_t const **vp)
{ return (tag_value_t)vp; }
#else
#define tsttag_header_v(v)   (tag_value_t)(v)
#define tsttag_header_vr(vp) (tag_value_t)(vp)
#endif

/**Tag list item for header string.
 *
 * The TSTTAG_HEADER_STR() macro is used to include a tag item containing a
 * header string in the tag list.
 *
 * @param x pointer to a string, or NULL.
 *
 * @HIDE
 */
#define TSTTAG_HEADER_STR(x)       tsttag_header_str, tag_str_v((x))

/** Tag for header string */
Pekka Pessi's avatar
Pekka Pessi committed
129
extern tag_typedef_t tsttag_header_str;
Pekka Pessi's avatar
Pekka Pessi committed
130 131

#define TSTTAG_HEADER_STR_REF(x)   tsttag_header_str_ref, tag_str_vr(&(x))
Pekka Pessi's avatar
Pekka Pessi committed
132
extern tag_typedef_t tsttag_header_str_ref;
Pekka Pessi's avatar
Pekka Pessi committed
133 134

#if HAVE_INLINE
135
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
136
tag_value_t tsttag_tst_v(msg_test_t const *v) { return (tag_value_t)v; }
137
su_inline 
Pekka Pessi's avatar
Pekka Pessi committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
tag_value_t tsttag_tst_vr(msg_test_t const **vp) { return (tag_value_t)vp; }
#else
#define tsttag_tst_v(v)   (tag_value_t)(v)
#define tsttag_tst_vr(vp) (tag_value_t)(vp)
#endif



/**@addtogroup test_msg_#xxxxxx#*//**@{*/

/** Parse a #xxxxxxx_xxxxxxx#. @internal */
msg_parse_f msg_#xxxxxx#_d;

/** Print a #xxxxxxx_xxxxxxx#. @internal */
msg_print_f msg_#xxxxxx#_e;


/**Header class for #xxxxxxx_xxxxxxx#.
 * 
 * The header class msg_#xxxxxx#_class defines how a 
 * #xxxxxxx_xxxxxxx# is parsed and printed.  It also
 * contains methods used by message parser and other functions
 * to manipulate the msg_#xxxxxx#_t header structure.
 */
extern msg_hclass_t msg_#xxxxxx#_class[];

/**Initializer for structure msg_#xxxxxx#_t.
 * 
 * A static msg_#xxxxxx#_t structure must be initialized
 * with the MSG_#XXXXXX#_INIT() macro. For instance,
 * @code 
 * 
 *  msg_#xxxxxx#_t msg_#xxxxxx# = MSG_#XXXXXX#_INIT;
 * 
 * @endcode
 * @HI
 */
#define MSG_#XXXXXX#_INIT() MSG_HDR_INIT(#xxxxxx#)

/**Initialize a structure msg_#xxxxxx#_t.
 * 
 * An msg_#xxxxxx#_t structure can be initialized with the
 * msg_#xxxxxx#_init() function/macro. For instance,
 * @code
 * 
 *  msg_#xxxxxx#_t msg_#xxxxxx#;
 * 
 *  msg_#xxxxxx#_init(&msg_#xxxxxx#);
 * 
 * @endcode
 * @HI
 */
#if SU_HAVE_INLINE
su_inline msg_#xxxxxx#_t *msg_#xxxxxx#_init(msg_#xxxxxx#_t x[1])
{
  return MSG_HEADER_INIT(x, msg_#xxxxxx#_class, sizeof(msg_#xxxxxx#_t));
}
#else
#define msg_#xxxxxx#_init(x) \
  MSG_HEADER_INIT(x, msg_#xxxxxx#_class, sizeof(msg_#xxxxxx#_t))
#endif

/**Test if header object is instance of msg_#xxxxxx#_t.
 * 
 * The function msg_is_#xxxxxx#() returns true (nonzero) if
 * the header class is an instance of #xxxxxxx_xxxxxxx#
 * object and false (zero) otherwise.
 * 
 * @param header pointer to the header structure to be tested
 * 
 * @return
 * The function msg_is_x#xxxxxx#() returns true (nonzero) if
 * the header object is an instance of header #xxxxxx# and
 * false (zero) otherwise.
 */
#if SU_HAVE_INLINE
su_inline int msg_is_#xxxxxx#(msg_header_t const *header)
{
  return header && header->sh_class->hc_hash == msg_#xxxxxx#_hash;
}
#else
int msg_is_#xxxxxx#(msg_header_t const *header);
#endif

#define msg_#xxxxxx#_p(h) msg_is_#xxxxxx#((h))

/**Duplicate (deep copy) @c msg_#xxxxxx#_t.
 * 
 * The function msg_#xxxxxx#_dup() duplicates a header
 * structure @a hdr.  If the header structure @a hdr
 * contains a reference (@c hdr->x_next) to a list of
 * headers, all the headers in the list are duplicated, too.
 * 
 * @param home  memory home used to allocate new structure
 * @param hdr   header structure to be duplicated
 * 
 * When duplicating, all parameter lists and non-constant
 * strings attached to the header are copied, too.  The
 * function uses given memory @a home to allocate all the
 * memory areas used to copy the header.
 * 
 * @par Example
 * @code
 * 
 *   #xxxxxx# = msg_#xxxxxx#_dup(home, tst->msg_#xxxxxx#);
 * 
 * @endcode
 * 
 * @return
 * The function msg_#xxxxxx#_dup() returns a pointer to the
 * newly duplicated msg_#xxxxxx#_t header structure, or NULL
 * upon an error.
 */
msg_#xxxxxx#_t *msg_#xxxxxx#_dup(su_home_t *home, msg_#xxxxxx#_t const *hdr);

/**Copy a msg_#xxxxxx#_t header structure.
 * 
 * The function msg_#xxxxxx#_copy() copies a header structure @a
 * hdr.  If the header structure @a hdr contains a reference (@c
 * hdr->h_next) to a list of headers, all the headers in that
 * list are copied, too. The function uses given memory @a home
 * to allocate all the memory areas used to copy the header
 * structure @a hdr.
 * 
 * @param home    memory home used to allocate new structure
 * @param hdr     pointer to the header structure to be duplicated
 * 
 * When copying, only the header structure and parameter lists
 * attached to it are duplicated.  The new header structure
 * retains all the references to the strings within the old @a
 * header, including the encoding of the old header, if present.
 * 
 * @par Example
 * @code
 * 
 *   #xxxxxx# = msg_#xxxxxx#_copy(home, tst->msg_#xxxxxx#);
 * 
 * @endcode
 * 
 * @return
 * The function msg_#xxxxxx#_copy() returns a pointer to
 * newly copied header structure, or NULL upon an error.
 */
msg_#xxxxxx#_t *msg_#xxxxxx#_copy(su_home_t *home, 
				  msg_#xxxxxx#_t const *hdr);

/**Make a header structure msg_#xxxxxx#_t.
 * 
 * The function msg_#xxxxxx#_make() makes a new
 * msg_#xxxxxx#_t header structure.  It allocates a new
 * header structure, and decodes the string @a s as the
 * value of the structure.
 * 
 * @param home memory home used to allocate new header structure.
 * @param s    string to be decoded as value of the new header structure
 * 
 * @note This function is usually implemented as a macro calling
 * msg_header_make().
 * 
 * @return
 * The function msg_#xxxxxx#_make() returns a pointer to
 * newly maked msg_#xxxxxx#_t header structure, or NULL upon
 * an error.
 */
#if SU_HAVE_INLINE
su_inline msg_#xxxxxx#_t *msg_#xxxxxx#_make(su_home_t *home, char const *s)
{
305
  return (msg_#xxxxxx#_t *)msg_header_make(home, msg_#xxxxxx#_class, s);
Pekka Pessi's avatar
Pekka Pessi committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
}
#else
msg_#xxxxxx#_t *msg_#xxxxxx#_make(su_home_t *home, char const *s);
#endif

/**Make a #xxxxxxx_xxxxxxx# from formatting result.
 * 
 * The function msg_#xxxxxx#_format() makes a new
 * #xxxxxxx_xxxxxxx# object using formatting result as its
 * value.  The function first prints the arguments according to
 * the format @a fmt specified.  Then it allocates a new header
 * structure, and uses the formatting result as the header
 * value.
 * 
 * @param home   memory home used to allocate new header structure.
 * @param fmt    string used as a printf()-style format
 * @param ...    argument list for format
 * 
 * @note This function is usually implemented as a macro calling
 * msg_header_format().
 * 
 * @return
 * The function msg_#xxxxxx#_format() returns a pointer to newly
 * makes header structure, or NULL upon an error.
 * 
 * @HIDE
 */
#if SU_HAVE_INLINE
su_inline
#endif
msg_#xxxxxx#_t *msg_#xxxxxx#_format(su_home_t *home, char const *fmt, ...)
     __attribute__((__format__ (printf, 2, 3)));

#if SU_HAVE_INLINE
su_inline msg_#xxxxxx#_t *msg_#xxxxxx#_format(su_home_t *home, char const *fmt, ...)
{
  msg_header_t *h;
  va_list ap;
  
  va_start(ap, fmt);
  h = msg_header_vformat(home, msg_#xxxxxx#_class, fmt, ap);
  va_end(ap);
 
349
  return (msg_#xxxxxx#_t *)h;
Pekka Pessi's avatar
Pekka Pessi committed
350 351 352 353 354 355 356
}
#endif

/** @} */



357 358
SOFIA_END_DECLS

359
#endif /* !defined(TEST_PROTOS_H) */