📄 sip_basic.c
字号:
* @endcode * *//**@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 * @b Content-Length 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_unknown_t *l_next; // Link to next (dummy) * unsigned long l_length; // Digits * } 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);int sip_content_length_d(su_home_t *home, sip_header_t *h, char *s, int slen){ return sip_numeric_d(home, h, s, slen);}int sip_content_length_e(char b[], int bsiz, sip_header_t const *h, int flags){ assert(sip_is_content_length(h)); return sip_numeric_e(b, bsiz, h, flags);}/**@ingroup sip_content_length * *燙reate a @b Content-Length header object. * * The function sip_content_length_create() creates a Content-Length * 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 * The function sip_content_length_create() returns a pointer to newly * created @b Content-Length 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_header_alloc(home, sip_content_length_class, 0)->sh_content_length; 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 [S10.21] and [H14.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 * *//**@ingroup sip_date * @typedef typedef struct sip_date_s sip_date_t; * * The structure #sip_date_t contains representation of SIP @b 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);int sip_date_d(su_home_t *home, sip_header_t *h, char *s, int slen){ sip_date_t *date = h->sh_date; if (msg_date_d((char const **)&s, &date->d_time) < 0 || *s) return -1; else return 0;}int sip_date_e(char b[], int bsiz, sip_header_t const *h, int f){ sip_date_t const *date = h->sh_date; return msg_date_e(b, bsiz, date->d_time);}/**@ingroup sip_date * @brief Create an @b Date header object. * * The function sip_date_create() creates 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 * The function sip_date_create() returns a pointer to newly created * @b 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_header_t *h = sip_header_alloc(home, sip_date_class, 0); if (h) { if (date == 0) date = sip_now(); h->sh_date->d_time = date; } return h->sh_date;}/* ====================================================================== *//**@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 [S10.24] as follows: * * @code * Expires = "Expires" HCOLON delta-seconds * @endcode * * Note that the first SIP revision (@RFC2543) also allowed absolute time in * Expires. *//**@ingroup sip_expires * @typedef typedef struct sip_expires_s sip_expires_t; * * The structure #sip_expires_t contains representation of SIP @b 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_unknown_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);int sip_expires_d(su_home_t *home, sip_header_t *h, char *s, int slen){ sip_expires_t *expires = h->sh_expires; if (msg_date_delta_d((char const **)&s, &expires->ex_date, &expires->ex_delta) < 0 || *s) return -1; else return 0;}int sip_expires_e(char b[], int bsiz, sip_header_t const *h, int f){ sip_expires_t const *expires = h->sh_expires; 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 @b Expires header object. * * The function sip_expires_create() creates an Expires header object * with the expiration time @a delta. * * @param home memory home * @param delta relative expiration time in seconds * * @return * The function sip_expires_create() returns a pointer to newly created * @b 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_header_t *h = sip_header_alloc(home, sip_expires_class, 0); if (h) h->sh_expires->ex_delta = delta; return h->sh_expires;}/* ====================================================================== *//**@SIP_HEADER sip_from From Header * * The From header indicates the initiator of the request. It is defined in * [S10.25] 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 * *//**@ingroup sip_from * @typedef typedef struct sip_addr_s sip_from_t; * * The structure sip_from_t contains representation of @b 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_unknown_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);int sip_from_d(su_home_t *home, sip_header_t *h, char *s, int slen){ return sip_addr_d(home, h, s, slen);}int sip_from_e(char b[], int 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 @b From header object with URL. * * The function sip_from_create() creates a From header object with * the given URL. * * @param home memory home * @param s pointer to the URL or a string * * @return * The function sip_from_create() returns a pointer to newly created @b * 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. * * The function sip_from_add_param() adds 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 * * @return * The function sip_from_add_param() returns 0 when successful, or -1 upon * an error. */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 * * The function sip_from_tag() adds a tag to a @b 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 @b From header to modify * @param tag tag token or parameter to be added * * @retval 0 when successful * @retval -1 upon an error. */int sip_from_tag(su_home_t *home, sip_from_t *from, char const *tag){ return sip_addr_tag(home, from, tag);}int sip_to_tag(su_home_t *home, sip_to_t *to, char const *tag){ return sip_addr_tag(home, to, tag);}/* ====================================================================== *//**@SIP_HEADER sip_max_forwards Max-Forwards Header * * The Max-Forwards header is used to limit the number of proxies or * gateways that can forward the request. The Max-Forwards syntax is * defined in [S10.27] as follows: * * @code * Max-Forwards = "Max-Forwards" HCOLON 1*DIGIT * @endcode * *//**@ingroup sip_max_forwards * @typedef typedef struct sip_max_forwards_s sip_max_forwards_t; * * The structure #sip_max_forwards_t contains representation of SIP * @b Max-Forwards header. * * The #sip_max_forwards_t is defined as follows: * @code * typedef struct sip_max_forwards_s { * sip_common_t mf_common[1]; // Common fragment info * sip_unknown_t *mf_next; // Link to next (dummy) * unsigned long mf_count; // Digits * } sip_max_forwards_t; * @endcode */msg_hclass_t sip_max_forwards_class[] = SIP_HEADER_CLASS(max_forwards, "Max-Forwards", "", mf_common, single, any);int sip_max_forwards_d(su_home_t *home, sip_header_t *h, char *s, int slen){ return sip_numeric_d(home, h, s, slen);}int sip_max_forwards_e(char b[], int bsiz, sip_header_t const *h, int f){ assert(sip_is_max_forwards(h)); return sip_numeric_e(b, bsiz, h, f);}/* ====================================================================== *//**@SIP_HEADER sip_min_expires Min-Expires Header * * The Min-Expires header is used to limit the number of proxies or * gateways that can forward the request. The Min-Expires syntax is * defined in [S20.23] as follows: * * @code * Min-Expires = "Min-Expires" HCOLON delta-seconds * @endcode * *//**@ingroup sip_min_expires * @typedef typedef struct sip_min_expires_s sip_min_expires_t; * * The structure #sip_min_expires_t contains representation of SIP * @b Min-Expires header. * * The #sip_min_expires_t is defined as follows: * @code * typedef struct sip_min_expires_s { * sip_common_t me_common[1]; // Common fragment info * sip_unknown_t *me_next; // Link to next (dummy) * unsigned long me_delta; // Seconds * } sip_min_expires_t; * @endcode */msg_hclass_t sip_min_expires_class[] = SIP_HEADER_CLASS(min_expires, "Min-Expires", "", me_common, single, any);int sip_min_expires_d(su_home_t *home, sip_header_t *h, char *s, int slen){ return sip_numeric_d(home, h, s, slen);}int sip_min_expires_e(char b[], int bsiz, sip_header_t const *h, int f){ assert(sip_is_min_expires(h)); return sip_numeric_e(b, bsiz, h, f);}/* ====================================================================== *//**@SIP_HEADER sip_retry_after Retry-After Header * * The Retry-After response-header field [RFC3261/20.33] can be used to * indicate how long the service is expected to be unavailable or when the * called party anticipates being available again. Its syntax is defined in * [RFC3261] as follows: * * @code * Retry-After = "Retry-After" HCOLON delta-seconds * [ comment ] *( SEMI retry-param ) * retry-param = ("duration" EQUAL delta-seconds) * / generic-param * @endcode *//**@ingroup sip_retry_after * @typedef struct sip_retry_after_s sip_retry_after_t; * * The structure sip_retry_after_t contains representation of an @b * Retry-After header. * * The sip_retry_after_t is defined as follows: * @code * typedef struct sip_retry_after_s { * sip_common_t af_common[1]; // Common fragment info * sip_error_t *af_next; // Link to next (dummy) * sip_time_t af_delta; // Seconds to before retry * msg_param_t af_comment; // Comment string * msg_param_t const *af_params; // List of parameters
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -