Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / doc / api / features.txt
1 As of u2.10.11, most of the compile-time configuration options present
2 in previous versions of ircu have been provided via the configuration
3 file as "features."  This document is intended not only to give an
4 explanation of how to use the features subsystem in new code, but also
5 how to define new features.
6
7 In the ircd_features.h header file is an enum Feature that lists all
8 the features known to the features subsystem.  The order of entries in
9 this list must match precisely the order of features as listed in the
10 features[] table in ircd_features.c.  There are four kinds of
11 features, seven different flags that can be set for features, and
12 seven different call-backs for more complex features.
13
14 Types of Features
15
16 There are at present four different types of features: NONE, INT,
17 BOOL, and STR.  Features of type "NONE" are complex features, such as
18 the logging subsystem, that have complicated behavior that's managed
19 through the use of call-backs.  The call-backs available are set,
20 which is called to set the value of the feature; reset, which is
21 called to reset the value of the feature back to its default; get,
22 which is called to send the user a RPL_FEATURE to describe the feature
23 setting; unmark, which is called prior to reading the configuration
24 file; mark, which is called after reading the configuration file; and
25 report, which is used to send a user a list of RPL_STATSFLINE
26 replies.
27
28 In comparison to type "NONE," the other types are very simple.  Type
29 "INT" is used for features that take an integer value; "BOOL" is for
30 those features that are boolean types; and "STR" is for those features
31 that take simple string values.  The values for these feature types
32 are handled directly by the features subsystem, and can be examined
33 from code with the feature_int(), feature_bool(), and feature_str()
34 functions, described below.
35
36 Feature Flags
37
38 There are seven feature flags, one of which is used internally by the
39 feature subsystem.  Three of these flags, FEAT_OPER, FEAT_MYOPER, and
40 FEAT_NODISP, are used to select who can see the settings of those
41 features; FEAT_OPER permits any operator anywhere on the network to
42 examine the settings of a particular feature, whereas FEAT_MYOPER only
43 permits operators local to a server to examine feature values, and
44 FEAT_NODISP prohibits display of the feature value altogether.  If
45 none of these three flags are specified, then any user may examine
46 that feature's value.
47
48 Two other flags only have any meaning for string values; they are
49 FEAT_NULL, which is used to specify that a feature of type "STR" may
50 have a NULL value, and FEAT_CASE, which specifies that the feature is
51 case sensitive--this may be used on file names, for example.  Note
52 that if you give "0" as the default value for a feature, you must also
53 set the FEAT_NULL flag.
54
55 The remaining non-internal flag is FEAT_READ, which simply sets the
56 feature to be read-only; a feature so marked may only be changed
57 through the configuration file.
58
59 Marking Features
60
61 When the configuration file is read, there must be some way to
62 determine if a particular F-line has been removed since the last time
63 the configuration file was read.  The way this is done in the features
64 subsystem is to have a "mark" for each feature.  Prior to reading the
65 configuration file, all marks are cleared for all features (and all
66 "unmark" call-backs are called).  As each F-line is encountered and
67 processed, that feature's mark is set.  Finally, when the
68 configuration file has been fully read, all remaining unmarked
69 features are reset to their default values (and all "mark" call-backs
70 are called).
71
72 Adding New Features
73
74 To add a new feature, first determine the feature's name (which must
75 begin with the string "FEAT_") and its type ("NONE," "INT," "BOOL," or
76 "STR").  Then add the feature to the enum Feature in an appropriate
77 place (i.e., it's good to group all features affecting operators
78 separate from those features affecting networking code), and a
79 corresponding entry in the features[] table in ircd_features.c.  It
80 will be best to use one of the F_?() macros, which are documented
81 below.  Then, whenever you need to refer to the value of a specific
82 feature, call the appropriate feature_<type>() function, as documented
83 below.
84
85 <enum>
86 enum Feature;
87
88 The "Feature" enum lists all of the features known to the feature
89 subsystem.  Each feature name *must* begin with "FEAT_"; the portion
90 of the name following "FEAT_" will be what you use to set the feature
91 from the configuration file or with the "set" or "reset" commands.
92 </enum>
93
94 <function>
95 int feature_set(struct Client* from, const char* const* fields, int count);
96
97 The feature_set() function takes an array of strings and a count of
98 the number of strings in the array.  The first string is a feature
99 name, and, for most features, the second string will be that feature's
100 value.  The _from_ parameter is the struct Client describing the user
101 that issued the "set" command.  This parameter may be NULL if
102 feature_set() is being called from the configuration file subsystem.
103 </function>
104
105 <function>
106 int feature_reset(struct Client* from, const char* const* fields, int count);
107
108 The feature_reset() function is very similar in arguments to the
109 feature_set() function, except that it may not be called from the
110 configuration file subsystem.  It resets the named feature to its
111 default value.
112 </function>
113
114 <function>
115 int feature_get(struct Client* from, const char* const* fields, int count);
116
117 Again, feature_get() is very similar in arguments to the feature_set()
118 function, except that again it may not be called from the
119 configuration file subsystem.  It reports the value of the named
120 feature to the user that issued the "get" command.
121 </function>
122
123 <function>
124 void feature_unmark(void);
125
126 This function is used to unmark all feature values, as described in
127 the subsection "Marking Features."  It takes no arguments and returns
128 nothing.
129 </function>
130
131 <function>
132 void feature_mark(void);
133
134 The complement to feature_unmark(), feature_mark() resets all
135 unchanged feature settings to their defaults.  See the subsection on
136 "Marking Features."
137 </function>
138
139 <function>
140 void feature_init(void);
141
142 This function initializes the feature interface by setting the default
143 values for all features correctly.
144 </function>
145
146 <function>
147 void feature_report(struct Client* to);
148
149 Reports all F-lines to a user using RPL_STATSFLINE, except those which
150 the user is not permitted to see due to flag settings.
151 </function>
152
153 <function>
154 int feature_int(enum Feature feat);
155
156 To retrieve the values of integer features, call this function.
157 Calling this function on a different type of feature, such as a "BOOL"
158 feature, will result in an assertion failure.
159 </function>
160
161 <function>
162 int feature_bool(enum Feature feat);
163
164 This function is the complement of feature_int() for features of type
165 "BOOL."
166 </function>
167
168 <function>
169 const char *feature_str(enum Feature feat);
170
171 Use this function to retrieve strings values for features of type
172 "STR"; you may not modify nor free the string value.
173 </function>
174
175 <macro>
176 #define F_N(type, flags, set, reset, get, notify, unmark, mark, report)
177
178 This macro is used in the features[] table to simplify defining a
179 feature of type "NONE."  The _type_ parameter is the name of the
180 feature excluding the "FEAT_" prefix, and MUST NOT be in
181 double-quotes.  The _flags_ parameter may be 0, FEAT_OPER, or
182 FEAT_MYOPER--the bitwise OR of these two flags is permissible but
183 would not make sense.  The rest of the arguments are pointers to
184 functions implementing the named call-back.
185 </macro>
186
187 <macro>
188 #define F_I(type, flags, v_int, notify)
189
190 To define integer features, use the F_I() macro.  The _type_ and
191 _flags_ parameters are as for F_N(), and the _v_int_ macro specifies
192 the default value of the feature.  The _notify_ parameter, if
193 non-zero, will be called whenever the value of the feature changes.
194 </macro>
195
196 <macro>
197 #define F_B(type, flags, v_int, notify)
198
199 This macro is used for defining features of type "BOOL"; it is very
200 similar to F_I(), but _v_int_ should either 0 (for a "FALSE" value) or
201 1 (for a "TRUE" value).  The _notify_ parameter, if non-zero, will be
202 called whenever the value of the feature changes.
203 </macro>
204
205 <macro>
206 #define F_S(type, flags, v_str, notify)
207
208 Also similar to F_I(), F_S() defines features of type "STR."  The
209 _flags_ argument may be the bitwise OR of one of FEAT_OPER or
210 FEAT_MYOPER with the special string flags FEAT_NULL and FEAT_CASE,
211 which are described above in the section "Feature Flags."  The
212 _notify_ parameter, if non-zero, will be called whenever the value of
213 the feature changes.  Note that FEAT_NULL *must* be set if the default
214 string _v_str_ is set to NULL.
215 </macro>
216
217 <authors>
218 Kev <klmitch@mit.edu>
219 </authors>
220
221 <changelog>
222 [2001-01-02 Kev] Add documentation for new flags and for the notify
223 mechanism
224
225 [2000-12-18 Kev] Document the features API
226 </changelog>