All pastes #94777 Raw Edit

Unnamed

public text v1 · immutable
#94777 ·published 2006-07-21 14:11 UTC
rendered paste body
static char *
pretty_mask(const char *idmask)
{
        static char mask_buf[BUFSIZE];
        int mask_pos;
        int old_mask_pos;
        char *nick, *user, *host;
        char splat[] = "*";
        char *t, *at, *ex;
        char ne = 0, ue = 0, he = 0;    /* save values at nick[NICKLEN], et all */
        char *mask;

        mask = LOCAL_COPY(idmask);
        mask = check_string(mask);
        collapse(mask);

        nick = user = host = splat;

        if((size_t)BUFSIZE - mask_pos < strlen(mask) + 5)
         return NULL;

        old_mask_pos = mask_pos;

        at = ex = NULL;
        if((t = strchr(mask, '@')) != NULL)
 {
                at = t;
                *t++ = '\0';
                if(*t != '\0')
                        host = t;

                if((t = strchr(mask, '!')) != NULL)
                {
                        ex = t;
                        *t++ = '\0';
                        if(*t != '\0')
                                user = t;
 if(*mask != '\0')
                                nick = mask;
                }
                else
                {
                        if(*mask != '\0')
                user = mask;
                }
        }
        else if((t = strchr(mask, '!')) != NULL)
        {
                ex = t;
                *t++ = '\0';
                if(*mask != '\0')
                        nick = mask;
                if(*t != '\0')
                        user = t;
        }
 else if(strchr(mask, '.') != NULL && strchr(mask, ':') != NULL)
        {
                if(*mask != '\0')
                        host = mask;
        }
        else
 {
                if(*mask != '\0')
                        nick = mask;
        }

        /* truncate values to max lengths */
        if(strlen(nick) > NICKLEN - 1)
        {
                ne = nick[NICKLEN - 1];
                nick[NICKLEN - 1] = '\0';
        }
        if(strlen(user) > USERLEN)
  {
                ue = user[USERLEN];
                user[USERLEN] = '\0';
        }
        if(strlen(host) > HOSTLEN)
        {
 he = host[HOSTLEN];
                host[HOSTLEN] = '\0';
        }

        mask_pos += rs_snprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;

        if(at)
                *at = '@';
        if(ex)
                *ex = '!';
        if(ne)
                nick[NICKLEN - 1] = ne;
        if(ue)
                user[USERLEN] = ue;
        if(he)
                host[HOSTLEN] = he;

        return mask_buf + old_mask_pos;
}