26
|
1 |
#include "irc_chan.h"
|
|
2 |
|
|
3 |
#include <stdlib.h>
|
|
4 |
#include <assert.h>
|
|
5 |
|
|
6 |
const char* irc_chan_name (struct irc_chan *chan)
|
|
7 |
{
|
|
8 |
return chan->info.channel;
|
|
9 |
}
|
|
10 |
|
|
11 |
err_t irc_chan_create (struct irc_chan **chan_ptr, struct irc_net *net, const struct irc_chan_info *info, struct error_info *err)
|
|
12 |
{
|
|
13 |
struct irc_chan *chan;
|
|
14 |
|
|
15 |
// allocate
|
|
16 |
if ((chan = calloc(1, sizeof(*chan))) == NULL)
|
|
17 |
return SET_ERROR(err, ERR_CALLOC);
|
|
18 |
|
|
19 |
// store
|
|
20 |
chan->net = net;
|
|
21 |
chan->info = *info;
|
|
22 |
chan->state = IRC_CHAN_INIT;
|
|
23 |
|
|
24 |
// ok
|
|
25 |
*chan_ptr = chan;
|
|
26 |
|
|
27 |
return SUCCESS;
|
|
28 |
}
|
|
29 |
|
|
30 |
err_t irc_chan_join (struct irc_chan *chan)
|
|
31 |
{
|
|
32 |
err_t err;
|
|
33 |
|
|
34 |
// XXX: error instead?
|
|
35 |
assert(chan->state == IRC_CHAN_INIT);
|
|
36 |
|
|
37 |
// send JOIN message on the appropriate connection
|
|
38 |
if ((err = irc_conn_JOIN(chan->net->conn, chan->info.channel)))
|
|
39 |
// XXX: state?
|
|
40 |
return err;
|
|
41 |
|
|
42 |
// ok, joining
|
|
43 |
chan->state = IRC_CHAN_JOINING;
|
|
44 |
|
|
45 |
// done
|
|
46 |
return SUCCESS;
|
|
47 |
}
|
|
48 |
|