indent pass 2

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2008-05-27 04:54:52 +00:00
parent 9bbcabbbdd
commit f930eaeec7
101 changed files with 31644 additions and 31458 deletions
+130 -157
View File
@@ -98,14 +98,14 @@ static switch_status_t sofia_on_init(switch_core_session_t *session)
if (sofia_glue_do_invite(session) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
assert( switch_channel_get_state(channel) != CS_INIT);
assert(switch_channel_get_state(channel) != CS_INIT);
return SWITCH_STATUS_FALSE;
}
}
/* Move channel's state machine to ROUTING */
switch_channel_set_state(channel, CS_ROUTING);
assert( switch_channel_get_state(channel) != CS_INIT);
assert(switch_channel_get_state(channel) != CS_INIT);
return SWITCH_STATUS_SUCCESS;
}
@@ -115,7 +115,7 @@ static switch_status_t sofia_on_routing(switch_core_session_t *session)
switch_assert(tech_pvt != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA ROUTING\n", switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
@@ -128,7 +128,7 @@ static switch_status_t sofia_on_reset(switch_core_session_t *session)
switch_assert(tech_pvt != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA RESET\n", switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
@@ -141,7 +141,7 @@ static switch_status_t sofia_on_hibernate(switch_core_session_t *session)
switch_assert(tech_pvt != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA HIBERNATE\n", switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
@@ -160,7 +160,7 @@ static switch_status_t sofia_on_execute(switch_core_session_t *session)
/* map QSIG cause codes to SIP from RFC4497 section 8.4.1 */
static int hangup_cause_to_sip(switch_call_cause_t cause)
{
{
switch (cause) {
case SWITCH_CAUSE_NO_ROUTE_TRANSIT_NET:
case SWITCH_CAUSE_NO_ROUTE_DESTINATION:
@@ -223,11 +223,11 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
switch_call_cause_t cause = switch_channel_get_cause(channel);
int sip_cause = hangup_cause_to_sip(cause);
const char *ps_cause = switch_channel_get_variable(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE);
if (!switch_strlen_zero(ps_cause) && !strncasecmp(ps_cause, "sip:", 4)) {
int new_cause = atoi(ps_cause + 4);
if (new_cause) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Overriding SIP cause %d with %d from the other leg\n",
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Overriding SIP cause %d with %d from the other leg\n",
switch_channel_get_name(channel), sip_cause, new_cause);
sip_cause = new_cause;
}
@@ -262,7 +262,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
sofia_glue_deactivate_rtp(tech_pvt);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s hanging up, cause: %s\n",
switch_channel_get_name(channel), switch_channel_cause2str(cause));
switch_channel_get_name(channel), switch_channel_cause2str(cause));
if (tech_pvt->hash_key) {
switch_core_hash_delete(tech_pvt->profile->chat_hash, tech_pvt->hash_key);
@@ -282,7 +282,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
switch_mutex_lock(tech_pvt->profile->flag_mutex);
if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
char reason[128] = "";
if (cause > 1 && cause < 128) {
switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
@@ -291,7 +291,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
} else {
switch_snprintf(reason, sizeof(reason), "FreeSWITCH;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
}
if (switch_test_flag(tech_pvt, TFLAG_ANS)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel));
nua_bye(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END());
@@ -349,7 +349,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE);
is_proxy = (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA));
if (b_sdp && is_proxy) {
tech_pvt->local_sdp_str = switch_core_session_strdup(session, b_sdp);
@@ -373,7 +373,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
tech_pvt->num_codecs = 0;
sofia_glue_tech_prepare_codecs(tech_pvt);
if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
//nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
@@ -394,8 +394,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
if (tech_pvt->nh) {
if (tech_pvt->local_sdp_str) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel),
tech_pvt->local_sdp_str);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel), tech_pvt->local_sdp_str);
}
}
}
@@ -406,16 +405,16 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
session_timeout = v_session_timeout;
}
}
if (switch_test_flag(tech_pvt, TFLAG_NAT) ||
(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
sticky = tech_pvt->record_route;
session_timeout = SOFIA_NAT_SESSION_TIMEOUT;
switch_channel_set_variable(channel, "sip_nat_detected", "true");
}
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_AUTOANSWER(0),
@@ -423,11 +422,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
NUTAG_SESSION_TIMER(session_timeout),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_AUDIO_AUX("cn telephone-event"),
NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_END());
SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
return SWITCH_STATUS_SUCCESS;
}
@@ -474,7 +469,7 @@ static switch_status_t sofia_read_video_frame(switch_core_session_t *session, sw
}
return status;
}
payload = tech_pvt->video_read_frame.payload;
if (tech_pvt->video_read_frame.datalen > 0) {
@@ -524,13 +519,13 @@ static switch_status_t sofia_write_video_frame(switch_core_session_t *session, s
if (!switch_test_flag(frame, SFF_CNG)) {
switch_rtp_write_frame(tech_pvt->video_rtp_session, frame);
}
return status;
}
static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
{
private_object_t *tech_pvt = switch_core_session_get_private(session);
private_object_t *tech_pvt = switch_core_session_get_private(session);
switch_channel_t *channel = switch_core_session_get_channel(session);
int payload = 0;
@@ -558,7 +553,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
if (switch_test_flag(tech_pvt, TFLAG_IO)) {
switch_status_t status;
if (!switch_test_flag(tech_pvt, TFLAG_RTP)) {
return SWITCH_STATUS_GENERR;
}
@@ -570,22 +565,22 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
tech_pvt->read_frame.flags = SFF_NONE;
status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame, flags);
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
if (status == SWITCH_STATUS_TIMEOUT) {
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_MEDIA_TIMEOUT);
}
return status;
}
payload = tech_pvt->read_frame.payload;
if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {
switch_dtmf_t dtmf = {0};
switch_dtmf_t dtmf = { 0 };
switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, &dtmf);
switch_channel_queue_dtmf(channel, &dtmf);
}
if (tech_pvt->read_frame.datalen > 0) {
size_t bytes = 0;
int frames = 1;
@@ -712,10 +707,7 @@ static switch_status_t sofia_send_dtmf(switch_core_session_t *session, const swi
case DTMF_INFO:
snprintf(message, sizeof(message), "Signal=%c\r\nDuration=%d\r\n", dtmf->digit, dtmf->duration / 8);
nua_info(tech_pvt->nh,
SIPTAG_CONTENT_TYPE_STR("application/dtmf-relay"),
SIPTAG_PAYLOAD_STR(message),
TAG_END());
nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/dtmf-relay"), SIPTAG_PAYLOAD_STR(message), TAG_END());
break;
default:
break;
@@ -750,18 +742,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
" <media_control>\r\n"
" <vc_primitive>\r\n"
" <to_encoder>\r\n"
" <picture_fast_update>\r\n"
" </picture_fast_update>\r\n"
" </to_encoder>\r\n"
" </vc_primitive>\r\n"
" </media_control>\r\n";
nua_info(tech_pvt->nh,
SIPTAG_CONTENT_TYPE_STR("application/media_control+xml"),
SIPTAG_PAYLOAD_STR(pl),
TAG_END());
" <picture_fast_update>\r\n" " </picture_fast_update>\r\n" " </to_encoder>\r\n" " </vc_primitive>\r\n" " </media_control>\r\n";
nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/media_control+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END());
}
break;
case SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY:
@@ -770,31 +755,27 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833);
}
break;
case SWITCH_MESSAGE_INDICATE_BROADCAST: {
const char *ip = NULL, *port = NULL;
ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
if (ip && port) {
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
case SWITCH_MESSAGE_INDICATE_BROADCAST:{
const char *ip = NULL, *port = NULL;
ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
if (ip && port) {
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
}
nua_respond(tech_pvt->nh, SIP_200_OK,
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
switch_channel_mark_answered(channel);
}
nua_respond(tech_pvt->nh, SIP_200_OK,
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_AUDIO_AUX("cn telephone-event"),
NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_END());
switch_channel_mark_answered(channel);
}
break;
case SWITCH_MESSAGE_INDICATE_NOMEDIA:
case SWITCH_MESSAGE_INDICATE_NOMEDIA:
{
const char *uuid;
switch_core_session_t *other_session;
switch_channel_t *other_channel;
const char *ip = NULL, *port = NULL;
switch_channel_set_flag(channel, CF_PROXY_MODE);
tech_pvt->local_sdp_str = NULL;
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
@@ -826,14 +807,14 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
case SWITCH_MESSAGE_INDICATE_MEDIA:
{
uint32_t send_invite = 1;
switch_channel_clear_flag(channel, CF_PROXY_MODE);
tech_pvt->local_sdp_str = NULL;
if (!switch_channel_media_ready(channel)) {
if (!switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
tech_pvt->num_codecs = 0;
sofia_glue_tech_prepare_codecs(tech_pvt);
if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
@@ -882,7 +863,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
}
break;
case SWITCH_MESSAGE_INDICATE_UNHOLD:
{
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
@@ -890,7 +871,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
break;
case SWITCH_MESSAGE_INDICATE_BRIDGE:
if (switch_test_flag(tech_pvt, TFLAG_XFER)) {
switch_clear_flag_locked(tech_pvt, TFLAG_XFER);
if (msg->pointer_arg) {
@@ -918,19 +899,19 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
}
/*
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
}
*/
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
}
*/
break;
case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
/*
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
}
*/
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
}
*/
break;
case SWITCH_MESSAGE_INDICATE_REDIRECT:
if (msg->string_arg) {
@@ -962,7 +943,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
if (code) {
reason = msg->string_arg;
} else {
if (!switch_strlen_zero(msg->string_arg)){
if (!switch_strlen_zero(msg->string_arg)) {
if ((code = atoi(msg->string_arg))) {
if ((reason = strchr(msg->string_arg, ' '))) {
reason++;
@@ -974,14 +955,14 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
if (!code) {
code = 488;
}
if (switch_strlen_zero(reason) && code != 407) {
reason = sip_status_phrase(code);
if (switch_strlen_zero(reason)) {
reason = "Because";
}
}
if (code == 407 && !msg->numeric_arg) {
const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri");
const char *to_host = reason;
@@ -990,14 +971,14 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
to_host = switch_channel_get_variable(channel, "sip_to_host");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri);
sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0);
sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0);
switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE);
} else if (code == 484 && msg->numeric_arg) {
const char *to = switch_channel_get_variable(channel, "sip_to_uri");
const char *max_forwards = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE);
char *to_uri = NULL;
if (to) {
char *p;
to_uri = switch_core_session_sprintf(session, "sip:%s", to);
@@ -1015,9 +996,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason);
if (!switch_strlen_zero(((char *)msg->pointer_arg))) {
tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, (char *)msg->pointer_arg);
if (!switch_strlen_zero(((char *) msg->pointer_arg))) {
tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, (char *) msg->pointer_arg);
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
sofia_glue_tech_patch_sdp(tech_pvt);
sofia_glue_tech_proxy_remote_addr(tech_pvt);
@@ -1025,10 +1006,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
nua_respond(tech_pvt->nh, code, reason, SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_AUDIO_AUX("cn telephone-event"),
NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_END());
SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
} else {
nua_respond(tech_pvt->nh, code, reason, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END());
}
@@ -1036,11 +1014,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
}
}
}
break;
case SWITCH_MESSAGE_INDICATE_RINGING:
if (!switch_channel_test_flag(channel, CF_RING_READY) &&
if (!switch_channel_test_flag(channel, CF_RING_READY) &&
!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) {
nua_respond(tech_pvt->nh, SIP_180_RINGING, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END());
switch_channel_mark_ring_ready(channel);
@@ -1055,10 +1033,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
const char *val = NULL;
if (!switch_test_flag(tech_pvt, TFLAG_ANS) && !switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Asked to send early media by %s\n", msg->from);
/* Transmit 183 Progress with SDP */
if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
const char *sdp = NULL;
@@ -1105,7 +1083,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
if (switch_test_flag(tech_pvt, TFLAG_NAT) ||
(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
sticky = tech_pvt->record_route;
switch_channel_set_variable(channel, "sip_nat_detected", "true");
@@ -1117,8 +1095,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
SOATAG_ORDERED_USER(1), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
}
}
break;
@@ -1126,10 +1103,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
break;
}
end:
end:
return status;
}
static switch_status_t sofia_receive_event(switch_core_session_t *session, switch_event_t *event)
@@ -1158,14 +1135,15 @@ static switch_status_t sofia_receive_event(switch_core_session_t *session, switc
typedef switch_status_t (*sofia_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
static const char *sofia_state_names[] = { "UNREGED",
"TRYING",
"REGISTER",
"REGED",
"UNREGISTER",
"FAILED",
"EXPIRED",
"NOREG",
NULL};
"TRYING",
"REGISTER",
"REGED",
"UNREGISTER",
"FAILED",
"EXPIRED",
"NOREG",
NULL
};
struct cb_helper {
sofia_profile_t *profile;
@@ -1188,17 +1166,14 @@ static int show_reg_callback(void *pArg, int argc, char **argv, char **columnNam
switch_strftime(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
}
cb->stream->write_function(cb->stream,
cb->stream->write_function(cb->stream,
"Call-ID \t%s\n"
"User \t%s@%s\n"
"Contact \t%s\n"
"Agent \t%s\n"
"Status \t%s(%s) EXP(%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);
"Status \t%s(%s) EXP(%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);
return 0;
}
@@ -1254,24 +1229,24 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
stream->write_function(stream, "Name \t%s\n", switch_str_nil(argv[1]));
stream->write_function(stream, "Domain Name\t%s\n", switch_str_nil(profile->domain_name));
if (strcasecmp(argv[1], profile->name)) {
stream->write_function(stream, "Alias Of \t%s\n", switch_str_nil(profile->name));
stream->write_function(stream, "Alias Of \t%s\n", switch_str_nil(profile->name));
}
stream->write_function(stream, "DBName \t%s\n", switch_str_nil(profile->dbname));
stream->write_function(stream, "Dialplan \t%s\n", switch_str_nil(profile->dialplan));
stream->write_function(stream, "RTP-IP \t%s\n", switch_str_nil(profile->rtpip));
if (profile->extrtpip) {
stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
}
stream->write_function(stream, "SIP-IP \t%s\n", switch_str_nil(profile->sipip));
if (profile->extsipip) {
stream->write_function(stream, "Ext-SIP-IP \t%s\n", profile->extsipip);
stream->write_function(stream, "Ext-SIP-IP \t%s\n", profile->extsipip);
}
stream->write_function(stream, "URL \t%s\n", switch_str_nil(profile->url));
stream->write_function(stream, "BIND-URL \t%s\n", switch_str_nil(profile->bindurl));
if (sofia_test_pflag(profile, PFLAG_TLS)) {
stream->write_function(stream, "TLS-URL \t%s\n", switch_str_nil(profile->tls_url));
stream->write_function(stream, "TLS-BIND-URL \t%s\n", switch_str_nil(profile->tls_bindurl));
stream->write_function(stream, "TLS-URL \t%s\n", switch_str_nil(profile->tls_url));
stream->write_function(stream, "TLS-BIND-URL \t%s\n", switch_str_nil(profile->tls_bindurl));
}
stream->write_function(stream, "HOLD-MUSIC \t%s\n", switch_str_nil(profile->hold_music));
stream->write_function(stream, "CODECS \t%s\n", switch_str_nil(profile->codec_string));
@@ -1283,10 +1258,8 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
cb.profile = profile;
cb.stream = stream;
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
"select * from sip_registrations",
show_reg_callback, &cb);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, "select * from sip_registrations", show_reg_callback, &cb);
stream->write_function(stream, "%s\n", line);
@@ -1308,7 +1281,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
switch_hash_this(hi, &vvar, NULL, &val);
profile = (sofia_profile_t *) val;
if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
if (strcmp(vvar, profile->name)) {
ac++;
stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", vvar, " alias", profile->name, "ALIASED");
@@ -1317,8 +1290,8 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
if (sofia_test_pflag(profile, PFLAG_TLS)) {
stream->write_function(stream, "%25s\t%s\t %32s\t%s (%u) (TLS)\n", profile->name, "profile", profile->tls_url,
sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
stream->write_function(stream, "%25s\t%s\t %32s\t%s (%u) (TLS)\n", profile->name, "profile", profile->tls_url,
sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
}
c++;
@@ -1366,12 +1339,12 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
}
return SWITCH_STATUS_SUCCESS;
}
if (switch_strlen_zero(profile_name) || !(profile = sofia_glue_find_profile(profile_name))) {
stream->write_function(stream, "Invalid Profile [%s]", switch_str_nil(profile_name));
return SWITCH_STATUS_SUCCESS;
}
if (!strcasecmp(argv[1], "flush_inbound_reg")) {
if (argc > 2) {
sofia_reg_expire_call_id(profile, argv[2]);
@@ -1407,7 +1380,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
} else {
stream->write_function(stream, "Invalid gateway!\n");
}
goto done;
}
@@ -1442,7 +1415,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
int diff = (int) (switch_timestamp(NULL) - profile->started);
int remain = rsec - diff;
if (diff < rsec) {
stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",
stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",
profile->name, rsec, remain, remain == 1 ? "" : "s");
} else {
@@ -1467,7 +1440,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
stream->write_function(stream, "-ERR Unknown command!\n");
done:
done:
if (profile) {
sofia_glue_release_profile(profile);
}
@@ -1524,14 +1497,14 @@ SWITCH_STANDARD_API(sofia_contact_function)
if ((domain = strchr(user, '@'))) {
*domain++ = '\0';
}
if (!profile_name && domain) {
profile_name = domain;
}
if (user && profile_name) {
char *sql;
if (!(profile = sofia_glue_find_profile(profile_name))) {
profile_name = domain;
domain = NULL;
@@ -1544,7 +1517,7 @@ SWITCH_STANDARD_API(sofia_contact_function)
if (profile) {
struct cb_helper cb;
switch_stream_handle_t mystream = { 0 };
if (!domain || !strchr(domain, '.')) {
domain = profile->name;
}
@@ -1553,9 +1526,9 @@ SWITCH_STANDARD_API(sofia_contact_function)
switch_assert(mystream.data);
cb.profile = profile;
cb.stream = &mystream;
if (exclude_contact) {
sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q' and contact not like '%%%s%%'",
sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q' and contact not like '%%%s%%'",
user, domain, exclude_contact);
} else {
sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q'", user, domain);
@@ -1573,7 +1546,7 @@ SWITCH_STANDARD_API(sofia_contact_function)
switch_safe_free(mystream.data);
}
}
if (reply) {
stream->write_function(stream, "%s", reply);
}
@@ -1600,13 +1573,12 @@ SWITCH_STANDARD_API(sofia_function)
"sofia help\n"
"sofia profile <profile_name> [start|stop|restart|flush_inbound_reg [<call_id>]|[register|unregister] [<gateway name>|all]] [reloadxml]\n"
"sofia status [[profile | gateway] <name>]\n"
"sofia loglevel [0-9]\n"
"--------------------------------------------------------------------------------\n";
"sofia loglevel [0-9]\n" "--------------------------------------------------------------------------------\n";
if (session) {
return SWITCH_STATUS_FALSE;
}
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "%s", usage_string);
goto done;
@@ -1621,7 +1593,7 @@ SWITCH_STANDARD_API(sofia_function)
stream->write_function(stream, "%s", usage_string);
goto done;
}
if (!strcasecmp(argv[0], "profile")) {
func = cmd_profile;
} else if (!strcasecmp(argv[0], "status")) {
@@ -1664,9 +1636,9 @@ switch_io_routines_t sofia_io_routines = {
/*.send_dtmf */ sofia_send_dtmf,
/*.receive_message */ sofia_receive_message,
/*.receive_event */ sofia_receive_event,
/*.state_change*/ NULL,
/*.read_video_frame*/ sofia_read_video_frame,
/*.write_video_frame*/ sofia_write_video_frame
/*.state_change */ NULL,
/*.read_video_frame */ sofia_read_video_frame,
/*.write_video_frame */ sofia_write_video_frame
};
switch_state_handler_table_t sofia_event_handlers = {
@@ -1677,8 +1649,8 @@ switch_state_handler_table_t sofia_event_handlers = {
/*.on_exchange_media */ sofia_on_exchange_media,
/*.on_soft_execute */ sofia_on_soft_execute,
/*.on_consume_media */ NULL,
/*.on_hibernate*/ sofia_on_hibernate,
/*.on_reset*/ sofia_on_reset
/*.on_hibernate */ sofia_on_hibernate,
/*.on_reset */ sofia_on_reset
};
static switch_status_t sofia_manage(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
@@ -1698,7 +1670,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
private_object_t *tech_pvt = NULL;
switch_channel_t *nchannel;
char *host = NULL, *dest_to = NULL;
*new_session = NULL;
if (!(nsession = switch_core_session_request(sofia_endpoint_interface, pool))) {
@@ -1758,14 +1730,14 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
* invite contact.
*
* TODO:
* - Add parameters back to destination url?
* - Add parameters back to destination url?
*/
if ((params = strchr(dest, ';'))) {
char *tp_param;
*params++ = '\0';
if ((tp_param = (char *)switch_stristr("port=", params))) {
if ((tp_param = (char *) switch_stristr("port=", params))) {
tp_param += 5;
tech_pvt->transport = sofia_glue_str2transport(tp_param);
if (tech_pvt->transport == SOFIA_TRANSPORT_UNKNOWN) {
@@ -1776,7 +1748,8 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
}
if (tech_pvt->transport != gateway_ptr->register_transport) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You are trying to use a different transport type for this gateway (overriding the register-transport), this is unsupported!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"You are trying to use a different transport type for this gateway (overriding the register-transport), this is unsupported!\n");
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
goto error;
}
@@ -1860,7 +1833,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
tech_pvt->dest_to = switch_core_session_sprintf(nsession, "sip:%s@%s", dest_to, host);
}
}
if (!tech_pvt->dest_to) {
tech_pvt->dest_to = tech_pvt->dest;
@@ -1961,7 +1934,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_core_hash_init(&mod_sofia_globals.profile_hash, mod_sofia_globals.pool);
switch_core_hash_init(&mod_sofia_globals.gateway_hash, mod_sofia_globals.pool);
switch_mutex_init(&mod_sofia_globals.hash_mutex, SWITCH_MUTEX_NESTED, mod_sofia_globals.pool);
switch_mutex_lock(mod_sofia_globals.mutex);
mod_sofia_globals.running = 1;
switch_mutex_unlock(mod_sofia_globals.mutex);
@@ -2034,7 +2007,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
{
int sanity = 0;
switch_mutex_lock(mod_sofia_globals.mutex);
if (mod_sofia_globals.running == 1) {
mod_sofia_globals.running = 0;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+147 -193
View File
@@ -127,7 +127,8 @@ void sofia_presence_cancel(void)
void *val;
struct presence_helper helper = { 0 };
if (!mod_sofia_globals.profile_hash) return;
if (!mod_sofia_globals.profile_hash)
return;
if ((sql = switch_mprintf("select *,-1,'unavailable','unavailable' from sip_subscriptions where event='presence'"))) {
switch_mutex_lock(mod_sofia_globals.hash_mutex);
@@ -151,16 +152,15 @@ void sofia_presence_cancel(void)
void sofia_presence_establish_presence(sofia_profile_t *profile)
{
if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
"select sip_user,sip_host,'Registered','unknown','' from sip_registrations",
if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
"select sip_user,sip_host,'Registered','unknown','' from sip_registrations",
sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
return;
}
if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
"select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
"where proto='ext' or proto='user' or proto='conf'",
sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
"where proto='ext' or proto='user' or proto='conf'", sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
return;
}
}
@@ -172,7 +172,7 @@ char *sofia_presence_translate_rpid(char *in, char *ext)
if (in && (switch_stristr("null", in))) {
in = NULL;
}
if (!in) {
in = ext;
}
@@ -233,7 +233,7 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
return;
}
}
if (profile->domain_name && profile->domain_name != host) {
host = profile->domain_name;
}
@@ -251,43 +251,32 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
if (!strcasecmp(hp->name, "mwi-message-account") && strncasecmp(hp->value, "sip:", 4)) {
tmp = switch_mprintf("sip:%s", hp->value);
value = tmp;
}
}
stream.write_function(&stream, "%s: %s\r\n", hp->name + 4, value);
switch_safe_free(tmp);
}
}
stream.write_function(&stream, "\r\n");
sql = switch_mprintf("select *,'%q' from sip_subscriptions where event='message-summary' and sub_to_user='%q' and sub_to_host='%q'",
stream.data, user, host);
switch_assert (sql != NULL);
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_mwi_callback,
&h);
sql = switch_mprintf("select *,'%q' from sip_subscriptions where event='message-summary' and sub_to_user='%q' and sub_to_host='%q'",
stream.data, user, host);
switch_assert(sql != NULL);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback, &h);
switch_safe_free(sql);
sql = switch_mprintf("select sip_user,sip_host,contact,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'",
stream.data, user, host);
switch_assert (sql != NULL);
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_mwi_callback2,
&h);
sql = switch_mprintf("select sip_user,sip_host,contact,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'", stream.data, user, host);
switch_assert(sql != NULL);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback2, &h);
switch_safe_free(sql);
switch_safe_free(stream.data);
@@ -312,11 +301,11 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
char *sql = NULL;
char *euser = NULL, *user = NULL, *host = NULL;
if (!mod_sofia_globals.running) {
return;
}
if (rpid && !strcasecmp(rpid, "n/a")) {
rpid = NULL;
}
@@ -350,8 +339,9 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
if (event->event_id == SWITCH_EVENT_ROSTER) {
struct presence_helper helper = { 0 };
if (!mod_sofia_globals.profile_hash) return;
if (!mod_sofia_globals.profile_hash)
return;
if (from) {
sql = switch_mprintf("select *,1,'%q','%q' from sip_subscriptions where event='presence' and full_from like '%%%q%%'", status, rpid, from);
} else {
@@ -367,13 +357,8 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
continue;
}
helper.profile = profile;
helper.event = NULL;
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_sub_callback,
&helper);
helper.event = NULL;
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
free(sql);
@@ -387,7 +372,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
if (switch_strlen_zero(alt_event_type)) {
alt_event_type = "presence";
}
if ((user = strdup(from))) {
if ((host = strchr(user, '@'))) {
char *p;
@@ -432,15 +417,9 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
"from sip_registrations left join sip_dialogs on "
"(sip_dialogs.sip_from_user = sip_registrations.sip_user) "
"and sip_dialogs.sip_from_host = sip_registrations.sip_host "
"where sip_registrations.sip_user='%q' and sip_registrations.sip_host='%q'",
probe_euser, probe_host);
"where sip_registrations.sip_user='%q' and sip_registrations.sip_host='%q'", probe_euser, probe_host);
switch_assert(sql);
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_resub_callback,
profile);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_resub_callback, profile);
sofia_glue_release_profile(profile);
switch_safe_free(sql);
@@ -465,7 +444,8 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
break;
}
if (!mod_sofia_globals.profile_hash) goto done;
if (!mod_sofia_globals.profile_hash)
goto done;
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -478,31 +458,27 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
if (sql) {
struct presence_helper helper = { 0 };
helper.profile = profile;
helper.event = event;
helper.event = event;
SWITCH_STANDARD_STREAM(helper.stream);
switch_assert(helper.stream.data);
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE,
//profile->ireg_mutex,
NULL,
sql,
sofia_presence_sub_callback,
&helper);
if (!switch_strlen_zero((char *)helper.stream.data)) {
char *this = (char *)helper.stream.data;
NULL, sql, sofia_presence_sub_callback, &helper);
if (!switch_strlen_zero((char *) helper.stream.data)) {
char *this = (char *) helper.stream.data;
char *next = NULL;
char *last = NULL;
do {
if ((next = strchr(this, ';'))) {
*next++ = '\0';
while(*next == '\n' || *next == ' ' || *next == '\r') {
while (*next == '\n' || *next == ' ' || *next == '\r') {
*next++ = '\0';
}
}
if (!switch_strlen_zero(this) && (!last || strcmp(last, this))) {
sofia_glue_execute_sql(profile, &this, SWITCH_FALSE);
last = this;
@@ -516,7 +492,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
done:
done:
switch_safe_free(sql);
switch_safe_free(user);
}
@@ -543,10 +519,10 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread Started\n");
while (mod_sofia_globals.running == 1) {
int count = 0;
if (switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_event_t *event = (switch_event_t *) pop;
@@ -580,7 +556,7 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
switch_event_t *event = (switch_event_t *) pop;
switch_event_destroy(&event);
}
while (switch_queue_trypop(mod_sofia_globals.mwi_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
switch_event_t *event = (switch_event_t *) pop;
switch_event_destroy(&event);
@@ -592,7 +568,7 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
mod_sofia_globals.threads--;
EVENT_THREAD_RUNNING = EVENT_THREAD_STARTED = 0;
switch_mutex_unlock(mod_sofia_globals.mutex);
return NULL;
}
@@ -728,7 +704,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "astate", "%s", state);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", direction);
}
switch_event_fire(&event);
}
@@ -738,7 +714,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
static char *translate_rpid(char *in)
{
char *r = in;
if (in && (strstr(in, "null") || strstr(in, "NULL"))) {
in = NULL;
}
@@ -762,7 +738,7 @@ static char *translate_rpid(char *in)
r = "busy";
}
end:
end:
return r;
}
@@ -792,17 +768,17 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
char *prpid;
int done = 0;
const char *ct = "no/idea";
time_t exptime = switch_timestamp(NULL) + 3600;
char exp[80] = "";
time_t exptime = switch_timestamp(NULL) + 3600;
char exp[80] = "";
int is_dialog = 0;
if (expires) {
long tmp = atol(expires);
if (tmp > 0) {
exptime = tmp - switch_timestamp(NULL);
if (expires) {
long tmp = atol(expires);
if (tmp > 0) {
exptime = tmp - switch_timestamp(NULL);
}
}
if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Cannot find handle for %s\n", call_id);
return 0;
@@ -817,7 +793,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
if (in < 0) {
done = 1;
in = 0;
}
}
if (!strcasecmp(proto, SOFIA_CHAT_PROTO)) {
clean_id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
@@ -838,7 +814,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
to = switch_mprintf("sip:%s@%s", user, host);
is_dialog = !strcmp(event, "dialog");
if (helper->event) {
switch_stream_handle_t stream = { 0 };
const char *direction = switch_str_nil(switch_event_get_header(helper->event, "call-direction"));
@@ -854,7 +830,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
const char *clean_to_user = NULL;
const char *clean_from_user = NULL;
if (is_dialog) {
SWITCH_STANDARD_STREAM(stream);
}
@@ -866,43 +842,43 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
direction = "initiator";
dft_state = "confirmed";
}
if (!strcasecmp(state, "cs_execute") && !strstr(event_status, "hold")) {
goto end;
}
}
if (!strcasecmp(event_status, "Registered")) {
answer_state = "resubscribe";
}
if (is_dialog) {
stream.write_function(&stream,
stream.write_function(&stream,
"<?xml version=\"1.0\"?>\n"
"<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" "
"version=\"%s\" state=\"%s\" entity=\"%s\">\n",
"version=\"%s\" state=\"%s\" entity=\"%s\">\n",
switch_str_nil(switch_event_get_header(helper->event, "event_count")),
!strcasecmp(answer_state, "resubscribe") ? "partial" : "full", clean_id);
}
if (strcasecmp(answer_state, "resubscribe")) {
if (!strcasecmp(state, "cs_hangup")) {
astate = "terminated";
} else if (switch_strlen_zero(astate)) {
} else if (switch_strlen_zero(astate)) {
astate = switch_str_nil(switch_event_get_header(helper->event, "answer-state"));
if (switch_strlen_zero(astate)) {
if (switch_strlen_zero(astate)) {
astate = dft_state;
}
}
}
if (!strcasecmp(event_status, "hold")) {
astate = "early";
}
if (!strcasecmp(astate, "answered")) {
astate = "confirmed";
}
if (!strcasecmp(astate, "ringing")) {
if (!strcasecmp(direction, "recipient")) {
astate = "early";
@@ -915,7 +891,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
stream.write_function(&stream, "<state>%s</state>\n", astate);
}
if (!strcasecmp(astate, "early") || !strcasecmp(astate, "confirmed")) {
clean_to_user = switch_mprintf("%s", sub_to_user ? sub_to_user : to_user);
clean_from_user = switch_mprintf("%s", from_id ? from_id : from_user);
@@ -923,24 +899,26 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
if (!switch_strlen_zero(clean_to_user) && !switch_strlen_zero(clean_from_user)) {
stream.write_function(&stream, "<local>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_to_user, clean_to_user, host);
stream.write_function(&stream, "<target uri=\"sip:%s@%s\">\n", clean_to_user, host);
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n", !strcasecmp(event_status, "hold") ? "no" : "yes" );
stream.write_function(&stream, "</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_from_user, clean_from_user, host);
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n",
!strcasecmp(event_status, "hold") ? "no" : "yes");
stream.write_function(&stream, "</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_from_user, clean_from_user,
host);
stream.write_function(&stream, "<target uri=\"sip:**%s@%s\"/>\n", clean_to_user, host);
stream.write_function(&stream, "</remote>\n");
} else if (!strcasecmp(proto, "park")) {
stream.write_function(&stream, "<local>\n<identity display=\"parking\">sip:parking@%s;fifo=%s</identity>\n",
stream.write_function(&stream, "<local>\n<identity display=\"parking\">sip:parking@%s;fifo=%s</identity>\n",
host, !switch_strlen_zero(clean_to_user) ? clean_to_user : "unknown");
stream.write_function(&stream, "<target uri=\"sip:parking@%s\">\n", host);
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n</target>\n</local>\n");
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"parking\">sip:%s</identity>\n", uuid);
stream.write_function(&stream, "<target uri=\"sip:park+%s\"/>\n", uuid);
stream.write_function(&stream, "</remote>\n");
} else if (!strcasecmp(proto, "conf")) {
stream.write_function(&stream, "<local>\n<identity display=\"conference\">sip:conference@%s;conference=%s</identity>\n",
stream.write_function(&stream, "<local>\n<identity display=\"conference\">sip:conference@%s;conference=%s</identity>\n",
host, !switch_strlen_zero(clean_to_user) ? clean_to_user : "unknown");
stream.write_function(&stream, "<target uri=\"sip:conference@%s\">\n", host);
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"yes\"/>\n</target>\n</local>\n");
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"yes\"/>\n</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"conference\">sip:%s@%s</identity>\n", uuid, host);
stream.write_function(&stream, "<target uri=\"sip:conf+%s@%s\"/>\n", uuid, host);
stream.write_function(&stream, "</remote>\n");
@@ -948,7 +926,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
}
}
if (is_dialog) {
stream.write_function(&stream, "</dialog>\n");
stream.write_function(&stream, "</dialog>\n");
}
}
@@ -957,10 +935,10 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
pl = stream.data;
ct = "application/dialog-info+xml";
}
if (!switch_strlen_zero(astate) && !switch_strlen_zero(uuid) && helper && helper->stream.data && strcmp(helper->last_uuid, uuid)) {
helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%s' where uuid='%s';", astate, uuid);
switch_copy_string(helper->last_uuid, uuid, sizeof(helper->last_uuid));
}
@@ -968,7 +946,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
if (!is_dialog) {
if (in) {
char status_line[256] = "";
if (!strcmp(astate, "early")) {
switch_snprintf(status_line, sizeof(status_line), "R %s", switch_str_nil(from_id));
rpid = "on-the-phone";
@@ -976,8 +954,8 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
char *dest = switch_event_get_header(helper->event, "Caller-Destination-Number");
if (switch_strlen_zero(from_id) && !switch_strlen_zero(dest)) {
from_id = dest;
}
}
if (switch_strlen_zero(from_id)) {
switch_snprintf(status_line, sizeof(status_line), "Available");
} else {
@@ -994,7 +972,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
note = NULL;
open = "closed";
}
prpid = translate_rpid(rpid);
pl = switch_mprintf("<?xml version='1.0' encoding='UTF-8'?>\r\n"
"<presence xmlns='urn:ietf:params:xml:ns:pidf'\r\n"
@@ -1017,11 +995,8 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
"</status>\r\n"
"</tuple>\r\n"
"<dm:person id='p06360c4a'>\r\n"
"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
"</rpid:activities>%s</dm:person>\r\n"
"</presence>", id,
id, profile->url, open, status, prpid,
open, rpid, note);
"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
"</rpid:activities>%s</dm:person>\r\n" "</presence>", id, id, profile->url, open, status, prpid, open, rpid, note);
ct = "application/pidf+xml";
}
@@ -1055,21 +1030,16 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
"</status>\r\n"
"</tuple>\r\n"
"<dm:person id='p06360c4a'>\r\n"
"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
"</rpid:activities>%s</dm:person>\r\n"
"</presence>", id,
id, profile->url, open, status, prpid,
open, rpid, note);
"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
"</rpid:activities>%s</dm:person>\r\n" "</presence>", id, id, profile->url, open, status, prpid, open, rpid, note);
ct = "application/pidf+xml";
}
switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime);
switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime);
nua_handle_bind(nh, &mod_sofia_globals.keep_private);
nua_notify(nh,
SIPTAG_SUBSCRIPTION_STATE_STR(exp),
SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR(exp), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
end:
end:
switch_safe_free(id);
switch_safe_free(clean_id);
@@ -1101,15 +1071,15 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
int expire_sec = atoi(expires);
//int *total = (int *) pArg;
struct mwi_helper *h = (struct mwi_helper *) pArg;
if (!(nh = nua_handle_by_call_id(h->profile->nua, call_id))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
return 0;
}
id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
expire_sec = (int)(expire_sec - switch_timestamp(NULL));
expire_sec = (int) (expire_sec - switch_timestamp(NULL));
if (expire_sec < 0) {
expire_sec = 3600;
}
@@ -1118,7 +1088,7 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
nua_notify(nh,
SIPTAG_SUBSCRIPTION_STATE_STR(exp),
SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
switch_safe_free(id);
switch_safe_free(exp);
@@ -1139,33 +1109,29 @@ static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char
char *id = NULL;
nua_handle_t *nh;
struct mwi_helper *h = (struct mwi_helper *) pArg;
id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
contact = sofia_glue_get_url_from_contact(o_contact, 1);
nh = nua_handle(h->profile->nua, NULL,
NUTAG_URL(contact),
SIPTAG_FROM_STR(id),
SIPTAG_TO_STR(id),
SIPTAG_CONTACT_STR(h->profile->url),
TAG_END());
nh = nua_handle(h->profile->nua, NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(h->profile->url), TAG_END());
nua_notify(nh,
NUTAG_NEWSUB(1),
TAG_IF(strstr(o_contact, ";nat"), NUTAG_PROXY(contact)),
SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
switch_safe_free(contact);
switch_safe_free(id);
return 0;
}
void sofia_presence_handle_sip_i_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, tagi_t tags[])
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
if (sip) {
long exp, exp_raw;
@@ -1205,15 +1171,14 @@ void sofia_presence_handle_sip_i_subscribe(int status,
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
tl_gets(tags,
NUTAG_SUBSTATE_REF(sub_state), TAG_END());
tl_gets(tags, NUTAG_SUBSTATE_REF(sub_state), TAG_END());
event = sip_header_as_string(profile->home, (void *) sip->sip_event);
port = (char *) contact->m_url->url_port;
contact_host = sip->sip_contact->m_url->url_host;
contact_user = sip->sip_contact->m_url->url_user;
display = contact->m_display;
if (switch_strlen_zero(display)) {
@@ -1226,12 +1191,12 @@ void sofia_presence_handle_sip_i_subscribe(int status,
} else {
display = "\"user\"";
}
if ((profile->pflags & PFLAG_AGGRESSIVE_NAT_DETECTION)) {
if (sip && sip->sip_via) {
const char *v_port = sip->sip_via->v_port;
const char *v_host = sip->sip_via->v_host;
if (v_host && sip->sip_via->v_received) {
is_nat = "via received";
} else if (v_host && strcmp(network_ip, v_host)) {
@@ -1241,27 +1206,27 @@ void sofia_presence_handle_sip_i_subscribe(int status,
}
}
}
if (!is_nat && profile->nat_acl_count) {
uint32_t x = 0;
int ok = 1;
char *last_acl = NULL;
if (!switch_strlen_zero(contact_host)) {
for (x = 0 ; x < profile->nat_acl_count; x++) {
for (x = 0; x < profile->nat_acl_count; x++) {
last_acl = profile->nat_acl[x];
if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) {
break;
}
}
if (ok) {
is_nat = last_acl;
}
}
}
if (is_nat) {
contact_host = network_ip;
switch_snprintf(new_port, sizeof(new_port), ":%d", network_port);
@@ -1272,14 +1237,14 @@ void sofia_presence_handle_sip_i_subscribe(int status,
if (port) {
switch_snprintf(new_port, sizeof(new_port), ":%s", port);
}
if (contact->m_url->url_params) {
contact_str = switch_mprintf("%s <sip:%s@%s%s;%s>%s",
display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, is_nat ? ";nat" : "");
} else {
contact_str = switch_mprintf("%s <sip:%s@%s%s>%s", display, contact->m_url->url_user, contact_host, new_port, is_nat ? ";nat" : "");
}
if (to) {
to_str = switch_mprintf("sip:%s@%s", to->a_url->url_user, to->a_url->url_host); //, to->a_url->url_port);
@@ -1306,7 +1271,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
if ((p = strchr(protocol, '+'))) {
*p = '\0';
}
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
@@ -1315,7 +1280,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
switch_event_fire(&sevent);
}
} else {
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
@@ -1358,12 +1323,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
} else {
sql = switch_mprintf("delete from sip_subscriptions where "
"proto='%q' and sip_user='%q' and sip_host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q'",
proto,
from_user,
from_host,
to_user,
to_host, event
);
proto, from_user, from_host, to_user, to_host, event);
}
@@ -1377,34 +1337,30 @@ void sofia_presence_handle_sip_i_subscribe(int status,
sip_accept_t *ap = sip->sip_accept;
char accept[256] = "";
full_agent = sip_header_as_string(profile->home, (void *) sip->sip_user_agent);
while(ap) {
while (ap) {
switch_snprintf(accept + strlen(accept), sizeof(accept) - strlen(accept), "%s%s ", ap->ac_type, ap->ac_next ? "," : "");
ap = ap->ac_next;
}
sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q')",
proto, from_user, from_host, to_user, to_host, event,
contact_str, call_id, full_from, full_via, exp, full_agent, accept);
proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp, full_agent, accept);
switch_assert(sql != NULL);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
sstr = switch_mprintf("active;expires=%ld", exp_raw);
}
switch_mutex_unlock(profile->ireg_mutex);
if (status < 200) {
char *sticky = NULL;
if (is_nat) {
sticky = switch_mprintf("sip:%s@%s:%d", contact_user, network_ip, network_port);
}
nua_respond(nh, SIP_202_ACCEPTED,
NUTAG_WITH_THIS(nua),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
TAG_IF(sticky, NUTAG_PROXY(sticky)),
nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS(nua), SIPTAG_SUBSCRIPTION_STATE_STR(sstr), TAG_IF(sticky, NUTAG_PROXY(sticky)),
//SIPTAG_FROM(sip->sip_to),
//SIPTAG_TO(sip->sip_from),
//SIPTAG_CONTACT_STR(contact_str),
@@ -1413,32 +1369,26 @@ void sofia_presence_handle_sip_i_subscribe(int status,
switch_safe_free(sticky);
}
sent_reply++;
#if 0
nua_notify(nh,
nua_notify(nh,
NUTAG_NEWSUB(1),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event),
SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"),
SIPTAG_PAYLOAD_STR("Note: Come to ClueCon http://www.cluecon.com\n\n"),
TAG_END());
SIPTAG_PAYLOAD_STR("Note: Come to ClueCon http://www.cluecon.com\n\n"), TAG_END());
#endif
switch_safe_free(sstr);
if ((sql = switch_mprintf("select * from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_sub_reg_callback,
profile);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
switch_safe_free(sql);
}
end:
end:
if (event) {
su_free(profile->home, event);
@@ -1466,13 +1416,15 @@ void sofia_presence_handle_sip_i_subscribe(int status,
}
void sofia_presence_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, tagi_t tags[])
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
}
void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
if (sip) {
sip_from_t const *from = sip->sip_from;
@@ -1573,8 +1525,9 @@ void sofia_presence_set_hash_key(char *hash_key, int32_t len, sip_t const *sip)
}
void sofia_presence_handle_sip_i_message(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, tagi_t tags[])
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
if (sip) {
sip_from_t const *from = sip->sip_from;
@@ -1692,7 +1645,7 @@ void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip)
if (sofia_reg_find_reg_url(tech_pvt->profile, sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host, buf, sizeof(buf))) {
home = su_home_new(sizeof(*home));
switch_assert(home != NULL);
switch_assert(home != NULL);
tech_pvt->chat_from = sip_header_as_string(home, (const sip_header_t *) sip->sip_to);
tech_pvt->chat_to = switch_core_session_strdup(tech_pvt->session, buf);
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
@@ -1706,6 +1659,7 @@ void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip)
switch_core_hash_insert(tech_pvt->profile->chat_hash, tech_pvt->hash_key, tech_pvt);
}
/* For Emacs:
* Local Variables:
* mode:c
+162 -208
View File
@@ -38,21 +38,21 @@
static void sofia_reg_kill_reg(sofia_gateway_t *gateway_ptr, int unreg)
{
if (gateway_ptr->nh) {
if (unreg) {
nua_unregister(gateway_ptr->nh,
NUTAG_URL(gateway_ptr->register_url),
SIPTAG_FROM_STR(gateway_ptr->register_from),
SIPTAG_TO_STR(gateway_ptr->register_from),
SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
NUTAG_REGISTRAR(gateway_ptr->register_proxy),
NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
}
nua_handle_bind(gateway_ptr->nh, NULL);
nua_handle_destroy(gateway_ptr->nh);
gateway_ptr->nh = NULL;
}
if (gateway_ptr->nh) {
if (unreg) {
nua_unregister(gateway_ptr->nh,
NUTAG_URL(gateway_ptr->register_url),
SIPTAG_FROM_STR(gateway_ptr->register_from),
SIPTAG_TO_STR(gateway_ptr->register_from),
SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
NUTAG_REGISTRAR(gateway_ptr->register_proxy),
NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
}
nua_handle_bind(gateway_ptr->nh, NULL);
nua_handle_destroy(gateway_ptr->nh);
gateway_ptr->nh = NULL;
}
}
@@ -64,7 +64,7 @@ void sofia_reg_unregister(sofia_profile_t *profile)
free(gateway_ptr->sofia_private);
gateway_ptr->sofia_private = NULL;
}
sofia_reg_kill_reg(gateway_ptr, 1);
sofia_reg_kill_reg(gateway_ptr, 1);
}
}
@@ -94,7 +94,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
gateway_ptr->pinging = 1;
nua_options(nh, TAG_END());
}
switch (ostate) {
case REG_STATE_NOREG:
gateway_ptr->status = SOFIA_GATEWAY_UP;
@@ -107,12 +107,12 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
break;
case REG_STATE_UNREGISTER:
sofia_reg_kill_reg(gateway_ptr, 1);
sofia_reg_kill_reg(gateway_ptr, 1);
gateway_ptr->state = REG_STATE_NOREG;
break;
case REG_STATE_UNREGED:
gateway_ptr->status = SOFIA_GATEWAY_DOWN;
sofia_reg_kill_reg(gateway_ptr, 1);
sofia_reg_kill_reg(gateway_ptr, 1);
if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
NUTAG_URL(gateway_ptr->register_proxy),
@@ -120,10 +120,10 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registering %s\n", gateway_ptr->name);
if (!gateway_ptr->sofia_private) {
gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
switch_assert(gateway_ptr->sofia_private);
}
if (!gateway_ptr->sofia_private) {
gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
switch_assert(gateway_ptr->sofia_private);
}
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
gateway_ptr->sofia_private->gateway = gateway_ptr;
@@ -159,7 +159,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
break;
case REG_STATE_FAILED:
sofia_reg_kill_reg(gateway_ptr, 0);
sofia_reg_kill_reg(gateway_ptr, 0);
gateway_ptr->status = SOFIA_GATEWAY_DOWN;
case REG_STATE_TRYING:
if (gateway_ptr->retry && now >= gateway_ptr->retry) {
@@ -201,7 +201,7 @@ int sofia_reg_nat_callback(void *pArg, int argc, char **argv, char **columnNames
nua_options(nh, TAG_END());
switch_safe_free(contact);
return 0;
}
@@ -242,15 +242,10 @@ void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id)
{
char sql[1024];
char *psql = sql;
switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where call_id='%s'", profile->name, call_id);
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_reg_del_callback,
NULL);
sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, NULL);
switch_mutex_unlock(profile->ireg_mutex);
switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where call_id='%s'", call_id);
@@ -262,19 +257,19 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
char sql[1024];
#ifdef SWITCH_HAVE_ODBC
if (profile->odbc_dsn) {
if (!profile->master_odbc) {
if (profile->odbc_dsn) {
if (!profile->master_odbc) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
return;
}
} else {
}
} else {
#endif
if (!profile->master_db) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
return;
}
#ifdef SWITCH_HAVE_ODBC
}
}
#endif
@@ -286,12 +281,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where expires > 0", profile->name);
}
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_reg_del_callback,
NULL);
sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, NULL);
if (now) {
switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld", (long) now);
} else {
@@ -299,7 +289,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
}
sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
if (now) {
switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld", (long) now);
} else {
@@ -307,7 +297,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
}
sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
if (now) {
@@ -316,12 +306,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
switch_snprintf(sql, sizeof(sql), "select call_id from sip_subscriptions where expires > 0");
}
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_sub_del_callback,
profile);
sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_sub_del_callback, profile);
if (now) {
switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires > 0 and expires <= %ld", (long) now);
@@ -330,16 +315,11 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
}
sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
if (now) {
switch_snprintf(sql, sizeof(sql), "select * from sip_registrations where status like '%%AUTO-NAT%%'");
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_reg_nat_callback,
profile);
sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_nat_callback, profile);
}
switch_mutex_unlock(profile->ireg_mutex);
@@ -365,12 +345,7 @@ char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const c
}
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
val,
sofia_reg_find_callback,
&cbt);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, val, sofia_reg_find_callback, &cbt);
if (cbt.matches) {
@@ -390,30 +365,24 @@ void sofia_reg_auth_challange(nua_t *nua, sofia_profile_t *profile, nua_handle_t
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
sql = switch_mprintf("insert into sip_authentication (nonce, expires) values('%q', %ld)",
uuid_str, switch_timestamp(NULL) + profile->nonce_ttl);
sql = switch_mprintf("insert into sip_authentication (nonce, expires) values('%q', %ld)", uuid_str, switch_timestamp(NULL) + profile->nonce_ttl);
switch_assert(sql != NULL);
sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
switch_safe_free(sql);
//sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
auth_str =
switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", realm, uuid_str, stale ? " stale=\"true\"," : "");
auth_str = switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", realm, uuid_str, stale ? " stale=\"true\"," : "");
if (regtype == REG_REGISTER) {
nua_respond(nh,
SIP_401_UNAUTHORIZED,
TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_WWW_AUTHENTICATE_STR(auth_str), TAG_END());
nua_respond(nh, SIP_401_UNAUTHORIZED, TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_WWW_AUTHENTICATE_STR(auth_str), TAG_END());
} else if (regtype == REG_INVITE) {
nua_respond(nh,
SIP_407_PROXY_AUTH_REQUIRED,
TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_PROXY_AUTHENTICATE_STR(auth_str), TAG_END());
nua_respond(nh, SIP_407_PROXY_AUTH_REQUIRED, TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_PROXY_AUTHENTICATE_STR(auth_str), TAG_END());
}
switch_safe_free(auth_str);
}
uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
uint32_t keylen, switch_event_t **v_event, const char *is_nat)
{
sip_to_t const *to = NULL;
@@ -446,7 +415,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
expires = sip->sip_expires;
authorization = sip->sip_authorization;
contact = sip->sip_contact;
@@ -468,14 +437,14 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
char new_port[25] = "";
const char *contact_host = contact->m_url->url_host;
display = contact->m_display;
if (is_nat) {
reg_desc = "Registered(AUTO-NAT)";
contact_host = network_ip;
switch_snprintf(new_port, sizeof(new_port), ":%d", network_port);
port = NULL;
}
if (switch_strlen_zero(display)) {
if (to) {
display = to->a_display;
@@ -495,13 +464,10 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (contact->m_url->url_params) {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s;%s>%s%s",
display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params,
received_data,
is_nat ? ";nat" : "");
display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, received_data, is_nat ? ";nat" : "");
} else {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s>%s%s", display, contact->m_url->url_user, contact_host, new_port,
received_data,
is_nat ? ";nat" : "");
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s>%s%s", display, contact->m_url->url_user, contact_host, new_port,
received_data, is_nat ? ";nat" : "");
}
}
@@ -524,37 +490,38 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (authorization) {
char *v_contact_str;
if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name,
if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name,
key, keylen, network_ip, v_event, exptime, regtype, to_user)) == AUTH_STALE) {
stale = 1;
}
if (exptime && v_event && *v_event) {
char *exp_var;
register_gateway = switch_event_get_header(*v_event, "sip-register-gateway");
/* Allow us to force the SIP user to be something specific - needed if
* we - for example - want to be able to ensure that the username a UA can
* be contacted at is the same one that they used for authentication.
*/
*/
if ((force_user = switch_event_get_header(*v_event, "sip-force-user"))) {
to_user = force_user;
}
if ((v_contact_str = switch_event_get_header(*v_event, "sip-force-contact"))) {
if (*received_data && (profile->pflags & PFLAG_RECIEVED_IN_NAT_REG_CONTACT)) {
switch_snprintf(received_data, sizeof(received_data), ";received=\"%s:%d\"", network_ip, network_port);
}
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
!strcasecmp(v_contact_str, "NDLB-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-tls-connectile-dysfunction")) {
if (contact->m_url->url_params) {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d;%s>%s;nat",
display, contact->m_url->url_user, network_ip, network_port, contact->m_url->url_params, received_data);
} else {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>%s;nat", display, contact->m_url->url_user, network_ip, network_port, received_data);
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>%s;nat", display, contact->m_url->url_user, network_ip,
network_port, received_data);
}
if (strstr(v_contact_str, "tls")) {
reg_desc = "Registered(TLSHACK)";
@@ -566,14 +533,14 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
} else {
char *p;
switch_copy_string(contact_str, v_contact_str, sizeof(contact_str));
for(p = contact_str; p && *p; p++) {
for (p = contact_str; p && *p; p++) {
if (*p == '\'' || *p == '[' || *p == ']') {
*p = '"';
}
}
}
}
if ((exp_var = switch_event_get_header(*v_event, "sip-force-expires"))) {
int tmp = atoi(exp_var);
if (tmp > 0) {
@@ -585,13 +552,9 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (auth_res != AUTH_OK && !stale) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "send %s for [%s@%s]\n", forbidden ? "forbidden" : "challange", to_user, to_host);
if (auth_res == AUTH_FORBIDDEN) {
nua_respond(nh,
SIP_403_FORBIDDEN,
NUTAG_WITH_THIS(nua), TAG_END());
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
} else {
nua_respond(nh,
SIP_401_UNAUTHORIZED,
NUTAG_WITH_THIS(nua), TAG_END());
nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END());
}
return 1;
}
@@ -604,13 +567,13 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
}
return 1;
}
reg:
reg:
if (regtype != REG_REGISTER) {
return 0;
}
call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
switch_assert(call_id);
if (exptime) {
@@ -627,10 +590,9 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
}
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','%q', '%q', %ld, '%q')", call_id,
to_user, to_host, contact_str, reg_desc,
rpid, (long) switch_timestamp(NULL) + (long) exptime * 2, agent);
to_user, to_host, contact_str, reg_desc, rpid, (long) switch_timestamp(NULL) + (long) exptime * 2, agent);
if (sql) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
@@ -647,7 +609,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
switch_event_fire(&s_event);
}
if (profile->debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
@@ -676,7 +638,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if ((sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
if ((sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
@@ -685,7 +647,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
if ((sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
@@ -709,22 +671,22 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
switch_event_fire(&event);
}
/*
if (call_id) {
su_free(profile->home, call_id);
}
*/
if (call_id) {
su_free(profile->home, call_id);
}
*/
if (regtype == REG_REGISTER) {
char *new_contact = NULL;
char new_port[30] = "";
char exp_param[128] = "";
if (exptime) {
switch_snprintf(exp_param, sizeof(exp_param), ";expires=%ld", exptime);
}
if (contact->m_url->url_port) {
switch_snprintf(new_port, sizeof(new_port), ":%s", contact->m_url->url_port);
@@ -732,17 +694,12 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (contact->m_url->url_params) {
new_contact = switch_mprintf("%s <sip:%s@%s%s;%s>%s",
display, contact->m_url->url_user, contact->m_url->url_host, new_port, contact->m_url->url_params,
exp_param);
display, contact->m_url->url_user, contact->m_url->url_host, new_port, contact->m_url->url_params, exp_param);
} else {
new_contact = switch_mprintf("%s <sip:%s@%s%s>%s",
display, contact->m_url->url_user, contact->m_url->url_host, new_port,
exp_param);
new_contact = switch_mprintf("%s <sip:%s@%s%s>%s", display, contact->m_url->url_user, contact->m_url->url_host, new_port, exp_param);
}
nua_respond(nh,
SIP_200_OK,
SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
switch_safe_free(new_contact);
if (exptime) {
@@ -763,7 +720,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
}
}
}
return 1;
}
@@ -773,7 +730,8 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
char key[128] = "";
switch_event_t *v_event = NULL;
@@ -785,7 +743,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
if (!(sip->sip_contact && sip->sip_contact->m_url)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n");
@@ -794,9 +752,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
}
if (!(profile->mflags & MFLAG_REGISTER)) {
nua_respond(nh,
SIP_403_FORBIDDEN,
NUTAG_WITH_THIS(nua), TAG_END());
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
goto end;
}
@@ -804,7 +760,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
if (sip && sip->sip_via) {
const char *port = sip->sip_via->v_port;
const char *host = sip->sip_via->v_host;
if (host && sip->sip_via->v_received) {
is_nat = "via received";
} else if (host && strcmp(network_ip, host)) {
@@ -826,13 +782,13 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
}
if (!switch_strlen_zero(contact_host)) {
for (x = 0 ; x < profile->nat_acl_count; x++) {
for (x = 0; x < profile->nat_acl_count; x++) {
last_acl = profile->nat_acl[x];
if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) {
break;
}
}
if (ok) {
is_nat = last_acl;
}
@@ -844,29 +800,25 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
int ok = 1;
char *last_acl = NULL;
for (x = 0 ; x < profile->reg_acl_count; x++) {
for (x = 0; x < profile->reg_acl_count; x++) {
last_acl = profile->reg_acl[x];
if (!(ok = switch_check_network_list_ip(network_ip, last_acl))) {
break;
}
}
if (ok && !(profile->pflags & PFLAG_BLIND_REG)) {
type = REG_AUTO_REGISTER;
} else if (!ok) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", network_ip, profile->reg_acl[x]);
nua_respond(nh,
SIP_403_FORBIDDEN,
NUTAG_WITH_THIS(nua), TAG_END());
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", network_ip, profile->reg_acl[x]);
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
goto end;
}
}
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_500_INTERNAL_SERVER_ERROR,
TAG_END());
nua_respond(nh, SIP_500_INTERNAL_SERVER_ERROR, TAG_END());
goto end;
}
@@ -876,7 +828,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
switch_event_fire(&v_event);
}
end:
end:
nua_handle_destroy(nh);
@@ -885,7 +837,8 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
void sofia_reg_handle_sip_r_register(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, tagi_t tags[])
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
if (sofia_private && sofia_private->gateway) {
switch (status) {
@@ -915,7 +868,7 @@ void sofia_reg_handle_sip_r_register(int status,
void sofia_reg_handle_sip_r_challenge(int status,
char const *phrase,
nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh,
switch_core_session_t *session, sofia_gateway_t *gateway, sip_t const *sip, tagi_t tags[])
{
sip_www_authenticate_t const *authenticate = NULL;
@@ -976,17 +929,17 @@ void sofia_reg_handle_sip_r_challenge(int status,
return;
cancel:
cancel:
if (session) {
switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_MANDATORY_IE_MISSING);
} else {
nua_cancel(nh, TAG_END());
}
}
auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, sip_t const *sip, const char *regstr,
auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, sip_t const *sip, const char *regstr,
char *np, size_t nplen, char *ip, switch_event_t **v_event, long exptime, sofia_regtype_t regtype, const char *to_user)
{
int indexnum;
@@ -1001,13 +954,13 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
const char *a1_hash = NULL;
char *sql;
char *mailbox = NULL;
switch_xml_t domain, xml = NULL, user, param, uparams, dparams;
switch_xml_t domain, xml = NULL, user, param, uparams, dparams;
char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1] = "";
char *domain_name = NULL;
switch_event_t *params = NULL;
username = realm = nonce = uri = qop = cnonce = nc = response = NULL;
if (authorization->au_params) {
for (indexnum = 0; (cur = authorization->au_params[indexnum]); indexnum++) {
char *var, *val, *p, *work;
@@ -1052,7 +1005,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
ret = AUTH_STALE;
goto end;
}
/* Optional check that auth name == SIP username */
if ((regtype == REG_REGISTER) && (profile->pflags & PFLAG_CHECKUSER)) {
if (switch_strlen_zero(username) || switch_strlen_zero(to_user) || strcasecmp(to_user, username)) {
@@ -1072,44 +1025,45 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
goto end;
}
free(sql);
}
}
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "sip_auth");
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_profile", profile->name);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_user_agent", (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_user_agent",
(sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_username", username);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_realm", realm);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nonce", nonce);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_uri", uri);
if (qop) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_qop", qop);
}
if (cnonce) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_cnonce", cnonce);
}
if (nc) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nc", nc);
}
if (qop) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_qop", qop);
}
if (cnonce) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_cnonce", cnonce);
}
if (nc) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nc", nc);
}
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_response", response);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_method", (sip && sip->sip_request) ? sip->sip_request->rq_method_name : NULL);
if (!switch_strlen_zero(profile->reg_domain)) {
domain_name = profile->reg_domain;
} else {
domain_name = realm;
}
if (switch_xml_locate_user("id", username, domain_name, ip, &xml, &domain, &user, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", username, domain_name);
ret = AUTH_FORBIDDEN;
goto end;
}
if (!(mailbox = (char *)switch_xml_attr(user, "mailbox"))) {
if (!(mailbox = (char *) switch_xml_attr(user, "mailbox"))) {
mailbox = username;
}
@@ -1125,11 +1079,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
for (param = switch_xml_child(dparams, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "password")) {
passwd = val;
}
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
@@ -1140,11 +1094,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
for (param = switch_xml_child(uparams, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "password")) {
passwd = val;
}
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
@@ -1164,10 +1118,10 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
su_md5_deinit(&ctx);
switch_safe_free(input);
a1_hash = hexdigest;
}
for_the_sake_of_interop:
for_the_sake_of_interop:
if ((input = switch_mprintf("%s:%q", regstr, uri))) {
su_md5_init(&ctx);
@@ -1176,38 +1130,38 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
su_md5_deinit(&ctx);
}
if (nc && cnonce && qop) {
input2 = switch_mprintf("%q:%q:%q:%q:%q:%q", a1_hash, nonce, nc, cnonce, qop, uridigest);
} else {
input2 = switch_mprintf("%q:%q:%q", a1_hash, nonce, uridigest);
}
if (nc && cnonce && qop) {
input2 = switch_mprintf("%q:%q:%q:%q:%q:%q", a1_hash, nonce, nc, cnonce, qop, uridigest);
} else {
input2 = switch_mprintf("%q:%q:%q", a1_hash, nonce, uridigest);
}
switch_assert(input2);
switch_assert(input2);
memset(&ctx, 0, sizeof(ctx));
su_md5_init(&ctx);
su_md5_strupdate(&ctx, input2);
su_md5_hexdigest(&ctx, bigdigest);
su_md5_deinit(&ctx);
memset(&ctx, 0, sizeof(ctx));
su_md5_init(&ctx);
su_md5_strupdate(&ctx, input2);
su_md5_hexdigest(&ctx, bigdigest);
su_md5_deinit(&ctx);
if (!strcasecmp(bigdigest, response)) {
ret = AUTH_OK;
} else {
if ((profile->ndlb & PFLAG_NDLB_BROKEN_AUTH_HASH) && strcasecmp(regstr, "REGISTER") && strcasecmp(regstr, "INVITE")) {
/* some clients send an ACK with the method 'INVITE' in the hash which will break auth so we will
try again with INVITE so we don't get people complaining to us when someone else's client has a bug......
*/
switch_safe_free(input);
switch_safe_free(input2);
regstr = "INVITE";
goto for_the_sake_of_interop;
}
if (!strcasecmp(bigdigest, response)) {
ret = AUTH_OK;
} else {
if ((profile->ndlb & PFLAG_NDLB_BROKEN_AUTH_HASH) && strcasecmp(regstr, "REGISTER") && strcasecmp(regstr, "INVITE")) {
/* some clients send an ACK with the method 'INVITE' in the hash which will break auth so we will
try again with INVITE so we don't get people complaining to us when someone else's client has a bug......
*/
switch_safe_free(input);
switch_safe_free(input2);
regstr = "INVITE";
goto for_the_sake_of_interop;
}
ret = AUTH_FORBIDDEN;
}
ret = AUTH_FORBIDDEN;
}
skip_auth:
skip_auth:
if (first && ret == AUTH_OK) {
if (v_event) {
@@ -1223,7 +1177,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "mailbox", "%s", mailbox);
switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "user_name", "%s", username);
switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "domain_name", "%s", realm);
if ((dparams = switch_xml_child(domain, "variables"))) {
xparams[i++] = dparams;
}
@@ -1243,7 +1197,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
if (!switch_strlen_zero(var) && !switch_strlen_zero(val)) {
switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, var, "%s", val);
if (!strcasecmp(var, "register-gateway")) {
if (!strcasecmp(val, "all")) {
switch_xml_t gateways_tag, gateway_tag;
@@ -1253,7 +1207,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
if (switch_strlen_zero(name)) {
name = "anonymous";
}
if ((gateway_ptr = sofia_reg_find_gateway(name))) {
gateway_ptr->retry = 0;
if (exptime) {
@@ -1263,7 +1217,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
}
sofia_reg_release_gateway(gateway_ptr);
}
}
}
} else {
@@ -1272,11 +1226,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
mydata = strdup(val);
switch_assert(mydata != NULL);
argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
for (x = 0; x < argc; x++) {
if ((gateway_ptr = sofia_reg_find_gateway((char *)argv[x]))) {
if ((gateway_ptr = sofia_reg_find_gateway((char *) argv[x]))) {
gateway_ptr->retry = 0;
if (exptime) {
gateway_ptr->state = REG_STATE_UNREGED;
@@ -1298,7 +1252,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
}
}
}
end:
end:
switch_event_destroy(&params);
@@ -1329,7 +1283,7 @@ sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, in
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if ((gateway = (sofia_gateway_t *) switch_core_hash_find(mod_sofia_globals.gateway_hash, key))) {
if (!(gateway->profile->pflags & PFLAG_RUNNING)) {
gateway = NULL;
gateway = NULL;
goto done;
}
if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
@@ -1343,7 +1297,7 @@ sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, in
#endif
}
done:
done:
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
return gateway;
}