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