msg  1.12.11devel
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
msg_params_length
size_t msg_params_length(char const *const *params)
Calculate number of parameters in a parameter list.
Definition: msg_parser_util.c:1392
su_home_t
SU_HOME_T su_home_t
msg_header_offset
msg_header_t ** msg_header_offset(msg_t const *, msg_pub_t const *, msg_header_t const *)
Get offset of header h from structure mo.
Definition: msg_parser_util.c:1898
msg_header_copy_one
msg_header_t * msg_header_copy_one(su_home_t *home, msg_header_t const *o))
Copy a single header.
Definition: msg_header_copy.c:182
msg_list_append_items
int msg_list_append_items(su_home_t *home, msg_list_t *k, msg_param_t const items[])
Append a list of constant items to a list.
Definition: msg_generic.c:211
msg_common_s::h_len
usize_t h_len
Fragment length (including CRLF)
Definition: msg_types.h:116
msg_unquote_dup
char * msg_unquote_dup(su_home_t *home, char const *q))
Unquote a string, return a duplicate.
Definition: msg_parser_util.c:1714
msg_list_replace_items
int msg_list_replace_items(su_home_t *home, msg_list_t *k, msg_param_t const items[])
Replace a list of constant items on a list.
Definition: msg_generic.c:233
msg_pub_t
MSG_PUB_T msg_pub_t
Public protocol-specific message structure for accessing the message.
Definition: msg_types.h:81
msg_protos.h
Prototypes for common headers.
msg_payload_s
Message payload.
Definition: msg_types.h:214
msg_header_params
msg_param_t ** msg_header_params(msg_common_t const *h)
Pointer to header parameters.
Definition: msg_header.h:213
su_types.h
msg_headers_prepare
issize_t msg_headers_prepare(msg_t *, msg_header_t *headers, int flags)
Encode headers in chain.
Definition: msg_parser.c:1589
msg_header_add_str
int msg_header_add_str(msg_t *msg, msg_pub_t *pub, char const *str)
Add string contents to message.
Definition: msg_parser.c:2800
msg_header_access
msg_header_t * msg_header_access(msg_pub_t const *pub, msg_hclass_t *hc)
Get a header from the public message structure.
Definition: msg_parser_util.c:1914
msg_header_remove_item
int msg_header_remove_item(msg_common_t *h, char const *name)
Remove an item from a header.
Definition: msg_parser_util.c:1232
su_inline
#define su_inline
msg_header_parse_str
int msg_header_parse_str(msg_t *msg, msg_pub_t *pub, char *s)
Add string to message.
Definition: msg_parser.c:2836
msg_random_token
issize_t msg_random_token(char token[], isize_t tlen, void const *d, isize_t dlen)
Generates a random token.
Definition: msg_parser_util.c:1934
msg_header_find_param
char const * msg_header_find_param(msg_common_t const *, char const *name)
Find a header parameter.
Definition: msg_parser_util.c:853
msg_header_remove
int msg_header_remove(msg_t *msg, msg_pub_t *mo, msg_header_t *h)
Remove a header from the header structure and fragment chain.
Definition: msg_parser.c:2919
msg_list_s
List header.
Definition: msg_types.h:161
msg_header_free
void msg_header_free(su_home_t *home, msg_header_t *h)
Free a header structure.
Definition: msg_parser.c:3096
msg.h
Base message interface.
msg_header_remove_param
int msg_header_remove_param(msg_common_t *h, char const *name)
Remove a parameter from header.
Definition: msg_parser_util.c:1081
msg_header_replace_param
int msg_header_replace_param(su_home_t *, msg_common_t *h, char const *param)
Replace or add a parameter to a header.
Definition: msg_parser_util.c:1049
msg_header_make
msg_header_t * msg_header_make(su_home_t *home, msg_hclass_t *hc, char const *s))
Make a header from a value string.
Definition: msg_header_make.c:64
msg_unquote
char * msg_unquote(char *dst, char const *s)
Unquote string.
Definition: msg_parser_util.c:1755
msg_fragment_clear
void msg_fragment_clear(msg_common_t *h)
Clear encoded data from header structure.
Definition: msg_header.h:206
msg_header_size
isize_t msg_header_size(msg_header_t const *h)
Calculate the size of a duplicate of a header structure.
Definition: msg_parser_util.c:1843
msg_header_alloc
msg_header_t * msg_header_alloc(su_home_t *, msg_hclass_t *hc, isize_t extra))
Allocate a header structure.
Definition: msg_parser.c:2307
msg_separator_s
Separator.
Definition: msg_types.h:207
msg_params_cmp
int msg_params_cmp(char const *const a[], char const *const b[])
Compare parameter lists.
Definition: msg_parser_util.c:1689
msg_hash_string
unsigned long msg_hash_string(char const *id)
Calculate a hash over a string.
Definition: msg_parser_util.c:1823
msg_header_replace
int msg_header_replace(msg_t *msg, msg_pub_t *mo, msg_header_t *old_header, msg_header_t *new_header)
Replace a header item with a (list of) header(s).
Definition: msg_parser.c:3020
msg_header_dup_as
msg_header_t * msg_header_dup_as(su_home_t *home, msg_hclass_t *hc, msg_header_t const *o))
Duplicate a header as class hc.
Definition: msg_header_copy.c:259
msg_object_e
issize_t msg_object_e(char b[], isize_t size, msg_pub_t const *mo, int flags)
Encode a message to the buffer.
Definition: msg_parser_util.c:1863
msg_header_dup
msg_header_t * msg_header_dup(su_home_t *home, msg_header_t const *h))
Duplicate a header list.
Definition: msg_header_copy.c:316
msg_payload_create
msg_payload_t * msg_payload_create(su_home_t *home, void const *data, usize_t len))
Create a MIME payload.
Definition: msg_basic.c:212
msg_mclass_s
Factory object for protocol messages.
Definition: msg_mclass.h:97
msg_header_add_dup_as
int msg_header_add_dup_as(msg_t *msg, msg_pub_t *pub, msg_hclass_t *hc, msg_header_t const *o)
Duplicate a header as a given type and add the duplicate into message.
Definition: msg_parser.c:2634
msg_header_copy
msg_header_t * msg_header_copy(su_home_t *home, msg_header_t const *o))
Copy a header list.
Definition: msg_header_copy.c:193
msg_header_copy_as
msg_header_t * msg_header_copy_as(su_home_t *home, msg_hclass_t *hc, msg_header_t const *o))
Copy a list of header objects.
Definition: msg_header_copy.c:148
msg_header_d
msg_header_t * msg_header_d(su_home_t *home, msg_t const *msg, char const *b)
Decode a message header.
Definition: msg_parser.c:1242
msg_header_add_param
int msg_header_add_param(su_home_t *, msg_common_t *h, char const *param)
Add a parameter to a header.
Definition: msg_parser_util.c:1013
msg_header_t
MSG_HDR_T msg_header_t
Any protocol-specific header object.
Definition: msg_types.h:87
msg_s
Message object.
Definition: msg_internal.h:59
msg_fragment_clear_chain
void msg_fragment_clear_chain(msg_header_t *h)
Clear encoded data from header fields.
Definition: msg_parser_util.c:805
msg_header_dup_one
msg_header_t * msg_header_dup_one(su_home_t *home, msg_header_t const *h))
Duplicate a sigle header.
Definition: msg_header_copy.c:213
msg_header_insert
int msg_header_insert(msg_t *msg, msg_pub_t *mo, msg_header_t *h)
Insert a (list of) header(s) to the fragment chain.
Definition: msg_parser.c:2891
SOFIAPUBFUN
#define SOFIAPUBFUN
msg_header_add_make
int msg_header_add_make(msg_t *msg, msg_pub_t *pub, msg_hclass_t *hc, char const *s)
Parse a string as a given header field and add result to the message.
Definition: msg_parser.c:2697
msg_header_find_item
char const * msg_header_find_item(msg_common_t const *h, char const *item)
Find a header item.
Definition: msg_parser_util.c:1160
msg_hclass_t
struct msg_hclass_s const msg_hclass_t
Header class.
Definition: msg_types.h:48
su_alloc.h
msg_header_free_all
void msg_header_free_all(su_home_t *home, msg_header_t *h)
Free a (list of) header structures.
Definition: msg_parser.c:3102
msg_common_s::h_data
void const * h_data
Fragment data.
Definition: msg_types.h:115
msg_hclass_offset
msg_header_t ** msg_hclass_offset(msg_mclass_t const *, msg_pub_t const *, msg_hclass_t *)
Find place to insert header of the class hc.
Definition: msg_parser.c:2469
msg_header_add_dup
int msg_header_add_dup(msg_t *msg, msg_pub_t *pub, msg_header_t const *o)
Duplicate and add a (list of) header(s) to the message.
Definition: msg_parser.c:2558
msg_header_field_e
issize_t msg_header_field_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
Encode header contents.
Definition: msg_parser_util.c:1889
msg_header_e
issize_t msg_header_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
Encode a header.
Definition: msg_parser.c:1717
msg_header_vformat
msg_header_t * msg_header_vformat(su_home_t *home, msg_hclass_t *hc, char const *fmt, va_list ap))
Make a MSG header with formatting provided.
Definition: msg_header_make.c:105
msg_header_prepend
int msg_header_prepend(msg_t *msg, msg_pub_t *pub, msg_header_t **hh, msg_header_t *h)
Prepend a (list of) header(s) to the header structure and fragment chain.
Definition: msg_parser.c:2411
msg_header_remove_all
int msg_header_remove_all(msg_t *msg, msg_pub_t *mo, msg_header_t *h)
Remove a header list from the header structure and fragment chain.
Definition: msg_parser.c:2968
msg_header_add_format
int msg_header_add_format(msg_t *msg, msg_pub_t *pub, msg_hclass_t *hc, char const *fmt,...)
Add formatting result to message.
Definition: msg_parser.c:2754
msg_common_s::h_class
msg_hclass_t * h_class
Header class.
Definition: msg_types.h:114
msg_common_s
Common part of the header objects (or message fragments).
Definition: msg_types.h:111
msg_header_join_items
int msg_header_join_items(su_home_t *home, msg_common_t *dst, msg_common_t const *src, int duplicate)
Join header item lists.
Definition: msg_parser_util.c:1578
msg_header_replace_item
int msg_header_replace_item(su_home_t *, msg_common_t *h, char const *item)
Add an item to a header.
Definition: msg_parser_util.c:1202

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