Example #1
0
/*
 * Verify parameters for OSP module
 * return 0 success, -1 failure
 */
static int ospVerifyParameters(void)
{
    int i;
    char hostname[OSP_STRBUF_SIZE];
    int result = 0;

    if ((_osp_work_mode < 0) || (_osp_work_mode > 1)) {
        _osp_work_mode = OSP_DEF_MODE;
        LM_WARN("work mode is out of range, reset to %d\n", OSP_DEF_MODE);
    }

    if ((_osp_service_type < 0) || (_osp_service_type > 3)) {
        _osp_service_type = OSP_DEF_SERVICE;
        LM_WARN("service type is out of range, reset to %d\n", OSP_DEF_SERVICE);
    }

    _osp_sp_number = 0;
    for (i = 0; i < OSP_DEF_SPS; i++) {
        if (_osp_sp_uris[i] != NULL) {
            if (_osp_sp_number != i) {
                _osp_sp_uris[_osp_sp_number] = _osp_sp_uris[i];
                _osp_sp_weights[_osp_sp_number] = _osp_sp_weights[i];
                _osp_sp_uris[i] = NULL;
                _osp_sp_weights[i] = OSP_DEF_WEIGHT;
            }
            osp_index[_osp_sp_number] = i + 1;
            _osp_sp_number++;
        }
    }

    if (_osp_sp_number == 0) {
        LM_ERR("at least one service point uri must be configured\n");
        result = -1;
    }

    if (_osp_device_ip == NULL) {
        gethostname(hostname, sizeof(hostname));
        _osp_device_ip = hostname;
    }
    ospConvertToOutAddress(_osp_device_ip, _osp_out_device, sizeof(_osp_out_device));
    ospConvertToInAddress(_osp_device_ip, _osp_in_device, sizeof(_osp_in_device));

    /* If use_security_features is 0, ignroe the certificate files */
    if (_osp_use_security != 0) {
        /* Default location for the cert files is in the compile time variable CFG_DIR */
        if (_osp_private_key == NULL) {
            sprintf(_osp_PRIVATE_KEY, "%spkey.pem", CFG_DIR);
            _osp_private_key = _osp_PRIVATE_KEY;
        }

        if (_osp_local_certificate == NULL) {
            sprintf(_osp_LOCAL_CERTIFICATE, "%slocalcert.pem", CFG_DIR);
            _osp_local_certificate = _osp_LOCAL_CERTIFICATE;
        }

        if (_osp_ca_certificate == NULL) {
            sprintf(_osp_CA_CERTIFICATE, "%scacert_0.pem", CFG_DIR);
            _osp_ca_certificate = _osp_CA_CERTIFICATE;
        }
    }

    if (_osp_token_format < 0 || _osp_token_format > 2) {
        _osp_token_format = OSP_DEF_TOKEN;
        LM_WARN("token_format is out of range, reset to %d\n", OSP_DEF_TOKEN);
    }

    if (_osp_max_dests > OSP_DEF_DESTS || _osp_max_dests < 1) {
        _osp_max_dests = OSP_DEF_DESTS;
        LM_WARN("max_destinations is out of range, reset to %d\n", OSP_DEF_DESTS);
    }

    if (_osp_report_nid < 0 || _osp_report_nid > 3) {
        _osp_report_nid = OSP_DEF_REPORTNID;
        LM_WARN("report_networkid is out of range, reset to %d\n", OSP_DEF_REPORTNID);
    }

    if (_osp_use_np < 0 || _osp_use_np > 1) {
        _osp_use_np = OSP_DEF_USENP;
        LM_WARN("use_number_portability is out of range, reset to %d\n", OSP_DEF_USENP);
    }

    if (_osp_export_np < 0 || _osp_export_np > 1) {
        _osp_export_np = OSP_DEF_EXPORTNP;
        LM_WARN("export_npparameter_order is out of range, reset to %d\n", OSP_DEF_EXPORTNP);
    }

    if (_osp_append_userphone < 0 || _osp_append_userphone > 1) {
        _osp_append_userphone = OSP_DEF_USERPHONE;
        LM_WARN("append_userphone is out of range, reset to %d\n", OSP_DEF_USERPHONE);
    }

    if ((_osp_dnid_location < 0) || (_osp_dnid_location > 2)) {
        _osp_dnid_location = OSP_DEF_DNIDLOC;
        LM_WARN("networkid_location is out of range, reset to %d\n", OSP_DEF_DNIDLOC);
    }

    if (!(_osp_dnid_param && *_osp_dnid_param)) {
        _osp_dnid_param = OSP_DEF_DNIDPARAM;
    }

    if ((_osp_swid_location < 0) || (_osp_swid_location > 2)) {
        _osp_swid_location = OSP_DEF_SWIDLOC;
        LM_WARN("switchid_location is out of range, reset to %d\n", OSP_DEF_SWIDLOC);
    }

    if (!(_osp_swid_param && *_osp_swid_param)) {
        _osp_swid_param = OSP_DEF_SWIDPARAM;
    }

    if ((_osp_paramstr_location < 0) || (_osp_paramstr_location > 2)) {
        _osp_paramstr_location = OSP_DEF_PARAMSTRLOC;
        LM_WARN("parameterstring_location is out of range, reset to %d\n", OSP_DEF_PARAMSTRLOC);
    }

    if (!(_osp_paramstr_value && *_osp_paramstr_value)) {
        _osp_paramstr_value = OSP_DEF_PARAMSTRVAL;
    }

    ospCheckAVP(_osp_srcdev_avp, &_osp_srcdev_avpid, &_osp_srcdev_avptype);

    ospCheckAVP(_osp_snid_avp, &_osp_snid_avpid, &_osp_snid_avptype);

    ospCheckAVP(_osp_swid_avp, &_osp_swid_avpid, &_osp_swid_avptype);

    ospCheckAVP(_osp_cinfo_avp, &_osp_cinfo_avpid, &_osp_cinfo_avptype);

    ospCheckAVP(_osp_cnam_avp, &_osp_cnam_avpid, &_osp_cnam_avptype);

    if (!(_osp_extraheaders_value && *_osp_extraheaders_value)) {
        _osp_extraheaders_value = OSP_DEF_EXTHEADERVAL;
    }

    ospCheckAVP(_osp_srcmedia_avp, &_osp_srcmedia_avpid, &_osp_srcmedia_avptype);
    ospCheckAVP(_osp_destmedia_avp, &_osp_destmedia_avpid, &_osp_destmedia_avptype);

    ospCheckAVP(_osp_reqdate_avp, &_osp_reqdate_avpid, &_osp_reqdate_avptype);
    ospCheckAVP(_osp_sdpfp_avp, &_osp_sdpfp_avpid, &_osp_sdpfp_avptype);
    ospCheckAVP(_osp_identity_avp, &_osp_identity_avpid, &_osp_identity_avptype);

    ospCheckAVP(_osp_sp_avp, &_osp_sp_avpid, &_osp_sp_avptype);
    ospCheckAVP(_osp_usergroup_avp, &_osp_usergroup_avpid, &_osp_usergroup_avptype);
    ospCheckAVP(_osp_userid_avp, &_osp_userid_avpid, &_osp_userid_avptype);

    ospCheckAVP(_osp_dest_avp, &_osp_dest_avpid, &_osp_dest_avptype);

    ospCheckAVP(_osp_reasontype_avp, &_osp_reasontype_avpid, &_osp_reasontype_avptype);
    ospCheckAVP(_osp_reasoncause_avp, &_osp_reasoncause_avpid, &_osp_reasoncause_avptype);
    ospCheckAVP(_osp_reasontext_avp, &_osp_reasontext_avpid, &_osp_reasontext_avptype);

    ospDumpParameters();

    return result;
}
Example #2
0
/*
 * Verify parameters for OSP module
 * return 0 success, -1 failure
 */
