### Description
Examples of [RFC7840](https://tools.ietf.org/html/rfc7840#section-7) contains this response: ```xml <locationResponse xmlns="urn:ietf:params:xml:ns:geopriv:held"> <locationUriSet expires="2006-01-01T13:00:00.0Z"> <locationURI> https://ls.example.com:9768/357yc6s64ceyoiuy5ax3o </locationURI> <locationURI> sip:9769+357yc6s64ceyoiuy5ax3o@ls.example.com </locationURI> </locationUriSet>
<routingInformation xmlns="urn:ietf:params:xml:ns:geopriv:held:ri"> <service serviceUri="urn:service:sos"> <dest>sip:112@example.com</dest> <dest>sips:112@example.com</dest> <dest>xmpp:112@example.com</dest> </service> </routingInformation>
</locationResponse> ```
When the `lost` module receives such a response, then generate this message ``` http_client [functions.c:299]: curL_query_url(): Malformed URL used in http client (url: https://ls.example.com:9768/357yc6s64ceyoiuy5ax3o ) lost [functions.c:325]: lost_held_function(): dereferencing location failed: 3 ```
This error is fixed when if I strip spaces in a string of `locationURI` element.
### Troubleshooting
#### Reproduction
Send xml eample from RFC as responce for `lost_held_query` function call.
### Possible Solutions
Strip leading and trailing spaces of `locationURI` element. Maybe the required changes here https://github.com/kamailio/kamailio/blob/master/src/modules/lost/functions....
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` [root@ip-100-86-47-115 ~]# kamailio -v version: kamailio 5.5.0-dev3 (x86_64/linux) 0f572c flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, 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_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED 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: 0f572c compiled on 04:01:25 Nov 29 2020 with gcc 8.3.1 ```
* **Operating System**:
``` [root@ip-100-86-47-115 ~]# cat /etc/os-release NAME="CentOS Linux" VERSION="8 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="8" ```
If you made a fix locally and you tested, then make a pull request, it is easier to review. Note that there is a function named `trim()` (inside `src/core/trim.h`) that can be useful, to avoid adding a new one.
looks as trim to not strip all trailing symbols. I have tested ```diff diff --git a/src/modules/lost/functions.c b/src/modules/lost/functions.c index c94c7883f0..b152b08300 100644 --- a/src/modules/lost/functions.c +++ b/src/modules/lost/functions.c @@ -290,6 +290,9 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url, if(xmlStrcmp(cur_node->name, (const xmlChar *)"locationUriSet") == 0) {
+ str test = {"test\n", 5}; + trim(&test); + LM_WARN("'%s' after\n", test.s); LM_DBG("*** node '%s' found\n", cur_node->name);
/* get the locationUri element */ ``` This produce message in log ``` 1(8906) WARNING: lost [functions.c:307]: lost_held_function(): 'test ' after ``` This produce ```
Looks as trailing `\n` not removed.
You need to use it correctly. ;-)
``` str test = str_init("test \n\n\n\n\n\n"); LM_WARN("'%.*s, %d' before\n", test.len, test.s, test.len); trim(&test); LM_WARN("'%.*s, %d' after\n", test.len, test.s, test.len);
```
``` 0(1403811) WARNING: <core> [main.c:2860]: main(): 'test
, 14' before 0(1403811) WARNING: <core> [main.c:2862]: main(): 'test, 4' after
```
Clarifying further for the devs dealing first time with `str` structure: the functions working with them do not change the content of the input value, it sets (shifts) the start pointer `str.s` and adjusts the length `str.len`.
Also, in many cases the str.s does not point to a zero-terminated string value of length str.len, that's why printing it in logs must be done with `%.*s` which requires first to provide the lenght. There are acases when str.s points to a zero-terminated string, but the developer has to track the origin of the value and be sure it is zero-terminated.
I created PR that resolve this issue. To trim spaces I used the module function `lost_trim_content`. This trim string and add `\0` ad the end of the string.
Closed #2569.