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