[Freeswitch-svn] [commit] r5210 - freeswitch/trunk/src/mod/endpoints/mod_sofia
Freeswitch SVN
anthm at freeswitch.org
Tue May 22 11:03:22 EDT 2007
Author: anthm
Date: Tue May 22 11:03:21 2007
New Revision: 5210
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
Log:
improve connectile-dysfunction mode to send message packets from the server end to keep the connection open
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Tue May 22 11:03:21 2007
@@ -110,6 +110,28 @@
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 @@
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:
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Tue May 22 11:03:21 2007
@@ -94,7 +94,7 @@
nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END());
-
+
switch_safe_free(ffrom);
free(user);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Tue May 22 11:03:21 2007
@@ -136,6 +136,24 @@
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 @@
return 0;
}
+
void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
{
char sql[1024];
@@ -205,6 +224,16 @@
}
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 @@
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 @@
} 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 @@
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 =
More information about the Freeswitch-svn
mailing list