summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--degesch.c65
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 <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 (&copy);
+ str_vector_add_vector (&copy, 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 (&copy, ' ');
+ str_vector_free (&copy);
+ 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 (&copy);
- str_vector_add_vector (&copy, 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 (&copy, ' ');
- str_vector_free (&copy);
- 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" },