static int ospVerifyParameters(void)
{
    int i;
    int result = 0;

    LOG(L_DBG, "osp: ospVerifyParamters\n");

    /* Default location for the cert files is in the compile time variable CFG_DIR */
    if (_osp_private_key == NULL) {
        sprintf(_osp_PRIVATE_KEY, "%spkey.pem", CFG_DIR);
        _osp_private_key = (unsigned char*)_osp_PRIVATE_KEY;
    } 

    if (_osp_local_certificate == NULL) {
        sprintf(_osp_LOCAL_CERTIFICATE, "%slocalcert.pem", CFG_DIR);
        _osp_local_certificate = (unsigned char*)_osp_LOCAL_CERTIFICATE;
    }

    if (_osp_ca_certificate == NULL) {
        sprintf(_osp_CA_CERTIFICATE, "%scacert_0.pem", CFG_DIR);
        _osp_ca_certificate = (unsigned char*)_osp_CA_CERTIFICATE;
    }

    if (_osp_device_ip == NULL) {
        _osp_device_ip = "";
    }

    if (_osp_device_port == NULL) {
        _osp_device_port = "";
    }

    if (_osp_max_dests > OSP_DEF_DESTS || _osp_max_dests < 1) {
        _osp_max_dests = OSP_DEF_DESTS;    
        LOG(L_WARN,
            "osp: WARN: max_destinations is out of range, reset to %d\n", 
            OSP_DEF_DESTS);
    }

    if (_osp_token_format < 0 || _osp_token_format > 2) {
        _osp_token_format = OSP_DEF_TOKEN;
        LOG(L_WARN, 
            "osp: WARN: token_format is out of range, reset to %d\n", 
            OSP_DEF_TOKEN);
    }

    _osp_sp_number = 0;
    for (i = 0; i < OSP_DEF_SPS; i++) {
        if (_osp_sp_uris[i] != NULL) {
            if (_osp_sp_number != i) {
                _osp_sp_uris[_osp_sp_number] = _osp_sp_uris[i];
                _osp_sp_weights[_osp_sp_number] = _osp_sp_weights[i];
                _osp_sp_uris[i] = NULL;
                _osp_sp_weights[i] = OSP_DEF_WEIGHT;
            }
            osp_index[_osp_sp_number] = i + 1;
            _osp_sp_number++;
        }
    }

    if (_osp_sp_number == 0) {
        LOG(L_ERR, "osp: ERROR: at least one service point uri must be configured\n");
        result = -1;
    }

    ospDumpParameters();

    return result;
}
/*
 * Verify parameters for OSP module
 * return 0 success, -1 failure
 */
