From 295e4c8bf92921790cc980b702a2c7740ccc649f Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 21 Apr 2015 22:08:18 +0200
Subject: degesch: preparations for numerics processing
---
CMakeLists.txt | 3 ++-
degesch.c | 65 ++++++++++++++++++++++++++++++++++++++--------------------
2 files changed, 45 insertions(+), 23 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b665740..f7f1945 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,7 +60,8 @@ set_source_files_properties (${PROJECT_BINARY_DIR}/kike-replies.c
add_executable (zyklonb zyklonb.c ${common_sources} ${common_headers})
target_link_libraries (zyklonb ${project_libraries})
-add_executable (degesch degesch.c ${common_sources} ${common_headers})
+add_executable (degesch degesch.c kike-replies.c
+ ${common_sources} ${common_headers})
target_link_libraries (degesch ${project_libraries} readline)
add_executable (kike kike.c kike-replies.c ${common_sources} ${common_headers})
diff --git a/degesch.c b/degesch.c
index 6555224..85f3ff4 100644
--- a/degesch.c
+++ b/degesch.c
@@ -37,6 +37,7 @@
#define PROGRAM_NAME "degesch"
#include "common.c"
+#include "kike-replies.c"
#include
#include
@@ -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);
}
@@ -2252,6 +2256,38 @@ irc_handler_cmp_by_name (const void *a, const void *b)
return strcasecmp_ascii (first->name, second->name);
}
+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" },
--
cgit v1.2.3-70-g09d2