Browse code

core: kemi - exported is_myself()

Daniel-Constantin Mierla authored on 20/04/2016 14:58:09
Showing 2 changed files
... ...
@@ -24,10 +24,12 @@
24 24
 #include <stdlib.h>
25 25
 
26 26
 #include "dprint.h"
27
+#include "forward.h"
27 28
 #include "locking.h"
28 29
 #include "data_lump.h"
29 30
 #include "data_lump_rpl.h"
30 31
 #include "mem/shm.h"
32
+#include "parser/parse_uri.h"
31 33
 
32 34
 #include "kemi.h"
33 35
 
... ...
@@ -98,6 +100,34 @@ static int sr_kemi_core_drop(sip_msg_t *msg)
98 98
 /**
99 99
  *
100 100
  */
101
+static int sr_kemi_core_is_myself(sip_msg_t *msg, str *uri)
102
+{
103
+	struct sip_uri puri;
104
+	int ret;
105
+
106
+	if(uri==NULL || uri->s==NULL) {
107
+		return SR_KEMI_FALSE;
108
+	}
109
+	if(uri->len>4 && (strncmp(uri->s, "sip:", 4)==0
110
+				|| strncmp(uri->s, "sips:", 5)==0)) {
111
+		if(parse_uri(uri->s, uri->len, &puri)!=0) {
112
+			LM_ERR("failed to parse uri [%.*s]\n", uri->len, uri->s);
113
+			return SR_KEMI_FALSE;
114
+		}
115
+		ret = check_self(&puri.host, (puri.port.s)?puri.port_no:0,
116
+				(puri.transport_val.s)?puri.proto:0);
117
+	} else {
118
+		ret = check_self(uri, 0, 0);
119
+	}
120
+	if(ret==1) {
121
+		return SR_KEMI_TRUE;
122
+	}
123
+	return SR_KEMI_FALSE;
124
+}
125
+
126
+/**
127
+ *
128
+ */
101 129
 static sr_kemi_t _sr_kemi_core[] = {
102 130
 	{ str_init(""), str_init("dbg"),
103 131
 		SR_KEMIP_NONE, sr_kemi_core_dbg,
... ...
@@ -119,6 +149,11 @@ static sr_kemi_t _sr_kemi_core[] = {
119 119
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
120 120
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
121 121
 	},
122
+	{ str_init(""), str_init("is_myself"),
123
+		SR_KEMIP_BOOL, sr_kemi_core_is_myself,
124
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
125
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
126
+	},
122 127
 
123 128
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
124 129
 };
... ...
@@ -31,6 +31,9 @@
31 31
 #define SR_KEMIP_STR	(1<<1)	/* type str* */
32 32
 #define SR_KEMIP_BOOL	(1<<2)	/* type boolean (0/1) */
33 33
 
34
+#define SR_KEMI_FALSE	0
35
+#define SR_KEMI_TRUE	1
36
+
34 37
 #define SR_KEMI_PARAMS_MAX	6
35 38
 
36 39
 typedef struct sr_kemi {