This commit is contained in:
vvaltman 2015-04-22 20:09:53 +03:00
parent 67ec7aa4b3
commit ff1057eaae
5 changed files with 77 additions and 56 deletions

View File

@ -26,7 +26,7 @@ ${TGL_OBJECTS_AUTO}: ${OBJ}/auto/%.o: ${AUTO}/%.c | create_dirs
# ${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/auto/auto.d -MQ ${OBJ}/auto/auto.o -o $@ $< # ${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/auto/auto.d -MQ ${OBJ}/auto/auto.o -o $@ $<
${LIB}/libtgl.a: ${TGL_OBJECTS} ${TGL_COMMON_OBJECTS} ${TGL_OBJECTS_AUTO} ${LIB}/libtgl.a: ${TGL_OBJECTS} ${TGL_COMMON_OBJECTS} ${TGL_OBJECTS_AUTO}
ar ruv $@ $^ rm -f $@ && ar ruv $@ $^
${EXE}/generate: ${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${EXE}/generate: ${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS}
${CC} ${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${LINK_FLAGS} -o $@ ${CC} ${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${LINK_FLAGS} -o $@

View File

@ -732,7 +732,7 @@ void do_rename_chat (int arg_num, struct arg args[], struct in_ev *ev) {
void do_ ## act ## _ ## tp (int arg_num, struct arg args[], struct in_ev *ev) { \ void do_ ## act ## _ ## tp (int arg_num, struct arg args[], struct in_ev *ev) { \
assert (arg_num == 1);\ assert (arg_num == 1);\
struct tgl_message *M = tgl_message_get (TLS, args[0].num);\ struct tgl_message *M = tgl_message_get (TLS, args[0].num);\
if (M && !M->service) {\ if (M && !(M->flags & TGLMF_SERVICE)) {\
if (M->media.type == tgl_message_media_photo) { \ if (M->media.type == tgl_message_media_photo) { \
tgl_do_load_photo (TLS, &M->media.photo, actf, ev);\ tgl_do_load_photo (TLS, &M->media.photo, actf, ev);\
} else if (M->media.type == tgl_message_media_document) {\ } else if (M->media.type == tgl_message_media_document) {\
@ -747,7 +747,7 @@ void do_ ## act ## _ ## tp (int arg_num, struct arg args[], struct in_ev *ev) {
void do_ ## act ## _ ## tp ## _thumb (int arg_num, struct arg args[], struct in_ev *ev) { \ void do_ ## act ## _ ## tp ## _thumb (int arg_num, struct arg args[], struct in_ev *ev) { \
assert (arg_num == 1);\ assert (arg_num == 1);\
struct tgl_message *M = tgl_message_get (TLS, args[0].num);\ struct tgl_message *M = tgl_message_get (TLS, args[0].num);\
if (M && !M->service) {\ if (M && !(M->flags & TGLMF_SERVICE)) {\
if (M->media.type == tgl_message_media_document) {\ if (M->media.type == tgl_message_media_document) {\
tgl_do_load_document_thumb (TLS, &M->media.document, actf, ev);\ tgl_do_load_document_thumb (TLS, &M->media.document, actf, ev);\
}\ }\
@ -972,10 +972,10 @@ void do_delete_msg (int arg_num, struct arg args[], struct in_ev *ev) {
tgl_do_delete_msg (TLS, args[0].num, print_success_gw, ev); tgl_do_delete_msg (TLS, args[0].num, print_success_gw, ev);
} }
void do_restore_msg (int arg_num, struct arg args[], struct in_ev *ev) { //void do_restore_msg (int arg_num, struct arg args[], struct in_ev *ev) {
if (ev) { ev->refcnt ++; } // if (ev) { ev->refcnt ++; }
tgl_do_restore_msg (TLS, args[0].num, print_success_gw, ev); // tgl_do_restore_msg (TLS, args[0].num, print_success_gw, ev);
} //}
void do_create_group_chat (int arg_num, struct arg args[], struct in_ev *ev) { void do_create_group_chat (int arg_num, struct arg args[], struct in_ev *ev) {
assert (arg_num >= 1 && arg_num <= 1000); assert (arg_num >= 1 && arg_num <= 1000);
@ -1181,7 +1181,7 @@ struct command commands[] = {
{"quit", {ca_none}, do_quit, "quit\tQuits immediately"}, {"quit", {ca_none}, do_quit, "quit\tQuits immediately"},
{"rename_chat", {ca_chat, ca_string_end, ca_none}, do_rename_chat, "rename_chat <chat> <new name>\tRenames chat"}, {"rename_chat", {ca_chat, ca_string_end, ca_none}, do_rename_chat, "rename_chat <chat> <new name>\tRenames chat"},
{"rename_contact", {ca_user, ca_string, ca_string, ca_none}, do_rename_contact, "rename_contact <user> <first name> <last name>\tRenames contact"}, {"rename_contact", {ca_user, ca_string, ca_string, ca_none}, do_rename_contact, "rename_contact <user> <first name> <last name>\tRenames contact"},
{"restore_msg", {ca_number, ca_none}, do_restore_msg, "restore_msg <msg-id>\tRestores message. Only available shortly (one hour?) after deletion"}, // {"restore_msg", {ca_number, ca_none}, do_restore_msg, "restore_msg <msg-id>\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"}, {"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)"}, {"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)"},
{"secret_chat_rekey", { ca_secret_chat, ca_none}, do_secret_chat_rekey, "generate new key for active secret chat"}, {"secret_chat_rekey", { ca_secret_chat, ca_none}, do_secret_chat_rekey, "generate new key for active secret chat"},
@ -1604,10 +1604,10 @@ void open_filename_gw (struct tgl_state *TLSR, void *extra, int success, char *n
if (snprintf (buf, sizeof (buf), OPEN_BIN, name) >= (int) sizeof (buf)) { if (snprintf (buf, sizeof (buf), OPEN_BIN, name) >= (int) sizeof (buf)) {
logprintf ("Open image command buffer overflow\n"); logprintf ("Open image command buffer overflow\n");
} else { } else {
int x = system (buf); int pid = fork ();
if (x < 0) { if (!pid) {
logprintf ("Can not open image viewer: %m\n"); execl("/bin/sh", "sh", "-c", buf, (char *) 0);
logprintf ("Image is at %s\n", name); exit (0);
} }
} }
} }
@ -1792,7 +1792,7 @@ void print_read_list (int num, struct tgl_message *list[]) {
end_id = list[j]->to_id; end_id = list[j]->to_id;
} }
if (!tgl_cmp_peer_id (to_id, end_id)) { if (!tgl_cmp_peer_id (to_id, end_id)) {
if (list[j]->out) { if (list[j]->flags & TGLMF_OUT) {
c1 ++; c1 ++;
} else { } else {
c2 ++; c2 ++;
@ -2658,6 +2658,22 @@ void print_media (struct in_ev *ev, struct tgl_message_media *M) {
case tgl_message_media_unsupported: case tgl_message_media_unsupported:
mprintf (ev, "[unsupported]"); mprintf (ev, "[unsupported]");
return; return;
case tgl_message_media_webpage:
mprintf (ev, "[webpage:");
if (M->webpage.url) {
mprintf (ev, " url:'%s'", M->webpage.url);
}
if (M->webpage.title) {
mprintf (ev, " title:'%s'", M->webpage.title);
}
if (M->webpage.description) {
mprintf (ev, " description:'%s'", M->webpage.description);
}
if (M->webpage.author) {
mprintf (ev, " author:'%s'", M->webpage.author);
}
mprintf (ev, "]");
break;
default: default:
mprintf (ev, "x = %d\n", M->type); mprintf (ev, "x = %d\n", M->type);
assert (0); assert (0);
@ -2685,12 +2701,12 @@ void print_user_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *U) {
unknown_user_list[unknown_user_list_pos ++] = tgl_get_peer_id (id); unknown_user_list[unknown_user_list_pos ++] = tgl_get_peer_id (id);
} }
} else { } else {
if (U->flags & (FLAG_USER_SELF | FLAG_USER_CONTACT)) { if (U->flags & (TGLUF_SELF | TGLUF_CONTACT)) {
mpush_color (ev, COLOR_REDB); mpush_color (ev, COLOR_REDB);
} }
if ((U->flags & FLAG_DELETED)) { if ((U->flags & TGLUF_DELETED)) {
mprintf (ev, "deleted user#%d", tgl_get_peer_id (id)); mprintf (ev, "deleted user#%d", tgl_get_peer_id (id));
} else if (!(U->flags & FLAG_CREATED)) { } else if (!(U->flags & TGLUF_CREATED)) {
mprintf (ev, "user#%d", tgl_get_peer_id (id)); mprintf (ev, "user#%d", tgl_get_peer_id (id));
} else if (use_ids) { } else if (use_ids) {
mprintf (ev, "user#%d", tgl_get_peer_id (id)); mprintf (ev, "user#%d", tgl_get_peer_id (id));
@ -2701,7 +2717,7 @@ void print_user_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *U) {
} else { } else {
mprintf (ev, "%s %s", U->user.first_name, U->user.last_name); mprintf (ev, "%s %s", U->user.first_name, U->user.last_name);
} }
if (U->flags & (FLAG_USER_SELF | FLAG_USER_CONTACT)) { if (U->flags & (TGLUF_SELF | TGLUF_CONTACT)) {
mpop_color (ev); mpop_color (ev);
} }
} }
@ -2860,11 +2876,11 @@ tgl_peer_id_t last_to_id;
void print_message (struct in_ev *ev, struct tgl_message *M) { void print_message (struct in_ev *ev, struct tgl_message *M) {
assert (M); assert (M);
if (M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) { if (M->flags & (TGLMF_EMPTY | TGLMF_DELETED)) {
return; return;
} }
if (!(M->flags & FLAG_CREATED)) { return; } if (!(M->flags & TGLMF_CREATED)) { return; }
if (M->service) { if (M->flags & TGLMF_SERVICE) {
print_service_message (ev, M); print_service_message (ev, M);
return; return;
} }
@ -2878,7 +2894,7 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
//print_start (); //print_start ();
if (tgl_get_peer_type (M->to_id) == TGL_PEER_USER) { if (tgl_get_peer_type (M->to_id) == TGL_PEER_USER) {
if (M->out) { if (M->flags & TGLMF_OUT) {
mpush_color (ev, COLOR_GREEN); mpush_color (ev, COLOR_GREEN);
if (msg_num_mode) { if (msg_num_mode) {
mprintf (ev, "%lld ", M->id); mprintf (ev, "%lld ", M->id);
@ -2888,7 +2904,7 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
mprintf (ev, " "); mprintf (ev, " ");
print_user_name (ev, M->to_id, tgl_peer_get (TLS, M->to_id)); print_user_name (ev, M->to_id, tgl_peer_get (TLS, M->to_id));
mpush_color (ev, COLOR_GREEN); mpush_color (ev, COLOR_GREEN);
if (M->unread) { if (M->flags & TGLMF_UNREAD) {
mprintf (ev, " <<< "); mprintf (ev, " <<< ");
} else { } else {
mprintf (ev, " ««« "); mprintf (ev, " ««« ");
@ -2903,7 +2919,7 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
mprintf (ev, " "); mprintf (ev, " ");
print_user_name (ev, M->from_id, tgl_peer_get (TLS, M->from_id)); print_user_name (ev, M->from_id, tgl_peer_get (TLS, M->from_id));
mpush_color (ev, COLOR_BLUE); mpush_color (ev, COLOR_BLUE);
if (M->unread) { if (M->flags & TGLMF_UNREAD) {
mprintf (ev, " >>> "); mprintf (ev, " >>> ");
} else { } else {
mprintf (ev, " »»» "); mprintf (ev, " »»» ");
@ -2912,7 +2928,7 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
} else if (tgl_get_peer_type (M->to_id) == TGL_PEER_ENCR_CHAT) { } else if (tgl_get_peer_type (M->to_id) == TGL_PEER_ENCR_CHAT) {
tgl_peer_t *P = tgl_peer_get (TLS, M->to_id); tgl_peer_t *P = tgl_peer_get (TLS, M->to_id);
assert (P); assert (P);
if (M->out) { if (M->flags & TGLMF_UNREAD) {
mpush_color (ev, COLOR_GREEN); mpush_color (ev, COLOR_GREEN);
if (msg_num_mode) { if (msg_num_mode) {
mprintf (ev, "%lld ", M->id); mprintf (ev, "%lld ", M->id);
@ -2922,7 +2938,7 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
mpush_color (ev, COLOR_CYAN); mpush_color (ev, COLOR_CYAN);
mprintf (ev, " %s", P->print_name); mprintf (ev, " %s", P->print_name);
mpop_color (ev); mpop_color (ev);
if (M->unread) { if (M->flags & TGLMF_UNREAD) {
mprintf (ev, " <<< "); mprintf (ev, " <<< ");
} else { } else {
mprintf (ev, " ««« "); mprintf (ev, " ««« ");
@ -2936,7 +2952,7 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
mpush_color (ev, COLOR_CYAN); mpush_color (ev, COLOR_CYAN);
mprintf (ev, " %s", P->print_name); mprintf (ev, " %s", P->print_name);
mpop_color (ev); mpop_color (ev);
if (M->unread) { if (M->flags & TGLMF_UNREAD) {
mprintf (ev, " >>> "); mprintf (ev, " >>> ");
} else { } else {
mprintf (ev, " »»» "); mprintf (ev, " »»» ");
@ -2959,7 +2975,7 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
} else { } else {
mpush_color (ev, COLOR_BLUE); mpush_color (ev, COLOR_BLUE);
} }
if (M->unread) { if (M->flags & TGLMF_UNREAD) {
mprintf (ev, " >>> "); mprintf (ev, " >>> ");
} else { } else {
mprintf (ev, " »»» "); mprintf (ev, " »»» ");
@ -2974,6 +2990,9 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
mprintf (ev, "%s", M->message); mprintf (ev, "%s", M->message);
} }
if (M->media.type != tgl_message_media_none) { if (M->media.type != tgl_message_media_none) {
if (M->message && strlen (M->message)) {
mprintf (ev, " ");
}
print_media (ev, &M->media); print_media (ev, &M->media);
} }
mpop_color (ev); mpop_color (ev);

42
loop.c
View File

@ -344,7 +344,7 @@ void write_dc (struct tgl_dc *DC, void *extra) {
assert (write (auth_file_fd, &x, 4) == 4); assert (write (auth_file_fd, &x, 4) == 4);
} }
assert (DC->has_auth); assert (DC->flags & TGLDCF_LOGGED_IN);
assert (write (auth_file_fd, &DC->port, 4) == 4); assert (write (auth_file_fd, &DC->port, 4) == 4);
int l = strlen (DC->ip); int l = strlen (DC->ip);
@ -436,7 +436,7 @@ void read_dc (int auth_file_fd, int id, unsigned ver) {
//bl_do_add_dc (id, ip, l, port, auth_key_id, auth_key); //bl_do_add_dc (id, ip, l, port, auth_key_id, auth_key);
bl_do_dc_option (TLS, id, 2, "DC", l, ip, port); bl_do_dc_option (TLS, id, 2, "DC", l, ip, port);
bl_do_set_auth_key_id (TLS, id, auth_key); bl_do_set_auth_key (TLS, id, auth_key);
bl_do_dc_signed (TLS, id); bl_do_dc_signed (TLS, id);
} }
@ -519,6 +519,8 @@ void read_secret_chat (int fd, int v) {
assert (read (fd, &key, 256) == 256); assert (read (fd, &key, 256) == 256);
if (v >= 2) { if (v >= 2) {
assert (read (fd, sha, 20) == 20); assert (read (fd, sha, 20) == 20);
} else {
SHA1 ((void *)key, 256, sha);
} }
int in_seq_no = 0, out_seq_no = 0, last_in_seq_no = 0; int in_seq_no = 0, out_seq_no = 0, last_in_seq_no = 0;
if (v >= 1) { if (v >= 1) {
@ -527,24 +529,24 @@ void read_secret_chat (int fd, int v) {
assert (read (fd, &out_seq_no, 4) == 4); assert (read (fd, &out_seq_no, 4) == 4);
} }
bl_do_encr_chat_create (TLS, id, user_id, admin_id, s, l); bl_do_encr_chat_new (TLS, id,
struct tgl_secret_chat *P = (void *)tgl_peer_get (TLS, TGL_MK_ENCR_CHAT (id)); &access_hash,
assert (P && (P->flags & FLAG_CREATED)); &date,
bl_do_encr_chat_set_date (TLS, P, date); &admin_id,
bl_do_encr_chat_set_ttl (TLS, P, ttl); &user_id,
bl_do_encr_chat_set_layer (TLS ,P, layer); key,
bl_do_encr_chat_set_access_hash (TLS, P, access_hash); NULL,
bl_do_encr_chat_set_state (TLS, P, state); sha,
bl_do_encr_chat_set_key (TLS, P, key, key_fingerprint); &state,
if (v >= 2) { &ttl,
bl_do_encr_chat_set_sha (TLS, P, sha); &layer,
} else { &in_seq_no,
SHA1 ((void *)key, 256, sha); &last_in_seq_no,
bl_do_encr_chat_set_sha (TLS, P, sha); &out_seq_no,
} &key_fingerprint,
if (v >= 1) { TGLECF_CREATE | TGLECF_CREATED
bl_do_encr_chat_set_seq (TLS, P, in_seq_no, last_in_seq_no, out_seq_no); );
}
} }
void read_secret_chat_file (void) { void read_secret_chat_file (void) {

View File

@ -199,7 +199,7 @@ void push_peer (tgl_peer_id_t id, tgl_peer_t *P) {
lua_settable (luaState, -3); lua_settable (luaState, -3);
if (!P || !(P->flags & FLAG_CREATED)) { if (!P || !(P->flags & TGLPF_CREATED)) {
lua_pushstring (luaState, "print_name"); lua_pushstring (luaState, "print_name");
static char s[100]; static char s[100];
switch (tgl_get_peer_type (id)) { switch (tgl_get_peer_type (id)) {
@ -294,7 +294,7 @@ void push_message (struct tgl_message *M) {
static char s[30]; static char s[30];
snprintf (s, 30, "%lld", M->id); snprintf (s, 30, "%lld", M->id);
lua_add_string_field ("id", s); lua_add_string_field ("id", s);
if (!(M->flags & FLAG_CREATED)) { return; } if (!(M->flags & TGLMF_CREATED)) { return; }
lua_add_num_field ("flags", M->flags); lua_add_num_field ("flags", M->flags);
if (tgl_get_peer_type (M->fwd_from_id)) { if (tgl_get_peer_type (M->fwd_from_id)) {
@ -314,11 +314,11 @@ void push_message (struct tgl_message *M) {
lua_settable (luaState, -3); lua_settable (luaState, -3);
lua_pushstring (luaState, "out"); lua_pushstring (luaState, "out");
lua_pushboolean (luaState, M->out); lua_pushboolean (luaState, (M->flags & TGLMF_OUT) != 0);
lua_settable (luaState, -3); lua_settable (luaState, -3);
lua_pushstring (luaState, "unread"); lua_pushstring (luaState, "unread");
lua_pushboolean (luaState, M->unread); lua_pushboolean (luaState, (M->flags & TGLMF_UNREAD) != 0);
lua_settable (luaState, -3); lua_settable (luaState, -3);
lua_pushstring (luaState, "date"); lua_pushstring (luaState, "date");
@ -326,10 +326,10 @@ void push_message (struct tgl_message *M) {
lua_settable (luaState, -3); lua_settable (luaState, -3);
lua_pushstring (luaState, "service"); lua_pushstring (luaState, "service");
lua_pushboolean (luaState, M->service); lua_pushboolean (luaState, (M->flags & TGLMF_SERVICE) != 0);
lua_settable (luaState, -3); lua_settable (luaState, -3);
if (!M->service) { if (!(M->flags & TGLMF_SERVICE)) {
if (M->message_len && M->message) { if (M->message_len && M->message) {
lua_pushstring (luaState, "text"); lua_pushstring (luaState, "text");
lua_pushlstring (luaState, M->message, M->message_len); lua_pushlstring (luaState, M->message, M->message_len);
@ -600,7 +600,7 @@ void lua_dialog_list_cb (struct tgl_state *TLSR, void *cb_extra, int success, in
lua_settable (luaState, -3); lua_settable (luaState, -3);
struct tgl_message *M = tgl_message_get (TLS, msgs[i]); struct tgl_message *M = tgl_message_get (TLS, msgs[i]);
if (M && (M->flags & FLAG_CREATED)) { if (M && (M->flags & TGLMF_CREATED)) {
lua_pushstring (luaState, "message"); lua_pushstring (luaState, "message");
push_message (M); push_message (M);
lua_settable (luaState, -3); lua_settable (luaState, -3);
@ -1311,7 +1311,7 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) {
M = tgl_message_get (TLS, num); M = tgl_message_get (TLS, num);
if (!M || !(M->flags & FLAG_CREATED)) { if (!M || !(M->flags & TGLMF_CREATED)) {
ok = 0; ok = 0;
break; break;
} }

2
tgl

@ -1 +1 @@
Subproject commit d43fea298fa944ae261de39e7680548ae25a9cd0 Subproject commit 8945b81f6d78f89aee3dcc123b9506370f886c16