From f8bdcd97af8d0dcee79ab692fffb83dba5a5498a Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 24 Nov 2005 15:34:08 +0000 Subject: [PATCH] 2005-11-24 Carl Worth * PROTOCOL: * src/ttt-server.c: (ttt_server_init), (ttt_server_register_client): Remove unique-name generation from the server. The client is going to have to have code to do this anyway. * src/ttt-client.c: Change minimum arguments for HELO from 0 to 1. * TODO: Note that HELO and ERROR INVALIDNAME are implemented in the server. --- ChangeLog | 13 +++++++++++++ PROTOCOL | 7 ++----- TODO | 4 ++-- src/ttt-client.c | 3 +-- src/ttt-server.c | 19 ++++++------------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index c6cfcdc..525bdfd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-11-24 Carl Worth + + * PROTOCOL: + * src/ttt-server.c: (ttt_server_init), + (ttt_server_register_client): Remove unique-name generation from + the server. The client is going to have to have code to do this + anyway. + + * src/ttt-client.c: Change minimum arguments for HELO from 0 to 1. + + * TODO: Note that HELO and ERROR INVALIDNAME are implemented in + the server. + 2005-11-23 Richard Worth * PROTOCOL: Removed unused servername diff --git a/PROTOCOL b/PROTOCOL index fe8905b..6663797 100644 --- a/PROTOCOL +++ b/PROTOCOL @@ -41,15 +41,12 @@ Document Conventions use must be done through some external mechanism. Once connected, the client must identify itself: - HELO [] + HELO -> HELO - If the client doesn't supply , the server will compute - one and return it. - Possible errors: INVALIDNAME 1.2. Global commands @@ -261,7 +258,7 @@ Document Conventions ERROR INVALIDNAME - All names must be unique. + All names must be of non-zero length and must be unique. Possibly returned by: HELO diff --git a/TODO b/TODO index 7972fce..98b90f5 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,7 @@ / /---- Client, implemented in ttt S C 1. Requests - 1.1 HELO +✓ 1.1 HELO 1.2. Global commands 1.2.1. WHO 1.2.2. MESSAGE @@ -32,7 +32,7 @@ S C 3. Errors 3.1. Connection setup errors 3.1.1. ERROR NONAMESET - 3.1.2. ERROR INVALIDNAME +✓ 3.1.2. ERROR INVALIDNAME 3.2. Command format errors 3.2.1. ERROR COMMAND 3.2.2. ERROR SYNTAX diff --git a/src/ttt-client.c b/src/ttt-client.c index 3fdcf83..508aa88 100644 --- a/src/ttt-client.c +++ b/src/ttt-client.c @@ -21,7 +21,6 @@ #include "ttt-client.h" -#include "ttt-command.h" #include "ttt-error.h" #include "ttt-lex.h" #include "ttt-server.h" @@ -59,7 +58,7 @@ typedef struct _ttt_command_description { } ttt_command_description_t; ttt_command_description_t command_descriptions[] = { - {"HELO", 0, 1, _ttt_client_execute_helo} + {"HELO", 1, 1, _ttt_client_execute_helo} }; static ttt_error_t diff --git a/src/ttt-server.c b/src/ttt-server.c index e9043b4..f1a1eef 100644 --- a/src/ttt-server.c +++ b/src/ttt-server.c @@ -32,8 +32,6 @@ struct _ttt_server { const char *host; const char *port; - int next_client_id; - ttt_client_t **clients; int clients_size; int num_clients; @@ -47,8 +45,6 @@ ttt_server_init (ttt_server_t *server, const char *host, const char *port) server->host = host; server->port = port; - server->next_client_id = 0; - server->clients = NULL; server->clients_size = 0; server->num_clients = 0; @@ -60,19 +56,17 @@ ttt_server_register_client (ttt_server_t *server, ttt_client_t *client) { int i; ttt_error_t error = TTT_ERROR_NONE; - char *name; + const char *name; pthread_mutex_lock (&server->mutex); - name = xstrdup (ttt_client_get_name (client)); + name = ttt_client_get_name (client); - if (name == NULL) { - xasprintf(&name, "user%03d", server->next_client_id++); - ttt_client_set_name (client, name); - } + assert (name != NULL); + + if (name[0] == '\0') + return TTT_ERROR_INVALIDNAME; - /* XXX: If generated name is not unique, this will return an error, - which violates the protocol. */ for (i = 0; i < server->num_clients; i++) { if (strcmp (ttt_client_get_name (server->clients[i]), name) == 0) { error = TTT_ERROR_INVALIDNAME; @@ -81,7 +75,6 @@ ttt_server_register_client (ttt_server_t *server, ttt_client_t *client) } printf ("Client %s has joined.\n", name); - free (name); server->num_clients++; -- 2.43.0