[sr-dev] [kamailio/kamailio] s.select transformation not returning null for nonexistent indexes (#2128)

pwakano notifications at github.com
Wed Nov 13 23:39:01 CET 2019


<!--
Kamailio Project uses GitHub Issues only for bugs in the code or feature requests. Please use this template only for bug reports.

If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:

  * http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list:

  * http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.

If there is no content to be filled in a section, the entire section can be removed.

You can delete the comments from the template sections when filling.

You can delete next line and everything above before submitting (it is a comment).
-->

### 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 Version** - output of `kamailio -v`

```
# 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
```

* **Operating System**:

<!--
Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...;
Kernel details (output of `uname -a`)
-->

```
# 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 or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2128
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20191113/d74a1074/attachment.html>


More information about the sr-dev mailing list