From b1fb7e500caa286931786de318c7f3d89ec39cd6 Mon Sep 17 00:00:00 2001 From: mjentsch Date: Tue, 8 Dec 2015 11:24:01 +0100 Subject: [PATCH] Improve logging of peer flags --- msglog.c | 20 ++++++++++++++++++++ msglog.h | 1 + telegram-purple.c | 16 ++++++++-------- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/msglog.c b/msglog.c index 6a3f211..67dffa7 100644 --- a/msglog.c +++ b/msglog.c @@ -129,6 +129,26 @@ const char *print_flags_channel (unsigned flags) { return text; } +const char *print_flags_user (unsigned flags) { + static char *text; + if (text) { + g_free (text); + text = NULL; + } + const char *names[] = { + "CONTACT", + "MUTUAL_CONTACT", + "BLOCKED", + "SELF", + "BOT" + }; + text = g_strdup (print_flags_peer (flags)); + char *old = text; + text = g_strconcat (text, " ", print_flags (names, 5, flags >> 16), NULL); + g_free (old); + return text; +} + const char *print_flags_update (unsigned flags) { const char *names[] = { "CREATED", diff --git a/msglog.h b/msglog.h index 4c43954..3df9426 100644 --- a/msglog.h +++ b/msglog.h @@ -27,3 +27,4 @@ void fatal(const char* format, ...); const char *print_flags_update (unsigned update); const char *print_flags_channel (unsigned flags); const char *print_flags_peer (unsigned flags); +const char *print_flags_user (unsigned flags); diff --git a/telegram-purple.c b/telegram-purple.c index 425f13d..1698247 100644 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -81,7 +81,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) { - debug ("update_user_handler() flags: %s", print_flags_update (flags)); + debug ("update_user_handler() (%s)", print_flags_update (flags)); if (tgl_get_peer_id (TLS->our_id) == tgl_get_peer_id (user->id) && (flags & (TGL_UPDATE_NAME | TGL_UPDATE_CONTACT))) { // own user object, do not add that user to the buddy list but make the ID known to the name lookup and @@ -94,7 +94,7 @@ static void update_user_handler (struct tgl_state *TLS, struct tgl_user *user, u if (flags & TGL_UPDATE_CREATED) { // new user was allocated, fetch the corresponding buddy from the buddy list PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, user->id); - debug ("new user %s allocated flags: %s", user->print_name, print_flags_peer (flags)); + debug ("new user %s allocated (%s)", user->print_name, print_flags_user (user->flags)); // the buddy doesn't exist, if it is stored in the legacy naming format find and migrate it. This // should only happen when making the switch from a version < 1.2.2 to a version >= 1.2.2 @@ -129,12 +129,12 @@ static void update_user_handler (struct tgl_state *TLS, struct tgl_user *user, u } static void update_channel_handler (struct tgl_state *TLS, struct tgl_channel *C, unsigned flags) { - debug ("update_channel_handler() flags: %s", print_flags_update (flags)); + debug ("update_channel_handler() (%s)", print_flags_update (flags)); assert (TLS); if (flags & TGL_UPDATE_CREATED) { PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, C->id); - debug ("new channel '%s' allocated flags: %s", C->title, print_flags_channel (C->flags)); + debug ("channel allocated '%s' (%s)", C->title, print_flags_channel (C->flags)); if (buddy) { tgp_blist_peer_add_purple_name (TLS, C->id, purple_buddy_get_name (buddy)); if (C->title && strcmp (C->title, purple_buddy_get_name (buddy))) { @@ -146,7 +146,7 @@ static void update_channel_handler (struct tgl_state *TLS, struct tgl_channel *C } } else { if (flags & TGL_UPDATE_FLAGS) { - debug ("channel updated flags '%s': new flags %s", C->title, print_flags_channel (C->flags)); + debug ("channel updated flags '%s' to (%s)", C->title, print_flags_channel (C->flags)); if (C->flags & TGLCHF_LEFT) { PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, C->id); if (buddy) { @@ -161,7 +161,7 @@ static void update_channel_handler (struct tgl_state *TLS, struct tgl_channel *C } static void update_secret_chat_handler (struct tgl_state *TLS, struct tgl_secret_chat *U, unsigned flags) { - debug ("update_secret_chat_handler() flags: %s", print_flags_update (flags)); + debug ("update_secret_chat_handler() (%s)", print_flags_update (flags)); PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, U->id); if (flags & TGL_UPDATE_CREATED) { @@ -205,10 +205,10 @@ static void update_secret_chat_handler (struct tgl_state *TLS, struct tgl_secret } static void update_chat_handler (struct tgl_state *TLS, struct tgl_chat *chat, unsigned flags) { - debug ("update_chat_handler() flags: %s", print_flags_update(flags)); + debug ("update_chat_handler() (%s)", print_flags_update(flags)); if (flags & TGL_UPDATE_CREATED) { - debug ("new chat '%s' allocated flags: %s", chat->title, print_flags_peer (chat->flags)); + debug ("new chat '%s' allocated (%s)", chat->title, print_flags_peer (chat->flags)); tgp_blist_peer_add_purple_name (TLS, chat->id, chat->print_title); } if (! (flags & TGL_UPDATE_CREATED)) {