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