浏览代码

htable: Add RPC htable.flush <htable>

Empties the entire specified hash table
Alex Hermann 6 年之前
父节点
当前提交
19d25bacb8
共有 2 个文件被更改,包括 47 次插入0 次删除
  1. 23 0
      src/modules/htable/doc/htable_admin.xml
  2. 24 0
      src/modules/htable/htable.c

+ 23 - 0
src/modules/htable/doc/htable_admin.xml

@@ -1390,6 +1390,29 @@ kamcmd htable.dump ipban
 ...
 kamcmd htable.reload ipban
 ...
+</programlisting>
+	</section>
+	<section id="htable.rpc.flush">
+          <title>
+                <function moreinfo="none">htable.flush htable</function>
+          </title>
+          <para>
+            Empty the hash table
+          </para>
+          <para>
+            Name: <emphasis>htable.flush</emphasis>
+          </para>
+          <para>Parameters:</para>
+          <itemizedlist>
+            <listitem><para>htable : Name of the hash table to flush</para></listitem>
+          </itemizedlist>
+          <para>
+          Example:
+          </para>
+<programlisting  format="linespecific">
+...
+kamcmd htable.flush ipban
+...
 </programlisting>
 	</section>
         <section id="htable.rpc.listTables">

+ 24 - 0
src/modules/htable/htable.c

@@ -1123,6 +1123,10 @@ static const char* htable_stats_doc[2] = {
 	"Statistics about htables.",
 	0
 };
+static const char* htable_flush_doc[2] = {
+	"Flush hash table.",
+	0
+};
 static const char* htable_reload_doc[2] = {
 	"Reload hash table.",
 	0
@@ -1474,6 +1478,25 @@ error:
 	return;
 }
 
+/*! \brief RPC htable.flush command to empty a hash table */
+static void  htable_rpc_flush(rpc_t* rpc, void* c)
+{
+	str htname;
+	ht_t *ht;
+
+	if (rpc->scan(c, "S", &htname) < 1)
+	{
+		rpc->fault(c, 500, "No htable name given");
+		return;
+	}
+	ht = ht_get_table(&htname);
+	if(ht==NULL)
+	{
+		rpc->fault(c, 500, "No such htable");
+		return;
+	}
+	ht_reset_content(ht);
+}
 
 /*! \brief RPC htable.reload command to reload content of a hash table */
 static void htable_rpc_reload(rpc_t* rpc, void* c)
@@ -1583,6 +1606,7 @@ rpc_export_t htable_rpc[] = {
 	{"htable.listTables", htable_rpc_list, htable_list_doc, RET_ARRAY},
 	{"htable.reload", htable_rpc_reload, htable_reload_doc, 0},
 	{"htable.stats", htable_rpc_stats, htable_stats_doc, RET_ARRAY},
+	{"htable.flush", htable_rpc_flush, htable_flush_doc, 0},
 	{0, 0, 0, 0}
 };