Skip to main content

Appendix - BNF for the Gopher Protocol

Appendix​

Paul's NQBNF (Not Quite BNF) for the Gopher Protocol.

Note: This is modified BNF (as used by the Pascal people) with a few English modifiers thrown in. Stuff enclosed in '{}' can be repeated zero or more times. Stuff in '[]' denotes a set of items. The '-' operator denotes set subtraction.

Directory Entity​

CR-LF     ::= ASCII Carriage Return Character followed by Line Feed
character.

Tab ::= ASCII Tab character.

NUL ::= ASCII NUL character.

UNASCII ::= ASCII - [Tab CR-LF NUL].

Lastline ::= '.'CR-LF.

TextBlock ::= Block of ASCII text not containing Lastline pattern.

Type ::= UNASCII.

RedType ::= '+'.

User_Name ::= {UNASCII}.

Selector ::= {UNASCII}.

Host ::= {{UNASCII - ['.']} '.'} {UNASCII - ['.']}.

Note: This is a Fully Qualified Domain Name as defined in RFC 1034. (e.g., gopher.micro.umn.edu) Hosts that have a CR-LF TAB or NUL in their name get what they deserve.

Digit     ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' .

DigitSeq ::= digit {digit}.

Port ::= DigitSeq.

Note: Port corresponds the the TCP Port Number, its value should be in the range [0..65535]; port 70 is officially assigned to gopher.

DirEntity ::= Type User_Name Tab Selector Tab Host Tab Port CR-LF
{RedType User_Name Tab Selector Tab Host Tab Port CR-LF}

Notes:

It is highly recommended that the User_Name field contain only printable characters, since many different clients will be using it. However if eight bit characters are used, the characters should conform with the ISO Latin1 Character Set. The length of the User displayable line should be less than 70 Characters; longer lines may not fit across some screens.

The Selector string should be no longer than 255 characters.

Menu      ::= {DirEntity} Lastline.
C: Opens Connection
S: Accepts Connection
C: Sends Selector String
S: Sends Menu Entity

Connection is closed by either client or server (typically server).

Textfile Entity​

TextFile  ::= {TextBlock} Lastline

Note: Lines beginning with periods must be prepended with an extra period to ensure that the transmission is not terminated early. The client should strip extra periods at the beginning of the line.

TextFile Transaction (Type 0 item)​

C: Opens Connection.
S: Accepts connection
C: Sends Selector String.
S: Sends TextFile Entity.

Connection is closed by either client or server (typically server).

Note: The client should be prepared for the server closing the connection without sending the Lastline. This allows the client to use fingerd servers.

Full-Text Search Transaction (Type 7 item)​

Word      ::= {UNASCII - ' '}
BoolOp ::= 'and' | 'or' | 'not' | SPACE
SearchStr ::= Word {{SPACE BoolOp} SPACE Word}

C: Opens Connection.
C: Sends Selector String, Tab, Search String.
S: Sends Menu Entity.

Note: In absence of 'and', 'or', or 'not' operators, a SPACE is regarded as an implied 'and' operator. Expression is evaluated left to right. Further, not all search engines or search gateways currently implemented have the boolean operators implemented.

Binary file Transaction (Type 9 or 5 item)​

C: Opens Connection.
S: Accepts connection
C: Sends Selector String.
S: Sends a binary file and closes connection when done.

Syntactic Meaning for Directory Entities​

The client should interpret the type field as follows:

0 The item is a TextFile Entity.​

1 The item is a Menu Entity.​

2 The information applies to a CSO phone book entity.​

3 Signals an error condition.​

4 Item is a Macintosh file encoded in BINHEX format​

5 Item is PC-DOS binary file of some sort. Client gets to decide.​

6 Item is a uuencoded file.​

7 The information applies to a Index Server.​

8 The information applies to a Telnet session.​

9 Item is a binary file. Client must decide what to do with it.​

+   The information applies to a duplicated server.  The information
contained within is a duplicate of the primary server. The primary
server is defined as the last DirEntity that is has a non-plus
"Type" field. The client should use the transaction as defined by
the primary server Type field.

g Item is a GIF graphic file.

I Item is some kind of image file. Client gets to decide.

T The information applies to a tn3270 based telnet session.
Connect to given host at given port. The name to login as at this
host is in the selector string.