Commit ee19277d authored by jan.koester's avatar jan.koester
Browse files

test

parent 278e1715
Loading
Loading
Loading
Loading
+17 −43
Original line number Diff line number Diff line
@@ -83,50 +83,24 @@ webedit::Config::Config(const std::string &path) : confplus::Config(path) {
        _language = "en";
    }

    // Parse AUTHDB sources (parallel arrays, same pattern as blogi server)
    try {
        auto *urlKey = getKey("/WEBEDIT/AUTHDB/URL");
        if (!urlKey) {
            std::cerr << "AUTHDB: key /WEBEDIT/AUTHDB/URL not found, dumping config tree:" << std::endl;
            for (auto *node = first(); node; node = node->next()) {
                std::cerr << "  /" << node->getKey();
                if (node->childs()) {
                    for (auto *c = node->getChild(); c; c = c->next()) {
                        std::cerr << std::endl << "    /" << node->getKey() << "/" << c->getKey();
                        if (c->childs()) {
                            for (auto *cc = c->getChild(); cc; cc = cc->next()) {
                                std::cerr << std::endl << "      /" << node->getKey() << "/" << c->getKey() << "/" << cc->getKey()
                                          << " [" << cc->getElements() << " elements]";
                            }
                        } else {
                            std::cerr << " [" << c->getElements() << " elements]";
                        }
                    }
                }
                std::cerr << std::endl;
            }
        }
        auto *nameKey = getKey("/WEBEDIT/AUTHDB/CLIENTNAME");
        auto *secretKey = getKey("/WEBEDIT/AUTHDB/CLIENTSECRET");
        size_t count = getElements(urlKey);
        for (size_t i = 0; i < count; ++i) {
    // Parse AUTHDB sources (indexed sequence-of-mappings:
    // /WEBEDIT/AUTHDB/<i>/URL, .../CLIENTNAME, .../CLIENTSECRET, .../DOMAIN)
    for (size_t i = 0; ; ++i) {
        std::string base = "/WEBEDIT/AUTHDB/" + std::to_string(i);
        if (!getKey(base.c_str()))
            break;

        blogi::AuthSource src;
            src.url = getValue(urlKey, i);
            src.clientName = getValue(nameKey, i);
            src.clientSecret = getValue(secretKey, i);
            try {
                auto *domKey = getKey("/WEBEDIT/AUTHDB/DOMAIN");
                src.domain = getValue(domKey, i);
            } catch (...) {
                src.domain = "";
            }
        try { src.url          = getValue(getKey((base + "/URL").c_str()), 0); }          catch (...) {}
        try { src.clientName   = getValue(getKey((base + "/CLIENTNAME").c_str()), 0); }   catch (...) {}
        try { src.clientSecret = getValue(getKey((base + "/CLIENTSECRET").c_str()), 0); } catch (...) {}
        try { src.domain       = getValue(getKey((base + "/DOMAIN").c_str()), 0); }       catch (...) { src.domain = ""; }

        if (src.url.empty())
            continue;

        _authSources.push_back(std::move(src));
    }
    } catch (confplus::ConfException &e) {
        std::cerr << "AUTHDB config error: " << e.what() << std::endl;
    } catch (...) {
        std::cerr << "AUTHDB config: unknown error" << std::endl;
    }
}

const blogi::AuthSource *webedit::Config::findAuthSource(const std::string &domain) const {