// This file is generated by kconfig_compiler from 802-1x.kcfg.
// All changes you do to this file will be lost.

#include "802-1xdbus.h"

#include "802-1x.h"

Security8021xDbus::Security8021xDbus(Knm::Security8021xSetting * setting) : SettingDbus(setting)
{
}

Security8021xDbus::~Security8021xDbus()
{
}

void Security8021xDbus::fromMap(const QVariantMap & map)
{
    Knm::Security8021xSetting * setting = static_cast<Knm::Security8021xSetting *>(m_setting);
    if (map.contains(QLatin1String(NM_SETTING_802_1X_EAP))) {
        setting->setEap(map.value(QLatin1String(NM_SETTING_802_1X_EAP)).value<QStringList>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_IDENTITY))) {
        setting->setIdentity(map.value(QLatin1String(NM_SETTING_802_1X_IDENTITY)).value<QString>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY))) {
        setting->setAnonymousidentity(map.value(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY)).value<QString>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_CA_CERT))) {
        setting->setCacert(map.value(QLatin1String(NM_SETTING_802_1X_CA_CERT)).value<QByteArray>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_CA_PATH))) {
        setting->setCapath(map.value(QLatin1String(NM_SETTING_802_1X_CA_PATH)).value<QString>());
    }
#if defined(NM_SETTING_802_1X_SUBJECT_MATCH)
    if (map.contains(QLatin1String(NM_SETTING_802_1X_SUBJECT_MATCH))) {
        setting->setSubjectmatch(map.value(QLatin1String(NM_SETTING_802_1X_SUBJECT_MATCH)).value<QString>());
    }
#endif
#if defined(NM_SETTING_802_1X_ALTSUBJECT_MATCHES)
    if (map.contains(QLatin1String(NM_SETTING_802_1X_ALTSUBJECT_MATCHES))) {
        setting->setAltsubjectmatches(map.value(QLatin1String(NM_SETTING_802_1X_ALTSUBJECT_MATCHES)).value<QStringList>());
    }
#endif
    if (map.contains(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT))) {
        setting->setClientcert(map.value(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT)).value<QByteArray>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER))) {
        setting->setPhase1peapver(map.value(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER)).value<int>() + 1 ); // 0 is automatic
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL))) {
        setting->setPhase1peaplabel(map.value(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL)).value<QString>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING))) {
        setting->setPhase1fastprovisioning(map.value(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING)).value<QString>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH))) {
        QString auth = map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH)).value<QString>();
        if (auth == QLatin1String("pap"))
            setting->setPhase2auth(Knm::Security8021xSetting::EnumPhase2auth::pap);
        else if (auth == QLatin1String("mschap"))
            setting->setPhase2auth(Knm::Security8021xSetting::EnumPhase2auth::mschap);
        else if (auth == QLatin1String("mschapv2"))
            setting->setPhase2auth(Knm::Security8021xSetting::EnumPhase2auth::mschapv2);
        else if (auth == QLatin1String("chap"))
            setting->setPhase2auth(Knm::Security8021xSetting::EnumPhase2auth::chap);
        else if (auth == QLatin1String("md5"))
            setting->setPhase2auth(Knm::Security8021xSetting::EnumPhase2auth::md5);
        else if (auth == QLatin1String("gtc"))
            setting->setPhase2auth(Knm::Security8021xSetting::EnumPhase2auth::gtc);
        else if (auth == QLatin1String("otp"))
            setting->setPhase2auth(Knm::Security8021xSetting::EnumPhase2auth::otp);
        else if (auth == QLatin1String("tls"))
            setting->setPhase2auth(Knm::Security8021xSetting::EnumPhase2auth::tls);
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP))) {
        QString eap = map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP)).value<QString>();
        if (eap == QLatin1String("md5"))
            setting->setPhase2autheap(Knm::Security8021xSetting::EnumPhase2autheap::md5);
        else if (eap == QLatin1String("gtc"))
            setting->setPhase2autheap(Knm::Security8021xSetting::EnumPhase2autheap::gtc);
        else if (eap == QLatin1String("otp"))
            setting->setPhase2autheap(Knm::Security8021xSetting::EnumPhase2autheap::otp);
        else if (eap == QLatin1String("mschapv2"))
            setting->setPhase2autheap(Knm::Security8021xSetting::EnumPhase2autheap::mschapv2);
        else if (eap == QLatin1String("tls"))
            setting->setPhase2autheap(Knm::Security8021xSetting::EnumPhase2autheap::tls);
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT))) {
        setting->setPhase2cacert(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT)).value<QByteArray>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH))) {
        setting->setPhase2capath(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH)).value<QString>());
    }
#if defined(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH)
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH))) {
        setting->setPhase2subjectmatch(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH)).value<QString>());
    }
#endif
#if defined(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES)
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES))) {
        setting->setPhase2altsubjectmatches(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES)).value<QStringList>());
    }
