NAME
plumb – format of plumb messages and rules |
SYNOPSIS
#include <plumb.h> |
DESCRIPTION
Message format
All fields are optional, but type should usually be set since
it describes the form of the data, and ndata must be an accurate
count (possibly zero) of the number of bytes of data. A missing
field is represented by an empty line. Plumbing rules The file is a sequence of rule sets, each of which is a set of one–line rules called patterns and actions. There must be at least one pattern and one action in each rule set. (The only exception is that a rule set may contain nothing but plumb to rules; such a rule set declares the named ports but has no other effect.) A blank line terminates a rule set. Lines beginning with a # character are commentary and are regarded as blank lines.
A line of the form
When a message is received by the plumber, the rule sets are examined in order. For each rule set, if the message matches all the patterns in the rule set, the actions associated with the rule set are triggered to dispose of the message. If a rule set is triggered, the rest are ignored for this message. If none is triggered, the message is discarded (giving a write error to the sender) unless it has a dst field that specifies an existing port, in which case the message is emitted, unchanged, from there. Patterns and actions all consist of three components: an object, a verb, and arguments. These are separated by white space on the line. The arguments may contain quoted strings and variable substitutions, described below, and in some cases contain multiple words. The object and verb are single words from a pre– defined set. The object in a pattern is the name of an element of the message, such as src or data, or the special case arg, which refers to the argument component of the current rule. The object in an action is always the word plumb.
The verbs in the pattern rules describe how the objects and arguments
are to be interpreted. Within a rule set, the patterns are evaluated
in sequence; if one fails, the rule set fails. Some verbs are
predicates that check properties of the message; others rewrite
components of the message and implicitly always succeed.
Such rewritings are permanent, so rules that specify them should
be placed after all pattern–matching rules in the rule set.
When the message has a click attribute, the data matches rules
extract the longest leftmost match to the regular expression that
contains or abuts the textual location identified by the click.
For a sequence of such rules within a given rule set, each regular
expression, evaluated by this specification, must
match the same subset of the data for the rule set to match the
message. For example, here is a pair of patterns that identify
a message whose data contains the name of an existing file with
a conventional ending for an encoded picture file:
If a click attribute is specified in a message, it will be deleted by the plumber before sending the message if the data matches rules expand the selection.
The action rules all have the object plumb. There are only three
verbs for action rules:
|
EXAMPLE
The following is a modest, representative file of plumbing rules. # these are generally in order from most specific to least, # since first rule that fires wins. addr=':(#?[0–9]+):?' protocol='(https?|ftp|file|gopher|mailto|news|nntp|telnet|wais)' domain='[a–zA–Z0–9_@]+([.:][a–zA–Z0–9_@]+)*/?[a–zA–Z0–9_?,%#~&/\–]+' file='([:.][a–zA–Z0–9_?,%#~&/\–]+)*' # image files go to page type is text data matches '[a–zA–Z0–9_\–./]+' data matches '([a–zA–Z0–9_\–./]+).(jpe?g|gif|bit)' arg isfile $0 plumb to image plumb start page –w $file # URLs go to web browser type is text data matches $protocol://$domain$file plumb to web plumb start window webbrowser $0 # existing files, possibly tagged by line number, go to edit/sam type is text data matches '([.a–zA–Z0–9_/–]+[a–zA–Z0–9_/\–])('$addr')?' arg isfile $1 data set $file attr add addr=$3 plumb to edit plumb start window sam $file # .h files are looked up in /sys/include and passed to edit/sam type is text data matches '([a–zA–Z0–9]+\.h)('$addr')?' arg isfile /sys/include/$1 data set $file attr add addr=$3 plumb to edit plumb start window sam $file
The following simple plumbing rules file is a good beginning set
of rules. |
FILES
/usr/$user/lib/plumbing default rules file. /mnt/plumb mount point for plumber(4). /sys/lib/plumb directory for include files. /sys/lib/plumb/fileaddr public macro definitions. /sys/lib/plumb/basic basic rule set. |
SEE ALSO
plumb(1), plumb(2), plumber(4), regexp(6) |