summaryrefslogtreecommitdiff
path: root/src/kike.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kike.c')
-rw-r--r--src/kike.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/kike.c b/src/kike.c
index 4e49ffe..0325e41 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -148,7 +148,7 @@ irc_validate_to_str (enum validation_result result)
#define N6 "[0-9ABCDEFabcdef]{1,}"
#define LE "A-Za-z"
-#define SP "\\[\\]\\\\`_^{|}"
+#define SP "][\\\\`_^{|}"
static enum validation_result
irc_validate_hostname (const char *hostname)
@@ -192,7 +192,7 @@ irc_validate_nickname (const char *nickname)
{
if (!*nickname)
return VALIDATION_ERROR_EMPTY;
- if (!irc_regex_match ("^[" LE SP "][-0-9" LE SP "]*$", nickname))
+ if (!irc_regex_match ("^[" SP LE "][" SP LE "0-9-]*$", nickname))
return VALIDATION_ERROR_INVALID;
if (strlen (nickname) > IRC_MAX_NICKNAME)
return VALIDATION_ERROR_TOO_LONG;
@@ -706,7 +706,7 @@ irc_register_handlers (struct server_context *ctx)
for (size_t i = 0; i < N_ELEMENTS (message_handlers); i++)
{
const struct irc_command *cmd = &message_handlers[i];
- str_map_set (&ctx->handlers, cmd->name, (void *) cmd->handler);
+ str_map_set (&ctx->handlers, cmd->name, (void *) cmd);
}
}
@@ -723,8 +723,7 @@ irc_process_message (const struct irc_message *msg,
struct client *c = user_data;
struct irc_command *cmd = str_map_find (&c->ctx->handlers, msg->command);
if (!cmd)
- irc_send_reply (c, IRC_ERR_UNKNOWNCOMMAND,
- "%s: Unknown command", msg->command);
+ irc_send_reply (c, IRC_ERR_UNKNOWNCOMMAND, msg->command);
else if (cmd->requires_registration && !c->registered)
irc_send_reply (c, IRC_ERR_NOTREGISTERED);
else
@@ -1020,20 +1019,22 @@ on_irc_client_available (const struct pollfd *pfd, void *user_data)
char host[NI_MAXHOST] = "unknown", port[NI_MAXSERV] = "unknown";
int err = getnameinfo ((struct sockaddr *) &peer, peer_len,
- host, sizeof host, port, sizeof port, AI_NUMERICSERV);
+ host, sizeof host, port, sizeof port, NI_NUMERICSERV);
if (err)
print_debug ("%s: %s", "getnameinfo", gai_strerror (err));
print_debug ("accepted connection from %s:%s", host, port);
struct client *c = xmalloc (sizeof *c);
client_init (c);
+ c->ctx = ctx;
c->socket_fd = fd;
c->hostname = xstrdup (host);
LIST_PREPEND (ctx->clients, c);
// TODO: set a timeout on the socket, something like 3 minutes, then we
// should terminate the connection.
- poller_set (&ctx->poller, c->socket_fd, POLLIN,
+ set_blocking (fd, false);
+ poller_set (&ctx->poller, fd, POLLIN,
(poller_dispatcher_func) on_irc_client_ready, c);
}
}
@@ -1283,6 +1284,7 @@ irc_listen (struct server_context *ctx, struct error **e)
return false;
}
+ set_blocking (sockfd, false);
ctx->listen_fd = sockfd;
poller_set (&ctx->poller, ctx->listen_fd, POLLIN,
(poller_dispatcher_func) on_irc_client_available, ctx);