Fix G-line handling and ?gtrace time display.
authorMichael Poole <mdpoole@troilus.org>
Sun, 18 Apr 2010 23:21:41 +0000 (19:21 -0400)
committerMichael Poole <mdpoole@troilus.org>
Sun, 18 Apr 2010 23:21:41 +0000 (19:21 -0400)
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.

src/gline.c
src/opserv.c

index a1cb2504ea81e790e2e5c509dc54ab38d349207c..bb169ab1cadca42875d0f6c5ddf54186c0832cb0 100644 (file)
@@ -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;
index abdbee95e234ac072f1d23d7bc32e046e13d930d..38ad356ee2d84bbc14fbe97b3156460d054ed2da 100644 (file)
@@ -3811,15 +3811,14 @@ gtrace_print_func(struct gline *gline, void *extra)
     else
         strcpy(lastmod, "<unknown>");
     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);
-
     }
 }