degesch: preparations for numerics processing
This commit is contained in:
parent
e937ac12d5
commit
295e4c8bf9
|
@ -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})
|
||||
|
|
65
degesch.c
65
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);
|
||||
}
|
||||
|
||||
|
@ -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" },
|
||||
|
|
Loading…
Reference in New Issue