diff options
| author | David Phillips <david@sighup.nz> | 2018-06-04 00:27:44 +1200 | 
|---|---|---|
| committer | David Phillips <david@sighup.nz> | 2018-06-04 00:27:44 +1200 | 
| commit | 89d1151c084d521f4c3fa68fd49716d46c74ed14 (patch) | |
| tree | 1f8c19e399a7d20afe617a38a9b42bd3bcee20c2 /alarm-tools | |
| parent | 92e15e302844a46185a80e43caea1be2f135e150 (diff) | |
| download | alarmd-89d1151c084d521f4c3fa68fd49716d46c74ed14.tar.xz | |
Remove old test code file
Diffstat (limited to 'alarm-tools')
| -rw-r--r-- | alarm-tools/alarmd_reference_client.c | 224 | 
1 files changed, 0 insertions, 224 deletions
diff --git a/alarm-tools/alarmd_reference_client.c b/alarm-tools/alarmd_reference_client.c deleted file mode 100644 index d200e04..0000000 --- a/alarm-tools/alarmd_reference_client.c +++ /dev/null @@ -1,224 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <string.h> -#include <arpa/inet.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netdb.h> -#include <unistd.h> - -#include "alarmd_proto.h" - -int8_t read_string(int sock, char (*buffer)[128]) -{ -	uint8_t length = 0; -	if (recv(sock, &length, sizeof(uint8_t), 0) < sizeof(uint8_t)) { -		return -1; -	} -	if (length >= 128) { -		return -1; -	} -	if (recv(sock, buffer, length, 0) < 0) { -		return -1; -	} -	(*buffer)[127] = '\0'; -	return length; -} - -int alarmd_dump_alarms(int sock) -{ -	ssize_t i = 0; -	ssize_t nread = 0; -	size_t length = 0; -	uint32_t count = 0; -	uint32_t packet_type = 0; -	uint8_t is_raised = 0; -	char buffer[128]; - -	packet_type = htonl(ALARMD_PACKET_TYPE_QUERY); - -	if (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type)) { -		perror("send"); -		return 1; -	} - -	nread = recv(sock, &count, sizeof(count), 0); -	if (nread < 0) { -		perror("recv"); -		return 1; -	} else if (nread < sizeof(count)) { -		fprintf(stderr, "Alarm count too small\n"); -		return 1; -	} - -	count = ntohl(count); - -	printf("Alarms\n" -	       "------\n"); - -	for (i = 0; i < count; i++) { -		if ((length = read_string(sock, &buffer)) < 0) { -			perror("recv"); -			break; -		} -		if (recv(sock, &is_raised, sizeof(is_raised), 0) != sizeof(is_raised)) { -			perror("recv"); -			break; -		} -		printf("[%s] %s\n", is_raised ? "\x1b[1;31mRAISE\x1b[0m" : "\x1b[1;32mCLEAR\x1b[0m", buffer); -	} - -	if (i < count) { -		fprintf(stderr, "Not all alarms received, output must be missing some\n"); -		return 1; -	} - -	printf("\n"); - -	return 0; -} - -int alarmd_register(int sock, char *desc, char (*uuid)[16]) -{ -	uint8_t length = 0; -	uint32_t packet_type = 0; - -	packet_type = htonl(ALARMD_PACKET_TYPE_REGISTER); -	if (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type)) { -		perror("send"); -		return 1; -	} - -	length = strlen(desc); -	if (send(sock, &length, sizeof(length), 0) != sizeof(length)) { -		perror("send"); -		return 1; -	} - -	if (send(sock, desc, strlen(desc), 0) != strlen(desc)) { -		perror("send"); -		return 1; -	} -	if (recv(sock, uuid, 16, 0) != 16) { -		perror("recv"); -		return 1; -	} -	return 0; -} - -int alarmd_deregister(int sock, char uuid[16]) -{ -	uint32_t packet_type = 0; - -	packet_type = htonl(ALARMD_PACKET_TYPE_DEREGISTER); -	if (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type)) { -		perror("send"); -		return 1; -	} - -	/* FIXME 16 magic */ -	if (send(sock, uuid, 16, 0) != 16) { -		perror("send"); -		return 1; -	} -	return 0; -} - -int alarmd_raise(int sock, char uuid[16]) -{ -	uint32_t packet_type = 0; - -	packet_type = htonl(ALARMD_PACKET_TYPE_RAISE); -	if (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type)) { -		perror("send"); -		return 1; -	} - -	/* FIXME 16 magic */ -	if (send(sock, uuid, 16, 0) != 16) { -		perror("send"); -		return 1; -	} -	return 0; -} - -int alarmd_clear(int sock, char uuid[16]) -{ -	uint32_t packet_type = 0; - -	packet_type = htonl(ALARMD_PACKET_TYPE_CLEAR); -	if (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type)) { -		perror("send"); -		return 1; -	} - -	/* FIXME 16 magic */ -	if (send(sock, uuid, 16, 0) != 16) { -		perror("send"); -		return 1; -	} -	return 0; -} - -int main(void) -{ -	int sock = 0; -	char buffer[128]; -	struct addrinfo hints, *s_info, *p; - -	bzero(&hints, sizeof(hints)); -	hints.ai_family = AF_UNSPEC; -	hints.ai_socktype = SOCK_STREAM; - -	/* FIXME spec custom hostname on cmd line */ -	if (getaddrinfo("localhost", ALARMD_PORT, &hints, &s_info) != 0) { -		perror("getaddrinfo"); -		return 1; -	} - -	for (p = s_info; p != NULL; p = p->ai_next) { -		if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) { -			perror("socket"); -			continue; -		} -		if (connect(sock, p->ai_addr, p->ai_addrlen) < 0) { -			close(sock); -			perror("connect"); -			continue; -		} -		break; -	} - -	if (!p) { -		fprintf(stderr, "Connection to server failed\n"); -		return 1; -	} - - -	/**/ -	char *name = "Some test alarm"; -	char uuid[16]; -	/**/ - -	freeaddrinfo(s_info); - -	printf(">>>Register\n"); -	int i, j; -	for (i = 0; i < 10000; i++) { -		for (j = 0; j < 100; j++) { -			alarmd_register(sock, name, &uuid); -		} -		fprintf(stderr, "%d", i); -	} -	 -//	alarmd_dump_alarms(sock); -//	printf(">>>Raise\n"); -//	alarmd_raise(sock, uuid); -//	alarmd_dump_alarms(sock); -//	printf(">>>Clear\n"); -//	alarmd_clear(sock, uuid); -//	alarmd_dump_alarms(sock); -//	printf(">>>Deregister\n"); -//	alarmd_deregister(sock, uuid); -	close(sock); -}  | 
