Browse code

htable: removed mi commands

Daniel-Constantin Mierla authored on 24/12/2016 07:45:37
Showing 3 changed files
... ...
@@ -12,7 +12,6 @@ LIBS=
12 12
 DEFS+=-DKAMAILIO_MOD_INTERFACE
13 13
 
14 14
 SERLIBPATH=../../lib
15
-SER_LIBS+=$(SERLIBPATH)/kmi/kmi
16 15
 SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1
17 16
 SER_LIBS+=$(SERLIBPATH)/srutils/srutils
18 17
 include ../../Makefile.modules
... ...
@@ -954,92 +954,14 @@ sht_iterator_end("i1");
954 954
 		Exported pseudo-variables are documented at &kamwikilink;.
955 955
 		</para>
956 956
 	</section>
957
-	<section>
958
-	<title>MI Commands</title>
959
-	<section>
960
-		<title>
961
-		<function moreinfo="none">sht_reload</function>
962
-		</title>
963
-		<para>
964
-		Reload a hash table from database.
965
-		</para>
966
-		<para>
967
-		Name: <emphasis>sht_reload</emphasis>
968
-		</para>
969
-		<para>Parameters: <emphasis>_hash_table_name_</emphasis> - the name
970
-		of hash table to reload.</para>
971
- 		<para>
972
-		MI FIFO Command Format:
973
-		</para>
974
-        <programlisting  format="linespecific">
975
-		:sht_reload:_reply_fifo_file_
976
-		_hash_table_name_
977
-		_empty_line_
978
-		</programlisting>
979
-    </section>
980
-    <section>
981
-		<title>
982
-		<function moreinfo="none">sht_dump</function>
983
-		</title>
984
-		<para>
985
-		Dump content of a hash table via MI.
986
-		</para>
987
-		<para>
988
-		Name: <emphasis>sht_dump</emphasis>
989
-		</para>
990
-		<para>Parameters: <emphasis>_hash_table_name_</emphasis> - the name
991
-		of hash table to dump.</para>
992
- 		<para>
993
-		MI FIFO Command Format:
994
-		</para>
995
-		<programlisting  format="linespecific">
996
-		:sht_dump:_reply_fifo_file_
997
-		_hash_table_name_
998
-		_empty_line_
999
-		</programlisting>
1000
-    </section>
1001
-    <section>
1002
-		<title>
1003
-		<function moreinfo="none">sht_delete</function>
1004
-		</title>
1005
-		<para>
1006
-		Delete a key from a hash table via MI.
1007
-		</para>
1008
-		<para>
1009
-		Name: <emphasis>sht_delete</emphasis>
1010
-		</para>
1011
-		<para>Parameters:</para>
1012
-		<itemizedlist>
1013
-			<listitem><para><emphasis>_hash_table_name: </emphasis>The table name to delete the key from</para></listitem>
1014
-			<listitem><para><emphasis>_key_name: </emphasis>The key to delete from the htable</para></listitem>
1015
-		</itemizedlist>
1016
-
1017
- 		<para>
1018
-		MI FIFO Command Format:
1019
-		</para>
1020
-		<programlisting  format="linespecific">
1021
-		:sht_delete:_reply_fifo_file_
1022
-		_hash_table_name_
1023
-		_key_name_
1024
-		_empty_line_
1025
-		</programlisting>
1026
-
1027
- 		<para>
1028
-		Example (note the quoting when executing it via FIFO):
1029
-		</para>
1030
-		<programlisting  format="linespecific">
1031
-		kamctl fifo sht_delete auth '"user@example.org::last_auth"'
1032
-		</programlisting>
1033
-    </section>
1034
-    </section>
1035 957
 	<section>
1036 958
         <title>Exported RPC Commands</title>
1037
-        <section>
959
+        <section id="htable.rpc.get">
1038 960
                 <title>
1039 961
                 <function moreinfo="none">htable.get htable key</function>
1040 962
                 </title>
1041 963
                 <para>
1042
-		Lists one value in a hash table
964
+					Lists one value in a hash table
1043 965
                 </para>
1044 966
                 <para>
1045 967
                 Name: <emphasis>htable.get</emphasis>
... ...
@@ -1057,20 +979,20 @@ sht_iterator_end("i1");
1057 979
                 </para>
1058 980
 <programlisting  format="linespecific">
1059 981
 ...
1060
-# Dump $sht(students=>daniel)
1061
-kamcmd htable.get students daniel
982
+# Dump $sht(students=>alice)
983
+kamcmd htable.get students alice
1062 984
 
1063 985
 # Dump first entry in array key course $sht(students=>course[0])
1064 986
 kamcmd htable.get students course[0]
1065 987
 ...
