跳到主要内容

附录 - Gopher 协议的 BNF

附录​

Paul 为 Gopher 协议编写的 NQBNF (Not Quite BNF).

注: 这是修改版 BNF (Pascal 圈使用的那种), 其中加入了一些英语修饰符. 用 '{}' 括起来的内容可以重复零次或多次. '[]' 中的内容表示一组条目. '-' 运算符表示集合减法.

目录实体​

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 - ['.']}.

注: 这是 RFC 1034 中定义的完全限定域名 (例如 gopher.micro.umn.edu). 名称中含有 CR-LF, TAB 或 NUL 的主机咎由自取.

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

DigitSeq ::= digit {digit}.

Port ::= DigitSeq.

注: Port 对应 TCP 端口号, 其值应在 [0..65535] 范围内; 端口 70 正式分配给 gopher.

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

注:

由于许多不同的客户端都会使用 User_Name 字段, 强烈建议该字段只包含可打印字符. 不过, 如果使用八位字符, 这些字符应当符合 ISO Latin1 字符集. 用户可显示行的长度应小于 70 个字符; 较长的行可能无法适配某些屏幕.

Selector 字符串不应超过 255 个字符.

菜单实体​

Menu      ::= {DirEntity} Lastline.

连接可由客户端或服务器关闭 (通常是服务器).

菜单事务 (类型 1 条目)​

C: Opens Connection
S: Accepts Connection
C: Sends Selector String
S: Sends Menu Entity

Textfile 实体​

TextFile  ::= {TextBlock} Lastline

注: 以句点开头的行必须额外加上一个句点作为前缀, 以确保传输不会过早终止. 客户端应去除行首多余的句点.

TextFile 事务 (类型 0 条目)​

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

连接可由客户端或服务器关闭 (通常是服务器).

注: 客户端应当做好准备, 服务器可能不发送 Lastline 就关闭连接. 这使客户端能够使用 fingerd 服务器.

全文搜索事务 (类型 7 条目)​

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.

注: 在没有 'and', 'or' 或 'not' 运算符时, SPACE 被视为隐含的 'and' 运算符. 表达式从左到右求值. 此外, 并非目前实现的所有搜索引擎或搜索网关都实现了布尔运算符.

二进制文件事务 (类型 9 或 5 条目)​

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

目录实体的句法含义​

客户端应按如下方式解释类型字段:

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.