]> git.cworth.org Git - ttt/commitdiff
2005-11-24 Carl Worth <cworth@cworth.org>
authorCarl Worth <carl@theworths.org>
Thu, 24 Nov 2005 15:34:08 +0000 (15:34 +0000)
committerCarl Worth <carl@theworths.org>
Thu, 24 Nov 2005 15:34:08 +0000 (15:34 +0000)
        * 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
PROTOCOL
TODO
src/ttt-client.c
src/ttt-server.c

index c6cfcdc02c194712a531f93831562de41c0d02b2..525bdfd33f631cee48339ae5b08e79316875226b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-11-24  Carl Worth  <cworth@cworth.org>
+
+       * 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  <richard@theworths.org>
 
        * PROTOCOL: Removed unused servername
index fe8905b2d0117639ff4089dea368429b18456294..666379735435cb56aebda1c4aed3be5adfeac89a 100644 (file)
--- 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 [<username>]
+    HELO <username>
     
     ->
     
     HELO <username> <server-addr> <server-port>
 
-    If the client doesn't supply <username>, 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 7972fcef432eb7f959122db27933fa76051e7fab..98b90f5a92d6362756c9125ab7690609f2e7ff82 100644 (file)
--- 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
index 3fdcf83afea53e444c14fa521cc8b6d60f97ced2..508aa88e91ecffba87e9c7e63a3caaa92db521ea 100644 (file)
@@ -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
index e9043b4e2cb25309e65e68ee202af9a617e2a90f..f1a1eef7310473c39f2aa09b5ab6a821cfcad934 100644 (file)
@@ -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++;