static void event_handler(switch_event_t *event) { const char *dest_proto = switch_event_get_header(event, "dest_proto"); const char *check_failure = switch_event_get_header(event, "Delivery-Failure"); const char *check_nonblocking = switch_event_get_header(event, "Nonblocking-Delivery"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "skip_global_process", "true"); if (switch_true(check_failure)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Delivery Failure\n"); DUMP_EVENT(event); send_report(event, "Failure"); return; } else if ( check_failure && switch_false(check_failure) ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SMS Delivery Success\n"); send_report(event, "Success"); return; } else if ( check_nonblocking && switch_true(check_nonblocking) ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SMS Delivery assumed successful due to being sent in non-blocking manner\n"); send_report(event, "Accepted"); return; } switch_core_chat_send(dest_proto, event); }
/** * Configure the module * @param cache to configure * @return SWITCH_STATUS_SUCCESS if successful */ static switch_status_t do_config(url_cache_t *cache) { char *cf = "http_cache.conf"; switch_xml_t cfg, xml, param, settings; switch_status_t status = SWITCH_STATUS_SUCCESS; int max_urls; switch_time_t default_max_age_sec; if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); return SWITCH_STATUS_TERM; } /* set default config */ max_urls = 4000; default_max_age_sec = 86400; cache->location = SWITCH_PREFIX_DIR "/http_cache"; cache->prefetch_queue_size = 100; cache->prefetch_thread_count = 8; cache->ssl_cacert = SWITCH_PREFIX_DIR "/conf/cacert.pem"; cache->ssl_verifyhost = 1; cache->ssl_verifypeer = 1; /* get params */ settings = switch_xml_child(cfg, "settings"); if (settings) { for (param = switch_xml_child(settings, "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, "max-urls")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting max-urls to %s\n", val); max_urls = atoi(val); } else if (!strcasecmp(var, "location")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting location to %s\n", val); cache->location = switch_core_strdup(cache->pool, val); } else if (!strcasecmp(var, "default-max-age")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting default-max-age to %s\n", val); default_max_age_sec = atoi(val); } else if (!strcasecmp(var, "prefetch-queue-size")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting prefetch-queue-size to %s\n", val); cache->prefetch_queue_size = atoi(val); } else if (!strcasecmp(var, "prefetch-thread-count")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting prefetch-thread-count to %s\n", val); cache->prefetch_thread_count = atoi(val); } else if (!strcasecmp(var, "ssl-cacert")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting ssl-cacert to %s\n", val); cache->ssl_cacert = switch_core_strdup(cache->pool, val); } else if (!strcasecmp(var, "ssl-verifyhost")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting ssl-verifyhost to %s\n", val); cache->ssl_verifyhost = !switch_false(val); /* only disable if explicitly set to false */ } else if (!strcasecmp(var, "ssl-verifypeer")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting ssl-verifypeer to %s\n", val); cache->ssl_verifypeer = !switch_false(val); /* only disable if explicitly set to false */ } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unsupported param: %s\n", var); } } } /* check config */ if (max_urls <= 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-urls must be > 0\n"); status = SWITCH_STATUS_TERM; goto done; } if (zstr(cache->location)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "location must not be empty\n"); status = SWITCH_STATUS_TERM; goto done; } if (default_max_age_sec <= 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "default-max-age must be > 0\n"); status = SWITCH_STATUS_TERM; goto done; } if (cache->prefetch_queue_size <= 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "prefetch-queue-size must be > 0\n"); status = SWITCH_STATUS_TERM; goto done; } if (cache->prefetch_thread_count <= 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "prefetch-thread-count must be > 0\n"); status = SWITCH_STATUS_TERM; goto done; } cache->max_url = max_urls; cache->default_max_age = (default_max_age_sec * 1000 * 1000); /* convert from seconds to nanoseconds */ done: switch_xml_free(xml); return status; }
static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) { crtp_private_t *tech_pvt = NULL; tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_DEBUG_MEDIA: { if (switch_rtp_ready(tech_pvt->rtp_session) && !zstr(msg->string_array_arg[0]) && !zstr(msg->string_array_arg[1])) { switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID] = {0}; int x = 0; if (!strcasecmp(msg->string_array_arg[0], "read")) { flags[SWITCH_RTP_FLAG_DEBUG_RTP_READ]++;x++; } else if (!strcasecmp(msg->string_array_arg[0], "write")) { flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]++;x++; } else if (!strcasecmp(msg->string_array_arg[0], "both")) { flags[SWITCH_RTP_FLAG_DEBUG_RTP_READ]++;x++; flags[SWITCH_RTP_FLAG_DEBUG_RTP_WRITE]++; } if (x) { if (switch_true(msg->string_array_arg[1])) { switch_rtp_set_flags(tech_pvt->rtp_session, flags); } else { switch_rtp_clear_flags(tech_pvt->rtp_session, flags); } } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid Options\n"); } } break; } case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC: if (switch_rtp_ready(tech_pvt->rtp_session)) { rtp_flush_read_buffer(tech_pvt->rtp_session, SWITCH_RTP_FLUSH_ONCE); } break; case SWITCH_MESSAGE_INDICATE_JITTER_BUFFER: { if (switch_rtp_ready(tech_pvt->rtp_session)) { int len = 0, maxlen = 0, qlen = 0, maxqlen = 50, max_drift = 0; if (msg->string_arg) { char *p, *q; const char *s; if (!strcasecmp(msg->string_arg, "pause")) { switch_rtp_pause_jitter_buffer(tech_pvt->rtp_session, SWITCH_TRUE); goto end; } else if (!strcasecmp(msg->string_arg, "resume")) { switch_rtp_pause_jitter_buffer(tech_pvt->rtp_session, SWITCH_FALSE); goto end; } else if (!strncasecmp(msg->string_arg, "debug:", 6)) { s = msg->string_arg + 6; if (s && !strcmp(s, "off")) { s = NULL; } switch_rtp_debug_jitter_buffer(tech_pvt->rtp_session, s); goto end; } if ((len = atoi(msg->string_arg))) { qlen = len / (tech_pvt->read_codec.implementation->microseconds_per_packet / 1000); if (qlen < 1) { qlen = 3; } } if (qlen) { if ((p = strchr(msg->string_arg, ':'))) { p++; maxlen = atol(p); if ((q = strchr(p, ':'))) { q++; max_drift = abs(atol(q)); } } } if (maxlen) { maxqlen = maxlen / (tech_pvt->read_codec.implementation->microseconds_per_packet / 1000); } } if (qlen) { if (maxqlen < qlen) { maxqlen = qlen * 5; } if (switch_rtp_activate_jitter_buffer(tech_pvt->rtp_session, qlen, maxqlen, tech_pvt->read_codec.implementation->samples_per_packet, tech_pvt->read_codec.implementation->samples_per_second, max_drift) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames) (%d max frames) (%d max drift)\n", len, qlen, maxqlen, max_drift); switch_channel_set_flag(tech_pvt->channel, CF_JITTERBUFFER); if (!switch_false(switch_channel_get_variable(tech_pvt->channel, "rtp_jitter_buffer_plc"))) { switch_channel_set_flag(tech_pvt->channel, CF_JITTERBUFFER_PLC); } } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_WARNING, "Error Setting Jitterbuffer to %dms (%d frames)\n", len, qlen); } } else { switch_rtp_deactivate_jitter_buffer(tech_pvt->rtp_session); } } } break; default: break; } end: return SWITCH_STATUS_SUCCESS; }
switch_status_t spandsp_inband_dtmf_session(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_media_bug_t *bug; switch_status_t status; switch_inband_dtmf_t *pvt; switch_codec_implementation_t read_impl = { 0 }; const char *value; switch_core_session_get_read_impl(session, &read_impl); if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) { return SWITCH_STATUS_MEMERR; } pvt->session = session; /* get detector params */ pvt->min_dup_digit_spacing = 0; value = switch_channel_get_variable(channel, "min_dup_digit_spacing_ms"); if (!zstr(value) && switch_is_number(value)) { int val = atoi(value) * 8; /* convert from ms to samples */ if (val < 0) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "min_dup_digit_spacing_ms must be >= 0\n"); } else { pvt->min_dup_digit_spacing = val; } } pvt->threshold = -100; value = switch_channel_get_variable(channel, "spandsp_dtmf_rx_threshold"); if (!zstr(value) && switch_is_number(value)) { int val = atoi(value); if (val < -99) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "spandsp_dtmf_rx_threshold must be >= -99 dBm0\n"); } else { pvt->threshold = val; } } pvt->twist = -1; value = switch_channel_get_variable(channel, "spandsp_dtmf_rx_twist"); if (!zstr(value) && switch_is_number(value)) { int val = atoi(value); if (val < 0) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "spandsp_dtmf_rx_twist must be >= 0 dB\n"); } else { pvt->twist = val; } } pvt->reverse_twist = -1; value = switch_channel_get_variable(channel, "spandsp_dtmf_rx_reverse_twist"); if (!zstr(value) && switch_is_number(value)) { int val = atoi(value); if (val < 0) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "spandsp_dtmf_rx_reverse_twist must be >= 0 dB\n"); } else { pvt->reverse_twist = val; } } pvt->filter_dialtone = -1; value = switch_channel_get_variable(channel, "spandsp_dtmf_rx_filter_dialtone"); if (switch_true(value)) { pvt->filter_dialtone = 1; } else if (switch_false(value)) { pvt->filter_dialtone = 0; } if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_FALSE; } if ((status = switch_core_media_bug_add(session, "spandsp_dtmf_detect", NULL, inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE | SMBF_NO_PAUSE, &bug)) != SWITCH_STATUS_SUCCESS) { return status; } switch_channel_set_private(channel, "dtmf", bug); return SWITCH_STATUS_SUCCESS; }
SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *event, int count, switch_bool_t reload, switch_xml_config_item_t *instructions) { switch_xml_config_item_t *item; int matched_count = 0; for (item = instructions; item->key; item++) { const char *value = switch_event_get_header(event, item->key); switch_bool_t changed = SWITCH_FALSE; switch_xml_config_callback_t callback = (switch_xml_config_callback_t) item->function; void *ptr = item->ptr; //switch_assert(ptr); if (value) { matched_count++; } if (reload && !switch_test_flag(item, CONFIG_RELOADABLE)) { continue; } if (!value && switch_test_flag(item, CONFIG_REQUIRED)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Required parameter [%s] is missing\n", item->key); return SWITCH_STATUS_FALSE; } switch (item->type) { case SWITCH_CONFIG_INT: { switch_xml_config_int_options_t *int_options = (switch_xml_config_int_options_t *) item->data; int *dest = (int *) ptr; int intval; if (value) { if (switch_is_number(value)) { intval = atoi(value); } else { intval = (int) (intptr_t) item->defaultvalue; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%d]\n", value, item->key, intval); } if (int_options) { /* Enforce validation options */ if ((int_options->enforce_min && !(intval >= int_options->min)) || (int_options->enforce_max && !(intval <= int_options->max))) { /* Validation failed, set default */ intval = (int) (intptr_t) item->defaultvalue; /* Then complain */ if (int_options->enforce_min && int_options->enforce_max) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], should be between [%d] and [%d], setting default [%d]\n", value, item->key, int_options->min, int_options->max, intval); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], should be %s [%d], setting default [%d]\n", value, item->key, int_options->enforce_min ? "at least" : "at max", int_options->enforce_min ? int_options->min : int_options->max, intval); } } } } else { intval = (int) (intptr_t) item->defaultvalue; } if (*dest != intval) { *dest = intval; changed = SWITCH_TRUE; } } break; case SWITCH_CONFIG_ATOMIC: { switch_xml_config_atomic_options_t *atomic_options = (switch_xml_config_atomic_options_t *) item->data; switch_atomic_t *dest = (switch_atomic_t *) ptr; uint32_t uintval; if (value) { if (switch_is_number(value)) { uintval = (uint32_t) strtol(value, NULL, 10); } else { uintval = (uint32_t) (uintptr_t) item->defaultvalue; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%u]\n", value, item->key, uintval); } if (atomic_options) { /* Enforce validation options */ if ((atomic_options->enforce_min && !(uintval >= atomic_options->min)) || (atomic_options->enforce_max && !(uintval <= atomic_options->max))) { /* Validation failed, set default */ uintval = (uint32_t) (uintptr_t) item->defaultvalue; /* Then complain */ if (atomic_options->enforce_min && atomic_options->enforce_max) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], should be between [%u] and [%u], setting default [%u]\n", value, item->key, atomic_options->min, atomic_options->max, uintval); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], should be %s [%u], setting default [%u]\n", value, item->key, atomic_options->enforce_min ? "at least" : "at max", atomic_options->enforce_min ? atomic_options->min : atomic_options->max, uintval); } } } } else { uintval = (uint32_t) (uintptr_t) item->defaultvalue; } if (switch_atomic_read(dest) != uintval) { switch_atomic_set(dest, uintval); changed = SWITCH_TRUE; } } break; case SWITCH_CONFIG_STRING: { switch_xml_config_string_options_t string_options_default = { 0 }; switch_xml_config_string_options_t *string_options = item->data ? (switch_xml_config_string_options_t *) item->data : &string_options_default; const char *newstring = NULL; /* Perform validation */ if (value) { if (!zstr(string_options->validation_regex)) { if (switch_regex_match(value, string_options->validation_regex) == SWITCH_STATUS_SUCCESS) { newstring = value; /* Regex match, accept value */ } else { newstring = (char *) item->defaultvalue; /* Regex failed */ if (newstring) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%s]\n", value, item->key, newstring); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s]\n", value, item->key); } switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item); } } else { newstring = value; /* No validation */ } } else { newstring = (char *) item->defaultvalue; } if (string_options->length > 0) { /* We have a preallocated buffer */ char *dest = (char *) ptr; if (newstring) { if (strncasecmp(dest, newstring, string_options->length)) { switch_copy_string(dest, newstring, string_options->length); changed = SWITCH_TRUE; } } else { if (*dest != '\0') { *dest = '\0'; changed = SWITCH_TRUE; } } } else if (string_options->pool) { /* Pool-allocated buffer */ char **dest = (char **) ptr; if (newstring) { if (!*dest || strcmp(*dest, newstring)) { *dest = switch_core_strdup(string_options->pool, newstring); } } else { if (*dest) { changed = SWITCH_TRUE; *dest = NULL; } } } else { /* Dynamically allocated buffer */ char **dest = (char **) ptr; if (newstring) { if (!*dest || strcmp(*dest, newstring)) { switch_safe_free(*dest); *dest = strdup(newstring); changed = SWITCH_TRUE; } } else { if (*dest) { switch_safe_free(*dest); changed = SWITCH_TRUE; } } } } break; case SWITCH_CONFIG_BOOL: { switch_bool_t *dest = (switch_bool_t *) ptr; switch_bool_t newval = SWITCH_FALSE; if (value && switch_true(value)) { newval = SWITCH_TRUE; } else if (value && switch_false(value)) { newval = SWITCH_FALSE; } else if (value) { /* Value isnt true or false */ newval = (switch_bool_t) (intptr_t) item->defaultvalue; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%s]\n", value, item->key, newval ? "true" : "false"); switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item); } else { newval = (switch_bool_t) (intptr_t) item->defaultvalue; } if (*dest != newval) { *dest = newval; changed = SWITCH_TRUE; } } break; case SWITCH_CONFIG_CUSTOM: break; case SWITCH_CONFIG_ENUM: { switch_xml_config_enum_item_t *enum_options = (switch_xml_config_enum_item_t *) item->data; int *dest = (int *) ptr; int newval = 0; switch_status_t lookup_result = SWITCH_STATUS_SUCCESS; if (value) { lookup_result = switch_xml_config_enum_str2int(enum_options, value, &newval); } else { newval = (int) (intptr_t) item->defaultvalue; } if (lookup_result != SWITCH_STATUS_SUCCESS) { newval = (int) (intptr_t) item->defaultvalue; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s]\n", value, item->key); switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item); } if (*dest != newval) { changed = SWITCH_TRUE; *dest = newval; } } break; case SWITCH_CONFIG_FLAG: { int32_t *dest = (int32_t *) ptr; int index = (int) (intptr_t) item->data; int8_t currentval = (int8_t) ! !(*dest & index); int newval = 0; if (value) { newval = switch_true(value); } else { newval = (switch_bool_t) (intptr_t) item->defaultvalue; } if (newval != currentval) { changed = SWITCH_TRUE; if (newval) { *dest |= (1 << index); } else { *dest &= ~(1 << index); } } } break; case SWITCH_CONFIG_FLAGARRAY: { int8_t *dest = (int8_t *) ptr; unsigned int index = (unsigned int) (intptr_t) item->data; int8_t newval = value ? !!switch_true(value) : (int8_t) ((intptr_t) item->defaultvalue); if (dest[index] != newval) { changed = SWITCH_TRUE; dest[index] = newval; } } break; case SWITCH_CONFIG_LAST: break; default: break; } if (callback) { callback(item, value, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed); } } if (count != matched_count) { /* User made a mistake, find it */ switch_event_header_t *header; for (header = event->headers; header; header = header->next) { switch_bool_t found = SWITCH_FALSE; for (item = instructions; item->key; item++) { if (!strcasecmp(header->name, item->key)) { found = SWITCH_TRUE; break; } } if (!found) { /* Tell the user */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Configuration parameter [%s] is unfortunately not valid, you might want to double-check that.\n", header->name); } } } return SWITCH_STATUS_SUCCESS; }