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