[sr-dev] git:master:df659d2e: htable: implemented starts with matching for remove functions
Daniel-Constantin Mierla
miconda at gmail.com
Tue May 23 02:34:30 CEST 2017
Module: kamailio
Branch: master
Commit: df659d2ee44eca688507aab48eb22260ef3577bd
URL: https://github.com/kamailio/kamailio/commit/df659d2ee44eca688507aab48eb22260ef3577bd
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-05-23T02:33:19+02:00
htable: implemented starts with matching for remove functions
---
Modified: src/modules/htable/doc/htable_admin.xml
Modified: src/modules/htable/ht_api.c
Modified: src/modules/htable/ht_api.h
Modified: src/modules/htable/htable.c
---
Diff: https://github.com/kamailio/kamailio/commit/df659d2ee44eca688507aab48eb22260ef3577bd.diff
Patch: https://github.com/kamailio/kamailio/commit/df659d2ee44eca688507aab48eb22260ef3577bd.patch
---
diff --git a/src/modules/htable/doc/htable_admin.xml b/src/modules/htable/doc/htable_admin.xml
index 7d31e4cc0f..6cb19907ad 100644
--- a/src/modules/htable/doc/htable_admin.xml
+++ b/src/modules/htable/doc/htable_admin.xml
@@ -788,6 +788,12 @@ sht_rm_value_re("ha=>.*");
expression.
</para>
</listitem>
+ <listitem>
+ <para>
+ <emphasis>sw</emphasis> - match the val parameter as 'starts
+ with'.
+ </para>
+ </listitem>
</itemizedlist>
<para>
All parameters can be static strings or contain variables.
@@ -822,6 +828,12 @@ sht_rm_name("ha", "re", ".*");
expression.
</para>
</listitem>
+ <listitem>
+ <para>
+ <emphasis>sw</emphasis> - match the val parameter as 'starts
+ with'.
+ </para>
+ </listitem>
</itemizedlist>
<para>
All parameters can be static strings or contain variables.
@@ -830,7 +842,7 @@ sht_rm_name("ha", "re", ".*");
This function can be used from ANY_ROUTE.
</para>
<example>
- <title><function>sht_rm_value_re</function> usage</title>
+ <title><function>sht_rm_value</function> usage</title>
<programlisting format="linespecific">
...
sht_rm_value("ha", "re", ".*");
diff --git a/src/modules/htable/ht_api.c b/src/modules/htable/ht_api.c
index 4c4ba5315b..1bbd079b30 100644
--- a/src/modules/htable/ht_api.c
+++ b/src/modules/htable/ht_api.c
@@ -1270,6 +1270,61 @@ int ht_rm_cell_re(str *sre, ht_t *ht, int mode)
return 0;
}
+int ht_rm_cell_op(str *sre, ht_t *ht, int mode, int op)
+{
+ ht_cell_t *it;
+ ht_cell_t *it0;
+ int match;
+ int i;
+
+ if(sre==NULL || sre->len<=0 || ht==NULL)
+ return -1;
+
+ for(i=0; i<ht->htsize; i++)
+ {
+ /* free entries */
+ ht_slot_lock(ht, i);
+ it = ht->entries[i].first;
+ while(it)
+ {
+ it0 = it->next;
+ match = 0;
+ if(mode==0)
+ {
+ if(op==HT_RM_OP_SW) {
+ if(sre->len<=it->name.len
+ && strncmp(it->name.s, sre->s, sre->len)==0) {
+ match = 1;
+ }
+ }
+ } else {
+ if(op==HT_RM_OP_SW) {
+ if(it->flags&AVP_VAL_STR) {
+ if(sre->len<=it->value.s.len
+ && strncmp(it->value.s.s, sre->s, sre->len)==0) {
+ match = 1;
+ }
+ }
+ }
+ }
+ if(match==1)
+ {
+ if(it->prev==NULL)
+ ht->entries[i].first = it->next;
+ else
+ it->prev->next = it->next;
+ if(it->next)
+ it->next->prev = it->prev;
+ ht->entries[i].esize--;
+ ht_cell_free(it);
+ }
+ it = it0;
+ }
+ ht_slot_unlock(ht, i);
+ }
+ return 0;
+}
+
int ht_reset_content(ht_t *ht)
{
ht_cell_t *it;
diff --git a/src/modules/htable/ht_api.h b/src/modules/htable/ht_api.h
index 8dea56d5ab..d64b68ac95 100644
--- a/src/modules/htable/ht_api.h
+++ b/src/modules/htable/ht_api.h
@@ -115,6 +115,9 @@ int ht_count_cells_re(str *sre, ht_t *ht, int mode);
ht_t *ht_get_root(void);
int ht_reset_content(ht_t *ht);
+#define HT_RM_OP_SW 1
+int ht_rm_cell_op(str *sre, ht_t *ht, int mode, int op);
+
void ht_iterator_init(void);
int ht_iterator_start(str *iname, str *hname);
int ht_iterator_next(str *iname);
diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index aaa4a5c5eb..40d1a558d1 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -437,6 +437,10 @@ static int ht_rm_items(sip_msg_t* msg, str* hname, str* op, str *val,
return -1;
}
return 1;
+ } else if(strncmp(op->s, "sw", 2)==0) {
+ if(ht_rm_cell_op(val, ht, mkey, HT_RM_OP_SW)<0) {
+ return -1;
+ }
}
LM_WARN("unsupported match operator: %.*s\n", op->len, op->s);
break;
More information about the sr-dev
mailing list