libpurple/protocols/ircv3/purpleircv3messagehandlers.c

Tue, 14 Nov 2023 00:26:54 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 14 Nov 2023 00:26:54 -0600
changeset 42494
4d6baa511e52
parent 42382
343e30628383
child 42503
55eff782a478
permissions
-rw-r--r--

IRCv3: create some helper functions for finding/creating conversations

This is necessary so we can start properly handling other channel messages as
we could miss a join message from a bouncer but then get join, part, etc.

Testing Done:
Received a dm and verified the conversation was created properly.

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

41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * (at your option) any later version.
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * GNU General Public License for more details.
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
19 #include <glib/gi18n-lib.h>
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
20
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include "purpleircv3messagehandlers.h"
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purpleircv3connection.h"
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41796
diff changeset
24 #include "purpleircv3core.h"
42345
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
25 #include "purpleircv3source.h"
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41796
diff changeset
27 /******************************************************************************
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41796
diff changeset
28 * Fallback
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41796
diff changeset
29 *****************************************************************************/
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 gboolean
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
31 purple_ircv3_message_handler_fallback(PurpleIRCv3Message *message,
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: 41916
diff changeset
32 G_GNUC_UNUSED GError **error,
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
33 gpointer data)
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 {
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
35 PurpleIRCv3Connection *connection = data;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
36 char *new_command = NULL;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
37 const char *command = NULL;
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
38
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
39 command = purple_ircv3_message_get_command(message);
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
40
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
41 new_command = g_strdup_printf(_("unknown command '%s'"), command);
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
42 purple_ircv3_message_set_command(message, new_command);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
43 purple_ircv3_connection_add_status_message(connection, message);
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
44
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
45 g_clear_pointer(&new_command, g_free);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
46
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
47 return TRUE;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
48 }
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
50 /******************************************************************************
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
51 * Status Messages
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
52 *****************************************************************************/
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
53 gboolean
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
54 purple_ircv3_message_handler_status(PurpleIRCv3Message *message,
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
55 G_GNUC_UNUSED GError **error,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
56 gpointer data)
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
57 {
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
58 purple_ircv3_connection_add_status_message(data, message);
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
59
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
60 return TRUE;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
61 }
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
63 gboolean
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
64 purple_ircv3_message_handler_status_ignore_param0(PurpleIRCv3Message *message,
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
65 GError **error,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
66 gpointer data)
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
67 {
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
68 GStrv params = NULL;
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
69 GStrv new_params = NULL;
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
70 guint n_params = 0;
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
71
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
72 params = purple_ircv3_message_get_params(message);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
73 if(params != NULL) {
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
74 n_params = g_strv_length(params);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
75 }
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
76
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
77 if(n_params <= 1) {
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
78 g_set_error(error, PURPLE_IRCV3_DOMAIN, 0,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
79 "expected n_params > 1, got %u", n_params);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
80
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
81 return FALSE;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
82 }
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42179
diff changeset
83
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
84 /* We need to make a copy because otherwise we'd get a use after free in
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
85 * set_params.
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
86 */
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
87 new_params = g_strdupv(params + 1);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
88 purple_ircv3_message_set_params(message, new_params);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
89 g_clear_pointer(&new_params, g_strfreev);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
90
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
91 purple_ircv3_connection_add_status_message(data, message);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 return TRUE;
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 }
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41796
diff changeset
96 /******************************************************************************
41821
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
97 * General Commands
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
98 *****************************************************************************/
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
99 gboolean
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
100 purple_ircv3_message_handler_ping(PurpleIRCv3Message *message,
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: 41916
diff changeset
101 G_GNUC_UNUSED GError **error,
41821
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
102 gpointer data)
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
103 {
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
104 PurpleIRCv3Connection *connection = data;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
105 GStrv params = NULL;
41821
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
106
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
107 params = purple_ircv3_message_get_params(message);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
108
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
109 if(params != NULL && g_strv_length(params) == 1) {
41821
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
110 purple_ircv3_connection_writef(connection, "PONG %s", params[0]);
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
111 } else {
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
112 purple_ircv3_connection_writef(connection, "PONG");
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
113 }
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
114
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
115 return TRUE;
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
116 }
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41815
diff changeset
117
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
118 gboolean
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
119 purple_ircv3_message_handler_privmsg(PurpleIRCv3Message *v3_message,
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
120 G_GNUC_UNUSED GError **error,
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
121 gpointer data)
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
122 {
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
123 PurpleIRCv3Connection *connection = data;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
124 PurpleAccount *account = NULL;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
125 PurpleContact *contact = NULL;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
126 PurpleContactManager *contact_manager = NULL;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
127 PurpleConversation *conversation = NULL;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
128 PurpleMessage *message = NULL;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
129 PurpleMessageFlags flags = PURPLE_MESSAGE_RECV;
42056
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
130 GDateTime *dt = NULL;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
131 GHashTable *tags = NULL;
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
132 GStrv params = NULL;
42056
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
133 gpointer raw_id = NULL;
42294
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
134 gpointer raw_timestamp = NULL;
42345
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
135 char *nick = NULL;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
136 const char *command = NULL;
42056
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
137 const char *id = NULL;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
138 const char *source = NULL;
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
139 const char *target = NULL;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
140
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
141 command = purple_ircv3_message_get_command(v3_message);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
142 params = purple_ircv3_message_get_params(v3_message);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
143 source = purple_ircv3_message_get_source(v3_message);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
144 tags = purple_ircv3_message_get_tags(v3_message);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42320
diff changeset
145
42382
343e30628383 IRCv3: Fix an issue scanbuild found
Gary Kramlich <grim@reaperworld.com>
parents: 42378
diff changeset
146 if(params == NULL) {
343e30628383 IRCv3: Fix an issue scanbuild found
Gary Kramlich <grim@reaperworld.com>
parents: 42378
diff changeset
147 g_warning("privmsg received with no parameters");
343e30628383 IRCv3: Fix an issue scanbuild found
Gary Kramlich <grim@reaperworld.com>
parents: 42378
diff changeset
148
343e30628383 IRCv3: Fix an issue scanbuild found
Gary Kramlich <grim@reaperworld.com>
parents: 42378
diff changeset
149 return FALSE;
343e30628383 IRCv3: Fix an issue scanbuild found
Gary Kramlich <grim@reaperworld.com>
parents: 42378
diff changeset
150 }
343e30628383 IRCv3: Fix an issue scanbuild found
Gary Kramlich <grim@reaperworld.com>
parents: 42378
diff changeset
151
343e30628383 IRCv3: Fix an issue scanbuild found
Gary Kramlich <grim@reaperworld.com>
parents: 42378
diff changeset
152 if(g_strv_length(params) != 2) {
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
153 char *body = g_strjoinv(" ", params);
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
154 g_warning("unknown privmsg message format: '%s'", body);
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
155 g_free(body);
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
156
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
157 return FALSE;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
158 }
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
159
42345
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
160 purple_ircv3_source_parse(source, &nick, NULL, NULL);
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
161
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41842
diff changeset
162 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
163
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
164 contact_manager = purple_contact_manager_get_default();
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
165 contact = purple_contact_manager_find_with_username(contact_manager,
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
166 account,
42345
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
167 nick);
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
168 if(!PURPLE_IS_CONTACT(contact)) {
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
169 contact = purple_contact_new(account, NULL);
42345
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
170 purple_contact_info_set_username(PURPLE_CONTACT_INFO(contact), nick);
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
171 purple_contact_info_set_sid(PURPLE_CONTACT_INFO(contact), source);
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
172 purple_contact_manager_add(contact_manager, contact);
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
173 }
42179
b8bb444799a4 Fix leaks from g_list_model_get_item
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42056
diff changeset
174 g_clear_object(&contact);
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
175
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
176 target = params[0];
42494
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42382
diff changeset
177 if(!purple_ircv3_connection_is_channel(connection, target)) {
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42382
diff changeset
178 target = nick;
42345
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
179 }
42494
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42382
diff changeset
180 conversation = purple_ircv3_connection_find_or_create_conversation(connection,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42382
diff changeset
181 target);
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
182
42056
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
183 /* Grab the msgid if one was provided. */
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
184 if(g_hash_table_lookup_extended(tags, "msgid", NULL, &raw_id)) {
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
185 if(!purple_strempty(raw_id)) {
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
186 id = raw_id;
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
187 }
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
188 }
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
189
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
190 if(purple_strequal(command, "NOTICE")) {
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
191 flags |= PURPLE_MESSAGE_NOTIFY;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
192 }
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
193
42294
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
194 /* Determine the timestamp of the message. */
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
195 if(g_hash_table_lookup_extended(tags, "time", NULL, &raw_timestamp)) {
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
196 const char *timestamp = raw_timestamp;
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
197
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
198 if(!purple_strempty(timestamp)) {
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
199 GTimeZone *tz = g_time_zone_new_utc();
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
200
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
201 dt = g_date_time_new_from_iso8601(timestamp, tz);
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
202
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
203 g_time_zone_unref(tz);
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
204 }
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
205 }
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
206
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
207 /* If the server didn't provide a time, use the current local time. */
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
208 if(dt == NULL) {
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
209 dt = g_date_time_new_now_local();
462317d1382d IRCv3: add support for the server-time capability
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
210 }
42056
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
211
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
212 message = g_object_new(
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
213 PURPLE_TYPE_MESSAGE,
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
214 "author", source,
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
215 "contents", params[1],
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
216 "flags", flags,
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
217 "id", id,
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
218 "timestamp", dt,
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
219 NULL);
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
220
ced07483f66a IRCv3: Add support for the msgid specification
Gary Kramlich <grim@reaperworld.com>
parents: 42048
diff changeset
221 g_date_time_unref(dt);
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
222
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
223 purple_conversation_write_message(conversation, message);
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
224
42345
e01084003f50 IRCv3: Finally fix sending messages between two users
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
225 g_clear_pointer(&nick, g_free);
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
226 g_clear_object(&message);
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
227
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
228 return TRUE;
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
229 }

mercurial