1 |
pippijn |
1.1 |
/* |
2 |
|
|
* packet.C: IRC packet handling. |
3 |
|
|
* Rights to this code are documented in doc/LICENSE. |
4 |
|
|
* |
5 |
|
|
* Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
static char const rcsid[] = "$Id"; |
9 |
|
|
|
10 |
|
|
#include "atheme.h" |
11 |
|
|
#include "uplink.h" |
12 |
|
|
#include "datastream.h" |
13 |
|
|
|
14 |
|
|
/* bursting timer */ |
15 |
|
|
#if HAVE_GETTIMEOFDAY |
16 |
|
|
struct timeval burstime; |
17 |
|
|
#endif |
18 |
|
|
|
19 |
|
|
static void |
20 |
|
|
irc_recvq_handler (connection_t *cptr) |
21 |
|
|
{ |
22 |
|
|
bool wasnonl; |
23 |
|
|
char parsebuf[BUFSIZE + 1]; |
24 |
|
|
int count; |
25 |
|
|
|
26 |
|
|
wasnonl = cptr->flags & CF_NONEWLINE ? true : false; |
27 |
|
|
count = recvq_getline (cptr, parsebuf, sizeof parsebuf - 1); |
28 |
|
|
if (count <= 0) |
29 |
|
|
return; |
30 |
|
|
cnt.bin += count; |
31 |
|
|
/* ignore the excessive part of a too long line */ |
32 |
|
|
if (wasnonl) |
33 |
|
|
return; |
34 |
|
|
me.uplinkpong = NOW; |
35 |
|
|
if (parsebuf[count - 1] == '\n') |
36 |
|
|
count--; |
37 |
|
|
if (count > 0 && parsebuf[count - 1] == '\r') |
38 |
|
|
count--; |
39 |
|
|
parsebuf[count] = '\0'; |
40 |
|
|
parse (parsebuf); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
static void |
44 |
|
|
ping_uplink (void *arg) |
45 |
|
|
{ |
46 |
|
|
unsigned int diff; |
47 |
|
|
|
48 |
|
|
if (me.connected) |
49 |
|
|
{ |
50 |
|
|
ping_sts (); |
51 |
|
|
|
52 |
|
|
diff = NOW - me.uplinkpong; |
53 |
|
|
|
54 |
|
|
if (diff >= 600) |
55 |
|
|
{ |
56 |
|
|
slog (LG_INFO, "ping_uplink(): uplink appears to be dead, disconnecting"); |
57 |
|
|
sts ("ERROR :Closing Link: 127.0.0.1 (Ping timeout: %d seconds)", diff); |
58 |
|
|
sendq_flush (curr_uplink->conn); |
59 |
|
|
if (me.connected) |
60 |
|
|
{ |
61 |
|
|
errno = 0; |
62 |
|
|
connection_close (curr_uplink->conn); |
63 |
|
|
} |
64 |
|
|
} |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
if (!me.connected) |
68 |
|
|
event_delete (ping_uplink, NULL); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
static void |
72 |
|
|
irc_handle_connect (void *vptr) |
73 |
|
|
{ |
74 |
|
|
connection_t *cptr = static_cast<connection_t *> (vptr); |
75 |
|
|
|
76 |
|
|
/* add our server */ |
77 |
|
|
|
78 |
|
|
if (cptr == curr_uplink->conn) |
79 |
|
|
{ |
80 |
|
|
cptr->flags = CF_UPLINK; |
81 |
|
|
cptr->recvq_handler = irc_recvq_handler; |
82 |
|
|
me.connected = true; |
83 |
|
|
/* no SERVER message received */ |
84 |
|
|
me.recvsvr = false; |
85 |
|
|
|
86 |
|
|
slog (LG_INFO, "irc_handle_connect(): connection to uplink established"); |
87 |
|
|
|
88 |
|
|
server_login (); |
89 |
|
|
|
90 |
|
|
#ifdef HAVE_GETTIMEOFDAY |
91 |
|
|
/* start our burst timer */ |
92 |
|
|
s_time (&burstime); |
93 |
|
|
#endif |
94 |
|
|
|
95 |
|
|
/* done bursting by this time... */ |
96 |
|
|
ping_sts (); |
97 |
|
|
|
98 |
|
|
/* ping our uplink every 5 minutes */ |
99 |
|
|
event_delete (ping_uplink, NULL); |
100 |
|
|
event_add ("ping_uplink", ping_uplink, NULL, 300); |
101 |
|
|
me.uplinkpong = time (NULL); |
102 |
|
|
} |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
void |
106 |
|
|
init_ircpacket (void) |
107 |
|
|
{ |
108 |
|
|
hook_add_event ("connected"); |
109 |
|
|
hook_add_hook ("connected", irc_handle_connect); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
113 |
|
|
* vim:ts=8 |
114 |
|
|
* vim:sw=8 |
115 |
|
|
* vim:noexpandtab |
116 |
|
|
*/ |