author | Tero Marttila <terom@fixme.fi> |
Thu, 28 May 2009 01:17:36 +0300 | |
branch | new-lib-errors |
changeset 219 | cefec18b8268 |
parent 217 | 7728d6ec3abf |
permissions | -rw-r--r-- |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
#include "irc_net.h" |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
2 |
#include "irc_net_internal.h" |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
#include "log.h" |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
#include <stdlib.h> |
26 | 6 |
#include <string.h> |
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
|
7 |
#include <assert.h> |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
8 |
#include <time.h> |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
10 |
const char* irc_net_name (struct irc_net *net) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
11 |
{ |
138
a716c621cb90
implement blackhole filters for logwatch, and stop applying filters after the first hit
Tero Marttila <terom@fixme.fi>
parents:
97
diff
changeset
|
12 |
return net ? net->info.network : NULL; |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
13 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
14 |
|
46
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
15 |
/** |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
16 |
* Do a lookup for an irc_user with the given nickname, and return it it found, else NULL. |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
17 |
* |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
18 |
* This does not refcount anything. |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
19 |
*/ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
20 |
static struct irc_user* irc_net_lookup_user (struct irc_net *net, const char *nickname) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
21 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
22 |
struct irc_user *user = NULL; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
23 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
24 |
// look for it... |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
25 |
LIST_FOREACH(user, &net->users, net_users) { |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
26 |
if (irc_cmp_nick(nickname, user->nickname) == 0) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
27 |
// found existing |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
28 |
return user; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
29 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
30 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
31 |
// not found |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
32 |
return NULL; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
33 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
34 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
35 |
/** |
46
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
36 |
* Our irc_conn has registered. Join our channels |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
37 |
*/ |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
38 |
static void irc_net_conn_registered (struct irc_conn *conn, void *arg) |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
39 |
{ |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
40 |
struct irc_net *net = arg; |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
41 |
struct irc_chan *chan = NULL; |
217 | 42 |
error_t err; |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
43 |
|
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
44 |
(void) conn; |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
45 |
|
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
46 |
// join our channels |
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
47 |
TAILQ_FOREACH(chan, &net->channels, net_channels) { |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
48 |
if ((ERROR_CODE(&err) = irc_chan_join(chan))) { |
46
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
49 |
// XXX: this should be some kind of irc_chan_error instead |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
50 |
|
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
51 |
} |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
52 |
} |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
53 |
} |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
54 |
|
46
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
55 |
/** |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
56 |
* Our irc_conn has spontaneously failed, destroy it |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
57 |
*/ |
217 | 58 |
static void irc_net_conn_error (struct irc_conn *conn, error_t *err, void *arg) |
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:
44
diff
changeset
|
59 |
{ |
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:
44
diff
changeset
|
60 |
struct irc_net *net = arg; |
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:
44
diff
changeset
|
61 |
|
46
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
62 |
(void) conn; |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
63 |
|
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
64 |
// log an error |
172
ea4972e51fa3
fix log_warn_*/log_err/log_error naming
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
65 |
log_error(err, "irc_conn error"); |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
66 |
|
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
67 |
// tear down state |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
153
diff
changeset
|
68 |
irc_net_disconnect(net); |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
69 |
|
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
70 |
// reconnect, either right away, or at the five-minute interval |
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
71 |
if (irc_net_connect(net, (time(NULL) - net->connected_ts > IRC_NET_RECONNECT_INTERVAL), err)) |
172
ea4972e51fa3
fix log_warn_*/log_err/log_error naming
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
72 |
log_error(err, "unable to reconnect"); |
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:
44
diff
changeset
|
73 |
} |
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:
44
diff
changeset
|
74 |
|
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
75 |
/** |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
76 |
* Our irc_conn has quit succesfully |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
77 |
*/ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
78 |
static void irc_net_conn_quit (struct irc_conn *conn, void *arg) |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
79 |
{ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
80 |
struct irc_net *net = arg; |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
153
diff
changeset
|
81 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
153
diff
changeset
|
82 |
(void) conn; |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
83 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
84 |
// clean up the conn |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
153
diff
changeset
|
85 |
irc_net_disconnect(net); |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
86 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
87 |
// XXX: notify user |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
88 |
} |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
89 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
90 |
/** |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
91 |
* Our irc_conn_callbacks list |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
92 |
*/ |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
93 |
struct irc_conn_callbacks irc_net_conn_callbacks = { |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
94 |
.on_registered = &irc_net_conn_registered, |
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:
44
diff
changeset
|
95 |
.on_error = &irc_net_conn_error, |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
96 |
.on_quit = &irc_net_conn_quit, |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
97 |
}; |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
98 |
|
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:
28
diff
changeset
|
99 |
/** |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
100 |
* Propagate the command to the appropriate irc_chan based on the given name |
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 |
static void irc_net_propagate_chan (struct irc_net *net, const struct irc_line *line, const char *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:
28
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:
28
diff
changeset
|
104 |
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:
28
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:
28
diff
changeset
|
106 |
// look up channel |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
107 |
if ((chan = irc_net_get_chan(net, channel)) == NULL) { |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
108 |
log_warn("unknown channel: %s", 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:
28
diff
changeset
|
109 |
return; |
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:
28
diff
changeset
|
110 |
} |
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:
28
diff
changeset
|
111 |
|
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:
28
diff
changeset
|
112 |
// propagate |
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:
28
diff
changeset
|
113 |
irc_cmd_invoke(&chan->handlers, line); |
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:
28
diff
changeset
|
114 |
} |
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:
28
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:
28
diff
changeset
|
116 |
/** |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
117 |
* Propagate line to irc_chan based on args[0] |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
118 |
*/ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
119 |
static void irc_net_on_chan0 (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
|
120 |
{ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
121 |
struct irc_net *net = arg; |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
122 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
123 |
irc_net_propagate_chan(net, line, line->args[0]); |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
124 |
} |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
125 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
126 |
/** |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
127 |
* Propagate line to irc_chan based on args[1] |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
128 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
129 |
static void irc_net_on_chan1 (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:
68
diff
changeset
|
130 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
131 |
struct irc_net *net = arg; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
132 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
133 |
irc_net_propagate_chan(net, line, line->args[1]); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
134 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
135 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
136 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
137 |
* Propagate line to irc_chan based on args[2] |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
138 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
139 |
static void irc_net_on_chan2 (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:
68
diff
changeset
|
140 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
141 |
struct irc_net *net = arg; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
142 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
143 |
irc_net_propagate_chan(net, line, line->args[2]); |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
144 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
145 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
146 |
/** |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
147 |
* Propagate line to irc_chans based on the source nickname and chan_users. |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
148 |
*/ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
149 |
static void irc_net_on_chanuser (const struct irc_line *line, void *arg) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
150 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
151 |
struct irc_net *net = arg; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
152 |
struct irc_chan *chan; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
153 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
154 |
// scan each channel |
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
155 |
TAILQ_FOREACH(chan, &net->channels, net_channels) { |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
156 |
if (irc_chan_get_user(chan, line->source->nickname)) { |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
157 |
// propagate |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
158 |
irc_cmd_invoke(&chan->handlers, line); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
159 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
160 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
161 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
162 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
163 |
/** |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
164 |
* :nm NICK <nickname> |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
165 |
* |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
166 |
* Look for a relevant irc_user, and rename them. |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
167 |
* |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
168 |
* Ignores if the irc_user could not be found, then propagates to the irc_chan's that the user is on, and then renames |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
169 |
* the irc_user. |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
170 |
*/ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
171 |
static void irc_net_on_NICK (const struct irc_line *line, void *arg) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
172 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
173 |
struct irc_net *net = arg; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
174 |
struct irc_user *user; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
175 |
err_t err; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
176 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
177 |
// ignore for unknown |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
178 |
if ((user = irc_net_lookup_user(net, line->source->nickname)) == NULL) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
179 |
return; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
180 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
181 |
// propagate to channels |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
182 |
irc_net_on_chanuser(line, arg); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
183 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
184 |
// rename them |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
185 |
if ((err = irc_user_rename(user, line->args[0]))) |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
186 |
// XXX: what to do? |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
187 |
log_err(err, "irc_user_rename failed"); |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
188 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
189 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
190 |
/** |
68
591a574f390e
add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
191 |
* :nm (PRIVMSG|NOTICE) <target> <message> |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
192 |
* |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
193 |
* Either propagate to channel if found, otherwise handle as a privmsg |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
194 |
*/ |
68
591a574f390e
add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
195 |
static void irc_net_on_msg (const struct irc_line *line, void *arg) |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
196 |
{ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
197 |
struct irc_net *net = arg; |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
198 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
199 |
// XXX: does two lookups |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
200 |
if (irc_net_get_chan(net, line->args[0])) { |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
201 |
// short-circuit to on_chan0 |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
202 |
irc_net_on_chan0(line, arg); |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
203 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
204 |
} else { |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
205 |
// XXX: callbacks for privmsgs |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
206 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
207 |
} |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
208 |
} |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
209 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
210 |
/** |
150
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
211 |
* :nm MODE <target> [<stuff> [ ... ]] |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
212 |
* |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
213 |
* If target is ourselves, handle as a private umode, otherwise, propagate to channel |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
214 |
*/ |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
215 |
static void irc_net_on_MODE (const struct irc_line *line, void *arg) |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
216 |
{ |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
217 |
struct irc_net *net = arg; |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
218 |
|
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
219 |
if (irc_conn_self(net->conn, line->args[0])) |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
220 |
// don't really care about our umode... |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
221 |
log_info("mode set: %s -> %s %s %s...", line->source->nickname, line->args[1], line->args[2], line->args[3]); |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
222 |
|
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
223 |
else |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
224 |
// it's a channel mode |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
225 |
irc_net_propagate_chan(net, line, line->args[0]); |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
226 |
|
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
227 |
} |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
228 |
|
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
229 |
/** |
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:
28
diff
changeset
|
230 |
* Our irc_cmd handler list |
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:
28
diff
changeset
|
231 |
*/ |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
232 |
struct irc_cmd_handler irc_net_cmd_handlers[] = { |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
233 |
// propagate certain messages to the appropriate channel |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
234 |
{ "QUIT", &irc_net_on_chanuser }, |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
235 |
{ "JOIN", &irc_net_on_chan0 }, |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
236 |
{ "PART", &irc_net_on_chan0 }, |
150
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
237 |
{ "MODE", &irc_net_on_MODE }, |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
238 |
{ "TOPIC", &irc_net_on_chan0 }, |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
239 |
{ "KICK", &irc_net_on_chan0 }, |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
240 |
{ IRC_RPL_NAMREPLY, &irc_net_on_chan2 }, |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
241 |
{ IRC_RPL_ENDOFNAMES, &irc_net_on_chan1 }, |
88
233916a00429
implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents:
86
diff
changeset
|
242 |
{ "CTCP ACTION", &irc_net_on_chan0 }, |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
243 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
244 |
// special-case handling for others |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
245 |
{ "NICK", &irc_net_on_NICK }, |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
246 |
// Note: no need to handle QUIT, as the channels should take care of irc_net_put_user'ing it away. |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
247 |
{ "PRIVMSG", &irc_net_on_msg }, |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
248 |
{ "NOTICE", &irc_net_on_msg }, |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
249 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
250 |
{ 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:
28
diff
changeset
|
251 |
}; |
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:
28
diff
changeset
|
252 |
|
217 | 253 |
err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, error_t *err) |
150
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
254 |
{ |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
255 |
struct irc_net *net; |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
256 |
|
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
257 |
// allocate |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
258 |
if ((net = calloc(1, sizeof(*net))) == NULL) |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
259 |
return SET_ERROR(err, ERR_CALLOC); |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
260 |
|
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
261 |
// initialize |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
262 |
// XXX: we need to copy *info's fields |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
263 |
net->info = *info; |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
264 |
TAILQ_INIT(&net->channels); |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
265 |
LIST_INIT(&net->users); |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
266 |
|
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
267 |
// init subsystems |
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
268 |
if (irc_net_connect_init(net, err)) |
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
269 |
goto error; |
150
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
270 |
|
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
271 |
// initial connect |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
272 |
if (irc_net_connect(net, true, err)) |
150
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
273 |
goto error; |
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
274 |
|
e8018446b336
special-case recieved user-mode messages, add irc_conn_self function
Tero Marttila <terom@fixme.fi>
parents:
147
diff
changeset
|
275 |
// ok |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
276 |
*net_ptr = net; |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
277 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
278 |
return SUCCESS; |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
279 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
280 |
error: |
47
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
281 |
// cleanup main |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
282 |
irc_net_destroy(net); |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
283 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
284 |
return ERROR_CODE(err); |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
285 |
} |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
286 |
|
47
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
287 |
void irc_net_destroy (struct irc_net *net) |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
288 |
{ |
140
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
289 |
struct irc_chan *chan_next = TAILQ_FIRST(&net->channels), *chan; |
147
fd97eb3c183a
fix bug with irc_net_destroy/users
Tero Marttila <terom@fixme.fi>
parents:
140
diff
changeset
|
290 |
struct irc_user *user_next, *user; |
47
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
291 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
292 |
// our conn |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
293 |
if (net->conn) |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
294 |
irc_conn_destroy(net->conn); |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
295 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
296 |
// our channels |
140
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
297 |
while ((chan = chan_next)) { |
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
298 |
chan_next = TAILQ_NEXT(chan, net_channels); |
47
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
299 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
300 |
irc_chan_destroy(chan); |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
301 |
} |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
302 |
|
140
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
303 |
// our users |
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
304 |
// XXX: this disregards external refs |
147
fd97eb3c183a
fix bug with irc_net_destroy/users
Tero Marttila <terom@fixme.fi>
parents:
140
diff
changeset
|
305 |
for (user_next = LIST_FIRST(&net->users); (user = user_next); ) { |
140
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
306 |
user_next = LIST_NEXT(user, net_users); |
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
307 |
|
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
308 |
irc_user_destroy(user); |
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
309 |
} |
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
310 |
|
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
311 |
// our info |
aa390e52eda8
implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
312 |
if (net->info.ssl_cred) |
180
22967b165692
rename sock_ssl/sock_gnutls -> ssl/ssl_client
Tero Marttila <terom@fixme.fi>
parents:
172
diff
changeset
|
313 |
ssl_client_cred_put(net->info.ssl_cred); |
153
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
314 |
|
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
315 |
// misc |
d35e7cb3a489
implement irc_net reconnect, requires testing
Tero Marttila <terom@fixme.fi>
parents:
150
diff
changeset
|
316 |
irc_net_connect_destroy(net); |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
317 |
|
47
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
318 |
// ourselves |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
319 |
free(net); |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
320 |
} |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
321 |
|
217 | 322 |
err_t irc_net_add_chan (struct irc_net *net, struct irc_chan **chan_ptr, const struct irc_chan_info *info, error_t *err) |
26 | 323 |
{ |
324 |
struct irc_chan *chan; |
|
325 |
||
326 |
// create the new irc_chan struct |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
327 |
if (irc_chan_create(&chan, net, info, err)) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
328 |
return ERROR_CODE(err); |
26 | 329 |
|
330 |
// add to network list |
|
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
331 |
TAILQ_INSERT_TAIL(&net->channels, chan, net_channels); |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
332 |
|
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
333 |
// currently connected? |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
334 |
if (net->conn && net->conn->registered) { |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
335 |
// then join |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
336 |
if ((ERROR_CODE(err) = irc_chan_join(chan))) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
337 |
return ERROR_CODE(err); |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
338 |
} |
26 | 339 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
340 |
// ok |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
341 |
if (chan_ptr) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
342 |
*chan_ptr = chan; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
343 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
344 |
return SUCCESS; |
26 | 345 |
} |
346 |
||
347 |
struct irc_chan* irc_net_get_chan (struct irc_net *net, const char *channel) |
|
348 |
{ |
|
349 |
struct irc_chan *chan = NULL; |
|
350 |
||
351 |
// look for it... |
|
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
352 |
TAILQ_FOREACH(chan, &net->channels, net_channels) { |
26 | 353 |
if (strcasecmp(chan->info.channel, channel) == 0) |
354 |
// found it |
|
355 |
return chan; |
|
356 |
} |
|
357 |
||
358 |
// no such channel |
|
359 |
return NULL; |
|
360 |
} |
|
361 |
||
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
362 |
err_t irc_net_get_user (struct irc_net *net, struct irc_user **user_ptr, const char *nickname) |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
363 |
{ |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
364 |
struct irc_user *user; |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
365 |
err_t err; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
366 |
|
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
367 |
// lookup |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
368 |
if ((user = irc_net_lookup_user(net, nickname)) == NULL) { |
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
|
369 |
// create a new user struct |
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
|
370 |
if ((err = irc_user_create(&user, net, nickname))) |
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
|
371 |
return err; |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
372 |
|
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
|
373 |
// add to our 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
|
374 |
LIST_INSERT_HEAD(&net->users, user, net_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
|
375 |
|
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
|
376 |
} else { |
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
|
377 |
// check for refcount overflow |
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
|
378 |
assert(user->refcount < SIZE_MAX); |
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
|
379 |
} |
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
|
380 |
|
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
|
381 |
// 'get' it |
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
|
382 |
user->refcount++; |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
383 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
384 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
385 |
*user_ptr = user; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
386 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
387 |
return SUCCESS; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
388 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
389 |
|
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
|
390 |
void irc_net_put_user (struct irc_net *net, struct irc_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
|
391 |
{ |
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
|
392 |
(void) net; |
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
|
393 |
|
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
|
394 |
assert(user->refcount > 0); |
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
|
395 |
|
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
|
396 |
// nothing if it's still in use elsewhere |
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
|
397 |
if (--user->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
|
398 |
return; |
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
|
399 |
|
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
|
400 |
// 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
|
401 |
LIST_REMOVE(user, net_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
|
402 |
|
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
|
403 |
// destroy |
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
|
404 |
irc_user_destroy(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
|
405 |
} |
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
|
406 |
|
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
407 |
err_t irc_net_quit (struct irc_net *net, const char *message) |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
408 |
{ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
409 |
if (!net->conn) |
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
88
diff
changeset
|
410 |
return ERR_IRC_NET_STATE; |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
411 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
412 |
// send the QUIT message, and then we can wait for the reply |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
413 |
return irc_conn_QUIT(net->conn, message); |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
414 |
} |