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

📄 msg_parser.h

📁 this is simple sip stack.
💻 H
字号:
/* * 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 * */#ifndef MSG_PARSER_H/** Defined when <sofia-sip/msg_parser.h> has been included. */#define MSG_PARSER_H /**@ingroup msg_parser * @file sofia-sip/msg_parser.h * * Message parser interface. * * @author Pekka Pessi <Pekka.Pessi@nokia.com> * * @date Created: Tue Aug 21 16:03:45 2001 ppessi * */#ifndef SU_ALLOC_H#include <sofia-sip/su_alloc.h>#endif#ifndef MSG_HEADER_H#include <sofia-sip/msg_header.h>#endif#ifndef BNF_H#include <sofia-sip/bnf.h>#endif#ifndef URL_H#include <sofia-sip/url.h>#endifSOFIA_BEGIN_DECLS/* --------------------------------------------------------------------------- * 1) Header class definitions. */#if HAVE_STRUCT_KEYWORDS/** Define a header class */#define MSG_HEADER_CLASS(pr, c, l, s, params, kind, dup, upd)	\  {{								\    hc_hash:	pr##c##_hash,					\    hc_parse:	pr##c##_d,					\    hc_print:	pr##c##_e,					\    hc_dxtra:	dup##_dup_xtra,					\    hc_dup_one: dup##_dup_one,					\    hc_update:	upd##_update,					\    hc_name:	l,						\    hc_len:	sizeof(l) - 1,					\    hc_short:	s,						\    hc_size:	MSG_ALIGN(sizeof(pr##c##_t), sizeof(void*)),	\    hc_params:	offsetof(pr##c##_t, params),			\    hc_kind:	msg_kind_##kind,				\  }}#else#define MSG_HEADER_CLASS(pr, c, l, s, params, kind, dup, upd)	\  {{ \     pr##c##_hash, \     pr##c##_d, \     pr##c##_e, \     dup##_dup_xtra, \     dup##_dup_one, \     upd##_update, \     l, \     sizeof(l) - 1, \     s, \     MSG_ALIGN(sizeof(pr##c##_t), sizeof(void*)), \     offsetof(pr##c##_t, params), \     msg_kind_##kind, \  }}#endif/* Mark headers critical for understanding the message */#define msg_kind_single_critical msg_kind_single, 1#define msg_kind_list_critical   msg_kind_list, 1SOFIAPUBFUN int msg_extract_header(msg_t *msg, msg_pub_t *mo,				   char b[], int bsiz, int eos);SOFIAPUBFUN int msg_extract_separator(msg_t *msg, msg_pub_t *mo,				      char b[], int bsiz, int eos);SOFIAPUBFUN int msg_extract_payload(msg_t *msg, msg_pub_t *mo, 				    msg_header_t **return_payload, 				    unsigned body_len,				    char b[], int bsiz, int eos);/* --------------------------------------------------------------------------- * 2) Header processing methods for common headers. */SOFIAPUBFUN int msg_firstline_d(char *s, char **ss2, char **ss3);SOFIAPUBFUN int msg_default_dup_xtra(msg_header_t const *header, int offset);SOFIAPUBFUN char *msg_default_dup_one(msg_header_t *dst, 				      msg_header_t const *src,				      char *b, 				      int xtra);SOFIAPUBFUN int msg_numeric_d(su_home_t *, msg_header_t *h, char *s, int slen);SOFIAPUBFUN int msg_numeric_e(char [], int, msg_header_t const *, int);SOFIAPUBFUN int msg_list_d(su_home_t *, msg_header_t *h, char *s, int slen);SOFIAPUBFUN int msg_list_e(char [], int, msg_header_t const *, int);SOFIAPUBFUN int msg_list_dup_xtra(msg_header_t const *h, int offset);SOFIAPUBFUN char *msg_list_dup_one(msg_header_t *dst,				   msg_header_t const *src,				   char *b, int xtra);SOFIAPUBFUN int msg_generic_d(su_home_t *, msg_header_t *, char *, int n);SOFIAPUBFUN int msg_generic_e(char [], int, msg_header_t const *, int);SOFIAPUBFUN int msg_generic_dup_xtra(msg_header_t const *h, int offset);SOFIAPUBFUN char *msg_generic_dup_one(msg_header_t *dst,				      msg_header_t const *src,				      char *b, 				      int xtra);SOFIAPUBFUN int msg_unknown_dup_xtra(msg_header_t const *h, int offset);SOFIAPUBFUN char *msg_unknown_dup_one(msg_header_t *dst,				      msg_header_t const *src,				      char *b, int xtra);SOFIAPUBFUN int msg_error_dup_xtra(msg_header_t const *h, int offset);SOFIAPUBFUN char *msg_error_dup_one(msg_header_t *dst,				    msg_header_t const *src,				    char *b, int xtra);SOFIAPUBFUN int msg_payload_d(su_home_t *, msg_header_t *h, char *s, int slen);SOFIAPUBFUN int msg_payload_e(char b[], int bsiz, msg_header_t const *, int f);SOFIAPUBFUN int msg_payload_dup_xtra(msg_header_t const *h, int offset);SOFIAPUBFUN char *msg_payload_dup_one(msg_header_t *dst,				      msg_header_t const *src,				      char *b, int xtra);SOFIAPUBFUN int msg_separator_d(su_home_t *, msg_header_t *, char *, int);SOFIAPUBFUN int msg_separator_e(char [], int, msg_header_t const *, int);SOFIAPUBFUN int msg_auth_d(su_home_t *, msg_header_t *h, char *s, int slen);SOFIAPUBFUN int msg_auth_e(char b[], int bsiz, msg_header_t const *h, int f);SOFIAPUBFUN int msg_auth_dup_xtra(msg_header_t const *h, int offset);SOFIAPUBFUN char *msg_auth_dup_one(msg_header_t *dst, msg_header_t const *src, 				   char *b, int xtra);/* --------------------------------------------------------------------------- * 2) Macros and prototypes for building header decoding/encoding functions. */#define MSG_HEADER_DATA(h) ((char *)(h) + (h)->sh_class->hc_size)#define MSG_HEADER_TEST(h) ((h) && (h)->sh_class)su_inline void *msg_header_data(msg_frg_t *h);SOFIAPUBFUN int msg_hostport_d(char **ss,			       char const **return_host,			       char const **return_port);SOFIAPUBFUN int msg_token_d(char **ss, char const **return_token);SOFIAPUBFUN int msg_uint32_d(char **ss, uint32_t *return_value);SOFIAPUBFUN int msg_comment_d(char **ss, char const **return_comment);SOFIAPUBFUN int msg_quoted_d(char **ss, char **return_unquoted);SOFIAPUBFUN int msg_unquoted_e(char *b, int bsiz, char const *s);/** Terminate encoding. @HI */#define MSG_TERM_E(p, e) ((p) < (e) ? (p)[0] = '\0' : '\0')/** Encode a character. @HI */#define MSG_CHAR_E(p, e, c) (++(p) < (e) ? ((p)[-1]=(c)) : (c)) /** Calculate separator and string length. @HI */#define MSG_STRING_LEN(s, sep_size) ((s) ? (strlen(s) + sep_size) : 0)/** Encode a string. @HI */#define MSG_STRING_E(p, e, s) do { \  int _n = strlen(s); if (p + _n+1 < e) memcpy(p, s, _n+1); p+= _n; } while(0)/** Duplicate string. @HI */#define MSG_STRING_DUP(p, d, s) \  (void)((s)?((p)=(char*)memccpy((void *)((d)=(char*)p),(s),0,0x7fffffff))\	    :((d)=NULL))/** Calculate string size. @HI */#define MSG_STRING_SIZE(s) ((s) ? (strlen(s) + 1) : 0)SOFIAPUBFUN int msg_commalist_d(su_home_t *, char **ss,				msg_param_t **return_list,				int (*scanner)(char *s));SOFIAPUBFUN int msg_token_scan(char *start);SOFIAPUBFUN int msg_attribute_value_scanner(char *s);SOFIAPUBFUN int msg_any_list_d(su_home_t *, char **ss, 			       msg_param_t **retval,			       int (*scanner)(char *s), int sep);/** Encode a comma-separated parameter list */#define MSG_COMMALIST_E(b, end, params, compact) do { \  char const * const *p_; char const * c_ = ""; \  for (p_ = (params); p_ && *p_; p_++, c_ = (compact ? "," : ", ")) \    { MSG_STRING_E(b, (end), c_); MSG_STRING_E(b, (end), *p_); } \} while(0)/* Parameter lists */SOFIAPUBFUN int msg_header_update_params(msg_common_t *h, int clear);/** Match a parameter with any value. @HI */#define MSG_PARAM_MATCH(v, s, name) \  (strncasecmp(s, name "=", sizeof(name)) == 0 ? (v = s + sizeof(name)) : NULL)/** Match a parameter with known value. @HI */#define MSG_PARAM_MATCH_P(v, s, name) \  ((strncasecmp((s), name "", sizeof(name) - 1) == 0 &&			\    ((s)[sizeof(name) - 1] == '=' || (s)[sizeof(name) - 1] == '\0')) ? \   ((v) = 1) : 0)/** Calculate allocated number of items in parameter list. @HI */#define MSG_PARAMS_NUM(n) ((((n) + MSG_N_PARAMS - 1 )&-MSG_N_PARAMS))/** Parse a semicolong-separated attribute-value list. @HI */SOFIAPUBFUN int msg_avlist_d(su_home_t *, char **ss,			     msg_param_t const **return_params);/** Parse a semicolon-separated parameter list starting with semicolon. @HI */SOFIAPUBFUN int msg_params_d(su_home_t *, char **ss,			     msg_param_t const **return_params);/** Encode a list of parameters. */SOFIAPUBFUN int msg_params_e(char b[], int bsiz, msg_param_t const pparams[]);/** Join list of parameters */SOFIAPUBFUN int msg_params_join(su_home_t *,				msg_param_t **dst,				msg_param_t const *src,				unsigned prune,				int dup);/** Encode a list of parameters. @HI */#define MSG_PARAMS_E(b, end, params, flags) \  b += msg_params_e(b, b < end ? end - b : 0, params)/** Calculate extra size of parametes. @HI */#define MSG_PARAMS_SIZE(rv, params) (rv = msg_params_dup_xtra(params, rv))/** Duplicate a parameter list */SOFIAPUBFUN char *msg_params_dup(msg_param_t const **d, msg_param_t const *s, 				 char *b, int xtra);/** Count number of parameters in the list */su_inline int msg_params_count(msg_param_t const params[]){  if (params) {    int n;    for (n = 0; params[n]; n++)      ;    return n;  }  else {    return 0;  }}/** Calculate memory size required by parameter list */su_inline int msg_params_dup_xtra(msg_param_t const params[], int offset){  int n = msg_params_count(params);  if (n) {    MSG_STRUCT_SIZE_ALIGN(offset);    offset += MSG_PARAMS_NUM(n + 1) * sizeof(msg_param_t);    for (n = 0; params[n]; n++)      offset += strlen(params[n]) + 1;  }  return offset;}/** Return pointer to extra data after header structure */su_inline void *msg_header_data(msg_frg_t *h){  if (h)    return (char *)h + h->h_class->hc_size;  else    return NULL;}SOFIA_END_DECLS#endif /** MSG_PARSER_H */

⌨️ 快捷键说明

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