#include "irc_chan.h"
#include <stdlib.h>
#include <assert.h>
const char* irc_chan_name (struct irc_chan *chan)
{
return chan->info.channel;
}
err_t irc_chan_create (struct irc_chan **chan_ptr, struct irc_net *net, const struct irc_chan_info *info, struct error_info *err)
{
struct irc_chan *chan;
// allocate
if ((chan = calloc(1, sizeof(*chan))) == NULL)
return SET_ERROR(err, ERR_CALLOC);
// store
chan->net = net;
chan->info = *info;
chan->state = IRC_CHAN_INIT;
// ok
*chan_ptr = chan;
return SUCCESS;
}
err_t irc_chan_join (struct irc_chan *chan)
{
err_t err;
// XXX: error instead?
assert(chan->state == IRC_CHAN_INIT);
// send JOIN message on the appropriate connection
if ((err = irc_conn_JOIN(chan->net->conn, chan->info.channel)))
// XXX: state?
return err;
// ok, joining
chan->state = IRC_CHAN_JOINING;
// done
return SUCCESS;
}