diff --git a/telegram-base.c b/telegram-base.c index 58026c7..9f52841 100644 --- a/telegram-base.c +++ b/telegram-base.c @@ -163,6 +163,15 @@ void read_dc (struct tgl_state *TLS, int auth_file_fd, int id, unsigned ver) { bl_do_dc_signed (TLS, id); } +int error_if_val_false (struct tgl_state *TLS, int val, const char *msg) { + if (!val) { + telegram_conn *conn = TLS->ev_base; + purple_connection_error_reason (conn->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, msg); + return 1; + } + return 0; +} + void empty_auth_file (struct tgl_state *TLS) { if (TLS->test_mode) { bl_do_dc_option (TLS, 1, 0, "", strlen (TG_SERVER_TEST_1), TG_SERVER_TEST_1, 443); @@ -225,8 +234,9 @@ void read_auth_file (struct tgl_state *TLS) { void telegram_export_authorization (struct tgl_state *TLS); void export_auth_callback (struct tgl_state *TLS, void *extra, int success) { - assert (success); - telegram_export_authorization (TLS); + if (!error_if_val_false(TLS, success, "Authentication Export failed.")) { + telegram_export_authorization (TLS); + } } void telegram_export_authorization (struct tgl_state *TLS) { @@ -341,14 +351,14 @@ static void request_name_and_code (struct tgl_state *TLS) { } static void sign_in_callback (struct tgl_state *TLS, void *extra, int success, int registered, const char *mhash) { - assert (success); // TODO proper error handle telegram_conn *conn = TLS->ev_base; - conn->hash = strdup (mhash); - - if (registered) { - request_code (TLS); - } else { - request_name_and_code (TLS); + if (!error_if_val_false (TLS, success, "Invalid or non-existing phone number.")) { + conn->hash = strdup (mhash); + if (registered) { + request_code (TLS); + } else { + request_name_and_code (TLS); + } } }