Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / ircd_features.c
1 /*
2  * IRC - Internet Relay Chat, ircd/features.c
3  * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
4  *
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)
8  * any later version.
9  *
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.
14  *
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.
18  *
19  * $Id$
20  */
21 #include "config.h"
22 #include "ircd_features.h"
23 #include "client.h"
24 #include "hash.h"
25 #include "ircd.h"
26 #include "ircd_alloc.h"
27 #include "ircd_log.h"
28 #include "ircd_reply.h"
29 #include "ircd_string.h"
30 #include "match.h"
31 #include "msg.h"
32 #include "numeric.h"
33 #include "numnicks.h"
34 #include "random.h"     /* random_seed_set */
35 #include "s_bsd.h"
36 #include "s_debug.h"
37 #include "s_misc.h"
38 #include "send.h"
39 #include "struct.h"
40 #include "support.h"
41 #include "sys.h"    /* FALSE bleah */
42
43 #include <assert.h>
44 #include <stdlib.h>
45 #include <string.h>
46
47 /* List of log output types that can be set */
48 static struct LogTypes {
49   char *type;
50   int (*set)(const char *, const char *);
51   char *(*get)(const char *);
52 } logTypes[] = {
53   { "FILE", log_set_file, log_get_file },
54   { "FACILITY", log_set_facility, log_get_facility },
55   { "SNOMASK", log_set_snomask, log_get_snomask },
56   { "LEVEL", log_set_level, log_get_level },
57   { 0, 0, 0 }
58 };
59
60 /* Look up a struct LogType given the type string */
61 static struct LogTypes *
62 feature_log_desc(struct Client* from, const char *type)
63 {
64   int i;
65
66   assert(0 != type);
67
68   for (i = 0; logTypes[i].type; i++) /* find appropriate descriptor */
69     if (!ircd_strcmp(type, logTypes[i].type))
70       return &logTypes[i];
71
72   Debug((DEBUG_ERROR, "Unknown log feature type \"%s\"", type));
73   if (from) /* send an error; if from is NULL, called from conf parser */
74     send_reply(from, ERR_BADLOGTYPE, type);
75   else
76     log_write(LS_CONFIG, L_ERROR, 0, "Unknown log feature type \"%s\"", type);
77
78   return 0; /* not found */
79 }
80
81 /* Set the value of a log output type for a log subsystem */
82 static int
83 feature_log_set(struct Client* from, const char* const* fields, int count)
84 {
85   struct LogTypes *desc;
86   char *subsys;
87
88   if (count < 2) { /* set default facility */
89     if (log_set_default(count < 1 ? 0 : fields[0])) {
90       assert(count >= 1); /* should always accept default */
91
92       if (from) /* send an error */
93         send_reply(from, ERR_BADLOGVALUE, fields[0]);
94       else
95         log_write(LS_CONFIG, L_ERROR, 0,
96                   "Bad value \"%s\" for default facility", fields[0]);
97     } else
98       return count < 1 ? -1 : 1; /* tell feature to set or clear mark */
99   } else if (!(subsys = log_canon(fields[0]))) { /* no such subsystem */
100     if (from) /* send an error */
101       send_reply(from, ERR_BADLOGSYS, fields[0]);
102     else
103       log_write(LS_CONFIG, L_ERROR, 0,
104                 "No such logging subsystem \"%s\"", fields[0]);
105   } else if ((desc = feature_log_desc(from, fields[1]))) { /* set value */
106     if ((*desc->set)(fields[0], count < 3 ? 0 : fields[2])) {
107       assert(count >= 3); /* should always accept default */
108
109       if (from) /* send an error */
110         send_reply(from, ERR_BADLOGVALUE, fields[2]);
111       else
112         log_write(LS_CONFIG, L_ERROR, 0,
113                   "Bad value \"%s\" for log type %s (subsystem %s)",
114                   fields[2], desc->type, subsys);
115     }
116   }
117
118   return 0;
119 }
120
121 /* reset a log type for a subsystem to its default value */
122 static int
123 feature_log_reset(struct Client* from, const char* const* fields, int count)
124 {
125   struct LogTypes *desc;
126   char *subsys;
127
128   assert(0 != from); /* Never called by the .conf parser */
129
130   if (count < 1) { /* reset default facility */
131     log_set_default(0);
132     return -1; /* unmark this entry */
133   } else if (count < 2)
134     need_more_params(from, "RESET");
135   else if (!(subsys = log_canon(fields[0]))) /* no such subsystem */
136     send_reply(from, ERR_BADLOGSYS, fields[0]);
137   else if ((desc = feature_log_desc(from, fields[1]))) /* reset value */
138     (*desc->set)(fields[0], 0); /* default should always be accepted */
139
140   return 0;
141 }
142
143 /* report the value of a log setting */
144 static void
145 feature_log_get(struct Client* from, const char* const* fields, int count)
146 {
147   struct LogTypes *desc;
148   char *value, *subsys;
149
150   assert(0 != from); /* never called by .conf parser */
151
152   if (count < 1) /* return default facility */
153     send_reply(from, SND_EXPLICIT | RPL_FEATURE, ":Log facility: %s",
154                log_get_default());
155   else if (count < 2)
156     need_more_params(from, "GET");
157   else if (!(subsys = log_canon(fields[0]))) { /* no such subsystem */
158     send_reply(from, ERR_BADLOGSYS, fields[0]);
159   } else if ((desc = feature_log_desc(from, fields[1]))) {
160     if ((value = (*desc->get)(fields[0]))) /* send along value */
161       send_reply(from, SND_EXPLICIT | RPL_FEATURE,
162                  ":Log %s for subsystem %s: %s", desc->type, subsys,
163                  (*desc->get)(subsys));
164     else
165       send_reply(from, SND_EXPLICIT | RPL_FEATURE,
166                  ":No log %s is set for subsystem %s", desc->type, subsys);
167   }
168 }
169
170 /* sets a feature to the given value */
171 typedef int  (*feat_set_call)(struct Client*, const char* const*, int);
172 /* gets the value of a feature */
173 typedef void (*feat_get_call)(struct Client*, const char* const*, int);
174 /* unmarks all sub-feature values prior to reading .conf */
175 typedef void (*feat_unmark_call)(void);
176 /* resets to defaults all currently unmarked values */
177 typedef void (*feat_mark_call)(int);
178 /* reports features as a /stats f list */
179 typedef void (*feat_report_call)(struct Client*, int);
180
181 #define FEAT_NONE   0x0000      /* no value */
182 #define FEAT_INT    0x0001      /* set if entry contains an integer value */
183 #define FEAT_BOOL   0x0002      /* set if entry contains a boolean value */
184 #define FEAT_STR    0x0003      /* set if entry contains a string value */
185 #define FEAT_MASK   0x000f      /* possible value types */
186
187 #define FEAT_MARK   0x0010      /* set if entry has been changed */
188 #define FEAT_NULL   0x0020      /* NULL string is permitted */
189 #define FEAT_CASE   0x0040      /* string is case-sensitive */
190
191 #define FEAT_OPER   0x0100      /* set to display only to opers */
192 #define FEAT_MYOPER 0x0200      /* set to display only to local opers */
193 #define FEAT_NODISP 0x0400      /* feature must never be displayed */
194
195 #define FEAT_READ   0x1000      /* feature is read-only (for now, perhaps?) */
196
197 static struct FeatureDesc {
198   enum Feature     feat;    /* feature identifier */
199   char*            type;    /* string describing type */
200   unsigned int     flags;   /* flags for feature */
201   int              v_int;   /* integer value */
202   int              def_int; /* default value */
203   char*            v_str;   /* string value */
204   char*            def_str; /* default value */
205   feat_set_call    set;     /* set feature values */
206   feat_set_call    reset;   /* reset feature values to defaults */
207   feat_get_call    get;     /* get feature values */
208   feat_unmark_call unmark;  /* unmark all feature change values */
209   feat_mark_call   mark;    /* reset to defaults all unchanged features */
210   feat_report_call report;  /* report feature values */
211 } features[] = {
212 #define F_N(type, flags, set, reset, get, unmark, mark, report)               \
213   { FEAT_ ## type, #type, FEAT_NONE | (flags), 0, 0, 0, 0,                    \
214     (set), (reset), (get), (unmark), (mark), (report) }
215 #define F_I(type, flags, v_int)                                               \
216   { FEAT_ ## type, #type, FEAT_INT | (flags), 0, (v_int), 0, 0,               \
217     0, 0, 0, 0, 0, 0 }
218 #define F_B(type, flags, v_int)                                               \
219   { FEAT_ ## type, #type, FEAT_BOOL | (flags), 0, (v_int), 0, 0,              \
220     0, 0, 0, 0, 0, 0 }
221 #define F_S(type, flags, v_str)                                               \
222   { FEAT_ ## type, #type, FEAT_STR | (flags), 0, 0, 0, (v_str),               \
223     0, 0, 0, 0, 0, 0 }
224
225   /* Misc. features */
226   F_N(LOG, FEAT_MYOPER, feature_log_set, feature_log_reset, feature_log_get,
227       log_feature_unmark, log_feature_mark, log_feature_report),
228   F_S(DOMAINNAME, 0, DOMAINNAME),
229   F_B(RELIABLE_CLOCK, 0, 0),
230   F_I(BUFFERPOOL, 0, 27000000),
231   F_B(HAS_FERGUSON_FLUSHER, 0, 0),
232   F_I(CLIENT_FLOOD, 0, 1024),
233   F_I(SERVER_PORT, FEAT_OPER, 4400),
234   F_B(NODEFAULTMOTD, 0, 1),
235   F_B(KILL_IPMISMATCH, FEAT_OPER, 0),
236   F_B(IDLE_FROM_MSG, 0, 1),
237   F_B(HUB, 0, 0),
238   F_B(WALLOPS_OPER_ONLY, 0, 0),
239   F_B(NODNS, 0, 0),
240   F_N(RANDOM_SEED, FEAT_NODISP, random_seed_set, 0, 0, 0, 0, 0),
241
242   /* features that probably should not be touched */
243   F_I(KILLCHASETIMELIMIT, 0, 30),
244   F_I(MAXCHANNELSPERUSER, 0, 10),
245   F_I(AVBANLEN, 0, 40),
246   F_I(MAXBANS, 0, 30),
247   F_I(MAXSILES, 0, 15),
248   F_I(HANGONGOODLINK, 0, 300),
249   F_I(HANGONRETRYDELAY, 0, 10),
250   F_I(CONNECTTIMEOUT, 0, 90),
251   F_I(TIMESEC, 0, 60),
252   F_I(MAXIMUM_LINKS, 0, 1),
253   F_I(PINGFREQUENCY, 0, 120),
254   F_I(CONNECTFREQUENCY, 0, 600),
255   F_I(DEFAULTMAXSENDQLENGTH, 0, 40000),
256
257   /* Some misc. default paths */
258   F_S(MPATH, FEAT_CASE | FEAT_MYOPER, "ircd.motd"),
259   F_S(RPATH, FEAT_CASE | FEAT_MYOPER, "remote.motd"),
260   F_S(PPATH, FEAT_CASE | FEAT_MYOPER | FEAT_READ, "ircd.pid"),
261
262   /* Networking features */
263   F_B(VIRTUAL_HOST, 0, 0),
264   F_I(TOS_SERVER, 0, 0x08),
265   F_I(TOS_CLIENT, 0, 0x08),
266
267   /* features that affect all operators */
268   F_B(CRYPT_OPER_PASSWORD, FEAT_MYOPER | FEAT_READ, 1),
269   F_B(OPER_NO_CHAN_LIMIT, 0, 1),
270   F_B(OPER_MODE_LCHAN, 0, 1),
271   F_B(OPER_WALK_THROUGH_LMODES, 0, 0),
272   F_B(NO_OPER_DEOP_LCHAN, 0, 0),
273   F_B(SHOW_INVISIBLE_USERS, 0, 1),
274   F_B(SHOW_ALL_INVISIBLE_USERS, 0, 1),
275   F_B(UNLIMIT_OPER_QUERY, 0, 0),
276   F_B(LOCAL_KILL_ONLY, 0, 0),
277   F_B(CONFIG_OPERCMDS, 0, 1), /* XXX change default before release */
278
279   /* features that affect global opers on this server */
280   F_B(OPER_KILL, 0, 1),
281   F_B(OPER_REHASH, 0, 1),
282   F_B(OPER_RESTART, 0, 1),
283   F_B(OPER_DIE, 0, 1),
284   F_B(OPER_GLINE, 0, 1),
285   F_B(OPER_LGLINE, 0, 1),
286   F_B(OPER_JUPE, 0, 1),
287   F_B(OPER_LJUPE, 0, 1),
288   F_B(OPER_OPMODE, 0, 1),
289   F_B(OPER_LOPMODE, 0, 1),
290   F_B(OPER_BADCHAN, 0, 0),
291   F_B(OPER_LBADCHAN, 0, 0),
292   F_B(OPER_SET, 0, 1),
293   F_B(OPERS_SEE_IN_SECRET_CHANNELS, 0, 1),
294
295   /* features that affect local opers on this server */
296   F_B(LOCOP_KILL, 0, 0),
297   F_B(LOCOP_REHASH, 0, 1),
298   F_B(LOCOP_RESTART, 0, 0),
299   F_B(LOCOP_DIE, 0, 0),
300   F_B(LOCOP_LGLINE, 0, 1),
301   F_B(LOCOP_LJUPE, 0, 1),
302   F_B(LOCOP_LOPMODE, 0, 1),
303   F_B(LOCOP_LBADCHAN, 0, 0),
304   F_B(LOCOP_SET, 0, 0),
305   F_B(LOCOP_SEE_IN_SECRET_CHANNELS, 0, 0),
306
307 #undef F_S
308 #undef F_B
309 #undef F_I
310 #undef F_N
311   { FEAT_LAST_F, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
312 };
313
314 /* Given a feature's identifier, look up the feature descriptor */
315 static struct FeatureDesc *
316 feature_desc(struct Client* from, const char *feature)
317 {
318   int i;
319
320   assert(0 != feature);
321
322   for (i = 0; features[i].type; i++) /* find appropriate descriptor */
323     if (!ircd_strcmp(feature, features[i].type))
324       return &features[i];
325
326   Debug((DEBUG_ERROR, "Unknown feature \"%s\"", feature));
327   if (from) /* report an error */
328     send_reply(from, ERR_NOFEATURE, feature);
329   else
330     log_write(LS_CONFIG, L_ERROR, 0, "Unknown feature \"%s\"", feature);
331
332   return 0; /* not found */
333 }
334
335 /* Given a feature vector string, set the value of a feature */
336 int
337 feature_set(struct Client* from, const char* const* fields, int count)
338 {
339   int i;
340   struct FeatureDesc *feat;
341
342   if (from && !HasPriv(from, PRIV_SET))
343     return send_reply(from, ERR_NOPRIVILEGES);
344
345   if (count < 1) {
346     if (from) /* report an error in the number of arguments */
347       need_more_params(from, "SET");
348     else
349       log_write(LS_CONFIG, L_ERROR, 0, "Not enough fields in F line");
350   } else if ((feat = feature_desc(from, fields[0]))) { /* find feature */
351     if (from && feat->flags & FEAT_READ)
352       return send_reply(from, ERR_NOFEATURE, fields[0]);
353
354     switch (feat->flags & FEAT_MASK) {
355     case FEAT_NONE:
356       if (feat->set && (i = (*feat->set)(from, fields + 1, count - 1))) {
357         if (i > 0) /* call the set callback and do marking */
358           feat->flags |= FEAT_MARK;
359         else /* i < 0 */
360           feat->flags &= ~FEAT_MARK;
361         break;
362       }
363
364     case FEAT_INT: /* an integer value */
365       if (count < 2) { /* reset value */
366         feat->v_int = feat->def_int;
367         feat->flags &= ~FEAT_MARK;
368       } else { /* ok, figure out the value and whether to mark it */
369         feat->v_int = atoi(fields[1]);
370         if (feat->v_int == feat->def_int)
371           feat->flags &= ~FEAT_MARK;
372         else
373           feat->flags |= FEAT_MARK;
374       }
375       break;
376
377     case FEAT_BOOL: /* it's a boolean value--true or false */
378       if (count < 2) { /* reset value */
379         feat->v_int = feat->def_int;
380         feat->flags &= ~FEAT_MARK;
381       } else { /* figure out the value and whether to mark it */
382         if (!ircd_strncmp(fields[1], "TRUE", strlen(fields[1])) ||
383             !ircd_strncmp(fields[1], "YES", strlen(fields[1])) ||
384             (strlen(fields[1]) >= 2 &&
385              !ircd_strncmp(fields[1], "ON", strlen(fields[1]))))
386           feat->v_int = 1;
387         else if (!ircd_strncmp(fields[1], "FALSE", strlen(fields[1])) ||
388                  !ircd_strncmp(fields[1], "NO", strlen(fields[1])) ||
389                  (strlen(fields[1]) >= 2 &&
390                   !ircd_strncmp(fields[1], "OFF", strlen(fields[1]))))
391           feat->v_int = 0;
392         else if (from) /* report an error... */
393           return send_reply(from, ERR_BADFEATVALUE, fields[1], feat->type);
394         else {
395           log_write(LS_CONFIG, L_ERROR, 0, "Bad value \"%s\" for feature %s",
396                     fields[1], feat->type);
397           return 0;
398         }
399
400         if (feat->v_int == feat->def_int) /* figure out whether to mark it */
401           feat->flags &= ~FEAT_MARK;
402         else
403           feat->flags |= FEAT_MARK;
404       }
405       break;
406
407     case FEAT_STR: /* it's a string value */
408       if (count < 2 ||
409           !(feat->flags & FEAT_CASE ? strcmp(fields[1], feat->def_str) :
410             ircd_strcmp(fields[1], feat->def_str))) { /* reset to default */
411         if (feat->v_str && feat->v_str != feat->def_str)
412           MyFree(feat->v_str); /* free old value */
413         feat->v_str = feat->def_str; /* very special... */
414
415         feat->flags &= ~FEAT_MARK; /* unmark it */
416       } else {
417         if (!*fields[1]) { /* empty string translates to NULL */
418           if (feat->flags & FEAT_NULL) { /* permitted? */
419             if (feat->v_str && feat->v_str != feat->def_str)
420               MyFree(feat->v_str); /* free old value */
421             feat->v_str = 0; /* set it to NULL */
422           } else if (from) /* hmmm...not permitted; report error */
423             return send_reply(from, ERR_BADFEATVALUE, "NULL", feat->type);
424           else {
425             log_write(LS_CONFIG, L_ERROR, 0,
426                       "Bad value \"NULL\" for feature %s", feat->type);
427             return 0;
428           }
429         } else if ((feat->flags & FEAT_CASE ?
430                     strcmp(fields[1], feat->v_str) :
431                     ircd_strcmp(fields[1], feat->v_str))) { /* new value */
432           if (feat->v_str && feat->v_str != feat->def_str)
433             MyFree(feat->v_str); /* free old value */
434           DupString(feat->v_str, fields[1]); /* store new value */
435         }
436
437         feat->flags |= FEAT_MARK; /* mark it as having been touched */
438       }
439       break;
440     }
441   }
442
443   return 0;
444 }
445
446 /* reset a feature to its default values */
447 int
448 feature_reset(struct Client* from, const char* const* fields, int count)
449 {
450   int i;
451   struct FeatureDesc *feat;
452
453   assert(0 != from);
454
455   if (!HasPriv(from, PRIV_SET))
456     return send_reply(from, ERR_NOPRIVILEGES);
457
458   if (count < 1) /* check arguments */
459     need_more_params(from, "RESET");
460   else if ((feat = feature_desc(from, fields[0]))) { /* get descriptor */
461     if (from && feat->flags & FEAT_READ)
462       return send_reply(from, ERR_NOFEATURE, fields[0]);
463
464     switch (feat->flags & FEAT_MASK) {
465     case FEAT_NONE: /* None... */
466       if (feat->reset && (i = (*feat->reset)(from, fields + 1, count - 1))) {
467         if (i > 0) /* call reset callback and parse mark return */
468           feat->flags |= FEAT_MARK;
469         else /* i < 0 */
470           feat->flags &= ~FEAT_MARK;
471       }
472       break;
473
474     case FEAT_INT:  /* Integer... */
475     case FEAT_BOOL: /* Boolean... */
476       feat->v_int = feat->def_int; /* set the default */
477       feat->flags &= ~FEAT_MARK; /* unmark it */
478       break;
479
480     case FEAT_STR: /* string! */
481       if (feat->v_str && feat->v_str != feat->def_str)
482         MyFree(feat->v_str); /* free old value */
483       feat->v_str = feat->def_str; /* set it to default */
484       feat->flags &= ~FEAT_MARK; /* unmark it */
485       break;
486     }
487   }
488
489   return 0;
490 }
491
492 /* Gets the value of a specific feature and reports it to the user */
493 int
494 feature_get(struct Client* from, const char* const* fields, int count)
495 {
496   struct FeatureDesc *feat;
497
498   assert(0 != from);
499
500   if (count < 1) /* check parameters */
501     need_more_params(from, "GET");
502   else if ((feat = feature_desc(from, fields[0]))) {
503     if ((feat->flags & FEAT_NODISP) ||
504         (feat->flags & FEAT_MYOPER && !MyOper(from)) ||
505         (feat->flags & FEAT_OPER && !IsAnOper(from))) /* check privs */
506       return send_reply(from, ERR_NOPRIVILEGES);
507
508     switch (feat->flags & FEAT_MASK) {
509     case FEAT_NONE: /* none, call the callback... */
510       if (feat->get) /* if there's a callback, use it */
511         (*feat->get)(from, fields + 1, count - 1);
512       break;
513
514     case FEAT_INT: /* integer, report integer value */
515       send_reply(from, SND_EXPLICIT | RPL_FEATURE,
516                  ":Integer value of %s: %d", feat->type, feat->v_int);
517       break;
518
519     case FEAT_BOOL: /* boolean, report boolean value */
520       send_reply(from, SND_EXPLICIT | RPL_FEATURE,
521                  ":Boolean value of %s: %s", feat->type,
522                  feat->v_int ? "TRUE" : "FALSE");
523       break;
524
525     case FEAT_STR: /* string, report string value */
526       if (feat->v_str) /* deal with null case */
527         send_reply(from, SND_EXPLICIT | RPL_FEATURE,
528                    ":String value of %s: %s", feat->type, feat->v_str);
529       else
530         send_reply(from, SND_EXPLICIT | RPL_FEATURE,
531                    ":String value for %s not set", feat->type);
532       break;
533     }
534   }
535
536   return 0;
537 }
538
539 /* called before reading the .conf to clear all marks */
540 void
541 feature_unmark(void)
542 {
543   int i;
544
545   for (i = 0; features[i].type; i++) {
546     features[i].flags &= ~FEAT_MARK; /* clear the marks... */
547     if (features[i].unmark) /* call the unmark callback if necessary */
548       (*features[i].unmark)();
549   }
550 }
551
552 /* Called after reading the .conf to reset unmodified values to defaults */
553 void
554 feature_mark(void)
555 {
556   int i;
557
558   for (i = 0; features[i].type; i++)
559     switch (features[i].flags & FEAT_MASK) {
560     case FEAT_NONE:
561       if (features[i].mark) /* call the mark callback if necessary */
562         (*features[i].mark)(features[i].flags & FEAT_MARK ? 1 : 0);
563       break;
564
565     case FEAT_INT:  /* Integers or Booleans... */
566     case FEAT_BOOL:
567       if (!(features[i].flags & FEAT_MARK)) /* not changed? */
568         features[i].v_int = features[i].def_int;
569       break;
570
571     case FEAT_STR: /* strings... */
572       if (!(features[i].flags & FEAT_MARK)) { /* not changed? */
573         if (features[i].v_str && features[i].v_str != features[i].def_str)
574           MyFree(features[i].v_str); /* free old value */
575         features[i].v_str = features[i].def_str;
576       }
577       break;
578     }
579 }
580
581 /* report all F-lines */
582 void
583 feature_report(struct Client* to)
584 {
585   int i;
586
587   for (i = 0; features[i].type; i++) {
588     if ((features[i].flags & FEAT_NODISP) ||
589         (features[i].flags & FEAT_MYOPER && !MyOper(to)) ||
590         (features[i].flags & FEAT_OPER && !IsAnOper(to)))
591       continue; /* skip this one */
592
593     switch (features[i].flags & FEAT_MASK) {
594     case FEAT_NONE:
595       if (features[i].report) /* let the callback handle this */
596         (*features[i].report)(to, features[i].flags & FEAT_MARK ? 1 : 0);
597       break;
598
599
600     case FEAT_INT: /* Report an F-line with integer values */
601       if (features[i].flags & FEAT_MARK) /* it's been changed */
602         send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F %s %d",
603                    features[i].type, features[i].v_int);
604       break;
605
606     case FEAT_BOOL: /* Report an F-line with boolean values */
607       if (features[i].flags & FEAT_MARK) /* it's been changed */
608         send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F %s %s",
609                    features[i].type, features[i].v_int ? "TRUE" : "FALSE");
610       break;
611
612     case FEAT_STR: /* Report an F-line with string values */
613       if (features[i].flags & FEAT_MARK) { /* it's been changed */
614         if (features[i].v_str)
615           send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F %s %s",
616                      features[i].type, features[i].v_str);
617         else /* Actually, F:<type> would reset it; you want F:<type>: */
618           send_reply(to, SND_EXPLICIT | RPL_STATSFLINE, "F %s",
619                      features[i].type);
620       }
621       break;
622     }
623   }
624 }
625
626 /* return a feature's integer value */
627 int
628 feature_int(enum Feature feat)
629 {
630   assert(features[feat].feat == feat);
631   assert((features[feat].flags & FEAT_MASK) == FEAT_INT);
632
633   return features[feat].v_int;
634 }
635
636 /* return a feature's boolean value */
637 int
638 feature_bool(enum Feature feat)
639 {
640   assert(features[feat].feat == feat);
641   assert((features[feat].flags & FEAT_MASK) == FEAT_BOOL);
642
643   return features[feat].v_int;
644 }
645
646 /* return a feature's string value */
647 const char *
648 feature_str(enum Feature feat)
649 {
650   assert(features[feat].feat == feat);
651   assert((features[feat].flags & FEAT_MASK) == FEAT_STR);
652
653   return features[feat].v_str;
654 }