Fully working phone call support, might need some tweaks and checks

This commit is contained in:
Jeroen Bobbeldijk 2014-02-24 07:59:20 +01:00
parent 98d638b7b5
commit f6fe5765d2
3 changed files with 47 additions and 2 deletions

16
loop.c
View File

@ -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;
}

View File

@ -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 */

View File

@ -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);