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