author | Tero Marttila <terom@fixme.fi> |
Thu, 12 Mar 2009 22:50:08 +0200 | |
changeset 45 | 71e65564afd2 |
parent 38 | 0c2e0cb46c3a |
child 69 | 6f298b6e0d5f |
permissions | -rw-r--r-- |
26 | 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" |
|
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
13 |
#include "irc_cmd.h" |
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
14 |
#include "irc_proto.h" |
26 | 15 |
#include "error.h" |
16 |
#include <sys/queue.h> |
|
17 |
||
18 |
/** |
|
19 |
* IRC channel info, as required to create an irc_chan |
|
20 |
*/ |
|
21 |
struct irc_chan_info { |
|
22 |
/** Channel name, with the [#&!] prefix */ |
|
23 |
const char *channel; |
|
24 |
||
25 |
}; |
|
26 |
||
27 |
/** |
|
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
28 |
* Semantic IRC channel callbacks. |
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
29 |
* |
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
30 |
* Where callbacks have irc_nm arguments, these are MAY be given as NULL if the prefix could not be parsed. |
26 | 31 |
*/ |
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
32 |
struct irc_chan_callbacks { |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
33 |
/** Joined the channel */ |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
34 |
void (*on_self_join) (struct irc_chan *chan, void *arg); |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
35 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
36 |
/** Someone sent a message to the channel */ |
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
37 |
void (*on_msg) (struct irc_chan *chan, const struct irc_nm *source, const char *msg, void *arg); |
26 | 38 |
}; |
39 |
||
40 |
/** |
|
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
41 |
* Invoke the given callback with the given args |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
42 |
*/ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
43 |
#define IRC_CHAN_INVOKE_CALLBACK(chan, _cb_name_, ...) \ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
44 |
do { \ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
45 |
struct chain_head *head; \ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
46 |
\ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
47 |
CHAIN_FOREACH(&(chan)->callbacks, head) { \ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
48 |
const struct irc_chan_callbacks *callbacks = head->chain; \ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
49 |
\ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
50 |
if (callbacks->_cb_name_) \ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
51 |
callbacks->_cb_name_((chan), ## __VA_ARGS__, head->arg); \ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
52 |
} \ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
53 |
} while (0); |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
54 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
55 |
/** |
26 | 56 |
* IRC channel state |
57 |
*/ |
|
58 |
struct irc_chan { |
|
59 |
/** The irc_net.channels list */ |
|
60 |
TAILQ_ENTRY(irc_chan) node; |
|
61 |
||
62 |
/* The network we're on */ |
|
63 |
struct irc_net *net; |
|
64 |
||
65 |
/** Our identifying info */ |
|
66 |
struct irc_chan_info info; |
|
67 |
||
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
68 |
/** State flags @{ */ |
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
69 |
/** JOIN request sent, waiting for reply */ |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
70 |
bool joining; |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
71 |
|
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
72 |
/** Currently joined to channel */ |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
73 |
bool joined; |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
74 |
|
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
75 |
// @} |
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
76 |
|
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
77 |
/** General command handlers */ |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
78 |
irc_cmd_handlers_t handlers; |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
79 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
80 |
/** High-level user callbacks */ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
81 |
struct chain_list callbacks; |
26 | 82 |
}; |
83 |
||
84 |
/** |
|
85 |
* Return the channel's name |
|
86 |
*/ |
|
87 |
const char* irc_chan_name (struct irc_chan *chan); |
|
88 |
||
89 |
/** |
|
90 |
* Build/initialize a new irc_chan struct. This does not have any external side-effects. |
|
91 |
* |
|
92 |
* The channel will be in the IRC_CHAN_INIT state after this. |
|
93 |
* |
|
94 |
* @param chan_ptr the new irc_chan is returned via this pointer |
|
95 |
* @param net the irc_net this channel is on |
|
96 |
* @param info the channel's identifying information |
|
97 |
* @param err error codes are returned via this |
|
98 |
*/ |
|
99 |
err_t irc_chan_create (struct irc_chan **chan_ptr, struct irc_net *net, const struct irc_chan_info *info, struct error_info *err); |
|
100 |
||
101 |
/** |
|
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
102 |
* Destroy irc_chan state, without doing anything to the network |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
103 |
*/ |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
104 |
void irc_chan_destroy (struct irc_chan *chan); |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
105 |
|
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
106 |
/** |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
107 |
* Add high-level irc_chan callbacks |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
108 |
*/ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
109 |
err_t irc_chan_add_callbacks (struct irc_chan *chan, const struct irc_chan_callbacks *callbacks, void *arg); |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
110 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
111 |
/** |
26 | 112 |
* Send the initial JOIN message. |
113 |
* |
|
114 |
* The channel must be in the IRC_CHAN_INIT state, and will transition to the IRC_CHAN_JOINING state. |
|
115 |
* |
|
116 |
* @param chan the channel to JOIN |
|
117 |
*/ |
|
118 |
err_t irc_chan_join (struct irc_chan *chan); |
|
119 |
||
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
120 |
|
26 | 121 |
#endif |