static void conference_list(conference_obj_t *conference, switch_stream_handle_t *stream, char *delim);
static conference_obj_t *conference_find(char *name);
static void member_bind_controls(conference_member_t *member, const char *controls);
+static void conference_send_presence(conference_obj_t *conference);
SWITCH_STANDARD_API(conf_api_main);
if (conference->end_count++);
}
- if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", conference->name);
- if (strchr(conference->name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", conference->name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
- }
-
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "force-status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", conference->name);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_ROUTING");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", conference->count == 1 ? "early" : "confirmed");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-direction", conference->count == 1 ? "outbound" : "inbound");
- switch_event_fire(&event);
- }
+ conference_send_presence(conference);
channel = switch_core_session_get_channel(member->session);
switch_channel_set_variable_printf(channel, "conference_member_id", "%d", member->id);
}
- if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", conference->name);
- if (strchr(conference->name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", conference->name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
- }
-
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "force-status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", conference->name);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_ROUTING");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", conference->count == 1 ? "early" : "confirmed");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", conference->count == 1 ? "outbound" : "inbound");
- switch_event_fire(&event);
- }
+ conference_send_presence(conference);
if ((conference->min && switch_test_flag(conference, CFLAG_ENFORCE_MIN) && conference->count < conference->min)
|| (switch_test_flag(conference, CFLAG_DYNAMIC) && conference->count == 0)) {
}
}
- if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", conference->name);
- if (strchr(conference->name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", conference->name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
- }
-
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", "Inactive");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", conference->name);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "terminated");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", "inbound");
- switch_event_fire(&event);
- }
+ conference_send_presence(conference);
switch_mutex_lock(conference->mutex);
conference_stop_file(conference, FILE_STOP_ASYNC);
return conference;
}
+static void conference_send_presence(conference_obj_t *conference)
+{
+ switch_event_t *event;
+
+ if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", conference->name);
+ if (strchr(conference->name, '@')) {
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", conference->name);
+ } else {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
+ }
+
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", conference->name);
+
+ if (conference->count) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "force-status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_ROUTING");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", conference->count == 1 ? "early" : "confirmed");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-direction", conference->count == 1 ? "outbound" : "inbound");
+ } else {
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", "Inactive");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "terminated");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", "inbound");
+ }
+
+
+
+ switch_event_fire(&event);
+ }
+
+}
+
+
static void pres_event_handler(switch_event_t *event)
{
char *to = switch_event_get_header(event, "to");
- char *dup_to = NULL, *conf_name;
+ char *domain_name = NULL;
+ char *dup_to = NULL, *conf_name, *dup_conf_name = NULL;
conference_obj_t *conference;
- if (!to || strncasecmp(to, "conf+", 5)) {
+ if (!to || strncasecmp(to, "conf+", 5) || !strchr(to, '@')) {
return;
}
if (!(dup_to = strdup(to))) {
return;
}
+
conf_name = dup_to + 5;
- if ((conference = conference_find(conf_name))) {
+ if ((domain_name = strchr(conf_name, '@'))) {
+ *domain_name++ = '\0';
+ }
+
+ dup_conf_name = switch_mprintf("%q@%q", conf_name, domain_name);
+
+
+ if ((conference = conference_find(conf_name)) || (conference = conference_find(dup_conf_name))) {
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", conference->name);
- if (strchr(conference->name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", conference->name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
- }
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", conference->name, conference->domain);
+
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "force-status", "Active (%d caller%s)", conference->count, conference->count == 1 ? "" : "s");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
}
switch_safe_free(dup_to);
+ switch_safe_free(dup_conf_name);
}
static void send_presence(switch_event_types_t id)
outbound_strategy_t outbound_strategy;
int ring_timeout;
int default_lag;
+ char *domain_name;
};
typedef struct fifo_node fifo_node_t;
char outbound_count[80] = "";
callback_t cbt = { 0 };
char *sql = NULL;
-
+ char *domain_name = NULL;
+
if (!globals.running) {
return NULL;
}
node->pool = pool;
node->outbound_strategy = default_strategy;
node->name = switch_core_strdup(node->pool, name);
+
+ if (!strchr(name, '@')) {
+ domain_name = switch_core_get_variable_dup("domain");
+ node->domain_name = switch_core_strdup(node->pool, domain_name);
+ }
+
for (x = 0; x < MAX_PRI; x++) {
fifo_queue_create(&node->fifo_list[x], 1000, node->pool);
switch_assert(node->fifo_list[x]);
switch_mutex_lock(globals.mutex);
switch_core_hash_insert(globals.fifo_hash, name, node);
switch_mutex_unlock(globals.mutex);
+
+ switch_safe_free(domain_name);
+
return node;
}
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "queue");
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", node->name);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", node->name);
+
+ if (node->domain_name) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s@%s", node->name, node->domain_name);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", node->name, node->domain_name);
+ } else {
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", node->name);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", node->name);
+ }
+
if ((wait_count = node_caller_count(node)) > 0) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d waiting)", wait_count);
} else {
static void pres_event_handler(switch_event_t *event)
{
char *to = switch_event_get_header(event, "to");
- char *dup_to = NULL, *node_name;
+ char *domain_name = NULL;
+ char *dup_to = NULL, *node_name , *dup_node_name;
fifo_node_t *node;
if (!globals.running) {
return;
}
- if (!to || strncasecmp(to, "queue+", 5)) {
+ if (!to || strncasecmp(to, "queue+", 6) || !strchr(to, '@')) {
return;
}
dup_to = strdup(to);
switch_assert(dup_to);
- node_name = dup_to + 5;
+ node_name = dup_to + 6;
+
+ if ((domain_name = strchr(node_name, '@'))) {
+ *domain_name++ = '\0';
+ }
+
+ dup_node_name = switch_mprintf("%q@%q", node_name, domain_name);
+
switch_mutex_lock(globals.mutex);
- if (!(node = switch_core_hash_find(globals.fifo_hash, node_name))) {
+ if (!(node = switch_core_hash_find(globals.fifo_hash, node_name)) && !(node = switch_core_hash_find(globals.fifo_hash, dup_node_name))) {
node = create_node(node_name, 0, globals.sql_mutex);
+ node->domain_name = switch_core_strdup(node->pool, domain_name);
node->ready = 1;
}
switch_mutex_unlock(globals.mutex);
switch_safe_free(dup_to);
+ switch_safe_free(dup_node_name);
}
static uint32_t fifo_add_outbound(const char *node_name, const char *url, uint32_t priority)
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
time_t last_timeout_check;
+ char *name;
} valet_lot_t;
static valet_lot_t globals = { 0 };
lot = switch_core_hash_find(globals.hash, name);
if (!lot && create) {
switch_zmalloc(lot, sizeof(*lot));
+ lot->name = strdup(name);
switch_mutex_init(&lot->mutex, SWITCH_MUTEX_NESTED, globals.pool);
switch_core_hash_init(&lot->hash, NULL);
switch_core_hash_insert(globals.hash, name, lot);
static void valet_send_presence(const char *lot_name, valet_lot_t *lot, valet_token_t *token, switch_bool_t in)
{
- char *domain_name, *dup_domain_name = NULL;
+ char *domain_name, *dup_lot_name = NULL, *dup_domain_name = NULL;
switch_event_t *event;
int count;
- if ((domain_name = strchr(lot_name, '@'))) {
- domain_name++;
+
+ dup_lot_name = strdup(lot_name);
+ lot_name = dup_lot_name;
+
+ if ((domain_name = strchr(dup_lot_name, '@'))) {
+ *domain_name++ = '\0';
}
if (zstr(domain_name)) {
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", lot_name);
- if (strchr(lot_name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", lot_name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
- }
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
+
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "force-status", "Active (%d caller%s)", count, count == 1 ? "" : "s");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "active");
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", lot_name);
- if (strchr(lot_name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", lot_name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
- }
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
+
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", "Empty");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
}
switch_safe_free(dup_domain_name);
+ switch_safe_free(dup_lot_name);
}
static void pres_event_handler(switch_event_t *event)
{
char *to = switch_event_get_header(event, "to");
- char *dup_to = NULL, *lot_name, *domain_name, *dup_domain_name = NULL;
+ char *dup_to = NULL, *lot_name, *dup_lot_name = NULL, *domain_name;
valet_lot_t *lot;
-
-
- if (!to || strncasecmp(to, "park+", 5)) {
+ int found = 0;
+
+ if (!to || strncasecmp(to, "park+", 5) || !strchr(to, '@')) {
return;
}
lot_name = dup_to + 5;
if ((domain_name = strchr(lot_name, '@'))) {
- domain_name++;
+ *domain_name++ = '\0';
}
- if (zstr(domain_name)) {
- dup_domain_name = switch_core_get_variable_dup("domain");
- domain_name = dup_domain_name;
- }
+ dup_lot_name = switch_mprintf("%q@%q", lot_name, domain_name);
- if (zstr(domain_name)) {
- domain_name = "cluecon.com";
- }
-
- if ((lot = valet_find_lot(lot_name, SWITCH_FALSE))) {
+ if ((lot = valet_find_lot(lot_name, SWITCH_FALSE)) || (dup_lot_name && (lot = valet_find_lot(dup_lot_name, SWITCH_FALSE)))) {
int count = valet_lot_count(lot);
-
+
if (count) {
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", lot_name);
- if (strchr(lot_name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", lot_name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
- }
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
+
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "force-status", "Active (%d caller%s)", count, count == 1 ? "" : "s");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "active");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", "inbound");
switch_event_fire(&event);
}
+ found++;
}
} else {
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO);
- if (strchr(lot_name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", lot_name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
- }
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", "Empty");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
switch_hash_index_t *hi;
const void *var;
void *val;
+ const char *nvar;
switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, globals.hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
- switch_console_push_match(&matches, (const char *) var);
+ nvar = (const char *) var;
+
+ if (!strchr(nvar, '@') || switch_stristr(domain_name, nvar)) {
+ switch_console_push_match(&matches, nvar);
+ }
}
switch_mutex_unlock(globals.mutex);
if (matches) {
valet_token_t *token;
- for (m = matches->head; m; m = m->next) {
+ for (m = matches->head; !found && m; m = m->next) {
lot = valet_find_lot(m->val, SWITCH_FALSE);
switch_mutex_lock(lot->mutex);
-
- if ((token = (valet_token_t *) switch_core_hash_find(lot->hash, lot_name))) {
+
+ if ((token = (valet_token_t *) switch_core_hash_find(lot->hash, lot_name)) && !token->timeout) {
+ found++;
+
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", lot_name);
- if (strchr(lot_name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", lot_name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
- }
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", "Active");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", token->bridged == 0 ? "Holding" : "Active");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++);
switch_mutex_unlock(lot->mutex);
}
}
-
}
- if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+ if (!found && switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", lot_name);
- if (strchr(lot_name, '@')) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", lot_name);
- } else {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
- }
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name);
+
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", "Empty");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
}
switch_safe_free(dup_to);
- switch_safe_free(dup_domain_name);
+ switch_safe_free(dup_lot_name);
}
/* Macro expands to: switch_status_t mod_valet_parking_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */