msg_header.h 9.11 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 MSG_HEADER_H
/** Defined when <sofia-sip/msg_header.h> has been included. */
Pekka Pessi's avatar
Pekka Pessi committed
27
#define MSG_HEADER_H
Pekka Pessi's avatar
Pekka Pessi committed
28
/**@ingroup msg_headers
Pekka Pessi's avatar
Pekka Pessi committed
29
 * @file sofia-sip/msg_header.h
Pekka Pessi's avatar
Pekka Pessi committed
30 31 32 33 34 35 36 37 38 39
 *
 * @brief Message headers.
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Mon Aug 27 15:44:27 2001 ppessi
 * 
 */

#include <stdarg.h>
40
#include <string.h>
Pekka Pessi's avatar
Pekka Pessi committed
41 42

#ifndef SU_TYPES_H
43
#include <sofia-sip/su_types.h>
Pekka Pessi's avatar
Pekka Pessi committed
44
#endif
45
#ifndef SU_ALLOC_H
46
#include <sofia-sip/su_alloc.h>
47 48
#endif
#ifndef MSG_H
49
#include <sofia-sip/msg.h>
50
#endif
51 52 53
#ifndef URL_H
#include <sofia-sip/url.h>
#endif
Pekka Pessi's avatar
Pekka Pessi committed
54

55
SOFIA_BEGIN_DECLS
Pekka Pessi's avatar
Pekka Pessi committed
56

57 58
SOFIAPUBFUN msg_header_t *msg_header_alloc(su_home_t *,
					   msg_hclass_t *hc,
59
					   isize_t extra)
60 61
  __attribute__((__malloc__));

62
SOFIAPUBFUN isize_t msg_header_size(msg_header_t const *h);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

SOFIAPUBFUN msg_header_t **msg_header_offset(msg_t const *,
					 msg_pub_t const *,
					 msg_header_t const *);
SOFIAPUBFUN msg_header_t **msg_hclass_offset(msg_mclass_t const *,
					     msg_pub_t const *,
					     msg_hclass_t *);
SOFIAPUBFUN msg_header_t *msg_header_access(msg_pub_t const *pub,
					    msg_hclass_t *hc);

SOFIAPUBFUN msg_header_t *msg_header_copy_as(su_home_t *home,
					     msg_hclass_t *hc,
					     msg_header_t const *o)
  __attribute__((__malloc__));
SOFIAPUBFUN msg_header_t *msg_header_copy(su_home_t *home,
					  msg_header_t const *o)
  __attribute__((__malloc__));
SOFIAPUBFUN msg_header_t *msg_header_copy_one(su_home_t *home,
					      msg_header_t const *o)
  __attribute__((__malloc__));
SOFIAPUBFUN msg_header_t *msg_header_dup_as(su_home_t *home,
					    msg_hclass_t *hc,
					    msg_header_t const *o)
  __attribute__((__malloc__));
SOFIAPUBFUN msg_header_t *msg_header_dup(su_home_t *home,
					 msg_header_t const *h)
  __attribute__((__malloc__));
SOFIAPUBFUN msg_header_t *msg_header_dup_one(su_home_t *home,
					     msg_header_t const *h)
  __attribute__((__malloc__));

SOFIAPUBFUN msg_header_t *msg_header_d(su_home_t *home,
				       msg_t const *msg,
				       char const *b);
97 98 99 100 101 102
SOFIAPUBFUN issize_t msg_header_e(char b[], isize_t bsiz,
				  msg_header_t const *h,
				  int flags);
SOFIAPUBFUN issize_t msg_object_e(char b[], isize_t size,
				  msg_pub_t const *mo,
				  int flags);
103

104 105 106
SOFIAPUBFUN issize_t msg_header_field_e(char b[], isize_t bsiz,
					msg_header_t const *h,
					int flags);
107 108 109 110

SOFIAPUBFUN int msg_header_remove(msg_t *msg,
				  msg_pub_t *mo,
				  msg_header_t *h);
111

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
SOFIAPUBFUN int msg_header_remove_all(msg_t *msg,
				      msg_pub_t *mo,
				      msg_header_t *h);

SOFIAPUBFUN int msg_header_insert(msg_t *msg, msg_pub_t *mo,
				  msg_header_t *h);

SOFIAPUBFUN int msg_header_replace(msg_t *msg, msg_pub_t *mo,
				   msg_header_t *old_header,
				   msg_header_t *new_header);

SOFIAPUBFUN int msg_header_add_dup(msg_t *msg,
				   msg_pub_t *pub,
				   msg_header_t const *o);

