Tue, 15 Apr 2014 21:20:13 +0200
cross-win32: fix prpls
| 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 | /** | |
| 33 | * This sends a channel 1 SNAC containing the FLAP version. | |
| 34 | * The FLAP version is sent by itself at the beginning of every | |
| 35 | * connection to a FLAP server. It is always the very first | |
| 36 | * packet sent by both the server and the client after the SYN, | |
| 37 | * SYN/ACK, ACK handshake. | |
| 38 | */ | |
| 39 | void | |
| 40 | flap_connection_send_version(OscarData *od, FlapConnection *conn) | |
| 41 | { | |
| 42 | FlapFrame *frame; | |
| 43 | ||
| 44 | frame = flap_frame_new(od, 0x01, 4); | |
|
27367
82426b0162d4
Make a function static and add two comments
Mark Doliner <markdoliner@pidgin.im>
parents:
25519
diff
changeset
|
45 | byte_stream_put32(&frame->data, 0x00000001); /* FLAP Version */ |
| 13593 | 46 | flap_connection_send(conn, frame); |
| 47 | } | |
| 48 | ||
| 49 | /** | |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
50 | * This sends a channel 1 FLAP containing the FLAP version and |
| 13593 | 51 | * the authentication cookie. This is sent when connecting to |
| 52 | * any FLAP server after the initial connection to the auth | |
| 53 | * server. It is always the very first packet sent by both the | |
| 54 | * server and the client after the SYN, SYN/ACK, ACK handshake. | |
| 55 | */ | |
| 56 | void | |
| 57 | flap_connection_send_version_with_cookie(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy) | |
| 58 | { | |
| 59 | FlapFrame *frame; | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
60 | GSList *tlvlist = NULL; |
| 13593 | 61 | |
| 62 | frame = flap_frame_new(od, 0x01, 4 + 2 + 2 + length); | |
|
27367
82426b0162d4
Make a function static and add two comments
Mark Doliner <markdoliner@pidgin.im>
parents:
25519
diff
changeset
|
63 | byte_stream_put32(&frame->data, 0x00000001); /* FLAP Version */ |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
64 | 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
|
65 | 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
|
66 | aim_tlvlist_free(tlvlist); |
| 13593 | 67 | |
| 68 | flap_connection_send(conn, frame); | |
| 69 | } | |
| 70 | ||
|
27385
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
71 | void |
|
28815
207193c7d909
oscar: Fix 'Allow multiple simultaenous logins' with clientLogin.
Paul Aurich <darkrain42@pidgin.im>
parents:
28804
diff
changeset
|
72 | flap_connection_send_version_with_cookie_and_clientinfo(OscarData *od, FlapConnection *conn, guint16 length, const guint8 *chipsahoy, ClientInfo *ci, gboolean allow_multiple_logins) |
|
27385
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
73 | { |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
74 | FlapFrame *frame; |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
75 | GSList *tlvlist = NULL; |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
76 | |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
77 | frame = flap_frame_new(od, 0x01, 1152 + length); |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
78 | |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
79 | byte_stream_put32(&frame->data, 0x00000001); /* FLAP Version */ |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
80 | aim_tlvlist_add_raw(&tlvlist, 0x0006, length, chipsahoy); |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
81 | |
|
27688
8c89470bfe9d
Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <markdoliner@pidgin.im>
parents:
27687
diff
changeset
|
82 | if (ci->clientstring != NULL) |
|
8c89470bfe9d
Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <markdoliner@pidgin.im>
parents:
27687
diff
changeset
|
83 | aim_tlvlist_add_str(&tlvlist, 0x0003, ci->clientstring); |
|
8c89470bfe9d
Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <markdoliner@pidgin.im>
parents:
27687
diff
changeset
|
84 | else { |
|
8c89470bfe9d
Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <markdoliner@pidgin.im>
parents:
27687
diff
changeset
|
85 | gchar *clientstring = oscar_get_clientstring(); |
|
27687
f46b6b5c25e1
Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <markdoliner@pidgin.im>
parents:
27635
diff
changeset
|
86 | aim_tlvlist_add_str(&tlvlist, 0x0003, clientstring); |
|
27688
8c89470bfe9d
Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <markdoliner@pidgin.im>
parents:
27687
diff
changeset
|
87 | g_free(clientstring); |
|
8c89470bfe9d
Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <markdoliner@pidgin.im>
parents:
27687
diff
changeset
|
88 | } |
|
27385
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
89 | aim_tlvlist_add_16(&tlvlist, 0x0017, (guint16)ci->major); |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
90 | aim_tlvlist_add_16(&tlvlist, 0x0018, (guint16)ci->minor); |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
91 | aim_tlvlist_add_16(&tlvlist, 0x0019, (guint16)ci->point); |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
92 | aim_tlvlist_add_16(&tlvlist, 0x001a, (guint16)ci->build); |
|
28815
207193c7d909
oscar: Fix 'Allow multiple simultaenous logins' with clientLogin.
Paul Aurich <darkrain42@pidgin.im>
parents:
28804
diff
changeset
|
93 | aim_tlvlist_add_8(&tlvlist, 0x004a, (allow_multiple_logins ? 0x01 : 0x03)); |
|
27385
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
94 | |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
95 | aim_tlvlist_write(&frame->data, &tlvlist); |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
96 | |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
97 | aim_tlvlist_free(tlvlist); |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
98 | |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
99 | flap_connection_send(conn, frame); |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
100 | } |
|
cd0d721fec8f
Check in code that connects to oscar using clientLogin. This is the
Mark Doliner <markdoliner@pidgin.im>
parents:
27382
diff
changeset
|
101 | |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
102 | static struct rateclass * |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
103 | flap_connection_get_rateclass(FlapConnection *conn, guint16 family, guint16 subtype) |
|
15152
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
104 | { |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
105 | gconstpointer key; |
|
29261
e39105368ed6
Put all our rateclass members in a single hash table instead of in one
Mark Doliner <markdoliner@pidgin.im>
parents:
29260
diff
changeset
|
106 | gpointer rateclass; |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
107 | |
|
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
108 | key = GUINT_TO_POINTER((family << 16) + subtype); |
|
29261
e39105368ed6
Put all our rateclass members in a single hash table instead of in one
Mark Doliner <markdoliner@pidgin.im>
parents:
29260
diff
changeset
|
109 | rateclass = g_hash_table_lookup(conn->rateclass_members, key); |
|
e39105368ed6
Put all our rateclass members in a single hash table instead of in one
Mark Doliner <markdoliner@pidgin.im>
parents:
29260
diff
changeset
|
110 | if (rateclass != NULL) |
|
e39105368ed6
Put all our rateclass members in a single hash table instead of in one
Mark Doliner <markdoliner@pidgin.im>
parents:
29260
diff
changeset
|
111 | return rateclass; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
112 | |
|
29259
87336a2f470d
optimization to the oscar prpl to use less memory, care of Shaun Lindsay
Mark Doliner <markdoliner@pidgin.im>
parents:
29258
diff
changeset
|
113 | return conn->default_rateclass; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
114 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
115 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
116 | /* |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
117 | * 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
|
118 | * 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
|
119 | */ |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
120 | static guint32 |
|
15172
8032180fbca3
[gaim-migrate @ 17896]
Mark Doliner <markdoliner@pidgin.im>
parents:
15169
diff
changeset
|
121 | 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
|
122 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
123 | unsigned long timediff; /* In milliseconds */ |
|
28804
24b032f5d478
oscar: Update the rate calculations based on OSCAR docs.
Aman Gupta <aman@tmm1.net>
parents:
27813
diff
changeset
|
124 | guint32 current; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
125 | |
|
29258
05ad83b03e68
We were using this formula from before the documentation was public, and
Mark Doliner <markdoliner@pidgin.im>
parents:
28815
diff
changeset
|
126 | /* This formula is documented at http://dev.aol.com/aim/oscar/#RATELIMIT */ |
|
15172
8032180fbca3
[gaim-migrate @ 17896]
Mark Doliner <markdoliner@pidgin.im>
parents:
15169
diff
changeset
|
127 | timediff = (now->tv_sec - rateclass->last.tv_sec) * 1000 + (now->tv_usec - rateclass->last.tv_usec) / 1000; |
|
28804
24b032f5d478
oscar: Update the rate calculations based on OSCAR docs.
Aman Gupta <aman@tmm1.net>
parents:
27813
diff
changeset
|
128 | current = ((rateclass->current * (rateclass->windowsize - 1)) + timediff) / rateclass->windowsize; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
129 | |
|
28804
24b032f5d478
oscar: Update the rate calculations based on OSCAR docs.
Aman Gupta <aman@tmm1.net>
parents:
27813
diff
changeset
|
130 | return MIN(current, rateclass->max); |
|
15152
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
131 | } |
|
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
132 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
133 | /* |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
134 | * 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
|
135 | * |
|
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
|
136 | * @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
|
137 | * 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
|
138 | * emptied. |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
139 | */ |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
140 | 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
|
141 | { |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
142 | while (!g_queue_is_empty(queue)) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
143 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
144 | QueuedSnac *queued_snac; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
145 | struct rateclass *rateclass; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
146 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
147 | queued_snac = g_queue_peek_head(queue); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
148 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
149 | 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
|
150 | if (rateclass != NULL) |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
151 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
152 | guint32 new_current; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
153 | |
|
15172
8032180fbca3
[gaim-migrate @ 17896]
Mark Doliner <markdoliner@pidgin.im>
parents:
15169
diff
changeset
|
154 | new_current = rateclass_get_new_current(conn, rateclass, &now); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
155 | |
|
28804
24b032f5d478
oscar: Update the rate calculations based on OSCAR docs.
Aman Gupta <aman@tmm1.net>
parents:
27813
diff
changeset
|
156 | if (rateclass->dropping_snacs || new_current <= rateclass->alert) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
157 | /* 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
|
158 | 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
|
159 | |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
160 | rateclass->current = new_current; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
161 | rateclass->last.tv_sec = now.tv_sec; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
162 | rateclass->last.tv_usec = now.tv_usec; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
163 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
164 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
165 | flap_connection_send(conn, queued_snac->frame); |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
166 | 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
|
167 | g_queue_pop_head(queue); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
168 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
169 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
170 | /* We emptied the queue */ |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
171 | return TRUE; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
172 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
173 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
174 | 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
|
175 | { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
176 | FlapConnection *conn; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
177 | struct timeval now; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
178 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
179 | conn = data; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
180 | gettimeofday(&now, NULL); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
181 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
182 | 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
|
183 | (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
|
184 | (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
|
185 | conn); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
186 | 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
|
187 | 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
|
188 | /* Both queues emptied. */ |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
189 | conn->queued_timeout = 0; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
190 | return FALSE; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
191 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
192 | } |
|
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
|
193 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
194 | /* 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
|
195 | return TRUE; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
196 | } |
|
15152
6eb1a86c7729
[gaim-migrate @ 17876]
Mark Doliner <markdoliner@pidgin.im>
parents:
15151
diff
changeset
|
197 | |
| 13593 | 198 | /** |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
199 | * 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
|
200 | * 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
|
201 | * sending this SNAC will induce rate limiting then we delay sending |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
202 | * 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
|
203 | * |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
204 | * @param data The optional bytestream that makes up the data portion |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
205 | * 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
|
206 | * @param high_priority If TRUE, the SNAC will be queued normally if |
|
31517
3e5023a642b4
Send keepalives for all types of network connections. Will hopefully
Mark Doliner <markdoliner@pidgin.im>
parents:
30885
diff
changeset
|
207 | * needed. If FALSE, it will be queued separately, to be sent |
|
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
|
208 | * only if all high priority SNACs have been sent. |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
209 | */ |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
210 | void |
|
30678
78aacd015725
Removed unused "flags" parameter.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
211 | flap_connection_send_snac_with_priority(OscarData *od, FlapConnection *conn, guint16 family, const guint16 subtype, aim_snacid_t snacid, ByteStream *data, gboolean high_priority) |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
212 | { |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
213 | FlapFrame *frame; |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
214 | guint32 length; |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
215 | gboolean enqueue = FALSE; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
216 | struct rateclass *rateclass; |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
217 | |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
218 | length = data != NULL ? data->offset : 0; |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
219 | |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
220 | frame = flap_frame_new(od, 0x02, 10 + length); |
|
30678
78aacd015725
Removed unused "flags" parameter.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
221 | aim_putsnac(&frame->data, family, subtype, snacid); |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
222 | |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
223 | if (length > 0) |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
224 | { |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
225 | byte_stream_rewind(data); |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
226 | byte_stream_putbs(&frame->data, data, length); |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
227 | } |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
228 | |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
229 | if (conn->queued_timeout != 0) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
230 | enqueue = TRUE; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
231 | else if ((rateclass = flap_connection_get_rateclass(conn, family, subtype)) != NULL) |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
232 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
233 | struct timeval now; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
234 | guint32 new_current; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
235 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
236 | gettimeofday(&now, NULL); |
|
15172
8032180fbca3
[gaim-migrate @ 17896]
Mark Doliner <markdoliner@pidgin.im>
parents:
15169
diff
changeset
|
237 | new_current = rateclass_get_new_current(conn, rateclass, &now); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
238 | |
|
28804
24b032f5d478
oscar: Update the rate calculations based on OSCAR docs.
Aman Gupta <aman@tmm1.net>
parents:
27813
diff
changeset
|
239 | if (rateclass->dropping_snacs || new_current <= rateclass->alert) |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
240 | { |
|
28804
24b032f5d478
oscar: Update the rate calculations based on OSCAR docs.
Aman Gupta <aman@tmm1.net>
parents:
27813
diff
changeset
|
241 | purple_debug_info("oscar", "Current rate for conn %p would be %u, but we alert at %u; enqueueing\n", conn, new_current, rateclass->alert); |
|
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
|
242 | |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
243 | enqueue = TRUE; |
|
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 | else |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
246 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
247 | rateclass->current = new_current; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
248 | rateclass->last.tv_sec = now.tv_sec; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
249 | rateclass->last.tv_usec = now.tv_usec; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
250 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
251 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
252 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
253 | if (enqueue) |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
254 | { |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
255 | /* We've been sending too fast, so delay this message */ |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
256 | QueuedSnac *queued_snac; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
257 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
258 | queued_snac = g_new(QueuedSnac, 1); |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
259 | queued_snac->family = family; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
260 | queued_snac->subtype = subtype; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
261 | 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
|
262 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
263 | if (high_priority) { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
264 | if (!conn->queued_snacs) |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
265 | 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
|
266 | 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
|
267 | } else { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
268 | 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
|
269 | 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
|
270 | 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
|
271 | } |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
272 | |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
273 | if (conn->queued_timeout == 0) |
| 15884 | 274 | 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
|
275 | |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
276 | return; |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
277 | } |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
278 | |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
279 | flap_connection_send(conn, frame); |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
280 | } |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
281 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
282 | void |
|
30678
78aacd015725
Removed unused "flags" parameter.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
283 | flap_connection_send_snac(OscarData *od, FlapConnection *conn, guint16 family, const guint16 subtype, aim_snacid_t snacid, ByteStream *data) |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
284 | { |
|
30678
78aacd015725
Removed unused "flags" parameter.
Ivan Komarov <ivan.komarov@pidgin.im>
parents:
30668
diff
changeset
|
285 | flap_connection_send_snac_with_priority(od, conn, family, subtype, snacid, data, TRUE); |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
286 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
287 | |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
288 | /** |
|
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
289 | * This sends an empty channel 4 FLAP. This is sent to signify |
| 13593 | 290 | * that we're logging off. This shouldn't really be necessary-- |
| 291 | * usually the AIM server will detect that the TCP connection has | |
| 292 | * been destroyed--but it's good practice. | |
| 293 | */ | |
| 294 | static void | |
| 295 | flap_connection_send_close(OscarData *od, FlapConnection *conn) | |
| 296 | { | |
| 297 | FlapFrame *frame; | |
| 298 | ||
| 299 | frame = flap_frame_new(od, 0x04, 0); | |
| 300 | flap_connection_send(conn, frame); | |
| 301 | } | |
| 302 | ||
| 303 | /** | |
|
15150
c218efb19164
[gaim-migrate @ 17874]
Mark Doliner <markdoliner@pidgin.im>
parents:
15148
diff
changeset
|
304 | * This sends an empty channel 5 FLAP. This is used as a keepalive |
| 13593 | 305 | * packet in FLAP connections. WinAIM 4.x and higher send these |
| 306 | * _every minute_ to keep the connection alive. | |
| 307 | */ | |
| 308 | void | |
| 309 | flap_connection_send_keepalive(OscarData *od, FlapConnection *conn) | |
| 310 | { | |
| 311 | FlapFrame *frame; | |
| 312 | ||
| 313 | frame = flap_frame_new(od, 0x05, 0); | |
| 314 | flap_connection_send(conn, frame); | |
| 315 | ||
| 316 | /* clean out SNACs over 60sec old */ | |
| 317 | aim_cleansnacs(od, 60); | |
| 318 | } | |
| 319 | ||
| 320 | /** | |
| 321 | * Allocate a new empty connection structure. | |
| 322 | * | |
| 323 | * @param od The oscar session associated with this connection. | |
| 324 | * @param type Type of connection to create | |
| 325 | * | |
| 326 | * @return Returns the new connection structure. | |
| 327 | */ | |
| 328 | FlapConnection * | |
| 329 | flap_connection_new(OscarData *od, int type) | |
| 330 | { | |
| 331 | FlapConnection *conn; | |
| 332 | ||
| 333 | conn = g_new0(FlapConnection, 1); | |
| 334 | conn->od = od; | |
|
34529
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
335 | conn->buffer_outgoing = purple_circular_buffer_new(0); |
| 13593 | 336 | conn->fd = -1; |
| 337 | conn->subtype = -1; | |
| 338 | conn->type = type; | |
|
29261
e39105368ed6
Put all our rateclass members in a single hash table instead of in one
Mark Doliner <markdoliner@pidgin.im>
parents:
29260
diff
changeset
|
339 | conn->rateclass_members = g_hash_table_new(g_direct_hash, g_direct_equal); |
| 13593 | 340 | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
341 | od->oscar_connections = g_slist_prepend(od->oscar_connections, conn); |
| 13593 | 342 | |
| 343 | return conn; | |
| 344 | } | |
| 345 | ||
| 346 | /** | |
| 347 | * Close (but not free) a connection. | |
| 348 | * | |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
349 | * This cancels any currently pending connection attempt, |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
350 | * closes any open fd and frees the auth cookie. |
| 13593 | 351 | * |
| 352 | * @param conn The connection to close. | |
| 353 | */ | |
| 354 | void | |
| 355 | flap_connection_close(OscarData *od, FlapConnection *conn) | |
| 356 | { | |
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
357 | if (conn->connect_data != NULL) |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
358 | { |
| 15884 | 359 | purple_proxy_connect_cancel(conn->connect_data); |
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
360 | conn->connect_data = NULL; |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
361 | } |
| 13593 | 362 | |
|
29754
f05a8c1637bf
oscar: Fix a race condition that leads to a crash.
Paul Aurich <darkrain42@pidgin.im>
parents:
29261
diff
changeset
|
363 | if (conn->gsc != NULL && conn->gsc->connect_data != NULL) |
|
f05a8c1637bf
oscar: Fix a race condition that leads to a crash.
Paul Aurich <darkrain42@pidgin.im>
parents:
29261
diff
changeset
|
364 | { |
|
f05a8c1637bf
oscar: Fix a race condition that leads to a crash.
Paul Aurich <darkrain42@pidgin.im>
parents:
29261
diff
changeset
|
365 | purple_ssl_close(conn->gsc); |
|
f05a8c1637bf
oscar: Fix a race condition that leads to a crash.
Paul Aurich <darkrain42@pidgin.im>
parents:
29261
diff
changeset
|
366 | conn->gsc = NULL; |
|
f05a8c1637bf
oscar: Fix a race condition that leads to a crash.
Paul Aurich <darkrain42@pidgin.im>
parents:
29261
diff
changeset
|
367 | } |
|
f05a8c1637bf
oscar: Fix a race condition that leads to a crash.
Paul Aurich <darkrain42@pidgin.im>
parents:
29261
diff
changeset
|
368 | |
|
23878
63d4f60097a4
Daniel Atallah pointed out that this was obviously wrong. So we would
Mark Doliner <markdoliner@pidgin.im>
parents:
23082
diff
changeset
|
369 | if (conn->new_conn_data != NULL) |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
370 | { |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
371 | if (conn->type == SNAC_FAMILY_CHAT) |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
372 | { |
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
373 | 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
|
374 | conn->new_conn_data = NULL; |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
375 | } |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
376 | } |
| 13593 | 377 | |
|
27382
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
378 | if ((conn->fd >= 0 || conn->gsc != NULL) |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
379 | && conn->type == SNAC_FAMILY_LOCATE) |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
380 | flap_connection_send_close(od, conn); |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
381 | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
382 | if (conn->watcher_incoming != 0) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
383 | { |
| 15884 | 384 | purple_input_remove(conn->watcher_incoming); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
385 | conn->watcher_incoming = 0; |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
386 | } |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
387 | |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
388 | if (conn->watcher_outgoing != 0) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
389 | { |
| 15884 | 390 | purple_input_remove(conn->watcher_outgoing); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
391 | conn->watcher_outgoing = 0; |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
392 | } |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
393 | |
|
27382
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
394 | if (conn->fd >= 0) |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
395 | { |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
396 | close(conn->fd); |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
397 | conn->fd = -1; |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
398 | } |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
399 | |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
400 | if (conn->gsc != NULL) |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
401 | { |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
402 | purple_ssl_close(conn->gsc); |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
403 | conn->gsc = NULL; |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
404 | } |
|
4a4dfc6ad0d6
Stop the watchers before closing the fds
Mark Doliner <markdoliner@pidgin.im>
parents:
27367
diff
changeset
|
405 | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
406 | g_free(conn->buffer_incoming.data.data); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
407 | conn->buffer_incoming.data.data = NULL; |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
408 | |
|
34529
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
409 | g_object_unref(G_OBJECT(conn->buffer_outgoing)); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
410 | conn->buffer_outgoing = NULL; |
| 13593 | 411 | } |
| 412 | ||
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
413 | /** |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
414 | * Free a FlapFrame |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
415 | * |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
416 | * @param frame The frame to free. |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
417 | */ |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
418 | static void |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
419 | flap_frame_destroy(FlapFrame *frame) |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
420 | { |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
421 | g_free(frame->data.data); |
|
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
422 | g_free(frame); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
423 | } |
|
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
424 | |
| 13593 | 425 | static gboolean |
| 426 | flap_connection_destroy_cb(gpointer data) | |
| 427 | { | |
| 428 | FlapConnection *conn; | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
429 | OscarData *od; |
| 15884 | 430 | PurpleAccount *account; |
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
431 | aim_rxcallback_t userfunc; |
| 13593 | 432 | |
| 433 | conn = data; | |
|
30885
aea5b6af4258
oscar: Add useful object debugging for #5927.
Paul Aurich <darkrain42@pidgin.im>
parents:
30678
diff
changeset
|
434 | /* Explicitly added for debugging #5927. Don't re-order this, only |
|
aea5b6af4258
oscar: Add useful object debugging for #5927.
Paul Aurich <darkrain42@pidgin.im>
parents:
30678
diff
changeset
|
435 | * consider removing it. |
|
aea5b6af4258
oscar: Add useful object debugging for #5927.
Paul Aurich <darkrain42@pidgin.im>
parents:
30678
diff
changeset
|
436 | */ |
|
aea5b6af4258
oscar: Add useful object debugging for #5927.
Paul Aurich <darkrain42@pidgin.im>
parents:
30678
diff
changeset
|
437 | purple_debug_info("oscar", "Destroying FLAP connection %p\n", conn); |
|
aea5b6af4258
oscar: Add useful object debugging for #5927.
Paul Aurich <darkrain42@pidgin.im>
parents:
30678
diff
changeset
|
438 | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
439 | od = conn->od; |
|
22296
120207b25525
Undo revision c10f76ea0a1d80d4b5e7c2807c239a9bbb59bc1e. This should
Mark Doliner <markdoliner@pidgin.im>
parents:
22295
diff
changeset
|
440 | account = purple_connection_get_account(od->gc); |
| 13593 | 441 | |
|
30885
aea5b6af4258
oscar: Add useful object debugging for #5927.
Paul Aurich <darkrain42@pidgin.im>
parents:
30678
diff
changeset
|
442 | purple_debug_info("oscar", "Destroying oscar connection (%p) of " |
|
aea5b6af4258
oscar: Add useful object debugging for #5927.
Paul Aurich <darkrain42@pidgin.im>
parents:
30678
diff
changeset
|
443 | "type 0x%04hx. Disconnect reason is %d\n", conn, |
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
444 | conn->type, conn->disconnect_reason); |
| 13593 | 445 | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
446 | od->oscar_connections = g_slist_remove(od->oscar_connections, conn); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
447 | |
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
448 | 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
|
449 | 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
|
450 | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
451 | /* |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
452 | * 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
|
453 | * we should try to request one instead of disconnecting. |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
454 | */ |
|
32722
50ed95d90d55
Add purple_account_is_disconnecting() accessor function.
Andrew Victor <andrew.victor@mxit.com>
parents:
32679
diff
changeset
|
455 | if (!purple_account_is_disconnecting(account) && ((od->oscar_connections == NULL) |
|
22296
120207b25525
Undo revision c10f76ea0a1d80d4b5e7c2807c239a9bbb59bc1e. This should
Mark Doliner <markdoliner@pidgin.im>
parents:
22295
diff
changeset
|
456 | || (!flap_connection_getbytype(od, SNAC_FAMILY_LOCATE)))) |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
457 | { |
| 15884 | 458 | /* No more FLAP connections! Sign off this PurpleConnection! */ |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
459 | gchar *tmp; |
| 21279 | 460 | PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; |
|
20452
a9fc6198b5c6
Add disconnection reasons to oscar.
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
461 | |
|
18875
c9c59be46538
Move a call to purple_connection_error() from oscar.c to
Mark Doliner <markdoliner@pidgin.im>
parents:
18874
diff
changeset
|
462 | if (conn->disconnect_code == 0x0001) { |
| 21279 | 463 | reason = PURPLE_CONNECTION_ERROR_NAME_IN_USE; |
|
27628
26ab0a63a199
Remove trailing periods from short disconnection error messags and remove
Mark Doliner <markdoliner@pidgin.im>
parents:
27385
diff
changeset
|
464 | 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
|
465 | if (!purple_account_get_remember_password(account)) |
|
34029
059c1270db1f
Remove the silly destroy argument from purple_account_set_password and
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
34028
diff
changeset
|
466 | purple_account_set_password(account, NULL, NULL, NULL); |
|
18875
c9c59be46538
Move a call to purple_connection_error() from oscar.c to
Mark Doliner <markdoliner@pidgin.im>
parents:
18874
diff
changeset
|
467 | } else if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED) |
|
27628
26ab0a63a199
Remove trailing periods from short disconnection error messags and remove
Mark Doliner <markdoliner@pidgin.im>
parents:
27385
diff
changeset
|
468 | tmp = g_strdup(_("Server closed the connection")); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
469 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION) |
|
27628
26ab0a63a199
Remove trailing periods from short disconnection error messags and remove
Mark Doliner <markdoliner@pidgin.im>
parents:
27385
diff
changeset
|
470 | tmp = g_strdup_printf(_("Lost connection with server: %s"), |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
471 | conn->error_message); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
472 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA) |
|
27628
26ab0a63a199
Remove trailing periods from short disconnection error messags and remove
Mark Doliner <markdoliner@pidgin.im>
parents:
27385
diff
changeset
|
473 | tmp = g_strdup(_("Received invalid data on connection with server")); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
474 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT) |
|
27635
0cd19038c417
More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents:
27628
diff
changeset
|
475 | tmp = g_strdup_printf(_("Unable to connect: %s"), |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
476 | conn->error_message); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
477 | else |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
478 | /* |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
479 | * We shouldn't print a message for some disconnect_reasons. |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
480 | * Like OSCAR_DISCONNECT_LOCAL_CLOSED. |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
481 | */ |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
482 | tmp = NULL; |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
483 | |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
484 | if (tmp != NULL) |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
485 | { |
|
32157
39ba2e2492ee
Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents:
31517
diff
changeset
|
486 | purple_connection_error(od->gc, reason, tmp); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
487 | g_free(tmp); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
488 | } |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
489 | } |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
490 | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
491 | flap_connection_close(od, conn); |
| 13593 | 492 | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
493 | g_free(conn->error_message); |
|
14171
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
494 | g_free(conn->cookie); |
|
351b731b9553
[gaim-migrate @ 16743]
Mark Doliner <markdoliner@pidgin.im>
parents:
14048
diff
changeset
|
495 | |
| 13593 | 496 | /* |
| 497 | * Free conn->internal, if necessary | |
| 498 | */ | |
| 499 | if (conn->type == SNAC_FAMILY_CHAT) | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
500 | flap_connection_destroy_chat(od, conn); |
| 13593 | 501 | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
502 | g_slist_free(conn->groups); |
|
15148
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
503 | while (conn->rateclasses != NULL) |
|
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
504 | { |
|
29261
e39105368ed6
Put all our rateclass members in a single hash table instead of in one
Mark Doliner <markdoliner@pidgin.im>
parents:
29260
diff
changeset
|
505 | g_free(conn->rateclasses->data); |
|
15148
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
506 | conn->rateclasses = g_slist_delete_link(conn->rateclasses, conn->rateclasses); |
|
48ce0abb422a
[gaim-migrate @ 17872]
Mark Doliner <markdoliner@pidgin.im>
parents:
15147
diff
changeset
|
507 | } |
| 13593 | 508 | |
|
29261
e39105368ed6
Put all our rateclass members in a single hash table instead of in one
Mark Doliner <markdoliner@pidgin.im>
parents:
29260
diff
changeset
|
509 | g_hash_table_destroy(conn->rateclass_members); |
|
e39105368ed6
Put all our rateclass members in a single hash table instead of in one
Mark Doliner <markdoliner@pidgin.im>
parents:
29260
diff
changeset
|
510 | |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
511 | if (conn->queued_snacs) { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
512 | 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
|
513 | { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
514 | QueuedSnac *queued_snac; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
515 | 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
|
516 | 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
|
517 | g_free(queued_snac); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
518 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
519 | g_queue_free(conn->queued_snacs); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
520 | } |
|
23886
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
521 | |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
522 | 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
|
523 | 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
|
524 | { |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
525 | QueuedSnac *queued_snac; |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
526 | 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
|
527 | 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
|
528 | g_free(queued_snac); |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
529 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
530 | 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
|
531 | } |
|
416eb5818cee
Added `flap_connection_send_snac_with_priority()`, which allows specifying
Evan Schoenberg <evands@pidgin.im>
parents:
23879
diff
changeset
|
532 | |
|
15168
4e604d302448
[gaim-migrate @ 17892]
Mark Doliner <markdoliner@pidgin.im>
parents:
15167
diff
changeset
|
533 | if (conn->queued_timeout > 0) |
| 15884 | 534 | purple_timeout_remove(conn->queued_timeout); |
|
15167
7114af0af12f
[gaim-migrate @ 17891]
Mark Doliner <markdoliner@pidgin.im>
parents:
15153
diff
changeset
|
535 | |
|
14048
b577c53406c0
[gaim-migrate @ 16556]
Mark Doliner <markdoliner@pidgin.im>
parents:
13726
diff
changeset
|
536 | g_free(conn); |
|
b577c53406c0
[gaim-migrate @ 16556]
Mark Doliner <markdoliner@pidgin.im>
parents:
13726
diff
changeset
|
537 | |
| 13593 | 538 | return FALSE; |
| 539 | } | |
| 540 | ||
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
541 | /** |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
542 | * See the comments for the parameters of |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
543 | * flap_connection_schedule_destroy(). |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
544 | */ |
| 13593 | 545 | void |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
546 | flap_connection_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
| 13593 | 547 | { |
| 548 | if (conn->destroy_timeout != 0) | |
| 15884 | 549 | purple_timeout_remove(conn->destroy_timeout); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
550 | conn->disconnect_reason = reason; |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
551 | g_free(conn->error_message); |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
552 | conn->error_message = g_strdup(error_message); |
| 13593 | 553 | flap_connection_destroy_cb(conn); |
| 554 | } | |
| 555 | ||
| 556 | /** | |
| 15884 | 557 | * Schedule Purple to destroy the given FlapConnection as soon as we |
| 13593 | 558 | * return control back to the program's main loop. We must do this |
| 559 | * if we want to destroy the connection but we are still using it | |
| 560 | * for some reason. | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
561 | * |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
562 | * @param reason The reason for the disconnection. |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
563 | * @param error_message A brief error message that gives more detail |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
564 | * regarding the reason for the disconnecting. This should |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
565 | * 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
|
566 | * 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
|
567 | * and OSCAR_DISCONNECT_COULD_NOT_CONNECT, in which case it |
|
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
568 | * should contain the error_message passed back from the call |
| 15884 | 569 | * to purple_proxy_connect(). |
| 13593 | 570 | */ |
| 571 | void | |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
572 | flap_connection_schedule_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
| 13593 | 573 | { |
| 574 | if (conn->destroy_timeout != 0) | |
| 575 | /* Already taken care of */ | |
| 576 | return; | |
| 577 | ||
| 15884 | 578 | purple_debug_info("oscar", "Scheduling destruction of FLAP " |
|
30885
aea5b6af4258
oscar: Add useful object debugging for #5927.
Paul Aurich <darkrain42@pidgin.im>
parents:
30678
diff
changeset
|
579 | "connection %p of type 0x%04hx\n", conn, conn->type); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
580 | conn->disconnect_reason = reason; |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14454
diff
changeset
|
581 | g_free(conn->error_message); |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
582 | conn->error_message = g_strdup(error_message); |
| 15884 | 583 | conn->destroy_timeout = purple_timeout_add(0, flap_connection_destroy_cb, conn); |
| 13593 | 584 | } |
| 585 | ||
| 586 | /** | |
| 587 | * In OSCAR, every connection has a set of SNAC groups associated | |
| 588 | * with it. These are the groups that you can send over this connection | |
| 589 | * without being guaranteed a "Not supported" SNAC error. | |
| 590 | * | |
| 591 | * The grand theory of things says that these associations transcend | |
| 592 | * what libfaim calls "connection types" (conn->type). You can probably | |
| 593 | * see the elegance here, but since I want to revel in it for a bit, you | |
| 594 | * get to hear it all spelled out. | |
| 595 | * | |
| 596 | * So let us say that you have your core BOS connection running. One | |
| 597 | * of your modules has just given you a SNAC of the group 0x0004 to send | |
| 598 | * you. Maybe an IM destined for some twit in Greenland. So you start | |
| 599 | * at the top of your connection list, looking for a connection that | |
| 600 | * claims to support group 0x0004. You find one. Why, that neat BOS | |
| 601 | * connection of yours can do that. So you send it on its way. | |
| 602 | * | |
| 603 | * Now, say, that fellow from Greenland has friends and they all want to | |
| 604 | * meet up with you in a lame chat room. This has landed you a SNAC | |
| 605 | * in the family 0x000e and you have to admit you're a bit lost. You've | |
| 606 | * searched your connection list for someone who wants to make your life | |
| 607 | * easy and deliver this SNAC for you, but there isn't one there. | |
| 608 | * | |
| 609 | * Here comes the good bit. Without even letting anyone know, particularly | |
| 610 | * the module that decided to send this SNAC, and definitely not that twit | |
| 611 | * in Greenland, you send out a service request. In this request, you have | |
| 612 | * marked the need for a connection supporting group 0x000e. A few seconds | |
| 613 | * later, you receive a service redirect with an IP address and a cookie in | |
| 614 | * it. Great, you say. Now I have something to do. Off you go, making | |
| 615 | * that connection. One of the first things you get from this new server | |
| 616 | * is a message saying that indeed it does support the group you were looking | |
| 617 | * for. So you continue and send rate confirmation and all that. | |
| 618 | * | |
| 619 | * Then you remember you had that SNAC to send, and now you have a means to | |
| 620 | * do it, and you do, and everyone is happy. Except the Greenlander, who is | |
| 621 | * still stuck in the bitter cold. | |
| 622 | * | |
| 623 | * Oh, and this is useful for building the Migration SNACs, too. In the | |
| 624 | * future, this may help convince me to implement rate limit mitigation | |
| 625 | * for real. We'll see. | |
| 626 | * | |
| 627 | * Just to make me look better, I'll say that I've known about this great | |
| 628 | * scheme for quite some time now. But I still haven't convinced myself | |
| 629 | * to make libfaim work that way. It would take a fair amount of effort, | |
| 630 | * and probably some client API changes as well. (Whenever I don't want | |
| 631 | * to do something, I just say it would change the client API. Then I | |
| 632 | * instantly have a couple of supporters of not doing it.) | |
| 633 | * | |
| 634 | * Generally, addgroup is only called by the internal handling of the | |
| 635 | * server ready SNAC. So if you want to do something before that, you'll | |
| 636 | * have to be more creative. That is done rather early, though, so I don't | |
| 637 | * think you have to worry about it. Unless you're me. I care deeply | |
| 638 | * about such inane things. | |
| 639 | * | |
| 640 | */ | |
| 641 | ||
| 642 | /** | |
| 643 | * Find a FlapConnection that supports the given oscar | |
| 644 | * family. | |
| 645 | */ | |
| 646 | FlapConnection * | |
| 647 | flap_connection_findbygroup(OscarData *od, guint16 group) | |
| 648 | { | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
649 | GSList *cur; |
| 13593 | 650 | |
| 651 | for (cur = od->oscar_connections; cur != NULL; cur = cur->next) | |
| 652 | { | |
| 653 | FlapConnection *conn; | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
654 | GSList *l; |
| 13593 | 655 | |
| 656 | conn = cur->data; | |
| 657 | ||
|
13612
c51da9e6fec1
[gaim-migrate @ 15997]
Mark Doliner <markdoliner@pidgin.im>
parents:
13611
diff
changeset
|
658 | for (l = conn->groups; l != NULL; l = l->next) |
| 13593 | 659 | { |
|
13612
c51da9e6fec1
[gaim-migrate @ 15997]
Mark Doliner <markdoliner@pidgin.im>
parents:
13611
diff
changeset
|
660 | if (GPOINTER_TO_UINT(l->data) == group) |
| 13593 | 661 | return conn; |
| 662 | } | |
| 663 | } | |
| 664 | ||
| 665 | return NULL; | |
| 666 | } | |
| 667 | ||
| 668 | /** | |
| 669 | * Locates a connection of the specified type in the | |
| 670 | * specified session. | |
| 671 | * | |
| 672 | * TODO: Use flap_connection_findbygroup everywhere and get rid of this. | |
| 673 | * | |
| 674 | * @param od The session to search. | |
| 675 | * @param type The type of connection to look for. | |
| 676 | * | |
| 677 | * @return Returns the first connection found of the given target type, | |
| 678 | * or NULL if none could be found. | |
| 679 | */ | |
| 680 | FlapConnection * | |
| 681 | flap_connection_getbytype(OscarData *od, int type) | |
| 682 | { | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
683 | GSList *cur; |
| 13593 | 684 | |
| 685 | for (cur = od->oscar_connections; cur != NULL; cur = cur->next) | |
| 686 | { | |
| 687 | FlapConnection *conn; | |
| 688 | conn = cur->data; | |
| 689 | if ((conn->type == type) && (conn->connected)) | |
| 690 | return conn; | |
| 691 | } | |
| 692 | ||
| 693 | return NULL; | |
| 694 | } | |
| 695 | ||
| 696 | FlapConnection * | |
| 697 | flap_connection_getbytype_all(OscarData *od, int type) | |
| 698 | { | |
|
14410
a5ae93474db6
[gaim-migrate @ 17050]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
699 | GSList *cur; |
| 13593 | 700 | |
| 701 | for (cur = od->oscar_connections; cur; cur = cur->next) | |
| 702 | { | |
| 703 | FlapConnection *conn; | |
| 704 | conn = cur->data; | |
| 705 | if (conn->type == type) | |
| 706 | return conn; | |
| 707 | } | |
| 708 | ||
| 709 | return NULL; | |
| 710 | } | |
| 711 | ||
| 712 | /** | |
| 713 | * Allocate a new FLAP frame. | |
| 714 | * | |
| 715 | * @param channel The FLAP channel. This is almost always 2. | |
| 716 | */ | |
| 717 | FlapFrame * | |
| 718 | flap_frame_new(OscarData *od, guint16 channel, int datalen) | |
| 719 | { | |
| 720 | FlapFrame *frame; | |
| 721 | ||
| 722 | frame = g_new0(FlapFrame, 1); | |
| 723 | frame->channel = channel; | |
| 724 | ||
| 725 | if (datalen > 0) | |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
15150
diff
changeset
|
726 | byte_stream_new(&frame->data, datalen); |
| 13593 | 727 | |
| 728 | return frame; | |
| 729 | } | |
| 730 | ||
| 731 | static void | |
| 732 | parse_snac(OscarData *od, FlapConnection *conn, FlapFrame *frame) | |
| 733 | { | |
| 734 | aim_module_t *cur; | |
| 735 | aim_modsnac_t snac; | |
| 736 | ||
| 30668 | 737 | if (byte_stream_bytes_left(&frame->data) < 10) |
| 13593 | 738 | return; |
| 739 | ||
| 740 | snac.family = byte_stream_get16(&frame->data); | |
| 741 | snac.subtype = byte_stream_get16(&frame->data); | |
| 742 | snac.flags = byte_stream_get16(&frame->data); | |
| 743 | snac.id = byte_stream_get32(&frame->data); | |
| 744 | ||
| 745 | /* SNAC flags are apparently uniform across all SNACs, so we handle them here */ | |
| 746 | if (snac.flags & 0x0001) { | |
| 747 | /* | |
| 748 | * This means the SNAC will be followed by another SNAC with | |
| 749 | * related information. We don't need to do anything about | |
| 750 | * this here. | |
| 751 | */ | |
| 752 | } | |
| 753 | if (snac.flags & 0x8000) { | |
| 754 | /* | |
| 755 | * This packet contains the version of the family that this SNAC is | |
| 756 | * in. You get this when your SSI module is version 2 or higher. | |
| 757 | * For now we have no need for this, but you could always save | |
| 758 | * it as a part of aim_modnsac_t, or something. The format is... | |
| 759 | * 2 byte length of total mini-header (which is 6 bytes), then TLV | |
| 760 | * of type 0x0001, length 0x0002, value is the 2 byte version | |
| 761 | * number | |
| 762 | */ | |
| 763 | byte_stream_advance(&frame->data, byte_stream_get16(&frame->data)); | |
| 764 | } | |
| 765 | ||
| 766 | for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) { | |
| 767 | ||
| 768 | if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) && | |
| 769 | (cur->family != snac.family)) | |
| 770 | continue; | |
| 771 | ||
| 772 | if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data)) | |
| 773 | return; | |
| 774 | } | |
| 775 | } | |
| 776 | ||
| 777 | static void | |
| 778 | parse_fakesnac(OscarData *od, FlapConnection *conn, FlapFrame *frame, guint16 family, guint16 subtype) | |
| 779 | { | |
| 780 | aim_module_t *cur; | |
| 781 | aim_modsnac_t snac; | |
| 782 | ||
| 783 | snac.family = family; | |
| 784 | snac.subtype = subtype; | |
| 785 | snac.flags = snac.id = 0; | |
| 786 | ||
| 787 | for (cur = (aim_module_t *)od->modlistv; cur; cur = cur->next) { | |
| 788 | ||
| 789 | if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) && | |
| 790 | (cur->family != snac.family)) | |
| 791 | continue; | |
| 792 | ||
| 793 | if (cur->snachandler(od, conn, cur, frame, &snac, &frame->data)) | |
| 794 | return; | |
| 795 | } | |
| 796 | } | |
| 797 | ||
| 798 | static void | |
| 799 | parse_flap_ch4(OscarData *od, FlapConnection *conn, FlapFrame *frame) | |
| 800 | { | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
801 | GSList *tlvlist; |
| 13593 | 802 | char *msg = NULL; |
| 803 | ||
| 30668 | 804 | if (byte_stream_bytes_left(&frame->data) == 0) { |
| 13593 | 805 | /* XXX should do something with this */ |
| 806 | return; | |
| 807 | } | |
| 808 | ||
|
13603
12489c04a4ea
[gaim-migrate @ 15988]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
809 | /* An ICQ account is logging in */ |
| 13593 | 810 | if (conn->type == SNAC_FAMILY_AUTH) |
| 811 | { | |
| 812 | parse_fakesnac(od, conn, frame, 0x0017, 0x0003); | |
| 813 | return; | |
| 814 | } | |
| 815 | ||
| 816 | tlvlist = aim_tlvlist_read(&frame->data); | |
| 817 | ||
| 818 | 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
|
819 | conn->disconnect_code = aim_tlv_get16(tlvlist, 0x0009, 1); |
| 13593 | 820 | |
| 821 | if (aim_tlv_gettlv(tlvlist, 0x000b, 1)) | |
| 822 | msg = aim_tlv_getstr(tlvlist, 0x000b, 1); | |
| 823 | ||
|
18874
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
824 | /* |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
825 | * 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
|
826 | * close the physical TCP connection |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
827 | */ |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
828 | flap_connection_schedule_destroy(conn, |
|
556ca90e3b0d
Call the AIM_CB_SPECIAL_CONNERR callback from
Mark Doliner <markdoliner@pidgin.im>
parents:
17573
diff
changeset
|
829 | OSCAR_DISCONNECT_REMOTE_CLOSED, msg); |
| 13593 | 830 | |
|
17443
bae8548d98b3
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
Mark Doliner <markdoliner@pidgin.im>
parents:
17280
diff
changeset
|
831 | aim_tlvlist_free(tlvlist); |
| 13593 | 832 | |
|
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
|
833 | g_free(msg); |
| 13593 | 834 | } |
| 835 | ||
| 836 | /** | |
| 837 | * Takes a new incoming FLAP frame and sends it to the appropriate | |
| 838 | * handler function to be parsed. | |
| 839 | */ | |
| 840 | static void | |
| 841 | parse_flap(OscarData *od, FlapConnection *conn, FlapFrame *frame) | |
| 842 | { | |
| 843 | if (frame->channel == 0x01) { | |
| 844 | guint32 flap_version = byte_stream_get32(&frame->data); | |
| 845 | if (flap_version != 0x00000001) | |
| 846 | { | |
| 847 | /* Error! */ | |
| 15884 | 848 | 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
|
849 | "0x00000001 but received FLAP version %08x. Closing connection.\n", |
| 13593 | 850 | flap_version); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
851 | flap_connection_schedule_destroy(conn, |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
852 | OSCAR_DISCONNECT_INVALID_DATA, NULL); |
| 13593 | 853 | } |
| 854 | else | |
| 855 | conn->connected = TRUE; | |
| 856 | ||
| 857 | } else if (frame->channel == 0x02) { | |
| 858 | parse_snac(od, conn, frame); | |
| 859 | ||
| 860 | } else if (frame->channel == 0x04) { | |
| 861 | parse_flap_ch4(od, conn, frame); | |
| 862 | ||
| 863 | } else if (frame->channel == 0x05) { | |
| 864 | /* TODO: Reset our keepalive watchdog? */ | |
| 865 | ||
| 866 | } | |
| 867 | } | |
| 868 | ||
| 869 | /** | |
| 870 | * Read in all available data on the socket for a given connection. | |
| 871 | * All complete FLAPs handled immedate after they're received. | |
| 872 | * Incomplete FLAP data is stored locally and appended to the next | |
| 873 | * time this callback is triggered. | |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
874 | * |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
875 | * This is called by flap_connection_recv_cb and |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
876 | * flap_connection_recv_cb_ssl for unencrypted/encrypted connections. |
| 13593 | 877 | */ |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
878 | static void |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
879 | flap_connection_recv(FlapConnection *conn) |
| 13593 | 880 | { |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
881 | gpointer buf; |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
882 | gsize buflen; |
|
23079
b887906eed60
More s/ssize_t/gssize/
Daniel Atallah <datallah@pidgin.im>
parents:
23004
diff
changeset
|
883 | gssize read; |
| 13593 | 884 | |
| 885 | /* Read data until we run out of data and break out of the loop */ | |
| 886 | while (TRUE) | |
| 887 | { | |
| 888 | /* Start reading a new FLAP */ | |
| 889 | if (conn->buffer_incoming.data.data == NULL) | |
| 890 | { | |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
891 | buf = conn->header + conn->header_received; |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
892 | buflen = 6 - conn->header_received; |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
893 | |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
894 | /* Read the first 6 bytes (the FLAP header) */ |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
895 | if (conn->gsc) |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
896 | read = purple_ssl_read(conn->gsc, buf, buflen); |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
897 | else |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
898 | read = recv(conn->fd, buf, buflen, 0); |
| 13593 | 899 | |
| 900 | /* Check if the FLAP server closed the connection */ | |
| 901 | if (read == 0) | |
| 902 | { | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
903 | flap_connection_schedule_destroy(conn, |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
904 | OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
| 13593 | 905 | break; |
| 906 | } | |
| 907 | ||
| 908 | /* 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
|
909 | if (read < 0) |
| 13593 | 910 | { |
| 911 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | |
| 912 | /* No worries */ | |
| 913 | break; | |
| 914 | ||
| 915 | /* Error! */ | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
916 | 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
|
917 | OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); |
| 13593 | 918 | break; |
| 919 | } | |
|
32679
fd936a0b84f7
Add a purple_connection_update_last_received() function to update the
Andrew Victor <andrew.victor@mxit.com>
parents:
32157
diff
changeset
|
920 | purple_connection_update_last_received(conn->od->gc); |
| 13593 | 921 | |
| 922 | /* 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
|
923 | conn->header_received += read; |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
924 | if (conn->header_received < 6) |
| 13593 | 925 | break; |
| 926 | ||
| 927 | /* All FLAP frames must start with the byte 0x2a */ | |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
928 | if (aimutil_get8(&conn->header[0]) != 0x2a) |
| 13593 | 929 | { |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
930 | flap_connection_schedule_destroy(conn, |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
931 | OSCAR_DISCONNECT_INVALID_DATA, NULL); |
| 13593 | 932 | break; |
| 933 | } | |
| 934 | ||
| 935 | /* Initialize a new temporary FlapFrame for incoming data */ | |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
936 | conn->buffer_incoming.channel = aimutil_get8(&conn->header[1]); |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
937 | conn->buffer_incoming.seqnum = aimutil_get16(&conn->header[2]); |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
938 | conn->buffer_incoming.data.len = aimutil_get16(&conn->header[4]); |
| 13593 | 939 | conn->buffer_incoming.data.data = g_new(guint8, conn->buffer_incoming.data.len); |
| 940 | conn->buffer_incoming.data.offset = 0; | |
| 941 | } | |
| 942 | ||
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
943 | buflen = conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset; |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
944 | if (buflen) |
| 13593 | 945 | { |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
946 | buf = &conn->buffer_incoming.data.data[conn->buffer_incoming.data.offset]; |
| 13593 | 947 | /* Read data into the temporary FlapFrame until it is complete */ |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
948 | if (conn->gsc) |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
949 | read = purple_ssl_read(conn->gsc, buf, buflen); |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
950 | else |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
951 | read = recv(conn->fd, buf, buflen, 0); |
| 13593 | 952 | |
| 953 | /* Check if the FLAP server closed the connection */ | |
| 954 | if (read == 0) | |
| 955 | { | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
956 | flap_connection_schedule_destroy(conn, |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
957 | OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
| 13593 | 958 | break; |
| 959 | } | |
| 960 | ||
|
17539
0fd875385856
Only check for EAGAIN if send returns -1, not when it returns 0
Mark Doliner <markdoliner@pidgin.im>
parents:
17443
diff
changeset
|
961 | if (read < 0) |
| 13593 | 962 | { |
| 963 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | |
| 964 | /* No worries */ | |
| 965 | break; | |
| 966 | ||
| 967 | /* Error! */ | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13603
diff
changeset
|
968 | 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
|
969 | OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); |
| 13593 | 970 | break; |
| 971 | } | |
| 972 | ||
| 973 | conn->buffer_incoming.data.offset += read; | |
| 974 | if (conn->buffer_incoming.data.offset < conn->buffer_incoming.data.len) | |
| 975 | /* Waiting for more data to arrive */ | |
| 976 | break; | |
| 977 | } | |
| 978 | ||
| 979 | /* We have a complete FLAP! Handle it and continue reading */ | |
| 980 | byte_stream_rewind(&conn->buffer_incoming.data); | |
| 981 | parse_flap(conn->od, conn, &conn->buffer_incoming); | |
| 982 | conn->lastactivity = time(NULL); | |
| 983 | ||
| 984 | g_free(conn->buffer_incoming.data.data); | |
| 985 | conn->buffer_incoming.data.data = NULL; | |
|
15256
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
986 | |
|
c57887cd5d08
[gaim-migrate @ 17983]
Mark Doliner <markdoliner@pidgin.im>
parents:
15191
diff
changeset
|
987 | conn->header_received = 0; |
| 13593 | 988 | } |
| 989 | } | |
| 990 | ||
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
991 | void |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
992 | flap_connection_recv_cb(gpointer data, gint source, PurpleInputCondition cond) |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
993 | { |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
994 | FlapConnection *conn = data; |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
995 | |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
996 | flap_connection_recv(conn); |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
997 | } |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
998 | |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
999 | void |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1000 | flap_connection_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, PurpleInputCondition cond) |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1001 | { |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1002 | FlapConnection *conn = data; |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1003 | |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1004 | flap_connection_recv(conn); |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1005 | } |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1006 | |
|
25519
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1007 | /** |
|
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1008 | * @param source When this function is called as a callback source is |
|
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1009 | * set to the fd that triggered the callback. But this function |
|
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1010 | * is also called directly from flap_connection_send_byte_stream(), |
|
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1011 | * in which case source will be -1. So don't use source--use |
|
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1012 | * conn->gsc or conn->fd instead. |
|
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1013 | */ |
| 13593 | 1014 | static void |
| 15884 | 1015 | send_cb(gpointer data, gint source, PurpleInputCondition cond) |
| 13593 | 1016 | { |
| 1017 | FlapConnection *conn; | |
| 1018 | int writelen, ret; | |
|
34529
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
1019 | const gchar *output = NULL; |
| 13593 | 1020 | |
| 1021 | conn = data; | |
|
34529
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
1022 | writelen = purple_circular_buffer_get_max_read(conn->buffer_outgoing); |
|
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
1023 | output = purple_circular_buffer_get_output(conn->buffer_outgoing); |
| 13593 | 1024 | |
| 1025 | if (writelen == 0) | |
| 1026 | { | |
| 15884 | 1027 | purple_input_remove(conn->watcher_outgoing); |
| 13593 | 1028 | conn->watcher_outgoing = 0; |
| 1029 | return; | |
| 1030 | } | |
| 1031 | ||
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1032 | if (conn->gsc) |
|
34529
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
1033 | ret = purple_ssl_write(conn->gsc, output, writelen); |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1034 | else |
|
34529
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
1035 | ret = send(conn->fd, output, writelen, 0); |
| 13593 | 1036 | if (ret <= 0) |
| 1037 | { | |
|
27628
26ab0a63a199
Remove trailing periods from short disconnection error messags and remove
Mark Doliner <markdoliner@pidgin.im>
parents:
27385
diff
changeset
|
1038 | if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) |
| 13593 | 1039 | /* No worries */ |
| 1040 | return; | |
| 1041 | ||
| 1042 | /* Error! */ | |
| 15884 | 1043 | purple_input_remove(conn->watcher_outgoing); |
|
15191
d52a86abd255
[gaim-migrate @ 17915]
Mark Doliner <markdoliner@pidgin.im>
parents:
15172
diff
changeset
|
1044 | conn->watcher_outgoing = 0; |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1045 | if (conn->gsc) { |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1046 | purple_ssl_close(conn->gsc); |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1047 | conn->gsc = NULL; |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1048 | } else { |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1049 | close(conn->fd); |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1050 | conn->fd = -1; |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1051 | } |
|
14454
df290cda81a3
[gaim-migrate @ 17099]
Mark Doliner <markdoliner@pidgin.im>
parents:
14410
diff
changeset
|
1052 | 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
|
1053 | OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); |
| 13593 | 1054 | return; |
| 1055 | } | |
| 1056 | ||
|
34529
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
1057 | purple_circular_buffer_mark_read(conn->buffer_outgoing, ret); |
| 13593 | 1058 | } |
| 1059 | ||
| 1060 | static void | |
| 1061 | flap_connection_send_byte_stream(ByteStream *bs, FlapConnection *conn, size_t count) | |
| 1062 | { | |
| 1063 | if (conn == NULL) | |
| 1064 | return; | |
| 1065 | ||
| 1066 | /* Make sure we don't send past the end of the bs */ | |
| 30668 | 1067 | if (count > byte_stream_bytes_left(bs)) |
| 1068 | count = byte_stream_bytes_left(bs); /* truncate to remaining space */ | |
| 13593 | 1069 | |
| 1070 | if (count == 0) | |
| 1071 | return; | |
| 1072 | ||
| 1073 | /* Add everything to our outgoing buffer */ | |
|
34529
68cf25486001
GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents:
34115
diff
changeset
|
1074 | purple_circular_buffer_append(conn->buffer_outgoing, bs->data, count); |
| 13593 | 1075 | |
| 1076 | /* If we haven't already started writing stuff, then start the cycle */ | |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1077 | if (conn->watcher_outgoing == 0) |
| 13593 | 1078 | { |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1079 | if (conn->gsc) { |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1080 | conn->watcher_outgoing = purple_input_add(conn->gsc->fd, |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1081 | PURPLE_INPUT_WRITE, send_cb, conn); |
|
25519
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1082 | send_cb(conn, -1, 0); |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1083 | } else if (conn->fd >= 0) { |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1084 | conn->watcher_outgoing = purple_input_add(conn->fd, |
|
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1085 | PURPLE_INPUT_WRITE, send_cb, conn); |
|
25519
d15507b37c1a
Shuffle a few comments around to make it look like I did something
Mark Doliner <markdoliner@pidgin.im>
parents:
25128
diff
changeset
|
1086 | send_cb(conn, -1, 0); |
|
25126
2a75db143599
First pass at adding SSL connections to OSCAR.
Paul Aurich <darkrain42@pidgin.im>
parents:
24659
diff
changeset
|
1087 | } |
| 13593 | 1088 | } |
| 1089 | } | |
| 1090 | ||
| 1091 | static void | |
| 1092 | sendframe_flap(FlapConnection *conn, FlapFrame *frame) | |
| 1093 | { | |
| 1094 | ByteStream bs; | |
| 1095 | int payloadlen, bslen; | |
| 1096 | ||
| 1097 | payloadlen = byte_stream_curpos(&frame->data); | |
| 1098 | ||
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
15150
diff
changeset
|
1099 | byte_stream_new(&bs, 6 + payloadlen); |
| 13593 | 1100 | |
| 1101 | /* FLAP header */ | |
| 1102 | byte_stream_put8(&bs, 0x2a); | |
| 1103 | byte_stream_put8(&bs, frame->channel); | |
| 1104 | byte_stream_put16(&bs, frame->seqnum); | |
| 1105 | byte_stream_put16(&bs, payloadlen); | |
| 1106 | ||
| 1107 | /* Payload */ | |
| 1108 | byte_stream_rewind(&frame->data); | |
| 1109 | byte_stream_putbs(&bs, &frame->data, payloadlen); | |
| 1110 | ||
| 1111 | bslen = byte_stream_curpos(&bs); | |
| 1112 | byte_stream_rewind(&bs); | |
| 1113 | flap_connection_send_byte_stream(&bs, conn, bslen); | |
| 1114 | ||
|
22861
76cb58c0c40a
Used byte_stream_destroy(), added in 2b0e247173b206213210577c194020c78c864474,
Evan Schoenberg <evands@pidgin.im>
parents:
22860
diff
changeset
|
1115 | byte_stream_destroy(&bs); |
| 13593 | 1116 | } |
| 1117 | ||
| 1118 | void | |
| 1119 | flap_connection_send(FlapConnection *conn, FlapFrame *frame) | |
| 1120 | { | |
|
15169
5066b0eb6abf
[gaim-migrate @ 17893]
Mark Doliner <markdoliner@pidgin.im>
parents:
15168
diff
changeset
|
1121 | frame->seqnum = ++(conn->seqnum_out); |
| 13593 | 1122 | sendframe_flap(conn, frame); |
| 1123 | flap_frame_destroy(frame); | |
| 1124 | } |