sofia-sip/sip_header.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00025 #ifndef SIP_HEADER_H
00026 
00027 #define SIP_HEADER_H 
00028 
00038 #ifndef SU_ALLOC_H
00039 #include <sofia-sip/su_alloc.h>
00040 #endif
00041 
00042 #ifndef SU_TAG_H
00043 #include <sofia-sip/su_tag.h>
00044 #endif
00045 
00046 #ifndef SIP_H
00047 #include <sofia-sip/sip.h>
00048 #endif
00049 
00050 #ifndef MSG_HEADER_H
00051 #include <sofia-sip/msg_header.h>
00052 #endif
00053 
00054 #ifndef _STRING_H
00055 #include <string.h>
00056 #endif
00057 
00058 SOFIA_BEGIN_DECLS
00059 
00061 SOFIAPUBFUN msg_mclass_t const *sip_default_mclass(void);
00062 
00064 #define sip_is_sip(sip) ((sip) && (sip)->sip_ident == SIP_PROTOCOL_TAG)
00065 
00067 #define SIP_HDR_INIT(name) {{{ 0, 0, sip_##name##_class }}}
00068 
00070 #define SIP_HEADER_INIT(h, sip_class, size)            \
00071   ((void)memset((h), 0, (size)),                       \
00072    (void)(((sip_common_t *)(h))->h_class = (sip_class)),        \
00073    (h))
00074 
00076 SOFIAPUBFUN int sip_serialize(msg_t *msg, sip_t *sip);
00077 
00079 SOFIAPUBFUN issize_t sip_e(sip_t const *sip, int flags, char b[], isize_t size);
00080 
00082 SOFIAPUBFUN int sip_is_header(sip_header_t const *header);
00083 
00085 SOFIAPUBFUN char *sip_header_as_string(su_home_t *home,
00086                                        sip_header_t const *h);
00087 
00089 SOFIAPUBFUN int sip_add_dup(msg_t *, sip_t *, sip_header_t const *);
00090 
00092 SOFIAPUBFUN int sip_add_dup_as(msg_t *msg, sip_t *sip,
00093                                msg_hclass_t *hc, sip_header_t const *o);
00094 
00096 SOFIAPUBFUN int sip_add_headers(msg_t *msg, sip_t *sip, 
00097                                 void const *extra, va_list headers);
00098 
00100 SOFIAPUBFUN int sip_add_tl(msg_t *msg, sip_t *sip,
00101                            tag_type_t tag, tag_value_t value, ...);
00102 
00104 SOFIAPUBFUN int sip_add_tagis(msg_t *, sip_t *, tagi_t const **inout_list);
00105 
00107 SOFIAPUBFUN int sip_add_make(msg_t *, sip_t *, msg_hclass_t *hc, char const *s);
00108 
00110 SOFIAPUBFUN char *sip_headers_as_url_query(su_home_t *home,
00111                                            tag_type_t tag, tag_value_t value,
00112                                            ...);
00113 
00115 SOFIAPUBFUN tagi_t *sip_url_query_as_taglist(su_home_t *home,
00116                                              char const *query,
00117                                              msg_mclass_t const *parser);
00118 
00120 SOFIAPUBFUN int sip_complete_message(msg_t *msg);
00121 
00123 #define sip_fragment_clear(a) ((a)->h_data = NULL, (a)->h_len = 0)
00124 
00125 /* Use __attribute__ to allow argument checking for sip_header_format() */
00126 #if !defined(__GNUC__) && !defined(__attribute__)
00127 #define __attribute__(x) 
00128 #endif
00129 
00131 SOFIAPUBFUN sip_header_t *sip_header_format(su_home_t *home, 
00132                                             msg_hclass_t *hc,
00133                                             char const *fmt,
00134                                             ...)
00135   __attribute__((__format__ (printf, 3, 4)));
00136 
00138 SOFIAPUBFUN sip_time_t sip_now(void);
00139 
00140 SOFIAPUBVAR char const sip_method_name_ack[];
00141 SOFIAPUBVAR char const sip_method_name_bye[];
00142 SOFIAPUBVAR char const sip_method_name_cancel[];
00143 SOFIAPUBVAR char const sip_method_name_invite[];
00144 SOFIAPUBVAR char const sip_method_name_options[];
00145 SOFIAPUBVAR char const sip_method_name_register[];
00146 SOFIAPUBVAR char const sip_method_name_info[];
00147 SOFIAPUBVAR char const sip_method_name_prack[];
00148 SOFIAPUBVAR char const sip_method_name_comet[];
00149 SOFIAPUBVAR char const sip_method_name_message[];
00150 SOFIAPUBVAR char const sip_method_name_subscribe[];
00151 SOFIAPUBVAR char const sip_method_name_notify[];
00152 SOFIAPUBVAR char const sip_method_name_refer[];
00153 
00155 SOFIAPUBVAR char const sip_transport_udp[];
00157 SOFIAPUBVAR char const sip_transport_tcp[];
00159 SOFIAPUBVAR char const sip_transport_sctp[];
00161 SOFIAPUBVAR char const sip_transport_tls[];
00163 SOFIAPUBVAR char const sip_version_2_0[];
00164 
00165 #define SIP_VERSION_CURRENT sip_version_2_0
00166 
00168 SOFIAPUBVAR char const sip_parser_version[];
00169 
00171 #define SIP_PORT(s) ((s) ? (s) : "5060")
00172 
00174 #define SIPS_PORT(s) ((s) ? (s) : "5061")
00175 
00177 SOFIAPUBFUN char const *sip_method_name(sip_method_t method, char const *name);
00178 
00180 SOFIAPUBFUN sip_method_t sip_method_code(char const *name);
00181 
00182 SOFIAPUBVAR char const * const sip_method_names[];
00183 
00184 #define SIP_METHOD_NAME(method, name) \
00185  ((method) == sip_method_unknown ? (name) : sip_method_name(method, name))
00186 
00187 #define sip_header_make(h, c, s) \
00188   ((sip_header_t *)msg_header_make((h), (c), (s)))
00189 #define sip_header_vformat(h, c, f, a) \
00190   ((sip_header_t *)msg_header_vformat((h), (c), (f), (a)))
00191 
00192 SOFIA_END_DECLS
00193 #ifndef SIP_PROTOS_H
00194 #include <sofia-sip/sip_protos.h>
00195 #endif
00196 SOFIA_BEGIN_DECLS
00197 
00199 SOFIAPUBFUN
00200 sip_request_t *sip_request_create(su_home_t *home,
00201                                   sip_method_t method, const char *name,
00202                                   url_string_t const *url,
00203                                   char const *version);
00204 
00206 SOFIAPUBFUN
00207 sip_status_t *sip_status_create(su_home_t *home,
00208                                 unsigned status,
00209                                 char const *phrase,
00210                                 char const *version);
00211 
00213 SOFIAPUBFUN sip_call_id_t *sip_call_id_create(su_home_t *home,
00214                                               char const *domain);
00215 
00217 SOFIAPUBFUN sip_cseq_t *sip_cseq_create(su_home_t *, uint32_t seq, 
00218                                         unsigned method, char const *name);
00219 
00221 SOFIAPUBFUN sip_contact_t * sip_contact_create(su_home_t *, 
00222                                                url_string_t const *url, 
00223                                                char const *param,
00224                                                /* char const *params, */
00225                                                ...);
00226 
00228 SOFIAPUBFUN sip_time_t sip_contact_expires(sip_contact_t const *m,
00229                                            sip_expires_t const *ex,
00230                                            sip_date_t const *date,
00231                                            sip_time_t def,
00232                                            sip_time_t now);
00233 
00235 SOFIAPUBFUN
00236 sip_content_length_t *sip_content_length_create(su_home_t *, uint32_t n);
00237 
00239 SOFIAPUBFUN sip_date_t *sip_date_create(su_home_t *, sip_time_t t);
00240 
00242 SOFIAPUBFUN sip_expires_t *sip_expires_create(su_home_t *, sip_time_t delta);
00243 
00245 SOFIAPUBFUN sip_route_t *sip_route_create(su_home_t *home, url_t const *url, 
00246                                           url_t const *maddr);
00247 
00249 SOFIAPUBFUN sip_record_route_t *sip_record_route_create(su_home_t *,
00250                                                         url_t const *rq_url,
00251                                                         url_t const *m_url);
00252 
00254 SOFIAPUBFUN sip_from_t *sip_from_create(su_home_t *, url_string_t const *url);
00255 
00256 SOFIAPUBFUN int sip_from_tag(su_home_t *, sip_from_t *from, char const *tag);
00257 
00259 SOFIAPUBFUN sip_to_t *sip_to_create(su_home_t *, url_string_t const *url);
00260 
00261 SOFIAPUBFUN int sip_to_tag(su_home_t *, sip_to_t *to, char const *tag);
00262 
00264 SOFIAPUBFUN sip_via_t *sip_via_create(su_home_t *h,
00265                                       char const *host,
00266                                       char const *port, 
00267                                       char const *transport,
00268                                       /* char const *params */
00269                                       ...);
00270 
00272 #if SU_HAVE_INLINE
00273 su_inline char const *sip_via_transport(sip_via_t const *v)
00274 {
00275   char const *tp = v->v_protocol;
00276   if (tp) {
00277     tp = strchr(tp, '/'); 
00278     if (tp) {
00279       tp = strchr(tp + 1, '/');
00280       if (tp)
00281         return tp + 1;
00282     }
00283   }
00284   return NULL;
00285 }
00286 #else
00287 char const *sip_via_transport(sip_via_t const *v);
00288 #endif
00289 
00290 SOFIAPUBFUN char const *sip_via_port(sip_via_t const *v, int *using_rport);
00291 
00292 SOFIAPUBFUN
00293 sip_payload_t *sip_payload_create(su_home_t *, void const *data, isize_t len);
00294 
00312 #define SIP_PAYLOAD_INIT2(data, length) \
00313   {{{ 0, 0, sip_payload_class, data, length }, NULL, data, length }}
00314 
00316 SOFIAPUBFUN sip_separator_t *sip_separator_create(su_home_t *home);
00317 
00319 SOFIAPUBFUN
00320 sip_unsupported_t *sip_has_unsupported(su_home_t *,
00321                                        sip_supported_t const *support, 
00322                                        sip_require_t const *require);
00323 
00324 SOFIAPUBFUN
00325 sip_unsupported_t *sip_has_unsupported2(su_home_t *,
00326                                         sip_supported_t const *support,
00327                                         sip_require_t const *by_require,
00328                                         sip_require_t const *require);
00329 
00330 SOFIAPUBFUN
00331 sip_unsupported_t *
00332 sip_has_unsupported_any(su_home_t *,
00333                         sip_supported_t const *support,
00334                         sip_require_t const *by_require,
00335                         sip_proxy_require_t const *by_proxy_require,
00336                         sip_require_t const *require,
00337                         sip_require_t const *require2,
00338                         sip_require_t const *require3);
00339 
00341 SOFIAPUBFUN
00342 int sip_has_supported(sip_supported_t const *support, char const *feature);
00343 
00345 SOFIAPUBFUN
00346 int sip_has_feature(msg_list_t const *supported, char const *feature);
00347 
00349 SOFIAPUBFUN int sip_is_allowed(sip_allow_t const *allow, 
00350                                sip_method_t method, char const *name);
00351 
00353 #define SIP_IS_ALLOWED(allow, method) \
00354   (sip_method_unknown < (method) && (method) < 32 && \
00355    (allow) && ((allow)->k_bitmap & (1 << (method))) != 0)
00356 
00357 /* ---------------------------------------------------------------------------
00358  * Bitmasks for header classifications
00359  */
00360 enum {
00361   sip_mask_request = 1,
00362   sip_mask_response = 2,
00363   sip_mask_ua = 4,
00364   sip_mask_proxy = 8,
00365   sip_mask_registrar = 16,
00366   sip_mask_100rel = 32,
00367   sip_mask_events = 64,
00368   sip_mask_timer = 128,
00369   sip_mask_privacy = 256,
00370   sip_mask_pref = 512,
00371   sip_mask_publish = 1024
00372 };
00373 
00374 /* ------------------------------------------------------------------------- */
00375 
00376 /* Here are @deprecated functions and names for compatibility */
00377 
00379 SOFIAPUBFUN issize_t sip_header_e(char[], isize_t, sip_header_t const *, int);
00380 
00382 SOFIAPUBFUN
00383 sip_header_t *sip_header_d(su_home_t *, msg_t const *, char const *);
00384 
00386 SOFIAPUBFUN issize_t sip_header_field_e(char[], isize_t, sip_header_t const *, int);
00387 
00389 SOFIAPUBFUN issize_t sip_header_field_d(su_home_t *, sip_header_t *, char *, isize_t);
00390 
00392 SOFIAPUBFUN isize_t sip_header_size(sip_header_t const *h);
00393 
00395 SOFIAPUBFUN sip_header_t *sip_header_dup(su_home_t *, sip_header_t const *);
00396 
00398 SOFIAPUBFUN sip_header_t *sip_header_copy(su_home_t *, sip_header_t const *o);
00399 
00401 SOFIAPUBFUN int sip_allow_events_add(su_home_t *, 
00402                                      sip_allow_events_t *ae, 
00403                                      char const *e);
00404 
00406 SOFIAPUBFUN int sip_contact_add_param(su_home_t *, sip_contact_t *,
00407                                       char const *param);
00408 
00409 SOFIAPUBFUN int sip_to_add_param(su_home_t *, sip_to_t *, char const *);
00410 
00411 SOFIAPUBFUN int sip_from_add_param(su_home_t *, sip_from_t *, char const *);
00412 
00414 SOFIAPUBFUN int sip_via_add_param(su_home_t *, sip_via_t *, char const *);
00415 
00416 #define sip_from_make_url     sip_from_create
00417 #define sip_to_make_url       sip_to_create
00418 #define sip_params_find       msg_params_find
00419 
00420 SOFIA_END_DECLS
00421 
00422 #endif 

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