📄 sip_extra.c
字号:
/* * This file is part of the Sofia-SIP package * * Copyright (C) 2005 Nokia Corporation. * * Contact: Pekka Pessi <pekka.pessi@nokia.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * *//**@CFILE sip_extra.c * @brief Non-critical SIP headers * * This file contains implementation of @CallInfo, @ErrorInfo, * @Organization, @Priority, @RetryAfter, @Server, @Subject, * @Timestamp, and @UserAgent headers. * * @author Pekka Pessi <Pekka.Pessi@nokia.com>. * * @date Created: Tue Jun 13 02:57:51 2000 ppessi */#include "config.h"/* Avoid casting sip_t to msg_pub_t and sip_header_t to msg_header_t */#define MSG_PUB_T struct sip_s#define MSG_HDR_T union sip_header_u#include "sofia-sip/sip_parser.h"#include "sofia-sip/sip_extra.h"#include <stdio.h>#include <stddef.h>#include <stdlib.h>#include <string.h>#include <limits.h>#include <assert.h>/* ====================================================================== */static issize_t sip_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen);static isize_t sip_info_dup_xtra(sip_header_t const *h, isize_t offset);static char *sip_info_dup_one(sip_header_t *dst, sip_header_t const *src, char *b, isize_t xtra);#define sip_info_update NULL/* ====================================================================== *//**@SIP_HEADER sip_call_info Call-Info Header * * The Call-Info header provides additional information about the caller or * callee. Its syntax is defined in @RFC3261 as follows: * * @code * Call-Info = "Call-Info" HCOLON info *(COMMA info) * info = LAQUOT absoluteURI RAQUOT *( SEMI info-param) * info-param = ( "purpose" EQUAL ( "icon" / "info" * / "card" / token ) ) / generic-param * @endcode * * * The parsed Call-Info header is stored in #sip_call_info_t structure. *//**@ingroup sip_call_info * @typedef struct sip_call_info_s sip_call_info_t; * * The structure #sip_call_info_t contains representation of an * @CallInfo header. * * The #sip_call_info_t is defined as follows: * @code * struct sip_call_info_s * { * sip_common_t ci_common[1]; // Common fragment info * sip_call_info_t *ci_next; // Link to next @CallInfo * url_t ci_url[1]; // URI to call info * msg_param_t const *ci_params; // List of parameters * char const *ci_purpose; // Value of @b purpose parameter * }; * @endcode */#define sip_call_info_dup_xtra sip_info_dup_xtra#define sip_call_info_dup_one sip_info_dup_onestatic msg_update_f sip_call_info_update;msg_hclass_t sip_call_info_class[] =SIP_HEADER_CLASS(call_info, "Call-Info", "", ci_params, append, call_info);issize_t sip_call_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen){ issize_t retval = sip_info_d(home, h, s, slen); if (retval == 0) for (;h; h = h->sh_next) msg_header_update_params(h->sh_common, 0); return retval;}issize_t sip_call_info_e(char b[], isize_t bsiz, sip_header_t const *h, int f){ sip_call_info_t *ci = (sip_call_info_t *)h; assert(sip_call_info_p(h)); return sip_name_addr_e(b, bsiz, f, NULL, 1, ci->ci_url, ci->ci_params, NULL);}/** @internal * Update parameter in a @CallInfo object. * */staticint sip_call_info_update(msg_common_t *h, char const *name, isize_t namelen, char const *value){ sip_call_info_t *ci = (sip_call_info_t *)h; if (name == NULL) { ci->ci_purpose = NULL; } else if (namelen == strlen("purpose") && !strncasecmp(name, "purpose", namelen)) { ci->ci_purpose = value; } return 0;}/* ====================================================================== *//**@SIP_HEADER sip_error_info Error-Info Header * * The Error-Info header provides a pointer to additional information about * the error status response. Its syntax is defined in @RFC3261 as follows: * * @code * Error-Info = "Error-Info" HCOLON error-uri *(COMMA error-uri) * error-uri = LAQUOT absoluteURI RAQUOT *( SEMI generic-param ) * @endcode * * * The parsed Error-Info header is stored in #sip_error_info_t structure. *//**@ingroup sip_error_info * @typedef struct sip_error_info_s sip_error_info_t; * * The structure #sip_error_info_t contains representation of an * @ErrorInfo header. * * The #sip_error_info_t is defined as follows: * @code * struct sip_error_info_s * { * sip_common_t ei_common[1]; // Common fragment info * sip_error_info_t *ei_next; // Link to next @ErrorInfo * url_t ei_url[1]; // URI to error info * msg_param_t const *ei_params; // List of parameters * }; * @endcode */msg_hclass_t sip_error_info_class[] = SIP_HEADER_CLASS(error_info, "Error-Info", "", ei_params, append, info);issize_t sip_error_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen){ return sip_info_d(home, h, s, slen);}issize_t sip_error_info_e(char b[], isize_t bsiz, sip_header_t const *h, int f){ sip_error_info_t const *ei = h->sh_error_info; assert(sip_error_info_p(h)); return sip_name_addr_e(b, bsiz, f, NULL, 1, ei->ei_url, ei->ei_params, NULL);}/* ====================================================================== *//**@SIP_HEADER sip_alert_info Alert-Info Header * * When present in an INVITE request, the Alert-Info header field * specifies an alternative ring tone to the UAS. When present in a 180 * (Ringing) response, the Alert-Info header field specifies an * alternative ringback tone to the UAC. A typical usage is for a proxy * to insert this header field to provide a distinctive ring feature. * * @code * Alert-Info = "Alert-Info" HCOLON alert-param *(COMMA alert-param) * alert-param = LAQUOT absoluteURI RAQUOT *(SEMI generic-param) * @endcode * * The parsed Alert-Info header is stored in #sip_alert_info_t structure. * * @NEW_1_12_7. In order to use @b Alert-Info header, initialize the SIP * parser before calling nta_agent_create() or nua_create() with, e.g., * sip_update_default_mclass(sip_extend_mclass(NULL)). * * The #sip_t structure does not contain a @a sip_alert_info field, but * sip_alert_info() function should be used for accessing the @b Alert-Info * header structure. *//**@ingroup sip_alert_info * @typedef struct sip_alert_info_s sip_alert_info_t; * * The structure #sip_alert_info_t contains representation of an * @AlertInfo header. * * The #sip_alert_info_t is defined as follows: * @code * struct sip_alert_info_s * { * sip_common_t ai_common[1]; // Common fragment info * sip_alert_info_t *ai_next; // Link to next @AlertInfo * url_t ai_url[1]; // URI to alert info * msg_param_t const *ai_params; // List of optional parameters * }; * @endcode * * @NEW_1_12_7. */msg_hclass_t sip_alert_info_class[] =SIP_HEADER_CLASS(alert_info, "Alert-Info", "", ai_params, append, info);issize_t sip_alert_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen){ return sip_info_d(home, h, s, slen);}issize_t sip_alert_info_e(char b[], isize_t bsiz, sip_header_t const *h, int f){ sip_alert_info_t *ai = (sip_alert_info_t *)h; return sip_name_addr_e(b, bsiz, f, NULL, 1, ai->ai_url, ai->ai_params, NULL);}/* ====================================================================== *//**@SIP_HEADER sip_reply_to Reply-To Header * * The @b Reply-To header field contains a logical return URI that may be * different from the @From header field. For example, the URI MAY be used to * return missed calls or unestablished sessions. If the user wished to * remain anonymous, the header field SHOULD either be omitted from the * request or populated in such a way that does not reveal any private * information. Its syntax is defined in @RFC3261 as follows: * * @code * Reply-To = "Reply-To" HCOLON rplyto-spec * rplyto-spec = ( name-addr / addr-spec ) * *( SEMI rplyto-param ) * rplyto-param = generic-param * @endcode * * The parsed Reply-To header is stored in #sip_reply_to_t structure. * * @sa sip_update_default_mclass() * * @NEW_1_12_7. In order to use @b Reply-To header, * initialize the SIP parser before calling nta_agent_create() or * nua_create() with, e.g., * sip_update_default_mclass(sip_extend_mclass(NULL)). * * @note * The #sip_t structure does not contain a @a sip_reply_to field, but * sip_reply_to() function should be used for accessing the @b Reply-To * header structure. *//**@ingroup sip_reply_to * @typedef struct msg_list_s sip_reply_to_t; * * The structure #sip_reply_to_t contains representation of SIP * @ReplyTo header. * * The #sip_reply_to_t is defined as follows: * @code * struct sip_reply_to_s * { * sip_common_t rplyto_common[1]; // Common fragment info * sip_error_t *rplyto_next; // Dummy link to next header * char const *rplyto_display; // Display name * url_t rplyto_url[1]; // Return URI * msg_param_t const *rplyto_params; // List of optional parameters * }; * @endcode */static isize_t sip_reply_to_dup_xtra(sip_header_t const *h, isize_t offset);static char *sip_reply_to_dup_one(sip_header_t *dst, sip_header_t const *src, char *b, isize_t xtra);#define sip_reply_to_update NULLmsg_hclass_t sip_reply_to_class[] = SIP_HEADER_CLASS(reply_to, "Reply-To", "", rplyto_params, single, reply_to);issize_t sip_reply_to_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen){ sip_reply_to_t *rplyto = (sip_reply_to_t *)h; return sip_name_addr_d(home, &s, &rplyto->rplyto_display, rplyto->rplyto_url, &rplyto->rplyto_params, NULL);}issize_t sip_reply_to_e(char b[], isize_t bsiz, sip_header_t const *h, int flags){ sip_reply_to_t *rplyto = (sip_reply_to_t *)h; return sip_name_addr_e(b, bsiz, flags, rplyto->rplyto_display, MSG_IS_CANONIC(flags), rplyto->rplyto_url, rplyto->rplyto_params, NULL);}static isize_t sip_reply_to_dup_xtra(sip_header_t const *h, isize_t offset){ sip_reply_to_t const *rplyto = (sip_reply_to_t const *)h; return sip_name_addr_xtra(rplyto->rplyto_display, rplyto->rplyto_url, rplyto->rplyto_params, offset);}/**@internal Duplicate one sip_reply_to_t object. */static char *sip_reply_to_dup_one(sip_header_t *dst, sip_header_t const *src, char *b, isize_t xtra){ sip_reply_to_t *rplyto = (sip_reply_to_t *)dst; sip_reply_to_t const *o = (sip_reply_to_t *)src; return sip_name_addr_dup(&rplyto->rplyto_display, o->rplyto_display, rplyto->rplyto_url, o->rplyto_url, &rplyto->rplyto_params, o->rplyto_params, b, xtra);}/* ====================================================================== *//**@SIP_HEADER sip_in_reply_to In-Reply-To Header * * The @b In-Reply-To request header field enumerates the * @ref sip_call_id "Call-IDs" that this call references or returns. * Its syntax is defined in @RFC3261 as follows: * * @code * In-Reply-To = "In-Reply-To" HCOLON callid *(COMMA callid) * @endcode * * The parsed In-Reply-To header is stored in #sip_in_reply_to_t structure. *//**@ingroup sip_in_reply_to * @typedef struct msg_list_s sip_in_reply_to_t; * * The structure #sip_in_reply_to_t contains representation of SIP * @InReplyTo header. * * The #sip_in_reply_to_t is defined as follows: * @code * typedef struct msg_list_s * { * msg_common_t k_common[1]; // Common fragment info * msg_list_t *k_next; // Link to next header * msg_param_t *k_items; // List of call ids * } sip_in_reply_to_t; * @endcode */msg_hclass_t sip_in_reply_to_class[] = SIP_HEADER_CLASS_LIST(in_reply_to, "In-Reply-To", "", list);issize_t sip_in_reply_to_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen){ return msg_list_d(home, h, s, slen);}issize_t sip_in_reply_to_e(char b[], isize_t bsiz, sip_header_t const *h, int f){ assert(sip_in_reply_to_p(h)); return msg_list_e(b, bsiz, h, f);}/* ====================================================================== *//**@SIP_HEADER sip_organization Organization Header * * The Organization header field conveys the name of the organization to * which the entity issuing the request or response belongs. Its syntax is * defined in @RFC3261 as follows: * * @code * Organization = "Organization" HCOLON [TEXT-UTF8-TRIM] * @endcode * * * The parsed Organization header is stored in #sip_organization_t structure. *//**@ingroup sip_organization * @typedef struct msg_generic_s sip_organization_t; * * The structure #sip_organization_t contains representation of a SIP * @Organization header. * * The #sip_organization_t is defined as follows: * @code * typedef struct msg_generic_s * { * msg_common_t g_common[1]; // Common fragment info * msg_generic_t *g_next; // Link to next header * char const *g_string; // Organization text * } sip_organization_t; * @endcode */msg_hclass_t sip_organization_class[] = SIP_HEADER_CLASS_G(organization, "Organization", "", single);issize_t sip_organization_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen){ return sip_generic_d(home, h, s, slen);}issize_t sip_organization_e(char b[], isize_t bsiz, sip_header_t const *h, int f){ assert(sip_organization_p(h)); return sip_generic_e(b, bsiz, h, f);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -