Mercurial > pidgin
annotate src/protocols/yahoo/yahoo.c @ 3640:1c39909fb476
[gaim-migrate @ 3763]
Bug fix by Craig Metz
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Fri, 11 Oct 2002 05:39:37 +0000 |
parents | 9682c0e022c6 |
children | 5e50f6746509 |
rev | line source |
---|---|
2681 | 1 /* |
2 * gaim | |
3 * | |
4 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include "config.h" | |
25 #endif | |
26 | |
3630 | 27 #ifndef _WIN32 |
2681 | 28 #include <netdb.h> |
29 #include <unistd.h> | |
30 #include <netinet/in.h> | |
31 #include <arpa/inet.h> | |
3630 | 32 #include <sys/socket.h> |
33 #else | |
34 #include <winsock.h> | |
35 #endif | |
36 | |
37 #include <errno.h> | |
2681 | 38 #include <string.h> |
39 #include <stdlib.h> | |
40 #include <stdio.h> | |
41 #include <time.h> | |
42 #include <sys/stat.h> | |
43 #include <ctype.h> | |
44 #include "multi.h" | |
45 #include "prpl.h" | |
46 #include "gaim.h" | |
47 #include "proxy.h" | |
3147 | 48 #include "md5.h" |
2681 | 49 |
3630 | 50 #ifdef _WIN32 |
51 #include "win32dep.h" | |
52 #endif | |
53 | |
2795
536bb833fdeb
[gaim-migrate @ 2808]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2786
diff
changeset
|
54 extern char *yahoo_crypt(char *, char *); |
536bb833fdeb
[gaim-migrate @ 2808]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2786
diff
changeset
|
55 |
3630 | 56 /* for win32 compatability */ |
57 G_MODULE_IMPORT GSList *connections; | |
58 | |
2681 | 59 #include "pixmaps/status-away.xpm" |
60 #include "pixmaps/status-here.xpm" | |
61 #include "pixmaps/status-idle.xpm" | |
3019 | 62 #include "pixmaps/status-game.xpm" |
2681 | 63 |
3035 | 64 /* Yahoo Smilies go here */ |
65 #include "pixmaps/protocols/yahoo/yahoo_alien.xpm" | |
66 #include "pixmaps/protocols/yahoo/yahoo_angel.xpm" | |
67 #include "pixmaps/protocols/yahoo/yahoo_angry.xpm" | |
68 #include "pixmaps/protocols/yahoo/yahoo_bigsmile.xpm" | |
69 #include "pixmaps/protocols/yahoo/yahoo_blush.xpm" | |
70 #include "pixmaps/protocols/yahoo/yahoo_bye.xpm" | |
71 #include "pixmaps/protocols/yahoo/yahoo_clown.xpm" | |
72 #include "pixmaps/protocols/yahoo/yahoo_cow.xpm" | |
73 #include "pixmaps/protocols/yahoo/yahoo_cowboy.xpm" | |
74 #include "pixmaps/protocols/yahoo/yahoo_cry.xpm" | |
75 #include "pixmaps/protocols/yahoo/yahoo_devil.xpm" | |
76 #include "pixmaps/protocols/yahoo/yahoo_flower.xpm" | |
77 #include "pixmaps/protocols/yahoo/yahoo_ghost.xpm" | |
78 #include "pixmaps/protocols/yahoo/yahoo_glasses.xpm" | |
79 #include "pixmaps/protocols/yahoo/yahoo_laughloud.xpm" | |
80 #include "pixmaps/protocols/yahoo/yahoo_love.xpm" | |
81 #include "pixmaps/protocols/yahoo/yahoo_mean.xpm" | |
82 #include "pixmaps/protocols/yahoo/yahoo_neutral.xpm" | |
83 #include "pixmaps/protocols/yahoo/yahoo_ooooh.xpm" | |
84 #include "pixmaps/protocols/yahoo/yahoo_question.xpm" | |
85 #include "pixmaps/protocols/yahoo/yahoo_sad.xpm" | |
86 #include "pixmaps/protocols/yahoo/yahoo_sleep.xpm" | |
87 #include "pixmaps/protocols/yahoo/yahoo_smiley.xpm" | |
88 #include "pixmaps/protocols/yahoo/yahoo_sunglas.xpm" | |
89 #include "pixmaps/protocols/yahoo/yahoo_tongue.xpm" | |
90 #include "pixmaps/protocols/yahoo/yahoo_wink.xpm" | |
91 | |
2993 | 92 #define YAHOO_DEBUG |
2681 | 93 |
94 #define USEROPT_MAIL 0 | |
95 | |
96 #define USEROPT_PAGERHOST 3 | |
3147 | 97 #define YAHOO_PAGER_HOST "scs.yahoo.com" |
2681 | 98 #define USEROPT_PAGERPORT 4 |
99 #define YAHOO_PAGER_PORT 5050 | |
100 | |
3467 | 101 #define YAHOO_PROTO_VER 0x0900 |
102 | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
103 enum yahoo_service { /* these are easier to see in hex */ |
2681 | 104 YAHOO_SERVICE_LOGON = 1, |
105 YAHOO_SERVICE_LOGOFF, | |
106 YAHOO_SERVICE_ISAWAY, | |
107 YAHOO_SERVICE_ISBACK, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
108 YAHOO_SERVICE_IDLE, /* 5 (placemarker) */ |
2681 | 109 YAHOO_SERVICE_MESSAGE, |
110 YAHOO_SERVICE_IDACT, | |
111 YAHOO_SERVICE_IDDEACT, | |
112 YAHOO_SERVICE_MAILSTAT, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
113 YAHOO_SERVICE_USERSTAT, /* 0xa */ |
2681 | 114 YAHOO_SERVICE_NEWMAIL, |
115 YAHOO_SERVICE_CHATINVITE, | |
116 YAHOO_SERVICE_CALENDAR, | |
117 YAHOO_SERVICE_NEWPERSONALMAIL, | |
118 YAHOO_SERVICE_NEWCONTACT, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
119 YAHOO_SERVICE_ADDIDENT, /* 0x10 */ |
2681 | 120 YAHOO_SERVICE_ADDIGNORE, |
121 YAHOO_SERVICE_PING, | |
122 YAHOO_SERVICE_GROUPRENAME, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
123 YAHOO_SERVICE_SYSMESSAGE = 0x14, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
124 YAHOO_SERVICE_PASSTHROUGH2 = 0x16, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
125 YAHOO_SERVICE_CONFINVITE = 0x18, |
2681 | 126 YAHOO_SERVICE_CONFLOGON, |
127 YAHOO_SERVICE_CONFDECLINE, | |
128 YAHOO_SERVICE_CONFLOGOFF, | |
129 YAHOO_SERVICE_CONFADDINVITE, | |
130 YAHOO_SERVICE_CONFMSG, | |
131 YAHOO_SERVICE_CHATLOGON, | |
132 YAHOO_SERVICE_CHATLOGOFF, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
133 YAHOO_SERVICE_CHATMSG = 0x20, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
134 YAHOO_SERVICE_GAMELOGON = 0x28, |
2786
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
135 YAHOO_SERVICE_GAMELOGOFF, |
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
136 YAHOO_SERVICE_GAMEMSG = 0x2a, |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
137 YAHOO_SERVICE_FILETRANSFER = 0x46, |
3019 | 138 YAHOO_SERVICE_NOTIFY = 0x4B, |
3147 | 139 YAHOO_SERVICE_AUTHRESP = 0x54, |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
140 YAHOO_SERVICE_LIST = 0x55, |
3147 | 141 YAHOO_SERVICE_AUTH = 0x57, |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
142 YAHOO_SERVICE_ADDBUDDY = 0x83, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
143 YAHOO_SERVICE_REMBUDDY = 0x84 |
2681 | 144 }; |
145 | |
146 enum yahoo_status { | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
147 YAHOO_STATUS_AVAILABLE = 0, |
2681 | 148 YAHOO_STATUS_BRB, |
149 YAHOO_STATUS_BUSY, | |
150 YAHOO_STATUS_NOTATHOME, | |
151 YAHOO_STATUS_NOTATDESK, | |
152 YAHOO_STATUS_NOTINOFFICE, | |
153 YAHOO_STATUS_ONPHONE, | |
154 YAHOO_STATUS_ONVACATION, | |
155 YAHOO_STATUS_OUTTOLUNCH, | |
156 YAHOO_STATUS_STEPPEDOUT, | |
157 YAHOO_STATUS_INVISIBLE = 12, | |
158 YAHOO_STATUS_CUSTOM = 99, | |
159 YAHOO_STATUS_IDLE = 999, | |
2993 | 160 YAHOO_STATUS_OFFLINE = 0x5a55aa56, /* don't ask */ |
161 YAHOO_STATUS_TYPING = 0x16 | |
2681 | 162 }; |
3019 | 163 #define YAHOO_STATUS_GAME 0x2 /* Games don't fit into the regular status model */ |
2681 | 164 |
165 struct yahoo_data { | |
166 int fd; | |
167 guchar *rxqueue; | |
168 int rxlen; | |
169 GHashTable *hash; | |
3019 | 170 GHashTable *games; |
2681 | 171 int current_status; |
172 gboolean logged_in; | |
173 }; | |
174 | |
175 struct yahoo_pair { | |
176 int key; | |
177 char *value; | |
178 }; | |
179 | |
180 struct yahoo_packet { | |
181 guint16 service; | |
182 guint32 status; | |
183 guint32 id; | |
184 GSList *hash; | |
185 }; | |
186 | |
187 #define YAHOO_PACKET_HDRLEN (4 + 2 + 2 + 2 + 2 + 4 + 4) | |
188 | |
189 static struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id) | |
190 { | |
191 struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1); | |
192 | |
193 pkt->service = service; | |
194 pkt->status = status; | |
195 pkt->id = id; | |
196 | |
197 return pkt; | |
198 } | |
199 | |
3466 | 200 static void yahoo_packet_hash(struct yahoo_packet *pkt, int key, const char *value) |
2681 | 201 { |
202 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
203 pair->key = key; | |
204 pair->value = g_strdup(value); | |
205 pkt->hash = g_slist_append(pkt->hash, pair); | |
206 } | |
207 | |
208 static int yahoo_packet_length(struct yahoo_packet *pkt) | |
209 { | |
210 GSList *l; | |
211 | |
212 int len = 0; | |
213 | |
214 l = pkt->hash; | |
215 while (l) { | |
216 struct yahoo_pair *pair = l->data; | |
217 int tmp = pair->key; | |
218 do { | |
219 tmp /= 10; | |
220 len++; | |
221 } while (tmp); | |
222 len += 2; | |
223 len += strlen(pair->value); | |
224 len += 2; | |
225 l = l->next; | |
226 } | |
227 | |
228 return len; | |
229 } | |
230 | |
231 /* sometimes i wish prpls could #include things from other prpls. then i could just | |
232 * use the routines from libfaim and not have to admit to knowing how they work. */ | |
233 #define yahoo_put16(buf, data) ( \ | |
234 (*(buf) = (u_char)((data)>>8)&0xff), \ | |
235 (*((buf)+1) = (u_char)(data)&0xff), \ | |
236 2) | |
237 #define yahoo_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff)) | |
238 #define yahoo_put32(buf, data) ( \ | |
239 (*((buf)) = (u_char)((data)>>24)&0xff), \ | |
240 (*((buf)+1) = (u_char)((data)>>16)&0xff), \ | |
241 (*((buf)+2) = (u_char)((data)>>8)&0xff), \ | |
242 (*((buf)+3) = (u_char)(data)&0xff), \ | |
243 4) | |
244 #define yahoo_get32(buf) ((((*(buf))<<24)&0xff000000) + \ | |
245 (((*((buf)+1))<<16)&0x00ff0000) + \ | |
246 (((*((buf)+2))<< 8)&0x0000ff00) + \ | |
247 (((*((buf)+3) )&0x000000ff))) | |
248 | |
249 static void yahoo_packet_read(struct yahoo_packet *pkt, guchar *data, int len) | |
250 { | |
251 int pos = 0; | |
252 | |
253 while (pos + 1 < len) { | |
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
254 char key[64], *value = NULL; |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
255 int accept; |
2681 | 256 int x; |
257 | |
258 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
259 | |
260 x = 0; | |
261 while (pos + 1 < len) { | |
262 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
263 break; | |
264 key[x++] = data[pos++]; | |
265 } | |
266 key[x] = 0; | |
267 pos += 2; | |
268 pair->key = strtol(key, NULL, 10); | |
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
269 accept = x; /* if x is 0 there was no key, so don't accept it */ |
2681 | 270 |
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
271 if (accept) |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
272 value = g_malloc(len - pos + 1); |
2681 | 273 x = 0; |
274 while (pos + 1 < len) { | |
275 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
276 break; | |
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
277 if (accept) |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
278 value[x++] = data[pos++]; |
2681 | 279 } |
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
280 if (accept) |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
281 value[x] = 0; |
2681 | 282 pos += 2; |
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
283 if (accept) { |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
284 pair->value = g_strdup(value); |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
285 g_free(value); |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
286 pkt->hash = g_slist_append(pkt->hash, pair); |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
287 debug_printf("Key: %d \tValue: %s\n", pair->key, pair->value); |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
288 } else { |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
289 g_free(pair); |
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
290 } |
2681 | 291 } |
292 } | |
293 | |
294 static void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data) | |
295 { | |
296 GSList *l = pkt->hash; | |
297 int pos = 0; | |
298 | |
299 while (l) { | |
300 struct yahoo_pair *pair = l->data; | |
301 guchar buf[100]; | |
302 | |
303 g_snprintf(buf, sizeof(buf), "%d", pair->key); | |
304 strcpy(data + pos, buf); | |
305 pos += strlen(buf); | |
306 data[pos++] = 0xc0; | |
307 data[pos++] = 0x80; | |
308 | |
309 strcpy(data + pos, pair->value); | |
310 pos += strlen(pair->value); | |
311 data[pos++] = 0xc0; | |
312 data[pos++] = 0x80; | |
313 | |
314 l = l->next; | |
315 } | |
316 } | |
317 | |
318 static void yahoo_packet_dump(guchar *data, int len) | |
319 { | |
320 #ifdef YAHOO_DEBUG | |
321 int i; | |
322 for (i = 0; i + 1 < len; i += 2) { | |
323 if ((i % 16 == 0) && i) | |
324 debug_printf("\n"); | |
325 debug_printf("%02x", data[i]); | |
326 debug_printf("%02x ", data[i+1]); | |
327 } | |
328 if (i < len) | |
329 debug_printf("%02x", data[i]); | |
330 debug_printf("\n"); | |
331 for (i = 0; i < len; i++) { | |
332 if ((i % 16 == 0) && i) | |
333 debug_printf("\n"); | |
334 if (isprint(data[i])) | |
335 debug_printf("%c ", data[i]); | |
336 else | |
337 debug_printf(". "); | |
338 } | |
339 debug_printf("\n"); | |
340 #endif | |
341 } | |
342 | |
343 static int yahoo_send_packet(struct yahoo_data *yd, struct yahoo_packet *pkt) | |
344 { | |
345 int pktlen = yahoo_packet_length(pkt); | |
346 int len = YAHOO_PACKET_HDRLEN + pktlen; | |
347 int ret; | |
348 | |
349 guchar *data; | |
350 int pos = 0; | |
351 | |
352 if (yd->fd < 0) | |
353 return -1; | |
354 | |
355 data = g_malloc0(len + 1); | |
356 | |
357 memcpy(data + pos, "YMSG", 4); pos += 4; | |
3467 | 358 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); |
2681 | 359 pos += yahoo_put16(data + pos, 0x0000); |
360 pos += yahoo_put16(data + pos, pktlen); | |
361 pos += yahoo_put16(data + pos, pkt->service); | |
362 pos += yahoo_put32(data + pos, pkt->status); | |
363 pos += yahoo_put32(data + pos, pkt->id); | |
364 | |
365 yahoo_packet_write(pkt, data + pos); | |
366 | |
367 yahoo_packet_dump(data, len); | |
3630 | 368 #ifndef _WIN32 |
2681 | 369 ret = write(yd->fd, data, len); |
3630 | 370 #else |
371 ret = send(yd->fd, data, len, 0); | |
372 #endif | |
2681 | 373 g_free(data); |
374 | |
375 return ret; | |
376 } | |
377 | |
378 static void yahoo_packet_free(struct yahoo_packet *pkt) | |
379 { | |
380 while (pkt->hash) { | |
381 struct yahoo_pair *pair = pkt->hash->data; | |
382 g_free(pair->value); | |
383 g_free(pair); | |
384 pkt->hash = g_slist_remove(pkt->hash, pair); | |
385 } | |
386 g_free(pkt); | |
387 } | |
388 | |
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
389 static void yahoo_process_status(struct gaim_connection *gc, struct yahoo_packet *pkt) |
2681 | 390 { |
391 struct yahoo_data *yd = gc->proto_data; | |
392 GSList *l = pkt->hash; | |
393 char *name = NULL; | |
394 int state = 0; | |
3019 | 395 int gamestate = 0; |
2681 | 396 char *msg = NULL; |
3019 | 397 |
2681 | 398 while (l) { |
399 struct yahoo_pair *pair = l->data; | |
400 | |
401 switch (pair->key) { | |
402 case 0: /* we won't actually do anything with this */ | |
403 break; | |
404 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
|
405 if (!yd->logged_in) { |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
406 account_online(gc); |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
407 serv_finish_login(gc); |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
408 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", pair->value); |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
409 yd->logged_in = TRUE; |
2681 | 410 |
3147 | 411 /* this requests the list. i have a feeling that this is very evil |
412 * | |
413 * scs.yahoo.com sends you the list before this packet without it being | |
414 * requested | |
415 * | |
416 * do_import(gc, NULL); | |
417 * newpkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_OFFLINE, 0); | |
418 * yahoo_send_packet(yd, newpkt); | |
419 * yahoo_packet_free(newpkt); | |
420 */ | |
421 | |
422 } | |
2681 | 423 break; |
424 case 8: /* how many online buddies we have */ | |
425 break; | |
426 case 7: /* the current buddy */ | |
427 name = pair->value; | |
428 break; | |
429 case 10: /* state */ | |
430 state = strtol(pair->value, NULL, 10); | |
431 break; | |
432 case 19: /* custom message */ | |
433 msg = pair->value; | |
434 break; | |
435 case 11: /* i didn't know what this was in the old protocol either */ | |
436 break; | |
437 case 17: /* in chat? */ | |
438 break; | |
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
439 case 13: /* in pager? */ |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
440 if (pkt->service == YAHOO_SERVICE_LOGOFF || |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
441 strtol(pair->value, NULL, 10) == 0) { |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
442 serv_got_update(gc, name, 0, 0, 0, 0, 0, 0); |
2807
f01e6a425136
[gaim-migrate @ 2820]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2805
diff
changeset
|
443 break; |
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
444 } |
3019 | 445 if (g_hash_table_lookup(yd->games, name)) |
446 gamestate = YAHOO_STATUS_GAME; | |
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
447 if (state == YAHOO_STATUS_AVAILABLE) |
3019 | 448 serv_got_update(gc, name, 1, 0, 0, 0, gamestate, 0); |
3147 | 449 else |
3019 | 450 serv_got_update(gc, name, 1, 0, 0, 0, (state << 2) | UC_UNAVAILABLE | gamestate, 0); |
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
451 if (state == YAHOO_STATUS_CUSTOM) { |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
452 gpointer val = g_hash_table_lookup(yd->hash, name); |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
453 if (val) { |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
454 g_free(val); |
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
455 g_hash_table_insert(yd->hash, name, |
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
456 msg ? g_strdup(msg) : g_malloc0(1)); |
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
457 } else |
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
458 g_hash_table_insert(yd->hash, g_strdup(name), |
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
459 msg ? g_strdup(msg) : g_malloc0(1)); |
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
460 } |
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
461 break; |
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
462 case 60: /* no clue */ |
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
463 break; |
2979 | 464 case 16: /* Custom error message */ |
3427 | 465 do_error_dialog(pair->value, NULL, GAIM_ERROR); |
2951 | 466 break; |
2681 | 467 default: |
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
468 debug_printf("unknown status key %d\n", pair->key); |
2681 | 469 break; |
470 } | |
471 | |
472 l = l->next; | |
473 } | |
474 } | |
475 | |
476 static void yahoo_process_list(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
477 { | |
478 GSList *l = pkt->hash; | |
479 gboolean export = FALSE; | |
480 | |
481 while (l) { | |
482 char **lines; | |
483 char **split; | |
484 char **buddies; | |
485 char **tmp, **bud; | |
486 | |
487 struct yahoo_pair *pair = l->data; | |
488 l = l->next; | |
489 | |
490 if (pair->key != 87) | |
491 continue; | |
492 | |
3147 | 493 do_import(gc, NULL); |
2681 | 494 lines = g_strsplit(pair->value, "\n", -1); |
495 for (tmp = lines; *tmp; tmp++) { | |
496 split = g_strsplit(*tmp, ":", 2); | |
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
497 if (!split) |
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
498 continue; |
2702
94b4271b9567
[gaim-migrate @ 2715]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2697
diff
changeset
|
499 if (!split[0] || !split[1]) { |
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
500 g_strfreev(split); |
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
501 continue; |
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
502 } |
2681 | 503 buddies = g_strsplit(split[1], ",", -1); |
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
504 for (bud = buddies; bud && *bud; bud++) |
2681 | 505 if (!find_buddy(gc, *bud)) { |
506 add_buddy(gc, split[0], *bud, *bud); | |
507 export = TRUE; | |
508 } | |
509 g_strfreev(buddies); | |
510 g_strfreev(split); | |
511 } | |
512 g_strfreev(lines); | |
513 } | |
514 | |
515 if (export) | |
516 do_export(gc); | |
517 } | |
518 | |
3019 | 519 static void yahoo_process_notify(struct gaim_connection *gc, struct yahoo_packet *pkt) |
2993 | 520 { |
521 char *msg = NULL; | |
522 char *from = NULL; | |
3019 | 523 char *stat = NULL; |
524 char *game = NULL; | |
2993 | 525 GSList *l = pkt->hash; |
3019 | 526 struct yahoo_data *yd = (struct yahoo_data*) gc->proto_data; |
2993 | 527 while (l) { |
528 struct yahoo_pair *pair = l->data; | |
529 if (pair->key == 4) | |
530 from = pair->value; | |
531 if (pair->key == 49) | |
532 msg = pair->value; | |
3001 | 533 if (pair->key == 13) |
3019 | 534 stat = pair->value; |
535 if (pair->key == 14) | |
536 game = pair->value; | |
2993 | 537 l = l->next; |
538 } | |
3640 | 539 |
540 if (!msg) | |
541 return; | |
3019 | 542 |
543 if (!g_strncasecmp(msg, "TYPING", strlen("TYPING"))) { | |
544 if (*stat == '1') | |
545 serv_got_typing(gc, from, 0); | |
546 else | |
547 serv_got_typing_stopped(gc, from); | |
548 } else if (!g_strncasecmp(msg, "GAME", strlen("GAME"))) { | |
549 struct buddy *bud = find_buddy(gc, from); | |
550 void *free1=NULL, *free2=NULL; | |
3020 | 551 if (!bud) |
3019 | 552 debug_printf("%s is playing a game, and doesn't want you to know.\n"); |
553 if (*stat == '1') { | |
554 if (g_hash_table_lookup_extended (yd->games, from, free1, free2)) { | |
555 g_free(free1); | |
556 g_free(free2); | |
557 } | |
558 g_hash_table_insert (yd->games, g_strdup(from), g_strdup(game)); | |
3020 | 559 if (bud) |
560 serv_got_update(gc, from, 1, 0, 0, 0, bud->uc | YAHOO_STATUS_GAME, 0); | |
3019 | 561 } else { |
562 if (g_hash_table_lookup_extended (yd->games, from, free1, free2)) { | |
563 g_free(free1); | |
564 g_free(free2); | |
565 g_hash_table_remove (yd->games, from); | |
566 } | |
3020 | 567 if (bud) |
568 serv_got_update(gc, from, 1, 0, 0, 0, bud->uc & ~YAHOO_STATUS_GAME, 0); | |
3019 | 569 } |
570 } | |
2993 | 571 } |
572 | |
2681 | 573 static void yahoo_process_message(struct gaim_connection *gc, struct yahoo_packet *pkt) |
574 { | |
575 char *msg = NULL; | |
576 char *from = NULL; | |
577 time_t tm = time(NULL); | |
578 GSList *l = pkt->hash; | |
3021 | 579 |
2681 | 580 while (l) { |
581 struct yahoo_pair *pair = l->data; | |
582 if (pair->key == 4) | |
583 from = pair->value; | |
584 if (pair->key == 14) | |
585 msg = pair->value; | |
586 if (pair->key == 15) | |
587 tm = strtol(pair->value, NULL, 10); | |
588 l = l->next; | |
589 } | |
590 | |
3021 | 591 if (pkt->status <= 1 || pkt->status == 5) { |
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
592 char *m; |
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
593 int i, j; |
2681 | 594 strip_linefeed(msg); |
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
595 m = msg; |
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
596 for (i = 0, j = 0; m[i]; i++) { |
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
597 if (m[i] == 033) { |
2813
bda5b89ba2f9
[gaim-migrate @ 2826]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2807
diff
changeset
|
598 while (m[i] && (m[i] != 'm')) |
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
599 i++; |
2813
bda5b89ba2f9
[gaim-migrate @ 2826]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2807
diff
changeset
|
600 if (!m[i]) |
bda5b89ba2f9
[gaim-migrate @ 2826]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2807
diff
changeset
|
601 i--; |
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
602 continue; |
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
603 } |
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
604 msg[j++] = m[i]; |
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
605 } |
2813
bda5b89ba2f9
[gaim-migrate @ 2826]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2807
diff
changeset
|
606 msg[j] = 0; |
3493 | 607 serv_got_im(gc, from, utf8_to_str(msg), 0, tm, -1); |
2681 | 608 } else if (pkt->status == 2) { |
3427 | 609 do_error_dialog(_("Your Yahoo! message did not get sent."), NULL, GAIM_ERROR); |
2681 | 610 } |
611 } | |
612 | |
613 | |
614 static void yahoo_process_contact(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
615 { | |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
616 struct yahoo_data *yd = gc->proto_data; |
2681 | 617 char *id = NULL; |
618 char *who = NULL; | |
619 char *msg = NULL; | |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
620 char *name = NULL; |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
621 int state = YAHOO_STATUS_AVAILABLE; |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
622 int online = FALSE; |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
623 |
2681 | 624 GSList *l = pkt->hash; |
625 | |
626 while (l) { | |
627 struct yahoo_pair *pair = l->data; | |
628 if (pair->key == 1) | |
629 id = pair->value; | |
630 else if (pair->key == 3) | |
631 who = pair->value; | |
632 else if (pair->key == 14) | |
633 msg = pair->value; | |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
634 else if (pair->key == 7) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
635 name = pair->value; |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
636 else if (pair->key == 10) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
637 state = strtol(pair->value, NULL, 10); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
638 else if (pair->key == 13) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
639 online = strtol(pair->value, NULL, 10); |
2681 | 640 l = l->next; |
641 } | |
642 | |
2682
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
643 if (id) |
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
644 show_got_added(gc, id, who, NULL, msg); |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
645 if (name) { |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
646 if (state == YAHOO_STATUS_AVAILABLE) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
647 serv_got_update(gc, name, 1, 0, 0, 0, 0, 0); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
648 else if (state == YAHOO_STATUS_IDLE) |
3019 | 649 serv_got_update(gc, name, 1, 0, 0, time(NULL) - 600, (state << 2), 0); |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
650 else |
3019 | 651 serv_got_update(gc, name, 1, 0, 0, 0, (state << 2) | UC_UNAVAILABLE, 0); |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
652 if (state == YAHOO_STATUS_CUSTOM) { |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
653 gpointer val = g_hash_table_lookup(yd->hash, name); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
654 if (val) { |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
655 g_free(val); |
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
656 g_hash_table_insert(yd->hash, name, |
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
657 msg ? g_strdup(msg) : g_malloc0(1)); |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
658 } else |
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
659 g_hash_table_insert(yd->hash, g_strdup(name), |
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
660 msg ? g_strdup(msg) : g_malloc0(1)); |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
661 } |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
662 } |
2681 | 663 } |
664 | |
665 static void yahoo_process_mail(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
666 { | |
667 char *who = NULL; | |
668 char *email = NULL; | |
669 char *subj = NULL; | |
670 int count = 0; | |
671 GSList *l = pkt->hash; | |
672 | |
673 while (l) { | |
674 struct yahoo_pair *pair = l->data; | |
675 if (pair->key == 9) | |
676 count = strtol(pair->value, NULL, 10); | |
677 else if (pair->key == 43) | |
678 who = pair->value; | |
679 else if (pair->key == 42) | |
680 email = pair->value; | |
681 else if (pair->key == 18) | |
682 subj = pair->value; | |
683 l = l->next; | |
684 } | |
685 | |
2850
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
686 if (who && email && subj) { |
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
687 char *from = g_strdup_printf("%s (%s)", who, email); |
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
688 connection_has_mail(gc, -1, from, subj, "http://mail.yahoo.com/"); |
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
689 g_free(from); |
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
690 } else |
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
691 connection_has_mail(gc, count, NULL, NULL, "http://mail.yahoo.com/"); |
2681 | 692 } |
3147 | 693 /* This is the y64 alphabet... it's like base64, but has a . and a _ */ |
694 char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; | |
695 | |
696 /* This is taken from Sylpheed by Hiroyuki Yamamoto. We have our own tobase64 function | |
697 * in util.c, but it has a bug I don't feel like finding right now ;) */ | |
698 void to_y64(unsigned char *out, const unsigned char *in, int inlen) | |
699 /* raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) */ | |
700 { | |
701 for (; inlen >= 3; inlen -= 3) | |
702 { | |
703 *out++ = base64digits[in[0] >> 2]; | |
704 *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)]; | |
705 *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; | |
706 *out++ = base64digits[in[2] & 0x3f]; | |
707 in += 3; | |
708 } | |
709 if (inlen > 0) | |
710 { | |
711 unsigned char fragment; | |
712 | |
713 *out++ = base64digits[in[0] >> 2]; | |
714 fragment = (in[0] << 4) & 0x30; | |
715 if (inlen > 1) | |
716 fragment |= in[1] >> 4; | |
717 *out++ = base64digits[fragment]; | |
718 *out++ = (inlen < 2) ? '-' : base64digits[(in[1] << 2) & 0x3c]; | |
719 *out++ = '-'; | |
720 } | |
721 *out = '\0'; | |
722 } | |
723 | |
724 static void yahoo_process_auth(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
725 { | |
726 char *seed = NULL; | |
727 char *sn = NULL; | |
728 GSList *l = pkt->hash; | |
729 struct yahoo_data *yd = gc->proto_data; | |
730 | |
731 while (l) { | |
732 struct yahoo_pair *pair = l->data; | |
733 if (pair->key == 94) | |
734 seed = pair->value; | |
735 if (pair->key == 1) | |
736 sn = pair->value; | |
737 l = l->next; | |
738 } | |
739 | |
740 if (seed) { | |
741 struct yahoo_packet *pack; | |
742 | |
743 /* So, Yahoo has stopped supporting its older clients in India, and undoubtedly | |
744 * will soon do so in the rest of the world. | |
745 * | |
746 * The new clients use this authentication method. I warn you in advance, it's | |
747 * bizzare, convoluted, inordinately complicated. It's also no more secure than | |
748 * crypt() was. The only purpose this scheme could serve is to prevent third | |
749 * part clients from connecting to their servers. | |
750 * | |
751 * Sorry, Yahoo. | |
752 */ | |
753 | |
754 md5_byte_t result[16]; | |
755 md5_state_t ctx; | |
756 char *crypt_result; | |
757 char *password_hash = g_malloc(25); | |
758 char *crypt_hash = g_malloc(25); | |
759 char *hash_string_p = g_malloc(50 + strlen(sn)); | |
760 char *hash_string_c = g_malloc(50 + strlen(sn)); | |
761 | |
762 char checksum; | |
763 | |
3157 | 764 int sv; |
3147 | 765 |
766 char *result6 = g_malloc(25); | |
767 char *result96 = g_malloc(25); | |
768 | |
769 sv = seed[15]; | |
3157 | 770 sv = sv % 8; |
3147 | 771 |
772 md5_init(&ctx); | |
773 md5_append(&ctx, gc->password, strlen(gc->password)); | |
774 md5_finish(&ctx, result); | |
775 to_y64(password_hash, result, 16); | |
776 | |
777 md5_init(&ctx); | |
778 crypt_result = yahoo_crypt(gc->password, "$1$_2S43d5f$"); | |
779 md5_append(&ctx, crypt_result, strlen(crypt_result)); | |
780 md5_finish(&ctx, result); | |
781 to_y64(crypt_hash, result, 16); | |
3157 | 782 |
783 switch (sv) { | |
3147 | 784 case 1: |
785 case 6: | |
3157 | 786 checksum = seed[seed[9] % 16]; |
3147 | 787 g_snprintf(hash_string_p, strlen(sn) + 50, |
3157 | 788 "%c%s%s%s", checksum, gc->username, seed, password_hash); |
789 g_snprintf(hash_string_c, strlen(sn) + 50, | |
3147 | 790 "%c%s%s%s", checksum, gc->username, seed, crypt_hash); |
791 break; | |
792 case 2: | |
793 case 7: | |
3157 | 794 checksum = seed[seed[15] % 16]; |
3147 | 795 g_snprintf(hash_string_p, strlen(sn) + 50, |
3157 | 796 "%c%s%s%s", checksum, seed, password_hash, gc->username); |
797 g_snprintf(hash_string_c, strlen(sn) + 50, | |
798 "%c%s%s%s", checksum, seed, crypt_hash, gc->username); | |
799 break; | |
3147 | 800 case 3: |
3157 | 801 checksum = seed[seed[1] % 16]; |
3147 | 802 g_snprintf(hash_string_p, strlen(sn) + 50, |
3157 | 803 "%c%s%s%s", checksum, gc->username, password_hash, seed); |
804 g_snprintf(hash_string_c, strlen(sn) + 50, | |
805 "%c%s%s%s", checksum, gc->username, crypt_hash, seed); | |
806 break; | |
807 case 4: | |
808 checksum = seed[seed[3] % 16]; | |
809 g_snprintf(hash_string_p, strlen(sn) + 50, | |
810 "%c%s%s%s", checksum, password_hash, seed, gc->username); | |
3147 | 811 g_snprintf(hash_string_c, strlen(sn) + 50, |
3157 | 812 "%c%s%s%s", checksum, crypt_hash, seed, gc->username); |
813 break; | |
3147 | 814 case 0: |
815 case 5: | |
3157 | 816 checksum = seed[seed[7] % 16]; |
3147 | 817 g_snprintf(hash_string_p, strlen(sn) + 50, |
3157 | 818 "%c%s%s%s", checksum, password_hash, gc->username, seed); |
819 g_snprintf(hash_string_c, strlen(sn) + 50, | |
3147 | 820 "%c%s%s%s", checksum, crypt_hash, gc->username, seed); |
3157 | 821 break; |
3147 | 822 } |
3157 | 823 |
3147 | 824 md5_init(&ctx); |
3157 | 825 md5_append(&ctx, hash_string_p, strlen(hash_string_p)); |
3147 | 826 md5_finish(&ctx, result); |
827 to_y64(result6, result, 16); | |
828 | |
829 md5_init(&ctx); | |
830 md5_append(&ctx, hash_string_c, strlen(hash_string_c)); | |
831 md5_finish(&ctx, result); | |
832 to_y64(result96, result, 16); | |
833 | |
834 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0); | |
835 yahoo_packet_hash(pack, 0, gc->username); | |
836 yahoo_packet_hash(pack, 6, result6); | |
837 yahoo_packet_hash(pack, 96, result96); | |
838 yahoo_packet_hash(pack, 1, gc->username); | |
839 | |
840 yahoo_send_packet(yd, pack); | |
841 | |
3523 | 842 g_free(result6); |
843 g_free(result96); | |
3147 | 844 g_free(password_hash); |
845 g_free(crypt_hash); | |
846 g_free(hash_string_p); | |
847 g_free(hash_string_c); | |
848 | |
849 yahoo_packet_free(pack); | |
850 } | |
851 } | |
2681 | 852 |
853 static void yahoo_packet_process(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
854 { | |
855 switch (pkt->service) | |
856 { | |
857 case YAHOO_SERVICE_LOGON: | |
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
858 case YAHOO_SERVICE_LOGOFF: |
2681 | 859 case YAHOO_SERVICE_ISAWAY: |
2737
f61c1f3a6afa
[gaim-migrate @ 2750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2724
diff
changeset
|
860 case YAHOO_SERVICE_ISBACK: |
3019 | 861 case YAHOO_SERVICE_GAMELOGON: |
862 case YAHOO_SERVICE_GAMELOGOFF: | |
2681 | 863 yahoo_process_status(gc, pkt); |
864 break; | |
3019 | 865 case YAHOO_SERVICE_NOTIFY: |
866 yahoo_process_notify(gc, pkt); | |
2993 | 867 break; |
2681 | 868 case YAHOO_SERVICE_MESSAGE: |
2786
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
869 case YAHOO_SERVICE_GAMEMSG: |
2681 | 870 yahoo_process_message(gc, pkt); |
871 break; | |
872 case YAHOO_SERVICE_NEWMAIL: | |
873 yahoo_process_mail(gc, pkt); | |
874 break; | |
875 case YAHOO_SERVICE_NEWCONTACT: | |
876 yahoo_process_contact(gc, pkt); | |
877 break; | |
878 case YAHOO_SERVICE_LIST: | |
879 yahoo_process_list(gc, pkt); | |
880 break; | |
3147 | 881 case YAHOO_SERVICE_AUTH: |
882 yahoo_process_auth(gc, pkt); | |
883 break; | |
2681 | 884 default: |
2741
38cb5fa48bec
[gaim-migrate @ 2754]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2737
diff
changeset
|
885 debug_printf("unhandled service 0x%02x\n", pkt->service); |
2681 | 886 break; |
887 } | |
888 } | |
889 | |
890 static void yahoo_pending(gpointer data, gint source, GaimInputCondition cond) | |
891 { | |
892 struct gaim_connection *gc = data; | |
893 struct yahoo_data *yd = gc->proto_data; | |
894 char buf[1024]; | |
895 int len; | |
896 | |
3630 | 897 #ifndef _WIN32 |
2681 | 898 len = read(yd->fd, buf, sizeof(buf)); |
3630 | 899 #else |
900 len = recv(yd->fd, buf, sizeof(buf), 0); | |
901 #endif | |
2681 | 902 |
903 if (len <= 0) { | |
3630 | 904 #ifdef _WIN32 |
905 if(len == SOCKET_ERROR) | |
906 debug_printf("Error reading socket: %d\n", WSAGetLastError()); | |
907 else if( len == 0 ) | |
908 debug_printf("Connection was gracefully closed.\n"); | |
909 #endif | |
3074 | 910 hide_login_progress_error(gc, "Unable to read"); |
2681 | 911 signoff(gc); |
912 return; | |
913 } | |
914 | |
915 yd->rxqueue = g_realloc(yd->rxqueue, len + yd->rxlen); | |
916 memcpy(yd->rxqueue + yd->rxlen, buf, len); | |
917 yd->rxlen += len; | |
918 | |
919 while (1) { | |
920 struct yahoo_packet *pkt; | |
921 int pos = 0; | |
922 int pktlen; | |
923 | |
924 if (yd->rxlen < YAHOO_PACKET_HDRLEN) | |
925 return; | |
926 | |
927 pos += 4; /* YMSG */ | |
928 pos += 2; | |
929 pos += 2; | |
930 | |
931 pktlen = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
932 debug_printf("%d bytes to read, rxlen is %d\n", pktlen, yd->rxlen); | |
933 | |
934 if (yd->rxlen < (YAHOO_PACKET_HDRLEN + pktlen)) | |
935 return; | |
936 | |
937 yahoo_packet_dump(yd->rxqueue, YAHOO_PACKET_HDRLEN + pktlen); | |
938 | |
939 pkt = yahoo_packet_new(0, 0, 0); | |
940 | |
941 pkt->service = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
3021 | 942 pkt->status = yahoo_get32(yd->rxqueue + pos); pos += 4; |
2741
38cb5fa48bec
[gaim-migrate @ 2754]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2737
diff
changeset
|
943 debug_printf("Yahoo Service: 0x%02x Status: %d\n", pkt->service, pkt->status); |
2681 | 944 pkt->id = yahoo_get32(yd->rxqueue + pos); pos += 4; |
945 | |
946 yahoo_packet_read(pkt, yd->rxqueue + pos, pktlen); | |
947 | |
948 yd->rxlen -= YAHOO_PACKET_HDRLEN + pktlen; | |
949 if (yd->rxlen) { | |
950 char *tmp = g_memdup(yd->rxqueue + YAHOO_PACKET_HDRLEN + pktlen, yd->rxlen); | |
951 g_free(yd->rxqueue); | |
952 yd->rxqueue = tmp; | |
953 } else { | |
954 g_free(yd->rxqueue); | |
955 yd->rxqueue = NULL; | |
956 } | |
957 | |
958 yahoo_packet_process(gc, pkt); | |
959 | |
960 yahoo_packet_free(pkt); | |
961 } | |
962 } | |
963 | |
964 static void yahoo_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
965 { | |
966 struct gaim_connection *gc = data; | |
967 struct yahoo_data *yd; | |
968 struct yahoo_packet *pkt; | |
969 | |
970 if (!g_slist_find(connections, gc)) { | |
3630 | 971 #ifndef _WIN32 |
2681 | 972 close(source); |
3630 | 973 #else |
974 closesocket(source); | |
975 #endif | |
2681 | 976 return; |
977 } | |
978 | |
979 if (source < 0) { | |
980 hide_login_progress(gc, "Unable to connect"); | |
981 signoff(gc); | |
982 return; | |
983 } | |
984 | |
985 yd = gc->proto_data; | |
986 yd->fd = source; | |
987 | |
3147 | 988 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YAHOO_STATUS_AVAILABLE, 0); |
2681 | 989 |
990 yahoo_packet_hash(pkt, 1, gc->username); | |
991 yahoo_send_packet(yd, pkt); | |
992 | |
993 yahoo_packet_free(pkt); | |
994 | |
995 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | |
996 } | |
997 | |
998 static void yahoo_login(struct aim_user *user) { | |
999 struct gaim_connection *gc = new_gaim_conn(user); | |
1000 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); | |
1001 | |
1002 set_login_progress(gc, 1, "Connecting"); | |
1003 | |
1004 yd->fd = -1; | |
1005 yd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
3019 | 1006 yd->games = g_hash_table_new(g_str_hash, g_str_equal); |
2681 | 1007 |
3193 | 1008 |
1009 if (!g_strncasecmp(user->proto_opt[USEROPT_PAGERHOST], "cs.yahoo.com", strlen("cs.yahoo.com"))) { | |
1010 /* Figured out the new auth method -- cs.yahoo.com likes to disconnect on buddy remove and add now */ | |
2951 | 1011 debug_printf("Setting new Yahoo! server.\n"); |
3193 | 1012 g_snprintf(user->proto_opt[USEROPT_PAGERHOST], strlen("scs.yahoo.com") + 1, "scs.yahoo.com"); |
2951 | 1013 save_prefs(); |
1014 } | |
3147 | 1015 |
1016 | |
2951 | 1017 if (proxy_connect(user->proto_opt[USEROPT_PAGERHOST][0] ? |
2681 | 1018 user->proto_opt[USEROPT_PAGERHOST] : YAHOO_PAGER_HOST, |
1019 user->proto_opt[USEROPT_PAGERPORT][0] ? | |
1020 atoi(user->proto_opt[USEROPT_PAGERPORT]) : YAHOO_PAGER_PORT, | |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2687
diff
changeset
|
1021 yahoo_got_connected, gc) < 0) { |
2681 | 1022 hide_login_progress(gc, "Connection problem"); |
1023 signoff(gc); | |
1024 return; | |
1025 } | |
1026 | |
1027 } | |
1028 | |
1029 static gboolean yahoo_destroy_hash(gpointer key, gpointer val, gpointer data) | |
1030 { | |
1031 g_free(key); | |
1032 g_free(val); | |
1033 return TRUE; | |
1034 } | |
1035 | |
1036 static void yahoo_close(struct gaim_connection *gc) { | |
1037 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1038 g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL); | |
1039 g_hash_table_destroy(yd->hash); | |
3019 | 1040 g_hash_table_foreach_remove(yd->games, yahoo_destroy_hash, NULL); |
1041 g_hash_table_destroy(yd->games); | |
2681 | 1042 if (yd->fd >= 0) |
3630 | 1043 #ifndef _WIN32 |
2681 | 1044 close(yd->fd); |
3630 | 1045 #else |
1046 closesocket(yd->fd); | |
1047 #endif | |
2681 | 1048 if (yd->rxqueue) |
1049 g_free(yd->rxqueue); | |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2686
diff
changeset
|
1050 yd->rxlen = 0; |
2681 | 1051 if (gc->inpa) |
1052 gaim_input_remove(gc->inpa); | |
1053 g_free(yd); | |
1054 } | |
1055 | |
1056 static char **yahoo_list_icon(int uc) | |
1057 { | |
3019 | 1058 if ((uc >> 2) == YAHOO_STATUS_IDLE) |
2681 | 1059 return status_idle_xpm; |
3019 | 1060 else if (uc & UC_UNAVAILABLE) |
1061 return status_away_xpm; | |
1062 else if (uc & YAHOO_STATUS_GAME) | |
1063 return status_game_xpm; | |
1064 return status_here_xpm; | |
2681 | 1065 } |
1066 | |
1067 static char *yahoo_get_status_string(enum yahoo_status a) | |
1068 { | |
1069 switch (a) { | |
1070 case YAHOO_STATUS_BRB: | |
1071 return "Be Right Back"; | |
1072 case YAHOO_STATUS_BUSY: | |
1073 return "Busy"; | |
1074 case YAHOO_STATUS_NOTATHOME: | |
1075 return "Not At Home"; | |
1076 case YAHOO_STATUS_NOTATDESK: | |
1077 return "Not At Desk"; | |
1078 case YAHOO_STATUS_NOTINOFFICE: | |
1079 return "Not In Office"; | |
1080 case YAHOO_STATUS_ONPHONE: | |
1081 return "On Phone"; | |
1082 case YAHOO_STATUS_ONVACATION: | |
1083 return "On Vacation"; | |
1084 case YAHOO_STATUS_OUTTOLUNCH: | |
1085 return "Out To Lunch"; | |
1086 case YAHOO_STATUS_STEPPEDOUT: | |
1087 return "Stepped Out"; | |
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
1088 case YAHOO_STATUS_INVISIBLE: |
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
1089 return "Invisible"; |
2879
5fc5123b7098
[gaim-migrate @ 2892]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2878
diff
changeset
|
1090 default: |
5fc5123b7098
[gaim-migrate @ 2892]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2878
diff
changeset
|
1091 return "Online"; |
2681 | 1092 } |
1093 } | |
1094 | |
3019 | 1095 static void yahoo_game(struct gaim_connection *gc, char *name) { |
1096 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1097 char *game = g_hash_table_lookup(yd->games, name); | |
1098 char *t; | |
1099 char url[256]; | |
1100 | |
1101 if (!game) | |
1102 return; | |
1103 t = game = g_strdup(strstr(game, "ante?room=")); | |
1104 while (*t != '\t') | |
1105 t++; | |
1106 *t = 0; | |
1107 g_snprintf(url, sizeof url, "http://games.yahoo.com/games/%s", game); | |
1108 open_url(NULL, url); | |
1109 g_free(game); | |
1110 } | |
2681 | 1111 static GList *yahoo_buddy_menu(struct gaim_connection *gc, char *who) |
1112 { | |
1113 GList *m = NULL; | |
1114 struct proto_buddy_menu *pbm; | |
1115 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1116 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, | |
1117 segfault and get the bug report. */ | |
1118 static char buf[1024]; | |
3019 | 1119 static char buf2[1024]; |
1120 | |
1121 if (b->uc & UC_UNAVAILABLE && b->uc >> 2 != YAHOO_STATUS_IDLE) { | |
1122 pbm = g_new0(struct proto_buddy_menu, 1); | |
1123 if ((b->uc >> 2) != YAHOO_STATUS_CUSTOM) | |
1124 g_snprintf(buf, sizeof buf, | |
1125 "Status: %s", yahoo_get_status_string(b->uc >> 2)); | |
1126 else | |
1127 g_snprintf(buf, sizeof buf, "Custom Status: %s", | |
1128 (char *)g_hash_table_lookup(yd->hash, b->name)); | |
1129 pbm->label = buf; | |
1130 pbm->callback = NULL; | |
1131 pbm->gc = gc; | |
1132 m = g_list_append(m, pbm); | |
1133 } | |
1134 | |
1135 if (b->uc | YAHOO_STATUS_GAME) { | |
1136 char *game = g_hash_table_lookup(yd->games, b->name); | |
1137 char *room; | |
1138 if (!game) | |
1139 return m; | |
1140 if (game) { | |
1141 char *t; | |
1142 pbm = g_new0(struct proto_buddy_menu, 1); | |
1143 if (!(room = strstr(game, "&follow="))) /* skip ahead to the url */ | |
1144 return NULL; | |
1145 while (*room && *room != '\t') /* skip to the tab */ | |
1146 room++; | |
1147 t = room++; /* room as now at the name */ | |
1148 while (*t != '\n') | |
1149 t++; /* replace the \n with a space */ | |
1150 *t = ' '; | |
1151 g_snprintf(buf2, sizeof buf2, "%s", room); | |
1152 pbm->label = buf2; | |
1153 pbm->callback = yahoo_game; | |
1154 pbm->gc = gc; | |
1155 m = g_list_append(m, pbm); | |
1156 } | |
1157 } | |
2681 | 1158 |
1159 return m; | |
1160 } | |
1161 | |
1162 static void yahoo_act_id(gpointer data, char *entry) | |
1163 { | |
1164 struct gaim_connection *gc = data; | |
1165 struct yahoo_data *yd = gc->proto_data; | |
1166 | |
1167 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0); | |
1168 yahoo_packet_hash(pkt, 3, entry); | |
1169 yahoo_send_packet(yd, pkt); | |
1170 yahoo_packet_free(pkt); | |
1171 | |
1172 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", entry); | |
1173 } | |
1174 | |
1175 static void yahoo_do_action(struct gaim_connection *gc, char *act) | |
1176 { | |
1177 if (!strcmp(act, "Activate ID")) { | |
1178 do_prompt_dialog("Activate which ID:", gc->displayname, gc, yahoo_act_id, NULL); | |
1179 } | |
1180 } | |
1181 | |
1182 static GList *yahoo_actions() { | |
1183 GList *m = NULL; | |
1184 | |
1185 m = g_list_append(m, "Activate ID"); | |
1186 | |
1187 return m; | |
1188 } | |
1189 | |
3033 | 1190 static int yahoo_send_im(struct gaim_connection *gc, char *who, char *what, int len, int flags) |
2681 | 1191 { |
1192 struct yahoo_data *yd = gc->proto_data; | |
1193 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0); | |
3493 | 1194 char *msg = str_to_utf8(what); |
2681 | 1195 |
1196 yahoo_packet_hash(pkt, 1, gc->displayname); | |
1197 yahoo_packet_hash(pkt, 5, who); | |
3493 | 1198 yahoo_packet_hash(pkt, 14, msg); |
2681 | 1199 |
1200 yahoo_send_packet(yd, pkt); | |
1201 | |
1202 yahoo_packet_free(pkt); | |
3493 | 1203 |
2681 | 1204 return 1; |
1205 } | |
1206 | |
3001 | 1207 int yahoo_send_typing(struct gaim_connection *gc, char *who, int typ) |
2993 | 1208 { |
1209 struct yahoo_data *yd = gc->proto_data; | |
3019 | 1210 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0); |
2993 | 1211 yahoo_packet_hash(pkt, 49, "TYPING"); |
1212 yahoo_packet_hash(pkt, 1, gc->displayname); | |
1213 yahoo_packet_hash(pkt, 14, " "); | |
3596 | 1214 yahoo_packet_hash(pkt, 13, typ == TYPING ? "1" : "0"); |
2993 | 1215 yahoo_packet_hash(pkt, 5, who); |
1216 yahoo_packet_hash(pkt, 1002, "1"); | |
1217 | |
1218 yahoo_send_packet(yd, pkt); | |
1219 | |
1220 yahoo_packet_free(pkt); | |
1221 | |
3001 | 1222 return 0; |
2993 | 1223 } |
1224 | |
2681 | 1225 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) |
1226 { | |
1227 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1228 struct yahoo_packet *pkt; | |
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1229 int service; |
2681 | 1230 char s[4]; |
1231 | |
1232 gc->away = NULL; | |
1233 | |
1234 if (msg) { | |
1235 yd->current_status = YAHOO_STATUS_CUSTOM; | |
1236 gc->away = ""; | |
1237 } else if (state) { | |
1238 gc->away = ""; | |
1239 if (!strcmp(state, "Available")) { | |
1240 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
1241 gc->away = NULL; | |
1242 } else if (!strcmp(state, "Be Right Back")) { | |
1243 yd->current_status = YAHOO_STATUS_BRB; | |
1244 } else if (!strcmp(state, "Busy")) { | |
1245 yd->current_status = YAHOO_STATUS_BUSY; | |
1246 } else if (!strcmp(state, "Not At Home")) { | |
1247 yd->current_status = YAHOO_STATUS_NOTATHOME; | |
1248 } else if (!strcmp(state, "Not At Desk")) { | |
1249 yd->current_status = YAHOO_STATUS_NOTATDESK; | |
1250 } else if (!strcmp(state, "Not In Office")) { | |
1251 yd->current_status = YAHOO_STATUS_NOTINOFFICE; | |
1252 } else if (!strcmp(state, "On Phone")) { | |
1253 yd->current_status = YAHOO_STATUS_ONPHONE; | |
1254 } else if (!strcmp(state, "On Vacation")) { | |
1255 yd->current_status = YAHOO_STATUS_ONVACATION; | |
1256 } else if (!strcmp(state, "Out To Lunch")) { | |
1257 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; | |
1258 } else if (!strcmp(state, "Stepped Out")) { | |
1259 yd->current_status = YAHOO_STATUS_STEPPEDOUT; | |
1260 } else if (!strcmp(state, "Invisible")) { | |
1261 yd->current_status = YAHOO_STATUS_INVISIBLE; | |
1262 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
1263 if (gc->is_idle) { | |
1264 yd->current_status = YAHOO_STATUS_IDLE; | |
1265 } else { | |
1266 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
1267 } | |
1268 gc->away = NULL; | |
1269 } | |
1270 } else if (gc->is_idle) { | |
1271 yd->current_status = YAHOO_STATUS_IDLE; | |
1272 } else { | |
1273 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
1274 } | |
1275 | |
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1276 if (yd->current_status == YAHOO_STATUS_AVAILABLE) |
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1277 service = YAHOO_SERVICE_ISBACK; |
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1278 else |
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1279 service = YAHOO_SERVICE_ISAWAY; |
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1280 pkt = yahoo_packet_new(service, yd->current_status, 0); |
2681 | 1281 g_snprintf(s, sizeof(s), "%d", yd->current_status); |
1282 yahoo_packet_hash(pkt, 10, s); | |
1283 if (yd->current_status == YAHOO_STATUS_CUSTOM) | |
1284 yahoo_packet_hash(pkt, 19, msg); | |
1285 | |
1286 yahoo_send_packet(yd, pkt); | |
1287 yahoo_packet_free(pkt); | |
1288 } | |
1289 | |
1290 static void yahoo_set_idle(struct gaim_connection *gc, int idle) | |
1291 { | |
1292 struct yahoo_data *yd = gc->proto_data; | |
1293 struct yahoo_packet *pkt = NULL; | |
1294 | |
1295 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
1296 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_IDLE, 0); | |
1297 yd->current_status = YAHOO_STATUS_IDLE; | |
1298 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
1299 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); | |
1300 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
1301 } | |
1302 | |
1303 if (pkt) { | |
1304 char buf[4]; | |
1305 g_snprintf(buf, sizeof(buf), "%d", yd->current_status); | |
1306 yahoo_packet_hash(pkt, 10, buf); | |
1307 yahoo_send_packet(yd, pkt); | |
1308 yahoo_packet_free(pkt); | |
1309 } | |
1310 } | |
1311 | |
1312 static GList *yahoo_away_states(struct gaim_connection *gc) | |
1313 { | |
1314 GList *m = NULL; | |
1315 | |
1316 m = g_list_append(m, "Available"); | |
1317 m = g_list_append(m, "Be Right Back"); | |
1318 m = g_list_append(m, "Busy"); | |
1319 m = g_list_append(m, "Not At Home"); | |
1320 m = g_list_append(m, "Not At Desk"); | |
1321 m = g_list_append(m, "Not In Office"); | |
1322 m = g_list_append(m, "On Phone"); | |
1323 m = g_list_append(m, "On Vacation"); | |
1324 m = g_list_append(m, "Out To Lunch"); | |
1325 m = g_list_append(m, "Stepped Out"); | |
1326 m = g_list_append(m, "Invisible"); | |
1327 m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
1328 | |
1329 return m; | |
1330 } | |
1331 | |
1332 static void yahoo_keepalive(struct gaim_connection *gc) | |
1333 { | |
1334 struct yahoo_data *yd = gc->proto_data; | |
1335 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0); | |
1336 yahoo_send_packet(yd, pkt); | |
1337 yahoo_packet_free(pkt); | |
1338 } | |
1339 | |
3466 | 1340 static void yahoo_add_buddy(struct gaim_connection *gc, const char *who) |
2681 | 1341 { |
1342 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1343 struct yahoo_packet *pkt; | |
1344 struct group *g; | |
1345 char *group = NULL; | |
1346 | |
1347 if (!yd->logged_in) | |
1348 return; | |
1349 | |
1350 g = find_group_by_buddy(gc, who); | |
1351 if (g) | |
1352 group = g->name; | |
1353 else | |
1354 group = "Buddies"; | |
1355 | |
1356 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
1357 yahoo_packet_hash(pkt, 1, gc->displayname); | |
1358 yahoo_packet_hash(pkt, 7, who); | |
1359 yahoo_packet_hash(pkt, 65, group); | |
1360 yahoo_send_packet(yd, pkt); | |
1361 yahoo_packet_free(pkt); | |
1362 } | |
1363 | |
1364 static void yahoo_remove_buddy(struct gaim_connection *gc, char *who, char *group) | |
1365 { | |
1366 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1367 | |
1368 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
1369 yahoo_packet_hash(pkt, 1, gc->displayname); | |
1370 yahoo_packet_hash(pkt, 7, who); | |
1371 yahoo_packet_hash(pkt, 65, group); | |
1372 yahoo_send_packet(yd, pkt); | |
1373 yahoo_packet_free(pkt); | |
1374 } | |
1375 | |
3035 | 1376 |
1377 GSList *yahoo_smiley_list() | |
1378 { | |
1379 GSList *smilies = NULL; | |
1380 | |
1381 smilies = add_smiley(smilies, "=:)", yahoo_alien, 1); | |
1382 smilies = add_smiley(smilies, "=:-)", yahoo_alien, 0); | |
1383 smilies = add_smiley(smilies, "o:)", yahoo_angel, 0); | |
1384 smilies = add_smiley(smilies, "o:-)", yahoo_angel, 0); | |
1385 smilies = add_smiley(smilies, "0:)", yahoo_angel, 0); | |
1386 smilies = add_smiley(smilies, "0:-)", yahoo_angel, 0); | |
1387 smilies = add_smiley(smilies, "X-(", yahoo_angry, 1); | |
1388 smilies = add_smiley(smilies, "X(", yahoo_angry, 0); | |
1389 smilies = add_smiley(smilies, "x-(", yahoo_angry, 0); | |
1390 smilies = add_smiley(smilies, "x(", yahoo_angry, 0); | |
1391 smilies = add_smiley(smilies, ":D", yahoo_bigsmile, 1); | |
1392 smilies = add_smiley(smilies, ":-D", yahoo_bigsmile, 0); | |
1393 smilies = add_smiley(smilies, ":\">", yahoo_blush, 1); | |
1394 smilies = add_smiley(smilies, "=;", yahoo_bye, 1); | |
1395 smilies = add_smiley(smilies, ":o)", yahoo_clown, 1); | |
1396 smilies = add_smiley(smilies, ":0)", yahoo_clown, 0); | |
1397 smilies = add_smiley(smilies, ":O)", yahoo_clown, 0); | |
1398 smilies = add_smiley(smilies, "<@:)", yahoo_clown, 0); | |
1399 smilies = add_smiley(smilies, "3:-0", yahoo_cow, 1); | |
1400 smilies = add_smiley(smilies, "3:-o", yahoo_cow, 0); | |
1401 smilies = add_smiley(smilies, "3:-O", yahoo_cow, 0); | |
1402 smilies = add_smiley(smilies, "3:O", yahoo_cow, 0); | |
1403 smilies = add_smiley(smilies, "<):)", yahoo_cowboy, 1); | |
1404 smilies = add_smiley(smilies, ":((", yahoo_cry, 1); | |
1405 smilies = add_smiley(smilies, ":-((", yahoo_cry, 0); | |
1406 smilies = add_smiley(smilies, ">:)", yahoo_devil, 1); | |
1407 smilies = add_smiley(smilies, "@};-", yahoo_flower, 1); | |
1408 smilies = add_smiley(smilies, "8-X", yahoo_ghost, 1); | |
1409 smilies = add_smiley(smilies, ":B", yahoo_glasses, 1); | |
1410 smilies = add_smiley(smilies, ":-B", yahoo_glasses, 0); | |
1411 smilies = add_smiley(smilies, ":))", yahoo_laughloud, 1); | |
1412 smilies = add_smiley(smilies, ":-))", yahoo_laughloud, 0); | |
1413 smilies = add_smiley(smilies, ":x", yahoo_love, 1); | |
1414 smilies = add_smiley(smilies, ":-x", yahoo_love, 0); | |
1415 smilies = add_smiley(smilies, ":X", yahoo_love, 0); | |
1416 smilies = add_smiley(smilies, ":-X", yahoo_love, 0); | |
1417 smilies = add_smiley(smilies, ":>", yahoo_mean, 1); | |
1418 smilies = add_smiley(smilies, ":->", yahoo_mean, 0); | |
1419 smilies = add_smiley(smilies, ":|", yahoo_neutral, 1); | |
1420 smilies = add_smiley(smilies, ":-|", yahoo_neutral, 0); | |
1421 smilies = add_smiley(smilies, ":O", yahoo_ooooh, 1); | |
1422 smilies = add_smiley(smilies, ":-O", yahoo_ooooh, 0); | |
1423 smilies = add_smiley(smilies, ":-\\", yahoo_question, 1); | |
1424 smilies = add_smiley(smilies, ":-/", yahoo_question, 0); | |
1425 smilies = add_smiley(smilies, ":(", yahoo_sad, 1); | |
1426 smilies = add_smiley(smilies, ":-(", yahoo_sad, 0); | |
1427 smilies = add_smiley(smilies, "I-)", yahoo_sleep, 1); | |
1428 smilies = add_smiley(smilies, "|-)", yahoo_sleep, 0); | |
1429 smilies = add_smiley(smilies, "I-|", yahoo_sleep, 0); | |
1430 smilies = add_smiley(smilies, ":)", yahoo_smiley, 1); | |
1431 smilies = add_smiley(smilies, ":-)", yahoo_smiley, 0); | |
1432 smilies = add_smiley(smilies, "(:", yahoo_smiley, 0); | |
1433 smilies = add_smiley(smilies, "(-:", yahoo_smiley, 0); | |
1434 smilies = add_smiley(smilies, "B-)", yahoo_sunglas, 1); | |
1435 smilies = add_smiley(smilies, ":-p", yahoo_tongue, 1); | |
1436 smilies = add_smiley(smilies, ":p", yahoo_tongue, 0); | |
1437 smilies = add_smiley(smilies, ":P", yahoo_tongue, 0); | |
1438 smilies = add_smiley(smilies, ":-P", yahoo_tongue, 0); | |
1439 smilies = add_smiley(smilies, ";)", yahoo_wink, 1); | |
1440 smilies = add_smiley(smilies, ";-)", yahoo_wink, 0); | |
1441 | |
1442 | |
1443 return smilies; | |
1444 } | |
1445 | |
2681 | 1446 static struct prpl *my_protocol = NULL; |
1447 | |
3630 | 1448 G_MODULE_EXPORT void yahoo_init(struct prpl *ret) { |
3572 | 1449 struct proto_user_opt *puo; |
2681 | 1450 ret->protocol = PROTO_YAHOO; |
1451 ret->options = OPT_PROTO_MAIL_CHECK; | |
3572 | 1452 ret->name = g_strdup("Yahoo"); |
2681 | 1453 ret->login = yahoo_login; |
1454 ret->close = yahoo_close; | |
1455 ret->buddy_menu = yahoo_buddy_menu; | |
1456 ret->list_icon = yahoo_list_icon; | |
1457 ret->actions = yahoo_actions; | |
1458 ret->do_action = yahoo_do_action; | |
1459 ret->send_im = yahoo_send_im; | |
1460 ret->away_states = yahoo_away_states; | |
1461 ret->set_away = yahoo_set_away; | |
1462 ret->set_idle = yahoo_set_idle; | |
1463 ret->keepalive = yahoo_keepalive; | |
1464 ret->add_buddy = yahoo_add_buddy; | |
1465 ret->remove_buddy = yahoo_remove_buddy; | |
2993 | 1466 ret->send_typing = yahoo_send_typing; |
3035 | 1467 ret->smiley_list = yahoo_smiley_list; |
2681 | 1468 |
3572 | 1469 puo = g_new0(struct proto_user_opt, 1); |
1470 puo->label = g_strdup("Pager Host:"); | |
1471 puo->def = g_strdup(YAHOO_PAGER_HOST); | |
1472 puo->pos = USEROPT_PAGERHOST; | |
1473 ret->user_opts = g_list_append(ret->user_opts, puo); | |
1474 | |
1475 puo = g_new0(struct proto_user_opt, 1); | |
1476 puo->label = g_strdup("Pager Port:"); | |
1477 puo->def = g_strdup("5050"); | |
1478 puo->pos = USEROPT_PAGERPORT; | |
1479 ret->user_opts = g_list_append(ret->user_opts, puo); | |
1480 | |
2681 | 1481 my_protocol = ret; |
1482 } | |
1483 | |
1484 #ifndef STATIC | |
1485 | |
3630 | 1486 G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl) |
2681 | 1487 { |
3572 | 1488 yahoo_init(prpl); |
1489 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
2681 | 1490 } |
1491 | |
1492 #endif |