sip  1.13.17
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
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 
71 
74 
76 #define sip_is_sip(sip) ((sip) && (sip)->sip_ident == SIP_PROTOCOL_TAG)
77 
79 #define SIP_HDR_INIT(name) {{{ 0, 0, sip_##name##_class }}}
80 
82 #define SIP_HEADER_INIT(h, sip_class, size) \
83  ((void)memset((h), 0, (size)), \
84  (void)(((sip_common_t *)(h))->h_class = (sip_class)), \
85  (h))
86 
89 
91 SOFIAPUBFUN issize_t sip_e(sip_t const *sip, int flags, char b[], isize_t size);
92 
95 
98  sip_header_t const *h);
99 
101 SOFIAPUBFUN int sip_add_dup(msg_t *, sip_t *, sip_header_t const *);
102 
104 SOFIAPUBFUN int sip_add_dup_as(msg_t *msg, sip_t *sip,
105  msg_hclass_t *hc, sip_header_t const *o);
106 
109  void const *extra, va_list headers);
110 
112 SOFIAPUBFUN int sip_add_tl(msg_t *msg, sip_t *sip,
113  tag_type_t tag, tag_value_t value, ...);
114 
116 SOFIAPUBFUN int sip_add_tagis(msg_t *, sip_t *, tagi_t const **inout_list);
117 
119 SOFIAPUBFUN int sip_add_make(msg_t *, sip_t *, msg_hclass_t *hc, char const *s);
120 
123  tag_type_t tag, tag_value_t value,
124  ...);
125 
128  char const *query,
129  msg_mclass_t const *parser);
130 
133 
135 #define sip_fragment_clear(a) ((a)->h_data = NULL, (a)->h_len = 0)
136 
137 /* Use __attribute__ to allow argument checking for sip_header_format() */
138 #if !defined(__GNUC__) && !defined(__attribute__)
139 #define __attribute__(x)
140 #endif
141 
144  msg_hclass_t *hc,
145  char const *fmt,
146  ...)
147  __attribute__((__format__ (printf, 3, 4)));
148 
150 SOFIAPUBFUN sip_time_t sip_now(void);
151 
152 SOFIAPUBVAR char const sip_method_name_ack[];
153 SOFIAPUBVAR char const sip_method_name_bye[];
154 SOFIAPUBVAR char const sip_method_name_cancel[];
155 SOFIAPUBVAR char const sip_method_name_invite[];
156 SOFIAPUBVAR char const sip_method_name_options[];
157 SOFIAPUBVAR char const sip_method_name_register[];
158 SOFIAPUBVAR char const sip_method_name_info[];
159 SOFIAPUBVAR char const sip_method_name_prack[];
160 SOFIAPUBVAR char const sip_method_name_comet[];
161 SOFIAPUBVAR char const sip_method_name_message[];
162 SOFIAPUBVAR char const sip_method_name_subscribe[];
163 SOFIAPUBVAR char const sip_method_name_notify[];
164 SOFIAPUBVAR char const sip_method_name_refer[];
165 
167 SOFIAPUBVAR char const sip_transport_udp[];
169 SOFIAPUBVAR char const sip_transport_tcp[];
171 SOFIAPUBVAR char const sip_transport_sctp[];
173 SOFIAPUBVAR char const sip_transport_tls[];
175 SOFIAPUBVAR char const sip_transport_ws[];
177 SOFIAPUBVAR char const sip_transport_wss[];
179 SOFIAPUBVAR char const sip_version_2_0[];
180 
181 #define SIP_VERSION_CURRENT sip_version_2_0
182 
184 SOFIAPUBVAR char const sip_parser_version[];
185 
187 #define SIP_PORT(s) ((s) ? (s) : "5060")
188 
190 #define SIPS_PORT(s) ((s) ? (s) : "5061")
191 
193 SOFIAPUBFUN char const *sip_method_name(sip_method_t method, char const *name);
194 
196 SOFIAPUBFUN sip_method_t sip_method_code(char const *name);
197 
198 SOFIAPUBVAR char const * const sip_method_names[];
199 
200 #define SIP_METHOD_NAME(method, name) \
201  ((method) == sip_method_unknown ? (name) : sip_method_name(method, name))
202 
203 #define sip_header_make(h, c, s) \
204  ((sip_header_t *)msg_header_make((h), (c), (s)))
205 #define sip_header_vformat(h, c, f, a) \
206  ((sip_header_t *)msg_header_vformat((h), (c), (f), (a)))
207 
208 SOFIA_END_DECLS
209 #ifndef SIP_PROTOS_H
210 #include <sofia-sip/sip_protos.h>
211 #endif
212 SOFIA_BEGIN_DECLS
213 
217  sip_method_t method, const char *name,
218  url_string_t const *url,
219  char const *version);
220 
224  unsigned status,
225  char const *phrase,
226  char const *version);
227 
230  char const *domain);
231 
234  unsigned method, char const *name);
235 
238  url_string_t const *url,
239  char const *param,
240  /* char const *params, */
241  ...);
242 
245  sip_expires_t const *ex,
246  sip_date_t const *date,
247  sip_time_t def,
248  sip_time_t now);
249 
253 
256 
259 
262  url_t const *maddr);
263 
266  url_t const *rq_url,
267  url_t const *m_url);
268 
271 
272 SOFIAPUBFUN int sip_from_tag(su_home_t *, sip_from_t *from, char const *tag);
273 
276 
277 SOFIAPUBFUN int sip_to_tag(su_home_t *, sip_to_t *to, char const *tag);
278 
281  char const *host,
282  char const *port,
283  char const *transport,
284  /* char const *params */
285  ...);
286 
288 #if SU_HAVE_INLINE
289 su_inline char const *sip_via_transport(sip_via_t const *v)
290 {
291  char const *tp = v->v_protocol;
292  if (tp) {
293  tp = strchr(tp, '/');
294  if (tp) {
295  tp = strchr(tp + 1, '/');
296  if (tp)
297  return tp + 1;
298  }
299  }
300  return NULL;
301 }
302 #else
303 char const *sip_via_transport(sip_via_t const *v);
304 #endif
305 
306 SOFIAPUBFUN char const *sip_via_port(sip_via_t const *v, int *using_rport);
307 
309 sip_payload_t *sip_payload_create(su_home_t *, void const *data, isize_t len);
310 
328 #define SIP_PAYLOAD_INIT2(data, length) \
329  {{{ 0, 0, sip_payload_class, data, length }}, NULL, data, length }
330 
333 
337  sip_supported_t const *support,
338  sip_require_t const *require);
339 
342  sip_supported_t const *support,
343  sip_require_t const *by_require,
344  sip_require_t const *require);
345 
349  sip_supported_t const *support,
350  sip_require_t const *by_require,
351  sip_proxy_require_t const *by_proxy_require,
352  sip_require_t const *require,
353  sip_require_t const *require2,
354  sip_require_t const *require3);
355 
358 int sip_has_supported(sip_supported_t const *support, char const *feature);
359 
362 int sip_has_feature(msg_list_t const *supported, char const *feature);
363 
365 SOFIAPUBFUN int sip_is_allowed(sip_allow_t const *allow,
366  sip_method_t method, char const *name);
367 
369 #define SIP_IS_ALLOWED(allow, method) \
370  (sip_method_unknown < (method) && (method) < 32 && \
371  (allow) && ((allow)->k_bitmap & (1 << (method))) != 0)
372 
393  sip_mask_request = (1 << 0),
394 
400  sip_mask_response = (1 << 1),
401 
407  sip_mask_ua = (1 << 2),
408 
414  sip_mask_proxy = (1 << 3),
415 
422  sip_mask_registrar = (1 << 4),
423 
430  sip_mask_100rel = (1 << 5),
431 
438  sip_mask_events = (1 << 6),
439 
446  sip_mask_timer = (1 << 7),
447 
454  sip_mask_privacy = (1 << 8),
455 
462  sip_mask_pref = (1 << 9),
463 
470  sip_mask_publish = (1 << 10)
471 
472  /* NOTE:
473  * When adding bits, please update nta_agent_create() and
474  * NTATAG_BAD_RESP_MASK()/NTATAG_BAD_REQ_MASK() documentation.
475  */
476 };
477 
478 /* ------------------------------------------------------------------------- */
479 
480 /* Here are @deprecated functions and names for compatibility */
481 
483 SOFIAPUBFUN issize_t sip_header_e(char[], isize_t, sip_header_t const *, int);
484 
487 sip_header_t *sip_header_d(su_home_t *, msg_t const *, char const *);
488 
490 SOFIAPUBFUN issize_t sip_header_field_e(char[], isize_t, sip_header_t const *, int);
491 
493 SOFIAPUBFUN issize_t sip_header_field_d(su_home_t *, sip_header_t *, char *, isize_t);
494 
496 SOFIAPUBFUN isize_t sip_header_size(sip_header_t const *h);
497 
500 
503 
506  sip_allow_events_t *ae,
507  char const *e);
508 
511  char const *param);
512 
513 SOFIAPUBFUN int sip_to_add_param(su_home_t *, sip_to_t *, char const *);
514 
515 SOFIAPUBFUN int sip_from_add_param(su_home_t *, sip_from_t *, char const *);
516 
518 SOFIAPUBFUN int sip_via_add_param(su_home_t *, sip_via_t *, char const *);
519 
520 #define sip_from_make_url sip_from_create
521 #define sip_to_make_url sip_to_create
522 #define sip_params_find msg_params_find
523 
524 SOFIA_END_DECLS
525 
526 #endif
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
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_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
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
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
sip_date_t * sip_date_create(su_home_t *, sip_time_t t)
Create an Date header object.
Definition: sip_basic.c:1656
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
sip_expires_t * sip_expires_create(su_home_t *, sip_time_t delta)
Create an Expires header object.
Definition: sip_basic.c:1740
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_from_t * sip_from_create(su_home_t *, url_string_t const *url)
Create a From header object.
Definition: sip_basic.c:1819
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
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
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
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
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
sip_separator_t * sip_separator_create(su_home_t *home)
Create a SIP separator line structure.
Definition: sip_basic.c:514
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
sip_to_t * sip_to_create(su_home_t *, url_string_t const *url)
Create a To header object.
Definition: sip_basic.c:2438
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
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
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
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
struct msg_hclass_s const msg_hclass_t
SIP objects.
msg_time_t sip_time_t
Time in seconds since Jan 01 1900.
Definition: sip.h:113
union sip_header_u sip_header_t
Any SIP header - union of all possible SIP headers.
Definition: sip.h:122
sip_method_t
IDs for well-known SIP methods.
Definition: sip.h:48
issize_t sip_header_field_e(char[], isize_t, sip_header_t const *, int)
Encode contents of a SIP header field.
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
char const * sip_method_name(sip_method_t method, char const *name)
Return string corresponding to the method.
Definition: sip_parser.c:378
char const sip_version_2_0[]
SIP version 2.0.
Definition: sip_parser.c:61
void sip_default_mclass_restore(void)
Restore default SIP parser to non-extended.
Definition: sip_parser.c:76
int sip_is_header(sip_header_t const *header)
Test if header is a pointer to a SIP header object.
void sip_cloned_parser_destroy(void)
Release SIP parser object if it was cloned.
Definition: sip_parser.c:95
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_time_t sip_now(void)
Return current time.
Definition: sip_time.c:49
int sip_has_supported(sip_supported_t const *support, char const *feature)
Check that a feature is supported.
Definition: sip_feature.c:490
char const * sip_via_transport(sip_via_t const *v)
Get transport protocol name.
Definition: sip_header.h:289
sip_method_t sip_method_code(char const *name)
Return code corresponding to the method code.
Definition: sip_parser.c:490
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:442
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
void sip_destroy_mclass(msg_mclass_t *mclass)
Destroy SIP parser object.
Definition: sip_parser.c:81
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
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
msg_mclass_t const * sip_default_mclass(void)
Return a built-in SIP parser object.
Definition: sip_parser.c:70
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
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
msg_mclass_t * sip_extend_mclass(msg_mclass_t *input)
Extend SIP parser class with extension headers.
Definition: sip_parser.c:165
int sip_complete_message(msg_t *msg)
Complete SIP message.
Definition: sip_parser.c:661
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
issize_t sip_e(sip_t const *sip, int flags, char b[], isize_t size)
Encode a SIP message.
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_bad_mask
Bitmasks for header classifications.
Definition: sip_header.h:387
@ sip_mask_request
Bit marking essential headers in a request message.
Definition: sip_header.h:393
@ sip_mask_privacy
Bit marking essential headers for privacy extension.
Definition: sip_header.h:454
@ sip_mask_events
Bit marking essential headers for SIP events.
Definition: sip_header.h:438
@ sip_mask_proxy
Bit marking essential headers for proxy server.
Definition: sip_header.h:414
@ sip_mask_timer
Bit marking essential headers for session timer extension.
Definition: sip_header.h:446
@ sip_mask_pref
Bit marking essential headers for caller preference extension.
Definition: sip_header.h:462
@ sip_mask_registrar
Bit marking essential headers for registrar server.
Definition: sip_header.h:422
@ sip_mask_publish
Bit marking essential headers for PUBLISH servers and clients.
Definition: sip_header.h:470
@ sip_mask_100rel
Bit marking essential headers for 100rel extension.
Definition: sip_header.h:430
@ sip_mask_ua
Bit marking essential headers for User-Agent.
Definition: sip_header.h:407
@ sip_mask_response
Bit marking essential headers in a response message.
Definition: sip_header.h:400
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
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
int sip_serialize(msg_t *msg, sip_t *sip)
Serialize headers into the fragment chain.
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
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
char const sip_parser_version[]
SIP parser version.
Definition: sip_parser.c:58
int sip_add_headers(msg_t *msg, sip_t *sip, void const *extra, va_list headers)
Add duplicates of headers to the SIP message.
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
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_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
char const *const sip_method_names[]
Well-known SIP method names.
Definition: sip_parser.c:357
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_update_default_mclass(msg_mclass_t const *mclass)
Update the default SIP parser.
Definition: sip_parser.c:136
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:397
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
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
SIP prototypes and macros for each header.
Structure for From and To headers.
Definition: sip.h:394
Structure for Allow header field.
Definition: sip.h:427
Structure for Call-ID (and In-Reply-To) header fields.
Definition: sip.h:450
Structure for Contact header field.
Definition: sip.h:500
Structure for Content-Length header.
Definition: sip.h:516
Structure for CSeq header.
Definition: sip.h:473
Structure for Date header.
Definition: sip.h:541
Structure for Expires header.
Definition: sip.h:574
Structure for SIP request line.
Definition: sip.h:369
Structure for Route and Record-Route header fields.
Definition: sip.h:708
SIP message object.
Definition: sip.h:241
Structure for SIP status line.
Definition: sip.h:382
Structure for Via header field.
Definition: sip.h:780
char const * v_protocol
Application and transport protocol.
Definition: sip.h:783
SU_HOME_T su_home_t
#define SOFIAPUBFUN
#define SOFIAPUBVAR
#define su_inline
intptr_t tag_value_t
struct tag_type_s const * tag_type_t
SU_U32_T uint32_t

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