From 8edfe990e819dcc1a951e9bf73c338a015cb6a6a Mon Sep 17 00:00:00 2001
From: David Phillips <david@sighup.nz>
Date: Wed, 27 Jun 2018 23:13:13 +1200
Subject: Remove some magic constants

Also removes old debug print code
---
 alarmd/alarmd.c | 8 +++-----
 lib/libalarm.c  | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/alarmd/alarmd.c b/alarmd/alarmd.c
index 4b3df78..9f2c254 100644
--- a/alarmd/alarmd.c
+++ b/alarmd/alarmd.c
@@ -68,12 +68,12 @@ int handle_register(int c_sock, pid_t owner)
 	}
 
 	new_alarm->name = strdup((const char*)buffer);
-	memcpy(new_alarm->uuid, uuid, 16);
+	memcpy(new_alarm->uuid, uuid, sizeof(new_alarm->uuid));
 	new_alarm->is_raised = 0;
 	new_alarm->owner = owner;
 
 	/* LOCK */
-	HASH_ADD(hh, alarms, uuid, 16, new_alarm);
+	HASH_ADD(hh, alarms, uuid, sizeof(uuid), new_alarm);
 	/* UNLOCK */
 	return 0;
 }
@@ -108,7 +108,7 @@ int handle_set_raised_generic(int c_sock, int shall_raise)
 	size_t nread = 0;
 	struct alarm *target = NULL;
 
-	if ((nread = recv(c_sock, &uuid, 16, 0)) < 16) {
+	if ((nread = recv(c_sock, &uuid, sizeof(uuid), 0)) < sizeof(uuid)) {
 		fprintf(stderr, "Received UUID too short\n");
 		return 1;
 	}
@@ -147,7 +147,6 @@ int handle_query(int c_sock)
 	}
 
 	HASH_ITER(hh, alarms, a, tmp) {
-		fprintf(stderr, "DEBUG : [%s] %s\n", a->is_raised ? "RAISE" : "CLEAR" , a->name);
 		/* FIXME factor out, idiot. also bounds check on strlen */
 		length = strlen(a->name);
 		if (send(c_sock, &length, sizeof(length), 0) < sizeof(length)) {
@@ -162,7 +161,6 @@ int handle_query(int c_sock)
 		if (send(c_sock, &(a->owner), sizeof(a->owner), 0) < sizeof(a->owner)) {
 			perror("send");
 		}
-		fprintf(stderr, "SENT.\n");
 	}
 	/* UNLOCK */
 	return 0;
diff --git a/lib/libalarm.c b/lib/libalarm.c
index 9dc9ae0..20448aa 100644
--- a/lib/libalarm.c
+++ b/lib/libalarm.c
@@ -58,7 +58,7 @@ int send_string(int sock, char *buffer)
 int send_packet_uuid(int sock, uint32_t packet_type, uuid_t uuid)
 {
 	return (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type)
-	        || send(sock, uuid, 16, 0) != 16);
+	        || send(sock, uuid, sizeof(uuid_t), 0) != 16);
 }
 
 /** End helper functions ***********/
-- 
cgit v1.1