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