summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-07 05:28:57 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-07 05:28:57 +0200
commit62845876d5035345a01d561ceac710e5eae09a71 (patch)
treee987dc84c03581335cc24703cbf3bab9bb151921
parent5bc259e388ae957ae16cecb6ca3e895ec681d85b (diff)
downloadxK-62845876d5035345a01d561ceac710e5eae09a71.tar.gz
xK-62845876d5035345a01d561ceac710e5eae09a71.tar.xz
xK-62845876d5035345a01d561ceac710e5eae09a71.zip
degesch: shuffle code around
-rw-r--r--degesch.c189
1 files changed, 94 insertions, 95 deletions
diff --git a/degesch.c b/degesch.c
index e01da85..abe8236 100644
--- a/degesch.c
+++ b/degesch.c
@@ -3862,100 +3862,7 @@ irc_is_highlight (struct server *s, const char *message)
return result;
}
-// --- Input handling ----------------------------------------------------------
-
-static void
-irc_handle_join (struct server *s, const struct irc_message *msg)
-{
- if (!msg->prefix || msg->params.len < 1)
- return;
-
- const char *channel_name = msg->params.vector[0];
- if (!irc_is_channel (s, channel_name))
- return;
-
- struct channel *channel = str_map_find (&s->irc_channels, channel_name);
- struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel_name);
- hard_assert ((channel && buffer) ||
- (channel && !buffer) || (!channel && !buffer));
-
- // We've joined a new channel
- if (!channel && irc_is_this_us (s, msg->prefix))
- {
- buffer = buffer_new ();
- buffer->type = BUFFER_CHANNEL;
- buffer->name = xstrdup_printf ("%s.%s", s->name, channel_name);
- buffer->server = s;
- buffer->channel = channel =
- irc_make_channel (s, xstrdup (channel_name));
- str_map_set (&s->irc_buffer_map, channel->name, buffer);
-
- buffer_add (s->ctx, buffer);
- buffer_activate (s->ctx, buffer);
-
- // Request the channel mode as we don't get it automatically
- irc_send (s, "MODE %s", channel_name);
- }
-
- // This is weird, ignoring
- if (!channel)
- return;
-
- // Add the user to the channel
- char *nickname = irc_cut_nickname (msg->prefix);
- irc_channel_link_user (channel, irc_get_or_make_user (s, nickname), "");
- free (nickname);
-
- // Finally log the message
- if (buffer)
- {
- buffer_send (s->ctx, buffer, BUFFER_LINE_JOIN, 0,
- .who = irc_to_utf8 (s->ctx, msg->prefix),
- .object = irc_to_utf8 (s->ctx, channel_name));
- }
-}
-
-static void
-irc_handle_kick (struct server *s, const struct irc_message *msg)
-{
- if (!msg->prefix || msg->params.len < 2)
- return;
-
- const char *channel_name = msg->params.vector[0];
- const char *target = msg->params.vector[1];
- if (!irc_is_channel (s, channel_name)
- || irc_is_channel (s, target))
- return;
-
- const char *message = "";
- if (msg->params.len > 2)
- message = msg->params.vector[2];
-
- struct user *user = str_map_find (&s->irc_users, target);
- struct channel *channel = str_map_find (&s->irc_channels, channel_name);
- struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel_name);
- hard_assert ((channel && buffer) ||
- (channel && !buffer) || (!channel && !buffer));
-
- // It would be is weird for this to be false
- if (user && channel)
- {
- if (irc_is_this_us (s, target))
- irc_left_channel (channel);
- else
- irc_remove_user_from_channel (user, channel);
- }
-
- if (buffer)
- {
- buffer_send (s->ctx, buffer, BUFFER_LINE_KICK, 0,
- .who = irc_to_utf8 (s->ctx, msg->prefix),
- .object = irc_to_utf8 (s->ctx, target),
- .reason = irc_to_utf8 (s->ctx, message));
- }
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// --- Mode processor ----------------------------------------------------------
struct mode_processor
{
@@ -4006,6 +3913,7 @@ mode_char_cmp (const void *a, const void *b)
return *(const char *) a - *(const char *) b;
}
+/// Add/remove the current mode character to/from the given ordered list
static void
mode_processor_toggle (struct mode_processor *self, struct str *modes)
{
@@ -4126,7 +4034,98 @@ irc_handle_mode_user (struct server *s, char **params)
mode_processor_run (&p, params, mode_processor_apply_user);
}
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+// --- Input handling ----------------------------------------------------------
+
+static void
+irc_handle_join (struct server *s, const struct irc_message *msg)
+{
+ if (!msg->prefix || msg->params.len < 1)
+ return;
+
+ const char *channel_name = msg->params.vector[0];
+ if (!irc_is_channel (s, channel_name))
+ return;
+
+ struct channel *channel = str_map_find (&s->irc_channels, channel_name);
+ struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel_name);
+ hard_assert ((channel && buffer) ||
+ (channel && !buffer) || (!channel && !buffer));
+
+ // We've joined a new channel
+ if (!channel && irc_is_this_us (s, msg->prefix))
+ {
+ buffer = buffer_new ();
+ buffer->type = BUFFER_CHANNEL;
+ buffer->name = xstrdup_printf ("%s.%s", s->name, channel_name);
+ buffer->server = s;
+ buffer->channel = channel =
+ irc_make_channel (s, xstrdup (channel_name));
+ str_map_set (&s->irc_buffer_map, channel->name, buffer);
+
+ buffer_add (s->ctx, buffer);
+ buffer_activate (s->ctx, buffer);
+
+ // Request the channel mode as we don't get it automatically
+ irc_send (s, "MODE %s", channel_name);
+ }
+
+ // This is weird, ignoring
+ if (!channel)
+ return;
+
+ // Add the user to the channel
+ char *nickname = irc_cut_nickname (msg->prefix);
+ irc_channel_link_user (channel, irc_get_or_make_user (s, nickname), "");
+ free (nickname);
+
+ // Finally log the message
+ if (buffer)
+ {
+ buffer_send (s->ctx, buffer, BUFFER_LINE_JOIN, 0,
+ .who = irc_to_utf8 (s->ctx, msg->prefix),
+ .object = irc_to_utf8 (s->ctx, channel_name));
+ }
+}
+
+static void
+irc_handle_kick (struct server *s, const struct irc_message *msg)
+{
+ if (!msg->prefix || msg->params.len < 2)
+ return;
+
+ const char *channel_name = msg->params.vector[0];
+ const char *target = msg->params.vector[1];
+ if (!irc_is_channel (s, channel_name)
+ || irc_is_channel (s, target))
+ return;
+
+ const char *message = "";
+ if (msg->params.len > 2)
+ message = msg->params.vector[2];
+
+ struct user *user = str_map_find (&s->irc_users, target);
+ struct channel *channel = str_map_find (&s->irc_channels, channel_name);
+ struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel_name);
+ hard_assert ((channel && buffer) ||
+ (channel && !buffer) || (!channel && !buffer));
+
+ // It would be is weird for this to be false
+ if (user && channel)
+ {
+ if (irc_is_this_us (s, target))
+ irc_left_channel (channel);
+ else
+ irc_remove_user_from_channel (user, channel);
+ }
+
+ if (buffer)
+ {
+ buffer_send (s->ctx, buffer, BUFFER_LINE_KICK, 0,
+ .who = irc_to_utf8 (s->ctx, msg->prefix),
+ .object = irc_to_utf8 (s->ctx, target),
+ .reason = irc_to_utf8 (s->ctx, message));
+ }
+}
static void
irc_handle_mode (struct server *s, const struct irc_message *msg)