/* This file is part of libravatarserv. * Copyright © 2018, 2020 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "libravatarserv.hpp" #include #include using namespace libravatarserv; using namespace libravatarserv::settings; bool settings::find_avatar_dir() { const char *envdir = std::getenv("LIBRAVATARSERV_DIR"); if (envdir == nullptr) { // TODO: Remove AVATAR_DIR in 1.0.0 // DEPRECATED because it is potentially used by another program envdir = std::getenv("AVATAR_DIR"); } if (envdir != nullptr && fs::is_directory(envdir)) { avatar_dir = envdir; } else { xdgHandle xdg; xdgInitHandle(&xdg); auto data_dirs = xdgDataDirectories(&xdg); const uint8_t size = sizeof(data_dirs) / sizeof(*data_dirs); for (uint8_t index = 0; index <= size; ++index) { const string searchdir = data_dirs[index] + string("/libravatarserv"); if (fs::is_directory(searchdir)) { avatar_dir = searchdir; break; } } xdgWipeHandle(&xdg); if (avatar_dir.empty()) { return false; } } return true; } void settings::read_settings() { const char *env = std::getenv("LIBRAVATARSERV_DEFAULT_FALLBACK"); if (env != nullptr) { settings.default_fallback = env; } env = std::getenv("LIBRAVATARSERV_REDIRECT_NOFALLBACK"); if (env != nullptr && env[0] == '1') { settings.redirect_nofallback = true; } env = std::getenv("LIBRAVATARSERV_REDIRECT_NOUSER"); if (env != nullptr && env[0] == '1') { settings.redirect_nouser = true; } }