author | Tero Marttila <terom@fixme.fi> |
Thu, 21 May 2009 16:23:50 +0300 | |
branch | lua-threads |
changeset 207 | 3fa22abb5421 |
parent 197 | 3f9175ead92a |
child 217 | 7728d6ec3abf |
permissions | -rw-r--r-- |
26 | 1 |
#include "irc_chan.h" |
39
a4891d71aca9
rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
2 |
#include "irc_proto.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
|
3 |
#include "log.h" |
26 | 4 |
|
5 |
#include <stdlib.h> |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
6 |
#include <string.h> |
26 | 7 |
#include <assert.h> |
8 |
||
9 |
const char* irc_chan_name (struct irc_chan *chan) |
|
10 |
{ |
|
138
a716c621cb90
implement blackhole filters for logwatch, and stop applying filters after the first hit
Tero Marttila <terom@fixme.fi>
parents:
127
diff
changeset
|
11 |
return chan ? chan->info.channel : "NULL"; |
26 | 12 |
} |
13 |
||
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
|
14 |
/** |
87 | 15 |
* Invoke the named irc_chan_callbacks field with the given args |
16 |
*/ |
|
17 |
#define IRC_CHAN_INVOKE_CALLBACK(chan, _cb_name_, ...) \ |
|
18 |
do { \ |
|
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
19 |
struct irc_chan_callback_item *item; \ |
87 | 20 |
\ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
21 |
CHAIN_FOREACH_SAFE(&(chan)->callbacks, item) { \ |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
22 |
if (item->callbacks->_cb_name_) \ |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
23 |
item->callbacks->_cb_name_((chan), ## __VA_ARGS__, item->arg); \ |
87 | 24 |
} \ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
25 |
} while (0) |
87 | 26 |
|
27 |
/** |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
28 |
* Add or update a nickname to the irc_chan.users list. |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
29 |
* |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
30 |
* If the given nickname already exists in our users list, this does nothing. Otherwise, an irc_user is aquired using |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
31 |
* irc_net_get_user, and a new irc_chan_user struct added to our users list. |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
32 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
33 |
static err_t irc_chan_add_user (struct irc_chan *chan, const char *nickname) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
34 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
35 |
struct irc_user *user; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
36 |
struct irc_chan_user *chan_user; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
37 |
err_t err; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
38 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
39 |
// skip if already listed |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
40 |
if (irc_chan_get_user(chan, nickname)) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
41 |
return SUCCESS; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
42 |
|
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
43 |
// lookup/create the irc_user state, incrementing the refcount |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
44 |
if ((err = irc_net_get_user(chan->net, &user, nickname))) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
45 |
return err; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
46 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
47 |
// alloc the new irc_chan_user |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
48 |
if ((chan_user = calloc(1, sizeof(*chan_user))) == NULL) { |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
49 |
// XXX: release irc_user |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
50 |
return ERR_CALLOC; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
51 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
52 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
53 |
// store |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
54 |
chan_user->user = user; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
55 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
56 |
// add to users list |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
57 |
LIST_INSERT_HEAD(&chan->users, chan_user, chan_users); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
58 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
59 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
60 |
return SUCCESS; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
61 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
62 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
63 |
/** |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
64 |
* Remove an irc_chan_user previously added by irc_chan_add_user(). |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
65 |
*/ |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
66 |
static void irc_chan_remove_user (struct irc_chan *chan, struct irc_chan_user *chan_user) |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
67 |
{ |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
68 |
// put the irc_user reference back, decrementing refcount |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
69 |
irc_net_put_user(chan->net, chan_user->user); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
70 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
71 |
// remove from list |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
72 |
LIST_REMOVE(chan_user, chan_users); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
73 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
74 |
// free |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
75 |
free(chan_user); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
76 |
} |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
77 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
78 |
/** |
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
|
79 |
* :nm JOIN <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
|
80 |
*/ |
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
|
81 |
static void irc_chan_on_JOIN (const struct irc_line *line, void *arg) |
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
|
82 |
{ |
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
|
83 |
struct irc_chan *chan = arg; |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
84 |
err_t err; |
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
|
85 |
|
197
3f9175ead92a
use irc_conn_self in irc_chan
Tero Marttila <terom@fixme.fi>
parents:
171
diff
changeset
|
86 |
if (irc_conn_self(chan->net->conn, line->source->nickname)) { |
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
|
87 |
// twiddle state |
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:
39
diff
changeset
|
88 |
chan->joining = false; |
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:
39
diff
changeset
|
89 |
chan->joined = true; |
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
|
90 |
|
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
91 |
// invoke callback |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
92 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_self_join); |
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:
39
diff
changeset
|
93 |
|
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:
39
diff
changeset
|
94 |
} else { |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
95 |
// add them |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
96 |
if ((err = irc_chan_add_user(chan, line->source->nickname))) |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
97 |
return log_warn("irc_chan_add_user(%s, %s): %s", irc_chan_name(chan), line->source->nickname, error_name(err)); |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
98 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
99 |
// invoke callback (source) |
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
100 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_join, line->source); |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
101 |
} |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
102 |
} |
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
|
103 |
|
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
104 |
/** |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
105 |
* :nm PRIVMSG <channel> <message> |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
106 |
*/ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
107 |
static void irc_chan_on_PRIVMSG (const struct irc_line *line, void *arg) |
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 |
struct irc_chan *chan = arg; |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
110 |
|
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:
39
diff
changeset
|
111 |
const char *msg = line->args[1]; |
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:
39
diff
changeset
|
112 |
|
75
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
113 |
// invoke callback (source, message) |
ff6272398d2e
change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
114 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_msg, line->source, msg); |
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
|
115 |
} |
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
|
116 |
|
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
|
117 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
118 |
* Add/update nicknames to users list using irc_chan_add_user |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
119 |
* |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
120 |
* @see IRC_RPL_NAMREPLY |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
121 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
122 |
static void irc_chan_on_RPL_NAMREPLY (const struct irc_line *line, void *arg) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
123 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
124 |
struct irc_chan *chan = arg; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
125 |
char chanflags[IRC_CHANFLAGS_MAX]; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
126 |
const char *nickname; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
127 |
err_t err; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
128 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
129 |
// the args |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
130 |
const char *arg_names = line->args[3]; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
131 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
132 |
// copy the nicklist to a mutable buffer |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
133 |
char names_buf[strlen(arg_names) + 1], *names = names_buf; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
134 |
strcpy(names, arg_names); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
135 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
136 |
// iterate over each name |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
137 |
while ((nickname = strsep(&names, " "))) { |
82
bc767e01648d
fix a valgrind'd bug with irc_nick_chanflags being given an empty string
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
138 |
// skip empty token at end |
bc767e01648d
fix a valgrind'd bug with irc_nick_chanflags being given an empty string
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
139 |
if (strlen(nickname) == 0) |
bc767e01648d
fix a valgrind'd bug with irc_nick_chanflags being given an empty string
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
140 |
continue; |
bc767e01648d
fix a valgrind'd bug with irc_nick_chanflags being given an empty string
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
141 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
142 |
// parse off the channel flags |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
143 |
nickname = irc_nick_chanflags(nickname, chanflags); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
144 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
145 |
// add/update |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
146 |
// XXX: do something with chanflags |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
147 |
if ((err = irc_chan_add_user(chan, nickname))) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
148 |
log_warn("irc_chan_add_user(%s, %s): %s", irc_chan_name(chan), nickname, error_name(err)); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
149 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
150 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
151 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
152 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
153 |
* Channel join sequence complete |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
154 |
* |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
155 |
* @see IRC_RPL_ENDOFNAMES |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
156 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
157 |
static void irc_chan_on_RPL_ENDOFNAMES (const struct irc_line *line, void *arg) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
158 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
159 |
struct irc_chan *chan = arg; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
160 |
|
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
161 |
(void) line; |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
162 |
(void) chan; |
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
163 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
164 |
// XXX: update state |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
165 |
log_info("channel join sync complete"); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
166 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
167 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
168 |
/** |
89 | 169 |
* Someone, or us ourselves, left a channel |
170 |
* |
|
171 |
* :nm PART <channel> [<message>] |
|
172 |
*/ |
|
173 |
static void irc_chan_on_PART (const struct irc_line *line, void *arg) |
|
174 |
{ |
|
175 |
struct irc_chan *chan = arg; |
|
176 |
||
177 |
const char *msg = line->args[1]; |
|
178 |
||
197
3f9175ead92a
use irc_conn_self in irc_chan
Tero Marttila <terom@fixme.fi>
parents:
171
diff
changeset
|
179 |
if (irc_conn_self(chan->net->conn, line->source->nickname)) { |
89 | 180 |
// twiddle state |
181 |
chan->joined = false; |
|
182 |
chan->parted = true; |
|
183 |
||
184 |
// invoke callback |
|
185 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_self_part); |
|
186 |
||
187 |
// XXX: cleanup |
|
188 |
||
189 |
} else { |
|
190 |
// someone else |
|
191 |
struct irc_chan_user *chan_user; |
|
192 |
||
193 |
// invoke callback (source, msg) |
|
194 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_part, line->source, msg); |
|
195 |
||
196 |
// look up the irc_chan_user |
|
197 |
if ((chan_user = irc_chan_get_user(chan, line->source->nickname)) == NULL) |
|
198 |
return log_warn("PART'd user not on channel: %s, %s", irc_chan_name(chan), line->source->nickname); |
|
199 |
||
200 |
// remove them |
|
201 |
irc_chan_remove_user(chan, chan_user); |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* :nm KICK <channel> <target> [<reason>] |
|
207 |
* |
|
208 |
* User kicked some other user, might be us |
|
209 |
*/ |
|
210 |
static void irc_chan_on_KICK (const struct irc_line *line, void *arg) |
|
211 |
{ |
|
212 |
struct irc_chan *chan = arg; |
|
213 |
struct irc_chan_user *target_user; |
|
214 |
||
215 |
const char *target = line->args[1]; |
|
216 |
const char *msg = line->args[2]; |
|
217 |
||
197
3f9175ead92a
use irc_conn_self in irc_chan
Tero Marttila <terom@fixme.fi>
parents:
171
diff
changeset
|
218 |
if (irc_conn_self(chan->net->conn, target)) { |
89 | 219 |
// twiddle state |
220 |
chan->joined = false; |
|
221 |
chan->kicked = true; |
|
222 |
||
223 |
// invoke callback (source, msg) |
|
224 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_self_kicked, line->source, msg); |
|
225 |
||
226 |
// XXX: cleanup |
|
227 |
||
228 |
} else { |
|
229 |
// look up the target irc_chan_user |
|
230 |
if ((target_user = irc_chan_get_user(chan, target)) == NULL) |
|
231 |
return log_warn("KICK'd user not on channel: %s, %s", irc_chan_name(chan), target); |
|
232 |
||
233 |
// invoke callback (source, target_user, msg) |
|
234 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_kick, line->source, target_user, msg); |
|
235 |
||
236 |
// remove them |
|
237 |
irc_chan_remove_user(chan, target_user); |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
/** |
|
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
242 |
* :nm QUIT [<message>] |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
243 |
* |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
244 |
* User quit, so remove them from our users list |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
245 |
*/ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
246 |
static void irc_chan_on_QUIT (const struct irc_line *line, void *arg) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
247 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
248 |
struct irc_chan *chan = arg; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
249 |
struct irc_chan_user *chan_user; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
250 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
251 |
const char *msg = line->args[1]; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
252 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
253 |
// invoke callback (source, msg) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
254 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_quit, line->source, msg); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
255 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
256 |
// look up the irc_chan_user |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
257 |
if ((chan_user = irc_chan_get_user(chan, line->source->nickname)) == NULL) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
258 |
return log_warn("QUIT'd user not on channel: %s, %s", irc_chan_name(chan), line->source->nickname); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
259 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
260 |
// remove them |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
261 |
irc_chan_remove_user(chan, chan_user); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
262 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
263 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
264 |
/** |
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
|
265 |
* Core 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
|
266 |
*/ |
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
|
267 |
struct irc_cmd_handler _cmd_handlers[] = { |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
268 |
{ "JOIN", &irc_chan_on_JOIN }, |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
269 |
{ IRC_RPL_NAMREPLY, &irc_chan_on_RPL_NAMREPLY }, |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
270 |
{ IRC_RPL_ENDOFNAMES, &irc_chan_on_RPL_ENDOFNAMES }, |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
271 |
{ "PRIVMSG", &irc_chan_on_PRIVMSG }, |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
272 |
{ "PART", &irc_chan_on_PART }, |
89 | 273 |
{ "KICK", &irc_chan_on_KICK }, |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
75
diff
changeset
|
274 |
{ "QUIT", &irc_chan_on_QUIT }, |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
275 |
{ NULL, NULL } |
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
|
276 |
}; |
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
|
277 |
|
26 | 278 |
err_t irc_chan_create (struct irc_chan **chan_ptr, struct irc_net *net, const struct irc_chan_info *info, struct error_info *err) |
279 |
{ |
|
280 |
struct irc_chan *chan; |
|
281 |
||
282 |
// allocate |
|
283 |
if ((chan = calloc(1, sizeof(*chan))) == NULL) |
|
284 |
return SET_ERROR(err, ERR_CALLOC); |
|
285 |
||
286 |
// store |
|
287 |
chan->net = net; |
|
148
2d8dec363f9e
fix irc_chan to copy the irc_chan_info strings
Tero Marttila <terom@fixme.fi>
parents:
138
diff
changeset
|
288 |
|
2d8dec363f9e
fix irc_chan to copy the irc_chan_info strings
Tero Marttila <terom@fixme.fi>
parents:
138
diff
changeset
|
289 |
// copy info |
2d8dec363f9e
fix irc_chan to copy the irc_chan_info strings
Tero Marttila <terom@fixme.fi>
parents:
138
diff
changeset
|
290 |
if ((chan->info.channel = strdup(info->channel)) == NULL) |
2d8dec363f9e
fix irc_chan to copy the irc_chan_info strings
Tero Marttila <terom@fixme.fi>
parents:
138
diff
changeset
|
291 |
JUMP_SET_ERROR(err, ERR_STRDUP); |
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
|
292 |
|
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
|
293 |
// init |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
294 |
LIST_INIT(&chan->users); |
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
|
295 |
irc_cmd_init(&chan->handlers); |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
296 |
CHAIN_INIT(&chan->callbacks); |
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
|
297 |
|
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
|
298 |
// add 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
|
299 |
if ((ERROR_CODE(err) = irc_cmd_add(&chan->handlers, _cmd_handlers, 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
|
300 |
goto error; |
26 | 301 |
|
302 |
// ok |
|
303 |
*chan_ptr = chan; |
|
304 |
||
305 |
return SUCCESS; |
|
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
|
306 |
|
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
|
307 |
error: |
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
|
308 |
// cleanup |
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
|
309 |
irc_chan_destroy(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
|
310 |
|
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
|
311 |
return ERROR_CODE(err); |
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
|
312 |
} |
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
|
313 |
|
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
|
314 |
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
|
315 |
{ |
74
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
316 |
struct irc_chan_user *chan_user; |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
317 |
|
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
318 |
// free users |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
319 |
while ((chan_user = LIST_FIRST(&chan->users))) { |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
320 |
irc_chan_remove_user(chan, chan_user); |
11ec458d1cbf
add irc_chan_on_PART, irc_net_put_user and test_irc_chan_user_part
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
321 |
} |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
322 |
|
148
2d8dec363f9e
fix irc_chan to copy the irc_chan_info strings
Tero Marttila <terom@fixme.fi>
parents:
138
diff
changeset
|
323 |
// free chan itself |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
324 |
irc_cmd_clear(&chan->handlers); |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
325 |
CHAIN_CLEAR(&chan->callbacks); |
148
2d8dec363f9e
fix irc_chan to copy the irc_chan_info strings
Tero Marttila <terom@fixme.fi>
parents:
138
diff
changeset
|
326 |
free((char *) chan->info.channel); |
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
|
327 |
free(chan); |
26 | 328 |
} |
329 |
||
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
330 |
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
|
331 |
{ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
332 |
struct irc_chan_callback_item *item; |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
333 |
|
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
334 |
// create a new item |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
335 |
if ((item = CHAIN_ADD_TAIL(&chan->callbacks)) == NULL) |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
336 |
return ERR_MEM; |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
337 |
|
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
338 |
// store |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
339 |
item->callbacks = callbacks; |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
340 |
item->arg = arg; |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
341 |
|
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
342 |
// ok |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
343 |
return SUCCESS; |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
344 |
} |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
345 |
|
69
6f298b6e0d5f
create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents:
67
diff
changeset
|
346 |
void irc_chan_remove_callbacks (struct irc_chan *chan, const struct irc_chan_callbacks *callbacks, void *arg) |
6f298b6e0d5f
create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents:
67
diff
changeset
|
347 |
{ |
171
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
348 |
struct irc_chan_callback_item *item; |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
349 |
|
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
350 |
// remove all matching callback_items |
b54f393c3df0
evil chain.h macro magic, fix irc_conn_set_nickname bug, misc. test bugs (mem leaks, missing #includes)
Tero Marttila <terom@fixme.fi>
parents:
152
diff
changeset
|
351 |
CHAIN_DELETE_WHICH(&chan->callbacks, item, item->callbacks == callbacks && item->arg == arg); |
69
6f298b6e0d5f
create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents:
67
diff
changeset
|
352 |
} |
6f298b6e0d5f
create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents:
67
diff
changeset
|
353 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
354 |
struct irc_chan_user* irc_chan_get_user (struct irc_chan *chan, const char *nickname) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
355 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
356 |
struct irc_chan_user *chan_user = NULL; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
357 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
358 |
// look for it... |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
359 |
LIST_FOREACH(chan_user, &chan->users, chan_users) { |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
360 |
if (irc_cmp_nick(nickname, chan_user->user->nickname) == 0) { |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
361 |
// found |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
362 |
return chan_user; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
363 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
364 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
365 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
366 |
// not found |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
367 |
return NULL; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
368 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
69
diff
changeset
|
369 |
|
26 | 370 |
err_t irc_chan_join (struct irc_chan *chan) |
371 |
{ |
|
372 |
err_t err; |
|
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
373 |
|
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
374 |
// correct state |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
375 |
if (chan->joining || chan->joined) |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
376 |
return ERR_IRC_CHAN_STATE; |
26 | 377 |
|
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
378 |
if (!chan->net->conn) |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
379 |
return ERR_IRC_NET_STATE; |
26 | 380 |
|
381 |
// send JOIN message on the appropriate connection |
|
382 |
if ((err = irc_conn_JOIN(chan->net->conn, chan->info.channel))) |
|
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
|
383 |
// XXX: error state? |
26 | 384 |
return err; |
385 |
||
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
|
386 |
// ok |
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:
39
diff
changeset
|
387 |
chan->joining = true; |
26 | 388 |
|
389 |
return SUCCESS; |
|
390 |
} |
|
391 |
||
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
392 |
err_t irc_chan_PRIVMSG (struct irc_chan *chan, const char *message) |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
393 |
{ |
152
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
394 |
err_t err; |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
395 |
|
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
396 |
// correct state |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
397 |
if (!chan->joined) |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
398 |
return ERR_IRC_CHAN_STATE; |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
399 |
|
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
400 |
if (!chan->net->conn) |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
401 |
return ERR_IRC_NET_STATE; |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
402 |
|
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
403 |
// send the PRIVMSG message |
152
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
404 |
if ((err = irc_conn_PRIVMSG(chan->net->conn, chan->info.channel, message))) |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
405 |
return err; |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
406 |
|
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
407 |
// invoke callback (msg) |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
408 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_self_msg, message); |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
409 |
|
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
410 |
// ok |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
411 |
return SUCCESS; |
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
412 |
} |
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
89
diff
changeset
|
413 |
|
127
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
414 |
err_t irc_chan_NOTICE (struct irc_chan *chan, const char *message) |
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
415 |
{ |
152
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
416 |
err_t err; |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
417 |
|
127
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
418 |
// correct state |
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
419 |
if (!chan->joined) |
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
420 |
return ERR_IRC_CHAN_STATE; |
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
421 |
|
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
422 |
if (!chan->net->conn) |
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
423 |
return ERR_IRC_NET_STATE; |
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
424 |
|
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
425 |
// send the PRIVMSG message |
152
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
426 |
if ((err = irc_conn_NOTICE(chan->net->conn, chan->info.channel, message))) |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
427 |
return err; |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
428 |
|
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
429 |
// invoke callback (msg) |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
430 |
IRC_CHAN_INVOKE_CALLBACK(chan, on_self_notice, message); |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
431 |
|
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
432 |
// ok |
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
433 |
return SUCCESS; |
127
94e6c3b4230f
implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
434 |
} |
152
dae7bcf08474
implement irc_chan_callbacks::on_self_msg/on_self_notice, and add code for mod_irc_log to use them
Tero Marttila <terom@fixme.fi>
parents:
148
diff
changeset
|
435 |