comparison mcabber/src/commands.c @ 772:464be13343a9

Store most data in UTF-8 internally Only chat buffer data is still using 1 byte for char size. User input still doesn't handle UTF-8 locales.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 25 Mar 2006 18:10:36 +0100
parents ae23c8826efb
children 46304b773a44
comparison
equal deleted inserted replaced
771:ce4f8a2129a4 772:464be13343a9
63 static GSList *Commands; 63 static GSList *Commands;
64 64
65 65
66 // cmd_add() 66 // cmd_add()
67 // Adds a command to the commands list and to the CMD completion list 67 // Adds a command to the commands list and to the CMD completion list
68 void cmd_add(const char *name, const char *help, 68 static void cmd_add(const char *name, const char *help,
69 guint flags_row1, guint flags_row2, void (*f)()) 69 guint flags_row1, guint flags_row2, void (*f)())
70 { 70 {
71 cmd *n_cmd = g_new0(cmd, 1); 71 cmd *n_cmd = g_new0(cmd, 1);
72 strncpy(n_cmd->name, name, 32-1); 72 strncpy(n_cmd->name, name, 32-1);
73 n_cmd->help = help; 73 n_cmd->help = help;
78 // Add to completion CMD category 78 // Add to completion CMD category
79 compl_add_category_word(COMPL_CMD, name); 79 compl_add_category_word(COMPL_CMD, name);
80 } 80 }
81 81
82 // cmd_init() 82 // cmd_init()
83 // ... 83 // Commands table initialization
84 void cmd_init(void) 84 void cmd_init(void)
85 { 85 {
86 cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add); 86 cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add);
87 cmd_add("alias", "Add an alias", 0, 0, &do_alias); 87 cmd_add("alias", "Add an alias", 0, 0, &do_alias);
88 cmd_add("authorization", "Manage subscription authorizations", 88 cmd_add("authorization", "Manage subscription authorizations",
509 scr_LogPrint(LPRINT_NORMAL, "Your status is: [%c] %s", 509 scr_LogPrint(LPRINT_NORMAL, "Your status is: [%c] %s",
510 imstatus2char[jb_getstatus()], 510 imstatus2char[jb_getstatus()],
511 (sm ? sm : "")); 511 (sm ? sm : ""));
512 return; 512 return;
513 } 513 }
514 arg = to_utf8(arg);
514 setstatus(NULL, arg); 515 setstatus(NULL, arg);
516 g_free(arg);
515 } 517 }
516 518
517 static void do_status_to(char *arg) 519 static void do_status_to(char *arg)
518 { 520 {
519 char **paramlst; 521 char **paramlst;
520 char *jid, *st, *msg; 522 char *jid, *st, *msg;
523 char *jid_utf8 = NULL;
521 524
522 paramlst = split_arg(arg, 3, 1); // jid, status, [message] 525 paramlst = split_arg(arg, 3, 1); // jid, status, [message]
523 jid = *paramlst; 526 jid = *paramlst;
524 st = *(paramlst+1); 527 st = *(paramlst+1);
525 msg = *(paramlst+2); 528 msg = *(paramlst+2);
543 } else { 546 } else {
544 // Convert jid to lowercase 547 // Convert jid to lowercase
545 char *p = jid; 548 char *p = jid;
546 for ( ; *p && *p != '/'; p++) 549 for ( ; *p && *p != '/'; p++)
547 *p = tolower(*p); 550 *p = tolower(*p);
551 jid = jid_utf8 = to_utf8(jid);
548 } 552 }
549 } else { 553 } else {
550 // Add the current buddy 554 // Add the current buddy
551 if (current_buddy) 555 if (current_buddy)
552 jid = (char*)buddy_getjid(BUDDATA(current_buddy)); 556 jid = (char*)buddy_getjid(BUDDATA(current_buddy));
556 560
557 if (jid) { 561 if (jid) {
558 char *cmd; 562 char *cmd;
559 if (!msg) 563 if (!msg)
560 msg = ""; 564 msg = "";
565 msg = to_utf8(msg);
561 cmd = g_strdup_printf("%s %s", st, msg); 566 cmd = g_strdup_printf("%s %s", st, msg);
562 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", jid, cmd); 567 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", jid, cmd);
563 setstatus(jid, cmd); 568 setstatus(jid, cmd);
569 g_free(msg);
564 g_free(cmd); 570 g_free(cmd);
571 g_free(jid_utf8);
565 } 572 }
566 free_arg_lst(paramlst); 573 free_arg_lst(paramlst);
567 } 574 }
568 575
569 static void do_add(char *arg) 576 static void do_add(char *arg)
570 { 577 {
571 char **paramlst; 578 char **paramlst;
572 char *id, *nick; 579 char *id, *nick;
580 char *jid_utf8 = NULL;
573 581
574 if (!jb_getonline()) { 582 if (!jb_getonline()) {
575 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); 583 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
576 return; 584 return;
577 } 585 }
590 if (check_jid_syntax(id)) { 598 if (check_jid_syntax(id)) {
591 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", id); 599 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", id);
592 id = NULL; 600 id = NULL;
593 } else { 601 } else {
594 mc_strtolower(id); 602 mc_strtolower(id);
603 // Actually an UTF-8 id isn't needed because only the bare jid will
604 // be used.
605 id = jid_utf8 = to_utf8(id);
595 } 606 }
596 } else { 607 } else {
597 // Add the current buddy 608 // Add the current buddy
598 if (current_buddy) 609 if (current_buddy)
599 id = (char*)buddy_getjid(BUDDATA(current_buddy)); 610 id = (char*)buddy_getjid(BUDDATA(current_buddy));
600 if (!id) 611 if (!id)
601 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); 612 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
602 } 613 }
603 614
615 if (nick)
616 nick = to_utf8(nick);
617
604 if (id) { 618 if (id) {
605 // 2nd parameter = optional nickname 619 // 2nd parameter = optional nickname
606 jb_addbuddy(id, nick, NULL); 620 jb_addbuddy(id, nick, NULL);
607 scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>.", 621 scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>.",
608 id); 622 id);
609 } 623 }
624
625 g_free(jid_utf8);
626 g_free(nick);
610 free_arg_lst(paramlst); 627 free_arg_lst(paramlst);
611 } 628 }
612 629
613 static void do_del(char *arg) 630 static void do_del(char *arg)
614 { 631 {
738 scr_LogPrint(LPRINT_NORMAL, "This is not a user."); 755 scr_LogPrint(LPRINT_NORMAL, "This is not a user.");
739 return; 756 return;
740 } 757 }
741 758
742 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); 759 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
760 arg = to_utf8(arg);
743 send_message(arg); 761 send_message(arg);
762 g_free(arg);
744 } 763 }
745 764
746 static void do_msay(char *arg) 765 static void do_msay(char *arg)
747 { 766 {
748 /* Parameters: begin verbatim abort send send_to */ 767 /* Parameters: begin verbatim abort send send_to */
793 } 812 }
794 813
795 scr_set_chatmode(TRUE); 814 scr_set_chatmode(TRUE);
796 815
797 if (!strcasecmp(subcmd, "send_to")) { 816 if (!strcasecmp(subcmd, "send_to")) {
817 int err;
818 gchar *msg_utf8;
798 // Let's send to the specified JID. We leave now if there 819 // Let's send to the specified JID. We leave now if there
799 // has been an error (so we don't leave multi-line mode). 820 // has been an error (so we don't leave multi-line mode).
800 if (send_message_to(arg, scr_get_multiline())) 821 arg = to_utf8(arg);
822 msg_utf8 = to_utf8(scr_get_multiline());
823 err = send_message_to(arg, msg_utf8);
824 g_free(msg_utf8);
825 g_free(arg);
826 if (err)
801 return; 827 return;
802 } else { // Send to currently selected buddy 828 } else { // Send to currently selected buddy
803 gpointer bud; 829 gpointer bud;
830 gchar *msg_utf8;
804 831
805 if (!current_buddy) { 832 if (!current_buddy) {
806 scr_LogPrint(LPRINT_NORMAL, "Whom are you talking to?"); 833 scr_LogPrint(LPRINT_NORMAL, "Whom are you talking to?");
807 return; 834 return;
808 } 835 }
812 scr_LogPrint(LPRINT_NORMAL, "This is not a user."); 839 scr_LogPrint(LPRINT_NORMAL, "This is not a user.");
813 return; 840 return;
814 } 841 }
815 842
816 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); 843 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
817 send_message(scr_get_multiline()); 844 msg_utf8 = to_utf8(scr_get_multiline());
845 send_message(msg_utf8);
846 g_free(msg_utf8);
818 } 847 }
819 scr_set_multimode(FALSE); 848 scr_set_multimode(FALSE);
820 } 849 }
821 850
822 static void do_say_to(char *arg) 851 static void do_say_to(char *arg)
837 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); 866 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
838 free_arg_lst(paramlst); 867 free_arg_lst(paramlst);
839 return; 868 return;
840 } 869 }
841 870
871 jid = to_utf8(jid);
872 msg = to_utf8(msg);
873
842 send_message_to(jid, msg); 874 send_message_to(jid, msg);
875
876 g_free(jid);
877 g_free(msg);
843 free_arg_lst(paramlst); 878 free_arg_lst(paramlst);
844 } 879 }
845 880
846 // buffer_updown(updown, nblines) 881 // buffer_updown(updown, nblines)
847 // updown: -1=up, +1=down 882 // updown: -1=up, +1=down
1088 { 1123 {
1089 gpointer bud; 1124 gpointer bud;
1090 const char *jid, *group; 1125 const char *jid, *group;
1091 guint type; 1126 guint type;
1092 char *newname, *p; 1127 char *newname, *p;
1128 char *name_utf8;
1093 1129
1094 if (!*arg) { 1130 if (!*arg) {
1095 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID to rename."); 1131 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID to rename.");
1096 return; 1132 return;
1097 } 1133 }
1113 for (p = newname; *p; p++) ; 1149 for (p = newname; *p; p++) ;
1114 while (p > newname && *p == ' ') *p = 0; 1150 while (p > newname && *p == ' ') *p = 0;
1115 1151
1116 strip_arg_special_chars(newname); 1152 strip_arg_special_chars(newname);
1117 1153
1118 buddy_setname(bud, newname); 1154 name_utf8 = to_utf8(newname);
1119 jb_updatebuddy(jid, newname, group); 1155 buddy_setname(bud, name_utf8);
1120 1156 jb_updatebuddy(jid, name_utf8, group);
1157
1158 g_free(name_utf8);
1121 g_free(newname); 1159 g_free(newname);
1122 update_roster = TRUE; 1160 update_roster = TRUE;
1123 } 1161 }
1124 1162
1125 static void do_move(char *arg) 1163 static void do_move(char *arg)
1126 { 1164 {
1127 gpointer bud; 1165 gpointer bud;
1128 const char *jid, *name, *oldgroupname; 1166 const char *jid, *name, *oldgroupname;
1129 guint type; 1167 guint type;
1130 char *newgroupname, *p; 1168 char *newgroupname, *p;
1169 char *group_utf8;
1131 1170
1132 if (!current_buddy) return; 1171 if (!current_buddy) return;
1133 bud = BUDDATA(current_buddy); 1172 bud = BUDDATA(current_buddy);
1134 1173
1135 jid = buddy_getjid(bud); 1174 jid = buddy_getjid(bud);
1148 for (p = newgroupname; *p; p++) ; 1187 for (p = newgroupname; *p; p++) ;
1149 while (p > newgroupname && *p == ' ') *p-- = 0; 1188 while (p > newgroupname && *p == ' ') *p-- = 0;
1150 1189
1151 strip_arg_special_chars(newgroupname); 1190 strip_arg_special_chars(newgroupname);
1152 1191
1153 if (strcmp(oldgroupname, newgroupname)) { 1192 group_utf8 = to_utf8(newgroupname);
1154 jb_updatebuddy(jid, name, *newgroupname ? newgroupname : NULL); 1193 if (strcmp(oldgroupname, group_utf8)) {
1194 jb_updatebuddy(jid, name, *group_utf8 ? group_utf8 : NULL);
1155 scr_RosterUp(); 1195 scr_RosterUp();
1156 buddy_setgroup(bud, newgroupname); 1196 buddy_setgroup(bud, group_utf8);
1157 } 1197 }
1158 1198
1199 g_free(group_utf8);
1159 g_free(newgroupname); 1200 g_free(newgroupname);
1160 update_roster = TRUE; 1201 update_roster = TRUE;
1161 } 1202 }
1162 1203
1163 static void do_set(char *arg) 1204 static void do_set(char *arg)
1164 { 1205 {
1165 guint assign; 1206 guint assign;
1166 const gchar *option, *value; 1207 const gchar *option, *value;
1208 gchar *option_utf8;
1167 1209
1168 assign = parse_assigment(arg, &option, &value); 1210 assign = parse_assigment(arg, &option, &value);
1169 if (!option) { 1211 if (!option) {
1170 scr_LogPrint(LPRINT_NORMAL, "Set what option?"); 1212 scr_LogPrint(LPRINT_NORMAL, "Set what option?");
1171 return; 1213 return;
1172 } 1214 }
1215 option_utf8 = to_utf8(option);
1173 if (!assign) { 1216 if (!assign) {
1174 // This is a query 1217 // This is a query
1175 value = settings_opt_get(option); 1218 value = settings_opt_get(option_utf8);
1176 if (value) { 1219 if (value) {
1177 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option, value); 1220 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option_utf8, value);
1178 } else 1221 } else
1179 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option); 1222 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option_utf8);
1223 g_free(option_utf8);
1180 return; 1224 return;
1181 } 1225 }
1182 // Update the option 1226 // Update the option
1183 // XXX Maybe some options should be protected when user is connected 1227 // XXX Maybe some options should be protected when user is connected
1184 // (server, username, etc.). And we should catch some options here, too 1228 // (server, username, etc.). And we should catch some options here, too
1185 // (hide_offline_buddies for ex.) 1229 // (hide_offline_buddies for ex.)
1186 if (!value) { 1230 if (!value) {
1187 settings_del(SETTINGS_TYPE_OPTION, option); 1231 settings_del(SETTINGS_TYPE_OPTION, option_utf8);
1188 } else { 1232 } else {
1189 settings_set(SETTINGS_TYPE_OPTION, option, value); 1233 gchar *value_utf8 = to_utf8(value);
1190 } 1234 settings_set(SETTINGS_TYPE_OPTION, option_utf8, value_utf8);
1235 g_free(value_utf8);
1236 }
1237 g_free(option_utf8);
1191 } 1238 }
1192 1239
1193 static void do_alias(char *arg) 1240 static void do_alias(char *arg)
1194 { 1241 {
1195 guint assign; 1242 guint assign;
1202 } 1249 }
1203 if (!assign) { 1250 if (!assign) {
1204 // This is a query 1251 // This is a query
1205 value = settings_get(SETTINGS_TYPE_ALIAS, alias); 1252 value = settings_get(SETTINGS_TYPE_ALIAS, alias);
1206 if (value) { 1253 if (value) {
1207 scr_LogPrint(LPRINT_NORMAL, "%s = %s", alias, value); 1254 // XXX LPRINT_NOTUTF8 here, see below why it isn't encoded...
1255 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, "%s = %s", alias, value);
1208 } else 1256 } else
1209 scr_LogPrint(LPRINT_NORMAL, "Alias '%s' does not exist", alias); 1257 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
1258 "Alias '%s' does not exist", alias);
1210 return; 1259 return;
1211 } 1260 }
1212 // Check the alias does not conflict with a registered command 1261 // Check the alias does not conflict with a registered command
1213 if (cmd_get(alias)) { 1262 if (cmd_get(alias)) {
1214 scr_LogPrint(LPRINT_NORMAL, "'%s' is a reserved word!", alias); 1263 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
1264 "'%s' is a reserved word!", alias);
1215 return; 1265 return;
1216 } 1266 }
1217 // Update the alias 1267 // Update the alias
1218 if (!value) { 1268 if (!value) {
1219 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) { 1269 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) {
1220 settings_del(SETTINGS_TYPE_ALIAS, alias); 1270 settings_del(SETTINGS_TYPE_ALIAS, alias);
1221 // Remove alias from the completion list 1271 // Remove alias from the completion list
1222 compl_del_category_word(COMPL_CMD, alias); 1272 compl_del_category_word(COMPL_CMD, alias);
1223 } 1273 }
1224 } else { 1274 } else {
1225 // Add alias to the completion list, if not already in 1275 /* Add alias to the completion list, if not already in.
1276 XXX We're not UTF8-encoding "alias" and "value" here because UTF-8 is
1277 not yet supported in the UI... (and we use the values in the completion
1278 system)
1279 */
1226 if (!settings_get(SETTINGS_TYPE_ALIAS, alias)) 1280 if (!settings_get(SETTINGS_TYPE_ALIAS, alias))
1227 compl_add_category_word(COMPL_CMD, alias); 1281 compl_add_category_word(COMPL_CMD, alias);
1228 settings_set(SETTINGS_TYPE_ALIAS, alias, value); 1282 settings_set(SETTINGS_TYPE_ALIAS, alias, value);
1229 } 1283 }
1230 } 1284 }
1247 } else 1301 } else
1248 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound.", keycode); 1302 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound.", keycode);
1249 return; 1303 return;
1250 } 1304 }
1251 // Update the key binding 1305 // Update the key binding
1252 if (!value) 1306 if (!value) {
1253 settings_del(SETTINGS_TYPE_BINDING, keycode); 1307 settings_del(SETTINGS_TYPE_BINDING, keycode);
1254 else 1308 } else {
1255 settings_set(SETTINGS_TYPE_BINDING, keycode, value); 1309 gchar *value_utf8 = to_utf8(value);
1310 settings_set(SETTINGS_TYPE_BINDING, keycode, value_utf8);
1311 g_free(value_utf8);
1312 }
1256 } 1313 }
1257 1314
1258 static void do_rawxml(char *arg) 1315 static void do_rawxml(char *arg)
1259 { 1316 {
1260 char **paramlst; 1317 char **paramlst;
1358 nick = tmpnick = g_strdup(nick); 1415 nick = tmpnick = g_strdup(nick);
1359 p = strchr(nick, '@'); 1416 p = strchr(nick, '@');
1360 *p = 0; 1417 *p = 0;
1361 } 1418 }
1362 } 1419 }
1420 } else {
1421 nick = tmpnick = to_utf8(nick);
1363 } 1422 }
1364 // If we still have no nickname, give up 1423 // If we still have no nickname, give up
1365 if (!nick || !*nick) { 1424 if (!nick || !*nick) {
1366 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname."); 1425 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname.");
1426 g_free(tmpnick);
1367 free_arg_lst(paramlst); 1427 free_arg_lst(paramlst);
1368 return; 1428 return;
1369 } 1429 }
1370 1430
1371 // Note that roomname is part of the array allocated by split_arg(), 1431 // Note that roomname is part of the array allocated by split_arg(),
1372 // so we can modify it. 1432 // so we can modify it.
1373 mc_strtolower(roomname); 1433 mc_strtolower(roomname);
1434 roomname = to_utf8(roomname);
1374 jb_room_join(roomname, nick); 1435 jb_room_join(roomname, nick);
1375 1436
1376 scr_LogPrint(LPRINT_LOGNORM, "Sent a join request to <%s>...", roomname); 1437 scr_LogPrint(LPRINT_LOGNORM, "Sent a join request to <%s>...", roomname);
1377 1438
1439 g_free(roomname);
1440 g_free(tmpnick);
1378 buddylist_build(); 1441 buddylist_build();
1379 update_roster = TRUE; 1442 update_roster = TRUE;
1380 free_arg_lst(paramlst); 1443 free_arg_lst(paramlst);
1381 if (tmpnick)
1382 g_free(tmpnick);
1383 } 1444 }
1384 1445
1385 static void room_invite(gpointer bud, char *arg) 1446 static void room_invite(gpointer bud, char *arg)
1386 { 1447 {
1387 char **paramlst; 1448 char **paramlst;
1388 const gchar *roomname; 1449 const gchar *roomname;
1389 char* jid; 1450 char* jid;
1451 gchar *reason_utf8;
1390 1452
1391 paramlst = split_arg(arg, 2, 1); // jid, [reason] 1453 paramlst = split_arg(arg, 2, 1); // jid, [reason]
1392 jid = *paramlst; 1454 jid = *paramlst;
1393 arg = *(paramlst+1); 1455 arg = *(paramlst+1);
1394 // An empty reason is no reason... 1456 // An empty reason is no reason...
1400 free_arg_lst(paramlst); 1462 free_arg_lst(paramlst);
1401 return; 1463 return;
1402 } 1464 }
1403 1465
1404 roomname = buddy_getjid(bud); 1466 roomname = buddy_getjid(bud);
1405 jb_room_invite(roomname, jid, arg); 1467 reason_utf8 = to_utf8(arg);
1468 jb_room_invite(roomname, jid, reason_utf8);
1406 scr_LogPrint(LPRINT_LOGNORM, "Invitation sent to <%s>...", jid); 1469 scr_LogPrint(LPRINT_LOGNORM, "Invitation sent to <%s>...", jid);
1470 if (reason_utf8) g_free(reason_utf8);
1407 free_arg_lst(paramlst); 1471 free_arg_lst(paramlst);
1408 } 1472 }
1409 1473
1410 static void room_affil(gpointer bud, char *arg) 1474 static void room_affil(gpointer bud, char *arg)
1411 { 1475 {
1429 ra.val.affil = affil_none; 1493 ra.val.affil = affil_none;
1430 for (; ra.val.affil < imaffiliation_size; ra.val.affil++) 1494 for (; ra.val.affil < imaffiliation_size; ra.val.affil++)
1431 if (!strcasecmp(rolename, straffil[ra.val.affil])) 1495 if (!strcasecmp(rolename, straffil[ra.val.affil]))
1432 break; 1496 break;
1433 1497
1434 if (ra.val.affil < imaffiliation_size) 1498 if (ra.val.affil < imaffiliation_size) {
1435 jb_room_setattrib(roomid, jid, NULL, ra, arg); 1499 gchar *jid_utf8, *reason_utf8;
1436 else 1500 jid_utf8 = to_utf8(jid);
1501 reason_utf8 = to_utf8(arg);
1502 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
1503 if (jid_utf8) g_free(jid_utf8);
1504 if (reason_utf8) g_free(reason_utf8);
1505 } else
1437 scr_LogPrint(LPRINT_NORMAL, "Wrong affiliation parameter."); 1506 scr_LogPrint(LPRINT_NORMAL, "Wrong affiliation parameter.");
1438 1507
1439 free_arg_lst(paramlst); 1508 free_arg_lst(paramlst);
1440 } 1509 }
1441 1510
1461 ra.val.role = role_none; 1530 ra.val.role = role_none;
1462 for (; ra.val.role < imrole_size; ra.val.role++) 1531 for (; ra.val.role < imrole_size; ra.val.role++)
1463 if (!strcasecmp(rolename, strrole[ra.val.role])) 1532 if (!strcasecmp(rolename, strrole[ra.val.role]))
1464 break; 1533 break;
1465 1534
1466 if (ra.val.role < imrole_size) 1535 if (ra.val.role < imrole_size) {
1467 jb_room_setattrib(roomid, jid, NULL, ra, arg); 1536 gchar *jid_utf8, *reason_utf8;
1468 else 1537 jid_utf8 = to_utf8(jid);
1538 reason_utf8 = to_utf8(arg);
1539 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
1540 if (jid_utf8) g_free(jid_utf8);
1541 if (reason_utf8) g_free(reason_utf8);
1542 } else
1469 scr_LogPrint(LPRINT_NORMAL, "Wrong role parameter."); 1543 scr_LogPrint(LPRINT_NORMAL, "Wrong role parameter.");
1470 1544
1471 free_arg_lst(paramlst); 1545 free_arg_lst(paramlst);
1472 } 1546 }
1473 1547
1475 // The expected argument is a Jabber id 1549 // The expected argument is a Jabber id
1476 static void room_ban(gpointer bud, char *arg) 1550 static void room_ban(gpointer bud, char *arg)
1477 { 1551 {
1478 char **paramlst; 1552 char **paramlst;
1479 gchar *jid; 1553 gchar *jid;
1554 gchar *jid_utf8, *reason_utf8;
1480 struct role_affil ra; 1555 struct role_affil ra;
1481 const char *roomid = buddy_getjid(bud); 1556 const char *roomid = buddy_getjid(bud);
1482 1557
1483 paramlst = split_arg(arg, 2, 1); // jid, [reason] 1558 paramlst = split_arg(arg, 2, 1); // jid, [reason]
1484 jid = *paramlst; 1559 jid = *paramlst;
1491 } 1566 }
1492 1567
1493 ra.type = type_affil; 1568 ra.type = type_affil;
1494 ra.val.affil = affil_outcast; 1569 ra.val.affil = affil_outcast;
1495 1570
1496 jb_room_setattrib(roomid, jid, NULL, ra, arg); 1571 jid_utf8 = to_utf8(jid);
1572 reason_utf8 = to_utf8(arg);
1573 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
1574 if (jid_utf8) g_free(jid_utf8);
1575 if (reason_utf8) g_free(reason_utf8);
1497 1576
1498 free_arg_lst(paramlst); 1577 free_arg_lst(paramlst);
1499 } 1578 }
1500 1579
1501 // The expected argument is a nickname 1580 // The expected argument is a nickname
1502 static void room_kick(gpointer bud, char *arg) 1581 static void room_kick(gpointer bud, char *arg)
1503 { 1582 {
1504 char **paramlst; 1583 char **paramlst;
1505 gchar *nick; 1584 gchar *nick;
1585 gchar *nick_utf8, *reason_utf8;
1506 struct role_affil ra; 1586 struct role_affil ra;
1507 const char *roomid = buddy_getjid(bud); 1587 const char *roomid = buddy_getjid(bud);
1508 1588
1509 paramlst = split_arg(arg, 2, 1); // nickname, [reason] 1589 paramlst = split_arg(arg, 2, 1); // nickname, [reason]
1510 nick = *paramlst; 1590 nick = *paramlst;
1517 } 1597 }
1518 1598
1519 ra.type = type_role; 1599 ra.type = type_role;
1520 ra.val.affil = role_none; 1600 ra.val.affil = role_none;
1521 1601
1522 jb_room_setattrib(roomid, NULL, nick, ra, arg); 1602 nick_utf8 = to_utf8(nick);
1603 reason_utf8 = to_utf8(arg);
1604 jb_room_setattrib(roomid, NULL, nick_utf8, ra, reason_utf8);
1605 if (nick_utf8) g_free(nick_utf8);
1606 if (reason_utf8) g_free(reason_utf8);
1523 1607
1524 free_arg_lst(paramlst); 1608 free_arg_lst(paramlst);
1525 } 1609 }
1526 1610
1527 static void room_leave(gpointer bud, char *arg) 1611 static void room_leave(gpointer bud, char *arg)
1528 { 1612 {
1529 gchar *roomid, *utf8_nickname; 1613 gchar *roomid, *desc;
1530 const char *nickname; 1614 const char *nickname;
1531 1615
1532 nickname = buddy_getnickname(bud); 1616 nickname = buddy_getnickname(bud);
1533 if (!nickname) { 1617 if (!nickname) {
1534 scr_LogPrint(LPRINT_NORMAL, "You are not in this room."); 1618 scr_LogPrint(LPRINT_NORMAL, "You are not in this room.");
1535 return; 1619 return;
1536 } 1620 }
1537 1621
1538 utf8_nickname = to_utf8(nickname); 1622 roomid = g_strdup_printf("%s/%s", buddy_getjid(bud), nickname);
1539 roomid = g_strdup_printf("%s/%s", buddy_getjid(bud), utf8_nickname); 1623 desc = to_utf8(arg);
1540 jb_setstatus(offline, roomid, arg); 1624 jb_setstatus(offline, roomid, desc);
1541 g_free(utf8_nickname); 1625 g_free(desc);
1542 g_free(roomid); 1626 g_free(roomid);
1543 } 1627 }
1544 1628
1545 static void room_nick(gpointer bud, char *arg) 1629 static void room_nick(gpointer bud, char *arg)
1546 { 1630 {
1622 else 1706 else
1623 scr_LogPrint(LPRINT_NORMAL, "No topic has been set."); 1707 scr_LogPrint(LPRINT_NORMAL, "No topic has been set.");
1624 return; 1708 return;
1625 } 1709 }
1626 1710
1711 arg = to_utf8(arg);
1627 // Set the topic 1712 // Set the topic
1628 msg = g_strdup_printf("/me has set the topic to: %s", arg); 1713 msg = g_strdup_printf("/me has set the topic to: %s", arg);
1629 jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg); 1714 jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg);
1715 g_free(arg);
1630 g_free(msg); 1716 g_free(msg);
1631 } 1717 }
1632 1718
1633 static void room_destroy(gpointer bud, char *arg) 1719 static void room_destroy(gpointer bud, char *arg)
1634 { 1720 {
1635 gchar *msg; 1721 gchar *msg;
1636 1722
1637 if (arg && *arg) 1723 if (arg && *arg)
1638 msg = arg; 1724 msg = to_utf8(arg);
1639 else 1725 else
1640 msg = NULL; 1726 msg = NULL;
1641 1727
1642 jb_room_destroy(buddy_getjid(bud), NULL, msg); 1728 jb_room_destroy(buddy_getjid(bud), NULL, msg);
1729 if (msg) g_free(msg);
1643 } 1730 }
1644 1731
1645 static void room_unlock(gpointer bud, char *arg) 1732 static void room_unlock(gpointer bud, char *arg)
1646 { 1733 {
1647 if (*arg) { 1734 if (*arg) {
1810 1897
1811 static void do_authorization(char *arg) 1898 static void do_authorization(char *arg)
1812 { 1899 {
1813 char **paramlst; 1900 char **paramlst;
1814 char *subcmd; 1901 char *subcmd;
1902 char *jid_utf8;
1815 1903
1816 if (!jb_getonline()) { 1904 if (!jb_getonline()) {
1817 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); 1905 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
1818 return; 1906 return;
1819 } 1907 }
1847 guint type; 1935 guint type;
1848 1936
1849 if (!current_buddy) return; 1937 if (!current_buddy) return;
1850 bud = BUDDATA(current_buddy); 1938 bud = BUDDATA(current_buddy);
1851 1939
1852 arg = (char*)buddy_getjid(bud); 1940 jid_utf8 = arg = (char*)buddy_getjid(bud);
1853 type = buddy_gettype(bud); 1941 type = buddy_gettype(bud);
1854 1942
1855 if (!(type & (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT))) { 1943 if (!(type & (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT))) {
1856 scr_LogPrint(LPRINT_NORMAL, "Invalid buddy."); 1944 scr_LogPrint(LPRINT_NORMAL, "Invalid buddy.");
1857 return; 1945 return;
1858 } 1946 }
1947 } else {
1948 jid_utf8 = to_utf8(arg);
1859 } 1949 }
1860 1950
1861 if (!strcasecmp(subcmd, "allow")) { 1951 if (!strcasecmp(subcmd, "allow")) {
1862 jb_subscr_send_auth(arg); 1952 jb_subscr_send_auth(jid_utf8);
1863 scr_LogPrint(LPRINT_LOGNORM, 1953 scr_LogPrint(LPRINT_LOGNORM,
1864 "<%s> is now allowed to receive your presence updates.", arg); 1954 "<%s> is now allowed to receive your presence updates.",
1955 jid_utf8);
1865 } else if (!strcasecmp(subcmd, "cancel")) { 1956 } else if (!strcasecmp(subcmd, "cancel")) {
1866 jb_subscr_cancel_auth(arg); 1957 jb_subscr_cancel_auth(jid_utf8);
1867 scr_LogPrint(LPRINT_LOGNORM, 1958 scr_LogPrint(LPRINT_LOGNORM,
1868 "<%s> will no longer receive your presence updates.", 1959 "<%s> will no longer receive your presence updates.",
1869 arg); 1960 jid_utf8);
1870 } else if (!strcasecmp(subcmd, "request")) { 1961 } else if (!strcasecmp(subcmd, "request")) {
1871 jb_subscr_request_auth(arg); 1962 jb_subscr_request_auth(jid_utf8);
1872 scr_LogPrint(LPRINT_LOGNORM, 1963 scr_LogPrint(LPRINT_LOGNORM,
1873 "Sent presence notification request to <%s>...", arg); 1964 "Sent presence notification request to <%s>...", jid_utf8);
1874 } else { 1965 } else {
1875 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); 1966 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
1876 } 1967 }
1877 1968
1969 // Only free jid_utf8 if it has been allocated, i.e. if != arg.
1970 if (jid_utf8 && jid_utf8 != arg)
1971 g_free(jid_utf8);
1878 free_arg_lst(paramlst); 1972 free_arg_lst(paramlst);
1879 } 1973 }
1880 1974
1881 static void do_version(char *arg) 1975 static void do_version(char *arg)
1882 { 1976 {
1886 static void do_request(char *arg) 1980 static void do_request(char *arg)
1887 { 1981 {
1888 char **paramlst; 1982 char **paramlst;
1889 char *jid, *type; 1983 char *jid, *type;
1890 enum iqreq_type numtype = iqreq_none; 1984 enum iqreq_type numtype = iqreq_none;
1985 char *jid_utf8 = NULL;
1891 1986
1892 paramlst = split_arg(arg, 2, 0); // type, jid 1987 paramlst = split_arg(arg, 2, 0); // type, jid
1893 type = *paramlst; 1988 type = *paramlst;
1894 jid = *(paramlst+1); 1989 jid = *(paramlst+1);
1895 1990
1923 if (check_jid_syntax(jid)) { 2018 if (check_jid_syntax(jid)) {
1924 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); 2019 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid);
1925 jid = NULL; 2020 jid = NULL;
1926 } else { 2021 } else {
1927 // Convert jid to lowercase 2022 // Convert jid to lowercase
1928 char *p = jid; 2023 char *p;
1929 for ( ; *p && *p != '/'; p++) 2024 for (p = jid; *p && *p != '/'; p++)
1930 *p = tolower(*p); 2025 *p = tolower(*p);
2026 jid = jid_utf8 = to_utf8(jid);
1931 } 2027 }
1932 } else { 2028 } else {
1933 // Add the current buddy 2029 // Add the current buddy
1934 if (current_buddy) 2030 if (current_buddy)
1935 jid = (char*)buddy_getjid(BUDDATA(current_buddy)); 2031 jid = (char*)buddy_getjid(BUDDATA(current_buddy));
1945 break; 2041 break;
1946 default: 2042 default:
1947 break; 2043 break;
1948 } 2044 }
1949 } 2045 }
2046 g_free(jid_utf8);
1950 free_arg_lst(paramlst); 2047 free_arg_lst(paramlst);
1951 } 2048 }
1952 2049
1953 static void do_event(char *arg) 2050 static void do_event(char *arg)
1954 { 2051 {