]> jfr.im git - irc/quakenet/newserv.git/blame - helpmod2/hticket.c
Added files that weren't in the initial import.
[irc/quakenet/newserv.git] / helpmod2 / hticket.c
CommitLineData
c86edd1d
Q
1#include <time.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "hchannel.h"
6#include "hticket.h"
7#include "hgen.h"
8
9hticket *hticket_get(char *authname, struct hchannel_struct *hchan)
10{
11 hticket *tmp;
12 if (hchan == NULL)
13 return NULL;
14 for (tmp = hchan->htickets;tmp;tmp = tmp->next)
15 if (!ci_strcmp(authname, tmp->authname))
16 return tmp;
17 return NULL;
18}
19
20hticket *hticket_del(hticket *htick, struct hchannel_struct *hchan)
21{
22 hticket **ptr;
23 for (ptr = &hchan->htickets;*ptr;ptr = &(*ptr)->next)
24 if (*ptr == htick)
25 {
26 *ptr = htick->next;
27 free(htick);
28 return NULL;
29 }
30
31 return htick;
32}
33
34hticket *hticket_add(char *authname, time_t expiration, struct hchannel_struct *hchan)
35{
36 hticket *tmp = hticket_get(authname, hchan);
37
38 if (hchan == NULL)
39 return NULL;
40
41 if (tmp != NULL)
42 return tmp;
43
44 tmp = (hticket*)malloc(sizeof(struct hticket_struct));
45
46 strcpy(tmp->authname, authname);
47 tmp->time_expiration = expiration;
48 tmp->next = hchan->htickets;
49
50 hchan->htickets = tmp;
51
52 return tmp;
53}
54
55int hticket_count(void)
56{
57 int count = 0;
58 hticket *htick;
59 hchannel *hchan;
60
61 for (hchan = hchannels;hchan;hchan = hchan->next)
62 for (htick = hchan->htickets;htick;htick = htick->next)
63 count++;
64
65 return count;
66}
67
68void hticket_remove_expired(void)
69{
70 hchannel *hchan;
71 hticket *htick, *next;
72 for (hchan = hchannels;hchan;hchan = hchan->next)
73 for (htick = hchan->htickets; htick; htick = next)
74 {
75 next = htick->next;
76 if (htick->time_expiration < time(NULL))
77 hticket_del(htick, hchan);
78 }
79}
80