annotate src/protocols/oscar/flap_connection.c @ 13868:b355f7ed1814

[gaim-migrate @ 16334] This should cause the logging DBUS registration to actually work. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 24 Jun 2006 22:52:59 +0000
parents 65a39e436567
children 8a8b4f7f7d99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * Gaim's oscar protocol plugin
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 * This file is the legal property of its developers.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 * Please see the AUTHORS file distributed alongside this file.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 * Lesser General Public License for more details.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 #include "oscar.h"
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 #include "eventloop.h"
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25 #ifndef _WIN32
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
26 #include <netdb.h>
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
27 #include <sys/socket.h>
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28 #include <netinet/in.h>
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 #endif
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 #ifdef _WIN32
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32 #include "win32dep.h"
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 #endif
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 * This sends a channel 1 SNAC containing the FLAP version.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 * The FLAP version is sent by itself at the beginning of every
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 * connection to a FLAP server. It is always the very first
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39 * packet sent by both the server and the client after the SYN,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40 * SYN/ACK, ACK handshake.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43 flap_connection_send_version(OscarData *od, FlapConnection *conn)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
45 FlapFrame *frame;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
47 frame = flap_frame_new(od, 0x01, 4);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
48 byte_stream_put32(&frame->data, 0x00000001);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49 flap_connection_send(conn, frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
51
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
52 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 * This sends a channel 1 SNAC containing the FLAP version and
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
54 * the authentication cookie. This is sent when connecting to
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55 * any FLAP server after the initial connection to the auth
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 * server. It is always the very first packet sent by both the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 * server and the client after the SYN, SYN/ACK, ACK handshake.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 flap_connection_send_version_with_cookie(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 FlapFrame *frame;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63 aim_tlvlist_t *tl = NULL;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65 frame = flap_frame_new(od, 0x01, 4 + 2 + 2 + length);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 byte_stream_put32(&frame->data, 0x00000001);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 aim_tlvlist_add_raw(&tl, 0x0006, length, chipsahoy);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68 aim_tlvlist_write(&frame->data, &tl);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 aim_tlvlist_free(&tl);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71 flap_connection_send(conn, frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 * This sends an empty channel 4 SNAC. This is sent to signify
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76 * that we're logging off. This shouldn't really be necessary--
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77 * usually the AIM server will detect that the TCP connection has
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78 * been destroyed--but it's good practice.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81 flap_connection_send_close(OscarData *od, FlapConnection *conn)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 FlapFrame *frame;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85 frame = flap_frame_new(od, 0x04, 0);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 flap_connection_send(conn, frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 * This sends an empty channel 5 SNAC. This is used as a keepalive
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91 * packet in FLAP connections. WinAIM 4.x and higher send these
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92 * _every minute_ to keep the connection alive.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95 flap_connection_send_keepalive(OscarData *od, FlapConnection *conn)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 FlapFrame *frame;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 frame = flap_frame_new(od, 0x05, 0);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 flap_connection_send(conn, frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 /* clean out SNACs over 60sec old */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
103 aim_cleansnacs(od, 60);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 * Allocate a new empty connection structure.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 * @param od The oscar session associated with this connection.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 * @param type Type of connection to create
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 * @return Returns the new connection structure.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 FlapConnection *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 flap_connection_new(OscarData *od, int type)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117 FlapConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119 conn = g_new0(FlapConnection, 1);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120 conn->od = od;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 conn->buffer_outgoing = gaim_circ_buffer_new(0);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 conn->fd = -1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123 conn->subtype = -1;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 conn->type = type;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
125
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
126 od->oscar_connections = g_list_prepend(od->oscar_connections, conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
127
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128 return conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
129 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 * Close (but not free) a connection.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
134 * This leaves everything untouched except for setting the fd
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 * to -1 (used to recognize dead connections).
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
136 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
137 * @param conn The connection to close.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
138 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
139 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
140 flap_connection_close(OscarData *od, FlapConnection *conn)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
141 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
142 if (conn->fd == -1)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
143 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
144
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
145 if (conn->type == SNAC_FAMILY_LOCATE)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 flap_connection_send_close(od, conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
147
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
148 close(conn->fd);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
149 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
150
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
151 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
152 flap_connection_destroy_rates(struct rateclass *head)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
153 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
154 struct rateclass *rc;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
155
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156 for (rc = head; rc; )
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
157 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
158 struct rateclass *tmp;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
159 struct snacpair *sp;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
160
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
161 tmp = rc->next;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
162
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
163 for (sp = rc->members; sp; ) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164 struct snacpair *tmpsp;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
165
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 tmpsp = sp->next;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
167 free(sp);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
168 sp = tmpsp;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
169 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170 free(rc);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
171
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
172 rc = tmp;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
173 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
174 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
175
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
176 static gboolean
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
177 flap_connection_destroy_cb(gpointer data)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
178 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
179 FlapConnection *conn;
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
180 OscarData *od;
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
181 GaimAccount *account;
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
182
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
183 conn = data;
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
184 od = conn->od;
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
185
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
186 gaim_debug_info("oscar", "Destroying oscar connection of "
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
187 "type 0x%04hx\n", conn->type);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
188
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
189 flap_connection_close(od, conn);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
190
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
191 if (conn->watcher_incoming != 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
192 gaim_input_remove(conn->watcher_incoming);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
193 if (conn->watcher_outgoing != 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
194 gaim_input_remove(conn->watcher_outgoing);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
195 g_free(conn->buffer_incoming.data.data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
196 gaim_circ_buffer_destroy(conn->buffer_outgoing);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
197
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 * Free conn->internal, if necessary
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
201 if (conn->type == SNAC_FAMILY_CHAT)
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
202 flap_connection_destroy_chat(od, conn);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203
13611
7f91efd5af77 [gaim-migrate @ 15997]
Mark Doliner <mark@kingant.net>
parents: 13610
diff changeset
204 g_list_free(conn->groups);
13609
5796551db930 [gaim-migrate @ 15995]
Mark Doliner <mark@kingant.net>
parents: 13608
diff changeset
205 flap_connection_destroy_rates(conn->rates);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
206
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
207 od->oscar_connections = g_list_remove(od->oscar_connections, conn);
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
208 g_free(conn);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
209
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
210 account = gaim_connection_get_account(od->gc);
13724
65a39e436567 [gaim-migrate @ 16133]
Mark Doliner <mark@kingant.net>
parents: 13611
diff changeset
211
65a39e436567 [gaim-migrate @ 16133]
Mark Doliner <mark@kingant.net>
parents: 13611
diff changeset
212 /*
65a39e436567 [gaim-migrate @ 16133]
Mark Doliner <mark@kingant.net>
parents: 13611
diff changeset
213 * TODO: If we don't have a SNAC_FAMILY_LOCATE connection then
65a39e436567 [gaim-migrate @ 16133]
Mark Doliner <mark@kingant.net>
parents: 13611
diff changeset
214 * we should try to request one instead of disconnecting.
65a39e436567 [gaim-migrate @ 16133]
Mark Doliner <mark@kingant.net>
parents: 13611
diff changeset
215 */
65a39e436567 [gaim-migrate @ 16133]
Mark Doliner <mark@kingant.net>
parents: 13611
diff changeset
216 if (!account->disconnecting && ((od->oscar_connections == NULL)
65a39e436567 [gaim-migrate @ 16133]
Mark Doliner <mark@kingant.net>
parents: 13611
diff changeset
217 || (!flap_connection_getbytype(od, SNAC_FAMILY_LOCATE))))
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
218 {
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
219 /* No more FLAP connections! Sign off this GaimConnection! */
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
220 const gchar *tmp;
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
221 if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED)
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
222 tmp = _("Server closed the connection.");
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
223 else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION)
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
224 tmp = _("Lost connection with server for an unknown reason.");
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
225 else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA)
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
226 tmp = _("Received invalid data on connection with server.");
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
227 else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT)
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
228 tmp = _("Could not establish a connection with the server.");
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
229 else
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
230 tmp = NULL;
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
231
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
232 if (tmp != NULL)
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
233 gaim_connection_error(od->gc, tmp);
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
234 }
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
235
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
236 return FALSE;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
237 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
238
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
239 void
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
240 flap_connection_destroy(FlapConnection *conn, OscarDisconnectReason reason)
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
241 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
242 if (conn->destroy_timeout != 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243 gaim_timeout_remove(conn->destroy_timeout);
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
244 conn->disconnect_reason = reason;
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245 flap_connection_destroy_cb(conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
248 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
249 * Schedule Gaim to destroy the given FlapConnection as soon as we
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
250 * return control back to the program's main loop. We must do this
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
251 * if we want to destroy the connection but we are still using it
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
252 * for some reason.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
253 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 void
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
255 flap_connection_schedule_destroy(FlapConnection *conn, OscarDisconnectReason reason)
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257 if (conn->destroy_timeout != 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258 /* Already taken care of */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
260
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
261 gaim_debug_info("oscar", "Scheduling destruction of FLAP "
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
262 "connection of type 0x%04hx\n", conn->type);
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
263 conn->disconnect_reason = reason;
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
264 conn->destroy_timeout = gaim_timeout_add(0, flap_connection_destroy_cb, conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
266
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
267 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
268 * In OSCAR, every connection has a set of SNAC groups associated
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 * with it. These are the groups that you can send over this connection
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
270 * without being guaranteed a "Not supported" SNAC error.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
271 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
272 * The grand theory of things says that these associations transcend
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
273 * what libfaim calls "connection types" (conn->type). You can probably
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
274 * see the elegance here, but since I want to revel in it for a bit, you
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
275 * get to hear it all spelled out.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
276 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
277 * So let us say that you have your core BOS connection running. One
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
278 * of your modules has just given you a SNAC of the group 0x0004 to send
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
279 * you. Maybe an IM destined for some twit in Greenland. So you start
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
280 * at the top of your connection list, looking for a connection that
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281 * claims to support group 0x0004. You find one. Why, that neat BOS
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
282 * connection of yours can do that. So you send it on its way.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
283 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
284 * Now, say, that fellow from Greenland has friends and they all want to
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
285 * meet up with you in a lame chat room. This has landed you a SNAC
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
286 * in the family 0x000e and you have to admit you're a bit lost. You've
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287 * searched your connection list for someone who wants to make your life
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
288 * easy and deliver this SNAC for you, but there isn't one there.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
289 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
290 * Here comes the good bit. Without even letting anyone know, particularly
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
291 * the module that decided to send this SNAC, and definitely not that twit
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
292 * in Greenland, you send out a service request. In this request, you have
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
293 * marked the need for a connection supporting group 0x000e. A few seconds
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
294 * later, you receive a service redirect with an IP address and a cookie in
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
295 * it. Great, you say. Now I have something to do. Off you go, making
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
296 * that connection. One of the first things you get from this new server
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
297 * is a message saying that indeed it does support the group you were looking
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
298 * for. So you continue and send rate confirmation and all that.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
299 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
300 * Then you remember you had that SNAC to send, and now you have a means to
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
301 * do it, and you do, and everyone is happy. Except the Greenlander, who is
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
302 * still stuck in the bitter cold.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
303 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
304 * Oh, and this is useful for building the Migration SNACs, too. In the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
305 * future, this may help convince me to implement rate limit mitigation
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
306 * for real. We'll see.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
307 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
308 * Just to make me look better, I'll say that I've known about this great
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
309 * scheme for quite some time now. But I still haven't convinced myself
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
310 * to make libfaim work that way. It would take a fair amount of effort,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
311 * and probably some client API changes as well. (Whenever I don't want
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
312 * to do something, I just say it would change the client API. Then I
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
313 * instantly have a couple of supporters of not doing it.)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
314 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
315 * Generally, addgroup is only called by the internal handling of the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
316 * server ready SNAC. So if you want to do something before that, you'll
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
317 * have to be more creative. That is done rather early, though, so I don't
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
318 * think you have to worry about it. Unless you're me. I care deeply
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
319 * about such inane things.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
320 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
321 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
322
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
323 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
324 * Find a FlapConnection that supports the given oscar
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
325 * family.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
326 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
327 FlapConnection *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
328 flap_connection_findbygroup(OscarData *od, guint16 group)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
329 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
330 GList *cur;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
331
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
332 for (cur = od->oscar_connections; cur != NULL; cur = cur->next)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
333 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
334 FlapConnection *conn;
13611
7f91efd5af77 [gaim-migrate @ 15997]
Mark Doliner <mark@kingant.net>
parents: 13610
diff changeset
335 GList *l;
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
336
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
337 conn = cur->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
338
13611
7f91efd5af77 [gaim-migrate @ 15997]
Mark Doliner <mark@kingant.net>
parents: 13610
diff changeset
339 for (l = conn->groups; l != NULL; l = l->next)
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
340 {
13611
7f91efd5af77 [gaim-migrate @ 15997]
Mark Doliner <mark@kingant.net>
parents: 13610
diff changeset
341 if (GPOINTER_TO_UINT(l->data) == group)
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
342 return conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
343 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
344 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
345
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
346 return NULL;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
347 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
348
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
349 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
350 * Locates a connection of the specified type in the
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
351 * specified session.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
352 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
353 * TODO: Use flap_connection_findbygroup everywhere and get rid of this.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
354 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
355 * @param od The session to search.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
356 * @param type The type of connection to look for.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
357 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
358 * @return Returns the first connection found of the given target type,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
359 * or NULL if none could be found.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
360 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
361 FlapConnection *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
362 flap_connection_getbytype(OscarData *od, int type)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
363 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
364 GList *cur;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
365
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
366 for (cur = od->oscar_connections; cur != NULL; cur = cur->next)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
367 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
368 FlapConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
369 conn = cur->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
370 if ((conn->type == type) && (conn->connected))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
371 return conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
372 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
373
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
374 return NULL;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
375 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
376
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
377 FlapConnection *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
378 flap_connection_getbytype_all(OscarData *od, int type)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
379 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
380 GList *cur;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
381
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
382 for (cur = od->oscar_connections; cur; cur = cur->next)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
383 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
384 FlapConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
385 conn = cur->data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
386 if (conn->type == type)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
387 return conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
388 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
389
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
390 return NULL;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
391 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
392
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
393 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
394 * Allocate a new FLAP frame.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
395 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
396 * @param channel The FLAP channel. This is almost always 2.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
397 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
398 FlapFrame *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
399 flap_frame_new(OscarData *od, guint16 channel, int datalen)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
400 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
401 FlapFrame *frame;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
402
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
403 frame = g_new0(FlapFrame, 1);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
404 frame->channel = channel;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
405
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
406 if (datalen > 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
407 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
408 guint8 *data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
409 data = g_malloc(datalen);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
410 byte_stream_init(&frame->data, data, datalen);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
411 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
412
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
413 return frame;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
414 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
415
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
416 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
417 * Free a FlapFrame
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
418 *
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
419 * @param frame The frame to free.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
420 * @return -1 on error; 0 on success.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
421 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
422 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
423 flap_frame_destroy(FlapFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
424 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
425 free(frame->data.data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
426 free(frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
427
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
428 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
429 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
430
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
431 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
432 parse_snac(OscarData *od, FlapConnection *conn, FlapFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
433 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
434 aim_module_t *cur;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
435 aim_modsnac_t snac;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
436
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
437 if (byte_stream_empty(&frame->data) < 10)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
438 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
439
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
440 snac.family = byte_stream_get16(&frame->data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
441 snac.subtype = byte_stream_get16(&frame->data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
442 snac.flags = byte_stream_get16(&frame->data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
443 snac.id = byte_stream_get32(&frame->data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
444
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
445 /* SNAC flags are apparently uniform across all SNACs, so we handle them here */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
446 if (snac.flags & 0x0001) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
447 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
448 * This means the SNAC will be followed by another SNAC with
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
449 * related information. We don't need to do anything about
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
450 * this here.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
451 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
452 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
453 if (snac.flags & 0x8000) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
454 /*
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
455 * This packet contains the version of the family that this SNAC is
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
456 * in. You get this when your SSI module is version 2 or higher.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
457 * For now we have no need for this, but you could always save
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
458 * it as a part of aim_modnsac_t, or something. The format is...
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
459 * 2 byte length of total mini-header (which is 6 bytes), then TLV
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
460 * of type 0x0001, length 0x0002, value is the 2 byte version
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
461 * number
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
462 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
463 byte_stream_advance(&frame->data, byte_stream_get16(&frame->data));
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
464 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
465
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
466 for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
467
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
468 if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) &&
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
469 (cur->family != snac.family))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
470 continue;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
471
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
472 if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
473 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
474 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
475 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
476
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
477 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
478 parse_fakesnac(OscarData *od, FlapConnection *conn, FlapFrame *frame, guint16 family, guint16 subtype)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
479 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
480 aim_module_t *cur;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
481 aim_modsnac_t snac;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
482
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
483 snac.family = family;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
484 snac.subtype = subtype;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
485 snac.flags = snac.id = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
486
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
487 for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
488
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
489 if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) &&
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
490 (cur->family != snac.family))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
491 continue;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
492
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
493 if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
494 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
495 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
496 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
497
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
498 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
499 parse_flap_ch4(OscarData *od, FlapConnection *conn, FlapFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
500 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
501 aim_tlvlist_t *tlvlist;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
502 char *msg = NULL;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
503 guint16 code = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
504 aim_rxcallback_t userfunc;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
505
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
506 if (byte_stream_empty(&frame->data) == 0) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
507 /* XXX should do something with this */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
508 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
509 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
510
13602
57e5d1455ad7 [gaim-migrate @ 15988]
Mark Doliner <mark@kingant.net>
parents: 13592
diff changeset
511 /* An ICQ account is logging in */
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
512 if (conn->type == SNAC_FAMILY_AUTH)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
513 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
514 parse_fakesnac(od, conn, frame, 0x0017, 0x0003);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
515 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
516 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
517
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
518 tlvlist = aim_tlvlist_read(&frame->data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
519
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
520 if (aim_tlv_gettlv(tlvlist, 0x0009, 1))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
521 code = aim_tlv_get16(tlvlist, 0x0009, 1);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
522
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
523 if (aim_tlv_gettlv(tlvlist, 0x000b, 1))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
524 msg = aim_tlv_getstr(tlvlist, 0x000b, 1);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
525
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
526 if ((userfunc = aim_callhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR)))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
527 userfunc(od, conn, frame, code, msg);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
528
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
529 aim_tlvlist_free(&tlvlist);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
530
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
531 free(msg);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
532 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
533
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
534 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
535 * Takes a new incoming FLAP frame and sends it to the appropriate
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
536 * handler function to be parsed.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
537 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
538 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
539 parse_flap(OscarData *od, FlapConnection *conn, FlapFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
540 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
541 if (frame->channel == 0x01) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
542 guint32 flap_version = byte_stream_get32(&frame->data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
543 if (flap_version != 0x00000001)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
544 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
545 /* Error! */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
546 gaim_debug_warning("oscar", "Expecting FLAP version "
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
547 "0x00000001 but received FLAP version %08lx. Closing connection.\n",
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
548 flap_version);
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
549 flap_connection_schedule_destroy(conn,
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
550 OSCAR_DISCONNECT_INVALID_DATA);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
551 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
552 else
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
553 conn->connected = TRUE;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
554
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
555 } else if (frame->channel == 0x02) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
556 parse_snac(od, conn, frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
557
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
558 } else if (frame->channel == 0x04) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
559 parse_flap_ch4(od, conn, frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
560
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
561 } else if (frame->channel == 0x05) {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
562 /* TODO: Reset our keepalive watchdog? */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
563
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
564 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
565 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
566
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
567 /**
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
568 * Read in all available data on the socket for a given connection.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
569 * All complete FLAPs handled immedate after they're received.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
570 * Incomplete FLAP data is stored locally and appended to the next
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
571 * time this callback is triggered.
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
572 */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
573 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
574 flap_connection_recv_cb(gpointer data, gint source, GaimInputCondition cond)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
575 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
576 FlapConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
577 ssize_t read;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
578 guint8 header[6];
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
579
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
580 conn = data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
581
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
582 /* Read data until we run out of data and break out of the loop */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
583 while (TRUE)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
584 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
585 /* Start reading a new FLAP */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
586 if (conn->buffer_incoming.data.data == NULL)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
587 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
588 /* Peek at the first 6 bytes to get the length */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
589 read = recv(conn->fd, &header, 6, MSG_PEEK);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
590
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
591 /* Check if the FLAP server closed the connection */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
592 if (read == 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
593 {
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
594 flap_connection_schedule_destroy(conn,
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
595 OSCAR_DISCONNECT_REMOTE_CLOSED);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
596 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
597 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
598
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
599 /* If there was an error then close the connection */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
600 if (read == -1)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
601 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
602 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
603 /* No worries */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
604 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
605
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
606 /* Error! */
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
607 flap_connection_schedule_destroy(conn,
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
608 OSCAR_DISCONNECT_LOST_CONNECTION);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
609 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
610 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
611
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
612 /* If we don't even have a complete FLAP header then do nothing */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
613 if (read < 6)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
614 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
615
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
616 /* Read the first 6 bytes (the FLAP header) */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
617 read = recv(conn->fd, &header, 6, 0);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
618
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
619 /* All FLAP frames must start with the byte 0x2a */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
620 if (aimutil_get8(&header[0]) != 0x2a)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
621 {
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
622 flap_connection_schedule_destroy(conn,
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
623 OSCAR_DISCONNECT_INVALID_DATA);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
624 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
625 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
626
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
627 /* Initialize a new temporary FlapFrame for incoming data */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
628 conn->buffer_incoming.channel = aimutil_get8(&header[1]);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
629 conn->buffer_incoming.seqnum = aimutil_get16(&header[2]);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
630 conn->buffer_incoming.data.len = aimutil_get16(&header[4]);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
631 conn->buffer_incoming.data.data = g_new(guint8, conn->buffer_incoming.data.len);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
632 conn->buffer_incoming.data.offset = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
633 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
634
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
635 if (conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
636 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
637 /* Read data into the temporary FlapFrame until it is complete */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
638 read = recv(conn->fd,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
639 &conn->buffer_incoming.data.data[conn->buffer_incoming.data.offset],
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
640 conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
641 0);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
642
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
643 /* Check if the FLAP server closed the connection */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
644 if (read == 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
645 {
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
646 flap_connection_schedule_destroy(conn,
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
647 OSCAR_DISCONNECT_REMOTE_CLOSED);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
648 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
649 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
650
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
651 if (read == -1)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
652 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
653 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
654 /* No worries */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
655 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
656
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
657 /* Error! */
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
658 flap_connection_schedule_destroy(conn,
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
659 OSCAR_DISCONNECT_LOST_CONNECTION);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
660 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
661 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
662
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
663 conn->buffer_incoming.data.offset += read;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
664 if (conn->buffer_incoming.data.offset < conn->buffer_incoming.data.len)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
665 /* Waiting for more data to arrive */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
666 break;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
667 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
668
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
669 /* We have a complete FLAP! Handle it and continue reading */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
670 byte_stream_rewind(&conn->buffer_incoming.data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
671 parse_flap(conn->od, conn, &conn->buffer_incoming);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
672 conn->lastactivity = time(NULL);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
673
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
674 g_free(conn->buffer_incoming.data.data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
675 conn->buffer_incoming.data.data = NULL;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
676 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
677 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
678
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
679 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
680 send_cb(gpointer data, gint source, GaimInputCondition cond)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
681 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
682 FlapConnection *conn;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
683 int writelen, ret;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
684
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
685 conn = data;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
686 writelen = gaim_circ_buffer_get_max_read(conn->buffer_outgoing);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
687
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
688 if (writelen == 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
689 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
690 gaim_input_remove(conn->watcher_outgoing);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
691 conn->watcher_outgoing = 0;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
692 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
693 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
694
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
695 ret = send(conn->fd, conn->buffer_outgoing->outptr, writelen, 0);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
696 if (ret <= 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
697 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
698 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
699 /* No worries */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
700 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
701
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
702 /* Error! */
13608
6c34fbb75bbd [gaim-migrate @ 15994]
Mark Doliner <mark@kingant.net>
parents: 13602
diff changeset
703 flap_connection_schedule_destroy(conn, OSCAR_DISCONNECT_LOST_CONNECTION);
13592
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
704 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
705 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
706
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
707 gaim_circ_buffer_mark_read(conn->buffer_outgoing, ret);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
708 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
709
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
710 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
711 flap_connection_send_byte_stream(ByteStream *bs, FlapConnection *conn, size_t count)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
712 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
713 if (conn == NULL)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
714 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
715
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
716 /* Make sure we don't send past the end of the bs */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
717 if (count > byte_stream_empty(bs))
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
718 count = byte_stream_empty(bs); /* truncate to remaining space */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
719
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
720 if (count == 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
721 return;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
722
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
723 /* Add everything to our outgoing buffer */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
724 gaim_circ_buffer_append(conn->buffer_outgoing, bs->data, count);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
725
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
726 /* If we haven't already started writing stuff, then start the cycle */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
727 if (conn->watcher_outgoing == 0)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
728 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
729 conn->watcher_outgoing = gaim_input_add(conn->fd,
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
730 GAIM_INPUT_WRITE, send_cb, conn);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
731 send_cb(conn, conn->fd, 0);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
732 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
733 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
734
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
735 static void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
736 sendframe_flap(FlapConnection *conn, FlapFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
737 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
738 ByteStream bs;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
739 int payloadlen, bslen;
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
740
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
741 payloadlen = byte_stream_curpos(&frame->data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
742
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
743 byte_stream_init(&bs, malloc(6 + payloadlen), 6 + payloadlen);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
744
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
745 /* FLAP header */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
746 byte_stream_put8(&bs, 0x2a);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
747 byte_stream_put8(&bs, frame->channel);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
748 byte_stream_put16(&bs, frame->seqnum);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
749 byte_stream_put16(&bs, payloadlen);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
750
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
751 /* Payload */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
752 byte_stream_rewind(&frame->data);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
753 byte_stream_putbs(&bs, &frame->data, payloadlen);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
754
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
755 bslen = byte_stream_curpos(&bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
756 byte_stream_rewind(&bs);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
757 flap_connection_send_byte_stream(&bs, conn, bslen);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
758
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
759 free(bs.data); /* XXX byte_stream_free */
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
760 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
761
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
762 void
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
763 flap_connection_send(FlapConnection *conn, FlapFrame *frame)
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
764 {
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
765 frame->seqnum = ++(conn->seqnum);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
766 sendframe_flap(conn, frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
767 flap_frame_destroy(frame);
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
768 }
6519aeb66b31 [gaim-migrate @ 15978]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
769