]> jfr.im git - irc/quakenet/newserv.git/blame - trusts2/trusts_blocks.c
Merge.
[irc/quakenet/newserv.git] / trusts2 / trusts_blocks.c
CommitLineData
ef9fab2e
P
1#include "trusts.h"
2
3static trustblock_t *trustblocklist = NULL;
4
5trustblock_t *createtrustblock(unsigned long id, patricia_node_t* node, unsigned long ownerid, time_t expire, char *reason_private, char *reason_public) {
6 trustblock_t *tb = newtrustblock();
7 memset(tb, 0, sizeof(trustblock_t));
8
9 tb->startdate = getnettime();
10
11 tb->id = id;
12 tb->node = node;
13 tb->ownerid = ownerid;
14 tb->expire = expire;
15 tb->reason_private = getsstring(reason_private,512);
16 tb->reason_public = getsstring(reason_public,512);
17
18 tb->next=trustblocklist;
19 trustblocklist = tb;
20 return tb;
21}
22
23trustblock_t *createtrustblockfromdb(unsigned long id, patricia_node_t* node, unsigned long ownerid, time_t expire, time_t startdate, char *reason_private, char *reason_public) {
24 trustblock_t *tb = createtrustblock(id,node,ownerid, expire, reason_private, reason_public);
25
26 tb->startdate = startdate;
27 return tb;
28}
29
30void trustblock_free(trustblock_t* t)
31{
32 trustblock_t *st, *pst=NULL;
33 for (st = trustblocklist; st; st=st->next) {
34 if (st == t ) {
35 break;
36 }
37 pst = st;
38 }
39
40 if (st) {
41 if (pst) {
42 pst->next = st->next;
43 }
4f2ce270 44
ef9fab2e
P
45 derefnode(iptree,st->node);
46 if (st->reason_public ) {
47 freesstring(st->reason_public);
48 }
49 if (st->reason_private) {
50 freesstring(st->reason_private);
51 }
52 freetrustblock(st);
53 }
54}
55
56void trustblock_expire( trustblock_t *tb) {
57 controlwall(NO_OPER, NL_TRUSTS, "trustblock on %s/%d expired",IPtostr(tb->node->prefix->sin),irc_bitlen(&(tb->node->prefix->sin),tb->node->prefix->bitlen));
58 trustsdb_deletetrustblock(tb->node->exts[tgb_ext]);
59 trustblock_free(tb->node->exts[tgb_ext]);
60 tb->node->exts[tgb_ext] = NULL;
61}
62
63void trustblock_freeall() {
64 trustblock_t *tb, *ptb=NULL;
65 tb=trustblocklist;
66 while(tb) {
67 ptb=tb;
68 tb=tb->next;
4f2ce270 69
ef9fab2e
P
70 derefnode(iptree,ptb->node);
71 if (ptb->reason_public ) {
72 freesstring(ptb->reason_public);
73 }
74 if (ptb->reason_private) {
75 freesstring(ptb->reason_private);
76 }
4f2ce270 77 ptb->node->exts[tgb_ext] = NULL;
ef9fab2e
P
78 }
79}