/*ARGSUSED*/ static void profile_provide(void *arg, const dtrace_probedesc_t *desc) { int i, j, rate, kind; hrtime_t val = 0, mult = 1, len; const char *name, *suffix = NULL; const struct { char *prefix; int kind; } types[] = { { PROF_PREFIX_PROFILE, PROF_PROFILE }, { PROF_PREFIX_TICK, PROF_TICK }, { NULL, NULL } }; const struct { char *name; hrtime_t mult; } suffixes[] = { { "ns", NANOSEC / NANOSEC }, { "nsec", NANOSEC / NANOSEC }, { "us", NANOSEC / MICROSEC }, { "usec", NANOSEC / MICROSEC }, { "ms", NANOSEC / MILLISEC }, { "msec", NANOSEC / MILLISEC }, { "s", NANOSEC / SEC }, { "sec", NANOSEC / SEC }, { "m", NANOSEC * (hrtime_t)60 }, { "min", NANOSEC * (hrtime_t)60 }, { "h", NANOSEC * (hrtime_t)(60 * 60) }, { "hour", NANOSEC * (hrtime_t)(60 * 60) }, { "d", NANOSEC * (hrtime_t)(24 * 60 * 60) }, { "day", NANOSEC * (hrtime_t)(24 * 60 * 60) }, { "hz", 0 }, { NULL } }; if (desc == NULL) { char n[PROF_NAMELEN]; /* * If no description was provided, provide all of our probes. */ for (i = 0; i < sizeof (profile_rates) / sizeof (int); i++) { if ((rate = profile_rates[i]) == 0) continue; (void) snprintf(n, PROF_NAMELEN, "%s%d", PROF_PREFIX_PROFILE, rate); profile_create(NANOSEC / rate, n, PROF_PROFILE); } for (i = 0; i < sizeof (profile_ticks) / sizeof (int); i++) { if ((rate = profile_ticks[i]) == 0) continue; (void) snprintf(n, PROF_NAMELEN, "%s%d", PROF_PREFIX_TICK, rate); profile_create(NANOSEC / rate, n, PROF_TICK); } return; } name = desc->dtpd_name; for (i = 0; types[i].prefix != NULL; i++) { len = strlen(types[i].prefix); if (strncmp(name, types[i].prefix, len) != 0) continue; break; } if (types[i].prefix == NULL) return; kind = types[i].kind; j = strlen(name) - len; /* * We need to start before any time suffix. */ for (j = strlen(name); j >= len; j--) { if (name[j] >= '0' && name[j] <= '9') break; suffix = &name[j]; } ASSERT(suffix != NULL); /* * Now determine the numerical value present in the probe name. */ for (; j >= len; j--) { if (name[j] < '0' || name[j] > '9') return; val += (name[j] - '0') * mult; mult *= (hrtime_t)10; } if (val == 0) return; /* * Look-up the suffix to determine the multiplier. */ for (i = 0, mult = 0; suffixes[i].name != NULL; i++) { if (strcasecmp(suffixes[i].name, suffix) == 0) { mult = suffixes[i].mult; break; } } if (suffixes[i].name == NULL && *suffix != '\0') return; if (mult == 0) { /* * The default is frequency-per-second. */ val = NANOSEC / val; } else { val *= mult; } profile_create(val, name, kind); }
int load_mrcp_config(const char *filename, const char *who_asked) { const char *cat = NULL; struct ast_variable *var; const char *value = NULL; #if AST_VERSION_AT_LEAST(1,6,0) struct ast_flags config_flags = { 0 }; struct ast_config *cfg = ast_config_load2(filename, who_asked, config_flags); #else struct ast_config *cfg = ast_config_load(filename); #endif if (!cfg) { ast_log(LOG_WARNING, "No such configuration file %s\n", filename); return -1; } #if AST_VERSION_AT_LEAST(1,6,2) if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_ERROR, "Config file %s is in an invalid format\n", filename); return -1; } #endif globals_clear(); globals_default(); if ((value = ast_variable_retrieve(cfg, "general", "default-tts-profile")) != NULL) { ast_log(LOG_DEBUG, "general.default-tts-profile=%s\n", value); globals.unimrcp_default_synth_profile = apr_pstrdup(globals.pool, value); } else { ast_log(LOG_ERROR, "Unable to load genreal.default-tts-profile from config file, aborting\n"); ast_config_destroy(cfg); return -1; } if ((value = ast_variable_retrieve(cfg, "general", "default-asr-profile")) != NULL) { ast_log(LOG_DEBUG, "general.default-asr-profile=%s\n", value); globals.unimrcp_default_recog_profile = apr_pstrdup(globals.pool, value); } else { ast_log(LOG_ERROR, "Unable to load genreal.default-asr-profile from config file, aborting\n"); ast_config_destroy(cfg); return -1; } if ((value = ast_variable_retrieve(cfg, "general", "log-level")) != NULL) { ast_log(LOG_DEBUG, "general.log-level=%s\n", value); globals.unimrcp_log_level = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "max-connection-count")) != NULL) { ast_log(LOG_DEBUG, "general.max-connection-count=%s\n", value); globals.unimrcp_max_connection_count = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "offer-new-connection")) != NULL) { ast_log(LOG_DEBUG, "general.offer-new-connection=%s\n", value); globals.unimrcp_offer_new_connection = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "rx-buffer-size")) != NULL) { ast_log(LOG_DEBUG, "general.rx-buffer-size=%s\n", value); globals.unimrcp_rx_buffer_size = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "tx-buffer-size")) != NULL) { ast_log(LOG_DEBUG, "general.tx-buffer-size=%s\n", value); globals.unimrcp_tx_buffer_size = apr_pstrdup(globals.pool, value); } if ((value = ast_variable_retrieve(cfg, "general", "request-timeout")) != NULL) { ast_log(LOG_DEBUG, "general.request-timeout=%s\n", value); globals.unimrcp_request_timeout = apr_pstrdup(globals.pool, value); } while ((cat = ast_category_browse(cfg, cat)) != NULL) { if (strcasecmp(cat, "general") != 0) { if ((value = ast_variable_retrieve(cfg, cat, "version")) != NULL) { ast_mrcp_profile_t *mod_profile = NULL; if (profile_create(&mod_profile, cat, value, globals.pool) == 0) { apr_hash_set(globals.profiles, apr_pstrdup(globals.pool, mod_profile->name), APR_HASH_KEY_STRING, mod_profile); for (var = ast_variable_browse(cfg, cat); var; var = var->next) { ast_log(LOG_DEBUG, "%s.%s=%s\n", cat, var->name, var->value); apr_hash_set(mod_profile->cfg, apr_pstrdup(globals.pool, var->name), APR_HASH_KEY_STRING, apr_pstrdup(globals.pool, var->value)); } } else ast_log(LOG_WARNING, "Unable to create a profile for %s\n", cat); } else ast_log(LOG_WARNING, "Category %s does not have a version variable defined\n", cat); } } ast_config_destroy(cfg); return 0; }