Module: kamailio
Branch: master
Commit: 5c7accbde8423072d5f3d6620115a588d8678294
URL: 
https://github.com/kamailio/kamailio/commit/5c7accbde8423072d5f3d6620115a588d8678294

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2025-12-10T09:40:15+01:00

core: ut - helper functions to search in string

---

Modified: src/core/ut.c
Modified: src/core/ut.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/5c7accbde8423072d5f3d6620115a588d8678294.diff
Patch: 
https://github.com/kamailio/kamailio/commit/5c7accbde8423072d5f3d6620115a588d8678294.patch

---

diff --git a/src/core/ut.c b/src/core/ut.c
index 317a0384a12..2b66b983d98 100644
--- a/src/core/ut.c
+++ b/src/core/ut.c
@@ -324,6 +324,39 @@ char *str_search(str *text, str *needle)
        return NULL;
 }
 
+/**
+ * case sensitive search of a charz string 'needlez' inside str 'text'
+ */
+char *str_search_strz(str *text, char *needlez)
+{
+       str needle;
+
+       needle.s = needlez;
+       needle.len = strlen(needlez);
+
+       return str_search(text, &needle);
+}
+
+/**
+ * search of a char 'needle' inside str 'text'
+ */
+char *str_search_char(str *text, char needle)
+{
+       char *p;
+
+       if(text == NULL || text->s == NULL) {
+               return NULL;
+       }
+
+       for(p = text->s; p <= text->s + text->len; p++) {
+               if(*p == needle) {
+                       return p;
+               }
+       }
+
+       return NULL;
+}
+
 /**
  * @brief search for occurrence of needlez starting from vstart and before vend
  * @return pointer to start of needle in text or NULL if the needle
diff --git a/src/core/ut.h b/src/core/ut.h
index a0b01e23dfb..c4a495ab2ed 100644
--- a/src/core/ut.h
+++ b/src/core/ut.h
@@ -50,19 +50,19 @@
 #define ZSW(_c) ((_c) ? (_c) : "")
 
 /* returns string beginning and length without insignificant chars */
-#define trim_len(_len, _begin, _mystr)                             \
-       do {                                                           \
-               static char _c;                                            \
-               (_len) = (_mystr).len;                                     \
-               while((_len)                                               \
-                               && ((_c = (_mystr).s[(_len)-1]) == 0 || _c == 
'\r' \
-                                               || _c == '\n' || _c == ' ' || 
_c == '\t')) \
-                       (_len)--;                                              \
-               (_begin) = (_mystr).s;                                     \
-               while((_len) && ((_c = *(_begin)) == ' ' || _c == '\t')) { \
-                       (_len)--;                                              \
-                       (_begin)++;                                            \
-               }                                                          \
+#define trim_len(_len, _begin, _mystr)                               \
+       do {                                                             \
+               static char _c;                                              \
+               (_len) = (_mystr).len;                                       \
+               while((_len)                                                 \
+                               && ((_c = (_mystr).s[(_len) - 1]) == 0 || _c == 
'\r' \
+                                               || _c == '\n' || _c == ' ' || 
_c == '\t'))   \
+                       (_len)--;                                               
 \
+               (_begin) = (_mystr).s;                                       \
+               while((_len) && ((_c = *(_begin)) == ' ' || _c == '\t')) {   \
+                       (_len)--;                                               
 \
+                       (_begin)++;                                             
 \
+               }                                                            \
        } while(0)
 
 #define trim_r(_mystr)                                                       \
@@ -145,7 +145,7 @@
 #define is_in_str(p, in) (p < in->s + in->len && *p)
 
 #define ksr_container_of(ptr, type, member) \
-       ((type *)((char *)(ptr)-offsetof(type, member)))
+       ((type *)((char *)(ptr) - offsetof(type, member)))
 
 /* links a value to a msgid */
 struct msgid_var
@@ -1268,6 +1268,8 @@ char *get_abs_pathname(str *base, str *file);
  */
 char *str_search(str *text, str *needle);
 
+char *str_search_strz(str *text, char *needlez);
+
 char *stre_search_strz(char *vstart, char *vend, char *needlez);
 
 char *str_casesearch(str *text, str *needle);
@@ -1280,6 +1282,8 @@ char *str_rsearch(str *text, str *needle);
 
 char *str_rcasesearch(str *text, str *needle);
 
+char *str_search_char(str *text, char needle);
+
 /*
  * ser_memmem() returns the location of the first occurrence of data
  * pattern b2 of size len2 in memory block b1 of size len1 or

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to