[sr-dev] git:master: htable(k) Add new RPC htable.listTables

Olle E. Johansson oej at edvina.net
Wed Jan 9 08:38:45 CET 2013


Module: sip-router
Branch: master
Commit: 2b09c72457a1c84508d74feb9dbc2d86f682508c
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2b09c72457a1c84508d74feb9dbc2d86f682508c

Author: Olle E. Johansson <oej at edvina.net>
Committer: Olle E. Johansson <oej at edvina.net>
Date:   Wed Jan  9 07:56:14 2013 +0100

htable(k) Add new RPC htable.listTables

This RPC list all defined tables and their settings

---

 modules_k/htable/README               |   17 +++++++++++
 modules_k/htable/doc/htable_admin.xml |   25 ++++++++++++++++
 modules_k/htable/ht_api.c             |    7 ++++-
 modules_k/htable/ht_api.h             |    1 +
 modules_k/htable/htable.c             |   52 +++++++++++++++++++++++++++++++++
 5 files changed, 101 insertions(+), 1 deletions(-)

diff --git a/modules_k/htable/README b/modules_k/htable/README
index cc7d5ff..4a48560 100644
--- a/modules_k/htable/README
+++ b/modules_k/htable/README
@@ -64,6 +64,7 @@ Alex Balashov
               7.1. htable.get htable key
               7.2. htable.delete htable key
               7.3. htable.dump htable
+              7.4. htable.listTables
 
         8. Event routes
 
@@ -133,6 +134,7 @@ Chapter 1. Admin Guide
         7.1. htable.get htable key
         7.2. htable.delete htable key
         7.3. htable.dump htable
+        7.4. htable.listTables
 
    8. Event routes
 
@@ -550,6 +552,7 @@ sht_rm_value_re("ha=>.*");
    7.1. htable.get htable key
    7.2. htable.delete htable key
    7.3. htable.dump htable
+   7.4. htable.listTables
 
 7.1.  htable.get htable key
 
@@ -597,6 +600,20 @@ kamcmd htable.get students anna
 kamcmd htable.dump ipban
 ...
 
+7.4.  htable.listTables
+
+   Lists all defined tables
+
+   Name: dhtable.listTables
+
+   Parameters:
+     * None
+
+   Example:
+...
+kamcmd htable.listTables
+...
+
 8. Event routes
 
    8.1. htable:mod-init
diff --git a/modules_k/htable/doc/htable_admin.xml b/modules_k/htable/doc/htable_admin.xml
index 4b6a89f..d652c8f 100644
--- a/modules_k/htable/doc/htable_admin.xml
+++ b/modules_k/htable/doc/htable_admin.xml
@@ -758,6 +758,31 @@ kamcmd htable.dump ipban
 ...
 </programlisting>
 	</section>
+        <section>
+                <title>
+                <function moreinfo="none">htable.listTables</function>
+                </title>
+                <para>
+		Lists all defined tables
+                </para>
+                <para>
+                Name: <emphasis>dhtable.listTables</emphasis>
+                </para>
+                <para>Parameters:</para>
+                <itemizedlist>
+                        <listitem><para>None</para>
+                        </listitem>
+
+                </itemizedlist>
+                <para>
+                Example:
+                </para>
+<programlisting  format="linespecific">
+...
+kamcmd htable.listTables
+...
+</programlisting>
+	</section>
 
 	</section><!-- RPC commands -->
 
diff --git a/modules_k/htable/ht_api.c b/modules_k/htable/ht_api.c
index f4c87cd..cad2e86 100644
--- a/modules_k/htable/ht_api.c
+++ b/modules_k/htable/ht_api.c
@@ -194,6 +194,11 @@ int ht_cell_pkg_free(ht_cell_t *cell)
 }
 
 
+ht_t *ht_get_root(void)
+{
+	return _ht_root;
+}
+
 ht_t* ht_get_table(str *name)
 {
 	unsigned int htid;
@@ -736,7 +741,7 @@ int ht_table_spec(char *spec)
 		LM_ERR("shared memory was not initialized\n");
 		return -1;
 	}
-	/* parse: name=>dbtable=abc;autoexpire=123;size=123*/
+	/* parse: name=>dbtable=abc;autoexpire=123;size=123 */
 	in.s = spec;
 	in.len = strlen(in.s);
 	if(keyvalue_parse_str(&in, KEYVALUE_TYPE_PARAMS, &kval)<0)
diff --git a/modules_k/htable/ht_api.h b/modules_k/htable/ht_api.h
index 4f7f9b6..c8b88f7 100644
--- a/modules_k/htable/ht_api.h
+++ b/modules_k/htable/ht_api.h
@@ -95,5 +95,6 @@ int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val);
 
 int ht_rm_cell_re(str *sre, ht_t *ht, int mode);
 int ht_count_cells_re(str *sre, ht_t *ht, int mode);
+ht_t *ht_get_root(void);
 
 #endif
diff --git a/modules_k/htable/htable.c b/modules_k/htable/htable.c
index 1aa5326..2b22542 100644
--- a/modules_k/htable/htable.c
+++ b/modules_k/htable/htable.c
@@ -530,6 +530,10 @@ static const char* htable_get_doc[2] = {
 	"Get one key from a hash table.",
 	0
 };
+static const char* htable_list_doc[2] = {
+	"List all htables.",
+	0
+};
 
 static void htable_rpc_delete(rpc_t* rpc, void* c) {
 	str htname, keyname;
@@ -686,10 +690,58 @@ error:
 	lock_release(&ht->entries[i].lock);
 }
 
+static void  htable_rpc_list(rpc_t* rpc, void* c)
+{
+	ht_t *ht;
+	void* th;
+	char dbname[128];
+
+	ht = ht_get_root();
+	if(ht==NULL)
+	{
+		rpc->fault(c, 500, "No htables");
+		return;
+	}
+	while (ht != NULL)
+	{
+		int len = 0;
+		/* add entry node */
+		if (rpc->add(c, "{", &th) < 0)
+		{
+			rpc->fault(c, 500, "Internal error creating structure rpc");
+			goto error;
+		}
+		if (ht->dbtable.len > 0) {
+			len = ht->dbtable.len > 127 ? 127 : ht->dbtable.len;
+			memcpy(dbname, ht->dbtable.s, len);
+			dbname[ht->dbtable.len] = '\0';
+		} else {
+			dbname[0] = '\0';
+		}
+
+		if(rpc->struct_add(th, "Ssdddd",
+						"name", &ht->name,	/* String */
+						"dbtable", &dbname ,	/* Char * */
+						"dbmode", (int)  ht->dbmode,		/* u int */
+						"expire", (int) ht->htexpire,		/* u int */
+						"updateexpire", ht->updateexpire,	/* int */
+						"size", (int) ht->htsize		/* u int */
+						) < 0) {
+			rpc->fault(c, 500, "Internal error creating data rpc");
+			goto error;
+		}
+		ht = ht->next;
+	}
+
+error:
+	return;
+}
+
 rpc_export_t htable_rpc[] = {
 	{"htable.dump", htable_rpc_dump, htable_dump_doc, 0},
 	{"htable.delete", htable_rpc_delete, htable_delete_doc, 0},
 	{"htable.get", htable_rpc_get, htable_get_doc, 0},
+	{"htable.listTables", htable_rpc_list, htable_list_doc, 0},
 	{0, 0, 0, 0}
 };
 




More information about the sr-dev mailing list