Log in | Back to darenet.org

ircd/api/features

(Created page with '== Overview == As of u2.10.11 (which what ircd-darenet 1.x is based upon), most of the compile-time configuration options present in previous versions of ircu have been provided…')
Line 4: Line 4:
In the <code>ircd_features.h</code> header file is an <code>enum Feature</code> that lists all the features known to the features subsystem. The order of the entries in this list must match precisely the order of the features as listed in the <code>features[]</code> table in <code>ircd_features.c</code>. There are four kinds of features, seven different flags that can be set for features, and seven different call-backs for more complex features.
In the <code>ircd_features.h</code> header file is an <code>enum Feature</code> that lists all the features known to the features subsystem. The order of the entries in this list must match precisely the order of the features as listed in the <code>features[]</code> table in <code>ircd_features.c</code>. There are four kinds of features, seven different flags that can be set for features, and seven different call-backs for more complex features.
 +
 +
== Types of Features ==
 +
 +
There are at present four different types of features: NONE, INT, BOOL, and STR. Features of type "NONE" are complex features, such as the logging subsystem, that have complicated behavior that's managed through the use of call-backs. The call-backs available are set, which is called to set the value of the feature; reset, which is called to reset the value of the feature back to its default; get, which is called to send the user a <code>RPL_FEATURE</code> to describe the feature setting; unmark, which is called prior to reading the configuration file; mark, which is called after reading the configuration file; and report, which is used to send a user a list of <code>RPL_STATSFLINE</code> replies.
 +
 +
In comparison to type "NONE," the other types are very simple. Type "INT" is used for features that take an integer value; "BOOL" is for those features that are boolean types; and "STR" is for those features that take simple string values. The values for these feature types are handled directly by the features subsystem, and can be examined from code with the <code>feature_int()</code>, <code>feature_bool()</code>, and <code>feature_str()</code> functions, described below. These features have a notify callback, which is used to warn subsystems that use the values of particular features that the value has changed.
 +
 +
== Feature Flags ==
 +
 +
There are seven feature flags, one of which is used internally by the feature subsystem. Three of these flags, <code>FEAT_OPER</code>, <code>FEAT_MYOPER</code>, and <code>FEAT_NODISP</code>, are used to select who can see the settings of those features; <code>FEAT_OPER</code> permits any operator anywhere on the network to examine the settings of a particular feature, whereas <code>FEAT_MYOPER</code> only permits operators local to a server to examine feature values, and <code>FEAT_NODISP</code> prohibits display of the feature value altogether. If none of these three flags are specified, then any user may examine that feature's value.
 +
 +
Two other flags only have any meaning for string values; they are <code>FEAT_NULL</code>, which is used to specify that a feature of type "STR" may have a <code>NULL</code> value, and <code>FEAT_CASE</code>, which specifies that the feature is case sensitive -- this may be used on file names, for example. Note that if you give "0" as the default value for a feature, you must also set the <code>FEAT_NULL</code> flag.
 +
 +
The remaining non-internal flag is <code>FEAT_READ</code>, which simply sets the feature to be read-only; a feature so marked may only be changed through the configuration file.
 +
 +
== Marking Features ==
 +
 +
When the configuration file is read, there must be some way to determine if a particular feature (key/value pair) has been removed since the last time the configuration file was read. The way this is done in the features subsystem is to have a "mark" for each feature. Prior to reading the configuration file, all marks are cleared for all features (and all "unmark" call-backs are called). As each feature (key/value pair) is encountered and processed, that feature's mark is set. Finally, when the configuration file has been fully read, all remaining unmarked features are reset to their default values (and all "mark" call-backs are called).
 +
 +
== Adding New Features ==
 +
 +
To add a new feature, first determine the feature's name (which must begin with the string "FEAT_") and its type ("NONE," "INT," "BOOL," or "STR").  Then add the feature to the <code>enum Feature</code> in an appropriate place (i.e., it's good to group all features affecting operators separate from those features affecting networking code), and a corresponding entry in the <code>features[]</code> table in <code>ircd_features.c</code>. It will be best to use one of the F_?() macros, which are documented below. Then, whenever you need to refer to the value of a specific feature, call the appropriate feature_<type>() function, as documented below.

Revision as of 15:27, 13 July 2010

In This Guide:

Overview

As of u2.10.11 (which what ircd-darenet 1.x is based upon), most of the compile-time configuration options present in previous versions of ircu have been provided via the configuration file as "features." This document is intended not only to give an explanation of how to use the features subsystem in new code, but also how to define new features.

In the ircd_features.h header file is an enum Feature that lists all the features known to the features subsystem. The order of the entries in this list must match precisely the order of the features as listed in the features[] table in ircd_features.c. There are four kinds of features, seven different flags that can be set for features, and seven different call-backs for more complex features.

Types of Features

There are at present four different types of features: NONE, INT, BOOL, and STR. Features of type "NONE" are complex features, such as the logging subsystem, that have complicated behavior that's managed through the use of call-backs. The call-backs available are set, which is called to set the value of the feature; reset, which is called to reset the value of the feature back to its default; get, which is called to send the user a RPL_FEATURE to describe the feature setting; unmark, which is called prior to reading the configuration file; mark, which is called after reading the configuration file; and report, which is used to send a user a list of RPL_STATSFLINE replies.

In comparison to type "NONE," the other types are very simple. Type "INT" is used for features that take an integer value; "BOOL" is for those features that are boolean types; and "STR" is for those features that take simple string values. The values for these feature types are handled directly by the features subsystem, and can be examined from code with the feature_int(), feature_bool(), and feature_str() functions, described below. These features have a notify callback, which is used to warn subsystems that use the values of particular features that the value has changed.

Feature Flags

There are seven feature flags, one of which is used internally by the feature subsystem. Three of these flags, FEAT_OPER, FEAT_MYOPER, and FEAT_NODISP, are used to select who can see the settings of those features; FEAT_OPER permits any operator anywhere on the network to examine the settings of a particular feature, whereas FEAT_MYOPER only permits operators local to a server to examine feature values, and FEAT_NODISP prohibits display of the feature value altogether. If none of these three flags are specified, then any user may examine that feature's value.

Two other flags only have any meaning for string values; they are FEAT_NULL, which is used to specify that a feature of type "STR" may have a NULL value, and FEAT_CASE, which specifies that the feature is case sensitive -- this may be used on file names, for example. Note that if you give "0" as the default value for a feature, you must also set the FEAT_NULL flag.

The remaining non-internal flag is FEAT_READ, which simply sets the feature to be read-only; a feature so marked may only be changed through the configuration file.

Marking Features

When the configuration file is read, there must be some way to determine if a particular feature (key/value pair) has been removed since the last time the configuration file was read. The way this is done in the features subsystem is to have a "mark" for each feature. Prior to reading the configuration file, all marks are cleared for all features (and all "unmark" call-backs are called). As each feature (key/value pair) is encountered and processed, that feature's mark is set. Finally, when the configuration file has been fully read, all remaining unmarked features are reset to their default values (and all "mark" call-backs are called).

Adding New Features

To add a new feature, first determine the feature's name (which must begin with the string "FEAT_") and its type ("NONE," "INT," "BOOL," or "STR"). Then add the feature to the enum Feature in an appropriate place (i.e., it's good to group all features affecting operators separate from those features affecting networking code), and a corresponding entry in the features[] table in ircd_features.c. It will be best to use one of the F_?() macros, which are documented below. Then, whenever you need to refer to the value of a specific feature, call the appropriate feature_<type>() function, as documented below.