Mercurial > pidgin
annotate src/protocols/yahoo/yahoo.c @ 9318:01c50436203e
[gaim-migrate @ 10126]
i think this is more intelligent scaling. it would certainly be hard for it to be less intelligent scaling
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Sat, 19 Jun 2004 17:34:29 +0000 |
| parents | 085190b9dd64 |
| children | f40233043b5a |
| rev | line source |
|---|---|
| 2681 | 1 /* |
| 2 * gaim | |
| 3 * | |
| 8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 * source distribution. | |
| 2681 | 7 * |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
23 #include "internal.h" |
| 2681 | 24 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
25 #include "account.h" |
|
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5590
diff
changeset
|
26 #include "accountopt.h" |
| 6760 | 27 #include "blist.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
28 #include "debug.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
29 #include "notify.h" |
| 6760 | 30 #include "privacy.h" |
| 2681 | 31 #include "prpl.h" |
| 32 #include "proxy.h" | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
33 #include "request.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
34 #include "server.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
35 #include "util.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
36 |
| 6986 | 37 #include "sha.h" |
| 6513 | 38 #include "yahoo.h" |
| 9278 | 39 #include "yahoo_friend.h" |
| 6729 | 40 #include "yahoochat.h" |
| 8349 | 41 #include "yahoo_auth.h" |
| 7651 | 42 #include "yahoo_filexfer.h" |
| 9306 | 43 #include "yahoo_picture.h" |
| 3147 | 44 #include "md5.h" |
| 2681 | 45 |
| 5583 | 46 extern char *yahoo_crypt(const char *, const char *); |
|
2795
536bb833fdeb
[gaim-migrate @ 2808]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2786
diff
changeset
|
47 |
|
5493
3e8487580024
[gaim-migrate @ 5889]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
48 /* #define YAHOO_DEBUG */ |
| 2681 | 49 |
| 9285 | 50 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *, GaimGroup *); |
| 9306 | 51 |
| 6784 | 52 |
| 6729 | 53 struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id) |
| 2681 | 54 { |
| 55 struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1); | |
| 56 | |
| 57 pkt->service = service; | |
| 58 pkt->status = status; | |
| 59 pkt->id = id; | |
| 60 | |
| 61 return pkt; | |
| 62 } | |
| 63 | |
| 6729 | 64 void yahoo_packet_hash(struct yahoo_packet *pkt, int key, const char *value) |
| 2681 | 65 { |
| 66 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
| 67 pair->key = key; | |
| 68 pair->value = g_strdup(value); | |
| 69 pkt->hash = g_slist_append(pkt->hash, pair); | |
| 70 } | |
| 71 | |
| 7651 | 72 int yahoo_packet_length(struct yahoo_packet *pkt) |
| 2681 | 73 { |
| 74 GSList *l; | |
| 75 | |
| 76 int len = 0; | |
| 77 | |
| 78 l = pkt->hash; | |
| 79 while (l) { | |
| 80 struct yahoo_pair *pair = l->data; | |
| 81 int tmp = pair->key; | |
| 82 do { | |
| 83 tmp /= 10; | |
| 84 len++; | |
| 85 } while (tmp); | |
| 86 len += 2; | |
| 87 len += strlen(pair->value); | |
| 88 len += 2; | |
| 89 l = l->next; | |
| 90 } | |
| 91 | |
| 92 return len; | |
| 93 } | |
| 94 | |
| 95 static void yahoo_packet_read(struct yahoo_packet *pkt, guchar *data, int len) | |
| 96 { | |
| 97 int pos = 0; | |
| 98 | |
| 99 while (pos + 1 < len) { | |
| 6629 | 100 char key[64], *value = NULL, *esc; |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
101 int accept; |
| 2681 | 102 int x; |
| 103 | |
| 104 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
| 105 | |
| 106 x = 0; | |
| 107 while (pos + 1 < len) { | |
| 108 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
| 109 break; | |
| 8118 | 110 if (x >= sizeof(key)-1) { |
| 111 x++; | |
| 8357 | 112 pos++; |
| 8118 | 113 continue; |
| 114 } | |
| 2681 | 115 key[x++] = data[pos++]; |
| 116 } | |
| 8118 | 117 if (x >= sizeof(key)-1) { |
| 118 x = 0; | |
| 119 } | |
| 2681 | 120 key[x] = 0; |
| 121 pos += 2; | |
| 122 pair->key = strtol(key, NULL, 10); | |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
123 accept = x; /* if x is 0 there was no key, so don't accept it */ |
| 2681 | 124 |
|
3996
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
125 if (len - pos + 1 <= 0) { |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
126 /* Truncated. Garbage or something. */ |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
127 accept = 0; |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
128 } |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
129 |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
130 if (accept) { |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
131 value = g_malloc(len - pos + 1); |
|
3996
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
132 x = 0; |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
133 while (pos + 1 < len) { |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
134 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
135 break; |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
136 value[x++] = data[pos++]; |
|
3996
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
137 } |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
138 value[x] = 0; |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
139 pair->value = g_strdup(value); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
140 g_free(value); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
141 pkt->hash = g_slist_append(pkt->hash, pair); |
| 6629 | 142 esc = g_strescape(pair->value, NULL); |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
143 gaim_debug(GAIM_DEBUG_MISC, "yahoo", |
| 6629 | 144 "Key: %d \tValue: %s\n", pair->key, esc); |
| 145 g_free(esc); | |
|
2724
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
146 } else { |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
147 g_free(pair); |
|
7f3f4aa114ad
[gaim-migrate @ 2737]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2723
diff
changeset
|
148 } |
|
3996
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
149 pos += 2; |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
150 |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
151 /* Skip over garbage we've noticed in the mail notifications */ |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
152 if (data[0] == '9' && data[pos] == 0x01) |
|
3fdfe7872118
[gaim-migrate @ 4191]
Christian Hammond <chipx86@chipx86.com>
parents:
3768
diff
changeset
|
153 pos++; |
| 2681 | 154 } |
| 155 } | |
| 156 | |
| 7651 | 157 void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data) |
| 2681 | 158 { |
| 159 GSList *l = pkt->hash; | |
| 160 int pos = 0; | |
| 161 | |
| 162 while (l) { | |
| 163 struct yahoo_pair *pair = l->data; | |
| 164 guchar buf[100]; | |
| 165 | |
| 166 g_snprintf(buf, sizeof(buf), "%d", pair->key); | |
| 167 strcpy(data + pos, buf); | |
| 168 pos += strlen(buf); | |
| 169 data[pos++] = 0xc0; | |
| 170 data[pos++] = 0x80; | |
| 171 | |
| 172 strcpy(data + pos, pair->value); | |
| 173 pos += strlen(pair->value); | |
| 174 data[pos++] = 0xc0; | |
| 175 data[pos++] = 0x80; | |
| 176 | |
| 177 l = l->next; | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 static void yahoo_packet_dump(guchar *data, int len) | |
| 182 { | |
| 183 #ifdef YAHOO_DEBUG | |
| 184 int i; | |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
185 |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
186 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
187 |
| 2681 | 188 for (i = 0; i + 1 < len; i += 2) { |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
189 if ((i % 16 == 0) && i) { |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
190 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
191 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
192 } |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
193 |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
194 gaim_debug(GAIM_DEBUG_MISC, NULL, "%02x%02x ", data[i], data[i + 1]); |
| 2681 | 195 } |
| 196 if (i < len) | |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
197 gaim_debug(GAIM_DEBUG_MISC, NULL, "%02x", data[i]); |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
198 |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
199 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
200 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
201 |
| 2681 | 202 for (i = 0; i < len; i++) { |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
203 if ((i % 16 == 0) && i) { |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
204 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
205 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
206 } |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
207 |
| 6686 | 208 if (g_ascii_isprint(data[i])) |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
209 gaim_debug(GAIM_DEBUG_MISC, NULL, "%c ", data[i]); |
| 2681 | 210 else |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
211 gaim_debug(GAIM_DEBUG_MISC, NULL, ". "); |
| 2681 | 212 } |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
213 |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
214 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); |
| 2681 | 215 #endif |
| 216 } | |
| 217 | |
| 6729 | 218 int yahoo_send_packet(struct yahoo_data *yd, struct yahoo_packet *pkt) |
| 2681 | 219 { |
| 220 int pktlen = yahoo_packet_length(pkt); | |
| 221 int len = YAHOO_PACKET_HDRLEN + pktlen; | |
| 222 int ret; | |
| 223 | |
| 224 guchar *data; | |
| 225 int pos = 0; | |
| 226 | |
| 227 if (yd->fd < 0) | |
| 228 return -1; | |
| 229 | |
| 230 data = g_malloc0(len + 1); | |
| 231 | |
| 232 memcpy(data + pos, "YMSG", 4); pos += 4; | |
| 3467 | 233 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); |
| 2681 | 234 pos += yahoo_put16(data + pos, 0x0000); |
| 235 pos += yahoo_put16(data + pos, pktlen); | |
| 236 pos += yahoo_put16(data + pos, pkt->service); | |
| 237 pos += yahoo_put32(data + pos, pkt->status); | |
| 238 pos += yahoo_put32(data + pos, pkt->id); | |
| 239 | |
| 240 yahoo_packet_write(pkt, data + pos); | |
| 241 | |
| 242 yahoo_packet_dump(data, len); | |
| 243 ret = write(yd->fd, data, len); | |
| 244 g_free(data); | |
| 245 | |
| 246 return ret; | |
| 247 } | |
| 248 | |
| 9306 | 249 int yahoo_send_packet_special(int fd, struct yahoo_packet *pkt, int pad) |
| 250 { | |
| 251 int pktlen = yahoo_packet_length(pkt); | |
| 252 int len = YAHOO_PACKET_HDRLEN + pktlen; | |
| 253 int ret; | |
| 254 | |
| 255 guchar *data; | |
| 256 int pos = 0; | |
| 257 | |
| 258 if (fd < 0) | |
| 259 return -1; | |
| 260 | |
| 261 data = g_malloc0(len + 1); | |
| 262 | |
| 263 memcpy(data + pos, "YMSG", 4); pos += 4; | |
| 264 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); | |
| 265 pos += yahoo_put16(data + pos, 0x0000); | |
| 266 pos += yahoo_put16(data + pos, pktlen + pad); | |
| 267 pos += yahoo_put16(data + pos, pkt->service); | |
| 268 pos += yahoo_put32(data + pos, pkt->status); | |
| 269 pos += yahoo_put32(data + pos, pkt->id); | |
| 270 | |
| 271 yahoo_packet_write(pkt, data + pos); | |
| 272 | |
| 273 ret = write(fd, data, len); | |
| 274 g_free(data); | |
| 275 | |
| 276 return ret; | |
| 277 } | |
| 278 | |
| 6729 | 279 void yahoo_packet_free(struct yahoo_packet *pkt) |
| 2681 | 280 { |
| 281 while (pkt->hash) { | |
| 282 struct yahoo_pair *pair = pkt->hash->data; | |
| 283 g_free(pair->value); | |
| 284 g_free(pair); | |
| 285 pkt->hash = g_slist_remove(pkt->hash, pair); | |
| 286 } | |
| 287 g_free(pkt); | |
| 288 } | |
| 289 | |
| 9278 | 290 static void yahoo_update_status(GaimConnection *gc, const char *name, YahooFriend *f) |
| 6784 | 291 { |
| 6840 | 292 int online = 1; |
| 293 | |
| 6784 | 294 if (!gc || !name || !f || !gaim_find_buddy(gaim_connection_get_account(gc), name)) |
| 295 return; | |
| 296 | |
| 6840 | 297 if (f->status == YAHOO_STATUS_OFFLINE) |
| 298 online = 0; | |
| 299 | |
| 300 serv_got_update(gc, name, online, 0, 0, f->idle, f->away ? UC_UNAVAILABLE : 0); | |
| 6784 | 301 } |
| 302 | |
| 5583 | 303 static void yahoo_process_status(GaimConnection *gc, struct yahoo_packet *pkt) |
| 2681 | 304 { |
| 305 struct yahoo_data *yd = gc->proto_data; | |
| 306 GSList *l = pkt->hash; | |
| 9278 | 307 YahooFriend *f = NULL; |
| 2681 | 308 char *name = NULL; |
| 6784 | 309 |
| 7892 | 310 if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) { |
| 8383 | 311 gc->wants_to_die = TRUE; |
| 7892 | 312 gaim_connection_error(gc, _("You have been logged off as you have logged in on a different machine or device.")); |
| 313 return; | |
| 314 } | |
| 6686 | 315 |
| 2681 | 316 while (l) { |
| 317 struct yahoo_pair *pair = l->data; | |
| 318 | |
| 319 switch (pair->key) { | |
| 320 case 0: /* we won't actually do anything with this */ | |
| 321 break; | |
| 322 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
|
323 if (!yd->logged_in) { |
| 7664 | 324 gaim_connection_set_display_name(gc, pair->value); |
| 5583 | 325 gaim_connection_set_state(gc, GAIM_CONNECTED); |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
326 serv_finish_login(gc); |
|
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
327 yd->logged_in = TRUE; |
| 9306 | 328 if (yd->picture_upload_todo) { |
| 329 yahoo_buddy_icon_upload(gc, yd->picture_upload_todo); | |
| 330 yd->picture_upload_todo = NULL; | |
| 331 } | |
| 2681 | 332 |
| 3147 | 333 /* this requests the list. i have a feeling that this is very evil |
| 334 * | |
| 6686 | 335 * scs.yahoo.com sends you the list before this packet without it being |
| 3147 | 336 * requested |
| 337 * | |
| 338 * do_import(gc, NULL); | |
| 339 * newpkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_OFFLINE, 0); | |
| 340 * yahoo_send_packet(yd, newpkt); | |
| 341 * yahoo_packet_free(newpkt); | |
| 342 */ | |
| 343 | |
| 344 } | |
| 2681 | 345 break; |
| 346 case 8: /* how many online buddies we have */ | |
| 347 break; | |
| 348 case 7: /* the current buddy */ | |
| 349 name = pair->value; | |
| 9279 | 350 f = yahoo_friend_find_or_new(gc, name); |
| 2681 | 351 break; |
| 352 case 10: /* state */ | |
| 6784 | 353 if (!f) |
| 354 break; | |
| 355 | |
| 356 f->status = strtol(pair->value, NULL, 10); | |
| 357 if ((f->status >= YAHOO_STATUS_BRB) && (f->status <= YAHOO_STATUS_STEPPEDOUT)) | |
| 358 f->away = 1; | |
| 359 else | |
| 360 f->away = 0; | |
| 361 if (f->status == YAHOO_STATUS_IDLE) | |
| 362 f->idle = time(NULL); | |
| 6804 | 363 else |
| 364 f->idle = 0; | |
| 9283 | 365 if (f->status != YAHOO_STATUS_CUSTOM) |
| 366 yahoo_friend_set_status_message(f, NULL); | |
| 6847 | 367 |
| 368 f->sms = 0; | |
| 2681 | 369 break; |
| 370 case 19: /* custom message */ | |
| 9283 | 371 if (f) |
| 372 yahoo_friend_set_status_message(f, yahoo_string_decode(gc, pair->value, FALSE)); | |
| 2681 | 373 break; |
| 6686 | 374 case 11: /* this is the buddy's session id */ |
| 2681 | 375 break; |
| 376 case 17: /* in chat? */ | |
| 377 break; | |
| 6784 | 378 case 47: /* is custom status away or not? 2=idle*/ |
| 379 if (!f) | |
| 380 break; | |
| 8441 | 381 |
| 382 /* I have no idea what it means when this is | |
| 383 * set when someone's available, but it doesn't | |
| 384 * mean idle. */ | |
| 385 if (f->status == YAHOO_STATUS_AVAILABLE) | |
| 386 break; | |
| 6784 | 387 f->away = strtol(pair->value, NULL, 10); |
| 388 if (f->away == 2) | |
| 389 f->idle = time(NULL); | |
| 6686 | 390 break; |
| 6784 | 391 case 138: /* either we're not idle, or we are but won't say how long */ |
| 392 if (!f) | |
| 393 break; | |
| 394 | |
| 395 if (f->idle) | |
| 396 f->idle = -1; | |
| 397 break; | |
| 398 case 137: /* usually idle time in seconds, sometimes login time */ | |
| 399 if (!f) | |
| 400 break; | |
| 401 | |
| 402 if (f->status != YAHOO_STATUS_AVAILABLE) | |
| 403 f->idle = time(NULL) - strtol(pair->value, NULL, 10); | |
| 6686 | 404 break; |
| 405 case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */ | |
| 6784 | 406 if (strtol(pair->value, NULL, 10) == 0) { |
| 407 if (f) | |
| 408 f->status = YAHOO_STATUS_OFFLINE; | |
| 4732 | 409 serv_got_update(gc, name, 0, 0, 0, 0, 0); |
|
2807
f01e6a425136
[gaim-migrate @ 2820]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2805
diff
changeset
|
410 break; |
|
2805
9b3c7d2a6e9a
[gaim-migrate @ 2818]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2795
diff
changeset
|
411 } |
| 6784 | 412 |
| 413 if (f) | |
| 414 yahoo_update_status(gc, name, f); | |
| 415 break; | |
| 416 case 60: /* SMS */ | |
| 417 if (f) { | |
| 418 f->sms = strtol(pair->value, NULL, 10); | |
| 419 yahoo_update_status(gc, name, f); | |
|
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
420 } |
|
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
421 break; |
| 9292 | 422 case 197: /* Avatars */ |
| 9277 | 423 { |
| 424 char *decoded, *tmp; | |
| 425 guint len; | |
| 426 | |
| 427 if (pair->value) { | |
| 428 gaim_base64_decode(pair->value, &decoded, &len); | |
| 429 if (len) { | |
| 430 tmp = gaim_str_binary_to_ascii(decoded, len); | |
| 431 gaim_debug_info("yahoo", "Got key 197, value = %s\n", tmp); | |
| 432 g_free(tmp); | |
| 433 } | |
| 434 g_free(decoded); | |
| 435 } | |
| 436 break; | |
| 437 } | |
| 9292 | 438 case 192: /* Pictures, aka Buddy Icons, checksum */ |
| 439 { | |
| 440 int cksum = strtol(pair->value, NULL, 10); | |
| 441 GaimBuddy *b; | |
| 442 | |
| 443 if (!name) | |
| 444 break; | |
| 445 | |
| 446 if (!cksum || (cksum == -1)) { | |
| 447 gaim_buddy_icons_set_for_user(gc->account, name, NULL, 0); | |
| 448 break; | |
| 449 } | |
| 450 | |
| 451 if (!f) | |
| 452 break; | |
| 453 b = gaim_find_buddy(gc->account, name); | |
| 454 yahoo_friend_set_buddy_icon_need_request(f, FALSE); | |
| 455 if (cksum != gaim_blist_node_get_int((GaimBlistNode*)b, YAHOO_ICON_CHECKSUM_KEY)) | |
| 9310 | 456 yahoo_send_picture_request(gc, name); |
| 9292 | 457 |
| 458 break; | |
| 459 } | |
| 2979 | 460 case 16: /* Custom error message */ |
| 7827 | 461 { |
| 462 char *tmp = yahoo_string_decode(gc, pair->value, TRUE); | |
| 463 gaim_notify_error(gc, NULL, tmp, NULL); | |
| 464 g_free(tmp); | |
| 465 } | |
| 2951 | 466 break; |
| 2681 | 467 default: |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
468 gaim_debug(GAIM_DEBUG_ERROR, "yahoo", |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
469 "Unknown status key %d\n", pair->key); |
| 2681 | 470 break; |
| 471 } | |
| 472 | |
| 473 l = l->next; | |
| 474 } | |
| 475 } | |
| 476 | |
| 9285 | 477 static void yahoo_do_group_check(GaimAccount *account, GHashTable *ht, const char *name, const char *group) |
| 6820 | 478 { |
| 479 GaimBuddy *b; | |
| 480 GaimGroup *g; | |
| 481 GSList *list, *i; | |
| 482 gboolean onlist = 0; | |
| 483 char *oname = NULL; | |
| 484 | |
| 9015 | 485 char **oname_p = &oname; |
| 486 GSList **list_p = &list; | |
| 487 | |
| 488 if (!g_hash_table_lookup_extended(ht, gaim_normalize(account, name), (gpointer *) oname_p, (gpointer *) list_p)) | |
| 6820 | 489 list = gaim_find_buddies(account, name); |
| 490 else | |
| 491 g_hash_table_steal(ht, name); | |
| 492 | |
| 493 for (i = list; i; i = i->next) { | |
| 494 b = i->data; | |
| 495 g = gaim_find_buddys_group(b); | |
| 496 if (!gaim_utf8_strcasecmp(group, g->name)) { | |
| 497 gaim_debug(GAIM_DEBUG_MISC, "yahoo", | |
| 498 "Oh good, %s is in the right group (%s).\n", name, group); | |
| 499 list = g_slist_delete_link(list, i); | |
| 500 onlist = 1; | |
| 501 break; | |
| 502 } | |
| 503 } | |
| 504 | |
| 505 if (!onlist) { | |
| 506 gaim_debug(GAIM_DEBUG_MISC, "yahoo", | |
| 507 "Uhoh, %s isn't on the list (or not in this group), adding him to group %s.\n", name, group); | |
| 508 if (!(g = gaim_find_group(group))) { | |
| 509 g = gaim_group_new(group); | |
| 510 gaim_blist_add_group(g, NULL); | |
| 511 } | |
| 512 b = gaim_buddy_new(account, name, NULL); | |
| 513 gaim_blist_add_buddy(b, NULL, g, NULL); | |
| 514 } | |
| 515 | |
| 516 if (list) { | |
| 517 if (!oname) | |
| 7823 | 518 oname = g_strdup(gaim_normalize(account, name)); |
| 6820 | 519 g_hash_table_insert(ht, oname, list); |
| 520 } else if (oname) | |
| 521 g_free(oname); | |
| 522 } | |
| 523 | |
| 524 static void yahoo_do_group_cleanup(gpointer key, gpointer value, gpointer user_data) | |
| 525 { | |
| 526 char *name = key; | |
| 527 GSList *list = value, *i; | |
| 528 GaimBuddy *b; | |
| 529 GaimGroup *g; | |
| 530 | |
| 531 for (i = list; i; i = i->next) { | |
| 532 b = i->data; | |
| 533 g = gaim_find_buddys_group(b); | |
| 534 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Deleting Buddy %s from group %s.\n", name, g->name); | |
| 535 gaim_blist_remove_buddy(b); | |
| 536 } | |
| 537 } | |
| 538 | |
| 7651 | 539 static char *_getcookie(char *rawcookie) |
| 540 { | |
| 541 char *cookie = NULL; | |
| 542 char *tmpcookie; | |
| 543 char *cookieend; | |
| 544 | |
| 545 if (strlen(rawcookie) < 2) | |
| 546 return NULL; | |
| 547 tmpcookie = g_strdup(rawcookie+2); | |
| 548 cookieend = strchr(tmpcookie, ';'); | |
| 549 | |
| 550 if (cookieend) | |
| 551 *cookieend = '\0'; | |
| 552 | |
| 553 cookie = g_strdup(tmpcookie); | |
| 554 g_free(tmpcookie); | |
| 555 | |
| 556 return cookie; | |
| 557 } | |
| 558 | |
| 559 static void yahoo_process_cookie(struct yahoo_data *yd, char *c) | |
| 560 { | |
| 561 if (c[0] == 'Y') { | |
| 562 if (yd->cookie_y) | |
| 563 g_free(yd->cookie_y); | |
| 564 yd->cookie_y = _getcookie(c); | |
| 565 } else if (c[0] == 'T') { | |
| 566 if (yd->cookie_t) | |
| 567 g_free(yd->cookie_t); | |
| 568 yd->cookie_t = _getcookie(c); | |
| 569 } | |
| 570 } | |
| 571 | |
| 5583 | 572 static void yahoo_process_list(GaimConnection *gc, struct yahoo_packet *pkt) |
| 2681 | 573 { |
| 574 GSList *l = pkt->hash; | |
| 575 gboolean export = FALSE; | |
| 6760 | 576 gboolean got_serv_list = FALSE; |
| 6695 | 577 GaimBuddy *b; |
| 578 GaimGroup *g; | |
| 9278 | 579 YahooFriend *f = NULL; |
| 6820 | 580 GaimAccount *account = gaim_connection_get_account(gc); |
| 6784 | 581 struct yahoo_data *yd = gc->proto_data; |
| 6820 | 582 GHashTable *ht; |
| 6784 | 583 |
| 584 char **lines; | |
| 585 char **split; | |
| 586 char **buddies; | |
| 7823 | 587 char **tmp, **bud, *norm_bud; |
| 7827 | 588 char *grp = NULL; |
| 2681 | 589 |
| 7651 | 590 if (pkt->id) |
| 591 yd->session_id = pkt->id; | |
| 592 | |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
593 while (l) { |
|
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
594 struct yahoo_pair *pair = l->data; |
|
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
595 l = l->next; |
|
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
596 |
| 6760 | 597 switch (pair->key) { |
| 598 case 87: | |
| 6784 | 599 if (!yd->tmp_serv_blist) |
| 600 yd->tmp_serv_blist = g_string_new(pair->value); | |
| 601 else | |
| 602 g_string_append(yd->tmp_serv_blist, pair->value); | |
| 6760 | 603 break; |
| 604 case 88: | |
| 6784 | 605 if (!yd->tmp_serv_ilist) |
| 606 yd->tmp_serv_ilist = g_string_new(pair->value); | |
| 607 else | |
| 608 g_string_append(yd->tmp_serv_ilist, pair->value); | |
| 6760 | 609 break; |
| 7651 | 610 case 59: /* cookies, yum */ |
| 611 yahoo_process_cookie(yd, pair->value); | |
| 612 break; | |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
613 } |
|
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
614 } |
| 2681 | 615 |
| 6784 | 616 if (pkt->status != 0) |
| 617 return; | |
| 618 | |
| 619 if (yd->tmp_serv_blist) { | |
| 6820 | 620 ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_slist_free); |
| 621 | |
| 6784 | 622 lines = g_strsplit(yd->tmp_serv_blist->str, "\n", -1); |
| 623 for (tmp = lines; *tmp; tmp++) { | |
| 624 split = g_strsplit(*tmp, ":", 2); | |
| 625 if (!split) | |
| 626 continue; | |
| 627 if (!split[0] || !split[1]) { | |
| 628 g_strfreev(split); | |
| 629 continue; | |
| 630 } | |
| 7827 | 631 grp = yahoo_string_decode(gc, split[0], FALSE); |
| 6784 | 632 buddies = g_strsplit(split[1], ",", -1); |
| 633 for (bud = buddies; bud && *bud; bud++) { | |
| 7823 | 634 norm_bud = g_strdup(gaim_normalize(account, *bud)); |
| 9279 | 635 f = yahoo_friend_find_or_new(gc, norm_bud); |
| 636 | |
| 7827 | 637 if (!(b = gaim_find_buddy(account, norm_bud))) { |
| 638 if (!(g = gaim_find_group(grp))) { | |
| 639 g = gaim_group_new(grp); | |
| 6784 | 640 gaim_blist_add_group(g, NULL); |
| 641 } | |
| 7823 | 642 b = gaim_buddy_new(account, norm_bud, NULL); |
| 6784 | 643 gaim_blist_add_buddy(b, NULL, g, NULL); |
| 644 export = TRUE; | |
| 6820 | 645 } |
| 6784 | 646 |
| 9285 | 647 yahoo_do_group_check(account, ht, norm_bud, grp); |
| 7823 | 648 g_free(norm_bud); |
| 6784 | 649 } |
| 650 g_strfreev(buddies); | |
| 651 g_strfreev(split); | |
| 7827 | 652 g_free(grp); |
| 6784 | 653 } |
| 654 g_strfreev(lines); | |
| 655 | |
| 656 g_string_free(yd->tmp_serv_blist, TRUE); | |
| 657 yd->tmp_serv_blist = NULL; | |
| 9285 | 658 g_hash_table_foreach(ht, yahoo_do_group_cleanup, NULL); |
| 6820 | 659 g_hash_table_destroy(ht); |
| 6784 | 660 } |
| 661 | |
| 662 | |
| 663 if (yd->tmp_serv_ilist) { | |
| 664 buddies = g_strsplit(yd->tmp_serv_ilist->str, ",", -1); | |
| 665 for (bud = buddies; bud && *bud; bud++) { | |
| 666 /* The server is already ignoring the user */ | |
| 667 got_serv_list = TRUE; | |
| 668 gaim_privacy_deny_add(gc->account, *bud, 1); | |
| 669 } | |
| 670 g_strfreev(buddies); | |
| 671 | |
| 672 g_string_free(yd->tmp_serv_ilist, TRUE); | |
| 673 yd->tmp_serv_ilist = NULL; | |
| 674 } | |
| 675 | |
| 676 if (got_serv_list) { | |
| 677 gc->account->perm_deny = 4; | |
| 678 serv_set_permit_deny(gc); | |
| 679 } | |
| 2681 | 680 } |
| 681 | |
| 5583 | 682 static void yahoo_process_notify(GaimConnection *gc, struct yahoo_packet *pkt) |
| 2993 | 683 { |
| 684 char *msg = NULL; | |
| 685 char *from = NULL; | |
| 3019 | 686 char *stat = NULL; |
| 687 char *game = NULL; | |
| 9278 | 688 YahooFriend *f = NULL; |
| 2993 | 689 GSList *l = pkt->hash; |
| 6784 | 690 |
| 2993 | 691 while (l) { |
| 692 struct yahoo_pair *pair = l->data; | |
| 693 if (pair->key == 4) | |
| 694 from = pair->value; | |
| 695 if (pair->key == 49) | |
| 696 msg = pair->value; | |
| 3001 | 697 if (pair->key == 13) |
| 3019 | 698 stat = pair->value; |
| 699 if (pair->key == 14) | |
| 700 game = pair->value; | |
| 2993 | 701 l = l->next; |
| 702 } | |
| 3640 | 703 |
| 6784 | 704 if (!from || !msg) |
| 3640 | 705 return; |
| 6686 | 706 |
| 4793 | 707 if (!g_ascii_strncasecmp(msg, "TYPING", strlen("TYPING"))) { |
| 3019 | 708 if (*stat == '1') |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
709 serv_got_typing(gc, from, 0, GAIM_TYPING); |
| 3019 | 710 else |
| 711 serv_got_typing_stopped(gc, from); | |
| 4793 | 712 } else if (!g_ascii_strncasecmp(msg, "GAME", strlen("GAME"))) { |
| 6695 | 713 GaimBuddy *bud = gaim_find_buddy(gc->account, from); |
| 6784 | 714 |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
715 if (!bud) { |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
716 gaim_debug(GAIM_DEBUG_WARNING, "yahoo", |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
717 "%s is playing a game, and doesn't want " |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
718 "you to know.\n", from); |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
719 } |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
720 |
| 9279 | 721 f = yahoo_friend_find(gc, from); |
| 6784 | 722 if (!f) |
| 723 return; /* if they're not on the list, don't bother */ | |
| 724 | |
| 9283 | 725 yahoo_friend_set_game(f, NULL); |
| 6784 | 726 |
| 3019 | 727 if (*stat == '1') { |
| 9283 | 728 yahoo_friend_set_game(f, game); |
| 3020 | 729 if (bud) |
| 6784 | 730 yahoo_update_status(gc, from, f); |
| 3019 | 731 } |
| 732 } | |
| 2993 | 733 } |
| 734 | |
| 7827 | 735 |
| 736 struct _yahoo_im { | |
| 737 char *from; | |
| 738 int time; | |
| 739 int utf8; | |
| 9284 | 740 int buddy_icon; |
| 7827 | 741 char *msg; |
| 742 }; | |
| 743 | |
| 5583 | 744 static void yahoo_process_message(GaimConnection *gc, struct yahoo_packet *pkt) |
| 2681 | 745 { |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
746 GSList *l = pkt->hash; |
| 7827 | 747 GSList *list = NULL; |
| 748 struct _yahoo_im *im = NULL; | |
| 6069 | 749 |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
750 if (pkt->status <= 1 || pkt->status == 5) { |
|
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
751 while (l) { |
|
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
752 struct yahoo_pair *pair = l->data; |
| 7827 | 753 if (pair->key == 4) { |
| 754 im = g_new0(struct _yahoo_im, 1); | |
| 755 list = g_slist_append(list, im); | |
| 756 im->from = pair->value; | |
| 757 im->time = time(NULL); | |
| 758 } | |
| 759 if (pair->key == 97) | |
| 760 if (im) | |
| 761 im->utf8 = strtol(pair->value, NULL, 10); | |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
762 if (pair->key == 15) |
| 7827 | 763 if (im) |
| 764 im->time = strtol(pair->value, NULL, 10); | |
| 9284 | 765 if (pair->key == 206) |
| 766 if (im) | |
| 767 im->buddy_icon = strtol(pair->value, NULL, 10); | |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
768 if (pair->key == 14) { |
| 7827 | 769 if (im) |
| 770 im->msg = pair->value; | |
| 6687 | 771 } |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
772 l = l->next; |
| 6687 | 773 } |
| 2681 | 774 } else if (pkt->status == 2) { |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5367
diff
changeset
|
775 gaim_notify_error(gc, NULL, |
|
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5367
diff
changeset
|
776 _("Your Yahoo! message did not get sent."), NULL); |
| 2681 | 777 } |
| 7827 | 778 |
| 779 for (l = list; l; l = l->next) { | |
| 9306 | 780 YahooFriend *f; |
| 7827 | 781 char *m, *m2; |
| 782 im = l->data; | |
| 783 | |
| 784 if (!im->from || !im->msg) { | |
| 785 g_free(im); | |
| 786 continue; | |
| 787 } | |
| 788 | |
| 789 m = yahoo_string_decode(gc, im->msg, im->utf8); | |
| 790 gaim_str_strip_cr(m); | |
| 8375 | 791 |
| 792 if (!strcmp(m, "<ding>")) { | |
| 793 GaimConversation *c = gaim_conversation_new(GAIM_CONV_IM, | |
| 794 gaim_connection_get_account(gc), im->from); | |
| 795 gaim_conv_im_write(GAIM_CONV_IM(c), "", _("Buzz!!"), GAIM_MESSAGE_NICK|GAIM_MESSAGE_RECV, | |
| 796 im->time); | |
| 797 g_free(m); | |
| 798 g_free(im); | |
| 799 continue; | |
| 800 } | |
| 801 | |
| 7827 | 802 m2 = yahoo_codes_to_html(m); |
| 803 g_free(m); | |
| 804 serv_got_im(gc, im->from, m2, 0, im->time); | |
| 805 g_free(m2); | |
| 9284 | 806 |
| 807 if ((f = yahoo_friend_find(gc, im->from)) && im->buddy_icon == 2) { | |
| 808 if (yahoo_friend_get_buddy_icon_need_request(f)) { | |
| 9310 | 809 yahoo_send_picture_request(gc, im->from); |
| 9284 | 810 yahoo_friend_set_buddy_icon_need_request(f, FALSE); |
| 811 } | |
| 812 } | |
| 813 | |
| 7827 | 814 g_free(im); |
| 815 } | |
| 816 g_slist_free(list); | |
| 2681 | 817 } |
| 818 | |
| 7865 | 819 static void yahoo_process_sysmessage(GaimConnection *gc, struct yahoo_packet *pkt) |
| 820 { | |
| 821 GSList *l = pkt->hash; | |
| 822 char *prim, *me = NULL, *msg = NULL; | |
| 823 | |
| 824 while (l) { | |
| 825 struct yahoo_pair *pair = l->data; | |
| 826 | |
| 827 if (pair->key == 5) | |
| 828 me = pair->value; | |
| 829 if (pair->key == 14) | |
| 830 msg = pair->value; | |
| 831 | |
| 832 l = l->next; | |
| 833 } | |
| 834 | |
| 835 if (!msg) | |
| 836 return; | |
| 837 | |
| 838 prim = g_strdup_printf(_("Yahoo! system message for %s:"), | |
| 839 me?me:gaim_connection_get_display_name(gc)); | |
| 840 gaim_notify_info(NULL, NULL, prim, msg); | |
| 841 g_free(prim); | |
| 842 } | |
| 843 | |
| 6686 | 844 static void yahoo_buddy_added_us(GaimConnection *gc, struct yahoo_packet *pkt) { |
| 2681 | 845 char *id = NULL; |
| 846 char *who = NULL; | |
| 7827 | 847 char *msg = NULL, *tmpmsg = NULL; |
| 2681 | 848 GSList *l = pkt->hash; |
| 849 | |
| 850 while (l) { | |
| 851 struct yahoo_pair *pair = l->data; | |
| 6686 | 852 |
| 853 switch (pair->key) { | |
| 854 case 1: | |
| 2681 | 855 id = pair->value; |
| 6686 | 856 break; |
| 857 case 3: | |
| 2681 | 858 who = pair->value; |
| 6686 | 859 break; |
| 860 case 15: /* time, for when they add us and we're offline */ | |
| 861 break; | |
| 862 case 14: | |
| 2681 | 863 msg = pair->value; |
| 6686 | 864 break; |
| 865 } | |
| 2681 | 866 l = l->next; |
| 867 } | |
| 868 | |
| 7827 | 869 if (id) { |
| 870 if (msg) | |
| 871 tmpmsg = yahoo_string_decode(gc, msg, FALSE); | |
| 872 gaim_account_notify_added(gc->account, id, who, NULL, tmpmsg); | |
| 873 if (tmpmsg) | |
| 874 g_free(tmpmsg); | |
| 875 } | |
| 6686 | 876 } |
| 877 | |
| 878 static void yahoo_buddy_denied_our_add(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 879 { | |
| 880 char *who = NULL; | |
| 881 char *msg = NULL; | |
| 882 GSList *l = pkt->hash; | |
| 883 GString *buf = NULL; | |
| 6784 | 884 struct yahoo_data *yd = gc->proto_data; |
| 6686 | 885 |
| 886 while (l) { | |
| 887 struct yahoo_pair *pair = l->data; | |
| 888 | |
| 889 switch (pair->key) { | |
| 890 case 3: | |
| 891 who = pair->value; | |
| 892 break; | |
| 893 case 14: | |
| 894 msg = pair->value; | |
| 895 break; | |
| 896 } | |
| 897 l = l->next; | |
| 898 } | |
| 899 | |
| 900 if (who) { | |
| 7827 | 901 char *msg2; |
| 6686 | 902 buf = g_string_sized_new(0); |
| 7827 | 903 if (!msg) { |
| 6686 | 904 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list."), who); |
| 7827 | 905 } else { |
| 906 msg2 = yahoo_string_decode(gc, msg, FALSE); | |
| 907 g_string_printf(buf, _("%s has (retroactively) denied your request to add them to your list for the following reason: %s."), who, msg2); | |
| 908 g_free(msg2); | |
| 909 } | |
| 6840 | 910 gaim_notify_info(gc, NULL, _("Add buddy rejected"), buf->str); |
| 6686 | 911 g_string_free(buf, TRUE); |
| 6784 | 912 g_hash_table_remove(yd->friends, who); |
| 913 serv_got_update(gc, who, 0, 0, 0, 0, 0); | |
| 6686 | 914 } |
| 915 } | |
| 916 | |
| 917 static void yahoo_process_contact(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 918 { | |
| 919 | |
| 920 | |
| 921 switch (pkt->status) { | |
| 922 case 1: | |
| 923 yahoo_process_status(gc, pkt); | |
| 924 return; | |
| 925 case 3: | |
| 926 yahoo_buddy_added_us(gc, pkt); | |
| 927 break; | |
| 928 case 7: | |
| 929 yahoo_buddy_denied_our_add(gc, pkt); | |
| 930 break; | |
| 931 default: | |
| 932 break; | |
|
2683
4836eae8dd8c
[gaim-migrate @ 2696]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2682
diff
changeset
|
933 } |
| 2681 | 934 } |
| 935 | |
| 7747 | 936 #define OUT_CHARSET "utf-8" |
| 937 | |
| 938 static char *yahoo_decode(const char *text) | |
| 939 { | |
| 9221 | 940 char *converted = NULL; |
| 8125 | 941 char *n, *new; |
| 942 const char *end, *p; | |
| 8616 | 943 int i, k; |
| 8125 | 944 |
| 7771 | 945 n = new = g_malloc(strlen (text) + 1); |
| 8118 | 946 end = text + strlen(text); |
| 947 | |
| 8125 | 948 for (p = text; p < end; p++, n++) { |
| 7747 | 949 if (*p == '\\') { |
| 9064 | 950 if (p[1] >= '0' && p[1] <= '7') { |
| 951 p += 1; | |
| 952 for (i = 0, k = 0; k < 3; k += 1) { | |
| 953 char c = p[k]; | |
| 9065 | 954 if (c < '0' || c > '7') break; |
| 9064 | 955 i *= 8; |
| 956 i += c - '0'; | |
| 957 } | |
| 958 *n = i; | |
| 959 p += k - 1; | |
| 960 } else { /* bug 959248 */ | |
| 961 /* If we see a \ not followed by an octal number, | |
| 962 * it means that it is actually a \\ with one \ | |
| 963 * already eaten by some unknown function. | |
| 964 * This is arguably broken. | |
| 965 * | |
| 966 * I think wing is wrong here, there is no function | |
| 967 * called that I see that could have done it. I guess | |
| 968 * it is just really sending single \'s. That's yahoo | |
| 969 * for you. | |
| 970 */ | |
| 971 *n = *p; | |
| 972 } | |
| 7747 | 973 } |
| 974 else | |
| 975 *n = *p; | |
| 976 } | |
| 977 | |
| 978 *n = '\0'; | |
| 8125 | 979 |
| 9221 | 980 if (strstr(text, "\033$B")) |
| 981 converted = g_convert(new, n - new, OUT_CHARSET, "iso-2022-jp", NULL, NULL, NULL); | |
| 982 if (!converted) | |
| 983 converted = g_convert(new, n - new, OUT_CHARSET, "iso-8859-1", NULL, NULL, NULL); | |
| 7747 | 984 g_free(new); |
| 985 | |
| 986 return converted; | |
| 987 } | |
| 988 | |
| 5583 | 989 static void yahoo_process_mail(GaimConnection *gc, struct yahoo_packet *pkt) |
| 2681 | 990 { |
| 5583 | 991 GaimAccount *account = gaim_connection_get_account(gc); |
| 9221 | 992 struct yahoo_data *yd = gc->proto_data; |
| 2681 | 993 char *who = NULL; |
| 994 char *email = NULL; | |
| 995 char *subj = NULL; | |
| 9221 | 996 char *yahoo_mail_url = (yd->jp? YAHOOJP_MAIL_URL: YAHOO_MAIL_URL); |
| 2681 | 997 int count = 0; |
| 998 GSList *l = pkt->hash; | |
| 999 | |
| 5583 | 1000 if (!gaim_account_get_check_mail(account)) |
|
5521
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1001 return; |
|
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1002 |
| 2681 | 1003 while (l) { |
| 1004 struct yahoo_pair *pair = l->data; | |
| 1005 if (pair->key == 9) | |
| 1006 count = strtol(pair->value, NULL, 10); | |
| 1007 else if (pair->key == 43) | |
| 1008 who = pair->value; | |
| 1009 else if (pair->key == 42) | |
| 1010 email = pair->value; | |
| 1011 else if (pair->key == 18) | |
| 1012 subj = pair->value; | |
| 1013 l = l->next; | |
| 1014 } | |
| 1015 | |
| 4001 | 1016 if (who && subj && email && *email) { |
| 7747 | 1017 char *dec_who = yahoo_decode(who); |
| 1018 char *dec_subj = yahoo_decode(subj); | |
| 1019 char *from = g_strdup_printf("%s (%s)", dec_who, email); | |
| 1020 | |
| 1021 gaim_notify_email(gc, dec_subj, from, gaim_account_get_username(account), | |
| 9221 | 1022 yahoo_mail_url, NULL, NULL); |
|
5521
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1023 |
| 7747 | 1024 g_free(dec_who); |
| 1025 g_free(dec_subj); | |
|
2850
cbe6a1e63a72
[gaim-migrate @ 2863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2813
diff
changeset
|
1026 g_free(from); |
|
5521
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1027 } else if (count > 0) { |
| 5583 | 1028 const char *to = gaim_account_get_username(account); |
| 9221 | 1029 const char *url = yahoo_mail_url; |
|
5521
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1030 |
|
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1031 gaim_notify_emails(gc, count, FALSE, NULL, NULL, &to, &url, |
|
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1032 NULL, NULL); |
|
76ec14ba51d7
[gaim-migrate @ 5921]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
1033 } |
| 2681 | 1034 } |
| 3147 | 1035 /* This is the y64 alphabet... it's like base64, but has a . and a _ */ |
| 1036 char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; | |
| 1037 | |
| 1038 /* This is taken from Sylpheed by Hiroyuki Yamamoto. We have our own tobase64 function | |
| 1039 * in util.c, but it has a bug I don't feel like finding right now ;) */ | |
| 1040 void to_y64(unsigned char *out, const unsigned char *in, int inlen) | |
| 1041 /* raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) */ | |
| 1042 { | |
| 1043 for (; inlen >= 3; inlen -= 3) | |
| 1044 { | |
| 1045 *out++ = base64digits[in[0] >> 2]; | |
| 1046 *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)]; | |
| 1047 *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; | |
| 1048 *out++ = base64digits[in[2] & 0x3f]; | |
| 1049 in += 3; | |
| 1050 } | |
| 1051 if (inlen > 0) | |
| 1052 { | |
| 1053 unsigned char fragment; | |
| 1054 | |
| 1055 *out++ = base64digits[in[0] >> 2]; | |
| 1056 fragment = (in[0] << 4) & 0x30; | |
| 1057 if (inlen > 1) | |
| 1058 fragment |= in[1] >> 4; | |
| 1059 *out++ = base64digits[fragment]; | |
| 1060 *out++ = (inlen < 2) ? '-' : base64digits[(in[1] << 2) & 0x3c]; | |
| 1061 *out++ = '-'; | |
| 1062 } | |
| 1063 *out = '\0'; | |
| 1064 } | |
| 1065 | |
| 6986 | 1066 static void yahoo_process_auth_old(GaimConnection *gc, const char *seed) |
| 1067 { | |
| 1068 struct yahoo_packet *pack; | |
| 1069 GaimAccount *account = gaim_connection_get_account(gc); | |
| 7261 | 1070 const char *name = gaim_normalize(account, gaim_account_get_username(account)); |
| 6986 | 1071 const char *pass = gaim_account_get_password(account); |
| 1072 struct yahoo_data *yd = gc->proto_data; | |
| 1073 | |
| 1074 /* So, Yahoo has stopped supporting its older clients in India, and undoubtedly | |
| 1075 * will soon do so in the rest of the world. | |
| 1076 * | |
| 1077 * The new clients use this authentication method. I warn you in advance, it's | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
1078 * bizarre, convoluted, inordinately complicated. It's also no more secure than |
| 6986 | 1079 * crypt() was. The only purpose this scheme could serve is to prevent third |
| 1080 * part clients from connecting to their servers. | |
| 1081 * | |
| 1082 * Sorry, Yahoo. | |
| 1083 */ | |
| 9277 | 1084 |
| 6986 | 1085 md5_byte_t result[16]; |
| 1086 md5_state_t ctx; | |
| 9277 | 1087 |
| 6986 | 1088 char *crypt_result; |
| 1089 char password_hash[25]; | |
| 1090 char crypt_hash[25]; | |
| 1091 char *hash_string_p = g_malloc(50 + strlen(name)); | |
| 1092 char *hash_string_c = g_malloc(50 + strlen(name)); | |
| 9277 | 1093 |
| 6986 | 1094 char checksum; |
| 9277 | 1095 |
| 6986 | 1096 int sv; |
| 9277 | 1097 |
| 6986 | 1098 char result6[25]; |
| 1099 char result96[25]; | |
| 1100 | |
| 1101 sv = seed[15]; | |
| 1102 sv = sv % 8; | |
| 1103 | |
| 1104 md5_init(&ctx); | |
| 1105 md5_append(&ctx, pass, strlen(pass)); | |
| 1106 md5_finish(&ctx, result); | |
| 1107 to_y64(password_hash, result, 16); | |
| 9277 | 1108 |
| 6986 | 1109 md5_init(&ctx); |
| 9277 | 1110 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$"); |
| 6986 | 1111 md5_append(&ctx, crypt_result, strlen(crypt_result)); |
| 1112 md5_finish(&ctx, result); | |
| 1113 to_y64(crypt_hash, result, 16); | |
| 1114 | |
| 1115 switch (sv) { | |
| 1116 case 1: | |
| 1117 case 6: | |
| 1118 checksum = seed[seed[9] % 16]; | |
| 1119 g_snprintf(hash_string_p, strlen(name) + 50, | |
| 1120 "%c%s%s%s", checksum, name, seed, password_hash); | |
| 1121 g_snprintf(hash_string_c, strlen(name) + 50, | |
| 1122 "%c%s%s%s", checksum, name, seed, crypt_hash); | |
| 1123 break; | |
| 1124 case 2: | |
| 1125 case 7: | |
| 1126 checksum = seed[seed[15] % 16]; | |
| 1127 g_snprintf(hash_string_p, strlen(name) + 50, | |
| 1128 "%c%s%s%s", checksum, seed, password_hash, name); | |
| 1129 g_snprintf(hash_string_c, strlen(name) + 50, | |
| 1130 "%c%s%s%s", checksum, seed, crypt_hash, name); | |
| 1131 break; | |
| 1132 case 3: | |
| 1133 checksum = seed[seed[1] % 16]; | |
| 1134 g_snprintf(hash_string_p, strlen(name) + 50, | |
| 1135 "%c%s%s%s", checksum, name, password_hash, seed); | |
| 1136 g_snprintf(hash_string_c, strlen(name) + 50, | |
| 1137 "%c%s%s%s", checksum, name, crypt_hash, seed); | |
| 1138 break; | |
| 1139 case 4: | |
| 1140 checksum = seed[seed[3] % 16]; | |
| 1141 g_snprintf(hash_string_p, strlen(name) + 50, | |
| 1142 "%c%s%s%s", checksum, password_hash, seed, name); | |
| 1143 g_snprintf(hash_string_c, strlen(name) + 50, | |
| 1144 "%c%s%s%s", checksum, crypt_hash, seed, name); | |
| 1145 break; | |
| 1146 case 0: | |
| 1147 case 5: | |
| 1148 checksum = seed[seed[7] % 16]; | |
| 1149 g_snprintf(hash_string_p, strlen(name) + 50, | |
| 1150 "%c%s%s%s", checksum, password_hash, name, seed); | |
| 1151 g_snprintf(hash_string_c, strlen(name) + 50, | |
| 1152 "%c%s%s%s", checksum, crypt_hash, name, seed); | |
| 1153 break; | |
| 1154 } | |
| 9277 | 1155 |
| 1156 md5_init(&ctx); | |
| 6986 | 1157 md5_append(&ctx, hash_string_p, strlen(hash_string_p)); |
| 1158 md5_finish(&ctx, result); | |
| 1159 to_y64(result6, result, 16); | |
| 9277 | 1160 |
| 1161 md5_init(&ctx); | |
| 6986 | 1162 md5_append(&ctx, hash_string_c, strlen(hash_string_c)); |
| 1163 md5_finish(&ctx, result); | |
| 1164 to_y64(result96, result, 16); | |
| 1165 | |
| 1166 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0); | |
| 1167 yahoo_packet_hash(pack, 0, name); | |
| 1168 yahoo_packet_hash(pack, 6, result6); | |
| 1169 yahoo_packet_hash(pack, 96, result96); | |
| 1170 yahoo_packet_hash(pack, 1, name); | |
| 9277 | 1171 |
| 6986 | 1172 yahoo_send_packet(yd, pack); |
| 9277 | 1173 |
| 6986 | 1174 g_free(hash_string_p); |
| 1175 g_free(hash_string_c); | |
| 9277 | 1176 |
| 6986 | 1177 yahoo_packet_free(pack); |
| 9277 | 1178 |
| 6986 | 1179 } |
| 1180 | |
| 6998 | 1181 /* I'm dishing out some uber-mad props to Cerulean Studios for cracking this |
| 1182 * and sending the fix! Thanks guys. */ | |
| 1183 | |
| 6986 | 1184 static void yahoo_process_auth_new(GaimConnection *gc, const char *seed) |
| 1185 { | |
| 1186 struct yahoo_packet *pack = NULL; | |
| 1187 GaimAccount *account = gaim_connection_get_account(gc); | |
| 7261 | 1188 const char *name = gaim_normalize(account, gaim_account_get_username(account)); |
| 6986 | 1189 const char *pass = gaim_account_get_password(account); |
| 1190 struct yahoo_data *yd = gc->proto_data; | |
| 9277 | 1191 |
| 8349 | 1192 md5_byte_t result[16]; |
| 1193 md5_state_t ctx; | |
| 9277 | 1194 |
| 8349 | 1195 SHA_CTX ctx1; |
| 1196 SHA_CTX ctx2; | |
| 9277 | 1197 |
| 8349 | 1198 char *alphabet1 = "FBZDWAGHrJTLMNOPpRSKUVEXYChImkwQ"; |
| 1199 char *alphabet2 = "F0E1D2C3B4A59687abcdefghijklmnop"; | |
| 1200 | |
| 1201 char *challenge_lookup = "qzec2tb3um1olpar8whx4dfgijknsvy5"; | |
| 1202 char *operand_lookup = "+|&%/*^-"; | |
| 1203 char *delimit_lookup = ",;"; | |
| 1204 | |
| 1205 char *password_hash = (char *)g_malloc(25); | |
| 1206 char *crypt_hash = (char *)g_malloc(25); | |
| 1207 char *crypt_result = NULL; | |
| 1208 | |
| 1209 char pass_hash_xor1[64]; | |
| 1210 char pass_hash_xor2[64]; | |
| 1211 char crypt_hash_xor1[64]; | |
| 1212 char crypt_hash_xor2[64]; | |
| 1213 char resp_6[100]; | |
| 1214 char resp_96[100]; | |
| 1215 | |
| 1216 unsigned char digest1[20]; | |
| 1217 unsigned char digest2[20]; | |
| 1218 unsigned char comparison_src[20]; | |
| 1219 unsigned char magic_key_char[4]; | |
| 8375 | 1220 const unsigned char *magic_ptr; |
| 8349 | 1221 |
| 1222 unsigned int magic[64]; | |
| 1223 unsigned int magic_work = 0; | |
| 1224 unsigned int magic_4 = 0; | |
| 1225 | |
| 1226 int x; | |
| 1227 int y; | |
| 1228 int cnt = 0; | |
| 1229 int magic_cnt = 0; | |
| 1230 int magic_len; | |
| 1231 | |
| 1232 memset(password_hash, 0, 25); | |
| 1233 memset(crypt_hash, 0, 25); | |
| 6986 | 1234 memset(&pass_hash_xor1, 0, 64); |
| 1235 memset(&pass_hash_xor2, 0, 64); | |
| 1236 memset(&crypt_hash_xor1, 0, 64); | |
| 1237 memset(&crypt_hash_xor2, 0, 64); | |
| 1238 memset(&digest1, 0, 20); | |
| 1239 memset(&digest2, 0, 20); | |
| 1240 memset(&magic, 0, 64); | |
| 1241 memset(&resp_6, 0, 100); | |
| 1242 memset(&resp_96, 0, 100); | |
| 1243 memset(&magic_key_char, 0, 4); | |
| 8349 | 1244 memset(&comparison_src, 0, 20); |
| 6986 | 1245 |
| 1246 /* | |
| 8349 | 1247 * Magic: Phase 1. Generate what seems to be a 30 byte value (could change if base64 |
| 1248 * ends up differently? I don't remember and I'm tired, so use a 64 byte buffer. | |
| 6986 | 1249 */ |
| 9277 | 1250 |
| 6986 | 1251 magic_ptr = seed; |
| 8375 | 1252 |
| 6986 | 1253 while (*magic_ptr != (int)NULL) { |
| 8349 | 1254 char *loc; |
| 6986 | 1255 |
| 8349 | 1256 /* Ignore parentheses. |
| 1257 */ | |
| 6986 | 1258 |
| 1259 if (*magic_ptr == '(' || *magic_ptr == ')') { | |
| 1260 magic_ptr++; | |
| 1261 continue; | |
| 1262 } | |
| 1263 | |
| 8349 | 1264 /* Characters and digits verify against the challenge lookup. |
| 1265 */ | |
| 6986 | 1266 |
| 1267 if (isalpha(*magic_ptr) || isdigit(*magic_ptr)) { | |
| 1268 loc = strchr(challenge_lookup, *magic_ptr); | |
| 1269 if (!loc) { | |
| 8349 | 1270 /* SME XXX Error - disconnect here */ |
| 6986 | 1271 } |
| 1272 | |
| 8349 | 1273 /* Get offset into lookup table and shl 3. |
| 1274 */ | |
| 6986 | 1275 |
| 1276 magic_work = loc - challenge_lookup; | |
| 1277 magic_work <<= 3; | |
| 1278 | |
| 1279 magic_ptr++; | |
| 1280 continue; | |
| 1281 } else { | |
| 8349 | 1282 unsigned int local_store; |
| 6986 | 1283 |
| 1284 loc = strchr(operand_lookup, *magic_ptr); | |
| 1285 if (!loc) { | |
| 8349 | 1286 /* SME XXX Disconnect */ |
| 6986 | 1287 } |
| 1288 | |
| 1289 local_store = loc - operand_lookup; | |
| 8349 | 1290 |
| 1291 /* Oops; how did this happen? | |
| 1292 */ | |
| 1293 | |
| 6986 | 1294 if (magic_cnt >= 64) |
| 1295 break; | |
| 8349 | 1296 |
| 6986 | 1297 magic[magic_cnt++] = magic_work | local_store; |
| 1298 magic_ptr++; | |
| 1299 continue; | |
| 1300 } | |
| 8349 | 1301 } |
| 6986 | 1302 |
| 1303 magic_len = magic_cnt; | |
| 1304 magic_cnt = 0; | |
| 1305 | |
| 8349 | 1306 /* Magic: Phase 2. Take generated magic value and sprinkle fairy dust on the values. |
| 1307 */ | |
| 1308 | |
| 6986 | 1309 for (magic_cnt = magic_len-2; magic_cnt >= 0; magic_cnt--) { |
| 8349 | 1310 unsigned char byte1; |
| 1311 unsigned char byte2; | |
| 6986 | 1312 |
| 1313 /* Bad. Abort. | |
| 1314 */ | |
| 8349 | 1315 |
| 1316 if ((magic_cnt + 1 > magic_len) || (magic_cnt > magic_len)) | |
| 6986 | 1317 break; |
| 1318 | |
| 1319 byte1 = magic[magic_cnt]; | |
| 1320 byte2 = magic[magic_cnt+1]; | |
| 8349 | 1321 |
| 6986 | 1322 byte1 *= 0xcd; |
| 1323 byte1 ^= byte2; | |
| 1324 | |
| 1325 magic[magic_cnt+1] = byte1; | |
| 8349 | 1326 } |
| 1327 | |
| 1328 /* | |
| 1329 * Magic: Phase 3. This computes 20 bytes. The first 4 bytes are used as our magic | |
| 1330 * key (and may be changed later); the next 16 bytes are an MD5 sum of the magic key | |
| 1331 * plus 3 bytes. The 3 bytes are found by looping, and they represent the offsets | |
| 1332 * into particular functions we'll later call to potentially alter the magic key. | |
| 1333 * | |
| 1334 * %-) | |
| 1335 */ | |
| 1336 | |
| 1337 magic_cnt = 1; | |
| 1338 x = 0; | |
| 1339 | |
| 1340 do { | |
| 1341 unsigned int bl = 0; | |
| 1342 unsigned int cl = magic[magic_cnt++]; | |
| 1343 | |
| 1344 if (magic_cnt >= magic_len) | |
| 1345 break; | |
| 1346 | |
| 1347 if (cl > 0x7F) { | |
| 1348 if (cl < 0xe0) | |
| 1349 bl = cl = (cl & 0x1f) << 6; | |
| 1350 else { | |
| 1351 bl = magic[magic_cnt++]; | |
| 1352 cl = (cl & 0x0f) << 6; | |
| 1353 bl = ((bl & 0x3f) + cl) << 6; | |
| 1354 } | |
| 9277 | 1355 |
| 8349 | 1356 cl = magic[magic_cnt++]; |
| 1357 bl = (cl & 0x3f) + bl; | |
| 1358 } else | |
| 1359 bl = cl; | |
| 1360 | |
| 1361 comparison_src[x++] = (bl & 0xff00) >> 8; | |
| 1362 comparison_src[x++] = bl & 0xff; | |
| 1363 } while (x < 20); | |
| 1364 | |
| 1365 /* First four bytes are magic key. | |
| 1366 */ | |
| 1367 | |
| 1368 memcpy(&magic_key_char[0], comparison_src, 4); | |
| 8482 | 1369 magic_4 = magic_key_char[0] | (magic_key_char[1]<<8) | (magic_key_char[2]<<16) | (magic_key_char[3]<<24); |
| 8349 | 1370 |
| 1371 /* | |
| 1372 * Magic: Phase 4. Determine what function to use later by getting outside/inside | |
| 1373 * loop values until we match our previous buffer. | |
| 1374 */ | |
| 1375 | |
| 1376 for (x = 0; x < 65535; x++) { | |
| 1377 int leave = 0; | |
| 1378 | |
| 1379 for (y = 0; y < 5; y++) { | |
| 1380 md5_byte_t result[16]; | |
| 1381 md5_state_t ctx; | |
| 1382 | |
| 1383 unsigned char test[3]; | |
| 1384 | |
| 1385 memset(&result, 0, 16); | |
| 1386 memset(&test, 0, 3); | |
| 1387 | |
| 1388 /* Calculate buffer. | |
| 1389 */ | |
| 1390 | |
| 1391 test[0] = x; | |
| 1392 test[1] = x >> 8; | |
| 1393 test[2] = y; | |
| 1394 | |
| 1395 md5_init(&ctx); | |
| 1396 md5_append(&ctx, magic_key_char, 4); | |
| 1397 md5_append(&ctx, test, 3); | |
| 1398 md5_finish(&ctx, result); | |
| 1399 | |
| 1400 if (!memcmp(result, comparison_src+4, 16)) { | |
| 1401 leave = 1; | |
| 1402 break; | |
| 1403 } | |
| 1404 } | |
| 1405 | |
| 1406 if (leave == 1) | |
| 1407 break; | |
| 6986 | 1408 } |
| 1409 | |
| 8349 | 1410 /* If y != 0, we need some help. |
| 1411 */ | |
| 6986 | 1412 |
| 8349 | 1413 if (y != 0) { |
| 1414 unsigned int updated_key; | |
| 6986 | 1415 |
| 8349 | 1416 /* Update magic stuff. Call it twice because Yahoo's encryption is super bad ass. |
| 1417 */ | |
| 7127 | 1418 |
| 8349 | 1419 updated_key = yahoo_auth_finalCountdown(magic_4, 0x60, y, x); |
| 1420 updated_key = yahoo_auth_finalCountdown(updated_key, 0x60, y, x); | |
| 6986 | 1421 |
| 8482 | 1422 magic_key_char[0] = updated_key & 0xff; |
| 1423 magic_key_char[1] = (updated_key >> 8) & 0xff; | |
| 1424 magic_key_char[2] = (updated_key >> 16) & 0xff; | |
| 1425 magic_key_char[3] = (updated_key >> 24) & 0xff; | |
| 8349 | 1426 } |
| 7127 | 1427 |
| 8349 | 1428 /* Get password and crypt hashes as per usual. |
| 1429 */ | |
| 1430 | |
| 6986 | 1431 md5_init(&ctx); |
| 8349 | 1432 md5_append(&ctx, pass, strlen(pass)); |
| 6986 | 1433 md5_finish(&ctx, result); |
| 1434 to_y64(password_hash, result, 16); | |
| 1435 | |
| 1436 md5_init(&ctx); | |
| 1437 crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$"); | |
| 1438 md5_append(&ctx, crypt_result, strlen(crypt_result)); | |
| 1439 md5_finish(&ctx, result); | |
| 1440 to_y64(crypt_hash, result, 16); | |
| 8349 | 1441 |
| 1442 /* Our first authentication response is based off of the password hash. | |
| 1443 */ | |
| 6986 | 1444 |
| 1445 for (x = 0; x < (int)strlen(password_hash); x++) | |
| 1446 pass_hash_xor1[cnt++] = password_hash[x] ^ 0x36; | |
| 1447 | |
| 1448 if (cnt < 64) | |
| 1449 memset(&(pass_hash_xor1[cnt]), 0x36, 64-cnt); | |
| 8349 | 1450 |
| 6986 | 1451 cnt = 0; |
| 1452 | |
| 1453 for (x = 0; x < (int)strlen(password_hash); x++) | |
| 1454 pass_hash_xor2[cnt++] = password_hash[x] ^ 0x5c; | |
| 1455 | |
| 1456 if (cnt < 64) | |
| 1457 memset(&(pass_hash_xor2[cnt]), 0x5c, 64-cnt); | |
| 1458 | |
| 1459 shaInit(&ctx1); | |
| 1460 shaInit(&ctx2); | |
| 1461 | |
| 8349 | 1462 /* |
| 1463 * The first context gets the password hash XORed with 0x36 plus a magic value | |
| 1464 * which we previously extrapolated from our challenge. | |
| 1465 */ | |
| 6986 | 1466 |
| 1467 shaUpdate(&ctx1, pass_hash_xor1, 64); | |
| 1468 shaUpdate(&ctx1, magic_key_char, 4); | |
| 1469 shaFinal(&ctx1, digest1); | |
| 1470 | |
| 8349 | 1471 /* |
| 1472 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest | |
| 1473 * of the first context. | |
| 1474 */ | |
| 6986 | 1475 |
| 1476 shaUpdate(&ctx2, pass_hash_xor2, 64); | |
| 1477 shaUpdate(&ctx2, digest1, 20); | |
| 1478 shaFinal(&ctx2, digest2); | |
| 1479 | |
| 8349 | 1480 /* |
| 1481 * Now that we have digest2, use it to fetch characters from an alphabet to construct | |
| 1482 * our first authentication response. | |
| 1483 */ | |
| 1484 | |
| 6986 | 1485 for (x = 0; x < 20; x += 2) { |
| 8349 | 1486 unsigned int val = 0; |
| 1487 unsigned int lookup = 0; | |
| 6986 | 1488 |
| 8349 | 1489 char byte[6]; |
| 1490 | |
| 6986 | 1491 memset(&byte, 0, 6); |
| 8349 | 1492 |
| 1493 /* First two bytes of digest stuffed together. | |
| 6986 | 1494 */ |
| 9277 | 1495 |
| 6986 | 1496 val = digest2[x]; |
| 1497 val <<= 8; | |
| 1498 val += digest2[x+1]; | |
| 1499 | |
| 1500 lookup = (val >> 0x0b); | |
| 1501 lookup &= 0x1f; | |
| 1502 if (lookup >= strlen(alphabet1)) | |
| 1503 break; | |
| 1504 sprintf(byte, "%c", alphabet1[lookup]); | |
| 1505 strcat(resp_6, byte); | |
| 1506 strcat(resp_6, "="); | |
| 8349 | 1507 |
| 6986 | 1508 lookup = (val >> 0x06); |
| 1509 lookup &= 0x1f; | |
| 1510 if (lookup >= strlen(alphabet2)) | |
| 1511 break; | |
| 1512 sprintf(byte, "%c", alphabet2[lookup]); | |
| 1513 strcat(resp_6, byte); | |
| 1514 | |
| 1515 lookup = (val >> 0x01); | |
| 1516 lookup &= 0x1f; | |
| 1517 if (lookup >= strlen(alphabet2)) | |
| 1518 break; | |
| 1519 sprintf(byte, "%c", alphabet2[lookup]); | |
| 1520 strcat(resp_6, byte); | |
| 8349 | 1521 |
| 6986 | 1522 lookup = (val & 0x01); |
| 1523 if (lookup >= strlen(delimit_lookup)) | |
| 1524 break; | |
| 1525 sprintf(byte, "%c", delimit_lookup[lookup]); | |
| 1526 strcat(resp_6, byte); | |
| 1527 } | |
| 1528 | |
| 8349 | 1529 /* Our second authentication response is based off of the crypto hash. |
| 1530 */ | |
| 6986 | 1531 |
| 1532 cnt = 0; | |
| 1533 memset(&digest1, 0, 20); | |
| 1534 memset(&digest2, 0, 20); | |
| 1535 | |
| 1536 for (x = 0; x < (int)strlen(crypt_hash); x++) | |
| 1537 crypt_hash_xor1[cnt++] = crypt_hash[x] ^ 0x36; | |
| 1538 | |
| 1539 if (cnt < 64) | |
| 1540 memset(&(crypt_hash_xor1[cnt]), 0x36, 64-cnt); | |
| 8349 | 1541 |
| 6986 | 1542 cnt = 0; |
| 1543 | |
| 1544 for (x = 0; x < (int)strlen(crypt_hash); x++) | |
| 1545 crypt_hash_xor2[cnt++] = crypt_hash[x] ^ 0x5c; | |
| 1546 | |
| 1547 if (cnt < 64) | |
| 1548 memset(&(crypt_hash_xor2[cnt]), 0x5c, 64-cnt); | |
| 1549 | |
| 1550 shaInit(&ctx1); | |
| 1551 shaInit(&ctx2); | |
| 1552 | |
| 8349 | 1553 /* |
| 1554 * The first context gets the password hash XORed with 0x36 plus a magic value | |
| 1555 * which we previously extrapolated from our challenge. | |
| 1556 */ | |
| 6986 | 1557 |
| 1558 shaUpdate(&ctx1, crypt_hash_xor1, 64); | |
| 1559 shaUpdate(&ctx1, magic_key_char, 4); | |
| 1560 shaFinal(&ctx1, digest1); | |
| 1561 | |
| 8349 | 1562 /* |
| 1563 * The second context gets the password hash XORed with 0x5c plus the SHA-1 digest | |
| 1564 * of the first context. | |
| 1565 */ | |
| 6986 | 1566 |
| 1567 shaUpdate(&ctx2, crypt_hash_xor2, 64); | |
| 1568 shaUpdate(&ctx2, digest1, 20); | |
| 1569 shaFinal(&ctx2, digest2); | |
| 1570 | |
| 8349 | 1571 /* |
| 1572 * Now that we have digest2, use it to fetch characters from an alphabet to construct | |
| 1573 * our first authentication response. | |
| 1574 */ | |
| 6986 | 1575 |
| 1576 for (x = 0; x < 20; x += 2) { | |
| 8349 | 1577 unsigned int val = 0; |
| 1578 unsigned int lookup = 0; | |
| 6986 | 1579 |
| 8349 | 1580 char byte[6]; |
| 6986 | 1581 |
| 1582 memset(&byte, 0, 6); | |
| 1583 | |
| 8349 | 1584 /* First two bytes of digest stuffed together. |
| 1585 */ | |
| 6986 | 1586 |
| 1587 val = digest2[x]; | |
| 1588 val <<= 8; | |
| 1589 val += digest2[x+1]; | |
| 8349 | 1590 |
| 6986 | 1591 lookup = (val >> 0x0b); |
| 1592 lookup &= 0x1f; | |
| 1593 if (lookup >= strlen(alphabet1)) | |
| 1594 break; | |
| 1595 sprintf(byte, "%c", alphabet1[lookup]); | |
| 1596 strcat(resp_96, byte); | |
| 1597 strcat(resp_96, "="); | |
| 1598 | |
| 1599 lookup = (val >> 0x06); | |
| 1600 lookup &= 0x1f; | |
| 1601 if (lookup >= strlen(alphabet2)) | |
| 1602 break; | |
| 1603 sprintf(byte, "%c", alphabet2[lookup]); | |
| 1604 strcat(resp_96, byte); | |
| 1605 | |
| 1606 lookup = (val >> 0x01); | |
| 1607 lookup &= 0x1f; | |
| 1608 if (lookup >= strlen(alphabet2)) | |
| 1609 break; | |
| 1610 sprintf(byte, "%c", alphabet2[lookup]); | |
| 1611 strcat(resp_96, byte); | |
| 1612 | |
| 1613 lookup = (val & 0x01); | |
| 1614 if (lookup >= strlen(delimit_lookup)) | |
| 1615 break; | |
| 1616 sprintf(byte, "%c", delimit_lookup[lookup]); | |
| 1617 strcat(resp_96, byte); | |
| 1618 } | |
| 1619 | |
| 1620 pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, YAHOO_STATUS_AVAILABLE, 0); | |
| 1621 yahoo_packet_hash(pack, 0, name); | |
| 1622 yahoo_packet_hash(pack, 6, resp_6); | |
| 1623 yahoo_packet_hash(pack, 96, resp_96); | |
| 1624 yahoo_packet_hash(pack, 1, name); | |
| 9306 | 1625 if (yd->picture_checksum) { |
| 1626 char *cksum = g_strdup_printf("%d", yd->picture_checksum); | |
| 1627 yahoo_packet_hash(pack, 192, cksum); | |
| 1628 g_free(cksum); | |
| 1629 } | |
| 6986 | 1630 yahoo_send_packet(yd, pack); |
| 1631 yahoo_packet_free(pack); | |
| 1632 | |
| 7424 | 1633 g_free(password_hash); |
| 1634 g_free(crypt_hash); | |
| 6986 | 1635 } |
| 1636 | |
| 5583 | 1637 static void yahoo_process_auth(GaimConnection *gc, struct yahoo_packet *pkt) |
| 3147 | 1638 { |
| 1639 char *seed = NULL; | |
| 1640 char *sn = NULL; | |
| 1641 GSList *l = pkt->hash; | |
| 7010 | 1642 int m = 0; |
| 9277 | 1643 gchar *buf; |
| 1644 | |
| 1645 | |
| 3147 | 1646 while (l) { |
| 1647 struct yahoo_pair *pair = l->data; | |
| 1648 if (pair->key == 94) | |
| 1649 seed = pair->value; | |
| 1650 if (pair->key == 1) | |
| 1651 sn = pair->value; | |
| 6986 | 1652 if (pair->key == 13) |
| 1653 m = atoi(pair->value); | |
| 3147 | 1654 l = l->next; |
| 1655 } | |
| 9277 | 1656 |
| 3147 | 1657 if (seed) { |
| 6986 | 1658 switch (m) { |
| 1659 case 0: | |
| 1660 yahoo_process_auth_old(gc, seed); | |
| 1661 break; | |
| 3147 | 1662 case 1: |
| 6986 | 1663 yahoo_process_auth_new(gc, seed); |
| 3147 | 1664 break; |
| 6986 | 1665 default: |
| 7043 | 1666 buf = g_strdup_printf(_("The Yahoo server has requested the use of an unrecognized " |
| 7129 | 1667 "authentication method. This version of Gaim will likely not be able " |
| 7043 | 1668 "to successfully sign on to Yahoo. Check %s for updates."), GAIM_WEBSITE); |
| 6986 | 1669 gaim_notify_error(gc, "", _("Failed Yahoo! Authentication"), |
| 7043 | 1670 buf); |
| 1671 g_free(buf); | |
| 6986 | 1672 yahoo_process_auth_new(gc, seed); /* Can't hurt to try it anyway. */ |
| 3147 | 1673 } |
| 1674 } | |
| 1675 } | |
| 2681 | 1676 |
| 9285 | 1677 static void ignore_buddy(GaimBuddy *buddy) { |
| 1678 GaimGroup *group; | |
| 1679 GaimConversation *conv; | |
| 6760 | 1680 GaimAccount *account; |
| 1681 gchar *name; | |
| 1682 | |
| 9285 | 1683 if (!buddy) |
| 6792 | 1684 return; |
| 6760 | 1685 |
| 9285 | 1686 group = gaim_find_buddys_group(buddy); |
| 1687 name = g_strdup(buddy->name); | |
| 1688 account = buddy->account; | |
| 6760 | 1689 |
| 6792 | 1690 gaim_debug(GAIM_DEBUG_INFO, "blist", |
| 9285 | 1691 "Removing '%s' from buddy list.\n", buddy->name); |
| 1692 serv_remove_buddy(account->gc, buddy, group); | |
| 1693 gaim_blist_remove_buddy(buddy); | |
| 6760 | 1694 |
| 6792 | 1695 serv_add_deny(account->gc, name); |
| 9285 | 1696 |
| 1697 conv = gaim_find_conversation_with_account(name, account); | |
| 1698 | |
| 1699 if (conv != NULL) | |
| 1700 gaim_conversation_update(conv, GAIM_CONV_UPDATE_REMOVE); | |
| 6760 | 1701 |
| 1702 g_free(name); | |
| 1703 } | |
| 1704 | |
| 1705 static void keep_buddy(GaimBuddy *b) { | |
| 1706 gaim_privacy_deny_remove(b->account, b->name, 1); | |
| 1707 } | |
| 1708 | |
| 1709 static void yahoo_process_ignore(GaimConnection *gc, struct yahoo_packet *pkt) { | |
| 1710 GaimBuddy *b; | |
| 1711 GSList *l; | |
| 1712 gchar *who = NULL; | |
| 1713 gchar *sn = NULL; | |
| 1714 gchar buf[BUF_LONG]; | |
| 1715 gint ignore = 0; | |
| 1716 gint status = 0; | |
| 1717 | |
| 1718 for (l = pkt->hash; l; l = l->next) { | |
| 1719 struct yahoo_pair *pair = l->data; | |
| 1720 switch (pair->key) { | |
| 1721 case 0: | |
| 1722 who = pair->value; | |
| 1723 break; | |
| 1724 case 1: | |
| 1725 sn = pair->value; | |
| 1726 break; | |
| 1727 case 13: | |
| 1728 ignore = strtol(pair->value, NULL, 10); | |
| 1729 break; | |
| 1730 case 66: | |
| 1731 status = strtol(pair->value, NULL, 10); | |
| 1732 break; | |
| 1733 default: | |
| 1734 break; | |
| 1735 } | |
| 1736 } | |
| 1737 | |
| 1738 switch (status) { | |
| 1739 case 12: | |
| 1740 b = gaim_find_buddy(gc->account, who); | |
| 1741 g_snprintf(buf, sizeof(buf), _("You have tried to ignore %s, but the " | |
| 1742 "user is on your buddy list. Clicking \"Yes\" " | |
| 1743 "will remove and ignore the buddy."), who); | |
| 1744 gaim_request_yes_no(gc, NULL, _("Ignore buddy?"), buf, 0, b, | |
| 1745 G_CALLBACK(ignore_buddy), | |
| 1746 G_CALLBACK(keep_buddy)); | |
| 1747 break; | |
| 1748 case 2: | |
| 1749 case 3: | |
| 1750 case 0: | |
| 1751 default: | |
| 1752 break; | |
| 1753 } | |
| 1754 } | |
| 1755 | |
| 6761 | 1756 static void yahoo_process_authresp(GaimConnection *gc, struct yahoo_packet *pkt) |
| 1757 { | |
| 1758 GSList *l = pkt->hash; | |
| 1759 int err = 0; | |
| 1760 char *msg; | |
| 7865 | 1761 char *url = NULL; |
| 1762 char *fullmsg; | |
| 6761 | 1763 |
| 1764 while (l) { | |
| 1765 struct yahoo_pair *pair = l->data; | |
| 1766 | |
| 1767 if (pair->key == 66) | |
| 1768 err = strtol(pair->value, NULL, 10); | |
| 7865 | 1769 if (pair->key == 20) |
| 1770 url = pair->value; | |
| 6761 | 1771 |
| 1772 l = l->next; | |
| 1773 } | |
| 1774 | |
| 1775 switch (err) { | |
| 1776 case 3: | |
| 7865 | 1777 msg = g_strdup(_("Invalid username.")); |
| 6761 | 1778 break; |
| 1779 case 13: | |
| 7865 | 1780 msg = g_strdup(_("Incorrect password.")); |
| 1781 break; | |
| 1782 case 14: | |
| 9280 | 1783 msg = g_strdup(_("Your account is locked, please log in to the Yahoo! website.")); |
| 6761 | 1784 break; |
| 1785 default: | |
| 9280 | 1786 msg = g_strdup_printf(_("Unknown error number %d. Logging into the Yahoo! website may fix this."), err); |
| 6761 | 1787 } |
| 7865 | 1788 |
| 1789 if (url) | |
| 1790 fullmsg = g_strdup_printf("%s\n%s", msg, url); | |
| 1791 else | |
| 1792 fullmsg = g_strdup(msg); | |
| 1793 | |
| 9280 | 1794 gc->wants_to_die = TRUE; |
| 7865 | 1795 gaim_connection_error(gc, fullmsg); |
| 1796 g_free(msg); | |
| 1797 g_free(fullmsg); | |
| 6761 | 1798 } |
| 1799 | |
| 6840 | 1800 static void yahoo_process_addbuddy(GaimConnection *gc, struct yahoo_packet *pkt) |
| 1801 { | |
| 1802 int err = 0; | |
| 1803 char *who = NULL; | |
| 1804 char *group = NULL; | |
| 7827 | 1805 char *decoded_group; |
| 6840 | 1806 char *buf; |
| 9278 | 1807 YahooFriend *f; |
| 6840 | 1808 GSList *l = pkt->hash; |
| 1809 | |
| 1810 while (l) { | |
| 1811 struct yahoo_pair *pair = l->data; | |
| 1812 | |
| 1813 switch (pair->key) { | |
| 1814 case 66: | |
| 1815 err = strtol(pair->value, NULL, 10); | |
| 1816 break; | |
| 1817 case 7: | |
| 1818 who = pair->value; | |
| 1819 break; | |
| 1820 case 65: | |
| 1821 group = pair->value; | |
| 1822 break; | |
| 1823 } | |
| 1824 | |
| 1825 l = l->next; | |
| 1826 } | |
| 1827 | |
| 1828 if (!who) | |
| 1829 return; | |
| 1830 if (!group) | |
| 1831 group = ""; | |
| 1832 | |
| 1833 if (!err || (err == 2)) { /* 0 = ok, 2 = already on serv list */ | |
| 9279 | 1834 f = yahoo_friend_find_or_new(gc, who); |
| 1835 yahoo_update_status(gc, who, f); | |
| 6840 | 1836 return; |
| 1837 } | |
| 1838 | |
| 7827 | 1839 decoded_group = yahoo_string_decode(gc, group, FALSE); |
| 6840 | 1840 buf = g_strdup_printf(_("Could not add buddy %s to group %s to the server list on account %s."), |
| 7827 | 1841 who, decoded_group, gaim_connection_get_display_name(gc)); |
| 6840 | 1842 gaim_notify_error(gc, NULL, _("Could not add buddy to server list"), buf); |
| 1843 g_free(buf); | |
| 7827 | 1844 g_free(decoded_group); |
| 6840 | 1845 } |
| 1846 | |
| 9062 | 1847 static void yahoo_process_p2p(GaimConnection *gc, struct yahoo_packet *pkt) |
| 1848 { | |
| 1849 GSList *l = pkt->hash; | |
| 1850 char *who = NULL; | |
| 1851 char *base64 = NULL; | |
| 9277 | 1852 char *decoded; |
| 9062 | 1853 int len; |
| 1854 | |
| 1855 while (l) { | |
| 1856 struct yahoo_pair *pair = l->data; | |
| 1857 | |
| 1858 switch (pair->key) { | |
| 1859 case 5: | |
| 1860 /* our identity */ | |
| 1861 break; | |
| 1862 case 4: | |
| 1863 who = pair->value; | |
| 1864 break; | |
| 1865 case 1: | |
| 1866 /* who again, the master identity this time? */ | |
| 1867 break; | |
| 1868 case 12: | |
| 1869 base64 = pair->value; | |
| 1870 /* so, this is an ip address. in base64. decoded it's in ascii. | |
| 1871 after strtol, it's in reversed byte order. Who thought this up?*/ | |
| 1872 break; | |
| 1873 /* | |
| 1874 TODO: figure these out | |
| 1875 yahoo: Key: 61 Value: 0 | |
| 1876 yahoo: Key: 2 Value: | |
| 1877 yahoo: Key: 13 Value: 0 | |
| 1878 yahoo: Key: 49 Value: PEERTOPEER | |
| 1879 yahoo: Key: 140 Value: 1 | |
| 1880 yahoo: Key: 11 Value: -1786225828 | |
| 1881 */ | |
| 1882 | |
| 1883 } | |
| 1884 | |
| 1885 l = l->next; | |
| 1886 } | |
| 1887 | |
| 9277 | 1888 if (base64) { |
| 9281 | 1889 guint32 ip; |
| 1890 char *tmp2; | |
| 1891 YahooFriend *f; | |
| 1892 | |
| 9062 | 1893 gaim_base64_decode(base64, &decoded, &len); |
| 9277 | 1894 if (len) { |
| 1895 char *tmp = gaim_str_binary_to_ascii(decoded, len); | |
| 1896 gaim_debug_info("yahoo", "Got P2P service packet (from server): who = %s, ip = %s\n", who, tmp); | |
| 1897 g_free(tmp); | |
| 1898 } | |
| 9281 | 1899 |
| 1900 tmp2 = g_strndup(decoded, len); /* so its \0 terminated...*/ | |
| 1901 ip = strtol(tmp2, NULL, 10); | |
| 1902 g_free(tmp2); | |
| 9062 | 1903 g_free(decoded); |
| 9281 | 1904 tmp2 = g_strdup_printf("%u.%u.%u.%u", ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff, |
| 1905 (ip >> 24) & 0xff); | |
| 1906 f = yahoo_friend_find(gc, who); | |
| 1907 if (f) | |
| 1908 yahoo_friend_set_ip(f, tmp2); | |
| 1909 g_free(tmp2); | |
| 9062 | 1910 } |
| 1911 } | |
| 1912 | |
| 5583 | 1913 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt) |
| 2681 | 1914 { |
| 6760 | 1915 switch (pkt->service) { |
| 2681 | 1916 case YAHOO_SERVICE_LOGON: |
|
2771
450f4f9d2f23
[gaim-migrate @ 2784]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2741
diff
changeset
|
1917 case YAHOO_SERVICE_LOGOFF: |
| 2681 | 1918 case YAHOO_SERVICE_ISAWAY: |
|
2737
f61c1f3a6afa
[gaim-migrate @ 2750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2724
diff
changeset
|
1919 case YAHOO_SERVICE_ISBACK: |
| 3019 | 1920 case YAHOO_SERVICE_GAMELOGON: |
| 1921 case YAHOO_SERVICE_GAMELOGOFF: | |
| 6686 | 1922 case YAHOO_SERVICE_CHATLOGON: |
| 1923 case YAHOO_SERVICE_CHATLOGOFF: | |
| 2681 | 1924 yahoo_process_status(gc, pkt); |
| 1925 break; | |
| 3019 | 1926 case YAHOO_SERVICE_NOTIFY: |
| 1927 yahoo_process_notify(gc, pkt); | |
| 2993 | 1928 break; |
| 2681 | 1929 case YAHOO_SERVICE_MESSAGE: |
|
2786
318f846120e2
[gaim-migrate @ 2799]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2772
diff
changeset
|
1930 case YAHOO_SERVICE_GAMEMSG: |
| 5939 | 1931 case YAHOO_SERVICE_CHATMSG: |
| 2681 | 1932 yahoo_process_message(gc, pkt); |
| 1933 break; | |
| 7865 | 1934 case YAHOO_SERVICE_SYSMESSAGE: |
| 1935 yahoo_process_sysmessage(gc, pkt); | |
| 1936 break; | |
| 2681 | 1937 case YAHOO_SERVICE_NEWMAIL: |
| 1938 yahoo_process_mail(gc, pkt); | |
| 1939 break; | |
| 1940 case YAHOO_SERVICE_NEWCONTACT: | |
| 1941 yahoo_process_contact(gc, pkt); | |
| 1942 break; | |
| 6784 | 1943 case YAHOO_SERVICE_AUTHRESP: |
| 1944 yahoo_process_authresp(gc, pkt); | |
| 1945 break; | |
| 2681 | 1946 case YAHOO_SERVICE_LIST: |
| 1947 yahoo_process_list(gc, pkt); | |
| 1948 break; | |
| 3147 | 1949 case YAHOO_SERVICE_AUTH: |
| 1950 yahoo_process_auth(gc, pkt); | |
| 1951 break; | |
| 6840 | 1952 case YAHOO_SERVICE_ADDBUDDY: |
| 1953 yahoo_process_addbuddy(gc, pkt); | |
| 1954 break; | |
| 6760 | 1955 case YAHOO_SERVICE_IGNORECONTACT: |
| 1956 yahoo_process_ignore(gc, pkt); | |
| 1957 break; | |
| 6729 | 1958 case YAHOO_SERVICE_CONFINVITE: |
| 1959 case YAHOO_SERVICE_CONFADDINVITE: | |
| 1960 yahoo_process_conference_invite(gc, pkt); | |
| 1961 break; | |
| 1962 case YAHOO_SERVICE_CONFDECLINE: | |
| 1963 yahoo_process_conference_decline(gc, pkt); | |
| 1964 break; | |
| 1965 case YAHOO_SERVICE_CONFLOGON: | |
| 1966 yahoo_process_conference_logon(gc, pkt); | |
| 1967 break; | |
| 1968 case YAHOO_SERVICE_CONFLOGOFF: | |
| 1969 yahoo_process_conference_logoff(gc, pkt); | |
| 1970 break; | |
| 1971 case YAHOO_SERVICE_CONFMSG: | |
| 1972 yahoo_process_conference_message(gc, pkt); | |
| 1973 break; | |
| 1974 case YAHOO_SERVICE_CHATONLINE: | |
| 1975 yahoo_process_chat_online(gc, pkt); | |
| 1976 break; | |
| 1977 case YAHOO_SERVICE_CHATLOGOUT: | |
| 1978 yahoo_process_chat_logout(gc, pkt); | |
| 1979 break; | |
| 1980 case YAHOO_SERVICE_CHATGOTO: | |
| 1981 yahoo_process_chat_goto(gc, pkt); | |
| 1982 break; | |
| 1983 case YAHOO_SERVICE_CHATJOIN: | |
| 1984 yahoo_process_chat_join(gc, pkt); | |
| 1985 break; | |
| 1986 case YAHOO_SERVICE_CHATLEAVE: /* XXX is this right? */ | |
| 1987 case YAHOO_SERVICE_CHATEXIT: | |
| 1988 yahoo_process_chat_exit(gc, pkt); | |
| 1989 break; | |
| 1990 case YAHOO_SERVICE_CHATINVITE: /* XXX never seen this one, might not do it right */ | |
| 1991 case YAHOO_SERVICE_CHATADDINVITE: | |
| 1992 yahoo_process_chat_addinvite(gc, pkt); | |
| 1993 break; | |
| 1994 case YAHOO_SERVICE_COMMENT: | |
| 1995 yahoo_process_chat_message(gc, pkt); | |
| 1996 break; | |
| 7651 | 1997 case YAHOO_SERVICE_P2PFILEXFER: |
| 1998 case YAHOO_SERVICE_FILETRANSFER: | |
| 1999 yahoo_process_filetransfer(gc, pkt); | |
| 2000 break; | |
| 9062 | 2001 case YAHOO_SERVICE_PEEPTOPEER: |
| 2002 yahoo_process_p2p(gc, pkt); | |
| 2003 break; | |
| 9284 | 2004 case YAHOO_SERVICE_PICTURE: |
| 2005 yahoo_process_picture(gc, pkt); | |
| 2006 break; | |
| 9292 | 2007 case YAHOO_SERVICE_PICTURE_UPDATE: |
| 2008 yahoo_process_picture_update(gc, pkt); | |
| 2009 break; | |
| 2010 case YAHOO_SERVICE_PICTURE_CHECKSUM: | |
| 2011 yahoo_process_picture_checksum(gc, pkt); | |
| 2012 break; | |
| 9306 | 2013 case YAHOO_SERVICE_PICTURE_UPLOAD: |
| 2014 yahoo_process_picture_upload(gc, pkt); | |
| 2015 break; | |
| 2681 | 2016 default: |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
2017 gaim_debug(GAIM_DEBUG_ERROR, "yahoo", |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
2018 "Unhandled service 0x%02x\n", pkt->service); |
| 2681 | 2019 break; |
| 2020 } | |
| 2021 } | |
| 2022 | |
| 2023 static void yahoo_pending(gpointer data, gint source, GaimInputCondition cond) | |
| 2024 { | |
| 5583 | 2025 GaimConnection *gc = data; |
| 2681 | 2026 struct yahoo_data *yd = gc->proto_data; |
| 2027 char buf[1024]; | |
| 2028 int len; | |
| 2029 | |
| 2030 len = read(yd->fd, buf, sizeof(buf)); | |
| 2031 | |
| 2032 if (len <= 0) { | |
| 6321 | 2033 gaim_connection_error(gc, _("Unable to read")); |
| 2681 | 2034 return; |
| 2035 } | |
| 2036 | |
| 2037 yd->rxqueue = g_realloc(yd->rxqueue, len + yd->rxlen); | |
| 2038 memcpy(yd->rxqueue + yd->rxlen, buf, len); | |
| 2039 yd->rxlen += len; | |
| 2040 | |
| 2041 while (1) { | |
| 2042 struct yahoo_packet *pkt; | |
| 2043 int pos = 0; | |
| 2044 int pktlen; | |
| 2045 | |
| 2046 if (yd->rxlen < YAHOO_PACKET_HDRLEN) | |
| 2047 return; | |
| 2048 | |
| 2049 pos += 4; /* YMSG */ | |
| 2050 pos += 2; | |
| 2051 pos += 2; | |
| 2052 | |
| 2053 pktlen = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
2054 gaim_debug(GAIM_DEBUG_MISC, "yahoo", |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
2055 "%d bytes to read, rxlen is %d\n", pktlen, yd->rxlen); |
| 2681 | 2056 |
| 2057 if (yd->rxlen < (YAHOO_PACKET_HDRLEN + pktlen)) | |
| 2058 return; | |
| 2059 | |
| 2060 yahoo_packet_dump(yd->rxqueue, YAHOO_PACKET_HDRLEN + pktlen); | |
| 2061 | |
| 2062 pkt = yahoo_packet_new(0, 0, 0); | |
| 2063 | |
| 2064 pkt->service = yahoo_get16(yd->rxqueue + pos); pos += 2; | |
| 3021 | 2065 pkt->status = yahoo_get32(yd->rxqueue + pos); pos += 4; |
|
5220
7b9d78fa051e
[gaim-migrate @ 5590]
Christian Hammond <chipx86@chipx86.com>
parents:
5216
diff
changeset
|
2066 gaim_debug(GAIM_DEBUG_MISC, "yahoo", |
|
5216
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
2067 "Yahoo Service: 0x%02x Status: %d\n", |
|
00bd3019749e
[gaim-migrate @ 5586]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
2068 pkt->service, pkt->status); |
| 2681 | 2069 pkt->id = yahoo_get32(yd->rxqueue + pos); pos += 4; |
| 2070 | |
| 2071 yahoo_packet_read(pkt, yd->rxqueue + pos, pktlen); | |
| 2072 | |
| 2073 yd->rxlen -= YAHOO_PACKET_HDRLEN + pktlen; | |
| 2074 if (yd->rxlen) { | |
| 2075 char *tmp = g_memdup(yd->rxqueue + YAHOO_PACKET_HDRLEN + pktlen, yd->rxlen); | |
| 2076 g_free(yd->rxqueue); | |
| 2077 yd->rxqueue = tmp; | |
| 2078 } else { | |
| 2079 g_free(yd->rxqueue); | |
| 2080 yd->rxqueue = NULL; | |
| 2081 } | |
| 2082 | |
| 2083 yahoo_packet_process(gc, pkt); | |
| 2084 | |
| 2085 yahoo_packet_free(pkt); | |
| 2086 } | |
| 2087 } | |
| 2088 | |
|
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2089 #ifndef YAHOO_WEBMESSENGER |
| 2681 | 2090 static void yahoo_got_connected(gpointer data, gint source, GaimInputCondition cond) |
| 2091 { | |
| 5583 | 2092 GaimConnection *gc = data; |
| 2681 | 2093 struct yahoo_data *yd; |
| 2094 struct yahoo_packet *pkt; | |
| 2095 | |
|
5590
011a0a975060
[gaim-migrate @ 5994]
Christian Hammond <chipx86@chipx86.com>
parents:
5583
diff
changeset
|
2096 if (!g_list_find(gaim_connections_get_all(), gc)) { |
| 2681 | 2097 close(source); |
| 2098 return; | |
| 2099 } | |
| 2100 | |
| 2101 if (source < 0) { | |
| 8057 | 2102 gaim_connection_error(gc, _("Unable to connect.")); |
| 2681 | 2103 return; |
| 2104 } | |
| 2105 | |
| 2106 yd = gc->proto_data; | |
| 2107 yd->fd = source; | |
| 2108 | |
| 3147 | 2109 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YAHOO_STATUS_AVAILABLE, 0); |
| 2681 | 2110 |
| 7261 | 2111 yahoo_packet_hash(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); |
| 2681 | 2112 yahoo_send_packet(yd, pkt); |
| 2113 | |
| 2114 yahoo_packet_free(pkt); | |
| 2115 | |
| 2116 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | |
| 2117 } | |
|
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2118 #endif |
| 2681 | 2119 |
| 7134 | 2120 #ifdef YAHOO_WEBMESSENGER |
| 2121 static void yahoo_got_web_connected(gpointer data, gint source, GaimInputCondition cond) | |
| 2122 { | |
| 2123 GaimConnection *gc = data; | |
| 2124 struct yahoo_data *yd; | |
| 2125 struct yahoo_packet *pkt; | |
| 2126 | |
| 2127 if (!g_list_find(gaim_connections_get_all(), gc)) { | |
| 2128 close(source); | |
| 2129 return; | |
| 2130 } | |
| 2131 | |
| 2132 if (source < 0) { | |
| 8057 | 2133 gaim_connection_error(gc, _("Unable to connect.")); |
| 7134 | 2134 return; |
| 2135 } | |
| 2136 | |
| 2137 yd = gc->proto_data; | |
| 2138 yd->fd = source; | |
| 2139 | |
| 2140 pkt = yahoo_packet_new(YAHOO_SERVICE_WEBLOGIN, YAHOO_STATUS_WEBLOGIN, 0); | |
| 2141 | |
| 7261 | 2142 yahoo_packet_hash(pkt, 0, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); |
| 2143 yahoo_packet_hash(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); | |
| 7134 | 2144 yahoo_packet_hash(pkt, 6, yd->auth); |
| 2145 yahoo_send_packet(yd, pkt); | |
| 2146 | |
| 2147 yahoo_packet_free(pkt); | |
| 2148 g_free(yd->auth); | |
| 2149 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | |
| 2150 } | |
| 2151 | |
| 2152 static void yahoo_web_pending(gpointer data, gint source, GaimInputCondition cond) | |
| 2153 { | |
| 2154 GaimConnection *gc = data; | |
| 2155 GaimAccount *account = gaim_connection_get_account(gc); | |
| 2156 struct yahoo_data *yd = gc->proto_data; | |
| 8243 | 2157 char buf[2048], *i = buf; |
| 8161 | 2158 int len; |
| 2159 GString *s; | |
| 7134 | 2160 |
| 8118 | 2161 len = read(source, buf, sizeof(buf)-1); |
|
8216
dcace041cfb8
[gaim-migrate @ 8939]
Christian Hammond <chipx86@chipx86.com>
parents:
8212
diff
changeset
|
2162 if (len <= 0 || (strncmp(buf, "HTTP/1.0 302", strlen("HTTP/1.0 302")) && |
|
dcace041cfb8
[gaim-migrate @ 8939]
Christian Hammond <chipx86@chipx86.com>
parents:
8212
diff
changeset
|
2163 strncmp(buf, "HTTP/1.1 302", strlen("HTTP/1.1 302")))) { |
| 7134 | 2164 gaim_connection_error(gc, _("Unable to read")); |
| 2165 return; | |
| 2166 } | |
| 8161 | 2167 |
| 2168 s = g_string_sized_new(len); | |
| 8118 | 2169 buf[sizeof(buf)-1] = '\0'; |
| 8161 | 2170 |
| 2171 while ((i = strstr(i, "Set-Cookie: "))) { | |
| 2172 i += strlen("Set-Cookie: "); | |
| 8243 | 2173 for (;*i != ';' && *i != '\0'; i++) |
| 8161 | 2174 g_string_append_c(s, *i); |
| 2175 | |
| 2176 g_string_append(s, "; "); | |
| 7134 | 2177 } |
| 8161 | 2178 |
| 2179 yd->auth = g_string_free(s, FALSE); | |
| 7134 | 2180 gaim_input_remove(gc->inpa); |
| 2181 close(source); | |
| 2182 /* Now we have our cookies to login with. I'll go get the milk. */ | |
| 8045 | 2183 if (gaim_proxy_connect(account, "wcs2.msg.dcn.yahoo.com", |
| 7134 | 2184 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT), |
| 2185 yahoo_got_web_connected, gc) != 0) { | |
| 2186 gaim_connection_error(gc, _("Connection problem")); | |
| 2187 return; | |
| 2188 } | |
| 2189 } | |
| 2190 | |
| 2191 static void yahoo_got_cookies(gpointer data, gint source, GaimInputCondition cond) | |
| 2192 { | |
| 2193 GaimConnection *gc = data; | |
| 2194 struct yahoo_data *yd = gc->proto_data; | |
| 2195 if (source < 0) { | |
| 8057 | 2196 gaim_connection_error(gc, _("Unable to connect.")); |
| 7134 | 2197 return; |
| 2198 } | |
| 2199 write(source, yd->auth, strlen(yd->auth)); | |
| 2200 g_free(yd->auth); | |
| 2201 gc->inpa = gaim_input_add(source, GAIM_INPUT_READ, yahoo_web_pending, gc); | |
| 2202 } | |
| 2203 | |
| 2204 static void yahoo_login_page_hash_iter(const char *key, const char *val, GString *url) | |
| 2205 { | |
| 2206 if (!strcmp(key, "passwd")) | |
| 2207 return; | |
| 2208 url = g_string_append_c(url, '&'); | |
| 2209 url = g_string_append(url, key); | |
| 2210 url = g_string_append_c(url, '='); | |
| 2211 if (!strcmp(key, ".save") || !strcmp(key, ".js")) | |
| 2212 url = g_string_append_c(url, '1'); | |
| 2213 else if (!strcmp(key, ".challenge")) | |
| 2214 url = g_string_append(url, val); | |
| 2215 else | |
| 2216 url = g_string_append(url, gaim_url_encode(val)); | |
| 2217 } | |
| 2218 | |
| 2219 static GHashTable *yahoo_login_page_hash(const char *buf, size_t len) | |
| 2220 { | |
| 2221 GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
|
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2222 const char *c = buf; |
|
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2223 char *d; |
| 7134 | 2224 char name[64], value[64]; |
| 8118 | 2225 int count = sizeof(name)-1; |
| 7134 | 2226 while ((c < (buf + len)) && (c = strstr(c, "<input "))) { |
| 2227 c = strstr(c, "name=\"") + strlen("name=\""); | |
| 8118 | 2228 for (d = name; *c!='"' && count; c++, d++, count--) |
| 7134 | 2229 *d = *c; |
| 2230 *d = '\0'; | |
| 8118 | 2231 count = sizeof(value)-1; |
| 7134 | 2232 d = strstr(c, "value=\"") + strlen("value=\""); |
| 2233 if (strchr(c, '>') < d) | |
| 2234 break; | |
| 8118 | 2235 for (c = d, d = value; *c!='"' && count; c++, d++, count--) |
| 7134 | 2236 *d = *c; |
| 2237 *d = '\0'; | |
| 2238 g_hash_table_insert(hash, g_strdup(name), g_strdup(value)); | |
| 2239 } | |
| 2240 return hash; | |
| 2241 } | |
| 2242 | |
|
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2243 static void yahoo_login_page_cb(void *user_data, const char *buf, size_t len) |
| 7134 | 2244 { |
|
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2245 GaimConnection *gc = (GaimConnection *)user_data; |
| 7134 | 2246 GaimAccount *account = gaim_connection_get_account(gc); |
| 2247 struct yahoo_data *yd = gc->proto_data; | |
| 2248 const char *sn = gaim_account_get_username(account); | |
| 2249 const char *pass = gaim_account_get_password(account); | |
| 2250 GHashTable *hash = yahoo_login_page_hash(buf, len); | |
| 2251 GString *url = g_string_new("GET /config/login?login="); | |
| 2252 char md5[33], *hashp = md5, *chal; | |
| 2253 int i; | |
| 2254 md5_byte_t result[16]; | |
| 2255 md5_state_t ctx; | |
|
7191
4bd3892cded3
[gaim-migrate @ 7760]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7161
diff
changeset
|
2256 |
|
4bd3892cded3
[gaim-migrate @ 7760]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7161
diff
changeset
|
2257 url = g_string_append(url, sn); |
|
4bd3892cded3
[gaim-migrate @ 7760]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7161
diff
changeset
|
2258 url = g_string_append(url, "&passwd="); |
|
4bd3892cded3
[gaim-migrate @ 7760]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7161
diff
changeset
|
2259 |
| 7134 | 2260 md5_init(&ctx); |
| 2261 md5_append(&ctx, pass, strlen(pass)); | |
| 2262 md5_finish(&ctx, result); | |
| 2263 for (i = 0; i < 16; ++i) { | |
| 2264 g_snprintf(hashp, 3, "%02x", result[i]); | |
| 2265 hashp += 2; | |
| 2266 } | |
| 2267 chal = g_strconcat(md5, g_hash_table_lookup(hash, ".challenge"), NULL); | |
| 2268 md5_init(&ctx); | |
| 2269 md5_append(&ctx, chal, strlen(chal)); | |
| 2270 md5_finish(&ctx, result); | |
| 2271 hashp = md5; | |
| 2272 for (i = 0; i < 16; ++i) { | |
| 2273 g_snprintf(hashp, 3, "%02x", result[i]); | |
| 2274 hashp += 2; | |
| 2275 } | |
| 2276 /* | |
| 2277 md5_init(&ctx); | |
| 2278 md5_append(&ctx, md5, strlen(md5)); | |
| 2279 md5_finish(&ctx, result); | |
| 2280 hashp = md5; | |
| 2281 for (i = 0; i < 16; ++i) { | |
| 2282 g_snprintf(hashp, 3, "%02x", result[i]); | |
| 2283 hashp += 2; | |
| 2284 } | |
| 2285 */ | |
| 2286 g_free(chal); | |
| 2287 | |
| 2288 url = g_string_append(url, md5); | |
|
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2289 g_hash_table_foreach(hash, (GHFunc)yahoo_login_page_hash_iter, url); |
| 7134 | 2290 |
| 2291 url = g_string_append(url, "&.hash=1&.md5=1 HTTP/1.1\r\n" | |
| 2292 "Host: login.yahoo.com\r\n\r\n"); | |
| 2293 g_hash_table_destroy(hash); | |
| 2294 yd->auth = g_string_free(url, FALSE); | |
| 2295 if (gaim_proxy_connect(account, "login.yahoo.com", 80, yahoo_got_cookies, gc) != 0) { | |
| 2296 gaim_connection_error(gc, _("Connection problem")); | |
| 2297 return; | |
| 2298 } | |
| 2299 } | |
| 2300 | |
| 2301 #endif /* YAHOO_WEBMESSENGER */ | |
| 2302 | |
| 7883 | 2303 #ifndef YAHOO_WEBMESSENGER |
| 2304 static void yahoo_server_check(GaimAccount *account) | |
| 2305 { | |
| 2306 const char *server; | |
| 2307 | |
| 2308 server = gaim_account_get_string(account, "server", YAHOO_PAGER_HOST); | |
| 2309 | |
| 2310 if (strcmp(server, "scs.yahoo.com") == 0) | |
| 2311 gaim_account_set_string(account, "server", YAHOO_PAGER_HOST); | |
| 2312 } | |
| 9306 | 2313 |
| 2314 static void yahoo_picture_check(GaimAccount *account) | |
| 2315 { | |
| 2316 GaimConnection *gc = gaim_account_get_connection(account); | |
| 2317 const char *buddyicon; | |
| 2318 | |
| 2319 buddyicon = gaim_account_get_buddy_icon(account); | |
| 2320 yahoo_set_buddy_icon(gc, buddyicon); | |
| 2321 } | |
| 2322 | |
| 7883 | 2323 #endif |
| 2324 | |
| 5583 | 2325 static void yahoo_login(GaimAccount *account) { |
| 2326 GaimConnection *gc = gaim_account_get_connection(account); | |
| 2681 | 2327 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); |
| 2328 | |
| 9041 | 2329 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_URLDESC; |
| 6629 | 2330 |
| 5583 | 2331 gaim_connection_update_progress(gc, _("Connecting"), 1, 2); |
| 2681 | 2332 |
| 8235 | 2333 gaim_connection_set_display_name(gc, gaim_account_get_username(account)); |
| 2334 | |
| 2681 | 2335 yd->fd = -1; |
| 6784 | 2336 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free); |
| 6729 | 2337 yd->confs = NULL; |
| 2338 yd->conf_id = 2; | |
| 2681 | 2339 |
| 7134 | 2340 #ifndef YAHOO_WEBMESSENGER |
| 7827 | 2341 |
| 7883 | 2342 yahoo_server_check(account); |
| 9306 | 2343 yahoo_picture_check(account); |
| 7883 | 2344 |
| 9164 | 2345 if (gaim_account_get_bool(account, "yahoojp", FALSE)) { |
| 2346 yd->jp = TRUE; | |
| 2347 if (gaim_proxy_connect(account, | |
| 2348 gaim_account_get_string(account, "serverjp", YAHOOJP_PAGER_HOST), | |
| 2349 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT), | |
| 2350 yahoo_got_connected, gc) != 0) | |
| 2351 { | |
| 2352 gaim_connection_error(gc, _("Connection problem")); | |
| 2353 return; | |
| 2354 } | |
| 2355 } else { | |
| 2356 yd->jp = FALSE; | |
| 2357 if (gaim_proxy_connect(account, | |
| 2358 gaim_account_get_string(account, "server", YAHOO_PAGER_HOST), | |
| 2359 gaim_account_get_int(account, "port", YAHOO_PAGER_PORT), | |
| 2360 yahoo_got_connected, gc) != 0) | |
| 2361 { | |
| 2362 gaim_connection_error(gc, _("Connection problem")); | |
| 2363 return; | |
| 2364 } | |
| 2681 | 2365 } |
| 7134 | 2366 #else |
|
7138
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2367 gaim_url_fetch(WEBMESSENGER_URL, TRUE, "Gaim/" VERSION, FALSE, |
|
f189f8ccaa98
[gaim-migrate @ 7705]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
2368 yahoo_login_page_cb, gc); |
| 7134 | 2369 #endif |
| 2681 | 2370 |
| 2371 } | |
| 2372 | |
| 5583 | 2373 static void yahoo_close(GaimConnection *gc) { |
| 2681 | 2374 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
| 6729 | 2375 |
| 6784 | 2376 g_hash_table_destroy(yd->friends); |
| 6729 | 2377 g_slist_free(yd->confs); |
| 6784 | 2378 if (yd->chat_name) |
| 2379 g_free(yd->chat_name); | |
| 6729 | 2380 |
| 7651 | 2381 if (yd->cookie_y) |
| 2382 g_free(yd->cookie_y); | |
| 2383 if (yd->cookie_t) | |
| 2384 g_free(yd->cookie_t); | |
| 2385 | |
| 2681 | 2386 if (yd->fd >= 0) |
| 2387 close(yd->fd); | |
|
3720
34c95669952f
[gaim-migrate @ 3853]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3642
diff
changeset
|
2388 |
| 2681 | 2389 if (yd->rxqueue) |
| 2390 g_free(yd->rxqueue); | |
|
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2686
diff
changeset
|
2391 yd->rxlen = 0; |
| 9306 | 2392 if (yd->picture_url) |
| 2393 g_free(yd->picture_url); | |
| 2394 if (yd->picture_upload_todo) | |
| 2395 yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo); | |
| 2681 | 2396 if (gc->inpa) |
| 2397 gaim_input_remove(gc->inpa); | |
| 2398 g_free(yd); | |
| 2399 } | |
| 2400 | |
| 6695 | 2401 static const char *yahoo_list_icon(GaimAccount *a, GaimBuddy *b) |
| 2681 | 2402 { |
| 4687 | 2403 return "yahoo"; |
| 2681 | 2404 } |
| 4916 | 2405 |
| 6695 | 2406 static void yahoo_list_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne) |
| 4916 | 2407 { |
| 2408 int i = 0; | |
| 2409 char *emblems[4] = {NULL,NULL,NULL,NULL}; | |
| 6784 | 2410 GaimAccount *account; |
| 2411 GaimConnection *gc; | |
| 2412 struct yahoo_data *yd; | |
| 9278 | 2413 YahooFriend *f; |
| 6784 | 2414 |
| 2415 if (!b || !(account = b->account) || !(gc = gaim_account_get_connection(account)) || | |
| 2416 !(yd = gc->proto_data)) | |
| 2417 return; | |
| 2418 | |
| 9279 | 2419 f = yahoo_friend_find(gc, b->name); |
| 6784 | 2420 if (!f) { |
| 2421 *se = "notauthorized"; | |
| 2422 return; | |
| 2423 } | |
| 2424 | |
| 5068 | 2425 if (b->present == GAIM_BUDDY_OFFLINE) { |
| 4916 | 2426 *se = "offline"; |
| 2427 return; | |
| 2428 } else { | |
| 6784 | 2429 if (f->away) |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
2430 emblems[i++] = "away"; |
| 6784 | 2431 if (f->sms) |
| 2432 emblems[i++] = "wireless"; | |
| 9283 | 2433 if (yahoo_friend_get_game(f)) |
| 4916 | 2434 emblems[i++] = "game"; |
| 2435 } | |
| 2436 *se = emblems[0]; | |
| 2437 *sw = emblems[1]; | |
| 2438 *nw = emblems[2]; | |
| 2439 *ne = emblems[3]; | |
| 2440 } | |
| 2681 | 2441 |
| 2442 static char *yahoo_get_status_string(enum yahoo_status a) | |
| 2443 { | |
| 2444 switch (a) { | |
| 2445 case YAHOO_STATUS_BRB: | |
| 4596 | 2446 return _("Be Right Back"); |
| 2681 | 2447 case YAHOO_STATUS_BUSY: |
| 4596 | 2448 return _("Busy"); |
| 2681 | 2449 case YAHOO_STATUS_NOTATHOME: |
| 4596 | 2450 return _("Not At Home"); |
| 2681 | 2451 case YAHOO_STATUS_NOTATDESK: |
| 4596 | 2452 return _("Not At Desk"); |
| 2681 | 2453 case YAHOO_STATUS_NOTINOFFICE: |
| 4596 | 2454 return _("Not In Office"); |
| 2681 | 2455 case YAHOO_STATUS_ONPHONE: |
| 4606 | 2456 return _("On The Phone"); |
| 2681 | 2457 case YAHOO_STATUS_ONVACATION: |
| 4596 | 2458 return _("On Vacation"); |
| 2681 | 2459 case YAHOO_STATUS_OUTTOLUNCH: |
| 4596 | 2460 return _("Out To Lunch"); |
| 2681 | 2461 case YAHOO_STATUS_STEPPEDOUT: |
| 4596 | 2462 return _("Stepped Out"); |
|
2873
26be84883f91
[gaim-migrate @ 2886]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2856
diff
changeset
|
2463 case YAHOO_STATUS_INVISIBLE: |
| 4596 | 2464 return _("Invisible"); |
| 4730 | 2465 case YAHOO_STATUS_IDLE: |
| 2466 return _("Idle"); | |
| 6784 | 2467 case YAHOO_STATUS_OFFLINE: |
| 2468 return _("Offline"); | |
|
2879
5fc5123b7098
[gaim-migrate @ 2892]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2878
diff
changeset
|
2469 default: |
| 4596 | 2470 return _("Online"); |
| 2681 | 2471 } |
| 2472 } | |
| 2473 | |
| 9030 | 2474 static void yahoo_initiate_conference(GaimBlistNode *node, gpointer data) { |
| 2475 | |
| 2476 GaimBuddy *buddy; | |
| 2477 GaimConnection *gc; | |
| 2478 | |
| 6729 | 2479 GHashTable *components; |
| 2480 struct yahoo_data *yd; | |
| 2481 int id; | |
| 2482 | |
| 9030 | 2483 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
| 2484 | |
| 2485 buddy = (GaimBuddy *) node; | |
| 2486 gc = gaim_account_get_connection(buddy->account); | |
| 6729 | 2487 yd = gc->proto_data; |
| 2488 id = yd->conf_id; | |
| 2489 | |
| 2490 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 2491 g_hash_table_replace(components, g_strdup("room"), | |
| 2492 g_strdup_printf("%s-%d", gaim_connection_get_display_name(gc), id)); | |
| 2493 g_hash_table_replace(components, g_strdup("topic"), g_strdup("Join my conference...")); | |
| 2494 g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference")); | |
| 2495 yahoo_c_join(gc, components); | |
| 2496 g_hash_table_destroy(components); | |
| 2497 | |
| 9030 | 2498 yahoo_c_invite(gc, id, "Join my conference...", buddy->name); |
| 6729 | 2499 } |
| 2500 | |
| 9030 | 2501 static void yahoo_game(GaimBlistNode *node, gpointer data) { |
| 2502 | |
| 2503 GaimBuddy *buddy; | |
| 2504 GaimConnection *gc; | |
| 2505 | |
| 2506 struct yahoo_data *yd; | |
| 9283 | 2507 const char *game; |
| 2508 char *game2; | |
| 3019 | 2509 char *t; |
| 2510 char url[256]; | |
| 9278 | 2511 YahooFriend *f; |
| 3019 | 2512 |
| 9030 | 2513 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
| 2514 | |
| 2515 buddy = (GaimBuddy *) node; | |
| 2516 gc = gaim_account_get_connection(buddy->account); | |
| 2517 yd = (struct yahoo_data *) gc->proto_data; | |
| 2518 | |
| 9279 | 2519 f = yahoo_friend_find(gc, buddy->name); |
| 6784 | 2520 if (!f) |
| 2521 return; | |
| 2522 | |
| 9283 | 2523 game = yahoo_friend_get_game(f); |
| 3019 | 2524 if (!game) |
| 2525 return; | |
| 6784 | 2526 |
| 9283 | 2527 t = game2 = g_strdup(strstr(game, "ante?room=")); |
| 2528 while (*t && *t != '\t') | |
| 3019 | 2529 t++; |
| 2530 *t = 0; | |
| 9283 | 2531 g_snprintf(url, sizeof url, "http://games.yahoo.com/games/%s", game2); |
|
6465
fb64cc87bc96
[gaim-migrate @ 6974]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
2532 gaim_notify_uri(gc, url); |
| 9283 | 2533 g_free(game2); |
| 3019 | 2534 } |
| 4722 | 2535 |
| 6695 | 2536 static char *yahoo_status_text(GaimBuddy *b) |
| 4722 | 2537 { |
| 9278 | 2538 YahooFriend *f = NULL; |
| 9283 | 2539 const char *msg; |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
2540 |
| 9279 | 2541 f = yahoo_friend_find(b->account->gc, b->name); |
| 6784 | 2542 if (!f) |
| 2543 return g_strdup(_("Not on server list")); | |
| 2544 | |
| 2545 switch (f->status) { | |
| 2546 case YAHOO_STATUS_AVAILABLE: | |
| 2547 return NULL; | |
| 2548 case YAHOO_STATUS_IDLE: | |
| 2549 if (f->idle == -1) | |
| 2550 return g_strdup(yahoo_get_status_string(f->status)); | |
| 2551 return NULL; | |
| 2552 case YAHOO_STATUS_CUSTOM: | |
| 9283 | 2553 if (!(msg = yahoo_friend_get_status_message(f))) |
| 6784 | 2554 return NULL; |
| 9283 | 2555 return g_markup_escape_text(msg, strlen(msg)); |
| 9224 | 2556 |
| 6784 | 2557 default: |
| 2558 return g_strdup(yahoo_get_status_string(f->status)); | |
| 2559 } | |
| 4722 | 2560 } |
| 2561 | |
| 9220 | 2562 char *yahoo_tooltip_text(GaimBuddy *b) |
| 4724 | 2563 { |
| 9278 | 2564 YahooFriend *f; |
| 6784 | 2565 char *escaped, *status, *ret; |
| 2566 | |
| 9279 | 2567 f = yahoo_friend_find(b->account->gc, b->name); |
| 6784 | 2568 if (!f) |
| 8591 | 2569 status = g_strdup_printf("\n%s", _("Not on server list")); |
| 6784 | 2570 else |
| 2571 switch (f->status) { | |
| 2572 case YAHOO_STATUS_IDLE: | |
| 2573 if (f->idle == -1) { | |
| 2574 status = g_strdup(yahoo_get_status_string(f->status)); | |
| 2575 break; | |
| 2576 } | |
| 2577 return NULL; | |
| 2578 case YAHOO_STATUS_CUSTOM: | |
| 9283 | 2579 if (!yahoo_friend_get_status_message(f)) |
| 6784 | 2580 return NULL; |
| 9283 | 2581 status = g_strdup(yahoo_friend_get_status_message(f)); |
| 6784 | 2582 break; |
| 2583 default: | |
| 2584 status = g_strdup(yahoo_get_status_string(f->status)); | |
| 2585 break; | |
| 4745 | 2586 } |
| 6784 | 2587 |
| 2588 escaped = g_markup_escape_text(status, strlen(status)); | |
| 8591 | 2589 ret = g_strdup_printf(_("\n<b>%s:</b> %s"), _("Status"), escaped); |
| 6784 | 2590 g_free(status); |
| 2591 g_free(escaped); | |
| 2592 | |
| 2593 return ret; | |
| 4729 | 2594 } |
| 2595 | |
| 9030 | 2596 static void yahoo_addbuddyfrommenu_cb(GaimBlistNode *node, gpointer data) |
| 2597 { | |
| 2598 GaimBuddy *buddy; | |
| 2599 GaimConnection *gc; | |
| 2600 | |
| 2601 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 2602 | |
| 2603 buddy = (GaimBuddy *) node; | |
| 2604 gc = gaim_account_get_connection(buddy->account); | |
| 2605 | |
| 9285 | 2606 yahoo_add_buddy(gc, buddy, NULL); |
| 9030 | 2607 } |
| 2608 | |
| 2609 | |
| 2610 static void yahoo_chat_goto_menu(GaimBlistNode *node, gpointer data) | |
| 6796 | 2611 { |
| 9030 | 2612 GaimBuddy *buddy; |
| 2613 GaimConnection *gc; | |
| 2614 | |
| 2615 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 2616 | |
| 2617 buddy = (GaimBuddy *) node; | |
| 2618 gc = gaim_account_get_connection(buddy->account); | |
| 2619 | |
| 2620 yahoo_chat_goto(gc, buddy->name); | |
| 6796 | 2621 } |
| 2622 | |
| 9030 | 2623 |
| 2624 static void yahoo_ask_send_file_menu(GaimBlistNode *node, gpointer data) | |
| 2625 { | |
| 2626 GaimBuddy *buddy; | |
| 2627 GaimConnection *gc; | |
| 2628 | |
| 2629 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 2630 | |
| 2631 buddy = (GaimBuddy *) node; | |
| 2632 gc = gaim_account_get_connection(buddy->account); | |
| 2633 | |
| 2634 yahoo_ask_send_file(gc, buddy->name); | |
| 2635 } | |
| 2636 | |
| 2637 | |
| 2638 static GList *yahoo_buddy_menu(GaimBuddy *buddy) | |
| 2681 | 2639 { |
| 2640 GList *m = NULL; | |
| 9030 | 2641 GaimBlistNodeAction *act; |
| 2642 | |
| 2643 GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
| 3019 | 2644 static char buf2[1024]; |
| 9278 | 2645 YahooFriend *f; |
| 6784 | 2646 |
| 9279 | 2647 f = yahoo_friend_find(gc, buddy->name); |
| 6784 | 2648 |
| 2649 if (!f) { | |
| 9030 | 2650 act = gaim_blist_node_action_new(_("Add Buddy"), |
| 2651 yahoo_addbuddyfrommenu_cb, NULL); | |
| 2652 m = g_list_append(m, act); | |
| 6784 | 2653 |
| 2654 return m; | |
| 9030 | 2655 |
| 2656 } else if (f->status == YAHOO_STATUS_OFFLINE) { | |
| 6784 | 2657 return NULL; |
| 9030 | 2658 } |
| 2659 | |
| 2660 act = gaim_blist_node_action_new(_("Join in Chat"), | |
| 2661 yahoo_chat_goto_menu, NULL); | |
| 2662 m = g_list_append(m, act); | |
| 2663 | |
| 2664 act = gaim_blist_node_action_new(_("Initiate Conference"), | |
| 2665 yahoo_initiate_conference, NULL); | |
| 2666 m = g_list_append(m, act); | |
| 6729 | 2667 |
| 7651 | 2668 /* FIXME: remove this when the ui does it for us. */ |
| 9030 | 2669 act = gaim_blist_node_action_new(_("Send File"), |
| 2670 yahoo_ask_send_file_menu, NULL); | |
| 2671 m = g_list_append(m, act); | |
| 7651 | 2672 |
| 9283 | 2673 if (yahoo_friend_get_game(f)) { |
| 2674 const char *game = yahoo_friend_get_game(f); | |
| 3019 | 2675 char *room; |
| 6784 | 2676 char *t; |
| 2677 | |
| 2678 if (!(room = strstr(game, "&follow="))) /* skip ahead to the url */ | |
| 2679 return m; | |
| 2680 while (*room && *room != '\t') /* skip to the tab */ | |
| 2681 room++; | |
| 2682 t = room++; /* room as now at the name */ | |
| 2683 while (*t != '\n') | |
| 2684 t++; /* replace the \n with a space */ | |
| 2685 *t = ' '; | |
| 2686 g_snprintf(buf2, sizeof buf2, "%s", room); | |
| 9030 | 2687 |
| 2688 act = gaim_blist_node_action_new(buf2, yahoo_game, NULL); | |
| 2689 m = g_list_append(m, act); | |
| 3019 | 2690 } |
| 6729 | 2691 |
| 2681 | 2692 return m; |
| 2693 } | |
| 2694 | |
| 9030 | 2695 |
| 2696 static GList *yahoo_blist_node_menu(GaimBlistNode *node) | |
| 2697 { | |
| 2698 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 2699 return yahoo_buddy_menu((GaimBuddy *) node); | |
| 2700 } else { | |
| 2701 return NULL; | |
| 2702 } | |
| 2703 } | |
| 2704 | |
| 2705 | |
| 5583 | 2706 static void yahoo_act_id(GaimConnection *gc, const char *entry) |
| 2681 | 2707 { |
| 2708 struct yahoo_data *yd = gc->proto_data; | |
| 2709 | |
| 2710 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0); | |
| 2711 yahoo_packet_hash(pkt, 3, entry); | |
| 2712 yahoo_send_packet(yd, pkt); | |
| 2713 yahoo_packet_free(pkt); | |
| 2714 | |
| 5583 | 2715 gaim_connection_set_display_name(gc, entry); |
| 2681 | 2716 } |
| 2717 | |
| 9015 | 2718 static void yahoo_show_act_id(GaimPluginAction *action) |
| 2681 | 2719 { |
| 9015 | 2720 GaimConnection *gc = (GaimConnection *) action->context; |
|
5493
3e8487580024
[gaim-migrate @ 5889]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
2721 gaim_request_input(gc, NULL, _("Active which ID?"), NULL, |
| 8697 | 2722 gaim_connection_get_display_name(gc), FALSE, FALSE, NULL, |
|
5493
3e8487580024
[gaim-migrate @ 5889]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
2723 _("OK"), G_CALLBACK(yahoo_act_id), |
|
3e8487580024
[gaim-migrate @ 5889]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
2724 _("Cancel"), NULL, gc); |
| 2681 | 2725 } |
| 2726 | |
| 9015 | 2727 static void yahoo_show_chat_goto(GaimPluginAction *action) |
| 7878 | 2728 { |
| 9015 | 2729 GaimConnection *gc = (GaimConnection *) action->context; |
| 7878 | 2730 gaim_request_input(gc, NULL, _("Join who in chat?"), NULL, |
| 8697 | 2731 "", FALSE, FALSE, NULL, |
| 7878 | 2732 _("OK"), G_CALLBACK(yahoo_chat_goto), |
| 2733 _("Cancel"), NULL, gc); | |
| 2734 } | |
| 2735 | |
| 9015 | 2736 static GList *yahoo_actions(GaimPlugin *plugin, gpointer context) { |
| 2681 | 2737 GList *m = NULL; |
| 9015 | 2738 GaimPluginAction *act; |
| 2739 | |
| 2740 act = gaim_plugin_action_new(_("Activate ID..."), | |
| 2741 yahoo_show_act_id); | |
| 2742 m = g_list_append(m, act); | |
| 2743 | |
| 2744 act = gaim_plugin_action_new(_("Join user in chat..."), | |
| 2745 yahoo_show_chat_goto); | |
| 2746 m = g_list_append(m, act); | |
| 7878 | 2747 |
| 2681 | 2748 return m; |
| 2749 } | |
| 2750 | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7112
diff
changeset
|
2751 static int yahoo_send_im(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags) |
| 2681 | 2752 { |
| 2753 struct yahoo_data *yd = gc->proto_data; | |
| 2754 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, YAHOO_STATUS_OFFLINE, 0); | |
| 6629 | 2755 char *msg = yahoo_html_to_codes(what); |
| 7827 | 2756 char *msg2; |
| 2757 gboolean utf8 = TRUE; | |
| 2758 | |
| 2759 msg2 = yahoo_string_encode(gc, msg, &utf8); | |
| 2681 | 2760 |
| 5583 | 2761 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
| 2681 | 2762 yahoo_packet_hash(pkt, 5, who); |
| 7827 | 2763 if (utf8) |
| 2764 yahoo_packet_hash(pkt, 97, "1"); | |
| 2765 yahoo_packet_hash(pkt, 14, msg2); | |
| 2766 | |
| 9280 | 2767 yahoo_packet_hash(pkt, 63, ";0"); /* IMvironment */ |
| 2768 yahoo_packet_hash(pkt, 64, "0"); /* no idea */ | |
| 9062 | 2769 yahoo_packet_hash(pkt, 1002, "1"); /* no idea, Yahoo 6 or later only it seems */ |
| 9306 | 2770 if (!yd->picture_url) |
| 2771 yahoo_packet_hash(pkt, 206, "0"); /* 0 = no picture, 2 = picture, maybe 1 = avatar? */ | |
| 2772 else | |
| 2773 yahoo_packet_hash(pkt, 206, "2"); | |
| 2681 | 2774 |
| 2775 yahoo_send_packet(yd, pkt); | |
| 2776 | |
| 2777 yahoo_packet_free(pkt); | |
| 6629 | 2778 |
| 2779 g_free(msg); | |
| 7827 | 2780 g_free(msg2); |
| 6629 | 2781 |
| 2681 | 2782 return 1; |
| 2783 } | |
| 2784 | |
| 6059 | 2785 int yahoo_send_typing(GaimConnection *gc, const char *who, int typ) |
| 2993 | 2786 { |
| 2787 struct yahoo_data *yd = gc->proto_data; | |
| 3019 | 2788 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0); |
| 2993 | 2789 yahoo_packet_hash(pkt, 49, "TYPING"); |
| 5583 | 2790 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
| 2993 | 2791 yahoo_packet_hash(pkt, 14, " "); |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5685
diff
changeset
|
2792 yahoo_packet_hash(pkt, 13, typ == GAIM_TYPING ? "1" : "0"); |
| 2993 | 2793 yahoo_packet_hash(pkt, 5, who); |
| 2794 yahoo_packet_hash(pkt, 1002, "1"); | |
| 2795 | |
| 2796 yahoo_send_packet(yd, pkt); | |
| 2797 | |
| 2798 yahoo_packet_free(pkt); | |
| 2799 | |
| 3001 | 2800 return 0; |
| 2993 | 2801 } |
| 2802 | |
| 6059 | 2803 static void yahoo_set_away(GaimConnection *gc, const char *state, const char *msg) |
| 2681 | 2804 { |
| 2805 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 2806 struct yahoo_packet *pkt; | |
|
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
2807 int service; |
| 2681 | 2808 char s[4]; |
| 7827 | 2809 char *conv_msg = NULL; |
| 8503 | 2810 char *conv_msg2 = NULL; |
|
6691
306790891ce7
[gaim-migrate @ 7217]
Christian Hammond <chipx86@chipx86.com>
parents:
6687
diff
changeset
|
2811 |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4044
diff
changeset
|
2812 if (gc->away) { |
|
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4044
diff
changeset
|
2813 g_free(gc->away); |
|
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4044
diff
changeset
|
2814 gc->away = NULL; |
|
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4044
diff
changeset
|
2815 } |
| 2681 | 2816 |
| 2817 if (msg) { | |
| 2818 yd->current_status = YAHOO_STATUS_CUSTOM; | |
| 6847 | 2819 gc->away = g_strndup(msg, YAHOO_MAX_STATUS_MESSAGE_LENGTH); |
| 2681 | 2820 } else if (state) { |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4044
diff
changeset
|
2821 gc->away = g_strdup(""); |
| 4596 | 2822 if (!strcmp(state, _("Available"))) { |
| 2681 | 2823 yd->current_status = YAHOO_STATUS_AVAILABLE; |
| 4596 | 2824 } else if (!strcmp(state, _("Be Right Back"))) { |
| 2681 | 2825 yd->current_status = YAHOO_STATUS_BRB; |
| 4596 | 2826 } else if (!strcmp(state, _("Busy"))) { |
| 2681 | 2827 yd->current_status = YAHOO_STATUS_BUSY; |
| 4596 | 2828 } else if (!strcmp(state, _("Not At Home"))) { |
| 2681 | 2829 yd->current_status = YAHOO_STATUS_NOTATHOME; |
| 4596 | 2830 } else if (!strcmp(state, _("Not At Desk"))) { |
| 2681 | 2831 yd->current_status = YAHOO_STATUS_NOTATDESK; |
| 4596 | 2832 } else if (!strcmp(state, _("Not In Office"))) { |
| 2681 | 2833 yd->current_status = YAHOO_STATUS_NOTINOFFICE; |
| 4606 | 2834 } else if (!strcmp(state, _("On The Phone"))) { |
| 2681 | 2835 yd->current_status = YAHOO_STATUS_ONPHONE; |
| 4596 | 2836 } else if (!strcmp(state, _("On Vacation"))) { |
| 2681 | 2837 yd->current_status = YAHOO_STATUS_ONVACATION; |
| 4596 | 2838 } else if (!strcmp(state, _("Out To Lunch"))) { |
| 2681 | 2839 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; |
| 4596 | 2840 } else if (!strcmp(state, _("Stepped Out"))) { |
| 2681 | 2841 yd->current_status = YAHOO_STATUS_STEPPEDOUT; |
| 4596 | 2842 } else if (!strcmp(state, _("Invisible"))) { |
| 2681 | 2843 yd->current_status = YAHOO_STATUS_INVISIBLE; |
| 6847 | 2844 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { /* this should never happen? */ |
| 2681 | 2845 if (gc->is_idle) { |
| 2846 yd->current_status = YAHOO_STATUS_IDLE; | |
| 2847 } else { | |
| 2848 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 2849 } | |
| 2850 } | |
| 2851 } else if (gc->is_idle) { | |
| 2852 yd->current_status = YAHOO_STATUS_IDLE; | |
| 2853 } else { | |
| 2854 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 2855 } | |
| 2856 | |
|
2772
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
2857 if (yd->current_status == YAHOO_STATUS_AVAILABLE) |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
2858 service = YAHOO_SERVICE_ISBACK; |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
2859 else |
|
f9227268db25
[gaim-migrate @ 2785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2771
diff
changeset
|
2860 service = YAHOO_SERVICE_ISAWAY; |
| 6847 | 2861 |
| 2862 pkt = yahoo_packet_new(service, YAHOO_STATUS_AVAILABLE, 0); | |
| 2681 | 2863 g_snprintf(s, sizeof(s), "%d", yd->current_status); |
| 2864 yahoo_packet_hash(pkt, 10, s); | |
| 6847 | 2865 |
| 7827 | 2866 if ((yd->current_status == YAHOO_STATUS_CUSTOM) && gc->away) { |
| 2867 conv_msg = yahoo_string_encode(gc, gc->away, NULL); | |
| 8503 | 2868 conv_msg2 = gaim_unescape_html(conv_msg); |
| 2869 yahoo_packet_hash(pkt, 19, conv_msg2); | |
| 7827 | 2870 } |
| 6847 | 2871 |
| 2872 if ((yd->current_status != YAHOO_STATUS_AVAILABLE) && | |
| 2873 (yd->current_status != YAHOO_STATUS_IDLE)) { | |
| 6784 | 2874 if (gc->is_idle) |
| 2875 yahoo_packet_hash(pkt, 47, "2"); | |
| 2876 else | |
| 2877 yahoo_packet_hash(pkt, 47, "1"); | |
| 6686 | 2878 } |
| 2681 | 2879 |
| 2880 yahoo_send_packet(yd, pkt); | |
| 2881 yahoo_packet_free(pkt); | |
| 7827 | 2882 if (conv_msg) |
| 2883 g_free(conv_msg); | |
| 8503 | 2884 if (conv_msg2) |
| 2885 g_free(conv_msg2); | |
| 2681 | 2886 } |
| 2887 | |
| 5583 | 2888 static void yahoo_set_idle(GaimConnection *gc, int idle) |
| 2681 | 2889 { |
| 2890 struct yahoo_data *yd = gc->proto_data; | |
| 2891 struct yahoo_packet *pkt = NULL; | |
| 8503 | 2892 char *msg = NULL, *msg2 = NULL; |
| 2681 | 2893 |
| 2894 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
| 6847 | 2895 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); |
| 2681 | 2896 yd->current_status = YAHOO_STATUS_IDLE; |
| 2897 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
| 2898 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); | |
| 2899 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
| 6847 | 2900 } else { |
| 6784 | 2901 pkt = yahoo_packet_new(YAHOO_SERVICE_ISAWAY, YAHOO_STATUS_AVAILABLE, 0); |
| 2681 | 2902 } |
| 2903 | |
| 2904 if (pkt) { | |
| 2905 char buf[4]; | |
| 2906 g_snprintf(buf, sizeof(buf), "%d", yd->current_status); | |
| 2907 yahoo_packet_hash(pkt, 10, buf); | |
| 6784 | 2908 if (gc->away && yd->current_status == YAHOO_STATUS_CUSTOM) { |
| 7827 | 2909 msg = yahoo_string_encode(gc, gc->away, NULL); |
| 8503 | 2910 msg2 = gaim_unescape_html(msg); |
| 2911 yahoo_packet_hash(pkt, 19, msg2); | |
| 6784 | 2912 if (idle) |
| 2913 yahoo_packet_hash(pkt, 47, "2"); | |
| 2914 else | |
| 2915 yahoo_packet_hash(pkt, 47, "1"); /* fixme when available messages are possible */ | |
| 6847 | 2916 } else if (idle && (yd->current_status != YAHOO_STATUS_AVAILABLE) && |
| 2917 (yd->current_status != YAHOO_STATUS_IDLE)) { | |
| 2918 yahoo_packet_hash(pkt, 47, "2"); | |
| 2919 } else if (!idle && (yd->current_status != YAHOO_STATUS_AVAILABLE) && | |
| 2920 (yd->current_status != YAHOO_STATUS_IDLE)) { | |
| 2921 yahoo_packet_hash(pkt, 47, "1"); | |
| 6784 | 2922 } |
| 6847 | 2923 |
| 2681 | 2924 yahoo_send_packet(yd, pkt); |
| 2925 yahoo_packet_free(pkt); | |
| 2926 } | |
| 7827 | 2927 if (msg) |
| 2928 g_free(msg); | |
| 8503 | 2929 if (msg2) |
| 2930 g_free(msg2); | |
| 2681 | 2931 } |
| 2932 | |
| 5583 | 2933 static GList *yahoo_away_states(GaimConnection *gc) |
| 2681 | 2934 { |
| 2935 GList *m = NULL; | |
| 2936 | |
| 4596 | 2937 m = g_list_append(m, _("Available")); |
| 2938 m = g_list_append(m, _("Be Right Back")); | |
| 2939 m = g_list_append(m, _("Busy")); | |
| 2940 m = g_list_append(m, _("Not At Home")); | |
| 2941 m = g_list_append(m, _("Not At Desk")); | |
| 2942 m = g_list_append(m, _("Not In Office")); | |
| 4606 | 2943 m = g_list_append(m, _("On The Phone")); |
| 4596 | 2944 m = g_list_append(m, _("On Vacation")); |
| 2945 m = g_list_append(m, _("Out To Lunch")); | |
| 2946 m = g_list_append(m, _("Stepped Out")); | |
| 2947 m = g_list_append(m, _("Invisible")); | |
| 2681 | 2948 m = g_list_append(m, GAIM_AWAY_CUSTOM); |
| 2949 | |
| 2950 return m; | |
| 2951 } | |
| 2952 | |
| 5583 | 2953 static void yahoo_keepalive(GaimConnection *gc) |
| 2681 | 2954 { |
| 2955 struct yahoo_data *yd = gc->proto_data; | |
| 2956 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0); | |
| 2957 yahoo_send_packet(yd, pkt); | |
| 2958 yahoo_packet_free(pkt); | |
| 6729 | 2959 |
| 2960 if (!yd->chat_online) | |
| 2961 return; | |
| 2962 | |
| 2963 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YAHOO_STATUS_AVAILABLE, 0); | |
| 2964 yahoo_packet_hash(pkt, 109, gaim_connection_get_display_name(gc)); | |
| 2965 yahoo_send_packet(yd, pkt); | |
| 2966 yahoo_packet_free(pkt); | |
| 2681 | 2967 } |
| 2968 | |
| 9285 | 2969 /* XXX - What's the deal with GaimGroup *foo? */ |
| 2970 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *foo) | |
| 2681 | 2971 { |
| 2972 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 2973 struct yahoo_packet *pkt; | |
| 6695 | 2974 GaimGroup *g; |
| 2681 | 2975 char *group = NULL; |
| 7829 | 2976 char *group2 = NULL; |
| 2681 | 2977 |
| 2978 if (!yd->logged_in) | |
| 2979 return; | |
| 2980 | |
| 6840 | 2981 if (foo) |
| 2982 group = foo->name; | |
| 2983 if (!group) { | |
| 9285 | 2984 g = gaim_find_buddys_group(gaim_find_buddy(gc->account, buddy->name)); |
| 6840 | 2985 if (g) |
| 2986 group = g->name; | |
| 2987 else | |
| 2988 group = "Buddies"; | |
| 2989 } | |
| 2681 | 2990 |
| 7829 | 2991 group2 = yahoo_string_encode(gc, group, NULL); |
| 2681 | 2992 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); |
| 5583 | 2993 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
| 9285 | 2994 yahoo_packet_hash(pkt, 7, buddy->name); |
| 7829 | 2995 yahoo_packet_hash(pkt, 65, group2); |
| 6820 | 2996 yahoo_packet_hash(pkt, 14, ""); |
| 2681 | 2997 yahoo_send_packet(yd, pkt); |
| 2998 yahoo_packet_free(pkt); | |
| 7829 | 2999 g_free(group2); |
| 2681 | 3000 } |
| 3001 | |
| 9285 | 3002 static void yahoo_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
| 2681 | 3003 { |
| 3004 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 9278 | 3005 YahooFriend *f; |
|
6795
40ba19133882
[gaim-migrate @ 7334]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6793
diff
changeset
|
3006 struct yahoo_packet *pkt; |
| 6840 | 3007 GSList *buddies, *l; |
| 3008 GaimGroup *g; | |
| 3009 gboolean remove = TRUE; | |
| 7827 | 3010 char *cg; |
| 6784 | 3011 |
| 9285 | 3012 if (!(f = yahoo_friend_find(gc, buddy->name))) |
| 6784 | 3013 return; |
| 3014 | |
| 9285 | 3015 buddies = gaim_find_buddies(gaim_connection_get_account(gc), buddy->name); |
| 6840 | 3016 for (l = buddies; l; l = l->next) { |
| 3017 g = gaim_find_buddys_group(l->data); | |
| 9285 | 3018 if (gaim_utf8_strcasecmp(group->name, g->name)) { |
| 6840 | 3019 remove = FALSE; |
| 3020 break; | |
| 3021 } | |
| 3022 } | |
| 3023 | |
| 3024 g_slist_free(buddies); | |
| 3025 | |
| 3026 if (remove) | |
| 9285 | 3027 g_hash_table_remove(yd->friends, buddy->name); |
| 3028 | |
| 3029 cg = yahoo_string_encode(gc, group->name, NULL); | |
|
6795
40ba19133882
[gaim-migrate @ 7334]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6793
diff
changeset
|
3030 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); |
| 5583 | 3031 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
| 9285 | 3032 yahoo_packet_hash(pkt, 7, buddy->name); |
| 7827 | 3033 yahoo_packet_hash(pkt, 65, cg); |
| 2681 | 3034 yahoo_send_packet(yd, pkt); |
| 3035 yahoo_packet_free(pkt); | |
| 7827 | 3036 g_free(cg); |
| 2681 | 3037 } |
| 3038 | |
| 6760 | 3039 static void yahoo_add_deny(GaimConnection *gc, const char *who) { |
| 3040 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 3041 struct yahoo_packet *pkt; | |
| 3042 | |
| 3043 if (!yd->logged_in) | |
| 3044 return; | |
| 8057 | 3045 /* It seems to work better without this */ |
| 3046 | |
| 8113 | 3047 /* if (gc->account->perm_deny != 4) |
| 3048 return; */ | |
| 3049 | |
| 3050 if (!who || who[0] == '\0') | |
| 3051 return; | |
| 3052 | |
| 6760 | 3053 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); |
| 3054 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
| 3055 yahoo_packet_hash(pkt, 7, who); | |
| 3056 yahoo_packet_hash(pkt, 13, "1"); | |
| 3057 yahoo_send_packet(yd, pkt); | |
| 3058 yahoo_packet_free(pkt); | |
| 3059 } | |
| 3060 | |
| 3061 static void yahoo_rem_deny(GaimConnection *gc, const char *who) { | |
| 3062 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
| 3063 struct yahoo_packet *pkt; | |
| 3064 | |
| 3065 if (!yd->logged_in) | |
| 3066 return; | |
| 3067 | |
| 3068 if (!who || who[0] == '\0') | |
| 3069 return; | |
| 3070 | |
| 3071 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); | |
| 3072 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
| 3073 yahoo_packet_hash(pkt, 7, who); | |
| 3074 yahoo_packet_hash(pkt, 13, "2"); | |
| 3075 yahoo_send_packet(yd, pkt); | |
| 3076 yahoo_packet_free(pkt); | |
| 3077 } | |
| 3078 | |
| 3079 static void yahoo_set_permit_deny(GaimConnection *gc) { | |
| 3080 GaimAccount *acct; | |
| 3081 GSList *deny; | |
| 3082 | |
| 3083 acct = gc->account; | |
| 3084 | |
| 3085 switch (acct->perm_deny) { | |
| 3086 case 1: | |
| 3087 case 3: | |
| 3088 case 5: | |
| 3089 for (deny = acct->deny;deny;deny = deny->next) | |
| 3090 yahoo_rem_deny(gc, deny->data); | |
| 3091 break; | |
| 3092 case 4: | |
| 3093 for (deny = acct->deny;deny;deny = deny->next) | |
| 3094 yahoo_add_deny(gc, deny->data); | |
| 3095 break; | |
| 3096 case 2: | |
| 3097 default: | |
| 3098 break; | |
| 3099 } | |
| 3100 } | |
| 3101 | |
| 6513 | 3102 static gboolean yahoo_unload_plugin(GaimPlugin *plugin) |
| 3103 { | |
| 3104 yahoo_dest_colorht(); | |
| 3105 return TRUE; | |
| 3106 } | |
| 3107 | |
| 6793 | 3108 static void yahoo_change_buddys_group(GaimConnection *gc, const char *who, |
| 3109 const char *old_group, const char *new_group) | |
| 3110 { | |
| 3111 struct yahoo_data *yd = gc->proto_data; | |
| 3112 struct yahoo_packet *pkt; | |
| 7827 | 3113 char *gpn, *gpo; |
| 6793 | 3114 |
| 3115 /* Step 0: If they aren't on the server list anyway, | |
| 3116 * don't bother letting the server know. | |
| 3117 */ | |
| 9279 | 3118 if (!yahoo_friend_find(gc, who)) |
| 6793 | 3119 return; |
| 3120 | |
| 7827 | 3121 /* If old and new are the same, we would probably |
| 3122 * end up deleting the buddy, which would be bad. | |
| 3123 * This might happen because of the charset conversation. | |
| 3124 */ | |
| 3125 gpn = yahoo_string_encode(gc, new_group, NULL); | |
| 3126 gpo = yahoo_string_encode(gc, old_group, NULL); | |
| 3127 if (!strcmp(gpn, gpo)) { | |
| 3128 g_free(gpn); | |
| 3129 g_free(gpo); | |
| 3130 return; | |
| 3131 } | |
| 3132 | |
| 6793 | 3133 /* Step 1: Add buddy to new group. */ |
| 3134 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
| 3135 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
| 3136 yahoo_packet_hash(pkt, 7, who); | |
| 7827 | 3137 yahoo_packet_hash(pkt, 65, gpn); |
| 6793 | 3138 yahoo_packet_hash(pkt, 14, ""); |
| 3139 yahoo_send_packet(yd, pkt); | |
| 3140 yahoo_packet_free(pkt); | |
| 3141 | |
| 3142 /* Step 2: Remove buddy from old group */ | |
| 3143 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); | |
| 3144 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
| 3145 yahoo_packet_hash(pkt, 7, who); | |
| 7827 | 3146 yahoo_packet_hash(pkt, 65, gpo); |
| 6793 | 3147 yahoo_send_packet(yd, pkt); |
| 3148 yahoo_packet_free(pkt); | |
| 7827 | 3149 g_free(gpn); |
| 3150 g_free(gpo); | |
| 6793 | 3151 } |
| 3152 | |
| 9285 | 3153 static void yahoo_rename_group(GaimConnection *gc, const char *old_name, |
| 3154 GaimGroup *group, GList *moved_buddies) | |
| 6793 | 3155 { |
| 3156 struct yahoo_data *yd = gc->proto_data; | |
| 3157 struct yahoo_packet *pkt; | |
| 7827 | 3158 char *gpn, *gpo; |
| 3159 | |
| 9285 | 3160 gpn = yahoo_string_encode(gc, group->name, NULL); |
| 3161 gpo = yahoo_string_encode(gc, old_name, NULL); | |
| 7827 | 3162 if (!strcmp(gpn, gpo)) { |
| 3163 g_free(gpn); | |
| 3164 g_free(gpo); | |
| 3165 return; | |
| 3166 } | |
| 6793 | 3167 |
| 3168 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, YAHOO_STATUS_AVAILABLE, 0); | |
| 3169 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
| 7827 | 3170 yahoo_packet_hash(pkt, 65, gpo); |
| 3171 yahoo_packet_hash(pkt, 67, gpn); | |
| 6793 | 3172 yahoo_send_packet(yd, pkt); |
| 3173 yahoo_packet_free(pkt); | |
| 7827 | 3174 g_free(gpn); |
| 3175 g_free(gpo); | |
| 6793 | 3176 } |
| 3177 | |
| 7696 | 3178 #if 0 |
| 7651 | 3179 static gboolean yahoo_has_send_file(GaimConnection *gc, const char *who) |
| 3180 { | |
| 3181 return TRUE; | |
| 3182 } | |
| 7696 | 3183 #endif |
| 7651 | 3184 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3185 static GaimPlugin *my_protocol = NULL; |
| 2681 | 3186 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3187 static GaimPluginProtocolInfo prpl_info = |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3188 { |
|
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3189 GAIM_PRPL_API_VERSION, |
| 9308 | 3190 OPT_PROTO_MAIL_CHECK | OPT_PROTO_CHAT_TOPIC, |
| 6729 | 3191 NULL, /* user_splits */ |
| 3192 NULL, /* protocol_options */ | |
| 9318 | 3193 {"png", 96, 96, 96, 96, GAIM_ICON_SCALE_SEND}, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3194 yahoo_list_icon, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3195 yahoo_list_emblems, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3196 yahoo_status_text, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3197 yahoo_tooltip_text, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3198 yahoo_away_states, |
| 9030 | 3199 yahoo_blist_node_menu, |
| 6729 | 3200 yahoo_c_info, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3201 yahoo_login, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3202 yahoo_close, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3203 yahoo_send_im, |
| 6729 | 3204 NULL, /* set info */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3205 yahoo_send_typing, |
| 6514 | 3206 yahoo_get_info, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3207 yahoo_set_away, |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3208 yahoo_set_idle, |
| 6729 | 3209 NULL, /* change_passwd*/ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3210 yahoo_add_buddy, |
| 6729 | 3211 NULL, /* add_buddies */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3212 yahoo_remove_buddy, |
| 6729 | 3213 NULL, /*remove_buddies */ |
| 3214 NULL, /* add_permit */ | |
| 6760 | 3215 yahoo_add_deny, |
| 6729 | 3216 NULL, /* rem_permit */ |
| 6760 | 3217 yahoo_rem_deny, |
| 3218 yahoo_set_permit_deny, | |
| 6729 | 3219 NULL, /* warn */ |
| 3220 yahoo_c_join, | |
| 8562 | 3221 NULL, /* reject chat invite */ |
| 6729 | 3222 yahoo_c_invite, |
| 3223 yahoo_c_leave, | |
| 3224 NULL, /* chat whisper */ | |
| 3225 yahoo_c_send, | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3226 yahoo_keepalive, |
| 6729 | 3227 NULL, /* register_user */ |
| 3228 NULL, /* get_cb_info */ | |
| 3229 NULL, /* get_cb_away */ | |
| 3230 NULL, /* alias_buddy */ | |
| 6793 | 3231 yahoo_change_buddys_group, |
| 3232 yahoo_rename_group, | |
| 6729 | 3233 NULL, /* buddy_free */ |
| 3234 NULL, /* convo_closed */ | |
| 3235 NULL, /* normalize */ | |
| 9306 | 3236 yahoo_set_buddy_icon, |
| 7651 | 3237 NULL, /* void (*remove_group)(GaimConnection *gc, const char *group);*/ |
| 3238 NULL, /* char *(*get_cb_real_name)(GaimConnection *gc, int id, const char *who); */ | |
| 3239 #if 0 | |
| 3240 yahoo_ask_send_file, | |
| 3241 yahoo_send_file, | |
| 8113 | 3242 yahoo_has_send_file, |
| 7651 | 3243 #endif |
| 8113 | 3244 NULL, |
| 3245 NULL, | |
| 3246 yahoo_roomlist_get_list, | |
| 3247 yahoo_roomlist_cancel, | |
| 9030 | 3248 yahoo_roomlist_expand_category |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3249 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3250 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3251 static GaimPluginInfo info = |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3252 { |
|
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3253 GAIM_PLUGIN_API_VERSION, /**< api_version */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3254 GAIM_PLUGIN_PROTOCOL, /**< type */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3255 NULL, /**< ui_requirement */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3256 0, /**< flags */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3257 NULL, /**< dependencies */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3258 GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3259 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3260 "prpl-yahoo", /**< id */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3261 "Yahoo", /**< name */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3262 VERSION, /**< version */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3263 /** summary */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3264 N_("Yahoo Protocol Plugin"), |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3265 /** description */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3266 N_("Yahoo Protocol Plugin"), |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3267 NULL, /**< author */ |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
3268 GAIM_WEBSITE, /**< homepage */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3269 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3270 NULL, /**< load */ |
| 6513 | 3271 yahoo_unload_plugin, /**< unload */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3272 NULL, /**< destroy */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3273 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3274 NULL, /**< ui_info */ |
| 8993 | 3275 &prpl_info, /**< extra_info */ |
| 3276 NULL, | |
| 9015 | 3277 yahoo_actions |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3278 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3279 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3280 static void |
|
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
3281 init_plugin(GaimPlugin *plugin) |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3282 { |
|
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5590
diff
changeset
|
3283 GaimAccountOption *option; |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3284 |
| 9164 | 3285 option = gaim_account_option_bool_new(_("Yahoo Japan"), "yahoojp", FALSE); |
| 3286 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 3287 | |
| 7827 | 3288 option = gaim_account_option_string_new(_("Pager host"), "server", YAHOO_PAGER_HOST); |
| 3289 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 3290 | |
| 9164 | 3291 option = gaim_account_option_string_new(_("Japan Pager host"), "serverjp", YAHOOJP_PAGER_HOST); |
| 3292 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 3293 | |
| 7827 | 3294 option = gaim_account_option_int_new(_("Pager port"), "port", YAHOO_PAGER_PORT); |
| 3295 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 7651 | 3296 |
| 3297 option = gaim_account_option_string_new(_("File transfer host"), "xfer_host", YAHOO_XFER_HOST); | |
| 3298 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 3299 | |
| 9164 | 3300 option = gaim_account_option_string_new(_("Japan File transfer host"), "xferjp_host", YAHOOJP_XFER_HOST); |
| 3301 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 3302 | |
| 7651 | 3303 option = gaim_account_option_int_new(_("File transfer port"), "xfer_port", YAHOO_XFER_PORT); |
| 3304 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 3305 | |
| 8113 | 3306 option = gaim_account_option_string_new(_("Chat Room List Url"), "room_list", YAHOO_ROOMLIST_URL); |
| 3307 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 3308 | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3309 my_protocol = plugin; |
| 6513 | 3310 |
| 3311 yahoo_init_colorht(); | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3312 } |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
3313 |
|
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
3314 GAIM_INIT_PLUGIN(yahoo, init_plugin, info); |
