- Timestamp:
- 2015-11-21T00:01:50Z (8 years ago)
- Parents:
- e4f08bf (diff), 8fdeaa5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
otr.c
re4f08bf r29ff5c2 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 int i; 755 for (i = 0; msg[i]; i++) { 756 if (msg[i] == '\x02' || msg[i] == '\x03') { 757 msg[i] = '?'; 758 } 759 } 760 return msg; 761 } 762 763 /* returns newly allocated string */ 764 static char *otr_color_encrypted(char *msg, char *color, gboolean is_query) { 765 char **lines; 766 GString *out; 767 int i; 768 769 lines = g_strsplit(msg, "\n", -1); 770 771 /* up to 4 extra chars per line (e.g., '\x03' + ("03"|"05") + ' ') */ 772 out = g_string_sized_new(strlen(msg) + g_strv_length(lines) * 4); 773 774 for (i = 0; lines[i]; i++) { 775 char *line = lines[i]; 776 777 if (i != 0) { 778 g_string_append_c(out, '\n'); 779 780 } else if (is_query && g_strncasecmp(line, "/me ", 4) == 0) { 781 /* in a query window, keep "/me " uncolored at the beginning */ 782 line += 4; 783 g_string_append(out, "/me "); 784 } 785 786 g_string_append_c(out, '\x03'); 787 g_string_append(out, color); 788 789 /* comma in first place could mess with the color code */ 790 if (line[0] == ',') { 791 /* insert a space between color spec and message */ 792 g_string_append_c(out, ' '); 793 } 794 795 g_string_append(out, otr_filter_colors(line)); 796 } 797 798 g_strfreev(lines); 799 800 return g_string_free(out, FALSE); 801 } 802 744 803 void op_convert_msg(void *opdata, ConnContext *ctx, OtrlConvertType typ, 745 804 char **dst, const char *src) … … 752 811 if (typ == OTRL_CONVERT_RECEIVING) { 753 812 char *msg = g_strdup(src); 754 char *buf = msg;755 813 756 814 /* HTML decoding */ … … 759 817 set_getbool(&ic->bee->set, "strip_html")) { 760 818 strip_html(msg); 819 820 /* msg is borrowed by *dst (unless the next if decides to color it) */ 761 821 *dst = msg; 762 822 } … … 764 824 /* coloring */ 765 825 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 826 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); 827 char *color = (trust && *trust) ? OTR_COLOR_TRUSTED : OTR_COLOR_UNTRUSTED; 828 gboolean is_query = (irc_user_msgdest(iu) == irc->user->nick); 829 830 /* the return value of otr_color_encrypted() is borrowed by *dst */ 831 *dst = otr_color_encrypted(msg, color, is_query); 832 833 /* this branch doesn't need msg */ 834 g_free(msg); 792 835 } 793 836 } else { … … 1357 1400 1358 1401 if (u) { 1359 /* display as a notice from this particular user*/1360 irc_user notice(u, "%s", msg);1402 /* just show this as a regular message */ 1403 irc_usermsg(u, "<<\002OTR\002>> %s", msg); 1361 1404 } else { 1362 1405 irc_rootmsg(irc, "[otr] %s", msg); … … 1695 1738 *p = '\0'; 1696 1739 1740 /* remove trailing whitespace */ 1741 g_strchomp(prefix); 1742 1697 1743 /* find first key which matches the given prefix */ 1698 1744 n = strlen(prefix);
Note: See TracChangeset
for help on using the changeset viewer.