From: Michael Poole Date: Sun, 18 Apr 2010 23:21:41 +0000 (-0400) Subject: Fix G-line handling and ?gtrace time display. X-Git-Url: http://git.pk910.de/?p=srvx.git;a=commitdiff_plain;h=f6b39d3f8fa704355045ace0df293bc6f04cb36d Fix G-line handling and ?gtrace time display. src/gline.c (gline_comparator): Use lifetime rather than expiration time to sort G-lines. (gline_add): Only update expiration time and reason if the new modification time is newer than the previous one. Never update issuer (ircu doesn't track it). src/opserv.c (gtrace_print_func): Display G-lines with no expiration time correctly. --- diff --git a/src/gline.c b/src/gline.c index a1cb250..bb169ab 100644 --- a/src/gline.c +++ b/src/gline.c @@ -52,7 +52,7 @@ static int gline_comparator(const void *a, const void *b) { const struct gline *ga=a, *gb=b; - return ga->expires - gb->expires; + return ga->lifetime - gb->lifetime; } static void @@ -127,20 +127,16 @@ gline_add(const char *issuer, const char *target, unsigned long duration, const heap_remove_pred(gline_heap, gline_equal_p, ent); if (ent->issued > lastmod) ent->issued = lastmod; - if (ent->lastmod < lastmod) + if (ent->lastmod < lastmod) { ent->lastmod = lastmod; - if (ent->expires != expires) - ent->expires = expires; + ent->expires = expires; + if (strcmp(ent->reason, reason)) { + free(ent->reason); + ent->reason = strdup(reason); + } + } if (ent->lifetime < lifetime) ent->lifetime = lifetime; - if (strcmp(ent->issuer, issuer)) { - free(ent->issuer); - ent->issuer = strdup(issuer); - } - if (strcmp(ent->reason, reason)) { - free(ent->reason); - ent->reason = strdup(reason); - } } else { ent = malloc(sizeof(*ent)); ent->issued = issued; diff --git a/src/opserv.c b/src/opserv.c index abdbee9..38ad356 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -3811,15 +3811,14 @@ gtrace_print_func(struct gline *gline, void *extra) else strcpy(lastmod, ""); intervalString(lifetime, gline->lifetime - now, xtra->user->handle_info); - if (gline->expires < now) { + if (!gline->expires) { + send_message(xtra->user, opserv, "OSMSG_GTRACE_FOREVER", gline->target, issued, gline->issuer, lastmod, NULL, gline->reason, lifetime); + } else 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) { + } else { /* must be in the future */ 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); - } }