Module: kamailio Branch: master Commit: fb1e1d847e6e6aeedb17949e7f871c966cca2c76 URL: https://github.com/kamailio/kamailio/commit/fb1e1d847e6e6aeedb17949e7f871c96...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2016-04-20T16:58:09+02:00
core: kemi - exported is_myself()
---
Modified: kemi.c Modified: kemi.h
---
Diff: https://github.com/kamailio/kamailio/commit/fb1e1d847e6e6aeedb17949e7f871c96... Patch: https://github.com/kamailio/kamailio/commit/fb1e1d847e6e6aeedb17949e7f871c96...
---
diff --git a/kemi.c b/kemi.c index 0bc6e3c..9c36d51 100644 --- a/kemi.c +++ b/kemi.c @@ -24,10 +24,12 @@ #include <stdlib.h>
#include "dprint.h" +#include "forward.h" #include "locking.h" #include "data_lump.h" #include "data_lump_rpl.h" #include "mem/shm.h" +#include "parser/parse_uri.h"
#include "kemi.h"
@@ -98,6 +100,34 @@ static int sr_kemi_core_drop(sip_msg_t *msg) /** * */ +static int sr_kemi_core_is_myself(sip_msg_t *msg, str *uri) +{ + struct sip_uri puri; + int ret; + + if(uri==NULL || uri->s==NULL) { + return SR_KEMI_FALSE; + } + if(uri->len>4 && (strncmp(uri->s, "sip:", 4)==0 + || strncmp(uri->s, "sips:", 5)==0)) { + if(parse_uri(uri->s, uri->len, &puri)!=0) { + LM_ERR("failed to parse uri [%.*s]\n", uri->len, uri->s); + return SR_KEMI_FALSE; + } + ret = check_self(&puri.host, (puri.port.s)?puri.port_no:0, + (puri.transport_val.s)?puri.proto:0); + } else { + ret = check_self(uri, 0, 0); + } + if(ret==1) { + return SR_KEMI_TRUE; + } + return SR_KEMI_FALSE; +} + +/** + * + */ static sr_kemi_t _sr_kemi_core[] = { { str_init(""), str_init("dbg"), SR_KEMIP_NONE, sr_kemi_core_dbg, @@ -119,6 +149,11 @@ static sr_kemi_t _sr_kemi_core[] = { { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init(""), str_init("is_myself"), + SR_KEMIP_BOOL, sr_kemi_core_is_myself, + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + },
{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } } }; diff --git a/kemi.h b/kemi.h index 3c9e0e1..bd3c19d 100644 --- a/kemi.h +++ b/kemi.h @@ -31,6 +31,9 @@ #define SR_KEMIP_STR (1<<1) /* type str* */ #define SR_KEMIP_BOOL (1<<2) /* type boolean (0/1) */
+#define SR_KEMI_FALSE 0 +#define SR_KEMI_TRUE 1 + #define SR_KEMI_PARAMS_MAX 6
typedef struct sr_kemi {