83 lines
2.3 KiB
C++
83 lines
2.3 KiB
C++
|
/* This file is part of libravatarserv.
|
||
|
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
||
|
*
|
||
|
* 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 <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include <cstdlib>
|
||
|
#include <basedir.h>
|
||
|
#include "libravatarserv.hpp"
|
||
|
|
||
|
using namespace 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;
|
||
|
}
|
||
|
}
|