Mercurial > pidgin
annotate src/protocols/oscar/conn.c @ 13299:b2b26d2ac2ef
[gaim-migrate @ 15665]
Compile
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 16 Feb 2006 02:20:30 +0000 |
parents | b08f8f3c9197 |
children |
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 |
13262 | 101 sg = g_new0(struct snacgroup, 1); |
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; |
13253 | 138 for (sg = head; sg; ) |
139 { | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
140 struct snacgroup *tmp; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
141 |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
142 tmp = sg->next; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
143 free(sg); |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
144 sg = tmp; |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
145 } |
2675 | 146 } |
147 | |
13253 | 148 static void |
149 connkill_rates(struct rateclass *head) | |
2675 | 150 { |
151 struct rateclass *rc; | |
152 | |
13253 | 153 for (rc = head; rc; ) |
154 { | |
2675 | 155 struct rateclass *tmp; |
2734
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
156 struct snacpair *sp; |
2675 | 157 |
158 tmp = rc->next; | |
2734
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
159 |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
160 for (sp = rc->members; sp; ) { |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
161 struct snacpair *tmpsp; |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
162 |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
163 tmpsp = sp->next; |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
164 free(sp); |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
165 sp = tmpsp; |
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
166 } |
2675 | 167 free(rc); |
2734
9fc65bb80596
[gaim-migrate @ 2747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2703
diff
changeset
|
168 |
2675 | 169 rc = tmp; |
170 } | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
171 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
172 |
13254 | 173 void |
174 oscar_connection_destroy(OscarSession *sess, OscarConnection *conn) | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
175 { |
13253 | 176 aim_rxqueue_cleanbyconn(sess, conn); |
177 aim_tx_cleanqueue(sess, conn); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
178 |
13253 | 179 if (conn->fd != -1) |
13254 | 180 aim_conn_close(sess, conn); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
181 |
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 * This will free ->internal if it necessary... |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
184 */ |
13253 | 185 if (conn->type == AIM_CONN_TYPE_CHAT) |
13262 | 186 oscar_connection_destroy_chat(sess, conn); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
187 |
13260 | 188 if (conn->inside != NULL) |
13253 | 189 { |
190 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
|
191 |
13253 | 192 connkill_snacgroups(inside->groups); |
193 connkill_rates(inside->rates); | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
194 |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
195 free(inside); |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
196 } |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
197 |
13253 | 198 gaim_circ_buffer_destroy(conn->buffer_outgoing); |
13254 | 199 g_free(conn); |
13260 | 200 |
201 sess->oscar_connections = g_list_remove(sess->oscar_connections, conn); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
202 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
203 |
2086 | 204 /** |
10271 | 205 * This sends an empty channel 4 SNAC. This is sent to signify |
206 * that we're logging off. This shouldn't really be necessary-- | |
207 * usually the AIM server will detect that the TCP connection has | |
208 * been destroyed. | |
209 */ | |
210 static int | |
13239 | 211 aim_flap_close(OscarSession *sess, OscarConnection *conn) |
10271 | 212 { |
13239 | 213 FlapFrame *fr; |
10271 | 214 |
215 if (!sess || !conn) | |
216 return -EINVAL; | |
217 | |
13253 | 218 if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x04, 0))) |
10271 | 219 return -ENOMEM; |
220 | |
221 aim_tx_enqueue(sess, fr); | |
222 | |
223 return 0; | |
224 } | |
225 | |
226 /** | |
2086 | 227 * Allocate a new empty connection structure. |
228 * | |
13253 | 229 * @param sess The oscar session associated with this connection. |
8880 | 230 * @return Returns the new connection structure. |
2086 | 231 */ |
13253 | 232 static OscarConnection * |
233 aim_conn_getnext(OscarSession *sess) | |
2086 | 234 { |
13253 | 235 OscarConnection *conn; |
2086 | 236 |
13253 | 237 conn = g_new0(OscarConnection, 1); |
238 conn->inside = g_new0(aim_conn_inside_t, 1); | |
239 conn->buffer_outgoing = gaim_circ_buffer_new(-1); | |
240 conn->fd = -1; | |
241 conn->subtype = -1; | |
242 conn->type = -1; | |
243 conn->seqnum = 0; | |
244 conn->lastactivity = 0; | |
245 conn->handlerlist = NULL; | |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
246 |
13254 | 247 sess->oscar_connections = g_list_prepend(sess->oscar_connections, conn); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
248 |
13253 | 249 return conn; |
2086 | 250 } |
251 | |
252 /** | |
253 * Close (but not free) a connection. | |
254 * | |
13253 | 255 * This leaves everything untouched except for clearing the |
2086 | 256 * 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
|
257 * dead connections). It will also remove cookies if necessary. |
2086 | 258 * |
13254 | 259 * @param conn The connection to close. |
2086 | 260 */ |
13253 | 261 void |
13254 | 262 aim_conn_close(OscarSession *sess, OscarConnection *conn) |
2086 | 263 { |
13254 | 264 if (conn->type == AIM_CONN_TYPE_BOS) |
265 aim_flap_close(sess, conn); | |
5435 | 266 |
13254 | 267 if (conn->fd >= 0) |
268 close(conn->fd); | |
5435 | 269 |
13254 | 270 conn->fd = -1; |
5435 | 271 |
13254 | 272 if (conn->handlerlist) |
273 aim_clearhandlers(conn); | |
2086 | 274 } |
275 | |
276 /** | |
13253 | 277 * Locates a connection of the specified type in the |
8866 | 278 * specified session. |
2086 | 279 * |
8880 | 280 * XXX - Except for rendezvous, all uses of this should be removed and |
281 * aim_conn_findbygroup() should be used instead. | |
8866 | 282 * |
8880 | 283 * @param sess The session to search. |
284 * @param type The type of connection to look for. | |
285 * @return Returns the first connection found of the given target type, | |
286 * or NULL if none could be found. | |
2086 | 287 */ |
13253 | 288 OscarConnection * |
289 aim_getconn_type(OscarSession *sess, int type) | |
2086 | 290 { |
13254 | 291 GList *cur; |
2086 | 292 |
13254 | 293 for (cur = sess->oscar_connections; cur; cur = cur->next) |
294 { | |
295 OscarConnection *conn; | |
296 conn = cur->data; | |
297 if ((conn->type == type) && | |
298 !(conn->status & AIM_CONN_STATUS_INPROGRESS)) | |
299 return conn; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
300 } |
2086 | 301 |
13254 | 302 return NULL; |
2086 | 303 } |
304 | |
13253 | 305 OscarConnection * |
306 aim_getconn_type_all(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; | |
13259 | 313 conn = cur->data; |
13254 | 314 if (conn->type == type) |
315 return conn; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
316 } |
2086 | 317 |
13254 | 318 return NULL; |
2086 | 319 } |
320 | |
321 /** | |
13239 | 322 * Clone an OscarConnection. |
2086 | 323 * |
324 * A new connection is allocated, and the values are filled in | |
13253 | 325 * appropriately. |
2086 | 326 * |
8880 | 327 * @param sess The session containing this connection. |
328 * @param src The connection to clone. | |
13239 | 329 * @return Returns a pointer to the new OscarConnection, or %NULL on error. |
2086 | 330 */ |
13253 | 331 OscarConnection * |
332 aim_cloneconn(OscarSession *sess, OscarConnection *src) | |
2086 | 333 { |
13239 | 334 OscarConnection *conn; |
2086 | 335 |
13262 | 336 conn = aim_conn_getnext(sess); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
337 conn->fd = src->fd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
338 conn->type = src->type; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
339 conn->subtype = src->subtype; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
340 conn->seqnum = src->seqnum; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
341 conn->internal = src->internal; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
342 conn->lastactivity = src->lastactivity; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
343 conn->sessv = src->sessv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
344 aim_clonehandlers(sess, conn, src); |
2086 | 345 |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
346 if (src->inside) { |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
347 /* |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
348 * XXX should clone this section as well, but since currently |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
349 * this function only gets called for some of that rendezvous |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
350 * crap, and not on SNAC connections, its probably okay for |
13253 | 351 * now. |
2270
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
352 * |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
353 */ |
d82efea341ef
[gaim-migrate @ 2280]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
354 } |
2086 | 355 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
356 return conn; |
2086 | 357 } |
358 | |
359 /** | |
360 * Opens a new connection to the specified dest host of specified | |
361 * type, using the proxy settings if available. If @host is %NULL, | |
11162 | 362 * the connection is allocated and returned, but no connection |
2086 | 363 * is made. |
364 * | |
365 * FIXME: Return errors in a more sane way. | |
366 * | |
8866 | 367 * @param sess Session to create connection in |
368 * @param type Type of connection to create | |
2086 | 369 */ |
13253 | 370 OscarConnection * |
13254 | 371 oscar_connection_new(OscarSession *sess, int type) |
2086 | 372 { |
13239 | 373 OscarConnection *conn; |
2086 | 374 |
13262 | 375 conn = aim_conn_getnext(sess); |
376 conn->sessv = sess; | |
11162 | 377 conn->type = type; |
378 conn->fd = -1; | |
379 conn->status = 0; | |
13262 | 380 |
11162 | 381 return conn; |
2086 | 382 } |
383 | |
384 /** | |
8880 | 385 * Determine if a connection is connecting. |
2086 | 386 * |
8880 | 387 * @param conn Connection to examine. |
8866 | 388 * @return Returns nonzero if the connection is in the process of |
389 * connecting (or if it just completed and | |
390 * aim_conn_completeconnect() has yet to be called on it). | |
2086 | 391 */ |
13253 | 392 int |
393 aim_conn_isconnecting(OscarConnection *conn) | |
2086 | 394 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
395 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
396 if (!conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
397 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
398 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
399 return !!(conn->status & AIM_CONN_STATUS_INPROGRESS); |
2086 | 400 } |
401 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
402 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
403 * XXX this is nearly as ugly as proxyconnect(). |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
404 */ |
13253 | 405 int |
406 aim_conn_completeconnect(OscarSession *sess, OscarConnection *conn) | |
2086 | 407 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
408 if (!conn || (conn->fd == -1)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
409 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
410 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
411 if (!(conn->status & AIM_CONN_STATUS_INPROGRESS)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
412 return -1; |
2086 | 413 |
5124 | 414 fcntl(conn->fd, F_SETFL, 0); |
415 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
416 conn->status &= ~AIM_CONN_STATUS_INPROGRESS; |
2086 | 417 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
418 /* 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
|
419 aim_tx_flushqueue(sess); |
2086 | 420 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
421 return 0; |
2086 | 422 } |
423 | |
13253 | 424 OscarSession * |
425 aim_conn_getsess(OscarConnection *conn) | |
2086 | 426 { |
427 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
428 if (!conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
429 return NULL; |
2086 | 430 |
13239 | 431 return (OscarSession *)conn->sessv; |
2086 | 432 } |
433 | |
8880 | 434 /** |
435 * No-op. This sends an empty channel 5 SNAC. WinAIM 4.x and higher | |
436 * sends these _every minute_ to keep the connection alive. | |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
437 */ |
13253 | 438 int |
439 aim_flap_nop(OscarSession *sess, OscarConnection *conn) | |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
440 { |
13239 | 441 FlapFrame *fr; |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
442 |
13253 | 443 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
|
444 return -ENOMEM; |
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
445 |
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
446 aim_tx_enqueue(sess, fr); |
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
447 |
7283 | 448 /* clean out SNACs over 60sec old */ |
449 aim_cleansnacs(sess, 60); | |
450 | |
2703
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
451 return 0; |
441b84ab7f4e
[gaim-migrate @ 2716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
452 } |