From f2a2206e49627f81918df89ef682d56736177ad6 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Wed, 22 Apr 2015 21:59:50 +0200 Subject: degesch: parse user@host from RPL_WELCOME --- degesch.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/degesch.c b/degesch.c index 5ed9dc8..a5443f5 100644 --- a/degesch.c +++ b/degesch.c @@ -2256,6 +2256,39 @@ irc_handler_cmp_by_name (const void *a, const void *b) return strcasecmp_ascii (first->name, second->name); } +static bool +irc_try_parse_word_for_userhost (struct app_context *ctx, const char *word) +{ + regex_t re; + int err = regcomp (&re, "^[^!@]+!([^!@]+@[^!@]+)$", REG_EXTENDED); + if (!soft_assert (!err)) + return false; + + regmatch_t matches[2]; + bool result = false; + if (!regexec (&re, word, 2, matches, 0)) + { + free (ctx->irc_user_host); + ctx->irc_user_host = xstrndup (word + matches[1].rm_so, + matches[1].rm_eo - matches[1].rm_so); + result = true; + } + regfree (&re); + return result; +} + +static void +irc_try_parse_welcome_for_userhost (struct app_context *ctx, const char *m) +{ + struct str_vector v; + str_vector_init (&v); + split_str_ignore_empty (m, ' ', &v); + for (size_t i = 0; i < v.len; i++) + if (irc_try_parse_word_for_userhost (ctx, v.vector[i])) + break; + str_vector_free (&v); +} + static void irc_process_numeric (struct app_context *ctx, const struct irc_message *msg, unsigned long numeric) @@ -2279,6 +2312,11 @@ irc_process_numeric (struct app_context *ctx, switch (numeric) { + case IRC_RPL_WELCOME: + // We still issue a USERHOST anyway as this is in general unreliable + if (msg->params.len == 1) + irc_try_parse_welcome_for_userhost (ctx, msg->params.vector[0]); + break; case IRC_RPL_ISUPPORT: // TODO: parse this, mainly PREFIX; see // http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt -- cgit v1.2.3-70-g09d2