no more static buffers for iptoa and iprtoa
This commit is contained in:
@@ -76,7 +76,8 @@ int pingpckserver(void *data) // fetch updates.txt from a media server, measure
|
||||
u.set(s->host);
|
||||
s->resolved = h.set_host(u.domain) ? 1 : 0;
|
||||
SDL_mutexP(pckpinglog_lock);
|
||||
cvecprintf(pckping_log, "lresolving hostname %s %s (%s)\n", u.domain, s->resolved ? "succeeded" : "failed", iptoa(ENET_NET_TO_HOST_32(h.ip.host)));
|
||||
string b;
|
||||
cvecprintf(pckping_log, "lresolving hostname %s %s (%s)\n", u.domain, s->resolved ? "succeeded" : "failed", iptoa(ENET_NET_TO_HOST_32(h.ip.host), b));
|
||||
SDL_mutexV(pckpinglog_lock);
|
||||
if(s->resolved)
|
||||
{
|
||||
|
||||
+16
-14
@@ -988,19 +988,20 @@ struct serveripcclist : serverconfigfile
|
||||
}
|
||||
ipranges.sort(cmpiprange);
|
||||
int orglength = ipranges.length();
|
||||
string b1, b2;
|
||||
loopv(ipranges)
|
||||
{ // make sure, ranges don't overlap - otherwise bsearch gets unpredictable
|
||||
if(!i) continue;
|
||||
if(ipranges[i].ur <= ipranges[i - 1].ur)
|
||||
{
|
||||
if(cmpcomment(ipranges[i], ipranges[i - 1]))
|
||||
logline(ACLOG_INFO," error: IP list entry %s|%s deleted because of overlapping %s|%s", iprtoa(ipranges[i]), printcomment(ipranges[i]), iprtoa(ipranges[i - 1]), printcomment(ipranges[i - 1]));
|
||||
logline(ACLOG_INFO," error: IP list entry %s|%s deleted because of overlapping %s|%s", iprtoa(ipranges[i], b1), printcomment(ipranges[i]), iprtoa(ipranges[i - 1], b2), printcomment(ipranges[i - 1]));
|
||||
else
|
||||
{
|
||||
if(ipranges[i].lr == ipranges[i - 1].lr && ipranges[i].ur == ipranges[i - 1].ur)
|
||||
logline(ACLOG_VERBOSE," IP list entry %s got dropped (double entry)", iprtoa(ipranges[i]));
|
||||
logline(ACLOG_VERBOSE," IP list entry %s got dropped (double entry)", iprtoa(ipranges[i], b1));
|
||||
else
|
||||
logline(ACLOG_VERBOSE," IP list entry %s got dropped (already covered by %s)", iprtoa(ipranges[i]), iprtoa(ipranges[i - 1]));
|
||||
logline(ACLOG_VERBOSE," IP list entry %s got dropped (already covered by %s)", iprtoa(ipranges[i], b1), iprtoa(ipranges[i - 1], b2));
|
||||
}
|
||||
ipranges.remove(i--); continue;
|
||||
}
|
||||
@@ -1008,26 +1009,26 @@ struct serveripcclist : serverconfigfile
|
||||
{
|
||||
if(!cmpcomment(ipranges[i], ipranges[i - 1])) // same comment
|
||||
{
|
||||
logline(ACLOG_VERBOSE," IP list entries %s and %s are joined due to overlap (both %s)", iprtoa(ipranges[i - 1]), iprtoa(ipranges[i]), printcomment(ipranges[i]));
|
||||
logline(ACLOG_VERBOSE," IP list entries %s and %s are joined due to overlap (both %s)", iprtoa(ipranges[i - 1], b1), iprtoa(ipranges[i], b2), printcomment(ipranges[i]));
|
||||
ipranges[i - 1].ur = ipranges[i].ur;
|
||||
ipranges.remove(i--); continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
logline(ACLOG_INFO," error: IP list entries %s|%s and %s|%s are overlapping - dropping %s|%s", iprtoa(ipranges[i - 1]), printcomment(ipranges[i - 1]),
|
||||
iprtoa(ipranges[i]), printcomment(ipranges[i]), iprtoa(ipranges[i]), printcomment(ipranges[i]));
|
||||
logline(ACLOG_INFO," error: IP list entries %s|%s and %s|%s are overlapping - dropping %s|%s", iprtoa(ipranges[i - 1], b1), printcomment(ipranges[i - 1]),
|
||||
iprtoa(ipranges[i], b2), printcomment(ipranges[i]), b2, printcomment(ipranges[i]));
|
||||
errors++;
|
||||
ipranges.remove(i--); continue;
|
||||
}
|
||||
}
|
||||
if(ipranges[i].lr - 1 == ipranges[i - 1].ur && !cmpcomment(ipranges[i], ipranges[i - 1]))
|
||||
{
|
||||
logline(ACLOG_VERBOSE," concatenating IP list entries %s and %s (both %s)", iprtoa(ipranges[i - 1]), iprtoa(ipranges[i]), printcomment(ipranges[i]));
|
||||
logline(ACLOG_VERBOSE," concatenating IP list entries %s and %s (both %s)", iprtoa(ipranges[i - 1], b1), iprtoa(ipranges[i], b2), printcomment(ipranges[i]));
|
||||
ipranges[i - 1].ur = ipranges[i].ur;
|
||||
ipranges.remove(i--); continue;
|
||||
}
|
||||
}
|
||||
if(logcheck(ACLOG_VERBOSE)) loopv(ipranges) logline(ACLOG_VERBOSE," %s %s", iprtoa(ipranges[i]), printcomment(ipranges[i]));
|
||||
if(logcheck(ACLOG_VERBOSE)) loopv(ipranges) logline(ACLOG_VERBOSE," %s %s", iprtoa(ipranges[i], b1), printcomment(ipranges[i]));
|
||||
logline(ACLOG_INFO,"read %d (%d) IP list entries from '%s', %d errors, %d concatenated", ipranges.length(), orglength, filename, errors, concatd);
|
||||
}
|
||||
|
||||
@@ -1078,25 +1079,26 @@ struct serveripblacklist : serverconfigfile
|
||||
}
|
||||
ipranges.sort(cmpiprange);
|
||||
int orglength = ipranges.length();
|
||||
string b1, b2;
|
||||
loopv(ipranges)
|
||||
{
|
||||
if(!i) continue;
|
||||
if(ipranges[i].ur <= ipranges[i - 1].ur)
|
||||
{
|
||||
if(ipranges[i].lr == ipranges[i - 1].lr && ipranges[i].ur == ipranges[i - 1].ur)
|
||||
logline(ACLOG_VERBOSE," blacklist entry %s got dropped (double entry)", iprtoa(ipranges[i]));
|
||||
logline(ACLOG_VERBOSE," blacklist entry %s got dropped (double entry)", iprtoa(ipranges[i], b1));
|
||||
else
|
||||
logline(ACLOG_VERBOSE," blacklist entry %s got dropped (already covered by %s)", iprtoa(ipranges[i]), iprtoa(ipranges[i - 1]));
|
||||
logline(ACLOG_VERBOSE," blacklist entry %s got dropped (already covered by %s)", iprtoa(ipranges[i], b1), iprtoa(ipranges[i - 1], b2));
|
||||
ipranges.remove(i--); continue;
|
||||
}
|
||||
if(ipranges[i].lr <= ipranges[i - 1].ur)
|
||||
{
|
||||
logline(ACLOG_VERBOSE," blacklist entries %s and %s are joined due to overlap", iprtoa(ipranges[i - 1]), iprtoa(ipranges[i]));
|
||||
logline(ACLOG_VERBOSE," blacklist entries %s and %s are joined due to overlap", iprtoa(ipranges[i - 1], b1), iprtoa(ipranges[i], b2));
|
||||
ipranges[i - 1].ur = ipranges[i].ur;
|
||||
ipranges.remove(i--); continue;
|
||||
}
|
||||
}
|
||||
if(logcheck(ACLOG_VERBOSE)) loopv(ipranges) logline(ACLOG_VERBOSE," %s", iprtoa(ipranges[i]));
|
||||
if(logcheck(ACLOG_VERBOSE)) loopv(ipranges) logline(ACLOG_VERBOSE," %s", iprtoa(ipranges[i], b1));
|
||||
logline(ACLOG_INFO,"read %d (%d) blacklist entries from '%s', %d errors", ipranges.length(), orglength, filename, errors);
|
||||
}
|
||||
|
||||
@@ -1199,7 +1201,7 @@ struct servernickblacklist : serverconfigfile
|
||||
if(logcheck(ACLOG_VERBOSE))
|
||||
{
|
||||
logline(ACLOG_VERBOSE," nickname whitelist (%d entries):", whitelist.numelems);
|
||||
string text;
|
||||
string text, b;
|
||||
enumeratekt(whitelist, const char *, key, int, idx,
|
||||
{
|
||||
text[0] = '\0';
|
||||
@@ -1207,7 +1209,7 @@ struct servernickblacklist : serverconfigfile
|
||||
{
|
||||
iprchain &ic = whitelistranges[i];
|
||||
if(ic.pwd) concatformatstring(text, " pwd:\"%s\"", hiddenpwd(ic.pwd));
|
||||
else concatformatstring(text, " %s", iprtoa(ic.ipr));
|
||||
else concatformatstring(text, " %s", iprtoa(ic.ipr, b));
|
||||
}
|
||||
logline(ACLOG_VERBOSE, " accept %s%s", key, text);
|
||||
});
|
||||
|
||||
+7
-13
@@ -503,23 +503,17 @@ const char *atoipr(const char *s, iprange *ir)
|
||||
return s;
|
||||
}
|
||||
|
||||
const char *iptoa(const enet_uint32 ip)
|
||||
const char *iptoa(const enet_uint32 ip, char *b)
|
||||
{
|
||||
static string s[2];
|
||||
static int buf = 0;
|
||||
buf = (buf + 1) % 2;
|
||||
formatstring(s[buf])("%d.%d.%d.%d", (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255);
|
||||
return s[buf];
|
||||
formatstring(b)("%d.%d.%d.%d", (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255);
|
||||
return b;
|
||||
}
|
||||
|
||||
const char *iprtoa(const struct iprange &ipr)
|
||||
const char *iprtoa(const struct iprange &ipr, char *b)
|
||||
{
|
||||
static string s[2];
|
||||
static int buf = 0;
|
||||
buf = (buf + 1) % 2;
|
||||
if(ipr.lr == ipr.ur) copystring(s[buf], iptoa(ipr.lr));
|
||||
else formatstring(s[buf])("%s-%s", iptoa(ipr.lr), iptoa(ipr.ur));
|
||||
return s[buf];
|
||||
if(ipr.lr == ipr.ur) return iptoa(ipr.lr, b);
|
||||
else formatstring(b)("%d.%d.%d.%d-%d.%d.%d.%d", (ipr.lr >> 24) & 255, (ipr.lr >> 16) & 255, (ipr.lr >> 8) & 255, ipr.lr & 255, (ipr.ur >> 24) & 255, (ipr.ur >> 16) & 255, (ipr.ur >> 8) & 255, ipr.ur & 255);
|
||||
return b;
|
||||
}
|
||||
|
||||
int cmpiprange(const struct iprange *a, const struct iprange *b)
|
||||
|
||||
+2
-2
@@ -959,8 +959,8 @@ struct iprange { enet_uint32 lr, ur; };
|
||||
struct iprangecc : iprange { union { int ci; char cc[4]; enet_uint32 cu; }; };
|
||||
extern const char *atoip(const char *s, enet_uint32 *ip);
|
||||
extern const char *atoipr(const char *s, iprange *ir);
|
||||
extern const char *iptoa(const enet_uint32 ip);
|
||||
extern const char *iprtoa(const struct iprange &ipr);
|
||||
extern const char *iptoa(const enet_uint32 ip, char *b);
|
||||
extern const char *iprtoa(const struct iprange &ipr, char *b);
|
||||
extern int cmpiprange(const struct iprange *a, const struct iprange *b);
|
||||
extern int cmpipmatch(const struct iprange *a, const struct iprange *b);
|
||||
extern int cvecprintf(vector<char> &v, const char *s, ...) PRINTFARGS(2, 3);
|
||||
|
||||
Reference in New Issue
Block a user