Mercurial > pidgin
annotate src/connection.c @ 5738:ec032cb2f9ec
[gaim-migrate @ 6162]
This probably doesn't fix problems when we display high ascii and stuff in
the debug window, but it at least displays them now, I think.. just now it
says it's not valid UTF-8.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Wed, 04 Jun 2003 07:15:17 +0000 |
| parents | 2e9f040f6b66 |
| children | 6ec7b32ab1df |
| rev | line source |
|---|---|
| 5563 | 1 /** |
| 2 * @file connection.c Connection API | |
| 3 * @ingroup core | |
| 4 * | |
| 5 * gaim | |
| 6 * | |
| 7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 5631 | 8 * |
| 5563 | 9 * This program is free software; you can redistribute it and/or modify |
| 10 * it under the terms of the GNU General Public License as published by | |
| 11 * the Free Software Foundation; either version 2 of the License, or | |
| 12 * (at your option) any later version. | |
| 13 * | |
| 14 * This program is distributed in the hope that it will be useful, | |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 * GNU General Public License for more details. | |
| 18 * | |
| 19 * You should have received a copy of the GNU General Public License | |
| 20 * along with this program; if not, write to the Free Software | |
| 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 22 */ | |
| 5717 | 23 |
| 5563 | 24 #include "connection.h" |
| 5717 | 25 #include "debug.h" |
| 26 #include "gaim.h" | |
| 5563 | 27 |
| 28 static GList *connections = NULL; | |
|
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
29 static GList *connections_connecting = NULL; |
| 5563 | 30 static GaimConnectionUiOps *connection_ui_ops = NULL; |
| 31 | |
| 32 GaimConnection * | |
| 33 gaim_connection_new(GaimAccount *account) | |
| 34 { | |
| 35 GaimConnection *gc; | |
| 36 | |
| 37 g_return_val_if_fail(account != NULL, NULL); | |
| 38 | |
| 39 gc = g_new0(GaimConnection, 1); | |
| 40 | |
| 41 gc->prpl = gaim_find_prpl(gaim_account_get_protocol(account)); | |
| 42 | |
| 43 gaim_connection_set_account(gc, account); | |
| 44 gaim_account_set_connection(account, gc); | |
| 45 | |
| 46 return gc; | |
| 47 } | |
| 48 | |
| 49 void | |
| 50 gaim_connection_destroy(GaimConnection *gc) | |
| 51 { | |
| 52 g_return_if_fail(gc != NULL); | |
| 53 | |
| 54 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) { | |
| 55 gaim_connection_disconnect(gc); | |
| 56 | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 if (gc->display_name != NULL) | |
| 61 g_free(gc->display_name); | |
| 62 | |
| 63 if (gc->away != NULL) | |
| 64 g_free(gc->away); | |
| 65 | |
| 66 if (gc->away_state != NULL) | |
| 67 g_free(gc->away_state); | |
| 68 | |
| 69 g_free(gc); | |
| 70 } | |
| 71 | |
| 72 void | |
| 73 gaim_connection_connect(GaimConnection *gc) | |
| 74 { | |
| 75 GaimAccount *account; | |
| 76 GaimConnectionUiOps *ops; | |
| 77 GaimPluginProtocolInfo *prpl_info = NULL; | |
| 78 | |
| 79 g_return_if_fail(gc != NULL); | |
| 80 | |
| 81 ops = gaim_get_connection_ui_ops(); | |
| 82 | |
| 83 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 84 | |
| 85 account = gaim_connection_get_account(gc); | |
| 86 | |
| 87 if ((prpl_info->options & OPT_PROTO_NO_PASSWORD) && | |
| 88 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL) && | |
| 89 gaim_account_get_password(account) == NULL) { | |
| 90 | |
|
5581
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5571
diff
changeset
|
91 gaim_debug(GAIM_DEBUG_INFO, "connection", "Requestin password\n"); |
|
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5571
diff
changeset
|
92 |
| 5563 | 93 if (ops != NULL && ops->request_pass != NULL) |
| 94 ops->request_pass(gc); | |
| 95 | |
| 96 return; | |
| 97 } | |
| 98 | |
| 99 gaim_connection_set_state(gc, GAIM_CONNECTING); | |
| 100 | |
|
5581
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5571
diff
changeset
|
101 gaim_debug(GAIM_DEBUG_INFO, "connection", "Calling serv_login\n"); |
|
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5571
diff
changeset
|
102 |
|
5623
8c895d80159a
[gaim-migrate @ 6030]
Christian Hammond <chipx86@chipx86.com>
parents:
5622
diff
changeset
|
103 connections = g_list_append(connections, gc); |
|
8c895d80159a
[gaim-migrate @ 6030]
Christian Hammond <chipx86@chipx86.com>
parents:
5622
diff
changeset
|
104 |
| 5563 | 105 serv_login(account); |
| 106 } | |
| 107 | |
| 108 void | |
| 109 gaim_connection_disconnect(GaimConnection *gc) | |
| 110 { | |
| 111 GList *wins; | |
| 112 | |
| 113 g_return_if_fail(gc != NULL); | |
| 114 g_return_if_fail(gaim_connection_get_state(gc) != GAIM_DISCONNECTED); | |
| 115 | |
| 116 if (gaim_connection_get_state(gc) != GAIM_CONNECTING) | |
| 117 gaim_blist_remove_account(gaim_connection_get_account(gc)); | |
| 118 | |
| 119 serv_close(gc); | |
| 120 | |
| 121 gaim_connection_set_state(gc, GAIM_DISCONNECTED); | |
| 122 | |
|
5622
70ae81fc802f
[gaim-migrate @ 6029]
Christian Hammond <chipx86@chipx86.com>
parents:
5615
diff
changeset
|
123 connections = g_list_remove(connections, gc); |
|
70ae81fc802f
[gaim-migrate @ 6029]
Christian Hammond <chipx86@chipx86.com>
parents:
5615
diff
changeset
|
124 |
|
5615
6500a6c8d679
[gaim-migrate @ 6022]
Christian Hammond <chipx86@chipx86.com>
parents:
5581
diff
changeset
|
125 gaim_event_broadcast(event_signoff, gc); |
|
6500a6c8d679
[gaim-migrate @ 6022]
Christian Hammond <chipx86@chipx86.com>
parents:
5581
diff
changeset
|
126 system_log(log_signoff, gc, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); |
|
6500a6c8d679
[gaim-migrate @ 6022]
Christian Hammond <chipx86@chipx86.com>
parents:
5581
diff
changeset
|
127 |
| 5563 | 128 /* |
| 129 * XXX This is a hack! Remove this and replace it with a better event | |
| 130 * notification system. | |
| 131 */ | |
| 132 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { | |
|
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5631
diff
changeset
|
133 GaimWindow *win = (GaimWindow *)wins->data; |
| 5563 | 134 gaim_conversation_update(gaim_window_get_conversation_at(win, 0), |
| 135 GAIM_CONV_ACCOUNT_OFFLINE); | |
| 136 } | |
| 137 | |
| 138 gaim_request_close_with_handle(gc); | |
| 139 gaim_notify_close_with_handle(gc); | |
| 140 | |
| 141 update_privacy_connections(); | |
| 142 | |
|
5622
70ae81fc802f
[gaim-migrate @ 6029]
Christian Hammond <chipx86@chipx86.com>
parents:
5615
diff
changeset
|
143 gaim_connection_destroy(gc); |
|
70ae81fc802f
[gaim-migrate @ 6029]
Christian Hammond <chipx86@chipx86.com>
parents:
5615
diff
changeset
|
144 |
| 5563 | 145 /* XXX More UI stuff! */ |
| 146 if (connections != NULL) | |
| 147 return; | |
| 148 | |
| 149 destroy_all_dialogs(); | |
| 150 gaim_blist_destroy(); | |
| 151 | |
| 152 show_login(); | |
| 153 } | |
| 154 | |
| 155 /* | |
| 156 * d:)->-< | |
| 157 * | |
| 158 * d:O-\-< | |
| 159 * | |
| 160 * d:D-/-< | |
| 161 * | |
| 162 * d8D->-< DANCE! | |
| 163 */ | |
| 164 | |
| 165 void | |
| 166 gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state) | |
| 167 { | |
| 168 g_return_if_fail(gc != NULL); | |
| 169 | |
| 170 gc->state = state; | |
| 171 | |
| 172 if (gc->state == GAIM_CONNECTED) { | |
| 173 GaimConnectionUiOps *ops = gaim_get_connection_ui_ops(); | |
| 174 GaimBlistNode *gnode,*bnode; | |
| 175 GList *wins; | |
| 176 GList *add_buds=NULL; | |
| 177 | |
| 178 /* Set the time the account came online */ | |
| 179 time(&gc->login_time); | |
| 180 | |
|
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
181 connections_connecting = g_list_append(connections_connecting, gc); |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
182 |
| 5563 | 183 if (ops != NULL && ops->connected != NULL) |
| 184 ops->connected(gc); | |
| 185 | |
| 186 gaim_blist_show(); | |
| 187 gaim_blist_add_account(gc->account); | |
| 188 | |
| 189 /* I hate this. -- ChipX86 */ | |
| 190 gaim_setup(gc); | |
| 191 | |
| 192 /* | |
| 193 * XXX This is a hack! Remove this and replace it with a better event | |
| 194 * notification system. | |
| 195 */ | |
| 196 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { | |
|
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5631
diff
changeset
|
197 GaimWindow *win = (GaimWindow *)wins->data; |
| 5563 | 198 gaim_conversation_update(gaim_window_get_conversation_at(win, 0), |
| 199 GAIM_CONV_ACCOUNT_ONLINE); | |
| 200 } | |
| 201 | |
| 202 gaim_event_broadcast(event_signon, gc); | |
| 203 system_log(log_signon, gc, NULL, | |
| 204 OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); | |
| 205 | |
| 206 #if 0 | |
| 207 /* away option given? */ | |
| 208 if (opt_away) { | |
| 209 away_on_login(opt_away_arg); | |
| 210 /* don't do it again */ | |
| 211 opt_away = 0; | |
| 212 } else if (awaymessage) { | |
| 213 serv_set_away(gc, GAIM_AWAY_CUSTOM, awaymessage->message); | |
| 214 } | |
| 215 if (opt_away_arg != NULL) { | |
| 216 g_free(opt_away_arg); | |
| 217 opt_away_arg = NULL; | |
| 218 } | |
| 219 #endif | |
| 220 | |
| 221 /* let the prpl know what buddies we pulled out of the local list */ | |
| 222 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
| 223 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 224 continue; | |
| 225 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
| 226 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 227 struct buddy *b = (struct buddy *)bnode; | |
| 228 if(b->account == gc->account) { | |
| 229 add_buds = g_list_append(add_buds, b->name); | |
| 230 } | |
| 231 } | |
| 232 } | |
| 233 } | |
| 234 | |
| 235 if(add_buds) { | |
| 236 serv_add_buddies(gc, add_buds); | |
| 237 g_list_free(add_buds); | |
| 238 } | |
| 239 | |
| 240 serv_set_permit_deny(gc); | |
| 241 } | |
|
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
242 else { |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
243 connections_connecting = g_list_remove(connections_connecting, gc); |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
244 } |
| 5563 | 245 } |
| 246 | |
| 247 void | |
| 248 gaim_connection_set_account(GaimConnection *gc, GaimAccount *account) | |
| 249 { | |
| 250 g_return_if_fail(gc != NULL); | |
| 251 g_return_if_fail(account != NULL); | |
| 252 | |
| 253 gc->account = account; | |
| 254 } | |
| 255 | |
| 256 void | |
| 257 gaim_connection_set_display_name(GaimConnection *gc, const char *name) | |
| 258 { | |
| 259 g_return_if_fail(gc != NULL); | |
| 260 | |
| 261 if (gc->display_name != NULL) | |
| 262 g_free(gc->display_name); | |
| 263 | |
| 264 gc->display_name = (name == NULL ? NULL : g_strdup(name)); | |
| 265 } | |
| 266 | |
| 267 GaimConnectionState | |
| 268 gaim_connection_get_state(const GaimConnection *gc) | |
| 269 { | |
| 270 g_return_val_if_fail(gc != NULL, GAIM_DISCONNECTED); | |
| 271 | |
| 272 return gc->state; | |
| 273 } | |
| 274 | |
| 275 GaimAccount * | |
| 276 gaim_connection_get_account(const GaimConnection *gc) | |
| 277 { | |
| 278 g_return_val_if_fail(gc != NULL, NULL); | |
| 279 | |
| 280 return gc->account; | |
| 281 } | |
| 282 | |
| 283 const char * | |
| 284 gaim_connection_get_display_name(const GaimConnection *gc) | |
| 285 { | |
| 286 g_return_val_if_fail(gc != NULL, NULL); | |
| 287 | |
| 288 return gc->display_name; | |
| 289 } | |
| 290 | |
| 291 void | |
| 292 gaim_connection_update_progress(GaimConnection *gc, const char *text, | |
| 293 size_t step, size_t count) | |
| 294 { | |
| 295 GaimConnectionUiOps *ops; | |
| 296 | |
| 297 g_return_if_fail(gc != NULL); | |
| 298 g_return_if_fail(text != NULL); | |
| 299 g_return_if_fail(step < count); | |
| 300 g_return_if_fail(count > 1); | |
| 301 | |
| 302 ops = gaim_get_connection_ui_ops(); | |
| 303 | |
| 304 if (ops != NULL && ops->connect_progress != NULL) | |
| 305 ops->connect_progress(gc, text, step, count); | |
| 306 } | |
| 307 | |
| 308 void | |
|
5571
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
309 gaim_connection_notice(GaimConnection *gc, const char *text) |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
310 { |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
311 GaimConnectionUiOps *ops; |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
312 |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
313 g_return_if_fail(gc != NULL); |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
314 g_return_if_fail(text != NULL); |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
315 |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
316 ops = gaim_get_connection_ui_ops(); |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
317 |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
318 if (ops != NULL && ops->notice != NULL) |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
319 ops->notice(gc, text); |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
320 } |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
321 |
|
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
322 void |
|
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
323 gaim_connection_error(GaimConnection *gc, const char *text) |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
324 { |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
325 GaimConnectionUiOps *ops; |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
326 |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
327 g_return_if_fail(gc != NULL); |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
328 g_return_if_fail(text != NULL); |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
329 |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
330 ops = gaim_get_connection_ui_ops(); |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
331 |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
332 if (ops != NULL && ops->disconnected != NULL) |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
333 ops->disconnected(gc, text); |
| 5727 | 334 |
| 335 gaim_connection_disconnect(gc); | |
|
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
336 } |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
337 |
|
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
338 void |
| 5563 | 339 gaim_connections_disconnect_all(void) |
| 340 { | |
| 341 GList *l; | |
| 342 | |
|
5624
4cc9e3fa22c4
[gaim-migrate @ 6031]
Christian Hammond <chipx86@chipx86.com>
parents:
5623
diff
changeset
|
343 while ((l = gaim_connections_get_all()) != NULL) |
| 5563 | 344 gaim_connection_destroy(l->data); |
| 345 } | |
| 346 | |
| 347 GList * | |
| 348 gaim_connections_get_all(void) | |
| 349 { | |
| 350 return connections; | |
| 351 } | |
| 352 | |
| 353 void | |
| 354 gaim_set_connection_ui_ops(GaimConnectionUiOps *ops) | |
| 355 { | |
| 356 connection_ui_ops = ops; | |
| 357 } | |
| 358 | |
| 359 GaimConnectionUiOps * | |
| 360 gaim_get_connection_ui_ops(void) | |
| 361 { | |
| 362 return connection_ui_ops; | |
| 363 } | |
| 364 |
