Changeset 654112d4
- Timestamp:
- 2015-08-11T06:48:15Z (9 years ago)
- Branches:
- master
- Children:
- 86fd261
- Parents:
- 666722e
- git-author:
- dequis <dx@…> (11-08-15 04:53:08)
- git-committer:
- dequis <dx@…> (11-08-15 06:48:15)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
otr.c
r666722e r654112d4 218 218 /* functions to be called for certain events */ 219 219 static const struct irc_plugin otr_plugin; 220 221 #define OTR_COLOR_TRUSTED "03" /* green */ 222 #define OTR_COLOR_UNTRUSTED "05" /* red */ 220 223 221 224 /*** routines declared in otr.h: ***/ … … 742 745 } 743 746 747 /* returns newly allocated string */ 748 static char *otr_color_encrypted(char *msg, char *color, gboolean is_query) { 749 char **lines; 750 GString *out; 751 int i; 752 753 lines = g_strsplit(msg, "\n", -1); 754 755 /* up to 4 extra chars per line (e.g., '\x03' + ("03"|"05") + ' ') */ 756 out = g_string_sized_new(strlen(msg) + g_strv_length(lines) * 4); 757 758 for (i = 0; lines[i]; i++) { 759 char *line = lines[i]; 760 761 if (i != 0) { 762 g_string_append_c(out, '\n'); 763 764 } else if (is_query && g_strncasecmp(line, "/me ", 4) == 0) { 765 /* in a query window, keep "/me " uncolored at the beginning */ 766 line += 4; 767 g_string_append(out, "/me "); 768 } 769 770 g_string_append_c(out, '\x03'); 771 g_string_append(out, color); 772 773 /* comma in first place could mess with the color code */ 774 if (line[0] == ',') { 775 /* insert a space between color spec and message */ 776 g_string_append_c(out, ' '); 777 } 778 779 g_string_append(out, line); 780 } 781 782 g_strfreev(lines); 783 784 return g_string_free(out, FALSE); 785 } 786 744 787 void op_convert_msg(void *opdata, ConnContext *ctx, OtrlConvertType typ, 745 788 char **dst, const char *src) … … 752 795 if (typ == OTRL_CONVERT_RECEIVING) { 753 796 char *msg = g_strdup(src); 754 char *buf = msg;755 797 756 798 /* HTML decoding */ … … 759 801 set_getbool(&ic->bee->set, "strip_html")) { 760 802 strip_html(msg); 803 804 /* msg is borrowed by *dst (unless the next if decides to color it) */ 761 805 *dst = msg; 762 806 } … … 764 808 /* coloring */ 765 809 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 810 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); 811 char *color = (trust && *trust) ? OTR_COLOR_TRUSTED : OTR_COLOR_UNTRUSTED; 812 gboolean is_query = (irc_user_msgdest(iu) == irc->user->nick); 813 814 /* the return value of otr_color_encrypted() is borrowed by *dst */ 815 *dst = otr_color_encrypted(msg, color, is_query); 816 817 /* this branch doesn't need msg */ 818 g_free(msg); 792 819 } 793 820 } else {
Note: See TracChangeset
for help on using the changeset viewer.