sip 1.12.10
|
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 00063 SOFIAPUBFUN int sip_update_default_mclass(msg_mclass_t const *mclass); 00064 SOFIAPUBFUN msg_mclass_t *sip_extend_mclass(msg_mclass_t *input); 00065 00067 #define sip_is_sip(sip) ((sip) && (sip)->sip_ident == SIP_PROTOCOL_TAG) 00068 00070 #define SIP_HDR_INIT(name) {{{ 0, 0, sip_##name##_class }}} 00071 00073 #define SIP_HEADER_INIT(h, sip_class, size) \ 00074 ((void)memset((h), 0, (size)), \ 00075 (void)(((sip_common_t *)(h))->h_class = (sip_class)), \ 00076 (h)) 00077 00079 SOFIAPUBFUN int sip_serialize(msg_t *msg, sip_t *sip); 00080 00082 SOFIAPUBFUN issize_t sip_e(sip_t const *sip, int flags, char b[], isize_t size); 00083 00085 SOFIAPUBFUN int sip_is_header(sip_header_t const *header); 00086 00088 SOFIAPUBFUN char *sip_header_as_string(su_home_t *home, 00089 sip_header_t const *h); 00090 00092 SOFIAPUBFUN int sip_add_dup(msg_t *, sip_t *, sip_header_t const *); 00093 00095 SOFIAPUBFUN int sip_add_dup_as(msg_t *msg, sip_t *sip, 00096 msg_hclass_t *hc, sip_header_t const *o); 00097 00099 SOFIAPUBFUN int sip_add_headers(msg_t *msg, sip_t *sip, 00100 void const *extra, va_list headers); 00101 00103 SOFIAPUBFUN int sip_add_tl(msg_t *msg, sip_t *sip, 00104 tag_type_t tag, tag_value_t value, ...); 00105 00107 SOFIAPUBFUN int sip_add_tagis(msg_t *, sip_t *, tagi_t const **inout_list); 00108 00110 SOFIAPUBFUN int sip_add_make(msg_t *, sip_t *, msg_hclass_t *hc, char const *s); 00111 00113 SOFIAPUBFUN char *sip_headers_as_url_query(su_home_t *home, 00114 tag_type_t tag, tag_value_t value, 00115 ...); 00116 00118 SOFIAPUBFUN tagi_t *sip_url_query_as_taglist(su_home_t *home, 00119 char const *query, 00120 msg_mclass_t const *parser); 00121 00123 SOFIAPUBFUN int sip_complete_message(msg_t *msg); 00124 00126 #define sip_fragment_clear(a) ((a)->h_data = NULL, (a)->h_len = 0) 00127 00128 /* Use __attribute__ to allow argument checking for sip_header_format() */ 00129 #if !defined(__GNUC__) && !defined(__attribute__) 00130 #define __attribute__(x) 00131 #endif 00132 00134 SOFIAPUBFUN sip_header_t *sip_header_format(su_home_t *home, 00135 msg_hclass_t *hc, 00136 char const *fmt, 00137 ...) 00138 __attribute__((__format__ (printf, 3, 4))); 00139 00141 SOFIAPUBFUN sip_time_t sip_now(void); 00142 00143 SOFIAPUBVAR char const sip_method_name_ack[]; 00144 SOFIAPUBVAR char const sip_method_name_bye[]; 00145 SOFIAPUBVAR char const sip_method_name_cancel[]; 00146 SOFIAPUBVAR char const sip_method_name_invite[]; 00147 SOFIAPUBVAR char const sip_method_name_options[]; 00148 SOFIAPUBVAR char const sip_method_name_register[]; 00149 SOFIAPUBVAR char const sip_method_name_info[]; 00150 SOFIAPUBVAR char const sip_method_name_prack[]; 00151 SOFIAPUBVAR char const sip_method_name_comet[]; 00152 SOFIAPUBVAR char const sip_method_name_message[]; 00153 SOFIAPUBVAR char const sip_method_name_subscribe[]; 00154 SOFIAPUBVAR char const sip_method_name_notify[]; 00155 SOFIAPUBVAR char const sip_method_name_refer[]; 00156 00158 SOFIAPUBVAR char const sip_transport_udp[]; 00160 SOFIAPUBVAR char const sip_transport_tcp[]; 00162 SOFIAPUBVAR char const sip_transport_sctp[]; 00164 SOFIAPUBVAR char const sip_transport_tls[]; 00166 SOFIAPUBVAR char const sip_version_2_0[]; 00167 00168 #define SIP_VERSION_CURRENT sip_version_2_0 00169 00171 SOFIAPUBVAR char const sip_parser_version[]; 00172 00174 #define SIP_PORT(s) ((s) ? (s) : "5060") 00175 00177 #define SIPS_PORT(s) ((s) ? (s) : "5061") 00178 00180 SOFIAPUBFUN char const *sip_method_name(sip_method_t method, char const *name); 00181 00183 SOFIAPUBFUN sip_method_t sip_method_code(char const *name); 00184 00185 SOFIAPUBVAR char const * const sip_method_names[]; 00186 00187 #define SIP_METHOD_NAME(method, name) \ 00188 ((method) == sip_method_unknown ? (name) : sip_method_name(method, name)) 00189 00190 #define sip_header_make(h, c, s) \ 00191 ((sip_header_t *)msg_header_make((h), (c), (s))) 00192 #define sip_header_vformat(h, c, f, a) \ 00193 ((sip_header_t *)msg_header_vformat((h), (c), (f), (a))) 00194 00195 SOFIA_END_DECLS 00196 #ifndef SIP_PROTOS_H 00197 #include <sofia-sip/sip_protos.h> 00198 #endif 00199 SOFIA_BEGIN_DECLS 00200 00202 SOFIAPUBFUN 00203 sip_request_t *sip_request_create(su_home_t *home, 00204 sip_method_t method, const char *name, 00205 url_string_t const *url, 00206 char const *version); 00207 00209 SOFIAPUBFUN 00210 sip_status_t *sip_status_create(su_home_t *home, 00211 unsigned status, 00212 char const *phrase, 00213 char const *version); 00214 00216 SOFIAPUBFUN sip_call_id_t *sip_call_id_create(su_home_t *home, 00217 char const *domain); 00218 00220 SOFIAPUBFUN sip_cseq_t *sip_cseq_create(su_home_t *, uint32_t seq, 00221 unsigned method, char const *name); 00222 00224 SOFIAPUBFUN sip_contact_t * sip_contact_create(su_home_t *, 00225 url_string_t const *url, 00226 char const *param, 00227 /* char const *params, */ 00228 ...); 00229 00231 SOFIAPUBFUN sip_time_t sip_contact_expires(sip_contact_t const *m, 00232 sip_expires_t const *ex, 00233 sip_date_t const *date, 00234 sip_time_t def, 00235 sip_time_t now); 00236 00238 SOFIAPUBFUN 00239 sip_content_length_t *sip_content_length_create(su_home_t *, uint32_t n); 00240 00242 SOFIAPUBFUN sip_date_t *sip_date_create(su_home_t *, sip_time_t t); 00243 00245 SOFIAPUBFUN sip_expires_t *sip_expires_create(su_home_t *, sip_time_t delta); 00246 00248 SOFIAPUBFUN sip_route_t *sip_route_create(su_home_t *home, url_t const *url, 00249 url_t const *maddr); 00250 00252 SOFIAPUBFUN sip_record_route_t *sip_record_route_create(su_home_t *, 00253 url_t const *rq_url, 00254 url_t const *m_url); 00255 00257 SOFIAPUBFUN sip_from_t *sip_from_create(su_home_t *, url_string_t const *url); 00258 00259 SOFIAPUBFUN int sip_from_tag(su_home_t *, sip_from_t *from, char const *tag); 00260 00262 SOFIAPUBFUN sip_to_t *sip_to_create(su_home_t *, url_string_t const *url); 00263 00264 SOFIAPUBFUN int sip_to_tag(su_home_t *, sip_to_t *to, char const *tag); 00265 00267 SOFIAPUBFUN sip_via_t *sip_via_create(su_home_t *h, 00268 char const *host, 00269 char const *port, 00270 char const *transport, 00271 /* char const *params */ 00272 ...); 00273 00275 #if SU_HAVE_INLINE 00276 su_inline char const *sip_via_transport(sip_via_t const *v) 00277 { 00278 char const *tp = v->v_protocol; 00279 if (tp) { 00280 tp = strchr(tp, '/'); 00281 if (tp) { 00282 tp = strchr(tp + 1, '/'); 00283 if (tp) 00284 return tp + 1; 00285 } 00286 } 00287 return NULL; 00288 } 00289 #else 00290 char const *sip_via_transport(sip_via_t const *v); 00291 #endif 00292 00293 SOFIAPUBFUN char const *sip_via_port(sip_via_t const *v, int *using_rport); 00294 00295 SOFIAPUBFUN 00296 sip_payload_t *sip_payload_create(su_home_t *, void const *data, isize_t len); 00297 00315 #define SIP_PAYLOAD_INIT2(data, length) \ 00316 {{{ 0, 0, sip_payload_class, data, length }, NULL, data, length }} 00317 00319 SOFIAPUBFUN sip_separator_t *sip_separator_create(su_home_t *home); 00320 00322 SOFIAPUBFUN 00323 sip_unsupported_t *sip_has_unsupported(su_home_t *, 00324 sip_supported_t const *support, 00325 sip_require_t const *require); 00326 00327 SOFIAPUBFUN 00328 sip_unsupported_t *sip_has_unsupported2(su_home_t *, 00329 sip_supported_t const *support, 00330 sip_require_t const *by_require, 00331 sip_require_t const *require); 00332 00333 SOFIAPUBFUN 00334 sip_unsupported_t * 00335 sip_has_unsupported_any(su_home_t *, 00336 sip_supported_t const *support, 00337 sip_require_t const *by_require, 00338 sip_proxy_require_t const *by_proxy_require, 00339 sip_require_t const *require, 00340 sip_require_t const *require2, 00341 sip_require_t const *require3); 00342 00344 SOFIAPUBFUN 00345 int sip_has_supported(sip_supported_t const *support, char const *feature); 00346 00348 SOFIAPUBFUN 00349 int sip_has_feature(msg_list_t const *supported, char const *feature); 00350 00352 SOFIAPUBFUN int sip_is_allowed(sip_allow_t const *allow, 00353 sip_method_t method, char const *name); 00354 00356 #define SIP_IS_ALLOWED(allow, method) \ 00357 (sip_method_unknown < (method) && (method) < 32 && \ 00358 (allow) && ((allow)->k_bitmap & (1 << (method))) != 0) 00359 00374 enum sip_bad_mask { 00380 sip_mask_request = (1 << 0), 00381 00387 sip_mask_response = (1 << 1), 00388 00394 sip_mask_ua = (1 << 2), 00395 00401 sip_mask_proxy = (1 << 3), 00402 00409 sip_mask_registrar = (1 << 4), 00410 00417 sip_mask_100rel = (1 << 5), 00418 00425 sip_mask_events = (1 << 6), 00426 00433 sip_mask_timer = (1 << 7), 00434 00441 sip_mask_privacy = (1 << 8), 00442 00449 sip_mask_pref = (1 << 9), 00450 00457 sip_mask_publish = (1 << 10) 00458 00459 /* NOTE: 00460 * When adding bits, please update nta_agent_create() and 00461 * NTATAG_BAD_RESP_MASK()/NTATAG_BAD_REQ_MASK() documentation. 00462 */ 00463 }; 00464 00465 /* ------------------------------------------------------------------------- */ 00466 00467 /* Here are @deprecated functions and names for compatibility */ 00468 00470 SOFIAPUBFUN issize_t sip_header_e(char[], isize_t, sip_header_t const *, int); 00471 00473 SOFIAPUBFUN 00474 sip_header_t *sip_header_d(su_home_t *, msg_t const *, char const *); 00475 00477 SOFIAPUBFUN issize_t sip_header_field_e(char[], isize_t, sip_header_t const *, int); 00478 00480 SOFIAPUBFUN issize_t sip_header_field_d(su_home_t *, sip_header_t *, char *, isize_t); 00481 00483 SOFIAPUBFUN isize_t sip_header_size(sip_header_t const *h); 00484 00486 SOFIAPUBFUN sip_header_t *sip_header_dup(su_home_t *, sip_header_t const *); 00487 00489 SOFIAPUBFUN sip_header_t *sip_header_copy(su_home_t *, sip_header_t const *o); 00490 00492 SOFIAPUBFUN int sip_allow_events_add(su_home_t *, 00493 sip_allow_events_t *ae, 00494 char const *e); 00495 00497 SOFIAPUBFUN int sip_contact_add_param(su_home_t *, sip_contact_t *, 00498 char const *param); 00499 00500 SOFIAPUBFUN int sip_to_add_param(su_home_t *, sip_to_t *, char const *); 00501 00502 SOFIAPUBFUN int sip_from_add_param(su_home_t *, sip_from_t *, char const *); 00503 00505 SOFIAPUBFUN int sip_via_add_param(su_home_t *, sip_via_t *, char const *); 00506 00507 #define sip_from_make_url sip_from_create 00508 #define sip_to_make_url sip_to_create 00509 #define sip_params_find msg_params_find 00510 00511 SOFIA_END_DECLS 00512 00513 #endif