src/irc_net.h
author Tero Marttila <terom@fixme.fi>
Thu, 12 Mar 2009 22:06:01 +0200
changeset 44 6bd70113e1ed
parent 27 e6639132bead
child 47 7d4094eb3117
permissions -rw-r--r--
add irc_net test
#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;

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

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

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

#endif