aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2026-05-25 05:48:07 +0200
committerPaul Oliver <contact@pauloliver.dev>2026-05-25 05:48:58 +0200
commit43764cc5172156d02d88a042c31f0c9d204cf0e6 (patch)
tree312de7c5fb739401f5785ceb642a130203826883 /data
parentad21f51f4f14da9b9283fa72f1574cdb7286c4d9 (diff)
Makes all comms between client and server JSON
Diffstat (limited to 'data')
-rw-r--r--data/server.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/data/server.c b/data/server.c
index c2fd276..2d96b81 100644
--- a/data/server.c
+++ b/data/server.c
@@ -1,6 +1,7 @@
#include <arpa/inet.h>
#include <json-c/json.h>
#include <signal.h>
+#include <string.h>
#include <threads.h>
#include "logger.c"
@@ -48,6 +49,11 @@ void respond_hash(int client_fd) {
json_object_put(git_hash);
}
+void respond_data(int client_fd, struct json_object *request_json) {
+ assert(request_json);
+ (void)client_fd;
+}
+
int handle_client(struct Client *client) {
assert(client);
@@ -55,23 +61,28 @@ int handle_client(struct Client *client) {
inet_ntop(AF_INET, &client->addr.sin_addr, client_ip, INET_ADDRSTRLEN);
log_info("Client connected: %s:%d", client_ip, ntohs(client->addr.sin_port));
- char request = '\0';
- recv(client->fd, &request, 1, 0);
+ struct json_object *request_json = json_object_from_fd(client->fd);
+ struct json_object *request_str = NULL;
+
+ if (!json_object_object_get_ex(request_json, "request", &request_str)) assert(false);
- switch (request) {
- case REQUEST_NAME:
+ const char *request = json_object_get_string(request_str);
+ assert(request);
+
+ if (!strcmp(request, "name")) {
respond_name(client->fd);
- break;
- case REQUEST_OPTS:
+ } else if (!strcmp(request, "opts")) {
respond_opts(client->fd);
- break;
- case REQUEST_HASH:
+ } else if (!strcmp(request, "hash")) {
respond_hash(client->fd);
- break;
- default:
- log_warn("Client made invalid request");
+ } else if (!strcmp(request, "data")) {
+ respond_data(client->fd, request_json);
+ } else {
+ assert(false);
}
+ json_object_put(request_json);
+
log_info("Client disconnected: %s:%d", client_ip, ntohs(client->addr.sin_port));
close(client->fd);