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