cc_status_t cc_agent_get(const char *key, const char *agent, char *ret_result, size_t ret_result_size) { cc_status_t result = CC_STATUS_SUCCESS; char *sql; switch_event_t *event; char res[256]; /* Check to see if agent already exists */ sql = switch_mprintf("SELECT count(*) FROM agents WHERE name = '%q'", agent); cc_execute_sql2str(NULL, NULL, sql, res, sizeof(res)); switch_safe_free(sql); if (atoi(res) == 0) { result = CC_STATUS_AGENT_NOT_FOUND; goto done; } if (!strcasecmp(key, "status") || !strcasecmp(key, "state") || !strcasecmp(key, "uuid") ) { /* Check to see if agent already exists */ sql = switch_mprintf("SELECT %q FROM agents WHERE name = '%q'", key, agent); cc_execute_sql2str(NULL, NULL, sql, res, sizeof(res)); switch_safe_free(sql); switch_snprintf(ret_result, ret_result_size, "%s", res); result = CC_STATUS_SUCCESS; if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CALLCENTER_EVENT) == SWITCH_STATUS_SUCCESS) { char tmpname[256]; if (!strcasecmp(key, "uuid")) { switch_snprintf(tmpname, sizeof(tmpname), "CC-Agent-UUID"); } else { switch_snprintf(tmpname, sizeof(tmpname), "CC-Agent-%c%s", (char) switch_toupper(key[0]), key+1); } switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "CC-Agent", agent); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "CC-Action", "agent-%s-get", key); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, tmpname, res); switch_event_fire(&event); } } else { result = CC_STATUS_INVALID_KEY; goto done; } done: if (result == CC_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Get Info Agent %s %s = %s\n", agent, key, res); } return result; }
static switch_status_t setup_formats(void) { SF_FORMAT_INFO info; char buffer[128]; int format, major_count, subtype_count, m, s; int len, x, skip; char *extras[] = { "r8", "r16", "r24", "r32", "gsm", "ul", "ulaw", "al", "alaw", "adpcm", "vox", NULL }; int exlen = (sizeof(extras) / sizeof(extras[0])); buffer[0] = 0; sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer)); if (strlen(buffer) < 1) { switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Line %d: could not retrieve lib version.\n", __LINE__); return SWITCH_STATUS_FALSE; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "\nLibSndFile Version : %s Supported Formats\n", buffer); switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "================================================================================\n"); sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof(int)); sf_command(NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof(int)); //sfinfo.channels = 1; len = ((major_count + (exlen + 2)) * sizeof(char *)); supported_formats = switch_core_permanent_alloc(len); len = 0; for (m = 0; m < major_count; m++) { skip = 0; info.format = m; sf_command(NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof(info)); switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s (extension \"%s\")\n", info.name, info.extension); for (x = 0; x < len; x++) { if (supported_formats[x] == info.extension) { skip++; break; } } if (!skip) { char *p; struct format_map *map = switch_core_permanent_alloc(sizeof(*map)); switch_assert(map); map->ext = switch_core_permanent_strdup(info.extension); map->uext = switch_core_permanent_strdup(info.extension); map->format = info.format; if (map->ext) { for (p = map->ext; *p; p++) { *p = (char) switch_tolower(*p); } switch_core_hash_insert(globals.format_hash, map->ext, map); } if (map->uext) { for (p = map->uext; *p; p++) { *p = (char) switch_toupper(*p); } switch_core_hash_insert(globals.format_hash, map->uext, map); } supported_formats[len++] = (char *) info.extension; } format = info.format; for (s = 0; s < subtype_count; s++) { info.format = s; sf_command(NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof(info)); format = (format & SF_FORMAT_TYPEMASK) | info.format; //sfinfo.format = format; /* if (sf_format_check(&sfinfo)) { switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, " %s\n", info.name); } */ } } for (m = 0; m < exlen; m++) { supported_formats[len++] = extras[m]; } switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_NOTICE, "================================================================================\n"); return SWITCH_STATUS_SUCCESS; }