Browse code

htable: Modify previous commit to create new API for RPC and keep old API for backwards compatibility

Thanks to @miconda for a hint!

Olle E. Johansson authored on 07/12/2021 09:09:29
Showing 4 changed files
... ...
@@ -655,14 +655,33 @@ static void ht_cell_unlink(ht_t *ht, int idx, ht_cell_t *it)
655 655
 	ht->entries[idx].esize--;
656 656
 }
657 657
 
658
-/* Delete htable entry
658
+
659
+/* Delete entry in htable.
660
+Return:
661
+  - 1 on error in argument
662
+  0 otherwise
663
+*/
664
+int ht_del_cell(ht_t *ht, str *name)
665
+{
666
+	int ret;
667
+
668
+	ret = ht_del_cell_confirm(ht, name);
669
+	if (ret == -1)
670
+		return -1;
671
+	return 0;
672
+}
673
+
674
+/* Delete htable entry with confirmation
675
+
676
+oldapi = 1 means to always return 0
677
+oldapi = 0 means to return 1 on successful deletion
659 678
 
660 679
 Return:
661 680
 	-1 on error in argument
662 681
 	0 on entry not found
663 682
 	1 on entry found and deleted
664 683
 */
665
-int ht_del_cell(ht_t *ht, str *name)
684
+int ht_del_cell_confirm(ht_t *ht, str *name)
666 685
 {
667 686
 	unsigned int idx;
668 687
 	unsigned int hid;
... ...
@@ -91,6 +91,7 @@ int ht_init_tables(void);
91 91
 int ht_destroy(void);
92 92
 int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode);
93 93
 int ht_del_cell(ht_t *ht, str *name);
94
+int ht_del_cell_confirm(ht_t *ht, str *name);
94 95
 ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, ht_cell_t *old);
95 96
 int ht_cell_exists(ht_t *ht, str *name);
96 97
 
... ...
@@ -410,6 +410,10 @@ error:
410 410
 	return -1;
411 411
 }
412 412
 
413
+/* Replay DMQ action
414
+
415
+Return 0 for non-error. Allt other returns are parsed as error.
416
+*/
413 417
 int ht_dmq_replay_action(ht_dmq_action_t action, str* htname, str* cname,
414 418
 		int type, int_str* val, int mode) {
415 419
 
... ...
@@ -1454,7 +1454,7 @@ static void htable_rpc_delete(rpc_t* rpc, void* c) {
1454 1454
 		LM_ERR("dmq replication failed\n");
1455 1455
 	}
1456 1456
 
1457
-	res = ht_del_cell(ht, &keyname);
1457
+	res = ht_del_cell_confirm(ht, &keyname);
1458 1458
 
1459 1459
 	if (res  == -1) {
1460 1460
 		rpc->fault(c, 500, "Internal error");