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