+ token = yylex (client->scanner);
+ /* Yes, EOF in two different enums is pretty ugly. */
+ if (token == TTT_TOKEN_EOF)
+ return TTT_STATUS_EOF;
+
+ if (token == TTT_TOKEN_NEWLINE) {
+ if (client->num_request_strings)
+ return TTT_STATUS_SUCCESS;
+ else
+ continue;
+ }
+
+ assert (token == TTT_TOKEN_STRING);
+
+ _append_to_request (client, yyget_text (client->scanner));
+ }
+}
+
+static ttt_error_t
+_execute_request (ttt_client_t *client)
+{
+ int i;
+
+ char *command = client->request_strings[0];
+ int num_args = client->num_request_strings-1;
+ ttt_command_description_t *desc;
+
+ for (i=0; i < strlen (command); i++)
+ command[i] = toupper (command[i]);
+
+ for (i=0; i < ARRAY_SIZE(command_descriptions); i++) {
+ desc = &command_descriptions[i];
+ if (strcmp(command, desc->command) == 0) {
+ if ((num_args < desc->args_min) || (num_args > desc->args_max))
+ return TTT_ERROR_SYNTAX;
+ return (desc->execute) (client, &client->request_strings[1], num_args);
+ }
+ }
+
+ return TTT_ERROR_COMMAND;
+}
+
+static void *
+_handle_requests_thread (void *closure)
+{
+ ttt_status_t status;
+ ttt_error_t error;
+ ttt_client_t *client = closure;
+
+ while (1) {
+
+ status = _read_request (client);
+ if (status == TTT_STATUS_EOF)