Module: kamailio
Branch: master
Commit: 4fe81fe0c31f2578659c3fe02079eadc3af36f46
URL:
https://github.com/kamailio/kamailio/commit/4fe81fe0c31f2578659c3fe02079ead…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2019-01-31T19:59:01+01:00
Merge pull request #1828 from gaaf/htable-flush
htable: Add RPC htable.flush <htable>
---
Modified: src/modules/htable/doc/htable_admin.xml
Modified: src/modules/htable/htable.c
---
Diff:
https://github.com/kamailio/kamailio/commit/4fe81fe0c31f2578659c3fe02079ead…
Patch:
https://github.com/kamailio/kamailio/commit/4fe81fe0c31f2578659c3fe02079ead…
---
diff --git a/src/modules/htable/doc/htable_admin.xml
b/src/modules/htable/doc/htable_admin.xml
index 708973a045..859f7787ca 100644
--- a/src/modules/htable/doc/htable_admin.xml
+++ b/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">
diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index 1da1ba7928..580e3bc881 100644
--- a/src/modules/htable/htable.c
+++ b/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 @@ static void htable_rpc_stats(rpc_t* rpc, void* c)
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}
};