| 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 PROPERTY command. |
| 7 |
* |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "atheme.h" |
| 11 |
|
| 12 |
DECLARE_MODULE_V1 |
| 13 |
( |
| 14 |
"chanserv/set_property", false, _modinit, _moddeinit, |
| 15 |
PACKAGE_STRING, |
| 16 |
VENDOR_STRING |
| 17 |
); |
| 18 |
|
| 19 |
static void cs_cmd_set_property(sourceinfo_t *si, int parc, char *parv[]); |
| 20 |
|
| 21 |
command_t cs_set_property = { "PROPERTY", N_("Manipulates channel metadata."), AC_NONE, 2, cs_cmd_set_property, { .path = "cservice/set_property" } }; |
| 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_property, *cs_set_cmdtree); |
| 30 |
} |
| 31 |
|
| 32 |
void _moddeinit(module_unload_intent_t intent) |
| 33 |
{ |
| 34 |
command_delete(&cs_set_property, *cs_set_cmdtree); |
| 35 |
} |
| 36 |
|
| 37 |
static void cs_cmd_set_property(sourceinfo_t *si, int parc, char *parv[]) |
| 38 |
{ |
| 39 |
mychan_t *mc; |
| 40 |
char *property = strtok(parv[1], " "); |
| 41 |
char *value = strtok(NULL, ""); |
| 42 |
unsigned int count; |
| 43 |
mowgli_patricia_iteration_state_t state; |
| 44 |
metadata_t *md; |
| 45 |
|
| 46 |
if (!property) |
| 47 |
{ |
| 48 |
command_fail(si, fault_needmoreparams, _("Syntax: SET <#channel> PROPERTY <property> [value]")); |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
/* do we really need to allow this? -- jilles */ |
| 53 |
if (strchr(property, ':') && !has_priv(si, PRIV_METADATA)) |
| 54 |
{ |
| 55 |
command_fail(si, fault_badparams, _("Invalid property name.")); |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
if (!(mc = mychan_find(parv[0]))) |
| 60 |
{ |
| 61 |
command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), parv[0]); |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
if (!is_founder(mc, entity(si->smu))) |
| 66 |
{ |
| 67 |
command_fail(si, fault_noprivs, _("You are not authorized to perform this command.")); |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
if (strchr(property, ':')) |
| 72 |
logcommand(si, CMDLOG_SET, "SET:PROPERTY: \2%s\2: \2%s\2/\2%s\2", mc->name, property, value); |
| 73 |
|
| 74 |
if (!value) |
| 75 |
{ |
| 76 |
md = metadata_find(mc, property); |
| 77 |
|
| 78 |
if (!md) |
| 79 |
{ |
| 80 |
command_fail(si, fault_nochange, _("Metadata entry \2%s\2 was not set."), property); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
metadata_delete(mc, property); |
| 85 |
logcommand(si, CMDLOG_SET, "SET:PROPERTY: \2%s\2 \2%s\2 (deleted)", mc->name, property); |
| 86 |
verbose(mc, _("\2%s\2 deleted the metadata entry \2%s\2"), get_source_name(si), property); |
| 87 |
command_success_nodata(si, _("Metadata entry \2%s\2 has been deleted."), property); |
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
count = 0; |
| 92 |
if (object(mc)->metadata) |
| 93 |
{ |
| 94 |
MOWGLI_PATRICIA_FOREACH(md, &state, object(mc)->metadata) |
| 95 |
{ |
| 96 |
if (strncmp(md->name, "private:", 8)) |
| 97 |
count++; |
| 98 |
} |
| 99 |
} |
| 100 |
if (count >= me.mdlimit) |
| 101 |
{ |
| 102 |
command_fail(si, fault_toomany, _("Cannot add \2%s\2 to \2%s\2 metadata table, it is full."), |
| 103 |
property, parv[0]); |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
if (strlen(property) > 32 || strlen(value) > 300 || has_ctrl_chars(property)) |
| 108 |
{ |
| 109 |
command_fail(si, fault_badparams, _("Parameters are too long. Aborting.")); |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
metadata_add(mc, property, value); |
| 114 |
logcommand(si, CMDLOG_SET, "SET:PROPERTY: \2%s\2 on \2%s\2 to \2%s\2", property, mc->name, value); |
| 115 |
verbose(mc, _("\2%s\2 added the metadata entry \2%s\2 with value \2%s\2"), get_source_name(si), property, value); |
| 116 |
command_success_nodata(si, _("Metadata entry \2%s\2 added."), property); |
| 117 |
} |
| 118 |
|
| 119 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 120 |
* vim:ts=8 |
| 121 |
* vim:sw=8 |
| 122 |
* vim:noexpandtab |
| 123 |
*/ |