remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
#ifndef IRC_PROTO_H
#define IRC_PROTO_H
/**
* @file
*
* General IRC protocol things, such as prefix/nickmask/nickname parsing
*/
#include "error.h"
#include <stddef.h>
/**
* Maximum length of an IRC nickname including terminating NUL.
*/
#define IRC_NICK_MAX 31
/**
* Maximum length of an IRC prefix/nickmask string, including any termianting NULs.
*
* XXX: currently this is pretty large, but does it really matter? We have more than 4k stack...
*/
#define IRC_PREFIX_MAX 510
/**
* Parsed nickmask
*/
struct irc_nm {
/** Nickname, not normalized */
const char *nickname;
/** Username, including any ident-related prefix from the network */
const char *username;
/** Hostname, either reverse DNS hostname, literal IPv4 or literal IPv6 */
const char *hostname;
};
/**
* Parse a full nickmask from a prefix. This fails if the prefix is a server name.
*
* Since we cannot modify the prefix string, the user must provide a buffer of at least IRC_PREFIX_MAX bytes to store
* the procesed prefix. The returned nm's fields will point into this buffer.
*/
err_t irc_nm_parse (struct irc_nm *nm, char *buf, const char *prefix);
/**
* Compare two nicknames for equality, with standard strcmp() semantics.
*/
int irc_cmp_nick (const char *nick1, const char *nick2);
/**
* Compare up to the first n chars of the two nickname strings for equality, with standard strcmp() semantics.
*/
int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n);
/**
* Parse the nickname portion of a prefix, storing it in the given buffer of IRC_NICK_MAX bytes.
*/
err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX]);
/**
* Compare the nickname in the given prefix and with the given nickname for equality.
*
* @return -err for invalid prefix, 0 for match, >0 for non-match.
*/
int irc_prefix_cmp_nick (const char *prefix, const char *nick);
/**
* @group IRC command numerics
* @{
*/
/**
* 001 <nick> :Welcome to the Internet Relay Network <nick>!<user>@<host>
*/
#define IRC_RPL_WELCOME "001"
// @}
#endif