Debian Codegraph @

modules/statserv/channel.c

raw
1 /*
2 * Copyright (c) 2011 Alexandria Wolcott
3 * Released under the same terms as Atheme itself.
4 *
5 * Channel information gatherer for statistics (Useful mostly for XMLRPC)
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1("statserv/channel", false, _modinit, _moddeinit,
12 PACKAGE_STRING, "Alexandria Wolcott <[email protected]>");
13
14 static void ss_cmd_channel(sourceinfo_t * si, int parc, char *parv[]);
15 static void ss_cmd_channel_topic(sourceinfo_t * si, int parc, char *parv[]);
16 static void ss_cmd_channel_count(sourceinfo_t * si, int parc, char *parv[]);
17
18 command_t ss_channel =
19 { "CHANNEL", N_("Obtain various information about a channel."), AC_NONE, 2, ss_cmd_channel, {.path = "statserv/channel"} };
20
21 command_t ss_channel_topic =
22 { "TOPIC", N_("Obtain the topic for a given channel."), AC_NONE, 1, ss_cmd_channel_topic, {.path = ""} };
23
24 command_t ss_channel_count =
25 { "COUNT", N_("Count the number of channels on the network."), AC_NONE, 1, ss_cmd_channel_count, {.path = ""}};
26
27 mowgli_patricia_t *ss_channel_cmds;
28
29 void _modinit(module_t * m)
30 {
31 service_named_bind_command("statserv", &ss_channel);
32
33 ss_channel_cmds = mowgli_patricia_create(strcasecanon);
34
35 command_add(&ss_channel_topic, ss_channel_cmds);
36 command_add(&ss_channel_count, ss_channel_cmds);
37 }
38
39 void _moddeinit(module_unload_intent_t intent)
40 {
41 service_named_unbind_command("statserv", &ss_channel);
42
43 command_delete(&ss_channel_topic, ss_channel_cmds);
44 command_delete(&ss_channel_count, ss_channel_cmds);
45
46 mowgli_patricia_destroy(ss_channel_cmds, NULL, NULL);
47 }
48
49 static void ss_cmd_channel(sourceinfo_t * si, int parc, char *parv[])
50 {
51 command_t *c;
52 char *cmd = parv[0];
53
54 if (!cmd)
55 {
56 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "CHANNEL");
57 command_fail(si, fault_needmoreparams,
58 _("Syntax: CHANNEL [TOPIC|COUNT] [parameters]"));
59 return;
60 }
61
62 c = command_find(ss_channel_cmds, cmd);
63 if (c == NULL)
64 {
65 command_fail(si, fault_badparams,
66 _("Invalid command. Use \2/%s%s help\2 for a command listing."),
67 (ircd->uses_rcommand == false) ? "msg " : "", si->service->disp);
68 return;
69 }
70
71 command_exec(si->service, si, c, parc - 1, parv + 1);
72 }
73
74 static void ss_cmd_channel_topic(sourceinfo_t * si, int parc, char *parv[])
75 {
76 char *chan = parv[0];
77 channel_t *c;
78
79 if (!chan)
80 {
81 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "CHANNEL TOPIC");
82 command_fail(si, fault_needmoreparams, _("Syntax: CHANNEL TOPIC <#channel>"));
83 return;
84 }
85
86 if (!(c = channel_find(chan)))
87 {
88 command_fail(si, fault_nosuch_target, _("The channel \2%s\2 does not exist."),
89 chan);
90 return;
91 }
92
93 if (c->modes & CMODE_SEC)
94 {
95 command_fail(si, fault_noprivs,
96 _("You are not authorised to perform this action."));
97 return;
98 }
99
100 if (c->topic)
101 command_success_nodata(si, _("Topic for %s set by %s: %s"), c->name,
102 c->topic_setter, c->topic);
103 else
104 command_success_nodata(si, _("No topic set for %s"), c->name);
105 }
106
107 static void ss_cmd_channel_count(sourceinfo_t * si, int parc, char *parv[])
108 {
109 command_success_nodata(si, "There are %u channels on the network.", mowgli_patricia_size(chanlist));
110 }