ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/packet.C
Revision: 1.4
Committed: Tue Aug 28 17:08:12 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +10 -17 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

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.3 2007-07-21 13:23:22 pippijn Exp $";
9
10 #include "atheme.h"
11 #include "uplink.h"
12 #include "datastream.h"
13
14 static void on_connected (connection_t *cptr);
15
16 /* bursting timer */
17 #if HAVE_GETTIMEOFDAY
18 struct timeval burstime;
19 #endif
20
21 static void
22 irc_recvq_handler (connection_t *cptr)
23 {
24 bool wasnonl;
25 char parsebuf[BUFSIZE + 1];
26 int count;
27
28 wasnonl = cptr->flags & CF_NONEWLINE ? true : false;
29 count = recvq_getline (cptr, parsebuf, sizeof parsebuf - 1);
30 if (count <= 0)
31 return;
32 cnt.bin += count;
33 /* ignore the excessive part of a too long line */
34 if (wasnonl)
35 return;
36 me.uplinkpong = NOW;
37 if (parsebuf[count - 1] == '\n')
38 count--;
39 if (count > 0 && parsebuf[count - 1] == '\r')
40 count--;
41 parsebuf[count] = '\0';
42 parse (parsebuf);
43 }
44
45 static void
46 ping_uplink (void *arg)
47 {
48 unsigned int diff;
49
50 if (me.connected)
51 {
52 phandler->ping_sts ();
53
54 diff = NOW - me.uplinkpong;
55
56 if (diff >= 600)
57 {
58 slog (LG_INFO, "ping_uplink(): uplink appears to be dead, disconnecting");
59 sts ("ERROR :Closing Link: 127.0.0.1 (Ping timeout: %d seconds)", diff);
60 sendq_flush (curr_uplink->conn);
61 if (me.connected)
62 {
63 errno = 0;
64 connection_close (curr_uplink->conn);
65 }
66 }
67 }
68
69 if (!me.connected)
70 event_delete (ping_uplink, NULL);
71 }
72
73 static void
74 on_connected (connection_t *cptr)
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 phandler->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 phandler->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 = NOW;
102 }
103 }
104
105 void
106 init_ircpacket (void)
107 {
108 connection_t::callback.connected.attach (on_connected);
109 }