Snert . Com dbm-server.pl
      from   Snert . Com

A Simple DBM Server

| dbm-client.pl | dbm-server.pl | mod_watch |
| Welcome | Software |

Syntax

dbm-server.pl [-d|-k][-p port][-h hosts]

-dDaemon server mode.
-h hostsComma separated list of host names or IPs allowed to connect. The default is the localhost 127.0.0.1
-k Kill an already running server.
-p portListen for TCP connections on this port. The default is 9866.

Description

The DBM API model allows for only one "writer" or many "readers", but not both at the same time on the same database. This limitation means that processes that wish to read & write to a DBM file, must pass through an intermediate server who has sole control of the DBM file.

The server waits on a given port for a TCP connection. Once a connection is establish, the client has sole control of the DBM file and should maintain the connection for the shortest time possible, because DBM files can only be written to by one process at a time, the DBM server must remain single threaded. During the time the client has the connection, it can make one or more requests such as get, set, delete, close, and quit.

The assumptions here are that DBM databases have far less overhead than more prowerful SQL servers, that the server will be simple and therefore fast, and that client connections are short and simple.

Any request, other than quit, will open or create the named database found in the database directory, if not already opened. Once opened a database will remain open until either the server terminates or a close request is received.

A simple (and not to secure) authentication scheme is used. Every request must supply a database specific secret. When a request is made for a non-existant database, the database is created and the key DATABASE-SECRET is assigned the secret of that request. All future requests for that database must use the same secret to access it. The secret can be changed by a set request of the DATABASE-SECRET key.

A Request

A request has the following format:

VNCDSKVDBNAMESECRETKEYVALUE
111112D bytesS bytesK bytesV bytes

where

VNbyteRequest format version number, should be 0
CbyteCommand code
DbyteLength of DBNAME (1..255)
SbyteLength of SECRET (0..255)
KbyteLength of KEY (0..255)
Vnetwork shortLength of VALUE (0..65535)
DBNAMED bytesDBM database name
SECRETS bytesDatabase secret
KEYK bytesDBM key
VALUEV bytesValue to store

The command codes are:

'c'Close the named database. Responds with the database's name.
'd'Delete the key from the database. Responds with the key's value.
'g'Get the value of key from the database. Responds with the key's value.
'q'Quit and close the connection. Responds with "END".
's'Set the key/value pair within database. Responds with value.
'x'Special extension. Responds with a random string.

An invalid command code or invalid field length will quit and close the connection, and respond with "END".

A Response

A response has the following format:

VNSTRRESPONSE
112R bytes

where

VNbyteResponse format version number, should be 0
STbyteStatus code
Rnetwork shortLength of the response (0..65535)
RESPONSER bytesThe response value or message.

The status codes are :

0x00Command successful
0x01Command successful: closing connection
0x10Connection error: unspecified
0x11Connection error: read
0x12Connection error: write
0x20Invalid command
0x21Invalid version
0x22Invalid request length
0x23Invalid secret
0xFFUndefined error

License

This source distribution is made freely available and there is no charge for its use, provided you retain this notice, disclaimers, author's copyright, and credits.

Disclaimer

THIS SOFTWARE IS PROVIDE "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO WAY SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


| dbm-client.pl | dbm-server.pl | mod_watch |
| Welcome | Software |