diff --git a/Makefile b/Makefile index 072b595..f956835 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ CC = g++ -CFLAGS = -std=c++20 -Wall -Werror -fsanitize=address +ASAN_FLAGS = -fsanitize=address -fno-omit-frame-pointer -Wno-format-security +CFLAGS := -std=c++20 -Wall -lssl -lcrypto +LDFLAGS += -lpthread TARGET = client server BUILD_DIR = build @@ -16,10 +18,10 @@ $(BUILD_DIR): mkdir -p $(BUILD_DIR) client: $(OBJS_CLIENT) - $(CC) $(CFLAGS) -o twmailer-client $^ + $(CC) $(CFLAGS) $(ASAN_FLAGS) -o twmailer-client $^ server: $(OBJS_SERVER) - $(CC) $(CFLAGS) -o twmailer-server $^ + $(CC) $(CFLAGS) $(ASAN_FLAGS) -o twmailer-server $^ $(BUILD_DIR)/%.o: %.cpp $(CC) $(CFLAGS) -c $< -o $@ diff --git a/server.cpp b/server.cpp index d66b0fd..ca5a884 100644 --- a/server.cpp +++ b/server.cpp @@ -1,6 +1,7 @@ #include "user.h" #include "user_handler.h" +#include #include #include #include @@ -9,12 +10,15 @@ #include #include +#include #include #include #include #include +#include #include +#include #define BUF 1024 @@ -215,18 +219,30 @@ void *clientCommunication(void *data) } buffer[size] = '\0'; - printf("Message received: %s\n", buffer); // ignore error + + + /* New code here for handling requests */ + + + std::stringstream ss(buffer); + std::string line; + + std::vector message; + + while (std::getline(ss, line, '\n')) { + message.push_back(line); + } enum commands cmd; // can't wait for reflections (maybe c++26?) - if (strcasecmp(buffer, "SEND") == 0) cmd = SEND; - else if (strcasecmp(buffer, "LIST") == 0) cmd = LIST; - else if (strcasecmp(buffer, "READ") == 0) cmd = READ; - else if (strcasecmp(buffer, "DEL") == 0) cmd = DEL; - else if (strcasecmp(buffer, "QUIT") == 0) cmd = QUIT; + if (boost::iequals(message.at(0), "SEND")) cmd = SEND; + else if (boost::iequals(message.at(0), "LIST")) cmd = LIST; + else if (boost::iequals(message.at(0), "READ")) cmd = READ; + else if (boost::iequals(message.at(0), "DEL")) cmd = DEL; + else if (boost::iequals(message.at(0), "QUIT")) cmd = QUIT; switch (cmd) { case SEND: