Skip to content

Commit 1d6d2e4

Browse files
committed
for-each statement: Fix iteration when <reply> context is used
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");
1 parent 1339b7a commit 1d6d2e4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

action.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,7 @@ int do_action(struct action* a, struct sip_msg* msg)
11671167

11681168
static int for_each_handler(struct sip_msg *msg, struct action *a)
11691169
{
1170+
struct sip_msg *msg_src = msg;
11701171
pv_spec_p iter, spec;
11711172
pv_param_t pvp;
11721173
pv_value_t val;
@@ -1189,6 +1190,13 @@ static int for_each_handler(struct sip_msg *msg, struct action *a)
11891190
memset(&pvp, 0, sizeof pvp);
11901191
pvp.pvi.type = PV_IDX_INT;
11911192
pvp.pvn = spec->pvp.pvn;
1193+
if (spec->pvc && spec->pvc->contextf) {
1194+
msg_src = spec->pvc->contextf(msg);
1195+
if (!msg_src || msg_src == FAKED_REPLY) {
1196+
LM_BUG("Invalid pv context message: %p\n", msg_src);
1197+
return E_BUG;
1198+
}
1199+
}
11921200

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

12011209
for (;;) {
1202-
if (spec->getf(msg, &pvp, &val) != 0) {
1210+
if (spec->getf(msg_src, &pvp, &val) != 0) {
12031211
LM_ERR("failed to get spec value\n");
12041212
return E_BUG;
12051213
}

0 commit comments

Comments
 (0)