Browse code

lost: URI list support in LoST response (filter for sip/sips scheme)

Wolfgang Kampichler authored on 28/05/2022 20:42:02
Showing 3 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * lost module functions
3 3
  *
4
- * Copyright (C) 2021 Wolfgang Kampichler
4
+ * Copyright (C) 2022 Wolfgang Kampichler
5 5
  * DEC112, FREQUENTIS AG
6 6
  *
7 7
  * 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,
1123 1123
 		switch(fsrdata->category) {
1124 1124
 			case RESPONSE:
1125 1125
 				if(fsrdata->uri != NULL) {
1126
-					/* get the first uri element */
1127
-					if((tmp.s = fsrdata->uri->value) != NULL) {
1128
-						tmp.len = strlen(fsrdata->uri->value);
1129
-						if(pkg_str_dup(&uri, &tmp) < 0) {
1130
-							LM_ERR("could not copy: [%.*s]\n", tmp.len, tmp.s);
1131
-							goto err;
1132
-						}
1126
+					/* get the first sips uri element ... */
1127
+					if(lost_search_response_list(&fsrdata->uri, &tmp.s, SIPS_S) > 0) {
1128
+						tmp.len = strlen(tmp.s);
1129
+					/* or the first sip uri element ... */
1130
+					} else if(lost_search_response_list(&fsrdata->uri, &tmp.s, SIP_S) > 0) {
1131
+						tmp.len = strlen(tmp.s);
1132
+					/* or return error if nothing found */
1133
+					} else {
1134
+					  LM_ERR("sip/sips uri not found: [%.*s]\n", ret.len, ret.s);
1135
+						goto err;
1136
+					}
1137
+					/* copy uri string */
1138
+					if(pkg_str_dup(&uri, &tmp) < 0) {
1139
+						LM_ERR("could not copy: [%.*s]\n", tmp.len, tmp.s);
1140
+						goto err;
1133 1141
 					}
1134 1142
 				} else {
1135
-					LM_ERR("uri not found: [%.*s]\n", ret.len, ret.s);
1143
+					LM_ERR("uri element not found: [%.*s]\n", ret.len, ret.s);
1136 1144
 					goto err;
1137 1145
 				}
1138 1146
 				if(fsrdata->mapping != NULL) {
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * lost module LoST response parsing functions
3 3
  *
4
- * Copyright (C) 2021 Wolfgang Kampichler
4
+ * Copyright (C) 2022 Wolfgang Kampichler
5 5
  * DEC112, FREQUENTIS AG
6 6
  *
7 7
  * This file is part of Kamailio, a free SIP server.
... ...
@@ -353,6 +353,40 @@ void lost_reverse_response_list(p_lost_list_t *head)
353 353
 	*head = prev;
354 354
 }
355 355
 
356
+/*
357
+ * lost_search_response_list(list, value, search)
358
+ * looks for search string in list object and returns pointer if found
359
+ */
360
+int lost_search_response_list(p_lost_list_t *list, char **val, const char *str)
361
+{
362
+	p_lost_list_t cur;
363
+	p_lost_list_t next;
364
+
365
+	if(*list == NULL)
366
+		return 0;
367
+
368
+	if(str == NULL)
369
+		return 0;
370
+
371
+	LM_DBG("### list data search [%s]\n", str);
372
+
373
+	next = *list;
374
+	while((cur = next) != NULL) {
375
+		next = cur->next;
376
+		if(cur->value != NULL) {
377
+			if(strncasecmp(cur->value, str, strlen(str)) == 0) {
378
+				*val = cur->value;
379
+
380
+				LM_DBG("###\t[%s] found\n", cur->value);
381
+				
382
+				return 1;
383
+			}
384
+		}
385
+	}
386
+
387
+	return 0;
388
+}
389
+
356 390
 /*
357 391
  * lost_delete_response_list(list)
358 392
  * removes response list from private memory
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * lost module LoST response parsing functions
3 3
  *
4
- * Copyright (C) 2021 Wolfgang Kampichler
4
+ * Copyright (C) 2022 Wolfgang Kampichler
5 5
  * DEC112, FREQUENTIS AG
6 6
  *
7 7
  * This file is part of Kamailio, a free SIP server.
... ...
@@ -56,6 +56,9 @@
56 56
 
57 57
 #define ERRORS_NODE (const char *)"errors"
58 58
 
59
+#define SIP_S (const char *)"sip:"
60
+#define SIPS_S (const char *)"sips:"
61
+
59 62
 #define HELD_RESPONSE_REFERENCE 1
60 63
 #define HELD_RESPONSE_VALUE 2
61 64
 
... ...
@@ -133,4 +136,7 @@ int is_cid_laquot(char *);
133 136
 int is_http_laquot(char *);
134 137
 int is_https_laquot(char *);
135 138
 
139
+/* list search */
140
+int lost_search_response_list(p_lost_list_t *, char **, const char *);
141
+
136 142
 #endif