From 03b1dd86395032c3598ea06274a89019e6f55cf2 Mon Sep 17 00:00:00 2001 From: Davide Pucci Date: Mon, 10 Nov 2014 17:39:47 +0100 Subject: [PATCH 1/4] tg: interface.c: alphabetical rearrangement of available commands --- interface.c | 110 ++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/interface.c b/interface.c index ec2fe64..0da4468 100644 --- a/interface.c +++ b/interface.c @@ -1075,66 +1075,66 @@ void do_send_location (int arg_num, struct arg args[], struct in_ev *ev) { struct command commands[] = { - {"help", {ca_none}, do_help, "help\tPrints this help"}, - {"contact_list", {ca_none}, do_contact_list, "contact_list\tPrints contact list"}, - {"stats", {ca_none}, do_stats, "stats\tFor debug purpose"}, - {"history", {ca_peer, ca_number | ca_optional, ca_number | ca_optional, ca_none}, do_history, "history [limit] [offset]\tPrints messages with this peer (most recent message lower). Also marks messages as read"}, - {"dialog_list", {ca_none}, do_dialog_list, "dialog_list\tList of last conversations"}, - {"send_photo", {ca_peer, ca_file_name_end, ca_none}, do_send_photo, "send_photo \tSends photo to peer"}, - {"send_video", {ca_peer, ca_file_name_end, ca_none}, do_send_video, "send_video \tSends video to peer"}, - {"send_audio", {ca_peer, ca_file_name_end, ca_none}, do_send_audio, "send_audio \tSends audio to peer"}, - {"send_document", {ca_peer, ca_file_name_end, ca_none}, do_send_document, "send_document \tSends document to peer"}, - {"send_text", {ca_peer, ca_file_name_end, ca_none}, do_send_text, "send_text \tSends contents of text file as plain text message"}, - {"chat_info", {ca_chat, ca_none}, do_chat_info, "chat_info \tPrints info about chat (id, members, admin, etc.)"}, - {"user_info", {ca_user, ca_none}, do_user_info, "user_info \tPrints info about user (id, last online, phone)"}, - {"fwd", {ca_peer, ca_number, ca_none}, do_fwd, "fwd \tForwards message to peer. Forward to secret chats is forbidden"}, - {"fwd_media", {ca_peer, ca_number, ca_none}, do_fwd_media, "fwd \tForwards message media to peer. Forward to secret chats is forbidden. Result slightly differs from fwd"}, - {"msg", {ca_peer, ca_string_end, ca_none}, do_msg, "msg \tSends text message to peer"}, - {"rename_chat", {ca_chat, ca_string_end, ca_none}, do_rename_chat, "rename_chat \tRenames chat"}, - {"load_photo", {ca_number, ca_none}, do_load_photo, "load_photo \tDownloads file to downloads dirs. Prints file name after download end"}, - {"load_video", {ca_number, ca_none}, do_load_video, "load_video \tDownloads file to downloads dirs. Prints file name after download end"}, - {"load_audio", {ca_number, ca_none}, do_load_audio, "load_audio \tDownloads file to downloads dirs. Prints file name after download end"}, - {"load_document", {ca_number, ca_none}, do_load_document, "load_document \tDownloads file to downloads dirs. Prints file name after download end"}, - {"load_video_thumb", {ca_number, ca_none}, do_load_video_thumb, "load_video_thumb \tDownloads file to downloads dirs. Prints file name after download end"}, - {"load_document_thumb", {ca_number, ca_none}, do_load_document_thumb, "load_document_thumb \tDownloads file to downloads dirs. Prints file name after download end"}, - {"view_photo", {ca_number, ca_none}, do_open_photo, "view_photo \tDownloads file to downloads dirs. Then tries to open it with system default action"}, - {"view_video", {ca_number, ca_none}, do_open_video, "view_video \tDownloads file to downloads dirs. Then tries to open it with system default action"}, - {"view_audio", {ca_number, ca_none}, do_open_audio, "view_audio \tDownloads file to downloads dirs. Then tries to open it with system default action"}, - {"view_document", {ca_number, ca_none}, do_open_document, "view_document \tDownloads file to downloads dirs. Then tries to open it with system default action"}, - {"view_video_thumb", {ca_number, ca_none}, do_open_video_thumb, "view_video_thumb \tDownloads file to downloads dirs. Then tries to open it with system default action"}, - {"view_document_thumb", {ca_number, ca_none}, do_open_document_thumb, "view_document_thumb \tDownloads file to downloads dirs. Then tries to open it with system default action"}, + {"accept_secret_chat", {ca_secret_chat, ca_none}, do_accept_secret_chat, "accept_secret_chat \tAccepts secret chat. Only useful with -E option"}, {"add_contact", {ca_string, ca_string, ca_string, ca_none}, do_add_contact, "add_contact \tTries to add user to contact list"}, - {"del_contact", {ca_user, ca_none}, do_del_contact, "del_contact \tDeletes contact from contact list"}, - {"rename_contact", {ca_user, ca_string, ca_string, ca_none}, do_rename_contact, "rename_contact \tRenames contact"}, - {"show_license", {ca_none}, do_show_license, "show_license\tPrints contents of GPL license"}, - {"search", {ca_peer | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_string_end}, do_search, "search [peer] [limit] [from] [to] [offset] pattern\tSearch for pattern in messages from date from to date to (unixtime) in messages with peer (if peer not present, in all messages)"}, - {"mark_read", {ca_peer, ca_none}, do_mark_read, "mark_read \tMarks messages with peer as read"}, - {"contact_search", {ca_string, ca_number | ca_optional, ca_none}, do_contact_search, "contact_search username [limit]\tSearches contacts by username"}, - {"visualize_key", {ca_secret_chat, ca_none}, do_visualize_key, "visualize_key \tPrints visualization of encryption key (first 16 bytes sha1 of it in fact}"}, - {"create_secret_chat", {ca_user, ca_none}, do_create_secret_chat, "create_secret_chat \tStarts creation of secret chat"}, {"chat_add_user", {ca_chat, ca_user, ca_number | ca_optional, ca_none}, do_chat_add_user, "chat_add_user [msgs-to-forward]\tAdds user to chat. Sends him last msgs-to-forward message from this chat. Default 100"}, {"chat_del_user", {ca_chat, ca_user, ca_none}, do_chat_del_user, "chat_del_user \tDeletes user from chat"}, + {"chat_info", {ca_chat, ca_none}, do_chat_info, "chat_info \tPrints info about chat (id, members, admin, etc.)"}, + {"chat_set_photo", {ca_chat, ca_file_name_end, ca_none}, do_chat_set_photo, "chat_set_photo \tSets chat photo. Photo will be cropped to square"}, + {"chat_with_peer", {ca_peer, ca_none}, do_chat_with_peer, "chat_with_peer \tInterface option. All input will be treated as messages to this peer. Type /quit to end this mode"}, + {"clear", {ca_none}, do_clear, "clear\tClears all data and exits. For debug."}, + {"contact_list", {ca_none}, do_contact_list, "contact_list\tPrints contact list"}, + {"contact_search", {ca_string, ca_number | ca_optional, ca_none}, do_contact_search, "contact_search username [limit]\tSearches contacts by username"}, + {"create_group_chat", {ca_string, ca_user, ca_period, ca_none}, do_create_group_chat, "create_group_chat +\tCreates group chat with users"}, + {"create_secret_chat", {ca_user, ca_none}, do_create_secret_chat, "create_secret_chat \tStarts creation of secret chat"}, + {"del_contact", {ca_user, ca_none}, do_del_contact, "del_contact \tDeletes contact from contact list"}, + {"delete_msg", {ca_number, ca_none}, do_delete_msg, "delete_msg \tDeletes message"}, + {"dialog_list", {ca_none}, do_dialog_list, "dialog_list\tList of last conversations"}, + {"export_card", {ca_none}, do_export_card, "export_card\tPrints card that can be imported by another user with import_card method"}, + {"fwd", {ca_peer, ca_number, ca_none}, do_fwd, "fwd \tForwards message to peer. Forward to secret chats is forbidden"}, + {"fwd_media", {ca_peer, ca_number, ca_none}, do_fwd_media, "fwd \tForwards message media to peer. Forward to secret chats is forbidden. Result slightly differs from fwd"}, + {"help", {ca_none}, do_help, "help\tPrints this help"}, + {"history", {ca_peer, ca_number | ca_optional, ca_number | ca_optional, ca_none}, do_history, "history [limit] [offset]\tPrints messages with this peer (most recent message lower). Also marks messages as read"}, + {"import_card", {ca_string, ca_none}, do_import_card, "import_card \tGets user by card and prints it name. You can then send messages to him as usual"}, + {"load_audio", {ca_number, ca_none}, do_load_audio, "load_audio \tDownloads file to downloads dirs. Prints file name after download end"}, + {"load_document", {ca_number, ca_none}, do_load_document, "load_document \tDownloads file to downloads dirs. Prints file name after download end"}, + {"load_document_thumb", {ca_number, ca_none}, do_load_document_thumb, "load_document_thumb \tDownloads file to downloads dirs. Prints file name after download end"}, + {"load_photo", {ca_number, ca_none}, do_load_photo, "load_photo \tDownloads file to downloads dirs. Prints file name after download end"}, + {"load_video", {ca_number, ca_none}, do_load_video, "load_video \tDownloads file to downloads dirs. Prints file name after download end"}, + {"load_video_thumb", {ca_number, ca_none}, do_load_video_thumb, "load_video_thumb \tDownloads file to downloads dirs. Prints file name after download end"}, + {"main_session", {ca_none}, do_main_session, "main_session\tSends updates to this connection (or terminal). Useful only with listening socket"}, + {"mark_read", {ca_peer, ca_none}, do_mark_read, "mark_read \tMarks messages with peer as read"}, + {"msg", {ca_peer, ca_string_end, ca_none}, do_msg, "msg \tSends text message to peer"}, + {"quit", {ca_none}, do_quit, "quit\tQuits immediately"}, + {"rename_chat", {ca_chat, ca_string_end, ca_none}, do_rename_chat, "rename_chat \tRenames chat"}, + {"rename_contact", {ca_user, ca_string, ca_string, ca_none}, do_rename_contact, "rename_contact \tRenames contact"}, + {"restore_msg", {ca_number, ca_none}, do_restore_msg, "restore_msg \tRestores message. Only available shortly (one hour?) after deletion"}, + {"safe_quit", {ca_none}, do_safe_quit, "safe_quit\tWaits for all queries to end, then quits"}, + {"search", {ca_peer | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_string_end}, do_search, "search [peer] [limit] [from] [to] [offset] pattern\tSearch for pattern in messages from date from to date to (unixtime) in messages with peer (if peer not present, in all messages)"}, + {"send_audio", {ca_peer, ca_file_name_end, ca_none}, do_send_audio, "send_audio \tSends audio to peer"}, + {"send_contact", {ca_peer, ca_string, ca_string, ca_string, ca_none}, do_send_contact, "send_contact \tSends contact (not necessary telegram user)"}, + {"send_document", {ca_peer, ca_file_name_end, ca_none}, do_send_document, "send_document \tSends document to peer"}, + {"send_location", {ca_peer, ca_double, ca_double, ca_none}, do_send_location, "send_location \tSends geo location"}, + {"send_photo", {ca_peer, ca_file_name_end, ca_none}, do_send_photo, "send_photo \tSends photo to peer"}, + {"send_text", {ca_peer, ca_file_name_end, ca_none}, do_send_text, "send_text \tSends contents of text file as plain text message"}, + {"send_video", {ca_peer, ca_file_name_end, ca_none}, do_send_video, "send_video \tSends video to peer"}, + {"set", {ca_string, ca_number, ca_none}, do_set, "set \tSets value of param. Currently available: log_level, debug_verbosity, alarm, msg_num"}, + {"set_profile_name", {ca_string, ca_string, ca_none}, do_set_profile_name, "set_profile_name \tSets profile name."}, + {"set_profile_photo", {ca_file_name_end, ca_none}, do_set_profile_photo, "set_profile_photo \tSets profile photo. Photo will be cropped to square"}, + {"set_ttl", {ca_secret_chat, ca_number, ca_none}, do_set_ttl, "set_ttl \tSets secret chat ttl. Client itself ignores ttl"}, + {"set_username", {ca_string, ca_none}, do_set_username, "set_username \tSets username."}, + {"show_license", {ca_none}, do_show_license, "show_license\tPrints contents of GPL license"}, + {"stats", {ca_none}, do_stats, "stats\tFor debug purpose"}, {"status_online", {ca_none}, do_status_online, "status_online\tSets status as online"}, {"status_offline", {ca_none}, do_status_offline, "status_offline\tSets status as offline"}, - {"quit", {ca_none}, do_quit, "quit\tQuits immediately"}, - {"safe_quit", {ca_none}, do_safe_quit, "safe_quit\tWaits for all queries to end, then quits"}, - {"set", {ca_string, ca_number, ca_none}, do_set, "set \tSets value of param. Currently available: log_level, debug_verbosity, alarm, msg_num"}, - {"chat_with_peer", {ca_peer, ca_none}, do_chat_with_peer, "chat_with_peer \tInterface option. All input will be treated as messages to this peer. Type /quit to end this mode"}, - {"delete_msg", {ca_number, ca_none}, do_delete_msg, "delete_msg \tDeletes message"}, - {"restore_msg", {ca_number, ca_none}, do_restore_msg, "restore_msg \tRestores message. Only available shortly (one hour?) after deletion"}, - {"create_group_chat", {ca_string, ca_user, ca_period, ca_none}, do_create_group_chat, "create_group_chat +\tCreates group chat with users"}, - {"chat_set_photo", {ca_chat, ca_file_name_end, ca_none}, do_chat_set_photo, "chat_set_photo \tSets chat photo. Photo will be cropped to square"}, - {"set_profile_photo", {ca_file_name_end, ca_none}, do_set_profile_photo, "set_profile_photo \tSets profile photo. Photo will be cropped to square"}, - {"set_profile_name", {ca_string, ca_string, ca_none}, do_set_profile_name, "set_profile_name \tSets profile name."}, - {"set_username", {ca_string, ca_none}, do_set_username, "set_username \tSets username."}, - {"accept_secret_chat", {ca_secret_chat, ca_none}, do_accept_secret_chat, "accept_secret_chat \tAccepts secret chat. Only useful with -E option"}, - {"set_ttl", {ca_secret_chat, ca_number, ca_none}, do_set_ttl, "set_ttl \tSets secret chat ttl. Client itself ignores ttl"}, - {"export_card", {ca_none}, do_export_card, "export_card\tPrints card that can be imported by another user with import_card method"}, - {"import_card", {ca_string, ca_none}, do_import_card, "import_card \tGets user by card and prints it name. You can then send messages to him as usual"}, - {"send_contact", {ca_peer, ca_string, ca_string, ca_string, ca_none}, do_send_contact, "send_contact \tSends contact (not necessary telegram user)"}, - {"main_session", {ca_none}, do_main_session, "main_session\tSends updates to this connection (or terminal). Useful only with listening socket"}, - {"clear", {ca_none}, do_clear, "clear\tClears all data and exits. For debug."}, - {"send_location", {ca_peer, ca_double, ca_double, ca_none}, do_send_location, "send_location \tSends geo location"}, + {"user_info", {ca_user, ca_none}, do_user_info, "user_info \tPrints info about user (id, last online, phone)"}, + {"view_audio", {ca_number, ca_none}, do_open_audio, "view_audio \tDownloads file to downloads dirs. Then tries to open it with system default action"}, + {"view_document", {ca_number, ca_none}, do_open_document, "view_document \tDownloads file to downloads dirs. Then tries to open it with system default action"}, + {"view_document_thumb", {ca_number, ca_none}, do_open_document_thumb, "view_document_thumb \tDownloads file to downloads dirs. Then tries to open it with system default action"}, + {"view_photo", {ca_number, ca_none}, do_open_photo, "view_photo \tDownloads file to downloads dirs. Then tries to open it with system default action"}, + {"view_video", {ca_number, ca_none}, do_open_video, "view_video \tDownloads file to downloads dirs. Then tries to open it with system default action"}, + {"view_video_thumb", {ca_number, ca_none}, do_open_video_thumb, "view_video_thumb \tDownloads file to downloads dirs. Then tries to open it with system default action"}, + {"visualize_key", {ca_secret_chat, ca_none}, do_visualize_key, "visualize_key \tPrints visualization of encryption key (first 16 bytes sha1 of it in fact}"}, {0, {ca_none}, 0, ""} }; From 862ae34ba8c0e014c4c27163ca76b6a5e762725e Mon Sep 17 00:00:00 2001 From: Vysheng Date: Tue, 11 Nov 2014 13:33:03 +0300 Subject: [PATCH 2/4] Added partial support for action resend. Fix crush on incorrect encrypted message in lua mode --- encrypted_scheme17.tl | 1 + interface.c | 3 +++ lua-tg.c | 3 ++- structures.c | 58 ++++++++++++++++++++++++------------------- tgl-layout.h | 5 ++++ 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/encrypted_scheme17.tl b/encrypted_scheme17.tl index cc4a76d..95e661b 100644 --- a/encrypted_scheme17.tl +++ b/encrypted_scheme17.tl @@ -24,6 +24,7 @@ decryptedMessageActionScreenshotMessages#8ac1f475 random_ids:Vector = Decr decryptedMessageActionFlushHistory#6719e45c = DecryptedMessageAction; decryptedMessageActionNotifyLayer#f3048883 layer:int = DecryptedMessageAction; +decryptedMessageActionResend#511110b0 start_seq_no:int end_seq_no:int = DecryptedMessageAction; decryptedMessageActionTyping#ccb27641 action:SendMessageAction = DecryptedMessageAction; diff --git a/interface.c b/interface.c index ec2fe64..b5efc47 100644 --- a/interface.c +++ b/interface.c @@ -2612,6 +2612,9 @@ void print_service_message (struct in_ev *ev, struct tgl_message *M) { case tgl_message_action_flush_history: mprintf (ev, " cleared history\n"); break; + case tgl_message_action_resend: + mprintf (ev, " resend query\n"); + break; case tgl_message_action_notify_layer: mprintf (ev, " updated layer to %d\n", M->action.layer); break; diff --git a/lua-tg.c b/lua-tg.c index c1b2628..f27ccb0 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -287,7 +287,7 @@ void push_media (struct tgl_message_media *M) { } } -void push_message (struct tgl_message *M) { +void push_message (struct tgl_message *M) { assert (M); my_lua_checkstack (luaState, 10); lua_newtable (luaState); @@ -295,6 +295,7 @@ void push_message (struct tgl_message *M) { static char s[30]; snprintf (s, 30, "%lld", M->id); lua_add_string_field ("id", s); + if (!(M->flags & FLAG_CREATED)) { return; } lua_add_num_field ("flags", M->flags); if (tgl_get_peer_type (M->fwd_from_id)) { diff --git a/structures.c b/structures.c index c459915..ce3473a 100644 --- a/structures.c +++ b/structures.c @@ -1010,6 +1010,11 @@ void tglf_fetch_message_action_encrypted (struct tgl_state *TLS, struct tgl_mess M->type = tgl_message_action_typing; M->typing = tglf_fetch_typing (); break; + case CODE_decrypted_message_action_resend: + M->type = tgl_message_action_resend; + M->start_seq_no = fetch_int (); + M->end_seq_no = fetch_int (); + break; default: vlogprintf (E_ERROR, "x = 0x%08x\n", x); assert (0); @@ -1250,35 +1255,37 @@ void tglf_fetch_encrypted_message (struct tgl_state *TLS, struct tgl_message *M) vlogprintf (E_DEBUG - 2, "layer = %d, in = %d, out = %d\n", layer, in_seq_no, out_seq_no); } if (!(x == CODE_decrypted_message || x == CODE_decrypted_message_service || x == CODE_decrypted_message_l16 || x == CODE_decrypted_message_service_l16)) { - vlogprintf (E_ERROR, "x = 0x%08x\n", x); - assert (x == CODE_decrypted_message || x == CODE_decrypted_message_service || x == CODE_decrypted_message_l16 || x == CODE_decrypted_message_service_l16); + vlogprintf (E_ERROR, "Incorrect message: x = 0x%08x\n", x); + drop = 1; } //assert (id == fetch_long ()); - long long new_id = fetch_long (); - if (P && P->encr_chat.layer >= 17) { - assert (new_id == id); - } - if (x == CODE_decrypted_message || x == CODE_decrypted_message_service) { - if (x == CODE_decrypted_message) { - fetch_int (); // ttl + if (!drop) { + long long new_id = fetch_long (); + if (P && P->encr_chat.layer >= 17) { + assert (new_id == id); } - } else { - ll = prefetch_strlen (); - fetch_str (ll); // random_bytes - } - if (x == CODE_decrypted_message || x == CODE_decrypted_message_l16) { - l = prefetch_strlen (); - s = fetch_str (l); - start = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (decrypted_message_media)) >= 0); - end = in_ptr; - } else { - start = in_ptr; - if (skip_type_any (TYPE_TO_PARAM (decrypted_message_action)) < 0) { - vlogprintf (E_ERROR, "Can not decrypt: Skipped %ld int out of %ld. Magic = 0x%08x\n", (long)(in_ptr - start), (long)(in_end - start), *start); - drop = 1; + if (x == CODE_decrypted_message || x == CODE_decrypted_message_service) { + if (x == CODE_decrypted_message) { + fetch_int (); // ttl + } + } else { + ll = prefetch_strlen (); + fetch_str (ll); // random_bytes + } + if (x == CODE_decrypted_message || x == CODE_decrypted_message_l16) { + l = prefetch_strlen (); + s = fetch_str (l); + start = in_ptr; + assert (skip_type_any (TYPE_TO_PARAM (decrypted_message_media)) >= 0); + end = in_ptr; + } else { + start = in_ptr; + if (skip_type_any (TYPE_TO_PARAM (decrypted_message_action)) < 0) { + vlogprintf (E_ERROR, "Can not decrypt: Skipped %ld int out of %ld. Magic = 0x%08x\n", (long)(in_ptr - start), (long)(in_end - start), *start); + drop = 1; + } + end = in_ptr; } - end = in_ptr; } in_ptr = save_in_ptr; in_end = save_in_end; @@ -1661,6 +1668,7 @@ void tgls_free_message_action (struct tgl_state *TLS, struct tgl_message_action case tgl_message_action_delete_messages: case tgl_message_action_screenshot_messages: case tgl_message_action_flush_history: + case tgl_message_action_resend: case tgl_message_action_notify_layer: break; diff --git a/tgl-layout.h b/tgl-layout.h index a11c15f..8f1c4db 100644 --- a/tgl-layout.h +++ b/tgl-layout.h @@ -119,6 +119,7 @@ enum tgl_message_action_type { tgl_message_action_delete_messages, tgl_message_action_screenshot_messages, tgl_message_action_flush_history, + tgl_message_action_resend, tgl_message_action_notify_layer, tgl_message_action_typing }; @@ -386,6 +387,10 @@ struct tgl_message_action { int delete_cnt; int screenshot_cnt; enum tgl_typing_status typing; + struct { + int start_seq_no; + int end_seq_no; + }; }; }; From bdbf8997e0fb192639b0087cc2e60a7829b1bdc9 Mon Sep 17 00:00:00 2001 From: Vysheng Date: Tue, 11 Nov 2014 20:13:41 +0300 Subject: [PATCH 3/4] Minor fixes --- binlog.c | 8 ++++---- interface.c | 2 +- loop.c | 2 ++ queries.c | 6 +++--- tgl.h | 5 ++++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/binlog.c b/binlog.c index 482d064..93d4a9a 100644 --- a/binlog.c +++ b/binlog.c @@ -1422,7 +1422,7 @@ static void create_new_binlog (struct tgl_state *TLS) { out_int (2); } - int fd = open (get_binlog_file_name (), O_WRONLY | O_EXCL | O_CREAT, 0600); + int fd = open (TLS->binlog_name, O_WRONLY | O_EXCL | O_CREAT, 0600); if (fd < 0) { perror ("Write new binlog"); exit (2); @@ -1434,11 +1434,11 @@ static void create_new_binlog (struct tgl_state *TLS) { void tgl_replay_log (struct tgl_state *TLS) { if (!TLS->binlog_enabled) { return; } - if (access (get_binlog_file_name (), F_OK) < 0) { + if (access (TLS->binlog_name, F_OK) < 0) { printf ("No binlog found. Creating new one\n"); create_new_binlog (TLS); } - int fd = open (get_binlog_file_name (), O_RDONLY); + int fd = open (TLS->binlog_name, O_RDONLY); if (fd < 0) { perror ("binlog open"); exit (2); @@ -1477,7 +1477,7 @@ void tgl_replay_log (struct tgl_state *TLS) { static int b_packet_buffer[PACKET_BUFFER_SIZE]; void tgl_reopen_binlog_for_writing (struct tgl_state *TLS) { - TLS->binlog_fd = open (get_binlog_file_name (), O_WRONLY); + TLS->binlog_fd = open (TLS->binlog_name, O_WRONLY); if (TLS->binlog_fd < 0) { perror ("binlog open"); exit (2); diff --git a/interface.c b/interface.c index 76348af..6492bae 100644 --- a/interface.c +++ b/interface.c @@ -1050,7 +1050,6 @@ extern struct event *term_ev; void do_clear (int arg_num, struct arg args[], struct in_ev *ev) { logprintf ("Do_clear\n"); - tgl_free_all (TLS); free (default_username); free (config_filename); free (prefix); @@ -1064,6 +1063,7 @@ void do_clear (int arg_num, struct arg args[], struct in_ev *ev) { clear_history (); event_free (term_ev); event_base_free (TLS->ev_base); + tgl_free_all (TLS); do_halt (0); } diff --git a/loop.c b/loop.c index 6c8c81a..65e6335 100644 --- a/loop.c +++ b/loop.c @@ -699,6 +699,7 @@ static void accept_incoming (evutil_socket_t efd, short what, void *arg) { bufferevent_enable(bev, EV_READ|EV_WRITE); } +char *get_downloads_directory (void); int loop (void) { //on_start (); tgl_set_callback (TLS, &upd_cb); @@ -707,6 +708,7 @@ int loop (void) { tgl_set_ev_base (TLS, ev); tgl_set_net_methods (TLS, &tgl_conn_methods); tgl_set_timer_methods (TLS, &tgl_libevent_timers); + tgl_set_download_directory (TLS, get_downloads_directory ()); tgl_init (TLS); if (binlog_enabled) { diff --git a/queries.c b/queries.c index 0b79857..e71fa5d 100644 --- a/queries.c +++ b/queries.c @@ -61,7 +61,7 @@ #endif //int want_dc_num; -char *get_downloads_directory (void); +//char *get_downloads_directory (void); //extern int offline_mode; //long long cur_uploading_bytes; @@ -2492,9 +2492,9 @@ static void load_next_part (struct tgl_state *TLS, struct download *D, void *cal static char buf[PATH_MAX]; int l; if (!D->id) { - l = tsnprintf (buf, sizeof (buf), "%s/download_%lld_%d", get_downloads_directory (), D->volume, D->local_id); + l = tsnprintf (buf, sizeof (buf), "%s/download_%lld_%d.jpg", TLS->downloads_directory, D->volume, D->local_id); } else { - l = tsnprintf (buf, sizeof (buf), "%s/download_%lld", get_downloads_directory (), D->id); + l = tsnprintf (buf, sizeof (buf), "%s/download_%lld", TLS->downloads_directory, D->id); } if (l >= (int) sizeof (buf)) { vlogprintf (E_ERROR, "Download filename is too long"); diff --git a/tgl.h b/tgl.h index e2d4e41..dd1fa20 100644 --- a/tgl.h +++ b/tgl.h @@ -30,11 +30,12 @@ #define TG_SERVER_3 "174.140.142.6" #define TG_SERVER_4 "149.154.167.91" #define TG_SERVER_5 "149.154.171.5" - +#define TG_SERVER_DEFAULT 4 #define TG_SERVER_TEST_1 "173.240.5.253" #define TG_SERVER_TEST_2 "149.154.167.40" #define TG_SERVER_TEST_3 "174.140.142.5" +#define TG_SERVER_TEST_DEFAULT 2 // JUST RANDOM STRING #define TGL_BUILD "2590" @@ -201,6 +202,8 @@ struct tgl_state { void *pubKey; struct tree_query *queries_tree; + + char *base_path; }; #pragma pack(pop) //extern struct tgl_state tgl_state; From 47a12f1a2ae63b3d4d5c01241851a11c7b2693e3 Mon Sep 17 00:00:00 2001 From: Vysheng Date: Tue, 11 Nov 2014 20:34:32 +0300 Subject: [PATCH 4/4] Makefile.in: deleted net.o and tgl-timers.o from libtgl. Libtgl now does not depend from libevent --- Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index 8dc3f1b..817b847 100644 --- a/Makefile.in +++ b/Makefile.in @@ -20,8 +20,8 @@ DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${LIB} ${DEP}/auto ${OBJ}/auto EXE_LIST=${EXE}/generate ${EXE}/tlc ${EXE}/telegram-cli LIB_LIST=${LIB}/libtgl.a -TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/lua-tg.o -TGL_OBJECTS=${OBJ}/net.o ${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/auto/auto.o ${OBJ}/tgl.o ${OBJ}/updates.o ${OBJ}/tgl-timers.o +TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/net.o ${OBJ}/lua-tg.o ${OBJ}/tgl-timers.o +TGL_OBJECTS=${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/auto/auto.o ${OBJ}/tgl.o ${OBJ}/updates.o TLC_OBJECTS=${OBJ}/tlc.o ${OBJ}/tl-parser.o ${OBJ}/crc32.o TLD_OBJECTS=${OBJ}/dump-tl-file.o GENERATE_OBJECTS=${OBJ}/generate.o