]> jfr.im git - irc/quakenet/newserv.git/blobdiff - helpmod2/hticket.c
DBAPI2: fix initialisation bug (thanks to anders for crash logs)
[irc/quakenet/newserv.git] / helpmod2 / hticket.c
index 0ef54bf7aca0d57e7180f7126fce1f1d45d9e8ea..1425995903eecdc22a1e4c3880d35e6a6f7c93c9 100644 (file)
@@ -6,7 +6,7 @@
 #include "hticket.h"
 #include "hgen.h"
 
-hticket *hticket_get(char *authname, struct hchannel_struct *hchan)
+hticket *hticket_get(const char *authname, struct hchannel_struct *hchan)
 {
     hticket *tmp;
     if (hchan == NULL)
@@ -23,17 +23,20 @@ hticket *hticket_del(hticket *htick, struct hchannel_struct *hchan)
     for (ptr = &hchan->htickets;*ptr;ptr = &(*ptr)->next)
         if (*ptr == htick)
         {
-            *ptr = htick->next;
-            free(htick);
+           hticket *tmp = (*ptr)->next;
+           if ((*ptr)->message)
+                freesstring((*ptr)->message);
+            free(*ptr);
+            *ptr = tmp;
             return NULL;
         }
 
     return htick;
 }
 
-hticket *hticket_add(char *authname, time_t expiration, struct hchannel_struct *hchan)
+hticket *hticket_add(const char *authname, time_t expiration, struct hchannel_struct *hchan, const char *message)
 {
-    hticket *tmp = hticket_get(authname, hchan);
+    hticket *tmp = hticket_get(authname, hchan), **ptr;
 
     if (hchan == NULL)
         return NULL;
@@ -45,9 +48,17 @@ hticket *hticket_add(char *authname, time_t expiration, struct hchannel_struct *
 
     strcpy(tmp->authname, authname);
     tmp->time_expiration = expiration;
-    tmp->next = hchan->htickets;
 
-    hchan->htickets = tmp;
+    if (message == NULL)
+       tmp->message = NULL;
+    else
+        tmp->message = getsstring(message, strlen(message));
+
+    /* find the correct position */
+    for (ptr = &hchan->htickets;*ptr && (*ptr)->time_expiration >= expiration;ptr = &(*ptr)->next);
+
+    tmp->next = *ptr;
+    *ptr = tmp;
 
     return tmp;
 }
@@ -68,13 +79,14 @@ int hticket_count(void)
 void hticket_remove_expired(void)
 {
     hchannel *hchan;
-    hticket *htick, *next;
+    hticket **tmp;
     for (hchan = hchannels;hchan;hchan = hchan->next)
-        for (htick = hchan->htickets; htick; htick = next)
-        {
-            next = htick->next;
-            if (htick->time_expiration < time(NULL))
-                hticket_del(htick, hchan);
-        }
+    {
+        tmp = &hchan->htickets;
+        while (*tmp)
+            if ((*tmp)->time_expiration < time(NULL))
+                hticket_del(*tmp, hchan);
+            else
+                tmp = &(*tmp)->next;
+    }
 }
-