diff --git a/Makefile.in b/Makefile.in index 6ca6989..d83604a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,9 +2,6 @@ srcdir=@srcdir@ CFLAGS=@CFLAGS@ @PURPLE_CFLAGS@ @DEFS@ -Wall -Wextra -Wno-deprecated-declarations -Wno-unused-parameter -I${srcdir} -I. -fno-strict-aliasing -fPIC LDFLAGS=@LDFLAGS@ @OPENSSL_LDFLAGS@ @PURPLE_LIBS@ @LIBS@ -lcrypto -rdynamic -ggdb -CPPFLAGS=@CPPFLAGS@ -DFLAGS -COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} -LINK_FLAGS=${LDFLAGS} DIR_PERM=0755 FILE_PERM=0644 @@ -12,11 +9,10 @@ CC=@CC@ PKG_CONFIG=@PKG_CONFIG@ DEP=dep -AUTO=auto EXE=bin OBJ=objs LIB=libs -DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${LIB} ${DEP}/auto ${OBJ}/auto ${DEP}/lodepng ${OBJ}/lodepng +DIR_LIST=${DEP} ${EXE} ${OBJ} ${LIB} ${DEP}/lodepng ${OBJ}/lodepng PLUGIN_OBJECTS=${OBJ}/tgp-net.o ${OBJ}/tgp-timers.o ${OBJ}/msglog.o ${OBJ}/telegram-base.o ${OBJ}/telegram-purple.o ${OBJ}/tgp-2prpl.o ${OBJ}/tgp-structs.o ${OBJ}/tgp-utils.o ${OBJ}/tgp-chat.o ${OBJ}/tgp-ft.o ${OBJ}/tgp-msg.o ${OBJ}/tgp-request.o ${OBJ}/lodepng/lodepng.o ALL_OBJS=${PLUGIN_OBJECTS} @@ -32,11 +28,7 @@ all: ${PRPL_LIBNAME} PLUGIN_DIR_PURPLE=$(shell ${PKG_CONFIG} --variable=plugindir purple) DATA_ROOT_DIR_PURPLE=$(shell ${PKG_CONFIG} --variable=datarootdir purple) -include ${srcdir}/Makefile.tl-parser -include ${srcdir}/Makefile.tgl - create_dirs: ${DIR_LIST} -create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto-skip.h ${AUTO}/auto-fetch.h ${AUTO}/auto-store.h ${AUTO}/auto-types.h ${DIR_LIST}: @test -d $@ || mkdir -p $@ @@ -46,9 +38,23 @@ DEPENDENCE_LIST=${DEPENDENCE} -include ${DEPENDENCE_LIST} -${PLUGIN_OBJECTS}: ${OBJ}/%.o: ${srcdir}/%.c | create_dirs_and_headers +# The dependency on tgl/libs/libtgl.a ensures that "make -C tgl" was called, +# and most importantly: It ensures that all automatic headers exist. +${PLUGIN_OBJECTS}: ${OBJ}/%.o: ${srcdir}/%.c ${LIB}/libtgl.a | create_dirs echo $@ && ${CC} ${CFLAGS} ${CPPFLAGS} -I ${srcdir}/tgl -I ${srcdir}/lodepng -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $< +tgl/Makefile.in: + @echo "tgl/Makefile.in not found. Maybe you need to 'git submodule update --init --recursive' ?" && exit 1 + +tgl/Makefile: tgl/Makefile.in + cd tgl && ./configure -q + +tgl/libs/libtgl.a: tgl/Makefile + +make -C tgl + +${LIB}/libtgl.a: tgl/libs/libtgl.a | create_dirs + cp $< $@ + ${PRPL_LIBNAME}: ${PLUGIN_OBJECTS} ${LIB}/libtgl.a | create_dirs ${CC} -shared -o $@ $^ ${LDFLAGS} @@ -98,4 +104,3 @@ debug: install clean: rm -rf ${DIR_LIST} *.so *.a *.o telegram config.log config.status $(PRPL_C_OBJS) $(PRPL_LIBNAME) > /dev/null || echo "all clean" - diff --git a/Makefile.tgl b/Makefile.tgl deleted file mode 100644 index 36a1d41..0000000 --- a/Makefile.tgl +++ /dev/null @@ -1,56 +0,0 @@ -TGL_OBJECTS=${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/tgl.o ${OBJ}/updates.o ${OBJ}/tg-mime-types.o ${OBJ}/mtproto-utils.o - -TGL_OBJECTS_AUTO=${OBJ}/auto/auto-skip.o ${OBJ}/auto/auto-fetch.o ${OBJ}/auto/auto-store.o ${OBJ}/auto/auto-autocomplete.o ${OBJ}/auto/auto-types.o ${OBJ}/auto/auto-fetch-ds.o ${OBJ}/auto/auto-free-ds.o ${OBJ}/auto/auto-store-ds.o ${OBJ}/auto/auto-print-ds.o - - -TLD_OBJECTS=${OBJ}/dump-tl-file.o -GENERATE_OBJECTS=${OBJ}/generate.o -TGL_COMMON_OBJECTS=${OBJ}/tools.o -TGL_OBJ_C=${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${TGL_OBJECTS} ${TLD_OBJECTS} - -AR?=ar - -.SUFFIXES: - -.SUFFIXES: .c .h .o - -dump-tl: ${EXE}/dump-tl-file - -${TGL_OBJECTS}: ${AUTO}/constants.h ${AUTO}/auto-skip.h ${AUTO}/auto-fetch.h ${AUTO}/auto-store.h ${AUTO}/auto-autocomplete.h ${AUTO}/auto-types.h ${AUTO}/auto-fetch-ds.h ${AUTO}/auto-free-ds.h ${AUTO}/auto-store-ds.h ${AUTO}/auto-print-ds.h - -${TGL_OBJ_C}: ${OBJ}/%.o: ${srcdir}/tgl/%.c | create_dirs - ${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $< - -${TGL_OBJECTS_AUTO}: ${OBJ}/auto/%.o: ${AUTO}/%.c | create_dirs - ${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $< - -#${OBJ}/auto/auto.o: ${AUTO}/auto.c -# ${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} - rm -f $@ && ${AR} ruv $@ $^ - -${EXE}/generate: ${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} - ${CC} ${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${LINK_FLAGS} -o $@ - -${AUTO}/scheme.tlo: ${AUTO}/scheme.tl ${EXE}/tl-parser - ${EXE}/tl-parser -e $@ ${AUTO}/scheme.tl - -${AUTO}/scheme.tl: ${srcdir}/tgl/scheme.tl ${srcdir}/tgl/encrypted_scheme.tl ${srcdir}/tgl/binlog.tl ${srcdir}/tgl/append.tl ${srcdir}/tgl/mtproto.tl | ${AUTO} - cat $^ > $@ - -${AUTO}/scheme2.tl: ${AUTO}/scheme.tl ${EXE}/tl-parser - ${EXE}/tl-parser -E ${AUTO}/scheme.tl 2> $@ || ( cat $@ && rm $@ && false ) - -${AUTO}/auto-%.c: ${AUTO}/scheme.tlo ${EXE}/generate auto/constants.h ${AUTO}/auto-%.h | create_dirs_and_headers - ${EXE}/generate -g $(patsubst ${AUTO}/auto-%.c,%,$@) ${AUTO}/scheme.tlo > $@ || rm $@ - -${AUTO}/auto-%.h: ${AUTO}/scheme.tlo ${EXE}/generate - ${EXE}/generate -g $(patsubst ${AUTO}/auto-%.h,%-header,$@) ${AUTO}/scheme.tlo > $@ || rm $@ - -${AUTO}/constants.h: ${AUTO}/scheme2.tl ${srcdir}/tgl/gen_constants_h.awk - awk -f ${srcdir}/tgl/gen_constants_h.awk < $< > $@ - -${EXE}/dump-tl-file: ${OBJ}/auto/auto.o ${TLD_OBJECTS} - ${CC} ${OBJ}/auto/auto.o ${TLD_OBJECTS} ${LINK_FLAGS} -o $@ - diff --git a/Makefile.tl-parser b/Makefile.tl-parser deleted file mode 100644 index ce6c3d9..0000000 --- a/Makefile.tl-parser +++ /dev/null @@ -1,9 +0,0 @@ - -TL_PARSER_OBJECTS=${OBJ}/tl-parser.o ${OBJ}/tlc.o ${OBJ}/crc32.o -ALL_OBJS+=${TL_PARSER_OBJS} - -${TL_PARSER_OBJECTS}: ${OBJ}/%.o: ${srcdir}/tgl/tl-parser/%.c | create_dirs - ${CC} ${INCLUDE} ${COMPILE_FLAGS} -iquote ${srcdir}/tgl/tl-parser -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $< - -${EXE}/tl-parser: ${TL_PARSER_OBJECTS} - ${CC} $^ ${LINK_FLAGS} -o $@ diff --git a/telegram-base.c b/telegram-base.c index 128330c..02836bf 100644 --- a/telegram-base.c +++ b/telegram-base.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -184,7 +185,7 @@ void read_dc (struct tgl_state *TLS, int auth_file_fd, int id, unsigned ver) { assert (read (auth_file_fd, &auth_key_id, 8) == 8); assert (read (auth_file_fd, auth_key, 256) == 256); - bl_do_dc_option (TLS, id, "DC", 2, ip, l, port); + bl_do_dc_option (TLS, 0, id, "DC", 2, ip, l, port); bl_do_set_auth_key (TLS, id, auth_key); bl_do_dc_signed (TLS, id); } @@ -203,16 +204,16 @@ int error_if_val_false (struct tgl_state *TLS, int val, const char *cause, const void empty_auth_file (struct tgl_state *TLS) { if (TLS->test_mode) { - bl_do_dc_option (TLS, 1, "", 0, TG_SERVER_TEST_1, strlen (TG_SERVER_TEST_1), 443); - bl_do_dc_option (TLS, 2, "", 0, TG_SERVER_TEST_2, strlen (TG_SERVER_TEST_2), 443); - bl_do_dc_option (TLS, 3, "", 0, TG_SERVER_TEST_3, strlen (TG_SERVER_TEST_3), 443); + bl_do_dc_option (TLS, 0, 1, "", 0, TG_SERVER_TEST_1, strlen (TG_SERVER_TEST_1), 443); + bl_do_dc_option (TLS, 0, 2, "", 0, TG_SERVER_TEST_2, strlen (TG_SERVER_TEST_2), 443); + bl_do_dc_option (TLS, 0, 3, "", 0, TG_SERVER_TEST_3, strlen (TG_SERVER_TEST_3), 443); bl_do_set_working_dc (TLS, TG_SERVER_TEST_DEFAULT); } else { - bl_do_dc_option (TLS, 1, "", 0, TG_SERVER_1, strlen (TG_SERVER_1), 443); - bl_do_dc_option (TLS, 2, "", 0, TG_SERVER_2, strlen (TG_SERVER_2), 443); - bl_do_dc_option (TLS, 3, "", 0, TG_SERVER_3, strlen (TG_SERVER_3), 443); - bl_do_dc_option (TLS, 4, "", 0, TG_SERVER_4, strlen (TG_SERVER_4), 443); - bl_do_dc_option (TLS, 5, "", 0, TG_SERVER_5, strlen (TG_SERVER_5), 443); + bl_do_dc_option (TLS, 0, 1, "", 0, TG_SERVER_1, strlen (TG_SERVER_1), 443); + bl_do_dc_option (TLS, 0, 2, "", 0, TG_SERVER_2, strlen (TG_SERVER_2), 443); + bl_do_dc_option (TLS, 0, 3, "", 0, TG_SERVER_3, strlen (TG_SERVER_3), 443); + bl_do_dc_option (TLS, 0, 4, "", 0, TG_SERVER_4, strlen (TG_SERVER_4), 443); + bl_do_dc_option (TLS, 0, 5, "", 0, TG_SERVER_5, strlen (TG_SERVER_5), 443); bl_do_set_working_dc (TLS, TG_SERVER_DEFAULT); } } @@ -256,7 +257,7 @@ void read_auth_file (struct tgl_state *TLS) { assert (!l); } if (our_id) { - bl_do_set_our_id (TLS, our_id); + bl_do_set_our_id (TLS, TGL_MK_USER (our_id)); } close (auth_file_fd); } @@ -346,7 +347,7 @@ void read_secret_chat (struct tgl_state *TLS, int fd, int v) { assert (read (fd, &out_seq_no, 4) == 4); } - bl_do_encr_chat_new (TLS, id, + bl_do_encr_chat (TLS, id, &access_hash, &date, &admin_id, &user_id, key, NULL, sha, &state, &ttl, &layer, &in_seq_no, &last_in_seq_no, &out_seq_no, @@ -443,7 +444,7 @@ void tgp_create_group_chat_by_usernames (struct tgl_state *TLS, const char *titl int use_print_names) { tgl_peer_id_t ids[num_users + 1]; int i, j = 0; - ids[j++] = TGL_MK_USER(TLS->our_id); + ids[j++] = TLS->our_id; for (i = 0; i < num_users; i++) if (str_not_empty (users[i])) { tgl_peer_t *P = NULL; if (use_print_names) { @@ -451,7 +452,7 @@ void tgp_create_group_chat_by_usernames (struct tgl_state *TLS, const char *titl } else { P = tgl_peer_get (TLS, TGL_MK_USER(atoi (users[i]))); } - if (P && tgl_get_peer_id (P->id) != TLS->our_id) { + if (P && tgl_get_peer_id (P->id) != tgl_get_peer_id (TLS->our_id)) { debug ("Adding %s: %d", P->print_name, tgl_get_peer_id (P->id)); ids[j++] = P->id; } else { diff --git a/telegram-purple.c b/telegram-purple.c index 8ea7155..980374a 100644 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -58,6 +58,7 @@ #include #include +#include #include #include @@ -123,7 +124,7 @@ static void _update_buddy (struct tgl_state *TLS, tgl_peer_t *user, unsigned fla } static void update_user_handler (struct tgl_state *TLS, struct tgl_user *user, unsigned flags) { - if (TLS->our_id == tgl_get_peer_id (user->id) && flags & TGL_UPDATE_NAME) { + if (tgl_get_peer_id (TLS->our_id) == tgl_get_peer_id (user->id) && flags & TGL_UPDATE_NAME) { p2tgl_connection_set_display_name (TLS, (tgl_peer_t *)user); return; } @@ -213,7 +214,7 @@ static void update_marked_read (struct tgl_state *TLS, int num, struct tgl_messa int i; for (i = 0; i < num; i++) if (list[i]) { tgl_peer_id_t to_id; - if (tgl_get_peer_type (list[i]->to_id) == TGL_PEER_USER && tgl_get_peer_id (list[i]->to_id) == TLS->our_id) { + if (tgl_get_peer_type (list[i]->to_id) == TGL_PEER_USER && tgl_get_peer_id (list[i]->to_id) == tgl_get_peer_id (TLS->our_id)) { to_id = list[i]->from_id; } else { to_id = list[i]->to_id; @@ -320,7 +321,7 @@ static void on_userpic_loaded (struct tgl_state *TLS, void *extra, int success, } static void on_get_dialog_list_done (struct tgl_state *TLS, void *callback_extra, int success, int size, - tgl_peer_id_t peers[], int last_msg_id[], int unread_count[]) { + tgl_peer_id_t peers[], tgl_message_id_t *last_msg_id[], int unread_count[]) { connection_data *conn = TLS->ev_base; @@ -331,7 +332,7 @@ static void on_get_dialog_list_done (struct tgl_state *TLS, void *callback_extra switch (tgl_get_peer_type (peers[i])) { case TGL_PEER_USER: assert (UC); - if (tgl_get_peer_id (UC->id) == TLS->our_id) { + if (tgl_get_peer_id (UC->id) == tgl_get_peer_id (TLS->our_id)) { p2tgl_connection_set_display_name (TLS, UC); continue; } @@ -502,7 +503,7 @@ void export_chat_link_checked (struct tgl_state *TLS, const char *name) { failure ("Chat \"%s\" not found, not exporting link.", name); return; } - if (C->chat.admin_id != TLS->our_id) { + if (C->chat.admin_id != tgl_get_peer_id (TLS->our_id)) { purple_notify_error (_telegram_protocol, "Failure", "Creating Chat Link Failed", "You need to be admin of the group to do that."); return; @@ -517,7 +518,7 @@ void leave_and_delete_chat (PurpleBlistNode *node, gpointer data) { tgl_peer_t *P = tgl_peer_get (conn->TLS, p2tgl_chat_get_id (PC)); if (P && P->chat.users_num) { - tgl_do_del_user_from_chat (conn->TLS, P->id, TGL_MK_USER(conn->TLS->our_id), + tgl_do_del_user_from_chat (conn->TLS, P->id, conn->TLS->our_id, tgp_notify_on_error_gw, NULL); serv_got_chat_left (conn->gc, tgl_get_peer_id (P->id)); } @@ -726,7 +727,7 @@ static void tgprpl_remove_buddy (PurpleConnection *gc, PurpleBuddy *buddy, Purpl /* TODO: implement the api call cancel secret chats. Currently the chat will only be marked as deleted on our side so that it won't be added on startup (when the secret chat file is loaded) */ - bl_do_encr_chat_delete (conn->TLS, &peer->encr_chat); + bl_do_peer_delete (conn->TLS, peer->encr_chat.id); } } @@ -750,7 +751,7 @@ static int tgprpl_send_chat (PurpleConnection * gc, int id, const char *message, connection_data *conn = purple_connection_get_protocol_data (gc); int ret = tgp_msg_send (conn->TLS, message, TGL_MK_CHAT(id)); if (ret != 0) { - p2tgl_got_chat_in (conn->TLS, TGL_MK_CHAT(id), TGL_MK_USER(conn->TLS->our_id), message, + p2tgl_got_chat_in (conn->TLS, TGL_MK_CHAT(id), conn->TLS->our_id, message, PURPLE_MESSAGE_RECV, time(NULL)); } return ret; diff --git a/tgl b/tgl index 126b42c..ed4e304 160000 --- a/tgl +++ b/tgl @@ -1 +1 @@ -Subproject commit 126b42c6d281841acc541735e845d94c54298f46 +Subproject commit ed4e304be425afecdf954e3d88fae98b80e6ff50 diff --git a/tgp-2prpl.c b/tgp-2prpl.c index 56cab9f..7df3a9c 100644 --- a/tgp-2prpl.c +++ b/tgp-2prpl.c @@ -275,7 +275,7 @@ void p2tgl_prpl_got_user_status (struct tgl_state *TLS, tgl_peer_id_t user, stru if (status->online == 1) { p2tgl_prpl_got_set_status_online (TLS, user); } else { - debug ("%d: when=%d", user.id, status->when); + debug ("%d: when=%d", tgl_get_peer_id (user), status->when); if (tgp_time_n_days_ago (purple_account_get_int (data->pa, "inactive-days-offline", TGP_DEFAULT_INACTIVE_DAYS_OFFLINE)) > status->when && status->when) { debug ("offline"); p2tgl_prpl_got_set_status_offline (TLS, user); diff --git a/tgp-chat.c b/tgp-chat.c index b15212d..36a0acb 100644 --- a/tgp-chat.c +++ b/tgp-chat.c @@ -25,6 +25,7 @@ #include "telegram-base.h" #include +#include #include GHashTable *tgp_chat_info_new (struct tgl_state *TLS, struct tgl_chat *chat) { diff --git a/tgp-ft.c b/tgp-ft.c index ad07fd3..200e91d 100644 --- a/tgp-ft.c +++ b/tgp-ft.c @@ -18,6 +18,7 @@ Copyright Matthias Jentsch 2014-2015 */ +#include #include "tgp-utils.h" #include "tgp-ft.h" #include "tgp-structs.h" diff --git a/tgp-msg.c b/tgp-msg.c index 76a606d..1025e10 100644 --- a/tgp-msg.c +++ b/tgp-msg.c @@ -28,6 +28,8 @@ #include #include +#include + #include "telegram-purple.h" #include "telegram-base.h" #include "tgp-structs.h" @@ -115,7 +117,7 @@ static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) { g_free (alias); p2tgl_conv_del_user (TLS, conv, txt_action, M->action.user); - if (M->action.user == TLS->our_id) { + if (M->action.user == tgl_get_peer_id (TLS->our_id)) { purple_conv_chat_left (purple_conversation_get_chat_data (conv)); } diff --git a/tgp-request.c b/tgp-request.c index 270c7cf..9f18e37 100644 --- a/tgp-request.c +++ b/tgp-request.c @@ -22,6 +22,7 @@ #include #include #include +#include #define _(m) m @@ -191,7 +192,7 @@ static void accept_secret_chat_cb (gpointer _data, const gchar *code) { static void decline_secret_chat_cb (gpointer _data, const gchar *code) { struct accept_secret_chat_data *data = _data; - bl_do_encr_chat_delete (data->TLS, data->U); + bl_do_peer_delete (data->TLS, data->U->id); purple_blist_remove_buddy (p2tgl_buddy_find(data->TLS, data->U->id)); g_free (data); diff --git a/tgp-structs.c b/tgp-structs.c index 8c2c314..b34c682 100644 --- a/tgp-structs.c +++ b/tgp-structs.c @@ -27,6 +27,7 @@ #include #include +#include static void pending_reads_free_cb (gpointer data) { free (data); @@ -42,7 +43,7 @@ void pending_reads_send_all (GQueue *queue, struct tgl_state *TLS) { tgl_peer_id_t *pending; while ((pending = (tgl_peer_id_t*) g_queue_pop_head(queue))) { tgl_do_mark_read (TLS, *pending, tgp_notify_on_error_gw, NULL); - debug ("tgl_do_mark_read (%d)", pending->id); + debug ("tgl_do_mark_read (%d)", tgl_get_peer_id (*pending)); free (pending); } } diff --git a/tgp-utils.c b/tgp-utils.c index 62a5a51..a650d73 100644 --- a/tgp-utils.c +++ b/tgp-utils.c @@ -80,7 +80,7 @@ int tgp_outgoing_msg (struct tgl_state *TLS, struct tgl_message *M) { } int tgp_our_msg (struct tgl_state *TLS, struct tgl_message *M) { - return TLS->our_id == tgl_get_peer_id(M->from_id); + return tgl_get_peer_id (TLS->our_id) == tgl_get_peer_id (M->from_id); } tgl_peer_t *find_peer_by_name (struct tgl_state *TLS, const char *who) { @@ -94,7 +94,7 @@ tgl_peer_t *find_peer_by_name (struct tgl_state *TLS, const char *who) { } tgl_peer_t *tgp_encr_chat_get_partner (struct tgl_state *TLS, struct tgl_secret_chat *chat) { - return tgl_peer_get (TLS, TGL_MK_USER(chat->admin_id == TLS->our_id ? chat->user_id : chat->admin_id)); + return tgl_peer_get (TLS, TGL_MK_USER(chat->admin_id == tgl_get_peer_id (TLS->our_id) ? chat->user_id : chat->admin_id)); } long tgp_time_n_days_ago (int days) {