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

Author: Xenofon Karamanos <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2025-12-08T11:16:52+01:00

htable: Add more KEMI functions

- PV shtcn equivalent
- match with mode
- seperate specific functions for exact, prefix, suffix, regex

---

Modified: src/modules/htable/htable.c

---

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

---

diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index 63c0b4ced02..59406deb494 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -1489,6 +1489,51 @@ static int ki_ht_dec(sip_msg_t *msg, str *htname, str 
*itname)
        return ki_ht_add_op(msg, htname, itname, -1);
 }
 
+static int ki_sht_cn(sip_msg_t *msg, str *table, str *op, str *pattern)
+{
+       ht_t *ht;
+       char *pat_buf;
+       str pat;
+       int cnt;
+
+       ht = ht_get_table(table);
+       if(!ht) {
+               LM_ERR("cannot get hash table [%.*s]\n", table->len, table->s);
+               return -1;
+       }
+
+       if(op->len != 0 && op->len != 2) {
+               LM_ERR("invalid operator [%.*s]\n", op->len, op->s);
+               return -1;
+       }
+
+       /* Build pattern with operator prefix */
+       pat_buf = pkg_malloc(pattern->len + 3);
+       if(!pat_buf) {
+               LM_ERR("no pkg memory\n");
+               return -1;
+       }
+
+       pat.s = pat_buf;
+       pat.len = pattern->len + 2;
+       pat.s[pat.len] = '\0';
+
+       /* Prepend operator prefix to pattern */
+       if(op->len == 0) {
+               pat.s[0] = '~';
+               pat.s[1] = '~';
+       } else {
+               pat.s[0] = op->s[0];
+               pat.s[1] = op->s[1];
+       }
+
+       memcpy(pat.s + 2, pattern->s, pattern->len);
+       cnt = ht_count_cells_re(&pat, ht, 0);
+
+       pkg_free(pat_buf);
+       return cnt;
+}
+
 #define RPC_DATE_BUF_LEN 21
 
 /* clang-format off */
@@ -2357,6 +2402,11 @@ static sr_kemi_t sr_kemi_htable_exports[] = {
                { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
                        SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
        },
+       { str_init("htable"), str_init("shtcn_match"),
+               SR_KEMIP_INT, ki_sht_cn,
+               { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
 
        { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };

_______________________________________________
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