Browse code

htable: Add RPC htable.flush <htable>

Empties the entire specified hash table

Alex Hermann authored on 31/01/2019 12:56:53
Showing 2 changed files
... ...
@@ -1390,6 +1390,29 @@ kamcmd htable.dump ipban
1390 1390
 ...
1391 1391
 kamcmd htable.reload ipban
1392 1392
 ...
1393
+</programlisting>
1394
+	</section>
1395
+	<section id="htable.rpc.flush">
1396
+          <title>
1397
+                <function moreinfo="none">htable.flush htable</function>
1398
+          </title>
1399
+          <para>
1400
+            Empty the hash table
1401
+          </para>
1402
+          <para>
1403
+            Name: <emphasis>htable.flush</emphasis>
1404
+          </para>
1405
+          <para>Parameters:</para>
1406
+          <itemizedlist>
1407
+            <listitem><para>htable : Name of the hash table to flush</para></listitem>
1408
+          </itemizedlist>
1409
+          <para>
1410
+          Example:
1411
+          </para>
1412
+<programlisting  format="linespecific">
1413
+...
1414
+kamcmd htable.flush ipban
1415
+...
1393 1416
 </programlisting>
1394 1417
 	</section>
1395 1418
         <section id="htable.rpc.listTables">
... ...
@@ -1123,6 +1123,10 @@ static const char* htable_stats_doc[2] = {
1123 1123
 	"Statistics about htables.",
1124 1124
 	0
1125 1125
 };
1126
+static const char* htable_flush_doc[2] = {
1127
+	"Flush hash table.",
1128
+	0
1129
+};
1126 1130
 static const char* htable_reload_doc[2] = {
1127 1131
 	"Reload hash table.",
1128 1132
 	0
... ...
@@ -1474,6 +1478,25 @@ error:
1474 1478
 	return;
1475 1479
 }
1476 1480
 
1481
+/*! \brief RPC htable.flush command to empty a hash table */
1482
+static void  htable_rpc_flush(rpc_t* rpc, void* c)
1483
+{
1484
+	str htname;
1485
+	ht_t *ht;
1486
+
1487
+	if (rpc->scan(c, "S", &htname) < 1)
1488
+	{
1489
+		rpc->fault(c, 500, "No htable name given");
1490
+		return;
1491
+	}
1492
+	ht = ht_get_table(&htname);
1493
+	if(ht==NULL)
1494
+	{
1495
+		rpc->fault(c, 500, "No such htable");
1496
+		return;
1497
+	}
1498
+	ht_reset_content(ht);
1499
+}
1477 1500
 
1478 1501
 /*! \brief RPC htable.reload command to reload content of a hash table */
1479 1502
 static void htable_rpc_reload(rpc_t* rpc, void* c)
... ...
@@ -1583,6 +1606,7 @@ rpc_export_t htable_rpc[] = {
1583 1606
 	{"htable.listTables", htable_rpc_list, htable_list_doc, RET_ARRAY},
1584 1607
 	{"htable.reload", htable_rpc_reload, htable_reload_doc, 0},
1585 1608
 	{"htable.stats", htable_rpc_stats, htable_stats_doc, RET_ARRAY},
1609
+	{"htable.flush", htable_rpc_flush, htable_flush_doc, 0},
1586 1610
 	{0, 0, 0, 0}
1587 1611
 };
1588 1612