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