comparison libpurple/protocols/yahoo/libyahoo.c @ 27590:a08e84032814

merge of '2348ff22f0ff3453774b8b25b36238465580c609' and 'e76f11543c2a4aa05bdf584f087cbe3439029661'
author Paul Aurich <paul@darkrain42.org>
date Sun, 12 Jul 2009 05:43:38 +0000
parents ca66c299dbbf
children 6d3f3473cb4c
comparison
equal deleted inserted replaced
27104:048bcf41deef 27590:a08e84032814
1 /*
2 * purple
3 *
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 *
22 */
23
24 #include "internal.h"
25
26 #include <account.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 }
160
161 static GHashTable *
162 yahoo_get_account_text_table(PurpleAccount *account)
163 {
164 GHashTable *table;
165 table = g_hash_table_new(g_str_hash, g_str_equal);
166 g_hash_table_insert(table, "login_label", (gpointer)_("Yahoo ID..."));
167 return table;
168 }
169
170 static gboolean yahoo_unload_plugin(PurplePlugin *plugin)
171 {
172 yahoo_dest_colorht();
173
174 return TRUE;
175 }
176
177 static PurpleWhiteboardPrplOps yahoo_whiteboard_prpl_ops =
178 {
179 yahoo_doodle_start,
180 yahoo_doodle_end,
181 yahoo_doodle_get_dimensions,
182 NULL,
183 yahoo_doodle_get_brush,
184 yahoo_doodle_set_brush,
185 yahoo_doodle_send_draw_list,
186 yahoo_doodle_clear,
187
188 /* padding */
189 NULL,
190 NULL,
191 NULL,
192 NULL
193 };
194
195 static PurplePluginProtocolInfo prpl_info =
196 {
197 OPT_PROTO_MAIL_CHECK | OPT_PROTO_CHAT_TOPIC,
198 NULL, /* user_splits */
199 NULL, /* protocol_options */
200 {"png,gif,jpeg", 96, 96, 96, 96, 0, PURPLE_ICON_SCALE_SEND},
201 yahoo_list_icon,
202 yahoo_list_emblem,
203 yahoo_status_text,
204 yahoo_tooltip_text,
205 yahoo_status_types,
206 yahoo_blist_node_menu,
207 yahoo_c_info,
208 yahoo_c_info_defaults,
209 yahoo_login,
210 yahoo_close,
211 yahoo_send_im,
212 NULL, /* set info */
213 yahoo_send_typing,
214 yahoo_get_info,
215 yahoo_set_status,
216 yahoo_set_idle,
217 NULL, /* change_passwd*/
218 yahoo_add_buddy,
219 NULL, /* add_buddies */
220 yahoo_remove_buddy,
221 NULL, /* remove_buddies */
222 NULL, /* add_permit */
223 yahoo_add_deny,
224 NULL, /* rem_permit */
225 yahoo_rem_deny,
226 yahoo_set_permit_deny,
227 yahoo_c_join,
228 NULL, /* reject chat invite */
229 yahoo_get_chat_name,
230 yahoo_c_invite,
231 yahoo_c_leave,
232 NULL, /* chat whisper */
233 yahoo_c_send,
234 yahoo_keepalive,
235 NULL, /* register_user */
236 NULL, /* get_cb_info */
237 NULL, /* get_cb_away */
238 yahoo_update_alias, /* alias_buddy */
239 yahoo_change_buddys_group,
240 yahoo_rename_group,
241 NULL, /* buddy_free */
242 NULL, /* convo_closed */
243 purple_normalize_nocase, /* normalize */
244 yahoo_set_buddy_icon,
245 NULL, /* void (*remove_group)(PurpleConnection *gc, const char *group);*/
246 NULL, /* char *(*get_cb_real_name)(PurpleConnection *gc, int id, const char *who); */
247 NULL, /* set_chat_topic */
248 NULL, /* find_blist_chat */
249 yahoo_roomlist_get_list,
250 yahoo_roomlist_cancel,
251 yahoo_roomlist_expand_category,
252 NULL, /* can_receive_file */
253 yahoo_send_file,
254 yahoo_new_xfer,
255 yahoo_offline_message, /* offline_message */
256 &yahoo_whiteboard_prpl_ops,
257 NULL, /* send_raw */
258 NULL, /* roomlist_room_serialize */
259 NULL, /* unregister_user */
260
261 yahoo_send_attention,
262 yahoo_attention_types,
263
264 sizeof(PurplePluginProtocolInfo), /* struct_size */
265 yahoo_get_account_text_table, /* get_account_text_table */
266 NULL, /* initiate_media */
267 NULL /* can_do_media */
268 };
269
270 static PurplePluginInfo info =
271 {
272 PURPLE_PLUGIN_MAGIC,
273 PURPLE_MAJOR_VERSION,
274 PURPLE_MINOR_VERSION,
275 PURPLE_PLUGIN_PROTOCOL, /**< type */
276 NULL, /**< ui_requirement */
277 0, /**< flags */
278 NULL, /**< dependencies */
279 PURPLE_PRIORITY_DEFAULT, /**< priority */
280 "prpl-yahoo", /**< id */
281 "Yahoo!", /**< name */
282 DISPLAY_VERSION, /**< version */
283 /** summary */
284 N_("Yahoo! Protocol Plugin"),
285 /** description */
286 N_("Yahoo! Protocol Plugin"),
287 NULL, /**< author */
288 PURPLE_WEBSITE, /**< homepage */
289 NULL, /**< load */
290 yahoo_unload_plugin, /**< unload */
291 NULL, /**< destroy */
292 NULL, /**< ui_info */
293 &prpl_info, /**< extra_info */
294 NULL,
295 yahoo_actions,
296
297 /* padding */
298 NULL,
299 NULL,
300 NULL,
301 NULL
302 };
303
304 static void
305 init_plugin(PurplePlugin *plugin)
306 {
307 PurpleAccountOption *option;
308
309 option = purple_account_option_string_new(_("Pager server"), "server", YAHOO_PAGER_HOST);
310 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
311
312 option = purple_account_option_int_new(_("Pager port"), "port", YAHOO_PAGER_PORT);
313 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
314
315 option = purple_account_option_string_new(_("File transfer server"), "xfer_host", YAHOO_XFER_HOST);
316 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
317
318 option = purple_account_option_int_new(_("File transfer port"), "xfer_port", YAHOO_XFER_PORT);
319 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
320
321 option = purple_account_option_string_new(_("Chat room locale"), "room_list_locale", YAHOO_ROOMLIST_LOCALE);
322 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
323
324 option = purple_account_option_bool_new(_("Ignore conference and chatroom invitations"), "ignore_invites", FALSE);
325 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
326
327 option = purple_account_option_string_new(_("Encoding"), "local_charset", "UTF-8");
328 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
329
330
331 #if 0
332 option = purple_account_option_string_new(_("Chat room list URL"), "room_list", YAHOO_ROOMLIST_URL);
333 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
334
335 option = purple_account_option_string_new(_("Yahoo Chat server"), "ycht-server", YAHOO_YCHT_HOST);
336 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
337
338 option = purple_account_option_int_new(_("Yahoo Chat port"), "ycht-port", YAHOO_YCHT_PORT);
339 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
340 #endif
341
342 my_protocol = plugin;
343 yahoo_register_commands();
344 yahoo_init_colorht();
345
346 purple_signal_connect(purple_get_core(), "uri-handler", plugin,
347 PURPLE_CALLBACK(yahoo_uri_handler), NULL);
348 }
349
350 PURPLE_INIT_PLUGIN(yahoo, init_plugin, info);