Files
nextcloud-samba-sync/src/usermanager.h
bartfaik04 31ec926793
All checks were successful
Build / build (push) Successful in 11s
Use configfilemanager to get the real command
2025-06-07 09:26:15 +02:00

121 lines
2.5 KiB
C++

#ifndef _USERMAN_H
#define _USERMAN_H
#include <string>
#include <map>
#include <vector>
#include <set>
#include <sstream>
#include <mutex>
#include "definitions.h"
#include "configfilemanager.h"
class userManager
{
private:
std::map<std::string, bool> users;
std::mutex mtx;
public:
static std::string getScanCommandFromUser(const std::string&, configfilemanager& cfm);
void addUserFromLogLine(std::string &line)
{
addUser(splitString(line, '|').at(USER_LOG_LOCATION));
}
void addUser(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 0)
{
users[user] = false;
}
}
void removeUser(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
users.erase(user);
}
bool isContains(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
return users.count(user) == 1;
}
void setUserFlagged(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1)
{
users[user] = true;
}
}
void setUserUnflagged(std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1)
{
users[user] = false;
}
}
void unflagAllUsers()
{
std::lock_guard<std::mutex> lock(mtx);
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
it->second = false;
}
}
std::set<std::string> getUsers()
{
std::set<std::string> ret;
std::lock_guard<std::mutex> lock(mtx);
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
ret.insert(it->first);
}
return ret;
}
std::set<std::string> getFlaggedUsers()
{
std::set<std::string> ret;
std::lock_guard<std::mutex> lock(mtx);
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
if (it->second)
{
ret.insert(it->first);
}
}
return ret;
}
bool isAnybodyFlagged()
{
std::lock_guard<std::mutex> lock(mtx);
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
if (it->second)
return true;
}
return false;
}
};
#endif // _USERMAN_H