annotate libgaim/protocols/oscar/flap_connection.c @ 15129:8138277e9369

[gaim-migrate @ 17915] * Add a little cushion to the rate average calculation to hopefully account for any inaccuracies due to network lag and stuff * If one of our connections is disconnected, close the socket and don't try to write to it again. This will hopefully fix a weird race condition that Kevin was running into? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 07 Dec 2006 08:23:18 +0000
parents 6cc89a43bf8f
children 4934e7a03a98
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
2 * Gaim's oscar protocol plugin
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
3 * This file is the legal property of its developers.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
4 * Please see the AUTHORS file distributed alongside this file.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
5 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
10 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
14 * Lesser General Public License for more details.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
15 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
19 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
20
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
21 #include "oscar.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
22
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
23 #include "eventloop.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
24 #include "proxy.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
25
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
26 #ifndef _WIN32
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
27 #include <netdb.h>
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
28 #include <sys/socket.h>
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
29 #include <netinet/in.h>
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
30 #endif
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
31
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
32 #ifdef _WIN32
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
33 #include "win32dep.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
34 #endif
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
35
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
36 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
37 * This sends a channel 1 SNAC containing the FLAP version.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
38 * The FLAP version is sent by itself at the beginning of every
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
39 * connection to a FLAP server. It is always the very first
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
40 * packet sent by both the server and the client after the SYN,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
41 * SYN/ACK, ACK handshake.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
42 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
43 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
44 flap_connection_send_version(OscarData *od, FlapConnection *conn)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
45 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
46 FlapFrame *frame;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
47
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
48 frame = flap_frame_new(od, 0x01, 4);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
49 byte_stream_put32(&frame->data, 0x00000001);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
50 flap_connection_send(conn, frame);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
51 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
52
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
53 /**
15088
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
54 * This sends a channel 1 FLAP containing the FLAP version and
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
55 * the authentication cookie. This is sent when connecting to
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
56 * any FLAP server after the initial connection to the auth
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
57 * server. It is always the very first packet sent by both the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
58 * server and the client after the SYN, SYN/ACK, ACK handshake.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
59 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
60 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
61 flap_connection_send_version_with_cookie(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
62 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
63 FlapFrame *frame;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
64 aim_tlvlist_t *tl = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
65
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
66 frame = flap_frame_new(od, 0x01, 4 + 2 + 2 + length);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
67 byte_stream_put32(&frame->data, 0x00000001);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
68 aim_tlvlist_add_raw(&tl, 0x0006, length, chipsahoy);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
69 aim_tlvlist_write(&frame->data, &tl);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
70 aim_tlvlist_free(&tl);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
71
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
72 flap_connection_send(conn, frame);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
73 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
74
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
75 static struct rateclass *
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
76 flap_connection_get_rateclass(FlapConnection *conn, guint16 family, guint16 subtype)
15090
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
77 {
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
78 GSList *tmp1;
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
79 gconstpointer key;
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
80
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
81 key = GUINT_TO_POINTER((family << 16) + subtype);
15090
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
82
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
83 for (tmp1 = conn->rateclasses; tmp1 != NULL; tmp1 = tmp1->next)
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
84 {
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
85 struct rateclass *rateclass;
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
86 rateclass = tmp1->data;
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
87
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
88 if (g_hash_table_lookup(rateclass->members, key))
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
89 return rateclass;
15090
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
90 }
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
91
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
92 return NULL;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
93 }
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
94
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
95 /*
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
96 * Attempt to calculate what our new current average would be if we
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
97 * were to send a SNAC in this rateclass at the given time.
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
98 */
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
99 static guint32
15110
6cc89a43bf8f [gaim-migrate @ 17896]
Mark Doliner <mark@kingant.net>
parents: 15107
diff changeset
100 rateclass_get_new_current(FlapConnection *conn, struct rateclass *rateclass, struct timeval *now)
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
101 {
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
102 unsigned long timediff; /* In milliseconds */
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
103
15110
6cc89a43bf8f [gaim-migrate @ 17896]
Mark Doliner <mark@kingant.net>
parents: 15107
diff changeset
104 timediff = (now->tv_sec - rateclass->last.tv_sec) * 1000 + (now->tv_usec - rateclass->last.tv_usec) / 1000;
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
106 /* This formula is taken from the joscar API docs. Preesh. */
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
107 return MIN(((rateclass->current * (rateclass->windowsize - 1)) + timediff) / rateclass->windowsize, rateclass->max);
15090
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
108 }
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
109
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
110 static gboolean flap_connection_send_queued(gpointer data)
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
111 {
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
112 FlapConnection *conn;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
113 struct timeval now;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
114
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
115 conn = data;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
116 gettimeofday(&now, NULL);
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
117
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
118 while (!g_queue_is_empty(conn->queued_snacs))
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
119 {
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
120 QueuedSnac *queued_snac;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
121 struct rateclass *rateclass;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
122
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
123 queued_snac = g_queue_peek_head(conn->queued_snacs);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
124
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
125 rateclass = flap_connection_get_rateclass(conn, queued_snac->family, queued_snac->subtype);
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
126 if (rateclass != NULL)
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
127 {
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
128 guint32 new_current;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
129
15110
6cc89a43bf8f [gaim-migrate @ 17896]
Mark Doliner <mark@kingant.net>
parents: 15107
diff changeset
130 new_current = rateclass_get_new_current(conn, rateclass, &now);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
131
15129
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
132 if (new_current < rateclass->alert + 100)
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
133 /* (Add 100ms padding to account for inaccuracies in the calculation) */
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
134 /* Not ready to send this SNAC yet--keep waiting. */
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
135 return TRUE;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
136
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
137 rateclass->current = new_current;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
138 rateclass->last.tv_sec = now.tv_sec;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
139 rateclass->last.tv_usec = now.tv_usec;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
140 }
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
141
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
142 flap_connection_send(conn, queued_snac->frame);
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
143 g_free(queued_snac);
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
144 g_queue_pop_head(conn->queued_snacs);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
145 }
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
146
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
147 conn->queued_timeout = 0;
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
148 return FALSE;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
149 }
15090
9cdc8bb39cf2 [gaim-migrate @ 17876]
Mark Doliner <mark@kingant.net>
parents: 15089
diff changeset
150
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
151 /**
15088
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
152 * This sends a channel 2 FLAP containing a SNAC. The SNAC family and
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
153 * subtype are looked up in the rate info for this connection, and if
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
154 * sending this SNAC will induce rate limiting then we delay sending
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
155 * of the SNAC by putting it into an outgoing holding queue.
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
156 *
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
157 * @param data The optional bytestream that makes up the data portion
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
158 * of this SNAC. For empty SNACs this should be NULL.
15088
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
159 */
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
160 void
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
161 flap_connection_send_snac(OscarData *od, FlapConnection *conn, guint16 family, guint16 subtype, guint16 flags, aim_snacid_t snacid, ByteStream *data)
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
162 {
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
163 FlapFrame *frame;
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
164 guint32 length;
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
165 gboolean enqueue = FALSE;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
166 struct rateclass *rateclass;
15088
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
167
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
168 length = data != NULL ? data->offset : 0;
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
169
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
170 frame = flap_frame_new(od, 0x02, 10 + length);
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
171 aim_putsnac(&frame->data, family, subtype, flags, snacid);
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
172
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
173 if (length > 0)
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
174 {
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
175 byte_stream_rewind(data);
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
176 byte_stream_putbs(&frame->data, data, length);
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
177 }
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
178
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
179 if (conn->queued_timeout != 0)
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
180 enqueue = TRUE;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
181 else if ((rateclass = flap_connection_get_rateclass(conn, family, subtype)) != NULL)
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
182 {
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
183 struct timeval now;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
184 guint32 new_current;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
185
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
186 gettimeofday(&now, NULL);
15110
6cc89a43bf8f [gaim-migrate @ 17896]
Mark Doliner <mark@kingant.net>
parents: 15107
diff changeset
187 new_current = rateclass_get_new_current(conn, rateclass, &now);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
188
15129
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
189 if (new_current < rateclass->alert + 100)
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
190 {
15129
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
191 /* (Add 100ms padding to account for inaccuracies in the calculation) */
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
192 enqueue = TRUE;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
193 }
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
194 else
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
195 {
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
196 rateclass->current = new_current;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
197 rateclass->last.tv_sec = now.tv_sec;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
198 rateclass->last.tv_usec = now.tv_usec;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
199 }
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
200 }
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
201
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
202 if (enqueue)
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
203 {
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
204 /* We've been sending too fast, so delay this message */
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
205 QueuedSnac *queued_snac;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
206
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
207 queued_snac = g_new(QueuedSnac, 1);
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
208 queued_snac->family = family;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
209 queued_snac->subtype = subtype;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
210 queued_snac->frame = frame;
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
211 g_queue_push_tail(conn->queued_snacs, queued_snac);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
212
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
213 if (conn->queued_timeout == 0)
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
214 conn->queued_timeout = gaim_timeout_add(500, flap_connection_send_queued, conn);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
215
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
216 return;
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
217 }
15088
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
218
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
219 flap_connection_send(conn, frame);
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
220 }
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
221
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
222 /**
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
223 * This sends an empty channel 4 FLAP. This is sent to signify
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
224 * that we're logging off. This shouldn't really be necessary--
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
225 * usually the AIM server will detect that the TCP connection has
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
226 * been destroyed--but it's good practice.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
227 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
228 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
229 flap_connection_send_close(OscarData *od, FlapConnection *conn)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
230 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
231 FlapFrame *frame;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
232
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
233 frame = flap_frame_new(od, 0x04, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
234 flap_connection_send(conn, frame);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
235 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
236
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
237 /**
15088
25c3a33c6485 [gaim-migrate @ 17874]
Mark Doliner <mark@kingant.net>
parents: 15086
diff changeset
238 * This sends an empty channel 5 FLAP. This is used as a keepalive
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
239 * packet in FLAP connections. WinAIM 4.x and higher send these
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
240 * _every minute_ to keep the connection alive.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
241 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
242 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
243 flap_connection_send_keepalive(OscarData *od, FlapConnection *conn)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
244 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
245 FlapFrame *frame;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
246
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
247 frame = flap_frame_new(od, 0x05, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
248 flap_connection_send(conn, frame);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
249
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
250 /* clean out SNACs over 60sec old */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
251 aim_cleansnacs(od, 60);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
252 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
253
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
254 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
255 * Allocate a new empty connection structure.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
256 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
257 * @param od The oscar session associated with this connection.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
258 * @param type Type of connection to create
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
259 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
260 * @return Returns the new connection structure.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
261 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
262 FlapConnection *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
263 flap_connection_new(OscarData *od, int type)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
264 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
265 FlapConnection *conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
266
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
267 conn = g_new0(FlapConnection, 1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
268 conn->od = od;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
269 conn->buffer_outgoing = gaim_circ_buffer_new(0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
270 conn->fd = -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
271 conn->subtype = -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
272 conn->type = type;
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
273 conn->queued_snacs = g_queue_new();
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
274
14348
80b05108652c [gaim-migrate @ 17050]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
275 od->oscar_connections = g_slist_prepend(od->oscar_connections, conn);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
276
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
277 return conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
278 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
279
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
280 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
281 * Close (but not free) a connection.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
282 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
283 * This cancels any currently pending connection attempt,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
284 * closes any open fd and frees the auth cookie.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
285 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
286 * @param conn The connection to close.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
287 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
288 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
289 flap_connection_close(OscarData *od, FlapConnection *conn)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
290 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
291 if (conn->connect_data != NULL)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
292 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
293 gaim_proxy_connect_cancel(conn->connect_data);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
294 conn->connect_data = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
295 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
296
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
297 if (conn->connect_data != NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
298 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
299 if (conn->type == SNAC_FAMILY_CHAT)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
300 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
301 oscar_chat_destroy(conn->new_conn_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
302 conn->connect_data = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
303 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
304 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
305
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
306 if (conn->fd != -1)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
307 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
308 if (conn->type == SNAC_FAMILY_LOCATE)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
309 flap_connection_send_close(od, conn);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
310
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
311 close(conn->fd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
312 conn->fd = -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
313 }
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
314
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
315 if (conn->watcher_incoming != 0)
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
316 {
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
317 gaim_input_remove(conn->watcher_incoming);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
318 conn->watcher_incoming = 0;
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
319 }
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
320
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
321 if (conn->watcher_outgoing != 0)
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
322 {
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
323 gaim_input_remove(conn->watcher_outgoing);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
324 conn->watcher_outgoing = 0;
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
325 }
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
326
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
327 g_free(conn->buffer_incoming.data.data);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
328 conn->buffer_incoming.data.data = NULL;
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
329
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
330 gaim_circ_buffer_destroy(conn->buffer_outgoing);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
331 conn->buffer_outgoing = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
332 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
333
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
334 static void
15086
eed75cc6cb88 [gaim-migrate @ 17872]
Mark Doliner <mark@kingant.net>
parents: 15085
diff changeset
335 flap_connection_destroy_rateclass(struct rateclass *rateclass)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
336 {
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
337 g_hash_table_destroy(rateclass->members);
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
338 g_free(rateclass);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
339 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
340
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
341 /**
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
342 * Free a FlapFrame
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
343 *
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
344 * @param frame The frame to free.
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
345 */
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
346 static void
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
347 flap_frame_destroy(FlapFrame *frame)
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
348 {
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
349 g_free(frame->data.data);
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
350 g_free(frame);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
351 }
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
352
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
353 static gboolean
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
354 flap_connection_destroy_cb(gpointer data)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
355 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
356 FlapConnection *conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
357 OscarData *od;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
358 GaimAccount *account;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
359
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
360 conn = data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
361 od = conn->od;
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
362 account = gaim_connection_get_account(od->gc);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
363
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
364 gaim_debug_info("oscar", "Destroying oscar connection of "
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
365 "type 0x%04hx\n", conn->type);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
366
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
367 od->oscar_connections = g_slist_remove(od->oscar_connections, conn);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
368
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
369 /*
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
370 * TODO: If we don't have a SNAC_FAMILY_LOCATE connection then
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
371 * we should try to request one instead of disconnecting.
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
372 */
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
373 if (!account->disconnecting && ((od->oscar_connections == NULL)
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
374 || (!flap_connection_getbytype(od, SNAC_FAMILY_LOCATE))))
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
375 {
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
376 /* No more FLAP connections! Sign off this GaimConnection! */
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
377 gchar *tmp;
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
378 if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED)
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
379 tmp = g_strdup(_("Server closed the connection."));
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
380 else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION)
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
381 tmp = g_strdup_printf(_("Lost connection with server:\n%s"),
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
382 conn->error_message);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
383 else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA)
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
384 tmp = g_strdup(_("Received invalid data on connection with server."));
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
385 else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT)
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
386 tmp = g_strdup_printf(_("Could not establish a connection with the server:\n%s"),
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
387 conn->error_message);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
388 else
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
389 /*
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
390 * We shouldn't print a message for some disconnect_reasons.
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
391 * Like OSCAR_DISCONNECT_LOCAL_CLOSED.
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
392 */
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
393 tmp = NULL;
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
394
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
395 if (tmp != NULL)
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
396 {
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
397 gaim_connection_error(od->gc, tmp);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
398 g_free(tmp);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
399 }
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
400 }
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
401
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
402 flap_connection_close(od, conn);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
403
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
404 g_free(conn->error_message);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
405 g_free(conn->cookie);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
406
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
407 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
408 * Free conn->internal, if necessary
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
409 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
410 if (conn->type == SNAC_FAMILY_CHAT)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
411 flap_connection_destroy_chat(od, conn);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
412
14348
80b05108652c [gaim-migrate @ 17050]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
413 g_slist_free(conn->groups);
15086
eed75cc6cb88 [gaim-migrate @ 17872]
Mark Doliner <mark@kingant.net>
parents: 15085
diff changeset
414 while (conn->rateclasses != NULL)
eed75cc6cb88 [gaim-migrate @ 17872]
Mark Doliner <mark@kingant.net>
parents: 15085
diff changeset
415 {
eed75cc6cb88 [gaim-migrate @ 17872]
Mark Doliner <mark@kingant.net>
parents: 15085
diff changeset
416 flap_connection_destroy_rateclass(conn->rateclasses->data);
eed75cc6cb88 [gaim-migrate @ 17872]
Mark Doliner <mark@kingant.net>
parents: 15085
diff changeset
417 conn->rateclasses = g_slist_delete_link(conn->rateclasses, conn->rateclasses);
eed75cc6cb88 [gaim-migrate @ 17872]
Mark Doliner <mark@kingant.net>
parents: 15085
diff changeset
418 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
419
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
420 while (!g_queue_is_empty(conn->queued_snacs))
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
421 {
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
422 QueuedSnac *queued_snac;
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
423 queued_snac = g_queue_pop_head(conn->queued_snacs);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
424 flap_frame_destroy(queued_snac->frame);
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
425 g_free(queued_snac);
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
426 }
15106
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
427 g_queue_free(conn->queued_snacs);
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
428 if (conn->queued_timeout > 0)
f41cd6f78c60 [gaim-migrate @ 17892]
Mark Doliner <mark@kingant.net>
parents: 15105
diff changeset
429 gaim_timeout_remove(conn->queued_timeout);
15105
b2b0839f57d0 [gaim-migrate @ 17891]
Mark Doliner <mark@kingant.net>
parents: 15091
diff changeset
430
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
431 g_free(conn);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
432
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
433 return FALSE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
434 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
435
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
436 /**
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
437 * See the comments for the parameters of
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
438 * flap_connection_schedule_destroy().
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
439 */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
440 void
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
441 flap_connection_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
442 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
443 if (conn->destroy_timeout != 0)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
444 gaim_timeout_remove(conn->destroy_timeout);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
445 conn->disconnect_reason = reason;
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
446 g_free(conn->error_message);
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
447 conn->error_message = g_strdup(error_message);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
448 flap_connection_destroy_cb(conn);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
449 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
450
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
451 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
452 * Schedule Gaim to destroy the given FlapConnection as soon as we
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
453 * return control back to the program's main loop. We must do this
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
454 * if we want to destroy the connection but we are still using it
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
455 * for some reason.
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
456 *
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
457 * @param reason The reason for the disconnection.
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
458 * @param error_message A brief error message that gives more detail
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
459 * regarding the reason for the disconnecting. This should
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
460 * be NULL for everything except OSCAR_DISCONNECT_LOST_CONNECTION,
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
461 * in which case it should contain the value of strerror(errno),
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
462 * and OSCAR_DISCONNECT_COULD_NOT_CONNECT, in which case it
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
463 * should contain the error_message passed back from the call
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
464 * to gaim_proxy_connect().
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
465 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
466 void
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
467 flap_connection_schedule_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
468 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
469 if (conn->destroy_timeout != 0)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
470 /* Already taken care of */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
471 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
472
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
473 gaim_debug_info("oscar", "Scheduling destruction of FLAP "
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
474 "connection of type 0x%04hx\n", conn->type);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
475 conn->disconnect_reason = reason;
14402
648e33275d9d [gaim-migrate @ 17110]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
476 g_free(conn->error_message);
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
477 conn->error_message = g_strdup(error_message);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
478 conn->destroy_timeout = gaim_timeout_add(0, flap_connection_destroy_cb, conn);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
479 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
480
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
481 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
482 * In OSCAR, every connection has a set of SNAC groups associated
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
483 * with it. These are the groups that you can send over this connection
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
484 * without being guaranteed a "Not supported" SNAC error.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
485 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
486 * The grand theory of things says that these associations transcend
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
487 * what libfaim calls "connection types" (conn->type). You can probably
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
488 * see the elegance here, but since I want to revel in it for a bit, you
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
489 * get to hear it all spelled out.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
490 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
491 * So let us say that you have your core BOS connection running. One
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
492 * of your modules has just given you a SNAC of the group 0x0004 to send
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
493 * you. Maybe an IM destined for some twit in Greenland. So you start
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
494 * at the top of your connection list, looking for a connection that
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
495 * claims to support group 0x0004. You find one. Why, that neat BOS
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
496 * connection of yours can do that. So you send it on its way.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
497 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
498 * Now, say, that fellow from Greenland has friends and they all want to
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
499 * meet up with you in a lame chat room. This has landed you a SNAC
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
500 * in the family 0x000e and you have to admit you're a bit lost. You've
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
501 * searched your connection list for someone who wants to make your life
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
502 * easy and deliver this SNAC for you, but there isn't one there.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
503 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
504 * Here comes the good bit. Without even letting anyone know, particularly
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
505 * the module that decided to send this SNAC, and definitely not that twit
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
506 * in Greenland, you send out a service request. In this request, you have
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
507 * marked the need for a connection supporting group 0x000e. A few seconds
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
508 * later, you receive a service redirect with an IP address and a cookie in
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
509 * it. Great, you say. Now I have something to do. Off you go, making
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
510 * that connection. One of the first things you get from this new server
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
511 * is a message saying that indeed it does support the group you were looking
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
512 * for. So you continue and send rate confirmation and all that.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
513 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
514 * Then you remember you had that SNAC to send, and now you have a means to
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
515 * do it, and you do, and everyone is happy. Except the Greenlander, who is
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
516 * still stuck in the bitter cold.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
517 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
518 * Oh, and this is useful for building the Migration SNACs, too. In the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
519 * future, this may help convince me to implement rate limit mitigation
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
520 * for real. We'll see.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
521 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
522 * Just to make me look better, I'll say that I've known about this great
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
523 * scheme for quite some time now. But I still haven't convinced myself
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
524 * to make libfaim work that way. It would take a fair amount of effort,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
525 * and probably some client API changes as well. (Whenever I don't want
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
526 * to do something, I just say it would change the client API. Then I
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
527 * instantly have a couple of supporters of not doing it.)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
528 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
529 * Generally, addgroup is only called by the internal handling of the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
530 * server ready SNAC. So if you want to do something before that, you'll
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
531 * have to be more creative. That is done rather early, though, so I don't
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
532 * think you have to worry about it. Unless you're me. I care deeply
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
533 * about such inane things.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
534 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
535 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
536
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
537 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
538 * Find a FlapConnection that supports the given oscar
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
539 * family.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
540 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
541 FlapConnection *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
542 flap_connection_findbygroup(OscarData *od, guint16 group)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
543 {
14348
80b05108652c [gaim-migrate @ 17050]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
544 GSList *cur;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
545
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
546 for (cur = od->oscar_connections; cur != NULL; cur = cur->next)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
547 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
548 FlapConnection *conn;
14348
80b05108652c [gaim-migrate @ 17050]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
549 GSList *l;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
550
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
551 conn = cur->data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
552
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
553 for (l = conn->groups; l != NULL; l = l->next)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
554 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
555 if (GPOINTER_TO_UINT(l->data) == group)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
556 return conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
557 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
558 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
559
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
560 return NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
561 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
562
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
563 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
564 * Locates a connection of the specified type in the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
565 * specified session.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
566 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
567 * TODO: Use flap_connection_findbygroup everywhere and get rid of this.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
568 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
569 * @param od The session to search.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
570 * @param type The type of connection to look for.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
571 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
572 * @return Returns the first connection found of the given target type,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
573 * or NULL if none could be found.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
574 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
575 FlapConnection *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
576 flap_connection_getbytype(OscarData *od, int type)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
577 {
14348
80b05108652c [gaim-migrate @ 17050]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
578 GSList *cur;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
579
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
580 for (cur = od->oscar_connections; cur != NULL; cur = cur->next)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
581 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
582 FlapConnection *conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
583 conn = cur->data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
584 if ((conn->type == type) && (conn->connected))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
585 return conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
586 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
587
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
588 return NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
589 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
590
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
591 FlapConnection *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
592 flap_connection_getbytype_all(OscarData *od, int type)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
593 {
14348
80b05108652c [gaim-migrate @ 17050]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
594 GSList *cur;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
595
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
596 for (cur = od->oscar_connections; cur; cur = cur->next)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
597 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
598 FlapConnection *conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
599 conn = cur->data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
600 if (conn->type == type)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
601 return conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
602 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
603
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
604 return NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
605 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
606
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
607 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
608 * Allocate a new FLAP frame.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
609 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
610 * @param channel The FLAP channel. This is almost always 2.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
611 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
612 FlapFrame *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
613 flap_frame_new(OscarData *od, guint16 channel, int datalen)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
614 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
615 FlapFrame *frame;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
616
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
617 frame = g_new0(FlapFrame, 1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
618 frame->channel = channel;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
619
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
620 if (datalen > 0)
15089
033e1604cf63 [gaim-migrate @ 17875]
Mark Doliner <mark@kingant.net>
parents: 15088
diff changeset
621 byte_stream_new(&frame->data, datalen);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
622
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
623 return frame;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
624 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
625
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
626 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
627 parse_snac(OscarData *od, FlapConnection *conn, FlapFrame *frame)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
628 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
629 aim_module_t *cur;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
630 aim_modsnac_t snac;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
631
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
632 if (byte_stream_empty(&frame->data) < 10)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
633 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
634
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
635 snac.family = byte_stream_get16(&frame->data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
636 snac.subtype = byte_stream_get16(&frame->data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
637 snac.flags = byte_stream_get16(&frame->data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
638 snac.id = byte_stream_get32(&frame->data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
639
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
640 /* SNAC flags are apparently uniform across all SNACs, so we handle them here */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
641 if (snac.flags & 0x0001) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
642 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
643 * This means the SNAC will be followed by another SNAC with
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
644 * related information. We don't need to do anything about
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
645 * this here.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
646 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
647 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
648 if (snac.flags & 0x8000) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
649 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
650 * This packet contains the version of the family that this SNAC is
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
651 * in. You get this when your SSI module is version 2 or higher.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
652 * For now we have no need for this, but you could always save
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
653 * it as a part of aim_modnsac_t, or something. The format is...
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
654 * 2 byte length of total mini-header (which is 6 bytes), then TLV
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
655 * of type 0x0001, length 0x0002, value is the 2 byte version
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
656 * number
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
657 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
658 byte_stream_advance(&frame->data, byte_stream_get16(&frame->data));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
659 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
660
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
661 for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
662
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
663 if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) &&
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
664 (cur->family != snac.family))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
665 continue;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
666
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
667 if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
668 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
669 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
670 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
671
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
672 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
673 parse_fakesnac(OscarData *od, FlapConnection *conn, FlapFrame *frame, guint16 family, guint16 subtype)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
674 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
675 aim_module_t *cur;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
676 aim_modsnac_t snac;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
677
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
678 snac.family = family;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
679 snac.subtype = subtype;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
680 snac.flags = snac.id = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
681
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
682 for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
683
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
684 if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) &&
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
685 (cur->family != snac.family))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
686 continue;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
687
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
688 if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
689 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
690 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
691 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
692
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
693 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
694 parse_flap_ch4(OscarData *od, FlapConnection *conn, FlapFrame *frame)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
695 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
696 aim_tlvlist_t *tlvlist;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
697 char *msg = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
698 guint16 code = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
699 aim_rxcallback_t userfunc;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
700
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
701 if (byte_stream_empty(&frame->data) == 0) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
702 /* XXX should do something with this */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
703 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
704 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
705
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
706 /* An ICQ account is logging in */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
707 if (conn->type == SNAC_FAMILY_AUTH)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
708 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
709 parse_fakesnac(od, conn, frame, 0x0017, 0x0003);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
710 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
711 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
712
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
713 tlvlist = aim_tlvlist_read(&frame->data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
714
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
715 if (aim_tlv_gettlv(tlvlist, 0x0009, 1))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
716 code = aim_tlv_get16(tlvlist, 0x0009, 1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
717
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
718 if (aim_tlv_gettlv(tlvlist, 0x000b, 1))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
719 msg = aim_tlv_getstr(tlvlist, 0x000b, 1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
720
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
721 if ((userfunc = aim_callhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR)))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
722 userfunc(od, conn, frame, code, msg);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
723
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
724 aim_tlvlist_free(&tlvlist);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
725
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
726 free(msg);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
727 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
728
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
729 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
730 * Takes a new incoming FLAP frame and sends it to the appropriate
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
731 * handler function to be parsed.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
732 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
733 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
734 parse_flap(OscarData *od, FlapConnection *conn, FlapFrame *frame)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
735 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
736 if (frame->channel == 0x01) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
737 guint32 flap_version = byte_stream_get32(&frame->data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
738 if (flap_version != 0x00000001)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
739 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
740 /* Error! */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
741 gaim_debug_warning("oscar", "Expecting FLAP version "
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
742 "0x00000001 but received FLAP version %08lx. Closing connection.\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
743 flap_version);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
744 flap_connection_schedule_destroy(conn,
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
745 OSCAR_DISCONNECT_INVALID_DATA, NULL);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
746 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
747 else
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
748 conn->connected = TRUE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
749
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
750 } else if (frame->channel == 0x02) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
751 parse_snac(od, conn, frame);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
752
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
753 } else if (frame->channel == 0x04) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
754 parse_flap_ch4(od, conn, frame);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
755
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
756 } else if (frame->channel == 0x05) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
757 /* TODO: Reset our keepalive watchdog? */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
758
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
759 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
760 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
761
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
762 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
763 * Read in all available data on the socket for a given connection.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
764 * All complete FLAPs handled immedate after they're received.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
765 * Incomplete FLAP data is stored locally and appended to the next
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
766 * time this callback is triggered.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
767 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
768 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
769 flap_connection_recv_cb(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
770 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
771 FlapConnection *conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
772 ssize_t read;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
773 guint8 header[6];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
774
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
775 conn = data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
776
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
777 /* Read data until we run out of data and break out of the loop */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
778 while (TRUE)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
779 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
780 /* Start reading a new FLAP */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
781 if (conn->buffer_incoming.data.data == NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
782 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
783 /* Peek at the first 6 bytes to get the length */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
784 read = recv(conn->fd, &header, 6, MSG_PEEK);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
785
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
786 /* Check if the FLAP server closed the connection */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
787 if (read == 0)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
788 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
789 flap_connection_schedule_destroy(conn,
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
790 OSCAR_DISCONNECT_REMOTE_CLOSED, NULL);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
791 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
792 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
793
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
794 /* If there was an error then close the connection */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
795 if (read == -1)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
796 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
797 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
798 /* No worries */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
799 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
800
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
801 /* Error! */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
802 flap_connection_schedule_destroy(conn,
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
803 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
804 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
805 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
806
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
807 /* If we don't even have a complete FLAP header then do nothing */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
808 if (read < 6)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
809 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
810
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
811 /* Read the first 6 bytes (the FLAP header) */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
812 read = recv(conn->fd, &header, 6, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
813
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
814 /* All FLAP frames must start with the byte 0x2a */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
815 if (aimutil_get8(&header[0]) != 0x2a)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
816 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
817 flap_connection_schedule_destroy(conn,
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
818 OSCAR_DISCONNECT_INVALID_DATA, NULL);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
819 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
820 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
821
15107
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
822 /* Verify the sequence number sent by the server. */
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
823 #if 0
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
824 /* TODO: Need to initialize conn->seqnum_in somewhere before we can use this. */
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
825 if (aimutil_get16(&header[1]) != conn->seqnum_in++)
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
826 {
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
827 /* Received an out-of-order FLAP! */
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
828 flap_connection_schedule_destroy(conn,
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
829 OSCAR_DISCONNECT_INVALID_DATA, NULL);
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
830 break;
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
831 }
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
832 #endif
15085
f3573d941d66 [gaim-migrate @ 17871]
Mark Doliner <mark@kingant.net>
parents: 14402
diff changeset
833
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
834 /* Initialize a new temporary FlapFrame for incoming data */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
835 conn->buffer_incoming.channel = aimutil_get8(&header[1]);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
836 conn->buffer_incoming.seqnum = aimutil_get16(&header[2]);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
837 conn->buffer_incoming.data.len = aimutil_get16(&header[4]);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
838 conn->buffer_incoming.data.data = g_new(guint8, conn->buffer_incoming.data.len);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
839 conn->buffer_incoming.data.offset = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
840 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
841
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
842 if (conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
843 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
844 /* Read data into the temporary FlapFrame until it is complete */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
845 read = recv(conn->fd,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
846 &conn->buffer_incoming.data.data[conn->buffer_incoming.data.offset],
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
847 conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
848 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
849
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
850 /* Check if the FLAP server closed the connection */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
851 if (read == 0)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
852 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
853 flap_connection_schedule_destroy(conn,
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
854 OSCAR_DISCONNECT_REMOTE_CLOSED, NULL);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
855 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
856 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
857
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
858 if (read == -1)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
859 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
860 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
861 /* No worries */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
862 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
863
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
864 /* Error! */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
865 flap_connection_schedule_destroy(conn,
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
866 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
867 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
868 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
869
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
870 conn->buffer_incoming.data.offset += read;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
871 if (conn->buffer_incoming.data.offset < conn->buffer_incoming.data.len)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
872 /* Waiting for more data to arrive */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
873 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
874 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
875
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
876 /* We have a complete FLAP! Handle it and continue reading */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
877 byte_stream_rewind(&conn->buffer_incoming.data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
878 parse_flap(conn->od, conn, &conn->buffer_incoming);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
879 conn->lastactivity = time(NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
880
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
881 g_free(conn->buffer_incoming.data.data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
882 conn->buffer_incoming.data.data = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
883 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
884 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
885
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
886 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
887 send_cb(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
888 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
889 FlapConnection *conn;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
890 int writelen, ret;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
891
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
892 conn = data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
893 writelen = gaim_circ_buffer_get_max_read(conn->buffer_outgoing);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
894
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
895 if (writelen == 0)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
896 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
897 gaim_input_remove(conn->watcher_outgoing);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
898 conn->watcher_outgoing = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
899 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
900 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
901
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
902 ret = send(conn->fd, conn->buffer_outgoing->outptr, writelen, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
903 if (ret <= 0)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
904 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
905 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
906 /* No worries */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
907 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
908
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
909 /* Error! */
15129
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
910 gaim_input_remove(conn->watcher_outgoing);
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
911 conn->watcher_outgoing = 0;
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
912 close(conn->fd);
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
913 conn->fd = -1;
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
914 flap_connection_schedule_destroy(conn,
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14348
diff changeset
915 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
916 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
917 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
918
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
919 gaim_circ_buffer_mark_read(conn->buffer_outgoing, ret);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
920 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
921
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
922 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
923 flap_connection_send_byte_stream(ByteStream *bs, FlapConnection *conn, size_t count)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
924 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
925 if (conn == NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
926 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
927
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
928 /* Make sure we don't send past the end of the bs */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
929 if (count > byte_stream_empty(bs))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
930 count = byte_stream_empty(bs); /* truncate to remaining space */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
931
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
932 if (count == 0)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
933 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
934
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
935 /* Add everything to our outgoing buffer */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
936 gaim_circ_buffer_append(conn->buffer_outgoing, bs->data, count);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
937
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
938 /* If we haven't already started writing stuff, then start the cycle */
15129
8138277e9369 [gaim-migrate @ 17915]
Mark Doliner <mark@kingant.net>
parents: 15110
diff changeset
939 if ((conn->watcher_outgoing == 0) && (conn->fd != -1))
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
940 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
941 conn->watcher_outgoing = gaim_input_add(conn->fd,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
942 GAIM_INPUT_WRITE, send_cb, conn);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
943 send_cb(conn, conn->fd, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
944 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
945 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
946
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
947 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
948 sendframe_flap(FlapConnection *conn, FlapFrame *frame)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
949 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
950 ByteStream bs;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
951 int payloadlen, bslen;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
952
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
953 payloadlen = byte_stream_curpos(&frame->data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
954
15089
033e1604cf63 [gaim-migrate @ 17875]
Mark Doliner <mark@kingant.net>
parents: 15088
diff changeset
955 byte_stream_new(&bs, 6 + payloadlen);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
956
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
957 /* FLAP header */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
958 byte_stream_put8(&bs, 0x2a);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
959 byte_stream_put8(&bs, frame->channel);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
960 byte_stream_put16(&bs, frame->seqnum);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
961 byte_stream_put16(&bs, payloadlen);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
962
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
963 /* Payload */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
964 byte_stream_rewind(&frame->data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
965 byte_stream_putbs(&bs, &frame->data, payloadlen);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
966
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
967 bslen = byte_stream_curpos(&bs);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
968 byte_stream_rewind(&bs);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
969 flap_connection_send_byte_stream(&bs, conn, bslen);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
970
15089
033e1604cf63 [gaim-migrate @ 17875]
Mark Doliner <mark@kingant.net>
parents: 15088
diff changeset
971 g_free(bs.data); /* XXX byte_stream_free */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
972 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
973
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
974 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
975 flap_connection_send(FlapConnection *conn, FlapFrame *frame)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
976 {
15107
917a50335af3 [gaim-migrate @ 17893]
Mark Doliner <mark@kingant.net>
parents: 15106
diff changeset
977 frame->seqnum = ++(conn->seqnum_out);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
978 sendframe_flap(conn, frame);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
979 flap_frame_destroy(frame);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
980 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
981