Skip to content

Commit

Permalink
geoip: exported functions to kemi framework
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 18, 2017
1 parent 39d2376 commit a138f65
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions src/modules/geoip/geoip_mod.c
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -78,7 +79,6 @@ struct module_exports exports = {
};



/**
* init module function
*/
Expand Down Expand Up @@ -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;
}

0 comments on commit a138f65

Please sign in to comment.