From b14340a5daf2318a25c5ebbda85bcc47b2e39697 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Jun 2011 10:45:28 -0500 Subject: [PATCH] dig into the database to figure out what profile to send mwi on when they are not willing to alais the domain to the profile =/ --- src/mod/endpoints/mod_sofia/sofia_presence.c | 27 +++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 1d65a15081..a7490f6a8b 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -396,9 +396,30 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event) if (!profile) { if (!host || !(profile = sofia_glue_find_profile(host))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile %s\n", switch_str_nil(host)); - switch_safe_free(dup_account); - return; + char *sql; + switch_hash_index_t *hi; + void *val; + const void *vvar; + char buf[512] = ""; + + sql = switch_mprintf("select profile_name from sip_registrations where sip_host='%s' or mwi_host='%s'", host, host); + + switch_mutex_lock(mod_sofia_globals.hash_mutex); + for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, &vvar, NULL, &val); + profile = (sofia_profile_t *) val; + sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf)); + if (!zstr(buf)) { + break; + } + } + switch_mutex_unlock(mod_sofia_globals.hash_mutex); + + if (!(profile = sofia_glue_find_profile(buf))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile %s\n", switch_str_nil(host)); + switch_safe_free(dup_account); + return; + } } }