Commit 77ab47b6 authored by Vysheng's avatar Vysheng

support for some error codes

parent 75b0f3d2
...@@ -1957,8 +1957,11 @@ void interpreter_ex (char *line UU, void *ex) { ...@@ -1957,8 +1957,11 @@ void interpreter_ex (char *line UU, void *ex) {
if (op == ca_none) { if (op == ca_none) {
next_token (); next_token ();
if (cur_token_end_str) { if (cur_token_end_str) {
int z;
for (z = 0; z < count; z ++) {
fun (args_num, args, ex); fun (args_num, args, ex);
} }
}
break; break;
} }
...@@ -1969,7 +1972,10 @@ void interpreter_ex (char *line UU, void *ex) { ...@@ -1969,7 +1972,10 @@ void interpreter_ex (char *line UU, void *ex) {
} else { } else {
args[args_num].flags = 1; args[args_num].flags = 1;
args[args_num ++].str = strndup (cur_token, cur_token_len); args[args_num ++].str = strndup (cur_token, cur_token_len);
int z;
for (z = 0; z < count; z ++) {
fun (args_num, args, ex); fun (args_num, args, ex);
}
break; break;
} }
} }
...@@ -1978,7 +1984,10 @@ void interpreter_ex (char *line UU, void *ex) { ...@@ -1978,7 +1984,10 @@ void interpreter_ex (char *line UU, void *ex) {
next_token (); next_token ();
if (period && cur_token_end_str) { if (period && cur_token_end_str) {
int z;
for (z = 0; z < count; z ++) {
fun (args_num, args, ex); fun (args_num, args, ex);
}
break; break;
} }
......
...@@ -94,7 +94,7 @@ struct query *tglq_query_get (long long id) { ...@@ -94,7 +94,7 @@ struct query *tglq_query_get (long long id) {
static int alarm_query (struct query *q) { static int alarm_query (struct query *q) {
assert (q); assert (q);
vlogprintf (E_DEBUG, "Alarm query %lld\n", q->msg_id); vlogprintf (E_DEBUG - 1, "Alarm query %lld\n", q->msg_id);
//q->ev.timeout = get_double_time () + QUERY_TIMEOUT; //q->ev.timeout = get_double_time () + QUERY_TIMEOUT;
//insert_event_timer (&q->ev); //insert_event_timer (&q->ev);
...@@ -118,7 +118,9 @@ static int alarm_query (struct query *q) { ...@@ -118,7 +118,9 @@ static int alarm_query (struct query *q) {
tglmp_encrypt_send_message (q->session->c, packet_buffer, packet_ptr - packet_buffer, q->flags & QUERY_FORCE_SEND); tglmp_encrypt_send_message (q->session->c, packet_buffer, packet_ptr - packet_buffer, q->flags & QUERY_FORCE_SEND);
} else { } else {
q->flags &= ~QUERY_ACK_RECEIVED; q->flags &= ~QUERY_ACK_RECEIVED;
if (tree_lookup_query (queries_tree, q)) {
queries_tree = tree_delete_query (queries_tree, q); queries_tree = tree_delete_query (queries_tree, q);
}
q->msg_id = tglmp_encrypt_send_message (q->session->c, q->data, q->data_len, (q->flags & QUERY_FORCE_SEND) | 1); q->msg_id = tglmp_encrypt_send_message (q->session->c, q->data, q->data_len, (q->flags & QUERY_FORCE_SEND) | 1);
queries_tree = tree_insert_query (queries_tree, q, lrand48 ()); queries_tree = tree_insert_query (queries_tree, q, lrand48 ());
q->session_id = q->session->session_id; q->session_id = q->session->session_id;
...@@ -219,15 +221,27 @@ void tglq_query_error (long long id) { ...@@ -219,15 +221,27 @@ void tglq_query_error (long long id) {
event_del (q->ev); event_del (q->ev);
} }
queries_tree = tree_delete_query (queries_tree, q); queries_tree = tree_delete_query (queries_tree, q);
if (q->methods && q->methods->on_error) { int res = 0;
q->methods->on_error (q, error_code, error_len, error); if (q->methods && q->methods->on_error && error_code != 500) {
res = q->methods->on_error (q, error_code, error_len, error);
} else { } else {
vlogprintf ( E_WARNING, "error for query #%lld: #%d :%.*s\n", id, error_code, error_len, error); if (error_code == 420 || error_code == 500) {
assert (!strncmp (error, "FLOOD_WAIT_", 11));
int wait = atoll (error + 11);
q->flags &= ~QUERY_ACK_RECEIVED;
static struct timeval ptimeout;
ptimeout.tv_sec = wait;
event_add (q->ev, &ptimeout);
q->session_id = 0;
res = 1;
}
} }
if (res <= 0) {
tfree (q->data, q->data_len * 4); tfree (q->data, q->data_len * 4);
event_free (q->ev); event_free (q->ev);
tfree (q, sizeof (*q)); tfree (q, sizeof (*q));
} }
}
tgl_state.active_queries --; tgl_state.active_queries --;
} }
...@@ -914,7 +928,17 @@ static int msg_send_on_answer (struct query *q UU) { ...@@ -914,7 +928,17 @@ static int msg_send_on_answer (struct query *q UU) {
} }
static int msg_send_on_error (struct query *q, int error_code, int error_len, char *error) { static int msg_send_on_error (struct query *q, int error_code, int error_len, char *error) {
vlogprintf (E_WARNING, "error for query #%lld: #%d :%.*s\n", q->msg_id, error_code, error_len, error); //vlogprintf (E_WARNING, "error for query #%lld: #%d :%.*s\n", q->msg_id, error_code, error_len, error);
if (error_code == 420) {
assert (!strncmp (error, "FLOOD_WAIT_", 11));
int wait = atoll (error + 11);
q->flags &= ~QUERY_ACK_RECEIVED;
static struct timeval ptimeout;
ptimeout.tv_sec = wait;
event_add (q->ev, &ptimeout);
q->session_id = 0;
return 1;
}
long long x = *(long long *)q->extra; long long x = *(long long *)q->extra;
tfree (q->extra, 8); tfree (q->extra, 8);
struct tgl_message *M = tgl_message_get (x); struct tgl_message *M = tgl_message_get (x);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment