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