From 8ea3ca45ad53987757aa35af80b1e45aca763760 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 19 Aug 2015 15:31:55 +0200 Subject: mds-colour: message parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-colour.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/mds-colour.c b/src/mds-colour.c index 489137e..b49348b 100644 --- a/src/mds-colour.c +++ b/src/mds-colour.c @@ -351,6 +351,20 @@ int handle_message(void) int handle_list_colours(const char* recv_client_id, const char* recv_message_id, const char* recv_include_values) { + int include_values = 0; + + if (strequals(recv_client_id, "0:0")) + return eprint("got a query from an anonymous client, ignoring."), 0; + + if (recv_include_values == NULL) remove_include_values = 0; + else if (strequals(recv_include_values, "yes")) remove_include_values = 1; + else if (strequals(recv_include_values, "no")) remove_include_values = 0; + else + ; /* TODO send EPROTO*/ + + /* TODO send list */ + + return 0; } @@ -365,6 +379,15 @@ int handle_list_colours(const char* recv_client_id, const char* recv_message_id, */ int handle_get_colour(const char* recv_client_id, const char* recv_message_id, const char* recv_name) { + if (strequals(recv_client_id, "0:0")) + return eprint("got a query from an anonymous client, ignoring."), 0; + + if (recv_name == NULL) + ; /* TODO send EPROTO */ + + /* TODO send colour, "not defined" if missing */ + + return 0; } @@ -383,15 +406,45 @@ int handle_get_colour(const char* recv_client_id, const char* recv_message_id, c int handle_set_colour(const char* recv_name, const char* recv_remove, const char* recv_bytes, const char* recv_red, const char* recv_green, const char* recv_blue) { + uint64_t limit = UINT64_MAX; int remove_colour = 0; + int bytes; + uint64_t red, green, blue; if (recv_remove == NULL) remove_colour = 0; else if (strequals(recv_remove, "yes")) remove_colour = 1; else if (strequals(recv_remove, "no")) remove_colour = 0; else + return eprint("got an invalid value on the Remove-header, ignoring."), 0; + + if (recv_name == NULL) + return eprint("did not get all required headers, ignoring."), 0; + + if (remove_colour == 0) { - eprint("got an invalid value on the Remove-header, ignoring."); - return 0; + if ((recv_bytes == NULL) || (recv_red == NULL) || (recv_green == NULL) || (recv_blue == NULL)) + return eprint("did not get all required headers, ignoring."), 0; + + if (strict_atoi(recv_bytes, &bytes, 1, 8)) + return eprint("got an invalid value on the Bytes-header, ignoring."), 0; + if ((bytes != 1) && (bytes != 2) && (bytes != 4) && (bytes != 8)) + return eprint("got an invalid value on the Bytes-header, ignoring."), 0; + + if (bytes < 8) + limit = (((uint64)1) << (bytes * 8)) - 1; + + if (strict_atou64(recv_red, &red, 0, limit)) + return eprint("got an invalid value on the Red-header, ignoring."), 0; + if (strict_atou64(recv_green, &green, 0, limit)) + return eprint("got an invalid value on the Green-header, ignoring."), 0; + if (strict_atou64(recv_blue, &blue, 0, limit)) + return eprint("got an invalid value on the Blue-header, ignoring."), 0; + + /* TOOD set colour */ + } + else + { + /* TODO remove colour */ } return 0; -- cgit v1.2.3-70-g09d2