src/irc_line.h
author Tero Marttila <terom@fixme.fi>
Sat, 28 Feb 2009 22:47:39 +0200
changeset 18 dedf137b504f
parent 17 5001564ac5fc
child 34 763f65f9df0c
permissions -rw-r--r--
add initial irc_conn code that can register
#ifndef IRC_LINE_H
#define IRC_LINE_H

#include "error.h"

/*
 * The maximum length of a line, without terminating CRLF
 */
#define IRC_LINE_MAX 510

/*
 * 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 */