improve connectile-dysfunction mode to send message packets from the server end to keep the connection open

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5210 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-05-22 15:03:21 +00:00
parent e0047afb3f
commit dcd1d6423b
3 changed files with 56 additions and 4 deletions

View File

@ -110,6 +110,28 @@ void sofia_event_callback(nua_event_t event,
su_root_break(profile->s_root);
}
break;
case nua_r_message:
{
if (status == 503) {
const char *user = NULL, *host = NULL;
char *sql;
if (sip->sip_to && sip->sip_to->a_url) {
user = sip->sip_to->a_url->url_user;
host = sip->sip_to->a_url->url_host;
sql = switch_mprintf("delete from sip_registrations where user='%q' and host='%q'", user, host);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Deleting registration for %s@%s\n", user, host);
sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
switch_safe_free(sql);
}
}
nua_handle_destroy(nh);
}
break;
case nua_r_get_params:
case nua_r_invite:
case nua_r_unregister:
@ -120,7 +142,6 @@ void sofia_event_callback(nua_event_t event,
case nua_i_bye:
case nua_r_unsubscribe:
case nua_r_publish:
case nua_r_message:
case nua_r_notify:
case nua_i_notify:
case nua_i_cancel:

View File

@ -94,7 +94,7 @@ switch_status_t sofia_presence_chat_send(char *proto, char *from, char *to, char
nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END());
switch_safe_free(ffrom);
free(user);

View File

@ -136,6 +136,24 @@ int sofia_reg_find_callback(void *pArg, int argc, char **argv, char **columnName
return 0;
}
int sofia_reg_nat_callback(void *pArg, int argc, char **argv, char **columnNames)
{
sofia_profile_t *profile = (sofia_profile_t *) pArg;
nua_handle_t *nh;
char *contact;
char to[128] = "";
snprintf(to, sizeof(to), "%s@%s", argv[0], argv[1]);
contact = sofia_glue_get_url_from_contact(argv[2], 1);
nh = nua_handle(profile->nua, NULL, SIPTAG_FROM_STR(profile->url), SIPTAG_TO_STR(to), NUTAG_URL(contact), SIPTAG_CONTACT_STR(profile->url), TAG_END());
nua_message(nh, SIPTAG_CONTENT_TYPE_STR("text/plain"),
SIPTAG_PAYLOAD_STR("You suffer from Connectile Dysfunction.\nYou should use stun....\n"), TAG_END());
return 0;
}
int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames)
{
switch_event_t *s_event;
@ -153,6 +171,7 @@ int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames
return 0;
}
void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
{
char sql[1024];
@ -205,6 +224,16 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
}
sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
if (now) {
snprintf(sql, sizeof(sql), "select * from sip_registrations where status like '%%NATHACK%%'");
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_reg_nat_callback,
profile);
}
switch_mutex_unlock(profile->ireg_mutex);
}
@ -264,6 +293,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
const char *display = "\"user\"";
char network_ip[80];
int network_port;
int cd = 0;
/* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
@ -342,6 +372,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
} else {
snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>", display, contact->m_url->url_user, network_ip, network_port);
}
cd = 1;
} else {
char *p;
switch_copy_string(contact_str, v_contact_str, sizeof(contact_str));
@ -397,8 +428,8 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (exptime) {
if (!sofia_reg_find_reg_url(profile, from_user, from_host, buf, sizeof(buf))) {
sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','Registered', '%q', %ld)",
from_user, from_host, contact_str, rpid, (long) time(NULL) + (long) exptime * 2);
sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','%q', '%q', %ld)",
from_user, from_host, contact_str, cd ? "Registered(NATHACK)" : "Registered", rpid, (long) time(NULL) + (long) exptime * 2);
} else {
sql =