Module: kamailio
Branch: master
Commit: 9b8a4fd17e8819395043f54d43dab07a226d8490
URL:
https://github.com/kamailio/kamailio/commit/9b8a4fd17e8819395043f54d43dab07…
Author: Wolfgang Kampichler <dev(a)kampichler.info>
Committer: Wolfgang Kampichler <dev(a)kampichler.info>
Date: 2022-05-28T22:42:02+02:00
lost: URI list support in LoST response (filter for sip/sips scheme)
---
Modified: src/modules/lost/functions.c
Modified: src/modules/lost/response.c
Modified: src/modules/lost/response.h
---
Diff:
https://github.com/kamailio/kamailio/commit/9b8a4fd17e8819395043f54d43dab07…
Patch:
https://github.com/kamailio/kamailio/commit/9b8a4fd17e8819395043f54d43dab07…
---
diff --git a/src/modules/lost/functions.c b/src/modules/lost/functions.c
index 711c3732bf..bc6dbd936c 100644
--- a/src/modules/lost/functions.c
+++ b/src/modules/lost/functions.c
@@ -1,7 +1,7 @@
/*
* lost module functions
*
- * Copyright (C) 2021 Wolfgang Kampichler
+ * Copyright (C) 2022 Wolfgang Kampichler
* DEC112, FREQUENTIS AG
*
* This file is part of Kamailio, a free SIP server.
@@ -1123,16 +1123,24 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char
*_name,
switch(fsrdata->category) {
case RESPONSE:
if(fsrdata->uri != NULL) {
- /* get the first uri element */
- if((tmp.s = fsrdata->uri->value) != NULL) {
- tmp.len = strlen(fsrdata->uri->value);
- if(pkg_str_dup(&uri, &tmp) < 0) {
- LM_ERR("could not copy: [%.*s]\n", tmp.len, tmp.s);
- goto err;
- }
+ /* get the first sips uri element ... */
+ if(lost_search_response_list(&fsrdata->uri, &tmp.s, SIPS_S) > 0) {
+ tmp.len = strlen(tmp.s);
+ /* or the first sip uri element ... */
+ } else if(lost_search_response_list(&fsrdata->uri, &tmp.s, SIP_S) > 0)
{
+ tmp.len = strlen(tmp.s);
+ /* or return error if nothing found */
+ } else {
+ LM_ERR("sip/sips uri not found: [%.*s]\n", ret.len, ret.s);
+ goto err;
+ }
+ /* copy uri string */
+ if(pkg_str_dup(&uri, &tmp) < 0) {
+ LM_ERR("could not copy: [%.*s]\n", tmp.len, tmp.s);
+ goto err;
}
} else {
- LM_ERR("uri not found: [%.*s]\n", ret.len, ret.s);
+ LM_ERR("uri element not found: [%.*s]\n", ret.len, ret.s);
goto err;
}
if(fsrdata->mapping != NULL) {
diff --git a/src/modules/lost/response.c b/src/modules/lost/response.c
index cc6d65ad2a..dcd6dc5363 100644
--- a/src/modules/lost/response.c
+++ b/src/modules/lost/response.c
@@ -1,7 +1,7 @@
/*
* lost module LoST response parsing functions
*
- * Copyright (C) 2021 Wolfgang Kampichler
+ * Copyright (C) 2022 Wolfgang Kampichler
* DEC112, FREQUENTIS AG
*
* This file is part of Kamailio, a free SIP server.
@@ -353,6 +353,40 @@ void lost_reverse_response_list(p_lost_list_t *head)
*head = prev;
}
+/*
+ * lost_search_response_list(list, value, search)
+ * looks for search string in list object and returns pointer if found
+ */
+int lost_search_response_list(p_lost_list_t *list, char **val, const char *str)
+{
+ p_lost_list_t cur;
+ p_lost_list_t next;
+
+ if(*list == NULL)
+ return 0;
+
+ if(str == NULL)
+ return 0;
+
+ LM_DBG("### list data search [%s]\n", str);
+
+ next = *list;
+ while((cur = next) != NULL) {
+ next = cur->next;
+ if(cur->value != NULL) {
+ if(strncasecmp(cur->value, str, strlen(str)) == 0) {
+ *val = cur->value;
+
+ LM_DBG("###\t[%s] found\n", cur->value);
+
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
/*
* lost_delete_response_list(list)
* removes response list from private memory
diff --git a/src/modules/lost/response.h b/src/modules/lost/response.h
index 991f82ac6e..9c1fcbcb23 100644
--- a/src/modules/lost/response.h
+++ b/src/modules/lost/response.h
@@ -1,7 +1,7 @@
/*
* lost module LoST response parsing functions
*
- * Copyright (C) 2021 Wolfgang Kampichler
+ * Copyright (C) 2022 Wolfgang Kampichler
* DEC112, FREQUENTIS AG
*
* This file is part of Kamailio, a free SIP server.
@@ -56,6 +56,9 @@
#define ERRORS_NODE (const char *)"errors"
+#define SIP_S (const char *)"sip:"
+#define SIPS_S (const char *)"sips:"
+
#define HELD_RESPONSE_REFERENCE 1
#define HELD_RESPONSE_VALUE 2
@@ -133,4 +136,7 @@ int is_cid_laquot(char *);
int is_http_laquot(char *);
int is_https_laquot(char *);
+/* list search */
+int lost_search_response_list(p_lost_list_t *, char **, const char *);
+
#endif