4.12.1.31 Sockmap Functions

Socket map (sockmap for short) is a special type of database used in MeTA1. It uses a simple server/client protocol over INET or UNIX stream sockets. The server listens on a socket for queries. The client connects to the server and sends it a query, consisting of a map name and a key separated by a single space. Both map name and key are sequences of non-whitespace characters. The map name serves to identify the type of the query. The server replies with a response consisting of a status indicator and result, separated by a single space. The result part is optional. Valid status indicator and corresponding results are described in the following table:

OK

The key was found, result contains the looked up value.

NOTFOUND

The key was not found, the result is empty.

NOMORE

Same as ‘NOTFOUND’. This indicator instructs the client to discontinue further searches using derivatives of the key.

TEMP

A temporary failure occurred. The result, if present, contains a textual description of the failure.

TIMEOUT

A timeout occurred on the server side. The result, if present, contains a textual description of the failure.

PERM

A permanent failure occurred. The result, if present, contains a textual description of the failure.

Both queries and replies (communication entities) use the same encapsulation format:

 
  len:entity,

where lentity is the query or reply string, len is its length in bytes, encoded as a decimal number in ASCII. Both colon and comma are parts of the protocol.

For example, following is the query for key ‘smith’ in map ‘aliases’:

 
11:aliases news,

A possible reply is:

 
18:OK root@domain.net,

This reply means that the key ‘news’ was found in the map, and the value corresponding to that key is ‘root@domain.net’.

The following reply means the key was not found:

 
8:NOTFOUND,

For a detailed description of the sockmap protocol, see http://www.meta1.org/current/doc/README.html.

The MFL library provides two primitives for dealing with sockmaps. Both primitives become available after requiring the ‘sockmap.mf’ module.

Library Function: string sockmap_lookup (number fd,   string map, string key)

This function look ups the key in the map. The fd refers to the sockmap to use. It must be obtained as a result of a previous call to open with the URL of the sockmap as its first argument (see section open). For example:

 
  number fd open("@ unix:///var/spool/meta1/smap/socket")
  string ret sockmap_query(%fd, "aliases", $rcpt_to)
  if %ret matches "OK (.+)"
    set alias \1
  fi
  close(%fd)
Library Function: string sockmap_single_lookup (string url,   string map, string key)

This function connects to the sockmap identified by the url, queries for key in map and closes the connection. It is useful when you need to perform only a single lookup on the sockmap.