sip  1.12.11devel
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 
67 #define sip_is_sip(sip) ((sip) && (sip)->sip_ident == SIP_PROTOCOL_TAG)
68 
70 #define SIP_HDR_INIT(name) {{{ 0, 0, sip_##name##_class }}}
71 
73 #define SIP_HEADER_INIT(h, sip_class, size) \
74  ((void)memset((h), 0, (size)), \
75  (void)(((sip_common_t *)(h))->h_class = (sip_class)), \
76  (h))
77 
79 SOFIAPUBFUN int sip_serialize(msg_t *msg, sip_t *sip);
80 
82 SOFIAPUBFUN issize_t sip_e(sip_t const *sip, int flags, char b[], isize_t size);
83 
85 SOFIAPUBFUN int sip_is_header(sip_header_t const *header);
86 
89  sip_header_t const *h);
90 
93 
95 SOFIAPUBFUN int sip_add_dup_as(msg_t *msg, sip_t *sip,
96  msg_hclass_t *hc, sip_header_t const *o);
97 
99 SOFIAPUBFUN int sip_add_headers(msg_t *msg, sip_t *sip,
100  void const *extra, va_list headers);
101 
103 SOFIAPUBFUN int sip_add_tl(msg_t *msg, sip_t *sip,
104  tag_type_t tag, tag_value_t value, ...);
105 
107 SOFIAPUBFUN int sip_add_tagis(msg_t *, sip_t *, tagi_t const **inout_list);
108 
110 SOFIAPUBFUN int sip_add_make(msg_t *, sip_t *, msg_hclass_t *hc, char const *s);
111 
114  tag_type_t tag, tag_value_t value,
115  ...);
116 
119  char const *query,
120  msg_mclass_t const *parser);
121 
124 
126 #define sip_fragment_clear(a) ((a)->h_data = NULL, (a)->h_len = 0)
127 
128 /* Use __attribute__ to allow argument checking for sip_header_format() */
129 #if !defined(__GNUC__) && !defined(__attribute__)
130 #define __attribute__(x)
131 #endif
132 
135  msg_hclass_t *hc,
136  char const *fmt,
137  ...)
138  __attribute__((__format__ (printf, 3, 4)));
139 
141 SOFIAPUBFUN sip_time_t sip_now(void);
142 
143 SOFIAPUBVAR char const sip_method_name_ack[];
144 SOFIAPUBVAR char const sip_method_name_bye[];
145 SOFIAPUBVAR char const sip_method_name_cancel[];
146 SOFIAPUBVAR char const sip_method_name_invite[];
147 SOFIAPUBVAR char const sip_method_name_options[];
148 SOFIAPUBVAR char const sip_method_name_register[];
149 SOFIAPUBVAR char const sip_method_name_info[];
150 SOFIAPUBVAR char const sip_method_name_prack[];
151 SOFIAPUBVAR char const sip_method_name_comet[];
152 SOFIAPUBVAR char const sip_method_name_message[];
153 SOFIAPUBVAR char const sip_method_name_subscribe[];
154 SOFIAPUBVAR char const sip_method_name_notify[];
155 SOFIAPUBVAR char const sip_method_name_refer[];
156 
158 SOFIAPUBVAR char const sip_transport_udp[];
160 SOFIAPUBVAR char const sip_transport_tcp[];
162 SOFIAPUBVAR char const sip_transport_sctp[];
164 SOFIAPUBVAR char const sip_transport_tls[];
166 SOFIAPUBVAR char const sip_version_2_0[];
167 
168 #define SIP_VERSION_CURRENT sip_version_2_0
169 
171 SOFIAPUBVAR char const sip_parser_version[];
172 
174 #define SIP_PORT(s) ((s) ? (s) : "5060")
175 
177 #define SIPS_PORT(s) ((s) ? (s) : "5061")
178 
180 SOFIAPUBFUN char const *sip_method_name(sip_method_t method, char const *name);
181 
183 SOFIAPUBFUN sip_method_t sip_method_code(char const *name);
184 
185 SOFIAPUBVAR char const * const sip_method_names[];
186 
187 #define SIP_METHOD_NAME(method, name) \
188  ((method) == sip_method_unknown ? (name) : sip_method_name(method, name))
189 
190 #define sip_header_make(h, c, s) \
191  ((sip_header_t *)msg_header_make((h), (c), (s)))
192 #define sip_header_vformat(h, c, f, a) \
193  ((sip_header_t *)msg_header_vformat((h), (c), (f), (a)))
194 
195 SOFIA_END_DECLS
196 #ifndef SIP_PROTOS_H
197 #include <sofia-sip/sip_protos.h>
198 #endif
199 SOFIA_BEGIN_DECLS
200 
204  sip_method_t method, const char *name,
205  url_string_t const *url,
206  char const *version);
207 
211  unsigned status,
212  char const *phrase,
213  char const *version);
214 
217  char const *domain);
218 
221  unsigned method, char const *name);
222 
225  url_string_t const *url,
226  char const *param,
227  /* char const *params, */
228  ...);
229 
232  sip_expires_t const *ex,
233  sip_date_t const *date,
234  sip_time_t def,
235  sip_time_t now);
236 
240 
243 
246 
249  url_t const *maddr);
250 
253  url_t const *rq_url,
254  url_t const *m_url);
255 
258 
259 SOFIAPUBFUN int sip_from_tag(su_home_t *, sip_from_t *from, char const *tag);
260 
263 
264 SOFIAPUBFUN int sip_to_tag(su_home_t *, sip_to_t *to, char const *tag);
265 
268  char const *host,
269  char const *port,
270  char const *transport,
271  /* char const *params */
272  ...);
273 
275 #if SU_HAVE_INLINE
276 su_inline char const *sip_via_transport(sip_via_t const *v)
277 {
278  char const *tp = v->v_protocol;
279  if (tp) {
280  tp = strchr(tp, '/');
281  if (tp) {
282  tp = strchr(tp + 1, '/');
283  if (tp)
284  return tp + 1;
285  }
286  }
287  return NULL;
288 }
289 #else
290 char const *sip_via_transport(sip_via_t const *v);
291 #endif
292 
293 SOFIAPUBFUN char const *sip_via_port(sip_via_t const *v, int *using_rport);
294 
296 sip_payload_t *sip_payload_create(su_home_t *, void const *data, isize_t len);
297 
315 #define SIP_PAYLOAD_INIT2(data, length) \
316  {{{ 0, 0, sip_payload_class, data, length }, NULL, data, length }}
317 
320 
324  sip_supported_t const *support,
325  sip_require_t const *require);
326 
329  sip_supported_t const *support,
330  sip_require_t const *by_require,
331  sip_require_t const *require);
332 
336  sip_supported_t const *support,
337  sip_require_t const *by_require,
338  sip_proxy_require_t const *by_proxy_require,
339  sip_require_t const *require,
340  sip_require_t const *require2,
341  sip_require_t const *require3);
342 
345 int sip_has_supported(sip_supported_t const *support, char const *feature);
346 
349 int sip_has_feature(msg_list_t const *supported, char const *feature);
350 
352 SOFIAPUBFUN int sip_is_allowed(sip_allow_t const *allow,
353  sip_method_t method, char const *name);
354 
356 #define SIP_IS_ALLOWED(allow, method) \
357  (sip_method_unknown < (method) && (method) < 32 && \
358  (allow) && ((allow)->k_bitmap & (1 << (method))) != 0)
359 
380  sip_mask_request = (1 << 0),
381 
387  sip_mask_response = (1 << 1),
388 
394  sip_mask_ua = (1 << 2),
395 
401  sip_mask_proxy = (1 << 3),
402 
409  sip_mask_registrar = (1 << 4),
410 
417  sip_mask_100rel = (1 << 5),
418 
425  sip_mask_events = (1 << 6),
426 
433  sip_mask_timer = (1 << 7),
434 
441  sip_mask_privacy = (1 << 8),
442 
449  sip_mask_pref = (1 << 9),
450 
457  sip_mask_publish = (1 << 10)
458 
459  /* NOTE:
460  * When adding bits, please update nta_agent_create() and
461  * NTATAG_BAD_RESP_MASK()/NTATAG_BAD_REQ_MASK() documentation.
462  */
463 };
464 
465 /* ------------------------------------------------------------------------- */
466 
467 /* Here are @deprecated functions and names for compatibility */
468 
470 SOFIAPUBFUN issize_t sip_header_e(char[], isize_t, sip_header_t const *, int);
471 
474 sip_header_t *sip_header_d(su_home_t *, msg_t const *, char const *);
475 
477 SOFIAPUBFUN issize_t sip_header_field_e(char[], isize_t, sip_header_t const *, int);
478 
480 SOFIAPUBFUN issize_t sip_header_field_d(su_home_t *, sip_header_t *, char *, isize_t);
481 
483 SOFIAPUBFUN isize_t sip_header_size(sip_header_t const *h);
484 
487 
490 
493  sip_allow_events_t *ae,
494  char const *e);
495 
498  char const *param);
499 
500 SOFIAPUBFUN int sip_to_add_param(su_home_t *, sip_to_t *, char const *);
501 
502 SOFIAPUBFUN int sip_from_add_param(su_home_t *, sip_from_t *, char const *);
503 
505 SOFIAPUBFUN int sip_via_add_param(su_home_t *, sip_via_t *, char const *);
506 
507 #define sip_from_make_url sip_from_create
508 #define sip_to_make_url sip_to_create
509 #define sip_params_find msg_params_find
510 
511 SOFIA_END_DECLS
512 
513 #endif
Bit marking essential headers for caller preference extension.
Definition: sip_header.h:449
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:488
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:365
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:396
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:488
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:471
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:1832
char const * sip_via_transport(sip_via_t const *v)
Get transport protocol name.
Definition: sip_header.h:276
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:457
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:374
sip_from_t * sip_from_create(su_home_t *, url_string_t const *url)
Create a From header object.
Definition: sip_basic.c:1814
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:105
int sip_update_default_mclass(msg_mclass_t const *mclass)
Update the default SIP parser.
Definition: sip_parser.c:98
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:2679
char const *const sip_method_names[]
Well-known SIP method names.
Definition: sip_parser.c:316
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:381
Bit marking essential headers in a response message.
Definition: sip_header.h:387
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:114
sip_expires_t * sip_expires_create(su_home_t *, sip_time_t delta)
Create an Expires header object.
Definition: sip_basic.c:1735
Structure for Allow header field.
Definition: sip.h:414
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:756
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:394
Structure for SIP status line.
Definition: sip.h:369
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:1488
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:460
sip_to_t * sip_to_create(su_home_t *, url_string_t const *url)
Create a To header object.
Definition: sip_basic.c:2427
Bit marking essential headers for 100rel extension.
Definition: sip_header.h:417
Structure for SIP request line.
Definition: sip.h:356
char const * sip_method_name(sip_method_t method, char const *name)
Return string corresponding to the method.
Definition: sip_parser.c:337
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:346
#define SOFIAPUBVAR
sip_date_t * sip_date_create(su_home_t *, sip_time_t t)
Create an Date header object.
Definition: sip_basic.c:1651
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:428
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:2705
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:449
Bit marking essential headers for session timer extension.
Definition: sip_header.h:433
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:2754
Bit marking essential headers for registrar server.
Definition: sip_header.h:409
Bit marking essential headers in a request message.
Definition: sip_header.h:380
Structure for Contact header field.
Definition: sip.h:472
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:441
Structure for Call-ID (and In-Reply-To) header fields.
Definition: sip.h:438
Bit marking essential headers for User-Agent.
Definition: sip_header.h:394
Structure for Via header field.
Definition: sip.h:752
int sip_complete_message(msg_t *msg)
Complete SIP message.
Definition: sip_parser.c:600
msg_mclass_t const * sip_default_mclass(void)
Return a built-in SIP parser object.
Definition: sip_parser.c:69
Structure for Date header.
Definition: sip.h:513
SIP message object.
Definition: sip.h:230
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:2447
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:2282
Bit marking essential headers for proxy server.
Definition: sip_header.h:401
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:2357
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:1855
sip_content_length_t * sip_content_length_create(su_home_t *, uint32_t n)
Create a Content-Length header object.
Definition: sip_basic.c:1565
Bit marking essential headers for SIP events.
Definition: sip_header.h:425
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 Route and Record-Route header fields.
Definition: sip.h:680
Structure for Expires header.
Definition: sip.h:546
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:127
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:362

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