Skip to content

Commit

Permalink
pipelimit: exported functions to kemi framework
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed May 27, 2017
1 parent 6a92bbc commit c218e35
Showing 1 changed file with 90 additions and 25 deletions.
115 changes: 90 additions & 25 deletions src/modules/pipelimit/pipelimit.c
Expand Up @@ -53,6 +53,7 @@
#include "../../core/rpc.h"
#include "../../core/rpc_lookup.h"
#include "../../core/rand/kam_rand.h"
#include "../../core/kemi.h"

#include "pl_statistics.h"
#include "pl_ht.h"
Expand Down Expand Up @@ -640,6 +641,36 @@ static int w_pl_check(struct sip_msg* msg, char *p1, char *p2)
}


/**
* limit checking with creation of pipe if it doesn't exist
*/
static int pl_check_limit(sip_msg_t* msg, str *pipeid, str *alg, int limit)
{
pl_pipe_t *pipe = NULL;

pipe = pl_pipe_get(pipeid, 1);
if(pipe==NULL) {
LM_DBG("pipe not found [%.*s] - trying to add it\n",
pipeid->len, pipeid->s);
if(pl_pipe_add(pipeid, alg, limit)<0) {
LM_ERR("failed to add pipe [%.*s]\n",
pipeid->len, pipeid->s);
return -2;
}
pipe = pl_pipe_get(pipeid, 0);
if(pipe==NULL) {
LM_ERR("failed to retrieve pipe [%.*s]\n",
pipeid->len, pipeid->s);
return -2;
}
} else {
if(limit>0) pipe->limit = limit;
pl_pipe_release(&pipe->name);
}

return pl_check(msg, pipeid);
}

/**
* limit checking with creation of pipe if it doesn't exist
*/
Expand All @@ -649,7 +680,6 @@ static int w_pl_check3(struct sip_msg* msg, char *p1pipe, char *p2alg,
int limit;
str pipeid = {0, 0};
str alg = {0, 0};
pl_pipe_t *pipe = NULL;

if(msg==NULL)
return -1;
Expand All @@ -674,30 +704,7 @@ static int w_pl_check3(struct sip_msg* msg, char *p1pipe, char *p2alg,
return -1;
}

pipe = pl_pipe_get(&pipeid, 1);
if(pipe==NULL)
{
LM_DBG("pipe not found [%.*s] - trying to add it\n",
pipeid.len, pipeid.s);
if(pl_pipe_add(&pipeid, &alg, limit)<0)
{
LM_ERR("failed to add pipe [%.*s]\n",
pipeid.len, pipeid.s);
return -2;
}
pipe = pl_pipe_get(&pipeid, 0);
if(pipe==NULL)
{
LM_ERR("failed to retrieve pipe [%.*s]\n",
pipeid.len, pipeid.s);
return -2;
}
} else {
if(limit>0) pipe->limit = limit;
pl_pipe_release(&pipe->name);
}

return pl_check(msg, &pipeid);
return pl_check_limit(msg, &pipeid, &alg, limit);
}

static int fixup_pl_check3(void** param, int param_no)
Expand Down Expand Up @@ -805,3 +812,61 @@ static rpc_export_t rpc_methods[] = {
{0, 0, 0, 0}
};

static int ki_pl_drop(sip_msg_t* msg)
{
return pl_drop(msg, 0, 0);
}

static int ki_pl_drop_retry(sip_msg_t* msg, int rafter)
{
return pl_drop(msg, rafter, rafter);
}

static int ki_pl_drop_range(sip_msg_t* msg, int rmin, int rmax)
{
return pl_drop(msg, rmin, rmax);
}

/**
*
*/
/* clang-format off */
static sr_kemi_t sr_kemi_pipelimit_exports[] = {
{ str_init("pipelimit"), str_init("pl_check"),
SR_KEMIP_INT, pl_check,
{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("pipelimit"), str_init("pl_check_limit"),
SR_KEMIP_INT, pl_check_limit,
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("pipelimit"), str_init("pl_drop"),
SR_KEMIP_INT, ki_pl_drop,
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("pipelimit"), str_init("pl_drop_retry"),
SR_KEMIP_INT, ki_pl_drop_retry,
{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("pipelimit"), str_init("pl_drop_range"),
SR_KEMIP_INT, ki_pl_drop_range,
{ SR_KEMIP_INT, SR_KEMIP_INT, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},

{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};
/* clang-format on */

/**
*
*/
int mod_register(char *path, int *dlflags, void *p1, void *p2)
{
sr_kemi_modules_add(sr_kemi_pipelimit_exports);
return 0;
}

0 comments on commit c218e35

Please sign in to comment.