clean up indenting in sofia

This commit is contained in:
Anthony Minessale 2010-06-23 13:22:52 -05:00
parent 39f6c58557
commit 0bff1a411b
3 changed files with 274 additions and 319 deletions

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
echo -n "-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l155 -cs -T size_t " > ./.indent.pro echo -n "-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l155 -cs -T size_t " > ./.indent.pro
grep "typedef struct.*_t;" `find ./src/include/ -name \*.h` | grep apr_ | grep -v "\*\|{" | sed -e s/struct// | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> ./.indent.pro
grep "typedef struct.*_t;" `find ./src/include/ -name \*.h` | grep switch_ | grep -v "\*\|{" | sed -e s/struct// | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> ./.indent.pro for i in `find src/ -name \*.c` ; do cat $i | perl -ne 'print "-T $1 " if (/([0-9A-Za-z_-]+_t)/)' ; done | sort | uniq >> ./.indent.pro
grep "} switch_" ./src/include/*.h | perl -ne '@l = split; $l[1] =~ s/;//g ; print " -T $l[1] "' >> ./.indent.pro for i in `find src/ -name \*.h` ; do cat $i | perl -ne 'print "-T $1 " if (/([0-9A-Za-z_-]+_t)/)' ; done | sort | uniq >> ./.indent.pro

View File

@ -109,7 +109,9 @@ static switch_status_t sofia_on_init(switch_core_session_t *session)
if (!sofia_test_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE)) { if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE)) {
switch_channel_set_state(channel, CS_RESET);
} else {
if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) { if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) {
switch_channel_set_state(channel, CS_EXECUTE); switch_channel_set_state(channel, CS_EXECUTE);
} else { } else {
@ -119,7 +121,7 @@ static switch_status_t sofia_on_init(switch_core_session_t *session)
} }
} }
end: end:
switch_mutex_unlock(tech_pvt->sofia_mutex); switch_mutex_unlock(tech_pvt->sofia_mutex);
@ -168,7 +170,10 @@ static switch_status_t sofia_on_reset(switch_core_session_t *session)
int x = 0; int x = 0;
if (other_uuid) { if (other_uuid) {
for(x = 0; other_session == NULL && x < 5; x++) { for (x = 0; other_session == NULL && x < 20; x++) {
if (!switch_channel_up(channel)) {
break;
}
other_session = switch_core_session_locate(other_uuid); other_session = switch_core_session_locate(other_uuid);
switch_yield(100000); switch_yield(100000);
} }
@ -178,10 +183,7 @@ static switch_status_t sofia_on_reset(switch_core_session_t *session)
switch_channel_t *other_channel = switch_core_session_get_channel(other_session); switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
switch_channel_clear_flag(channel, CF_BRIDGE_ORIGINATOR); switch_channel_clear_flag(channel, CF_BRIDGE_ORIGINATOR);
switch_channel_wait_for_state_timeout(other_channel, CS_RESET, 5000); switch_channel_wait_for_state_timeout(other_channel, CS_RESET, 5000);
switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL); switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 2000, NULL);
switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
if (switch_channel_test_flag(channel, CF_PROXY_MODE) && switch_channel_test_flag(other_channel, CF_PROXY_MODE)) { if (switch_channel_test_flag(channel, CF_PROXY_MODE) && switch_channel_test_flag(other_channel, CF_PROXY_MODE)) {
switch_ivr_signal_bridge(session, other_session); switch_ivr_signal_bridge(session, other_session);
@ -905,7 +907,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
if (switch_event_create(&event, SWITCH_EVENT_RECV_RTCP_MESSAGE) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_RECV_RTCP_MESSAGE) == SWITCH_STATUS_SUCCESS) {
char buf[30]; char buf[30];
char* uuid = switch_core_session_get_uuid(session); char *uuid = switch_core_session_get_uuid(session);
if (uuid) { if (uuid) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session)); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session));
} }
@ -922,10 +924,10 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
snprintf(buf, sizeof(buf), "%u", rtcp_frame.timestamp); snprintf(buf, sizeof(buf), "%u", rtcp_frame.timestamp);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Timestamp", buf); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Timestamp", buf);
snprintf(buf, sizeof(buf), "%u", rtcp_frame.packet_count); snprintf(buf, sizeof(buf), "%u", rtcp_frame.packet_count);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sender-Packet-Count", buf); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sender-Packet-Count", buf);
snprintf(buf, sizeof(buf), "%u", rtcp_frame.octect_count); snprintf(buf, sizeof(buf), "%u", rtcp_frame.octect_count);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Octect-Packet-Count", buf); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Octect-Packet-Count", buf);
snprintf(buf, sizeof(buf), "%" SWITCH_SIZE_T_FMT, tech_pvt->read_frame.timestamp); snprintf(buf, sizeof(buf), "%" SWITCH_SIZE_T_FMT, tech_pvt->read_frame.timestamp);
@ -1017,8 +1019,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
"ShoreTel\n" "ShoreTel\n"
"Sonus/L3\n" "Sonus/L3\n"
"We will try to fix it but some of the devices on this list are so broken,\n" "We will try to fix it but some of the devices on this list are so broken,\n"
"who knows what will happen..\n", "who knows what will happen..\n", (int) tech_pvt->codec_ms, (int) codec_ms);
(int) tech_pvt->codec_ms, (int) codec_ms);
switch_channel_set_variable_printf(channel, "sip_h_X-Broken-PTIME", "Adv=%d;Sent=%d", switch_channel_set_variable_printf(channel, "sip_h_X-Broken-PTIME", "Adv=%d;Sent=%d",
(int) tech_pvt->codec_ms, (int) codec_ms); (int) tech_pvt->codec_ms, (int) codec_ms);
@ -1090,7 +1091,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
tech_pvt->mismatch_count = 0; tech_pvt->mismatch_count = 0;
tech_pvt->last_ts = 0; tech_pvt->last_ts = 0;
} }
skip: skip:
if ((bytes = tech_pvt->read_impl.encoded_bytes_per_packet)) { if ((bytes = tech_pvt->read_impl.encoded_bytes_per_packet)) {
frames = (tech_pvt->read_frame.datalen / bytes); frames = (tech_pvt->read_frame.datalen / bytes);
@ -1570,8 +1571,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")), SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), 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), SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
TAG_END());
} else { } else {
nua_respond(tech_pvt->nh, SIP_200_OK, nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_AUTOANSWER(0), NUTAG_AUTOANSWER(0),
@ -1579,9 +1579,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
SIPTAG_CONTACT_STR(tech_pvt->reply_contact), SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")), SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")),
SIPTAG_CONTENT_TYPE_STR("application/sdp"), SIPTAG_CONTENT_TYPE_STR("application/sdp"),
SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_END());
} }
switch_safe_free(extra_headers); switch_safe_free(extra_headers);
sofia_set_flag_locked(tech_pvt, TFLAG_ANS); sofia_set_flag_locked(tech_pvt, TFLAG_ANS);
@ -1825,7 +1823,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
argc = switch_split(mydata, ',', argv); argc = switch_split(mydata, ',', argv);
for(i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
if (!strchr(argv[i], '<') && !strchr(argv[i], '>')) { if (!strchr(argv[i], '<') && !strchr(argv[i], '>')) {
if (i == argc - 1) { if (i == argc - 1) {
switch_snprintf(newdest + strlen(newdest), len - strlen(newdest), "\"unknown\" <%s>", argv[i]); switch_snprintf(newdest + strlen(newdest), len - strlen(newdest), "\"unknown\" <%s>", argv[i]);
@ -2199,7 +2197,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
break; break;
} }
end_lock: end_lock:
//if (msg->message_id == SWITCH_MESSAGE_INDICATE_ANSWER || msg->message_id == SWITCH_MESSAGE_INDICATE_PROGRESS) { //if (msg->message_id == SWITCH_MESSAGE_INDICATE_ANSWER || msg->message_id == SWITCH_MESSAGE_INDICATE_PROGRESS) {
//sofia_send_callee_id(session, NULL, NULL); //sofia_send_callee_id(session, NULL, NULL);
@ -2207,7 +2205,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_mutex_unlock(tech_pvt->sofia_mutex); switch_mutex_unlock(tech_pvt->sofia_mutex);
end: end:
if (switch_channel_down(channel) || !tech_pvt || sofia_test_flag(tech_pvt, TFLAG_BYE)) { if (switch_channel_down(channel) || !tech_pvt || sofia_test_flag(tech_pvt, TFLAG_BYE)) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
@ -2263,9 +2261,9 @@ const char *sofia_state_string(int state)
} }
struct cb_helper_sql2str { struct cb_helper_sql2str {
char *buf; char *buf;
size_t len; size_t len;
int matches; int matches;
}; };
struct cb_helper { struct cb_helper {
@ -2335,19 +2333,21 @@ static int show_reg_callback_xml(void *pArg, int argc, char **argv, char **colum
switch_strftime_nocheck(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm); switch_strftime_nocheck(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
} }
cb->stream->write_function(cb->stream," <registration>\n"); cb->stream->write_function(cb->stream, " <registration>\n");
cb->stream->write_function(cb->stream," <call-id>%s</call-id>\n", switch_str_nil(argv[0])); cb->stream->write_function(cb->stream, " <call-id>%s</call-id>\n", switch_str_nil(argv[0]));
cb->stream->write_function(cb->stream," <user>%s@%s</user>\n", switch_str_nil(argv[1]), switch_str_nil(argv[2])); cb->stream->write_function(cb->stream, " <user>%s@%s</user>\n", switch_str_nil(argv[1]), switch_str_nil(argv[2]));
cb->stream->write_function(cb->stream," <contact>%s</contact>\n", switch_amp_encode(switch_str_nil(argv[3]), xmlbuf, buflen)); cb->stream->write_function(cb->stream, " <contact>%s</contact>\n", switch_amp_encode(switch_str_nil(argv[3]), xmlbuf, buflen));
cb->stream->write_function(cb->stream," <agent>%s</agent>\n", switch_str_nil(argv[7])); cb->stream->write_function(cb->stream, " <agent>%s</agent>\n", switch_str_nil(argv[7]));
cb->stream->write_function(cb->stream," <status>%s(%s) exp(%s) expsecs(%d)</status>\n", switch_str_nil(argv[4]), switch_str_nil(argv[5]), exp_buf, exp_secs); cb->stream->write_function(cb->stream, " <status>%s(%s) exp(%s) expsecs(%d)</status>\n", switch_str_nil(argv[4]), switch_str_nil(argv[5]),
cb->stream->write_function(cb->stream," <host>%s</host>\n", switch_str_nil(argv[11])); exp_buf, exp_secs);
cb->stream->write_function(cb->stream," <network-ip>%s</network-ip>\n", switch_str_nil(argv[12])); cb->stream->write_function(cb->stream, " <host>%s</host>\n", switch_str_nil(argv[11]));
cb->stream->write_function(cb->stream," <network-port>%s</network-port>\n", switch_str_nil(argv[13])); cb->stream->write_function(cb->stream, " <network-ip>%s</network-ip>\n", switch_str_nil(argv[12]));
cb->stream->write_function(cb->stream," <sip-auth-user>%s</sip-auth-user>\n", switch_url_encode(switch_str_nil(argv[14]), xmlbuf, sizeof(xmlbuf))); cb->stream->write_function(cb->stream, " <network-port>%s</network-port>\n", switch_str_nil(argv[13]));
cb->stream->write_function(cb->stream," <sip-auth-realm>%s</sip-auth-realm>\n", switch_str_nil(argv[15])); cb->stream->write_function(cb->stream, " <sip-auth-user>%s</sip-auth-user>\n",
cb->stream->write_function(cb->stream," <mwi-account>%s@%s</mwi-account>\n", switch_str_nil(argv[16]), switch_str_nil(argv[17])); switch_url_encode(switch_str_nil(argv[14]), xmlbuf, sizeof(xmlbuf)));
cb->stream->write_function(cb->stream," </registration>\n"); cb->stream->write_function(cb->stream, " <sip-auth-realm>%s</sip-auth-realm>\n", switch_str_nil(argv[15]));
cb->stream->write_function(cb->stream, " <mwi-account>%s@%s</mwi-account>\n", switch_str_nil(argv[16]), switch_str_nil(argv[17]));
cb->stream->write_function(cb->stream, " </registration>\n");
return 0; return 0;
} }
@ -2368,7 +2368,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
if (argc > 0) { if (argc > 0) {
if (argc == 1) { if (argc == 1) {
/* show summary of all gateways*/ /* show summary of all gateways */
uint32_t ib_failed = 0; uint32_t ib_failed = 0;
uint32_t ib = 0; uint32_t ib = 0;
@ -2383,7 +2383,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
profile = (sofia_profile_t *) val; profile = (sofia_profile_t *) val;
if (sofia_test_pflag(profile, PFLAG_RUNNING)) { if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
if (!strcmp(vvar, profile->name)) { /* not an alias */ if (!strcmp(vvar, profile->name)) { /* not an alias */
for (gp = profile->gateways; gp; gp = gp->next) { for (gp = profile->gateways; gp; gp = gp->next) {
char *pkey = switch_mprintf("%s::%s", profile->name, gp->name); char *pkey = switch_mprintf("%s::%s", profile->name, gp->name);
@ -2396,8 +2396,8 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
ob += gp->ob_calls; ob += gp->ob_calls;
stream->write_function(stream, "%25s\t%32s\t%s\t%ld/%ld\t%ld/%ld", stream->write_function(stream, "%25s\t%32s\t%s\t%ld/%ld\t%ld/%ld",
pkey, gp->register_to, sofia_state_names[gp->state], pkey, gp->register_to, sofia_state_names[gp->state],
gp->ib_failed_calls, gp->ib_calls, gp->ob_failed_calls, gp->ob_calls); gp->ib_failed_calls, gp->ib_calls, gp->ob_failed_calls, gp->ob_calls);
if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) { if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
time_t now = switch_epoch_time_now(NULL); time_t now = switch_epoch_time_now(NULL);
@ -2415,8 +2415,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
switch_mutex_unlock(mod_sofia_globals.hash_mutex); switch_mutex_unlock(mod_sofia_globals.hash_mutex);
stream->write_function(stream, "%s\n", line); stream->write_function(stream, "%s\n", line);
stream->write_function(stream, "%d gateway%s: Inound(Failed/Total): %ld/%ld," stream->write_function(stream, "%d gateway%s: Inound(Failed/Total): %ld/%ld,"
"Outbound(Failed/Total):%ld/%ld\n", c, c == 1 ? "" : "s", "Outbound(Failed/Total):%ld/%ld\n", c, c == 1 ? "" : "s", ib_failed, ib, ob_failed, ob);
ib_failed, ib, ob_failed, ob);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -2457,7 +2456,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
} else if (!strcasecmp(argv[0], "profile")) { } else if (!strcasecmp(argv[0], "profile")) {
struct cb_helper cb; struct cb_helper cb;
char *sql = NULL; char *sql = NULL;
int x = 0 ; int x = 0;
cb.row_process = 0; cb.row_process = 0;
@ -2625,8 +2624,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
switch_assert(gp->state < REG_STATE_LAST); switch_assert(gp->state < REG_STATE_LAST);
stream->write_function(stream, "%25s\t%s\t %40s\t%s", stream->write_function(stream, "%25s\t%s\t %40s\t%s", pkey, "gateway", gp->register_to, sofia_state_names[gp->state]);
pkey, "gateway", gp->register_to, sofia_state_names[gp->state]);
free(pkey); free(pkey);
if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) { if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
@ -2663,45 +2661,45 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl
if (argc > 0) { if (argc > 0) {
if (argc == 1) { if (argc == 1) {
/* show summary of all gateways */ /* show summary of all gateways */
stream->write_function(stream, "%s\n", header); stream->write_function(stream, "%s\n", header);
stream->write_function(stream, "<gateways>\n", header); stream->write_function(stream, "<gateways>\n", header);
switch_mutex_lock(mod_sofia_globals.hash_mutex); 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)) { for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &vvar, NULL, &val); switch_hash_this(hi, &vvar, NULL, &val);
profile = (sofia_profile_t *) val; profile = (sofia_profile_t *) val;
if (sofia_test_pflag(profile, PFLAG_RUNNING)) { if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
if (!strcmp(vvar, profile->name)) { /* not an alias */ if (!strcmp(vvar, profile->name)) { /* not an alias */
for (gp = profile->gateways; gp; gp = gp->next) { for (gp = profile->gateways; gp; gp = gp->next) {
switch_assert(gp->state < REG_STATE_LAST); switch_assert(gp->state < REG_STATE_LAST);
stream->write_function(stream, "\t<gateway>\n"); stream->write_function(stream, "\t<gateway>\n");
stream->write_function(stream, "\t\t<profile>%s</profile>\n", profile->name); stream->write_function(stream, "\t\t<profile>%s</profile>\n", profile->name);
stream->write_function(stream, "\t\t<to>%s</to>\n", gp->register_to); stream->write_function(stream, "\t\t<to>%s</to>\n", gp->register_to);
stream->write_function(stream, "\t\t<state>%s</state>\n", sofia_state_names[gp->state]); stream->write_function(stream, "\t\t<state>%s</state>\n", sofia_state_names[gp->state]);
stream->write_function(stream, "\t\t<calls-in>%ld</calls-in>\n", gp->ib_calls); stream->write_function(stream, "\t\t<calls-in>%ld</calls-in>\n", gp->ib_calls);
stream->write_function(stream, "\t\t<calls-out>%ld</calls-out>\n", gp->ob_calls); stream->write_function(stream, "\t\t<calls-out>%ld</calls-out>\n", gp->ob_calls);
stream->write_function(stream, "\t\t<failed-calls-in>%ld</failed-calls-in>\n", gp->ib_failed_calls); stream->write_function(stream, "\t\t<failed-calls-in>%ld</failed-calls-in>\n", gp->ib_failed_calls);
stream->write_function(stream, "\t\t<failed-calls-out>%ld</failed-calls-out>\n", gp->ob_failed_calls); stream->write_function(stream, "\t\t<failed-calls-out>%ld</failed-calls-out>\n", gp->ob_failed_calls);
if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) { if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
time_t now = switch_epoch_time_now(NULL); time_t now = switch_epoch_time_now(NULL);
if (gp->retry > now) { if (gp->retry > now) {
stream->write_function(stream, "\t\t<retry>%ds</retry>\n", gp->retry - now); stream->write_function(stream, "\t\t<retry>%ds</retry>\n", gp->retry - now);
} else { } else {
stream->write_function(stream, "\t\t<retry>NEVER</retry>\n"); stream->write_function(stream, "\t\t<retry>NEVER</retry>\n");
} }
} }
stream->write_function(stream, "\t</gateway>\n"); stream->write_function(stream, "\t</gateway>\n");
} }
} }
} }
} }
switch_mutex_unlock(mod_sofia_globals.hash_mutex); switch_mutex_unlock(mod_sofia_globals.hash_mutex);
stream->write_function(stream, "</gateways>\n"); stream->write_function(stream, "</gateways>\n");
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -3150,7 +3148,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
stream->write_function(stream, "-ERR Unknown command!\n"); stream->write_function(stream, "-ERR Unknown command!\n");
done: done:
if (profile) { if (profile) {
sofia_glue_release_profile(profile); sofia_glue_release_profile(profile);
} }
@ -3174,14 +3172,15 @@ static int contact_callback(void *pArg, int argc, char **argv, char **columnName
} }
static int sql2str_callback(void *pArg, int argc, char **argv, char **columnNames) static int sql2str_callback(void *pArg, int argc, char **argv, char **columnNames)
{ {
struct cb_helper_sql2str *cbt = (struct cb_helper_sql2str *) pArg; struct cb_helper_sql2str *cbt = (struct cb_helper_sql2str *) pArg;
switch_copy_string(cbt->buf, argv[0], cbt->len); switch_copy_string(cbt->buf, argv[0], cbt->len);
cbt->matches++; cbt->matches++;
return 0; return 0;
} }
SWITCH_STANDARD_API(sofia_count_reg_function) { SWITCH_STANDARD_API(sofia_count_reg_function)
{
char *data; char *data;
char *user = NULL; char *user = NULL;
char *domain = NULL; char *domain = NULL;
@ -3209,13 +3208,12 @@ SWITCH_STANDARD_API(sofia_count_reg_function) {
if ((domain = strchr(user, '@'))) { if ((domain = strchr(user, '@'))) {
*domain++ = '\0'; *domain++ = '\0';
if ( (concat = strchr( domain, '/')) ) { if ((concat = strchr(domain, '/'))) {
*concat++ = '\0'; *concat++ = '\0';
} }
} } else {
else { if ((concat = strchr(user, '/'))) {
if ( (concat = strchr( user, '/')) ) { *concat++ = '\0';
*concat++ = '\0';
} }
} }
@ -3248,13 +3246,13 @@ SWITCH_STANDARD_API(sofia_count_reg_function) {
if (zstr(user)) { if (zstr(user)) {
sql = switch_mprintf("select count(*) " sql = switch_mprintf("select count(*) "
"from sip_registrations where (sip_host='%q' or presence_hosts like '%%%q%%')", "from sip_registrations where (sip_host='%q' or presence_hosts like '%%%q%%')",
( concat != NULL ) ? concat : "", domain, domain); (concat != NULL) ? concat : "", domain, domain);
} else { } else {
sql = switch_mprintf("select count(*) " sql = switch_mprintf("select count(*) "
"from sip_registrations where (sip_user='%q' or dir_user='%q') and (sip_host='%q' or presence_hosts like '%%%q%%')", "from sip_registrations where (sip_user='%q' or dir_user='%q') and (sip_host='%q' or presence_hosts like '%%%q%%')",
( concat != NULL ) ? concat : "", user, user, domain, domain); (concat != NULL) ? concat : "", user, user, domain, domain);
} }
switch_assert(sql); switch_assert(sql);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sql2str_callback, &cb); sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sql2str_callback, &cb);
@ -3281,6 +3279,7 @@ SWITCH_STANDARD_API(sofia_count_reg_function) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_STANDARD_API(sofia_contact_function) SWITCH_STANDARD_API(sofia_contact_function)
{ {
char *data; char *data;
@ -3447,7 +3446,7 @@ SWITCH_STANDARD_API(sofia_gateway_data_function)
sofia_reg_release_gateway(gateway); sofia_reg_release_gateway(gateway);
end: end:
switch_safe_free(mydata); switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -3464,11 +3463,11 @@ SWITCH_STANDARD_API(sofia_function)
"--------------------------------------------------------------------------------\n" "--------------------------------------------------------------------------------\n"
"sofia help\n" "sofia help\n"
"sofia profile <profile_name> [[start|stop|restart|rescan] [reloadxml]|" "sofia profile <profile_name> [[start|stop|restart|rescan] [reloadxml]|"
"flush_inbound_reg [<call_id>] [reboot]|" "flush_inbound_reg [<call_id>] [reboot]|"
"[register|unregister] [<gateway name>|all]|" "[register|unregister] [<gateway name>|all]|"
"killgw <gateway name>|" "killgw <gateway name>|"
"[stun-auto-disable|stun-enabled] [true|false]]|" "[stun-auto-disable|stun-enabled] [true|false]]|"
"siptrace [on|off]\n" "siptrace [on|off]\n"
"sofia status|xmlstatus profile <name> [ reg <contact str> ] | [ pres <pres str> ] | [ user <user@domain> ]\n" "sofia status|xmlstatus profile <name> [ reg <contact str> ] | [ pres <pres str> ] | [ user <user@domain> ]\n"
"sofia status|xmlstatus gateway <name>\n" "sofia status|xmlstatus gateway <name>\n"
"sofia loglevel <all|default|tport|iptsec|nea|nta|nth_client|nth_server|nua|soa|sresolv|stun> [0-9]\n" "sofia loglevel <all|default|tport|iptsec|nea|nta|nth_client|nth_server|nua|soa|sresolv|stun> [0-9]\n"
@ -3550,7 +3549,7 @@ SWITCH_STANDARD_API(sofia_function)
stream->write_function(stream, "Unknown Command [%s]\n", argv[0]); stream->write_function(stream, "Unknown Command [%s]\n", argv[0]);
} }
done: done:
switch_safe_free(mycmd); switch_safe_free(mycmd);
return status; return status;
} }
@ -3937,7 +3936,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (switch_core_session_compare(session, nsession)) { if (switch_core_session_compare(session, nsession)) {
/* It's another sofia channel! so lets cache what they use as a pt for telephone event so /* It's another sofia channel! so lets cache what they use as a pt for telephone event so
we can keep it the same we can keep it the same
*/ */
private_object_t *ctech_pvt; private_object_t *ctech_pvt;
ctech_pvt = switch_core_session_get_private(session); ctech_pvt = switch_core_session_get_private(session);
switch_assert(ctech_pvt != NULL); switch_assert(ctech_pvt != NULL);
@ -3970,14 +3969,14 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
goto done; goto done;
error: error:
if (nsession) { if (nsession) {
switch_core_session_destroy(&nsession); switch_core_session_destroy(&nsession);
} }
if (pool) { if (pool) {
*pool = NULL; *pool = NULL;
} }
done: done:
if (profile) { if (profile) {
if (cause == SWITCH_CAUSE_SUCCESS) { if (cause == SWITCH_CAUSE_SUCCESS) {
@ -4131,12 +4130,12 @@ static void general_event_handler(switch_event_t *event)
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' " sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
"from sip_registrations where mwi_user='%s' and mwi_host='%q'", "from sip_registrations where mwi_user='%s' and mwi_host='%q'",
ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host) ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
); );
} else { } else {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' " sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
"from sip_registrations where sip_user='%s' and sip_host='%q'", "from sip_registrations where sip_user='%s' and sip_host='%q'",
ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host) ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
); );
} }
} }
@ -4192,9 +4191,7 @@ static void general_event_handler(switch_event_t *event)
NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(profile->url), TAG_END()); NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(profile->url), TAG_END());
nua_message(nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR(ct), nua_message(nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR(ct),
TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_IF(!zstr(subject), SIPTAG_SUBJECT_STR(subject)), TAG_END());
TAG_IF(!zstr(subject), SIPTAG_SUBJECT_STR(subject)),
TAG_END());
free(id); free(id);
@ -4292,7 +4289,7 @@ static void general_event_handler(switch_event_t *event)
sofia_glue_release_profile(profile); sofia_glue_release_profile(profile);
} }
done: done:
switch_safe_free(local_dup); switch_safe_free(local_dup);
@ -4456,7 +4453,7 @@ static switch_status_t list_profile_gateway(const char *line, const char *cursor
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} }
end: end:
switch_safe_free(dup); switch_safe_free(dup);

