Debian Codegraph @

modules/chanserv/set_url.c

raw
1 /*
2 * Copyright (c) 2003-2004 E. Will et al.
3 * Copyright (c) 2006-2010 Atheme Development Group
4 * Rights to this code are documented in doc/LICENSE.
5 *
6 * This file contains routines to handle the CService SET URL command.
7 *
8 */
9
10 #include "atheme.h"
11
12 DECLARE_MODULE_V1
13 (
14 "chanserv/set_url", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void cs_cmd_set_url(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t cs_set_url = { "URL", N_("Sets the channel URL."), AC_NONE, 2, cs_cmd_set_url, { .path = "cservice/set_url" } };
22
23 mowgli_patricia_t **cs_set_cmdtree;
24
25 void _modinit(module_t *m)
26 {
27 MODULE_TRY_REQUEST_SYMBOL(m, cs_set_cmdtree, "chanserv/set_core", "cs_set_cmdtree");
28
29 command_add(&cs_set_url, *cs_set_cmdtree);
30 }
31
32 void _moddeinit(module_unload_intent_t intent)
33 {
34 command_delete(&cs_set_url, *cs_set_cmdtree);
35 }
36
37 static void cs_cmd_set_url(sourceinfo_t *si, int parc, char *parv[])
38 {
39 mychan_t *mc;
40 char *url = parv[1];
41
42 if (!(mc = mychan_find(parv[0])))
43 {
44 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), parv[0]);
45 return;
46 }
47
48 if (!chanacs_source_has_flag(mc, si, CA_SET))
49 {
50 command_fail(si, fault_noprivs, _("You are not authorized to execute this command."));
51 return;
52 }
53
54 if (!url || !strcasecmp("OFF", url) || !strcasecmp("NONE", url))
55 {
56 /* not in a namespace to allow more natural use of SET PROPERTY.
57 * they may be able to introduce spaces, though. c'est la vie.
58 */
59 if (metadata_find(mc, "url"))
60 {
61 metadata_delete(mc, "url");
62 logcommand(si, CMDLOG_SET, "SET:URL:NONE: \2%s\2", mc->name);
63 verbose(mc, _("\2%s\2 cleared the channel URL"), get_source_name(si));
64 command_success_nodata(si, _("The URL for \2%s\2 has been cleared."), parv[0]);
65 return;
66 }
67
68 command_fail(si, fault_nochange, _("The URL for \2%s\2 was not set."), parv[0]);
69 return;
70 }
71
72 /* we'll overwrite any existing metadata */
73 metadata_add(mc, "url", url);
74
75 logcommand(si, CMDLOG_SET, "SET:URL: \2%s\2 \2%s\2", mc->name, url);
76 verbose(mc, _("\2%s\2 set the channel URL to \2%s\2"), get_source_name(si), url);
77 command_success_nodata(si, _("The URL of \2%s\2 has been set to \2%s\2."), parv[0], url);
78 }
79
80 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
81 * vim:ts=8
82 * vim:sw=8
83 * vim:noexpandtab
84 */