terom@25: #ifndef IRC_NET_H terom@25: #define IRC_NET_H terom@25: terom@25: /** terom@25: * @file terom@25: * terom@25: * Support for IRC networks. This is similar to an IRC connection, but we keep track of channel state, and handle terom@25: * reconnects. terom@25: */ terom@72: terom@72: struct irc_net; terom@72: terom@25: #include "error.h" terom@25: #include "irc_conn.h" terom@26: #include "irc_chan.h" terom@26: #include terom@25: terom@25: /** terom@25: * Configuration info for an IRC network terom@25: */ terom@25: struct irc_net_info { terom@25: /** The name of the network */ terom@25: const char *network; terom@25: terom@25: /** The hostname to connect to */ terom@25: const char *hostname; terom@25: terom@25: /** Service name (port) */ terom@25: const char *service; terom@25: terom@25: /** SSL? */ terom@25: bool use_ssl; terom@25: terom@86: /** Protocol registration info (nickname etc) */ terom@27: struct irc_conn_register_info register_info; terom@44: terom@44: /** Raw socket to use, mainly for testing purposes */ terom@44: struct sock_stream *raw_sock; terom@25: }; terom@25: terom@25: /** terom@86: * The persistent IRC network state. This includes the "current" connection (which may change over time), the terom@86: * identifying info, the list of channels and their state, etc. terom@86: * terom@86: * This handles the irc_conn's messages, and propagates relevant messages to the appropriate irc_chan terom@86: * (using irc_chan::handlers). This includes NICK/QUIT events for users on said channel. terom@86: * terom@86: * For NICK events, the event is propagated *before* updating irc_user::nickname. terom@86: * terom@86: * XXX: needs some callbacks terom@25: */ terom@25: struct irc_net { terom@86: /** The current connection */ terom@25: struct irc_conn *conn; terom@25: terom@53: /** Our connection info */ terom@53: struct irc_net_info info; terom@53: terom@26: /** The list of IRC channel states */ terom@26: TAILQ_HEAD(irc_net_chan_list, irc_chan) channels; terom@53: terom@72: /** Our set of valid irc_user items for use with irc_chan */ terom@72: LIST_HEAD(irc_net_users_list, irc_user) users; terom@72: terom@53: /** The irc_client list */ terom@53: TAILQ_ENTRY(irc_net) client_networks; terom@25: }; terom@25: terom@25: /** terom@86: * Return the network's name, as per irc_net_info::network terom@72: */ terom@72: const char* irc_net_name (struct irc_net *net); terom@72: terom@72: /** terom@25: * Create a new IRC network state, using the given network info to connect/register. terom@25: * terom@25: * Errors are returned via *err, also returning the error code. terom@26: * terom@98: * The irc_net_info struct itself is copied, but the strings contained therein are not... terom@98: * terom@26: * @param net the new irc_net struct is returned via this pointer terom@86: * @param info network information, used to connect and register terom@65: * @param err return error info terom@25: */ terom@25: err_t irc_net_create (struct irc_net **net, const struct irc_net_info *info, struct error_info *err); terom@25: terom@26: /** terom@47: * Destroy an irc_net state without closing anything cleanly. This destroys the irc_conn, if any, and any irc_chans as terom@47: * well. terom@47: */ terom@47: void irc_net_destroy (struct irc_net *net); terom@47: terom@47: /** terom@27: * Create a new irc_chan and add it to our channel list. terom@27: * terom@86: * If we are connected and registered, join the channel right away, otherwise, join it once we register. terom@65: * terom@65: * @param net the irc_net the channel is on terom@86: * @param chan_ptr return the new irc_chan via this, if given terom@65: * @param info the info required to identify and join the channel terom@65: * @param err return error info terom@26: */ terom@63: err_t irc_net_add_chan (struct irc_net *net, struct irc_chan **chan_ptr, const struct irc_chan_info *info, struct error_info *err); terom@26: terom@26: /** terom@26: * Look up an existing irc_chan by name, returning NULL if not found. terom@26: * terom@72: * @param net the network context terom@26: * @param channel the channel name terom@26: */ terom@26: struct irc_chan* irc_net_get_chan (struct irc_net *net, const char *channel); terom@26: terom@48: /** terom@72: * Look up an existing irc_user by nickname, or create a new one if not found. terom@72: * terom@74: * This will increment the reference count on the irc_user object, so do call irc_net_put_user once you're done with terom@74: * it, or you'll get reference-counting bugs... terom@74: * terom@72: * @param user_ptr set to the new irc_user state terom@72: * @param net the network context terom@72: * @param nickname the user's current nickname terom@72: */ terom@72: err_t irc_net_get_user (struct irc_net *net, struct irc_user **user_ptr, const char *nickname); terom@72: terom@72: /** terom@74: * Release a previously get'd irc_user, decrementing its refcount and destroying it if unused. terom@74: */ terom@74: void irc_net_put_user (struct irc_net *net, struct irc_user *user); terom@74: terom@74: /** terom@48: * Quit from the IRC network, this sends a QUIT message to the server, and waits for the connection to be closed cleanly. terom@86: * terom@86: * XXX: nothing to indicate completion terom@48: */ terom@48: err_t irc_net_quit (struct irc_net *net, const char *message); terom@48: terom@25: #endif