comparison mcabber/src/commands.c @ 1058:c0d44a9a99bc

Code cleanup Cosmetics. Mostly get rid of "jid" variables, as it is a structure pointer defined in libjabber/jabber.h.
author Mikael Berthe <mikael@lilotux.net>
date Thu, 30 Nov 2006 19:51:09 +0100
parents 6eb1efea75d0
children 875d2c9d399c
comparison
equal deleted inserted replaced
1057:4cdf19d9c74e 1058:c0d44a9a99bc
292 // send_message(msg) 292 // send_message(msg)
293 // Write the message in the buddy's window and send the message on 293 // Write the message in the buddy's window and send the message on
294 // the network. 294 // the network.
295 static void send_message(const char *msg, const char *subj) 295 static void send_message(const char *msg, const char *subj)
296 { 296 {
297 const char *jid; 297 const char *bjid;
298 guint crypted; 298 guint crypted;
299 299
300 if (!jb_getonline()) { 300 if (!jb_getonline()) {
301 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); 301 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
302 return; 302 return;
305 if (!current_buddy) { 305 if (!current_buddy) {
306 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected."); 306 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
307 return; 307 return;
308 } 308 }
309 309
310 jid = CURRENT_JID; 310 bjid = CURRENT_JID;
311 if (!jid) { 311 if (!bjid) {
312 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected."); 312 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
313 return; 313 return;
314 } 314 }
315 315
316 // Network part 316 // Network part
317 jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL, 317 jb_send_msg(bjid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL,
318 &crypted); 318 &crypted);
319 319
320 // Hook 320 // Hook
321 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { 321 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) {
322 // local part (UI, logging, etc.) 322 // local part (UI, logging, etc.)
323 gchar *hmsg; 323 gchar *hmsg;
324 if (subj) 324 if (subj)
325 hmsg = g_strdup_printf("[%s]\n%s", subj, msg); 325 hmsg = g_strdup_printf("[%s]\n%s", subj, msg);
326 else 326 else
327 hmsg = (char*)msg; 327 hmsg = (char*)msg;
328 hk_message_out(jid, NULL, 0, hmsg, crypted); 328 hk_message_out(bjid, NULL, 0, hmsg, crypted);
329 if (hmsg != msg) g_free(hmsg); 329 if (hmsg != msg) g_free(hmsg);
330 } 330 }
331 } 331 }
332 332
333 // process_command(line) 333 // process_command(line)
429 /* It is (probably) a command -- except for verbatim multi-line mode */ 429 /* It is (probably) a command -- except for verbatim multi-line mode */
430 return process_command(line); 430 return process_command(line);
431 } 431 }
432 432
433 // Helper routine for buffer item_{lock,unlock} 433 // Helper routine for buffer item_{lock,unlock}
434 static void roster_buddylock(char *jid, bool lock) 434 static void roster_buddylock(char *bjid, bool lock)
435 { 435 {
436 gpointer bud = NULL; 436 gpointer bud = NULL;
437 bool may_need_refresh = FALSE; 437 bool may_need_refresh = FALSE;
438 438
439 // Allow special jid "" or "." (current buddy) 439 // Allow special jid "" or "." (current buddy)
440 if (jid && (!*jid || !strcmp(jid, "."))) 440 if (bjid && (!*bjid || !strcmp(bjid, ".")))
441 jid = NULL; 441 bjid = NULL;
442 442
443 if (jid) { 443 if (bjid) {
444 // The JID has been specified. Quick check... 444 // The JID has been specified. Quick check...
445 if (check_jid_syntax(jid)) { 445 if (check_jid_syntax(bjid)) {
446 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); 446 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", bjid);
447 } else { 447 } else {
448 // Find the buddy 448 // Find the buddy
449 GSList *roster_elt; 449 GSList *roster_elt;
450 roster_elt = roster_find(jid, jidsearch, 450 roster_elt = roster_find(bjid, jidsearch,
451 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM); 451 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM);
452 if (roster_elt) 452 if (roster_elt)
453 bud = roster_elt->data; 453 bud = roster_elt->data;
454 else 454 else
455 scr_LogPrint(LPRINT_NORMAL, "This jid isn't in the roster."); 455 scr_LogPrint(LPRINT_NORMAL, "This jid isn't in the roster.");
535 g_slist_free(notes); 535 g_slist_free(notes);
536 } 536 }
537 537
538 static void roster_note(char *arg) 538 static void roster_note(char *arg)
539 { 539 {
540 const char *jid; 540 const char *bjid;
541 guint type; 541 guint type;
542 542
543 if (!current_buddy) 543 if (!current_buddy)
544 return; 544 return;
545 545
546 jid = buddy_getjid(BUDDATA(current_buddy)); 546 bjid = buddy_getjid(BUDDATA(current_buddy));
547 type = buddy_gettype(BUDDATA(current_buddy)); 547 type = buddy_gettype(BUDDATA(current_buddy));
548 548
549 if (!jid && type == ROSTER_TYPE_SPECIAL && !arg) { 549 if (!bjid && type == ROSTER_TYPE_SPECIAL && !arg) {
550 // We're in the status window (the only special buffer currently) 550 // We're in the status window (the only special buffer currently)
551 // Let's display all server notes 551 // Let's display all server notes
552 display_all_annotations(); 552 display_all_annotations();
553 return; 553 return;
554 } 554 }
555 555
556 if (!jid || (type != ROSTER_TYPE_USER && 556 if (!bjid || (type != ROSTER_TYPE_USER &&
557 type != ROSTER_TYPE_ROOM && 557 type != ROSTER_TYPE_ROOM &&
558 type != ROSTER_TYPE_AGENT)) { 558 type != ROSTER_TYPE_AGENT)) {
559 scr_LogPrint(LPRINT_NORMAL, "This item can't have a note."); 559 scr_LogPrint(LPRINT_NORMAL, "This item can't have a note.");
560 return; 560 return;
561 } 561 }
565 msg = to_utf8(arg); 565 msg = to_utf8(arg);
566 if (!strcmp(msg, "-")) 566 if (!strcmp(msg, "-"))
567 notetxt = NULL; // delete note 567 notetxt = NULL; // delete note
568 else 568 else
569 notetxt = msg; 569 notetxt = msg;
570 jb_set_storage_rosternotes(jid, notetxt); 570 jb_set_storage_rosternotes(bjid, notetxt);
571 g_free(msg); 571 g_free(msg);
572 } else { // Display a note 572 } else { // Display a note
573 struct annotation *note = jb_get_storage_rosternotes(jid, FALSE); 573 struct annotation *note = jb_get_storage_rosternotes(bjid, FALSE);
574 if (note) { 574 if (note) {
575 display_and_free_note(note, jid); 575 display_and_free_note(note, bjid);
576 } else { 576 } else {
577 scr_WriteIncomingMessage(jid, "This item doesn't have a note.", 0, 577 scr_WriteIncomingMessage(bjid, "This item doesn't have a note.", 0,
578 HBB_PREFIX_INFO); 578 HBB_PREFIX_INFO);
579 } 579 }
580 } 580 }
581 } 581 }
582 582
722 } 722 }
723 723
724 static void do_status_to(char *arg) 724 static void do_status_to(char *arg)
725 { 725 {
726 char **paramlst; 726 char **paramlst;
727 char *jid, *st, *msg; 727 char *fjid, *st, *msg;
728 char *jid_utf8 = NULL; 728 char *jid_utf8 = NULL;
729 729
730 paramlst = split_arg(arg, 3, 1); // jid, status, [message] 730 paramlst = split_arg(arg, 3, 1); // jid, status, [message]
731 jid = *paramlst; 731 fjid = *paramlst;
732 st = *(paramlst+1); 732 st = *(paramlst+1);
733 msg = *(paramlst+2); 733 msg = *(paramlst+2);
734 734
735 if (!jid || !st) { 735 if (!fjid || !st) {
736 scr_LogPrint(LPRINT_NORMAL, 736 scr_LogPrint(LPRINT_NORMAL,
737 "Please specify both a Jabber ID and a status."); 737 "Please specify both a Jabber ID and a status.");
738 free_arg_lst(paramlst); 738 free_arg_lst(paramlst);
739 return; 739 return;
740 } 740 }
741 741
742 // Allow things like /status_to "" away 742 // Allow things like /status_to "" away
743 if (!*jid || !strcmp(jid, ".")) 743 if (!*fjid || !strcmp(fjid, "."))
744 jid = NULL; 744 fjid = NULL;
745 745
746 if (jid) { 746 if (fjid) {
747 // The JID has been specified. Quick check... 747 // The JID has been specified. Quick check...
748 if (check_jid_syntax(jid)) { 748 if (check_jid_syntax(fjid)) {
749 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); 749 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", fjid);
750 jid = NULL; 750 fjid = NULL;
751 } else { 751 } else {
752 // Convert jid to lowercase 752 // Convert jid to lowercase
753 char *p = jid; 753 char *p = fjid;
754 for ( ; *p && *p != JID_RESOURCE_SEPARATOR; p++) 754 for ( ; *p && *p != JID_RESOURCE_SEPARATOR; p++)
755 *p = tolower(*p); 755 *p = tolower(*p);
756 jid = jid_utf8 = to_utf8(jid); 756 fjid = jid_utf8 = to_utf8(fjid);
757 } 757 }
758 } else { 758 } else {
759 // Add the current buddy 759 // Add the current buddy
760 if (current_buddy) 760 if (current_buddy)
761 jid = (char*)buddy_getjid(BUDDATA(current_buddy)); 761 fjid = (char*)buddy_getjid(BUDDATA(current_buddy));
762 if (!jid) 762 if (!fjid)
763 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); 763 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
764 } 764 }
765 765
766 if (jid) { 766 if (fjid) {
767 char *cmd; 767 char *cmdline;
768 if (!msg) 768 if (!msg)
769 msg = ""; 769 msg = "";
770 msg = to_utf8(msg); 770 msg = to_utf8(msg);
771 cmd = g_strdup_printf("%s %s", st, msg); 771 cmdline = g_strdup_printf("%s %s", st, msg);
772 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", jid, cmd); 772 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", fjid, cmdline);
773 setstatus(jid, cmd); 773 setstatus(fjid, cmdline);
774 g_free(msg); 774 g_free(msg);
775 g_free(cmd); 775 g_free(cmdline);
776 g_free(jid_utf8); 776 g_free(jid_utf8);
777 } 777 }
778 free_arg_lst(paramlst); 778 free_arg_lst(paramlst);
779 } 779 }
780 780
832 free_arg_lst(paramlst); 832 free_arg_lst(paramlst);
833 } 833 }
834 834
835 static void do_del(char *arg) 835 static void do_del(char *arg)
836 { 836 {
837 const char *jid; 837 const char *bjid;
838 838
839 if (*arg) { 839 if (*arg) {
840 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter; " 840 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter; "
841 "the currently-selected buddy will be deleted."); 841 "the currently-selected buddy will be deleted.");
842 return; 842 return;
843 } 843 }
844 844
845 if (!current_buddy) return; 845 if (!current_buddy)
846 jid = buddy_getjid(BUDDATA(current_buddy)); 846 return;
847 if (!jid) return; 847 bjid = buddy_getjid(BUDDATA(current_buddy));
848 if (!bjid)
849 return;
848 850
849 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_ROOM) { 851 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_ROOM) {
850 // This is a chatroom 852 // This is a chatroom
851 if (buddy_getinsideroom(BUDDATA(current_buddy))) { 853 if (buddy_getinsideroom(BUDDATA(current_buddy))) {
852 scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!"); 854 scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!");
853 return; 855 return;
854 } 856 }
855 } 857 }
856 858
857 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", jid); 859 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", bjid);
858 jb_delbuddy(jid); 860 jb_delbuddy(bjid);
859 scr_UpdateBuddyWindow(); 861 scr_UpdateBuddyWindow();
860 } 862 }
861 863
862 static void do_group(char *arg) 864 static void do_group(char *arg)
863 { 865 {
867 if (!*arg) { 869 if (!*arg) {
868 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); 870 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
869 return; 871 return;
870 } 872 }
871 873
872 if (!current_buddy) return; 874 if (!current_buddy)
875 return;
873 876
874 group = buddy_getgroup(BUDDATA(current_buddy)); 877 group = buddy_getgroup(BUDDATA(current_buddy));
875 if (!group) return; 878 if (!group)
879 return;
876 880
877 // We'll have to redraw the chat window if we're not currently on the group 881 // We'll have to redraw the chat window if we're not currently on the group
878 // entry itself, because it means we'll have to leave the current buddy 882 // entry itself, because it means we'll have to leave the current buddy
879 // chat window. 883 // chat window.
880 leave_buddywindow = (group != BUDDATA(current_buddy)); 884 leave_buddywindow = (group != BUDDATA(current_buddy));
899 buddylist_build(); 903 buddylist_build();
900 update_roster = TRUE; 904 update_roster = TRUE;
901 if (leave_buddywindow) scr_ShowBuddyWindow(); 905 if (leave_buddywindow) scr_ShowBuddyWindow();
902 } 906 }
903 907
904 static int send_message_to(const char *jid, const char *msg, const char *subj) 908 static int send_message_to(const char *fjid, const char *msg, const char *subj)
905 { 909 {
906 char *bare_jid, *rp; 910 char *bare_jid, *rp;
907 char *hmsg; 911 char *hmsg;
908 guint crypted; 912 guint crypted;
909 913
910 if (!jid || !*jid) { 914 if (!fjid || !*fjid) {
911 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID."); 915 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID.");
912 return 1; 916 return 1;
913 } 917 }
914 if (!msg || !*msg) { 918 if (!msg || !*msg) {
915 scr_LogPrint(LPRINT_NORMAL, "You must specify a message."); 919 scr_LogPrint(LPRINT_NORMAL, "You must specify a message.");
916 return 1; 920 return 1;
917 } 921 }
918 if (check_jid_syntax((char*)jid)) { 922 if (check_jid_syntax((char*)fjid)) {
919 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); 923 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", fjid);
920 return 1; 924 return 1;
921 } 925 }
922 926
923 // We must use the bare jid in hk_message_out() 927 // We must use the bare jid in hk_message_out()
924 rp = strchr(jid, JID_RESOURCE_SEPARATOR); 928 rp = strchr(fjid, JID_RESOURCE_SEPARATOR);
925 if (rp) bare_jid = g_strndup(jid, rp - jid); 929 if (rp) bare_jid = g_strndup(fjid, rp - fjid);
926 else bare_jid = (char*)jid; 930 else bare_jid = (char*)fjid;
927 931
928 // Jump to window, create one if needed 932 // Jump to window, create one if needed
929 scr_RosterJumpJid(bare_jid); 933 scr_RosterJumpJid(bare_jid);
930 934
931 // Check if we're sending a message to a conference room 935 // Check if we're sending a message to a conference room
940 hmsg = g_strdup_printf("[%s]\n%s", subj, msg); 944 hmsg = g_strdup_printf("[%s]\n%s", subj, msg);
941 else 945 else
942 hmsg = (char*)msg; 946 hmsg = (char*)msg;
943 947
944 // Network part 948 // Network part
945 jb_send_msg(jid, msg, ROSTER_TYPE_USER, subj, NULL, &crypted); 949 jb_send_msg(fjid, msg, ROSTER_TYPE_USER, subj, NULL, &crypted);
946 950
947 // Hook 951 // Hook
948 hk_message_out(bare_jid, rp, 0, hmsg, crypted); 952 hk_message_out(bare_jid, rp, 0, hmsg, crypted);
949 if (hmsg != msg) g_free(hmsg); 953 if (hmsg != msg) g_free(hmsg);
950 954
1091 } 1095 }
1092 1096
1093 static void do_say_to(char *arg) 1097 static void do_say_to(char *arg)
1094 { 1098 {
1095 char **paramlst; 1099 char **paramlst;
1096 char *jid, *msg; 1100 char *fjid, *msg;
1097 1101
1098 if (!jb_getonline()) { 1102 if (!jb_getonline()) {
1099 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); 1103 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
1100 return; 1104 return;
1101 } 1105 }
1102 1106
1103 paramlst = split_arg(arg, 2, 1); // jid, message 1107 paramlst = split_arg(arg, 2, 1); // jid, message
1104 jid = *paramlst; 1108 fjid = *paramlst;
1105 msg = *(paramlst+1); 1109 msg = *(paramlst+1);
1106 1110
1107 if (!jid || !strcmp(jid, ".")) { 1111 if (!fjid || !strcmp(fjid, ".")) {
1108 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); 1112 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
1109 free_arg_lst(paramlst); 1113 free_arg_lst(paramlst);
1110 return; 1114 return;
1111 } 1115 }
1112 1116
1113 jid = to_utf8(jid); 1117 fjid = to_utf8(fjid);
1114 msg = to_utf8(msg); 1118 msg = to_utf8(msg);
1115 1119
1116 send_message_to(jid, msg, NULL); 1120 send_message_to(fjid, msg, NULL);
1117 1121
1118 g_free(jid); 1122 g_free(fjid);
1119 g_free(msg); 1123 g_free(msg);
1120 free_arg_lst(paramlst); 1124 free_arg_lst(paramlst);
1121 } 1125 }
1122 1126
1123 // buffer_updown(updown, nblines) 1127 // buffer_updown(updown, nblines)
1186 static void do_buffer(char *arg) 1190 static void do_buffer(char *arg)
1187 { 1191 {
1188 char **paramlst; 1192 char **paramlst;
1189 char *subcmd; 1193 char *subcmd;
1190 1194
1191 if (!current_buddy) return; 1195 if (!current_buddy)
1196 return;
1192 1197
1193 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_GROUP) { 1198 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_GROUP) {
1194 scr_LogPrint(LPRINT_NORMAL, "Groups have no buffer."); 1199 scr_LogPrint(LPRINT_NORMAL, "Groups have no buffer.");
1195 return; 1200 return;
1196 } 1201 }
1246 } 1251 }
1247 1252
1248 static void do_info(char *arg) 1253 static void do_info(char *arg)
1249 { 1254 {
1250 gpointer bud; 1255 gpointer bud;
1251 const char *jid, *name; 1256 const char *bjid, *name;
1252 guint type; 1257 guint type;
1253 char *buffer; 1258 char *buffer;
1254 enum subscr esub; 1259 enum subscr esub;
1255 1260
1256 if (!current_buddy) return; 1261 if (!current_buddy)
1262 return;
1257 bud = BUDDATA(current_buddy); 1263 bud = BUDDATA(current_buddy);
1258 1264
1259 jid = buddy_getjid(bud); 1265 bjid = buddy_getjid(bud);
1260 name = buddy_getname(bud); 1266 name = buddy_getname(bud);
1261 type = buddy_gettype(bud); 1267 type = buddy_gettype(bud);
1262 esub = buddy_getsubscription(bud); 1268 esub = buddy_getsubscription(bud);
1263 1269
1264 buffer = g_new(char, 4096); 1270 buffer = g_new(char, 4096);
1265 1271
1266 if (jid) { 1272 if (bjid) {
1267 GSList *resources; 1273 GSList *resources;
1268 char *bstr = "unknown"; 1274 char *bstr = "unknown";
1269 1275
1270 // Enter chat mode 1276 // Enter chat mode
1271 scr_set_chatmode(TRUE); 1277 scr_set_chatmode(TRUE);
1272 scr_ShowBuddyWindow(); 1278 scr_ShowBuddyWindow();
1273 1279
1274 snprintf(buffer, 4095, "jid: <%s>", jid); 1280 snprintf(buffer, 4095, "jid: <%s>", bjid);
1275 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 1281 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
1276 if (name) { 1282 if (name) {
1277 snprintf(buffer, 4095, "Name: %s", name); 1283 snprintf(buffer, 4095, "Name: %s", name);
1278 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 1284 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
1279 } 1285 }
1280 1286
1281 if (type == ROSTER_TYPE_USER) bstr = "user"; 1287 if (type == ROSTER_TYPE_USER) bstr = "user";
1282 else if (type == ROSTER_TYPE_ROOM) bstr = "chatroom"; 1288 else if (type == ROSTER_TYPE_ROOM) bstr = "chatroom";
1283 else if (type == ROSTER_TYPE_AGENT) bstr = "agent"; 1289 else if (type == ROSTER_TYPE_AGENT) bstr = "agent";
1284 snprintf(buffer, 127, "Type: %s", bstr); 1290 snprintf(buffer, 127, "Type: %s", bstr);
1285 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 1291 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
1286 1292
1287 if (esub == sub_both) bstr = "both"; 1293 if (esub == sub_both) bstr = "both";
1288 else if (esub & sub_from) bstr = "from"; 1294 else if (esub & sub_from) bstr = "from";
1289 else if (esub & sub_to) bstr = "to"; 1295 else if (esub & sub_to) bstr = "to";
1290 else bstr = "none"; 1296 else bstr = "none";
1291 snprintf(buffer, 64, "Subscription: %s", bstr); 1297 snprintf(buffer, 64, "Subscription: %s", bstr);
1292 if (esub & sub_pending) 1298 if (esub & sub_pending)
1293 strcat(buffer, " (pending)"); 1299 strcat(buffer, " (pending)");
1294 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 1300 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
1295 1301
1296 resources = buddy_getresources(bud); 1302 resources = buddy_getresources(bud);
1297 if (!resources && type == ROSTER_TYPE_USER) { 1303 if (!resources && type == ROSTER_TYPE_USER) {
1298 // No resource; display last status message, if any. 1304 // No resource; display last status message, if any.
1299 const char *rst_msg = buddy_getstatusmsg(bud, ""); 1305 const char *rst_msg = buddy_getstatusmsg(bud, "");
1300 if (rst_msg) { 1306 if (rst_msg) {
1301 snprintf(buffer, 4095, "Last status message: %s", rst_msg); 1307 snprintf(buffer, 4095, "Last status message: %s", rst_msg);
1302 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 1308 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
1303 } 1309 }
1304 } 1310 }
1305 for ( ; resources ; resources = g_slist_next(resources) ) { 1311 for ( ; resources ; resources = g_slist_next(resources) ) {
1306 gchar rprio; 1312 gchar rprio;
1307 enum imstatus rstatus; 1313 enum imstatus rstatus;
1315 rst_time = buddy_getstatustime(bud, resources->data); 1321 rst_time = buddy_getstatustime(bud, resources->data);
1316 rpgp = buddy_resource_pgp(bud, resources->data); 1322 rpgp = buddy_resource_pgp(bud, resources->data);
1317 1323
1318 snprintf(buffer, 4095, "Resource: [%c] (%d) %s", imstatus2char[rstatus], 1324 snprintf(buffer, 4095, "Resource: [%c] (%d) %s", imstatus2char[rstatus],
1319 rprio, (char*)resources->data); 1325 rprio, (char*)resources->data);
1320 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 1326 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
1321 if (rst_msg) { 1327 if (rst_msg) {
1322 snprintf(buffer, 4095, "Status message: %s", rst_msg); 1328 snprintf(buffer, 4095, "Status message: %s", rst_msg);
1323 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 1329 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
1324 } 1330 }
1325 if (rst_time) { 1331 if (rst_time) {
1326 char tbuf[128]; 1332 char tbuf[128];
1327 1333
1328 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", localtime(&rst_time)); 1334 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", localtime(&rst_time));
1329 snprintf(buffer, 127, "Status timestamp: %s", tbuf); 1335 snprintf(buffer, 127, "Status timestamp: %s", tbuf);
1330 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 1336 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
1331 } 1337 }
1332 #ifdef HAVE_GPGME 1338 #ifdef HAVE_GPGME
1333 if (rpgp && rpgp->sign_keyid) { 1339 if (rpgp && rpgp->sign_keyid) {
1334 snprintf(buffer, 4095, "PGP key id: %s", rpgp->sign_keyid); 1340 snprintf(buffer, 4095, "PGP key id: %s", rpgp->sign_keyid);
1335 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 1341 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
1336 if (rpgp->last_sigsum) { 1342 if (rpgp->last_sigsum) {
1337 gpgme_sigsum_t ss = rpgp->last_sigsum; 1343 gpgme_sigsum_t ss = rpgp->last_sigsum;
1338 snprintf(buffer, 4095, "Last PGP signature: %s", 1344 snprintf(buffer, 4095, "Last PGP signature: %s",
1339 (ss & GPGME_SIGSUM_GREEN ? "good": 1345 (ss & GPGME_SIGSUM_GREEN ? "good":
1340 (ss & GPGME_SIGSUM_RED ? "bad" : "unknown"))); 1346 (ss & GPGME_SIGSUM_RED ? "bad" : "unknown")));
1341 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 1347 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
1342 } 1348 }
1343 } 1349 }
1344 #endif 1350 #endif
1345 } 1351 }
1346 } else { 1352 } else {
1353 1359
1354 // Tell the user if this item has an annotation. 1360 // Tell the user if this item has an annotation.
1355 if (type == ROSTER_TYPE_USER || 1361 if (type == ROSTER_TYPE_USER ||
1356 type == ROSTER_TYPE_ROOM || 1362 type == ROSTER_TYPE_ROOM ||
1357 type == ROSTER_TYPE_AGENT) { 1363 type == ROSTER_TYPE_AGENT) {
1358 struct annotation *note = jb_get_storage_rosternotes(jid, TRUE); 1364 struct annotation *note = jb_get_storage_rosternotes(bjid, TRUE);
1359 if (note) { 1365 if (note) {
1360 // We do not display the note, we just tell the user. 1366 // We do not display the note, we just tell the user.
1361 g_free(note->text); 1367 g_free(note->text);
1362 g_free(note->jid); 1368 g_free(note->jid);
1363 g_free(note); 1369 g_free(note);
1364 scr_WriteIncomingMessage(jid, "(This item has an annotation)", 0, 1370 scr_WriteIncomingMessage(bjid, "(This item has an annotation)", 0,
1365 HBB_PREFIX_INFO); 1371 HBB_PREFIX_INFO);
1366 } 1372 }
1367 } 1373 }
1368 } 1374 }
1369 1375
1370 // room_names() is a variation of do_info(), for chatrooms only 1376 // room_names() is a variation of do_info(), for chatrooms only
1371 static void room_names(gpointer bud, char *arg) 1377 static void room_names(gpointer bud, char *arg)
1372 { 1378 {
1373 const char *jid; 1379 const char *bjid;
1374 char *buffer; 1380 char *buffer;
1375 GSList *resources; 1381 GSList *resources;
1376 1382
1377 if (*arg) { 1383 if (*arg) {
1378 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter."); 1384 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter.");
1381 1387
1382 // Enter chat mode 1388 // Enter chat mode
1383 scr_set_chatmode(TRUE); 1389 scr_set_chatmode(TRUE);
1384 scr_ShowBuddyWindow(); 1390 scr_ShowBuddyWindow();
1385 1391
1386 jid = buddy_getjid(bud); 1392 bjid = buddy_getjid(bud);
1387 1393
1388 buffer = g_new(char, 4096); 1394 buffer = g_new(char, 4096);
1389 strncpy(buffer, "Room members:", 127); 1395 strncpy(buffer, "Room members:", 127);
1390 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 1396 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
1391 1397
1392 resources = buddy_getresources(bud); 1398 resources = buddy_getresources(bud);
1393 for ( ; resources ; resources = g_slist_next(resources) ) { 1399 for ( ; resources ; resources = g_slist_next(resources) ) {
1394 enum imstatus rstatus; 1400 enum imstatus rstatus;
1395 const char *rst_msg; 1401 const char *rst_msg;
1397 rstatus = buddy_getstatus(bud, resources->data); 1403 rstatus = buddy_getstatus(bud, resources->data);
1398 rst_msg = buddy_getstatusmsg(bud, resources->data); 1404 rst_msg = buddy_getstatusmsg(bud, resources->data);
1399 1405
1400 snprintf(buffer, 4095, "[%c] %s", imstatus2char[rstatus], 1406 snprintf(buffer, 4095, "[%c] %s", imstatus2char[rstatus],
1401 (char*)resources->data); 1407 (char*)resources->data);
1402 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 1408 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
1403 if (rst_msg) { 1409 if (rst_msg) {
1404 snprintf(buffer, 4095, "Status message: %s", rst_msg); 1410 snprintf(buffer, 4095, "Status message: %s", rst_msg);
1405 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 1411 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
1406 } 1412 }
1407 } 1413 }
1408 1414
1409 g_free(buffer); 1415 g_free(buffer);
1410 } 1416 }
1411 1417
1412 static void move_group_member(gpointer bud, void *groupnamedata) 1418 static void move_group_member(gpointer bud, void *groupnamedata)
1413 { 1419 {
1414 const char *jid, *name, *groupname; 1420 const char *bjid, *name, *groupname;
1415 1421
1416 groupname = (char *)groupnamedata; 1422 groupname = (char *)groupnamedata;
1417 1423
1418 jid = buddy_getjid(bud); 1424 bjid = buddy_getjid(bud);
1419 name = buddy_getname(bud); 1425 name = buddy_getname(bud);
1420 1426
1421 jb_updatebuddy(jid, name, *groupname ? groupname : NULL); 1427 jb_updatebuddy(bjid, name, *groupname ? groupname : NULL);
1422 } 1428 }
1423 1429
1424 static void do_rename(char *arg) 1430 static void do_rename(char *arg)
1425 { 1431 {
1426 gpointer bud; 1432 gpointer bud;
1427 const char *jid, *group; 1433 const char *bjid, *group;
1428 guint type; 1434 guint type;
1429 char *newname, *p; 1435 char *newname, *p;
1430 char *name_utf8; 1436 char *name_utf8;
1431 1437
1432 if (!current_buddy) return; 1438 if (!current_buddy)
1439 return;
1433 bud = BUDDATA(current_buddy); 1440 bud = BUDDATA(current_buddy);
1434 1441
1435 jid = buddy_getjid(bud); 1442 bjid = buddy_getjid(bud);
1436 group = buddy_getgroupname(bud); 1443 group = buddy_getgroupname(bud);
1437 type = buddy_gettype(bud); 1444 type = buddy_gettype(bud);
1438 1445
1439 if (type & ROSTER_TYPE_SPECIAL) { 1446 if (type & ROSTER_TYPE_SPECIAL) {
1440 scr_LogPrint(LPRINT_NORMAL, "You can't rename this item."); 1447 scr_LogPrint(LPRINT_NORMAL, "You can't rename this item.");
1462 // disappear when we receive the server answer. 1469 // disappear when we receive the server answer.
1463 scr_RosterUp(); 1470 scr_RosterUp();
1464 } else { 1471 } else {
1465 // Rename a single buddy 1472 // Rename a single buddy
1466 buddy_setname(bud, name_utf8); 1473 buddy_setname(bud, name_utf8);
1467 jb_updatebuddy(jid, name_utf8, group); 1474 jb_updatebuddy(bjid, name_utf8, group);
1468 } 1475 }
1469 1476
1470 g_free(name_utf8); 1477 g_free(name_utf8);
1471 g_free(newname); 1478 g_free(newname);
1472 update_roster = TRUE; 1479 update_roster = TRUE;
1473 } 1480 }
1474 1481
1475 static void do_move(char *arg) 1482 static void do_move(char *arg)
1476 { 1483 {
1477 gpointer bud; 1484 gpointer bud;
1478 const char *jid, *name, *oldgroupname; 1485 const char *bjid, *name, *oldgroupname;
1479 guint type; 1486 guint type;
1480 char *newgroupname, *p; 1487 char *newgroupname, *p;
1481 char *group_utf8; 1488 char *group_utf8;
1482 1489
1483 if (!current_buddy) return; 1490 if (!current_buddy)
1491 return;
1484 bud = BUDDATA(current_buddy); 1492 bud = BUDDATA(current_buddy);
1485 1493
1486 jid = buddy_getjid(bud); 1494 bjid = buddy_getjid(bud);
1487 name = buddy_getname(bud); 1495 name = buddy_getname(bud);
1488 type = buddy_gettype(bud); 1496 type = buddy_gettype(bud);
1489 1497
1490 oldgroupname = buddy_getgroupname(bud); 1498 oldgroupname = buddy_getgroupname(bud);
1491 1499
1505 1513
1506 strip_arg_special_chars(newgroupname); 1514 strip_arg_special_chars(newgroupname);
1507 1515
1508 group_utf8 = to_utf8(newgroupname); 1516 group_utf8 = to_utf8(newgroupname);
1509 if (strcmp(oldgroupname, group_utf8)) { 1517 if (strcmp(oldgroupname, group_utf8)) {
1510 jb_updatebuddy(jid, name, *group_utf8 ? group_utf8 : NULL); 1518 jb_updatebuddy(bjid, name, *group_utf8 ? group_utf8 : NULL);
1511 scr_RosterUp(); 1519 scr_RosterUp();
1512 buddy_setgroup(bud, group_utf8); 1520 buddy_setgroup(bud, group_utf8);
1513 } 1521 }
1514 1522
1515 g_free(group_utf8); 1523 g_free(group_utf8);
1610 } 1618 }
1611 1619
1612 static void do_bind(char *arg) 1620 static void do_bind(char *arg)
1613 { 1621 {
1614 guint assign; 1622 guint assign;
1615 const gchar *keycode, *value; 1623 const gchar *k_code, *value;
1616 1624
1617 assign = parse_assigment(arg, &keycode, &value); 1625 assign = parse_assigment(arg, &k_code, &value);
1618 if (!keycode) { 1626 if (!k_code) {
1619 settings_foreach(SETTINGS_TYPE_BINDING, &dump_bind, NULL); 1627 settings_foreach(SETTINGS_TYPE_BINDING, &dump_bind, NULL);
1620 return; 1628 return;
1621 } 1629 }
1622 if (!assign) { 1630 if (!assign) {
1623 // This is a query 1631 // This is a query
1624 value = settings_get(SETTINGS_TYPE_BINDING, keycode); 1632 value = settings_get(SETTINGS_TYPE_BINDING, k_code);
1625 if (value) { 1633 if (value) {
1626 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", keycode, value); 1634 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", k_code, value);
1627 } else 1635 } else
1628 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound.", keycode); 1636 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound.", k_code);
1629 return; 1637 return;
1630 } 1638 }
1631 // Update the key binding 1639 // Update the key binding
1632 if (!value) { 1640 if (!value) {
1633 settings_del(SETTINGS_TYPE_BINDING, keycode); 1641 settings_del(SETTINGS_TYPE_BINDING, k_code);
1634 } else { 1642 } else {
1635 gchar *value_utf8 = to_utf8(value); 1643 gchar *value_utf8 = to_utf8(value);
1636 settings_set(SETTINGS_TYPE_BINDING, keycode, value_utf8); 1644 settings_set(SETTINGS_TYPE_BINDING, k_code, value_utf8);
1637 g_free(value_utf8); 1645 g_free(value_utf8);
1638 } 1646 }
1639 } 1647 }
1640 1648
1641 static void do_rawxml(char *arg) 1649 static void do_rawxml(char *arg)
1780 1788
1781 static void room_invite(gpointer bud, char *arg) 1789 static void room_invite(gpointer bud, char *arg)
1782 { 1790 {
1783 char **paramlst; 1791 char **paramlst;
1784 const gchar *roomname; 1792 const gchar *roomname;
1785 char* jid; 1793 char* fjid;
1786 gchar *reason_utf8; 1794 gchar *reason_utf8;
1787 1795
1788 paramlst = split_arg(arg, 2, 1); // jid, [reason] 1796 paramlst = split_arg(arg, 2, 1); // jid, [reason]
1789 jid = *paramlst; 1797 fjid = *paramlst;
1790 arg = *(paramlst+1); 1798 arg = *(paramlst+1);
1791 // An empty reason is no reason... 1799 // An empty reason is no reason...
1792 if (arg && !*arg) 1800 if (arg && !*arg)
1793 arg = NULL; 1801 arg = NULL;
1794 1802
1795 if (!jid || !*jid) { 1803 if (!fjid || !*fjid) {
1796 scr_LogPrint(LPRINT_NORMAL, "Missing or incorrect Jabber ID."); 1804 scr_LogPrint(LPRINT_NORMAL, "Missing or incorrect Jabber ID.");
1797 free_arg_lst(paramlst); 1805 free_arg_lst(paramlst);
1798 return; 1806 return;
1799 } 1807 }
1800 1808
1801 roomname = buddy_getjid(bud); 1809 roomname = buddy_getjid(bud);
1802 reason_utf8 = to_utf8(arg); 1810 reason_utf8 = to_utf8(arg);
1803 jb_room_invite(roomname, jid, reason_utf8); 1811 jb_room_invite(roomname, fjid, reason_utf8);
1804 scr_LogPrint(LPRINT_LOGNORM, "Invitation sent to <%s>.", jid); 1812 scr_LogPrint(LPRINT_LOGNORM, "Invitation sent to <%s>.", fjid);
1805 g_free(reason_utf8); 1813 g_free(reason_utf8);
1806 free_arg_lst(paramlst); 1814 free_arg_lst(paramlst);
1807 } 1815 }
1808 1816
1809 static void room_affil(gpointer bud, char *arg) 1817 static void room_affil(gpointer bud, char *arg)
1810 { 1818 {
1811 char **paramlst; 1819 char **paramlst;
1812 gchar *jid, *rolename; 1820 gchar *fjid, *rolename;
1813 struct role_affil ra; 1821 struct role_affil ra;
1814 const char *roomid = buddy_getjid(bud); 1822 const char *roomid = buddy_getjid(bud);
1815 1823
1816 paramlst = split_arg(arg, 3, 1); // jid, new_affil, [reason] 1824 paramlst = split_arg(arg, 3, 1); // jid, new_affil, [reason]
1817 jid = *paramlst; 1825 fjid = *paramlst;
1818 rolename = *(paramlst+1); 1826 rolename = *(paramlst+1);
1819 arg = *(paramlst+2); 1827 arg = *(paramlst+2);
1820 1828
1821 if (!jid || !*jid || !rolename || !*rolename) { 1829 if (!fjid || !*fjid || !rolename || !*rolename) {
1822 scr_LogPrint(LPRINT_NORMAL, "Please specify both a Jabber ID and a role."); 1830 scr_LogPrint(LPRINT_NORMAL, "Please specify both a Jabber ID and a role.");
1823 free_arg_lst(paramlst); 1831 free_arg_lst(paramlst);
1824 return; 1832 return;
1825 } 1833 }
1826 1834
1830 if (!strcasecmp(rolename, straffil[ra.val.affil])) 1838 if (!strcasecmp(rolename, straffil[ra.val.affil]))
1831 break; 1839 break;
1832 1840
1833 if (ra.val.affil < imaffiliation_size) { 1841 if (ra.val.affil < imaffiliation_size) {
1834 gchar *jid_utf8, *reason_utf8; 1842 gchar *jid_utf8, *reason_utf8;
1835 jid_utf8 = to_utf8(jid); 1843 jid_utf8 = to_utf8(fjid);
1836 reason_utf8 = to_utf8(arg); 1844 reason_utf8 = to_utf8(arg);
1837 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8); 1845 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
1838 g_free(jid_utf8); 1846 g_free(jid_utf8);
1839 g_free(reason_utf8); 1847 g_free(reason_utf8);
1840 } else 1848 } else
1844 } 1852 }
1845 1853
1846 static void room_role(gpointer bud, char *arg) 1854 static void room_role(gpointer bud, char *arg)
1847 { 1855 {
1848 char **paramlst; 1856 char **paramlst;
1849 gchar *jid, *rolename; 1857 gchar *fjid, *rolename;
1850 struct role_affil ra; 1858 struct role_affil ra;
1851 const char *roomid = buddy_getjid(bud); 1859 const char *roomid = buddy_getjid(bud);
1852 1860
1853 paramlst = split_arg(arg, 3, 1); // jid, new_role, [reason] 1861 paramlst = split_arg(arg, 3, 1); // jid, new_role, [reason]
1854 jid = *paramlst; 1862 fjid = *paramlst;
1855 rolename = *(paramlst+1); 1863 rolename = *(paramlst+1);
1856 arg = *(paramlst+2); 1864 arg = *(paramlst+2);
1857 1865
1858 if (!jid || !*jid || !rolename || !*rolename) { 1866 if (!fjid || !*fjid || !rolename || !*rolename) {
1859 scr_LogPrint(LPRINT_NORMAL, "Please specify both a Jabber ID and a role."); 1867 scr_LogPrint(LPRINT_NORMAL, "Please specify both a Jabber ID and a role.");
1860 free_arg_lst(paramlst); 1868 free_arg_lst(paramlst);
1861 return; 1869 return;
1862 } 1870 }
1863 1871
1867 if (!strcasecmp(rolename, strrole[ra.val.role])) 1875 if (!strcasecmp(rolename, strrole[ra.val.role]))
1868 break; 1876 break;
1869 1877
1870 if (ra.val.role < imrole_size) { 1878 if (ra.val.role < imrole_size) {
1871 gchar *jid_utf8, *reason_utf8; 1879 gchar *jid_utf8, *reason_utf8;
1872 jid_utf8 = to_utf8(jid); 1880 jid_utf8 = to_utf8(fjid);
1873 reason_utf8 = to_utf8(arg); 1881 reason_utf8 = to_utf8(arg);
1874 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8); 1882 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
1875 g_free(jid_utf8); 1883 g_free(jid_utf8);
1876 g_free(reason_utf8); 1884 g_free(reason_utf8);
1877 } else 1885 } else
1883 1891
1884 // The expected argument is a Jabber id 1892 // The expected argument is a Jabber id
1885 static void room_ban(gpointer bud, char *arg) 1893 static void room_ban(gpointer bud, char *arg)
1886 { 1894 {
1887 char **paramlst; 1895 char **paramlst;
1888 gchar *jid; 1896 gchar *fjid;
1889 gchar *jid_utf8, *reason_utf8; 1897 gchar *jid_utf8, *reason_utf8;
1890 struct role_affil ra; 1898 struct role_affil ra;
1891 const char *roomid = buddy_getjid(bud); 1899 const char *roomid = buddy_getjid(bud);
1892 1900
1893 paramlst = split_arg(arg, 2, 1); // jid, [reason] 1901 paramlst = split_arg(arg, 2, 1); // jid, [reason]
1894 jid = *paramlst; 1902 fjid = *paramlst;
1895 arg = *(paramlst+1); 1903 arg = *(paramlst+1);
1896 1904
1897 if (!jid || !*jid) { 1905 if (!fjid || !*fjid) {
1898 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); 1906 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
1899 free_arg_lst(paramlst); 1907 free_arg_lst(paramlst);
1900 return; 1908 return;
1901 } 1909 }
1902 1910
1903 ra.type = type_affil; 1911 ra.type = type_affil;
1904 ra.val.affil = affil_outcast; 1912 ra.val.affil = affil_outcast;
1905 1913
1906 jid_utf8 = to_utf8(jid); 1914 jid_utf8 = to_utf8(fjid);
1907 reason_utf8 = to_utf8(arg); 1915 reason_utf8 = to_utf8(arg);
1908 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8); 1916 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
1909 g_free(jid_utf8); 1917 g_free(jid_utf8);
1910 g_free(reason_utf8); 1918 g_free(reason_utf8);
1911 1919
1989 } 1997 }
1990 1998
1991 static void room_privmsg(gpointer bud, char *arg) 1999 static void room_privmsg(gpointer bud, char *arg)
1992 { 2000 {
1993 char **paramlst; 2001 char **paramlst;
1994 gchar *nick, *cmd; 2002 gchar *nick, *cmdline;
1995 2003
1996 paramlst = split_arg(arg, 2, 0); // nickname, message 2004 paramlst = split_arg(arg, 2, 0); // nickname, message
1997 nick = *paramlst; 2005 nick = *paramlst;
1998 arg = *(paramlst+1); 2006 arg = *(paramlst+1);
1999 2007
2002 "Please specify both a Jabber ID and a message."); 2010 "Please specify both a Jabber ID and a message.");
2003 free_arg_lst(paramlst); 2011 free_arg_lst(paramlst);
2004 return; 2012 return;
2005 } 2013 }
2006 2014
2007 cmd = g_strdup_printf("%s/%s %s", buddy_getjid(bud), nick, arg); 2015 cmdline = g_strdup_printf("%s/%s %s", buddy_getjid(bud), nick, arg);
2008 do_say_to(cmd); 2016 do_say_to(cmdline);
2009 g_free(cmd); 2017 g_free(cmdline);
2010 free_arg_lst(paramlst); 2018 free_arg_lst(paramlst);
2011 } 2019 }
2012 2020
2013 static void room_remove(gpointer bud, char *arg) 2021 static void room_remove(gpointer bud, char *arg)
2014 { 2022 {
2084 // If interactive is TRUE, chatmode can be enabled. 2092 // If interactive is TRUE, chatmode can be enabled.
2085 void room_whois(gpointer bud, char *arg, guint interactive) 2093 void room_whois(gpointer bud, char *arg, guint interactive)
2086 { 2094 {
2087 char **paramlst; 2095 char **paramlst;
2088 gchar *nick, *buffer; 2096 gchar *nick, *buffer;
2089 const char *jid, *realjid; 2097 const char *bjid, *realjid;
2090 const char *rst_msg; 2098 const char *rst_msg;
2091 gchar rprio; 2099 gchar rprio;
2092 enum imstatus rstatus; 2100 enum imstatus rstatus;
2093 enum imrole role; 2101 enum imrole role;
2094 enum imaffiliation affil; 2102 enum imaffiliation affil;
2095 time_t rst_time; 2103 time_t rst_time;
2096 2104
2097 char *strroles[] = { "none", "moderator", "participant", "visitor" };
2098 char *straffil[] = { "none", "owner", "admin", "member", "outcast" };
2099
2100 paramlst = split_arg(arg, 1, 0); // nickname 2105 paramlst = split_arg(arg, 1, 0); // nickname
2101 nick = *paramlst; 2106 nick = *paramlst;
2102 2107
2103 if (!nick || !*nick) { 2108 if (!nick || !*nick) {
2104 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname."); 2109 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname.");
2112 // Enter chat mode 2117 // Enter chat mode
2113 scr_set_chatmode(TRUE); 2118 scr_set_chatmode(TRUE);
2114 scr_ShowBuddyWindow(); 2119 scr_ShowBuddyWindow();
2115 } 2120 }
2116 2121
2117 jid = buddy_getjid(bud); 2122 bjid = buddy_getjid(bud);
2118 rstatus = buddy_getstatus(bud, nick); 2123 rstatus = buddy_getstatus(bud, nick);
2119 2124
2120 if (rstatus == offline) { 2125 if (rstatus == offline) {
2121 scr_LogPrint(LPRINT_NORMAL, "No such member: %s", nick); 2126 scr_LogPrint(LPRINT_NORMAL, "No such member: %s", nick);
2122 free_arg_lst(paramlst); 2127 free_arg_lst(paramlst);
2134 realjid = buddy_getrjid(bud, nick); 2139 realjid = buddy_getrjid(bud, nick);
2135 2140
2136 buffer = g_new(char, 4096); 2141 buffer = g_new(char, 4096);
2137 2142
2138 snprintf(buffer, 4095, "Whois [%s]", nick); 2143 snprintf(buffer, 4095, "Whois [%s]", nick);
2139 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 2144 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
2140 snprintf(buffer, 4095, "Status : [%c] %s", imstatus2char[rstatus], 2145 snprintf(buffer, 4095, "Status : [%c] %s", imstatus2char[rstatus],
2141 rst_msg); 2146 rst_msg);
2142 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 2147 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
2143 2148
2144 if (rst_time) { 2149 if (rst_time) {
2145 char tbuf[128]; 2150 char tbuf[128];
2146 2151
2147 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", localtime(&rst_time)); 2152 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", localtime(&rst_time));
2148 snprintf(buffer, 127, "Timestamp: %s", tbuf); 2153 snprintf(buffer, 127, "Timestamp: %s", tbuf);
2149 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 2154 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
2150 } 2155 }
2151 2156
2152 if (realjid) { 2157 if (realjid) {
2153 snprintf(buffer, 4095, "JID : <%s>", realjid); 2158 snprintf(buffer, 4095, "JID : <%s>", realjid);
2154 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 2159 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
2155 } 2160 }
2156 2161
2157 snprintf(buffer, 4095, "Role : %s", strroles[role]); 2162 snprintf(buffer, 4095, "Role : %s", strrole[role]);
2158 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 2163 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
2159 snprintf(buffer, 4095, "Affiliat.: %s", straffil[affil]); 2164 snprintf(buffer, 4095, "Affiliat.: %s", straffil[affil]);
2160 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 2165 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
2161 snprintf(buffer, 4095, "Priority : %d", rprio); 2166 snprintf(buffer, 4095, "Priority : %d", rprio);
2162 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE); 2167 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
2163 2168
2164 scr_WriteIncomingMessage(jid, "End of WHOIS", 0, HBB_PREFIX_INFO); 2169 scr_WriteIncomingMessage(bjid, "End of WHOIS", 0, HBB_PREFIX_INFO);
2165 2170
2166 g_free(buffer); 2171 g_free(buffer);
2167 g_free(nick); 2172 g_free(nick);
2168 free_arg_lst(paramlst); 2173 free_arg_lst(paramlst);
2169 } 2174 }
2327 2332
2328 if (!arg) { // Use the current selected buddy's jid 2333 if (!arg) { // Use the current selected buddy's jid
2329 gpointer bud; 2334 gpointer bud;
2330 guint type; 2335 guint type;
2331 2336
2332 if (!current_buddy) return; 2337 if (!current_buddy)
2338 return;
2333 bud = BUDDATA(current_buddy); 2339 bud = BUDDATA(current_buddy);
2334 2340
2335 jid_utf8 = arg = (char*)buddy_getjid(bud); 2341 jid_utf8 = arg = (char*)buddy_getjid(bud);
2336 type = buddy_gettype(bud); 2342 type = buddy_gettype(bud);
2337 2343
2380 } 2386 }
2381 2387
2382 static void do_request(char *arg) 2388 static void do_request(char *arg)
2383 { 2389 {
2384 char **paramlst; 2390 char **paramlst;
2385 char *jid, *type; 2391 char *fjid, *type;
2386 enum iqreq_type numtype = iqreq_none; 2392 enum iqreq_type numtype = iqreq_none;
2387 char *jid_utf8 = NULL; 2393 char *jid_utf8 = NULL;
2388 2394
2389 paramlst = split_arg(arg, 2, 0); // type, jid 2395 paramlst = split_arg(arg, 2, 0); // type, jid
2390 type = *paramlst; 2396 type = *paramlst;
2391 jid = *(paramlst+1); 2397 fjid = *(paramlst+1);
2392 2398
2393 if (type) { 2399 if (type) {
2394 // Quick check... 2400 // Quick check...
2395 if (!strcasecmp(type, "version")) 2401 if (!strcasecmp(type, "version"))
2396 numtype = iqreq_version; 2402 numtype = iqreq_version;
2414 free_arg_lst(paramlst); 2420 free_arg_lst(paramlst);
2415 return; 2421 return;
2416 } 2422 }
2417 2423
2418 // Allow special jid "" or "." (current buddy) 2424 // Allow special jid "" or "." (current buddy)
2419 if (jid && (!*jid || !strcmp(jid, "."))) 2425 if (fjid && (!*fjid || !strcmp(fjid, ".")))
2420 jid = NULL; 2426 fjid = NULL;
2421 2427
2422 if (jid) { 2428 if (fjid) {
2423 // The JID has been specified. Quick check... 2429 // The JID has been specified. Quick check...
2424 if (check_jid_syntax(jid)) { 2430 if (check_jid_syntax(fjid)) {
2425 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); 2431 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", fjid);
2426 jid = NULL; 2432 fjid = NULL;
2427 } else { 2433 } else {
2428 // Convert jid to lowercase 2434 // Convert jid to lowercase
2429 char *p; 2435 char *p;
2430 for (p = jid; *p && *p != JID_RESOURCE_SEPARATOR; p++) 2436 for (p = fjid; *p && *p != JID_RESOURCE_SEPARATOR; p++)
2431 *p = tolower(*p); 2437 *p = tolower(*p);
2432 jid = jid_utf8 = to_utf8(jid); 2438 fjid = jid_utf8 = to_utf8(fjid);
2433 } 2439 }
2434 } else { 2440 } else {
2435 // Add the current buddy 2441 // Add the current buddy
2436 if (current_buddy) 2442 if (current_buddy)
2437 jid = (char*)buddy_getjid(BUDDATA(current_buddy)); 2443 fjid = (char*)buddy_getjid(BUDDATA(current_buddy));
2438 if (!jid) 2444 if (!fjid)
2439 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); 2445 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
2440 } 2446 }
2441 2447
2442 if (jid) { 2448 if (fjid) {
2443 switch (numtype) { 2449 switch (numtype) {
2444 case iqreq_version: 2450 case iqreq_version:
2445 case iqreq_time: 2451 case iqreq_time:
2446 case iqreq_last: 2452 case iqreq_last:
2447 case iqreq_vcard: 2453 case iqreq_vcard:
2448 jb_request(jid, numtype); 2454 jb_request(fjid, numtype);
2449 break; 2455 break;
2450 default: 2456 default:
2451 break; 2457 break;
2452 } 2458 }
2453 } 2459 }