static int ospVerifyParameters(void)
{
    int i;
    pv_spec_t avp_spec;
    str avp_str;
    int result = 0;

    if ((_osp_work_mode < 0) || (_osp_work_mode > 1)) {
        _osp_work_mode = OSP_DEF_MODE;
        LM_WARN("work mode is out of range, reset to %d\n", OSP_DEF_MODE);
    }

    if ((_osp_service_type < 0) || (_osp_service_type > 1)) {
        _osp_service_type = OSP_DEF_SERVICE;
        LM_WARN("service type is out of range, reset to %d\n", OSP_DEF_SERVICE);
    }

    /* If use_security_features is 0, ignroe the certificate files */
    if (_osp_use_security != 0) {
        /* Default location for the cert files is in the compile time variable CFG_DIR */
        if (_osp_private_key == NULL) {
            sprintf(_osp_PRIVATE_KEY, "%spkey.pem", CFG_DIR);
            _osp_private_key = _osp_PRIVATE_KEY;
        }

        if (_osp_local_certificate == NULL) {
            sprintf(_osp_LOCAL_CERTIFICATE, "%slocalcert.pem", CFG_DIR);
            _osp_local_certificate = _osp_LOCAL_CERTIFICATE;
        }

        if (_osp_ca_certificate == NULL) {
            sprintf(_osp_CA_CERTIFICATE, "%scacert_0.pem", CFG_DIR);
            _osp_ca_certificate = _osp_CA_CERTIFICATE;
        }
    }

    if (_osp_device_ip != NULL) {
        ospConvertToInAddress(_osp_device_ip, _osp_in_device, sizeof(_osp_in_device));
        ospConvertToOutAddress(_osp_device_ip, _osp_out_device, sizeof(_osp_out_device));
    } else {
        _osp_in_device[0] = '\0';
        _osp_out_device[0] = '\0';
    }

    if (_osp_max_dests > OSP_MAX_DESTS || _osp_max_dests < 1) {
        _osp_max_dests = OSP_DEF_DESTS;
        LM_WARN("max_destinations is out of range, reset to %d\n", OSP_DEF_DESTS);
    }

    if (_osp_report_nid < 0 || _osp_report_nid > 3) {
        _osp_report_nid = OSP_DEF_REPORTNID;
        LM_WARN("report_networkid is out of range, reset to %d\n", OSP_DEF_REPORTNID);
    }

    if (_osp_token_format < 0 || _osp_token_format > 2) {
        _osp_token_format = OSP_DEF_TOKEN;
        LM_WARN("token_format is out of range, reset to %d\n", OSP_DEF_TOKEN);
    }

    _osp_sp_number = 0;
    for (i = 0; i < OSP_DEF_SPS; i++) {
        if (_osp_sp_uris[i] != NULL) {
            if (_osp_sp_number != i) {
                _osp_sp_uris[_osp_sp_number] = _osp_sp_uris[i];
                _osp_sp_weights[_osp_sp_number] = _osp_sp_weights[i];
                _osp_sp_uris[i] = NULL;
                _osp_sp_weights[i] = OSP_DEF_WEIGHT;
            }
            osp_index[_osp_sp_number] = i + 1;
            _osp_sp_number++;
        }
    }

    if (_osp_sp_number == 0) {
        LM_ERR("at least one service point uri must be configured\n");
        result = -1;
    }

    if ((_osp_dnid_location < 0) || (_osp_dnid_location > 3)) {
        _osp_dnid_location = OSP_DEF_DNIDLOC;
        LM_WARN("networkid_location is out of range, reset to %d\n", OSP_DEF_DNIDLOC);
    }

    if (!(_osp_dnid_param && *_osp_dnid_param)) {
        _osp_dnid_param = OSP_DEF_DNIDPARAM;
    }

    if ((_osp_work_mode == 1) && _osp_srcdev_avp && *_osp_srcdev_avp) {
        avp_str.s = _osp_srcdev_avp;
        avp_str.len = strlen(_osp_srcdev_avp);
        if ((pv_parse_spec(&avp_str, &avp_spec) == NULL) ||
            avp_spec.type != PVT_AVP ||
            pv_get_avp_name(0, &(avp_spec.pvp), &_osp_srcdev_avpid, &_osp_srcdev_avptype) != 0)
        {
            LM_WARN("'%s' invalid AVP definition\n", _osp_srcdev_avp);
            _osp_srcdev_avpid = OSP_DEF_AVP;
            _osp_srcdev_avptype = 0;
        }
    } else {
        _osp_srcdev_avpid = OSP_DEF_AVP;
        _osp_srcdev_avptype = 0;
    }

    if (_osp_snid_avp && *_osp_snid_avp) {
        avp_str.s = _osp_snid_avp;
        avp_str.len = strlen(_osp_snid_avp);
        if (pv_parse_spec(&avp_str, &avp_spec) == NULL ||
            avp_spec.type != PVT_AVP ||
            pv_get_avp_name(0, &(avp_spec.pvp), &_osp_snid_avpid, &_osp_snid_avptype) != 0)
        {
            LM_WARN("'%s' invalid AVP definition\n", _osp_snid_avp);
            _osp_snid_avpid = OSP_DEF_AVP;
            _osp_snid_avptype = 0;
        }
    } else {
        _osp_snid_avpid = OSP_DEF_AVP;
        _osp_snid_avptype = 0;
    }

    if (_osp_cinfo_avp && *_osp_cinfo_avp) {
        avp_str.s = _osp_cinfo_avp;
        avp_str.len = strlen(_osp_cinfo_avp);
        if (pv_parse_spec(&avp_str, &avp_spec) == NULL ||
            avp_spec.type != PVT_AVP ||
            pv_get_avp_name(0, &(avp_spec.pvp), &_osp_cinfo_avpid, &_osp_cinfo_avptype) != 0)
        {
            LM_WARN("'%s' invalid AVP definition\n", _osp_cinfo_avp);
            _osp_cinfo_avpid = OSP_DEF_AVP;
            _osp_cinfo_avptype = 0;
        }
    } else {
        _osp_cinfo_avpid = OSP_DEF_AVP;
        _osp_cinfo_avptype = 0;
    }

    ospDumpParameters();

    return result;
}