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
 
... ...
@@ -95,6 +97,34 @@ static int sr_kemi_core_drop(sip_msg_t *msg)
95 97
 	return 0;
96 98
 }
97 99
 
100
+/**
101
+ *
102
+ */
103
+static int sr_kemi_core_is_myself(sip_msg_t *msg, str *uri)
104
+{
105
+	struct sip_uri puri;
106
+	int ret;
107
+
108
+	if(uri==NULL || uri->s==NULL) {
109
+		return SR_KEMI_FALSE;
110
+	}
111
+	if(uri->len>4 && (strncmp(uri->s, "sip:", 4)==0
112
+				|| strncmp(uri->s, "sips:", 5)==0)) {
113
+		if(parse_uri(uri->s, uri->len, &puri)!=0) {
114
+			LM_ERR("failed to parse uri [%.*s]\n", uri->len, uri->s);
115
+			return SR_KEMI_FALSE;
116
+		}
117
+		ret = check_self(&puri.host, (puri.port.s)?puri.port_no:0,
118
+				(puri.transport_val.s)?puri.proto:0);
119
+	} else {
120
+		ret = check_self(uri, 0, 0);
121
+	}
122
+	if(ret==1) {
123
+		return SR_KEMI_TRUE;
124
+	}
125
+	return SR_KEMI_FALSE;
126
+}
127
+
98 128
 /**
99 129
  *
100 130
  */
... ...
@@ -119,6 +149,11 @@ static sr_kemi_t _sr_kemi_core[] = {
119 149
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
120 150
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
121 151
 	},
152
+	{ str_init(""), str_init("is_myself"),
153
+		SR_KEMIP_BOOL, sr_kemi_core_is_myself,
154
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
155
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
156
+	},
122 157
 
123 158
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
124 159
 };
... ...
@@ -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 {