diff --git a/modules/presence/doc/presence_admin.xml b/modules/presence/doc/presence_admin.xml index f3f9ea49403..b4ca5f9ae4a 100644 --- a/modules/presence/doc/presence_admin.xml +++ b/modules/presence/doc/presence_admin.xml @@ -756,6 +756,35 @@ modparam("presence", "retrieve_order", 1) +
+ <varname>sip_uri_match</varname> (int) + + The mode used when comparing uris. + + + + Possible Values + + 0 : case sensitive + + + 1 : case insensitive + + + + + Default value is 0. + + + Set <varname>sip_uri_match</varname> parameter + + ... + modparam("presence", "sip_uri_match", 1) + ... + + +
+
diff --git a/modules/presence/hash.c b/modules/presence/hash.c index 5e46fd4af28..49e5a919062 100644 --- a/modules/presence/hash.c +++ b/modules/presence/hash.c @@ -375,7 +375,7 @@ int update_shtable(shtable_t htable,unsigned int hash_code, subs->version = ++s->version; } - if(strncmp(s->contact.s, subs->contact.s, subs->contact.len)) + if(presence_sip_uri_match(&s->contact, &subs->contact)) { shm_free(s->contact.s); s->contact.s= (char*)shm_malloc(subs->contact.len* sizeof(char)); @@ -483,7 +483,7 @@ pres_entry_t* search_phtable(str* pres_uri,int event, unsigned int hash_code) while(p) { if(p->event== event && p->pres_uri.len== pres_uri->len && - strncmp(p->pres_uri.s, pres_uri->s, pres_uri->len)== 0 ) + presence_sip_uri_match(&p->pres_uri, pres_uri)== 0 ) return p; p= p->next; } @@ -496,7 +496,7 @@ int insert_phtable(str* pres_uri, int event, char* sphere) pres_entry_t* p= NULL; int size; - hash_code= core_hash(pres_uri, NULL, phtable_size); + hash_code= core_case_hash(pres_uri, NULL, phtable_size); lock_get(&pres_htable[hash_code].lock); @@ -554,7 +554,7 @@ int delete_phtable(str* pres_uri, int event) unsigned int hash_code; pres_entry_t* p= NULL, *prev_p= NULL; - hash_code= core_hash(pres_uri, NULL, phtable_size); + hash_code= core_case_hash(pres_uri, NULL, phtable_size); lock_get(&pres_htable[hash_code].lock); @@ -611,7 +611,7 @@ int update_phtable(presentity_t* presentity, str pres_uri, str body) } /* search for record in hash table */ - hash_code= core_hash(&pres_uri, NULL, phtable_size); + hash_code= core_case_hash(&pres_uri, NULL, phtable_size); lock_get(&pres_htable[hash_code].lock); diff --git a/modules/presence/notify.c b/modules/presence/notify.c index 06f17dff84b..641cb40abbf 100644 --- a/modules/presence/notify.c +++ b/modules/presence/notify.c @@ -371,7 +371,7 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs) goto error; } } else { - hash_code= core_hash(&subs->pres_uri, &subs->event->wipeer->name, + hash_code= core_case_hash(&subs->pres_uri, &subs->event->wipeer->name, shtable_size); lock_get(&subs_htable[hash_code].lock); s= subs_htable[hash_code].entries; @@ -387,7 +387,7 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs) if(s->event== subs->event->wipeer && s->pres_uri.len== subs->pres_uri.len && - strncmp(s->pres_uri.s, subs->pres_uri.s,subs->pres_uri.len)== 0) + presence_sip_uri_match(&s->pres_uri, &subs->pres_uri)== 0) { if(add_watcher_list(s, watchers)< 0) { @@ -609,7 +609,7 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag, if( publ_cache_enabled ) { /* search in hash table if any record exists */ - hash_code= core_hash(&pres_uri, NULL, phtable_size); + hash_code= core_case_hash(&pres_uri, NULL, phtable_size); if(search_phtable(&pres_uri, event->evp->type, hash_code)== NULL) { LM_DBG("No record exists in hash_table\n"); @@ -701,7 +701,7 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag, sender.len= strlen(sender.s); if(sender.len== contact->len && - strncmp(sender.s, contact->s, sender.len)== 0) + presence_sip_uri_match(&sender, contact)== 0) { notify_body= build_empty_bla_body(pres_uri); pa_dbf.free_result(pa_db, result); @@ -1188,7 +1188,7 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender) goto error; } }else { - hash_code= core_hash(pres_uri, &event->name, shtable_size); + hash_code= core_case_hash(pres_uri, &event->name, shtable_size); lock_get(&subs_htable[hash_code].lock); @@ -1209,9 +1209,9 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender) if((!(s->status== ACTIVE_STATUS && s->reason.len== 0 && s->event== event && s->pres_uri.len== pres_uri->len && - strncmp(s->pres_uri.s, pres_uri->s, pres_uri->len)== 0)) || + presence_sip_uri_match(&s->pres_uri, pres_uri)== 0)) || (sender && sender->len== s->contact.len && - strncmp(sender->s, s->contact.s, sender->len)== 0)) + presence_sip_uri_match(sender, &s->contact)== 0)) continue; s_new= mem_copy_subs(s, PKG_MEM_TYPE); @@ -1650,7 +1650,7 @@ int notify(subs_t* subs, subs_t * watcher_subs,str* n_body,int force_null_body) if(subs->expires!= 0 && subs->status != TERMINATED_STATUS) { unsigned int hash_code; - hash_code= core_hash(&subs->pres_uri, &subs->event->name, shtable_size); + hash_code= core_case_hash(&subs->pres_uri, &subs->event->name, shtable_size); /* if subscriptions are held also in memory, update the subscription hashtable */ if(subs_dbmode != DB_ONLY) @@ -1885,7 +1885,7 @@ int watcher_found_in_list(watcher_t * watchers, str wuri) while(w) { - if(w->uri.len == wuri.len && strncmp(w->uri.s, wuri.s, wuri.len)== 0) + if(w->uri.len == wuri.len && presence_sip_uri_match(&w->uri, &wuri)== 0) return 1; w= w->next; } @@ -2262,7 +2262,7 @@ int set_wipeer_subs_updated(str *pres_uri, pres_ev_t *event, int full) update_vals[n_update_cols].type = DB1_INT; update_vals[n_update_cols].nul = 0; update_vals[n_update_cols].val.int_val = - core_hash(&callid, &from_tag, 0) % (pres_waitn_time * + core_case_hash(&callid, &from_tag, 0) % (pres_waitn_time * pres_notifier_poll_rate * pres_notifier_processes); n_update_cols++; @@ -2323,7 +2323,7 @@ int set_updated(subs_t *sub) update_vals[0].type = DB1_INT; update_vals[0].nul = 0; update_vals[0].val.int_val = - core_hash(&sub->callid, &sub->from_tag, 0) % + core_case_hash(&sub->callid, &sub->from_tag, 0) % (pres_waitn_time * pres_notifier_poll_rate * pres_notifier_processes); diff --git a/modules/presence/presence.c b/modules/presence/presence.c index 817e25f6739..18c00df9f2f 100644 --- a/modules/presence/presence.c +++ b/modules/presence/presence.c @@ -97,6 +97,12 @@ str server_address= {0, 0}; evlist_t* EvList= NULL; int pres_subs_remove_match = 0; +/* sip uri match */ +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"; @@ -212,6 +218,7 @@ static param_export_t params[]={ { "subs_remove_match", PARAM_INT, &pres_subs_remove_match}, { "xavp_cfg", PARAM_STR, &pres_xavp_cfg}, { "retrieve_order", PARAM_INT, &pres_retrieve_order}, + { "sip_uri_match", PARAM_INT, &pres_uri_match}, {0,0,0} }; @@ -242,6 +249,12 @@ struct module_exports exports= { */ static int mod_init(void) { + if(pres_uri_match == 1) { + presence_sip_uri_match = sip_uri_case_insensitive_match; + } else { + presence_sip_uri_match = sip_uri_case_sensitive_match; + } + if(register_mi_mod(exports.name, mi_cmds)!=0) { LM_ERR("failed to register MI commands\n"); @@ -1012,7 +1025,7 @@ int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc) } LM_DBG("found %d record-uri in watchers_table\n", result->n); - hash_code= core_hash(&pres_uri, &ev->name, shtable_size); + hash_code= core_case_hash(&pres_uri, &ev->name, shtable_size); subs.db_flag= hash_code; /*must do a copy as sphere_check requires database queries */ @@ -1433,7 +1446,7 @@ static int update_pw_dialogs_dbonlymode(subs_t* subs, subs_t** subs_array) * pres_notifier_processes)); } else { db_vals[n_update_cols].val.int_val = - core_hash(&subs->callid, &subs->from_tag, 0) % + core_case_hash(&subs->callid, &subs->from_tag, 0) % (pres_waitn_time * pres_notifier_poll_rate * pres_notifier_processes); } @@ -1472,9 +1485,9 @@ static int update_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs if(s->event== subs->event && s->pres_uri.len== subs->pres_uri.len && s->watcher_user.len== subs->watcher_user.len && s->watcher_domain.len==subs->watcher_domain.len && - strncmp(s->pres_uri.s, subs->pres_uri.s, subs->pres_uri.len)== 0 && - strncmp(s->watcher_user.s, subs->watcher_user.s, s->watcher_user.len)== 0 && - strncmp(s->watcher_domain.s,subs->watcher_domain.s,s->watcher_domain.len)==0) + presence_sip_uri_match(&s->pres_uri, &subs->pres_uri)== 0 && + presence_sip_uri_match(&s->watcher_user, &subs->watcher_user)== 0 && + presence_sip_uri_match(&s->watcher_domain, &subs->watcher_domain)==0) { i++; s->status= subs->status; @@ -1840,3 +1853,29 @@ static int presence_init_rpc(void) } return 0; } + +static int sip_uri_case_sensitive_match(str* s1, str* s2) +{ + if(!s1) { + LM_ERR("null pointer (s1) in sip_uri_match\n"); + return -1; + } + if(!s2) { + LM_ERR("null pointer (s2) in sip_uri_match\n"); + return -1; + } + return strncmp(s1->s, s2->s, s2->len); +} + +static int sip_uri_case_insensitive_match(str* s1, str* s2) +{ + if(!s1) { + LM_ERR("null pointer (s1) in sip_uri_match\n"); + return -1; + } + if(!s2) { + LM_ERR("null pointer (s2) in sip_uri_match\n"); + return -1; + } + return strncasecmp(s1->s, s2->s, s2->len); +} diff --git a/modules/presence/presence.h b/modules/presence/presence.h index 93c28792d42..6f40f714a73 100644 --- a/modules/presence/presence.h +++ b/modules/presence/presence.h @@ -99,4 +99,7 @@ extern db_locking_t 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); +typedef int (*sip_uri_match_f) (str* s1, str* s2); +extern sip_uri_match_f presence_sip_uri_match; + #endif /* PA_MOD_H */ diff --git a/modules/presence/presentity.c b/modules/presence/presentity.c index cdefabbd1f3..c358b81846c 100644 --- a/modules/presence/presentity.c +++ b/modules/presence/presentity.c @@ -550,7 +550,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body, if(presentity->sender) { if(!(presentity->sender->len == sender.len && - strncmp(presentity->sender->s, sender.s, sender.len)== 0)) + presence_sip_uri_match(presentity->sender, &sender)== 0)) bla_update_publish= 0; } after_dialog_check: @@ -1071,7 +1071,7 @@ char* get_sphere(str* pres_uri) if ( publ_cache_enabled ) { /* search in hash table*/ - hash_code= core_hash(pres_uri, NULL, phtable_size); + hash_code= core_case_hash(pres_uri, NULL, phtable_size); lock_get(&pres_htable[hash_code].lock); diff --git a/modules/presence/subscribe.c b/modules/presence/subscribe.c index 0363e3a915e..73bf4fe47ff 100644 --- a/modules/presence/subscribe.c +++ b/modules/presence/subscribe.c @@ -463,7 +463,7 @@ void delete_subs(str* pres_uri, str* ev_name, str* to_tag, /* delete record from hash table also if not in dbonly mode */ if(subs_dbmode != DB_ONLY) { - unsigned int hash_code= core_hash(pres_uri, ev_name, shtable_size); + unsigned int hash_code= core_case_hash(pres_uri, ev_name, shtable_size); if(delete_shtable(subs_htable, hash_code, &subs) < 0) { LM_ERR("Failed to delete subscription from memory" " [slot: %u ev: %.*s pu: %.*s ci: %.*s ft: %.*s tt: %.*s]\n", @@ -486,7 +486,7 @@ int update_subscription_notifier(struct sip_msg* msg, subs_t* subs, *sent_reply= 0; /* Set the notifier/update fields for the subscription */ - subs->updated = core_hash(&subs->callid, &subs->from_tag, 0) % + subs->updated = core_case_hash(&subs->callid, &subs->from_tag, 0) % (pres_waitn_time * pres_notifier_poll_rate * pres_notifier_processes); if (subs->event->type & WINFO_TYPE) @@ -606,7 +606,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int to_tag_gen, /* if subscriptions are stored in memory, update them */ if(subs_dbmode != DB_ONLY) { - hash_code= core_hash(&subs->pres_uri, &subs->event->name, shtable_size); + hash_code= core_case_hash(&subs->pres_uri, &subs->event->name, shtable_size); if(update_shtable(subs_htable, hash_code, subs, REMOTE_TYPE)< 0) { LM_ERR("failed to update subscription in memory\n"); @@ -633,7 +633,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int to_tag_gen, { LM_DBG("inserting in shtable\n"); subs->db_flag = (subs_dbmode==WRITE_THROUGH)?WTHROUGHDB_FLAG:INSERTDB_FLAG; - hash_code= core_hash(&subs->pres_uri, &subs->event->name, shtable_size); + hash_code= core_case_hash(&subs->pres_uri, &subs->event->name, shtable_size); subs->version = 0; if(insert_shtable(subs_htable,hash_code,subs)< 0) { @@ -1367,7 +1367,7 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* reply_code, else pres_uri = subs->pres_uri; - hash_code= core_hash(&pres_uri, &subs->event->name, shtable_size); + hash_code= core_case_hash(&pres_uri, &subs->event->name, shtable_size); lock_get(&subs_htable[hash_code].lock); s= search_shtable(subs_htable, subs->callid, subs->to_tag, subs->from_tag, hash_code); @@ -2476,7 +2476,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:NO_UPDATEDB_FLAG; - hash_code= core_hash(&s.pres_uri, &s.event->name, shtable_size); + hash_code= core_case_hash(&s.pres_uri, &s.event->name, shtable_size); if(insert_shtable(subs_htable, hash_code, &s)< 0) { LM_ERR("adding new record in hash table\n");