static ftdm_status_t parse_yesno(const char* var, const char* val, uint8_t *target)
{
	if (ftdm_true(val)) {
		*target = SNGISDN_OPT_TRUE; 
	} else {
		*target = SNGISDN_OPT_FALSE;
	}
	return FTDM_SUCCESS;
}
Beispiel #2
0
static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_pritap_configure_span)
{
    uint32_t i;
    const char *var, *val;
    const char *debug = NULL;
    pritap_mix_mode_t mixaudio = PRITAP_MIX_BOTH;
    ftdm_channel_t *dchan = NULL;
    pritap_t *pritap = NULL;
    ftdm_span_t *peerspan = NULL;
    pritap_iface_t iface = PRITAP_IFACE_UNKNOWN;
    unsigned paramindex = 0;

    if (span->trunk_type >= FTDM_TRUNK_NONE) {
        ftdm_log(FTDM_LOG_WARNING, "Invalid trunk type '%s' defaulting to T1.\n", ftdm_trunk_type2str(span->trunk_type));
        span->trunk_type = FTDM_TRUNK_T1;
    }

    for (i = 1; i <= span->chan_count; i++) {
        if (span->channels[i]->type == FTDM_CHAN_TYPE_DQ921) {
            dchan = span->channels[i];
        }
    }

    if (!dchan) {
        ftdm_log(FTDM_LOG_ERROR, "No d-channel specified in freetdm.conf!\n");
        return FTDM_FAIL;
    }

    for (paramindex = 0; ftdm_parameters[paramindex].var; paramindex++) {
        var = ftdm_parameters[paramindex].var;
        val = ftdm_parameters[paramindex].val;
        ftdm_log(FTDM_LOG_DEBUG, "Tapping PRI key=value, %s=%s\n", var, val);

        if (!strcasecmp(var, "debug")) {
            debug = val;
        } else if (!strcasecmp(var, "mixaudio")) {
            if (ftdm_true(val) || !strcasecmp(val, "both")) {
                ftdm_log(FTDM_LOG_DEBUG, "Setting mix audio mode to 'both' for span %s\n", span->name);
                mixaudio = PRITAP_MIX_BOTH;
            } else if (!strcasecmp(val, "peer")) {
                ftdm_log(FTDM_LOG_DEBUG, "Setting mix audio mode to 'peer' for span %s\n", span->name);
                mixaudio = PRITAP_MIX_PEER;
            } else {
                ftdm_log(FTDM_LOG_DEBUG, "Setting mix audio mode to 'self' for span %s\n", span->name);
                mixaudio = PRITAP_MIX_SELF;
            }
        } else if (!strcasecmp(var, "interface")) {
            if (!strcasecmp(val, "cpe")) {
                iface = PRITAP_IFACE_CPE;
            } else if (!strcasecmp(val, "net")) {
                iface = PRITAP_IFACE_NET;
            } else {
                ftdm_log(FTDM_LOG_WARNING, "Ignoring invalid tapping interface type %s\n", val);
            }
        } else if (!strcasecmp(var, "peerspan")) {
            if (ftdm_span_find_by_name(val, &peerspan) != FTDM_SUCCESS) {
                ftdm_log(FTDM_LOG_ERROR, "Invalid tapping peer span %s\n", val);
                break;
            }
        } else {
            ftdm_log(FTDM_LOG_ERROR,  "Unknown pri tapping parameter [%s]", var);
        }
    }

    if (!peerspan) {
        ftdm_log(FTDM_LOG_ERROR, "No valid peerspan was specified!\n");
        return FTDM_FAIL;
    }

    pritap = ftdm_calloc(1, sizeof(*pritap));
    if (!pritap) {
        return FTDM_FAIL;
    }

    pritap->debug = parse_debug(debug);
    pritap->dchan = dchan;
    pritap->peerspan = peerspan;
    pritap->mixaudio = mixaudio;
    pritap->iface = iface;

    span->start = ftdm_pritap_start;
    span->stop = ftdm_pritap_stop;
    span->sig_read = ftdm_pritap_sig_read;
    span->signal_cb = sig_cb;

    span->signal_data = pritap;
    span->signal_type = FTDM_SIGTYPE_ISDN;
    span->outgoing_call = pritap_outgoing_call;

    span->get_channel_sig_status = pritap_get_channel_sig_status;
    span->get_span_sig_status = pritap_get_span_sig_status;

    span->state_map = &pritap_state_map;
    span->state_processor = state_advance;

    return FTDM_SUCCESS;
}