From 131be776f16ff89cfea62e6495916f81fd86a959 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 21 Apr 2009 17:47:22 +0000 Subject: [PATCH] add calls count and failed calls count to sofia profile sorted by direction git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13103 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_channel.h | 1 + src/mod/endpoints/mod_sofia/mod_sofia.c | 31 +++++++++++++++++++++---- src/mod/endpoints/mod_sofia/mod_sofia.h | 4 ++++ src/mod/endpoints/mod_sofia/sofia.c | 29 ++++++++++++++++++----- src/switch_channel.c | 5 ++++ 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index 719748debe..f70abba5fc 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -512,6 +512,7 @@ SWITCH_DECLARE(void) switch_channel_set_app_flag(switch_channel_t *channel, uint SWITCH_DECLARE(void) switch_channel_clear_app_flag(switch_channel_t *channel, uint32_t flags); SWITCH_DECLARE(int) switch_channel_test_app_flag(switch_channel_t *channel, uint32_t flags); SWITCH_DECLARE(void) switch_channel_set_hangup_time(switch_channel_t *channel); +SWITCH_DECLARE(switch_call_direction_t) switch_channel_direction(switch_channel_t *channel); /** @} */ diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index fee6a366d0..a6ed51dd40 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -273,6 +273,14 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) switch_mutex_lock(tech_pvt->sofia_mutex); + if (!switch_channel_test_flag(channel, CF_ANSWERED)) { + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + tech_pvt->profile->ob_failed_calls++; + } else { + tech_pvt->profile->ib_failed_calls++; + } + } + if (!((use_my_cause = switch_channel_get_variable(channel, "sip_ignore_remote_cause")) && switch_true(use_my_cause))) { ps_cause = switch_channel_get_variable(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE); } @@ -1664,6 +1672,10 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t stream->write_function(stream, "AGGRESSIVENAT \t%s\n", sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION) ? "true" : "false"); stream->write_function(stream, "STUN_ENABLED \t%s\n", sofia_test_pflag(profile, PFLAG_STUN_ENABLED) ? "true" : "false"); stream->write_function(stream, "STUN_AUTO_DISABLE\t%s\n", sofia_test_pflag(profile, PFLAG_STUN_AUTO_DISABLE) ? "true" : "false"); + stream->write_function(stream, "CallsIN \t%d\n", profile->ib_calls); + stream->write_function(stream, "FailedCallsIN \t%d\n", profile->ib_failed_calls); + stream->write_function(stream, "CallsOUT \t%d\n", profile->ob_calls); + stream->write_function(stream, "FailedCallsOUT \t%d\n", profile->ob_failed_calls); } stream->write_function(stream, "\nRegistrations:\n%s\n", line); @@ -1796,8 +1808,8 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl stream->write_function(stream, " %d\n", gp->ping_freq); stream->write_function(stream, " %s\n", sofia_state_names[gp->state]); stream->write_function(stream, " %s%s\n", status_names[gp->status], gp->pinging ? " (ping)" : ""); - stream->write_function(stream, " %d\n", gp->ib_calls); - stream->write_function(stream, " %d\n", gp->ob_calls); + stream->write_function(stream, " %d\n", gp->ib_calls); + stream->write_function(stream, " %d\n", gp->ob_calls); stream->write_function(stream, " \n"); sofia_reg_release_gateway(gp); @@ -1845,9 +1857,15 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl stream->write_function(stream, " %s\n", sofia_test_flag(profile, TFLAG_INB_NOMEDIA) ? "true" : "false"); stream->write_function(stream, " %s\n", sofia_test_flag(profile, TFLAG_LATE_NEGOTIATION) ? "true" : "false"); stream->write_function(stream, " %s\n", sofia_test_flag(profile, TFLAG_PROXY_MEDIA) ? "true" : "false"); - stream->write_function(stream, " %s\n", sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION) ? "true" : "false"); + stream->write_function(stream, " %s\n", + sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION) ? "true" : "false"); stream->write_function(stream, " %s\n", sofia_test_pflag(profile, PFLAG_STUN_ENABLED) ? "true" : "false"); - stream->write_function(stream, " %s\n", sofia_test_pflag(profile, PFLAG_STUN_AUTO_DISABLE) ? "true" : "false"); + stream->write_function(stream, " %s\n", + sofia_test_pflag(profile, PFLAG_STUN_AUTO_DISABLE) ? "true" : "false"); + stream->write_function(stream, " %s\n", profile->ib_calls); + stream->write_function(stream, " %s\n", profile->ob_calls); + stream->write_function(stream, " %s\n", profile->ib_failed_calls); + stream->write_function(stream, " %s\n", profile->ob_failed_calls); } stream->write_function(stream, " \n"); @@ -2694,6 +2712,11 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session done: if (profile) { + if (cause == SWITCH_CAUSE_SUCCESS) { + profile->ob_calls++; + } else { + profile->ob_failed_calls++; + } sofia_glue_release_profile(profile); } return cause; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index e4697b1d3f..c1048bde6a 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -469,6 +469,10 @@ struct sofia_profile { sofia_media_options_t media_options; uint32_t force_subscription_expires; switch_rtp_bug_flag_t auto_rtp_bugs; + uint32_t ib_calls; + uint32_t ob_calls; + uint32_t ib_failed_calls; + uint32_t ob_failed_calls; }; struct private_object { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 0f867f69ab..d8397c3e8a 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1473,6 +1473,10 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile) profile->rport_level = 1; /* default setting */ profile->acl_count = 0; sofia_set_pflag(profile, PFLAG_STUN_ENABLED); + profile->ib_calls = 0; + profile->ob_calls = 0; + profile->ib_failed_calls = 0; + profile->ob_failed_calls = 0; if (xprofiledomain) { profile->domain_name = switch_core_strdup(profile->pool, xprofiledomain); @@ -4124,21 +4128,23 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ char *is_nat = NULL; char acl_token[512] = ""; + profile->ib_calls++; + if (sess_count >= sess_max || !sofia_test_pflag(profile, PFLAG_RUNNING)) { nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); - return; + goto fail; } if (!sip || !sip->sip_request || !sip->sip_request->rq_method_name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received an invalid packet!\n"); nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END()); - return; + goto fail; } if (!(sip->sip_contact && sip->sip_contact->m_url)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n"); nua_respond(nh, 400, "Missing Contact Header", TAG_END()); - return; + goto fail; } get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); @@ -4209,7 +4215,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (!sofia_test_pflag(profile, PFLAG_AUTH_CALLS)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl \"%s\"\n", network_ip, switch_str_nil(last_acl)); nua_respond(nh, SIP_403_FORBIDDEN, TAG_END()); - return; + goto fail; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s Rejected by acl \"%s\". Falling back to Digest auth.\n", network_ip, switch_str_nil(last_acl)); @@ -4226,6 +4232,11 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (v_event) { switch_event_destroy(&v_event); } + + if (sip->sip_authorization || sip->sip_proxy_authorization) { + goto fail; + } + return; } } @@ -4242,14 +4253,14 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (!session) { nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); - return; + goto fail; } if (!(tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END()); switch_core_session_destroy(&session); - return; + goto fail; } @@ -4860,6 +4871,12 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ sofia_private_free(sofia_private); switch_core_session_destroy(&session); nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); + return; + + fail: + profile->ib_failed_calls++; + return; + } void sofia_handle_sip_i_options(int status, diff --git a/src/switch_channel.c b/src/switch_channel.c index 50050b277e..a6d1f182bb 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -212,6 +212,11 @@ SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(switch return times; } +SWITCH_DECLARE(switch_call_direction_t) switch_channel_direction(switch_channel_t *channel) +{ + return channel->direction; +} + SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel, switch_call_direction_t direction, switch_memory_pool_t *pool) { switch_assert(pool != NULL);