Browse Source

htable: add ew (end-with) operator for delete items functions

Daniel-Constantin Mierla 1 year ago
parent
commit
29a890ffdc

+ 20 - 3
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) {

+ 1 - 0
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);

+ 2 - 1
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();

+ 12 - 0
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;