From: Michael Poole Date: Thu, 18 Mar 2010 02:53:30 +0000 (-0400) Subject: Simplify G-line code somewhat. Generate better output for ?gtrace print. X-Git-Url: http://git.pk910.de/?p=srvx.git;a=commitdiff_plain;h=2e67ca10af3665e1027a236fd0f7055a1b63c5ff Simplify G-line code somewhat. Generate better output for ?gtrace print. A hub with a negative clock skew will cause adverse results (like the issued or lastmod times being in the network's future). That will be fixed in ircu. src/gline.c (gline_for_p): Rewrite to just compare the G-line pointer. (gline_add): Use that instead. Move "issued" back in time if the lastmod time is earlier than we know the G-line was issued. src/opserv.c (OSMSG_GTRACE_FOREVER): New format string. (OSMSG_GTRACE_EXPIRED): Likewise. (gtrace_print_func): Use the appropriate OSMSG_GTRACE_* string. --- diff --git a/src/gline.c b/src/gline.c index 0b2ed9b..a1cb250 100644 --- a/src/gline.c +++ b/src/gline.c @@ -72,10 +72,9 @@ free_gline(struct gline *ent) } static int -gline_for_p(UNUSED_ARG(void *key), void *data, void *extra) +gline_equal_p(UNUSED_ARG(void *key), void *data, void *extra) { - struct gline *ge = data; - return !irccasecmp(ge->target, extra); + return data == extra; } static void @@ -125,13 +124,15 @@ gline_add(const char *issuer, const char *target, unsigned long duration, const lifetime = expires; ent = dict_find(gline_dict, target, NULL); if (ent) { - heap_remove_pred(gline_heap, gline_for_p, (char*)target); + heap_remove_pred(gline_heap, gline_equal_p, ent); + if (ent->issued > lastmod) + ent->issued = lastmod; + if (ent->lastmod < lastmod) + ent->lastmod = lastmod; if (ent->expires != expires) ent->expires = expires; if (ent->lifetime < lifetime) ent->lifetime = lifetime; - if (ent->lastmod < lastmod) - ent->lastmod = lastmod; if (strcmp(ent->issuer, issuer)) { free(ent->issuer); ent->issuer = strdup(issuer); diff --git a/src/opserv.c b/src/opserv.c index 4bc6be2..ec4b57f 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -202,6 +202,8 @@ static const struct message_entry msgtab[] = { { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" }, { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." }, { "OSMSG_GTRACE_FORMAT", "%1$s (issued %2$s ago by %3$s, lastmod %4$s ago, expires %5$s, lifetime %7$s): %6$s" }, + { "OSMSG_GTRACE_FOREVER", "%1$s (issued %2$s ago by %3$s, lastmod %4$s ago, never expires, lifetime %7$s): %6$s" }, + { "OSMSG_GTRACE_EXPIRED", "%1$s (issued %2$s ago by %3$s, lastmod %4$s ago, expired %5$s ago, lifetime %7$s): %6$s" }, { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." }, { "OSMSG_GAG_ADDED", "Gagged $b%s$b." }, { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." }, @@ -3808,12 +3810,17 @@ gtrace_print_func(struct gline *gline, void *extra) intervalString(lastmod, now - gline->lastmod, xtra->user->handle_info); else strcpy(lastmod, ""); - if (gline->expires) - intervalString(expires, gline->expires - now, xtra->user->handle_info); - else - strcpy(expires, "never"); intervalString(lifetime, gline->lifetime - now, xtra->user->handle_info); - send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, lastmod, expires, gline->reason, lifetime); + if (gline->expires < now) { + intervalString(expires, now - gline->expires, xtra->user->handle_info); + send_message(xtra->user, opserv, "OSMSG_GTRACE_EXPIRED", gline->target, issued, gline->issuer, lastmod, expires, gline->reason, lifetime); + } else if (gline->expires) { + intervalString(expires, gline->expires - now, xtra->user->handle_info); + send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, lastmod, expires, gline->reason, lifetime); + } else { + send_message(xtra->user, opserv, "OSMSG_GTRACE_FOREVER", gline->target, issued, gline->issuer, lastmod, NULL, gline->reason, lifetime); + + } } static MODCMD_FUNC(cmd_stats_glines) {