浏览代码

parser: Add parser for Min-Expires

Alex Hermann 9 年之前
父节点
当前提交
2cf3641354
共有 6 个文件被更改,包括 50 次插入16 次删除
  1. 31 16
      parser/case_min.h
  2. 4 0
      parser/hf.c
  3. 3 0
      parser/hf.h
  4. 5 0
      parser/msg_parser.c
  5. 1 0
      parser/msg_parser.h
  6. 6 0
      sip_msg_clone.c

+ 31 - 16
parser/case_min.h

@@ -31,22 +31,37 @@
 #define CASE_MIN_H
 #define CASE_MIN_H
 
 
 
 
-#define min_se_CASE                  \
-        if (LOWER_BYTE(*p) == 's') {                       \
-                p++;                                       \
-                if (LOWER_BYTE(*p) == 'e') {               \
-                        hdr->type = HDR_MIN_SE_T;          \
-                        p++;                               \
-                        goto dc_end;                       \
-                }                                          \
-        }
-
-
-#define min_CASE       \
-     p += 4;           \
-     val = READ(p);    \
-     min_se_CASE;      \
-     goto other;       \
+#define RES_CASE                            \
+	switch(LOWER_DWORD(val)) {              \
+		case _res1_:    /* "res:" */        \
+			hdr->type = HDR_MIN_EXPIRES_T;  \
+			hdr->name.len = 11;             \
+			return (p + 4);                 \
+		case _res2_:    /* "res " */        \
+			hdr->type = HDR_MIN_EXPIRES_T;  \
+			p+=4;                           \
+			goto dc_end;                    \
+	}
+
+#define MIN2_CASE                           \
+	if (LOWER_BYTE(*p) == 's') {            \
+		p++;                                \
+		if (LOWER_BYTE(*p) == 'e') {        \
+			hdr->type = HDR_MIN_SE_T;       \
+			p++;                            \
+			goto dc_end;                    \
+		}                                   \
+	} else if (LOWER_DWORD(val) == _expi_) { \
+		p += 4;                             \
+		val = READ(p);                      \
+		RES_CASE;                           \
+	}
+
+#define min_CASE                            \
+	p += 4;                                 \
+	val = READ(p);                          \
+	MIN2_CASE;                              \
+	goto other;
 
 
 
 
 #endif /* CASE_MIN_H */
 #endif /* CASE_MIN_H */

+ 4 - 0
parser/hf.c

@@ -98,6 +98,10 @@ void clean_hdr_field(struct hdr_field* const hf)
 			free_expires((exp_body_t**)h_parsed);
 			free_expires((exp_body_t**)h_parsed);
 			break;
 			break;
 
 
+		case HDR_MIN_EXPIRES_T:
+			free_expires((exp_body_t**)h_parsed);
+			break;
+
 		case HDR_FROM_T:
 		case HDR_FROM_T:
 			free_to(hf->parsed);
 			free_to(hf->parsed);
 			break;
 			break;

+ 3 - 0
parser/hf.h

