protocols/ircv3/purpleircv3ctcphandlers.c

Thu, 24 Apr 2025 22:19:39 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 24 Apr 2025 22:19:39 -0500
changeset 43242
a9bc19e23c36
parent 42947
741fc66f01b8
permissions
-rw-r--r--

IRCv3: check if a member is in a conversation before adding them

Awhile ago we update the NAMREPLY handler to build a separate
Purple.ConversationMembers and then splice that onto the existing one to help
with sorting and other performance issues. However, we didn't check if the
users already existed in the existing list, so we would get duplicates. This
address that.

Also fixed a reference leak.

Testing Done:
Joined a channel and sent `/quote names #channel` multiple times and verified that the member list did not grow to include a bunch of duplicates.

Reviewed at https://reviews.imfreedom.org/r/3987/

42937
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This library is free software; you can redistribute it and/or modify
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This library is distributed in the hope that it will be useful,
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this library; if not, see <https://www.gnu.org/licenses/>.
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purpleircv3ctcphandlers.h"
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 /******************************************************************************
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 * Handlers
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 *****************************************************************************/
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 static void
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 purple_ircv3_ctcp_handle_version(G_GNUC_UNUSED PurpleIRCv3Connection *connection,
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 IbisClient *client, IbisMessage *message,
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 G_GNUC_UNUSED IbisCTCPMessage *ctcp_message)
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 {
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 PurpleUi *ui = NULL;
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 IbisMessage *response = NULL;
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 IbisCTCPMessage *ctcp_response = NULL;
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 char *nick = NULL;
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 const char *id = NULL;
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 const char *source = NULL;
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 source = ibis_message_get_source(message);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 ibis_source_parse(source, &nick, NULL, NULL);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 ui = purple_core_get_ui();
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 id = purple_ui_get_id(ui);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 ctcp_response = ibis_ctcp_message_new(IBIS_CTCP_VERSION);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 ibis_ctcp_message_set_params(ctcp_response, id, NULL);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 response = ibis_message_new(IBIS_MSG_NOTICE);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 ibis_message_set_params(response, nick, NULL);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 g_free(nick);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 ibis_message_set_ctcp_message(response, ctcp_response);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 g_clear_object(&ctcp_response);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 ibis_client_write(client, response);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 }
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
42947
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
59 static void
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
60 purple_ircv3_ctcp_handle_ping(G_GNUC_UNUSED PurpleIRCv3Connection *connection,
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
61 IbisClient *client, IbisMessage *message,
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
62 IbisCTCPMessage *ctcp_message)
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
63 {
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
64 IbisMessage *response = NULL;
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
65 IbisCTCPMessage *ctcp_response = NULL;
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
66 GStrv params = NULL;
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
67 char *nick = NULL;
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
68 const char *source = NULL;
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
69
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
70 ctcp_response = ibis_ctcp_message_new(IBIS_CTCP_PING);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
71 params = ibis_ctcp_message_get_params(ctcp_message);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
72 if(params != NULL) {
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
73 ibis_ctcp_message_set_paramsv(ctcp_response, params);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
74 }
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
75
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
76 response = ibis_message_new(IBIS_MSG_NOTICE);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
77
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
78 source = ibis_message_get_source(message);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
79 ibis_source_parse(source, &nick, NULL, NULL);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
80 ibis_message_set_params(response, nick, NULL);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
81 g_free(nick);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
82
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
83 ibis_message_set_ctcp_message(response, ctcp_response);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
84 g_clear_object(&ctcp_response);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
85
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
86 ibis_client_write(client, response);
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
87 }
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
88
42937
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 /******************************************************************************
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 * Internal API
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 *****************************************************************************/
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 void
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 purple_ircv3_ctcp_handler(PurpleIRCv3Connection *connection,
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 IbisClient *client, IbisMessage *message)
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 {
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 IbisCTCPMessage *ctcp_message = NULL;
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 const char *command = NULL;
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 ctcp_message = ibis_message_get_ctcp_message(message);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 command = ibis_ctcp_message_get_command(ctcp_message);
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 if(purple_strequal(command, IBIS_CTCP_VERSION)) {
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 purple_ircv3_ctcp_handle_version(connection, client, message,
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 ctcp_message);
42947
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
105 } else if(purple_strequal(command, IBIS_CTCP_PING)) {
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
106 purple_ircv3_ctcp_handle_ping(connection, client, message,
741fc66f01b8 IRCv3: Respond to CTCP PING
Gary Kramlich <grim@reaperworld.com>
parents: 42937
diff changeset
107 ctcp_message);
42937
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 }
34ac8ac8c7b6 Implement CTCP VERSION response
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 }

mercurial