comparison mcabber/src/commands.c @ 636:f84cce8382e8

Add "/msay send_to"
author Mikael Berthe <mikael@lilotux.net>
date Mon, 26 Dec 2005 13:14:40 +0100
parents 423c24e5875a
children f6946251acdf
comparison
equal deleted inserted replaced
635:d4119cb85aeb 636:f84cce8382e8
154 154
155 // Multi-line (msay) category 155 // Multi-line (msay) category
156 compl_add_category_word(COMPL_MULTILINE, "abort"); 156 compl_add_category_word(COMPL_MULTILINE, "abort");
157 compl_add_category_word(COMPL_MULTILINE, "begin"); 157 compl_add_category_word(COMPL_MULTILINE, "begin");
158 compl_add_category_word(COMPL_MULTILINE, "send"); 158 compl_add_category_word(COMPL_MULTILINE, "send");
159 compl_add_category_word(COMPL_MULTILINE, "send_to");
159 compl_add_category_word(COMPL_MULTILINE, "verbatim"); 160 compl_add_category_word(COMPL_MULTILINE, "verbatim");
160 161
161 // Room category 162 // Room category
162 compl_add_category_word(COMPL_ROOM, "affil"); 163 compl_add_category_word(COMPL_ROOM, "affil");
163 compl_add_category_word(COMPL_ROOM, "ban"); 164 compl_add_category_word(COMPL_ROOM, "ban");
247 } 248 }
248 249
249 // send_message(msg) 250 // send_message(msg)
250 // Write the message in the buddy's window and send the message on 251 // Write the message in the buddy's window and send the message on
251 // the network. 252 // the network.
252 void send_message(const char *msg) 253 static void send_message(const char *msg)
253 { 254 {
254 const char *jid; 255 const char *jid;
255 256
256 if (!jb_getonline()) { 257 if (!jb_getonline()) {
257 scr_LogPrint(LPRINT_NORMAL, "You are not connected"); 258 scr_LogPrint(LPRINT_NORMAL, "You are not connected");
609 buddylist_build(); 610 buddylist_build();
610 update_roster = TRUE; 611 update_roster = TRUE;
611 if (leave_windowbuddy) scr_ShowBuddyWindow(); 612 if (leave_windowbuddy) scr_ShowBuddyWindow();
612 } 613 }
613 614
615 static int send_message_to(const char *jid, const char *msg)
616 {
617 char *bare_jid, *rp;
618
619 if (!jid || !*jid) {
620 scr_LogPrint(LPRINT_NORMAL, "JID is missing");
621 return 1;
622 }
623 if (!msg || !*msg) {
624 scr_LogPrint(LPRINT_NORMAL, "Message is missing");
625 return 1;
626 }
627 if (check_jid_syntax((char*)jid)) {
628 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid);
629 return 1;
630 }
631
632 // We must use the bare jid in hk_message_out()
633 rp = strchr(jid, '/');
634 if (rp) bare_jid = g_strndup(jid, rp - jid);
635 else bare_jid = (char*)jid;
636
637 // Jump to window, create one if needed
638 scr_RosterJumpJid(bare_jid);
639
640 // Check if we're sending a message to a conference room
641 // If not, we must make sure rp is NULL, for hk_message_out()
642 if (rp) {
643 if (roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM)) rp++;
644 else rp = NULL;
645 }
646
647 // local part (UI, logging, etc.)
648 hk_message_out(bare_jid, rp, 0, msg);
649
650 // Network part
651 jb_send_msg(jid, msg, ROSTER_TYPE_USER, NULL);
652
653 if (rp) g_free(bare_jid);
654 return 0;
655 }
656
614 static void do_say(char *arg) 657 static void do_say(char *arg)
615 { 658 {
616 gpointer bud; 659 gpointer bud;
617 660
618 scr_set_chatmode(TRUE); 661 scr_set_chatmode(TRUE);
633 send_message(arg); 676 send_message(arg);
634 } 677 }
635 678
636 static void do_msay(char *arg) 679 static void do_msay(char *arg)
637 { 680 {
638 /* Parameters: begin verbatim abort send */ 681 /* Parameters: begin verbatim abort send send_to */
639 gpointer bud; 682 char **paramlst;
640 683 char *subcmd;
641 if (!strcasecmp(arg, "abort")) { 684
642 if (scr_get_multimode()) 685 paramlst = split_arg(arg, 2, 1); // subcmd, arg
643 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode"); 686 subcmd = *paramlst;
644 scr_set_multimode(FALSE); 687 arg = *(paramlst+1);
645 return; 688
646 } else if ((!strcasecmp(arg, "begin")) || (!strcasecmp(arg, "verbatim"))) { 689 if (!subcmd || !*subcmd) {
647 if (!strcasecmp(arg, "verbatim")) 690 scr_LogPrint(LPRINT_NORMAL, "Missing parameter");
648 scr_set_multimode(2);
649 else
650 scr_set_multimode(1);
651
652 scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode.");
653 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" "
654 "when your message is ready.");
655 return;
656 } else if (!*arg) {
657 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using " 691 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using "
658 "the /msay command."); 692 "the /msay command.");
659 scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter " 693 scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter "
660 "multi-line mode...)"); 694 "multi-line mode...)");
661 return; 695 free_arg_lst(paramlst);
662 } else if (strcasecmp(arg, "send")) { 696 return;
697 }
698
699 if (!strcasecmp(subcmd, "abort")) {
700 if (scr_get_multimode())
701 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode");
702 scr_set_multimode(FALSE);
703 return;
704 } else if ((!strcasecmp(subcmd, "begin")) ||
705 (!strcasecmp(subcmd, "verbatim"))) {
706 if (!strcasecmp(subcmd, "verbatim"))
707 scr_set_multimode(2);
708 else
709 scr_set_multimode(1);
710
711 scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode.");
712 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" "
713 "when your message is ready.");
714 return;
715 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) {
663 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); 716 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
664 return; 717 return;
665 } 718 }
666 719
667 // send command 720 /* send/send_to command */
668 721
669 if (!scr_get_multimode()) { 722 if (!scr_get_multimode()) {
670 scr_LogPrint(LPRINT_NORMAL, "No message to send. " 723 scr_LogPrint(LPRINT_NORMAL, "No message to send. "
671 "Use \"/msay begin\" first."); 724 "Use \"/msay begin\" first.");
672 return; 725 return;
673 } 726 }
674 727
675 scr_set_chatmode(TRUE); 728 scr_set_chatmode(TRUE);
676 729
677 if (!current_buddy) { 730 if (!strcasecmp(subcmd, "send_to")) {
678 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); 731 // Let's send to the specified JID. We leave now if there
679 return; 732 // has been an error (so we don't leave multi-line mode).
680 } 733 if (send_message_to(arg, scr_get_multiline()))
681 734 return;
682 bud = BUDDATA(current_buddy); 735 } else { // Send to currently selected buddy
683 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) { 736 gpointer bud;
684 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); 737
685 return; 738 if (!current_buddy) {
686 } 739 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??");
687 740 return;
688 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); 741 }
689 send_message(scr_get_multiline()); 742
743 bud = BUDDATA(current_buddy);
744 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) {
745 scr_LogPrint(LPRINT_NORMAL, "This is not a user");
746 return;
747 }
748
749 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
750 send_message(scr_get_multiline());
751 }
690 scr_set_multimode(FALSE); 752 scr_set_multimode(FALSE);
691 } 753 }
692 754
693 static void do_say_to(char *arg) 755 static void do_say_to(char *arg)
694 { 756 {
695 char **paramlst; 757 char **paramlst;
696 char *jid, *msg; 758 char *jid, *msg;
697 char *bare_jid, *p;
698 759
699 if (!jb_getonline()) { 760 if (!jb_getonline()) {
700 scr_LogPrint(LPRINT_NORMAL, "You are not connected"); 761 scr_LogPrint(LPRINT_NORMAL, "You are not connected");
701 return; 762 return;
702 } 763 }
703 764
704 paramlst = split_arg(arg, 2, 1); // jid, message 765 paramlst = split_arg(arg, 2, 1); // jid, message
705 jid = *paramlst; 766 jid = *paramlst;
706 msg = *(paramlst+1); 767 msg = *(paramlst+1);
707 768
708 if (check_jid_syntax(jid)) { 769 if (!jid) {
709 if (!jid) 770 scr_LogPrint(LPRINT_NORMAL, "Wrong usage");
710 scr_LogPrint(LPRINT_NORMAL, "Wrong usage");
711 else
712 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid);
713 free_arg_lst(paramlst); 771 free_arg_lst(paramlst);
714 return; 772 return;
715 } 773 }
716 774
717 if (!msg || !*msg) { 775 send_message_to(jid, msg);
718 scr_LogPrint(LPRINT_NORMAL, "Missing parameter");
719 free_arg_lst(paramlst);
720 return;
721 }
722
723 // We must use the bare jid in hk_message_out()
724 p = strchr(jid, '/');
725 if (p) bare_jid = g_strndup(jid, p - jid);
726 else bare_jid = jid;
727
728 // Jump to window, create one if needed
729 scr_RosterJumpJid(bare_jid);
730
731 // Check if we're sending a message to a conference room
732 // If not, we must make sure p is NULL, for hk_message_out()
733 if (p) {
734 if (roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM)) p++;
735 else p = NULL;
736 }
737
738 // local part (UI, logging, etc.)
739 hk_message_out(bare_jid, p, 0, msg);
740
741 // Network part
742 jb_send_msg(jid, msg, ROSTER_TYPE_USER, NULL);
743
744 if (p) g_free(bare_jid);
745 free_arg_lst(paramlst); 776 free_arg_lst(paramlst);
746 } 777 }
747 778
748 // buffer_updown(updown, nblines) 779 // buffer_updown(updown, nblines)
749 // updown: -1=up, +1=down 780 // updown: -1=up, +1=down