Module: sip-router
Branch: admorten/sca
Commit: ce461b43aaf2422d8f223fad78c6d193f8b9277e
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ce461b4…
Author: Juha Heinanen <jh(a)tutpro.com>
Committer: Andrew Mortensen <admorten(a)isc.upenn.edu>
Date: Wed May 1 12:34:25 2013 +0300
modules/htable: added htable.reload rpc command
---
modules/htable/README | 29 ++++++++++---
modules/htable/doc/htable_admin.xml | 25 +++++++++++
modules/htable/htable.c | 82 +++++++++++++++++++++++++++++++++++
3 files changed, 130 insertions(+), 6 deletions(-)
diff --git a/modules/htable/README b/modules/htable/README
index 4a48560..bf28a7a 100644
--- a/modules/htable/README
+++ b/modules/htable/README
@@ -17,7 +17,7 @@ Alex Balashov
<abalashov(a)evaristesys.com>
- Copyright � 2008-2011
http://www.asipto.com
+ Copyright (c) 2008-2011
http://www.asipto.com
__________________________________________________________________
Table of Contents
@@ -64,7 +64,8 @@ Alex Balashov
7.1. htable.get htable key
7.2. htable.delete htable key
7.3. htable.dump htable
- 7.4. htable.listTables
+ 7.4. htable.reload htable
+ 7.5. htable.listTables
8. Event routes
@@ -134,7 +135,8 @@ 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
+ 7.4. htable.reload htable
+ 7.5. htable.listTables
8. Event routes
@@ -494,7 +496,7 @@ sht_rm_value_re("ha=>.*");
* $shtval(htable=>key)
Exported pseudo-variables are documented at
-
http://www.kamailio.org/dokuwiki/.
+
http://www.kamailio.org/wiki/.
6. MI Commands
@@ -552,7 +554,8 @@ 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.4. htable.reload htable
+ 7.5. htable.listTables
7.1. htable.get htable key
@@ -600,7 +603,21 @@ kamcmd htable.get students anna
kamcmd htable.dump ipban
...
-7.4. htable.listTables
+7.4. htable.reload htable
+
+ Reload hash table from database.
+
+ Name: dhtable.reload
+
+ Parameters:
+ * htable : Name of the hash table to reload
+
+ Example:
+...
+kamcmd htable.reload ipban
+...
+
+7.5. htable.listTables
Lists all defined tables
diff --git a/modules/htable/doc/htable_admin.xml b/modules/htable/doc/htable_admin.xml
index d652c8f..978298f 100644
--- a/modules/htable/doc/htable_admin.xml
+++ b/modules/htable/doc/htable_admin.xml
@@ -760,6 +760,31 @@ kamcmd htable.dump ipban
</section>
<section>
<title>
+ <function moreinfo="none">htable.reload
htable</function>
+ </title>
+ <para>
+ Reload hash table from database.
+ </para>
+ <para>
+ Name: <emphasis>dhtable.reload</emphasis>
+ </para>
+ <para>Parameters:</para>
+ <itemizedlist>
+ <listitem><para>htable : Name of the hash table to
reload</para>
+ </listitem>
+
+ </itemizedlist>
+ <para>
+ Example:
+ </para>
+<programlisting format="linespecific">
+...
+kamcmd htable.reload ipban
+...
+</programlisting>
+ </section>
+ <section>
+ <title>
<function
moreinfo="none">htable.listTables</function>
</title>
<para>
diff --git a/modules/htable/htable.c b/modules/htable/htable.c
index 2b22542..e740d71 100644
--- a/modules/htable/htable.c
+++ b/modules/htable/htable.c
@@ -534,6 +534,10 @@ static const char* htable_list_doc[2] = {
"List all htables.",
0
};
+static const char* htable_reload_doc[2] = {
+ "Reload hash table.",
+ 0
+};
static void htable_rpc_delete(rpc_t* rpc, void* c) {
str htname, keyname;
@@ -737,11 +741,89 @@ error:
return;
}
+static void htable_rpc_reload(rpc_t* rpc, void* c)
+{
+ str htname;
+ ht_t *ht;
+ ht_t nht;
+ ht_cell_t *first;
+ ht_cell_t *it;
+ int i;
+
+ if(ht_db_url.len<=0) {
+ rpc->fault(c, 500, "No htable db_url");
+ return;
+ }
+ if(ht_db_init_con()!=0) {
+ rpc->fault(c, 500, "Failed to init htable db connection");
+ return;
+ }
+ if(ht_db_open_con()!=0) {
+ rpc->fault(c, 500, "Failed to open htable db connection");
+ return;
+ }
+
+ 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;
+ }
+
+
+ memcpy(&nht, ht, sizeof(ht_t));
+ nht.entries = (ht_entry_t*)shm_malloc(nht.htsize*sizeof(ht_entry_t));
+ if(nht.entries == NULL)
+ {
+ ht_db_close_con();
+ rpc->fault(c, 500, "Mtree reload failed");
+ return;
+ }
+ memset(nht.entries, 0, nht.htsize*sizeof(ht_entry_t));
+
+ if(ht_db_load_table(&nht, &ht->dbtable, 0)<0)
+ {
+ ht_db_close_con();
+ rpc->fault(c, 500, "Mtree reload failed");
+ return;
+ }
+
+ /* replace old entries */
+ for(i=0; i<nht.htsize; i++)
+ {
+ lock_get(&ht->entries[i].lock);
+ first = ht->entries[i].first;
+ ht->entries[i].first = nht.entries[i].first;
+ ht->entries[i].esize = nht.entries[i].esize;
+ lock_release(&ht->entries[i].lock);
+ nht.entries[i].first = first;
+ }
+ /* free old entries */
+ for(i=0; i<nht.htsize; i++)
+ {
+ first = nht.entries[i].first;
+ while(first)
+ {
+ it = first;
+ first = first->next;
+ ht_cell_free(it);
+ }
+ }
+ ht_db_close_con();
+ 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},
+ {"htable.reload", htable_rpc_reload, htable_reload_doc, 0},
{0, 0, 0, 0}
};