/* HostToMask() Convert a userhost like "user@host.name.org" into "*user@*.name.org" or "user@1.2.3.4" into "*user@1.2.3.*" */ char * HostToMask (char *username, char *hostname) { char *realhost, /* user@host (without nick!) */ *temp, *final, /* final product */ *user, /* stores the username */ *host, /* stores the hostname */ /* * first segment of hostname (ie: if host == "a.b.c", * topsegment == "c" (top-level domain) */ *topsegment = NULL; char userhost[UHOSTLEN + 2]; int ii, /* looping */ cnt, len; if (!username || !hostname) return (NULL); ircsprintf(userhost, "%s@%s", username, hostname); len = strlen(userhost) + 32; final = (char *) MyMalloc(len); memset(final, 0, len); /* strip off a nick nick!user@host (if there is one) */ realhost = (host = strchr(userhost, '!')) ? host + 1 : userhost; user = realhost; if ((host = strchr(realhost, '@'))) { final[0] = '*'; ii = 1; /* * only use the last 8 characters of the username if there * are more * * >=10, not >10. We lost one character to the * prefix * -- asuffield */ if ((host - realhost) >= 10) user = host - 8; /* now store the username into 'final' */ while (*user != '@') final[ii++] = *user++; final[ii++] = '@'; /* host == "@host.name", so point past the @ */ host++; } else { /* there's no @ in the hostname, just make it *@*.host.com */ strcpy(final, "*@"); ii = 2; host = userhost; } /* * ii now points to the offset in 'final' of where the * converted hostname should go */ realhost = strchr(host, '.'); if (realhost) topsegment = strchr(realhost + 1, '.'); if (!realhost || !topsegment) { /* * if realhost is NULL, then the hostname must be a top-level * domain; and if topsegment is NULL, the hostname must be * 2 parts (ie: blah.org), so don't strip off "blah" */ strcpy(final + ii, host); } else { /* * topsegment now contains the top-level domain - if it's * numerical, it MUST be an ip address, since there are * no numerical TLD's =P */ /* advance to the end of topsegment */ for (temp = topsegment; *temp; temp++); --temp; /* point to the last letter (number) of the TLD */ if ((*temp >= '0') && (*temp <= '9')) { /* Numerical IP Address */ while (*temp != '.') --temp; /* * copy the ip address (except the last .XXX) into the * right spot in 'final' */ strncpy(final + ii, host, temp - host); /* stick a .* on the end :-) */ ii += (temp - host); strcpy(final + ii, ".*"); } else { /* its a regular hostname with >= 3 segments */ if (SmartMasking) { /* * Pick up with temp from were we left off above. * Temp now points to the very last charater of userhost. * Go backwards, counting all the periods we encounter. * If we find 3 periods, make the hostmask: * *.seg1.seg2.seg3 * Since some users may have extremely long hostnames * because of some weird isp. Also, if they have * a second TLD, such as xx.xx.isp.com.au, this * routine will make their mask: *.isp.com.au, which * is much better than *.xx.isp.com.au */ cnt = 0; while (temp--) { if (*temp == '.') if (++cnt >= 3) break; } if (cnt >= 3) { /* * We have a hostname with more than 3 segments. * Set topsegment to temp, so the final mask * will be *user@*.seg1.seg2.seg3 */ topsegment = temp; } } /* if (SmartMasking) */ /* * topsegment doesn't necessarily point to the TLD. * It simply points one segment further than realhost. * Check if there is another period in topsegment, * and if so use it. Otherwise use realhost */ ircsprintf(final + ii, "*%s", strchr(topsegment + 1, '.') ? topsegment : realhost); } } return (final); } /* HostToMask() */