#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)
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;
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;
}
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;
+ }
}
-