From 158f188646caa7739c11cc9d637af6269d23f5db Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sun, 19 Apr 2015 22:47:45 +0200
Subject: degesch: fix "irc_nickname" and send USERHOST
---
degesch.c | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/degesch.c b/degesch.c
index 34ee64c..acec999 100644
--- a/degesch.c
+++ b/degesch.c
@@ -416,10 +416,6 @@ struct app_context
struct str_map irc_channels; ///< IRC channel data
struct str_map irc_buffer_map; ///< Maps IRC identifiers to buffers
- // TODO: initialize and update these two values
- // TODO: probably issue a USERHOST message for ourselves after connecting
- // to enable proper word-wrapping; then store it here also, separately,
- // without the nickname at the beginning; also could just use WHOIS
char *irc_nickname; ///< Current nickname
char *irc_user_mode; ///< Current user mode
@@ -1547,13 +1543,6 @@ make_unseen_prefix (struct app_context *ctx)
static void
make_prompt (struct app_context *ctx, struct str *output)
{
- if (!ctx->irc_ready)
- {
- // XXX: does this make any sense?
- str_append (output, "(disconnected)");
- return;
- }
-
struct buffer *buffer = ctx->current_buffer;
if (!soft_assert (buffer))
return;
@@ -1573,9 +1562,14 @@ make_prompt (struct app_context *ctx, struct str *output)
if (buffer != ctx->global_buffer)
{
str_append_c (output, ' ');
- str_append (output, ctx->irc_nickname);
- if (*ctx->irc_user_mode)
- str_append_printf (output, "(%s)", ctx->irc_user_mode);
+ if (!ctx->irc_fd == -1)
+ str_append (output, "(disconnected)");
+ else
+ {
+ str_append (output, ctx->irc_nickname);
+ if (*ctx->irc_user_mode)
+ str_append_printf (output, "(%s)", ctx->irc_user_mode);
+ }
}
str_append_c (output, ']');
@@ -1958,6 +1952,7 @@ irc_process_message (const struct irc_message *msg,
app_readline_restore (&state, ctx->readline_prompt);
}
+ // XXX: or is the 001 numeric enough? For what?
if (!ctx->irc_ready && (!strcasecmp (msg->command, "MODE")
|| !strcasecmp (msg->command, "376") // RPL_ENDOFMOTD
|| !strcasecmp (msg->command, "422"))) // ERR_NOMOTD
@@ -1967,6 +1962,11 @@ irc_process_message (const struct irc_message *msg,
ctx->irc_ready = true;
refresh_prompt (ctx);
+ // TODO: parse any response and store the result for us in app_context;
+ // this enables proper message splitting on output;
+ // we can also use WHOIS if it's not supported (optional by RFC 2812)
+ irc_send (ctx, "USERHOST %s", ctx->irc_nickname);
+
const char *autojoin = str_map_find (&ctx->config, "autojoin");
if (autojoin)
irc_send (ctx, "JOIN :%s", autojoin);
@@ -2503,6 +2503,10 @@ on_irc_disconnected (struct app_context *ctx)
xclose (ctx->irc_fd);
ctx->irc_fd = -1;
ctx->irc_ready = false;
+ free (ctx->irc_nickname);
+ ctx->irc_nickname = NULL;
+ free (ctx->irc_user_mode);
+ ctx->irc_user_mode = NULL;
ctx->irc_event.closed = true;
poller_fd_reset (&ctx->irc_event);
@@ -2664,6 +2668,10 @@ irc_connect (struct app_context *ctx, struct error **e)
irc_send (ctx, "NICK %s", nickname);
irc_send (ctx, "USER %s 8 * :%s", username, realname);
+
+ // XXX: maybe we should wait for the first message from the server
+ ctx->irc_nickname = xstrdup (nickname);
+ ctx->irc_user_mode = xstrdup ("");
return true;
}
@@ -3043,10 +3051,6 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
- // TODO
- ctx.irc_nickname = xstrdup ("TODO");
- ctx.irc_user_mode = xstrdup ("");
-
rl_startup_hook = init_readline;
rl_catch_sigwinch = false;
rl_callback_handler_install (ctx.readline_prompt, on_readline_input);
--
cgit v1.2.3-70-g09d2