aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
528 stars 97 forks source link

Parsing message prefixes (sources) into an enumeration. #143

Closed aatxe closed 5 years ago

aatxe commented 6 years ago

This is a relatively small and self-contained task. So, I think it'd be a good first issue for anyone looking for a way to contribute! This should be contributed as part of 0.14.

Currently, Message is defined to use a String for prefixes, but in RFC 2812, the grammar for prefixes is given as prefix = servername / ( nickname [ [ "!" user ] "@" host ] ) which is sufficiently specific to allow for parsing them into an enumeration instead.

This should be probably look something like:

enum Prefix {
    /// servername
    ServerName(String),
    /// nickname [ ["!" username] "@" hostname ]
    Nickname(String, Option<String>, Option<String>),
}

One problem is that in the (probably rare in practice) situation where you are receiving a nickname without a username or hostname attached, there is ambiguity. Most nicknames are also valid server names. However, I think it would be reasonable to classify anything containing a . as a server name and anything else as a nick name. Otherwise, we could add a third option for Ambiguous, but that probably punishes the common case for something that I'm not sure even happens on modern IRCds.

Ramifications

Part of the Message API has some functionality for getting the source nickname and so forth. This API should be cleaned up using this new enum.

aatxe commented 5 years ago

This was implemented in #149.