Jelajahi Sumber

added function supports_extension for search within Supported headers

Vaclav Kubart 19 tahun lalu
induk
melakukan
d86d839798
3 mengubah file dengan 64 tambahan dan 0 penghapusan
  1. 3 0
      lib/cds/ChangeLog
  2. 57 0
      lib/cds/sip_utils.c
  3. 4 0
      lib/cds/sip_utils.h

+ 3 - 0
lib/cds/ChangeLog

@@ -1,3 +1,6 @@
+2006-06-22
+	* added function supports_extension
+
 2006-06-21
 	* corrected bug in get_expiration_value (result was always -1/1)
 	* is_terminating_notify changed to use Subscription-State parser

+ 57 - 0
lib/cds/sip_utils.c

@@ -4,6 +4,9 @@
 #include <cds/sstr.h>
 #include <parser/parse_expires.h>
 #include <parser/parse_subscription_state.h>
+#include <parser/parser_f.h>
+#include <trim.h>
+
 
 int get_expiration_value(struct sip_msg *m, int *value)
 {
@@ -54,4 +57,58 @@ int is_terminating_notify(struct sip_msg *m)
 	return 0;
 }
 
+static inline int contains_extension_support(struct hdr_field *h, 
+		str *extension)
+{
+	/* "parses" Supported header and looks for extension */
+	str s, val;
+	char *c;
+	
+	if (!h) return 0;
+
+	s = h->body;
+	while (s.len > 0) {
+		c = find_not_quoted(&s, ',');
+		if (c) {
+			val.s = s.s;
+			val.len = c - val.s;
+			trim(&val);
+			if (str_case_equals(&val, extension) == 0) return 1;
+			s.len = s.len - (c - s.s) - 1;
+			s.s = c + 1;
+		}
+		else {
+			trim(&s);
+			if (str_case_equals(&s, extension) == 0) return 1;
+			break;
+		}
+	}
+	return 0;
+}
+
+int supports_extension(struct sip_msg *m, str *extension)
+{
+	/* walk through all Supported headers */
+	struct hdr_field *h;
+	int res;
+
+	/* we need all Supported headers, Min-SE, 
+	 * Session-Expires */
+	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->supported;
+	while (h) {
+		if (h->type == HDR_SUPPORTED_T) {
+			if (contains_extension_support(h, extension)) return 1;
+		}
+		h = h->next;
+	}
+	return 0;
+}
+
+
 #endif

+ 4 - 0
lib/cds/sip_utils.h

@@ -12,6 +12,10 @@ int get_expiration_value(struct sip_msg *m, int *value);
 /* returns 1 if the message has Subscription-Status: terminated (hack!) */
 int is_terminating_notify(struct sip_msg *m);
 
+/* returns 1 if given extension is in Supported headers, 
+ * 0 if not or an error occured while parsing */
+int supports_extension(struct sip_msg *m, str *extension);
+
 #endif
 
 #endif