Module: sip-router Branch: master Commit: f6149f8d960a8c46166d48d570ed2391e34f67c8 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f6149f8d...
Author: pd peter.dunkley@crocodile-rcs.com Committer: pd peter.dunkley@crocodile-rcs.com Date: Wed Oct 19 11:57:36 2011 +0100
modules_k/presence: added db_only mode support for presentity table
- This enhancement was made by Paul Pankhurst at Crocodile RCS
---
modules_k/presence/presence.c | 44 ++++++++++++++++++++-------------- modules_k/presence/presentity.c | 49 +++++++++++++++++++++++--------------- modules_k/presence/publish.c | 2 +- 3 files changed, 57 insertions(+), 38 deletions(-)
diff --git a/modules_k/presence/presence.c b/modules_k/presence/presence.c index 1bb6c9b..b0ec644 100644 --- a/modules_k/presence/presence.c +++ b/modules_k/presence/presence.c @@ -140,7 +140,7 @@ int timeout_rm_subs = 1; int send_fast_notify = 1;
int phtable_size= 9; -phtable_t* pres_htable; +phtable_t* pres_htable=NULL;
static cmd_export_t cmds[]= { @@ -330,22 +330,25 @@ static int mod_init(void) } }
- if(phtable_size< 1) - phtable_size= 256; - else - phtable_size= 1<< phtable_size; + if(dbmode != DB_ONLY) + { + if(phtable_size< 1) + phtable_size= 256; + else + phtable_size= 1<< phtable_size;
- pres_htable= new_phtable(); - if(pres_htable== NULL) - { - LM_ERR("initializing presentity hash table\n"); - return -1; - } + pres_htable= new_phtable(); + if(pres_htable== NULL) + { + LM_ERR("initializing presentity hash table\n"); + return -1; + }
- if(pres_htable_restore()< 0) - { - LM_ERR("filling in presentity hash table from database\n"); - return -1; + if(pres_htable_restore()< 0) + { + LM_ERR("filling in presentity hash table from database\n"); + return -1; + } }
startup_time = (int) time(NULL); @@ -366,9 +369,14 @@ static int mod_init(void) /* for legacy, we also keep the fallback2db parameter, but make sure for consistency */ if(fallback2db) { - dbmode = DB_FALLBACK; + if (dbmode == DB_ONLY) + LM_ERR( "fallback2db ignored as in DB_ONLY mode\n" ); + else + dbmode = DB_FALLBACK; }
+ if (dbmode == DB_ONLY) + LM_INFO( "Database mode set to DB_ONLY\n" ); return 0; }
@@ -751,7 +759,7 @@ int pres_update_status(subs_t subs, str reason, db_key_t* query_cols, } /* save in the list all affected dialogs */ /* if status switches to terminated -> delete dialog */ - if(update_pw_dialogs(&subs, subs.db_flag, subs_array)< 0) + if(dbmode != DB_ONLY && update_pw_dialogs(&subs, subs.db_flag, subs_array)< 0) { LM_ERR( "extracting dialogs from [watcher]=%.*s@%.*s to" " [presentity]=%.*s\n", subs.from_user.len, subs.from_user.s, diff --git a/modules_k/presence/presentity.c b/modules_k/presence/presentity.c index 427a572..75c3cfc 100644 --- a/modules_k/presence/presentity.c +++ b/modules_k/presence/presentity.c @@ -336,8 +336,9 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, if(new_t) { /* insert new record in hash_table */ - - if(insert_phtable(&pres_uri, presentity->event->evp->type, sphere)< 0) + + if ( dbmode != DB_ONLY && + insert_phtable(&pres_uri, presentity->event->evp->type, sphere)< 0) { LM_ERR("inserting record in hash table\n"); goto error; @@ -489,7 +490,8 @@ after_dialog_check:
/* delete from hash table */ - if(delete_phtable(&pres_uri, presentity->event->evp->type)< 0) + if(dbmode != DB_ONLY && + delete_phtable(&pres_uri, presentity->event->evp->type)< 0) { LM_ERR("deleting record from hash table\n"); goto error; @@ -584,7 +586,8 @@ after_dialog_check: if(sphere_enable && presentity->event->evp->type== EVENT_PRESENCE) { - if(update_phtable(presentity, pres_uri, *body)< 0) + if(dbmode != DB_ONLY && + update_phtable(presentity, pres_uri, *body)< 0) { LM_ERR("failed to update sphere for presentity\n"); goto error; @@ -695,6 +698,12 @@ int pres_htable_restore(void) event_t ev; char* sphere= NULL;
+ if ( dbmode == DB_ONLY ) + { + LM_ERR( "Can't restore when dbmode is DB_ONLY\n" ); + return(-1); + } + result_cols[user_col= n_result_cols++]= &str_username_col; result_cols[domain_col= n_result_cols++]= &str_domain_col; result_cols[event_col= n_result_cols++]= &str_event_col; @@ -871,30 +880,32 @@ char* get_sphere(str* pres_uri) if(!sphere_enable) return NULL;
- /* search in hash table*/ - hash_code= core_hash(pres_uri, NULL, phtable_size); + if ( dbmode != DB_ONLY ) + { + /* search in hash table*/ + hash_code= core_hash(pres_uri, NULL, phtable_size);
- lock_get(&pres_htable[hash_code].lock); + lock_get(&pres_htable[hash_code].lock);
- p= search_phtable(pres_uri, EVENT_PRESENCE, hash_code); + p= search_phtable(pres_uri, EVENT_PRESENCE, hash_code);
- if(p) - { - if(p->sphere) + if(p) { - sphere= (char*)pkg_malloc(strlen(p->sphere)* sizeof(char)); - if(sphere== NULL) + if(p->sphere) { - lock_release(&pres_htable[hash_code].lock); - ERR_MEM(PKG_MEM_STR); + sphere= (char*)pkg_malloc(strlen(p->sphere)* sizeof(char)); + if(sphere== NULL) + { + lock_release(&pres_htable[hash_code].lock); + ERR_MEM(PKG_MEM_STR); + } + strcpy(sphere, p->sphere); } - strcpy(sphere, p->sphere); + lock_release(&pres_htable[hash_code].lock); + return sphere; } lock_release(&pres_htable[hash_code].lock); - return sphere; } - lock_release(&pres_htable[hash_code].lock); -
/* if record not found and subscriptions are held also in database, query database*/ if(dbmode == DB_MEMORY_ONLY) diff --git a/modules_k/presence/publish.c b/modules_k/presence/publish.c index c2738bb..79bb65d 100644 --- a/modules_k/presence/publish.c +++ b/modules_k/presence/publish.c @@ -187,7 +187,7 @@ void msg_presentity_clean(unsigned int ticks,void *param) } /* delete from hash table */ - if(delete_phtable(&p[i].uri, ev.type)< 0) + if(dbmode != DB_ONLY && delete_phtable(&p[i].uri, ev.type)< 0) { LM_ERR("deleting from pres hash table\n"); free_event_params(ev.params.list, PKG_MEM_TYPE);