Skip to content

Commit

Permalink
htable: add ew (end-with) operator for delete items functions
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 14, 2024
1 parent 671b874 commit 29a890f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/modules/htable/ht_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/htable/ht_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/modules/htable/ht_dmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions src/modules/htable/htable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 29a890f

Please sign in to comment.