libpurple/protocols/ircv3/purpleircv3core.c

Thu, 30 Nov 2023 22:38:54 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 30 Nov 2023 22:38:54 -0600
changeset 42530
55b30ce86f17
parent 42229
605f8cba9704
child 42568
31e8c7c92e2f
permissions
-rw-r--r--

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/

41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * (at your option) any later version.
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * GNU General Public License for more details.
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib.h>
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 #include <glib/gi18n-lib.h>
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 #include <gplugin.h>
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <gplugin-native.h>
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include <purple.h>
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents: 41750
diff changeset
27 #include "purpleircv3core.h"
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents: 41750
diff changeset
28
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
29 #include "purpleircv3capabilities.h"
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
30 #include "purpleircv3connection.h"
41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 #include "purpleircv3protocol.h"
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 /******************************************************************************
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 * Globals
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 *****************************************************************************/
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 static PurpleProtocol *ircv3_protocol = NULL;
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 /******************************************************************************
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 * GPlugin Exports
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 *****************************************************************************/
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 static GPluginPluginInfo *
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 purple_ircv3_query(G_GNUC_UNUSED GError **error) {
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 PurplePluginInfoFlags flags = PURPLE_PLUGIN_INFO_FLAGS_INTERNAL |
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD;
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 const gchar * const authors[] = {
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 "Pidgin Developers <devel@pidgin.im>",
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 NULL
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 };
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 return purple_plugin_info_new(
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 "id", "prpl-ircv3",
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 "name", "IRCv3 Protocol",
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 "authors", authors,
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 "version", DISPLAY_VERSION,
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 "category", N_("Protocol"),
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 "summary", N_("IRCv3 Protocol Plugin"),
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 "description", N_("Modern IRC Support"),
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 "website", PURPLE_WEBSITE,
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 "abi-version", PURPLE_ABI_VERSION,
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 "flags", flags,
42229
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
61 "bind-global", TRUE,
41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 NULL);
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 }
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 static gboolean
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 purple_ircv3_load(GPluginPlugin *plugin, GError **error) {
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 PurpleProtocolManager *manager = NULL;
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 if(PURPLE_IS_PROTOCOL(ircv3_protocol)) {
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0,
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 "plugin was not cleaned up properly");
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 return FALSE;
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 }
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
76 purple_ircv3_capabilities_register(GPLUGIN_NATIVE_PLUGIN(plugin));
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
77 purple_ircv3_connection_register(GPLUGIN_NATIVE_PLUGIN(plugin));
41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 purple_ircv3_protocol_register(GPLUGIN_NATIVE_PLUGIN(plugin));
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79
42229
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
80 ircv3_protocol = purple_ircv3_protocol_new();
41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81
42229
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
82 manager = purple_protocol_manager_get_default();
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
83 /* Manager can be NULL when we're generating the GIR stuff. */
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
84 if(PURPLE_IS_PROTOCOL_MANAGER(manager)) {
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
85 if(!purple_protocol_manager_register(manager, ircv3_protocol, error)) {
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
86 g_clear_object(&ircv3_protocol);
41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87
42229
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
88 return FALSE;
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
89 }
41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 }
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 return TRUE;
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 }
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 static gboolean
41941
355bd17297f0 Set the C standard to C99 and set warning_level to 2 for the IRCv3 Protocol Plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
96 purple_ircv3_unload(G_GNUC_UNUSED GPluginPlugin *plugin,
355bd17297f0 Set the C standard to C99 and set warning_level to 2 for the IRCv3 Protocol Plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
97 G_GNUC_UNUSED gboolean shutdown,
355bd17297f0 Set the C standard to C99 and set warning_level to 2 for the IRCv3 Protocol Plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
98 GError **error)
355bd17297f0 Set the C standard to C99 and set warning_level to 2 for the IRCv3 Protocol Plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
99 {
41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 PurpleProtocolManager *manager = NULL;
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 if(!PURPLE_IS_PROTOCOL(ircv3_protocol)) {
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0,
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 "plugin was not setup properly");
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 return FALSE;
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 }
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 manager = purple_protocol_manager_get_default();
42229
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
110 /* Manager can be NULL when we're generating the GIR stuff. */
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
111 if(PURPLE_IS_PROTOCOL_MANAGER(manager)) {
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
112 if(!purple_protocol_manager_unregister(manager, ircv3_protocol,
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
113 error))
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
114 {
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
115 return FALSE;
605f8cba9704 Add gobject-introspection for ircv3
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
116 }
41750
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 }
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 g_clear_object(&ircv3_protocol);
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 return TRUE;
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 }
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
7ab7d79ac0c5 Create a skeleton for the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 GPLUGIN_NATIVE_PLUGIN_DECLARE(purple_ircv3)

mercurial