Mercurial > pidgin
comparison libpurple/protocols/oscar/peer_proxy.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | 648551e3243a |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /* | 1 /* |
2 * Gaim's oscar protocol plugin | 2 * Purple's oscar protocol plugin |
3 * This file is the legal property of its developers. | 3 * This file is the legal property of its developers. |
4 * Please see the AUTHORS file distributed alongside this file. | 4 * Please see the AUTHORS file distributed alongside this file. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | 7 * modify it under the terms of the GNU Lesser General Public |
29 peer_proxy_send(PeerConnection *conn, ProxyFrame *frame) | 29 peer_proxy_send(PeerConnection *conn, ProxyFrame *frame) |
30 { | 30 { |
31 size_t length; | 31 size_t length; |
32 ByteStream bs; | 32 ByteStream bs; |
33 | 33 |
34 gaim_debug_info("oscar", "Outgoing peer proxy frame with " | 34 purple_debug_info("oscar", "Outgoing peer proxy frame with " |
35 "type=0x%04hx, unknown=0x%08x, " | 35 "type=0x%04hx, unknown=0x%08x, " |
36 "flags=0x%04hx, and payload length=%hd\n", | 36 "flags=0x%04hx, and payload length=%hd\n", |
37 frame->type, frame->unknown, | 37 frame->type, frame->unknown, |
38 frame->flags, frame->payload.len); | 38 frame->flags, frame->payload.len); |
39 | 39 |
60 */ | 60 */ |
61 static void | 61 static void |
62 peer_proxy_send_create_new_conn(PeerConnection *conn) | 62 peer_proxy_send_create_new_conn(PeerConnection *conn) |
63 { | 63 { |
64 ProxyFrame frame; | 64 ProxyFrame frame; |
65 GaimAccount *account; | 65 PurpleAccount *account; |
66 const gchar *sn; | 66 const gchar *sn; |
67 guint8 sn_length; | 67 guint8 sn_length; |
68 | 68 |
69 memset(&frame, 0, sizeof(ProxyFrame)); | 69 memset(&frame, 0, sizeof(ProxyFrame)); |
70 frame.type = PEER_PROXY_TYPE_CREATE; | 70 frame.type = PEER_PROXY_TYPE_CREATE; |
71 frame.flags = 0x0000; | 71 frame.flags = 0x0000; |
72 | 72 |
73 account = gaim_connection_get_account(conn->od->gc); | 73 account = purple_connection_get_account(conn->od->gc); |
74 sn = gaim_account_get_username(account); | 74 sn = purple_account_get_username(account); |
75 sn_length = strlen(sn); | 75 sn_length = strlen(sn); |
76 byte_stream_new(&frame.payload, 1 + sn_length + 8 + 20); | 76 byte_stream_new(&frame.payload, 1 + sn_length + 8 + 20); |
77 byte_stream_put8(&frame.payload, sn_length); | 77 byte_stream_put8(&frame.payload, sn_length); |
78 byte_stream_putraw(&frame.payload, (const guint8 *)sn, sn_length); | 78 byte_stream_putraw(&frame.payload, (const guint8 *)sn, sn_length); |
79 byte_stream_putraw(&frame.payload, conn->cookie, 8); | 79 byte_stream_putraw(&frame.payload, conn->cookie, 8); |
96 */ | 96 */ |
97 static void | 97 static void |
98 peer_proxy_send_join_existing_conn(PeerConnection *conn, guint16 pin) | 98 peer_proxy_send_join_existing_conn(PeerConnection *conn, guint16 pin) |
99 { | 99 { |
100 ProxyFrame frame; | 100 ProxyFrame frame; |
101 GaimAccount *account; | 101 PurpleAccount *account; |
102 const gchar *sn; | 102 const gchar *sn; |
103 guint8 sn_length; | 103 guint8 sn_length; |
104 | 104 |
105 memset(&frame, 0, sizeof(ProxyFrame)); | 105 memset(&frame, 0, sizeof(ProxyFrame)); |
106 frame.type = PEER_PROXY_TYPE_JOIN; | 106 frame.type = PEER_PROXY_TYPE_JOIN; |
107 frame.flags = 0x0000; | 107 frame.flags = 0x0000; |
108 | 108 |
109 account = gaim_connection_get_account(conn->od->gc); | 109 account = purple_connection_get_account(conn->od->gc); |
110 sn = gaim_account_get_username(account); | 110 sn = purple_account_get_username(account); |
111 sn_length = strlen(sn); | 111 sn_length = strlen(sn); |
112 byte_stream_new(&frame.payload, 1 + sn_length + 2 + 8 + 20); | 112 byte_stream_new(&frame.payload, 1 + sn_length + 2 + 8 + 20); |
113 byte_stream_put8(&frame.payload, sn_length); | 113 byte_stream_put8(&frame.payload, sn_length); |
114 byte_stream_putraw(&frame.payload, (const guint8 *)sn, sn_length); | 114 byte_stream_putraw(&frame.payload, (const guint8 *)sn, sn_length); |
115 byte_stream_put16(&frame.payload, pin); | 115 byte_stream_put16(&frame.payload, pin); |
126 * Handle an incoming peer proxy negotiation frame. | 126 * Handle an incoming peer proxy negotiation frame. |
127 */ | 127 */ |
128 static void | 128 static void |
129 peer_proxy_recv_frame(PeerConnection *conn, ProxyFrame *frame) | 129 peer_proxy_recv_frame(PeerConnection *conn, ProxyFrame *frame) |
130 { | 130 { |
131 gaim_debug_info("oscar", "Incoming peer proxy frame with " | 131 purple_debug_info("oscar", "Incoming peer proxy frame with " |
132 "type=0x%04hx, unknown=0x%08x, " | 132 "type=0x%04hx, unknown=0x%08x, " |
133 "flags=0x%04hx, and payload length=%hd\n", frame->type, | 133 "flags=0x%04hx, and payload length=%hd\n", frame->type, |
134 frame->unknown, frame->flags, frame->payload.len); | 134 frame->unknown, frame->flags, frame->payload.len); |
135 | 135 |
136 if (frame->type == PEER_PROXY_TYPE_CREATED) | 136 if (frame->type == PEER_PROXY_TYPE_CREATED) |
159 conn->xferdata.size, conn->xferdata.totfiles); | 159 conn->xferdata.size, conn->xferdata.totfiles); |
160 } | 160 } |
161 } | 161 } |
162 else if (frame->type == PEER_PROXY_TYPE_READY) | 162 else if (frame->type == PEER_PROXY_TYPE_READY) |
163 { | 163 { |
164 gaim_input_remove(conn->watcher_incoming); | 164 purple_input_remove(conn->watcher_incoming); |
165 conn->watcher_incoming = 0; | 165 conn->watcher_incoming = 0; |
166 | 166 |
167 peer_connection_finalize_connection(conn); | 167 peer_connection_finalize_connection(conn); |
168 } | 168 } |
169 else if (frame->type == PEER_PROXY_TYPE_ERROR) | 169 else if (frame->type == PEER_PROXY_TYPE_ERROR) |
179 msg = "initial request timed out"; | 179 msg = "initial request timed out"; |
180 else if (error == 0x001a) | 180 else if (error == 0x001a) |
181 msg ="accept period timed out"; | 181 msg ="accept period timed out"; |
182 else | 182 else |
183 msg = "unknown reason"; | 183 msg = "unknown reason"; |
184 gaim_debug_info("oscar", "Proxy negotiation failed with " | 184 purple_debug_info("oscar", "Proxy negotiation failed with " |
185 "error 0x%04hx: %s\n", error, msg); | 185 "error 0x%04hx: %s\n", error, msg); |
186 } | 186 } |
187 else | 187 else |
188 { | 188 { |
189 gaim_debug_warning("oscar", "Proxy negotiation failed with " | 189 purple_debug_warning("oscar", "Proxy negotiation failed with " |
190 "an unknown error\n"); | 190 "an unknown error\n"); |
191 } | 191 } |
192 peer_connection_trynext(conn); | 192 peer_connection_trynext(conn); |
193 } | 193 } |
194 else | 194 else |
195 { | 195 { |
196 gaim_debug_warning("oscar", "Unknown peer proxy frame type 0x%04hx.\n", | 196 purple_debug_warning("oscar", "Unknown peer proxy frame type 0x%04hx.\n", |
197 frame->type); | 197 frame->type); |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 static void | 201 static void |
202 peer_proxy_connection_recv_cb(gpointer data, gint source, GaimInputCondition cond) | 202 peer_proxy_connection_recv_cb(gpointer data, gint source, PurpleInputCondition cond) |
203 { | 203 { |
204 PeerConnection *conn; | 204 PeerConnection *conn; |
205 ssize_t read; | 205 ssize_t read; |
206 ProxyFrame *frame; | 206 ProxyFrame *frame; |
207 | 207 |
216 12 - conn->proxy_header_received, 0); | 216 12 - conn->proxy_header_received, 0); |
217 | 217 |
218 /* Check if the proxy server closed the connection */ | 218 /* Check if the proxy server closed the connection */ |
219 if (read == 0) | 219 if (read == 0) |
220 { | 220 { |
221 gaim_debug_info("oscar", "Peer proxy server closed connection\n"); | 221 purple_debug_info("oscar", "Peer proxy server closed connection\n"); |
222 peer_connection_trynext(conn); | 222 peer_connection_trynext(conn); |
223 return; | 223 return; |
224 } | 224 } |
225 | 225 |
226 /* If there was an error then close the connection */ | 226 /* If there was an error then close the connection */ |
228 { | 228 { |
229 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | 229 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
230 /* No worries */ | 230 /* No worries */ |
231 return; | 231 return; |
232 | 232 |
233 gaim_debug_info("oscar", "Lost connection with peer proxy server\n"); | 233 purple_debug_info("oscar", "Lost connection with peer proxy server\n"); |
234 peer_connection_trynext(conn); | 234 peer_connection_trynext(conn); |
235 return; | 235 return; |
236 } | 236 } |
237 | 237 |
238 conn->lastactivity = time(NULL); | 238 conn->lastactivity = time(NULL); |
243 return; | 243 return; |
244 | 244 |
245 /* We only support a specific version of the proxy protocol */ | 245 /* We only support a specific version of the proxy protocol */ |
246 if (aimutil_get16(&conn->proxy_header[2]) != PEER_PROXY_PACKET_VERSION) | 246 if (aimutil_get16(&conn->proxy_header[2]) != PEER_PROXY_PACKET_VERSION) |
247 { | 247 { |
248 gaim_debug_warning("oscar", "Expected peer proxy protocol " | 248 purple_debug_warning("oscar", "Expected peer proxy protocol " |
249 "version %u but received version %u. Closing " | 249 "version %u but received version %u. Closing " |
250 "connection.\n", PEER_PROXY_PACKET_VERSION, | 250 "connection.\n", PEER_PROXY_PACKET_VERSION, |
251 aimutil_get16(&conn->proxy_header[2])); | 251 aimutil_get16(&conn->proxy_header[2])); |
252 peer_connection_trynext(conn); | 252 peer_connection_trynext(conn); |
253 return; | 253 return; |
275 0); | 275 0); |
276 | 276 |
277 /* Check if the proxy server closed the connection */ | 277 /* Check if the proxy server closed the connection */ |
278 if (read == 0) | 278 if (read == 0) |
279 { | 279 { |
280 gaim_debug_info("oscar", "Peer proxy server closed connection\n"); | 280 purple_debug_info("oscar", "Peer proxy server closed connection\n"); |
281 g_free(frame->payload.data); | 281 g_free(frame->payload.data); |
282 g_free(frame); | 282 g_free(frame); |
283 conn->frame = NULL; | 283 conn->frame = NULL; |
284 peer_connection_trynext(conn); | 284 peer_connection_trynext(conn); |
285 return; | 285 return; |
289 { | 289 { |
290 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | 290 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
291 /* No worries */ | 291 /* No worries */ |
292 return; | 292 return; |
293 | 293 |
294 gaim_debug_info("oscar", "Lost connection with peer proxy server\n"); | 294 purple_debug_info("oscar", "Lost connection with peer proxy server\n"); |
295 g_free(frame->payload.data); | 295 g_free(frame->payload.data); |
296 g_free(frame); | 296 g_free(frame); |
297 conn->frame = NULL; | 297 conn->frame = NULL; |
298 peer_connection_trynext(conn); | 298 peer_connection_trynext(conn); |
299 return; | 299 return; |
336 peer_connection_trynext(conn); | 336 peer_connection_trynext(conn); |
337 return; | 337 return; |
338 } | 338 } |
339 | 339 |
340 conn->fd = source; | 340 conn->fd = source; |
341 conn->watcher_incoming = gaim_input_add(conn->fd, | 341 conn->watcher_incoming = purple_input_add(conn->fd, |
342 GAIM_INPUT_READ, peer_proxy_connection_recv_cb, conn); | 342 PURPLE_INPUT_READ, peer_proxy_connection_recv_cb, conn); |
343 | 343 |
344 if (conn->proxyip != NULL) | 344 if (conn->proxyip != NULL) |
345 /* Connect to the session created by the remote user */ | 345 /* Connect to the session created by the remote user */ |
346 peer_proxy_send_join_existing_conn(conn, conn->port); | 346 peer_proxy_send_join_existing_conn(conn, conn->port); |
347 else | 347 else |