Commit 11bf4177 authored by vvaltman's avatar vvaltman

Added dump-tl binary. Updated to 17 layer

parent b9878e5c
...@@ -23,10 +23,11 @@ LIB_LIST=${LIB}/libtgl.a ...@@ -23,10 +23,11 @@ LIB_LIST=${LIB}/libtgl.a
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/lua-tg.o 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 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
TLC_OBJECTS=${OBJ}/tlc.o ${OBJ}/tl-parser.o ${OBJ}/crc32.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 GENERATE_OBJECTS=${OBJ}/generate.o
COMMON_OBJECTS=${OBJ}/tools.o COMMON_OBJECTS=${OBJ}/tools.o
OBJ_LIST=${TG_OBJECTS} ${TLC_OBJECTS} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS} OBJ_LIST=${TG_OBJECTS} ${TLC_OBJECTS} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS} ${TLD_OBJECTS}
OBJ_C=${TLC_OBJECTS} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS} OBJ_C=${TLC_OBJECTS} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${TGL_OBJECTS} ${TLD_OBJECTS}
DEPENDENCE=$(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJ_LIST})) DEPENDENCE=$(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJ_LIST}))
DEPENDENCE_LIST=${DEPENDENCE} DEPENDENCE_LIST=${DEPENDENCE}
...@@ -41,6 +42,7 @@ CC=@CC@ ...@@ -41,6 +42,7 @@ CC=@CC@
all: ${EXE_LIST} ${DIR_LIST} ${LIB_LIST} all: ${EXE_LIST} ${DIR_LIST} ${LIB_LIST}
create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto.c ${AUTO}/auto-header.h ${AUTO}/constants.h create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto.c ${AUTO}/auto-header.h ${AUTO}/constants.h
create_dirs: ${DIR_LIST} create_dirs: ${DIR_LIST}
dump-tl: ${EXE}/dump-tl-file
${DIR_LIST}: ${DIR_LIST}:
@test -d $@ || mkdir -p $@ @test -d $@ || mkdir -p $@
...@@ -85,6 +87,9 @@ ${AUTO}/auto-header.h: ${AUTO}/scheme.tlo ${EXE}/generate ...@@ -85,6 +87,9 @@ ${AUTO}/auto-header.h: ${AUTO}/scheme.tlo ${EXE}/generate
${AUTO}/constants.h: ${AUTO}/scheme2.tl ${srcdir}/gen_constants_h.awk ${AUTO}/constants.h: ${AUTO}/scheme2.tl ${srcdir}/gen_constants_h.awk
awk -f ${srcdir}/gen_constants_h.awk < $< > $@ awk -f ${srcdir}/gen_constants_h.awk < $< > $@
${EXE}/dump-tl-file: ${OBJ}/auto/auto.o ${TLD_OBJECTS}
${CC} ${OBJ}/auto/auto.o ${TLD_OBJECTS} ${LINK_FLAGS} -o $@
clean: clean:
rm -rf ${DIR_LIST} config.log config.status > /dev/null || echo "all clean" rm -rf ${DIR_LIST} config.log config.status > /dev/null || echo "all clean"
This diff is collapsed.
...@@ -432,6 +432,6 @@ static void print_offset (void) { ...@@ -432,6 +432,6 @@ static void print_offset (void) {
char *tglf_extf_fetch (struct paramed_type *T) { char *tglf_extf_fetch (struct paramed_type *T) {
out_buf_pos = 0; out_buf_pos = 0;
fetch_type_any (T); if (fetch_type_any (T) < 0) { return 0; }
return out_buf; return out_buf;
} }
...@@ -782,6 +782,12 @@ static int fetch_comb_binlog_send_message_text (void *extra) { ...@@ -782,6 +782,12 @@ static int fetch_comb_binlog_send_message_text (void *extra) {
} }
M->to_id = tgl_set_peer_id (t, fetch_int ()); M->to_id = tgl_set_peer_id (t, fetch_int ());
if (t == TGL_PEER_ENCR_CHAT) {
tgl_peer_t *P = tgl_peer_get (M->to_id);
if (P) {
P->encr_chat.out_seq_no ++;
}
}
M->date = fetch_int (); M->date = fetch_int ();
int l = prefetch_strlen (); int l = prefetch_strlen ();
...@@ -824,6 +830,11 @@ static int fetch_comb_binlog_send_message_action_encr (void *extra) { ...@@ -824,6 +830,11 @@ static int fetch_comb_binlog_send_message_action_encr (void *extra) {
M->media.type = tgl_message_media_none; M->media.type = tgl_message_media_none;
tglf_fetch_message_action_encrypted (&M->action); tglf_fetch_message_action_encrypted (&M->action);
tgl_peer_t *P = tgl_peer_get (M->to_id);
if (P) {
P->encr_chat.out_seq_no ++;
}
M->unread = 1; M->unread = 1;
M->out = tgl_get_peer_id (M->from_id) == tgl_state.our_id; M->out = tgl_get_peer_id (M->from_id) == tgl_state.our_id;
...@@ -952,6 +963,11 @@ static int fetch_comb_binlog_create_message_media_encr_pending (void *extra) { ...@@ -952,6 +963,11 @@ static int fetch_comb_binlog_create_message_media_encr_pending (void *extra) {
int t = fetch_int (); int t = fetch_int ();
M->to_id = tgl_set_peer_id (t, fetch_int ()); M->to_id = tgl_set_peer_id (t, fetch_int ());
M->date = fetch_int (); M->date = fetch_int ();
tgl_peer_t *P = tgl_peer_get (M->to_id);
if (P) {
P->encr_chat.out_seq_no ++;
}
int l = prefetch_strlen (); int l = prefetch_strlen ();
M->message = talloc (l + 1); M->message = talloc (l + 1);
......
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <assert.h>
#include <string.h>
#include "auto.h"
int *tgl_in_ptr, *tgl_in_end;
int tgl_packet_buffer[0];
int *tgl_packet_ptr;
char *tgl_strdup (char *s) {
return strdup (s);
}
void tgl_out_cstring (const char *str, long len) {}
char *tglf_extf_fetch (struct paramed_type *T);
#define LEN (1 << 28)
static int x[LEN / 4];
int main (int argc, char **argv) {
int i;
int dump_binlog = 0;
while ((i = getopt (argc, argv, "b")) != -1) {
switch (i) {
case 'b':
dump_binlog = 1;
break;
default:
printf ("unknown option '%c'\n", (char)i);
exit (1);
}
}
if (!dump_binlog) {
exit (1);
}
if (optind + 1 != argc) {
exit (1);
}
int fd = open (argv[optind], O_RDONLY);
if (fd < 0) {
perror ("open");
exit (1);
}
int r = read (fd, x, LEN);
if (r <= 0) {
perror ("read");
exit (1);
}
if (r == LEN) {
printf ("Too long file\n");
exit (1);
}
assert (!(r & 3));
tgl_in_ptr = x;
tgl_in_end = x + (r / 4);
while (tgl_in_ptr < tgl_in_end) {
if (dump_binlog) {
char *R = tglf_extf_fetch (TYPE_TO_PARAM(binlog_update));
if (!R) {
printf ("Can not fetch\n");
exit (1);
}
printf ("%s\n", R);
}
}
return 0;
}
encrypted_scheme16.tl encrypted_scheme17.tl
\ No newline at end of file \ No newline at end of file
---types---
decryptedMessageLayer#99a438cf layer:int message:DecryptedMessage = DecryptedMessageLayer;
decryptedMessage_l16#1f814f1f random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage;
decryptedMessageService_l16#aa48327d random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage;
decryptedMessage#20a6d4e2 in_seq_no:int out_seq_no:int ttl:int random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage;
decryptedMessageService#9bb84a4e in_seq_no:int out_seq_no:int random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage;
decryptedMessageMediaEmpty#89f5c4a = DecryptedMessageMedia;
decryptedMessageMediaPhoto#32798a8c thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
//decryptedMessageMediaVideo#4cee6ef3 thumb:bytes thumb_w:int thumb_h:int duration:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageMediaGeoPoint#35480a59 lat:double long:double = DecryptedMessageMedia;
decryptedMessageMediaContact#588a0a97 phone_number:string first_name:string last_name:string user_id:int = DecryptedMessageMedia;
decryptedMessageActionSetMessageTTL#a1733aec ttl_seconds:int = DecryptedMessageAction;
decryptedMessageMediaDocument#b095434b thumb:bytes thumb_w:int thumb_h:int file_name:string mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia;
//decryptedMessageMediaAudio#6080758f duration:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageMediaVideo#524a415d thumb:bytes thumb_w:int thumb_h:int duration:int mime_type:string w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageMediaAudio#57e0a9cb duration:int mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia;
decryptedMessageActionReadMessages#c4f40be random_ids:Vector<long> = DecryptedMessageAction;
decryptedMessageActionDeleteMessages#65614304 random_ids:Vector<long> = DecryptedMessageAction;
decryptedMessageActionScreenshotMessages#8ac1f475 random_ids:Vector<long> = DecryptedMessageAction;
decryptedMessageActionFlushHistory#6719e45c = DecryptedMessageAction;
decryptedMessageActionNotifyLayer#f3048883 layer:int = DecryptedMessageAction;
decryptedMessageActionTyping#ccb27641 action:SendMessageAction = DecryptedMessageAction;
---functions---
...@@ -1594,26 +1594,68 @@ void mark_read_upd (int num, struct tgl_message *list[]) { ...@@ -1594,26 +1594,68 @@ void mark_read_upd (int num, struct tgl_message *list[]) {
} }
} }
void type_notification_upd (struct tgl_user *U) { void print_typing (struct in_ev *ev, enum tgl_typing_status status) {
switch (status) {
case tgl_typing_none:
mprintf (ev, "doing nothing");
break;
case tgl_typing_typing:
mprintf (ev, "typing");
break;
case tgl_typing_cancel:
mprintf (ev, "deleting typed message");
break;
case tgl_typing_record_video:
mprintf (ev, "recording video");
break;
case tgl_typing_upload_video:
mprintf (ev, "uploading video");
break;
case tgl_typing_record_audio:
mprintf (ev, "recording audio");
break;
case tgl_typing_upload_audio:
mprintf (ev, "uploading audio");
break;
case tgl_typing_upload_photo:
mprintf (ev, "uploading photo");
break;
case tgl_typing_upload_document:
mprintf (ev, "uploading document");
break;
case tgl_typing_geo:
mprintf (ev, "choosing location");
break;
case tgl_typing_choose_contact:
mprintf (ev, "choosing contact");
break;
}
}
void type_notification_upd (struct tgl_user *U, enum tgl_typing_status status) {
if (log_level < 2 || (disable_output && !notify_ev)) { return; } if (log_level < 2 || (disable_output && !notify_ev)) { return; }
struct in_ev *ev = notify_ev; struct in_ev *ev = notify_ev;
mprint_start (ev); mprint_start (ev);
mpush_color (ev, COLOR_YELLOW); mpush_color (ev, COLOR_YELLOW);
mprintf (ev, "User "); mprintf (ev, "User ");
print_user_name (ev, U->id, (void *)U); print_user_name (ev, U->id, (void *)U);
mprintf (ev, " is typing\n"); mprintf (ev, " is ");
print_typing (ev, status);
mprintf (ev, "\n");
mpop_color (ev); mpop_color (ev);
mprint_end (ev); mprint_end (ev);
} }
void type_in_chat_notification_upd (struct tgl_user *U, struct tgl_chat *C) { void type_in_chat_notification_upd (struct tgl_user *U, struct tgl_chat *C, enum tgl_typing_status status) {
if (log_level < 2 || (disable_output && !notify_ev)) { return; } if (log_level < 2 || (disable_output && !notify_ev)) { return; }
struct in_ev *ev = notify_ev; struct in_ev *ev = notify_ev;
mprint_start (ev); mprint_start (ev);
mpush_color (ev, COLOR_YELLOW); mpush_color (ev, COLOR_YELLOW);
mprintf (ev, "User "); mprintf (ev, "User ");
print_user_name (ev, U->id, (void *)U); print_user_name (ev, U->id, (void *)U);
mprintf (ev, " is typing in chat "); mprintf (ev, " is ");
print_typing (ev, status);
mprintf (ev, " in chat ");
print_chat_name (ev, C->id, (void *)C); print_chat_name (ev, C->id, (void *)C);
mprintf (ev, "\n"); mprintf (ev, "\n");
mpop_color (ev); mpop_color (ev);
...@@ -2385,6 +2427,10 @@ void print_service_message (struct in_ev *ev, struct tgl_message *M) { ...@@ -2385,6 +2427,10 @@ void print_service_message (struct in_ev *ev, struct tgl_message *M) {
case tgl_message_action_notify_layer: case tgl_message_action_notify_layer:
mprintf (ev, " updated layer to %d\n", M->action.layer); mprintf (ev, " updated layer to %d\n", M->action.layer);
break; break;
case tgl_message_action_typing:
mprintf (ev, " is ");
print_typing (ev, M->action.typing);
break;
default: default:
assert (0); assert (0);
} }
......
...@@ -201,7 +201,6 @@ static inline int prefetch_strlen (void) { ...@@ -201,7 +201,6 @@ static inline int prefetch_strlen (void) {
static inline char *fetch_str (int len) { static inline char *fetch_str (int len) {
assert (len >= 0); assert (len >= 0);
vlogprintf (E_DEBUG + 3, "fetch_string: len = %d\n", len);
if (len < 254) { if (len < 254) {
char *str = (char *) in_ptr + 1; char *str = (char *) in_ptr + 1;
in_ptr += 1 + (len >> 2); in_ptr += 1 + (len >> 2);
...@@ -294,12 +293,10 @@ int tgl_fetch_bignum (BIGNUM *x); ...@@ -294,12 +293,10 @@ int tgl_fetch_bignum (BIGNUM *x);
static inline int fetch_int (void) { static inline int fetch_int (void) {
assert (in_ptr + 1 <= in_end); assert (in_ptr + 1 <= in_end);
vlogprintf (E_DEBUG + 3, "fetch_int: 0x%08x (%d)\n", *in_ptr, *in_ptr);
return *(in_ptr ++); return *(in_ptr ++);
} }
static inline int fetch_bool (void) { static inline int fetch_bool (void) {
vlogprintf (E_DEBUG + 3, "fetch_bool: 0x%08x (%d)\n", *in_ptr, *in_ptr);
assert (in_ptr + 1 <= in_end); assert (in_ptr + 1 <= in_end);
assert (*(in_ptr) == (int)CODE_bool_true || *(in_ptr) == (int)CODE_bool_false); assert (*(in_ptr) == (int)CODE_bool_true || *(in_ptr) == (int)CODE_bool_false);
return *(in_ptr ++) == (int)CODE_bool_true; return *(in_ptr ++) == (int)CODE_bool_true;
......
...@@ -314,7 +314,7 @@ static void out_random (int n) { ...@@ -314,7 +314,7 @@ static void out_random (int n) {
int allow_send_linux_version; int allow_send_linux_version;
void tgl_do_insert_header (void) { void tgl_do_insert_header (void) {
out_int (CODE_invoke_with_layer16); out_int (CODE_invoke_with_layer17);
out_int (CODE_init_connection); out_int (CODE_init_connection);
out_int (TG_APP_ID); out_int (TG_APP_ID);
if (allow_send_linux_version) { if (allow_send_linux_version) {
...@@ -957,7 +957,13 @@ void tgl_do_send_encr_msg_action (struct tgl_message *M, void (*callback)(void * ...@@ -957,7 +957,13 @@ void tgl_do_send_encr_msg_action (struct tgl_message *M, void (*callback)(void *
out_long (P->encr_chat.access_hash); out_long (P->encr_chat.access_hash);
out_long (M->id); out_long (M->id);
encr_start (); encr_start ();
out_int (CODE_decrypted_message_service); if (P->encr_chat.layer <= 16) {
out_int (CODE_decrypted_message_service_l16);
} else {
out_int (CODE_decrypted_message_service);
out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id));
out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id));
}
out_long (M->id); out_long (M->id);
static int buf[4]; static int buf[4];
tglt_secure_random (buf, 16); tglt_secure_random (buf, 16);
...@@ -1001,7 +1007,14 @@ void tgl_do_send_encr_msg (struct tgl_message *M, void (*callback)(void *callbac ...@@ -1001,7 +1007,14 @@ void tgl_do_send_encr_msg (struct tgl_message *M, void (*callback)(void *callbac
out_long (P->encr_chat.access_hash); out_long (P->encr_chat.access_hash);
out_long (M->id); out_long (M->id);
encr_start (); encr_start ();
out_int (CODE_decrypted_message); if (P->encr_chat.layer <= 16) {
out_int (CODE_decrypted_message_l16);
} else {
out_int (CODE_decrypted_message);
out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id));
out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id));
out_int (0);
}
out_long (M->id); out_long (M->id);
static int buf[4]; static int buf[4];
tglt_secure_random (buf, 16); tglt_secure_random (buf, 16);
...@@ -1141,6 +1154,7 @@ void tgl_do_messages_mark_read (tgl_peer_id_t id, int max_id, int offset, void ( ...@@ -1141,6 +1154,7 @@ void tgl_do_messages_mark_read (tgl_peer_id_t id, int max_id, int offset, void (
out_peer_id (id); out_peer_id (id);
out_int (max_id); out_int (max_id);
out_int (offset); out_int (offset);
out_int (CODE_bool_true);
int *t = talloc (12); int *t = talloc (12);
t[0] = tgl_get_peer_type (id); t[0] = tgl_get_peer_type (id);
t[1] = tgl_get_peer_id (id); t[1] = tgl_get_peer_id (id);
...@@ -1738,7 +1752,14 @@ static void send_part (struct send_file *f, void *callback, void *callback_extra ...@@ -1738,7 +1752,14 @@ static void send_part (struct send_file *f, void *callback, void *callback_extra
tglt_secure_random (&r, 8); tglt_secure_random (&r, 8);
out_long (r); out_long (r);
encr_start (); encr_start ();
out_int (CODE_decrypted_message); if (P->encr_chat.layer <= 16) {
out_int (CODE_decrypted_message_l16);
} else {
out_int (CODE_decrypted_message);
out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id));
out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id) + 2);
out_int (0);
}
out_long (r); out_long (r);
out_random (15 + 4 * (lrand48 () % 3)); out_random (15 + 4 * (lrand48 () % 3));
out_string (""); out_string ("");
...@@ -2906,6 +2927,9 @@ static int send_encr_accept_on_answer (struct query *q UU) { ...@@ -2906,6 +2927,9 @@ static int send_encr_accept_on_answer (struct query *q UU) {
print_end (); print_end ();
}*/ }*/
if (E->state == sc_ok) {
tgl_do_send_encr_chat_layer (E);
}
if (q->callback) { if (q->callback) {
((void (*)(void *, int, struct tgl_secret_chat *))q->callback) (q->callback_extra, E->state == sc_ok, E); ((void (*)(void *, int, struct tgl_secret_chat *))q->callback) (q->callback_extra, E->state == sc_ok, E);
} }
......
scheme16.tl scheme17.tl
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
...@@ -108,6 +108,34 @@ char *tgls_default_create_print_name (tgl_peer_id_t id, const char *a1, const ch ...@@ -108,6 +108,34 @@ char *tgls_default_create_print_name (tgl_peer_id_t id, const char *a1, const ch
return tstrdup (s); return tstrdup (s);
} }
enum tgl_typing_status tglf_fetch_typing (void) {
switch (fetch_int ()) {
case CODE_send_message_typing_action:
return tgl_typing_typing;
case CODE_send_message_cancel_action:
return tgl_typing_cancel;
case CODE_send_message_record_video_action:
return tgl_typing_record_video;
case CODE_send_message_upload_video_action:
return tgl_typing_upload_video;
case CODE_send_message_record_audio_action:
return tgl_typing_record_audio;
case CODE_send_message_upload_audio_action:
return tgl_typing_upload_audio;
case CODE_send_message_upload_photo_action:
return tgl_typing_upload_photo;
case CODE_send_message_upload_document_action:
return tgl_typing_upload_document;
case CODE_send_message_geo_location_action:
return tgl_typing_geo;
case CODE_send_message_choose_contact_action:
return tgl_typing_choose_contact;
default:
assert (0);
return tgl_typing_none;
}
}
/* {{{ Fetch */ /* {{{ Fetch */
int tglf_fetch_file_location (struct tgl_file_location *loc) { int tglf_fetch_file_location (struct tgl_file_location *loc) {
...@@ -990,6 +1018,10 @@ void tglf_fetch_message_action_encrypted (struct tgl_message_action *M) { ...@@ -990,6 +1018,10 @@ void tglf_fetch_message_action_encrypted (struct tgl_message_action *M) {
case CODE_decrypted_message_action_flush_history: case CODE_decrypted_message_action_flush_history:
M->type = tgl_message_action_flush_history; M->type = tgl_message_action_flush_history;
break; break;
case CODE_decrypted_message_action_typing:
M->type = tgl_message_action_typing;
M->typing = tglf_fetch_typing ();
break;
default: default:
vlogprintf (E_ERROR, "x = 0x%08x\n", x); vlogprintf (E_ERROR, "x = 0x%08x\n", x);
assert (0); assert (0);
...@@ -1009,6 +1041,10 @@ tgl_peer_id_t tglf_fetch_peer_id (void) { ...@@ -1009,6 +1041,10 @@ tgl_peer_id_t tglf_fetch_peer_id (void) {
void tglf_fetch_message (struct tgl_message *M) { void tglf_fetch_message (struct tgl_message *M) {
unsigned x = fetch_int (); unsigned x = fetch_int ();
assert (x == CODE_message_empty || x == CODE_message || x == CODE_message_forwarded || x == CODE_message_service); assert (x == CODE_message_empty || x == CODE_message || x == CODE_message_forwarded || x == CODE_message_service);
int flags = 0;
if (x != CODE_message_empty) {
flags = fetch_int ();
}
int id = fetch_int (); int id = fetch_int ();
assert (M->id == id); assert (M->id == id);
if (x == CODE_message_empty) { if (x == CODE_message_empty) {
...@@ -1024,11 +1060,12 @@ void tglf_fetch_message (struct tgl_message *M) { ...@@ -1024,11 +1060,12 @@ void tglf_fetch_message (struct tgl_message *M) {
int from_id = fetch_int (); int from_id = fetch_int ();
tgl_peer_id_t to_id = tglf_fetch_peer_id (); tgl_peer_id_t to_id = tglf_fetch_peer_id ();
fetch_bool (); // out. //fetch_bool (); // out.
int unread = fetch_bool (); //int unread = fetch_bool ();
int date = fetch_int (); int date = fetch_int ();
int unread = (flags & 1) != 0;
int new = !(M->flags & FLAG_CREATED); int new = !(M->flags & FLAG_CREATED);
if (x == CODE_message_service) { if (x == CODE_message_service) {
...@@ -1190,12 +1227,30 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) { ...@@ -1190,12 +1227,30 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) {
assert (layer >= 0); assert (layer >= 0);
x = fetch_int (); x = fetch_int ();
} }
assert (x == CODE_decrypted_message || x == CODE_decrypted_message_service); assert (x == CODE_decrypted_message || x == CODE_decrypted_message_service || x == CODE_decrypted_message_l16 || x == CODE_decrypted_message_service_l16);
//assert (id == fetch_long ()); //assert (id == fetch_long ());
if (x == CODE_decrypted_message || x == CODE_decrypted_message_service) {
int out_seq_no = fetch_int ();
int in_seq_no = fetch_int ();
if (in_seq_no / 2 <= P->encr_chat.in_seq_no) {
vlogprintf (E_WARNING, "Hole in seq in secret chat. in_seq_no = %d, expect_seq_no = %d\n", in_seq_no / 2, P->encr_chat.in_seq_no + 1);
}
if (in_seq_no / 2 > P->encr_chat.in_seq_no + 1) {
vlogprintf (E_WARNING, "Hole in seq in secret chat. in_seq_no = %d, expect_seq_no = %d\n", in_seq_no / 2, P->encr_chat.in_seq_no + 1);
}
//vlogprintf (E_WARNING, "in = %d, out = %d\n", in_seq_no, out_seq_no);
assert (out_seq_no / 2 <= P->encr_chat.out_seq_no);
P->encr_chat.in_seq_no = in_seq_no / 2;
if (x == CODE_decrypted_message) {
fetch_int (); // ttl
}
} else {
P->encr_chat.in_seq_no ++;
}
fetch_long (); fetch_long ();
ll = prefetch_strlen (); ll = prefetch_strlen ();
fetch_str (ll); // random_bytes fetch_str (ll); // random_bytes
if (x == CODE_decrypted_message) { if (x == CODE_decrypted_message || x == CODE_decrypted_message_l16) {
l = prefetch_strlen (); l = prefetch_strlen ();
s = fetch_str (l); s = fetch_str (l);
start = in_ptr; start = in_ptr;
...@@ -1216,9 +1271,9 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) { ...@@ -1216,9 +1271,9 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) {
if (ok) { if (ok) {
int *start_file = in_ptr; int *start_file = in_ptr;
assert (skip_type_any (TYPE_TO_PARAM (encrypted_file)) >= 0); assert (skip_type_any (TYPE_TO_PARAM (encrypted_file)) >= 0);
if (x == CODE_decrypted_message) { if (x == CODE_decrypted_message || x == CODE_decrypted_message_l16) {
bl_do_create_message_media_encr (id, P->encr_chat.user_id, TGL_PEER_ENCR_CHAT, to_id, date, l, s, start, end - start, start_file, in_ptr - start_file); bl_do_create_message_media_encr (id, P->encr_chat.user_id, TGL_PEER_ENCR_CHAT, to_id, date, l, s, start, end - start, start_file, in_ptr - start_file);
} else if (x == CODE_decrypted_message_service) { } else if (x == CODE_decrypted_message_service || x == CODE_decrypted_message_service_l16) {
bl_do_create_message_service_encr (id, P->encr_chat.user_id, TGL_PEER_ENCR_CHAT, to_id, date, start, end - start); bl_do_create_message_service_encr (id, P->encr_chat.user_id, TGL_PEER_ENCR_CHAT, to_id, date, start, end - start);
} }
} else { } else {
...@@ -1226,7 +1281,7 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) { ...@@ -1226,7 +1281,7 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) {
M->media.type = CODE_message_media_empty; M->media.type = CODE_message_media_empty;
} }
} else { } else {
if (ok && x == CODE_decrypted_message_service) { if (ok && (x == CODE_decrypted_message_service || x == CODE_decrypted_message_service_l16)) {
bl_do_create_message_service_encr (id, P->encr_chat.user_id, TGL_PEER_ENCR_CHAT, to_id, date, start, end - start); bl_do_create_message_service_encr (id, P->encr_chat.user_id, TGL_PEER_ENCR_CHAT, to_id, date, start, end - start);
} }
} }
...@@ -1310,12 +1365,12 @@ struct tgl_user *tglf_fetch_alloc_user_full (void) { ...@@ -1310,12 +1365,12 @@ struct tgl_user *tglf_fetch_alloc_user_full (void) {
} }
struct tgl_message *tglf_fetch_alloc_message (void) { struct tgl_message *tglf_fetch_alloc_message (void) {
int data[2]; int data[3];
prefetch_data (data, 8); prefetch_data (data, 12);
struct tgl_message *M = tgl_message_get (data[1]); struct tgl_message *M = tgl_message_get (data[0] != (int)CODE_message_empty ? data[2] : data[1]);
if (!M) { if (!M) {
M = tglm_message_alloc (data[1]); M = tglm_message_alloc (data[0] != (int)CODE_message_empty ? data[2] : data[1]);
} }
tglf_fetch_message (M); tglf_fetch_message (M);
return M; return M;
......
...@@ -51,5 +51,6 @@ void tglp_peer_delete_name (tgl_peer_t *P); ...@@ -51,5 +51,6 @@ void tglp_peer_delete_name (tgl_peer_t *P);
void tglp_insert_encrypted_chat (tgl_peer_t *P); void tglp_insert_encrypted_chat (tgl_peer_t *P);
void tglp_insert_user (tgl_peer_t *P); void tglp_insert_user (tgl_peer_t *P);
void tglp_insert_chat (tgl_peer_t *P); void tglp_insert_chat (tgl_peer_t *P);
enum tgl_typing_status tglf_fetch_typing (void);
#endif #endif
...@@ -120,7 +120,22 @@ enum tgl_message_action_type { ...@@ -120,7 +120,22 @@ enum tgl_message_action_type {
tgl_message_action_delete_messages, tgl_message_action_delete_messages,
tgl_message_action_screenshot_messages, tgl_message_action_screenshot_messages,
tgl_message_action_flush_history, tgl_message_action_flush_history,
tgl_message_action_notify_layer tgl_message_action_notify_layer,
tgl_message_action_typing
};
enum tgl_typing_status {
tgl_typing_none,
tgl_typing_typing,
tgl_typing_cancel,
tgl_typing_record_video,
tgl_typing_upload_video,
tgl_typing_record_audio,
tgl_typing_upload_audio,
tgl_typing_upload_photo,
tgl_typing_upload_document,
tgl_typing_geo,
tgl_typing_choose_contact
}; };
struct tgl_file_location { struct tgl_file_location {
...@@ -288,6 +303,8 @@ struct tgl_secret_chat { ...@@ -288,6 +303,8 @@ struct tgl_secret_chat {
int date; int date;
int ttl; int ttl;
int layer; int layer;
int in_seq_no;
int out_seq_no;
long long access_hash; long long access_hash;
unsigned char *g_key; unsigned char *g_key;
unsigned char *nonce; unsigned char *nonce;
...@@ -367,6 +384,7 @@ struct tgl_message_action { ...@@ -367,6 +384,7 @@ struct tgl_message_action {
int read_cnt; int read_cnt;
int delete_cnt; int delete_cnt;
int screenshot_cnt; int screenshot_cnt;
enum tgl_typing_status typing;
}; };
}; };
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#define TGL_BUILD "2014" #define TGL_BUILD "2014"
#define TGL_VERSION "1.0.5" #define TGL_VERSION "1.0.5"
#define TGL_ENCRYPTED_LAYER 16 #define TGL_ENCRYPTED_LAYER 17
struct connection; struct connection;
struct mtproto_methods; struct mtproto_methods;
...@@ -70,8 +70,8 @@ struct tgl_update_callback { ...@@ -70,8 +70,8 @@ struct tgl_update_callback {
void (*new_msg)(struct tgl_message *M); void (*new_msg)(struct tgl_message *M);
void (*marked_read)(int num, struct tgl_message *list[]); void (*marked_read)(int num, struct tgl_message *list[]);
void (*logprintf)(const char *format, ...) __attribute__ ((format (printf, 1, 2))); void (*logprintf)(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void (*type_notification)(struct tgl_user *U); void (*type_notification)(struct tgl_user *U, enum tgl_typing_status status);
void (*type_in_chat_notification)(struct tgl_user *U, struct tgl_chat *C); void (*type_in_chat_notification)(struct tgl_user *U, struct tgl_chat *C, enum tgl_typing_status status);
void (*type_in_secret_chat_notification)(struct tgl_secret_chat *E); void (*type_in_secret_chat_notification)(struct tgl_secret_chat *E);
void (*status_notification)(struct tgl_user *U); void (*status_notification)(struct tgl_user *U);
void (*user_registered)(struct tgl_user *U); void (*user_registered)(struct tgl_user *U);
......
...@@ -99,24 +99,28 @@ void tglu_work_update (struct connection *c, long long msg_id) { ...@@ -99,24 +99,28 @@ void tglu_work_update (struct connection *c, long long msg_id) {
break; break;
case CODE_update_user_typing: case CODE_update_user_typing:
{ {
//vlogprintf (E_ERROR, "user typing\n");
tgl_peer_id_t id = TGL_MK_USER (fetch_int ()); tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
tgl_peer_t *U = tgl_peer_get (id); tgl_peer_t *U = tgl_peer_get (id);
enum tgl_typing_status status = tglf_fetch_typing ();
if (tgl_state.callback.type_notification && U) { if (tgl_state.callback.type_notification && U) {
tgl_state.callback.type_notification ((void *)U); tgl_state.callback.type_notification ((void *)U, status);
} }
} }
break; break;
case CODE_update_chat_user_typing: case CODE_update_chat_user_typing:
{ {
//vlogprintf (E_ERROR, "chat typing\n");
tgl_peer_id_t chat_id = TGL_MK_CHAT (fetch_int ()); tgl_peer_id_t chat_id = TGL_MK_CHAT (fetch_int ());
tgl_peer_id_t id = TGL_MK_USER (fetch_int ()); tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
tgl_peer_t *C = tgl_peer_get (chat_id); tgl_peer_t *C = tgl_peer_get (chat_id);
tgl_peer_t *U = tgl_peer_get (id); tgl_peer_t *U = tgl_peer_get (id);
enum tgl_typing_status status = tglf_fetch_typing ();
if (U && C) { if (U && C) {
if (tgl_state.callback.type_in_chat_notification) { if (tgl_state.callback.type_in_chat_notification) {
tgl_state.callback.type_in_chat_notification ((void *)U, (void *)C); tgl_state.callback.type_in_chat_notification ((void *)U, (void *)C, status);
} }
} }
} }
......
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