From eb1bf9a69abad3d237c136750fe8cacea4cd0a31 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 13 Jan 2019 11:31:22 +0100 Subject: [PATCH] presence: do not include presence.h in other header files - it exports as extern the module parameter variables and other modules built on top of presence can end up including this header file, overwriting declaration of variables with same name - renamed db_url to pres_db_url, this being a common variable name, to avoid same situation with a mistaken include in the future - GH #1809 --- src/modules/presence/hash.h | 1 - src/modules/presence/presence.c | 21 +++++++++++---------- src/modules/presence/presence.h | 2 +- src/modules/presence/presence_dmq.c | 5 +++-- src/modules/presence/presence_dmq.h | 1 - src/modules/presence/presentity.h | 1 - src/modules/presence/subscribe.h | 1 - 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/modules/presence/hash.h b/src/modules/presence/hash.h index 59731c253d1..8a36fad6a56 100644 --- a/src/modules/presence/hash.h +++ b/src/modules/presence/hash.h @@ -32,7 +32,6 @@ #define PS_HASH_H #include "../../core/lock_ops.h" -//#include "presentity.h" struct presentity; #define REMOTE_TYPE 1<<1 diff --git a/src/modules/presence/presence.c b/src/modules/presence/presence.c index 5fab3e9f3bf..a62e1a163d0 100644 --- a/src/modules/presence/presence.c +++ b/src/modules/presence/presence.c @@ -145,7 +145,7 @@ int counter =0; int pid = 0; char prefix='a'; int startup_time=0; -str db_url = {0, 0}; +str pres_db_url = {0, 0}; int expires_offset = 0; int pres_cseq_offset = 0; uint32_t min_expires= 0; @@ -204,7 +204,7 @@ static cmd_export_t cmds[]= }; static param_export_t params[]={ - { "db_url", PARAM_STR, &db_url}, + { "db_url", PARAM_STR, &pres_db_url}, { "presentity_table", PARAM_STR, &presentity_table}, { "active_watchers_table", PARAM_STR, &active_watchers_table}, { "watchers_table", PARAM_STR, &watchers_table}, @@ -279,9 +279,10 @@ static int mod_init(void) return -1; } - LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len,db_url.s); + LM_DBG("db_url=%s (len=%d addr=%p)\n", ZSW(pres_db_url.s), pres_db_url.len, + pres_db_url.s); - if(db_url.s== NULL) + if(pres_db_url.s== NULL) library_mode= 1; EvList= init_evlist(); @@ -333,14 +334,14 @@ static int mod_init(void) return -1; } - if(db_url.s== NULL) + if(pres_db_url.s== NULL) { LM_ERR("database url not set!\n"); return -1; } /* binding to database module */ - if (db_bind_mod(&db_url, &pa_dbf)) + if (db_bind_mod(&pres_db_url, &pa_dbf)) { LM_ERR("Database module not found\n"); return -1; @@ -353,7 +354,7 @@ static int mod_init(void) return -1; } - pa_db = pa_dbf.init(&db_url); + pa_db = pa_dbf.init(&pres_db_url); if (!pa_db) { LM_ERR("Connection to database failed\n"); @@ -531,9 +532,9 @@ static int child_init(int rank) /* Do not pool the connections where possible when running notifier * processes. */ if (pres_notifier_processes > 0 && pa_dbf.init2) - pa_db = pa_dbf.init2(&db_url, DB_POOLING_NONE); + pa_db = pa_dbf.init2(&pres_db_url, DB_POOLING_NONE); else - pa_db = pa_dbf.init(&db_url); + pa_db = pa_dbf.init(&pres_db_url); if (!pa_db) { LM_ERR("child %d: unsuccessful connecting to database\n", rank); @@ -572,7 +573,7 @@ static void destroy(void) { if(subs_htable && subs_dbmode == WRITE_BACK) { /* open database connection */ - pa_db = pa_dbf.init(&db_url); + pa_db = pa_dbf.init(&pres_db_url); if (!pa_db) { LM_ERR("mod_destroy: unsuccessful connecting to database\n"); } else diff --git a/src/modules/presence/presence.h b/src/modules/presence/presence.h index bdce11ef0d9..7f99073b081 100644 --- a/src/modules/presence/presence.h +++ b/src/modules/presence/presence.h @@ -62,7 +62,7 @@ extern db_func_t pa_dbf; extern db1_con_t* pa_db; /* PRESENCE database */ -extern str db_url; +extern str pres_db_url; extern str presentity_table; extern str active_watchers_table; extern str watchers_table; diff --git a/src/modules/presence/presence_dmq.c b/src/modules/presence/presence_dmq.c index 258116d53a4..6a775d0a0da 100644 --- a/src/modules/presence/presence_dmq.c +++ b/src/modules/presence/presence_dmq.c @@ -20,6 +20,7 @@ * */ +#include "presence.h" #include "presence_dmq.h" static str pres_dmq_content_type = str_init("application/json"); @@ -112,9 +113,9 @@ static int pres_dmq_init_proc() /* Do not pool the connections where possible when running notifier * processes. */ if(pres_notifier_processes > 0 && pa_dbf.init2) - pa_db = pa_dbf.init2(&db_url, DB_POOLING_NONE); + pa_db = pa_dbf.init2(&pres_db_url, DB_POOLING_NONE); else - pa_db = pa_dbf.init(&db_url); + pa_db = pa_dbf.init(&pres_db_url); if(!pa_db) { LM_ERR("dmq_worker_init: unsuccessful database connection\n"); diff --git a/src/modules/presence/presence_dmq.h b/src/modules/presence/presence_dmq.h index 357629ccfa3..5602c3399e4 100644 --- a/src/modules/presence/presence_dmq.h +++ b/src/modules/presence/presence_dmq.h @@ -22,7 +22,6 @@ #ifndef _PRESENCE_DMQ_H_ #define _PRESENCE_DMQ_H_ -#include "presence.h" #include "presentity.h" #include "../dmq/bind_dmq.h" #include "../../lib/srutils/srjson.h" diff --git a/src/modules/presence/presentity.h b/src/modules/presence/presentity.h index 8fe75cf642c..c672f6c0251 100644 --- a/src/modules/presence/presentity.h +++ b/src/modules/presence/presentity.h @@ -32,7 +32,6 @@ #include "../../core/str.h" #include "../../core/parser/msg_parser.h" #include "event_list.h" -#include "presence.h" extern char prefix; diff --git a/src/modules/presence/subscribe.h b/src/modules/presence/subscribe.h index 6f3cd637d87..8c2caa923ae 100644 --- a/src/modules/presence/subscribe.h +++ b/src/modules/presence/subscribe.h @@ -30,7 +30,6 @@ #ifndef SUBSCRIBE_H #define SUBSCRIBE_H -//#include "presence.h" #include "../../core/str.h" #include "../../lib/srdb1/db.h"