Mercurial > pidgin
annotate src/connection.c @ 10740:94cc67130789
[gaim-migrate @ 12342]
More big changes, yay.
I combined gaim_connection_new and gaim_connection_connect. Earlier
today I realized that it's dumb to have a GaimConnection that isn't
connected.
I'm about to combine gaim_connection_disconnect and
gaim_connection_destroy, as well.
I added a "password" field to GaimConnection.
It holds the password used to login a specific GaimConnection. Now,
when "remember password" is false, account->password is NEVER set.
When the user tries to sign on and Gaim prompts for the password,
it goes directly into the GaimConnection.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 26 Mar 2005 23:25:18 +0000 |
parents | 55af3fa46329 |
children | 4228b6d78506 |
rev | line source |
---|---|
5563 | 1 /** |
2 * @file connection.c Connection API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
5631 | 10 * |
5563 | 11 * This program is free software; you can redistribute it and/or modify |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
25 #include "internal.h" |
10740 | 26 #include "account.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
27 #include "blist.h" |
5563 | 28 #include "connection.h" |
5717 | 29 #include "debug.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
30 #include "log.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
31 #include "notify.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
32 #include "prefs.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
33 #include "request.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
34 #include "server.h" |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
35 #include "signals.h" |
6106 | 36 #include "util.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
37 |
5563 | 38 static GList *connections = NULL; |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
39 static GList *connections_connecting = NULL; |
5563 | 40 static GaimConnectionUiOps *connection_ui_ops = NULL; |
41 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
42 static int connections_handle; |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
43 |
10740 | 44 void |
45 gaim_connection_new(GaimAccount *account, gboolean regist, const char *password) | |
5563 | 46 { |
47 GaimConnection *gc; | |
10740 | 48 GaimPlugin *prpl; |
49 GaimPluginProtocolInfo *prpl_info; | |
5563 | 50 |
10740 | 51 g_return_if_fail(account != NULL); |
52 | |
53 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
54 | |
55 if (prpl != NULL) | |
56 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
57 else { | |
58 gchar *message; | |
59 | |
60 message = g_strdup_printf(_("Missing protocol plugin for %s"), | |
61 gaim_account_get_username(account)); | |
62 gaim_notify_error(NULL, regist ? _("Registration Error") : | |
63 _("Connection Error"), message, NULL); | |
64 g_free(message); | |
65 return; | |
66 } | |
67 | |
68 if (regist) | |
69 { | |
70 if (prpl_info->register_user == NULL) | |
71 return; | |
72 } | |
73 else | |
74 { | |
75 if ((password == NULL) && | |
76 !(prpl_info->options & OPT_PROTO_NO_PASSWORD) && | |
77 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL)) | |
78 { | |
79 gaim_debug_error("connection", "Can not connect to account %s without " | |
80 "a password.\n", gaim_account_get_username(account)); | |
81 return; | |
82 } | |
83 } | |
5563 | 84 |
85 gc = g_new0(GaimConnection, 1); | |
10740 | 86 gc->prpl = prpl; |
87 gc->password = g_strdup(password); | |
5563 | 88 gaim_connection_set_account(gc, account); |
10740 | 89 gaim_connection_set_state(gc, GAIM_CONNECTING); |
90 connections = g_list_append(connections, gc); | |
5563 | 91 gaim_account_set_connection(account, gc); |
92 | |
10740 | 93 gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc); |
94 | |
95 if (regist) | |
96 { | |
97 gaim_debug_info("connection", "Registering. gc = %p\n", gc); | |
98 | |
99 /* set this so we don't auto-reconnect after registering */ | |
100 gc->wants_to_die = TRUE; | |
101 | |
102 prpl_info->register_user(account); | |
103 } | |
104 else | |
105 { | |
106 gaim_debug_info("connection", "Connecting. gc = %p\n", gc); | |
107 | |
108 gaim_signal_emit(gaim_accounts_get_handle(), "account-connecting", account); | |
109 prpl_info->login(account, gaim_account_get_active_status(account)); | |
110 } | |
5563 | 111 } |
112 | |
113 void | |
114 gaim_connection_destroy(GaimConnection *gc) | |
115 { | |
5741
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
116 GaimAccount *account; |
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
117 |
5563 | 118 g_return_if_fail(gc != NULL); |
119 | |
120 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) { | |
121 gaim_connection_disconnect(gc); | |
122 | |
123 return; | |
124 } | |
125 | |
10301 | 126 gaim_debug_info("connection", "Destroying connection %p\n", gc); |
5930
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
127 |
5741
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
128 account = gaim_connection_get_account(gc); |
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
129 gaim_account_set_connection(account, NULL); |
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
130 |
10740 | 131 if (gc->password != NULL) |
132 g_free(gc->password); | |
133 | |
5563 | 134 if (gc->display_name != NULL) |
135 g_free(gc->display_name); | |
136 | |
6393 | 137 if (gc->disconnect_timeout) |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
138 gaim_timeout_remove(gc->disconnect_timeout); |
6393 | 139 |
5563 | 140 g_free(gc); |
141 } | |
142 | |
143 void | |
144 gaim_connection_disconnect(GaimConnection *gc) | |
145 { | |
5926
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
146 GaimAccount *account; |
5563 | 147 GList *wins; |
10052 | 148 GaimPresence *presence = NULL; |
5563 | 149 |
150 g_return_if_fail(gc != NULL); | |
151 | |
5926
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
152 account = gaim_connection_get_account(gc); |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
153 |
10384 | 154 if (!account->disconnecting) { |
5926
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
155 gaim_account_disconnect(account); |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
156 return; |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
157 } |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
158 |
10301 | 159 gaim_debug_info("connection", "Disconnecting connection %p\n", gc); |
5930
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
160 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
161 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) { |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
162 if (gaim_connection_get_state(gc) != GAIM_CONNECTING) |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
163 gaim_blist_remove_account(gaim_connection_get_account(gc)); |
5563 | 164 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
165 gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
166 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
167 serv_close(gc); |
5563 | 168 |
6533 | 169 connections = g_list_remove(connections, gc); |
170 | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5788
diff
changeset
|
171 gaim_connection_set_state(gc, GAIM_DISCONNECTED); |
5563 | 172 |
7431 | 173 /* LOG system_log(log_signoff, gc, NULL, |
174 OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
175 gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
176 |
10052 | 177 presence = gaim_account_get_presence(account); |
178 if (gaim_presence_is_online(presence) == TRUE) | |
179 gaim_presence_set_status_active(presence, "offline", TRUE); | |
5615
6500a6c8d679
[gaim-migrate @ 6022]
Christian Hammond <chipx86@chipx86.com>
parents:
5581
diff
changeset
|
180 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
181 /* |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
182 * XXX This is a hack! Remove this and replace it with a better event |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
183 * notification system. |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
184 */ |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
185 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
186 GaimConvWindow *win = (GaimConvWindow *)wins->data; |
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
187 gaim_conversation_update(gaim_conv_window_get_conversation_at(win, 0), |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
188 GAIM_CONV_ACCOUNT_OFFLINE); |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
189 } |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
190 |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
191 gaim_request_close_with_handle(gc); |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
192 gaim_notify_close_with_handle(gc); |
5563 | 193 } |
194 | |
5622
70ae81fc802f
[gaim-migrate @ 6029]
Christian Hammond <chipx86@chipx86.com>
parents:
5615
diff
changeset
|
195 gaim_connection_destroy(gc); |
5563 | 196 } |
197 | |
6029 | 198 gboolean |
199 gaim_connection_disconnect_cb(gpointer data) | |
200 { | |
6076 | 201 GaimAccount *account = data; |
9848 | 202 |
10738 | 203 gaim_account_disconnect(account); |
6029 | 204 |
205 return FALSE; | |
206 } | |
207 | |
5563 | 208 /* |
8130
ff88d4cbf4db
[gaim-migrate @ 8835]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
209 * d:)->-< |
5563 | 210 * |
211 * d:O-\-< | |
8130
ff88d4cbf4db
[gaim-migrate @ 8835]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
212 * |
5563 | 213 * d:D-/-< |
214 * | |
215 * d8D->-< DANCE! | |
216 */ | |
217 | |
218 void | |
219 gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state) | |
220 { | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
221 GaimConnectionUiOps *ops; |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
222 |
5563 | 223 g_return_if_fail(gc != NULL); |
224 | |
5784
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
225 if (gc->state == state) |
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
226 return; |
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
227 |
5563 | 228 gc->state = state; |
229 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
230 ops = gaim_connections_get_ui_ops(); |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
231 |
5905
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
232 if (gc->state == GAIM_CONNECTING) { |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
233 connections_connecting = g_list_append(connections_connecting, gc); |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
234 } |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
235 else { |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
236 connections_connecting = g_list_remove(connections_connecting, gc); |
5905
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
237 } |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
238 |
5563 | 239 if (gc->state == GAIM_CONNECTED) { |
6695 | 240 GaimBlistNode *gnode,*cnode,*bnode; |
5563 | 241 GList *wins; |
9285 | 242 GList *add_buds = NULL; |
10052 | 243 GaimAccount *account; |
244 GaimPresence *presence; | |
245 | |
246 account = gaim_connection_get_account(gc); | |
247 presence = gaim_account_get_presence(account); | |
5563 | 248 |
249 /* Set the time the account came online */ | |
250 time(&gc->login_time); | |
251 | |
10301 | 252 if (gaim_prefs_get_bool("/core/logging/log_system") && |
253 gaim_prefs_get_bool("/core/logging/log_own_states")){ | |
254 GaimLog *log = gaim_account_get_log(account); | |
255 char *msg = g_strdup_printf("+++ %s signed on", | |
256 gaim_account_get_username(account)); | |
257 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
258 gaim_account_get_username(account), gc->login_time, | |
259 msg); | |
260 g_free(msg); | |
261 } | |
262 | |
5563 | 263 if (ops != NULL && ops->connected != NULL) |
264 ops->connected(gc); | |
265 | |
266 gaim_blist_show(); | |
8573 | 267 gaim_blist_add_account(account); |
5563 | 268 |
269 /* | |
270 * XXX This is a hack! Remove this and replace it with a better event | |
271 * notification system. | |
272 */ | |
273 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
274 GaimConvWindow *win = (GaimConvWindow *)wins->data; |
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
275 gaim_conversation_update(gaim_conv_window_get_conversation_at(win, 0), |
5563 | 276 GAIM_CONV_ACCOUNT_ONLINE); |
277 } | |
278 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
279 gaim_signal_emit(gaim_connections_get_handle(), "signed-on", gc); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
280 |
5563 | 281 /* let the prpl know what buddies we pulled out of the local list */ |
10301 | 282 /* XXX - Remove this and let the prpl take care of it itself? */ |
5563 | 283 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
284 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
285 continue; | |
6695 | 286 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
287 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
288 continue; | |
289 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
290 GaimBuddy *b; | |
291 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
292 continue; | |
293 | |
294 b = (GaimBuddy *)bnode; | |
5563 | 295 if(b->account == gc->account) { |
9285 | 296 add_buds = g_list_append(add_buds, b); |
5563 | 297 } |
298 } | |
299 } | |
300 } | |
301 | |
302 if(add_buds) { | |
303 serv_add_buddies(gc, add_buds); | |
304 g_list_free(add_buds); | |
305 } | |
306 | |
307 serv_set_permit_deny(gc); | |
308 } | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
309 else if (gc->state == GAIM_DISCONNECTED) { |
8573 | 310 GaimAccount *account = gaim_connection_get_account(gc); |
311 | |
312 if(gaim_prefs_get_bool("/core/logging/log_system") && | |
313 gaim_prefs_get_bool("/core/logging/log_own_states")){ | |
314 GaimLog *log = gaim_account_get_log(account); | |
315 char *msg = g_strdup_printf("+++ %s signed off", | |
316 gaim_account_get_username(account)); | |
317 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
318 gaim_account_get_username(account), time(NULL), | |
319 msg); | |
9190
9e3289499977
[gaim-migrate @ 9985]
Christian Hammond <chipx86@chipx86.com>
parents:
9019
diff
changeset
|
320 g_free(msg); |
8573 | 321 } |
322 | |
323 gaim_account_destroy_log(account); | |
324 | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
325 if (ops != NULL && ops->disconnected != NULL) |
9190
9e3289499977
[gaim-migrate @ 9985]
Christian Hammond <chipx86@chipx86.com>
parents:
9019
diff
changeset
|
326 ops->disconnected(gc); |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
327 } |
5563 | 328 } |
329 | |
330 void | |
331 gaim_connection_set_account(GaimConnection *gc, GaimAccount *account) | |
332 { | |
333 g_return_if_fail(gc != NULL); | |
334 g_return_if_fail(account != NULL); | |
335 | |
336 gc->account = account; | |
337 } | |
338 | |
339 void | |
340 gaim_connection_set_display_name(GaimConnection *gc, const char *name) | |
341 { | |
342 g_return_if_fail(gc != NULL); | |
343 | |
344 if (gc->display_name != NULL) | |
345 g_free(gc->display_name); | |
346 | |
347 gc->display_name = (name == NULL ? NULL : g_strdup(name)); | |
348 } | |
349 | |
350 GaimConnectionState | |
351 gaim_connection_get_state(const GaimConnection *gc) | |
352 { | |
353 g_return_val_if_fail(gc != NULL, GAIM_DISCONNECTED); | |
354 | |
355 return gc->state; | |
356 } | |
357 | |
358 GaimAccount * | |
359 gaim_connection_get_account(const GaimConnection *gc) | |
360 { | |
361 g_return_val_if_fail(gc != NULL, NULL); | |
362 | |
363 return gc->account; | |
364 } | |
365 | |
366 const char * | |
10740 | 367 gaim_connection_get_password(const GaimConnection *gc) |
368 { | |
369 g_return_val_if_fail(gc != NULL, NULL); | |
370 | |
371 return gc->password; | |
372 } | |
373 | |
374 const char * | |
5563 | 375 gaim_connection_get_display_name(const GaimConnection *gc) |
376 { | |
377 g_return_val_if_fail(gc != NULL, NULL); | |
378 | |
379 return gc->display_name; | |
380 } | |
381 | |
382 void | |
383 gaim_connection_update_progress(GaimConnection *gc, const char *text, | |
384 size_t step, size_t count) | |
385 { | |
386 GaimConnectionUiOps *ops; | |
387 | |
388 g_return_if_fail(gc != NULL); | |
389 g_return_if_fail(text != NULL); | |
390 g_return_if_fail(step < count); | |
391 g_return_if_fail(count > 1); | |
392 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
393 ops = gaim_connections_get_ui_ops(); |
5563 | 394 |
395 if (ops != NULL && ops->connect_progress != NULL) | |
396 ops->connect_progress(gc, text, step, count); | |
397 } | |
398 | |
399 void | |
5571
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
400 gaim_connection_notice(GaimConnection *gc, const char *text) |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
401 { |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
402 GaimConnectionUiOps *ops; |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
403 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
404 g_return_if_fail(gc != NULL); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
405 g_return_if_fail(text != NULL); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
406 |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
407 ops = gaim_connections_get_ui_ops(); |
5571
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
408 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
409 if (ops != NULL && ops->notice != NULL) |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
410 ops->notice(gc, text); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
411 } |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
412 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
413 void |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
414 gaim_connection_error(GaimConnection *gc, const char *text) |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
415 { |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
416 GaimConnectionUiOps *ops; |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
417 |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
418 g_return_if_fail(gc != NULL); |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
419 g_return_if_fail(text != NULL); |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
420 |
6393 | 421 /* If we've already got one error, we don't need any more */ |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
422 if (gc->disconnect_timeout) |
6393 | 423 return; |
424 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
425 ops = gaim_connections_get_ui_ops(); |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
426 |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
427 if (ops != NULL) { |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
428 if (ops->report_disconnect != NULL) |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
429 ops->report_disconnect(gc, text); |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
430 } |
5727 | 431 |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8131
diff
changeset
|
432 gc->disconnect_timeout = gaim_timeout_add(0, gaim_connection_disconnect_cb, |
6076 | 433 gaim_connection_get_account(gc)); |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
434 } |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
435 |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
436 void |
5563 | 437 gaim_connections_disconnect_all(void) |
438 { | |
439 GList *l; | |
6113 | 440 GaimConnection *gc; |
5563 | 441 |
6113 | 442 while ((l = gaim_connections_get_all()) != NULL) { |
443 gc = l->data; | |
444 gc->wants_to_die = TRUE; | |
445 gaim_connection_destroy(gc); | |
446 } | |
5563 | 447 } |
448 | |
449 GList * | |
450 gaim_connections_get_all(void) | |
451 { | |
452 return connections; | |
453 } | |
454 | |
5788
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
455 GList * |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
456 gaim_connections_get_connecting(void) |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
457 { |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
458 return connections_connecting; |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
459 } |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
460 |
5563 | 461 void |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
462 gaim_connections_set_ui_ops(GaimConnectionUiOps *ops) |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
463 { |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
464 connection_ui_ops = ops; |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
465 } |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
466 |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
467 GaimConnectionUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
468 gaim_connections_get_ui_ops(void) |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
469 { |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
470 return connection_ui_ops; |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
471 } |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
472 |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
473 void |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
474 gaim_connections_init(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
475 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
476 void *handle = gaim_connections_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
477 |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
478 gaim_signal_register(handle, "signing-on", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
479 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
480 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6597
fe569b675cd2
[gaim-migrate @ 7121]
Christian Hammond <chipx86@chipx86.com>
parents:
6581
diff
changeset
|
481 GAIM_SUBTYPE_CONNECTION)); |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
482 |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
483 gaim_signal_register(handle, "signed-on", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
484 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
485 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6597
fe569b675cd2
[gaim-migrate @ 7121]
Christian Hammond <chipx86@chipx86.com>
parents:
6581
diff
changeset
|
486 GAIM_SUBTYPE_CONNECTION)); |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
487 |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
488 gaim_signal_register(handle, "signing-off", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
489 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
490 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6597
fe569b675cd2
[gaim-migrate @ 7121]
Christian Hammond <chipx86@chipx86.com>
parents:
6581
diff
changeset
|
491 GAIM_SUBTYPE_CONNECTION)); |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
492 |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
493 gaim_signal_register(handle, "signed-off", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
494 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
495 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6597
fe569b675cd2
[gaim-migrate @ 7121]
Christian Hammond <chipx86@chipx86.com>
parents:
6581
diff
changeset
|
496 GAIM_SUBTYPE_CONNECTION)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
497 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
498 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
499 void |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
500 gaim_connections_uninit(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
501 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
502 gaim_signals_unregister_by_instance(gaim_connections_get_handle()); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
503 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
504 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
505 void * |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
506 gaim_connections_get_handle(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
507 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
508 return &connections_handle; |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
509 } |