Mercurial > pidgin.yaz
comparison src/server.c @ 6485:70d5122bc3ff
[gaim-migrate @ 6999]
Removed the old event system and replaced it with a much better signal
system. There will most likely be some bugs in this, but it seems to be
working for now. Plugins can now generate their own signals, and other
plugins can find those plugins and connect to them. This could give
plugins a form of IPC. It's also useful for other things. It's rather
flexible, except for the damn marshalling, but there's no way around that
that I or the glib people can see.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 18 Aug 2003 01:03:43 +0000 |
parents | b808f9734879 |
children | b6f7fcafc908 |
comparison
equal
deleted
inserted
replaced
6484:5ced8e111473 | 6485:70d5122bc3ff |
---|---|
26 #include "notify.h" | 26 #include "notify.h" |
27 #include "pounce.h" | 27 #include "pounce.h" |
28 #include "prefs.h" | 28 #include "prefs.h" |
29 #include "prpl.h" | 29 #include "prpl.h" |
30 #include "request.h" | 30 #include "request.h" |
31 #include "signals.h" | |
31 #include "server.h" | 32 #include "server.h" |
32 #include "sound.h" | 33 #include "sound.h" |
33 #include "util.h" | 34 #include "util.h" |
34 | 35 |
35 /* XXX UI Stuff */ | 36 /* XXX UI Stuff */ |
59 | 60 |
60 gaim_debug(GAIM_DEBUG_INFO, "server", | 61 gaim_debug(GAIM_DEBUG_INFO, "server", |
61 PACKAGE " " VERSION " logging in %s using %s\n", | 62 PACKAGE " " VERSION " logging in %s using %s\n", |
62 account->username, p->info->name); | 63 account->username, p->info->name); |
63 | 64 |
64 gaim_event_broadcast(event_connecting, account); | 65 gaim_signal_emit(gaim_accounts_get_handle(), |
66 "account-connecting", account); | |
65 prpl_info->login(account); | 67 prpl_info->login(account); |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 static gboolean send_keepalive(gpointer d) | 71 static gboolean send_keepalive(gpointer d) |
354 | 356 |
355 | 357 |
356 void serv_set_away(GaimConnection *gc, const char *state, const char *message) | 358 void serv_set_away(GaimConnection *gc, const char *state, const char *message) |
357 { | 359 { |
358 GaimPluginProtocolInfo *prpl_info = NULL; | 360 GaimPluginProtocolInfo *prpl_info = NULL; |
361 GaimAccount *account; | |
359 | 362 |
360 if (gc->away_state == NULL && state == NULL && | 363 if (gc->away_state == NULL && state == NULL && |
361 gc->away == NULL && message == NULL) { | 364 gc->away == NULL && message == NULL) { |
362 | 365 |
363 return; | 366 return; |
372 } | 375 } |
373 | 376 |
374 if (gc != NULL && gc->prpl != NULL) | 377 if (gc != NULL && gc->prpl != NULL) |
375 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | 378 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
376 | 379 |
380 account = gaim_connection_get_account(gc); | |
381 | |
377 if (prpl_info && prpl_info->set_away) { | 382 if (prpl_info && prpl_info->set_away) { |
378 if (gc->away_state) { | 383 if (gc->away_state) { |
379 g_free(gc->away_state); | 384 g_free(gc->away_state); |
380 gc->away_state = NULL; | 385 gc->away_state = NULL; |
381 } | 386 } |
384 | 389 |
385 if (gc->away && state) { | 390 if (gc->away && state) { |
386 gc->away_state = g_strdup(state); | 391 gc->away_state = g_strdup(state); |
387 } | 392 } |
388 | 393 |
389 gaim_event_broadcast(event_away, gc, state, message); | 394 gaim_signal_emit(gaim_accounts_get_handle(), "account-away", |
390 | 395 account, state, message); |
391 } | 396 } |
392 | 397 |
393 /* New away message... Clear out the record of sent autoresponses */ | 398 /* New away message... Clear out the record of sent autoresponses */ |
394 flush_last_auto_responses(gc); | 399 flush_last_auto_responses(gc); |
395 | 400 |
409 } | 414 } |
410 | 415 |
411 void serv_set_info(GaimConnection *g, const char *info) | 416 void serv_set_info(GaimConnection *g, const char *info) |
412 { | 417 { |
413 GaimPluginProtocolInfo *prpl_info = NULL; | 418 GaimPluginProtocolInfo *prpl_info = NULL; |
414 | 419 GaimAccount *account; |
415 if (g != NULL && g->prpl != NULL) | 420 |
416 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl); | 421 if (g != NULL && g->prpl != NULL) |
417 | 422 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl); |
418 if (prpl_info && g_list_find(gaim_connections_get_all(), g) && prpl_info->set_info) { | 423 |
419 if (gaim_event_broadcast(event_set_info, g, info)) | 424 if (prpl_info && g_list_find(gaim_connections_get_all(), g) && |
425 prpl_info->set_info) { | |
426 | |
427 account = gaim_connection_get_account(g); | |
428 | |
429 if (gaim_signal_emit_return_1(gaim_accounts_get_handle(), | |
430 "account-setting-info", account, info)) | |
420 return; | 431 return; |
421 | 432 |
422 prpl_info->set_info(g, info); | 433 prpl_info->set_info(g, info); |
434 | |
435 gaim_signal_emit(gaim_accounts_get_handle(), | |
436 "account-set-info", account, info); | |
423 } | 437 } |
424 } | 438 } |
425 | 439 |
426 void serv_change_passwd(GaimConnection *g, const char *orig, const char *new) | 440 void serv_change_passwd(GaimConnection *g, const char *orig, const char *new) |
427 { | 441 { |
676 } | 690 } |
677 | 691 |
678 void serv_chat_invite(GaimConnection *g, int id, const char *message, const char *name) | 692 void serv_chat_invite(GaimConnection *g, int id, const char *message, const char *name) |
679 { | 693 { |
680 GaimPluginProtocolInfo *prpl_info = NULL; | 694 GaimPluginProtocolInfo *prpl_info = NULL; |
695 GaimConversation *conv; | |
681 char *buffy = message && *message ? g_strdup(message) : NULL; | 696 char *buffy = message && *message ? g_strdup(message) : NULL; |
682 | 697 |
683 if (g != NULL && g->prpl != NULL) | 698 conv = gaim_find_chat(g, id); |
684 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl); | 699 |
685 | 700 if (conv == NULL) |
686 gaim_event_broadcast(event_chat_send_invite, g, id, name, &buffy); | 701 return; |
702 | |
703 if (g != NULL && g->prpl != NULL) | |
704 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(g->prpl); | |
705 | |
706 gaim_signal_emit(gaim_conversations_get_handle(), "chat-inviting-user", | |
707 conv, name, &buffy); | |
687 | 708 |
688 if (prpl_info && g_list_find(gaim_connections_get_all(), g) && prpl_info->chat_invite) | 709 if (prpl_info && g_list_find(gaim_connections_get_all(), g) && prpl_info->chat_invite) |
689 prpl_info->chat_invite(g, id, buffy, name); | 710 prpl_info->chat_invite(g, id, buffy, name); |
711 | |
712 gaim_signal_emit(gaim_conversations_get_handle(), "chat-invited-user", | |
713 conv, name, buffy); | |
690 | 714 |
691 if (buffy) | 715 if (buffy) |
692 g_free(buffy); | 716 g_free(buffy); |
693 } | 717 } |
694 | 718 |
829 */ | 853 */ |
830 if (len < 0) { | 854 if (len < 0) { |
831 buffy = g_malloc(MAX(strlen(msg) + 1, BUF_LONG)); | 855 buffy = g_malloc(MAX(strlen(msg) + 1, BUF_LONG)); |
832 strcpy(buffy, msg); | 856 strcpy(buffy, msg); |
833 angel = g_strdup(who); | 857 angel = g_strdup(who); |
834 plugin_return = gaim_event_broadcast(event_im_recv, gc, &angel, &buffy, &flags); | 858 |
859 plugin_return = GPOINTER_TO_INT( | |
860 gaim_signal_emit_return_1(gaim_conversations_get_handle(), | |
861 "received-im-msg", | |
862 cnv, &angel, &buffy, &flags)); | |
835 | 863 |
836 if (!buffy || !angel || plugin_return) { | 864 if (!buffy || !angel || plugin_return) { |
837 if (buffy) | 865 if (buffy) |
838 g_free(buffy); | 866 g_free(buffy); |
839 if (angel) | 867 if (angel) |
1047 away | WFLAG_RECV, mtime); | 1075 away | WFLAG_RECV, mtime); |
1048 gaim_window_flash(gaim_conversation_get_window(cnv)); | 1076 gaim_window_flash(gaim_conversation_get_window(cnv)); |
1049 } | 1077 } |
1050 } | 1078 } |
1051 | 1079 |
1052 gaim_event_broadcast(event_im_displayed_rcvd, gc, name, message, flags, mtime); | |
1053 g_free(name); | 1080 g_free(name); |
1054 g_free(message); | 1081 g_free(message); |
1055 } | 1082 } |
1056 | 1083 |
1057 | 1084 |
1095 gaim_blist_save(); | 1122 gaim_blist_save(); |
1096 } | 1123 } |
1097 | 1124 |
1098 if (!b->idle && idle) { | 1125 if (!b->idle && idle) { |
1099 gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_IDLE); | 1126 gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_IDLE); |
1100 gaim_event_broadcast(event_buddy_idle, gc, b->name); | 1127 gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle", account, b); |
1101 system_log(log_idle, gc, b, OPT_LOG_BUDDY_IDLE); | 1128 system_log(log_idle, gc, b, OPT_LOG_BUDDY_IDLE); |
1102 } else if (b->idle && !idle) { | 1129 } else if (b->idle && !idle) { |
1103 gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_IDLE_RETURN); | 1130 gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_IDLE_RETURN); |
1104 gaim_event_broadcast(event_buddy_unidle, gc, b->name); | 1131 gaim_signal_emit(gaim_blist_get_handle(), "buddy-unidle", account, b); |
1105 system_log(log_unidle, gc, b, OPT_LOG_BUDDY_IDLE); | 1132 system_log(log_unidle, gc, b, OPT_LOG_BUDDY_IDLE); |
1106 } | 1133 } |
1107 | 1134 |
1108 gaim_blist_update_buddy_idle(b, idle); | 1135 gaim_blist_update_buddy_idle(b, idle); |
1109 gaim_blist_update_buddy_evil(b, evil); | 1136 gaim_blist_update_buddy_evil(b, evil); |
1192 | 1219 |
1193 | 1220 |
1194 void serv_got_eviled(GaimConnection *gc, const char *name, int lev) | 1221 void serv_got_eviled(GaimConnection *gc, const char *name, int lev) |
1195 { | 1222 { |
1196 char buf2[1024]; | 1223 char buf2[1024]; |
1197 | 1224 GaimAccount *account; |
1198 gaim_event_broadcast(event_warned, gc, name, lev); | 1225 |
1226 account = gaim_connection_get_account(gc); | |
1227 | |
1228 gaim_signal_emit(gaim_accounts_get_handle(), "account-warned", | |
1229 account, name, lev); | |
1199 | 1230 |
1200 if (gc->evil >= lev) { | 1231 if (gc->evil >= lev) { |
1201 gc->evil = lev; | 1232 gc->evil = lev; |
1202 return; | 1233 return; |
1203 } | 1234 } |
1229 gaim_im_set_typing_state(im, state); | 1260 gaim_im_set_typing_state(im, state); |
1230 gaim_im_update_typing(im); | 1261 gaim_im_update_typing(im); |
1231 | 1262 |
1232 b = gaim_find_buddy(gc->account, name); | 1263 b = gaim_find_buddy(gc->account, name); |
1233 | 1264 |
1234 gaim_event_broadcast(event_got_typing, gc, name); | 1265 gaim_signal_emit(gaim_conversations_get_handle(), "buddy-typing", cnv); |
1235 | 1266 |
1236 if (b != NULL) { | 1267 if (b != NULL) { |
1237 if (state == GAIM_TYPING) | 1268 if (state == GAIM_TYPING) |
1238 gaim_pounce_execute(gc->account, name, GAIM_POUNCE_TYPING); | 1269 gaim_pounce_execute(gc->account, name, GAIM_POUNCE_TYPING); |
1239 else | 1270 else |
1296 char buf2[BUF_LONG]; | 1327 char buf2[BUF_LONG]; |
1297 struct chat_invite_data *cid = g_new0(struct chat_invite_data, 1); | 1328 struct chat_invite_data *cid = g_new0(struct chat_invite_data, 1); |
1298 | 1329 |
1299 account = gaim_connection_get_account(gc); | 1330 account = gaim_connection_get_account(gc); |
1300 | 1331 |
1301 gaim_event_broadcast(event_chat_invited, gc, who, name, message); | 1332 gaim_signal_emit(gaim_conversations_get_handle(), |
1333 "chat-invited", account, who, name, message); | |
1302 | 1334 |
1303 if (message) | 1335 if (message) |
1304 g_snprintf(buf2, sizeof(buf2), | 1336 g_snprintf(buf2, sizeof(buf2), |
1305 _("User '%s' invites %s to buddy chat room: '%s'\n%s"), | 1337 _("User '%s' invites %s to buddy chat room: '%s'\n%s"), |
1306 who, gaim_account_get_username(account), name, message); | 1338 who, gaim_account_get_username(account), name, message); |
1319 } | 1351 } |
1320 | 1352 |
1321 GaimConversation *serv_got_joined_chat(GaimConnection *gc, | 1353 GaimConversation *serv_got_joined_chat(GaimConnection *gc, |
1322 int id, const char *name) | 1354 int id, const char *name) |
1323 { | 1355 { |
1324 GaimConversation *b; | 1356 GaimConversation *conv; |
1325 GaimChat *chat; | 1357 GaimChat *chat; |
1326 | 1358 GaimAccount *account; |
1327 b = gaim_conversation_new(GAIM_CONV_CHAT, gc->account, name); | 1359 |
1328 chat = GAIM_CHAT(b); | 1360 account = gaim_connection_get_account(gc); |
1329 | 1361 |
1330 gc->buddy_chats = g_slist_append(gc->buddy_chats, b); | 1362 conv = gaim_conversation_new(GAIM_CONV_CHAT, account, name); |
1363 chat = GAIM_CHAT(conv); | |
1364 | |
1365 gc->buddy_chats = g_slist_append(gc->buddy_chats, conv); | |
1331 | 1366 |
1332 gaim_chat_set_id(chat, id); | 1367 gaim_chat_set_id(chat, id); |
1333 | 1368 |
1334 /* TODO Move this to UI logging code! */ | 1369 /* TODO Move this to UI logging code! */ |
1335 if (gaim_prefs_get_bool("/gaim/gtk/logging/log_chats") || | 1370 if (gaim_prefs_get_bool("/gaim/gtk/logging/log_chats") || |
1336 find_log_info(gaim_conversation_get_name(b))) { | 1371 find_log_info(gaim_conversation_get_name(conv))) { |
1337 | 1372 |
1338 FILE *fd; | 1373 FILE *fd; |
1339 char *filename; | 1374 char *filename; |
1340 | 1375 |
1341 filename = (char *)malloc(100); | 1376 filename = (char *)malloc(100); |
1342 g_snprintf(filename, 100, "%s.chat", gaim_conversation_get_name(b)); | 1377 g_snprintf(filename, 100, "%s.chat", gaim_conversation_get_name(conv)); |
1343 | 1378 |
1344 fd = open_log_file(filename, TRUE); | 1379 fd = open_log_file(filename, TRUE); |
1345 | 1380 |
1346 if (fd) { | 1381 if (fd) { |
1347 if (!gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) | 1382 if (!gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) |
1354 fclose(fd); | 1389 fclose(fd); |
1355 } | 1390 } |
1356 free(filename); | 1391 free(filename); |
1357 } | 1392 } |
1358 | 1393 |
1359 gaim_window_show(gaim_conversation_get_window(b)); | 1394 gaim_window_show(gaim_conversation_get_window(conv)); |
1360 gaim_window_switch_conversation(gaim_conversation_get_window(b), | 1395 gaim_window_switch_conversation(gaim_conversation_get_window(conv), |
1361 gaim_conversation_get_index(b)); | 1396 gaim_conversation_get_index(conv)); |
1362 | 1397 |
1363 gaim_event_broadcast(event_chat_join, gc, id, name); | 1398 gaim_signal_emit(gaim_conversations_get_handle(), "chat-joined", conv); |
1364 | 1399 |
1365 return b; | 1400 return conv; |
1366 } | 1401 } |
1367 | 1402 |
1368 void serv_got_chat_left(GaimConnection *g, int id) | 1403 void serv_got_chat_left(GaimConnection *g, int id) |
1369 { | 1404 { |
1370 GSList *bcs; | 1405 GSList *bcs; |
1371 GaimConversation *conv = NULL; | 1406 GaimConversation *conv = NULL; |
1372 GaimChat *chat = NULL; | 1407 GaimChat *chat = NULL; |
1408 GaimAccount *account; | |
1409 | |
1410 account = gaim_connection_get_account(g); | |
1373 | 1411 |
1374 for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) { | 1412 for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) { |
1375 conv = (GaimConversation *)bcs->data; | 1413 conv = (GaimConversation *)bcs->data; |
1376 | 1414 |
1377 chat = GAIM_CHAT(conv); | 1415 chat = GAIM_CHAT(conv); |
1383 } | 1421 } |
1384 | 1422 |
1385 if (!conv) | 1423 if (!conv) |
1386 return; | 1424 return; |
1387 | 1425 |
1388 gaim_event_broadcast(event_chat_leave, g, gaim_chat_get_id(chat)); | 1426 gaim_signal_emit(gaim_conversations_get_handle(), "chat-left", conv); |
1389 | 1427 |
1390 gaim_debug(GAIM_DEBUG_INFO, "server", "Leaving room: %s\n", | 1428 gaim_debug(GAIM_DEBUG_INFO, "server", "Leaving room: %s\n", |
1391 gaim_conversation_get_name(conv)); | 1429 gaim_conversation_get_name(conv)); |
1392 | 1430 |
1393 g->buddy_chats = g_slist_remove(g->buddy_chats, conv); | 1431 g->buddy_chats = g_slist_remove(g->buddy_chats, conv); |
1429 */ | 1467 */ |
1430 | 1468 |
1431 buffy = g_malloc(MAX(strlen(message) + 1, BUF_LONG)); | 1469 buffy = g_malloc(MAX(strlen(message) + 1, BUF_LONG)); |
1432 strcpy(buffy, message); | 1470 strcpy(buffy, message); |
1433 angel = g_strdup(who); | 1471 angel = g_strdup(who); |
1434 plugin_return = gaim_event_broadcast(event_chat_recv, g, gaim_chat_get_id(chat), | 1472 |
1435 &angel, &buffy); | 1473 plugin_return = GPOINTER_TO_INT( |
1474 gaim_signal_emit_return_1(gaim_conversations_get_handle(), | |
1475 "received-chat-msg", | |
1476 conv, &angel, &buffy)); | |
1436 | 1477 |
1437 if (!buffy || !angel || plugin_return) { | 1478 if (!buffy || !angel || plugin_return) { |
1438 if (buffy) | 1479 if (buffy) |
1439 g_free(buffy); | 1480 g_free(buffy); |
1440 if (angel) | 1481 if (angel) |