Description

When trying to iterate over a semi-colon separated string list, the s.select transformation seems to be returning empty string instead of null, so the suggested idea from here does not work -> https://www.kamailio.org/wiki/tutorials/faq/main#how_to_iterate_through_the_ite
It is expected that the access to an invalid index would return null.

Troubleshooting

avp and var variables were tried and both had the same result.

Reproduction

Original piece of code is below. The while loop will run until the max_while_loops is reached.
The "DEBUG" log line will print the loop iterator value and an empty string for nonexistent values.

        $var(allowed_headers) = "X-header1; X-header2;";
        if (not_empty("$var(allowed_headers)")) {
                xlog("L_NOTICE","Forwarding headers: $avp(allowed_headers)\n");
                $var(i) = 0;
                while($(var(allowed_headers){s.select,$var(i),;}) != $null)
                {
                        xlog("L_NOTICE","DEBUG: $var(i) - $(var(allowed_headers){s.select,$var(i),;})\n");
                        $var(hdr) = $(var(allowed_headers){s.select,$var(i),;}{s.trim});
                        if (not_empty("$var(hdr)") &&
                                not_empty("$(hdr($var(hdr)))")) {
                                xlog("L_NOTICE","Header: $var(hdr): $(hdr($var(hdr))) allowed\n");
                                append_hf("$var(hdr): $(hdr($var(hdr)))\r\n");
                        }
                        $var(i) = $var(i) + 1;
                }
        }

It is also possible to simulate it by simply doing this:

        $var(allowed_headers) = "X-header1; X-header2;";
        if ($(var(allowed_headers){s.select,100,;}) != $null) {
                xlog("L_ERR","THIS IS WRONG :(");
        }

Possible Solutions

Other while conditions can be done. but this is the most elegant and is not working.... For example, checking with "not_empty" works, but then we can't actually have empty values in the semi-colon separated list because it would stop the loop and entries after that would not be reached....

Additional Information

# kamailio -v
version: kamailio 5.2.2 (x86_64/linux) 67f967
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: 67f967 
compiled on 11:40:41 Mar 11 2019 with gcc 4.8.5
# uname -a
Linux voice-conn-kamailio-1 3.10.0-514.21.2.el7.x86_64 #1 SMP Tue Jun 20 12:24:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.