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