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