[sr-dev] git:mariusbucur/dmq: changed init behaviour

Marius Ovidiu Bucur marius at marius-bucur.ro
Fri Apr 1 07:36:56 CEST 2011


Module: sip-router
Branch: mariusbucur/dmq
Commit: f1808e4d5b2ac89033f61e3c6423da5c27dbbbbd
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f1808e4d5b2ac89033f61e3c6423da5c27dbbbbd

Author: Marius Bucur <marius at marius-bucur.ro>
Committer: mariusb <mariusb at ubuntu.(none)>
Date:   Fri Apr  1 08:35:18 2011 +0300

changed init behaviour

---

 modules_k/dmq/Makefile |    4 +-
 modules_k/dmq/dmq.c    |   94 ++++++++++++++++++++----------------------------
 2 files changed, 41 insertions(+), 57 deletions(-)

diff --git a/modules_k/dmq/Makefile b/modules_k/dmq/Makefile
index 9c35e52..a361bed 100644
--- a/modules_k/dmq/Makefile
+++ b/modules_k/dmq/Makefile
@@ -1,6 +1,6 @@
 # $Id$
 #
-# Presence Agent
+# distributed message queue system for inter-intstance communication
 #
 # 
 # WARNING: do not run this directly, it should be run by the master Makefile
@@ -20,4 +20,4 @@ SERLIBPATH=../../lib
 SER_LIBS+=$(SERLIBPATH)/kmi/kmi
 SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1
 SER_LIBS+=$(SERLIBPATH)/kcore/kcore
-include ../../Makefile.modules
+include ../../Makefile.modules
\ No newline at end of file
diff --git a/modules_k/dmq/dmq.c b/modules_k/dmq/dmq.c
index d8a1040..f2bc2a8 100644
--- a/modules_k/dmq/dmq.c
+++ b/modules_k/dmq/dmq.c
@@ -66,55 +66,51 @@ MODULE_VERSION
 /* database connection */
 db1_con_t *dmq_db = NULL;
 db_func_t dmq_dbf;
-int library_mode= 0;
-str server_address= {0, 0};
+int library_mode = 0;
+str server_address = {0, 0};
 int startup_time = 0;
 int pid = 0;
 
 /* module parameters */
 str db_url;
 
-/* to tag prefix */
-char* to_tag_pref = "10";
-
 /* TM bind */
 struct tm_binds tmb;
 /* SL API structure */
 sl_api_t slb;
 
 /** module functions */
-
 static int mod_init(void);
 static int child_init(int);
 static void destroy(void);
 static int fixup_dmq(void** param, int param_no);
 
