Browse code

few common SIP/SER helper functions moved into CDS (needed elsewhere)

Vaclav Kubart authored on 13/06/2006 08:11:04
Showing 4 changed files
... ...
@@ -1,3 +1,6 @@
1
+2006-06-13
2
+	* added few common SIP/SER functions into sip_utils.h
3
+
1 4
 2006-05-11
2 5
 	* added changelog
3 6
 	* added "simple profiling" capability (need to call PROF_START and
... ...
@@ -84,6 +84,7 @@ void trace_func()
84 84
 	
85 85
 void ser_profile_init()
86 86
 {
87
+	WARN("initializing profiler\n");
87 88
 	start_profile(trace_func);
88 89
 }
89 90
 
90 91
new file mode 100644
... ...
@@ -0,0 +1,52 @@
1
+#ifdef SER
2
+
3
+#include <cds/sip_utils.h>
4
+#include <cds/sstr.h>
5
+#include <parser/parse_expires.h>
6
+
7
+int get_expiration_value(struct sip_msg *m, int *value)
8
+{
9
+	exp_body_t *expires = NULL;
10
+	int res = 1;
11
+
12
+	if (parse_headers(m, HDR_EXPIRES_F, 0) == -1) {
13
+		/* can't parse expires header */
14
+		return -1;
15
+	}
16
+	if (m->expires) {
17
+		if (parse_expires(m->expires) < 0) {
18
+			return -1;
19
+		}
20
+
21
+		expires = (exp_body_t *)m->expires->parsed;
22
+		if (expires) if (expires->valid && value) *value = expires->val;
23
+	}
24
+	/* ERR("subscription will expire in %d secs\n", e); */
25
+	return res;
26
+}
27
+
28
+int is_terminating_notify(struct sip_msg *m)
29
+{
30
+	int res = 0;
31
+	struct hdr_field *h;
32
+	static str ss = STR_STATIC_INIT("Subscription-State");
33
+	static str terminated = STR_STATIC_INIT("terminated");
34
+
35
+	if (parse_headers(m, HDR_EOH_F, 0) == -1) {
36
+		ERR("can't parse NOTIFY message\n");
37
+		return 0;
38
+	}
39
+	h = m->headers;
40
+	while (h) {
41
+		/* try to find Subscription-Status with "terminated" */
42
+		if (str_nocase_equals(&h->name, &ss) == 0) {
43
+			if (str_str(&h->body, &terminated)) return 1;
44
+			else return 0;
45
+		}
46
+		h = h->next;
47
+	}
48
+
49
+	return res;
50
+}
51
+
52
+#endif
0 53
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+#ifndef __COMMON_SIP_UTILS_H
2
+#define __COMMON_SIP_UTILS_H
3
+
4
+#ifdef SER /* SER only helper routines */
5
+
6
+#include <parser/msg_parser.h>
7
+
8
+/* returns negative value on error, positive when message contains 
9
+ * no Expires header and 0 if everything ok */
10
+int get_expiration_value(struct sip_msg *m, int *value);
11
+
12
+/* returns 1 if the message has Subscription-Status: terminated (hack!) */
13
+int is_terminating_notify(struct sip_msg *m);
14
+
15
+#endif
16
+
17
+#endif