Mercurial > pidgin.yaz
comparison libpurple/protocols/oscar/oscar.c @ 15624:71af5b6209d5
uri-handler support for AIM/ICQ, Yahoo and MSN
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sun, 11 Feb 2007 21:58:50 +0000 |
parents | a2411e8dbe2d |
children | 3548e64b0245 |
comparison
equal
deleted
inserted
replaced
15623:a2411e8dbe2d | 15624:71af5b6209d5 |
---|---|
6512 od = (OscarData *)gc->proto_data; | 6512 od = (OscarData *)gc->proto_data; |
6513 | 6513 |
6514 return (od->icq && aim_sn_is_icq(gaim_account_get_username(account))); | 6514 return (od->icq && aim_sn_is_icq(gaim_account_get_username(account))); |
6515 } | 6515 } |
6516 | 6516 |
6517 /* TODO: Find somewhere to put this instead of including it in a bunch of places. | |
6518 * Maybe just change gaim_accounts_find() to return anything for the prpl if there is no acct_id. | |
6519 */ | |
6520 static GaimAccount *find_acct(const char *prpl, const char *acct_id) | |
6521 { | |
6522 GaimAccount *acct = NULL; | |
6523 | |
6524 /* If we have a specific acct, use it */ | |
6525 if (acct_id) { | |
6526 acct = gaim_accounts_find(acct_id, prpl); | |
6527 if (acct && !gaim_account_is_connected(acct)) | |
6528 acct = NULL; | |
6529 } else { /* Otherwise find an active account for the protocol */ | |
6530 GList *l = gaim_accounts_get_all(); | |
6531 while (l) { | |
6532 if (!strcmp(prpl, gaim_account_get_protocol_id(l->data)) | |
6533 && gaim_account_is_connected(l->data)) { | |
6534 acct = l->data; | |
6535 break; | |
6536 } | |
6537 l = l->next; | |
6538 } | |
6539 } | |
6540 | |
6541 return acct; | |
6542 } | |
6543 | |
6544 | |
6545 static gboolean oscar_uri_handler(const char *proto, const char *cmd, GHashTable *params) | |
6546 { | |
6547 char *acct_id = g_hash_table_lookup(params, "account"); | |
6548 char prpl[11]; | |
6549 GaimAccount *acct; | |
6550 | |
6551 if (g_ascii_strcasecmp(proto, "aim") && g_ascii_strcasecmp(proto, "icq")) | |
6552 return FALSE; | |
6553 | |
6554 g_snprintf(prpl, sizeof(prpl), "prpl-%s", proto); | |
6555 | |
6556 acct = find_acct(prpl, acct_id); | |
6557 | |
6558 if (!acct) | |
6559 return FALSE; | |
6560 | |
6561 /* aim:GoIM?screenname=SCREENNAME&message=MESSAGE */ | |
6562 if (!g_ascii_strcasecmp(cmd, "GoIM")) { | |
6563 char *sname = g_hash_table_lookup(params, "screenname"); | |
6564 if (sname) { | |
6565 char *message = g_hash_table_lookup(params, "message"); | |
6566 | |
6567 GaimConversation *conv = gaim_find_conversation_with_account( | |
6568 GAIM_CONV_TYPE_IM, sname, acct); | |
6569 if (conv == NULL) | |
6570 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, acct, sname); | |
6571 gaim_conversation_present(conv); | |
6572 | |
6573 if (message) { | |
6574 /* Spaces are encoded as '+' */ | |
6575 g_strdelimit(message, "+", ' '); | |
6576 gaim_conv_im_send(GAIM_CONV_IM(conv), message); | |
6577 } | |
6578 } | |
6579 /*else | |
6580 **If pidgindialogs_im() was in the core, we could use it here. | |
6581 * It is all gaim_request_* based, but I'm not sure it really belongs in the core | |
6582 pidgindialogs_im();*/ | |
6583 | |
6584 return TRUE; | |
6585 } | |
6586 /* aim:GoChat?roomname=CHATROOMNAME&exchange=4 */ | |
6587 else if (!g_ascii_strcasecmp(cmd, "GoChat")) { | |
6588 char *rname = g_hash_table_lookup(params, "roomname"); | |
6589 if (rname) { | |
6590 /* This is somewhat hacky, but the params aren't useful after this command */ | |
6591 g_hash_table_insert(params, g_strdup("exchange"), g_strdup("4")); | |
6592 g_hash_table_insert(params, g_strdup("room"), g_strdup(rname)); | |
6593 serv_join_chat(gaim_account_get_connection(acct), params); | |
6594 } | |
6595 /*else | |
6596 ** Same as above (except that this would have to be re-written using gaim_request_*) | |
6597 pidgin_blist_joinchat_show(); */ | |
6598 | |
6599 return TRUE; | |
6600 } | |
6601 /* aim:AddBuddy?screenname=SCREENNAME&groupname=GROUPNAME*/ | |
6602 else if (!g_ascii_strcasecmp(cmd, "AddBuddy")) { | |
6603 char *sname = g_hash_table_lookup(params, "screenname"); | |
6604 char *gname = g_hash_table_lookup(params, "groupname"); | |
6605 gaim_blist_request_add_buddy(acct, sname, gname, NULL); | |
6606 return TRUE; | |
6607 } | |
6608 | |
6609 return FALSE; | |
6610 } | |
6611 | |
6612 void oscar_init(GaimPluginProtocolInfo *prpl_info) | |
6613 { | |
6614 GaimAccountOption *option; | |
6615 static gboolean init = FALSE; | |
6616 | |
6617 option = gaim_account_option_string_new(_("Server"), "server", OSCAR_DEFAULT_LOGIN_SERVER); | |
6618 prpl_info->protocol_options = g_list_append(prpl_info->protocol_options, option); | |
6619 | |
6620 option = gaim_account_option_int_new(_("Port"), "port", OSCAR_DEFAULT_LOGIN_PORT); | |
6621 prpl_info->protocol_options = g_list_append(prpl_info->protocol_options, option); | |
6622 | |
6623 option = gaim_account_option_bool_new( | |
6624 _("Always use ICQ proxy server for file transfers\n(slower, but does not reveal your IP address)"), "always_use_rv_proxy", | |
6625 OSCAR_DEFAULT_ALWAYS_USE_RV_PROXY); | |
6626 prpl_info->protocol_options = g_list_append(prpl_info->protocol_options, option); | |
6627 | |
6628 if (init) | |
6629 return; | |
6630 init = TRUE; | |
6631 | |
6632 /* Preferences */ | |
6633 gaim_prefs_add_none("/plugins/prpl/oscar"); | |
6634 gaim_prefs_add_bool("/plugins/prpl/oscar/recent_buddies", FALSE); | |
6635 gaim_prefs_add_bool("/plugins/prpl/oscar/show_idle", FALSE); | |
6636 gaim_prefs_remove("/plugins/prpl/oscar/always_use_rv_proxy"); | |
6637 | |
6638 /* protocol handler */ | |
6639 /* TODO: figure out a good instance to use here */ | |
6640 gaim_signal_connect(gaim_get_core(), "uri-handler", &init, | |
6641 GAIM_CALLBACK(oscar_uri_handler), NULL); | |
6642 } | |
6643 |