comparison 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
comparison
equal deleted inserted replaced
1196:d657a13fd71a 1197:6f602d3270a4
245 compl_add_category_word(COMPL_EVENTS, "reject"); 245 compl_add_category_word(COMPL_EVENTS, "reject");
246 246
247 // PGP category 247 // PGP category
248 compl_add_category_word(COMPL_PGP, "disable"); 248 compl_add_category_word(COMPL_PGP, "disable");
249 compl_add_category_word(COMPL_PGP, "enable"); 249 compl_add_category_word(COMPL_PGP, "enable");
250 compl_add_category_word(COMPL_PGP, "force");
250 compl_add_category_word(COMPL_PGP, "info"); 251 compl_add_category_word(COMPL_PGP, "info");
251 compl_add_category_word(COMPL_PGP, "setkey"); 252 compl_add_category_word(COMPL_PGP, "setkey");
252 } 253 }
253 254
254 // expandalias(line) 255 // expandalias(line)
320 // Write the message in the buddy's window and send the message on 321 // Write the message in the buddy's window and send the message on
321 // the network. 322 // the network.
322 static void send_message(const char *msg, const char *subj) 323 static void send_message(const char *msg, const char *subj)
323 { 324 {
324 const char *bjid; 325 const char *bjid;
325 guint crypted; 326 gint crypted;
326 327
327 if (!jb_getonline()) { 328 if (!jb_getonline()) {
328 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); 329 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
329 return; 330 return;
330 } 331 }
341 } 342 }
342 343
343 // Network part 344 // Network part
344 jb_send_msg(bjid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL, 345 jb_send_msg(bjid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL,
345 &crypted); 346 &crypted);
347
348 if (crypted == -1) {
349 scr_LogPrint(LPRINT_LOGNORM, "Encryption error. Message was not sent.");
350 return;
351 }
346 352
347 // Hook 353 // Hook
348 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { 354 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) {
349 // local part (UI, logging, etc.) 355 // local part (UI, logging, etc.)
350 gchar *hmsg; 356 gchar *hmsg;
952 958
953 static int send_message_to(const char *fjid, const char *msg, const char *subj) 959 static int send_message_to(const char *fjid, const char *msg, const char *subj)
954 { 960 {
955 char *bare_jid, *rp; 961 char *bare_jid, *rp;
956 char *hmsg; 962 char *hmsg;
957 guint crypted; 963 gint crypted;
964 gint retval = 0;
958 965
959 if (!fjid || !*fjid) { 966 if (!fjid || !*fjid) {
960 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID."); 967 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID.");
961 return 1; 968 return 1;
962 } 969 }
992 hmsg = (char*)msg; 999 hmsg = (char*)msg;
993 1000
994 // Network part 1001 // Network part
995 jb_send_msg(fjid, msg, ROSTER_TYPE_USER, subj, NULL, &crypted); 1002 jb_send_msg(fjid, msg, ROSTER_TYPE_USER, subj, NULL, &crypted);
996 1003
1004 if (crypted == -1) {
1005 scr_LogPrint(LPRINT_LOGNORM, "Encryption error. Message was not sent.");
1006 retval = 1;
1007 goto send_message_to_return;
1008 }
1009
997 // Hook 1010 // Hook
998 hk_message_out(bare_jid, rp, 0, hmsg, crypted); 1011 hk_message_out(bare_jid, rp, 0, hmsg, crypted);
1012
1013 send_message_to_return:
999 if (hmsg != msg) g_free(hmsg); 1014 if (hmsg != msg) g_free(hmsg);
1000
1001 if (rp) g_free(bare_jid); 1015 if (rp) g_free(bare_jid);
1002 return 0; 1016 return retval;
1003 } 1017 }
1004 1018
1005 static void do_say(char *arg) 1019 static void do_say(char *arg)
1006 { 1020 {
1007 gpointer bud; 1021 gpointer bud;
2638 enum { 2652 enum {
2639 pgp_none, 2653 pgp_none,
2640 pgp_enable, 2654 pgp_enable,
2641 pgp_disable, 2655 pgp_disable,
2642 pgp_setkey, 2656 pgp_setkey,
2657 pgp_force,
2643 pgp_info 2658 pgp_info
2644 } op = 0; 2659 } op = 0;
2660 int force = FALSE;
2645 2661
2646 paramlst = split_arg(arg, 3, 0); // subcmd, jid, [key] 2662 paramlst = split_arg(arg, 3, 0); // subcmd, jid, [key]
2647 subcmd = *paramlst; 2663 subcmd = *paramlst;
2648 fjid = *(paramlst+1); 2664 fjid = *(paramlst+1);
2649 keyid = *(paramlst+2); 2665 keyid = *(paramlst+2);
2658 op = pgp_enable; 2674 op = pgp_enable;
2659 else if (!strcasecmp(subcmd, "disable")) 2675 else if (!strcasecmp(subcmd, "disable"))
2660 op = pgp_disable; 2676 op = pgp_disable;
2661 else if (!strcasecmp(subcmd, "setkey")) 2677 else if (!strcasecmp(subcmd, "setkey"))
2662 op = pgp_setkey; 2678 op = pgp_setkey;
2679 else if ((!strcasecmp(subcmd, "force")) ||
2680 (!strcasecmp(subcmd, "+force"))) {
2681 op = pgp_force;
2682 force = TRUE;
2683 } else if (!strcasecmp(subcmd, "-force"))
2684 op = pgp_force;
2663 else if (!strcasecmp(subcmd, "info")) 2685 else if (!strcasecmp(subcmd, "info"))
2664 op = pgp_info; 2686 op = pgp_info;
2665 } 2687 }
2666 2688
2667 if (!op) { 2689 if (!op) {
2700 scr_LogPrint(LPRINT_NORMAL, "The selected item should be a user."); 2722 scr_LogPrint(LPRINT_NORMAL, "The selected item should be a user.");
2701 } 2723 }
2702 } 2724 }
2703 2725
2704 if (fjid) { // fjid is actually a bare jid... 2726 if (fjid) { // fjid is actually a bare jid...
2727 guint disabled;
2705 GString *sbuf; 2728 GString *sbuf;
2706 switch (op) { 2729 switch (op) {
2707 case pgp_enable: 2730 case pgp_enable:
2708 case pgp_disable: 2731 case pgp_disable:
2709 settings_pgp_setdisabled(fjid, (op == pgp_disable ? TRUE : FALSE)); 2732 settings_pgp_setdisabled(fjid, (op == pgp_disable ? TRUE : FALSE));
2733 break;
2734 case pgp_force:
2735 settings_pgp_setforce(fjid, force);
2710 break; 2736 break;
2711 case pgp_setkey: 2737 case pgp_setkey:
2712 settings_pgp_setkeyid(fjid, keyid); 2738 settings_pgp_setkeyid(fjid, keyid);
2713 break; 2739 break;
2714 case pgp_info: 2740 case pgp_info:
2716 if (settings_pgp_getkeyid(fjid)) { 2742 if (settings_pgp_getkeyid(fjid)) {
2717 g_string_printf(sbuf, "PGP Encryption key id: %s", 2743 g_string_printf(sbuf, "PGP Encryption key id: %s",
2718 settings_pgp_getkeyid(fjid)); 2744 settings_pgp_getkeyid(fjid));
2719 scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO); 2745 scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO);
2720 } 2746 }
2747 disabled = settings_pgp_getdisabled(fjid);
2721 g_string_printf(sbuf, "PGP encryption is %s", 2748 g_string_printf(sbuf, "PGP encryption is %s",
2722 (settings_pgp_getdisabled(fjid) ? "disabled" : 2749 (disabled ? "disabled" : "enabled"));
2723 "enabled"));
2724 scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO); 2750 scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO);
2751 if (!disabled && settings_pgp_getforce(fjid)) {
2752 scr_WriteIncomingMessage(fjid,
2753 "Encryption enforced (no negotiation)",
2754 0, HBB_PREFIX_INFO);
2755 }
2725 g_string_free(sbuf, TRUE); 2756 g_string_free(sbuf, TRUE);
2726 break; 2757 break;
2727 default: 2758 default:
2728 break; 2759 break;
2729 } 2760 }