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