Changes in otr.c [2c81d15:47ab9a9]
Legend:
- Unmodified
- Added
- Removed
-
otr.c
r2c81d15 r47ab9a9 187 187 /* update op/voice flag of given user according to encryption state and settings 188 188 returns 0 if neither op_buddies nor voice_buddies is set to "encrypted", 189 i.e. msgstate should be announced sep erately */189 i.e. msgstate should be announced separately */ 190 190 int otr_update_modeflags(irc_t *irc, irc_user_t *u); 191 191 … … 216 216 void otr_disconnect_all(irc_t *irc); 217 217 218 /* modifies string in-place, replacing \x03 with '?', 219 as a quick way to prevent remote users from messing with irc colors */ 220 static char *otr_filter_colors(char *msg); 221 218 222 /* functions to be called for certain events */ 219 223 static const struct irc_plugin otr_plugin; 224 225 #define OTR_COLOR_TRUSTED "03" /* green */ 226 #define OTR_COLOR_UNTRUSTED "05" /* red */ 220 227 221 228 /*** routines declared in otr.h: ***/ … … 434 441 435 442 /* don't do OTR on certain (not classic IM) protocols, e.g. twitter */ 436 if (ic->acc->prpl->options & OPT_NOOTR) { 443 if (ic->acc->prpl->options & OPT_NOOTR || 444 iu->bu->flags & BEE_USER_NOOTR) { 437 445 return msg; 438 446 } … … 451 459 } else if (!newmsg) { 452 460 /* this was a non-OTR message */ 453 return msg;461 return otr_filter_colors(msg); 454 462 } else { 455 463 /* we're done with the original msg, which will be caller-freed. */ … … 472 480 473 481 /* don't do OTR on certain (not classic IM) protocols, e.g. twitter */ 474 if (ic->acc->prpl->options & OPT_NOOTR) { 482 if (ic->acc->prpl->options & OPT_NOOTR || 483 iu->bu->flags & BEE_USER_NOOTR) { 475 484 return msg; 476 485 } … … 742 751 } 743 752 753 static char *otr_filter_colors(char *msg) 754 { 755 return str_reject_chars(msg, "\x02\x03", '?'); 756 } 757 758 /* returns newly allocated string */ 759 static char *otr_color_encrypted(char *msg, char *color, gboolean is_query) { 760 char **lines; 761 GString *out; 762 int i; 763 764 lines = g_strsplit(msg, "\n", -1); 765 766 /* up to 4 extra chars per line (e.g., '\x03' + ("03"|"05") + ' ') */ 767 out = g_string_sized_new(strlen(msg) + g_strv_length(lines) * 4); 768 769 for (i = 0; lines[i]; i++) { 770 char *line = lines[i]; 771 772 if (i != 0) { 773 g_string_append_c(out, '\n'); 774 775 } else if (is_query && g_strncasecmp(line, "/me ", 4) == 0) { 776 /* in a query window, keep "/me " uncolored at the beginning */ 777 line += 4; 778 g_string_append(out, "/me "); 779 } 780 781 g_string_append_c(out, '\x03'); 782 g_string_append(out, color); 783 784 /* comma in first place could mess with the color code */ 785 if (line[0] == ',') { 786 /* insert a space between color spec and message */ 787 g_string_append_c(out, ' '); 788 } 789 790 g_string_append(out, otr_filter_colors(line)); 791 } 792 793 g_strfreev(lines); 794 795 return g_string_free(out, FALSE); 796 } 797 744 798 void op_convert_msg(void *opdata, ConnContext *ctx, OtrlConvertType typ, 745 799 char **dst, const char *src) … … 752 806 if (typ == OTRL_CONVERT_RECEIVING) { 753 807 char *msg = g_strdup(src); 754 char *buf = msg;755 808 756 809 /* HTML decoding */ … … 759 812 set_getbool(&ic->bee->set, "strip_html")) { 760 813 strip_html(msg); 814 815 /* msg is borrowed by *dst (unless the next if decides to color it) */ 761 816 *dst = msg; 762 817 } … … 764 819 /* coloring */ 765 820 if (set_getbool(&ic->bee->set, "otr_color_encrypted")) { 766 int color; /* color according to f'print trust */767 char *pre = "", *sep = ""; /* optional parts */768 821 const char *trust = ctx->active_fingerprint->trust; 769 770 if (trust && trust[0] != '\0') { 771 color = 3; /* green */ 772 } else { 773 color = 5; /* red */ 774 775 } 776 /* in a query window, keep "/me " uncolored at the beginning */ 777 if (g_strncasecmp(msg, "/me ", 4) == 0 778 && irc_user_msgdest(iu) == irc->user->nick) { 779 msg += 4; /* skip */ 780 pre = "/me "; 781 } 782 783 /* comma in first place could mess with the color code */ 784 if (msg[0] == ',') { 785 /* insert a space between color spec and message */ 786 sep = " "; 787 } 788 789 *dst = g_strdup_printf("%s\x03%.2d%s%s\x0F", pre, 790 color, sep, msg); 791 g_free(buf); 822 char *color = (trust && *trust) ? OTR_COLOR_TRUSTED : OTR_COLOR_UNTRUSTED; 823 gboolean is_query = (irc_user_msgdest(iu) == irc->user->nick); 824 825 /* the return value of otr_color_encrypted() is borrowed by *dst */ 826 *dst = otr_color_encrypted(msg, color, is_query); 827 828 /* this branch doesn't need msg */ 829 g_free(msg); 792 830 } 793 831 } else { … … 1357 1395 1358 1396 if (u) { 1359 /* display as a notice from this particular user*/1360 irc_user notice(u, "%s", msg);1397 /* just show this as a regular message */ 1398 irc_usermsg(u, "<<\002OTR\002>> %s", msg); 1361 1399 } else { 1362 1400 irc_rootmsg(irc, "[otr] %s", msg); … … 1695 1733 *p = '\0'; 1696 1734 1735 /* remove trailing whitespace */ 1736 g_strchomp(prefix); 1737 1697 1738 /* find first key which matches the given prefix */ 1698 1739 n = strlen(prefix);
Note: See TracChangeset
for help on using the changeset viewer.