sip  1.13.0
sip_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 SIP_HEADER_H
26 
27 #define SIP_HEADER_H
28 
38 #ifndef SU_ALLOC_H
39 #include <sofia-sip/su_alloc.h>
40 #endif
41 
42 #ifndef SU_TAG_H
43 #include <sofia-sip/su_tag.h>
44 #endif
45 
46 #ifndef SIP_H
47 #include <sofia-sip/sip.h>
48 #endif
49 
50 #ifndef MSG_HEADER_H
51 #include <sofia-sip/msg_header.h>
52 #endif
53 
54 #ifndef _STRING_H
55 #include <string.h>
56 #endif
57 
58 SOFIA_BEGIN_DECLS
59 
62 
65 
68 
70 #define sip_is_sip(sip) ((sip) && (sip)->sip_ident == SIP_PROTOCOL_TAG)
71 
73 #define SIP_HDR_INIT(name) {{{ 0, 0, sip_##name##_class }}}
74 
76 #define SIP_HEADER_INIT(h, sip_class, size) \
77  ((void)memset((h), 0, (size)), \
78  (void)(((sip_common_t *)(h))->h_class = (sip_class)), \
79  (h))
80 
82 SOFIAPUBFUN int sip_serialize(msg_t *msg, sip_t *sip);
83 
85 SOFIAPUBFUN issize_t sip_e(sip_t const *sip, int flags, char b[], isize_t size);
86 
88 SOFIAPUBFUN int sip_is_header(sip_header_t const *header);
89 
92  sip_header_t const *h);
93 
96 
98 SOFIAPUBFUN int sip_add_dup_as(msg_t *msg, sip_t *sip,
99  msg_hclass_t *hc, sip_header_t const *o);
100 
102 SOFIAPUBFUN int sip_add_headers(msg_t *msg, sip_t *sip,
103  void const *extra, va_list headers);
104 
106 SOFIAPUBFUN int sip_add_tl(msg_t *msg, sip_t *sip,
107  tag_type_t tag, tag_value_t value, ...);
108 
110 SOFIAPUBFUN int sip_add_tagis(msg_t *, sip_t *, tagi_t const **inout_list);
111 
113 SOFIAPUBFUN int sip_add_make(msg_t *, sip_t *, msg_hclass_t *hc, char const *s);
114 
117  tag_type_t tag, tag_value_t value,
118  ...);
119 
122  char const *query,
123  msg_mclass_t const *parser);
124 
127 
129 #define sip_fragment_clear(a) ((a)->h_data = NULL, (a)->h_len = 0)
130 
131 /* Use __attribute__ to allow argument checking for sip_header_format() */
132 #if !defined(__GNUC__) && !defined(__attribute__)
133 #define __attribute__(x)
134 #endif
135 
138  msg_hclass_t *hc,
139  char const *fmt,
140  ...)
141  __attribute__((__format__ (printf, 3, 4)));
142 
144 SOFIAPUBFUN sip_time_t sip_now(void);
145 
146 SOFIAPUBVAR char const sip_method_name_ack[];
147 SOFIAPUBVAR char const sip_method_name_bye[];
148 SOFIAPUBVAR char const sip_method_name_cancel[];
149 SOFIAPUBVAR char const sip_method_name_invite[];
150 SOFIAPUBVAR char const sip_method_name_options[];
151 SOFIAPUBVAR char const sip_method_name_register[];
152 SOFIAPUBVAR char const sip_method_name_info[];
153 SOFIAPUBVAR char const sip_method_name_prack[];
154 SOFIAPUBVAR char const sip_method_name_comet[];
155 SOFIAPUBVAR char const sip_method_name_message[];
156 SOFIAPUBVAR char const sip_method_name_subscribe[];
157 SOFIAPUBVAR char const sip_method_name_notify[];
158 SOFIAPUBVAR char const sip_method_name_refer[];
159 
161 SOFIAPUBVAR char const sip_transport_udp[];
163 SOFIAPUBVAR char const sip_transport_tcp[];
165 SOFIAPUBVAR char const sip_transport_sctp[];
167 SOFIAPUBVAR char const sip_transport_tls[];
169 SOFIAPUBVAR char const sip_transport_ws[];
171 SOFIAPUBVAR char const sip_transport_wss[];
173 SOFIAPUBVAR char const sip_version_2_0[];
174 
175 #define SIP_VERSION_CURRENT sip_version_2_0
176 
178 SOFIAPUBVAR char const sip_parser_version[];
179 
181 #define SIP_PORT(s) ((s) ? (s) : "5060")
182 
184 #define SIPS_PORT(s) ((s) ? (s) : "5061")
185 
187 SOFIAPUBFUN char const *sip_method_name(sip_method_t method, char const *name);
188 
190 SOFIAPUBFUN sip_method_t sip_method_code(char const *name);
191 
192 SOFIAPUBVAR char const * const sip_method_names[];
193 
194 #define SIP_METHOD_NAME(method, name) \
195  ((method) == sip_method_unknown ? (name) : sip_method_name(method, name))
196 
197 #define sip_header_make(h, c, s) \
198  ((sip_header_t *)msg_header_make((h), (c), (s)))
199 #define sip_header_vformat(h, c, f, a) \
200  ((sip_header_t *)msg_header_vformat((h), (c), (f), (a)))
201 
202 SOFIA_END_DECLS
203 #ifndef SIP_PROTOS_H
204 #include <sofia-sip/sip_protos.h>
205 #endif
206 SOFIA_BEGIN_DECLS
207 
211  sip_method_t method, const char *name,
212  url_string_t const *url,
213  char const *version);
214 
218  unsigned status,
219  char const *phrase,
220  char const *version);
221 
224  char const *domain);
225 
228  unsigned method, char const *name);
229 
232  unsigned method, char const *name);
233 
236  url_string_t const *url,
237  char const *param,
238  /* char const *params, */
239  ...);
240 
243  sip_expires_t const *ex,
244  sip_date_t const *date,
245  sip_time_t def,
246  sip_time_t now);
247 
251 
254 
257 
260  url_t const *maddr);
261 
264  url_t const *rq_url,
265  url_t const *m_url);
266 
269 
270 SOFIAPUBFUN int sip_from_tag(su_home_t *, sip_from_t *from, char const *tag);
271 
274 
275 SOFIAPUBFUN int sip_to_tag(su_home_t *, sip_to_t *to, char const *tag);
276 
279  char const *host,
280  char const *port,
281  char const *transport,
282  /* char const *params */
283  ...);
284 
286 #if SU_HAVE_INLINE
287 su_inline char const *sip_via_transport(sip_via_t const *v)
288 {
289  char const *tp = v->v_protocol;
290  if (tp) {
291  tp = strchr(tp, '/');
292  if (tp) {
293  tp = strchr(tp + 1, '/');
294  if (tp)
295  return tp + 1;
296  }
297  }
298  return NULL;
299 }
300 #else
301 char const *sip_via_transport(sip_via_t const *v);
302 #endif
303 
304 SOFIAPUBFUN char const *sip_via_port(sip_via_t const *v, int *using_rport);
305 
307 sip_payload_t *sip_payload_create(su_home_t *, void const *data, isize_t len);
308 
326 #define SIP_PAYLOAD_INIT2(data, length) \
327  {{{ 0, 0, sip_payload_class, data, length }}, NULL, data, length }
328 
331 
335  sip_supported_t const *support,
336  sip_require_t const *require);
337 
340  sip_supported_t const *support,
341  sip_require_t const *by_require,
342  sip_require_t const *require);
343 
347  sip_supported_t const *support,
348  sip_require_t const *by_require,
349  sip_proxy_require_t const *by_proxy_require,
350  sip_require_t const *require,
351  sip_require_t const *require2,
352  sip_require_t const *require3);
353 
356 int sip_has_supported(sip_supported_t const *support, char const *feature);
357 
360 int sip_has_feature(msg_list_t const *supported, char const *feature);
361 
363 SOFIAPUBFUN int sip_is_allowed(sip_allow_t const *allow,
364  sip_method_t method, char const *name);
365 
367 #define SIP_IS_ALLOWED(allow, method) \
368  (sip_method_unknown < (method) && (method) < 32 && \
369  (allow) && ((allow)->k_bitmap & (1 << (method))) != 0)
370 
391  sip_mask_request = (1 << 0),
392 
398  sip_mask_response = (1 << 1),
399 
405  sip_mask_ua = (1 << 2),
406 
412  sip_mask_proxy = (1 << 3),
413 
420  sip_mask_registrar = (1 << 4),
421 
428  sip_mask_100rel = (1 << 5),
429 
436  sip_mask_events = (1 << 6),
437 
444  sip_mask_timer = (1 << 7),
445 
452  sip_mask_privacy = (1 << 8),
453 
460  sip_mask_pref = (1 << 9),
461 
468  sip_mask_publish = (1 << 10)
469 
470  /* NOTE:
471  * When adding bits, please update nta_agent_create() and
472  * NTATAG_BAD_RESP_MASK()/NTATAG_BAD_REQ_MASK() documentation.
473  */
474 };
475 
476 /* ------------------------------------------------------------------------- */
477 
478 /* Here are @deprecated functions and names for compatibility */
479 
481 SOFIAPUBFUN issize_t sip_header_e(char[], isize_t, sip_header_t const *, int);
482 
485 sip_header_t *sip_header_d(su_home_t *, msg_t const *, char const *);
486 
488 SOFIAPUBFUN issize_t sip_header_field_e(char[], isize_t, sip_header_t const *, int);
489 
491 SOFIAPUBFUN issize_t sip_header_field_d(su_home_t *, sip_header_t *, char *, isize_t);
492 
494 SOFIAPUBFUN isize_t sip_header_size(sip_header_t const *h);
495 
498 
501 
504  sip_allow_events_t *ae,
505  char const *e);
506 
509  char const *param);
510 
511 SOFIAPUBFUN int sip_to_add_param(su_home_t *, sip_to_t *, char const *);
512 
513 SOFIAPUBFUN int sip_from_add_param(su_home_t *, sip_from_t *, char const *);
514 
516 SOFIAPUBFUN int sip_via_add_param(su_home_t *, sip_via_t *, char const *);
517 
518 #define sip_from_make_url sip_from_create
519 #define sip_to_make_url sip_to_create
520 #define sip_params_find msg_params_find
521 
522 SOFIA_END_DECLS
523 
524 #endif
Bit marking essential headers for caller preference extension.
Definition: sip_header.h:460
SIP objects.
sip_payload_t * sip_payload_create(su_home_t *, void const *data, isize_t len)
Create a SIP payload structure.
Definition: sip_basic.c:452
struct msg_hclass_s const msg_hclass_t
Structure for Content-Length header.
Definition: sip.h:511
SU_HOME_T su_home_t
issize_t sip_header_field_d(su_home_t *, sip_header_t *, char *, isize_t)
Decode the string containing header field.
Definition: sip_util.c:367
sip_unsupported_t * sip_has_unsupported_any(su_home_t *, sip_supported_t const *support, sip_require_t const *by_require, sip_proxy_require_t const *by_proxy_require, sip_require_t const *require, sip_require_t const *require2, sip_require_t const *require3)
Check if required features are not supported.
Definition: sip_feature.c:398
char const sip_version_2_0[]
SIP version 2.0.
Definition: sip_parser.c:61
int sip_has_supported(sip_supported_t const *support, char const *feature)
Check that a feature is supported.
Definition: sip_feature.c:490
sip_time_t sip_contact_expires(sip_contact_t const *m, sip_expires_t const *ex, sip_date_t const *date, sip_time_t def, sip_time_t now)
Calculate expiration time of a Contact header.
Definition: sip_time.c:72
char const sip_parser_version[]
SIP parser version.
Definition: sip_parser.c:58
int sip_has_feature(msg_list_t const *supported, char const *feature)
Check that a feature is in the list.
Definition: sip_feature.c:473
sip_separator_t * sip_separator_create(su_home_t *home)
Create a SIP separator line structure.
Definition: sip_basic.c:514
sip_method_t
IDs for well-known SIP methods.
Definition: sip.h:48
#define su_inline
int sip_is_header(sip_header_t const *header)
Test if header is a pointer to a SIP header object.
issize_t sip_header_e(char[], isize_t, sip_header_t const *, int)
Encode a SIP header field (name: contents CRLF).
Definition: sip_header.c:92
sip_request_t * sip_request_create(su_home_t *home, sip_method_t method, const char *name, url_string_t const *url, char const *version)
Create a request line object.
Definition: sip_basic.c:208
struct tag_type_s const * tag_type_t
sip_cseq_t * sip_cseq_create(su_home_t *, uint32_t seq, unsigned method, char const *name)
Create a CSeq header object.
Definition: sip_basic.c:1281
int sip_add_dup_as(msg_t *msg, sip_t *sip, msg_hclass_t *hc, sip_header_t const *o)
Add a duplicate of header object to the SIP message.
Definition: sip_header.c:122
int sip_from_add_param(su_home_t *, sip_from_t *, char const *)
Add a parameter to an sip_from_t object.
Definition: sip_basic.c:1837
char const * sip_via_transport(sip_via_t const *v)
Get transport protocol name.
Definition: sip_header.h:287
issize_t sip_header_field_e(char[], isize_t, sip_header_t const *, int)
Encode contents of a SIP header field.
Bit marking essential headers for PUBLISH servers and clients.
Definition: sip_header.h:468
int sip_allow_events_add(su_home_t *, sip_allow_events_t *ae, char const *e)
Add an event to Allow-Events header.
Definition: sip_event.c:229
int sip_add_make(msg_t *, sip_t *, msg_hclass_t *hc, char const *s)
Parse a string as a header and add it to the SIP message.
Definition: sip_header.c:130
sip_bad_mask
Bitmasks for header classifications.
Definition: sip_header.h:385
sip_from_t * sip_from_create(su_home_t *, url_string_t const *url)
Create a From header object.
Definition: sip_basic.c:1819
sip_header_t * sip_header_copy(su_home_t *, sip_header_t const *o)
Copy a SIP header or whole list.
Definition: sip_header.c:60
msg_time_t sip_time_t
Time in seconds since Jan 01 1900.
Definition: sip.h:113
int sip_update_default_mclass(msg_mclass_t const *mclass)
Update the default SIP parser.
Definition: sip_parser.c:108
char * sip_headers_as_url_query(su_home_t *home, tag_type_t tag, tag_value_t value,...)
Convert headers from taglist as URL query.
Definition: sip_tag_class.c:302
int sip_via_add_param(su_home_t *, sip_via_t *, char const *)
Add a parameter to a Via header object.
Definition: sip_basic.c:2693
char const *const sip_method_names[]
Well-known SIP method names.
Definition: sip_parser.c:330
sip_status_t * sip_status_create(su_home_t *home, unsigned status, char const *phrase, char const *version)
Create a status line object.
Definition: sip_basic.c:377
Structure for From and To headers.
Definition: sip.h:393
Bit marking essential headers in a response message.
Definition: sip_header.h:398
sip_time_t sip_now(void)
Return current time.
Definition: sip_time.c:49
union sip_header_u sip_header_t
Any SIP header - union of all possible SIP headers.
Definition: sip.h:122
sip_expires_t * sip_expires_create(su_home_t *, sip_time_t delta)
Create an Expires header object.
Definition: sip_basic.c:1740
Structure for Allow header field.
Definition: sip.h:426
sip_identity_t * sip_identity_create(su_home_t *, uint32_t seq, unsigned method, char const *name)
Create a @Identity header object.
int sip_add_tagis(msg_t *, sip_t *, tagi_t const **inout_list)
Add duplicates of headers from taglist to the SIP message.
Definition: sip_tag_class.c:209
sip_contact_t * sip_contact_create(su_home_t *, url_string_t const *url, char const *param,...)
Create a Contact header object.
Definition: sip_util.c:96
#define SOFIAPUBFUN
char const * v_protocol
Application and transport protocol.
Definition: sip.h:779
sip_call_id_t * sip_call_id_create(su_home_t *home, char const *domain)
Create a Call-ID header object.
Definition: sip_basic.c:1124
char * sip_header_as_string(su_home_t *home, sip_header_t const *h)
Convert the header h to a string allocated from home.
Definition: sip_util.c:396
Structure for SIP status line.
Definition: sip.h:381
int sip_contact_add_param(su_home_t *, sip_contact_t *, char const *param)
Add a parameter to a Contact header object.
Definition: sip_basic.c:1493
sip_header_t * sip_header_format(su_home_t *home, msg_hclass_t *hc, char const *fmt,...)))
Make a SIP header with formatting provided.
Definition: sip_header.c:97
intptr_t tag_value_t
Structure for CSeq header.
Definition: sip.h:472
sip_to_t * sip_to_create(su_home_t *, url_string_t const *url)
Create a To header object.
Definition: sip_basic.c:2438
Bit marking essential headers for 100rel extension.
Definition: sip_header.h:428
Structure for SIP request line.
Definition: sip.h:368
char const * sip_method_name(sip_method_t method, char const *name)
Return string corresponding to the method.
Definition: sip_parser.c:351
sip_unsupported_t * sip_has_unsupported(su_home_t *, sip_supported_t const *support, sip_require_t const *require)
Check that a required feature is supported.
Definition: sip_feature.c:348
#define SOFIAPUBVAR
sip_date_t * sip_date_create(su_home_t *, sip_time_t t)
Create an Date header object.
Definition: sip_basic.c:1656
isize_t sip_header_size(sip_header_t const *h)
Calculate the size of a SIP header and associated memory areas.
Definition: sip_util.c:432
sip_via_t * sip_via_create(su_home_t *h, char const *host, char const *port, char const *transport,...)
Create a Via object.
Definition: sip_basic.c:2719
issize_t sip_e(sip_t const *sip, int flags, char b[], isize_t size)
Encode a SIP message.
sip_method_t sip_method_code(char const *name)
Return code corresponding to the method code.
Definition: sip_parser.c:459
Bit marking essential headers for session timer extension.
Definition: sip_header.h:444
char const * sip_via_port(sip_via_t const *v, int *using_rport)
Get port number corresponding to a Via line.
Definition: sip_basic.c:2768
Bit marking essential headers for registrar server.
Definition: sip_header.h:420
Bit marking essential headers in a request message.
Definition: sip_header.h:391
Structure for Contact header field.
Definition: sip.h:495
tagi_t * sip_url_query_as_taglist(su_home_t *home, char const *query, msg_mclass_t const *parser)
Convert URL query to a tag list.
Definition: sip_tag_class.c:418
SU_U32_T uint32_t
Bit marking essential headers for privacy extension.
Definition: sip_header.h:452
Structure for Call-ID (and In-Reply-To) header fields.
Definition: sip.h:450
Bit marking essential headers for User-Agent.
Definition: sip_header.h:405
Structure for Via header field.
Definition: sip.h:775
int sip_complete_message(msg_t *msg)
Complete SIP message.
Definition: sip_parser.c:630
msg_mclass_t const * sip_default_mclass(void)
Return a built-in SIP parser object.
Definition: sip_parser.c:70
Structure for Date header.
Definition: sip.h:536
void sip_cloned_parser_destroy(void)
Release SIP parser object if it was cloned.
Definition: sip_parser.c:76
SIP message object.
Definition: sip.h:241
int sip_to_add_param(su_home_t *, sip_to_t *, char const *)
Add a parameter to a sip_to_t object.
Definition: sip_basic.c:2458
int sip_is_allowed(sip_allow_t const *allow, sip_method_t method, char const *name)
Return true if the method is listed in Allow header.
Definition: sip_feature.c:129
sip_route_t * sip_route_create(su_home_t *home, url_t const *url, url_t const *maddr)
Create a Route header object.
Definition: sip_basic.c:2293
Bit marking essential headers for proxy server.
Definition: sip_header.h:412
int sip_add_dup(msg_t *, sip_t *, sip_header_t const *)
Add a duplicate of header object to a SIP message.
Definition: sip_header.c:115
int sip_serialize(msg_t *msg, sip_t *sip)
Serialize headers into the fragment chain.
sip_header_t * sip_header_d(su_home_t *, msg_t const *, char const *)
Decode a SIP header string (name: contents CRLF?).
Definition: sip_header.c:83
sip_record_route_t * sip_record_route_create(su_home_t *, url_t const *rq_url, url_t const *m_url)
Create a Record-Route header object.
Definition: sip_basic.c:2368
int sip_from_tag(su_home_t *, sip_from_t *from, char const *tag)
Add a tag to a From header.
Definition: sip_basic.c:1860
sip_content_length_t * sip_content_length_create(su_home_t *, uint32_t n)
Create a Content-Length header object.
Definition: sip_basic.c:1570
Bit marking essential headers for SIP events.
Definition: sip_header.h:436
sip_header_t * sip_header_dup(su_home_t *, sip_header_t const *)
Duplicate (deep copy) a SIP header or whole list.
Definition: sip_header.c:71
int sip_add_tl(msg_t *msg, sip_t *sip, tag_type_t tag, tag_value_t value,...)
Add duplicates of headers from taglist to the SIP message.
Definition: sip_tag_class.c:191
Structure for @Identity SIP header.
Definition: sip.h:484
Structure for Route and Record-Route header fields.
Definition: sip.h:703
Structure for Expires header.
Definition: sip.h:569
int sip_add_headers(msg_t *msg, sip_t *sip, void const *extra, va_list headers)
Add duplicates of headers to the SIP message.
msg_mclass_t * sip_extend_mclass(msg_mclass_t *input)
Extend SIP parser class with extension headers.
Definition: sip_parser.c:137
SIP prototypes and macros for each header.
sip_unsupported_t * sip_has_unsupported2(su_home_t *, sip_supported_t const *support, sip_require_t const *by_require, sip_require_t const *require)
Check if required feature is not supported.
Definition: sip_feature.c:364

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