[b7d3cc34] | 1 | /* |
---|
| 2 | * libyahoo2: libyahoo2.c |
---|
| 3 | * |
---|
| 4 | * Some code copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net> |
---|
[c36f73b] | 5 | * YMSG16 code copyright (C) 2009, |
---|
| 6 | * Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com> |
---|
[b7d3cc34] | 7 | * |
---|
| 8 | * Yahoo Search copyright (C) 2003, Konstantin Klyagin <konst AT konst.org.ua> |
---|
| 9 | * |
---|
| 10 | * Much of this code was taken and adapted from the yahoo module for |
---|
| 11 | * gaim released under the GNU GPL. This code is also released under the |
---|
| 12 | * GNU GPL. |
---|
| 13 | * |
---|
| 14 | * This code is derivitive of Gaim <http://gaim.sourceforge.net> |
---|
| 15 | * copyright (C) 1998-1999, Mark Spencer <markster@marko.net> |
---|
| 16 | * 1998-1999, Adam Fritzler <afritz@marko.net> |
---|
| 17 | * 1998-2002, Rob Flynn <rob@marko.net> |
---|
| 18 | * 2000-2002, Eric Warmenhoven <eric@warmenhoven.org> |
---|
| 19 | * 2001-2002, Brian Macke <macke@strangelove.net> |
---|
| 20 | * 2001, Anand Biligiri S <abiligiri@users.sf.net> |
---|
| 21 | * 2001, Valdis Kletnieks |
---|
| 22 | * 2002, Sean Egan <bj91704@binghamton.edu> |
---|
| 23 | * 2002, Toby Gray <toby.gray@ntlworld.com> |
---|
| 24 | * |
---|
| 25 | * This library also uses code from other libraries, namely: |
---|
| 26 | * Portions from libfaim copyright 1998, 1999 Adam Fritzler |
---|
| 27 | * <afritz@auk.cx> |
---|
| 28 | * Portions of Sylpheed copyright 2000-2002 Hiroyuki Yamamoto |
---|
| 29 | * <hiro-y@kcn.ne.jp> |
---|
| 30 | * |
---|
[c36f73b] | 31 | * YMSG16 authentication code based mostly on write-up at: |
---|
| 32 | * http://www.carbonize.co.uk/ymsg16.html |
---|
[b7d3cc34] | 33 | * |
---|
| 34 | * This program is free software; you can redistribute it and/or modify |
---|
| 35 | * it under the terms of the GNU General Public License as published by |
---|
| 36 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 37 | * (at your option) any later version. |
---|
| 38 | * |
---|
| 39 | * This program is distributed in the hope that it will be useful, |
---|
| 40 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 41 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 42 | * GNU General Public License for more details. |
---|
| 43 | * |
---|
| 44 | * You should have received a copy of the GNU General Public License |
---|
| 45 | * along with this program; if not, write to the Free Software |
---|
[6f10697] | 46 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[b7d3cc34] | 47 | * |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | #include <unistd.h> |
---|
| 51 | #include <errno.h> |
---|
| 52 | #include <stdio.h> |
---|
| 53 | #include <stdarg.h> |
---|
| 54 | |
---|
| 55 | #if STDC_HEADERS |
---|
| 56 | # include <string.h> |
---|
| 57 | #else |
---|
| 58 | # if !HAVE_STRCHR |
---|
| 59 | # define strchr index |
---|
| 60 | # define strrchr rindex |
---|
| 61 | # endif |
---|
| 62 | char *strchr (), *strrchr (); |
---|
| 63 | # if !HAVE_MEMCPY |
---|
| 64 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) |
---|
| 65 | # define memmove(d, s, n) bcopy ((s), (d), (n)) |
---|
| 66 | # endif |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | #include <sys/types.h> |
---|
| 70 | |
---|
| 71 | #ifdef __MINGW32__ |
---|
| 72 | # include <winsock2.h> |
---|
| 73 | #endif |
---|
| 74 | |
---|
| 75 | #include <stdlib.h> |
---|
| 76 | #include <ctype.h> |
---|
| 77 | |
---|
[77bfd07] | 78 | #include "sha1.h" |
---|
[b7d3cc34] | 79 | #include "md5.h" |
---|
| 80 | #include "yahoo2.h" |
---|
| 81 | #include "yahoo_httplib.h" |
---|
| 82 | #include "yahoo_util.h" |
---|
| 83 | |
---|
| 84 | #include "yahoo2_callbacks.h" |
---|
| 85 | #include "yahoo_debug.h" |
---|
| 86 | #if defined(__MINGW32__) && !defined(HAVE_GLIB) |
---|
| 87 | #define snprintf _snprintf |
---|
| 88 | #define vsnprintf _vsnprintf |
---|
| 89 | #endif |
---|
| 90 | |
---|
[7ed3199] | 91 | #include "base64.h" |
---|
[4fefb77] | 92 | #include "http_client.h" |
---|
| 93 | |
---|
[b7d3cc34] | 94 | #ifdef USE_STRUCT_CALLBACKS |
---|
[c36f73b] | 95 | struct yahoo_callbacks *yc = NULL; |
---|
[b7d3cc34] | 96 | |
---|
[c36f73b] | 97 | void yahoo_register_callbacks(struct yahoo_callbacks *tyc) |
---|
[b7d3cc34] | 98 | { |
---|
| 99 | yc = tyc; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | #define YAHOO_CALLBACK(x) yc->x |
---|
| 103 | #else |
---|
| 104 | #define YAHOO_CALLBACK(x) x |
---|
| 105 | #endif |
---|
| 106 | |
---|
[9034ba0] | 107 | static int yahoo_send_data(void *fd, void *data, int len); |
---|
| 108 | static void _yahoo_http_connected(int id, void *fd, int error, void *data); |
---|
| 109 | static void yahoo_connected(void *fd, int error, void *data); |
---|
[cfc8d58] | 110 | |
---|
[c36f73b] | 111 | int yahoo_log_message(char *fmt, ...) |
---|
[b7d3cc34] | 112 | { |
---|
| 113 | char out[1024]; |
---|
| 114 | va_list ap; |
---|
| 115 | va_start(ap, fmt); |
---|
| 116 | vsnprintf(out, sizeof(out), fmt, ap); |
---|
| 117 | va_end(ap); |
---|
[c36f73b] | 118 | return YAHOO_CALLBACK(ext_yahoo_log) ("%s", out); |
---|
[b7d3cc34] | 119 | } |
---|
| 120 | |
---|
| 121 | static enum yahoo_log_level log_level = YAHOO_LOG_NONE; |
---|
| 122 | |
---|
| 123 | enum yahoo_log_level yahoo_get_log_level() |
---|
| 124 | { |
---|
| 125 | return log_level; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | int yahoo_set_log_level(enum yahoo_log_level level) |
---|
| 129 | { |
---|
| 130 | enum yahoo_log_level l = log_level; |
---|
| 131 | log_level = level; |
---|
| 132 | return l; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | /* default values for servers */ |
---|
[9034ba0] | 136 | static char *default_pager_hosts[] = { "scs.msg.yahoo.com", |
---|
| 137 | "scsa.msg.yahoo.com", |
---|
| 138 | "scsb.msg.yahoo.com", |
---|
| 139 | "scsc.msg.yahoo.com", |
---|
| 140 | NULL}; |
---|
| 141 | |
---|
[b7d3cc34] | 142 | static int pager_port = 5050; |
---|
[c36f73b] | 143 | static int fallback_ports[] = { 23, 25, 80, 20, 119, 8001, 8002, 5050, 0 }; |
---|
[9034ba0] | 144 | |
---|
[c36f73b] | 145 | static char filetransfer_host[] = "filetransfer.msg.yahoo.com"; |
---|
| 146 | static int filetransfer_port = 80; |
---|
| 147 | static char webcam_host[] = "webcam.yahoo.com"; |
---|
| 148 | static int webcam_port = 5100; |
---|
| 149 | static char webcam_description[] = ""; |
---|
| 150 | static char local_host[] = ""; |
---|
| 151 | static int conn_type = Y_WCM_DSL; |
---|
[b7d3cc34] | 152 | |
---|
| 153 | static char profile_url[] = "http://profiles.yahoo.com/"; |
---|
| 154 | |
---|
[9034ba0] | 155 | struct connect_callback_data { |
---|
| 156 | struct yahoo_data *yd; |
---|
| 157 | int tag; |
---|
| 158 | int i; |
---|
| 159 | int server_i; |
---|
[b7d3cc34] | 160 | }; |
---|
| 161 | |
---|
| 162 | struct yahoo_pair { |
---|
| 163 | int key; |
---|
| 164 | char *value; |
---|
| 165 | }; |
---|
| 166 | |
---|
| 167 | struct yahoo_packet { |
---|
| 168 | unsigned short int service; |
---|
| 169 | unsigned int status; |
---|
| 170 | unsigned int id; |
---|
| 171 | YList *hash; |
---|
| 172 | }; |
---|
| 173 | |
---|
| 174 | struct yahoo_search_state { |
---|
[c36f73b] | 175 | int lsearch_type; |
---|
| 176 | char *lsearch_text; |
---|
| 177 | int lsearch_gender; |
---|
| 178 | int lsearch_agerange; |
---|
| 179 | int lsearch_photo; |
---|
| 180 | int lsearch_yahoo_only; |
---|
| 181 | int lsearch_nstart; |
---|
| 182 | int lsearch_nfound; |
---|
| 183 | int lsearch_ntotal; |
---|
[b7d3cc34] | 184 | }; |
---|
| 185 | |
---|
| 186 | struct data_queue { |
---|
| 187 | unsigned char *queue; |
---|
| 188 | int len; |
---|
| 189 | }; |
---|
| 190 | |
---|
| 191 | struct yahoo_input_data { |
---|
| 192 | struct yahoo_data *yd; |
---|
| 193 | struct yahoo_webcam *wcm; |
---|
| 194 | struct yahoo_webcam_data *wcd; |
---|
| 195 | struct yahoo_search_state *ys; |
---|
| 196 | |
---|
[9034ba0] | 197 | void *fd; |
---|
[b7d3cc34] | 198 | enum yahoo_connection_type type; |
---|
[9034ba0] | 199 | |
---|
[c36f73b] | 200 | unsigned char *rxqueue; |
---|
| 201 | int rxlen; |
---|
| 202 | int read_tag; |
---|
[b7d3cc34] | 203 | |
---|
| 204 | YList *txqueues; |
---|
[c36f73b] | 205 | int write_tag; |
---|
[b7d3cc34] | 206 | }; |
---|
| 207 | |
---|
| 208 | struct yahoo_server_settings { |
---|
| 209 | char *pager_host; |
---|
[c36f73b] | 210 | int pager_port; |
---|
[b7d3cc34] | 211 | char *filetransfer_host; |
---|
[c36f73b] | 212 | int filetransfer_port; |
---|
[b7d3cc34] | 213 | char *webcam_host; |
---|
[c36f73b] | 214 | int webcam_port; |
---|
[b7d3cc34] | 215 | char *webcam_description; |
---|
| 216 | char *local_host; |
---|
[c36f73b] | 217 | int conn_type; |
---|
[9034ba0] | 218 | char **pager_host_list; |
---|
[b7d3cc34] | 219 | }; |
---|
| 220 | |
---|
[9034ba0] | 221 | static void yahoo_process_ft_connection(struct yahoo_input_data *yid, int over); |
---|
| 222 | |
---|
| 223 | static void yahoo_process_filetransfer(struct yahoo_input_data *yid, |
---|
| 224 | struct yahoo_packet *pkt); |
---|
| 225 | static void yahoo_process_filetransferinfo(struct yahoo_input_data *yid, |
---|
| 226 | struct yahoo_packet *pkt); |
---|
| 227 | static void yahoo_process_filetransferaccept(struct yahoo_input_data *yid, |
---|
| 228 | struct yahoo_packet *pkt); |
---|
| 229 | |
---|
| 230 | static void yahoo_https_auth(struct yahoo_input_data *yid, const char *seed, const char *sn); |
---|
| 231 | |
---|
[c36f73b] | 232 | static void *_yahoo_default_server_settings() |
---|
[b7d3cc34] | 233 | { |
---|
[9034ba0] | 234 | struct yahoo_server_settings *yss = |
---|
| 235 | y_new0(struct yahoo_server_settings, 1); |
---|
| 236 | |
---|
| 237 | /* Give preference to the default host list |
---|
| 238 | * Make sure that only one of the two is set at any time |
---|
| 239 | */ |
---|
| 240 | yss->pager_host = NULL; |
---|
| 241 | yss->pager_host_list = default_pager_hosts; |
---|
[b7d3cc34] | 242 | |
---|
| 243 | yss->pager_port = pager_port; |
---|
| 244 | yss->filetransfer_host = strdup(filetransfer_host); |
---|
| 245 | yss->filetransfer_port = filetransfer_port; |
---|
| 246 | yss->webcam_host = strdup(webcam_host); |
---|
| 247 | yss->webcam_port = webcam_port; |
---|
| 248 | yss->webcam_description = strdup(webcam_description); |
---|
| 249 | yss->local_host = strdup(local_host); |
---|
| 250 | yss->conn_type = conn_type; |
---|
| 251 | |
---|
| 252 | return yss; |
---|
| 253 | } |
---|
| 254 | |
---|
[c36f73b] | 255 | static void *_yahoo_assign_server_settings(va_list ap) |
---|
[b7d3cc34] | 256 | { |
---|
| 257 | struct yahoo_server_settings *yss = _yahoo_default_server_settings(); |
---|
| 258 | char *key; |
---|
| 259 | char *svalue; |
---|
[c36f73b] | 260 | int nvalue; |
---|
[9034ba0] | 261 | char **pvalue; |
---|
[b7d3cc34] | 262 | |
---|
[c36f73b] | 263 | while (1) { |
---|
[b7d3cc34] | 264 | key = va_arg(ap, char *); |
---|
[c36f73b] | 265 | if (key == NULL) |
---|
[b7d3cc34] | 266 | break; |
---|
| 267 | |
---|
[c36f73b] | 268 | if (!strcmp(key, "pager_host")) { |
---|
[b7d3cc34] | 269 | svalue = va_arg(ap, char *); |
---|
| 270 | free(yss->pager_host); |
---|
| 271 | yss->pager_host = strdup(svalue); |
---|
[9034ba0] | 272 | yss->pager_host_list = NULL; |
---|
| 273 | } else if (!strcmp(key, "pager_host_list")) { |
---|
| 274 | pvalue = va_arg(ap, char **); |
---|
| 275 | yss->pager_host_list = pvalue; |
---|
| 276 | free(yss->pager_host); |
---|
| 277 | yss->pager_host = NULL; |
---|
[c36f73b] | 278 | } else if (!strcmp(key, "pager_port")) { |
---|
[b7d3cc34] | 279 | nvalue = va_arg(ap, int); |
---|
| 280 | yss->pager_port = nvalue; |
---|
[c36f73b] | 281 | } else if (!strcmp(key, "filetransfer_host")) { |
---|
[b7d3cc34] | 282 | svalue = va_arg(ap, char *); |
---|
| 283 | free(yss->filetransfer_host); |
---|
| 284 | yss->filetransfer_host = strdup(svalue); |
---|
[c36f73b] | 285 | } else if (!strcmp(key, "filetransfer_port")) { |
---|
[b7d3cc34] | 286 | nvalue = va_arg(ap, int); |
---|
| 287 | yss->filetransfer_port = nvalue; |
---|
[c36f73b] | 288 | } else if (!strcmp(key, "webcam_host")) { |
---|
[b7d3cc34] | 289 | svalue = va_arg(ap, char *); |
---|
| 290 | free(yss->webcam_host); |
---|
| 291 | yss->webcam_host = strdup(svalue); |
---|
[c36f73b] | 292 | } else if (!strcmp(key, "webcam_port")) { |
---|
[b7d3cc34] | 293 | nvalue = va_arg(ap, int); |
---|
| 294 | yss->webcam_port = nvalue; |
---|
[c36f73b] | 295 | } else if (!strcmp(key, "webcam_description")) { |
---|
[b7d3cc34] | 296 | svalue = va_arg(ap, char *); |
---|
| 297 | free(yss->webcam_description); |
---|
| 298 | yss->webcam_description = strdup(svalue); |
---|
[c36f73b] | 299 | } else if (!strcmp(key, "local_host")) { |
---|
[b7d3cc34] | 300 | svalue = va_arg(ap, char *); |
---|
| 301 | free(yss->local_host); |
---|
| 302 | yss->local_host = strdup(svalue); |
---|
[c36f73b] | 303 | } else if (!strcmp(key, "conn_type")) { |
---|
[b7d3cc34] | 304 | nvalue = va_arg(ap, int); |
---|
| 305 | yss->conn_type = nvalue; |
---|
| 306 | } else { |
---|
| 307 | WARNING(("Unknown key passed to yahoo_init, " |
---|
[c36f73b] | 308 | "perhaps you didn't terminate the list " |
---|
| 309 | "with NULL")); |
---|
[b7d3cc34] | 310 | } |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | return yss; |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | static void yahoo_free_server_settings(struct yahoo_server_settings *yss) |
---|
| 317 | { |
---|
[c36f73b] | 318 | if (!yss) |
---|
[b7d3cc34] | 319 | return; |
---|
| 320 | |
---|
| 321 | free(yss->pager_host); |
---|
| 322 | free(yss->filetransfer_host); |
---|
| 323 | free(yss->webcam_host); |
---|
| 324 | free(yss->webcam_description); |
---|
| 325 | free(yss->local_host); |
---|
| 326 | |
---|
| 327 | free(yss); |
---|
| 328 | } |
---|
| 329 | |
---|
[c36f73b] | 330 | static YList *conns = NULL; |
---|
| 331 | static YList *inputs = NULL; |
---|
| 332 | static int last_id = 0; |
---|
[b7d3cc34] | 333 | |
---|
| 334 | static void add_to_list(struct yahoo_data *yd) |
---|
| 335 | { |
---|
| 336 | conns = y_list_prepend(conns, yd); |
---|
| 337 | } |
---|
[9034ba0] | 338 | |
---|
[c36f73b] | 339 | static struct yahoo_data *find_conn_by_id(int id) |
---|
[b7d3cc34] | 340 | { |
---|
| 341 | YList *l; |
---|
[c36f73b] | 342 | for (l = conns; l; l = y_list_next(l)) { |
---|
[b7d3cc34] | 343 | struct yahoo_data *yd = l->data; |
---|
[c36f73b] | 344 | if (yd->client_id == id) |
---|
[b7d3cc34] | 345 | return yd; |
---|
| 346 | } |
---|
| 347 | return NULL; |
---|
| 348 | } |
---|
[9034ba0] | 349 | |
---|
[b7d3cc34] | 350 | static void del_from_list(struct yahoo_data *yd) |
---|
| 351 | { |
---|
| 352 | conns = y_list_remove(conns, yd); |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | /* call repeatedly to get the next one */ |
---|
[9034ba0] | 356 | /* |
---|
| 357 | static struct yahoo_input_data * find_input_by_id(int id) |
---|
[b7d3cc34] | 358 | { |
---|
| 359 | YList *l; |
---|
| 360 | for(l = inputs; l; l = y_list_next(l)) { |
---|
| 361 | struct yahoo_input_data *yid = l->data; |
---|
| 362 | if(yid->yd->client_id == id) |
---|
| 363 | return yid; |
---|
| 364 | } |
---|
| 365 | return NULL; |
---|
| 366 | } |
---|
[9034ba0] | 367 | */ |
---|
[b7d3cc34] | 368 | |
---|
[509cf60] | 369 | #if 0 |
---|
[9034ba0] | 370 | static struct yahoo_input_data *find_input_by_id_and_webcam_user(int id, |
---|
| 371 | const char *who) |
---|
[b7d3cc34] | 372 | { |
---|
| 373 | YList *l; |
---|
| 374 | LOG(("find_input_by_id_and_webcam_user")); |
---|
[c36f73b] | 375 | for (l = inputs; l; l = y_list_next(l)) { |
---|
[b7d3cc34] | 376 | struct yahoo_input_data *yid = l->data; |
---|
[9034ba0] | 377 | if (yid->type == YAHOO_CONNECTION_WEBCAM |
---|
| 378 | && yid->yd->client_id == id && yid->wcm && ((who |
---|
| 379 | && yid->wcm->user |
---|
| 380 | && !strcmp(who, yid->wcm->user)) |
---|
| 381 | || !(yid->wcm->user && !who))) |
---|
[b7d3cc34] | 382 | return yid; |
---|
| 383 | } |
---|
| 384 | return NULL; |
---|
| 385 | } |
---|
[509cf60] | 386 | #endif |
---|
[b7d3cc34] | 387 | |
---|
[9034ba0] | 388 | static struct yahoo_input_data *find_input_by_id_and_type(int id, |
---|
| 389 | enum yahoo_connection_type type) |
---|
[b7d3cc34] | 390 | { |
---|
| 391 | YList *l; |
---|
| 392 | LOG(("find_input_by_id_and_type")); |
---|
[c36f73b] | 393 | for (l = inputs; l; l = y_list_next(l)) { |
---|
[b7d3cc34] | 394 | struct yahoo_input_data *yid = l->data; |
---|
[c36f73b] | 395 | if (yid->type == type && yid->yd->client_id == id) |
---|
[b7d3cc34] | 396 | return yid; |
---|
| 397 | } |
---|
| 398 | return NULL; |
---|
| 399 | } |
---|
| 400 | |
---|
[9034ba0] | 401 | static struct yahoo_input_data *find_input_by_id_and_fd(int id, void *fd) |
---|
[b7d3cc34] | 402 | { |
---|
| 403 | YList *l; |
---|
| 404 | LOG(("find_input_by_id_and_fd")); |
---|
[c36f73b] | 405 | for (l = inputs; l; l = y_list_next(l)) { |
---|
[b7d3cc34] | 406 | struct yahoo_input_data *yid = l->data; |
---|
[c36f73b] | 407 | if (yid->fd == fd && yid->yd->client_id == id) |
---|
[b7d3cc34] | 408 | return yid; |
---|
| 409 | } |
---|
| 410 | return NULL; |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | static int count_inputs_with_id(int id) |
---|
| 414 | { |
---|
[c36f73b] | 415 | int c = 0; |
---|
[b7d3cc34] | 416 | YList *l; |
---|
| 417 | LOG(("counting %d", id)); |
---|
[c36f73b] | 418 | for (l = inputs; l; l = y_list_next(l)) { |
---|
[b7d3cc34] | 419 | struct yahoo_input_data *yid = l->data; |
---|
[c36f73b] | 420 | if (yid->yd->client_id == id) |
---|
[b7d3cc34] | 421 | c++; |
---|
| 422 | } |
---|
| 423 | LOG(("%d", c)); |
---|
| 424 | return c; |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | /* Free a buddy list */ |
---|
[c36f73b] | 428 | static void yahoo_free_buddies(YList *list) |
---|
[b7d3cc34] | 429 | { |
---|
| 430 | YList *l; |
---|
| 431 | |
---|
[c36f73b] | 432 | for (l = list; l; l = l->next) { |
---|
[b7d3cc34] | 433 | struct yahoo_buddy *bud = l->data; |
---|
[c36f73b] | 434 | if (!bud) |
---|
[b7d3cc34] | 435 | continue; |
---|
| 436 | |
---|
| 437 | FREE(bud->group); |
---|
| 438 | FREE(bud->id); |
---|
| 439 | FREE(bud->real_name); |
---|
[c36f73b] | 440 | if (bud->yab_entry) { |
---|
[b7d3cc34] | 441 | FREE(bud->yab_entry->fname); |
---|
| 442 | FREE(bud->yab_entry->lname); |
---|
| 443 | FREE(bud->yab_entry->nname); |
---|
| 444 | FREE(bud->yab_entry->id); |
---|
| 445 | FREE(bud->yab_entry->email); |
---|
| 446 | FREE(bud->yab_entry->hphone); |
---|
| 447 | FREE(bud->yab_entry->wphone); |
---|
| 448 | FREE(bud->yab_entry->mphone); |
---|
| 449 | FREE(bud->yab_entry); |
---|
| 450 | } |
---|
| 451 | FREE(bud); |
---|
| 452 | l->data = bud = NULL; |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | y_list_free(list); |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | /* Free an identities list */ |
---|
[c36f73b] | 459 | static void yahoo_free_identities(YList *list) |
---|
[b7d3cc34] | 460 | { |
---|
| 461 | while (list) { |
---|
| 462 | YList *n = list; |
---|
| 463 | FREE(list->data); |
---|
| 464 | list = y_list_remove_link(list, list); |
---|
| 465 | y_list_free_1(n); |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | /* Free webcam data */ |
---|
| 470 | static void yahoo_free_webcam(struct yahoo_webcam *wcm) |
---|
| 471 | { |
---|
| 472 | if (wcm) { |
---|
| 473 | FREE(wcm->user); |
---|
| 474 | FREE(wcm->server); |
---|
| 475 | FREE(wcm->key); |
---|
| 476 | FREE(wcm->description); |
---|
| 477 | FREE(wcm->my_ip); |
---|
| 478 | } |
---|
| 479 | FREE(wcm); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | static void yahoo_free_data(struct yahoo_data *yd) |
---|
| 483 | { |
---|
| 484 | FREE(yd->user); |
---|
| 485 | FREE(yd->password); |
---|
| 486 | FREE(yd->cookie_y); |
---|
| 487 | FREE(yd->cookie_t); |
---|
[9034ba0] | 488 | FREE(yd->cookie_b); |
---|
[b7d3cc34] | 489 | FREE(yd->cookie_c); |
---|
| 490 | FREE(yd->login_cookie); |
---|
| 491 | FREE(yd->login_id); |
---|
| 492 | |
---|
| 493 | yahoo_free_buddies(yd->buddies); |
---|
| 494 | yahoo_free_buddies(yd->ignore); |
---|
| 495 | yahoo_free_identities(yd->identities); |
---|
| 496 | |
---|
| 497 | yahoo_free_server_settings(yd->server_settings); |
---|
| 498 | |
---|
| 499 | FREE(yd); |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | #define YAHOO_PACKET_HDRLEN (4 + 2 + 2 + 2 + 2 + 4 + 4) |
---|
| 503 | |
---|
[9034ba0] | 504 | static struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, |
---|
| 505 | enum ypacket_status status, int id) |
---|
[b7d3cc34] | 506 | { |
---|
| 507 | struct yahoo_packet *pkt = y_new0(struct yahoo_packet, 1); |
---|
| 508 | |
---|
| 509 | pkt->service = service; |
---|
| 510 | pkt->status = status; |
---|
| 511 | pkt->id = id; |
---|
| 512 | |
---|
| 513 | return pkt; |
---|
| 514 | } |
---|
| 515 | |
---|
[9034ba0] | 516 | static void yahoo_packet_hash(struct yahoo_packet *pkt, int key, |
---|
| 517 | const char *value) |
---|
[b7d3cc34] | 518 | { |
---|
| 519 | struct yahoo_pair *pair = y_new0(struct yahoo_pair, 1); |
---|
| 520 | pair->key = key; |
---|
| 521 | pair->value = strdup(value); |
---|
| 522 | pkt->hash = y_list_append(pkt->hash, pair); |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | static int yahoo_packet_length(struct yahoo_packet *pkt) |
---|
| 526 | { |
---|
| 527 | YList *l; |
---|
| 528 | |
---|
| 529 | int len = 0; |
---|
| 530 | |
---|
| 531 | for (l = pkt->hash; l; l = l->next) { |
---|
| 532 | struct yahoo_pair *pair = l->data; |
---|
| 533 | int tmp = pair->key; |
---|
| 534 | do { |
---|
| 535 | tmp /= 10; |
---|
| 536 | len++; |
---|
| 537 | } while (tmp); |
---|
| 538 | len += 2; |
---|
| 539 | len += strlen(pair->value); |
---|
| 540 | len += 2; |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | return len; |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | #define yahoo_put16(buf, data) ( \ |
---|
| 547 | (*(buf) = (unsigned char)((data)>>8)&0xff), \ |
---|
| 548 | (*((buf)+1) = (unsigned char)(data)&0xff), \ |
---|
| 549 | 2) |
---|
| 550 | #define yahoo_get16(buf) ((((*(buf))&0xff)<<8) + ((*((buf)+1)) & 0xff)) |
---|
| 551 | #define yahoo_put32(buf, data) ( \ |
---|
| 552 | (*((buf)) = (unsigned char)((data)>>24)&0xff), \ |
---|
| 553 | (*((buf)+1) = (unsigned char)((data)>>16)&0xff), \ |
---|
| 554 | (*((buf)+2) = (unsigned char)((data)>>8)&0xff), \ |
---|
| 555 | (*((buf)+3) = (unsigned char)(data)&0xff), \ |
---|
| 556 | 4) |
---|
| 557 | #define yahoo_get32(buf) ((((*(buf) )&0xff)<<24) + \ |
---|
| 558 | (((*((buf)+1))&0xff)<<16) + \ |
---|
| 559 | (((*((buf)+2))&0xff)<< 8) + \ |
---|
| 560 | (((*((buf)+3))&0xff))) |
---|
| 561 | |
---|
[9034ba0] | 562 | static void yahoo_packet_read(struct yahoo_packet *pkt, unsigned char *data, |
---|
| 563 | int len) |
---|
[b7d3cc34] | 564 | { |
---|
| 565 | int pos = 0; |
---|
| 566 | |
---|
| 567 | while (pos + 1 < len) { |
---|
| 568 | char *key, *value = NULL; |
---|
| 569 | int accept; |
---|
| 570 | int x; |
---|
| 571 | |
---|
| 572 | struct yahoo_pair *pair = y_new0(struct yahoo_pair, 1); |
---|
| 573 | |
---|
| 574 | key = malloc(len + 1); |
---|
| 575 | x = 0; |
---|
| 576 | while (pos + 1 < len) { |
---|
| 577 | if (data[pos] == 0xc0 && data[pos + 1] == 0x80) |
---|
| 578 | break; |
---|
| 579 | key[x++] = data[pos++]; |
---|
| 580 | } |
---|
| 581 | key[x] = 0; |
---|
| 582 | pos += 2; |
---|
| 583 | pair->key = strtol(key, NULL, 10); |
---|
| 584 | free(key); |
---|
| 585 | |
---|
| 586 | /* Libyahoo2 developer(s) don't seem to have the time to fix |
---|
| 587 | this problem, so for now try to work around it: |
---|
| 588 | |
---|
| 589 | Sometimes we receive an invalid packet with not any more |
---|
| 590 | data at this point. I don't know how to handle this in a |
---|
| 591 | clean way, but let's hope this is clean enough: */ |
---|
| 592 | |
---|
| 593 | if (pos + 1 < len) { |
---|
| 594 | accept = x; |
---|
| 595 | /* if x is 0 there was no key, so don't accept it */ |
---|
| 596 | if (accept) |
---|
| 597 | value = malloc(len - pos + 1); |
---|
| 598 | x = 0; |
---|
| 599 | while (pos + 1 < len) { |
---|
| 600 | if (data[pos] == 0xc0 && data[pos + 1] == 0x80) |
---|
| 601 | break; |
---|
| 602 | if (accept) |
---|
| 603 | value[x++] = data[pos++]; |
---|
| 604 | } |
---|
| 605 | if (accept) |
---|
| 606 | value[x] = 0; |
---|
| 607 | pos += 2; |
---|
| 608 | } else { |
---|
| 609 | accept = 0; |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | if (accept) { |
---|
| 613 | pair->value = strdup(value); |
---|
| 614 | FREE(value); |
---|
| 615 | pkt->hash = y_list_append(pkt->hash, pair); |
---|
[9034ba0] | 616 | DEBUG_MSG(("Key: %d \tValue: %s", pair->key, |
---|
| 617 | pair->value)); |
---|
[b7d3cc34] | 618 | } else { |
---|
| 619 | FREE(pair); |
---|
| 620 | } |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | static void yahoo_packet_write(struct yahoo_packet *pkt, unsigned char *data) |
---|
| 625 | { |
---|
| 626 | YList *l; |
---|
| 627 | int pos = 0; |
---|
| 628 | |
---|
| 629 | for (l = pkt->hash; l; l = l->next) { |
---|
| 630 | struct yahoo_pair *pair = l->data; |
---|
| 631 | unsigned char buf[100]; |
---|
| 632 | |
---|
| 633 | snprintf((char *)buf, sizeof(buf), "%d", pair->key); |
---|
| 634 | strcpy((char *)data + pos, (char *)buf); |
---|
| 635 | pos += strlen((char *)buf); |
---|
| 636 | data[pos++] = 0xc0; |
---|
| 637 | data[pos++] = 0x80; |
---|
| 638 | |
---|
| 639 | strcpy((char *)data + pos, pair->value); |
---|
| 640 | pos += strlen(pair->value); |
---|
| 641 | data[pos++] = 0xc0; |
---|
| 642 | data[pos++] = 0x80; |
---|
| 643 | } |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | static void yahoo_dump_unhandled(struct yahoo_packet *pkt) |
---|
| 647 | { |
---|
| 648 | YList *l; |
---|
| 649 | |
---|
| 650 | NOTICE(("Service: 0x%02x\tStatus: %d", pkt->service, pkt->status)); |
---|
| 651 | for (l = pkt->hash; l; l = l->next) { |
---|
| 652 | struct yahoo_pair *pair = l->data; |
---|
| 653 | NOTICE(("\t%d => %s", pair->key, pair->value)); |
---|
| 654 | } |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | static void yahoo_packet_dump(unsigned char *data, int len) |
---|
| 658 | { |
---|
[c36f73b] | 659 | if (yahoo_get_log_level() >= YAHOO_LOG_DEBUG) { |
---|
[b7d3cc34] | 660 | int i; |
---|
| 661 | for (i = 0; i < len; i++) { |
---|
| 662 | if ((i % 8 == 0) && i) |
---|
[c36f73b] | 663 | YAHOO_CALLBACK(ext_yahoo_log) (" "); |
---|
[b7d3cc34] | 664 | if ((i % 16 == 0) && i) |
---|
[c36f73b] | 665 | YAHOO_CALLBACK(ext_yahoo_log) ("\n"); |
---|
| 666 | YAHOO_CALLBACK(ext_yahoo_log) ("%02x ", data[i]); |
---|
[b7d3cc34] | 667 | } |
---|
[c36f73b] | 668 | YAHOO_CALLBACK(ext_yahoo_log) ("\n"); |
---|
[b7d3cc34] | 669 | for (i = 0; i < len; i++) { |
---|
| 670 | if ((i % 8 == 0) && i) |
---|
[c36f73b] | 671 | YAHOO_CALLBACK(ext_yahoo_log) (" "); |
---|
[b7d3cc34] | 672 | if ((i % 16 == 0) && i) |
---|
[c36f73b] | 673 | YAHOO_CALLBACK(ext_yahoo_log) ("\n"); |
---|
[b7d3cc34] | 674 | if (isprint(data[i])) |
---|
[c36f73b] | 675 | YAHOO_CALLBACK(ext_yahoo_log) (" %c ", data[i]); |
---|
[b7d3cc34] | 676 | else |
---|
[c36f73b] | 677 | YAHOO_CALLBACK(ext_yahoo_log) (" . "); |
---|
[b7d3cc34] | 678 | } |
---|
[c36f73b] | 679 | YAHOO_CALLBACK(ext_yahoo_log) ("\n"); |
---|
[b7d3cc34] | 680 | } |
---|
| 681 | } |
---|
| 682 | |
---|
[b38d399] | 683 | /* yahoo's variant of base64 */ |
---|
[812a413] | 684 | static void to_y64(unsigned char *out, const unsigned char *in, int inlen) |
---|
[b7d3cc34] | 685 | { |
---|
[b38d399] | 686 | char *encoded = base64_encode(in, inlen); |
---|
| 687 | int i = 0; |
---|
| 688 | |
---|
| 689 | do { |
---|
| 690 | if (encoded[i] == '+') { |
---|
| 691 | out[i] = '.'; |
---|
| 692 | } else if (encoded[i] == '/') { |
---|
| 693 | out[i] = '_'; |
---|
| 694 | } else if (encoded[i] == '=') { |
---|
| 695 | out[i] = '-'; |
---|
| 696 | } else { |
---|
| 697 | out[i] = encoded[i]; |
---|
| 698 | } |
---|
| 699 | } while (encoded[i++]); |
---|
| 700 | |
---|
| 701 | g_free(encoded); |
---|
[b7d3cc34] | 702 | } |
---|
| 703 | |
---|
[c36f73b] | 704 | static void yahoo_add_to_send_queue(struct yahoo_input_data *yid, void *data, |
---|
| 705 | int length) |
---|
[b7d3cc34] | 706 | { |
---|
| 707 | struct data_queue *tx = y_new0(struct data_queue, 1); |
---|
| 708 | tx->queue = y_new0(unsigned char, length); |
---|
| 709 | tx->len = length; |
---|
| 710 | memcpy(tx->queue, data, length); |
---|
| 711 | |
---|
| 712 | yid->txqueues = y_list_append(yid->txqueues, tx); |
---|
| 713 | |
---|
[c36f73b] | 714 | if (!yid->write_tag) |
---|
| 715 | yid->write_tag = |
---|
| 716 | YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd-> |
---|
| 717 | client_id, yid->fd, YAHOO_INPUT_WRITE, yid); |
---|
[b7d3cc34] | 718 | } |
---|
| 719 | |
---|
[c36f73b] | 720 | static void yahoo_send_packet(struct yahoo_input_data *yid, |
---|
| 721 | struct yahoo_packet *pkt, int extra_pad) |
---|
[b7d3cc34] | 722 | { |
---|
| 723 | int pktlen = yahoo_packet_length(pkt); |
---|
| 724 | int len = YAHOO_PACKET_HDRLEN + pktlen; |
---|
| 725 | unsigned char *data; |
---|
| 726 | int pos = 0; |
---|
| 727 | |
---|
| 728 | if (yid->fd < 0) |
---|
| 729 | return; |
---|
| 730 | |
---|
| 731 | data = y_new0(unsigned char, len + 1); |
---|
| 732 | |
---|
[c36f73b] | 733 | memcpy(data + pos, "YMSG", 4); |
---|
| 734 | pos += 4; |
---|
| 735 | pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); /* version [latest 12 0x000c] */ |
---|
| 736 | pos += yahoo_put16(data + pos, 0x0000); /* HIWORD pkt length??? */ |
---|
| 737 | pos += yahoo_put16(data + pos, pktlen + extra_pad); /* LOWORD pkt length? */ |
---|
| 738 | pos += yahoo_put16(data + pos, pkt->service); /* service */ |
---|
| 739 | pos += yahoo_put32(data + pos, pkt->status); /* status [4bytes] */ |
---|
| 740 | pos += yahoo_put32(data + pos, pkt->id); /* session [4bytes] */ |
---|
[b7d3cc34] | 741 | |
---|
| 742 | yahoo_packet_write(pkt, data + pos); |
---|
| 743 | |
---|
| 744 | yahoo_packet_dump(data, len); |
---|
[c36f73b] | 745 | |
---|
| 746 | if (yid->type == YAHOO_CONNECTION_FT) |
---|
[cfc8d58] | 747 | yahoo_send_data(yid->fd, data, len); |
---|
| 748 | else |
---|
[ba16895] | 749 | yahoo_add_to_send_queue(yid, data, len); |
---|
[b7d3cc34] | 750 | FREE(data); |
---|
| 751 | } |
---|
| 752 | |
---|
| 753 | static void yahoo_packet_free(struct yahoo_packet *pkt) |
---|
| 754 | { |
---|
| 755 | while (pkt->hash) { |
---|
| 756 | struct yahoo_pair *pair = pkt->hash->data; |
---|
| 757 | YList *tmp; |
---|
| 758 | FREE(pair->value); |
---|
| 759 | FREE(pair); |
---|
| 760 | tmp = pkt->hash; |
---|
| 761 | pkt->hash = y_list_remove_link(pkt->hash, pkt->hash); |
---|
| 762 | y_list_free_1(tmp); |
---|
| 763 | } |
---|
| 764 | FREE(pkt); |
---|
| 765 | } |
---|
| 766 | |
---|
[9034ba0] | 767 | static int yahoo_send_data(void *fd, void *data, int len) |
---|
[b7d3cc34] | 768 | { |
---|
| 769 | int ret; |
---|
| 770 | int e; |
---|
| 771 | |
---|
[9034ba0] | 772 | if (fd == NULL) |
---|
[b7d3cc34] | 773 | return -1; |
---|
| 774 | |
---|
| 775 | yahoo_packet_dump(data, len); |
---|
| 776 | |
---|
| 777 | do { |
---|
[9034ba0] | 778 | ret = YAHOO_CALLBACK(ext_yahoo_write) (fd, data, len); |
---|
[c36f73b] | 779 | } while (ret == -1 && errno == EINTR); |
---|
| 780 | e = errno; |
---|
[b7d3cc34] | 781 | |
---|
[c36f73b] | 782 | if (ret == -1) { |
---|
[b7d3cc34] | 783 | LOG(("wrote data: ERR %s", strerror(errno))); |
---|
| 784 | } else { |
---|
| 785 | LOG(("wrote data: OK")); |
---|
| 786 | } |
---|
| 787 | |
---|
[c36f73b] | 788 | errno = e; |
---|
[b7d3cc34] | 789 | return ret; |
---|
| 790 | } |
---|
| 791 | |
---|
[c36f73b] | 792 | void yahoo_close(int id) |
---|
[b7d3cc34] | 793 | { |
---|
| 794 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
[c36f73b] | 795 | if (!yd) |
---|
[b7d3cc34] | 796 | return; |
---|
| 797 | |
---|
| 798 | del_from_list(yd); |
---|
| 799 | |
---|
| 800 | yahoo_free_data(yd); |
---|
[c36f73b] | 801 | if (id == last_id) |
---|
[b7d3cc34] | 802 | last_id--; |
---|
| 803 | } |
---|
| 804 | |
---|
[c36f73b] | 805 | static void yahoo_input_close(struct yahoo_input_data *yid) |
---|
[b7d3cc34] | 806 | { |
---|
| 807 | inputs = y_list_remove(inputs, yid); |
---|
| 808 | |
---|
[c36f73b] | 809 | LOG(("yahoo_input_close(read)")); |
---|
| 810 | YAHOO_CALLBACK(ext_yahoo_remove_handler) (yid->yd->client_id, |
---|
| 811 | yid->read_tag); |
---|
| 812 | LOG(("yahoo_input_close(write)")); |
---|
| 813 | YAHOO_CALLBACK(ext_yahoo_remove_handler) (yid->yd->client_id, |
---|
| 814 | yid->write_tag); |
---|
[b7d3cc34] | 815 | yid->read_tag = yid->write_tag = 0; |
---|
[c36f73b] | 816 | if (yid->fd) |
---|
[9034ba0] | 817 | YAHOO_CALLBACK(ext_yahoo_close) (yid->fd); |
---|
[b7d3cc34] | 818 | yid->fd = 0; |
---|
| 819 | FREE(yid->rxqueue); |
---|
[c36f73b] | 820 | if (count_inputs_with_id(yid->yd->client_id) == 0) { |
---|
[b7d3cc34] | 821 | LOG(("closing %d", yid->yd->client_id)); |
---|
| 822 | yahoo_close(yid->yd->client_id); |
---|
| 823 | } |
---|
| 824 | yahoo_free_webcam(yid->wcm); |
---|
[c36f73b] | 825 | if (yid->wcd) |
---|
[b7d3cc34] | 826 | FREE(yid->wcd); |
---|
[c36f73b] | 827 | if (yid->ys) { |
---|
[b7d3cc34] | 828 | FREE(yid->ys->lsearch_text); |
---|
| 829 | FREE(yid->ys); |
---|
| 830 | } |
---|
| 831 | FREE(yid); |
---|
| 832 | } |
---|
| 833 | |
---|
[c36f73b] | 834 | static int is_same_bud(const void *a, const void *b) |
---|
| 835 | { |
---|
[b7d3cc34] | 836 | const struct yahoo_buddy *subject = a; |
---|
| 837 | const struct yahoo_buddy *object = b; |
---|
| 838 | |
---|
| 839 | return strcmp(subject->id, object->id); |
---|
| 840 | } |
---|
| 841 | |
---|
[c36f73b] | 842 | static char *getcookie(char *rawcookie) |
---|
[b7d3cc34] | 843 | { |
---|
[c36f73b] | 844 | char *cookie = NULL; |
---|
| 845 | char *tmpcookie; |
---|
| 846 | char *cookieend; |
---|
[b7d3cc34] | 847 | |
---|
[c36f73b] | 848 | if (strlen(rawcookie) < 2) |
---|
[b7d3cc34] | 849 | return NULL; |
---|
| 850 | |
---|
[c36f73b] | 851 | tmpcookie = strdup(rawcookie + 2); |
---|
[b7d3cc34] | 852 | cookieend = strchr(tmpcookie, ';'); |
---|
| 853 | |
---|
[c36f73b] | 854 | if (cookieend) |
---|
[b7d3cc34] | 855 | *cookieend = '\0'; |
---|
| 856 | |
---|
| 857 | cookie = strdup(tmpcookie); |
---|
| 858 | FREE(tmpcookie); |
---|
| 859 | /* cookieend=NULL; not sure why this was there since the value is not preserved in the stack -dd */ |
---|
| 860 | |
---|
| 861 | return cookie; |
---|
| 862 | } |
---|
| 863 | |
---|
[c36f73b] | 864 | static char *getlcookie(char *cookie) |
---|
[b7d3cc34] | 865 | { |
---|
| 866 | char *tmp; |
---|
| 867 | char *tmpend; |
---|
| 868 | char *login_cookie = NULL; |
---|
| 869 | |
---|
| 870 | tmpend = strstr(cookie, "n="); |
---|
[c36f73b] | 871 | if (tmpend) { |
---|
| 872 | tmp = strdup(tmpend + 2); |
---|
[b7d3cc34] | 873 | tmpend = strchr(tmp, '&'); |
---|
[c36f73b] | 874 | if (tmpend) |
---|
| 875 | *tmpend = '\0'; |
---|
[b7d3cc34] | 876 | login_cookie = strdup(tmp); |
---|
| 877 | FREE(tmp); |
---|
| 878 | } |
---|
| 879 | |
---|
| 880 | return login_cookie; |
---|
| 881 | } |
---|
| 882 | |
---|
[c36f73b] | 883 | static void yahoo_process_notify(struct yahoo_input_data *yid, |
---|
| 884 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 885 | { |
---|
| 886 | struct yahoo_data *yd = yid->yd; |
---|
| 887 | char *msg = NULL; |
---|
| 888 | char *from = NULL; |
---|
[cfc8d58] | 889 | char *to = NULL; |
---|
[b7d3cc34] | 890 | int stat = 0; |
---|
| 891 | int accept = 0; |
---|
| 892 | char *ind = NULL; |
---|
| 893 | YList *l; |
---|
| 894 | for (l = pkt->hash; l; l = l->next) { |
---|
| 895 | struct yahoo_pair *pair = l->data; |
---|
| 896 | if (pair->key == 4) |
---|
| 897 | from = pair->value; |
---|
[cfc8d58] | 898 | if (pair->key == 5) |
---|
| 899 | to = pair->value; |
---|
[b7d3cc34] | 900 | if (pair->key == 49) |
---|
| 901 | msg = pair->value; |
---|
| 902 | if (pair->key == 13) |
---|
| 903 | stat = atoi(pair->value); |
---|
| 904 | if (pair->key == 14) |
---|
| 905 | ind = pair->value; |
---|
| 906 | if (pair->key == 16) { /* status == -1 */ |
---|
| 907 | NOTICE((pair->value)); |
---|
| 908 | return; |
---|
| 909 | } |
---|
| 910 | |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | if (!msg) |
---|
| 914 | return; |
---|
[c36f73b] | 915 | |
---|
| 916 | if (!strncasecmp(msg, "TYPING", strlen("TYPING"))) |
---|
| 917 | YAHOO_CALLBACK(ext_yahoo_typing_notify) (yd->client_id, to, |
---|
| 918 | from, stat); |
---|
| 919 | else if (!strncasecmp(msg, "GAME", strlen("GAME"))) |
---|
| 920 | YAHOO_CALLBACK(ext_yahoo_game_notify) (yd->client_id, to, from, |
---|
[9034ba0] | 921 | stat, ind); |
---|
[c36f73b] | 922 | else if (!strncasecmp(msg, "WEBCAMINVITE", strlen("WEBCAMINVITE"))) { |
---|
[b7d3cc34] | 923 | if (!strcmp(ind, " ")) { |
---|
[c36f73b] | 924 | YAHOO_CALLBACK(ext_yahoo_webcam_invite) (yd->client_id, |
---|
| 925 | to, from); |
---|
[b7d3cc34] | 926 | } else { |
---|
| 927 | accept = atoi(ind); |
---|
| 928 | /* accept the invitation (-1 = deny 1 = accept) */ |
---|
| 929 | if (accept < 0) |
---|
| 930 | accept = 0; |
---|
[c36f73b] | 931 | YAHOO_CALLBACK(ext_yahoo_webcam_invite_reply) (yd-> |
---|
| 932 | client_id, to, from, accept); |
---|
[b7d3cc34] | 933 | } |
---|
[c36f73b] | 934 | } else |
---|
[b7d3cc34] | 935 | LOG(("Got unknown notification: %s", msg)); |
---|
| 936 | } |
---|
| 937 | |
---|
[9034ba0] | 938 | static void yahoo_process_conference(struct yahoo_input_data *yid, |
---|
| 939 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 940 | { |
---|
| 941 | struct yahoo_data *yd = yid->yd; |
---|
| 942 | char *msg = NULL; |
---|
| 943 | char *host = NULL; |
---|
| 944 | char *who = NULL; |
---|
| 945 | char *room = NULL; |
---|
| 946 | char *id = NULL; |
---|
[c36f73b] | 947 | int utf8 = 0; |
---|
[b7d3cc34] | 948 | YList *members = NULL; |
---|
| 949 | YList *l; |
---|
[c36f73b] | 950 | |
---|
[b7d3cc34] | 951 | for (l = pkt->hash; l; l = l->next) { |
---|
| 952 | struct yahoo_pair *pair = l->data; |
---|
| 953 | if (pair->key == 50) |
---|
| 954 | host = pair->value; |
---|
[c36f73b] | 955 | |
---|
| 956 | if (pair->key == 52) { /* invite */ |
---|
[b7d3cc34] | 957 | members = y_list_append(members, strdup(pair->value)); |
---|
| 958 | } |
---|
[c36f73b] | 959 | if (pair->key == 53) /* logon */ |
---|
[b7d3cc34] | 960 | who = pair->value; |
---|
[c36f73b] | 961 | if (pair->key == 54) /* decline */ |
---|
[b7d3cc34] | 962 | who = pair->value; |
---|
[c36f73b] | 963 | if (pair->key == 55) /* unavailable (status == 2) */ |
---|
[b7d3cc34] | 964 | who = pair->value; |
---|
[c36f73b] | 965 | if (pair->key == 56) /* logoff */ |
---|
[b7d3cc34] | 966 | who = pair->value; |
---|
| 967 | |
---|
| 968 | if (pair->key == 57) |
---|
| 969 | room = pair->value; |
---|
| 970 | |
---|
[c36f73b] | 971 | if (pair->key == 58) /* join message */ |
---|
[b7d3cc34] | 972 | msg = pair->value; |
---|
[c36f73b] | 973 | if (pair->key == 14) /* decline/conf message */ |
---|
[b7d3cc34] | 974 | msg = pair->value; |
---|
| 975 | |
---|
[25c4c78] | 976 | if (pair->key == 13) |
---|
| 977 | ; |
---|
[c36f73b] | 978 | if (pair->key == 16) /* error */ |
---|
[b7d3cc34] | 979 | msg = pair->value; |
---|
| 980 | |
---|
[c36f73b] | 981 | if (pair->key == 1) /* my id */ |
---|
[b7d3cc34] | 982 | id = pair->value; |
---|
[c36f73b] | 983 | if (pair->key == 3) /* message sender */ |
---|
[b7d3cc34] | 984 | who = pair->value; |
---|
| 985 | |
---|
| 986 | if (pair->key == 97) |
---|
| 987 | utf8 = atoi(pair->value); |
---|
| 988 | } |
---|
| 989 | |
---|
[c36f73b] | 990 | if (!room) |
---|
[b7d3cc34] | 991 | return; |
---|
| 992 | |
---|
[c36f73b] | 993 | if (host) { |
---|
| 994 | for (l = members; l; l = l->next) { |
---|
| 995 | char *w = l->data; |
---|
| 996 | if (!strcmp(w, host)) |
---|
[b7d3cc34] | 997 | break; |
---|
| 998 | } |
---|
[c36f73b] | 999 | if (!l) |
---|
[b7d3cc34] | 1000 | members = y_list_append(members, strdup(host)); |
---|
| 1001 | } |
---|
| 1002 | /* invite, decline, join, left, message -> status == 1 */ |
---|
| 1003 | |
---|
[c36f73b] | 1004 | switch (pkt->service) { |
---|
[b7d3cc34] | 1005 | case YAHOO_SERVICE_CONFINVITE: |
---|
[c36f73b] | 1006 | if (pkt->status == 2) ; |
---|
| 1007 | else if (members) |
---|
| 1008 | YAHOO_CALLBACK(ext_yahoo_got_conf_invite) (yd-> |
---|
| 1009 | client_id, id, host, room, msg, members); |
---|
| 1010 | else if (msg) |
---|
| 1011 | YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id, msg, 0, |
---|
| 1012 | E_CONFNOTAVAIL); |
---|
[b7d3cc34] | 1013 | break; |
---|
| 1014 | case YAHOO_SERVICE_CONFADDINVITE: |
---|
[9034ba0] | 1015 | if (pkt->status == 1) |
---|
| 1016 | YAHOO_CALLBACK(ext_yahoo_got_conf_invite) (yd-> |
---|
| 1017 | client_id, id, host, room, msg, members); |
---|
[b7d3cc34] | 1018 | break; |
---|
| 1019 | case YAHOO_SERVICE_CONFDECLINE: |
---|
[c36f73b] | 1020 | if (who) |
---|
| 1021 | YAHOO_CALLBACK(ext_yahoo_conf_userdecline) (yd-> |
---|
| 1022 | client_id, id, who, room, msg); |
---|
[b7d3cc34] | 1023 | break; |
---|
| 1024 | case YAHOO_SERVICE_CONFLOGON: |
---|
[c36f73b] | 1025 | if (who) |
---|
| 1026 | YAHOO_CALLBACK(ext_yahoo_conf_userjoin) (yd->client_id, |
---|
| 1027 | id, who, room); |
---|
[b7d3cc34] | 1028 | break; |
---|
| 1029 | case YAHOO_SERVICE_CONFLOGOFF: |
---|
[c36f73b] | 1030 | if (who) |
---|
| 1031 | YAHOO_CALLBACK(ext_yahoo_conf_userleave) (yd->client_id, |
---|
| 1032 | id, who, room); |
---|
[b7d3cc34] | 1033 | break; |
---|
| 1034 | case YAHOO_SERVICE_CONFMSG: |
---|
[c36f73b] | 1035 | if (who) |
---|
| 1036 | YAHOO_CALLBACK(ext_yahoo_conf_message) (yd->client_id, |
---|
| 1037 | id, who, room, msg, utf8); |
---|
[b7d3cc34] | 1038 | break; |
---|
| 1039 | } |
---|
| 1040 | } |
---|
| 1041 | |
---|
[c36f73b] | 1042 | static void yahoo_process_chat(struct yahoo_input_data *yid, |
---|
| 1043 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 1044 | { |
---|
| 1045 | char *msg = NULL; |
---|
[cfc8d58] | 1046 | char *id = NULL; |
---|
[b7d3cc34] | 1047 | char *who = NULL; |
---|
| 1048 | char *room = NULL; |
---|
| 1049 | char *topic = NULL; |
---|
| 1050 | YList *members = NULL; |
---|
| 1051 | struct yahoo_chat_member *currentmember = NULL; |
---|
[c36f73b] | 1052 | int msgtype = 1; |
---|
| 1053 | int utf8 = 0; |
---|
| 1054 | int firstjoin = 0; |
---|
| 1055 | int membercount = 0; |
---|
| 1056 | int chaterr = 0; |
---|
[b7d3cc34] | 1057 | YList *l; |
---|
[9034ba0] | 1058 | |
---|
[b7d3cc34] | 1059 | yahoo_dump_unhandled(pkt); |
---|
| 1060 | for (l = pkt->hash; l; l = l->next) { |
---|
| 1061 | struct yahoo_pair *pair = l->data; |
---|
| 1062 | |
---|
[cfc8d58] | 1063 | if (pair->key == 1) { |
---|
| 1064 | /* My identity */ |
---|
| 1065 | id = pair->value; |
---|
| 1066 | } |
---|
| 1067 | |
---|
[b7d3cc34] | 1068 | if (pair->key == 104) { |
---|
| 1069 | /* Room name */ |
---|
| 1070 | room = pair->value; |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | if (pair->key == 105) { |
---|
| 1074 | /* Room topic */ |
---|
| 1075 | topic = pair->value; |
---|
| 1076 | } |
---|
| 1077 | |
---|
| 1078 | if (pair->key == 108) { |
---|
| 1079 | /* Number of members in this packet */ |
---|
| 1080 | membercount = atoi(pair->value); |
---|
| 1081 | } |
---|
| 1082 | |
---|
| 1083 | if (pair->key == 109) { |
---|
| 1084 | /* message sender */ |
---|
| 1085 | who = pair->value; |
---|
| 1086 | |
---|
| 1087 | if (pkt->service == YAHOO_SERVICE_CHATJOIN) { |
---|
[c36f73b] | 1088 | currentmember = |
---|
| 1089 | y_new0(struct yahoo_chat_member, 1); |
---|
[b7d3cc34] | 1090 | currentmember->id = strdup(pair->value); |
---|
| 1091 | members = y_list_append(members, currentmember); |
---|
| 1092 | } |
---|
| 1093 | } |
---|
| 1094 | |
---|
| 1095 | if (pair->key == 110) { |
---|
| 1096 | /* age */ |
---|
| 1097 | if (pkt->service == YAHOO_SERVICE_CHATJOIN) |
---|
| 1098 | currentmember->age = atoi(pair->value); |
---|
| 1099 | } |
---|
| 1100 | |
---|
| 1101 | if (pair->key == 113) { |
---|
| 1102 | /* attribs */ |
---|
| 1103 | if (pkt->service == YAHOO_SERVICE_CHATJOIN) |
---|
| 1104 | currentmember->attribs = atoi(pair->value); |
---|
| 1105 | } |
---|
| 1106 | |
---|
| 1107 | if (pair->key == 141) { |
---|
| 1108 | /* alias */ |
---|
| 1109 | if (pkt->service == YAHOO_SERVICE_CHATJOIN) |
---|
| 1110 | currentmember->alias = strdup(pair->value); |
---|
| 1111 | } |
---|
| 1112 | |
---|
| 1113 | if (pair->key == 142) { |
---|
| 1114 | /* location */ |
---|
| 1115 | if (pkt->service == YAHOO_SERVICE_CHATJOIN) |
---|
| 1116 | currentmember->location = strdup(pair->value); |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | if (pair->key == 130) { |
---|
| 1120 | /* first join */ |
---|
| 1121 | firstjoin = 1; |
---|
| 1122 | } |
---|
| 1123 | |
---|
| 1124 | if (pair->key == 117) { |
---|
| 1125 | /* message */ |
---|
| 1126 | msg = pair->value; |
---|
| 1127 | } |
---|
| 1128 | |
---|
| 1129 | if (pair->key == 124) { |
---|
| 1130 | /* Message type */ |
---|
| 1131 | msgtype = atoi(pair->value); |
---|
| 1132 | } |
---|
| 1133 | if (pair->key == 114) { |
---|
| 1134 | /* message error not sure what all the pair values mean */ |
---|
| 1135 | /* but -1 means no session in room */ |
---|
[c36f73b] | 1136 | chaterr = atoi(pair->value); |
---|
[b7d3cc34] | 1137 | } |
---|
| 1138 | } |
---|
| 1139 | |
---|
[c36f73b] | 1140 | if (!room) { |
---|
| 1141 | if (pkt->service == YAHOO_SERVICE_CHATLOGOUT) { /* yahoo originated chat logout */ |
---|
| 1142 | YAHOO_CALLBACK(ext_yahoo_chat_yahoologout) (yid->yd-> |
---|
| 1143 | client_id, id); |
---|
| 1144 | return; |
---|
[b7d3cc34] | 1145 | } |
---|
[c36f73b] | 1146 | if (pkt->service == YAHOO_SERVICE_COMMENT && chaterr) { |
---|
| 1147 | YAHOO_CALLBACK(ext_yahoo_chat_yahooerror) (yid->yd-> |
---|
| 1148 | client_id, id); |
---|
[cfc8d58] | 1149 | return; |
---|
[b7d3cc34] | 1150 | } |
---|
| 1151 | |
---|
| 1152 | WARNING(("We didn't get a room name, ignoring packet")); |
---|
| 1153 | return; |
---|
| 1154 | } |
---|
| 1155 | |
---|
[c36f73b] | 1156 | switch (pkt->service) { |
---|
[b7d3cc34] | 1157 | case YAHOO_SERVICE_CHATJOIN: |
---|
[c36f73b] | 1158 | if (y_list_length(members) != membercount) { |
---|
[b7d3cc34] | 1159 | WARNING(("Count of members doesn't match No. of members we got")); |
---|
| 1160 | } |
---|
[c36f73b] | 1161 | if (firstjoin && members) { |
---|
| 1162 | YAHOO_CALLBACK(ext_yahoo_chat_join) (yid->yd->client_id, |
---|
| 1163 | id, room, topic, members, yid->fd); |
---|
| 1164 | } else if (who) { |
---|
| 1165 | if (y_list_length(members) != 1) { |
---|
[b7d3cc34] | 1166 | WARNING(("Got more than 1 member on a normal join")); |
---|
| 1167 | } |
---|
| 1168 | /* this should only ever have one, but just in case */ |
---|
[c36f73b] | 1169 | while (members) { |
---|
[b7d3cc34] | 1170 | YList *n = members->next; |
---|
| 1171 | currentmember = members->data; |
---|
[c36f73b] | 1172 | YAHOO_CALLBACK(ext_yahoo_chat_userjoin) (yid-> |
---|
| 1173 | yd->client_id, id, room, currentmember); |
---|
[b7d3cc34] | 1174 | y_list_free_1(members); |
---|
[c36f73b] | 1175 | members = n; |
---|
[b7d3cc34] | 1176 | } |
---|
| 1177 | } |
---|
| 1178 | break; |
---|
| 1179 | case YAHOO_SERVICE_CHATEXIT: |
---|
[c36f73b] | 1180 | if (who) { |
---|
| 1181 | YAHOO_CALLBACK(ext_yahoo_chat_userleave) (yid->yd-> |
---|
| 1182 | client_id, id, room, who); |
---|
[b7d3cc34] | 1183 | } |
---|
| 1184 | break; |
---|
| 1185 | case YAHOO_SERVICE_COMMENT: |
---|
[c36f73b] | 1186 | if (who) { |
---|
| 1187 | YAHOO_CALLBACK(ext_yahoo_chat_message) (yid->yd-> |
---|
| 1188 | client_id, id, who, room, msg, msgtype, utf8); |
---|
[b7d3cc34] | 1189 | } |
---|
| 1190 | break; |
---|
| 1191 | } |
---|
| 1192 | } |
---|
| 1193 | |
---|
[c36f73b] | 1194 | static void yahoo_process_message(struct yahoo_input_data *yid, |
---|
| 1195 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 1196 | { |
---|
| 1197 | struct yahoo_data *yd = yid->yd; |
---|
| 1198 | YList *l; |
---|
[c36f73b] | 1199 | YList *messages = NULL; |
---|
[b7d3cc34] | 1200 | |
---|
| 1201 | struct m { |
---|
[c36f73b] | 1202 | int i_31; |
---|
| 1203 | int i_32; |
---|
[b7d3cc34] | 1204 | char *to; |
---|
| 1205 | char *from; |
---|
| 1206 | long tm; |
---|
| 1207 | char *msg; |
---|
[c36f73b] | 1208 | int utf8; |
---|
[9034ba0] | 1209 | char *gunk; |
---|
[b7d3cc34] | 1210 | } *message = y_new0(struct m, 1); |
---|
| 1211 | |
---|
| 1212 | for (l = pkt->hash; l; l = l->next) { |
---|
| 1213 | struct yahoo_pair *pair = l->data; |
---|
[c36f73b] | 1214 | if (pair->key == 1 || pair->key == 4) { |
---|
| 1215 | if (!message->from) |
---|
[b7d3cc34] | 1216 | message->from = pair->value; |
---|
[c36f73b] | 1217 | } else if (pair->key == 5) |
---|
[b7d3cc34] | 1218 | message->to = pair->value; |
---|
| 1219 | else if (pair->key == 15) |
---|
| 1220 | message->tm = strtol(pair->value, NULL, 10); |
---|
| 1221 | else if (pair->key == 97) |
---|
| 1222 | message->utf8 = atoi(pair->value); |
---|
[9034ba0] | 1223 | /* This comes when the official client sends us a message */ |
---|
| 1224 | else if (pair->key == 429) |
---|
| 1225 | message->gunk = pair->value; |
---|
| 1226 | /* user message *//* sys message */ |
---|
[b7d3cc34] | 1227 | else if (pair->key == 14 || pair->key == 16) |
---|
| 1228 | message->msg = pair->value; |
---|
| 1229 | else if (pair->key == 31) { |
---|
[c36f73b] | 1230 | if (message->i_31) { |
---|
[b7d3cc34] | 1231 | messages = y_list_append(messages, message); |
---|
| 1232 | message = y_new0(struct m, 1); |
---|
| 1233 | } |
---|
| 1234 | message->i_31 = atoi(pair->value); |
---|
[c36f73b] | 1235 | } else if (pair->key == 32) |
---|
[b7d3cc34] | 1236 | message->i_32 = atoi(pair->value); |
---|
| 1237 | else |
---|
[c36f73b] | 1238 | LOG(("yahoo_process_message: status: %d, key: %d, value: %s", pkt->status, pair->key, pair->value)); |
---|
[b7d3cc34] | 1239 | } |
---|
| 1240 | |
---|
| 1241 | messages = y_list_append(messages, message); |
---|
| 1242 | |
---|
[c36f73b] | 1243 | for (l = messages; l; l = l->next) { |
---|
[b7d3cc34] | 1244 | message = l->data; |
---|
| 1245 | if (pkt->service == YAHOO_SERVICE_SYSMESSAGE) { |
---|
[9034ba0] | 1246 | YAHOO_CALLBACK(ext_yahoo_system_message) (yd->client_id, |
---|
| 1247 | message->to, message->from, message->msg); |
---|
[b7d3cc34] | 1248 | } else if (pkt->status <= 2 || pkt->status == 5) { |
---|
[9034ba0] | 1249 | /* Confirm message receipt if we got the gunk */ |
---|
| 1250 | if(message->gunk) { |
---|
| 1251 | struct yahoo_packet *outpkt; |
---|
| 1252 | |
---|
| 1253 | outpkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE_CONFIRM, |
---|
| 1254 | YPACKET_STATUS_DEFAULT, 0); |
---|
| 1255 | yahoo_packet_hash(outpkt, 1, yd->user); |
---|
| 1256 | yahoo_packet_hash(outpkt, 5, message->from); |
---|
| 1257 | yahoo_packet_hash(outpkt, 302, "430"); |
---|
| 1258 | yahoo_packet_hash(outpkt, 430, message->gunk); |
---|
| 1259 | yahoo_packet_hash(outpkt, 303, "430"); |
---|
| 1260 | yahoo_packet_hash(outpkt, 450, "0"); |
---|
| 1261 | yahoo_send_packet(yid, outpkt, 0); |
---|
| 1262 | |
---|
| 1263 | yahoo_packet_free(outpkt); |
---|
| 1264 | } |
---|
| 1265 | |
---|
| 1266 | if (!strcmp(message->msg, "<ding>")) |
---|
| 1267 | YAHOO_CALLBACK(ext_yahoo_got_buzz) (yd->client_id, |
---|
| 1268 | message->to, message->from, message->tm); |
---|
| 1269 | else |
---|
| 1270 | YAHOO_CALLBACK(ext_yahoo_got_im) (yd->client_id, |
---|
| 1271 | message->to, message->from, message->msg, |
---|
| 1272 | message->tm, pkt->status, message->utf8); |
---|
[b7d3cc34] | 1273 | } else if (pkt->status == 0xffffffff) { |
---|
[9034ba0] | 1274 | YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id, |
---|
| 1275 | message->msg, 0, E_SYSTEM); |
---|
[b7d3cc34] | 1276 | } |
---|
[9034ba0] | 1277 | FREE(message); |
---|
[b7d3cc34] | 1278 | } |
---|
| 1279 | |
---|
| 1280 | y_list_free(messages); |
---|
| 1281 | } |
---|
| 1282 | |
---|
[9034ba0] | 1283 | /* |
---|
| 1284 | * Here's what multi-level packets look like. Data in brackets is the value. |
---|
| 1285 | * |
---|
| 1286 | * 3 level: |
---|
| 1287 | * ======= |
---|
| 1288 | * |
---|
| 1289 | * 302 (318) - Beginning level 1 |
---|
| 1290 | * 300 (318) - Begin level 2 |
---|
| 1291 | * 302 (319) - End level 2 header |
---|
| 1292 | * 300 (319) - Begin level 3 |
---|
| 1293 | * 301 (319) - End level 3 |
---|
| 1294 | * 303 (319) - End level 2 |
---|
| 1295 | * 303 (318) - End level 1 |
---|
| 1296 | * |
---|
| 1297 | * 2 level: |
---|
| 1298 | * ======= |
---|
| 1299 | * |
---|
| 1300 | * 302 (315) - Beginning level 1 |
---|
| 1301 | * 300 (315) - Begin level 2 |
---|
| 1302 | * 301 (315) - End level 2 |
---|
| 1303 | * 303 (315) - End level 1 |
---|
| 1304 | * |
---|
| 1305 | */ |
---|
[547c94c] | 1306 | static void yahoo_process_status(struct yahoo_input_data *yid, |
---|
| 1307 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 1308 | { |
---|
| 1309 | YList *l; |
---|
| 1310 | struct yahoo_data *yd = yid->yd; |
---|
[cfc8d58] | 1311 | |
---|
[7053379] | 1312 | struct yahoo_process_status_entry *u; |
---|
[cfc8d58] | 1313 | |
---|
| 1314 | YList *users = 0; |
---|
[547c94c] | 1315 | |
---|
[cfc8d58] | 1316 | if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) { |
---|
[547c94c] | 1317 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, |
---|
| 1318 | YAHOO_LOGIN_DUPL, NULL); |
---|
[b7d3cc34] | 1319 | return; |
---|
| 1320 | } |
---|
| 1321 | |
---|
[c36f73b] | 1322 | /* |
---|
| 1323 | * Status updates may be spread accross multiple packets and not |
---|
| 1324 | * even on buddy boundaries, so keeping some state is important. |
---|
| 1325 | * So, continue where we left off, and only add a user entry to |
---|
| 1326 | * the list once it's complete (301-315 End buddy). |
---|
| 1327 | */ |
---|
[7053379] | 1328 | u = yd->half_user; |
---|
[547c94c] | 1329 | |
---|
[b7d3cc34] | 1330 | for (l = pkt->hash; l; l = l->next) { |
---|
| 1331 | struct yahoo_pair *pair = l->data; |
---|
| 1332 | |
---|
| 1333 | switch (pair->key) { |
---|
[547c94c] | 1334 | case 300: /* Begin buddy */ |
---|
| 1335 | if (!strcmp(pair->value, "315") && !u) { |
---|
[7053379] | 1336 | u = yd->half_user = y_new0(struct yahoo_process_status_entry, 1); |
---|
[547c94c] | 1337 | } |
---|
| 1338 | break; |
---|
| 1339 | case 301: /* End buddy */ |
---|
| 1340 | if (!strcmp(pair->value, "315") && u) { |
---|
[9fca0657] | 1341 | /* Sometimes user info comes in an odd format with no |
---|
| 1342 | "begin buddy" but *with* an "end buddy". Don't add |
---|
| 1343 | it twice. */ |
---|
| 1344 | if (!y_list_find(users, u)) |
---|
| 1345 | users = y_list_prepend(users, u); |
---|
[7053379] | 1346 | u = yd->half_user = NULL; |
---|
[547c94c] | 1347 | } |
---|
| 1348 | break; |
---|
| 1349 | case 0: /* we won't actually do anything with this */ |
---|
[b7d3cc34] | 1350 | NOTICE(("key %d:%s", pair->key, pair->value)); |
---|
| 1351 | break; |
---|
[547c94c] | 1352 | case 1: /* we don't get the full buddy list here. */ |
---|
[b7d3cc34] | 1353 | if (!yd->logged_in) { |
---|
[547c94c] | 1354 | yd->logged_in = 1; |
---|
| 1355 | if (yd->current_status < 0) |
---|
[b7d3cc34] | 1356 | yd->current_status = yd->initial_status; |
---|
[547c94c] | 1357 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd-> |
---|
| 1358 | client_id, YAHOO_LOGIN_OK, NULL); |
---|
[b7d3cc34] | 1359 | } |
---|
| 1360 | break; |
---|
[547c94c] | 1361 | case 8: /* how many online buddies we have */ |
---|
[b7d3cc34] | 1362 | NOTICE(("key %d:%s", pair->key, pair->value)); |
---|
| 1363 | break; |
---|
[547c94c] | 1364 | case 7: /* the current buddy */ |
---|
| 1365 | if (!u) { |
---|
| 1366 | /* This will only happen in case of a single level message */ |
---|
[7053379] | 1367 | u = y_new0(struct yahoo_process_status_entry, 1); |
---|
[547c94c] | 1368 | users = y_list_prepend(users, u); |
---|
| 1369 | } |
---|
[cfc8d58] | 1370 | u->name = pair->value; |
---|
[b7d3cc34] | 1371 | break; |
---|
[547c94c] | 1372 | case 10: /* state */ |
---|
| 1373 | u->state = strtol(pair->value, NULL, 10); |
---|
[b7d3cc34] | 1374 | break; |
---|
[547c94c] | 1375 | case 19: /* custom status message */ |
---|
| 1376 | u->msg = pair->value; |
---|
[b7d3cc34] | 1377 | break; |
---|
[547c94c] | 1378 | case 47: /* is it an away message or not. Not applicable for YMSG16 anymore */ |
---|
| 1379 | u->away = atoi(pair->value); |
---|
[b7d3cc34] | 1380 | break; |
---|
[547c94c] | 1381 | case 137: /* seconds idle */ |
---|
| 1382 | u->idle = atoi(pair->value); |
---|
[b7d3cc34] | 1383 | break; |
---|
[547c94c] | 1384 | case 11: /* this is the buddy's session id */ |
---|
| 1385 | u->buddy_session = atoi(pair->value); |
---|
[b7d3cc34] | 1386 | break; |
---|
[547c94c] | 1387 | case 17: /* in chat? */ |
---|
| 1388 | u->f17 = atoi(pair->value); |
---|
[b7d3cc34] | 1389 | break; |
---|
[547c94c] | 1390 | case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */ |
---|
| 1391 | u->flags = atoi(pair->value); |
---|
[b7d3cc34] | 1392 | break; |
---|
[547c94c] | 1393 | case 60: /* SMS -> 1 MOBILE USER */ |
---|
[b7d3cc34] | 1394 | /* sometimes going offline makes this 2, but invisible never sends it */ |
---|
[547c94c] | 1395 | u->mobile = atoi(pair->value); |
---|
[cfc8d58] | 1396 | break; |
---|
| 1397 | case 138: |
---|
[547c94c] | 1398 | u->f138 = atoi(pair->value); |
---|
[cfc8d58] | 1399 | break; |
---|
| 1400 | case 184: |
---|
[547c94c] | 1401 | u->f184 = pair->value; |
---|
[cfc8d58] | 1402 | break; |
---|
| 1403 | case 192: |
---|
[547c94c] | 1404 | u->f192 = atoi(pair->value); |
---|
[cfc8d58] | 1405 | break; |
---|
| 1406 | case 10001: |
---|
[547c94c] | 1407 | u->f10001 = atoi(pair->value); |
---|
[cfc8d58] | 1408 | break; |
---|
| 1409 | case 10002: |
---|
[547c94c] | 1410 | u->f10002 = atoi(pair->value); |
---|
[cfc8d58] | 1411 | break; |
---|
| 1412 | case 198: |
---|
[547c94c] | 1413 | u->f198 = atoi(pair->value); |
---|
[cfc8d58] | 1414 | break; |
---|
| 1415 | case 197: |
---|
[547c94c] | 1416 | u->f197 = pair->value; |
---|
[cfc8d58] | 1417 | break; |
---|
| 1418 | case 205: |
---|
[547c94c] | 1419 | u->f205 = pair->value; |
---|
[cfc8d58] | 1420 | break; |
---|
| 1421 | case 213: |
---|
[547c94c] | 1422 | u->f213 = atoi(pair->value); |
---|
[cfc8d58] | 1423 | break; |
---|
[547c94c] | 1424 | case 16: /* Custom error message */ |
---|
| 1425 | YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id, |
---|
| 1426 | pair->value, 0, E_CUSTOM); |
---|
[b7d3cc34] | 1427 | break; |
---|
| 1428 | default: |
---|
[547c94c] | 1429 | WARNING(("unknown status key %d:%s", pair->key, |
---|
| 1430 | pair->value)); |
---|
[b7d3cc34] | 1431 | break; |
---|
| 1432 | } |
---|
| 1433 | } |
---|
[547c94c] | 1434 | |
---|
[cfc8d58] | 1435 | while (users) { |
---|
| 1436 | YList *t = users; |
---|
[7053379] | 1437 | struct yahoo_process_status_entry *u = users->data; |
---|
[cfc8d58] | 1438 | |
---|
| 1439 | if (u->name != NULL) { |
---|
[547c94c] | 1440 | if (pkt->service == |
---|
| 1441 | YAHOO_SERVICE_LOGOFF |
---|
| 1442 | /*|| u->flags == 0 No flags for YMSG16 */ ) { |
---|
| 1443 | YAHOO_CALLBACK(ext_yahoo_status_changed) (yd-> |
---|
| 1444 | client_id, u->name, |
---|
| 1445 | YAHOO_STATUS_OFFLINE, NULL, 1, 0, 0); |
---|
[cfc8d58] | 1446 | } else { |
---|
[ba16895] | 1447 | /* Key 47 always seems to be 1 for YMSG16 */ |
---|
[547c94c] | 1448 | if (!u->state) |
---|
[ba16895] | 1449 | u->away = 0; |
---|
| 1450 | else |
---|
| 1451 | u->away = 1; |
---|
| 1452 | |
---|
[547c94c] | 1453 | YAHOO_CALLBACK(ext_yahoo_status_changed) (yd-> |
---|
| 1454 | client_id, u->name, u->state, u->msg, |
---|
| 1455 | u->away, u->idle, u->mobile); |
---|
[cfc8d58] | 1456 | } |
---|
| 1457 | } |
---|
| 1458 | |
---|
| 1459 | users = y_list_remove_link(users, users); |
---|
| 1460 | y_list_free_1(t); |
---|
| 1461 | FREE(u); |
---|
| 1462 | } |
---|
[b7d3cc34] | 1463 | } |
---|
| 1464 | |
---|
[547c94c] | 1465 | static void yahoo_process_buddy_list(struct yahoo_input_data *yid, |
---|
| 1466 | struct yahoo_packet *pkt) |
---|
[4fefb77] | 1467 | { |
---|
| 1468 | struct yahoo_data *yd = yid->yd; |
---|
| 1469 | YList *l; |
---|
| 1470 | int last_packet = 0; |
---|
| 1471 | char *cur_group = NULL; |
---|
| 1472 | struct yahoo_buddy *newbud = NULL; |
---|
| 1473 | |
---|
| 1474 | /* we could be getting multiple packets here */ |
---|
| 1475 | for (l = pkt->hash; l; l = l->next) { |
---|
| 1476 | struct yahoo_pair *pair = l->data; |
---|
| 1477 | |
---|
[547c94c] | 1478 | switch (pair->key) { |
---|
[4fefb77] | 1479 | case 300: |
---|
| 1480 | case 301: |
---|
| 1481 | case 302: |
---|
[547c94c] | 1482 | break; /* Separators. Our logic does not need them */ |
---|
[4fefb77] | 1483 | case 303: |
---|
[547c94c] | 1484 | if (318 == atoi(pair->value)) |
---|
[4fefb77] | 1485 | last_packet = 1; |
---|
| 1486 | break; |
---|
| 1487 | case 65: |
---|
| 1488 | cur_group = strdup(pair->value); |
---|
| 1489 | break; |
---|
| 1490 | case 7: |
---|
| 1491 | newbud = y_new0(struct yahoo_buddy, 1); |
---|
| 1492 | newbud->id = strdup(pair->value); |
---|
[547c94c] | 1493 | if (cur_group) |
---|
[4fefb77] | 1494 | newbud->group = strdup(cur_group); |
---|
[1be0d26] | 1495 | else if (yd->buddies) { |
---|
[547c94c] | 1496 | struct yahoo_buddy *lastbud = |
---|
| 1497 | (struct yahoo_buddy *)y_list_nth(yd-> |
---|
| 1498 | buddies, |
---|
| 1499 | y_list_length(yd->buddies) - 1)->data; |
---|
| 1500 | newbud->group = strdup(lastbud->group); |
---|
[1be0d26] | 1501 | } else |
---|
| 1502 | newbud->group = strdup("Buddies"); |
---|
[4fefb77] | 1503 | |
---|
| 1504 | yd->buddies = y_list_append(yd->buddies, newbud); |
---|
| 1505 | |
---|
| 1506 | break; |
---|
| 1507 | } |
---|
| 1508 | } |
---|
| 1509 | |
---|
| 1510 | /* we could be getting multiple packets here */ |
---|
[547c94c] | 1511 | if (pkt->hash && !last_packet) |
---|
[4fefb77] | 1512 | return; |
---|
| 1513 | |
---|
[547c94c] | 1514 | YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, yd->buddies); |
---|
[4fefb77] | 1515 | |
---|
[547c94c] | 1516 | /* Logged in */ |
---|
[4fefb77] | 1517 | if (!yd->logged_in) { |
---|
[547c94c] | 1518 | yd->logged_in = 1; |
---|
| 1519 | if (yd->current_status < 0) |
---|
[4fefb77] | 1520 | yd->current_status = yd->initial_status; |
---|
[547c94c] | 1521 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, |
---|
| 1522 | YAHOO_LOGIN_OK, NULL); |
---|
| 1523 | |
---|
| 1524 | /* |
---|
| 1525 | yahoo_set_away(yd->client_id, yd->initial_status, NULL, |
---|
| 1526 | (yd->initial_status == YAHOO_STATUS_AVAILABLE) ? 0 : 1); |
---|
| 1527 | |
---|
| 1528 | yahoo_get_yab(yd->client_id); |
---|
| 1529 | */ |
---|
[4fefb77] | 1530 | } |
---|
[547c94c] | 1531 | |
---|
[4fefb77] | 1532 | } |
---|
| 1533 | |
---|
[547c94c] | 1534 | static void yahoo_process_list(struct yahoo_input_data *yid, |
---|
| 1535 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 1536 | { |
---|
| 1537 | struct yahoo_data *yd = yid->yd; |
---|
| 1538 | YList *l; |
---|
| 1539 | |
---|
[547c94c] | 1540 | /* we could be getting multiple packets here */ |
---|
[b7d3cc34] | 1541 | for (l = pkt->hash; l; l = l->next) { |
---|
| 1542 | struct yahoo_pair *pair = l->data; |
---|
| 1543 | |
---|
[547c94c] | 1544 | switch (pair->key) { |
---|
| 1545 | case 89: /* identities */ |
---|
[b7d3cc34] | 1546 | { |
---|
[547c94c] | 1547 | char **identities = |
---|
| 1548 | y_strsplit(pair->value, ",", -1); |
---|
| 1549 | int i; |
---|
| 1550 | for (i = 0; identities[i]; i++) |
---|
| 1551 | yd->identities = |
---|
| 1552 | y_list_append(yd->identities, |
---|
[b7d3cc34] | 1553 | strdup(identities[i])); |
---|
[547c94c] | 1554 | y_strfreev(identities); |
---|
[b7d3cc34] | 1555 | } |
---|
[547c94c] | 1556 | YAHOO_CALLBACK(ext_yahoo_got_identities) (yd->client_id, |
---|
| 1557 | yd->identities); |
---|
[b7d3cc34] | 1558 | break; |
---|
[547c94c] | 1559 | case 59: /* cookies */ |
---|
| 1560 | if (pair->value[0] == 'Y') { |
---|
[b7d3cc34] | 1561 | FREE(yd->cookie_y); |
---|
| 1562 | FREE(yd->login_cookie); |
---|
| 1563 | |
---|
| 1564 | yd->cookie_y = getcookie(pair->value); |
---|
| 1565 | yd->login_cookie = getlcookie(yd->cookie_y); |
---|
| 1566 | |
---|
[547c94c] | 1567 | } else if (pair->value[0] == 'T') { |
---|
[b7d3cc34] | 1568 | FREE(yd->cookie_t); |
---|
| 1569 | yd->cookie_t = getcookie(pair->value); |
---|
| 1570 | |
---|
[547c94c] | 1571 | } else if (pair->value[0] == 'C') { |
---|
[b7d3cc34] | 1572 | FREE(yd->cookie_c); |
---|
| 1573 | yd->cookie_c = getcookie(pair->value); |
---|
[547c94c] | 1574 | } |
---|
[b7d3cc34] | 1575 | |
---|
| 1576 | break; |
---|
[547c94c] | 1577 | case 3: /* my id */ |
---|
| 1578 | case 90: /* 1 */ |
---|
| 1579 | case 100: /* 0 */ |
---|
| 1580 | case 101: /* NULL */ |
---|
| 1581 | case 102: /* NULL */ |
---|
| 1582 | case 93: /* 86400/1440 */ |
---|
[b7d3cc34] | 1583 | break; |
---|
| 1584 | } |
---|
| 1585 | } |
---|
[547c94c] | 1586 | |
---|
| 1587 | if (yd->cookie_y && yd->cookie_t) /* We don't get cookie_c anymore */ |
---|
| 1588 | YAHOO_CALLBACK(ext_yahoo_got_cookies) (yd->client_id); |
---|
[b7d3cc34] | 1589 | } |
---|
| 1590 | |
---|
[c36f73b] | 1591 | static void yahoo_process_verify(struct yahoo_input_data *yid, |
---|
| 1592 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 1593 | { |
---|
| 1594 | struct yahoo_data *yd = yid->yd; |
---|
| 1595 | |
---|
[c36f73b] | 1596 | if (pkt->status != 0x01) { |
---|
[b7d3cc34] | 1597 | DEBUG_MSG(("expected status: 0x01, got: %d", pkt->status)); |
---|
[c36f73b] | 1598 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, |
---|
| 1599 | YAHOO_LOGIN_LOCK, ""); |
---|
[b7d3cc34] | 1600 | return; |
---|
| 1601 | } |
---|
| 1602 | |
---|
[c36f73b] | 1603 | pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YPACKET_STATUS_DEFAULT, |
---|
| 1604 | yd->session_id); |
---|
[b7d3cc34] | 1605 | |
---|
| 1606 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 1607 | yahoo_send_packet(yid, pkt, 0); |
---|
| 1608 | |
---|
| 1609 | yahoo_packet_free(pkt); |
---|
| 1610 | |
---|
| 1611 | } |
---|
| 1612 | |
---|
[c36f73b] | 1613 | static void yahoo_process_picture_checksum(struct yahoo_input_data *yid, |
---|
| 1614 | struct yahoo_packet *pkt) |
---|
[cfc8d58] | 1615 | { |
---|
| 1616 | struct yahoo_data *yd = yid->yd; |
---|
| 1617 | char *from = NULL; |
---|
| 1618 | char *to = NULL; |
---|
| 1619 | int checksum = 0; |
---|
| 1620 | YList *l; |
---|
| 1621 | |
---|
[c36f73b] | 1622 | for (l = pkt->hash; l; l = l->next) { |
---|
[cfc8d58] | 1623 | struct yahoo_pair *pair = l->data; |
---|
| 1624 | |
---|
[c36f73b] | 1625 | switch (pair->key) { |
---|
| 1626 | case 1: |
---|
| 1627 | case 4: |
---|
| 1628 | from = pair->value; |
---|
| 1629 | case 5: |
---|
| 1630 | to = pair->value; |
---|
| 1631 | break; |
---|
| 1632 | case 212: |
---|
| 1633 | break; |
---|
| 1634 | case 192: |
---|
| 1635 | checksum = atoi(pair->value); |
---|
| 1636 | break; |
---|
[cfc8d58] | 1637 | } |
---|
| 1638 | } |
---|
| 1639 | |
---|
[c36f73b] | 1640 | YAHOO_CALLBACK(ext_yahoo_got_buddyicon_checksum) (yd->client_id, to, |
---|
| 1641 | from, checksum); |
---|
[cfc8d58] | 1642 | } |
---|
| 1643 | |
---|
[c36f73b] | 1644 | static void yahoo_process_picture(struct yahoo_input_data *yid, |
---|
| 1645 | struct yahoo_packet *pkt) |
---|
[cfc8d58] | 1646 | { |
---|
| 1647 | struct yahoo_data *yd = yid->yd; |
---|
| 1648 | char *url = NULL; |
---|
| 1649 | char *from = NULL; |
---|
| 1650 | char *to = NULL; |
---|
| 1651 | int status = 0; |
---|
| 1652 | int checksum = 0; |
---|
| 1653 | YList *l; |
---|
[c36f73b] | 1654 | |
---|
| 1655 | for (l = pkt->hash; l; l = l->next) { |
---|
[cfc8d58] | 1656 | struct yahoo_pair *pair = l->data; |
---|
| 1657 | |
---|
[c36f73b] | 1658 | switch (pair->key) { |
---|
[cfc8d58] | 1659 | case 1: |
---|
[c36f73b] | 1660 | case 4: /* sender */ |
---|
[cfc8d58] | 1661 | from = pair->value; |
---|
| 1662 | break; |
---|
[c36f73b] | 1663 | case 5: /* we */ |
---|
[cfc8d58] | 1664 | to = pair->value; |
---|
| 1665 | break; |
---|
[c36f73b] | 1666 | case 13: /* request / sending */ |
---|
| 1667 | status = atoi(pair->value); |
---|
[cfc8d58] | 1668 | break; |
---|
[c36f73b] | 1669 | case 20: /* url */ |
---|
[cfc8d58] | 1670 | url = pair->value; |
---|
| 1671 | break; |
---|
| 1672 | case 192: /*checksum */ |
---|
[c36f73b] | 1673 | checksum = atoi(pair->value); |
---|
[cfc8d58] | 1674 | break; |
---|
| 1675 | } |
---|
| 1676 | } |
---|
| 1677 | |
---|
[c36f73b] | 1678 | switch (status) { |
---|
| 1679 | case 1: /* this is a request, ignore for now */ |
---|
| 1680 | YAHOO_CALLBACK(ext_yahoo_got_buddyicon_request) (yd->client_id, |
---|
| 1681 | to, from); |
---|
| 1682 | break; |
---|
| 1683 | case 2: /* this is cool - we get a picture :) */ |
---|
| 1684 | YAHOO_CALLBACK(ext_yahoo_got_buddyicon) (yd->client_id, to, |
---|
| 1685 | from, url, checksum); |
---|
| 1686 | break; |
---|
[cfc8d58] | 1687 | } |
---|
| 1688 | } |
---|
| 1689 | |
---|
[c36f73b] | 1690 | static void yahoo_process_picture_upload(struct yahoo_input_data *yid, |
---|
| 1691 | struct yahoo_packet *pkt) |
---|
[cfc8d58] | 1692 | { |
---|
| 1693 | struct yahoo_data *yd = yid->yd; |
---|
| 1694 | YList *l; |
---|
| 1695 | char *url = NULL; |
---|
| 1696 | |
---|
[9034ba0] | 1697 | if (pkt->status != 1) |
---|
[cfc8d58] | 1698 | return; /* something went wrong */ |
---|
[9034ba0] | 1699 | |
---|
| 1700 | for (l = pkt->hash; l; l = l->next) { |
---|
[cfc8d58] | 1701 | struct yahoo_pair *pair = l->data; |
---|
| 1702 | |
---|
[9034ba0] | 1703 | switch (pair->key) { |
---|
| 1704 | case 5: /* we */ |
---|
| 1705 | break; |
---|
| 1706 | case 20: /* url */ |
---|
| 1707 | url = pair->value; |
---|
| 1708 | break; |
---|
| 1709 | case 27: /* local filename */ |
---|
| 1710 | break; |
---|
| 1711 | case 38: /* time */ |
---|
| 1712 | break; |
---|
[cfc8d58] | 1713 | } |
---|
| 1714 | } |
---|
| 1715 | |
---|
[c36f73b] | 1716 | YAHOO_CALLBACK(ext_yahoo_buddyicon_uploaded) (yd->client_id, url); |
---|
[cfc8d58] | 1717 | } |
---|
| 1718 | |
---|
[9034ba0] | 1719 | void yahoo_login(int id, int initial) |
---|
[b7d3cc34] | 1720 | { |
---|
[9034ba0] | 1721 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
| 1722 | struct connect_callback_data *ccd; |
---|
| 1723 | struct yahoo_server_settings *yss; |
---|
| 1724 | int tag; |
---|
[b7d3cc34] | 1725 | |
---|
[9034ba0] | 1726 | char *host; |
---|
[b7d3cc34] | 1727 | |
---|
[9034ba0] | 1728 | struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); |
---|
| 1729 | yid->yd = yd; |
---|
| 1730 | yid->type = YAHOO_CONNECTION_PAGER; |
---|
| 1731 | inputs = y_list_prepend(inputs, yid); |
---|
[b7d3cc34] | 1732 | |
---|
[9034ba0] | 1733 | yd->initial_status = initial; |
---|
| 1734 | yss = yd->server_settings; |
---|
[b7d3cc34] | 1735 | |
---|
[9034ba0] | 1736 | ccd = y_new0(struct connect_callback_data, 1); |
---|
| 1737 | ccd->yd = yd; |
---|
[b7d3cc34] | 1738 | |
---|
[9034ba0] | 1739 | host = yss->pager_host; |
---|
[b7d3cc34] | 1740 | |
---|
[9034ba0] | 1741 | if (!host) |
---|
| 1742 | host = yss->pager_host_list[0]; |
---|
[b7d3cc34] | 1743 | |
---|
[9034ba0] | 1744 | tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id, |
---|
| 1745 | host, yss->pager_port, yahoo_connected, ccd, 0); |
---|
[b7d3cc34] | 1746 | |
---|
[9034ba0] | 1747 | /* |
---|
| 1748 | * if tag <= 0, then callback has already been called |
---|
| 1749 | * so ccd will have been freed |
---|
[b7d3cc34] | 1750 | */ |
---|
[9034ba0] | 1751 | if (tag > 0) |
---|
| 1752 | ccd->tag = tag; |
---|
| 1753 | else if (tag < 0) |
---|
| 1754 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, |
---|
| 1755 | YAHOO_LOGIN_SOCK, NULL); |
---|
| 1756 | } |
---|
[b7d3cc34] | 1757 | |
---|
[9034ba0] | 1758 | struct yahoo_https_auth_data |
---|
| 1759 | { |
---|
| 1760 | struct yahoo_input_data *yid; |
---|
| 1761 | char *token; |
---|
| 1762 | char *chal; |
---|
| 1763 | }; |
---|
[b7d3cc34] | 1764 | |
---|
[9034ba0] | 1765 | static void yahoo_https_auth_token_init(struct yahoo_https_auth_data *had); |
---|
| 1766 | static void yahoo_https_auth_token_finish(struct http_request *req); |
---|
| 1767 | static void yahoo_https_auth_init(struct yahoo_https_auth_data *had); |
---|
| 1768 | static void yahoo_https_auth_finish(struct http_request *req); |
---|
[b7d3cc34] | 1769 | |
---|
[9034ba0] | 1770 | /* Extract a value from a login.yahoo.com response. Assume CRLF-linebreaks |
---|
| 1771 | and FAIL miserably if they're not there... */ |
---|
| 1772 | static char *yahoo_ha_find_key(char *response, char *key) |
---|
| 1773 | { |
---|
| 1774 | char *s, *end; |
---|
| 1775 | int len = strlen(key); |
---|
| 1776 | |
---|
| 1777 | s = response; |
---|
| 1778 | do { |
---|
| 1779 | if (strncmp(s, key, len) == 0 && s[len] == '=') { |
---|
| 1780 | s += len + 1; |
---|
| 1781 | if ((end = strchr(s, '\r'))) |
---|
| 1782 | return g_strndup(s, end - s); |
---|
| 1783 | else |
---|
| 1784 | return g_strdup(s); |
---|
[b7d3cc34] | 1785 | } |
---|
[9034ba0] | 1786 | |
---|
| 1787 | if ((s = strchr(s, '\n'))) |
---|
| 1788 | s ++; |
---|
| 1789 | } while (s && *s); |
---|
| 1790 | |
---|
| 1791 | return NULL; |
---|
| 1792 | } |
---|
[b7d3cc34] | 1793 | |
---|
[9034ba0] | 1794 | static enum yahoo_status yahoo_https_status_parse(int code) |
---|
| 1795 | { |
---|
| 1796 | switch (code) |
---|
| 1797 | { |
---|
[25c4c78] | 1798 | case 1212: return (enum yahoo_status) YAHOO_LOGIN_PASSWD; |
---|
| 1799 | case 1213: return (enum yahoo_status) YAHOO_LOGIN_LOCK; |
---|
| 1800 | case 1235: return (enum yahoo_status) YAHOO_LOGIN_UNAME; |
---|
[9034ba0] | 1801 | default: return (enum yahoo_status) code; |
---|
[b7d3cc34] | 1802 | } |
---|
[9034ba0] | 1803 | } |
---|
[b7d3cc34] | 1804 | |
---|
[9034ba0] | 1805 | static void yahoo_https_auth(struct yahoo_input_data *yid, const char *seed, const char *sn) |
---|
| 1806 | { |
---|
| 1807 | struct yahoo_https_auth_data *had = g_new0(struct yahoo_https_auth_data, 1); |
---|
[b7d3cc34] | 1808 | |
---|
[9034ba0] | 1809 | had->yid = yid; |
---|
| 1810 | had->chal = g_strdup(seed); |
---|
[b7d3cc34] | 1811 | |
---|
[9034ba0] | 1812 | yahoo_https_auth_token_init(had); |
---|
| 1813 | } |
---|
[b7d3cc34] | 1814 | |
---|
[9034ba0] | 1815 | static void yahoo_https_auth_token_init(struct yahoo_https_auth_data *had) |
---|
| 1816 | { |
---|
| 1817 | struct yahoo_input_data *yid = had->yid; |
---|
| 1818 | struct yahoo_data *yd = yid->yd; |
---|
| 1819 | char *login, *passwd, *chal; |
---|
| 1820 | char *url; |
---|
[b7d3cc34] | 1821 | |
---|
[9034ba0] | 1822 | login = g_strndup(yd->user, 3 * strlen(yd->user)); |
---|
| 1823 | http_encode(login); |
---|
| 1824 | passwd = g_strndup(yd->password, 3 * strlen(yd->password)); |
---|
| 1825 | http_encode(passwd); |
---|
| 1826 | chal = g_strndup(had->chal, 3 * strlen(had->chal)); |
---|
| 1827 | http_encode(chal); |
---|
| 1828 | |
---|
| 1829 | url = g_strdup_printf("https://login.yahoo.com/config/pwtoken_get?src=ymsgr&ts=%d&login=%s&passwd=%s&chal=%s", |
---|
| 1830 | (int) time(NULL), login, passwd, chal); |
---|
| 1831 | |
---|
[d7edadf] | 1832 | http_dorequest_url(url, yahoo_https_auth_token_finish, had); |
---|
[9034ba0] | 1833 | |
---|
| 1834 | g_free(url); |
---|
| 1835 | g_free(chal); |
---|
| 1836 | g_free(passwd); |
---|
| 1837 | g_free(login); |
---|
| 1838 | } |
---|
[4fefb77] | 1839 | |
---|
[e71cfbc] | 1840 | static void yahoo_https_auth_token_finish(struct http_request *req) |
---|
| 1841 | { |
---|
| 1842 | struct yahoo_https_auth_data *had = req->data; |
---|
[ccba980] | 1843 | struct yahoo_input_data *yid; |
---|
| 1844 | struct yahoo_data *yd; |
---|
[e71cfbc] | 1845 | int st; |
---|
| 1846 | |
---|
[ccba980] | 1847 | if (y_list_find(inputs, had->yid) == NULL) |
---|
| 1848 | return; |
---|
| 1849 | |
---|
| 1850 | yid = had->yid; |
---|
| 1851 | yd = yid->yd; |
---|
| 1852 | |
---|
[e71cfbc] | 1853 | if (req->status_code != 200) { |
---|
[c36f73b] | 1854 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 2000 + req->status_code, NULL); |
---|
[e71cfbc] | 1855 | goto fail; |
---|
| 1856 | } |
---|
| 1857 | |
---|
| 1858 | if (sscanf(req->reply_body, "%d", &st) != 1 || st != 0) { |
---|
[c36f73b] | 1859 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, yahoo_https_status_parse(st), NULL); |
---|
[e71cfbc] | 1860 | goto fail; |
---|
| 1861 | } |
---|
| 1862 | |
---|
| 1863 | if ((had->token = yahoo_ha_find_key(req->reply_body, "ymsgr")) == NULL) { |
---|
[c36f73b] | 1864 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 3001, NULL); |
---|
[e71cfbc] | 1865 | goto fail; |
---|
| 1866 | } |
---|
| 1867 | |
---|
[daae10f] | 1868 | yahoo_https_auth_init(had); |
---|
| 1869 | return; |
---|
[e71cfbc] | 1870 | |
---|
| 1871 | fail: |
---|
| 1872 | g_free(had->token); |
---|
| 1873 | g_free(had->chal); |
---|
| 1874 | g_free(had); |
---|
| 1875 | } |
---|
[4fefb77] | 1876 | |
---|
[e71cfbc] | 1877 | static void yahoo_https_auth_init(struct yahoo_https_auth_data *had) |
---|
| 1878 | { |
---|
| 1879 | char *url; |
---|
| 1880 | |
---|
| 1881 | url = g_strdup_printf("https://login.yahoo.com/config/pwtoken_login?src=ymsgr&ts=%d&token=%s", |
---|
| 1882 | (int) time(NULL), had->token); |
---|
| 1883 | |
---|
[d7edadf] | 1884 | http_dorequest_url(url, yahoo_https_auth_finish, had); |
---|
[4fefb77] | 1885 | |
---|
| 1886 | g_free(url); |
---|
| 1887 | } |
---|
| 1888 | |
---|
[e71cfbc] | 1889 | static void yahoo_https_auth_finish(struct http_request *req) |
---|
| 1890 | { |
---|
| 1891 | struct yahoo_https_auth_data *had = req->data; |
---|
[ccba980] | 1892 | struct yahoo_input_data *yid; |
---|
| 1893 | struct yahoo_data *yd; |
---|
[e71cfbc] | 1894 | struct yahoo_packet *pack; |
---|
[ccba980] | 1895 | char *crumb = NULL; |
---|
[e71cfbc] | 1896 | int st; |
---|
| 1897 | |
---|
[ccba980] | 1898 | if (y_list_find(inputs, had->yid) == NULL) |
---|
| 1899 | return; |
---|
| 1900 | |
---|
| 1901 | yid = had->yid; |
---|
| 1902 | yd = yid->yd; |
---|
| 1903 | |
---|
[e71cfbc] | 1904 | md5_byte_t result[16]; |
---|
| 1905 | md5_state_t ctx; |
---|
| 1906 | |
---|
| 1907 | unsigned char yhash[32]; |
---|
| 1908 | |
---|
| 1909 | if (req->status_code != 200) { |
---|
[c36f73b] | 1910 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 2000 + req->status_code, NULL); |
---|
[e71cfbc] | 1911 | goto fail; |
---|
| 1912 | } |
---|
| 1913 | |
---|
| 1914 | if (sscanf(req->reply_body, "%d", &st) != 1 || st != 0) { |
---|
[c36f73b] | 1915 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, yahoo_https_status_parse(st), NULL); |
---|
[e71cfbc] | 1916 | goto fail; |
---|
| 1917 | } |
---|
| 1918 | |
---|
| 1919 | if ((yd->cookie_y = yahoo_ha_find_key(req->reply_body, "Y")) == NULL || |
---|
| 1920 | (yd->cookie_t = yahoo_ha_find_key(req->reply_body, "T")) == NULL || |
---|
| 1921 | (crumb = yahoo_ha_find_key(req->reply_body, "crumb")) == NULL) { |
---|
[c36f73b] | 1922 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, 3002, NULL); |
---|
[e71cfbc] | 1923 | goto fail; |
---|
| 1924 | } |
---|
| 1925 | |
---|
| 1926 | md5_init(&ctx); |
---|
| 1927 | md5_append(&ctx, (unsigned char*) crumb, 11); |
---|
| 1928 | md5_append(&ctx, (unsigned char*) had->chal, strlen(had->chal)); |
---|
| 1929 | md5_finish(&ctx, result); |
---|
| 1930 | to_y64(yhash, result, 16); |
---|
| 1931 | |
---|
| 1932 | pack = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yd->initial_status, yd->session_id); |
---|
| 1933 | yahoo_packet_hash(pack, 1, yd->user); |
---|
| 1934 | yahoo_packet_hash(pack, 0, yd->user); |
---|
| 1935 | yahoo_packet_hash(pack, 277, yd->cookie_y); |
---|
| 1936 | yahoo_packet_hash(pack, 278, yd->cookie_t); |
---|
| 1937 | yahoo_packet_hash(pack, 307, (char*) yhash); |
---|
| 1938 | yahoo_packet_hash(pack, 244, "524223"); |
---|
| 1939 | yahoo_packet_hash(pack, 2, yd->user); |
---|
| 1940 | yahoo_packet_hash(pack, 2, "1"); |
---|
| 1941 | yahoo_packet_hash(pack, 98, "us"); |
---|
| 1942 | yahoo_packet_hash(pack, 135, "7.5.0.647"); |
---|
| 1943 | |
---|
| 1944 | yahoo_send_packet(yid, pack, 0); |
---|
| 1945 | |
---|
| 1946 | yahoo_packet_free(pack); |
---|
| 1947 | |
---|
| 1948 | fail: |
---|
[99c8f13] | 1949 | g_free(crumb); |
---|
[e71cfbc] | 1950 | g_free(had->token); |
---|
| 1951 | g_free(had->chal); |
---|
| 1952 | g_free(had); |
---|
| 1953 | } |
---|
| 1954 | |
---|
[9034ba0] | 1955 | static void yahoo_process_auth(struct yahoo_input_data *yid, |
---|
| 1956 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 1957 | { |
---|
| 1958 | char *seed = NULL; |
---|
[9034ba0] | 1959 | char *sn = NULL; |
---|
[b7d3cc34] | 1960 | YList *l = pkt->hash; |
---|
| 1961 | int m = 0; |
---|
[9034ba0] | 1962 | struct yahoo_data *yd = yid->yd; |
---|
[b7d3cc34] | 1963 | |
---|
| 1964 | while (l) { |
---|
| 1965 | struct yahoo_pair *pair = l->data; |
---|
[9034ba0] | 1966 | |
---|
| 1967 | switch (pair->key) { |
---|
| 1968 | case 94: |
---|
[b7d3cc34] | 1969 | seed = pair->value; |
---|
[9034ba0] | 1970 | break; |
---|
| 1971 | case 1: |
---|
[b7d3cc34] | 1972 | sn = pair->value; |
---|
[9034ba0] | 1973 | break; |
---|
| 1974 | case 13: |
---|
[b7d3cc34] | 1975 | m = atoi(pair->value); |
---|
[9034ba0] | 1976 | break; |
---|
| 1977 | } |
---|
[b7d3cc34] | 1978 | l = l->next; |
---|
| 1979 | } |
---|
| 1980 | |
---|
[9034ba0] | 1981 | if (!seed) |
---|
[b7d3cc34] | 1982 | return; |
---|
| 1983 | |
---|
[9034ba0] | 1984 | if (m==2) |
---|
| 1985 | yahoo_https_auth(yid, seed, sn); |
---|
| 1986 | else { |
---|
| 1987 | /* call error */ |
---|
| 1988 | WARNING(("unknown auth type %d", m)); |
---|
| 1989 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, |
---|
| 1990 | YAHOO_LOGIN_UNKNOWN, NULL); |
---|
[b7d3cc34] | 1991 | } |
---|
| 1992 | } |
---|
| 1993 | |
---|
[9034ba0] | 1994 | static void yahoo_process_auth_resp(struct yahoo_input_data *yid, |
---|
| 1995 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 1996 | { |
---|
| 1997 | struct yahoo_data *yd = yid->yd; |
---|
[c36f73b] | 1998 | char *url = NULL; |
---|
[9034ba0] | 1999 | int login_status = -1; |
---|
[b7d3cc34] | 2000 | |
---|
| 2001 | YList *l; |
---|
| 2002 | |
---|
| 2003 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2004 | struct yahoo_pair *pair = l->data; |
---|
| 2005 | if (pair->key == 0) |
---|
[d7edadf] | 2006 | ; /* login_id */ |
---|
[b7d3cc34] | 2007 | else if (pair->key == 1) |
---|
[d7edadf] | 2008 | ; /* handle */ |
---|
[b7d3cc34] | 2009 | else if (pair->key == 20) |
---|
| 2010 | url = pair->value; |
---|
| 2011 | else if (pair->key == 66) |
---|
| 2012 | login_status = atoi(pair->value); |
---|
| 2013 | } |
---|
| 2014 | |
---|
[9034ba0] | 2015 | if (pkt->status == YPACKET_STATUS_DISCONNECTED) { |
---|
| 2016 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, |
---|
| 2017 | login_status, url); |
---|
| 2018 | /* yahoo_logoff(yd->client_id); */ |
---|
[b7d3cc34] | 2019 | } |
---|
| 2020 | } |
---|
| 2021 | |
---|
[c36f73b] | 2022 | static void yahoo_process_mail(struct yahoo_input_data *yid, |
---|
| 2023 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 2024 | { |
---|
| 2025 | struct yahoo_data *yd = yid->yd; |
---|
| 2026 | char *who = NULL; |
---|
| 2027 | char *email = NULL; |
---|
| 2028 | char *subj = NULL; |
---|
| 2029 | int count = 0; |
---|
| 2030 | YList *l; |
---|
| 2031 | |
---|
| 2032 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2033 | struct yahoo_pair *pair = l->data; |
---|
| 2034 | if (pair->key == 9) |
---|
| 2035 | count = strtol(pair->value, NULL, 10); |
---|
| 2036 | else if (pair->key == 43) |
---|
| 2037 | who = pair->value; |
---|
| 2038 | else if (pair->key == 42) |
---|
| 2039 | email = pair->value; |
---|
| 2040 | else if (pair->key == 18) |
---|
| 2041 | subj = pair->value; |
---|
| 2042 | else |
---|
| 2043 | LOG(("key: %d => value: %s", pair->key, pair->value)); |
---|
| 2044 | } |
---|
| 2045 | |
---|
| 2046 | if (who && email && subj) { |
---|
| 2047 | char from[1024]; |
---|
| 2048 | snprintf(from, sizeof(from), "%s (%s)", who, email); |
---|
[c36f73b] | 2049 | YAHOO_CALLBACK(ext_yahoo_mail_notify) (yd->client_id, from, |
---|
| 2050 | subj, count); |
---|
| 2051 | } else if (count > 0) |
---|
| 2052 | YAHOO_CALLBACK(ext_yahoo_mail_notify) (yd->client_id, NULL, |
---|
| 2053 | NULL, count); |
---|
[b7d3cc34] | 2054 | } |
---|
| 2055 | |
---|
[9034ba0] | 2056 | static void yahoo_process_new_contact(struct yahoo_input_data *yid, |
---|
| 2057 | struct yahoo_packet *pkt) |
---|
| 2058 | { |
---|
| 2059 | struct yahoo_data *yd = yid->yd; |
---|
| 2060 | char *me = NULL; |
---|
| 2061 | char *who = NULL; |
---|
| 2062 | char *msg = NULL; |
---|
| 2063 | int online = -1; |
---|
| 2064 | |
---|
| 2065 | YList *l; |
---|
| 2066 | |
---|
| 2067 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2068 | struct yahoo_pair *pair = l->data; |
---|
| 2069 | if (pair->key == 4) |
---|
| 2070 | who = pair->value; |
---|
| 2071 | else if (pair->key == 5) |
---|
| 2072 | me = pair->value; |
---|
| 2073 | else if (pair->key == 14) |
---|
| 2074 | msg = pair->value; |
---|
| 2075 | else if (pair->key == 13) |
---|
| 2076 | online = strtol(pair->value, NULL, 10); |
---|
| 2077 | } |
---|
| 2078 | |
---|
| 2079 | if (who && online < 0) |
---|
| 2080 | YAHOO_CALLBACK(ext_yahoo_contact_added) (yd->client_id, me, who, |
---|
| 2081 | msg); |
---|
| 2082 | else if (online == 2) |
---|
| 2083 | YAHOO_CALLBACK(ext_yahoo_rejected) (yd->client_id, who, msg); |
---|
| 2084 | } |
---|
| 2085 | |
---|
| 2086 | /* UNUSED? */ |
---|
[c36f73b] | 2087 | static void yahoo_process_contact(struct yahoo_input_data *yid, |
---|
| 2088 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 2089 | { |
---|
| 2090 | struct yahoo_data *yd = yid->yd; |
---|
| 2091 | char *id = NULL; |
---|
| 2092 | char *who = NULL; |
---|
| 2093 | char *msg = NULL; |
---|
| 2094 | char *name = NULL; |
---|
| 2095 | int state = YAHOO_STATUS_AVAILABLE; |
---|
| 2096 | int away = 0; |
---|
[cfc8d58] | 2097 | int idle = 0; |
---|
| 2098 | int mobile = 0; |
---|
[b7d3cc34] | 2099 | |
---|
| 2100 | YList *l; |
---|
| 2101 | |
---|
| 2102 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2103 | struct yahoo_pair *pair = l->data; |
---|
| 2104 | if (pair->key == 1) |
---|
| 2105 | id = pair->value; |
---|
| 2106 | else if (pair->key == 3) |
---|
| 2107 | who = pair->value; |
---|
| 2108 | else if (pair->key == 14) |
---|
| 2109 | msg = pair->value; |
---|
| 2110 | else if (pair->key == 7) |
---|
| 2111 | name = pair->value; |
---|
| 2112 | else if (pair->key == 10) |
---|
| 2113 | state = strtol(pair->value, NULL, 10); |
---|
| 2114 | else if (pair->key == 15) |
---|
[d7edadf] | 2115 | ; /* tm */ |
---|
[b7d3cc34] | 2116 | else if (pair->key == 13) |
---|
[d7edadf] | 2117 | ; /* online */ |
---|
[b7d3cc34] | 2118 | else if (pair->key == 47) |
---|
| 2119 | away = strtol(pair->value, NULL, 10); |
---|
[cfc8d58] | 2120 | else if (pair->key == 137) |
---|
| 2121 | idle = strtol(pair->value, NULL, 10); |
---|
| 2122 | else if (pair->key == 60) |
---|
| 2123 | mobile = strtol(pair->value, NULL, 10); |
---|
[c36f73b] | 2124 | |
---|
[b7d3cc34] | 2125 | } |
---|
| 2126 | |
---|
| 2127 | if (id) |
---|
[c36f73b] | 2128 | YAHOO_CALLBACK(ext_yahoo_contact_added) (yd->client_id, id, who, |
---|
| 2129 | msg); |
---|
[b7d3cc34] | 2130 | else if (name) |
---|
[c36f73b] | 2131 | YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->client_id, name, |
---|
| 2132 | state, msg, away, idle, mobile); |
---|
| 2133 | else if (pkt->status == 0x07) |
---|
| 2134 | YAHOO_CALLBACK(ext_yahoo_rejected) (yd->client_id, who, msg); |
---|
[b7d3cc34] | 2135 | } |
---|
| 2136 | |
---|
[c36f73b] | 2137 | static void yahoo_process_buddyadd(struct yahoo_input_data *yid, |
---|
| 2138 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 2139 | { |
---|
| 2140 | struct yahoo_data *yd = yid->yd; |
---|
| 2141 | char *who = NULL; |
---|
| 2142 | char *where = NULL; |
---|
| 2143 | int status = 0; |
---|
| 2144 | |
---|
[c36f73b] | 2145 | struct yahoo_buddy *bud = NULL; |
---|
[b7d3cc34] | 2146 | |
---|
| 2147 | YList *l; |
---|
| 2148 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2149 | struct yahoo_pair *pair = l->data; |
---|
| 2150 | if (pair->key == 1) |
---|
[d7edadf] | 2151 | ; /* Me... don't care */ |
---|
[b7d3cc34] | 2152 | if (pair->key == 7) |
---|
| 2153 | who = pair->value; |
---|
| 2154 | if (pair->key == 65) |
---|
| 2155 | where = pair->value; |
---|
| 2156 | if (pair->key == 66) |
---|
| 2157 | status = strtol(pair->value, NULL, 10); |
---|
| 2158 | } |
---|
| 2159 | |
---|
[c36f73b] | 2160 | if (!who) |
---|
[b7d3cc34] | 2161 | return; |
---|
[c36f73b] | 2162 | if (!where) |
---|
[b7d3cc34] | 2163 | where = "Unknown"; |
---|
| 2164 | |
---|
[9034ba0] | 2165 | bud = y_new0(struct yahoo_buddy, 1); |
---|
| 2166 | bud->id = strdup(who); |
---|
| 2167 | bud->group = strdup(where); |
---|
| 2168 | bud->real_name = NULL; |
---|
[b7d3cc34] | 2169 | |
---|
[9034ba0] | 2170 | yd->buddies = y_list_append(yd->buddies, bud); |
---|
[b7d3cc34] | 2171 | |
---|
[241f9f6] | 2172 | #if 0 |
---|
| 2173 | /* BitlBee: This seems to be wrong in my experience. I think: |
---|
| 2174 | status = 0: Success |
---|
| 2175 | status = 2: Already on list |
---|
| 2176 | status = 3: Doesn't exist |
---|
| 2177 | status = 42: Invalid handle (possibly banned/reserved, I get it for |
---|
| 2178 | handles like joe or jjjjjj) |
---|
| 2179 | Haven't seen others yet. But whenever the add is successful, there |
---|
| 2180 | will be a separate "went online" packet when the auth. request is |
---|
| 2181 | accepted. Couldn't find any test account that doesn't require auth. |
---|
| 2182 | unfortunately (if there is even such a thing?) */ |
---|
| 2183 | |
---|
[9034ba0] | 2184 | /* A non-zero status (i've seen 2) seems to mean the buddy is already |
---|
| 2185 | * added and is online */ |
---|
| 2186 | if (status) { |
---|
| 2187 | LOG(("Setting online see packet for info")); |
---|
| 2188 | yahoo_dump_unhandled(pkt); |
---|
| 2189 | YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->client_id, who, |
---|
| 2190 | YAHOO_STATUS_AVAILABLE, NULL, 0, 0, 0); |
---|
[ba16895] | 2191 | } |
---|
[241f9f6] | 2192 | #endif |
---|
| 2193 | /* BitlBee: Need ACK of added buddy, if it was successful. */ |
---|
| 2194 | if (status == 0) { |
---|
| 2195 | YList *tmp = y_list_append(NULL, bud); |
---|
| 2196 | YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, tmp); |
---|
| 2197 | y_list_free(tmp); |
---|
| 2198 | } |
---|
[ba16895] | 2199 | } |
---|
| 2200 | |
---|
[c36f73b] | 2201 | static void yahoo_process_buddydel(struct yahoo_input_data *yid, |
---|
| 2202 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 2203 | { |
---|
| 2204 | struct yahoo_data *yd = yid->yd; |
---|
| 2205 | char *who = NULL; |
---|
| 2206 | char *where = NULL; |
---|
| 2207 | struct yahoo_buddy *bud; |
---|
| 2208 | |
---|
| 2209 | YList *buddy; |
---|
| 2210 | |
---|
| 2211 | YList *l; |
---|
| 2212 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2213 | struct yahoo_pair *pair = l->data; |
---|
| 2214 | if (pair->key == 1) |
---|
[d7edadf] | 2215 | ; /* Me... don't care */ |
---|
[b7d3cc34] | 2216 | else if (pair->key == 7) |
---|
| 2217 | who = pair->value; |
---|
| 2218 | else if (pair->key == 65) |
---|
| 2219 | where = pair->value; |
---|
| 2220 | else if (pair->key == 66) |
---|
[d7edadf] | 2221 | ; /* unk_66 */ |
---|
[b7d3cc34] | 2222 | else |
---|
[c36f73b] | 2223 | DEBUG_MSG(("unknown key: %d = %s", pair->key, |
---|
| 2224 | pair->value)); |
---|
[b7d3cc34] | 2225 | } |
---|
| 2226 | |
---|
[c36f73b] | 2227 | if (!who || !where) |
---|
[b7d3cc34] | 2228 | return; |
---|
[c36f73b] | 2229 | |
---|
[b7d3cc34] | 2230 | bud = y_new0(struct yahoo_buddy, 1); |
---|
| 2231 | bud->id = strdup(who); |
---|
| 2232 | bud->group = strdup(where); |
---|
| 2233 | |
---|
| 2234 | buddy = y_list_find_custom(yd->buddies, bud, is_same_bud); |
---|
| 2235 | |
---|
| 2236 | FREE(bud->id); |
---|
| 2237 | FREE(bud->group); |
---|
| 2238 | FREE(bud); |
---|
| 2239 | |
---|
[c36f73b] | 2240 | if (buddy) { |
---|
[b7d3cc34] | 2241 | bud = buddy->data; |
---|
| 2242 | yd->buddies = y_list_remove_link(yd->buddies, buddy); |
---|
| 2243 | y_list_free_1(buddy); |
---|
| 2244 | |
---|
| 2245 | FREE(bud->id); |
---|
| 2246 | FREE(bud->group); |
---|
| 2247 | FREE(bud->real_name); |
---|
| 2248 | FREE(bud); |
---|
| 2249 | |
---|
[c36f73b] | 2250 | bud = NULL; |
---|
[b7d3cc34] | 2251 | } |
---|
| 2252 | } |
---|
| 2253 | |
---|
[c36f73b] | 2254 | static void yahoo_process_ignore(struct yahoo_input_data *yid, |
---|
| 2255 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 2256 | { |
---|
| 2257 | YList *l; |
---|
| 2258 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2259 | struct yahoo_pair *pair = l->data; |
---|
| 2260 | if (pair->key == 0) |
---|
[d7edadf] | 2261 | ; /* who */ |
---|
[b7d3cc34] | 2262 | if (pair->key == 1) |
---|
[d7edadf] | 2263 | ; /* Me... don't care */ |
---|
[c36f73b] | 2264 | if (pair->key == 13) /* 1 == ignore, 2 == unignore */ |
---|
[d7edadf] | 2265 | ; |
---|
[c36f73b] | 2266 | if (pair->key == 66) |
---|
[d7edadf] | 2267 | ; /* status */ |
---|
[b7d3cc34] | 2268 | } |
---|
| 2269 | |
---|
| 2270 | /* |
---|
| 2271 | * status |
---|
[c36f73b] | 2272 | * 0 - ok |
---|
| 2273 | * 2 - already in ignore list, could not add |
---|
| 2274 | * 3 - not in ignore list, could not delete |
---|
| 2275 | * 12 - is a buddy, could not add |
---|
[b7d3cc34] | 2276 | */ |
---|
| 2277 | |
---|
| 2278 | /* if(status) |
---|
[9034ba0] | 2279 | YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, who, 0, status); |
---|
[c36f73b] | 2280 | */ |
---|
[b7d3cc34] | 2281 | } |
---|
| 2282 | |
---|
[c36f73b] | 2283 | static void yahoo_process_voicechat(struct yahoo_input_data *yid, |
---|
| 2284 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 2285 | { |
---|
| 2286 | char *who = NULL; |
---|
| 2287 | char *me = NULL; |
---|
| 2288 | char *room = NULL; |
---|
| 2289 | |
---|
| 2290 | YList *l; |
---|
| 2291 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2292 | struct yahoo_pair *pair = l->data; |
---|
| 2293 | if (pair->key == 4) |
---|
| 2294 | who = pair->value; |
---|
| 2295 | if (pair->key == 5) |
---|
| 2296 | me = pair->value; |
---|
| 2297 | if (pair->key == 13) |
---|
[d7edadf] | 2298 | ; /* voice room */ |
---|
[c36f73b] | 2299 | if (pair->key == 57) |
---|
| 2300 | room = pair->value; |
---|
[b7d3cc34] | 2301 | } |
---|
| 2302 | |
---|
[c36f73b] | 2303 | NOTICE(("got voice chat invite from %s in %s to identity %s", who, room, |
---|
| 2304 | me)); |
---|
[b7d3cc34] | 2305 | /* |
---|
| 2306 | * send: s:0 1:me 5:who 57:room 13:1 |
---|
| 2307 | * ???? s:4 5:who 10:99 19:-1615114531 |
---|
| 2308 | * gotr: s:4 5:who 10:99 19:-1615114615 |
---|
| 2309 | * ???? s:1 5:me 4:who 57:room 13:3room |
---|
| 2310 | * got: s:1 5:me 4:who 57:room 13:1room |
---|
| 2311 | * rej: s:0 1:me 5:who 57:room 13:3 |
---|
| 2312 | * rejr: s:4 5:who 10:99 19:-1617114599 |
---|
| 2313 | */ |
---|
| 2314 | } |
---|
| 2315 | |
---|
[c36f73b] | 2316 | static void yahoo_process_ping(struct yahoo_input_data *yid, |
---|
| 2317 | struct yahoo_packet *pkt) |
---|
[cfc8d58] | 2318 | { |
---|
| 2319 | char *errormsg = NULL; |
---|
[c36f73b] | 2320 | |
---|
[cfc8d58] | 2321 | YList *l; |
---|
| 2322 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2323 | struct yahoo_pair *pair = l->data; |
---|
| 2324 | if (pair->key == 16) |
---|
| 2325 | errormsg = pair->value; |
---|
| 2326 | } |
---|
[c36f73b] | 2327 | |
---|
[cfc8d58] | 2328 | NOTICE(("got ping packet")); |
---|
[c36f73b] | 2329 | YAHOO_CALLBACK(ext_yahoo_got_ping) (yid->yd->client_id, errormsg); |
---|
[cfc8d58] | 2330 | } |
---|
| 2331 | |
---|
[9034ba0] | 2332 | static void yahoo_process_buddy_change_group(struct yahoo_input_data *yid, |
---|
| 2333 | struct yahoo_packet *pkt) |
---|
| 2334 | { |
---|
| 2335 | YList *l; |
---|
| 2336 | char *me = NULL; |
---|
| 2337 | char *who = NULL; |
---|
| 2338 | char *old_group = NULL; |
---|
| 2339 | char *new_group = NULL; |
---|
| 2340 | |
---|
| 2341 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2342 | struct yahoo_pair *pair = l->data; |
---|
| 2343 | if (pair->key == 1) |
---|
| 2344 | me = pair->value; |
---|
| 2345 | if (pair->key == 7) |
---|
| 2346 | who = pair->value; |
---|
| 2347 | if (pair->key == 224) |
---|
| 2348 | old_group = pair->value; |
---|
| 2349 | if (pair->key == 264) |
---|
| 2350 | new_group = pair->value; |
---|
| 2351 | } |
---|
| 2352 | |
---|
| 2353 | YAHOO_CALLBACK(ext_yahoo_got_buddy_change_group) (yid->yd->client_id, |
---|
| 2354 | me, who, old_group, new_group); |
---|
| 2355 | } |
---|
| 2356 | |
---|
| 2357 | static void _yahoo_webcam_get_server_connected(void *fd, int error, void *d) |
---|
[b7d3cc34] | 2358 | { |
---|
| 2359 | struct yahoo_input_data *yid = d; |
---|
| 2360 | char *who = yid->wcm->user; |
---|
| 2361 | char *data = NULL; |
---|
| 2362 | char *packet = NULL; |
---|
[c36f73b] | 2363 | unsigned char magic_nr[] = { 0, 1, 0 }; |
---|
[b7d3cc34] | 2364 | unsigned char header_len = 8; |
---|
| 2365 | unsigned int len = 0; |
---|
| 2366 | unsigned int pos = 0; |
---|
| 2367 | |
---|
[9034ba0] | 2368 | if (error || !fd) { |
---|
[b7d3cc34] | 2369 | FREE(who); |
---|
| 2370 | FREE(yid); |
---|
| 2371 | return; |
---|
| 2372 | } |
---|
| 2373 | |
---|
| 2374 | yid->fd = fd; |
---|
| 2375 | inputs = y_list_prepend(inputs, yid); |
---|
[c36f73b] | 2376 | |
---|
[b7d3cc34] | 2377 | /* send initial packet */ |
---|
| 2378 | if (who) |
---|
| 2379 | data = strdup("<RVWCFG>"); |
---|
| 2380 | else |
---|
| 2381 | data = strdup("<RUPCFG>"); |
---|
| 2382 | yahoo_add_to_send_queue(yid, data, strlen(data)); |
---|
| 2383 | FREE(data); |
---|
| 2384 | |
---|
| 2385 | /* send data */ |
---|
[c36f73b] | 2386 | if (who) { |
---|
[b7d3cc34] | 2387 | data = strdup("g="); |
---|
| 2388 | data = y_string_append(data, who); |
---|
| 2389 | data = y_string_append(data, "\r\n"); |
---|
| 2390 | } else { |
---|
| 2391 | data = strdup("f=1\r\n"); |
---|
| 2392 | } |
---|
| 2393 | len = strlen(data); |
---|
| 2394 | packet = y_new0(char, header_len + len); |
---|
| 2395 | packet[pos++] = header_len; |
---|
| 2396 | memcpy(packet + pos, magic_nr, sizeof(magic_nr)); |
---|
| 2397 | pos += sizeof(magic_nr); |
---|
| 2398 | pos += yahoo_put32(packet + pos, len); |
---|
| 2399 | memcpy(packet + pos, data, len); |
---|
| 2400 | pos += len; |
---|
| 2401 | yahoo_add_to_send_queue(yid, packet, pos); |
---|
| 2402 | FREE(packet); |
---|
| 2403 | FREE(data); |
---|
| 2404 | |
---|
[c36f73b] | 2405 | yid->read_tag = |
---|
| 2406 | YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd, |
---|
| 2407 | YAHOO_INPUT_READ, yid); |
---|
[b7d3cc34] | 2408 | } |
---|
| 2409 | |
---|
[c36f73b] | 2410 | static void yahoo_webcam_get_server(struct yahoo_input_data *y, char *who, |
---|
| 2411 | char *key) |
---|
[b7d3cc34] | 2412 | { |
---|
| 2413 | struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); |
---|
| 2414 | struct yahoo_server_settings *yss = y->yd->server_settings; |
---|
| 2415 | |
---|
| 2416 | yid->type = YAHOO_CONNECTION_WEBCAM_MASTER; |
---|
| 2417 | yid->yd = y->yd; |
---|
| 2418 | yid->wcm = y_new0(struct yahoo_webcam, 1); |
---|
[c36f73b] | 2419 | yid->wcm->user = who ? strdup(who) : NULL; |
---|
| 2420 | yid->wcm->direction = who ? YAHOO_WEBCAM_DOWNLOAD : YAHOO_WEBCAM_UPLOAD; |
---|
[b7d3cc34] | 2421 | yid->wcm->key = strdup(key); |
---|
| 2422 | |
---|
[c36f73b] | 2423 | YAHOO_CALLBACK(ext_yahoo_connect_async) (yid->yd->client_id, |
---|
| 2424 | yss->webcam_host, yss->webcam_port, |
---|
[9034ba0] | 2425 | _yahoo_webcam_get_server_connected, yid, 0); |
---|
[b7d3cc34] | 2426 | |
---|
| 2427 | } |
---|
| 2428 | |
---|
[c36f73b] | 2429 | static YList *webcam_queue = NULL; |
---|
| 2430 | static void yahoo_process_webcam_key(struct yahoo_input_data *yid, |
---|
| 2431 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 2432 | { |
---|
| 2433 | char *key = NULL; |
---|
| 2434 | char *who = NULL; |
---|
| 2435 | |
---|
| 2436 | YList *l; |
---|
[c36f73b] | 2437 | yahoo_dump_unhandled(pkt); |
---|
[b7d3cc34] | 2438 | for (l = pkt->hash; l; l = l->next) { |
---|
| 2439 | struct yahoo_pair *pair = l->data; |
---|
| 2440 | if (pair->key == 5) |
---|
[d7edadf] | 2441 | ; /* me */ |
---|
[c36f73b] | 2442 | if (pair->key == 61) |
---|
| 2443 | key = pair->value; |
---|
[b7d3cc34] | 2444 | } |
---|
| 2445 | |
---|
| 2446 | l = webcam_queue; |
---|
[c36f73b] | 2447 | if (!l) |
---|
[b7d3cc34] | 2448 | return; |
---|
| 2449 | who = l->data; |
---|
| 2450 | webcam_queue = y_list_remove_link(webcam_queue, webcam_queue); |
---|
| 2451 | y_list_free_1(l); |
---|
| 2452 | yahoo_webcam_get_server(yid, who, key); |
---|
| 2453 | FREE(who); |
---|
| 2454 | } |
---|
| 2455 | |
---|
[c36f73b] | 2456 | static void yahoo_packet_process(struct yahoo_input_data *yid, |
---|
| 2457 | struct yahoo_packet *pkt) |
---|
[b7d3cc34] | 2458 | { |
---|
| 2459 | DEBUG_MSG(("yahoo_packet_process: 0x%02x", pkt->service)); |
---|
[c36f73b] | 2460 | switch (pkt->service) { |
---|
[b7d3cc34] | 2461 | case YAHOO_SERVICE_USERSTAT: |
---|
| 2462 | case YAHOO_SERVICE_LOGON: |
---|
| 2463 | case YAHOO_SERVICE_LOGOFF: |
---|
| 2464 | case YAHOO_SERVICE_ISAWAY: |
---|
| 2465 | case YAHOO_SERVICE_ISBACK: |
---|
| 2466 | case YAHOO_SERVICE_GAMELOGON: |
---|
| 2467 | case YAHOO_SERVICE_GAMELOGOFF: |
---|
| 2468 | case YAHOO_SERVICE_IDACT: |
---|
| 2469 | case YAHOO_SERVICE_IDDEACT: |
---|
[4fefb77] | 2470 | case YAHOO_SERVICE_Y6_STATUS_UPDATE: |
---|
[9034ba0] | 2471 | case YAHOO_SERVICE_Y8_STATUS: |
---|
[b7d3cc34] | 2472 | yahoo_process_status(yid, pkt); |
---|
| 2473 | break; |
---|
| 2474 | case YAHOO_SERVICE_NOTIFY: |
---|
| 2475 | yahoo_process_notify(yid, pkt); |
---|
| 2476 | break; |
---|
| 2477 | case YAHOO_SERVICE_MESSAGE: |
---|
| 2478 | case YAHOO_SERVICE_GAMEMSG: |
---|
| 2479 | case YAHOO_SERVICE_SYSMESSAGE: |
---|
| 2480 | yahoo_process_message(yid, pkt); |
---|
| 2481 | break; |
---|
| 2482 | case YAHOO_SERVICE_NEWMAIL: |
---|
| 2483 | yahoo_process_mail(yid, pkt); |
---|
| 2484 | break; |
---|
[9034ba0] | 2485 | case YAHOO_SERVICE_Y7_AUTHORIZATION: |
---|
| 2486 | yahoo_process_new_contact(yid, pkt); |
---|
| 2487 | break; |
---|
[b7d3cc34] | 2488 | case YAHOO_SERVICE_NEWCONTACT: |
---|
| 2489 | yahoo_process_contact(yid, pkt); |
---|
| 2490 | break; |
---|
| 2491 | case YAHOO_SERVICE_LIST: |
---|
| 2492 | yahoo_process_list(yid, pkt); |
---|
| 2493 | break; |
---|
| 2494 | case YAHOO_SERVICE_VERIFY: |
---|
| 2495 | yahoo_process_verify(yid, pkt); |
---|
| 2496 | break; |
---|
| 2497 | case YAHOO_SERVICE_AUTH: |
---|
| 2498 | yahoo_process_auth(yid, pkt); |
---|
| 2499 | break; |
---|
| 2500 | case YAHOO_SERVICE_AUTHRESP: |
---|
| 2501 | yahoo_process_auth_resp(yid, pkt); |
---|
| 2502 | break; |
---|
| 2503 | case YAHOO_SERVICE_CONFINVITE: |
---|
| 2504 | case YAHOO_SERVICE_CONFADDINVITE: |
---|
| 2505 | case YAHOO_SERVICE_CONFDECLINE: |
---|
| 2506 | case YAHOO_SERVICE_CONFLOGON: |
---|
| 2507 | case YAHOO_SERVICE_CONFLOGOFF: |
---|
| 2508 | case YAHOO_SERVICE_CONFMSG: |
---|
| 2509 | yahoo_process_conference(yid, pkt); |
---|
| 2510 | break; |
---|
| 2511 | case YAHOO_SERVICE_CHATONLINE: |
---|
| 2512 | case YAHOO_SERVICE_CHATGOTO: |
---|
| 2513 | case YAHOO_SERVICE_CHATJOIN: |
---|
| 2514 | case YAHOO_SERVICE_CHATLEAVE: |
---|
| 2515 | case YAHOO_SERVICE_CHATEXIT: |
---|
| 2516 | case YAHOO_SERVICE_CHATLOGOUT: |
---|
| 2517 | case YAHOO_SERVICE_CHATPING: |
---|
| 2518 | case YAHOO_SERVICE_COMMENT: |
---|
| 2519 | yahoo_process_chat(yid, pkt); |
---|
| 2520 | break; |
---|
| 2521 | case YAHOO_SERVICE_P2PFILEXFER: |
---|
[9034ba0] | 2522 | case YAHOO_SERVICE_Y7_FILETRANSFER: |
---|
[b7d3cc34] | 2523 | yahoo_process_filetransfer(yid, pkt); |
---|
| 2524 | break; |
---|
[9034ba0] | 2525 | case YAHOO_SERVICE_Y7_FILETRANSFERINFO: |
---|
| 2526 | yahoo_process_filetransferinfo(yid, pkt); |
---|
| 2527 | break; |
---|
| 2528 | case YAHOO_SERVICE_Y7_FILETRANSFERACCEPT: |
---|
| 2529 | yahoo_process_filetransferaccept(yid, pkt); |
---|
| 2530 | break; |
---|
[b7d3cc34] | 2531 | case YAHOO_SERVICE_ADDBUDDY: |
---|
| 2532 | yahoo_process_buddyadd(yid, pkt); |
---|
| 2533 | break; |
---|
| 2534 | case YAHOO_SERVICE_REMBUDDY: |
---|
| 2535 | yahoo_process_buddydel(yid, pkt); |
---|
| 2536 | break; |
---|
| 2537 | case YAHOO_SERVICE_IGNORECONTACT: |
---|
| 2538 | yahoo_process_ignore(yid, pkt); |
---|
| 2539 | break; |
---|
| 2540 | case YAHOO_SERVICE_VOICECHAT: |
---|
| 2541 | yahoo_process_voicechat(yid, pkt); |
---|
| 2542 | break; |
---|
| 2543 | case YAHOO_SERVICE_WEBCAM: |
---|
| 2544 | yahoo_process_webcam_key(yid, pkt); |
---|
| 2545 | break; |
---|
[cfc8d58] | 2546 | case YAHOO_SERVICE_PING: |
---|
| 2547 | yahoo_process_ping(yid, pkt); |
---|
| 2548 | break; |
---|
[9034ba0] | 2549 | case YAHOO_SERVICE_Y7_CHANGE_GROUP: |
---|
| 2550 | yahoo_process_buddy_change_group(yid, pkt); |
---|
| 2551 | break; |
---|
[b7d3cc34] | 2552 | case YAHOO_SERVICE_IDLE: |
---|
| 2553 | case YAHOO_SERVICE_MAILSTAT: |
---|
| 2554 | case YAHOO_SERVICE_CHATINVITE: |
---|
| 2555 | case YAHOO_SERVICE_CALENDAR: |
---|
| 2556 | case YAHOO_SERVICE_NEWPERSONALMAIL: |
---|
| 2557 | case YAHOO_SERVICE_ADDIDENT: |
---|
| 2558 | case YAHOO_SERVICE_ADDIGNORE: |
---|
| 2559 | case YAHOO_SERVICE_GOTGROUPRENAME: |
---|
| 2560 | case YAHOO_SERVICE_GROUPRENAME: |
---|
| 2561 | case YAHOO_SERVICE_PASSTHROUGH2: |
---|
| 2562 | case YAHOO_SERVICE_CHATLOGON: |
---|
| 2563 | case YAHOO_SERVICE_CHATLOGOFF: |
---|
| 2564 | case YAHOO_SERVICE_CHATMSG: |
---|
[9034ba0] | 2565 | case YAHOO_SERVICE_REJECTCONTACT: |
---|
[b7d3cc34] | 2566 | case YAHOO_SERVICE_PEERTOPEER: |
---|
| 2567 | WARNING(("unhandled service 0x%02x", pkt->service)); |
---|
| 2568 | yahoo_dump_unhandled(pkt); |
---|
| 2569 | break; |
---|
[cfc8d58] | 2570 | case YAHOO_SERVICE_PICTURE: |
---|
| 2571 | yahoo_process_picture(yid, pkt); |
---|
| 2572 | break; |
---|
| 2573 | case YAHOO_SERVICE_PICTURE_CHECKSUM: |
---|
| 2574 | yahoo_process_picture_checksum(yid, pkt); |
---|
| 2575 | break; |
---|
| 2576 | case YAHOO_SERVICE_PICTURE_UPLOAD: |
---|
| 2577 | yahoo_process_picture_upload(yid, pkt); |
---|
[9034ba0] | 2578 | break; |
---|
| 2579 | case YAHOO_SERVICE_Y8_LIST: /* Buddy List */ |
---|
[4fefb77] | 2580 | yahoo_process_buddy_list(yid, pkt); |
---|
[9034ba0] | 2581 | break; |
---|
[b7d3cc34] | 2582 | default: |
---|
| 2583 | WARNING(("unknown service 0x%02x", pkt->service)); |
---|
| 2584 | yahoo_dump_unhandled(pkt); |
---|
| 2585 | break; |
---|
| 2586 | } |
---|
| 2587 | } |
---|
| 2588 | |
---|
[c36f73b] | 2589 | static struct yahoo_packet *yahoo_getdata(struct yahoo_input_data *yid) |
---|
[b7d3cc34] | 2590 | { |
---|
| 2591 | struct yahoo_packet *pkt; |
---|
| 2592 | struct yahoo_data *yd = yid->yd; |
---|
| 2593 | int pos = 0; |
---|
| 2594 | int pktlen; |
---|
| 2595 | |
---|
[c36f73b] | 2596 | if (!yd) |
---|
[b7d3cc34] | 2597 | return NULL; |
---|
| 2598 | |
---|
| 2599 | DEBUG_MSG(("rxlen is %d", yid->rxlen)); |
---|
| 2600 | if (yid->rxlen < YAHOO_PACKET_HDRLEN) { |
---|
| 2601 | DEBUG_MSG(("len < YAHOO_PACKET_HDRLEN")); |
---|
| 2602 | return NULL; |
---|
| 2603 | } |
---|
| 2604 | |
---|
[c36f73b] | 2605 | pos += 4; /* YMSG */ |
---|
[b7d3cc34] | 2606 | pos += 2; |
---|
| 2607 | pos += 2; |
---|
| 2608 | |
---|
[c36f73b] | 2609 | pktlen = yahoo_get16(yid->rxqueue + pos); |
---|
| 2610 | pos += 2; |
---|
| 2611 | DEBUG_MSG(("%d bytes to read, rxlen is %d", pktlen, yid->rxlen)); |
---|
[b7d3cc34] | 2612 | |
---|
| 2613 | if (yid->rxlen < (YAHOO_PACKET_HDRLEN + pktlen)) { |
---|
| 2614 | DEBUG_MSG(("len < YAHOO_PACKET_HDRLEN + pktlen")); |
---|
| 2615 | return NULL; |
---|
| 2616 | } |
---|
| 2617 | |
---|
| 2618 | LOG(("reading packet")); |
---|
| 2619 | yahoo_packet_dump(yid->rxqueue, YAHOO_PACKET_HDRLEN + pktlen); |
---|
| 2620 | |
---|
| 2621 | pkt = yahoo_packet_new(0, 0, 0); |
---|
| 2622 | |
---|
[c36f73b] | 2623 | pkt->service = yahoo_get16(yid->rxqueue + pos); |
---|
| 2624 | pos += 2; |
---|
| 2625 | pkt->status = yahoo_get32(yid->rxqueue + pos); |
---|
| 2626 | pos += 4; |
---|
[b7d3cc34] | 2627 | DEBUG_MSG(("Yahoo Service: 0x%02x Status: %d", pkt->service, |
---|
[c36f73b] | 2628 | pkt->status)); |
---|
| 2629 | pkt->id = yahoo_get32(yid->rxqueue + pos); |
---|
| 2630 | pos += 4; |
---|
[b7d3cc34] | 2631 | |
---|
| 2632 | yd->session_id = pkt->id; |
---|
| 2633 | |
---|
| 2634 | yahoo_packet_read(pkt, yid->rxqueue + pos, pktlen); |
---|
| 2635 | |
---|
| 2636 | yid->rxlen -= YAHOO_PACKET_HDRLEN + pktlen; |
---|
| 2637 | DEBUG_MSG(("rxlen == %d, rxqueue == %p", yid->rxlen, yid->rxqueue)); |
---|
[c36f73b] | 2638 | if (yid->rxlen > 0) { |
---|
| 2639 | unsigned char *tmp = y_memdup(yid->rxqueue + YAHOO_PACKET_HDRLEN |
---|
| 2640 | + pktlen, yid->rxlen); |
---|
[b7d3cc34] | 2641 | FREE(yid->rxqueue); |
---|
| 2642 | yid->rxqueue = tmp; |
---|
[c36f73b] | 2643 | DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, |
---|
| 2644 | yid->rxqueue)); |
---|
[b7d3cc34] | 2645 | } else { |
---|
| 2646 | DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); |
---|
| 2647 | FREE(yid->rxqueue); |
---|
| 2648 | } |
---|
| 2649 | |
---|
| 2650 | return pkt; |
---|
| 2651 | } |
---|
| 2652 | |
---|
[509cf60] | 2653 | #if 0 |
---|
[c36f73b] | 2654 | static struct yab *yahoo_yab_read(unsigned char *d, int len) |
---|
[b7d3cc34] | 2655 | { |
---|
| 2656 | char *st, *en; |
---|
| 2657 | char *data = (char *)d; |
---|
[c36f73b] | 2658 | struct yab *yab = NULL; |
---|
| 2659 | |
---|
| 2660 | data[len] = '\0'; |
---|
[b7d3cc34] | 2661 | |
---|
| 2662 | DEBUG_MSG(("Got yab: %s", data)); |
---|
[c36f73b] | 2663 | st = en = strstr(data, "e0=\""); |
---|
| 2664 | if (st) { |
---|
| 2665 | yab = y_new0(struct yab, 1); |
---|
| 2666 | |
---|
| 2667 | st += strlen("e0=\""); |
---|
| 2668 | en = strchr(st, '"'); |
---|
| 2669 | *en++ = '\0'; |
---|
| 2670 | yab->email = yahoo_xmldecode(st); |
---|
| 2671 | } |
---|
| 2672 | |
---|
| 2673 | if (!en) |
---|
| 2674 | return NULL; |
---|
| 2675 | |
---|
| 2676 | st = strstr(en, "id=\""); |
---|
| 2677 | if (st) { |
---|
| 2678 | st += strlen("id=\""); |
---|
| 2679 | en = strchr(st, '"'); |
---|
| 2680 | *en++ = '\0'; |
---|
| 2681 | yab->yid = atoi(yahoo_xmldecode(st)); |
---|
[b7d3cc34] | 2682 | } |
---|
| 2683 | |
---|
[c36f73b] | 2684 | st = strstr(en, "fn=\""); |
---|
| 2685 | if (st) { |
---|
| 2686 | st += strlen("fn=\""); |
---|
| 2687 | en = strchr(st, '"'); |
---|
| 2688 | *en++ = '\0'; |
---|
[b7d3cc34] | 2689 | yab->fname = yahoo_xmldecode(st); |
---|
| 2690 | } |
---|
| 2691 | |
---|
[c36f73b] | 2692 | st = strstr(en, "ln=\""); |
---|
| 2693 | if (st) { |
---|
| 2694 | st += strlen("ln=\""); |
---|
| 2695 | en = strchr(st, '"'); |
---|
| 2696 | *en++ = '\0'; |
---|
[b7d3cc34] | 2697 | yab->lname = yahoo_xmldecode(st); |
---|
| 2698 | } |
---|
| 2699 | |
---|
[c36f73b] | 2700 | st = strstr(en, "nn=\""); |
---|
| 2701 | if (st) { |
---|
| 2702 | st += strlen("nn=\""); |
---|
| 2703 | en = strchr(st, '"'); |
---|
| 2704 | *en++ = '\0'; |
---|
[b7d3cc34] | 2705 | yab->nname = yahoo_xmldecode(st); |
---|
| 2706 | } |
---|
| 2707 | |
---|
[c36f73b] | 2708 | st = strstr(en, "yi=\""); |
---|
| 2709 | if (st) { |
---|
| 2710 | st += strlen("yi=\""); |
---|
| 2711 | en = strchr(st, '"'); |
---|
| 2712 | *en++ = '\0'; |
---|
| 2713 | yab->id = yahoo_xmldecode(st); |
---|
[b7d3cc34] | 2714 | } |
---|
| 2715 | |
---|
| 2716 | st = strstr(en, "hphone=\""); |
---|
[c36f73b] | 2717 | if (st) { |
---|
[b7d3cc34] | 2718 | st += strlen("hphone=\""); |
---|
[c36f73b] | 2719 | en = strchr(st, '"'); |
---|
| 2720 | *en++ = '\0'; |
---|
[b7d3cc34] | 2721 | yab->hphone = yahoo_xmldecode(st); |
---|
| 2722 | } |
---|
| 2723 | |
---|
| 2724 | st = strstr(en, "wphone=\""); |
---|
[c36f73b] | 2725 | if (st) { |
---|
[b7d3cc34] | 2726 | st += strlen("wphone=\""); |
---|
[c36f73b] | 2727 | en = strchr(st, '"'); |
---|
| 2728 | *en++ = '\0'; |
---|
[b7d3cc34] | 2729 | yab->wphone = yahoo_xmldecode(st); |
---|
| 2730 | } |
---|
| 2731 | |
---|
| 2732 | st = strstr(en, "mphone=\""); |
---|
[c36f73b] | 2733 | if (st) { |
---|
[b7d3cc34] | 2734 | st += strlen("mphone=\""); |
---|
[c36f73b] | 2735 | en = strchr(st, '"'); |
---|
| 2736 | *en++ = '\0'; |
---|
[b7d3cc34] | 2737 | yab->mphone = yahoo_xmldecode(st); |
---|
| 2738 | } |
---|
| 2739 | |
---|
| 2740 | st = strstr(en, "dbid=\""); |
---|
[c36f73b] | 2741 | if (st) { |
---|
[b7d3cc34] | 2742 | st += strlen("dbid=\""); |
---|
[c36f73b] | 2743 | en = strchr(st, '"'); |
---|
| 2744 | *en++ = '\0'; |
---|
[b7d3cc34] | 2745 | yab->dbid = atoi(st); |
---|
| 2746 | } |
---|
[c36f73b] | 2747 | |
---|
| 2748 | return yab; |
---|
[b7d3cc34] | 2749 | } |
---|
| 2750 | |
---|
[c36f73b] | 2751 | static struct yab *yahoo_getyab(struct yahoo_input_data *yid) |
---|
[b7d3cc34] | 2752 | { |
---|
| 2753 | struct yab *yab = NULL; |
---|
[c36f73b] | 2754 | int pos = 0, end = 0; |
---|
[b7d3cc34] | 2755 | struct yahoo_data *yd = yid->yd; |
---|
| 2756 | |
---|
[c36f73b] | 2757 | if (!yd) |
---|
[b7d3cc34] | 2758 | return NULL; |
---|
| 2759 | |
---|
[c36f73b] | 2760 | do { |
---|
| 2761 | DEBUG_MSG(("rxlen is %d", yid->rxlen)); |
---|
| 2762 | |
---|
| 2763 | if (yid->rxlen <= strlen("<ct")) |
---|
| 2764 | return NULL; |
---|
| 2765 | |
---|
| 2766 | /* start with <ct */ |
---|
| 2767 | while (pos < yid->rxlen - strlen("<ct") + 1 |
---|
| 2768 | && memcmp(yid->rxqueue + pos, "<ct", strlen("<ct"))) |
---|
| 2769 | pos++; |
---|
| 2770 | |
---|
| 2771 | if (pos >= yid->rxlen - 1) |
---|
| 2772 | return NULL; |
---|
| 2773 | |
---|
| 2774 | end = pos + 2; |
---|
| 2775 | /* end with > */ |
---|
| 2776 | while (end < yid->rxlen - strlen(">") |
---|
| 2777 | && memcmp(yid->rxqueue + end, ">", strlen(">"))) |
---|
| 2778 | end++; |
---|
| 2779 | |
---|
| 2780 | if (end >= yid->rxlen - 1) |
---|
| 2781 | return NULL; |
---|
| 2782 | |
---|
| 2783 | yab = yahoo_yab_read(yid->rxqueue + pos, end + 2 - pos); |
---|
| 2784 | |
---|
| 2785 | yid->rxlen -= end + 1; |
---|
| 2786 | DEBUG_MSG(("rxlen == %d, rxqueue == %p", yid->rxlen, |
---|
| 2787 | yid->rxqueue)); |
---|
| 2788 | if (yid->rxlen > 0) { |
---|
| 2789 | unsigned char *tmp = |
---|
| 2790 | y_memdup(yid->rxqueue + end + 1, yid->rxlen); |
---|
| 2791 | FREE(yid->rxqueue); |
---|
| 2792 | yid->rxqueue = tmp; |
---|
| 2793 | DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, |
---|
| 2794 | yid->rxqueue)); |
---|
| 2795 | } else { |
---|
| 2796 | DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); |
---|
| 2797 | FREE(yid->rxqueue); |
---|
| 2798 | } |
---|
[b7d3cc34] | 2799 | |
---|
[c36f73b] | 2800 | } while (!yab && end < yid->rxlen - 1); |
---|
[b7d3cc34] | 2801 | |
---|
| 2802 | return yab; |
---|
| 2803 | } |
---|
[509cf60] | 2804 | #endif |
---|
[b7d3cc34] | 2805 | |
---|
[c36f73b] | 2806 | static char *yahoo_getwebcam_master(struct yahoo_input_data *yid) |
---|
[b7d3cc34] | 2807 | { |
---|
[c36f73b] | 2808 | unsigned int pos = 0; |
---|
| 2809 | unsigned int len = 0; |
---|
| 2810 | unsigned int status = 0; |
---|
| 2811 | char *server = NULL; |
---|
[b7d3cc34] | 2812 | struct yahoo_data *yd = yid->yd; |
---|
| 2813 | |
---|
[c36f73b] | 2814 | if (!yid || !yd) |
---|
[b7d3cc34] | 2815 | return NULL; |
---|
| 2816 | |
---|
| 2817 | DEBUG_MSG(("rxlen is %d", yid->rxlen)); |
---|
| 2818 | |
---|
| 2819 | len = yid->rxqueue[pos++]; |
---|
| 2820 | if (yid->rxlen < len) |
---|
| 2821 | return NULL; |
---|
| 2822 | |
---|
| 2823 | /* extract status (0 = ok, 6 = webcam not online) */ |
---|
| 2824 | status = yid->rxqueue[pos++]; |
---|
| 2825 | |
---|
[c36f73b] | 2826 | if (status == 0) { |
---|
| 2827 | pos += 2; /* skip next 2 bytes */ |
---|
| 2828 | server = y_memdup(yid->rxqueue + pos, 16); |
---|
[b7d3cc34] | 2829 | pos += 16; |
---|
[c36f73b] | 2830 | } else if (status == 6) { |
---|
[b7d3cc34] | 2831 | YAHOO_CALLBACK(ext_yahoo_webcam_closed) |
---|
| 2832 | (yd->client_id, yid->wcm->user, 4); |
---|
| 2833 | } |
---|
| 2834 | |
---|
| 2835 | /* skip rest of the data */ |
---|
| 2836 | |
---|
| 2837 | yid->rxlen -= len; |
---|
| 2838 | DEBUG_MSG(("rxlen == %d, rxqueue == %p", yid->rxlen, yid->rxqueue)); |
---|
[c36f73b] | 2839 | if (yid->rxlen > 0) { |
---|
[b7d3cc34] | 2840 | unsigned char *tmp = y_memdup(yid->rxqueue + pos, yid->rxlen); |
---|
| 2841 | FREE(yid->rxqueue); |
---|
| 2842 | yid->rxqueue = tmp; |
---|
[c36f73b] | 2843 | DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, |
---|
| 2844 | yid->rxqueue)); |
---|
[b7d3cc34] | 2845 | } else { |
---|
| 2846 | DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); |
---|
| 2847 | FREE(yid->rxqueue); |
---|
| 2848 | } |
---|
| 2849 | |
---|
| 2850 | return server; |
---|
| 2851 | } |
---|
| 2852 | |
---|
| 2853 | static int yahoo_get_webcam_data(struct yahoo_input_data *yid) |
---|
| 2854 | { |
---|
[c36f73b] | 2855 | unsigned char reason = 0; |
---|
| 2856 | unsigned int pos = 0; |
---|
| 2857 | unsigned int begin = 0; |
---|
| 2858 | unsigned int end = 0; |
---|
| 2859 | unsigned int closed = 0; |
---|
| 2860 | unsigned char header_len = 0; |
---|
[b7d3cc34] | 2861 | char *who; |
---|
[c36f73b] | 2862 | int connect = 0; |
---|
[b7d3cc34] | 2863 | struct yahoo_data *yd = yid->yd; |
---|
| 2864 | |
---|
[c36f73b] | 2865 | if (!yd) |
---|
[b7d3cc34] | 2866 | return -1; |
---|
| 2867 | |
---|
[c36f73b] | 2868 | if (!yid->wcm || !yid->wcd || !yid->rxlen) |
---|
[b7d3cc34] | 2869 | return -1; |
---|
| 2870 | |
---|
| 2871 | DEBUG_MSG(("rxlen is %d", yid->rxlen)); |
---|
| 2872 | |
---|
| 2873 | /* if we are not reading part of image then read header */ |
---|
[c36f73b] | 2874 | if (!yid->wcd->to_read) { |
---|
| 2875 | header_len = yid->rxqueue[pos++]; |
---|
| 2876 | yid->wcd->packet_type = 0; |
---|
[b7d3cc34] | 2877 | |
---|
| 2878 | if (yid->rxlen < header_len) |
---|
| 2879 | return 0; |
---|
| 2880 | |
---|
[c36f73b] | 2881 | if (header_len >= 8) { |
---|
[b7d3cc34] | 2882 | reason = yid->rxqueue[pos++]; |
---|
| 2883 | /* next 2 bytes should always be 05 00 */ |
---|
| 2884 | pos += 2; |
---|
| 2885 | yid->wcd->data_size = yahoo_get32(yid->rxqueue + pos); |
---|
| 2886 | pos += 4; |
---|
| 2887 | yid->wcd->to_read = yid->wcd->data_size; |
---|
| 2888 | } |
---|
[c36f73b] | 2889 | if (header_len >= 13) { |
---|
[b7d3cc34] | 2890 | yid->wcd->packet_type = yid->rxqueue[pos++]; |
---|
| 2891 | yid->wcd->timestamp = yahoo_get32(yid->rxqueue + pos); |
---|
| 2892 | pos += 4; |
---|
| 2893 | } |
---|
| 2894 | |
---|
| 2895 | /* skip rest of header */ |
---|
| 2896 | pos = header_len; |
---|
| 2897 | } |
---|
| 2898 | |
---|
| 2899 | begin = pos; |
---|
| 2900 | pos += yid->wcd->to_read; |
---|
[c36f73b] | 2901 | if (pos > yid->rxlen) |
---|
| 2902 | pos = yid->rxlen; |
---|
[b7d3cc34] | 2903 | |
---|
| 2904 | /* if it is not an image then make sure we have the whole packet */ |
---|
| 2905 | if (yid->wcd->packet_type != 0x02) { |
---|
| 2906 | if ((pos - begin) != yid->wcd->data_size) { |
---|
| 2907 | yid->wcd->to_read = 0; |
---|
| 2908 | return 0; |
---|
| 2909 | } else { |
---|
| 2910 | yahoo_packet_dump(yid->rxqueue + begin, pos - begin); |
---|
| 2911 | } |
---|
| 2912 | } |
---|
| 2913 | |
---|
| 2914 | DEBUG_MSG(("packet type %.2X, data length %d", yid->wcd->packet_type, |
---|
[c36f73b] | 2915 | yid->wcd->data_size)); |
---|
[b7d3cc34] | 2916 | |
---|
| 2917 | /* find out what kind of packet we got */ |
---|
[9034ba0] | 2918 | switch (yid->wcd->packet_type) { |
---|
| 2919 | case 0x00: |
---|
| 2920 | /* user requests to view webcam (uploading) */ |
---|
| 2921 | if (yid->wcd->data_size && |
---|
| 2922 | yid->wcm->direction == YAHOO_WEBCAM_UPLOAD) { |
---|
| 2923 | end = begin; |
---|
| 2924 | while (end <= yid->rxlen && yid->rxqueue[end++] != 13) ; |
---|
| 2925 | if (end > begin) { |
---|
| 2926 | who = y_memdup(yid->rxqueue + begin, |
---|
| 2927 | end - begin); |
---|
| 2928 | who[end - begin - 1] = 0; |
---|
| 2929 | YAHOO_CALLBACK(ext_yahoo_webcam_viewer) (yd-> |
---|
| 2930 | client_id, who + 2, 2); |
---|
| 2931 | FREE(who); |
---|
[b7d3cc34] | 2932 | } |
---|
[9034ba0] | 2933 | } |
---|
[b7d3cc34] | 2934 | |
---|
[9034ba0] | 2935 | if (yid->wcm->direction == YAHOO_WEBCAM_DOWNLOAD) { |
---|
| 2936 | /* timestamp/status field */ |
---|
| 2937 | /* 0 = declined viewing permission */ |
---|
| 2938 | /* 1 = accepted viewing permission */ |
---|
| 2939 | if (yid->wcd->timestamp == 0) { |
---|
| 2940 | YAHOO_CALLBACK(ext_yahoo_webcam_closed) (yd-> |
---|
| 2941 | client_id, yid->wcm->user, 3); |
---|
[b7d3cc34] | 2942 | } |
---|
[9034ba0] | 2943 | } |
---|
| 2944 | break; |
---|
| 2945 | case 0x01: /* status packets?? */ |
---|
| 2946 | /* timestamp contains status info */ |
---|
| 2947 | /* 00 00 00 01 = we have data?? */ |
---|
| 2948 | break; |
---|
| 2949 | case 0x02: /* image data */ |
---|
| 2950 | YAHOO_CALLBACK(ext_yahoo_got_webcam_image) (yd->client_id, |
---|
| 2951 | yid->wcm->user, yid->rxqueue + begin, |
---|
| 2952 | yid->wcd->data_size, pos - begin, yid->wcd->timestamp); |
---|
| 2953 | break; |
---|
| 2954 | case 0x05: /* response packets when uploading */ |
---|
| 2955 | if (!yid->wcd->data_size) { |
---|
| 2956 | YAHOO_CALLBACK(ext_yahoo_webcam_data_request) (yd-> |
---|
| 2957 | client_id, yid->wcd->timestamp); |
---|
| 2958 | } |
---|
| 2959 | break; |
---|
| 2960 | case 0x07: /* connection is closing */ |
---|
| 2961 | switch (reason) { |
---|
| 2962 | case 0x01: /* user closed connection */ |
---|
| 2963 | closed = 1; |
---|
[b7d3cc34] | 2964 | break; |
---|
[9034ba0] | 2965 | case 0x0F: /* user cancelled permission */ |
---|
| 2966 | closed = 2; |
---|
[b7d3cc34] | 2967 | break; |
---|
[9034ba0] | 2968 | } |
---|
| 2969 | YAHOO_CALLBACK(ext_yahoo_webcam_closed) (yd->client_id, |
---|
| 2970 | yid->wcm->user, closed); |
---|
| 2971 | break; |
---|
| 2972 | case 0x0C: /* user connected */ |
---|
| 2973 | case 0x0D: /* user disconnected */ |
---|
| 2974 | if (yid->wcd->data_size) { |
---|
| 2975 | who = y_memdup(yid->rxqueue + begin, pos - begin + 1); |
---|
| 2976 | who[pos - begin] = 0; |
---|
| 2977 | if (yid->wcd->packet_type == 0x0C) |
---|
| 2978 | connect = 1; |
---|
| 2979 | else |
---|
| 2980 | connect = 0; |
---|
| 2981 | YAHOO_CALLBACK(ext_yahoo_webcam_viewer) (yd->client_id, |
---|
| 2982 | who, connect); |
---|
| 2983 | FREE(who); |
---|
| 2984 | } |
---|
| 2985 | break; |
---|
| 2986 | case 0x13: /* user data */ |
---|
| 2987 | /* i=user_ip (ip of the user we are viewing) */ |
---|
| 2988 | /* j=user_ext_ip (external ip of the user we */ |
---|
| 2989 | /* are viewing) */ |
---|
| 2990 | break; |
---|
| 2991 | case 0x17: /* ?? */ |
---|
| 2992 | break; |
---|
[b7d3cc34] | 2993 | } |
---|
| 2994 | yid->wcd->to_read -= pos - begin; |
---|
| 2995 | |
---|
| 2996 | yid->rxlen -= pos; |
---|
| 2997 | DEBUG_MSG(("rxlen == %d, rxqueue == %p", yid->rxlen, yid->rxqueue)); |
---|
[9034ba0] | 2998 | if (yid->rxlen > 0) { |
---|
[b7d3cc34] | 2999 | unsigned char *tmp = y_memdup(yid->rxqueue + pos, yid->rxlen); |
---|
| 3000 | FREE(yid->rxqueue); |
---|
| 3001 | yid->rxqueue = tmp; |
---|
[9034ba0] | 3002 | DEBUG_MSG(("new rxlen == %d, rxqueue == %p", yid->rxlen, |
---|
| 3003 | yid->rxqueue)); |
---|
[b7d3cc34] | 3004 | } else { |
---|
| 3005 | DEBUG_MSG(("freed rxqueue == %p", yid->rxqueue)); |
---|
| 3006 | FREE(yid->rxqueue); |
---|
| 3007 | } |
---|
| 3008 | |
---|
| 3009 | /* If we read a complete packet return success */ |
---|
| 3010 | if (!yid->wcd->to_read) |
---|
| 3011 | return 1; |
---|
| 3012 | |
---|
| 3013 | return 0; |
---|
| 3014 | } |
---|
| 3015 | |
---|
[9034ba0] | 3016 | int yahoo_write_ready(int id, void *fd, void *data) |
---|
[b7d3cc34] | 3017 | { |
---|
| 3018 | struct yahoo_input_data *yid = data; |
---|
| 3019 | int len; |
---|
| 3020 | struct data_queue *tx; |
---|
| 3021 | |
---|
[9034ba0] | 3022 | LOG(("write callback: id=%d fd=%p data=%p", id, fd, data)); |
---|
| 3023 | if (!yid || !yid->txqueues) |
---|
[b7d3cc34] | 3024 | return -2; |
---|
[9034ba0] | 3025 | |
---|
[b7d3cc34] | 3026 | tx = yid->txqueues->data; |
---|
| 3027 | LOG(("writing %d bytes", tx->len)); |
---|
| 3028 | len = yahoo_send_data(fd, tx->queue, MIN(1024, tx->len)); |
---|
| 3029 | |
---|
[c36f73b] | 3030 | if (len == -1 && errno == EAGAIN) |
---|
[b7d3cc34] | 3031 | return 1; |
---|
| 3032 | |
---|
[c36f73b] | 3033 | if (len <= 0) { |
---|
[b7d3cc34] | 3034 | int e = errno; |
---|
| 3035 | DEBUG_MSG(("len == %d (<= 0)", len)); |
---|
[c36f73b] | 3036 | while (yid->txqueues) { |
---|
| 3037 | YList *l = yid->txqueues; |
---|
[b7d3cc34] | 3038 | tx = l->data; |
---|
| 3039 | free(tx->queue); |
---|
| 3040 | free(tx); |
---|
[9034ba0] | 3041 | yid->txqueues = |
---|
| 3042 | y_list_remove_link(yid->txqueues, |
---|
| 3043 | yid->txqueues); |
---|
[b7d3cc34] | 3044 | y_list_free_1(l); |
---|
| 3045 | } |
---|
[9034ba0] | 3046 | LOG(("yahoo_write_ready(%d, %p) len < 0", id, fd)); |
---|
[c36f73b] | 3047 | YAHOO_CALLBACK(ext_yahoo_remove_handler) (id, yid->write_tag); |
---|
[b7d3cc34] | 3048 | yid->write_tag = 0; |
---|
[c36f73b] | 3049 | errno = e; |
---|
[b7d3cc34] | 3050 | return 0; |
---|
| 3051 | } |
---|
| 3052 | |
---|
| 3053 | |
---|
| 3054 | tx->len -= len; |
---|
[c36f73b] | 3055 | if (tx->len > 0) { |
---|
[b7d3cc34] | 3056 | unsigned char *tmp = y_memdup(tx->queue + len, tx->len); |
---|
| 3057 | FREE(tx->queue); |
---|
| 3058 | tx->queue = tmp; |
---|
| 3059 | } else { |
---|
[c36f73b] | 3060 | YList *l = yid->txqueues; |
---|
[b7d3cc34] | 3061 | free(tx->queue); |
---|
| 3062 | free(tx); |
---|
[9034ba0] | 3063 | yid->txqueues = |
---|
| 3064 | y_list_remove_link(yid->txqueues, yid->txqueues); |
---|
[b7d3cc34] | 3065 | y_list_free_1(l); |
---|
| 3066 | /* |
---|
[9034ba0] | 3067 | if(!yid->txqueues) |
---|
| 3068 | LOG(("yahoo_write_ready(%d, %d) !yxqueues", id, fd)); |
---|
| 3069 | */ |
---|
[c36f73b] | 3070 | if (!yid->txqueues) { |
---|
[9034ba0] | 3071 | LOG(("yahoo_write_ready(%d, %p) !txqueues", id, fd)); |
---|
| 3072 | YAHOO_CALLBACK(ext_yahoo_remove_handler) (id, |
---|
| 3073 | yid->write_tag); |
---|
[b7d3cc34] | 3074 | yid->write_tag = 0; |
---|
| 3075 | } |
---|
| 3076 | } |
---|
| 3077 | |
---|
| 3078 | return 1; |
---|
| 3079 | } |
---|
| 3080 | |
---|
[9034ba0] | 3081 | static void yahoo_process_pager_connection(struct yahoo_input_data *yid, |
---|
| 3082 | int over) |
---|
[b7d3cc34] | 3083 | { |
---|
| 3084 | struct yahoo_packet *pkt; |
---|
| 3085 | struct yahoo_data *yd = yid->yd; |
---|
| 3086 | int id = yd->client_id; |
---|
| 3087 | |
---|
[c36f73b] | 3088 | if (over) |
---|
[b7d3cc34] | 3089 | return; |
---|
| 3090 | |
---|
[9034ba0] | 3091 | while (find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER) |
---|
| 3092 | && (pkt = yahoo_getdata(yid)) != NULL) { |
---|
[b7d3cc34] | 3093 | |
---|
| 3094 | yahoo_packet_process(yid, pkt); |
---|
| 3095 | |
---|
| 3096 | yahoo_packet_free(pkt); |
---|
| 3097 | } |
---|
| 3098 | } |
---|
| 3099 | |
---|
[9034ba0] | 3100 | static void yahoo_process_chatcat_connection(struct yahoo_input_data *yid, |
---|
| 3101 | int over) |
---|
[b7d3cc34] | 3102 | { |
---|
[c36f73b] | 3103 | if (over) |
---|
[b7d3cc34] | 3104 | return; |
---|
| 3105 | |
---|
[9034ba0] | 3106 | if (strstr((char *)yid->rxqueue + (yid->rxlen - 20), "</content>")) { |
---|
| 3107 | YAHOO_CALLBACK(ext_yahoo_chat_cat_xml) (yid->yd->client_id, |
---|
| 3108 | (char *)yid->rxqueue); |
---|
[b7d3cc34] | 3109 | } |
---|
| 3110 | } |
---|
| 3111 | |
---|
[509cf60] | 3112 | #if 0 |
---|
[b7d3cc34] | 3113 | static void yahoo_process_yab_connection(struct yahoo_input_data *yid, int over) |
---|
| 3114 | { |
---|
| 3115 | struct yahoo_data *yd = yid->yd; |
---|
| 3116 | struct yab *yab; |
---|
| 3117 | YList *buds; |
---|
[c36f73b] | 3118 | int changed = 0; |
---|
[b7d3cc34] | 3119 | int id = yd->client_id; |
---|
[9034ba0] | 3120 | int yab_used = 0; |
---|
| 3121 | |
---|
| 3122 | LOG(("Got data for YAB")); |
---|
[b7d3cc34] | 3123 | |
---|
[c36f73b] | 3124 | if (over) |
---|
[b7d3cc34] | 3125 | return; |
---|
| 3126 | |
---|
[9034ba0] | 3127 | while (find_input_by_id_and_type(id, YAHOO_CONNECTION_YAB) |
---|
| 3128 | && (yab = yahoo_getyab(yid)) != NULL) { |
---|
[c36f73b] | 3129 | if (!yab->id) |
---|
[b7d3cc34] | 3130 | continue; |
---|
[9034ba0] | 3131 | |
---|
[c36f73b] | 3132 | changed = 1; |
---|
[9034ba0] | 3133 | yab_used = 0; |
---|
[c36f73b] | 3134 | for (buds = yd->buddies; buds; buds = buds->next) { |
---|
| 3135 | struct yahoo_buddy *bud = buds->data; |
---|
| 3136 | if (!strcmp(bud->id, yab->id)) { |
---|
[9034ba0] | 3137 | yab_used = 1; |
---|
[b7d3cc34] | 3138 | bud->yab_entry = yab; |
---|
[c36f73b] | 3139 | if (yab->nname) { |
---|
[b7d3cc34] | 3140 | bud->real_name = strdup(yab->nname); |
---|
[c36f73b] | 3141 | } else if (yab->fname && yab->lname) { |
---|
[9034ba0] | 3142 | bud->real_name = y_new0(char, |
---|
| 3143 | strlen(yab->fname) + |
---|
| 3144 | strlen(yab->lname) + 2); |
---|
[b7d3cc34] | 3145 | sprintf(bud->real_name, "%s %s", |
---|
[9034ba0] | 3146 | yab->fname, yab->lname); |
---|
[c36f73b] | 3147 | } else if (yab->fname) { |
---|
[b7d3cc34] | 3148 | bud->real_name = strdup(yab->fname); |
---|
| 3149 | } |
---|
[9034ba0] | 3150 | break; /* for */ |
---|
[b7d3cc34] | 3151 | } |
---|
| 3152 | } |
---|
[9034ba0] | 3153 | |
---|
| 3154 | if (!yab_used) { |
---|
| 3155 | FREE(yab->fname); |
---|
| 3156 | FREE(yab->lname); |
---|
| 3157 | FREE(yab->nname); |
---|
| 3158 | FREE(yab->id); |
---|
| 3159 | FREE(yab->email); |
---|
| 3160 | FREE(yab->hphone); |
---|
| 3161 | FREE(yab->wphone); |
---|
| 3162 | FREE(yab->mphone); |
---|
| 3163 | FREE(yab); |
---|
| 3164 | } |
---|
| 3165 | |
---|
[b7d3cc34] | 3166 | } |
---|
| 3167 | |
---|
[c36f73b] | 3168 | if (changed) |
---|
[9034ba0] | 3169 | YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, |
---|
| 3170 | yd->buddies); |
---|
[b7d3cc34] | 3171 | } |
---|
[509cf60] | 3172 | #endif |
---|
[b7d3cc34] | 3173 | |
---|
[9034ba0] | 3174 | static void yahoo_process_search_connection(struct yahoo_input_data *yid, |
---|
| 3175 | int over) |
---|
[b7d3cc34] | 3176 | { |
---|
[c36f73b] | 3177 | struct yahoo_found_contact *yct = NULL; |
---|
[b7d3cc34] | 3178 | char *p = (char *)yid->rxqueue, *np, *cp; |
---|
| 3179 | int k, n; |
---|
[9034ba0] | 3180 | int start = 0, found = 0, total = 0; |
---|
[c36f73b] | 3181 | YList *contacts = NULL; |
---|
[9034ba0] | 3182 | struct yahoo_input_data *pyid = |
---|
| 3183 | find_input_by_id_and_type(yid->yd->client_id, |
---|
| 3184 | YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3185 | |
---|
[c36f73b] | 3186 | if (!over || !pyid) |
---|
[b7d3cc34] | 3187 | return; |
---|
| 3188 | |
---|
[c36f73b] | 3189 | if (p && (p = strstr(p, "\r\n\r\n"))) { |
---|
[b7d3cc34] | 3190 | p += 4; |
---|
| 3191 | |
---|
[c36f73b] | 3192 | for (k = 0; (p = strchr(p, 4)) && (k < 4); k++) { |
---|
[b7d3cc34] | 3193 | p++; |
---|
| 3194 | n = atoi(p); |
---|
[9034ba0] | 3195 | switch (k) { |
---|
| 3196 | case 0: |
---|
| 3197 | found = pyid->ys->lsearch_nfound = n; |
---|
| 3198 | break; |
---|
| 3199 | case 2: |
---|
| 3200 | start = pyid->ys->lsearch_nstart = n; |
---|
| 3201 | break; |
---|
| 3202 | case 3: |
---|
| 3203 | total = pyid->ys->lsearch_ntotal = n; |
---|
| 3204 | break; |
---|
[b7d3cc34] | 3205 | } |
---|
| 3206 | } |
---|
| 3207 | |
---|
[c36f73b] | 3208 | if (p) |
---|
[b7d3cc34] | 3209 | p++; |
---|
| 3210 | |
---|
[c36f73b] | 3211 | k = 0; |
---|
| 3212 | while (p && *p) { |
---|
[b7d3cc34] | 3213 | cp = p; |
---|
| 3214 | np = strchr(p, 4); |
---|
| 3215 | |
---|
[c36f73b] | 3216 | if (!np) |
---|
[b7d3cc34] | 3217 | break; |
---|
| 3218 | *np = 0; |
---|
[9034ba0] | 3219 | p = np + 1; |
---|
| 3220 | |
---|
| 3221 | switch (k++) { |
---|
| 3222 | case 1: |
---|
| 3223 | if (strlen(cp) > 2 |
---|
| 3224 | && y_list_length(contacts) < total) { |
---|
| 3225 | yct = y_new0(struct yahoo_found_contact, |
---|
| 3226 | 1); |
---|
| 3227 | contacts = y_list_append(contacts, yct); |
---|
| 3228 | yct->id = cp + 2; |
---|
| 3229 | } else { |
---|
| 3230 | *p = 0; |
---|
| 3231 | } |
---|
| 3232 | break; |
---|
| 3233 | case 2: |
---|
| 3234 | yct->online = !strcmp(cp, "2") ? 1 : 0; |
---|
| 3235 | break; |
---|
| 3236 | case 3: |
---|
| 3237 | yct->gender = cp; |
---|
| 3238 | break; |
---|
| 3239 | case 4: |
---|
| 3240 | yct->age = atoi(cp); |
---|
| 3241 | break; |
---|
| 3242 | case 5: |
---|
| 3243 | /* not worth the context switch for strcmp */ |
---|
| 3244 | if (cp[0] != '\005' || cp[1] != '\000') |
---|
| 3245 | yct->location = cp; |
---|
| 3246 | k = 0; |
---|
| 3247 | break; |
---|
[b7d3cc34] | 3248 | } |
---|
| 3249 | } |
---|
| 3250 | } |
---|
| 3251 | |
---|
[9034ba0] | 3252 | YAHOO_CALLBACK(ext_yahoo_got_search_result) (yid->yd->client_id, found, |
---|
| 3253 | start, total, contacts); |
---|
[b7d3cc34] | 3254 | |
---|
[c36f73b] | 3255 | while (contacts) { |
---|
[b7d3cc34] | 3256 | YList *node = contacts; |
---|
| 3257 | contacts = y_list_remove_link(contacts, node); |
---|
| 3258 | free(node->data); |
---|
| 3259 | y_list_free_1(node); |
---|
| 3260 | } |
---|
| 3261 | } |
---|
| 3262 | |
---|
[9034ba0] | 3263 | static void _yahoo_webcam_connected(void *fd, int error, void *d) |
---|
[b7d3cc34] | 3264 | { |
---|
| 3265 | struct yahoo_input_data *yid = d; |
---|
| 3266 | struct yahoo_webcam *wcm = yid->wcm; |
---|
| 3267 | struct yahoo_data *yd = yid->yd; |
---|
| 3268 | char conn_type[100]; |
---|
[c36f73b] | 3269 | char *data = NULL; |
---|
| 3270 | char *packet = NULL; |
---|
[9034ba0] | 3271 | unsigned char magic_nr[] = { 1, 0, 0, 0, 1 }; |
---|
[c36f73b] | 3272 | unsigned header_len = 0; |
---|
| 3273 | unsigned int len = 0; |
---|
| 3274 | unsigned int pos = 0; |
---|
[b7d3cc34] | 3275 | |
---|
[9034ba0] | 3276 | if (error || !fd) { |
---|
[b7d3cc34] | 3277 | FREE(yid); |
---|
| 3278 | return; |
---|
| 3279 | } |
---|
| 3280 | |
---|
| 3281 | yid->fd = fd; |
---|
| 3282 | inputs = y_list_prepend(inputs, yid); |
---|
| 3283 | |
---|
| 3284 | LOG(("Connected")); |
---|
| 3285 | /* send initial packet */ |
---|
[9034ba0] | 3286 | switch (wcm->direction) { |
---|
| 3287 | case YAHOO_WEBCAM_DOWNLOAD: |
---|
| 3288 | data = strdup("<REQIMG>"); |
---|
| 3289 | break; |
---|
| 3290 | case YAHOO_WEBCAM_UPLOAD: |
---|
| 3291 | data = strdup("<SNDIMG>"); |
---|
| 3292 | break; |
---|
| 3293 | default: |
---|
| 3294 | return; |
---|
[b7d3cc34] | 3295 | } |
---|
| 3296 | yahoo_add_to_send_queue(yid, data, strlen(data)); |
---|
| 3297 | FREE(data); |
---|
| 3298 | |
---|
| 3299 | /* send data */ |
---|
[9034ba0] | 3300 | switch (wcm->direction) { |
---|
| 3301 | case YAHOO_WEBCAM_DOWNLOAD: |
---|
| 3302 | header_len = 8; |
---|
| 3303 | data = strdup("a=2\r\nc=us\r\ne=21\r\nu="); |
---|
| 3304 | data = y_string_append(data, yd->user); |
---|
| 3305 | data = y_string_append(data, "\r\nt="); |
---|
| 3306 | data = y_string_append(data, wcm->key); |
---|
| 3307 | data = y_string_append(data, "\r\ni="); |
---|
| 3308 | data = y_string_append(data, wcm->my_ip); |
---|
| 3309 | data = y_string_append(data, "\r\ng="); |
---|
| 3310 | data = y_string_append(data, wcm->user); |
---|
| 3311 | data = y_string_append(data, "\r\no=w-2-5-1\r\np="); |
---|
| 3312 | snprintf(conn_type, sizeof(conn_type), "%d", wcm->conn_type); |
---|
| 3313 | data = y_string_append(data, conn_type); |
---|
| 3314 | data = y_string_append(data, "\r\n"); |
---|
| 3315 | break; |
---|
| 3316 | case YAHOO_WEBCAM_UPLOAD: |
---|
| 3317 | header_len = 13; |
---|
| 3318 | data = strdup("a=2\r\nc=us\r\nu="); |
---|
| 3319 | data = y_string_append(data, yd->user); |
---|
| 3320 | data = y_string_append(data, "\r\nt="); |
---|
| 3321 | data = y_string_append(data, wcm->key); |
---|
| 3322 | data = y_string_append(data, "\r\ni="); |
---|
| 3323 | data = y_string_append(data, wcm->my_ip); |
---|
| 3324 | data = y_string_append(data, "\r\no=w-2-5-1\r\np="); |
---|
| 3325 | snprintf(conn_type, sizeof(conn_type), "%d", wcm->conn_type); |
---|
| 3326 | data = y_string_append(data, conn_type); |
---|
| 3327 | data = y_string_append(data, "\r\nb="); |
---|
| 3328 | data = y_string_append(data, wcm->description); |
---|
| 3329 | data = y_string_append(data, "\r\n"); |
---|
| 3330 | break; |
---|
[b7d3cc34] | 3331 | } |
---|
| 3332 | |
---|
| 3333 | len = strlen(data); |
---|
| 3334 | packet = y_new0(char, header_len + len); |
---|
| 3335 | packet[pos++] = header_len; |
---|
| 3336 | packet[pos++] = 0; |
---|
[9034ba0] | 3337 | switch (wcm->direction) { |
---|
| 3338 | case YAHOO_WEBCAM_DOWNLOAD: |
---|
| 3339 | packet[pos++] = 1; |
---|
| 3340 | packet[pos++] = 0; |
---|
| 3341 | break; |
---|
| 3342 | case YAHOO_WEBCAM_UPLOAD: |
---|
| 3343 | packet[pos++] = 5; |
---|
| 3344 | packet[pos++] = 0; |
---|
| 3345 | break; |
---|
[b7d3cc34] | 3346 | } |
---|
| 3347 | |
---|
| 3348 | pos += yahoo_put32(packet + pos, len); |
---|
[9034ba0] | 3349 | if (wcm->direction == YAHOO_WEBCAM_UPLOAD) { |
---|
[b7d3cc34] | 3350 | memcpy(packet + pos, magic_nr, sizeof(magic_nr)); |
---|
| 3351 | pos += sizeof(magic_nr); |
---|
| 3352 | } |
---|
| 3353 | memcpy(packet + pos, data, len); |
---|
| 3354 | yahoo_add_to_send_queue(yid, packet, header_len + len); |
---|
| 3355 | FREE(packet); |
---|
| 3356 | FREE(data); |
---|
| 3357 | |
---|
[9034ba0] | 3358 | yid->read_tag = |
---|
| 3359 | YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, |
---|
| 3360 | yid->fd, YAHOO_INPUT_READ, yid); |
---|
[b7d3cc34] | 3361 | } |
---|
| 3362 | |
---|
| 3363 | static void yahoo_webcam_connect(struct yahoo_input_data *y) |
---|
| 3364 | { |
---|
| 3365 | struct yahoo_webcam *wcm = y->wcm; |
---|
| 3366 | struct yahoo_input_data *yid; |
---|
| 3367 | |
---|
| 3368 | if (!wcm || !wcm->server || !wcm->key) |
---|
| 3369 | return; |
---|
| 3370 | |
---|
| 3371 | yid = y_new0(struct yahoo_input_data, 1); |
---|
| 3372 | yid->type = YAHOO_CONNECTION_WEBCAM; |
---|
| 3373 | yid->yd = y->yd; |
---|
| 3374 | |
---|
| 3375 | /* copy webcam data to new connection */ |
---|
| 3376 | yid->wcm = y->wcm; |
---|
| 3377 | y->wcm = NULL; |
---|
| 3378 | |
---|
| 3379 | yid->wcd = y_new0(struct yahoo_webcam_data, 1); |
---|
| 3380 | |
---|
| 3381 | LOG(("Connecting to: %s:%d", wcm->server, wcm->port)); |
---|
[9034ba0] | 3382 | YAHOO_CALLBACK(ext_yahoo_connect_async) (y->yd->client_id, wcm->server, |
---|
| 3383 | wcm->port, _yahoo_webcam_connected, yid, 0); |
---|
[b7d3cc34] | 3384 | |
---|
| 3385 | } |
---|
| 3386 | |
---|
[9034ba0] | 3387 | static void yahoo_process_webcam_master_connection(struct yahoo_input_data *yid, |
---|
| 3388 | int over) |
---|
[b7d3cc34] | 3389 | { |
---|
[9034ba0] | 3390 | char *server; |
---|
[b7d3cc34] | 3391 | struct yahoo_server_settings *yss; |
---|
| 3392 | |
---|
[c36f73b] | 3393 | if (over) |
---|
[b7d3cc34] | 3394 | return; |
---|
| 3395 | |
---|
| 3396 | server = yahoo_getwebcam_master(yid); |
---|
| 3397 | |
---|
[9034ba0] | 3398 | if (server) { |
---|
[b7d3cc34] | 3399 | yss = yid->yd->server_settings; |
---|
| 3400 | yid->wcm->server = strdup(server); |
---|
| 3401 | yid->wcm->port = yss->webcam_port; |
---|
| 3402 | yid->wcm->conn_type = yss->conn_type; |
---|
| 3403 | yid->wcm->my_ip = strdup(yss->local_host); |
---|
| 3404 | if (yid->wcm->direction == YAHOO_WEBCAM_UPLOAD) |
---|
| 3405 | yid->wcm->description = strdup(yss->webcam_description); |
---|
| 3406 | yahoo_webcam_connect(yid); |
---|
| 3407 | FREE(server); |
---|
| 3408 | } |
---|
| 3409 | } |
---|
| 3410 | |
---|
[9034ba0] | 3411 | static void yahoo_process_webcam_connection(struct yahoo_input_data *yid, |
---|
| 3412 | int over) |
---|
[b7d3cc34] | 3413 | { |
---|
| 3414 | int id = yid->yd->client_id; |
---|
[9034ba0] | 3415 | void *fd = yid->fd; |
---|
[b7d3cc34] | 3416 | |
---|
[c36f73b] | 3417 | if (over) |
---|
[b7d3cc34] | 3418 | return; |
---|
| 3419 | |
---|
| 3420 | /* as long as we still have packets available keep processing them */ |
---|
[9034ba0] | 3421 | while (find_input_by_id_and_fd(id, fd) |
---|
| 3422 | && yahoo_get_webcam_data(yid) == 1) ; |
---|
| 3423 | } |
---|
| 3424 | |
---|
| 3425 | static void (*yahoo_process_connection[]) (struct yahoo_input_data *, |
---|
| 3426 | int over) = { |
---|
| 3427 | yahoo_process_pager_connection, yahoo_process_ft_connection, |
---|
[509cf60] | 3428 | NULL, /*yahoo_process_yab_connection, */ |
---|
[9034ba0] | 3429 | yahoo_process_webcam_master_connection, |
---|
| 3430 | yahoo_process_webcam_connection, |
---|
| 3431 | yahoo_process_chatcat_connection, |
---|
| 3432 | yahoo_process_search_connection}; |
---|
[b7d3cc34] | 3433 | |
---|
[9034ba0] | 3434 | int yahoo_read_ready(int id, void *fd, void *data) |
---|
[b7d3cc34] | 3435 | { |
---|
| 3436 | struct yahoo_input_data *yid = data; |
---|
| 3437 | char buf[1024]; |
---|
| 3438 | int len; |
---|
| 3439 | |
---|
[9034ba0] | 3440 | LOG(("read callback: id=%d fd=%p data=%p", id, fd, data)); |
---|
[c36f73b] | 3441 | if (!yid) |
---|
[b7d3cc34] | 3442 | return -2; |
---|
| 3443 | |
---|
| 3444 | do { |
---|
[9034ba0] | 3445 | len = YAHOO_CALLBACK(ext_yahoo_read) (fd, buf, sizeof(buf)); |
---|
[c36f73b] | 3446 | } while (len == -1 && errno == EINTR); |
---|
[b7d3cc34] | 3447 | |
---|
[9034ba0] | 3448 | if (len == -1 && (errno == EAGAIN || errno == EINTR)) /* we'll try again later */ |
---|
[b7d3cc34] | 3449 | return 1; |
---|
| 3450 | |
---|
| 3451 | if (len <= 0) { |
---|
| 3452 | int e = errno; |
---|
| 3453 | DEBUG_MSG(("len == %d (<= 0)", len)); |
---|
| 3454 | |
---|
[c36f73b] | 3455 | if (yid->type == YAHOO_CONNECTION_PAGER) { |
---|
[9034ba0] | 3456 | YAHOO_CALLBACK(ext_yahoo_login_response) (yid->yd-> |
---|
| 3457 | client_id, YAHOO_LOGIN_SOCK, NULL); |
---|
[b7d3cc34] | 3458 | } |
---|
| 3459 | |
---|
[9034ba0] | 3460 | yahoo_process_connection[yid->type] (yid, 1); |
---|
[b7d3cc34] | 3461 | yahoo_input_close(yid); |
---|
| 3462 | |
---|
| 3463 | /* no need to return an error, because we've already fixed it */ |
---|
[c36f73b] | 3464 | if (len == 0) |
---|
[b7d3cc34] | 3465 | return 1; |
---|
| 3466 | |
---|
[c36f73b] | 3467 | errno = e; |
---|
[b7d3cc34] | 3468 | LOG(("read error: %s", strerror(errno))); |
---|
| 3469 | return -1; |
---|
| 3470 | } |
---|
| 3471 | |
---|
[9034ba0] | 3472 | yid->rxqueue = |
---|
| 3473 | y_renew(unsigned char, yid->rxqueue, len + yid->rxlen + 1); |
---|
[b7d3cc34] | 3474 | memcpy(yid->rxqueue + yid->rxlen, buf, len); |
---|
| 3475 | yid->rxlen += len; |
---|
[9034ba0] | 3476 | yid->rxqueue[yid->rxlen] = 0; |
---|
[b7d3cc34] | 3477 | |
---|
[9034ba0] | 3478 | yahoo_process_connection[yid->type] (yid, 0); |
---|
[b7d3cc34] | 3479 | |
---|
| 3480 | return len; |
---|
| 3481 | } |
---|
| 3482 | |
---|
| 3483 | int yahoo_init_with_attributes(const char *username, const char *password, ...) |
---|
| 3484 | { |
---|
| 3485 | va_list ap; |
---|
| 3486 | struct yahoo_data *yd; |
---|
| 3487 | |
---|
| 3488 | yd = y_new0(struct yahoo_data, 1); |
---|
| 3489 | |
---|
[c36f73b] | 3490 | if (!yd) |
---|
[b7d3cc34] | 3491 | return 0; |
---|
| 3492 | |
---|
| 3493 | yd->user = strdup(username); |
---|
| 3494 | yd->password = strdup(password); |
---|
| 3495 | |
---|
| 3496 | yd->initial_status = -1; |
---|
| 3497 | yd->current_status = -1; |
---|
| 3498 | |
---|
| 3499 | yd->client_id = ++last_id; |
---|
| 3500 | |
---|
| 3501 | add_to_list(yd); |
---|
| 3502 | |
---|
| 3503 | va_start(ap, password); |
---|
| 3504 | yd->server_settings = _yahoo_assign_server_settings(ap); |
---|
| 3505 | va_end(ap); |
---|
| 3506 | |
---|
| 3507 | return yd->client_id; |
---|
| 3508 | } |
---|
| 3509 | |
---|
| 3510 | int yahoo_init(const char *username, const char *password) |
---|
| 3511 | { |
---|
| 3512 | return yahoo_init_with_attributes(username, password, NULL); |
---|
| 3513 | } |
---|
| 3514 | |
---|
[9034ba0] | 3515 | static void yahoo_connected(void *fd, int error, void *data) |
---|
[b7d3cc34] | 3516 | { |
---|
| 3517 | struct connect_callback_data *ccd = data; |
---|
| 3518 | struct yahoo_data *yd = ccd->yd; |
---|
| 3519 | struct yahoo_packet *pkt; |
---|
| 3520 | struct yahoo_input_data *yid; |
---|
| 3521 | struct yahoo_server_settings *yss = yd->server_settings; |
---|
| 3522 | |
---|
[c36f73b] | 3523 | if (error) { |
---|
[9034ba0] | 3524 | int tag; |
---|
[c36f73b] | 3525 | if (fallback_ports[ccd->i]) { |
---|
[9034ba0] | 3526 | char *host = yss->pager_host; |
---|
| 3527 | |
---|
| 3528 | if (!host) |
---|
| 3529 | host = yss->pager_host_list[ccd->server_i]; |
---|
| 3530 | |
---|
[b7d3cc34] | 3531 | yss->pager_port = fallback_ports[ccd->i++]; |
---|
[9034ba0] | 3532 | tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd-> |
---|
| 3533 | client_id, host, yss->pager_port, |
---|
| 3534 | yahoo_connected, ccd, 0); |
---|
[b7d3cc34] | 3535 | |
---|
[c36f73b] | 3536 | if (tag > 0) |
---|
| 3537 | ccd->tag = tag; |
---|
[9034ba0] | 3538 | } else if (yss->pager_host_list |
---|
| 3539 | && yss->pager_host_list[ccd->server_i]) { |
---|
| 3540 | |
---|
| 3541 | /* Get back to the default port */ |
---|
| 3542 | yss->pager_port = pager_port; |
---|
| 3543 | ccd->server_i++; |
---|
| 3544 | LOG(("Fallback: Connecting to %s:%d", yss->pager_host_list[ccd->server_i], yss->pager_port)); |
---|
| 3545 | |
---|
| 3546 | ccd->i = 0; |
---|
| 3547 | tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id, |
---|
| 3548 | yss->pager_host_list[ccd->server_i], yss->pager_port, |
---|
| 3549 | yahoo_connected, ccd, 0); |
---|
[b7d3cc34] | 3550 | } else { |
---|
| 3551 | FREE(ccd); |
---|
[9034ba0] | 3552 | YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id, |
---|
| 3553 | YAHOO_LOGIN_SOCK, NULL); |
---|
[b7d3cc34] | 3554 | } |
---|
| 3555 | return; |
---|
| 3556 | } |
---|
| 3557 | |
---|
| 3558 | FREE(ccd); |
---|
| 3559 | |
---|
[9034ba0] | 3560 | /* fd == NULL && error == 0 means connect was cancelled */ |
---|
| 3561 | if (!fd) |
---|
[b7d3cc34] | 3562 | return; |
---|
| 3563 | |
---|
[9034ba0] | 3564 | pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YPACKET_STATUS_DEFAULT, |
---|
| 3565 | yd->session_id); |
---|
[b7d3cc34] | 3566 | NOTICE(("Sending initial packet")); |
---|
| 3567 | |
---|
| 3568 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 3569 | |
---|
[9034ba0] | 3570 | yid = find_input_by_id_and_type(yd->client_id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3571 | yid->fd = fd; |
---|
| 3572 | |
---|
| 3573 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3574 | |
---|
| 3575 | yahoo_packet_free(pkt); |
---|
| 3576 | |
---|
[9034ba0] | 3577 | yid->read_tag = |
---|
| 3578 | YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, |
---|
| 3579 | yid->fd, YAHOO_INPUT_READ, yid); |
---|
[b7d3cc34] | 3580 | } |
---|
| 3581 | |
---|
[9034ba0] | 3582 | void *yahoo_get_fd(int id) |
---|
[b7d3cc34] | 3583 | { |
---|
[9034ba0] | 3584 | struct yahoo_input_data *yid = |
---|
| 3585 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[c36f73b] | 3586 | if (!yid) |
---|
[b7d3cc34] | 3587 | return 0; |
---|
| 3588 | else |
---|
| 3589 | return yid->fd; |
---|
| 3590 | } |
---|
| 3591 | |
---|
[3cd37d7] | 3592 | #if 0 |
---|
[9034ba0] | 3593 | void yahoo_send_buzz(int id, const char *from, const char *who) |
---|
[b7d3cc34] | 3594 | { |
---|
[9034ba0] | 3595 | yahoo_send_im(id, from, who, "<ding>", 1, 0); |
---|
| 3596 | } |
---|
[3cd37d7] | 3597 | #endif |
---|
[9034ba0] | 3598 | |
---|
| 3599 | void yahoo_send_im(int id, const char *from, const char *who, const char *what, |
---|
| 3600 | int utf8, int picture) |
---|
| 3601 | { |
---|
| 3602 | struct yahoo_input_data *yid = |
---|
| 3603 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3604 | struct yahoo_packet *pkt = NULL; |
---|
| 3605 | struct yahoo_data *yd; |
---|
[cfc8d58] | 3606 | char pic_str[10]; |
---|
[b7d3cc34] | 3607 | |
---|
[c36f73b] | 3608 | if (!yid) |
---|
[b7d3cc34] | 3609 | return; |
---|
| 3610 | |
---|
| 3611 | yd = yid->yd; |
---|
| 3612 | |
---|
[25c4c78] | 3613 | pkt = yahoo_packet_new(YAHOO_SERVICE_MESSAGE, (enum ypacket_status) YAHOO_STATUS_OFFLINE, |
---|
[9034ba0] | 3614 | yd->session_id); |
---|
[b7d3cc34] | 3615 | |
---|
[cfc8d58] | 3616 | snprintf(pic_str, sizeof(pic_str), "%d", picture); |
---|
[9034ba0] | 3617 | |
---|
[c36f73b] | 3618 | if (from && strcmp(from, yd->user)) |
---|
[b7d3cc34] | 3619 | yahoo_packet_hash(pkt, 0, yd->user); |
---|
[9034ba0] | 3620 | yahoo_packet_hash(pkt, 1, from ? from : yd->user); |
---|
[b7d3cc34] | 3621 | yahoo_packet_hash(pkt, 5, who); |
---|
| 3622 | yahoo_packet_hash(pkt, 14, what); |
---|
| 3623 | |
---|
[c36f73b] | 3624 | if (utf8) |
---|
[b7d3cc34] | 3625 | yahoo_packet_hash(pkt, 97, "1"); |
---|
| 3626 | |
---|
| 3627 | yahoo_packet_hash(pkt, 63, ";0"); /* imvironment name; or ;0 */ |
---|
| 3628 | yahoo_packet_hash(pkt, 64, "0"); |
---|
[cfc8d58] | 3629 | yahoo_packet_hash(pkt, 206, pic_str); |
---|
[b7d3cc34] | 3630 | |
---|
| 3631 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3632 | |
---|
| 3633 | yahoo_packet_free(pkt); |
---|
| 3634 | } |
---|
| 3635 | |
---|
| 3636 | void yahoo_send_typing(int id, const char *from, const char *who, int typ) |
---|
| 3637 | { |
---|
[9034ba0] | 3638 | struct yahoo_input_data *yid = |
---|
| 3639 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3640 | struct yahoo_data *yd; |
---|
| 3641 | struct yahoo_packet *pkt = NULL; |
---|
[c36f73b] | 3642 | if (!yid) |
---|
[b7d3cc34] | 3643 | return; |
---|
| 3644 | |
---|
| 3645 | yd = yid->yd; |
---|
[9034ba0] | 3646 | pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YPACKET_STATUS_NOTIFY, |
---|
| 3647 | yd->session_id); |
---|
[b7d3cc34] | 3648 | |
---|
| 3649 | yahoo_packet_hash(pkt, 5, who); |
---|
[9034ba0] | 3650 | yahoo_packet_hash(pkt, 1, from ? from : yd->user); |
---|
[b7d3cc34] | 3651 | yahoo_packet_hash(pkt, 14, " "); |
---|
| 3652 | yahoo_packet_hash(pkt, 13, typ ? "1" : "0"); |
---|
| 3653 | yahoo_packet_hash(pkt, 49, "TYPING"); |
---|
| 3654 | |
---|
| 3655 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3656 | |
---|
| 3657 | yahoo_packet_free(pkt); |
---|
| 3658 | } |
---|
| 3659 | |
---|
| 3660 | void yahoo_set_away(int id, enum yahoo_status state, const char *msg, int away) |
---|
| 3661 | { |
---|
[9034ba0] | 3662 | struct yahoo_input_data *yid = |
---|
| 3663 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3664 | struct yahoo_data *yd; |
---|
| 3665 | struct yahoo_packet *pkt = NULL; |
---|
[7ea8697] | 3666 | int old_status; |
---|
[b7d3cc34] | 3667 | char s[4]; |
---|
| 3668 | |
---|
[c36f73b] | 3669 | if (!yid) |
---|
[b7d3cc34] | 3670 | return; |
---|
| 3671 | |
---|
| 3672 | yd = yid->yd; |
---|
[9034ba0] | 3673 | |
---|
[7ea8697] | 3674 | old_status = yd->current_status; |
---|
[4049061] | 3675 | yd->current_status = state; |
---|
[b7d3cc34] | 3676 | |
---|
[7ea8697] | 3677 | /* Thank you libpurple :) */ |
---|
| 3678 | if (yd->current_status == YAHOO_STATUS_INVISIBLE) { |
---|
[9034ba0] | 3679 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, |
---|
[25c4c78] | 3680 | (enum ypacket_status) YAHOO_STATUS_AVAILABLE, 0); |
---|
[7ea8697] | 3681 | yahoo_packet_hash(pkt, 13, "2"); |
---|
| 3682 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3683 | yahoo_packet_free(pkt); |
---|
| 3684 | |
---|
| 3685 | return; |
---|
| 3686 | } |
---|
| 3687 | |
---|
[9034ba0] | 3688 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, |
---|
| 3689 | yd->current_status, yd->session_id); |
---|
[7ea8697] | 3690 | snprintf(s, sizeof(s), "%d", yd->current_status); |
---|
| 3691 | yahoo_packet_hash(pkt, 10, s); |
---|
[be915f5] | 3692 | yahoo_packet_hash(pkt, 19, msg && state == YAHOO_STATUS_CUSTOM ? msg : ""); |
---|
[7ea8697] | 3693 | yahoo_packet_hash(pkt, 47, (away == 2)? "2": (away) ?"1":"0"); |
---|
[b7d3cc34] | 3694 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3695 | yahoo_packet_free(pkt); |
---|
[7ea8697] | 3696 | |
---|
[c36f73b] | 3697 | if (old_status == YAHOO_STATUS_INVISIBLE) { |
---|
[9034ba0] | 3698 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, |
---|
[25c4c78] | 3699 | (enum ypacket_status) YAHOO_STATUS_AVAILABLE, 0); |
---|
[7ea8697] | 3700 | yahoo_packet_hash(pkt, 13, "1"); |
---|
| 3701 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3702 | yahoo_packet_free(pkt); |
---|
| 3703 | } |
---|
[b7d3cc34] | 3704 | } |
---|
| 3705 | |
---|
| 3706 | void yahoo_logoff(int id) |
---|
| 3707 | { |
---|
[9034ba0] | 3708 | struct yahoo_input_data *yid = |
---|
| 3709 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3710 | struct yahoo_data *yd; |
---|
| 3711 | struct yahoo_packet *pkt = NULL; |
---|
| 3712 | |
---|
[c36f73b] | 3713 | if (!yid) |
---|
[b7d3cc34] | 3714 | return; |
---|
| 3715 | yd = yid->yd; |
---|
| 3716 | |
---|
| 3717 | LOG(("yahoo_logoff: current status: %d", yd->current_status)); |
---|
| 3718 | |
---|
[c36f73b] | 3719 | if (yd->current_status != -1 && 0) { |
---|
[99c8f13] | 3720 | /* Meh. Don't send this. The event handlers are not going to |
---|
| 3721 | get to do this so it'll just leak memory. And the TCP |
---|
| 3722 | connection reset will hopefully be clear enough. */ |
---|
[9034ba0] | 3723 | pkt = yahoo_packet_new(YAHOO_SERVICE_LOGOFF, |
---|
| 3724 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 3725 | yd->current_status = -1; |
---|
| 3726 | |
---|
| 3727 | if (pkt) { |
---|
| 3728 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3729 | yahoo_packet_free(pkt); |
---|
| 3730 | } |
---|
| 3731 | } |
---|
| 3732 | |
---|
[9034ba0] | 3733 | /* do { |
---|
[b7d3cc34] | 3734 | yahoo_input_close(yid); |
---|
[9034ba0] | 3735 | } while((yid = find_input_by_id(id)));*/ |
---|
| 3736 | |
---|
[b7d3cc34] | 3737 | } |
---|
| 3738 | |
---|
[3cd37d7] | 3739 | #if 0 |
---|
[b7d3cc34] | 3740 | void yahoo_get_list(int id) |
---|
| 3741 | { |
---|
[9034ba0] | 3742 | struct yahoo_input_data *yid = |
---|
| 3743 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3744 | struct yahoo_data *yd; |
---|
| 3745 | struct yahoo_packet *pkt = NULL; |
---|
| 3746 | |
---|
[c36f73b] | 3747 | if (!yid) |
---|
[b7d3cc34] | 3748 | return; |
---|
| 3749 | yd = yid->yd; |
---|
| 3750 | |
---|
[9034ba0] | 3751 | pkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YPACKET_STATUS_DEFAULT, |
---|
| 3752 | yd->session_id); |
---|
[b7d3cc34] | 3753 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 3754 | if (pkt) { |
---|
| 3755 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3756 | yahoo_packet_free(pkt); |
---|
| 3757 | } |
---|
| 3758 | } |
---|
[3cd37d7] | 3759 | #endif |
---|
[b7d3cc34] | 3760 | |
---|
[9034ba0] | 3761 | static void _yahoo_http_connected(int id, void *fd, int error, void *data) |
---|
[b7d3cc34] | 3762 | { |
---|
| 3763 | struct yahoo_input_data *yid = data; |
---|
[9034ba0] | 3764 | if (fd == NULL || error) { |
---|
[b7d3cc34] | 3765 | inputs = y_list_remove(inputs, yid); |
---|
| 3766 | FREE(yid); |
---|
| 3767 | return; |
---|
| 3768 | } |
---|
| 3769 | |
---|
| 3770 | yid->fd = fd; |
---|
[9034ba0] | 3771 | yid->read_tag = |
---|
| 3772 | YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd, |
---|
| 3773 | YAHOO_INPUT_READ, yid); |
---|
[b7d3cc34] | 3774 | } |
---|
| 3775 | |
---|
[509cf60] | 3776 | #if 0 |
---|
[9034ba0] | 3777 | /* FIXME Get address book from address.yahoo.com instead */ |
---|
[b7d3cc34] | 3778 | void yahoo_get_yab(int id) |
---|
| 3779 | { |
---|
| 3780 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
| 3781 | struct yahoo_input_data *yid; |
---|
| 3782 | char url[1024]; |
---|
[9034ba0] | 3783 | char buff[2048]; |
---|
[b7d3cc34] | 3784 | |
---|
[c36f73b] | 3785 | if (!yd) |
---|
[b7d3cc34] | 3786 | return; |
---|
| 3787 | |
---|
| 3788 | yid = y_new0(struct yahoo_input_data, 1); |
---|
| 3789 | yid->yd = yd; |
---|
| 3790 | yid->type = YAHOO_CONNECTION_YAB; |
---|
| 3791 | |
---|
[9034ba0] | 3792 | LOG(("Sending request for Address Book")); |
---|
[b7d3cc34] | 3793 | |
---|
[9034ba0] | 3794 | snprintf(url, 1024, |
---|
| 3795 | "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us" |
---|
| 3796 | "&diffs=1&t=0&tags=short&rt=0&prog-ver=8.1.0.249&useutf8=1&legenc=codepage-1252"); |
---|
| 3797 | |
---|
| 3798 | snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); |
---|
[b7d3cc34] | 3799 | |
---|
| 3800 | inputs = y_list_prepend(inputs, yid); |
---|
| 3801 | |
---|
[9034ba0] | 3802 | yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, |
---|
| 3803 | _yahoo_http_connected, yid); |
---|
| 3804 | } |
---|
| 3805 | |
---|
| 3806 | struct yahoo_post_data { |
---|
| 3807 | struct yahoo_input_data *yid; |
---|
| 3808 | char *data; |
---|
| 3809 | }; |
---|
| 3810 | |
---|
| 3811 | static void _yahoo_http_post_connected(int id, void *fd, int error, void *data) |
---|
| 3812 | { |
---|
| 3813 | struct yahoo_post_data *yad = data; |
---|
| 3814 | struct yahoo_input_data *yid = yad->yid; |
---|
| 3815 | char *buff = yad->data; |
---|
| 3816 | |
---|
| 3817 | if (!fd) { |
---|
| 3818 | inputs = y_list_remove(inputs, yid); |
---|
| 3819 | FREE(yid); |
---|
| 3820 | return; |
---|
| 3821 | } |
---|
| 3822 | |
---|
| 3823 | YAHOO_CALLBACK(ext_yahoo_write) (fd, buff, strlen(buff)); |
---|
| 3824 | |
---|
| 3825 | yid->fd = fd; |
---|
| 3826 | yid->read_tag = |
---|
| 3827 | YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd, |
---|
| 3828 | YAHOO_INPUT_READ, yid); |
---|
| 3829 | |
---|
| 3830 | FREE(buff); |
---|
| 3831 | FREE(yad); |
---|
[b7d3cc34] | 3832 | } |
---|
| 3833 | |
---|
[9034ba0] | 3834 | /* FIXME This is also likely affected */ |
---|
[c36f73b] | 3835 | void yahoo_set_yab(int id, struct yab *yab) |
---|
[b7d3cc34] | 3836 | { |
---|
[9034ba0] | 3837 | struct yahoo_post_data *yad = y_new0(struct yahoo_post_data, 1); |
---|
[b7d3cc34] | 3838 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
| 3839 | struct yahoo_input_data *yid; |
---|
| 3840 | char url[1024]; |
---|
| 3841 | char buff[1024]; |
---|
[9034ba0] | 3842 | char post[1024]; |
---|
| 3843 | int size = 0; |
---|
[b7d3cc34] | 3844 | |
---|
[c36f73b] | 3845 | if (!yd) |
---|
[b7d3cc34] | 3846 | return; |
---|
| 3847 | |
---|
| 3848 | yid = y_new0(struct yahoo_input_data, 1); |
---|
| 3849 | yid->type = YAHOO_CONNECTION_YAB; |
---|
| 3850 | yid->yd = yd; |
---|
| 3851 | |
---|
[9034ba0] | 3852 | if(yab->yid) |
---|
| 3853 | size = snprintf(post, sizeof(post), "<?xml version=\"1.0\" encoding=\"utf-8\"?>" |
---|
| 3854 | "<ab k=\"%s\" cc=\"%d\">" |
---|
| 3855 | "<ct id=\"%d\" e=\"1\" yi=\"%s\" nn=\"%s\" />" |
---|
| 3856 | "</ab>", yd->user, 9, yab->yid, /* Don't know why */ |
---|
| 3857 | yab->id, yab->nname?yab->nname:""); |
---|
| 3858 | else |
---|
| 3859 | size = snprintf(post, sizeof(post), "<?xml version=\"1.0\" encoding=\"utf-8\"?>" |
---|
| 3860 | "<ab k=\"%s\" cc=\"%d\">" |
---|
| 3861 | "<ct a=\"1\" yi=\"%s\" nn=\"%s\" />" |
---|
| 3862 | "</ab>", yd->user, 1, /* Don't know why */ |
---|
| 3863 | yab->id, yab->nname?yab->nname:""); |
---|
| 3864 | |
---|
| 3865 | yad->yid = yid; |
---|
| 3866 | yad->data = strdup(post); |
---|
| 3867 | |
---|
| 3868 | strcpy(url, "http://address.yahoo.com/yab/us?v=XM&prog=ymsgr&.intl=us" |
---|
| 3869 | "&sync=1&tags=short&noclear=1&useutf8=1&legenc=codepage-1252"); |
---|
| 3870 | |
---|
| 3871 | snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); |
---|
[b7d3cc34] | 3872 | |
---|
| 3873 | inputs = y_list_prepend(inputs, yid); |
---|
| 3874 | |
---|
[9034ba0] | 3875 | yahoo_http_post(yid->yd->client_id, url, buff, size, |
---|
| 3876 | _yahoo_http_post_connected, yad); |
---|
[b7d3cc34] | 3877 | } |
---|
| 3878 | |
---|
[c36f73b] | 3879 | void yahoo_set_identity_status(int id, const char *identity, int active) |
---|
[b7d3cc34] | 3880 | { |
---|
[9034ba0] | 3881 | struct yahoo_input_data *yid = |
---|
| 3882 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3883 | struct yahoo_data *yd; |
---|
| 3884 | struct yahoo_packet *pkt = NULL; |
---|
| 3885 | |
---|
[c36f73b] | 3886 | if (!yid) |
---|
[b7d3cc34] | 3887 | return; |
---|
| 3888 | yd = yid->yd; |
---|
| 3889 | |
---|
[9034ba0] | 3890 | pkt = yahoo_packet_new(active ? YAHOO_SERVICE_IDACT : |
---|
| 3891 | YAHOO_SERVICE_IDDEACT, YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 3892 | yahoo_packet_hash(pkt, 3, identity); |
---|
| 3893 | if (pkt) { |
---|
| 3894 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3895 | yahoo_packet_free(pkt); |
---|
| 3896 | } |
---|
| 3897 | } |
---|
| 3898 | |
---|
| 3899 | void yahoo_refresh(int id) |
---|
| 3900 | { |
---|
[9034ba0] | 3901 | struct yahoo_input_data *yid = |
---|
| 3902 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3903 | struct yahoo_data *yd; |
---|
| 3904 | struct yahoo_packet *pkt = NULL; |
---|
| 3905 | |
---|
[c36f73b] | 3906 | if (!yid) |
---|
[b7d3cc34] | 3907 | return; |
---|
| 3908 | yd = yid->yd; |
---|
| 3909 | |
---|
[9034ba0] | 3910 | pkt = yahoo_packet_new(YAHOO_SERVICE_USERSTAT, YPACKET_STATUS_DEFAULT, |
---|
| 3911 | yd->session_id); |
---|
[b7d3cc34] | 3912 | if (pkt) { |
---|
| 3913 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3914 | yahoo_packet_free(pkt); |
---|
| 3915 | } |
---|
| 3916 | } |
---|
[3cd37d7] | 3917 | #endif |
---|
[b7d3cc34] | 3918 | |
---|
| 3919 | void yahoo_keepalive(int id) |
---|
| 3920 | { |
---|
[9034ba0] | 3921 | struct yahoo_input_data *yid = |
---|
| 3922 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3923 | struct yahoo_data *yd; |
---|
[c36f73b] | 3924 | struct yahoo_packet *pkt = NULL; |
---|
| 3925 | if (!yid) |
---|
[b7d3cc34] | 3926 | return; |
---|
| 3927 | yd = yid->yd; |
---|
| 3928 | |
---|
[9034ba0] | 3929 | pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YPACKET_STATUS_DEFAULT, |
---|
| 3930 | yd->session_id); |
---|
[b7d3cc34] | 3931 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3932 | yahoo_packet_free(pkt); |
---|
| 3933 | } |
---|
| 3934 | |
---|
[3cd37d7] | 3935 | #if 0 |
---|
[9034ba0] | 3936 | void yahoo_chat_keepalive(int id) |
---|
[b7d3cc34] | 3937 | { |
---|
[9034ba0] | 3938 | struct yahoo_input_data *yid = |
---|
| 3939 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3940 | struct yahoo_data *yd; |
---|
| 3941 | struct yahoo_packet *pkt = NULL; |
---|
| 3942 | |
---|
| 3943 | if (!yid) |
---|
[9034ba0] | 3944 | return; |
---|
[b7d3cc34] | 3945 | |
---|
| 3946 | yd = yid->yd; |
---|
| 3947 | |
---|
[9034ba0] | 3948 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YPACKET_STATUS_DEFAULT, |
---|
| 3949 | yd->session_id); |
---|
| 3950 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3951 | yahoo_packet_free(pkt); |
---|
[b7d3cc34] | 3952 | } |
---|
[3cd37d7] | 3953 | #endif |
---|
[b7d3cc34] | 3954 | |
---|
[9034ba0] | 3955 | void yahoo_add_buddy(int id, const char *who, const char *group, |
---|
| 3956 | const char *msg) |
---|
[b7d3cc34] | 3957 | { |
---|
[9034ba0] | 3958 | struct yahoo_input_data *yid = |
---|
| 3959 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3960 | struct yahoo_data *yd; |
---|
| 3961 | struct yahoo_packet *pkt; |
---|
| 3962 | |
---|
[c36f73b] | 3963 | if (!yid) |
---|
[b7d3cc34] | 3964 | return; |
---|
| 3965 | yd = yid->yd; |
---|
| 3966 | |
---|
| 3967 | if (!yd->logged_in) |
---|
| 3968 | return; |
---|
| 3969 | |
---|
[9034ba0] | 3970 | pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YPACKET_STATUS_DEFAULT, |
---|
| 3971 | yd->session_id); |
---|
| 3972 | if (msg != NULL) /* add message/request "it's me add me" */ |
---|
[cfc8d58] | 3973 | yahoo_packet_hash(pkt, 14, msg); |
---|
[ba16895] | 3974 | else |
---|
[9034ba0] | 3975 | yahoo_packet_hash(pkt, 14, ""); |
---|
[ba16895] | 3976 | yahoo_packet_hash(pkt, 65, group); |
---|
| 3977 | yahoo_packet_hash(pkt, 97, "1"); |
---|
| 3978 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 3979 | yahoo_packet_hash(pkt, 302, "319"); |
---|
| 3980 | yahoo_packet_hash(pkt, 300, "319"); |
---|
| 3981 | yahoo_packet_hash(pkt, 7, who); |
---|
| 3982 | yahoo_packet_hash(pkt, 334, "0"); |
---|
| 3983 | yahoo_packet_hash(pkt, 301, "319"); |
---|
| 3984 | yahoo_packet_hash(pkt, 303, "319"); |
---|
[b7d3cc34] | 3985 | yahoo_send_packet(yid, pkt, 0); |
---|
| 3986 | yahoo_packet_free(pkt); |
---|
| 3987 | } |
---|
| 3988 | |
---|
| 3989 | void yahoo_remove_buddy(int id, const char *who, const char *group) |
---|
| 3990 | { |
---|
[9034ba0] | 3991 | struct yahoo_input_data *yid = |
---|
| 3992 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 3993 | struct yahoo_data *yd; |
---|
| 3994 | struct yahoo_packet *pkt = NULL; |
---|
| 3995 | |
---|
[c36f73b] | 3996 | if (!yid) |
---|
[b7d3cc34] | 3997 | return; |
---|
| 3998 | yd = yid->yd; |
---|
| 3999 | |
---|
[9034ba0] | 4000 | pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YPACKET_STATUS_DEFAULT, |
---|
| 4001 | yd->session_id); |
---|
[b7d3cc34] | 4002 | |
---|
| 4003 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 4004 | yahoo_packet_hash(pkt, 7, who); |
---|
| 4005 | yahoo_packet_hash(pkt, 65, group); |
---|
| 4006 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4007 | yahoo_packet_free(pkt); |
---|
| 4008 | } |
---|
| 4009 | |
---|
[9034ba0] | 4010 | void yahoo_confirm_buddy(int id, const char *who, int reject, const char *msg) |
---|
[b7d3cc34] | 4011 | { |
---|
[9034ba0] | 4012 | struct yahoo_input_data *yid = |
---|
| 4013 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4014 | struct yahoo_data *yd; |
---|
| 4015 | struct yahoo_packet *pkt; |
---|
| 4016 | |
---|
[c36f73b] | 4017 | if (!yid) |
---|
[b7d3cc34] | 4018 | return; |
---|
| 4019 | yd = yid->yd; |
---|
| 4020 | |
---|
| 4021 | if (!yd->logged_in) |
---|
| 4022 | return; |
---|
| 4023 | |
---|
[9034ba0] | 4024 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_AUTHORIZATION, |
---|
| 4025 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 4026 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
[9034ba0] | 4027 | yahoo_packet_hash(pkt, 5, who); |
---|
| 4028 | if (reject) |
---|
| 4029 | yahoo_packet_hash(pkt, 13, "2"); |
---|
| 4030 | else { |
---|
| 4031 | yahoo_packet_hash(pkt, 241, "0"); |
---|
| 4032 | yahoo_packet_hash(pkt, 13, "1"); |
---|
| 4033 | } |
---|
| 4034 | |
---|
| 4035 | yahoo_packet_hash(pkt, 334, "0"); |
---|
| 4036 | |
---|
| 4037 | if (reject) { |
---|
| 4038 | yahoo_packet_hash(pkt, 14, msg ? msg : ""); |
---|
| 4039 | yahoo_packet_hash(pkt, 97, "1"); |
---|
| 4040 | } |
---|
| 4041 | |
---|
[b7d3cc34] | 4042 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4043 | yahoo_packet_free(pkt); |
---|
| 4044 | } |
---|
| 4045 | |
---|
[3cd37d7] | 4046 | #if 0 |
---|
[b7d3cc34] | 4047 | void yahoo_ignore_buddy(int id, const char *who, int unignore) |
---|
| 4048 | { |
---|
[9034ba0] | 4049 | struct yahoo_input_data *yid = |
---|
| 4050 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4051 | struct yahoo_data *yd; |
---|
| 4052 | struct yahoo_packet *pkt; |
---|
| 4053 | |
---|
[c36f73b] | 4054 | if (!yid) |
---|
[b7d3cc34] | 4055 | return; |
---|
| 4056 | yd = yid->yd; |
---|
| 4057 | |
---|
| 4058 | if (!yd->logged_in) |
---|
| 4059 | return; |
---|
| 4060 | |
---|
[9034ba0] | 4061 | pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, |
---|
| 4062 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 4063 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 4064 | yahoo_packet_hash(pkt, 7, who); |
---|
[9034ba0] | 4065 | yahoo_packet_hash(pkt, 13, unignore ? "2" : "1"); |
---|
[b7d3cc34] | 4066 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4067 | yahoo_packet_free(pkt); |
---|
| 4068 | } |
---|
| 4069 | |
---|
[cfc8d58] | 4070 | void yahoo_stealth_buddy(int id, const char *who, int unstealth) |
---|
| 4071 | { |
---|
[9034ba0] | 4072 | struct yahoo_input_data *yid = |
---|
| 4073 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[cfc8d58] | 4074 | struct yahoo_data *yd; |
---|
| 4075 | struct yahoo_packet *pkt; |
---|
| 4076 | |
---|
[c36f73b] | 4077 | if (!yid) |
---|
[cfc8d58] | 4078 | return; |
---|
| 4079 | yd = yid->yd; |
---|
| 4080 | |
---|
| 4081 | if (!yd->logged_in) |
---|
| 4082 | return; |
---|
| 4083 | |
---|
[9034ba0] | 4084 | pkt = yahoo_packet_new(YAHOO_SERVICE_STEALTH_PERM, |
---|
| 4085 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[cfc8d58] | 4086 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 4087 | yahoo_packet_hash(pkt, 7, who); |
---|
[9034ba0] | 4088 | yahoo_packet_hash(pkt, 31, unstealth ? "2" : "1"); |
---|
[cfc8d58] | 4089 | yahoo_packet_hash(pkt, 13, "2"); |
---|
| 4090 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4091 | yahoo_packet_free(pkt); |
---|
| 4092 | } |
---|
[3cd37d7] | 4093 | #endif |
---|
[cfc8d58] | 4094 | |
---|
[9034ba0] | 4095 | void yahoo_change_buddy_group(int id, const char *who, const char *old_group, |
---|
| 4096 | const char *new_group) |
---|
[b7d3cc34] | 4097 | { |
---|
[9034ba0] | 4098 | struct yahoo_input_data *yid = |
---|
| 4099 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4100 | struct yahoo_data *yd; |
---|
| 4101 | struct yahoo_packet *pkt = NULL; |
---|
| 4102 | |
---|
[c36f73b] | 4103 | if (!yid) |
---|
[b7d3cc34] | 4104 | return; |
---|
| 4105 | yd = yid->yd; |
---|
| 4106 | |
---|
[9034ba0] | 4107 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_CHANGE_GROUP, |
---|
| 4108 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 4109 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
[9034ba0] | 4110 | yahoo_packet_hash(pkt, 302, "240"); |
---|
| 4111 | yahoo_packet_hash(pkt, 300, "240"); |
---|
[b7d3cc34] | 4112 | yahoo_packet_hash(pkt, 7, who); |
---|
[9034ba0] | 4113 | yahoo_packet_hash(pkt, 224, old_group); |
---|
| 4114 | yahoo_packet_hash(pkt, 264, new_group); |
---|
| 4115 | yahoo_packet_hash(pkt, 301, "240"); |
---|
| 4116 | yahoo_packet_hash(pkt, 303, "240"); |
---|
[b7d3cc34] | 4117 | |
---|
| 4118 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4119 | yahoo_packet_free(pkt); |
---|
| 4120 | } |
---|
| 4121 | |
---|
[3cd37d7] | 4122 | #if 0 |
---|
[b7d3cc34] | 4123 | void yahoo_group_rename(int id, const char *old_group, const char *new_group) |
---|
| 4124 | { |
---|
[9034ba0] | 4125 | struct yahoo_input_data *yid = |
---|
| 4126 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4127 | struct yahoo_data *yd; |
---|
| 4128 | struct yahoo_packet *pkt = NULL; |
---|
| 4129 | |
---|
[c36f73b] | 4130 | if (!yid) |
---|
[b7d3cc34] | 4131 | return; |
---|
| 4132 | yd = yid->yd; |
---|
| 4133 | |
---|
[9034ba0] | 4134 | pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, |
---|
| 4135 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 4136 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 4137 | yahoo_packet_hash(pkt, 65, old_group); |
---|
| 4138 | yahoo_packet_hash(pkt, 67, new_group); |
---|
| 4139 | |
---|
| 4140 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4141 | yahoo_packet_free(pkt); |
---|
| 4142 | } |
---|
| 4143 | |
---|
[9034ba0] | 4144 | void yahoo_conference_addinvite(int id, const char *from, const char *who, |
---|
| 4145 | const char *room, const YList *members, const char *msg) |
---|
[b7d3cc34] | 4146 | { |
---|
[9034ba0] | 4147 | struct yahoo_input_data *yid = |
---|
| 4148 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4149 | struct yahoo_data *yd; |
---|
| 4150 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4151 | |
---|
[c36f73b] | 4152 | if (!yid) |
---|
[b7d3cc34] | 4153 | return; |
---|
| 4154 | yd = yid->yd; |
---|
| 4155 | |
---|
[9034ba0] | 4156 | pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, |
---|
| 4157 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 4158 | |
---|
[9034ba0] | 4159 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
[b7d3cc34] | 4160 | yahoo_packet_hash(pkt, 51, who); |
---|
| 4161 | yahoo_packet_hash(pkt, 57, room); |
---|
| 4162 | yahoo_packet_hash(pkt, 58, msg); |
---|
| 4163 | yahoo_packet_hash(pkt, 13, "0"); |
---|
[c36f73b] | 4164 | for (; members; members = members->next) { |
---|
[b7d3cc34] | 4165 | yahoo_packet_hash(pkt, 52, (char *)members->data); |
---|
| 4166 | yahoo_packet_hash(pkt, 53, (char *)members->data); |
---|
| 4167 | } |
---|
| 4168 | /* 52, 53 -> other members? */ |
---|
| 4169 | |
---|
| 4170 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4171 | |
---|
| 4172 | yahoo_packet_free(pkt); |
---|
| 4173 | } |
---|
[3cd37d7] | 4174 | #endif |
---|
[b7d3cc34] | 4175 | |
---|
[9034ba0] | 4176 | void yahoo_conference_invite(int id, const char *from, YList *who, |
---|
| 4177 | const char *room, const char *msg) |
---|
[b7d3cc34] | 4178 | { |
---|
[9034ba0] | 4179 | struct yahoo_input_data *yid = |
---|
| 4180 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4181 | struct yahoo_data *yd; |
---|
| 4182 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4183 | |
---|
[c36f73b] | 4184 | if (!yid) |
---|
[b7d3cc34] | 4185 | return; |
---|
| 4186 | yd = yid->yd; |
---|
| 4187 | |
---|
[9034ba0] | 4188 | pkt = yahoo_packet_new(YAHOO_SERVICE_CONFINVITE, YPACKET_STATUS_DEFAULT, |
---|
| 4189 | yd->session_id); |
---|
[b7d3cc34] | 4190 | |
---|
[9034ba0] | 4191 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
[b7d3cc34] | 4192 | yahoo_packet_hash(pkt, 50, yd->user); |
---|
[c36f73b] | 4193 | for (; who; who = who->next) { |
---|
[b7d3cc34] | 4194 | yahoo_packet_hash(pkt, 52, (char *)who->data); |
---|
| 4195 | } |
---|
| 4196 | yahoo_packet_hash(pkt, 57, room); |
---|
| 4197 | yahoo_packet_hash(pkt, 58, msg); |
---|
| 4198 | yahoo_packet_hash(pkt, 13, "0"); |
---|
| 4199 | |
---|
| 4200 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4201 | |
---|
| 4202 | yahoo_packet_free(pkt); |
---|
| 4203 | } |
---|
| 4204 | |
---|
[9034ba0] | 4205 | void yahoo_conference_logon(int id, const char *from, YList *who, |
---|
| 4206 | const char *room) |
---|
[b7d3cc34] | 4207 | { |
---|
[9034ba0] | 4208 | struct yahoo_input_data *yid = |
---|
| 4209 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4210 | struct yahoo_data *yd; |
---|
| 4211 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4212 | |
---|
[c36f73b] | 4213 | if (!yid) |
---|
[b7d3cc34] | 4214 | return; |
---|
| 4215 | yd = yid->yd; |
---|
| 4216 | |
---|
[9034ba0] | 4217 | pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YPACKET_STATUS_DEFAULT, |
---|
| 4218 | yd->session_id); |
---|
[b7d3cc34] | 4219 | |
---|
[9034ba0] | 4220 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
| 4221 | yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); |
---|
[b7d3cc34] | 4222 | yahoo_packet_hash(pkt, 57, room); |
---|
[9034ba0] | 4223 | for (; who; who = who->next) |
---|
| 4224 | yahoo_packet_hash(pkt, 3, (char *)who->data); |
---|
[b7d3cc34] | 4225 | |
---|
| 4226 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4227 | |
---|
| 4228 | yahoo_packet_free(pkt); |
---|
| 4229 | } |
---|
| 4230 | |
---|
[9034ba0] | 4231 | void yahoo_conference_decline(int id, const char *from, YList *who, |
---|
| 4232 | const char *room, const char *msg) |
---|
[b7d3cc34] | 4233 | { |
---|
[9034ba0] | 4234 | struct yahoo_input_data *yid = |
---|
| 4235 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4236 | struct yahoo_data *yd; |
---|
| 4237 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4238 | |
---|
[c36f73b] | 4239 | if (!yid) |
---|
[b7d3cc34] | 4240 | return; |
---|
| 4241 | yd = yid->yd; |
---|
| 4242 | |
---|
[9034ba0] | 4243 | pkt = yahoo_packet_new(YAHOO_SERVICE_CONFDECLINE, |
---|
| 4244 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 4245 | |
---|
[9034ba0] | 4246 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
| 4247 | yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); |
---|
| 4248 | for (; who; who = who->next) |
---|
[b7d3cc34] | 4249 | yahoo_packet_hash(pkt, 3, (char *)who->data); |
---|
| 4250 | yahoo_packet_hash(pkt, 57, room); |
---|
| 4251 | yahoo_packet_hash(pkt, 14, msg); |
---|
| 4252 | |
---|
| 4253 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4254 | |
---|
| 4255 | yahoo_packet_free(pkt); |
---|
| 4256 | } |
---|
| 4257 | |
---|
[9034ba0] | 4258 | void yahoo_conference_logoff(int id, const char *from, YList *who, |
---|
| 4259 | const char *room) |
---|
[b7d3cc34] | 4260 | { |
---|
[9034ba0] | 4261 | struct yahoo_input_data *yid = |
---|
| 4262 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4263 | struct yahoo_data *yd; |
---|
| 4264 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4265 | |
---|
[c36f73b] | 4266 | if (!yid) |
---|
[b7d3cc34] | 4267 | return; |
---|
| 4268 | yd = yid->yd; |
---|
| 4269 | |
---|
[9034ba0] | 4270 | pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YPACKET_STATUS_DEFAULT, |
---|
| 4271 | yd->session_id); |
---|
[b7d3cc34] | 4272 | |
---|
[9034ba0] | 4273 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
| 4274 | yahoo_packet_hash(pkt, 3, (from ? from : yd->user)); |
---|
| 4275 | for (; who; who = who->next) |
---|
[b7d3cc34] | 4276 | yahoo_packet_hash(pkt, 3, (char *)who->data); |
---|
[9034ba0] | 4277 | |
---|
[b7d3cc34] | 4278 | yahoo_packet_hash(pkt, 57, room); |
---|
| 4279 | |
---|
| 4280 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4281 | |
---|
| 4282 | yahoo_packet_free(pkt); |
---|
| 4283 | } |
---|
| 4284 | |
---|
[9034ba0] | 4285 | void yahoo_conference_message(int id, const char *from, YList *who, |
---|
| 4286 | const char *room, const char *msg, int utf8) |
---|
[b7d3cc34] | 4287 | { |
---|
[9034ba0] | 4288 | struct yahoo_input_data *yid = |
---|
| 4289 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4290 | struct yahoo_data *yd; |
---|
| 4291 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4292 | |
---|
[c36f73b] | 4293 | if (!yid) |
---|
[b7d3cc34] | 4294 | return; |
---|
| 4295 | yd = yid->yd; |
---|
| 4296 | |
---|
[9034ba0] | 4297 | pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YPACKET_STATUS_DEFAULT, |
---|
| 4298 | yd->session_id); |
---|
[b7d3cc34] | 4299 | |
---|
[9034ba0] | 4300 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
| 4301 | yahoo_packet_hash(pkt, 53, (from ? from : yd->user)); |
---|
| 4302 | for (; who; who = who->next) |
---|
[b7d3cc34] | 4303 | yahoo_packet_hash(pkt, 53, (char *)who->data); |
---|
[9034ba0] | 4304 | |
---|
[b7d3cc34] | 4305 | yahoo_packet_hash(pkt, 57, room); |
---|
| 4306 | yahoo_packet_hash(pkt, 14, msg); |
---|
| 4307 | |
---|
[c36f73b] | 4308 | if (utf8) |
---|
[b7d3cc34] | 4309 | yahoo_packet_hash(pkt, 97, "1"); |
---|
| 4310 | |
---|
| 4311 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4312 | |
---|
| 4313 | yahoo_packet_free(pkt); |
---|
| 4314 | } |
---|
| 4315 | |
---|
[509cf60] | 4316 | #if 0 |
---|
[b7d3cc34] | 4317 | void yahoo_get_chatrooms(int id, int chatroomid) |
---|
| 4318 | { |
---|
| 4319 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
| 4320 | struct yahoo_input_data *yid; |
---|
| 4321 | char url[1024]; |
---|
| 4322 | char buff[1024]; |
---|
| 4323 | |
---|
[c36f73b] | 4324 | if (!yd) |
---|
[b7d3cc34] | 4325 | return; |
---|
| 4326 | |
---|
| 4327 | yid = y_new0(struct yahoo_input_data, 1); |
---|
| 4328 | yid->yd = yd; |
---|
| 4329 | yid->type = YAHOO_CONNECTION_CHATCAT; |
---|
| 4330 | |
---|
| 4331 | if (chatroomid == 0) { |
---|
[9034ba0] | 4332 | snprintf(url, 1024, |
---|
| 4333 | "http://insider.msg.yahoo.com/ycontent/?chatcat=0"); |
---|
[b7d3cc34] | 4334 | } else { |
---|
[9034ba0] | 4335 | snprintf(url, 1024, |
---|
| 4336 | "http://insider.msg.yahoo.com/ycontent/?chatroom_%d=0", |
---|
| 4337 | chatroomid); |
---|
[b7d3cc34] | 4338 | } |
---|
| 4339 | |
---|
| 4340 | snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); |
---|
| 4341 | |
---|
| 4342 | inputs = y_list_prepend(inputs, yid); |
---|
| 4343 | |
---|
[9034ba0] | 4344 | yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, |
---|
| 4345 | _yahoo_http_connected, yid); |
---|
[b7d3cc34] | 4346 | } |
---|
| 4347 | |
---|
[9034ba0] | 4348 | void yahoo_chat_logon(int id, const char *from, const char *room, |
---|
| 4349 | const char *roomid) |
---|
[b7d3cc34] | 4350 | { |
---|
[9034ba0] | 4351 | struct yahoo_input_data *yid = |
---|
| 4352 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4353 | struct yahoo_data *yd; |
---|
| 4354 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4355 | |
---|
[c36f73b] | 4356 | if (!yid) |
---|
[b7d3cc34] | 4357 | return; |
---|
| 4358 | |
---|
| 4359 | yd = yid->yd; |
---|
| 4360 | |
---|
[9034ba0] | 4361 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE, YPACKET_STATUS_DEFAULT, |
---|
| 4362 | yd->session_id); |
---|
[b7d3cc34] | 4363 | |
---|
[9034ba0] | 4364 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
[b7d3cc34] | 4365 | yahoo_packet_hash(pkt, 109, yd->user); |
---|
| 4366 | yahoo_packet_hash(pkt, 6, "abcde"); |
---|
| 4367 | |
---|
| 4368 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4369 | |
---|
| 4370 | yahoo_packet_free(pkt); |
---|
| 4371 | |
---|
[9034ba0] | 4372 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YPACKET_STATUS_DEFAULT, |
---|
| 4373 | yd->session_id); |
---|
[b7d3cc34] | 4374 | |
---|
[9034ba0] | 4375 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
[b7d3cc34] | 4376 | yahoo_packet_hash(pkt, 104, room); |
---|
| 4377 | yahoo_packet_hash(pkt, 129, roomid); |
---|
[9034ba0] | 4378 | yahoo_packet_hash(pkt, 62, "2"); /* ??? */ |
---|
[b7d3cc34] | 4379 | |
---|
| 4380 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4381 | |
---|
| 4382 | yahoo_packet_free(pkt); |
---|
| 4383 | } |
---|
| 4384 | |
---|
[9034ba0] | 4385 | void yahoo_chat_message(int id, const char *from, const char *room, |
---|
| 4386 | const char *msg, const int msgtype, const int utf8) |
---|
[b7d3cc34] | 4387 | { |
---|
[9034ba0] | 4388 | struct yahoo_input_data *yid = |
---|
| 4389 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4390 | struct yahoo_data *yd; |
---|
| 4391 | struct yahoo_packet *pkt; |
---|
| 4392 | char buf[2]; |
---|
[9034ba0] | 4393 | |
---|
[c36f73b] | 4394 | if (!yid) |
---|
[b7d3cc34] | 4395 | return; |
---|
| 4396 | |
---|
| 4397 | yd = yid->yd; |
---|
| 4398 | |
---|
[9034ba0] | 4399 | pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YPACKET_STATUS_DEFAULT, |
---|
| 4400 | yd->session_id); |
---|
[b7d3cc34] | 4401 | |
---|
[9034ba0] | 4402 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
[b7d3cc34] | 4403 | yahoo_packet_hash(pkt, 104, room); |
---|
| 4404 | yahoo_packet_hash(pkt, 117, msg); |
---|
[9034ba0] | 4405 | |
---|
[b7d3cc34] | 4406 | snprintf(buf, sizeof(buf), "%d", msgtype); |
---|
| 4407 | yahoo_packet_hash(pkt, 124, buf); |
---|
| 4408 | |
---|
[c36f73b] | 4409 | if (utf8) |
---|
[b7d3cc34] | 4410 | yahoo_packet_hash(pkt, 97, "1"); |
---|
| 4411 | |
---|
| 4412 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4413 | |
---|
| 4414 | yahoo_packet_free(pkt); |
---|
| 4415 | } |
---|
| 4416 | |
---|
| 4417 | void yahoo_chat_logoff(int id, const char *from) |
---|
| 4418 | { |
---|
[9034ba0] | 4419 | struct yahoo_input_data *yid = |
---|
| 4420 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4421 | struct yahoo_data *yd; |
---|
| 4422 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4423 | |
---|
[c36f73b] | 4424 | if (!yid) |
---|
[b7d3cc34] | 4425 | return; |
---|
| 4426 | |
---|
| 4427 | yd = yid->yd; |
---|
| 4428 | |
---|
[9034ba0] | 4429 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, YPACKET_STATUS_DEFAULT, |
---|
| 4430 | yd->session_id); |
---|
[b7d3cc34] | 4431 | |
---|
[9034ba0] | 4432 | yahoo_packet_hash(pkt, 1, (from ? from : yd->user)); |
---|
[b7d3cc34] | 4433 | |
---|
| 4434 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4435 | |
---|
| 4436 | yahoo_packet_free(pkt); |
---|
| 4437 | } |
---|
| 4438 | |
---|
[cfc8d58] | 4439 | void yahoo_buddyicon_request(int id, const char *who) |
---|
| 4440 | { |
---|
[9034ba0] | 4441 | struct yahoo_input_data *yid = |
---|
| 4442 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[cfc8d58] | 4443 | struct yahoo_data *yd; |
---|
| 4444 | struct yahoo_packet *pkt; |
---|
| 4445 | |
---|
[9034ba0] | 4446 | if (!yid) |
---|
[cfc8d58] | 4447 | return; |
---|
| 4448 | |
---|
| 4449 | yd = yid->yd; |
---|
[9034ba0] | 4450 | |
---|
| 4451 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YPACKET_STATUS_DEFAULT, |
---|
| 4452 | 0); |
---|
[cfc8d58] | 4453 | yahoo_packet_hash(pkt, 4, yd->user); |
---|
| 4454 | yahoo_packet_hash(pkt, 5, who); |
---|
| 4455 | yahoo_packet_hash(pkt, 13, "1"); |
---|
| 4456 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4457 | |
---|
| 4458 | yahoo_packet_free(pkt); |
---|
| 4459 | } |
---|
| 4460 | |
---|
[9034ba0] | 4461 | void yahoo_send_picture_info(int id, const char *who, const char *url, |
---|
| 4462 | int checksum) |
---|
[cfc8d58] | 4463 | { |
---|
[9034ba0] | 4464 | struct yahoo_input_data *yid = |
---|
| 4465 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[cfc8d58] | 4466 | struct yahoo_data *yd; |
---|
| 4467 | struct yahoo_packet *pkt; |
---|
| 4468 | char checksum_str[10]; |
---|
| 4469 | |
---|
[9034ba0] | 4470 | if (!yid) |
---|
[cfc8d58] | 4471 | return; |
---|
| 4472 | |
---|
| 4473 | yd = yid->yd; |
---|
| 4474 | |
---|
| 4475 | snprintf(checksum_str, sizeof(checksum_str), "%d", checksum); |
---|
| 4476 | |
---|
[9034ba0] | 4477 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE, YPACKET_STATUS_DEFAULT, |
---|
| 4478 | 0); |
---|
[cfc8d58] | 4479 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 4480 | yahoo_packet_hash(pkt, 4, yd->user); |
---|
| 4481 | yahoo_packet_hash(pkt, 5, who); |
---|
| 4482 | yahoo_packet_hash(pkt, 13, "2"); |
---|
| 4483 | yahoo_packet_hash(pkt, 20, url); |
---|
| 4484 | yahoo_packet_hash(pkt, 192, checksum_str); |
---|
| 4485 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4486 | |
---|
| 4487 | yahoo_packet_free(pkt); |
---|
| 4488 | } |
---|
| 4489 | |
---|
| 4490 | void yahoo_send_picture_update(int id, const char *who, int type) |
---|
| 4491 | { |
---|
[9034ba0] | 4492 | struct yahoo_input_data *yid = |
---|
| 4493 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[cfc8d58] | 4494 | struct yahoo_data *yd; |
---|
| 4495 | struct yahoo_packet *pkt; |
---|
| 4496 | char type_str[10]; |
---|
| 4497 | |
---|
[9034ba0] | 4498 | if (!yid) |
---|
[cfc8d58] | 4499 | return; |
---|
| 4500 | |
---|
| 4501 | yd = yid->yd; |
---|
| 4502 | |
---|
| 4503 | snprintf(type_str, sizeof(type_str), "%d", type); |
---|
| 4504 | |
---|
[9034ba0] | 4505 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_UPDATE, |
---|
| 4506 | YPACKET_STATUS_DEFAULT, 0); |
---|
[cfc8d58] | 4507 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 4508 | yahoo_packet_hash(pkt, 5, who); |
---|
| 4509 | yahoo_packet_hash(pkt, 206, type_str); |
---|
| 4510 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4511 | |
---|
| 4512 | yahoo_packet_free(pkt); |
---|
| 4513 | } |
---|
| 4514 | |
---|
| 4515 | void yahoo_send_picture_checksum(int id, const char *who, int checksum) |
---|
| 4516 | { |
---|
[9034ba0] | 4517 | struct yahoo_input_data *yid = |
---|
| 4518 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[cfc8d58] | 4519 | struct yahoo_data *yd; |
---|
| 4520 | struct yahoo_packet *pkt; |
---|
| 4521 | char checksum_str[10]; |
---|
| 4522 | |
---|
[9034ba0] | 4523 | if (!yid) |
---|
[cfc8d58] | 4524 | return; |
---|
| 4525 | |
---|
| 4526 | yd = yid->yd; |
---|
[9034ba0] | 4527 | |
---|
[cfc8d58] | 4528 | snprintf(checksum_str, sizeof(checksum_str), "%d", checksum); |
---|
| 4529 | |
---|
[9034ba0] | 4530 | pkt = yahoo_packet_new(YAHOO_SERVICE_PICTURE_CHECKSUM, |
---|
| 4531 | YPACKET_STATUS_DEFAULT, 0); |
---|
[cfc8d58] | 4532 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
[9034ba0] | 4533 | if (who != 0) |
---|
[cfc8d58] | 4534 | yahoo_packet_hash(pkt, 5, who); |
---|
| 4535 | yahoo_packet_hash(pkt, 192, checksum_str); |
---|
| 4536 | yahoo_packet_hash(pkt, 212, "1"); |
---|
| 4537 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4538 | |
---|
| 4539 | yahoo_packet_free(pkt); |
---|
| 4540 | } |
---|
| 4541 | |
---|
[b7d3cc34] | 4542 | void yahoo_webcam_close_feed(int id, const char *who) |
---|
| 4543 | { |
---|
[9034ba0] | 4544 | struct yahoo_input_data *yid = |
---|
| 4545 | find_input_by_id_and_webcam_user(id, who); |
---|
[b7d3cc34] | 4546 | |
---|
[c36f73b] | 4547 | if (yid) |
---|
[b7d3cc34] | 4548 | yahoo_input_close(yid); |
---|
| 4549 | } |
---|
| 4550 | |
---|
| 4551 | void yahoo_webcam_get_feed(int id, const char *who) |
---|
| 4552 | { |
---|
[9034ba0] | 4553 | struct yahoo_input_data *yid = |
---|
| 4554 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4555 | struct yahoo_data *yd; |
---|
| 4556 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4557 | |
---|
[c36f73b] | 4558 | if (!yid) |
---|
[b7d3cc34] | 4559 | return; |
---|
| 4560 | |
---|
| 4561 | /* |
---|
| 4562 | * add the user to the queue. this is a dirty hack, since |
---|
| 4563 | * the yahoo server doesn't tell us who's key it's returning, |
---|
| 4564 | * we have to just hope that it sends back keys in the same |
---|
| 4565 | * order that we request them. |
---|
| 4566 | * The queue is popped in yahoo_process_webcam_key |
---|
| 4567 | */ |
---|
[9034ba0] | 4568 | webcam_queue = y_list_append(webcam_queue, who ? strdup(who) : NULL); |
---|
[b7d3cc34] | 4569 | |
---|
| 4570 | yd = yid->yd; |
---|
| 4571 | |
---|
[9034ba0] | 4572 | pkt = yahoo_packet_new(YAHOO_SERVICE_WEBCAM, YPACKET_STATUS_DEFAULT, |
---|
| 4573 | yd->session_id); |
---|
[b7d3cc34] | 4574 | |
---|
| 4575 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 4576 | if (who != NULL) |
---|
| 4577 | yahoo_packet_hash(pkt, 5, who); |
---|
| 4578 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4579 | |
---|
| 4580 | yahoo_packet_free(pkt); |
---|
| 4581 | } |
---|
| 4582 | |
---|
[9034ba0] | 4583 | void yahoo_webcam_send_image(int id, unsigned char *image, unsigned int length, |
---|
| 4584 | unsigned int timestamp) |
---|
[b7d3cc34] | 4585 | { |
---|
[9034ba0] | 4586 | struct yahoo_input_data *yid = |
---|
| 4587 | find_input_by_id_and_type(id, YAHOO_CONNECTION_WEBCAM); |
---|
[b7d3cc34] | 4588 | unsigned char *packet; |
---|
| 4589 | unsigned char header_len = 13; |
---|
| 4590 | unsigned int pos = 0; |
---|
| 4591 | |
---|
| 4592 | if (!yid) |
---|
| 4593 | return; |
---|
| 4594 | |
---|
| 4595 | packet = y_new0(unsigned char, header_len); |
---|
| 4596 | |
---|
| 4597 | packet[pos++] = header_len; |
---|
| 4598 | packet[pos++] = 0; |
---|
[9034ba0] | 4599 | packet[pos++] = 5; /* version byte?? */ |
---|
[b7d3cc34] | 4600 | packet[pos++] = 0; |
---|
| 4601 | pos += yahoo_put32(packet + pos, length); |
---|
[9034ba0] | 4602 | packet[pos++] = 2; /* packet type, image */ |
---|
[b7d3cc34] | 4603 | pos += yahoo_put32(packet + pos, timestamp); |
---|
| 4604 | yahoo_add_to_send_queue(yid, packet, header_len); |
---|
| 4605 | FREE(packet); |
---|
| 4606 | |
---|
| 4607 | if (length) |
---|
| 4608 | yahoo_add_to_send_queue(yid, image, length); |
---|
| 4609 | } |
---|
| 4610 | |
---|
[9034ba0] | 4611 | void yahoo_webcam_accept_viewer(int id, const char *who, int accept) |
---|
[b7d3cc34] | 4612 | { |
---|
[9034ba0] | 4613 | struct yahoo_input_data *yid = |
---|
| 4614 | find_input_by_id_and_type(id, YAHOO_CONNECTION_WEBCAM); |
---|
[b7d3cc34] | 4615 | char *packet = NULL; |
---|
| 4616 | char *data = NULL; |
---|
| 4617 | unsigned char header_len = 13; |
---|
| 4618 | unsigned int pos = 0; |
---|
| 4619 | unsigned int len = 0; |
---|
| 4620 | |
---|
| 4621 | if (!yid) |
---|
| 4622 | return; |
---|
| 4623 | |
---|
| 4624 | data = strdup("u="); |
---|
[9034ba0] | 4625 | data = y_string_append(data, (char *)who); |
---|
[b7d3cc34] | 4626 | data = y_string_append(data, "\r\n"); |
---|
| 4627 | len = strlen(data); |
---|
| 4628 | |
---|
| 4629 | packet = y_new0(char, header_len + len); |
---|
| 4630 | packet[pos++] = header_len; |
---|
| 4631 | packet[pos++] = 0; |
---|
[9034ba0] | 4632 | packet[pos++] = 5; /* version byte?? */ |
---|
[b7d3cc34] | 4633 | packet[pos++] = 0; |
---|
| 4634 | pos += yahoo_put32(packet + pos, len); |
---|
[9034ba0] | 4635 | packet[pos++] = 0; /* packet type */ |
---|
[b7d3cc34] | 4636 | pos += yahoo_put32(packet + pos, accept); |
---|
| 4637 | memcpy(packet + pos, data, len); |
---|
| 4638 | FREE(data); |
---|
| 4639 | yahoo_add_to_send_queue(yid, packet, header_len + len); |
---|
| 4640 | FREE(packet); |
---|
| 4641 | } |
---|
| 4642 | |
---|
| 4643 | void yahoo_webcam_invite(int id, const char *who) |
---|
| 4644 | { |
---|
[9034ba0] | 4645 | struct yahoo_input_data *yid = |
---|
| 4646 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4647 | struct yahoo_packet *pkt; |
---|
[9034ba0] | 4648 | |
---|
[c36f73b] | 4649 | if (!yid) |
---|
[b7d3cc34] | 4650 | return; |
---|
| 4651 | |
---|
[9034ba0] | 4652 | pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YPACKET_STATUS_NOTIFY, |
---|
| 4653 | yid->yd->session_id); |
---|
[b7d3cc34] | 4654 | |
---|
| 4655 | yahoo_packet_hash(pkt, 49, "WEBCAMINVITE"); |
---|
| 4656 | yahoo_packet_hash(pkt, 14, " "); |
---|
| 4657 | yahoo_packet_hash(pkt, 13, "0"); |
---|
| 4658 | yahoo_packet_hash(pkt, 1, yid->yd->user); |
---|
| 4659 | yahoo_packet_hash(pkt, 5, who); |
---|
| 4660 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4661 | |
---|
| 4662 | yahoo_packet_free(pkt); |
---|
| 4663 | } |
---|
| 4664 | |
---|
[9034ba0] | 4665 | static void yahoo_search_internal(int id, int t, const char *text, int g, |
---|
| 4666 | int ar, int photo, int yahoo_only, int startpos, int total) |
---|
[b7d3cc34] | 4667 | { |
---|
| 4668 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
| 4669 | struct yahoo_input_data *yid; |
---|
| 4670 | char url[1024]; |
---|
| 4671 | char buff[1024]; |
---|
| 4672 | char *ctext, *p; |
---|
| 4673 | |
---|
[c36f73b] | 4674 | if (!yd) |
---|
[b7d3cc34] | 4675 | return; |
---|
| 4676 | |
---|
| 4677 | yid = y_new0(struct yahoo_input_data, 1); |
---|
| 4678 | yid->yd = yd; |
---|
| 4679 | yid->type = YAHOO_CONNECTION_SEARCH; |
---|
| 4680 | |
---|
| 4681 | /* |
---|
[9034ba0] | 4682 | age range |
---|
| 4683 | .ar=1 - 13-18, 2 - 18-25, 3 - 25-35, 4 - 35-50, 5 - 50-70, 6 - 70+ |
---|
| 4684 | */ |
---|
[b7d3cc34] | 4685 | |
---|
[9034ba0] | 4686 | snprintf(buff, sizeof(buff), "&.sq=%%20&.tt=%d&.ss=%d", total, |
---|
| 4687 | startpos); |
---|
[b7d3cc34] | 4688 | |
---|
| 4689 | ctext = strdup(text); |
---|
[c36f73b] | 4690 | while ((p = strchr(ctext, ' '))) |
---|
[b7d3cc34] | 4691 | *p = '+'; |
---|
| 4692 | |
---|
[9034ba0] | 4693 | snprintf(url, 1024, |
---|
| 4694 | "http://members.yahoo.com/interests?.oc=m&.kw=%s&.sb=%d&.g=%d&.ar=0%s%s%s", |
---|
| 4695 | ctext, t, g, photo ? "&.p=y" : "", yahoo_only ? "&.pg=y" : "", |
---|
| 4696 | startpos ? buff : ""); |
---|
[b7d3cc34] | 4697 | |
---|
| 4698 | FREE(ctext); |
---|
| 4699 | |
---|
| 4700 | snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); |
---|
| 4701 | |
---|
| 4702 | inputs = y_list_prepend(inputs, yid); |
---|
[9034ba0] | 4703 | yahoo_http_get(yid->yd->client_id, url, buff, 0, 0, |
---|
| 4704 | _yahoo_http_connected, yid); |
---|
[b7d3cc34] | 4705 | } |
---|
| 4706 | |
---|
[9034ba0] | 4707 | void yahoo_search(int id, enum yahoo_search_type t, const char *text, |
---|
| 4708 | enum yahoo_search_gender g, enum yahoo_search_agerange ar, int photo, |
---|
| 4709 | int yahoo_only) |
---|
[b7d3cc34] | 4710 | { |
---|
[9034ba0] | 4711 | struct yahoo_input_data *yid = |
---|
| 4712 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4713 | struct yahoo_search_state *yss; |
---|
| 4714 | |
---|
[c36f73b] | 4715 | if (!yid) |
---|
[b7d3cc34] | 4716 | return; |
---|
| 4717 | |
---|
[c36f73b] | 4718 | if (!yid->ys) |
---|
[b7d3cc34] | 4719 | yid->ys = y_new0(struct yahoo_search_state, 1); |
---|
| 4720 | |
---|
| 4721 | yss = yid->ys; |
---|
| 4722 | |
---|
| 4723 | FREE(yss->lsearch_text); |
---|
| 4724 | yss->lsearch_type = t; |
---|
| 4725 | yss->lsearch_text = strdup(text); |
---|
| 4726 | yss->lsearch_gender = g; |
---|
| 4727 | yss->lsearch_agerange = ar; |
---|
| 4728 | yss->lsearch_photo = photo; |
---|
| 4729 | yss->lsearch_yahoo_only = yahoo_only; |
---|
| 4730 | |
---|
| 4731 | yahoo_search_internal(id, t, text, g, ar, photo, yahoo_only, 0, 0); |
---|
| 4732 | } |
---|
| 4733 | |
---|
| 4734 | void yahoo_search_again(int id, int start) |
---|
| 4735 | { |
---|
[9034ba0] | 4736 | struct yahoo_input_data *yid = |
---|
| 4737 | find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
[b7d3cc34] | 4738 | struct yahoo_search_state *yss; |
---|
| 4739 | |
---|
[c36f73b] | 4740 | if (!yid || !yid->ys) |
---|
[b7d3cc34] | 4741 | return; |
---|
| 4742 | |
---|
| 4743 | yss = yid->ys; |
---|
| 4744 | |
---|
[c36f73b] | 4745 | if (start == -1) |
---|
[b7d3cc34] | 4746 | start = yss->lsearch_nstart + yss->lsearch_nfound; |
---|
| 4747 | |
---|
[9034ba0] | 4748 | yahoo_search_internal(id, yss->lsearch_type, yss->lsearch_text, |
---|
| 4749 | yss->lsearch_gender, yss->lsearch_agerange, |
---|
| 4750 | yss->lsearch_photo, yss->lsearch_yahoo_only, |
---|
| 4751 | start, yss->lsearch_ntotal); |
---|
[b7d3cc34] | 4752 | } |
---|
| 4753 | |
---|
[9034ba0] | 4754 | void yahoo_send_picture(int id, const char *name, unsigned long size, |
---|
| 4755 | yahoo_get_fd_callback callback, void *data) |
---|
| 4756 | { |
---|
| 4757 | /* Not Implemented */ |
---|
| 4758 | } |
---|
[509cf60] | 4759 | #endif |
---|
[9034ba0] | 4760 | |
---|
| 4761 | /* File Transfer */ |
---|
| 4762 | static YList *active_file_transfers = NULL; |
---|
| 4763 | |
---|
| 4764 | enum { |
---|
| 4765 | FT_STATE_HEAD = 1, |
---|
| 4766 | FT_STATE_RECV, |
---|
| 4767 | FT_STATE_RECV_START, |
---|
| 4768 | FT_STATE_SEND |
---|
| 4769 | }; |
---|
| 4770 | |
---|
[b7d3cc34] | 4771 | struct send_file_data { |
---|
[9034ba0] | 4772 | int client_id; |
---|
| 4773 | char *id; |
---|
| 4774 | char *who; |
---|
| 4775 | char *filename; |
---|
| 4776 | char *ip_addr; |
---|
| 4777 | char *token; |
---|
| 4778 | int size; |
---|
| 4779 | |
---|
| 4780 | struct yahoo_input_data *yid; |
---|
| 4781 | int state; |
---|
| 4782 | |
---|
[b7d3cc34] | 4783 | yahoo_get_fd_callback callback; |
---|
[9034ba0] | 4784 | void *data; |
---|
[b7d3cc34] | 4785 | }; |
---|
| 4786 | |
---|
[509cf60] | 4787 | #if 0 |
---|
[9034ba0] | 4788 | static char *yahoo_get_random(void) |
---|
| 4789 | { |
---|
| 4790 | int i = 0; |
---|
| 4791 | int r = 0; |
---|
| 4792 | int c = 0; |
---|
| 4793 | char out[25]; |
---|
| 4794 | |
---|
| 4795 | out[24] = '\0'; |
---|
| 4796 | out[23] = '$'; |
---|
| 4797 | out[22] = '$'; |
---|
| 4798 | |
---|
| 4799 | for (i = 0; i < 22; i++) { |
---|
| 4800 | if(r == 0) |
---|
| 4801 | r = rand(); |
---|
| 4802 | |
---|
| 4803 | c = r%61; |
---|
| 4804 | |
---|
| 4805 | if(c<26) |
---|
| 4806 | out[i] = c + 'a'; |
---|
| 4807 | else if (c<52) |
---|
| 4808 | out[i] = c - 26 + 'A'; |
---|
| 4809 | else |
---|
| 4810 | out[i] = c - 52 + '0'; |
---|
| 4811 | |
---|
| 4812 | r /= 61; |
---|
| 4813 | } |
---|
| 4814 | |
---|
| 4815 | return strdup(out); |
---|
| 4816 | } |
---|
[509cf60] | 4817 | #endif |
---|
[9034ba0] | 4818 | |
---|
| 4819 | static int _are_same_id(const void *sfd1, const void *id) |
---|
| 4820 | { |
---|
| 4821 | return strcmp(((struct send_file_data *)sfd1)->id, (char *)id); |
---|
| 4822 | } |
---|
| 4823 | |
---|
| 4824 | static int _are_same_yid(const void *sfd1, const void *yid) |
---|
| 4825 | { |
---|
| 4826 | if(((struct send_file_data *)sfd1)->yid == yid) |
---|
| 4827 | return 0; |
---|
| 4828 | else |
---|
| 4829 | return 1; |
---|
| 4830 | } |
---|
| 4831 | |
---|
| 4832 | static struct send_file_data *yahoo_get_active_transfer(char *id) |
---|
| 4833 | { |
---|
| 4834 | YList *l = y_list_find_custom(active_file_transfers, id, |
---|
| 4835 | _are_same_id); |
---|
| 4836 | |
---|
| 4837 | if(l) |
---|
| 4838 | return (struct send_file_data *)l->data; |
---|
| 4839 | |
---|
| 4840 | return NULL; |
---|
| 4841 | } |
---|
| 4842 | |
---|
| 4843 | static struct send_file_data *yahoo_get_active_transfer_with_yid(void *yid) |
---|
| 4844 | { |
---|
| 4845 | YList *l = y_list_find_custom(active_file_transfers, yid, |
---|
| 4846 | _are_same_yid); |
---|
| 4847 | |
---|
| 4848 | if(l) |
---|
| 4849 | return (struct send_file_data *)l->data; |
---|
| 4850 | |
---|
| 4851 | return NULL; |
---|
| 4852 | } |
---|
| 4853 | |
---|
| 4854 | static void yahoo_add_active_transfer(struct send_file_data *sfd) |
---|
| 4855 | { |
---|
| 4856 | active_file_transfers = y_list_prepend(active_file_transfers, sfd); |
---|
| 4857 | } |
---|
| 4858 | |
---|
| 4859 | static void yahoo_remove_active_transfer(struct send_file_data *sfd) |
---|
| 4860 | { |
---|
[c6bf805] | 4861 | if (sfd == NULL) |
---|
| 4862 | return; |
---|
| 4863 | |
---|
[9034ba0] | 4864 | active_file_transfers = y_list_remove(active_file_transfers, sfd); |
---|
| 4865 | free(sfd->id); |
---|
| 4866 | free(sfd->who); |
---|
| 4867 | free(sfd->filename); |
---|
| 4868 | free(sfd->ip_addr); |
---|
| 4869 | FREE(sfd); |
---|
| 4870 | } |
---|
| 4871 | |
---|
| 4872 | static void _yahoo_ft_upload_connected(int id, void *fd, int error, void *data) |
---|
[cfc8d58] | 4873 | { |
---|
| 4874 | struct send_file_data *sfd = data; |
---|
[9034ba0] | 4875 | struct yahoo_input_data *yid = sfd->yid; |
---|
[cfc8d58] | 4876 | |
---|
[9034ba0] | 4877 | if (!fd) { |
---|
[cfc8d58] | 4878 | inputs = y_list_remove(inputs, yid); |
---|
| 4879 | FREE(yid); |
---|
| 4880 | return; |
---|
| 4881 | } |
---|
| 4882 | |
---|
[9034ba0] | 4883 | sfd->callback(id, fd, error, sfd->data); |
---|
| 4884 | |
---|
[cfc8d58] | 4885 | yid->fd = fd; |
---|
[9034ba0] | 4886 | yid->read_tag = |
---|
| 4887 | YAHOO_CALLBACK(ext_yahoo_add_handler) (yid->yd->client_id, fd, |
---|
| 4888 | YAHOO_INPUT_READ, yid); |
---|
| 4889 | } |
---|
[cfc8d58] | 4890 | |
---|
[9034ba0] | 4891 | static void yahoo_file_transfer_upload(struct yahoo_data *yd, |
---|
| 4892 | struct send_file_data *sfd) |
---|
| 4893 | { |
---|
| 4894 | char url[256]; |
---|
| 4895 | char buff[4096]; |
---|
| 4896 | char *sender_enc = NULL, *recv_enc = NULL, *token_enc = NULL; |
---|
[cfc8d58] | 4897 | |
---|
[9034ba0] | 4898 | struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); |
---|
[cfc8d58] | 4899 | |
---|
[9034ba0] | 4900 | yid->yd = yd; |
---|
| 4901 | yid->type = YAHOO_CONNECTION_FT; |
---|
| 4902 | |
---|
| 4903 | inputs = y_list_prepend(inputs, yid); |
---|
| 4904 | sfd->yid = yid; |
---|
| 4905 | sfd->state = FT_STATE_SEND; |
---|
| 4906 | |
---|
| 4907 | token_enc = yahoo_urlencode(sfd->token); |
---|
| 4908 | sender_enc = yahoo_urlencode(yd->user); |
---|
| 4909 | recv_enc = yahoo_urlencode(sfd->who); |
---|
| 4910 | |
---|
| 4911 | snprintf(url, sizeof(url), |
---|
| 4912 | "http://%s/relay?token=%s&sender=%s&recver=%s", sfd->ip_addr, |
---|
| 4913 | token_enc, sender_enc, recv_enc); |
---|
| 4914 | |
---|
| 4915 | snprintf(buff, sizeof(buff), "T=%s; Y=%s", yd->cookie_t, yd->cookie_y); |
---|
| 4916 | |
---|
| 4917 | yahoo_http_post(yd->client_id, url, buff, sfd->size, |
---|
| 4918 | _yahoo_ft_upload_connected, sfd); |
---|
| 4919 | |
---|
| 4920 | FREE(token_enc); |
---|
| 4921 | FREE(sender_enc); |
---|
| 4922 | FREE(recv_enc); |
---|
| 4923 | } |
---|
| 4924 | |
---|
| 4925 | static void yahoo_init_ft_recv(struct yahoo_data *yd, |
---|
| 4926 | struct send_file_data *sfd) |
---|
| 4927 | { |
---|
| 4928 | char url[256]; |
---|
| 4929 | char buff[1024]; |
---|
| 4930 | char *sender_enc = NULL, *recv_enc = NULL, *token_enc = NULL; |
---|
| 4931 | |
---|
| 4932 | struct yahoo_input_data *yid = y_new0(struct yahoo_input_data, 1); |
---|
| 4933 | |
---|
| 4934 | yid->yd = yd; |
---|
| 4935 | yid->type = YAHOO_CONNECTION_FT; |
---|
| 4936 | |
---|
| 4937 | inputs = y_list_prepend(inputs, yid); |
---|
| 4938 | sfd->yid = yid; |
---|
| 4939 | sfd->state = FT_STATE_HEAD; |
---|
| 4940 | |
---|
| 4941 | token_enc = yahoo_urlencode(sfd->token); |
---|
| 4942 | sender_enc = yahoo_urlencode(sfd->who); |
---|
| 4943 | recv_enc = yahoo_urlencode(yd->user); |
---|
| 4944 | |
---|
| 4945 | snprintf(url, sizeof(url), |
---|
| 4946 | "http://%s/relay?token=%s&sender=%s&recver=%s", sfd->ip_addr, |
---|
| 4947 | token_enc, sender_enc, recv_enc); |
---|
| 4948 | |
---|
| 4949 | snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, yd->cookie_t); |
---|
| 4950 | |
---|
| 4951 | yahoo_http_head(yid->yd->client_id, url, buff, 0, NULL, |
---|
| 4952 | _yahoo_http_connected, yid); |
---|
| 4953 | |
---|
| 4954 | FREE(token_enc); |
---|
| 4955 | FREE(sender_enc); |
---|
| 4956 | FREE(recv_enc); |
---|
[cfc8d58] | 4957 | } |
---|
| 4958 | |
---|
[9034ba0] | 4959 | static void yahoo_file_transfer_accept(struct yahoo_input_data *yid, |
---|
| 4960 | struct send_file_data *sfd) |
---|
| 4961 | { |
---|
| 4962 | struct yahoo_packet *pkt; |
---|
| 4963 | |
---|
| 4964 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFERACCEPT, |
---|
| 4965 | YPACKET_STATUS_DEFAULT, yid->yd->session_id); |
---|
| 4966 | |
---|
| 4967 | yahoo_packet_hash(pkt, 1, yid->yd->user); |
---|
| 4968 | yahoo_packet_hash(pkt, 5, sfd->who); |
---|
| 4969 | yahoo_packet_hash(pkt, 265, sfd->id); |
---|
| 4970 | yahoo_packet_hash(pkt, 27, sfd->filename); |
---|
| 4971 | yahoo_packet_hash(pkt, 249, "3"); |
---|
| 4972 | yahoo_packet_hash(pkt, 251, sfd->token); |
---|
| 4973 | |
---|
| 4974 | yahoo_send_packet(yid, pkt, 0); |
---|
| 4975 | |
---|
| 4976 | yahoo_packet_free(pkt); |
---|
| 4977 | |
---|
| 4978 | yahoo_init_ft_recv(yid->yd, sfd); |
---|
[cfc8d58] | 4979 | } |
---|
| 4980 | |
---|
[9034ba0] | 4981 | static void yahoo_process_filetransferaccept(struct yahoo_input_data *yid, |
---|
| 4982 | struct yahoo_packet *pkt) |
---|
[cfc8d58] | 4983 | { |
---|
[9034ba0] | 4984 | YList *l; |
---|
[cfc8d58] | 4985 | struct send_file_data *sfd; |
---|
[9034ba0] | 4986 | char *id = NULL; |
---|
| 4987 | char *token = NULL; |
---|
[cfc8d58] | 4988 | |
---|
[9034ba0] | 4989 | for (l = pkt->hash; l; l = l->next) { |
---|
| 4990 | struct yahoo_pair *pair = l->data; |
---|
| 4991 | switch (pair->key) { |
---|
| 4992 | case 4: |
---|
[d7edadf] | 4993 | /* who */ |
---|
[9034ba0] | 4994 | break; |
---|
| 4995 | case 5: |
---|
| 4996 | /* Me... don't care */ |
---|
| 4997 | break; |
---|
| 4998 | case 249: |
---|
| 4999 | break; |
---|
| 5000 | case 265: |
---|
| 5001 | id = pair->value; |
---|
| 5002 | break; |
---|
| 5003 | case 251: |
---|
| 5004 | token = pair->value; |
---|
| 5005 | break; |
---|
| 5006 | case 27: |
---|
[d7edadf] | 5007 | /* filename */ |
---|
[9034ba0] | 5008 | break; |
---|
| 5009 | } |
---|
| 5010 | } |
---|
[cfc8d58] | 5011 | |
---|
[9034ba0] | 5012 | sfd = yahoo_get_active_transfer(id); |
---|
[cfc8d58] | 5013 | |
---|
[9034ba0] | 5014 | if (sfd) { |
---|
| 5015 | sfd->token = strdup(token); |
---|
[cfc8d58] | 5016 | |
---|
[9034ba0] | 5017 | yahoo_file_transfer_upload(yid->yd, sfd); |
---|
| 5018 | } |
---|
| 5019 | else { |
---|
| 5020 | YAHOO_CALLBACK(ext_yahoo_file_transfer_done) |
---|
| 5021 | (yid->yd->client_id, YAHOO_FILE_TRANSFER_UNKNOWN, |
---|
[c6bf805] | 5022 | sfd ? sfd->data : NULL); |
---|
[cfc8d58] | 5023 | |
---|
[9034ba0] | 5024 | yahoo_remove_active_transfer(sfd); |
---|
| 5025 | } |
---|
| 5026 | } |
---|
[cfc8d58] | 5027 | |
---|
[9034ba0] | 5028 | static void yahoo_process_filetransferinfo(struct yahoo_input_data *yid, |
---|
| 5029 | struct yahoo_packet *pkt) |
---|
| 5030 | { |
---|
| 5031 | YList *l; |
---|
| 5032 | char *id = NULL; |
---|
| 5033 | char *token = NULL; |
---|
| 5034 | char *ip_addr = NULL; |
---|
[cfc8d58] | 5035 | |
---|
[9034ba0] | 5036 | struct send_file_data *sfd; |
---|
[cfc8d58] | 5037 | |
---|
[9034ba0] | 5038 | for (l = pkt->hash; l; l = l->next) { |
---|
| 5039 | struct yahoo_pair *pair = l->data; |
---|
| 5040 | switch (pair->key) { |
---|
| 5041 | case 1: |
---|
| 5042 | case 4: |
---|
[d7edadf] | 5043 | /* who */ |
---|
[9034ba0] | 5044 | break; |
---|
| 5045 | case 5: |
---|
| 5046 | /* Me... don't care */ |
---|
| 5047 | break; |
---|
| 5048 | case 249: |
---|
| 5049 | break; |
---|
| 5050 | case 265: |
---|
| 5051 | id = pair->value; |
---|
| 5052 | break; |
---|
| 5053 | case 250: |
---|
| 5054 | ip_addr = pair->value; |
---|
| 5055 | break; |
---|
| 5056 | case 251: |
---|
| 5057 | token = pair->value; |
---|
| 5058 | break; |
---|
| 5059 | case 27: |
---|
[d7edadf] | 5060 | /* filename */ |
---|
[9034ba0] | 5061 | break; |
---|
| 5062 | } |
---|
| 5063 | } |
---|
[cfc8d58] | 5064 | |
---|
[9034ba0] | 5065 | sfd = yahoo_get_active_transfer(id); |
---|
| 5066 | |
---|
| 5067 | if (sfd) { |
---|
| 5068 | sfd->token = strdup(token); |
---|
| 5069 | sfd->ip_addr = strdup(ip_addr); |
---|
| 5070 | |
---|
| 5071 | yahoo_file_transfer_accept(yid, sfd); |
---|
| 5072 | } |
---|
| 5073 | else { |
---|
| 5074 | YAHOO_CALLBACK(ext_yahoo_file_transfer_done) |
---|
| 5075 | (yid->yd->client_id, YAHOO_FILE_TRANSFER_UNKNOWN, |
---|
[c6bf805] | 5076 | sfd ? sfd->data : NULL); |
---|
[9034ba0] | 5077 | |
---|
| 5078 | yahoo_remove_active_transfer(sfd); |
---|
| 5079 | } |
---|
[cfc8d58] | 5080 | } |
---|
| 5081 | |
---|
[9034ba0] | 5082 | static void yahoo_send_filetransferinfo(struct yahoo_data *yd, |
---|
| 5083 | struct send_file_data *sfd) |
---|
[b7d3cc34] | 5084 | { |
---|
[9034ba0] | 5085 | struct yahoo_input_data *yid; |
---|
| 5086 | struct yahoo_packet *pkt; |
---|
| 5087 | |
---|
| 5088 | yid = find_input_by_id_and_type(yd->client_id, YAHOO_CONNECTION_PAGER); |
---|
| 5089 | sfd->ip_addr = YAHOO_CALLBACK(ext_yahoo_get_ip_addr)("relay.yahoo.com"); |
---|
| 5090 | |
---|
| 5091 | if (!sfd->ip_addr) { |
---|
| 5092 | YAHOO_CALLBACK(ext_yahoo_file_transfer_done) |
---|
| 5093 | (yd->client_id, YAHOO_FILE_TRANSFER_RELAY, sfd->data); |
---|
| 5094 | |
---|
| 5095 | yahoo_remove_active_transfer(sfd); |
---|
[b7d3cc34] | 5096 | |
---|
| 5097 | return; |
---|
| 5098 | } |
---|
| 5099 | |
---|
[9034ba0] | 5100 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFERINFO, |
---|
| 5101 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
| 5102 | |
---|
| 5103 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
| 5104 | yahoo_packet_hash(pkt, 5, sfd->who); |
---|
| 5105 | yahoo_packet_hash(pkt, 265, sfd->id); |
---|
| 5106 | yahoo_packet_hash(pkt, 27, sfd->filename); |
---|
| 5107 | yahoo_packet_hash(pkt, 249, "3"); |
---|
| 5108 | yahoo_packet_hash(pkt, 250, sfd->ip_addr); |
---|
| 5109 | |
---|
| 5110 | yahoo_send_packet(yid, pkt, 0); |
---|
| 5111 | |
---|
[b7d3cc34] | 5112 | yahoo_packet_free(pkt); |
---|
[9034ba0] | 5113 | } |
---|
[b7d3cc34] | 5114 | |
---|
[9034ba0] | 5115 | static void yahoo_process_filetransfer(struct yahoo_input_data *yid, |
---|
| 5116 | struct yahoo_packet *pkt) |
---|
| 5117 | { |
---|
| 5118 | YList *l; |
---|
| 5119 | char *who = NULL; |
---|
| 5120 | char *filename = NULL; |
---|
| 5121 | char *msg = NULL; |
---|
| 5122 | char *id = NULL; |
---|
| 5123 | int action = 0; |
---|
| 5124 | int size = 0; |
---|
| 5125 | struct yahoo_data *yd = yid->yd; |
---|
[b7d3cc34] | 5126 | |
---|
[9034ba0] | 5127 | struct send_file_data *sfd; |
---|
[b7d3cc34] | 5128 | |
---|
[9034ba0] | 5129 | for (l = pkt->hash; l; l = l->next) { |
---|
| 5130 | struct yahoo_pair *pair = l->data; |
---|
| 5131 | switch (pair->key) { |
---|
| 5132 | case 4: |
---|
| 5133 | who = pair->value; |
---|
| 5134 | break; |
---|
| 5135 | case 5: |
---|
| 5136 | /* Me... don't care */ |
---|
| 5137 | break; |
---|
| 5138 | case 222: |
---|
| 5139 | action = atoi(pair->value); |
---|
| 5140 | break; |
---|
| 5141 | case 265: |
---|
| 5142 | id = pair->value; |
---|
| 5143 | break; |
---|
| 5144 | case 266: /* Don't know */ |
---|
| 5145 | break; |
---|
| 5146 | case 302: /* Start Data? */ |
---|
| 5147 | break; |
---|
| 5148 | case 300: |
---|
[b7d3cc34] | 5149 | break; |
---|
[9034ba0] | 5150 | case 27: |
---|
| 5151 | filename = pair->value; |
---|
| 5152 | break; |
---|
| 5153 | case 28: |
---|
| 5154 | size = atoi(pair->value); |
---|
| 5155 | break; |
---|
| 5156 | case 14: |
---|
| 5157 | msg = pair->value; |
---|
| 5158 | case 301: /* End Data? */ |
---|
| 5159 | break; |
---|
| 5160 | case 303: |
---|
| 5161 | break; |
---|
| 5162 | |
---|
| 5163 | } |
---|
| 5164 | } |
---|
| 5165 | |
---|
| 5166 | if (action == YAHOO_FILE_TRANSFER_INIT) { |
---|
| 5167 | /* Received a FT request from buddy */ |
---|
| 5168 | sfd = y_new0(struct send_file_data, 1); |
---|
| 5169 | |
---|
| 5170 | sfd->client_id = yd->client_id; |
---|
| 5171 | sfd->id = strdup(id); |
---|
| 5172 | sfd->who = strdup(who); |
---|
| 5173 | sfd->filename = strdup(filename); |
---|
| 5174 | sfd->size = size; |
---|
| 5175 | |
---|
| 5176 | yahoo_add_active_transfer(sfd); |
---|
| 5177 | |
---|
| 5178 | YAHOO_CALLBACK(ext_yahoo_got_file) (yd->client_id, yd->user, |
---|
| 5179 | who, msg, filename, size, sfd->id); |
---|
[b7d3cc34] | 5180 | } |
---|
[9034ba0] | 5181 | else { |
---|
| 5182 | /* Response to our request */ |
---|
| 5183 | sfd = yahoo_get_active_transfer(id); |
---|
[b7d3cc34] | 5184 | |
---|
[9034ba0] | 5185 | if (sfd && action == YAHOO_FILE_TRANSFER_ACCEPT) { |
---|
| 5186 | yahoo_send_filetransferinfo(yd, sfd); |
---|
| 5187 | } |
---|
| 5188 | else if (!sfd || action == YAHOO_FILE_TRANSFER_REJECT) { |
---|
| 5189 | YAHOO_CALLBACK(ext_yahoo_file_transfer_done) |
---|
| 5190 | (yd->client_id, YAHOO_FILE_TRANSFER_REJECT, |
---|
[c6bf805] | 5191 | sfd ? sfd->data : NULL); |
---|
[9034ba0] | 5192 | |
---|
| 5193 | yahoo_remove_active_transfer(sfd); |
---|
| 5194 | } |
---|
| 5195 | } |
---|
[b7d3cc34] | 5196 | } |
---|
| 5197 | |
---|
[509cf60] | 5198 | #if 0 |
---|
[9034ba0] | 5199 | void yahoo_send_file(int id, const char *who, const char *msg, |
---|
| 5200 | const char *name, unsigned long size, |
---|
| 5201 | yahoo_get_fd_callback callback, void *data) |
---|
[b7d3cc34] | 5202 | { |
---|
| 5203 | struct yahoo_packet *pkt = NULL; |
---|
| 5204 | char size_str[10]; |
---|
[9034ba0] | 5205 | struct yahoo_input_data *yid; |
---|
| 5206 | struct yahoo_data *yd; |
---|
[b7d3cc34] | 5207 | struct send_file_data *sfd; |
---|
[9034ba0] | 5208 | |
---|
| 5209 | yid = find_input_by_id_and_type(id, YAHOO_CONNECTION_PAGER); |
---|
| 5210 | yd = find_conn_by_id(id); |
---|
| 5211 | sfd = y_new0(struct send_file_data, 1); |
---|
[b7d3cc34] | 5212 | |
---|
[9034ba0] | 5213 | sfd->client_id = id; |
---|
| 5214 | sfd->id = yahoo_get_random(); |
---|
| 5215 | sfd->who = strdup(who); |
---|
| 5216 | sfd->filename = strdup(name); |
---|
| 5217 | sfd->size = size; |
---|
| 5218 | sfd->callback = callback; |
---|
| 5219 | sfd->data = data; |
---|
[b7d3cc34] | 5220 | |
---|
[9034ba0] | 5221 | yahoo_add_active_transfer(sfd); |
---|
[b7d3cc34] | 5222 | |
---|
[9034ba0] | 5223 | if (!yd) |
---|
| 5224 | return; |
---|
[b7d3cc34] | 5225 | |
---|
[9034ba0] | 5226 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFER, |
---|
| 5227 | YPACKET_STATUS_DEFAULT, yd->session_id); |
---|
[b7d3cc34] | 5228 | |
---|
| 5229 | snprintf(size_str, sizeof(size_str), "%ld", size); |
---|
| 5230 | |
---|
[9034ba0] | 5231 | yahoo_packet_hash(pkt, 1, yd->user); |
---|
[b7d3cc34] | 5232 | yahoo_packet_hash(pkt, 5, who); |
---|
[9034ba0] | 5233 | yahoo_packet_hash(pkt, 265, sfd->id); |
---|
| 5234 | yahoo_packet_hash(pkt, 222, "1"); |
---|
| 5235 | yahoo_packet_hash(pkt, 266, "1"); |
---|
| 5236 | yahoo_packet_hash(pkt, 302, "268"); |
---|
| 5237 | yahoo_packet_hash(pkt, 300, "268"); |
---|
[b7d3cc34] | 5238 | yahoo_packet_hash(pkt, 27, name); |
---|
| 5239 | yahoo_packet_hash(pkt, 28, size_str); |
---|
[9034ba0] | 5240 | yahoo_packet_hash(pkt, 301, "268"); |
---|
| 5241 | yahoo_packet_hash(pkt, 303, "268"); |
---|
[b7d3cc34] | 5242 | |
---|
[9034ba0] | 5243 | yahoo_send_packet(yid, pkt, 0); |
---|
[b7d3cc34] | 5244 | |
---|
[9034ba0] | 5245 | yahoo_packet_free(pkt); |
---|
| 5246 | } |
---|
[b7d3cc34] | 5247 | |
---|
[9034ba0] | 5248 | void yahoo_send_file_transfer_response(int client_id, int response, char *id, void *data) |
---|
| 5249 | { |
---|
| 5250 | struct yahoo_packet *pkt = NULL; |
---|
| 5251 | char resp[2]; |
---|
| 5252 | struct yahoo_input_data *yid; |
---|
| 5253 | |
---|
| 5254 | struct send_file_data *sfd = yahoo_get_active_transfer(id); |
---|
| 5255 | |
---|
| 5256 | sfd->data = data; |
---|
| 5257 | |
---|
| 5258 | yid = find_input_by_id_and_type(client_id, YAHOO_CONNECTION_PAGER); |
---|
| 5259 | |
---|
| 5260 | pkt = yahoo_packet_new(YAHOO_SERVICE_Y7_FILETRANSFER, |
---|
| 5261 | YPACKET_STATUS_DEFAULT, yid->yd->session_id); |
---|
| 5262 | |
---|
| 5263 | snprintf(resp, sizeof(resp), "%d", response); |
---|
| 5264 | |
---|
| 5265 | yahoo_packet_hash(pkt, 1, yid->yd->user); |
---|
| 5266 | yahoo_packet_hash(pkt, 5, sfd->who); |
---|
| 5267 | yahoo_packet_hash(pkt, 265, sfd->id); |
---|
| 5268 | yahoo_packet_hash(pkt, 222, resp); |
---|
| 5269 | |
---|
| 5270 | yahoo_send_packet(yid, pkt, 0); |
---|
| 5271 | |
---|
| 5272 | yahoo_packet_free(pkt); |
---|
| 5273 | |
---|
| 5274 | if(response == YAHOO_FILE_TRANSFER_REJECT) |
---|
| 5275 | yahoo_remove_active_transfer(sfd); |
---|
[b7d3cc34] | 5276 | } |
---|
[509cf60] | 5277 | #endif |
---|
[b7d3cc34] | 5278 | |
---|
[9034ba0] | 5279 | static void yahoo_process_ft_connection(struct yahoo_input_data *yid, int over) |
---|
| 5280 | { |
---|
| 5281 | struct send_file_data *sfd; |
---|
| 5282 | struct yahoo_data *yd = yid->yd; |
---|
| 5283 | |
---|
| 5284 | sfd = yahoo_get_active_transfer_with_yid(yid); |
---|
| 5285 | |
---|
| 5286 | if (!sfd) { |
---|
| 5287 | LOG(("Something funny happened. yid %p has no sfd.\n", yid)); |
---|
| 5288 | return; |
---|
| 5289 | } |
---|
| 5290 | |
---|
| 5291 | /* |
---|
| 5292 | * We want to handle only the complete data with HEAD since we don't |
---|
| 5293 | * want a situation where both the GET and HEAD are active. |
---|
| 5294 | * With SEND, we really can't do much with partial response |
---|
| 5295 | */ |
---|
| 5296 | if ((sfd->state == FT_STATE_HEAD || sfd->state == FT_STATE_SEND) |
---|
| 5297 | && !over) |
---|
| 5298 | return; |
---|
| 5299 | |
---|
| 5300 | if (sfd->state == FT_STATE_HEAD) { |
---|
| 5301 | /* Do a GET */ |
---|
| 5302 | char url[256]; |
---|
| 5303 | char buff[1024]; |
---|
| 5304 | char *sender_enc = NULL, *recv_enc = NULL, *token_enc = NULL; |
---|
| 5305 | |
---|
| 5306 | struct yahoo_input_data *yid_ft = |
---|
| 5307 | y_new0(struct yahoo_input_data, 1); |
---|
| 5308 | |
---|
| 5309 | yid_ft->yd = yid->yd; |
---|
| 5310 | yid_ft->type = YAHOO_CONNECTION_FT; |
---|
| 5311 | |
---|
| 5312 | inputs = y_list_prepend(inputs, yid_ft); |
---|
| 5313 | sfd->yid = yid_ft; |
---|
| 5314 | sfd->state = FT_STATE_RECV; |
---|
| 5315 | |
---|
| 5316 | token_enc = yahoo_urlencode(sfd->token); |
---|
| 5317 | sender_enc = yahoo_urlencode(sfd->who); |
---|
| 5318 | recv_enc = yahoo_urlencode(yd->user); |
---|
| 5319 | |
---|
| 5320 | snprintf(url, sizeof(url), |
---|
| 5321 | "http://%s/relay?token=%s&sender=%s&recver=%s", sfd->ip_addr, |
---|
| 5322 | token_enc, sender_enc, recv_enc); |
---|
| 5323 | |
---|
| 5324 | snprintf(buff, sizeof(buff), "Y=%s; T=%s", yd->cookie_y, |
---|
| 5325 | yd->cookie_t); |
---|
| 5326 | |
---|
| 5327 | |
---|
| 5328 | yahoo_http_get(yd->client_id, url, buff, 1, 1, |
---|
| 5329 | _yahoo_http_connected, yid_ft); |
---|
| 5330 | |
---|
| 5331 | FREE(token_enc); |
---|
| 5332 | FREE(sender_enc); |
---|
| 5333 | FREE(recv_enc); |
---|
| 5334 | } |
---|
| 5335 | else if (sfd->state == FT_STATE_RECV || |
---|
| 5336 | sfd->state == FT_STATE_RECV_START) { |
---|
| 5337 | |
---|
| 5338 | unsigned char *data_begin = NULL; |
---|
| 5339 | |
---|
| 5340 | if (yid->rxlen == 0) |
---|
| 5341 | yahoo_remove_active_transfer(sfd); |
---|
| 5342 | |
---|
| 5343 | if (sfd->state != FT_STATE_RECV_START && |
---|
| 5344 | (data_begin = |
---|
| 5345 | (unsigned char *)strstr((char *)yid->rxqueue, |
---|
| 5346 | "\r\n\r\n"))) { |
---|
| 5347 | |
---|
| 5348 | sfd->state = FT_STATE_RECV_START; |
---|
| 5349 | |
---|
| 5350 | yid->rxlen -= 4+(data_begin-yid->rxqueue)/sizeof(char); |
---|
| 5351 | data_begin += 4; |
---|
| 5352 | |
---|
| 5353 | if (yid->rxlen > 0) |
---|
| 5354 | YAHOO_CALLBACK(ext_yahoo_got_ft_data) |
---|
| 5355 | (yd->client_id, data_begin, |
---|
| 5356 | yid->rxlen, sfd->data); |
---|
| 5357 | } |
---|
| 5358 | else if (sfd->state == FT_STATE_RECV_START) |
---|
| 5359 | YAHOO_CALLBACK(ext_yahoo_got_ft_data) (yd->client_id, |
---|
| 5360 | yid->rxqueue, yid->rxlen, sfd->data); |
---|
| 5361 | |
---|
| 5362 | FREE(yid->rxqueue); |
---|
| 5363 | yid->rxqueue = NULL; |
---|
| 5364 | yid->rxlen = 0; |
---|
| 5365 | } |
---|
| 5366 | else if (sfd->state == FT_STATE_SEND) { |
---|
| 5367 | /* Sent file completed */ |
---|
| 5368 | int len = 0; |
---|
| 5369 | char *off = strstr((char *)yid->rxqueue, "Content-Length: "); |
---|
| 5370 | |
---|
| 5371 | if (off) { |
---|
| 5372 | off += 16; |
---|
| 5373 | len = atoi(off); |
---|
| 5374 | } |
---|
| 5375 | |
---|
| 5376 | if (len < sfd->size) |
---|
| 5377 | YAHOO_CALLBACK(ext_yahoo_file_transfer_done) |
---|
| 5378 | (yd->client_id, |
---|
| 5379 | YAHOO_FILE_TRANSFER_FAILED, sfd->data); |
---|
| 5380 | else |
---|
| 5381 | YAHOO_CALLBACK(ext_yahoo_file_transfer_done) |
---|
| 5382 | (yd->client_id, |
---|
| 5383 | YAHOO_FILE_TRANSFER_DONE, sfd->data); |
---|
| 5384 | |
---|
| 5385 | yahoo_remove_active_transfer(sfd); |
---|
| 5386 | } |
---|
| 5387 | } |
---|
| 5388 | |
---|
| 5389 | /* End File Transfer */ |
---|
[b7d3cc34] | 5390 | |
---|
[509cf60] | 5391 | #if 0 |
---|
[b7d3cc34] | 5392 | enum yahoo_status yahoo_current_status(int id) |
---|
| 5393 | { |
---|
| 5394 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
[c36f73b] | 5395 | if (!yd) |
---|
[b7d3cc34] | 5396 | return YAHOO_STATUS_OFFLINE; |
---|
| 5397 | return yd->current_status; |
---|
| 5398 | } |
---|
| 5399 | |
---|
[c36f73b] | 5400 | const YList *yahoo_get_buddylist(int id) |
---|
[b7d3cc34] | 5401 | { |
---|
| 5402 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
[c36f73b] | 5403 | if (!yd) |
---|
[b7d3cc34] | 5404 | return NULL; |
---|
| 5405 | return yd->buddies; |
---|
| 5406 | } |
---|
| 5407 | |
---|
[c36f73b] | 5408 | const YList *yahoo_get_ignorelist(int id) |
---|
[b7d3cc34] | 5409 | { |
---|
| 5410 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
[c36f73b] | 5411 | if (!yd) |
---|
[b7d3cc34] | 5412 | return NULL; |
---|
| 5413 | return yd->ignore; |
---|
| 5414 | } |
---|
| 5415 | |
---|
[c36f73b] | 5416 | const YList *yahoo_get_identities(int id) |
---|
[b7d3cc34] | 5417 | { |
---|
| 5418 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
[c36f73b] | 5419 | if (!yd) |
---|
[b7d3cc34] | 5420 | return NULL; |
---|
| 5421 | return yd->identities; |
---|
| 5422 | } |
---|
| 5423 | |
---|
[c36f73b] | 5424 | const char *yahoo_get_cookie(int id, const char *which) |
---|
[b7d3cc34] | 5425 | { |
---|
| 5426 | struct yahoo_data *yd = find_conn_by_id(id); |
---|
[c36f73b] | 5427 | if (!yd) |
---|
[b7d3cc34] | 5428 | return NULL; |
---|
[c36f73b] | 5429 | if (!strncasecmp(which, "y", 1)) |
---|
[b7d3cc34] | 5430 | return yd->cookie_y; |
---|
[9034ba0] | 5431 | if (!strncasecmp(which, "b", 1)) |
---|
| 5432 | return yd->cookie_b; |
---|
[c36f73b] | 5433 | if (!strncasecmp(which, "t", 1)) |
---|
[b7d3cc34] | 5434 | return yd->cookie_t; |
---|
[c36f73b] | 5435 | if (!strncasecmp(which, "c", 1)) |
---|
[b7d3cc34] | 5436 | return yd->cookie_c; |
---|
[c36f73b] | 5437 | if (!strncasecmp(which, "login", 5)) |
---|
[b7d3cc34] | 5438 | return yd->login_cookie; |
---|
| 5439 | return NULL; |
---|
| 5440 | } |
---|
[509cf60] | 5441 | #endif |
---|
[b7d3cc34] | 5442 | |
---|
[9034ba0] | 5443 | const char *yahoo_get_profile_url(void) |
---|
[b7d3cc34] | 5444 | { |
---|
| 5445 | return profile_url; |
---|
| 5446 | } |
---|