Skip to content

Commit

Permalink
for-each statement: Fix iteration when <reply> context is used
Browse files Browse the repository at this point in the history
Make sure to interpret the variable's context, if any, e.g.:

    for ($var(ct) in $(<reply>ct[*]))
        xlog("300 Redirect Contact: $var(ct)\n");
  • Loading branch information
liviuchircu committed Jan 17, 2024
1 parent 1339b7a commit 1d6d2e4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion action.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ int do_action(struct action* a, struct sip_msg* msg)

static int for_each_handler(struct sip_msg *msg, struct action *a)
{
struct sip_msg *msg_src = msg;
pv_spec_p iter, spec;
pv_param_t pvp;
pv_value_t val;
Expand All @@ -1189,6 +1190,13 @@ static int for_each_handler(struct sip_msg *msg, struct action *a)
memset(&pvp, 0, sizeof pvp);
pvp.pvi.type = PV_IDX_INT;
pvp.pvn = spec->pvp.pvn;
if (spec->pvc && spec->pvc->contextf) {
msg_src = spec->pvc->contextf(msg);
if (!msg_src || msg_src == FAKED_REPLY) {
LM_BUG("Invalid pv context message: %p\n", msg_src);
return E_BUG;
}
}

/*
* for $json iterators, better to assume script writer
Expand All @@ -1199,7 +1207,7 @@ static int for_each_handler(struct sip_msg *msg, struct action *a)
op = COLONEQ_T;

for (;;) {
if (spec->getf(msg, &pvp, &val) != 0) {
if (spec->getf(msg_src, &pvp, &val) != 0) {
LM_ERR("failed to get spec value\n");
return E_BUG;
}
Expand Down

0 comments on commit 1d6d2e4

Please sign in to comment.