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