Mapping entry templates

From Messaging Server Technical Reference Wiki
Jump to: navigation, search

If the comparison of the pattern in a given mapping entry fails, no action is taken; the scan proceeds to the next entry. If the comparison succeeds, the right hand side of the entry is used as a template to produce an output string. The template effectively causes the replacement of the input string with the output string that is constructed from the instructions given by the template.

Almost all characters in the template simply produce themselves in the output. The one exception is a dollar sign.

A dollar sign followed by a dollar sign, space, or tab produces a dollar sign, space, or tab in the output string. Note that all these characters must be quoted in order to be inserted into the output string.

A dollar sign followed by a digit n calls for a substitution; a dollar sign followed by an alphabetic character is referred to as a "metacharacter". Metacharacters themselves will not appear in the output string produced by a template. See the table below for a list of the special substitution and standard processing metacharacters. Any other metacharacters are reserved for mapping-specific applications.

Note that any of the metacharacters $C, $E, $L, or $R, when present in the template of a matching pattern, will influence the mapping process, controlling whether it terminates or continues. That is, it is possible to set up iterative mapping table entries, where the output of one entry becomes the input of another entry. If the template of a matching pattern does not contain any of the metacharacters $C, $E, $L, or $R, then $E (immediate termination of the mapping process) is assumed.

The number of iterative passes through a mapping table is limited to prevent infinite loops. A counter is incremented each time a pass is restarted with a pattern that is the same length or longer than the previous pass. If the string has a shorter length than previously, the counter is reset to zero. A request to again iterate a mapping is not honored after the counter has exceeded 10.