1066 988
 </programlisting>
1067 989
 	</section>
1068
-        <section>
990
+        <section id="htable.rpc.delete">
1069 991
                 <title>
1070 992
                 <function moreinfo="none">htable.delete htable key</function>
1071 993
                 </title>
1072 994
                 <para>
1073
-		Delete one value in a hash table
995
+					Delete one value in a hash table
1074 996
                 </para>
1075 997
                 <para>
1076 998
                 Name: <emphasis>htable.delete</emphasis>
... ...
@@ -1088,15 +1010,15 @@ kamcmd htable.get students course[0]
1088 1010
                 </para>
1089 1011
 <programlisting  format="linespecific">
1090 1012
 ...
1091
-# Delete $sht(students=>anna)
1092
-kamcmd htable.delete students anna
1013
+# Delete $sht(students=>alice)
1014
+kamcmd htable.delete students alice
1093 1015
 
1094 1016
 # Delete first entry in array key course $sht(students=>course[0])
1095 1017
 kamcmd htable.delete students course[0]
1096 1018
 ...
1097 1019
 </programlisting>
1098 1020
 	</section>
1099
-       <section>
1021
+       <section id="htable.rpc.sets">
1100 1022
                 <title>
1101 1023
                 <function moreinfo="none">htable.sets htable key value</function>
1102 1024
                 </title>
... ...
@@ -1129,7 +1051,7 @@ kamcmd htable.sets test x[0] abc
1129 1051
 ...
1130 1052
 </programlisting>
1131 1053
 	</section>
1132
-       <section>
1054
+       <section id="htable.rpc.seti">
1133 1055
                 <title>
1134 1056
                 <function moreinfo="none">htable.seti htable key value</function>
1135 1057
                 </title>
... ...
@@ -1162,7 +1084,7 @@ kamcmd htable.sets test x[0] 123
1162 1084
 ...
1163 1085
 </programlisting>
1164 1086
 	</section>
1165
-        <section>
1087
+        <section id="htable.rpc.dump">
1166 1088
                 <title>
1167 1089
                 <function moreinfo="none">htable.dump htable</function>
1168 1090
                 </title>
... ...
@@ -1187,7 +1109,7 @@ kamcmd htable.dump ipban
1187 1109
 ...
1188 1110
 </programlisting>
1189 1111
 	</section>
1190
-        <section>
1112
+        <section id="htable.rpc.reload">
1191 1113
                 <title>
1192 1114
                 <function moreinfo="none">htable.reload htable</function>
1193 1115
                 </title>
... ...
@@ -1212,7 +1134,7 @@ kamcmd htable.reload ipban
1212 1134
 ...
1213 1135
 </programlisting>
1214 1136
 	</section>
1215
-        <section>
1137
+        <section id="htable.rpc.listTables">
1216 1138
                 <title>
1217 1139
                 <function moreinfo="none">htable.listTables</function>
1218 1140
                 </title>
... ...
@@ -1237,7 +1159,7 @@ kamcmd htable.listTables
1237 1159
 ...
1238 1160
 </programlisting>
1239 1161
 	</section>
1240
-    <section>
1162
+    <section id="htable.rpc.stats">
1241 1163
           <title>
1242 1164
                 <function moreinfo="none">htable.stats</function>
1243 1165
           </title>
... ...
@@ -37,7 +37,6 @@
37 37
 #include "../../core/rpc.h"
38 38
 #include "../../core/rpc_lookup.h"
39 39
 #include "../../core/kemi.h"
40
-#include "../../lib/kmi/mi.h"
41 40
 #include "../../core/fmsg.h"
42 41
 
43 42
 #include "../../core/pvar.h"
... ...
@@ -77,10 +76,6 @@ static int w_ht_iterator_end(struct sip_msg* msg, char* iname, char* foo);
77 76
 
78 77
 int ht_param(modparam_t type, void* val);
79 78
 
