libpurple/protocols/ircv3/purpleircv3connection.c

Mon, 31 Oct 2022 23:00:12 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 31 Oct 2022 23:00:12 -0500
changeset 41870
7668d023ae05
parent 41814
f8940ebd4eee
child 41941
355bd17297f0
permissions
-rw-r--r--

Update the IRCv3 protocol plugin to the new connection setup

Testing Done:
Connected and disconnected an IRCv3 account and verified that it worked and that there were no `g_warnings`.

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

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 *
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * 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
7 * 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
8 * (at your option) any later version.
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * 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
12 * 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
13 * GNU General Public License for more details.
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
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 #include <glib/gi18n-lib.h>
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include "purpleircv3connection.h"
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 "purpleircv3core.h"
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
24 #include "purpleircv3parser.h"
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 enum {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 PROP_0,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 PROP_CANCELLABLE,
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
29 PROP_CAPABILITIES,
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 N_PROPERTIES,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 };
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 struct _PurpleIRCv3Connection {
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
35 PurpleConnection parent;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 GSocketConnection *connection;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 GCancellable *cancellable;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 gchar *server_name;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 GDataInputStream *input;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 PurpleQueuedOutputStream *output;
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
44
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
45 PurpleIRCv3Parser *parser;
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
46
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
47 char *capabilities;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 };
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 G_DEFINE_DYNAMIC_TYPE(PurpleIRCv3Connection, purple_ircv3_connection,
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
51 PURPLE_TYPE_CONNECTION)
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52
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 * Helpers
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 static void
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
57 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
58 PurpleAccount *account = NULL;
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
59 const char *identname = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
60 const char *nickname = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
61 const char *realname = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
62
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
63 nickname =
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
64 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
65
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
66 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
67
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
68 /* 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
69 * 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
70 */
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
71 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
72 if(identname == NULL || *identname == '\0') {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
73 identname = nickname;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
74 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
75
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
76 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
77 if(realname == NULL || *realname == '\0') {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
78 realname = nickname;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
79 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
80
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
81 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
82 realname);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
83 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
84
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
85 static void
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
86 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
87 const char *nickname = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
88
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
89 nickname =
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
90 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
91
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
92 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
93 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
94
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 /******************************************************************************
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 * Callbacks
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 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
100 gpointer data)
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 {
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
102 PurpleIRCv3Connection *connection = data;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 GDataInputStream *istream = G_DATA_INPUT_STREAM(source);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 GError *error = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 gchar *line = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 gsize length;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 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
109 &error);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 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
111 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
112 if(error == NULL) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
113 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
114 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
115 _("Server closed the connection"));
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
116 } else {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
117 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
118 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
119
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
120 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
121 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 /* 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
124 g_free(line);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 return;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
129 purple_ircv3_parser_parse(connection->parser, line, &error, connection);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 g_free(line);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
132
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
133 /* Call read_line_async again to continue reading lines. */
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
134 g_data_input_stream_read_line_async(connection->input,
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
135 G_PRIORITY_DEFAULT,
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
136 connection->cancellable,
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
137 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
138 connection);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 static void
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
142 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
143 gpointer data)
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
144 {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
145 PurpleIRCv3Connection *connection = data;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
146 PurpleQueuedOutputStream *stream = PURPLE_QUEUED_OUTPUT_STREAM(source);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
147 GError *error = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
148 gboolean success = FALSE;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
149
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
150 success = purple_queued_output_stream_push_bytes_finish(stream, result,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
151 &error);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
152
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
153 if(!success) {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
154 purple_queued_output_stream_clear_queue(stream);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
155
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
156 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
157
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
158 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
159
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
160 return;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
161 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
162 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
163
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
164 static void
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 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
166 gpointer data)
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 {
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
168 PurpleIRCv3Connection *connection = data;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 GError *error = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 GInputStream *istream = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 GOutputStream *ostream = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 GSocketClient *client = G_SOCKET_CLIENT(source);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 GSocketConnection *conn = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 /* Finish the async method. */
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 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
177 if(conn == NULL || error != NULL) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 g_prefix_error(&error, "%s", _("Unable to connect: "));
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
180 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
181
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 return;
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
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
185 purple_connection_set_state(PURPLE_CONNECTION(connection),
41812
c3cd920261b6 Fix the namespace of the PurpleConnectionState enum constants
Gary Kramlich <grim@reaperworld.com>
parents: 41811
diff changeset
186 PURPLE_CONNECTION_STATE_CONNECTED);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
187
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 g_message("Successfully connected to %s", connection->server_name);
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 /* Save our connection and setup our input and outputs. */
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 connection->connection = conn;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
193 /* Create our parser. */
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
194 connection->parser = purple_ircv3_parser_new();
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
195 purple_ircv3_parser_add_default_handlers(connection->parser);
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
196
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 ostream = g_io_stream_get_output_stream(G_IO_STREAM(conn));
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 connection->output = purple_queued_output_stream_new(ostream);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 istream = g_io_stream_get_input_stream(G_IO_STREAM(conn));
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 connection->input = g_data_input_stream_new(istream);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
202 g_data_input_stream_set_newline_type(G_DATA_INPUT_STREAM(connection->input),
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
203 G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 /* Add our read callback. */
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 g_data_input_stream_read_line_async(connection->input,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 G_PRIORITY_DEFAULT,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 connection->cancellable,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209 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
210 connection);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
212 /* Send our registration commands. */
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
213 purple_ircv3_connection_writef(connection, "CAP LS %s",
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
214 PURPLE_IRCV3_CONNECTION_CAP_VERSION);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
215 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
216 purple_ircv3_connection_send_nick_command(connection);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 /******************************************************************************
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
220 * PurpleConnection Implementation
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
221 *****************************************************************************/
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
222 static gboolean
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
223 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
224 GError **error)
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
225 {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
226 PurpleIRCv3Connection *connection = NULL;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
227 PurpleAccount *account = NULL;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
228 GSocketClient *client = NULL;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
229 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
230 gint port = 0;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
231 gboolean use_tls = TRUE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
232
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
233 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
234
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
235 connection = PURPLE_IRCV3_CONNECTION(purple_connection);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
236 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
237
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
238 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
239 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
240 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
241 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
242 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
243
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
244 return FALSE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
245 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
246
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
247 /* 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
248 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
249 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
250
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
251 /* 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
252 if(!use_tls) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
253 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
254 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
255 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
256
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
257 /* Finally start the async connection. */
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
258 g_socket_client_connect_to_host_async(client, connection->server_name,
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
259 port, connection->cancellable,
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
260 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
261 connection);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
262
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
263 g_clear_object(&client);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
264
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
265 return TRUE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
266 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
267
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
268 static gboolean
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
269 purple_ircv3_connection_disconnect(PurpleConnection *purple_connection,
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
270 GError **error)
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
271 {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
272 PurpleIRCv3Connection *connection = NULL;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
273
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
274 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
275
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
276 connection = PURPLE_IRCV3_CONNECTION(purple_connection);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
277
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
278 /* TODO: send QUIT command. */
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
279
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
280 /* Cancel the cancellable to tell everyone we're shutting down. */
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
281 if(G_IS_CANCELLABLE(connection->cancellable)) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
282 g_cancellable_cancel(connection->cancellable);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
283
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
284 g_clear_object(&connection->cancellable);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
285 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
286
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
287 if(G_IS_SOCKET_CONNECTION(connection->connection)) {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
288 GInputStream *istream = G_INPUT_STREAM(connection->input);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
289 GOutputStream *ostream = G_OUTPUT_STREAM(connection->output);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
290
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
291 purple_gio_graceful_close(G_IO_STREAM(connection->connection),
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
292 istream, ostream);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
293 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
294
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
295 g_clear_object(&connection->input);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
296 g_clear_object(&connection->output);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
297 g_clear_object(&connection->connection);
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
298
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
299 return TRUE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
300 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
301
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
302 /******************************************************************************
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303 * GObject Implementation
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306 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
307 GValue *value, GParamSpec *pspec)
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 switch(param_id) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 case PROP_CANCELLABLE:
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 g_value_set_object(value,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 purple_ircv3_connection_get_cancellable(connection));
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 break;
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
316 case PROP_CAPABILITIES:
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
317 g_value_set_string(value,
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
318 purple_ircv3_connection_get_capabilities(connection));
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
319 break;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 default:
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 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
322 break;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 purple_ircv3_connection_set_property(GObject *obj, guint param_id,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 const GValue *value, GParamSpec *pspec)
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329 {
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
330 // PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
41814
f8940ebd4eee Back out the PurpleProtocol->login change that returned a PurpleConnection
Gary Kramlich <grim@reaperworld.com>
parents: 41812
diff changeset
331
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332 switch(param_id) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 default:
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 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
335 break;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 purple_ircv3_connection_dispose(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 g_clear_object(&connection->cancellable);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345 g_clear_object(&connection->input);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346 g_clear_object(&connection->output);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347 g_clear_object(&connection->connection);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
349 g_clear_object(&connection->parser);
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41793
diff changeset
350
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 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
352 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 purple_ircv3_connection_finalize(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
356 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 g_clear_pointer(&connection->server_name, g_free);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
360 g_clear_pointer(&connection->capabilities, g_free);
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
361
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362 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
363 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366 purple_ircv3_connection_constructed(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
367 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
368 PurpleAccount *account = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369 gchar **userparts = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370 const gchar *username = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372 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
373
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
374 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
375
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
376 /* Split the username into nick and server and store the values. */
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
377 username = purple_account_get_username(account);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
378 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
379 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
380 userparts[0]);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
381 connection->server_name = g_strdup(userparts[1]);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 g_strfreev(userparts);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
383
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384 /* Finally create our cancellable. */
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385 connection->cancellable = g_cancellable_new();
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
386 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
387
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389 purple_ircv3_connection_init(PurpleIRCv3Connection *connection) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
391
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 purple_ircv3_connection_class_finalize(PurpleIRCv3ConnectionClass *klass) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
395
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
396 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
397 purple_ircv3_connection_class_init(PurpleIRCv3ConnectionClass *klass) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
398 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
399 PurpleConnectionClass *connection_class = PURPLE_CONNECTION_CLASS(klass);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
401 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
402 obj_class->set_property = purple_ircv3_connection_set_property;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 obj_class->constructed = purple_ircv3_connection_constructed;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
404 obj_class->dispose = purple_ircv3_connection_dispose;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
405 obj_class->finalize = purple_ircv3_connection_finalize;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
406
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
407 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
408 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
409
f8940ebd4eee Back out the PurpleProtocol->login change that returned a PurpleConnection
Gary Kramlich <grim@reaperworld.com>
parents: 41812
diff changeset
410 /**
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
411 * PurpleIRCv3Connection:cancellable:
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
412 *
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
413 * The [class@Gio.Cancellable] for this connection.
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
414 *
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
415 * Since: 3.0.0
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
416 */
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
417 properties[PROP_CANCELLABLE] = g_param_spec_object(
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
418 "cancellable", "cancellable",
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
419 "The cancellable for this connection",
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
420 G_TYPE_CANCELLABLE,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
421 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
422
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
423 /**
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
424 * PurpleIRCv3Connection:capabilities:
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
425 *
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
426 * The capabilities that the server supports.
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
427 *
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
428 * 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
429 * 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
430 *
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
431 * Since: 3.0.0
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
432 */
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
433 properties[PROP_CAPABILITIES] = g_param_spec_string(
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
434 "capabilities", "capabilities",
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
435 "The capabilities that the server supports",
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
436 NULL,
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
437 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
438
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
439 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
440 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
441
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
442 /******************************************************************************
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
443 * GObject Implementation
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
444 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
445 void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
446 purple_ircv3_connection_register(GPluginNativePlugin *plugin) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
447 purple_ircv3_connection_register_type(G_TYPE_MODULE(plugin));
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
448 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
449
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
450 GCancellable *
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
451 purple_ircv3_connection_get_cancellable(PurpleIRCv3Connection *connection) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
452 g_return_val_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection), NULL);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
453
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
454 return connection->cancellable;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
455 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
456
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
457 void
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
458 purple_ircv3_connection_writef(PurpleIRCv3Connection *connection,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
459 const char *format, ...)
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
460 {
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
461 GBytes *bytes = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
462 GString *msg = NULL;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
463 va_list vargs;
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
464
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
465 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
466 g_return_if_fail(format != NULL);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
467
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
468 /* 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
469 msg = g_string_new("");
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
470
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
471 va_start(vargs, format);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
472 g_string_vprintf(msg, format, vargs);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
473 va_end(vargs);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
474
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
475 /* 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
476 g_string_append(msg, "\r\n");
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
477
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
478 /* Finally turn the string into bytes and send it! */
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
479 bytes = g_bytes_new_take(msg->str, msg->len);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
480 g_string_free(msg, FALSE);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
481
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
482 purple_queued_output_stream_push_bytes_async(connection->output, bytes,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
483 G_PRIORITY_DEFAULT,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
484 connection->cancellable,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
485 purple_ircv3_connection_write_cb,
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
486 connection);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
487
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
488 g_bytes_unref(bytes);
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
489 }
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
490
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
491 const char *
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
492 purple_ircv3_connection_get_capabilities(PurpleIRCv3Connection *connection) {
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
493 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
494
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
495 return connection->capabilities;
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
496 }
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
497
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
498 void
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
499 purple_ircv3_connection_append_capabilities(PurpleIRCv3Connection *connection,
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
500 const char *capabilities)
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
501 {
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
502 g_return_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection));
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
503 g_return_if_fail(capabilities != NULL);
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
504
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
505 if(connection->capabilities == NULL) {
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
506 connection->capabilities = g_strdup(capabilities);
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
507 } else {
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
508 char *tmp = connection->capabilities;
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
509
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
510 connection->capabilities = g_strdup_printf("%s %s",
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
511 connection->capabilities,
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
512 capabilities);
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
513
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
514 g_free(tmp);
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
515 }
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
516
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
517 g_object_notify_by_pspec(G_OBJECT(connection),
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
518 properties[PROP_CAPABILITIES]);
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
519 }

mercurial