Mercurial > pidgin
annotate src/protocols/yahoo/yahoo.c @ 2810:dfcd5010dd13
[gaim-migrate @ 2823]
gtk2 (1.3.11)
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Wed, 28 Nov 2001 21:06:45 +0000 |
| parents | f01e6a425136 |
| children | bda5b89ba2f9 |
| rev | line source |
|---|---|
| 2681 | 1 /* |
| 2 * gaim | |
| 3 * | |
| 4 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 5 * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> | |
| 6 * | |
| 7 * This program is free software; you can redistribute it and/or modify | |
| 8 * it under the terms of the GNU General Public License as published by | |
| 9 * the Free Software Foundation; either version 2 of the License, or | |
| 10 * (at your option) any later version. | |
| 11 * | |
| 12 * This program is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 * GNU General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU General Public License | |
| 18 * along with this program; if not, write to the Free Software | |
| 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 * | |
| 21 */ | |
| 22 | |
| 23 #ifdef HAVE_CONFIG_H | |
| 24 #include "config.h" | |
| 25 #endif | |
| 26 | |
| 27 | |
| 28 #include <netdb.h> | |
| 29 #include <unistd.h> | |
| 30 #include <errno.h> | |
| 31 #include <netinet/in.h> | |
| 32 #include <arpa/inet.h> | |
| 33 #include <string.h> | |
| 34 #include <stdlib.h> | |
| 35 #include <stdio.h> | |
| 36 #include <time.h> | |
| 37 #include <sys/socket.h> | |
| 38 #include <sys/stat.h> | |
| 39 #include <ctype.h> | |
| 40 #include "multi.h" | |
| 41 #include "prpl.h" | |
| 42 #include "gaim.h" | |
| 43 #include "proxy.h" | |
| 44 | |
|
2795
536bb833fdeb
[gaim-migrate @ 2808]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2786
diff
changeset
|
45 extern char *yahoo_crypt(char *, char *); |
|
536bb833fdeb
[gaim-migrate @ 2808]
Eric Warmenhoven <eric@warmenhoven.org>
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
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
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
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
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
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
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
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
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
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
76 YAHOO_SERVICE_ADDIDENT, /* 0x10 */ |
| 2681 | 77 YAHOO_SERVICE_ADDIGNORE, |
| 78 YAHOO_SERVICE_PING, | |
| 79 YAHOO_SERVICE_GROUPRENAME, | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
80 YAHOO_SERVICE_SYSMESSAGE = 0x14, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
81 YAHOO_SERVICE_PASSTHROUGH2 = 0x16, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
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
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
90 YAHOO_SERVICE_CHATMSG = 0x20, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
91 YAHOO_SERVICE_GAMELOGON = 0x28, |
|
2786
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
92 YAHOO_SERVICE_GAMELOGOFF, |
|
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
93 YAHOO_SERVICE_GAMEMSG = 0x2a, |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
94 YAHOO_SERVICE_FILETRANSFER = 0x46, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
95 YAHOO_SERVICE_LIST = 0x55, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
96 YAHOO_SERVICE_ADDBUDDY = 0x83, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
97 YAHOO_SERVICE_REMBUDDY = 0x84 |
| 2681 | 98 }; |
| 99 | |
| 100 enum yahoo_status { | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
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
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
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
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
209 char key[64], *value = NULL; |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
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
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
224 accept = x; /* if x is 0 there was no key, so don't accept it */ |
| 2681 | 225 |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
226 if (accept) |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
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
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
232 if (accept) |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
233 value[x++] = data[pos++]; |
| 2681 | 234 } |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
235 if (accept) |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
236 value[x] = 0; |
| 2681 | 237 pos += 2; |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
238 if (accept) { |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
239 pair->value = g_strdup(value); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
240 g_free(value); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
241 pkt->hash = g_slist_append(pkt->hash, pair); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
242 debug_printf("Key: %d \tValue: %s\n", pair->key, pair->value); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
243 } else { |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
244 g_free(pair); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
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
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
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
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
357 if (!yd->logged_in) { |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
358 account_online(gc); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
359 serv_finish_login(gc); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
360 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", pair->value); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
361 do_import(gc, NULL); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
362 yd->logged_in = TRUE; |
| 2681 | 363 |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
364 /* this requests the list. i have a feeling that this is very evil */ |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
365 newpkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_OFFLINE, 0); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
366 yahoo_send_packet(yd, newpkt); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
367 yahoo_packet_free(newpkt); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
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
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
385 case 13: /* in pager? */ |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
386 if (pkt->service == YAHOO_SERVICE_LOGOFF || |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
387 strtol(pair->value, NULL, 10) == 0) { |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
388 serv_got_update(gc, name, 0, 0, 0, 0, 0, 0); |
|
2807
f01e6a425136
[gaim-migrate @ 2820]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2805
diff
changeset
|
389 break; |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
390 } |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
391 if (state == YAHOO_STATUS_AVAILABLE) |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
392 serv_got_update(gc, name, 1, 0, 0, 0, 0, 0); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
393 else |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
394 serv_got_update(gc, name, 1, 0, 0, 0, (state << 1) | UC_UNAVAILABLE, 0); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
395 if (state == YAHOO_STATUS_CUSTOM) { |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
396 gpointer val = g_hash_table_lookup(yd->hash, name); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
397 if (val) { |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
398 g_free(val); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
399 g_hash_table_insert(yd->hash, name, g_strdup(msg)); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
400 } else |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
401 g_hash_table_insert(yd->hash, g_strdup(name), g_strdup(msg)); |
|
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
402 } |
|
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
403 break; |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
404 case 60: /* no clue */ |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
405 break; |
| 2681 | 406 default: |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
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
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
435 if (!split) |
|
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
436 continue; |
|
2702
94b4271b9567
[gaim-migrate @ 2715]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2697
diff
changeset
|
437 if (!split[0] || !split[1]) { |
|
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
438 g_strfreev(split); |
|
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
439 continue; |
|
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
440 } |
| 2681 | 441 buddies = g_strsplit(split[1], ",", -1); |
|
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
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
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
476 char *m; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
477 int i, j; |
| 2681 | 478 strip_linefeed(msg); |
|
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
479 m = msg; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
480 for (i = 0, j = 0; m[i]; i++) { |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
481 if (m[i] == 033) { |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
482 while (m[i] != 'm') |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
483 i++; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
484 continue; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
485 } |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
486 msg[j++] = m[i]; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
487 } |
| 2681 | 488 serv_got_im(gc, from, msg, 0, tm); |
| 489 } else if (pkt->status == 2) { | |
| 490 do_error_dialog(_("Your message did not get sent."), _("Gaim - Error")); | |
| 491 } | |
| 492 } | |
| 493 | |
| 494 | |
| 495 static void yahoo_process_contact(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
| 496 { | |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
497 struct yahoo_data *yd = gc->proto_data; |
| 2681 | 498 char *id = NULL; |
| 499 char *who = NULL; | |
| 500 char *msg = NULL; | |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
501 char *name = NULL; |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
502 int state = YAHOO_STATUS_AVAILABLE; |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
503 int online = FALSE; |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
504 |
| 2681 | 505 GSList *l = pkt->hash; |
| 506 | |
| 507 while (l) { | |
| 508 struct yahoo_pair *pair = l->data; | |
| 509 if (pair->key == 1) | |
| 510 id = pair->value; | |
| 511 else if (pair->key == 3) | |
| 512 who = pair->value; | |
| 513 else if (pair->key == 14) | |
| 514 msg = pair->value; | |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
515 else if (pair->key == 7) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
516 name = pair->value; |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
517 else if (pair->key == 10) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
518 state = strtol(pair->value, NULL, 10); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
519 else if (pair->key == 13) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
520 online = strtol(pair->value, NULL, 10); |
| 2681 | 521 l = l->next; |
| 522 } | |
| 523 | |
|
2682
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
524 if (id) |
|
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
525 show_got_added(gc, id, who, NULL, msg); |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
526 if (name) { |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
527 if (state == YAHOO_STATUS_AVAILABLE) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
528 serv_got_update(gc, name, 1, 0, 0, 0, 0, 0); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
529 else if (state == YAHOO_STATUS_IDLE) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
530 serv_got_update(gc, name, 1, 0, 0, time(NULL) - 600, (state << 1), 0); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
531 else |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
532 serv_got_update(gc, name, 1, 0, 0, 0, (state << 1) | UC_UNAVAILABLE, 0); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
533 if (state == YAHOO_STATUS_CUSTOM) { |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
534 gpointer val = g_hash_table_lookup(yd->hash, name); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
535 if (val) { |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
536 g_free(val); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
537 g_hash_table_insert(yd->hash, name, g_strdup(msg)); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
538 } else |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
539 g_hash_table_insert(yd->hash, g_strdup(name), g_strdup(msg)); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
540 } |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
541 } |
| 2681 | 542 } |
| 543 | |
| 544 static void yahoo_process_mail(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
| 545 { | |
| 546 char *who = NULL; | |
| 547 char *email = NULL; | |
| 548 char *subj = NULL; | |
| 549 int count = 0; | |
| 550 GSList *l = pkt->hash; | |
| 551 | |
| 552 while (l) { | |
| 553 struct yahoo_pair *pair = l->data; | |
| 554 if (pair->key == 9) | |
| 555 count = strtol(pair->value, NULL, 10); | |
| 556 else if (pair->key == 43) | |
| 557 who = pair->value; | |
| 558 else if (pair->key == 42) | |
| 559 email = pair->value; | |
| 560 else if (pair->key == 18) | |
| 561 subj = pair->value; | |
| 562 l = l->next; | |
| 563 } | |
| 564 | |
| 565 connection_has_mail(gc, count, NULL, NULL, "http://mail.yahoo.com/"); | |
| 566 } | |
| 567 | |
| 568 static void yahoo_packet_process(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
| 569 { | |
| 570 switch (pkt->service) | |
| 571 { | |
| 572 case YAHOO_SERVICE_LOGON: | |
|
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
573 case YAHOO_SERVICE_LOGOFF: |
| 2681 | 574 case YAHOO_SERVICE_ISAWAY: |
|
2737
f61c1f3a6afa
[gaim-migrate @ 2750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2724
diff
changeset
|
575 case YAHOO_SERVICE_ISBACK: |
| 2681 | 576 yahoo_process_status(gc, pkt); |
| 577 break; | |
| 578 case YAHOO_SERVICE_MESSAGE: | |
|
2786
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
579 case YAHOO_SERVICE_GAMEMSG: |
| 2681 | 580 yahoo_process_message(gc, pkt); |
| 581 break; | |
| 582 case YAHOO_SERVICE_NEWMAIL: | |
| 583 yahoo_process_mail(gc, pkt); | |
| 584 break; | |
| 585 case YAHOO_SERVICE_NEWCONTACT: | |
| 586 yahoo_process_contact(gc, pkt); | |
| 587 break; | |
| 588 case YAHOO_SERVICE_LIST: | |
| 589 yahoo_process_list(gc, pkt); | |
| 590 break; | |
| 591 default: | |
|
2741
38cb5fa48bec
[gaim-migrate @ 2754]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2737
diff
changeset
|
592 debug_printf("unhandled service 0x%02x\n", pkt->service); |
| 2681 | 593 break; |
| 594 } | |
| 595 } | |
| 596 | |
| 597 static void yahoo_pending(gpointer data, gint source, GaimInputCondition cond) | |
| 598 { | |
| 599 struct gaim_connection *gc = data; | |
| 600 struct yahoo_data *yd = gc->proto_data; | |
| 601 char buf[1024]; | |
| 602 int len; | |
| 603 | |
| 604 len = read(yd->fd, buf, sizeof(buf)); | |
| 605 | |
| 606 if (len <= 0) { | |
| 607 hide_login_progress(gc, "Unable to read"); | |
| 608 signoff(gc); | |
| 609 return; | |
| 610 } | |
| 611 | |
| 612 yd->rxqueue = g_realloc(yd->rxqueue, len + yd->rxlen); | |
| 613 memcpy(yd->rxqueue + yd->rxlen, buf, len); | |
| 614 yd->rxlen += len; | |
| 615 | |
| 616 while (1) { | |
| 617 struct yahoo_packet *pkt; | |
| 618 int pos = 0; | |
| 619 int pktlen; | |
| 620 | |
| 621 if (yd->rxlen < YAHOO_PACKET_HDRLEN) | |
| 622 return; | |
| 623 | |
| 624 pos += 4; /* YMSG */ | |
| 625 pos += 2; | |
| 626 pos += 2; | |
| 627 | |
| 628 pktlen = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
| 629 debug_printf("%d bytes to read, rxlen is %d\n", pktlen, yd->rxlen); | |
| 630 | |
| 631 if (yd->rxlen < (YAHOO_PACKET_HDRLEN + pktlen)) | |
| 632 return; | |
| 633 | |
| 634 yahoo_packet_dump(yd->rxqueue, YAHOO_PACKET_HDRLEN + pktlen); | |
| 635 | |
| 636 pkt = yahoo_packet_new(0, 0, 0); | |
| 637 | |
| 638 pkt->service = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
|
2741
38cb5fa48bec
[gaim-migrate @ 2754]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2737
diff
changeset
|
639 debug_printf("Yahoo Service: 0x%02x Status: %d\n", pkt->service, pkt->status); |
| 2681 | 640 pkt->status = yahoo_get32(yd->rxqueue + pos); pos += 4; |
| 641 pkt->id = yahoo_get32(yd->rxqueue + pos); pos += 4; | |
| 642 | |
| 643 yahoo_packet_read(pkt, yd->rxqueue + pos, pktlen); | |
| 644 | |
| 645 yd->rxlen -= YAHOO_PACKET_HDRLEN + pktlen; | |
| 646 if (yd->rxlen) { | |
| 647 char *tmp = g_memdup(yd->rxqueue + YAHOO_PACKET_HDRLEN + pktlen, yd->rxlen); | |
| 648 g_free(yd->rxqueue); | |
| 649 yd->rxqueue = tmp; | |
| 650 } else { | |
| 651 g_free(yd->rxqueue); | |
| 652 yd->rxqueue = NULL; | |
| 653 } | |
| 654 | |
| 655 yahoo_packet_process(gc, pkt); | |
| 656 | |
| 657 yahoo_packet_free(pkt); | |
| 658 } | |
| 659 } | |
| 660 | |
| 661 static void yahoo_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
| 662 { | |
| 663 struct gaim_connection *gc = data; | |
| 664 struct yahoo_data *yd; | |
| 665 struct yahoo_packet *pkt; | |
| 666 | |
| 667 if (!g_slist_find(connections, gc)) { | |
| 668 close(source); | |
| 669 return; | |
| 670 } | |
| 671 | |
| 672 if (source < 0) { | |
| 673 hide_login_progress(gc, "Unable to connect"); | |
| 674 signoff(gc); | |
| 675 return; | |
| 676 } | |
| 677 | |
| 678 yd = gc->proto_data; | |
| 679 yd->fd = source; | |
| 680 | |
| 681 pkt = yahoo_packet_new(YAHOO_SERVICE_LOGON, YAHOO_STATUS_AVAILABLE, 0); | |
| 682 | |
| 683 yahoo_packet_hash(pkt, 0, gc->username); | |
| 684 yahoo_packet_hash(pkt, 1, gc->username); | |
|
2795
536bb833fdeb
[gaim-migrate @ 2808]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2786
diff
changeset
|
685 yahoo_packet_hash(pkt, 6, yahoo_crypt(gc->password, "$1$_2S43d5f$")); |
| 2681 | 686 |
| 687 yahoo_send_packet(yd, pkt); | |
| 688 | |
| 689 yahoo_packet_free(pkt); | |
| 690 | |
| 691 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | |
| 692 } | |
| 693 | |
| 694 static void yahoo_login(struct aim_user *user) { | |
| 695 struct gaim_connection *gc = new_gaim_conn(user); | |
| 696 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); | |
| 697 | |
| 698 set_login_progress(gc, 1, "Connecting"); | |
| 699 | |
| 700 yd->fd = -1; | |
| 701 yd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
| 702 | |
|
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2687
diff
changeset
|
703 if (proxy_connect(user->proto_opt[USEROPT_PAGERHOST][0] ? |
| 2681 | 704 user->proto_opt[USEROPT_PAGERHOST] : YAHOO_PAGER_HOST, |
| 705 user->proto_opt[USEROPT_PAGERPORT][0] ? | |
| 706 atoi(user->proto_opt[USEROPT_PAGERPORT]) : YAHOO_PAGER_PORT, | |
|
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2687
diff
changeset
|
707 yahoo_got_connected, gc) < 0) { |
| 2681 | 708 hide_login_progress(gc, "Connection problem"); |
| 709 signoff(gc); | |
| 710 return; | |
| 711 } | |
| 712 | |
| 713 } | |
| 714 | |
| 715 static gboolean yahoo_destroy_hash(gpointer key, gpointer val, gpointer data) | |
| 716 { | |
| 717 g_free(key); | |
| 718 g_free(val); | |
| 719 return TRUE; | |
| 720 } | |
| 721 | |
| 722 static void yahoo_close(struct gaim_connection *gc) { | |
| 723 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 724 g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL); | |
| 725 g_hash_table_destroy(yd->hash); | |
| 726 if (yd->fd >= 0) | |
| 727 close(yd->fd); | |
| 728 if (yd->rxqueue) | |
| 729 g_free(yd->rxqueue); | |
|
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2686
diff
changeset
|
730 yd->rxlen = 0; |
| 2681 | 731 if (gc->inpa) |
| 732 gaim_input_remove(gc->inpa); | |
| 733 g_free(yd); | |
| 734 } | |
| 735 | |
| 736 static char **yahoo_list_icon(int uc) | |
| 737 { | |
| 738 if ((uc >> 1) == YAHOO_STATUS_IDLE) | |
| 739 return status_idle_xpm; | |
| 740 else if (uc == 0) | |
| 741 return status_here_xpm; | |
| 742 return status_away_xpm; | |
| 743 } | |
| 744 | |
| 745 static char *yahoo_get_status_string(enum yahoo_status a) | |
| 746 { | |
| 747 switch (a) { | |
| 748 case YAHOO_STATUS_BRB: | |
| 749 return "Be Right Back"; | |
| 750 case YAHOO_STATUS_BUSY: | |
| 751 return "Busy"; | |
| 752 case YAHOO_STATUS_NOTATHOME: | |
| 753 return "Not At Home"; | |
| 754 case YAHOO_STATUS_NOTATDESK: | |
| 755 return "Not At Desk"; | |
| 756 case YAHOO_STATUS_NOTINOFFICE: | |
| 757 return "Not In Office"; | |
| 758 case YAHOO_STATUS_ONPHONE: | |
| 759 return "On Phone"; | |
| 760 case YAHOO_STATUS_ONVACATION: | |
| 761 return "On Vacation"; | |
| 762 case YAHOO_STATUS_OUTTOLUNCH: | |
| 763 return "Out To Lunch"; | |
| 764 case YAHOO_STATUS_STEPPEDOUT: | |
| 765 return "Stepped Out"; | |
| 766 default: | |
| 767 return NULL; | |
| 768 } | |
| 769 } | |
| 770 | |
| 771 static GList *yahoo_buddy_menu(struct gaim_connection *gc, char *who) | |
| 772 { | |
| 773 GList *m = NULL; | |
| 774 struct proto_buddy_menu *pbm; | |
| 775 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 776 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, | |
| 777 segfault and get the bug report. */ | |
| 778 static char buf[1024]; | |
| 779 | |
| 780 if (!(b->uc & UC_UNAVAILABLE)) | |
| 781 return NULL; | |
| 782 | |
| 783 pbm = g_new0(struct proto_buddy_menu, 1); | |
| 784 if ((b->uc >> 1) != YAHOO_STATUS_CUSTOM) | |
| 785 g_snprintf(buf, sizeof buf, "Status: %s", yahoo_get_status_string(b->uc >> 1)); | |
| 786 else | |
| 787 g_snprintf(buf, sizeof buf, "Custom Status: %s", | |
| 788 (char *)g_hash_table_lookup(yd->hash, b->name)); | |
| 789 pbm->label = buf; | |
| 790 pbm->callback = NULL; | |
| 791 pbm->gc = gc; | |
| 792 m = g_list_append(m, pbm); | |
| 793 | |
| 794 return m; | |
| 795 } | |
| 796 | |
| 797 static GList *yahoo_user_opts() | |
| 798 { | |
| 799 GList *m = NULL; | |
| 800 struct proto_user_opt *puo; | |
| 801 | |
| 802 puo = g_new0(struct proto_user_opt, 1); | |
| 803 puo->label = "Pager Host:"; | |
| 804 puo->def = YAHOO_PAGER_HOST; | |
| 805 puo->pos = USEROPT_PAGERHOST; | |
| 806 m = g_list_append(m, puo); | |
| 807 | |
| 808 puo = g_new0(struct proto_user_opt, 1); | |
| 809 puo->label = "Pager Port:"; | |
| 810 puo->def = "5050"; | |
| 811 puo->pos = USEROPT_PAGERPORT; | |
| 812 m = g_list_append(m, puo); | |
| 813 | |
| 814 return m; | |
| 815 } | |
| 816 | |
| 817 static void yahoo_act_id(gpointer data, char *entry) | |
| 818 { | |
| 819 struct gaim_connection *gc = data; | |
| 820 struct yahoo_data *yd = gc->proto_data; | |
| 821 | |
| 822 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0); | |
| 823 yahoo_packet_hash(pkt, 3, entry); | |
| 824 yahoo_send_packet(yd, pkt); | |
| 825 yahoo_packet_free(pkt); | |
| 826 | |
| 827 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", entry); | |
| 828 } | |
| 829 | |
| 830 static void yahoo_do_action(struct gaim_connection *gc, char *act) | |
| 831 { | |
| 832 if (!strcmp(act, "Activate ID")) { | |
| 833 do_prompt_dialog("Activate which ID:", gc->displayname, gc, yahoo_act_id, NULL); | |
| 834 } | |
| 835 } | |
| 836 | |
| 837 static GList *yahoo_actions() { | |
| 838 GList *m = NULL; | |
| 839 | |
| 840 m = g_list_append(m, "Activate ID"); | |
| 841 | |
| 842 return m; | |
| 843 } | |
| 844 | |
| 845 static int yahoo_send_im(struct gaim_connection *gc, char *who, char *what, int flags) | |
| 846 { | |
| 847 struct yahoo_data *yd = gc->proto_data; | |
| 848 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0); | |
| 849 | |
| 850 yahoo_packet_hash(pkt, 1, gc->displayname); | |
| 851 yahoo_packet_hash(pkt, 5, who); | |
| 852 yahoo_packet_hash(pkt, 14, what); | |
| 853 | |
| 854 yahoo_send_packet(yd, pkt); | |
| 855 | |
| 856 yahoo_packet_free(pkt); | |
| 857 | |
| 858 return 1; | |
| 859 } | |
| 860 | |
| 861 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) | |
| 862 { | |
| 863 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 864 struct yahoo_packet *pkt; | |
|
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
865 int service; |
| 2681 | 866 char s[4]; |
| 867 | |
| 868 gc->away = NULL; | |
| 869 | |
| 870 if (msg) { | |
| 871 yd->current_status = YAHOO_STATUS_CUSTOM; | |
| 872 gc->away = ""; | |
| 873 } else if (state) { | |
| 874 gc->away = ""; | |
| 875 if (!strcmp(state, "Available")) { | |
| 876 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 877 gc->away = NULL; | |
| 878 } else if (!strcmp(state, "Be Right Back")) { | |
| 879 yd->current_status = YAHOO_STATUS_BRB; | |
| 880 } else if (!strcmp(state, "Busy")) { | |
| 881 yd->current_status = YAHOO_STATUS_BUSY; | |
| 882 } else if (!strcmp(state, "Not At Home")) { | |
| 883 yd->current_status = YAHOO_STATUS_NOTATHOME; | |
| 884 } else if (!strcmp(state, "Not At Desk")) { | |
| 885 yd->current_status = YAHOO_STATUS_NOTATDESK; | |
| 886 } else if (!strcmp(state, "Not In Office")) { | |
| 887 yd->current_status = YAHOO_STATUS_NOTINOFFICE; | |
| 888 } else if (!strcmp(state, "On Phone")) { | |
| 889 yd->current_status = YAHOO_STATUS_ONPHONE; | |
| 890 } else if (!strcmp(state, "On Vacation")) { | |
| 891 yd->current_status = YAHOO_STATUS_ONVACATION; | |
| 892 } else if (!strcmp(state, "Out To Lunch")) { | |
| 893 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; | |
| 894 } else if (!strcmp(state, "Stepped Out")) { | |
| 895 yd->current_status = YAHOO_STATUS_STEPPEDOUT; | |
| 896 } else if (!strcmp(state, "Invisible")) { | |
| 897 yd->current_status = YAHOO_STATUS_INVISIBLE; | |
| 898 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
| 899 if (gc->is_idle) { | |
| 900 yd->current_status = YAHOO_STATUS_IDLE; | |
| 901 } else { | |
| 902 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 903 } | |
| 904 gc->away = NULL; | |
| 905 } | |
| 906 } else if (gc->is_idle) { | |
| 907 yd->current_status = YAHOO_STATUS_IDLE; | |
| 908 } else { | |
| 909 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 910 } | |
| 911 | |
|
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
912 if (yd->current_status == YAHOO_STATUS_AVAILABLE) |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
913 service = YAHOO_SERVICE_ISBACK; |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
914 else |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
915 service = YAHOO_SERVICE_ISAWAY; |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
916 pkt = yahoo_packet_new(service, yd->current_status, 0); |
| 2681 | 917 g_snprintf(s, sizeof(s), "%d", yd->current_status); |
| 918 yahoo_packet_hash(pkt, 10, s); | |
| 919 if (yd->current_status == YAHOO_STATUS_CUSTOM) | |
| 920 yahoo_packet_hash(pkt, 19, msg); | |
| 921 | |
| 922 yahoo_send_packet(yd, pkt); | |
| 923 yahoo_packet_free(pkt); | |
| 924 } | |
| 925 | |
| 926 static void yahoo_set_idle(struct gaim_connection *gc, int idle) | |
| 927 { | |
| 928 struct yahoo_data *yd = gc->proto_data; | |
| 929 struct yahoo_packet *pkt = NULL; | |
| 930 | |
| 931 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
| 932 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_IDLE, 0); | |
| 933 yd->current_status = YAHOO_STATUS_IDLE; | |
| 934 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
| 935 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); | |
| 936 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 937 } | |
| 938 | |
| 939 if (pkt) { | |
| 940 char buf[4]; | |
| 941 g_snprintf(buf, sizeof(buf), "%d", yd->current_status); | |
| 942 yahoo_packet_hash(pkt, 10, buf); | |
| 943 yahoo_send_packet(yd, pkt); | |
| 944 yahoo_packet_free(pkt); | |
| 945 } | |
| 946 } | |
| 947 | |
| 948 static GList *yahoo_away_states(struct gaim_connection *gc) | |
| 949 { | |
| 950 GList *m = NULL; | |
| 951 | |
| 952 m = g_list_append(m, "Available"); | |
| 953 m = g_list_append(m, "Be Right Back"); | |
| 954 m = g_list_append(m, "Busy"); | |
| 955 m = g_list_append(m, "Not At Home"); | |
| 956 m = g_list_append(m, "Not At Desk"); | |
| 957 m = g_list_append(m, "Not In Office"); | |
| 958 m = g_list_append(m, "On Phone"); | |
| 959 m = g_list_append(m, "On Vacation"); | |
| 960 m = g_list_append(m, "Out To Lunch"); | |
| 961 m = g_list_append(m, "Stepped Out"); | |
| 962 m = g_list_append(m, "Invisible"); | |
| 963 m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
| 964 | |
| 965 return m; | |
| 966 } | |
| 967 | |
| 968 static void yahoo_keepalive(struct gaim_connection *gc) | |
| 969 { | |
| 970 struct yahoo_data *yd = gc->proto_data; | |
| 971 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0); | |
| 972 yahoo_send_packet(yd, pkt); | |
| 973 yahoo_packet_free(pkt); | |
| 974 } | |
| 975 | |
| 976 static void yahoo_add_buddy(struct gaim_connection *gc, char *who) | |
| 977 { | |
| 978 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 979 struct yahoo_packet *pkt; | |
| 980 struct group *g; | |
| 981 char *group = NULL; | |
| 982 | |
| 983 if (!yd->logged_in) | |
| 984 return; | |
| 985 | |
| 986 g = find_group_by_buddy(gc, who); | |
| 987 if (g) | |
| 988 group = g->name; | |
| 989 else | |
| 990 group = "Buddies"; | |
| 991 | |
| 992 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
| 993 yahoo_packet_hash(pkt, 1, gc->displayname); | |
| 994 yahoo_packet_hash(pkt, 7, who); | |
| 995 yahoo_packet_hash(pkt, 65, group); | |
| 996 yahoo_send_packet(yd, pkt); | |
| 997 yahoo_packet_free(pkt); | |
| 998 } | |
| 999 | |
| 1000 static void yahoo_remove_buddy(struct gaim_connection *gc, char *who, char *group) | |
| 1001 { | |
| 1002 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 1003 | |
| 1004 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
| 1005 yahoo_packet_hash(pkt, 1, gc->displayname); | |
| 1006 yahoo_packet_hash(pkt, 7, who); | |
| 1007 yahoo_packet_hash(pkt, 65, group); | |
| 1008 yahoo_send_packet(yd, pkt); | |
| 1009 yahoo_packet_free(pkt); | |
| 1010 } | |
| 1011 | |
| 1012 static struct prpl *my_protocol = NULL; | |
| 1013 | |
| 1014 void yahoo_init(struct prpl *ret) { | |
| 1015 ret->protocol = PROTO_YAHOO; | |
| 1016 ret->options = OPT_PROTO_MAIL_CHECK; | |
| 1017 ret->name = yahoo_name; | |
| 1018 ret->user_opts = yahoo_user_opts; | |
| 1019 ret->login = yahoo_login; | |
| 1020 ret->close = yahoo_close; | |
| 1021 ret->buddy_menu = yahoo_buddy_menu; | |
| 1022 ret->list_icon = yahoo_list_icon; | |
| 1023 ret->actions = yahoo_actions; | |
| 1024 ret->do_action = yahoo_do_action; | |
| 1025 ret->send_im = yahoo_send_im; | |
| 1026 ret->away_states = yahoo_away_states; | |
| 1027 ret->set_away = yahoo_set_away; | |
| 1028 ret->set_idle = yahoo_set_idle; | |
| 1029 ret->keepalive = yahoo_keepalive; | |
| 1030 ret->add_buddy = yahoo_add_buddy; | |
| 1031 ret->remove_buddy = yahoo_remove_buddy; | |
| 1032 | |
| 1033 my_protocol = ret; | |
| 1034 } | |
| 1035 | |
| 1036 #ifndef STATIC | |
| 1037 | |
| 1038 char *gaim_plugin_init(GModule *handle) | |
| 1039 { | |
| 1040 load_protocol(yahoo_init, sizeof(struct prpl)); | |
| 1041 return NULL; | |
| 1042 } | |
| 1043 | |
| 1044 void gaim_plugin_remove() | |
| 1045 { | |
| 1046 struct prpl *p = find_prpl(PROTO_YAHOO); | |
| 1047 if (p == my_protocol) | |
| 1048 unload_protocol(p); | |
| 1049 } | |
| 1050 | |
| 1051 char *name() | |
| 1052 { | |
| 1053 return "Yahoo"; | |
| 1054 } | |
| 1055 | |
| 1056 char *description() | |
| 1057 { | |
| 1058 return PRPL_DESC("Yahoo"); | |
| 1059 } | |
| 1060 | |
| 1061 #endif |
