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