#endif
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT))) {
        setting->setPhase2clientcert(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT)).value<QByteArray>());
    }
    // SECRET
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PASSWORD))) {
        setting->setPassword(map.value(QLatin1String(NM_SETTING_802_1X_PASSWORD)).value<QString>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY))) {
        setting->setPrivatekey(map.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY)).value<QByteArray>());
    }
    // SECRET
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD))) {
        setting->setPrivatekeypassword(map.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD)).value<QString>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY))) {
        setting->setPhase2privatekey(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY)).value<QByteArray>());
    }
    // SECRET
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD))) {
        setting->setPhase2privatekeypassword(map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD)).value<QString>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_PIN))) {
        setting->setPin(map.value(QLatin1String(NM_SETTING_802_1X_PIN)).value<QString>());
    }
    if (map.contains(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS))) {
        setting->setUseSystemCaCerts(map.value(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS)).value<bool>());
    } else {
        setting->setUseSystemCaCerts(false);
    }
    setting->setPasswordflags((Knm::Setting::secretsTypes)map.value(QLatin1String(NM_SETTING_802_1X_PASSWORD_FLAGS)).value<int>());
    setting->setPrivatekeypasswordflags((Knm::Setting::secretsTypes)map.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS)).value<int>());
    setting->setPhase2privatekeypasswordflags((Knm::Setting::secretsTypes)map.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS)).value<int>());
    setting->setPinflags((Knm::Setting::secretsTypes)map.value(QLatin1String(NM_SETTING_802_1X_PIN_FLAGS)).value<int>());

    setting->setEnabled(true);
}

QVariantMap Security8021xDbus::toMap()
{
    QVariantMap map;
    Knm::Security8021xSetting * setting = static_cast<Knm::Security8021xSetting *>(m_setting);
    if (setting->enabled()) {
        if (!setting->eap().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_EAP), setting->eap());
        }
        if (!setting->identity().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_IDENTITY), setting->identity());
        }
        if (!setting->anonymousidentity().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY), setting->anonymousidentity());
        }
        if (!setting->cacert().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_CA_CERT), setting->cacert());
        }
        if (!setting->capath().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_CA_PATH), setting->capath());
        }
#if defined(NM_SETTING_802_1X_SUBJECT_MATCH)
        if (!setting->subjectmatch().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_SUBJECT_MATCH), setting->subjectmatch());
        }
#endif
#if defined(NM_SETTING_802_1X_ALTSUBJECT_MATCHES)
        if (!setting->altsubjectmatches().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_ALTSUBJECT_MATCHES), setting->altsubjectmatches());
        }
#endif
        if (!setting->clientcert().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT), setting->clientcert());
        }
        if (setting->eap().contains(QLatin1String("peap"))) {
            switch (setting->phase1peapver()) {
                case Knm::Security8021xSetting::EnumPhase1peapver::zero:
                    map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER), "0");
                    break;
                case Knm::Security8021xSetting::EnumPhase1peapver::one:
                    map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER), "1");
                    if (!setting->phase1peaplabel().isEmpty()) {
                        map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL), setting->phase1peaplabel());
                    }
                    break;
            }
        }
        if (!setting->phase1fastprovisioning().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING), setting->phase1fastprovisioning());
        }
        switch (setting->phase2auth()) {
            case Knm::Security8021xSetting::EnumPhase2auth::none:
                //map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "none");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::pap:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "pap");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::mschap:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "mschap");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::mschapv2:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "mschapv2");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::chap:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "chap");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::md5:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "md5");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::gtc:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "gtc");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::otp:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "otp");
                break;
            case Knm::Security8021xSetting::EnumPhase2auth::tls:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), "tls");
                break;
        }
        switch (setting->phase2autheap()) {
            case Knm::Security8021xSetting::EnumPhase2autheap::none:
                //map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "none");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::md5:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "md5");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::gtc:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "gtc");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::otp:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "otp");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::mschapv2:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "mschapv2");
                break;
            case Knm::Security8021xSetting::EnumPhase2autheap::tls:
                map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), "tls");
                break;
        }
        if (!setting->phase2cacert().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT), setting->phase2cacert());
        if (!setting->phase2capath().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH), setting->phase2capath());
#if defined(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH)
        if (!setting->phase2subjectmatch().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH), setting->phase2subjectmatch());
#endif
#if defined(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES)
        if (!setting->phase2altsubjectmatches().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES), setting->phase2altsubjectmatches());
#endif
        if (!setting->phase2clientcert().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT), setting->phase2clientcert());
        if (!setting->phase2privatekey().isEmpty())
            map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY), setting->phase2privatekey());
        if (!setting->privatekey().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY), setting->privatekey());
        }
        if (!setting->pin().isEmpty()) {
            map.insert(QLatin1String(NM_SETTING_802_1X_PIN), setting->pin());
            map.insert(QLatin1String(NM_SETTING_802_1X_PIN_FLAGS), (int)setting->pinflags());
        }
        if (!setting->eap().contains(QLatin1String("leap"))) {
            map.insert(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS), setting->useSystemCaCerts());
        }

        map.unite(toSecretsMap());

        map.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD_FLAGS), (int)setting->passwordflags());
        map.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS), (int)setting->privatekeypasswordflags());
        map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS), (int)setting->phase2privatekeypasswordflags());
    }
    return map;
}

QVariantMap Security8021xDbus::toSecretsMap()
{
    QVariantMap map;
    Knm::Security8021xSetting * setting = static_cast<Knm::Security8021xSetting *>(m_setting);
    if (!setting->password().isEmpty())
        map.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD), setting->password());
    if (!setting->privatekeypassword().isEmpty())
        map.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD), setting->privatekeypassword());
    if (!setting->phase2privatekeypassword().isEmpty())
        map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD), setting->phase2privatekeypassword());
    return map;
}

