<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.darenet.org/skins/common/feed.css?12"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>ircu api - features - Revision history</title>
		<link>http://wiki.darenet.org/index.php?title=ircu_api_-_features&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.15.1</generator>
		<lastBuildDate>Wed, 20 May 2026 06:11:47 GMT</lastBuildDate>
		<item>
			<title>Secretagent:&amp;#32;New page: &lt;pre&gt;As of u2.10.11, most of the compile-time configuration options present in previous versions of ircu have been provided via the configuration file as &quot;features.&quot;  This document is inte...</title>
			<link>http://wiki.darenet.org/index.php?title=ircu_api_-_features&amp;diff=2268&amp;oldid=prev</link>
			<description>&lt;p&gt;New page: &amp;lt;pre&amp;gt;As of u2.10.11, most of the compile-time configuration options present in previous versions of ircu have been provided via the configuration file as &amp;quot;features.&amp;quot;  This document is inte...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;As of u2.10.11, most of the compile-time configuration options present&lt;br /&gt;
in previous versions of ircu have been provided via the configuration&lt;br /&gt;
file as &amp;quot;features.&amp;quot;  This document is intended not only to give an&lt;br /&gt;
explanation of how to use the features subsystem in new code, but also&lt;br /&gt;
how to define new features.&lt;br /&gt;
&lt;br /&gt;
In the ircd_features.h header file is an enum Feature that lists all&lt;br /&gt;
the features known to the features subsystem.  The order of entries in&lt;br /&gt;
this list must match precisely the order of features as listed in the&lt;br /&gt;
features[] table in ircd_features.c.  There are four kinds of&lt;br /&gt;
features, seven different flags that can be set for features, and&lt;br /&gt;
seven different call-backs for more complex features.&lt;br /&gt;
&lt;br /&gt;
Types of Features&lt;br /&gt;
&lt;br /&gt;
There are at present four different types of features: NONE, INT,&lt;br /&gt;
BOOL, and STR.  Features of type &amp;quot;NONE&amp;quot; are complex features, such as&lt;br /&gt;
the logging subsystem, that have complicated behavior that's managed&lt;br /&gt;
through the use of call-backs.  The call-backs available are set,&lt;br /&gt;
which is called to set the value of the feature; reset, which is&lt;br /&gt;
called to reset the value of the feature back to its default; get,&lt;br /&gt;
which is called to send the user a RPL_FEATURE to describe the feature&lt;br /&gt;
setting; unmark, which is called prior to reading the configuration&lt;br /&gt;
file; mark, which is called after reading the configuration file; and&lt;br /&gt;
report, which is used to send a user a list of RPL_STATSFLINE&lt;br /&gt;
replies.&lt;br /&gt;
&lt;br /&gt;
In comparison to type &amp;quot;NONE,&amp;quot; the other types are very simple.  Type&lt;br /&gt;
&amp;quot;INT&amp;quot; is used for features that take an integer value; &amp;quot;BOOL&amp;quot; is for&lt;br /&gt;
those features that are boolean types; and &amp;quot;STR&amp;quot; is for those features&lt;br /&gt;
that take simple string values.  The values for these feature types&lt;br /&gt;
are handled directly by the features subsystem, and can be examined&lt;br /&gt;
from code with the feature_int(), feature_bool(), and feature_str()&lt;br /&gt;
functions, described below.  These features have a notify callback,&lt;br /&gt;
which is used to warn subsystems that use the values of particular&lt;br /&gt;
features that the value has changed.&lt;br /&gt;
&lt;br /&gt;
Feature Flags&lt;br /&gt;
&lt;br /&gt;
There are seven feature flags, one of which is used internally by the&lt;br /&gt;
feature subsystem.  Three of these flags, FEAT_OPER, FEAT_MYOPER, and&lt;br /&gt;
FEAT_NODISP, are used to select who can see the settings of those&lt;br /&gt;
features; FEAT_OPER permits any operator anywhere on the network to&lt;br /&gt;
examine the settings of a particular feature, whereas FEAT_MYOPER only&lt;br /&gt;
permits operators local to a server to examine feature values, and&lt;br /&gt;
FEAT_NODISP prohibits display of the feature value altogether.  If&lt;br /&gt;
none of these three flags are specified, then any user may examine&lt;br /&gt;
that feature's value.&lt;br /&gt;
&lt;br /&gt;
Two other flags only have any meaning for string values; they are&lt;br /&gt;
FEAT_NULL, which is used to specify that a feature of type &amp;quot;STR&amp;quot; may&lt;br /&gt;
have a NULL value, and FEAT_CASE, which specifies that the feature is&lt;br /&gt;
case sensitive--this may be used on file names, for example.  Note&lt;br /&gt;
that if you give &amp;quot;0&amp;quot; as the default value for a feature, you must also&lt;br /&gt;
set the FEAT_NULL flag.&lt;br /&gt;
&lt;br /&gt;
The remaining non-internal flag is FEAT_READ, which simply sets the&lt;br /&gt;
feature to be read-only; a feature so marked may only be changed&lt;br /&gt;
through the configuration file.&lt;br /&gt;
&lt;br /&gt;
Marking Features&lt;br /&gt;
&lt;br /&gt;
When the configuration file is read, there must be some way to&lt;br /&gt;
determine if a particular F-line has been removed since the last time&lt;br /&gt;
the configuration file was read.  The way this is done in the features&lt;br /&gt;
subsystem is to have a &amp;quot;mark&amp;quot; for each feature.  Prior to reading the&lt;br /&gt;
configuration file, all marks are cleared for all features (and all&lt;br /&gt;
&amp;quot;unmark&amp;quot; call-backs are called).  As each F-line is encountered and&lt;br /&gt;
processed, that feature's mark is set.  Finally, when the&lt;br /&gt;
configuration file has been fully read, all remaining unmarked&lt;br /&gt;
features are reset to their default values (and all &amp;quot;mark&amp;quot; call-backs&lt;br /&gt;
are called).&lt;br /&gt;
&lt;br /&gt;
Adding New Features&lt;br /&gt;
&lt;br /&gt;
To add a new feature, first determine the feature's name (which must&lt;br /&gt;
begin with the string &amp;quot;FEAT_&amp;quot;) and its type (&amp;quot;NONE,&amp;quot; &amp;quot;INT,&amp;quot; &amp;quot;BOOL,&amp;quot; or&lt;br /&gt;
&amp;quot;STR&amp;quot;).  Then add the feature to the enum Feature in an appropriate&lt;br /&gt;
place (i.e., it's good to group all features affecting operators&lt;br /&gt;
separate from those features affecting networking code), and a&lt;br /&gt;
corresponding entry in the features[] table in ircd_features.c.  It&lt;br /&gt;
will be best to use one of the F_?() macros, which are documented&lt;br /&gt;
below.  Then, whenever you need to refer to the value of a specific&lt;br /&gt;
feature, call the appropriate feature_&amp;lt;type&amp;gt;() function, as documented&lt;br /&gt;
below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;enum&amp;gt;&lt;br /&gt;
enum Feature;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Feature&amp;quot; enum lists all of the features known to the feature&lt;br /&gt;
subsystem.  Each feature name *must* begin with &amp;quot;FEAT_&amp;quot;; the portion&lt;br /&gt;
of the name following &amp;quot;FEAT_&amp;quot; will be what you use to set the feature&lt;br /&gt;
from the configuration file or with the &amp;quot;set&amp;quot; or &amp;quot;reset&amp;quot; commands.&lt;br /&gt;
&amp;lt;/enum&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
int feature_set(struct Client* from, const char* const* fields, int count);&lt;br /&gt;
&lt;br /&gt;
The feature_set() function takes an array of strings and a count of&lt;br /&gt;
the number of strings in the array.  The first string is a feature&lt;br /&gt;
name, and, for most features, the second string will be that feature's&lt;br /&gt;
value.  The _from_ parameter is the struct Client describing the user&lt;br /&gt;
that issued the &amp;quot;set&amp;quot; command.  This parameter may be NULL if&lt;br /&gt;
feature_set() is being called from the configuration file subsystem.&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
int feature_reset(struct Client* from, const char* const* fields, int count);&lt;br /&gt;
&lt;br /&gt;
The feature_reset() function is very similar in arguments to the&lt;br /&gt;
feature_set() function, except that it may not be called from the&lt;br /&gt;
configuration file subsystem.  It resets the named feature to its&lt;br /&gt;
default value.&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
int feature_get(struct Client* from, const char* const* fields, int count);&lt;br /&gt;
&lt;br /&gt;
Again, feature_get() is very similar in arguments to the feature_set()&lt;br /&gt;
function, except that again it may not be called from the&lt;br /&gt;
configuration file subsystem.  It reports the value of the named&lt;br /&gt;
feature to the user that issued the &amp;quot;get&amp;quot; command.&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
void feature_unmark(void);&lt;br /&gt;
&lt;br /&gt;
This function is used to unmark all feature values, as described in&lt;br /&gt;
the subsection &amp;quot;Marking Features.&amp;quot;  It takes no arguments and returns&lt;br /&gt;
nothing.&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
void feature_mark(void);&lt;br /&gt;
&lt;br /&gt;
The complement to feature_unmark(), feature_mark() resets all&lt;br /&gt;
unchanged feature settings to their defaults.  See the subsection on&lt;br /&gt;
&amp;quot;Marking Features.&amp;quot;&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
void feature_init(void);&lt;br /&gt;
&lt;br /&gt;
This function initializes the feature interface by setting the default&lt;br /&gt;
values for all features correctly.&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
void feature_report(struct Client* to);&lt;br /&gt;
&lt;br /&gt;
Reports all F-lines to a user using RPL_STATSFLINE, except those which&lt;br /&gt;
the user is not permitted to see due to flag settings.&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
int feature_int(enum Feature feat);&lt;br /&gt;
&lt;br /&gt;
To retrieve the values of integer features, call this function.&lt;br /&gt;
Calling this function on a different type of feature, such as a &amp;quot;BOOL&amp;quot;&lt;br /&gt;
feature, will result in an assertion failure.&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
int feature_bool(enum Feature feat);&lt;br /&gt;
&lt;br /&gt;
This function is the complement of feature_int() for features of type&lt;br /&gt;
&amp;quot;BOOL.&amp;quot;&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;function&amp;gt;&lt;br /&gt;
const char *feature_str(enum Feature feat);&lt;br /&gt;
&lt;br /&gt;
Use this function to retrieve strings values for features of type&lt;br /&gt;
&amp;quot;STR&amp;quot;; you may not modify nor free the string value.&lt;br /&gt;
&amp;lt;/function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;macro&amp;gt;&lt;br /&gt;
#define F_N(type, flags, set, reset, get, notify, unmark, mark, report)&lt;br /&gt;
&lt;br /&gt;
This macro is used in the features[] table to simplify defining a&lt;br /&gt;
feature of type &amp;quot;NONE.&amp;quot;  The _type_ parameter is the name of the&lt;br /&gt;
feature excluding the &amp;quot;FEAT_&amp;quot; prefix, and MUST NOT be in&lt;br /&gt;
double-quotes.  The _flags_ parameter may be 0, FEAT_OPER, or&lt;br /&gt;
FEAT_MYOPER--the bitwise OR of these two flags is permissible but&lt;br /&gt;
would not make sense.  The rest of the arguments are pointers to&lt;br /&gt;
functions implementing the named call-back.&lt;br /&gt;
&amp;lt;/macro&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;macro&amp;gt;&lt;br /&gt;
#define F_I(type, flags, v_int, notify)&lt;br /&gt;
&lt;br /&gt;
To define integer features, use the F_I() macro.  The _type_ and&lt;br /&gt;
_flags_ parameters are as for F_N(), and the _v_int_ parameter&lt;br /&gt;
specifies the default value of the feature.  The _notify_ parameter,&lt;br /&gt;
if non-zero, will be called whenever the value of the feature changes.&lt;br /&gt;
&amp;lt;/macro&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;macro&amp;gt;&lt;br /&gt;
#define F_B(type, flags, v_int, notify)&lt;br /&gt;
&lt;br /&gt;
This macro is used for defining features of type &amp;quot;BOOL&amp;quot;; it is very&lt;br /&gt;
similar to F_I(), but _v_int_ should either 0 (for a &amp;quot;FALSE&amp;quot; value) or&lt;br /&gt;
1 (for a &amp;quot;TRUE&amp;quot; value).  The _notify_ parameter, if non-zero, will be&lt;br /&gt;
called whenever the value of the feature changes.&lt;br /&gt;
&amp;lt;/macro&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;macro&amp;gt;&lt;br /&gt;
#define F_S(type, flags, v_str, notify)&lt;br /&gt;
&lt;br /&gt;
Also similar to F_I(), F_S() defines features of type &amp;quot;STR.&amp;quot;  The&lt;br /&gt;
_flags_ argument may be the bitwise OR of one of FEAT_OPER or&lt;br /&gt;
FEAT_MYOPER with the special string flags FEAT_NULL and FEAT_CASE,&lt;br /&gt;
which are described above in the section &amp;quot;Feature Flags.&amp;quot;  The&lt;br /&gt;
_notify_ parameter, if non-zero, will be called whenever the value of&lt;br /&gt;
the feature changes.  Note that FEAT_NULL *must* be set if the default&lt;br /&gt;
string _v_str_ is set to NULL.&lt;br /&gt;
&amp;lt;/macro&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;authors&amp;gt;&lt;br /&gt;
Kev &amp;lt;klmitch@mit.edu&amp;gt;&lt;br /&gt;
&amp;lt;/authors&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;changelog&amp;gt;&lt;br /&gt;
[2001-06-13 Kev] Mention notify with the other callbacks&lt;br /&gt;
&lt;br /&gt;
[2001-01-02 Kev] Add documentation for new flags and for the notify&lt;br /&gt;
mechanism&lt;br /&gt;
&lt;br /&gt;
[2000-12-18 Kev] Document the features API&lt;br /&gt;
&amp;lt;/changelog&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:IRCu API|Features]]&lt;/div&gt;</description>
			<pubDate>Fri, 25 Apr 2008 03:59:55 GMT</pubDate>			<dc:creator>Secretagent</dc:creator>			<comments>http://wiki.darenet.org/Talk:ircu_api_-_features</comments>		</item>
	</channel>
</rss>