added userhandler (WIP)
This commit is contained in:
parent
9ef789caf3
commit
ddb1c277a3
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,5 +1,9 @@
|
|||||||
twmailer-server
|
twmailer-server
|
||||||
twmailer-client
|
twmailer-client
|
||||||
|
spool
|
||||||
|
|
||||||
|
.cache
|
||||||
|
compile_commands.json
|
||||||
|
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
*.d
|
*.d
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
#include "user_handler.h"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -34,6 +35,8 @@ inline bool isInteger(const std::string & s);
|
|||||||
void *clientCommunication(void *data);
|
void *clientCommunication(void *data);
|
||||||
void signalHandler(int sig);
|
void signalHandler(int sig);
|
||||||
|
|
||||||
|
user_handler* user_handler::instancePtr = nullptr;
|
||||||
|
|
||||||
int main (int argc, char* argv[])
|
int main (int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if (argc < 3 ||
|
if (argc < 3 ||
|
||||||
@ -44,6 +47,12 @@ int main (int argc, char* argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs::path spool_dir;
|
||||||
|
user_handler::getInstance()->setSpoolDir(spool_dir = fs::path(argv[2]));
|
||||||
|
|
||||||
|
fs::create_directory(spool_dir/"users");
|
||||||
|
fs::create_directory(spool_dir/"messages");
|
||||||
|
|
||||||
char* p;
|
char* p;
|
||||||
u_long PORT = strtoul(argv[1], &p, 10);
|
u_long PORT = strtoul(argv[1], &p, 10);
|
||||||
|
|
||||||
|
|||||||
5
user.cpp
5
user.cpp
@ -1,3 +1,8 @@
|
|||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|
||||||
|
user::user(fs::path)
|
||||||
|
{
|
||||||
|
// json stuff go here
|
||||||
|
}
|
||||||
|
|
||||||
user::~user() {}
|
user::~user() {}
|
||||||
12
user.h
12
user.h
@ -5,6 +5,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static const bool ptr_cmp = [](T* left, T* right) { return *left < *right; };
|
static const bool ptr_cmp = [](T* left, T* right) { return *left < *right; };
|
||||||
@ -14,13 +17,14 @@ typedef std::set<mail*, decltype(ptr_cmp<int>)> maillist;
|
|||||||
class user {
|
class user {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
user(std::string name, maillist mails)
|
user(fs::path);
|
||||||
: name(name), mails(mails)
|
user(std::string name)
|
||||||
{};
|
: name(name) {};
|
||||||
|
|
||||||
~user();
|
~user();
|
||||||
|
|
||||||
void addMail(mail mail);
|
void addMail(mail mail);
|
||||||
std::set<mail*> getMails();
|
maillist getMails() { return this->mails; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
12
user_handler.cpp
Normal file
12
user_handler.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "user_handler.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
user_handler::user_handler()
|
||||||
|
{
|
||||||
|
for (const auto& entry : fs::directory_iterator()) {
|
||||||
|
if (entry.path().extension() == ".json") {
|
||||||
|
this->users.insert(std::pair<std::string, user*>(fs::path(entry.path()).replace_extension(), new user(entry)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
user_handler.h
Normal file
36
user_handler.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "user.h"
|
||||||
|
#include <filesystem>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
/* singleton for handling users */
|
||||||
|
class user_handler {
|
||||||
|
public:
|
||||||
|
|
||||||
|
user_handler(const user_handler& obj) = delete;
|
||||||
|
|
||||||
|
static user_handler* getInstance() {
|
||||||
|
if (instancePtr == nullptr) {
|
||||||
|
instancePtr = new user_handler();
|
||||||
|
return instancePtr;
|
||||||
|
} else {
|
||||||
|
return instancePtr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
~user_handler();
|
||||||
|
|
||||||
|
void setSpoolDir(fs::path p) { this->spool_dir = p; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static user_handler* instancePtr;
|
||||||
|
user_handler();
|
||||||
|
|
||||||
|
fs::path spool_dir;
|
||||||
|
std::map<std::string, user*> users;
|
||||||
|
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user