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