spacecookie-0.2.1.2: Gopher Library and Server Daemon

Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Network.Gopher

Contents

Description

Overview

This is the main module of the spacecookie library. It allows to write gopher applications by taking care of handling gopher requests while leaving the application logic to a user-supplied function.

For a small tutorial an example of a trivial pure gopher application:

import Network.Gopher
import Network.Gopher.Util

main = do
  runGopherPure (GopherConfig "localhost" 7000 Nothing) (\req -> FileResponse (uEncode req))

This server just returns the request string as a file.

There are three possibilities for a GopherResponse:

If you use runGopher, it is the same story like in the example above, but you can do IO effects. To see a more elaborate example, have a look at the server code in this package.

Note: In practice it is probably best to use record update syntax on defaultConfig which won't break your application every time the config record fields are changed.

Synopsis

Main API

runGopher :: GopherConfig -> (String -> IO GopherResponse) -> IO () Source #

Run a gopher application that may cause effects in IO. The application function is given the gopher request (path) and required to produce a GopherResponse.

runGopherPure :: GopherConfig -> (String -> GopherResponse) -> IO () Source #

Run a gopher application that may not cause effects in IO.

runGopherManual :: IO (Socket Inet6 Stream TCP) -> IO () -> (Socket Inet6 Stream TCP -> IO ()) -> GopherConfig -> (String -> IO GopherResponse) -> IO () Source #

Same as runGopher, but allows you to setup the Socket manually and calls an action of type IO () as soon as the server is ready to accept requests. When the server terminates, it calls the action of type Socket Inet6 Stream TCP -> IO () to clean up the socket.

Spacecookie assumes the Socket is properly set up to listen on the port and host specified in the GopherConfig (i. e. bind and listen have been called). This can be achieved using setupGopherSocket.

This is intended for supporting systemd socket activation and storage. Only use, if you know what you are doing.

data GopherConfig Source #

necessary information to handle gopher requests

Constructors

GopherConfig 

Fields

defaultConfig :: GopherConfig Source #

Default GopherConfig describing a server on localhost:70.

Helper Functions

gophermapToDirectoryResponse :: Gophermap -> GopherResponse Source #

Convert a gophermap to a gopher menu response.

setupGopherSocket :: GopherConfig -> IO (Socket Inet6 Stream TCP) Source #

Auxiliary function that sets up the listening socket for runGopherManual correctly and starts to listen.

Representations

Responses

data GopherResponse Source #

Constructors

MenuResponse [GopherMenuItem]

gopher menu, wrapper around a list of GopherMenuItems

FileResponse ByteString

return the given ByteString as a file

ErrorResponse String

gopher menu containing a single error with the given String as text

data GopherMenuItem Source #

entry in a gopher menu

Constructors

Item GopherFileType ByteString FilePath (Maybe ByteString) (Maybe Integer)

file type, menu text, filepath (does not need to be a real file), server name (optional), port (optional)

data GopherFileType Source #

rfc-defined gopher file types plus info line and HTML

Constructors

File

text file, default type

Directory

a gopher menu

PhoneBookServer 
Error

error entry in menu

BinHexMacintoshFile 
DOSArchive 
UnixUuencodedFile 
IndexSearchServer 
TelnetSession 
BinaryFile

binary file

RedundantServer 
Tn3270Session 
GifFile

gif

ImageFile

image of any format

InfoLine

menu entry without associated file

Html

Special type for HTML, most commonly used for links to other protocols

Gophermaps

data GophermapEntry Source #

A gophermap entry makes all values of a gopher menu item optional except for file type and description. When converting to a GopherMenuItem, appropriate default values are used.

Constructors

GophermapEntry GopherFileType ByteString (Maybe FilePath) (Maybe ByteString) (Maybe Integer)

file type, description, path, server name, port number