]> jfr.im git - irc/quakenet/newserv.git/blame - helpmod2/hticket.c
Reorganise the JIT bit
[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
3a839281 9hticket *hticket_get(const char *authname, struct hchannel_struct *hchan)
c86edd1d
Q
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 {
b808acb7 26 hticket *tmp = (*ptr)->next;
27 free(*ptr);
28 *ptr = tmp;
c86edd1d
Q
29 return NULL;
30 }
31
32 return htick;
33}
34
3a839281 35hticket *hticket_add(const char *authname, time_t expiration, struct hchannel_struct *hchan)
c86edd1d 36{
9af95c3d 37 hticket *tmp = hticket_get(authname, hchan), **ptr;
c86edd1d
Q
38
39 if (hchan == NULL)
40 return NULL;
41
42 if (tmp != NULL)
43 return tmp;
44
45 tmp = (hticket*)malloc(sizeof(struct hticket_struct));
46
47 strcpy(tmp->authname, authname);
48 tmp->time_expiration = expiration;
c86edd1d 49
9af95c3d 50 /* find the correct position */
51 for (ptr = &hchan->htickets;*ptr && (*ptr)->time_expiration >= expiration;ptr = &(*ptr)->next);
52
53 tmp->next = *ptr;
54 *ptr = tmp;
c86edd1d
Q
55
56 return tmp;
57}
58
59int hticket_count(void)
60{
61 int count = 0;
62 hticket *htick;
63 hchannel *hchan;
64
65 for (hchan = hchannels;hchan;hchan = hchan->next)
66 for (htick = hchan->htickets;htick;htick = htick->next)
67 count++;
68
69 return count;
70}
71
72void hticket_remove_expired(void)
73{
74 hchannel *hchan;
b808acb7 75 hticket **tmp;
c86edd1d 76 for (hchan = hchannels;hchan;hchan = hchan->next)
b808acb7 77 {
78 tmp = &hchan->htickets;
79 while (*tmp)
80 if ((*tmp)->time_expiration < time(NULL))
81 hticket_del(*tmp, hchan);
82 else
83 tmp = &(*tmp)->next;
84 }
c86edd1d 85}