Browse code

added function supports_extension for search within Supported headers

Vaclav Kubart authored on 22/06/2006 10:24:24
Showing 3 changed files
... ...
@@ -1,3 +1,6 @@
1
+2006-06-22
2
+	* added function supports_extension
3
+
1 4
 2006-06-21
2 5
 	* corrected bug in get_expiration_value (result was always -1/1)
3 6
 	* is_terminating_notify changed to use Subscription-State parser
... ...
@@ -4,6 +4,9 @@
4 4
 #include <cds/sstr.h>
5 5
 #include <parser/parse_expires.h>
6 6
 #include <parser/parse_subscription_state.h>
7
+#include <parser/parser_f.h>
8
+#include <trim.h>
9
+
7 10
 
8 11
 int get_expiration_value(struct sip_msg *m, int *value)
9 12
 {
... ...
@@ -54,4 +57,58 @@ int is_terminating_notify(struct sip_msg *m)
54 57
 	return 0;
55 58
 }
56 59
 
60
+static inline int contains_extension_support(struct hdr_field *h, 
61
+		str *extension)
62
+{
63
+	/* "parses" Supported header and looks for extension */
64
+	str s, val;
65
+	char *c;
66
+	
67
+	if (!h) return 0;
68
+
69
+	s = h->body;
70
+	while (s.len > 0) {
71
+		c = find_not_quoted(&s, ',');
72
+		if (c) {
73
+			val.s = s.s;
74
+			val.len = c - val.s;
75
+			trim(&val);
76
+			if (str_case_equals(&val, extension) == 0) return 1;
77
+			s.len = s.len - (c - s.s) - 1;
78
+			s.s = c + 1;
79
+		}
80
+		else {
81
+			trim(&s);
82
+			if (str_case_equals(&s, extension) == 0) return 1;
83
+			break;
84
+		}
85
+	}
86
+	return 0;
87
+}
88
+
89
+int supports_extension(struct sip_msg *m, str *extension)
90
+{
91
+	/* walk through all Supported headers */
92
+	struct hdr_field *h;
93
+	int res;
94
+
95
+	/* we need all Supported headers, Min-SE, 
96
+	 * Session-Expires */
97
+	res = parse_headers(m, HDR_EOH_F, 0);
98
+	if (res == -1) {
99
+		ERR("Error while parsing headers (%d)\n", res);
100
+		return 0; /* what to return here ? */
101
+	}
102
+	
103
+	h = m->supported;
104
+	while (h) {
105
+		if (h->type == HDR_SUPPORTED_T) {
106
+			if (contains_extension_support(h, extension)) return 1;
107
+		}
108
+		h = h->next;
109
+	}
110
+	return 0;
111
+}
112
+
113
+
57 114
 #endif
... ...
@@ -12,6 +12,10 @@ int get_expiration_value(struct sip_msg *m, int *value);
12 12
 /* returns 1 if the message has Subscription-Status: terminated (hack!) */
13 13
 int is_terminating_notify(struct sip_msg *m);
14 14
 
15
+/* returns 1 if given extension is in Supported headers, 
16
+ * 0 if not or an error occured while parsing */
17
+int supports_extension(struct sip_msg *m, str *extension);
18
+
15 19
 #endif
16 20
 
17 21
 #endif