Mercurial > pidgin.yaz
annotate src/protocols/yahoo/yahoo.c @ 10009:c124bef68132
[gaim-migrate @ 10926]
Thou shalt NULL terminate va_lists!
This fixes the crash-at-startup bug I mentioned in my commit
of Dave West's stuff last night.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 10 Sep 2004 19:51:52 +0000 |
parents | e4a032202d49 |
children | 2b6bf836c6b9 |
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; | |
916 char *prim, *me = NULL, *msg = NULL; | |
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 | |
929 if (!msg) | |
930 return; | |
931 | |
932 prim = g_strdup_printf(_("Yahoo! system message for %s:"), | |
933 me?me:gaim_connection_get_display_name(gc)); | |
934 gaim_notify_info(NULL, NULL, prim, msg); | |
935 g_free(prim); | |
936 } | |
937 | |
6686 | 938 static void yahoo_buddy_added_us(GaimConnection *gc, struct yahoo_packet *pkt) { |
2681 | 939 char *id = NULL; |
940 char *who = NULL; | |
7827 | 941 char *msg = NULL, *tmpmsg = NULL; |
2681 | 942 GSList *l = pkt->hash; |
943 | |
944 while (l) { | |
945 struct yahoo_pair *pair = l->data; | |
6686 | 946 |
947 switch (pair->key) { | |
948 case 1: | |
2681 | 949 id = pair->value; |
6686 | 950 break; |
951 case 3: | |
2681 | 952 who = pair->value; |
6686 | 953 break; |
954 case 15: /* time, for when they add us and we're offline */ | |
955 break; | |
956 case 14: | |
2681 | 957 msg = pair->value; |
6686 | 958 break; |
959 } | |
2681 | 960 l = l->next; |
961 } | |
962 | |
7827 | 963 if (id) { |
964 if (msg) | |
965 tmpmsg = yahoo_string_decode(gc, msg, FALSE); | |
966 gaim_account_notify_added(gc->account, id, who, NULL, tmpmsg); | |
967 if (tmpmsg) | |
968 g_free(tmpmsg); | |
969 } | |
6686 | 970 } |
971 | |
972 static void yahoo_buddy_denied_our_add(GaimConnection *gc, struct yahoo_packet *pkt) | |
973 { | |
974 char *who = NULL; | |
975 char *msg = NULL; | |
976 GSList *l = pkt->hash; | |
977 GString *buf = NULL; | |
6784 | 978 struct yahoo_data *yd = gc->proto_data; |
6686 | 979 |
980 while (l) { | |
981 struct yahoo_pair *pair = l->data; | |
982 | |
983 switch (pair->key) { | |
984 case 3: | |
985 who = pair->value; | |
986 break; | |
987 case 14: | |
988 msg = pair->value; | |
989 break; | |
990 } | |
991 l = l->next; | |
992 } | |
993 | |
994 if (who) { | |
7827 | 995 char *msg2; |
6686 | 996 buf = g_string_sized_new(0); |
7827 | 997 if (!msg) { |
6686 | 998 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list."), who); |
7827 | 999 } else { |
1000 msg2 = yahoo_string_decode(gc, msg, FALSE); | |
1001 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list for the following reason: %s."), who, msg2); | |
1002 g_free(msg2); | |
1003 } | |
6840 | 1004 gaim_notify_info(gc, NULL, _("Add buddy rejected"), buf->str); |
6686 | 1005 g_string_free(buf, TRUE); |
6784 | 1006 g_hash_table_remove(yd->friends, who); |
9983 | 1007 gaim_prpl_got_user_status(gaim_connection_get_account(gc), who, "offline", NULL); /* FIXME: make this set not on list status instead */ |
6686 | 1008 } |
1009 } | |
1010 | |
1011 static void yahoo_process_contact(GaimConnection *gc, struct yahoo_packet *pkt) | |
1012 { | |
1013 | |
1014 | |
1015 switch (pkt->status) { | |
1016 case 1: | |
1017 yahoo_process_status(gc, pkt); | |
1018 return; | |
1019 case 3: | |
1020 yahoo_buddy_added_us(gc, pkt); | |
1021 break; | |
1022 case 7: | |
1023 yahoo_buddy_denied_our_add(gc, pkt); | |
1024 break; | |
1025 default: | |
1026 break; | |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
1027 } |
2681 | 1028 } |
1029 | |
7747 | 1030 #define OUT_CHARSET "utf-8" |
1031 | |
1032 static char *yahoo_decode(const char *text) | |
1033 { | |
9221 | 1034 char *converted = NULL; |
8125 | 1035 char *n, *new; |
1036 const char *end, *p; | |
8616 | 1037 int i, k; |
8125 | 1038 |
7771 | 1039 n = new = g_malloc(strlen (text) + 1); |
8118 | 1040 end = text + strlen(text); |
1041 | |
8125 | 1042 for (p = text; p < end; p++, n++) { |
7747 | 1043 if (*p == '\\') { |
9064 | 1044 if (p[1] >= '0' && p[1] <= '7') { |
1045 p += 1; | |
1046 for (i = 0, k = 0; k < 3; k += 1) { | |
1047 char c = p[k]; | |
9065 | 1048 if (c < '0' || c > '7') break; |
9064 | 1049 i *= 8; |
1050 i += c - '0'; | |
1051 } | |
1052 *n = i; | |
1053 p += k - 1; | |
1054 } else { /* bug 959248 */ | |
1055 /* If we see a \ not followed by an octal number, | |
1056 * it means that it is actually a \\ with one \ | |
1057 * already eaten by some unknown function. | |
1058 * This is arguably broken. | |
1059 * | |
1060 * I think wing is wrong here, there is no function | |
1061 * called that I see that could have done it. I guess | |
1062 * it is just really sending single \'s. That's yahoo | |
1063 * for you. | |
1064 */ | |
1065 *n = *p; | |
1066 } | |
7747 | 1067 } |
1068 else | |
1069 *n = *p; | |
1070 } | |
1071 | |
1072 *n = '\0'; | |
8125 | 1073 |
9221 | 1074 if (strstr(text, "\033$B")) |
1075 converted = g_convert(new, n - new, OUT_CHARSET, "iso-2022-jp", NULL, NULL, NULL); | |
1076 if (!converted) | |
1077 converted = g_convert(new, n - new, OUT_CHARSET, "iso-8859-1", NULL, NULL, NULL); | |
7747 | 1078 g_free(new); |
1079 | |
1080 return converted; | |
1081 } | |
1082 | |
5583 | 1083 static void yahoo_process_mail(GaimConnection *gc, struct yahoo_packet *pkt) |
2681 | 1084 { |
5583 | 1085 GaimAccount *account = gaim_connection_get_account(gc); |
9221 | 1086 struct yahoo_data *yd = gc->proto_data; |
2681 | 1087 char *who = NULL; |
1088 char *email = NULL; | |
1089 char *subj = NULL; | |
9221 | 1090 char *yahoo_mail_url = (yd->jp? YAHOOJP_MAIL_URL: YAHOO_MAIL_URL); |
2681 | 1091 int count = 0; |
1092 GSList *l = pkt->hash; | |
1093 | |
5583 | 1094 if (!gaim_account_get_check_mail(account)) |
5521
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1095 return; |
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1096 |
2681 | 1097 while (l) { |
1098 struct yahoo_pair *pair = l->data; | |
1099 if (pair->key == 9) | |
1100 count = strtol(pair->value, NULL, 10); | |
1101 else if (pair->key == 43) | |
1102 who = pair->value; | |
1103 else if (pair->key == 42) | |
1104 email = pair->value; | |
1105 else if (pair->key == 18) | |
1106 subj = pair->value; | |
1107 l = l->next; | |
1108 } | |
1109 | |
4001 | 1110 if (who && subj && email && *email) { |
7747 | 1111 char *dec_who = yahoo_decode(who); |
1112 char *dec_subj = yahoo_decode(subj); | |
1113 char *from = g_strdup_printf("%s (%s)", dec_who, email); | |
1114 | |
1115 gaim_notify_email(gc, dec_subj, from, gaim_account_get_username(account), | |
9221 | 1116 yahoo_mail_url, NULL, NULL); |
5521
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1117 |
7747 | 1118 g_free(dec_who); |
1119 g_free(dec_subj); | |
2850
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
1120 g_free(from); |
5521
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1121 } else if (count > 0) { |
5583 | 1122 const char *to = gaim_account_get_username(account); |
9221 | 1123 const char *url = yahoo_mail_url; |
5521
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1124 |
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1125 gaim_notify_emails(gc, count, FALSE, NULL, NULL, &to, &url, |
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1126 NULL, NULL); |
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1127 } |
2681 | 1128 } |
3147 | 1129 /* This is the y64 alphabet... it's like base64, but has a . and a _ */ |
1130 char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; | |
1131 | |
1132 /* This is taken from Sylpheed by Hiroyuki Yamamoto. We have our own tobase64 function | |
1133 * in util.c, but it has a bug I don't feel like finding right now ;) */ | |
1134 void to_y64(unsigned char *out, const unsigned char *in, int inlen) | |
1135 /* raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) */ | |
1136 { | |
1137 for (; inlen >= 3; inlen -= 3) | |
1138 { | |
1139 *out++ = base64digits[in[0] >> 2]; | |
1140 *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)]; | |
1141 *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; | |
1142 *out++ = base64digits[in[2] & 0x3f]; | |
1143 in += 3; | |
1144 } | |
1145 if (inlen > 0) | |
1146 { | |
1147 unsigned char fragment; | |
1148 | |
1149 *out++ = base64digits[in[0] >> 2]; | |
1150 fragment = (in[0] << 4) & 0x30; | |
1151 if (inlen > 1) | |
1152 fragment |= in[1] >> 4; | |
1153 *out++ = base64digits[fragment]; | |
1154 *out++ = (inlen < 2) ? '-' : base64digits[(in[1] << 2) & 0x3c]; | |
1155 *out++ = '-'; | |
1156 } | |
1157 *out = '\0'; | |
1158 } | |
1159 | |
6986 | 1160 static void yahoo_process_auth_old(GaimConnection *gc, const char *seed) |
1161 { | |
1162 struct yahoo_packet *pack; | |
1163 GaimAccount *account = gaim_connection_get_account(gc); | |
7261 | 1164 const char *name = gaim_normalize(account, gaim_account_get_username(account)); |
6986 | 1165 const char *pass = gaim_account_get_password(account); |
1166 struct yahoo_data *yd = gc->proto_data; | |
1167 | |
1168 /* So, Yahoo has stopped supporting its older clients in India, and undoubtedly | |
1169 * will soon do so in the rest of the world. | |
1170 * | |
1171 * 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
|
1172 * bizarre, convoluted, inordinately complicated. It's also no more secure than |
6986 | 1173 * crypt() was. The only purpose this scheme could serve is to prevent third |
1174 * part clients from connecting to their servers. | |
1175 * | |
1176 * Sorry, Yahoo. | |
1177 */ | |
9277 | 1178 |
6986 | 1179 md5_byte_t result[16]; |
1180 md5_state_t ctx; | |
9277 | 1181 |
6986 | 1182 char *crypt_result; |
1183 char password_hash[25]; | |
1184 char crypt_hash[25]; | |
1185 char *hash_string_p = g_malloc(50 + strlen(name)); | |
1186 char *hash_string_c = g_malloc(50 + strlen(name)); | |
9277 | 1187 |
6986 | 1188 char checksum; |
9277 | 1189 |
6986 | 1190 int sv; |
9277 | 1191 |
6986 | 1192 char result6[25]; |
1193 char result96[25]; | |
1194 | |
1195 sv = seed[15]; | |
1196 sv = sv % 8; | |
1197 | |
1198 md5_init(&ctx); | |
1199 md5_append(&ctx, pass, strlen(pass)); | |
1200 md5_finish(&ctx, result); | |
1201 to_y64(password_hash, result, 16); | |
9277 | 1202 |
6986 | 1203 md5_init(&ctx); |
9277 | 1204 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$"); |
6986 | 1205 md5_append(&ctx, crypt_result, strlen(crypt_result)); |
1206 md5_finish(&ctx, result); | |
1207 to_y64(crypt_hash, result, 16); | |
1208 | |
1209 switch (sv) { | |
1210 case 1: | |
1211 case 6: | |
1212 checksum = seed[seed[9] % 16]; | |
1213 g_snprintf(hash_string_p, strlen(name) + 50, | |
1214 "%c%s%s%s", checksum, name, seed, password_hash); | |
1215 g_snprintf(hash_string_c, strlen(name) + 50, | |
1216 "%c%s%s%s", checksum, name, seed, crypt_hash); | |
1217 break; | |
1218 case 2: | |
1219 case 7: | |
1220 checksum = seed[seed[15] % 16]; | |
1221 g_snprintf(hash_string_p, strlen(name) + 50, | |
1222 "%c%s%s%s", checksum, seed, password_hash, name); | |
1223 g_snprintf(hash_string_c, strlen(name) + 50, | |
1224 "%c%s%s%s", checksum, seed, crypt_hash, name); | |
1225 break; | |
1226 case 3: | |
1227 checksum = seed[seed[1] % 16]; | |
1228 g_snprintf(hash_string_p, strlen(name) + 50, | |
1229 "%c%s%s%s", checksum, name, password_hash, seed); | |
1230 g_snprintf(hash_string_c, strlen(name) + 50, | |
1231 "%c%s%s%s", checksum, name, crypt_hash, seed); | |
1232 break; | |
1233 case 4: | |
1234 checksum = seed[seed[3] % 16]; | |
1235 g_snprintf(hash_string_p, strlen(name) + 50, | |
1236 "%c%s%s%s", checksum, password_hash, seed, name); | |
1237 g_snprintf(hash_string_c, strlen(name) + 50, | |
1238 "%c%s%s%s", checksum, crypt_hash, seed, name); | |
1239 break; | |
1240 case 0: | |
1241 case 5: | |
1242 checksum = seed[seed[7] % 16]; | |
1243 g_snprintf(hash_string_p, strlen(name) + 50, | |
1244 "%c%s%s%s", checksum, password_hash, name, seed); | |
1245 g_snprintf(hash_string_c, strlen(name) + 50, | |
1246 "%c%s%s%s", checksum, crypt_hash, name, seed); | |
1247 break; | |
1248 } | |
9277 | 1249 |
1250 md5_init(&ctx); | |
6986 | 1251 md5_append(&ctx, hash_string_p, strlen(hash_string_p)); |
1252 md5_finish(&ctx, result); | |
1253 to_y64(result6, result, 16); | |
9277 | 1254 |
1255 md5_init(&ctx); | |
6986 | 1256 md5_append(&ctx, hash_string_c, strlen(hash_string_c)); |
1257 md5_finish(&ctx, result); | |
1258 to_y64(result96, result, 16); | |
1259 | |
1260 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0); | |
1261 yahoo_packet_hash(pack, 0, name); | |
1262 yahoo_packet_hash(pack, 6, result6); | |
1263 yahoo_packet_hash(pack, 96, result96); | |
1264 yahoo_packet_hash(pack, 1, name); | |
9277 | 1265 |
6986 | 1266 yahoo_send_packet(yd, pack); |
9277 | 1267 |
6986 | 1268 g_free(hash_string_p); |
1269 g_free(hash_string_c); | |
9277 | 1270 |
6986 | 1271 yahoo_packet_free(pack); |
9277 | 1272 |
6986 | 1273 } |
1274 | |
6998 | 1275 /* I'm dishing out some uber-mad props to Cerulean Studios for cracking this |
1276 * and sending the fix! Thanks guys. */ | |
1277 | |
6986 | 1278 static void yahoo_process_auth_new(GaimConnection *gc, const char *seed) |
1279 { | |
1280 struct yahoo_packet *pack = NULL; | |
1281 GaimAccount *account = gaim_connection_get_account(gc); | |
7261 | 1282 const char *name = gaim_normalize(account, gaim_account_get_username(account)); |
6986 | 1283 const char *pass = gaim_account_get_password(account); |
1284 struct yahoo_data *yd = gc->proto_data; | |
9277 | 1285 |
8349 | 1286 md5_byte_t result[16]; |
1287 md5_state_t ctx; | |
9277 | 1288 |
8349 | 1289 SHA_CTX ctx1; |
1290 SHA_CTX ctx2; | |
9277 | 1291 |
8349 | 1292 char *alphabet1 = "FBZDWAGHrJTLMNOPpRSKUVEXYChImkwQ"; |
1293 char *alphabet2 = "F0E1D2C3B4A59687abcdefghijklmnop"; | |
1294 | |
1295 char *challenge_lookup = "qzec2tb3um1olpar8whx4dfgijknsvy5"; | |
1296 char *operand_lookup = "+|&%/*^-"; | |
1297 char *delimit_lookup = ",;"; | |
1298 | |
1299 char *password_hash = (char *)g_malloc(25); | |
1300 char *crypt_hash = (char *)g_malloc(25); | |
1301 char *crypt_result = NULL; | |
1302 | |
1303 char pass_hash_xor1[64]; | |
1304 char pass_hash_xor2[64]; | |
1305 char crypt_hash_xor1[64]; | |
1306 char crypt_hash_xor2[64]; | |
1307 char resp_6[100]; | |
1308 char resp_96[100]; | |
1309 | |
1310 unsigned char digest1[20]; | |
1311 unsigned char digest2[20]; | |
1312 unsigned char comparison_src[20]; | |
1313 unsigned char magic_key_char[4]; | |
8375 | 1314 const unsigned char *magic_ptr; |
8349 | 1315 |
1316 unsigned int magic[64]; | |
1317 unsigned int magic_work = 0; | |
1318 unsigned int magic_4 = 0; | |
1319 | |
1320 int x; | |
1321 int y; | |
1322 int cnt = 0; | |
1323 int magic_cnt = 0; | |
1324 int magic_len; | |
1325 | |
1326 memset(password_hash, 0, 25); | |
1327 memset(crypt_hash, 0, 25); | |
6986 | 1328 memset(&pass_hash_xor1, 0, 64); |
1329 memset(&pass_hash_xor2, 0, 64); | |
1330 memset(&crypt_hash_xor1, 0, 64); | |
1331 memset(&crypt_hash_xor2, 0, 64); | |
1332 memset(&digest1, 0, 20); | |
1333 memset(&digest2, 0, 20); | |
1334 memset(&magic, 0, 64); | |
1335 memset(&resp_6, 0, 100); | |
1336 memset(&resp_96, 0, 100); | |
1337 memset(&magic_key_char, 0, 4); | |
8349 | 1338 memset(&comparison_src, 0, 20); |
6986 | 1339 |
1340 /* | |
8349 | 1341 * Magic: Phase 1. Generate what seems to be a 30 byte value (could change if base64 |
1342 * ends up differently? I don't remember and I'm tired, so use a 64 byte buffer. | |
6986 | 1343 */ |
9277 | 1344 |
6986 | 1345 magic_ptr = seed; |
8375 | 1346 |
6986 | 1347 while (*magic_ptr != (int)NULL) { |
8349 | 1348 char *loc; |
6986 | 1349 |
8349 | 1350 /* Ignore parentheses. |
1351 */ | |
6986 | 1352 |
1353 if (*magic_ptr == '(' || *magic_ptr == ')') { | |
1354 magic_ptr++; | |
1355 continue; | |
1356 } | |
1357 | |
8349 | 1358 /* Characters and digits verify against the challenge lookup. |
1359 */ | |
6986 | 1360 |
1361 if (isalpha(*magic_ptr) || isdigit(*magic_ptr)) { | |
1362 loc = strchr(challenge_lookup, *magic_ptr); | |
1363 if (!loc) { | |
8349 | 1364 /* SME XXX Error - disconnect here */ |
6986 | 1365 } |
1366 | |
8349 | 1367 /* Get offset into lookup table and shl 3. |
1368 */ | |
6986 | 1369 |
1370 magic_work = loc - challenge_lookup; | |
1371 magic_work <<= 3; | |
1372 | |
1373 magic_ptr++; | |
1374 continue; | |
1375 } else { | |
8349 | 1376 unsigned int local_store; |
6986 | 1377 |
1378 loc = strchr(operand_lookup, *magic_ptr); | |
1379 if (!loc) { | |
8349 | 1380 /* SME XXX Disconnect */ |
6986 | 1381 } |
1382 | |
1383 local_store = loc - operand_lookup; | |
8349 | 1384 |
1385 /* Oops; how did this happen? | |
1386 */ | |
1387 | |
6986 | 1388 if (magic_cnt >= 64) |
1389 break; | |
8349 | 1390 |
6986 | 1391 magic[magic_cnt++] = magic_work | local_store; |
1392 magic_ptr++; | |
1393 continue; | |
1394 } | |
8349 | 1395 } |
6986 | 1396 |
1397 magic_len = magic_cnt; | |
1398 magic_cnt = 0; | |
1399 | |
8349 | 1400 /* Magic: Phase 2. Take generated magic value and sprinkle fairy dust on the values. |
1401 */ | |
1402 | |
6986 | 1403 for (magic_cnt = magic_len-2; magic_cnt >= 0; magic_cnt--) { |
8349 | 1404 unsigned char byte1; |
1405 unsigned char byte2; | |
6986 | 1406 |
1407 /* Bad. Abort. | |
1408 */ | |
8349 | 1409 |
1410 if ((magic_cnt + 1 > magic_len) || (magic_cnt > magic_len)) | |
6986 | 1411 break; |
1412 | |
1413 byte1 = magic[magic_cnt]; | |
1414 byte2 = magic[magic_cnt+1]; | |
8349 | 1415 |
6986 | 1416 byte1 *= 0xcd; |
1417 byte1 ^= byte2; | |
1418 | |
1419 magic[magic_cnt+1] = byte1; | |
8349 | 1420 } |
1421 | |
1422 /* | |
1423 * Magic: Phase 3. This computes 20 bytes. The first 4 bytes are used as our magic | |
1424 * key (and may be changed later); the next 16 bytes are an MD5 sum of the magic key | |
1425 * plus 3 bytes. The 3 bytes are found by looping, and they represent the offsets | |
1426 * into particular functions we'll later call to potentially alter the magic key. | |
1427 * | |
1428 * %-) | |
1429 */ | |
1430 | |
1431 magic_cnt = 1; | |
1432 x = 0; | |
1433 | |
1434 do { | |
1435 unsigned int bl = 0; | |
1436 unsigned int cl = magic[magic_cnt++]; | |
1437 | |
1438 if (magic_cnt >= magic_len) | |
1439 break; | |
1440 | |
1441 if (cl > 0x7F) { | |
1442 if (cl < 0xe0) | |
1443 bl = cl = (cl & 0x1f) << 6; | |
1444 else { | |
1445 bl = magic[magic_cnt++]; | |
1446 cl = (cl & 0x0f) << 6; | |
1447 bl = ((bl & 0x3f) + cl) << 6; | |
1448 } | |
9277 | 1449 |
8349 | 1450 cl = magic[magic_cnt++]; |
1451 bl = (cl & 0x3f) + bl; | |
1452 } else | |
1453 bl = cl; | |
1454 | |
1455 comparison_src[x++] = (bl & 0xff00) >> 8; | |
1456 comparison_src[x++] = bl & 0xff; | |
1457 } while (x < 20); | |
1458 | |
1459 /* First four bytes are magic key. | |
1460 */ | |
1461 | |
1462 memcpy(&magic_key_char[0], comparison_src, 4); | |
8482 | 1463 magic_4 = magic_key_char[0] | (magic_key_char[1]<<8) | (magic_key_char[2]<<16) | (magic_key_char[3]<<24); |
8349 | 1464 |
1465 /* | |
1466 * Magic: Phase 4. Determine what function to use later by getting outside/inside | |
1467 * loop values until we match our previous buffer. | |
1468 */ | |
1469 | |
1470 for (x = 0; x < 65535; x++) { | |
1471 int leave = 0; | |
1472 | |
1473 for (y = 0; y < 5; y++) { | |
1474 md5_byte_t result[16]; | |
1475 md5_state_t ctx; | |
1476 | |
1477 unsigned char test[3]; | |
1478 | |
1479 memset(&result, 0, 16); | |
1480 memset(&test, 0, 3); | |
1481 | |
1482 /* Calculate buffer. | |
1483 */ | |
1484 | |
1485 test[0] = x; | |
1486 test[1] = x >> 8; | |
1487 test[2] = y; | |
1488 | |
1489 md5_init(&ctx); | |
1490 md5_append(&ctx, magic_key_char, 4); | |
1491 md5_append(&ctx, test, 3); | |
1492 md5_finish(&ctx, result); | |
1493 | |
1494 if (!memcmp(result, comparison_src+4, 16)) { | |
1495 leave = 1; | |
1496 break; | |
1497 } | |
1498 } | |
1499 | |
1500 if (leave == 1) | |
1501 break; | |
6986 | 1502 } |
1503 | |
8349 | 1504 /* If y != 0, we need some help. |
1505 */ | |
6986 | 1506 |
8349 | 1507 if (y != 0) { |
1508 unsigned int updated_key; | |
6986 | 1509 |
8349 | 1510 /* Update magic stuff. Call it twice because Yahoo's encryption is super bad ass. |
1511 */ | |
7127 | 1512 |
8349 | 1513 updated_key = yahoo_auth_finalCountdown(magic_4, 0x60, y, x); |
1514 updated_key = yahoo_auth_finalCountdown(updated_key, 0x60, y, x); | |
6986 | 1515 |
8482 | 1516 magic_key_char[0] = updated_key & 0xff; |
1517 magic_key_char[1] = (updated_key >> 8) & 0xff; | |
1518 magic_key_char[2] = (updated_key >> 16) & 0xff; | |
1519 magic_key_char[3] = (updated_key >> 24) & 0xff; | |
8349 | 1520 } |
7127 | 1521 |
8349 | 1522 /* Get password and crypt hashes as per usual. |
1523 */ | |
1524 | |
6986 | 1525 md5_init(&ctx); |
8349 | 1526 md5_append(&ctx, pass, strlen(pass)); |
6986 | 1527 md5_finish(&ctx, result); |
1528 to_y64(password_hash, result, 16); | |
1529 | |
1530 md5_init(&ctx); | |
1531 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$"); | |
1532 md5_append(&ctx, crypt_result, strlen(crypt_result)); | |
1533 md5_finish(&ctx, result); | |
1534 to_y64(crypt_hash, result, 16); | |
8349 | 1535 |
1536 /* Our first authentication response is based off of the password hash. | |
1537 */ | |
6986 | 1538 |
1539 for (x = 0; x < (int)strlen(password_hash); x++) | |
1540 pass_hash_xor1[cnt++] = password_hash[x] ^ 0x36; | |
1541 | |
1542 if (cnt < 64) | |
1543 memset(&(pass_hash_xor1[cnt]), 0x36, 64-cnt); | |
8349 | 1544 |
6986 | 1545 cnt = 0; |
1546 | |
1547 for (x = 0; x < (int)strlen(password_hash); x++) | |
1548 pass_hash_xor2[cnt++] = password_hash[x] ^ 0x5c; | |
1549 | |
1550 if (cnt < 64) | |
1551 memset(&(pass_hash_xor2[cnt]), 0x5c, 64-cnt); | |
1552 | |
1553 shaInit(&ctx1); | |
1554 shaInit(&ctx2); | |
1555 | |
8349 | 1556 /* |
1557 * The first context gets the password hash XORed with 0x36 plus a magic value | |
1558 * which we previously extrapolated from our challenge. | |
1559 */ | |
6986 | 1560 |
1561 shaUpdate(&ctx1, pass_hash_xor1, 64); | |
9382 | 1562 if (y >= 3) |
1563 ctx1.sizeLo = 0x1ff; | |
6986 | 1564 shaUpdate(&ctx1, magic_key_char, 4); |
1565 shaFinal(&ctx1, digest1); | |
1566 | |
8349 | 1567 /* |
1568 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest | |
1569 * of the first context. | |
1570 */ | |
6986 | 1571 |
1572 shaUpdate(&ctx2, pass_hash_xor2, 64); | |
1573 shaUpdate(&ctx2, digest1, 20); | |
1574 shaFinal(&ctx2, digest2); | |
1575 | |
8349 | 1576 /* |
1577 * Now that we have digest2, use it to fetch characters from an alphabet to construct | |
1578 * our first authentication response. | |
1579 */ | |
1580 | |
6986 | 1581 for (x = 0; x < 20; x += 2) { |
8349 | 1582 unsigned int val = 0; |
1583 unsigned int lookup = 0; | |
6986 | 1584 |
8349 | 1585 char byte[6]; |
1586 | |
6986 | 1587 memset(&byte, 0, 6); |
8349 | 1588 |
1589 /* First two bytes of digest stuffed together. | |
6986 | 1590 */ |
9277 | 1591 |
6986 | 1592 val = digest2[x]; |
1593 val <<= 8; | |
1594 val += digest2[x+1]; | |
1595 | |
1596 lookup = (val >> 0x0b); | |
1597 lookup &= 0x1f; | |
1598 if (lookup >= strlen(alphabet1)) | |
1599 break; | |
1600 sprintf(byte, "%c", alphabet1[lookup]); | |
1601 strcat(resp_6, byte); | |
1602 strcat(resp_6, "="); | |
8349 | 1603 |
6986 | 1604 lookup = (val >> 0x06); |
1605 lookup &= 0x1f; | |
1606 if (lookup >= strlen(alphabet2)) | |
1607 break; | |
1608 sprintf(byte, "%c", alphabet2[lookup]); | |
1609 strcat(resp_6, byte); | |
1610 | |
1611 lookup = (val >> 0x01); | |
1612 lookup &= 0x1f; | |
1613 if (lookup >= strlen(alphabet2)) | |
1614 break; | |
1615 sprintf(byte, "%c", alphabet2[lookup]); | |
1616 strcat(resp_6, byte); | |
8349 | 1617 |
6986 | 1618 lookup = (val & 0x01); |
1619 if (lookup >= strlen(delimit_lookup)) | |
1620 break; | |
1621 sprintf(byte, "%c", delimit_lookup[lookup]); | |
1622 strcat(resp_6, byte); | |
1623 } | |
1624 | |
8349 | 1625 /* Our second authentication response is based off of the crypto hash. |
1626 */ | |
6986 | 1627 |
1628 cnt = 0; | |
1629 memset(&digest1, 0, 20); | |
1630 memset(&digest2, 0, 20); | |
1631 | |
1632 for (x = 0; x < (int)strlen(crypt_hash); x++) | |
1633 crypt_hash_xor1[cnt++] = crypt_hash[x] ^ 0x36; | |
1634 | |
1635 if (cnt < 64) | |
1636 memset(&(crypt_hash_xor1[cnt]), 0x36, 64-cnt); | |
8349 | 1637 |
6986 | 1638 cnt = 0; |
1639 | |
1640 for (x = 0; x < (int)strlen(crypt_hash); x++) | |
1641 crypt_hash_xor2[cnt++] = crypt_hash[x] ^ 0x5c; | |
1642 | |
1643 if (cnt < 64) | |
1644 memset(&(crypt_hash_xor2[cnt]), 0x5c, 64-cnt); | |
1645 | |
1646 shaInit(&ctx1); | |
1647 shaInit(&ctx2); | |
1648 | |
8349 | 1649 /* |
1650 * The first context gets the password hash XORed with 0x36 plus a magic value | |
1651 * which we previously extrapolated from our challenge. | |
1652 */ | |
6986 | 1653 |
1654 shaUpdate(&ctx1, crypt_hash_xor1, 64); | |
9382 | 1655 if (y >= 3) |
1656 ctx1.sizeLo = 0x1ff; | |
6986 | 1657 shaUpdate(&ctx1, magic_key_char, 4); |
1658 shaFinal(&ctx1, digest1); | |
1659 | |
8349 | 1660 /* |
1661 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest | |
1662 * of the first context. | |
1663 */ | |
6986 | 1664 |
1665 shaUpdate(&ctx2, crypt_hash_xor2, 64); | |
1666 shaUpdate(&ctx2, digest1, 20); | |
1667 shaFinal(&ctx2, digest2); | |
1668 | |
8349 | 1669 /* |
1670 * Now that we have digest2, use it to fetch characters from an alphabet to construct | |
1671 * our first authentication response. | |
1672 */ | |
6986 | 1673 |
1674 for (x = 0; x < 20; x += 2) { | |
8349 | 1675 unsigned int val = 0; |
1676 unsigned int lookup = 0; | |
6986 | 1677 |
8349 | 1678 char byte[6]; |
6986 | 1679 |
1680 memset(&byte, 0, 6); | |
1681 | |
8349 | 1682 /* First two bytes of digest stuffed together. |
1683 */ | |
6986 | 1684 |
1685 val = digest2[x]; | |
1686 val <<= 8; | |
1687 val += digest2[x+1]; | |
8349 | 1688 |
6986 | 1689 lookup = (val >> 0x0b); |
1690 lookup &= 0x1f; | |
1691 if (lookup >= strlen(alphabet1)) | |
1692 break; | |
1693 sprintf(byte, "%c", alphabet1[lookup]); | |
1694 strcat(resp_96, byte); | |
1695 strcat(resp_96, "="); | |
1696 | |
1697 lookup = (val >> 0x06); | |
1698 lookup &= 0x1f; | |
1699 if (lookup >= strlen(alphabet2)) | |
1700 break; | |
1701 sprintf(byte, "%c", alphabet2[lookup]); | |
1702 strcat(resp_96, byte); | |
1703 | |
1704 lookup = (val >> 0x01); | |
1705 lookup &= 0x1f; | |
1706 if (lookup >= strlen(alphabet2)) | |
1707 break; | |
1708 sprintf(byte, "%c", alphabet2[lookup]); | |
1709 strcat(resp_96, byte); | |
1710 | |
1711 lookup = (val & 0x01); | |
1712 if (lookup >= strlen(delimit_lookup)) | |
1713 break; | |
1714 sprintf(byte, "%c", delimit_lookup[lookup]); | |
1715 strcat(resp_96, byte); | |
1716 } | |
1717 | |
1718 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0); | |
1719 yahoo_packet_hash(pack, 0, name); | |
1720 yahoo_packet_hash(pack, 6, resp_6); | |
1721 yahoo_packet_hash(pack, 96, resp_96); | |
1722 yahoo_packet_hash(pack, 1, name); | |
9888 | 1723 yahoo_packet_hash(pack, 135, "6,0,0,1710"); |
9306 | 1724 if (yd->picture_checksum) { |
1725 char *cksum = g_strdup_printf("%d", yd->picture_checksum); | |
1726 yahoo_packet_hash(pack, 192, cksum); | |
1727 g_free(cksum); | |
1728 } | |
6986 | 1729 yahoo_send_packet(yd, pack); |
1730 yahoo_packet_free(pack); | |
1731 | |
7424 | 1732 g_free(password_hash); |
1733 g_free(crypt_hash); | |
6986 | 1734 } |
1735 | |
5583 | 1736 static void yahoo_process_auth(GaimConnection *gc, struct yahoo_packet *pkt) |
3147 | 1737 { |
1738 char *seed = NULL; | |
1739 char *sn = NULL; | |
1740 GSList *l = pkt->hash; | |
7010 | 1741 int m = 0; |
9277 | 1742 gchar *buf; |
1743 | |
1744 | |
3147 | 1745 while (l) { |
1746 struct yahoo_pair *pair = l->data; | |
1747 if (pair->key == 94) | |
1748 seed = pair->value; | |
1749 if (pair->key == 1) | |
1750 sn = pair->value; | |
6986 | 1751 if (pair->key == 13) |
1752 m = atoi(pair->value); | |
3147 | 1753 l = l->next; |
1754 } | |
9277 | 1755 |
3147 | 1756 if (seed) { |
6986 | 1757 switch (m) { |
1758 case 0: | |
1759 yahoo_process_auth_old(gc, seed); | |
1760 break; | |
3147 | 1761 case 1: |
6986 | 1762 yahoo_process_auth_new(gc, seed); |
3147 | 1763 break; |
6986 | 1764 default: |
7043 | 1765 buf = g_strdup_printf(_("The Yahoo server has requested the use of an unrecognized " |
7129 | 1766 "authentication method. This version of Gaim will likely not be able " |
7043 | 1767 "to successfully sign on to Yahoo. Check %s for updates."), GAIM_WEBSITE); |
6986 | 1768 gaim_notify_error(gc, "", _("Failed Yahoo! Authentication"), |
7043 | 1769 buf); |
1770 g_free(buf); | |
6986 | 1771 yahoo_process_auth_new(gc, seed); /* Can't hurt to try it anyway. */ |
3147 | 1772 } |
1773 } | |
1774 } | |
2681 | 1775 |
9285 | 1776 static void ignore_buddy(GaimBuddy *buddy) { |
1777 GaimGroup *group; | |
1778 GaimConversation *conv; | |
6760 | 1779 GaimAccount *account; |
1780 gchar *name; | |
1781 | |
9285 | 1782 if (!buddy) |
6792 | 1783 return; |
6760 | 1784 |
9285 | 1785 group = gaim_find_buddys_group(buddy); |
1786 name = g_strdup(buddy->name); | |
1787 account = buddy->account; | |
6760 | 1788 |
6792 | 1789 gaim_debug(GAIM_DEBUG_INFO, "blist", |
9285 | 1790 "Removing '%s' from buddy list.\n", buddy->name); |
1791 serv_remove_buddy(account->gc, buddy, group); | |
1792 gaim_blist_remove_buddy(buddy); | |
6760 | 1793 |
6792 | 1794 serv_add_deny(account->gc, name); |
9285 | 1795 |
1796 conv = gaim_find_conversation_with_account(name, account); | |
1797 | |
1798 if (conv != NULL) | |
1799 gaim_conversation_update(conv, GAIM_CONV_UPDATE_REMOVE); | |
6760 | 1800 |
1801 g_free(name); | |
1802 } | |
1803 | |
1804 static void keep_buddy(GaimBuddy *b) { | |
1805 gaim_privacy_deny_remove(b->account, b->name, 1); | |
1806 } | |
1807 | |
1808 static void yahoo_process_ignore(GaimConnection *gc, struct yahoo_packet *pkt) { | |
1809 GaimBuddy *b; | |
1810 GSList *l; | |
1811 gchar *who = NULL; | |
1812 gchar *sn = NULL; | |
1813 gchar buf[BUF_LONG]; | |
1814 gint ignore = 0; | |
1815 gint status = 0; | |
1816 | |
1817 for (l = pkt->hash; l; l = l->next) { | |
1818 struct yahoo_pair *pair = l->data; | |
1819 switch (pair->key) { | |
1820 case 0: | |
1821 who = pair->value; | |
1822 break; | |
1823 case 1: | |
1824 sn = pair->value; | |
1825 break; | |
1826 case 13: | |
1827 ignore = strtol(pair->value, NULL, 10); | |
1828 break; | |
1829 case 66: | |
1830 status = strtol(pair->value, NULL, 10); | |
1831 break; | |
1832 default: | |
1833 break; | |
1834 } | |
1835 } | |
1836 | |
1837 switch (status) { | |
1838 case 12: | |
1839 b = gaim_find_buddy(gc->account, who); | |
1840 g_snprintf(buf, sizeof(buf), _("You have tried to ignore %s, but the " | |
1841 "user is on your buddy list. Clicking \"Yes\" " | |
1842 "will remove and ignore the buddy."), who); | |
1843 gaim_request_yes_no(gc, NULL, _("Ignore buddy?"), buf, 0, b, | |
1844 G_CALLBACK(ignore_buddy), | |
1845 G_CALLBACK(keep_buddy)); | |
1846 break; | |
1847 case 2: | |
1848 case 3: | |
1849 case 0: | |
1850 default: | |
1851 break; | |
1852 } | |
1853 } | |
1854 | |
6761 | 1855 static void yahoo_process_authresp(GaimConnection *gc, struct yahoo_packet *pkt) |
1856 { | |
9410 | 1857 struct yahoo_data *yd = gc->proto_data; |
6761 | 1858 GSList *l = pkt->hash; |
1859 int err = 0; | |
1860 char *msg; | |
7865 | 1861 char *url = NULL; |
1862 char *fullmsg; | |
6761 | 1863 |
1864 while (l) { | |
1865 struct yahoo_pair *pair = l->data; | |
1866 | |
1867 if (pair->key == 66) | |
1868 err = strtol(pair->value, NULL, 10); | |
7865 | 1869 if (pair->key == 20) |
1870 url = pair->value; | |
6761 | 1871 |
1872 l = l->next; | |
1873 } | |
1874 | |
1875 switch (err) { | |
1876 case 3: | |
7865 | 1877 msg = g_strdup(_("Invalid username.")); |
6761 | 1878 break; |
1879 case 13: | |
9410 | 1880 if (!yd->wm) { |
1881 yd->wm = TRUE; | |
1882 if (yd->fd >= 0) | |
1883 close(yd->fd); | |
1884 if (gc->inpa) | |
1885 gaim_input_remove(gc->inpa); | |
1886 gaim_url_fetch(WEBMESSENGER_URL, TRUE, "Gaim/" VERSION, FALSE, | |
1887 yahoo_login_page_cb, gc); | |
9835 | 1888 gaim_notify_warning(gc, NULL, _("Normal authentication failed!"), |
1889 _("The normal authentication method has failed. " | |
9410 | 1890 "This means either your password is incorrect, " |
9835 | 1891 "or Yahoo!'s authentication scheme has changed. " |
9410 | 1892 "Gaim will now attempt to log in using Web " |
9835 | 1893 "Messenger authentication, which will result " |
9410 | 1894 "in reduced functionality and features.")); |
1895 return; | |
1896 } | |
7865 | 1897 msg = g_strdup(_("Incorrect password.")); |
1898 break; | |
1899 case 14: | |
9280 | 1900 msg = g_strdup(_("Your account is locked, please log in to the Yahoo! website.")); |
6761 | 1901 break; |
1902 default: | |
9280 | 1903 msg = g_strdup_printf(_("Unknown error number %d. Logging into the Yahoo! website may fix this."), err); |
6761 | 1904 } |
7865 | 1905 |
1906 if (url) | |
1907 fullmsg = g_strdup_printf("%s\n%s", msg, url); | |
1908 else | |
1909 fullmsg = g_strdup(msg); | |
1910 | |
9280 | 1911 gc->wants_to_die = TRUE; |
7865 | 1912 gaim_connection_error(gc, fullmsg); |
1913 g_free(msg); | |
1914 g_free(fullmsg); | |
6761 | 1915 } |
1916 | |
6840 | 1917 static void yahoo_process_addbuddy(GaimConnection *gc, struct yahoo_packet *pkt) |
1918 { | |
1919 int err = 0; | |
1920 char *who = NULL; | |
1921 char *group = NULL; | |
7827 | 1922 char *decoded_group; |
6840 | 1923 char *buf; |
9278 | 1924 YahooFriend *f; |
6840 | 1925 GSList *l = pkt->hash; |
1926 | |
1927 while (l) { | |
1928 struct yahoo_pair *pair = l->data; | |
1929 | |
1930 switch (pair->key) { | |
1931 case 66: | |
1932 err = strtol(pair->value, NULL, 10); | |
1933 break; | |
1934 case 7: | |
1935 who = pair->value; | |
1936 break; | |
1937 case 65: | |
1938 group = pair->value; | |
1939 break; | |
1940 } | |
1941 | |
1942 l = l->next; | |
1943 } | |
1944 | |
1945 if (!who) | |
1946 return; | |
1947 if (!group) | |
1948 group = ""; | |
1949 | |
1950 if (!err || (err == 2)) { /* 0 = ok, 2 = already on serv list */ | |
9279 | 1951 f = yahoo_friend_find_or_new(gc, who); |
1952 yahoo_update_status(gc, who, f); | |
6840 | 1953 return; |
1954 } | |
1955 | |
7827 | 1956 decoded_group = yahoo_string_decode(gc, group, FALSE); |
6840 | 1957 buf = g_strdup_printf(_("Could not add buddy %s to group %s to the server list on account %s."), |
7827 | 1958 who, decoded_group, gaim_connection_get_display_name(gc)); |
9637 | 1959 if (!gaim_conv_present_error(who, gaim_connection_get_account(gc), buf)) |
1960 gaim_notify_error(gc, NULL, _("Could not add buddy to server list"), buf); | |
6840 | 1961 g_free(buf); |
7827 | 1962 g_free(decoded_group); |
6840 | 1963 } |
1964 | |
9062 | 1965 static void yahoo_process_p2p(GaimConnection *gc, struct yahoo_packet *pkt) |
1966 { | |
1967 GSList *l = pkt->hash; | |
1968 char *who = NULL; | |
1969 char *base64 = NULL; | |
9277 | 1970 char *decoded; |
9062 | 1971 int len; |
1972 | |
1973 while (l) { | |
1974 struct yahoo_pair *pair = l->data; | |
1975 | |
1976 switch (pair->key) { | |
1977 case 5: | |
1978 /* our identity */ | |
1979 break; | |
1980 case 4: | |
1981 who = pair->value; | |
1982 break; | |
1983 case 1: | |
1984 /* who again, the master identity this time? */ | |
1985 break; | |
1986 case 12: | |
1987 base64 = pair->value; | |
1988 /* so, this is an ip address. in base64. decoded it's in ascii. | |
1989 after strtol, it's in reversed byte order. Who thought this up?*/ | |
1990 break; | |
1991 /* | |
1992 TODO: figure these out | |
1993 yahoo: Key: 61 Value: 0 | |
1994 yahoo: Key: 2 Value: | |
1995 yahoo: Key: 13 Value: 0 | |
1996 yahoo: Key: 49 Value: PEERTOPEER | |
1997 yahoo: Key: 140 Value: 1 | |
1998 yahoo: Key: 11 Value: -1786225828 | |
1999 */ | |
2000 | |
2001 } | |
2002 | |
2003 l = l->next; | |
2004 } | |
2005 | |
9277 | 2006 if (base64) { |
9281 | 2007 guint32 ip; |
2008 char *tmp2; | |
2009 YahooFriend *f; | |
2010 | |
9062 | 2011 gaim_base64_decode(base64, &decoded, &len); |
9277 | 2012 if (len) { |
2013 char *tmp = gaim_str_binary_to_ascii(decoded, len); | |
2014 gaim_debug_info("yahoo", "Got P2P service packet (from server): who = %s, ip = %s\n", who, tmp); | |
2015 g_free(tmp); | |
2016 } | |
9281 | 2017 |
2018 tmp2 = g_strndup(decoded, len); /* so its \0 terminated...*/ | |
2019 ip = strtol(tmp2, NULL, 10); | |
2020 g_free(tmp2); | |
9062 | 2021 g_free(decoded); |
9281 | 2022 tmp2 = g_strdup_printf("%u.%u.%u.%u", ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff, |
2023 (ip >> 24) & 0xff); | |
2024 f = yahoo_friend_find(gc, who); | |
2025 if (f) | |
2026 yahoo_friend_set_ip(f, tmp2); | |
2027 g_free(tmp2); | |
9062 | 2028 } |
2029 } | |
2030 | |
9604 | 2031 static void yahoo_process_audible(GaimConnection *gc, struct yahoo_packet *pkt) |
2032 { | |
2033 char *who = NULL, *msg = NULL; | |
2034 GSList *l = pkt->hash; | |
2035 | |
2036 while (l) { | |
2037 struct yahoo_pair *pair = l->data; | |
2038 | |
2039 switch (pair->key) { | |
2040 case 4: | |
2041 who = pair->value; | |
2042 break; | |
2043 case 5: | |
2044 /* us */ | |
2045 break; | |
2046 case 230: | |
2047 /* the audible, in foo.bar.baz format */ | |
2048 break; | |
2049 case 231: | |
2050 /* the text of the audible */ | |
2051 msg = pair->value; | |
2052 break; | |
2053 case 232: | |
2054 /* weird number (md5 hash?), like 8ebab9094156135f5dcbaccbeee662a5c5fd1420 */ | |
2055 break; | |
2056 } | |
2057 | |
2058 l = l->next; | |
2059 } | |
2060 | |
2061 if (!who || !msg) | |
2062 return; | |
2063 if (!g_utf8_validate(msg, -1, NULL)) { | |
2064 gaim_debug_misc("yahoo", "Warning, nonutf8 audible, ignoring!\n"); | |
2065 return; | |
2066 } | |
2067 | |
2068 serv_got_im(gc, who, msg, 0, time(NULL)); | |
2069 } | |
2070 | |
5583 | 2071 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt) |
2681 | 2072 { |
6760 | 2073 switch (pkt->service) { |
2681 | 2074 case YAHOO_SERVICE_LOGON: |
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
2075 case YAHOO_SERVICE_LOGOFF: |
2681 | 2076 case YAHOO_SERVICE_ISAWAY: |
2737
f61c1f3a6afa
[gaim-migrate @ 2750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2724
diff
changeset
|
2077 case YAHOO_SERVICE_ISBACK: |
3019 | 2078 case YAHOO_SERVICE_GAMELOGON: |
2079 case YAHOO_SERVICE_GAMELOGOFF: | |
6686 | 2080 case YAHOO_SERVICE_CHATLOGON: |
2081 case YAHOO_SERVICE_CHATLOGOFF: | |
9409 | 2082 case YAHOO_SERVICE_YAHOO6_STATUS_UPDATE: |
2681 | 2083 yahoo_process_status(gc, pkt); |
2084 break; | |
3019 | 2085 case YAHOO_SERVICE_NOTIFY: |
2086 yahoo_process_notify(gc, pkt); | |
2993 | 2087 break; |
2681 | 2088 case YAHOO_SERVICE_MESSAGE: |
2786
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
2089 case YAHOO_SERVICE_GAMEMSG: |
5939 | 2090 case YAHOO_SERVICE_CHATMSG: |
2681 | 2091 yahoo_process_message(gc, pkt); |
2092 break; | |
7865 | 2093 case YAHOO_SERVICE_SYSMESSAGE: |
2094 yahoo_process_sysmessage(gc, pkt); | |
2095 break; | |
2681 | 2096 case YAHOO_SERVICE_NEWMAIL: |
2097 yahoo_process_mail(gc, pkt); | |
2098 break; | |
2099 case YAHOO_SERVICE_NEWCONTACT: | |
2100 yahoo_process_contact(gc, pkt); | |
2101 break; | |
6784 | 2102 case YAHOO_SERVICE_AUTHRESP: |
2103 yahoo_process_authresp(gc, pkt); | |
2104 break; | |
2681 | 2105 case YAHOO_SERVICE_LIST: |
2106 yahoo_process_list(gc, pkt); | |
2107 break; | |
3147 | 2108 case YAHOO_SERVICE_AUTH: |
2109 yahoo_process_auth(gc, pkt); | |
2110 break; | |
6840 | 2111 case YAHOO_SERVICE_ADDBUDDY: |
2112 yahoo_process_addbuddy(gc, pkt); | |
2113 break; | |
6760 | 2114 case YAHOO_SERVICE_IGNORECONTACT: |
2115 yahoo_process_ignore(gc, pkt); | |
2116 break; | |
6729 | 2117 case YAHOO_SERVICE_CONFINVITE: |
2118 case YAHOO_SERVICE_CONFADDINVITE: | |
2119 yahoo_process_conference_invite(gc, pkt); | |
2120 break; | |
2121 case YAHOO_SERVICE_CONFDECLINE: | |
2122 yahoo_process_conference_decline(gc, pkt); | |
2123 break; | |
2124 case YAHOO_SERVICE_CONFLOGON: | |
2125 yahoo_process_conference_logon(gc, pkt); | |
2126 break; | |
2127 case YAHOO_SERVICE_CONFLOGOFF: | |
2128 yahoo_process_conference_logoff(gc, pkt); | |
2129 break; | |
2130 case YAHOO_SERVICE_CONFMSG: | |
2131 yahoo_process_conference_message(gc, pkt); | |
2132 break; | |
2133 case YAHOO_SERVICE_CHATONLINE: | |
2134 yahoo_process_chat_online(gc, pkt); | |
2135 break; | |
2136 case YAHOO_SERVICE_CHATLOGOUT: | |
2137 yahoo_process_chat_logout(gc, pkt); | |
2138 break; | |
2139 case YAHOO_SERVICE_CHATGOTO: | |
2140 yahoo_process_chat_goto(gc, pkt); | |
2141 break; | |
2142 case YAHOO_SERVICE_CHATJOIN: | |
2143 yahoo_process_chat_join(gc, pkt); | |
2144 break; | |
2145 case YAHOO_SERVICE_CHATLEAVE: /* XXX is this right? */ | |
2146 case YAHOO_SERVICE_CHATEXIT: | |
2147 yahoo_process_chat_exit(gc, pkt); | |
2148 break; | |
2149 case YAHOO_SERVICE_CHATINVITE: /* XXX never seen this one, might not do it right */ | |
2150 case YAHOO_SERVICE_CHATADDINVITE: | |
2151 yahoo_process_chat_addinvite(gc, pkt); | |
2152 break; | |
2153 case YAHOO_SERVICE_COMMENT: | |
2154 yahoo_process_chat_message(gc, pkt); | |
2155 break; | |
7651 | 2156 case YAHOO_SERVICE_P2PFILEXFER: |
2157 case YAHOO_SERVICE_FILETRANSFER: | |
2158 yahoo_process_filetransfer(gc, pkt); | |
2159 break; | |
9062 | 2160 case YAHOO_SERVICE_PEEPTOPEER: |
2161 yahoo_process_p2p(gc, pkt); | |
2162 break; | |
9284 | 2163 case YAHOO_SERVICE_PICTURE: |
2164 yahoo_process_picture(gc, pkt); | |
2165 break; | |
9292 | 2166 case YAHOO_SERVICE_PICTURE_UPDATE: |
2167 yahoo_process_picture_update(gc, pkt); | |
2168 break; | |
2169 case YAHOO_SERVICE_PICTURE_CHECKSUM: | |
2170 yahoo_process_picture_checksum(gc, pkt); | |
2171 break; | |
9306 | 2172 case YAHOO_SERVICE_PICTURE_UPLOAD: |
2173 yahoo_process_picture_upload(gc, pkt); | |
2174 break; | |
9604 | 2175 case YAHOO_SERVICE_AUDIBLE: |
2176 yahoo_process_audible(gc, pkt); | |
2681 | 2177 default: |
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
2178 gaim_debug(GAIM_DEBUG_ERROR, "yahoo", |
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
2179 "Unhandled service 0x%02x\n", pkt->service); |
2681 | 2180 break; |
2181 } | |
2182 } | |
2183 | |
2184 static void yahoo_pending(gpointer data, gint source, GaimInputCondition cond) | |
2185 { | |
5583 | 2186 GaimConnection *gc = data; |
2681 | 2187 struct yahoo_data *yd = gc->proto_data; |
2188 char buf[1024]; | |
2189 int len; | |
2190 | |
2191 len = read(yd->fd, buf, sizeof(buf)); | |
2192 | |
2193 if (len <= 0) { | |
6321 | 2194 gaim_connection_error(gc, _("Unable to read")); |
2681 | 2195 return; |
2196 } | |
2197 | |
2198 yd->rxqueue = g_realloc(yd->rxqueue, len + yd->rxlen); | |
2199 memcpy(yd->rxqueue + yd->rxlen, buf, len); | |
2200 yd->rxlen += len; | |
2201 | |
2202 while (1) { | |
2203 struct yahoo_packet *pkt; | |
2204 int pos = 0; | |
2205 int pktlen; | |
2206 | |
2207 if (yd->rxlen < YAHOO_PACKET_HDRLEN) | |
2208 return; | |
2209 | |
2210 pos += 4; /* YMSG */ | |
2211 pos += 2; | |
2212 pos += 2; | |
2213 | |
2214 pktlen = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
2215 gaim_debug(GAIM_DEBUG_MISC, "yahoo", |
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
2216 "%d bytes to read, rxlen is %d\n", pktlen, yd->rxlen); |
2681 | 2217 |
2218 if (yd->rxlen < (YAHOO_PACKET_HDRLEN + pktlen)) | |
2219 return; | |
2220 | |
2221 yahoo_packet_dump(yd->rxqueue, YAHOO_PACKET_HDRLEN + pktlen); | |
2222 | |
2223 pkt = yahoo_packet_new(0, 0, 0); | |
2224 | |
2225 pkt->service = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
3021 | 2226 pkt->status = yahoo_get32(yd->rxqueue + pos); pos += 4; |
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
2227 gaim_debug(GAIM_DEBUG_MISC, "yahoo", |
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
2228 "Yahoo Service: 0x%02x Status: %d\n", |
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
2229 pkt->service, pkt->status); |
2681 | 2230 pkt->id = yahoo_get32(yd->rxqueue + pos); pos += 4; |
2231 | |
2232 yahoo_packet_read(pkt, yd->rxqueue + pos, pktlen); | |
2233 | |
2234 yd->rxlen -= YAHOO_PACKET_HDRLEN + pktlen; | |
2235 if (yd->rxlen) { | |
2236 char *tmp = g_memdup(yd->rxqueue + YAHOO_PACKET_HDRLEN + pktlen, yd->rxlen); | |
2237 g_free(yd->rxqueue); | |
2238 yd->rxqueue = tmp; | |
2239 } else { | |
2240 g_free(yd->rxqueue); | |
2241 yd->rxqueue = NULL; | |
2242 } | |
2243 | |
2244 yahoo_packet_process(gc, pkt); | |
2245 | |
2246 yahoo_packet_free(pkt); | |
2247 } | |
2248 } | |
2249 | |
2250 static void yahoo_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
2251 { | |
5583 | 2252 GaimConnection *gc = data; |
2681 | 2253 struct yahoo_data *yd; |
2254 struct yahoo_packet *pkt; | |
2255 | |
5590
011a0a975060
[gaim-migrate @ 5994]
Christian Hammond <chipx86@chipx86.com>
parents:
5583
diff
changeset
|
2256 if (!g_list_find(gaim_connections_get_all(), gc)) { |
2681 | 2257 close(source); |
2258 return; | |
2259 } | |
2260 | |
2261 if (source < 0) { | |
8057 | 2262 gaim_connection_error(gc, _("Unable to connect.")); |
2681 | 2263 return; |
2264 } | |
2265 | |
2266 yd = gc->proto_data; | |
2267 yd->fd = source; | |
2268 | |
3147 | 2269 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YAHOO_STATUS_AVAILABLE, 0); |
2681 | 2270 |
7261 | 2271 yahoo_packet_hash(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); |
2681 | 2272 yahoo_send_packet(yd, pkt); |
2273 | |
2274 yahoo_packet_free(pkt); | |
2275 | |
2276 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | |
2277 } | |
9370 | 2278 |
7134 | 2279 static void yahoo_got_web_connected(gpointer data, gint source, GaimInputCondition cond) |
2280 { | |
2281 GaimConnection *gc = data; | |
2282 struct yahoo_data *yd; | |
2283 struct yahoo_packet *pkt; | |
2284 | |
2285 if (!g_list_find(gaim_connections_get_all(), gc)) { | |
2286 close(source); | |
2287 return; | |
2288 } | |
2289 | |
2290 if (source < 0) { | |
8057 | 2291 gaim_connection_error(gc, _("Unable to connect.")); |
7134 | 2292 return; |
2293 } | |
2294 | |
2295 yd = gc->proto_data; | |
2296 yd->fd = source; | |
2297 | |
2298 pkt = yahoo_packet_new(YAHOO_SERVICE_WEBLOGIN, YAHOO_STATUS_WEBLOGIN, 0); | |
2299 | |
7261 | 2300 yahoo_packet_hash(pkt, 0, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); |
2301 yahoo_packet_hash(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); | |
7134 | 2302 yahoo_packet_hash(pkt, 6, yd->auth); |
2303 yahoo_send_packet(yd, pkt); | |
2304 | |
2305 yahoo_packet_free(pkt); | |
2306 g_free(yd->auth); | |
2307 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | |
2308 } | |
2309 | |
2310 static void yahoo_web_pending(gpointer data, gint source, GaimInputCondition cond) | |
2311 { | |
2312 GaimConnection *gc = data; | |
2313 GaimAccount *account = gaim_connection_get_account(gc); | |
2314 struct yahoo_data *yd = gc->proto_data; | |
8243 | 2315 char buf[2048], *i = buf; |
8161 | 2316 int len; |
2317 GString *s; | |
7134 | 2318 |
8118 | 2319 len = read(source, buf, sizeof(buf)-1); |
8216
dcace041cfb8
[gaim-migrate @ 8939]
Christian Hammond <chipx86@chipx86.com>
parents:
8212
diff
changeset
|
2320 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
|
2321 strncmp(buf, "HTTP/1.1 302", strlen("HTTP/1.1 302")))) { |
7134 | 2322 gaim_connection_error(gc, _("Unable to read")); |
2323 return; | |
2324 } | |
8161 | 2325 |
2326 s = g_string_sized_new(len); | |
8118 | 2327 buf[sizeof(buf)-1] = '\0'; |
8161 | 2328 |
2329 while ((i = strstr(i, "Set-Cookie: "))) { | |
2330 i += strlen("Set-Cookie: "); | |
8243 | 2331 for (;*i != ';' && *i != '\0'; i++) |
8161 | 2332 g_string_append_c(s, *i); |
2333 | |
2334 g_string_append(s, "; "); | |
7134 | 2335 } |
8161 | 2336 |
2337 yd->auth = g_string_free(s, FALSE); | |
7134 | 2338 gaim_input_remove(gc->inpa); |
2339 close(source); | |
2340 /* Now we have our cookies to login with. I'll go get the milk. */ | |
8045 | 2341 if (gaim_proxy_connect(account, "wcs2.msg.dcn.yahoo.com", |
7134 | 2342 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT), |
2343 yahoo_got_web_connected, gc) != 0) { | |
2344 gaim_connection_error(gc, _("Connection problem")); | |
2345 return; | |
2346 } | |
2347 } | |
2348 | |
2349 static void yahoo_got_cookies(gpointer data, gint source, GaimInputCondition cond) | |
2350 { | |
2351 GaimConnection *gc = data; | |
2352 struct yahoo_data *yd = gc->proto_data; | |
2353 if (source < 0) { | |
8057 | 2354 gaim_connection_error(gc, _("Unable to connect.")); |
7134 | 2355 return; |
2356 } | |
2357 write(source, yd->auth, strlen(yd->auth)); | |
2358 g_free(yd->auth); | |
2359 gc->inpa = gaim_input_add(source, GAIM_INPUT_READ, yahoo_web_pending, gc); | |
2360 } | |
2361 | |
2362 static void yahoo_login_page_hash_iter(const char *key, const char *val, GString *url) | |
2363 { | |
2364 if (!strcmp(key, "passwd")) | |
2365 return; | |
2366 url = g_string_append_c(url, '&'); | |
2367 url = g_string_append(url, key); | |
2368 url = g_string_append_c(url, '='); | |
2369 if (!strcmp(key, ".save") || !strcmp(key, ".js")) | |
2370 url = g_string_append_c(url, '1'); | |
2371 else if (!strcmp(key, ".challenge")) | |
2372 url = g_string_append(url, val); | |
2373 else | |
2374 url = g_string_append(url, gaim_url_encode(val)); | |
2375 } | |
2376 | |
2377 static GHashTable *yahoo_login_page_hash(const char *buf, size_t len) | |
2378 { | |
2379 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
|
2380 const char *c = buf; |
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2381 char *d; |
7134 | 2382 char name[64], value[64]; |
8118 | 2383 int count = sizeof(name)-1; |
7134 | 2384 while ((c < (buf + len)) && (c = strstr(c, "<input "))) { |
2385 c = strstr(c, "name=\"") + strlen("name=\""); | |
8118 | 2386 for (d = name; *c!='"' && count; c++, d++, count--) |
7134 | 2387 *d = *c; |
2388 *d = '\0'; | |
8118 | 2389 count = sizeof(value)-1; |
7134 | 2390 d = strstr(c, "value=\"") + strlen("value=\""); |
2391 if (strchr(c, '>') < d) | |
2392 break; | |
8118 | 2393 for (c = d, d = value; *c!='"' && count; c++, d++, count--) |
7134 | 2394 *d = *c; |
2395 *d = '\0'; | |
2396 g_hash_table_insert(hash, g_strdup(name), g_strdup(value)); | |
2397 } | |
2398 return hash; | |
2399 } | |
2400 | |
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2401 static void yahoo_login_page_cb(void *user_data, const char *buf, size_t len) |
7134 | 2402 { |
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2403 GaimConnection *gc = (GaimConnection *)user_data; |
7134 | 2404 GaimAccount *account = gaim_connection_get_account(gc); |
2405 struct yahoo_data *yd = gc->proto_data; | |
2406 const char *sn = gaim_account_get_username(account); | |
2407 const char *pass = gaim_account_get_password(account); | |
2408 GHashTable *hash = yahoo_login_page_hash(buf, len); | |
2409 GString *url = g_string_new("GET /config/login?login="); | |
2410 char md5[33], *hashp = md5, *chal; | |
2411 int i; | |
2412 md5_byte_t result[16]; | |
2413 md5_state_t ctx; | |
7191
4bd3892cded3
[gaim-migrate @ 7760]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7161
diff
changeset
|
2414 |
4bd3892cded3
[gaim-migrate @ 7760]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7161
diff
changeset
|
2415 url = g_string_append(url, sn); |
4bd3892cded3
[gaim-migrate @ 7760]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7161
diff
changeset
|
2416 url = g_string_append(url, "&passwd="); |
4bd3892cded3
[gaim-migrate @ 7760]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7161
diff
changeset
|
2417 |
7134 | 2418 md5_init(&ctx); |
2419 md5_append(&ctx, pass, strlen(pass)); | |
2420 md5_finish(&ctx, result); | |
2421 for (i = 0; i < 16; ++i) { | |
2422 g_snprintf(hashp, 3, "%02x", result[i]); | |
2423 hashp += 2; | |
2424 } | |
2425 chal = g_strconcat(md5, g_hash_table_lookup(hash, ".challenge"), NULL); | |
2426 md5_init(&ctx); | |
2427 md5_append(&ctx, chal, strlen(chal)); | |
2428 md5_finish(&ctx, result); | |
2429 hashp = md5; | |
2430 for (i = 0; i < 16; ++i) { | |
2431 g_snprintf(hashp, 3, "%02x", result[i]); | |
2432 hashp += 2; | |
2433 } | |
2434 /* | |
2435 md5_init(&ctx); | |
2436 md5_append(&ctx, md5, strlen(md5)); | |
2437 md5_finish(&ctx, result); | |
2438 hashp = md5; | |
2439 for (i = 0; i < 16; ++i) { | |
2440 g_snprintf(hashp, 3, "%02x", result[i]); | |
2441 hashp += 2; | |
2442 } | |
2443 */ | |
2444 g_free(chal); | |
2445 | |
2446 url = g_string_append(url, md5); | |
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2447 g_hash_table_foreach(hash, (GHFunc)yahoo_login_page_hash_iter, url); |
7134 | 2448 |
2449 url = g_string_append(url, "&.hash=1&.md5=1 HTTP/1.1\r\n" | |
2450 "Host: login.yahoo.com\r\n\r\n"); | |
2451 g_hash_table_destroy(hash); | |
2452 yd->auth = g_string_free(url, FALSE); | |
2453 if (gaim_proxy_connect(account, "login.yahoo.com", 80, yahoo_got_cookies, gc) != 0) { | |
2454 gaim_connection_error(gc, _("Connection problem")); | |
2455 return; | |
2456 } | |
2457 } | |
2458 | |
7883 | 2459 static void yahoo_server_check(GaimAccount *account) |
2460 { | |
2461 const char *server; | |
2462 | |
2463 server = gaim_account_get_string(account, "server", YAHOO_PAGER_HOST); | |
2464 | |
2465 if (strcmp(server, "scs.yahoo.com") == 0) | |
2466 gaim_account_set_string(account, "server", YAHOO_PAGER_HOST); | |
2467 } | |
9306 | 2468 |
2469 static void yahoo_picture_check(GaimAccount *account) | |
2470 { | |
2471 GaimConnection *gc = gaim_account_get_connection(account); | |
2472 const char *buddyicon; | |
2473 | |
2474 buddyicon = gaim_account_get_buddy_icon(account); | |
2475 yahoo_set_buddy_icon(gc, buddyicon); | |
2476 } | |
2477 | |
7883 | 2478 |
5583 | 2479 static void yahoo_login(GaimAccount *account) { |
2480 GaimConnection *gc = gaim_account_get_connection(account); | |
2681 | 2481 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); |
2482 | |
9041 | 2483 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_URLDESC; |
6629 | 2484 |
5583 | 2485 gaim_connection_update_progress(gc, _("Connecting"), 1, 2); |
2681 | 2486 |
8235 | 2487 gaim_connection_set_display_name(gc, gaim_account_get_username(account)); |
2488 | |
2681 | 2489 yd->fd = -1; |
6784 | 2490 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free); |
6729 | 2491 yd->confs = NULL; |
2492 yd->conf_id = 2; | |
2681 | 2493 |
7883 | 2494 yahoo_server_check(account); |
9306 | 2495 yahoo_picture_check(account); |
7883 | 2496 |
9164 | 2497 if (gaim_account_get_bool(account, "yahoojp", FALSE)) { |
2498 yd->jp = TRUE; | |
2499 if (gaim_proxy_connect(account, | |
2500 gaim_account_get_string(account, "serverjp", YAHOOJP_PAGER_HOST), | |
2501 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT), | |
2502 yahoo_got_connected, gc) != 0) | |
2503 { | |
2504 gaim_connection_error(gc, _("Connection problem")); | |
2505 return; | |
2506 } | |
2507 } else { | |
2508 yd->jp = FALSE; | |
2509 if (gaim_proxy_connect(account, | |
2510 gaim_account_get_string(account, "server", YAHOO_PAGER_HOST), | |
2511 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT), | |
2512 yahoo_got_connected, gc) != 0) | |
2513 { | |
2514 gaim_connection_error(gc, _("Connection problem")); | |
2515 return; | |
2516 } | |
2681 | 2517 } |
9370 | 2518 |
2681 | 2519 |
2520 } | |
2521 | |
5583 | 2522 static void yahoo_close(GaimConnection *gc) { |
2681 | 2523 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
9782 | 2524 GSList *l; |
2525 | |
2526 for (l = yd->confs; l; l = l->next) { | |
2527 GaimConversation *conv = l->data; | |
2528 | |
2529 yahoo_conf_leave(yd, gaim_conversation_get_name(conv), | |
2530 gaim_connection_get_display_name(gc), | |
2531 gaim_conv_chat_get_users(GAIM_CONV_CHAT(conv))); | |
2532 } | |
2533 g_slist_free(yd->confs); | |
6729 | 2534 |
6784 | 2535 g_hash_table_destroy(yd->friends); |
2536 if (yd->chat_name) | |
2537 g_free(yd->chat_name); | |
6729 | 2538 |
7651 | 2539 if (yd->cookie_y) |
2540 g_free(yd->cookie_y); | |
2541 if (yd->cookie_t) | |
2542 g_free(yd->cookie_t); | |
2543 | |
2681 | 2544 if (yd->fd >= 0) |
2545 close(yd->fd); | |
3720
34c95669952f
[gaim-migrate @ 3853]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3642
diff
changeset
|
2546 |
2681 | 2547 if (yd->rxqueue) |
2548 g_free(yd->rxqueue); | |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2686
diff
changeset
|
2549 yd->rxlen = 0; |
9306 | 2550 if (yd->picture_url) |
2551 g_free(yd->picture_url); | |
2552 if (yd->picture_upload_todo) | |
2553 yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo); | |
9376 | 2554 if (yd->ycht) |
2555 ycht_connection_close(yd->ycht); | |
2681 | 2556 if (gc->inpa) |
2557 gaim_input_remove(gc->inpa); | |
2558 g_free(yd); | |
2559 } | |
2560 | |
6695 | 2561 static const char *yahoo_list_icon(GaimAccount *a, GaimBuddy *b) |
2681 | 2562 { |
4687 | 2563 return "yahoo"; |
2681 | 2564 } |
4916 | 2565 |
9972 | 2566 static void yahoo_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) |
4916 | 2567 { |
2568 int i = 0; | |
2569 char *emblems[4] = {NULL,NULL,NULL,NULL}; | |
6784 | 2570 GaimAccount *account; |
2571 GaimConnection *gc; | |
2572 struct yahoo_data *yd; | |
9278 | 2573 YahooFriend *f; |
6784 | 2574 |
2575 if (!b || !(account = b->account) || !(gc = gaim_account_get_connection(account)) || | |
2576 !(yd = gc->proto_data)) | |
2577 return; | |
2578 | |
9279 | 2579 f = yahoo_friend_find(gc, b->name); |
6784 | 2580 if (!f) { |
2581 *se = "notauthorized"; | |
2582 return; | |
2583 } | |
2584 | |
5068 | 2585 if (b->present == GAIM_BUDDY_OFFLINE) { |
4916 | 2586 *se = "offline"; |
2587 return; | |
2588 } else { | |
6784 | 2589 if (f->away) |
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
2590 emblems[i++] = "away"; |
6784 | 2591 if (f->sms) |
2592 emblems[i++] = "wireless"; | |
9283 | 2593 if (yahoo_friend_get_game(f)) |
4916 | 2594 emblems[i++] = "game"; |
2595 } | |
2596 *se = emblems[0]; | |
2597 *sw = emblems[1]; | |
2598 *nw = emblems[2]; | |
2599 *ne = emblems[3]; | |
2600 } | |
2681 | 2601 |
2602 static char *yahoo_get_status_string(enum yahoo_status a) | |
2603 { | |
2604 switch (a) { | |
2605 case YAHOO_STATUS_BRB: | |
4596 | 2606 return _("Be Right Back"); |
2681 | 2607 case YAHOO_STATUS_BUSY: |
4596 | 2608 return _("Busy"); |
2681 | 2609 case YAHOO_STATUS_NOTATHOME: |
4596 | 2610 return _("Not At Home"); |
2681 | 2611 case YAHOO_STATUS_NOTATDESK: |
4596 | 2612 return _("Not At Desk"); |
2681 | 2613 case YAHOO_STATUS_NOTINOFFICE: |
4596 | 2614 return _("Not In Office"); |
2681 | 2615 case YAHOO_STATUS_ONPHONE: |
4606 | 2616 return _("On The Phone"); |
2681 | 2617 case YAHOO_STATUS_ONVACATION: |
4596 | 2618 return _("On Vacation"); |
2681 | 2619 case YAHOO_STATUS_OUTTOLUNCH: |
4596 | 2620 return _("Out To Lunch"); |
2681 | 2621 case YAHOO_STATUS_STEPPEDOUT: |
4596 | 2622 return _("Stepped Out"); |
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
2623 case YAHOO_STATUS_INVISIBLE: |
4596 | 2624 return _("Invisible"); |
4730 | 2625 case YAHOO_STATUS_IDLE: |
2626 return _("Idle"); | |
6784 | 2627 case YAHOO_STATUS_OFFLINE: |
2628 return _("Offline"); | |
2879
5fc5123b7098
[gaim-migrate @ 2892]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2878
diff
changeset
|
2629 default: |
4596 | 2630 return _("Online"); |
2681 | 2631 } |
2632 } | |
2633 | |
9030 | 2634 static void yahoo_initiate_conference(GaimBlistNode *node, gpointer data) { |
2635 | |
2636 GaimBuddy *buddy; | |
2637 GaimConnection *gc; | |
2638 | |
6729 | 2639 GHashTable *components; |
2640 struct yahoo_data *yd; | |
2641 int id; | |
2642 | |
9030 | 2643 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
2644 | |
2645 buddy = (GaimBuddy *) node; | |
2646 gc = gaim_account_get_connection(buddy->account); | |
6729 | 2647 yd = gc->proto_data; |
2648 id = yd->conf_id; | |
2649 | |
2650 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
2651 g_hash_table_replace(components, g_strdup("room"), | |
2652 g_strdup_printf("%s-%d", gaim_connection_get_display_name(gc), id)); | |
2653 g_hash_table_replace(components, g_strdup("topic"), g_strdup("Join my conference...")); | |
2654 g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference")); | |
2655 yahoo_c_join(gc, components); | |
2656 g_hash_table_destroy(components); | |
2657 | |
9030 | 2658 yahoo_c_invite(gc, id, "Join my conference...", buddy->name); |
6729 | 2659 } |
2660 | |
9030 | 2661 static void yahoo_game(GaimBlistNode *node, gpointer data) { |
2662 | |
2663 GaimBuddy *buddy; | |
2664 GaimConnection *gc; | |
2665 | |
2666 struct yahoo_data *yd; | |
9283 | 2667 const char *game; |
2668 char *game2; | |
3019 | 2669 char *t; |
2670 char url[256]; | |
9278 | 2671 YahooFriend *f; |
3019 | 2672 |
9030 | 2673 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
2674 | |
2675 buddy = (GaimBuddy *) node; | |
2676 gc = gaim_account_get_connection(buddy->account); | |
2677 yd = (struct yahoo_data *) gc->proto_data; | |
2678 | |
9279 | 2679 f = yahoo_friend_find(gc, buddy->name); |
6784 | 2680 if (!f) |
2681 return; | |
2682 | |
9283 | 2683 game = yahoo_friend_get_game(f); |
3019 | 2684 if (!game) |
2685 return; | |
6784 | 2686 |
9283 | 2687 t = game2 = g_strdup(strstr(game, "ante?room=")); |
2688 while (*t && *t != '\t') | |
3019 | 2689 t++; |
2690 *t = 0; | |
9283 | 2691 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
|
2692 gaim_notify_uri(gc, url); |
9283 | 2693 g_free(game2); |
3019 | 2694 } |
4722 | 2695 |
6695 | 2696 static char *yahoo_status_text(GaimBuddy *b) |
4722 | 2697 { |
9278 | 2698 YahooFriend *f = NULL; |
9283 | 2699 const char *msg; |
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
2700 |
9279 | 2701 f = yahoo_friend_find(b->account->gc, b->name); |
6784 | 2702 if (!f) |
2703 return g_strdup(_("Not on server list")); | |
2704 | |
2705 switch (f->status) { | |
2706 case YAHOO_STATUS_AVAILABLE: | |
2707 return NULL; | |
2708 case YAHOO_STATUS_IDLE: | |
2709 if (f->idle == -1) | |
2710 return g_strdup(yahoo_get_status_string(f->status)); | |
2711 return NULL; | |
2712 case YAHOO_STATUS_CUSTOM: | |
9283 | 2713 if (!(msg = yahoo_friend_get_status_message(f))) |
6784 | 2714 return NULL; |
9283 | 2715 return g_markup_escape_text(msg, strlen(msg)); |
9224 | 2716 |
6784 | 2717 default: |
2718 return g_strdup(yahoo_get_status_string(f->status)); | |
2719 } | |
4722 | 2720 } |
2721 | |
9220 | 2722 char *yahoo_tooltip_text(GaimBuddy *b) |
4724 | 2723 { |
9278 | 2724 YahooFriend *f; |
6784 | 2725 char *escaped, *status, *ret; |
2726 | |
9279 | 2727 f = yahoo_friend_find(b->account->gc, b->name); |
6784 | 2728 if (!f) |
8591 | 2729 status = g_strdup_printf("\n%s", _("Not on server list")); |
6784 | 2730 else |
2731 switch (f->status) { | |
2732 case YAHOO_STATUS_IDLE: | |
2733 if (f->idle == -1) { | |
2734 status = g_strdup(yahoo_get_status_string(f->status)); | |
2735 break; | |
2736 } | |
2737 return NULL; | |
2738 case YAHOO_STATUS_CUSTOM: | |
9283 | 2739 if (!yahoo_friend_get_status_message(f)) |
6784 | 2740 return NULL; |
9283 | 2741 status = g_strdup(yahoo_friend_get_status_message(f)); |
6784 | 2742 break; |
2743 default: | |
2744 status = g_strdup(yahoo_get_status_string(f->status)); | |
2745 break; | |
4745 | 2746 } |
6784 | 2747 |
2748 escaped = g_markup_escape_text(status, strlen(status)); | |
8591 | 2749 ret = g_strdup_printf(_("\n<b>%s:</b> %s"), _("Status"), escaped); |
6784 | 2750 g_free(status); |
2751 g_free(escaped); | |
2752 | |
2753 return ret; | |
4729 | 2754 } |
2755 | |
9030 | 2756 static void yahoo_addbuddyfrommenu_cb(GaimBlistNode *node, gpointer data) |
2757 { | |
2758 GaimBuddy *buddy; | |
2759 GaimConnection *gc; | |
2760 | |
2761 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
2762 | |
2763 buddy = (GaimBuddy *) node; | |
2764 gc = gaim_account_get_connection(buddy->account); | |
2765 | |
9285 | 2766 yahoo_add_buddy(gc, buddy, NULL); |
9030 | 2767 } |
2768 | |
2769 | |
2770 static void yahoo_chat_goto_menu(GaimBlistNode *node, gpointer data) | |
6796 | 2771 { |
9030 | 2772 GaimBuddy *buddy; |
2773 GaimConnection *gc; | |
2774 | |
2775 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
2776 | |
2777 buddy = (GaimBuddy *) node; | |
2778 gc = gaim_account_get_connection(buddy->account); | |
2779 | |
2780 yahoo_chat_goto(gc, buddy->name); | |
6796 | 2781 } |
2782 | |
9030 | 2783 |
2784 static GList *yahoo_buddy_menu(GaimBuddy *buddy) | |
2681 | 2785 { |
2786 GList *m = NULL; | |
9030 | 2787 GaimBlistNodeAction *act; |
2788 | |
2789 GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
9370 | 2790 struct yahoo_data *yd = gc->proto_data; |
3019 | 2791 static char buf2[1024]; |
9278 | 2792 YahooFriend *f; |
6784 | 2793 |
9279 | 2794 f = yahoo_friend_find(gc, buddy->name); |
6784 | 2795 |
9370 | 2796 if (!f && !yd->wm) { |
9030 | 2797 act = gaim_blist_node_action_new(_("Add Buddy"), |
2798 yahoo_addbuddyfrommenu_cb, NULL); | |
2799 m = g_list_append(m, act); | |
6784 | 2800 |
2801 return m; | |
9030 | 2802 |
2803 } else if (f->status == YAHOO_STATUS_OFFLINE) { | |
6784 | 2804 return NULL; |
9030 | 2805 } |
2806 | |
9370 | 2807 if (!yd->wm) { |
2808 act = gaim_blist_node_action_new(_("Join in Chat"), | |
2809 yahoo_chat_goto_menu, NULL); | |
2810 m = g_list_append(m, act); | |
2811 } | |
9030 | 2812 |
2813 act = gaim_blist_node_action_new(_("Initiate Conference"), | |
2814 yahoo_initiate_conference, NULL); | |
2815 m = g_list_append(m, act); | |
6729 | 2816 |
9283 | 2817 if (yahoo_friend_get_game(f)) { |
2818 const char *game = yahoo_friend_get_game(f); | |
3019 | 2819 char *room; |
6784 | 2820 char *t; |
2821 | |
2822 if (!(room = strstr(game, "&follow="))) /* skip ahead to the url */ | |
2823 return m; | |
2824 while (*room && *room != '\t') /* skip to the tab */ | |
2825 room++; | |
2826 t = room++; /* room as now at the name */ | |
2827 while (*t != '\n') | |
2828 t++; /* replace the \n with a space */ | |
2829 *t = ' '; | |
2830 g_snprintf(buf2, sizeof buf2, "%s", room); | |
9030 | 2831 |
2832 act = gaim_blist_node_action_new(buf2, yahoo_game, NULL); | |
2833 m = g_list_append(m, act); | |
3019 | 2834 } |
6729 | 2835 |
2681 | 2836 return m; |
2837 } | |
2838 | |
9030 | 2839 |
2840 static GList *yahoo_blist_node_menu(GaimBlistNode *node) | |
2841 { | |
2842 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
2843 return yahoo_buddy_menu((GaimBuddy *) node); | |
2844 } else { | |
2845 return NULL; | |
2846 } | |
2847 } | |
2848 | |
2849 | |
5583 | 2850 static void yahoo_act_id(GaimConnection *gc, const char *entry) |
2681 | 2851 { |
2852 struct yahoo_data *yd = gc->proto_data; | |
2853 | |
2854 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0); | |
2855 yahoo_packet_hash(pkt, 3, entry); | |
2856 yahoo_send_packet(yd, pkt); | |
2857 yahoo_packet_free(pkt); | |
2858 | |
5583 | 2859 gaim_connection_set_display_name(gc, entry); |
2681 | 2860 } |
2861 | |
9015 | 2862 static void yahoo_show_act_id(GaimPluginAction *action) |
2681 | 2863 { |
9015 | 2864 GaimConnection *gc = (GaimConnection *) action->context; |
5493
3e8487580024
[gaim-migrate @ 5889]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
2865 gaim_request_input(gc, NULL, _("Active which ID?"), NULL, |
8697 | 2866 gaim_connection_get_display_name(gc), FALSE, FALSE, NULL, |
5493
3e8487580024
[gaim-migrate @ 5889]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
2867 _("OK"), G_CALLBACK(yahoo_act_id), |
3e8487580024
[gaim-migrate @ 5889]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
2868 _("Cancel"), NULL, gc); |
2681 | 2869 } |
2870 | |
9015 | 2871 static void yahoo_show_chat_goto(GaimPluginAction *action) |
7878 | 2872 { |
9015 | 2873 GaimConnection *gc = (GaimConnection *) action->context; |
7878 | 2874 gaim_request_input(gc, NULL, _("Join who in chat?"), NULL, |
8697 | 2875 "", FALSE, FALSE, NULL, |
7878 | 2876 _("OK"), G_CALLBACK(yahoo_chat_goto), |
2877 _("Cancel"), NULL, gc); | |
2878 } | |
2879 | |
9015 | 2880 static GList *yahoo_actions(GaimPlugin *plugin, gpointer context) { |
2681 | 2881 GList *m = NULL; |
9015 | 2882 GaimPluginAction *act; |
2883 | |
2884 act = gaim_plugin_action_new(_("Activate ID..."), | |
2885 yahoo_show_act_id); | |
2886 m = g_list_append(m, act); | |
2887 | |
2888 act = gaim_plugin_action_new(_("Join user in chat..."), | |
2889 yahoo_show_chat_goto); | |
2890 m = g_list_append(m, act); | |
7878 | 2891 |
2681 | 2892 return m; |
2893 } | |
2894 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7112
diff
changeset
|
2895 static int yahoo_send_im(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags) |
2681 | 2896 { |
2897 struct yahoo_data *yd = gc->proto_data; | |
2898 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0); | |
6629 | 2899 char *msg = yahoo_html_to_codes(what); |
7827 | 2900 char *msg2; |
2901 gboolean utf8 = TRUE; | |
9828 | 2902 int ret = 1; |
7827 | 2903 |
2904 msg2 = yahoo_string_encode(gc, msg, &utf8); | |
2681 | 2905 |
5583 | 2906 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
2681 | 2907 yahoo_packet_hash(pkt, 5, who); |
7827 | 2908 if (utf8) |
2909 yahoo_packet_hash(pkt, 97, "1"); | |
2910 yahoo_packet_hash(pkt, 14, msg2); | |
2911 | |
9280 | 2912 yahoo_packet_hash(pkt, 63, ";0"); /* IMvironment */ |
2913 yahoo_packet_hash(pkt, 64, "0"); /* no idea */ | |
9062 | 2914 yahoo_packet_hash(pkt, 1002, "1"); /* no idea, Yahoo 6 or later only it seems */ |
9306 | 2915 if (!yd->picture_url) |
2916 yahoo_packet_hash(pkt, 206, "0"); /* 0 = no picture, 2 = picture, maybe 1 = avatar? */ | |
2917 else | |
2918 yahoo_packet_hash(pkt, 206, "2"); | |
2681 | 2919 |
9828 | 2920 /* We may need to not send any packets over 2000 bytes, but I'm not sure yet. */ |
2921 if ((YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt)) <= 2000) | |
2922 yahoo_send_packet(yd, pkt); | |
2923 else | |
2924 ret = -E2BIG; | |
2681 | 2925 |
2926 yahoo_packet_free(pkt); | |
6629 | 2927 |
2928 g_free(msg); | |
7827 | 2929 g_free(msg2); |
6629 | 2930 |
9828 | 2931 return ret; |
2681 | 2932 } |
2933 | |
6059 | 2934 int yahoo_send_typing(GaimConnection *gc, const char *who, int typ) |
2993 | 2935 { |
2936 struct yahoo_data *yd = gc->proto_data; | |
3019 | 2937 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0); |
2993 | 2938 yahoo_packet_hash(pkt, 49, "TYPING"); |
5583 | 2939 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
2993 | 2940 yahoo_packet_hash(pkt, 14, " "); |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
2941 yahoo_packet_hash(pkt, 13, typ == GAIM_TYPING ? "1" : "0"); |
2993 | 2942 yahoo_packet_hash(pkt, 5, who); |
2943 yahoo_packet_hash(pkt, 1002, "1"); | |
2944 | |
2945 yahoo_send_packet(yd, pkt); | |
2946 | |
2947 yahoo_packet_free(pkt); | |
2948 | |
3001 | 2949 return 0; |
2993 | 2950 } |
2951 | |
9984 | 2952 static void yahoo_set_status(GaimAccount *account, GaimStatus *status) |
2681 | 2953 { |
9984 | 2954 GaimConnection *gc = gaim_account_get_connection(account); |
2681 | 2955 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
2956 struct yahoo_packet *pkt; | |
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
2957 int service; |
2681 | 2958 char s[4]; |
9984 | 2959 const char *id; |
7827 | 2960 char *conv_msg = NULL; |
8503 | 2961 char *conv_msg2 = NULL; |
9984 | 2962 gboolean away = FALSE; /* only for YAHOO_STATUS_CUSTOM */ |
2963 | |
2964 id = gaim_status_get_id(status); | |
2965 | |
2966 if (!strcmp(id, "available")) { | |
2967 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
2968 } else if (!strcmp(id, "berightback")) { | |
2969 yd->current_status = YAHOO_STATUS_BRB; | |
2970 } else if (!strcmp(id, "busy")) { | |
2971 yd->current_status = YAHOO_STATUS_BUSY; | |
2972 } else if (!strcmp(id, "notathome")) { | |
2973 yd->current_status = YAHOO_STATUS_NOTATHOME; | |
2974 } else if (!strcmp(id,"notatdesk")) { | |
2975 yd->current_status = YAHOO_STATUS_NOTATDESK; | |
2976 } else if (!strcmp(id, "notinoffice")) { | |
2977 yd->current_status = YAHOO_STATUS_NOTINOFFICE; | |
2978 } else if (!strcmp(id, "onthephone")) { | |
2979 yd->current_status = YAHOO_STATUS_ONPHONE; | |
2980 } else if (!strcmp(id, "onvacation")) { | |
2981 yd->current_status = YAHOO_STATUS_ONVACATION; | |
2982 } else if (!strcmp(id, "outtolunch")) { | |
2983 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; | |
2984 } else if (!strcmp(id, "steppedout")) { | |
2985 yd->current_status = YAHOO_STATUS_STEPPEDOUT; | |
2986 } else if (!strcmp(id, "invisible")) { | |
2987 yd->current_status = YAHOO_STATUS_INVISIBLE; | |
2988 } else if (!strcmp(id, "away")) { | |
2681 | 2989 yd->current_status = YAHOO_STATUS_CUSTOM; |
9984 | 2990 away = TRUE; |
2991 } else if (!strcmp(id, "avaiablewm")) { | |
2992 yd->current_status = YAHOO_STATUS_CUSTOM; | |
2993 away = FALSE; | |
2994 } else if (gc->is_idle) { /* i think this is broken */ | |
2681 | 2995 yd->current_status = YAHOO_STATUS_IDLE; |
2996 } else { | |
2997 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
2998 } | |
2999 | |
9984 | 3000 if (yd->current_status == YAHOO_STATUS_AVAILABLE || |
3001 ((yd->current_status == YAHOO_STATUS_CUSTOM) && !away)) | |
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
3002 service = YAHOO_SERVICE_ISBACK; |
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
3003 else |
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
3004 service = YAHOO_SERVICE_ISAWAY; |
6847 | 3005 |
3006 pkt = yahoo_packet_new(service, YAHOO_STATUS_AVAILABLE, 0); | |
2681 | 3007 g_snprintf(s, sizeof(s), "%d", yd->current_status); |
3008 yahoo_packet_hash(pkt, 10, s); | |
6847 | 3009 |
9984 | 3010 if (yd->current_status == YAHOO_STATUS_CUSTOM) { |
3011 const char *msg = gaim_status_get_attr_string(status, "message"); | |
3012 conv_msg = yahoo_string_encode(gc, msg, NULL); | |
3013 conv_msg2 = gaim_markup_strip_html(conv_msg); | |
8503 | 3014 yahoo_packet_hash(pkt, 19, conv_msg2); |
9984 | 3015 |
6784 | 3016 if (gc->is_idle) |
3017 yahoo_packet_hash(pkt, 47, "2"); | |
9984 | 3018 else if (away) |
3019 yahoo_packet_hash(pkt, 47, "1"); | |
6784 | 3020 else |
9984 | 3021 yahoo_packet_hash(pkt, 47, "0"); |
3022 } else if (gc->is_idle) { | |
3023 yahoo_packet_hash(pkt, 47, "2"); | |
6686 | 3024 } |
2681 | 3025 |
3026 yahoo_send_packet(yd, pkt); | |
3027 yahoo_packet_free(pkt); | |
9984 | 3028 |
3029 g_free(conv_msg); | |
3030 g_free(conv_msg2); | |
2681 | 3031 } |
3032 | |
5583 | 3033 static void yahoo_set_idle(GaimConnection *gc, int idle) |
2681 | 3034 { |
9984 | 3035 #if 0 |
3036 /* this is complicated, since it interacts with other statuses */ | |
2681 | 3037 struct yahoo_data *yd = gc->proto_data; |
3038 struct yahoo_packet *pkt = NULL; | |
8503 | 3039 char *msg = NULL, *msg2 = NULL; |
2681 | 3040 |
3041 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
6847 | 3042 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); |
2681 | 3043 yd->current_status = YAHOO_STATUS_IDLE; |
3044 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
3045 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); | |
3046 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
6847 | 3047 } else { |
6784 | 3048 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); |
2681 | 3049 } |
3050 | |
3051 if (pkt) { | |
3052 char buf[4]; | |
3053 g_snprintf(buf, sizeof(buf), "%d", yd->current_status); | |
3054 yahoo_packet_hash(pkt, 10, buf); | |
6784 | 3055 if (gc->away && yd->current_status == YAHOO_STATUS_CUSTOM) { |
7827 | 3056 msg = yahoo_string_encode(gc, gc->away, NULL); |
8503 | 3057 msg2 = gaim_unescape_html(msg); |
3058 yahoo_packet_hash(pkt, 19, msg2); | |
6784 | 3059 if (idle) |
3060 yahoo_packet_hash(pkt, 47, "2"); | |
3061 else | |
3062 yahoo_packet_hash(pkt, 47, "1"); /* fixme when available messages are possible */ | |
6847 | 3063 } else if (idle && (yd->current_status != YAHOO_STATUS_AVAILABLE) && |
3064 (yd->current_status != YAHOO_STATUS_IDLE)) { | |
3065 yahoo_packet_hash(pkt, 47, "2"); | |
3066 } else if (!idle && (yd->current_status != YAHOO_STATUS_AVAILABLE) && | |
3067 (yd->current_status != YAHOO_STATUS_IDLE)) { | |
3068 yahoo_packet_hash(pkt, 47, "1"); | |
6784 | 3069 } |
6847 | 3070 |
2681 | 3071 yahoo_send_packet(yd, pkt); |
3072 yahoo_packet_free(pkt); | |
3073 } | |
7827 | 3074 if (msg) |
3075 g_free(msg); | |
8503 | 3076 if (msg2) |
3077 g_free(msg2); | |
9984 | 3078 #endif |
2681 | 3079 } |
3080 | |
9979 | 3081 static GList *yahoo_status_types(GaimAccount *account) |
2681 | 3082 { |
9979 | 3083 GaimConnection *gc = gaim_account_get_connection(account); |
3084 struct yahoo_data *yd = NULL; | |
3085 GaimStatusType *type; | |
3086 GList *types = NULL; | |
3087 | |
3088 if (gc) | |
3089 yd = gc->proto_data; | |
3090 | |
3091 type = gaim_status_type_new(GAIM_STATUS_OFFLINE, "offline", _("Offline"), FALSE); | |
3092 types = g_list_append(types, type); | |
3093 | |
3094 type = gaim_status_type_new(GAIM_STATUS_ONLINE, "online", _("Online"), FALSE); | |
3095 types = g_list_append(types, type); | |
3096 | |
3097 type = gaim_status_type_new(GAIM_STATUS_AVAILABLE, "available", _("Available"), TRUE); | |
3098 types = g_list_append(types, type); | |
3099 | |
3100 if (!yd || !yd->wm) { | |
3101 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, "available-wm", | |
3102 "Available With Message", TRUE, TRUE, FALSE, | |
3103 "message", _("Message"), | |
10009 | 3104 gaim_value_new(GAIM_TYPE_STRING), NULL); |
9979 | 3105 types = g_list_append(types, type); |
3106 | |
3107 | |
3108 type = gaim_status_type_new(GAIM_STATUS_AWAY, "brb", _("Be Right Back"), TRUE); | |
3109 types = g_list_append(types, type); | |
3110 | |
3111 type = gaim_status_type_new(GAIM_STATUS_AWAY, "busy", _("Busy"), TRUE); | |
3112 types = g_list_append(types, type); | |
3113 | |
3114 type = gaim_status_type_new(GAIM_STATUS_AWAY, "notathome", _("Not At Home"), TRUE); | |
3115 types = g_list_append(types, type); | |
3116 | |
3117 type = gaim_status_type_new(GAIM_STATUS_AWAY, "notatdesk", _("Not At Desk"), TRUE); | |
3118 types = g_list_append(types, type); | |
3119 | |
3120 type = gaim_status_type_new(GAIM_STATUS_AWAY, "notinoffice", _("Not In Office"), TRUE); | |
3121 types = g_list_append(types, type); | |
3122 | |
3123 type = gaim_status_type_new(GAIM_STATUS_AWAY, "onthephone", _("On The Phone"), TRUE); | |
3124 types = g_list_append(types, type); | |
3125 | |
3126 type = gaim_status_type_new(GAIM_STATUS_AWAY, "onvacation", _("On Vacation"), TRUE); | |
3127 types = g_list_append(types, type); | |
3128 | |
3129 type = gaim_status_type_new(GAIM_STATUS_AWAY, "outtolunch", _("Out To Lunch"), TRUE); | |
3130 types = g_list_append(types, type); | |
3131 | |
3132 type = gaim_status_type_new(GAIM_STATUS_AWAY, "steppedout", _("Stepped Out"), TRUE); | |
3133 types = g_list_append(types, type); | |
3134 | |
3135 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, "away", | |
3136 "Away", TRUE, TRUE, FALSE, | |
3137 "message", _("Message"), | |
10009 | 3138 gaim_value_new(GAIM_TYPE_STRING), NULL); |
9979 | 3139 types = g_list_append(types, type); |
9370 | 3140 } |
9979 | 3141 type = gaim_status_type_new(GAIM_STATUS_HIDDEN, "invisible", _("Invisible"), TRUE); |
3142 types = g_list_append(types, type); | |
3143 | |
3144 | |
3145 return types; | |
2681 | 3146 } |
3147 | |
5583 | 3148 static void yahoo_keepalive(GaimConnection *gc) |
2681 | 3149 { |
3150 struct yahoo_data *yd = gc->proto_data; | |
3151 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0); | |
3152 yahoo_send_packet(yd, pkt); | |
3153 yahoo_packet_free(pkt); | |
6729 | 3154 |
3155 if (!yd->chat_online) | |
3156 return; | |
3157 | |
9376 | 3158 if (yd->wm) { |
3159 ycht_chat_send_keepalive(yd->ycht); | |
3160 return; | |
3161 } | |
3162 | |
6729 | 3163 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YAHOO_STATUS_AVAILABLE, 0); |
3164 yahoo_packet_hash(pkt, 109, gaim_connection_get_display_name(gc)); | |
3165 yahoo_send_packet(yd, pkt); | |
3166 yahoo_packet_free(pkt); | |
2681 | 3167 } |
3168 | |
9285 | 3169 /* XXX - What's the deal with GaimGroup *foo? */ |
3170 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *foo) | |
2681 | 3171 { |
3172 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
3173 struct yahoo_packet *pkt; | |
6695 | 3174 GaimGroup *g; |
2681 | 3175 char *group = NULL; |
7829 | 3176 char *group2 = NULL; |
2681 | 3177 |
3178 if (!yd->logged_in) | |
3179 return; | |
3180 | |
6840 | 3181 if (foo) |
3182 group = foo->name; | |
3183 if (!group) { | |
9285 | 3184 g = gaim_find_buddys_group(gaim_find_buddy(gc->account, buddy->name)); |
6840 | 3185 if (g) |
3186 group = g->name; | |
3187 else | |
3188 group = "Buddies"; | |
3189 } | |
2681 | 3190 |
7829 | 3191 group2 = yahoo_string_encode(gc, group, NULL); |
2681 | 3192 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); |
5583 | 3193 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
9285 | 3194 yahoo_packet_hash(pkt, 7, buddy->name); |
7829 | 3195 yahoo_packet_hash(pkt, 65, group2); |
6820 | 3196 yahoo_packet_hash(pkt, 14, ""); |
2681 | 3197 yahoo_send_packet(yd, pkt); |
3198 yahoo_packet_free(pkt); | |
7829 | 3199 g_free(group2); |
2681 | 3200 } |
3201 | |
9285 | 3202 static void yahoo_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
2681 | 3203 { |
3204 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
9278 | 3205 YahooFriend *f; |
6795
40ba19133882
[gaim-migrate @ 7334]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6793
diff
changeset
|
3206 struct yahoo_packet *pkt; |
6840 | 3207 GSList *buddies, *l; |
3208 GaimGroup *g; | |
3209 gboolean remove = TRUE; | |
7827 | 3210 char *cg; |
6784 | 3211 |
9285 | 3212 if (!(f = yahoo_friend_find(gc, buddy->name))) |
6784 | 3213 return; |
3214 | |
9285 | 3215 buddies = gaim_find_buddies(gaim_connection_get_account(gc), buddy->name); |
6840 | 3216 for (l = buddies; l; l = l->next) { |
3217 g = gaim_find_buddys_group(l->data); | |
9285 | 3218 if (gaim_utf8_strcasecmp(group->name, g->name)) { |
6840 | 3219 remove = FALSE; |
3220 break; | |
3221 } | |
3222 } | |
3223 | |
3224 g_slist_free(buddies); | |
3225 | |
3226 if (remove) | |
9285 | 3227 g_hash_table_remove(yd->friends, buddy->name); |
3228 | |
3229 cg = yahoo_string_encode(gc, group->name, NULL); | |
6795
40ba19133882
[gaim-migrate @ 7334]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6793
diff
changeset
|
3230 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); |
5583 | 3231 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
9285 | 3232 yahoo_packet_hash(pkt, 7, buddy->name); |
7827 | 3233 yahoo_packet_hash(pkt, 65, cg); |
2681 | 3234 yahoo_send_packet(yd, pkt); |
3235 yahoo_packet_free(pkt); | |
7827 | 3236 g_free(cg); |
2681 | 3237 } |
3238 | |
6760 | 3239 static void yahoo_add_deny(GaimConnection *gc, const char *who) { |
3240 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
3241 struct yahoo_packet *pkt; | |
3242 | |
3243 if (!yd->logged_in) | |
3244 return; | |
8057 | 3245 /* It seems to work better without this */ |
3246 | |
8113 | 3247 /* if (gc->account->perm_deny != 4) |
3248 return; */ | |
3249 | |
3250 if (!who || who[0] == '\0') | |
3251 return; | |
3252 | |
6760 | 3253 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); |
3254 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
3255 yahoo_packet_hash(pkt, 7, who); | |
3256 yahoo_packet_hash(pkt, 13, "1"); | |
3257 yahoo_send_packet(yd, pkt); | |
3258 yahoo_packet_free(pkt); | |
3259 } | |
3260 | |
3261 static void yahoo_rem_deny(GaimConnection *gc, const char *who) { | |
3262 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
3263 struct yahoo_packet *pkt; | |
3264 | |
3265 if (!yd->logged_in) | |
3266 return; | |
3267 | |
3268 if (!who || who[0] == '\0') | |
3269 return; | |
3270 | |
3271 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); | |
3272 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
3273 yahoo_packet_hash(pkt, 7, who); | |
3274 yahoo_packet_hash(pkt, 13, "2"); | |
3275 yahoo_send_packet(yd, pkt); | |
3276 yahoo_packet_free(pkt); | |
3277 } | |
3278 | |
3279 static void yahoo_set_permit_deny(GaimConnection *gc) { | |
3280 GaimAccount *acct; | |
3281 GSList *deny; | |
3282 | |
3283 acct = gc->account; | |
3284 | |
3285 switch (acct->perm_deny) { | |
3286 case 1: | |
3287 case 3: | |
3288 case 5: | |
3289 for (deny = acct->deny;deny;deny = deny->next) | |
3290 yahoo_rem_deny(gc, deny->data); | |
3291 break; | |
3292 case 4: | |
3293 for (deny = acct->deny;deny;deny = deny->next) | |
3294 yahoo_add_deny(gc, deny->data); | |
3295 break; | |
3296 case 2: | |
3297 default: | |
3298 break; | |
3299 } | |
3300 } | |
3301 | |
6513 | 3302 static gboolean yahoo_unload_plugin(GaimPlugin *plugin) |
3303 { | |
3304 yahoo_dest_colorht(); | |
3305 return TRUE; | |
3306 } | |
3307 | |
6793 | 3308 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who, |
3309 const char *old_group, const char *new_group) | |
3310 { | |
3311 struct yahoo_data *yd = gc->proto_data; | |
3312 struct yahoo_packet *pkt; | |
7827 | 3313 char *gpn, *gpo; |
6793 | 3314 |
3315 /* Step 0: If they aren't on the server list anyway, | |
3316 * don't bother letting the server know. | |
3317 */ | |
9279 | 3318 if (!yahoo_friend_find(gc, who)) |
6793 | 3319 return; |
3320 | |
7827 | 3321 /* If old and new are the same, we would probably |
3322 * end up deleting the buddy, which would be bad. | |
3323 * This might happen because of the charset conversation. | |
3324 */ | |
3325 gpn = yahoo_string_encode(gc, new_group, NULL); | |
3326 gpo = yahoo_string_encode(gc, old_group, NULL); | |
3327 if (!strcmp(gpn, gpo)) { | |
3328 g_free(gpn); | |
3329 g_free(gpo); | |
3330 return; | |
3331 } | |
3332 | |
6793 | 3333 /* Step 1: Add buddy to new group. */ |
3334 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
3335 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
3336 yahoo_packet_hash(pkt, 7, who); | |
7827 | 3337 yahoo_packet_hash(pkt, 65, gpn); |
6793 | 3338 yahoo_packet_hash(pkt, 14, ""); |
3339 yahoo_send_packet(yd, pkt); | |
3340 yahoo_packet_free(pkt); | |
3341 | |
3342 /* Step 2: Remove buddy from old group */ | |
3343 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
3344 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
3345 yahoo_packet_hash(pkt, 7, who); | |
7827 | 3346 yahoo_packet_hash(pkt, 65, gpo); |
6793 | 3347 yahoo_send_packet(yd, pkt); |
3348 yahoo_packet_free(pkt); | |
7827 | 3349 g_free(gpn); |
3350 g_free(gpo); | |
6793 | 3351 } |
3352 | |
9285 | 3353 static void yahoo_rename_group(GaimConnection *gc, const char *old_name, |
3354 GaimGroup *group, GList *moved_buddies) | |
6793 | 3355 { |
3356 struct yahoo_data *yd = gc->proto_data; | |
3357 struct yahoo_packet *pkt; | |
7827 | 3358 char *gpn, *gpo; |
3359 | |
9285 | 3360 gpn = yahoo_string_encode(gc, group->name, NULL); |
3361 gpo = yahoo_string_encode(gc, old_name, NULL); | |
7827 | 3362 if (!strcmp(gpn, gpo)) { |
3363 g_free(gpn); | |
3364 g_free(gpo); | |
3365 return; | |
3366 } | |
6793 | 3367 |
3368 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, YAHOO_STATUS_AVAILABLE, 0); | |
3369 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
7827 | 3370 yahoo_packet_hash(pkt, 65, gpo); |
3371 yahoo_packet_hash(pkt, 67, gpn); | |
6793 | 3372 yahoo_send_packet(yd, pkt); |
3373 yahoo_packet_free(pkt); | |
7827 | 3374 g_free(gpn); |
3375 g_free(gpo); | |
6793 | 3376 } |
3377 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3378 static GaimPlugin *my_protocol = NULL; |
2681 | 3379 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3380 static GaimPluginProtocolInfo prpl_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3381 { |
9308 | 3382 OPT_PROTO_MAIL_CHECK | OPT_PROTO_CHAT_TOPIC, |
6729 | 3383 NULL, /* user_splits */ |
3384 NULL, /* protocol_options */ | |
9318 | 3385 {"png", 96, 96, 96, 96, GAIM_ICON_SCALE_SEND}, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3386 yahoo_list_icon, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3387 yahoo_list_emblems, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3388 yahoo_status_text, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3389 yahoo_tooltip_text, |
9979 | 3390 yahoo_status_types, |
9030 | 3391 yahoo_blist_node_menu, |
6729 | 3392 yahoo_c_info, |
9768 | 3393 yahoo_c_info_defaults, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3394 yahoo_login, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3395 yahoo_close, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3396 yahoo_send_im, |
6729 | 3397 NULL, /* set info */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3398 yahoo_send_typing, |
6514 | 3399 yahoo_get_info, |
9984 | 3400 yahoo_set_status, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3401 yahoo_set_idle, |
6729 | 3402 NULL, /* change_passwd*/ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3403 yahoo_add_buddy, |
6729 | 3404 NULL, /* add_buddies */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3405 yahoo_remove_buddy, |
6729 | 3406 NULL, /*remove_buddies */ |
3407 NULL, /* add_permit */ | |
6760 | 3408 yahoo_add_deny, |
6729 | 3409 NULL, /* rem_permit */ |
6760 | 3410 yahoo_rem_deny, |
3411 yahoo_set_permit_deny, | |
6729 | 3412 NULL, /* warn */ |
3413 yahoo_c_join, | |
8562 | 3414 NULL, /* reject chat invite */ |
9917 | 3415 yahoo_get_chat_name, |
6729 | 3416 yahoo_c_invite, |
3417 yahoo_c_leave, | |
3418 NULL, /* chat whisper */ | |
3419 yahoo_c_send, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3420 yahoo_keepalive, |
6729 | 3421 NULL, /* register_user */ |
3422 NULL, /* get_cb_info */ | |
3423 NULL, /* get_cb_away */ | |
3424 NULL, /* alias_buddy */ | |
6793 | 3425 yahoo_change_buddys_group, |
3426 yahoo_rename_group, | |
6729 | 3427 NULL, /* buddy_free */ |
3428 NULL, /* convo_closed */ | |
3429 NULL, /* normalize */ | |
9306 | 3430 yahoo_set_buddy_icon, |
7651 | 3431 NULL, /* void (*remove_group)(GaimConnection *gc, const char *group);*/ |
3432 NULL, /* char *(*get_cb_real_name)(GaimConnection *gc, int id, const char *who); */ | |
9475 | 3433 NULL, /* set_chat_topic */ |
3434 NULL, /* find_blist_chat */ | |
8113 | 3435 yahoo_roomlist_get_list, |
3436 yahoo_roomlist_cancel, | |
9466 | 3437 yahoo_roomlist_expand_category, |
9475 | 3438 NULL, /* can_receive_file */ |
9466 | 3439 yahoo_send_file |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3440 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3441 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3442 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3443 { |
9943 | 3444 GAIM_PLUGIN_MAGIC, |
3445 GAIM_MAJOR_VERSION, | |
3446 GAIM_MINOR_VERSION, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3447 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3448 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3449 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3450 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3451 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3452 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3453 "prpl-yahoo", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3454 "Yahoo", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3455 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3456 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3457 N_("Yahoo Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3458 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3459 N_("Yahoo Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3460 NULL, /**< author */ |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
3461 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3462 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3463 NULL, /**< load */ |
6513 | 3464 yahoo_unload_plugin, /**< unload */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3465 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3466 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3467 NULL, /**< ui_info */ |
8993 | 3468 &prpl_info, /**< extra_info */ |
3469 NULL, | |
9015 | 3470 yahoo_actions |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3471 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3472 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3473 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
3474 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3475 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5590
diff
changeset
|
3476 GaimAccountOption *option; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3477 |
9164 | 3478 option = gaim_account_option_bool_new(_("Yahoo Japan"), "yahoojp", FALSE); |
3479 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3480 | |
7827 | 3481 option = gaim_account_option_string_new(_("Pager host"), "server", YAHOO_PAGER_HOST); |
3482 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3483 | |
9164 | 3484 option = gaim_account_option_string_new(_("Japan Pager host"), "serverjp", YAHOOJP_PAGER_HOST); |
3485 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3486 | |
7827 | 3487 option = gaim_account_option_int_new(_("Pager port"), "port", YAHOO_PAGER_PORT); |
3488 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
7651 | 3489 |
3490 option = gaim_account_option_string_new(_("File transfer host"), "xfer_host", YAHOO_XFER_HOST); | |
3491 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3492 | |
9164 | 3493 option = gaim_account_option_string_new(_("Japan File transfer host"), "xferjp_host", YAHOOJP_XFER_HOST); |
3494 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3495 | |
7651 | 3496 option = gaim_account_option_int_new(_("File transfer port"), "xfer_port", YAHOO_XFER_PORT); |
3497 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3498 | |
8113 | 3499 option = gaim_account_option_string_new(_("Chat Room List Url"), "room_list", YAHOO_ROOMLIST_URL); |
3500 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
9376 | 3501 #if 0 |
3502 option = gaim_account_option_string_new(_("YCHT Host"), "ycht-server", YAHOO_YCHT_HOST); | |
3503 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3504 | |
3505 option = gaim_account_option_int_new(_("YCHT Port"), "ycht-port", YAHOO_YCHT_PORT); | |
3506 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3507 #endif | |
3508 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3509 my_protocol = plugin; |
6513 | 3510 |
3511 yahoo_init_colorht(); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3512 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3513 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
3514 GAIM_INIT_PLUGIN(yahoo, init_plugin, info); |