protocols/ircv3/purpleircv3connection.c

Mon, 25 Mar 2024 21:43:28 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 25 Mar 2024 21:43:28 -0500
changeset 42652
225762d4e206
parent 42619
libpurple/protocols/ircv3/purpleircv3connection.c@3dd7cd0eabf1
child 42653
584895b844d2
permissions
-rw-r--r--

Move the Demo and IRCv3 protocols to the new protocols directory

Testing Done:
Ran `meson dist` and `ninja turtles`

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

41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
42568
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42547
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42547
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42547
diff changeset
7 * source distribution.
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42547
diff changeset
8 *
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42547
diff changeset
9 * This library is free software; you can redistribute it and/or modify
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
42568
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42547
diff changeset
14 * This library is distributed in the hope that it will be useful,
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
42568
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42547
diff changeset
20 * along with this library; if not, see <https://www.gnu.org/licenses/>.
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <glib/gi18n-lib.h>
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
42547
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
25 #include <birb.h>
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
26
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #include "purpleircv3connection.h"
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
29 #include "purpleircv3constants.h"
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 #include "purpleircv3core.h"
42544
95d36c221e21 Implement CTCP ACTION and VERSION
Gary Kramlich <grim@reaperworld.com>
parents: 42543
diff changeset
31 #include "purpleircv3ctcp.h"
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
32 #include "purpleircv3formatting.h"
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
33 #include "purpleircv3parser.h"
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 enum {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 PROP_0,
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
37 PROP_CAPABILITIES,
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
38 PROP_REGISTERED,
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 N_PROPERTIES,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 };
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
43 enum {
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
44 SIG_REGISTRATION_COMPLETE,
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
45 SIG_CTCP_REQUEST,
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
46 SIG_CTCP_RESPONSE,
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
47 N_SIGNALS,
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
48 };
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
49 static guint signals[N_SIGNALS] = {0, };
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
50
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
51 typedef struct {
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 GSocketConnection *connection;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 gchar *server_name;
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
55 gboolean registered;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 GDataInputStream *input;
42547
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
58 GOutputStream *output;
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
59
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
60 PurpleIRCv3Parser *parser;
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
61
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
62 PurpleIRCv3Capabilities *capabilities;
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
63
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
64 PurpleConversation *status_conversation;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
65 } PurpleIRCv3ConnectionPrivate;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
67 G_DEFINE_DYNAMIC_TYPE_EXTENDED(PurpleIRCv3Connection,
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
68 purple_ircv3_connection,
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
69 PURPLE_TYPE_CONNECTION,
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
70 0,
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
71 G_ADD_PRIVATE_DYNAMIC(PurpleIRCv3Connection))
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 /******************************************************************************
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 * Helpers
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 static void
41955
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
77 purple_ircv3_connection_send_pass_command(PurpleIRCv3Connection *connection) {
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
78 PurpleAccount *account = NULL;
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
79 const char *password = NULL;
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
80
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
81 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
82
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
83 password = purple_account_get_string(account, "server-password", "");
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
84 if(password != NULL && *password != '\0') {
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
85 purple_ircv3_connection_writef(connection, "PASS %s", password);
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
86 }
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
87 }
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
88
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
89 static void
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
90 purple_ircv3_connection_send_user_command(PurpleIRCv3Connection *connection) {
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
91 PurpleAccount *account = NULL;
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
92 const char *identname = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
93 const char *nickname = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
94 const char *realname = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
95
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
96 nickname =
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
97 purple_connection_get_display_name(PURPLE_CONNECTION(connection));
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
98
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
99 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
100
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
101 /* The stored value could be an empty string, so pass a default of empty
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
102 * string and then if it was empty, set our correct fallback.
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
103 */
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
104 identname = purple_account_get_string(account, "ident", "");
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
105 if(identname == NULL || *identname == '\0') {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
106 identname = nickname;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
107 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
108
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
109 realname = purple_account_get_string(account, "real-name", "");
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
110 if(realname == NULL || *realname == '\0') {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
111 realname = nickname;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
112 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
113
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
114 purple_ircv3_connection_writef(connection, "USER %s 0 * :%s", identname,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
115 realname);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
116 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
117
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
118 static void
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
119 purple_ircv3_connection_send_nick_command(PurpleIRCv3Connection *connection) {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
120 const char *nickname = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
121
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
122 nickname =
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
123 purple_connection_get_display_name(PURPLE_CONNECTION(connection));
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
124
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
125 purple_ircv3_connection_writef(connection, "NICK %s", nickname);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
126 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
127
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
128 static void
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
129 purple_ircv3_connection_rejoin_channels(PurpleIRCv3Connection *connection) {
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
130 PurpleAccount *account = NULL;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
131 PurpleConversationManager *manager = NULL;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
132 GList *conversations = NULL;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
133
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
134 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
135 manager = purple_conversation_manager_get_default();
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
136
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
137 conversations = purple_conversation_manager_get_all(manager);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
138 while(conversations != NULL) {
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
139 PurpleConversation *conversation = conversations->data;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
140 PurpleAccount *conv_account = NULL;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
141
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
142 conv_account = purple_conversation_get_account(conversation);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
143 if(conv_account == account) {
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
144 const char *id = purple_conversation_get_id(conversation);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
145
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
146 purple_ircv3_connection_writef(connection, "%s %s",
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
147 PURPLE_IRCV3_MSG_JOIN, id);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
148 }
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
149
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
150 conversations = g_list_delete_link(conversations, conversations);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
151 }
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
152 }
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
153
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 /******************************************************************************
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 * Callbacks
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 purple_ircv3_connection_read_cb(GObject *source, GAsyncResult *result,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 gpointer data)
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 {
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
161 PurpleIRCv3Connection *connection = data;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
162 PurpleIRCv3ConnectionPrivate *priv = NULL;
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
163 GCancellable *cancellable = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 GDataInputStream *istream = G_DATA_INPUT_STREAM(source);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 GError *error = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 gchar *line = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 gsize length;
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
168 gboolean parsed = FALSE;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 line = g_data_input_stream_read_line_finish(istream, result, &length,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 &error);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 if(line == NULL || error != NULL) {
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
173 if(PURPLE_IS_CONNECTION(connection)) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
174 if(error == NULL) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
175 g_set_error_literal(&error, PURPLE_CONNECTION_ERROR,
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
176 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
177 _("Server closed the connection"));
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
178 } else {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
179 g_prefix_error(&error, "%s", _("Lost connection with server: "));
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
180 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
181
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
182 purple_connection_take_error(PURPLE_CONNECTION(connection), error);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 /* In the off chance that line was returned, make sure we free it. */
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 g_free(line);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 return;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
191 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
192
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
193 parsed = purple_ircv3_parser_parse(priv->parser, line, &error,
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
194 connection);
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
195 if(!parsed) {
42023
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 42013
diff changeset
196 g_warning("failed to handle '%s': %s", line,
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
197 error != NULL ? error->message : "unknown error");
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
198 }
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
199 g_clear_error(&error);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 g_free(line);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
202
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
203 /* Call read_line_async again to continue reading lines. */
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
204 cancellable = purple_connection_get_cancellable(PURPLE_CONNECTION(connection));
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
205 g_data_input_stream_read_line_async(priv->input,
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
206 G_PRIORITY_DEFAULT,
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
207 cancellable,
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
208 purple_ircv3_connection_read_cb,
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
209 connection);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 static void
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
213 purple_ircv3_connection_write_cb(GObject *source, GAsyncResult *result,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
214 gpointer data)
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
215 {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
216 PurpleIRCv3Connection *connection = data;
42547
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
217 BirbQueuedOutputStream *stream = BIRB_QUEUED_OUTPUT_STREAM(source);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
218 GError *error = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
219 gboolean success = FALSE;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
220
42547
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
221 success = birb_queued_output_stream_push_bytes_finish(stream, result,
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
222 &error);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
223
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
224 if(!success) {
42547
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
225 birb_queued_output_stream_clear_queue(stream);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
226
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
227 g_prefix_error(&error, "%s", _("Lost connection with server: "));
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
228
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
229 purple_connection_take_error(PURPLE_CONNECTION(connection), error);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
230
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
231 return;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
232 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
233 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
234
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
235 static void
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 purple_ircv3_connection_connected_cb(GObject *source, GAsyncResult *result,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 gpointer data)
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 {
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
239 PurpleIRCv3Connection *connection = data;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
240 PurpleIRCv3ConnectionPrivate *priv = NULL;
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
241 GCancellable *cancellable = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 GError *error = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243 GInputStream *istream = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244 GOutputStream *ostream = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 GSocketClient *client = G_SOCKET_CLIENT(source);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 GSocketConnection *conn = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
248 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
249
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 /* Finish the async method. */
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 conn = g_socket_client_connect_to_host_finish(client, result, &error);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 if(conn == NULL || error != NULL) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 g_prefix_error(&error, "%s", _("Unable to connect: "));
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
255 purple_connection_take_error(PURPLE_CONNECTION(connection), error);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 return;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
260 g_message("Successfully connected to %s", priv->server_name);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 /* Save our connection and setup our input and outputs. */
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
263 priv->connection = conn;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
265 /* Create our parser. */
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
266 priv->parser = purple_ircv3_parser_new();
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
267 purple_ircv3_parser_add_default_handlers(priv->parser);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
268
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269 ostream = g_io_stream_get_output_stream(G_IO_STREAM(conn));
42547
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
270 priv->output = birb_queued_output_stream_new(ostream);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 istream = g_io_stream_get_input_stream(G_IO_STREAM(conn));
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
273 priv->input = g_data_input_stream_new(istream);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
274 g_data_input_stream_set_newline_type(G_DATA_INPUT_STREAM(priv->input),
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
275 G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
277 cancellable = purple_connection_get_cancellable(PURPLE_CONNECTION(connection));
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
278
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 /* Add our read callback. */
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
280 g_data_input_stream_read_line_async(priv->input,
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281 G_PRIORITY_DEFAULT,
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
282 cancellable,
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 purple_ircv3_connection_read_cb,
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
284 connection);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
286 /* Send our registration commands. */
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
287 purple_ircv3_capabilities_start(priv->capabilities);
41955
d3117aac63b3 Add support for server passwords to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41954
diff changeset
288 purple_ircv3_connection_send_pass_command(connection);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
289 purple_ircv3_connection_send_user_command(connection);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
290 purple_ircv3_connection_send_nick_command(connection);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
293 static void
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
294 purple_ircv3_connection_caps_done_cb(G_GNUC_UNUSED PurpleIRCv3Capabilities *caps,
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
295 gpointer data)
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
296 {
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
297 PurpleIRCv3Connection *connection = data;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
298 PurpleIRCv3ConnectionPrivate *priv = NULL;
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
299
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
300 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
301
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
302 priv->registered = TRUE;
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
303
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
304 g_signal_emit(connection, signals[SIG_REGISTRATION_COMPLETE], 0);
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
305
42544
95d36c221e21 Implement CTCP ACTION and VERSION
Gary Kramlich <grim@reaperworld.com>
parents: 42543
diff changeset
306 /* Add our supported CTCP commands. */
95d36c221e21 Implement CTCP ACTION and VERSION
Gary Kramlich <grim@reaperworld.com>
parents: 42543
diff changeset
307 purple_ircv3_ctcp_add_default_handlers(connection);
95d36c221e21 Implement CTCP ACTION and VERSION
Gary Kramlich <grim@reaperworld.com>
parents: 42543
diff changeset
308
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
309 /* Now that registration is complete, rejoin any channels that the
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
310 * conversation manager has for us.
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
311 */
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
312 purple_ircv3_connection_rejoin_channels(connection);
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
313 }
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
314
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 /******************************************************************************
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
316 * PurpleConnection Implementation
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
317 *****************************************************************************/
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
318 static gboolean
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
319 purple_ircv3_connection_connect(PurpleConnection *purple_connection,
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
320 GError **error)
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
321 {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
322 PurpleIRCv3Connection *connection = NULL;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
323 PurpleIRCv3ConnectionPrivate *priv = NULL;
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
324 PurpleAccount *account = NULL;
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
325 GCancellable *cancellable = NULL;
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
326 GSocketClient *client = NULL;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
327 gint default_port = PURPLE_IRCV3_DEFAULT_TLS_PORT;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
328 gint port = 0;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
329 gboolean use_tls = TRUE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
330
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
331 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(purple_connection), FALSE);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
332
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
333 connection = PURPLE_IRCV3_CONNECTION(purple_connection);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
334 priv = purple_ircv3_connection_get_instance_private(connection);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
335 account = purple_connection_get_account(purple_connection);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
336
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
337 client = purple_gio_socket_client_new(account, error);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
338 if(!G_IS_SOCKET_CLIENT(client)) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
339 if(error != NULL && *error != NULL) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
340 purple_connection_take_error(purple_connection, *error);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
341 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
342
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
343 return FALSE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
344 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
345
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
346 /* Turn on TLS if requested. */
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
347 use_tls = purple_account_get_bool(account, "use-tls", TRUE);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
348 g_socket_client_set_tls(client, use_tls);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
349
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
350 /* If TLS is not being used, set the default port to the plain port. */
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
351 if(!use_tls) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
352 default_port = PURPLE_IRCV3_DEFAULT_PLAIN_PORT;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
353 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
354 port = purple_account_get_int(account, "port", default_port);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
355
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
356 cancellable = purple_connection_get_cancellable(purple_connection);
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
357
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
358 /* Finally start the async connection. */
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
359 g_socket_client_connect_to_host_async(client, priv->server_name,
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
360 port, cancellable,
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
361 purple_ircv3_connection_connected_cb,
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
362 connection);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
363
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
364 g_clear_object(&client);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
365
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
366 return TRUE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
367 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
368
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
369 static gboolean
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
370 purple_ircv3_connection_disconnect(PurpleConnection *purple_connection,
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
371 GError **error)
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
372 {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
373 PurpleIRCv3Connection *connection = NULL;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
374 PurpleIRCv3ConnectionPrivate *priv = NULL;
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
375 PurpleConnectionClass *parent_class = NULL;
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
376
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
377 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(purple_connection), FALSE);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
378
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
379 /* Chain up to our parent's disconnect to do initial clean up. */
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
380 parent_class = PURPLE_CONNECTION_CLASS(purple_ircv3_connection_parent_class);
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
381 parent_class->disconnect(purple_connection, error);
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
382
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
383 connection = PURPLE_IRCV3_CONNECTION(purple_connection);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
384 priv = purple_ircv3_connection_get_instance_private(connection);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
385
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
386 /* TODO: send QUIT command. */
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
387
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
388 if(G_IS_SOCKET_CONNECTION(priv->connection)) {
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
389 GInputStream *istream = G_INPUT_STREAM(priv->input);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
390 GOutputStream *ostream = G_OUTPUT_STREAM(priv->output);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
391
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
392 purple_gio_graceful_close(G_IO_STREAM(priv->connection),
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
393 istream, ostream);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
394 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
395
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
396 g_clear_object(&priv->input);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
397 g_clear_object(&priv->output);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
398 g_clear_object(&priv->connection);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
399
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
400 return TRUE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
401 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
402
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
403 static void
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
404 purple_ircv3_connection_registration_complete_cb(PurpleIRCv3Connection *connection) {
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
405 /* Don't set our connection state to connected until we've completed
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
406 * registration as connected implies that we can start chatting or join
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
407 * rooms and other "online" activities.
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
408 */
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
409 purple_connection_set_state(PURPLE_CONNECTION(connection),
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
410 PURPLE_CONNECTION_STATE_CONNECTED);
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
411 }
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
412
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
413 /******************************************************************************
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
414 * Default Handlers
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
415 *****************************************************************************/
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
416 static gboolean
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
417 purple_ircv3_connection_ctcp_request_default_handler(G_GNUC_UNUSED PurpleIRCv3Connection *connection,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
418 G_GNUC_UNUSED PurpleConversation *conversation,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
419 PurpleMessage *message,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
420 const char *command,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
421 const char *params)
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
422 {
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
423 char *contents = NULL;
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
424
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
425 if(!purple_strempty(params)) {
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
426 contents = g_strdup_printf(_("requested CTCP %s: %s"), command,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
427 params);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
428 } else {
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
429 contents = g_strdup_printf(_("requested CTCP %s"),
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
430 command);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
431 }
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
432
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
433 purple_message_set_contents(message, contents);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
434
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
435 g_clear_pointer(&contents, g_free);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
436
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
437 return FALSE;
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
438 }
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
439
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
440 static gboolean
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
441 purple_ircv3_connection_ctcp_response_default_handler(G_GNUC_UNUSED PurpleIRCv3Connection *connection,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
442 G_GNUC_UNUSED PurpleConversation *conversation,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
443 PurpleMessage *message,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
444 const char *command,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
445 const char *params)
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
446 {
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
447 char *contents = NULL;
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
448
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
449 if(!purple_strempty(params)) {
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
450 contents = g_strdup_printf(_("CTCP %s response: %s"), command,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
451 params);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
452 } else {
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
453 contents = g_strdup_printf(_("CTCP %s response was empty"),
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
454 command);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
455 }
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
456
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
457 purple_message_set_contents(message, contents);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
458
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
459 g_clear_pointer(&contents, g_free);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
460
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
461 return FALSE;
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
462 }
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
463
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
464 /******************************************************************************
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
465 * GObject Implementation
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
466 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
467 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
468 purple_ircv3_connection_get_property(GObject *obj, guint param_id,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
469 GValue *value, GParamSpec *pspec)
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
470 {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
471 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
472
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
473 switch(param_id) {
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
474 case PROP_CAPABILITIES:
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
475 g_value_set_object(value,
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
476 purple_ircv3_connection_get_capabilities(connection));
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
477 break;
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
478 case PROP_REGISTERED:
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
479 g_value_set_boolean(value,
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
480 purple_ircv3_connection_get_registered(connection));
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
481 break;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
482 default:
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
483 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
484 break;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
485 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
486 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
487
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
488 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
489 purple_ircv3_connection_dispose(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
490 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
491 PurpleIRCv3ConnectionPrivate *priv = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
492
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
493 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
494
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
495 g_clear_object(&priv->input);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
496 g_clear_object(&priv->output);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
497 g_clear_object(&priv->connection);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
498
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
499 g_clear_object(&priv->capabilities);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
500 g_clear_object(&priv->parser);
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
501 g_clear_object(&priv->status_conversation);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
502
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
503 G_OBJECT_CLASS(purple_ircv3_connection_parent_class)->dispose(obj);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
504 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
505
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
506 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
507 purple_ircv3_connection_finalize(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
508 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
509 PurpleIRCv3ConnectionPrivate *priv = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
510
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
511 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
512
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
513 g_clear_pointer(&priv->server_name, g_free);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
514
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
515 G_OBJECT_CLASS(purple_ircv3_connection_parent_class)->finalize(obj);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
516 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
517
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
518 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
519 purple_ircv3_connection_constructed(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
520 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
521 PurpleIRCv3ConnectionPrivate *priv = NULL;
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
522 PurpleAccount *account = NULL;
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
523 PurpleContactInfo *info = NULL;
42506
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
524 PurpleConversationManager *conversation_manager = NULL;
42133
e9a794bfe183 IRCv3: Set the SASL login name to the current nick if not set during connection
Gary Kramlich <grim@reaperworld.com>
parents: 42030
diff changeset
525 char **userparts = NULL;
e9a794bfe183 IRCv3: Set the SASL login name to the current nick if not set during connection
Gary Kramlich <grim@reaperworld.com>
parents: 42030
diff changeset
526 const char *username = NULL;
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
527 char *title = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
528
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
529 G_OBJECT_CLASS(purple_ircv3_connection_parent_class)->constructed(obj);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
530
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
531 priv = purple_ircv3_connection_get_instance_private(connection);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
532 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
533 info = PURPLE_CONTACT_INFO(account);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
534
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
535 title = g_strdup_printf(_("status for %s"),
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
536 purple_contact_info_get_username(info));
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
537
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
538 /* Split the username into nick and server and store the values. */
41977
bade7303795a Update all protocol except gg and xmpp for the account api deprecations
Gary Kramlich <grim@reaperworld.com>
parents: 41955
diff changeset
539 username = purple_contact_info_get_username(PURPLE_CONTACT_INFO(account));
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
540 userparts = g_strsplit(username, "@", 2);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
541 purple_connection_set_display_name(PURPLE_CONNECTION(connection),
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
542 userparts[0]);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
543 priv->server_name = g_strdup(userparts[1]);
42133
e9a794bfe183 IRCv3: Set the SASL login name to the current nick if not set during connection
Gary Kramlich <grim@reaperworld.com>
parents: 42030
diff changeset
544
e9a794bfe183 IRCv3: Set the SASL login name to the current nick if not set during connection
Gary Kramlich <grim@reaperworld.com>
parents: 42030
diff changeset
545 /* Free the userparts vector. */
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
546 g_strfreev(userparts);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
547
42506
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
548 /* Check if we have an existing status conversation. */
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
549 conversation_manager = purple_conversation_manager_get_default();
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
550 priv->status_conversation = purple_conversation_manager_find_with_id(conversation_manager,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
551 account,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
552 priv->server_name);
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
553
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
554 if(!PURPLE_IS_CONVERSATION(priv->status_conversation)) {
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
555 /* Create our status conversation. */
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
556 priv->status_conversation = g_object_new(
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
557 PURPLE_TYPE_CONVERSATION,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
558 "account", account,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
559 "id", priv->server_name,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
560 "name", priv->server_name,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
561 "title", title,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
562 NULL);
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
563
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
564 purple_conversation_manager_register(conversation_manager,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
565 priv->status_conversation);
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
566 } else {
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
567 /* The conversation existed, so add a reference to it. */
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
568 g_object_ref(priv->status_conversation);
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
569 }
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
570
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
571 g_clear_pointer(&title, g_free);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
572
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
573 /* Finally create our objects. */
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
574 priv->capabilities = purple_ircv3_capabilities_new(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
575 g_signal_connect_object(priv->capabilities, "done",
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
576 G_CALLBACK(purple_ircv3_connection_caps_done_cb),
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
577 connection, 0);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
578 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
579
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
580 static void
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: 41870
diff changeset
581 purple_ircv3_connection_init(G_GNUC_UNUSED PurpleIRCv3Connection *connection) {
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
582 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
583
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
584 static void
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: 41870
diff changeset
585 purple_ircv3_connection_class_finalize(G_GNUC_UNUSED PurpleIRCv3ConnectionClass *klass) {
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
586 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
587
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
588 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
589 purple_ircv3_connection_class_init(PurpleIRCv3ConnectionClass *klass) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
590 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
591 PurpleConnectionClass *connection_class = PURPLE_CONNECTION_CLASS(klass);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
592
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
593 obj_class->get_property = purple_ircv3_connection_get_property;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
594 obj_class->constructed = purple_ircv3_connection_constructed;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
595 obj_class->dispose = purple_ircv3_connection_dispose;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
596 obj_class->finalize = purple_ircv3_connection_finalize;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
597
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
598 connection_class->connect = purple_ircv3_connection_connect;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
599 connection_class->disconnect = purple_ircv3_connection_disconnect;
41814
f8940ebd4eee Back out the PurpleProtocol->login change that returned a PurpleConnection
Gary Kramlich <grim@reaperworld.com>
parents: 41812
diff changeset
600
f8940ebd4eee Back out the PurpleProtocol->login change that returned a PurpleConnection
Gary Kramlich <grim@reaperworld.com>
parents: 41812
diff changeset
601 /**
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
602 * PurpleIRCv3Connection:capabilities:
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
603 *
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
604 * The capabilities that the server supports.
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
605 *
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
606 * This is created during registration of the connection and is useful for
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
607 * troubleshooting or just reporting them to end users.
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
608 *
42619
3dd7cd0eabf1 Remove the micro version from Since tags in IRCv3 prpl
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42568
diff changeset
609 * Since: 3.0
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
610 */
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
611 properties[PROP_CAPABILITIES] = g_param_spec_object(
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
612 "capabilities", "capabilities",
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
613 "The capabilities that the server supports",
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
614 PURPLE_IRCV3_TYPE_CAPABILITIES,
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
615 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
616
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
617 /**
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
618 * PurpleIRCv3Connection:registered:
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
619 *
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
620 * Whether or not the connection has finished the registration portion of
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
621 * the connection.
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
622 *
42619
3dd7cd0eabf1 Remove the micro version from Since tags in IRCv3 prpl
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42568
diff changeset
623 * Since: 3.0
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
624 */
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
625 properties[PROP_REGISTERED] = g_param_spec_boolean(
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
626 "registered", "registered",
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
627 "Whether or not the connection has finished registration.",
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
628 FALSE,
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
629 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
630
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
631 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
632
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
633 /* Signals */
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
634
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
635 /**
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
636 * PurpleIRCv3Connection::registration-complete:
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
637 * @connection: The instance.
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
638 *
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
639 * This signal is emitted after the registration process has been
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
640 * completed. Plugins can use this to perform additional actions before
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
641 * any channels are auto joined or similar.
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
642 *
42619
3dd7cd0eabf1 Remove the micro version from Since tags in IRCv3 prpl
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42568
diff changeset
643 * Since: 3.0
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
644 */
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
645 signals[SIG_REGISTRATION_COMPLETE] = g_signal_new_class_handler(
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
646 "registration-complete",
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
647 G_OBJECT_CLASS_TYPE(klass),
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
648 G_SIGNAL_RUN_LAST,
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
649 G_CALLBACK(purple_ircv3_connection_registration_complete_cb),
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
650 NULL,
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
651 NULL,
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
652 NULL,
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
653 G_TYPE_NONE,
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
654 0);
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
655
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
656 /**
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
657 * PurpleIRCv3Connection::ctcp-request:
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
658 * @connection: The instance.
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
659 * @conversation: The conversation.
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
660 * @message: The message.
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
661 * @command: The CTCP command.
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
662 * @params: (nullable): The CTCP parameters.
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
663 *
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
664 * This signal is emitted after a CTCP request has been received.
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
665 *
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
666 * Signal handlers should return TRUE if they fully handled the request and
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
667 * do not want it echoed out to the user.
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
668 *
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
669 * Handlers may also modify the message. For example, the CTCP ACTION
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
670 * command has its message contents replaced with just the CTCP parameters
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
671 * and sets the [property@Message:action] to %TRUE and then returns %TRUE.
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
672 *
42619
3dd7cd0eabf1 Remove the micro version from Since tags in IRCv3 prpl
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42568
diff changeset
673 * Since: 3.0
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
674 */
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
675 signals[SIG_CTCP_REQUEST] = g_signal_new_class_handler(
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
676 "ctcp-request",
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
677 G_OBJECT_CLASS_TYPE(klass),
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
678 G_SIGNAL_RUN_LAST,
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
679 G_CALLBACK(purple_ircv3_connection_ctcp_request_default_handler),
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
680 g_signal_accumulator_true_handled,
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
681 NULL,
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
682 NULL,
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
683 G_TYPE_BOOLEAN,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
684 4,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
685 PURPLE_TYPE_CONVERSATION,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
686 PURPLE_TYPE_MESSAGE,
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
687 G_TYPE_STRING,
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
688 G_TYPE_STRING);
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
689
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
690 /**
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
691 * PurpleIRCv3Connection::ctcp-response:
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
692 * @connection: The instance.
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
693 * @conversation: The conversation.
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
694 * @message: The message.
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
695 * @command: The CTCP command.
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
696 * @params: (nullable): The CTCP parameters.
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
697 *
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
698 * This signal is emitted after a CTCP response has been received.
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
699 *
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
700 * Signal handlers should return TRUE if they fully handled the response
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
701 * and do not want it echoed out to the user.
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
702 *
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
703 * Handlers may modify @conversation or @message to depending on their
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
704 * needs.
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
705 *
42619
3dd7cd0eabf1 Remove the micro version from Since tags in IRCv3 prpl
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42568
diff changeset
706 * Since: 3.0
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
707 */
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
708 signals[SIG_CTCP_RESPONSE] = g_signal_new_class_handler(
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
709 "ctcp-response",
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
710 G_OBJECT_CLASS_TYPE(klass),
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
711 G_SIGNAL_RUN_LAST,
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
712 G_CALLBACK(purple_ircv3_connection_ctcp_response_default_handler),
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
713 g_signal_accumulator_true_handled,
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
714 NULL,
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
715 NULL,
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
716 G_TYPE_BOOLEAN,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
717 4,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
718 PURPLE_TYPE_CONVERSATION,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
719 PURPLE_TYPE_MESSAGE,
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
720 G_TYPE_STRING,
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
721 G_TYPE_STRING);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
722 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
723
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
724 /******************************************************************************
42000
0b26ebc842db Make purple_ircv3_connection_writef public
Gary Kramlich <grim@reaperworld.com>
parents: 41977
diff changeset
725 * Internal API
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
726 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
727 void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
728 purple_ircv3_connection_register(GPluginNativePlugin *plugin) {
42288
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
729 GObjectClass *hack = NULL;
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
730
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
731 purple_ircv3_connection_register_type(G_TYPE_MODULE(plugin));
42288
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
732
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
733 /* Without this hack we get some warnings about no reference on this type
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
734 * when generating the gir file. However, there are no changes to the
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
735 * generated gir file with or without this hack, so this is purely to get
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
736 * rid of the warnings.
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
737 *
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
738 * - GK 2023-08-21
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
739 */
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
740 hack = g_type_class_ref(purple_ircv3_connection_get_type());
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
741 g_type_class_unref(hack);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
742 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
743
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
744 gboolean
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
745 purple_ircv3_connection_emit_ctcp_request(PurpleIRCv3Connection *connection,
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
746 PurpleConversation *conversation,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
747 PurpleMessage *message,
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
748 const char *command,
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
749 const char *parameters)
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
750 {
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
751 gboolean ret = FALSE;
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
752
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
753 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection), FALSE);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
754 g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
755 g_return_val_if_fail(PURPLE_IS_MESSAGE(message), FALSE);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
756 g_return_val_if_fail(!purple_strempty(command), FALSE);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
757
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
758 g_signal_emit(connection, signals[SIG_CTCP_REQUEST], 0, conversation,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
759 message, command, parameters, &ret);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
760
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
761 return ret;
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
762 }
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
763
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
764 gboolean
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
765 purple_ircv3_connection_emit_ctcp_response(PurpleIRCv3Connection *connection,
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
766 PurpleConversation *conversation,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
767 PurpleMessage *message,
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
768 const char *command,
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
769 const char *parameters)
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
770 {
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
771 gboolean ret = FALSE;
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
772
42543
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
773 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection), FALSE);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
774 g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
775 g_return_val_if_fail(PURPLE_IS_MESSAGE(message), FALSE);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
776 g_return_val_if_fail(!purple_strempty(command), FALSE);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
777
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
778 g_signal_emit(connection, signals[SIG_CTCP_RESPONSE], 0, conversation,
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
779 message, command, parameters, &ret);
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
780
6dcf672547fe IRCv3: Update the signals so that handlers can inhibit the message from being displayed
Gary Kramlich <grim@reaperworld.com>
parents: 42542
diff changeset
781 return ret;
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
782 }
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
783
42000
0b26ebc842db Make purple_ircv3_connection_writef public
Gary Kramlich <grim@reaperworld.com>
parents: 41977
diff changeset
784 /******************************************************************************
0b26ebc842db Make purple_ircv3_connection_writef public
Gary Kramlich <grim@reaperworld.com>
parents: 41977
diff changeset
785 * Public API
0b26ebc842db Make purple_ircv3_connection_writef public
Gary Kramlich <grim@reaperworld.com>
parents: 41977
diff changeset
786 *****************************************************************************/
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
787 void
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
788 purple_ircv3_connection_writef(PurpleIRCv3Connection *connection,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
789 const char *format, ...)
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
790 {
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
791 PurpleIRCv3ConnectionPrivate *priv = NULL;
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
792 GBytes *bytes = NULL;
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
793 GCancellable *cancellable = NULL;
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
794 GString *msg = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
795 va_list vargs;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
796
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
797 g_return_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection));
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
798 g_return_if_fail(format != NULL);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
799
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
800 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
801
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
802 /* Create our string and append our format to it. */
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
803 msg = g_string_new("");
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
804
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
805 va_start(vargs, format);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
806 g_string_vprintf(msg, format, vargs);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
807 va_end(vargs);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
808
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
809 /* Next add the trailing carriage return line feed. */
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
810 g_string_append(msg, "\r\n");
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
811
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
812 /* Finally turn the string into bytes and send it! */
42250
c2c0eb8398da Fix a warn_unused_result in ircv3connection.c
Gary Kramlich <grim@reaperworld.com>
parents: 42133
diff changeset
813 bytes = g_string_free_to_bytes(msg);
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
814
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
815 cancellable = purple_connection_get_cancellable(PURPLE_CONNECTION(connection));
42547
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
816 birb_queued_output_stream_push_bytes_async(BIRB_QUEUED_OUTPUT_STREAM(priv->output),
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
817 bytes,
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
818 G_PRIORITY_DEFAULT,
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
819 cancellable,
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
820 purple_ircv3_connection_write_cb,
7a4558293dca Add birb as a subproject and make IRCv3 use it
Gary Kramlich <grim@reaperworld.com>
parents: 42544
diff changeset
821 connection);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
822
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
823 g_bytes_unref(bytes);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
824 }
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
825
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
826 PurpleIRCv3Capabilities *
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
827 purple_ircv3_connection_get_capabilities(PurpleIRCv3Connection *connection) {
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
828 PurpleIRCv3ConnectionPrivate *priv = NULL;
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
829
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
830 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection), NULL);
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
831
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
832 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
833
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
834 return priv->capabilities;
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
835 }
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
836
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
837 gboolean
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
838 purple_ircv3_connection_get_registered(PurpleIRCv3Connection *connection) {
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
839 PurpleIRCv3ConnectionPrivate *priv = NULL;
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
840
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
841 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection), FALSE);
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
842
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
843 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
844
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
845 return priv->registered;
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
846 }
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
847
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
848 void
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
849 purple_ircv3_connection_add_status_message(PurpleIRCv3Connection *connection,
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
850 PurpleIRCv3Message *v3_message)
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
851 {
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
852 PurpleIRCv3ConnectionPrivate *priv = NULL;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
853 PurpleMessage *message = NULL;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
854 GString *str = NULL;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
855 GStrv params = NULL;
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
856 char *stripped = NULL;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
857 const char *command = NULL;
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
858
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
859 g_return_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection));
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
860 g_return_if_fail(PURPLE_IRCV3_IS_MESSAGE(v3_message));
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
861
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
862 priv = purple_ircv3_connection_get_instance_private(connection);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
863
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
864 command = purple_ircv3_message_get_command(v3_message);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
865
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
866 str = g_string_new(command);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
867
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
868 params = purple_ircv3_message_get_params(v3_message);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
869 if(params != NULL && params[0] != NULL) {
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
870 char *joined = g_strjoinv(" ", params);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
871
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
872 g_string_append_printf(str, " %s", joined);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
873
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
874 g_free(joined);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
875 }
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
876
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
877 stripped = purple_ircv3_formatting_strip(str->str);
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
878 g_string_free(str, TRUE);
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
879
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
880 message = g_object_new(
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
881 PURPLE_TYPE_MESSAGE,
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
882 "author", purple_ircv3_message_get_source(v3_message),
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
883 "contents", stripped,
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
884 NULL);
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
885 g_free(stripped);
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
886
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
887 purple_conversation_write_message(priv->status_conversation, message);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
888
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
889 g_clear_object(&message);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
890 }
42494
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
891
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
892 gboolean
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
893 purple_ircv3_connection_is_channel(PurpleIRCv3Connection *connection,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
894 const char *id)
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
895 {
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
896 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection), FALSE);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
897 g_return_val_if_fail(id != NULL, FALSE);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
898
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
899 return (id[0] == '#');
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
900 }
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
901
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
902 PurpleConversation *
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
903 purple_ircv3_connection_find_or_create_conversation(PurpleIRCv3Connection *connection,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
904 const char *id)
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
905 {
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
906 PurpleAccount *account = NULL;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
907 PurpleConversation *conversation = NULL;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
908 PurpleConversationManager *manager = NULL;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
909
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
910 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection), NULL);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
911 g_return_val_if_fail(id != NULL, NULL);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
912
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
913 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
914 manager = purple_conversation_manager_get_default();
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
915 conversation = purple_conversation_manager_find_with_id(manager, account,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
916 id);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
917
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
918 if(!PURPLE_IS_CONVERSATION(conversation)) {
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
919 PurpleConversationType type = PurpleConversationTypeDM;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
920
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
921 if(purple_ircv3_connection_is_channel(connection, id)) {
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
922 type = PurpleConversationTypeChannel;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
923 }
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
924
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
925 conversation = g_object_new(
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
926 PURPLE_TYPE_CONVERSATION,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
927 "account", account,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
928 "id", id,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
929 "name", id,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
930 "type", type,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
931 NULL);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
932
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
933 purple_conversation_manager_register(manager, conversation);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
934
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
935 /* The manager creates its own reference on our new conversation, so we
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
936 * borrow it like we do above if it already exists.
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
937 */
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
938 g_object_unref(conversation);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
939 }
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
940
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
941 return conversation;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
942 }
42513
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
943
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
944 PurpleContact *
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
945 purple_ircv3_connection_find_or_create_contact(PurpleIRCv3Connection *connection,
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
946 const char *nick)
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
947 {
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
948 PurpleAccount *account = NULL;
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
949 PurpleContact *contact = NULL;
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
950 PurpleContactManager *manager = NULL;
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
951
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
952 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
953 manager = purple_contact_manager_get_default();
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
954 contact = purple_contact_manager_find_with_id(manager, account, nick);
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
955
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
956 if(!PURPLE_IS_CONTACT(contact)) {
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
957 contact = purple_contact_new(account, nick);
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
958 purple_contact_info_set_username(PURPLE_CONTACT_INFO(contact), nick);
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
959
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
960 purple_contact_manager_add(manager, contact);
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
961 }
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
962
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
963 return contact;
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
964 }

mercurial