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