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