author | Tero Marttila <terom@fixme.fi> |
Tue, 31 Mar 2009 22:09:53 +0300 | |
changeset 98 | f357f835f0d5 |
parent 97 | d3bc82ee76cb |
child 138 | a716c621cb90 |
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" |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
#include "log.h" |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
#include <stdlib.h> |
26 | 5 |
#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
|
6 |
#include <assert.h> |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
8 |
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
|
9 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
10 |
return net->info.network; |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
11 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
12 |
|
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
|
13 |
/** |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
14 |
* Something happaned which caused our irc_conn to fail. Destroy it, and recover. XXX: somehow |
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 |
*/ |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
16 |
static void irc_net_error (struct irc_net *net, struct error_info *err) |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
17 |
{ |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
18 |
struct irc_chan *chan = NULL; |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
19 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
20 |
// log an error |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
21 |
log_err_info(err, "irc_conn failed"); |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
22 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
23 |
// destroy connection and set NULL |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
24 |
irc_conn_destroy(net->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
|
25 |
net->conn = NULL; |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
26 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
27 |
// update channel state |
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
28 |
TAILQ_FOREACH(chan, &net->channels, net_channels) { |
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
|
29 |
// XXX: notify channel somehow |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
30 |
} |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
31 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
32 |
// XXX: reconnect? |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
33 |
} |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
34 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
35 |
/** |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
36 |
* 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
|
37 |
* |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
38 |
* This does not refcount anything. |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
39 |
*/ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
40 |
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
|
41 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
42 |
struct irc_user *user = NULL; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
43 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
44 |
// look for it... |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
// found existing |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
48 |
return user; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
49 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
50 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
51 |
// not found |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
52 |
return NULL; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
53 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
54 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
55 |
/** |
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
|
56 |
* 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
|
57 |
*/ |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
58 |
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
|
59 |
{ |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
60 |
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
|
61 |
struct irc_chan *chan = NULL; |
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 |
struct error_info err; |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
63 |
|
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
64 |
(void) conn; |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
65 |
|
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
66 |
// join our channels |
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
67 |
TAILQ_FOREACH(chan, &net->channels, net_channels) { |
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
|
68 |
if ((ERROR_CODE(&err) = irc_chan_join(chan))) |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
69 |
// XXX: this should be some kind of irc_chan_error instead |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
70 |
irc_net_error(net, &err); |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
71 |
} |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
72 |
} |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
73 |
|
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
|
74 |
/** |
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
75 |
* 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
|
76 |
*/ |
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
|
77 |
static void irc_net_conn_error (struct irc_conn *conn, struct error_info *err, void *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
|
78 |
{ |
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
|
79 |
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
|
80 |
|
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
|
81 |
(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
|
82 |
|
0c13bca53ae1
add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
83 |
irc_net_error(net, err); |
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
|
84 |
} |
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
|
85 |
|
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
86 |
/** |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
87 |
* Our irc_conn has quit succesfully |
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 |
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
|
90 |
{ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
91 |
struct irc_net *net = arg; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
92 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
93 |
// clean up the conn |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
94 |
irc_conn_destroy(conn); |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
95 |
net->conn = NULL; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
96 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
97 |
// XXX: notify user |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
98 |
} |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
99 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
100 |
/** |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
101 |
* 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
|
102 |
*/ |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
103 |
struct irc_conn_callbacks _conn_callbacks = { |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
104 |
.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
|
105 |
.on_error = &irc_net_conn_error, |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
106 |
.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
|
107 |
}; |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
108 |
|
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 |
/** |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
110 |
* 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
|
111 |
*/ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
112 |
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
|
113 |
{ |
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 |
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
|
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 |
// look up channel |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
} |
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
|
121 |
|
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
|
122 |
// 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
|
123 |
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
|
124 |
} |
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
|
125 |
|
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
|
126 |
/** |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
127 |
* 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
|
128 |
*/ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
129 |
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
|
130 |
{ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
131 |
struct irc_net *net = arg; |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
132 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
133 |
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
|
134 |
} |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
135 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
136 |
/** |
72
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[1] |
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_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
|
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[1]); |
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 |
/** |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
147 |
* 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
|
148 |
*/ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
149 |
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
|
150 |
{ |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
151 |
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
|
152 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
153 |
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
|
154 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
155 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
156 |
/** |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
157 |
* 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
|
158 |
*/ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
159 |
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
|
160 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
161 |
struct irc_net *net = arg; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
162 |
struct irc_chan *chan; |
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 |
// scan each channel |
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
165 |
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
|
166 |
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
|
167 |
// propagate |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
168 |
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
|
169 |
} |
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 |
} |
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 |
/** |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
174 |
* :nm NICK <nickname> |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
175 |
* |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
176 |
* 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
|
177 |
* |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
178 |
* 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
|
179 |
* the irc_user. |
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 |
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
|
182 |
{ |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
183 |
struct irc_net *net = arg; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
184 |
struct irc_user *user; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
185 |
err_t err; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
186 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
187 |
// ignore for unknown |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
188 |
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
|
189 |
return; |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
190 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
191 |
// propagate to channels |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
192 |
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
|
193 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
194 |
// rename them |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
195 |
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
|
196 |
// XXX: what to do? |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
197 |
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
|
198 |
} |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
199 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
200 |
/** |
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
|
201 |
* :nm (PRIVMSG|NOTICE) <target> <message> |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
202 |
* |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
203 |
* 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
|
204 |
*/ |
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
|
205 |
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
|
206 |
{ |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
207 |
struct irc_net *net = arg; |
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 |
// XXX: does two lookups |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
210 |
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
|
211 |
// short-circuit to on_chan0 |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
212 |
irc_net_on_chan0(line, arg); |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
213 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
214 |
} else { |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
215 |
// XXX: callbacks for privmsgs |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
216 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
217 |
} |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
218 |
} |
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
219 |
|
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
220 |
/** |
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
|
221 |
* 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
|
222 |
*/ |
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
|
223 |
static struct irc_cmd_handler _cmd_handlers[] = { |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
224 |
// 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
|
225 |
{ "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
|
226 |
{ "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
|
227 |
{ "PART", &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
|
228 |
{ "MODE", &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
|
229 |
{ "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
|
230 |
{ "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
|
231 |
{ 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
|
232 |
{ 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
|
233 |
{ "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
|
234 |
|
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
235 |
// special-case handling for others |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
236 |
{ "NICK", &irc_net_on_NICK }, |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
237 |
// 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
|
238 |
{ "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
|
239 |
{ "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
|
240 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
241 |
{ 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
|
242 |
}; |
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
|
243 |
|
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
244 |
/** |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
245 |
* The given socket is now connected, so create the irc_conn and bind it in to us |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
246 |
*/ |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
247 |
static err_t irc_net_connected (struct irc_net *net, struct sock_stream *sock, struct error_info *err) |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
248 |
{ |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
249 |
// create the irc connection state |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
250 |
if (irc_conn_create(&net->conn, sock, &_conn_callbacks, net, err)) |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
251 |
return ERROR_CODE(err); |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
252 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
253 |
// add our command handlers |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
254 |
if ((ERROR_CODE(err) = irc_conn_add_cmd_handlers (net->conn, _cmd_handlers, net))) |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
255 |
return ERROR_CODE(err); |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
256 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
257 |
// register |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
258 |
if ((ERROR_CODE(err) = irc_conn_register(net->conn, &net->info.register_info))) |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
259 |
return ERROR_CODE(err); |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
260 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
261 |
// ok |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
262 |
return SUCCESS; |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
263 |
} |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
264 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
265 |
static void irc_net_on_connect (struct sock_stream *sock, struct error_info *conn_err, void *arg) |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
266 |
{ |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
267 |
struct irc_net *net = arg; |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
268 |
struct error_info err; |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
269 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
270 |
// XXX: better error handling |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
271 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
272 |
// trap errors |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
273 |
if (conn_err) |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
274 |
FATAL_ERROR(conn_err, "async TCP connect failed"); |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
275 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
276 |
// ok, yay |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
277 |
if (irc_net_connected(net, sock, &err)) |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
278 |
FATAL_ERROR(&err, "irc_net_connected failed"); |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
279 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
280 |
// XXX: cleanup |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
281 |
} |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
282 |
|
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
283 |
err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err) |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
284 |
{ |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
285 |
struct irc_net *net; |
28
9c1050bc8709
add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents:
27
diff
changeset
|
286 |
struct sock_stream *sock = NULL; |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
287 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
288 |
// allocate |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
289 |
if ((net = calloc(1, sizeof(*net))) == NULL) |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
290 |
return SET_ERROR(err, ERR_CALLOC); |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
291 |
|
26 | 292 |
// initialize |
53
12d806823775
add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
293 |
net->info = *info; |
26 | 294 |
TAILQ_INIT(&net->channels); |
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
295 |
LIST_INIT(&net->users); |
26 | 296 |
|
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
297 |
// non-async socket connect? |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
298 |
if (info->raw_sock || info->use_ssl) { |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
299 |
// create the socket |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
300 |
if (info->raw_sock) { |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
301 |
log_debug("connected using raw socket: %p", info->raw_sock); |
44 | 302 |
|
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
303 |
sock = info->raw_sock; |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
304 |
|
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
305 |
} else if (info->use_ssl) { |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
306 |
log_debug("connecting to [%s]:%s using SSL", info->hostname, info->service); |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
307 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
308 |
// XXX: over-simplified blocking connect |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
309 |
if (sock_ssl_connect(&sock, info->hostname, info->service, err)) |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
310 |
goto error; |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
311 |
} |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
312 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
313 |
// then create the conn right away |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
314 |
if (irc_net_connected(net, sock, err)) |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
315 |
goto error; |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
316 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
317 |
} else { |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
72
diff
changeset
|
318 |
log_debug("connecting to [%s]:%s", info->hostname, info->service); |
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
319 |
|
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
320 |
// begin async connect |
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
321 |
if (sock_tcp_connect_async(&sock, info->hostname, info->service, &irc_net_on_connect, net, err)) |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
322 |
goto error; |
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
323 |
|
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
324 |
} |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
325 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
326 |
// ok |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
327 |
*net_ptr = net; |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
328 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
329 |
return SUCCESS; |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
330 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
331 |
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
|
332 |
if (sock && !net->conn) |
28
9c1050bc8709
add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents:
27
diff
changeset
|
333 |
// we need to clean up the socket ourself |
9c1050bc8709
add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents:
27
diff
changeset
|
334 |
sock_stream_release(sock); |
9c1050bc8709
add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents:
27
diff
changeset
|
335 |
|
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
|
336 |
// 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
|
337 |
irc_net_destroy(net); |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
338 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
339 |
return ERROR_CODE(err); |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
340 |
} |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
341 |
|
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
|
342 |
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
|
343 |
{ |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
344 |
struct irc_chan *next = TAILQ_FIRST(&net->channels), *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
|
345 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
346 |
// 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
|
347 |
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
|
348 |
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
|
349 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
350 |
// our channels |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
351 |
while (next) { |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
352 |
chan = next; |
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
353 |
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
|
354 |
|
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
355 |
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
|
356 |
} |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
357 |
|
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
358 |
// XXX: our users |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
359 |
|
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
|
360 |
// 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
|
361 |
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
|
362 |
} |
7d4094eb3117
add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents:
46
diff
changeset
|
363 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
364 |
err_t irc_net_add_chan (struct irc_net *net, struct irc_chan **chan_ptr, const struct irc_chan_info *info, struct error_info *err) |
26 | 365 |
{ |
366 |
struct irc_chan *chan; |
|
367 |
||
368 |
// 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
|
369 |
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
|
370 |
return ERROR_CODE(err); |
26 | 371 |
|
372 |
// add to network list |
|
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
373 |
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
|
374 |
|
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
375 |
// currently connected? |
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
376 |
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
|
377 |
// then join |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
378 |
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
|
379 |
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
|
380 |
} |
26 | 381 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
382 |
// ok |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
383 |
if (chan_ptr) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
384 |
*chan_ptr = chan; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
385 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
386 |
return SUCCESS; |
26 | 387 |
} |
388 |
||
389 |
struct irc_chan* irc_net_get_chan (struct irc_net *net, const char *channel) |
|
390 |
{ |
|
391 |
struct irc_chan *chan = NULL; |
|
392 |
||
393 |
// look for it... |
|
86
5e7e64544cb7
some irc_net code to use said async connects
Tero Marttila <terom@fixme.fi>
parents:
78
diff
changeset
|
394 |
TAILQ_FOREACH(chan, &net->channels, net_channels) { |
26 | 395 |
if (strcasecmp(chan->info.channel, channel) == 0) |
396 |
// found it |
|
397 |
return chan; |
|
398 |
} |
|
399 |
||
400 |
// no such channel |
|
401 |
return NULL; |
|
402 |
} |
|
403 |
||
72
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
404 |
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
|
405 |
{ |
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
406 |
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
|
407 |
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
|
408 |
|
78
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
409 |
// lookup |
941bb8379d3d
implement NICK/QUIT handling for irc_net/irc_chan
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
410 |
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
|
411 |
// 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
|
412 |
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
|
413 |
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
|
414 |
|
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
|
415 |
// 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
|
416 |
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
|
417 |
|
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
|
418 |
} 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
|
419 |
// 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
|
420 |
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
|
421 |
} |
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
|
422 |
|
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
|
423 |
// '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
|
424 |
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
|
425 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
426 |
// ok |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
427 |
*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
|
428 |
|
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
429 |
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
|
430 |
} |
43084f103c2a
add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
431 |
|
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
|
432 |
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
|
433 |
{ |
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
|
434 |
(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
|
435 |
|
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
|
436 |
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
|
437 |
|
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
|
438 |
// 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
|
439 |
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
|
440 |
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
|
441 |
|
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
|
442 |
// 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
|
443 |
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
|
444 |
|
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
|
445 |
// 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
|
446 |
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
|
447 |
} |
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
|
448 |
|
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
449 |
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
|
450 |
{ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
451 |
if (!net->conn) |
97
d3bc82ee76cb
add irc_conn_PRIVMSG/irc_chan_PRIVMSG and lua bindings
Tero Marttila <terom@fixme.fi>
parents:
88
diff
changeset
|
452 |
return ERR_IRC_NET_STATE; |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
453 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
454 |
// 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
|
455 |
return irc_conn_QUIT(net->conn, message); |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
47
diff
changeset
|
456 |
} |