Mercurial > hg
diff mcabber/src/commands.c @ 1197:6f602d3270a4
Add /pgp [-]force
With this command it becomes possible to enforce PGP encryption without
checking if the remote client has PGP support. It can be used to send
encrypted offline messages too.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 27 Apr 2007 00:37:57 +0200 |
parents | 7b8765c10abb |
children | ede6c7aa59b0 |
line wrap: on
line diff
--- a/mcabber/src/commands.c Sun Apr 22 15:01:20 2007 +0200 +++ b/mcabber/src/commands.c Fri Apr 27 00:37:57 2007 +0200 @@ -247,6 +247,7 @@ // PGP category compl_add_category_word(COMPL_PGP, "disable"); compl_add_category_word(COMPL_PGP, "enable"); + compl_add_category_word(COMPL_PGP, "force"); compl_add_category_word(COMPL_PGP, "info"); compl_add_category_word(COMPL_PGP, "setkey"); } @@ -322,7 +323,7 @@ static void send_message(const char *msg, const char *subj) { const char *bjid; - guint crypted; + gint crypted; if (!jb_getonline()) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); @@ -344,6 +345,11 @@ jb_send_msg(bjid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL, &crypted); + if (crypted == -1) { + scr_LogPrint(LPRINT_LOGNORM, "Encryption error. Message was not sent."); + return; + } + // Hook if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { // local part (UI, logging, etc.) @@ -954,7 +960,8 @@ { char *bare_jid, *rp; char *hmsg; - guint crypted; + gint crypted; + gint retval = 0; if (!fjid || !*fjid) { scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID."); @@ -994,12 +1001,19 @@ // Network part jb_send_msg(fjid, msg, ROSTER_TYPE_USER, subj, NULL, &crypted); + if (crypted == -1) { + scr_LogPrint(LPRINT_LOGNORM, "Encryption error. Message was not sent."); + retval = 1; + goto send_message_to_return; + } + // Hook hk_message_out(bare_jid, rp, 0, hmsg, crypted); + +send_message_to_return: if (hmsg != msg) g_free(hmsg); - if (rp) g_free(bare_jid); - return 0; + return retval; } static void do_say(char *arg) @@ -2640,8 +2654,10 @@ pgp_enable, pgp_disable, pgp_setkey, + pgp_force, pgp_info } op = 0; + int force = FALSE; paramlst = split_arg(arg, 3, 0); // subcmd, jid, [key] subcmd = *paramlst; @@ -2660,6 +2676,12 @@ op = pgp_disable; else if (!strcasecmp(subcmd, "setkey")) op = pgp_setkey; + else if ((!strcasecmp(subcmd, "force")) || + (!strcasecmp(subcmd, "+force"))) { + op = pgp_force; + force = TRUE; + } else if (!strcasecmp(subcmd, "-force")) + op = pgp_force; else if (!strcasecmp(subcmd, "info")) op = pgp_info; } @@ -2702,12 +2724,16 @@ } if (fjid) { // fjid is actually a bare jid... + guint disabled; GString *sbuf; switch (op) { case pgp_enable: case pgp_disable: settings_pgp_setdisabled(fjid, (op == pgp_disable ? TRUE : FALSE)); break; + case pgp_force: + settings_pgp_setforce(fjid, force); + break; case pgp_setkey: settings_pgp_setkeyid(fjid, keyid); break; @@ -2718,10 +2744,15 @@ settings_pgp_getkeyid(fjid)); scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO); } + disabled = settings_pgp_getdisabled(fjid); g_string_printf(sbuf, "PGP encryption is %s", - (settings_pgp_getdisabled(fjid) ? "disabled" : - "enabled")); + (disabled ? "disabled" : "enabled")); scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO); + if (!disabled && settings_pgp_getforce(fjid)) { + scr_WriteIncomingMessage(fjid, + "Encryption enforced (no negotiation)", + 0, HBB_PREFIX_INFO); + } g_string_free(sbuf, TRUE); break; default: