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/
|
42530
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 | /* |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 | * Purple - Internet Messaging Library |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 | * |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * This program is free software; you can redistribute it and/or modify |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation; either version 2 of the License, or |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 | * |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | */ |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | #include <glib/gi18n-lib.h> |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 | #include "purpleircv3ctcp.h" |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 | #include "purpleircv3constants.h" |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | /****************************************************************************** |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | * Internal API |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | *****************************************************************************/ |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | void |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | purple_ircv3_ctcp_handle(PurpleIRCv3Connection *connection, |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | PurpleMessage *message) |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 | const char *contents = NULL; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 | g_return_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection)); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
35 | g_return_if_fail(PURPLE_IS_MESSAGE(message)); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | contents = purple_message_get_contents(message); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | if(contents != NULL && contents[0] == PURPLE_IRCV3_CTCP_DELIMITER) { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | PurpleMessageFlags flags; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | char *command = NULL; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 | char *contents = NULL; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 | char *params = NULL; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | char *ptr = NULL; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 | /* Move past the delimiter. */ |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 | contents += 1; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | /* Find the delimiter for the command. */ |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | ptr = g_strstr_len(contents, -1, " "); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | /* If we don't have a space, then we have no parameters. */ |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 | if(ptr == NULL) { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | size_t len = strlen(contents); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | command = g_strdup(contents); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | if(command[len - 1] == PURPLE_IRCV3_CTCP_DELIMITER) { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 | command[len - 1] = '\0'; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | } |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | } else { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 | size_t len = 0; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | command = g_strndup(contents, ptr - contents); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | params = g_strdup(ptr + 1); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | len = strlen(params); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 | if(params[len - 1] == PURPLE_IRCV3_CTCP_DELIMITER) { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | params[len - 1] = '\0'; |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | } |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 | } |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 | flags = purple_message_get_flags(message); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | if(flags & PURPLE_MESSAGE_NOTIFY) { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | if(!purple_strempty(params)) { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 | contents = g_strdup_printf(_("CTCP %s response: %s"), command, |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 | params); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | } else { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | contents = g_strdup_printf(_("CTCP %s response was empty"), |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | command); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 | } |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 | purple_ircv3_connection_emit_ctcp_response(connection, command, |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | params); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 | } else { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 | if(!purple_strempty(params)) { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 | contents = g_strdup_printf(_("requested CTCP %s: %s"), command, |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 | params); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 | } else { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 | contents = g_strdup_printf(_("requested CTCP %s"), command); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 | } |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | purple_ircv3_connection_emit_ctcp_request(connection, command, |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | params); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | } |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 | if(!purple_strempty(contents)) { |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | purple_message_set_contents(message, contents); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | } |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 | g_clear_pointer(&contents, g_free); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 | g_clear_pointer(&command, g_free); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 | g_clear_pointer(¶ms, g_free); |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | } |
|
55b30ce86f17
IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | } |