#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)
{
- hticket *tmp = (*ptr)->next;
+ 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;
}