]>
Commit | Line | Data |
---|---|---|
1 | #include <stdlib.h> | |
2 | #include <assert.h> | |
3 | #include "../core/nsmalloc.h" | |
4 | #include <stdio.h> | |
5 | #include <string.h> | |
6 | ||
7 | #include "gline.h" | |
8 | ||
9 | #define ALLOCUNIT 100 | |
10 | ||
11 | gline *gline_freelist; | |
12 | ||
13 | gline *newgline() { | |
14 | gline *gl; | |
15 | int i; | |
16 | ||
17 | if( gline_freelist ==NULL ) { | |
18 | gline_freelist=(gline *)nsmalloc(POOL_GLINE,ALLOCUNIT*sizeof(gline)); | |
19 | ||
20 | for (i=0;i<(ALLOCUNIT-1);i++) { | |
21 | gline_freelist[i].next=(gline *)&(gline_freelist[i+1]); | |
22 | } | |
23 | gline_freelist[ALLOCUNIT-1].next=NULL; | |
24 | } | |
25 | ||
26 | gl=gline_freelist; | |
27 | gline_freelist=(gline *)gl->next; | |
28 | ||
29 | gl->next=NULL; | |
30 | gl->nextbynode=NULL; | |
31 | gl->nextbynonnode=NULL; | |
32 | ||
33 | gl->glineid=0; | |
34 | gl->numeric=0; | |
35 | ||
36 | gl->nick=NULL; | |
37 | gl->user=NULL; | |
38 | gl->host=NULL; | |
39 | gl->reason=NULL; | |
40 | gl->creator=NULL; | |
41 | ||
42 | gl->node=NULL; | |
43 | ||
44 | gl->expires=0; | |
45 | gl->lastmod=0; | |
46 | gl->lifetime=0; | |
47 | ||
48 | gl->flags=0; | |
49 | ||
50 | return gl; | |
51 | } | |
52 | ||
53 | void removeglinefromlists( gline *gl) { | |
54 | gline *gl2; | |
55 | ||
56 | if (gl->flags & GLINE_IPMASK) { | |
57 | if ( gl == gl->node->exts[gl_nodeext]) { | |
58 | gl->node->exts[gl_nodeext] = gl->nextbynode; | |
59 | } else { | |
60 | gl2 = gl->node->exts[gl_nodeext]; | |
61 | while (gl2) { | |
62 | if ( gl2->nextbynode == gl) { | |
63 | gl2->nextbynode = gl->nextbynode; | |
64 | break; | |
65 | } | |
66 | gl2 = gl2->nextbynode; | |
67 | } | |
68 | } | |
69 | } else { | |
70 | if ( gl == glinelistnonnode) { | |
71 | glinelistnonnode = gl->nextbynonnode; | |
72 | } else { | |
73 | gl2 = glinelistnonnode; | |
74 | while (gl2) { | |
75 | if ( gl2->nextbynonnode == gl) { | |
76 | gl2->nextbynonnode = gl->nextbynonnode; | |
77 | break; | |
78 | } | |
79 | gl2 = gl2->nextbynonnode; | |
80 | } | |
81 | } | |
82 | } | |
83 | ||
84 | if ( gl == glinelist) { | |
85 | glinelist = gl->next; | |
86 | } else { | |
87 | gl2 = glinelist; | |
88 | while (gl2) { | |
89 | if ( gl2->next == gl) { | |
90 | gl2->next = gl->next; | |
91 | break; | |
92 | } | |
93 | gl2 = gl2->next; | |
94 | } | |
95 | } | |
96 | } | |
97 | ||
98 | void freegline (gline *gl) { | |
99 | gl->next=(gline *)gline_freelist; | |
100 | ||
101 | if (gl->nick) | |
102 | freesstring(gl->nick); | |
103 | if (gl->user) | |
104 | freesstring(gl->user); | |
105 | if (gl->host) | |
106 | freesstring(gl->host); | |
107 | if (gl->reason) | |
108 | freesstring(gl->reason); | |
109 | if (gl->creator) | |
110 | freesstring(gl->creator); | |
111 | ||
112 | if (gl->node) { | |
113 | derefnode(iptree, gl->node); | |
114 | } | |
115 | gline_freelist=gl; | |
116 | } | |
117 | ||
118 | void removegline( gline *gl) { | |
119 | removeglinefromlists(gl); | |
120 | freegline(gl); | |
121 | } | |
122 | ||
123 |