-static cmd_export_t cmds[]=
-{
-	{"handle_dmq_message",        (cmd_function)handle_dmq_message, 0, fixup_dmq, 0, REQUEST_ROUTE},
+static cmd_export_t cmds[] = {
+	{"handle_dmq_message",  (cmd_function)handle_dmq_message, 0, fixup_dmq, 0, 
+		REQUEST_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
 
-static param_export_t params[]={
-	{ "db_url",                 STR_PARAM, &db_url.s},
-	{0,0,0}
+static param_export_t params[] = {
+	{"db_url", STR_PARAM, &db_url.s},
+	{0, 0, 0}
 };
 
 static mi_export_t mi_cmds[] = {
-	{ "cleanup",         0,            0,  0,  mi_child_init},
-	{  0,                0,                     0,  0,  0}
+	{"cleanup", 0, 0, 0, mi_child_init},
+	{0, 0, 0, 0, 0}
 };
 
 /** module exports */
-struct module_exports exports= {
-	"dmq",			/* module name */
-	DEFAULT_DLFLAGS,	/* dlopen flags */
+struct module_exports exports = {
+	"dmq",				/* module name */
+	DEFAULT_DLFLAGS,		/* dlopen flags */
 	cmds,				/* exported functions */
 	params,				/* exported parameters */
-	0,					/* exported statistics */
+	0,				/* exported statistics */
 	mi_cmds,   			/* exported MI functions */
-	0,					/* exported pseudo-variables */
-	0,					/* extra processes */
+	0,				/* exported pseudo-variables */
+	0,				/* extra processes */
 	mod_init,			/* module initialization function */
 	0,   				/* response handling function */
 	(destroy_function) destroy, 	/* destroy function */
@@ -124,21 +120,19 @@ struct module_exports exports= {
 /**
  * init module function
  */
-static int mod_init(void)
-{
-	if(register_mi_mod(exports.name, mi_cmds)!=0)
-	{
+static int mod_init(void) {
+	if(register_mi_mod(exports.name, mi_cmds)!=0) {
 		LM_ERR("failed to register MI commands\n");
 		return -1;
 	}
 
 	db_url.len = db_url.s ? strlen(db_url.s) : 0;
 	LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len,db_url.s);
-	if(db_url.s== NULL)
+	if(db_url.s== NULL) {
 		library_mode= 1;
+	}
 
-	if(library_mode== 1)
-	{
+	if(library_mode== 1) {
 		LM_DBG("dmq module used for API library purpose only\n");
 	}
 
@@ -149,40 +143,34 @@ static int mod_init(void)
 	}
 
 	/* load all TM stuff */
-	if(load_tm_api(&tmb)==-1)
-	{
+	if(load_tm_api(&tmb)==-1) {
 		LM_ERR("Can't load tm functions. Module TM not loaded?\n");
 		return -1;
 	}
 	
-	if(db_url.s== NULL)
-	{
+	if(db_url.s== NULL) {
 		LM_ERR("database url not set!\n");
 		return -1;
 	}
 
 	/* binding to database module  */
-	if (db_bind_mod(&db_url, &dmq_dbf))
-	{
+	if (db_bind_mod(&db_url, &dmq_dbf)) {
 		LM_ERR("database module not found\n");
 		return -1;
 	}
 	
 
-	if (!DB_CAPABILITY(dmq_dbf, DB_CAP_ALL))
-	{
+	if (!DB_CAPABILITY(dmq_dbf, DB_CAP_ALL)) {
 		LM_ERR("database module does not implement all functions needed by dmq module\n");
 		return -1;
 	}
 
 	dmq_db = dmq_dbf.init(&db_url);
-	if (!dmq_db)
-	{
+	if (!dmq_db) {
 		LM_ERR("connection to database failed\n");
 		return -1;
 	}
 	
-	/*verify table versions */
 	startup_time = (int) time(NULL);
 	return 0;
 }
@@ -190,26 +178,26 @@ static int mod_init(void)
 /**
  * Initialize children
  */
-static int child_init(int rank)
-{
-	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
-		return 0; /* do nothing for the main process */
+static int child_init(int rank) {
+	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) {
+		/* do nothing for the main process */
+		return 0;
+	}
 
 	pid = my_pid();
 	
 	if(library_mode)
 		return 0;
 
-	if (dmq_dbf.init==0)
-	{
+	if (dmq_dbf.init==0) {
 		LM_CRIT("child_init: database not bound\n");
 		return -1;
 	}
 	if (dmq_db)
 		return 0;
+	
 	dmq_db = dmq_dbf.init(&db_url);
-	if (!dmq_db)
-	{
+	if (!dmq_db) {
 		LM_ERR("child %d: unsuccessful connecting to database\n", rank);
 		return -1;
 	}
@@ -218,21 +206,18 @@ static int child_init(int rank)
 	return 0;
 }
 
-static int mi_child_init(void)
-{
+static int mi_child_init(void) {
 	if(library_mode)
 		return 0;
 
-	if (dmq_dbf.init==0)
-	{
+	if (dmq_dbf.init==0) {
 		LM_CRIT("database not bound\n");
 		return -1;
 	}
 	if (dmq_db)
 		return 0;
 	dmq_db = dmq_dbf.init(&db_url);
-	if (!dmq_db)
-	{
+	if (!dmq_db) {
 		LM_ERR("connecting database\n");
 		return -1;
 	}
@@ -245,6 +230,5 @@ static int mi_child_init(void)
 /*
  * destroy function
  */
-static void destroy(void)
-{
-}
\ No newline at end of file
+static void destroy(void) {
+}




More information about the sr-dev mailing list