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