# HG changeset patch # User Mikael Berthe # Date 1164667180 -3600 # Node ID 6eb1efea75d01e59a43ea0ba1ae323d65f4f24db # Parent 082d55152a258a739a637d8780c1919562309e79 PGP: Visual encryption flag diff -r 082d55152a25 -r 6eb1efea75d0 mcabber/src/commands.c --- a/mcabber/src/commands.c Mon Nov 27 21:40:26 2006 +0100 +++ b/mcabber/src/commands.c Mon Nov 27 23:39:40 2006 +0100 @@ -295,6 +295,7 @@ static void send_message(const char *msg, const char *subj) { const char *jid; + guint crypted; if (!jb_getonline()) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); @@ -312,6 +313,11 @@ return; } + // Network part + jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL, + &crypted); + + // Hook if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { // local part (UI, logging, etc.) gchar *hmsg; @@ -319,12 +325,9 @@ hmsg = g_strdup_printf("[%s]\n%s", subj, msg); else hmsg = (char*)msg; - hk_message_out(jid, NULL, 0, hmsg); + hk_message_out(jid, NULL, 0, hmsg, crypted); if (hmsg != msg) g_free(hmsg); } - - // Network part - jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL); } // process_command(line) @@ -902,6 +905,7 @@ { char *bare_jid, *rp; char *hmsg; + guint crypted; if (!jid || !*jid) { scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID."); @@ -937,11 +941,12 @@ else hmsg = (char*)msg; - hk_message_out(bare_jid, rp, 0, hmsg); - if (hmsg != msg) g_free(hmsg); + // Network part + jb_send_msg(jid, msg, ROSTER_TYPE_USER, subj, NULL, &crypted); - // Network part - jb_send_msg(jid, msg, ROSTER_TYPE_USER, subj, NULL); + // Hook + hk_message_out(bare_jid, rp, 0, hmsg, crypted); + if (hmsg != msg) g_free(hmsg); if (rp) g_free(bare_jid); return 0; @@ -2047,7 +2052,7 @@ arg = to_utf8(arg); // Set the topic msg = g_strdup_printf("%s has set the topic to: %s", mkcmdstr("me"), arg); - jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg, NULL); + jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg, NULL, NULL); g_free(arg); g_free(msg); } diff -r 082d55152a25 -r 6eb1efea75d0 mcabber/src/hbuf.h --- a/mcabber/src/hbuf.h Mon Nov 27 21:40:26 2006 +0100 +++ b/mcabber/src/hbuf.h Mon Nov 27 23:39:40 2006 +0100 @@ -24,6 +24,7 @@ #define HBB_PREFIX_HLIGHT 128U #define HBB_PREFIX_NONE 256U #define HBB_PREFIX_SPECIAL 512U +#define HBB_PREFIX_PGPCRYPT 1024U typedef struct { time_t timestamp; diff -r 082d55152a25 -r 6eb1efea75d0 mcabber/src/hooks.c --- a/mcabber/src/hooks.c Mon Nov 27 21:40:26 2006 +0100 +++ b/mcabber/src/hooks.c Mon Nov 27 23:39:40 2006 +0100 @@ -34,7 +34,8 @@ static char *extcmd; inline void hk_message_in(const char *jid, const char *resname, - time_t timestamp, const char *msg, const char *type) + time_t timestamp, const char *msg, const char *type, + guint encrypted) { int new_guy = FALSE; int is_groupchat = FALSE; // groupchat message @@ -45,6 +46,9 @@ char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; GSList *roster_usr; + if (encrypted) + message_flags |= HBB_PREFIX_PGPCRYPT; + if (type && !strcmp(type, "groupchat")) { rtype = ROSTER_TYPE_ROOM; is_groupchat = TRUE; @@ -165,7 +169,7 @@ // nick should be set for private messages in a chat room, and null for // normal messages. inline void hk_message_out(const char *jid, const char *nick, - time_t timestamp, const char *msg) + time_t timestamp, const char *msg, guint encrypted) { char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; @@ -184,7 +188,7 @@ // Note: the hlog_write should not be called first, because in some // cases scr_WriteOutgoingMessage() will load the history and we'd // have the message twice... - scr_WriteOutgoingMessage(jid, wmsg); + scr_WriteOutgoingMessage(jid, wmsg, (encrypted ? HBB_PREFIX_PGPCRYPT : 0)); // We don't log private messages if (!nick) hlog_write_message(jid, timestamp, TRUE, msg); diff -r 082d55152a25 -r 6eb1efea75d0 mcabber/src/hooks.h --- a/mcabber/src/hooks.h Mon Nov 27 21:40:26 2006 +0100 +++ b/mcabber/src/hooks.h Mon Nov 27 23:39:40 2006 +0100 @@ -6,9 +6,10 @@ inline void hk_message_in(const char *jid, const char *resname, - time_t timestamp, const char *msg, const char *type); + time_t timestamp, const char *msg, const char *type, + guint encrypted); inline void hk_message_out(const char *jid, const char *nickname, - time_t timestamp, const char *msg); + time_t timestamp, const char *msg, guint encrypted); inline void hk_statuschange(const char *jid, const char *resname, gchar prio, time_t timestamp, enum imstatus status, char const *status_msg); diff -r 082d55152a25 -r 6eb1efea75d0 mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Mon Nov 27 21:40:26 2006 +0100 +++ b/mcabber/src/jabglue.c Mon Nov 27 23:39:40 2006 +0100 @@ -506,8 +506,11 @@ return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); } +// jb_send_msg(jid, test, type, subject, msgid, *encrypted) +// When encrypted is not NULL, the function set *encrypted to TRUE if the +// message has been PGP-encrypted. void jb_send_msg(const char *jid, const char *text, int type, - const char *subject, const char *msgid) + const char *subject, const char *msgid, guint *encrypted) { xmlnode x; gchar *strtype; @@ -522,6 +525,9 @@ #endif gchar *enc = NULL; + if (encrypted) + *encrypted = FALSE; + if (!online) return; if (type == ROSTER_TYPE_ROOM) @@ -562,6 +568,8 @@ y = xmlnode_insert_tag(x, "x"); xmlnode_put_attrib(y, "xmlns", NS_ENCRYPTED); xmlnode_insert_cdata(y, enc, (unsigned) -1); + if (encrypted) + *encrypted = TRUE; g_free(enc); } @@ -1546,7 +1554,8 @@ (roster_getsubscription(jid) & sub_from) || (type && strcmp(type, "chat")) || ((s = settings_opt_get("server")) != NULL && !strcasecmp(jid, s))) { - hk_message_in(jid, rname, timestamp, body, type); + hk_message_in(jid, rname, timestamp, body, type, + (decrypted ? TRUE : FALSE)); } else { scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", jid); } diff -r 082d55152a25 -r 6eb1efea75d0 mcabber/src/jabglue.h --- a/mcabber/src/jabglue.h Mon Nov 27 21:40:26 2006 +0100 +++ b/mcabber/src/jabglue.h Mon Nov 27 23:39:40 2006 +0100 @@ -62,7 +62,7 @@ int do_not_sign); inline void jb_setprevstatus(void); void jb_send_msg(const char *jid, const char *text, int type, - const char *subject, const char *id); + const char *subject, const char *id, guint *encrypted); void jb_send_raw(const char *str); void jb_send_chatstate(gpointer buddy, guint chatstate); void jb_keepalive(void); diff -r 082d55152a25 -r 6eb1efea75d0 mcabber/src/screen.c --- a/mcabber/src/screen.c Mon Nov 27 21:40:26 2006 +0100 +++ b/mcabber/src/screen.c Mon Nov 27 23:39:40 2006 +0100 @@ -568,9 +568,11 @@ dir = '>'; wprintw(win_entry->win, "%.11s #%c# ", date, dir); } else if (line->flags & HBB_PREFIX_IN) { - wprintw(win_entry->win, "%.11s <== ", date); + char crypt = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '='; + wprintw(win_entry->win, "%.11s <%c= ", date, crypt); } else if (line->flags & HBB_PREFIX_OUT) { - wprintw(win_entry->win, "%.11s --> ", date); + char crypt = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '-'; + wprintw(win_entry->win, "%.11s -%c> ", date, crypt); } else if (line->flags & HBB_PREFIX_SPECIAL) { strftime(date, 30, "%m-%d %H:%M:%S", localtime(&line->timestamp)); wprintw(win_entry->win, "%.14s ", date); @@ -1355,16 +1357,17 @@ void scr_WriteIncomingMessage(const char *jidfrom, const char *text, time_t timestamp, guint prefix) { - if (!(prefix & ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT)) + if (!(prefix & + ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_PGPCRYPT)) prefix |= HBB_PREFIX_IN; scr_WriteMessage(jidfrom, text, timestamp, prefix); update_panels(); } -void scr_WriteOutgoingMessage(const char *jidto, const char *text) +void scr_WriteOutgoingMessage(const char *jidto, const char *text, guint prefix) { - scr_WriteMessage(jidto, text, 0, HBB_PREFIX_OUT|HBB_PREFIX_HLIGHT); + scr_WriteMessage(jidto, text, 0, prefix|HBB_PREFIX_OUT|HBB_PREFIX_HLIGHT); scr_ShowWindow(jidto, FALSE); } diff -r 082d55152a25 -r 6eb1efea75d0 mcabber/src/screen.h --- a/mcabber/src/screen.h Mon Nov 27 21:40:26 2006 +0100 +++ b/mcabber/src/screen.h Mon Nov 27 23:39:40 2006 +0100 @@ -81,8 +81,9 @@ void scr_UpdateChatStatus(int forceupdate); void scr_RosterVisibility(int status); void scr_WriteIncomingMessage(const char *jidfrom, const char *text, - time_t timestamp, guint prefix); -void scr_WriteOutgoingMessage(const char *jidto, const char *text); + time_t timestamp, guint prefix); +void scr_WriteOutgoingMessage(const char *jidto, const char *text, + guint prefix); void scr_ShowBuddyWindow(void); int scr_BuddyBufferExists(const char *jid); inline void scr_UpdateBuddyWindow(void);