ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/packet.C
Revision: 1.6
Committed: Wed Sep 5 11:23:15 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +3 -3 lines
Log Message:
removed GPLed code and put license back to BSD

File Contents

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