From fe0e0b894b16478ae490eac6b873ea6c39dd5b2f Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Tue, 14 Apr 2020 11:10:55 +0200 Subject: [PATCH] presence: renamed global vars to add common module prefix - better protection against name conflicts, as this module is used by other modules and can run in library mode --- src/modules/presence/event_list.c | 24 ++--- src/modules/presence/event_list.h | 2 +- src/modules/presence/hash.c | 11 ++- src/modules/presence/hash.h | 2 +- src/modules/presence/notify.c | 29 +++--- src/modules/presence/presence.c | 159 ++++++++++++++++-------------- src/modules/presence/presence.h | 28 +++--- src/modules/presence/presentity.c | 24 ++--- src/modules/presence/presentity.h | 2 +- src/modules/presence/publish.c | 14 +-- src/modules/presence/subscribe.c | 68 ++++++------- src/modules/presence/utils_func.c | 6 +- 12 files changed, 196 insertions(+), 173 deletions(-) diff --git a/src/modules/presence/event_list.c b/src/modules/presence/event_list.c index 6f062614e10..5afd6eb900c 100644 --- a/src/modules/presence/event_list.c +++ b/src/modules/presence/event_list.c @@ -231,10 +231,10 @@ int add_event(pres_ev_t *event) ev->default_expires = event->default_expires; if(not_in_list) { - ev->next = EvList->events; - EvList->events = ev; + ev->next = pres_evlist->events; + pres_evlist->events = ev; } - EvList->ev_count++; + pres_evlist->ev_count++; LM_DBG("successfully added event: %.*s - len= %d\n", ev->name.len, ev->name.s, ev->name.len); @@ -319,7 +319,7 @@ void free_event_params(param_t *params, int mem_type) pres_ev_t *search_event(event_t *event) { pres_ev_t *pres_ev; - pres_ev = EvList->events; + pres_ev = pres_evlist->events; LM_DBG("start event= [%.*s/%d]\n", event->name.len, event->name.s, event->type); @@ -388,13 +388,14 @@ int search_event_params(event_t *ev, event_t *searched_ev) } int get_event_list(str **ev_list) { - pres_ev_t *ev = EvList->events; + pres_ev_t *ev = pres_evlist->events; int i; str *list; *ev_list = NULL; - if(EvList->ev_count == 0) + if(pres_evlist->ev_count == 0) { return 0; + } list = (str *)pkg_malloc(sizeof(str)); if(list == NULL) { @@ -402,7 +403,7 @@ int get_event_list(str **ev_list) return -1; } memset(list, 0, sizeof(str)); - list->s = (char *)pkg_malloc(EvList->ev_count * MAX_EVNAME_SIZE); + list->s = (char *)pkg_malloc(pres_evlist->ev_count * MAX_EVNAME_SIZE); if(list->s == NULL) { LM_ERR("No more memory\n"); pkg_free(list); @@ -410,7 +411,7 @@ int get_event_list(str **ev_list) } list->s[0] = '\0'; - for(i = 0; i < EvList->ev_count; i++) { + for(i = 0; i < pres_evlist->ev_count; i++) { if(i > 0) { memcpy(list->s + list->len, ", ", 2); list->len += 2; @@ -427,13 +428,14 @@ int get_event_list(str **ev_list) void destroy_evlist(void) { pres_ev_t *e1, *e2; - if(EvList) { - e1 = EvList->events; + if(pres_evlist) { + e1 = pres_evlist->events; while(e1) { e2 = e1->next; free_pres_event(e1); e1 = e2; } - shm_free(EvList); + shm_free(pres_evlist); + pres_evlist = NULL; } } diff --git a/src/modules/presence/event_list.h b/src/modules/presence/event_list.h index 4962dd5f227..3f30cb8265e 100644 --- a/src/modules/presence/event_list.h +++ b/src/modules/presence/event_list.h @@ -150,7 +150,7 @@ typedef int (*get_event_list_t)(str **ev_list); void destroy_evlist(void); -extern evlist_t *EvList; +extern evlist_t *pres_evlist; pres_ev_t *search_event(event_t *event); typedef pres_ev_t *(*search_event_t)(event_t *event); diff --git a/src/modules/presence/hash.c b/src/modules/presence/hash.c index 50d4d9948cb..ea50ab6e80b 100644 --- a/src/modules/presence/hash.c +++ b/src/modules/presence/hash.c @@ -272,16 +272,19 @@ int insert_shtable(shtable_t htable, unsigned int hash_code, subs_t *subs) subs->pres_uri.len, subs->pres_uri.s, subs->callid.len, subs->callid.s); /* delete this record */ - if (prev_rec) + if (prev_rec) { prev_rec->next = rec->next; - else + } else { htable[hash_code].entries->next = rec->next; + } - if (subs_dbmode != NO_DB) + if (pres_subs_dbmode != NO_DB) { delete_db_subs(&rec->to_tag, &rec->from_tag, &rec->callid); + } - if (rec->contact.s!=NULL) + if (rec->contact.s!=NULL) { shm_free(rec->contact.s); + } shm_free(rec); break; diff --git a/src/modules/presence/hash.h b/src/modules/presence/hash.h index 676e6b4cff3..6d13018f489 100644 --- a/src/modules/presence/hash.h +++ b/src/modules/presence/hash.h @@ -120,7 +120,7 @@ typedef struct pres_entry struct pres_entry *next; } pres_entry_t; -typedef struct pres_htable +typedef struct pres_phtable { pres_entry_t *entries; gen_lock_t lock; diff --git a/src/modules/presence/notify.c b/src/modules/presence/notify.c index 3bc1d0dc521..92c5b607eb3 100644 --- a/src/modules/presence/notify.c +++ b/src/modules/presence/notify.c @@ -294,7 +294,7 @@ int get_wi_subs_db(subs_t *subs, watcher_t *watchers) query_ops[n_query_cols] = OP_GT; query_vals[n_query_cols].type = DB1_INT; query_vals[n_query_cols].nul = 0; - query_vals[n_query_cols].val.int_val = (int)time(NULL) + expires_offset; + query_vals[n_query_cols].val.int_val = (int)time(NULL) + pres_expires_offset; n_query_cols++; result_cols[status_col = n_result_cols++] = &str_status_col; @@ -387,7 +387,7 @@ str *get_wi_notify_body(subs_t *subs, subs_t *watcher_subs) goto done; } - if(subs_dbmode == DB_ONLY) { + if(pres_subs_dbmode == DB_ONLY) { if(get_wi_subs_db(subs, watchers) < 0) { LM_ERR("getting watchers from database\n"); goto error; @@ -1131,7 +1131,7 @@ int get_subs_db( s.event = event; s.local_cseq = row_vals[cseq_col].val.int_val + 1; - if(row_vals[expires_col].val.int_val < (int)time(NULL) + expires_offset) + if(row_vals[expires_col].val.int_val < (int)time(NULL) + pres_expires_offset) s.expires = 0; else s.expires = row_vals[expires_col].val.int_val - (int)time(NULL); @@ -1169,11 +1169,10 @@ subs_t *get_subs_dialog(str *pres_uri, pres_ev_t *event, str *sender) subs_t *s_array = NULL; int n = 0; - /* if subs_dbmode!=DB_ONLY, should take the subscriptions from the hashtable only - in DB_ONLY mode should take all dialogs from db - */ + /* if pres_subs_dbmode!=DB_ONLY, should take the subscriptions from the + hashtable only in DB_ONLY mode should take all dialogs from db */ - if(subs_dbmode == DB_ONLY) { + if(pres_subs_dbmode == DB_ONLY) { if(get_subs_db(pres_uri, event, sender, &s_array, &n) < 0) { LM_ERR("getting dialogs from database\n"); goto error; @@ -1578,7 +1577,7 @@ int notify(subs_t *subs, subs_t *watcher_subs, str *n_body, int force_null_body, &subs->pres_uri, &subs->event->name, shtable_size); /* if subscriptions are held also in memory, update the subscription hashtable */ - if(subs_dbmode != DB_ONLY) { + if(pres_subs_dbmode != DB_ONLY) { if(update_shtable(subs_htable, hash_code, subs, LOCAL_TYPE) < 0) { /* subscriptions are held only in memory, and hashtable update failed */ LM_ERR("updating subscription record in hash table\n"); @@ -1587,8 +1586,8 @@ int notify(subs_t *subs, subs_t *watcher_subs, str *n_body, int force_null_body, } /* if DB_ONLY mode or WRITE_THROUGH update in database */ if(subs->recv_event != PRES_SUBSCRIBE_RECV - && ((subs_dbmode == DB_ONLY && pres_notifier_processes == 0) - || subs_dbmode == WRITE_THROUGH)) { + && ((pres_subs_dbmode == DB_ONLY && pres_notifier_processes == 0) + || pres_subs_dbmode == WRITE_THROUGH)) { LM_DBG("updating subscription to database\n"); if(update_subs_db(subs, LOCAL_TYPE) < 0) { LM_ERR("updating subscription in database\n"); @@ -1764,7 +1763,7 @@ void p_tm_callback(struct cell *t, int type, struct tmcb_params *ps) run_notify_reply_event(t, ps); if(ps->code == 404 || ps->code == 481 - || (ps->code == 408 && timeout_rm_subs + || (ps->code == 408 && pres_timeout_rm_subs && subs->status != TERMINATED_STATUS) || pres_get_delete_sub()) { delete_subs(&subs->pres_uri, &subs->event->name, &subs->to_tag, @@ -2601,7 +2600,7 @@ static int notifier_notify(subs_t *sub, int *updated, int *end_transaction) goto error; } else if(num_other_watchers == 0) attempt_delete_presentities = 1; - } else if(!send_fast_notify) + } else if(!pres_send_fast_notify) goto done; } @@ -2692,7 +2691,7 @@ int process_dialogs(int round, int presence_winfo) } if(pa_dbf.start_transaction) { - if(pa_dbf.start_transaction(pa_db, db_table_lock) < 0) { + if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -2796,7 +2795,7 @@ int process_dialogs(int round, int presence_winfo) } if(pa_dbf.start_transaction) { - if(pa_dbf.start_transaction(pa_db, db_table_lock) < 0) { + if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -2856,7 +2855,7 @@ int process_dialogs(int round, int presence_winfo) cached_updated_winfo = sub.updated_winfo = VAL_INT(&dvalues[updated_winfo_col]); - if(VAL_INT(&dvalues[expires_col]) > now + expires_offset) + if(VAL_INT(&dvalues[expires_col]) > now + pres_expires_offset) sub.expires = VAL_INT(&dvalues[expires_col]) - now; else sub.expires = 0; diff --git a/src/modules/presence/presence.c b/src/modules/presence/presence.c index 52ad35bef5a..c25d1aa8f64 100644 --- a/src/modules/presence/presence.c +++ b/src/modules/presence/presence.c @@ -81,8 +81,8 @@ MODULE_VERSION #define P_TABLE_VERSION 5 #define ACTWATCH_TABLE_VERSION 12 -static int clean_period = 100; -static int db_update_period = 100; +static int pres_clean_period = 100; +static int pres_db_update_period = 100; int pres_local_log_level = L_INFO; static char *pres_log_facility_str = @@ -97,20 +97,20 @@ str active_watchers_table = str_init("active_watchers"); str watchers_table = str_init("watchers"); int pres_fetch_rows = 500; -int library_mode = 0; -str server_address = {0, 0}; -evlist_t *EvList = NULL; +static int pres_library_mode = 0; +str pres_server_address = {0, 0}; +evlist_t *pres_evlist = NULL; int pres_subs_remove_match = 0; int _pres_subs_mode = 1; -/* sip uri match */ +int pres_uri_match = 0; +/* sip uri match function pointer */ sip_uri_match_f presence_sip_uri_match; static int sip_uri_case_sensitive_match(str *s1, str *s2); static int sip_uri_case_insensitive_match(str *s1, str *s2); -int pres_uri_match = 0; /* to tag prefix */ -char *to_tag_pref = "10"; +char *pres_totag_pref = "10"; /* TM bind */ struct tm_binds tmb; @@ -142,22 +142,22 @@ static int presence_init_rpc(void); static int w_pres_has_subscribers(struct sip_msg *_msg, char *_sp1, char *_sp2); static int fixup_has_subscribers(void **param, int param_no); -int counter = 0; -int pid = 0; -char prefix = 'a'; -int startup_time = 0; +int pres_counter = 0; +int pres_pid = 0; +char pres_prefix = 'a'; +int pres_startup_time = 0; str pres_db_url = {0, 0}; -int expires_offset = 0; +int pres_expires_offset = 0; int pres_cseq_offset = 0; -uint32_t min_expires = 0; -int min_expires_action = 1; -uint32_t max_expires = 3600; +uint32_t pres_min_expires = 0; +int pres_min_expires_action = 1; +uint32_t pres_max_expires = 3600; int shtable_size = 9; shtable_t subs_htable = NULL; -int subs_dbmode = WRITE_BACK; -int sphere_enable = 0; -int timeout_rm_subs = 1; -int send_fast_notify = 1; +int pres_subs_dbmode = WRITE_BACK; +int pres_sphere_enable = 0; +int pres_timeout_rm_subs = 1; +int pres_send_fast_notify = 1; int publ_cache_enabled = 1; int pres_waitn_time = 5; int pres_notifier_poll_rate = 10; @@ -170,8 +170,8 @@ str pres_retrieve_order_by = str_init("priority"); int pres_enable_dmq = 0; int pres_delete_same_subs = 0; -int db_table_lock_type = 1; -db_locking_t db_table_lock = DB_LOCKING_WRITE; +int pres_db_table_lock_type = 1; +db_locking_t pres_db_table_lock = DB_LOCKING_WRITE; int *pres_notifier_id = NULL; @@ -213,28 +213,28 @@ static param_export_t params[]={ { "presentity_table", PARAM_STR, &presentity_table}, { "active_watchers_table", PARAM_STR, &active_watchers_table}, { "watchers_table", PARAM_STR, &watchers_table}, - { "clean_period", INT_PARAM, &clean_period }, - { "db_update_period", INT_PARAM, &db_update_period }, + { "clean_period", INT_PARAM, &pres_clean_period }, + { "db_update_period", INT_PARAM, &pres_db_update_period }, { "waitn_time", INT_PARAM, &pres_waitn_time }, { "notifier_poll_rate", INT_PARAM, &pres_notifier_poll_rate }, { "notifier_processes", INT_PARAM, &pres_notifier_processes }, { "force_delete", INT_PARAM, &pres_force_delete }, { "startup_mode", INT_PARAM, &pres_startup_mode }, - { "to_tag_pref", PARAM_STRING, &to_tag_pref }, - { "expires_offset", INT_PARAM, &expires_offset }, - { "max_expires", INT_PARAM, &max_expires }, - { "min_expires", INT_PARAM, &min_expires }, - { "min_expires_action", INT_PARAM, &min_expires_action }, - { "server_address", PARAM_STR, &server_address}, + { "to_tag_pref", PARAM_STRING, &pres_totag_pref }, + { "expires_offset", INT_PARAM, &pres_expires_offset }, + { "max_expires", INT_PARAM, &pres_max_expires }, + { "min_expires", INT_PARAM, &pres_min_expires }, + { "min_expires_action", INT_PARAM, &pres_min_expires_action }, + { "server_address", PARAM_STR, &pres_server_address}, { "subs_htable_size", INT_PARAM, &shtable_size}, { "pres_htable_size", INT_PARAM, &phtable_size}, - { "subs_db_mode", INT_PARAM, &subs_dbmode}, + { "subs_db_mode", INT_PARAM, &pres_subs_dbmode}, { "publ_cache", INT_PARAM, &publ_cache_enabled}, - { "enable_sphere_check", INT_PARAM, &sphere_enable}, - { "timeout_rm_subs", INT_PARAM, &timeout_rm_subs}, - { "send_fast_notify", INT_PARAM, &send_fast_notify}, + { "enable_sphere_check", INT_PARAM, &pres_sphere_enable}, + { "timeout_rm_subs", INT_PARAM, &pres_timeout_rm_subs}, + { "send_fast_notify", INT_PARAM, &pres_send_fast_notify}, { "fetch_rows", INT_PARAM, &pres_fetch_rows}, - { "db_table_lock_type", INT_PARAM, &db_table_lock_type}, + { "db_table_lock_type", INT_PARAM, &pres_db_table_lock_type}, { "local_log_level", PARAM_INT, &pres_local_log_level}, { "local_log_facility", PARAM_STR, &pres_log_facility_str}, { "subs_remove_match", PARAM_INT, &pres_subs_remove_match}, @@ -295,16 +295,18 @@ static int mod_init(void) LM_DBG("db_url=%s (len=%d addr=%p)\n", ZSW(pres_db_url.s), pres_db_url.len, pres_db_url.s); - if(pres_db_url.s == NULL) - library_mode = 1; + if(pres_db_url.s == NULL || pres_db_url.len == 0) { + LM_DBG("db url is not set - switch to library mode\n"); + pres_library_mode = 1; + } - EvList = init_evlist(); - if(!EvList) { + pres_evlist = init_evlist(); + if(!pres_evlist) { LM_ERR("unsuccessful initialize event list\n"); return -1; } - if(library_mode == 1) { + if(pres_library_mode == 1) { LM_DBG("Presence module used for API library purpose only\n"); return 0; } @@ -313,26 +315,31 @@ static int mod_init(void) return -1; } - if(expires_offset < 0) - expires_offset = 0; + if(pres_expires_offset < 0) { + pres_expires_offset = 0; + } - if(to_tag_pref == NULL || strlen(to_tag_pref) == 0) - to_tag_pref = "10"; + if(pres_totag_pref == NULL || strlen(pres_totag_pref) == 0) { + pres_totag_pref = "10"; + } - if(max_expires == 0) - max_expires = 3600; + if(pres_max_expires <= 0) { + pres_max_expires = 3600; + } - if(min_expires > max_expires) - min_expires = max_expires; + if(pres_min_expires > pres_max_expires) { + pres_min_expires = pres_max_expires; + } - if(min_expires_action < 1 || min_expires_action > 2) { + if(pres_min_expires_action < 1 || pres_min_expires_action > 2) { LM_ERR("min_expires_action must be 1 = RFC 6665/3261 Reply 423, 2 = " "force min_expires value\n"); return -1; } - if(server_address.s == NULL) + if(pres_server_address.s == NULL || pres_server_address.len==0) { LM_DBG("server_address parameter not set in configuration file\n"); + } /* bind the SL API */ if(sl_load_api(&slb) != 0) { @@ -380,7 +387,7 @@ static int mod_init(void) goto dberror; } - if(subs_dbmode != NO_DB + if(pres_subs_dbmode != NO_DB && db_check_table_version(&pa_dbf, pa_db, &active_watchers_table, ACTWATCH_TABLE_VERSION) < 0) { @@ -388,7 +395,7 @@ static int mod_init(void) goto dberror; } - if(subs_dbmode != DB_ONLY) { + if(pres_subs_dbmode != DB_ONLY) { if(shtable_size < 1) shtable_size = 512; else @@ -423,23 +430,27 @@ static int mod_init(void) } } - startup_time = (int)time(NULL); - if(clean_period > 0) { - register_timer(msg_presentity_clean, 0, clean_period); - register_timer(msg_watchers_clean, 0, clean_period); + pres_startup_time = (int)time(NULL); + if(pres_clean_period > 0) { + register_timer(msg_presentity_clean, 0, pres_clean_period); + register_timer(msg_watchers_clean, 0, pres_clean_period); } - if(db_update_period > 0) - register_timer(timer_db_update, 0, db_update_period); + if(pres_db_update_period > 0) { + register_timer(timer_db_update, 0, pres_db_update_period); + } - if(pres_waitn_time <= 0) + if(pres_waitn_time <= 0) { pres_waitn_time = 5; + } - if(pres_notifier_poll_rate <= 0) + if(pres_notifier_poll_rate <= 0) { pres_notifier_poll_rate = 10; + } - if(pres_notifier_processes < 0 || subs_dbmode != DB_ONLY) + if(pres_notifier_processes < 0 || pres_subs_dbmode != DB_ONLY) { pres_notifier_processes = 0; + } if(pres_notifier_processes > 0) { if((pres_notifier_id = @@ -468,8 +479,9 @@ static int mod_init(void) pres_local_log_facility = cfg_get(core, core_cfg, log_facility); } - if(db_table_lock_type != 1) - db_table_lock = DB_LOCKING_NONE; + if(pres_db_table_lock_type != 1) { + pres_db_table_lock = DB_LOCKING_NONE; + } pa_dbf.close(pa_db); pa_db = NULL; @@ -496,13 +508,15 @@ static int mod_init(void) */ static int child_init(int rank) { - if(rank == PROC_INIT || rank == PROC_TCP_MAIN) + if(rank == PROC_INIT || rank == PROC_TCP_MAIN) { return 0; + } - pid = my_pid(); + pres_pid = my_pid(); - if(library_mode) + if(pres_library_mode) { return 0; + } if(sruid_init(&pres_sruid, '-', "pres", SRUID_INC) < 0) { return -1; @@ -568,7 +582,7 @@ static int child_init(int rank) */ static void destroy(void) { - if(subs_htable && subs_dbmode == WRITE_BACK) { + if(subs_htable && pres_subs_dbmode == WRITE_BACK) { /* open database connection */ pa_db = pa_dbf.init(&pres_db_url); if(!pa_db) { @@ -594,7 +608,7 @@ static void destroy(void) static int fixup_presence(void **param, int param_no) { - if(library_mode) { + if(pres_library_mode) { LM_ERR("Bad config - you can not call 'handle_publish' function" " (db_url not set)\n"); return -1; @@ -608,7 +622,7 @@ static int fixup_presence(void **param, int param_no) static int fixup_subscribe(void **param, int param_no) { - if(library_mode) { + if(pres_library_mode) { LM_ERR("Bad config - you can not call 'handle_subscribe' function" " (db_url not set)\n"); return -1; @@ -903,7 +917,7 @@ int update_watchers_status(str pres_uri, pres_ev_t *ev, str *rules_doc) subs.db_flag = hash_code; /* must do a copy as sphere_check requires database queries */ - if(sphere_enable) { + if(pres_sphere_enable) { n = result->n; ws_list = (ws_t *)pkg_malloc(n * sizeof(ws_t)); if(ws_list == NULL) { @@ -1248,7 +1262,7 @@ static int update_pw_dialogs_dbonlymode(subs_t *subs, subs_t **subs_array) s.expires = row_vals[r_expires_col].val.int_val; - if(s.expires > (int)time(NULL) + expires_offset) + if(s.expires > (int)time(NULL) + pres_expires_offset) s.expires -= (int)time(NULL); else s.expires = 0; @@ -1335,8 +1349,9 @@ static int update_pw_dialogs( LM_DBG("start\n"); - if(subs_dbmode == DB_ONLY) + if(pres_subs_dbmode == DB_ONLY) { return (update_pw_dialogs_dbonlymode(subs, subs_array)); + } lock_get(&subs_htable[hash_code].lock); diff --git a/src/modules/presence/presence.h b/src/modules/presence/presence.h index 55e94c6f508..26f39a45a50 100644 --- a/src/modules/presence/presence.h +++ b/src/modules/presence/presence.h @@ -67,21 +67,21 @@ extern str presentity_table; extern str active_watchers_table; extern str watchers_table; -extern int counter; -extern int pid; -extern int startup_time; -extern char *to_tag_pref; -extern int expires_offset; +extern int pres_counter; +extern int pres_pid; +extern int pres_startup_time; +extern char *pres_totag_pref; +extern int pres_expires_offset; extern int pres_cseq_offset; -extern str server_address; -extern uint32_t min_expires; -extern int min_expires_action; -extern uint32_t max_expires; -extern int subs_dbmode; +extern str pres_server_address; +extern uint32_t pres_min_expires; +extern int pres_min_expires_action; +extern uint32_t pres_max_expires; +extern int pres_subs_dbmode; extern int publ_cache_enabled; -extern int sphere_enable; -extern int timeout_rm_subs; -extern int send_fast_notify; +extern int pres_sphere_enable; +extern int pres_timeout_rm_subs; +extern int pres_send_fast_notify; extern int shtable_size; extern shtable_t subs_htable; @@ -102,7 +102,7 @@ extern phtable_t *pres_htable; extern sruid_t pres_sruid; -extern db_locking_t db_table_lock; +extern db_locking_t pres_db_table_lock; int update_watchers_status(str pres_uri, pres_ev_t *ev, str *rules_doc); int pres_auth_status(struct sip_msg *msg, str watcher_uri, str presentity_uri); diff --git a/src/modules/presence/presentity.c b/src/modules/presence/presentity.c index a0667d096a0..03ec6ee1290 100644 --- a/src/modules/presence/presentity.c +++ b/src/modules/presence/presentity.c @@ -69,8 +69,8 @@ char *generate_ETag(int publ_count) ERR_MEM(PKG_MEM_STR); } memset(etag, 0, ETAG_LEN * sizeof(char)); - size = snprintf(etag, ETAG_LEN, "%c.%d.%d.%d.%d", prefix, startup_time, pid, - counter, publ_count); + size = snprintf(etag, ETAG_LEN, "%c.%d.%d.%d.%d", pres_prefix, + pres_startup_time, pres_pid, pres_counter, publ_count); if(size < 0) { LM_ERR("unsuccessful snprintf\n "); pkg_free(etag); @@ -105,7 +105,7 @@ int publ_send200ok(struct sip_msg *msg, int lexpire, str etag) hdr_append.s = buf; hdr_append.s[0] = '\0'; hdr_append.len = snprintf(hdr_append.s, buf_len, "Expires: %d\r\n", - ((lexpire == 0) ? 0 : (lexpire - expires_offset))); + ((lexpire == 0) ? 0 : (lexpire - pres_expires_offset))); if(hdr_append.len < 0) { LM_ERR("unsuccessful snprintf\n"); goto error; @@ -703,7 +703,7 @@ int update_presentity(struct sip_msg *msg, presentity_t *presentity, str *body, } if(pa_dbf.start_transaction) { - if(pa_dbf.start_transaction(pa_db, db_table_lock) < 0) { + if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -752,7 +752,7 @@ int update_presentity(struct sip_msg *msg, presentity_t *presentity, str *body, } if(pa_dbf.start_transaction) { - if(pa_dbf.start_transaction(pa_db, db_table_lock) < 0) { + if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -796,7 +796,7 @@ int update_presentity(struct sip_msg *msg, presentity_t *presentity, str *body, } if(pa_dbf.start_transaction) { - if(pa_dbf.start_transaction(pa_db, db_table_lock) < 0) { + if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -1100,7 +1100,7 @@ int update_presentity(struct sip_msg *msg, presentity_t *presentity, str *body, n_update_cols++; /* updated stored sphere */ - if(sphere_enable + if(pres_sphere_enable && presentity->event->evp->type == EVENT_PRESENCE) { if(publ_cache_enabled && update_phtable(presentity, pres_uri, *body) < 0) { @@ -1315,8 +1315,9 @@ int pres_htable_restore(void) result_cols[domain_col = n_result_cols++] = &str_domain_col; result_cols[event_col = n_result_cols++] = &str_event_col; result_cols[expires_col = n_result_cols++] = &str_expires_col; - if(sphere_enable) + if(pres_sphere_enable) { result_cols[body_col = n_result_cols++] = &str_body_col; + } if(pa_dbf.use_table(pa_db, &presentity_table) < 0) { LM_ERR("unsuccessful use table sql operation\n"); @@ -1370,7 +1371,7 @@ int pres_htable_restore(void) } /* insert in hash_table*/ - if(sphere_enable && event == EVENT_PRESENCE) { + if(pres_sphere_enable && event == EVENT_PRESENCE) { body.s = (char *)row_vals[body_col].val.string_val; body.len = strlen(body.s); sphere = extract_sphere(body); @@ -1483,8 +1484,9 @@ char *get_sphere(str *pres_uri) static str query_str; - if(!sphere_enable) + if(!pres_sphere_enable) { return NULL; + } if(publ_cache_enabled) { /* search in hash table*/ @@ -1869,7 +1871,7 @@ int _api_update_presentity(str *event, str *realm, str *user, str *etag, pres = new_presentity(realm, user, expires, ev, etag, sender); - if(sphere_enable) { + if(pres_sphere_enable) { sphere = extract_sphere(*body); } if(pres) { diff --git a/src/modules/presence/presentity.h b/src/modules/presence/presentity.h index 735ccf30a3b..6d2b8ee9d89 100644 --- a/src/modules/presence/presentity.h +++ b/src/modules/presence/presentity.h @@ -33,7 +33,7 @@ #include "../../core/parser/msg_parser.h" #include "event_list.h" -extern char prefix; +extern char pres_prefix; typedef struct presentity { diff --git a/src/modules/presence/publish.c b/src/modules/presence/publish.c index 98a6490c427..aebb299e240 100644 --- a/src/modules/presence/publish.c +++ b/src/modules/presence/publish.c @@ -156,7 +156,7 @@ void msg_presentity_clean(unsigned int ticks, void *param) } } else if(pres_notifier_processes > 0) { if(pa_dbf.start_transaction) { - if(pa_dbf.start_transaction(pa_db, db_table_lock) < 0) { + if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -274,7 +274,7 @@ int ki_handle_publish_uri(struct sip_msg *msg, str *sender_uri) reply_code = 500; reply_str = pu_500_rpl; - counter++; + pres_counter++; if(parse_headers(msg, HDR_EOH_F, 0) == -1) { LM_ERR("parsing headers\n"); reply_code = 400; @@ -345,8 +345,9 @@ int ki_handle_publish_uri(struct sip_msg *msg, str *sender_uri) LM_DBG("'expires' not found; default=%d\n", event->default_expires); lexpire = event->default_expires; } - if(lexpire > max_expires) - lexpire = max_expires; + if(lexpire > pres_max_expires) { + lexpire = pres_max_expires; + } /* get pres_uri from Request-URI*/ if(parse_sip_msg_uri(msg) < 0) { @@ -384,7 +385,7 @@ int ki_handle_publish_uri(struct sip_msg *msg, str *sender_uri) } body.len = get_content_length(msg); - if(sphere_enable && event->evp->type == EVENT_PRESENCE + if(pres_sphere_enable && event->evp->type == EVENT_PRESENCE && get_content_type(msg) == SUBTYPE_PIDFXML) { sphere = extract_sphere(body); } @@ -536,8 +537,9 @@ int update_hard_presentity( LM_DBG("INSERT/REPLACE\n"); xmlDocPtr doc; - if(sphere_enable) + if(pres_sphere_enable) { sphere = extract_sphere(*pidf_doc); + } doc = xmlParseMemory(pidf_doc->s, pidf_doc->len); if(doc == NULL) { diff --git a/src/modules/presence/subscribe.c b/src/modules/presence/subscribe.c index 7d27a76d756..5a2f741eac0 100644 --- a/src/modules/presence/subscribe.c +++ b/src/modules/presence/subscribe.c @@ -478,7 +478,7 @@ void delete_subs( subs.callid = *callid; /* delete record from hash table also if not in dbonly mode */ - if(subs_dbmode != DB_ONLY) { + if(pres_subs_dbmode != DB_ONLY) { unsigned int hash_code = core_case_hash(pres_uri, ev_name, shtable_size); if(delete_shtable(subs_htable, hash_code, &subs) < 0) { @@ -490,7 +490,7 @@ void delete_subs( } } - if(subs_dbmode != NO_DB && delete_db_subs(to_tag, from_tag, callid) < 0) + if(pres_subs_dbmode != NO_DB && delete_db_subs(to_tag, from_tag, callid) < 0) LM_ERR("Failed to delete subscription from database\n"); } @@ -605,7 +605,7 @@ int update_subscription( return 1; } /* if subscriptions are stored in memory, update them */ - if(subs_dbmode != DB_ONLY) { + if(pres_subs_dbmode != DB_ONLY) { hash_code = core_case_hash( &subs->pres_uri, &subs->event->name, shtable_size); if(update_shtable(subs_htable, hash_code, subs, REMOTE_TYPE) < 0) { @@ -614,7 +614,7 @@ int update_subscription( } } /* for modes that update the subscription synchronously in database, write in db */ - if(subs_dbmode == DB_ONLY || subs_dbmode == WRITE_THROUGH) { + if(pres_subs_dbmode == DB_ONLY || pres_subs_dbmode == WRITE_THROUGH) { /* update in database table */ if(update_subs_db(subs, REMOTE_TYPE | LOCAL_TYPE) < 0) { LM_ERR("updating subscription in database table\n"); @@ -624,9 +624,9 @@ int update_subscription( } else { LM_DBG("subscription not in dialog\n"); if(subs->expires != 0) { - if(subs_dbmode != DB_ONLY) { + if(pres_subs_dbmode != DB_ONLY) { LM_DBG("inserting in shtable\n"); - subs->db_flag = (subs_dbmode == WRITE_THROUGH) ? WTHROUGHDB_FLAG + subs->db_flag = (pres_subs_dbmode == WRITE_THROUGH) ? WTHROUGHDB_FLAG : INSERTDB_FLAG; hash_code = core_case_hash( &subs->pres_uri, &subs->event->name, shtable_size); @@ -637,7 +637,7 @@ int update_subscription( } } - if(subs_dbmode == DB_ONLY || subs_dbmode == WRITE_THROUGH) { + if(pres_subs_dbmode == DB_ONLY || pres_subs_dbmode == WRITE_THROUGH) { subs->version = 1; if(insert_subs_db(subs, REMOTE_TYPE) < 0) { LM_ERR("failed to insert new record in database\n"); @@ -676,7 +676,7 @@ int update_subscription( } } } else { - if(send_fast_notify && (notify(subs, NULL, NULL, 0, 0) < 0)) { + if(pres_send_fast_notify && (notify(subs, NULL, NULL, 0, 0) < 0)) { LM_ERR("Could not send notify\n"); goto error; } @@ -689,7 +689,7 @@ int update_subscription( } *sent_reply = 1; - if(send_fast_notify && (notify(subs, NULL, NULL, 0, 0) < 0)) { + if(pres_send_fast_notify && (notify(subs, NULL, NULL, 0, 0) < 0)) { LM_ERR("sending notify request\n"); goto error; } @@ -1044,8 +1044,7 @@ int handle_subscribe(struct sip_msg *msg, str watcher_user, str watcher_domain) } } - /* ??? rename to avoid collisions with other symbols */ - counter++; + pres_counter++; memset(&subs, 0, sizeof(subs_t)); @@ -1087,20 +1086,20 @@ int handle_subscribe(struct sip_msg *msg, str watcher_user, str watcher_domain) ev_param = ev_param->next; } - if(extract_sdialog_info_ex(&subs, msg, min_expires, max_expires, - &to_tag_gen, server_address, watcher_user, watcher_domain, + if(extract_sdialog_info_ex(&subs, msg, pres_min_expires, pres_max_expires, + &to_tag_gen, pres_server_address, watcher_user, watcher_domain, &reply_code, &reply_str) < 0) { goto error; } - if(pres_notifier_processes > 0 && !send_fast_notify + if(pres_notifier_processes > 0 && !pres_send_fast_notify && pa_dbf.start_transaction) { if(pa_dbf.use_table(pa_db, &active_watchers_table) < 0) { LM_ERR("unsuccessful use_table sql operation\n"); goto error; } - if(pa_dbf.start_transaction(pa_db, db_table_lock) < 0) { + if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -1203,7 +1202,7 @@ int handle_subscribe(struct sip_msg *msg, str watcher_user, str watcher_domain) LM_DBG("subscription status= %s - %s\n", get_status_str(subs.status), (found == 0) ? "inserted" : "found in watcher table"); - if(pres_notifier_processes > 0 && !send_fast_notify) { + if(pres_notifier_processes > 0 && !pres_send_fast_notify) { if(update_subscription_notifier(msg, &subs, to_tag_gen, &sent_reply) < 0) { LM_ERR("in update_subscription_notifier\n"); @@ -1214,7 +1213,7 @@ int handle_subscribe(struct sip_msg *msg, str watcher_user, str watcher_domain) goto error; } - if(pres_notifier_processes > 0 && !send_fast_notify + if(pres_notifier_processes > 0 && !pres_send_fast_notify && pa_dbf.end_transaction) { if(pa_dbf.end_transaction(pa_db) < 0) { LM_ERR("in end_transaction\n"); @@ -1232,7 +1231,7 @@ int handle_subscribe(struct sip_msg *msg, str watcher_user, str watcher_domain) if(subs.pres_uri.s) pkg_free(subs.pres_uri.s); - if((!server_address.s) || (server_address.len == 0)) { + if((!pres_server_address.s) || (pres_server_address.len == 0)) { pkg_free(subs.local_contact.s); } if(subs.record_route.s) @@ -1270,7 +1269,7 @@ int handle_subscribe(struct sip_msg *msg, str watcher_user, str watcher_domain) if(reason.s) pkg_free(reason.s); - if(((!server_address.s) || (server_address.len == 0)) + if(((!pres_server_address.s) || (pres_server_address.len == 0)) && subs.local_contact.s) { pkg_free(subs.local_contact.s); } @@ -1315,7 +1314,7 @@ int extract_sdialog_info_ex(subs_t *subs, struct sip_msg *msg, uint32_t miexp, lexpire = mexp; if(lexpire && miexp && lexpire < miexp) { - if(min_expires_action == 1) { + if(pres_min_expires_action == 1) { LM_DBG("subscription expiration invalid , requested=%u, minimum=%u," " returning error \"423 Interval Too brief\"\n", lexpire, miexp); @@ -1512,7 +1511,7 @@ int extract_sdialog_info(subs_t *subs, struct sip_msg *msg, int mexp, { int reply_code = 500; str reply_str = pu_500_rpl; - return extract_sdialog_info_ex(subs, msg, min_expires, mexp, to_tag_gen, + return extract_sdialog_info_ex(subs, msg, pres_min_expires, mexp, to_tag_gen, scontact, watcher_user, watcher_domain, &reply_code, &reply_str); } @@ -1524,8 +1523,9 @@ int get_stored_info( int i; unsigned int hash_code; - if(subs_dbmode == DB_ONLY) + if(pres_subs_dbmode == DB_ONLY) { return get_database_info(msg, subs, reply_code, reply_str); + } /* first try to_user== pres_user and to_domain== pres_domain */ if(subs->pres_uri.s == NULL) { @@ -1836,7 +1836,7 @@ void update_db_subs_timer_notifier(void) query_cols[n_query_cols] = &str_expires_col; query_vals[n_query_cols].type = DB1_INT; query_vals[n_query_cols].nul = 0; - query_vals[n_query_cols].val.int_val = (int)time(NULL) - expires_offset; + query_vals[n_query_cols].val.int_val = (int)time(NULL) - pres_expires_offset; query_ops[n_query_cols] = OP_LT; n_query_cols++; @@ -1852,7 +1852,7 @@ void update_db_subs_timer_notifier(void) result_cols[r_from_tag_col = n_result_cols++] = &str_from_tag_col; if(pa_dbf.start_transaction) { - if(pa_dbf.start_transaction(pa_db, db_table_lock) < 0) { + if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { LM_ERR("in start_transaction\n"); goto error; } @@ -1936,7 +1936,7 @@ void update_db_subs_timer_dbonly(void) qcols[0] = &str_expires_col; qvals[0].type = DB1_INT; qvals[0].nul = 0; - qvals[0].val.int_val = (int)time(NULL) - expires_offset; + qvals[0].val.int_val = (int)time(NULL) - pres_expires_offset; qops[0] = OP_LT; /* query the expired subscriptions */ @@ -2083,7 +2083,7 @@ void update_db_subs_timer_dbnone(int no_lock) while(s) { printf_subs(s); - if(s->expires < now - expires_offset) { + if(s->expires < now - pres_expires_offset) { LM_DBG("Found expired record\n"); if(!no_lock) { if(handle_expired_subs(s) < 0) { @@ -2308,7 +2308,7 @@ void update_db_subs_timer(db1_con_t *db, db_func_t *dbf, shtable_t hash_table, while(s) { printf_subs(s); - if(s->expires < now - expires_offset) { + if(s->expires < now - pres_expires_offset) { LM_DBG("Found expired record\n"); if(!no_lock) { if(handle_expired_func(s) < 0) @@ -2408,7 +2408,7 @@ void update_db_subs_timer(db1_con_t *db, db_func_t *dbf, shtable_t hash_table, lock_release(&hash_table[i].lock); } - update_vals[0].val.int_val = (int)time(NULL) - expires_offset; + update_vals[0].val.int_val = (int)time(NULL) - pres_expires_offset; update_ops[0] = OP_LT; if(dbf->delete(db, update_cols, update_ops, update_vals, 1) < 0) { LM_ERR("deleting expired information from database\n"); @@ -2430,7 +2430,7 @@ void timer_db_update(unsigned int ticks, void *param) no_lock = 1; - switch(subs_dbmode) { + switch(pres_subs_dbmode) { case DB_ONLY: if(pres_notifier_processes > 0) update_db_subs_timer_notifier(); @@ -2597,8 +2597,8 @@ int restore_db_subs(void) free_event_params(parsed_event.params.list, PKG_MEM_TYPE); goto error; } - event->next = EvList->events; - EvList->events = event; + event->next = pres_evlist->events; + pres_evlist->events = event; } free_event_params(parsed_event.params.list, PKG_MEM_TYPE); @@ -2634,7 +2634,7 @@ int restore_db_subs(void) s.sockinfo_str.s = (char *)row_vals[sockinfo_col].val.string_val; s.sockinfo_str.len = strlen(s.sockinfo_str.s); - s.db_flag = (subs_dbmode == WRITE_THROUGH) ? WTHROUGHDB_FLAG + s.db_flag = (pres_subs_dbmode == WRITE_THROUGH) ? WTHROUGHDB_FLAG : NO_UPDATEDB_FLAG; hash_code = core_case_hash(&s.pres_uri, &s.event->name, shtable_size); @@ -2650,7 +2650,7 @@ int restore_db_subs(void) pa_dbf.free_result(pa_db, result); /* delete all records only if in memory mode */ - if(subs_dbmode == NO_DB) { + if(pres_subs_dbmode == NO_DB) { if(pa_dbf.delete(pa_db, 0, 0, 0, 0) < 0) { LM_ERR("deleting all records from database table\n"); return -1; @@ -2894,7 +2894,7 @@ int get_subscribers_count_from_db(struct sip_msg *msg, str pres_uri, str event) int get_subscribers_count(struct sip_msg *msg, str pres_uri, str event) { - if(subs_dbmode == DB_ONLY) { + if(pres_subs_dbmode == DB_ONLY) { return get_subscribers_count_from_db(msg, pres_uri, event); } else { return get_subscribers_count_from_mem(msg, pres_uri, event); diff --git a/src/modules/presence/utils_func.c b/src/modules/presence/utils_func.c index 0132101485f..d2d8908737f 100644 --- a/src/modules/presence/utils_func.c +++ b/src/modules/presence/utils_func.c @@ -84,7 +84,7 @@ int send_error_reply(struct sip_msg *msg, int reply_code, str reply_str) str hdr_append; char buffer[256]; int i; - pres_ev_t *ev = EvList->events; + pres_ev_t *ev = pres_evlist->events; if(reply_code == BAD_EVENT_CODE) { hdr_append.s = buffer; @@ -95,7 +95,7 @@ int send_error_reply(struct sip_msg *msg, int reply_code, str reply_str) return -1; } - for(i = 0; i < EvList->ev_count; i++) { + for(i = 0; i < pres_evlist->ev_count; i++) { if(i > 0) { memcpy(hdr_append.s + hdr_append.len, ", ", 2); hdr_append.len += 2; @@ -116,7 +116,7 @@ int send_error_reply(struct sip_msg *msg, int reply_code, str reply_str) hdr_append.s = buffer; hdr_append.s[0] = '\0'; - hdr_append.len = sprintf(hdr_append.s, "Min-Expires: %d", min_expires); + hdr_append.len = sprintf(hdr_append.s, "Min-Expires: %d", pres_min_expires); if(hdr_append.len < 0) { LM_ERR("unsuccessful sprintf\n"); return -1;