Module: kamailio Branch: master Commit: 29a890ffdcd394d26d53bd0951c7ca58262c7696 URL: https://github.com/kamailio/kamailio/commit/29a890ffdcd394d26d53bd0951c7ca58...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2024-04-14T15:29:57+02:00
htable: add ew (end-with) operator for delete items functions
---
Modified: src/modules/htable/ht_api.c Modified: src/modules/htable/ht_api.h Modified: src/modules/htable/ht_dmq.h Modified: src/modules/htable/htable.c
---
Diff: https://github.com/kamailio/kamailio/commit/29a890ffdcd394d26d53bd0951c7ca58... Patch: https://github.com/kamailio/kamailio/commit/29a890ffdcd394d26d53bd0951c7ca58...
---
diff --git a/src/modules/htable/ht_api.c b/src/modules/htable/ht_api.c index 2391cb5c5d0..afda3dc6c54 100644 --- a/src/modules/htable/ht_api.c +++ b/src/modules/htable/ht_api.c @@ -1033,7 +1033,7 @@ int ht_table_spec(char *spec)
coldelim = tok.s[0]; LM_DBG("htable [%.*s] - coldelim [%c]\n", name.len, name.s, - coldelim); + coldelim); } else if(pit->name.len == 7 && strncmp(pit->name.s, "colnull", 7) == 0) { if(tok.len > 1) @@ -1045,8 +1045,7 @@ int ht_table_spec(char *spec) colnull = tok.s[0]; }
- LM_DBG("htable [%.*s] - colnull [%c]\n", name.len, name.s, - colnull); + LM_DBG("htable [%.*s] - colnull [%c]\n", name.len, name.s, colnull); } else { goto error; } @@ -1383,7 +1382,15 @@ int ht_rm_cell_op(str *sre, ht_t *ht, int mode, int op) && strncmp(it->name.s, sre->s, sre->len) == 0) { match = 1; } + } else if(op == HT_RM_OP_EW) { + if(sre->len <= it->name.len + && strncmp(it->name.s + it->name.len - sre->len, + sre->s, sre->len) + == 0) { + match = 1; + } } + } else { if(op == HT_RM_OP_SW) { if(it->flags & AVP_VAL_STR) { @@ -1393,6 +1400,16 @@ int ht_rm_cell_op(str *sre, ht_t *ht, int mode, int op) match = 1; } } + } else if(op == HT_RM_OP_EW) { + if(it->flags & AVP_VAL_STR) { + if(sre->len <= it->value.s.len + && strncmp(it->value.s.s + it->value.s.len + - sre->len, + sre->s, sre->len) + == 0) { + match = 1; + } + } } } if(match == 1) { diff --git a/src/modules/htable/ht_api.h b/src/modules/htable/ht_api.h index e24a93b1f17..7c7642ef5df 100644 --- a/src/modules/htable/ht_api.h +++ b/src/modules/htable/ht_api.h @@ -124,6 +124,7 @@ int ht_reset_content(ht_t *ht); #define HT_RM_OP_EQ 1 #define HT_RM_OP_NE 2 #define HT_RM_OP_SW 3 +#define HT_RM_OP_EW 3 #define HT_RM_OP_RE 4 int ht_rm_cell_op(str *sre, ht_t *ht, int mode, int op); int ht_match_cell_op_str(str *sre, ht_t *ht, int mode, int op); diff --git a/src/modules/htable/ht_dmq.h b/src/modules/htable/ht_dmq.h index bc5f18830be..7577e445a76 100644 --- a/src/modules/htable/ht_dmq.h +++ b/src/modules/htable/ht_dmq.h @@ -39,7 +39,8 @@ typedef enum HT_DMQ_SET_CELL_EXPIRE, HT_DMQ_DEL_CELL, HT_DMQ_RM_CELL_RE, - HT_DMQ_RM_CELL_SW + HT_DMQ_RM_CELL_SW, + HT_DMQ_RM_CELL_EW } ht_dmq_action_t;
int ht_dmq_initialize(); diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c index 0fcd280de9c..6f775bb33ce 100644 --- a/src/modules/htable/htable.c +++ b/src/modules/htable/htable.c @@ -515,6 +515,18 @@ static int ht_rm_items(sip_msg_t *msg, str *hname, str *op, str *val, int mkey) return -1; } return 1; + } else if(strncmp(op->s, "ew", 2) == 0) { + isval.s = *val; + if((ht->dmqreplicate > 0) + && ht_dmq_replicate_action(HT_DMQ_RM_CELL_EW, &ht->name, + NULL, AVP_VAL_STR, &isval, mkey) + != 0) { + LM_ERR("dmq replication failed (op %d)\n", mkey); + } + if(ht_rm_cell_op(val, ht, mkey, HT_RM_OP_EW) < 0) { + return -1; + } + return 1; } LM_WARN("unsupported match operator: %.*s\n", op->len, op->s); break;