Mon, 06 Aug 2001 17:50:46 +0000
[gaim-migrate @ 2133]
now has the ability to notify you beforehand that messages are too long. I haven't tested this yet though.
| 2086 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 5 | * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> | |
| 6 | * | |
| 7 | * This program is free software; you can redistribute it and/or modify | |
| 8 | * it under the terms of the GNU General Public License as published by | |
| 9 | * the Free Software Foundation; either version 2 of the License, or | |
| 10 | * (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | * | |
| 21 | */ | |
| 22 | ||
| 23 | #ifdef HAVE_CONFIG_H | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
24 | #include <config.h> |
| 2086 | 25 | #endif |
| 26 | ||
| 27 | ||
| 28 | #include <netdb.h> | |
| 29 | #include <gtk/gtk.h> | |
| 30 | #include <unistd.h> | |
| 31 | #include <errno.h> | |
| 32 | #include <netinet/in.h> | |
| 33 | #include <arpa/inet.h> | |
| 34 | #include <string.h> | |
| 35 | #include <stdlib.h> | |
| 36 | #include <stdio.h> | |
| 37 | #include <time.h> | |
| 38 | #include <sys/socket.h> | |
| 39 | #include <sys/stat.h> | |
| 40 | #include "multi.h" | |
| 41 | #include "prpl.h" | |
| 42 | #include "gaim.h" | |
| 43 | #include "aim.h" | |
| 44 | #include "proxy.h" | |
| 45 | ||
| 46 | #if USE_PIXBUF | |
| 47 | #include <gdk-pixbuf/gdk-pixbuf.h> | |
| 48 | #include <gdk-pixbuf/gdk-pixbuf-loader.h> | |
| 49 | #endif | |
| 50 | ||
| 51 | /*#include "pixmaps/cancel.xpm"*/ | |
| 52 | #include "pixmaps/admin_icon.xpm" | |
| 53 | #include "pixmaps/aol_icon.xpm" | |
| 54 | #include "pixmaps/away_icon.xpm" | |
| 55 | #include "pixmaps/dt_icon.xpm" | |
| 56 | #include "pixmaps/free_icon.xpm" | |
| 57 | ||
| 58 | /* constants to identify proto_opts */ | |
| 59 | #define USEROPT_AUTH 0 | |
| 60 | #define USEROPT_AUTHPORT 1 | |
| 61 | ||
| 62 | #define AIMHASHDATA "http://gaim.sourceforge.net/aim_data.php3" | |
| 63 | ||
| 64 | static int gaim_caps = AIM_CAPS_CHAT | | |
| 65 | #if USE_PIXBUF | |
| 66 | AIM_CAPS_BUDDYICON | | |
| 67 | #endif | |
| 68 | AIM_CAPS_GETFILE | | |
| 69 | AIM_CAPS_IMIMAGE; | |
| 70 | ||
| 71 | static GtkWidget *join_chat_spin = NULL; | |
| 72 | static GtkWidget *join_chat_entry = NULL; | |
| 73 | ||
| 74 | struct oscar_data { | |
| 75 | struct aim_session_t *sess; | |
| 76 | struct aim_conn_t *conn; | |
| 77 | ||
| 78 | guint cnpa; | |
| 79 | guint paspa; | |
| 80 | ||
| 81 | int create_exchange; | |
| 82 | char *create_name; | |
| 83 | ||
| 84 | gboolean conf; | |
| 85 | gboolean reqemail; | |
| 86 | gboolean chpass; | |
| 87 | char *oldp; | |
| 88 | char *newp; | |
| 89 | ||
| 90 | GSList *oscar_chats; | |
| 91 | GSList *direct_ims; | |
| 92 | GSList *getfiles; | |
| 93 | GSList *hasicons; | |
| 94 | ||
| 95 | gboolean killme; | |
| 96 | }; | |
| 97 | ||
| 98 | struct chat_connection { | |
| 99 | char *name; | |
| 100 | char *show; /* AOL did something funny to us */ | |
| 101 | int exchange; | |
| 102 | int fd; /* this is redundant since we have the conn below */ | |
| 103 | struct aim_conn_t *conn; | |
| 104 | int inpa; | |
| 105 | int id; | |
| 106 | struct gaim_connection *gc; /* i hate this. */ | |
| 107 | struct conversation *cnv; /* bah. */ | |
| 108 | }; | |
| 109 | ||
| 110 | struct direct_im { | |
| 111 | struct gaim_connection *gc; | |
| 112 | char name[80]; | |
| 113 | struct conversation *cnv; | |
| 114 | int watcher; | |
| 115 | struct aim_conn_t *conn; | |
| 116 | }; | |
| 117 | ||
| 118 | struct ask_direct { | |
| 119 | struct gaim_connection *gc; | |
| 120 | char *sn; | |
| 121 | struct aim_directim_priv *priv; | |
| 122 | }; | |
| 123 | ||
| 124 | struct ask_getfile { | |
| 125 | struct gaim_connection *gc; | |
| 126 | char *sn; | |
| 127 | char *cookie; | |
| 128 | char *ip; | |
| 129 | }; | |
| 130 | ||
| 131 | struct getfile_transfer { | |
| 132 | struct gaim_connection *gc; | |
| 133 | char *receiver; | |
| 134 | char *filename; | |
| 135 | struct aim_conn_t *conn; | |
| 136 | struct aim_fileheader_t *fh; | |
| 137 | int gip; | |
| 138 | int gop; | |
| 139 | FILE *listing; | |
| 140 | FILE *file; | |
| 141 | GtkWidget *window; | |
| 142 | GtkWidget *meter; | |
| 143 | GtkWidget *label; | |
| 144 | long pos; | |
| 145 | long size; | |
| 146 | }; | |
| 147 | ||
| 148 | #if USE_PIXBUF | |
| 149 | struct icon_req { | |
| 150 | char *user; | |
| 151 | time_t timestamp; | |
| 152 | unsigned long length; | |
| 153 | gpointer data; | |
| 154 | gboolean request; | |
| 155 | GdkPixbufAnimation *anim; | |
| 156 | GdkPixbuf *unanim; | |
| 157 | struct conversation *cnv; | |
| 158 | GtkWidget *pix; | |
| 159 | int curframe; | |
| 160 | int timer; | |
| 161 | }; | |
| 162 | #endif | |
| 163 | ||
| 164 | static struct direct_im *find_direct_im(struct oscar_data *od, char *who) { | |
| 165 | GSList *d = od->direct_ims; | |
| 166 | char *n = g_strdup(normalize(who)); | |
| 167 | struct direct_im *m = NULL; | |
| 168 | ||
| 169 | while (d) { | |
| 170 | m = (struct direct_im *)d->data; | |
| 171 | if (!strcmp(n, normalize(m->name))) | |
| 172 | break; | |
| 173 | m = NULL; | |
| 174 | d = d->next; | |
| 175 | } | |
| 176 | ||
| 177 | g_free(n); | |
| 178 | return m; | |
| 179 | } | |
| 180 | ||
| 181 | /* | |
| 182 | static struct getfile_transfer *find_getfile_transfer(struct oscar_data *od, struct aim_conn_t *conn) { | |
| 183 | GSList *g = od->getfiles; | |
| 184 | struct getfile_transfer *n = NULL; | |
| 185 | ||
| 186 | while (g) { | |
| 187 | n = (struct getfile_transfer *)g->data; | |
| 188 | if (n->conn == conn) | |
| 189 | return n; | |
| 190 | n = NULL; | |
| 191 | g = g->next; | |
| 192 | } | |
| 193 | ||
| 194 | return n; | |
| 195 | } | |
| 196 | */ | |
| 197 | ||
| 198 | static char *extract_name(char *name) { | |
| 199 | char *tmp; | |
| 200 | int i, j; | |
| 201 | char *x = strchr(name, '-'); | |
| 202 | if (!x) return NULL; | |
| 203 | x = strchr(++x, '-'); | |
| 204 | if (!x) return NULL; | |
| 205 | tmp = g_strdup(++x); | |
| 206 | ||
| 207 | for (i = 0, j = 0; x[i]; i++) { | |
| 208 | if (x[i] != '%') | |
| 209 | tmp[j++] = x[i]; | |
| 210 | else { | |
| 211 | char hex[3]; | |
| 212 | hex[0] = x[++i]; | |
| 213 | hex[1] = x[++i]; | |
| 214 | hex[2] = 0; | |
| 215 | sscanf(hex, "%x", (int *)&tmp[j++]); | |
| 216 | } | |
| 217 | } | |
| 218 | ||
| 219 | tmp[j] = 0; | |
| 220 | return tmp; | |
| 221 | } | |
| 222 | ||
| 223 | static struct chat_connection *find_oscar_chat(struct gaim_connection *gc, int id) { | |
| 224 | GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats; | |
| 225 | struct chat_connection *c = NULL; | |
| 226 | if (gc->protocol != PROTO_OSCAR) return NULL; | |
| 227 | ||
| 228 | while (g) { | |
| 229 | c = (struct chat_connection *)g->data; | |
| 230 | if (c->id == id) | |
| 231 | break; | |
| 232 | g = g->next; | |
| 233 | c = NULL; | |
| 234 | } | |
| 235 | ||
| 236 | return c; | |
| 237 | } | |
| 238 | ||
| 239 | static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc, | |
| 240 | struct aim_conn_t *conn) { | |
| 241 | GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats; | |
| 242 | struct chat_connection *c = NULL; | |
| 243 | ||
| 244 | while (g) { | |
| 245 | c = (struct chat_connection *)g->data; | |
| 246 | if (c->conn == conn) | |
| 247 | break; | |
| 248 | g = g->next; | |
| 249 | c = NULL; | |
| 250 | } | |
| 251 | ||
| 252 | return c; | |
| 253 | } | |
| 254 | ||
| 255 | static int gaim_parse_auth_resp (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 256 | static int gaim_parse_login (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 257 | static int gaim_server_ready (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 258 | static int gaim_handle_redirect (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 259 | static int gaim_info_change (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 260 | static int gaim_account_confirm (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 261 | static int gaim_parse_oncoming (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 262 | static int gaim_parse_offgoing (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 263 | static int gaim_parse_incoming_im(struct aim_session_t *, struct command_rx_struct *, ...); | |
| 264 | static int gaim_parse_misses (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 265 | static int gaim_parse_user_info (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 266 | static int gaim_parse_motd (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 267 | static int gaim_chatnav_info (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 268 | static int gaim_chat_join (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 269 | static int gaim_chat_leave (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 270 | static int gaim_chat_info_update (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 271 | static int gaim_chat_incoming_msg(struct aim_session_t *, struct command_rx_struct *, ...); | |
| 272 | static int gaim_parse_msgack (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 273 | static int gaim_parse_ratechange (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 274 | static int gaim_parse_evilnotify (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 275 | static int gaim_parse_searcherror(struct aim_session_t *, struct command_rx_struct *, ...); | |
| 276 | static int gaim_parse_searchreply(struct aim_session_t *, struct command_rx_struct *, ...); | |
| 277 | static int gaim_bosrights (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 278 | static int gaim_rateresp (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 279 | static int gaim_reportinterval (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 280 | static int gaim_parse_msgerr (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 281 | static int gaim_parse_buddyrights(struct aim_session_t *, struct command_rx_struct *, ...); | |
| 282 | static int gaim_parse_locerr (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 283 | static int gaim_parse_genericerr (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 284 | static int gaim_memrequest (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 285 | ||
| 286 | static int gaim_directim_initiate (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 287 | static int gaim_directim_incoming (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 288 | static int gaim_directim_disconnect(struct aim_session_t *, struct command_rx_struct *, ...); | |
| 289 | static int gaim_directim_typing (struct aim_session_t *, struct command_rx_struct *, ...); | |
| 290 | ||
| 291 | static char *msgerrreason[] = { | |
| 292 | "Invalid error", | |
| 293 | "Invalid SNAC", | |
| 294 | "Rate to host", | |
| 295 | "Rate to client", | |
| 296 | "Not logged in", | |
| 297 | "Service unavailable", | |
| 298 | "Service not defined", | |
| 299 | "Obsolete SNAC", | |
| 300 | "Not supported by host", | |
| 301 | "Not supported by client", | |
| 302 | "Refused by client", | |
| 303 | "Reply too big", | |
| 304 | "Responses lost", | |
| 305 | "Request denied", | |
| 306 | "Busted SNAC payload", | |
| 307 | "Insufficient rights", | |
| 308 | "In local permit/deny", | |
| 309 | "Too evil (sender)", | |
| 310 | "Too evil (receiver)", | |
| 311 | "User temporarily unavailable", | |
| 312 | "No match", | |
| 313 | "List overflow", | |
| 314 | "Request ambiguous", | |
| 315 | "Queue full", | |
| 316 | "Not while on AOL" | |
| 317 | }; | |
| 318 | static int msgerrreasonlen = 25; | |
| 319 | ||
| 320 | static void oscar_callback(gpointer data, gint source, | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
321 | GaimInputCondition condition) { |
| 2086 | 322 | struct aim_conn_t *conn = (struct aim_conn_t *)data; |
| 323 | struct aim_session_t *sess = aim_conn_getsess(conn); | |
| 324 | struct gaim_connection *gc = sess ? sess->aux_data : NULL; | |
| 325 | struct oscar_data *odata; | |
| 326 | ||
| 327 | if (!gc) { | |
| 328 | /* gc is null. we return, else we seg SIGSEG on next line. */ | |
| 329 | debug_printf("oscar callback for closed connection (1).\n"); | |
| 330 | return; | |
| 331 | } | |
| 332 | ||
| 333 | odata = (struct oscar_data *)gc->proto_data; | |
| 334 | ||
| 335 | if (!g_slist_find(connections, gc)) { | |
| 336 | /* oh boy. this is probably bad. i guess the only thing we | |
| 337 | * can really do is return? */ | |
| 338 | debug_printf("oscar callback for closed connection (2).\n"); | |
| 339 | return; | |
| 340 | } | |
| 341 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
342 | if (condition & GAIM_INPUT_READ) { |
| 2086 | 343 | if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { |
| 344 | debug_printf("got information on rendezvous\n"); | |
| 345 | if (aim_handlerendconnect(odata->sess, conn) < 0) { | |
| 346 | debug_printf(_("connection error (rend)\n")); | |
| 347 | } | |
| 348 | } else { | |
| 349 | if (aim_get_command(odata->sess, conn) >= 0) { | |
| 350 | aim_rxdispatch(odata->sess); | |
| 351 | if (odata->killme) | |
| 352 | signoff(gc); | |
| 353 | } else { | |
| 354 | if ((conn->type == AIM_CONN_TYPE_BOS) || | |
| 355 | !(aim_getconn_type(odata->sess, AIM_CONN_TYPE_BOS))) { | |
| 356 | debug_printf(_("major connection error\n")); | |
| 357 | hide_login_progress(gc, _("Disconnected.")); | |
| 358 | signoff(gc); | |
| 359 | } else if (conn->type == AIM_CONN_TYPE_CHAT) { | |
| 360 | struct chat_connection *c = find_oscar_chat_by_conn(gc, conn); | |
| 361 | char buf[BUF_LONG]; | |
| 362 | debug_printf("disconnected from chat room %s\n", c->name); | |
| 363 | c->conn = NULL; | |
| 364 | if (c->inpa > 0) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
365 | gaim_input_remove(c->inpa); |
| 2086 | 366 | c->inpa = 0; |
| 367 | c->fd = -1; | |
| 368 | aim_conn_kill(odata->sess, &conn); | |
| 369 | sprintf(buf, _("You have been disconnected from chat room %s."), c->name); | |
| 370 | do_error_dialog(buf, _("Chat Error!")); | |
| 371 | } else if (conn->type == AIM_CONN_TYPE_CHATNAV) { | |
| 372 | if (odata->cnpa > 0) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
373 | gaim_input_remove(odata->cnpa); |
| 2086 | 374 | odata->cnpa = 0; |
| 375 | debug_printf("removing chatnav input watcher\n"); | |
| 376 | if (odata->create_exchange) { | |
| 377 | odata->create_exchange = 0; | |
| 378 | g_free(odata->create_name); | |
| 379 | odata->create_name = NULL; | |
| 380 | do_error_dialog(_("Chat is currently unavailable"), | |
| 381 | _("Gaim - Chat")); | |
| 382 | } | |
| 383 | aim_conn_kill(odata->sess, &conn); | |
| 384 | } else if (conn->type == AIM_CONN_TYPE_AUTH) { | |
| 385 | if (odata->paspa > 0) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
386 | gaim_input_remove(odata->paspa); |
| 2086 | 387 | odata->paspa = 0; |
| 388 | debug_printf("removing authconn input watcher\n"); | |
| 389 | aim_conn_kill(odata->sess, &conn); | |
| 390 | } else if (conn->type == AIM_CONN_TYPE_RENDEZVOUS) { | |
| 391 | debug_printf("No handler for rendezvous disconnect (%d).\n", | |
| 392 | source); | |
| 393 | aim_conn_kill(odata->sess, &conn); | |
| 394 | } else { | |
| 395 | debug_printf("holy crap! generic connection error! %d\n", | |
| 396 | conn->type); | |
| 397 | aim_conn_kill(odata->sess, &conn); | |
| 398 | } | |
| 399 | } | |
| 400 | } | |
| 401 | } | |
| 402 | } | |
| 403 | ||
| 404 | static void oscar_debug(struct aim_session_t *sess, int level, const char *format, va_list va) { | |
| 405 | char *s = g_strdup_vprintf(format, va); | |
| 406 | char buf[256]; | |
| 407 | char *t; | |
| 408 | struct gaim_connection *gc = sess->aux_data; | |
| 409 | ||
| 410 | g_snprintf(buf, sizeof(buf), "%s %d: ", gc->username, level); | |
| 411 | t = g_strconcat(buf, s, NULL); | |
| 412 | debug_printf(t); | |
| 413 | if (t[strlen(t)-1] != '\n') | |
| 414 | debug_printf("\n"); | |
| 415 | g_free(t); | |
| 416 | g_free(s); | |
| 417 | } | |
| 418 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
419 | static void oscar_login_connect(gpointer data, gint source, GaimInputCondition cond) |
| 2086 | 420 | { |
| 421 | struct gaim_connection *gc = data; | |
| 422 | struct oscar_data *odata; | |
| 423 | struct aim_session_t *sess; | |
| 424 | struct aim_conn_t *conn; | |
| 425 | ||
| 426 | if (!g_slist_find(connections, gc)) { | |
| 427 | close(source); | |
| 428 | return; | |
| 429 | } | |
| 430 | ||
| 431 | odata = gc->proto_data; | |
| 432 | sess = odata->sess; | |
| 433 | conn = aim_getconn_type_all(sess, AIM_CONN_TYPE_AUTH); | |
| 434 | ||
| 435 | if (source < 0) { | |
| 436 | hide_login_progress(gc, _("Couldn't connect to host")); | |
| 437 | signoff(gc); | |
| 438 | return; | |
| 439 | } | |
| 440 | ||
| 441 | aim_conn_completeconnect(sess, conn); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
442 | gc->inpa = gaim_input_add(conn->fd, GAIM_INPUT_READ, |
| 2086 | 443 | oscar_callback, conn); |
| 444 | debug_printf(_("Password sent, waiting for response\n")); | |
| 445 | } | |
| 446 | ||
| 447 | static void oscar_login(struct aim_user *user) { | |
| 448 | struct aim_session_t *sess; | |
| 449 | struct aim_conn_t *conn; | |
| 450 | char buf[256]; | |
| 451 | struct gaim_connection *gc = new_gaim_conn(user); | |
| 452 | struct oscar_data *odata = gc->proto_data = g_new0(struct oscar_data, 1); | |
| 453 | odata->create_exchange = 0; | |
| 454 | ||
| 455 | debug_printf(_("Logging in %s\n"), user->username); | |
| 456 | ||
| 457 | sess = g_new0(struct aim_session_t, 1); | |
| 458 | ||
| 459 | aim_session_init(sess, AIM_SESS_FLAGS_NONBLOCKCONNECT, 0); | |
| 460 | aim_setdebuggingcb(sess, oscar_debug); | |
| 461 | ||
| 462 | /* we need an immediate queue because we don't use a while-loop to | |
| 463 | * see if things need to be sent. */ | |
| 464 | aim_tx_setenqueue(sess, AIM_TX_IMMEDIATE, NULL); | |
| 465 | odata->sess = sess; | |
| 466 | sess->aux_data = gc; | |
| 467 | ||
| 468 | conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL); | |
| 469 | if (conn == NULL) { | |
| 470 | debug_printf(_("internal connection error\n")); | |
| 471 | hide_login_progress(gc, _("Unable to login to AIM")); | |
| 472 | signoff(gc); | |
| 473 | return; | |
| 474 | } | |
| 475 | ||
| 476 | g_snprintf(buf, sizeof(buf), _("Signon: %s"), gc->username); | |
| 477 | set_login_progress(gc, 2, buf); | |
| 478 | ||
| 479 | aim_conn_addhandler(sess, conn, 0x0017, 0x0007, gaim_parse_login, 0); | |
| 480 | aim_conn_addhandler(sess, conn, 0x0017, 0x0003, gaim_parse_auth_resp, 0); | |
| 481 | ||
| 482 | conn->status |= AIM_CONN_STATUS_INPROGRESS; | |
| 483 | conn->fd = proxy_connect(user->proto_opt[USEROPT_AUTH][0] ? | |
| 484 | user->proto_opt[USEROPT_AUTH] : FAIM_LOGIN_SERVER, | |
| 485 | user->proto_opt[USEROPT_AUTHPORT][0] ? | |
| 486 | atoi(user->proto_opt[USEROPT_AUTHPORT]) : FAIM_LOGIN_PORT, | |
| 487 | oscar_login_connect, gc); | |
| 488 | if (conn->fd < 0) { | |
| 489 | hide_login_progress(gc, _("Couldn't connect to host")); | |
| 490 | signoff(gc); | |
| 491 | return; | |
| 492 | } | |
| 493 | aim_request_login(sess, conn, gc->username); | |
| 494 | } | |
| 495 | ||
| 496 | static void oscar_close(struct gaim_connection *gc) { | |
| 497 | struct oscar_data *odata = (struct oscar_data *)gc->proto_data; | |
| 498 | if (gc->protocol != PROTO_OSCAR) return; | |
| 499 | ||
| 500 | while (odata->oscar_chats) { | |
| 501 | struct chat_connection *n = odata->oscar_chats->data; | |
| 502 | if (n->inpa > 0) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
503 | gaim_input_remove(n->inpa); |
| 2086 | 504 | g_free(n->name); |
| 505 | g_free(n->show); | |
| 506 | odata->oscar_chats = g_slist_remove(odata->oscar_chats, n); | |
| 507 | g_free(n); | |
| 508 | } | |
| 509 | while (odata->direct_ims) { | |
| 510 | struct direct_im *n = odata->direct_ims->data; | |
| 511 | if (n->watcher > 0) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
512 | gaim_input_remove(n->watcher); |
| 2086 | 513 | odata->direct_ims = g_slist_remove(odata->direct_ims, n); |
| 514 | g_free(n); | |
| 515 | } | |
| 516 | #if USE_PIXBUF | |
| 517 | while (odata->hasicons) { | |
| 518 | struct icon_req *n = odata->hasicons->data; | |
| 519 | if (n->anim) | |
| 520 | gdk_pixbuf_animation_unref(n->anim); | |
| 521 | if (n->unanim) | |
| 522 | gdk_pixbuf_unref(n->unanim); | |
| 523 | if (n->timer) | |
| 524 | gtk_timeout_remove(n->timer); | |
| 525 | if (n->cnv && n->pix) | |
| 526 | gtk_container_remove(GTK_CONTAINER(n->cnv->bbox), n->pix); | |
| 527 | g_free(n->user); | |
| 528 | if (n->data) | |
| 529 | g_free(n->data); | |
| 530 | odata->hasicons = g_slist_remove(odata->hasicons, n); | |
| 531 | g_free(n); | |
| 532 | } | |
| 533 | #endif | |
| 534 | if (gc->inpa > 0) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
535 | gaim_input_remove(gc->inpa); |
| 2086 | 536 | if (odata->cnpa > 0) |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
537 | gaim_input_remove(odata->cnpa); |
| 2086 | 538 | if (odata->paspa > 0) |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
539 | gaim_input_remove(odata->paspa); |
| 2086 | 540 | aim_session_kill(odata->sess); |
| 541 | g_free(odata->sess); | |
| 542 | odata->sess = NULL; | |
| 543 | g_free(gc->proto_data); | |
| 544 | gc->proto_data = NULL; | |
| 545 | debug_printf(_("Signed off.\n")); | |
| 546 | } | |
| 547 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
548 | static void oscar_bos_connect(gpointer data, gint source, GaimInputCondition cond) { |
| 2086 | 549 | struct gaim_connection *gc = data; |
| 550 | struct oscar_data *odata; | |
| 551 | struct aim_session_t *sess; | |
| 552 | struct aim_conn_t *bosconn; | |
| 553 | ||
| 554 | if (!g_slist_find(connections, gc)) { | |
| 555 | close(source); | |
| 556 | return; | |
| 557 | } | |
| 558 | ||
| 559 | odata = gc->proto_data; | |
| 560 | sess = odata->sess; | |
| 561 | bosconn = odata->conn; | |
| 562 | ||
| 563 | if (source < 0) { | |
| 564 | hide_login_progress(gc, _("Could Not Connect")); | |
| 565 | signoff(gc); | |
| 566 | return; | |
| 567 | } | |
| 568 | ||
| 569 | aim_conn_completeconnect(sess, bosconn); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
570 | gc->inpa = gaim_input_add(bosconn->fd, GAIM_INPUT_READ, |
| 2086 | 571 | oscar_callback, bosconn); |
| 572 | set_login_progress(gc, 4, _("Connection established, cookie sent")); | |
| 573 | } | |
| 574 | ||
| 575 | int gaim_parse_auth_resp(struct aim_session_t *sess, | |
| 576 | struct command_rx_struct *command, ...) { | |
| 577 | va_list ap; | |
| 578 | struct aim_conn_t *bosconn = NULL; | |
| 579 | char *sn = NULL, *bosip = NULL, *errurl = NULL, *email = NULL; | |
| 580 | unsigned char *cookie = NULL; | |
| 581 | int errorcode = 0, regstatus = 0; | |
| 582 | int latestbuild = 0, latestbetabuild = 0; | |
| 583 | char *latestrelease = NULL, *latestbeta = NULL; | |
| 584 | char *latestreleaseurl = NULL, *latestbetaurl = NULL; | |
| 585 | char *latestreleaseinfo = NULL, *latestbetainfo = NULL; | |
| 586 | int i; char *host; int port; | |
| 587 | struct aim_user *user; | |
| 588 | ||
| 589 | struct gaim_connection *gc = sess->aux_data; | |
| 590 | struct oscar_data *od = gc->proto_data; | |
| 591 | user = gc->user; | |
| 592 | port = user->proto_opt[USEROPT_AUTHPORT][0] ? | |
| 593 | atoi(user->proto_opt[USEROPT_AUTHPORT]) : FAIM_LOGIN_PORT, | |
| 594 | ||
| 595 | va_start(ap, command); | |
| 596 | sn = va_arg(ap, char *); | |
| 597 | errorcode = va_arg(ap, int); | |
| 598 | errurl = va_arg(ap, char *); | |
| 599 | regstatus = va_arg(ap, int); | |
| 600 | email = va_arg(ap, char *); | |
| 601 | bosip = va_arg(ap, char *); | |
| 602 | cookie = va_arg(ap, unsigned char *); | |
| 603 | ||
| 604 | latestrelease = va_arg(ap, char *); | |
| 605 | latestbuild = va_arg(ap, int); | |
| 606 | latestreleaseurl = va_arg(ap, char *); | |
| 607 | latestreleaseinfo = va_arg(ap, char *); | |
| 608 | ||
| 609 | latestbeta = va_arg(ap, char *); | |
| 610 | latestbetabuild = va_arg(ap, int); | |
| 611 | latestbetaurl = va_arg(ap, char *); | |
| 612 | latestbetainfo = va_arg(ap, char *); | |
| 613 | ||
| 614 | va_end(ap); | |
| 615 | ||
| 616 | debug_printf("inside auth_resp (Screen name: %s)\n", sn); | |
| 617 | ||
| 618 | if (errorcode || !bosip || !cookie) { | |
| 619 | switch (errorcode) { | |
| 620 | case 0x05: | |
| 621 | /* Incorrect nick/password */ | |
| 622 | hide_login_progress(gc, _("Incorrect nickname or password.")); | |
| 623 | plugin_event(event_error, (void *)980, 0, 0, 0); | |
| 624 | break; | |
| 625 | case 0x11: | |
| 626 | /* Suspended account */ | |
| 627 | hide_login_progress(gc, _("Your account is currently suspended.")); | |
| 628 | break; | |
| 629 | case 0x18: | |
| 630 | /* connecting too frequently */ | |
| 631 | hide_login_progress(gc, _("You have been connecting and disconnecting too frequently. Wait ten minutes and try again. If you continue to try, you will need to wait even longer.")); | |
| 632 | plugin_event(event_error, (void *)983, 0, 0, 0); | |
| 633 | break; | |
| 634 | case 0x1c: | |
| 635 | /* client too old */ | |
| 636 | hide_login_progress(gc, _("The client version you are using is too old. Please upgrade at " WEBSITE)); | |
| 637 | plugin_event(event_error, (void *)989, 0, 0, 0); | |
| 638 | break; | |
| 639 | default: | |
| 640 | hide_login_progress(gc, _("Authentication Failed")); | |
| 641 | break; | |
| 642 | } | |
| 643 | debug_printf("Login Error Code 0x%04x\n", errorcode); | |
| 644 | debug_printf("Error URL: %s\n", errurl); | |
| 645 | od->killme = TRUE; | |
| 646 | return 1; | |
| 647 | } | |
| 648 | ||
| 649 | ||
| 650 | debug_printf("Reg status: %2d\n", regstatus); | |
| 651 | if (email) { | |
| 652 | debug_printf("Email: %s\n", email); | |
| 653 | } else { | |
| 654 | debug_printf("Email is NULL\n"); | |
| 655 | } | |
| 656 | debug_printf("BOSIP: %s\n", bosip); | |
| 657 | if (latestbeta) | |
| 658 | debug_printf("Latest WinAIM beta version %s, build %d, at %s (%s)\n", | |
| 659 | latestbeta, latestbetabuild, latestbetaurl, latestbetainfo); | |
| 660 | if (latestrelease) | |
| 661 | debug_printf("Latest WinAIM released version %s, build %d, at %s (%s)\n", | |
| 662 | latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo); | |
| 663 | debug_printf("Closing auth connection...\n"); | |
| 664 | aim_conn_kill(sess, &command->conn); | |
| 665 | ||
| 666 | bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, NULL); | |
| 667 | if (bosconn == NULL) { | |
| 668 | hide_login_progress(gc, _("Internal Error")); | |
| 669 | od->killme = TRUE; | |
| 670 | return 0; | |
| 671 | } | |
| 672 | ||
| 673 | aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, gaim_bosrights, 0); | |
| 674 | aim_conn_addhandler(sess, bosconn, 0x0001, 0x0007, gaim_rateresp, 0); /* rate info */ | |
| 675 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0); | |
| 676 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, gaim_server_ready, 0); | |
| 677 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATEINFO, NULL, 0); | |
| 678 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, gaim_handle_redirect, 0); | |
| 679 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, gaim_reportinterval, 0); | |
| 680 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_RIGHTSINFO, gaim_parse_buddyrights, 0); | |
| 681 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, gaim_parse_oncoming, 0); | |
| 682 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, gaim_parse_offgoing, 0); | |
| 683 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, gaim_parse_incoming_im, 0); | |
| 684 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, gaim_parse_locerr, 0); | |
| 685 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, gaim_parse_misses, 0); | |
| 686 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, gaim_parse_ratechange, 0); | |
| 687 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_EVIL, gaim_parse_evilnotify, 0); | |
| 688 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOK, AIM_CB_LOK_ERROR, gaim_parse_searcherror, 0); | |
| 689 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOK, 0x0003, gaim_parse_searchreply, 0); | |
| 690 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, gaim_parse_msgerr, 0); | |
| 691 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, gaim_parse_user_info, 0); | |
| 692 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, gaim_parse_msgack, 0); | |
| 693 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); | |
| 694 | aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, gaim_parse_genericerr, 0); | |
| 695 | aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, gaim_parse_genericerr, 0); | |
| 696 | aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, gaim_parse_genericerr, 0); | |
| 697 | aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, gaim_memrequest, 0); | |
| 698 | ||
| 699 | ((struct oscar_data *)gc->proto_data)->conn = bosconn; | |
| 700 | for (i = 0; i < (int)strlen(bosip); i++) { | |
| 701 | if (bosip[i] == ':') { | |
| 702 | port = atoi(&(bosip[i+1])); | |
| 703 | break; | |
| 704 | } | |
| 705 | } | |
| 706 | host = g_strndup(bosip, i); | |
| 707 | bosconn->status |= AIM_CONN_STATUS_INPROGRESS; | |
| 708 | bosconn->fd = proxy_connect(host, port, oscar_bos_connect, gc); | |
| 709 | g_free(host); | |
| 710 | if (bosconn->fd < 0) { | |
| 711 | hide_login_progress(gc, _("Could Not Connect")); | |
| 712 | od->killme = TRUE; | |
| 713 | return 0; | |
| 714 | } | |
| 715 | aim_auth_sendcookie(sess, bosconn, cookie); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
716 | gaim_input_remove(gc->inpa); |
| 2086 | 717 | return 1; |
| 718 | } | |
| 719 | ||
| 720 | struct pieceofcrap { | |
| 721 | struct gaim_connection *gc; | |
| 722 | unsigned long offset; | |
| 723 | unsigned long len; | |
| 724 | char *modname; | |
| 725 | int fd; | |
| 726 | struct aim_conn_t *conn; | |
| 727 | unsigned int inpa; | |
| 728 | }; | |
| 729 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
730 | static void damn_you(gpointer data, gint source, GaimInputCondition c) |
| 2086 | 731 | { |
| 732 | struct pieceofcrap *pos = data; | |
| 733 | struct oscar_data *od = pos->gc->proto_data; | |
| 734 | char in = '\0'; | |
| 735 | int x = 0; | |
| 736 | unsigned char m[17]; | |
| 737 | ||
| 738 | while (read(pos->fd, &in, 1) == 1) { | |
| 739 | if (in == '\n') | |
| 740 | x++; | |
| 741 | else if (in != '\r') | |
| 742 | x = 0; | |
| 743 | if (x == 2) | |
| 744 | break; | |
| 745 | in = '\0'; | |
| 746 | } | |
| 747 | if (in != '\n') { | |
| 748 | do_error_dialog("Gaim was unable to get a valid hash for logging into AIM." | |
| 749 | " You may be disconnected shortly.", "Login Error"); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
750 | gaim_input_remove(pos->inpa); |
| 2086 | 751 | close(pos->fd); |
| 752 | g_free(pos); | |
| 753 | return; | |
| 754 | } | |
| 755 | read(pos->fd, m, 16); | |
| 756 | m[16] = '\0'; | |
| 757 | debug_printf("Sending hash: "); | |
| 758 | for (x = 0; x < 16; x++) | |
| 759 | debug_printf("%02x ", (unsigned char)m[x]); | |
| 760 | debug_printf("\n"); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
761 | gaim_input_remove(pos->inpa); |
| 2086 | 762 | close(pos->fd); |
| 763 | aim_sendmemblock(od->sess, pos->conn, 0, 16, m, AIM_SENDMEMBLOCK_FLAG_ISHASH); | |
| 764 | g_free(pos); | |
| 765 | } | |
| 766 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
767 | static void straight_to_hell(gpointer data, gint source, GaimInputCondition cond) { |
| 2086 | 768 | struct pieceofcrap *pos = data; |
| 769 | char buf[BUF_LONG]; | |
| 770 | ||
| 771 | if (source < 0) { | |
| 772 | do_error_dialog("Gaim was unable to get a valid hash for logging into AIM." | |
| 773 | " You may be disconnected shortly.", "Login Error"); | |
| 774 | if (pos->modname) | |
| 775 | g_free(pos->modname); | |
| 776 | g_free(pos); | |
| 777 | return; | |
| 778 | } | |
| 779 | ||
| 780 | g_snprintf(buf, sizeof(buf), "GET " AIMHASHDATA | |
| 781 | "?offset=%ld&len=%ld&modname=%s HTTP/1.0\n\n", | |
| 782 | pos->offset, pos->len, pos->modname ? pos->modname : ""); | |
| 783 | write(pos->fd, buf, strlen(buf)); | |
| 784 | if (pos->modname) | |
| 785 | g_free(pos->modname); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
786 | pos->inpa = gaim_input_add(pos->fd, GAIM_INPUT_READ, damn_you, pos); |
| 2086 | 787 | return; |
| 788 | } | |
| 789 | ||
| 790 | /* size of icbmui.ocm, the largest module in AIM 3.5 */ | |
| 791 | #define AIM_MAX_FILE_SIZE 98304 | |
| 792 | ||
| 793 | int gaim_memrequest(struct aim_session_t *sess, | |
| 794 | struct command_rx_struct *command, ...) { | |
| 795 | va_list ap; | |
| 796 | struct pieceofcrap *pos; | |
| 797 | unsigned long offset, len; | |
| 798 | char *modname; | |
| 799 | int fd; | |
| 800 | ||
| 801 | va_start(ap, command); | |
| 802 | offset = va_arg(ap, unsigned long); | |
| 803 | len = va_arg(ap, unsigned long); | |
| 804 | modname = va_arg(ap, char *); | |
| 805 | va_end(ap); | |
| 806 | ||
| 807 | debug_printf("offset: %d, len: %d, file: %s\n", offset, len, modname ? modname : "aim.exe"); | |
| 808 | if (len == 0) { | |
| 809 | debug_printf("len is 0, hashing NULL\n"); | |
| 810 | aim_sendmemblock(sess, command->conn, offset, len, NULL, | |
| 811 | AIM_SENDMEMBLOCK_FLAG_ISREQUEST); | |
| 812 | return 1; | |
| 813 | } | |
| 814 | /* uncomment this when you're convinced it's right. remember, it's been wrong before. | |
| 815 | if (offset > AIM_MAX_FILE_SIZE || len > AIM_MAX_FILE_SIZE) { | |
| 816 | char *buf; | |
| 817 | int i = 8; | |
| 818 | if (modname) | |
| 819 | i += strlen(modname); | |
| 820 | buf = g_malloc(i); | |
| 821 | i = 0; | |
| 822 | if (modname) { | |
| 823 | memcpy(buf, modname, strlen(modname)); | |
| 824 | i += strlen(modname); | |
| 825 | } | |
| 826 | buf[i++] = offset & 0xff; | |
| 827 | buf[i++] = (offset >> 8) & 0xff; | |
| 828 | buf[i++] = (offset >> 16) & 0xff; | |
| 829 | buf[i++] = (offset >> 24) & 0xff; | |
| 830 | buf[i++] = len & 0xff; | |
| 831 | buf[i++] = (len >> 8) & 0xff; | |
| 832 | buf[i++] = (len >> 16) & 0xff; | |
| 833 | buf[i++] = (len >> 24) & 0xff; | |
| 834 | debug_printf("len + offset is invalid, hashing request\n"); | |
| 835 | aim_sendmemblock(sess, command->conn, offset, i, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST); | |
| 836 | g_free(buf); | |
| 837 | return 1; | |
| 838 | } | |
| 839 | */ | |
| 840 | ||
| 841 | pos = g_new0(struct pieceofcrap, 1); | |
| 842 | pos->gc = sess->aux_data; | |
| 843 | pos->conn = command->conn; | |
| 844 | ||
| 845 | pos->offset = offset; | |
| 846 | pos->len = len; | |
| 847 | pos->modname = modname ? g_strdup(modname) : NULL; | |
| 848 | ||
| 849 | fd = proxy_connect("gaim.sourceforge.net", 80, straight_to_hell, pos); | |
| 850 | if (fd < 0) { | |
| 851 | if (pos->modname) | |
| 852 | g_free(pos->modname); | |
| 853 | g_free(pos); | |
| 854 | do_error_dialog("Gaim was unable to get a valid hash for logging into AIM." | |
| 855 | " You may be disconnected shortly.", "Login Error"); | |
| 856 | } | |
| 857 | pos->fd = fd; | |
| 858 | ||
| 859 | return 1; | |
| 860 | } | |
| 861 | ||
| 862 | int gaim_parse_login(struct aim_session_t *sess, | |
| 863 | struct command_rx_struct *command, ...) { | |
| 864 | #if 0 | |
| 865 | struct client_info_s info = {"gaim", 4, 1, 2010, "us", "en", 0x0004, 0x0000, 0x04b}; | |
| 866 | #else | |
| 867 | struct client_info_s info = AIM_CLIENTINFO_KNOWNGOOD; | |
| 868 | #endif | |
| 869 | char *key; | |
| 870 | va_list ap; | |
| 871 | struct gaim_connection *gc = sess->aux_data; | |
| 872 | ||
| 873 | va_start(ap, command); | |
| 874 | key = va_arg(ap, char *); | |
| 875 | va_end(ap); | |
| 876 | ||
| 877 | aim_send_login(sess, command->conn, gc->username, gc->password, &info, key); | |
| 878 | return 1; | |
| 879 | } | |
| 880 | ||
| 881 | int gaim_server_ready(struct aim_session_t *sess, | |
| 882 | struct command_rx_struct *command, ...) { | |
| 883 | static int id = 1; | |
| 884 | struct gaim_connection *gc = sess->aux_data; | |
| 885 | struct oscar_data *od = gc->proto_data; | |
| 886 | struct chat_connection *chatcon; | |
| 887 | switch (command->conn->type) { | |
| 888 | case AIM_CONN_TYPE_AUTH: | |
| 889 | aim_auth_setversions(sess, command->conn); | |
| 890 | aim_bos_reqrate(sess, command->conn); | |
| 891 | debug_printf("done with AUTH ServerReady\n"); | |
| 892 | if (od->chpass) { | |
| 893 | debug_printf("changing password\n"); | |
| 894 | aim_auth_changepasswd(sess, command->conn, od->newp, od->oldp); | |
| 895 | g_free(od->oldp); | |
| 896 | g_free(od->newp); | |
| 897 | od->chpass = FALSE; | |
| 898 | } | |
| 899 | if (od->conf) { | |
| 900 | debug_printf("confirming account\n"); | |
| 901 | aim_auth_reqconfirm(sess, command->conn); | |
| 902 | od->conf = FALSE; | |
| 903 | } | |
| 904 | if (od->reqemail) { | |
| 905 | debug_printf("requesting email\n"); | |
| 906 | aim_auth_getinfo(sess, command->conn, 0x0011); | |
| 907 | od->reqemail = FALSE; | |
| 908 | } | |
| 909 | break; | |
| 910 | case AIM_CONN_TYPE_BOS: | |
| 911 | aim_setversions(sess, command->conn); | |
| 912 | aim_bos_reqrate(sess, command->conn); /* request rate info */ | |
| 913 | debug_printf("done with BOS ServerReady\n"); | |
| 914 | break; | |
| 915 | case AIM_CONN_TYPE_CHATNAV: | |
| 916 | debug_printf("chatnav: got server ready\n"); | |
| 917 | aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CTN, AIM_CB_CTN_INFO, gaim_chatnav_info, 0); | |
| 918 | aim_bos_reqrate(sess, command->conn); | |
| 919 | aim_bos_ackrateresp(sess, command->conn); | |
| 920 | aim_chatnav_clientready(sess, command->conn); | |
| 921 | aim_chatnav_reqrights(sess, command->conn); | |
| 922 | break; | |
| 923 | case AIM_CONN_TYPE_CHAT: | |
| 924 | debug_printf("chat: got server ready\n"); | |
| 925 | aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, gaim_chat_join, 0); | |
| 926 | aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, gaim_chat_leave, 0); | |
| 927 | aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, gaim_chat_info_update, 0); | |
| 928 | aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, gaim_chat_incoming_msg, 0); | |
| 929 | aim_bos_reqrate(sess, command->conn); | |
| 930 | aim_bos_ackrateresp(sess, command->conn); | |
| 931 | aim_chat_clientready(sess, command->conn); | |
| 932 | chatcon = find_oscar_chat_by_conn(gc, command->conn); | |
| 933 | chatcon->id = id; | |
| 934 | chatcon->cnv = serv_got_joined_chat(gc, id++, chatcon->show); | |
| 935 | break; | |
| 936 | case AIM_CONN_TYPE_RENDEZVOUS: | |
| 937 | break; | |
| 938 | default: /* huh? */ | |
| 939 | debug_printf("server ready: got unexpected connection type %04x\n", command->conn->type); | |
| 940 | break; | |
| 941 | } | |
| 942 | return 1; | |
| 943 | } | |
| 944 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
945 | static void oscar_chatnav_connect(gpointer data, gint source, GaimInputCondition cond) |
| 2086 | 946 | { |
| 947 | struct gaim_connection *gc = data; | |
| 948 | struct oscar_data *odata; | |
| 949 | struct aim_session_t *sess; | |
| 950 | struct aim_conn_t *tstconn; | |
| 951 | ||
| 952 | if (!g_slist_find(connections, gc)) { | |
| 953 | close(source); | |
| 954 | return; | |
| 955 | } | |
| 956 | ||
| 957 | odata = gc->proto_data; | |
| 958 | sess = odata->sess; | |
| 959 | tstconn = aim_getconn_type_all(sess, AIM_CONN_TYPE_CHATNAV); | |
| 960 | ||
| 961 | if (source < 0) { | |
| 962 | aim_conn_kill(sess, &tstconn); | |
| 963 | debug_printf("unable to connect to chatnav server\n"); | |
| 964 | return; | |
| 965 | } | |
| 966 | ||
| 967 | aim_conn_completeconnect(sess, tstconn); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
968 | odata->cnpa = gaim_input_add(tstconn->fd, GAIM_INPUT_READ, |
| 2086 | 969 | oscar_callback, tstconn); |
| 970 | debug_printf("chatnav: connected\n"); | |
| 971 | } | |
| 972 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
973 | static void oscar_auth_connect(gpointer data, gint source, GaimInputCondition cond) |
| 2086 | 974 | { |
| 975 | struct gaim_connection *gc = data; | |
| 976 | struct oscar_data *odata; | |
| 977 | struct aim_session_t *sess; | |
| 978 | struct aim_conn_t *tstconn; | |
| 979 | ||
| 980 | if (!g_slist_find(connections, gc)) { | |
| 981 | close(source); | |
| 982 | return; | |
| 983 | } | |
| 984 | ||
| 985 | odata = gc->proto_data; | |
| 986 | sess = odata->sess; | |
| 987 | tstconn = aim_getconn_type_all(sess, AIM_CONN_TYPE_AUTH); | |
| 988 | ||
| 989 | if (source < 0) { | |
| 990 | aim_conn_kill(sess, &tstconn); | |
| 991 | debug_printf("unable to connect to authorizer\n"); | |
| 992 | return; | |
| 993 | } | |
| 994 | ||
| 995 | aim_conn_completeconnect(sess, tstconn); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
996 | odata->paspa = gaim_input_add(tstconn->fd, GAIM_INPUT_READ, |
| 2086 | 997 | oscar_callback, tstconn); |
| 998 | debug_printf("chatnav: connected\n"); | |
| 999 | } | |
| 1000 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1001 | static void oscar_chat_connect(gpointer data, gint source, GaimInputCondition cond) |
| 2086 | 1002 | { |
| 1003 | struct chat_connection *ccon = data; | |
| 1004 | struct gaim_connection *gc = ccon->gc; | |
| 1005 | struct oscar_data *odata; | |
| 1006 | struct aim_session_t *sess; | |
| 1007 | struct aim_conn_t *tstconn; | |
| 1008 | ||
| 1009 | if (!g_slist_find(connections, gc)) { | |
| 1010 | close(source); | |
| 1011 | g_free(ccon->show); | |
| 1012 | g_free(ccon->name); | |
| 1013 | g_free(ccon); | |
| 1014 | return; | |
| 1015 | } | |
| 1016 | ||
| 1017 | odata = gc->proto_data; | |
| 1018 | sess = odata->sess; | |
| 1019 | tstconn = ccon->conn; | |
| 1020 | ||
| 1021 | if (source < 0) { | |
| 1022 | aim_conn_kill(sess, &tstconn); | |
| 1023 | g_free(ccon->show); | |
| 1024 | g_free(ccon->name); | |
| 1025 | g_free(ccon); | |
| 1026 | return; | |
| 1027 | } | |
| 1028 | ||
| 1029 | aim_conn_completeconnect(sess, ccon->conn); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1030 | ccon->inpa = gaim_input_add(tstconn->fd, |
|
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1031 | GAIM_INPUT_READ, |
| 2086 | 1032 | oscar_callback, tstconn); |
| 1033 | odata->oscar_chats = g_slist_append(odata->oscar_chats, ccon); | |
| 1034 | aim_chat_attachname(tstconn, ccon->name); | |
| 1035 | } | |
| 1036 | ||
| 1037 | int gaim_handle_redirect(struct aim_session_t *sess, | |
| 1038 | struct command_rx_struct *command, ...) { | |
| 1039 | va_list ap; | |
| 1040 | int serviceid; | |
| 1041 | char *ip; | |
| 1042 | unsigned char *cookie; | |
| 1043 | struct gaim_connection *gc = sess->aux_data; | |
| 1044 | struct aim_user *user = gc->user; | |
| 1045 | struct aim_conn_t *tstconn; | |
| 1046 | int i; | |
| 1047 | char *host; | |
| 1048 | int port; | |
| 1049 | ||
| 1050 | port = user->proto_opt[USEROPT_AUTHPORT][0] ? | |
| 1051 | atoi(user->proto_opt[USEROPT_AUTHPORT]) : FAIM_LOGIN_PORT, | |
| 1052 | ||
| 1053 | va_start(ap, command); | |
| 1054 | serviceid = va_arg(ap, int); | |
| 1055 | ip = va_arg(ap, char *); | |
| 1056 | cookie = va_arg(ap, unsigned char *); | |
| 1057 | ||
| 1058 | for (i = 0; i < (int)strlen(ip); i++) { | |
| 1059 | if (ip[i] == ':') { | |
| 1060 | port = atoi(&(ip[i+1])); | |
| 1061 | break; | |
| 1062 | } | |
| 1063 | } | |
| 1064 | host = g_strndup(ip, i); | |
| 1065 | ||
| 1066 | switch(serviceid) { | |
| 1067 | case 0x7: /* Authorizer */ | |
| 1068 | debug_printf("Reconnecting with authorizor...\n"); | |
| 1069 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL); | |
| 1070 | if (tstconn == NULL) { | |
| 1071 | debug_printf("unable to reconnect with authorizer\n"); | |
| 1072 | g_free(host); | |
| 1073 | return 1; | |
| 1074 | } | |
| 1075 | aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); | |
| 1076 | aim_conn_addhandler(sess, tstconn, 0x0001, 0x0007, gaim_rateresp, 0); | |
| 1077 | aim_conn_addhandler(sess, tstconn, 0x0007, 0x0003, gaim_info_change, 0); | |
| 1078 | aim_conn_addhandler(sess, tstconn, 0x0007, 0x0005, gaim_info_change, 0); | |
| 1079 | aim_conn_addhandler(sess, tstconn, 0x0007, 0x0007, gaim_account_confirm, 0); | |
| 1080 | ||
| 1081 | tstconn->status |= AIM_CONN_STATUS_INPROGRESS; | |
| 1082 | tstconn->fd = proxy_connect(host, port, oscar_auth_connect, gc); | |
| 1083 | if (tstconn->fd < 0) { | |
| 1084 | aim_conn_kill(sess, &tstconn); | |
| 1085 | debug_printf("unable to reconnect with authorizer\n"); | |
| 1086 | g_free(host); | |
| 1087 | return 1; | |
| 1088 | } | |
| 1089 | aim_auth_sendcookie(sess, tstconn, cookie); | |
| 1090 | break; | |
| 1091 | case 0xd: /* ChatNav */ | |
| 1092 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, NULL); | |
| 1093 | if (tstconn == NULL) { | |
| 1094 | debug_printf("unable to connect to chatnav server\n"); | |
| 1095 | g_free(host); | |
| 1096 | return 1; | |
| 1097 | } | |
| 1098 | aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); | |
| 1099 | ||
| 1100 | tstconn->status |= AIM_CONN_STATUS_INPROGRESS; | |
| 1101 | tstconn->fd = proxy_connect(host, port, oscar_chatnav_connect, gc); | |
| 1102 | if (tstconn->fd < 0) { | |
| 1103 | aim_conn_kill(sess, &tstconn); | |
| 1104 | debug_printf("unable to connect to chatnav server\n"); | |
| 1105 | g_free(host); | |
| 1106 | return 1; | |
| 1107 | } | |
| 1108 | aim_auth_sendcookie(sess, tstconn, cookie); | |
| 1109 | break; | |
| 1110 | case 0xe: /* Chat */ | |
| 1111 | { | |
| 1112 | char *roomname = va_arg(ap, char *); | |
| 1113 | int exchange = va_arg(ap, int); | |
| 1114 | struct chat_connection *ccon; | |
| 1115 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, NULL); | |
| 1116 | if (tstconn == NULL) { | |
| 1117 | debug_printf("unable to connect to chat server\n"); | |
| 1118 | g_free(host); | |
| 1119 | return 1; | |
| 1120 | } | |
| 1121 | ||
| 1122 | aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); | |
| 1123 | ccon = g_new0(struct chat_connection, 1); | |
| 1124 | ccon->conn = tstconn; | |
| 1125 | ccon->gc = gc; | |
| 1126 | ccon->fd = -1; | |
| 1127 | ccon->name = g_strdup(roomname); | |
| 1128 | ccon->exchange = exchange; | |
| 1129 | ccon->show = extract_name(roomname); | |
| 1130 | ||
| 1131 | ccon->conn->status |= AIM_CONN_STATUS_INPROGRESS; | |
| 1132 | ccon->conn->fd = proxy_connect(host, port, oscar_chat_connect, ccon); | |
| 1133 | if (ccon->conn->fd < 0) { | |
| 1134 | aim_conn_kill(sess, &tstconn); | |
| 1135 | debug_printf("unable to connect to chat server\n"); | |
| 1136 | g_free(host); | |
| 1137 | g_free(ccon->show); | |
| 1138 | g_free(ccon->name); | |
| 1139 | g_free(ccon); | |
| 1140 | return 1; | |
| 1141 | } | |
| 1142 | aim_auth_sendcookie(sess, tstconn, cookie); | |
| 1143 | debug_printf("Connected to chat room %s exchange %d\n", roomname, exchange); | |
| 1144 | } | |
| 1145 | break; | |
| 1146 | default: /* huh? */ | |
| 1147 | debug_printf("got redirect for unknown service 0x%04x\n", serviceid); | |
| 1148 | break; | |
| 1149 | } | |
| 1150 | ||
| 1151 | va_end(ap); | |
| 1152 | ||
| 1153 | g_free(host); | |
| 1154 | return 1; | |
| 1155 | } | |
| 1156 | ||
| 1157 | int gaim_parse_oncoming(struct aim_session_t *sess, | |
| 1158 | struct command_rx_struct *command, ...) { | |
| 1159 | struct aim_userinfo_s *info; | |
| 1160 | time_t time_idle; | |
| 1161 | int type = 0; | |
| 1162 | struct gaim_connection *gc = sess->aux_data; | |
| 1163 | ||
| 1164 | va_list ap; | |
| 1165 | va_start(ap, command); | |
| 1166 | info = va_arg(ap, struct aim_userinfo_s *); | |
| 1167 | va_end(ap); | |
| 1168 | ||
| 1169 | if (info->flags & AIM_FLAG_UNCONFIRMED) | |
| 1170 | type |= UC_UNCONFIRMED; | |
| 1171 | else if (info->flags & AIM_FLAG_ADMINISTRATOR) | |
| 1172 | type |= UC_ADMIN; | |
| 1173 | else if (info->flags & AIM_FLAG_AOL) | |
| 1174 | type |= UC_AOL; | |
| 1175 | else if (info->flags & AIM_FLAG_FREE) | |
| 1176 | type |= UC_NORMAL; | |
| 1177 | if (info->flags & AIM_FLAG_AWAY) | |
| 1178 | type |= UC_UNAVAILABLE; | |
| 1179 | ||
| 1180 | if (info->idletime) { | |
| 1181 | time(&time_idle); | |
| 1182 | time_idle -= info->idletime*60; | |
| 1183 | } else | |
| 1184 | time_idle = 0; | |
| 1185 | ||
| 1186 | serv_got_update(gc, info->sn, 1, info->warnlevel/10, info->onlinesince, | |
| 1187 | time_idle, type, info->capabilities); | |
| 1188 | ||
| 1189 | return 1; | |
| 1190 | } | |
| 1191 | ||
| 1192 | int gaim_parse_offgoing(struct aim_session_t *sess, | |
| 1193 | struct command_rx_struct *command, ...) { | |
| 1194 | struct aim_userinfo_s *info; | |
| 1195 | va_list ap; | |
| 1196 | struct gaim_connection *gc = sess->aux_data; | |
| 1197 | ||
| 1198 | va_start(ap, command); | |
| 1199 | info = va_arg(ap, struct aim_userinfo_s *); | |
| 1200 | va_end(ap); | |
| 1201 | ||
| 1202 | serv_got_update(gc, info->sn, 0, 0, 0, 0, 0, 0); | |
| 1203 | ||
| 1204 | return 1; | |
| 1205 | } | |
| 1206 | ||
| 1207 | static void cancel_direct_im(gpointer w, struct ask_direct *d) { | |
| 1208 | debug_printf("Freeing DirectIM prompts.\n"); | |
| 1209 | ||
| 1210 | g_free(d->sn); | |
| 1211 | g_free(d); | |
| 1212 | } | |
| 1213 | ||
| 1214 | static void delete_direct_im(gpointer w, struct direct_im *d) { | |
| 1215 | struct oscar_data *od = (struct oscar_data *)d->gc->proto_data; | |
| 1216 | ||
| 1217 | od->direct_ims = g_slist_remove(od->direct_ims, d); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1218 | gaim_input_remove(d->watcher); |
| 2086 | 1219 | aim_conn_kill(od->sess, &d->conn); |
| 1220 | g_free(d); | |
| 1221 | } | |
| 1222 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1223 | static void oscar_directim_callback(gpointer data, gint source, GaimInputCondition condition) { |
| 2086 | 1224 | struct direct_im *dim = data; |
| 1225 | struct gaim_connection *gc = dim->gc; | |
| 1226 | struct oscar_data *od = gc->proto_data; | |
| 1227 | char buf[256]; | |
| 1228 | ||
| 1229 | if (!g_slist_find(connections, gc)) { | |
| 1230 | g_free(dim); | |
| 1231 | return; | |
| 1232 | } | |
| 1233 | ||
| 1234 | if (source < 0) { | |
| 1235 | g_free(dim); | |
| 1236 | return; | |
| 1237 | } | |
| 1238 | ||
| 1239 | aim_conn_completeconnect(od->sess, dim->conn); | |
| 1240 | if (!(dim->cnv = find_conversation(dim->name))) dim->cnv = new_conversation(dim->name); | |
| 1241 | g_snprintf(buf, sizeof buf, _("Direct IM with %s established"), dim->name); | |
| 1242 | write_to_conv(dim->cnv, buf, WFLAG_SYSTEM, NULL, time((time_t)NULL)); | |
| 1243 | ||
| 1244 | od->direct_ims = g_slist_append(od->direct_ims, dim); | |
| 1245 | ||
| 1246 | gtk_signal_connect(GTK_OBJECT(dim->cnv->window), "destroy", | |
| 1247 | GTK_SIGNAL_FUNC(delete_direct_im), dim); | |
| 1248 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1249 | dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, |
| 2086 | 1250 | oscar_callback, dim->conn); |
| 1251 | } | |
| 1252 | ||
| 1253 | static int accept_direct_im(gpointer w, struct ask_direct *d) { | |
| 1254 | struct gaim_connection *gc = d->gc; | |
| 1255 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 1256 | struct direct_im *dim; | |
| 1257 | char *host; int port = FAIM_LOGIN_PORT; | |
| 1258 | int i; | |
| 1259 | ||
| 1260 | debug_printf("Accepted DirectIM.\n"); | |
| 1261 | ||
| 1262 | dim = find_direct_im(od, d->sn); | |
| 1263 | if (dim) { | |
| 1264 | cancel_direct_im(w, d); /* 40 */ | |
| 1265 | return TRUE; | |
| 1266 | } | |
| 1267 | dim = g_new0(struct direct_im, 1); | |
| 1268 | dim->gc = d->gc; | |
| 1269 | g_snprintf(dim->name, sizeof dim->name, "%s", d->sn); | |
| 1270 | ||
| 1271 | if ((dim->conn = aim_newconn(od->sess, AIM_CONN_TYPE_RENDEZVOUS, NULL)) == NULL) { | |
| 1272 | g_free(dim); | |
| 1273 | cancel_direct_im(w, d); | |
| 1274 | return TRUE; | |
| 1275 | } | |
| 1276 | dim->conn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; | |
| 1277 | dim->conn->priv = d->priv; | |
| 1278 | aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, | |
| 1279 | gaim_directim_incoming, 0); | |
| 1280 | aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, | |
| 1281 | gaim_directim_disconnect, 0); | |
| 1282 | aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, | |
| 1283 | gaim_directim_typing, 0); | |
| 1284 | ||
| 1285 | for (i = 0; i < (int)strlen(d->priv->ip); i++) { | |
| 1286 | if (d->priv->ip[i] == ':') { | |
| 1287 | port = atoi(&(d->priv->ip[i+1])); | |
| 1288 | break; | |
| 1289 | } | |
| 1290 | } | |
| 1291 | host = g_strndup(d->priv->ip, i); | |
| 1292 | dim->conn->status |= AIM_CONN_STATUS_INPROGRESS; | |
| 1293 | dim->conn->fd = proxy_connect(host, port, oscar_directim_callback, dim); | |
| 1294 | g_free(host); | |
| 1295 | if (dim->conn->fd < 0) { | |
| 1296 | aim_conn_kill(od->sess, &dim->conn); | |
| 1297 | g_free(dim); | |
| 1298 | cancel_direct_im(w, d); | |
| 1299 | return TRUE; | |
| 1300 | } | |
| 1301 | ||
| 1302 | cancel_direct_im(w, d); | |
| 1303 | ||
| 1304 | return TRUE; | |
| 1305 | } | |
| 1306 | ||
| 1307 | /* | |
| 1308 | static void cancel_getfile(gpointer w, struct ask_getfile *g) { | |
| 1309 | g_free(g->ip); | |
| 1310 | g_free(g->cookie); | |
| 1311 | g_free(g->sn); | |
| 1312 | g_free(g); | |
| 1313 | } | |
| 1314 | ||
| 1315 | static void cancel_getfile_file(GtkObject *obj, struct ask_getfile *g) { | |
| 1316 | GtkWidget *w = gtk_object_get_user_data(obj); | |
| 1317 | gtk_widget_destroy(w); | |
| 1318 | cancel_getfile(w, g); | |
| 1319 | } | |
| 1320 | ||
| 1321 | static void cancel_getfile_cancel(GtkObject *obj, struct ask_getfile *g) { | |
| 1322 | GtkWidget *w = gtk_object_get_user_data(obj); | |
| 1323 | gtk_widget_destroy(w); | |
| 1324 | } | |
| 1325 | ||
| 1326 | static void interrupt_getfile(GtkObject *obj, struct getfile_transfer *gt) { | |
| 1327 | struct gaim_connection *gc = gt->gc; | |
| 1328 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 1329 | ||
| 1330 | gtk_widget_destroy(gt->window); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1331 | gaim_input_remove(gt->gip); |
| 2086 | 1332 | if (gt->gop > 0) |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1333 | gaim_input_remove(gt->gop); |
| 2086 | 1334 | aim_conn_kill(od->sess, >->conn); |
| 1335 | od->getfiles = g_slist_remove(od->getfiles, gt); | |
| 1336 | g_free(gt->receiver); | |
| 1337 | g_free(gt->filename); | |
| 1338 | fclose(gt->listing); | |
| 1339 | g_free(gt); | |
| 1340 | } | |
| 1341 | ||
| 1342 | static int gaim_getfile_filereq(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 1343 | struct gaim_connection *gc = sess->aux_data; | |
| 1344 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 1345 | struct getfile_transfer *gt; | |
| 1346 | char buf[2048]; | |
| 1347 | GtkWidget *label; | |
| 1348 | GtkWidget *button; | |
| 1349 | ||
| 1350 | va_list ap; | |
| 1351 | struct aim_conn_t *oftconn; | |
| 1352 | struct aim_fileheader_t *fh; | |
| 1353 | char *cookie; | |
| 1354 | ||
| 1355 | va_start(ap, command); | |
| 1356 | oftconn = va_arg(ap, struct aim_conn_t *); | |
| 1357 | fh = va_arg(ap, struct aim_fileheader_t *); | |
| 1358 | cookie = va_arg(ap, char *); | |
| 1359 | va_end(ap); | |
| 1360 | ||
| 1361 | gt = find_getfile_transfer(od, oftconn); | |
| 1362 | ||
| 1363 | if (gt->window) | |
| 1364 | return 1; | |
| 1365 | ||
| 1366 | gt->window = gtk_dialog_new(); | |
| 1367 | gtk_window_set_title(GTK_WINDOW(gt->window), _("Gaim - File Transfer")); | |
| 1368 | gtk_widget_realize(gt->window); | |
| 1369 | aol_icon(gt->window->window); | |
| 1370 | ||
| 1371 | g_snprintf(buf, sizeof buf, _("Sending %s to %s"), fh->name, gt->receiver); | |
| 1372 | label = gtk_label_new(buf); | |
| 1373 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gt->window)->vbox), label, FALSE, FALSE, 5); | |
| 1374 | gtk_widget_show(label); | |
| 1375 | ||
| 1376 | gt->meter = gtk_progress_bar_new(); | |
| 1377 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gt->window)->action_area), gt->meter, FALSE, FALSE, 5); | |
| 1378 | gtk_widget_show(gt->meter); | |
| 1379 | ||
| 1380 | gt->label = gtk_label_new("0 %"); | |
| 1381 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gt->window)->action_area), gt->label, FALSE, FALSE, 5); | |
| 1382 | gtk_widget_show(gt->label); | |
| 1383 | ||
| 1384 | button = picture_button(gt->window, _("Cancel"), cancel_xpm); | |
| 1385 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gt->window)->action_area), button, FALSE, FALSE, 5); | |
| 1386 | gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(interrupt_getfile), gt); | |
| 1387 | ||
| 1388 | gtk_widget_show(gt->window); | |
| 1389 | ||
| 1390 | return 1; | |
| 1391 | } | |
| 1392 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1393 | static void getfile_send_callback(gpointer data, gint source, GaimInputCondition condition) { |
| 2086 | 1394 | struct getfile_transfer *gt = (struct getfile_transfer *)data; |
| 1395 | int result; | |
| 1396 | ||
| 1397 | result = aim_getfile_send_chunk(gt->conn, gt->file, gt->fh, -1, 1024); | |
| 1398 | gt->pos += result; | |
| 1399 | if (result == 0) { | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1400 | gaim_input_remove(gt->gop); gt->gop = 0; |
| 2086 | 1401 | } else if (result == -1) { |
| 1402 | do_error_dialog(_("Error in transfer"), "Gaim"); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1403 | gaim_input_remove(gt->gop); gt->gop = 0; |
| 2086 | 1404 | interrupt_getfile(NULL, gt); |
| 1405 | } | |
| 1406 | } | |
| 1407 | ||
| 1408 | static int gaim_getfile_filesend(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 1409 | struct gaim_connection *gc = sess->aux_data; | |
| 1410 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 1411 | struct getfile_transfer *gt; | |
| 1412 | ||
| 1413 | va_list ap; | |
| 1414 | struct aim_conn_t *oftconn; | |
| 1415 | struct aim_fileheader_t *fh; | |
| 1416 | char *cookie; | |
| 1417 | ||
| 1418 | va_start(ap, command); | |
| 1419 | oftconn = va_arg(ap, struct aim_conn_t *); | |
| 1420 | fh = va_arg(ap, struct aim_fileheader_t *); | |
| 1421 | cookie = va_arg(ap, char *); | |
| 1422 | va_end(ap); | |
| 1423 | ||
| 1424 | gt = find_getfile_transfer(od, oftconn); | |
| 1425 | ||
| 1426 | if (gt->gop > 0) { | |
| 1427 | debug_printf("already have output watcher?\n"); | |
| 1428 | return 1; | |
| 1429 | } | |
| 1430 | ||
| 1431 | if ((gt->file = fopen(gt->filename, "r")) == NULL) { | |
| 1432 | interrupt_getfile(NULL, gt); | |
| 1433 | return 1; | |
| 1434 | } | |
| 1435 | gt->pos = 0; | |
| 1436 | gt->fh = g_memdup(fh, sizeof(struct aim_fileheader_t)); | |
| 1437 | fseek(gt->file, 0, SEEK_SET); | |
| 1438 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1439 | gt->gop = gaim_input_add(gt->conn->fd, GAIM_INPUT_WRITE, getfile_send_callback, gt); |
| 2086 | 1440 | |
| 1441 | return 1; | |
| 1442 | } | |
| 1443 | ||
| 1444 | static int gaim_getfile_complete(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 1445 | struct gaim_connection *gc = sess->aux_data; | |
| 1446 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 1447 | struct getfile_transfer *gt; | |
| 1448 | ||
| 1449 | va_list ap; | |
| 1450 | struct aim_conn_t *conn; | |
| 1451 | struct aim_fileheader_t *fh; | |
| 1452 | ||
| 1453 | va_start(ap, command); | |
| 1454 | conn = va_arg(ap, struct aim_conn_t *); | |
| 1455 | fh = va_arg(ap, struct aim_fileheader_t *); | |
| 1456 | va_end(ap); | |
| 1457 | ||
| 1458 | gt = find_getfile_transfer(od, conn); | |
| 1459 | ||
| 1460 | gtk_widget_destroy(gt->window); | |
| 1461 | gt->window = NULL; | |
| 1462 | do_error_dialog(_("Transfer complete."), "Gaim"); | |
| 1463 | ||
| 1464 | return 1; | |
| 1465 | } | |
| 1466 | ||
| 1467 | static int gaim_getfile_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 1468 | struct gaim_connection *gc = sess->aux_data; | |
| 1469 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 1470 | struct getfile_transfer *gt; | |
| 1471 | ||
| 1472 | va_list ap; | |
| 1473 | struct aim_conn_t *conn; | |
| 1474 | char *sn; | |
| 1475 | ||
| 1476 | va_start(ap, command); | |
| 1477 | conn = va_arg(ap, struct aim_conn_t *); | |
| 1478 | sn = va_arg(ap, char *); | |
| 1479 | va_end(ap); | |
| 1480 | ||
| 1481 | gt = find_getfile_transfer(od, conn); | |
| 1482 | od->getfiles = g_slist_remove(od->getfiles, gt); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1483 | gaim_input_remove(gt->gip); |
| 2086 | 1484 | if (gt->gop > 0) |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1485 | gaim_input_remove(gt->gop); |
| 2086 | 1486 | g_free(gt->receiver); |
| 1487 | g_free(gt->filename); | |
| 1488 | aim_conn_kill(sess, &conn); | |
| 1489 | fclose(gt->listing); | |
| 1490 | g_free(gt); | |
| 1491 | ||
| 1492 | debug_printf("getfile disconnect\n"); | |
| 1493 | ||
| 1494 | return 1; | |
| 1495 | } | |
| 1496 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1497 | static void oscar_getfile_callback(gpointer data, gint source, GaimInputCondition condition) { |
| 2086 | 1498 | struct getfile_transfer *gf = data; |
| 1499 | struct gaim_connection *gc = gf->gc; | |
| 1500 | struct oscar_data *od = gc->proto_data; | |
| 1501 | ||
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1502 | gaim_input_remove(gf->gip); |
|
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1503 | gf->gip = gaim_input_add(source, GAIM_INPUT_READ, oscar_callback, gf->conn); |
| 2086 | 1504 | |
| 1505 | aim_conn_addhandler(od->sess, gf->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ, gaim_getfile_filereq, 0); | |
| 1506 | aim_conn_addhandler(od->sess, gf->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND, gaim_getfile_filesend, 0); | |
| 1507 | aim_conn_addhandler(od->sess, gf->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE, gaim_getfile_complete, 0); | |
| 1508 | aim_conn_addhandler(od->sess, gf->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT, gaim_getfile_disconnect, 0); | |
| 1509 | } | |
| 1510 | ||
| 1511 | static void do_getfile(GtkObject *obj, struct ask_getfile *g) { | |
| 1512 | GtkWidget *w = gtk_object_get_user_data(obj); | |
| 1513 | char *filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(w)); | |
| 1514 | struct gaim_connection *gc = g->gc; | |
| 1515 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 1516 | struct getfile_transfer *gf; | |
| 1517 | struct stat st; | |
| 1518 | struct tm *ft; | |
| 1519 | char tmppath[256]; | |
| 1520 | FILE *file; | |
| 1521 | static int current = 0; | |
| 1522 | struct aim_conn_t *newconn; | |
| 1523 | ||
| 1524 | if (file_is_dir(filename, w)) | |
| 1525 | return; | |
| 1526 | ||
| 1527 | if (stat(filename, &st) != 0) { | |
| 1528 | gtk_widget_destroy(w); | |
| 1529 | do_error_dialog(_("Error examining file"), _("GetFile Error")); | |
| 1530 | cancel_getfile(w, g); | |
| 1531 | return; | |
| 1532 | } | |
| 1533 | ||
| 1534 | g_snprintf(tmppath, sizeof tmppath, "/%s/gaim%d%d", g_get_tmp_dir(), getpid(), current++); | |
| 1535 | if ((file = fopen(tmppath, "w+")) == NULL) { | |
| 1536 | gtk_widget_destroy(w); | |
| 1537 | do_error_dialog(_("Could not open temporary file, aborting"), _("GetFile Error")); | |
| 1538 | cancel_getfile(w, g); | |
| 1539 | return; | |
| 1540 | } | |
| 1541 | ||
| 1542 | gf = g_new0(struct getfile_transfer, 1); | |
| 1543 | gf->gc = gc; | |
| 1544 | gf->filename = g_strdup(filename); | |
| 1545 | gf->listing = file; | |
| 1546 | gf->receiver = g_strdup(g->sn); | |
| 1547 | gf->size = st.st_size; | |
| 1548 | ||
| 1549 | ft = localtime(&st.st_ctime); | |
| 1550 | fprintf(file, "%2d/%2d/%4d %2d:%2d %8ld ", | |
| 1551 | ft->tm_mon + 1, ft->tm_mday, ft->tm_year + 1900, | |
| 1552 | ft->tm_hour + 1, ft->tm_min + 1, (long)st.st_size); | |
| 1553 | fprintf(file, "%s\r\n", g_basename(filename)); | |
| 1554 | rewind(file); | |
| 1555 | ||
| 1556 | aim_oft_registerlisting(od->sess, file, ""); | |
| 1557 | if ((newconn = aim_accepttransfer(od->sess, od->conn, g->sn, g->cookie, g->ip, file, AIM_CAPS_GETFILE)) == NULL) { | |
| 1558 | od->sess->flags ^= AIM_SESS_FLAGS_NONBLOCKCONNECT; | |
| 1559 | do_error_dialog(_("Error connecting for transfer"), _("GetFile Error")); | |
| 1560 | g_free(gf->filename); | |
| 1561 | fclose(file); | |
| 1562 | g_free(gf); | |
| 1563 | gtk_widget_destroy(w); | |
| 1564 | return; | |
| 1565 | } | |
| 1566 | ||
| 1567 | gtk_widget_destroy(w); | |
| 1568 | ||
| 1569 | od->getfiles = g_slist_append(od->getfiles, gf); | |
| 1570 | gf->conn = newconn; | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
1571 | gf->gip = gaim_input_add(newconn->fd, GAIM_INPUT_WRITE, oscar_getfile_callback, gf); |
| 2086 | 1572 | } |
| 1573 | ||
| 1574 | static int accept_getfile(gpointer w, struct ask_getfile *g) { | |
| 1575 | GtkWidget *window; | |
| 1576 | window = gtk_file_selection_new(_("Gaim - Send File...")); | |
| 1577 | gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(window)); | |
| 1578 | gtk_object_set_user_data(GTK_OBJECT(window), window); | |
| 1579 | gtk_signal_connect(GTK_OBJECT(window), "destroy", | |
| 1580 | GTK_SIGNAL_FUNC(cancel_getfile_file), g); | |
| 1581 | gtk_object_set_user_data(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), window); | |
| 1582 | gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), "clicked", | |
| 1583 | GTK_SIGNAL_FUNC(do_getfile), g); | |
| 1584 | gtk_object_set_user_data(GTK_OBJECT(GTK_FILE_SELECTION(window)->cancel_button), window); | |
| 1585 | gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(window)->cancel_button), "clicked", | |
| 1586 | GTK_SIGNAL_FUNC(cancel_getfile_cancel), g); | |
| 1587 | gtk_widget_show(window); | |
| 1588 | ||
| 1589 | return TRUE; | |
| 1590 | } | |
| 1591 | */ | |
| 1592 | ||
| 1593 | #if USE_PIXBUF | |
| 1594 | static gboolean redraw_anim(gpointer data) | |
| 1595 | { | |
| 1596 | int delay; | |
| 1597 | struct icon_req *ir = data; | |
| 1598 | GList *frames; | |
| 1599 | GdkPixbufFrame *frame; | |
| 1600 | GdkPixbuf *buf; | |
| 1601 | GdkPixmap *pm; GdkBitmap *bm; | |
| 1602 | GdkPixmap *src; | |
| 1603 | GdkGC *gc; | |
| 1604 | ||
| 1605 | if (!ir->cnv || !g_list_find(conversations, ir->cnv)) { | |
| 1606 | debug_printf("I think this is a bug.\n"); | |
| 1607 | return FALSE; | |
| 1608 | } | |
| 1609 | ||
| 1610 | frames = gdk_pixbuf_animation_get_frames(ir->anim); | |
| 1611 | frame = g_list_nth_data(frames, ir->curframe); | |
| 1612 | buf = gdk_pixbuf_frame_get_pixbuf(frame); | |
| 1613 | switch (gdk_pixbuf_frame_get_action(frame)) { | |
| 1614 | case GDK_PIXBUF_FRAME_RETAIN: | |
| 1615 | gdk_pixbuf_render_pixmap_and_mask(buf, &src, NULL, 0); | |
| 1616 | gtk_pixmap_get(GTK_PIXMAP(ir->pix), &pm, &bm); | |
| 1617 | gc = gdk_gc_new(pm); | |
| 1618 | gdk_draw_pixmap(pm, gc, src, 0, 0, | |
| 1619 | gdk_pixbuf_frame_get_x_offset(frame), | |
| 1620 | gdk_pixbuf_frame_get_y_offset(frame), | |
| 1621 | -1, -1); | |
| 1622 | gdk_pixmap_unref(src); | |
| 1623 | gtk_widget_queue_draw(ir->pix); | |
| 1624 | gdk_gc_unref(gc); | |
| 1625 | break; | |
| 1626 | case GDK_PIXBUF_FRAME_DISPOSE: | |
| 1627 | gdk_pixbuf_render_pixmap_and_mask(buf, &pm, &bm, 0); | |
| 1628 | gtk_pixmap_set(GTK_PIXMAP(ir->pix), pm, bm); | |
| 1629 | gdk_pixmap_unref(pm); | |
| 1630 | if (bm) | |
| 1631 | gdk_bitmap_unref(bm); | |
| 1632 | break; | |
| 1633 | case GDK_PIXBUF_FRAME_REVERT: | |
| 1634 | frame = frames->data; | |
| 1635 | buf = gdk_pixbuf_frame_get_pixbuf(frame); | |
| 1636 | gdk_pixbuf_render_pixmap_and_mask(buf, &pm, &bm, 0); | |
| 1637 | gtk_pixmap_set(GTK_PIXMAP(ir->pix), pm, bm); | |
| 1638 | gdk_pixmap_unref(pm); | |
| 1639 | if (bm) | |
| 1640 | gdk_bitmap_unref(bm); | |
| 1641 | break; | |
| 1642 | } | |
| 1643 | ir->curframe = (ir->curframe + 1) % g_list_length(frames); | |
| 1644 | delay = MAX(gdk_pixbuf_frame_get_delay_time(frame), 13); | |
| 1645 | ir->timer = gtk_timeout_add(delay * 10, redraw_anim, ir); | |
| 1646 | return FALSE; | |
| 1647 | } | |
| 1648 | #endif | |
| 1649 | ||
| 1650 | int gaim_parse_incoming_im(struct aim_session_t *sess, | |
| 1651 | struct command_rx_struct *command, ...) { | |
| 1652 | int channel; | |
| 1653 | struct aim_userinfo_s *userinfo; | |
| 1654 | va_list ap; | |
| 1655 | struct gaim_connection *gc = sess->aux_data; | |
| 1656 | ||
| 1657 | va_start(ap, command); | |
| 1658 | channel = va_arg(ap, int); | |
| 1659 | userinfo = va_arg(ap, struct aim_userinfo_s *); | |
| 1660 | ||
| 1661 | /* channel 1: standard message */ | |
| 1662 | if (channel == 1) { | |
| 1663 | char *tmp = g_malloc(BUF_LONG); | |
| 1664 | struct aim_incomingim_ch1_args *args; | |
| 1665 | ||
| 1666 | args = va_arg(ap, struct aim_incomingim_ch1_args *); | |
| 1667 | va_end(ap); | |
| 1668 | ||
| 1669 | #if USE_PIXBUF | |
| 1670 | if (args->icbmflags & AIM_IMFLAGS_HASICON) { | |
| 1671 | struct oscar_data *od = gc->proto_data; | |
| 1672 | struct icon_req *ir; | |
| 1673 | GSList *h = od->hasicons; | |
| 1674 | char *who = normalize(userinfo->sn); | |
| 1675 | debug_printf("%s has an icon\n", userinfo->sn); | |
| 1676 | while (h) { | |
| 1677 | ir = h->data; | |
| 1678 | if (!strcmp(ir->user, who)) | |
| 1679 | break; | |
| 1680 | h = h->next; | |
| 1681 | } | |
| 1682 | if (!h) { | |
| 1683 | ir = g_new0(struct icon_req, 1); | |
| 1684 | ir->user = g_strdup(who); | |
| 1685 | od->hasicons = g_slist_append(od->hasicons, ir); | |
| 1686 | } | |
| 1687 | if (args->iconstamp > ir->timestamp) | |
| 1688 | ir->request = TRUE; | |
| 1689 | ir->timestamp = args->iconstamp; | |
| 1690 | } | |
| 1691 | #endif | |
| 1692 | ||
| 1693 | /* | |
| 1694 | * Quickly convert it to eight bit format, replacing | |
| 1695 | * non-ASCII UNICODE characters with their equivelent | |
| 1696 | * HTML entity. | |
| 1697 | */ | |
| 1698 | if (args->icbmflags & AIM_IMFLAGS_UNICODE) { | |
| 1699 | int i; | |
| 1700 | ||
| 1701 | for (i = 0, tmp[0] = '\0'; i < args->msglen; i += 2) { | |
| 1702 | unsigned short uni; | |
| 1703 | ||
| 1704 | uni = ((args->msg[i] & 0xff) << 8) | (args->msg[i+1] & 0xff); | |
| 1705 | ||
| 1706 | if ((uni < 128) || ((uni >= 160) && (uni <= 255))) { /* ISO 8859-1 */ | |
| 1707 | ||
| 1708 | g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "%c", uni); | |
| 1709 | ||
| 1710 | } else { /* something else, do UNICODE entity */ | |
| 1711 | g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "&#%04x;", uni); | |
| 1712 | } | |
| 1713 | } | |
| 1714 | } else | |
| 1715 | g_snprintf(tmp, BUF_LONG, "%s", args->msg); | |
| 1716 | ||
| 1717 | serv_got_im(gc, userinfo->sn, tmp, args->icbmflags & AIM_IMFLAGS_AWAY, time(NULL)); | |
| 1718 | g_free(tmp); | |
| 1719 | } else if (channel == 2) { | |
| 1720 | struct aim_incomingim_ch2_args *args; | |
| 1721 | args = va_arg(ap, struct aim_incomingim_ch2_args *); | |
| 1722 | va_end(ap); | |
| 1723 | if (args->reqclass & AIM_CAPS_CHAT) { | |
| 1724 | char *name = extract_name(args->info.chat.roominfo.name); | |
| 1725 | serv_got_chat_invite(gc, | |
| 1726 | name ? name : args->info.chat.roominfo.name, | |
| 1727 | args->info.chat.roominfo.exchange, | |
| 1728 | userinfo->sn, | |
| 1729 | args->info.chat.msg); | |
| 1730 | if (name) | |
| 1731 | g_free(name); | |
| 1732 | } else if (args->reqclass & AIM_CAPS_SENDFILE) { | |
| 1733 | } else if (args->reqclass & AIM_CAPS_GETFILE) { | |
| 1734 | /* | |
| 1735 | char *ip, *cookie; | |
| 1736 | struct ask_getfile *g = g_new0(struct ask_getfile, 1); | |
| 1737 | char buf[256]; | |
| 1738 | ||
| 1739 | userinfo = va_arg(ap, struct aim_userinfo_s *); | |
| 1740 | ip = va_arg(ap, char *); | |
| 1741 | cookie = va_arg(ap, char *); | |
| 1742 | va_end(ap); | |
| 1743 | ||
| 1744 | debug_printf("%s received getfile request from %s (%s), cookie = %s\n", | |
| 1745 | gc->username, userinfo->sn, ip, cookie); | |
| 1746 | ||
| 1747 | g->gc = gc; | |
| 1748 | g->sn = g_strdup(userinfo->sn); | |
| 1749 | g->cookie = g_strdup(cookie); | |
| 1750 | g->ip = g_strdup(ip); | |
| 1751 | g_snprintf(buf, sizeof buf, "%s has just asked to get a file from %s.", | |
| 1752 | userinfo->sn, gc->username); | |
| 1753 | do_ask_dialog(buf, g, accept_getfile, cancel_getfile); | |
| 1754 | */ | |
| 1755 | } else if (args->reqclass & AIM_CAPS_VOICE) { | |
| 1756 | } else if (args->reqclass & AIM_CAPS_BUDDYICON) { | |
| 1757 | #if USE_PIXBUF | |
| 1758 | struct oscar_data *od = gc->proto_data; | |
| 1759 | GSList *h = od->hasicons; | |
| 1760 | struct icon_req *ir = NULL; | |
| 1761 | char *who; | |
| 1762 | struct conversation *c; | |
| 1763 | ||
| 1764 | GdkPixbufLoader *load; | |
| 1765 | GList *frames; | |
| 1766 | GdkPixbuf *buf; | |
| 1767 | GdkPixmap *pm; | |
| 1768 | GdkBitmap *bm; | |
| 1769 | ||
| 1770 | who = normalize(userinfo->sn); | |
| 1771 | ||
| 1772 | while (h) { | |
| 1773 | ir = h->data; | |
| 1774 | if (!strcmp(who, ir->user)) | |
| 1775 | break; | |
| 1776 | h = h->next; | |
| 1777 | ||
| 1778 | } | |
| 1779 | ||
| 1780 | if (!h || ((c = find_conversation(userinfo->sn)) == NULL) || (c->gc != gc)) { | |
| 1781 | debug_printf("got buddy icon for %s but didn't want it\n", userinfo->sn); | |
| 1782 | return 1; | |
| 1783 | } | |
| 1784 | ||
| 1785 | if (ir->pix && ir->cnv) | |
| 1786 | gtk_container_remove(GTK_CONTAINER(ir->cnv->bbox), ir->pix); | |
| 1787 | ir->pix = NULL; | |
| 1788 | ir->cnv = NULL; | |
| 1789 | if (ir->data) | |
| 1790 | g_free(ir->data); | |
| 1791 | if (ir->anim) | |
| 1792 | gdk_pixbuf_animation_unref(ir->anim); | |
| 1793 | ir->anim = NULL; | |
| 1794 | if (ir->unanim) | |
| 1795 | gdk_pixbuf_unref(ir->unanim); | |
| 1796 | ir->unanim = NULL; | |
| 1797 | if (ir->timer) | |
| 1798 | gtk_timeout_remove(ir->timer); | |
| 1799 | ir->timer = 0; | |
| 1800 | ||
| 1801 | ir->length = args->info.icon.length; | |
| 1802 | ||
| 1803 | if (!ir->length) | |
| 1804 | return 1; | |
| 1805 | ||
| 1806 | ir->data = g_memdup(args->info.icon.icon, args->info.icon.length); | |
| 1807 | ||
| 1808 | load = gdk_pixbuf_loader_new(); | |
| 1809 | gdk_pixbuf_loader_write(load, ir->data, ir->length); | |
| 1810 | ir->anim = gdk_pixbuf_loader_get_animation(load); | |
| 1811 | ||
| 1812 | if (ir->anim) { | |
| 1813 | frames = gdk_pixbuf_animation_get_frames(ir->anim); | |
| 1814 | buf = gdk_pixbuf_frame_get_pixbuf(frames->data); | |
| 1815 | gdk_pixbuf_render_pixmap_and_mask(buf, &pm, &bm, 0); | |
| 1816 | ||
| 1817 | if (gdk_pixbuf_animation_get_num_frames(ir->anim) > 1) { | |
| 1818 | int delay = | |
| 1819 | MAX(gdk_pixbuf_frame_get_delay_time(frames->data), 13); | |
| 1820 | ir->curframe = 1; | |
| 1821 | ir->timer = gtk_timeout_add(delay * 10, redraw_anim, ir); | |
| 1822 | } | |
| 1823 | } else { | |
| 1824 | ir->unanim = gdk_pixbuf_loader_get_pixbuf(load); | |
| 1825 | if (!ir->unanim) { | |
| 1826 | gdk_pixbuf_loader_close(load); | |
| 1827 | return 1; | |
| 1828 | } | |
| 1829 | gdk_pixbuf_render_pixmap_and_mask(ir->unanim, &pm, &bm, 0); | |
| 1830 | } | |
| 1831 | ||
| 1832 | ir->cnv = c; | |
| 1833 | ir->pix = gtk_pixmap_new(pm, bm); | |
| 1834 | gtk_box_pack_start(GTK_BOX(c->bbox), ir->pix, FALSE, FALSE, 5); | |
| 1835 | if (ir->anim && (gdk_pixbuf_animation_get_num_frames(ir->anim) > 1)) | |
| 1836 | gtk_widget_set_usize(ir->pix, gdk_pixbuf_animation_get_width(ir->anim), | |
| 1837 | gdk_pixbuf_animation_get_height(ir->anim)); | |
| 1838 | gtk_widget_show(ir->pix); | |
| 1839 | gdk_pixmap_unref(pm); | |
| 1840 | if (bm) | |
| 1841 | gdk_bitmap_unref(bm); | |
| 1842 | ||
| 1843 | gdk_pixbuf_loader_close(load); | |
| 1844 | ||
| 1845 | #endif | |
| 1846 | } else if (args->reqclass & AIM_CAPS_IMIMAGE) { | |
| 1847 | struct ask_direct *d = g_new0(struct ask_direct, 1); | |
| 1848 | char buf[256]; | |
| 1849 | ||
| 1850 | debug_printf("%s received direct im request from %s (%s)\n", | |
| 1851 | gc->username, userinfo->sn, args->info.directim->ip); | |
| 1852 | ||
| 1853 | d->gc = gc; | |
| 1854 | d->sn = g_strdup(userinfo->sn); | |
| 1855 | d->priv = args->info.directim; | |
| 1856 | g_snprintf(buf, sizeof buf, "%s has just asked to directly connect to %s.", | |
| 1857 | userinfo->sn, gc->username); | |
| 1858 | do_ask_dialog(buf, d, accept_direct_im, cancel_direct_im); | |
| 1859 | } else { | |
| 1860 | debug_printf("Unknown reqclass %d\n", args->reqclass); | |
| 1861 | } | |
| 1862 | } | |
| 1863 | ||
| 1864 | return 1; | |
| 1865 | } | |
| 1866 | ||
| 1867 | int gaim_parse_misses(struct aim_session_t *sess, | |
| 1868 | struct command_rx_struct *command, ...) { | |
| 1869 | va_list ap; | |
| 1870 | unsigned short chan, nummissed, reason; | |
| 1871 | struct aim_userinfo_s *userinfo; | |
| 1872 | char buf[1024]; | |
| 1873 | ||
| 1874 | va_start(ap, command); | |
| 1875 | chan = (unsigned short)va_arg(ap, unsigned int); | |
| 1876 | userinfo = va_arg(ap, struct aim_userinfo_s *); | |
| 1877 | nummissed = (unsigned short)va_arg(ap, unsigned int); | |
| 1878 | reason = (unsigned short)va_arg(ap, unsigned int); | |
| 1879 | va_end(ap); | |
| 1880 | ||
| 1881 | switch(reason) { | |
| 1882 | case 1: | |
| 1883 | /* message too large */ | |
| 1884 | sprintf(buf, _("You missed a message from %s because it was too large."), userinfo->sn); | |
| 1885 | do_error_dialog(buf, _("Gaim - Error")); | |
| 1886 | plugin_event(event_error, (void *)961, 0, 0, 0); | |
| 1887 | break; | |
| 1888 | default: | |
| 1889 | sprintf(buf, _("You missed a message from %s for unknown reasons."), userinfo->sn); | |
| 1890 | do_error_dialog(buf, _("Gaim - Error")); | |
| 1891 | plugin_event(event_error, (void *)970, 0, 0, 0); | |
| 1892 | break; | |
| 1893 | } | |
| 1894 | ||
| 1895 | return 1; | |
| 1896 | } | |
| 1897 | ||
| 1898 | int gaim_parse_genericerr(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 1899 | va_list ap; | |
| 1900 | unsigned short reason; | |
| 1901 | ||
| 1902 | va_start(ap, command); | |
| 1903 | reason = va_arg(ap, int); | |
| 1904 | va_end(ap); | |
| 1905 | ||
| 1906 | debug_printf("snac threw error (reason 0x%04x: %s\n", reason, | |
| 1907 | (reason < msgerrreasonlen) ? msgerrreason[reason] : "unknown"); | |
| 1908 | ||
| 1909 | return 1; | |
| 1910 | } | |
| 1911 | ||
| 1912 | int gaim_parse_msgerr(struct aim_session_t *sess, | |
| 1913 | struct command_rx_struct *command, ...) { | |
| 1914 | va_list ap; | |
| 1915 | char *destn; | |
| 1916 | unsigned short reason; | |
| 1917 | char buf[1024]; | |
| 1918 | ||
| 1919 | va_start(ap, command); | |
| 1920 | reason = (unsigned short)va_arg(ap, unsigned int); | |
| 1921 | destn = va_arg(ap, char *); | |
| 1922 | va_end(ap); | |
| 1923 | ||
| 1924 | sprintf(buf, _("Your message to %s did not get sent: %s"), destn, | |
| 1925 | (reason < msgerrreasonlen) ? msgerrreason[reason] : _("Reason unknown")); | |
| 1926 | do_error_dialog(buf, _("Gaim - Error")); | |
| 1927 | ||
| 1928 | return 1; | |
| 1929 | } | |
| 1930 | ||
| 1931 | int gaim_parse_locerr(struct aim_session_t *sess, | |
| 1932 | struct command_rx_struct *command, ...) { | |
| 1933 | va_list ap; | |
| 1934 | char *destn; | |
| 1935 | unsigned short reason; | |
| 1936 | char buf[1024]; | |
| 1937 | ||
| 1938 | va_start(ap, command); | |
| 1939 | reason = (unsigned short)va_arg(ap, unsigned int); | |
| 1940 | destn = va_arg(ap, char *); | |
| 1941 | va_end(ap); | |
| 1942 | ||
| 1943 | sprintf(buf, _("User information for %s unavailable: %s"), destn, | |
| 1944 | (reason < msgerrreasonlen) ? msgerrreason[reason] : _("Reason unknown")); | |
| 1945 | do_error_dialog(buf, _("Gaim - Error")); | |
| 1946 | ||
| 1947 | return 1; | |
| 1948 | } | |
| 1949 | ||
| 1950 | static char *images(int flags) { | |
| 1951 | static char buf[1024]; | |
| 1952 | g_snprintf(buf, sizeof(buf), "%s%s%s%s", | |
| 1953 | (flags & AIM_FLAG_UNCONFIRMED) ? "<IMG SRC=\"dt_icon.gif\">" : "", | |
| 1954 | (flags & AIM_FLAG_AOL) ? "<IMG SRC=\"aol_icon.gif\">" : "", | |
| 1955 | (flags & AIM_FLAG_ADMINISTRATOR) ? "<IMG SRC=\"admin_icon.gif\">" : "", | |
| 1956 | (flags & AIM_FLAG_FREE) ? "<IMG SRC=\"free_icon.gif\">" : ""); | |
| 1957 | return buf; | |
| 1958 | } | |
| 1959 | ||
| 1960 | int gaim_parse_user_info(struct aim_session_t *sess, | |
| 1961 | struct command_rx_struct *command, ...) { | |
| 1962 | struct aim_userinfo_s *info; | |
| 1963 | char *prof_enc = NULL, *prof = NULL; | |
| 1964 | unsigned short infotype; | |
| 1965 | char buf[BUF_LONG]; | |
| 1966 | struct gaim_connection *gc = sess->aux_data; | |
| 1967 | va_list ap; | |
| 1968 | char *asc; | |
| 1969 | ||
| 1970 | va_start(ap, command); | |
| 1971 | info = va_arg(ap, struct aim_userinfo_s *); | |
| 1972 | prof_enc = va_arg(ap, char *); | |
| 1973 | prof = va_arg(ap, char *); | |
| 1974 | infotype = (unsigned short)va_arg(ap, unsigned int); | |
| 1975 | va_end(ap); | |
| 1976 | ||
| 1977 | if (info->membersince) | |
| 1978 | asc = g_strdup_printf("Member Since : <B>%s</B><BR>\n", | |
| 1979 | asctime(localtime(&info->membersince))); | |
| 1980 | else | |
| 1981 | asc = g_strdup(""); | |
| 1982 | ||
| 1983 | g_snprintf(buf, sizeof buf, | |
| 1984 | _("Username : <B>%s</B> %s <BR>\n" | |
| 1985 | "%s" | |
| 1986 | "Warning Level : <B>%d %%</B><BR>\n" | |
| 1987 | "Online Since : <B>%s</B><BR>\n" | |
| 1988 | "Idle Minutes : <B>%d</B>\n<BR>\n<HR><BR>\n" | |
| 1989 | "%s" | |
| 1990 | "<br><BODY BGCOLOR=WHITE><hr><I>Legend:</I><br><br>" | |
| 1991 | "<IMG SRC=\"free_icon.gif\"> : Normal AIM User<br>" | |
| 1992 | "<IMG SRC=\"aol_icon.gif\"> : AOL User <br>" | |
| 1993 | "<IMG SRC=\"dt_icon.gif\"> : Trial AIM User <br>" | |
| 1994 | "<IMG SRC=\"admin_icon.gif\"> : Administrator"), | |
| 1995 | info->sn, images(info->flags), | |
| 1996 | asc, | |
| 1997 | info->warnlevel/10, | |
| 1998 | asctime(localtime(&info->onlinesince)), | |
| 1999 | info->idletime, | |
| 2000 | (prof && strlen(prof)) ? | |
| 2001 | (infotype == AIM_GETINFO_GENERALINFO ? | |
| 2002 | prof : | |
| 2003 | away_subs(prof, gc->username)) | |
| 2004 | : | |
| 2005 | (infotype == AIM_GETINFO_GENERALINFO ? | |
| 2006 | _("<i>No Information Provided</i>") : | |
| 2007 | _("<i>User has no away message</i>"))); | |
| 2008 | ||
| 2009 | g_show_info_text(away_subs(buf, gc->username)); | |
| 2010 | ||
| 2011 | g_free(asc); | |
| 2012 | ||
| 2013 | return 1; | |
| 2014 | } | |
| 2015 | ||
| 2016 | int gaim_parse_motd(struct aim_session_t *sess, | |
| 2017 | struct command_rx_struct *command, ...) { | |
| 2018 | char *msg; | |
| 2019 | unsigned short id; | |
| 2020 | va_list ap; | |
| 2021 | char buildbuf[150]; | |
| 2022 | ||
| 2023 | va_start(ap, command); | |
| 2024 | id = (unsigned short)va_arg(ap, unsigned int); | |
| 2025 | msg = va_arg(ap, char *); | |
| 2026 | va_end(ap); | |
| 2027 | ||
| 2028 | aim_getbuildstring(buildbuf, sizeof(buildbuf)); | |
| 2029 | ||
| 2030 | debug_printf("MOTD: %s (%d)\n", msg ? msg : "Unknown", id); | |
| 2031 | debug_printf("Gaim %s / Libfaim %s\n", VERSION, buildbuf); | |
|
2092
f56061012e3c
[gaim-migrate @ 2102]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2090
diff
changeset
|
2032 | if (id < 4) |
| 2086 | 2033 | do_error_dialog(_("Your connection may be lost."), |
| 2034 | _("AOL error")); | |
| 2035 | ||
| 2036 | return 1; | |
| 2037 | } | |
| 2038 | ||
| 2039 | int gaim_chatnav_info(struct aim_session_t *sess, | |
| 2040 | struct command_rx_struct *command, ...) { | |
| 2041 | va_list ap; | |
| 2042 | unsigned short type; | |
| 2043 | struct gaim_connection *gc = sess->aux_data; | |
| 2044 | struct oscar_data *odata = (struct oscar_data *)gc->proto_data; | |
| 2045 | ||
| 2046 | va_start(ap, command); | |
| 2047 | type = (unsigned short)va_arg(ap, unsigned int); | |
| 2048 | ||
| 2049 | switch(type) { | |
| 2050 | case 0x0002: { | |
| 2051 | int maxrooms; | |
| 2052 | struct aim_chat_exchangeinfo *exchanges; | |
| 2053 | int exchangecount, i = 0; | |
| 2054 | ||
| 2055 | maxrooms = (unsigned char)va_arg(ap, unsigned int); | |
| 2056 | exchangecount = va_arg(ap, int); | |
| 2057 | exchanges = va_arg(ap, struct aim_chat_exchangeinfo *); | |
| 2058 | va_end(ap); | |
| 2059 | ||
| 2060 | debug_printf("chat info: Chat Rights:\n"); | |
| 2061 | debug_printf("chat info: \tMax Concurrent Rooms: %d\n", maxrooms); | |
| 2062 | debug_printf("chat info: \tExchange List: (%d total)\n", exchangecount); | |
| 2063 | while (i < exchangecount) | |
| 2064 | debug_printf("chat info: \t\t%d\n", exchanges[i++].number); | |
| 2065 | if (odata->create_exchange) { | |
| 2066 | debug_printf("creating room %s\n", odata->create_name); | |
| 2067 | aim_chatnav_createroom(sess, command->conn, odata->create_name, | |
| 2068 | odata->create_exchange); | |
| 2069 | odata->create_exchange = 0; | |
| 2070 | g_free(odata->create_name); | |
| 2071 | odata->create_name = NULL; | |
| 2072 | } | |
| 2073 | } | |
| 2074 | break; | |
| 2075 | case 0x0008: { | |
| 2076 | char *fqcn, *name, *ck; | |
| 2077 | unsigned short instance, flags, maxmsglen, maxoccupancy, unknown, exchange; | |
| 2078 | unsigned char createperms; | |
| 2079 | unsigned long createtime; | |
| 2080 | ||
| 2081 | fqcn = va_arg(ap, char *); | |
| 2082 | instance = (unsigned short)va_arg(ap, unsigned int); | |
| 2083 | exchange = (unsigned short)va_arg(ap, unsigned int); | |
| 2084 | flags = (unsigned short)va_arg(ap, unsigned int); | |
| 2085 | createtime = va_arg(ap, unsigned long); | |
| 2086 | maxmsglen = (unsigned short)va_arg(ap, unsigned int); | |
| 2087 | maxoccupancy = (unsigned short)va_arg(ap, unsigned int); | |
| 2088 | createperms = (unsigned char)va_arg(ap, int); | |
| 2089 | unknown = (unsigned short)va_arg(ap, unsigned int); | |
| 2090 | name = va_arg(ap, char *); | |
| 2091 | ck = va_arg(ap, char *); | |
| 2092 | va_end(ap); | |
| 2093 | ||
| 2094 | debug_printf("created room: %s %d %d %d %lu %d %d %d %d %s %s\n", | |
| 2095 | fqcn, | |
| 2096 | exchange, instance, flags, | |
| 2097 | createtime, | |
| 2098 | maxmsglen, maxoccupancy, createperms, unknown, | |
| 2099 | name, ck); | |
| 2100 | aim_chat_join(odata->sess, odata->conn, exchange, ck); | |
| 2101 | } | |
| 2102 | break; | |
| 2103 | default: | |
| 2104 | va_end(ap); | |
| 2105 | debug_printf("chatnav info: unknown type (%04x)\n", type); | |
| 2106 | break; | |
| 2107 | } | |
| 2108 | return 1; | |
| 2109 | } | |
| 2110 | ||
| 2111 | int gaim_chat_join(struct aim_session_t *sess, | |
| 2112 | struct command_rx_struct *command, ...) { | |
| 2113 | va_list ap; | |
| 2114 | int count, i = 0; | |
| 2115 | struct aim_userinfo_s *info; | |
| 2116 | struct gaim_connection *g = sess->aux_data; | |
| 2117 | ||
| 2118 | struct chat_connection *c = NULL; | |
| 2119 | ||
| 2120 | va_start(ap, command); | |
| 2121 | count = va_arg(ap, int); | |
| 2122 | info = va_arg(ap, struct aim_userinfo_s *); | |
| 2123 | va_end(ap); | |
| 2124 | ||
| 2125 | c = find_oscar_chat_by_conn(g, command->conn); | |
| 2126 | if (!c) | |
| 2127 | return 1; | |
| 2128 | ||
| 2129 | while (i < count) | |
| 2130 | add_chat_buddy(c->cnv, info[i++].sn); | |
| 2131 | ||
| 2132 | return 1; | |
| 2133 | } | |
| 2134 | ||
| 2135 | int gaim_chat_leave(struct aim_session_t *sess, | |
| 2136 | struct command_rx_struct *command, ...) { | |
| 2137 | va_list ap; | |
| 2138 | int count, i = 0; | |
| 2139 | struct aim_userinfo_s *info; | |
| 2140 | struct gaim_connection *g = sess->aux_data; | |
| 2141 | ||
| 2142 | struct chat_connection *c = NULL; | |
| 2143 | ||
| 2144 | va_start(ap, command); | |
| 2145 | count = va_arg(ap, int); | |
| 2146 | info = va_arg(ap, struct aim_userinfo_s *); | |
| 2147 | va_end(ap); | |
| 2148 | ||
| 2149 | c = find_oscar_chat_by_conn(g, command->conn); | |
| 2150 | if (!c) | |
| 2151 | return 1; | |
| 2152 | ||
| 2153 | while (i < count) | |
| 2154 | remove_chat_buddy(c->cnv, info[i++].sn); | |
| 2155 | ||
| 2156 | return 1; | |
| 2157 | } | |
| 2158 | ||
| 2159 | int gaim_chat_info_update(struct aim_session_t *sess, | |
| 2160 | struct command_rx_struct *command, ...) { | |
| 2161 | debug_printf("inside chat_info_update\n"); | |
| 2162 | return 1; | |
| 2163 | } | |
| 2164 | ||
| 2165 | int gaim_chat_incoming_msg(struct aim_session_t *sess, | |
| 2166 | struct command_rx_struct *command, ...) { | |
| 2167 | va_list ap; | |
| 2168 | struct aim_userinfo_s *info; | |
| 2169 | char *msg; | |
| 2170 | struct gaim_connection *gc = sess->aux_data; | |
| 2171 | struct chat_connection *ccon = find_oscar_chat_by_conn(gc, command->conn); | |
| 2172 | char *tmp; | |
| 2173 | ||
| 2174 | va_start(ap, command); | |
| 2175 | info = va_arg(ap, struct aim_userinfo_s *); | |
| 2176 | msg = va_arg(ap, char *); | |
| 2177 | ||
| 2178 | tmp = g_malloc(BUF_LONG); | |
| 2179 | g_snprintf(tmp, BUF_LONG, "%s", msg); | |
| 2180 | serv_got_chat_in(gc, ccon->id, info->sn, 0, tmp, time((time_t)NULL)); | |
| 2181 | g_free(tmp); | |
| 2182 | ||
| 2183 | return 1; | |
| 2184 | } | |
| 2185 | ||
| 2186 | /* | |
| 2187 | * Recieved in response to an IM sent with the AIM_IMFLAGS_ACK option. | |
| 2188 | */ | |
| 2189 | int gaim_parse_msgack(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2190 | va_list ap; | |
| 2191 | unsigned short type; | |
| 2192 | char *sn = NULL; | |
| 2193 | ||
| 2194 | va_start(ap, command); | |
| 2195 | type = (unsigned short)va_arg(ap, unsigned int); | |
| 2196 | sn = va_arg(ap, char *); | |
| 2197 | va_end(ap); | |
| 2198 | ||
| 2199 | debug_printf("Sent message to %s.\n", sn); | |
| 2200 | ||
| 2201 | return 1; | |
| 2202 | } | |
| 2203 | ||
| 2204 | int gaim_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2205 | static char *codes[5] = {"invalid", | |
| 2206 | "change", | |
| 2207 | "warning", | |
| 2208 | "limit", | |
| 2209 | "limit cleared"}; | |
| 2210 | va_list ap; | |
| 2211 | int code; | |
| 2212 | unsigned long rateclass, windowsize, clear, alert, limit, disconnect; | |
| 2213 | unsigned long currentavg, maxavg; | |
| 2214 | ||
| 2215 | va_start(ap, command); | |
| 2216 | code = va_arg(ap, int); | |
| 2217 | rateclass= va_arg(ap, int); | |
| 2218 | windowsize = va_arg(ap, unsigned long); | |
| 2219 | clear = va_arg(ap, unsigned long); | |
| 2220 | alert = va_arg(ap, unsigned long); | |
| 2221 | limit = va_arg(ap, unsigned long); | |
| 2222 | disconnect = va_arg(ap, unsigned long); | |
| 2223 | currentavg = va_arg(ap, unsigned long); | |
| 2224 | maxavg = va_arg(ap, unsigned long); | |
| 2225 | va_end(ap); | |
| 2226 | ||
| 2227 | debug_printf("rate %s (paramid 0x%04lx): curavg = %ld, maxavg = %ld, alert at %ld, " | |
| 2228 | "clear warning at %ld, limit at %ld, disconnect at %ld (window size = %ld)\n", | |
| 2229 | (code < 5) ? codes[code] : codes[0], | |
| 2230 | rateclass, | |
| 2231 | currentavg, maxavg, | |
| 2232 | alert, clear, | |
| 2233 | limit, disconnect, | |
| 2234 | windowsize); | |
| 2235 | ||
| 2236 | if (code == AIM_RATE_CODE_CHANGE) { | |
| 2237 | if (currentavg >= clear) | |
| 2238 | aim_conn_setlatency(command->conn, 0); | |
| 2239 | } else if (code == AIM_RATE_CODE_WARNING) { | |
| 2240 | aim_conn_setlatency(command->conn, windowsize/4); | |
| 2241 | } else if (code == AIM_RATE_CODE_LIMIT) { | |
| 2242 | aim_conn_setlatency(command->conn, windowsize/2); | |
| 2243 | } else if (code == AIM_RATE_CODE_CLEARLIMIT) { | |
| 2244 | aim_conn_setlatency(command->conn, 0); | |
| 2245 | } | |
| 2246 | ||
| 2247 | return 1; | |
| 2248 | } | |
| 2249 | ||
| 2250 | int gaim_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2251 | va_list ap; | |
| 2252 | int newevil; | |
| 2253 | struct aim_userinfo_s *userinfo; | |
| 2254 | struct gaim_connection *gc = sess->aux_data; | |
| 2255 | ||
| 2256 | va_start(ap, command); | |
| 2257 | newevil = va_arg(ap, int); | |
| 2258 | userinfo = va_arg(ap, struct aim_userinfo_s *); | |
| 2259 | va_end(ap); | |
| 2260 | ||
| 2261 | serv_got_eviled(gc, (userinfo && userinfo->sn[0]) ? userinfo->sn : NULL, newevil / 10); | |
| 2262 | ||
| 2263 | return 1; | |
| 2264 | } | |
| 2265 | ||
| 2266 | int gaim_rateresp(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2267 | struct gaim_connection *gc = sess->aux_data; | |
| 2268 | switch (command->conn->type) { | |
| 2269 | case AIM_CONN_TYPE_BOS: | |
| 2270 | aim_bos_ackrateresp(sess, command->conn); | |
| 2271 | aim_bos_reqpersonalinfo(sess, command->conn); | |
| 2272 | aim_bos_reqlocaterights(sess, command->conn); | |
| 2273 | aim_bos_setprofile(sess, command->conn, gc->user->user_info, NULL, gaim_caps); | |
| 2274 | aim_bos_reqbuddyrights(sess, command->conn); | |
| 2275 | ||
| 2276 | account_online(gc); | |
| 2277 | serv_finish_login(gc); | |
| 2278 | ||
| 2279 | if (bud_list_cache_exists(gc)) | |
| 2280 | do_import(NULL, gc); | |
| 2281 | ||
| 2282 | debug_printf("buddy list loaded\n"); | |
| 2283 | ||
| 2284 | aim_addicbmparam(sess, command->conn); | |
| 2285 | aim_bos_reqicbmparaminfo(sess, command->conn); | |
| 2286 | ||
| 2287 | aim_bos_reqrights(sess, command->conn); | |
| 2288 | aim_bos_setgroupperm(sess, command->conn, AIM_FLAG_ALLUSERS); | |
| 2289 | aim_bos_setprivacyflags(sess, command->conn, AIM_PRIVFLAGS_ALLOWIDLE | | |
| 2290 | AIM_PRIVFLAGS_ALLOWMEMBERSINCE); | |
| 2291 | ||
| 2292 | break; | |
| 2293 | case AIM_CONN_TYPE_AUTH: | |
| 2294 | aim_bos_ackrateresp(sess, command->conn); | |
| 2295 | aim_auth_clientready(sess, command->conn); | |
| 2296 | debug_printf("connected to auth (admin)\n"); | |
| 2297 | break; | |
| 2298 | default: | |
| 2299 | debug_printf("got rate response for unhandled connection type %04x\n", | |
| 2300 | command->conn->type); | |
| 2301 | break; | |
| 2302 | } | |
| 2303 | ||
| 2304 | return 1; | |
| 2305 | } | |
| 2306 | ||
| 2307 | int gaim_reportinterval(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2308 | if (command->data) { | |
| 2309 | debug_printf("minimum report interval: %d (seconds?)\n", aimutil_get16(command->data+10)); | |
| 2310 | } else | |
| 2311 | debug_printf("NULL minimum report interval!\n"); | |
| 2312 | return 1; | |
| 2313 | } | |
| 2314 | ||
| 2315 | int gaim_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2316 | va_list ap; | |
| 2317 | unsigned short maxbuddies, maxwatchers; | |
| 2318 | ||
| 2319 | va_start(ap, command); | |
| 2320 | maxbuddies = (unsigned short)va_arg(ap, unsigned int); | |
| 2321 | maxwatchers = (unsigned short)va_arg(ap, unsigned int); | |
| 2322 | va_end(ap); | |
| 2323 | ||
| 2324 | debug_printf("buddy list rights: Max buddies = %d / Max watchers = %d\n", maxbuddies, maxwatchers); | |
| 2325 | ||
| 2326 | return 1; | |
| 2327 | } | |
| 2328 | ||
| 2329 | int gaim_bosrights(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2330 | unsigned short maxpermits, maxdenies; | |
| 2331 | va_list ap; | |
| 2332 | ||
| 2333 | va_start(ap, command); | |
| 2334 | maxpermits = (unsigned short)va_arg(ap, unsigned int); | |
| 2335 | maxdenies = (unsigned short)va_arg(ap, unsigned int); | |
| 2336 | va_end(ap); | |
| 2337 | ||
| 2338 | debug_printf("BOS rights: Max permit = %d / Max deny = %d\n", maxpermits, maxdenies); | |
| 2339 | ||
| 2340 | aim_bos_clientready(sess, command->conn); | |
| 2341 | ||
| 2342 | aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV); | |
| 2343 | ||
| 2344 | return 1; | |
| 2345 | } | |
| 2346 | ||
| 2347 | int gaim_parse_searchreply(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2348 | va_list ap; | |
| 2349 | char *address, *SNs; | |
| 2350 | int i, num; | |
| 2351 | char *buf; | |
| 2352 | int at = 0, len; | |
| 2353 | ||
| 2354 | va_start(ap, command); | |
| 2355 | address = va_arg(ap, char *); | |
| 2356 | num = va_arg(ap, int); | |
| 2357 | SNs = va_arg(ap, char *); | |
| 2358 | va_end(ap); | |
| 2359 | ||
| 2360 | len = num * (MAXSNLEN + 1) + 1024; | |
| 2361 | buf = g_malloc(len); | |
| 2362 | at += g_snprintf(buf + at, len - at, "<B>%s has the following screen names:</B><BR>", address); | |
| 2363 | for (i = 0; i < num; i++) | |
| 2364 | at += g_snprintf(buf + at, len - at, "%s<BR>", &SNs[i * (MAXSNLEN + 1)]); | |
| 2365 | g_show_info_text(buf); | |
| 2366 | g_free(buf); | |
| 2367 | ||
| 2368 | return 1; | |
| 2369 | } | |
| 2370 | ||
| 2371 | int gaim_parse_searcherror(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2372 | va_list ap; | |
| 2373 | char *address; | |
| 2374 | char buf[BUF_LONG]; | |
| 2375 | ||
| 2376 | va_start(ap, command); | |
| 2377 | address = va_arg(ap, char *); | |
| 2378 | va_end(ap); | |
| 2379 | ||
| 2380 | g_snprintf(buf, sizeof(buf), "No results found for email address %s", address); | |
| 2381 | do_error_dialog(buf, _("Error")); | |
| 2382 | ||
| 2383 | return 1; | |
| 2384 | } | |
| 2385 | ||
| 2386 | int gaim_account_confirm(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2387 | int status; | |
| 2388 | va_list ap; | |
| 2389 | char msg[256]; | |
| 2390 | struct gaim_connection *gc = sess->aux_data; | |
| 2391 | ||
| 2392 | va_start(ap, command); | |
| 2393 | status = va_arg(ap, int); /* status code of confirmation request */ | |
| 2394 | va_end(ap); | |
| 2395 | ||
| 2396 | debug_printf("account confirmation returned status 0x%04x (%s)\n", status, | |
| 2397 | status ? "email sent" : "unknown"); | |
| 2398 | if (status) { | |
| 2399 | g_snprintf(msg, sizeof(msg), "You should receive an email asking to confirm %s.", | |
| 2400 | gc->username); | |
| 2401 | do_error_dialog(msg, "Confirm"); | |
| 2402 | } | |
| 2403 | ||
| 2404 | return 1; | |
| 2405 | } | |
| 2406 | ||
| 2407 | int gaim_info_change(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2408 | unsigned short change = 0; | |
| 2409 | int perms, type, length, str; | |
| 2410 | char *val; | |
| 2411 | va_list ap; | |
| 2412 | char buf[BUF_LONG]; | |
| 2413 | struct gaim_connection *gc = sess->aux_data; | |
| 2414 | ||
| 2415 | va_start(ap, command); | |
| 2416 | perms = va_arg(ap, int); | |
| 2417 | type = va_arg(ap, int); | |
| 2418 | length = va_arg(ap, int); | |
| 2419 | val = va_arg(ap, char *); | |
| 2420 | str = va_arg(ap, int); | |
| 2421 | va_end(ap); | |
| 2422 | ||
| 2423 | if (aimutil_get16(command->data+2) == 0x0005) | |
| 2424 | change = 1; | |
| 2425 | ||
| 2426 | debug_printf("info%s: perms = %d, type = %x, length = %d, val = %s\n", | |
| 2427 | change ? " change" : "", perms, type, length, str ? val : "(not string)"); | |
| 2428 | ||
| 2429 | if ((type == 0x0011) && str) { | |
| 2430 | g_snprintf(buf, sizeof(buf), "The email address for %s is %s", gc->username, val); | |
| 2431 | do_error_dialog(buf, "Email"); | |
| 2432 | } | |
| 2433 | ||
| 2434 | return 1; | |
| 2435 | } | |
| 2436 | ||
| 2437 | static void oscar_keepalive(struct gaim_connection *gc) { | |
| 2438 | struct oscar_data *odata = (struct oscar_data *)gc->proto_data; | |
| 2439 | aim_flap_nop(odata->sess, odata->conn); | |
| 2440 | } | |
| 2441 | ||
| 2442 | static char *oscar_name() { | |
| 2443 | return "Oscar"; | |
| 2444 | } | |
| 2445 | ||
|
2123
4cfdde0aa3f1
[gaim-migrate @ 2133]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2113
diff
changeset
|
2446 | static int oscar_send_im(struct gaim_connection *gc, char *name, char *message, int away) { |
| 2086 | 2447 | struct oscar_data *odata = (struct oscar_data *)gc->proto_data; |
| 2448 | struct direct_im *dim = find_direct_im(odata, name); | |
| 2449 | if (dim) { | |
|
2123
4cfdde0aa3f1
[gaim-migrate @ 2133]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2113
diff
changeset
|
2450 | return aim_send_im_direct(odata->sess, dim->conn, message); |
| 2086 | 2451 | } else { |
| 2452 | if (away) | |
|
2123
4cfdde0aa3f1
[gaim-migrate @ 2133]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2113
diff
changeset
|
2453 | return aim_send_im(odata->sess, odata->conn, name, AIM_IMFLAGS_AWAY, message); |
| 2086 | 2454 | else { |
| 2455 | int flags = AIM_IMFLAGS_ACK; | |
| 2456 | #if USE_PIXBUF | |
| 2457 | GSList *h = odata->hasicons; | |
| 2458 | struct icon_req *ir; | |
| 2459 | char *who = normalize(name); | |
| 2460 | while (h) { | |
| 2461 | ir = h->data; | |
| 2462 | if (ir->request && !strcmp(who, ir->user)) | |
| 2463 | break; | |
| 2464 | h = h->next; | |
| 2465 | } | |
| 2466 | if (h) { | |
| 2467 | ir->request = FALSE; | |
| 2468 | flags |= AIM_IMFLAGS_BUDDYREQ; | |
| 2469 | debug_printf("sending buddy icon request with message\n"); | |
| 2470 | } | |
| 2471 | #endif | |
|
2123
4cfdde0aa3f1
[gaim-migrate @ 2133]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2113
diff
changeset
|
2472 | return aim_send_im(odata->sess, odata->conn, name, flags, message); |
| 2086 | 2473 | } |
| 2474 | } | |
| 2475 | } | |
| 2476 | ||
| 2477 | static void oscar_get_info(struct gaim_connection *g, char *name) { | |
| 2478 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2479 | aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_GENERALINFO); | |
| 2480 | } | |
| 2481 | ||
| 2482 | static void oscar_get_away_msg(struct gaim_connection *g, char *name) { | |
| 2483 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2484 | aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_AWAYMESSAGE); | |
| 2485 | } | |
| 2486 | ||
| 2487 | static void oscar_set_dir(struct gaim_connection *g, char *first, char *middle, char *last, | |
| 2488 | char *maiden, char *city, char *state, char *country, int web) { | |
| 2489 | /* FIXME : some of these things are wrong, but i'm lazy */ | |
| 2490 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2491 | aim_setdirectoryinfo(odata->sess, odata->conn, first, middle, last, | |
| 2492 | maiden, NULL, NULL, city, state, NULL, 0, web); | |
| 2493 | } | |
| 2494 | ||
| 2495 | ||
| 2496 | static void oscar_set_idle(struct gaim_connection *g, int time) { | |
| 2497 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2498 | aim_bos_setidle(odata->sess, odata->conn, time); | |
| 2499 | } | |
| 2500 | ||
| 2501 | static void oscar_set_info(struct gaim_connection *g, char *info) { | |
| 2502 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2503 | char inforeal[1025], away[1025]; | |
| 2504 | g_snprintf(inforeal, sizeof(inforeal), "%s", info); | |
| 2505 | if (g->away) | |
| 2506 | g_snprintf(away, sizeof(away), "%s", g->away); | |
| 2507 | if (strlen(info) > 1024) | |
| 2508 | do_error_dialog("Maximum info length (1024) exceeded, truncating", "Info Too Long"); | |
| 2509 | aim_bos_setprofile(odata->sess, odata->conn, inforeal, g->away ? NULL : "", gaim_caps); | |
| 2510 | } | |
| 2511 | ||
| 2512 | static void oscar_set_away(struct gaim_connection *g, char *state, char *message) { | |
| 2513 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2514 | char info[1025], away[1025]; | |
| 2515 | g_snprintf(info, sizeof(info), "%s", g->user->user_info); | |
| 2516 | if (message) | |
| 2517 | g_snprintf(away, sizeof(away), "%s", message); | |
| 2518 | aim_bos_setprofile(odata->sess, odata->conn, NULL, message ? away : "", gaim_caps); | |
| 2519 | if (g->away) | |
| 2520 | g_free (g->away); | |
| 2521 | g->away = NULL; | |
| 2522 | if (message) { | |
| 2523 | if (strlen(message) > 1024) | |
| 2524 | do_error_dialog("Maximum away length (1024) exceeded, truncating", | |
| 2525 | "Info Too Long"); | |
| 2526 | g->away = g_strdup (message); | |
| 2527 | } | |
| 2528 | } | |
| 2529 | ||
| 2530 | static void oscar_warn(struct gaim_connection *g, char *name, int anon) { | |
| 2531 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2113 | 2532 | aim_send_warning(odata->sess, odata->conn, name, anon ? AIM_WARN_ANON : 0); |
| 2086 | 2533 | } |
| 2534 | ||
| 2535 | static void oscar_dir_search(struct gaim_connection *g, char *first, char *middle, char *last, | |
| 2536 | char *maiden, char *city, char *state, char *country, char *email) { | |
| 2537 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2538 | if (strlen(email)) | |
| 2539 | aim_usersearch_address(odata->sess, odata->conn, email); | |
| 2540 | } | |
| 2541 | ||
| 2542 | static void oscar_add_buddy(struct gaim_connection *g, char *name) { | |
| 2543 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2544 | aim_add_buddy(odata->sess, odata->conn, name); | |
| 2545 | } | |
| 2546 | ||
| 2547 | static void oscar_add_buddies(struct gaim_connection *g, GList *buddies) { | |
| 2548 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2549 | char buf[MSG_LEN]; | |
| 2550 | int n = 0; | |
| 2551 | while (buddies) { | |
| 2552 | if (n > MSG_LEN - 18) { | |
| 2553 | aim_bos_setbuddylist(odata->sess, odata->conn, buf); | |
| 2554 | n = 0; | |
| 2555 | } | |
| 2556 | n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (char *)buddies->data); | |
| 2557 | buddies = buddies->next; | |
| 2558 | } | |
| 2559 | aim_bos_setbuddylist(odata->sess, odata->conn, buf); | |
| 2560 | } | |
| 2561 | ||
| 2562 | static void oscar_remove_buddy(struct gaim_connection *g, char *name) { | |
| 2563 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2564 | aim_remove_buddy(odata->sess, odata->conn, name); | |
| 2565 | } | |
| 2566 | ||
| 2567 | static void oscar_join_chat(struct gaim_connection *g, int exchange, char *name) { | |
| 2568 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2569 | struct aim_conn_t *cur = NULL; | |
| 2570 | if (!name) { | |
| 2571 | if (!join_chat_entry || !join_chat_spin) | |
| 2572 | return; | |
| 2573 | name = gtk_entry_get_text(GTK_ENTRY(join_chat_entry)); | |
| 2574 | exchange = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(join_chat_spin)); | |
| 2575 | if (!name || !strlen(name)) | |
| 2576 | return; | |
| 2577 | } | |
| 2578 | debug_printf("Attempting to join chat room %s.\n", name); | |
| 2579 | if ((cur = aim_getconn_type(odata->sess, AIM_CONN_TYPE_CHATNAV))) { | |
| 2580 | debug_printf("chatnav exists, creating room\n"); | |
| 2581 | aim_chatnav_createroom(odata->sess, cur, name, exchange); | |
| 2582 | } else { | |
| 2583 | /* this gets tricky */ | |
| 2584 | debug_printf("chatnav does not exist, opening chatnav\n"); | |
| 2585 | odata->create_exchange = exchange; | |
| 2586 | odata->create_name = g_strdup(name); | |
| 2587 | aim_bos_reqservice(odata->sess, odata->conn, AIM_CONN_TYPE_CHATNAV); | |
| 2588 | } | |
| 2589 | } | |
| 2590 | ||
| 2591 | static void des_jc() | |
| 2592 | { | |
| 2593 | join_chat_entry = NULL; | |
| 2594 | join_chat_spin = NULL; | |
| 2595 | } | |
| 2596 | ||
| 2597 | static void oscar_draw_join_chat(struct gaim_connection *gc, GtkWidget *fbox) { | |
| 2598 | GtkWidget *label; | |
| 2599 | GtkWidget *rowbox; | |
| 2600 | GtkObject *adjust; | |
| 2601 | ||
| 2602 | rowbox = gtk_hbox_new(FALSE, 5); | |
| 2603 | gtk_box_pack_start(GTK_BOX(fbox), rowbox, TRUE, TRUE, 0); | |
| 2604 | gtk_widget_show(rowbox); | |
| 2605 | ||
| 2606 | label = gtk_label_new(_("Join what group:")); | |
| 2607 | gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
| 2608 | gtk_signal_connect(GTK_OBJECT(label), "destroy", GTK_SIGNAL_FUNC(des_jc), NULL); | |
| 2609 | gtk_widget_show(label); | |
| 2610 | ||
| 2611 | join_chat_entry = gtk_entry_new(); | |
| 2612 | gtk_box_pack_start(GTK_BOX(rowbox), join_chat_entry, TRUE, TRUE, 0); | |
| 2613 | gtk_widget_grab_focus(join_chat_entry); | |
| 2614 | gtk_signal_connect(GTK_OBJECT(join_chat_entry), "activate", GTK_SIGNAL_FUNC(do_join_chat), NULL); | |
| 2615 | gtk_widget_show(join_chat_entry); | |
| 2616 | ||
| 2617 | rowbox = gtk_hbox_new(FALSE, 5); | |
| 2618 | gtk_box_pack_start(GTK_BOX(fbox), rowbox, TRUE, TRUE, 0); | |
| 2619 | gtk_widget_show(rowbox); | |
| 2620 | ||
| 2621 | label = gtk_label_new(_("Exchange:")); | |
| 2622 | gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
| 2623 | gtk_widget_show(label); | |
| 2624 | ||
| 2625 | adjust = gtk_adjustment_new(4, 4, 20, 1, 10, 10); | |
| 2626 | join_chat_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0); | |
| 2627 | gtk_widget_set_usize(join_chat_spin, 50, -1); | |
| 2628 | gtk_box_pack_start(GTK_BOX(rowbox), join_chat_spin, FALSE, FALSE, 0); | |
| 2629 | gtk_widget_show(join_chat_spin); | |
| 2630 | } | |
| 2631 | ||
| 2632 | static void oscar_chat_invite(struct gaim_connection *g, int id, char *message, char *name) { | |
| 2633 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2634 | struct chat_connection *ccon = find_oscar_chat(g, id); | |
| 2635 | ||
| 2636 | if (!ccon) | |
| 2637 | return; | |
| 2638 | ||
| 2639 | aim_chat_invite(odata->sess, odata->conn, name, message ? message : "", | |
| 2640 | ccon->exchange, ccon->name, 0x0); | |
| 2641 | } | |
| 2642 | ||
| 2643 | static void oscar_chat_leave(struct gaim_connection *g, int id) { | |
| 2644 | struct oscar_data *odata = g ? (struct oscar_data *)g->proto_data : NULL; | |
| 2645 | GSList *bcs = g->buddy_chats; | |
| 2646 | struct conversation *b = NULL; | |
| 2647 | struct chat_connection *c = NULL; | |
| 2648 | int count = 0; | |
| 2649 | ||
| 2650 | while (bcs) { | |
| 2651 | count++; | |
| 2652 | b = (struct conversation *)bcs->data; | |
| 2653 | if (id == b->id) | |
| 2654 | break; | |
| 2655 | bcs = bcs->next; | |
| 2656 | b = NULL; | |
| 2657 | } | |
| 2658 | ||
| 2659 | if (!b) | |
| 2660 | return; | |
| 2661 | ||
| 2662 | debug_printf("Attempting to leave room %s (currently in %d rooms)\n", b->name, count); | |
| 2663 | ||
| 2664 | c = find_oscar_chat(g, b->id); | |
| 2665 | if (c != NULL) { | |
| 2666 | if (odata) | |
| 2667 | odata->oscar_chats = g_slist_remove(odata->oscar_chats, c); | |
| 2668 | if (c->inpa > 0) | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
2669 | gaim_input_remove(c->inpa); |
| 2086 | 2670 | if (g && odata->sess) |
| 2671 | aim_conn_kill(odata->sess, &c->conn); | |
| 2672 | g_free(c->name); | |
| 2673 | g_free(c->show); | |
| 2674 | g_free(c); | |
| 2675 | } | |
| 2676 | /* we do this because with Oscar it doesn't tell us we left */ | |
| 2677 | serv_got_chat_left(g, b->id); | |
| 2678 | } | |
| 2679 | ||
| 2680 | static void oscar_chat_send(struct gaim_connection *g, int id, char *message) { | |
| 2681 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
| 2682 | GSList *bcs = g->buddy_chats; | |
| 2683 | struct conversation *b = NULL; | |
| 2684 | struct chat_connection *c = NULL; | |
| 2685 | char *buf; | |
| 2686 | int i, j; | |
| 2687 | ||
| 2688 | while (bcs) { | |
| 2689 | b = (struct conversation *)bcs->data; | |
| 2690 | if (id == b->id) | |
| 2691 | break; | |
| 2692 | bcs = bcs->next; | |
| 2693 | b = NULL; | |
| 2694 | } | |
| 2695 | if (!b) | |
| 2696 | return; | |
| 2697 | ||
| 2698 | bcs = odata->oscar_chats; | |
| 2699 | while (bcs) { | |
| 2700 | c = (struct chat_connection *)bcs->data; | |
| 2701 | if (b == c->cnv) | |
| 2702 | break; | |
| 2703 | bcs = bcs->next; | |
| 2704 | c = NULL; | |
| 2705 | } | |
| 2706 | if (!c) | |
| 2707 | return; | |
| 2708 | ||
| 2709 | buf = g_malloc(strlen(message) * 4 + 1); | |
| 2710 | for (i = 0, j = 0; i < strlen(message); i++) { | |
| 2711 | if (message[i] == '\n') { | |
| 2712 | buf[j++] = '<'; | |
| 2713 | buf[j++] = 'B'; | |
| 2714 | buf[j++] = 'R'; | |
| 2715 | buf[j++] = '>'; | |
| 2716 | } else { | |
| 2717 | buf[j++] = message[i]; | |
| 2718 | } | |
| 2719 | } | |
| 2720 | buf[j] = '\0'; | |
| 2721 | aim_chat_send_im(odata->sess, c->conn, 0, buf, strlen(buf)); | |
| 2722 | g_free(buf); | |
| 2723 | } | |
| 2724 | ||
| 2725 | static char **oscar_list_icon(int uc) { | |
| 2726 | if (uc & UC_UNAVAILABLE) | |
| 2727 | return (char **)away_icon_xpm; | |
| 2728 | if (uc & UC_AOL) | |
| 2729 | return (char **)aol_icon_xpm; | |
| 2730 | if (uc & UC_NORMAL) | |
| 2731 | return (char **)free_icon_xpm; | |
| 2732 | if (uc & UC_ADMIN) | |
| 2733 | return (char **)admin_icon_xpm; | |
| 2734 | if (uc & UC_UNCONFIRMED) | |
| 2735 | return (char **)dt_icon_xpm; | |
| 2736 | return NULL; | |
| 2737 | } | |
| 2738 | ||
| 2739 | static void oscar_info(GtkObject *obj, char *who) { | |
| 2740 | struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(obj); | |
| 2741 | serv_get_info(gc, who); | |
| 2742 | } | |
| 2743 | ||
| 2744 | static void oscar_away_msg(GtkObject *obj, char *who) { | |
| 2745 | struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(obj); | |
| 2746 | serv_get_away_msg(gc, who); | |
| 2747 | } | |
| 2748 | ||
| 2749 | static int gaim_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2750 | va_list ap; | |
| 2751 | struct gaim_connection *gc = sess->aux_data; | |
| 2752 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 2753 | struct aim_directim_priv *priv; | |
| 2754 | struct aim_conn_t *newconn; | |
| 2755 | struct direct_im *dim; | |
| 2756 | char buf[256]; | |
| 2757 | ||
| 2758 | va_start(ap, command); | |
| 2759 | newconn = va_arg(ap, struct aim_conn_t *); | |
| 2760 | va_end(ap); | |
| 2761 | ||
| 2762 | priv = (struct aim_directim_priv *)newconn->priv; | |
| 2763 | ||
| 2764 | debug_printf("DirectIM: initiate success to %s\n", priv->sn); | |
| 2765 | dim = find_direct_im(od, priv->sn); | |
| 2766 | ||
| 2767 | dim->cnv = find_conversation(priv->sn); | |
| 2768 | if (!dim->cnv) dim->cnv = new_conversation(priv->sn); | |
| 2769 | gtk_signal_connect(GTK_OBJECT(dim->cnv->window), "destroy", | |
| 2770 | GTK_SIGNAL_FUNC(delete_direct_im), dim); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
2771 | gaim_input_remove(dim->watcher); |
| 2086 | 2772 | dim->conn = newconn; |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
2773 | dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, |
| 2086 | 2774 | oscar_callback, dim->conn); |
| 2775 | g_snprintf(buf, sizeof buf, _("Direct IM with %s established"), priv->sn); | |
| 2776 | write_to_conv(dim->cnv, buf, WFLAG_SYSTEM, NULL, time((time_t)NULL)); | |
| 2777 | ||
| 2778 | aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, | |
| 2779 | gaim_directim_incoming, 0); | |
| 2780 | aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, | |
| 2781 | gaim_directim_disconnect, 0); | |
| 2782 | aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, | |
| 2783 | gaim_directim_typing, 0); | |
| 2784 | ||
| 2785 | return 1; | |
| 2786 | } | |
| 2787 | ||
| 2788 | static int gaim_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2789 | va_list ap; | |
| 2790 | char *msg = NULL; | |
| 2791 | struct aim_conn_t *conn; | |
| 2792 | struct aim_directim_priv *priv; | |
| 2793 | struct gaim_connection *gc = sess->aux_data; | |
| 2794 | ||
| 2795 | va_start(ap, command); | |
| 2796 | conn = va_arg(ap, struct aim_conn_t *); | |
| 2797 | msg = va_arg(ap, char *); | |
| 2798 | va_end(ap); | |
| 2799 | ||
| 2800 | if (!(priv = conn->priv)) { | |
| 2801 | return -1; | |
| 2802 | } | |
| 2803 | ||
| 2804 | debug_printf("Got DirectIM message from %s\n", priv->sn); | |
| 2805 | ||
| 2806 | serv_got_im(gc, priv->sn, msg, 0, time((time_t)NULL)); | |
| 2807 | ||
| 2808 | return 1; | |
| 2809 | } | |
| 2810 | ||
| 2811 | static int gaim_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2812 | va_list ap; | |
| 2813 | struct aim_conn_t *conn; | |
| 2814 | char *sn; | |
| 2815 | struct gaim_connection *gc = sess->aux_data; | |
| 2816 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 2817 | struct direct_im *dim; | |
| 2818 | char buf[256]; | |
| 2819 | ||
| 2820 | va_start(ap, command); | |
| 2821 | conn = va_arg(ap, struct aim_conn_t *); | |
| 2822 | sn = va_arg(ap, char *); | |
| 2823 | va_end(ap); | |
| 2824 | ||
| 2825 | debug_printf("%s disconnected Direct IM.\n", sn); | |
| 2826 | ||
| 2827 | dim = find_direct_im(od, sn); | |
| 2828 | od->direct_ims = g_slist_remove(od->direct_ims, dim); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
2829 | gaim_input_remove(dim->watcher); |
| 2086 | 2830 | gtk_signal_disconnect_by_data(GTK_OBJECT(dim->cnv->window), dim); |
| 2831 | ||
| 2832 | g_snprintf(buf, sizeof buf, _("Direct IM with %s closed"), sn); | |
| 2833 | if (dim->cnv) | |
| 2834 | write_to_conv(dim->cnv, buf, WFLAG_SYSTEM, NULL, time((time_t)NULL)); | |
| 2835 | ||
| 2836 | aim_conn_kill(sess, &conn); | |
| 2837 | ||
| 2838 | return 1; | |
| 2839 | } | |
| 2840 | ||
| 2841 | static int gaim_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...) { | |
| 2842 | va_list ap; | |
| 2843 | struct aim_conn_t *conn; | |
| 2844 | struct aim_directim_priv *priv; | |
| 2845 | ||
| 2846 | va_start(ap, command); | |
| 2847 | conn = va_arg(ap, struct aim_conn_t *); | |
| 2848 | va_end(ap); | |
| 2849 | ||
| 2850 | if (!(priv = conn->priv)) { | |
| 2851 | return -1; | |
| 2852 | } | |
| 2853 | ||
| 2854 | /* I had to leave this. It's just too funny. It reminds me of my sister. */ | |
| 2855 | debug_printf("ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", priv->sn); | |
| 2856 | ||
| 2857 | return 1; | |
| 2858 | } | |
| 2859 | ||
| 2860 | struct ask_do_dir_im { | |
| 2861 | char *who; | |
| 2862 | struct gaim_connection *gc; | |
| 2863 | }; | |
| 2864 | ||
| 2865 | static void oscar_cancel_direct_im(GtkObject *obj, struct ask_do_dir_im *data) { | |
| 2866 | g_free(data); | |
| 2867 | } | |
| 2868 | ||
| 2869 | static void oscar_direct_im(GtkObject *obj, struct ask_do_dir_im *data) { | |
| 2870 | struct gaim_connection *gc = data->gc; | |
| 2871 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 2872 | struct direct_im *dim; | |
| 2873 | ||
| 2874 | dim = find_direct_im(od, data->who); | |
| 2875 | if (dim) { | |
| 2876 | do_error_dialog("Direct IM request already pending.", "Unable"); | |
| 2877 | return; | |
| 2878 | } | |
| 2879 | dim = g_new0(struct direct_im, 1); | |
| 2880 | dim->gc = gc; | |
| 2881 | g_snprintf(dim->name, sizeof dim->name, "%s", data->who); | |
| 2882 | ||
| 2883 | dim->conn = aim_directim_initiate(od->sess, od->conn, NULL, data->who); | |
| 2884 | if (dim->conn != NULL) { | |
| 2885 | od->direct_ims = g_slist_append(od->direct_ims, dim); | |
|
2090
bab8b7e309db
[gaim-migrate @ 2100]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
2886 | dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, |
| 2086 | 2887 | oscar_callback, dim->conn); |
| 2888 | aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, | |
| 2889 | gaim_directim_initiate, 0); | |
| 2890 | } else { | |
| 2891 | do_error_dialog(_("Unable to open Direct IM"), _("Error")); | |
| 2892 | g_free(dim); | |
| 2893 | } | |
| 2894 | } | |
| 2895 | ||
| 2896 | static void oscar_ask_direct_im(GtkObject *m, gchar *who) { | |
| 2897 | char buf[BUF_LONG]; | |
| 2898 | struct ask_do_dir_im *data = g_new0(struct ask_do_dir_im, 1); | |
| 2899 | data->who = who; | |
| 2900 | data->gc = gtk_object_get_user_data(m); | |
| 2901 | g_snprintf(buf, sizeof(buf), _("You have selected to open a Direct IM connection with %s." | |
| 2902 | " Doing this will let them see your IP address, and may be" | |
| 2903 | " a security risk. Do you wish to continue?"), who); | |
| 2904 | do_ask_dialog(buf, data, oscar_direct_im, oscar_cancel_direct_im); | |
| 2905 | } | |
| 2906 | ||
| 2907 | static void oscar_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { | |
| 2908 | GtkWidget *button; | |
| 2909 | char *n = g_strdup(normalize(gc->username)); | |
| 2910 | ||
| 2911 | button = gtk_menu_item_new_with_label(_("Get Info")); | |
| 2912 | gtk_signal_connect(GTK_OBJECT(button), "activate", | |
| 2913 | GTK_SIGNAL_FUNC(oscar_info), who); | |
| 2914 | gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 2915 | gtk_menu_append(GTK_MENU(menu), button); | |
| 2916 | gtk_widget_show(button); | |
| 2917 | ||
| 2918 | button = gtk_menu_item_new_with_label(_("Get Away Msg")); | |
| 2919 | gtk_signal_connect(GTK_OBJECT(button), "activate", | |
| 2920 | GTK_SIGNAL_FUNC(oscar_away_msg), who); | |
| 2921 | gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 2922 | gtk_menu_append(GTK_MENU(menu), button); | |
| 2923 | gtk_widget_show(button); | |
| 2924 | ||
| 2925 | if (strcmp(n, normalize(who))) { | |
| 2926 | button = gtk_menu_item_new_with_label(_("Direct IM")); | |
| 2927 | gtk_signal_connect(GTK_OBJECT(button), "activate", | |
| 2928 | GTK_SIGNAL_FUNC(oscar_ask_direct_im), who); | |
| 2929 | gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 2930 | gtk_menu_append(GTK_MENU(menu), button); | |
| 2931 | gtk_widget_show(button); | |
| 2932 | } | |
| 2933 | g_free(n); | |
| 2934 | } | |
| 2935 | ||
| 2936 | ||
| 2937 | /* weeee */ | |
| 2938 | static void oscar_print_option(GtkEntry *entry, struct aim_user *user) | |
| 2939 | { | |
| 2940 | int entrynum; | |
| 2941 | ||
| 2942 | entrynum = (int)gtk_object_get_user_data(GTK_OBJECT(entry)); | |
| 2943 | ||
| 2944 | if (entrynum == USEROPT_AUTH) { | |
| 2945 | g_snprintf(user->proto_opt[USEROPT_AUTH], | |
| 2946 | sizeof(user->proto_opt[USEROPT_AUTH]), "%s", gtk_entry_get_text(entry)); | |
| 2947 | } else if (entrynum == USEROPT_AUTHPORT) { | |
| 2948 | g_snprintf(user->proto_opt[USEROPT_AUTHPORT], | |
| 2949 | sizeof(user->proto_opt[USEROPT_AUTHPORT]), "%s", gtk_entry_get_text(entry)); | |
| 2950 | } | |
| 2951 | } | |
| 2952 | ||
| 2953 | static void oscar_user_opts(GtkWidget *book, struct aim_user *user) | |
| 2954 | { | |
| 2955 | /* so here, we create the new notebook page */ | |
| 2956 | GtkWidget *vbox; | |
| 2957 | GtkWidget *hbox; | |
| 2958 | GtkWidget *label; | |
| 2959 | GtkWidget *entry; | |
| 2960 | ||
| 2961 | vbox = gtk_vbox_new(FALSE, 5); | |
| 2962 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | |
| 2963 | gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("Oscar Options")); | |
| 2964 | gtk_widget_show(vbox); | |
| 2965 | ||
| 2966 | hbox = gtk_hbox_new(FALSE, 5); | |
| 2967 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
| 2968 | gtk_widget_show(hbox); | |
| 2969 | ||
| 2970 | label = gtk_label_new("Auth Host:"); | |
| 2971 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 2972 | gtk_widget_show(label); | |
| 2973 | ||
| 2974 | entry = gtk_entry_new(); | |
| 2975 | gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
| 2976 | gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_AUTH); | |
| 2977 | gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(oscar_print_option), user); | |
| 2978 | if (user->proto_opt[USEROPT_AUTH][0]) { | |
| 2979 | debug_printf("setting text %s\n", user->proto_opt[USEROPT_AUTH]); | |
| 2980 | gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_AUTH]); | |
| 2981 | } else | |
| 2982 | gtk_entry_set_text(GTK_ENTRY(entry), "login.oscar.aol.com"); | |
| 2983 | gtk_widget_show(entry); | |
| 2984 | ||
| 2985 | hbox = gtk_hbox_new(FALSE, 0); | |
| 2986 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
| 2987 | gtk_widget_show(hbox); | |
| 2988 | ||
| 2989 | label = gtk_label_new("Auth Port:"); | |
| 2990 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 2991 | gtk_widget_show(label); | |
| 2992 | ||
| 2993 | entry = gtk_entry_new(); | |
| 2994 | gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
| 2995 | gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_AUTHPORT); | |
| 2996 | gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(oscar_print_option), user); | |
| 2997 | if (user->proto_opt[USEROPT_AUTHPORT][0]) { | |
| 2998 | debug_printf("setting text %s\n", user->proto_opt[USEROPT_AUTHPORT]); | |
| 2999 | gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_AUTHPORT]); | |
| 3000 | } else | |
| 3001 | gtk_entry_set_text(GTK_ENTRY(entry), "5190"); | |
| 3002 | ||
| 3003 | gtk_widget_show(entry); | |
| 3004 | } | |
| 3005 | ||
| 3006 | static void oscar_set_permit_deny(struct gaim_connection *gc) { | |
| 3007 | struct oscar_data *od = (struct oscar_data *)gc->proto_data; | |
| 3008 | GSList *list; | |
| 3009 | char buf[MAXMSGLEN]; | |
| 3010 | int at; | |
| 3011 | ||
| 3012 | switch(gc->permdeny) { | |
| 3013 | case 1: | |
| 3014 | aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_DENYADD, gc->username); | |
| 3015 | break; | |
| 3016 | case 2: | |
| 3017 | aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_PERMITADD, gc->username); | |
| 3018 | break; | |
| 3019 | case 3: | |
| 3020 | list = gc->permit; | |
| 3021 | at = 0; | |
| 3022 | while (list) { | |
| 3023 | at += g_snprintf(buf + at, sizeof(buf) - at, "%s&", (char *)list->data); | |
| 3024 | list = list->next; | |
| 3025 | } | |
| 3026 | aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_PERMITADD, buf); | |
| 3027 | break; | |
| 3028 | case 4: | |
| 3029 | list = gc->deny; | |
| 3030 | at = 0; | |
| 3031 | while (list) { | |
| 3032 | at += g_snprintf(buf + at, sizeof(buf) - at, "%s&", (char *)list->data); | |
| 3033 | list = list->next; | |
| 3034 | } | |
| 3035 | aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_DENYADD, buf); | |
| 3036 | break; | |
| 3037 | default: | |
| 3038 | break; | |
| 3039 | } | |
| 3040 | } | |
| 3041 | ||
| 3042 | static void oscar_add_permit(struct gaim_connection *gc, char *who) { | |
| 3043 | if (gc->permdeny != 3) return; | |
| 3044 | oscar_set_permit_deny(gc); | |
| 3045 | } | |
| 3046 | ||
| 3047 | static void oscar_add_deny(struct gaim_connection *gc, char *who) { | |
| 3048 | if (gc->permdeny != 4) return; | |
| 3049 | oscar_set_permit_deny(gc); | |
| 3050 | } | |
| 3051 | ||
| 3052 | static void oscar_rem_permit(struct gaim_connection *gc, char *who) { | |
| 3053 | if (gc->permdeny != 3) return; | |
| 3054 | oscar_set_permit_deny(gc); | |
| 3055 | } | |
| 3056 | ||
| 3057 | static void oscar_rem_deny(struct gaim_connection *gc, char *who) { | |
| 3058 | if (gc->permdeny != 4) return; | |
| 3059 | oscar_set_permit_deny(gc); | |
| 3060 | } | |
| 3061 | ||
| 3062 | static void oscar_draw_new_user(GtkWidget *box) | |
| 3063 | { | |
| 3064 | GtkWidget *label; | |
| 3065 | ||
| 3066 | label = gtk_label_new(_("Unfortunately, currently Oscar only allows new user registration by " | |
| 3067 | "going to http://aim.aol.com/aimnew/Aim/register.adp?promo=106723&pageset=Aim&client=no" | |
| 3068 | ". Clicking the Register button will open the URL for you.")); | |
| 3069 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 3070 | gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5); | |
| 3071 | gtk_widget_show(label); | |
| 3072 | } | |
| 3073 | ||
| 3074 | static void oscar_do_new_user() | |
| 3075 | { | |
| 3076 | open_url(NULL, "http://aim.aol.com/aimnew/Aim/register.adp?promo=106723&pageset=Aim&client=no"); | |
| 3077 | } | |
| 3078 | ||
| 3079 | static GList *oscar_away_states() | |
| 3080 | { | |
| 3081 | return g_list_append(NULL, GAIM_AWAY_CUSTOM); | |
| 3082 | } | |
| 3083 | ||
| 3084 | static void oscar_do_action(struct gaim_connection *gc, char *act) | |
| 3085 | { | |
| 3086 | struct oscar_data *od = gc->proto_data; | |
| 3087 | struct aim_conn_t *conn = aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH); | |
| 3088 | ||
| 3089 | if (!strcmp(act, "Set User Info")) { | |
| 3090 | show_set_info(gc); | |
| 3091 | } else if (!strcmp(act, "Change Password")) { | |
| 3092 | show_change_passwd(gc); | |
| 3093 | } else if (!strcmp(act, "Confirm Account")) { | |
| 3094 | if (!conn) { | |
| 3095 | od->conf = TRUE; | |
| 3096 | aim_bos_reqservice(od->sess, od->conn, AIM_CONN_TYPE_AUTH); | |
| 3097 | } else | |
| 3098 | aim_auth_reqconfirm(od->sess, conn); | |
| 3099 | } else if (!strcmp(act, "Change Email")) { | |
| 3100 | } else if (!strcmp(act, "Display Current Registered Address")) { | |
| 3101 | if (!conn) { | |
| 3102 | od->reqemail = TRUE; | |
| 3103 | aim_bos_reqservice(od->sess, od->conn, AIM_CONN_TYPE_AUTH); | |
| 3104 | } else | |
| 3105 | aim_auth_getinfo(od->sess, conn, 0x11); | |
| 3106 | } else if (!strcmp(act, "Search for Buddy by Email")) { | |
| 3107 | show_find_email(gc); | |
| 3108 | } | |
| 3109 | } | |
| 3110 | ||
| 3111 | static GList *oscar_actions() | |
| 3112 | { | |
| 3113 | GList *m = NULL; | |
| 3114 | ||
| 3115 | m = g_list_append(m, "Set User Info"); | |
| 3116 | m = g_list_append(m, NULL); | |
| 3117 | m = g_list_append(m, "Change Password"); | |
| 3118 | m = g_list_append(m, "Confirm Account"); | |
| 3119 | /* | |
| 3120 | m = g_list_append(m, "Change Email"); | |
| 3121 | */ | |
| 3122 | m = g_list_append(m, "Display Current Registered Address"); | |
| 3123 | m = g_list_append(m, NULL); | |
| 3124 | m = g_list_append(m, "Search for Buddy by Email"); | |
| 3125 | ||
| 3126 | return m; | |
| 3127 | } | |
| 3128 | ||
| 3129 | static void oscar_change_passwd(struct gaim_connection *gc, char *old, char *new) | |
| 3130 | { | |
| 3131 | struct oscar_data *od = gc->proto_data; | |
| 3132 | if (!aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH)) { | |
| 3133 | od->chpass = TRUE; | |
| 3134 | od->oldp = g_strdup(old); | |
| 3135 | od->newp = g_strdup(new); | |
| 3136 | aim_bos_reqservice(od->sess, od->conn, AIM_CONN_TYPE_AUTH); | |
| 3137 | } else { | |
| 3138 | aim_auth_changepasswd(od->sess, aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH), | |
| 3139 | new, old); | |
| 3140 | } | |
| 3141 | } | |
| 3142 | ||
| 3143 | static void oscar_insert_convo(struct gaim_connection *gc, struct conversation *c) | |
| 3144 | { | |
| 3145 | #if USE_PIXBUF | |
| 3146 | struct oscar_data *od = gc->proto_data; | |
| 3147 | GSList *h = od->hasicons; | |
| 3148 | struct icon_req *ir = NULL; | |
| 3149 | char *who = normalize(c->name); | |
| 3150 | ||
| 3151 | GdkPixbufLoader *load; | |
| 3152 | GList *frames; | |
| 3153 | GdkPixbuf *buf; | |
| 3154 | GdkPixmap *pm; | |
| 3155 | GdkBitmap *bm; | |
| 3156 | ||
| 3157 | while (h) { | |
| 3158 | ir = h->data; | |
| 3159 | if (!strcmp(who, ir->user)) | |
| 3160 | break; | |
| 3161 | h = h->next; | |
| 3162 | } | |
| 3163 | if (!h || !ir->data) | |
| 3164 | return; | |
| 3165 | ||
| 3166 | ir->cnv = c; | |
| 3167 | ||
| 3168 | load = gdk_pixbuf_loader_new(); | |
| 3169 | gdk_pixbuf_loader_write(load, ir->data, ir->length); | |
| 3170 | ir->anim = gdk_pixbuf_loader_get_animation(load); | |
| 3171 | ||
| 3172 | if (ir->anim) { | |
| 3173 | frames = gdk_pixbuf_animation_get_frames(ir->anim); | |
| 3174 | buf = gdk_pixbuf_frame_get_pixbuf(frames->data); | |
| 3175 | gdk_pixbuf_render_pixmap_and_mask(buf, &pm, &bm, 0); | |
| 3176 | ||
| 3177 | if (gdk_pixbuf_animation_get_num_frames(ir->anim) > 1) { | |
| 3178 | int delay = MAX(gdk_pixbuf_frame_get_delay_time(frames->data), 13); | |
| 3179 | ir->curframe = 1; | |
| 3180 | ir->timer = gtk_timeout_add(delay * 10, redraw_anim, ir); | |
| 3181 | } | |
| 3182 | } else { | |
| 3183 | ir->unanim = gdk_pixbuf_loader_get_pixbuf(load); | |
| 3184 | if (!ir->unanim) { | |
| 3185 | gdk_pixbuf_loader_close(load); | |
| 3186 | return; | |
| 3187 | } | |
| 3188 | gdk_pixbuf_render_pixmap_and_mask(ir->unanim, &pm, &bm, 0); | |
| 3189 | } | |
| 3190 | ||
| 3191 | ir->pix = gtk_pixmap_new(pm, bm); | |
| 3192 | gtk_box_pack_start(GTK_BOX(c->bbox), ir->pix, FALSE, FALSE, 5); | |
| 3193 | if (ir->anim && (gdk_pixbuf_animation_get_num_frames(ir->anim) > 1)) | |
| 3194 | gtk_widget_set_usize(ir->pix, gdk_pixbuf_animation_get_width(ir->anim), | |
| 3195 | gdk_pixbuf_animation_get_height(ir->anim)); | |
| 3196 | gtk_widget_show(ir->pix); | |
| 3197 | gdk_pixmap_unref(pm); | |
| 3198 | if (bm) | |
| 3199 | gdk_bitmap_unref(bm); | |
| 3200 | ||
| 3201 | gdk_pixbuf_loader_close(load); | |
| 3202 | #endif | |
| 3203 | } | |
| 3204 | ||
| 3205 | static void oscar_remove_convo(struct gaim_connection *gc, struct conversation *c) | |
| 3206 | { | |
| 3207 | #if USE_PIXBUF | |
| 3208 | struct oscar_data *od = gc->proto_data; | |
| 3209 | GSList *h = od->hasicons; | |
| 3210 | struct icon_req *ir = NULL; | |
| 3211 | char *who = normalize(c->name); | |
| 3212 | ||
| 3213 | while (h) { | |
| 3214 | ir = h->data; | |
| 3215 | if (!strcmp(who, ir->user)) | |
| 3216 | break; | |
| 3217 | h = h->next; | |
| 3218 | } | |
| 3219 | if (!h || !ir->data) | |
| 3220 | return; | |
| 3221 | ||
| 3222 | if (ir->cnv && ir->pix) { | |
| 3223 | gtk_container_remove(GTK_CONTAINER(ir->cnv->bbox), ir->pix); | |
| 3224 | ir->pix = NULL; | |
| 3225 | ir->cnv = NULL; | |
| 3226 | } | |
| 3227 | ||
| 3228 | if (ir->anim) { | |
| 3229 | gdk_pixbuf_animation_unref(ir->anim); | |
| 3230 | ir->anim = NULL; | |
| 3231 | } else if (ir->unanim) { | |
| 3232 | gdk_pixbuf_unref(ir->unanim); | |
| 3233 | ir->unanim = NULL; | |
| 3234 | } | |
| 3235 | ||
| 3236 | ir->curframe = 0; | |
| 3237 | ||
| 3238 | if (ir->timer) | |
| 3239 | gtk_timeout_remove(ir->timer); | |
| 3240 | ir->timer = 0; | |
| 3241 | #endif | |
| 3242 | } | |
| 3243 | ||
| 3244 | static struct prpl *my_protocol = NULL; | |
| 3245 | ||
| 3246 | void oscar_init(struct prpl *ret) { | |
| 3247 | ret->protocol = PROTO_OSCAR; | |
| 3248 | ret->options = OPT_PROTO_HTML | OPT_PROTO_CORRECT_TIME; | |
| 3249 | ret->name = oscar_name; | |
| 3250 | ret->list_icon = oscar_list_icon; | |
| 3251 | ret->away_states = oscar_away_states; | |
| 3252 | ret->actions = oscar_actions; | |
| 3253 | ret->do_action = oscar_do_action; | |
| 3254 | ret->buddy_menu = oscar_buddy_menu; | |
| 3255 | ret->user_opts = oscar_user_opts; | |
| 3256 | ret->draw_new_user = oscar_draw_new_user; | |
| 3257 | ret->do_new_user = oscar_do_new_user; | |
| 3258 | ret->insert_convo = oscar_insert_convo; | |
| 3259 | ret->remove_convo = oscar_remove_convo; | |
| 3260 | ret->login = oscar_login; | |
| 3261 | ret->close = oscar_close; | |
| 3262 | ret->send_im = oscar_send_im; | |
| 3263 | ret->set_info = oscar_set_info; | |
| 3264 | ret->get_info = oscar_get_info; | |
| 3265 | ret->set_away = oscar_set_away; | |
| 3266 | ret->get_away_msg = oscar_get_away_msg; | |
| 3267 | ret->set_dir = oscar_set_dir; | |
| 3268 | ret->get_dir = NULL; /* Oscar really doesn't have this */ | |
| 3269 | ret->dir_search = oscar_dir_search; | |
| 3270 | ret->set_idle = oscar_set_idle; | |
| 3271 | ret->change_passwd = oscar_change_passwd; | |
| 3272 | ret->add_buddy = oscar_add_buddy; | |
| 3273 | ret->add_buddies = oscar_add_buddies; | |
| 3274 | ret->remove_buddy = oscar_remove_buddy; | |
| 3275 | ret->add_permit = oscar_add_permit; | |
| 3276 | ret->add_deny = oscar_add_deny; | |
| 3277 | ret->rem_permit = oscar_rem_permit; | |
| 3278 | ret->rem_deny = oscar_rem_deny; | |
| 3279 | ret->set_permit_deny = oscar_set_permit_deny; | |
| 3280 | ret->warn = oscar_warn; | |
| 3281 | ret->accept_chat = NULL; /* oscar doesn't have accept, it just joins */ | |
| 3282 | ret->join_chat = oscar_join_chat; | |
| 3283 | ret->draw_join_chat = oscar_draw_join_chat; | |
| 3284 | ret->chat_invite = oscar_chat_invite; | |
| 3285 | ret->chat_leave = oscar_chat_leave; | |
| 3286 | ret->chat_whisper = NULL; | |
| 3287 | ret->chat_send = oscar_chat_send; | |
| 3288 | ret->keepalive = oscar_keepalive; | |
| 3289 | ||
| 3290 | my_protocol = ret; | |
| 3291 | } | |
| 3292 | ||
| 3293 | #ifndef STATIC | |
| 3294 | ||
| 3295 | char *gaim_plugin_init(GModule *handle) | |
| 3296 | { | |
| 3297 | load_protocol(oscar_init, sizeof(struct prpl)); | |
| 3298 | return NULL; | |
| 3299 | } | |
| 3300 | ||
| 3301 | void gaim_plugin_remove() | |
| 3302 | { | |
| 3303 | struct prpl *p = find_prpl(PROTO_OSCAR); | |
| 3304 | if (p == my_protocol) | |
| 3305 | unload_protocol(p); | |
| 3306 | } | |
| 3307 | ||
| 3308 | char *name() | |
| 3309 | { | |
| 3310 | return "Oscar"; | |
| 3311 | } | |
| 3312 | ||
| 3313 | char *description() | |
| 3314 | { | |
| 3315 | return "Allows gaim to use the Oscar protocol."; | |
| 3316 | } | |
| 3317 | ||
| 3318 | #endif |