Przeglądaj źródła

geoip: exported functions to kemi framework

Daniel-Constantin Mierla 8 lat temu
rodzic
commit
a138f65cd5
1 zmienionych plików z 31 dodań i 15 usunięć
  1. 31 15
      src/modules/geoip/geoip_mod.c

+ 31 - 15
src/modules/geoip/geoip_mod.c

@@ -30,6 +30,7 @@
 #include "../../core/dprint.h"
 #include "../../core/ut.h"
 #include "../../core/pvar.h"
+#include "../../core/kemi.h"
 #include "../../core/mod_fix.h"
 
 #include "geoip_pv.h"
@@ -42,7 +43,7 @@ static int  mod_init(void);
 static void mod_destroy(void);
 
 static int w_geoip_match(struct sip_msg* msg, char* str1, char* str2);
-static int geoip_match(struct sip_msg *msg, gparam_t *target, gparam_t *pvname);
+static int geoip_match(sip_msg_t *msg, str *tomatch, str *pvclass);
 
 static pv_export_t mod_pvs[] = {
 	{ {"gip", sizeof("git")-1}, PVT_OTHER, pv_get_geoip, 0,
@@ -78,7 +79,6 @@ struct module_exports exports = {
 };
 
 
-
 /**
  * init module function
  */
@@ -107,34 +107,50 @@ static void mod_destroy(void)
 	geoip_destroy_pv();
 }
 
-static int w_geoip_match(struct sip_msg* msg, char* str1, char* str2)
+
+static int geoip_match(sip_msg_t *msg, str *tomatch, str *pvclass)
 {
-	return geoip_match(msg, (gparam_t*)str1, (gparam_t*)str2);
+	geoip_pv_reset(pvclass);
+
+	return geoip_update_pv(tomatch, pvclass);
 }
 
-static int geoip_match(struct sip_msg *msg, gparam_t *target, gparam_t *pvname)
+static int w_geoip_match(sip_msg_t* msg, char* target, char* pvname)
 {
-	str tomatch;
-	str pvclass;
+	str tomatch = STR_NULL;
+	str pvclass = STR_NULL;
 
-	if(msg==NULL)
-	{
+	if(msg==NULL) {
 		LM_ERR("received null msg\n");
 		return -1;
 	}
 
-	if(fixup_get_svalue(msg, target, &tomatch)<0)
-	{
+	if(fixup_get_svalue(msg, (gparam_t*)target, &tomatch)<0) {
 		LM_ERR("cannot get the address\n");
 		return -1;
 	}
-	if(fixup_get_svalue(msg, pvname, &pvclass)<0)
-	{
+	if(fixup_get_svalue(msg, (gparam_t*)pvname, &pvclass)<0) {
 		LM_ERR("cannot get the pv class\n");
 		return -1;
 	}
-	geoip_pv_reset(&pvclass);
 
-	return geoip_update_pv(&tomatch, &pvclass);
+	return geoip_match(msg, &tomatch, &pvclass);
 }
 
+/**
+ *
+ */
+static sr_kemi_t sr_kemi_geoip_exports[] = {
+    { str_init("geoip"), str_init("match"),
+        SR_KEMIP_INT, geoip_match,
+        { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+    },
+
+    { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+
+int mod_register(char *path, int *dlflags, void *p1, void *p2) {
+    sr_kemi_modules_add(sr_kemi_geoip_exports);
+    return 0;
+}