Mercurial > pidgin
annotate src/protocols/oscar/conn.c @ 13259:3128ef5250ad
[gaim-migrate @ 15625]
Fix good things thanks Bleeter
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 12 Feb 2006 23:00:33 +0000 |
parents | 7ead7b8aea63 |
children | 2d5a1d2a520e |
rev | line source |
---|---|
13234 | 1 /* |
2 * Gaim's oscar protocol plugin | |
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 | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 | |
8888 | 21 /** |
8880 | 22 * Low-level connection handling. |
2086 | 23 * |
24 * Does all this gloriously nifty connection handling stuff... | |
25 * | |
26 */ | |
27 | |
13234 | 28 #include "oscar.h" |
2086 | 29 |
30 #ifndef _WIN32 | |
31 #include <netdb.h> | |
32 #include <sys/socket.h> | |
33 #include <netinet/in.h> | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3694
diff
changeset
|
34 #endif |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3694
diff
changeset
|
35 |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3694
diff
changeset
|
36 #ifdef _WIN32 |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3694
diff
changeset
|
37 #include "win32dep.h" |
2086 | 38 #endif |
39 | |
8880 | 40 /** |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
41 * In OSCAR, every connection has a set of SNAC groups associated |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
42 * with it. These are the groups that you can send over this connection |
13253 | 43 * without being guaranteed a "Not supported" SNAC error. |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
44 * |
13253 | 45 * The grand theory of things says that these associations transcend |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
46 * what libfaim calls "connection types" (conn->type). You can probably |
13253 | 47 * see the elegance here, but since I want to revel in it for a bit, you |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
48 * get to hear it all spelled out. |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
49 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
50 * So let us say that you have your core BOS connection running. One |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
51 * of your modules has just given you a SNAC of the group 0x0004 to send |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
52 * you. Maybe an IM destined for some twit in Greenland. So you start |
13253 | 53 * at the top of your connection list, looking for a connection that |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
54 * claims to support group 0x0004. You find one. Why, that neat BOS |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
55 * connection of yours can do that. So you send it on its way. |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
56 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
57 * Now, say, that fellow from Greenland has friends and they all want to |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
58 * meet up with you in a lame chat room. This has landed you a SNAC |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
59 * in the family 0x000e and you have to admit you're a bit lost. You've |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
60 * searched your connection list for someone who wants to make your life |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
61 * easy and deliver this SNAC for you, but there isn't one there. |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
62 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
63 * Here comes the good bit. Without even letting anyone know, particularly |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
7474
diff
changeset
|
64 * the module that decided to send this SNAC, and definitely not that twit |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
65 * in Greenland, you send out a service request. In this request, you have |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
66 * marked the need for a connection supporting group 0x000e. A few seconds |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
67 * later, you receive a service redirect with an IP address and a cookie in |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
68 * it. Great, you say. Now I have something to do. Off you go, making |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
69 * that connection. One of the first things you get from this new server |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
70 * is a message saying that indeed it does support the group you were looking |
13253 | 71 * for. So you continue and send rate confirmation and all that. |
72 * | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
73 * Then you remember you had that SNAC to send, and now you have a means to |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
74 * do it, and you do, and everyone is happy. Except the Greenlander, who is |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
75 * still stuck in the bitter cold. |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
76 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
77 * Oh, and this is useful for building the Migration SNACs, too. In the |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
78 * future, this may help convince me to implement rate limit mitigation |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
79 * for real. We'll see. |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
80 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
81 * Just to make me look better, I'll say that I've known about this great |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
82 * scheme for quite some time now. But I still haven't convinced myself |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
83 * to make libfaim work that way. It would take a fair amount of effort, |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
84 * and probably some client API changes as well. (Whenever I don't want |
13253 | 85 * to do something, I just say it would change the client API. Then I |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
86 * instantly have a couple of supporters of not doing it.) |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
87 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
88 * Generally, addgroup is only called by the internal handling of the |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
89 * server ready SNAC. So if you want to do something before that, you'll |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
90 * have to be more creative. That is done rather early, though, so I don't |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
91 * think you have to worry about it. Unless you're me. I care deeply |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
92 * about such inane things. |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
93 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
94 */ |
13253 | 95 void |
96 aim_conn_addgroup(OscarConnection *conn, guint16 group) | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
97 { |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
98 aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
99 struct snacgroup *sg; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
100 |
13253 | 101 sg = malloc(sizeof(struct snacgroup)); |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
102 |
11253 | 103 gaim_debug_misc("oscar", "adding group 0x%04x\n", group); |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
104 sg->group = group; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
105 |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
106 sg->next = ins->groups; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
107 ins->groups = sg; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
108 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
109 |
13253 | 110 OscarConnection * |
111 aim_conn_findbygroup(OscarSession *sess, guint16 group) | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
112 { |
13254 | 113 GList *cur;; |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
114 |
13254 | 115 for (cur = sess->oscar_connections; cur; cur = cur->next) |
13253 | 116 { |
13254 | 117 OscarConnection *conn; |
118 aim_conn_inside_t *ins; | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
119 struct snacgroup *sg; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
120 |
13254 | 121 conn = cur->data; |
122 ins = (aim_conn_inside_t *)conn->inside; | |
123 | |
13253 | 124 for (sg = ins->groups; sg; sg = sg->next) |
125 { | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
126 if (sg->group == group) |
13254 | 127 return conn; |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
128 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
129 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
130 |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
131 return NULL; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
132 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
133 |
13253 | 134 static void |
135 connkill_snacgroups(struct snacgroup *head) | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
136 { |
2675 | 137 struct snacgroup *sg; |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
138 |
13253 | 139 for (sg = head; sg; ) |
140 { | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
141 struct snacgroup *tmp; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
142 |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
143 tmp = sg->next; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
144 free(sg); |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
145 sg = tmp; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
146 } |
2675 | 147 } |
148 | |
13253 | 149 static void |
150 connkill_rates(struct rateclass *head) | |
2675 | 151 { |
152 struct rateclass *rc; | |
153 | |
13253 | 154 for (rc = head; rc; ) |
155 { | |
2675 | 156 struct rateclass *tmp; |
2734
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
157 struct snacpair *sp; |
2675 | 158 |
159 tmp = rc->next; | |
2734
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
160 |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
161 for (sp = rc->members; sp; ) { |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
162 struct snacpair *tmpsp; |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
163 |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
164 tmpsp = sp->next; |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
165 free(sp); |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
166 sp = tmpsp; |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
167 } |
2675 | 168 free(rc); |
2734
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
169 |
2675 | 170 rc = tmp; |
171 } | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
172 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
173 |
13254 | 174 void |
175 oscar_connection_destroy(OscarSession *sess, OscarConnection *conn) | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
176 { |
13253 | 177 aim_rxqueue_cleanbyconn(sess, conn); |
178 aim_tx_cleanqueue(sess, conn); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
179 |
13253 | 180 if (conn->fd != -1) |
13254 | 181 aim_conn_close(sess, conn); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
182 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
183 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
184 * This will free ->internal if it necessary... |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
185 */ |
13253 | 186 if (conn->type == AIM_CONN_TYPE_CHAT) |
187 aim_conn_kill_chat(sess, conn); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
188 |
13253 | 189 if (conn->inside) |
190 { | |
191 aim_conn_inside_t *inside = (aim_conn_inside_t *)conn->inside; | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
192 |
13253 | 193 connkill_snacgroups(inside->groups); |
194 connkill_rates(inside->rates); | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
195 |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
196 free(inside); |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
197 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
198 |
13253 | 199 gaim_circ_buffer_destroy(conn->buffer_outgoing); |
13254 | 200 g_free(conn); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
201 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
202 |
2086 | 203 /** |
10271 | 204 * This sends an empty channel 4 SNAC. This is sent to signify |
205 * that we're logging off. This shouldn't really be necessary-- | |
206 * usually the AIM server will detect that the TCP connection has | |
207 * been destroyed. | |
208 */ | |
209 static int | |
13239 | 210 aim_flap_close(OscarSession *sess, OscarConnection *conn) |
10271 | 211 { |
13239 | 212 FlapFrame *fr; |
10271 | 213 |
214 if (!sess || !conn) | |
215 return -EINVAL; | |
216 | |
13253 | 217 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x04, 0))) |
10271 | 218 return -ENOMEM; |
219 | |
220 aim_tx_enqueue(sess, fr); | |
221 | |
222 return 0; | |
223 } | |
224 | |
225 /** | |
2086 | 226 * Allocate a new empty connection structure. |
227 * | |
13253 | 228 * @param sess The oscar session associated with this connection. |
8880 | 229 * @return Returns the new connection structure. |
2086 | 230 */ |
13253 | 231 static OscarConnection * |
232 aim_conn_getnext(OscarSession *sess) | |
2086 | 233 { |
13253 | 234 OscarConnection *conn; |
2086 | 235 |
13253 | 236 conn = g_new0(OscarConnection, 1); |
237 conn->inside = g_new0(aim_conn_inside_t, 1); | |
238 conn->buffer_outgoing = gaim_circ_buffer_new(-1); | |
239 conn->fd = -1; | |
240 conn->subtype = -1; | |
241 conn->type = -1; | |
242 conn->seqnum = 0; | |
243 conn->lastactivity = 0; | |
244 conn->handlerlist = NULL; | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
245 |
13254 | 246 sess->oscar_connections = g_list_prepend(sess->oscar_connections, conn); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
247 |
13253 | 248 return conn; |
2086 | 249 } |
250 | |
251 /** | |
252 * Close, clear, and free a connection structure. Should never be | |
253 * called from within libfaim. | |
254 * | |
8880 | 255 * @param sess Session for the connection. |
256 * @param deadconn Connection to be freed. | |
2086 | 257 */ |
13253 | 258 void |
13254 | 259 aim_conn_kill(OscarSession *sess, OscarConnection *conn) |
2086 | 260 { |
13254 | 261 if (!conn) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
262 return; |
2086 | 263 |
13254 | 264 sess->oscar_connections = g_list_remove(sess->oscar_connections, conn); |
2086 | 265 |
13254 | 266 oscar_connection_destroy(sess, conn); |
2086 | 267 } |
268 | |
269 /** | |
270 * Close (but not free) a connection. | |
271 * | |
13253 | 272 * This leaves everything untouched except for clearing the |
2086 | 273 * handler list and setting the fd to -1 (used to recognize |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
274 * dead connections). It will also remove cookies if necessary. |
2086 | 275 * |
13254 | 276 * @param conn The connection to close. |
2086 | 277 */ |
13253 | 278 void |
13254 | 279 aim_conn_close(OscarSession *sess, OscarConnection *conn) |
2086 | 280 { |
13254 | 281 if (conn->type == AIM_CONN_TYPE_BOS) |
282 aim_flap_close(sess, conn); | |
5435 | 283 |
13254 | 284 if (conn->fd >= 0) |
285 close(conn->fd); | |
5435 | 286 |
13254 | 287 conn->fd = -1; |
5435 | 288 |
13254 | 289 if (conn->handlerlist) |
290 aim_clearhandlers(conn); | |
2086 | 291 } |
292 | |
293 /** | |
13253 | 294 * Locates a connection of the specified type in the |
8866 | 295 * specified session. |
2086 | 296 * |
8880 | 297 * XXX - Except for rendezvous, all uses of this should be removed and |
298 * aim_conn_findbygroup() should be used instead. | |
8866 | 299 * |
8880 | 300 * @param sess The session to search. |
301 * @param type The type of connection to look for. | |
302 * @return Returns the first connection found of the given target type, | |
303 * or NULL if none could be found. | |
2086 | 304 */ |
13253 | 305 OscarConnection * |
306 aim_getconn_type(OscarSession *sess, int type) | |
2086 | 307 { |
13254 | 308 GList *cur; |
2086 | 309 |
13254 | 310 for (cur = sess->oscar_connections; cur; cur = cur->next) |
311 { | |
312 OscarConnection *conn; | |
313 conn = cur->data; | |
314 if ((conn->type == type) && | |
315 !(conn->status & AIM_CONN_STATUS_INPROGRESS)) | |
316 return conn; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
317 } |
2086 | 318 |
13254 | 319 return NULL; |
2086 | 320 } |
321 | |
13253 | 322 OscarConnection * |
323 aim_getconn_type_all(OscarSession *sess, int type) | |
2086 | 324 { |
13254 | 325 GList *cur; |
2086 | 326 |
13254 | 327 for (cur = sess->oscar_connections; cur; cur = cur->next) |
328 { | |
329 OscarConnection *conn; | |
13259 | 330 conn = cur->data; |
13254 | 331 if (conn->type == type) |
332 return conn; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
333 } |
2086 | 334 |
13254 | 335 return NULL; |
2086 | 336 } |
337 | |
338 /** | |
13239 | 339 * Clone an OscarConnection. |
2086 | 340 * |
341 * A new connection is allocated, and the values are filled in | |
13253 | 342 * appropriately. |
2086 | 343 * |
8880 | 344 * @param sess The session containing this connection. |
345 * @param src The connection to clone. | |
13239 | 346 * @return Returns a pointer to the new OscarConnection, or %NULL on error. |
2086 | 347 */ |
13253 | 348 OscarConnection * |
349 aim_cloneconn(OscarSession *sess, OscarConnection *src) | |
2086 | 350 { |
13239 | 351 OscarConnection *conn; |
2086 | 352 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
353 if (!(conn = aim_conn_getnext(sess))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
354 return NULL; |
2086 | 355 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
356 conn->fd = src->fd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
357 conn->type = src->type; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
358 conn->subtype = src->subtype; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
359 conn->seqnum = src->seqnum; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
360 conn->internal = src->internal; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
361 conn->lastactivity = src->lastactivity; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
362 conn->sessv = src->sessv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
363 aim_clonehandlers(sess, conn, src); |
2086 | 364 |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
365 if (src->inside) { |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
366 /* |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
367 * XXX should clone this section as well, but since currently |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
368 * this function only gets called for some of that rendezvous |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
369 * crap, and not on SNAC connections, its probably okay for |
13253 | 370 * now. |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
371 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
372 */ |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
373 } |
2086 | 374 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
375 return conn; |
2086 | 376 } |
377 | |
378 /** | |
379 * Opens a new connection to the specified dest host of specified | |
380 * type, using the proxy settings if available. If @host is %NULL, | |
11162 | 381 * the connection is allocated and returned, but no connection |
2086 | 382 * is made. |
383 * | |
384 * FIXME: Return errors in a more sane way. | |
385 * | |
8866 | 386 * @param sess Session to create connection in |
387 * @param type Type of connection to create | |
2086 | 388 */ |
13253 | 389 OscarConnection * |
13254 | 390 oscar_connection_new(OscarSession *sess, int type) |
2086 | 391 { |
13239 | 392 OscarConnection *conn; |
2086 | 393 |
11162 | 394 if (!(conn = aim_conn_getnext(sess))) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
395 return NULL; |
2086 | 396 |
11162 | 397 conn->sessv = (void *)sess; |
398 conn->type = type; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
399 |
11162 | 400 conn->fd = -1; |
401 conn->status = 0; | |
402 return conn; | |
2086 | 403 } |
404 | |
405 /** | |
8880 | 406 * Determine if a connection is connecting. |
2086 | 407 * |
8880 | 408 * @param conn Connection to examine. |
8866 | 409 * @return Returns nonzero if the connection is in the process of |
410 * connecting (or if it just completed and | |
411 * aim_conn_completeconnect() has yet to be called on it). | |
2086 | 412 */ |
13253 | 413 int |
414 aim_conn_isconnecting(OscarConnection *conn) | |
2086 | 415 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
416 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
417 if (!conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
418 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
419 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
420 return !!(conn->status & AIM_CONN_STATUS_INPROGRESS); |
2086 | 421 } |
422 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
423 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
424 * XXX this is nearly as ugly as proxyconnect(). |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
425 */ |
13253 | 426 int |
427 aim_conn_completeconnect(OscarSession *sess, OscarConnection *conn) | |
2086 | 428 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
429 if (!conn || (conn->fd == -1)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
430 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
431 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
432 if (!(conn->status & AIM_CONN_STATUS_INPROGRESS)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
433 return -1; |
2086 | 434 |
5124 | 435 fcntl(conn->fd, F_SETFL, 0); |
436 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
437 conn->status &= ~AIM_CONN_STATUS_INPROGRESS; |
2086 | 438 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
439 /* Flush out the queues if there was something waiting for this conn */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
440 aim_tx_flushqueue(sess); |
2086 | 441 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
442 return 0; |
2086 | 443 } |
444 | |
13253 | 445 OscarSession * |
446 aim_conn_getsess(OscarConnection *conn) | |
2086 | 447 { |
448 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
449 if (!conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
450 return NULL; |
2086 | 451 |
13239 | 452 return (OscarSession *)conn->sessv; |
2086 | 453 } |
454 | |
8880 | 455 /** |
456 * No-op. This sends an empty channel 5 SNAC. WinAIM 4.x and higher | |
457 * sends these _every minute_ to keep the connection alive. | |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
458 */ |
13253 | 459 int |
460 aim_flap_nop(OscarSession *sess, OscarConnection *conn) | |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
461 { |
13239 | 462 FlapFrame *fr; |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
463 |
13253 | 464 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x05, 0))) |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
465 return -ENOMEM; |
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
466 |
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
467 aim_tx_enqueue(sess, fr); |
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
468 |
7283 | 469 /* clean out SNACs over 60sec old */ |
470 aim_cleansnacs(sess, 60); | |
471 | |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
472 return 0; |
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
473 } |