2 * IRC - Internet Relay Chat, ircd/features.c
3 * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 1, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "ircd_alloc.h"
27 #include "ircd_reply.h"
28 #include "ircd_string.h"
39 #include "sys.h" /* FALSE bleah */
44 static struct LogTypes {
46 int (*set)(const char *, const char *);
47 char *(*get)(const char *);
49 { "FILE", log_set_file, log_get_file },
50 { "FACILITY", log_set_facility, log_get_facility },
51 { "SNOMASK", log_set_snomask, log_get_snomask },
52 { "LEVEL", log_set_level, log_get_level },
56 static struct LogTypes *
57 feature_log_desc(struct Client* from, const char *type)
63 for (i = 0; logTypes[i].type; i++) /* find appropriate descriptor */
64 if (!ircd_strcmp(type, logTypes[i].type))
67 Debug((DEBUG_ERROR, "Unknown log feature type \"%s\"", type));
69 send_reply(from, ERR_BADLOGTYPE, type);
71 log_write(LS_CONFIG, L_ERROR, 0, "Unknown log feature type \"%s\"", type);
73 return 0; /* not found */
77 feature_log_set(struct Client* from, const char* const* fields, int count)
79 struct LogTypes *desc;
82 if (count < 2) { /* set default facility */
83 if (log_set_default(count < 1 ? 0 : fields[0])) {
84 assert(count >= 1); /* should always accept default */
87 send_reply(from, ERR_BADLOGVALUE, fields[0]);
89 log_write(LS_CONFIG, L_ERROR, 0,
90 "Bad value \"%s\" for default facility", fields[0]);
92 } else if (!(subsys = log_canon(fields[0]))) { /* no such subsystem */
94 send_reply(from, ERR_BADLOGSYS, fields[0]);
96 log_write(LS_CONFIG, L_ERROR, 0,
97 "No such logging subsystem \"%s\"", fields[0]);
98 } else if ((desc = feature_log_desc(from, fields[1]))) { /* set value */
99 if ((*desc->set)(fields[0], count < 3 ? 0 : fields[2])) {
100 assert(count >= 3); /* should always accept default */
103 send_reply(from, ERR_BADLOGVALUE, fields[2]);
105 log_write(LS_CONFIG, L_ERROR, 0,
106 "Bad value \"%s\" for log type %s (subsystem %s)",
107 fields[2], desc->type, subsys);
113 feature_log_reset(struct Client* from, const char* const* fields, int count)
115 struct LogTypes *desc;
120 if (count < 1) /* reset default facility */
123 need_more_params(from, "RESET");
124 else if (!(subsys = log_canon(fields[0]))) /* no such subsystem */
125 send_reply(from, ERR_BADLOGSYS, fields[0]);
126 else if ((desc = feature_log_desc(from, fields[1]))) /* reset value */
127 (*desc->set)(fields[0], 0);
131 feature_log_get(struct Client* from, const char* const* fields, int count)
133 struct LogTypes *desc;
134 char *value, *subsys;
138 if (count < 1) /* return default facility */
139 send_reply(from, SND_EXPLICIT | RPL_FEATURE, ":Log facility: %s",
142 need_more_params(from, "GET");
143 else if (!(subsys = log_canon(fields[0]))) { /* no such subsystem */
144 send_reply(from, ERR_BADLOGSYS, fields[0]);
145 } else if ((desc = feature_log_desc(from, fields[1]))) {
146 if ((value = (*desc->get)(fields[0]))) /* send along value */
147 send_reply(from, SND_EXPLICIT | RPL_FEATURE,
148 ":Log %s for subsystem %s: %s", desc->type, subsys,
149 (*desc->get)(subsys));
151 send_reply(from, SND_EXPLICIT | RPL_FEATURE,
152 ":No log %s is set for subsystem %s", desc->type, subsys);
156 typedef void (*feature_call)(struct Client*, const char* const*, int);
158 static struct FeatureDesc {
160 feature_call set; /* set feature values */
161 feature_call reset; /* reset feature values to defaults */
162 feature_call get; /* get feature values */
164 { "LOG", feature_log_set, feature_log_reset, feature_log_get },
168 static struct FeatureDesc *
169 feature_desc(struct Client* from, const char *feature)
173 assert(0 != feature);
175 for (i = 0; features[i].type; i++) /* find appropriate descriptor */
176 if (!ircd_strcmp(feature, features[i].type))
179 Debug((DEBUG_ERROR, "Unknown feature \"%s\"", feature));
181 send_reply(from, ERR_NOFEATURE, feature);
183 log_write(LS_CONFIG, L_ERROR, 0, "Unknown feature \"%s\"", feature);
185 return 0; /* not found */
189 feature_set(struct Client* from, const char* const* fields, int count)
191 struct FeatureDesc *feat;
195 need_more_params(from, "SET");
197 log_write(LS_CONFIG, L_ERROR, 0, "Not enough fields in F line");
198 } else if ((feat = feature_desc(from, fields[0])))
199 (*feat->set)(from, fields + 1, count - 1);
205 feature_reset(struct Client* from, const char* const* fields, int count)
207 struct FeatureDesc *feat;
212 need_more_params(from, "RESET");
213 else if ((feat = feature_desc(from, fields[0])))
214 (*feat->reset)(from, fields + 1, count - 1);
220 feature_get(struct Client* from, const char* const* fields, int count)
222 struct FeatureDesc *feat;
227 need_more_params(from, "GET");
228 else if ((feat = feature_desc(from, fields[0])))
229 (*feat->get)(from, fields + 1, count - 1);