"IP: \t%s\n"
"Port: \t%s\n"
"Auth-User: \t%s\n"
- "Auth-Realm: \t%s\n\n",
+ "Auth-Realm: \t%s\n"
+ "MWI-Account:\t%s@%s\n\n",
switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]), switch_str_nil(argv[3]),
switch_str_nil(argv[7]), switch_str_nil(argv[4]), switch_str_nil(argv[5]), exp_buf, switch_str_nil(argv[11]),
- switch_str_nil(argv[12]), switch_str_nil(argv[13]), switch_str_nil(argv[14]), switch_str_nil(argv[15]));
+ switch_str_nil(argv[12]), switch_str_nil(argv[13]), switch_str_nil(argv[14]), switch_str_nil(argv[15]),
+ switch_str_nil(argv[16]), switch_str_nil(argv[17]));
return 0;
}
" <network-port>%s</network-port>\n"
" <sip-auth-user>%s</sip-auth-user>\n"
" <sip-auth-realm>%s</sip-auth-realm>\n"
+ " <mwi-account>%s@%s</mwi-account>\n"
" </registration>\n",
switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]),
switch_amp_encode(switch_str_nil(argv[3]),xmlbuf,buflen),
switch_str_nil(argv[7]), switch_str_nil(argv[4]), switch_str_nil(argv[5]), exp_buf, switch_str_nil(argv[11]),
- switch_str_nil(argv[12]), switch_str_nil(argv[13]), switch_str_nil(argv[14]), switch_str_nil(argv[15]));
+ switch_str_nil(argv[12]), switch_str_nil(argv[13]), switch_str_nil(argv[14]), switch_str_nil(argv[15]),
+ switch_str_nil(argv[16]), switch_str_nil(argv[17]));
return 0;
}
if (!sql && argv[2] && !strcasecmp(argv[2], "pres") && argv[3]) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
" from sip_registrations where profile_name='%q' and presence_hosts like '%%%q%%'",
profile->name, argv[3]);
}
if (!sql && argv[2] && !strcasecmp(argv[2], "reg") && argv[3]) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
" from sip_registrations where profile_name='%q' and contact like '%%%q%%'",
profile->name, argv[3]);
}
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
" from sip_registrations where profile_name='%q' and %s",
profile->name, sqlextra);
switch_safe_free(dup);
if (!sql) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
" from sip_registrations where profile_name='%q'",
profile->name);
}
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
" from sip_registrations where profile_name='%q' and presence_hosts like '%%%q%%'",
profile->name, argv[3]);
}
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
" from sip_registrations where profile_name='%q' and contact like '%%%q%%'",
profile->name, argv[3]);
}
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
" from sip_registrations where profile_name='%q' and %s",
profile->name, sqlextra);
switch_safe_free(dup);
if (!sql) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
" from sip_registrations where profile_name='%q'",
profile->name);
}
"from sip_registrations where call_id='%q'", ct, es, switch_str_nil(body), call_id
);
} else {
- sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
- "from sip_registrations where sip_user='%s' and sip_host='%q'",
- ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
- );
+ if (!strcasecmp(es, "message-summary")) {
+ sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
+ "from sip_registrations where mwi_user='%s' and mwi_host='%q'",
+ ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
+ );
+ } else {
+ sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
+ "from sip_registrations where sip_user='%s' and sip_host='%q'",
+ ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
+ );
+
+ }
}
sofia_profile_t *profile = NULL;
+ char *mwi_account = NULL;
+ char *dup_mwi_account = NULL;
+ char *mwi_user = NULL;
+ char *mwi_host = NULL;
+
+ if ((mwi_account = switch_event_get_header(event, "orig-mwi-account"))) {
+ dup_mwi_account = strdup(mwi_account);
+ switch_assert(dup_mwi_account != NULL);
+ sofia_glue_get_user_host(dup_mwi_account, &mwi_user, &mwi_host);
+ }
+
+ if (!mwi_user) {
+ mwi_user = (char *) from_user;
+ }
+ if (!mwi_host) {
+ mwi_host = (char *) from_host;
+ }
+
char guess_ip4[256];
if (exp_str) {
if (!profile_name || !(profile = sofia_glue_find_profile(profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
- return;
+ goto end;
}
if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
sql = switch_mprintf("insert into sip_registrations "
"(call_id, sip_user, sip_host, presence_hosts, contact, status, rpid, expires,"
- "user_agent, server_user, server_host, profile_name, hostname, network_ip, network_port, sip_username, sip_realm) "
- "values ('%q','%q','%q','%q','%q','Registered','%q',%ld, '%q','%q','%q','%q','%q','%q','%q','%q','%q')",
+ "user_agent, server_user, server_host, profile_name, hostname, network_ip, network_port, sip_username, sip_realm, mwi_user, mwi_host) "
+ "values ('%q','%q','%q','%q','%q','Registered','%q',%ld, '%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
call_id, from_user, from_host, presence_hosts, contact_str, rpid, expires, user_agent, to_user, guess_ip4,
- profile_name, mod_sofia_globals.hostname, network_ip, network_port, username, realm);
+ profile_name, mod_sofia_globals.hostname, network_ip, network_port, username, realm, mwi_user, mwi_host);
if (sql) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
if (profile) {
sofia_glue_release_profile(profile);
}
-
+end:
switch_safe_free(fixed_contact_str);
+ switch_safe_free(dup_mwi_account);
}
}
" network_ip VARCHAR(255),\n"
" network_port VARCHAR(6),\n"
" sip_username VARCHAR(255),\n"
- " sip_realm VARCHAR(255)\n"
+ " sip_realm VARCHAR(255),\n"
+ " mwi_user VARCHAR(255),\n"
+ " mwi_host VARCHAR(255)\n"
");\n";
test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' "
"or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' "
- "and network_ip!='-1' and network_port!='-1' and sip_username != '-1'",
+ "and network_ip!='-1' and network_port!='-1' and sip_username != '-1' and mwi_user != '-1' and mwi_host != '-1'",
mod_sofia_globals.hostname);
if (switch_odbc_handle_exec(profile->master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' "
"or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' "
- "and network_ip!='-1' and network_port!='-1' and sip_username != '-1'",
+ "and network_ip!='-1' and network_port!='-1' and sip_username != '-1' and mwi_user != '-1' and mwi_host != '-1'",
mod_sofia_globals.hostname);
switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_registrations", reg_sql);
int sofia_glue_get_user_host(char *in, char **user, char **host)
{
- char *p, *h, *u = in;
+ char *p = NULL, *h = NULL, *u = in;
- if (user) {
- *user = NULL;
+ if (!in) {
+ return 0;
}
- *host = NULL;
-
/* First isolate the host part from the user part */
if ((h = strchr(u, '@'))) {
*h++ = '\0';
- } else {
- return 0;
}
/* Clean out the user part of its protocol prefix (if any) */
- if (user && (p = strchr(u, ':'))) {
+ if ((p = strchr(u, ':'))) {
*p++ = '\0';
u = p;
}
/* Clean out the host part of any suffix */
- if ((p = strchr(h, ':'))) {
- *p = '\0';
- }
-
- if ((p = strchr(h, ';'))) {
- *p = '\0';
- }
-
- if ((p = strchr(h, ' '))) {
- *p = '\0';
- }
+ if (h) {
+ if ((p = strchr(h, ':'))) {
+ *p = '\0';
+ }
+
+ if ((p = strchr(h, ';'))) {
+ *p = '\0';
+ }
+ if ((p = strchr(h, ' '))) {
+ *p = '\0';
+ }
+ }
if (user) {
- *user = u;
+ *user = u;
+ }
+ if (host) {
+ *host = h;
}
-
- *host = h;
return 1;
}
if (for_everyone) {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q' "
- "from sip_registrations where sip_user='%q' and sip_host='%q'",
+ "from sip_registrations where mwi_user='%q' and mwi_host='%q'",
stream.data, user, host);
} else if (call_id) {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q' "
- "from sip_registrations where sip_user='%q' and sip_host='%q' and call_id='%q'",
+ "from sip_registrations where mwi_user='%q' and mwi_host='%q' and call_id='%q'",
stream.data, user, host, call_id);
}
switch_event_t *s_event;
const char *to_user = NULL;
const char *to_host = NULL;
+ char *mwi_account = NULL;
+ char *dup_mwi_account = NULL;
+ char *mwi_user = NULL;
+ char *mwi_host = NULL;
const char *from_user = NULL;
const char *from_host = NULL;
const char *reg_host = profile->reg_db_domain;
}
reg:
+ if ((mwi_account = switch_event_get_header(*v_event, "mwi-account"))) {
+ dup_mwi_account = strdup(mwi_account);
+ switch_assert(dup_mwi_account != NULL);
+ sofia_glue_get_user_host(dup_mwi_account, &mwi_user, &mwi_host);
+ }
+
+ if (!mwi_user) {
+ mwi_user = (char *) to_user;
+ }
+ if (!mwi_host) {
+ mwi_host = (char *) reg_host;
+ }
+
if (regtype != REG_REGISTER) {
switch_goto_int(r, 0, end);
}
}
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
-
+
switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
sql = switch_mprintf("insert into sip_registrations "
"(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,"
- "user_agent,server_user,server_host,profile_name,hostname,network_ip,network_port,sip_username,sip_realm) "
- "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q','%q','%q')",
+ "user_agent,server_user,server_host,profile_name,hostname,network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host) "
+ "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q','%q','%q','%q','%q')",
call_id, to_user, reg_host, profile->presence_hosts ? profile->presence_hosts : reg_host,
contact_str, reg_desc, rpid, (long) switch_epoch_time_now(NULL) + (long) exptime * 2,
- agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c, username, realm);
+ agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c, username, realm, mwi_user, mwi_host);
if (sql) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
-
switch_mutex_unlock(profile->ireg_mutex);
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_REGISTER) == SWITCH_STATUS_SUCCESS) {
if (sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER)) {
if (switch_event_create(&s_event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", to_user, reg_host);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", mwi_user, mwi_host);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "VM-Sofia-Profile", profile->name);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "VM-Call-ID", call_id);
}
end:
+ switch_safe_free(dup_mwi_account);
if (auth_params) {
switch_event_destroy(&auth_params);
int first = 0;
const char *passwd = NULL;
const char *a1_hash = NULL;
+ const char *mwi_account = NULL;
char *sql;
char *number_alias = NULL;
switch_xml_t domain, xml = NULL, user, param, uparams, dparams, group = NULL, gparams = NULL;
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
+ if (!strcasecmp(var, "mwi-account")) {
+ mwi_account = val;
+ }
}
}
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
+ if (!strcasecmp(var, "mwi-account")) {
+ mwi_account = val;
+ }
}
}
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
+ if (!strcasecmp(var, "mwi-account")) {
+ mwi_account = val;
+ }
}
}
switch_event_add_header_string(*v_event, SWITCH_STACK_BOTTOM, "user_name", username);
switch_event_add_header_string(*v_event, SWITCH_STACK_BOTTOM, "domain_name", domain_name);
+ if (mwi_account) {
+ switch_event_add_header_string(*v_event, SWITCH_STACK_BOTTOM, "mwi-account", mwi_account);
+ }
+
if ((uparams = switch_xml_child(user, "params"))) {
xparams_type[i] = 0;
xparams[i++] = uparams;