80
-static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param);
81
-static struct mi_root* ht_mi_dump(struct mi_root* cmd_tree, void* param);
82
-static struct mi_root* ht_mi_delete(struct mi_root* cmd_tree, void* param);
83
-
84 79
 static pv_export_t mod_pvs[] = {
85 80
 	{ {"sht", sizeof("sht")-1}, PVT_OTHER, pv_get_ht_cell, pv_set_ht_cell,
86 81
 		pv_parse_ht_name, 0, 0, 0 },
... ...
@@ -104,13 +99,6 @@ static pv_export_t mod_pvs[] = {
104 99
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
105 100
 };
106 101
 
107
-static mi_export_t mi_cmds[] = {
108
-	{ "sht_reload",     ht_mi_reload,  0,  0,  0},
109
-	{ "sht_dump",       ht_mi_dump,    0,  0,  0},
110
-	{ "sht_delete",     ht_mi_delete,  0,  0,  0},
111
-	{ 0, 0, 0, 0, 0}
112
-};
113
-
114 102
 
115 103
 static cmd_export_t cmds[]={
116 104
 	{"sht_print",       (cmd_function)ht_print,        0, 0, 0,
... ...
@@ -162,7 +150,7 @@ struct module_exports exports= {
162 150
 	cmds,
163 151
 	params,
164 152
 	0,          /* exported statistics */
165
-	mi_cmds,    /* exported MI functions */
153
+	0,          /* exported MI functions */
166 154
 	mod_pvs,    /* exported pseudo-variables */
167 155
 	0,          /* extra processes */
168 156
 	mod_init,   /* module initialization function */
... ...
@@ -176,11 +164,6 @@ struct module_exports exports= {
176 164
  */
177 165
 static int mod_init(void)
178 166
 {
179
-	if(register_mi_mod(exports.name, mi_cmds)!=0)
180
-	{
181
-		LM_ERR("failed to register MI commands\n");
182
-		return -1;
183
-	}
184 167
 	if(htable_init_rpc()!=0)
185 168
 	{
186 169
 		LM_ERR("failed to register RPC commands\n");
... ...
@@ -630,209 +613,6 @@ error:
630 613
 
631 614
 }
632 615
 
633
-#define MI_ERR_RELOAD 			"ERROR Reloading data"
634
-#define MI_ERR_RELOAD_LEN 		(sizeof(MI_ERR_RELOAD)-1)
635
-static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param)
636
-{
637
-	struct mi_node* node;
638
-	str htname;
639
-	ht_t *ht;
640
-	ht_t nht;
641
-	ht_cell_t *first;
642
-	ht_cell_t *it;
643
-	int i;
644
-
645
-	if(ht_db_url.len<=0)
646
-		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
647
-
648
-	if(ht_db_init_con()!=0)
649
-		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
650
-	if(ht_db_open_con()!=0)
651
-		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
652
-
653
-	node = cmd_tree->node.kids;
654
-	if(node == NULL)
655
-	{
656
-		ht_db_close_con();
657
-		return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
658
-	}
659
-	htname = node->value;
660
-	if(htname.len<=0 || htname.s==NULL)
661
-	{
662
-		LM_ERR("bad hash table name\n");
663
-		ht_db_close_con();
664
-		return init_mi_tree( 500, "bad hash table name", 19);
665
-	}
666
-	ht = ht_get_table(&htname);
667
-	if(ht==NULL || ht->dbtable.len<=0)
668
-	{
669
-		LM_ERR("bad hash table name\n");
670
-		ht_db_close_con();
671
-		return init_mi_tree( 500, "no such hash table", 18);
672
-	}
673
-	memcpy(&nht, ht, sizeof(ht_t));
674
-	/* it's temporary operation - use system malloc */
675
-	nht.entries = (ht_entry_t*)malloc(nht.htsize*sizeof(ht_entry_t));
676
-	if(nht.entries == NULL)
677
-	{
678
-		ht_db_close_con();
679
-		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
680
-	}
681
-	memset(nht.entries, 0, nht.htsize*sizeof(ht_entry_t));
682
-
683
-	if(ht_db_load_table(&nht, &ht->dbtable, 0)<0)
684
-	{
685
-		/* free any entry set if it was a partial load */
686
-		for(i=0; i<nht.htsize; i++)
687
-		{
688
-			first = nht.entries[i].first;
689
-			while(first)
690
-			{
691
-				it = first;
692
-				first = first->next;
693
-				ht_cell_free(it);
694
-			}
695
-		}
696
-		free(nht.entries);
697
-		ht_db_close_con();
698
-		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
699
-	}
700
-
701
-	/* replace old entries */
702
-	for(i=0; i<nht.htsize; i++)
703
-	{
704
-		ht_slot_lock(ht, i);
705
-		first = ht->entries[i].first;
706
-		ht->entries[i].first = nht.entries[i].first;
707
-		ht->entries[i].esize = nht.entries[i].esize;
708
-		ht_slot_unlock(ht, i);
709
-		nht.entries[i].first = first;
710
-	}
711
-	/* free old entries */
712
-	for(i=0; i<nht.htsize; i++)
713
-	{
714
-		first = nht.entries[i].first;
715
-		while(first)
716
-		{
717
-			it = first;
718
-			first = first->next;
719
-			ht_cell_free(it);
720
-		}
721
-	}
722
-	free(nht.entries);
723
-	ht_db_close_con();
724
-	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
725
-}
726
-
727
-static struct mi_root* ht_mi_delete(struct mi_root* cmd_tree, void* param) {
728
-	struct mi_node *node;
729
-	str *htname, *key;
730
-	ht_t *ht;
731
-
732
-	node = cmd_tree->node.kids;
733
-	if (!node)
734
-		goto param_err;
735
-
736
-	htname = &node->value;
737
-	if (!htname->len)
738
-		goto param_err;
739
-
740
-	node = node->next;
741
-	if (!node)
742
-		goto param_err;
743
-
744
-	key = &node->value;
745
-	if (!key->len)
746
-		goto param_err;
747
-
748
-	ht = ht_get_table(htname);
749
-	if (!ht)
750
-		return init_mi_tree(404, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
751
-
752
-	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_DEL_CELL, &ht->name, key, 0, NULL, 0)!=0) {
753
-		LM_ERR("dmq relication failed\n");
754
-	}
755
-
756
-	LM_DBG("deleting key [%.*s] from [%.*s]\n",
757
-		key->len, key->s, htname->len, htname->s);
758
-
759
-	ht_del_cell(ht, key);
760
-
761
-	return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
762
-
763
-param_err:
764
-	return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
765
-}
766
-
767
-static struct mi_root* ht_mi_dump(struct mi_root* cmd_tree, void* param)
768
-{
769
-	struct mi_node* node;
770
-	struct mi_node* node2;
771
-	struct mi_root *rpl_tree;
772
-	struct mi_node *rpl;
773
-	str htname;
774
-	ht_t *ht;
775
-	ht_cell_t *it;
776
-	int i;
777
-	int len;
778
-	char *p;
779
-
780
-	node = cmd_tree->node.kids;
781
-	if(node == NULL)
782
-		return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
783
-	htname = node->value;
784
-	if(htname.len<=0 || htname.s==NULL)
785
-	{
786
-		LM_ERR("bad hash table name\n");
787
-		return init_mi_tree( 500, "bad hash table name", 19);
788
-	}
789
-	ht = ht_get_table(&htname);
790
-	if(ht==NULL)
791
-	{
792
-		LM_ERR("bad hash table name\n");
793
-		return init_mi_tree( 500, "no such hash table", 18);
794
-	}
795
-
796
-	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
797
-	if (rpl_tree==NULL)
798
-		return 0;
799
-	rpl = &rpl_tree->node;
800
-
801
-	for(i=0; i<ht->htsize; i++)
802
-	{
803
-		ht_slot_lock(ht, i);
804
-		it = ht->entries[i].first;
805
-		if(it)
806
-		{
807
-			/* add entry node */
808
-			p = int2str((unsigned long)i, &len);
809
-			node = add_mi_node_child(rpl, MI_DUP_VALUE, "Entry", 5, p, len);
810
-			if (node==0)
811
-				goto error;
812
-			while(it)
813
-			{
814
-				if(it->flags&AVP_VAL_STR) {
815
-					node2 = add_mi_node_child(node, MI_DUP_VALUE, it->name.s, it->name.len,
816
-							it->value.s.s, it->value.s.len);
817
-				} else {
818
-					p = sint2str((long)it->value.n, &len);
819
-					node2 = add_mi_node_child(node, MI_DUP_VALUE, it->name.s, it->name.len,
820
-							p, len);
821
-				}
822
-				if (node2==0)
823
-					goto error;
824
-				it = it->next;
825
-			}
826
-		}
827
-		ht_slot_unlock(ht, i);
828
-	}
829
-
830
-	return rpl_tree;
831
-error:
832
-	free_mi_tree(rpl_tree);
833
-	return 0;
834
-}
835
-
836 616
 #define RPC_DATE_BUF_LEN 21
837 617
 
838 618
 static const char* htable_dump_doc[2] = {
... ...
@@ -982,7 +762,8 @@ static void htable_rpc_sets(rpc_t* rpc, void* c) {
982 762
 		return;
983 763
 	}
984 764
 
985
-	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &ht->name, &keyname, AVP_VAL_STR, &keyvalue, 1)!=0) {
765
+	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL,
766
+				&ht->name, &keyname, AVP_VAL_STR, &keyvalue, 1)!=0) {
986 767
 		LM_ERR("dmq relication failed\n");
987 768
 	}
988 769
 
... ...
@@ -1016,7 +797,8 @@ static void htable_rpc_seti(rpc_t* rpc, void* c) {
1016 797
 		return;
1017 798
 	}
1018 799
 
1019
-	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, &ht->name, &keyname, 0, &keyvalue, 1)!=0) {
800
+	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL,
801
+				&ht->name, &keyname, 0, &keyvalue, 1)!=0) {
1020 802
 		LM_ERR("dmq relication failed\n");
1021 803
 	}
1022 804