@@ -65,6 +65,7 @@ enum _hdr_types_t {
 	HDR_CONTENTLENGTH_T			       /*!< Content-Length header field */,
 	HDR_CONTENTLENGTH_T			       /*!< Content-Length header field */,
 	HDR_AUTHORIZATION_T			       /*!< Authorization header field */,
 	HDR_AUTHORIZATION_T			       /*!< Authorization header field */,
 	HDR_EXPIRES_T				       /*!< Expires header field */,
 	HDR_EXPIRES_T				       /*!< Expires header field */,
+	HDR_MIN_EXPIRES_T			       /*!< Min-Expires header */,
 	HDR_PROXYAUTH_T				       /*!< Proxy-Authorization hdr field */,
 	HDR_PROXYAUTH_T				       /*!< Proxy-Authorization hdr field */,
 	HDR_SUPPORTED_T				       /*!< Supported  header field */,
 	HDR_SUPPORTED_T				       /*!< Supported  header field */,
 	HDR_REQUIRE_T				       /*!< Require header */,
 	HDR_REQUIRE_T				       /*!< Require header */,
@@ -137,6 +138,7 @@ typedef unsigned long long hdr_flags_t;
 #define HDR_CONTENTLENGTH_F			HDR_F_DEF(CONTENTLENGTH)
 #define HDR_CONTENTLENGTH_F			HDR_F_DEF(CONTENTLENGTH)
 #define HDR_AUTHORIZATION_F			HDR_F_DEF(AUTHORIZATION)
 #define HDR_AUTHORIZATION_F			HDR_F_DEF(AUTHORIZATION)
 #define HDR_EXPIRES_F				HDR_F_DEF(EXPIRES)
 #define HDR_EXPIRES_F				HDR_F_DEF(EXPIRES)
+#define HDR_MIN_EXPIRES_F			HDR_F_DEF(MIN_EXPIRES)
 #define HDR_PROXYAUTH_F				HDR_F_DEF(PROXYAUTH)
 #define HDR_PROXYAUTH_F				HDR_F_DEF(PROXYAUTH)
 #define HDR_SUPPORTED_F				HDR_F_DEF(SUPPORTED)
 #define HDR_SUPPORTED_F				HDR_F_DEF(SUPPORTED)
 #define HDR_REQUIRE_F				HDR_F_DEF(REQUIRE)
 #define HDR_REQUIRE_F				HDR_F_DEF(REQUIRE)
@@ -217,6 +219,7 @@ static inline int hdr_allocs_parse(struct hdr_field* hdr)
 		case HDR_DIVERSION_T:
 		case HDR_DIVERSION_T:
 		case HDR_EVENT_T:
 		case HDR_EVENT_T:
 		case HDR_EXPIRES_T:
 		case HDR_EXPIRES_T:
+		case HDR_MIN_EXPIRES_T:
 		case HDR_FROM_T:
 		case HDR_FROM_T:
 		case HDR_IDENTITY_INFO_T:
 		case HDR_IDENTITY_INFO_T:
 		case HDR_IDENTITY_T:
 		case HDR_IDENTITY_T:

+ 5 - 0
parser/msg_parser.c

@@ -212,6 +212,7 @@ char* get_hdr_field(char* const buf, char* const end, struct hdr_field* const hd
 		case HDR_MAXFORWARDS_T:
 		case HDR_MAXFORWARDS_T:
 		case HDR_AUTHORIZATION_T:
 		case HDR_AUTHORIZATION_T:
 		case HDR_EXPIRES_T:
 		case HDR_EXPIRES_T:
+		case HDR_MIN_EXPIRES_T:
 		case HDR_PROXYAUTH_T:
 		case HDR_PROXYAUTH_T:
 		case HDR_PROXYREQUIRE_T:
 		case HDR_PROXYREQUIRE_T:
 		case HDR_UNSUPPORTED_T:
 		case HDR_UNSUPPORTED_T:
@@ -406,6 +407,10 @@ int parse_headers(struct sip_msg* const msg, const hdr_flags_t flags, const int
 				if (msg->expires==0) msg->expires = hf;
 				if (msg->expires==0) msg->expires = hf;
 				msg->parsed_flag|=HDR_EXPIRES_F;
 				msg->parsed_flag|=HDR_EXPIRES_F;
 				break;
 				break;
+			case HDR_MIN_EXPIRES_T:
+				if (msg->min_expires==0) msg->min_expires = hf;
+				msg->parsed_flag|=HDR_MIN_EXPIRES_F;
+				break;
 			case HDR_PROXYAUTH_T:
 			case HDR_PROXYAUTH_T:
 				if (msg->proxy_auth==0) msg->proxy_auth = hf;
 				if (msg->proxy_auth==0) msg->proxy_auth = hf;
 				msg->parsed_flag|=HDR_PROXYAUTH_F;
 				msg->parsed_flag|=HDR_PROXYAUTH_F;

+ 1 - 0
parser/msg_parser.h

@@ -318,6 +318,7 @@ typedef struct sip_msg {
 	struct hdr_field* ppi;
 	struct hdr_field* ppi;
 	struct hdr_field* path;
 	struct hdr_field* path;
 	struct hdr_field* privacy;
 	struct hdr_field* privacy;
+	struct hdr_field* min_expires;
 
 
 	struct msg_body* body;
 	struct msg_body* body;
 
 

+ 6 - 0
sip_msg_clone.c

@@ -442,6 +442,7 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
 		case HDR_CONTENTLENGTH_T:
 		case HDR_CONTENTLENGTH_T:
 		case HDR_RETRY_AFTER_T:
 		case HDR_RETRY_AFTER_T:
 		case HDR_EXPIRES_T:
 		case HDR_EXPIRES_T:
+		case HDR_MIN_EXPIRES_T:
 		case HDR_SUPPORTED_T:
 		case HDR_SUPPORTED_T:
 		case HDR_REQUIRE_T:
 		case HDR_REQUIRE_T:
 		case HDR_PROXYREQUIRE_T:
 		case HDR_PROXYREQUIRE_T:
@@ -772,6 +773,11 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
 				new_msg->expires = new_hdr;
 				new_msg->expires = new_hdr;
 			}
 			}
 			break;
 			break;
+		case HDR_MIN_EXPIRES_T:
+			if (!HOOK_SET(min_expires)) {
+				new_msg->min_expires = new_hdr;
+			}
+			break;
 		case HDR_PROXYAUTH_T:
 		case HDR_PROXYAUTH_T:
 			if (!HOOK_SET(proxy_auth)) {
 			if (!HOOK_SET(proxy_auth)) {
 				new_msg->proxy_auth = new_hdr;
 				new_msg->proxy_auth = new_hdr;