Pārlūkot izejas kodu

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

Vadim Gaysin 2 gadi atpakaļ
vecāks
revīzija
2181790685

+ 26 - 2
src/modules/geoip2/doc/geoip2_admin.xml

@@ -81,7 +81,7 @@
     </section>
     </section>
     <section>
     <section>
 	<title>Parameters</title>
 	<title>Parameters</title>
-	<section>
+	<section id="geoip2.p.path">
 	    <title><varname>path</varname> (string)</title>
 	    <title><varname>path</varname> (string)</title>
 	    <para>
 	    <para>
 		Path to the GeoIP2 database file.
 		Path to the GeoIP2 database file.
@@ -100,7 +100,31 @@ modparam("geoip2", "path", "/usr/local/share/GeoIP/GeoLite2-City.mmdb")
 </programlisting>
 </programlisting>
 	    </example>
 	    </example>
 	</section>
 	</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>
 	
 	
     <section>
     <section>

+ 17 - 4
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 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_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[] = {
 static pv_export_t mod_pvs[] = {
 	{ {"gip2", sizeof("gip2")-1}, PVT_OTHER, pv_get_geoip2, 0,
 	{ {"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 }
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
 };
 };
 
 
-
 static cmd_export_t cmds[]={
 static cmd_export_t cmds[]={
 	{"geoip2_match", (cmd_function)w_geoip2_match, 2, fixup_spve_spve,
 	{"geoip2_match", (cmd_function)w_geoip2_match, 2, fixup_spve_spve,
 		0, ANY_ROUTE},
 		0, ANY_ROUTE},
@@ -59,7 +59,8 @@ static cmd_export_t cmds[]={
 };
 };
 
 
 static param_export_t params[]={
 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}
 	{0, 0, 0}
 };
 };
 
 
@@ -76,7 +77,6 @@ struct module_exports exports = {
 	mod_destroy			/* module destroy function */
 	mod_destroy			/* module destroy function */
 };
 };
 
 
-
 /**
 /**
  * init module function
  * init module function
  */
  */
@@ -113,6 +113,19 @@ static void mod_destroy(void)
 	geoip2_destroy_pv();
 	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)
 static int geoip2_match(sip_msg_t *msg, str *tomatch, str *pvclass)
 {
 {
 	geoip2_pv_reset(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) {
 int mod_register(char *path, int *dlflags, void *p1, void *p2) {
     sr_kemi_modules_add(sr_kemi_geoip2_exports);
     sr_kemi_modules_add(sr_kemi_geoip2_exports);
     return 0;
     return 0;
-}
+}

+ 7 - 0
src/modules/geoip2/geoip2_pv.c

@@ -124,6 +124,13 @@ sr_geoip2_item_t *sr_geoip2_add_item(str *name)
 	return it;
 	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)
 int pv_parse_geoip2_name(pv_spec_p sp, str *in)
 {
 {

+ 1 - 0
src/modules/geoip2/geoip2_pv.h

@@ -35,6 +35,7 @@ void geoip2_destroy_pv(void);
 int geoip2_reload_pv(char *path);
 int geoip2_reload_pv(char *path);
 void geoip2_pv_reset(str *pvclass);
 void geoip2_pv_reset(str *pvclass);
 int geoip2_update_pv(str *tomatch, str *pvclass);
 int geoip2_update_pv(str *tomatch, str *pvclass);
+int sr_geoip2_add_resid(str *rname);
 
 
 #endif
 #endif