فهرست منبع

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

Vaclav Kubart 19 سال پیش
والد
کامیت
110e298d0d
4فایلهای تغییر یافته به همراه73 افزوده شده و 0 حذف شده
  1. 3 0
      lib/cds/ChangeLog
  2. 1 0
      lib/cds/ser_profile.c
  3. 52 0
      lib/cds/sip_utils.c
  4. 17 0
      lib/cds/sip_utils.h

+ 3 - 0
lib/cds/ChangeLog

@@ -1,3 +1,6 @@
+2006-06-13
+	* added few common SIP/SER functions into sip_utils.h
+
 2006-05-11
 	* added changelog
 	* added "simple profiling" capability (need to call PROF_START and

+ 1 - 0
lib/cds/ser_profile.c

@@ -84,6 +84,7 @@ void trace_func()
 	
 void ser_profile_init()
 {
+	WARN("initializing profiler\n");
 	start_profile(trace_func);
 }
 

+ 52 - 0
lib/cds/sip_utils.c

@@ -0,0 +1,52 @@
+#ifdef SER
+
+#include <cds/sip_utils.h>
+#include <cds/sstr.h>
+#include <parser/parse_expires.h>
+
+int get_expiration_value(struct sip_msg *m, int *value)
+{
+	exp_body_t *expires = NULL;
+	int res = 1;
+
+	if (parse_headers(m, HDR_EXPIRES_F, 0) == -1) {
+		/* can't parse expires header */
+		return -1;
+	}
+	if (m->expires) {
+		if (parse_expires(m->expires) < 0) {
+			return -1;
+		}
+
+		expires = (exp_body_t *)m->expires->parsed;
+		if (expires) if (expires->valid && value) *value = expires->val;
+	}
+	/* ERR("subscription will expire in %d secs\n", e); */
+	return res;
+}
+
+int is_terminating_notify(struct sip_msg *m)
+{
+	int res = 0;
+	struct hdr_field *h;
+	static str ss = STR_STATIC_INIT("Subscription-State");
+	static str terminated = STR_STATIC_INIT("terminated");
+
+	if (parse_headers(m, HDR_EOH_F, 0) == -1) {
+		ERR("can't parse NOTIFY message\n");
+		return 0;
+	}
+	h = m->headers;
+	while (h) {
+		/* try to find Subscription-Status with "terminated" */
+		if (str_nocase_equals(&h->name, &ss) == 0) {
+			if (str_str(&h->body, &terminated)) return 1;
+			else return 0;
+		}
+		h = h->next;
+	}
+
+	return res;
+}
+
+#endif

+ 17 - 0
lib/cds/sip_utils.h

@@ -0,0 +1,17 @@
+#ifndef __COMMON_SIP_UTILS_H
+#define __COMMON_SIP_UTILS_H
+
+#ifdef SER /* SER only helper routines */
+
+#include <parser/msg_parser.h>
+
+/* returns negative value on error, positive when message contains 
+ * no Expires header and 0 if everything ok */
+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);
+
+#endif
+
+#endif