Changes in otr.c [47ab9a9:2c81d15]
Legend:
- Unmodified
- Added
- Removed
-
otr.c
r47ab9a9 r2c81d15 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 arately */189 i.e. msgstate should be announced seperately */ 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 222 218 /* functions to be called for certain events */ 223 219 static const struct irc_plugin otr_plugin; 224 225 #define OTR_COLOR_TRUSTED "03" /* green */226 #define OTR_COLOR_UNTRUSTED "05" /* red */227 220 228 221 /*** routines declared in otr.h: ***/ … … 441 434 442 435 /* don't do OTR on certain (not classic IM) protocols, e.g. twitter */ 443 if (ic->acc->prpl->options & OPT_NOOTR || 444 iu->bu->flags & BEE_USER_NOOTR) { 436 if (ic->acc->prpl->options & OPT_NOOTR) { 445 437 return msg; 446 438 } … … 459 451 } else if (!newmsg) { 460 452 /* this was a non-OTR message */ 461 return otr_filter_colors(msg);453 return msg; 462 454 } else { 463 455 /* we're done with the original msg, which will be caller-freed. */ … … 480 472 481 473 /* don't do OTR on certain (not classic IM) protocols, e.g. twitter */ 482 if (ic->acc->prpl->options & OPT_NOOTR || 483 iu->bu->flags & BEE_USER_NOOTR) { 474 if (ic->acc->prpl->options & OPT_NOOTR) { 484 475 return msg; 485 476 } … … 751 742 } 752 743 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 798 744 void op_convert_msg(void *opdata, ConnContext *ctx, OtrlConvertType typ, 799 745 char **dst, const char *src) … … 806 752 if (typ == OTRL_CONVERT_RECEIVING) { 807 753 char *msg = g_strdup(src); 754 char *buf = msg; 808 755 809 756 /* HTML decoding */ … … 812 759 set_getbool(&ic->bee->set, "strip_html")) { 813 760 strip_html(msg); 814 815 /* msg is borrowed by *dst (unless the next if decides to color it) */816 761 *dst = msg; 817 762 } … … 819 764 /* coloring */ 820 765 if (set_getbool(&ic->bee->set, "otr_color_encrypted")) { 766 int color; /* color according to f'print trust */ 767 char *pre = "", *sep = ""; /* optional parts */ 821 768 const char *trust = ctx->active_fingerprint->trust; 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); 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); 830 792 } 831 793 } else { … … 1395 1357 1396 1358 if (u) { 1397 /* just show this as a regular message*/1398 irc_user msg(u, "<<\002OTR\002>>%s", msg);1359 /* display as a notice from this particular user */ 1360 irc_usernotice(u, "%s", msg); 1399 1361 } else { 1400 1362 irc_rootmsg(irc, "[otr] %s", msg); … … 1733 1695 *p = '\0'; 1734 1696 1735 /* remove trailing whitespace */1736 g_strchomp(prefix);1737 1738 1697 /* find first key which matches the given prefix */ 1739 1698 n = strlen(prefix);
Note: See TracChangeset
for help on using the changeset viewer.