SOFIAPUBFUN int msg_header_add_str(msg_t *msg,
				   msg_pub_t *pub,
				   char const *str);

131 132 133 134
SOFIAPUBFUN int msg_header_parse_str(msg_t *msg,
				     msg_pub_t *pub,
				     char *s);

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
SOFIAPUBFUN int msg_header_add_dup_as(msg_t *msg,
				      msg_pub_t *pub,
				      msg_hclass_t *hc,
				      msg_header_t const *o);

SOFIAPUBFUN int msg_header_add_make(msg_t *msg,
				    msg_pub_t *pub,
				    msg_hclass_t *hc,
				    char const *s);

SOFIAPUBFUN int msg_header_prepend(msg_t *msg,
				   msg_pub_t *pub,
				   msg_header_t **hh,
				   msg_header_t *h);

SOFIAPUBFUN msg_header_t *msg_header_make(su_home_t *home,
					  msg_hclass_t *hc,
					  char const *s)
Pekka Pessi's avatar
Pekka Pessi committed
153 154
     __attribute__((__malloc__));

155 156 157
SOFIAPUBFUN msg_header_t *msg_header_format(su_home_t *home,
					    msg_hclass_t *hc,
					    char const *fmt, ...)
Pekka Pessi's avatar
Pekka Pessi committed
158 159
     __attribute__ ((__malloc__, __format__ (printf, 3, 4)));

160 161 162 163
SOFIAPUBFUN msg_header_t *msg_header_vformat(su_home_t *home,
					     msg_hclass_t *hc,
					     char const *fmt,
					     va_list ap)
Pekka Pessi's avatar
Pekka Pessi committed
164 165
     __attribute__((__malloc__));

166

167 168
SOFIAPUBFUN void msg_header_free(su_home_t *home,
				 msg_header_t *h);
169

170 171
SOFIAPUBFUN void msg_header_free_all(su_home_t *home,
				     msg_header_t *h);
172

173 174
SOFIAPUBFUN msg_payload_t *msg_payload_create(su_home_t *home,
					      void const *data,
175
					      usize_t len)
Pekka Pessi's avatar
Pekka Pessi committed
176 177
     __attribute__((__malloc__));

178 179
SOFIAPUBFUN msg_separator_t *msg_separator_create(su_home_t *home)
  __attribute__((__malloc__));
Pekka Pessi's avatar
Pekka Pessi committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193

/* Chunk handling macros */

/** Get pointer to beginning of available buffer space */
#define MSG_CHUNK_BUFFER(pl) \
  ((char *)pl->pl_common->h_data + (pl)->pl_common->h_len)
/** Get size of available buffer space */
#define MSG_CHUNK_AVAIL(pl) \
  ((pl)->pl_len + ((pl)->pl_data - (char *)pl->pl_common->h_data) - \
   (pl)->pl_common->h_len)
/** Get next chunk in list */
#define MSG_CHUNK_NEXT(pl) \
  ((pl)->pl_next)

194 195 196
SOFIAPUBFUN issize_t msg_headers_prepare(msg_t *,
					 msg_header_t *headers,
					 int flags);
Pekka Pessi's avatar
Pekka Pessi committed
197 198 199

#ifdef SU_HAVE_INLINE
/** Clear encoded data from header structure. */
200
su_inline void msg_fragment_clear(msg_common_t *h) 
Pekka Pessi's avatar
Pekka Pessi committed
201 202 203
{
  h->h_data = NULL, h->h_len = 0;
}
204

Pekka Pessi's avatar
Pekka Pessi committed
205
/** Pointer to header parameters. */
206
su_inline 
207
msg_param_t **msg_header_params(msg_common_t const *h)
Pekka Pessi's avatar
Pekka Pessi committed
208 209 210 211 212 213 214 215
{
  if (h && h->h_class->hc_params) {
    return (msg_param_t **)((char *)h + h->h_class->hc_params);
  }
  return NULL;
}
#else
#define msg_fragment_clear(h) ((h)->h_data = NULL, (h)->h_len = 0)
216 217 218
#define msg_header_params(h) \
 (((h) && ((msg_common_t *)h)->h_class->hc_params) ? \
  (msg_param_t **)((char *)(h) + ((msg_common_t *)h)->h_class->hc_params) : NULL)
Pekka Pessi's avatar
Pekka Pessi committed
219 220
#endif

221 222 223 224 225 226 227
SOFIAPUBFUN char const *msg_header_find_param(msg_common_t const *,
					      char const *name);
SOFIAPUBFUN int msg_header_add_param(su_home_t *, msg_common_t *h,
				     char const *param);
SOFIAPUBFUN int msg_header_replace_param(su_home_t *, msg_common_t *h,
					 char const *param);
SOFIAPUBFUN int msg_header_remove_param(msg_common_t *h, char const *name);
Pekka Pessi's avatar
Pekka Pessi committed
228

229 230 231 232 233 234 235
SOFIAPUBFUN char const *msg_header_find_item(msg_common_t const *h,
					     char const *item);

SOFIAPUBFUN int msg_header_replace_item(su_home_t *, msg_common_t *h,
					char const *item);
SOFIAPUBFUN int msg_header_remove_item(msg_common_t *h, char const *name);

Pekka Pessi's avatar
Pekka Pessi committed
236
/** Append a list of constant items to a list. */
237 238
SOFIAPUBFUN int msg_list_append_items(su_home_t *home,
				      msg_list_t *k,
239
				      msg_param_t const items[]);
Pekka Pessi's avatar
Pekka Pessi committed
240 241

/** Replace a list of constant items on a list */
242 243 244 245
SOFIAPUBFUN int msg_list_replace_items(su_home_t *home,
				       msg_list_t *k,
				       msg_param_t const items[]);

246 247 248 249 250
SOFIAPUBFUN int msg_header_join_items(su_home_t *home,
				      msg_common_t *dst,
				      msg_common_t const *src,
				      int duplicate);

251 252
SOFIAPUBFUN issize_t msg_random_token(char token[], isize_t tlen,
				      void const *d, isize_t dlen);
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

SOFIAPUBFUN msg_param_t msg_params_find(msg_param_t const pp[],
					char const *name);
SOFIAPUBFUN msg_param_t *msg_params_find_slot(msg_param_t [],
					      char const *name);
SOFIAPUBFUN int msg_params_add(su_home_t *sh,
			       msg_param_t **pp,
			       char const *param);
SOFIAPUBFUN int msg_params_cmp(char const * const a[],
			       char const * const b[]);
SOFIAPUBFUN int msg_params_replace(su_home_t *,
				   char const * **inout_paramlist,
				   char const *);
SOFIAPUBFUN int msg_params_remove(char const **paramlist,
				  char const *name);
SOFIAPUBFUN size_t msg_params_length(char const * const * params);
Pekka Pessi's avatar
Pekka Pessi committed
269 270

/** Unquote a string, return a duplicate. */
271
SOFIAPUBFUN char *msg_unquote_dup(su_home_t *home, char const *q)
Pekka Pessi's avatar
Pekka Pessi committed
272 273
     __attribute__((__malloc__));

274
SOFIAPUBFUN char *msg_unquote(char *dst, char const *s);
Pekka Pessi's avatar
Pekka Pessi committed
275 276

/** Calculate a hash over a string. */
277
SOFIAPUBFUN unsigned long msg_hash_string(char const *id);
Pekka Pessi's avatar
Pekka Pessi committed
278 279

/* Align pointer p for multiple of t (which must be a power of 2) */
280 281 282
#define MSG_ALIGN(p, t) (((uintptr_t)(p) + (t) - 1) & (0 - (uintptr_t)(t)))
#define MSG_STRUCT_SIZE_ALIGN(rv) ((rv) = MSG_ALIGN(rv, sizeof(void *)))
#define MSG_STRUCT_ALIGN(p) ((p) = (void*)MSG_ALIGN(p, sizeof(void *)))
Pekka Pessi's avatar
Pekka Pessi committed
283 284 285 286 287 288 289

enum {
 msg_n_params = 8,	/* allocation size of parameter string list */
#define MSG_N_PARAMS msg_n_params
};

/** Initialize a header structure. @HIDE */
290 291 292 293
#define MSG_HEADER_INIT(h, msg_class, size)			\
  ((void)memset((h), 0, (size)),				\
   (void)(((msg_common_t *)(h))->h_class = (msg_class)),	\
   (h))
Pekka Pessi's avatar
Pekka Pessi committed
294 295 296 297

/** No header. */
#define MSG_HEADER_NONE ((msg_header_t *)-1)

298 299
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
300
#ifndef MSG_PROTOS_H
301
#include <sofia-sip/msg_protos.h>
Pekka Pessi's avatar
Pekka Pessi committed
302 303 304
#endif

#endif /** !defined(MSG_HEADER_H) */