Mercurial > pidgin
annotate src/protocols/yahoo/yahoo.c @ 3484:5d1dff030d8b
[gaim-migrate @ 3538]
Another nice patch from Etan Reisner.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Sat, 31 Aug 2002 02:40:51 +0000 |
| parents | 79e0d2f8ad2b |
| children | 4b204c262376 |
| 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" | |
| 3147 | 44 #include "md5.h" |
| 2681 | 45 |
|
2795
536bb833fdeb
[gaim-migrate @ 2808]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2786
diff
changeset
|
46 extern char *yahoo_crypt(char *, char *); |
|
536bb833fdeb
[gaim-migrate @ 2808]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2786
diff
changeset
|
47 |
| 2681 | 48 #include "pixmaps/status-away.xpm" |
| 49 #include "pixmaps/status-here.xpm" | |
| 50 #include "pixmaps/status-idle.xpm" | |
| 3019 | 51 #include "pixmaps/status-game.xpm" |
| 2681 | 52 |
| 3035 | 53 /* Yahoo Smilies go here */ |
| 54 #include "pixmaps/protocols/yahoo/yahoo_alien.xpm" | |
| 55 #include "pixmaps/protocols/yahoo/yahoo_angel.xpm" | |
| 56 #include "pixmaps/protocols/yahoo/yahoo_angry.xpm" | |
| 57 #include "pixmaps/protocols/yahoo/yahoo_bigsmile.xpm" | |
| 58 #include "pixmaps/protocols/yahoo/yahoo_blush.xpm" | |
| 59 #include "pixmaps/protocols/yahoo/yahoo_bye.xpm" | |
| 60 #include "pixmaps/protocols/yahoo/yahoo_clown.xpm" | |
| 61 #include "pixmaps/protocols/yahoo/yahoo_cow.xpm" | |
| 62 #include "pixmaps/protocols/yahoo/yahoo_cowboy.xpm" | |
| 63 #include "pixmaps/protocols/yahoo/yahoo_cry.xpm" | |
| 64 #include "pixmaps/protocols/yahoo/yahoo_devil.xpm" | |
| 65 #include "pixmaps/protocols/yahoo/yahoo_flower.xpm" | |
| 66 #include "pixmaps/protocols/yahoo/yahoo_ghost.xpm" | |
| 67 #include "pixmaps/protocols/yahoo/yahoo_glasses.xpm" | |
| 68 #include "pixmaps/protocols/yahoo/yahoo_laughloud.xpm" | |
| 69 #include "pixmaps/protocols/yahoo/yahoo_love.xpm" | |
| 70 #include "pixmaps/protocols/yahoo/yahoo_mean.xpm" | |
| 71 #include "pixmaps/protocols/yahoo/yahoo_neutral.xpm" | |
| 72 #include "pixmaps/protocols/yahoo/yahoo_ooooh.xpm" | |
| 73 #include "pixmaps/protocols/yahoo/yahoo_question.xpm" | |
| 74 #include "pixmaps/protocols/yahoo/yahoo_sad.xpm" | |
| 75 #include "pixmaps/protocols/yahoo/yahoo_sleep.xpm" | |
| 76 #include "pixmaps/protocols/yahoo/yahoo_smiley.xpm" | |
| 77 #include "pixmaps/protocols/yahoo/yahoo_sunglas.xpm" | |
| 78 #include "pixmaps/protocols/yahoo/yahoo_tongue.xpm" | |
| 79 #include "pixmaps/protocols/yahoo/yahoo_wink.xpm" | |
| 80 | |
| 2993 | 81 #define YAHOO_DEBUG |
| 2681 | 82 |
| 83 #define USEROPT_MAIL 0 | |
| 84 | |
| 85 #define USEROPT_PAGERHOST 3 | |
| 3147 | 86 #define YAHOO_PAGER_HOST "scs.yahoo.com" |
| 2681 | 87 #define USEROPT_PAGERPORT 4 |
| 88 #define YAHOO_PAGER_PORT 5050 | |
| 89 | |
| 3467 | 90 #define YAHOO_PROTO_VER 0x0900 |
| 91 | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
92 enum yahoo_service { /* these are easier to see in hex */ |
| 2681 | 93 YAHOO_SERVICE_LOGON = 1, |
| 94 YAHOO_SERVICE_LOGOFF, | |
| 95 YAHOO_SERVICE_ISAWAY, | |
| 96 YAHOO_SERVICE_ISBACK, | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
97 YAHOO_SERVICE_IDLE, /* 5 (placemarker) */ |
| 2681 | 98 YAHOO_SERVICE_MESSAGE, |
| 99 YAHOO_SERVICE_IDACT, | |
| 100 YAHOO_SERVICE_IDDEACT, | |
| 101 YAHOO_SERVICE_MAILSTAT, | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
102 YAHOO_SERVICE_USERSTAT, /* 0xa */ |
| 2681 | 103 YAHOO_SERVICE_NEWMAIL, |
| 104 YAHOO_SERVICE_CHATINVITE, | |
| 105 YAHOO_SERVICE_CALENDAR, | |
| 106 YAHOO_SERVICE_NEWPERSONALMAIL, | |
| 107 YAHOO_SERVICE_NEWCONTACT, | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
108 YAHOO_SERVICE_ADDIDENT, /* 0x10 */ |
| 2681 | 109 YAHOO_SERVICE_ADDIGNORE, |
| 110 YAHOO_SERVICE_PING, | |
| 111 YAHOO_SERVICE_GROUPRENAME, | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
112 YAHOO_SERVICE_SYSMESSAGE = 0x14, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
113 YAHOO_SERVICE_PASSTHROUGH2 = 0x16, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
114 YAHOO_SERVICE_CONFINVITE = 0x18, |
| 2681 | 115 YAHOO_SERVICE_CONFLOGON, |
| 116 YAHOO_SERVICE_CONFDECLINE, | |
| 117 YAHOO_SERVICE_CONFLOGOFF, | |
| 118 YAHOO_SERVICE_CONFADDINVITE, | |
| 119 YAHOO_SERVICE_CONFMSG, | |
| 120 YAHOO_SERVICE_CHATLOGON, | |
| 121 YAHOO_SERVICE_CHATLOGOFF, | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
122 YAHOO_SERVICE_CHATMSG = 0x20, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
123 YAHOO_SERVICE_GAMELOGON = 0x28, |
|
2786
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
124 YAHOO_SERVICE_GAMELOGOFF, |
|
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
125 YAHOO_SERVICE_GAMEMSG = 0x2a, |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
126 YAHOO_SERVICE_FILETRANSFER = 0x46, |
| 3019 | 127 YAHOO_SERVICE_NOTIFY = 0x4B, |
| 3147 | 128 YAHOO_SERVICE_AUTHRESP = 0x54, |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
129 YAHOO_SERVICE_LIST = 0x55, |
| 3147 | 130 YAHOO_SERVICE_AUTH = 0x57, |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
131 YAHOO_SERVICE_ADDBUDDY = 0x83, |
|
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
132 YAHOO_SERVICE_REMBUDDY = 0x84 |
| 2681 | 133 }; |
| 134 | |
| 135 enum yahoo_status { | |
|
2686
7b21c5446baf
[gaim-migrate @ 2699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2683
diff
changeset
|
136 YAHOO_STATUS_AVAILABLE = 0, |
| 2681 | 137 YAHOO_STATUS_BRB, |
| 138 YAHOO_STATUS_BUSY, | |
| 139 YAHOO_STATUS_NOTATHOME, | |
| 140 YAHOO_STATUS_NOTATDESK, | |
| 141 YAHOO_STATUS_NOTINOFFICE, | |
| 142 YAHOO_STATUS_ONPHONE, | |
| 143 YAHOO_STATUS_ONVACATION, | |
| 144 YAHOO_STATUS_OUTTOLUNCH, | |
| 145 YAHOO_STATUS_STEPPEDOUT, | |
| 146 YAHOO_STATUS_INVISIBLE = 12, | |
| 147 YAHOO_STATUS_CUSTOM = 99, | |
| 148 YAHOO_STATUS_IDLE = 999, | |
| 2993 | 149 YAHOO_STATUS_OFFLINE = 0x5a55aa56, /* don't ask */ |
| 150 YAHOO_STATUS_TYPING = 0x16 | |
| 2681 | 151 }; |
| 3019 | 152 #define YAHOO_STATUS_GAME 0x2 /* Games don't fit into the regular status model */ |
| 2681 | 153 |
| 154 struct yahoo_data { | |
| 155 int fd; | |
| 156 guchar *rxqueue; | |
| 157 int rxlen; | |
| 158 GHashTable *hash; | |
| 3019 | 159 GHashTable *games; |
| 2681 | 160 int current_status; |
| 161 gboolean logged_in; | |
| 162 }; | |
| 163 | |
| 164 struct yahoo_pair { | |
| 165 int key; | |
| 166 char *value; | |
| 167 }; | |
| 168 | |
| 169 struct yahoo_packet { | |
| 170 guint16 service; | |
| 171 guint32 status; | |
| 172 guint32 id; | |
| 173 GSList *hash; | |
| 174 }; | |
| 175 | |
| 176 static char *yahoo_name() { | |
| 177 return "Yahoo"; | |
| 178 } | |
| 179 | |
| 180 #define YAHOO_PACKET_HDRLEN (4 + 2 + 2 + 2 + 2 + 4 + 4) | |
| 181 | |
| 182 static struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id) | |
| 183 { | |
| 184 struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1); | |
| 185 | |
| 186 pkt->service = service; | |
| 187 pkt->status = status; | |
| 188 pkt->id = id; | |
| 189 | |
| 190 return pkt; | |
| 191 } | |
| 192 | |
| 3466 | 193 static void yahoo_packet_hash(struct yahoo_packet *pkt, int key, const char *value) |
| 2681 | 194 { |
| 195 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
| 196 pair->key = key; | |
| 197 pair->value = g_strdup(value); | |
| 198 pkt->hash = g_slist_append(pkt->hash, pair); | |
| 199 } | |
| 200 | |
| 201 static int yahoo_packet_length(struct yahoo_packet *pkt) | |
| 202 { | |
| 203 GSList *l; | |
| 204 | |
| 205 int len = 0; | |
| 206 | |
| 207 l = pkt->hash; | |
| 208 while (l) { | |
| 209 struct yahoo_pair *pair = l->data; | |
| 210 int tmp = pair->key; | |
| 211 do { | |
| 212 tmp /= 10; | |
| 213 len++; | |
| 214 } while (tmp); | |
| 215 len += 2; | |
| 216 len += strlen(pair->value); | |
| 217 len += 2; | |
| 218 l = l->next; | |
| 219 } | |
| 220 | |
| 221 return len; | |
| 222 } | |
| 223 | |
| 224 /* sometimes i wish prpls could #include things from other prpls. then i could just | |
| 225 * use the routines from libfaim and not have to admit to knowing how they work. */ | |
| 226 #define yahoo_put16(buf, data) ( \ | |
| 227 (*(buf) = (u_char)((data)>>8)&0xff), \ | |
| 228 (*((buf)+1) = (u_char)(data)&0xff), \ | |
| 229 2) | |
| 230 #define yahoo_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff)) | |
| 231 #define yahoo_put32(buf, data) ( \ | |
| 232 (*((buf)) = (u_char)((data)>>24)&0xff), \ | |
| 233 (*((buf)+1) = (u_char)((data)>>16)&0xff), \ | |
| 234 (*((buf)+2) = (u_char)((data)>>8)&0xff), \ | |
| 235 (*((buf)+3) = (u_char)(data)&0xff), \ | |
| 236 4) | |
| 237 #define yahoo_get32(buf) ((((*(buf))<<24)&0xff000000) + \ | |
| 238 (((*((buf)+1))<<16)&0x00ff0000) + \ | |
| 239 (((*((buf)+2))<< 8)&0x0000ff00) + \ | |
| 240 (((*((buf)+3) )&0x000000ff))) | |
| 241 | |
| 242 static void yahoo_packet_read(struct yahoo_packet *pkt, guchar *data, int len) | |
| 243 { | |
| 244 int pos = 0; | |
| 245 | |
| 246 while (pos + 1 < len) { | |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
247 char key[64], *value = NULL; |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
248 int accept; |
| 2681 | 249 int x; |
| 250 | |
| 251 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
| 252 | |
| 253 x = 0; | |
| 254 while (pos + 1 < len) { | |
| 255 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
| 256 break; | |
| 257 key[x++] = data[pos++]; | |
| 258 } | |
| 259 key[x] = 0; | |
| 260 pos += 2; | |
| 261 pair->key = strtol(key, NULL, 10); | |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
262 accept = x; /* if x is 0 there was no key, so don't accept it */ |
| 2681 | 263 |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
264 if (accept) |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
265 value = g_malloc(len - pos + 1); |
| 2681 | 266 x = 0; |
| 267 while (pos + 1 < len) { | |
| 268 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
| 269 break; | |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
270 if (accept) |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
271 value[x++] = data[pos++]; |
| 2681 | 272 } |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
273 if (accept) |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
274 value[x] = 0; |
| 2681 | 275 pos += 2; |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
276 if (accept) { |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
277 pair->value = g_strdup(value); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
278 g_free(value); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
279 pkt->hash = g_slist_append(pkt->hash, pair); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
280 debug_printf("Key: %d \tValue: %s\n", pair->key, pair->value); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
281 } else { |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
282 g_free(pair); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
283 } |
| 2681 | 284 } |
| 285 } | |
| 286 | |
| 287 static void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data) | |
| 288 { | |
| 289 GSList *l = pkt->hash; | |
| 290 int pos = 0; | |
| 291 | |
| 292 while (l) { | |
| 293 struct yahoo_pair *pair = l->data; | |
| 294 guchar buf[100]; | |
| 295 | |
| 296 g_snprintf(buf, sizeof(buf), "%d", pair->key); | |
| 297 strcpy(data + pos, buf); | |
| 298 pos += strlen(buf); | |
| 299 data[pos++] = 0xc0; | |
| 300 data[pos++] = 0x80; | |
| 301 | |
| 302 strcpy(data + pos, pair->value); | |
| 303 pos += strlen(pair->value); | |
| 304 data[pos++] = 0xc0; | |
| 305 data[pos++] = 0x80; | |
| 306 | |
| 307 l = l->next; | |
| 308 } | |
| 309 } | |
| 310 | |
| 311 static void yahoo_packet_dump(guchar *data, int len) | |
| 312 { | |
| 313 #ifdef YAHOO_DEBUG | |
| 314 int i; | |
| 315 for (i = 0; i + 1 < len; i += 2) { | |
| 316 if ((i % 16 == 0) && i) | |
| 317 debug_printf("\n"); | |
| 318 debug_printf("%02x", data[i]); | |
| 319 debug_printf("%02x ", data[i+1]); | |
| 320 } | |
| 321 if (i < len) | |
| 322 debug_printf("%02x", data[i]); | |
| 323 debug_printf("\n"); | |
| 324 for (i = 0; i < len; i++) { | |
| 325 if ((i % 16 == 0) && i) | |
| 326 debug_printf("\n"); | |
| 327 if (isprint(data[i])) | |
| 328 debug_printf("%c ", data[i]); | |
| 329 else | |
| 330 debug_printf(". "); | |
| 331 } | |
| 332 debug_printf("\n"); | |
| 333 #endif | |
| 334 } | |
| 335 | |
| 336 static int yahoo_send_packet(struct yahoo_data *yd, struct yahoo_packet *pkt) | |
| 337 { | |
| 338 int pktlen = yahoo_packet_length(pkt); | |
| 339 int len = YAHOO_PACKET_HDRLEN + pktlen; | |
| 340 int ret; | |
| 341 | |
| 342 guchar *data; | |
| 343 int pos = 0; | |
| 344 | |
| 345 if (yd->fd < 0) | |
| 346 return -1; | |
| 347 | |
| 348 data = g_malloc0(len + 1); | |
| 349 | |
| 350 memcpy(data + pos, "YMSG", 4); pos += 4; | |
| 3467 | 351 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); |
| 2681 | 352 pos += yahoo_put16(data + pos, 0x0000); |
| 353 pos += yahoo_put16(data + pos, pktlen); | |
| 354 pos += yahoo_put16(data + pos, pkt->service); | |
| 355 pos += yahoo_put32(data + pos, pkt->status); | |
| 356 pos += yahoo_put32(data + pos, pkt->id); | |
| 357 | |
| 358 yahoo_packet_write(pkt, data + pos); | |
| 359 | |
| 360 yahoo_packet_dump(data, len); | |
| 361 ret = write(yd->fd, data, len); | |
| 362 | |
| 363 g_free(data); | |
| 364 | |
| 365 return ret; | |
| 366 } | |
| 367 | |
| 368 static void yahoo_packet_free(struct yahoo_packet *pkt) | |
| 369 { | |
| 370 while (pkt->hash) { | |
| 371 struct yahoo_pair *pair = pkt->hash->data; | |
| 372 g_free(pair->value); | |
| 373 g_free(pair); | |
| 374 pkt->hash = g_slist_remove(pkt->hash, pair); | |
| 375 } | |
| 376 g_free(pkt); | |
| 377 } | |
| 378 | |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
379 static void yahoo_process_status(struct gaim_connection *gc, struct yahoo_packet *pkt) |
| 2681 | 380 { |
| 381 struct yahoo_data *yd = gc->proto_data; | |
| 382 GSList *l = pkt->hash; | |
| 383 char *name = NULL; | |
| 384 int state = 0; | |
| 3019 | 385 int gamestate = 0; |
| 2681 | 386 char *msg = NULL; |
| 3019 | 387 |
| 2681 | 388 while (l) { |
| 389 struct yahoo_pair *pair = l->data; | |
| 390 | |
| 391 switch (pair->key) { | |
| 392 case 0: /* we won't actually do anything with this */ | |
| 393 break; | |
| 394 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
|
395 if (!yd->logged_in) { |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
396 account_online(gc); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
397 serv_finish_login(gc); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
398 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", pair->value); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
399 yd->logged_in = TRUE; |
| 2681 | 400 |
| 3147 | 401 /* this requests the list. i have a feeling that this is very evil |
| 402 * | |
| 403 * scs.yahoo.com sends you the list before this packet without it being | |
| 404 * requested | |
| 405 * | |
| 406 * do_import(gc, NULL); | |
| 407 * newpkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_OFFLINE, 0); | |
| 408 * yahoo_send_packet(yd, newpkt); | |
| 409 * yahoo_packet_free(newpkt); | |
| 410 */ | |
| 411 | |
| 412 } | |
| 2681 | 413 break; |
| 414 case 8: /* how many online buddies we have */ | |
| 415 break; | |
| 416 case 7: /* the current buddy */ | |
| 417 name = pair->value; | |
| 418 break; | |
| 419 case 10: /* state */ | |
| 420 state = strtol(pair->value, NULL, 10); | |
| 421 break; | |
| 422 case 19: /* custom message */ | |
| 423 msg = pair->value; | |
| 424 break; | |
| 425 case 11: /* i didn't know what this was in the old protocol either */ | |
| 426 break; | |
| 427 case 17: /* in chat? */ | |
| 428 break; | |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
429 case 13: /* in pager? */ |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
430 if (pkt->service == YAHOO_SERVICE_LOGOFF || |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
431 strtol(pair->value, NULL, 10) == 0) { |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
432 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
|
433 break; |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
434 } |
| 3019 | 435 if (g_hash_table_lookup(yd->games, name)) |
| 436 gamestate = YAHOO_STATUS_GAME; | |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
437 if (state == YAHOO_STATUS_AVAILABLE) |
| 3019 | 438 serv_got_update(gc, name, 1, 0, 0, 0, gamestate, 0); |
| 3147 | 439 else |
| 3019 | 440 serv_got_update(gc, name, 1, 0, 0, 0, (state << 2) | UC_UNAVAILABLE | gamestate, 0); |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
441 if (state == YAHOO_STATUS_CUSTOM) { |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
442 gpointer val = g_hash_table_lookup(yd->hash, name); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
443 if (val) { |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
444 g_free(val); |
|
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
445 g_hash_table_insert(yd->hash, name, |
|
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
446 msg ? g_strdup(msg) : g_malloc0(1)); |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
447 } else |
|
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
448 g_hash_table_insert(yd->hash, g_strdup(name), |
|
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
449 msg ? g_strdup(msg) : g_malloc0(1)); |
|
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
450 } |
|
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
451 break; |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
452 case 60: /* no clue */ |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
453 break; |
| 2979 | 454 case 16: /* Custom error message */ |
| 3427 | 455 do_error_dialog(pair->value, NULL, GAIM_ERROR); |
| 2951 | 456 break; |
| 2681 | 457 default: |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
458 debug_printf("unknown status key %d\n", pair->key); |
| 2681 | 459 break; |
| 460 } | |
| 461 | |
| 462 l = l->next; | |
| 463 } | |
| 464 } | |
| 465 | |
| 466 static void yahoo_process_list(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
| 467 { | |
| 468 GSList *l = pkt->hash; | |
| 469 gboolean export = FALSE; | |
| 470 | |
| 471 while (l) { | |
| 472 char **lines; | |
| 473 char **split; | |
| 474 char **buddies; | |
| 475 char **tmp, **bud; | |
| 476 | |
| 477 struct yahoo_pair *pair = l->data; | |
| 478 l = l->next; | |
| 479 | |
| 480 if (pair->key != 87) | |
| 481 continue; | |
| 482 | |
| 3147 | 483 do_import(gc, NULL); |
| 2681 | 484 lines = g_strsplit(pair->value, "\n", -1); |
| 485 for (tmp = lines; *tmp; tmp++) { | |
| 486 split = g_strsplit(*tmp, ":", 2); | |
|
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
487 if (!split) |
|
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
488 continue; |
|
2702
94b4271b9567
[gaim-migrate @ 2715]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2697
diff
changeset
|
489 if (!split[0] || !split[1]) { |
|
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
490 g_strfreev(split); |
|
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
491 continue; |
|
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
492 } |
| 2681 | 493 buddies = g_strsplit(split[1], ",", -1); |
|
2697
7759f914a009
[gaim-migrate @ 2710]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
494 for (bud = buddies; bud && *bud; bud++) |
| 2681 | 495 if (!find_buddy(gc, *bud)) { |
| 496 add_buddy(gc, split[0], *bud, *bud); | |
| 497 export = TRUE; | |
| 498 } | |
| 499 g_strfreev(buddies); | |
| 500 g_strfreev(split); | |
| 501 } | |
| 502 g_strfreev(lines); | |
| 503 } | |
| 504 | |
| 505 if (export) | |
| 506 do_export(gc); | |
| 507 } | |
| 508 | |
| 3019 | 509 static void yahoo_process_notify(struct gaim_connection *gc, struct yahoo_packet *pkt) |
| 2993 | 510 { |
| 511 char *msg = NULL; | |
| 512 char *from = NULL; | |
| 3019 | 513 char *stat = NULL; |
| 514 char *game = NULL; | |
| 2993 | 515 GSList *l = pkt->hash; |
| 3019 | 516 struct yahoo_data *yd = (struct yahoo_data*) gc->proto_data; |
| 2993 | 517 while (l) { |
| 518 struct yahoo_pair *pair = l->data; | |
| 519 if (pair->key == 4) | |
| 520 from = pair->value; | |
| 521 if (pair->key == 49) | |
| 522 msg = pair->value; | |
| 3001 | 523 if (pair->key == 13) |
| 3019 | 524 stat = pair->value; |
| 525 if (pair->key == 14) | |
| 526 game = pair->value; | |
| 2993 | 527 l = l->next; |
| 528 } | |
| 3019 | 529 |
| 530 if (!g_strncasecmp(msg, "TYPING", strlen("TYPING"))) { | |
| 531 if (*stat == '1') | |
| 532 serv_got_typing(gc, from, 0); | |
| 533 else | |
| 534 serv_got_typing_stopped(gc, from); | |
| 535 } else if (!g_strncasecmp(msg, "GAME", strlen("GAME"))) { | |
| 536 struct buddy *bud = find_buddy(gc, from); | |
| 537 void *free1=NULL, *free2=NULL; | |
| 3020 | 538 if (!bud) |
| 3019 | 539 debug_printf("%s is playing a game, and doesn't want you to know.\n"); |
| 540 if (*stat == '1') { | |
| 541 if (g_hash_table_lookup_extended (yd->games, from, free1, free2)) { | |
| 542 g_free(free1); | |
| 543 g_free(free2); | |
| 544 } | |
| 545 g_hash_table_insert (yd->games, g_strdup(from), g_strdup(game)); | |
| 3020 | 546 if (bud) |
| 547 serv_got_update(gc, from, 1, 0, 0, 0, bud->uc | YAHOO_STATUS_GAME, 0); | |
| 3019 | 548 } else { |
| 549 if (g_hash_table_lookup_extended (yd->games, from, free1, free2)) { | |
| 550 g_free(free1); | |
| 551 g_free(free2); | |
| 552 g_hash_table_remove (yd->games, from); | |
| 553 } | |
| 3020 | 554 if (bud) |
| 555 serv_got_update(gc, from, 1, 0, 0, 0, bud->uc & ~YAHOO_STATUS_GAME, 0); | |
| 3019 | 556 } |
| 557 } | |
| 2993 | 558 } |
| 559 | |
| 2681 | 560 static void yahoo_process_message(struct gaim_connection *gc, struct yahoo_packet *pkt) |
| 561 { | |
| 562 char *msg = NULL; | |
| 563 char *from = NULL; | |
| 564 time_t tm = time(NULL); | |
| 565 GSList *l = pkt->hash; | |
| 3021 | 566 |
| 2681 | 567 while (l) { |
| 568 struct yahoo_pair *pair = l->data; | |
| 569 if (pair->key == 4) | |
| 570 from = pair->value; | |
| 571 if (pair->key == 14) | |
| 572 msg = pair->value; | |
| 573 if (pair->key == 15) | |
| 574 tm = strtol(pair->value, NULL, 10); | |
| 575 l = l->next; | |
| 576 } | |
| 577 | |
| 3021 | 578 if (pkt->status <= 1 || pkt->status == 5) { |
|
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
579 char *m; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
580 int i, j; |
| 2681 | 581 strip_linefeed(msg); |
|
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
582 m = msg; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
583 for (i = 0, j = 0; m[i]; i++) { |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
584 if (m[i] == 033) { |
|
2813
bda5b89ba2f9
[gaim-migrate @ 2826]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2807
diff
changeset
|
585 while (m[i] && (m[i] != 'm')) |
|
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
586 i++; |
|
2813
bda5b89ba2f9
[gaim-migrate @ 2826]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2807
diff
changeset
|
587 if (!m[i]) |
|
bda5b89ba2f9
[gaim-migrate @ 2826]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2807
diff
changeset
|
588 i--; |
|
2715
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
589 continue; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
590 } |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
591 msg[j++] = m[i]; |
|
e901fd3ebbad
[gaim-migrate @ 2728]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2708
diff
changeset
|
592 } |
|
2813
bda5b89ba2f9
[gaim-migrate @ 2826]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2807
diff
changeset
|
593 msg[j] = 0; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2850
diff
changeset
|
594 serv_got_im(gc, from, msg, 0, tm, -1); |
| 2681 | 595 } else if (pkt->status == 2) { |
| 3427 | 596 do_error_dialog(_("Your Yahoo! message did not get sent."), NULL, GAIM_ERROR); |
| 2681 | 597 } |
| 598 } | |
| 599 | |
| 600 | |
| 601 static void yahoo_process_contact(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
| 602 { | |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
603 struct yahoo_data *yd = gc->proto_data; |
| 2681 | 604 char *id = NULL; |
| 605 char *who = NULL; | |
| 606 char *msg = NULL; | |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
607 char *name = NULL; |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
608 int state = YAHOO_STATUS_AVAILABLE; |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
609 int online = FALSE; |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
610 |
| 2681 | 611 GSList *l = pkt->hash; |
| 612 | |
| 613 while (l) { | |
| 614 struct yahoo_pair *pair = l->data; | |
| 615 if (pair->key == 1) | |
| 616 id = pair->value; | |
| 617 else if (pair->key == 3) | |
| 618 who = pair->value; | |
| 619 else if (pair->key == 14) | |
| 620 msg = pair->value; | |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
621 else if (pair->key == 7) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
622 name = pair->value; |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
623 else if (pair->key == 10) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
624 state = strtol(pair->value, NULL, 10); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
625 else if (pair->key == 13) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
626 online = strtol(pair->value, NULL, 10); |
| 2681 | 627 l = l->next; |
| 628 } | |
| 629 | |
|
2682
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
630 if (id) |
|
db2b0b733732
[gaim-migrate @ 2695]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
631 show_got_added(gc, id, who, NULL, msg); |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
632 if (name) { |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
633 if (state == YAHOO_STATUS_AVAILABLE) |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
634 serv_got_update(gc, name, 1, 0, 0, 0, 0, 0); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
635 else if (state == YAHOO_STATUS_IDLE) |
| 3019 | 636 serv_got_update(gc, name, 1, 0, 0, time(NULL) - 600, (state << 2), 0); |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
637 else |
| 3019 | 638 serv_got_update(gc, name, 1, 0, 0, 0, (state << 2) | UC_UNAVAILABLE, 0); |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
639 if (state == YAHOO_STATUS_CUSTOM) { |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
640 gpointer val = g_hash_table_lookup(yd->hash, name); |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
641 if (val) { |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
642 g_free(val); |
|
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
643 g_hash_table_insert(yd->hash, name, |
|
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
644 msg ? g_strdup(msg) : g_malloc0(1)); |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
645 } else |
|
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
646 g_hash_table_insert(yd->hash, g_strdup(name), |
|
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
647 msg ? g_strdup(msg) : g_malloc0(1)); |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
648 } |
|
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
649 } |
| 2681 | 650 } |
| 651 | |
| 652 static void yahoo_process_mail(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
| 653 { | |
| 654 char *who = NULL; | |
| 655 char *email = NULL; | |
| 656 char *subj = NULL; | |
| 657 int count = 0; | |
| 658 GSList *l = pkt->hash; | |
| 659 | |
| 660 while (l) { | |
| 661 struct yahoo_pair *pair = l->data; | |
| 662 if (pair->key == 9) | |
| 663 count = strtol(pair->value, NULL, 10); | |
| 664 else if (pair->key == 43) | |
| 665 who = pair->value; | |
| 666 else if (pair->key == 42) | |
| 667 email = pair->value; | |
| 668 else if (pair->key == 18) | |
| 669 subj = pair->value; | |
| 670 l = l->next; | |
| 671 } | |
| 672 | |
|
2850
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
673 if (who && email && subj) { |
|
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
674 char *from = g_strdup_printf("%s (%s)", who, email); |
|
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
675 connection_has_mail(gc, -1, from, subj, "http://mail.yahoo.com/"); |
|
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
676 g_free(from); |
|
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
677 } else |
|
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
678 connection_has_mail(gc, count, NULL, NULL, "http://mail.yahoo.com/"); |
| 2681 | 679 } |
| 3147 | 680 /* This is the y64 alphabet... it's like base64, but has a . and a _ */ |
| 681 char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; | |
| 682 | |
| 683 /* This is taken from Sylpheed by Hiroyuki Yamamoto. We have our own tobase64 function | |
| 684 * in util.c, but it has a bug I don't feel like finding right now ;) */ | |
| 685 void to_y64(unsigned char *out, const unsigned char *in, int inlen) | |
| 686 /* raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) */ | |
| 687 { | |
| 688 for (; inlen >= 3; inlen -= 3) | |
| 689 { | |
| 690 *out++ = base64digits[in[0] >> 2]; | |
| 691 *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)]; | |
| 692 *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; | |
| 693 *out++ = base64digits[in[2] & 0x3f]; | |
| 694 in += 3; | |
| 695 } | |
| 696 if (inlen > 0) | |
| 697 { | |
| 698 unsigned char fragment; | |
| 699 | |
| 700 *out++ = base64digits[in[0] >> 2]; | |
| 701 fragment = (in[0] << 4) & 0x30; | |
| 702 if (inlen > 1) | |
| 703 fragment |= in[1] >> 4; | |
| 704 *out++ = base64digits[fragment]; | |
| 705 *out++ = (inlen < 2) ? '-' : base64digits[(in[1] << 2) & 0x3c]; | |
| 706 *out++ = '-'; | |
| 707 } | |
| 708 *out = '\0'; | |
| 709 } | |
| 710 | |
| 711 static void yahoo_process_auth(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
| 712 { | |
| 713 char *seed = NULL; | |
| 714 char *sn = NULL; | |
| 715 GSList *l = pkt->hash; | |
| 716 struct yahoo_data *yd = gc->proto_data; | |
| 717 | |
| 718 while (l) { | |
| 719 struct yahoo_pair *pair = l->data; | |
| 720 if (pair->key == 94) | |
| 721 seed = pair->value; | |
| 722 if (pair->key == 1) | |
| 723 sn = pair->value; | |
| 724 l = l->next; | |
| 725 } | |
| 726 | |
| 727 if (seed) { | |
| 728 struct yahoo_packet *pack; | |
| 729 | |
| 730 /* So, Yahoo has stopped supporting its older clients in India, and undoubtedly | |
| 731 * will soon do so in the rest of the world. | |
| 732 * | |
| 733 * The new clients use this authentication method. I warn you in advance, it's | |
| 734 * bizzare, convoluted, inordinately complicated. It's also no more secure than | |
| 735 * crypt() was. The only purpose this scheme could serve is to prevent third | |
| 736 * part clients from connecting to their servers. | |
| 737 * | |
| 738 * Sorry, Yahoo. | |
| 739 */ | |
| 740 | |
| 741 md5_byte_t result[16]; | |
| 742 md5_state_t ctx; | |
| 743 char *crypt_result; | |
| 744 char *password_hash = g_malloc(25); | |
| 745 char *crypt_hash = g_malloc(25); | |
| 746 char *hash_string_p = g_malloc(50 + strlen(sn)); | |
| 747 char *hash_string_c = g_malloc(50 + strlen(sn)); | |
| 748 | |
| 749 char checksum; | |
| 750 | |
| 3157 | 751 int sv; |
| 3147 | 752 |
| 753 char *result6 = g_malloc(25); | |
| 754 char *result96 = g_malloc(25); | |
| 755 | |
| 756 sv = seed[15]; | |
| 3157 | 757 sv = sv % 8; |
| 3147 | 758 |
| 759 md5_init(&ctx); | |
| 760 md5_append(&ctx, gc->password, strlen(gc->password)); | |
| 761 md5_finish(&ctx, result); | |
| 762 to_y64(password_hash, result, 16); | |
| 763 | |
| 764 md5_init(&ctx); | |
| 765 crypt_result = yahoo_crypt(gc->password, "$1$_2S43d5f$"); | |
| 766 md5_append(&ctx, crypt_result, strlen(crypt_result)); | |
| 767 md5_finish(&ctx, result); | |
| 768 to_y64(crypt_hash, result, 16); | |
| 3157 | 769 |
| 770 switch (sv) { | |
| 3147 | 771 case 1: |
| 772 case 6: | |
| 3157 | 773 checksum = seed[seed[9] % 16]; |
| 3147 | 774 g_snprintf(hash_string_p, strlen(sn) + 50, |
| 3157 | 775 "%c%s%s%s", checksum, gc->username, seed, password_hash); |
| 776 g_snprintf(hash_string_c, strlen(sn) + 50, | |
| 3147 | 777 "%c%s%s%s", checksum, gc->username, seed, crypt_hash); |
| 778 break; | |
| 779 case 2: | |
| 780 case 7: | |
| 3157 | 781 checksum = seed[seed[15] % 16]; |
| 3147 | 782 g_snprintf(hash_string_p, strlen(sn) + 50, |
| 3157 | 783 "%c%s%s%s", checksum, seed, password_hash, gc->username); |
| 784 g_snprintf(hash_string_c, strlen(sn) + 50, | |
| 785 "%c%s%s%s", checksum, seed, crypt_hash, gc->username); | |
| 786 break; | |
| 3147 | 787 case 3: |
| 3157 | 788 checksum = seed[seed[1] % 16]; |
| 3147 | 789 g_snprintf(hash_string_p, strlen(sn) + 50, |
| 3157 | 790 "%c%s%s%s", checksum, gc->username, password_hash, seed); |
| 791 g_snprintf(hash_string_c, strlen(sn) + 50, | |
| 792 "%c%s%s%s", checksum, gc->username, crypt_hash, seed); | |
| 793 break; | |
| 794 case 4: | |
| 795 checksum = seed[seed[3] % 16]; | |
| 796 g_snprintf(hash_string_p, strlen(sn) + 50, | |
| 797 "%c%s%s%s", checksum, password_hash, seed, gc->username); | |
| 3147 | 798 g_snprintf(hash_string_c, strlen(sn) + 50, |
| 3157 | 799 "%c%s%s%s", checksum, crypt_hash, seed, gc->username); |
| 800 break; | |
| 3147 | 801 case 0: |
| 802 case 5: | |
| 3157 | 803 checksum = seed[seed[7] % 16]; |
| 3147 | 804 g_snprintf(hash_string_p, strlen(sn) + 50, |
| 3157 | 805 "%c%s%s%s", checksum, password_hash, gc->username, seed); |
| 806 g_snprintf(hash_string_c, strlen(sn) + 50, | |
| 3147 | 807 "%c%s%s%s", checksum, crypt_hash, gc->username, seed); |
| 3157 | 808 break; |
| 3147 | 809 } |
| 3157 | 810 |
| 3147 | 811 md5_init(&ctx); |
| 3157 | 812 md5_append(&ctx, hash_string_p, strlen(hash_string_p)); |
| 3147 | 813 md5_finish(&ctx, result); |
| 814 to_y64(result6, result, 16); | |
| 815 | |
| 816 md5_init(&ctx); | |
| 817 md5_append(&ctx, hash_string_c, strlen(hash_string_c)); | |
| 818 md5_finish(&ctx, result); | |
| 819 to_y64(result96, result, 16); | |
| 820 | |
| 821 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0); | |
| 822 yahoo_packet_hash(pack, 0, gc->username); | |
| 823 yahoo_packet_hash(pack, 6, result6); | |
| 824 yahoo_packet_hash(pack, 96, result96); | |
| 825 yahoo_packet_hash(pack, 1, gc->username); | |
| 826 | |
| 827 yahoo_send_packet(yd, pack); | |
| 828 | |
| 829 g_free(password_hash); | |
| 830 g_free(crypt_hash); | |
| 831 g_free(hash_string_p); | |
| 832 g_free(hash_string_c); | |
| 833 | |
| 834 yahoo_packet_free(pack); | |
| 835 } | |
| 836 } | |
| 2681 | 837 |
| 838 static void yahoo_packet_process(struct gaim_connection *gc, struct yahoo_packet *pkt) | |
| 839 { | |
| 840 switch (pkt->service) | |
| 841 { | |
| 842 case YAHOO_SERVICE_LOGON: | |
|
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
843 case YAHOO_SERVICE_LOGOFF: |
| 2681 | 844 case YAHOO_SERVICE_ISAWAY: |
|
2737
f61c1f3a6afa
[gaim-migrate @ 2750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2724
diff
changeset
|
845 case YAHOO_SERVICE_ISBACK: |
| 3019 | 846 case YAHOO_SERVICE_GAMELOGON: |
| 847 case YAHOO_SERVICE_GAMELOGOFF: | |
| 2681 | 848 yahoo_process_status(gc, pkt); |
| 849 break; | |
| 3019 | 850 case YAHOO_SERVICE_NOTIFY: |
| 851 yahoo_process_notify(gc, pkt); | |
| 2993 | 852 break; |
| 2681 | 853 case YAHOO_SERVICE_MESSAGE: |
|
2786
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
854 case YAHOO_SERVICE_GAMEMSG: |
| 2681 | 855 yahoo_process_message(gc, pkt); |
| 856 break; | |
| 857 case YAHOO_SERVICE_NEWMAIL: | |
| 858 yahoo_process_mail(gc, pkt); | |
| 859 break; | |
| 860 case YAHOO_SERVICE_NEWCONTACT: | |
| 861 yahoo_process_contact(gc, pkt); | |
| 862 break; | |
| 863 case YAHOO_SERVICE_LIST: | |
| 864 yahoo_process_list(gc, pkt); | |
| 865 break; | |
| 3147 | 866 case YAHOO_SERVICE_AUTH: |
| 867 yahoo_process_auth(gc, pkt); | |
| 868 break; | |
| 2681 | 869 default: |
|
2741
38cb5fa48bec
[gaim-migrate @ 2754]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2737
diff
changeset
|
870 debug_printf("unhandled service 0x%02x\n", pkt->service); |
| 2681 | 871 break; |
| 872 } | |
| 873 } | |
| 874 | |
| 875 static void yahoo_pending(gpointer data, gint source, GaimInputCondition cond) | |
| 876 { | |
| 877 struct gaim_connection *gc = data; | |
| 878 struct yahoo_data *yd = gc->proto_data; | |
| 879 char buf[1024]; | |
| 880 int len; | |
| 881 | |
| 882 len = read(yd->fd, buf, sizeof(buf)); | |
| 883 | |
| 884 if (len <= 0) { | |
| 3074 | 885 hide_login_progress_error(gc, "Unable to read"); |
| 2681 | 886 signoff(gc); |
| 887 return; | |
| 888 } | |
| 889 | |
| 890 yd->rxqueue = g_realloc(yd->rxqueue, len + yd->rxlen); | |
| 891 memcpy(yd->rxqueue + yd->rxlen, buf, len); | |
| 892 yd->rxlen += len; | |
| 893 | |
| 894 while (1) { | |
| 895 struct yahoo_packet *pkt; | |
| 896 int pos = 0; | |
| 897 int pktlen; | |
| 898 | |
| 899 if (yd->rxlen < YAHOO_PACKET_HDRLEN) | |
| 900 return; | |
| 901 | |
| 902 pos += 4; /* YMSG */ | |
| 903 pos += 2; | |
| 904 pos += 2; | |
| 905 | |
| 906 pktlen = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
| 907 debug_printf("%d bytes to read, rxlen is %d\n", pktlen, yd->rxlen); | |
| 908 | |
| 909 if (yd->rxlen < (YAHOO_PACKET_HDRLEN + pktlen)) | |
| 910 return; | |
| 911 | |
| 912 yahoo_packet_dump(yd->rxqueue, YAHOO_PACKET_HDRLEN + pktlen); | |
| 913 | |
| 914 pkt = yahoo_packet_new(0, 0, 0); | |
| 915 | |
| 916 pkt->service = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
| 3021 | 917 pkt->status = yahoo_get32(yd->rxqueue + pos); pos += 4; |
|
2741
38cb5fa48bec
[gaim-migrate @ 2754]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2737
diff
changeset
|
918 debug_printf("Yahoo Service: 0x%02x Status: %d\n", pkt->service, pkt->status); |
| 2681 | 919 pkt->id = yahoo_get32(yd->rxqueue + pos); pos += 4; |
| 920 | |
| 921 yahoo_packet_read(pkt, yd->rxqueue + pos, pktlen); | |
| 922 | |
| 923 yd->rxlen -= YAHOO_PACKET_HDRLEN + pktlen; | |
| 924 if (yd->rxlen) { | |
| 925 char *tmp = g_memdup(yd->rxqueue + YAHOO_PACKET_HDRLEN + pktlen, yd->rxlen); | |
| 926 g_free(yd->rxqueue); | |
| 927 yd->rxqueue = tmp; | |
| 928 } else { | |
| 929 g_free(yd->rxqueue); | |
| 930 yd->rxqueue = NULL; | |
| 931 } | |
| 932 | |
| 933 yahoo_packet_process(gc, pkt); | |
| 934 | |
| 935 yahoo_packet_free(pkt); | |
| 936 } | |
| 937 } | |
| 938 | |
| 939 static void yahoo_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
| 940 { | |
| 941 struct gaim_connection *gc = data; | |
| 942 struct yahoo_data *yd; | |
| 943 struct yahoo_packet *pkt; | |
| 944 | |
| 945 if (!g_slist_find(connections, gc)) { | |
| 946 close(source); | |
| 947 return; | |
| 948 } | |
| 949 | |
| 950 if (source < 0) { | |
| 951 hide_login_progress(gc, "Unable to connect"); | |
| 952 signoff(gc); | |
| 953 return; | |
| 954 } | |
| 955 | |
| 956 yd = gc->proto_data; | |
| 957 yd->fd = source; | |
| 958 | |
| 3147 | 959 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YAHOO_STATUS_AVAILABLE, 0); |
| 2681 | 960 |
| 961 yahoo_packet_hash(pkt, 1, gc->username); | |
| 962 yahoo_send_packet(yd, pkt); | |
| 963 | |
| 964 yahoo_packet_free(pkt); | |
| 965 | |
| 966 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | |
| 967 } | |
| 968 | |
| 969 static void yahoo_login(struct aim_user *user) { | |
| 970 struct gaim_connection *gc = new_gaim_conn(user); | |
| 971 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); | |
| 972 | |
| 973 set_login_progress(gc, 1, "Connecting"); | |
| 974 | |
| 975 yd->fd = -1; | |
| 976 yd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
| 3019 | 977 yd->games = g_hash_table_new(g_str_hash, g_str_equal); |
| 2681 | 978 |
| 3193 | 979 |
| 980 if (!g_strncasecmp(user->proto_opt[USEROPT_PAGERHOST], "cs.yahoo.com", strlen("cs.yahoo.com"))) { | |
| 981 /* Figured out the new auth method -- cs.yahoo.com likes to disconnect on buddy remove and add now */ | |
| 2951 | 982 debug_printf("Setting new Yahoo! server.\n"); |
| 3193 | 983 g_snprintf(user->proto_opt[USEROPT_PAGERHOST], strlen("scs.yahoo.com") + 1, "scs.yahoo.com"); |
| 2951 | 984 save_prefs(); |
| 985 } | |
| 3147 | 986 |
| 987 | |
| 2951 | 988 if (proxy_connect(user->proto_opt[USEROPT_PAGERHOST][0] ? |
| 2681 | 989 user->proto_opt[USEROPT_PAGERHOST] : YAHOO_PAGER_HOST, |
| 990 user->proto_opt[USEROPT_PAGERPORT][0] ? | |
| 991 atoi(user->proto_opt[USEROPT_PAGERPORT]) : YAHOO_PAGER_PORT, | |
|
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2687
diff
changeset
|
992 yahoo_got_connected, gc) < 0) { |
| 2681 | 993 hide_login_progress(gc, "Connection problem"); |
| 994 signoff(gc); | |
| 995 return; | |
| 996 } | |
| 997 | |
| 998 } | |
| 999 | |
| 1000 static gboolean yahoo_destroy_hash(gpointer key, gpointer val, gpointer data) | |
| 1001 { | |
| 1002 g_free(key); | |
| 1003 g_free(val); | |
| 1004 return TRUE; | |
| 1005 } | |
| 1006 | |
| 1007 static void yahoo_close(struct gaim_connection *gc) { | |
| 1008 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 1009 g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL); | |
| 1010 g_hash_table_destroy(yd->hash); | |
| 3019 | 1011 g_hash_table_foreach_remove(yd->games, yahoo_destroy_hash, NULL); |
| 1012 g_hash_table_destroy(yd->games); | |
| 2681 | 1013 if (yd->fd >= 0) |
| 1014 close(yd->fd); | |
| 1015 if (yd->rxqueue) | |
| 1016 g_free(yd->rxqueue); | |
|
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2686
diff
changeset
|
1017 yd->rxlen = 0; |
| 2681 | 1018 if (gc->inpa) |
| 1019 gaim_input_remove(gc->inpa); | |
| 1020 g_free(yd); | |
| 1021 } | |
| 1022 | |
| 1023 static char **yahoo_list_icon(int uc) | |
| 1024 { | |
| 3019 | 1025 if ((uc >> 2) == YAHOO_STATUS_IDLE) |
| 2681 | 1026 return status_idle_xpm; |
| 3019 | 1027 else if (uc & UC_UNAVAILABLE) |
| 1028 return status_away_xpm; | |
| 1029 else if (uc & YAHOO_STATUS_GAME) | |
| 1030 return status_game_xpm; | |
| 1031 return status_here_xpm; | |
| 2681 | 1032 } |
| 1033 | |
| 1034 static char *yahoo_get_status_string(enum yahoo_status a) | |
| 1035 { | |
| 1036 switch (a) { | |
| 1037 case YAHOO_STATUS_BRB: | |
| 1038 return "Be Right Back"; | |
| 1039 case YAHOO_STATUS_BUSY: | |
| 1040 return "Busy"; | |
| 1041 case YAHOO_STATUS_NOTATHOME: | |
| 1042 return "Not At Home"; | |
| 1043 case YAHOO_STATUS_NOTATDESK: | |
| 1044 return "Not At Desk"; | |
| 1045 case YAHOO_STATUS_NOTINOFFICE: | |
| 1046 return "Not In Office"; | |
| 1047 case YAHOO_STATUS_ONPHONE: | |
| 1048 return "On Phone"; | |
| 1049 case YAHOO_STATUS_ONVACATION: | |
| 1050 return "On Vacation"; | |
| 1051 case YAHOO_STATUS_OUTTOLUNCH: | |
| 1052 return "Out To Lunch"; | |
| 1053 case YAHOO_STATUS_STEPPEDOUT: | |
| 1054 return "Stepped Out"; | |
|
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
1055 case YAHOO_STATUS_INVISIBLE: |
|
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
1056 return "Invisible"; |
|
2879
5fc5123b7098
[gaim-migrate @ 2892]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2878
diff
changeset
|
1057 default: |
|
5fc5123b7098
[gaim-migrate @ 2892]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2878
diff
changeset
|
1058 return "Online"; |
| 2681 | 1059 } |
| 1060 } | |
| 1061 | |
| 3019 | 1062 static void yahoo_game(struct gaim_connection *gc, char *name) { |
| 1063 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 1064 char *game = g_hash_table_lookup(yd->games, name); | |
| 1065 char *t; | |
| 1066 char url[256]; | |
| 1067 | |
| 1068 if (!game) | |
| 1069 return; | |
| 1070 t = game = g_strdup(strstr(game, "ante?room=")); | |
| 1071 while (*t != '\t') | |
| 1072 t++; | |
| 1073 *t = 0; | |
| 1074 g_snprintf(url, sizeof url, "http://games.yahoo.com/games/%s", game); | |
| 1075 open_url(NULL, url); | |
| 1076 g_free(game); | |
| 1077 } | |
| 2681 | 1078 static GList *yahoo_buddy_menu(struct gaim_connection *gc, char *who) |
| 1079 { | |
| 1080 GList *m = NULL; | |
| 1081 struct proto_buddy_menu *pbm; | |
| 1082 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 1083 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, | |
| 1084 segfault and get the bug report. */ | |
| 1085 static char buf[1024]; | |
| 3019 | 1086 static char buf2[1024]; |
| 1087 | |
| 1088 if (b->uc & UC_UNAVAILABLE && b->uc >> 2 != YAHOO_STATUS_IDLE) { | |
| 1089 pbm = g_new0(struct proto_buddy_menu, 1); | |
| 1090 if ((b->uc >> 2) != YAHOO_STATUS_CUSTOM) | |
| 1091 g_snprintf(buf, sizeof buf, | |
| 1092 "Status: %s", yahoo_get_status_string(b->uc >> 2)); | |
| 1093 else | |
| 1094 g_snprintf(buf, sizeof buf, "Custom Status: %s", | |
| 1095 (char *)g_hash_table_lookup(yd->hash, b->name)); | |
| 1096 pbm->label = buf; | |
| 1097 pbm->callback = NULL; | |
| 1098 pbm->gc = gc; | |
| 1099 m = g_list_append(m, pbm); | |
| 1100 } | |
| 1101 | |
| 1102 if (b->uc | YAHOO_STATUS_GAME) { | |
| 1103 char *game = g_hash_table_lookup(yd->games, b->name); | |
| 1104 char *room; | |
| 1105 if (!game) | |
| 1106 return m; | |
| 1107 if (game) { | |
| 1108 char *t; | |
| 1109 pbm = g_new0(struct proto_buddy_menu, 1); | |
| 1110 if (!(room = strstr(game, "&follow="))) /* skip ahead to the url */ | |
| 1111 return NULL; | |
| 1112 while (*room && *room != '\t') /* skip to the tab */ | |
| 1113 room++; | |
| 1114 t = room++; /* room as now at the name */ | |
| 1115 while (*t != '\n') | |
| 1116 t++; /* replace the \n with a space */ | |
| 1117 *t = ' '; | |
| 1118 g_snprintf(buf2, sizeof buf2, "%s", room); | |
| 1119 pbm->label = buf2; | |
| 1120 pbm->callback = yahoo_game; | |
| 1121 pbm->gc = gc; | |
| 1122 m = g_list_append(m, pbm); | |
| 1123 } | |
| 1124 } | |
| 2681 | 1125 |
| 1126 return m; | |
| 1127 } | |
| 1128 | |
| 1129 static GList *yahoo_user_opts() | |
| 1130 { | |
| 1131 GList *m = NULL; | |
| 1132 struct proto_user_opt *puo; | |
| 1133 | |
| 1134 puo = g_new0(struct proto_user_opt, 1); | |
| 1135 puo->label = "Pager Host:"; | |
| 1136 puo->def = YAHOO_PAGER_HOST; | |
| 1137 puo->pos = USEROPT_PAGERHOST; | |
| 1138 m = g_list_append(m, puo); | |
| 1139 | |
| 1140 puo = g_new0(struct proto_user_opt, 1); | |
| 1141 puo->label = "Pager Port:"; | |
| 1142 puo->def = "5050"; | |
| 1143 puo->pos = USEROPT_PAGERPORT; | |
| 1144 m = g_list_append(m, puo); | |
| 1145 | |
| 1146 return m; | |
| 1147 } | |
| 1148 | |
| 1149 static void yahoo_act_id(gpointer data, char *entry) | |
| 1150 { | |
| 1151 struct gaim_connection *gc = data; | |
| 1152 struct yahoo_data *yd = gc->proto_data; | |
| 1153 | |
| 1154 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0); | |
| 1155 yahoo_packet_hash(pkt, 3, entry); | |
| 1156 yahoo_send_packet(yd, pkt); | |
| 1157 yahoo_packet_free(pkt); | |
| 1158 | |
| 1159 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", entry); | |
| 1160 } | |
| 1161 | |
| 1162 static void yahoo_do_action(struct gaim_connection *gc, char *act) | |
| 1163 { | |
| 1164 if (!strcmp(act, "Activate ID")) { | |
| 1165 do_prompt_dialog("Activate which ID:", gc->displayname, gc, yahoo_act_id, NULL); | |
| 1166 } | |
| 1167 } | |
| 1168 | |
| 1169 static GList *yahoo_actions() { | |
| 1170 GList *m = NULL; | |
| 1171 | |
| 1172 m = g_list_append(m, "Activate ID"); | |
| 1173 | |
| 1174 return m; | |
| 1175 } | |
| 1176 | |
| 3033 | 1177 static int yahoo_send_im(struct gaim_connection *gc, char *who, char *what, int len, int flags) |
| 2681 | 1178 { |
| 1179 struct yahoo_data *yd = gc->proto_data; | |
| 1180 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0); | |
| 1181 | |
| 1182 yahoo_packet_hash(pkt, 1, gc->displayname); | |
| 1183 yahoo_packet_hash(pkt, 5, who); | |
| 1184 yahoo_packet_hash(pkt, 14, what); | |
| 1185 | |
| 1186 yahoo_send_packet(yd, pkt); | |
| 1187 | |
| 1188 yahoo_packet_free(pkt); | |
| 1189 | |
| 1190 return 1; | |
| 1191 } | |
| 1192 | |
| 3001 | 1193 int yahoo_send_typing(struct gaim_connection *gc, char *who, int typ) |
| 2993 | 1194 { |
| 1195 struct yahoo_data *yd = gc->proto_data; | |
| 3019 | 1196 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0); |
| 2993 | 1197 yahoo_packet_hash(pkt, 49, "TYPING"); |
| 1198 yahoo_packet_hash(pkt, 1, gc->displayname); | |
| 1199 yahoo_packet_hash(pkt, 14, " "); | |
| 3001 | 1200 yahoo_packet_hash(pkt, 13, typ ? "1" : "0"); |
| 2993 | 1201 yahoo_packet_hash(pkt, 5, who); |
| 1202 yahoo_packet_hash(pkt, 1002, "1"); | |
| 1203 | |
| 1204 yahoo_send_packet(yd, pkt); | |
| 1205 | |
| 1206 yahoo_packet_free(pkt); | |
| 1207 | |
| 3001 | 1208 return 0; |
| 2993 | 1209 } |
| 1210 | |
| 2681 | 1211 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) |
| 1212 { | |
| 1213 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 1214 struct yahoo_packet *pkt; | |
|
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1215 int service; |
| 2681 | 1216 char s[4]; |
| 1217 | |
| 1218 gc->away = NULL; | |
| 1219 | |
| 1220 if (msg) { | |
| 1221 yd->current_status = YAHOO_STATUS_CUSTOM; | |
| 1222 gc->away = ""; | |
| 1223 } else if (state) { | |
| 1224 gc->away = ""; | |
| 1225 if (!strcmp(state, "Available")) { | |
| 1226 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 1227 gc->away = NULL; | |
| 1228 } else if (!strcmp(state, "Be Right Back")) { | |
| 1229 yd->current_status = YAHOO_STATUS_BRB; | |
| 1230 } else if (!strcmp(state, "Busy")) { | |
| 1231 yd->current_status = YAHOO_STATUS_BUSY; | |
| 1232 } else if (!strcmp(state, "Not At Home")) { | |
| 1233 yd->current_status = YAHOO_STATUS_NOTATHOME; | |
| 1234 } else if (!strcmp(state, "Not At Desk")) { | |
| 1235 yd->current_status = YAHOO_STATUS_NOTATDESK; | |
| 1236 } else if (!strcmp(state, "Not In Office")) { | |
| 1237 yd->current_status = YAHOO_STATUS_NOTINOFFICE; | |
| 1238 } else if (!strcmp(state, "On Phone")) { | |
| 1239 yd->current_status = YAHOO_STATUS_ONPHONE; | |
| 1240 } else if (!strcmp(state, "On Vacation")) { | |
| 1241 yd->current_status = YAHOO_STATUS_ONVACATION; | |
| 1242 } else if (!strcmp(state, "Out To Lunch")) { | |
| 1243 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; | |
| 1244 } else if (!strcmp(state, "Stepped Out")) { | |
| 1245 yd->current_status = YAHOO_STATUS_STEPPEDOUT; | |
| 1246 } else if (!strcmp(state, "Invisible")) { | |
| 1247 yd->current_status = YAHOO_STATUS_INVISIBLE; | |
| 1248 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
| 1249 if (gc->is_idle) { | |
| 1250 yd->current_status = YAHOO_STATUS_IDLE; | |
| 1251 } else { | |
| 1252 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 1253 } | |
| 1254 gc->away = NULL; | |
| 1255 } | |
| 1256 } else if (gc->is_idle) { | |
| 1257 yd->current_status = YAHOO_STATUS_IDLE; | |
| 1258 } else { | |
| 1259 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 1260 } | |
| 1261 | |
|
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1262 if (yd->current_status == YAHOO_STATUS_AVAILABLE) |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1263 service = YAHOO_SERVICE_ISBACK; |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1264 else |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1265 service = YAHOO_SERVICE_ISAWAY; |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
1266 pkt = yahoo_packet_new(service, yd->current_status, 0); |
| 2681 | 1267 g_snprintf(s, sizeof(s), "%d", yd->current_status); |
| 1268 yahoo_packet_hash(pkt, 10, s); | |
| 1269 if (yd->current_status == YAHOO_STATUS_CUSTOM) | |
| 1270 yahoo_packet_hash(pkt, 19, msg); | |
| 1271 | |
| 1272 yahoo_send_packet(yd, pkt); | |
| 1273 yahoo_packet_free(pkt); | |
| 1274 } | |
| 1275 | |
| 1276 static void yahoo_set_idle(struct gaim_connection *gc, int idle) | |
| 1277 { | |
| 1278 struct yahoo_data *yd = gc->proto_data; | |
| 1279 struct yahoo_packet *pkt = NULL; | |
| 1280 | |
| 1281 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
| 1282 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_IDLE, 0); | |
| 1283 yd->current_status = YAHOO_STATUS_IDLE; | |
| 1284 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
| 1285 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); | |
| 1286 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 1287 } | |
| 1288 | |
| 1289 if (pkt) { | |
| 1290 char buf[4]; | |
| 1291 g_snprintf(buf, sizeof(buf), "%d", yd->current_status); | |
| 1292 yahoo_packet_hash(pkt, 10, buf); | |
| 1293 yahoo_send_packet(yd, pkt); | |
| 1294 yahoo_packet_free(pkt); | |
| 1295 } | |
| 1296 } | |
| 1297 | |
| 1298 static GList *yahoo_away_states(struct gaim_connection *gc) | |
| 1299 { | |
| 1300 GList *m = NULL; | |
| 1301 | |
| 1302 m = g_list_append(m, "Available"); | |
| 1303 m = g_list_append(m, "Be Right Back"); | |
| 1304 m = g_list_append(m, "Busy"); | |
| 1305 m = g_list_append(m, "Not At Home"); | |
| 1306 m = g_list_append(m, "Not At Desk"); | |
| 1307 m = g_list_append(m, "Not In Office"); | |
| 1308 m = g_list_append(m, "On Phone"); | |
| 1309 m = g_list_append(m, "On Vacation"); | |
| 1310 m = g_list_append(m, "Out To Lunch"); | |
| 1311 m = g_list_append(m, "Stepped Out"); | |
| 1312 m = g_list_append(m, "Invisible"); | |
| 1313 m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
| 1314 | |
| 1315 return m; | |
| 1316 } | |
| 1317 | |
| 1318 static void yahoo_keepalive(struct gaim_connection *gc) | |
| 1319 { | |
| 1320 struct yahoo_data *yd = gc->proto_data; | |
| 1321 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0); | |
| 1322 yahoo_send_packet(yd, pkt); | |
| 1323 yahoo_packet_free(pkt); | |
| 1324 } | |
| 1325 | |
| 3466 | 1326 static void yahoo_add_buddy(struct gaim_connection *gc, const char *who) |
| 2681 | 1327 { |
| 1328 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 1329 struct yahoo_packet *pkt; | |
| 1330 struct group *g; | |
| 1331 char *group = NULL; | |
| 1332 | |
| 1333 if (!yd->logged_in) | |
| 1334 return; | |
| 1335 | |
| 1336 g = find_group_by_buddy(gc, who); | |
| 1337 if (g) | |
| 1338 group = g->name; | |
| 1339 else | |
| 1340 group = "Buddies"; | |
| 1341 | |
| 1342 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
| 1343 yahoo_packet_hash(pkt, 1, gc->displayname); | |
| 1344 yahoo_packet_hash(pkt, 7, who); | |
| 1345 yahoo_packet_hash(pkt, 65, group); | |
| 1346 yahoo_send_packet(yd, pkt); | |
| 1347 yahoo_packet_free(pkt); | |
| 1348 } | |
| 1349 | |
| 1350 static void yahoo_remove_buddy(struct gaim_connection *gc, char *who, char *group) | |
| 1351 { | |
| 1352 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 1353 | |
| 1354 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
| 1355 yahoo_packet_hash(pkt, 1, gc->displayname); | |
| 1356 yahoo_packet_hash(pkt, 7, who); | |
| 1357 yahoo_packet_hash(pkt, 65, group); | |
| 1358 yahoo_send_packet(yd, pkt); | |
| 1359 yahoo_packet_free(pkt); | |
| 1360 } | |
| 1361 | |
| 3035 | 1362 |
| 1363 GSList *yahoo_smiley_list() | |
| 1364 { | |
| 1365 GSList *smilies = NULL; | |
| 1366 | |
| 1367 smilies = add_smiley(smilies, "=:)", yahoo_alien, 1); | |
| 1368 smilies = add_smiley(smilies, "=:-)", yahoo_alien, 0); | |
| 1369 smilies = add_smiley(smilies, "o:)", yahoo_angel, 0); | |
| 1370 smilies = add_smiley(smilies, "o:-)", yahoo_angel, 0); | |
| 1371 smilies = add_smiley(smilies, "0:)", yahoo_angel, 0); | |
| 1372 smilies = add_smiley(smilies, "0:-)", yahoo_angel, 0); | |
| 1373 smilies = add_smiley(smilies, "X-(", yahoo_angry, 1); | |
| 1374 smilies = add_smiley(smilies, "X(", yahoo_angry, 0); | |
| 1375 smilies = add_smiley(smilies, "x-(", yahoo_angry, 0); | |
| 1376 smilies = add_smiley(smilies, "x(", yahoo_angry, 0); | |
| 1377 smilies = add_smiley(smilies, ":D", yahoo_bigsmile, 1); | |
| 1378 smilies = add_smiley(smilies, ":-D", yahoo_bigsmile, 0); | |
| 1379 smilies = add_smiley(smilies, ":\">", yahoo_blush, 1); | |
| 1380 smilies = add_smiley(smilies, "=;", yahoo_bye, 1); | |
| 1381 smilies = add_smiley(smilies, ":o)", yahoo_clown, 1); | |
| 1382 smilies = add_smiley(smilies, ":0)", yahoo_clown, 0); | |
| 1383 smilies = add_smiley(smilies, ":O)", yahoo_clown, 0); | |
| 1384 smilies = add_smiley(smilies, "<@:)", yahoo_clown, 0); | |
| 1385 smilies = add_smiley(smilies, "3:-0", yahoo_cow, 1); | |
| 1386 smilies = add_smiley(smilies, "3:-o", yahoo_cow, 0); | |
| 1387 smilies = add_smiley(smilies, "3:-O", yahoo_cow, 0); | |
| 1388 smilies = add_smiley(smilies, "3:O", yahoo_cow, 0); | |
| 1389 smilies = add_smiley(smilies, "<):)", yahoo_cowboy, 1); | |
| 1390 smilies = add_smiley(smilies, ":((", yahoo_cry, 1); | |
| 1391 smilies = add_smiley(smilies, ":-((", yahoo_cry, 0); | |
| 1392 smilies = add_smiley(smilies, ">:)", yahoo_devil, 1); | |
| 1393 smilies = add_smiley(smilies, "@};-", yahoo_flower, 1); | |
| 1394 smilies = add_smiley(smilies, "8-X", yahoo_ghost, 1); | |
| 1395 smilies = add_smiley(smilies, ":B", yahoo_glasses, 1); | |
| 1396 smilies = add_smiley(smilies, ":-B", yahoo_glasses, 0); | |
| 1397 smilies = add_smiley(smilies, ":))", yahoo_laughloud, 1); | |
| 1398 smilies = add_smiley(smilies, ":-))", yahoo_laughloud, 0); | |
| 1399 smilies = add_smiley(smilies, ":x", yahoo_love, 1); | |
| 1400 smilies = add_smiley(smilies, ":-x", yahoo_love, 0); | |
| 1401 smilies = add_smiley(smilies, ":X", yahoo_love, 0); | |
| 1402 smilies = add_smiley(smilies, ":-X", yahoo_love, 0); | |
| 1403 smilies = add_smiley(smilies, ":>", yahoo_mean, 1); | |
| 1404 smilies = add_smiley(smilies, ":->", yahoo_mean, 0); | |
| 1405 smilies = add_smiley(smilies, ":|", yahoo_neutral, 1); | |
| 1406 smilies = add_smiley(smilies, ":-|", yahoo_neutral, 0); | |
| 1407 smilies = add_smiley(smilies, ":O", yahoo_ooooh, 1); | |
| 1408 smilies = add_smiley(smilies, ":-O", yahoo_ooooh, 0); | |
| 1409 smilies = add_smiley(smilies, ":-\\", yahoo_question, 1); | |
| 1410 smilies = add_smiley(smilies, ":-/", yahoo_question, 0); | |
| 1411 smilies = add_smiley(smilies, ":(", yahoo_sad, 1); | |
| 1412 smilies = add_smiley(smilies, ":-(", yahoo_sad, 0); | |
| 1413 smilies = add_smiley(smilies, "I-)", yahoo_sleep, 1); | |
| 1414 smilies = add_smiley(smilies, "|-)", yahoo_sleep, 0); | |
| 1415 smilies = add_smiley(smilies, "I-|", yahoo_sleep, 0); | |
| 1416 smilies = add_smiley(smilies, ":)", yahoo_smiley, 1); | |
| 1417 smilies = add_smiley(smilies, ":-)", yahoo_smiley, 0); | |
| 1418 smilies = add_smiley(smilies, "(:", yahoo_smiley, 0); | |
| 1419 smilies = add_smiley(smilies, "(-:", yahoo_smiley, 0); | |
| 1420 smilies = add_smiley(smilies, "B-)", yahoo_sunglas, 1); | |
| 1421 smilies = add_smiley(smilies, ":-p", yahoo_tongue, 1); | |
| 1422 smilies = add_smiley(smilies, ":p", yahoo_tongue, 0); | |
| 1423 smilies = add_smiley(smilies, ":P", yahoo_tongue, 0); | |
| 1424 smilies = add_smiley(smilies, ":-P", yahoo_tongue, 0); | |
| 1425 smilies = add_smiley(smilies, ";)", yahoo_wink, 1); | |
| 1426 smilies = add_smiley(smilies, ";-)", yahoo_wink, 0); | |
| 1427 | |
| 1428 | |
| 1429 return smilies; | |
| 1430 } | |
| 1431 | |
| 2681 | 1432 static struct prpl *my_protocol = NULL; |
| 1433 | |
| 1434 void yahoo_init(struct prpl *ret) { | |
| 1435 ret->protocol = PROTO_YAHOO; | |
| 1436 ret->options = OPT_PROTO_MAIL_CHECK; | |
| 1437 ret->name = yahoo_name; | |
| 1438 ret->user_opts = yahoo_user_opts; | |
| 1439 ret->login = yahoo_login; | |
| 1440 ret->close = yahoo_close; | |
| 1441 ret->buddy_menu = yahoo_buddy_menu; | |
| 1442 ret->list_icon = yahoo_list_icon; | |
| 1443 ret->actions = yahoo_actions; | |
| 1444 ret->do_action = yahoo_do_action; | |
| 1445 ret->send_im = yahoo_send_im; | |
| 1446 ret->away_states = yahoo_away_states; | |
| 1447 ret->set_away = yahoo_set_away; | |
| 1448 ret->set_idle = yahoo_set_idle; | |
| 1449 ret->keepalive = yahoo_keepalive; | |
| 1450 ret->add_buddy = yahoo_add_buddy; | |
| 1451 ret->remove_buddy = yahoo_remove_buddy; | |
| 2993 | 1452 ret->send_typing = yahoo_send_typing; |
| 3035 | 1453 ret->smiley_list = yahoo_smiley_list; |
| 2681 | 1454 |
| 1455 my_protocol = ret; | |
| 1456 } | |
| 1457 | |
| 1458 #ifndef STATIC | |
| 1459 | |
| 1460 char *gaim_plugin_init(GModule *handle) | |
| 1461 { | |
| 1462 load_protocol(yahoo_init, sizeof(struct prpl)); | |
| 1463 return NULL; | |
| 1464 } | |
| 1465 | |
| 1466 void gaim_plugin_remove() | |
| 1467 { | |
| 1468 struct prpl *p = find_prpl(PROTO_YAHOO); | |
| 1469 if (p == my_protocol) | |
| 1470 unload_protocol(p); | |
| 1471 } | |
| 1472 | |
| 1473 char *name() | |
| 1474 { | |
| 1475 return "Yahoo"; | |
| 1476 } | |
| 1477 | |
| 1478 char *description() | |
| 1479 { | |
| 1480 return PRPL_DESC("Yahoo"); | |
| 1481 } | |
| 1482 | |
| 1483 #endif |
