diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-22 21:59:50 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-22 21:59:50 +0200 |
commit | f2a2206e49627f81918df89ef682d56736177ad6 (patch) | |
tree | d7e3b4d1fae4ea8543c94575c027878a8e5612ca | |
parent | a7ccdc78bec660f8173a31242ccad029018f9b6f (diff) | |
download | xK-f2a2206e49627f81918df89ef682d56736177ad6.tar.gz xK-f2a2206e49627f81918df89ef682d56736177ad6.tar.xz xK-f2a2206e49627f81918df89ef682d56736177ad6.zip |
degesch: parse user@host from RPL_WELCOME
-rw-r--r-- | degesch.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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 |