Module: sip-router
Branch: master
Commit: 1fbb9573ba15a9164e9742380bdd597df68df1d3
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1fbb957…
Author: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Date: Mon Apr 23 17:15:34 2012 +0100
modules_k/rls: Added MI command to "clean" the rlsubs and rlpres entries
- This is similar to the clean MI command in presence
- Useful on multi-server systems where you don't want to run the timers
and have each Kamailio instance try and clean. The MI command allows
you to kick of a clean on a specific server as required.
---
modules_k/rls/Makefile | 1 +
modules_k/rls/rls.c | 112 +++++++++++++++++++++++++++++++++++++++++++-----
modules_k/rls/rls.h | 1 -
3 files changed, 102 insertions(+), 12 deletions(-)
diff --git a/modules_k/rls/Makefile b/modules_k/rls/Makefile
index 1c71af7..590418d 100644
--- a/modules_k/rls/Makefile
+++ b/modules_k/rls/Makefile
@@ -17,6 +17,7 @@ LIBS+=-L$(LOCALBASE)/lib -lxml2
DEFS+=-DOPENSER_MOD_INTERFACE
SERLIBPATH=../../lib
+SER_LIBS+=$(SERLIBPATH)/kmi/kmi
SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1
SER_LIBS+=$(SERLIBPATH)/kcore/kcore
include ../../Makefile.modules
diff --git a/modules_k/rls/rls.c b/modules_k/rls/rls.c
index 845297b..026b9b3 100644
--- a/modules_k/rls/rls.c
+++ b/modules_k/rls/rls.c
@@ -43,6 +43,7 @@
#include "../../ut.h"
#include "../../timer_proc.h"
#include "../../hashes.h"
+#include "../../lib/kmi/mi.h"
#include "../../mem/mem.h"
#include "../../mem/shm_mem.h"
#include "../../modules/tm/tm_load.h"
@@ -90,7 +91,6 @@ str xcap_db_url = str_init("");
str rlpres_db_url = str_init("");
int hash_size = 512;
shtable_t rls_table;
-int pid;
contains_event_t pres_contains_event;
search_event_t pres_search_event;
get_event_list_t pres_get_ev_list;
@@ -201,12 +201,14 @@ int rls_max_backend_subs = 0;
static int mod_init(void);
static int child_init(int);
+static int mi_child_init(void);
static void destroy(void);
int rlsubs_table_restore();
void rlsubs_table_update(unsigned int ticks,void *param);
int add_rls_event(modparam_t type, void* val);
int rls_update_subs(struct sip_msg *msg, char *puri, char *pevent);
int fixup_update_subs(void** param, int param_no);
+static struct mi_root* mi_cleanup(struct mi_root* cmd, void* param);
static cmd_export_t cmds[]=
{
@@ -253,20 +255,25 @@ static param_export_t params[]={
{0, 0, 0 }
};
+static mi_export_t mi_cmds[] = {
+ { "cleanup", mi_cleanup, 0, 0, mi_child_init},
+ { 0, 0, 0, 0, 0}
+};
+
/** module exports */
struct module_exports exports= {
"rls", /* module name */
- DEFAULT_DLFLAGS, /* dlopen flags */
+ DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* exported functions */
params, /* exported parameters */
- 0, /* exported statistics */
- 0, /* exported MI functions */
- 0, /* exported pseudo-variables */
- 0, /* extra processes */
+ 0, /* exported statistics */
+ mi_cmds, /* exported MI functions */
+ 0, /* exported pseudo-variables */
+ 0, /* extra processes */
mod_init, /* module initialization function */
- 0, /* response handling function */
- (destroy_function) destroy, /* destroy function */
- child_init /* per-child init function */
+ 0, /* response handling function */
+ (destroy_function) destroy, /* destroy function */
+ child_init /* per-child init function */
};
/**
@@ -676,7 +683,7 @@ static int mod_init(void)
static int child_init(int rank)
{
if (rank==PROC_INIT || rank==PROC_TCP_MAIN)
- return 0; /* don't call child_init for main process more than once */
+ return 0;
if (rank==PROC_MAIN && dbmode == RLS_DB_ONLY)
{
@@ -697,6 +704,8 @@ static int child_init(int rank)
return -1;
}
}
+
+ return 0;
}
LM_DBG("child [%d] pid [%d]\n", rank, getpid());
@@ -769,10 +778,81 @@ static int child_init(int rank)
LM_DBG("child %d: Database connection opened successfully\n", rank);
}
- pid= my_pid();
return 0;
}
+static int mi_child_init(void)
+{
+ if (rls_dbf.init==0)
+ {
+ LM_CRIT("database not bound\n");
+ return -1;
+ }
+ rls_db = rls_dbf.init(&db_url);
+ if (!rls_db)
+ {
+ LM_ERR("Error while connecting database\n");
+ return -1;
+ }
+ else
+ {
+ if (rls_dbf.use_table(rls_db, &rlsubs_table) < 0)
+ {
+ LM_ERR("Error in use_table rlsubs_table\n");
+ return -1;
+ }
+
+ LM_DBG("Database connection opened successfully\n");
+ }
+
+ if (rlpres_dbf.init==0)
+ {
+ LM_CRIT("database not bound\n");
+ return -1;
+ }
+ rlpres_db = rlpres_dbf.init(&rlpres_db_url);
+ if (!rlpres_db)
+ {
+ LM_ERR("Error while connecting database\n");
+ return -1;
+ }
+ else
+ {
+ if (rlpres_dbf.use_table(rlpres_db, &rlpres_table) < 0)
+ {
+ LM_ERR("Error in use_table rlpres_table\n");
+ return -1;
+ }
+
+ LM_DBG("Database connection opened successfully\n");
+ }
+
+ if (rls_xcap_dbf.init==0)
+ {
+ LM_CRIT("database not bound\n");
+ return -1;
+ }
+ rls_xcap_db = rls_xcap_dbf.init(&xcap_db_url);
+ if (!rls_xcap_db)
+ {
+ LM_ERR("Error while connecting database\n");
+ return -1;
+ }
+ else
+ {
+ if (rls_xcap_dbf.use_table(rls_xcap_db, &rls_xcap_table) < 0)
+ {
+ LM_ERR("Error in use_table rls_xcap_table\n");
+ return -1;
+ }
+
+ LM_DBG("Database connection opened successfully\n");
+ }
+
+ return 0;
+
+}
+
/*
* destroy function
*/
@@ -1063,3 +1143,13 @@ int bind_rls(struct rls_binds *pxb)
pxb->rls_handle_notify = rls_handle_notify;
return 0;
}
+
+static struct mi_root* mi_cleanup(struct mi_root* cmd, void *param)
+{
+ LM_DBG("mi_cleanup:start\n");
+
+ (void)rlsubs_table_update(0,0);
+ (void)rls_presentity_clean(0,0);
+
+ return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
+}
diff --git a/modules_k/rls/rls.h b/modules_k/rls/rls.h
index a2e9439..a3b3c39 100644
--- a/modules_k/rls/rls.h
+++ b/modules_k/rls/rls.h
@@ -96,7 +96,6 @@ extern str rls_xcap_table;
extern str db_url;
extern int hash_size;
extern shtable_t rls_table;
-extern int pid;
extern int rls_max_expires;
extern int rls_integrated_xcap_server;
extern int rls_events;