Skip to content

Commit

Permalink
Allow fixups to be run for omitted optional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu authored and liviuchircu committed Apr 4, 2019
1 parent 7533df1 commit 574f744
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
40 changes: 31 additions & 9 deletions mod_fix.c
Expand Up @@ -70,6 +70,20 @@ int fixup_regcomp(regex_t **re, str *re_str, int dup_nt)
return 0;
}

static inline gparam_p alloc_gp(void)
{
gparam_p gp;

gp = pkg_malloc(sizeof *gp);
if (!gp) {
LM_ERR("no more pkg memory\n");
return NULL;
}
memset(gp, 0, sizeof *gp);

return gp;
}

int fix_cmd(struct cmd_param *params, action_elem_t *elems)
{
int i;
Expand All @@ -82,22 +96,30 @@ int fix_cmd(struct cmd_param *params, action_elem_t *elems)
for (param=params, i=1; param->flags; param++, i++) {
if ((elems[i].type == NOSUBTYPE) ||
(elems[i].type == NULLV_ST)) {
if (param->flags & CMD_PARAM_OPT)
if (param->flags & CMD_PARAM_OPT) {
if (param->fixup && (param->flags & CMD_PARAM_FIX_NULL)) {
if ((gp = alloc_gp()) == NULL)
return E_OUT_OF_MEM;

gp->v.val = NULL;
if (param->fixup(&gp->v.val) < 0) {
LM_ERR("Fixup failed for param [%d]\n", i);
ret = E_UNSPEC;
goto error;
}
gp->type = GPARAM_TYPE_FIXUP;
}

continue;
else {
} else {
LM_BUG("Mandatory parameter missing\n");
ret = E_BUG;
goto error;
}
}

gp = pkg_malloc(sizeof *gp);
if (!gp) {
LM_ERR("no more pkg memory\n");
ret = E_OUT_OF_MEM;
goto error;
}
memset(gp, 0, sizeof *gp);
if ((gp = alloc_gp()) == NULL)
return E_OUT_OF_MEM;

if (param->flags & CMD_PARAM_INT) {

Expand Down
4 changes: 4 additions & 0 deletions sr_module.h
Expand Up @@ -108,11 +108,15 @@ typedef int (*mod_proc_wrapper)();

#define MAX_CMD_PARAMS (MAX_ACTION_ELEMS-1)


/* parameter type flags */
#define CMD_PARAM_INT (1<<0) /* integer parameter */
#define CMD_PARAM_STR (1<<1) /* string parameter */
#define CMD_PARAM_VAR (1<<2) /* PV spec parameter */
#define CMD_PARAM_REGEX (1<<3) /* regexp string parameter */

#define CMD_PARAM_OPT (1<<4) /* optional parameter */
#define CMD_PARAM_FIX_NULL (1<<5) /* run fixup even if optional parameter is omitted */

struct cmd_param {
int flags; /* parameter flags */
Expand Down

0 comments on commit 574f744

Please sign in to comment.