+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
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
ERROR INVALIDNAME
- All names must be unique.
+ All names must be of non-zero length and must be unique.
Possibly returned by: HELO
/ /---- 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
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
#include "ttt-client.h"
-#include "ttt-command.h"
#include "ttt-error.h"
#include "ttt-lex.h"
#include "ttt-server.h"
} 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
const char *host;
const char *port;
- int next_client_id;
-
ttt_client_t **clients;
int clients_size;
int num_clients;
server->host = host;
server->port = port;
- server->next_client_id = 0;
-
server->clients = NULL;
server->clients_size = 0;
server->num_clients = 0;
{
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;
}
printf ("Client %s has joined.\n", name);
- free (name);
server->num_clients++;