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