提交 e9bde2eb authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-3758 --resolve ok so I wrote my own patch but i did borrow the 2 lines of…

FS-3758 --resolve ok so I wrote my own patch but i did borrow the 2 lines of code to create a seq from the original patch! sofia changes probably need to be converted to a tag if they are to go upstream.  This completely manages sub/pub from inside mod_sofia inside the db and subs can now persist and/or fail over mid dialog tested on several things like polycom/snom/yealink on SLA and presence
上级 e164b76c
...@@ -827,10 +827,10 @@ static int nua_notify_usage_shutdown(nua_handle_t *nh, ...@@ -827,10 +827,10 @@ static int nua_notify_usage_shutdown(nua_handle_t *nh,
nua_dialog_usage_t *du) nua_dialog_usage_t *du)
{ {
struct notifier_usage *nu = nua_dialog_usage_private(du); struct notifier_usage *nu = nua_dialog_usage_private(du);
nua_client_request_t *cr = du->du_cr; //nua_client_request_t *cr = du->du_cr;
nu->nu_substate = nua_substate_terminated; nu->nu_substate = nua_substate_terminated;
#if 0
if (cr) { if (cr) {
SU_DEBUG_5(("%s(%p, %p, %p): using existing cr=%p\n", SU_DEBUG_5(("%s(%p, %p, %p): using existing cr=%p\n",
"nua_notify_usage_shutdown", "nua_notify_usage_shutdown",
...@@ -852,7 +852,7 @@ static int nua_notify_usage_shutdown(nua_handle_t *nh, ...@@ -852,7 +852,7 @@ static int nua_notify_usage_shutdown(nua_handle_t *nh,
TAG_END()) >= 0) TAG_END()) >= 0)
return 0; return 0;
} }
#endif
nua_dialog_usage_remove(nh, ds, du, NULL, NULL); nua_dialog_usage_remove(nh, ds, du, NULL, NULL);
return 200; return 200;
} }
......
...@@ -158,14 +158,15 @@ int nua_stack_process_request(nua_handle_t *nh, ...@@ -158,14 +158,15 @@ int nua_stack_process_request(nua_handle_t *nh,
/* These must be in-dialog */ /* These must be in-dialog */
sm = NULL; sm = NULL;
} }
else if (initial && sip->sip_to->a_tag) { else if (initial && sip->sip_to->a_tag && method != sip_method_subscribe) {
/* RFC 3261 section 12.2.2: /* RFC 3261 section 12.2.2:
If the UAS wishes to reject the request because it does not wish to If the UAS wishes to reject the request because it does not wish to
recreate the dialog, it MUST respond to the request with a 481 recreate the dialog, it MUST respond to the request with a 481
(Call/Transaction Does Not Exist) status code and pass that to the (Call/Transaction Does Not Exist) status code and pass that to the
server transaction. server transaction.
*/ */ /* we allow this on subscribes because we have disabled the built-in notify server and we need those messages in the application layer */
if (method == sip_method_info) if (method == sip_method_info)
/* accept out-of-dialog info */; else /* accept out-of-dialog info */; else
if (method != sip_method_message || !NH_PGET(nh, win_messenger_enable)) if (method != sip_method_message || !NH_PGET(nh, win_messenger_enable))
......
...@@ -9,7 +9,7 @@ SOFIAUA_BUILDDIR=$(SOFIA_BUILDDIR)/libsofia-sip-ua ...@@ -9,7 +9,7 @@ SOFIAUA_BUILDDIR=$(SOFIA_BUILDDIR)/libsofia-sip-ua
SOFIALA=$(SOFIAUA_BUILDDIR)/libsofia-sip-ua.la SOFIALA=$(SOFIAUA_BUILDDIR)/libsofia-sip-ua.la
mod_LTLIBRARIES = mod_sofia.la mod_LTLIBRARIES = mod_sofia.la
mod_sofia_la_SOURCES = mod_sofia.c sofia.c sofia_glue.c sofia_presence.c sofia_reg.c sofia_sla.c sip-dig.c mod_sofia.h mod_sofia_la_SOURCES = mod_sofia.c sofia.c sofia_glue.c sofia_presence.c sofia_reg.c sip-dig.c mod_sofia.h
mod_sofia_la_CFLAGS = $(AM_CFLAGS) -I. $(SOFIA_CMD_LINE_CFLAGS) mod_sofia_la_CFLAGS = $(AM_CFLAGS) -I. $(SOFIA_CMD_LINE_CFLAGS)
mod_sofia_la_CFLAGS += -I$(SOFIAUA_DIR)/bnf -I$(SOFIAUA_BUILDDIR)/bnf mod_sofia_la_CFLAGS += -I$(SOFIAUA_DIR)/bnf -I$(SOFIAUA_BUILDDIR)/bnf
mod_sofia_la_CFLAGS += -I$(SOFIAUA_DIR)/http -I$(SOFIAUA_BUILDDIR)/http mod_sofia_la_CFLAGS += -I$(SOFIAUA_DIR)/http -I$(SOFIAUA_BUILDDIR)/http
......
...@@ -217,7 +217,7 @@ typedef enum { ...@@ -217,7 +217,7 @@ typedef enum {
PFLAG_UUID_AS_CALLID, PFLAG_UUID_AS_CALLID,
PFLAG_SCROOGE, PFLAG_SCROOGE,
PFLAG_MANAGE_SHARED_APPEARANCE, PFLAG_MANAGE_SHARED_APPEARANCE,
PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO, PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO_DELETED_USE_ME,
PFLAG_DISABLE_SRV, PFLAG_DISABLE_SRV,
PFLAG_DISABLE_SRV503, PFLAG_DISABLE_SRV503,
PFLAG_DISABLE_NAPTR, PFLAG_DISABLE_NAPTR,
...@@ -634,6 +634,7 @@ struct sofia_profile { ...@@ -634,6 +634,7 @@ struct sofia_profile {
int watchdog_enabled; int watchdog_enabled;
switch_mutex_t *gw_mutex; switch_mutex_t *gw_mutex;
uint32_t queued_events; uint32_t queued_events;
uint32_t cseq_base;
}; };
struct private_object { struct private_object {
...@@ -1064,24 +1065,6 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force) ...@@ -1064,24 +1065,6 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout); void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout);
void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *t38_options, int insist); void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *t38_options, int insist);
/*
* SLA (shared line appearance) entrypoints
*/
void sofia_sla_handle_register(nua_t *nua, sofia_profile_t *profile, sip_t const *sip,
sofia_dispatch_event_t *de, long exptime, const char *full_contact);
void sofia_sla_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip,
sofia_dispatch_event_t *de, tagi_t tags[]);
void sofia_sla_handle_sip_i_subscribe(nua_t *nua, const char *contact_str, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip,
sofia_dispatch_event_t *de, tagi_t tags[]);
void sofia_sla_handle_sip_r_subscribe(int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
sofia_dispatch_event_t *de,
tagi_t tags[]);
void sofia_sla_handle_sip_i_notify(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip,
sofia_dispatch_event_t *de, tagi_t tags[]);
/* /*
* Logging control functions * Logging control functions
*/ */
...@@ -1145,3 +1128,4 @@ char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, sof ...@@ -1145,3 +1128,4 @@ char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, sof
void sofia_glue_pause_jitterbuffer(switch_core_session_t *session, switch_bool_t on); void sofia_glue_pause_jitterbuffer(switch_core_session_t *session, switch_bool_t on);
void sofia_process_dispatch_event(sofia_dispatch_event_t **dep); void sofia_process_dispatch_event(sofia_dispatch_event_t **dep);
char *sofia_glue_get_host(const char *str, switch_memory_pool_t *pool); char *sofia_glue_get_host(const char *str, switch_memory_pool_t *pool);
void sofia_presence_check_subscriptions(sofia_profile_t *profile, time_t now);
...@@ -90,7 +90,8 @@ void sofia_handle_sip_r_notify(switch_core_session_t *session, int status, ...@@ -90,7 +90,8 @@ void sofia_handle_sip_r_notify(switch_core_session_t *session, int status,
if (status >= 300 && sip && sip->sip_call_id && (!sofia_private || !sofia_private->is_call)) { if (status >= 300 && sip && sip->sip_call_id && (!sofia_private || !sofia_private->is_call)) {
char *sql; char *sql;
sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", sip->sip_call_id->i_id);
sql = switch_mprintf("update sip_subscriptions set expires=%ld where call_id='%q'", (long) switch_epoch_time_now(NULL), sip->sip_call_id->i_id);
switch_assert(sql != NULL); switch_assert(sql != NULL);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
nua_handle_destroy(nh); nua_handle_destroy(nh);
...@@ -238,19 +239,21 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, ...@@ -238,19 +239,21 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip,
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
int x = 0; int x = 0;
SWITCH_STANDARD_STREAM(stream); if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
SWITCH_STANDARD_STREAM(stream);
for(vp = sip->sip_via; vp; vp = vp->v_next) {
char *v = sip_header_as_string(nh->nh_home, (void *) vp); for(vp = sip->sip_via; vp; vp = vp->v_next) {
char *v = sip_header_as_string(nh->nh_home, (void *) vp);
stream.write_function(&stream, x == 0 ? "%s" : ",%s", v);
su_free(nh->nh_home, v); stream.write_function(&stream, x == 0 ? "%s" : ",%s", v);
su_free(nh->nh_home, v);
x++;
}
x++; switch_channel_set_variable(channel, "sip_recover_via", (char *)stream.data);
free(stream.data);
} }
switch_channel_set_variable(channel, "sip_recover_via", (char *)stream.data);
free(stream.data);
} }
if (sip->sip_from) { if (sip->sip_from) {
...@@ -337,21 +340,6 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, ...@@ -337,21 +340,6 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
goto error; goto error;
} }
/* the following could be refactored back to the calling event handler here in sofia.c XXX MTK */
/* potentially interesting note: for Linksys shared appearance, we'll probably have to set up to get bare notifies
* and pass them inward to the sla handler. we'll have to set NUTAG_APPL_METHOD("NOTIFY") when creating
* nua, and also pick them off special elsewhere here in sofia.c - MTK
* *and* for Linksys, I believe they use "sa" as their magic appearance agent name for those blind notifies, so
* we'll probably have to change to match
*/
if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) {
if (sip->sip_request->rq_url->url_user && !strncmp(sip->sip_request->rq_url->url_user, "sla-agent", sizeof("sla-agent"))) {
sofia_sla_handle_sip_i_notify(nua, profile, nh, sip, de, tags);
goto end;
}
}
/* Automatically return a 200 OK for Event: keep-alive */ /* Automatically return a 200 OK for Event: keep-alive */
if (!strcasecmp(sip->sip_event->o_type, "keep-alive")) { if (!strcasecmp(sip->sip_event->o_type, "keep-alive")) {
/* XXX MTK - is this right? in this case isn't sofia is already sending a 200 itself also? */ /* XXX MTK - is this right? in this case isn't sofia is already sending a 200 itself also? */
...@@ -4077,8 +4065,9 @@ switch_status_t config_sofia(int reload, char *profile_name) ...@@ -4077,8 +4065,9 @@ switch_status_t config_sofia(int reload, char *profile_name)
sofia_set_pflag(profile, PFLAG_MULTIREG); sofia_set_pflag(profile, PFLAG_MULTIREG);
} else if (!strcasecmp(val, "sylantro")) { } else if (!strcasecmp(val, "sylantro")) {
profile->sla_contact = switch_core_sprintf(profile->pool, "sla-agent"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
sofia_set_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO); "Sylantro support has been removed.\n"
"It was incomplete anyway, and we fully support the broadsoft SCA shared line spec.");
} }
} else if (!strcasecmp(var, "disable-srv")) { } else if (!strcasecmp(var, "disable-srv")) {
if (switch_true(val)) { if (switch_true(val)) {
......
...@@ -5904,7 +5904,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -5904,7 +5904,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
" network_port VARCHAR(6),\n" " network_port VARCHAR(6),\n"
" network_ip VARCHAR(255),\n" " network_ip VARCHAR(255),\n"
" version INTEGER DEFAULT 0 NOT NULL,\n" " version INTEGER DEFAULT 0 NOT NULL,\n"
" orig_proto VARCHAR(255)\n" " orig_proto VARCHAR(255),\n"
" full_to VARCHAR(255)\n"
");\n"; ");\n";
char auth_sql[] = char auth_sql[] =
...@@ -6047,10 +6048,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -6047,10 +6048,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
free(test_sql); free(test_sql);
test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and full_to='XXX'", mod_sofia_globals.hostname);
test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' "
"and (version < 0 or orig_proto like '%%' or network_ip like '%%' or network_port like '%%')",
mod_sofia_globals.hostname);
switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_subscriptions", sub_sql); switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
free(test_sql); free(test_sql);
......
...@@ -763,15 +763,8 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot) ...@@ -763,15 +763,8 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sub_del_callback, profile); sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sub_del_callback, profile);
if (now) {
switch_snprintfv(sql, sizeof(sql), "delete from sip_subscriptions where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%q'",
(long) now, mod_sofia_globals.hostname);
} else {
switch_snprintfv(sql, sizeof(sql), "delete from sip_subscriptions where expires >= -1 and hostname='%q'", mod_sofia_globals.hostname);
}
sofia_glue_actually_execute_sql(profile, sql, NULL);
sofia_presence_check_subscriptions(profile, now);
if (now) { if (now) {
switch_snprintfv(sql, sizeof(sql), "delete from sip_dialogs where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%q'", switch_snprintfv(sql, sizeof(sql), "delete from sip_dialogs where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%q'",
...@@ -1500,8 +1493,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -1500,8 +1493,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
if (delete_subs) { if (delete_subs) {
if (reg_count == 1) { if (reg_count == 1) {
sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q' and contact='%q'", sql = switch_mprintf("update sip_subscriptions set expires=%ld where sip_user='%q' and sip_host='%q' and contact='%q'",
to_user, sub_host, contact_str); (long) switch_epoch_time_now(NULL), to_user, sub_host, contact_str);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
} }
} }
...@@ -1509,16 +1502,19 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -1509,16 +1502,19 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
if (multi_reg_contact) { if (multi_reg_contact) {
sql = sql =
switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str); switch_mprintf("update sip_registrations set expires=%ld where sip_user='%q' and sip_host='%q' and contact='%q'",
(long) switch_epoch_time_now(NULL), to_user, reg_host, contact_str);
} else { } else {
sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id); sql = switch_mprintf("update sip_registrations set expires=%ld where call_id='%q'", (long) switch_epoch_time_now(NULL), call_id);
} }
} else { } else {
if (delete_subs) { if (delete_subs) {
sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, sub_host); sql = switch_mprintf("update sip_subscriptions set expires=%ld where sip_user='%q' and sip_host='%q'",
(long) switch_epoch_time_now(NULL), to_user, sub_host);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
} }
sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, reg_host); sql = switch_mprintf("update sip_registrations set expires=%ld where sip_user='%q' and sip_host='%q'",
(long) switch_epoch_time_now(NULL), to_user, reg_host);
} }
switch_mutex_lock(profile->ireg_mutex); switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
...@@ -1664,9 +1660,10 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -1664,9 +1660,10 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
if (delete_subs) { if (delete_subs) {
if (multi_reg_contact) { if (multi_reg_contact) {
sql = sql =
switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, sub_host, contact_str); switch_mprintf("update sip_subscriptions set expires=%ld where sip_user='%q' and sip_host='%q' and contact='%q'",
(long) switch_epoch_time_now(NULL), to_user, sub_host, contact_str);
} else { } else {
sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id); sql = switch_mprintf("update sip_subscriptions set expires=%ld where call_id='%q'", (long) switch_epoch_time_now(NULL), call_id);
} }
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
...@@ -1684,7 +1681,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -1684,7 +1681,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
switch_safe_free(icontact); switch_safe_free(icontact);
} else { } else {
if (delete_subs) { if (delete_subs) {
if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, sub_host))) { if ((sql = switch_mprintf("update sip_subscriptions set expires=%ld where sip_user='%q' and sip_host='%q'",
(long) switch_epoch_time_now(NULL), to_user, sub_host))) {
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
} }
} }
...@@ -1812,10 +1810,6 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand ...@@ -1812,10 +1810,6 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
switch_event_fire(&s_mwi_event); switch_event_fire(&s_mwi_event);
} }
if (contact && *contact_str && sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO)) {
sofia_sla_handle_register(nua, profile, sip, de, exptime, contact_str);
}
switch_goto_int(r, 1, end); switch_goto_int(r, 1, end);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论