\n"
+ ;
+
+ if (stream->event) {
+ http = switch_event_get_header(stream->event, "http-host");
+ }
+
+ if (http) {
+ /* Output must be to a web browser */
+ stream->write_function(stream, "\n");
+ }
+
+ if (!buf) {
+ stream->write_function(stream, topusage);
+ return status;
+ }
+
+ if ((lbuf = strdup(buf))) {
+ conference_obj_t *conference = NULL;
+ int argc;
+ char *argv[25];
+ switch_event_t *event;
+
+ argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+
+ /* Figure out what conference */
+ if (argc) {
+ if (!strcasecmp(argv[0], "commands")) {
+ stream->write_function(stream, topusage);
+ goto done;
+ } else if (!strcasecmp(argv[0], "list")) {
+ switch_hash_index_t *hi;
+ void *val;
+ char *d = ";";
+
+ if (argv[1]) {
+ if (argv[2] && !strcasecmp(argv[1], "delim")) {
+ d = argv[2];
+
+ if (*d == '"') {
+ if (++d) {
+ char *p;
+ if ((p = strchr(d, '"'))) {
+ *p = '\0';
+ }
+ } else {
+ d = ";";
+ }
+ }
+ }
+ }
+
+ for (hi = switch_hash_first(globals.conference_pool, globals.conference_hash); hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, NULL, NULL, &val);
+ conference = (conference_obj_t *) val;
+
+ stream->write_function(stream, "Conference %s (%u members)\n", conference->name, conference->count);
+ conference_list(conference, stream, d);
+ stream->write_function(stream, "\n");
+ }
+ goto done;
+ } else if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, argv[0]))) {
+ stream->write_function(stream, "No Conference called %s found.\n", argv[0]);
+ goto done;
+ }
+
+ if (argc > 1) {
+ if (!strcasecmp(argv[1], "lock")) {
+ switch_set_flag_locked(conference, CFLAG_LOCKED);
+ stream->write_function(stream, "OK %s locked\n", argv[0]);
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "lock");
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else if (!strcasecmp(argv[1], "unlock")) {
+ switch_clear_flag_locked(conference, CFLAG_LOCKED);
+ stream->write_function(stream, "OK %s unlocked\n", argv[0]);
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "lock");
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else if (!strcasecmp(argv[1], "dial")) {
+ if (argc > 2) {
+ conference_outcall(conference, NULL, argv[2], argv[3], argv[4]);
+ stream->write_function(stream, "OK\n");
+ goto done;
+ } else {
+ stream->write_function(stream, "Error!\n");
+ goto done;
+ }
+ } else if (!strcasecmp(argv[1], "play")) {
+ if (argc == 3) {
+ if (conference_play_file(conference, argv[2], 0) == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "(play) Playing file %s\n", argv[2]);
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "play-file");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "File", argv[2]);
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "(play) File: %s not found.\n", argv[2] ? argv[2] : "(unspecified)");
+ goto done;
+ }
+ } else if (argc == 4) {
+ uint32_t id = atoi(argv[3]);
+ conference_member_t *member;
+
+ if ((member = conference_member_get(conference, id))) {
+ if (conference_member_play_file(member, argv[2], 0) == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "(play) Playing file %s to member %u\n", argv[2], id);
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "play-file-member");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "File", argv[2]);
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "(play) File: %s not found.\n", argv[2] ? argv[2] : "(unspecified)");
+ goto done;
+ }
+ } else {
+ stream->write_function(stream, "Member: %u not found.\n", id);
+ goto done;
+ }
+ }
+ } else if (!strcasecmp(argv[1], "say")) {
+ char *tbuf = NULL;
+ char *text;
+
+ if ((tbuf = strdup(buf))) {
+ if ((text = strstr(tbuf, "say "))) {
+ text += 4;
+ if (text && conference_say(conference, text, 0) == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "(say) OK\n");
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", text);
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "(say) Error!");
+ goto done;
+ }
+ }
+
+ free(tbuf);
+ }
+ } else if (!strcasecmp(argv[1], "saymember")) {
+ char *tbuf = NULL, *text, *name;
+ uint32_t id = atoi(argv[3]);
+ conference_member_t *member;
+
+ if ((tbuf = strdup(buf))) {
+ if ((name = strstr(tbuf, "saymember "))) {
+ name += 10;
+ text = strchr(name, ' ');
+ id = atoi(name);
+
+ if ((member = conference_member_get(conference, id))) {
+ if (text && conference_member_say(conference, member, text, 0) == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "(saymember) OK\n");
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text-member");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", text);
+ switch_event_fire(&event);
+ }
+ } else {
+ stream->write_function(stream, "(saymember) Error!");
+ }
+ } else {
+ stream->write_function(stream, "(saymember) Unknown Member %u!", id);
+ }
+ } else {
+ stream->write_function(stream, "(saymember) Syntax Error!");
+ }
+
+ free(tbuf);
+ goto done;
+ }
+ } else if (!strcasecmp(argv[1], "stop")) {
+ uint8_t current = 0, all = 0;
+
+ if (argc > 2) {
+ current = strcasecmp(argv[2], "current") ? 0 : 1;
+ all = strcasecmp(argv[2], "all") ? 0 : 1;
+ }
+
+ if (current || all) {
+ if (argc == 4) {
+ uint32_t id = atoi(argv[3]);
+ conference_member_t *member;
+ if ((member = conference_member_get(conference, id))) {
+ uint32_t stopped = conference_member_stop_file(member, current ? FILE_STOP_CURRENT : FILE_STOP_ALL);
+ stream->write_function(stream, "Stopped %u files.\n", stopped);
+ } else {
+ stream->write_function(stream, "Member: %u not found.\n", id);
+ goto done;
+ }
+ } else {
+ uint32_t stopped = conference_stop_file(conference, current ? FILE_STOP_CURRENT : FILE_STOP_ALL);
+ stream->write_function(stream, "Stopped %u files.\n", stopped);
+ }
+ } else {
+ stream->write_function(stream, "Usage stop [current/all]\n");
+ goto done;
+ }
+
+ } else if (!strcasecmp(argv[1], "mute")) {
+ if (argc > 2) {
+ uint32_t id = atoi(argv[2]);
+ conference_member_t *member;
+
+ if ((member = conference_member_get(conference, id))) {
+ switch_clear_flag_locked(member, MFLAG_CAN_SPEAK);
+ if (member->conference->muted_sound) {
+ conference_member_play_file(member, member->conference->muted_sound, 0);
+ }
+ stream->write_function(stream, "OK mute %u\n", id);
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_t *channel = switch_core_session_get_channel(member->session);
+ switch_channel_event_set_data(channel, event);
+
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "mute-member");
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "Non-Existant ID %u\n", id);
+ goto done;
+ }
+ } else {
+ stream->write_function(stream, "usage mute \n");
+ goto done;
+ }
+ } else if (!strcasecmp(argv[1], "unmute")) {
+ if (argc > 2) {
+ uint32_t id = atoi(argv[2]);
+ conference_member_t *member;
+
+ if ((member = conference_member_get(conference, id))) {
+ switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
+ stream->write_function(stream, "OK unmute %u\n", id);
+ if (member->conference->unmuted_sound) {
+ conference_member_play_file(member, member->conference->unmuted_sound, 0);
+ }
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_t *channel = switch_core_session_get_channel(member->session);
+ switch_channel_event_set_data(channel, event);
+
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "unmute-member");
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "Non-Existant ID %u\n", id);
+ goto done;
+ }
+ } else {
+ stream->write_function(stream, "usage unmute \n");
+ goto done;
+ }
+ } else if (!strcasecmp(argv[1], "deaf")) {
+ if (argc > 2) {
+ uint32_t id = atoi(argv[2]);
+ conference_member_t *member;
+
+ if ((member = conference_member_get(conference, id))) {
+ switch_clear_flag_locked(member, MFLAG_CAN_HEAR);
+ stream->write_function(stream, "OK deaf %u\n", id);
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_t *channel = switch_core_session_get_channel(member->session);
+ switch_channel_event_set_data(channel, event);
+
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "deaf-member");
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "Non-Existant ID %u\n", id);
+ goto done;
+ }
+ } else {
+ stream->write_function(stream, "usage deaf \n");
+ goto done;
+ }
+ } else if (!strcasecmp(argv[1], "undeaf")) {
+ if (argc > 2) {
+ uint32_t id = atoi(argv[2]);
+ conference_member_t *member;
+
+ if ((member = conference_member_get(conference, id))) {
+ switch_set_flag_locked(member, MFLAG_CAN_HEAR);
+ stream->write_function(stream, "OK undeaf %u\n", id);
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_t *channel = switch_core_session_get_channel(member->session);
+ switch_channel_event_set_data(channel, event);
+
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "undeaf-member");
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "Non-Existant ID %u\n", id);
+ goto done;
+ }
+ } else {
+ stream->write_function(stream, "usage undeaf \n");
+ goto done;
+ }
+ } else if (!strcasecmp(argv[1], "kick")) {
+ if (argc > 2) {
+ uint32_t id = atoi(argv[2]);
+ conference_member_t *member;
+
+ if ((member = conference_member_get(conference, id))) {
+ switch_mutex_lock(member->flag_mutex);
+ switch_clear_flag(member, MFLAG_RUNNING);
+ switch_set_flag(member, MFLAG_KICKED);
+ switch_mutex_unlock(member->flag_mutex);
+
+ stream->write_function(stream, "OK kicked %u\n", id);
+
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_t *channel = switch_core_session_get_channel(member->session);
+ switch_channel_event_set_data(channel, event);
+
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "kick-member");
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "Non-Existant ID %u\n", id);
+ goto done;
+ }
+ } else {
+ stream->write_function(stream, "usage kick \n");
+ goto done;
+ }
+ } else if (!strcasecmp(argv[1], "transfer")) {
+ char *transfer_usage = "Usage transfer \n";
+ if (argc > 3) {
+ conference_member_t *member = NULL;
+ uint32_t id = atoi(argv[2]);
+ conference_obj_t *new_conference = NULL;
+
+ if ((new_conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, argv[3]))) {
+ if ((member = conference_member_get(conference, id))) {
+ switch_channel_t *channel = switch_core_session_get_channel(member->session);
+ switch_event_t *event;
+
+ conference_del_member(member->last_conference, member);
+ conference_add_member(new_conference, member);
+ stream->write_function(stream, "OK Member %u sent to conference %s.\n", id, argv[3]);
+
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(channel, event);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Old-Conference-Name", conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Conference-Name", argv[3]);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "transfer");
+ switch_event_fire(&event);
+ }
+ goto done;
+ } else {
+ stream->write_function(stream, "No Member %u in conference %s.\n", id, conference->name);
+ goto done;
+ }
+ } else {
+ stream->write_function(stream, "No Conference called %s found.\n", argv[3]);
+ goto done;
+ }
+
+ } else {
+ stream->write_function(stream, transfer_usage);
+ goto done;
+ }
+ } else if (!strcasecmp(argv[1], "relate")) {
+ char *relate_usage = "Usage relate [nospeak|nohear|clear]\n";
+ if (argc > 4) {
+ uint8_t nospeak = 0, nohear = 0, clear = 0;
+ nospeak = strstr(argv[4], "nospeak") ? 1 : 0;
+ nohear = strstr(argv[4], "nohear") ? 1 : 0;
+
+ if (!strcasecmp(argv[4], "clear")) {
+ clear = 1;
+ }
+
+ if (!(clear || nospeak || nohear)) {
+ stream->write_function(stream, relate_usage);
+ goto done;
+ }
+
+ if (clear) {
+ conference_member_t *member = NULL;
+ uint32_t id = atoi(argv[2]);
+ uint32_t oid = atoi(argv[3]);
+
+ switch_mutex_lock(conference->mutex);
+ switch_mutex_lock(conference->member_mutex);
+ if ((member = conference_member_get(conference, id))) {
+ member_del_relationship(member, oid);
+ stream->write_function(stream, "relationship %u->%u cleared.", id, oid);
+ } else {
+ stream->write_function(stream, "relationship %u->%u not found", id, oid);
+ }
+ switch_mutex_unlock(conference->member_mutex);
+ switch_mutex_unlock(conference->mutex);
+ } else if (nospeak || nohear) {
+ conference_member_t *member = NULL, *other_member = NULL;
+ uint32_t id = atoi(argv[2]);
+ uint32_t oid = atoi(argv[3]);
+
+ switch_mutex_lock(conference->mutex);
+ switch_mutex_lock(conference->member_mutex);
+ if ((member = conference_member_get(conference, id)) && (other_member = conference_member_get(conference, oid))) {
+ conference_relationship_t *rel = NULL;
+ if ((rel = member_get_relationship(member, other_member))) {
+ rel->flags = 0;
+ } else {
+ rel = member_add_relationship(member, oid);
+ }
+
+ if (rel) {
+ switch_set_flag(rel, RFLAG_CAN_SPEAK | RFLAG_CAN_HEAR);
+ if (nospeak) {
+ switch_clear_flag(rel, RFLAG_CAN_SPEAK);
+ }
+ if (nohear) {
+ switch_clear_flag(rel, RFLAG_CAN_HEAR);
+ }
+ stream->write_function(stream, "ok %u->%u set\n", id, oid);
+ } else {
+ stream->write_function(stream, "error!\n");
+ }
+
+ } else {
+ stream->write_function(stream, "relationship %u->%u not found", id, oid);
+ }
+ switch_mutex_unlock(conference->member_mutex);
+ switch_mutex_unlock(conference->mutex);
+ }
+
+
+ } else {
+ stream->write_function(stream, relate_usage);
+ }
+ } else if (!strcasecmp(argv[1], "list")) {
+ char *d = ";";
+
+ if (argv[2]) {
+ if (argv[3] && !strcasecmp(argv[2], "delim")) {
+ d = argv[3];
+
+ if (*d == '"') {
+ if (++d) {
+ char *p;
+ if ((p = strchr(d, '"'))) {
+ *p = '\0';
+ }
+ } else {
+ d = ";";
+ }
+ }
+ }
+ }
+ conference_list(conference, stream, d);
+ } else {
+ stream->write_function(stream, "Command: %s not found.\n", argv[1]);
+ goto done;
+ }
+
+ } else {
+ stream->write_function(stream, "Command not specified.\n");
+ goto done;
+ }
+ } else {
+ stream->write_function(stream, topusage);
+ }
+ } else {
+ stream->write_function(stream, "Memory Error!\n");
+ }
+
+ done:
+
+ if (lbuf) {
+ free(lbuf);
+ }
+
+ return status;
+
+}
+
+static switch_status_t audio_bridge_on_ring(switch_core_session_t *session)
+{
+ switch_channel_t *channel = NULL;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM RING\n");
+
+ /* put the channel in a passive state so we can loop audio to it */
+ return SWITCH_STATUS_FALSE;
+}
+
+static const switch_state_handler_table_t audio_bridge_peer_state_handlers = {
+ /*.on_init */ NULL,
+ /*.on_ring */ audio_bridge_on_ring,
+ /*.on_execute */ NULL,
+ /*.on_hangup */ NULL,
+ /*.on_loopback */ NULL,
+ /*.on_transmit */ NULL,
+ /*.on_hold */ NULL,
+};
+
+static switch_status_t conference_outcall(conference_obj_t *conference, switch_core_session_t *session, char *bridgeto, char *cid_name, char *cid_num)
+{
+ switch_core_session_t *peer_session;
+ switch_caller_profile_t *caller_profile, *caller_caller_profile;
+ char *chan_type, *chan_data;
+ unsigned int timelimit = 60;
+ switch_channel_t *peer_channel;
+ time_t start;
+ switch_frame_t *read_frame = NULL;
+ switch_status_t status = SWITCH_STATUS_SUCCESS;
+ switch_channel_t *caller_channel = NULL;
+
+ chan_type = strdup(bridgeto);
+
+ if ((chan_data = strchr(chan_type, '/')) != 0) {
+ *chan_data = '\0';
+ chan_data++;
+ }
+
+ if (session) {
+ caller_channel = switch_core_session_get_channel(session);
+ assert(caller_channel != NULL);
+ caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
+
+ if (!cid_name) {
+ cid_name = caller_caller_profile->caller_id_name;
+ }
+
+ if (!cid_num) {
+ cid_num = caller_caller_profile->caller_id_number;
+ }
+
+ caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
+ caller_caller_profile->username,
+ caller_caller_profile->dialplan,
+ cid_name,
+ cid_num,
+ caller_caller_profile->network_addr,
+ NULL,
+ NULL,
+ caller_caller_profile->rdnis,
+ caller_caller_profile->source,
+ caller_caller_profile->context,
+ chan_data);
+ } else {
+
+ if (!cid_name) {
+ cid_name = conference->caller_id_name;
+ }
+
+ if (!cid_num) {
+ cid_num = conference->caller_id_number;
+ }
+
+ caller_profile = switch_caller_profile_new(conference->pool,
+ NULL,
+ NULL,
+ cid_name,
+ cid_num,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ (char *) global_app_name,
+ NULL,
+ chan_data);
+ }
+
+
+
+ if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session, NULL) !=
+ SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
+ if (caller_channel) {
+ switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
+ }
+ status = SWITCH_STATUS_FALSE;
+ goto done;
+ }
+
+ peer_channel = switch_core_session_get_channel(peer_session);
+ assert(peer_channel != NULL);
+
+ switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers);
+
+ if (switch_core_session_runing(peer_session)) {
+ switch_channel_set_state(peer_channel, CS_RING);
+ } else {
+ switch_core_session_thread_launch(peer_session);
+ }
+
+ time(&start);
+
+ for (;;) {
+ int state = switch_channel_get_state(peer_channel);
+ if (state >= CS_RING) {
+ break;
+ }
+
+ if (caller_channel && !switch_channel_ready(caller_channel)) {
+ break;
+ }
+
+ if ((time(NULL) - start) > timelimit) {
+ break;
+ }
+ switch_yield(1000);
+ }
+
+ if (caller_channel) {
+ switch_channel_pre_answer(caller_channel);
+ }
+
+ while ((!caller_channel || switch_channel_ready(caller_channel)) &&
+ switch_channel_ready(peer_channel) &&
+ !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
+ !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) &&
+ ((time(NULL) - start) < timelimit)) {
+
+ /* read from the channel while we wait if the audio is up on it */
+ if (session && (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA))) {
+ switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
+
+ if (!SWITCH_READ_ACCEPTABLE(status)) {
+ break;
+ }
+ if (read_frame) {
+ if (switch_core_session_write_frame(session, read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
+ break;
+ }
+ }
+
+ } else {
+ switch_yield(1000);
+ }
+
+ }
+
+ if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
+ switch_channel_answer(caller_channel);
+ }
+
+ if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
+ switch_caller_extension_t *extension = NULL;
+ if ((extension = switch_caller_extension_new(peer_session, caller_profile->destination_number,
+ caller_profile->destination_number)) == 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
+ status = SWITCH_STATUS_MEMERR;
+ goto done;
+ }
+ /* add them to the conference */
+ switch_caller_extension_add_application(peer_session, extension, (char *) global_app_name, conference->name);
+ switch_channel_set_caller_extension(peer_channel, extension);
+ switch_channel_set_state(peer_channel, CS_EXECUTE);
+
+ } else {
+ switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ANSWER);
+ status = SWITCH_STATUS_FALSE;
+ goto done;
+ }
+
+ done:
+ free(chan_type);
+ return status;
+}
+
+/* Play a file */
+static switch_status_t conference_local_play_file(switch_core_session_t *session, char *path, uint32_t leadin, char *buf, switch_size_t len)
+{
+ uint32_t x = 0;
+ switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+ for (x = 0; x < leadin; x++) {
+ switch_frame_t *read_frame;
+ switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
+
+ if (!SWITCH_READ_ACCEPTABLE(status)) {
+ break;
+ }
+ }
+
+ if (status == SWITCH_STATUS_SUCCESS) {
+ status = switch_ivr_play_file(session, NULL, path, NULL, NULL, NULL, 0);
+ }
+
+ return status;
+}
+
+/* Application interface function that is called from the dialplan to join the channel to a conference */
+static void conference_function(switch_core_session_t *session, char *data)
+{
+ switch_codec_t *read_codec = NULL;
+ switch_memory_pool_t *pool = NULL, *freepool = NULL;
+ uint32_t flags = 0;
+ conference_member_t member = {0};
+ conference_obj_t *conference = NULL;
+ switch_channel_t *channel = NULL;
+ char *mydata = switch_core_session_strdup(session, data);
+ char *conf_name = NULL;
+ char *bridge_prefix = "bridge:";
+ char *bridgeto = NULL;
+ char *profile_name = NULL;
+ switch_xml_t cxml = NULL, cfg = NULL, profile = NULL, profiles = NULL;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ if (!mydata) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+ return;
+ }
+
+ /* Setup a memory pool to use. */
+ if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+ return;
+ }
+
+ if (!strncasecmp(mydata, bridge_prefix, strlen(bridge_prefix))) {
+ char *uuid = switch_core_session_get_uuid(session);
+
+ mydata += strlen(bridge_prefix);
+ conf_name = mydata;
+
+ if ((bridgeto = strchr(conf_name, ':'))) {
+ *bridgeto++ = '\0';
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Config Error!\n");
+ goto done;
+ }
+
+ if ((profile_name = strchr(conf_name, '@'))) {
+ *profile_name++ = '\0';
+
+ /* Open the config from the xml registry */
+ if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
+ goto done;
+ }
+
+ if ((profiles = switch_xml_child(cfg, "profiles"))) {
+ profile = switch_xml_find_child(profiles, "profile", "name", profile_name);
+ }
+ }
+
+ if (!strcmp(conf_name, "_uuid_")) {
+ conf_name = uuid;
+ }
+
+ if ((conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference %s already exists!\n", conf_name);
+ goto done;
+ }
+
+ /* Create the conference object. */
+ conference = conference_new(conf_name, profile, pool);
+
+ /* Release the config registry handle */
+ switch_xml_free(cxml);
+ cxml = NULL;
+
+ if (!conference) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+ goto done;
+ }
+
+ /* Set the minimum number of members (once you go above it you cannot go below it) */
+ conference->min = 2;
+
+ /* Indicate the conference is dynamic */
+ switch_set_flag_locked(conference, CFLAG_DYNAMIC);
+
+ /* Start the conference thread for this conference */
+ launch_conference_thread(conference);
+
+ } else {
+ conf_name = mydata;
+ freepool = pool;
+ /* Figure out what conference to call. */
+ if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Conference called %s found.\n", conf_name);
+ goto done;
+ }
+
+ if (conference->pin) {
+ char term = '\0';
+ char pin[80] = "";
+ char *buf;
+
+ /* Answer the channel */
+ switch_channel_answer(channel);
+
+ if (conference->pin_sound) {
+ conference_local_play_file(session, conference->pin_sound, 20, pin, sizeof(pin));
+ }
+
+ if (strlen(pin) < strlen(conference->pin)) {
+ buf = pin + strlen(pin);
+ switch_ivr_collect_digits_count(session, buf, sizeof(pin) - (unsigned int)strlen(pin), (unsigned int)strlen(conference->pin) - (unsigned int)strlen(pin), "#", &term, 10000);
+ }
+
+ if (strcmp(pin, conference->pin)) {
+ if (conference->bad_pin_sound) {
+ conference_local_play_file(session, conference->bad_pin_sound, 20, NULL, 0);
+ }
+ goto done;
+ }
+ }
+
+ if (switch_test_flag(conference, CFLAG_LOCKED)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Conference %s is locked.\n", conf_name);
+ if (conference->locked_sound) {
+ /* Answer the channel */
+ switch_channel_answer(channel);
+ conference_local_play_file(session, conference->locked_sound, 20, NULL, 0);
+ }
+ goto done;
+ }
+
+ }
+
+ if (bridgeto) {
+ if (conference_outcall(conference, session, bridgeto, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
+ goto done;
+ }
+ }
+
+ /* Save the original read codec. */
+ read_codec = switch_core_session_get_read_codec(session);
+
+ /* Setup a Signed Linear codec for reading audio. */
+ if (switch_core_codec_init(&member.read_codec,
+ "L16",
+ read_codec->implementation->samples_per_second,
+ conference->interval,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ pool) == SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
+ conference->rate, conference->interval);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
+ conference->rate, conference->interval);
+ flags = 0;
+ goto done;
+ }
+
+ /* Setup a Signed Linear codec for writing audio. */
+ if (switch_core_codec_init(&member.write_codec,
+ "L16",
+ read_codec->implementation->samples_per_second,
+ conference->interval,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ pool) == SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
+ conference->rate, conference->interval);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
+ conference->rate, conference->interval);
+ flags = 0;
+ goto codec_done2;
+ }
+
+ /* Setup an audio buffer for the incoming audio */
+ if (switch_buffer_create(pool, &member.audio_buffer, CONF_BUFFER_SIZE) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
+ goto codec_done1;
+ }
+
+ /* Setup an audio buffer for the outgoing audio */
+ if (switch_buffer_create(pool, &member.mux_buffer, CONF_BUFFER_SIZE) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
+ goto codec_done1;
+ }
+
+ /* Prepare MUTEXS */
+ member.id = next_member_id();
+ member.pool = pool;
+ member.session = session;
+ switch_mutex_init(&member.flag_mutex, SWITCH_MUTEX_NESTED, pool);
+ switch_mutex_init(&member.audio_in_mutex, SWITCH_MUTEX_NESTED, pool);
+ switch_mutex_init(&member.audio_out_mutex, SWITCH_MUTEX_NESTED, pool);
+
+ /* Install our Signed Linear codec so we get the audio in that format */
+ switch_core_session_set_read_codec(member.session, &member.read_codec);
+
+ /* Add the caller to the conference */
+ if (conference_add_member(conference, &member) != SWITCH_STATUS_SUCCESS) {
+ goto codec_done1;
+ }
+ switch_set_flag_locked((&member), MFLAG_RUNNING | MFLAG_CAN_SPEAK | MFLAG_CAN_HEAR);
+
+ /* Run the confernece loop */
+ conference_loop(&member);
+
+ /* Remove the caller from the conference */
+ conference_del_member(member.last_conference, &member);
+
+ /* Put the original codec back */
+ switch_core_session_set_read_codec(member.session, read_codec);
+
+ /* Clean Up. codec_done(X): is for error situations after the codecs were setup and done: is for situations before */
+ codec_done1:
+ switch_core_codec_destroy(&member.read_codec);
+ codec_done2:
+ switch_core_codec_destroy(&member.write_codec);
+ done:
+
+ /* Release the config registry handle */
+ if (cxml) {
+ switch_xml_free(cxml);
+ }
+
+ if (freepool) {
+ switch_core_destroy_memory_pool(&freepool);
+ }
+
+ if (switch_test_flag(&member, MFLAG_KICKED) && conference->kicked_sound) {
+ switch_ivr_play_file(session, NULL, conference->kicked_sound, NULL, NULL, NULL, 0);
+ }
+
+ switch_core_session_reset(session);
+
+}
+
+/* Create a thread for the conference and launch it */
+static void launch_conference_thread(conference_obj_t *conference)
+{
+ switch_thread_t *thread;
+ switch_threadattr_t *thd_attr = NULL;
+
+ switch_set_flag_locked(conference, CFLAG_RUNNING);
+ switch_threadattr_create(&thd_attr, conference->pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_mutex_lock(globals.hash_mutex);
+ switch_core_hash_insert(globals.conference_hash, conference->name, conference);
+ switch_mutex_unlock(globals.hash_mutex);
+ switch_thread_create(&thread, thd_attr, conference_thread_run, conference, conference->pool);
+}
+
+static void *SWITCH_THREAD_FUNC input_thread_run(switch_thread_t *thread, void *obj)
+{
+ conference_member_t *member = obj;
+ switch_channel_t *channel;
+ switch_status_t status;
+ switch_frame_t *read_frame = NULL;
+ switch_codec_t *read_codec;
+ uint32_t hangover = 40,
+ hangunder = 15,
+ hangover_hits = 0,
+ hangunder_hits = 0,
+ energy_level = 0,
+ diff_level = 400;
+ uint8_t talking = 0;
+
+ assert(member != NULL);
+
+ energy_level = member->conference->energy_level;
+
+ channel = switch_core_session_get_channel(member->session);
+ assert(channel != NULL);
+
+ read_codec = switch_core_session_get_read_codec(member->session);
+ assert(read_codec != NULL);
+
+ /* As long as we have a valid read, feed that data into an input buffer where the conference thread will take it
+ and mux it with any audio from other channels. */
+
+ while(switch_test_flag(member, MFLAG_RUNNING) && switch_channel_ready(channel)) {
+ /* Read a frame. */
+ status = switch_core_session_read_frame(member->session, &read_frame, -1, 0);
+
+ /* end the loop, if appropriate */
+ if (!SWITCH_READ_ACCEPTABLE(status) || !switch_test_flag(member, MFLAG_RUNNING)) {
+ break;
+ }
+
+ if (switch_test_flag(read_frame, SFF_CNG)) {
+ continue;
+ }
+
+ if (switch_test_flag(member, MFLAG_CAN_SPEAK) && energy_level) {
+ uint32_t energy = 0, i = 0, samples = 0, j = 0, score = 0;
+ int16_t *data;
+
+ data = read_frame->data;
+ samples = read_frame->datalen / sizeof(*data);
+
+ for (i = 0; i < samples; i++) {
+ energy += abs(data[j]);
+ j += read_codec->implementation->number_of_channels;
+ }
+
+ score = energy / samples;
+
+ if (score > energy_level) {
+ uint32_t diff = score - energy_level;
+ if (hangover_hits) {
+ hangover_hits--;
+ }
+
+ if (diff >= diff_level || ++hangunder_hits >= hangunder) {
+ hangover_hits = hangunder_hits = 0;
+
+ if (!talking) {
+ switch_event_t *event;
+ talking = 1;
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(channel, event);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "start-talking");
+ switch_event_fire(&event);
+ }
+ }
+
+ }
+ } else {
+ if (hangunder_hits) {
+ hangunder_hits--;
+ }
+ if (talking) {
+ switch_event_t *event;
+ if (++hangover_hits >= hangover) {
+ hangover_hits = hangunder_hits = 0;
+ talking = 0;
+
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(channel, event);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", member->conference->name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "stop-talking");
+ switch_event_fire(&event);
+ }
+ }
+ }
+ }
+ }
+
+ /* skip frames that are not actual media or when we are muted or silent */
+ if (talking && switch_test_flag(member, MFLAG_CAN_SPEAK)) {
+ /* Write the audio into the input buffer */
+ switch_mutex_lock(member->audio_in_mutex);
+ switch_buffer_write(member->audio_buffer, read_frame->data, read_frame->datalen);
+ switch_mutex_unlock(member->audio_in_mutex);
+ }
+ }
+
+ switch_clear_flag_locked(member, MFLAG_ITHREAD);
+
+ return NULL;
+}
+
+/* Create a thread for the conference and launch it */
+static void launch_input_thread(conference_member_t *member, switch_memory_pool_t *pool)
+{
+ switch_thread_t *thread;
+ switch_threadattr_t *thd_attr = NULL;
+
+ switch_threadattr_create(&thd_attr, pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_set_flag_locked(member, MFLAG_ITHREAD);
+ switch_thread_create(&thread, thd_attr, input_thread_run, member, pool);
+}
+
+static const switch_application_interface_t conference_application_interface = {
+ /*.interface_name */ global_app_name,
+ /*.application_function */ conference_function,
+ NULL, NULL, NULL,
+ /*.next*/ NULL
+};
+
+static switch_api_interface_t conf_api_interface = {
+ /*.interface_name */ "conference",
+ /*.desc */ "Conference",
+ /*.function */ conf_function
+ /*.next */
+};
+
+static switch_loadable_module_interface_t conference_module_interface = {
+ /*.module_name */ modname,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ &conference_application_interface,
+ /*.api_interface */ &conf_api_interface,
+ /*.file_interface */ NULL,
+ /*.speech_interface */ NULL,
+ /*.directory_interface */ NULL
+};
+
+/* create a new conferene with a specific profile */
+static conference_obj_t *conference_new(char *name, switch_xml_t profile, switch_memory_pool_t *pool)
+{
+ conference_obj_t *conference;
+ switch_xml_t param;
+ char *rate_name = NULL;
+ char *interval_name = NULL;
+ char *timer_name = NULL;
+ char *tts_engine = NULL;
+ char *tts_voice = NULL;
+ char *enter_sound = NULL;
+ char *exit_sound = NULL;
+ char *alone_sound = NULL;
+ char *ack_sound = NULL;
+ char *nack_sound = NULL;
+ char *muted_sound = NULL;
+ char *unmuted_sound = NULL;
+ char *locked_sound = NULL;
+ char *kicked_sound = NULL;
+ char *pin = NULL;
+ char *pin_sound = NULL;
+ char *bad_pin_sound = NULL;
+ char *energy_level = NULL;
+ char *caller_id_name = NULL;
+ char *caller_id_number = NULL;
+ uint32_t rate = 8000, interval = 20;
+ switch_status_t status;
+
+ /* Conference Name */
+ if (switch_strlen_zero(name)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Record! no name.\n");
+ return NULL;
+ }
+
+
+ for (param = switch_xml_child(profile, "param"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
+
+ if (!strcasecmp(var, "rate")) {
+ rate_name = val;
+ } else if (!strcasecmp(var, "interval")) {
+ interval_name= val;
+ } else if (!strcasecmp(var, "timer_name")) {
+ timer_name= val;
+ } else if (!strcasecmp(var, "tts_engine")) {
+ tts_engine= val;
+ } else if (!strcasecmp(var, "tts_voice")) {
+ tts_voice= val;
+ } else if (!strcasecmp(var, "enter_sound")) {
+ enter_sound = val;
+ } else if (!strcasecmp(var, "exit_sound")) {
+ exit_sound = val;
+ } else if (!strcasecmp(var, "alone_sound")) {
+ alone_sound = val;
+ } else if (!strcasecmp(var, "ack_sound")) {
+ ack_sound = val;
+ } else if (!strcasecmp(var, "nack_sound")) {
+ nack_sound = val;
+ } else if (!strcasecmp(var, "muted_sound")) {
+ muted_sound = val;
+ } else if (!strcasecmp(var, "unmuted_sound")) {
+ unmuted_sound = val;
+ } else if (!strcasecmp(var, "locked_sound")) {
+ locked_sound= val;
+ } else if (!strcasecmp(var, "kicked_sound")) {
+ kicked_sound = val;
+ } else if (!strcasecmp(var, "pin")) {
+ pin = val;
+ } else if (!strcasecmp(var, "pin_sound")) {
+ pin_sound = val;
+ } else if (!strcasecmp(var, "bad_pin_sound")) {
+ bad_pin_sound = val;
+ } else if (!strcasecmp(var, "energy_level")) {
+ energy_level = val;
+ } else if (!strcasecmp(var, "caller_id_name")) {
+ caller_id_name = val;
+ } else if (!strcasecmp(var, "caller_id_number")) {
+ caller_id_number = val;
+ }
+ }
+
+ /* Set defaults and various paramaters */
+
+ /* Speed in hertz */
+ if (!switch_strlen_zero(rate_name)) {
+ uint32_t r = atoi(rate_name);
+ if (r) {
+ rate = r;
+ }
+ }
+
+ /* Packet Interval in milliseconds */
+ if (!switch_strlen_zero(interval_name)) {
+ uint32_t i = atoi(interval_name);
+ if (i) {
+ interval = i;
+ }
+ }
+
+ /* Timer module to use */
+ if (switch_strlen_zero(timer_name)) {
+ timer_name = "soft";
+ }
+
+ /* TTS engine to use */
+ if (switch_strlen_zero(tts_engine)) {
+ tts_engine = "cepstral";
+ }
+
+ /* TTS voice to use */
+ if (switch_strlen_zero(tts_voice)) {
+ tts_voice = "david";
+ }
+
+ /* Caller ID Name */
+ if (switch_strlen_zero(caller_id_name)) {
+ caller_id_name = (char *) global_app_name;
+ }
+
+ /* Caller ID Number */
+ if (switch_strlen_zero(caller_id_number)) {
+ caller_id_number = "0000000000";
+ }
+
+ if (!pool) {
+ /* Setup a memory pool to use. */
+ if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+ status = SWITCH_STATUS_TERM;
+ return NULL;
+ }
+ }
+
+ /* Create the conference object. */
+ if (!(conference = switch_core_alloc(pool, sizeof(*conference)))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
+ status = SWITCH_STATUS_TERM;
+ return NULL;
+ }
+
+ /* Initilize the object with some settings */
+ conference->pool = pool;
+ conference->timer_name = switch_core_strdup(conference->pool, timer_name);
+ conference->tts_engine = switch_core_strdup(conference->pool, tts_engine);
+ conference->tts_voice = switch_core_strdup(conference->pool, tts_voice);
+
+ conference->caller_id_name = switch_core_strdup(conference->pool, caller_id_name);
+ conference->caller_id_number = switch_core_strdup(conference->pool, caller_id_number);
+
+ if (!switch_strlen_zero(enter_sound)) {
+ conference->enter_sound = switch_core_strdup(conference->pool, enter_sound);
+ }
+
+ if (!switch_strlen_zero(exit_sound)) {
+ conference->exit_sound = switch_core_strdup(conference->pool, exit_sound);
+ }
+
+ if (!switch_strlen_zero(ack_sound)) {
+ conference->ack_sound = switch_core_strdup(conference->pool, ack_sound);
+ }
+
+ if (!switch_strlen_zero(nack_sound)) {
+ conference->nack_sound = switch_core_strdup(conference->pool, nack_sound);
+ }
+
+ if (!switch_strlen_zero(muted_sound)) {
+ conference->muted_sound = switch_core_strdup(conference->pool, muted_sound);
+ }
+
+ if (!switch_strlen_zero(unmuted_sound)) {
+ conference->unmuted_sound = switch_core_strdup(conference->pool, unmuted_sound);
+ }
+
+ if (!switch_strlen_zero(kicked_sound)) {
+ conference->kicked_sound = switch_core_strdup(conference->pool, kicked_sound);
+ }
+
+ if (!switch_strlen_zero(pin_sound)) {
+ conference->pin_sound = switch_core_strdup(conference->pool, pin_sound);
+ }
+
+ if (!switch_strlen_zero(bad_pin_sound)) {
+ conference->bad_pin_sound = switch_core_strdup(conference->pool, bad_pin_sound);
+ }
+
+ if (!switch_strlen_zero(pin)) {
+ conference->pin = switch_core_strdup(conference->pool, pin);
+ }
+
+ if (!switch_strlen_zero(alone_sound)) {
+ conference->alone_sound = switch_core_strdup(conference->pool, alone_sound);
+ }
+
+ if (!switch_strlen_zero(locked_sound)) {
+ conference->locked_sound = switch_core_strdup(conference->pool, locked_sound);
+ }
+
+ if (!switch_strlen_zero(energy_level)) {
+ conference->energy_level = atoi(energy_level);
+ }
+
+ conference->name = switch_core_strdup(conference->pool, name);
+ conference->rate = rate;
+ conference->interval = interval;
+
+
+ /* Activate the conference mutex for exclusivity */
+ switch_mutex_init(&conference->mutex, SWITCH_MUTEX_NESTED, conference->pool);
+ switch_mutex_init(&conference->member_mutex, SWITCH_MUTEX_NESTED, conference->pool);
+ switch_mutex_init(&conference->flag_mutex, SWITCH_MUTEX_NESTED, conference->pool);
+ switch_thread_rwlock_create(&conference->rwlock, conference->pool);
+
+ return conference;
+}
+
+/* Called by FreeSWITCH when the module loads */
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
+{
+ switch_xml_t cfg, cxml, room, rooms, profiles, profile = NULL;
+ conference_obj_t *conference;
+ switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+ memset(&globals, 0, sizeof(globals));
+
+ /* Connect my internal structure to the blank pointer passed to me */
+ *module_interface = &conference_module_interface;
+
+ if (switch_event_reserve_subclass(CONF_EVENT_MAINT) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass %s!", CONF_EVENT_MAINT);
+ return SWITCH_STATUS_TERM;
+ }
+
+ /* Setup the pool */
+ if (switch_core_new_memory_pool(&globals.conference_pool) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no conference pool\n");
+ return SWITCH_STATUS_TERM;
+ }
+
+ /* Open the config from the xml registry */
+ if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
+ return SWITCH_STATUS_TERM;
+ }
+
+ /* Setup a hash to store conferences by name */
+ switch_core_hash_init(&globals.conference_hash, globals.conference_pool);
+ switch_mutex_init(&globals.conference_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
+ switch_mutex_init(&globals.id_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
+ switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
+
+ /* Itterate the config */
+ if ((rooms = switch_xml_child(cfg, "rooms"))) {
+ /* Parse various rooms. */
+ for (room = switch_xml_child(rooms, "room"); room; room = room->next) {
+ char *name = (char *) switch_xml_attr_soft(room, "name");
+ char *pname = (char *) switch_xml_attr_soft(room, "profile");
+
+ if ((profiles = switch_xml_child(cfg, "profiles"))) {
+ profile = switch_xml_find_child(profiles, "profile", "name", pname);
+ }
+
+ if ((conference = conference_new(name, profile, NULL))) {
+ /* Start the conference thread for this conference */
+ launch_conference_thread(conference);
+ }
+ }
+ }
+
+ /* Release the config registry handle */
+ switch_xml_free(cxml);
+
+ /* indicate that the module should continue to be loaded */
+ return status;
+}
diff --git a/src/mod/applications/mod_conference/mod_conference.vcproj b/src/mod/applications/mod_conference/mod_conference.vcproj
new file mode 100755
index 0000000000..7d33769a5c
--- /dev/null
+++ b/src/mod/applications/mod_conference/mod_conference.vcproj
@@ -0,0 +1,209 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/w32/vsnet/Freeswitch.sln b/w32/vsnet/Freeswitch.sln
index 0b7edc49f2..d54590b4de 100644
--- a/w32/vsnet/Freeswitch.sln
+++ b/w32/vsnet/Freeswitch.sln
@@ -208,6 +208,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_rss", "..\..\src\mod\ap
{202D7A4E-760D-4D0E-AFA1-D7459CED30FF} = {202D7A4E-760D-4D0E-AFA1-D7459CED30FF}
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_conference", "..\..\src\mod\applications\mod_conference\mod_conference.vcproj", "{C24FB505-05D7-4319-8485-7540B44C8603}"
+ ProjectSection(ProjectDependencies) = postProject
+ {202D7A4E-760D-4D0E-AFA1-D7459CED30FF} = {202D7A4E-760D-4D0E-AFA1-D7459CED30FF}
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -354,6 +359,10 @@ Global
{B69247FA-ECD6-40ED-8E44-5CA6C3BAF9A4}.Debug|Win32.Build.0 = Debug|Win32
{B69247FA-ECD6-40ED-8E44-5CA6C3BAF9A4}.Release|Win32.ActiveCfg = Release|Win32
{B69247FA-ECD6-40ED-8E44-5CA6C3BAF9A4}.Release|Win32.Build.0 = Release|Win32
+ {C24FB505-05D7-4319-8485-7540B44C8603}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C24FB505-05D7-4319-8485-7540B44C8603}.Debug|Win32.Build.0 = Debug|Win32
+ {C24FB505-05D7-4319-8485-7540B44C8603}.Release|Win32.ActiveCfg = Release|Win32
+ {C24FB505-05D7-4319-8485-7540B44C8603}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -376,6 +385,7 @@ Global
{0E2C6395-13B9-46E5-9264-8859D346018D} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
{30A5B29C-983E-4580-9FD0-D647CCDCC7EB} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
{B69247FA-ECD6-40ED-8E44-5CA6C3BAF9A4} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
+ {C24FB505-05D7-4319-8485-7540B44C8603} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
{3A5B9131-F20C-4A85-9447-6C1610941CEE} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C}
{5FD31A25-5D83-4794-8BEE-904DAD84CE71} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C}
{FE3540C5-3303-46E0-A69E-D92F775687F1} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C}