diff -r 20ce0029e4a0 -r 5001564ac5fc src/irc_line.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/irc_line.h Sat Feb 28 21:39:15 2009 +0200 @@ -0,0 +1,47 @@ +#ifndef IRC_LINE_H +#define IRC_LINE_H + +#include "error.h" + +/* + * The maximum length of a line, including terminating CRLF + */ +#define IRC_LINE_MAX 512 + +/* + * The maximum number of arguments for a single command + */ +#define IRC_ARG_MAX 15 + +/* + * Chars that are invalid inside of tokens + */ +#define IRC_TOKEN_INVALID "\r\n\n " +#define IRC_TOKEN_TRAILING_INVALID "\r\n\n" + +/* + * Low-level IRC protocol unit is a line with its bits + */ +struct irc_line { + /* The message source, either a server name or a nickmask */ + const char *prefix; + + /* The command, either a numeric or a primary command */ + const char *command; + + /* The arguments, with unused ones set to NULL */ + const char *args[IRC_ARG_MAX]; +}; + +/* + * Parse an IRC message to fill in an irc_line. This mutates the value of data (to insert NULs between tokens), and + * stores pointers into this data into the irc_line. + */ +err_t irc_line_parse (struct irc_line *line, char *data); + +/* + * Formats an irc_line as a protocol line into the given buffer (which should hold at least IRC_LINE_MAX bytes). + */ +err_t irc_line_build (const struct irc_line *line, char *buf); + +#endif /* IRC_LINE_H */