weechat-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Weechat-dev] [task #6583] handle netsplits in some better way.


From: Mantas M.
Subject: [Weechat-dev] [task #6583] handle netsplits in some better way.
Date: Fri, 24 Jan 2014 15:54:27 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36

Follow-up Comment #2, task #6583 (project weechat):

This is how irssi detects netsplit quits.

(Some checks might no longer be necessary, as almost all servers prefix
user-provided quit messages with "Quit: " or similar. Still...)


/* check if quit message is a netsplit message */
int quitmsg_is_split(const char *msg)
{
        const char *host2, *p;
        int prev, len, host1_dot, host2_dot;

        g_return_val_if_fail(msg != NULL, FALSE);

        /* NOTE: there used to be some paranoia checks (some older IRC
           clients have even more), but they're pretty useless nowadays,
           since IRC server prefixes the quit message with a space if it
           looks like a netsplit message.

           So, the check is currently just:
             - host1.domain1 host2.domain2
             - top-level domains have to be 2+ characters long,
               containing only alphabets
             - only 1 space
             - no double-dots (".." - probably useless check)
             - hosts/domains can't start or end with a dot
             - the two hosts can't be identical (probably useless check)
             - can't contain ':' or '/' chars (some servers allow URLs)
           */
        host2 = NULL;
        prev = ' '; len = 0; host1_dot = host2_dot = 0;
        while (*msg != ' ') {
                if (*msg == ' ') {
                        if (prev == '.' || prev == ' ') {
                                /* domains can't end with '.', space can't
                                   be the first character in msg. */
                                return FALSE;
                        }
                        if (host2 != NULL)
                                return FALSE; /* only one space allowed */
                        if (!host1_dot)
                                return FALSE; /* host1 didn't have domain */
                        host2 = msg+1; len = -1;
                } else if (*msg == '.') {
                        if (prev == ' ' || prev == ' ' || prev == '.') {
                                /* domains can't start with '.'
                                   and can't have ".." */
                                return FALSE;
                        }

                        if (host2 != NULL)
                                host2_dot = TRUE;
                        else
                                host1_dot = TRUE;
                } else if (*msg == ':' || *msg == '/')
                        return FALSE;

                prev = *msg;
                msg++; len++;
        }

        if (!host2_dot || prev == '.')
                return FALSE;

        /* top-domain1 must be 2+ chars long and contain only alphabets */
        p = host2-1;
        while (p[-1] != '.') {
                if (!i_isalpha(p[-1]))
                        return FALSE;
                p--;
        }
        if (host2-p-1 < 2) return FALSE;

        /* top-domain2 must be 2+ chars long and contain only alphabets */
        p = host2+strlen(host2);
        while (p[-1] != '.') {
                if (!i_isalpha(p[-1]))
                        return FALSE;
                p--;
        }
        if (strlen(p) < 2) return FALSE;

        return TRUE;
}


    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/task/?6583>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]