Atua is a gopher server written in Retro.
This will get run as an inetd service, which keeps things simple as it prevents needing to handle socket I/O directly.
Atua is a minimal server targetting the the basic Gopher0 protocol. It supports a minimal gophermap format for indexes and transfer of static content.
Atua uses Retro's rre interface layer. Designed to run a single program then exit, this makes using Retro as a scripting language possible.
Atua needs to know:
• the path to the files to serve
• the name of the index file
• The maximum length of a selector
• The maximum file size
Retro only supports basic output by default. The RRE interface that Atua uses adds support for files and stdin, so we use these and provide some other helpers.
Console Output
The Gopher protocol uses tabs and cr/lf for signficant things. To aid in this, I define output words for tabs and end of line.
Console Input
Input lines end with a cr, lf, or tab. The eol? checks for this. The gets word could easily be made more generic in terms of what it checks for. This suffices for a Gopher server though.
Atua uses a gopher: namespace to group the server related words.
First up are buffers for the selector string and the file buffer. The variables and buffers are kept private.
Next up, variables to track information related to the requested selector. Atua will construct filenames based on these.
FID, the file id, tracks the open file handle that Atua uses when reading in a file. The Size variable will hold the size of the file (in bytes).
I use a Server-Info variable to decide whether or not to display the index footer. This will become a configurable option in the future.
A gophermap is a file that makes it easier to handle Gopher menus. Atua's gophermap support covers:
• comment lines
Comment lines are static text without any tabs. They will be reformatted according to protocol and sent.
• selector lines
Any line with a tab is treated as a selector line and is transferred without changing.
The internal helpers are now defined, so switch to the part of the namespace that'll be left exposed to the world.
An information line s:get a format like:
i...text...
The gopher:i displays a string in this format. It's used later for
the index footer.
The only thing left is the top level server.
Close off the helper portion of the namespace.
And run the gopher:server.