terom@39: #ifndef IRC_PROTO_H terom@39: #define IRC_PROTO_H terom@39: terom@39: /** terom@39: * @file terom@39: * terom@39: * General IRC protocol things, such as prefix/nickmask/nickname parsing terom@39: */ terom@39: #include "error.h" terom@39: #include terom@39: terom@39: /** terom@45: * Maximum length of an IRC nickname including terminating NUL. terom@39: */ terom@72: #define IRC_NICK_MAX (30 + 1) terom@39: terom@39: /** terom@45: * Maximum length of an IRC prefix/nickmask string, including any termianting NULs. terom@45: * terom@45: * XXX: currently this is pretty large, but does it really matter? We have more than 4k stack... terom@45: */ terom@45: #define IRC_PREFIX_MAX 510 terom@45: terom@45: /** terom@72: * Maximum length of an IRC nickname channel flags prefix, including any terminating NUL terom@72: */ terom@72: #define IRC_CHANFLAGS_MAX (8 + 1) terom@72: terom@72: /** terom@72: * The set of characters that are considered nickname channel flag prefixes (i.e. op, voice, etc). terom@87: * terom@87: * XXX: many IRCd's have more than these, should use the 005 reply instead. terom@72: */ terom@72: #define IRC_CHANFLAGS "@+" terom@72: terom@72: /** terom@75: * Parsed nickmask. For normal user prefixes, all fields will be non-NULL. For server prefixes, nickname and username terom@75: * will be NULL, and hostname will be the server name. terom@39: */ terom@39: struct irc_nm { terom@39: /** Nickname, not normalized */ terom@39: const char *nickname; terom@39: terom@39: /** Username, including any ident-related prefix from the network */ terom@39: const char *username; terom@39: terom@87: /** Hostname, either reverse DNS hostname, literal IPv4, literal IPv6, or something else... */ terom@39: const char *hostname; terom@39: }; terom@39: terom@39: /** terom@75: * Parse a full nickmask from a prefix, mutating the value of the given buffer, and returning pointers into the buffer terom@75: * inside \a nm. terom@75: */ terom@75: err_t irc_nm_parse_buf (struct irc_nm *nm, char *prefix); terom@75: terom@75: /** terom@75: * Same as irc_nm_parse_buf(), but copies the prefix into the given mutable buffer of at least IRC_PREFIX_MAX bytes and terom@75: * returns pointers into that instead. terom@39: */ terom@45: err_t irc_nm_parse (struct irc_nm *nm, char *buf, const char *prefix); terom@39: terom@39: /** terom@87: * Compare two nicknames for equality, with standard cmp() semantics. terom@39: */ terom@39: int irc_cmp_nick (const char *nick1, const char *nick2); terom@39: terom@39: /** terom@87: * Compare up to the first n chars of the two nickname strings for equality, with standard cmp() semantics. terom@39: */ terom@39: int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n); terom@39: terom@39: /** terom@39: * Parse the nickname portion of a prefix, storing it in the given buffer of IRC_NICK_MAX bytes. terom@39: */ terom@39: err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX]); terom@39: terom@39: /** terom@39: * Compare the nickname in the given prefix and with the given nickname for equality. terom@39: * terom@39: * @return -err for invalid prefix, 0 for match, >0 for non-match. terom@39: */ terom@39: int irc_prefix_cmp_nick (const char *prefix, const char *nick); terom@39: terom@39: /** terom@72: * Copy the prefixed flags from the given nickname into the given flags buffer (of at least IRC_CHANFLAGS_MAX bytes) and terom@72: * NUL-terminate it. Returns a pointer to the actual nickname itself. terom@72: * terom@87: * @param nickname the nickname including prefixed chanflags terom@87: * @param chanflags buffer to store the parsed chanflags into terom@87: * @return a pointer to the first char of the actual nickname terom@72: */ terom@87: const char* irc_nick_chanflags (const char *nickname, char chanflags[IRC_CHANFLAGS_MAX]); terom@72: terom@72: /** terom@87: * @defgroup IRC_RPL_ IRC command numerics terom@39: * @{ terom@39: */ terom@39: terom@39: /** terom@72: * 001 "Welcome to the Internet Relay Network !@" terom@72: * terom@72: * The first "official" reply sent by the server after the NICK/USER registration was accepted. terom@39: */ terom@39: #define IRC_RPL_WELCOME "001" terom@39: terom@72: /** terom@72: * 353 ( "=" | "*" | "@" ) ( [ "@" | "+" ] [ " " ... ] ) terom@72: * terom@72: * Sent by the server after a JOIN/NAMES command to give the full list of users currently on a channel. The list may terom@72: * be split into multiple messages RPL_NAMREPLY messages, which are then terminated by a RPL_ENDOFNAMES reply. terom@72: * terom@72: * The first argument char denotes the "channel type", and is, apparently, one of the following, for those who care: terom@72: * @ secret terom@72: * * private terom@72: * = others (public) terom@72: */ terom@72: #define IRC_RPL_NAMREPLY "353" terom@72: terom@72: /** terom@72: * 366 "End of NAMES list" terom@72: * terom@72: * Sent by the server to terminate a sequence of zero or more RPL_NAMREPLY messages from a JOIN/NAMES command. terom@72: */ terom@72: #define IRC_RPL_ENDOFNAMES "366" terom@72: terom@39: // @} terom@39: terom@39: #endif