Module: sip-router
Branch: master
Commit: 8a88206ee66227657f827290df0e46119eedcd8d
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8a88206…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sun Nov 28 12:59:16 2010 +0100
kex: added new function is_myself(uri)
- return true if given parameter matches 'myself' condition, the
parameter can be a static string or pseduo-variables holding an IP or
a SIP URI
---
modules_k/kex/kex_mod.c | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/modules_k/kex/kex_mod.c b/modules_k/kex/kex_mod.c
index d86cfbd..d0d7525 100644
--- a/modules_k/kex/kex_mod.c
+++ b/modules_k/kex/kex_mod.c
@@ -26,9 +26,11 @@
#include "../../sr_module.h"
#include "../../dprint.h"
+#include "../../forward.h"
#include "../../flags.h"
#include "../../dset.h"
#include "../../mod_fix.h"
+#include "../../parser/parse_uri.h"
#include "flags.h"
#include "km_core.h"
@@ -42,6 +44,8 @@ MODULE_VERSION
/** parameters */
/** module functions */
+int w_is_myself(struct sip_msg *msg, char *uri, str *s2);
+
static int mod_init(void);
static void destroy(void);
@@ -78,6 +82,8 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE },
{"avp_printf", (cmd_function)w_pv_printf, 2, pv_printf_fixup,
0, ANY_ROUTE },
+ {"is_myself", (cmd_function)w_is_myself, 1, fixup_spve_null,
+ 0, ANY_ROUTE },
{0,0,0,0,0,0}
};
@@ -128,3 +134,35 @@ static void destroy(void)
}
+/**
+ *
+ */
+int w_is_myself(struct sip_msg *msg, char *uri, str *s2)
+{
+ int ret;
+ str suri;
+ struct sip_uri puri;
+
+ if(fixup_get_svalue(msg, (gparam_p)uri, &suri)!=0)
+ {
+ LM_ERR("cannot get the URI parameter\n");
+ return -1;
+ }
+ if(suri.len>4 && (strncmp(suri.s, "sip:", 4)==0
+ || strncmp(suri.s, "sips:", 5)==0))
+ {
+ if(parse_uri(suri.s, suri.len, &puri)!=0)
+ {
+ LM_ERR("failed to parse uri [%.*s]\n", suri.len, suri.s);
+ return -1;
+ }
+ ret = check_self(&puri.host, (puri.port.s)?puri.port_no:0,
+ (puri.transport_val.s)?puri.proto:0);
+ } else {
+ ret = check_self(&suri, 0, 0);
+ }
+ if(ret!=1)
+ return -1;
+ return 1;
+}
+