Mercurial > pidgin
annotate src/protocols/yahoo/yahoo.c @ 2697:7759f914a009
[gaim-migrate @ 2710]
maybe this will fix some things
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 08 Nov 2001 09:44:36 +0000 |
parents | 98b1ac8ddea3 |
children | 94b4271b9567 |
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 <crypt.h> | |
41 #include "multi.h" | |
42 #include "prpl.h" | |
43 #include "gaim.h" | |
44 #include "proxy.h" | |
45 | |
46 #include "pixmaps/status-away.xpm" | |
47 #include "pixmaps/status-here.xpm" | |
48 #include "pixmaps/status-idle.xpm" | |
49 | |
2682
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
50 #undef YAHOO_DEBUG |
2681 | 51 |
52 #define USEROPT_MAIL 0 | |
53 | |
54 #define USEROPT_PAGERHOST 3 | |
55 #define YAHOO_PAGER_HOST "scs.yahoo.com" | |
56 #define USEROPT_PAGERPORT 4 | |
57 #define YAHOO_PAGER_PORT 5050 | |
58 | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
59 enum yahoo_service { /* these are easier to see in hex */ |
2681 | 60 YAHOO_SERVICE_LOGON = 1, |
61 YAHOO_SERVICE_LOGOFF, | |
62 YAHOO_SERVICE_ISAWAY, | |
63 YAHOO_SERVICE_ISBACK, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
64 YAHOO_SERVICE_IDLE, /* 5 (placemarker) */ |
2681 | 65 YAHOO_SERVICE_MESSAGE, |
66 YAHOO_SERVICE_IDACT, | |
67 YAHOO_SERVICE_IDDEACT, | |
68 YAHOO_SERVICE_MAILSTAT, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
69 YAHOO_SERVICE_USERSTAT, /* 0xa */ |
2681 | 70 YAHOO_SERVICE_NEWMAIL, |
71 YAHOO_SERVICE_CHATINVITE, | |
72 YAHOO_SERVICE_CALENDAR, | |
73 YAHOO_SERVICE_NEWPERSONALMAIL, | |
74 YAHOO_SERVICE_NEWCONTACT, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
75 YAHOO_SERVICE_ADDIDENT, /* 0x10 */ |
2681 | 76 YAHOO_SERVICE_ADDIGNORE, |
77 YAHOO_SERVICE_PING, | |
78 YAHOO_SERVICE_GROUPRENAME, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
79 YAHOO_SERVICE_SYSMESSAGE = 0x14, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
80 YAHOO_SERVICE_PASSTHROUGH2 = 0x16, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
81 YAHOO_SERVICE_CONFINVITE = 0x18, |
2681 | 82 YAHOO_SERVICE_CONFLOGON, |
83 YAHOO_SERVICE_CONFDECLINE, | |
84 YAHOO_SERVICE_CONFLOGOFF, | |
85 YAHOO_SERVICE_CONFADDINVITE, | |
86 YAHOO_SERVICE_CONFMSG, | |
87 YAHOO_SERVICE_CHATLOGON, | |
88 YAHOO_SERVICE_CHATLOGOFF, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
89 YAHOO_SERVICE_CHATMSG = 0x20, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
90 YAHOO_SERVICE_GAMELOGON = 0x28, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
91 YAHOO_SERVICE_GAMELOGOFF = 0x29, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
92 YAHOO_SERVICE_FILETRANSFER = 0x46, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
93 YAHOO_SERVICE_LIST = 0x55, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
94 YAHOO_SERVICE_ADDBUDDY = 0x83, |
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
95 YAHOO_SERVICE_REMBUDDY = 0x84 |
2681 | 96 }; |
97 | |
98 enum yahoo_status { | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
99 YAHOO_STATUS_AVAILABLE = 0, |
2681 | 100 YAHOO_STATUS_BRB, |
101 YAHOO_STATUS_BUSY, | |
102 YAHOO_STATUS_NOTATHOME, | |
103 YAHOO_STATUS_NOTATDESK, | |
104 YAHOO_STATUS_NOTINOFFICE, | |
105 YAHOO_STATUS_ONPHONE, | |
106 YAHOO_STATUS_ONVACATION, | |
107 YAHOO_STATUS_OUTTOLUNCH, | |
108 YAHOO_STATUS_STEPPEDOUT, | |
109 YAHOO_STATUS_INVISIBLE = 12, | |
110 YAHOO_STATUS_CUSTOM = 99, | |
111 YAHOO_STATUS_IDLE = 999, | |
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
112 YAHOO_STATUS_OFFLINE = 0x5a55aa56 /* don't ask */ |
2681 | 113 }; |
114 | |
115 struct yahoo_data { | |
116 int fd; | |
117 guchar *rxqueue; | |
118 int rxlen; | |
119 GHashTable *hash; | |
120 GSList *login; | |
121 int current_status; | |
122 gboolean logged_in; | |
123 }; | |
124 | |
125 struct yahoo_pair { | |
126 int key; | |
127 char *value; | |
128 }; | |
129 | |
130 struct yahoo_packet { | |
131 guint16 service; | |
132 guint32 status; | |
133 guint32 id; | |
134 GSList *hash; | |
135 }; | |
136 | |
137 struct yahoo_buddy { | |
138 char *name; | |
139 int state; | |
140 char *msg; | |
141 }; | |
142 | |
143 static char *yahoo_name() { | |
144 return "Yahoo"; | |
145 } | |
146 | |
147 #define YAHOO_PACKET_HDRLEN (4 + 2 + 2 + 2 + 2 + 4 + 4) | |
148 | |
149 static struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id) | |
150 { | |
151 struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1); | |
152 | |
153 pkt->service = service; | |
154 pkt->status = status; | |
155 pkt->id = id; | |
156 | |
157 return pkt; | |
158 } | |
159 | |
160 static void yahoo_packet_hash(struct yahoo_packet *pkt, int key, char *value) | |
161 { | |
162 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
163 pair->key = key; | |
164 pair->value = g_strdup(value); | |
165 pkt->hash = g_slist_append(pkt->hash, pair); | |
166 } | |
167 | |
168 static int yahoo_packet_length(struct yahoo_packet *pkt) | |
169 { | |
170 GSList *l; | |
171 | |
172 int len = 0; | |
173 | |
174 l = pkt->hash; | |
175 while (l) { | |
176 struct yahoo_pair *pair = l->data; | |
177 int tmp = pair->key; | |
178 do { | |
179 tmp /= 10; | |
180 len++; | |
181 } while (tmp); | |
182 len += 2; | |
183 len += strlen(pair->value); | |
184 len += 2; | |
185 l = l->next; | |
186 } | |
187 | |
188 return len; | |
189 } | |
190 | |
191 /* sometimes i wish prpls could #include things from other prpls. then i could just | |
192 * use the routines from libfaim and not have to admit to knowing how they work. */ | |
193 #define yahoo_put16(buf, data) ( \ | |
194 (*(buf) = (u_char)((data)>>8)&0xff), \ | |
195 (*((buf)+1) = (u_char)(data)&0xff), \ | |
196 2) | |
197 #define yahoo_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff)) | |
198 #define yahoo_put32(buf, data) ( \ | |
199 (*((buf)) = (u_char)((data)>>24)&0xff), \ | |
200 (*((buf)+1) = (u_char)((data)>>16)&0xff), \ | |
201 (*((buf)+2) = (u_char)((data)>>8)&0xff), \ | |
202 (*((buf)+3) = (u_char)(data)&0xff), \ | |
203 4) | |
204 #define yahoo_get32(buf) ((((*(buf))<<24)&0xff000000) + \ | |
205 (((*((buf)+1))<<16)&0x00ff0000) + \ | |
206 (((*((buf)+2))<< 8)&0x0000ff00) + \ | |
207 (((*((buf)+3) )&0x000000ff))) | |
208 | |
209 static void yahoo_packet_read(struct yahoo_packet *pkt, guchar *data, int len) | |
210 { | |
211 int pos = 0; | |
212 | |
213 while (pos + 1 < len) { | |
214 char key[64], *value; | |
215 int x; | |
216 | |
217 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
218 pkt->hash = g_slist_append(pkt->hash, pair); | |
219 | |
220 x = 0; | |
221 while (pos + 1 < len) { | |
222 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
223 break; | |
224 key[x++] = data[pos++]; | |
225 } | |
226 key[x] = 0; | |
227 pos += 2; | |
228 pair->key = strtol(key, NULL, 10); | |
229 | |
230 value = g_malloc(len - pos); | |
231 x = 0; | |
232 while (pos + 1 < len) { | |
233 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
234 break; | |
235 value[x++] = data[pos++]; | |
236 } | |
237 value[x] = 0; | |
238 pos += 2; | |
239 pair->value = g_strdup(value); | |
240 g_free(value); | |
241 debug_printf("Key: %d \tValue: %s\n", pair->key, pair->value); | |
242 } | |
243 } | |
244 | |
245 static void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data) | |
246 { | |
247 GSList *l = pkt->hash; | |
248 int pos = 0; | |
249 | |
250 while (l) { | |
251 struct yahoo_pair *pair = l->data; | |
252 guchar buf[100]; | |
253 | |
254 g_snprintf(buf, sizeof(buf), "%d", pair->key); | |
255 strcpy(data + pos, buf); | |
256 pos += strlen(buf); | |
257 data[pos++] = 0xc0; | |
258 data[pos++] = 0x80; | |
259 | |
260 strcpy(data + pos, pair->value); | |
261 pos += strlen(pair->value); | |
262 data[pos++] = 0xc0; | |
263 data[pos++] = 0x80; | |
264 | |
265 l = l->next; | |
266 } | |
267 } | |
268 | |
269 static void yahoo_packet_dump(guchar *data, int len) | |
270 { | |
271 #ifdef YAHOO_DEBUG | |
272 int i; | |
273 for (i = 0; i + 1 < len; i += 2) { | |
274 if ((i % 16 == 0) && i) | |
275 debug_printf("\n"); | |
276 debug_printf("%02x", data[i]); | |
277 debug_printf("%02x ", data[i+1]); | |
278 } | |
279 if (i < len) | |
280 debug_printf("%02x", data[i]); | |
281 debug_printf("\n"); | |
282 for (i = 0; i < len; i++) { | |
283 if ((i % 16 == 0) && i) | |
284 debug_printf("\n"); | |
285 if (isprint(data[i])) | |
286 debug_printf("%c ", data[i]); | |
287 else | |
288 debug_printf(". "); | |
289 } | |
290 debug_printf("\n"); | |
291 #endif | |
292 } | |
293 | |
294 static int yahoo_send_packet(struct yahoo_data *yd, struct yahoo_packet *pkt) | |
295 { | |
296 int pktlen = yahoo_packet_length(pkt); | |
297 int len = YAHOO_PACKET_HDRLEN + pktlen; | |
298 int ret; | |
299 | |
300 guchar *data; | |
301 int pos = 0; | |
302 | |
303 if (yd->fd < 0) | |
304 return -1; | |
305 | |
306 data = g_malloc0(len + 1); | |
307 | |
308 memcpy(data + pos, "YMSG", 4); pos += 4; | |
309 pos += yahoo_put16(data + pos, 0x0600); | |
310 pos += yahoo_put16(data + pos, 0x0000); | |
311 pos += yahoo_put16(data + pos, pktlen); | |
312 pos += yahoo_put16(data + pos, pkt->service); | |
313 pos += yahoo_put32(data + pos, pkt->status); | |
314 pos += yahoo_put32(data + pos, pkt->id); | |
315 | |
316 yahoo_packet_write(pkt, data + pos); | |
317 | |
318 yahoo_packet_dump(data, len); | |
319 ret = write(yd->fd, data, len); | |
320 | |
321 g_free(data); | |
322 | |
323 return ret; | |
324 } | |
325 | |
326 static void yahoo_packet_free(struct yahoo_packet *pkt) | |
327 { | |
328 while (pkt->hash) { | |
329 struct yahoo_pair *pair = pkt->hash->data; | |
330 g_free(pair->value); | |
331 g_free(pair); | |
332 pkt->hash = g_slist_remove(pkt->hash, pair); | |
333 } | |
334 g_free(pkt); | |
335 } | |
336 | |
337 static void yahoo_process_logon(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
338 { | |
339 struct yahoo_data *yd = gc->proto_data; | |
340 GSList *l = pkt->hash; | |
341 struct yahoo_buddy *buddy = NULL; | |
342 struct yahoo_packet *newpkt; | |
343 char *name = NULL; | |
344 int state = 0; | |
345 char *msg = NULL; | |
346 | |
347 while (l) { | |
348 struct yahoo_pair *pair = l->data; | |
349 | |
350 switch (pair->key) { | |
351 case 0: /* we won't actually do anything with this */ | |
352 break; | |
353 case 1: /* we don't get the full buddy list here. */ | |
354 account_online(gc); | |
355 serv_finish_login(gc); | |
356 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", pair->value); | |
357 do_import(gc, NULL); | |
358 yd->logged_in = TRUE; | |
359 | |
360 /* this requests the list. i have a feeling that this is very evil */ | |
361 newpkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_OFFLINE, 0); | |
362 yahoo_send_packet(yd, newpkt); | |
363 yahoo_packet_free(newpkt); | |
364 | |
365 break; | |
366 case 8: /* how many online buddies we have */ | |
367 break; | |
368 case 7: /* the current buddy */ | |
369 name = pair->value; | |
370 break; | |
371 case 10: /* state */ | |
372 state = strtol(pair->value, NULL, 10); | |
373 break; | |
374 case 19: /* custom message */ | |
375 msg = pair->value; | |
376 break; | |
377 case 11: /* i didn't know what this was in the old protocol either */ | |
378 break; | |
379 case 17: /* in chat? */ | |
380 break; | |
381 case 13: /* in pager, i think this should always be 1 */ | |
382 /* we don't actually give notification here. we wait until after we've | |
383 * gotten the list, so that they get added to the right group */ | |
384 buddy = g_new0(struct yahoo_buddy, 1); | |
385 buddy->name = g_strdup(name); | |
386 buddy->state = state; | |
387 buddy->msg = msg ? g_strdup(msg) : NULL; | |
388 yd->login = g_slist_append(yd->login, buddy); | |
389 break; | |
390 default: | |
391 debug_printf("unknown login key %d\n", pair->key); | |
392 break; | |
393 } | |
394 | |
395 l = l->next; | |
396 } | |
397 } | |
398 | |
399 static void yahoo_process_list(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
400 { | |
401 struct yahoo_data *yd = gc->proto_data; | |
402 GSList *l = pkt->hash; | |
403 gboolean export = FALSE; | |
404 | |
405 while (l) { | |
406 char **lines; | |
407 char **split; | |
408 char **buddies; | |
409 char **tmp, **bud; | |
410 | |
411 struct yahoo_pair *pair = l->data; | |
412 l = l->next; | |
413 | |
414 if (pair->key != 87) | |
415 continue; | |
416 | |
417 lines = g_strsplit(pair->value, "\n", -1); | |
418 for (tmp = lines; *tmp; tmp++) { | |
419 split = g_strsplit(*tmp, ":", 2); | |
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
420 if (!split) |
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
421 continue; |
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
422 if (!split[1]) { |
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
423 g_strfreev(split); |
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
424 continue; |
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
425 } |
2681 | 426 buddies = g_strsplit(split[1], ",", -1); |
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
427 for (bud = buddies; bud && *bud; bud++) |
2681 | 428 if (!find_buddy(gc, *bud)) { |
429 add_buddy(gc, split[0], *bud, *bud); | |
430 export = TRUE; | |
431 } | |
432 g_strfreev(buddies); | |
433 g_strfreev(split); | |
434 } | |
435 g_strfreev(lines); | |
436 } | |
437 | |
438 if (export) | |
439 do_export(gc); | |
440 | |
441 while (yd->login) { | |
442 struct yahoo_buddy *buddy = yd->login->data; | |
443 int status = buddy->state; | |
444 yd->login = g_slist_remove(yd->login, buddy); | |
445 if (status == YAHOO_STATUS_AVAILABLE) | |
446 serv_got_update(gc, buddy->name, 1, 0, 0, 0, 0, 0); | |
447 else if (status == YAHOO_STATUS_IDLE) | |
448 serv_got_update(gc, buddy->name, 1, 0, 0, time(NULL) - 600, (status << 1), 0); | |
449 else | |
450 serv_got_update(gc, buddy->name, 1, 0, 0, 0, (status << 1) | UC_UNAVAILABLE, 0); | |
451 if (status == YAHOO_STATUS_CUSTOM) { | |
452 gpointer val = g_hash_table_lookup(yd->hash, buddy->name); | |
453 if (val) { | |
454 g_free(val); | |
455 g_hash_table_insert(yd->hash, buddy->name, g_strdup(buddy->msg)); | |
456 } else | |
457 g_hash_table_insert(yd->hash, g_strdup(buddy->name), g_strdup(buddy->msg)); | |
458 } | |
459 g_free(buddy->msg); | |
460 g_free(buddy->name); | |
461 g_free(buddy); | |
462 } | |
463 } | |
464 | |
465 static void yahoo_process_message(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
466 { | |
467 char *msg = NULL; | |
468 char *from = NULL; | |
469 time_t tm = time(NULL); | |
470 GSList *l = pkt->hash; | |
471 | |
472 while (l) { | |
473 struct yahoo_pair *pair = l->data; | |
474 if (pair->key == 4) | |
475 from = pair->value; | |
476 if (pair->key == 14) | |
477 msg = pair->value; | |
478 if (pair->key == 15) | |
479 tm = strtol(pair->value, NULL, 10); | |
480 l = l->next; | |
481 } | |
482 | |
483 if (pkt->status == 1) { | |
484 strip_linefeed(msg); | |
485 serv_got_im(gc, from, msg, 0, tm); | |
486 } else if (pkt->status == 2) { | |
487 do_error_dialog(_("Your message did not get sent."), _("Gaim - Error")); | |
488 } | |
489 } | |
490 | |
491 static void yahoo_process_status(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
492 { | |
493 struct yahoo_data *yd = gc->proto_data; | |
494 GSList *l = pkt->hash; | |
495 char *name = NULL; | |
496 int state = 0; | |
497 char *msg = NULL; | |
498 | |
499 while (l) { | |
500 struct yahoo_pair *pair = l->data; | |
501 | |
502 switch (pair->key) { | |
503 case 7: | |
504 name = pair->value; | |
505 break; | |
506 case 10: | |
507 state = strtol(pair->value, NULL, 10); | |
508 break; | |
509 case 19: | |
510 msg = pair->value; | |
511 break; | |
512 case 11: /* i didn't know what this was in the old protocol either */ | |
513 break; | |
514 case 17: /* in chat? */ | |
515 break; | |
516 case 13: | |
517 if (strtol(pair->value, NULL, 10) != 1) { | |
518 serv_got_update(gc, name, 0, 0, 0, 0, 0, 0); | |
519 break; | |
520 } | |
521 if (state == YAHOO_STATUS_AVAILABLE) | |
522 serv_got_update(gc, name, 1, 0, 0, 0, 0, 0); | |
523 else if (state == YAHOO_STATUS_IDLE) | |
524 serv_got_update(gc, name, 1, 0, 0, time(NULL) - 600, (state << 1), 0); | |
525 else | |
526 serv_got_update(gc, name, 1, 0, 0, 0, (state << 1) | UC_UNAVAILABLE, 0); | |
527 if (state == YAHOO_STATUS_CUSTOM) { | |
528 gpointer val = g_hash_table_lookup(yd->hash, name); | |
529 if (val) { | |
530 g_free(val); | |
531 g_hash_table_insert(yd->hash, name, g_strdup(msg)); | |
532 } else | |
533 g_hash_table_insert(yd->hash, g_strdup(name), g_strdup(msg)); | |
534 } | |
535 break; | |
536 } | |
537 | |
538 l = l->next; | |
539 } | |
540 } | |
541 | |
542 static void yahoo_process_contact(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
543 { | |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
544 struct yahoo_data *yd = gc->proto_data; |
2681 | 545 char *id = NULL; |
546 char *who = NULL; | |
547 char *msg = NULL; | |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
548 char *name = NULL; |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
549 int state = YAHOO_STATUS_AVAILABLE; |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
550 int online = FALSE; |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
551 |
2681 | 552 GSList *l = pkt->hash; |
553 | |
554 while (l) { | |
555 struct yahoo_pair *pair = l->data; | |
556 if (pair->key == 1) | |
557 id = pair->value; | |
558 else if (pair->key == 3) | |
559 who = pair->value; | |
560 else if (pair->key == 14) | |
561 msg = pair->value; | |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
562 else if (pair->key == 7) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
563 name = pair->value; |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
564 else if (pair->key == 10) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
565 state = strtol(pair->value, NULL, 10); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
566 else if (pair->key == 13) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
567 online = strtol(pair->value, NULL, 10); |
2681 | 568 l = l->next; |
569 } | |
570 | |
2682
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
571 if (id) |
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
572 show_got_added(gc, id, who, NULL, msg); |
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
573 if (name) { |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
574 if (state == YAHOO_STATUS_AVAILABLE) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
575 serv_got_update(gc, name, 1, 0, 0, 0, 0, 0); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
576 else if (state == YAHOO_STATUS_IDLE) |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
577 serv_got_update(gc, name, 1, 0, 0, time(NULL) - 600, (state << 1), 0); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
578 else |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
579 serv_got_update(gc, name, 1, 0, 0, 0, (state << 1) | UC_UNAVAILABLE, 0); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
580 if (state == YAHOO_STATUS_CUSTOM) { |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
581 gpointer val = g_hash_table_lookup(yd->hash, name); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
582 if (val) { |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
583 g_free(val); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
584 g_hash_table_insert(yd->hash, name, g_strdup(msg)); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
585 } else |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
586 g_hash_table_insert(yd->hash, g_strdup(name), g_strdup(msg)); |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
587 } |
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
588 } |
2681 | 589 } |
590 | |
591 static void yahoo_process_mail(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
592 { | |
593 char *who = NULL; | |
594 char *email = NULL; | |
595 char *subj = NULL; | |
596 int count = 0; | |
597 GSList *l = pkt->hash; | |
598 | |
599 while (l) { | |
600 struct yahoo_pair *pair = l->data; | |
601 if (pair->key == 9) | |
602 count = strtol(pair->value, NULL, 10); | |
603 else if (pair->key == 43) | |
604 who = pair->value; | |
605 else if (pair->key == 42) | |
606 email = pair->value; | |
607 else if (pair->key == 18) | |
608 subj = pair->value; | |
609 l = l->next; | |
610 } | |
611 | |
612 connection_has_mail(gc, count, NULL, NULL, "http://mail.yahoo.com/"); | |
613 } | |
614 | |
615 static void yahoo_packet_process(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
616 { | |
617 switch (pkt->service) | |
618 { | |
619 case YAHOO_SERVICE_LOGON: | |
620 yahoo_process_logon(gc, pkt); | |
621 break; | |
622 case YAHOO_SERVICE_ISAWAY: | |
623 yahoo_process_status(gc, pkt); | |
624 break; | |
625 case YAHOO_SERVICE_MESSAGE: | |
626 yahoo_process_message(gc, pkt); | |
627 break; | |
628 case YAHOO_SERVICE_NEWMAIL: | |
629 yahoo_process_mail(gc, pkt); | |
630 break; | |
631 case YAHOO_SERVICE_NEWCONTACT: | |
632 yahoo_process_contact(gc, pkt); | |
633 break; | |
634 case YAHOO_SERVICE_LIST: | |
635 yahoo_process_list(gc, pkt); | |
636 break; | |
637 default: | |
638 debug_printf("unhandled service %d\n", pkt->service); | |
639 break; | |
640 } | |
641 } | |
642 | |
643 static void yahoo_pending(gpointer data, gint source, GaimInputCondition cond) | |
644 { | |
645 struct gaim_connection *gc = data; | |
646 struct yahoo_data *yd = gc->proto_data; | |
647 char buf[1024]; | |
648 int len; | |
649 | |
650 len = read(yd->fd, buf, sizeof(buf)); | |
651 | |
652 if (len <= 0) { | |
653 hide_login_progress(gc, "Unable to read"); | |
654 signoff(gc); | |
655 return; | |
656 } | |
657 | |
658 yd->rxqueue = g_realloc(yd->rxqueue, len + yd->rxlen); | |
659 memcpy(yd->rxqueue + yd->rxlen, buf, len); | |
660 yd->rxlen += len; | |
661 | |
662 while (1) { | |
663 struct yahoo_packet *pkt; | |
664 int pos = 0; | |
665 int pktlen; | |
666 | |
667 if (yd->rxlen < YAHOO_PACKET_HDRLEN) | |
668 return; | |
669 | |
670 pos += 4; /* YMSG */ | |
671 pos += 2; | |
672 pos += 2; | |
673 | |
674 pktlen = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
675 debug_printf("%d bytes to read, rxlen is %d\n", pktlen, yd->rxlen); | |
676 | |
677 if (yd->rxlen < (YAHOO_PACKET_HDRLEN + pktlen)) | |
678 return; | |
679 | |
680 yahoo_packet_dump(yd->rxqueue, YAHOO_PACKET_HDRLEN + pktlen); | |
681 | |
682 pkt = yahoo_packet_new(0, 0, 0); | |
683 | |
684 pkt->service = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
685 debug_printf("Yahoo Service: %d Status: %d\n", pkt->service, pkt->status); | |
686 pkt->status = yahoo_get32(yd->rxqueue + pos); pos += 4; | |
687 pkt->id = yahoo_get32(yd->rxqueue + pos); pos += 4; | |
688 | |
689 yahoo_packet_read(pkt, yd->rxqueue + pos, pktlen); | |
690 | |
691 yd->rxlen -= YAHOO_PACKET_HDRLEN + pktlen; | |
692 if (yd->rxlen) { | |
693 char *tmp = g_memdup(yd->rxqueue + YAHOO_PACKET_HDRLEN + pktlen, yd->rxlen); | |
694 g_free(yd->rxqueue); | |
695 yd->rxqueue = tmp; | |
696 } else { | |
697 g_free(yd->rxqueue); | |
698 yd->rxqueue = NULL; | |
699 } | |
700 | |
701 yahoo_packet_process(gc, pkt); | |
702 | |
703 yahoo_packet_free(pkt); | |
704 } | |
705 } | |
706 | |
707 static void yahoo_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
708 { | |
709 struct gaim_connection *gc = data; | |
710 struct yahoo_data *yd; | |
711 struct yahoo_packet *pkt; | |
712 | |
713 if (!g_slist_find(connections, gc)) { | |
714 close(source); | |
715 return; | |
716 } | |
717 | |
718 if (source < 0) { | |
719 hide_login_progress(gc, "Unable to connect"); | |
720 signoff(gc); | |
721 return; | |
722 } | |
723 | |
724 yd = gc->proto_data; | |
725 yd->fd = source; | |
726 | |
727 pkt = yahoo_packet_new(YAHOO_SERVICE_LOGON, YAHOO_STATUS_AVAILABLE, 0); | |
728 | |
729 yahoo_packet_hash(pkt, 0, gc->username); | |
730 yahoo_packet_hash(pkt, 1, gc->username); | |
731 yahoo_packet_hash(pkt, 6, crypt(gc->password, "$1$_2S43d5f$")); | |
732 | |
733 yahoo_send_packet(yd, pkt); | |
734 | |
735 yahoo_packet_free(pkt); | |
736 | |
737 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | |
738 } | |
739 | |
740 static void yahoo_login(struct aim_user *user) { | |
741 struct gaim_connection *gc = new_gaim_conn(user); | |
742 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); | |
743 | |
744 set_login_progress(gc, 1, "Connecting"); | |
745 | |
746 yd->fd = -1; | |
747 yd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
748 | |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2687
diff
changeset
|
749 if (proxy_connect(user->proto_opt[USEROPT_PAGERHOST][0] ? |
2681 | 750 user->proto_opt[USEROPT_PAGERHOST] : YAHOO_PAGER_HOST, |
751 user->proto_opt[USEROPT_PAGERPORT][0] ? | |
752 atoi(user->proto_opt[USEROPT_PAGERPORT]) : YAHOO_PAGER_PORT, | |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2687
diff
changeset
|
753 yahoo_got_connected, gc) < 0) { |
2681 | 754 hide_login_progress(gc, "Connection problem"); |
755 signoff(gc); | |
756 return; | |
757 } | |
758 | |
759 } | |
760 | |
761 static gboolean yahoo_destroy_hash(gpointer key, gpointer val, gpointer data) | |
762 { | |
763 g_free(key); | |
764 g_free(val); | |
765 return TRUE; | |
766 } | |
767 | |
768 static void yahoo_close(struct gaim_connection *gc) { | |
769 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
770 g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL); | |
771 g_hash_table_destroy(yd->hash); | |
772 if (yd->fd >= 0) | |
773 close(yd->fd); | |
774 if (yd->rxqueue) | |
775 g_free(yd->rxqueue); | |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2686
diff
changeset
|
776 yd->rxlen = 0; |
2681 | 777 while (yd->login) { |
778 struct yahoo_buddy *buddy = yd->login->data; | |
779 yd->login = g_slist_remove(yd->login, buddy); | |
780 g_free(buddy->msg); | |
781 g_free(buddy->name); | |
782 g_free(buddy); | |
783 } | |
784 if (gc->inpa) | |
785 gaim_input_remove(gc->inpa); | |
786 g_free(yd); | |
787 } | |
788 | |
789 static char **yahoo_list_icon(int uc) | |
790 { | |
791 if ((uc >> 1) == YAHOO_STATUS_IDLE) | |
792 return status_idle_xpm; | |
793 else if (uc == 0) | |
794 return status_here_xpm; | |
795 return status_away_xpm; | |
796 } | |
797 | |
798 static char *yahoo_get_status_string(enum yahoo_status a) | |
799 { | |
800 switch (a) { | |
801 case YAHOO_STATUS_BRB: | |
802 return "Be Right Back"; | |
803 case YAHOO_STATUS_BUSY: | |
804 return "Busy"; | |
805 case YAHOO_STATUS_NOTATHOME: | |
806 return "Not At Home"; | |
807 case YAHOO_STATUS_NOTATDESK: | |
808 return "Not At Desk"; | |
809 case YAHOO_STATUS_NOTINOFFICE: | |
810 return "Not In Office"; | |
811 case YAHOO_STATUS_ONPHONE: | |
812 return "On Phone"; | |
813 case YAHOO_STATUS_ONVACATION: | |
814 return "On Vacation"; | |
815 case YAHOO_STATUS_OUTTOLUNCH: | |
816 return "Out To Lunch"; | |
817 case YAHOO_STATUS_STEPPEDOUT: | |
818 return "Stepped Out"; | |
819 default: | |
820 return NULL; | |
821 } | |
822 } | |
823 | |
824 static GList *yahoo_buddy_menu(struct gaim_connection *gc, char *who) | |
825 { | |
826 GList *m = NULL; | |
827 struct proto_buddy_menu *pbm; | |
828 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
829 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, | |
830 segfault and get the bug report. */ | |
831 static char buf[1024]; | |
832 | |
833 if (!(b->uc & UC_UNAVAILABLE)) | |
834 return NULL; | |
835 | |
836 pbm = g_new0(struct proto_buddy_menu, 1); | |
837 if ((b->uc >> 1) != YAHOO_STATUS_CUSTOM) | |
838 g_snprintf(buf, sizeof buf, "Status: %s", yahoo_get_status_string(b->uc >> 1)); | |
839 else | |
840 g_snprintf(buf, sizeof buf, "Custom Status: %s", | |
841 (char *)g_hash_table_lookup(yd->hash, b->name)); | |
842 pbm->label = buf; | |
843 pbm->callback = NULL; | |
844 pbm->gc = gc; | |
845 m = g_list_append(m, pbm); | |
846 | |
847 return m; | |
848 } | |
849 | |
850 static GList *yahoo_user_opts() | |
851 { | |
852 GList *m = NULL; | |
853 struct proto_user_opt *puo; | |
854 | |
855 puo = g_new0(struct proto_user_opt, 1); | |
856 puo->label = "Pager Host:"; | |
857 puo->def = YAHOO_PAGER_HOST; | |
858 puo->pos = USEROPT_PAGERHOST; | |
859 m = g_list_append(m, puo); | |
860 | |
861 puo = g_new0(struct proto_user_opt, 1); | |
862 puo->label = "Pager Port:"; | |
863 puo->def = "5050"; | |
864 puo->pos = USEROPT_PAGERPORT; | |
865 m = g_list_append(m, puo); | |
866 | |
867 return m; | |
868 } | |
869 | |
870 static void yahoo_act_id(gpointer data, char *entry) | |
871 { | |
872 struct gaim_connection *gc = data; | |
873 struct yahoo_data *yd = gc->proto_data; | |
874 | |
875 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0); | |
876 yahoo_packet_hash(pkt, 3, entry); | |
877 yahoo_send_packet(yd, pkt); | |
878 yahoo_packet_free(pkt); | |
879 | |
880 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", entry); | |
881 } | |
882 | |
883 static void yahoo_do_action(struct gaim_connection *gc, char *act) | |
884 { | |
885 if (!strcmp(act, "Activate ID")) { | |
886 do_prompt_dialog("Activate which ID:", gc->displayname, gc, yahoo_act_id, NULL); | |
887 } | |
888 } | |
889 | |
890 static GList *yahoo_actions() { | |
891 GList *m = NULL; | |
892 | |
893 m = g_list_append(m, "Activate ID"); | |
894 | |
895 return m; | |
896 } | |
897 | |
898 static int yahoo_send_im(struct gaim_connection *gc, char *who, char *what, int flags) | |
899 { | |
900 struct yahoo_data *yd = gc->proto_data; | |
901 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0); | |
902 | |
903 yahoo_packet_hash(pkt, 1, gc->displayname); | |
904 yahoo_packet_hash(pkt, 5, who); | |
905 yahoo_packet_hash(pkt, 14, what); | |
906 | |
907 yahoo_send_packet(yd, pkt); | |
908 | |
909 yahoo_packet_free(pkt); | |
910 | |
911 return 1; | |
912 } | |
913 | |
914 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) | |
915 { | |
916 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
917 struct yahoo_packet *pkt; | |
918 char s[4]; | |
919 | |
920 gc->away = NULL; | |
921 | |
922 if (msg) { | |
923 yd->current_status = YAHOO_STATUS_CUSTOM; | |
924 gc->away = ""; | |
925 } else if (state) { | |
926 gc->away = ""; | |
927 if (!strcmp(state, "Available")) { | |
928 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
929 gc->away = NULL; | |
930 } else if (!strcmp(state, "Be Right Back")) { | |
931 yd->current_status = YAHOO_STATUS_BRB; | |
932 } else if (!strcmp(state, "Busy")) { | |
933 yd->current_status = YAHOO_STATUS_BUSY; | |
934 } else if (!strcmp(state, "Not At Home")) { | |
935 yd->current_status = YAHOO_STATUS_NOTATHOME; | |
936 } else if (!strcmp(state, "Not At Desk")) { | |
937 yd->current_status = YAHOO_STATUS_NOTATDESK; | |
938 } else if (!strcmp(state, "Not In Office")) { | |
939 yd->current_status = YAHOO_STATUS_NOTINOFFICE; | |
940 } else if (!strcmp(state, "On Phone")) { | |
941 yd->current_status = YAHOO_STATUS_ONPHONE; | |
942 } else if (!strcmp(state, "On Vacation")) { | |
943 yd->current_status = YAHOO_STATUS_ONVACATION; | |
944 } else if (!strcmp(state, "Out To Lunch")) { | |
945 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; | |
946 } else if (!strcmp(state, "Stepped Out")) { | |
947 yd->current_status = YAHOO_STATUS_STEPPEDOUT; | |
948 } else if (!strcmp(state, "Invisible")) { | |
949 yd->current_status = YAHOO_STATUS_INVISIBLE; | |
950 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
951 if (gc->is_idle) { | |
952 yd->current_status = YAHOO_STATUS_IDLE; | |
953 } else { | |
954 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
955 } | |
956 gc->away = NULL; | |
957 } | |
958 } else if (gc->is_idle) { | |
959 yd->current_status = YAHOO_STATUS_IDLE; | |
960 } else { | |
961 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
962 } | |
963 | |
964 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, yd->current_status, 0); | |
965 g_snprintf(s, sizeof(s), "%d", yd->current_status); | |
966 yahoo_packet_hash(pkt, 10, s); | |
967 if (yd->current_status == YAHOO_STATUS_CUSTOM) | |
968 yahoo_packet_hash(pkt, 19, msg); | |
969 | |
970 yahoo_send_packet(yd, pkt); | |
971 yahoo_packet_free(pkt); | |
972 } | |
973 | |
974 static void yahoo_set_idle(struct gaim_connection *gc, int idle) | |
975 { | |
976 struct yahoo_data *yd = gc->proto_data; | |
977 struct yahoo_packet *pkt = NULL; | |
978 | |
979 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
980 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_IDLE, 0); | |
981 yd->current_status = YAHOO_STATUS_IDLE; | |
982 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
983 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); | |
984 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
985 } | |
986 | |
987 if (pkt) { | |
988 char buf[4]; | |
989 g_snprintf(buf, sizeof(buf), "%d", yd->current_status); | |
990 yahoo_packet_hash(pkt, 10, buf); | |
991 yahoo_send_packet(yd, pkt); | |
992 yahoo_packet_free(pkt); | |
993 } | |
994 } | |
995 | |
996 static GList *yahoo_away_states(struct gaim_connection *gc) | |
997 { | |
998 GList *m = NULL; | |
999 | |
1000 m = g_list_append(m, "Available"); | |
1001 m = g_list_append(m, "Be Right Back"); | |
1002 m = g_list_append(m, "Busy"); | |
1003 m = g_list_append(m, "Not At Home"); | |
1004 m = g_list_append(m, "Not At Desk"); | |
1005 m = g_list_append(m, "Not In Office"); | |
1006 m = g_list_append(m, "On Phone"); | |
1007 m = g_list_append(m, "On Vacation"); | |
1008 m = g_list_append(m, "Out To Lunch"); | |
1009 m = g_list_append(m, "Stepped Out"); | |
1010 m = g_list_append(m, "Invisible"); | |
1011 m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
1012 | |
1013 return m; | |
1014 } | |
1015 | |
1016 static void yahoo_keepalive(struct gaim_connection *gc) | |
1017 { | |
1018 struct yahoo_data *yd = gc->proto_data; | |
1019 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0); | |
1020 yahoo_send_packet(yd, pkt); | |
1021 yahoo_packet_free(pkt); | |
1022 } | |
1023 | |
1024 static void yahoo_add_buddy(struct gaim_connection *gc, char *who) | |
1025 { | |
1026 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1027 struct yahoo_packet *pkt; | |
1028 struct group *g; | |
1029 char *group = NULL; | |
1030 | |
1031 if (!yd->logged_in) | |
1032 return; | |
1033 | |
1034 g = find_group_by_buddy(gc, who); | |
1035 if (g) | |
1036 group = g->name; | |
1037 else | |
1038 group = "Buddies"; | |
1039 | |
1040 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
1041 yahoo_packet_hash(pkt, 1, gc->displayname); | |
1042 yahoo_packet_hash(pkt, 7, who); | |
1043 yahoo_packet_hash(pkt, 65, group); | |
1044 yahoo_send_packet(yd, pkt); | |
1045 yahoo_packet_free(pkt); | |
1046 } | |
1047 | |
1048 static void yahoo_remove_buddy(struct gaim_connection *gc, char *who, char *group) | |
1049 { | |
1050 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
1051 | |
1052 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
1053 yahoo_packet_hash(pkt, 1, gc->displayname); | |
1054 yahoo_packet_hash(pkt, 7, who); | |
1055 yahoo_packet_hash(pkt, 65, group); | |
1056 yahoo_send_packet(yd, pkt); | |
1057 yahoo_packet_free(pkt); | |
1058 } | |
1059 | |
1060 static struct prpl *my_protocol = NULL; | |
1061 | |
1062 void yahoo_init(struct prpl *ret) { | |
1063 ret->protocol = PROTO_YAHOO; | |
1064 ret->options = OPT_PROTO_MAIL_CHECK; | |
1065 ret->name = yahoo_name; | |
1066 ret->user_opts = yahoo_user_opts; | |
1067 ret->login = yahoo_login; | |
1068 ret->close = yahoo_close; | |
1069 ret->buddy_menu = yahoo_buddy_menu; | |
1070 ret->list_icon = yahoo_list_icon; | |
1071 ret->actions = yahoo_actions; | |
1072 ret->do_action = yahoo_do_action; | |
1073 ret->send_im = yahoo_send_im; | |
1074 ret->away_states = yahoo_away_states; | |
1075 ret->set_away = yahoo_set_away; | |
1076 ret->set_idle = yahoo_set_idle; | |
1077 ret->keepalive = yahoo_keepalive; | |
1078 ret->add_buddy = yahoo_add_buddy; | |
1079 ret->remove_buddy = yahoo_remove_buddy; | |
1080 | |
1081 my_protocol = ret; | |
1082 } | |
1083 | |
1084 #ifndef STATIC | |
1085 | |
1086 char *gaim_plugin_init(GModule *handle) | |
1087 { | |
1088 load_protocol(yahoo_init, sizeof(struct prpl)); | |
1089 return NULL; | |
1090 } | |
1091 | |
1092 void gaim_plugin_remove() | |
1093 { | |
1094 struct prpl *p = find_prpl(PROTO_YAHOO); | |
1095 if (p == my_protocol) | |
1096 unload_protocol(p); | |
1097 } | |
1098 | |
1099 char *name() | |
1100 { | |
1101 return "Yahoo"; | |
1102 } | |
1103 | |
1104 char *description() | |
1105 { | |
1106 return PRPL_DESC("Yahoo"); | |
1107 } | |
1108 | |
1109 #endif |