From 03086c03841d2f1b44d086d4d17838abf5fb1e4c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 11 Jan 2014 19:10:00 +0000 Subject: [PATCH] Added /otr theirfp with hardcoded fingerprint --- src/command/commands.c | 17 ++++++++++++++++- src/otr.c | 9 ++++++++- src/otr.h | 3 ++- src/ui/console.c | 2 +- src/ui/core.c | 11 +++++++---- src/ui/window.c | 10 ++++++++++ src/ui/window.h | 4 +++- 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 6d9479b7..4eb8a645 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2312,8 +2312,23 @@ cmd_otr(gchar **args, struct cmd_help_t help) otr_keygen(account); return TRUE; } else if (strcmp(args[0], "myfp") == 0) { - char *fingerprint = otr_get_fingerprint(); + char *fingerprint = otr_get_my_fingerprint(); cons_show("Your fingerprint: %s", fingerprint); + free(fingerprint); + return TRUE; + } else if (strcmp(args[0], "theirfp") == 0) { + win_type_t win_type = ui_current_win_type(); + + if (win_type != WIN_CHAT) { + ui_current_print_line("You must be in a regular chat window to view a recipient's fingerprint."); + } else if (!ui_current_win_is_otr()) { + ui_current_print_line("You not currently in an OTR session with this recipient."); + } else { + char *recipient = ui_current_recipient(); + char *fingerprint = otr_get_their_fingerprint(recipient); + ui_current_print_line("OTR fingerprint for %s: %s", recipient, fingerprint); + free(fingerprint); + } return TRUE; } else if (strcmp(args[0], "start") == 0) { win_type_t win_type = ui_current_win_type(); diff --git a/src/otr.c b/src/otr.c index 42a02e96..52ce6540 100644 --- a/src/otr.c +++ b/src/otr.c @@ -333,7 +333,7 @@ otr_key_loaded(void) } char * -otr_get_fingerprint(void) +otr_get_my_fingerprint(void) { char fingerprint[45]; otrl_privkey_fingerprint(user_state, fingerprint, jid, "xmpp"); @@ -342,6 +342,13 @@ otr_get_fingerprint(void) return result; } +char * +otr_get_their_fingerprint(char *recipient) +{ + char *fingerprint = "1234 5678"; + return strdup(fingerprint); +} + char * otr_encrypt_message(const char * const to, const char * const message) { diff --git a/src/otr.h b/src/otr.h index 59477ab0..5008b2d3 100644 --- a/src/otr.h +++ b/src/otr.h @@ -31,7 +31,8 @@ void otr_keygen(ProfAccount *account); gboolean otr_key_loaded(void); -char * otr_get_fingerprint(void); +char * otr_get_my_fingerprint(void); +char * otr_get_their_fingerprint(char *recipient); char * otr_encrypt_message(const char * const to, const char * const message); char * otr_decrypt_message(const char * const from, const char * const message); diff --git a/src/ui/console.c b/src/ui/console.c index c02201f9..afdc1776 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -131,7 +131,7 @@ _cons_show_typing(const char * const barejid) display_usr = barejid; } - win_print_line(console, '-', COLOUR_TYPING, "!! %s is typing a message...", display_usr); + win_vprint_line(console, '-', COLOUR_TYPING, "!! %s is typing a message...", display_usr); wins_refresh_console(); cons_alert(); diff --git a/src/ui/core.c b/src/ui/core.c index 41fd31e8..74a4d66e 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -746,8 +746,11 @@ _ui_current_print_line(const char * const msg, ...) ProfWin *current = wins_get_current(); va_list arg; va_start(arg, msg); - win_print_line(current, '-', 0, msg, arg); + GString *fmt_msg = g_string_new(NULL); + g_string_vprintf(fmt_msg, msg, arg); + win_print_line(current, '-', 0, fmt_msg->str); va_end(arg); + g_string_free(fmt_msg, TRUE); win_refresh(current); } @@ -775,7 +778,7 @@ _ui_print_error_from_recipient(const char * const from, const char *err_msg) ProfWin *window = wins_get_by_recipient(from); if (window != NULL) { - win_print_line(window, '-', COLOUR_ERROR, "%s", err_msg); + win_vprint_line(window, '-', COLOUR_ERROR, "%s", err_msg); if (wins_is_current(window)) { wins_refresh_current(); } @@ -833,7 +836,7 @@ _ui_recipient_gone(const char * const barejid) ProfWin *window = wins_get_by_recipient(barejid); if (window != NULL) { - win_print_line(window, '!', COLOUR_GONE, "<- %s has left the conversation.", display_usr); + win_vprint_line(window, '!', COLOUR_GONE, "<- %s has left the conversation.", display_usr); if (wins_is_current(window)) { wins_refresh_current(); } @@ -1329,7 +1332,7 @@ _ui_status_room(const char * const contact) if (pcontact != NULL) { win_show_contact(current, pcontact); } else { - win_print_line(current, '-', 0, "No such participant \"%s\" in room.", contact); + win_vprint_line(current, '-', 0, "No such participant \"%s\" in room.", contact); } } diff --git a/src/ui/window.c b/src/ui/window.c index 6d6df429..370f876c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -84,6 +84,16 @@ win_print_time(ProfWin* window, char show_char) void win_print_line(ProfWin *window, const char show_char, int attrs, + const char * const msg) +{ + win_print_time(window, show_char); + wattron(window->win, attrs); + wprintw(window->win, "%s\n", msg); + wattroff(window->win, attrs); +} + +void +win_vprint_line(ProfWin *window, const char show_char, int attrs, const char * const msg, ...) { va_list arg; diff --git a/src/ui/window.h b/src/ui/window.h index fabf8ae6..752787dc 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -58,8 +58,10 @@ typedef struct prof_win_t { ProfWin* win_create(const char * const title, int cols, win_type_t type); void win_free(ProfWin *window); -void win_print_line(ProfWin *self, const char show_char, int attrs, +void win_vprint_line(ProfWin *self, const char show_char, int attrs, const char * const msg, ...); +void win_print_line(ProfWin *self, const char show_char, int attrs, + const char * const msg); void win_refresh(ProfWin *window); void win_page_off(ProfWin *window); void win_print_time(ProfWin *window, char show_char);