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