14192
|
1 /*
|
|
2 * gaim
|
|
3 *
|
|
4 * Gaim 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 *
|
|
22 */
|
|
23
|
|
24 #include "internal.h"
|
|
25
|
|
26 #include "account.h"
|
|
27 #include "accountopt.h"
|
|
28 #include "blist.h"
|
|
29 #include "cipher.h"
|
|
30 #include "cmds.h"
|
|
31 #include "debug.h"
|
|
32 #include "notify.h"
|
|
33 #include "privacy.h"
|
|
34 #include "prpl.h"
|
|
35 #include "proxy.h"
|
|
36 #include "request.h"
|
|
37 #include "server.h"
|
|
38 #include "util.h"
|
|
39 #include "version.h"
|
|
40
|
|
41 #include "yahoo.h"
|
|
42 #include "yahoochat.h"
|
|
43 #include "yahoo_auth.h"
|
|
44 #include "yahoo_crypt.h"
|
|
45 #include "yahoo_doodle.h"
|
|
46 #include "yahoo_filexfer.h"
|
|
47 #include "yahoo_friend.h"
|
|
48 #include "yahoo_packet.h"
|
|
49 #include "yahoo_picture.h"
|
|
50 #include "ycht.h"
|
|
51
|
|
52 /* #define YAHOO_DEBUG */
|
|
53
|
|
54 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *, GaimGroup *);
|
|
55 static void yahoo_login_page_cb(void *user_data, const char *buf, size_t len);
|
|
56 static void yahoo_set_status(GaimAccount *account, GaimStatus *status);
|
|
57
|
|
58 static void
|
|
59 yahoo_add_permit(GaimConnection *gc, const char *who)
|
|
60 {
|
|
61 gaim_debug_info("yahoo",
|
|
62 "Permitting ID %s local contact rights for account %s\n", who, gc->account);
|
|
63 gaim_privacy_permit_add(gc->account,who,TRUE);
|
|
64 }
|
|
65
|
|
66 static void
|
|
67 yahoo_rem_permit(GaimConnection *gc, const char *who)
|
|
68 {
|
|
69 gaim_debug_info("yahoo",
|
|
70 "Denying ID %s local contact rights for account %s\n", who, gc->account);
|
|
71 gaim_privacy_permit_remove(gc->account,who,TRUE);
|
|
72 }
|
|
73
|
|
74 gboolean yahoo_privacy_check(GaimConnection *gc, const char *who)
|
|
75 {
|
|
76 /* returns TRUE if allowed through, FALSE otherwise */
|
|
77 gboolean permitted;
|
|
78
|
|
79 permitted = gaim_privacy_check(gc->account, who);
|
|
80
|
|
81 /* print some debug info */
|
|
82 if (!permitted) {
|
|
83 char *deb = NULL;
|
|
84 switch (gc->account->perm_deny)
|
|
85 {
|
|
86 case GAIM_PRIVACY_DENY_ALL:
|
|
87 deb = "GAIM_PRIVACY_DENY_ALL";
|
|
88 break;
|
|
89 case GAIM_PRIVACY_DENY_USERS:
|
|
90 deb = "GAIM_PRIVACY_DENY_USERS";
|
|
91 break;
|
|
92 case GAIM_PRIVACY_ALLOW_BUDDYLIST:
|
|
93 deb = "GAIM_PRIVACY_ALLOW_BUDDYLIST";
|
|
94 break;
|
|
95 }
|
|
96 if(deb)
|
|
97 gaim_debug_info("yahoo",
|
|
98 "%s blocked data received from %s (%s)\n",
|
|
99 gc->account->username,who, deb);
|
|
100 } else if (gc->account->perm_deny == GAIM_PRIVACY_ALLOW_USERS) {
|
|
101 gaim_debug_info("yahoo",
|
|
102 "%s allowed data received from %s (GAIM_PRIVACY_ALLOW_USERS)\n",
|
|
103 gc->account->username,who);
|
|
104 }
|
|
105
|
|
106 return permitted;
|
|
107 }
|
|
108
|
|
109 static void yahoo_update_status(GaimConnection *gc, const char *name, YahooFriend *f)
|
|
110 {
|
|
111 char *status = NULL;
|
|
112
|
|
113 if (!gc || !name || !f || !gaim_find_buddy(gaim_connection_get_account(gc), name))
|
|
114 return;
|
|
115
|
|
116 if (f->status == YAHOO_STATUS_OFFLINE)
|
|
117 {
|
|
118 return;
|
|
119 }
|
|
120
|
|
121 switch (f->status) {
|
|
122 case YAHOO_STATUS_AVAILABLE:
|
|
123 status = YAHOO_STATUS_TYPE_AVAILABLE;
|
|
124 break;
|
|
125 case YAHOO_STATUS_BRB:
|
|
126 status = YAHOO_STATUS_TYPE_BRB;
|
|
127 break;
|
|
128 case YAHOO_STATUS_BUSY:
|
|
129 status = YAHOO_STATUS_TYPE_BUSY;
|
|
130 break;
|
|
131 case YAHOO_STATUS_NOTATHOME:
|
|
132 status = YAHOO_STATUS_TYPE_NOTATHOME;
|
|
133 break;
|
|
134 case YAHOO_STATUS_NOTATDESK:
|
|
135 status = YAHOO_STATUS_TYPE_NOTATDESK;
|
|
136 break;
|
|
137 case YAHOO_STATUS_NOTINOFFICE:
|
|
138 status = YAHOO_STATUS_TYPE_NOTINOFFICE;
|
|
139 break;
|
|
140 case YAHOO_STATUS_ONPHONE:
|
|
141 status = YAHOO_STATUS_TYPE_ONPHONE;
|
|
142 break;
|
|
143 case YAHOO_STATUS_ONVACATION:
|
|
144 status = YAHOO_STATUS_TYPE_ONVACATION;
|
|
145 break;
|
|
146 case YAHOO_STATUS_OUTTOLUNCH:
|
|
147 status = YAHOO_STATUS_TYPE_OUTTOLUNCH;
|
|
148 break;
|
|
149 case YAHOO_STATUS_STEPPEDOUT:
|
|
150 status = YAHOO_STATUS_TYPE_STEPPEDOUT;
|
|
151 break;
|
|
152 case YAHOO_STATUS_INVISIBLE: /* this should never happen? */
|
|
153 status = YAHOO_STATUS_TYPE_INVISIBLE;
|
|
154 break;
|
|
155 case YAHOO_STATUS_CUSTOM:
|
|
156 case YAHOO_STATUS_IDLE:
|
|
157 if (!f->away)
|
|
158 status = YAHOO_STATUS_TYPE_AVAILABLE;
|
|
159 else
|
|
160 status = YAHOO_STATUS_TYPE_AWAY;
|
|
161 break;
|
|
162 default:
|
|
163 gaim_debug_warning("yahoo", "Warning, unknown status %d\n", f->status);
|
|
164 break;
|
|
165 }
|
|
166
|
|
167 if (status) {
|
|
168 if (f->status == YAHOO_STATUS_CUSTOM)
|
|
169 gaim_prpl_got_user_status(gaim_connection_get_account(gc), name, status, "message",
|
|
170 yahoo_friend_get_status_message(f), NULL);
|
|
171 else
|
|
172 gaim_prpl_got_user_status(gaim_connection_get_account(gc), name, status, NULL);
|
|
173 }
|
|
174
|
|
175 if (f->idle != 0)
|
|
176 gaim_prpl_got_user_idle(gaim_connection_get_account(gc), name, TRUE, f->idle);
|
|
177 else
|
|
178 gaim_prpl_got_user_idle(gaim_connection_get_account(gc), name, FALSE, 0);
|
|
179 }
|
|
180
|
|
181 static void yahoo_process_status(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
182 {
|
|
183 GaimAccount *account = gaim_connection_get_account(gc);
|
|
184 struct yahoo_data *yd = gc->proto_data;
|
|
185 GSList *l = pkt->hash;
|
|
186 YahooFriend *f = NULL;
|
|
187 char *name = NULL;
|
|
188
|
|
189 if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) {
|
|
190 gc->wants_to_die = TRUE;
|
|
191 gaim_connection_error(gc, _("You have signed on from another location."));
|
|
192 return;
|
|
193 }
|
|
194
|
|
195 while (l) {
|
|
196 struct yahoo_pair *pair = l->data;
|
|
197
|
|
198 switch (pair->key) {
|
|
199 case 0: /* we won't actually do anything with this */
|
|
200 break;
|
|
201 case 1: /* we don't get the full buddy list here. */
|
|
202 if (!yd->logged_in) {
|
|
203 gaim_connection_set_display_name(gc, pair->value);
|
|
204 gaim_connection_set_state(gc, GAIM_CONNECTED);
|
|
205 yd->logged_in = TRUE;
|
|
206 if (yd->picture_upload_todo) {
|
|
207 yahoo_buddy_icon_upload(gc, yd->picture_upload_todo);
|
|
208 yd->picture_upload_todo = NULL;
|
|
209 }
|
|
210 yahoo_set_status(account, gaim_account_get_active_status(account));
|
|
211
|
|
212 /* this requests the list. i have a feeling that this is very evil
|
|
213 *
|
|
214 * scs.yahoo.com sends you the list before this packet without it being
|
|
215 * requested
|
|
216 *
|
|
217 * do_import(gc, NULL);
|
|
218 * newpkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_OFFLINE, 0);
|
|
219 * yahoo_packet_send_and_free(newpkt, yd);
|
|
220 */
|
|
221
|
|
222 }
|
|
223 break;
|
|
224 case 8: /* how many online buddies we have */
|
|
225 break;
|
|
226 case 7: /* the current buddy */
|
|
227 if (name && f) /* update the previous buddy before changing the variables */
|
|
228 yahoo_update_status(gc, name, f);
|
|
229 name = pair->value;
|
|
230 if (name && g_utf8_validate(name, -1, NULL))
|
|
231 f = yahoo_friend_find_or_new(gc, name);
|
|
232 else {
|
|
233 f = NULL;
|
|
234 name = NULL;
|
|
235 }
|
|
236 break;
|
|
237 case 10: /* state */
|
|
238 if (!f)
|
|
239 break;
|
|
240
|
|
241 f->status = strtol(pair->value, NULL, 10);
|
|
242 if ((f->status >= YAHOO_STATUS_BRB) && (f->status <= YAHOO_STATUS_STEPPEDOUT))
|
|
243 f->away = 1;
|
|
244 else
|
|
245 f->away = 0;
|
|
246
|
|
247 if (f->status == YAHOO_STATUS_IDLE) {
|
|
248 /* Idle may have already been set in a more precise way in case 137 */
|
|
249 if (f->idle == 0)
|
|
250 f->idle = time(NULL);
|
|
251 } else
|
|
252 f->idle = 0;
|
|
253
|
|
254 if (f->status != YAHOO_STATUS_CUSTOM)
|
|
255 yahoo_friend_set_status_message(f, NULL);
|
|
256
|
|
257 f->sms = 0;
|
|
258 break;
|
|
259 case 19: /* custom message */
|
|
260 if (f)
|
|
261 yahoo_friend_set_status_message(f, yahoo_string_decode(gc, pair->value, FALSE));
|
|
262 break;
|
|
263 case 11: /* this is the buddy's session id */
|
|
264 break;
|
|
265 case 17: /* in chat? */
|
|
266 break;
|
|
267 case 47: /* is custom status away or not? 2=idle*/
|
|
268 if (!f)
|
|
269 break;
|
|
270
|
|
271 /* I have no idea what it means when this is
|
|
272 * set when someone's available, but it doesn't
|
|
273 * mean idle. */
|
|
274 if (f->status == YAHOO_STATUS_AVAILABLE)
|
|
275 break;
|
|
276
|
|
277 f->away = strtol(pair->value, NULL, 10);
|
|
278 if (f->away == 2) {
|
|
279 /* Idle may have already been set in a more precise way in case 137 */
|
|
280 if (f->idle == 0)
|
|
281 f->idle = time(NULL);
|
|
282 }
|
|
283
|
|
284 break;
|
|
285 case 138: /* either we're not idle, or we are but won't say how long */
|
|
286 if (!f)
|
|
287 break;
|
|
288
|
|
289 if (f->idle)
|
|
290 f->idle = -1;
|
|
291 break;
|
|
292 case 137: /* usually idle time in seconds, sometimes login time */
|
|
293 if (!f)
|
|
294 break;
|
|
295
|
|
296 if (f->status != YAHOO_STATUS_AVAILABLE)
|
|
297 f->idle = time(NULL) - strtol(pair->value, NULL, 10);
|
|
298 break;
|
|
299 case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */
|
|
300 if (strtol(pair->value, NULL, 10) == 0) {
|
|
301 if (f)
|
|
302 f->status = YAHOO_STATUS_OFFLINE;
|
|
303 gaim_prpl_got_user_status(account, name, "offline", NULL);
|
|
304 break;
|
|
305 }
|
|
306 break;
|
|
307 case 60: /* SMS */
|
|
308 if (f) {
|
|
309 f->sms = strtol(pair->value, NULL, 10);
|
|
310 yahoo_update_status(gc, name, f);
|
|
311 }
|
|
312 break;
|
|
313 case 197: /* Avatars */
|
|
314 {
|
|
315 guchar *decoded;
|
|
316 char *tmp;
|
|
317 gsize len;
|
|
318
|
|
319 if (pair->value) {
|
|
320 decoded = gaim_base64_decode(pair->value, &len);
|
|
321 if (len) {
|
|
322 tmp = gaim_str_binary_to_ascii(decoded, len);
|
|
323 gaim_debug_info("yahoo", "Got key 197, value = %s\n", tmp);
|
|
324 g_free(tmp);
|
|
325 }
|
|
326 g_free(decoded);
|
|
327 }
|
|
328 break;
|
|
329 }
|
|
330 case 192: /* Pictures, aka Buddy Icons, checksum */
|
|
331 {
|
|
332 int cksum = strtol(pair->value, NULL, 10);
|
|
333 GaimBuddy *b;
|
|
334
|
|
335 if (!name)
|
|
336 break;
|
|
337
|
|
338 b = gaim_find_buddy(gc->account, name);
|
|
339
|
|
340 if (!cksum || (cksum == -1)) {
|
|
341 if (f)
|
|
342 yahoo_friend_set_buddy_icon_need_request(f, TRUE);
|
|
343 gaim_buddy_icons_set_for_user(gc->account, name, NULL, 0);
|
|
344 if (b)
|
|
345 gaim_blist_node_remove_setting((GaimBlistNode *)b, YAHOO_ICON_CHECKSUM_KEY);
|
|
346 break;
|
|
347 }
|
|
348
|
|
349 if (!f)
|
|
350 break;
|
|
351
|
|
352 yahoo_friend_set_buddy_icon_need_request(f, FALSE);
|
|
353 if (b && cksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY))
|
|
354 yahoo_send_picture_request(gc, name);
|
|
355
|
|
356 break;
|
|
357 }
|
|
358 case 16: /* Custom error message */
|
|
359 {
|
|
360 char *tmp = yahoo_string_decode(gc, pair->value, TRUE);
|
|
361 gaim_notify_error(gc, NULL, tmp, NULL);
|
|
362 g_free(tmp);
|
|
363 }
|
|
364 break;
|
|
365 default:
|
|
366 gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
|
|
367 "Unknown status key %d\n", pair->key);
|
|
368 break;
|
|
369 }
|
|
370
|
|
371 l = l->next;
|
|
372 }
|
|
373
|
|
374 if (name && f) /* update the last buddy */
|
|
375 yahoo_update_status(gc, name, f);
|
|
376 }
|
|
377
|
|
378 static void yahoo_do_group_check(GaimAccount *account, GHashTable *ht, const char *name, const char *group)
|
|
379 {
|
|
380 GaimBuddy *b;
|
|
381 GaimGroup *g;
|
|
382 GSList *list, *i;
|
|
383 gboolean onlist = 0;
|
|
384 char *oname = NULL;
|
|
385 char **oname_p = &oname;
|
|
386 GSList **list_p = &list;
|
|
387
|
|
388 if (!g_hash_table_lookup_extended(ht, gaim_normalize(account, name), (gpointer *) oname_p, (gpointer *) list_p))
|
|
389 list = gaim_find_buddies(account, name);
|
|
390 else
|
|
391 g_hash_table_steal(ht, name);
|
|
392
|
|
393 for (i = list; i; i = i->next) {
|
|
394 b = i->data;
|
|
395 g = gaim_buddy_get_group(b);
|
|
396 if (!gaim_utf8_strcasecmp(group, g->name)) {
|
|
397 gaim_debug(GAIM_DEBUG_MISC, "yahoo",
|
|
398 "Oh good, %s is in the right group (%s).\n", name, group);
|
|
399 list = g_slist_delete_link(list, i);
|
|
400 onlist = 1;
|
|
401 break;
|
|
402 }
|
|
403 }
|
|
404
|
|
405 if (!onlist) {
|
|
406 gaim_debug(GAIM_DEBUG_MISC, "yahoo",
|
|
407 "Uhoh, %s isn't on the list (or not in this group), adding him to group %s.\n", name, group);
|
|
408 if (!(g = gaim_find_group(group))) {
|
|
409 g = gaim_group_new(group);
|
|
410 gaim_blist_add_group(g, NULL);
|
|
411 }
|
|
412 b = gaim_buddy_new(account, name, NULL);
|
|
413 gaim_blist_add_buddy(b, NULL, g, NULL);
|
|
414 }
|
|
415
|
|
416 if (list) {
|
|
417 if (!oname)
|
|
418 oname = g_strdup(gaim_normalize(account, name));
|
|
419 g_hash_table_insert(ht, oname, list);
|
|
420 } else if (oname)
|
|
421 g_free(oname);
|
|
422 }
|
|
423
|
|
424 static void yahoo_do_group_cleanup(gpointer key, gpointer value, gpointer user_data)
|
|
425 {
|
|
426 char *name = key;
|
|
427 GSList *list = value, *i;
|
|
428 GaimBuddy *b;
|
|
429 GaimGroup *g;
|
|
430
|
|
431 for (i = list; i; i = i->next) {
|
|
432 b = i->data;
|
|
433 g = gaim_buddy_get_group(b);
|
|
434 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Deleting Buddy %s from group %s.\n", name, g->name);
|
|
435 gaim_blist_remove_buddy(b);
|
|
436 }
|
|
437 }
|
|
438
|
|
439 static char *_getcookie(char *rawcookie)
|
|
440 {
|
|
441 char *cookie = NULL;
|
|
442 char *tmpcookie;
|
|
443 char *cookieend;
|
|
444
|
|
445 if (strlen(rawcookie) < 2)
|
|
446 return NULL;
|
|
447 tmpcookie = g_strdup(rawcookie+2);
|
|
448 cookieend = strchr(tmpcookie, ';');
|
|
449
|
|
450 if (cookieend)
|
|
451 *cookieend = '\0';
|
|
452
|
|
453 cookie = g_strdup(tmpcookie);
|
|
454 g_free(tmpcookie);
|
|
455
|
|
456 return cookie;
|
|
457 }
|
|
458
|
|
459 static void yahoo_process_cookie(struct yahoo_data *yd, char *c)
|
|
460 {
|
|
461 if (c[0] == 'Y') {
|
|
462 if (yd->cookie_y)
|
|
463 g_free(yd->cookie_y);
|
|
464 yd->cookie_y = _getcookie(c);
|
|
465 } else if (c[0] == 'T') {
|
|
466 if (yd->cookie_t)
|
|
467 g_free(yd->cookie_t);
|
|
468 yd->cookie_t = _getcookie(c);
|
|
469 }
|
|
470 }
|
|
471
|
14258
|
472 static void yahoo_process_list_15(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
473 {
|
|
474 GSList *l = pkt->hash;
|
|
475
|
|
476 GaimAccount *account = gaim_connection_get_account(gc);
|
|
477 GHashTable *ht;
|
|
478 char *grp = NULL;
|
|
479 char *norm_bud = NULL;
|
14300
|
480 YahooFriend *f = NULL; /* It's your friends. They're going to want you to share your StarBursts. */
|
|
481 /* But what if you had no friends? */
|
|
482 GaimBuddy *b;
|
|
483 GaimGroup *g;
|
|
484
|
14258
|
485
|
|
486 ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_slist_free);
|
|
487
|
|
488 while (l) {
|
|
489 struct yahoo_pair *pair = l->data;
|
|
490 l = l->next;
|
|
491
|
|
492 switch (pair->key) {
|
|
493 case 302: /* what is this? it's always 318 before a group, 319 before a s/n */
|
|
494 case 300: /* ditto */
|
|
495 break;
|
|
496 case 65: /* This is the group */
|
|
497 g_free(grp);
|
|
498 grp = yahoo_string_decode(gc, pair->value, FALSE);
|
|
499 break;
|
|
500 case 7: /* buddy's s/n */
|
|
501 g_free(norm_bud);
|
|
502 norm_bud = g_strdup(gaim_normalize(account, pair->value));
|
|
503 f = yahoo_friend_find_or_new(gc, norm_bud);
|
|
504 if (!(b = gaim_find_buddy(account, norm_bud))) {
|
|
505 if (!(g = gaim_find_group(grp))) {
|
|
506 g = gaim_group_new(grp);
|
|
507 gaim_blist_add_group(g, NULL);
|
|
508 }
|
|
509 b = gaim_buddy_new(account, norm_bud, NULL);
|
|
510 gaim_blist_add_buddy(b, NULL, g, NULL);
|
|
511 }
|
|
512 yahoo_do_group_check(account, ht, norm_bud, grp);
|
|
513
|
|
514 break;
|
14284
|
515 case 241: /* another protocol user */
|
14300
|
516 if (f) {
|
14284
|
517 f->protocol = strtol(pair->value, NULL, 10);
|
14300
|
518 gaim_debug_info("yahoo", "Setting protocol to %d\n", f->protocol);
|
|
519 }
|
14258
|
520 break;
|
|
521 /* case 242: */ /* this seems related to 241 */
|
|
522 /* break; */
|
|
523 }
|
|
524 }
|
|
525
|
|
526 g_hash_table_foreach(ht, yahoo_do_group_cleanup, NULL);
|
|
527 g_hash_table_destroy(ht);
|
|
528 g_free(grp);
|
|
529 g_free(norm_bud);
|
|
530 }
|
|
531
|
14192
|
532 static void yahoo_process_list(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
533 {
|
|
534 GSList *l = pkt->hash;
|
|
535 gboolean export = FALSE;
|
|
536 gboolean got_serv_list = FALSE;
|
|
537 GaimBuddy *b;
|
|
538 GaimGroup *g;
|
|
539 YahooFriend *f = NULL;
|
|
540 GaimAccount *account = gaim_connection_get_account(gc);
|
|
541 struct yahoo_data *yd = gc->proto_data;
|
|
542 GHashTable *ht;
|
|
543
|
|
544 char **lines;
|
|
545 char **split;
|
|
546 char **buddies;
|
|
547 char **tmp, **bud, *norm_bud;
|
|
548 char *grp = NULL;
|
|
549
|
|
550 if (pkt->id)
|
|
551 yd->session_id = pkt->id;
|
|
552
|
|
553 while (l) {
|
|
554 struct yahoo_pair *pair = l->data;
|
|
555 l = l->next;
|
|
556
|
|
557 switch (pair->key) {
|
|
558 case 87:
|
|
559 if (!yd->tmp_serv_blist)
|
|
560 yd->tmp_serv_blist = g_string_new(pair->value);
|
|
561 else
|
|
562 g_string_append(yd->tmp_serv_blist, pair->value);
|
|
563 break;
|
|
564 case 88:
|
|
565 if (!yd->tmp_serv_ilist)
|
|
566 yd->tmp_serv_ilist = g_string_new(pair->value);
|
|
567 else
|
|
568 g_string_append(yd->tmp_serv_ilist, pair->value);
|
|
569 break;
|
|
570 case 59: /* cookies, yum */
|
|
571 yahoo_process_cookie(yd, pair->value);
|
|
572 break;
|
|
573 case YAHOO_SERVICE_PRESENCE_PERM:
|
|
574 if (!yd->tmp_serv_plist)
|
|
575 yd->tmp_serv_plist = g_string_new(pair->value);
|
|
576 else
|
|
577 g_string_append(yd->tmp_serv_plist, pair->value);
|
|
578 break;
|
|
579 }
|
|
580 }
|
|
581
|
|
582 if (pkt->status != 0)
|
|
583 return;
|
|
584
|
|
585 if (yd->tmp_serv_blist) {
|
|
586 ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_slist_free);
|
|
587
|
|
588 lines = g_strsplit(yd->tmp_serv_blist->str, "\n", -1);
|
|
589 for (tmp = lines; *tmp; tmp++) {
|
|
590 split = g_strsplit(*tmp, ":", 2);
|
|
591 if (!split)
|
|
592 continue;
|
|
593 if (!split[0] || !split[1]) {
|
|
594 g_strfreev(split);
|
|
595 continue;
|
|
596 }
|
|
597 grp = yahoo_string_decode(gc, split[0], FALSE);
|
|
598 buddies = g_strsplit(split[1], ",", -1);
|
|
599 for (bud = buddies; bud && *bud; bud++) {
|
|
600 norm_bud = g_strdup(gaim_normalize(account, *bud));
|
|
601 f = yahoo_friend_find_or_new(gc, norm_bud);
|
|
602
|
|
603 if (!(b = gaim_find_buddy(account, norm_bud))) {
|
|
604 if (!(g = gaim_find_group(grp))) {
|
|
605 g = gaim_group_new(grp);
|
|
606 gaim_blist_add_group(g, NULL);
|
|
607 }
|
|
608 b = gaim_buddy_new(account, norm_bud, NULL);
|
|
609 gaim_blist_add_buddy(b, NULL, g, NULL);
|
|
610 export = TRUE;
|
|
611 }
|
|
612
|
|
613 yahoo_do_group_check(account, ht, norm_bud, grp);
|
|
614 g_free(norm_bud);
|
|
615 }
|
|
616 g_strfreev(buddies);
|
|
617 g_strfreev(split);
|
|
618 g_free(grp);
|
|
619 }
|
|
620 g_strfreev(lines);
|
|
621
|
|
622 g_string_free(yd->tmp_serv_blist, TRUE);
|
|
623 yd->tmp_serv_blist = NULL;
|
|
624 g_hash_table_foreach(ht, yahoo_do_group_cleanup, NULL);
|
|
625 g_hash_table_destroy(ht);
|
|
626 }
|
|
627
|
|
628 if (yd->tmp_serv_ilist) {
|
|
629 buddies = g_strsplit(yd->tmp_serv_ilist->str, ",", -1);
|
|
630 for (bud = buddies; bud && *bud; bud++) {
|
|
631 /* The server is already ignoring the user */
|
|
632 got_serv_list = TRUE;
|
|
633 gaim_privacy_deny_add(gc->account, *bud, 1);
|
|
634 }
|
|
635 g_strfreev(buddies);
|
|
636
|
|
637 g_string_free(yd->tmp_serv_ilist, TRUE);
|
|
638 yd->tmp_serv_ilist = NULL;
|
|
639 }
|
|
640
|
|
641 if (got_serv_list &&
|
|
642 ((gc->account->perm_deny != GAIM_PRIVACY_ALLOW_BUDDYLIST) &&
|
|
643 (gc->account->perm_deny != GAIM_PRIVACY_DENY_ALL) &&
|
|
644 (gc->account->perm_deny != GAIM_PRIVACY_ALLOW_USERS)))
|
|
645 {
|
|
646 gc->account->perm_deny = GAIM_PRIVACY_DENY_USERS;
|
|
647 gaim_debug_info("yahoo", "%s privacy defaulting to GAIM_PRIVACY_DENY_USERS.\n",
|
|
648 gc->account->username);
|
|
649 }
|
|
650
|
|
651 if (yd->tmp_serv_plist) {
|
|
652 buddies = g_strsplit(yd->tmp_serv_plist->str, ",", -1);
|
|
653 for (bud = buddies; bud && *bud; bud++) {
|
|
654 f = yahoo_friend_find(gc, *bud);
|
|
655 if (f) {
|
|
656 gaim_debug_info("yahoo", "%s setting presence for %s to PERM_OFFLINE\n",
|
|
657 gc->account->username, *bud);
|
|
658 f->presence = YAHOO_PRESENCE_PERM_OFFLINE;
|
|
659 }
|
|
660 }
|
|
661 g_strfreev(buddies);
|
|
662 g_string_free(yd->tmp_serv_plist, TRUE);
|
|
663 yd->tmp_serv_plist = NULL;
|
|
664
|
|
665 }
|
|
666 }
|
|
667
|
|
668 static void yahoo_process_notify(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
669 {
|
|
670 char *msg = NULL;
|
|
671 char *from = NULL;
|
|
672 char *stat = NULL;
|
|
673 char *game = NULL;
|
|
674 YahooFriend *f = NULL;
|
|
675 GSList *l = pkt->hash;
|
|
676
|
|
677 while (l) {
|
|
678 struct yahoo_pair *pair = l->data;
|
|
679 if (pair->key == 4)
|
|
680 from = pair->value;
|
|
681 if (pair->key == 49)
|
|
682 msg = pair->value;
|
|
683 if (pair->key == 13)
|
|
684 stat = pair->value;
|
|
685 if (pair->key == 14)
|
|
686 game = pair->value;
|
|
687 l = l->next;
|
|
688 }
|
|
689
|
|
690 if (!from || !msg)
|
|
691 return;
|
|
692
|
|
693 if (!g_ascii_strncasecmp(msg, "TYPING", strlen("TYPING"))
|
|
694 && (yahoo_privacy_check(gc, from))) {
|
|
695 if (*stat == '1')
|
|
696 serv_got_typing(gc, from, 0, GAIM_TYPING);
|
|
697 else
|
|
698 serv_got_typing_stopped(gc, from);
|
|
699 } else if (!g_ascii_strncasecmp(msg, "GAME", strlen("GAME"))) {
|
|
700 GaimBuddy *bud = gaim_find_buddy(gc->account, from);
|
|
701
|
|
702 if (!bud) {
|
|
703 gaim_debug(GAIM_DEBUG_WARNING, "yahoo",
|
|
704 "%s is playing a game, and doesn't want "
|
|
705 "you to know.\n", from);
|
|
706 }
|
|
707
|
|
708 f = yahoo_friend_find(gc, from);
|
|
709 if (!f)
|
|
710 return; /* if they're not on the list, don't bother */
|
|
711
|
|
712 yahoo_friend_set_game(f, NULL);
|
|
713
|
|
714 if (*stat == '1') {
|
|
715 yahoo_friend_set_game(f, game);
|
|
716 if (bud)
|
|
717 yahoo_update_status(gc, from, f);
|
|
718 }
|
|
719 }
|
|
720 }
|
|
721
|
|
722
|
|
723 struct _yahoo_im {
|
|
724 char *from;
|
|
725 int time;
|
|
726 int utf8;
|
|
727 int buddy_icon;
|
|
728 char *msg;
|
|
729 };
|
|
730
|
|
731 static void yahoo_process_message(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
732 {
|
|
733 struct yahoo_data *yd = gc->proto_data;
|
|
734 GSList *l = pkt->hash;
|
|
735 GSList *list = NULL;
|
|
736 struct _yahoo_im *im = NULL;
|
|
737
|
|
738 const char *imv = NULL;
|
|
739
|
|
740 if (pkt->status <= 1 || pkt->status == 5) {
|
|
741 while (l != NULL) {
|
|
742 struct yahoo_pair *pair = l->data;
|
|
743 if (pair->key == 4) {
|
|
744 im = g_new0(struct _yahoo_im, 1);
|
|
745 list = g_slist_append(list, im);
|
|
746 im->from = pair->value;
|
|
747 im->time = time(NULL);
|
|
748 }
|
|
749 if (pair->key == 97)
|
|
750 if (im)
|
|
751 im->utf8 = strtol(pair->value, NULL, 10);
|
|
752 if (pair->key == 15)
|
|
753 if (im)
|
|
754 im->time = strtol(pair->value, NULL, 10);
|
|
755 if (pair->key == 206)
|
|
756 if (im)
|
|
757 im->buddy_icon = strtol(pair->value, NULL, 10);
|
|
758 if (pair->key == 14) {
|
|
759 if (im)
|
|
760 im->msg = pair->value;
|
|
761 }
|
|
762 /* IMV key */
|
|
763 if (pair->key == 63)
|
|
764 {
|
|
765 imv = pair->value;
|
|
766 }
|
|
767 l = l->next;
|
|
768 }
|
|
769 } else if (pkt->status == 2) {
|
|
770 gaim_notify_error(gc, NULL,
|
|
771 _("Your Yahoo! message did not get sent."), NULL);
|
|
772 }
|
|
773
|
|
774 /** TODO: It seems that this check should be per IM, not global */
|
|
775 /* Check for the Doodle IMV */
|
|
776 if (im != NULL && imv!= NULL && im->from != NULL)
|
|
777 {
|
|
778 g_hash_table_replace(yd->imvironments, g_strdup(im->from), g_strdup(imv));
|
|
779
|
|
780 if (strcmp(imv, "doodle;11") == 0)
|
|
781 {
|
|
782 GaimWhiteboard *wb;
|
|
783
|
|
784 if (!yahoo_privacy_check(gc, im->from)) {
|
|
785 gaim_debug_info("yahoo", "Doodle request from %s dropped.\n", im->from);
|
|
786 return;
|
|
787 }
|
|
788
|
|
789 wb = gaim_whiteboard_get_session(gc->account, im->from);
|
|
790
|
|
791 /* If a Doodle session doesn't exist between this user */
|
|
792 if(wb == NULL)
|
|
793 {
|
|
794 wb = gaim_whiteboard_create(gc->account, im->from, DOODLE_STATE_REQUESTED);
|
|
795
|
|
796 yahoo_doodle_command_send_request(gc, im->from);
|
|
797 yahoo_doodle_command_send_ready(gc, im->from);
|
|
798 }
|
|
799 }
|
|
800 }
|
|
801
|
|
802 for (l = list; l; l = l->next) {
|
|
803 YahooFriend *f;
|
|
804 char *m, *m2;
|
|
805 im = l->data;
|
|
806
|
|
807 if (!im->from || !im->msg) {
|
|
808 g_free(im);
|
|
809 continue;
|
|
810 }
|
|
811
|
|
812 if (!yahoo_privacy_check(gc, im->from)) {
|
|
813 gaim_debug_info("yahoo", "Message from %s dropped.\n", im->from);
|
|
814 return;
|
|
815 }
|
|
816
|
|
817 m = yahoo_string_decode(gc, im->msg, im->utf8);
|
|
818 /* This may actually not be necessary, but it appears
|
|
819 * that at least at one point some clients were sending
|
|
820 * "\r\n" as line delimiters, so we want to avoid double
|
|
821 * lines. */
|
|
822 m2 = gaim_strreplace(m, "\r\n", "\n");
|
|
823 g_free(m);
|
|
824 m = m2;
|
|
825 gaim_util_chrreplace(m, '\r', '\n');
|
|
826
|
|
827 if (!strcmp(m, "<ding>")) {
|
|
828 GaimConversation *c = gaim_conversation_new(GAIM_CONV_TYPE_IM,
|
|
829 gaim_connection_get_account(gc), im->from);
|
|
830 gaim_conv_im_write(GAIM_CONV_IM(c), "", _("Buzz!!"), GAIM_MESSAGE_NICK|GAIM_MESSAGE_RECV,
|
|
831 im->time);
|
|
832 g_free(m);
|
|
833 g_free(im);
|
|
834 continue;
|
|
835 }
|
|
836
|
|
837 m2 = yahoo_codes_to_html(m);
|
|
838 g_free(m);
|
|
839 serv_got_im(gc, im->from, m2, 0, im->time);
|
|
840 g_free(m2);
|
|
841
|
|
842 if ((f = yahoo_friend_find(gc, im->from)) && im->buddy_icon == 2) {
|
|
843 if (yahoo_friend_get_buddy_icon_need_request(f)) {
|
|
844 yahoo_send_picture_request(gc, im->from);
|
|
845 yahoo_friend_set_buddy_icon_need_request(f, FALSE);
|
|
846 }
|
|
847 }
|
|
848
|
|
849 g_free(im);
|
|
850 }
|
|
851 g_slist_free(list);
|
|
852 }
|
|
853
|
|
854 static void yahoo_process_sysmessage(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
855 {
|
|
856 GSList *l = pkt->hash;
|
|
857 char *prim, *me = NULL, *msg = NULL, *escmsg = NULL;
|
|
858
|
|
859 while (l) {
|
|
860 struct yahoo_pair *pair = l->data;
|
|
861
|
|
862 if (pair->key == 5)
|
|
863 me = pair->value;
|
|
864 if (pair->key == 14)
|
|
865 msg = pair->value;
|
|
866
|
|
867 l = l->next;
|
|
868 }
|
|
869
|
|
870 if (!msg || !g_utf8_validate(msg, -1, NULL))
|
|
871 return;
|
|
872
|
|
873 /* TODO: Does this really need to be escaped? It seems like it doesn't. */
|
|
874 escmsg = g_markup_escape_text(msg, -1);
|
|
875
|
|
876 prim = g_strdup_printf(_("Yahoo! system message for %s:"),
|
|
877 me?me:gaim_connection_get_display_name(gc));
|
|
878 gaim_notify_info(NULL, NULL, prim, escmsg);
|
|
879 g_free(prim);
|
|
880 g_free(escmsg);
|
|
881 }
|
|
882
|
|
883 struct yahoo_add_request {
|
|
884 GaimConnection *gc;
|
|
885 char *id;
|
|
886 char *who;
|
|
887 char *msg;
|
|
888 };
|
|
889
|
|
890 static void
|
|
891 yahoo_buddy_add_authorize_cb(struct yahoo_add_request *add_req, const char *msg) {
|
|
892 GaimBuddy *buddy = gaim_find_buddy(add_req->gc->account, add_req->who);
|
|
893
|
|
894 if (buddy != NULL)
|
|
895 gaim_account_notify_added(add_req->gc->account, add_req->who,
|
|
896 add_req->id, NULL, add_req->msg);
|
|
897 else
|
|
898 gaim_account_request_add(add_req->gc->account, add_req->who,
|
|
899 add_req->id, NULL, add_req->msg);
|
|
900
|
|
901 g_free(add_req->id);
|
|
902 g_free(add_req->who);
|
|
903 g_free(add_req->msg);
|
|
904 g_free(add_req);
|
|
905 }
|
|
906
|
|
907 static void
|
|
908 yahoo_buddy_add_deny_cb(struct yahoo_add_request *add_req, const char *msg) {
|
|
909 struct yahoo_packet *pkt;
|
|
910 char *encoded_msg = NULL;
|
|
911 struct yahoo_data *yd = add_req->gc->proto_data;
|
|
912
|
|
913 if (msg)
|
|
914 encoded_msg = yahoo_string_encode(add_req->gc, msg, NULL);
|
|
915
|
|
916 pkt = yahoo_packet_new(YAHOO_SERVICE_REJECTCONTACT,
|
|
917 YAHOO_STATUS_AVAILABLE, 0);
|
|
918
|
|
919 yahoo_packet_hash(pkt, "sss",
|
|
920 1, gaim_normalize(add_req->gc->account,
|
|
921 gaim_account_get_username(
|
|
922 gaim_connection_get_account(
|
|
923 add_req->gc))),
|
|
924 7, add_req->who,
|
|
925 14, encoded_msg ? encoded_msg : "");
|
|
926
|
|
927 yahoo_packet_send_and_free(pkt, yd);
|
|
928
|
|
929 g_free(encoded_msg);
|
|
930
|
|
931 g_free(add_req->id);
|
|
932 g_free(add_req->who);
|
|
933 g_free(add_req->msg);
|
|
934 g_free(add_req);
|
|
935 }
|
|
936
|
|
937 static void yahoo_buddy_added_us(GaimConnection *gc, struct yahoo_packet *pkt) {
|
|
938 struct yahoo_add_request *add_req;
|
|
939 char *msg = NULL;
|
|
940 GSList *l = pkt->hash;
|
|
941
|
|
942 add_req = g_new0(struct yahoo_add_request, 1);
|
|
943 add_req->gc = gc;
|
|
944
|
|
945 while (l) {
|
|
946 struct yahoo_pair *pair = l->data;
|
|
947
|
|
948 switch (pair->key) {
|
|
949 case 1:
|
|
950 add_req->id = g_strdup(pair->value);
|
|
951 break;
|
|
952 case 3:
|
|
953 add_req->who = g_strdup(pair->value);
|
|
954 break;
|
|
955 case 15: /* time, for when they add us and we're offline */
|
|
956 break;
|
|
957 case 14:
|
|
958 msg = pair->value;
|
|
959 break;
|
|
960 }
|
|
961 l = l->next;
|
|
962 }
|
|
963
|
|
964 if (add_req->id) {
|
|
965 char *prompt_msg;
|
|
966 if (msg)
|
|
967 add_req->msg = yahoo_string_decode(gc, msg, FALSE);
|
|
968
|
|
969 /* TODO: this is almost exactly the same as what MSN does,
|
|
970 * this should probably be moved to the core.
|
|
971 */
|
|
972 prompt_msg = g_strdup_printf(_("The user %s wants to add %s to "
|
|
973 "his or her buddy list%s%s."),
|
|
974 add_req->who, add_req->id,
|
|
975 add_req->msg ? ": " : "",
|
|
976 add_req->msg ? add_req->msg : "");
|
|
977 gaim_request_input(gc, NULL, prompt_msg,
|
|
978 _("Message (optional) :"),
|
|
979 NULL, TRUE, FALSE, NULL,
|
|
980 _("Authorize"), G_CALLBACK(
|
|
981 yahoo_buddy_add_authorize_cb),
|
|
982 _("Deny"), G_CALLBACK(
|
|
983 yahoo_buddy_add_deny_cb),
|
|
984 add_req);
|
|
985 g_free(prompt_msg);
|
|
986 } else {
|
|
987 g_free(add_req->id);
|
|
988 g_free(add_req->who);
|
|
989 /*g_free(add_req->msg);*/
|
|
990 g_free(add_req);
|
|
991 }
|
|
992 }
|
|
993
|
|
994 static void yahoo_buddy_denied_our_add(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
995 {
|
|
996 char *who = NULL;
|
|
997 char *msg = NULL;
|
|
998 GSList *l = pkt->hash;
|
|
999 GString *buf = NULL;
|
|
1000 struct yahoo_data *yd = gc->proto_data;
|
|
1001
|
|
1002 while (l) {
|
|
1003 struct yahoo_pair *pair = l->data;
|
|
1004
|
|
1005 switch (pair->key) {
|
|
1006 case 3:
|
|
1007 who = pair->value;
|
|
1008 break;
|
|
1009 case 14:
|
|
1010 msg = pair->value;
|
|
1011 break;
|
|
1012 }
|
|
1013 l = l->next;
|
|
1014 }
|
|
1015
|
|
1016 if (who) {
|
|
1017 char *msg2;
|
|
1018 buf = g_string_sized_new(0);
|
|
1019 if (!msg) {
|
|
1020 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list."), who);
|
|
1021 } else {
|
|
1022 msg2 = yahoo_string_decode(gc, msg, FALSE);
|
|
1023 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list for the following reason: %s."), who, msg2);
|
|
1024 g_free(msg2);
|
|
1025 }
|
|
1026 gaim_notify_info(gc, NULL, _("Add buddy rejected"), buf->str);
|
|
1027 g_string_free(buf, TRUE);
|
|
1028 g_hash_table_remove(yd->friends, who);
|
|
1029 gaim_prpl_got_user_status(gaim_connection_get_account(gc), who, "offline", NULL); /* FIXME: make this set not on list status instead */
|
|
1030 /* TODO: Shouldn't we remove the buddy from our local list? */
|
|
1031 }
|
|
1032 }
|
|
1033
|
|
1034 static void yahoo_process_contact(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
1035 {
|
|
1036 switch (pkt->status) {
|
|
1037 case 1:
|
|
1038 yahoo_process_status(gc, pkt);
|
|
1039 return;
|
|
1040 case 3:
|
|
1041 yahoo_buddy_added_us(gc, pkt);
|
|
1042 break;
|
|
1043 case 7:
|
|
1044 yahoo_buddy_denied_our_add(gc, pkt);
|
|
1045 break;
|
|
1046 default:
|
|
1047 break;
|
|
1048 }
|
|
1049 }
|
|
1050
|
|
1051 #define OUT_CHARSET "utf-8"
|
|
1052
|
|
1053 static char *yahoo_decode(const char *text)
|
|
1054 {
|
|
1055 char *converted = NULL;
|
|
1056 char *n, *new;
|
|
1057 const char *end, *p;
|
|
1058 int i, k;
|
|
1059
|
|
1060 n = new = g_malloc(strlen (text) + 1);
|
|
1061 end = text + strlen(text);
|
|
1062
|
|
1063 for (p = text; p < end; p++, n++) {
|
|
1064 if (*p == '\\') {
|
|
1065 if (p[1] >= '0' && p[1] <= '7') {
|
|
1066 p += 1;
|
|
1067 for (i = 0, k = 0; k < 3; k += 1) {
|
|
1068 char c = p[k];
|
|
1069 if (c < '0' || c > '7') break;
|
|
1070 i *= 8;
|
|
1071 i += c - '0';
|
|
1072 }
|
|
1073 *n = i;
|
|
1074 p += k - 1;
|
|
1075 } else { /* bug 959248 */
|
|
1076 /* If we see a \ not followed by an octal number,
|
|
1077 * it means that it is actually a \\ with one \
|
|
1078 * already eaten by some unknown function.
|
|
1079 * This is arguably broken.
|
|
1080 *
|
|
1081 * I think wing is wrong here, there is no function
|
|
1082 * called that I see that could have done it. I guess
|
|
1083 * it is just really sending single \'s. That's yahoo
|
|
1084 * for you.
|
|
1085 */
|
|
1086 *n = *p;
|
|
1087 }
|
|
1088 }
|
|
1089 else
|
|
1090 *n = *p;
|
|
1091 }
|
|
1092
|
|
1093 *n = '\0';
|
|
1094
|
|
1095 if (strstr(text, "\033$B"))
|
|
1096 converted = g_convert(new, n - new, OUT_CHARSET, "iso-2022-jp", NULL, NULL, NULL);
|
|
1097 if (!converted)
|
|
1098 converted = g_convert(new, n - new, OUT_CHARSET, "iso-8859-1", NULL, NULL, NULL);
|
|
1099 g_free(new);
|
|
1100
|
|
1101 return converted;
|
|
1102 }
|
|
1103
|
|
1104 static void yahoo_process_mail(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
1105 {
|
|
1106 GaimAccount *account = gaim_connection_get_account(gc);
|
|
1107 struct yahoo_data *yd = gc->proto_data;
|
|
1108 char *who = NULL;
|
|
1109 char *email = NULL;
|
|
1110 char *subj = NULL;
|
|
1111 char *yahoo_mail_url = (yd->jp? YAHOOJP_MAIL_URL: YAHOO_MAIL_URL);
|
|
1112 int count = 0;
|
|
1113 GSList *l = pkt->hash;
|
|
1114
|
|
1115 if (!gaim_account_get_check_mail(account))
|
|
1116 return;
|
|
1117
|
|
1118 while (l) {
|
|
1119 struct yahoo_pair *pair = l->data;
|
|
1120 if (pair->key == 9)
|
|
1121 count = strtol(pair->value, NULL, 10);
|
|
1122 else if (pair->key == 43)
|
|
1123 who = pair->value;
|
|
1124 else if (pair->key == 42)
|
|
1125 email = pair->value;
|
|
1126 else if (pair->key == 18)
|
|
1127 subj = pair->value;
|
|
1128 l = l->next;
|
|
1129 }
|
|
1130
|
|
1131 if (who && subj && email && *email) {
|
|
1132 char *dec_who = yahoo_decode(who);
|
|
1133 char *dec_subj = yahoo_decode(subj);
|
|
1134 char *from = g_strdup_printf("%s (%s)", dec_who, email);
|
|
1135
|
|
1136 gaim_notify_email(gc, dec_subj, from, gaim_account_get_username(account),
|
|
1137 yahoo_mail_url, NULL, NULL);
|
|
1138
|
|
1139 g_free(dec_who);
|
|
1140 g_free(dec_subj);
|
|
1141 g_free(from);
|
|
1142 } else if (count > 0) {
|
|
1143 const char *to = gaim_account_get_username(account);
|
|
1144 const char *url = yahoo_mail_url;
|
|
1145
|
|
1146 gaim_notify_emails(gc, count, FALSE, NULL, NULL, &to, &url,
|
|
1147 NULL, NULL);
|
|
1148 }
|
|
1149 }
|
|
1150 /* This is the y64 alphabet... it's like base64, but has a . and a _ */
|
|
1151 char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
|
|
1152
|
|
1153 /* This is taken from Sylpheed by Hiroyuki Yamamoto. We have our own tobase64 function
|
|
1154 * in util.c, but it has a bug I don't feel like finding right now ;) */
|
|
1155 static void to_y64(char *out, const unsigned char *in, gsize inlen)
|
|
1156 /* raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) */
|
|
1157 {
|
|
1158 for (; inlen >= 3; inlen -= 3)
|
|
1159 {
|
|
1160 *out++ = base64digits[in[0] >> 2];
|
|
1161 *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)];
|
|
1162 *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)];
|
|
1163 *out++ = base64digits[in[2] & 0x3f];
|
|
1164 in += 3;
|
|
1165 }
|
|
1166 if (inlen > 0)
|
|
1167 {
|
|
1168 unsigned char fragment;
|
|
1169
|
|
1170 *out++ = base64digits[in[0] >> 2];
|
|
1171 fragment = (in[0] << 4) & 0x30;
|
|
1172 if (inlen > 1)
|
|
1173 fragment |= in[1] >> 4;
|
|
1174 *out++ = base64digits[fragment];
|
|
1175 *out++ = (inlen < 2) ? '-' : base64digits[(in[1] << 2) & 0x3c];
|
|
1176 *out++ = '-';
|
|
1177 }
|
|
1178 *out = '\0';
|
|
1179 }
|
|
1180
|
|
1181 static void yahoo_process_auth_old(GaimConnection *gc, const char *seed)
|
|
1182 {
|
|
1183 struct yahoo_packet *pack;
|
|
1184 GaimAccount *account = gaim_connection_get_account(gc);
|
|
1185 const char *name = gaim_normalize(account, gaim_account_get_username(account));
|
|
1186 const char *pass = gaim_connection_get_password(gc);
|
|
1187 struct yahoo_data *yd = gc->proto_data;
|
|
1188
|
|
1189 /* So, Yahoo has stopped supporting its older clients in India, and undoubtedly
|
|
1190 * will soon do so in the rest of the world.
|
|
1191 *
|
|
1192 * The new clients use this authentication method. I warn you in advance, it's
|
|
1193 * bizarre, convoluted, inordinately complicated. It's also no more secure than
|
|
1194 * crypt() was. The only purpose this scheme could serve is to prevent third
|
|
1195 * party clients from connecting to their servers.
|
|
1196 *
|
|
1197 * Sorry, Yahoo.
|
|
1198 */
|
|
1199
|
|
1200 GaimCipher *cipher;
|
|
1201 GaimCipherContext *context;
|
|
1202 guchar digest[16];
|
|
1203
|
|
1204 char *crypt_result;
|
|
1205 char password_hash[25];
|
|
1206 char crypt_hash[25];
|
|
1207 char *hash_string_p = g_malloc(50 + strlen(name));
|
|
1208 char *hash_string_c = g_malloc(50 + strlen(name));
|
|
1209
|
|
1210 char checksum;
|
|
1211
|
|
1212 int sv;
|
|
1213
|
|
1214 char result6[25];
|
|
1215 char result96[25];
|
|
1216
|
|
1217 sv = seed[15];
|
|
1218 sv = sv % 8;
|
|
1219
|
|
1220 cipher = gaim_ciphers_find_cipher("md5");
|
|
1221 context = gaim_cipher_context_new(cipher, NULL);
|
|
1222
|
|
1223 gaim_cipher_context_append(context, (const guchar *)pass, strlen(pass));
|
|
1224 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
1225
|
|
1226 to_y64(password_hash, digest, 16);
|
|
1227
|
|
1228 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$");
|
|
1229
|
|
1230 gaim_cipher_context_reset(context, NULL);
|
|
1231 gaim_cipher_context_append(context, (const guchar *)crypt_result, strlen(crypt_result));
|
|
1232 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
1233 to_y64(crypt_hash, digest, 16);
|
|
1234
|
|
1235 switch (sv) {
|
|
1236 case 1:
|
|
1237 case 6:
|
|
1238 checksum = seed[seed[9] % 16];
|
|
1239 g_snprintf(hash_string_p, strlen(name) + 50,
|
|
1240 "%c%s%s%s", checksum, name, seed, password_hash);
|
|
1241 g_snprintf(hash_string_c, strlen(name) + 50,
|
|
1242 "%c%s%s%s", checksum, name, seed, crypt_hash);
|
|
1243 break;
|
|
1244 case 2:
|
|
1245 case 7:
|
|
1246 checksum = seed[seed[15] % 16];
|
|
1247 g_snprintf(hash_string_p, strlen(name) + 50,
|
|
1248 "%c%s%s%s", checksum, seed, password_hash, name);
|
|
1249 g_snprintf(hash_string_c, strlen(name) + 50,
|
|
1250 "%c%s%s%s", checksum, seed, crypt_hash, name);
|
|
1251 break;
|
|
1252 case 3:
|
|
1253 checksum = seed[seed[1] % 16];
|
|
1254 g_snprintf(hash_string_p, strlen(name) + 50,
|
|
1255 "%c%s%s%s", checksum, name, password_hash, seed);
|
|
1256 g_snprintf(hash_string_c, strlen(name) + 50,
|
|
1257 "%c%s%s%s", checksum, name, crypt_hash, seed);
|
|
1258 break;
|
|
1259 case 4:
|
|
1260 checksum = seed[seed[3] % 16];
|
|
1261 g_snprintf(hash_string_p, strlen(name) + 50,
|
|
1262 "%c%s%s%s", checksum, password_hash, seed, name);
|
|
1263 g_snprintf(hash_string_c, strlen(name) + 50,
|
|
1264 "%c%s%s%s", checksum, crypt_hash, seed, name);
|
|
1265 break;
|
|
1266 case 0:
|
|
1267 case 5:
|
|
1268 checksum = seed[seed[7] % 16];
|
|
1269 g_snprintf(hash_string_p, strlen(name) + 50,
|
|
1270 "%c%s%s%s", checksum, password_hash, name, seed);
|
|
1271 g_snprintf(hash_string_c, strlen(name) + 50,
|
|
1272 "%c%s%s%s", checksum, crypt_hash, name, seed);
|
|
1273 break;
|
|
1274 }
|
|
1275
|
|
1276 gaim_cipher_context_reset(context, NULL);
|
|
1277 gaim_cipher_context_append(context, (const guchar *)hash_string_p, strlen(hash_string_p));
|
|
1278 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
1279 to_y64(result6, digest, 16);
|
|
1280
|
|
1281 gaim_cipher_context_reset(context, NULL);
|
|
1282 gaim_cipher_context_append(context, (const guchar *)hash_string_c, strlen(hash_string_c));
|
|
1283 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
1284 gaim_cipher_context_destroy(context);
|
|
1285 to_y64(result96, digest, 16);
|
|
1286
|
|
1287 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0);
|
|
1288 yahoo_packet_hash(pack, "ssss", 0, name, 6, result6, 96, result96, 1, name);
|
|
1289 yahoo_packet_send_and_free(pack, yd);
|
|
1290
|
|
1291 g_free(hash_string_p);
|
|
1292 g_free(hash_string_c);
|
|
1293 }
|
|
1294
|
|
1295 /* I'm dishing out some uber-mad props to Cerulean Studios for cracking this
|
|
1296 * and sending the fix! Thanks guys. */
|
|
1297
|
|
1298 static void yahoo_process_auth_new(GaimConnection *gc, const char *seed)
|
|
1299 {
|
|
1300 struct yahoo_packet *pack = NULL;
|
|
1301 GaimAccount *account = gaim_connection_get_account(gc);
|
|
1302 const char *name = gaim_normalize(account, gaim_account_get_username(account));
|
|
1303 const char *pass = gaim_connection_get_password(gc);
|
|
1304 char *enc_pass;
|
|
1305 struct yahoo_data *yd = gc->proto_data;
|
|
1306
|
|
1307 GaimCipher *md5_cipher;
|
|
1308 GaimCipherContext *md5_ctx;
|
|
1309 guchar md5_digest[16];
|
|
1310
|
|
1311 GaimCipher *sha1_cipher;
|
|
1312 GaimCipherContext *sha1_ctx1;
|
|
1313 GaimCipherContext *sha1_ctx2;
|
|
1314
|
|
1315 char *alphabet1 = "FBZDWAGHrJTLMNOPpRSKUVEXYChImkwQ";
|
|
1316 char *alphabet2 = "F0E1D2C3B4A59687abcdefghijklmnop";
|
|
1317
|
|
1318 char *challenge_lookup = "qzec2tb3um1olpar8whx4dfgijknsvy5";
|
|
1319 char *operand_lookup = "+|&%/*^-";
|
|
1320 char *delimit_lookup = ",;";
|
|
1321
|
|
1322 char *password_hash = (char *)g_malloc(25);
|
|
1323 char *crypt_hash = (char *)g_malloc(25);
|
|
1324 char *crypt_result = NULL;
|
|
1325
|
|
1326 unsigned char pass_hash_xor1[64];
|
|
1327 unsigned char pass_hash_xor2[64];
|
|
1328 unsigned char crypt_hash_xor1[64];
|
|
1329 unsigned char crypt_hash_xor2[64];
|
|
1330 char resp_6[100];
|
|
1331 char resp_96[100];
|
|
1332
|
|
1333 unsigned char digest1[20];
|
|
1334 unsigned char digest2[20];
|
|
1335 unsigned char comparison_src[20];
|
|
1336 unsigned char magic_key_char[4];
|
|
1337 const char *magic_ptr;
|
|
1338
|
|
1339 unsigned int magic[64];
|
|
1340 unsigned int magic_work = 0;
|
|
1341 unsigned int magic_4 = 0;
|
|
1342
|
|
1343 int x;
|
|
1344 int y;
|
|
1345 int cnt = 0;
|
|
1346 int magic_cnt = 0;
|
|
1347 int magic_len;
|
|
1348
|
|
1349 memset(password_hash, 0, 25);
|
|
1350 memset(crypt_hash, 0, 25);
|
|
1351 memset(&pass_hash_xor1, 0, 64);
|
|
1352 memset(&pass_hash_xor2, 0, 64);
|
|
1353 memset(&crypt_hash_xor1, 0, 64);
|
|
1354 memset(&crypt_hash_xor2, 0, 64);
|
|
1355 memset(&digest1, 0, 20);
|
|
1356 memset(&digest2, 0, 20);
|
|
1357 memset(&magic, 0, 64);
|
|
1358 memset(&resp_6, 0, 100);
|
|
1359 memset(&resp_96, 0, 100);
|
|
1360 memset(&magic_key_char, 0, 4);
|
|
1361 memset(&comparison_src, 0, 20);
|
|
1362
|
|
1363 md5_cipher = gaim_ciphers_find_cipher("md5");
|
|
1364 md5_ctx = gaim_cipher_context_new(md5_cipher, NULL);
|
|
1365
|
|
1366 sha1_cipher = gaim_ciphers_find_cipher("sha1");
|
|
1367 sha1_ctx1 = gaim_cipher_context_new(sha1_cipher, NULL);
|
|
1368 sha1_ctx2 = gaim_cipher_context_new(sha1_cipher, NULL);
|
|
1369
|
|
1370 /*
|
|
1371 * Magic: Phase 1. Generate what seems to be a 30 byte value (could change if base64
|
|
1372 * ends up differently? I don't remember and I'm tired, so use a 64 byte buffer.
|
|
1373 */
|
|
1374
|
|
1375 magic_ptr = seed;
|
|
1376
|
|
1377 while (*magic_ptr != (int)NULL) {
|
|
1378 char *loc;
|
|
1379
|
|
1380 /* Ignore parentheses. */
|
|
1381
|
|
1382 if (*magic_ptr == '(' || *magic_ptr == ')') {
|
|
1383 magic_ptr++;
|
|
1384 continue;
|
|
1385 }
|
|
1386
|
|
1387 /* Characters and digits verify against the challenge lookup. */
|
|
1388
|
|
1389 if (isalpha(*magic_ptr) || isdigit(*magic_ptr)) {
|
|
1390 loc = strchr(challenge_lookup, *magic_ptr);
|
|
1391 if (!loc) {
|
|
1392 /* SME XXX Error - disconnect here */
|
|
1393 }
|
|
1394
|
|
1395 /* Get offset into lookup table and shl 3. */
|
|
1396
|
|
1397 magic_work = loc - challenge_lookup;
|
|
1398 magic_work <<= 3;
|
|
1399
|
|
1400 magic_ptr++;
|
|
1401 continue;
|
|
1402 } else {
|
|
1403 unsigned int local_store;
|
|
1404
|
|
1405 loc = strchr(operand_lookup, *magic_ptr);
|
|
1406 if (!loc) {
|
|
1407 /* SME XXX Disconnect */
|
|
1408 }
|
|
1409
|
|
1410 local_store = loc - operand_lookup;
|
|
1411
|
|
1412 /* Oops; how did this happen? */
|
|
1413
|
|
1414 if (magic_cnt >= 64)
|
|
1415 break;
|
|
1416
|
|
1417 magic[magic_cnt++] = magic_work | local_store;
|
|
1418 magic_ptr++;
|
|
1419 continue;
|
|
1420 }
|
|
1421 }
|
|
1422
|
|
1423 magic_len = magic_cnt;
|
|
1424 magic_cnt = 0;
|
|
1425
|
|
1426 /* Magic: Phase 2. Take generated magic value and sprinkle fairy
|
|
1427 * dust on the values.
|
|
1428 */
|
|
1429
|
|
1430 for (magic_cnt = magic_len-2; magic_cnt >= 0; magic_cnt--) {
|
|
1431 unsigned char byte1;
|
|
1432 unsigned char byte2;
|
|
1433
|
|
1434 /* Bad. Abort. */
|
|
1435
|
|
1436 if ((magic_cnt + 1 > magic_len) || (magic_cnt > magic_len))
|
|
1437 break;
|
|
1438
|
|
1439 byte1 = magic[magic_cnt];
|
|
1440 byte2 = magic[magic_cnt+1];
|
|
1441
|
|
1442 byte1 *= 0xcd;
|
|
1443 byte1 ^= byte2;
|
|
1444
|
|
1445 magic[magic_cnt+1] = byte1;
|
|
1446 }
|
|
1447
|
|
1448 /*
|
|
1449 * Magic: Phase 3. This computes 20 bytes. The first 4 bytes are used as our magic
|
|
1450 * key (and may be changed later); the next 16 bytes are an MD5 sum of the magic key
|
|
1451 * plus 3 bytes. The 3 bytes are found by looping, and they represent the offsets
|
|
1452 * into particular functions we'll later call to potentially alter the magic key.
|
|
1453 *
|
|
1454 * %-)
|
|
1455 */
|
|
1456
|
|
1457 magic_cnt = 1;
|
|
1458 x = 0;
|
|
1459
|
|
1460 do {
|
|
1461 unsigned int bl = 0;
|
|
1462 unsigned int cl = magic[magic_cnt++];
|
|
1463
|
|
1464 if (magic_cnt >= magic_len)
|
|
1465 break;
|
|
1466
|
|
1467 if (cl > 0x7F) {
|
|
1468 if (cl < 0xe0)
|
|
1469 bl = cl = (cl & 0x1f) << 6;
|
|
1470 else {
|
|
1471 bl = magic[magic_cnt++];
|
|
1472 cl = (cl & 0x0f) << 6;
|
|
1473 bl = ((bl & 0x3f) + cl) << 6;
|
|
1474 }
|
|
1475
|
|
1476 cl = magic[magic_cnt++];
|
|
1477 bl = (cl & 0x3f) + bl;
|
|
1478 } else
|
|
1479 bl = cl;
|
|
1480
|
|
1481 comparison_src[x++] = (bl & 0xff00) >> 8;
|
|
1482 comparison_src[x++] = bl & 0xff;
|
|
1483 } while (x < 20);
|
|
1484
|
|
1485 /* First four bytes are magic key. */
|
|
1486 memcpy(&magic_key_char[0], comparison_src, 4);
|
|
1487 magic_4 = magic_key_char[0] | (magic_key_char[1]<<8) | (magic_key_char[2]<<16) | (magic_key_char[3]<<24);
|
|
1488
|
|
1489 /*
|
|
1490 * Magic: Phase 4. Determine what function to use later by getting outside/inside
|
|
1491 * loop values until we match our previous buffer.
|
|
1492 */
|
|
1493 for (x = 0; x < 65535; x++) {
|
|
1494 int leave = 0;
|
|
1495
|
|
1496 for (y = 0; y < 5; y++) {
|
|
1497 unsigned char test[3];
|
|
1498
|
|
1499 /* Calculate buffer. */
|
|
1500 test[0] = x;
|
|
1501 test[1] = x >> 8;
|
|
1502 test[2] = y;
|
|
1503
|
|
1504 gaim_cipher_context_reset(md5_ctx, NULL);
|
|
1505 gaim_cipher_context_append(md5_ctx, magic_key_char, 4);
|
|
1506 gaim_cipher_context_append(md5_ctx, test, 3);
|
|
1507 gaim_cipher_context_digest(md5_ctx, sizeof(md5_digest),
|
|
1508 md5_digest, NULL);
|
|
1509
|
|
1510 if (!memcmp(md5_digest, comparison_src+4, 16)) {
|
|
1511 leave = 1;
|
|
1512 break;
|
|
1513 }
|
|
1514 }
|
|
1515
|
|
1516 if (leave == 1)
|
|
1517 break;
|
|
1518 }
|
|
1519
|
|
1520 /* If y != 0, we need some help. */
|
|
1521 if (y != 0) {
|
|
1522 unsigned int updated_key;
|
|
1523
|
|
1524 /* Update magic stuff.
|
|
1525 * Call it twice because Yahoo's encryption is super bad ass.
|
|
1526 */
|
|
1527 updated_key = yahoo_auth_finalCountdown(magic_4, 0x60, y, x);
|
|
1528 updated_key = yahoo_auth_finalCountdown(updated_key, 0x60, y, x);
|
|
1529
|
|
1530 magic_key_char[0] = updated_key & 0xff;
|
|
1531 magic_key_char[1] = (updated_key >> 8) & 0xff;
|
|
1532 magic_key_char[2] = (updated_key >> 16) & 0xff;
|
|
1533 magic_key_char[3] = (updated_key >> 24) & 0xff;
|
|
1534 }
|
|
1535
|
|
1536 enc_pass = yahoo_string_encode(gc, pass, NULL);
|
|
1537
|
|
1538 /* Get password and crypt hashes as per usual. */
|
|
1539 gaim_cipher_context_reset(md5_ctx, NULL);
|
|
1540 gaim_cipher_context_append(md5_ctx, (const guchar *)enc_pass, strlen(enc_pass));
|
|
1541 gaim_cipher_context_digest(md5_ctx, sizeof(md5_digest),
|
|
1542 md5_digest, NULL);
|
|
1543 to_y64(password_hash, md5_digest, 16);
|
|
1544
|
|
1545 crypt_result = yahoo_crypt(enc_pass, "$1$_2S43d5f$");
|
|
1546
|
|
1547 g_free(enc_pass);
|
|
1548 enc_pass = NULL;
|
|
1549
|
|
1550 gaim_cipher_context_reset(md5_ctx, NULL);
|
|
1551 gaim_cipher_context_append(md5_ctx, (const guchar *)crypt_result, strlen(crypt_result));
|
|
1552 gaim_cipher_context_digest(md5_ctx, sizeof(md5_digest),
|
|
1553 md5_digest, NULL);
|
|
1554 to_y64(crypt_hash, md5_digest, 16);
|
|
1555
|
|
1556 /* Our first authentication response is based off of the password hash. */
|
|
1557 for (x = 0; x < (int)strlen(password_hash); x++)
|
|
1558 pass_hash_xor1[cnt++] = password_hash[x] ^ 0x36;
|
|
1559
|
|
1560 if (cnt < 64)
|
|
1561 memset(&(pass_hash_xor1[cnt]), 0x36, 64-cnt);
|
|
1562
|
|
1563 cnt = 0;
|
|
1564
|
|
1565 for (x = 0; x < (int)strlen(password_hash); x++)
|
|
1566 pass_hash_xor2[cnt++] = password_hash[x] ^ 0x5c;
|
|
1567
|
|
1568 if (cnt < 64)
|
|
1569 memset(&(pass_hash_xor2[cnt]), 0x5c, 64-cnt);
|
|
1570
|
|
1571 /*
|
|
1572 * The first context gets the password hash XORed with 0x36 plus a magic value
|
|
1573 * which we previously extrapolated from our challenge.
|
|
1574 */
|
|
1575
|
|
1576 gaim_cipher_context_append(sha1_ctx1, pass_hash_xor1, 64);
|
|
1577 if (y >= 3)
|
|
1578 gaim_cipher_context_set_option(sha1_ctx1, "sizeLo", GINT_TO_POINTER(0x1ff));
|
|
1579 gaim_cipher_context_append(sha1_ctx1, magic_key_char, 4);
|
|
1580 gaim_cipher_context_digest(sha1_ctx1, sizeof(digest1), digest1, NULL);
|
|
1581
|
|
1582 /*
|
|
1583 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest
|
|
1584 * of the first context.
|
|
1585 */
|
|
1586
|
|
1587 gaim_cipher_context_append(sha1_ctx2, pass_hash_xor2, 64);
|
|
1588 gaim_cipher_context_append(sha1_ctx2, digest1, 20);
|
|
1589 gaim_cipher_context_digest(sha1_ctx2, sizeof(digest2), digest2, NULL);
|
|
1590
|
|
1591 /*
|
|
1592 * Now that we have digest2, use it to fetch characters from an alphabet to construct
|
|
1593 * our first authentication response.
|
|
1594 */
|
|
1595
|
|
1596 for (x = 0; x < 20; x += 2) {
|
|
1597 unsigned int val = 0;
|
|
1598 unsigned int lookup = 0;
|
|
1599
|
|
1600 char byte[6];
|
|
1601
|
|
1602 memset(&byte, 0, 6);
|
|
1603
|
|
1604 /* First two bytes of digest stuffed together. */
|
|
1605
|
|
1606 val = digest2[x];
|
|
1607 val <<= 8;
|
|
1608 val += digest2[x+1];
|
|
1609
|
|
1610 lookup = (val >> 0x0b);
|
|
1611 lookup &= 0x1f;
|
|
1612 if (lookup >= strlen(alphabet1))
|
|
1613 break;
|
|
1614 sprintf(byte, "%c", alphabet1[lookup]);
|
|
1615 strcat(resp_6, byte);
|
|
1616 strcat(resp_6, "=");
|
|
1617
|
|
1618 lookup = (val >> 0x06);
|
|
1619 lookup &= 0x1f;
|
|
1620 if (lookup >= strlen(alphabet2))
|
|
1621 break;
|
|
1622 sprintf(byte, "%c", alphabet2[lookup]);
|
|
1623 strcat(resp_6, byte);
|
|
1624
|
|
1625 lookup = (val >> 0x01);
|
|
1626 lookup &= 0x1f;
|
|
1627 if (lookup >= strlen(alphabet2))
|
|
1628 break;
|
|
1629 sprintf(byte, "%c", alphabet2[lookup]);
|
|
1630 strcat(resp_6, byte);
|
|
1631
|
|
1632 lookup = (val & 0x01);
|
|
1633 if (lookup >= strlen(delimit_lookup))
|
|
1634 break;
|
|
1635 sprintf(byte, "%c", delimit_lookup[lookup]);
|
|
1636 strcat(resp_6, byte);
|
|
1637 }
|
|
1638
|
|
1639 /* Our second authentication response is based off of the crypto hash. */
|
|
1640
|
|
1641 cnt = 0;
|
|
1642 memset(&digest1, 0, 20);
|
|
1643 memset(&digest2, 0, 20);
|
|
1644
|
|
1645 for (x = 0; x < (int)strlen(crypt_hash); x++)
|
|
1646 crypt_hash_xor1[cnt++] = crypt_hash[x] ^ 0x36;
|
|
1647
|
|
1648 if (cnt < 64)
|
|
1649 memset(&(crypt_hash_xor1[cnt]), 0x36, 64-cnt);
|
|
1650
|
|
1651 cnt = 0;
|
|
1652
|
|
1653 for (x = 0; x < (int)strlen(crypt_hash); x++)
|
|
1654 crypt_hash_xor2[cnt++] = crypt_hash[x] ^ 0x5c;
|
|
1655
|
|
1656 if (cnt < 64)
|
|
1657 memset(&(crypt_hash_xor2[cnt]), 0x5c, 64-cnt);
|
|
1658
|
|
1659 gaim_cipher_context_reset(sha1_ctx1, NULL);
|
|
1660 gaim_cipher_context_reset(sha1_ctx2, NULL);
|
|
1661
|
|
1662 /*
|
|
1663 * The first context gets the password hash XORed with 0x36 plus a magic value
|
|
1664 * which we previously extrapolated from our challenge.
|
|
1665 */
|
|
1666
|
|
1667 gaim_cipher_context_append(sha1_ctx1, crypt_hash_xor1, 64);
|
|
1668 if (y >= 3) {
|
|
1669 gaim_cipher_context_set_option(sha1_ctx1, "sizeLo",
|
|
1670 GINT_TO_POINTER(0x1ff));
|
|
1671 }
|
|
1672 gaim_cipher_context_append(sha1_ctx1, magic_key_char, 4);
|
|
1673 gaim_cipher_context_digest(sha1_ctx1, sizeof(digest1), digest1, NULL);
|
|
1674
|
|
1675 /*
|
|
1676 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest
|
|
1677 * of the first context.
|
|
1678 */
|
|
1679
|
|
1680 gaim_cipher_context_append(sha1_ctx2, crypt_hash_xor2, 64);
|
|
1681 gaim_cipher_context_append(sha1_ctx2, digest1, 20);
|
|
1682 gaim_cipher_context_digest(sha1_ctx2, sizeof(digest2), digest2, NULL);
|
|
1683
|
|
1684 /*
|
|
1685 * Now that we have digest2, use it to fetch characters from an alphabet to construct
|
|
1686 * our first authentication response.
|
|
1687 */
|
|
1688
|
|
1689 for (x = 0; x < 20; x += 2) {
|
|
1690 unsigned int val = 0;
|
|
1691 unsigned int lookup = 0;
|
|
1692
|
|
1693 char byte[6];
|
|
1694
|
|
1695 memset(&byte, 0, 6);
|
|
1696
|
|
1697 /* First two bytes of digest stuffed together. */
|
|
1698
|
|
1699 val = digest2[x];
|
|
1700 val <<= 8;
|
|
1701 val += digest2[x+1];
|
|
1702
|
|
1703 lookup = (val >> 0x0b);
|
|
1704 lookup &= 0x1f;
|
|
1705 if (lookup >= strlen(alphabet1))
|
|
1706 break;
|
|
1707 sprintf(byte, "%c", alphabet1[lookup]);
|
|
1708 strcat(resp_96, byte);
|
|
1709 strcat(resp_96, "=");
|
|
1710
|
|
1711 lookup = (val >> 0x06);
|
|
1712 lookup &= 0x1f;
|
|
1713 if (lookup >= strlen(alphabet2))
|
|
1714 break;
|
|
1715 sprintf(byte, "%c", alphabet2[lookup]);
|
|
1716 strcat(resp_96, byte);
|
|
1717
|
|
1718 lookup = (val >> 0x01);
|
|
1719 lookup &= 0x1f;
|
|
1720 if (lookup >= strlen(alphabet2))
|
|
1721 break;
|
|
1722 sprintf(byte, "%c", alphabet2[lookup]);
|
|
1723 strcat(resp_96, byte);
|
|
1724
|
|
1725 lookup = (val & 0x01);
|
|
1726 if (lookup >= strlen(delimit_lookup))
|
|
1727 break;
|
|
1728 sprintf(byte, "%c", delimit_lookup[lookup]);
|
|
1729 strcat(resp_96, byte);
|
|
1730 }
|
|
1731 gaim_debug_info("yahoo", "yahoo status: %d\n", yd->current_status);
|
|
1732 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yd->current_status, 0);
|
|
1733 yahoo_packet_hash(pack, "sssss", 0, name, 6, resp_6, 96, resp_96, 1,
|
|
1734 name, 135, "6,0,0,1710");
|
|
1735 if (yd->picture_checksum)
|
|
1736 yahoo_packet_hash_int(pack, 192, yd->picture_checksum);
|
|
1737
|
|
1738 yahoo_packet_send_and_free(pack, yd);
|
|
1739
|
|
1740 gaim_cipher_context_destroy(md5_ctx);
|
|
1741 gaim_cipher_context_destroy(sha1_ctx1);
|
|
1742 gaim_cipher_context_destroy(sha1_ctx2);
|
|
1743
|
|
1744 g_free(password_hash);
|
|
1745 g_free(crypt_hash);
|
|
1746 }
|
|
1747
|
|
1748 static void yahoo_process_auth(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
1749 {
|
|
1750 char *seed = NULL;
|
|
1751 char *sn = NULL;
|
|
1752 GSList *l = pkt->hash;
|
|
1753 int m = 0;
|
|
1754 gchar *buf;
|
|
1755
|
|
1756 while (l) {
|
|
1757 struct yahoo_pair *pair = l->data;
|
|
1758 if (pair->key == 94)
|
|
1759 seed = pair->value;
|
|
1760 if (pair->key == 1)
|
|
1761 sn = pair->value;
|
|
1762 if (pair->key == 13)
|
|
1763 m = atoi(pair->value);
|
|
1764 l = l->next;
|
|
1765 }
|
|
1766
|
|
1767 if (seed) {
|
|
1768 switch (m) {
|
|
1769 case 0:
|
|
1770 yahoo_process_auth_old(gc, seed);
|
|
1771 break;
|
|
1772 case 1:
|
14258
|
1773 case 2: /* This case seems to work, could probably use testing */
|
14192
|
1774 yahoo_process_auth_new(gc, seed);
|
|
1775 break;
|
|
1776 default:
|
|
1777 buf = g_strdup_printf(_("The Yahoo server has requested the use of an unrecognized "
|
|
1778 "authentication method. This version of Gaim will likely not be able "
|
|
1779 "to successfully sign on to Yahoo. Check %s for updates."), GAIM_WEBSITE);
|
|
1780 gaim_notify_error(gc, "", _("Failed Yahoo! Authentication"),
|
|
1781 buf);
|
|
1782 g_free(buf);
|
|
1783 yahoo_process_auth_new(gc, seed); /* Can't hurt to try it anyway. */
|
|
1784 }
|
|
1785 }
|
|
1786 }
|
|
1787
|
|
1788 static void ignore_buddy(GaimBuddy *buddy) {
|
|
1789 GaimGroup *group;
|
|
1790 GaimAccount *account;
|
|
1791 gchar *name;
|
|
1792
|
|
1793 if (!buddy)
|
|
1794 return;
|
|
1795
|
|
1796 group = gaim_buddy_get_group(buddy);
|
|
1797 name = g_strdup(buddy->name);
|
|
1798 account = buddy->account;
|
|
1799
|
|
1800 gaim_debug(GAIM_DEBUG_INFO, "blist",
|
|
1801 "Removing '%s' from buddy list.\n", buddy->name);
|
|
1802 gaim_account_remove_buddy(account, buddy, group);
|
|
1803 gaim_blist_remove_buddy(buddy);
|
|
1804
|
|
1805 serv_add_deny(account->gc, name);
|
|
1806
|
|
1807 g_free(name);
|
|
1808 }
|
|
1809
|
|
1810 static void keep_buddy(GaimBuddy *b) {
|
|
1811 gaim_privacy_deny_remove(b->account, b->name, 1);
|
|
1812 }
|
|
1813
|
|
1814 static void yahoo_process_ignore(GaimConnection *gc, struct yahoo_packet *pkt) {
|
|
1815 GaimBuddy *b;
|
|
1816 GSList *l;
|
|
1817 gchar *who = NULL;
|
|
1818 gchar *sn = NULL;
|
|
1819 gchar buf[BUF_LONG];
|
|
1820 gint ignore = 0;
|
|
1821 gint status = 0;
|
|
1822
|
|
1823 for (l = pkt->hash; l; l = l->next) {
|
|
1824 struct yahoo_pair *pair = l->data;
|
|
1825 switch (pair->key) {
|
|
1826 case 0:
|
|
1827 who = pair->value;
|
|
1828 break;
|
|
1829 case 1:
|
|
1830 sn = pair->value;
|
|
1831 break;
|
|
1832 case 13:
|
|
1833 ignore = strtol(pair->value, NULL, 10);
|
|
1834 break;
|
|
1835 case 66:
|
|
1836 status = strtol(pair->value, NULL, 10);
|
|
1837 break;
|
|
1838 default:
|
|
1839 break;
|
|
1840 }
|
|
1841 }
|
|
1842
|
|
1843 switch (status) {
|
|
1844 case 12:
|
|
1845 b = gaim_find_buddy(gc->account, who);
|
|
1846 g_snprintf(buf, sizeof(buf), _("You have tried to ignore %s, but the "
|
|
1847 "user is on your buddy list. Clicking \"Yes\" "
|
|
1848 "will remove and ignore the buddy."), who);
|
|
1849 gaim_request_yes_no(gc, NULL, _("Ignore buddy?"), buf, 0, b,
|
|
1850 G_CALLBACK(ignore_buddy),
|
|
1851 G_CALLBACK(keep_buddy));
|
|
1852 break;
|
|
1853 case 2:
|
|
1854 case 3:
|
|
1855 case 0:
|
|
1856 default:
|
|
1857 break;
|
|
1858 }
|
|
1859 }
|
|
1860
|
|
1861 static void yahoo_process_authresp(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
1862 {
|
|
1863 struct yahoo_data *yd = gc->proto_data;
|
|
1864 GSList *l = pkt->hash;
|
|
1865 int err = 0;
|
|
1866 char *msg;
|
|
1867 char *url = NULL;
|
|
1868 char *fullmsg;
|
|
1869
|
|
1870 while (l) {
|
|
1871 struct yahoo_pair *pair = l->data;
|
|
1872
|
|
1873 if (pair->key == 66)
|
|
1874 err = strtol(pair->value, NULL, 10);
|
|
1875 if (pair->key == 20)
|
|
1876 url = pair->value;
|
|
1877
|
|
1878 l = l->next;
|
|
1879 }
|
|
1880
|
|
1881 switch (err) {
|
|
1882 case 3:
|
|
1883 msg = g_strdup(_("Invalid username."));
|
|
1884 break;
|
|
1885 case 13:
|
|
1886 if (!yd->wm) {
|
|
1887 yd->wm = TRUE;
|
|
1888 if (yd->fd >= 0)
|
|
1889 close(yd->fd);
|
|
1890 if (gc->inpa)
|
|
1891 gaim_input_remove(gc->inpa);
|
|
1892 gaim_url_fetch(WEBMESSENGER_URL, TRUE, "Gaim/" VERSION, FALSE,
|
|
1893 yahoo_login_page_cb, gc);
|
|
1894 gaim_notify_warning(gc, NULL, _("Normal authentication failed!"),
|
|
1895 _("The normal authentication method has failed. "
|
|
1896 "This means either your password is incorrect, "
|
|
1897 "or Yahoo!'s authentication scheme has changed. "
|
|
1898 "Gaim will now attempt to log in using Web "
|
|
1899 "Messenger authentication, which will result "
|
|
1900 "in reduced functionality and features."));
|
|
1901 return;
|
|
1902 }
|
|
1903 msg = g_strdup(_("Incorrect password."));
|
|
1904 break;
|
|
1905 case 14:
|
|
1906 msg = g_strdup(_("Your account is locked, please log in to the Yahoo! website."));
|
|
1907 break;
|
|
1908 default:
|
|
1909 msg = g_strdup_printf(_("Unknown error number %d. Logging into the Yahoo! website may fix this."), err);
|
|
1910 }
|
|
1911
|
|
1912 if (url)
|
|
1913 fullmsg = g_strdup_printf("%s\n%s", msg, url);
|
|
1914 else
|
|
1915 fullmsg = g_strdup(msg);
|
|
1916
|
|
1917 gc->wants_to_die = TRUE;
|
|
1918 gaim_connection_error(gc, fullmsg);
|
|
1919 g_free(msg);
|
|
1920 g_free(fullmsg);
|
|
1921 }
|
|
1922
|
|
1923 static void yahoo_process_addbuddy(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
1924 {
|
|
1925 int err = 0;
|
|
1926 char *who = NULL;
|
|
1927 char *group = NULL;
|
|
1928 char *decoded_group;
|
|
1929 char *buf;
|
|
1930 YahooFriend *f;
|
|
1931 GSList *l = pkt->hash;
|
|
1932
|
|
1933 while (l) {
|
|
1934 struct yahoo_pair *pair = l->data;
|
|
1935
|
|
1936 switch (pair->key) {
|
|
1937 case 66:
|
|
1938 err = strtol(pair->value, NULL, 10);
|
|
1939 break;
|
|
1940 case 7:
|
|
1941 who = pair->value;
|
|
1942 break;
|
|
1943 case 65:
|
|
1944 group = pair->value;
|
|
1945 break;
|
|
1946 }
|
|
1947
|
|
1948 l = l->next;
|
|
1949 }
|
|
1950
|
|
1951 if (!who)
|
|
1952 return;
|
|
1953 if (!group)
|
|
1954 group = "";
|
|
1955
|
|
1956 if (!err || (err == 2)) { /* 0 = ok, 2 = already on serv list */
|
|
1957 f = yahoo_friend_find_or_new(gc, who);
|
|
1958 yahoo_update_status(gc, who, f);
|
|
1959 return;
|
|
1960 }
|
|
1961
|
|
1962 decoded_group = yahoo_string_decode(gc, group, FALSE);
|
|
1963 buf = g_strdup_printf(_("Could not add buddy %s to group %s to the server list on account %s."),
|
|
1964 who, decoded_group, gaim_connection_get_display_name(gc));
|
|
1965 if (!gaim_conv_present_error(who, gaim_connection_get_account(gc), buf))
|
|
1966 gaim_notify_error(gc, NULL, _("Could not add buddy to server list"), buf);
|
|
1967 g_free(buf);
|
|
1968 g_free(decoded_group);
|
|
1969 }
|
|
1970
|
|
1971 static void yahoo_process_p2p(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
1972 {
|
|
1973 GSList *l = pkt->hash;
|
|
1974 char *who = NULL;
|
|
1975 char *base64 = NULL;
|
|
1976 guchar *decoded;
|
|
1977 gsize len;
|
|
1978
|
|
1979 while (l) {
|
|
1980 struct yahoo_pair *pair = l->data;
|
|
1981
|
|
1982 switch (pair->key) {
|
|
1983 case 5:
|
|
1984 /* our identity */
|
|
1985 break;
|
|
1986 case 4:
|
|
1987 who = pair->value;
|
|
1988 break;
|
|
1989 case 1:
|
|
1990 /* who again, the master identity this time? */
|
|
1991 break;
|
|
1992 case 12:
|
|
1993 base64 = pair->value;
|
|
1994 /* so, this is an ip address. in base64. decoded it's in ascii.
|
|
1995 after strtol, it's in reversed byte order. Who thought this up?*/
|
|
1996 break;
|
|
1997 /*
|
|
1998 TODO: figure these out
|
|
1999 yahoo: Key: 61 Value: 0
|
|
2000 yahoo: Key: 2 Value:
|
|
2001 yahoo: Key: 13 Value: 0
|
|
2002 yahoo: Key: 49 Value: PEERTOPEER
|
|
2003 yahoo: Key: 140 Value: 1
|
|
2004 yahoo: Key: 11 Value: -1786225828
|
|
2005 */
|
|
2006
|
|
2007 }
|
|
2008
|
|
2009 l = l->next;
|
|
2010 }
|
|
2011
|
|
2012 if (base64) {
|
|
2013 guint32 ip;
|
|
2014 char *tmp2;
|
|
2015 YahooFriend *f;
|
|
2016
|
|
2017 decoded = gaim_base64_decode(base64, &len);
|
|
2018 if (len) {
|
|
2019 char *tmp = gaim_str_binary_to_ascii(decoded, len);
|
|
2020 gaim_debug_info("yahoo", "Got P2P service packet (from server): who = %s, ip = %s\n", who, tmp);
|
|
2021 g_free(tmp);
|
|
2022 }
|
|
2023
|
|
2024 tmp2 = g_strndup((const gchar *)decoded, len); /* so its \0 terminated...*/
|
|
2025 ip = strtol(tmp2, NULL, 10);
|
|
2026 g_free(tmp2);
|
|
2027 g_free(decoded);
|
|
2028 tmp2 = g_strdup_printf("%u.%u.%u.%u", ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff,
|
|
2029 (ip >> 24) & 0xff);
|
|
2030 f = yahoo_friend_find(gc, who);
|
|
2031 if (f)
|
|
2032 yahoo_friend_set_ip(f, tmp2);
|
|
2033 g_free(tmp2);
|
|
2034 }
|
|
2035 }
|
|
2036
|
|
2037 static void yahoo_process_audible(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
2038 {
|
|
2039 char *who = NULL, *msg = NULL, *id = NULL;
|
|
2040 GSList *l = pkt->hash;
|
|
2041
|
|
2042 while (l) {
|
|
2043 struct yahoo_pair *pair = l->data;
|
|
2044
|
|
2045 switch (pair->key) {
|
|
2046 case 4:
|
|
2047 who = pair->value;
|
|
2048 break;
|
|
2049 case 5:
|
|
2050 /* us */
|
|
2051 break;
|
|
2052 case 230:
|
|
2053 /* the audible, in foo.locale.bar.baz format
|
|
2054 eg: base.tw.smiley.smiley43 */
|
|
2055 id = pair->value;
|
|
2056 break;
|
|
2057 case 231:
|
|
2058 /* the text of the audible */
|
|
2059 msg = pair->value;
|
|
2060 break;
|
|
2061 case 232:
|
|
2062 /* weird number (md5 hash?), like 8ebab9094156135f5dcbaccbeee662a5c5fd1420 */
|
|
2063 break;
|
|
2064 }
|
|
2065
|
|
2066 l = l->next;
|
|
2067 }
|
|
2068
|
|
2069 if (!msg)
|
|
2070 msg = id;
|
|
2071 if (!who || !msg)
|
|
2072 return;
|
|
2073 if (!g_utf8_validate(msg, -1, NULL)) {
|
|
2074 gaim_debug_misc("yahoo", "Warning, nonutf8 audible, ignoring!\n");
|
|
2075 return;
|
|
2076 }
|
|
2077 if (!yahoo_privacy_check(gc, who)) {
|
|
2078 gaim_debug_misc("yahoo", "Audible message from %s for %s dropped!\n",
|
|
2079 gc->account->username, who);
|
|
2080 return;
|
|
2081 }
|
|
2082 if (id) {
|
|
2083 /* "http://us.dl1.yimg.com/download.yahoo.com/dl/aud/"+locale+"/"+id+".swf" */
|
|
2084 char **audible_locale = g_strsplit(id, ".", 0);
|
|
2085 char *buf = g_strdup_printf(_("[ Audible %s/%s/%s.swf ] %s"), YAHOO_AUDIBLE_URL, audible_locale[1], id, msg);
|
|
2086 g_strfreev(audible_locale);
|
|
2087
|
|
2088 serv_got_im(gc, who, buf, 0, time(NULL));
|
|
2089 g_free(buf);
|
|
2090 } else
|
|
2091 serv_got_im(gc, who, msg, 0, time(NULL));
|
|
2092 }
|
|
2093
|
|
2094 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt)
|
|
2095 {
|
|
2096 switch (pkt->service) {
|
|
2097 case YAHOO_SERVICE_LOGON:
|
|
2098 case YAHOO_SERVICE_LOGOFF:
|
|
2099 case YAHOO_SERVICE_ISAWAY:
|
|
2100 case YAHOO_SERVICE_ISBACK:
|
|
2101 case YAHOO_SERVICE_GAMELOGON:
|
|
2102 case YAHOO_SERVICE_GAMELOGOFF:
|
|
2103 case YAHOO_SERVICE_CHATLOGON:
|
|
2104 case YAHOO_SERVICE_CHATLOGOFF:
|
|
2105 case YAHOO_SERVICE_Y6_STATUS_UPDATE:
|
14258
|
2106 case YAHOO_SERVICE_STATUS_15:
|
14192
|
2107 yahoo_process_status(gc, pkt);
|
|
2108 break;
|
|
2109 case YAHOO_SERVICE_NOTIFY:
|
|
2110 yahoo_process_notify(gc, pkt);
|
|
2111 break;
|
|
2112 case YAHOO_SERVICE_MESSAGE:
|
|
2113 case YAHOO_SERVICE_GAMEMSG:
|
|
2114 case YAHOO_SERVICE_CHATMSG:
|
|
2115 yahoo_process_message(gc, pkt);
|
|
2116 break;
|
|
2117 case YAHOO_SERVICE_SYSMESSAGE:
|
|
2118 yahoo_process_sysmessage(gc, pkt);
|
|
2119 break;
|
|
2120 case YAHOO_SERVICE_NEWMAIL:
|
|
2121 yahoo_process_mail(gc, pkt);
|
|
2122 break;
|
|
2123 case YAHOO_SERVICE_NEWCONTACT:
|
|
2124 yahoo_process_contact(gc, pkt);
|
|
2125 break;
|
|
2126 case YAHOO_SERVICE_AUTHRESP:
|
|
2127 yahoo_process_authresp(gc, pkt);
|
|
2128 break;
|
|
2129 case YAHOO_SERVICE_LIST:
|
|
2130 yahoo_process_list(gc, pkt);
|
|
2131 break;
|
14258
|
2132 case YAHOO_SERVICE_LIST_15:
|
|
2133 yahoo_process_list_15(gc, pkt);
|
|
2134 break;
|
14192
|
2135 case YAHOO_SERVICE_AUTH:
|
|
2136 yahoo_process_auth(gc, pkt);
|
|
2137 break;
|
|
2138 case YAHOO_SERVICE_ADDBUDDY:
|
|
2139 yahoo_process_addbuddy(gc, pkt);
|
|
2140 break;
|
|
2141 case YAHOO_SERVICE_IGNORECONTACT:
|
|
2142 yahoo_process_ignore(gc, pkt);
|
|
2143 break;
|
|
2144 case YAHOO_SERVICE_CONFINVITE:
|
|
2145 case YAHOO_SERVICE_CONFADDINVITE:
|
|
2146 yahoo_process_conference_invite(gc, pkt);
|
|
2147 break;
|
|
2148 case YAHOO_SERVICE_CONFDECLINE:
|
|
2149 yahoo_process_conference_decline(gc, pkt);
|
|
2150 break;
|
|
2151 case YAHOO_SERVICE_CONFLOGON:
|
|
2152 yahoo_process_conference_logon(gc, pkt);
|
|
2153 break;
|
|
2154 case YAHOO_SERVICE_CONFLOGOFF:
|
|
2155 yahoo_process_conference_logoff(gc, pkt);
|
|
2156 break;
|
|
2157 case YAHOO_SERVICE_CONFMSG:
|
|
2158 yahoo_process_conference_message(gc, pkt);
|
|
2159 break;
|
|
2160 case YAHOO_SERVICE_CHATONLINE:
|
|
2161 yahoo_process_chat_online(gc, pkt);
|
|
2162 break;
|
|
2163 case YAHOO_SERVICE_CHATLOGOUT:
|
|
2164 yahoo_process_chat_logout(gc, pkt);
|
|
2165 break;
|
|
2166 case YAHOO_SERVICE_CHATGOTO:
|
|
2167 yahoo_process_chat_goto(gc, pkt);
|
|
2168 break;
|
|
2169 case YAHOO_SERVICE_CHATJOIN:
|
|
2170 yahoo_process_chat_join(gc, pkt);
|
|
2171 break;
|
|
2172 case YAHOO_SERVICE_CHATLEAVE: /* XXX is this right? */
|
|
2173 case YAHOO_SERVICE_CHATEXIT:
|
|
2174 yahoo_process_chat_exit(gc, pkt);
|
|
2175 break;
|
|
2176 case YAHOO_SERVICE_CHATINVITE: /* XXX never seen this one, might not do it right */
|
|
2177 case YAHOO_SERVICE_CHATADDINVITE:
|
|
2178 yahoo_process_chat_addinvite(gc, pkt);
|
|
2179 break;
|
|
2180 case YAHOO_SERVICE_COMMENT:
|
|
2181 yahoo_process_chat_message(gc, pkt);
|
|
2182 break;
|
|
2183 case YAHOO_SERVICE_PRESENCE_PERM:
|
|
2184 case YAHOO_SERVICE_PRESENCE_SESSION:
|
|
2185 yahoo_process_presence(gc, pkt);
|
|
2186 break;
|
|
2187 case YAHOO_SERVICE_P2PFILEXFER:
|
|
2188 /* This case had no break and continued; thus keeping it this way.*/
|
|
2189 yahoo_process_p2pfilexfer(gc, pkt);
|
|
2190 case YAHOO_SERVICE_FILETRANSFER:
|
|
2191 yahoo_process_filetransfer(gc, pkt);
|
|
2192 break;
|
|
2193 case YAHOO_SERVICE_PEERTOPEER:
|
|
2194 yahoo_process_p2p(gc, pkt);
|
|
2195 break;
|
|
2196 case YAHOO_SERVICE_PICTURE:
|
|
2197 yahoo_process_picture(gc, pkt);
|
|
2198 break;
|
|
2199 case YAHOO_SERVICE_PICTURE_UPDATE:
|
|
2200 yahoo_process_picture_update(gc, pkt);
|
|
2201 break;
|
|
2202 case YAHOO_SERVICE_PICTURE_CHECKSUM:
|
|
2203 yahoo_process_picture_checksum(gc, pkt);
|
|
2204 break;
|
|
2205 case YAHOO_SERVICE_PICTURE_UPLOAD:
|
|
2206 yahoo_process_picture_upload(gc, pkt);
|
|
2207 break;
|
|
2208 case YAHOO_SERVICE_AVATAR_UPDATE:
|
|
2209 yahoo_process_avatar_update(gc, pkt);
|
|
2210 break;
|
|
2211 case YAHOO_SERVICE_AUDIBLE:
|
|
2212 yahoo_process_audible(gc, pkt);
|
|
2213 break;
|
|
2214 default:
|
|
2215 gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
|
|
2216 "Unhandled service 0x%02x\n", pkt->service);
|
|
2217 break;
|
|
2218 }
|
|
2219 }
|
|
2220
|
|
2221 static void yahoo_pending(gpointer data, gint source, GaimInputCondition cond)
|
|
2222 {
|
|
2223 GaimConnection *gc = data;
|
|
2224 struct yahoo_data *yd = gc->proto_data;
|
|
2225 char buf[1024];
|
|
2226 int len;
|
|
2227
|
|
2228 len = read(yd->fd, buf, sizeof(buf));
|
|
2229
|
|
2230 if (len <= 0) {
|
|
2231 gaim_connection_error(gc, _("Unable to read"));
|
|
2232 return;
|
|
2233 }
|
|
2234
|
|
2235 yd->rxqueue = g_realloc(yd->rxqueue, len + yd->rxlen);
|
|
2236 memcpy(yd->rxqueue + yd->rxlen, buf, len);
|
|
2237 yd->rxlen += len;
|
|
2238
|
|
2239 while (1) {
|
|
2240 struct yahoo_packet *pkt;
|
|
2241 int pos = 0;
|
|
2242 int pktlen;
|
|
2243
|
|
2244 if (yd->rxlen < YAHOO_PACKET_HDRLEN)
|
|
2245 return;
|
|
2246
|
|
2247 if (strncmp((char *)yd->rxqueue, "YMSG", MIN(4, yd->rxlen)) != 0) {
|
|
2248 /* HEY! This isn't even a YMSG packet. What
|
|
2249 * are you trying to pull? */
|
|
2250 guchar *start;
|
|
2251
|
|
2252 gaim_debug_warning("yahoo", "Error in YMSG stream, got something not a YMSG packet!");
|
|
2253
|
|
2254 start = memchr(yd->rxqueue + 1, 'Y', yd->rxlen - 1);
|
|
2255 if (start) {
|
|
2256 g_memmove(yd->rxqueue, start, yd->rxlen - (start - yd->rxqueue));
|
|
2257 yd->rxlen -= start - yd->rxqueue;
|
|
2258 continue;
|
|
2259 } else {
|
|
2260 g_free(yd->rxqueue);
|
|
2261 yd->rxqueue = NULL;
|
|
2262 yd->rxlen = 0;
|
|
2263 return;
|
|
2264 }
|
|
2265 }
|
|
2266
|
|
2267 pos += 4; /* YMSG */
|
|
2268 pos += 2;
|
|
2269 pos += 2;
|
|
2270
|
|
2271 pktlen = yahoo_get16(yd->rxqueue + pos); pos += 2;
|
|
2272 gaim_debug(GAIM_DEBUG_MISC, "yahoo",
|
|
2273 "%d bytes to read, rxlen is %d\n", pktlen, yd->rxlen);
|
|
2274
|
|
2275 if (yd->rxlen < (YAHOO_PACKET_HDRLEN + pktlen))
|
|
2276 return;
|
|
2277
|
|
2278 yahoo_packet_dump(yd->rxqueue, YAHOO_PACKET_HDRLEN + pktlen);
|
|
2279
|
|
2280 pkt = yahoo_packet_new(0, 0, 0);
|
|
2281
|
|
2282 pkt->service = yahoo_get16(yd->rxqueue + pos); pos += 2;
|
|
2283 pkt->status = yahoo_get32(yd->rxqueue + pos); pos += 4;
|
|
2284 gaim_debug(GAIM_DEBUG_MISC, "yahoo",
|
|
2285 "Yahoo Service: 0x%02x Status: %d\n",
|
|
2286 pkt->service, pkt->status);
|
|
2287 pkt->id = yahoo_get32(yd->rxqueue + pos); pos += 4;
|
|
2288
|
|
2289 yahoo_packet_read(pkt, yd->rxqueue + pos, pktlen);
|
|
2290
|
|
2291 yd->rxlen -= YAHOO_PACKET_HDRLEN + pktlen;
|
|
2292 if (yd->rxlen) {
|
|
2293 guchar *tmp = g_memdup(yd->rxqueue + YAHOO_PACKET_HDRLEN + pktlen, yd->rxlen);
|
|
2294 g_free(yd->rxqueue);
|
|
2295 yd->rxqueue = tmp;
|
|
2296 } else {
|
|
2297 g_free(yd->rxqueue);
|
|
2298 yd->rxqueue = NULL;
|
|
2299 }
|
|
2300
|
|
2301 yahoo_packet_process(gc, pkt);
|
|
2302
|
|
2303 yahoo_packet_free(pkt);
|
|
2304 }
|
|
2305 }
|
|
2306
|
|
2307 static void yahoo_got_connected(gpointer data, gint source, const gchar *error_message)
|
|
2308 {
|
|
2309 GaimConnection *gc = data;
|
|
2310 struct yahoo_data *yd;
|
|
2311 struct yahoo_packet *pkt;
|
|
2312
|
|
2313 if (!GAIM_CONNECTION_IS_VALID(gc)) {
|
|
2314 close(source);
|
|
2315 return;
|
|
2316 }
|
|
2317
|
|
2318 if (source < 0) {
|
|
2319 gaim_connection_error(gc, _("Unable to connect."));
|
|
2320 return;
|
|
2321 }
|
|
2322
|
|
2323 yd = gc->proto_data;
|
|
2324 yd->fd = source;
|
|
2325
|
|
2326 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, yd->current_status, 0);
|
|
2327
|
|
2328 yahoo_packet_hash_str(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc))));
|
|
2329 yahoo_packet_send_and_free(pkt, yd);
|
|
2330
|
|
2331 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc);
|
|
2332 }
|
|
2333
|
|
2334 static void yahoo_got_web_connected(gpointer data, gint source, const gchar *error_message)
|
|
2335 {
|
|
2336 GaimConnection *gc = data;
|
|
2337 struct yahoo_data *yd;
|
|
2338 struct yahoo_packet *pkt;
|
|
2339
|
|
2340 if (!GAIM_CONNECTION_IS_VALID(gc)) {
|
|
2341 close(source);
|
|
2342 return;
|
|
2343 }
|
|
2344
|
|
2345 if (source < 0) {
|
|
2346 gaim_connection_error(gc, _("Unable to connect."));
|
|
2347 return;
|
|
2348 }
|
|
2349
|
|
2350 yd = gc->proto_data;
|
|
2351 yd->fd = source;
|
|
2352
|
|
2353 pkt = yahoo_packet_new(YAHOO_SERVICE_WEBLOGIN, YAHOO_STATUS_WEBLOGIN, 0);
|
|
2354
|
|
2355 yahoo_packet_hash(pkt, "sss", 0,
|
|
2356 gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc))),
|
|
2357 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc))),
|
|
2358 6, yd->auth);
|
|
2359 yahoo_packet_send_and_free(pkt, yd);
|
|
2360
|
|
2361 g_free(yd->auth);
|
|
2362 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc);
|
|
2363 }
|
|
2364
|
|
2365 static void yahoo_web_pending(gpointer data, gint source, GaimInputCondition cond)
|
|
2366 {
|
|
2367 GaimConnection *gc = data;
|
|
2368 GaimAccount *account = gaim_connection_get_account(gc);
|
|
2369 struct yahoo_data *yd = gc->proto_data;
|
|
2370 char bufread[2048], *i = bufread, *buf = bufread;
|
|
2371 int len;
|
|
2372 GString *s;
|
|
2373
|
|
2374 len = read(source, bufread, sizeof(bufread) - 1);
|
|
2375 if (len < 0 && errno == EAGAIN)
|
|
2376 return;
|
|
2377 else if (len <= 0) {
|
|
2378 gaim_connection_error(gc, _("Unable to read"));
|
|
2379 return;
|
|
2380 }
|
|
2381
|
|
2382 if (yd->rxlen > 0 || !g_strstr_len(buf, len, "\r\n\r\n")) {
|
|
2383 yd->rxqueue = g_realloc(yd->rxqueue, yd->rxlen + len + 1);
|
|
2384 memcpy(yd->rxqueue + yd->rxlen, buf, len);
|
|
2385 yd->rxlen += len;
|
14259
|
2386 i = buf = (char *)yd->rxqueue;
|
14192
|
2387 len = yd->rxlen;
|
|
2388 }
|
|
2389 buf[len] = '\0';
|
|
2390
|
|
2391 if ((strncmp(buf, "HTTP/1.0 302", strlen("HTTP/1.0 302")) &&
|
|
2392 strncmp(buf, "HTTP/1.1 302", strlen("HTTP/1.1 302")))) {
|
|
2393 gaim_connection_error(gc, _("Unable to read"));
|
|
2394 return;
|
|
2395 }
|
|
2396
|
|
2397 s = g_string_sized_new(len);
|
|
2398
|
|
2399 while ((i = strstr(i, "Set-Cookie: "))) {
|
|
2400 i += strlen("Set-Cookie: ");
|
|
2401 for (;*i != ';' && *i != '\0'; i++)
|
|
2402 g_string_append_c(s, *i);
|
|
2403
|
|
2404 g_string_append(s, "; ");
|
|
2405 }
|
|
2406
|
|
2407 yd->auth = g_string_free(s, FALSE);
|
|
2408 gaim_input_remove(gc->inpa);
|
|
2409 close(source);
|
|
2410 g_free(yd->rxqueue);
|
|
2411 yd->rxqueue = NULL;
|
|
2412 yd->rxlen = 0;
|
|
2413 /* Now we have our cookies to login with. I'll go get the milk. */
|
|
2414 if (gaim_proxy_connect(account, "wcs2.msg.dcn.yahoo.com",
|
|
2415 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT),
|
|
2416 yahoo_got_web_connected, gc) == NULL) {
|
|
2417 gaim_connection_error(gc, _("Connection problem"));
|
|
2418 return;
|
|
2419 }
|
|
2420 }
|
|
2421
|
|
2422 static void yahoo_got_cookies_send_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
2423 {
|
|
2424 GaimConnection *gc;
|
|
2425 struct yahoo_data *yd;
|
|
2426 int written, remaining;
|
|
2427
|
|
2428 gc = data;
|
|
2429 yd = gc->proto_data;
|
|
2430
|
|
2431 remaining = strlen(yd->auth) - yd->auth_written;
|
|
2432 written = write(source, yd->auth + yd->auth_written, remaining);
|
|
2433
|
|
2434 if (written < 0 && errno == EAGAIN)
|
|
2435 written = 0;
|
|
2436 else if (written <= 0) {
|
|
2437 g_free(yd->auth);
|
|
2438 yd->auth = NULL;
|
|
2439 if (gc->inpa)
|
|
2440 gaim_input_remove(gc->inpa);
|
|
2441 gc->inpa = 0;
|
|
2442 gaim_connection_error(gc, _("Unable to connect."));
|
|
2443 return;
|
|
2444 }
|
|
2445
|
|
2446 if (written < remaining) {
|
|
2447 yd->auth_written += written;
|
|
2448 return;
|
|
2449 }
|
|
2450
|
|
2451 g_free(yd->auth);
|
|
2452 yd->auth = NULL;
|
|
2453 yd->auth_written = 0;
|
|
2454 gaim_input_remove(gc->inpa);
|
|
2455 gc->inpa = gaim_input_add(source, GAIM_INPUT_READ, yahoo_web_pending, gc);
|
|
2456 }
|
|
2457
|
|
2458 static void yahoo_got_cookies(gpointer data, gint source, const gchar *error_message)
|
|
2459 {
|
|
2460 GaimConnection *gc = data;
|
|
2461
|
|
2462 if (source < 0) {
|
|
2463 gaim_connection_error(gc, _("Unable to connect."));
|
|
2464 return;
|
|
2465 }
|
|
2466
|
|
2467 if (gc->inpa == 0)
|
|
2468 {
|
|
2469 gc->inpa = gaim_input_add(source, GAIM_INPUT_WRITE,
|
|
2470 yahoo_got_cookies_send_cb, gc);
|
|
2471 yahoo_got_cookies_send_cb(gc, source, GAIM_INPUT_WRITE);
|
|
2472 }
|
|
2473 }
|
|
2474
|
|
2475 static void yahoo_login_page_hash_iter(const char *key, const char *val, GString *url)
|
|
2476 {
|
|
2477 if (!strcmp(key, "passwd"))
|
|
2478 return;
|
|
2479 g_string_append_c(url, '&');
|
|
2480 g_string_append(url, key);
|
|
2481 g_string_append_c(url, '=');
|
|
2482 if (!strcmp(key, ".save") || !strcmp(key, ".js"))
|
|
2483 g_string_append_c(url, '1');
|
|
2484 else if (!strcmp(key, ".challenge"))
|
|
2485 g_string_append(url, val);
|
|
2486 else
|
|
2487 g_string_append(url, gaim_url_encode(val));
|
|
2488 }
|
|
2489
|
|
2490 static GHashTable *yahoo_login_page_hash(const char *buf, size_t len)
|
|
2491 {
|
|
2492 GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
2493 const char *c = buf;
|
|
2494 char *d;
|
|
2495 char name[64], value[64];
|
|
2496 int count;
|
|
2497 int input_len = strlen("<input ");
|
|
2498 int name_len = strlen("name=\"");
|
|
2499 int value_len = strlen("value=\"");
|
|
2500 while ((len > ((c - buf) + input_len))
|
|
2501 && (c = strstr(c, "<input "))) {
|
|
2502 if (!(c = g_strstr_len(c, len - (c - buf), "name=\"")))
|
|
2503 continue;
|
|
2504 c += name_len;
|
|
2505 count = sizeof(name)-1;
|
|
2506 for (d = name; (len > ((c - buf) + 1)) && *c!='"'
|
|
2507 && count; c++, d++, count--)
|
|
2508 *d = *c;
|
|
2509 *d = '\0';
|
|
2510 count = sizeof(value)-1;
|
|
2511 if (!(d = g_strstr_len(c, len - (c - buf), "value=\"")))
|
|
2512 continue;
|
|
2513 d += value_len;
|
|
2514 if (strchr(c, '>') < d)
|
|
2515 break;
|
|
2516 for (c = d, d = value; (len > ((c - buf) + 1))
|
|
2517 && *c!='"' && count; c++, d++, count--)
|
|
2518 *d = *c;
|
|
2519 *d = '\0';
|
|
2520 g_hash_table_insert(hash, g_strdup(name), g_strdup(value));
|
|
2521 }
|
|
2522 return hash;
|
|
2523 }
|
|
2524
|
|
2525 static void yahoo_login_page_cb(void *user_data, const char *buf, size_t len)
|
|
2526 {
|
|
2527 GaimConnection *gc = (GaimConnection *)user_data;
|
|
2528 GaimAccount *account = gaim_connection_get_account(gc);
|
|
2529 struct yahoo_data *yd = gc->proto_data;
|
|
2530 const char *sn = gaim_account_get_username(account);
|
|
2531 const char *pass = gaim_connection_get_password(gc);
|
|
2532 GHashTable *hash = yahoo_login_page_hash(buf, len);
|
|
2533 GString *url = g_string_new("GET http://login.yahoo.com/config/login?login=");
|
|
2534 char md5[33], *hashp = md5, *chal;
|
|
2535 int i;
|
|
2536 GaimCipher *cipher;
|
|
2537 GaimCipherContext *context;
|
|
2538 guchar digest[16];
|
|
2539
|
|
2540 url = g_string_append(url, sn);
|
|
2541 url = g_string_append(url, "&passwd=");
|
|
2542
|
|
2543 cipher = gaim_ciphers_find_cipher("md5");
|
|
2544 context = gaim_cipher_context_new(cipher, NULL);
|
|
2545
|
|
2546 gaim_cipher_context_append(context, (const guchar *)pass, strlen(pass));
|
|
2547 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
2548 for (i = 0; i < 16; ++i) {
|
|
2549 g_snprintf(hashp, 3, "%02x", digest[i]);
|
|
2550 hashp += 2;
|
|
2551 }
|
|
2552
|
|
2553 chal = g_strconcat(md5, g_hash_table_lookup(hash, ".challenge"), NULL);
|
|
2554 gaim_cipher_context_reset(context, NULL);
|
|
2555 gaim_cipher_context_append(context, (const guchar *)chal, strlen(chal));
|
|
2556 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
2557 hashp = md5;
|
|
2558 for (i = 0; i < 16; ++i) {
|
|
2559 g_snprintf(hashp, 3, "%02x", digest[i]);
|
|
2560 hashp += 2;
|
|
2561 }
|
|
2562 /*
|
|
2563 * I dunno why this is here and commented out.. but in case it's needed
|
|
2564 * I updated it..
|
|
2565
|
|
2566 gaim_cipher_context_reset(context, NULL);
|
|
2567 gaim_cipher_context_append(context, md5, strlen(md5));
|
|
2568 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
|
|
2569 hashp = md5;
|
|
2570 for (i = 0; i < 16; ++i) {
|
|
2571 g_snprintf(hashp, 3, "%02x", digest[i]);
|
|
2572 hashp += 2;
|
|
2573 }
|
|
2574 */
|
|
2575 g_free(chal);
|
|
2576
|
|
2577 url = g_string_append(url, md5);
|
|
2578 g_hash_table_foreach(hash, (GHFunc)yahoo_login_page_hash_iter, url);
|
|
2579
|
|
2580 url = g_string_append(url, "&.hash=1&.md5=1 HTTP/1.1\r\n"
|
|
2581 "Host: login.yahoo.com\r\n\r\n");
|
|
2582 g_hash_table_destroy(hash);
|
|
2583 yd->auth = g_string_free(url, FALSE);
|
|
2584 if (gaim_proxy_connect(account, "login.yahoo.com", 80, yahoo_got_cookies, gc) == NULL) {
|
|
2585 gaim_connection_error(gc, _("Connection problem"));
|
|
2586 return;
|
|
2587 }
|
|
2588
|
|
2589 gaim_cipher_context_destroy(context);
|
|
2590 }
|
|
2591
|
|
2592 static void yahoo_server_check(GaimAccount *account)
|
|
2593 {
|
|
2594 const char *server;
|
|
2595
|
|
2596 server = gaim_account_get_string(account, "server", YAHOO_PAGER_HOST);
|
|
2597
|
|
2598 if (strcmp(server, "scs.yahoo.com") == 0)
|
|
2599 gaim_account_set_string(account, "server", YAHOO_PAGER_HOST);
|
|
2600 }
|
|
2601
|
|
2602 static void yahoo_picture_check(GaimAccount *account)
|
|
2603 {
|
|
2604 GaimConnection *gc = gaim_account_get_connection(account);
|
|
2605 char *buddyicon;
|
|
2606
|
|
2607 buddyicon = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(account));
|
|
2608 yahoo_set_buddy_icon(gc, buddyicon);
|
|
2609 g_free(buddyicon);
|
|
2610 }
|
|
2611
|
|
2612 static int get_yahoo_status_from_gaim_status(GaimStatus *status)
|
|
2613 {
|
|
2614 GaimPresence *presence;
|
|
2615 const char *status_id;
|
|
2616 const char *msg;
|
|
2617
|
|
2618 presence = gaim_status_get_presence(status);
|
|
2619 status_id = gaim_status_get_id(status);
|
|
2620 msg = gaim_status_get_attr_string(status, "message");
|
|
2621
|
|
2622 if (!strcmp(status_id, YAHOO_STATUS_TYPE_AVAILABLE)) {
|
|
2623 if ((msg != NULL) && (*msg != '\0'))
|
|
2624 return YAHOO_STATUS_CUSTOM;
|
|
2625 else
|
|
2626 return YAHOO_STATUS_AVAILABLE;
|
|
2627 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_BRB)) {
|
|
2628 return YAHOO_STATUS_BRB;
|
|
2629 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_BUSY)) {
|
|
2630 return YAHOO_STATUS_BUSY;
|
|
2631 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_NOTATHOME)) {
|
|
2632 return YAHOO_STATUS_NOTATHOME;
|
|
2633 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_NOTATDESK)) {
|
|
2634 return YAHOO_STATUS_NOTATDESK;
|
|
2635 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_NOTINOFFICE)) {
|
|
2636 return YAHOO_STATUS_NOTINOFFICE;
|
|
2637 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_ONPHONE)) {
|
|
2638 return YAHOO_STATUS_ONPHONE;
|
|
2639 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_ONVACATION)) {
|
|
2640 return YAHOO_STATUS_ONVACATION;
|
|
2641 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_OUTTOLUNCH)) {
|
|
2642 return YAHOO_STATUS_OUTTOLUNCH;
|
|
2643 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_STEPPEDOUT)) {
|
|
2644 return YAHOO_STATUS_STEPPEDOUT;
|
|
2645 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_INVISIBLE)) {
|
|
2646 return YAHOO_STATUS_INVISIBLE;
|
|
2647 } else if (!strcmp(status_id, YAHOO_STATUS_TYPE_AWAY)) {
|
|
2648 return YAHOO_STATUS_CUSTOM;
|
|
2649 } else if (gaim_presence_is_idle(presence)) {
|
|
2650 return YAHOO_STATUS_IDLE;
|
|
2651 } else {
|
|
2652 gaim_debug_error("yahoo", "Unexpected GaimStatus!\n");
|
|
2653 return YAHOO_STATUS_AVAILABLE;
|
|
2654 }
|
|
2655 }
|
|
2656
|
|
2657 static void yahoo_login(GaimAccount *account) {
|
|
2658 GaimConnection *gc = gaim_account_get_connection(account);
|
|
2659 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1);
|
|
2660 GaimStatus *status = gaim_account_get_active_status(account);
|
|
2661 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_URLDESC;
|
|
2662
|
|
2663 gaim_connection_update_progress(gc, _("Connecting"), 1, 2);
|
|
2664
|
|
2665 gaim_connection_set_display_name(gc, gaim_account_get_username(account));
|
|
2666
|
|
2667 yd->fd = -1;
|
|
2668 yd->txhandler = -1;
|
|
2669 /* TODO: Is there a good grow size for the buffer? */
|
|
2670 yd->txbuf = gaim_circ_buffer_new(0);
|
|
2671 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free);
|
|
2672 yd->imvironments = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
2673 yd->confs = NULL;
|
|
2674 yd->conf_id = 2;
|
|
2675
|
|
2676 yd->current_status = get_yahoo_status_from_gaim_status(status);
|
|
2677
|
|
2678 yahoo_server_check(account);
|
|
2679 yahoo_picture_check(account);
|
|
2680
|
|
2681 if (gaim_account_get_bool(account, "yahoojp", FALSE)) {
|
|
2682 yd->jp = TRUE;
|
|
2683 if (gaim_proxy_connect(account,
|
|
2684 gaim_account_get_string(account, "serverjp", YAHOOJP_PAGER_HOST),
|
|
2685 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT),
|
|
2686 yahoo_got_connected, gc) == NULL)
|
|
2687 {
|
|
2688 gaim_connection_error(gc, _("Connection problem"));
|
|
2689 return;
|
|
2690 }
|
|
2691 } else {
|
|
2692 yd->jp = FALSE;
|
|
2693 if (gaim_proxy_connect(account,
|
|
2694 gaim_account_get_string(account, "server", YAHOO_PAGER_HOST),
|
|
2695 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT),
|
|
2696 yahoo_got_connected, gc) == NULL)
|
|
2697 {
|
|
2698 gaim_connection_error(gc, _("Connection problem"));
|
|
2699 return;
|
|
2700 }
|
|
2701 }
|
|
2702 }
|
|
2703
|
|
2704 static void yahoo_close(GaimConnection *gc) {
|
|
2705 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
2706 GSList *l;
|
|
2707
|
|
2708 if (gc->inpa)
|
|
2709 gaim_input_remove(gc->inpa);
|
|
2710
|
|
2711 for (l = yd->confs; l; l = l->next) {
|
|
2712 GaimConversation *conv = l->data;
|
|
2713
|
|
2714 yahoo_conf_leave(yd, gaim_conversation_get_name(conv),
|
|
2715 gaim_connection_get_display_name(gc),
|
|
2716 gaim_conv_chat_get_users(GAIM_CONV_CHAT(conv)));
|
|
2717 }
|
|
2718 g_slist_free(yd->confs);
|
|
2719
|
|
2720 yd->chat_online = 0;
|
|
2721 if (yd->in_chat)
|
|
2722 yahoo_c_leave(gc, 1); /* 1 = YAHOO_CHAT_ID */
|
|
2723
|
|
2724 g_hash_table_destroy(yd->friends);
|
|
2725 g_hash_table_destroy(yd->imvironments);
|
|
2726 g_free(yd->chat_name);
|
|
2727
|
|
2728 g_free(yd->cookie_y);
|
|
2729 g_free(yd->cookie_t);
|
|
2730
|
|
2731 if (yd->txhandler)
|
|
2732 gaim_input_remove(yd->txhandler);
|
|
2733
|
|
2734 gaim_circ_buffer_destroy(yd->txbuf);
|
|
2735
|
|
2736 if (yd->fd >= 0)
|
|
2737 close(yd->fd);
|
|
2738
|
|
2739 g_free(yd->rxqueue);
|
|
2740 yd->rxlen = 0;
|
|
2741 g_free(yd->picture_url);
|
|
2742
|
|
2743 if (yd->picture_upload_todo)
|
|
2744 yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo);
|
|
2745 if (yd->ycht)
|
|
2746 ycht_connection_close(yd->ycht);
|
|
2747
|
|
2748 g_free(yd);
|
|
2749 gc->proto_data = NULL;
|
|
2750 }
|
|
2751
|
|
2752 static const char *yahoo_list_icon(GaimAccount *a, GaimBuddy *b)
|
|
2753 {
|
|
2754 return "yahoo";
|
|
2755 }
|
|
2756
|
|
2757 static void yahoo_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne)
|
|
2758 {
|
|
2759 int i = 0;
|
|
2760 char *emblems[4] = {NULL,NULL,NULL,NULL};
|
|
2761 GaimAccount *account;
|
|
2762 GaimConnection *gc;
|
|
2763 struct yahoo_data *yd;
|
|
2764 YahooFriend *f;
|
|
2765 GaimPresence *presence;
|
|
2766
|
|
2767 if (!b || !(account = b->account) || !(gc = gaim_account_get_connection(account)) ||
|
|
2768 !(yd = gc->proto_data))
|
|
2769 return;
|
|
2770
|
|
2771 f = yahoo_friend_find(gc, b->name);
|
|
2772 if (!f) {
|
|
2773 *se = "notauthorized";
|
|
2774 return;
|
|
2775 }
|
|
2776
|
|
2777 presence = gaim_buddy_get_presence(b);
|
|
2778
|
|
2779 if (gaim_presence_is_online(presence) == FALSE) {
|
|
2780 *se = "offline";
|
|
2781 return;
|
|
2782 } else {
|
|
2783 if (f->away)
|
|
2784 emblems[i++] = "away";
|
|
2785 if (f->sms)
|
|
2786 emblems[i++] = "wireless";
|
|
2787 if (yahoo_friend_get_game(f))
|
|
2788 emblems[i++] = "game";
|
|
2789 }
|
|
2790 *se = emblems[0];
|
|
2791 *sw = emblems[1];
|
|
2792 *nw = emblems[2];
|
|
2793 *ne = emblems[3];
|
|
2794 }
|
|
2795
|
|
2796 static const char *yahoo_get_status_string(enum yahoo_status a)
|
|
2797 {
|
|
2798 switch (a) {
|
|
2799 case YAHOO_STATUS_BRB:
|
|
2800 return _("Be Right Back");
|
|
2801 case YAHOO_STATUS_BUSY:
|
|
2802 return _("Busy");
|
|
2803 case YAHOO_STATUS_NOTATHOME:
|
|
2804 return _("Not at Home");
|
|
2805 case YAHOO_STATUS_NOTATDESK:
|
|
2806 return _("Not at Desk");
|
|
2807 case YAHOO_STATUS_NOTINOFFICE:
|
|
2808 return _("Not in Office");
|
|
2809 case YAHOO_STATUS_ONPHONE:
|
|
2810 return _("On the Phone");
|
|
2811 case YAHOO_STATUS_ONVACATION:
|
|
2812 return _("On Vacation");
|
|
2813 case YAHOO_STATUS_OUTTOLUNCH:
|
|
2814 return _("Out to Lunch");
|
|
2815 case YAHOO_STATUS_STEPPEDOUT:
|
|
2816 return _("Stepped Out");
|
|
2817 case YAHOO_STATUS_INVISIBLE:
|
|
2818 return _("Invisible");
|
|
2819 case YAHOO_STATUS_IDLE:
|
|
2820 return _("Idle");
|
|
2821 case YAHOO_STATUS_OFFLINE:
|
|
2822 return _("Offline");
|
|
2823 default:
|
|
2824 return _("Available");
|
|
2825 }
|
|
2826 }
|
|
2827
|
|
2828 static void yahoo_initiate_conference(GaimBlistNode *node, gpointer data) {
|
|
2829
|
|
2830 GaimBuddy *buddy;
|
|
2831 GaimConnection *gc;
|
|
2832
|
|
2833 GHashTable *components;
|
|
2834 struct yahoo_data *yd;
|
|
2835 int id;
|
|
2836
|
|
2837 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
2838
|
|
2839 buddy = (GaimBuddy *) node;
|
|
2840 gc = gaim_account_get_connection(buddy->account);
|
|
2841 yd = gc->proto_data;
|
|
2842 id = yd->conf_id;
|
|
2843
|
|
2844 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
2845 g_hash_table_replace(components, g_strdup("room"),
|
|
2846 g_strdup_printf("%s-%d", gaim_connection_get_display_name(gc), id));
|
|
2847 g_hash_table_replace(components, g_strdup("topic"), g_strdup("Join my conference..."));
|
|
2848 g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference"));
|
|
2849 yahoo_c_join(gc, components);
|
|
2850 g_hash_table_destroy(components);
|
|
2851
|
|
2852 yahoo_c_invite(gc, id, "Join my conference...", buddy->name);
|
|
2853 }
|
|
2854
|
|
2855 static void yahoo_presence_settings(GaimBlistNode *node, gpointer data) {
|
|
2856 GaimBuddy *buddy;
|
|
2857 GaimConnection *gc;
|
|
2858 int presence_val = GPOINTER_TO_INT(data);
|
|
2859
|
|
2860 buddy = (GaimBuddy *) node;
|
|
2861 gc = gaim_account_get_connection(buddy->account);
|
|
2862
|
|
2863 yahoo_friend_update_presence(gc, buddy->name, presence_val);
|
|
2864 }
|
|
2865
|
|
2866 static void yahoo_game(GaimBlistNode *node, gpointer data) {
|
|
2867
|
|
2868 GaimBuddy *buddy;
|
|
2869 GaimConnection *gc;
|
|
2870
|
|
2871 struct yahoo_data *yd;
|
|
2872 const char *game;
|
|
2873 char *game2;
|
|
2874 char *t;
|
|
2875 char url[256];
|
|
2876 YahooFriend *f;
|
|
2877
|
|
2878 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
2879
|
|
2880 buddy = (GaimBuddy *) node;
|
|
2881 gc = gaim_account_get_connection(buddy->account);
|
|
2882 yd = (struct yahoo_data *) gc->proto_data;
|
|
2883
|
|
2884 f = yahoo_friend_find(gc, buddy->name);
|
|
2885 if (!f)
|
|
2886 return;
|
|
2887
|
|
2888 game = yahoo_friend_get_game(f);
|
|
2889 if (!game)
|
|
2890 return;
|
|
2891
|
|
2892 t = game2 = g_strdup(strstr(game, "ante?room="));
|
|
2893 while (*t && *t != '\t')
|
|
2894 t++;
|
|
2895 *t = 0;
|
|
2896 g_snprintf(url, sizeof url, "http://games.yahoo.com/games/%s", game2);
|
|
2897 gaim_notify_uri(gc, url);
|
|
2898 g_free(game2);
|
|
2899 }
|
|
2900
|
|
2901 static char *yahoo_status_text(GaimBuddy *b)
|
|
2902 {
|
|
2903 YahooFriend *f = NULL;
|
|
2904 const char *msg;
|
|
2905 char *msg2;
|
|
2906
|
|
2907 f = yahoo_friend_find(b->account->gc, b->name);
|
|
2908 if (!f)
|
|
2909 return g_strdup(_("Not on server list"));
|
|
2910
|
|
2911 switch (f->status) {
|
|
2912 case YAHOO_STATUS_AVAILABLE:
|
|
2913 return NULL;
|
|
2914 case YAHOO_STATUS_IDLE:
|
|
2915 if (f->idle == -1)
|
|
2916 return g_strdup(yahoo_get_status_string(f->status));
|
|
2917 return NULL;
|
|
2918 case YAHOO_STATUS_CUSTOM:
|
|
2919 if (!(msg = yahoo_friend_get_status_message(f)))
|
|
2920 return NULL;
|
|
2921 msg2 = g_markup_escape_text(msg, strlen(msg));
|
|
2922 gaim_util_chrreplace(msg2, '\n', ' ');
|
|
2923 return msg2;
|
|
2924
|
|
2925 default:
|
|
2926 return g_strdup(yahoo_get_status_string(f->status));
|
|
2927 }
|
|
2928 }
|
|
2929
|
|
2930 void yahoo_tooltip_text(GaimBuddy *b, GString *str, gboolean full)
|
|
2931 {
|
|
2932 YahooFriend *f;
|
|
2933 char *escaped;
|
|
2934 char *status = NULL;
|
|
2935 const char *presence = NULL;
|
|
2936
|
|
2937 f = yahoo_friend_find(b->account->gc, b->name);
|
|
2938 if (!f)
|
|
2939 status = g_strdup_printf("\n%s", _("Not on server list"));
|
|
2940 else {
|
|
2941 switch (f->status) {
|
|
2942 case YAHOO_STATUS_CUSTOM:
|
|
2943 if (!yahoo_friend_get_status_message(f))
|
|
2944 return;
|
|
2945 status = g_strdup(yahoo_friend_get_status_message(f));
|
|
2946 break;
|
|
2947 case YAHOO_STATUS_OFFLINE:
|
|
2948 break;
|
|
2949 default:
|
|
2950 status = g_strdup(yahoo_get_status_string(f->status));
|
|
2951 break;
|
|
2952 }
|
|
2953
|
|
2954 switch (f->presence) {
|
|
2955 case YAHOO_PRESENCE_ONLINE:
|
|
2956 presence = _("Appear Online");
|
|
2957 break;
|
|
2958 case YAHOO_PRESENCE_PERM_OFFLINE:
|
|
2959 presence = _("Appear Permanently Offline");
|
|
2960 break;
|
|
2961 case YAHOO_PRESENCE_DEFAULT:
|
|
2962 break;
|
|
2963 default:
|
|
2964 gaim_debug_error("yahoo", "Unknown presence in yahoo_tooltip_text\n");
|
|
2965 break;
|
|
2966 }
|
|
2967 }
|
|
2968
|
|
2969 if (status != NULL) {
|
|
2970 escaped = g_markup_escape_text(status, strlen(status));
|
|
2971 g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Status"), escaped);
|
|
2972 g_free(status);
|
|
2973 g_free(escaped);
|
|
2974 }
|
|
2975
|
|
2976 if (presence != NULL)
|
|
2977 g_string_append_printf(str, _("\n<b>%s:</b> %s"),
|
|
2978 _("Presence"), presence);
|
|
2979 }
|
|
2980
|
|
2981 static void yahoo_addbuddyfrommenu_cb(GaimBlistNode *node, gpointer data)
|
|
2982 {
|
|
2983 GaimBuddy *buddy;
|
|
2984 GaimConnection *gc;
|
|
2985
|
|
2986 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
2987
|
|
2988 buddy = (GaimBuddy *) node;
|
|
2989 gc = gaim_account_get_connection(buddy->account);
|
|
2990
|
|
2991 yahoo_add_buddy(gc, buddy, NULL);
|
|
2992 }
|
|
2993
|
|
2994
|
|
2995 static void yahoo_chat_goto_menu(GaimBlistNode *node, gpointer data)
|
|
2996 {
|
|
2997 GaimBuddy *buddy;
|
|
2998 GaimConnection *gc;
|
|
2999
|
|
3000 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
3001
|
|
3002 buddy = (GaimBuddy *) node;
|
|
3003 gc = gaim_account_get_connection(buddy->account);
|
|
3004
|
|
3005 yahoo_chat_goto(gc, buddy->name);
|
|
3006 }
|
|
3007
|
|
3008 static GList *build_presence_submenu(YahooFriend *f, GaimConnection *gc) {
|
|
3009 GList *m = NULL;
|
|
3010 GaimMenuAction *act;
|
|
3011 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;
|
|
3012
|
|
3013 if (yd->current_status == YAHOO_STATUS_INVISIBLE) {
|
|
3014 if (f->presence != YAHOO_PRESENCE_ONLINE) {
|
|
3015 act = gaim_menu_action_new(_("Appear Online"),
|
|
3016 GAIM_CALLBACK(yahoo_presence_settings),
|
|
3017 GINT_TO_POINTER(YAHOO_PRESENCE_ONLINE),
|
|
3018 NULL);
|
|
3019 m = g_list_append(m, act);
|
|
3020 } else if (f->presence != YAHOO_PRESENCE_DEFAULT) {
|
|
3021 act = gaim_menu_action_new(_("Appear Offline"),
|
|
3022 GAIM_CALLBACK(yahoo_presence_settings),
|
|
3023 GINT_TO_POINTER(YAHOO_PRESENCE_DEFAULT),
|
|
3024 NULL);
|
|
3025 m = g_list_append(m, act);
|
|
3026 }
|
|
3027 }
|
|
3028
|
|
3029 if (f->presence == YAHOO_PRESENCE_PERM_OFFLINE) {
|
|
3030 act = gaim_menu_action_new(_("Don't Appear Permanently Offline"),
|
|
3031 GAIM_CALLBACK(yahoo_presence_settings),
|
|
3032 GINT_TO_POINTER(YAHOO_PRESENCE_DEFAULT),
|
|
3033 NULL);
|
|
3034 m = g_list_append(m, act);
|
|
3035 } else {
|
|
3036 act = gaim_menu_action_new(_("Appear Permanently Offline"),
|
|
3037 GAIM_CALLBACK(yahoo_presence_settings),
|
|
3038 GINT_TO_POINTER(YAHOO_PRESENCE_PERM_OFFLINE),
|
|
3039 NULL);
|
|
3040 m = g_list_append(m, act);
|
|
3041 }
|
|
3042
|
|
3043 return m;
|
|
3044 }
|
|
3045
|
|
3046 static void yahoo_doodle_blist_node(GaimBlistNode *node, gpointer data)
|
|
3047 {
|
|
3048 GaimBuddy *b = (GaimBuddy *)node;
|
|
3049 GaimConnection *gc = b->account->gc;
|
|
3050
|
|
3051 yahoo_doodle_initiate(gc, b->name);
|
|
3052 }
|
|
3053
|
|
3054 static GList *yahoo_buddy_menu(GaimBuddy *buddy)
|
|
3055 {
|
|
3056 GList *m = NULL;
|
|
3057 GaimMenuAction *act;
|
|
3058
|
|
3059 GaimConnection *gc = gaim_account_get_connection(buddy->account);
|
|
3060 struct yahoo_data *yd = gc->proto_data;
|
|
3061 static char buf2[1024];
|
|
3062 YahooFriend *f;
|
|
3063
|
|
3064 f = yahoo_friend_find(gc, buddy->name);
|
|
3065
|
|
3066 if (!f && !yd->wm) {
|
|
3067 act = gaim_menu_action_new(_("Add Buddy"),
|
|
3068 GAIM_CALLBACK(yahoo_addbuddyfrommenu_cb),
|
|
3069 NULL, NULL);
|
|
3070 m = g_list_append(m, act);
|
|
3071
|
|
3072 return m;
|
|
3073
|
|
3074 }
|
|
3075
|
|
3076 if (f && f->status != YAHOO_STATUS_OFFLINE) {
|
|
3077 if (!yd->wm) {
|
|
3078 act = gaim_menu_action_new(_("Join in Chat"),
|
|
3079 GAIM_CALLBACK(yahoo_chat_goto_menu),
|
|
3080 NULL, NULL);
|
|
3081 m = g_list_append(m, act);
|
|
3082 }
|
|
3083
|
|
3084 act = gaim_menu_action_new(_("Initiate Conference"),
|
|
3085 GAIM_CALLBACK(yahoo_initiate_conference),
|
|
3086 NULL, NULL);
|
|
3087 m = g_list_append(m, act);
|
|
3088
|
|
3089 if (yahoo_friend_get_game(f)) {
|
|
3090 const char *game = yahoo_friend_get_game(f);
|
|
3091 char *room;
|
|
3092 char *t;
|
|
3093
|
|
3094 if ((room = strstr(game, "&follow="))) {/* skip ahead to the url */
|
|
3095 while (*room && *room != '\t') /* skip to the tab */
|
|
3096 room++;
|
|
3097 t = room++; /* room as now at the name */
|
|
3098 while (*t != '\n')
|
|
3099 t++; /* replace the \n with a space */
|
|
3100 *t = ' ';
|
|
3101 g_snprintf(buf2, sizeof buf2, "%s", room);
|
|
3102
|
|
3103 act = gaim_menu_action_new(buf2,
|
|
3104 GAIM_CALLBACK(yahoo_game),
|
|
3105 NULL, NULL);
|
|
3106 m = g_list_append(m, act);
|
|
3107 }
|
|
3108 }
|
|
3109 }
|
|
3110
|
|
3111 if (f) {
|
|
3112 act = gaim_menu_action_new(_("Presence Settings"), NULL, NULL,
|
|
3113 build_presence_submenu(f, gc));
|
|
3114 m = g_list_append(m, act);
|
|
3115 }
|
|
3116
|
|
3117 if (f) {
|
|
3118 act = gaim_menu_action_new(_("Start Doodling"),
|
|
3119 GAIM_CALLBACK(yahoo_doodle_blist_node),
|
|
3120 NULL, NULL);
|
|
3121 m = g_list_append(m, act);
|
|
3122 }
|
|
3123
|
|
3124 return m;
|
|
3125 }
|
|
3126
|
|
3127 static GList *yahoo_blist_node_menu(GaimBlistNode *node)
|
|
3128 {
|
|
3129 if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
|
|
3130 return yahoo_buddy_menu((GaimBuddy *) node);
|
|
3131 } else {
|
|
3132 return NULL;
|
|
3133 }
|
|
3134 }
|
|
3135
|
|
3136 static void yahoo_act_id(GaimConnection *gc, const char *entry)
|
|
3137 {
|
|
3138 struct yahoo_data *yd = gc->proto_data;
|
|
3139
|
|
3140 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0);
|
|
3141 yahoo_packet_hash_str(pkt, 3, entry);
|
|
3142 yahoo_packet_send_and_free(pkt, yd);
|
|
3143
|
|
3144 gaim_connection_set_display_name(gc, entry);
|
|
3145 }
|
|
3146
|
|
3147 static void yahoo_show_act_id(GaimPluginAction *action)
|
|
3148 {
|
|
3149 GaimConnection *gc = (GaimConnection *) action->context;
|
|
3150 gaim_request_input(gc, NULL, _("Active which ID?"), NULL,
|
|
3151 gaim_connection_get_display_name(gc), FALSE, FALSE, NULL,
|
|
3152 _("OK"), G_CALLBACK(yahoo_act_id),
|
|
3153 _("Cancel"), NULL, gc);
|
|
3154 }
|
|
3155
|
|
3156 static void yahoo_show_chat_goto(GaimPluginAction *action)
|
|
3157 {
|
|
3158 GaimConnection *gc = (GaimConnection *) action->context;
|
|
3159 gaim_request_input(gc, NULL, _("Join who in chat?"), NULL,
|
|
3160 "", FALSE, FALSE, NULL,
|
|
3161 _("OK"), G_CALLBACK(yahoo_chat_goto),
|
|
3162 _("Cancel"), NULL, gc);
|
|
3163 }
|
|
3164
|
|
3165 static GList *yahoo_actions(GaimPlugin *plugin, gpointer context) {
|
|
3166 GList *m = NULL;
|
|
3167 GaimPluginAction *act;
|
|
3168
|
|
3169 act = gaim_plugin_action_new(_("Activate ID..."),
|
|
3170 yahoo_show_act_id);
|
|
3171 m = g_list_append(m, act);
|
|
3172
|
|
3173 act = gaim_plugin_action_new(_("Join User in Chat..."),
|
|
3174 yahoo_show_chat_goto);
|
|
3175 m = g_list_append(m, act);
|
|
3176
|
|
3177 return m;
|
|
3178 }
|
|
3179
|
|
3180 static int yahoo_send_im(GaimConnection *gc, const char *who, const char *what, GaimMessageFlags flags)
|
|
3181 {
|
|
3182 struct yahoo_data *yd = gc->proto_data;
|
|
3183 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0);
|
|
3184 char *msg = yahoo_html_to_codes(what);
|
|
3185 char *msg2;
|
|
3186 gboolean utf8 = TRUE;
|
|
3187 GaimWhiteboard *wb;
|
|
3188 int ret = 1;
|
14258
|
3189 YahooFriend *f = NULL;
|
14192
|
3190
|
|
3191 msg2 = yahoo_string_encode(gc, msg, &utf8);
|
|
3192
|
|
3193 yahoo_packet_hash(pkt, "ss", 1, gaim_connection_get_display_name(gc), 5, who);
|
14284
|
3194 if ((f = yahoo_friend_find(gc, who)) && f->protocol)
|
|
3195 yahoo_packet_hash_int(pkt, 241, f->protocol);
|
14258
|
3196
|
14192
|
3197 if (utf8)
|
|
3198 yahoo_packet_hash_str(pkt, 97, "1");
|
|
3199 yahoo_packet_hash_str(pkt, 14, msg2);
|
|
3200
|
|
3201 /*
|
|
3202 * IMVironment.
|
|
3203 *
|
|
3204 * If this message is to a user who is also Doodling with the local user,
|
|
3205 * format the chat packet with the correct IMV information (thanks Yahoo!)
|
|
3206 *
|
|
3207 * Otherwise attempt to use the same IMVironment as the remote user,
|
|
3208 * just so that we don't inadvertantly reset their IMVironment back
|
|
3209 * to nothing.
|
|
3210 *
|
|
3211 * If they have no set an IMVironment, then use the default.
|
|
3212 */
|
|
3213 wb = gaim_whiteboard_get_session(gc->account, who);
|
|
3214 if (wb)
|
|
3215 yahoo_packet_hash_str(pkt, 63, "doodle;11");
|
|
3216 else
|
|
3217 {
|
|
3218 const char *imv;
|
|
3219 imv = g_hash_table_lookup(yd->imvironments, who);
|
|
3220 if (imv != NULL)
|
|
3221 yahoo_packet_hash_str(pkt, 63, imv);
|
|
3222 else
|
|
3223 yahoo_packet_hash_str(pkt, 63, ";0");
|
|
3224 }
|
|
3225
|
|
3226 yahoo_packet_hash_str(pkt, 64, "0"); /* no idea */
|
|
3227 yahoo_packet_hash_str(pkt, 1002, "1"); /* no idea, Yahoo 6 or later only it seems */
|
|
3228 if (!yd->picture_url)
|
|
3229 yahoo_packet_hash_str(pkt, 206, "0"); /* 0 = no picture, 2 = picture, maybe 1 = avatar? */
|
|
3230 else
|
|
3231 yahoo_packet_hash_str(pkt, 206, "2");
|
|
3232
|
|
3233 /* We may need to not send any packets over 2000 bytes, but I'm not sure yet. */
|
|
3234 if ((YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt)) <= 2000)
|
|
3235 yahoo_packet_send(pkt, yd);
|
|
3236 else
|
|
3237 ret = -E2BIG;
|
|
3238
|
|
3239 yahoo_packet_free(pkt);
|
|
3240
|
|
3241 g_free(msg);
|
|
3242 g_free(msg2);
|
|
3243
|
|
3244 return ret;
|
|
3245 }
|
|
3246
|
|
3247 static unsigned int yahoo_send_typing(GaimConnection *gc, const char *who, GaimTypingState state)
|
|
3248 {
|
|
3249 struct yahoo_data *yd = gc->proto_data;
|
|
3250 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0);
|
|
3251 yahoo_packet_hash(pkt, "ssssss", 49, "TYPING", 1, gaim_connection_get_display_name(gc),
|
|
3252 14, " ", 13, state == GAIM_TYPING ? "1" : "0",
|
|
3253 5, who, 1002, "1");
|
|
3254
|
|
3255 yahoo_packet_send_and_free(pkt, yd);
|
|
3256
|
|
3257 return 0;
|
|
3258 }
|
|
3259
|
|
3260 static void yahoo_session_presence_remove(gpointer key, gpointer value, gpointer data)
|
|
3261 {
|
|
3262 YahooFriend *f = value;
|
|
3263 if (f && f->presence == YAHOO_PRESENCE_ONLINE)
|
|
3264 f->presence = YAHOO_PRESENCE_DEFAULT;
|
|
3265 }
|
|
3266
|
|
3267 static void yahoo_set_status(GaimAccount *account, GaimStatus *status)
|
|
3268 {
|
|
3269 GaimConnection *gc;
|
|
3270 GaimPresence *presence;
|
|
3271 struct yahoo_data *yd;
|
|
3272 struct yahoo_packet *pkt;
|
|
3273 int old_status;
|
|
3274 const char *msg = NULL;
|
|
3275 char *tmp = NULL;
|
|
3276 char *conv_msg = NULL;
|
|
3277
|
|
3278 if (!gaim_status_is_active(status))
|
|
3279 return;
|
|
3280
|
|
3281 gc = gaim_account_get_connection(account);
|
|
3282 presence = gaim_status_get_presence(status);
|
|
3283 yd = (struct yahoo_data *)gc->proto_data;
|
|
3284 old_status = yd->current_status;
|
|
3285
|
|
3286 yd->current_status = get_yahoo_status_from_gaim_status(status);
|
|
3287
|
|
3288 if (yd->current_status == YAHOO_STATUS_CUSTOM)
|
|
3289 {
|
|
3290 msg = gaim_status_get_attr_string(status, "message");
|
|
3291
|
|
3292 if (gaim_status_is_available(status)) {
|
|
3293 tmp = yahoo_string_encode(gc, msg, NULL);
|
|
3294 conv_msg = gaim_markup_strip_html(tmp);
|
|
3295 g_free(tmp);
|
|
3296 } else {
|
|
3297 if ((msg == NULL) || (*msg == '\0'))
|
|
3298 msg = _("Away");
|
|
3299 tmp = yahoo_string_encode(gc, msg, NULL);
|
|
3300 conv_msg = gaim_markup_strip_html(tmp);
|
|
3301 g_free(tmp);
|
|
3302 }
|
|
3303 }
|
|
3304
|
|
3305 if (yd->current_status == YAHOO_STATUS_INVISIBLE) {
|
|
3306 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, YAHOO_STATUS_AVAILABLE, 0);
|
|
3307 yahoo_packet_hash_str(pkt, 13, "2");
|
|
3308 yahoo_packet_send_and_free(pkt, yd);
|
|
3309
|
|
3310 return;
|
|
3311 }
|
|
3312
|
|
3313 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
|
|
3314 yahoo_packet_hash_int(pkt, 10, yd->current_status);
|
|
3315
|
|
3316 if (yd->current_status == YAHOO_STATUS_CUSTOM) {
|
|
3317 yahoo_packet_hash_str(pkt, 19, conv_msg);
|
|
3318 } else {
|
|
3319 yahoo_packet_hash_str(pkt, 19, "");
|
|
3320 }
|
|
3321
|
|
3322 g_free(conv_msg);
|
|
3323
|
|
3324 if (gaim_presence_is_idle(presence))
|
|
3325 yahoo_packet_hash_str(pkt, 47, "2");
|
|
3326 else if (!gaim_status_is_available(status))
|
|
3327 yahoo_packet_hash_str(pkt, 47, "1");
|
|
3328
|
|
3329 yahoo_packet_send_and_free(pkt, yd);
|
|
3330
|
|
3331 if (old_status == YAHOO_STATUS_INVISIBLE) {
|
|
3332 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, YAHOO_STATUS_AVAILABLE, 0);
|
|
3333 yahoo_packet_hash_str(pkt, 13, "1");
|
|
3334 yahoo_packet_send_and_free(pkt, yd);
|
|
3335
|
|
3336 /* Any per-session presence settings are removed */
|
|
3337 g_hash_table_foreach(yd->friends, yahoo_session_presence_remove, NULL);
|
|
3338
|
|
3339 }
|
|
3340 }
|
|
3341
|
|
3342 static void yahoo_set_idle(GaimConnection *gc, int idle)
|
|
3343 {
|
|
3344 struct yahoo_data *yd = gc->proto_data;
|
|
3345 struct yahoo_packet *pkt = NULL;
|
|
3346 char *msg = NULL, *msg2 = NULL;
|
|
3347 GaimStatus *status = NULL;
|
|
3348
|
|
3349 if (idle && yd->current_status != YAHOO_STATUS_CUSTOM)
|
|
3350 yd->current_status = YAHOO_STATUS_IDLE;
|
|
3351 else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) {
|
|
3352 status = gaim_presence_get_active_status(gaim_account_get_presence(gaim_connection_get_account(gc)));
|
|
3353 yd->current_status = get_yahoo_status_from_gaim_status(status);
|
|
3354 }
|
|
3355
|
|
3356 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
|
|
3357
|
|
3358 yahoo_packet_hash_int(pkt, 10, yd->current_status);
|
|
3359 if (yd->current_status == YAHOO_STATUS_CUSTOM) {
|
|
3360 const char *tmp;
|
|
3361 if (status == NULL)
|
|
3362 status = gaim_presence_get_active_status(gaim_account_get_presence(gaim_connection_get_account(gc)));
|
|
3363 tmp = gaim_status_get_attr_string(status, "message");
|
|
3364 if (tmp != NULL) {
|
|
3365 msg = yahoo_string_encode(gc, tmp, NULL);
|
|
3366 msg2 = gaim_markup_strip_html(msg);
|
|
3367 yahoo_packet_hash_str(pkt, 19, msg2);
|
|
3368 } else {
|
|
3369 /* get_yahoo_status_from_gaim_status() returns YAHOO_STATUS_CUSTOM for
|
|
3370 * the generic away state (YAHOO_STATUS_TYPE_AWAY) with no message */
|
|
3371 yahoo_packet_hash_str(pkt, 19, _("Away"));
|
|
3372 }
|
|
3373 } else {
|
|
3374 yahoo_packet_hash_str(pkt, 19, "");
|
|
3375 }
|
|
3376
|
|
3377 if (idle)
|
|
3378 yahoo_packet_hash_str(pkt, 47, "2");
|
|
3379 else if (!gaim_presence_is_available(gaim_account_get_presence(gaim_connection_get_account(gc))))
|
|
3380 yahoo_packet_hash_str(pkt, 47, "1");
|
|
3381
|
|
3382 yahoo_packet_send_and_free(pkt, yd);
|
|
3383
|
|
3384 g_free(msg);
|
|
3385 g_free(msg2);
|
|
3386 }
|
|
3387
|
|
3388 static GList *yahoo_status_types(GaimAccount *account)
|
|
3389 {
|
|
3390 GaimStatusType *type;
|
|
3391 GList *types = NULL;
|
|
3392
|
|
3393 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, YAHOO_STATUS_TYPE_AVAILABLE,
|
|
3394 NULL, TRUE, TRUE, FALSE,
|
|
3395 "message", _("Message"),
|
|
3396 gaim_value_new(GAIM_TYPE_STRING), NULL);
|
|
3397 types = g_list_append(types, type);
|
|
3398
|
|
3399 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_AWAY,
|
|
3400 NULL, TRUE, TRUE, FALSE,
|
|
3401 "message", _("Message"),
|
|
3402 gaim_value_new(GAIM_TYPE_STRING), NULL);
|
|
3403 types = g_list_append(types, type);
|
|
3404
|
|
3405 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_BRB, _("Be Right Back"), TRUE);
|
|
3406 types = g_list_append(types, type);
|
|
3407
|
|
3408 type = gaim_status_type_new(GAIM_STATUS_UNAVAILABLE, YAHOO_STATUS_TYPE_BUSY, _("Busy"), TRUE);
|
|
3409 types = g_list_append(types, type);
|
|
3410
|
|
3411 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTATHOME, _("Not at Home"), TRUE);
|
|
3412 types = g_list_append(types, type);
|
|
3413
|
|
3414 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTATDESK, _("Not at Desk"), TRUE);
|
|
3415 types = g_list_append(types, type);
|
|
3416
|
|
3417 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTINOFFICE, _("Not in Office"), TRUE);
|
|
3418 types = g_list_append(types, type);
|
|
3419
|
|
3420 type = gaim_status_type_new(GAIM_STATUS_UNAVAILABLE, YAHOO_STATUS_TYPE_ONPHONE, _("On the Phone"), TRUE);
|
|
3421 types = g_list_append(types, type);
|
|
3422
|
|
3423 type = gaim_status_type_new(GAIM_STATUS_EXTENDED_AWAY, YAHOO_STATUS_TYPE_ONVACATION, _("On Vacation"), TRUE);
|
|
3424 types = g_list_append(types, type);
|
|
3425
|
|
3426 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_OUTTOLUNCH, _("Out to Lunch"), TRUE);
|
|
3427 types = g_list_append(types, type);
|
|
3428
|
|
3429 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_STEPPEDOUT, _("Stepped Out"), TRUE);
|
|
3430 types = g_list_append(types, type);
|
|
3431
|
|
3432
|
|
3433 type = gaim_status_type_new(GAIM_STATUS_INVISIBLE, YAHOO_STATUS_TYPE_INVISIBLE, NULL, TRUE);
|
|
3434 types = g_list_append(types, type);
|
|
3435
|
|
3436 type = gaim_status_type_new(GAIM_STATUS_OFFLINE, YAHOO_STATUS_TYPE_OFFLINE, NULL, TRUE);
|
|
3437 types = g_list_append(types, type);
|
|
3438
|
|
3439 return types;
|
|
3440 }
|
|
3441
|
|
3442 static void yahoo_keepalive(GaimConnection *gc)
|
|
3443 {
|
|
3444 struct yahoo_data *yd = gc->proto_data;
|
|
3445 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0);
|
|
3446 yahoo_packet_send_and_free(pkt, yd);
|
|
3447
|
|
3448 if (!yd->chat_online)
|
|
3449 return;
|
|
3450
|
|
3451 if (yd->wm) {
|
|
3452 ycht_chat_send_keepalive(yd->ycht);
|
|
3453 return;
|
|
3454 }
|
|
3455
|
|
3456 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YAHOO_STATUS_AVAILABLE, 0);
|
|
3457 yahoo_packet_hash_str(pkt, 109, gaim_connection_get_display_name(gc));
|
|
3458 yahoo_packet_send_and_free(pkt, yd);
|
|
3459 }
|
|
3460
|
|
3461 /* XXX - What's the deal with GaimGroup *foo? */
|
|
3462 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *foo)
|
|
3463 {
|
|
3464 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
3465 struct yahoo_packet *pkt;
|
|
3466 GaimGroup *g;
|
|
3467 char *group = NULL;
|
|
3468 char *group2 = NULL;
|
|
3469
|
|
3470 if (!yd->logged_in)
|
|
3471 return;
|
|
3472
|
|
3473 if (!yahoo_privacy_check(gc, gaim_buddy_get_name(buddy)))
|
|
3474 return;
|
|
3475
|
|
3476 if (foo)
|
|
3477 group = foo->name;
|
|
3478 if (!group) {
|
|
3479 g = gaim_buddy_get_group(buddy);
|
|
3480 if (g)
|
|
3481 group = g->name;
|
|
3482 else
|
|
3483 group = "Buddies";
|
|
3484 }
|
|
3485
|
|
3486 group2 = yahoo_string_encode(gc, group, NULL);
|
|
3487 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0);
|
|
3488 yahoo_packet_hash(pkt, "ssss", 1, gaim_connection_get_display_name(gc),
|
|
3489 7, buddy->name, 65, group2, 14, "");
|
|
3490 yahoo_packet_send_and_free(pkt, yd);
|
|
3491 g_free(group2);
|
|
3492 }
|
|
3493
|
|
3494 static void yahoo_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
|
|
3495 {
|
|
3496 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
3497 struct yahoo_packet *pkt;
|
|
3498 GSList *buddies, *l;
|
|
3499 GaimGroup *g;
|
|
3500 gboolean remove = TRUE;
|
|
3501 char *cg;
|
|
3502
|
|
3503 if (!(yahoo_friend_find(gc, buddy->name)))
|
|
3504 return;
|
|
3505
|
|
3506 buddies = gaim_find_buddies(gaim_connection_get_account(gc), buddy->name);
|
|
3507 for (l = buddies; l; l = l->next) {
|
|
3508 g = gaim_buddy_get_group(l->data);
|
|
3509 if (gaim_utf8_strcasecmp(group->name, g->name)) {
|
|
3510 remove = FALSE;
|
|
3511 break;
|
|
3512 }
|
|
3513 }
|
|
3514
|
|
3515 g_slist_free(buddies);
|
|
3516
|
|
3517 if (remove)
|
|
3518 g_hash_table_remove(yd->friends, buddy->name);
|
|
3519
|
|
3520 cg = yahoo_string_encode(gc, group->name, NULL);
|
|
3521 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0);
|
|
3522 yahoo_packet_hash(pkt, "sss", 1, gaim_connection_get_display_name(gc),
|
|
3523 7, buddy->name, 65, cg);
|
|
3524 yahoo_packet_send_and_free(pkt, yd);
|
|
3525 g_free(cg);
|
|
3526 }
|
|
3527
|
|
3528 static void yahoo_add_deny(GaimConnection *gc, const char *who) {
|
|
3529 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
3530 struct yahoo_packet *pkt;
|
|
3531
|
|
3532 if (!yd->logged_in)
|
|
3533 return;
|
|
3534 /* It seems to work better without this */
|
|
3535
|
|
3536 /* if (gc->account->perm_deny != 4)
|
|
3537 return; */
|
|
3538
|
|
3539 if (!who || who[0] == '\0')
|
|
3540 return;
|
|
3541
|
|
3542 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0);
|
|
3543 yahoo_packet_hash(pkt, "sss", 1, gaim_connection_get_display_name(gc),
|
|
3544 7, who, 13, "1");
|
|
3545 yahoo_packet_send_and_free(pkt, yd);
|
|
3546 }
|
|
3547
|
|
3548 static void yahoo_rem_deny(GaimConnection *gc, const char *who) {
|
|
3549 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
3550 struct yahoo_packet *pkt;
|
|
3551
|
|
3552 if (!yd->logged_in)
|
|
3553 return;
|
|
3554
|
|
3555 if (!who || who[0] == '\0')
|
|
3556 return;
|
|
3557
|
|
3558 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0);
|
|
3559 yahoo_packet_hash(pkt, "sss", 1, gaim_connection_get_display_name(gc), 7, who, 13, "2");
|
|
3560 yahoo_packet_send_and_free(pkt, yd);
|
|
3561 }
|
|
3562
|
|
3563 static void yahoo_set_permit_deny(GaimConnection *gc) {
|
|
3564 GaimAccount *acct;
|
|
3565 GSList *deny;
|
|
3566
|
|
3567 acct = gc->account;
|
|
3568
|
|
3569 switch (acct->perm_deny) {
|
|
3570 /* privacy 1 */
|
|
3571 case GAIM_PRIVACY_ALLOW_ALL:
|
|
3572 for (deny = acct->deny;deny;deny = deny->next)
|
|
3573 yahoo_rem_deny(gc, deny->data);
|
|
3574 break;
|
|
3575 /* privacy 3 */
|
|
3576 case GAIM_PRIVACY_ALLOW_USERS:
|
|
3577 for (deny = acct->deny;deny;deny = deny->next)
|
|
3578 yahoo_rem_deny(gc, deny->data);
|
|
3579 break;
|
|
3580 /* privacy 5 */
|
|
3581 case GAIM_PRIVACY_ALLOW_BUDDYLIST:
|
|
3582 /* privacy 4 */
|
|
3583 case GAIM_PRIVACY_DENY_USERS:
|
|
3584 for (deny = acct->deny;deny;deny = deny->next)
|
|
3585 yahoo_add_deny(gc, deny->data);
|
|
3586 break;
|
|
3587 /* privacy 2 */
|
|
3588 case GAIM_PRIVACY_DENY_ALL:
|
|
3589 default:
|
|
3590 break;
|
|
3591 }
|
|
3592 }
|
|
3593
|
|
3594 static gboolean yahoo_unload_plugin(GaimPlugin *plugin)
|
|
3595 {
|
|
3596 yahoo_dest_colorht();
|
|
3597
|
|
3598 return TRUE;
|
|
3599 }
|
|
3600
|
|
3601 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who,
|
|
3602 const char *old_group, const char *new_group)
|
|
3603 {
|
|
3604 struct yahoo_data *yd = gc->proto_data;
|
|
3605 struct yahoo_packet *pkt;
|
|
3606 char *gpn, *gpo;
|
|
3607
|
|
3608 /* Step 0: If they aren't on the server list anyway,
|
|
3609 * don't bother letting the server know.
|
|
3610 */
|
|
3611 if (!yahoo_friend_find(gc, who))
|
|
3612 return;
|
|
3613
|
|
3614 /* If old and new are the same, we would probably
|
|
3615 * end up deleting the buddy, which would be bad.
|
|
3616 * This might happen because of the charset conversation.
|
|
3617 */
|
|
3618 gpn = yahoo_string_encode(gc, new_group, NULL);
|
|
3619 gpo = yahoo_string_encode(gc, old_group, NULL);
|
|
3620 if (!strcmp(gpn, gpo)) {
|
|
3621 g_free(gpn);
|
|
3622 g_free(gpo);
|
|
3623 return;
|
|
3624 }
|
|
3625
|
|
3626 /* Step 1: Add buddy to new group. */
|
|
3627 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0);
|
|
3628 yahoo_packet_hash(pkt, "ssss", 1, gaim_connection_get_display_name(gc),
|
|
3629 7, who, 65, gpn, 14, "");
|
|
3630 yahoo_packet_send_and_free(pkt, yd);
|
|
3631
|
|
3632 /* Step 2: Remove buddy from old group */
|
|
3633 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0);
|
|
3634 yahoo_packet_hash(pkt, "sss", 1, gaim_connection_get_display_name(gc), 7, who, 65, gpo);
|
|
3635 yahoo_packet_send_and_free(pkt, yd);
|
|
3636 g_free(gpn);
|
|
3637 g_free(gpo);
|
|
3638 }
|
|
3639
|
|
3640 static void yahoo_rename_group(GaimConnection *gc, const char *old_name,
|
|
3641 GaimGroup *group, GList *moved_buddies)
|
|
3642 {
|
|
3643 struct yahoo_data *yd = gc->proto_data;
|
|
3644 struct yahoo_packet *pkt;
|
|
3645 char *gpn, *gpo;
|
|
3646
|
|
3647 gpn = yahoo_string_encode(gc, group->name, NULL);
|
|
3648 gpo = yahoo_string_encode(gc, old_name, NULL);
|
|
3649 if (!strcmp(gpn, gpo)) {
|
|
3650 g_free(gpn);
|
|
3651 g_free(gpo);
|
|
3652 return;
|
|
3653 }
|
|
3654
|
|
3655 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, YAHOO_STATUS_AVAILABLE, 0);
|
|
3656 yahoo_packet_hash(pkt, "sss", 1, gaim_connection_get_display_name(gc),
|
|
3657 65, gpo, 67, gpn);
|
|
3658 yahoo_packet_send_and_free(pkt, yd);
|
|
3659 g_free(gpn);
|
|
3660 g_free(gpo);
|
|
3661 }
|
|
3662
|
|
3663 /********************************* Commands **********************************/
|
|
3664
|
|
3665 static GaimCmdRet
|
|
3666 yahoogaim_cmd_buzz(GaimConversation *c, const gchar *cmd, gchar **args, gchar **error, void *data) {
|
|
3667
|
|
3668 GaimAccount *account = gaim_conversation_get_account(c);
|
|
3669 const char *username = gaim_account_get_username(account);
|
|
3670
|
|
3671 if (*args && args[0])
|
|
3672 return GAIM_CMD_RET_FAILED;
|
|
3673
|
|
3674 gaim_debug(GAIM_DEBUG_INFO, "yahoo",
|
|
3675 "Sending <ding> on account %s to buddy %s.\n", username, c->name);
|
|
3676 gaim_conv_im_send(GAIM_CONV_IM(c), "<ding>");
|
|
3677 gaim_conv_im_write(GAIM_CONV_IM(c), "", _("Buzz!!"), GAIM_MESSAGE_NICK|GAIM_MESSAGE_SEND, time(NULL));
|
|
3678 return GAIM_CMD_RET_OK;
|
|
3679 }
|
|
3680
|
|
3681 static GaimPlugin *my_protocol = NULL;
|
|
3682
|
|
3683 static GaimCmdRet
|
|
3684 yahoogaim_cmd_chat_join(GaimConversation *conv, const char *cmd,
|
|
3685 char **args, char **error, void *data)
|
|
3686 {
|
|
3687 GHashTable *comp;
|
|
3688 GaimConnection *gc;
|
|
3689 struct yahoo_data *yd;
|
|
3690 int id;
|
|
3691
|
|
3692 if (!args || !args[0])
|
|
3693 return GAIM_CMD_RET_FAILED;
|
|
3694
|
|
3695 gc = gaim_conversation_get_gc(conv);
|
|
3696 yd = gc->proto_data;
|
|
3697 id = yd->conf_id;
|
|
3698 gaim_debug(GAIM_DEBUG_INFO, "yahoo",
|
|
3699 "Trying to join %s \n", args[0]);
|
|
3700
|
|
3701 comp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
3702 g_hash_table_replace(comp, g_strdup("room"),
|
|
3703 g_strdup_printf("%s", g_ascii_strdown(args[0], strlen(args[0]))));
|
|
3704 g_hash_table_replace(comp, g_strdup("type"), g_strdup("Chat"));
|
|
3705
|
|
3706 yahoo_c_join(gc, comp);
|
|
3707
|
|
3708 g_hash_table_destroy(comp);
|
|
3709 return GAIM_CMD_RET_OK;
|
|
3710 }
|
|
3711
|
|
3712 static GaimCmdRet
|
|
3713 yahoogaim_cmd_chat_list(GaimConversation *conv, const char *cmd,
|
|
3714 char **args, char **error, void *data)
|
|
3715 {
|
|
3716 GaimAccount *account = gaim_conversation_get_account(conv);
|
|
3717 if (*args && args[0])
|
|
3718 return GAIM_CMD_RET_FAILED;
|
|
3719 gaim_roomlist_show_with_account(account);
|
|
3720 return GAIM_CMD_RET_OK;
|
|
3721 }
|
|
3722
|
|
3723 static gboolean yahoo_offline_message(const GaimBuddy *buddy)
|
|
3724 {
|
|
3725 return TRUE;
|
|
3726 }
|
|
3727
|
|
3728 /************************** Plugin Initialization ****************************/
|
|
3729 static void
|
|
3730 yahoogaim_register_commands(void)
|
|
3731 {
|
|
3732 gaim_cmd_register("join", "s", GAIM_CMD_P_PRPL,
|
|
3733 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT |
|
|
3734 GAIM_CMD_FLAG_PRPL_ONLY,
|
|
3735 "prpl-yahoo", yahoogaim_cmd_chat_join,
|
|
3736 _("join <room>: Join a chat room on the Yahoo network"), NULL);
|
|
3737 gaim_cmd_register("list", "", GAIM_CMD_P_PRPL,
|
|
3738 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT |
|
|
3739 GAIM_CMD_FLAG_PRPL_ONLY,
|
|
3740 "prpl-yahoo", yahoogaim_cmd_chat_list,
|
|
3741 _("list: List rooms on the Yahoo network"), NULL);
|
|
3742 gaim_cmd_register("buzz", "", GAIM_CMD_P_PRPL,
|
|
3743 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
3744 "prpl-yahoo", yahoogaim_cmd_buzz,
|
|
3745 _("buzz: Buzz a user to get their attention"), NULL);
|
|
3746 gaim_cmd_register("doodle", "", GAIM_CMD_P_PRPL,
|
|
3747 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
3748 "prpl-yahoo", yahoo_doodle_gaim_cmd_start,
|
|
3749 _("doodle: Request user to start a Doodle session"), NULL);
|
|
3750 }
|
|
3751
|
|
3752 static GaimWhiteboardPrplOps yahoo_whiteboard_prpl_ops =
|
|
3753 {
|
|
3754 yahoo_doodle_start,
|
|
3755 yahoo_doodle_end,
|
|
3756 yahoo_doodle_get_dimensions,
|
|
3757 NULL,
|
|
3758 yahoo_doodle_get_brush,
|
|
3759 yahoo_doodle_set_brush,
|
|
3760 yahoo_doodle_send_draw_list,
|
|
3761 yahoo_doodle_clear
|
|
3762 };
|
|
3763
|
|
3764 static GaimPluginProtocolInfo prpl_info =
|
|
3765 {
|
|
3766 OPT_PROTO_MAIL_CHECK | OPT_PROTO_CHAT_TOPIC,
|
|
3767 NULL, /* user_splits */
|
|
3768 NULL, /* protocol_options */
|
|
3769 {"png", 96, 96, 96, 96, GAIM_ICON_SCALE_SEND},
|
|
3770 yahoo_list_icon,
|
|
3771 yahoo_list_emblems,
|
|
3772 yahoo_status_text,
|
|
3773 yahoo_tooltip_text,
|
|
3774 yahoo_status_types,
|
|
3775 yahoo_blist_node_menu,
|
|
3776 yahoo_c_info,
|
|
3777 yahoo_c_info_defaults,
|
|
3778 yahoo_login,
|
|
3779 yahoo_close,
|
|
3780 yahoo_send_im,
|
|
3781 NULL, /* set info */
|
|
3782 yahoo_send_typing,
|
|
3783 yahoo_get_info,
|
|
3784 yahoo_set_status,
|
|
3785 yahoo_set_idle,
|
|
3786 NULL, /* change_passwd*/
|
|
3787 yahoo_add_buddy,
|
|
3788 NULL, /* add_buddies */
|
|
3789 yahoo_remove_buddy,
|
|
3790 NULL, /*remove_buddies */
|
|
3791 yahoo_add_permit,
|
|
3792 yahoo_add_deny,
|
|
3793 yahoo_rem_permit,
|
|
3794 yahoo_rem_deny,
|
|
3795 yahoo_set_permit_deny,
|
|
3796 yahoo_c_join,
|
|
3797 NULL, /* reject chat invite */
|
|
3798 yahoo_get_chat_name,
|
|
3799 yahoo_c_invite,
|
|
3800 yahoo_c_leave,
|
|
3801 NULL, /* chat whisper */
|
|
3802 yahoo_c_send,
|
|
3803 yahoo_keepalive,
|
|
3804 NULL, /* register_user */
|
|
3805 NULL, /* get_cb_info */
|
|
3806 NULL, /* get_cb_away */
|
|
3807 NULL, /* alias_buddy */
|
|
3808 yahoo_change_buddys_group,
|
|
3809 yahoo_rename_group,
|
|
3810 NULL, /* buddy_free */
|
|
3811 NULL, /* convo_closed */
|
|
3812 gaim_normalize_nocase, /* normalize */
|
|
3813 yahoo_set_buddy_icon,
|
|
3814 NULL, /* void (*remove_group)(GaimConnection *gc, const char *group);*/
|
|
3815 NULL, /* char *(*get_cb_real_name)(GaimConnection *gc, int id, const char *who); */
|
|
3816 NULL, /* set_chat_topic */
|
|
3817 NULL, /* find_blist_chat */
|
|
3818 yahoo_roomlist_get_list,
|
|
3819 yahoo_roomlist_cancel,
|
|
3820 yahoo_roomlist_expand_category,
|
|
3821 NULL, /* can_receive_file */
|
|
3822 yahoo_send_file,
|
|
3823 yahoo_new_xfer,
|
|
3824 yahoo_offline_message, /* offline_message */
|
|
3825 &yahoo_whiteboard_prpl_ops,
|
|
3826 };
|
|
3827
|
|
3828 static GaimPluginInfo info =
|
|
3829 {
|
|
3830 GAIM_PLUGIN_MAGIC,
|
|
3831 GAIM_MAJOR_VERSION,
|
|
3832 GAIM_MINOR_VERSION,
|
|
3833 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
3834 NULL, /**< ui_requirement */
|
|
3835 0, /**< flags */
|
|
3836 NULL, /**< dependencies */
|
|
3837 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
3838 "prpl-yahoo", /**< id */
|
|
3839 "Yahoo", /**< name */
|
|
3840 VERSION, /**< version */
|
|
3841 /** summary */
|
|
3842 N_("Yahoo Protocol Plugin"),
|
|
3843 /** description */
|
|
3844 N_("Yahoo Protocol Plugin"),
|
|
3845 NULL, /**< author */
|
|
3846 GAIM_WEBSITE, /**< homepage */
|
|
3847 NULL, /**< load */
|
|
3848 yahoo_unload_plugin, /**< unload */
|
|
3849 NULL, /**< destroy */
|
|
3850 NULL, /**< ui_info */
|
|
3851 &prpl_info, /**< extra_info */
|
|
3852 NULL,
|
|
3853 yahoo_actions
|
|
3854 };
|
|
3855
|
|
3856 static void
|
|
3857 init_plugin(GaimPlugin *plugin)
|
|
3858 {
|
|
3859 GaimAccountOption *option;
|
|
3860
|
|
3861 option = gaim_account_option_bool_new(_("Yahoo Japan"), "yahoojp", FALSE);
|
|
3862 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3863
|
|
3864 option = gaim_account_option_string_new(_("Pager server"), "server", YAHOO_PAGER_HOST);
|
|
3865 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3866
|
|
3867 option = gaim_account_option_string_new(_("Japan Pager server"), "serverjp", YAHOOJP_PAGER_HOST);
|
|
3868 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3869
|
|
3870 option = gaim_account_option_int_new(_("Pager port"), "port", YAHOO_PAGER_PORT);
|
|
3871 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3872
|
|
3873 option = gaim_account_option_string_new(_("File transfer server"), "xfer_host", YAHOO_XFER_HOST);
|
|
3874 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3875
|
|
3876 option = gaim_account_option_string_new(_("Japan file transfer server"), "xferjp_host", YAHOOJP_XFER_HOST);
|
|
3877 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3878
|
|
3879 option = gaim_account_option_int_new(_("File transfer port"), "xfer_port", YAHOO_XFER_PORT);
|
|
3880 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3881
|
|
3882 option = gaim_account_option_string_new(_("Chat room locale"), "room_list_locale", YAHOO_ROOMLIST_LOCALE);
|
|
3883 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3884
|
|
3885 option = gaim_account_option_bool_new(_("Ignore conference and chatroom invitations"), "ignore_invites", FALSE);
|
|
3886 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3887
|
14285
|
3888 option = gaim_account_option_string_new(_("Encoding"), "local_charset", "ISO-8859-1");
|
|
3889 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3890
|
|
3891
|
14192
|
3892 #if 0
|
|
3893 option = gaim_account_option_string_new(_("Chat room list URL"), "room_list", YAHOO_ROOMLIST_URL);
|
|
3894 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3895
|
|
3896 option = gaim_account_option_string_new(_("Yahoo Chat server"), "ycht-server", YAHOO_YCHT_HOST);
|
|
3897 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3898
|
|
3899 option = gaim_account_option_int_new(_("Yahoo Chat port"), "ycht-port", YAHOO_YCHT_PORT);
|
|
3900 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
3901 #endif
|
|
3902
|
|
3903 my_protocol = plugin;
|
|
3904 yahoogaim_register_commands();
|
|
3905 yahoo_init_colorht();
|
|
3906 }
|
|
3907
|
|
3908 GAIM_INIT_PLUGIN(yahoo, init_plugin, info);
|