diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-21 22:08:18 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-21 22:08:18 +0200 |
commit | 295e4c8bf92921790cc980b702a2c7740ccc649f (patch) | |
tree | 070388020638e0aba149a3766e593ecdd04cfeec /degesch.c | |
parent | e937ac12d51a9d58b2bcddb18be0ab5f93488600 (diff) | |
download | xK-295e4c8bf92921790cc980b702a2c7740ccc649f.tar.gz xK-295e4c8bf92921790cc980b702a2c7740ccc649f.tar.xz xK-295e4c8bf92921790cc980b702a2c7740ccc649f.zip |
degesch: preparations for numerics processing
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 65 |
1 files changed, 43 insertions, 22 deletions
@@ -37,6 +37,7 @@ #define PROGRAM_NAME "degesch" #include "common.c" +#include "kike-replies.c" #include <langinfo.h> #include <locale.h> @@ -238,6 +239,7 @@ struct channel char *topic; ///< Channel topic struct channel_user *users; ///< Channel users + struct str_vector names_buf; ///< Buffer for RPL_NAMREPLY }; static struct channel * @@ -245,6 +247,7 @@ channel_new (void) { struct channel *self = xcalloc (1, sizeof *self); self->ref_count = 1; + str_vector_init (&self->names_buf); return self; } @@ -256,6 +259,7 @@ channel_destroy (struct channel *self) free (self->topic); LIST_FOR_EACH (struct channel_user, iter, self->users) channel_user_destroy (iter); + str_vector_free (&self->names_buf); free (self); } @@ -2253,6 +2257,38 @@ irc_handler_cmp_by_name (const void *a, const void *b) } static void +irc_process_numeric (struct app_context *ctx, + const struct irc_message *msg, unsigned long numeric) +{ + // Numerics typically have human-readable information + + // Get rid of the first parameter, if there's any at all, + // as it contains our nickname and is of no practical use to the user + struct str_vector copy; + str_vector_init (©); + str_vector_add_vector (©, msg->params.vector + !!msg->params.len); + + // Join the parameter vector back, recode it to our internal encoding + // and send it to the server buffer + char *reconstructed = join_str_vector (©, ' '); + str_vector_free (©); + char *utf8 = irc_to_utf8 (ctx, reconstructed); + free (reconstructed); + buffer_send_status (ctx, ctx->server_buffer, "%s", utf8); + free (utf8); + + switch (numeric) + { + case IRC_RPL_NAMREPLY: + // TODO: find the channel and if found, push nicks to names_buf + break; + case IRC_RPL_ENDOFNAMES: + // TODO: find the channel and if found, overwrite users + break; + } +} + +static void irc_process_message (const struct irc_message *msg, const char *raw, void *user_data) { @@ -2296,30 +2332,11 @@ irc_process_message (const struct irc_message *msg, struct irc_handler *handler = bsearch (&key, g_irc_handlers, N_ELEMENTS (g_irc_handlers), sizeof key, irc_handler_cmp_by_name); if (handler) - { handler->handler (ctx, msg); - return; - } - // Numerics typically have human-readable information - unsigned long dummy; - if (xstrtoul (&dummy, msg->command, 10)) - { - // Get rid of the first parameter, if there's any at all, - // as it contains our nickname and is of no practical use to the user - struct str_vector copy; - str_vector_init (©); - str_vector_add_vector (©, msg->params.vector + !!msg->params.len); - - // Join the parameter vector back, recode it to our internal encoding - // and send it to the server buffer - char *reconstructed = join_str_vector (©, ' '); - str_vector_free (©); - char *utf8 = irc_to_utf8 (ctx, reconstructed); - free (reconstructed); - buffer_send_status (ctx, ctx->server_buffer, "%s", utf8); - free (utf8); - } + unsigned long numeric; + if (xstrtoul (&numeric, msg->command, 10)) + irc_process_numeric (ctx, msg, numeric); } // --- User input handling ----------------------------------------------------- @@ -3302,6 +3319,10 @@ init_poller_events (struct app_context *ctx) int main (int argc, char *argv[]) { + // We include a generated file from kike including this array we don't use; + // let's just keep it there and silence the compiler warning instead + (void) g_default_replies; + static const struct opt opts[] = { { 'd', "debug", NULL, 0, "run in debug mode" }, |