Skip to content

Commit

Permalink
cpl_c: port script functions to new param interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Apr 2, 2019
1 parent 0326ea9 commit 0354b8c
Showing 1 changed file with 54 additions and 41 deletions.
95 changes: 54 additions & 41 deletions modules/cpl_c/cpl.c
Expand Up @@ -93,11 +93,12 @@ struct cpl_functions cpl_fct;
static str cpl_ok_rpl = str_init("OK");


static int cpl_invoke_script (struct sip_msg* msg, char* str, char* str2);
static int cpl_invoke_script (struct sip_msg* msg, void* type, void* mode);
static int w_process_register(struct sip_msg* msg, char* str, char* str2);
static int w_process_register_norpl(struct sip_msg* msg, char* str,char* str2);
static int cpl_process_register(struct sip_msg* msg, int no_rpl);
static int fixup_cpl_run_script(void** param, int param_no);
static int fixup_cpl_run_script_1(void** param);
static int fixup_cpl_run_script_2(void** param);
static int cpl_init(void);
static int cpl_child_init(int rank);
static int cpl_exit(void);
Expand All @@ -116,17 +117,19 @@ static proc_export_t cpl_procs[] = {
/*
* Exported functions
*/

static cmd_export_t cmds[] = {
{"cpl_run_script", (cmd_function)cpl_invoke_script, 2,
fixup_cpl_run_script, 0, REQUEST_ROUTE},
{"cpl_process_register", (cmd_function)w_process_register, 0,
0, 0, REQUEST_ROUTE},
{"cpl_process_register_norpl",(cmd_function)w_process_register_norpl, 0,
0, 0, REQUEST_ROUTE},
{0, 0, 0, 0, 0, 0}
{"cpl_run_script", (cmd_function)cpl_invoke_script, {
{CMD_PARAM_STR,fixup_cpl_run_script_1,0},
{CMD_PARAM_STR,fixup_cpl_run_script_2,0}, {0,0,0}},
REQUEST_ROUTE},
{"cpl_process_register",(cmd_function)w_process_register, {{0,0,0}},
REQUEST_ROUTE},
{"cpl_process_register_norpl",(cmd_function)w_process_register_norpl, {{0,0,0}},
REQUEST_ROUTE},
{0,0,{{0,0,0}},0}
};


/*
* Exported parameters
*/
Expand Down Expand Up @@ -213,39 +216,49 @@ struct module_exports exports = {



static int fixup_cpl_run_script(void** param, int param_no)
static int fixup_cpl_run_script_1(void** param)
{
long flag;
static str incoming_s = str_init("incoming");
static str outgoing_s = str_init("outgoing");

if (param_no==1) {
if (!strcasecmp( "incoming", *param))
flag = CPL_RUN_INCOMING;
else if (!strcasecmp( "outgoing", *param))
flag = CPL_RUN_OUTGOING;
else {
LM_ERR("script directive \"%s\" unknown!\n",(char*)*param);
return E_UNSPEC;
}
pkg_free(*param);
*param=(void*)flag;
return 0;
} else if (param_no==2) {
if ( !strcasecmp("is_stateless", *param) ) {
flag = 0;
} else if ( !strcasecmp("is_stateful", *param) ) {
flag = CPL_IS_STATEFUL;
} else if ( !strcasecmp("force_stateful", *param) ) {
flag = CPL_FORCE_STATEFUL;
} else {
LM_ERR("flag \"%s\" (second param) unknown!\n",(char*)*param);
return E_UNSPEC;
}
pkg_free(*param);
*param=(void*)flag;
if (!str_strcasecmp( &incoming_s, (str*)*param))
flag = CPL_RUN_INCOMING;
else if (!str_strcasecmp( &outgoing_s, (str*)*param))
flag = CPL_RUN_OUTGOING;
else {
LM_ERR("script directive \"%.*s\" unknown!\n",
((str*)*param)->len, ((str*)*param)->s);
return E_UNSPEC;
}

*param=(void*)flag;
return 0;
}

static int fixup_cpl_run_script_2(void** param)
{
long flag;
static str is_stateless_s = str_init("is_stateless");
static str is_stateful_s = str_init("is_stateful");
static str force_stateful_s = str_init("force_stateful");

if ( !str_strcasecmp(&is_stateless_s, (str*)*param) ) {
flag = 0;
} else if ( !str_strcasecmp(&is_stateful_s, (str*)*param) ) {
flag = CPL_IS_STATEFUL;
} else if ( !str_strcasecmp(&force_stateful_s, (str*)*param) ) {
flag = CPL_FORCE_STATEFUL;
} else {
LM_ERR("flag \"%.*s\" (second param) unknown!\n",
((str*)*param)->len, ((str*)*param)->s);
return E_UNSPEC;
}

*param=(void*)flag;

return 0;
}


static int cpl_init(void)
Expand Down Expand Up @@ -339,7 +352,7 @@ static int cpl_init(void)
/* bind to usrloc module if requested */
if (lookup_domain) {
/* import all usrloc functions */
bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 0);
if (!bind_usrloc) {
LM_ERR("can't bind usrloc\n");
goto error;
Expand Down Expand Up @@ -549,7 +562,7 @@ static inline int get_orig_user(struct sip_msg *msg, str *username, str *domain)
* str1 - as unsigned int - can be CPL_RUN_INCOMING or CPL_RUN_OUTGOING
* str2 - as unsigned int - flags regarding state(less)|(ful)
*/
static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
static int cpl_invoke_script(struct sip_msg* msg, void* type, void* mode)
{
struct cpl_interpreter *cpl_intr;
str username = {0,0};
Expand All @@ -558,7 +571,7 @@ static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
str script;

/* get the user_name */
if ( ((unsigned long)str1)&CPL_RUN_INCOMING ) {
if ( ((unsigned long)type)&CPL_RUN_INCOMING ) {
/* if it's incoming -> get the destination user name */
if (get_dest_user( msg, &username, &domain)==-1)
goto error0;
Expand All @@ -582,13 +595,13 @@ static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
if ( (cpl_intr=new_cpl_interpreter(msg,&script))==0 )
goto error1;
/* set the flags */
cpl_intr->flags =(unsigned int)((unsigned long)str1)|((unsigned long)str2);
cpl_intr->flags =(unsigned int)((unsigned long)type)|((unsigned long)mode);
/* build user AOR */
if (build_user_AOR( &username, &domain, &(cpl_intr->user), 0)!=0 )
goto error2;
/* for OUTGOING we need also the destination user for init. with him
* the location set */
if ( ((unsigned long)str1)&CPL_RUN_OUTGOING ) {
if ( ((unsigned long)type)&CPL_RUN_OUTGOING ) {
/* build user initial location -> get the destination user name */
if (get_dest_user( msg, &username, &domain)==-1)
goto error2;
Expand Down

0 comments on commit 0354b8c

Please sign in to comment.