From 15d7706f8f548e6495bb961ae7396a625041657a Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 Aug 2014 18:41:58 -0400 Subject: [PATCH 01/20] clean up some injection issues in chat display --- html5/verto/demo/verto.js | 67 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/html5/verto/demo/verto.js b/html5/verto/demo/verto.js index 9e68674b9f..3935854ffb 100644 --- a/html5/verto/demo/verto.js +++ b/html5/verto/demo/verto.js @@ -76,6 +76,54 @@ function check_vid() { return use_vid; } +function messageTextToJQ(body) { + // Builds a jQuery collection from body text, linkifies http/https links, imageifies http/https links to images, and doesn't allow script injection + + var match, $link, img_url, $body_parts = $(), rx = /(https?:\/\/[^ \n\r]+|\n\r|\n|\r)/; + + while ((match = rx.exec(body)) !== null) { + if (match.index !== 0) { + $body_parts = $body_parts.add(document.createTextNode(body.substr(0, match.index))); + } + + if (match[0].match(/^(\n|\r|\n\r)$/)) { + // Make a BR from a newline + $body_parts = $body_parts.add($('
')); + body = body.substr(match.index + match[0].length); + } else { + // Make a link (or image) + $link = $('').attr('href', match[0]); + + if (match[0].search(/\.(gif|jpe?g|png)/) > -1) { + // Make an image + img_url = match[0]; + + // Handle dropbox links + if (img_url.indexOf('dropbox.com') !== -1) { + if (img_url.indexOf('?dl=1') === -1 && img_url.indexOf('?dl=0') === -1) { + img_url += '?dl=1'; + } else if (img_url.indexOf('?dl=0') !== -1) { + img_url = img_url.replace(/dl=0$/, 'dl=1'); + } + } + + $link.append($('').attr('src', img_url)); + } else { + // Make a link + $link.text(match[0]); + } + + body = body.substr(match.index + match[0].length); + $body_parts = $body_parts.add($link); + } + } + if (body) { + $body_parts = $body_parts.add(document.createTextNode(body)); + } + + return $body_parts; +} // END function messageTextToJQ + var callbacks = { onMessage: function(verto, dialog, msg, data) { @@ -114,6 +162,9 @@ var callbacks = { case $.verto.enum.message.info: var body = data.body; + /* + // This section has been replaced with messageTextToJQ function + if (body.match(/\.gif|\.jpg|\.jpeg|\.png/)) { var mod = ""; if (body.match(/dropbox.com/)) { @@ -129,11 +180,21 @@ var callbacks = { } body = body.replace(/(?:\r\n|\r|\n)/g, '
'); - var from = data.from_msg_name || data.from; - + var from = data.from_msg_name || data.from; + $("#chatwin").append("" + from + ":
" + body); $('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast"); - + */ + + var from = data.from_msg_name || data.from; + + $('#chatwin') + .append($('').text(from + ':')) + .append($('
')) + .append(messageTextToJQ(body)) + .append($('
')); + $('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast"); + break; case $.verto.enum.message.display: var party = dialog.params.remote_caller_id_name + "<" + dialog.params.remote_caller_id_number + ">"; From 0f1494ae06d8db3cd140b1b1da12bc0bf5d5d69d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Aug 2014 09:52:55 -0500 Subject: [PATCH 02/20] Improve conference recording --- .../mod_conference/mod_conference.c | 118 ++++++++---------- 1 file changed, 53 insertions(+), 65 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 4d2478ce7c..fbb1cd9036 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -3312,7 +3312,6 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v main_frame[x] = (int32_t) bptr[x]; } else { memset(&main_frame[x], 255, sizeof(main_frame[x])); - //printf("FUCCCK %d <= %ld (%ld/%d)\n", x, file_sample_len * conference->channels, file_sample_len, conference->channels); } } } @@ -3372,6 +3371,10 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v } if (!switch_test_flag(omember, MFLAG_CAN_HEAR)) { + switch_mutex_lock(omember->audio_out_mutex); + memset(write_frame, 255, bytes); + ok = switch_buffer_write(omember->mux_buffer, write_frame, bytes); + switch_mutex_unlock(omember->audio_out_mutex); continue; } @@ -3423,6 +3426,31 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v ok = switch_buffer_write(omember->mux_buffer, write_frame, bytes); switch_mutex_unlock(omember->audio_out_mutex); + if (!ok) { + switch_mutex_unlock(conference->mutex); + goto end; + } + } + } else { /* There is no source audio. Push silence into all of the buffers */ + int16_t write_frame[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 }; + + if (conference->comfort_noise_level) { + switch_generate_sln_silence(write_frame, samples, conference->channels, conference->comfort_noise_level); + } else { + memset(write_frame, 255, bytes); + } + + for (omember = conference->members; omember; omember = omember->next) { + switch_size_t ok = 1; + + if (!switch_test_flag(omember, MFLAG_RUNNING)) { + continue; + } + + switch_mutex_lock(omember->audio_out_mutex); + ok = switch_buffer_write(omember->mux_buffer, write_frame, bytes); + switch_mutex_unlock(omember->audio_out_mutex); + if (!ok) { switch_mutex_unlock(conference->mutex); goto end; @@ -4902,63 +4930,33 @@ static void conference_loop_output(conference_member_t *member) write_frame.data = data; use_buffer = member->mux_buffer; low_count = 0; + if ((write_frame.datalen = (uint32_t) switch_buffer_read(use_buffer, write_frame.data, bytes))) { if (write_frame.datalen) { write_frame.samples = write_frame.datalen / 2 / member->conference->channels; if( !switch_test_flag(member, MFLAG_CAN_HEAR)) { memset(write_frame.data, 255, write_frame.datalen); + } else if (member->volume_out_level) { /* Check for output volume adjustments */ + switch_change_sln_volume(write_frame.data, write_frame.samples * member->conference->channels, member->volume_out_level); } - else { - /* Check for output volume adjustments */ - if (member->volume_out_level) { - switch_change_sln_volume(write_frame.data, write_frame.samples * member->conference->channels, member->volume_out_level); - } + + write_frame.timestamp = timer.samplecount; + + if (member->fnode) { + member_add_file_data(member, write_frame.data, write_frame.datalen); } - write_frame.timestamp = timer.samplecount; - if (member->fnode) { - member_add_file_data(member, write_frame.data, write_frame.datalen); - } - member_check_channels(&write_frame, member, SWITCH_FALSE); - - if (switch_core_session_write_frame(member->session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - switch_mutex_unlock(member->audio_out_mutex); - break; - } + member_check_channels(&write_frame, member, SWITCH_FALSE); + + if (switch_core_session_write_frame(member->session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { + switch_mutex_unlock(member->audio_out_mutex); + break; + } } } switch_mutex_unlock(member->audio_out_mutex); - } else if (member->fnode) { - write_frame.datalen = bytes; - write_frame.samples = samples; - memset(write_frame.data, 255, write_frame.datalen); - write_frame.timestamp = timer.samplecount; - member_add_file_data(member, write_frame.data, write_frame.datalen); - member_check_channels(&write_frame, member, SWITCH_FALSE); - if (switch_core_session_write_frame(member->session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - break; - } - } else { - - if (member->conference->comfort_noise_level) { - switch_generate_sln_silence(write_frame.data, samples, member->conference->channels, member->conference->comfort_noise_level); - } else { - memset(write_frame.data, 255, bytes); - } - - write_frame.datalen = bytes; - write_frame.samples = samples; - write_frame.timestamp = timer.samplecount; - - member_check_channels(&write_frame, member, SWITCH_FALSE); - - if (switch_core_session_write_frame(member->session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - break; - } } if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) { @@ -5068,8 +5066,6 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th uint32_t rlen; switch_size_t data_buf_len; switch_event_t *event; - int no_data = 0; - int lead_in = 20; switch_size_t len = 0; if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) { @@ -5174,11 +5170,6 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th len = 0; - if (lead_in) { - lead_in--; - goto loop; - } - mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer); if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) { @@ -5205,7 +5196,6 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data_buf, data_buf_len))) { len = (switch_size_t) rlen / sizeof(int16_t) / conference->channels; - no_data = 0; } switch_mutex_unlock(member->audio_out_mutex); } @@ -5217,10 +5207,6 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th goto again; } - if (++no_data < 2) { - goto loop; - } - memset(data_buf, 255, (switch_size_t) data_buf_len); len = (switch_size_t) samples; } @@ -5238,16 +5224,18 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th } /* Rinse ... Repeat */ end: - - while(!no_data) { + + for(;;) { switch_mutex_lock(member->audio_out_mutex); - if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data_buf, data_buf_len))) { - len = (switch_size_t) rlen / sizeof(int16_t)/ conference->channels; - switch_core_file_write(&fh, data_buf, &len); - } else { - no_data = 1; - } + rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data_buf, data_buf_len); switch_mutex_unlock(member->audio_out_mutex); + + if (rlen > 0) { + len = (switch_size_t) rlen / sizeof(int16_t)/ conference->channels; + switch_core_file_write(&fh, data_buf, &len); + } else { + break; + } } switch_safe_free(data_buf); From 323a3d617c6474cd5d2bd18e0e71aa56e2e32553 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 26 Aug 2014 18:41:01 +0000 Subject: [PATCH 03/20] Avoid output of junk text by fs_cli In some cases where `redisplay()` is called immediately after a command is run (e.g. `log ...`) we often get a prompt, junk output, and a second prompt. This is due to a (known) race. We believe we're falling afoul of this code in `el_deletestr`: if (el->el_line.cursor < &el->el_line.buffer[n]) return; Basing the length of text to delete off of the cursor position resolves the issue of junk text, but the real solution is to eliminate the race conditions, which will also resolve the sometimes duplicated prompt. FS-6764 #resolve Thanks-to: Nathan Neulinger --- libs/esl/fs_cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/esl/fs_cli.c b/libs/esl/fs_cli.c index ed59792771..43c186b728 100644 --- a/libs/esl/fs_cli.c +++ b/libs/esl/fs_cli.c @@ -1284,7 +1284,7 @@ static void read_config(const char *dft_cfile, const char *cfile) { static void clear_el_buffer(void) { #ifdef HAVE_LIBEDIT const LineInfo *lf = el_line(el); - int len = (int)(lf->lastchar - lf->buffer); + int len = (int)(lf->cursor - lf->buffer); if (global_profile->batch_mode) return; el_deletestr(el, len); memset((char*)lf->buffer, 0, len); From 2db039bc5f3928f8e478026bf51aaed7d03b1082 Mon Sep 17 00:00:00 2001 From: Nathan Neulinger Date: Wed, 27 Aug 2014 10:38:16 -0500 Subject: [PATCH 04/20] mod_skinny: FS-6720 - fix issue with SLA - had to do with answering in wrong state --- src/mod/endpoints/mod_skinny/skinny_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_skinny/skinny_server.c b/src/mod/endpoints/mod_skinny/skinny_server.c index d2c4cd1ca7..18b10e584d 100644 --- a/src/mod/endpoints/mod_skinny/skinny_server.c +++ b/src/mod/endpoints/mod_skinny/skinny_server.c @@ -1485,7 +1485,7 @@ switch_status_t skinny_handle_off_hook_message(listener_t *listener, skinny_mess line_state = skinny_line_get_state(listener, line_instance, call_id); - if(session && line_state != SKINNY_OFF_HOOK ) { /*answering a call */ + if(session && line_state == SKINNY_RING_IN ) { /*answering a call */ skinny_session_answer(session, listener, line_instance); } else { /* start a new call */ skinny_create_incoming_session(listener, &line_instance, &session); From 1dc44067cd2111440ef384720b98dba536e0369b Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 27 Aug 2014 13:28:11 -0500 Subject: [PATCH 05/20] FS-6770 #resolve --- src/mod/endpoints/mod_sofia/sofia.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 79339e9781..edc15cf69b 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -8265,6 +8265,29 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t } } + } else if (!strncasecmp(sip->sip_content_type->c_type, "application", 11) && + !strcasecmp(sip->sip_content_type->c_subtype, "vnd.nortelnetworks.digits")) { + int tmp; + if ((signal_ptr = switch_stristr("d=", sip->sip_payload->pl_data))) { + signal_ptr = signal_ptr + 2; + + while (*signal_ptr && *signal_ptr == ' ') { + signal_ptr++; + } + + if (*signal_ptr && (*signal_ptr == '*' || *signal_ptr == '#' || *signal_ptr == 'A' || *signal_ptr == 'B' + || *signal_ptr == 'C' || *signal_ptr == 'D')) { + dtmf.digit = *signal_ptr; + } else { + tmp = atoi(signal_ptr); + dtmf.digit = switch_rfc2833_to_char(tmp); + } + + dtmf.duration = 100; + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Bad signal\n"); + goto end; + } } else if (!strncasecmp(sip->sip_content_type->c_type, "application", 11) && !strcasecmp(sip->sip_content_type->c_subtype, "dtmf-relay")) { /* Try and find signal information in the payload */ if ((signal_ptr = switch_stristr("Signal=", sip->sip_payload->pl_data))) { From 5a209a968044ad5dad0d61c1d0ed576769a48f20 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Wed, 27 Aug 2014 23:10:54 +0000 Subject: [PATCH 06/20] Remove misleading `tport` example from configs As an example of using mod_sofia's gateway parameter `contact-params` we'd used the value `tport=tcp`. Looking around, it's clear this has misled people into believing you can specify `tport=tcp` to make the gateway use TCP or `tport=tls` to make the gateway use TLS. This does not work. The actual contact parameter is named `transport` rather than `tport`, and you shouldn't use `transport` in `contact-params` because we automatically add a `transport` to the Contact: based on the value of `register-transport` (even if the gateway is set to not register). It's clear why this would be confusing, so we'll just remove this as an example. --- conf/insideout/directory/default/brian.xml | 2 +- conf/insideout/sip_profiles/external/example.xml | 2 +- conf/insideout/sip_profiles/internal/example.xml | 2 +- conf/rayo/sip_profiles/external/example.xml | 2 +- conf/sbc/sbc_profiles/external/example.xml | 2 +- conf/sbc/sbc_profiles/internal/example.xml | 2 +- conf/softphone/accounts/example.xml | 2 +- conf/vanilla/directory/default/brian.xml | 2 +- conf/vanilla/sip_profiles/external/example.xml | 2 +- conf/vanilla/sip_profiles/internal/example.xml | 2 +- src/mod/endpoints/mod_sofia/conf/sofia.conf.xml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/conf/insideout/directory/default/brian.xml b/conf/insideout/directory/default/brian.xml index 4bd562686f..43f349f144 100644 --- a/conf/insideout/directory/default/brian.xml +++ b/conf/insideout/directory/default/brian.xml @@ -34,7 +34,7 @@ - + diff --git a/conf/insideout/sip_profiles/external/example.xml b/conf/insideout/sip_profiles/external/example.xml index c6b79e8fe3..64081fdcd8 100644 --- a/conf/insideout/sip_profiles/external/example.xml +++ b/conf/insideout/sip_profiles/external/example.xml @@ -27,7 +27,7 @@ - + diff --git a/conf/insideout/sip_profiles/internal/example.xml b/conf/insideout/sip_profiles/internal/example.xml index c6b79e8fe3..64081fdcd8 100644 --- a/conf/insideout/sip_profiles/internal/example.xml +++ b/conf/insideout/sip_profiles/internal/example.xml @@ -27,7 +27,7 @@ - + diff --git a/conf/rayo/sip_profiles/external/example.xml b/conf/rayo/sip_profiles/external/example.xml index 2a4df31aaf..0497bcd1e1 100644 --- a/conf/rayo/sip_profiles/external/example.xml +++ b/conf/rayo/sip_profiles/external/example.xml @@ -27,7 +27,7 @@ - + diff --git a/conf/sbc/sbc_profiles/external/example.xml b/conf/sbc/sbc_profiles/external/example.xml index c6b79e8fe3..64081fdcd8 100644 --- a/conf/sbc/sbc_profiles/external/example.xml +++ b/conf/sbc/sbc_profiles/external/example.xml @@ -27,7 +27,7 @@ - + diff --git a/conf/sbc/sbc_profiles/internal/example.xml b/conf/sbc/sbc_profiles/internal/example.xml index c6b79e8fe3..64081fdcd8 100644 --- a/conf/sbc/sbc_profiles/internal/example.xml +++ b/conf/sbc/sbc_profiles/internal/example.xml @@ -27,7 +27,7 @@ - + diff --git a/conf/softphone/accounts/example.xml b/conf/softphone/accounts/example.xml index 7ac8db1186..249b460709 100644 --- a/conf/softphone/accounts/example.xml +++ b/conf/softphone/accounts/example.xml @@ -27,7 +27,7 @@ - + diff --git a/conf/vanilla/directory/default/brian.xml b/conf/vanilla/directory/default/brian.xml index 5ea3f58ea6..98f720f47e 100644 --- a/conf/vanilla/directory/default/brian.xml +++ b/conf/vanilla/directory/default/brian.xml @@ -36,7 +36,7 @@ - + diff --git a/conf/vanilla/sip_profiles/external/example.xml b/conf/vanilla/sip_profiles/external/example.xml index 2a4df31aaf..0497bcd1e1 100644 --- a/conf/vanilla/sip_profiles/external/example.xml +++ b/conf/vanilla/sip_profiles/external/example.xml @@ -27,7 +27,7 @@ - + diff --git a/conf/vanilla/sip_profiles/internal/example.xml b/conf/vanilla/sip_profiles/internal/example.xml index 10263b05a5..a5cbd7d2b7 100644 --- a/conf/vanilla/sip_profiles/internal/example.xml +++ b/conf/vanilla/sip_profiles/internal/example.xml @@ -27,7 +27,7 @@ - + diff --git a/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml b/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml index f624fa5a74..52fb8faefb 100644 --- a/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml +++ b/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml @@ -43,7 +43,7 @@ calls via this gateway --> - +