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