فهرست منبع

htable(k) Add new RPC htable.listTables

This RPC list all defined tables and their settings
Olle E. Johansson 12 سال پیش
والد
کامیت
2b09c72457
5فایلهای تغییر یافته به همراه101 افزوده شده و 1 حذف شده
  1. 17 0
      modules_k/htable/README
  2. 25 0
      modules_k/htable/doc/htable_admin.xml
  3. 6 1
      modules_k/htable/ht_api.c
  4. 1 0
      modules_k/htable/ht_api.h
  5. 52 0
      modules_k/htable/htable.c

+ 17 - 0
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

+ 25 - 0
modules_k/htable/doc/htable_admin.xml

@@ -756,6 +756,31 @@ kamcmd htable.get students anna
 ...
 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>
 

+ 6 - 1
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)

+ 1 - 0
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

+ 52 - 0
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}
 };