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

add presence for conference and dial an eavesdrop

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8091 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 cd7b1e12
......@@ -121,13 +121,89 @@ SWITCH_STANDARD_APP(intercept_function)
switch_ivr_intercept_session(session, data);
}
#define MAX_SPY 3000
struct e_data {
char *uuid_list[MAX_SPY];
int total;
};
static int e_callback(void *pArg, int argc, char **argv, char **columnNames)
{
char *uuid = argv[0];
struct e_data *e_data = (struct e_data *) pArg;
if (uuid && e_data) {
e_data->uuid_list[e_data->total++] = strdup(uuid);
return 0;
}
return 1;
}
#define eavesdrop_SYNTAX "<uuid>"
SWITCH_STANDARD_APP(eavesdrop_function)
{
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", eavesdrop_SYNTAX);
} else {
switch_ivr_eavesdrop_session(session, data, ED_DTMF);
if (!strcasecmp((char *)data, "all")) {
switch_core_db_t *db = switch_core_db_handle();
char *errmsg = NULL;
struct e_data e_data = {{ 0 }};
char *sql = switch_mprintf("select uuid from channels where uuid != '%q'", switch_core_session_get_uuid(session));
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *file = NULL;
int x = 0;
char buf[2] = "";
switch_size_t buflen = sizeof(buf);
char terminator;
while(switch_channel_ready(channel)) {
for(x = 0; x < MAX_SPY; x++) {
switch_safe_free(e_data.uuid_list[x]);
}
e_data.total = 0;
switch_core_db_exec(db, sql, e_callback, &e_data, &errmsg);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error: %s\n", errmsg);
switch_core_db_free(errmsg);
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_failed"))) {
switch_ivr_play_file(session, NULL, file, NULL);
}
switch_ivr_collect_digits_count(session, buf, buflen, 1, "*", &terminator, 5000, 0, 0);
continue;
}
if (e_data.total) {
for (x = 0; x < e_data.total && switch_channel_ready(channel); x++) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Spy: %s\n", e_data.uuid_list[x]);
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_new"))) {
switch_ivr_play_file(session, NULL, file, NULL);
}
if (switch_ivr_eavesdrop_session(session, e_data.uuid_list[x], ED_DTMF) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Spy: %s Failed\n", e_data.uuid_list[x]);
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_failed"))) {
switch_ivr_play_file(session, NULL, file, NULL);
}
switch_ivr_collect_digits_count(session, buf, buflen, 1, "*", &terminator, 5000, 0, 0);
}
}
} else {
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_idle"))) {
switch_ivr_play_file(session, NULL, file, NULL);
}
switch_ivr_collect_digits_count(session, buf, buflen, 1, "*", &terminator, 2000, 0, 0);
}
}
for(x = 0; x < MAX_SPY; x++) {
switch_safe_free(e_data.uuid_list[x]);
}
switch_core_db_close(db);
} else {
switch_ivr_eavesdrop_session(session, data, ED_DTMF);
}
}
}
......
......@@ -81,10 +81,8 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
moh_a = switch_channel_get_variable(channel, "hold_music");
}
}
switch_ivr_soft_hold(session, "0", moh_a, moh_b);
switch_ivr_soft_hold(session, "0", moh_a, moh_b);
return SWITCH_STATUS_IGNORE;
}
}
......
......@@ -482,7 +482,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
*next++ = '\0';
}
}
if (!switch_strlen_zero(this) && (!last || strcmp(last, this))) {
sofia_glue_execute_sql(profile, &this, SWITCH_FALSE);
last = this;
......
......@@ -497,17 +497,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
if ((tsession = switch_core_session_locate(uuid))) {
struct eavesdrop_pvt *ep;
struct eavesdrop_pvt *ep = NULL;
switch_media_bug_t *bug = NULL;
switch_channel_t *tchannel = switch_core_session_get_channel(tsession);
switch_frame_t *read_frame, write_frame = { 0 };
switch_codec_t codec = {0};
int16_t buf[SWITCH_RECOMMENDED_BUFFER_SIZE/2];
switch_codec_t *tread_codec = switch_core_session_get_read_codec(tsession);
uint32_t tlen = tread_codec->implementation->bytes_per_frame;
uint32_t tlen;
if (!switch_channel_media_ready(channel)) {
goto end;
}
ep = switch_core_session_alloc(session, sizeof(*ep));
tlen = tread_codec->implementation->bytes_per_frame;
switch_channel_pre_answer(channel);
if (switch_core_codec_init(&codec,
......@@ -520,7 +526,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot init codec\n");
switch_core_session_rwunlock(tsession);
return status;
goto end;
}
switch_core_session_set_read_codec(session, &codec);
......@@ -599,6 +605,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
switch_clear_flag(ep, ED_MUX_READ);
switch_clear_flag(ep, ED_MUX_WRITE);
break;
case '*':
goto end;
default:
z = 0;
break;
......@@ -657,17 +665,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
switch_core_media_bug_remove(tsession, &bug);
}
if (ep->buffer) {
switch_buffer_destroy(&ep->buffer);
}
if (ep->r_buffer) {
switch_buffer_destroy(&ep->r_buffer);
}
if (ep->w_buffer) {
switch_buffer_destroy(&ep->w_buffer);
}
if (ep) {
if (ep->buffer) {
switch_buffer_destroy(&ep->buffer);
}
if (ep->r_buffer) {
switch_buffer_destroy(&ep->r_buffer);
}
if (ep->w_buffer) {
switch_buffer_destroy(&ep->w_buffer);
}
}
switch_core_session_rwunlock(tsession);
status = SWITCH_STATUS_SUCCESS;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论