comparison libpurple/protocols/yahoo/libymsg.c @ 27400:31534ae3406a

Moved functions around and made some no longer static. All the functions that are no longer static now have prototypes in libymsg.h. Moved the URI handling stuff to libyahoo.c since I removed the handling capability from libyahoojp.c. I still need to find out if Yahoo! JAPAN has its own URI scheme or not.
author John Bailey <rekkanoryo@rekkanoryo.org>
date Sun, 05 Jul 2009 23:56:07 +0000
parents 7f008ce8604b
children 430eb9e9042a
comparison
equal deleted inserted replaced
27399:1f63548d3da5 27400:31534ae3406a
39 #include "server.h" 39 #include "server.h"
40 #include "util.h" 40 #include "util.h"
41 #include "version.h" 41 #include "version.h"
42 #include "xmlnode.h" 42 #include "xmlnode.h"
43 43
44 #include "ymsg.h" 44 #include "libymsg.h"
45 #include "yahoochat.h" 45 #include "yahoochat.h"
46 #include "yahoo_aliases.h" 46 #include "yahoo_aliases.h"
47 #include "yahoo_doodle.h" 47 #include "yahoo_doodle.h"
48 #include "yahoo_filexfer.h" 48 #include "yahoo_filexfer.h"
49 #include "yahoo_friend.h" 49 #include "yahoo_friend.h"
59 #define PING_TIMEOUT 3600 59 #define PING_TIMEOUT 3600
60 60
61 /* One minute */ 61 /* One minute */
62 #define KEEPALIVE_TIMEOUT 60 62 #define KEEPALIVE_TIMEOUT 60
63 63
64 static void yahoo_add_buddy(PurpleConnection *gc, PurpleBuddy *, PurpleGroup *);
65 #ifdef TRY_WEBMESSENGER_LOGIN 64 #ifdef TRY_WEBMESSENGER_LOGIN
66 static void yahoo_login_page_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message); 65 static void yahoo_login_page_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
67 #endif /* TRY_WEBMESSENGER_LOGIN */ 66 #endif /* TRY_WEBMESSENGER_LOGIN */
68 static void yahoo_set_status(PurpleAccount *account, PurpleStatus *status);
69 67
70 static void yahoo_update_status(PurpleConnection *gc, const char *name, YahooFriend *f) 68 static void yahoo_update_status(PurpleConnection *gc, const char *name, YahooFriend *f)
71 { 69 {
72 char *status = NULL; 70 char *status = NULL;
73 71
3396 purple_debug_error("yahoo", "Unexpected PurpleStatus!\n"); 3394 purple_debug_error("yahoo", "Unexpected PurpleStatus!\n");
3397 return YAHOO_STATUS_AVAILABLE; 3395 return YAHOO_STATUS_AVAILABLE;
3398 } 3396 }
3399 } 3397 }
3400 3398
3401 static void yahoo_login(PurpleAccount *account) { 3399 void yahoo_login(PurpleAccount *account) {
3402 PurpleConnection *gc = purple_account_get_connection(account); 3400 PurpleConnection *gc = purple_account_get_connection(account);
3403 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); 3401 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1);
3404 PurpleStatus *status = purple_account_get_active_status(account); 3402 PurpleStatus *status = purple_account_get_active_status(account);
3405 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_URLDESC; 3403 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_URLDESC;
3406 3404
3451 return; 3449 return;
3452 } 3450 }
3453 } 3451 }
3454 } 3452 }
3455 3453
3456 static void yahoo_close(PurpleConnection *gc) { 3454 void yahoo_close(PurpleConnection *gc) {
3457 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 3455 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
3458 GSList *l; 3456 GSList *l;
3459 3457
3460 if (gc->inpa) 3458 if (gc->inpa)
3461 purple_input_remove(gc->inpa); 3459 purple_input_remove(gc->inpa);
3539 3537
3540 g_free(yd); 3538 g_free(yd);
3541 gc->proto_data = NULL; 3539 gc->proto_data = NULL;
3542 } 3540 }
3543 3541
3544 static const char *yahoo_list_icon(PurpleAccount *a, PurpleBuddy *b) 3542 const char *yahoo_list_icon(PurpleAccount *a, PurpleBuddy *b)
3545 { 3543 {
3546 return "yahoo"; 3544 return "yahoo";
3547 } 3545 }
3548 3546
3549 static const char *yahoo_list_emblem(PurpleBuddy *b) 3547 const char *yahoo_list_emblem(PurpleBuddy *b)
3550 { 3548 {
3551 PurpleAccount *account; 3549 PurpleAccount *account;
3552 PurpleConnection *gc; 3550 PurpleConnection *gc;
3553 struct yahoo_data *yd; 3551 struct yahoo_data *yd;
3554 YahooFriend *f; 3552 YahooFriend *f;
3678 g_snprintf(url, sizeof url, "http://games.yahoo.com/games/%s", game2); 3676 g_snprintf(url, sizeof url, "http://games.yahoo.com/games/%s", game2);
3679 purple_notify_uri(gc, url); 3677 purple_notify_uri(gc, url);
3680 g_free(game2); 3678 g_free(game2);
3681 } 3679 }
3682 3680
3683 static char *yahoo_status_text(PurpleBuddy *b) 3681 char *yahoo_status_text(PurpleBuddy *b)
3684 { 3682 {
3685 YahooFriend *f = NULL; 3683 YahooFriend *f = NULL;
3686 const char *msg; 3684 const char *msg;
3687 char *msg2; 3685 char *msg2;
3688 PurpleAccount *account; 3686 PurpleAccount *account;
3908 } 3906 }
3909 3907
3910 return m; 3908 return m;
3911 } 3909 }
3912 3910
3913 static GList *yahoo_blist_node_menu(PurpleBlistNode *node) 3911 GList *yahoo_blist_node_menu(PurpleBlistNode *node)
3914 { 3912 {
3915 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { 3913 if(PURPLE_BLIST_NODE_IS_BUDDY(node)) {
3916 return yahoo_buddy_menu((PurpleBuddy *) node); 3914 return yahoo_buddy_menu((PurpleBuddy *) node);
3917 } else { 3915 } else {
3918 return NULL; 3916 return NULL;
4047 _("Cancel"), NULL, 4045 _("Cancel"), NULL,
4048 purple_connection_get_account(gc), NULL, NULL, 4046 purple_connection_get_account(gc), NULL, NULL,
4049 gc); 4047 gc);
4050 } 4048 }
4051 4049
4052 static GList *yahoo_actions(PurplePlugin *plugin, gpointer context) { 4050 GList *yahoo_actions(PurplePlugin *plugin, gpointer context) {
4053 GList *m = NULL; 4051 GList *m = NULL;
4054 PurplePluginAction *act; 4052 PurplePluginAction *act;
4055 4053
4056 act = purple_plugin_action_new(_("Activate ID..."), 4054 act = purple_plugin_action_new(_("Activate ID..."),
4057 yahoo_show_act_id); 4055 yahoo_show_act_id);
4072 struct yahoo_sms_carrier_cb_data { 4070 struct yahoo_sms_carrier_cb_data {
4073 PurpleConnection *gc; 4071 PurpleConnection *gc;
4074 char *who; 4072 char *who;
4075 char *what; 4073 char *what;
4076 }; 4074 };
4077
4078 static int yahoo_send_im(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags);
4079 4075
4080 static void yahoo_get_sms_carrier_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, 4076 static void yahoo_get_sms_carrier_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
4081 const gchar *webdata, size_t len, const gchar *error_message) 4077 const gchar *webdata, size_t len, const gchar *error_message)
4082 { 4078 {
4083 struct yahoo_sms_carrier_cb_data *sms_cb_data = user_data; 4079 struct yahoo_sms_carrier_cb_data *sms_cb_data = user_data;
4187 g_free(sms_cb_data->what); 4183 g_free(sms_cb_data->what);
4188 g_free(sms_cb_data); 4184 g_free(sms_cb_data);
4189 } 4185 }
4190 } 4186 }
4191 4187
4192 static int yahoo_send_im(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags) 4188 int yahoo_send_im(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags)
4193 { 4189 {
4194 struct yahoo_data *yd = gc->proto_data; 4190 struct yahoo_data *yd = gc->proto_data;
4195 struct yahoo_packet *pkt = NULL; 4191 struct yahoo_packet *pkt = NULL;
4196 char *msg = yahoo_html_to_codes(what); 4192 char *msg = yahoo_html_to_codes(what);
4197 char *msg2; 4193 char *msg2;
4338 g_free(msg2); 4334 g_free(msg2);
4339 4335
4340 return ret; 4336 return ret;
4341 } 4337 }
4342 4338
4343 static unsigned int yahoo_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state) 4339 unsigned int yahoo_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state)
4344 { 4340 {
4345 struct yahoo_data *yd = gc->proto_data; 4341 struct yahoo_data *yd = gc->proto_data;
4346 struct yahoo_p2p_data *p2p_data; 4342 struct yahoo_p2p_data *p2p_data;
4347 gboolean msn = !g_strncasecmp(who, "msn/", 4); 4343 gboolean msn = !g_strncasecmp(who, "msn/", 4);
4348 struct yahoo_packet *pkt = NULL; 4344 struct yahoo_packet *pkt = NULL;
4381 YahooFriend *f = value; 4377 YahooFriend *f = value;
4382 if (f && f->presence == YAHOO_PRESENCE_ONLINE) 4378 if (f && f->presence == YAHOO_PRESENCE_ONLINE)
4383 f->presence = YAHOO_PRESENCE_DEFAULT; 4379 f->presence = YAHOO_PRESENCE_DEFAULT;
4384 } 4380 }
4385 4381
4386 static void yahoo_set_status(PurpleAccount *account, PurpleStatus *status) 4382 void yahoo_set_status(PurpleAccount *account, PurpleStatus *status)
4387 { 4383 {
4388 PurpleConnection *gc; 4384 PurpleConnection *gc;
4389 PurplePresence *presence; 4385 PurplePresence *presence;
4390 struct yahoo_data *yd; 4386 struct yahoo_data *yd;
4391 struct yahoo_packet *pkt; 4387 struct yahoo_packet *pkt;
4458 g_hash_table_foreach(yd->friends, yahoo_session_presence_remove, NULL); 4454 g_hash_table_foreach(yd->friends, yahoo_session_presence_remove, NULL);
4459 4455
4460 } 4456 }
4461 } 4457 }
4462 4458
4463 static void yahoo_set_idle(PurpleConnection *gc, int idle) 4459 void yahoo_set_idle(PurpleConnection *gc, int idle)
4464 { 4460 {
4465 struct yahoo_data *yd = gc->proto_data; 4461 struct yahoo_data *yd = gc->proto_data;
4466 struct yahoo_packet *pkt = NULL; 4462 struct yahoo_packet *pkt = NULL;
4467 char *msg = NULL, *msg2 = NULL; 4463 char *msg = NULL, *msg2 = NULL;
4468 PurpleStatus *status = NULL; 4464 PurpleStatus *status = NULL;
4506 4502
4507 g_free(msg); 4503 g_free(msg);
4508 g_free(msg2); 4504 g_free(msg2);
4509 } 4505 }
4510 4506
4511 static GList *yahoo_status_types(PurpleAccount *account) 4507 GList *yahoo_status_types(PurpleAccount *account)
4512 { 4508 {
4513 PurpleStatusType *type; 4509 PurpleStatusType *type;
4514 GList *types = NULL; 4510 GList *types = NULL;
4515 4511
4516 type = purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE, YAHOO_STATUS_TYPE_AVAILABLE, 4512 type = purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE, YAHOO_STATUS_TYPE_AVAILABLE,
4563 types = g_list_append(types, type); 4559 types = g_list_append(types, type);
4564 4560
4565 return types; 4561 return types;
4566 } 4562 }
4567 4563
4568 static void yahoo_keepalive(PurpleConnection *gc) 4564 void yahoo_keepalive(PurpleConnection *gc)
4569 { 4565 {
4570 struct yahoo_packet *pkt; 4566 struct yahoo_packet *pkt;
4571 struct yahoo_data *yd = gc->proto_data; 4567 struct yahoo_data *yd = gc->proto_data;
4572 time_t now = time(NULL); 4568 time_t now = time(NULL);
4573 4569
4597 yahoo_packet_send_and_free(pkt, yd); 4593 yahoo_packet_send_and_free(pkt, yd);
4598 } 4594 }
4599 4595
4600 } 4596 }
4601 4597
4602 static void yahoo_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *g) 4598 void yahoo_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *g)
4603 { 4599 {
4604 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 4600 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
4605 struct yahoo_packet *pkt; 4601 struct yahoo_packet *pkt;
4606 const char *group = NULL; 4602 const char *group = NULL;
4607 char *group2; 4603 char *group2;
4661 4657
4662 yahoo_packet_send_and_free(pkt, yd); 4658 yahoo_packet_send_and_free(pkt, yd);
4663 g_free(group2); 4659 g_free(group2);
4664 } 4660 }
4665 4661
4666 static void yahoo_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 4662 void yahoo_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
4667 { 4663 {
4668 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 4664 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
4669 struct yahoo_packet *pkt; 4665 struct yahoo_packet *pkt;
4670 GSList *buddies, *l; 4666 GSList *buddies, *l;
4671 PurpleGroup *g; 4667 PurpleGroup *g;
4710 yahoo_packet_hash_int(pkt, 241, f->protocol); 4706 yahoo_packet_hash_int(pkt, 241, f->protocol);
4711 yahoo_packet_send_and_free(pkt, yd); 4707 yahoo_packet_send_and_free(pkt, yd);
4712 g_free(cg); 4708 g_free(cg);
4713 } 4709 }
4714 4710
4715 static void yahoo_add_deny(PurpleConnection *gc, const char *who) { 4711 void yahoo_add_deny(PurpleConnection *gc, const char *who) {
4716 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 4712 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
4717 struct yahoo_packet *pkt; 4713 struct yahoo_packet *pkt;
4718 4714
4719 if (!yd->logged_in) 4715 if (!yd->logged_in)
4720 return; 4716 return;
4726 yahoo_packet_hash(pkt, "sss", 1, purple_connection_get_display_name(gc), 4722 yahoo_packet_hash(pkt, "sss", 1, purple_connection_get_display_name(gc),
4727 7, who, 13, "1"); 4723 7, who, 13, "1");
4728 yahoo_packet_send_and_free(pkt, yd); 4724 yahoo_packet_send_and_free(pkt, yd);
4729 } 4725 }
4730 4726
4731 static void yahoo_rem_deny(PurpleConnection *gc, const char *who) { 4727 void yahoo_rem_deny(PurpleConnection *gc, const char *who) {
4732 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; 4728 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
4733 struct yahoo_packet *pkt; 4729 struct yahoo_packet *pkt;
4734 4730
4735 if (!yd->logged_in) 4731 if (!yd->logged_in)
4736 return; 4732 return;
4741 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); 4737 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0);
4742 yahoo_packet_hash(pkt, "sss", 1, purple_connection_get_display_name(gc), 7, who, 13, "2"); 4738 yahoo_packet_hash(pkt, "sss", 1, purple_connection_get_display_name(gc), 7, who, 13, "2");
4743 yahoo_packet_send_and_free(pkt, yd); 4739 yahoo_packet_send_and_free(pkt, yd);
4744 } 4740 }
4745 4741
4746 static void yahoo_set_permit_deny(PurpleConnection *gc) 4742 void yahoo_set_permit_deny(PurpleConnection *gc)
4747 { 4743 {
4748 PurpleAccount *account; 4744 PurpleAccount *account;
4749 GSList *deny; 4745 GSList *deny;
4750 4746
4751 account = purple_connection_get_account(gc); 4747 account = purple_connection_get_account(gc);
4765 yahoo_add_deny(gc, deny->data); 4761 yahoo_add_deny(gc, deny->data);
4766 break; 4762 break;
4767 } 4763 }
4768 } 4764 }
4769 4765
4770 static gboolean yahoo_unload_plugin(PurplePlugin *plugin) 4766 void yahoo_change_buddys_group(PurpleConnection *gc, const char *who,
4771 {
4772 yahoo_dest_colorht();
4773
4774 return TRUE;
4775 }
4776
4777 static void yahoo_change_buddys_group(PurpleConnection *gc, const char *who,
4778 const char *old_group, const char *new_group) 4767 const char *old_group, const char *new_group)
4779 { 4768 {
4780 struct yahoo_data *yd = gc->proto_data; 4769 struct yahoo_data *yd = gc->proto_data;
4781 struct yahoo_packet *pkt; 4770 struct yahoo_packet *pkt;
4782 char *gpn, *gpo; 4771 char *gpn, *gpo;
4821 4810
4822 g_free(gpn); 4811 g_free(gpn);
4823 g_free(gpo); 4812 g_free(gpo);
4824 } 4813 }
4825 4814
4826 static void yahoo_rename_group(PurpleConnection *gc, const char *old_name, 4815 void yahoo_rename_group(PurpleConnection *gc, const char *old_name,
4827 PurpleGroup *group, GList *moved_buddies) 4816 PurpleGroup *group, GList *moved_buddies)
4828 { 4817 {
4829 struct yahoo_data *yd = gc->proto_data; 4818 struct yahoo_data *yd = gc->proto_data;
4830 struct yahoo_packet *pkt; 4819 struct yahoo_packet *pkt;
4831 char *gpn, *gpo; 4820 char *gpn, *gpo;
4846 g_free(gpo); 4835 g_free(gpo);
4847 } 4836 }
4848 4837
4849 /********************************* Commands **********************************/ 4838 /********************************* Commands **********************************/
4850 4839
4851 static PurpleCmdRet 4840 PurpleCmdRet
4852 yahoopurple_cmd_buzz(PurpleConversation *c, const gchar *cmd, gchar **args, gchar **error, void *data) { 4841 yahoopurple_cmd_buzz(PurpleConversation *c, const gchar *cmd, gchar **args, gchar **error, void *data) {
4853 PurpleAccount *account = purple_conversation_get_account(c); 4842 PurpleAccount *account = purple_conversation_get_account(c);
4854 4843
4855 if (*args && args[0]) 4844 if (*args && args[0])
4856 return PURPLE_CMD_RET_FAILED; 4845 return PURPLE_CMD_RET_FAILED;
4858 purple_prpl_send_attention(account->gc, c->name, YAHOO_BUZZ); 4847 purple_prpl_send_attention(account->gc, c->name, YAHOO_BUZZ);
4859 4848
4860 return PURPLE_CMD_RET_OK; 4849 return PURPLE_CMD_RET_OK;
4861 } 4850 }
4862 4851
4863 static PurplePlugin *my_protocol = NULL; 4852 PurpleCmdRet
4864
4865 static PurpleCmdRet
4866 yahoopurple_cmd_chat_join(PurpleConversation *conv, const char *cmd, 4853 yahoopurple_cmd_chat_join(PurpleConversation *conv, const char *cmd,
4867 char **args, char **error, void *data) 4854 char **args, char **error, void *data)
4868 { 4855 {
4869 GHashTable *comp; 4856 GHashTable *comp;
4870 PurpleConnection *gc; 4857 PurpleConnection *gc;
4887 4874
4888 g_hash_table_destroy(comp); 4875 g_hash_table_destroy(comp);
4889 return PURPLE_CMD_RET_OK; 4876 return PURPLE_CMD_RET_OK;
4890 } 4877 }
4891 4878
4892 static PurpleCmdRet 4879 PurpleCmdRet
4893 yahoopurple_cmd_chat_list(PurpleConversation *conv, const char *cmd, 4880 yahoopurple_cmd_chat_list(PurpleConversation *conv, const char *cmd,
4894 char **args, char **error, void *data) 4881 char **args, char **error, void *data)
4895 { 4882 {
4896 PurpleAccount *account = purple_conversation_get_account(conv); 4883 PurpleAccount *account = purple_conversation_get_account(conv);
4897 if (*args && args[0]) 4884 if (*args && args[0])
4898 return PURPLE_CMD_RET_FAILED; 4885 return PURPLE_CMD_RET_FAILED;
4899 purple_roomlist_show_with_account(account); 4886 purple_roomlist_show_with_account(account);
4900 return PURPLE_CMD_RET_OK; 4887 return PURPLE_CMD_RET_OK;
4901 } 4888 }
4902 4889
4903 static gboolean yahoo_offline_message(const PurpleBuddy *buddy) 4890 gboolean yahoo_offline_message(const PurpleBuddy *buddy)
4904 { 4891 {
4905 return TRUE; 4892 return TRUE;
4906 } 4893 }
4907 4894
4908 gboolean yahoo_send_attention(PurpleConnection *gc, const char *username, guint type) 4895 gboolean yahoo_send_attention(PurpleConnection *gc, const char *username, guint type)
4933 } 4920 }
4934 4921
4935 return list; 4922 return list;
4936 } 4923 }
4937 4924
4938 /************************** Plugin Initialization ****************************/
4939 static void
4940 yahoopurple_register_commands(void)
4941 {
4942 purple_cmd_register("join", "s", PURPLE_CMD_P_PRPL,
4943 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT |
4944 PURPLE_CMD_FLAG_PRPL_ONLY,
4945 "prpl-yahoo", yahoopurple_cmd_chat_join,
4946 _("join &lt;room&gt;: Join a chat room on the Yahoo network"), NULL);
4947 purple_cmd_register("list", "", PURPLE_CMD_P_PRPL,
4948 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT |
4949 PURPLE_CMD_FLAG_PRPL_ONLY,
4950 "prpl-yahoo", yahoopurple_cmd_chat_list,
4951 _("list: List rooms on the Yahoo network"), NULL);
4952 purple_cmd_register("buzz", "", PURPLE_CMD_P_PRPL,
4953 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY,
4954 "prpl-yahoo", yahoopurple_cmd_buzz,
4955 _("buzz: Buzz a user to get their attention"), NULL);
4956 purple_cmd_register("doodle", "", PURPLE_CMD_P_PRPL,
4957 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY,
4958 "prpl-yahoo", yahoo_doodle_purple_cmd_start,
4959 _("doodle: Request user to start a Doodle session"), NULL);
4960 }
4961
4962 static PurpleAccount *find_acct(const char *prpl, const char *acct_id)
4963 {
4964 PurpleAccount *acct = NULL;
4965
4966 /* If we have a specific acct, use it */
4967 if (acct_id) {
4968 acct = purple_accounts_find(acct_id, prpl);
4969 if (acct && !purple_account_is_connected(acct))
4970 acct = NULL;
4971 } else { /* Otherwise find an active account for the protocol */
4972 GList *l = purple_accounts_get_all();
4973 while (l) {
4974 if (!strcmp(prpl, purple_account_get_protocol_id(l->data))
4975 && purple_account_is_connected(l->data)) {
4976 acct = l->data;
4977 break;
4978 }
4979 l = l->next;
4980 }
4981 }
4982
4983 return acct;
4984 }
4985
4986 /* This may not be the best way to do this, but we find the first key w/o a value
4987 * and assume it is the buddy name */
4988 static void yahoo_find_uri_novalue_param(gpointer key, gpointer value, gpointer user_data)
4989 {
4990 char **retval = user_data;
4991
4992 if (value == NULL && *retval == NULL) {
4993 *retval = key;
4994 }
4995 }
4996
4997 static gboolean yahoo_uri_handler(const char *proto, const char *cmd, GHashTable *params)
4998 {
4999 char *acct_id = g_hash_table_lookup(params, "account");
5000 PurpleAccount *acct;
5001
5002 if (g_ascii_strcasecmp(proto, "ymsgr"))
5003 return FALSE;
5004
5005 acct = find_acct(purple_plugin_get_id(my_protocol), acct_id);
5006
5007 if (!acct)
5008 return FALSE;
5009
5010 /* ymsgr:SendIM?screename&m=The+Message */
5011 if (!g_ascii_strcasecmp(cmd, "SendIM")) {
5012 char *sname = NULL;
5013 g_hash_table_foreach(params, yahoo_find_uri_novalue_param, &sname);
5014 if (sname) {
5015 char *message = g_hash_table_lookup(params, "m");
5016
5017 PurpleConversation *conv = purple_find_conversation_with_account(
5018 PURPLE_CONV_TYPE_IM, sname, acct);
5019 if (conv == NULL)
5020 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, sname);
5021 purple_conversation_present(conv);
5022
5023 if (message) {
5024 /* Spaces are encoded as '+' */
5025 g_strdelimit(message, "+", ' ');
5026 purple_conv_send_confirm(conv, message);
5027 }
5028 }
5029 /* else
5030 **If pidgindialogs_im() was in the core, we could use it here.
5031 * It is all purple_request_* based, but I'm not sure it really belongs in the core
5032 pidgindialogs_im(); */
5033
5034 return TRUE;
5035 }
5036 /* ymsgr:Chat?roomname */
5037 else if (!g_ascii_strcasecmp(cmd, "Chat")) {
5038 char *rname = NULL;
5039 g_hash_table_foreach(params, yahoo_find_uri_novalue_param, &rname);
5040 if (rname) {
5041 /* This is somewhat hacky, but the params aren't useful after this command */
5042 g_hash_table_insert(params, g_strdup("room"), g_strdup(rname));
5043 g_hash_table_insert(params, g_strdup("type"), g_strdup("Chat"));
5044 serv_join_chat(purple_account_get_connection(acct), params);
5045 }
5046 /* else
5047 ** Same as above (except that this would have to be re-written using purple_request_*)
5048 pidgin_blist_joinchat_show(); */
5049
5050 return TRUE;
5051 }
5052 /* ymsgr:AddFriend?name */
5053 else if (!g_ascii_strcasecmp(cmd, "AddFriend")) {
5054 char *name = NULL;
5055 g_hash_table_foreach(params, yahoo_find_uri_novalue_param, &name);
5056 purple_blist_request_add_buddy(acct, name, NULL, NULL);
5057 return TRUE;
5058 }
5059
5060 return FALSE;
5061 }
5062