|
1 #ifndef IRC_CHAN_H |
|
2 #define IRC_CHAN_H |
|
3 |
|
4 /** |
|
5 * @file |
|
6 * |
|
7 * Support for IRC channels, including tracking their state and actions on them. |
|
8 */ |
|
9 struct irc_chan_info; |
|
10 struct irc_chan; |
|
11 |
|
12 #include "irc_net.h" |
|
13 #include "error.h" |
|
14 #include <sys/queue.h> |
|
15 |
|
16 /** |
|
17 * IRC channel info, as required to create an irc_chan |
|
18 */ |
|
19 struct irc_chan_info { |
|
20 /** Channel name, with the [#&!] prefix */ |
|
21 const char *channel; |
|
22 |
|
23 }; |
|
24 |
|
25 /** |
|
26 * General IRC channel states |
|
27 */ |
|
28 enum irc_chan_state { |
|
29 /** Initialized, but idle */ |
|
30 IRC_CHAN_INIT, |
|
31 |
|
32 /** JOIN request sent */ |
|
33 IRC_CHAN_JOINING, |
|
34 |
|
35 /** Currently joined to the channel */ |
|
36 IRC_CHAN_JOINED, |
|
37 }; |
|
38 |
|
39 /** |
|
40 * IRC channel state |
|
41 */ |
|
42 struct irc_chan { |
|
43 /** The irc_net.channels list */ |
|
44 TAILQ_ENTRY(irc_chan) node; |
|
45 |
|
46 /* The network we're on */ |
|
47 struct irc_net *net; |
|
48 |
|
49 /** Our identifying info */ |
|
50 struct irc_chan_info info; |
|
51 |
|
52 /** Current state */ |
|
53 enum irc_chan_state state; |
|
54 }; |
|
55 |
|
56 /** |
|
57 * Return the channel's name |
|
58 */ |
|
59 const char* irc_chan_name (struct irc_chan *chan); |
|
60 |
|
61 /** |
|
62 * Build/initialize a new irc_chan struct. This does not have any external side-effects. |
|
63 * |
|
64 * The channel will be in the IRC_CHAN_INIT state after this. |
|
65 * |
|
66 * @param chan_ptr the new irc_chan is returned via this pointer |
|
67 * @param net the irc_net this channel is on |
|
68 * @param info the channel's identifying information |
|
69 * @param err error codes are returned via this |
|
70 */ |
|
71 err_t irc_chan_create (struct irc_chan **chan_ptr, struct irc_net *net, const struct irc_chan_info *info, struct error_info *err); |
|
72 |
|
73 /** |
|
74 * Send the initial JOIN message. |
|
75 * |
|
76 * The channel must be in the IRC_CHAN_INIT state, and will transition to the IRC_CHAN_JOINING state. |
|
77 * |
|
78 * @param chan the channel to JOIN |
|
79 */ |
|
80 err_t irc_chan_join (struct irc_chan *chan); |
|
81 |
|
82 #endif |