⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sip_basic.c

📁 Sofia SIP is an open-source SIP User-Agent library, compliant with the IETF RFC3261 specification.
💻 C
📖 第 1 页 / 共 5 页
字号:
		       sip_header_t *h,		       char *s,		       isize_t slen){  sip_contact_t *m = (sip_contact_t *)h;  assert(h);  while (*s == ',')   /* Ignore empty entries (comma-whitespace) */    *s = '\0', s += span_lws(s + 1) + 1;  if (sip_name_addr_d(home, &s, &m->m_display, m->m_url, 		      &m->m_params, &m->m_comment) == -1)    return -1;  return msg_parse_next_field(home, h, s, slen);}issize_t sip_contact_e(char b[], isize_t bsiz, sip_header_t const *h, int flags){  sip_contact_t const *m = (sip_contact_t *)h;  int always_lt_gt = MSG_IS_CANONIC(flags) && m->m_url->url_type != url_any;  assert(sip_is_contact(h));  return sip_name_addr_e(b, bsiz, flags,			 m->m_display, always_lt_gt, m->m_url, 			 m->m_params,			 NULL /* m->m_comment */);}isize_t sip_contact_dup_xtra(sip_header_t const *h, isize_t offset){  sip_contact_t const *m = (sip_contact_t *)h;  return sip_name_addr_xtra(m->m_display,			    m->m_url,			    m->m_params,			    offset)    + MSG_STRING_SIZE(m->m_comment);}char *sip_contact_dup_one(sip_header_t *dst, sip_header_t const *src,			  char *b, isize_t xtra){  sip_contact_t *m = (sip_contact_t *)dst;  sip_contact_t const *o = (sip_contact_t *)src;  b = sip_name_addr_dup(&m->m_display, o->m_display,			m->m_url, o->m_url,			&m->m_params, o->m_params,			b, xtra);  MSG_STRING_DUP(b, m->m_comment, o->m_comment);  return b;}/** Update parameter in #sip_contact_t */static int sip_contact_update(msg_common_t *h, 			      char const *name, isize_t namelen,			      char const *value){  sip_contact_t *m = (sip_contact_t *)h;  if (name == NULL) {    m->m_q = NULL;    m->m_expires = NULL;  }  else if (namelen == 1 && strncasecmp(name, "q", 1) == 0) {    /* XXX - check for invalid value? */    m->m_q = value;  }  else if (namelen == strlen("expires") && 	   !strncasecmp(name, "expires", namelen)) {    m->m_expires = value;  }  return 0;}/**@ingroup sip_contact  * * Add a parameter to a @Contact header object * * Add a parameter to a @Contact * object. It does not copy the contents of the string @c param. * * @note This function @b does @b not duplicate @p param. * * @param home   memory home * @param m      #sip_contact_t object * @param param  parameter string * * @return 0 when successful, and -1 upon an error. * * @deprecated Use msg_header_replace_param() directly. */int sip_contact_add_param(su_home_t *home,			  sip_contact_t *m,			  char const *param){  return msg_header_replace_param(home, m->m_common, param);}/* ====================================================================== *//**@SIP_HEADER sip_content_length Content-Length Header * * The Content-Length header indicates the size of the message-body in * decimal number of octets.  Its syntax is defined in @RFC3261 as * follows: * * @code *    Content-Length  =  ( "Content-Length" / "l" ) HCOLON 1*DIGIT * @endcode * * The parsed Content-Length header is stored in #sip_content_length_t * structure. *//**@ingroup sip_content_length * @typedef typedef struct sip_content_length_s sip_content_length_t; * * The structure #sip_content_length_t contains representation of SIP * @ContentLength header. * * The #sip_content_length_t is defined as follows: * @code * typedef struct sip_content_length_s { *   sip_common_t   l_common[1];        // Common fragment info *   sip_error_t   *l_next;             // Dummy link to next *   uint32_t       l_length;           // Message body length in bytes * } sip_content_length_t; * @endcode */msg_hclass_t sip_content_length_class[] = SIP_HEADER_CLASS(content_length, "Content-Length", "l", l_common, 		 single_critical, any);issize_t sip_content_length_d(su_home_t *home,			      sip_header_t *h,			      char *s,			      isize_t slen){  sip_content_length_t *l = (sip_content_length_t *)h;  issize_t retval = msg_uint32_d(&s, &l->l_length);  if (*s)    retval = -1;  return retval;}issize_t sip_content_length_e(char b[], isize_t bsiz, sip_header_t const *h, int flags){  sip_content_length_t const *l = (sip_content_length_t const *)h;  assert(sip_is_content_length(h));  return snprintf(b, bsiz, "%lu", (unsigned long)l->l_length);}/**@ingroup sip_content_length  * *燙reate a @ContentLength header object.  * * Create a @ContentLength * header object with the value @a n.  The memory for the header is * allocated from the memory home @a home. * * @param home  memory home * @param n     payload size in bytes * * @return * A pointer to newly created @ContentLength header object when successful * or NULL upon an error. */sip_content_length_t *sip_content_length_create(su_home_t *home, uint32_t n){  sip_content_length_t *l = (sip_content_length_t *)    sip_header_alloc(home, sip_content_length_class, 0);    if (l)    l->l_length = n;  return l;}/* ====================================================================== *//**@SIP_HEADER sip_date Date Header * * The Date header field reflects the time when the request or response was * first sent.  Its syntax is defined in @RFC3261 and @RFC2616 section 14.18 as * follows: *  * @code *    Date          =  "Date" HCOLON SIP-date *    SIP-date      =  rfc1123-date *    rfc1123-date  =  wkday "," SP date1 SP time SP "GMT" *    date1         =  2DIGIT SP month SP 4DIGIT *                     ; day month year (e.g., 02 Jun 1982) *    time          =  2DIGIT ":" 2DIGIT ":" 2DIGIT *                     ; 00:00:00 - 23:59:59 *    wkday         =  "Mon" / "Tue" / "Wed" *                     / "Thu" / "Fri" / "Sat" / "Sun" *    month         =  "Jan" / "Feb" / "Mar" / "Apr" *                     / "May" / "Jun" / "Jul" / "Aug" *                     / "Sep" / "Oct" / "Nov" / "Dec" * @endcode * * The parsed Date header is stored in #sip_date_t structure. *//**@ingroup sip_date * @typedef typedef struct sip_date_s sip_date_t; * * The structure #sip_date_t contains representation of SIP @Date header. * * The #sip_date_t is defined as follows: * @code * typedef struct sip_date_s { *   sip_common_t   d_common[1];        // Common fragment info *   sip_date_t    *d_next;             // Link to next (dummy) *   sip_time_t     d_time;             // Seconds since Jan 1, 1900 * } sip_date_t; * @endcode */msg_hclass_t sip_date_class[] = SIP_HEADER_CLASS(date, "Date", "", d_common, single, any);issize_t sip_date_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen){  sip_date_t *date = (sip_date_t *)h;  if (msg_date_d((char const **)&s, &date->d_time) < 0 || *s)    return -1;  else    return 0;}issize_t sip_date_e(char b[], isize_t bsiz, sip_header_t const *h, int f){  sip_date_t const *date = (sip_date_t *)h;  return msg_date_e(b, bsiz, date->d_time);}/**@ingroup sip_date * @brief Create an @Date header object.  * * Create a @Date header object with * the date @a date.  If @date is 0, current time (as returned by sip_now()) * is used. * * @param home   memory home * @param date   date expressed as seconds since Mon, 01 Jan 1900 00:00:00 * * @return * A pointer to newly created @Date header object when successful, or NULL * upon an error. */sip_date_t *sip_date_create(su_home_t *home, sip_time_t date){  sip_date_t *d = (sip_date_t *)sip_header_alloc(home, sip_date_class, 0);    if (d) {    if (date == 0)      date = sip_now();    d->d_time = date;  }  return d;}/* ====================================================================== *//**@SIP_HEADER sip_expires Expires Header * * The Expires header field gives the date and time after which the message * content expires.  Its syntax is defined in @RFC3261 as follows: *  * @code *    Expires     =  "Expires" HCOLON delta-seconds * @endcode *  * Note that the first SIP revision (@RFC2543) also allowed absolute time in * Expires. * * The parsed Expires header is stored in #sip_expires_t structure. *//**@ingroup sip_expires * @typedef typedef struct sip_expires_s sip_expires_t; * * The structure #sip_expires_t contains representation of SIP @Expires * header. * * The #sip_expires_t is defined as follows: * @code * typedef struct sip_expires_s { *   sip_common_t        ex_common[1];  // Common fragment info *   sip_error_t        *ex_next;       // Link to next (dummy) *   sip_time_t          ex_date;       // Seconds since Jan 1, 1900 *   sip_time_t          ex_delta;      // ...or delta seconds * } sip_expires_t; * @endcode */msg_hclass_t sip_expires_class[] = SIP_HEADER_CLASS(expires, "Expires", "", ex_common, single, any);issize_t sip_expires_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen){  sip_expires_t *expires = (sip_expires_t *)h;  if (msg_date_delta_d((char const **)&s, 		       &expires->ex_date, 		       &expires->ex_delta) < 0 || *s)    return -1;  else    return 0;}issize_t sip_expires_e(char b[], isize_t bsiz, sip_header_t const *h, int f){  sip_expires_t const *expires = (sip_expires_t *)h;  if (expires->ex_date)    return msg_date_e(b, bsiz, expires->ex_date + expires->ex_delta);  else    return msg_delta_e(b, bsiz, expires->ex_delta);}/**@ingroup sip_expires * @brief Create an @Expires header object.  * * Create an @Expires header object with the expiration time @a delta. * * @param home   memory home used to allocate #sip_expires_t structure * @param delta  relative expiration time in seconds * * @return * A pointer to newly created @Expires header object when successful or NULL * upon an error. */sip_expires_t *sip_expires_create(su_home_t *home, sip_time_t delta){  sip_expires_t *ex = (sip_expires_t *)    sip_header_alloc(home, sip_expires_class, 0);  if (ex)    ex->ex_delta = delta;  return ex;}/* ====================================================================== *//**@SIP_HEADER sip_from From Header * * The From header indicates the initiator of the request.  It is defined in * @RFC3261 as follows: *  * @code *    From        =  ( "From" / "f" ) HCOLON from-spec *    from-spec   =  ( name-addr / addr-spec ) *                   *( SEMI from-param ) *    from-param  =  tag-param / generic-param *    tag-param   =  "tag" EQUAL token * @endcode * * * The parsed From header is stored in #sip_from_t structure. *//**@ingroup sip_from * @typedef typedef struct sip_addr_s sip_from_t; * * The structure #sip_from_t contains representation of @From header. * * The #sip_from_t is defined as follows: * @code * typedef struct sip_addr_s { *   sip_common_t       a_common[1];    // Common fragment info *   sip_error_t       *a_next;         // Link to next *   char const        *a_display;      // Display name *   url_t              a_url[1];       // URL *   msg_param_t const *a_params;       // List of from-param *   char const        *a_comment;      // Comment *   char const        *a_tag;          // Tag parameter  * } sip_from_t; * @endcode * */msg_hclass_t sip_from_class[] = SIP_HEADER_CLASS(from, "From", "f", a_params, single, addr);issize_t sip_from_d(su_home_t *home,		    sip_header_t *h,		    char *s,		    isize_t slen){  return sip_addr_d(home, h, s, slen);}issize_t sip_from_e(char b[], isize_t bsiz, sip_header_t const *h, int flags){  assert(sip_is_from(h));  return sip_addr_e(b, bsiz, h, flags);}/**@ingroup sip_from * * Create a @From header object with URL. * * @param home      memory home used to allocate #sip_from_t structure * @param s         pointer to the URL or a string * * @return * A pointer to newly created @From header object when successful or NULL * upon an error. */sip_from_t *sip_from_create(su_home_t *home, url_string_t const *s){  return sip_addr_make_url(home, sip_from_class, s);}/**@ingroup sip_from * * Add a parameter to an #sip_from_t object. * * @param home   memory home * @param from   a pointer to #sip_from_t object * @param param  parameter string * * @retval 0 when successful * @retval -1 upon an error * * @deprecated Use msg_header_replace_param() directly. */int sip_from_add_param(su_home_t *home,		       sip_from_t *from,		       char const *param){  return msg_header_replace_param(home, from->a_common, param);}/**@ingroup sip_from * * Add a tag to a @From header. If @a tag is * identical with the existing one, nothing will be done. An error is * returned, if the header already contains a different tag. The @a tag can * be provided either as a single token ("deadbeer") or as in parameter form * ("tag=deadbeer"). In both cases the tag is duplicated using the memory * home @a home. *  * @param home memory home used to allocate new tag  * @param from @From header to modify * @param tag  tag token or parameter to be added  * * @retval 0 when successful

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -