From f6fe5765d237919fea806b15fe9dd24ac5bb1b0a Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Mon, 24 Feb 2014 07:59:20 +0100 Subject: [PATCH] Fully working phone call support, might need some tweaks and checks --- loop.c | 16 ++++++++++++++-- queries.c | 32 ++++++++++++++++++++++++++++++++ queries.h | 1 + 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/loop.c b/loop.c index be76da8..3cce8e3 100644 --- a/loop.c +++ b/loop.c @@ -517,12 +517,18 @@ int loop (void) { do_send_code (default_username); char *code = 0; size_t size = 0; - printf ("Code from sms: "); + printf ("Code from sms (if you did not receive an SMS and want to be called, type 0): "); while (1) { if (net_getline (&code, &size) == -1) { perror ("getline()"); exit (EXIT_FAILURE); } + if (*code == '0') { + printf ("You typed 0, switching to phone system.\n"); + do_phone_call (default_username); + printf ("Calling you! Code: "); + continue; + } if (do_send_code_result (code) >= 0) { break; } @@ -563,12 +569,18 @@ int loop (void) { DC_working = DC_list[dc_working_num]; do_send_code (default_username); - printf ("Code from sms: "); + printf ("Code from sms (if you did not receive an SMS and want to be called, type 0): "); while (1) { if (net_getline (&code, &size) == -1) { perror ("getline()"); exit (EXIT_FAILURE); } + if (*code == '0') { + printf ("You typed 0, switching to phone system.\n"); + do_phone_call (default_username); + printf ("Calling you! Code: "); + continue; + } if (do_send_code_result_auth (code, first_name, last_name) >= 0) { break; } diff --git a/queries.c b/queries.c index 633f601..f7aa8e3 100644 --- a/queries.c +++ b/queries.c @@ -468,6 +468,38 @@ void do_send_code (const char *user) { net_loop (0, code_is_sent); assert (want_dc_num == -1); } + + +int phone_call_on_answer (struct query *q UU) { + fetch_bool (); + assert(1); + return 0; +} + +int phone_call_on_error (struct query *q UU, int error_code, int l, char *error) { + logprintf ( "error_code = %d, error = %.*s\n", error_code, l, error); + assert (0); + return 0; +} + +struct query_methods phone_call_methods = { + .on_answer = phone_call_on_answer, + .on_error = phone_call_on_error +}; + +void do_phone_call (const char *user) { + logprintf ("calling user\n"); + suser = tstrdup (user); + want_dc_num = 0; + clear_packet (); + do_insert_header (); + out_int (CODE_auth_send_call); + out_string (user); + out_string (phone_code_hash); + + logprintf ("do_phone_call: dc_num = %d\n", dc_working_num); + send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &phone_call_methods, 0); +} /* }}} */ /* {{{ Check phone */ diff --git a/queries.h b/queries.h index d631cd4..17c1e74 100644 --- a/queries.h +++ b/queries.h @@ -64,6 +64,7 @@ void work_timers (void); extern struct query_methods help_get_config_methods; void do_send_code (const char *user); +void do_phone_call (const char *user); int do_send_code_result (const char *code); double get_double_time (void);