Browse code

"hacked" version of is_terminating_notify replaced by correct one

Vaclav Kubart authored on 21/06/2006 13:59:01
Showing 2 changed files
... ...
@@ -1,5 +1,6 @@
1 1
 2006-06-21
2 2
 	* corrected bug in get_expiration_value (result was always -1/1)
3
+	* is_terminating_notify changed to use Subscription-State parser
3 4
 
4 5
 2006-06-13
5 6
 	* added few common SIP/SER functions into sip_utils.h
... ...
@@ -3,6 +3,7 @@
3 3
 #include <cds/sip_utils.h>
4 4
 #include <cds/sstr.h>
5 5
 #include <parser/parse_expires.h>
6
+#include <parser/parse_subscription_state.h>
6 7
 
7 8
 int get_expiration_value(struct sip_msg *m, int *value)
8 9
 {
... ...
@@ -28,26 +29,29 @@ int get_expiration_value(struct sip_msg *m, int *value)
28 29
 
29 30
 int is_terminating_notify(struct sip_msg *m)
30 31
 {
31
-	int res = 0;
32
-	struct hdr_field *h;
33
-	static str ss = STR_STATIC_INIT("Subscription-State");
34
-	static str terminated = STR_STATIC_INIT("terminated");
35
-
36
-	if (parse_headers(m, HDR_EOH_F, 0) == -1) {
37
-		ERR("can't parse NOTIFY message\n");
38
-		return 0;
32
+	subscription_state_t *ss;
33
+
34
+	if (parse_headers(m, HDR_SUBSCRIPTION_STATE_F, 0) == -1) {
35
+		ERR("Error while parsing headers\n");
36
+		return 0; /* ignore */
39 37
 	}
40
-	h = m->headers;
41
-	while (h) {
42
-		/* try to find Subscription-Status with "terminated" */
43
-		if (str_nocase_equals(&h->name, &ss) == 0) {
44
-			if (str_str(&h->body, &terminated)) return 1;
45
-			else return 0;
46
-		}
47
-		h = h->next;
38
+	if (!m->subscription_state) {
39
+		ERR("Invalid NOTIFY request (without Subscription-State)\n");
40
+		return 0; /* ignore */
41
+	}
42
+	if (parse_subscription_state(m->subscription_state) < 0) {
43
+		ERR("can't parse Subscription-State\n");
44
+		return 0; /* ignore */
48 45
 	}
46
+	ss = (subscription_state_t*)m->subscription_state->parsed;
47
+	if (!ss) {
48
+		ERR("invalid Subscription-State\n");
49
+		return 0; /* ignore */
50
+	}
51
+	
52
+	if (ss->value == ss_terminated) return 1;
49 53
 
50
-	return res;
54
+	return 0;
51 55
 }
52 56
 
53 57
 #endif