comparison libpurple/protocols/yahoo/libyahoo.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 1f63548d3da5
children ca66c299dbbf
comparison
equal deleted inserted replaced
27399:1f63548d3da5 27400:31534ae3406a
22 */ 22 */
23 23
24 #include "internal.h" 24 #include "internal.h"
25 25
26 #include <account.h> 26 #include <account.h>
27 #include <prpl.h> 27 #include <core.h>
28
29 #include "libymsg.h"
30 #include "yahoochat.h"
31 #include "yahoo_aliases.h"
32 #include "yahoo_doodle.h"
33 #include "yahoo_filexfer.h"
34 #include "yahoo_picture.h"
35
36 static PurplePlugin *my_protocol = NULL;
37
38 static void yahoo_register_commands(void)
39 {
40 purple_cmd_register("join", "s", PURPLE_CMD_P_PRPL,
41 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT |
42 PURPLE_CMD_FLAG_PRPL_ONLY,
43 "prpl-yahoo", yahoopurple_cmd_chat_join,
44 _("join &lt;room&gt;: Join a chat room on the Yahoo network"), NULL);
45 purple_cmd_register("list", "", PURPLE_CMD_P_PRPL,
46 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT |
47 PURPLE_CMD_FLAG_PRPL_ONLY,
48 "prpl-yahoo", yahoopurple_cmd_chat_list,
49 _("list: List rooms on the Yahoo network"), NULL);
50 purple_cmd_register("buzz", "", PURPLE_CMD_P_PRPL,
51 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY,
52 "prpl-yahoo", yahoopurple_cmd_buzz,
53 _("buzz: Buzz a user to get their attention"), NULL);
54 purple_cmd_register("doodle", "", PURPLE_CMD_P_PRPL,
55 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY,
56 "prpl-yahoo", yahoo_doodle_purple_cmd_start,
57 _("doodle: Request user to start a Doodle session"), NULL);
58 }
59
60 static PurpleAccount *find_acct(const char *prpl, const char *acct_id)
61 {
62 PurpleAccount *acct = NULL;
63
64 /* If we have a specific acct, use it */
65 if (acct_id) {
66 acct = purple_accounts_find(acct_id, prpl);
67 if (acct && !purple_account_is_connected(acct))
68 acct = NULL;
69 } else { /* Otherwise find an active account for the protocol */
70 GList *l = purple_accounts_get_all();
71 while (l) {
72 if (!strcmp(prpl, purple_account_get_protocol_id(l->data))
73 && purple_account_is_connected(l->data)) {
74 acct = l->data;
75 break;
76 }
77 l = l->next;
78 }
79 }
80
81 return acct;
82 }
83
84 /* This may not be the best way to do this, but we find the first key w/o a value
85 * and assume it is the buddy name */
86 static void yahoo_find_uri_novalue_param(gpointer key, gpointer value, gpointer user_data)
87 {
88 char **retval = user_data;
89
90 if (value == NULL && *retval == NULL) {
91 *retval = key;
92 }
93 }
94
95 static gboolean yahoo_uri_handler(const char *proto, const char *cmd, GHashTable *params)
96 {
97 char *acct_id = g_hash_table_lookup(params, "account");
98 PurpleAccount *acct;
99
100 if (g_ascii_strcasecmp(proto, "ymsgr"))
101 return FALSE;
102
103 acct = find_acct(purple_plugin_get_id(my_protocol), acct_id);
104
105 if (!acct)
106 return FALSE;
107
108 /* ymsgr:SendIM?screename&m=The+Message */
109 if (!g_ascii_strcasecmp(cmd, "SendIM")) {
110 char *sname = NULL;
111 g_hash_table_foreach(params, yahoo_find_uri_novalue_param, &sname);
112 if (sname) {
113 char *message = g_hash_table_lookup(params, "m");
114
115 PurpleConversation *conv = purple_find_conversation_with_account(
116 PURPLE_CONV_TYPE_IM, sname, acct);
117 if (conv == NULL)
118 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, sname);
119 purple_conversation_present(conv);
120
121 if (message) {
122 /* Spaces are encoded as '+' */
123 g_strdelimit(message, "+", ' ');
124 purple_conv_send_confirm(conv, message);
125 }
126 }
127 /* else
128 **If pidgindialogs_im() was in the core, we could use it here.
129 * It is all purple_request_* based, but I'm not sure it really belongs in the core
130 pidgindialogs_im(); */
131
132 return TRUE;
133 }
134 /* ymsgr:Chat?roomname */
135 else if (!g_ascii_strcasecmp(cmd, "Chat")) {
136 char *rname = NULL;
137 g_hash_table_foreach(params, yahoo_find_uri_novalue_param, &rname);
138 if (rname) {
139 /* This is somewhat hacky, but the params aren't useful after this command */
140 g_hash_table_insert(params, g_strdup("room"), g_strdup(rname));
141 g_hash_table_insert(params, g_strdup("type"), g_strdup("Chat"));
142 serv_join_chat(purple_account_get_connection(acct), params);
143 }
144 /* else
145 ** Same as above (except that this would have to be re-written using purple_request_*)
146 pidgin_blist_joinchat_show(); */
147
148 return TRUE;
149 }
150 /* ymsgr:AddFriend?name */
151 else if (!g_ascii_strcasecmp(cmd, "AddFriend")) {
152 char *name = NULL;
153 g_hash_table_foreach(params, yahoo_find_uri_novalue_param, &name);
154 purple_blist_request_add_buddy(acct, name, NULL, NULL);
155 return TRUE;
156 }
157
158 return FALSE;
159 }
28 160
29 static GHashTable * 161 static GHashTable *
30 yahoo_get_account_text_table(PurpleAccount *account) 162 yahoo_get_account_text_table(PurpleAccount *account)
31 { 163 {
32 GHashTable *table; 164 GHashTable *table;
33 table = g_hash_table_new(g_str_hash, g_str_equal); 165 table = g_hash_table_new(g_str_hash, g_str_equal);
34 g_hash_table_insert(table, "login_label", (gpointer)_("Yahoo ID...")); 166 g_hash_table_insert(table, "login_label", (gpointer)_("Yahoo ID..."));
35 return table; 167 return table;
168 }
169
170 static gboolean yahoo_unload_plugin(PurplePlugin *plugin)
171 {
172 yahoo_dest_colorht();
173
174 return TRUE;
36 } 175 }
37 176
38 static PurpleWhiteboardPrplOps yahoo_whiteboard_prpl_ops = 177 static PurpleWhiteboardPrplOps yahoo_whiteboard_prpl_ops =
39 { 178 {
40 yahoo_doodle_start, 179 yahoo_doodle_start,
199 option = purple_account_option_int_new(_("Yahoo Chat port"), "ycht-port", YAHOO_YCHT_PORT); 338 option = purple_account_option_int_new(_("Yahoo Chat port"), "ycht-port", YAHOO_YCHT_PORT);
200 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 339 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
201 #endif 340 #endif
202 341
203 my_protocol = plugin; 342 my_protocol = plugin;
204 yahoopurple_register_commands(); 343 yahoo_register_commands();
205 yahoo_init_colorht(); 344 yahoo_init_colorht();
206 345
207 purple_signal_connect(purple_get_core(), "uri-handler", plugin, 346 purple_signal_connect(purple_get_core(), "uri-handler", plugin,
208 PURPLE_CALLBACK(yahoo_uri_handler), NULL); 347 PURPLE_CALLBACK(yahoo_uri_handler), NULL);
209 } 348 }