src/irc_conn.h
author Tero Marttila <terom@fixme.fi>
Sun, 01 Mar 2009 00:34:33 +0200
changeset 20 d9c4c2980a0d
parent 18 dedf137b504f
child 21 0911d0b828d4
permissions -rw-r--r--
irc_conn PING/PONG code, and line_proto fixups
#ifndef IRC_CONN_H
#define IRC_CONN_H

/*
 * Per-connection IRC setup and state/protocol handling.
 */

#include "sock.h"
#include "line_proto.h"
#include "irc_line.h"
#include "error.h"

/*
 * A connection to an IRC server.
 */
struct irc_conn {
    /* We are a line-based protocol */
    struct line_proto *lp;
};

// XXX: this should probably be slightly reworked
struct irc_conn_config {
    /* Nickname to use on that server */
    const char *nickname;

    /* Username to supply */
    const char *username;

    /* Realname to supply */
    const char *realname;
};

/*
 * Create a new irc_conn using the given sock_stream, which should be connected to an IRC server. The parameters given
 * in \a config will be used to identify with the IRC server.
 *
 * On success, the resulting irc_conn is returned via *conn with SUCCESS. Otherwise, -ERR_* and error info is returned
 * via *err.
 */
err_t irc_conn_create (struct irc_conn **conn, struct sock_stream *sock, const struct irc_conn_config *config, struct error_info *err);

/*
 * Send an IRC message directly
 */
err_t irc_conn_send (struct irc_conn *conn, const struct irc_line *line);

/**
 * @group Simple request functions
 *
 * The error handling of these functions is such that the error return code is can be used or ignored as convenient,
 * as connection-fatal errors will be handled internally.
 *
 * @{
 */

/*
 * Send a NICK message
 */
err_t irc_conn_NICK (struct irc_conn *conn, const char *nickname);

/*
 * Send a USER message
 */
err_t irc_conn_USER (struct irc_conn *conn, const char *username, const char *realname);

/*
 * Send a PONG message to the given target
 */
err_t irc_conn_PONG (struct irc_conn *conn, const char *target);

#endif /* IRC_CONN_H */