Implement better fallback mode in case requests is missing

Open a dummy chat to query the user for the entered SMS code
This commit is contained in:
mjentsch 2014-11-26 09:40:13 +01:00
parent 50c52b091c
commit 69360b4f57
4 changed files with 21 additions and 19 deletions

View file

@ -259,7 +259,7 @@ static void code_auth_receive_result (struct tgl_state *TLS, void *extra, int su
}
}
static void request_code_entered (gpointer data, const gchar *code) {
void request_code_entered (gpointer data, const gchar *code) {
struct tgl_state *TLS = data;
telegram_conn *conn = TLS->ev_base;
char const *username = purple_account_get_username(conn->pa);
@ -299,16 +299,15 @@ static void request_code (struct tgl_state *TLS) {
"Telegram wants to verify your identity, please enter the code, that you have received via SMS.",
NULL, 0, 0, "code", "OK", G_CALLBACK(request_code_entered), "Cancel",
G_CALLBACK(request_code_canceled), conn->pa, NULL, NULL, TLS)) {
const char *sms = purple_account_get_string(tg_get_acc(TLS), "code", "");
if (*sms == '\0') {
const char *error = "Could not prompt for sms code, please set SMS code in account settings and reconnect.";
purple_connection_error_reason(conn->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, error);
purple_notify_error(_telegram_protocol, "Enter SMS code", "Enter SMS code", error);
return;
}
request_code_entered (TLS, sms);
purple_account_set_string(tg_get_acc(TLS), "code", "");
// purple request API is not available, so we create a new conversation (the Telegram system
// account "7770000") to prompt the user for the code
conn->in_fallback_chat = 1;
purple_connection_set_state (conn->gc, PURPLE_CONNECTED);
PurpleConversation *conv = purple_conversation_new (PURPLE_CONV_TYPE_IM, conn->pa, "777000");
purple_conversation_write (conv, "777000", "What is your SMS verification code?",
PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, 0);
}
}

View file

@ -28,4 +28,5 @@ void telegram_login (struct tgl_state *TLS);
PurpleConversation *chat_show (PurpleConnection *gc, int id);
int chat_add_message (struct tgl_state *TLS, struct tgl_message *M, char *text);
void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat);
void request_code_entered (gpointer data, const gchar *code);
#endif

View file

@ -627,6 +627,14 @@ static int tgprpl_send_im (PurpleConnection * gc, const char *who, const char *m
telegram_conn *conn = purple_connection_get_protocol_data(gc);
PurpleAccount *pa = conn->pa;
// this is part of a workaround to support clients without
// the request API (request.h), see telegram-base.c:request_code()
if (conn->in_fallback_chat) {
request_code_entered (conn->TLS, message);
conn->in_fallback_chat = 0;
return 1;
}
PurpleBuddy *b = purple_find_buddy (pa, who);
if (!b) {
@ -893,16 +901,9 @@ static PurplePluginProtocolInfo prpl_info = {
static void tgprpl_init (PurplePlugin *plugin) {
//PurpleAccountOption *option;
//GList *verification_values = NULL;
PurpleAccountOption *opt;
opt = purple_account_option_bool_new("Compatibility Mode (read SMS code from settings)",
"compat-verification", 0);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt);
opt = purple_account_option_string_new("SMS Code", "code", "");
opt = purple_account_option_bool_new("Fallback SMS verification", "compat-verification", 0);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt);
_telegram_protocol = plugin;

View file

@ -47,6 +47,7 @@ typedef struct {
GQueue *new_messages;
GHashTable *joining_chats;
guint timer;
int in_fallback_chat;
} telegram_conn;
struct download_desc {