Mapping template substitutions and metacharacters
Substitution sequence Substitutes
$n nth wildcarded field as counted from left to right starting from 0
$%...% (New in MS 6.2.) Substitute in a load average value.
$#...# Sequence number substitution.
$+n#...# Hash substitution.
$&...& (New in MS 6.2.) Character value substitution.
$]...[ LDAP search URL lookup; substitute in result (first value, if multiple values returned).
$]$]...[ LDAP search URL lookup requiring that only one value be returned; substitute in result.
$.text. (New in MS 6.3.) Result to use in the case of LDAP lookup temporary failures.
$}...{ LDAP domain map attribute lookup; substitute in attribute value.
${...} General database substitution.
$|...| Apply specified mapping table to supplied string.
$+n|...| Apply specified mapping table to supplied string with one or more prefixes specified by the bit-encoded value n.
$`...' Evaluate expression; substitute in result.
$[...] Invoke site-supplied routine; substitute in result.
Metacharacter Description
$C Continue the mapping process starting with the next table entry; use the output string of this entry as the new input string for the mapping process.
$E End the mapping process now; use the output string from this entry as the final result of the mapping process.
$+1E (New in MS 6.3.) End the mapping process now and (unlike $E) do not even interpret the rest of the template; use the output string from this entry (sans interpretation of the rest of the template) as the final result of the mapping process.
$L Continue the mapping process starting with the next table entry; use the output string of this entry as the new input string; after all entries in the table are exhausted make one additional pass starting with the first table entry. A subsequent match may override this condition with a $C, $E, or $R metacharacter.
$R Continue the mapping process starting with the first entry of the mapping table; use the output string of this entry as the new input string for the mapping process.
$+1R New in MS 8.0.2.2. Continue the mapping process by repeating the current entry of the mapping table; use the output string of this entry as the new input string for the mapping process.
$?x? Mapping entry succeeds x percent of the time.
$?a,b,c...? Select a random value from a list of values. New in MS 8.0.2.3
$\ Force subsequent text to lowercase.
$^ Force subsequent text to uppercase.
$_ Leave subsequent text in its original case (and without LDAP URL style quoting).
$= Force subsequent material to be properly quoted (encoded) according to LDAP URL syntax rules.
$:x Match only if the specified flag is set.
$;x Match only if the specified flag is clear.

Wildcard field substitutions, $n

A dollar sign followed by a digit n is replaced with the material that matched the nth wildcard in the pattern. The wildcards are numbered starting with 0. For example, the entry


  PSI$%*::*    $1@$0.psi.network.org

would match the input string PSI%A::B and produce the resultant output string b@a.psi.network.org. The input string PSI%1234::USER would also match producing USER@1234.psi.network.org as the output string. The input string PSIABC::DEF would not match the pattern in this entry and no action would be taken; i.e., no output string would result from this entry.

Controlling text case, $\, $^, $_

$\forces subsequent text to lowercase, $^ forces subsequent text to uppercase, and $_ causes subsequent text to retain its original case (and turns off LDAP URL quoting if it had been previously turned on via the $= metacharacter. For instance, these metacharacters may be useful when using mappings to transform addresses for which case is significant.

Processing control, $C, $L, $R, $+1R, $E, $+1E

The $C, $L, $R, and $E metacharacters influence the mapping process, controlling whether and when the mapping process terminates. $C causes the mapping process to continue with the next entry, using the output string of the current entry as the new input string for the mapping process. $L causes the mapping process to continue with the next entry, using the output string of the current entry as the new input string for the mapping process, and, if no matching entry is found, making one additional pass through the table starting with the first table entry; a subsequent matching entry with a $C, $E, or $R metacharacter overrides this condition. $R causes the mapping process to continue from the first entry of the table, using the output string of the current entry as the new input string for the mapping process. $E causes the mapping process to terminate; the output string of this entry is the final output. $E is the default.

New in MS 6.3 is the $+1E metacharacter. It acts like $E, except that unlike $E it inhibits (stops) interpretation of the rest of the template.

New in MS 8.0.2.2, the $+1R provides a variant of $R: Rather than restarting the entire mapping from the first entry, it repeats the current entry with updated output from the current operation.

The $+1R is useful in constructing mappings that perform multiple replacements of all occurrences of one string with another where some of the strings overlap. A single operation of this sort can be done with $R; for example, replacing all percent signs with at-signs can be done with:


PERCENT_TO_AT

   *%*          $R$0@$1
   *            $0$Y

But when multiple replacements are involved restarting the mapping from the beginning is inefficient. And if the strings being replaced overlap restarting from the beginning won't work because the earlier, completed operations will see the later replacements and get confused. For this to work repeating the same entry until it no longer matches is required.

For example, the following mapping performs the quoting necessary for a string being inserted into an LDAP DN:


DN_QUOTE

  *\*         $+1R$0~$1
  *~*         $+1R$0\5c$1
  #*          $C\23$0
  *"*         $+1R$0\22$1
  *+*         $+1R$0\2b$1
  *,*         $+1R$0\2c$1
  *;*         $+1R$0\3b$1
  *<*         $+1R$0\3c$1
  *>*         $+1R$0\3e$1
  *           $0$Y

Note that if $R was used that the inital entry would damage the later replacement operations.

Mapping table templates are scanned left to right. So to set a $C, $L, or $R flag for entries that may "succeed" or "fail", e.g., general database substitutions, or random value controlled entries, put the $C, $L, or $R metacharacter to the left of the part of the entry that may succeed or fail; otherwise, if the remainder of the entry fails, the flag will not be seen.

Check for special flags

Some mapping probes have special flags set. $:x causes an entry to match only if the flag x is set. $;x causes an entry to match only if the flag x is clear. See specific mapping table descriptions for any special flags that may apply for that table.

When the intention is that an entry should succeed and terminate if the flag check succeeds, but that the mapping process should continue if the flag check fails, then the entry should use the $C metacharacter to the left of the flag check and use the $E metacharacter to the right of the flag check.

Entry randomly succeeds or fails, $?x?

A $?x? sequence in a mapping table entry causes the entry to "succeed" x percent of the time; the rest of the time, the entry "fails" and the output of the mapping entry's input is taken unchanged as the output. (Note that, depending upon the mapping, the effect of the entry "failing" is not necessarily the same as the entry not matching in the first place.) The argument between the ?'s, x, should consist of a real number specifying the success percentage.

For instance, suppose that a system with IP address 123.45.6.78 is sending your site just a little too much e-mail and you'd like to slow it down; if you're using the MTA's SMTP server on port 25, you can use a PORT_ACCESS mapping table in the following way. Suppose you'd like to allow through only 25 percent of its connection attempts and temporarily reject the other 75 percent of its connection attempts. The following PORT_ACCESS mapping table uses $?25? to cause the entry with the $Y (accept the connection) to succeed only 25 percent of the time; the other 75 percent of the time, when this entry fails, the initial $C on that entry causes the MTA to continue the mapping from the next entry, which causes the connection attempt to be rejected with a temporary SMTP error (in this example, 452 4.4.0) and the text message "Try again later".


PORT_ACCESS

  TCP|*|25|123.45.6.78|*     $C$?25?$Y
  TCP|*|25|123.45.6.78|*     $N452$ 4.4.0$ Try$ again$ later

Another example would be randomly issuing a temporary failure message for a certain percentage of SMTP messages from a particular envelope From address; for instance, suppose the goal is to issue a temporary failure message with extended SMTP code 4.5.9 to eighty percent of the messages that busybee@some.where attempts to send to your local channel users. Then a SEND_ACCESS mapping table could be used, e.g.,


SEND_ACCESS

  tcp_*|busybee@some.where|l|*    $C$?20?$Y
  tcp_*|busybee@some.where|l|*    $N$X4.5.9|Try$ again$ later

Load average substitutions, #%...%

At the present time load average substitutions are not implemented.

Select random entry from list, $?a,b,c...?

As of MS 8.0.2.3, a $?a,b,c,...? sequence consisting of two or more comma-separated string values in a mapping table entry causes one of the string values to be selected at random and retained in the output.

Sequence number substitutions, $#...#

A $#...# substitution increments the value stored in an MTA sequence file and substitutes that value into the template. This can be used to generate unique, increasing strings in cases where it is desirable to have a uniquifier in the mapping table output; for instance, when using a mapping table to generate file names.

Permitted syntax is any one of:


$#seq-file-spec#

or


$#seq-file-spec|radix#

or


$#seq-file-spec|radix|width#

or (new in MS 6.1)


$#seq-file-spec|radix|width|modulus#

where the optional seq-file-spec argument is a full file specification for an (already existing) MTA sequence file, and where the optional radix, width, and modulus arguments specify the radix (base) in which to output the sequence value, the number of digits to output, and the modulus, respectively. The seq-file-spec argument may be omitted, in which case the MTA will use its own temporary sequence file (that will be created and used for the duration of this image). The default radix is 10. Radices in the range -36 to 36 are also allowed; for instance, base 36 gives values expressed with digits 0,...,9,A,...,Z. By default, the sequence value is printed in its natural width, but if the specified width calls for a greater number of digits, then the output will be padded with 0's on the left to obtain the desired number of digits. Note that if a width is explicitly specified, then the radix must be explicitly specified also. If a modulus is specified, then the value inserted is the sequence number retrieved from the file mod the modulus; the default (and the only behavior available prior to MS 6.1) is not to perform any modulus operation.

As noted above, when specifying an explicit sequence file in a mapping, that file must already exist. To create a proper sequence file, on UNIX use the command:


% touch seq-file-spec

or


% cat >seq-file-spec

A sequence number file accessed via a mapping table must be world readable in order to operate properly. (In particular, the noprivuser user id, as specified in the restricted.cnf file,is used to access the file.)

Hash substitutions, $+n#...#

(New in 7.4-18.01.)

A $+n#...# substitution, n > 0, computes a hash of a specified string and inserts the hash result into the mapping result. The value n selects the type of hash to compute.

Permitted syntax is any one of:


$+n#string#

or


$+n#string|radix#

or


$+n#string|radix|width#
 

$+n#string|radix|width|modulus#

where the string argument is the string to be hashed, and where the optional radix, width, and modulus arguments specify the radix (base) in which to output the hash value, the number of digits to output, and the modulus, respectively. The default radix is 10. Radices in the range -36 to 36 are also allowed; for instance, base 36 gives values expressed with digits 0,...,9,A,...,Z. By default, the sequence value is printed in its natural width, but if the specified width calls for a greater number of digits, then the output will be padded with 0's on the left to obtain the desired number of digits. Note that if a width is explicitly specified, then the radix must be explicitly specified also. If a modulus is specified, then the value inserted is the sequence number retrieved from the file mod the modulus; the default is not to perform any modulus operation on the hash value.

As noted above, the value of n selects the hash operation to perform. Currently the only supported value for n is 1, which employs the following hash function (32 bit integers are assumed):


int hashvalue(char *string, int length)
{
    unsigned int hash;
    int i, j;
    unsigned int *uptr;

    uptr = (unsigned int *)string;
    hash = length;
    j = length >> 2;
    for (i = 0; i < j; i++)
    {
        hash ^= *uptr++;
        hash = (hash << 9) | (hash >> 23);
    }
    for (i = j << 2; i < length; i++)
    {
        hash ^= string[i];
        hash = (hash << 13) | (hash >> 19);
    }
    return ((hash * 0x71279461U) >> 2);
}

Character value substitutions, $&...&

(New in MS 6.2.) The MTA can generate UTF-8 strings from Unicode character values using the $&...& substitution sequence. Multiple Unicode character values may be specified, by separating them with the comma character. For instance, substitution sequence of the form:


$&A0A0,20,A1A1&

will produce a UTF-8 string containing the characters at position A0A0, 20, and A1A1.

LDAP query URL substitutions, $]...[, $]$]...[, $=, $.

A substitution of the form $]ldap-url[ or $]$]ldap-url[ is handled specially. ldap-url is interpreted as an LDAP query URL and the result of the LDAP query is substituted. The difference between the two forms is that in the case of a multi-valued result, $]ldap-url[ uses the "first" returned value (note that the LDAP protocol leaves the order of values returned as unspecified and implementation-dependent -- thus you must not make any assumptions about which value might be returned "first"), whereas a multi-valued response is an error (the lookup is considered to have failed) for $]$]ldap-url[.

Standard LDAP URLs as per RFC 2255 are used, with the host and port typically omitted. (In versions prior to 7.4-18.01, the host and port had to be omitted; as of version 7.4-18.01, specifying the LDAP host and port in the URL is permissable.) If the host and port are omitted, they are assumed from the values of the ldap_host and ldap_port MTA options (or the ugldaphost and ugldapport base options, if the MTA options are not set, corresponding to the legacy configutil parameters local.ugldaphost and local.ugldapport). That is, the LDAP URL should be specified as:


ldap:///dn[?attributes[?scope?filter]]

or


ldap://host[:port]/dn[?attributes[?scope?filter]]

where the square bracket characters [ and ] shown above indicate optional portions of the URL. The dn is required and is a distinguished name specifying the search base. The optional attributes, scope, and filter portions of the URL further refine what information to return. That is, attributes specifies the attribute or attributes to be returned from LDAP directory entries matching this LDAP query. The scope may be any of base (the default), one, or sub. filter describes the characteristics of matching entries.

As of Messaging Server 7.2-7.02, so-called external LDAP (extldap:) URLs are also supported. (As of the Messaging Server 7.0u4 support for explicit host and port specification directly in the LDAP URL, this functionality is somewhat redundant. But it may still be useful when a particular external directory, and perhaps one with different authentication credentials needed for access, is used.) That is, if a URL is specified as


extldap:///dn[?attributes[?scope?filter]]

then an LDAP lookup will be performed against the alternate LDAP directory configured (via the LDAP external directory lookup MTA options) as the "external LDAP" directory.

Note that LDAP URLs have special character quoting (encoding) requirements. (See RFC 1738, Section 2.2, "URL Character Encoding Issues", and RFC 2254, Section 4, "String Search Filter Definition". Note that the quoting rules in RFC 1960, Section 3, "String Search Filter Definition", have been superceded by those of RFC 2254.) The $= metacharacter forces subsequent material to be properly quoted (encoded) for LDAP URL usage; that is, any of the characters


$ & + , : ; = ?

will be converted to the percent character, "%", followed by the hexadecimal representation of their location in US-ASCII, any of the characters


( ) *

will be converted to %5C" followed by the hexadecimal representation of their location in US-ASCII (the encoded form of the backslash character followed by the hexadecimal for the particular character), while the backslash character itself


\

will be converted to %5C5C".

The $_ metacharacter disables such LDAP quoting.

So note that when using a $]...[ LDAP URL callout, one should normally use the $= and $_ metacharacters around and substituted material that might contain special characters, and manually encode any fixed special characters in the material in the callout, or use just the $= and $_ metacharacters around the entire interior of the LDAP URL body, e.g.,


$]ldap:///$=...$_[

The overall length of the LDAP URL (after any substitutions are performed) is limited to 252 characters in iMS 5.2, limited to 256 characters in MS 6.0 through MS 6.2, and limited to 1024 characters as of MS 6.3. Note also that the length of the original template in which such an LDAP URL appears is limited: to 252 characters in iMS 5.2 and earlier, or to 256 characters as of MS 6.0 and later; but substitutions in the template, and in particular substitutions used to construct the LDAP URL, may increase the LDAP URL length.

(New in MS 6.3.) The $.text. sequence can be used in a mapping entry to establish a string text which will be processed as the mapping entry result in the event of a temporary LDAP lookup failure. By default temporary LDAP failures cause the current mapping entry to fail, which is is problematic in cases where different actions need to be taken depending on whether the LDAP lookup failed versus the directory server being unavailable or misconfigured. Once a failure string has been set using this construct, it will remain set until current mapping processing is completed. $.. can be used to return to the default state where no temporary failure string is set and temporary LDAP failures cause mapping entry failure. Note that all errors other than failure to match an entry in the directory are considered to be temporary errors; in general it isn't possible to distinguish between errors caused by incorrect LDAP URLs and errors caused by directory server configuration problems.

LDAP domain map attribute substitutions, $}...{

(New in MS 6.1p1/MS 6.2.) A substitution of the form $}domain-name,attribute{ is handled specially. domain-name is looked up in the directory as a domain, with domain map processing of the domain-name to build a proper LDAP query URL being automatically performed by the MTA. (In particular, in Schema 1 mode, the domain-name is looked up in the DC portion of the directory; while in Schema 2 mode, the domain-name is looked up using the Schema 2 domain filter.) Note that this argument domain-name truly is a domain name. If the domain domain-name exists and has the specified attribute, then the attribute's initial value is substituted into the mapping result; if either the attribute or the domain does not exist, then the mapping entry fails.

The following special syntaxes are also supported:

Domain map mapping template special syntaxes
Syntax Interpretation and effect
$}domain,_base_dn_{ Return the base DN for the user/group entries belonging to this domain
$}domain,_domain_dn_{ Return the DN of the domain entry itself
$}domain,_domain_name_{ Return the name of the domain (as opposed to an alias)
$}domain,_canonical_name_{ Return the canonical name associated with the domain

(New in 8.0.) A substitution of the form $}user-identifier,attribute{ is handled specially. user-identifier is looked up in the directory as a user name.

The following attributes can be specified:

User identifier mapping template attributes
Syntax Interpretation and effect
$}user-identifier,#canonical_user#{ Return the canonical form of user identifier
$}user-identifier,#canonical_domain#{ Return the canonical domain the user is associated with
$}user-identifier,#user_dn#{ Return the DN of the user's entry in the directory

(New in MS 8.0.2) A substitution of the form $}host,query{ is handled specially. host is treated as the name of a deployment map host.

The following queries can be specified:

Deployment map mapping queries
Syntax Interpretation and effect
$}host,/role/{ return role of the specified host; fail if host does not exist in the deployment map
$}host,/online/{ succeeds if the specified host exists and is online
$}host,/offline/{ succeeds if the specified host is offline or does not exist
$}user-identifier,/<n>/{ <n> must be an unsigned number - return the <n>th property value for the host; fail if host or specified property does not exist
$}user-identifier,/<p>/{ <p> must be a string not matching any previous sort of query - succeeds if the specified host has properity <p> associated with it, fails otherwise. <p> may contain glob-style wildcards. On success the value of the first retained wildcard will be returned if it exists.

General database substitutions, ${...}

A substitution of the form ${text} is handled specially. The text part is used as a key to access the MTA's general database. If text is found in the database, the corresponding template from the database is substituted. If text does not match an entry in the database, the input string is used unchanged as the output string.

Depending upon the setting of the use_text_databases MTA option, the general "database" is either stored and accessed as an on-disk database (the default), or as an in-memory structure constructed (during configuration compilation or MTA initialization) from an on-disk flat text file. Or new in MS 8.0, the general "database" can instead be stored in memcache; see the general_database_url MTA option. The on-disk database, if that is what is being used, is IMTA_DATAROOT:db/generaldb (which formerly could be redirected via the now-deleted imta_general_database MTA Tailor option), which must be generated using the imsimta crdb utility from some site-supplied source text file. If an in-memory database structure is instead being used, then when the MTA configuration is compiled (or at MTA process initialization time, if a compiled configuration is not in use) the MTA reads the file IMTA_TABLE:general.txt (which formerly could be redirected via the now-deleted imta_general_data MTA Tailor file option), and compiles it into an in-memory structure. Use of an in-memory "database" is normally recommended (for reasons of performance and reliability); however, do note that use of this in-memory "database" does require recompiling the configuration to get changes to the "database" (changes to the source text file) incorporated into the compiled configuration.

Note that when wishing to use processing control metacharacters such as $C, $R, or $L in a mapping table entry that does a general database substitution, the processing control metacharacter should be placed to the left of the general database substitution in the mapping table template; otherwise the "failure" of a general database substitution will mean that the processing control metacharacter will not be seen.

In some cases it may be useful to test to see if a given entry exists in the general database without substituting the corresponding template value from the database entry. This can be accomplished by creating a secondary mapping of the form:


GENERAL_EXISTS

   *                      $E${$0}$C
   *                      $Y

A mapping table substitution callout, described in the following section, with the general database key as the probe, will now succeed if and only if the corresponding entry is in the database, but will not return the corresponding template from the database entry.

Mapping table substitutions, $|...|

A substitution of the form $|mapping;argument| is handled specially. The MTA looks for an auxiliary mapping table named mapping in the mapping file, and uses argument as the input (probe) to that named auxiliary mapping table. The named auxiliary mapping table must exist and must set the $Y flag in its output if it is successful; if the named auxiliary mapping table does not exist or doesn't set the $Y flag, then that auxiliary mapping table substitution fails and the original mapping entry is considered to fail: the original input string will be used as the output string.

A substitution of the form $+n|mapping;argument|, where n is a non-zero bit-encoded value works in same way, except that one or more |-separated prefixes are added to the auxiliary mapping probe. The available prefixes are:

Auxiliary mapping probe prefixes
Bit Value Prefix
0 1 Transport information in the usual "TCP|server-address|server-port|client-address|client-port" format.
1 2 Application information.
2 4 Source channel (blank if no source channel is currently active).
3 8 Destination channel (blank if no destination channel is currently active).
4 16 Authenticated sender address (blank if no authenticated sender is currently active).

If multiple bits are enabled the corresponding prefixes are added in numerical order with the least significant bit on the left.

Note that prefixes required an enqueue context; they will be ignored in mapping calls where such a context is not available.

Note that when wishing to use processing control metacharacters such as $C, $R, or $L in a mapping table entry that does a mapping table substitution, the processing control metacharacter should be placed to the left of the mapping table substitution in the mapping table template; otherwise the "failure" of a mapping table substitution will mean that the processing control metacharacter will not be seen.

Mapping table substitutions have similarities to both subroutine calls and nesting of regular expressions using parentheses. The following recipient rate limit example illustrates the subroutine call aspect of mapping table substitutions by using a separate mapping table to remove any subaddress from an address so that subaddresses can't be used to avoid the limit.

A Metermaid throttle table with the following settings is used to implement a limit of 10 occurrence of a given recipient every 5 minutes:


msconfig> show metermaid.local_table:reclim
role.metermaid.local_table:reclim.data_type = string
role.metermaid.local_table:reclim.max_entries = 100000
role.metermaid.local_table:reclim.quota = 10
role.metermaid.local_table:reclim.quota_time = 300
role.metermaid.local_table:reclim.table_type = throttle

The following mapping removes any subaddress that's present in an address:


REMOVE_SUBADDRESS

  "$[a-z0-9.#$&'*\-/=?^_`{}\~]*+$_*"@*  $Y$0@$2
  "$_*+$_*"@*                           $Y"$0"@$2
  $_*+$_*@*                             $Y$0@$2
  *                                     $Y$0

