Wed, 19 Oct 2022 06:25:35 -0500
Back out the PurpleProtocol->login change that returned a PurpleConnection
This remains to be a good idea, but this implementation caused more issues than
it solved. I'm working on that better implementation, but we need to revert all
of this first, otherwise the new review request is going to be massive.
This reverts commits 3f96e2b2b03d, d567f89d6a9b, and 6ef5bb284651. These were
backed out manually due to some other commits that made automative backouts
difficult.
Testing Done:
Connected a demo, ircv3, and xmpp accounts without issue.
Reviewed at https://reviews.imfreedom.org/r/1937/
|
35358
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
1 | /* purple |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
2 | * |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
3 | * Purple is the legal property of its developers, whose names are too numerous |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
4 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
5 | * source distribution. |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
6 | * |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
7 | * Component written by Tomek Wasilczyk (http://www.wasilczyk.pl). |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
8 | * |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
9 | * This file is dual-licensed under the GPL2+ and the X11 (MIT) licences. |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
10 | * As a recipient of this file you may choose, which license to receive the |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
11 | * code under. As a contributor, you have to ensure the new code is |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
12 | * compatible with both. |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
13 | * |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
14 | * This program is free software; you can redistribute it and/or modify |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
15 | * it under the terms of the GNU General Public License as published by |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
16 | * the Free Software Foundation; either version 2 of the License, or |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
17 | * (at your option) any later version. |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
18 | * |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
19 | * This program is distributed in the hope that it will be useful, |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
22 | * GNU General Public License for more details. |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
23 | * |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
24 | * You should have received a copy of the GNU General Public License |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
25 | * along with this program; if not, write to the Free Software |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
26 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
7beae478c905
Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34473
diff
changeset
|
27 | */ |
|
40523
9bcf96663cb9
Make gstreamer-1.0 a required dependency
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
28 | |
|
9bcf96663cb9
Make gstreamer-1.0 a required dependency
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
29 | #include <errno.h> |
|
9bcf96663cb9
Make gstreamer-1.0 a required dependency
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
30 | |
|
9bcf96663cb9
Make gstreamer-1.0 a required dependency
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
31 | #include <purple.h> |
|
9bcf96663cb9
Make gstreamer-1.0 a required dependency
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
32 | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
33 | #include "tcpsocket.h" |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
34 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
35 | #include "gg.h" |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
36 | |
|
40439
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40358
diff
changeset
|
37 | |
| 38139 | 38 | typedef struct { |
| 39 | GSocketConnection *conn; | |
| 40 | GCancellable *cancellable; | |
| 41 | PurpleConnection *gc; | |
| 42 | gpointer priv_gg; | |
| 43 | } GGPTcpSocketData; | |
| 44 | ||
| 45 | static void | |
| 46 | ggp_tcp_socket_data_free(GGPTcpSocketData *data) | |
| 47 | { | |
| 48 | g_return_if_fail(data != NULL); | |
| 49 | ||
| 50 | if (data->cancellable != NULL) { | |
| 51 | g_cancellable_cancel(data->cancellable); | |
| 52 | g_clear_object(&data->cancellable); | |
| 53 | } | |
| 54 | ||
| 55 | if (data->conn != NULL) { | |
| 56 | purple_gio_graceful_close(G_IO_STREAM(data->conn), NULL, NULL); | |
| 57 | g_clear_object(&data->conn); | |
| 58 | } | |
| 59 | ||
| 60 | g_free(data); | |
| 61 | } | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
62 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
63 | static void |
| 38139 | 64 | ggp_tcpsocket_connected(GObject *source, GAsyncResult *res, gpointer user_data) |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
65 | { |
| 38139 | 66 | GGPTcpSocketData *data = user_data; |
| 67 | GSocketConnection *conn; | |
| 68 | GSocket *socket; | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
69 | int fd = -1; |
| 38139 | 70 | GGPInfo *info; |
| 71 | GError *error = NULL; | |
| 72 | ||
| 73 | conn = g_socket_client_connect_to_host_finish(G_SOCKET_CLIENT(source), | |
| 74 | res, &error); | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
75 | |
| 38139 | 76 | if (conn == NULL) { |
|
38142
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
77 | if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
78 | /* The connection was already closed, return now */ |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
79 | g_clear_error(&error); |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
80 | return; |
| 38139 | 81 | } |
|
36068
e9b9320a985a
Drop PURPLE_CONNECTION_IS_VALID in favor of (temporary) PURPLE_ASSERT_CONNECTION_IS_VALID
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36067
diff
changeset
|
82 | |
|
38142
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
83 | purple_debug_error("gg", "socket failed to connect: %s", |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
84 | error->message); |
| 38139 | 85 | g_clear_error(&error); |
| 86 | } else { | |
| 87 | data->conn = conn; | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
88 | |
| 38139 | 89 | socket = g_socket_connection_get_socket(data->conn); |
| 90 | ||
| 91 | if (socket != NULL) { | |
| 92 | fd = g_socket_get_fd(socket); | |
| 93 | } | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
94 | } |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
95 | |
|
38142
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
96 | /* XXX: For some reason if you try to connect and then immediately |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
97 | * disconnect, this gets into a state where ggp_tcpsocket_close() |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
98 | * isn't called. The cancellable is therefore not cancelled, and |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
99 | * the connection is never closed. Guard against that state here. |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
100 | */ |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
101 | if (data->gc == NULL || |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
102 | !g_list_find(purple_connections_get_all(), data->gc)) { |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
103 | purple_debug_error("gg", |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
104 | "disconnected without closing connection: %p", |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
105 | data); |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
106 | ggp_tcp_socket_data_free(data); |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
107 | return; |
|
1dff6e343f9f
gg: Protect against issues when closing while connecting
Mike Ruprecht <cmaiku@gmail.com>
parents:
38139
diff
changeset
|
108 | } |
| 38139 | 109 | |
| 110 | if (!gg_socket_manager_connected(data, data->priv_gg, fd)) { | |
| 111 | purple_debug_error("gg", "socket not handled"); | |
| 112 | ggp_tcp_socket_data_free(data); | |
| 113 | return; | |
| 114 | } | |
| 115 | ||
| 116 | info = purple_connection_get_protocol_data(data->gc); | |
| 117 | ||
| 118 | if (info->inpa > 0) { | |
| 119 | g_source_remove(info->inpa); | |
| 120 | info->inpa = 0; | |
| 121 | } | |
| 122 | ||
|
34442
4534c27446e8
Gadu-Gadu: better fit for new API
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34437
diff
changeset
|
123 | if (info->session->fd < 0) |
|
4534c27446e8
Gadu-Gadu: better fit for new API
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34437
diff
changeset
|
124 | return; |
| 38139 | 125 | |
| 126 | /* XXX: This works, but not recommended to use GSocket FDs directly */ | |
|
34442
4534c27446e8
Gadu-Gadu: better fit for new API
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34437
diff
changeset
|
127 | info->inpa = purple_input_add(info->session->fd, |
|
4534c27446e8
Gadu-Gadu: better fit for new API
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34437
diff
changeset
|
128 | ggp_tcpsocket_inputcond_gg_to_purple(info->session->check), |
| 38139 | 129 | ggp_async_login_handler, data->gc); |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
130 | } |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
131 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
132 | static void* |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
133 | ggp_tcpsocket_connect(void *_gc, const char *host, int port, int is_tls, |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
134 | int is_async, void *priv) |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
135 | { |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
136 | PurpleConnection *gc = _gc; |
| 38139 | 137 | GGPTcpSocketData *data; |
| 138 | GSocketClient *client; | |
| 139 | GError *error = NULL; | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
140 | |
|
36068
e9b9320a985a
Drop PURPLE_CONNECTION_IS_VALID in favor of (temporary) PURPLE_ASSERT_CONNECTION_IS_VALID
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36067
diff
changeset
|
141 | PURPLE_ASSERT_CONNECTION_IS_VALID(gc); |
|
36067
df9f5de00ea2
PurpleSocket: fix a crash
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35358
diff
changeset
|
142 | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
143 | g_return_val_if_fail(host != NULL, NULL); |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
144 | g_return_val_if_fail(is_async, NULL); |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
145 | |
| 34434 | 146 | purple_debug_misc("gg", "ggp_tcpsocket_connect(%p, %s:%d, %s, %p)", |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
147 | gc, host, port, is_tls ? "tls" : "tcp", priv); |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
148 | |
| 38139 | 149 | client = purple_gio_socket_client_new( |
| 150 | purple_connection_get_account(gc), &error); | |
| 151 | ||
| 152 | if (client == NULL) { | |
| 153 | purple_debug_error("gg", "unable to connect: %s", | |
| 154 | error->message); | |
| 155 | g_clear_error(&error); | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
156 | return NULL; |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
157 | } |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
158 | |
| 38139 | 159 | g_socket_client_set_tls(client, is_tls); |
| 160 | ||
| 161 | data = g_new0(GGPTcpSocketData, 1); | |
| 162 | data->cancellable = g_cancellable_new(); | |
| 163 | data->gc = gc; | |
| 164 | data->priv_gg = priv; | |
| 165 | ||
| 166 | g_socket_client_connect_to_host_async(client, host, port, | |
| 167 | data->cancellable, ggp_tcpsocket_connected, data); | |
| 168 | g_object_unref(client); | |
| 169 | ||
| 170 | return data; | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
171 | } |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
172 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
173 | static void |
| 38139 | 174 | ggp_tcpsocket_close(void *_gc, void *_data) |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
175 | { |
| 38139 | 176 | GGPTcpSocketData *data = _data; |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
177 | |
| 38139 | 178 | ggp_tcp_socket_data_free(data); |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
179 | } |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
180 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
181 | static ssize_t |
| 38139 | 182 | ggp_tcpsocket_read(void *_gc, void *_data, unsigned char *buffer, size_t bufsize) |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
183 | { |
| 38139 | 184 | GGPTcpSocketData *data = _data; |
| 185 | GPollableInputStream *input; | |
| 186 | gssize ret; | |
| 187 | GError *error = NULL; | |
| 188 | ||
| 189 | if (data->conn == NULL) { | |
| 190 | return -1; | |
| 191 | } | |
| 192 | ||
| 193 | input = G_POLLABLE_INPUT_STREAM( | |
| 194 | g_io_stream_get_input_stream(G_IO_STREAM(data->conn))); | |
| 195 | ret = g_pollable_input_stream_read_nonblocking(input, | |
| 196 | buffer, bufsize, NULL, &error); | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
197 | |
| 38139 | 198 | if (ret < 0) { |
| 199 | if (g_error_matches(error, | |
| 200 | G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { | |
| 201 | errno = EAGAIN; | |
| 202 | } else { | |
| 203 | purple_debug_error("gg", "socket read error: %s", | |
| 204 | error->message); | |
| 205 | } | |
| 206 | ||
| 207 | g_clear_error(&error); | |
| 208 | } | |
| 209 | ||
| 210 | return ret; | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
211 | } |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
212 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
213 | static ssize_t |
| 38139 | 214 | ggp_tcpsocket_write(void *_gc, void *_data, const unsigned char *data_buf, size_t len) |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
215 | { |
| 38139 | 216 | GGPTcpSocketData *data = _data; |
| 217 | GPollableOutputStream *output; | |
| 218 | gssize ret; | |
| 219 | GError *error = NULL; | |
| 220 | ||
| 221 | if (data->conn == NULL) { | |
| 222 | return -1; | |
| 223 | } | |
| 224 | ||
| 225 | output = G_POLLABLE_OUTPUT_STREAM( | |
| 226 | g_io_stream_get_output_stream(G_IO_STREAM(data->conn))); | |
| 227 | ret = g_pollable_output_stream_write_nonblocking(output, | |
| 228 | data_buf, len, NULL, &error); | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
229 | |
| 38139 | 230 | if (ret < 0) { |
| 231 | if (g_error_matches(error, | |
| 232 | G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { | |
| 233 | errno = EAGAIN; | |
| 234 | } else { | |
| 235 | purple_debug_error("gg", "socket write error: %s", | |
| 236 | error->message); | |
| 237 | } | |
| 238 | ||
| 239 | g_clear_error(&error); | |
| 240 | } | |
| 241 | ||
| 242 | return ret; | |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
243 | } |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
244 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
245 | void |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
246 | ggp_tcpsocket_setup(PurpleConnection *gc, struct gg_login_params *glp) |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
247 | { |
|
37417
b29ee022017f
Require SSL/TLS support. ok'd by elb@
Michael McConville <mmcco@mykolab.com>
parents:
36124
diff
changeset
|
248 | glp->socket_manager_type = GG_SOCKET_MANAGER_TYPE_TLS; |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
249 | glp->socket_manager.cb_data = gc; |
|
34473
fb04c75906e0
Gadu-Gadu: update code for the new libpurple and libgadu APIs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34442
diff
changeset
|
250 | glp->socket_manager.connect_cb = ggp_tcpsocket_connect; |
|
fb04c75906e0
Gadu-Gadu: update code for the new libpurple and libgadu APIs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34442
diff
changeset
|
251 | glp->socket_manager.close_cb = ggp_tcpsocket_close; |
|
fb04c75906e0
Gadu-Gadu: update code for the new libpurple and libgadu APIs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34442
diff
changeset
|
252 | glp->socket_manager.read_cb = ggp_tcpsocket_read; |
|
fb04c75906e0
Gadu-Gadu: update code for the new libpurple and libgadu APIs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34442
diff
changeset
|
253 | glp->socket_manager.write_cb = ggp_tcpsocket_write; |
|
34433
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
254 | } |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
255 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
256 | PurpleInputCondition |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
257 | ggp_tcpsocket_inputcond_gg_to_purple(enum gg_check_t check) |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
258 | { |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
259 | PurpleInputCondition cond = 0; |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
260 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
261 | if (check & GG_CHECK_READ) |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
262 | cond |= PURPLE_INPUT_READ; |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
263 | if (check & GG_CHECK_WRITE) |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
264 | cond |= PURPLE_INPUT_WRITE; |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
265 | |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
266 | return cond; |
|
fa2313e5f320
Gadu-Gadu: use our own proxy/tls connecting code instead of libgadu's
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
267 | } |