Mercurial > pidgin.yaz
comparison libpurple/protocols/oscar/peer.c @ 15823: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 | 08db93bbd798 |
comparison
equal
deleted
inserted
replaced
15822:84b0f9b23ede | 15823: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 |
31 | 31 |
32 /* From the oscar PRPL */ | 32 /* From the oscar PRPL */ |
33 #include "oscar.h" | 33 #include "oscar.h" |
34 #include "peer.h" | 34 #include "peer.h" |
35 | 35 |
36 /* From Gaim */ | 36 /* From Purple */ |
37 #include "conversation.h" | 37 #include "conversation.h" |
38 #include "ft.h" | 38 #include "ft.h" |
39 #include "network.h" | 39 #include "network.h" |
40 #include "notify.h" | 40 #include "notify.h" |
41 #include "request.h" | 41 #include "request.h" |
105 | 105 |
106 PeerConnection * | 106 PeerConnection * |
107 peer_connection_new(OscarData *od, OscarCapability type, const char *sn) | 107 peer_connection_new(OscarData *od, OscarCapability type, const char *sn) |
108 { | 108 { |
109 PeerConnection *conn; | 109 PeerConnection *conn; |
110 GaimAccount *account; | 110 PurpleAccount *account; |
111 | 111 |
112 account = gaim_connection_get_account(od->gc); | 112 account = purple_connection_get_account(od->gc); |
113 | 113 |
114 conn = g_new0(PeerConnection, 1); | 114 conn = g_new0(PeerConnection, 1); |
115 conn->od = od; | 115 conn->od = od; |
116 conn->type = type; | 116 conn->type = type; |
117 conn->sn = g_strdup(sn); | 117 conn->sn = g_strdup(sn); |
118 conn->buffer_outgoing = gaim_circ_buffer_new(0); | 118 conn->buffer_outgoing = purple_circ_buffer_new(0); |
119 conn->listenerfd = -1; | 119 conn->listenerfd = -1; |
120 conn->fd = -1; | 120 conn->fd = -1; |
121 conn->lastactivity = time(NULL); | 121 conn->lastactivity = time(NULL); |
122 conn->use_proxy |= gaim_account_get_bool(account, "always_use_rv_proxy", FALSE); | 122 conn->use_proxy |= purple_account_get_bool(account, "always_use_rv_proxy", FALSE); |
123 | 123 |
124 if (type == OSCAR_CAPABILITY_DIRECTIM) | 124 if (type == OSCAR_CAPABILITY_DIRECTIM) |
125 memcpy(conn->magic, "ODC2", 4); | 125 memcpy(conn->magic, "ODC2", 4); |
126 else if (type == OSCAR_CAPABILITY_SENDFILE) | 126 else if (type == OSCAR_CAPABILITY_SENDFILE) |
127 memcpy(conn->magic, "OFT2", 4); | 127 memcpy(conn->magic, "OFT2", 4); |
139 else if (conn->type == OSCAR_CAPABILITY_SENDFILE) | 139 else if (conn->type == OSCAR_CAPABILITY_SENDFILE) |
140 peer_oft_close(conn); | 140 peer_oft_close(conn); |
141 | 141 |
142 if (conn->verified_connect_data != NULL) | 142 if (conn->verified_connect_data != NULL) |
143 { | 143 { |
144 gaim_proxy_connect_cancel(conn->verified_connect_data); | 144 purple_proxy_connect_cancel(conn->verified_connect_data); |
145 conn->verified_connect_data = NULL; | 145 conn->verified_connect_data = NULL; |
146 } | 146 } |
147 | 147 |
148 if (conn->client_connect_data != NULL) | 148 if (conn->client_connect_data != NULL) |
149 { | 149 { |
150 gaim_proxy_connect_cancel(conn->client_connect_data); | 150 purple_proxy_connect_cancel(conn->client_connect_data); |
151 conn->client_connect_data = NULL; | 151 conn->client_connect_data = NULL; |
152 } | 152 } |
153 | 153 |
154 if (conn->listen_data != NULL) | 154 if (conn->listen_data != NULL) |
155 { | 155 { |
156 gaim_network_listen_cancel(conn->listen_data); | 156 purple_network_listen_cancel(conn->listen_data); |
157 conn->listen_data = NULL; | 157 conn->listen_data = NULL; |
158 } | 158 } |
159 | 159 |
160 if (conn->connect_timeout_timer != 0) | 160 if (conn->connect_timeout_timer != 0) |
161 { | 161 { |
162 gaim_timeout_remove(conn->connect_timeout_timer); | 162 purple_timeout_remove(conn->connect_timeout_timer); |
163 conn->connect_timeout_timer = 0; | 163 conn->connect_timeout_timer = 0; |
164 } | 164 } |
165 | 165 |
166 if (conn->watcher_incoming != 0) | 166 if (conn->watcher_incoming != 0) |
167 { | 167 { |
168 gaim_input_remove(conn->watcher_incoming); | 168 purple_input_remove(conn->watcher_incoming); |
169 conn->watcher_incoming = 0; | 169 conn->watcher_incoming = 0; |
170 } | 170 } |
171 if (conn->watcher_outgoing != 0) | 171 if (conn->watcher_outgoing != 0) |
172 { | 172 { |
173 gaim_input_remove(conn->watcher_outgoing); | 173 purple_input_remove(conn->watcher_outgoing); |
174 conn->watcher_outgoing = 0; | 174 conn->watcher_outgoing = 0; |
175 } | 175 } |
176 if (conn->listenerfd != -1) | 176 if (conn->listenerfd != -1) |
177 { | 177 { |
178 close(conn->listenerfd); | 178 close(conn->listenerfd); |
187 g_free(conn->buffer_incoming.data); | 187 g_free(conn->buffer_incoming.data); |
188 conn->buffer_incoming.data = NULL; | 188 conn->buffer_incoming.data = NULL; |
189 conn->buffer_incoming.len = 0; | 189 conn->buffer_incoming.len = 0; |
190 conn->buffer_incoming.offset = 0; | 190 conn->buffer_incoming.offset = 0; |
191 | 191 |
192 gaim_circ_buffer_destroy(conn->buffer_outgoing); | 192 purple_circ_buffer_destroy(conn->buffer_outgoing); |
193 conn->buffer_outgoing = gaim_circ_buffer_new(0); | 193 conn->buffer_outgoing = purple_circ_buffer_new(0); |
194 | 194 |
195 conn->flags &= ~PEER_CONNECTION_FLAG_IS_INCOMING; | 195 conn->flags &= ~PEER_CONNECTION_FLAG_IS_INCOMING; |
196 } | 196 } |
197 | 197 |
198 static gboolean | 198 static gboolean |
200 { | 200 { |
201 PeerConnection *conn; | 201 PeerConnection *conn; |
202 | 202 |
203 conn = data; | 203 conn = data; |
204 | 204 |
205 gaim_request_close_with_handle(conn); | 205 purple_request_close_with_handle(conn); |
206 | 206 |
207 peer_connection_close(conn); | 207 peer_connection_close(conn); |
208 | 208 |
209 if (conn->checksum_data != NULL) | 209 if (conn->checksum_data != NULL) |
210 peer_oft_checksum_destroy(conn->checksum_data); | 210 peer_oft_checksum_destroy(conn->checksum_data); |
211 | 211 |
212 if (conn->xfer != NULL) | 212 if (conn->xfer != NULL) |
213 { | 213 { |
214 GaimXferStatusType status; | 214 PurpleXferStatusType status; |
215 conn->xfer->data = NULL; | 215 conn->xfer->data = NULL; |
216 status = gaim_xfer_get_status(conn->xfer); | 216 status = purple_xfer_get_status(conn->xfer); |
217 if ((status != GAIM_XFER_STATUS_DONE) && | 217 if ((status != PURPLE_XFER_STATUS_DONE) && |
218 (status != GAIM_XFER_STATUS_CANCEL_LOCAL) && | 218 (status != PURPLE_XFER_STATUS_CANCEL_LOCAL) && |
219 (status != GAIM_XFER_STATUS_CANCEL_REMOTE)) | 219 (status != PURPLE_XFER_STATUS_CANCEL_REMOTE)) |
220 { | 220 { |
221 if ((conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED) || | 221 if ((conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED) || |
222 (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_REFUSED)) | 222 (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_REFUSED)) |
223 gaim_xfer_cancel_remote(conn->xfer); | 223 purple_xfer_cancel_remote(conn->xfer); |
224 else | 224 else |
225 gaim_xfer_cancel_local(conn->xfer); | 225 purple_xfer_cancel_local(conn->xfer); |
226 } | 226 } |
227 gaim_xfer_unref(conn->xfer); | 227 purple_xfer_unref(conn->xfer); |
228 conn->xfer = NULL; | 228 conn->xfer = NULL; |
229 } | 229 } |
230 | 230 |
231 g_free(conn->sn); | 231 g_free(conn->sn); |
232 g_free(conn->error_message); | 232 g_free(conn->error_message); |
233 g_free(conn->proxyip); | 233 g_free(conn->proxyip); |
234 g_free(conn->clientip); | 234 g_free(conn->clientip); |
235 g_free(conn->verifiedip); | 235 g_free(conn->verifiedip); |
236 g_free(conn->xferdata.name); | 236 g_free(conn->xferdata.name); |
237 gaim_circ_buffer_destroy(conn->buffer_outgoing); | 237 purple_circ_buffer_destroy(conn->buffer_outgoing); |
238 | 238 |
239 conn->od->peer_connections = g_slist_remove(conn->od->peer_connections, conn); | 239 conn->od->peer_connections = g_slist_remove(conn->od->peer_connections, conn); |
240 | 240 |
241 g_free(conn); | 241 g_free(conn); |
242 | 242 |
245 | 245 |
246 void | 246 void |
247 peer_connection_destroy(PeerConnection *conn, OscarDisconnectReason reason, const gchar *error_message) | 247 peer_connection_destroy(PeerConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
248 { | 248 { |
249 if (conn->destroy_timeout != 0) | 249 if (conn->destroy_timeout != 0) |
250 gaim_timeout_remove(conn->destroy_timeout); | 250 purple_timeout_remove(conn->destroy_timeout); |
251 conn->disconnect_reason = reason; | 251 conn->disconnect_reason = reason; |
252 g_free(conn->error_message); | 252 g_free(conn->error_message); |
253 conn->error_message = g_strdup(error_message); | 253 conn->error_message = g_strdup(error_message); |
254 peer_connection_destroy_cb(conn); | 254 peer_connection_destroy_cb(conn); |
255 } | 255 } |
259 { | 259 { |
260 if (conn->destroy_timeout != 0) | 260 if (conn->destroy_timeout != 0) |
261 /* Already taken care of */ | 261 /* Already taken care of */ |
262 return; | 262 return; |
263 | 263 |
264 gaim_debug_info("oscar", "Scheduling destruction of peer connection\n"); | 264 purple_debug_info("oscar", "Scheduling destruction of peer connection\n"); |
265 conn->disconnect_reason = reason; | 265 conn->disconnect_reason = reason; |
266 g_free(conn->error_message); | 266 g_free(conn->error_message); |
267 conn->error_message = g_strdup(error_message); | 267 conn->error_message = g_strdup(error_message); |
268 conn->destroy_timeout = gaim_timeout_add(0, peer_connection_destroy_cb, conn); | 268 conn->destroy_timeout = purple_timeout_add(0, peer_connection_destroy_cb, conn); |
269 } | 269 } |
270 | 270 |
271 /*******************************************************************/ | 271 /*******************************************************************/ |
272 /* Begin code for receiving data on a peer connection */ | 272 /* Begin code for receiving data on a peer connection */ |
273 /*******************************************************************/ | 273 /*******************************************************************/ |
286 * receiving a file from the remote user. Once the data has been | 286 * receiving a file from the remote user. Once the data has been |
287 * read, the watcher will be switched back to this function to | 287 * read, the watcher will be switched back to this function to |
288 * continue reading the next frame. | 288 * continue reading the next frame. |
289 */ | 289 */ |
290 void | 290 void |
291 peer_connection_recv_cb(gpointer data, gint source, GaimInputCondition cond) | 291 peer_connection_recv_cb(gpointer data, gint source, PurpleInputCondition cond) |
292 { | 292 { |
293 PeerConnection *conn; | 293 PeerConnection *conn; |
294 ssize_t read; | 294 ssize_t read; |
295 | 295 |
296 conn = data; | 296 conn = data; |
329 return; | 329 return; |
330 | 330 |
331 /* All ODC/OFT frames must start with a magic string */ | 331 /* All ODC/OFT frames must start with a magic string */ |
332 if (memcmp(conn->magic, conn->header, 4)) | 332 if (memcmp(conn->magic, conn->header, 4)) |
333 { | 333 { |
334 gaim_debug_warning("oscar", "Expecting magic string to " | 334 purple_debug_warning("oscar", "Expecting magic string to " |
335 "be %c%c%c%c but received magic string %c%c%c%c. " | 335 "be %c%c%c%c but received magic string %c%c%c%c. " |
336 "Closing connection.\n", | 336 "Closing connection.\n", |
337 conn->magic[0], conn->magic[1], conn->magic[2], | 337 conn->magic[0], conn->magic[1], conn->magic[2], |
338 conn->magic[3], conn->header[0], conn->header[1], | 338 conn->magic[3], conn->header[0], conn->header[1], |
339 conn->header[2], conn->header[3]); | 339 conn->header[2], conn->header[3]); |
401 /*******************************************************************/ | 401 /*******************************************************************/ |
402 /* Begin code for sending data on a peer connection */ | 402 /* Begin code for sending data on a peer connection */ |
403 /*******************************************************************/ | 403 /*******************************************************************/ |
404 | 404 |
405 static void | 405 static void |
406 send_cb(gpointer data, gint source, GaimInputCondition cond) | 406 send_cb(gpointer data, gint source, PurpleInputCondition cond) |
407 { | 407 { |
408 PeerConnection *conn; | 408 PeerConnection *conn; |
409 gsize writelen; | 409 gsize writelen; |
410 ssize_t wrotelen; | 410 ssize_t wrotelen; |
411 | 411 |
412 conn = data; | 412 conn = data; |
413 writelen = gaim_circ_buffer_get_max_read(conn->buffer_outgoing); | 413 writelen = purple_circ_buffer_get_max_read(conn->buffer_outgoing); |
414 | 414 |
415 if (writelen == 0) | 415 if (writelen == 0) |
416 { | 416 { |
417 gaim_input_remove(conn->watcher_outgoing); | 417 purple_input_remove(conn->watcher_outgoing); |
418 conn->watcher_outgoing = 0; | 418 conn->watcher_outgoing = 0; |
419 return; | 419 return; |
420 } | 420 } |
421 | 421 |
422 wrotelen = send(conn->fd, conn->buffer_outgoing->outptr, writelen, 0); | 422 wrotelen = send(conn->fd, conn->buffer_outgoing->outptr, writelen, 0); |
426 /* No worries */ | 426 /* No worries */ |
427 return; | 427 return; |
428 | 428 |
429 if (conn->ready) | 429 if (conn->ready) |
430 { | 430 { |
431 gaim_input_remove(conn->watcher_outgoing); | 431 purple_input_remove(conn->watcher_outgoing); |
432 conn->watcher_outgoing = 0; | 432 conn->watcher_outgoing = 0; |
433 close(conn->fd); | 433 close(conn->fd); |
434 conn->fd = -1; | 434 conn->fd = -1; |
435 peer_connection_schedule_destroy(conn, | 435 peer_connection_schedule_destroy(conn, |
436 OSCAR_DISCONNECT_LOST_CONNECTION, NULL); | 436 OSCAR_DISCONNECT_LOST_CONNECTION, NULL); |
444 peer_connection_trynext(conn); | 444 peer_connection_trynext(conn); |
445 } | 445 } |
446 return; | 446 return; |
447 } | 447 } |
448 | 448 |
449 gaim_circ_buffer_mark_read(conn->buffer_outgoing, wrotelen); | 449 purple_circ_buffer_mark_read(conn->buffer_outgoing, wrotelen); |
450 conn->lastactivity = time(NULL); | 450 conn->lastactivity = time(NULL); |
451 } | 451 } |
452 | 452 |
453 /** | 453 /** |
454 * This should be called by OFT/ODC code to send a standard OFT or ODC | 454 * This should be called by OFT/ODC code to send a standard OFT or ODC |
457 */ | 457 */ |
458 void | 458 void |
459 peer_connection_send(PeerConnection *conn, ByteStream *bs) | 459 peer_connection_send(PeerConnection *conn, ByteStream *bs) |
460 { | 460 { |
461 /* Add everything to our outgoing buffer */ | 461 /* Add everything to our outgoing buffer */ |
462 gaim_circ_buffer_append(conn->buffer_outgoing, bs->data, bs->len); | 462 purple_circ_buffer_append(conn->buffer_outgoing, bs->data, bs->len); |
463 | 463 |
464 /* If we haven't already started writing stuff, then start the cycle */ | 464 /* If we haven't already started writing stuff, then start the cycle */ |
465 if ((conn->watcher_outgoing == 0) && (conn->fd != -1)) | 465 if ((conn->watcher_outgoing == 0) && (conn->fd != -1)) |
466 { | 466 { |
467 conn->watcher_outgoing = gaim_input_add(conn->fd, | 467 conn->watcher_outgoing = purple_input_add(conn->fd, |
468 GAIM_INPUT_WRITE, send_cb, conn); | 468 PURPLE_INPUT_WRITE, send_cb, conn); |
469 send_cb(conn, conn->fd, 0); | 469 send_cb(conn, conn->fd, 0); |
470 } | 470 } |
471 } | 471 } |
472 | 472 |
473 /*******************************************************************/ | 473 /*******************************************************************/ |
479 /*******************************************************************/ | 479 /*******************************************************************/ |
480 | 480 |
481 void | 481 void |
482 peer_connection_finalize_connection(PeerConnection *conn) | 482 peer_connection_finalize_connection(PeerConnection *conn) |
483 { | 483 { |
484 conn->watcher_incoming = gaim_input_add(conn->fd, | 484 conn->watcher_incoming = purple_input_add(conn->fd, |
485 GAIM_INPUT_READ, peer_connection_recv_cb, conn); | 485 PURPLE_INPUT_READ, peer_connection_recv_cb, conn); |
486 | 486 |
487 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) | 487 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) |
488 { | 488 { |
489 /* | 489 /* |
490 * If we are connecting to them then send our cookie so they | 490 * If we are connecting to them then send our cookie so they |
494 if (!(conn->flags & PEER_CONNECTION_FLAG_IS_INCOMING)) | 494 if (!(conn->flags & PEER_CONNECTION_FLAG_IS_INCOMING)) |
495 peer_odc_send_cookie(conn); | 495 peer_odc_send_cookie(conn); |
496 } | 496 } |
497 else if (conn->type == OSCAR_CAPABILITY_SENDFILE) | 497 else if (conn->type == OSCAR_CAPABILITY_SENDFILE) |
498 { | 498 { |
499 if (gaim_xfer_get_type(conn->xfer) == GAIM_XFER_SEND) | 499 if (purple_xfer_get_type(conn->xfer) == PURPLE_XFER_SEND) |
500 { | 500 { |
501 peer_oft_send_prompt(conn); | 501 peer_oft_send_prompt(conn); |
502 } | 502 } |
503 } | 503 } |
504 | 504 |
535 peer_connection_trynext(conn); | 535 peer_connection_trynext(conn); |
536 } | 536 } |
537 return; | 537 return; |
538 } | 538 } |
539 | 539 |
540 gaim_timeout_remove(conn->connect_timeout_timer); | 540 purple_timeout_remove(conn->connect_timeout_timer); |
541 conn->connect_timeout_timer = 0; | 541 conn->connect_timeout_timer = 0; |
542 | 542 |
543 if (conn->client_connect_data != NULL) | 543 if (conn->client_connect_data != NULL) |
544 { | 544 { |
545 gaim_proxy_connect_cancel(conn->client_connect_data); | 545 purple_proxy_connect_cancel(conn->client_connect_data); |
546 conn->client_connect_data = NULL; | 546 conn->client_connect_data = NULL; |
547 } | 547 } |
548 | 548 |
549 if (conn->verified_connect_data != NULL) | 549 if (conn->verified_connect_data != NULL) |
550 { | 550 { |
551 gaim_proxy_connect_cancel(conn->verified_connect_data); | 551 purple_proxy_connect_cancel(conn->verified_connect_data); |
552 conn->verified_connect_data = NULL; | 552 conn->verified_connect_data = NULL; |
553 } | 553 } |
554 | 554 |
555 conn->fd = source; | 555 conn->fd = source; |
556 | 556 |
579 * received a peer frame from the remote user and have verified that | 579 * received a peer frame from the remote user and have verified that |
580 * the cookie in the peer frame matches the cookie that was exchanged | 580 * the cookie in the peer frame matches the cookie that was exchanged |
581 * in the channel 2 ICBM. | 581 * in the channel 2 ICBM. |
582 */ | 582 */ |
583 void | 583 void |
584 peer_connection_listen_cb(gpointer data, gint source, GaimInputCondition cond) | 584 peer_connection_listen_cb(gpointer data, gint source, PurpleInputCondition cond) |
585 { | 585 { |
586 PeerConnection *conn; | 586 PeerConnection *conn; |
587 OscarData *od; | 587 OscarData *od; |
588 GaimConnection *gc; | 588 PurpleConnection *gc; |
589 struct sockaddr addr; | 589 struct sockaddr addr; |
590 socklen_t addrlen = sizeof(addr); | 590 socklen_t addrlen = sizeof(addr); |
591 | 591 |
592 conn = data; | 592 conn = data; |
593 od = conn->od; | 593 od = conn->od; |
594 gc = od->gc; | 594 gc = od->gc; |
595 | 595 |
596 gaim_debug_info("oscar", "Accepting connection on listener socket.\n"); | 596 purple_debug_info("oscar", "Accepting connection on listener socket.\n"); |
597 | 597 |
598 conn->fd = accept(conn->listenerfd, &addr, &addrlen); | 598 conn->fd = accept(conn->listenerfd, &addr, &addrlen); |
599 if (conn->fd == -1) | 599 if (conn->fd == -1) |
600 { | 600 { |
601 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | 601 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
613 close(conn->fd); | 613 close(conn->fd); |
614 return; | 614 return; |
615 } | 615 } |
616 | 616 |
617 fcntl(conn->fd, F_SETFL, O_NONBLOCK); | 617 fcntl(conn->fd, F_SETFL, O_NONBLOCK); |
618 gaim_input_remove(conn->watcher_incoming); | 618 purple_input_remove(conn->watcher_incoming); |
619 | 619 |
620 peer_connection_finalize_connection(conn); | 620 peer_connection_finalize_connection(conn); |
621 } | 621 } |
622 | 622 |
623 /** | 623 /** |
627 static void | 627 static void |
628 peer_connection_establish_listener_cb(int listenerfd, gpointer data) | 628 peer_connection_establish_listener_cb(int listenerfd, gpointer data) |
629 { | 629 { |
630 PeerConnection *conn; | 630 PeerConnection *conn; |
631 OscarData *od; | 631 OscarData *od; |
632 GaimConnection *gc; | 632 PurpleConnection *gc; |
633 GaimAccount *account; | 633 PurpleAccount *account; |
634 GaimConversation *conv; | 634 PurpleConversation *conv; |
635 char *tmp; | 635 char *tmp; |
636 FlapConnection *bos_conn; | 636 FlapConnection *bos_conn; |
637 const char *listener_ip; | 637 const char *listener_ip; |
638 unsigned short listener_port; | 638 unsigned short listener_port; |
639 | 639 |
647 return; | 647 return; |
648 } | 648 } |
649 | 649 |
650 od = conn->od; | 650 od = conn->od; |
651 gc = od->gc; | 651 gc = od->gc; |
652 account = gaim_connection_get_account(gc); | 652 account = purple_connection_get_account(gc); |
653 conn->listenerfd = listenerfd; | 653 conn->listenerfd = listenerfd; |
654 | 654 |
655 /* Send the "please connect to me!" ICBM */ | 655 /* Send the "please connect to me!" ICBM */ |
656 bos_conn = flap_connection_findbygroup(od, SNAC_FAMILY_ICBM); | 656 bos_conn = flap_connection_findbygroup(od, SNAC_FAMILY_ICBM); |
657 if (bos_conn == NULL) | 657 if (bos_conn == NULL) |
659 /* Not good */ | 659 /* Not good */ |
660 peer_connection_trynext(conn); | 660 peer_connection_trynext(conn); |
661 return; | 661 return; |
662 } | 662 } |
663 | 663 |
664 listener_ip = gaim_network_get_my_ip(bos_conn->fd); | 664 listener_ip = purple_network_get_my_ip(bos_conn->fd); |
665 listener_port = gaim_network_get_port_from_fd(conn->listenerfd); | 665 listener_port = purple_network_get_port_from_fd(conn->listenerfd); |
666 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) | 666 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) |
667 { | 667 { |
668 aim_im_sendch2_odc_requestdirect(od, | 668 aim_im_sendch2_odc_requestdirect(od, |
669 conn->cookie, conn->sn, gaim_network_ip_atoi(listener_ip), | 669 conn->cookie, conn->sn, purple_network_ip_atoi(listener_ip), |
670 listener_port, ++conn->lastrequestnumber); | 670 listener_port, ++conn->lastrequestnumber); |
671 | 671 |
672 /* Print a message to a local conversation window */ | 672 /* Print a message to a local conversation window */ |
673 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, conn->sn); | 673 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, conn->sn); |
674 tmp = g_strdup_printf(_("Asking %s to connect to us at %s:%hu for " | 674 tmp = g_strdup_printf(_("Asking %s to connect to us at %s:%hu for " |
675 "Direct IM."), conn->sn, listener_ip, listener_port); | 675 "Direct IM."), conn->sn, listener_ip, listener_port); |
676 gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | 676 purple_conversation_write(conv, NULL, tmp, PURPLE_MESSAGE_SYSTEM, time(NULL)); |
677 g_free(tmp); | 677 g_free(tmp); |
678 } | 678 } |
679 else if (conn->type == OSCAR_CAPABILITY_SENDFILE) | 679 else if (conn->type == OSCAR_CAPABILITY_SENDFILE) |
680 { | 680 { |
681 aim_im_sendch2_sendfile_requestdirect(od, | 681 aim_im_sendch2_sendfile_requestdirect(od, |
682 conn->cookie, conn->sn, | 682 conn->cookie, conn->sn, |
683 gaim_network_ip_atoi(listener_ip), | 683 purple_network_ip_atoi(listener_ip), |
684 listener_port, ++conn->lastrequestnumber, | 684 listener_port, ++conn->lastrequestnumber, |
685 (const gchar *)conn->xferdata.name, | 685 (const gchar *)conn->xferdata.name, |
686 conn->xferdata.size, conn->xferdata.totfiles); | 686 conn->xferdata.size, conn->xferdata.totfiles); |
687 } | 687 } |
688 } | 688 } |
694 * waiting for the OS to time out the connection attempt is not | 694 * waiting for the OS to time out the connection attempt is not |
695 * practical--the default timeout on many OSes can be 3 minutes or | 695 * practical--the default timeout on many OSes can be 3 minutes or |
696 * more, and users are impatient. | 696 * more, and users are impatient. |
697 * | 697 * |
698 * Worst case scenario: the user is connected to the Internet using | 698 * Worst case scenario: the user is connected to the Internet using |
699 * a modem with severe lag. The peer connections fail and Gaim falls | 699 * a modem with severe lag. The peer connections fail and Purple falls |
700 * back to using a proxied connection. The lower bandwidth | 700 * back to using a proxied connection. The lower bandwidth |
701 * limitations imposed by the proxied connection won't matter because | 701 * limitations imposed by the proxied connection won't matter because |
702 * the user is using a modem. | 702 * the user is using a modem. |
703 * | 703 * |
704 * I suppose this line of thinking is discriminatory against people | 704 * I suppose this line of thinking is discriminatory against people |
715 { | 715 { |
716 PeerConnection *conn; | 716 PeerConnection *conn; |
717 | 717 |
718 conn = data; | 718 conn = data; |
719 | 719 |
720 gaim_debug_info("oscar", "Peer connection timed out after 5 seconds. " | 720 purple_debug_info("oscar", "Peer connection timed out after 5 seconds. " |
721 "Trying next method...\n"); | 721 "Trying next method...\n"); |
722 | 722 |
723 peer_connection_trynext(conn); | 723 peer_connection_trynext(conn); |
724 | 724 |
725 /* Cancel this timer. It'll be added again, if needed. */ | 725 /* Cancel this timer. It'll be added again, if needed. */ |
731 * sequence of steps. | 731 * sequence of steps. |
732 */ | 732 */ |
733 void | 733 void |
734 peer_connection_trynext(PeerConnection *conn) | 734 peer_connection_trynext(PeerConnection *conn) |
735 { | 735 { |
736 GaimAccount *account; | 736 PurpleAccount *account; |
737 | 737 |
738 account = gaim_connection_get_account(conn->od->gc); | 738 account = purple_connection_get_account(conn->od->gc); |
739 | 739 |
740 /* | 740 /* |
741 * Close any remnants of a previous failed connection attempt. | 741 * Close any remnants of a previous failed connection attempt. |
742 */ | 742 */ |
743 peer_connection_close(conn); | 743 peer_connection_close(conn); |
753 conn->flags |= PEER_CONNECTION_FLAG_TRIED_DIRECT; | 753 conn->flags |= PEER_CONNECTION_FLAG_TRIED_DIRECT; |
754 | 754 |
755 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) | 755 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) |
756 { | 756 { |
757 gchar *tmp; | 757 gchar *tmp; |
758 GaimConversation *conv; | 758 PurpleConversation *conv; |
759 tmp = g_strdup_printf(_("Attempting to connect to %s:%hu."), | 759 tmp = g_strdup_printf(_("Attempting to connect to %s:%hu."), |
760 conn->verifiedip, conn->port); | 760 conn->verifiedip, conn->port); |
761 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, conn->sn); | 761 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, conn->sn); |
762 gaim_conversation_write(conv, NULL, tmp, | 762 purple_conversation_write(conv, NULL, tmp, |
763 GAIM_MESSAGE_SYSTEM, time(NULL)); | 763 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
764 g_free(tmp); | 764 g_free(tmp); |
765 } | 765 } |
766 | 766 |
767 conn->verified_connect_data = gaim_proxy_connect(NULL, account, | 767 conn->verified_connect_data = purple_proxy_connect(NULL, account, |
768 conn->verifiedip, conn->port, | 768 conn->verifiedip, conn->port, |
769 peer_connection_verified_established_cb, conn); | 769 peer_connection_verified_established_cb, conn); |
770 | 770 |
771 if ((conn->verifiedip == NULL) || | 771 if ((conn->verifiedip == NULL) || |
772 strcmp(conn->verifiedip, conn->clientip)) | 772 strcmp(conn->verifiedip, conn->clientip)) |
773 { | 773 { |
774 conn->client_connect_data = gaim_proxy_connect(NULL, account, | 774 conn->client_connect_data = purple_proxy_connect(NULL, account, |
775 conn->clientip, conn->port, | 775 conn->clientip, conn->port, |
776 peer_connection_client_established_cb, conn); | 776 peer_connection_client_established_cb, conn); |
777 } | 777 } |
778 | 778 |
779 if ((conn->verified_connect_data != NULL) || | 779 if ((conn->verified_connect_data != NULL) || |
780 (conn->client_connect_data != NULL)) | 780 (conn->client_connect_data != NULL)) |
781 { | 781 { |
782 /* Connecting... */ | 782 /* Connecting... */ |
783 conn->connect_timeout_timer = gaim_timeout_add(5000, | 783 conn->connect_timeout_timer = purple_timeout_add(5000, |
784 peer_connection_tooktoolong, conn); | 784 peer_connection_tooktoolong, conn); |
785 return; | 785 return; |
786 } | 786 } |
787 } | 787 } |
788 | 788 |
799 * Remote user is connecting to us, so we'll need to verify | 799 * Remote user is connecting to us, so we'll need to verify |
800 * that the user who connected is our friend. | 800 * that the user who connected is our friend. |
801 */ | 801 */ |
802 conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING; | 802 conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING; |
803 | 803 |
804 conn->listen_data = gaim_network_listen_range(5190, 5290, SOCK_STREAM, | 804 conn->listen_data = purple_network_listen_range(5190, 5290, SOCK_STREAM, |
805 peer_connection_establish_listener_cb, conn); | 805 peer_connection_establish_listener_cb, conn); |
806 if (conn->listen_data != NULL) | 806 if (conn->listen_data != NULL) |
807 { | 807 { |
808 /* Opening listener socket... */ | 808 /* Opening listener socket... */ |
809 return; | 809 return; |
827 conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING; | 827 conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING; |
828 | 828 |
829 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) | 829 if (conn->type == OSCAR_CAPABILITY_DIRECTIM) |
830 { | 830 { |
831 gchar *tmp; | 831 gchar *tmp; |
832 GaimConversation *conv; | 832 PurpleConversation *conv; |
833 tmp = g_strdup_printf(_("Attempting to connect via proxy server.")); | 833 tmp = g_strdup_printf(_("Attempting to connect via proxy server.")); |
834 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, conn->sn); | 834 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, conn->sn); |
835 gaim_conversation_write(conv, NULL, tmp, | 835 purple_conversation_write(conv, NULL, tmp, |
836 GAIM_MESSAGE_SYSTEM, time(NULL)); | 836 PURPLE_MESSAGE_SYSTEM, time(NULL)); |
837 g_free(tmp); | 837 g_free(tmp); |
838 } | 838 } |
839 | 839 |
840 conn->verified_connect_data = gaim_proxy_connect(NULL, account, | 840 conn->verified_connect_data = purple_proxy_connect(NULL, account, |
841 (conn->proxyip != NULL) ? conn->proxyip : PEER_PROXY_SERVER, | 841 (conn->proxyip != NULL) ? conn->proxyip : PEER_PROXY_SERVER, |
842 PEER_PROXY_PORT, | 842 PEER_PROXY_PORT, |
843 peer_proxy_connection_established_cb, conn); | 843 peer_proxy_connection_established_cb, conn); |
844 if (conn->verified_connect_data != NULL) | 844 if (conn->verified_connect_data != NULL) |
845 { | 845 { |
865 conn = peer_connection_find_by_type(od, sn, type); | 865 conn = peer_connection_find_by_type(od, sn, type); |
866 if (conn != NULL) | 866 if (conn != NULL) |
867 { | 867 { |
868 if (conn->ready) | 868 if (conn->ready) |
869 { | 869 { |
870 GaimAccount *account; | 870 PurpleAccount *account; |
871 GaimConversation *conv; | 871 PurpleConversation *conv; |
872 | 872 |
873 gaim_debug_info("oscar", "Already have a direct IM " | 873 purple_debug_info("oscar", "Already have a direct IM " |
874 "session with %s.\n", sn); | 874 "session with %s.\n", sn); |
875 account = gaim_connection_get_account(od->gc); | 875 account = purple_connection_get_account(od->gc); |
876 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, | 876 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
877 sn, account); | 877 sn, account); |
878 if (conv != NULL) | 878 if (conv != NULL) |
879 gaim_conversation_present(conv); | 879 purple_conversation_present(conv); |
880 return; | 880 return; |
881 } | 881 } |
882 | 882 |
883 /* Cancel the old connection and try again */ | 883 /* Cancel the old connection and try again */ |
884 peer_connection_destroy(conn, OSCAR_DISCONNECT_RETRYING, NULL); | 884 peer_connection_destroy(conn, OSCAR_DISCONNECT_RETRYING, NULL); |
931 * Someone else wants to establish a peer connection with us. | 931 * Someone else wants to establish a peer connection with us. |
932 */ | 932 */ |
933 void | 933 void |
934 peer_connection_got_proposition(OscarData *od, const gchar *sn, const gchar *message, IcbmArgsCh2 *args) | 934 peer_connection_got_proposition(OscarData *od, const gchar *sn, const gchar *message, IcbmArgsCh2 *args) |
935 { | 935 { |
936 GaimConnection *gc; | 936 PurpleConnection *gc; |
937 GaimAccount *account; | 937 PurpleAccount *account; |
938 PeerConnection *conn; | 938 PeerConnection *conn; |
939 gchar *buf; | 939 gchar *buf; |
940 | 940 |
941 gc = od->gc; | 941 gc = od->gc; |
942 account = gaim_connection_get_account(gc); | 942 account = purple_connection_get_account(gc); |
943 | 943 |
944 /* | 944 /* |
945 * If we have a connection with this same cookie then they are | 945 * If we have a connection with this same cookie then they are |
946 * probably just telling us they weren't able to connect to us | 946 * probably just telling us they weren't able to connect to us |
947 * and we should try connecting to them, instead. Or they want | 947 * and we should try connecting to them, instead. Or they want |
948 * to go through a proxy. | 948 * to go through a proxy. |
949 */ | 949 */ |
950 conn = peer_connection_find_by_cookie(od, sn, args->cookie); | 950 conn = peer_connection_find_by_cookie(od, sn, args->cookie); |
951 if ((conn != NULL) && (conn->type == args->type)) | 951 if ((conn != NULL) && (conn->type == args->type)) |
952 { | 952 { |
953 gaim_debug_info("oscar", "Remote user wants to try a " | 953 purple_debug_info("oscar", "Remote user wants to try a " |
954 "different connection method\n"); | 954 "different connection method\n"); |
955 g_free(conn->proxyip); | 955 g_free(conn->proxyip); |
956 g_free(conn->clientip); | 956 g_free(conn->clientip); |
957 g_free(conn->verifiedip); | 957 g_free(conn->verifiedip); |
958 if (args->use_proxy) | 958 if (args->use_proxy) |
973 { | 973 { |
974 conn = peer_connection_find_by_type(od, sn, args->type); | 974 conn = peer_connection_find_by_type(od, sn, args->type); |
975 if (conn != NULL) | 975 if (conn != NULL) |
976 { | 976 { |
977 /* Close the old direct IM and start a new one */ | 977 /* Close the old direct IM and start a new one */ |
978 gaim_debug_info("oscar", "Received new direct IM request " | 978 purple_debug_info("oscar", "Received new direct IM request " |
979 "from %s. Destroying old connection.\n", sn); | 979 "from %s. Destroying old connection.\n", sn); |
980 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); | 980 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
981 } | 981 } |
982 } | 982 } |
983 | 983 |
986 { | 986 { |
987 if ((args->info.sendfile.filename == NULL) || | 987 if ((args->info.sendfile.filename == NULL) || |
988 (args->info.sendfile.totsize == 0) || | 988 (args->info.sendfile.totsize == 0) || |
989 (args->info.sendfile.totfiles == 0)) | 989 (args->info.sendfile.totfiles == 0)) |
990 { | 990 { |
991 gaim_debug_warning("oscar", | 991 purple_debug_warning("oscar", |
992 "%s tried to send you a file with incomplete " | 992 "%s tried to send you a file with incomplete " |
993 "information.\n", sn); | 993 "information.\n", sn); |
994 return; | 994 return; |
995 } | 995 } |
996 } | 996 } |
1006 conn->lastrequestnumber++; | 1006 conn->lastrequestnumber++; |
1007 | 1007 |
1008 if (args->type == OSCAR_CAPABILITY_DIRECTIM) | 1008 if (args->type == OSCAR_CAPABILITY_DIRECTIM) |
1009 { | 1009 { |
1010 buf = g_strdup_printf(_("%s has just asked to directly connect to %s"), | 1010 buf = g_strdup_printf(_("%s has just asked to directly connect to %s"), |
1011 sn, gaim_account_get_username(account)); | 1011 sn, purple_account_get_username(account)); |
1012 | 1012 |
1013 gaim_request_action(conn, NULL, buf, | 1013 purple_request_action(conn, NULL, buf, |
1014 _("This requires a direct connection between " | 1014 _("This requires a direct connection between " |
1015 "the two computers and is necessary for IM " | 1015 "the two computers and is necessary for IM " |
1016 "Images. Because your IP address will be " | 1016 "Images. Because your IP address will be " |
1017 "revealed, this may be considered a privacy " | 1017 "revealed, this may be considered a privacy " |
1018 "risk."), | 1018 "risk."), |
1019 GAIM_DEFAULT_ACTION_NONE, conn, 2, | 1019 PURPLE_DEFAULT_ACTION_NONE, conn, 2, |
1020 _("_Connect"), G_CALLBACK(peer_connection_got_proposition_yes_cb), | 1020 _("_Connect"), G_CALLBACK(peer_connection_got_proposition_yes_cb), |
1021 _("Cancel"), G_CALLBACK(peer_connection_got_proposition_no_cb)); | 1021 _("Cancel"), G_CALLBACK(peer_connection_got_proposition_no_cb)); |
1022 } | 1022 } |
1023 else if (args->type == OSCAR_CAPABILITY_SENDFILE) | 1023 else if (args->type == OSCAR_CAPABILITY_SENDFILE) |
1024 { | 1024 { |
1025 gchar *filename; | 1025 gchar *filename; |
1026 | 1026 |
1027 conn->xfer = gaim_xfer_new(account, GAIM_XFER_RECEIVE, sn); | 1027 conn->xfer = purple_xfer_new(account, PURPLE_XFER_RECEIVE, sn); |
1028 if (conn->xfer) | 1028 if (conn->xfer) |
1029 { | 1029 { |
1030 conn->xfer->data = conn; | 1030 conn->xfer->data = conn; |
1031 gaim_xfer_ref(conn->xfer); | 1031 purple_xfer_ref(conn->xfer); |
1032 gaim_xfer_set_size(conn->xfer, args->info.sendfile.totsize); | 1032 purple_xfer_set_size(conn->xfer, args->info.sendfile.totsize); |
1033 | 1033 |
1034 /* Set the file name */ | 1034 /* Set the file name */ |
1035 if (g_utf8_validate(args->info.sendfile.filename, -1, NULL)) | 1035 if (g_utf8_validate(args->info.sendfile.filename, -1, NULL)) |
1036 filename = g_strdup(args->info.sendfile.filename); | 1036 filename = g_strdup(args->info.sendfile.filename); |
1037 else | 1037 else |
1038 filename = gaim_utf8_salvage(args->info.sendfile.filename); | 1038 filename = purple_utf8_salvage(args->info.sendfile.filename); |
1039 | 1039 |
1040 if (args->info.sendfile.subtype == AIM_OFT_SUBTYPE_SEND_DIR) | 1040 if (args->info.sendfile.subtype == AIM_OFT_SUBTYPE_SEND_DIR) |
1041 { | 1041 { |
1042 /* | 1042 /* |
1043 * If they are sending us a directory then the last character | 1043 * If they are sending us a directory then the last character |
1047 */ | 1047 */ |
1048 char *tmp = strrchr(filename, '\\'); | 1048 char *tmp = strrchr(filename, '\\'); |
1049 if ((tmp != NULL) && (tmp[1] == '*')) | 1049 if ((tmp != NULL) && (tmp[1] == '*')) |
1050 tmp[0] = '\0'; | 1050 tmp[0] = '\0'; |
1051 } | 1051 } |
1052 gaim_xfer_set_filename(conn->xfer, filename); | 1052 purple_xfer_set_filename(conn->xfer, filename); |
1053 g_free(filename); | 1053 g_free(filename); |
1054 | 1054 |
1055 /* | 1055 /* |
1056 * Set the message, unless this is the dummy message from an | 1056 * Set the message, unless this is the dummy message from an |
1057 * ICQ client or an empty message from an AIM client. | 1057 * ICQ client or an empty message from an AIM client. |
1059 */ | 1059 */ |
1060 if ((message != NULL) && | 1060 if ((message != NULL) && |
1061 (g_ascii_strncasecmp(message, "<ICQ_COOL_FT>", 13) != 0) && | 1061 (g_ascii_strncasecmp(message, "<ICQ_COOL_FT>", 13) != 0) && |
1062 (g_ascii_strcasecmp(message, "<HTML>") != 0)) | 1062 (g_ascii_strcasecmp(message, "<HTML>") != 0)) |
1063 { | 1063 { |
1064 gaim_xfer_set_message(conn->xfer, message); | 1064 purple_xfer_set_message(conn->xfer, message); |
1065 } | 1065 } |
1066 | 1066 |
1067 /* Setup our I/O op functions */ | 1067 /* Setup our I/O op functions */ |
1068 gaim_xfer_set_init_fnc(conn->xfer, peer_oft_recvcb_init); | 1068 purple_xfer_set_init_fnc(conn->xfer, peer_oft_recvcb_init); |
1069 gaim_xfer_set_end_fnc(conn->xfer, peer_oft_recvcb_end); | 1069 purple_xfer_set_end_fnc(conn->xfer, peer_oft_recvcb_end); |
1070 gaim_xfer_set_request_denied_fnc(conn->xfer, peer_oft_cb_generic_cancel); | 1070 purple_xfer_set_request_denied_fnc(conn->xfer, peer_oft_cb_generic_cancel); |
1071 gaim_xfer_set_cancel_recv_fnc(conn->xfer, peer_oft_cb_generic_cancel); | 1071 purple_xfer_set_cancel_recv_fnc(conn->xfer, peer_oft_cb_generic_cancel); |
1072 gaim_xfer_set_ack_fnc(conn->xfer, peer_oft_recvcb_ack_recv); | 1072 purple_xfer_set_ack_fnc(conn->xfer, peer_oft_recvcb_ack_recv); |
1073 | 1073 |
1074 /* Now perform the request */ | 1074 /* Now perform the request */ |
1075 gaim_xfer_request(conn->xfer); | 1075 purple_xfer_request(conn->xfer); |
1076 } | 1076 } |
1077 } | 1077 } |
1078 } | 1078 } |
1079 | 1079 |
1080 /*******************************************************************/ | 1080 /*******************************************************************/ |