[sr-dev] git:master:21817906: geoip2: new parameter to register result id to get pv work in kemi

Daniel-Constantin Mierla miconda at gmail.com
Wed Nov 30 09:35:52 CET 2022


Module: kamailio
Branch: master
Commit: 21817906853140322c701f8cbb8201049d2b58f0
URL: https://github.com/kamailio/kamailio/commit/21817906853140322c701f8cbb8201049d2b58f0

Author: Vadim Gaysin <gaysin at zvonok.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2022-11-30T09:31:45+01:00

geoip2: new parameter to register result id to get pv work in kemi

---

Modified: src/modules/geoip2/doc/geoip2_admin.xml
Modified: src/modules/geoip2/geoip2_mod.c
Modified: src/modules/geoip2/geoip2_pv.c
Modified: src/modules/geoip2/geoip2_pv.h

---

Diff:  https://github.com/kamailio/kamailio/commit/21817906853140322c701f8cbb8201049d2b58f0.diff
Patch: https://github.com/kamailio/kamailio/commit/21817906853140322c701f8cbb8201049d2b58f0.patch

---

diff --git a/src/modules/geoip2/doc/geoip2_admin.xml b/src/modules/geoip2/doc/geoip2_admin.xml
index a82b1a9a293..76e59055fa2 100644
--- a/src/modules/geoip2/doc/geoip2_admin.xml
+++ b/src/modules/geoip2/doc/geoip2_admin.xml
@@ -81,7 +81,7 @@
     </section>
     <section>
 	<title>Parameters</title>
-	<section>
+	<section id="geoip2.p.path">
 	    <title><varname>path</varname> (string)</title>
 	    <para>
 		Path to the GeoIP2 database file.
@@ -100,7 +100,31 @@ modparam("geoip2", "path", "/usr/local/share/GeoIP/GeoLite2-City.mmdb")
 </programlisting>
 	    </example>
 	</section>
-
+	<section id="geoip2.p.resid">
+	    <title><varname>resid</varname> (str)</title>
+	    <para>
+		Preregister result container id during initialization, enabling the use
+		of the module in KEMI scripts. In native &kamailio;.cfg file, registration
+		is done when parsing config and finding variables.
+	    </para>
+	    <para>
+		<emphasis>
+		    Default value is <quote></quote> (empty).
+		</emphasis>
+	    </para>
+	    <example>
+		<title>Set <varname>resid</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("geoip2", "resid", "src")
+...
+if(geoip2_match("$si", "src")) {
+   ...
+}
+...
+</programlisting>
+	    </example>
+	</section>
 	</section>
 	
     <section>
diff --git a/src/modules/geoip2/geoip2_mod.c b/src/modules/geoip2/geoip2_mod.c
index 96285592425..b5b5e7db6c4 100644
--- a/src/modules/geoip2/geoip2_mod.c
+++ b/src/modules/geoip2/geoip2_mod.c
@@ -44,6 +44,7 @@ static int geoip2_rpc_init(void);
 
 static int w_geoip2_match(struct sip_msg* msg, char* str1, char* str2);
 static int geoip2_match(sip_msg_t *msg, str *tomatch, str *pvclass);
+static int geoip2_resid_param(modparam_t type, void* val);
 
 static pv_export_t mod_pvs[] = {
 	{ {"gip2", sizeof("gip2")-1}, PVT_OTHER, pv_get_geoip2, 0,
@@ -51,7 +52,6 @@ static pv_export_t mod_pvs[] = {
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
 };
 
-
 static cmd_export_t cmds[]={
 	{"geoip2_match", (cmd_function)w_geoip2_match, 2, fixup_spve_spve,
 		0, ANY_ROUTE},
@@ -59,7 +59,8 @@ static cmd_export_t cmds[]={
 };
 
 static param_export_t params[]={
-	{"path",     PARAM_STRING, &geoip2_path},
+	{"path",  PARAM_STRING, &geoip2_path},
+	{"resid", PARAM_STR|PARAM_USE_FUNC, &geoip2_resid_param},
 	{0, 0, 0}
 };
 
@@ -76,7 +77,6 @@ struct module_exports exports = {
 	mod_destroy			/* module destroy function */
 };
 
-
 /**
  * init module function
  */
@@ -113,6 +113,19 @@ static void mod_destroy(void)
 	geoip2_destroy_pv();
 }
 
+static int geoip2_resid_param(modparam_t type, void* val)
+{
+	str rname;
+
+	rname = *((str*)val);
+	if(sr_geoip2_add_resid(&rname) < 0) {
+		LM_ERR("failed to register result container with id: %.*s\n",
+				rname.len, rname.s);
+		return -1;
+	}
+	return 0;
+}
+
 static int geoip2_match(sip_msg_t *msg, str *tomatch, str *pvclass)
 {
 	geoip2_pv_reset(pvclass);
@@ -192,4 +205,4 @@ static sr_kemi_t sr_kemi_geoip2_exports[] = {
 int mod_register(char *path, int *dlflags, void *p1, void *p2) {
     sr_kemi_modules_add(sr_kemi_geoip2_exports);
     return 0;
-}
\ No newline at end of file
+}
diff --git a/src/modules/geoip2/geoip2_pv.c b/src/modules/geoip2/geoip2_pv.c
index ff427f259f6..71b814e9ad3 100644
--- a/src/modules/geoip2/geoip2_pv.c
+++ b/src/modules/geoip2/geoip2_pv.c
@@ -124,6 +124,13 @@ sr_geoip2_item_t *sr_geoip2_add_item(str *name)
 	return it;
 }
 
+int sr_geoip2_add_resid(str *rname)
+{
+	if(sr_geoip2_add_item(rname)==NULL) {
+		return -1;
+	}
+	return 0;
+}
 
 int pv_parse_geoip2_name(pv_spec_p sp, str *in)
 {
diff --git a/src/modules/geoip2/geoip2_pv.h b/src/modules/geoip2/geoip2_pv.h
index d616461673a..fbd25c00440 100644
--- a/src/modules/geoip2/geoip2_pv.h
+++ b/src/modules/geoip2/geoip2_pv.h
@@ -35,6 +35,7 @@ void geoip2_destroy_pv(void);
 int geoip2_reload_pv(char *path);
 void geoip2_pv_reset(str *pvclass);
 int geoip2_update_pv(str *tomatch, str *pvclass);
+int sr_geoip2_add_resid(str *rname);
 
 #endif
 




More information about the sr-dev mailing list