Sun, 16 Nov 2008 08:16:17 +0000
Revert the unnecessary addition of the pixbuf boolean to PurpleRequestField.list
| 13593 | 1 | /* |
| 15884 | 2 | * Purple's oscar protocol plugin |
| 13593 | 3 | * This file is the legal property of its developers. |
| 4 | * Please see the AUTHORS file distributed alongside this file. | |
| 5 | * | |
| 6 | * This library is free software; you can redistribute it and/or | |
| 7 | * modify it under the terms of the GNU Lesser General Public | |
| 8 | * License as published by the Free Software Foundation; either | |
| 9 | * version 2 of the License, or (at your option) any later version. | |
| 10 | * | |
| 11 | * This library is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | * Lesser General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU Lesser General Public | |
| 17 | * License along with this library; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19110
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 13593 | 19 | */ |
| 20 | ||
| 21 | #include "oscar.h" | |
| 22 | ||
| 23 | #include "eventloop.h" | |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
24 | #include "proxy.h" |
| 13593 | 25 | |
| 26 | #ifndef _WIN32 | |
| 27 | #include <netdb.h> | |
| 28 | #include <sys/socket.h> | |
| 29 | #include <netinet/in.h> | |
| 30 | #endif | |
| 31 | ||
| 32 | #ifdef _WIN32 | |
| 33 | #include "win32dep.h" | |
| 34 | #endif | |
| 35 | ||
| 36 | /** | |
| 37 | * This sends a channel 1 SNAC containing the FLAP version. | |
| 38 | * The FLAP version is sent by itself at the beginning of every | |
| 39 | * connection to a FLAP server. It is always the very first | |
| 40 | * packet sent by both the server and the client after the SYN, | |
| 41 | * SYN/ACK, ACK handshake. | |
| 42 | */ | |
| 43 | void | |
| 44 | flap_connection_send_version(OscarData *od, FlapConnection *conn) | |
| 45 | { | |
| 46 | FlapFrame *frame; | |
| 47 | ||
| 48 | frame = flap_frame_new(od, 0x01, 4); | |
| 49 | byte_stream_put32(&frame->data, 0x00000001); | |
| 50 | flap_connection_send(conn, frame); | |
| 51 | } | |
| 52 | ||
| 53 | /** | |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
54 | * This sends a channel 1 FLAP containing the FLAP version and |
| 13593 | 55 | * the authentication cookie. This is sent when connecting to |
| 56 | * any FLAP server after the initial connection to the auth | |
| 57 | * server. It is always the very first packet sent by both the | |
| 58 | * server and the client after the SYN, SYN/ACK, ACK handshake. | |
| 59 | */ | |
| 60 | void | |
| 61 | flap_connection_send_version_with_cookie(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy) | |
| 62 | { | |
| 63 | FlapFrame *frame; | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
64 | GSList *tlvlist = NULL; |
| 13593 | 65 | |
| 66 | frame = flap_frame_new(od, 0x01, 4 + 2 + 2 + length); | |
| 67 | byte_stream_put32(&frame->data, 0x00000001); | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
68 | aim_tlvlist_add_raw(&tlvlist, 0x0006, length, chipsahoy); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
69 | aim_tlvlist_write(&frame->data, &tlvlist); |
|
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
70 | aim_tlvlist_free(tlvlist); |
| 13593 | 71 | |
| 72 | flap_connection_send(conn, frame); | |
| 73 | } | |
| 74 | ||
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
75 | static struct rateclass * |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
76 | flap_connection_get_rateclass(FlapConnection *conn, guint16 family, guint16 subtype) |
|
15152
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
77 | { |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
78 | GSList *tmp1; |
|
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
79 | gconstpointer key; |
|
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
80 | |
|
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
81 | key = GUINT_TO_POINTER((family << 16) + subtype); |
|
15152
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
82 | |
|
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
83 | for (tmp1 = conn->rateclasses; tmp1 != NULL; tmp1 = tmp1->next) |
|
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
84 | { |
|
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
85 | struct rateclass *rateclass; |
|
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
86 | rateclass = tmp1->data; |
|
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
87 | |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
88 | if (g_hash_table_lookup(rateclass->members, key)) |
|
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
89 | return rateclass; |
|
15152
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
90 | } |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
91 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
92 | return NULL; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
93 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
94 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
95 | /* |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
96 | * Attempt to calculate what our new current average would be if we |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
97 | * were to send a SNAC in this rateclass at the given time. |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
98 | */ |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
99 | static guint32 |
|
15172
8032180fbca3
[gaim-migrate @ 17896]
Mark Doliner <markdoliner@pidgin.im>
parents:
15169
diff
changeset
|
100 | rateclass_get_new_current(FlapConnection *conn, struct rateclass *rateclass, struct timeval *now) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
101 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
102 | unsigned long timediff; /* In milliseconds */ |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
103 | |
|
15172
8032180fbca3
[gaim-migrate @ 17896]
Mark Doliner <markdoliner@pidgin.im>
parents:
15169
diff
changeset
|
104 | timediff = (now->tv_sec - rateclass->last.tv_sec) * 1000 + (now->tv_usec - rateclass->last.tv_usec) / 1000; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
105 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
106 | /* This formula is taken from the joscar API docs. Preesh. */ |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
107 | return MIN(((rateclass->current * (rateclass->windowsize - 1)) + timediff) / rateclass->windowsize, rateclass->max); |
|
15152
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
108 | } |
|
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
109 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
110 | /* |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
111 | * Attempt to send the contents of a given queue |
|
23888
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
112 | * |
|
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
113 | * @return TRUE if the queue was completely emptied or was initially |
|
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
114 | * empty; FALSE if rate limiting prevented it from being |
|
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
115 | * emptied. |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
116 | */ |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
117 | static gboolean flap_connection_send_snac_queue(FlapConnection *conn, struct timeval now, GQueue *queue) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
118 | { |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
119 | while (!g_queue_is_empty(queue)) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
120 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
121 | QueuedSnac *queued_snac; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
122 | struct rateclass *rateclass; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
123 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
124 | queued_snac = g_queue_peek_head(queue); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
125 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
126 | rateclass = flap_connection_get_rateclass(conn, queued_snac->family, queued_snac->subtype); |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
127 | if (rateclass != NULL) |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
128 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
129 | guint32 new_current; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
130 | |
|
15172
8032180fbca3
[gaim-migrate @ 17896]
Mark Doliner <markdoliner@pidgin.im>
parents:
15169
diff
changeset
|
131 | new_current = rateclass_get_new_current(conn, rateclass, &now); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
132 | |
|
19110
0a9827c6feb0
Wiggle two comments around
Mark Doliner <markdoliner@pidgin.im>
parents:
18875
diff
changeset
|
133 | /* (Add 100ms padding to account for inaccuracies in the calculation) */ |
|
15191
d52a86abd255
[gaim-migrate @ 17915]
Mark Doliner <markdoliner@pidgin.im>
parents:
15172
diff
changeset
|
134 | if (new_current < rateclass->alert + 100) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
135 | /* Not ready to send this SNAC yet--keep waiting. */ |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
136 | return FALSE; |
|
23888
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
137 | |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
138 | rateclass->current = new_current; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
139 | rateclass->last.tv_sec = now.tv_sec; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
140 | rateclass->last.tv_usec = now.tv_usec; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
141 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
142 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
143 | flap_connection_send(conn, queued_snac->frame); |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
144 | g_free(queued_snac); |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
145 | g_queue_pop_head(queue); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
146 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
147 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
148 | /* We emptied the queue */ |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
149 | return TRUE; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
150 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
151 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
152 | static gboolean flap_connection_send_queued(gpointer data) |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
153 | { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
154 | FlapConnection *conn; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
155 | struct timeval now; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
156 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
157 | conn = data; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
158 | gettimeofday(&now, NULL); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
159 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
160 | purple_debug_info("oscar", "Attempting to send %u queued SNACs and %u queued low-priority SNACs for %p\n", |
|
24317
f51faf0f2f36
Don't use g_queue_get_length because it requires glib 2.4
Mark Doliner <markdoliner@pidgin.im>
parents:
23889
diff
changeset
|
161 | (conn->queued_snacs ? conn->queued_snacs->length : 0), |
|
f51faf0f2f36
Don't use g_queue_get_length because it requires glib 2.4
Mark Doliner <markdoliner@pidgin.im>
parents:
23889
diff
changeset
|
162 | (conn->queued_lowpriority_snacs ? conn->queued_lowpriority_snacs->length : 0), |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
163 | conn); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
164 | if (!conn->queued_snacs || flap_connection_send_snac_queue(conn, now, conn->queued_snacs)) { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
165 | if (!conn->queued_lowpriority_snacs || flap_connection_send_snac_queue(conn, now, conn->queued_lowpriority_snacs)) { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
166 | /* Both queues emptied. */ |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
167 | conn->queued_timeout = 0; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
168 | return FALSE; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
169 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
170 | } |
|
23888
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
171 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
172 | /* We couldn't send all our SNACs. Keep trying */ |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
173 | return TRUE; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
174 | } |
|
15152
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
175 | |
| 13593 | 176 | /** |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
177 | * This sends a channel 2 FLAP containing a SNAC. The SNAC family and |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
178 | * subtype are looked up in the rate info for this connection, and if |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
179 | * sending this SNAC will induce rate limiting then we delay sending |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
180 | * of the SNAC by putting it into an outgoing holding queue. |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
181 | * |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
182 | * @param data The optional bytestream that makes up the data portion |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
183 | * of this SNAC. For empty SNACs this should be NULL. |
|
23888
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
184 | * @param high_priority If TRUE, the SNAC will be queued normally if |
|
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
185 | * needed. If FALSE, it wil be queued separately, to be sent |
|
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
186 | * only if all high priority SNACs have been sent. |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
187 | */ |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
188 | void |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
189 | flap_connection_send_snac_with_priority(OscarData *od, FlapConnection *conn, guint16 family, const guint16 subtype, guint16 flags, aim_snacid_t snacid, ByteStream *data, gboolean high_priority) |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
190 | { |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
191 | FlapFrame *frame; |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
192 | guint32 length; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
193 | gboolean enqueue = FALSE; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
194 | struct rateclass *rateclass; |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
195 | |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
196 | length = data != NULL ? data->offset : 0; |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
197 | |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
198 | frame = flap_frame_new(od, 0x02, 10 + length); |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
199 | aim_putsnac(&frame->data, family, subtype, flags, snacid); |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
200 | |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
201 | if (length > 0) |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
202 | { |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
203 | byte_stream_rewind(data); |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
204 | byte_stream_putbs(&frame->data, data, length); |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
205 | } |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
206 | |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
207 | if (conn->queued_timeout != 0) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
208 | enqueue = TRUE; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
209 | else if ((rateclass = flap_connection_get_rateclass(conn, family, subtype)) != NULL) |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
210 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
211 | struct timeval now; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
212 | guint32 new_current; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
213 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
214 | gettimeofday(&now, NULL); |
|
15172
8032180fbca3
[gaim-migrate @ 17896]
Mark Doliner <markdoliner@pidgin.im>
parents:
15169
diff
changeset
|
215 | new_current = rateclass_get_new_current(conn, rateclass, &now); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
216 | |
|
19110
0a9827c6feb0
Wiggle two comments around
Mark Doliner <markdoliner@pidgin.im>
parents:
18875
diff
changeset
|
217 | /* (Add 100ms padding to account for inaccuracies in the calculation) */ |
|
15191
d52a86abd255
[gaim-migrate @ 17915]
Mark Doliner <markdoliner@pidgin.im>
parents:
15172
diff
changeset
|
218 | if (new_current < rateclass->alert + 100) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
219 | { |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
22622
diff
changeset
|
220 | purple_debug_info("oscar", "Current rate for conn %p would be %u, but we alert at %u; enqueueing\n", conn, new_current, (rateclass->alert + 100)); |
|
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
22622
diff
changeset
|
221 | |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
222 | enqueue = TRUE; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
223 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
224 | else |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
225 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
226 | rateclass->current = new_current; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
227 | rateclass->last.tv_sec = now.tv_sec; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
228 | rateclass->last.tv_usec = now.tv_usec; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
229 | } |
|
22860
2b0e247173b2
All SNACs on FLAP channel 2 except in the auth family are now sent through
Evan Schoenberg <evands@pidgin.im>
parents:
22622
diff
changeset
|
230 | } else { |
|
24659
6e20158ee689
Remove a few spurious debug_warns
Mark Doliner <markdoliner@pidgin.im>
parents:
24317
diff
changeset
|
231 | /* |
|
6e20158ee689
Remove a few spurious debug_warns
Mark Doliner <markdoliner@pidgin.im>
parents:
24317
diff
changeset
|
232 | * It's normal for SNACs 0x0001/0x0006 and 0x0001/0x0017 to be |
|
6e20158ee689
Remove a few spurious debug_warns
Mark Doliner <markdoliner@pidgin.im>
parents:
24317
diff
changeset
|
233 | * sent before we receive rate info from the server, so don't |
|
6e20158ee689
Remove a few spurious debug_warns
Mark Doliner <markdoliner@pidgin.im>
parents:
24317
diff
changeset
|
234 | * bother warning about them. |
|
6e20158ee689
Remove a few spurious debug_warns
Mark Doliner <markdoliner@pidgin.im>
parents:
24317
diff
changeset
|
235 | */ |
|
6e20158ee689
Remove a few spurious debug_warns
Mark Doliner <markdoliner@pidgin.im>
parents:
24317
diff
changeset
|
236 | if (family != 0x0001 || (subtype != 0x0006 && subtype != 0x0017)) |
|
6e20158ee689
Remove a few spurious debug_warns
Mark Doliner <markdoliner@pidgin.im>
parents:
24317
diff
changeset
|
237 | purple_debug_warning("oscar", "No rate class found for family 0x%04hx subtype 0x%04hx\n", family, subtype); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
238 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
239 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
240 | if (enqueue) |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
241 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
242 | /* We've been sending too fast, so delay this message */ |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
243 | QueuedSnac *queued_snac; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
244 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
245 | queued_snac = g_new(QueuedSnac, 1); |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
246 | queued_snac->family = family; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
247 | queued_snac->subtype = subtype; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
248 | queued_snac->frame = frame; |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
249 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
250 | if (high_priority) { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
251 | if (!conn->queued_snacs) |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
252 | conn->queued_snacs = g_queue_new(); |
|
23888
415748b9d4f7
This looks good to me. I'm thinking we probably don't want to get
Mark Doliner <markdoliner@pidgin.im>
parents:
23886
diff
changeset
|
253 | g_queue_push_tail(conn->queued_snacs, queued_snac); |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
254 | } else { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
255 | if (!conn->queued_lowpriority_snacs) |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
256 | conn->queued_lowpriority_snacs = g_queue_new(); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
257 | g_queue_push_tail(conn->queued_lowpriority_snacs, queued_snac); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
258 | } |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
259 | |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
260 | if (conn->queued_timeout == 0) |
| 15884 | 261 | conn->queued_timeout = purple_timeout_add(500, flap_connection_send_queued, conn); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
262 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
263 | return; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
264 | } |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
265 | |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
266 | flap_connection_send(conn, frame); |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
267 | } |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
268 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
269 | void |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
270 | flap_connection_send_snac(OscarData *od, FlapConnection *conn, guint16 family, const guint16 subtype, guint16 flags, aim_snacid_t snacid, ByteStream *data) |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
271 | { |
|
23889
9c737b728db7
Missed one of these guys
Mark Doliner <markdoliner@pidgin.im>
parents:
23888
diff
changeset
|
272 | flap_connection_send_snac_with_priority(od, conn, family, subtype, flags, snacid, data, TRUE); |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
273 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
274 | |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
275 | /** |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
276 | * This sends an empty channel 4 FLAP. This is sent to signify |
| 13593 | 277 | * that we're logging off. This shouldn't really be necessary-- |
| 278 | * usually the AIM server will detect that the TCP connection has | |
| 279 | * been destroyed--but it's good practice. | |
| 280 | */ | |
| 281 | static void | |
| 282 | flap_connection_send_close(OscarData *od, FlapConnection *conn) | |
| 283 | { | |
| 284 | FlapFrame *frame; | |
| 285 | ||
| 286 | frame = flap_frame_new(od, 0x04, 0); | |
| 287 | flap_connection_send(conn, frame); | |
| 288 | } | |
| 289 | ||
| 290 | /** | |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
291 | * This sends an empty channel 5 FLAP. This is used as a keepalive |
| 13593 | 292 | * packet in FLAP connections. WinAIM 4.x and higher send these |
| 293 | * _every minute_ to keep the connection alive. | |
| 294 | */ | |
| 295 | void | |
| 296 | flap_connection_send_keepalive(OscarData *od, FlapConnection *conn) | |
| 297 | { | |
| 298 | FlapFrame *frame; | |
| 299 | ||
| 300 | frame = flap_frame_new(od, 0x05, 0); | |
| 301 | flap_connection_send(conn, frame); | |
| 302 | ||
| 303 | /* clean out SNACs over 60sec old */ | |
| 304 | aim_cleansnacs(od, 60); | |
| 305 | } | |
| 306 | ||
| 307 | /** | |
| 308 | * Allocate a new empty connection structure. | |
| 309 | * | |
| 310 | * @param od The oscar session associated with this connection. | |
| 311 | * @param type Type of connection to create | |
| 312 | * | |
| 313 | * @return Returns the new connection structure. | |
| 314 | */ | |
| 315 | FlapConnection * | |
| 316 | flap_connection_new(OscarData *od, int type) | |
| 317 | { | |
| 318 | FlapConnection *conn; | |
| 319 | ||
| 320 | conn = g_new0(FlapConnection, 1); | |
| 321 | conn->od = od; | |
| 15884 | 322 | conn->buffer_outgoing = purple_circ_buffer_new(0); |
| 13593 | 323 | conn->fd = -1; |
| 324 | conn->subtype = -1; | |
| 325 | conn->type = type; | |
| 326 | ||
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
327 | od->oscar_connections = g_slist_prepend(od->oscar_connections, conn); |
| 13593 | 328 | |
| 329 | return conn; | |
| 330 | } | |
| 331 | ||
| 332 | /** | |
| 333 | * Close (but not free) a connection. | |
| 334 | * | |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
335 | * This cancels any currently pending connection attempt, |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
336 | * closes any open fd and frees the auth cookie. |
| 13593 | 337 | * |
| 338 | * @param conn The connection to close. | |
| 339 | */ | |
| 340 | void | |
| 341 | flap_connection_close(OscarData *od, FlapConnection *conn) | |
| 342 | { | |
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
343 | if (conn->connect_data != NULL) |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
344 | { |
| 15884 | 345 | purple_proxy_connect_cancel(conn->connect_data); |
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
346 | conn->connect_data = NULL; |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
347 | } |
| 13593 | 348 | |
|
23878
63d4f60097a4
Daniel Atallah pointed out that this was obviously wrong. So we would
Mark Doliner <markdoliner@pidgin.im>
parents:
23082
diff
changeset
|
349 | if (conn->new_conn_data != NULL) |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
350 | { |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
351 | if (conn->type == SNAC_FAMILY_CHAT) |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
352 | { |
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
353 | oscar_chat_destroy(conn->new_conn_data); |
|
23879
ba5affe13543
I swear I did this! I must have gotten a little overzealous with the
Mark Doliner <markdoliner@pidgin.im>
parents:
23878
diff
changeset
|
354 | conn->new_conn_data = NULL; |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
355 | } |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
356 | } |
| 13593 | 357 | |
|
17539
0fd875385856
Only check for EAGAIN if send returns -1, not when it returns 0
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
358 | if (conn->fd >= 0) |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
359 | { |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
360 | if (conn->type == SNAC_FAMILY_LOCATE) |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
361 | flap_connection_send_close(od, conn); |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
362 | |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
363 | close(conn->fd); |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
364 | conn->fd = -1; |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
365 | } |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
366 | |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
367 | if (conn->watcher_incoming != 0) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
368 | { |
| 15884 | 369 | purple_input_remove(conn->watcher_incoming); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
370 | conn->watcher_incoming = 0; |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
371 | } |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
372 | |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
373 | if (conn->watcher_outgoing != 0) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
374 | { |
| 15884 | 375 | purple_input_remove(conn->watcher_outgoing); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
376 | conn->watcher_outgoing = 0; |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
377 | } |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
378 | |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
379 | g_free(conn->buffer_incoming.data.data); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
380 | conn->buffer_incoming.data.data = NULL; |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
381 | |
| 15884 | 382 | purple_circ_buffer_destroy(conn->buffer_outgoing); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
383 | conn->buffer_outgoing = NULL; |
| 13593 | 384 | } |
| 385 | ||
| 386 | static void | |
|
15148
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
387 | flap_connection_destroy_rateclass(struct rateclass *rateclass) |
| 13593 | 388 | { |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
389 | g_hash_table_destroy(rateclass->members); |
|
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
390 | g_free(rateclass); |
| 13593 | 391 | } |
| 392 | ||
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
393 | /** |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
394 | * Free a FlapFrame |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
395 | * |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
396 | * @param frame The frame to free. |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
397 | */ |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
398 | static void |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
399 | flap_frame_destroy(FlapFrame *frame) |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
400 | { |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
401 | g_free(frame->data.data); |
|
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
402 | g_free(frame); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
403 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
404 | |
| 13593 | 405 | static gboolean |
| 406 | flap_connection_destroy_cb(gpointer data) | |
| 407 | { | |
| 408 | FlapConnection *conn; | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
409 | OscarData *od; |
| 15884 | 410 | PurpleAccount *account; |
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
411 | aim_rxcallback_t userfunc; |
| 13593 | 412 | |
| 413 | conn = data; | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
414 | od = conn->od; |
|
22296
120207b25525
Undo revision c10f76ea0a1d80d4b5e7c2807c239a9bbb59bc1e. This should
Mark Doliner <markdoliner@pidgin.im>
parents:
22295
diff
changeset
|
415 | account = purple_connection_get_account(od->gc); |
| 13593 | 416 | |
| 15884 | 417 | purple_debug_info("oscar", "Destroying oscar connection of " |
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
418 | "type 0x%04hx. Disconnect reason is %d\n", |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
419 | conn->type, conn->disconnect_reason); |
| 13593 | 420 | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
421 | od->oscar_connections = g_slist_remove(od->oscar_connections, conn); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
422 | |
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
423 | if ((userfunc = aim_callhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR))) |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
424 | userfunc(od, conn, NULL, conn->disconnect_code, conn->error_message); |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
425 | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
426 | /* |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
427 | * TODO: If we don't have a SNAC_FAMILY_LOCATE connection then |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
428 | * we should try to request one instead of disconnecting. |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
429 | */ |
|
22296
120207b25525
Undo revision c10f76ea0a1d80d4b5e7c2807c239a9bbb59bc1e. This should
Mark Doliner <markdoliner@pidgin.im>
parents:
22295
diff
changeset
|
430 | if (!account->disconnecting && ((od->oscar_connections == NULL) |
|
120207b25525
Undo revision c10f76ea0a1d80d4b5e7c2807c239a9bbb59bc1e. This should
Mark Doliner <markdoliner@pidgin.im>
parents:
22295
diff
changeset
|
431 | || (!flap_connection_getbytype(od, SNAC_FAMILY_LOCATE)))) |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
432 | { |
| 15884 | 433 | /* No more FLAP connections! Sign off this PurpleConnection! */ |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
434 | gchar *tmp; |
| 21279 | 435 | PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; |
|
20452
a9fc6198b5c6
Add disconnection reasons to oscar.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
436 | |
|
18875
c9c59be46538
Move a call to purple_connection_error() from oscar.c to
Mark Doliner <markdoliner@pidgin.im>
parents:
18874
diff
changeset
|
437 | if (conn->disconnect_code == 0x0001) { |
| 21279 | 438 | reason = PURPLE_CONNECTION_ERROR_NAME_IN_USE; |
|
18875
c9c59be46538
Move a call to purple_connection_error() from oscar.c to
Mark Doliner <markdoliner@pidgin.im>
parents:
18874
diff
changeset
|
439 | tmp = g_strdup(_("You have signed on from another location.")); |
|
20658
91594d39738c
Clear the password consistently when we get a "Signed-On elsewhere" or a "Invalid Password" disconnection. Disconnection reason codes will take care of this in the core, but until then, this is ok. Fixes #3204.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
440 | if (!purple_account_get_remember_password(account)) |
|
91594d39738c
Clear the password consistently when we get a "Signed-On elsewhere" or a "Invalid Password" disconnection. Disconnection reason codes will take care of this in the core, but until then, this is ok. Fixes #3204.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
441 | purple_account_set_password(account, NULL); |
|
18875
c9c59be46538
Move a call to purple_connection_error() from oscar.c to
Mark Doliner <markdoliner@pidgin.im>
parents:
18874
diff
changeset
|
442 | } else if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED) |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
443 | tmp = g_strdup(_("Server closed the connection.")); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
444 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
445 | tmp = g_strdup_printf(_("Lost connection with server:\n%s"), |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
446 | conn->error_message); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
447 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
448 | tmp = g_strdup(_("Received invalid data on connection with server.")); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
449 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
450 | tmp = g_strdup_printf(_("Could not establish a connection with the server:\n%s"), |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
451 | conn->error_message); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
452 | else |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
453 | /* |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
454 | * We shouldn't print a message for some disconnect_reasons. |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
455 | * Like OSCAR_DISCONNECT_LOCAL_CLOSED. |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
456 | */ |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
457 | tmp = NULL; |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
458 | |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
459 | if (tmp != NULL) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
460 | { |
|
20452
a9fc6198b5c6
Add disconnection reasons to oscar.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
461 | purple_connection_error_reason(od->gc, reason, tmp); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
462 | g_free(tmp); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
463 | } |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
464 | } |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
465 | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
466 | flap_connection_close(od, conn); |
| 13593 | 467 | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
468 | g_free(conn->error_message); |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
469 | g_free(conn->cookie); |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
470 | |
| 13593 | 471 | /* |
| 472 | * Free conn->internal, if necessary | |
| 473 | */ | |
| 474 | if (conn->type == SNAC_FAMILY_CHAT) | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
475 | flap_connection_destroy_chat(od, conn); |
| 13593 | 476 | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
477 | g_slist_free(conn->groups); |
|
15148
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
478 | while (conn->rateclasses != NULL) |
|
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
479 | { |
|
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
480 | flap_connection_destroy_rateclass(conn->rateclasses->data); |
|
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
481 | conn->rateclasses = g_slist_delete_link(conn->rateclasses, conn->rateclasses); |
|
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
482 | } |
| 13593 | 483 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
484 | if (conn->queued_snacs) { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
485 | while (!g_queue_is_empty(conn->queued_snacs)) |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
486 | { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
487 | QueuedSnac *queued_snac; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
488 | queued_snac = g_queue_pop_head(conn->queued_snacs); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
489 | flap_frame_destroy(queued_snac->frame); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
490 | g_free(queued_snac); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
491 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
492 | g_queue_free(conn->queued_snacs); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
493 | } |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
494 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
495 | if (conn->queued_lowpriority_snacs) { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
496 | while (!g_queue_is_empty(conn->queued_lowpriority_snacs)) |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
497 | { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
498 | QueuedSnac *queued_snac; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
499 | queued_snac = g_queue_pop_head(conn->queued_lowpriority_snacs); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
500 | flap_frame_destroy(queued_snac->frame); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
501 | g_free(queued_snac); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
502 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
503 | g_queue_free(conn->queued_lowpriority_snacs); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
504 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
505 | |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
506 | if (conn->queued_timeout > 0) |
| 15884 | 507 | purple_timeout_remove(conn->queued_timeout); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
508 | |
|
14048
b577c53406c0
[gaim-migrate @ 16556]
Mark Doliner <markdoliner@pidgin.im>
parents:
13726
diff
changeset
|
509 | g_free(conn); |
|
b577c53406c0
[gaim-migrate @ 16556]
Mark Doliner <markdoliner@pidgin.im>
parents:
13726
diff
changeset
|
510 | |
| 13593 | 511 | return FALSE; |
| 512 | } | |
| 513 | ||
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
514 | /** |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
515 | * See the comments for the parameters of |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
516 | * flap_connection_schedule_destroy(). |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
517 | */ |
| 13593 | 518 | void |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
519 | flap_connection_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
| 13593 | 520 | { |
| 521 | if (conn->destroy_timeout != 0) | |
| 15884 | 522 | purple_timeout_remove(conn->destroy_timeout); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
523 | conn->disconnect_reason = reason; |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
524 | g_free(conn->error_message); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
525 | conn->error_message = g_strdup(error_message); |
| 13593 | 526 | flap_connection_destroy_cb(conn); |
| 527 | } | |
| 528 | ||
| 529 | /** | |
| 15884 | 530 | * Schedule Purple to destroy the given FlapConnection as soon as we |
| 13593 | 531 | * return control back to the program's main loop. We must do this |
| 532 | * if we want to destroy the connection but we are still using it | |
| 533 | * for some reason. | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
534 | * |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
535 | * @param reason The reason for the disconnection. |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
536 | * @param error_message A brief error message that gives more detail |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
537 | * regarding the reason for the disconnecting. This should |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
538 | * be NULL for everything except OSCAR_DISCONNECT_LOST_CONNECTION, |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20658
diff
changeset
|
539 | * in which case it should contain the value of g_strerror(errno), |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
540 | * and OSCAR_DISCONNECT_COULD_NOT_CONNECT, in which case it |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
541 | * should contain the error_message passed back from the call |
| 15884 | 542 | * to purple_proxy_connect(). |
| 13593 | 543 | */ |
| 544 | void | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
545 | flap_connection_schedule_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
| 13593 | 546 | { |
| 547 | if (conn->destroy_timeout != 0) | |
| 548 | /* Already taken care of */ | |
| 549 | return; | |
| 550 | ||
| 15884 | 551 | purple_debug_info("oscar", "Scheduling destruction of FLAP " |
| 13593 | 552 | "connection of type 0x%04hx\n", conn->type); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
553 | conn->disconnect_reason = reason; |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14454
diff
changeset
|
554 | g_free(conn->error_message); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
555 | conn->error_message = g_strdup(error_message); |
| 15884 | 556 | conn->destroy_timeout = purple_timeout_add(0, flap_connection_destroy_cb, conn); |
| 13593 | 557 | } |
| 558 | ||
| 559 | /** | |
| 560 | * In OSCAR, every connection has a set of SNAC groups associated | |
| 561 | * with it. These are the groups that you can send over this connection | |
| 562 | * without being guaranteed a "Not supported" SNAC error. | |
| 563 | * | |
| 564 | * The grand theory of things says that these associations transcend | |
| 565 | * what libfaim calls "connection types" (conn->type). You can probably | |
| 566 | * see the elegance here, but since I want to revel in it for a bit, you | |
| 567 | * get to hear it all spelled out. | |
| 568 | * | |
| 569 | * So let us say that you have your core BOS connection running. One | |
| 570 | * of your modules has just given you a SNAC of the group 0x0004 to send | |
| 571 | * you. Maybe an IM destined for some twit in Greenland. So you start | |
| 572 | * at the top of your connection list, looking for a connection that | |
| 573 | * claims to support group 0x0004. You find one. Why, that neat BOS | |
| 574 | * connection of yours can do that. So you send it on its way. | |
| 575 | * | |
| 576 | * Now, say, that fellow from Greenland has friends and they all want to | |
| 577 | * meet up with you in a lame chat room. This has landed you a SNAC | |
| 578 | * in the family 0x000e and you have to admit you're a bit lost. You've | |
| 579 | * searched your connection list for someone who wants to make your life | |
| 580 | * easy and deliver this SNAC for you, but there isn't one there. | |
| 581 | * | |
| 582 | * Here comes the good bit. Without even letting anyone know, particularly | |
| 583 | * the module that decided to send this SNAC, and definitely not that twit | |
| 584 | * in Greenland, you send out a service request. In this request, you have | |
| 585 | * marked the need for a connection supporting group 0x000e. A few seconds | |
| 586 | * later, you receive a service redirect with an IP address and a cookie in | |
| 587 | * it. Great, you say. Now I have something to do. Off you go, making | |
| 588 | * that connection. One of the first things you get from this new server | |
| 589 | * is a message saying that indeed it does support the group you were looking | |
| 590 | * for. So you continue and send rate confirmation and all that. | |
| 591 | * | |
| 592 | * Then you remember you had that SNAC to send, and now you have a means to | |
| 593 | * do it, and you do, and everyone is happy. Except the Greenlander, who is | |
| 594 | * still stuck in the bitter cold. | |
| 595 | * | |
| 596 | * Oh, and this is useful for building the Migration SNACs, too. In the | |
| 597 | * future, this may help convince me to implement rate limit mitigation | |
| 598 | * for real. We'll see. | |
| 599 | * | |
| 600 | * Just to make me look better, I'll say that I've known about this great | |
| 601 | * scheme for quite some time now. But I still haven't convinced myself | |
| 602 | * to make libfaim work that way. It would take a fair amount of effort, | |
| 603 | * and probably some client API changes as well. (Whenever I don't want | |
| 604 | * to do something, I just say it would change the client API. Then I | |
| 605 | * instantly have a couple of supporters of not doing it.) | |
| 606 | * | |
| 607 | * Generally, addgroup is only called by the internal handling of the | |
| 608 | * server ready SNAC. So if you want to do something before that, you'll | |
| 609 | * have to be more creative. That is done rather early, though, so I don't | |
| 610 | * think you have to worry about it. Unless you're me. I care deeply | |
| 611 | * about such inane things. | |
| 612 | * | |
| 613 | */ | |
| 614 | ||
| 615 | /** | |
| 616 | * Find a FlapConnection that supports the given oscar | |
| 617 | * family. | |
| 618 | */ | |
| 619 | FlapConnection * | |
| 620 | flap_connection_findbygroup(OscarData *od, guint16 group) | |
| 621 | { | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
622 | GSList *cur; |
| 13593 | 623 | |
| 624 | for (cur = od->oscar_connections; cur != NULL; cur = cur->next) | |
| 625 | { | |
| 626 | FlapConnection *conn; | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
627 | GSList *l; |
| 13593 | 628 | |
| 629 | conn = cur->data; | |
| 630 | ||
|
13612
c51da9e6fec1
[gaim-migrate @ 15997]
Mark Doliner <markdoliner@pidgin.im>
parents:
13611
diff
changeset
|
631 | for (l = conn->groups; l != NULL; l = l->next) |
| 13593 | 632 | { |
|
13612
c51da9e6fec1
[gaim-migrate @ 15997]
Mark Doliner <markdoliner@pidgin.im>
parents:
13611
diff
changeset
|
633 | if (GPOINTER_TO_UINT(l->data) == group) |
| 13593 | 634 | return conn; |
| 635 | } | |
| 636 | } | |
| 637 | ||
| 638 | return NULL; | |
| 639 | } | |
| 640 | ||
| 641 | /** | |
| 642 | * Locates a connection of the specified type in the | |
| 643 | * specified session. | |
| 644 | * | |
| 645 | * TODO: Use flap_connection_findbygroup everywhere and get rid of this. | |
| 646 | * | |
| 647 | * @param od The session to search. | |
| 648 | * @param type The type of connection to look for. | |
| 649 | * | |
| 650 | * @return Returns the first connection found of the given target type, | |
| 651 | * or NULL if none could be found. | |
| 652 | */ | |
| 653 | FlapConnection * | |
| 654 | flap_connection_getbytype(OscarData *od, int type) | |
| 655 | { | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
656 | GSList *cur; |
| 13593 | 657 | |
| 658 | for (cur = od->oscar_connections; cur != NULL; cur = cur->next) | |
| 659 | { | |
| 660 | FlapConnection *conn; | |
| 661 | conn = cur->data; | |
| 662 | if ((conn->type == type) && (conn->connected)) | |
| 663 | return conn; | |
| 664 | } | |
| 665 | ||
| 666 | return NULL; | |
| 667 | } | |
| 668 | ||
| 669 | FlapConnection * | |
| 670 | flap_connection_getbytype_all(OscarData *od, int type) | |
| 671 | { | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
672 | GSList *cur; |
| 13593 | 673 | |
| 674 | for (cur = od->oscar_connections; cur; cur = cur->next) | |
| 675 | { | |
| 676 | FlapConnection *conn; | |
| 677 | conn = cur->data; | |
| 678 | if (conn->type == type) | |
| 679 | return conn; | |
| 680 | } | |
| 681 | ||
| 682 | return NULL; | |
| 683 | } | |
| 684 | ||
| 685 | /** | |
| 686 | * Allocate a new FLAP frame. | |
| 687 | * | |
| 688 | * @param channel The FLAP channel. This is almost always 2. | |
| 689 | */ | |
| 690 | FlapFrame * | |
| 691 | flap_frame_new(OscarData *od, guint16 channel, int datalen) | |
| 692 | { | |
| 693 | FlapFrame *frame; | |
| 694 | ||
| 695 | frame = g_new0(FlapFrame, 1); | |
| 696 | frame->channel = channel; | |
| 697 | ||
| 698 | if (datalen > 0) | |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
15150
diff
changeset
|
699 | byte_stream_new(&frame->data, datalen); |
| 13593 | 700 | |
| 701 | return frame; | |
| 702 | } | |
| 703 | ||
| 704 | static void | |
| 705 | parse_snac(OscarData *od, FlapConnection *conn, FlapFrame *frame) | |
| 706 | { | |
| 707 | aim_module_t *cur; | |
| 708 | aim_modsnac_t snac; | |
| 709 | ||
| 710 | if (byte_stream_empty(&frame->data) < 10) | |
| 711 | return; | |
| 712 | ||
| 713 | snac.family = byte_stream_get16(&frame->data); | |
| 714 | snac.subtype = byte_stream_get16(&frame->data); | |
| 715 | snac.flags = byte_stream_get16(&frame->data); | |
| 716 | snac.id = byte_stream_get32(&frame->data); | |
| 717 | ||
| 718 | /* SNAC flags are apparently uniform across all SNACs, so we handle them here */ | |
| 719 | if (snac.flags & 0x0001) { | |
| 720 | /* | |
| 721 | * This means the SNAC will be followed by another SNAC with | |
| 722 | * related information. We don't need to do anything about | |
| 723 | * this here. | |
| 724 | */ | |
| 725 | } | |
| 726 | if (snac.flags & 0x8000) { | |
| 727 | /* | |
| 728 | * This packet contains the version of the family that this SNAC is | |
| 729 | * in. You get this when your SSI module is version 2 or higher. | |
| 730 | * For now we have no need for this, but you could always save | |
| 731 | * it as a part of aim_modnsac_t, or something. The format is... | |
| 732 | * 2 byte length of total mini-header (which is 6 bytes), then TLV | |
| 733 | * of type 0x0001, length 0x0002, value is the 2 byte version | |
| 734 | * number | |
| 735 | */ | |
| 736 | byte_stream_advance(&frame->data, byte_stream_get16(&frame->data)); | |
| 737 | } | |
| 738 | ||
| 739 | for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) { | |
| 740 | ||
| 741 | if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) && | |
| 742 | (cur->family != snac.family)) | |
| 743 | continue; | |
| 744 | ||
| 745 | if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data)) | |
| 746 | return; | |
| 747 | } | |
| 748 | } | |
| 749 | ||
| 750 | static void | |
| 751 | parse_fakesnac(OscarData *od, FlapConnection *conn, FlapFrame *frame, guint16 family, guint16 subtype) | |
| 752 | { | |
| 753 | aim_module_t *cur; | |
| 754 | aim_modsnac_t snac; | |
| 755 | ||
| 756 | snac.family = family; | |
| 757 | snac.subtype = subtype; | |
| 758 | snac.flags = snac.id = 0; | |
| 759 | ||
| 760 | for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) { | |
| 761 | ||
| 762 | if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) && | |
| 763 | (cur->family != snac.family)) | |
| 764 | continue; | |
| 765 | ||
| 766 | if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data)) | |
| 767 | return; | |
| 768 | } | |
| 769 | } | |
| 770 | ||
| 771 | static void | |
| 772 | parse_flap_ch4(OscarData *od, FlapConnection *conn, FlapFrame *frame) | |
| 773 | { | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
774 | GSList *tlvlist; |
| 13593 | 775 | char *msg = NULL; |
| 776 | ||
| 777 | if (byte_stream_empty(&frame->data) == 0) { | |
| 778 | /* XXX should do something with this */ | |
| 779 | return; | |
| 780 | } | |
| 781 | ||
|
13603
12489c04a4ea
[gaim-migrate @ 15988]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
782 | /* An ICQ account is logging in */ |
| 13593 | 783 | if (conn->type == SNAC_FAMILY_AUTH) |
| 784 | { | |
| 785 | parse_fakesnac(od, conn, frame, 0x0017, 0x0003); | |
| 786 | return; | |
| 787 | } | |
| 788 | ||
| 789 | tlvlist = aim_tlvlist_read(&frame->data); | |
| 790 | ||
| 791 | if (aim_tlv_gettlv(tlvlist, 0x0009, 1)) | |
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
792 | conn->disconnect_code = aim_tlv_get16(tlvlist, 0x0009, 1); |
| 13593 | 793 | |
| 794 | if (aim_tlv_gettlv(tlvlist, 0x000b, 1)) | |
| 795 | msg = aim_tlv_getstr(tlvlist, 0x000b, 1); | |
| 796 | ||
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
797 | /* |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
798 | * The server ended this FLAP connnection, so let's be nice and |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
799 | * close the physical TCP connection |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
800 | */ |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
801 | flap_connection_schedule_destroy(conn, |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
802 | OSCAR_DISCONNECT_REMOTE_CLOSED, msg); |
| 13593 | 803 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
804 | aim_tlvlist_free(tlvlist); |
| 13593 | 805 | |
|
17280
7c0472208173
Make all the oscar memory allocations and frees use the glib functions to avoid problems when mixing C runtimes.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
806 | g_free(msg); |
| 13593 | 807 | } |
| 808 | ||
| 809 | /** | |
| 810 | * Takes a new incoming FLAP frame and sends it to the appropriate | |
| 811 | * handler function to be parsed. | |
| 812 | */ | |
| 813 | static void | |
| 814 | parse_flap(OscarData *od, FlapConnection *conn, FlapFrame *frame) | |
| 815 | { | |
| 816 | if (frame->channel == 0x01) { | |
| 817 | guint32 flap_version = byte_stream_get32(&frame->data); | |
| 818 | if (flap_version != 0x00000001) | |
| 819 | { | |
| 820 | /* Error! */ | |
| 15884 | 821 | purple_debug_warning("oscar", "Expecting FLAP version " |
|
22622
1ecb840b5101
Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <markdoliner@pidgin.im>
parents:
22317
diff
changeset
|
822 | "0x00000001 but received FLAP version %08x. Closing connection.\n", |
| 13593 | 823 | flap_version); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
824 | flap_connection_schedule_destroy(conn, |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
825 | OSCAR_DISCONNECT_INVALID_DATA, NULL); |
| 13593 | 826 | } |
| 827 | else | |
| 828 | conn->connected = TRUE; | |
| 829 | ||
| 830 | } else if (frame->channel == 0x02) { | |
| 831 | parse_snac(od, conn, frame); | |
| 832 | ||
| 833 | } else if (frame->channel == 0x04) { | |
| 834 | parse_flap_ch4(od, conn, frame); | |
| 835 | ||
| 836 | } else if (frame->channel == 0x05) { | |
| 837 | /* TODO: Reset our keepalive watchdog? */ | |
| 838 | ||
| 839 | } | |
| 840 | } | |
| 841 | ||
| 842 | /** | |
| 843 | * Read in all available data on the socket for a given connection. | |
| 844 | * All complete FLAPs handled immedate after they're received. | |
| 845 | * Incomplete FLAP data is stored locally and appended to the next | |
| 846 | * time this callback is triggered. | |
| 847 | */ | |
| 848 | void | |
| 15884 | 849 | flap_connection_recv_cb(gpointer data, gint source, PurpleInputCondition cond) |
| 13593 | 850 | { |
| 851 | FlapConnection *conn; | |
|
23079
b887906eed60
More s/ssize_t/gssize/
Daniel Atallah <datallah@pidgin.im>
parents:
23004
diff
changeset
|
852 | gssize read; |
| 13593 | 853 | |
| 854 | conn = data; | |
| 855 | ||
| 856 | /* Read data until we run out of data and break out of the loop */ | |
| 857 | while (TRUE) | |
| 858 | { | |
| 859 | /* Start reading a new FLAP */ | |
| 860 | if (conn->buffer_incoming.data.data == NULL) | |
| 861 | { | |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
862 | /* Read the first 6 bytes (the FLAP header) */ |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
863 | read = recv(conn->fd, conn->header + conn->header_received, |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
864 | 6 - conn->header_received, 0); |
| 13593 | 865 | |
| 866 | /* Check if the FLAP server closed the connection */ | |
| 867 | if (read == 0) | |
| 868 | { | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
869 | flap_connection_schedule_destroy(conn, |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
870 | OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
| 13593 | 871 | break; |
| 872 | } | |
| 873 | ||
| 874 | /* If there was an error then close the connection */ | |
|
17539
0fd875385856
Only check for EAGAIN if send returns -1, not when it returns 0
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
875 | if (read < 0) |
| 13593 | 876 | { |
| 877 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | |
| 878 | /* No worries */ | |
| 879 | break; | |
| 880 | ||
| 881 | /* Error! */ | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
882 | flap_connection_schedule_destroy(conn, |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20658
diff
changeset
|
883 | OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); |
| 13593 | 884 | break; |
| 885 | } | |
|
22277
7c386db62c81
Don't send keep-alives if we've received data since in the last KEEPALIVE_INTERVAL seconds
Sean Egan <seanegan@pidgin.im>
parents:
21503
diff
changeset
|
886 | conn->od->gc->last_received = time(NULL); |
| 13593 | 887 | |
| 888 | /* If we don't even have a complete FLAP header then do nothing */ | |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
889 | conn->header_received += read; |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
890 | if (conn->header_received < 6) |
| 13593 | 891 | break; |
| 892 | ||
| 893 | /* All FLAP frames must start with the byte 0x2a */ | |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
894 | if (aimutil_get8(&conn->header[0]) != 0x2a) |
| 13593 | 895 | { |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
896 | flap_connection_schedule_destroy(conn, |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
897 | OSCAR_DISCONNECT_INVALID_DATA, NULL); |
| 13593 | 898 | break; |
| 899 | } | |
| 900 | ||
|
15169
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
901 | /* Verify the sequence number sent by the server. */ |
|
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
902 | #if 0 |
|
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
903 | /* TODO: Need to initialize conn->seqnum_in somewhere before we can use this. */ |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
904 | if (aimutil_get16(&conn->header[1]) != conn->seqnum_in++) |
|
15169
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
905 | { |
|
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
906 | /* Received an out-of-order FLAP! */ |
|
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
907 | flap_connection_schedule_destroy(conn, |
|
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
908 | OSCAR_DISCONNECT_INVALID_DATA, NULL); |
|
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
909 | break; |
|
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
910 | } |
|
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
911 | #endif |
|
15147
101192282f5d
[gaim-migrate @ 17871]
Mark Doliner <markdoliner@pidgin.im>
parents:
14464
diff
changeset
|
912 | |
| 13593 | 913 | /* Initialize a new temporary FlapFrame for incoming data */ |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
914 | conn->buffer_incoming.channel = aimutil_get8(&conn->header[1]); |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
915 | conn->buffer_incoming.seqnum = aimutil_get16(&conn->header[2]); |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
916 | conn->buffer_incoming.data.len = aimutil_get16(&conn->header[4]); |
| 13593 | 917 | conn->buffer_incoming.data.data = g_new(guint8, conn->buffer_incoming.data.len); |
| 918 | conn->buffer_incoming.data.offset = 0; | |
| 919 | } | |
| 920 | ||
| 921 | if (conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset) | |
| 922 | { | |
| 923 | /* Read data into the temporary FlapFrame until it is complete */ | |
| 924 | read = recv(conn->fd, | |
| 925 | &conn->buffer_incoming.data.data[conn->buffer_incoming.data.offset], | |
| 926 | conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset, | |
| 927 | 0); | |
| 928 | ||
| 929 | /* Check if the FLAP server closed the connection */ | |
| 930 | if (read == 0) | |
| 931 | { | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
932 | flap_connection_schedule_destroy(conn, |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
933 | OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
| 13593 | 934 | break; |
| 935 | } | |
| 936 | ||
|
17539
0fd875385856
Only check for EAGAIN if send returns -1, not when it returns 0
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
937 | if (read < 0) |
| 13593 | 938 | { |
| 939 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | |
| 940 | /* No worries */ | |
| 941 | break; | |
| 942 | ||
| 943 | /* Error! */ | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
944 | flap_connection_schedule_destroy(conn, |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20658
diff
changeset
|
945 | OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); |
| 13593 | 946 | break; |
| 947 | } | |
| 948 | ||
| 949 | conn->buffer_incoming.data.offset += read; | |
| 950 | if (conn->buffer_incoming.data.offset < conn->buffer_incoming.data.len) | |
| 951 | /* Waiting for more data to arrive */ | |
| 952 | break; | |
| 953 | } | |
| 954 | ||
| 955 | /* We have a complete FLAP! Handle it and continue reading */ | |
| 956 | byte_stream_rewind(&conn->buffer_incoming.data); | |
| 957 | parse_flap(conn->od, conn, &conn->buffer_incoming); | |
| 958 | conn->lastactivity = time(NULL); | |
| 959 | ||
| 960 | g_free(conn->buffer_incoming.data.data); | |
| 961 | conn->buffer_incoming.data.data = NULL; | |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
962 | |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
963 | conn->header_received = 0; |
| 13593 | 964 | } |
| 965 | } | |
| 966 | ||
| 967 | static void | |
| 15884 | 968 | send_cb(gpointer data, gint source, PurpleInputCondition cond) |
| 13593 | 969 | { |
| 970 | FlapConnection *conn; | |
| 971 | int writelen, ret; | |
| 972 | ||
| 973 | conn = data; | |
| 15884 | 974 | writelen = purple_circ_buffer_get_max_read(conn->buffer_outgoing); |
| 13593 | 975 | |
| 976 | if (writelen == 0) | |
| 977 | { | |
| 15884 | 978 | purple_input_remove(conn->watcher_outgoing); |
| 13593 | 979 | conn->watcher_outgoing = 0; |
| 980 | return; | |
| 981 | } | |
| 982 | ||
| 983 | ret = send(conn->fd, conn->buffer_outgoing->outptr, writelen, 0); | |
| 984 | if (ret <= 0) | |
| 985 | { | |
|
17573
798d53d90cd1
Get rid of a compile warning
Mark Doliner <markdoliner@pidgin.im>
parents:
17539
diff
changeset
|
986 | if (ret < 0 && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) |
| 13593 | 987 | /* No worries */ |
| 988 | return; | |
| 989 | ||
| 990 | /* Error! */ | |
| 15884 | 991 | purple_input_remove(conn->watcher_outgoing); |
|
15191
d52a86abd255
[gaim-migrate @ 17915]
Mark Doliner <markdoliner@pidgin.im>
parents:
15172
diff
changeset
|
992 | conn->watcher_outgoing = 0; |
|
d52a86abd255
[gaim-migrate @ 17915]
Mark Doliner <markdoliner@pidgin.im>
parents:
15172
diff
changeset
|
993 | close(conn->fd); |
|
d52a86abd255
[gaim-migrate @ 17915]
Mark Doliner <markdoliner@pidgin.im>
parents:
15172
diff
changeset
|
994 | conn->fd = -1; |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
995 | flap_connection_schedule_destroy(conn, |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20658
diff
changeset
|
996 | OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); |
| 13593 | 997 | return; |
| 998 | } | |
| 999 | ||
| 15884 | 1000 | purple_circ_buffer_mark_read(conn->buffer_outgoing, ret); |
| 13593 | 1001 | } |
| 1002 | ||
| 1003 | static void | |
| 1004 | flap_connection_send_byte_stream(ByteStream *bs, FlapConnection *conn, size_t count) | |
| 1005 | { | |
| 1006 | if (conn == NULL) | |
| 1007 | return; | |
| 1008 | ||
| 1009 | /* Make sure we don't send past the end of the bs */ | |
| 1010 | if (count > byte_stream_empty(bs)) | |
| 1011 | count = byte_stream_empty(bs); /* truncate to remaining space */ | |
| 1012 | ||
| 1013 | if (count == 0) | |
| 1014 | return; | |
| 1015 | ||
| 1016 | /* Add everything to our outgoing buffer */ | |
| 15884 | 1017 | purple_circ_buffer_append(conn->buffer_outgoing, bs->data, count); |
| 13593 | 1018 | |
| 1019 | /* If we haven't already started writing stuff, then start the cycle */ | |
|
17539
0fd875385856
Only check for EAGAIN if send returns -1, not when it returns 0
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
1020 | if ((conn->watcher_outgoing == 0) && (conn->fd >= 0)) |
| 13593 | 1021 | { |
| 15884 | 1022 | conn->watcher_outgoing = purple_input_add(conn->fd, |
| 1023 | PURPLE_INPUT_WRITE, send_cb, conn); | |
| 13593 | 1024 | send_cb(conn, conn->fd, 0); |
| 1025 | } | |
| 1026 | } | |
| 1027 | ||
| 1028 | static void | |
| 1029 | sendframe_flap(FlapConnection *conn, FlapFrame *frame) | |
| 1030 | { | |
| 1031 | ByteStream bs; | |
| 1032 | int payloadlen, bslen; | |
| 1033 | ||
| 1034 | payloadlen = byte_stream_curpos(&frame->data); | |
| 1035 | ||
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
15150
diff
changeset
|
1036 | byte_stream_new(&bs, 6 + payloadlen); |
| 13593 | 1037 | |
| 1038 | /* FLAP header */ | |
| 1039 | byte_stream_put8(&bs, 0x2a); | |
| 1040 | byte_stream_put8(&bs, frame->channel); | |
| 1041 | byte_stream_put16(&bs, frame->seqnum); | |
| 1042 | byte_stream_put16(&bs, payloadlen); | |
| 1043 | ||
| 1044 | /* Payload */ | |
| 1045 | byte_stream_rewind(&frame->data); | |
| 1046 | byte_stream_putbs(&bs, &frame->data, payloadlen); | |
| 1047 | ||
| 1048 | bslen = byte_stream_curpos(&bs); | |
| 1049 | byte_stream_rewind(&bs); | |
| 1050 | flap_connection_send_byte_stream(&bs, conn, bslen); | |
| 1051 | ||
|
22861
76cb58c0c40a
Used byte_stream_destroy(), added in 2b0e247173b206213210577c194020c78c864474,
Evan Schoenberg <evands@pidgin.im>
parents:
22860
diff
changeset
|
1052 | byte_stream_destroy(&bs); |
| 13593 | 1053 | } |
| 1054 | ||
| 1055 | void | |
| 1056 | flap_connection_send(FlapConnection *conn, FlapFrame *frame) | |
| 1057 | { | |
|
15169
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
1058 | frame->seqnum = ++(conn->seqnum_out); |
| 13593 | 1059 | sendframe_flap(conn, frame); |
| 1060 | flap_frame_destroy(frame); | |
| 1061 | } |