Skip to content
Permalink
Browse files

Allow fixups to be run for omitted optional parameters

  • Loading branch information
rvlad-patrascu committed Mar 18, 2019
1 parent 0a0616c commit 705f432462ede6e22d148ef4247cb68ab3dd7c7f
Showing with 35 additions and 9 deletions.
  1. +31 −9 mod_fix.c
  2. +4 −0 sr_module.h
@@ -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;
@@ -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) {

@@ -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 */

0 comments on commit 705f432

Please sign in to comment.
You can’t perform that action at this time.