fixed receive and command logic
This commit is contained in:
parent
353e3123f3
commit
a5afcbe965
8
Makefile
8
Makefile
@ -1,5 +1,7 @@
|
|||||||
CC = g++
|
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
|
TARGET = client server
|
||||||
BUILD_DIR = build
|
BUILD_DIR = build
|
||||||
@ -16,10 +18,10 @@ $(BUILD_DIR):
|
|||||||
mkdir -p $(BUILD_DIR)
|
mkdir -p $(BUILD_DIR)
|
||||||
|
|
||||||
client: $(OBJS_CLIENT)
|
client: $(OBJS_CLIENT)
|
||||||
$(CC) $(CFLAGS) -o twmailer-client $^
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -o twmailer-client $^
|
||||||
|
|
||||||
server: $(OBJS_SERVER)
|
server: $(OBJS_SERVER)
|
||||||
$(CC) $(CFLAGS) -o twmailer-server $^
|
$(CC) $(CFLAGS) $(ASAN_FLAGS) -o twmailer-server $^
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: %.cpp
|
$(BUILD_DIR)/%.o: %.cpp
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|||||||
28
server.cpp
28
server.cpp
@ -1,6 +1,7 @@
|
|||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "user_handler.h"
|
#include "user_handler.h"
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -9,12 +10,15 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/compute/detail/sha1.hpp>
|
#include <boost/compute/detail/sha1.hpp>
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#define BUF 1024
|
#define BUF 1024
|
||||||
|
|
||||||
@ -215,18 +219,30 @@ void *clientCommunication(void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer[size] = '\0';
|
buffer[size] = '\0';
|
||||||
printf("Message received: %s\n", buffer); // ignore error
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* New code here for handling requests */
|
/* New code here for handling requests */
|
||||||
|
|
||||||
|
|
||||||
|
std::stringstream ss(buffer);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
std::vector<std::string> message;
|
||||||
|
|
||||||
|
while (std::getline(ss, line, '\n')) {
|
||||||
|
message.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
enum commands cmd;
|
enum commands cmd;
|
||||||
|
|
||||||
// can't wait for reflections (maybe c++26?)
|
// can't wait for reflections (maybe c++26?)
|
||||||
if (strcasecmp(buffer, "SEND") == 0) cmd = SEND;
|
if (boost::iequals(message.at(0), "SEND")) cmd = SEND;
|
||||||
else if (strcasecmp(buffer, "LIST") == 0) cmd = LIST;
|
else if (boost::iequals(message.at(0), "LIST")) cmd = LIST;
|
||||||
else if (strcasecmp(buffer, "READ") == 0) cmd = READ;
|
else if (boost::iequals(message.at(0), "READ")) cmd = READ;
|
||||||
else if (strcasecmp(buffer, "DEL") == 0) cmd = DEL;
|
else if (boost::iequals(message.at(0), "DEL")) cmd = DEL;
|
||||||
else if (strcasecmp(buffer, "QUIT") == 0) cmd = QUIT;
|
else if (boost::iequals(message.at(0), "QUIT")) cmd = QUIT;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case SEND:
|
case SEND:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user