msg  1.12.11devel
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
msg_header.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Sofia-SIP package
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  *
6  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 
25 #ifndef MSG_HEADER_H
26 
27 #define MSG_HEADER_H
28 
39 #include <stdarg.h>
40 #include <string.h>
41 
42 #ifndef SU_TYPES_H
43 #include <sofia-sip/su_types.h>
44 #endif
45 #ifndef SU_ALLOC_H
46 #include <sofia-sip/su_alloc.h>
47 #endif
48 #ifndef MSG_H
49 #include <sofia-sip/msg.h>
50 #endif
51 #ifndef URL_H
52 #include <sofia-sip/url.h>
53 #endif
54 
55 SOFIA_BEGIN_DECLS
56 
58  msg_hclass_t *hc,
59  isize_t extra)
60  __attribute__((__malloc__));
61 
62 SOFIAPUBFUN isize_t msg_header_size(msg_header_t const *h);
63 
65  msg_pub_t const *,
66  msg_header_t const *);
68  msg_pub_t const *,
69  msg_hclass_t *);
71  msg_hclass_t *hc);
72 
74  msg_hclass_t *hc,
75  msg_header_t const *o)
76  __attribute__((__malloc__));
78  msg_header_t const *o)
79  __attribute__((__malloc__));
81  msg_header_t const *o)
82  __attribute__((__malloc__));
84  msg_hclass_t *hc,
85  msg_header_t const *o)
86  __attribute__((__malloc__));
88  msg_header_t const *h)
89  __attribute__((__malloc__));
91  msg_header_t const *h)
92  __attribute__((__malloc__));
93 
95  msg_t const *msg,
96  char const *b);
97 SOFIAPUBFUN issize_t msg_header_e(char b[], isize_t bsiz,
98  msg_header_t const *h,
99  int flags);
100 SOFIAPUBFUN issize_t msg_object_e(char b[], isize_t size,
101  msg_pub_t const *mo,
102  int flags);
103 
104 SOFIAPUBFUN issize_t msg_header_field_e(char b[], isize_t bsiz,
105  msg_header_t const *h,
106  int flags);
107 
109  msg_pub_t *mo,
110  msg_header_t *h);
111 
113  msg_pub_t *mo,
114  msg_header_t *h);
115 
117  msg_header_t *h);
118 
120  msg_header_t *old_header,
121  msg_header_t *new_header);
122 
124  msg_pub_t *pub,
125  msg_header_t const *o);
126 
128  msg_pub_t *pub,
129  char const *str);
130 
132  msg_pub_t *pub,
133  char *s);
134 
136  msg_pub_t *pub,
137  msg_hclass_t *hc,
138  msg_header_t const *o);
139 
141  msg_pub_t *pub,
142  msg_hclass_t *hc,
143  char const *s);
144 
146  msg_pub_t *pub,
147  msg_hclass_t *hc,
148  char const *fmt,
149  ...);
150 
152  msg_pub_t *pub,
153  msg_header_t **hh,
154  msg_header_t *h);
155 
157  msg_hclass_t *hc,
158  char const *s)
159  __attribute__((__malloc__));
160 
161 SOFIAPUBFUN msg_header_t *msg_header_format(su_home_t *home,
162  msg_hclass_t *hc,
163  char const *fmt, ...)
164  __attribute__ ((__malloc__, __format__ (printf, 3, 4)));
165 
166 SOFIAPUBFUN msg_header_t *msg_header_vformat(su_home_t *home,
167  msg_hclass_t *hc,
168  char const *fmt,
169  va_list ap)
170  __attribute__((__malloc__));
171 
172 
173 SOFIAPUBFUN void msg_header_free(su_home_t *home,
174  msg_header_t *h);
175 
176 SOFIAPUBFUN void msg_header_free_all(su_home_t *home,
177  msg_header_t *h);
178 
179 SOFIAPUBFUN msg_payload_t *msg_payload_create(su_home_t *home,
180  void const *data,
181  usize_t len)
182  __attribute__((__malloc__));
183 
184 SOFIAPUBFUN msg_separator_t *msg_separator_create(su_home_t *home)
185  __attribute__((__malloc__));
186 
187 /* Chunk handling macros */
188 
190 #define MSG_CHUNK_BUFFER(pl) \
191  ((char *)pl->pl_common->h_data + (pl)->pl_common->h_len)
192 
193 #define MSG_CHUNK_AVAIL(pl) \
194  ((pl)->pl_len + ((pl)->pl_data - (char *)pl->pl_common->h_data) - \
195  (pl)->pl_common->h_len)
196 
197 #define MSG_CHUNK_NEXT(pl) \
198  ((pl)->pl_next)
199 
201  msg_header_t *headers,
202  int flags);
203 
204 #ifdef SU_HAVE_INLINE
205 
207 {
208  h->h_data = NULL, h->h_len = 0;
209 }
210 
212 su_inline
213 msg_param_t **msg_header_params(msg_common_t const *h)
214 {
215  if (h && h->h_class->hc_params) {
216  return (msg_param_t **)((char *)h + h->h_class->hc_params);
217  }
218  return NULL;
219 }
220 #else
221 #define msg_fragment_clear(h) ((h)->h_data = NULL, (h)->h_len = 0)
222 #define msg_header_params(h) \
223  (((h) && ((msg_common_t *)h)->h_class->hc_params) ? \
224  (msg_param_t **)((char *)(h) + ((msg_common_t *)h)->h_class->hc_params) : NULL)
225 #endif
226 
228 
230  char const *name);
232  char const *param);
234  char const *param);
235 SOFIAPUBFUN int msg_header_remove_param(msg_common_t *h, char const *name);
236 
237 SOFIAPUBFUN char const *msg_header_find_item(msg_common_t const *h,
238  char const *item);
239 
241  char const *item);
242 SOFIAPUBFUN int msg_header_remove_item(msg_common_t *h, char const *name);
243 
246  msg_list_t *k,
247  msg_param_t const items[]);
248 
251  msg_list_t *k,
252  msg_param_t const items[]);
253 
255  msg_common_t *dst,
256  msg_common_t const *src,
257  int duplicate);
258 
259 SOFIAPUBFUN issize_t msg_random_token(char token[], isize_t tlen,
260  void const *d, isize_t dlen);
261 
262 SOFIAPUBFUN msg_param_t msg_params_find(msg_param_t const pp[],
263  char const *name);
264 SOFIAPUBFUN msg_param_t *msg_params_find_slot(msg_param_t [],
265  char const *name);
266 SOFIAPUBFUN int msg_params_add(su_home_t *sh,
267  msg_param_t **pp,
268  char const *param);
269 SOFIAPUBFUN int msg_params_cmp(char const * const a[],
270  char const * const b[]);
271 SOFIAPUBFUN int msg_params_replace(su_home_t *,
272  char const * **inout_paramlist,
273  char const *);
274 SOFIAPUBFUN int msg_params_remove(char const **paramlist,
275  char const *name);
276 SOFIAPUBFUN size_t msg_params_length(char const * const * params);
277 
279 SOFIAPUBFUN char *msg_unquote_dup(su_home_t *home, char const *q)
280  __attribute__((__malloc__));
281 
282 SOFIAPUBFUN char *msg_unquote(char *dst, char const *s);
283 
285 SOFIAPUBFUN unsigned long msg_hash_string(char const *id);
286 
287 /* Align pointer p for multiple of t (which must be a power of 2) */
288 #define MSG_ALIGN(p, t) (((uintptr_t)(p) + (t) - 1) & (0 - (uintptr_t)(t)))
289 #define MSG_STRUCT_SIZE_ALIGN(rv) ((rv) = MSG_ALIGN(rv, sizeof(void *)))
290 #define MSG_STRUCT_ALIGN(p) ((p) = (void*)MSG_ALIGN(p, sizeof(void *)))
291 
292 enum {
293  msg_n_params = 8 /* allocation size of parameter string list */
294 #define MSG_N_PARAMS msg_n_params
295 };
296 
298 #define MSG_HEADER_INIT(h, msg_class, size) \
299  ((void)memset((h), 0, (size)), \
300  (void)(((msg_common_t *)(h))->h_class = (msg_class)), \
301  (h))
302 
304 #define MSG_HEADER_NONE ((msg_header_t *)(intptr_t)-1)
305 
306 SOFIA_END_DECLS
307 
308 #ifndef MSG_PROTOS_H
309 #include <sofia-sip/msg_protos.h>
310 #endif
311 
312 #endif

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