Skip to content

Commit

Permalink
Rework interface for script functions parameters
Browse files Browse the repository at this point in the history
* basic parameter fixup (type validation and variables evaluation) is now
  transparently done by the core for all script functions
* pass variables and integers to functions without quotes
  • Loading branch information
rvlad-patrascu committed Feb 28, 2019
1 parent d948aa0 commit a8661f7
Show file tree
Hide file tree
Showing 16 changed files with 606 additions and 174 deletions.
2 changes: 1 addition & 1 deletion aaa/aaa.c
Expand Up @@ -94,7 +94,7 @@ int aaa_prot_bind(str* aaa_url, aaa_prot* prot) {
sprintf(module_name, "aaa_%.*s", pc.prot_name->len,pc.prot_name->s);

bind_f = (aaa_bind_api_f) find_mod_export(module_name,
"aaa_bind_api", 0, 0);
"aaa_bind_api", 0);

if (bind_f) {
LM_DBG("using aaa bind api for %s\n", module_name);
Expand Down
75 changes: 59 additions & 16 deletions action.c
Expand Up @@ -438,6 +438,9 @@ int do_action(struct action* a, struct sip_msg* msg)
struct timeval start;
int end_time;
int aux_counter;
cmd_export_t *cmd = NULL;
acmd_export_t *acmd;
void* cmdp[MAX_CMD_PARAMS];

/* reset the value of error to E_UNSPEC so avoid unknowledgable
functions to return with error (status<0) and not setting it
Expand Down Expand Up @@ -1860,48 +1863,88 @@ int do_action(struct action* a, struct sip_msg* msg)
ret=return_code;
break;
case MODULE_T:
script_trace("module", ((cmd_export_t*)(a->elem[0].u.data))->name,
msg, a->file, a->line) ;
if ( (a->elem[0].type==CMD_ST) && a->elem[0].u.data ) {
ret=((cmd_export_t*)(a->elem[0].u.data))->function(msg,
(char*)a->elem[1].u.data, (char*)a->elem[2].u.data,
(char*)a->elem[3].u.data, (char*)a->elem[4].u.data,
(char*)a->elem[5].u.data, (char*)a->elem[6].u.data);
}else{
if (a->elem[0].type != CMD_ST ||
((cmd = (cmd_export_t*)a->elem[0].u.data) == NULL)) {
LM_ALERT("BUG in module call\n");
break;
}

script_trace("module", cmd->name, msg, a->file, a->line);

if ((ret = get_cmd_fixups(msg, cmd->params, a->elem, cmdp)) < 0) {
LM_ERR("Failed to get fixups for command <%s>\n",
cmd->name);
break;
}

ret = cmd->function(msg,
cmdp[0],cmdp[1],cmdp[2],
cmdp[3],cmdp[4],cmdp[5]);

if ((ret = free_cmd_fixups(cmd->params, a->elem, cmdp)) < 0) {
LM_ERR("Failed to free fixups for command <%s>\n",
cmd->name);
break;
}

break;
case ASYNC_T:
/* first param - an ACTIONS_ST containing an ACMD_ST
* second param - a NUMBER_ST pointing to resume route */
aitem = (struct action *)(a->elem[0].u.data);
acmd = (acmd_export_t *)aitem->elem[0].u.data;

if (async_script_start_f==NULL || a->elem[0].type!=ACTIONS_ST ||
a->elem[1].type!=NUMBER_ST || aitem->type!=AMODULE_T) {
LM_ALERT("BUG in async expression\n");
} else {
script_trace("async",
((acmd_export_t*)(aitem->elem[0].u.data))->name,
msg, a->file, a->line) ;
ret = async_script_start_f( msg, aitem, a->elem[1].u.number);
script_trace("async", acmd->name, msg, a->file, a->line);

if ((ret = get_cmd_fixups(msg, acmd->params, aitem->elem, cmdp)) < 0) {
LM_ERR("Failed to get fixups for async command <%s>\n",
acmd->name);
break;
}

ret = async_script_start_f(msg, aitem, a->elem[1].u.number, cmdp);
if (ret>=0)
action_flags |= ACT_FL_TBCONT;

if ((ret = free_cmd_fixups(acmd->params, aitem->elem, cmdp)) < 0) {
LM_ERR("Failed to free fixups for command <%s>\n",
cmd->name);
break;
}
}
ret = 0;
break;
case LAUNCH_T:
/* first param - an ACTIONS_ST containing an ACMD_ST
* second param - an optional NUMBER_ST pointing to an end route */
aitem = (struct action *)(a->elem[0].u.data);
acmd = (acmd_export_t *)aitem->elem[0].u.data;

if (async_script_start_f==NULL || a->elem[0].type!=ACTIONS_ST ||
a->elem[1].type!=NUMBER_ST || aitem->type!=AMODULE_T) {
LM_ALERT("BUG in launch expression\n");
} else {
script_trace("launch",
((acmd_export_t*)(aitem->elem[0].u.data))->name,
msg, a->file, a->line) ;
script_trace("launch", acmd->name, msg, a->file, a->line);
/* NOTE that the routeID (a->elem[1].u.number) is set to
* -1 if no reporting route is set */
ret = async_script_launch( msg, aitem, a->elem[1].u.number);

if ((ret = get_cmd_fixups(msg, acmd->params, aitem->elem, cmdp)) < 0) {
LM_ERR("Failed to get fixups for async command <%s>\n",
acmd->name);
break;
}

ret = async_script_launch( msg, aitem, a->elem[1].u.number, cmdp);

if ((ret = free_cmd_fixups(acmd->params, aitem->elem, cmdp)) < 0) {
LM_ERR("Failed to free fixups for command <%s>\n",
cmd->name);
break;
}
}
break;
case FORCE_RPORT_T:
Expand Down
7 changes: 3 additions & 4 deletions async.c
Expand Up @@ -249,7 +249,7 @@ int async_launch_resume(int fd, void *param)


int async_script_launch(struct sip_msg *msg, struct action* a,
int report_route)
int report_route, void **params)
{
struct sip_msg req;
async_launch_ctx *ctx;
Expand All @@ -273,9 +273,8 @@ int async_script_launch(struct sip_msg *msg, struct action* a,

return_code = ((acmd_export_t*)(a->elem[0].u.data))->function(msg,
(async_ctx*)ctx,
(char*)a->elem[1].u.data, (char*)a->elem[2].u.data,
(char*)a->elem[3].u.data, (char*)a->elem[4].u.data,
(char*)a->elem[5].u.data, (char*)a->elem[6].u.data );
params[0], params[1], params[2],
params[3], params[4], params[5]);
/* what to do now ? */
if (async_status>=0) {
/* async I/O was successfully launched */
Expand Down
9 changes: 5 additions & 4 deletions async.h
Expand Up @@ -64,14 +64,15 @@ extern int async_status;
/******** functions related to script async ops *******/

/* function to handle script function in async mode.
Input: the sip message, the function/action (MODULE_T) and the ID of
the resume route (where to continue after the I/O is done).
Input: the sip message, the function/action (MODULE_T), the ID of
the resume route (where to continue after the I/O is done) and the
array of parameters for the function.
Output: 0 if the async call was successfully done and script execution
must be terminated.
-1 some error happened and the async call did not happened.
*/
typedef int (async_script_start_function)
(struct sip_msg *msg, struct action* a , int resume_route);
(struct sip_msg *msg, struct action* a , int resume_route, void **params);

/* Handles periodic progress (data arrival) on behalf of the contained,
* module-specific resume function, which it must also call
Expand Down Expand Up @@ -136,7 +137,7 @@ int async_fd_resume(int fd, void *param);
/******** functions related to async launch *******/

int async_script_launch(struct sip_msg *msg, struct action* a,
int report_route);
int report_route, void **params);

/* @fd is always valid */
int async_launch_resume(int fd, void *param);
Expand Down

0 comments on commit a8661f7

Please sign in to comment.