📄 msg_mime.c
字号:
/* "Accept:" #(type/subtyp ; *(parameters))) */ if (msg_mediatype_d(&s, &ac->ac_type) == -1) return -1; if (!(ac->ac_subtype = strchr(ac->ac_type, '/'))) return -1; ac->ac_subtype++; if (*s == ';' && msg_params_d(home, &s, &ac->ac_params) == -1) return -1; return msg_parse_next_field(home, h, s, slen);}issize_t msg_accept_e(char b[], isize_t bsiz, msg_header_t const *h, int flags){ char *b0 = b, *end = b + bsiz; msg_accept_t const *ac = (msg_accept_t *)h; assert(msg_is_accept(h)); if (ac->ac_type) { MSG_STRING_E(b, end, ac->ac_type); MSG_PARAMS_E(b, end, ac->ac_params, flags); } MSG_TERM_E(b, end); return b - b0;}isize_t msg_accept_dup_xtra(msg_header_t const *h, isize_t offset){ msg_accept_t const *ac = (msg_accept_t *)h; if (ac->ac_type) { MSG_PARAMS_SIZE(offset, ac->ac_params); offset += MSG_STRING_SIZE(ac->ac_type); } return offset;}/** Duplicate one msg_accept_t object */char *msg_accept_dup_one(msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra){ msg_accept_t *ac = (msg_accept_t *)dst; msg_accept_t const *o = (msg_accept_t *)src; char *end = b + xtra; if (o->ac_type) { b = msg_params_dup(&ac->ac_params, o->ac_params, b, xtra); MSG_STRING_DUP(b, ac->ac_type, o->ac_type); if ((ac->ac_subtype = strchr(ac->ac_type, '/'))) ac->ac_subtype++; } assert(b <= end); (void)end; return b;}/** Update parameter(s) for Accept header. */ int msg_accept_update(msg_common_t *h, char const *name, isize_t namelen, char const *value){ msg_accept_t *ac = (msg_accept_t *)h; if (name == NULL) { ac->ac_q = NULL; } else if (namelen == 1 && strncasecmp(name, "q", 1) == 0) { /* XXX - check for invalid value? */ ac->ac_q = value; } return 0;}/* ====================================================================== *//** Decode an Accept-* header. */issize_t msg_accept_any_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen){ /** @relatesalso msg_accept_any_s */ msg_accept_any_t *aa = (msg_accept_any_t *)h; while (*s == ',') /* Ignore empty entries (comma-whitespace) */ *s = '\0', s += span_lws(s + 1) + 1; if (*s == '\0') return -2; /* Empty list */ /* "Accept-*:" 1#(token *(SEMI accept-param)) */ if (msg_token_d(&s, &aa->aa_value) == -1) return -1; if (*s == ';' && msg_params_d(home, &s, &aa->aa_params) == -1) return -1; return msg_parse_next_field(home, h, s, slen);}/** Encode an Accept-* header field. */issize_t msg_accept_any_e(char b[], isize_t bsiz, msg_header_t const *h, int f){ /** @relatesalso msg_accept_any_s */ char *b0 = b, *end = b + bsiz; msg_accept_any_t const *aa = (msg_accept_any_t *)h; MSG_STRING_E(b, end, aa->aa_value); MSG_PARAMS_E(b, end, aa->aa_params, flags); MSG_TERM_E(b, end); return b - b0;}/** Calculate extra memory used by accept-* headers. */isize_t msg_accept_any_dup_xtra(msg_header_t const *h, isize_t offset){ /** @relatesalso msg_accept_any_s */ msg_accept_any_t const *aa = (msg_accept_any_t *)h; MSG_PARAMS_SIZE(offset, aa->aa_params); offset += MSG_STRING_SIZE(aa->aa_value); return offset;}/** Duplicate one msg_accept_any_t object. */char *msg_accept_any_dup_one(msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra){ /** @relatesalso msg_accept_any_s */ msg_accept_any_t *aa = (msg_accept_any_t *)dst; msg_accept_any_t const *o = (msg_accept_any_t *)src; char *end = b + xtra; b = msg_params_dup(&aa->aa_params, o->aa_params, b, xtra); MSG_STRING_DUP(b, aa->aa_value, o->aa_value); assert(b <= end); (void)end; return b;}/** Update parameter(s) for Accept-* header. */ int msg_accept_any_update(msg_common_t *h, char const *name, isize_t namelen, char const *value){ msg_accept_any_t *aa = (msg_accept_any_t *)h; if (name == NULL) { aa->aa_q = NULL; } else if (namelen == 1 && strncasecmp(name, "q", 1) == 0) { aa->aa_q = value; } return 0;}/* ====================================================================== *//**@ingroup msg_mime * @defgroup msg_accept_charset Accept-Charset Header * * The Accept-Charset header is similar to Accept, but restricts the * character set that are acceptable in the response. Its syntax is * defined in [H14.2] as follows: * * @code * Accept-Charset = "Accept-Charset" ":" * 1#( ( charset | "*" )[ ";" "q" "=" qvalue ] ) * @endcode * *//**@ingroup msg_accept_charset * @typedef typedef struct msg_accept_charset_s msg_accept_charset_t; * * The structure msg_accept_encoding_t contains representation of @b * Accept-Charset header. * * The msg_accept_charset_t is defined as follows: * @code * typedef struct { * msg_common_t aa_common[1]; // Common fragment info * msg_accept_any_t *aa_next; // Pointer to next Accept-Charset * char const *aa_value; // Charset * msg_param_t const *aa_params; // Parameter list * char const *aa_q; // Q-value * } msg_accept_charset_t; * @endcode */msg_hclass_t msg_accept_charset_class[1] = MSG_HEADER_CLASS(msg_, accept_charset, "Accept-Charset", "", aa_params, apndlist, msg_accept_any, msg_accept_any);issize_t msg_accept_charset_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen){ return msg_accept_any_d(home, h, s, slen);}issize_t msg_accept_charset_e(char b[], isize_t bsiz, msg_header_t const *h, int f){ assert(msg_is_accept_charset(h)); return msg_accept_any_e(b, bsiz, h, f);}/* ====================================================================== *//**@ingroup msg_mime * @defgroup msg_accept_encoding Accept-Encoding Header * * The Accept-Encoding header is similar to Accept, but restricts the * content-codings that are acceptable in the response. Its syntax is * defined in [H14.3, S20.2] as follows: * * @code * Accept-Encoding = "Accept-Encoding" ":" * 1#( codings [ ";" "q" "=" qvalue ] ) * codings = ( content-coding | "*" ) * content-coding = token * @endcode * *//**@ingroup msg_accept_encoding * @typedef typedef struct msg_accept_encoding_s msg_accept_encoding_t; * * The structure msg_accept_encoding_t contains representation of @b * Accept-Encoding header. * * The msg_accept_encoding_t is defined as follows: * @code * typedef struct { * msg_common_t aa_common[1]; // Common fragment info * msg_accept_any_t *aa_next; // Pointer to next Accept-Encoding * char const *aa_value; // Content-coding * msg_param_t const *aa_params; // Parameter list * char const *aa_q; // Q-value * } msg_accept_encoding_t; * @endcode */msg_hclass_t msg_accept_encoding_class[1] = MSG_HEADER_CLASS(msg_, accept_encoding, "Accept-Encoding", "", aa_params, apndlist, msg_accept_any, msg_accept_any);issize_t msg_accept_encoding_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen){ return msg_accept_any_d(home, h, s, slen);}issize_t msg_accept_encoding_e(char b[], isize_t bsiz, msg_header_t const *h, int f){ return msg_accept_any_e(b, bsiz, h, f);}/* ====================================================================== *//**@ingroup msg_mime * @defgroup msg_accept_language Accept-Language Header * * The Accept-Language header allows the client to indicate to the server in * which language it would prefer to receive reason phrases, session * descriptions or status responses carried as message bodies. Its syntax is * defined in [H14.4, S20.3] as follows: * * @code * Accept-Language = "Accept-Language" ":" * 1#( language-range [ ";" "q" "=" qvalue ] ) * * language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" ) * @endcode * *//**@ingroup msg_accept_language * @typedef typedef struct msg_accept_language_s msg_accept_language_t; * * The structure msg_accept_language_t contains representation of @b * Accept-Language header. * * The msg_accept_language_t is defined as follows: * @code * typedef struct { * msg_common_t aa_common[1]; // Common fragment info * msg_accept_any_t *aa_next; // Pointer to next Accept-Encoding * char const *aa_value; // Language-range * msg_param_t const *aa_params; // Parameter list * char const *aa_q; // Q-value * } msg_accept_language_t; * @endcode */msg_hclass_t msg_accept_language_class[1] = MSG_HEADER_CLASS(msg_, accept_language, "Accept-Language", "", aa_params, apndlist, msg_accept_any, msg_accept_any);issize_t msg_accept_language_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen){ return msg_accept_any_d(home, h, s, slen);}issize_t msg_accept_language_e(char b[], isize_t bsiz, msg_header_t const *h, int f){ assert(msg_is_accept_language(h)); return msg_accept_any_e(b, bsiz, h, f);}/* ====================================================================== *//**@ingroup msg_mime * @defgroup msg_content_disposition Content-Disposition Header * * The Content-Disposition header field describes how the message body or, * in the case of multipart messages, a message body part is to be * interpreted by the UAC or UAS. Its syntax is defined in [S20.11] * as follows: * * @code * Content-Disposition = "Content-Disposition" ":" * disposition-type *( ";" disposition-param ) * disposition-type = "render" | "session" | "icon" | "alert" * | disp-extension-token * disposition-param = "handling" "=" * ( "optional" | "required" | other-handling ) * | generic-param * other-handling = token * disp-extension-token = token * @endcode * * The Content-Disposition header was extended by * draft-lennox-sip-reg-payload-01.txt section 3.1 as follows: * * @code * Content-Disposition = "Content-Disposition" ":" * disposition-type *( ";" disposition-param ) * disposition-type /= "script" | "sip-cgi" | token * disposition-param /= action-param * / modification-date-param * action-param = "action" "=" action-value * action-value = "store" | "remove" | token * modification-date-param = "modification-date" "=" quoted-date-time * quoted-date-time = <"> SIP-date <"> * @endcode *//**@ingroup msg_content_disposition * @typedef struct msg_content_disposition_s msg_content_disposition_t; * * The structure msg_content_disposition_t contains representation of an @b * Content-Disposition header. * * The msg_content_disposition_t is defined as follows: * @code * typedef struct msg_content_disposition_s * { * msg_common_t cd_common[1]; // Common fragment info * msg_error_t *cd_next; // Link to next (dummy) * char const *cd_type; // Disposition type * msg_param_t const *cd_params; // List of parameters * msg_param_t cd_handling; // Value of @b handling parameter * unsigned cd_required:1; // True if handling=required * unsigned cd_optional:1; // True if handling=optional * } msg_content_disposition_t; * @endcode */msg_hclass_t msg_content_disposition_class[] =MSG_HEADER_CLASS(msg_, content_disposition, "Content-Disposition", "", cd_params, single, msg_content_disposition, msg_content_disposition);issize_t msg_content_disposition_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen){ msg_content_disposition_t *cd = (msg_content_disposition_t *)h; if (msg_token_d(&s, &cd->cd_type) < 0 || (*s == ';' && msg_params_d(home, &s, &cd->cd_params) < 0)) return -1; if (cd->cd_params) msg_header_update_params(cd->cd_common, 0); return 0;}issize_t msg_content_disposition_e(char b[], isize_t bsiz, msg_header_t const *h, int f){ char *b0 = b, *end = b + bsiz; msg_content_disposition_t const *cd = (msg_content_disposition_t *)h; assert(msg_is_content_disposition(h)); MSG_STRING_E(b, end, cd->cd_type); MSG_PARAMS_E(b, end, cd->cd_params, f); MSG_TERM_E(b, end); return b - b0;}isize_t msg_content_disposition_dup_xtra(msg_header_t const *h, isize_t offset){ msg_content_disposition_t const *cd = (msg_content_disposition_t *)h; MSG_PARAMS_SIZE(offset, cd->cd_params); offset += MSG_STRING_SIZE(cd->cd_type); return offset;}/** Duplicate one msg_content_disposition_t object */char *msg_content_disposition_dup_one(msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra){ msg_content_disposition_t *cd = (msg_content_disposition_t *)dst; msg_content_disposition_t const *o = (msg_content_disposition_t *)src; char *end = b + xtra; b = msg_params_dup(&cd->cd_params, o->cd_params, b, xtra); MSG_STRING_DUP(b, cd->cd_type, o->cd_type); assert(b <= end); (void)end; return b;}/** Update Content-Disposition parameters */int msg_content_disposition_update(msg_common_t *h, char const *name, isize_t namelen, char const *value){ msg_content_disposition_t *cd = (msg_content_disposition_t *)h; if (name == NULL) { cd->cd_handling = NULL, cd->cd_required = 0, cd->cd_optional = 0; } else if (namelen == strlen("handling") && strncasecmp(name, "handling", namelen) == 0) { cd->cd_handling = value; cd->cd_required = strcasecmp(value, "required") == 0; cd->cd_optional = strcasecmp(value, "optional") == 0; } return 0;}/* ====================================================================== *//**@ingroup msg_mime * @defgroup msg_content_encoding Content-Encoding Header * * The Content-Encoding header indicates what additional content codings * have been applied to the entity-body. Its syntax is defined in [H14.11] * and [S20.12] as follows: * * @code * Content-Encoding = ( "Content-Encoding" / "e" ) ":" 1#content-coding * content-coding = token * @endcode *//**@ingroup msg_content_encoding * @typedef struct msg_list_s msg_content_encoding_t; * * The structure msg_content_encoding_t contains representation of an @b * Content-Encoding header. * * The msg_content_encoding_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 items * } msg_content_encoding_t; * @endcode */msg_hclass_t msg_content_encoding_class[] = MSG_HEADER_CLASS_LIST(content_encoding, "Content-Encoding", "e", list);issize_t msg_content_encoding_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen){ msg_content_encoding_t *e = (msg_content_encoding_t *)h; return msg_commalist_d(home, &s, &e->k_items, msg_token_scan);}issize_t msg_content_encoding_e(char b[], isize_t bsiz, msg_header_t const *h, int f){ assert(msg_is_content_encoding(h)); return msg_list_e(b, bsiz, h, f);}/* ====================================================================== *//**@ingroup msg_mime * @defgroup msg_content_language Content-Language Header * * The Content-Language header describes the natural language(s) of the * intended audience for the enclosed message body. Note that this might not * be equivalent to all the languages used within the message-body. Its * syntax is defined in [H14.12, S20.13] as follows: * * @code * Content-Language = "Content-Language" ":" 1#language-tag * @endcode * or * @code * Content-Language = "Content-Language" HCOLON * language-tag *(COMMA language-tag) * language-tag = primary-tag *( "-" subtag ) * primary-tag = 1*8ALPHA * subtag = 1*8ALPHA * @endcode * *//**@ingroup msg_content_language * @typedef typedef struct msg_content_language_s msg_content_language_t; * * The structure msg_content_language_t contains representation of @b * Content-Language header. * * The msg_content_language_t is defined as follows: * @code * typedef struct {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -