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

test

parent 24899143
Loading
Loading
Loading
Loading
+49 −82
Original line number Diff line number Diff line
@@ -30,12 +30,14 @@
#include "conf.h"

blogi::Config::Config(const std::string &path) : confplus::Config(path), _ConfigPath(path){
    try {
        for(size_t i =0; i<getElements(getKey("/BLOGI/PLUGINDIR")); ++i){
           _PlgDir.push_back(getValue(getKey("/BLOGI/PLUGINDIR"),i));
        }
    } catch(...) {}

    _DBDriver=getValue(getKey("/BLOGI/DATABASE/DRIVER"),0);
    _DBConnection=getValue(getKey("/BLOGI/DATABASE/CONNECTION"),0);
    try { _DBDriver=getValue(getKey("/BLOGI/DATABASE/DRIVER"),0); } catch(...) {}
    try { _DBConnection=getValue(getKey("/BLOGI/DATABASE/CONNECTION"),0); } catch(...) {}

    // Parse global database replicas
    try {
@@ -50,9 +52,9 @@ blogi::Config::Config(const std::string &path) : confplus::Config(path), _Config
        }
    } catch(...) {}

    _AuthUrl=getValue(getKey("/BLOGI/AUTHDB/URL"),0);
    _ClientName=getValue(getKey("/BLOGI/AUTHDB/CLIENTNAME"),0);
    _ClientSecret=getValue(getKey("/BLOGI/AUTHDB/CLIENTSECRET"),0);
    try { _AuthUrl=getValue(getKey("/BLOGI/AUTHDB/URL"),0); } catch(...) {}
    try { _ClientName=getValue(getKey("/BLOGI/AUTHDB/CLIENTNAME"),0); } catch(...) {}
    try { _ClientSecret=getValue(getKey("/BLOGI/AUTHDB/CLIENTSECRET"),0); } catch(...) {}

    // Parse multi-domain AUTHDB sources (parallel arrays)
    try {
@@ -84,7 +86,7 @@ blogi::Config::Config(const std::string &path) : confplus::Config(path), _Config
            _AuthSources.push_back(std::move(src));
        }
    }
    _HttpBind=getValue(getKey("/BLOGI/HTTP/BIND"),0);
    try { _HttpBind=getValue(getKey("/BLOGI/HTTP/BIND"),0); } catch(...) { _HttpBind="0.0.0.0"; }
    try {
        _HttpPort = getIntValue(getKey("/BLOGI/HTTP/PORT"), 0);
    } catch (...) {
@@ -95,20 +97,20 @@ blogi::Config::Config(const std::string &path) : confplus::Config(path), _Config
    } catch (...) {
        _MaxCon = -1;
    }
    _HttpUrl=getValue(getKey("/BLOGI/HTTP/URL"),0);
    try { _HttpUrl=getValue(getKey("/BLOGI/HTTP/URL"),0); } catch(...) {}
    try {
        auto *urlKey = getKey("/BLOGI/HTTP/URL");
        size_t urlCount = getElements(urlKey);
        for (size_t i = 0; i < urlCount; ++i)
            _HttpUrls.push_back(getValue(urlKey, i));
    } catch (...) {
        _HttpUrls.push_back(_HttpUrl);
        if (!_HttpUrl.empty()) _HttpUrls.push_back(_HttpUrl);
    }
    _HttpPrefix=getValue(getKey("/BLOGI/HTTP/PREFIX"),0);
    try { _HttpPrefix=getValue(getKey("/BLOGI/HTTP/PREFIX"),0); } catch(...) {}
    if(_HttpPrefix == "/")
        _HttpPrefix = "";
    _Template=getValue(getKey("/BLOGI/TEMPLATE"),0);
    _StartPage=getValue(getKey("/BLOGI/STARTPAGE"),0);
    try { _Template=getValue(getKey("/BLOGI/TEMPLATE"),0); } catch(...) {}
    try { _StartPage=getValue(getKey("/BLOGI/STARTPAGE"),0); } catch(...) {}

    try{
        _SSLCertpath=getValue(getKey("/BLOGI/SSL/CERT"),0);
@@ -133,79 +135,45 @@ blogi::Config::Config(const std::string &path) : confplus::Config(path), _Config
    }

    // Parse multi-domain configurations
    // libconfplus YAML stores sequence-of-mappings as flat keys with positional values:
    //   /BLOGI/DOMAINS/NAME  pos 0 = "domain1", pos 1 = "domain2"
    //   /BLOGI/DOMAINS/DB_DRIVER  pos 0 = "pgsql", pos 1 = "sqlite"
    // Use NAME element count to determine number of domains.
    try {
        auto *domainsKey = getKey("/BLOGI/DOMAINS");
        size_t domCount = getElements(domainsKey);
        auto *nameKey = getKey("/BLOGI/DOMAINS/NAME");
        if (!nameKey) throw std::runtime_error("no domains");
        size_t domCount = getElements(nameKey);
        for (size_t i = 0; i < domCount; ++i) {
            DomainConfig dc;
            std::string basePath = "/BLOGI/DOMAINS/" + std::to_string(i);

            try { dc.name = getValue(getKey((basePath + "/NAME").c_str()), 0); } catch(...) { continue; }
            try { dc.dbDriver = getValue(getKey((basePath + "/DATABASE/DRIVER").c_str()), 0); } catch(...) { dc.dbDriver = _DBDriver; }
            try { dc.dbConnection = getValue(getKey((basePath + "/DATABASE/CONNECTION").c_str()), 0); } catch(...) { dc.dbConnection = _DBConnection; }
            try { dc.name = getValue(nameKey, i); } catch(...) { continue; }
            try { dc.dbDriver = getValue(getKey("/BLOGI/DOMAINS/DB_DRIVER"), i); } catch(...) { dc.dbDriver = _DBDriver; }
            try { dc.dbConnection = getValue(getKey("/BLOGI/DOMAINS/DB_CONNECTION"), i); } catch(...) { dc.dbConnection = _DBConnection; }

            // Parse per-domain database replicas
            try {
                auto *repKey = getKey((basePath + "/DATABASE/REPLICAS").c_str());
                size_t repCount = getElements(repKey);
                for (size_t r = 0; r < repCount; ++r) {
                    ReplicaConfig rc;
                    std::string repBase = basePath + "/DATABASE/REPLICAS/" + std::to_string(r);
                    try { rc.driver = getValue(getKey((repBase + "/DRIVER").c_str()), 0); } catch(...) { rc.driver = dc.dbDriver; }
                    try { rc.connection = getValue(getKey((repBase + "/CONNECTION").c_str()), 0); } catch(...) { continue; }
                    dc.dbReplicas.push_back(std::move(rc));
                }
            } catch(...) {
            dc.dbReplicas = _DBReplicas;
            }

            try { dc.authUrl = getValue(getKey((basePath + "/AUTHDB/URL").c_str()), 0); } catch(...) { dc.authUrl = _AuthUrl; }
            try { dc.clientName = getValue(getKey((basePath + "/AUTHDB/CLIENTNAME").c_str()), 0); } catch(...) { dc.clientName = _ClientName; }
            try { dc.clientSecret = getValue(getKey((basePath + "/AUTHDB/CLIENTSECRET").c_str()), 0); } catch(...) { dc.clientSecret = _ClientSecret; }
            try { dc.siteUrl = getValue(getKey((basePath + "/HTTP/URL").c_str()), 0); } catch(...) { dc.siteUrl = _HttpUrl; }
            try {
                auto *durlKey = getKey((basePath + "/HTTP/URL").c_str());
                size_t durlCount = getElements(durlKey);
                for (size_t u = 0; u < durlCount; ++u)
                    dc.siteUrls.push_back(getValue(durlKey, u));
            } catch(...) { dc.siteUrls = _HttpUrls; }
            try { dc.prefix = getValue(getKey((basePath + "/HTTP/PREFIX").c_str()), 0); } catch(...) { dc.prefix = _HttpPrefix; }
            try { dc.authUrl = getValue(getKey("/BLOGI/DOMAINS/AUTH_URL"), i); } catch(...) { dc.authUrl = _AuthUrl; }
            try { dc.clientName = getValue(getKey("/BLOGI/DOMAINS/AUTH_CLIENTNAME"), i); } catch(...) { dc.clientName = _ClientName; }
            try { dc.clientSecret = getValue(getKey("/BLOGI/DOMAINS/AUTH_CLIENTSECRET"), i); } catch(...) { dc.clientSecret = _ClientSecret; }
            try { dc.siteUrl = getValue(getKey("/BLOGI/DOMAINS/URL"), i); } catch(...) { dc.siteUrl = _HttpUrl; }
            dc.siteUrls.clear();
            if (!dc.siteUrl.empty()) dc.siteUrls.push_back(dc.siteUrl);
            try { dc.prefix = getValue(getKey("/BLOGI/DOMAINS/PREFIX"), i); } catch(...) { dc.prefix = _HttpPrefix; }
            if (dc.prefix == "/") dc.prefix = "";
            try { dc.templatePath = getValue(getKey((basePath + "/TEMPLATE").c_str()), 0); } catch(...) { dc.templatePath = _Template; }
            try { dc.startPage = getValue(getKey((basePath + "/STARTPAGE").c_str()), 0); } catch(...) { dc.startPage = _StartPage; }
            try { dc.mediaDBUrl = getValue(getKey((basePath + "/MEDIADB/URL").c_str()), 0); } catch(...) { dc.mediaDBUrl = _MediaDBUrl; }
            try { dc.tmpDir = getValue(getKey((basePath + "/TMPDIR").c_str()), 0); } catch(...) { dc.tmpDir = _TmpDir; }
            try { dc.templatePath = getValue(getKey("/BLOGI/DOMAINS/TEMPLATE"), i); } catch(...) { dc.templatePath = _Template; }
            try { dc.startPage = getValue(getKey("/BLOGI/DOMAINS/STARTPAGE"), i); } catch(...) { dc.startPage = _StartPage; }
            try { dc.mediaDBUrl = getValue(getKey("/BLOGI/DOMAINS/MEDIA_URL"), i); } catch(...) { dc.mediaDBUrl = _MediaDBUrl; }
            try { dc.tmpDir = getValue(getKey("/BLOGI/DOMAINS/TMPDIR"), i); } catch(...) { dc.tmpDir = _TmpDir; }

            // Plugin directories for this domain
            // Plugin directory (single value per domain in flat config)
            try {
                auto *plgKey = getKey((basePath + "/PLUGINDIR").c_str());
                for (size_t p = 0; p < getElements(plgKey); ++p) {
                    dc.plgDirs.push_back(getValue(plgKey, p));
                }
                std::string plgdir = getValue(getKey("/BLOGI/DOMAINS/PLUGINDIR"), i);
                if (!plgdir.empty()) dc.plgDirs.push_back(plgdir);
            } catch(...) {
                dc.plgDirs = _PlgDir;
            }

            // Auth sources for this domain
            try {
                auto *aUrlKey = getKey((basePath + "/AUTHDB/URL").c_str());
                auto *aNameKey = getKey((basePath + "/AUTHDB/CLIENTNAME").c_str());
                auto *aSecretKey = getKey((basePath + "/AUTHDB/CLIENTSECRET").c_str());
                size_t aCount = getElements(aUrlKey);
                for (size_t a = 0; a < aCount; ++a) {
                    AuthSource src;
                    src.url = getValue(aUrlKey, a);
                    src.clientName = getValue(aNameKey, a);
                    src.clientSecret = getValue(aSecretKey, a);
                    try {
                        auto *aDomKey = getKey((basePath + "/AUTHDB/DOMAIN").c_str());
                        src.domain = getValue(aDomKey, a);
                    } catch(...) {
                        src.domain = dc.name;
                    }
                    dc.authSources.push_back(std::move(src));
                }
            } catch(...) {
            // Auth source from domain values
            if (!dc.authUrl.empty()) {
                AuthSource src;
                src.url = dc.authUrl;
@@ -214,7 +182,6 @@ blogi::Config::Config(const std::string &path) : confplus::Config(path), _Config
                src.domain = dc.name;
                dc.authSources.push_back(std::move(src));
            }
            }

            _Domains.push_back(std::move(dc));
        }