comparison libpurple/connection.c @ 21355:fa3c4c5dea66

propagate from branch 'im.pidgin.pidgin.next.minor' (head 4018add8ebbf0e7dfc0fa002ebaeedb7048a26a6) to branch 'im.pidgin.cpw.resiak.disconnectreason' (head b9fff782d80fd2d1a999b82e31433db57c0c2db3)
author Will Thompson <will.thompson@collabora.co.uk>
date Fri, 12 Oct 2007 23:26:11 +0000
parents c560286daede
children 5a3242b676ad
comparison
equal deleted inserted replaced
21225:e967fd47baa5 21355:fa3c4c5dea66
486 } 486 }
487 487
488 void 488 void
489 purple_connection_error(PurpleConnection *gc, const char *text) 489 purple_connection_error(PurpleConnection *gc, const char *text)
490 { 490 {
491 /* prpls that have not been updated to use disconnection reasons will
492 * be setting wants_to_die before calling this function, so choose
493 * PURPLE_REASON_OTHER_ERROR (which is fatal) if it's true, and
494 * PURPLE_REASON_NETWORK_ERROR (which isn't) if not. See the
495 * documentation in connection.h.
496 */
497 PurpleDisconnectReason reason = gc->wants_to_die
498 ? PURPLE_REASON_OTHER_ERROR
499 : PURPLE_REASON_NETWORK_ERROR;
500 purple_connection_error_reason (gc, reason, text);
501 }
502
503 void
504 purple_connection_error_reason (PurpleConnection *gc,
505 PurpleDisconnectReason reason,
506 const char *description)
507 {
491 PurpleConnectionUiOps *ops; 508 PurpleConnectionUiOps *ops;
492 509
493 g_return_if_fail(gc != NULL); 510 g_return_if_fail(gc != NULL);
494 511 g_return_if_fail(reason < PURPLE_NUM_REASONS);
495 if (text == NULL) { 512
496 purple_debug_error("connection", "purple_connection_error: check `text != NULL' failed\n"); 513 if (description == NULL) {
497 text = _("Unknown error"); 514 purple_debug_error("connection", "purple_connection_error_reason: check `description != NULL' failed\n");
515 description = _("Unknown error");
498 } 516 }
499 517
500 /* If we've already got one error, we don't need any more */ 518 /* If we've already got one error, we don't need any more */
501 if (gc->disconnect_timeout) 519 if (gc->disconnect_timeout)
502 return; 520 return;
503 521
522 gc->wants_to_die = purple_connection_reason_is_fatal (reason);
523
504 ops = purple_connections_get_ui_ops(); 524 ops = purple_connections_get_ui_ops();
505 525
506 if (ops != NULL && ops->report_disconnect != NULL) 526 if (ops != NULL)
507 ops->report_disconnect(gc, text); 527 {
528 if (ops->report_disconnect_reason != NULL)
529 ops->report_disconnect_reason (gc, reason, description);
530 if (ops->report_disconnect != NULL)
531 ops->report_disconnect (gc, description);
532 }
508 533
509 gc->disconnect_timeout = purple_timeout_add(0, purple_connection_disconnect_cb, 534 gc->disconnect_timeout = purple_timeout_add(0, purple_connection_disconnect_cb,
510 purple_connection_get_account(gc)); 535 purple_connection_get_account(gc));
536 }
537
538 void
539 purple_connection_ssl_error (PurpleConnection *gc,
540 PurpleSslErrorType ssl_error)
541 {
542 PurpleDisconnectReason reason;
543
544 switch (ssl_error) {
545 case PURPLE_SSL_HANDSHAKE_FAILED:
546 case PURPLE_SSL_CONNECT_FAILED:
547 reason = PURPLE_REASON_ENCRYPTION_ERROR;
548 break;
549 case PURPLE_SSL_CERTIFICATE_INVALID:
550 /* TODO: maybe PURPLE_SSL_* should be more specific? */
551 reason = PURPLE_REASON_CERT_OTHER_ERROR;
552 break;
553 default:
554 g_assert_not_reached ();
555 reason = PURPLE_REASON_ENCRYPTION_ERROR;
556 }
557
558 purple_connection_error_reason (gc, reason, purple_ssl_strerror(ssl_error));
559 }
560
561 gboolean
562 purple_connection_reason_is_fatal (PurpleDisconnectReason reason)
563 {
564 switch (reason)
565 {
566 case PURPLE_REASON_NETWORK_ERROR:
567 case PURPLE_REASON_AUTHENTICATION_IMPOSSIBLE:
568 case PURPLE_REASON_CERT_NOT_PROVIDED:
569 case PURPLE_REASON_CERT_UNTRUSTED:
570 case PURPLE_REASON_CERT_EXPIRED:
571 case PURPLE_REASON_CERT_NOT_ACTIVATED:
572 case PURPLE_REASON_CERT_HOSTNAME_MISMATCH:
573 case PURPLE_REASON_CERT_FINGERPRINT_MISMATCH:
574 case PURPLE_REASON_CERT_SELF_SIGNED:
575 case PURPLE_REASON_CERT_OTHER_ERROR:
576 return FALSE;
577 case PURPLE_REASON_AUTHENTICATION_FAILED:
578 case PURPLE_REASON_NO_SSL_SUPPORT:
579 case PURPLE_REASON_ENCRYPTION_ERROR:
580 case PURPLE_REASON_NAME_IN_USE:
581 case PURPLE_REASON_INVALID_SETTINGS:
582 case PURPLE_REASON_OTHER_ERROR:
583 return TRUE;
584 default:
585 g_return_val_if_reached(TRUE);
586 }
511 } 587 }
512 588
513 void 589 void
514 purple_connections_disconnect_all(void) 590 purple_connections_disconnect_all(void)
515 { 591 {