summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-07-15 23:28:00 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-07-16 00:57:55 +0200
commit996e0912c26caeb08b8f3874c82177ec81aa14b3 (patch)
treed33e9a9b0443c76b5169d622a0fdc9bf803847df
parentc4199467296eb21488258f29f7029891d918b585 (diff)
downloadxK-996e0912c26caeb08b8f3874c82177ec81aa14b3.tar.gz
xK-996e0912c26caeb08b8f3874c82177ec81aa14b3.tar.xz
xK-996e0912c26caeb08b8f3874c82177ec81aa14b3.zip
First bugfixes
Now we can at least successfully register.
-rw-r--r--src/common.c7
-rw-r--r--src/kike.c16
2 files changed, 14 insertions, 9 deletions
diff --git a/src/common.c b/src/common.c
index e20c79d..fecaa92 100644
--- a/src/common.c
+++ b/src/common.c
@@ -519,7 +519,7 @@ error_set (struct error **e, const char *message, ...)
va_list ap;
va_start (ap, message);
- int size = snprintf (NULL, 0, message, ap);
+ int size = vsnprintf (NULL, 0, message, ap);
va_end (ap);
hard_assert (size >= 0);
@@ -528,7 +528,7 @@ error_set (struct error **e, const char *message, ...)
tmp->message = xmalloc (size + 1);
va_start (ap, message);
- size = snprintf (tmp->message, size + 1, message, ap);
+ size = vsnprintf (tmp->message, size + 1, message, ap);
va_end (ap);
hard_assert (size >= 0);
@@ -579,6 +579,8 @@ struct str_map
void (*free) (void *); ///< Callback to destruct the payload
/// Callback to compare keys for equivalence
+ // FIXME: they may still end up on a different index, and actually should;
+ // delete this callback and put strxfrm() in its place
int (*key_cmp) (const char *, const char *);
};
@@ -1088,6 +1090,7 @@ poller_set (struct poller *self, int fd, short int events,
struct poller_info *info = self->info[index];
info->fd = fd;
+ info->events = events;
info->dispatcher = dispatcher;
info->user_data = data;
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);