degesch: parse user@host from RPL_WELCOME
This commit is contained in:
parent
a7ccdc78be
commit
f2a2206e49
38
degesch.c
38
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
|
||||
|
Loading…
Reference in New Issue
Block a user