diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 777707e5f5..c2e425d284 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -484,23 +484,33 @@ int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int reboot) { char sql[1024]; + char sqlextra[1024] = ""; char *psql = sql; - char *user = strdup(call_id); - char *host = NULL; + char *dup = strdup(call_id); + char *host = NULL, *user = NULL; - switch_assert(user); + switch_assert(dup); - if ((host = strchr(user, '@'))) { + if ((host = strchr(dup, '@'))) { *host++ = '\0'; + user = dup; + } else { + host = dup; } - + if (!host) { host = "none"; } + if (switch_strlen_zero(user)) { + switch_snprintf(sqlextra, sizeof(sqlextra), " or (sip_host='%s')", host); + } else { + switch_snprintf(sqlextra, sizeof(sqlextra), " or (sip_user='%s' and sip_host='%s')", user, host); + } + switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name" - ",%d from sip_registrations where call_id='%s' or (sip_user='%s' and sip_host='%s')", - reboot, call_id, user, host); + ",%d from sip_registrations where call_id='%s' %s", + reboot, call_id, sqlextra); switch_mutex_lock(profile->ireg_mutex); sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, profile); @@ -510,7 +520,7 @@ void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int call_id, user, host); sofia_glue_execute_sql(profile, &psql, SWITCH_FALSE); - switch_safe_free(user); + switch_safe_free(dup); }