Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

presence: add sip_uri_match module parameter #116

Merged
merged 1 commit into from
Mar 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions modules/presence/doc/presence_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,35 @@ modparam("presence", "retrieve_order", 1)
</example>
</section>

<section id="presence.p.sip_uri_match">
<title><varname>sip_uri_match</varname> (int)</title>
<para>
The mode used when comparing uris.
</para>
<para>
<itemizedlist>
<title>Possible Values</title>
<listitem>
<para> 0 : case sensitive</para>
</listitem>
<listitem>
<para> 1 : case insensitive</para>
</listitem>
</itemizedlist>
</para>
<para>
<emphasis>Default value is <quote>0</quote>.</emphasis>
</para>
<example>
<title>Set <varname>sip_uri_match</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("presence", "sip_uri_match", 1)
...
</programlisting>
</example>
</section>

</section>

<section>
Expand Down
10 changes: 5 additions & 5 deletions modules/presence/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
22 changes: 11 additions & 11 deletions modules/presence/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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++;

Expand Down Expand Up @@ -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);

Expand Down
49 changes: 44 additions & 5 deletions modules/presence/presence.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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}
};

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions modules/presence/presence.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions modules/presence/presentity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions modules/presence/subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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");
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down