<remark>At the request of the author, changed the status of this document to Deferred pending development of an implementation; also changed the type to Informational.</remark>
<p>Traditionally, the &jabberd; server included an internal server module called "mod_filter", which provided a packet filtering facility for users. That service had the following problems:</p>
<ul>
<li>The service and protocol were undocumented, apart from some documentation reverse-engineered from the source code.</li>
<li>The processing requirements that the service required made it unusable for large installations.</li>
<li>Bugs in the service often caused the Jabber server to crash.</li>
<p>The most common use for this service was to provide server-side blacklists. Unforuntately, mod_filter was overpowered even by this relatively simple form of packet filtering (matching the sending JID and dropping the packet if necessary), so this need has been neatly filled by &xep0016;.</p>
<p>However, packet filtering (as opposed to the subset of JID blacklisting) is still of use, for the following tasks:</p>
<ul>
<li>Setting up automatic responses to messages (e.g., "vacation" messages).</li>
<li>Redirecting packets to another JID.</li>
<li>Modifying the contents of a packet in-transit (e.g., language translation, adding <x/> data).</li>
<li>Force incoming messages to be stored offline (e.g., for low-bandwidth clients).</li>
</ul>
<p>This document proposes a modular, extensible framework for specifying packet filtering rules. This document does not, however, propose any specific filter conditions or actions - that is left to other proposals.</p>
<p>The framework itself operates in the "http://jabber.org/protocol/filter" namespace.</p>
<section2topic='Definitions'>
<p>The following definitions are used throughout this document:</p>
<ul>
<li>ruleset - a set of filtering rules.</li>
<li>rule - a set of conditions with an associated action.</li>
<li>condition - an expression (or set of expressions) that, when applied to a packet, is either true or false.</li>
<li>action - a task that may be performed on a packet.</li>
</ul>
</section2>
</section1>
<section1topic='Structure'>
<p>A single rule is be expressed in XML like so:</p>
<examplecaption='XML representation of a rule'><![CDATA[
<ruledescription='natural-language description of rule'>
<condition>[conditionexpr]</condition>
<action>[actionspec]</action>
</rule>
]]></example>
<p>A rule is processed by applying its condition to the packet. If the condition is true, then the action is taken. The "description" attribute is provided so a rule generator can assign a meaningful and user-readable description of a rule.</p>
<p>A ruleset is be expressed in XML like so:</p>
<examplecaption='XML representation of a ruleset'><![CDATA[
<p>A ruleset is processed by applying each rule to the packet, one at a time. Processing of the ruleset stops after the first matching rule is found and its action taken, <em>unless</em> the "continue" attribute is found on the matched rule, in which case the remaining rules get processed as though the current rule did not match. If no rules match, packet processing continues as though no rules were specified.</p>
<p>A filter module is a document that defines conditions and/or actions that can be use by this framework. Each module should have its own namespace, and should clearly define the effect of each condition and action it defines.</p>
<p>Consider a hypothetical module that defines conditions that match packets based on their header information. It might use the namespace "http://jabber.org/protocol/filter/header" and might define the following conditions:</p>
<ul>
<li><to/> - true when the CDATA of this element matches the "to" attribute of the packet.</li>
<li><from/> - true when the CDATA of this element matches the "from" attribute of the packet.</li>
<li><type/> - true when the CDATA of this element matches the "type" attribute of the packet.</li>
</ul>
<p>Equally, consider a hypothetical module that defines actions for redirecting messages. It might use the namespace "http://jabber.org/protocol/filter/redirect" and might define the following conditions:</p>
<ul>
<li><redirect/> - redirects the packet to the JID specified in the CDATA of this element.</li>
<li><copy/> - sends a copy of the packet to the JID specified in the CDATA of this element, while giving the original packet to the user.</li>
</ul>
<p>These two modules might be combined to produce a ruleset like the following:</p>
<examplecaption='Using modules in a ruleset'><![CDATA[
<ruleset>
<ruledescription='Send messages from my friend to my home account to be dealt with later'>
<p>Using modules in this way enables this framework to be easily extended to support new types of filtering, as well as enabling site administrators to select the types of functionallity that are best suited to their site.</p>
</section1>
<section1topic='Protocol'>
<p>It will not always be appropriate for a service to provide a Jabber-based interface to its filter settings (e.g., in the case of an XML router, it will almost always be more appropriate to limit the specification of rules and rulesets to the router configuration). However, this will be appropriate sometimes (e.g., a session manager providing per-user packet filtering). In these cases, the following protocol should be used.
</p>
<section2topic='Module discovery'>
<p>An entity may find out if a service supports filtering, and the modules its supports, by issuing a discovery request to the service:</p>