View File

@ -85,17 +85,7 @@ void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *
switch_snprintf(buf, sizeof(buf), switch_snprintf(buf, sizeof(buf),
"v=0\n" "v=0\n"
"o=%s %010u %010u IN %s %s\n" "o=%s %010u %010u IN %s %s\n"
"s=%s\n" "s=%s\n" "c=IN %s %s\n" "t=0 0\n", username, tech_pvt->owner_id, tech_pvt->session_id, family, ip, username, family, ip);
"c=IN %s %s\n"
"t=0 0\n",
username,
tech_pvt->owner_id,
tech_pvt->session_id,
family,
ip,
username,
family,
ip);
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
@ -118,15 +108,12 @@ void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *
t38_options->T38FaxTranscodingJBIG ? "a=T38FaxTranscodingJBIG\n" : "", t38_options->T38FaxTranscodingJBIG ? "a=T38FaxTranscodingJBIG\n" : "",
t38_options->T38FaxRateManagement, t38_options->T38FaxRateManagement,
t38_options->T38FaxMaxBuffer, t38_options->T38FaxMaxBuffer,
t38_options->T38FaxMaxDatagram, t38_options->T38FaxMaxDatagram, t38_options->T38FaxUdpEC, t38_options->T38VendorInfo ? t38_options->T38VendorInfo : "0 0 0");
t38_options->T38FaxUdpEC,
t38_options->T38VendorInfo ? t38_options->T38VendorInfo : "0 0 0");
if (insist) { if (insist) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "m=audio 0 RTP/AVP 19\n");
"m=audio 0 RTP/AVP 19\n");
} }
sofia_glue_tech_set_local_sdp(tech_pvt, buf, SWITCH_TRUE); sofia_glue_tech_set_local_sdp(tech_pvt, buf, SWITCH_TRUE);
@ -196,7 +183,7 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32
if (!sr) { if (!sr) {
if ((var_val = switch_channel_get_variable(tech_pvt->channel, "media_audio_mode"))) { if ((var_val = switch_channel_get_variable(tech_pvt->channel, "media_audio_mode"))) {
sr=var_val; sr = var_val;
} else { } else {
sr = "sendrecv"; sr = "sendrecv";
} }
@ -522,7 +509,7 @@ void sofia_glue_tech_prepare_codecs(private_object_t *tech_pvt)
} }
} }
ready: ready:
if (codec_string) { if (codec_string) {
char *tmp_codec_string; char *tmp_codec_string;
@ -707,7 +694,7 @@ switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, private_
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} }
out: out:
switch_safe_free(stun_ip); switch_safe_free(stun_ip);
@ -731,7 +718,7 @@ const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name)
switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt, int force) switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt, int force)
{ {
char *lookup_rtpip = tech_pvt->rtpip; /* Pointer to externally looked up address */ char *lookup_rtpip = tech_pvt->rtpip; /* Pointer to externally looked up address */
switch_port_t sdp_port, rtcp_port; /* The external port to be sent in the SDP */ switch_port_t sdp_port, rtcp_port; /* The external port to be sent in the SDP */
const char *use_ip = NULL; /* The external IP to be sent in the SDP */ const char *use_ip = NULL; /* The external IP to be sent in the SDP */
/* Don't do anything if we're in proxy mode or if a (remote) port already has been found */ /* Don't do anything if we're in proxy mode or if a (remote) port already has been found */
@ -914,7 +901,7 @@ sofia_transport_t sofia_glue_url2transport(const url_t *url)
return (tls) ? SOFIA_TRANSPORT_TCP_TLS : SOFIA_TRANSPORT_UDP; return (tls) ? SOFIA_TRANSPORT_TCP_TLS : SOFIA_TRANSPORT_UDP;
} }
sofia_transport_t sofia_glue_via2transport(const sip_via_t *via) sofia_transport_t sofia_glue_via2transport(const sip_via_t * via)
{ {
char *ptr = NULL; char *ptr = NULL;
@ -1168,7 +1155,7 @@ switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt)
switch_channel_set_flag(tech_pvt->channel, CF_VIDEO); switch_channel_set_flag(tech_pvt->channel, CF_VIDEO);
if (switch_rtp_ready(tech_pvt->video_rtp_session)) { if (switch_rtp_ready(tech_pvt->video_rtp_session)) {
const char *rport = NULL; const char *rport = NULL;
switch_port_t remote_rtcp_port = 0; switch_port_t remote_rtcp_port = 0;
if ((rport = switch_channel_get_variable(tech_pvt->channel, "sip_remote_video_rtcp_port"))) { if ((rport = switch_channel_get_variable(tech_pvt->channel, "sip_remote_video_rtcp_port"))) {
remote_rtcp_port = atoi(rport); remote_rtcp_port = atoi(rport);
@ -1333,11 +1320,7 @@ void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt)
snprintf(o_line, sizeof(o_line), "o=%s %010u %010u IN %s %s\n", snprintf(o_line, sizeof(o_line), "o=%s %010u %010u IN %s %s\n",
tech_pvt->profile->username, tech_pvt->profile->username, tech_pvt->owner_id, tech_pvt->session_id, family, tech_pvt->profile->sipip);
tech_pvt->owner_id,
tech_pvt->session_id,
family,
tech_pvt->profile->sipip);
strncpy(q, o_line, strlen(o_line)); strncpy(q, o_line, strlen(o_line));
q += strlen(o_line) - 1; q += strlen(o_line) - 1;
@ -1476,7 +1459,7 @@ void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt)
} }
end: end:
if (bad) { if (bad) {
return; return;
@ -1828,9 +1811,9 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
/* /*
Does the "genius" who wanted SIP to be "text-based" so it was "easier to read" even use it now, Does the "genius" who wanted SIP to be "text-based" so it was "easier to read" even use it now,
or did he just suggest it to make our lives miserable? or did he just suggest it to make our lives miserable?
*/ */
use_from_str = from_str; use_from_str = from_str;
if (!switch_stristr("sip:", use_from_str)) { if (!switch_stristr("sip:", use_from_str)) {
@ -2120,10 +2103,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
TAG_IF(cseq, SIPTAG_CSEQ(cseq)), TAG_IF(cseq, SIPTAG_CSEQ(cseq)),
NUTAG_MEDIA_ENABLE(0), NUTAG_MEDIA_ENABLE(0),
SIPTAG_CONTENT_TYPE_STR(mp_type ? mp_type : "application/sdp"), SIPTAG_CONTENT_TYPE_STR(mp_type ? mp_type : "application/sdp"),
SIPTAG_PAYLOAD_STR(mp ? mp : tech_pvt->local_sdp_str), SIPTAG_PAYLOAD_STR(mp ? mp : tech_pvt->local_sdp_str), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END());
TAG_IF(rep, SIPTAG_REPLACES_STR(rep)),
SOATAG_HOLD(holdstr),
TAG_END());
} }
sofia_glue_free_destination(dst); sofia_glue_free_destination(dst);
@ -2216,7 +2196,7 @@ void sofia_glue_tech_absorb_sdp(private_object_t *tech_pvt)
} }
#define add_stat(_i, _s) \ #define add_stat(_i, _s) \
switch_snprintf(var_name, sizeof(var_name), "rtp_%s_%s", switch_str_nil(prefix), _s) ; \ switch_snprintf(var_name, sizeof(var_name), "rtp_%s_%s", switch_str_nil(prefix), _s) ; \
switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_SIZE_T_FMT, _i); \ switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_SIZE_T_FMT, _i); \
switch_channel_set_variable(tech_pvt->channel, var_name, var_val) switch_channel_set_variable(tech_pvt->channel, var_name, var_val)
@ -2478,7 +2458,7 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
switch_rtp_set_default_payload(tech_pvt->rtp_session, tech_pvt->pt); switch_rtp_set_default_payload(tech_pvt->rtp_session, tech_pvt->pt);
} }
end: end:
if (resetting) { if (resetting) {
switch_core_session_unlock_codec_write(tech_pvt->session); switch_core_session_unlock_codec_write(tech_pvt->session);
switch_core_session_unlock_codec_read(tech_pvt->session); switch_core_session_unlock_codec_read(tech_pvt->session);
@ -2582,7 +2562,7 @@ switch_status_t sofia_glue_add_crypto(private_object_t *tech_pvt, const char *ke
} }
bad: bad:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Error!\n"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Error!\n");
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -2713,7 +2693,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
if (tech_pvt->rtp_session && sofia_test_flag(tech_pvt, TFLAG_REINVITE)) { if (tech_pvt->rtp_session && sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
const char *rport = NULL; const char *rport = NULL;
switch_port_t remote_rtcp_port = 0; switch_port_t remote_rtcp_port = 0;
sofia_clear_flag_locked(tech_pvt, TFLAG_REINVITE); sofia_clear_flag_locked(tech_pvt, TFLAG_REINVITE);
@ -2722,8 +2702,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
} }
if (switch_rtp_set_remote_address(tech_pvt->rtp_session, tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port, if (switch_rtp_set_remote_address(tech_pvt->rtp_session, tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port,
remote_rtcp_port, SWITCH_TRUE, &err) != remote_rtcp_port, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {
SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", err); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", err);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "AUDIO RTP CHANGING DEST TO: [%s:%d]\n", switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "AUDIO RTP CHANGING DEST TO: [%s:%d]\n",
@ -2857,7 +2836,8 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
} else { } else {
int interval = atoi(val); int interval = atoi(val);
if (interval < 100 || interval > 5000) { if (interval < 100 || interval > 5000) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Invalid rtcp interval spec [%d] must be between 100 and 5000\n", interval); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR,
"Invalid rtcp interval spec [%d] must be between 100 and 5000\n", interval);
} else { } else {
switch_rtp_activate_rtcp(tech_pvt->rtp_session, interval, remote_port); switch_rtp_activate_rtcp(tech_pvt->rtp_session, interval, remote_port);
} }
@ -2943,7 +2923,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, tech_pvt->remote_sdp_audio_ip); switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, tech_pvt->remote_sdp_audio_ip);
switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp); switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
video: video:
sofia_glue_check_video_codecs(tech_pvt); sofia_glue_check_video_codecs(tech_pvt);
if (sofia_test_flag(tech_pvt, TFLAG_VIDEO) && tech_pvt->video_rm_encoding && tech_pvt->remote_sdp_video_port) { if (sofia_test_flag(tech_pvt, TFLAG_VIDEO) && tech_pvt->video_rm_encoding && tech_pvt->remote_sdp_video_port) {
@ -3087,7 +3067,8 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
switch_channel_set_variable_printf(tech_pvt->channel, "rtp_use_video_ssrc", "%u", tech_pvt->ssrc); switch_channel_set_variable_printf(tech_pvt->channel, "rtp_use_video_ssrc", "%u", tech_pvt->ssrc);
if ((val = switch_channel_get_variable(tech_pvt->channel, "rtcp_audio_interval_msec")) || (val = tech_pvt->profile->rtcp_audio_interval_msec)) { if ((val = switch_channel_get_variable(tech_pvt->channel, "rtcp_audio_interval_msec"))
|| (val = tech_pvt->profile->rtcp_audio_interval_msec)) {
const char *rport = switch_channel_get_variable(tech_pvt->channel, "sip_remote_video_rtcp_port"); const char *rport = switch_channel_get_variable(tech_pvt->channel, "sip_remote_video_rtcp_port");
switch_port_t remote_port = 0; switch_port_t remote_port = 0;
if (rport) { if (rport) {
@ -3098,7 +3079,8 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
} else { } else {
int interval = atoi(val); int interval = atoi(val);
if (interval < 100 || interval > 5000) { if (interval < 100 || interval > 5000) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Invalid rtcp interval spec [%d] must be between 100 and 5000\n", interval); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR,
"Invalid rtcp interval spec [%d] must be between 100 and 5000\n", interval);
} else { } else {
switch_rtp_activate_rtcp(tech_pvt->rtp_session, interval, remote_port); switch_rtp_activate_rtcp(tech_pvt->rtp_session, interval, remote_port);
} }
@ -3121,12 +3103,12 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f
goto end; goto end;
} }
video_up: video_up:
sofia_set_flag(tech_pvt, TFLAG_IO); sofia_set_flag(tech_pvt, TFLAG_IO);
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
end: end:
sofia_glue_tech_track(tech_pvt->profile, tech_pvt->session); sofia_glue_tech_track(tech_pvt->profile, tech_pvt->session);
@ -3650,7 +3632,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
} }
/* do nothing here, mod_fax will trigger a response (if it's listening =/)*/ /* do nothing here, mod_fax will trigger a response (if it's listening =/) */
match = 1; match = 1;
goto done; goto done;
} else if (m->m_type == sdp_media_audio && m->m_port && !got_audio) { } else if (m->m_type == sdp_media_audio && m->m_port && !got_audio) {
@ -3751,7 +3733,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
break; break;
} }
greed: greed:
x = 0; x = 0;
if (tech_pvt->rm_encoding) { // && !sofia_test_flag(tech_pvt, TFLAG_REINVITE)) { if (tech_pvt->rm_encoding) { // && !sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
@ -3909,7 +3891,8 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
char tmp[80]; char tmp[80];
int num; int num;
switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second, codec_ms); switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second,
codec_ms);
prefs[0] = tmp; prefs[0] = tmp;
num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1); num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
@ -4050,9 +4033,10 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
} }
} }
done: done:
if (parser) sdp_parser_free(parser); if (parser)
sdp_parser_free(parser);
tech_pvt->cng_pt = cng_pt; tech_pvt->cng_pt = cng_pt;
sofia_set_flag_locked(tech_pvt, TFLAG_SDP); sofia_set_flag_locked(tech_pvt, TFLAG_SDP);
@ -4202,7 +4186,7 @@ sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, i
#endif #endif
} }
done: done:
switch_mutex_unlock(mod_sofia_globals.hash_mutex); switch_mutex_unlock(mod_sofia_globals.hash_mutex);
return profile; return profile;
@ -4335,26 +4319,6 @@ void sofia_glue_del_profile(sofia_profile_t *profile)
switch_mutex_unlock(mod_sofia_globals.hash_mutex); switch_mutex_unlock(mod_sofia_globals.hash_mutex);
} }
static int rebridge_callback(void *pArg, int argc, char **argv, char **columnNames)
{
char *uuid = argv[2];
switch_core_session_t *session;
if ((session = switch_core_session_locate(uuid))) {
switch_channel_t *channel = switch_core_session_get_channel(session);
private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE)) {
switch_channel_wait_for_state_timeout(channel, CS_INIT, 10000);
switch_channel_set_state(channel, CS_RESET);
}
switch_core_session_rwunlock(session);
}
return 0;
}
struct recover_helper { struct recover_helper {
sofia_profile_t *profile; sofia_profile_t *profile;
int total; int total;
@ -4411,7 +4375,7 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName
switch_channel_set_variable_printf(channel, "sip_invite_route_uri", "<sip:%s@%s:%s;lr>", switch_channel_set_variable_printf(channel, "sip_invite_route_uri", "<sip:%s@%s:%s;lr>",
switch_channel_get_variable(channel, "sip_from_user"), switch_channel_get_variable(channel, "sip_from_user"),
switch_channel_get_variable(channel, "sip_network_ip"), switch_channel_get_variable(channel, "sip_network_port") switch_channel_get_variable(channel, "sip_network_ip"), switch_channel_get_variable(channel, "sip_network_port")
); );
tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_from_uri")); tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_from_uri"));
@ -4444,7 +4408,7 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName
switch_channel_set_variable_printf(channel, "sip_route_uri", "sip:%s@%s:%s", switch_channel_set_variable_printf(channel, "sip_route_uri", "sip:%s@%s:%s",
switch_channel_get_variable(channel, "sip_req_user"), switch_channel_get_variable(channel, "sip_req_user"),
switch_channel_get_variable(channel, "sip_network_ip"), switch_channel_get_variable(channel, "sip_network_port") switch_channel_get_variable(channel, "sip_network_ip"), switch_channel_get_variable(channel, "sip_network_port")
); );
} }
if (session) { if (session) {
@ -4518,7 +4482,6 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName
tech_pvt->remote_sdp_video_ip = (char *) r_ip; tech_pvt->remote_sdp_video_ip = (char *) r_ip;
tech_pvt->remote_sdp_video_port = atoi(r_port); tech_pvt->remote_sdp_video_port = atoi(r_port);
} }
//sofia_glue_tech_set_video_codec(tech_pvt, 1); //sofia_glue_tech_set_video_codec(tech_pvt, 1);
} }
@ -4550,12 +4513,10 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName
} }
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Resurrecting fallen channel %s\n", switch_channel_get_name(channel));
switch_core_session_thread_launch(session);
} }
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Resurrecting fallen channel %s\n", switch_channel_get_name(channel));
switch_core_session_thread_launch(session);
switch_xml_free(xml); switch_xml_free(xml);
h->total++; h->total++;
@ -4600,13 +4561,6 @@ int sofia_glue_recover(switch_bool_t flush)
free(sql); free(sql);
sql = NULL; sql = NULL;
sql = switch_mprintf("select profile_name, hostname, uuid "
"from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, rebridge_callback, NULL);
free(sql);
sql = NULL;
sql = switch_mprintf("delete " sql = switch_mprintf("delete "
"from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name); "from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
@ -4716,7 +4670,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
" profile_name VARCHAR(255),\n" " profile_name VARCHAR(255),\n"
" hostname VARCHAR(255),\n" " hostname VARCHAR(255),\n"
" uuid VARCHAR(255),\n" " uuid VARCHAR(255),\n"
" metadata text\n" ");\n"; " metadata text\n"
");\n";
char pres_sql[] = char pres_sql[] =
"CREATE TABLE sip_presence (\n" "CREATE TABLE sip_presence (\n"
@ -4879,8 +4834,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
"or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' " "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' "
"and network_ip like '%%' and network_port like '%%' and sip_username " "and network_ip like '%%' and network_port like '%%' and sip_username "
"like '%%' and mwi_user like '%%' and mwi_host like '%%' " "like '%%' and mwi_user like '%%' and mwi_host like '%%' "
"and orig_server_host like '%%' and orig_hostname like '%%'", "and orig_server_host like '%%' and orig_hostname like '%%'", mod_sofia_globals.hostname);
mod_sofia_globals.hostname);
if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) {
switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_registrations", NULL, NULL); switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_registrations", NULL, NULL);
@ -4981,8 +4935,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
"or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' " "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' "
"and network_ip like '%%' and network_port like '%%' and sip_username " "and network_ip like '%%' and network_port like '%%' and sip_username "
"like '%%' and mwi_user like '%%' and mwi_host like '%%' " "like '%%' and mwi_user like '%%' and mwi_host like '%%' "
"and orig_server_host like '%%' and orig_hostname like '%%'", "and orig_server_host like '%%' and orig_hostname like '%%'", mod_sofia_globals.hostname);
mod_sofia_globals.hostname);
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_registrations", reg_sql); switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_registrations", reg_sql);
free(test_sql); free(test_sql);
@ -5010,7 +4963,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_shared_appearance_subscriptions", shared_appearance_sql); switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_shared_appearance_subscriptions", shared_appearance_sql);
free(test_sql); free(test_sql);
test_sql = switch_mprintf("delete from sip_shared_appearance_dialogs where contact_str = '' or hostname='%q' and network_ip like '%%'", mod_sofia_globals.hostname); test_sql =
switch_mprintf("delete from sip_shared_appearance_dialogs where contact_str = '' or hostname='%q' and network_ip like '%%'",
mod_sofia_globals.hostname);
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_shared_appearance_dialogs", shared_appearance_dialogs_sql); switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_shared_appearance_dialogs", shared_appearance_dialogs_sql);
free(test_sql); free(test_sql);
@ -5474,7 +5429,7 @@ void sofia_glue_tech_simplify(private_object_t *tech_pvt)
other_channel = switch_core_session_get_channel(other_session); other_channel = switch_core_session_get_channel(other_session);
if (switch_channel_test_flag(other_channel, CF_ANSWERED)) { /* Check if the other channel is answered */ if (switch_channel_test_flag(other_channel, CF_ANSWERED)) { /* Check if the other channel is answered */
simplify = switch_channel_get_variable(tech_pvt->channel, "sip_auto_simplify"); simplify = switch_channel_get_variable(tech_pvt->channel, "sip_auto_simplify");
simplify_other_channel = switch_channel_get_variable(other_channel, "sip_auto_simplify"); simplify_other_channel = switch_channel_get_variable(other_channel, "sip_auto_simplify");
@ -5491,12 +5446,13 @@ void sofia_glue_tech_simplify(private_object_t *tech_pvt)
} }
if (inbound_channel && inbound_session && !zstr(network_addr_a) && !zstr(network_addr_b) && !strcmp(network_addr_a, network_addr_b)) { if (inbound_channel && inbound_session && !zstr(network_addr_a) && !zstr(network_addr_b) && !strcmp(network_addr_a, network_addr_b)) {
if (strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->sipip)) && strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->extsipip))) { if (strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->sipip))
&& strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->extsipip))) {
switch_core_session_message_t *msg; switch_core_session_message_t *msg;
switch_log_printf(SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, switch_channel_get_uuid(inbound_channel), SWITCH_LOG_NOTICE, switch_log_printf(SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, switch_channel_get_uuid(inbound_channel),
"Will simplify channel [%s]\n", switch_channel_get_name(inbound_channel)); SWITCH_LOG_NOTICE, "Will simplify channel [%s]\n", switch_channel_get_name(inbound_channel));
msg = switch_core_session_alloc(inbound_session, sizeof(*msg)); msg = switch_core_session_alloc(inbound_session, sizeof(*msg));
MESSAGE_STAMP_FFL(msg); MESSAGE_STAMP_FFL(msg);
@ -5512,7 +5468,7 @@ void sofia_glue_tech_simplify(private_object_t *tech_pvt)
if (!did_simplify && inbound_channel) { if (!did_simplify && inbound_channel) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, switch_channel_get_uuid(inbound_channel), SWITCH_LOG_NOTICE, switch_log_printf(SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__, switch_channel_get_uuid(inbound_channel), SWITCH_LOG_NOTICE,
"Could not simplify channel [%s]\n", switch_channel_get_name(inbound_channel)); "Could not simplify channel [%s]\n", switch_channel_get_name(inbound_channel));
} }
} }