Next: , Previous: , Up: Library   [Contents][Index]


5.39 Sockmap Functions

Socket map (sockmap for short) is a special type of database used in Sendmail and 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.

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 Protocol in Smap manual.

The MFL library provides two primitives for dealing with sockmaps. Both primitives become available after requiring the sockmap 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 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.


Next: , Previous: , Up: Library   [Contents][Index]