ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/list.C
Revision: 1.6
Committed: Wed Sep 5 11:23:13 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +6 -6 lines
Log Message:
removed GPLed code and put license back to BSD

File Contents

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