ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/list.C
Revision: 1.8
Committed: Sat Sep 22 14:27:28 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * list.C: This file contains code for the NickServ LIST function.
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 * Copyright © 2005-2007 Robin Burchell, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: list.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include <boost/foreach.hpp>
16
17 #include "atheme.h"
18 #include <ermyth/module.h>
19 #include <account/mynick.h>
20 #include <account/myuser.h>
21
22 static char const rcsid[] = "$Id: list.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
23
24 REGISTER_MODULE ("nickserv/list", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25
26 static void ns_cmd_list (sourceinfo_t *si, int parc, char *parv[]);
27
28 command_t const ns_list = { "LIST", N_("Lists nicknames registered matching a given pattern."), PRIV_USER_AUSPEX, 1, ns_cmd_list };
29
30 E cmdvec ns_cmdtree;
31 E helpvec ns_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 ns_cmdtree << ns_list;
37 help_addentry (ns_helptree, "LIST", "help/nickserv/list", NULL);
38
39 return true;
40 }
41
42 void
43 _moddeinit ()
44 {
45 ns_cmdtree >> ns_list;
46 help_delentry (ns_helptree, "LIST");
47 }
48
49 static void
50 list_one (sourceinfo_t *si, myuser_t *mu, mynick_t *mn)
51 {
52 char buf[BUFSIZE];
53
54 if (mn != NULL)
55 mu = mn->owner;
56
57 *buf = '\0';
58 if (mu->find_metadata ("private:freeze:freezer"))
59 {
60 if (*buf)
61 strlcat (buf, " ", BUFSIZE);
62
63 strlcat (buf, "\2[frozen]\2", BUFSIZE);
64 }
65 if (mu->find_metadata ("private:mark:setter"))
66 {
67 if (*buf)
68 strlcat (buf, " ", BUFSIZE);
69
70 strlcat (buf, "\2[marked]\2", BUFSIZE);
71 }
72 if (mu->flags & MU_HOLD)
73 {
74 if (*buf)
75 strlcat (buf, " ", BUFSIZE);
76
77 strlcat (buf, "\2[held]\2", BUFSIZE);
78 }
79 if (mu->flags & MU_WAITAUTH)
80 {
81 if (*buf)
82 strlcat (buf, " ", BUFSIZE);
83
84 strlcat (buf, "\2[unverified]\2", BUFSIZE);
85 }
86
87 if (mn == NULL || !irccasecmp (mn->nick, mu->name))
88 command_success_nodata (si, "- %s (%s) %s", mu->name, mu->email, buf);
89 else
90 command_success_nodata (si, "- %s (%s) (%s) %s", mn->nick, mu->email, mu->name, buf);
91 }
92
93 static void
94 ns_cmd_list (sourceinfo_t *si, int parc, char *parv[])
95 {
96 char pat[512], *nickpattern = NULL, *hostpattern = NULL, *p;
97 bool hostmatch;
98 myuser_t *mu;
99 mynick_t *mn;
100 metadata *md;
101 int matches = 0;
102
103 if (parc < 1)
104 {
105 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "LIST");
106 command_fail (si, fault::needmoreparams, _("Syntax: LIST <pattern>[!<user@host>]"));
107 return;
108 }
109 strlcpy (pat, parv[0], sizeof pat);
110 p = strrchr (pat, ' ');
111 if (p == NULL)
112 p = strrchr (pat, '!');
113 if (p != NULL)
114 {
115 *p++ = '\0';
116 nickpattern = pat;
117 hostpattern = p;
118 }
119 else if (strchr (pat, '@'))
120 hostpattern = pat;
121 else
122 nickpattern = pat;
123 if (nickpattern && !strcmp (nickpattern, "*"))
124 nickpattern = NULL;
125
126 if (nicksvs.no_nick_ownership)
127 {
128 myuser_t::map_type::iterator it = myuser_t::map.begin ();
129 myuser_t::map_type::iterator et = myuser_t::map.end ();
130
131 snoop ("LIST:ACCOUNTS: \2%s\2 by \2%s\2", parv[0], get_oper_name (si));
132 while (it != et)
133 {
134 mu = it->second;
135 if (nickpattern && match (nickpattern, mu->name))
136 continue;
137 if (hostpattern)
138 {
139 hostmatch = false;
140 md = mu->find_metadata ("private:host:actual");
141 if (md != NULL && !match (hostpattern, md->value))
142 hostmatch = true;
143 md = mu->find_metadata ("private:host:vhost");
144 if (md != NULL && !match (hostpattern, md->value))
145 hostmatch = true;
146 if (!hostmatch)
147 continue;
148 }
149 list_one (si, mu, NULL);
150 matches++;
151
152 ++it;
153 }
154 }
155 else
156 {
157 snoop ("LIST:NICKS: \2%s\2 by \2%s\2", parv[0], get_oper_name (si));
158 foreach (mynick_t::pair_type &mnp, mynick_t::map)
159 {
160 mn = mnp.second;
161 if (nickpattern && match (nickpattern, mn->nick))
162 continue;
163 mu = mn->owner;
164 if (hostpattern)
165 {
166 hostmatch = false;
167 md = mu->find_metadata ("private:host:actual");
168 if (md != NULL && !match (hostpattern, md->value))
169 hostmatch = true;
170 md = mu->find_metadata ("private:host:vhost");
171 if (md != NULL && !match (hostpattern, md->value))
172 hostmatch = true;
173 if (!hostmatch)
174 continue;
175 }
176 list_one (si, NULL, mn);
177 matches++;
178 }
179 }
180
181 logcommand (si, CMDLOG_ADMIN, "LIST %s (%d matches)", parv[0], matches);
182 if (matches == 0)
183 command_success_nodata (si, _("No nicknames matched pattern \2%s\2"), parv[0]);
184 else
185 command_success_nodata (si, ngettext (N_("\2%d\2 match for pattern \2%s\2"), N_("\2%d\2 matches for pattern \2%s\2"), matches), matches, parv[0]);
186 }