And finally, the following callout rule added at the end of the ORIG_SEND_ACCESS mapping implements the limit:


tcp_*|*|*|* $C$;R$[IMTA_LIB:check_metermaid.so,throttle,reclim,$|REMOVE_SUBADDRESS;$3|]$X4.2.3|$NRate$ too$ high$E

Note the "$;R" (new in MS 8.0) prevents this rule from being applied to enqueues from "internal" channels (process channel, reprocess channel, conversions channel, etc.).

Expression substitutions, $`..'

In addition to basic arithmetic operations and tests listed in Operators in Order of Precedence, see Symbol table functions for a list of additional functions available for use in expressions. Note that mapping tables operate on strings; string arguments must be converted to integers (see for instance the integer function) before performing integer arithmetic on them, and conversely any arithmetic intermediate results must be converted back to strings (see for instance the string function) before being substituted back into mapping table entry templates.

Expression arithmetic can be used to manipulate IP addresses, which are a common component of many mapping probes. For example, the following mapping takes an IP address as input performs a general database lookup on successive subnets derived from the input address up to /8:


SUBNET_LOOKUP

  $D*.$D*.$D*.$D*    $C${$0.$1.$2.$3/32}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$2.$`$3>>1<<1'/31}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$2.$`$3>>2<<2'/30}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$2.$`$3>>3<<3'/29}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$2.$`$3>>4<<4'/28}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$2.$`$3>>5<<5'/27}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$2.$`$3>>6<<6'/26}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$2.$`$3>>7<<7'/25}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$2/24}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$`$2>>1<<1'/23}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$`$2>>2<<2'/22}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$`$2>>3<<3'/21}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$`$2>>4<<4'/20}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$`$2>>5<<5'/19}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$`$2>>6<<6'/18}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1.$`$2>>7<<7'/17}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$1/16}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$`$1>>1<<1'/15}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$`$1>>2<<2'/14}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$`$1>>3<<3'/13}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$`$1>>4<<4'/12}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$`$1>>5<<5'/11}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$`$1>>6<<6'/10}$Y$E
  $D*.$D*.$D*.$D*    $C${$0.$`$1>>7<<7'/9}$Y$E
  $D*.$D*.$D*.$D*    $C${$0/8}$Y$E

Mapping routine substitutions, $[...]

A substitution of the form $[image,routine,argument] is handled specially. The image,routine,argument part is used to find and call an Oracle-supplied or customer-supplied routine. At run-time on UNIX, the MTA uses dlopen and dlsym to dynamically load and call the routine routine from the shared library image. The routine routine is then called as a function with the following argument list:


status = routine (argument, arglength, result, reslength);

The argument and result arguments are 256 byte long character string buffers. On OpenVMS argument and result are passed by descriptor (a class S descriptor is used to ensure maximum compatibility); on Digital UNIX, Solaris, and NT, argument and result are passed as a pointer to a character string, (e.g., in C, as char*.) arglength and reslength are signed, 32 bit integers passed by reference. On input, argument contains the argument string from the mapping table template, and arglength the length of that string. On return, the resultant string should be placed in result and its length in reslength. This resultant string will then replace the "$[image,routine,argument]" in the mapping table template. The routine routine should return 0 if the mapping table substitution should fail and -1 if the mapping table substitution should succeed. If the substitution fails, then normally the original input string will be used unchanged as the output string.

Note that when wishing to use processing control metacharacters such as $C, $R, or $L in a mapping table entry that does a site-supplied routine substitution, the processing control metacharacter should be placed to the left of the site-supplied routine substitution in the mapping table template; otherwise the "failure" of a mapping table substitution will mean that the processing control metacharacter will not be seen.

The site-supplied routine callout mechanism allows the MTA's mapping process to be extended in all sorts of complex ways. For example, in a PORT_ACCESS or SEND_ACCESS mapping table, a call to some type of load monitoring service could be performed and the result used to decide whether or not to accept a connection or message.

See the dns_verify callouts, the check_memcache.so callout, and check_metermaid callout for examples of Oracle-provided such callout routines.


See also: