static switch_status_t skinny_api_list_stimulus_instances(const char *line, const char *cursor, switch_console_callback_match_t **matches) { switch_status_t status = SWITCH_STATUS_FALSE; switch_console_callback_match_t *my_matches = NULL; switch_console_push_match(&my_matches, "<stimulus_instance>"); switch_console_push_match(&my_matches, "0"); if (my_matches) { *matches = my_matches; status = SWITCH_STATUS_SUCCESS; } return status; }
static switch_status_t skinny_api_list_call_ids(const char *line, const char *cursor, switch_console_callback_match_t **matches) { switch_status_t status = SWITCH_STATUS_FALSE; switch_console_callback_match_t *my_matches = NULL; /* TODO */ switch_console_push_match(&my_matches, "1345"); switch_console_push_match(&my_matches, "<call_id>"); if (my_matches) { *matches = my_matches; status = SWITCH_STATUS_SUCCESS; } return status; }
static switch_status_t skinny_api_list_profiles(const char *line, const char *cursor, switch_console_callback_match_t **matches) { switch_console_callback_match_t *my_matches = NULL; switch_status_t status = SWITCH_STATUS_FALSE; switch_hash_index_t *hi; void *val; skinny_profile_t *profile; /* walk profiles */ switch_mutex_lock(globals.mutex); for (hi = switch_core_hash_first( globals.profile_hash); hi; hi = switch_core_hash_next(hi)) { switch_core_hash_this(hi, NULL, NULL, &val); profile = (skinny_profile_t *) val; switch_console_push_match(&my_matches, profile->name); } switch_mutex_unlock(globals.mutex); if (my_matches) { *matches = my_matches; status = SWITCH_STATUS_SUCCESS; } return status; }
static int skinny_api_list_devices_callback(void *pArg, int argc, char **argv, char **columnNames) { struct match_helper *h = (struct match_helper *) pArg; char *device_name = argv[0]; switch_console_push_match(&h->my_matches, device_name); return 0; }
static void check_timeouts(void) { switch_hash_index_t *hi; const void *var; void *val; time_t now; valet_lot_t *lot; switch_console_callback_match_t *matches = NULL; switch_console_callback_match_node_t *m; switch_hash_index_t *i_hi; const void *i_var; void *i_val; char *i_ext; valet_token_t *token; now = switch_epoch_time_now(NULL); switch_mutex_lock(globals.mutex); if (now - globals.last_timeout_check < TOKEN_FREQ) { switch_mutex_unlock(globals.mutex); return; } globals.last_timeout_check = now; 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); } switch_mutex_unlock(globals.mutex); if (matches) { for (m = matches->head; m; m = m->next) { lot = valet_find_lot(m->val, SWITCH_FALSE); switch_mutex_lock(lot->mutex); top: for (i_hi = switch_hash_first(NULL, lot->hash); i_hi; i_hi = switch_hash_next(i_hi)) { switch_hash_this(i_hi, &i_var, NULL, &i_val); i_ext = (char *) i_var; token = (valet_token_t *) i_val; if (token->timeout > 0 && (token->timeout < now || token->timeout == 1)) { switch_core_hash_delete(lot->hash, i_ext); switch_safe_free(token); goto top; } } switch_mutex_unlock(lot->mutex); } switch_console_free_matches(&matches); } }
static int skinny_api_list_devices_show_callback(void *pArg, int argc, char **argv, char **columnNames) { struct match_helper *h = (struct match_helper *) pArg; int i; for(i = 0; i < argc; i++){ if(argv[i] == NULL) argv[i] = "0\0"; switch_console_push_match(&h->my_matches, argv[i]); } return 0; }
static switch_status_t api_complete_erlang_node(const char *line, const char *cursor, switch_console_callback_match_t **matches) { switch_console_callback_match_t *my_matches = NULL; switch_status_t status = SWITCH_STATUS_FALSE; ei_node_t *ei_node; switch_thread_rwlock_rdlock(globals.ei_nodes_lock); ei_node = globals.ei_nodes; while(ei_node != NULL) { switch_console_push_match(&my_matches, ei_node->peer_nodename); ei_node = ei_node->next; } switch_thread_rwlock_unlock(globals.ei_nodes_lock); if (my_matches) { *matches = my_matches; status = SWITCH_STATUS_SUCCESS; } return status; }
static void pres_event_handler(switch_event_t *event) { char *to = switch_event_get_header(event, "to"); char *dup_to = NULL, *lot_name, *dup_lot_name = NULL, *domain_name; valet_lot_t *lot; int found = 0; if (!to || strncasecmp(to, "park+", 5) || !strchr(to, '@')) { return; } if (!(dup_to = strdup(to))) { return; } lot_name = dup_to + 5; if ((domain_name = strchr(lot_name, '@'))) { *domain_name++ = '\0'; } dup_lot_name = switch_mprintf("%q@%q", lot_name, domain_name); 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); 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, "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", lot_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", "confirmed"); 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); 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_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", lot_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); } } } else { switch_console_callback_match_t *matches = NULL; switch_console_callback_match_node_t *m; 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); 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; !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)) && !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); 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", 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_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", lot_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", token->bridged == 0 ? "early" : "confirmed"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", token->bridged == 0 ? "outbound" : "inbound"); switch_event_fire(&event); } } switch_mutex_unlock(lot->mutex); } } } 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); 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_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", lot_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); } switch_safe_free(dup_to); switch_safe_free(dup_lot_name); }
static switch_status_t skinny_api_list_settings(const char *line, const char *cursor, switch_console_callback_match_t **matches) { switch_status_t status = SWITCH_STATUS_FALSE; switch_console_callback_match_t *my_matches = NULL; switch_console_push_match(&my_matches, "domain"); switch_console_push_match(&my_matches, "ip"); switch_console_push_match(&my_matches, "port"); switch_console_push_match(&my_matches, "patterns-dialplan"); switch_console_push_match(&my_matches, "patterns-context"); switch_console_push_match(&my_matches, "dialplan"); switch_console_push_match(&my_matches, "context"); switch_console_push_match(&my_matches, "keep-alive"); switch_console_push_match(&my_matches, "date-format"); switch_console_push_match(&my_matches, "odbc-dsn"); switch_console_push_match(&my_matches, "debug"); switch_console_push_match(&my_matches, "auto-restart"); switch_console_push_match(&my_matches, "ext-voicemail"); switch_console_push_match(&my_matches, "ext-redial"); switch_console_push_match(&my_matches, "ext-meetme"); switch_console_push_match(&my_matches, "ext-pickup"); switch_console_push_match(&my_matches, "ext-cfwdall"); if (my_matches) { *matches = my_matches; status = SWITCH_STATUS_SUCCESS; } return status; }