comparison src/protocols/irc/msgs.c @ 10774:d83f745c997b

[gaim-migrate @ 12383] Some escaping stuff, all over the place. Various escaping fixes in the IRC prpl. The core and plugins only need to escape text if it's going to be shown in a gtkimhtml or equivalent - such as writing to a conversation window, or gaim_notify_{formatted,userinfo} The primary and secondary text for all notify and request API functions do NOT need to be escaped by the core or plugins, because whether html-like markup is required for these is UI dependent. Now we always escape these in the Gtk UI request & notify ops. Should I backport any of the above to oldstatus? I also removed gaim_chat_get_display_name() - it was almost a duplicate of gaim_chat_get_name(), and it leaked. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 02 Apr 2005 17:18:43 +0000
parents bf5e48215158
children d087e928ffd1
comparison
equal deleted inserted replaced
10773:888d4c328be5 10774:d83f745c997b
74 } 74 }
75 75
76 void irc_msg_away(struct irc_conn *irc, const char *name, const char *from, char **args) 76 void irc_msg_away(struct irc_conn *irc, const char *name, const char *from, char **args)
77 { 77 {
78 GaimConnection *gc; 78 GaimConnection *gc;
79 char *msg;
79 80
80 if (!args || !args[1]) 81 if (!args || !args[1])
81 return; 82 return;
82 83
83 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) { 84 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) {
85 irc_msg_whois(irc, name, from, args); 86 irc_msg_whois(irc, name, from, args);
86 return; 87 return;
87 } 88 }
88 89
89 gc = gaim_account_get_connection(irc->account); 90 gc = gaim_account_get_connection(irc->account);
90 if (gc) 91 if (gc) {
91 serv_got_im(gc, args[1], args[2], GAIM_CONV_IM_AUTO_RESP, time(NULL)); 92 msg = g_markup_escape_text(args[2], -1);
93 serv_got_im(gc, args[1], msg, GAIM_CONV_IM_AUTO_RESP, time(NULL));
94 g_free(msg);
95 }
92 } 96 }
93 97
94 void irc_msg_badmode(struct irc_conn *irc, const char *name, const char *from, char **args) 98 void irc_msg_badmode(struct irc_conn *irc, const char *name, const char *from, char **args)
95 { 99 {
96 GaimConnection *gc = gaim_account_get_connection(irc->account); 100 GaimConnection *gc = gaim_account_get_connection(irc->account);
136 } 140 }
137 141
138 void irc_msg_chanmode(struct irc_conn *irc, const char *name, const char *from, char **args) 142 void irc_msg_chanmode(struct irc_conn *irc, const char *name, const char *from, char **args)
139 { 143 {
140 GaimConversation *convo; 144 GaimConversation *convo;
141 char *buf; 145 char *buf, *escaped;
142 146
143 if (!args || !args[1] || !args[2]) 147 if (!args || !args[1] || !args[2])
144 return; 148 return;
145 149
146 convo = gaim_find_conversation_with_account(GAIM_CONV_CHAT, args[1], irc->account); 150 convo = gaim_find_conversation_with_account(GAIM_CONV_CHAT, args[1], irc->account);
147 if (!convo) /* XXX punt on channels we are not in for now */ 151 if (!convo) /* XXX punt on channels we are not in for now */
148 return; 152 return;
149 153
150 buf = g_strdup_printf("mode for %s: %s %s", args[1], args[2], args[3] ? args[3] : ""); 154 escaped = (args[3] != NULL) ? g_markup_escape_text(args[3], -1) : NULL;
155 buf = g_strdup_printf("mode for %s: %s %s", args[1], args[2], escaped ? escaped : "");
151 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); 156 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL));
157 g_free(escaped);
152 g_free(buf); 158 g_free(buf);
153 159
154 return; 160 return;
155 } 161 }
156 162
414 } 420 }
415 421
416 void irc_msg_motd(struct irc_conn *irc, const char *name, const char *from, char **args) 422 void irc_msg_motd(struct irc_conn *irc, const char *name, const char *from, char **args)
417 { 423 {
418 GaimConnection *gc; 424 GaimConnection *gc;
425 char *escaped;
419 if (!strcmp(name, "375")) { 426 if (!strcmp(name, "375")) {
420 gc = gaim_account_get_connection(irc->account); 427 gc = gaim_account_get_connection(irc->account);
421 if (gc) 428 if (gc)
422 gaim_connection_set_display_name(gc, args[0]); 429 gaim_connection_set_display_name(gc, args[0]);
423 } 430 }
424 431
425 if (!irc->motd) 432 if (!irc->motd)
426 irc->motd = g_string_new(""); 433 irc->motd = g_string_new("");
427 434
428 g_string_append_printf(irc->motd, "%s<br>", args[1]); 435 escaped = g_markup_escape_text(args[1], -1);
436 g_string_append_printf(irc->motd, "%s<br>", escaped);
437 g_free(escaped);
429 } 438 }
430 439
431 void irc_msg_endmotd(struct irc_conn *irc, const char *name, const char *from, char **args) 440 void irc_msg_endmotd(struct irc_conn *irc, const char *name, const char *from, char **args)
432 { 441 {
433 GaimConnection *gc; 442 GaimConnection *gc;
468 477
469 void irc_msg_nonick(struct irc_conn *irc, const char *name, const char *from, char **args) 478 void irc_msg_nonick(struct irc_conn *irc, const char *name, const char *from, char **args)
470 { 479 {
471 GaimConnection *gc; 480 GaimConnection *gc;
472 GaimConversation *convo; 481 GaimConversation *convo;
473 char *nick;
474 482
475 convo = gaim_find_conversation_with_account(GAIM_CONV_ANY, args[1], irc->account); 483 convo = gaim_find_conversation_with_account(GAIM_CONV_ANY, args[1], irc->account);
476 if (convo) { 484 if (convo) {
477 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) /* does this happen? */ 485 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) /* does this happen? */
478 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], _("no such channel"), 486 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], _("no such channel"),
481 gaim_conv_im_write(GAIM_CONV_IM(convo), args[1], _("User is not logged in"), 489 gaim_conv_im_write(GAIM_CONV_IM(convo), args[1], _("User is not logged in"),
482 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); 490 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL));
483 } else { 491 } else {
484 if ((gc = gaim_account_get_connection(irc->account)) == NULL) 492 if ((gc = gaim_account_get_connection(irc->account)) == NULL)
485 return; 493 return;
486 nick = g_markup_escape_text(args[1], -1); 494 gaim_notify_error(gc, NULL, _("No such nick or channel"), args[1]);
487 gaim_notify_error(gc, NULL, _("No such nick or channel"), nick);
488 g_free(nick);
489 } 495 }
490 496
491 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) { 497 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) {
492 g_free(irc->whois.nick); 498 g_free(irc->whois.nick);
493 irc->whois.nick = NULL; 499 irc->whois.nick = NULL;
647 653
648 void irc_msg_kick(struct irc_conn *irc, const char *name, const char *from, char **args) 654 void irc_msg_kick(struct irc_conn *irc, const char *name, const char *from, char **args)
649 { 655 {
650 GaimConnection *gc = gaim_account_get_connection(irc->account); 656 GaimConnection *gc = gaim_account_get_connection(irc->account);
651 GaimConversation *convo = gaim_find_conversation_with_account(GAIM_CONV_CHAT, args[0], irc->account); 657 GaimConversation *convo = gaim_find_conversation_with_account(GAIM_CONV_CHAT, args[0], irc->account);
652 char *nick = irc_mask_nick(from), *buf; 658 char *nick = irc_mask_nick(from), *buf, *reason;
653 659
654 if (!gc) { 660 if (!gc) {
655 g_free(nick); 661 g_free(nick);
656 return; 662 return;
657 } 663 }
660 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Recieved a KICK for unknown channel %s\n", args[0]); 666 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Recieved a KICK for unknown channel %s\n", args[0]);
661 g_free(nick); 667 g_free(nick);
662 return; 668 return;
663 } 669 }
664 670
671 reason = g_markup_escape_text(args[2], -1);
665 if (!gaim_utf8_strcasecmp(gaim_connection_get_display_name(gc), args[1])) { 672 if (!gaim_utf8_strcasecmp(gaim_connection_get_display_name(gc), args[1])) {
666 buf = g_strdup_printf(_("You have been kicked by %s: (%s)"), nick, args[2]); 673 buf = g_strdup_printf(_("You have been kicked by %s: (%s)"), nick, reason);
667 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM, time(NULL)); 674 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM, time(NULL));
668 g_free(buf); 675 g_free(buf);
669 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo))); 676 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)));
670 } else { 677 } else {
671 buf = g_strdup_printf(_("Kicked by %s (%s)"), nick, args[2]); 678 buf = g_strdup_printf(_("Kicked by %s (%s)"), nick, reason);
672 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), args[1], buf); 679 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), args[1], buf);
673 g_free(buf); 680 g_free(buf);
674 } 681 }
675 682
683 g_free(reason);
676 g_free(nick); 684 g_free(nick);
677 return; 685 return;
678 } 686 }
679 687
680 void irc_msg_mode(struct irc_conn *irc, const char *name, const char *from, char **args) 688 void irc_msg_mode(struct irc_conn *irc, const char *name, const char *from, char **args)
681 { 689 {
682 GaimConversation *convo; 690 GaimConversation *convo;
683 char *nick = irc_mask_nick(from), *buf; 691 char *nick = irc_mask_nick(from), *buf;
684 692
685 if (*args[0] == '#' || *args[0] == '&') { /* Channel */ 693 if (*args[0] == '#' || *args[0] == '&') { /* Channel */
694 char *escaped;
686 convo = gaim_find_conversation_with_account(GAIM_CONV_CHAT, args[0], irc->account); 695 convo = gaim_find_conversation_with_account(GAIM_CONV_CHAT, args[0], irc->account);
687 if (!convo) { 696 if (!convo) {
688 gaim_debug(GAIM_DEBUG_ERROR, "irc", "MODE received for %s, which we are not in\n", args[0]); 697 gaim_debug(GAIM_DEBUG_ERROR, "irc", "MODE received for %s, which we are not in\n", args[0]);
689 g_free(nick); 698 g_free(nick);
690 return; 699 return;
691 } 700 }
692 buf = g_strdup_printf(_("mode (%s %s) by %s"), args[1], args[2] ? args[2] : "", nick); 701 escaped = (args[2] != NULL) ? g_markup_escape_text(args[2], -1) : NULL;
702 buf = g_strdup_printf(_("mode (%s %s) by %s"), args[1], escaped ? escaped : "", nick);
693 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); 703 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL));
704 g_free(escaped);
694 g_free(buf); 705 g_free(buf);
695 if(args[2]) { 706 if(args[2]) {
696 GaimConvChatBuddyFlags newflag, flags; 707 GaimConvChatBuddyFlags newflag, flags;
697 char *mcur, *cur, *end, *user; 708 char *mcur, *cur, *end, *user;
698 gboolean add = FALSE; 709 gboolean add = FALSE;
805 } 816 }
806 817
807 void irc_msg_nochangenick(struct irc_conn *irc, const char *name, const char *from, char **args) 818 void irc_msg_nochangenick(struct irc_conn *irc, const char *name, const char *from, char **args)
808 { 819 {
809 GaimConnection *gc = gaim_account_get_connection(irc->account); 820 GaimConnection *gc = gaim_account_get_connection(irc->account);
810 char *msg;
811 821
812 if (!args || !args[2] || !gc) 822 if (!args || !args[2] || !gc)
813 return; 823 return;
814 824
815 msg = g_strdup_printf(_("Could not change nick")); 825 gaim_notify_error(gc, _("Cannot change nick"), _("Could not change nick"), args[2]);
816 gaim_notify_error(gc, _("Cannot change nick"), msg, args[2]);
817 g_free(msg);
818 } 826 }
819 827
820 void irc_msg_part(struct irc_conn *irc, const char *name, const char *from, char **args) 828 void irc_msg_part(struct irc_conn *irc, const char *name, const char *from, char **args)
821 { 829 {
822 GaimConnection *gc = gaim_account_get_connection(irc->account); 830 GaimConnection *gc = gaim_account_get_connection(irc->account);
993 } 1001 }
994 1002
995 void irc_msg_wallops(struct irc_conn *irc, const char *name, const char *from, char **args) 1003 void irc_msg_wallops(struct irc_conn *irc, const char *name, const char *from, char **args)
996 { 1004 {
997 GaimConnection *gc = gaim_account_get_connection(irc->account); 1005 GaimConnection *gc = gaim_account_get_connection(irc->account);
998 char *nick, *msg, *wallop; 1006 char *nick, *msg;
999 1007
1000 if (!args || !args[0] || !gc) 1008 if (!args || !args[0] || !gc)
1001 return; 1009 return;
1002 1010
1003 nick = irc_mask_nick(from); 1011 nick = irc_mask_nick(from);
1004 msg = g_strdup_printf (_("Wallops from %s"), nick); 1012 msg = g_strdup_printf (_("Wallops from %s"), nick);
1005 g_free(nick); 1013 g_free(nick);
1006 wallop = g_markup_escape_text(args[0], strlen(args[0])); 1014 gaim_notify_info(gc, NULL, msg, args[0]);
1007 gaim_notify_info(gc, NULL, msg, wallop);
1008 g_free(msg); 1015 g_free(msg);
1009 g_free(wallop);
1010 } 1016 }
1011 1017
1012 void irc_msg_ignore(struct irc_conn *irc, const char *name, const char *from, char **args) 1018 void irc_msg_ignore(struct irc_conn *irc, const char *name, const char *from, char **args)
1013 { 1019 {
1014 return; 1020 return;