Thu, 30 Nov 2023 22:38:54 -0600
IRCv3: Implement basic CTCP support
This is just the scaffolding for it and doesn't implement any actual commands.
Testing Done:
Sent some `CTCP VERSION`'s to an IRCv3 account. Also manually sent `CTCP VERSION`'s to users and channel via temporary code in when the connection was fully established.
Reviewed at https://reviews.imfreedom.org/r/2854/
|
42505
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 | /* |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 | * Purple - Internet Messaging Library |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 | * |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * This program is free software; you can redistribute it and/or modify |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation; either version 2 of the License, or |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 | * |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | */ |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | #include "purpleircv3formatting.h" |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 | #define IRCV3_FORMAT_BOLD (0x02) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | #define IRCV3_FORMAT_COLOR (0x03) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 | #define IRCV3_FORMAT_HEX_COLOR (0x04) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | #define IRCV3_FORMAT_ITALIC (0x1d) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | #define IRCV3_FORMAT_MONOSPACE (0x11) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | #define IRCV3_FORMAT_RESET (0x0f) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | #define IRCV3_FORMAT_REVERSE (0x16) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | #define IRCV3_FORMAT_STRIKETHROUGH (0x1e) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | #define IRCV3_FORMAT_UNDERLINE (0x1f) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | /****************************************************************************** |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 | * Helpers |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 | *****************************************************************************/ |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 | static inline gboolean |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
35 | purple_ircv3_formatting_is_hex_color(const char *text) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 | for(int i = 0; i < 6; i++) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | if(text[i] == '\0') { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | return FALSE; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 | if(!g_ascii_isxdigit(text[i])) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 | return FALSE; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 | return TRUE; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | /****************************************************************************** |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | * Public API |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | *****************************************************************************/ |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 | char * |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | purple_ircv3_formatting_strip(const char *text) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | GString *str = NULL; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | /* We don't use purple_strempty here because if we're passed an empty |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 | * string, we should return a newly allocated empty string. |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | */ |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | if(text == NULL) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 | return NULL; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | str = g_string_new(""); |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | for(int i = 0; text[i] != '\0'; i++) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | switch(text[i]) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | case IRCV3_FORMAT_BOLD: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | case IRCV3_FORMAT_ITALIC: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 | case IRCV3_FORMAT_MONOSPACE: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 | case IRCV3_FORMAT_RESET: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 | case IRCV3_FORMAT_REVERSE: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | case IRCV3_FORMAT_STRIKETHROUGH: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | case IRCV3_FORMAT_UNDERLINE: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 | continue; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 | break; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | case IRCV3_FORMAT_COLOR: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | if(g_ascii_isdigit(text[i + 1])) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | i += 1; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | if(g_ascii_isdigit(text[i + 1])) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 | i += 1; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 | if(text[i + 1] == ',' && g_ascii_isdigit(text[i + 2])) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 | i += 2; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 | if(g_ascii_isdigit(text[i + 1])) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 | i += 1; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | break; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | case IRCV3_FORMAT_HEX_COLOR: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 | if(purple_ircv3_formatting_is_hex_color(&text[i + 1])) { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | i += 6; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 | if(text[i + 1] == ',' && |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 | purple_ircv3_formatting_is_hex_color(&text[i + 2])) |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 | { |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | i += 7; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 | break; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 | default: |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 | g_string_append_c(str, text[i]); |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 | break; |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
110 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
111 | } |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 | |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 | return g_string_free(str, FALSE); |
|
cc095f9ce1f3
IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 | } |