瀏覽代碼

added parsing of Require header field

Vaclav Kubart 19 年之前
父節點
當前提交
e696bf82db
共有 9 個文件被更改,包括 44 次插入2 次删除
  1. 3 0
      lib/cds/ChangeLog
  2. 23 2
      lib/cds/sip_utils.c
  3. 4 0
      lib/cds/sip_utils.h
  4. 3 0
      parser/hf.c
  5. 2 0
      parser/hf.h
  6. 5 0
      parser/msg_parser.c
  7. 1 0
      parser/msg_parser.h
  8. 2 0
      parser/parse_hname2.c
  9. 1 0
      parser/parse_subscription_state.c

+ 3 - 0
lib/cds/ChangeLog

@@ -1,3 +1,6 @@
+2006-06-23
+	* added function requires_extension
+
 2006-06-22
 	* added function supports_extension
 

+ 23 - 2
lib/cds/sip_utils.c

@@ -92,8 +92,7 @@ int supports_extension(struct sip_msg *m, str *extension)
 	struct hdr_field *h;
 	int res;
 
-	/* we need all Supported headers, Min-SE, 
-	 * Session-Expires */
+	/* we need all Supported headers */
 	res = parse_headers(m, HDR_EOH_F, 0);
 	if (res == -1) {
 		ERR("Error while parsing headers (%d)\n", res);
@@ -110,5 +109,27 @@ int supports_extension(struct sip_msg *m, str *extension)
 	return 0;
 }
 
+int requires_extension(struct sip_msg *m, str *extension)
+{
+	/* walk through all Require headers */
+	struct hdr_field *h;
+	int res;
+
+	/* we need all Require headers */
+	res = parse_headers(m, HDR_EOH_F, 0);
+	if (res == -1) {
+		ERR("Error while parsing headers (%d)\n", res);
+		return 0; /* what to return here ? */
+	}
+	
+	h = m->require;
+	while (h) {
+		if (h->type == HDR_REQUIRE_T) {
+			if (contains_extension_support(h, extension)) return 1;
+		}
+		h = h->next;
+	}
+	return 0;
+}
 
 #endif

+ 4 - 0
lib/cds/sip_utils.h

@@ -16,6 +16,10 @@ int is_terminating_notify(struct sip_msg *m);
  * 0 if not or an error occured while parsing */
 int supports_extension(struct sip_msg *m, str *extension);
 
+/* returns 1 if given extension is in Require headers, 
+ * 0 if not or an error occured while parsing */
+int requires_extension(struct sip_msg *m, str *extension);
+
 #endif
 
 #endif

+ 3 - 0
parser/hf.c

@@ -117,6 +117,9 @@ void clean_hdr_field(struct hdr_field* hf)
 		case HDR_SUPPORTED_T:
 			break;
 
+		case HDR_REQUIRE_T:
+			break;
+			
 		case HDR_PROXYREQUIRE_T:
 			break;
 

+ 2 - 0
parser/hf.h

@@ -71,6 +71,7 @@ enum _hdr_types_t {
 	HDR_EXPIRES_T				       /* Expires header field */,
 	HDR_PROXYAUTH_T				       /* Proxy-Authorization hdr field */,
 	HDR_SUPPORTED_T				       /* Supported  header field */,
+	HDR_REQUIRE_T					   /* Require header */,
 	HDR_PROXYREQUIRE_T			       /* Proxy-Require header field */,
 	HDR_UNSUPPORTED_T			       /* Unsupported header field */,
 	HDR_ALLOW_T					       /* Allow header field */,
@@ -131,6 +132,7 @@ typedef unsigned long long hdr_flags_t;
 #define HDR_EXPIRES_F				HDR_F_DEF(EXPIRES)
 #define HDR_PROXYAUTH_F				HDR_F_DEF(PROXYAUTH)
 #define HDR_SUPPORTED_F				HDR_F_DEF(SUPPORTED)
+#define HDR_REQUIRE_F				HDR_F_DEF(REQUIRE)
 #define HDR_PROXYREQUIRE_F			HDR_F_DEF(PROXYREQUIRE)
 #define HDR_UNSUPPORTED_F			HDR_F_DEF(UNSUPPORTED)
 #define HDR_ALLOW_F					HDR_F_DEF(ALLOW)

+ 5 - 0
parser/msg_parser.c

@@ -182,6 +182,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
 					(int)(long)hdr->parsed);
 			break;
 		case HDR_SUPPORTED_T:
+		case HDR_REQUIRE_T:
 		case HDR_CONTENTTYPE_T:
 		case HDR_FROM_T:
 		case HDR_CALLID_T:
@@ -381,6 +382,10 @@ int parse_headers(struct sip_msg* msg, hdr_flags_t flags, int next)
 				if (msg->supported==0) msg->supported=hf;
 				msg->parsed_flag|=HDR_SUPPORTED_F;
 				break;
+			case HDR_REQUIRE_T:
+				if (msg->require==0) msg->require=hf;
+				msg->parsed_flag|=HDR_REQUIRE_F;
+				break;
 			case HDR_UNSUPPORTED_T:
 				if (msg->unsupported==0) msg->unsupported=hf;
 				msg->parsed_flag|=HDR_UNSUPPORTED_F;

+ 1 - 0
parser/msg_parser.h

@@ -193,6 +193,7 @@ struct sip_msg {
 	struct hdr_field* expires;
 	struct hdr_field* proxy_auth;
 	struct hdr_field* supported;
+	struct hdr_field* require;
 	struct hdr_field* proxy_require;
 	struct hdr_field* unsupported;
 	struct hdr_field* allow;

+ 2 - 0
parser/parse_hname2.c

@@ -90,6 +90,7 @@ static inline char* skip_ws(char* p, unsigned int size)
 #include "case_reje.h"     /* Reject-Contact */
 #include "case_min.h"      /* Min-SE */
 #include "case_subs.h"     /* Subscription-State */
+#include "case_requ.h"     /* Require */
 
 
 #define READ(val) \
@@ -127,6 +128,7 @@ static inline char* skip_ws(char* p, unsigned int size)
 	case _sess_: sess_CASE; \
 	case _reje_: reje_CASE; \
 	case _min__: min_CASE;  \
+	case _requ_: requ_CASE;  \
 
 
 

+ 1 - 0
parser/parse_subscription_state.c

@@ -60,6 +60,7 @@ static int ss_parse(str *src, subscription_state_t *ss)
 	}
 
 	/* set state value */
+	trim(&state);
 	if (str_cmp(&state, &active) == 0) {
 		ss->value = ss_active;
 	}