Mercurial > pidgin
comparison libpurple/connection.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
| author | Elliott Sales de Andrade <qulogic@pidgin.im> |
|---|---|
| date | Sat, 02 Jun 2012 02:30:49 +0000 |
| parents | 50cd80d3554e |
| children |
comparison
equal
deleted
inserted
replaced
| 32818:01ff09d4a463 | 32819:2c6510167895 |
|---|---|
| 90 gc->keepalive = 0; | 90 gc->keepalive = 0; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 void | 94 void |
| 95 purple_connection_new(PurpleAccount *account, gboolean regist, const char *password) | |
| 96 { | |
| 97 _purple_connection_new(account, regist, password); | |
| 98 } | |
| 99 | |
| 100 void | |
| 101 _purple_connection_new(PurpleAccount *account, gboolean regist, const char *password) | 95 _purple_connection_new(PurpleAccount *account, gboolean regist, const char *password) |
| 102 { | 96 { |
| 103 PurpleConnection *gc; | 97 PurpleConnection *gc; |
| 104 PurplePlugin *prpl; | 98 PurplePlugin *prpl; |
| 105 PurplePluginProtocolInfo *prpl_info; | 99 PurplePluginProtocolInfo *prpl_info; |
| 169 | 163 |
| 170 purple_signal_emit(purple_accounts_get_handle(), "account-connecting", account); | 164 purple_signal_emit(purple_accounts_get_handle(), "account-connecting", account); |
| 171 prpl_info->login(account); | 165 prpl_info->login(account); |
| 172 } | 166 } |
| 173 } | 167 } |
| 174 void | |
| 175 purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data) | |
| 176 { | |
| 177 _purple_connection_new_unregister(account, password, cb, user_data); | |
| 178 } | |
| 179 | 168 |
| 180 void | 169 void |
| 181 _purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data) | 170 _purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data) |
| 182 { | 171 { |
| 183 /* Lots of copy/pasted code to avoid API changes. You might want to integrate that into the previous function when posssible. */ | 172 /* Lots of copy/pasted code to avoid API changes. You might want to integrate that into the previous function when posssible. */ |
| 229 purple_signal_emit(purple_connections_get_handle(), "signing-on", gc); | 218 purple_signal_emit(purple_connections_get_handle(), "signing-on", gc); |
| 230 | 219 |
| 231 purple_debug_info("connection", "Unregistering. gc = %p\n", gc); | 220 purple_debug_info("connection", "Unregistering. gc = %p\n", gc); |
| 232 | 221 |
| 233 prpl_info->unregister_user(account, cb, user_data); | 222 prpl_info->unregister_user(account, cb, user_data); |
| 234 } | |
| 235 | |
| 236 void | |
| 237 purple_connection_destroy(PurpleConnection *gc) | |
| 238 { | |
| 239 _purple_connection_destroy(gc); | |
| 240 } | 223 } |
| 241 | 224 |
| 242 void | 225 void |
| 243 _purple_connection_destroy(PurpleConnection *gc) | 226 _purple_connection_destroy(PurpleConnection *gc) |
| 244 { | 227 { |
| 402 ops->disconnected(gc); | 385 ops->disconnected(gc); |
| 403 } | 386 } |
| 404 } | 387 } |
| 405 | 388 |
| 406 void | 389 void |
| 390 purple_connection_set_flags(PurpleConnection *gc, PurpleConnectionFlags flags) | |
| 391 { | |
| 392 g_return_if_fail(gc != NULL); | |
| 393 | |
| 394 gc->flags = flags; | |
| 395 } | |
| 396 | |
| 397 void | |
| 407 purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account) | 398 purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account) |
| 408 { | 399 { |
| 409 g_return_if_fail(gc != NULL); | 400 g_return_if_fail(gc != NULL); |
| 410 g_return_if_fail(account != NULL); | 401 g_return_if_fail(account != NULL); |
| 411 | 402 |
| 434 g_return_val_if_fail(gc != NULL, PURPLE_DISCONNECTED); | 425 g_return_val_if_fail(gc != NULL, PURPLE_DISCONNECTED); |
| 435 | 426 |
| 436 return gc->state; | 427 return gc->state; |
| 437 } | 428 } |
| 438 | 429 |
| 430 PurpleConnectionFlags | |
| 431 purple_connection_get_flags(const PurpleConnection *gc) | |
| 432 { | |
| 433 g_return_val_if_fail(gc != NULL, 0); | |
| 434 | |
| 435 return gc->flags; | |
| 436 } | |
| 437 | |
| 439 PurpleAccount * | 438 PurpleAccount * |
| 440 purple_connection_get_account(const PurpleConnection *gc) | 439 purple_connection_get_account(const PurpleConnection *gc) |
| 441 { | 440 { |
| 442 g_return_val_if_fail(gc != NULL, NULL); | 441 g_return_val_if_fail(gc != NULL, NULL); |
| 443 | 442 |
| 455 const char * | 454 const char * |
| 456 purple_connection_get_password(const PurpleConnection *gc) | 455 purple_connection_get_password(const PurpleConnection *gc) |
| 457 { | 456 { |
| 458 g_return_val_if_fail(gc != NULL, NULL); | 457 g_return_val_if_fail(gc != NULL, NULL); |
| 459 | 458 |
| 460 return gc->password ? gc->password : gc->account->password; | 459 return gc->password ? gc->password : purple_account_get_password(gc->account); |
| 461 } | 460 } |
| 462 | 461 |
| 463 const char * | 462 const char * |
| 464 purple_connection_get_display_name(const PurpleConnection *gc) | 463 purple_connection_get_display_name(const PurpleConnection *gc) |
| 465 { | 464 { |
| 526 | 525 |
| 527 return FALSE; | 526 return FALSE; |
| 528 } | 527 } |
| 529 | 528 |
| 530 void | 529 void |
| 531 purple_connection_error(PurpleConnection *gc, const char *text) | 530 purple_connection_error (PurpleConnection *gc, |
| 532 { | |
| 533 /* prpls that have not been updated to use disconnection reasons will | |
| 534 * be setting wants_to_die before calling this function, so choose | |
| 535 * PURPLE_CONNECTION_ERROR_OTHER_ERROR (which is fatal) if it's true, | |
| 536 * and PURPLE_CONNECTION_ERROR_NETWORK_ERROR (which isn't) if not. See | |
| 537 * the documentation in connection.h. | |
| 538 */ | |
| 539 PurpleConnectionError reason = gc->wants_to_die | |
| 540 ? PURPLE_CONNECTION_ERROR_OTHER_ERROR | |
| 541 : PURPLE_CONNECTION_ERROR_NETWORK_ERROR; | |
| 542 purple_connection_error_reason (gc, reason, text); | |
| 543 } | |
| 544 | |
| 545 void | |
| 546 purple_connection_error_reason (PurpleConnection *gc, | |
| 547 PurpleConnectionError reason, | 531 PurpleConnectionError reason, |
| 548 const char *description) | 532 const char *description) |
| 549 { | 533 { |
| 550 PurpleConnectionUiOps *ops; | 534 PurpleConnectionUiOps *ops; |
| 551 | 535 |
| 555 * connection.h; if other reasons are added after it, this check should | 539 * connection.h; if other reasons are added after it, this check should |
| 556 * be updated. | 540 * be updated. |
| 557 */ | 541 */ |
| 558 if (reason > PURPLE_CONNECTION_ERROR_OTHER_ERROR) { | 542 if (reason > PURPLE_CONNECTION_ERROR_OTHER_ERROR) { |
| 559 purple_debug_error("connection", | 543 purple_debug_error("connection", |
| 560 "purple_connection_error_reason: reason %u isn't a " | 544 "purple_connection_error: reason %u isn't a " |
| 561 "valid reason\n", reason); | 545 "valid reason\n", reason); |
| 562 reason = PURPLE_CONNECTION_ERROR_OTHER_ERROR; | 546 reason = PURPLE_CONNECTION_ERROR_OTHER_ERROR; |
| 563 } | 547 } |
| 564 | 548 |
| 565 if (description == NULL) { | 549 if (description == NULL) { |
| 566 purple_debug_error("connection", "purple_connection_error_reason called with NULL description\n"); | 550 purple_debug_error("connection", "purple_connection_error called with NULL description\n"); |
| 567 description = _("Unknown error"); | 551 description = _("Unknown error"); |
| 568 } | 552 } |
| 569 | 553 |
| 570 /* If we've already got one error, we don't need any more */ | 554 /* If we've already got one error, we don't need any more */ |
| 571 if (gc->disconnect_timeout > 0) | 555 if (gc->disconnect_timeout > 0) |
| 576 purple_debug_info("connection", "Connection error on %p (reason: %u description: %s)\n", | 560 purple_debug_info("connection", "Connection error on %p (reason: %u description: %s)\n", |
| 577 gc, reason, description); | 561 gc, reason, description); |
| 578 | 562 |
| 579 ops = purple_connections_get_ui_ops(); | 563 ops = purple_connections_get_ui_ops(); |
| 580 | 564 |
| 581 if (ops != NULL) | 565 if (ops && ops->report_disconnect) |
| 582 { | 566 ops->report_disconnect(gc, reason, description); |
| 583 if (ops->report_disconnect_reason != NULL) | |
| 584 ops->report_disconnect_reason (gc, reason, description); | |
| 585 if (ops->report_disconnect != NULL) | |
| 586 ops->report_disconnect (gc, description); | |
| 587 } | |
| 588 | 567 |
| 589 purple_signal_emit(purple_connections_get_handle(), "connection-error", | 568 purple_signal_emit(purple_connections_get_handle(), "connection-error", |
| 590 gc, reason, description); | 569 gc, reason, description); |
| 591 | 570 |
| 592 gc->disconnect_timeout = purple_timeout_add(0, purple_connection_disconnect_cb, | 571 gc->disconnect_timeout = purple_timeout_add(0, purple_connection_disconnect_cb, |
| 613 default: | 592 default: |
| 614 g_assert_not_reached (); | 593 g_assert_not_reached (); |
| 615 reason = PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR; | 594 reason = PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR; |
| 616 } | 595 } |
| 617 | 596 |
| 618 purple_connection_error_reason (gc, reason, | 597 purple_connection_error (gc, reason, |
| 619 purple_ssl_strerror(ssl_error)); | 598 purple_ssl_strerror(ssl_error)); |
| 620 } | 599 } |
| 621 | 600 |
| 622 gboolean | 601 gboolean |
| 623 purple_connection_error_is_fatal (PurpleConnectionError reason) | 602 purple_connection_error_is_fatal (PurpleConnectionError reason) |
| 646 default: | 625 default: |
| 647 g_return_val_if_reached(TRUE); | 626 g_return_val_if_reached(TRUE); |
| 648 } | 627 } |
| 649 } | 628 } |
| 650 | 629 |
| 630 void purple_connection_update_last_received(PurpleConnection *gc) | |
| 631 { | |
| 632 g_return_if_fail(gc != NULL); | |
| 633 | |
| 634 gc->last_received = time(NULL); | |
| 635 } | |
| 636 | |
| 651 void | 637 void |
| 652 purple_connections_disconnect_all(void) | 638 purple_connections_disconnect_all(void) |
| 653 { | 639 { |
| 654 GList *l; | 640 GList *l; |
| 655 PurpleConnection *gc; | 641 PurpleConnection *gc; |
