Skip to content

Commit c006227

Browse files
rvlad-patrasculiviuchircu
authored andcommitted
Rework interface for script functions parameters
* 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
1 parent 3bce368 commit c006227

File tree

16 files changed

+606
-174
lines changed

16 files changed

+606
-174
lines changed

aaa/aaa.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int aaa_prot_bind(str* aaa_url, aaa_prot* prot) {
9494
sprintf(module_name, "aaa_%.*s", pc.prot_name->len,pc.prot_name->s);
9595

9696
bind_f = (aaa_bind_api_f) find_mod_export(module_name,
97-
"aaa_bind_api", 0, 0);
97+
"aaa_bind_api", 0);
9898

9999
if (bind_f) {
100100
LM_DBG("using aaa bind api for %s\n", module_name);

action.c

+59-16
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ int do_action(struct action* a, struct sip_msg* msg)
438438
struct timeval start;
439439
int end_time;
440440
int aux_counter;
441+
cmd_export_t *cmd = NULL;
442+
acmd_export_t *acmd;
443+
void* cmdp[MAX_CMD_PARAMS];
441444

442445
/* reset the value of error to E_UNSPEC so avoid unknowledgable
443446
functions to return with error (status<0) and not setting it
@@ -1860,48 +1863,88 @@ int do_action(struct action* a, struct sip_msg* msg)
18601863
ret=return_code;
18611864
break;
18621865
case MODULE_T:
1863-
script_trace("module", ((cmd_export_t*)(a->elem[0].u.data))->name,
1864-
msg, a->file, a->line) ;
1865-
if ( (a->elem[0].type==CMD_ST) && a->elem[0].u.data ) {
1866-
ret=((cmd_export_t*)(a->elem[0].u.data))->function(msg,
1867-
(char*)a->elem[1].u.data, (char*)a->elem[2].u.data,
1868-
(char*)a->elem[3].u.data, (char*)a->elem[4].u.data,
1869-
(char*)a->elem[5].u.data, (char*)a->elem[6].u.data);
1870-
}else{
1866+
if (a->elem[0].type != CMD_ST ||
1867+
((cmd = (cmd_export_t*)a->elem[0].u.data) == NULL)) {
18711868
LM_ALERT("BUG in module call\n");
1869+
break;
1870+
}
1871+
1872+
script_trace("module", cmd->name, msg, a->file, a->line);
1873+
1874+
if ((ret = get_cmd_fixups(msg, cmd->params, a->elem, cmdp)) < 0) {
1875+
LM_ERR("Failed to get fixups for command <%s>\n",
1876+
cmd->name);
1877+
break;
1878+
}
1879+
1880+
ret = cmd->function(msg,
1881+
cmdp[0],cmdp[1],cmdp[2],
1882+
cmdp[3],cmdp[4],cmdp[5]);
1883+
1884+
if ((ret = free_cmd_fixups(cmd->params, a->elem, cmdp)) < 0) {
1885+
LM_ERR("Failed to free fixups for command <%s>\n",
1886+
cmd->name);
1887+
break;
18721888
}
1889+
18731890
break;
18741891
case ASYNC_T:
18751892
/* first param - an ACTIONS_ST containing an ACMD_ST
18761893
* second param - a NUMBER_ST pointing to resume route */
18771894
aitem = (struct action *)(a->elem[0].u.data);
1895+
acmd = (acmd_export_t *)aitem->elem[0].u.data;
1896+
18781897
if (async_script_start_f==NULL || a->elem[0].type!=ACTIONS_ST ||
18791898
a->elem[1].type!=NUMBER_ST || aitem->type!=AMODULE_T) {
18801899
LM_ALERT("BUG in async expression\n");
18811900
} else {
1882-
script_trace("async",
1883-
((acmd_export_t*)(aitem->elem[0].u.data))->name,
1884-
msg, a->file, a->line) ;
1885-
ret = async_script_start_f( msg, aitem, a->elem[1].u.number);
1901+
script_trace("async", acmd->name, msg, a->file, a->line);
1902+
1903+
if ((ret = get_cmd_fixups(msg, acmd->params, aitem->elem, cmdp)) < 0) {
1904+
LM_ERR("Failed to get fixups for async command <%s>\n",
1905+
acmd->name);
1906+
break;
1907+
}
1908+
1909+
ret = async_script_start_f(msg, aitem, a->elem[1].u.number, cmdp);
18861910
if (ret>=0)
18871911
action_flags |= ACT_FL_TBCONT;
1912+
1913+
if ((ret = free_cmd_fixups(acmd->params, aitem->elem, cmdp)) < 0) {
1914+
LM_ERR("Failed to free fixups for command <%s>\n",
1915+
cmd->name);
1916+
break;
1917+
}
18881918
}
18891919
ret = 0;
18901920
break;
18911921
case LAUNCH_T:
18921922
/* first param - an ACTIONS_ST containing an ACMD_ST
18931923
* second param - an optional NUMBER_ST pointing to an end route */
18941924
aitem = (struct action *)(a->elem[0].u.data);
1925+
acmd = (acmd_export_t *)aitem->elem[0].u.data;
1926+
18951927
if (async_script_start_f==NULL || a->elem[0].type!=ACTIONS_ST ||
18961928
a->elem[1].type!=NUMBER_ST || aitem->type!=AMODULE_T) {
18971929
LM_ALERT("BUG in launch expression\n");
18981930
} else {
1899-
script_trace("launch",
1900-
((acmd_export_t*)(aitem->elem[0].u.data))->name,
1901-
msg, a->file, a->line) ;
1931+
script_trace("launch", acmd->name, msg, a->file, a->line);
19021932
/* NOTE that the routeID (a->elem[1].u.number) is set to
19031933
* -1 if no reporting route is set */
1904-
ret = async_script_launch( msg, aitem, a->elem[1].u.number);
1934+
1935+
if ((ret = get_cmd_fixups(msg, acmd->params, aitem->elem, cmdp)) < 0) {
1936+
LM_ERR("Failed to get fixups for async command <%s>\n",
1937+
acmd->name);
1938+
break;
1939+
}
1940+
1941+
ret = async_script_launch( msg, aitem, a->elem[1].u.number, cmdp);
1942+
1943+
if ((ret = free_cmd_fixups(acmd->params, aitem->elem, cmdp)) < 0) {
1944+
LM_ERR("Failed to free fixups for command <%s>\n",
1945+
cmd->name);
1946+
break;
1947+
}
19051948
}
19061949
break;
19071950
case FORCE_RPORT_T:

async.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int async_launch_resume(int fd, void *param)
249249

250250

251251
int async_script_launch(struct sip_msg *msg, struct action* a,
252-
int report_route)
252+
int report_route, void **params)
253253
{
254254
struct sip_msg req;
255255
async_launch_ctx *ctx;
@@ -273,9 +273,8 @@ int async_script_launch(struct sip_msg *msg, struct action* a,
273273

274274
return_code = ((acmd_export_t*)(a->elem[0].u.data))->function(msg,
275275
(async_ctx*)ctx,
276-
(char*)a->elem[1].u.data, (char*)a->elem[2].u.data,
277-
(char*)a->elem[3].u.data, (char*)a->elem[4].u.data,
278-
(char*)a->elem[5].u.data, (char*)a->elem[6].u.data );
276+
params[0], params[1], params[2],
277+
params[3], params[4], params[5]);
279278
/* what to do now ? */
280279
if (async_status>=0) {
281280
/* async I/O was successfully launched */

async.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ extern int async_status;
6464
/******** functions related to script async ops *******/
6565

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

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

138139
int async_script_launch(struct sip_msg *msg, struct action* a,
139-
int report_route);
140+
int report_route, void **params);
140141

141142
/* @fd is always valid */
142143
int async_launch_resume(int fd, void *param);

0 commit comments

Comments
 (0)