src/irc_net.h
author Tero Marttila <terom@fixme.fi>
Fri, 13 Mar 2009 16:10:48 +0200
changeset 53 12d806823775
parent 48 4841f4398fd2
child 63 d399a1d915a3
permissions -rw-r--r--
add irc_client module, plus nexus.h header
#ifndef IRC_NET_H
#define IRC_NET_H

/**
 * @file
 *
 * Support for IRC networks. This is similar to an IRC connection, but we keep track of channel state, and handle
 * reconnects.
 */
#include "error.h"
#include "irc_conn.h"
#include "irc_chan.h"
#include <sys/queue.h>

/**
 * Configuration info for an IRC network
 */
struct irc_net_info {
    /** The name of the network */
    const char *network;

    /** The hostname to connect to */
    const char *hostname;

    /** Service name (port) */
    const char *service;

    /** SSL? */
    bool use_ssl;

    /** Protocol registration info */
    struct irc_conn_register_info register_info;

    /** Raw socket to use, mainly for testing purposes */
    struct sock_stream *raw_sock;
};

/**
 * IRC Network state
 */
struct irc_net {
    /* The current connection */
    struct irc_conn *conn;

    /** Our connection info */
    struct irc_net_info info;

    /** The list of IRC channel states */
    TAILQ_HEAD(irc_net_chan_list, irc_chan) channels;

    /** The irc_client list */
    TAILQ_ENTRY(irc_net) client_networks;
};

/**
 * Create a new IRC network state, using the given network info to connect/register.
 *
 * Errors are returned via *err, also returning the error code.
 *
 * @param net the new irc_net struct is returned via this pointer
 * @param info network informated, used to connect and register
 * @param err used to return extended error information
 */
err_t irc_net_create (struct irc_net **net, const struct irc_net_info *info, struct error_info *err);

/**
 * Destroy an irc_net state without closing anything cleanly. This destroys the irc_conn, if any, and any irc_chans as
 * well.
 */
void irc_net_destroy (struct irc_net *net);

/**
 * Create a new irc_chan and add it to our channel list.
 *
 * If we are connected and registered, JOIN the channel right away, otherwise, join it once we register.
 */
struct irc_chan* irc_net_add_chan (struct irc_net *net, const struct irc_chan_info *info);

/**
 * Look up an existing irc_chan by name, returning NULL if not found.
 *
 * @param net the network state
 * @param channel the channel name
 */
struct irc_chan* irc_net_get_chan (struct irc_net *net, const char *channel);

/**
 * Quit from the IRC network, this sends a QUIT message to the server, and waits for the connection to be closed cleanly.
 */
err_t irc_net_quit (struct irc_net *net, const char *message);

#endif