protocols/ircv3/purpleircv3connection.c

Tue, 04 Jun 2024 09:43:14 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 04 Jun 2024 09:43:14 -0500
changeset 42775
98b71fc8a330
parent 42772
4103b1b41a29
child 42780
c1af98cbd43a
permissions
-rw-r--r--

Only check tags if we have a tags object

Testing Done:
Called in the turtles.

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

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
42772
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
27 #include <hasl.h>
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
28
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 #include "purpleircv3connection.h"
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 #include "purpleircv3core.h"
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
32 #include "purpleircv3messagehandlers.h"
41783
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 enum {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 PROP_0,
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
36 PROP_CLIENT,
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 N_PROPERTIES,
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 };
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
41 typedef struct {
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
42 IbisClient *client;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 gchar *server_name;
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
45
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
46 PurpleConversation *status_conversation;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
47 } PurpleIRCv3ConnectionPrivate;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
49 G_DEFINE_DYNAMIC_TYPE_EXTENDED(PurpleIRCv3Connection,
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
50 purple_ircv3_connection,
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
51 PURPLE_TYPE_CONNECTION,
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
52 0,
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
53 G_ADD_PRIVATE_DYNAMIC(PurpleIRCv3Connection))
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
42771
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
55 static gboolean
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
56 purple_ircv3_connection_unknown_message_cb(IbisClient *client,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
57 const char *command,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
58 IbisMessage *message,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
59 gpointer data);
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
60
42772
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
61 static gboolean
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
62 purple_ircv3_connection_saslsuccess(IbisClient *client, const char *command,
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
63 IbisMessage *message, gpointer data);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
64
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 /******************************************************************************
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 * Helpers
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 static void
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
69 purple_ircv3_connection_add_message_handlers(PurpleIRCv3Connection *connection,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
70 IbisClient *client)
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
71 {
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
72 g_signal_connect_object(client, "message::" IBIS_MSG_TOPIC,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
73 G_CALLBACK(purple_ircv3_message_handler_topic),
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
74 connection, G_CONNECT_DEFAULT);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
75 g_signal_connect_object(client, "message::" IBIS_RPL_NOTOPIC,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
76 G_CALLBACK(purple_ircv3_message_handler_topic),
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
77 connection, G_CONNECT_DEFAULT);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
78 g_signal_connect_object(client, "message::" IBIS_RPL_TOPIC,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
79 G_CALLBACK(purple_ircv3_message_handler_topic),
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
80 connection, G_CONNECT_DEFAULT);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
81
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
82 g_signal_connect_object(client, "message::" IBIS_MSG_PRIVMSG,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
83 G_CALLBACK(purple_ircv3_message_handler_privmsg),
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
84 connection, G_CONNECT_DEFAULT);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
85 g_signal_connect_object(client, "message::" IBIS_MSG_NOTICE,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
86 G_CALLBACK(purple_ircv3_message_handler_privmsg),
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
87 connection, G_CONNECT_DEFAULT);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
88
42771
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
89 g_signal_connect_object(client, "message",
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
90 G_CALLBACK(purple_ircv3_connection_unknown_message_cb),
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
91 connection, G_CONNECT_AFTER);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
92 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
93
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
94 static void
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
95 purple_ircv3_connection_rejoin_channels(PurpleIRCv3Connection *connection) {
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
96 PurpleIRCv3ConnectionPrivate *priv = NULL;
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
97 PurpleAccount *account = NULL;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
98 PurpleConversationManager *manager = NULL;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
99 GList *conversations = NULL;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
100
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
101 priv = purple_ircv3_connection_get_instance_private(connection);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
102
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
103 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
104 manager = purple_conversation_manager_get_default();
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
105
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
106 conversations = purple_conversation_manager_get_all(manager);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
107 while(conversations != NULL) {
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
108 PurpleConversation *conversation = conversations->data;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
109 PurpleAccount *conv_account = NULL;
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
110
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
111 conv_account = purple_conversation_get_account(conversation);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
112 if(conv_account == account) {
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
113 IbisMessage *message = NULL;
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
114 const char *id = purple_conversation_get_id(conversation);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
115
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
116 message = ibis_message_new(IBIS_MSG_JOIN);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
117 ibis_message_set_params(message, id, NULL);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
118 ibis_client_write(priv->client, message);
42511
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
119 }
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
120
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
121 conversations = g_list_delete_link(conversations, conversations);
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
122 }
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
123 }
77d01d3cf007 IRCv3: rejoin channels after reconnect
Gary Kramlich <grim@reaperworld.com>
parents: 42506
diff changeset
124
42772
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
125 static inline void
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
126 purple_ircv3_connection_setup_sasl(PurpleIRCv3Connection *connection,
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
127 PurpleAccount *account)
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
128 {
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
129 PurpleIRCv3ConnectionPrivate *priv = NULL;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
130 HaslContext *hasl_context = NULL;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
131 const char *value = NULL;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
132 gboolean clear_text = FALSE;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
133
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
134 priv = purple_ircv3_connection_get_instance_private(connection);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
135
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
136 hasl_context = hasl_context_new();
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
137
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
138 value = purple_account_get_string(account, "sasl-login-name", NULL);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
139 if(!purple_strempty(value)) {
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
140 hasl_context_set_username(hasl_context, value);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
141 } else {
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
142 hasl_context_set_username(hasl_context,
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
143 ibis_client_get_nick(priv->client));
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
144
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
145 /* Since the user doesn't have a SASL login name set, we'll listen for
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
146 * IBIS_RPL_SASLSUCCESS and use that to set the login name to the
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
147 * username in HASL which worked if the signal handler gets called.
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
148 */
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
149 g_signal_connect_object(priv->client, "message::" IBIS_RPL_SASLSUCCESS,
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
150 G_CALLBACK(purple_ircv3_connection_saslsuccess),
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
151 connection, G_CONNECT_DEFAULT);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
152 }
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
153
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
154 value = purple_connection_get_password(PURPLE_CONNECTION(connection));
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
155 hasl_context_set_password(hasl_context, value);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
156
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
157 value = purple_account_get_string(account, "sasl-mechanisms", NULL);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
158 if(!purple_strempty(value)) {
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
159 hasl_context_set_allowed_mechanisms(hasl_context, value);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
160 }
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
161
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
162 clear_text = purple_account_get_bool(account, "plain-sasl-in-clear", FALSE);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
163 hasl_context_set_allow_clear_text(hasl_context, clear_text);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
164
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
165 ibis_client_set_hasl_context(priv->client, hasl_context);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
166 g_clear_object(&hasl_context);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
167 }
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
168
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 * Callbacks
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 *****************************************************************************/
42771
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
172 static gboolean
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
173 purple_ircv3_connection_unknown_message_cb(G_GNUC_UNUSED IbisClient *client,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
174 G_GNUC_UNUSED const char *command,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
175 IbisMessage *message,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
176 gpointer data)
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
177 {
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
178 PurpleIRCv3Connection *connection = data;
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
179 PurpleIRCv3ConnectionPrivate *priv = NULL;
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
180 PurpleMessage *purple_message = NULL;
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
181 char *contents = NULL;
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
182
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
183 priv = purple_ircv3_connection_get_instance_private(connection);
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
184
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
185 contents = g_strdup_printf(_("unhandled message: '%s'"),
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
186 ibis_message_get_raw_message(message));
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
187
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
188 purple_message = g_object_new(
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
189 PURPLE_TYPE_MESSAGE,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
190 "author", ibis_message_get_source(message),
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
191 "contents", contents,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
192 NULL);
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
193
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
194 purple_conversation_write_message(priv->status_conversation,
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
195 purple_message);
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
196 g_clear_object(&purple_message);
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
197
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
198 g_free(contents);
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
199
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
200 return TRUE;
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
201 }
3dc6600c6c0e IRCv3: write the unhandled raw messages to the status window
Gary Kramlich <grim@reaperworld.com>
parents: 42770
diff changeset
202
42772
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
203 static gboolean
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
204 purple_ircv3_connection_saslsuccess(IbisClient *client,
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
205 G_GNUC_UNUSED const char *command,
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
206 G_GNUC_UNUSED IbisMessage *message,
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
207 gpointer data)
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
208 {
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
209 PurpleIRCv3Connection *connection = data;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
210 PurpleAccount *account = NULL;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
211 const char *value = NULL;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
212
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
213 account = purple_connection_get_account(PURPLE_CONNECTION(connection));
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
214 value = purple_account_get_string(account, "sasl-login-name", NULL);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
215
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
216 /* If the sasl-login-name is empty, we set it to the current username in
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
217 * our hasl context that was used to login.
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
218 */
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
219 if(purple_strempty(value)) {
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
220 HaslContext *hasl_context = NULL;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
221
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
222 hasl_context = ibis_client_get_hasl_context(client);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
223 if(HASL_IS_CONTEXT(hasl_context)) {
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
224 purple_account_set_string(account, "sasl-login-name",
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
225 hasl_context_get_username(hasl_context));
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
226
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
227 }
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
228 }
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
229
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
230 /* We don't actually handle SASLSUCCESS, but we just needed to know if it
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
231 * was sent.
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
232 */
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
233 return FALSE;
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
234 }
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
235
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 static void
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
237 purple_ircv3_connection_connect_cb(GObject *source,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
238 G_GNUC_UNUSED GParamSpec *pspec,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
239 gpointer data)
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240 {
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
241 PurpleConnection *connection = data;
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
242 IbisClient *client = IBIS_CLIENT(source);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
243
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
244 if(ibis_client_get_connected(client)) {
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
245 purple_connection_set_state(connection,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
246 PURPLE_CONNECTION_STATE_CONNECTED);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
248 /* Once reconnected, we need to rejoin any channels that the
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
249 * conversation manager has for us.
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
250 */
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
251 purple_ircv3_connection_rejoin_channels(PURPLE_IRCV3_CONNECTION(connection));
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
252 } else {
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
253 purple_connection_set_state(connection,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
254 PURPLE_CONNECTION_STATE_DISCONNECTED);
41793
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
255 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
256 }
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
257
2e6f09066f94 Add connection registration to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41783
diff changeset
258 static void
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
259 purple_ircv3_connection_error_cb(GObject *source,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
260 G_GNUC_UNUSED GParamSpec *pspec,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
261 gpointer data)
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 {
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
263 IbisClient *client = IBIS_CLIENT(source);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
264 PurpleConnection *connection = data;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 GError *error = NULL;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
267 error = ibis_client_get_error(client);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
268 if(error != NULL) {
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
269 purple_connection_g_error(connection, error);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
270 }
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
271 }
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
272
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273 /******************************************************************************
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
274 * PurpleConnection Implementation
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 static gboolean
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
277 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
278 GError **error)
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 PurpleIRCv3Connection *connection = NULL;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
281 PurpleIRCv3ConnectionPrivate *priv = NULL;
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
282 PurpleAccount *account = NULL;
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
283 GError *local_error = NULL;
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
284 GProxyResolver *resolver = NULL;
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
285 const char *password = NULL;
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
286 const char *value = NULL;
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
287 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
288 gint port = 0;
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
289 gboolean tls = TRUE;
41870
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 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
292
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
293 connection = PURPLE_IRCV3_CONNECTION(purple_connection);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
294 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
295 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
296
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
297 priv->client = ibis_client_new();
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
298 g_signal_connect_object(priv->client, "notify::connected",
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
299 G_CALLBACK(purple_ircv3_connection_connect_cb),
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
300 connection, G_CONNECT_DEFAULT);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
301 g_signal_connect_object(priv->client, "notify::error",
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
302 G_CALLBACK(purple_ircv3_connection_error_cb),
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
303 connection, G_CONNECT_DEFAULT);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
304 purple_ircv3_connection_add_message_handlers(connection, priv->client);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
305
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
306 ibis_client_set_nick(priv->client,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
307 purple_connection_get_display_name(purple_connection));
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
308
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
309 value = purple_account_get_string(account, "ident", NULL);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
310 ibis_client_set_username(priv->client, value);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
311
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
312 value = purple_account_get_string(account, "real-name", NULL);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
313 ibis_client_set_realname(priv->client, value);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
314
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
315 password = purple_account_get_string(account, "server-password", NULL);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
316
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
317 /* Turn on TLS if requested. */
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
318 tls = purple_account_get_bool(account, "use-tls", TRUE);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
319
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
320 /* If TLS is not being used, set the default port to the plain port. */
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
321 if(!tls) {
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
322 default_port = PURPLE_IRCV3_DEFAULT_PLAIN_PORT;
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
323 }
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
324 port = purple_account_get_int(account, "port", default_port);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
325
42772
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
326 purple_ircv3_connection_setup_sasl(connection, account);
4103b1b41a29 IRCv3: Require Ibis 0.1.0 and wire up SASL
Gary Kramlich <grim@reaperworld.com>
parents: 42771
diff changeset
327
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
328 resolver = purple_proxy_get_proxy_resolver(account, &local_error);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
329 if(local_error != NULL) {
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
330 g_propagate_error(error, local_error);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
331
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
332 g_clear_object(&resolver);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
333 g_clear_object(&priv->client);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
334
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
335 return FALSE;
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
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
338 ibis_client_connect(priv->client, priv->server_name, port, password, tls,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
339 resolver);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
340
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
341 return TRUE;
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
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
344 static gboolean
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
345 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
346 GError **error)
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
347 {
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
348 PurpleIRCv3Connection *connection = NULL;
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
349 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
350 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
351
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
352 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
353
42542
1407a0aac0bf Add a cancellable property to PurpleConnection and port IRCv3 to it
Gary Kramlich <grim@reaperworld.com>
parents: 42530
diff changeset
354 /* 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
355 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
356 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
357
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
358 connection = PURPLE_IRCV3_CONNECTION(purple_connection);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
359 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
360
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
361 /* TODO: send QUIT command. */
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
362
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
363 g_clear_object(&priv->client);
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
364
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
365 return TRUE;
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
366 }
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
367
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
368 /******************************************************************************
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369 * GObject Implementation
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372 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
373 GValue *value, GParamSpec *pspec)
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
374 {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
375 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
376
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
377 switch(param_id) {
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
378 case PROP_CLIENT:
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
379 g_value_set_object(value,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
380 purple_ircv3_connection_get_client(connection));
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
381 break;
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
382 default:
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
383 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
384 break;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385 }
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_dispose(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
391 PurpleIRCv3ConnectionPrivate *priv = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
393 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
394
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
395 g_clear_object(&priv->client);
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
396 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
397
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
398 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
399 }
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 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
402 purple_ircv3_connection_finalize(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
404 PurpleIRCv3ConnectionPrivate *priv = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
405
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
406 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
407
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
408 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
409
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
410 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
411 }
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 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
414 purple_ircv3_connection_constructed(GObject *obj) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
415 PurpleIRCv3Connection *connection = PURPLE_IRCV3_CONNECTION(obj);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
416 PurpleIRCv3ConnectionPrivate *priv = NULL;
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
417 PurpleAccount *account = NULL;
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
418 PurpleContactInfo *info = NULL;
42506
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
419 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
420 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
421 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
422 char *title = NULL;
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
423
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
424 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
425
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
426 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
427 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
428 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
429
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
430 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
431 purple_contact_info_get_username(info));
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
432
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
433 /* 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
434 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
435 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
436 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
437 userparts[0]);
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
438 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
439
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
440 /* Free the userparts vector. */
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
441 g_strfreev(userparts);
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
442
42506
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
443 /* 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
444 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
445 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
446 account,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
447 priv->server_name);
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
448
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
449 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
450 /* Create our status conversation. */
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
451 priv->status_conversation = g_object_new(
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
452 PURPLE_TYPE_CONVERSATION,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
453 "account", account,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
454 "id", priv->server_name,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
455 "name", priv->server_name,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
456 "title", title,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
457 NULL);
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
458
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
459 purple_conversation_manager_register(conversation_manager,
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
460 priv->status_conversation);
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
461 } else {
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
462 /* 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
463 g_object_ref(priv->status_conversation);
bf4beafd15a3 IRCv3: Reuse existing status window if it exists
Gary Kramlich <grim@reaperworld.com>
parents: 42505
diff changeset
464 }
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
465
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
466 g_clear_pointer(&title, g_free);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
467 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
468
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
469 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
470 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
471 }
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 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
474 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
475 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
476
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
477 static void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
478 purple_ircv3_connection_class_init(PurpleIRCv3ConnectionClass *klass) {
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
479 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
480 PurpleConnectionClass *connection_class = PURPLE_CONNECTION_CLASS(klass);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
481
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
482 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
483 obj_class->constructed = purple_ircv3_connection_constructed;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
484 obj_class->dispose = purple_ircv3_connection_dispose;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
485 obj_class->finalize = purple_ircv3_connection_finalize;
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
486
41870
7668d023ae05 Update the IRCv3 protocol plugin to the new connection setup
Gary Kramlich <grim@reaperworld.com>
parents: 41814
diff changeset
487 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
488 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
489
f8940ebd4eee Back out the PurpleProtocol->login change that returned a PurpleConnection
Gary Kramlich <grim@reaperworld.com>
parents: 41812
diff changeset
490 /**
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
491 * PurpleIRCv3Connection:client:
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
492 *
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
493 * The [class@Ibis.Client] that this connection is using.
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
494 *
42619
3dd7cd0eabf1 Remove the micro version from Since tags in IRCv3 prpl
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42568
diff changeset
495 * Since: 3.0
41954
558106ebf999 Various clean ups to the IRCv3 connection process
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
496 */
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
497 properties[PROP_CLIENT] = g_param_spec_object(
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
498 "client", NULL, NULL,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
499 IBIS_TYPE_CLIENT,
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
500 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
42530
55b30ce86f17 IRCv3: Implement basic CTCP support
Gary Kramlich <grim@reaperworld.com>
parents: 42513
diff changeset
501
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
502 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
503 }
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 /******************************************************************************
42000
0b26ebc842db Make purple_ircv3_connection_writef public
Gary Kramlich <grim@reaperworld.com>
parents: 41977
diff changeset
506 * Internal API
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
507 *****************************************************************************/
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
508 void
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
509 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
510 GObjectClass *hack = NULL;
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
511
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
512 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
513
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
514 /* 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
515 * 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
516 * 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
517 * rid of the warnings.
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
518 *
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
519 * - GK 2023-08-21
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
520 */
fe086fff5eab IRCv3: work around some warnings when generating the gir file
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
521 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
522 g_type_class_unref(hack);
41783
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
523 }
5ea6c18ef7a8 Add the ability to connect to IRCv3
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
524
42000
0b26ebc842db Make purple_ircv3_connection_writef public
Gary Kramlich <grim@reaperworld.com>
parents: 41977
diff changeset
525 /******************************************************************************
0b26ebc842db Make purple_ircv3_connection_writef public
Gary Kramlich <grim@reaperworld.com>
parents: 41977
diff changeset
526 * Public API
0b26ebc842db Make purple_ircv3_connection_writef public
Gary Kramlich <grim@reaperworld.com>
parents: 41977
diff changeset
527 *****************************************************************************/
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
528 IbisClient *
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
529 purple_ircv3_connection_get_client(PurpleIRCv3Connection *connection) {
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
530 PurpleIRCv3ConnectionPrivate *priv = NULL;
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
531
41807
66d473190e94 Start adding capability support to the IRCv3 protocol
Gary Kramlich <grim@reaperworld.com>
parents: 41805
diff changeset
532 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
533
42030
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
534 priv = purple_ircv3_connection_get_instance_private(connection);
7af8ab97086d Make PurpleIRCv3Connection Derivable
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
535
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
536 return priv->client;
42013
5634642aca06 Add a registered property to PurpleIRCv3Connection
Gary Kramlich <grim@reaperworld.com>
parents: 42000
diff changeset
537 }
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
538
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
539 void
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
540 purple_ircv3_connection_add_status_message(PurpleIRCv3Connection *connection,
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
541 IbisMessage *ibis_message)
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
542 {
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
543 PurpleIRCv3ConnectionPrivate *priv = NULL;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
544 PurpleMessage *message = NULL;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
545 GString *str = NULL;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
546 GStrv params = NULL;
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
547 char *stripped = NULL;
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
548 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
549
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
550 g_return_if_fail(PURPLE_IRCV3_IS_CONNECTION(connection));
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
551 g_return_if_fail(IBIS_IS_MESSAGE(ibis_message));
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
552
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
553 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
554
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
555 command = ibis_message_get_command(ibis_message);
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
556
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
557 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
558
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
559 params = ibis_message_get_params(ibis_message);
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42288
diff changeset
560 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
561 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
562
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
563 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
564
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
565 g_free(joined);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
566 }
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
567
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
568 stripped = ibis_formatting_strip(str->str);
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
569 g_string_free(str, TRUE);
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
570
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
571 message = g_object_new(
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
572 PURPLE_TYPE_MESSAGE,
42769
c488d7af2923 Move the IRCv3 protocol plugin to our new Ibis library
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
573 "author", ibis_message_get_source(ibis_message),
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
574 "contents", stripped,
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
575 NULL);
42505
cc095f9ce1f3 IRCv3: strip formatting from incoming messages
Gary Kramlich <grim@reaperworld.com>
parents: 42494
diff changeset
576 g_free(stripped);
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
577
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
578 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
579
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
580 g_clear_object(&message);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42271
diff changeset
581 }
42494
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
582
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
583 gboolean
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
584 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
585 const char *id)
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
586 {
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
587 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
588 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
589
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
590 return (id[0] == '#');
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
591 }
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
592
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
593 PurpleConversation *
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
594 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
595 const char *id)
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
596 {
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
597 PurpleAccount *account = NULL;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
598 PurpleConversation *conversation = NULL;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
599 PurpleConversationManager *manager = NULL;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
600
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
601 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
602 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
603
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
604 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
605 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
606 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
607 id);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
608
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
609 if(!PURPLE_IS_CONVERSATION(conversation)) {
42653
584895b844d2 PurpleConversationType's values were pascal case when they should be upper snake case
Gary Kramlich <grim@reaperworld.com>
parents: 42652
diff changeset
610 PurpleConversationType type = PURPLE_CONVERSATION_TYPE_DM;
42494
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
611
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
612 if(purple_ircv3_connection_is_channel(connection, id)) {
42653
584895b844d2 PurpleConversationType's values were pascal case when they should be upper snake case
Gary Kramlich <grim@reaperworld.com>
parents: 42652
diff changeset
613 type = PURPLE_CONVERSATION_TYPE_CHANNEL;
42494
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
614 }
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
615
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
616 conversation = g_object_new(
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
617 PURPLE_TYPE_CONVERSATION,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
618 "account", account,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
619 "id", id,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
620 "name", id,
42770
3e1f34d33c9a IRCv3: Make sure to set the title property when creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42769
diff changeset
621 "title", id,
42494
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
622 "type", type,
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
623 NULL);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
624
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
625 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
626
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
627 /* 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
628 * 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
629 */
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
630 g_object_unref(conversation);
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
631 }
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
632
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
633 return conversation;
4d6baa511e52 IRCv3: create some helper functions for finding/creating conversations
Gary Kramlich <grim@reaperworld.com>
parents: 42333
diff changeset
634 }
42513
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
635
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
636 PurpleContact *
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
637 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
638 const char *nick)
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
639 {
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
640 PurpleAccount *account = NULL;
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
641 PurpleContact *contact = NULL;
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
642 PurpleContactManager *manager = NULL;
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
643
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
644 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
645 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
646 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
647
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
648 if(!PURPLE_IS_CONTACT(contact)) {
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
649 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
650 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
651
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
652 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
653 }
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
654
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
655 return contact;
482ba61e5123 IRCv3: Add an ircv3_connection_find_or_create_contact
Gary Kramlich <grim@reaperworld.com>
parents: 42511
diff changeset
656 }

mercurial