1 |
pippijn |
1.1 |
/* |
2 |
|
|
* svsignore.C: Services ignore list management. |
3 |
pippijn |
1.5 |
* |
4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
|
|
* Rights to this code are as documented in COPYING. |
6 |
|
|
* |
7 |
|
|
* |
8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
9 |
pippijn |
1.2 |
* Rights to this code are documented in doc/pod/license.pod. |
10 |
pippijn |
1.4 |
* Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
11 |
pippijn |
1.1 |
*/ |
12 |
|
|
|
13 |
pippijn |
1.6 |
static char const rcsid[] = "$Id: svsignore.C,v 1.5 2007-09-16 18:54:45 pippijn Exp $"; |
14 |
pippijn |
1.1 |
|
15 |
|
|
#include "atheme.h" |
16 |
pippijn |
1.6 |
#include <libermyth.h> |
17 |
pippijn |
1.1 |
#include <account/svsignore.h> |
18 |
|
|
|
19 |
|
|
svsignore_vector svs_ignore_list; |
20 |
|
|
|
21 |
|
|
/* |
22 |
|
|
* svsignore_add(char *mask, char *reason) |
23 |
|
|
* |
24 |
|
|
* Services ignore factory. |
25 |
|
|
* |
26 |
|
|
* Inputs: |
27 |
|
|
* - mask to ignore |
28 |
|
|
* - reason for ignore |
29 |
|
|
* |
30 |
|
|
* Outputs: |
31 |
|
|
* - on success, a new svsignore object |
32 |
|
|
* |
33 |
|
|
* Side Effects: |
34 |
|
|
* - a services ignore is added |
35 |
|
|
* |
36 |
|
|
* Bugs: |
37 |
|
|
* - this function does not check for dupes |
38 |
|
|
*/ |
39 |
|
|
svsignore_t * |
40 |
|
|
svsignore_add (char *mask, char *reason) |
41 |
|
|
{ |
42 |
|
|
svsignore_t *svsignore; |
43 |
|
|
|
44 |
pippijn |
1.4 |
svsignore = new svsignore_t; |
45 |
pippijn |
1.1 |
|
46 |
|
|
svs_ignore_list.push_back (svsignore); |
47 |
|
|
|
48 |
|
|
svsignore->mask = sstrdup (mask); |
49 |
|
|
svsignore->settime = NOW; |
50 |
|
|
svsignore->reason = sstrdup (reason); |
51 |
|
|
cnt.svsignore++; |
52 |
|
|
|
53 |
|
|
return svsignore; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
/* |
57 |
|
|
* svsignore_find(user_t *source) |
58 |
|
|
* |
59 |
|
|
* Finds any services ignores that affect a user. |
60 |
|
|
* |
61 |
|
|
* Inputs: |
62 |
|
|
* - user object to check |
63 |
|
|
* |
64 |
|
|
* Outputs: |
65 |
|
|
* - if any ignores match, the ignore that matches |
66 |
|
|
* - if none match, NULL |
67 |
|
|
* |
68 |
|
|
* Side Effects: |
69 |
|
|
* - none |
70 |
|
|
*/ |
71 |
|
|
svsignore_t * |
72 |
|
|
svsignore_find (user_t *source) |
73 |
|
|
{ |
74 |
|
|
svsignore_t *svsignore; |
75 |
pippijn |
1.4 |
svsignore_vector::iterator it = svs_ignore_list.begin (); |
76 |
|
|
svsignore_vector::iterator et = svs_ignore_list.end (); |
77 |
pippijn |
1.1 |
char host[BUFSIZE]; |
78 |
|
|
|
79 |
|
|
if (!use_svsignore) |
80 |
|
|
return NULL; |
81 |
|
|
|
82 |
|
|
*host = '\0'; |
83 |
|
|
strlcpy (host, source->nick, BUFSIZE); |
84 |
|
|
strlcat (host, "!", BUFSIZE); |
85 |
|
|
strlcat (host, source->user, BUFSIZE); |
86 |
|
|
strlcat (host, "@", BUFSIZE); |
87 |
|
|
strlcat (host, source->host, BUFSIZE); |
88 |
|
|
|
89 |
pippijn |
1.4 |
while (it != et) |
90 |
pippijn |
1.1 |
{ |
91 |
|
|
svsignore = *it; |
92 |
|
|
|
93 |
|
|
if (!match (svsignore->mask, host)) |
94 |
|
|
return svsignore; |
95 |
pippijn |
1.4 |
|
96 |
|
|
++it; |
97 |
pippijn |
1.1 |
} |
98 |
|
|
|
99 |
|
|
return NULL; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
/* |
103 |
|
|
* svsignore_delete(svsignore_t *svsignore) |
104 |
|
|
* |
105 |
|
|
* Destroys a services ignore. |
106 |
|
|
* |
107 |
|
|
* Inputs: |
108 |
|
|
* - svsignore to destroy |
109 |
|
|
* |
110 |
|
|
* Outputs: |
111 |
|
|
* - nothing |
112 |
|
|
* |
113 |
|
|
* Side Effects: |
114 |
|
|
* - a services ignore is destroyed and removed from the list |
115 |
|
|
*/ |
116 |
|
|
void |
117 |
|
|
svsignore_delete (svsignore_t *svsignore) |
118 |
|
|
{ |
119 |
|
|
svs_ignore_list.erase (svsignore); |
120 |
|
|
|
121 |
pippijn |
1.4 |
sfree (svsignore->mask); |
122 |
|
|
sfree (svsignore->reason); |
123 |
|
|
delete svsignore; |
124 |
pippijn |
1.1 |
} |