Mercurial > pidgin
comparison libpurple/protocols/oscar/flap_connection.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 | 1927f4ead3ca |
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 |
209 queued_snac->subtype = subtype; | 209 queued_snac->subtype = subtype; |
210 queued_snac->frame = frame; | 210 queued_snac->frame = frame; |
211 g_queue_push_tail(conn->queued_snacs, queued_snac); | 211 g_queue_push_tail(conn->queued_snacs, queued_snac); |
212 | 212 |
213 if (conn->queued_timeout == 0) | 213 if (conn->queued_timeout == 0) |
214 conn->queued_timeout = gaim_timeout_add(500, flap_connection_send_queued, conn); | 214 conn->queued_timeout = purple_timeout_add(500, flap_connection_send_queued, conn); |
215 | 215 |
216 return; | 216 return; |
217 } | 217 } |
218 | 218 |
219 flap_connection_send(conn, frame); | 219 flap_connection_send(conn, frame); |
264 { | 264 { |
265 FlapConnection *conn; | 265 FlapConnection *conn; |
266 | 266 |
267 conn = g_new0(FlapConnection, 1); | 267 conn = g_new0(FlapConnection, 1); |
268 conn->od = od; | 268 conn->od = od; |
269 conn->buffer_outgoing = gaim_circ_buffer_new(0); | 269 conn->buffer_outgoing = purple_circ_buffer_new(0); |
270 conn->fd = -1; | 270 conn->fd = -1; |
271 conn->subtype = -1; | 271 conn->subtype = -1; |
272 conn->type = type; | 272 conn->type = type; |
273 conn->queued_snacs = g_queue_new(); | 273 conn->queued_snacs = g_queue_new(); |
274 | 274 |
288 void | 288 void |
289 flap_connection_close(OscarData *od, FlapConnection *conn) | 289 flap_connection_close(OscarData *od, FlapConnection *conn) |
290 { | 290 { |
291 if (conn->connect_data != NULL) | 291 if (conn->connect_data != NULL) |
292 { | 292 { |
293 gaim_proxy_connect_cancel(conn->connect_data); | 293 purple_proxy_connect_cancel(conn->connect_data); |
294 conn->connect_data = NULL; | 294 conn->connect_data = NULL; |
295 } | 295 } |
296 | 296 |
297 if (conn->connect_data != NULL) | 297 if (conn->connect_data != NULL) |
298 { | 298 { |
312 conn->fd = -1; | 312 conn->fd = -1; |
313 } | 313 } |
314 | 314 |
315 if (conn->watcher_incoming != 0) | 315 if (conn->watcher_incoming != 0) |
316 { | 316 { |
317 gaim_input_remove(conn->watcher_incoming); | 317 purple_input_remove(conn->watcher_incoming); |
318 conn->watcher_incoming = 0; | 318 conn->watcher_incoming = 0; |
319 } | 319 } |
320 | 320 |
321 if (conn->watcher_outgoing != 0) | 321 if (conn->watcher_outgoing != 0) |
322 { | 322 { |
323 gaim_input_remove(conn->watcher_outgoing); | 323 purple_input_remove(conn->watcher_outgoing); |
324 conn->watcher_outgoing = 0; | 324 conn->watcher_outgoing = 0; |
325 } | 325 } |
326 | 326 |
327 g_free(conn->buffer_incoming.data.data); | 327 g_free(conn->buffer_incoming.data.data); |
328 conn->buffer_incoming.data.data = NULL; | 328 conn->buffer_incoming.data.data = NULL; |
329 | 329 |
330 gaim_circ_buffer_destroy(conn->buffer_outgoing); | 330 purple_circ_buffer_destroy(conn->buffer_outgoing); |
331 conn->buffer_outgoing = NULL; | 331 conn->buffer_outgoing = NULL; |
332 } | 332 } |
333 | 333 |
334 static void | 334 static void |
335 flap_connection_destroy_rateclass(struct rateclass *rateclass) | 335 flap_connection_destroy_rateclass(struct rateclass *rateclass) |
353 static gboolean | 353 static gboolean |
354 flap_connection_destroy_cb(gpointer data) | 354 flap_connection_destroy_cb(gpointer data) |
355 { | 355 { |
356 FlapConnection *conn; | 356 FlapConnection *conn; |
357 OscarData *od; | 357 OscarData *od; |
358 GaimAccount *account; | 358 PurpleAccount *account; |
359 | 359 |
360 conn = data; | 360 conn = data; |
361 od = conn->od; | 361 od = conn->od; |
362 account = (GAIM_CONNECTION_IS_VALID(od->gc) ? gaim_connection_get_account(od->gc) : NULL); | 362 account = (PURPLE_CONNECTION_IS_VALID(od->gc) ? purple_connection_get_account(od->gc) : NULL); |
363 | 363 |
364 gaim_debug_info("oscar", "Destroying oscar connection of " | 364 purple_debug_info("oscar", "Destroying oscar connection of " |
365 "type 0x%04hx\n", conn->type); | 365 "type 0x%04hx\n", conn->type); |
366 | 366 |
367 od->oscar_connections = g_slist_remove(od->oscar_connections, conn); | 367 od->oscar_connections = g_slist_remove(od->oscar_connections, conn); |
368 | 368 |
369 /* | 369 /* |
371 * we should try to request one instead of disconnecting. | 371 * we should try to request one instead of disconnecting. |
372 */ | 372 */ |
373 if (account && !account->disconnecting && | 373 if (account && !account->disconnecting && |
374 ((od->oscar_connections == NULL) || (!flap_connection_getbytype(od, SNAC_FAMILY_LOCATE)))) | 374 ((od->oscar_connections == NULL) || (!flap_connection_getbytype(od, SNAC_FAMILY_LOCATE)))) |
375 { | 375 { |
376 /* No more FLAP connections! Sign off this GaimConnection! */ | 376 /* No more FLAP connections! Sign off this PurpleConnection! */ |
377 gchar *tmp; | 377 gchar *tmp; |
378 if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED) | 378 if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED) |
379 tmp = g_strdup(_("Server closed the connection.")); | 379 tmp = g_strdup(_("Server closed the connection.")); |
380 else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION) | 380 else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION) |
381 tmp = g_strdup_printf(_("Lost connection with server:\n%s"), | 381 tmp = g_strdup_printf(_("Lost connection with server:\n%s"), |
392 */ | 392 */ |
393 tmp = NULL; | 393 tmp = NULL; |
394 | 394 |
395 if (tmp != NULL) | 395 if (tmp != NULL) |
396 { | 396 { |
397 gaim_connection_error(od->gc, tmp); | 397 purple_connection_error(od->gc, tmp); |
398 g_free(tmp); | 398 g_free(tmp); |
399 } | 399 } |
400 } | 400 } |
401 | 401 |
402 flap_connection_close(od, conn); | 402 flap_connection_close(od, conn); |
424 flap_frame_destroy(queued_snac->frame); | 424 flap_frame_destroy(queued_snac->frame); |
425 g_free(queued_snac); | 425 g_free(queued_snac); |
426 } | 426 } |
427 g_queue_free(conn->queued_snacs); | 427 g_queue_free(conn->queued_snacs); |
428 if (conn->queued_timeout > 0) | 428 if (conn->queued_timeout > 0) |
429 gaim_timeout_remove(conn->queued_timeout); | 429 purple_timeout_remove(conn->queued_timeout); |
430 | 430 |
431 g_free(conn); | 431 g_free(conn); |
432 | 432 |
433 return FALSE; | 433 return FALSE; |
434 } | 434 } |
439 */ | 439 */ |
440 void | 440 void |
441 flap_connection_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message) | 441 flap_connection_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
442 { | 442 { |
443 if (conn->destroy_timeout != 0) | 443 if (conn->destroy_timeout != 0) |
444 gaim_timeout_remove(conn->destroy_timeout); | 444 purple_timeout_remove(conn->destroy_timeout); |
445 conn->disconnect_reason = reason; | 445 conn->disconnect_reason = reason; |
446 g_free(conn->error_message); | 446 g_free(conn->error_message); |
447 conn->error_message = g_strdup(error_message); | 447 conn->error_message = g_strdup(error_message); |
448 flap_connection_destroy_cb(conn); | 448 flap_connection_destroy_cb(conn); |
449 } | 449 } |
450 | 450 |
451 /** | 451 /** |
452 * Schedule Gaim to destroy the given FlapConnection as soon as we | 452 * Schedule Purple to destroy the given FlapConnection as soon as we |
453 * return control back to the program's main loop. We must do this | 453 * return control back to the program's main loop. We must do this |
454 * if we want to destroy the connection but we are still using it | 454 * if we want to destroy the connection but we are still using it |
455 * for some reason. | 455 * for some reason. |
456 * | 456 * |
457 * @param reason The reason for the disconnection. | 457 * @param reason The reason for the disconnection. |
459 * regarding the reason for the disconnecting. This should | 459 * regarding the reason for the disconnecting. This should |
460 * be NULL for everything except OSCAR_DISCONNECT_LOST_CONNECTION, | 460 * be NULL for everything except OSCAR_DISCONNECT_LOST_CONNECTION, |
461 * in which case it should contain the value of strerror(errno), | 461 * in which case it should contain the value of strerror(errno), |
462 * and OSCAR_DISCONNECT_COULD_NOT_CONNECT, in which case it | 462 * and OSCAR_DISCONNECT_COULD_NOT_CONNECT, in which case it |
463 * should contain the error_message passed back from the call | 463 * should contain the error_message passed back from the call |
464 * to gaim_proxy_connect(). | 464 * to purple_proxy_connect(). |
465 */ | 465 */ |
466 void | 466 void |
467 flap_connection_schedule_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message) | 467 flap_connection_schedule_destroy(FlapConnection *conn, OscarDisconnectReason reason, const gchar *error_message) |
468 { | 468 { |
469 if (conn->destroy_timeout != 0) | 469 if (conn->destroy_timeout != 0) |
470 /* Already taken care of */ | 470 /* Already taken care of */ |
471 return; | 471 return; |
472 | 472 |
473 gaim_debug_info("oscar", "Scheduling destruction of FLAP " | 473 purple_debug_info("oscar", "Scheduling destruction of FLAP " |
474 "connection of type 0x%04hx\n", conn->type); | 474 "connection of type 0x%04hx\n", conn->type); |
475 conn->disconnect_reason = reason; | 475 conn->disconnect_reason = reason; |
476 g_free(conn->error_message); | 476 g_free(conn->error_message); |
477 conn->error_message = g_strdup(error_message); | 477 conn->error_message = g_strdup(error_message); |
478 conn->destroy_timeout = gaim_timeout_add(0, flap_connection_destroy_cb, conn); | 478 conn->destroy_timeout = purple_timeout_add(0, flap_connection_destroy_cb, conn); |
479 } | 479 } |
480 | 480 |
481 /** | 481 /** |
482 * In OSCAR, every connection has a set of SNAC groups associated | 482 * In OSCAR, every connection has a set of SNAC groups associated |
483 * with it. These are the groups that you can send over this connection | 483 * with it. These are the groups that you can send over this connection |
736 if (frame->channel == 0x01) { | 736 if (frame->channel == 0x01) { |
737 guint32 flap_version = byte_stream_get32(&frame->data); | 737 guint32 flap_version = byte_stream_get32(&frame->data); |
738 if (flap_version != 0x00000001) | 738 if (flap_version != 0x00000001) |
739 { | 739 { |
740 /* Error! */ | 740 /* Error! */ |
741 gaim_debug_warning("oscar", "Expecting FLAP version " | 741 purple_debug_warning("oscar", "Expecting FLAP version " |
742 "0x00000001 but received FLAP version %08lx. Closing connection.\n", | 742 "0x00000001 but received FLAP version %08lx. Closing connection.\n", |
743 flap_version); | 743 flap_version); |
744 flap_connection_schedule_destroy(conn, | 744 flap_connection_schedule_destroy(conn, |
745 OSCAR_DISCONNECT_INVALID_DATA, NULL); | 745 OSCAR_DISCONNECT_INVALID_DATA, NULL); |
746 } | 746 } |
764 * All complete FLAPs handled immedate after they're received. | 764 * All complete FLAPs handled immedate after they're received. |
765 * Incomplete FLAP data is stored locally and appended to the next | 765 * Incomplete FLAP data is stored locally and appended to the next |
766 * time this callback is triggered. | 766 * time this callback is triggered. |
767 */ | 767 */ |
768 void | 768 void |
769 flap_connection_recv_cb(gpointer data, gint source, GaimInputCondition cond) | 769 flap_connection_recv_cb(gpointer data, gint source, PurpleInputCondition cond) |
770 { | 770 { |
771 FlapConnection *conn; | 771 FlapConnection *conn; |
772 ssize_t read; | 772 ssize_t read; |
773 | 773 |
774 conn = data; | 774 conn = data; |
882 conn->header_received = 0; | 882 conn->header_received = 0; |
883 } | 883 } |
884 } | 884 } |
885 | 885 |
886 static void | 886 static void |
887 send_cb(gpointer data, gint source, GaimInputCondition cond) | 887 send_cb(gpointer data, gint source, PurpleInputCondition cond) |
888 { | 888 { |
889 FlapConnection *conn; | 889 FlapConnection *conn; |
890 int writelen, ret; | 890 int writelen, ret; |
891 | 891 |
892 conn = data; | 892 conn = data; |
893 writelen = gaim_circ_buffer_get_max_read(conn->buffer_outgoing); | 893 writelen = purple_circ_buffer_get_max_read(conn->buffer_outgoing); |
894 | 894 |
895 if (writelen == 0) | 895 if (writelen == 0) |
896 { | 896 { |
897 gaim_input_remove(conn->watcher_outgoing); | 897 purple_input_remove(conn->watcher_outgoing); |
898 conn->watcher_outgoing = 0; | 898 conn->watcher_outgoing = 0; |
899 return; | 899 return; |
900 } | 900 } |
901 | 901 |
902 ret = send(conn->fd, conn->buffer_outgoing->outptr, writelen, 0); | 902 ret = send(conn->fd, conn->buffer_outgoing->outptr, writelen, 0); |
905 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | 905 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
906 /* No worries */ | 906 /* No worries */ |
907 return; | 907 return; |
908 | 908 |
909 /* Error! */ | 909 /* Error! */ |
910 gaim_input_remove(conn->watcher_outgoing); | 910 purple_input_remove(conn->watcher_outgoing); |
911 conn->watcher_outgoing = 0; | 911 conn->watcher_outgoing = 0; |
912 close(conn->fd); | 912 close(conn->fd); |
913 conn->fd = -1; | 913 conn->fd = -1; |
914 flap_connection_schedule_destroy(conn, | 914 flap_connection_schedule_destroy(conn, |
915 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno)); | 915 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno)); |
916 return; | 916 return; |
917 } | 917 } |
918 | 918 |
919 gaim_circ_buffer_mark_read(conn->buffer_outgoing, ret); | 919 purple_circ_buffer_mark_read(conn->buffer_outgoing, ret); |
920 } | 920 } |
921 | 921 |
922 static void | 922 static void |
923 flap_connection_send_byte_stream(ByteStream *bs, FlapConnection *conn, size_t count) | 923 flap_connection_send_byte_stream(ByteStream *bs, FlapConnection *conn, size_t count) |
924 { | 924 { |
931 | 931 |
932 if (count == 0) | 932 if (count == 0) |
933 return; | 933 return; |
934 | 934 |
935 /* Add everything to our outgoing buffer */ | 935 /* Add everything to our outgoing buffer */ |
936 gaim_circ_buffer_append(conn->buffer_outgoing, bs->data, count); | 936 purple_circ_buffer_append(conn->buffer_outgoing, bs->data, count); |
937 | 937 |
938 /* If we haven't already started writing stuff, then start the cycle */ | 938 /* If we haven't already started writing stuff, then start the cycle */ |
939 if ((conn->watcher_outgoing == 0) && (conn->fd != -1)) | 939 if ((conn->watcher_outgoing == 0) && (conn->fd != -1)) |
940 { | 940 { |
941 conn->watcher_outgoing = gaim_input_add(conn->fd, | 941 conn->watcher_outgoing = purple_input_add(conn->fd, |
942 GAIM_INPUT_WRITE, send_cb, conn); | 942 PURPLE_INPUT_WRITE, send_cb, conn); |
943 send_cb(conn, conn->fd, 0); | 943 send_cb(conn, conn->fd, 0); |
944 } | 944 } |
945 } | 945 } |
946 | 946 |
947 static void | 947 static void |