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