--- a/ChangeLog Sat Dec 21 15:11:06 2002 -0500
+++ b/ChangeLog Fri Dec 27 02:22:31 2002 -0500
@@ -10,6 +10,8 @@
notably MIPSpro (Thanks David Kaelbling)
* Fixed a bad argument to accept() calls (Thanks David
+ * Fixed crashbug on empty rvous requests (Thanks Brandon Scott (Xeon)) + for being the first to point this out. version 0.59.6 (11/07/2002):
* Fixed a segfault introduced in 0.59.5 when gtk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/oscar/oscar.c Fri Dec 27 02:22:31 2002 -0500
@@ -0,0 +1,3960 @@
+ * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> + * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#include "pixmaps/ab.xpm" +#include "pixmaps/admin_icon.xpm" +#include "pixmaps/aol_icon.xpm" +#include "pixmaps/away_icon.xpm" +#include "pixmaps/dt_icon.xpm" +#include "pixmaps/free_icon.xpm" +#include "pixmaps/wireless_icon.xpm" +#include "pixmaps/gnomeicu-online.xpm" +#include "pixmaps/gnomeicu-offline.xpm" +#include "pixmaps/gnomeicu-away.xpm" +#include "pixmaps/gnomeicu-dnd.xpm" +#include "pixmaps/gnomeicu-na.xpm" +#include "pixmaps/gnomeicu-occ.xpm" +#include "pixmaps/gnomeicu-ffc.xpm" +/* constants to identify proto_opts */ +#define USEROPT_AUTHPORT 1 +#define UC_UNCONFIRMED 0x08 +#define UC_WIRELESS 0x40 +#define AIMHASHDATA "http://gaim.sourceforge.net/aim_data.php3" +static int gaim_caps = AIM_CAPS_CHAT | +static fu8_t gaim_features[] = {0x01, 0x01, 0x01, 0x02}; + guint maxbuddies; /* max users you can watch */ + guint maxwatchers; /* max users who can watch you */ + guint maxpermits; /* max users on permit list */ + guint maxdenies; /* max users on deny list */ + guint maxsiglen; /* max size (bytes) of profile */ + guint maxawaymsglen; /* max size (bytes) of posted away message */ +struct chat_connection { + char *show; /* AOL did something funny to us */ + int fd; /* this is redundant since we have the conn below */ + struct gaim_connection *gc; /* i hate this. */ + struct conversation *cnv; /* bah. */ + struct gaim_connection *gc; + struct gaim_connection *gc; + unsigned long checksum; + struct gaim_connection *gc; +static struct direct_im *find_direct_im(struct oscar_data *od, const char *who) { + GSList *d = od->direct_ims; + char *n = g_strdup(normalize(who)); + struct direct_im *m = NULL; + m = (struct direct_im *)d->data; + if (!strcmp(n, normalize(m->name))) +static char *extract_name(const char *name) { + for (i = 0, j = 0; x[i]; i++) { + strncpy(hex, x + ++i, 2); hex[2] = 0; + tmp[j++] = strtol(hex, NULL, 16); +static struct chat_connection *find_oscar_chat(struct gaim_connection *gc, int id) { + GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats; + struct chat_connection *c = NULL; + c = (struct chat_connection *)g->data; +static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc, + GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats; + struct chat_connection *c = NULL; + c = (struct chat_connection *)g->data; +static int gaim_parse_auth_resp (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_login (aim_session_t *, aim_frame_t *, ...); +static int gaim_handle_redirect (aim_session_t *, aim_frame_t *, ...); +static int gaim_info_change (aim_session_t *, aim_frame_t *, ...); +static int gaim_account_confirm (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_oncoming (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_offgoing (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_incoming_im(aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_misses (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_clientauto (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_user_info (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_motd (aim_session_t *, aim_frame_t *, ...); +static int gaim_chatnav_info (aim_session_t *, aim_frame_t *, ...); +static int gaim_chat_join (aim_session_t *, aim_frame_t *, ...); +static int gaim_chat_leave (aim_session_t *, aim_frame_t *, ...); +static int gaim_chat_info_update (aim_session_t *, aim_frame_t *, ...); +static int gaim_chat_incoming_msg(aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_msgack (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_ratechange (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_evilnotify (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_searcherror(aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_searchreply(aim_session_t *, aim_frame_t *, ...); +static int gaim_bosrights (aim_session_t *, aim_frame_t *, ...); +static int conninitdone_bos (aim_session_t *, aim_frame_t *, ...); +static int conninitdone_admin (aim_session_t *, aim_frame_t *, ...); +static int conninitdone_chat (aim_session_t *, aim_frame_t *, ...); +static int conninitdone_chatnav (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_msgerr (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_locaterights(aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_buddyrights(aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_locerr (aim_session_t *, aim_frame_t *, ...); +static int gaim_icbm_param_info (aim_session_t *, aim_frame_t *, ...); +static int gaim_parse_genericerr (aim_session_t *, aim_frame_t *, ...); +static int gaim_memrequest (aim_session_t *, aim_frame_t *, ...); +static int gaim_selfinfo (aim_session_t *, aim_frame_t *, ...); +static int gaim_offlinemsg (aim_session_t *, aim_frame_t *, ...); +static int gaim_offlinemsgdone (aim_session_t *, aim_frame_t *, ...); +static int gaim_simpleinfo (aim_session_t *, aim_frame_t *, ...); +static int gaim_popup (aim_session_t *, aim_frame_t *, ...); +static int gaim_ssi_parserights (aim_session_t *, aim_frame_t *, ...); +static int gaim_ssi_parselist (aim_session_t *, aim_frame_t *, ...); +static int gaim_directim_initiate(aim_session_t *, aim_frame_t *, ...); +static int gaim_directim_incoming(aim_session_t *, aim_frame_t *, ...); +static int gaim_directim_typing (aim_session_t *, aim_frame_t *, ...); +static int gaim_update_ui (aim_session_t *, aim_frame_t *, ...); +static char *msgerrreason[] = { + "Not supported by host", + "Not supported by client", + "In local permit/deny", + "User temporarily unavailable", +static int msgerrreasonlen = 25; +static void gaim_directim_disconnect(aim_session_t *sess, aim_conn_t *conn) { + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + struct conversation *cnv; + sn = g_strdup(aim_directim_getsn(conn)); + debug_printf("%s disconnected Direct IM.\n", sn); + dim = find_direct_im(od, sn); + od->direct_ims = g_slist_remove(od->direct_ims, dim); + gaim_input_remove(dim->watcher); + g_snprintf(buf, sizeof buf, _("Direct IM with %s closed"), sn); + g_snprintf(buf, sizeof buf, _("Direct IM with %s failed"), sn); + if ((cnv = find_conversation(sn))) + write_to_conv(cnv, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); + update_progress(cnv, 100); + g_free(dim); /* I guess? I don't see it anywhere else... -- mid */ +static void oscar_callback(gpointer data, gint source, + GaimInputCondition condition) { + aim_conn_t *conn = (aim_conn_t *)data; + aim_session_t *sess = aim_conn_getsess(conn); + struct gaim_connection *gc = sess ? sess->aux_data : NULL; + struct oscar_data *odata; + /* gc is null. we return, else we seg SIGSEG on next line. */ + debug_printf("oscar callback for closed connection (1).\n"); + odata = (struct oscar_data *)gc->proto_data; + if (!g_slist_find(connections, gc)) { + /* oh boy. this is probably bad. i guess the only thing we + * can really do is return? */ + debug_printf("oscar callback for closed connection (2).\n"); + if (condition & GAIM_INPUT_READ) { + if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { + debug_printf("got information on rendezvous\n"); + if (aim_handlerendconnect(odata->sess, conn) < 0) { + debug_printf(_("connection error (rend)\n")); + aim_conn_kill(odata->sess, &conn); + if (aim_get_command(odata->sess, conn) >= 0) { + aim_rxdispatch(odata->sess); + if ((conn->type == AIM_CONN_TYPE_BOS) || + !(aim_getconn_type(odata->sess, AIM_CONN_TYPE_BOS))) { + debug_printf(_("major connection error\n")); + hide_login_progress_error(gc, _("Disconnected.")); + } else if (conn->type == AIM_CONN_TYPE_CHAT) { + struct chat_connection *c = find_oscar_chat_by_conn(gc, conn); + debug_printf("disconnected from chat room %s\n", c->name); + gaim_input_remove(c->inpa); + aim_conn_kill(odata->sess, &conn); + sprintf(buf, _("You have been disconnected from chat room %s."), c->name); + do_error_dialog(buf, _("Chat Error!")); + } else if (conn->type == AIM_CONN_TYPE_CHATNAV) { + gaim_input_remove(odata->cnpa); + debug_printf("removing chatnav input watcher\n"); + while (odata->create_rooms) { + struct create_room *cr = odata->create_rooms->data; + g_slist_remove(odata->create_rooms, cr); + do_error_dialog(_("Chat is currently unavailable"), + aim_conn_kill(odata->sess, &conn); + } else if (conn->type == AIM_CONN_TYPE_AUTH) { + gaim_input_remove(odata->paspa); + debug_printf("removing authconn input watcher\n"); + aim_conn_kill(odata->sess, &conn); + } else if (conn->type == AIM_CONN_TYPE_RENDEZVOUS) { + if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) + gaim_directim_disconnect(odata->sess, conn); + debug_printf("No handler for rendezvous disconnect (%d).\n", + aim_conn_kill(odata->sess, &conn); + debug_printf("holy crap! generic connection error! %d\n", + aim_conn_kill(odata->sess, &conn); +static void oscar_debug(aim_session_t *sess, int level, const char *format, va_list va) { + char *s = g_strdup_vprintf(format, va); + struct gaim_connection *gc = sess->aux_data; + g_snprintf(buf, sizeof(buf), "%s %d: ", gc->username, level); + t = g_strconcat(buf, s, NULL); + if (t[strlen(t)-1] != '\n') +static void oscar_login_connect(gpointer data, gint source, GaimInputCondition cond) + struct gaim_connection *gc = data; + struct oscar_data *odata; + if (!g_slist_find(connections, gc)) { + odata = gc->proto_data; + conn = aim_getconn_type_all(sess, AIM_CONN_TYPE_AUTH); + hide_login_progress(gc, _("Couldn't connect to host")); + aim_conn_completeconnect(sess, conn); + gc->inpa = gaim_input_add(conn->fd, GAIM_INPUT_READ, + debug_printf(_("Password sent, waiting for response\n")); +static void oscar_login(struct aim_user *user) { + struct gaim_connection *gc = new_gaim_conn(user); + struct oscar_data *odata = gc->proto_data = g_new0(struct oscar_data, 1); + if (isdigit(*user->username)) { + /* this is odd but it's necessary for a proper do_import and do_export */ + gc->protocol = PROTO_ICQ; + gc->protocol = PROTO_TOC; + gc->flags |= OPT_CONN_HTML; + sess = g_new0(aim_session_t, 1); + aim_session_init(sess, AIM_SESS_FLAGS_NONBLOCKCONNECT, 0); + aim_setdebuggingcb(sess, oscar_debug); + /* we need an immediate queue because we don't use a while-loop to + * see if things need to be sent. */ + aim_tx_setenqueue(sess, AIM_TX_IMMEDIATE, NULL); + conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL); + debug_printf(_("internal connection error\n")); + hide_login_progress(gc, _("Unable to login to AIM")); + g_snprintf(buf, sizeof(buf), _("Signon: %s"), gc->username); + set_login_progress(gc, 2, buf); + aim_conn_addhandler(sess, conn, 0x0017, 0x0007, gaim_parse_login, 0); + aim_conn_addhandler(sess, conn, 0x0017, 0x0003, gaim_parse_auth_resp, 0); + conn->status |= AIM_CONN_STATUS_INPROGRESS; + conn->fd = proxy_connect(user->proto_opt[USEROPT_AUTH][0] ? + user->proto_opt[USEROPT_AUTH] : FAIM_LOGIN_SERVER, + user->proto_opt[USEROPT_AUTHPORT][0] ? + atoi(user->proto_opt[USEROPT_AUTHPORT]) : FAIM_LOGIN_PORT, + oscar_login_connect, gc); + hide_login_progress(gc, _("Couldn't connect to host")); + aim_request_login(sess, conn, gc->username); +static void oscar_close(struct gaim_connection *gc) { + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + while (odata->oscar_chats) { + struct chat_connection *n = odata->oscar_chats->data; + gaim_input_remove(n->inpa); + odata->oscar_chats = g_slist_remove(odata->oscar_chats, n); + while (odata->direct_ims) { + struct direct_im *n = odata->direct_ims->data; + gaim_input_remove(n->watcher); + odata->direct_ims = g_slist_remove(odata->direct_ims, n); + while (odata->hasicons) { + struct icon_req *n = odata->hasicons->data; + odata->hasicons = g_slist_remove(odata->hasicons, n); + while (odata->evilhack) { + g_free(odata->evilhack->data); + odata->evilhack = g_slist_remove(odata->evilhack, odata->evilhack->data); + while (odata->create_rooms) { + struct create_room *cr = odata->create_rooms->data; + odata->create_rooms = g_slist_remove(odata->create_rooms, cr); + gaim_input_remove(gc->inpa); + gaim_input_remove(odata->cnpa); + gaim_input_remove(odata->paspa); + aim_session_kill(odata->sess); + g_free(gc->proto_data); + debug_printf(_("Signed off.\n")); +static void oscar_bos_connect(gpointer data, gint source, GaimInputCondition cond) { + struct gaim_connection *gc = data; + struct oscar_data *odata; + if (!g_slist_find(connections, gc)) { + odata = gc->proto_data; + hide_login_progress(gc, _("Could Not Connect")); + aim_conn_completeconnect(sess, bosconn); + gc->inpa = gaim_input_add(bosconn->fd, GAIM_INPUT_READ, + oscar_callback, bosconn); + set_login_progress(gc, 4, _("Connection established, cookie sent")); +static int gaim_parse_auth_resp(aim_session_t *sess, aim_frame_t *fr, ...) { + struct aim_authresp_info *info; + int i; char *host; int port; + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *od = gc->proto_data; + port = user->proto_opt[USEROPT_AUTHPORT][0] ? + atoi(user->proto_opt[USEROPT_AUTHPORT]) : FAIM_LOGIN_PORT, + info = va_arg(ap, struct aim_authresp_info *); + debug_printf("inside auth_resp (Screen name: %s)\n", info->sn); + if (info->errorcode || !info->bosip || !info->cookie) { + switch (info->errorcode) { + /* Incorrect nick/password */ + hide_login_progress(gc, _("Incorrect nickname or password.")); + plugin_event(event_error, (void *)980, 0, 0, 0); + /* Suspended account */ + hide_login_progress(gc, _("Your account is currently suspended.")); + /* connecting too frequently */ + 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.")); + plugin_event(event_error, (void *)983, 0, 0, 0); + hide_login_progress(gc, _("The client version you are using is too old. Please upgrade at " WEBSITE)); + plugin_event(event_error, (void *)989, 0, 0, 0); + hide_login_progress(gc, _("Authentication Failed")); + debug_printf("Login Error Code 0x%04x\n", info->errorcode); + debug_printf("Error URL: %s\n", info->errorurl); + debug_printf("Reg status: %d\n", info->regstatus); + debug_printf("Email: %s\n", info->email); + debug_printf("Email is NULL\n"); + debug_printf("BOSIP: %s\n", info->bosip); + debug_printf("Closing auth connection...\n"); + aim_conn_kill(sess, &fr->conn); + bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, NULL); + hide_login_progress(gc, _("Internal Error")); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_bos, 0); + aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, gaim_bosrights, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, gaim_handle_redirect, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_RIGHTSINFO, gaim_parse_locaterights, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_RIGHTSINFO, gaim_parse_buddyrights, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, gaim_parse_oncoming, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, gaim_parse_offgoing, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, gaim_parse_incoming_im, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, gaim_parse_locerr, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, gaim_parse_misses, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_CLIENTAUTORESP, gaim_parse_clientauto, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, gaim_parse_ratechange, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_EVIL, gaim_parse_evilnotify, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOK, AIM_CB_LOK_ERROR, gaim_parse_searcherror, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOK, 0x0003, gaim_parse_searchreply, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, gaim_parse_msgerr, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, gaim_parse_user_info, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, gaim_parse_msgack, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); + aim_conn_addhandler(sess, bosconn, 0x0004, 0x0005, gaim_icbm_param_info, 0); + aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, gaim_parse_genericerr, 0); + aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, gaim_parse_genericerr, 0); + aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, gaim_parse_genericerr, 0); + aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, gaim_memrequest, 0); + aim_conn_addhandler(sess, bosconn, 0x0001, 0x000f, gaim_selfinfo, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG, gaim_offlinemsg, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE, gaim_offlinemsgdone, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_POP, 0x0002, gaim_popup, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_SIMPLEINFO, gaim_simpleinfo, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_RIGHTSINFO, gaim_ssi_parserights, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_LIST, gaim_ssi_parselist, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_NOLIST, gaim_ssi_parselist, 0); + ((struct oscar_data *)gc->proto_data)->conn = bosconn; + for (i = 0; i < (int)strlen(info->bosip); i++) { + if (info->bosip[i] == ':') { + port = atoi(&(info->bosip[i+1])); + host = g_strndup(info->bosip, i); + bosconn->status |= AIM_CONN_STATUS_INPROGRESS; + bosconn->fd = proxy_connect(host, port, oscar_bos_connect, gc); + hide_login_progress(gc, _("Could Not Connect")); + aim_sendcookie(sess, bosconn, info->cookie); + gaim_input_remove(gc->inpa); + struct gaim_connection *gc; +static void damn_you(gpointer data, gint source, GaimInputCondition c) + struct pieceofcrap *pos = data; + struct oscar_data *od = pos->gc->proto_data; + while (read(pos->fd, &in, 1) == 1) { + do_error_dialog("Gaim was unable to get a valid hash for logging into AIM." + " You may be disconnected shortly.", "Login Error"); + gaim_input_remove(pos->inpa); + debug_printf("Sending hash: "); + for (x = 0; x < 16; x++) + debug_printf("%02x ", (unsigned char)m[x]); + gaim_input_remove(pos->inpa); + aim_sendmemblock(od->sess, pos->conn, 0, 16, m, AIM_SENDMEMBLOCK_FLAG_ISHASH); +static void straight_to_hell(gpointer data, gint source, GaimInputCondition cond) { + struct pieceofcrap *pos = data; + do_error_dialog("Gaim was unable to get a valid hash for logging into AIM." + " You may be disconnected shortly.", "Login Error"); + g_snprintf(buf, sizeof(buf), "GET " AIMHASHDATA + "?offset=%ld&len=%ld&modname=%s HTTP/1.0\n\n", + pos->offset, pos->len, pos->modname ? pos->modname : ""); + write(pos->fd, buf, strlen(buf)); + pos->inpa = gaim_input_add(pos->fd, GAIM_INPUT_READ, damn_you, pos); +/* size of icbmui.ocm, the largest module in AIM 3.5 */ +#define AIM_MAX_FILE_SIZE 98304 +int gaim_memrequest(aim_session_t *sess, aim_frame_t *fr, ...) { + struct pieceofcrap *pos; + offset = (fu32_t)va_arg(ap, unsigned long); + len = (fu32_t)va_arg(ap, unsigned long); + modname = va_arg(ap, char *); + debug_printf("offset: %d, len: %d, file: %s\n", offset, len, modname ? modname : "aim.exe"); + debug_printf("len is 0, hashing NULL\n"); + aim_sendmemblock(sess, fr->conn, offset, len, NULL, + AIM_SENDMEMBLOCK_FLAG_ISREQUEST); + /* uncomment this when you're convinced it's right. remember, it's been wrong before. + if (offset > AIM_MAX_FILE_SIZE || len > AIM_MAX_FILE_SIZE) { + memcpy(buf, modname, strlen(modname)); + buf[i++] = offset & 0xff; + buf[i++] = (offset >> 8) & 0xff; + buf[i++] = (offset >> 16) & 0xff; + buf[i++] = (offset >> 24) & 0xff; + buf[i++] = (len >> 8) & 0xff; + buf[i++] = (len >> 16) & 0xff; + buf[i++] = (len >> 24) & 0xff; + debug_printf("len + offset is invalid, hashing request\n"); + aim_sendmemblock(sess, command->conn, offset, i, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST); + pos = g_new0(struct pieceofcrap, 1); + pos->gc = sess->aux_data; + pos->modname = modname ? g_strdup(modname) : NULL; + fd = proxy_connect("gaim.sourceforge.net", 80, straight_to_hell, pos); + do_error_dialog("Gaim was unable to get a valid hash for logging into AIM." + " You may be disconnected shortly.", "Login Error"); +static int gaim_parse_login(aim_session_t *sess, aim_frame_t *fr, ...) { + struct client_info_s info = {"gaim", 4, 1, 2010, "us", "en", 0x0004, 0x0000, 0x04b}; + struct client_info_s info = AIM_CLIENTINFO_KNOWNGOOD; + struct gaim_connection *gc = sess->aux_data; + key = va_arg(ap, char *); + aim_send_login(sess, fr->conn, gc->username, gc->password, &info, key); +static int conninitdone_chat(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + struct chat_connection *chatcon; + aim_conn_addhandler(sess, fr->conn, 0x000e, 0x0001, gaim_parse_genericerr, 0); + aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, gaim_chat_join, 0); + aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, gaim_chat_leave, 0); + aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, gaim_chat_info_update, 0); + aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, gaim_chat_incoming_msg, 0); + aim_clientready(sess, fr->conn); + chatcon = find_oscar_chat_by_conn(gc, fr->conn); + chatcon->cnv = serv_got_joined_chat(gc, id++, chatcon->show); +static int conninitdone_chatnav(aim_session_t *sess, aim_frame_t *fr, ...) { + aim_conn_addhandler(sess, fr->conn, 0x000d, 0x0001, gaim_parse_genericerr, 0); + aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CTN, AIM_CB_CTN_INFO, gaim_chatnav_info, 0); + aim_clientready(sess, fr->conn); + aim_chatnav_reqrights(sess, fr->conn); +static void oscar_chatnav_connect(gpointer data, gint source, GaimInputCondition cond) { + struct gaim_connection *gc = data; + struct oscar_data *odata; + if (!g_slist_find(connections, gc)) { + odata = gc->proto_data; + tstconn = aim_getconn_type_all(sess, AIM_CONN_TYPE_CHATNAV); + aim_conn_kill(sess, &tstconn); + debug_printf("unable to connect to chatnav server\n"); + aim_conn_completeconnect(sess, tstconn); + odata->cnpa = gaim_input_add(tstconn->fd, GAIM_INPUT_READ, + oscar_callback, tstconn); + debug_printf("chatnav: connected\n"); +static void oscar_auth_connect(gpointer data, gint source, GaimInputCondition cond) + struct gaim_connection *gc = data; + struct oscar_data *odata; + if (!g_slist_find(connections, gc)) { + odata = gc->proto_data; + tstconn = aim_getconn_type_all(sess, AIM_CONN_TYPE_AUTH); + aim_conn_kill(sess, &tstconn); + debug_printf("unable to connect to authorizer\n"); + aim_conn_completeconnect(sess, tstconn); + odata->paspa = gaim_input_add(tstconn->fd, GAIM_INPUT_READ, + oscar_callback, tstconn); + debug_printf("chatnav: connected\n"); +static void oscar_chat_connect(gpointer data, gint source, GaimInputCondition cond) + struct chat_connection *ccon = data; + struct gaim_connection *gc = ccon->gc; + struct oscar_data *odata; + if (!g_slist_find(connections, gc)) { + odata = gc->proto_data; + aim_conn_kill(sess, &tstconn); + aim_conn_completeconnect(sess, ccon->conn); + ccon->inpa = gaim_input_add(tstconn->fd, + oscar_callback, tstconn); + odata->oscar_chats = g_slist_append(odata->oscar_chats, ccon); +/* Hrmph. I don't know how to make this look better. --mid */ +static int gaim_handle_redirect(aim_session_t *sess, aim_frame_t *fr, ...) { + struct aim_redirect_data *redir; + struct gaim_connection *gc = sess->aux_data; + struct aim_user *user = gc->user; + port = user->proto_opt[USEROPT_AUTHPORT][0] ? + atoi(user->proto_opt[USEROPT_AUTHPORT]) : FAIM_LOGIN_PORT, + redir = va_arg(ap, struct aim_redirect_data *); + for (i = 0; i < (int)strlen(redir->ip); i++) { + if (redir->ip[i] == ':') { + port = atoi(&(redir->ip[i+1])); + host = g_strndup(redir->ip, i); + case 0x7: /* Authorizer */ + debug_printf("Reconnecting with authorizor...\n"); + tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL); + debug_printf("unable to reconnect with authorizer\n"); + aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_admin, 0); + aim_conn_addhandler(sess, tstconn, 0x0007, 0x0003, gaim_info_change, 0); + aim_conn_addhandler(sess, tstconn, 0x0007, 0x0005, gaim_info_change, 0); + aim_conn_addhandler(sess, tstconn, 0x0007, 0x0007, gaim_account_confirm, 0); + tstconn->status |= AIM_CONN_STATUS_INPROGRESS; + tstconn->fd = proxy_connect(host, port, oscar_auth_connect, gc); + aim_conn_kill(sess, &tstconn); + debug_printf("unable to reconnect with authorizer\n"); + aim_sendcookie(sess, tstconn, redir->cookie); + case 0xd: /* ChatNav */ + tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, NULL); + debug_printf("unable to connect to chatnav server\n"); + aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_chatnav, 0); + tstconn->status |= AIM_CONN_STATUS_INPROGRESS; + tstconn->fd = proxy_connect(host, port, oscar_chatnav_connect, gc); + aim_conn_kill(sess, &tstconn); + debug_printf("unable to connect to chatnav server\n"); + aim_sendcookie(sess, tstconn, redir->cookie); + struct chat_connection *ccon; + tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, NULL); + debug_printf("unable to connect to chat server\n"); + aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_chat, 0); + ccon = g_new0(struct chat_connection, 1); + ccon->name = g_strdup(redir->chat.room); + ccon->exchange = redir->chat.exchange; + ccon->instance = redir->chat.instance; + ccon->show = extract_name(redir->chat.room); + ccon->conn->status |= AIM_CONN_STATUS_INPROGRESS; + ccon->conn->fd = proxy_connect(host, port, oscar_chat_connect, ccon); + if (ccon->conn->fd < 0) { + aim_conn_kill(sess, &tstconn); + debug_printf("unable to connect to chat server\n"); + aim_sendcookie(sess, tstconn, redir->cookie); + debug_printf("Connected to chat room %s exchange %d\n", ccon->name, ccon->exchange); + debug_printf("got redirect for unknown service 0x%04x\n", redir->group); +static int gaim_parse_oncoming(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *od = gc->proto_data; + time_t time_idle = 0, signon = 0; + info = va_arg(ap, aim_userinfo_t *); + if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES) + caps = info->capabilities; + if (info->flags & AIM_FLAG_ACTIVEBUDDY) + if ((!od->icq) && (info->present & AIM_USERINFO_PRESENT_FLAGS)) { + if (info->flags & AIM_FLAG_UNCONFIRMED) + type |= UC_UNCONFIRMED; + if (info->flags & AIM_FLAG_ADMINISTRATOR) + if (info->flags & AIM_FLAG_AOL) + if (info->flags & AIM_FLAG_FREE) + if (info->flags & AIM_FLAG_AWAY) + type |= UC_UNAVAILABLE; + if (info->flags & AIM_FLAG_WIRELESS) + if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS) { + type = (info->icqinfo.status << 7); + if (!(info->icqinfo.status & AIM_ICQ_STATE_CHAT) && + (info->icqinfo.status != AIM_ICQ_STATE_NORMAL)) { + type |= UC_UNAVAILABLE; + if (caps & AIM_CAPS_ICQ) + if (info->present & AIM_USERINFO_PRESENT_IDLE) { + time_idle -= info->idletime*60; + if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN) + signon = time(NULL) - info->sessionlen; + tmp = g_strdup(normalize(gc->username)); + if (!strcmp(tmp, normalize(info->sn))) + g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", info->sn); + serv_got_update(gc, info->sn, 1, info->warnlevel/10, signon, + time_idle, type, caps); +static int gaim_parse_offgoing(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + info = va_arg(ap, aim_userinfo_t *); + serv_got_update(gc, info->sn, 0, 0, 0, 0, 0, 0); +static void cancel_direct_im(gpointer w, struct ask_direct *d) { + debug_printf("Freeing DirectIM prompts.\n"); +static void oscar_directim_callback(gpointer data, gint source, GaimInputCondition condition) { + struct direct_im *dim = data; + struct gaim_connection *gc = dim->gc; + struct oscar_data *od = gc->proto_data; + struct conversation *cnv; + socklen_t name_len = 1; + if (!g_slist_find(connections, gc)) { + if (dim->conn->fd != source) + dim->conn->fd = source; + aim_conn_completeconnect(od->sess, dim->conn); + if (!(cnv = find_conversation(dim->name))) + cnv = new_conversation(dim->name); + /* This is the best way to see if we're connected or not */ + if (getpeername(source, &name, &name_len) == 0) { + g_snprintf(buf, sizeof buf, _("Direct IM with %s established"), dim->name); + write_to_conv(cnv, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); + od->direct_ims = g_slist_append(od->direct_ims, dim); + dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, + oscar_callback, dim->conn); +static int accept_direct_im(gpointer w, struct ask_direct *d) { + struct gaim_connection *gc = d->gc; + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + char *host; int port = 4443; + debug_printf("Accepted DirectIM.\n"); + dim = find_direct_im(od, d->sn); + cancel_direct_im(w, d); /* 40 */ + dim = g_new0(struct direct_im, 1); + g_snprintf(dim->name, sizeof dim->name, "%s", d->sn); + dim->conn = aim_directim_connect(od->sess, d->sn, NULL, d->cookie); + cancel_direct_im(w, d); + aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, + gaim_directim_incoming, 0); + aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, + gaim_directim_typing, 0); + aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_IMAGETRANSFER, + for (i = 0; i < (int)strlen(d->ip); i++) { + port = atoi(&(d->ip[i+1])); + host = g_strndup(d->ip, i); + dim->conn->status |= AIM_CONN_STATUS_INPROGRESS; + dim->conn->fd = proxy_connect(host, port, oscar_directim_callback, dim); + if (dim->conn->fd < 0) { + aim_conn_kill(od->sess, &dim->conn); + cancel_direct_im(w, d); + cancel_direct_im(w, d); +static int incomingim_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch1_args *args) { + char *tmp = g_malloc(BUF_LONG); + struct gaim_connection *gc = sess->aux_data; + if (args->icbmflags & AIM_IMFLAGS_AWAY) + if (args->icbmflags & AIM_IMFLAGS_HASICON) { + struct oscar_data *od = gc->proto_data; + struct icon_req *ir = NULL; + GSList *h = od->hasicons; + char *who = normalize(userinfo->sn); + if (!args->iconlen || !args->iconsum || !args->iconstamp) + debug_printf("%s has an icon\n", userinfo->sn); + if (!strcmp(ir->user, who)) + ir = g_new0(struct icon_req, 1); + ir->user = g_strdup(who); + od->hasicons = g_slist_append(od->hasicons, ir); + if ((args->iconlen != ir->length) || + (args->iconsum != ir->checksum) || + (args->iconstamp != ir->timestamp)) + ir->length = args->iconlen; + ir->checksum = args->iconsum; + ir->timestamp = args->iconstamp; + if (gc->user->iconfile[0] && (args->icbmflags & AIM_IMFLAGS_BUDDYREQ)) { + if (!stat(gc->user->iconfile, &st)) { + char *buf = g_malloc(st.st_size); + file = fopen(gc->user->iconfile, "r"); + int len = fread(buf, 1, st.st_size, file); + debug_printf("Sending buddy icon to %s (%d bytes, %d reported)\n", + userinfo->sn, len, st.st_size); + aim_send_icon(sess, userinfo->sn, buf, st.st_size, + st.st_mtime, aim_iconsum(buf, st.st_size)); + debug_printf("Can't open buddy icon file!\n"); + debug_printf("Can't stat buddy icon file!\n"); + * Quickly convert it to eight bit format, replacing + * non-ASCII UNICODE characters with their equivelent + if (args->icbmflags & AIM_IMFLAGS_UNICODE) { + for (i = 0, tmp[0] = '\0'; i < args->msglen; i += 2) { + uni = ((args->msg[i] & 0xff) << 8) | (args->msg[i+1] & 0xff); + if ((uni < 128) || ((uni >= 160) && (uni <= 255))) { /* ISO 8859-1 */ + g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "%c", uni); + } else { /* something else, do UNICODE entity */ + g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "&#%04x;", uni); + g_snprintf(tmp, BUF_LONG, "%s", args->msg); + serv_got_im(gc, userinfo->sn, tmp, flags, time(NULL), -1); +static int incomingim_chan2(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args) { + struct gaim_connection *gc = sess->aux_data; + debug_printf("rendezvous status %d (%s)\n", args->status, userinfo->sn); + if (args->status != AIM_RENDEZVOUS_PROPOSE) + if (args->reqclass & AIM_CAPS_CHAT) { + if (!args->info.chat.roominfo.name || !args->info.chat.roominfo.exchange || !args->msg) + name = extract_name(args->info.chat.roominfo.name); + m = g_list_append(m, g_strdup(name ? name : args->info.chat.roominfo.name)); + *exch = args->info.chat.roominfo.exchange; + m = g_list_append(m, exch); + serv_got_chat_invite(gc, + name ? name : args->info.chat.roominfo.name, + } else if (args->reqclass & AIM_CAPS_SENDFILE) { + } else if (args->reqclass & AIM_CAPS_GETFILE) { + } else if (args->reqclass & AIM_CAPS_VOICE) { + } else if (args->reqclass & AIM_CAPS_BUDDYICON) { + set_icon_data(gc, normalize(userinfo->sn), args->info.icon.icon, + args->info.icon.length); + } else if (args->reqclass & AIM_CAPS_IMIMAGE) { + struct ask_direct *d = g_new0(struct ask_direct, 1); + debug_printf("%s received direct im request from %s (%s)\n", + gc->username, userinfo->sn, args->verifiedip); + d->sn = g_strdup(userinfo->sn); + strncpy(d->ip, args->verifiedip, sizeof(d->ip)); + memcpy(d->cookie, args->cookie, 8); + g_snprintf(buf, sizeof buf, "%s has just asked to directly connect to %s.", + userinfo->sn, gc->username); + do_ask_dialog(buf, d, accept_direct_im, cancel_direct_im); + debug_printf("Unknown reqclass %d\n", args->reqclass); +static void gaim_icq_authgrant(gpointer w, struct icq_auth *data) { + struct oscar_data *od = (struct oscar_data *)data->gc->proto_data; + uin = g_strdup_printf("%lu", data->uin); + aim_send_im_ch4(od->sess, uin, AIM_ICQMSG_AUTHGRANTED, &message); + show_got_added(data->gc, NULL, uin, NULL, NULL); +static void gaim_icq_authdeny(gpointer w, struct icq_auth *data) { + struct oscar_data *od = (struct oscar_data *)data->gc->proto_data; + uin = g_strdup_printf("%lu", data->uin); + message = g_strdup_printf("No reason given."); + aim_send_im_ch4(od->sess, uin, AIM_ICQMSG_AUTHDENIED, message); + * For when other people ask you for authorization +static void gaim_icq_authask(struct gaim_connection *gc, fu32_t uin, char *msg) { + struct icq_auth *data = g_new(struct icq_auth, 1); + /* The first 6 chars of the message are some type of alien gibberish, so skip them */ + char *dialog_msg = g_strdup_printf("The user %lu wants to add you to their buddy list for the following reason:\n\n%s", uin, (msg && strlen(msg)>6) ? msg+6 : "No reason given."); + debug_printf("Received an authorization request from UIN %lu\n", uin); + do_ask_dialog(dialog_msg, data, gaim_icq_authgrant, gaim_icq_authdeny); +static int incomingim_chan4(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch4_args *args) { + struct gaim_connection *gc = sess->aux_data; + if (!args->type || !args->msg || !args->uin) + case 0x0001: { /* An almost-normal instant message. Mac ICQ sends this. It's peculiar. */ + uin = g_strdup_printf("%lu", args->uin); + message = g_strdup(args->msg); + strip_linefeed(message); + serv_got_im(gc, uin, message, 0, time(NULL), -1); + case 0x0006: { /* Someone requested authorization */ + gaim_icq_authask(gc, args->uin, args->msg); + case 0x0007: { /* Someone has denied you authorization */ + dialog_msg = g_strdup_printf(_("The user %lu has denied your request to add them to your contact list for the following reason:\n%s"), args->uin, args->msg ? args->msg : _("No reason given.")); + do_error_dialog(dialog_msg, _("Gaim - ICQ Authorization Denied")); + case 0x0008: { /* Someone has granted you authorization */ + dialog_msg = g_strdup_printf(_("The user %lu has granted your request to add them to your contact list."), args->uin); + do_error_dialog(dialog_msg, _("Gaim - ICQ Authorization Granted")); + /* Ack for authorizing/denying someone. Or possibly an ack for sending any system notice */ + debug_printf("Received a channel 4 message of unknown type (type 0x%04d).\n", args->type); +static int gaim_parse_incoming_im(aim_session_t *sess, aim_frame_t *fr, ...) { + aim_userinfo_t *userinfo; + channel = va_arg(ap, int); + userinfo = va_arg(ap, aim_userinfo_t *); + case 1: { /* standard message */ + struct aim_incomingim_ch1_args *args; + args = va_arg(ap, struct aim_incomingim_ch1_args *); + ret = incomingim_chan1(sess, fr->conn, userinfo, args); + case 2: { /* rendevous */ + struct aim_incomingim_ch2_args *args; + args = va_arg(ap, struct aim_incomingim_ch2_args *); + ret = incomingim_chan2(sess, fr->conn, userinfo, args); + struct aim_incomingim_ch4_args *args; + args = va_arg(ap, struct aim_incomingim_ch4_args *); + ret = incomingim_chan4(sess, fr->conn, userinfo, args); + debug_printf("ICBM received on unsupported channel (channel 0x%04d).", channel); +static int gaim_parse_misses(aim_session_t *sess, aim_frame_t *fr, ...) { + fu16_t chan, nummissed, reason; + aim_userinfo_t *userinfo; + chan = (fu16_t)va_arg(ap, unsigned int); + userinfo = va_arg(ap, aim_userinfo_t *); + nummissed = (fu16_t)va_arg(ap, unsigned int); + reason = (fu16_t)va_arg(ap, unsigned int); + _("You missed %d message from %s because it was invalid.") : + _("You missed %d messages from %s because they were invalid."), + /* Message too large */ + _("You missed %d message from %s because it was too large.") : + _("You missed %d messages from %s because they were too large."), + _("You missed %d message from %s because the rate limit has been exceeded.") : + _("You missed %d messages from %s because the rate limit has been exceeded."), + _("You missed %d message from %s because it was too evil.") : + _("You missed %d messages from %s because they are too evil."), + _("You missed %d message from %s because you are too evil.") : + _("You missed %d messages from %s because you are too evil."), + _("You missed %d message from %s for unknown reasons.") : + _("You missed %d messages from %s for unknown reasons."), + do_error_dialog(buf, _("Gaim - Error")); +static char *gaim_icq_status(int state) { + /* Make a cute little string that shows the status of the dude or dudet */ + if (state & AIM_ICQ_STATE_CHAT) + return g_strdup_printf("Free For Chat"); + else if (state & AIM_ICQ_STATE_DND) + return g_strdup_printf("Do Not Disturb"); + else if (state & AIM_ICQ_STATE_OUT) + return g_strdup_printf("Not Available"); + else if (state & AIM_ICQ_STATE_BUSY) + return g_strdup_printf("Occupied"); + else if (state & AIM_ICQ_STATE_AWAY) + return g_strdup_printf("Away"); + else if (state & AIM_ICQ_STATE_WEBAWARE) + return g_strdup_printf("Web Aware"); + else if (state & AIM_ICQ_STATE_INVISIBLE) + return g_strdup_printf("Invisible"); + return g_strdup_printf("Online"); +static int gaim_parse_clientauto(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + chan = (fu16_t)va_arg(ap, unsigned int); + who = va_arg(ap, char *); + reason = (fu16_t)va_arg(ap, unsigned int); + case 0x0003: { /* Reply from an ICQ status message request */ + int state = (int)va_arg(ap, fu32_t); + char *msg = va_arg(ap, char *); + char *status_msg = gaim_icq_status(state); + char *dialog_msg, **splitmsg; + struct oscar_data *od = gc->proto_data; + GSList *l = od->evilhack; + gboolean evilhack = FALSE; + /* Split at (carriage return/newline)'s, then rejoin later with BRs between. */ + splitmsg = g_strsplit(msg, "\r\n", 0); + /* If who is in od->evilhack, then we're just getting the away message, otherwise this + * will just get appended to the info box (which is already showing). */ + if (!strcmp(x, normalize(who))) { + od->evilhack = g_slist_remove(od->evilhack, x); + dialog_msg = g_strdup_printf(_("<B>UIN:</B> %s<BR><B>Status:</B> %s<BR><HR><BR>%s<BR>"), who, status_msg, g_strjoinv("<BR>", splitmsg)); + dialog_msg = g_strdup_printf(_("<B>Status:</B> %s<BR><HR><BR>%s<BR>"), status_msg, g_strjoinv("<BR>", splitmsg)); + g_show_info_text(gc, who, 2, dialog_msg, NULL); + debug_printf("Received an unknown client auto-response from %s. Type 0x%04x\n", who, reason); +static int gaim_parse_genericerr(aim_session_t *sess, aim_frame_t *fr, ...) { + reason = (fu16_t)va_arg(ap, unsigned int); + debug_printf("snac threw error (reason 0x%04x: %s)\n", reason, + (reason < msgerrreasonlen) ? msgerrreason[reason] : "unknown"); + m = g_strdup_printf(_("SNAC threw error: %s\n"), + reason < msgerrreasonlen ? msgerrreason[reason] : "Unknown error"); + do_error_dialog(m, _("Gaim - Oscar SNAC Error")); +static int gaim_parse_msgerr(aim_session_t *sess, aim_frame_t *fr, ...) { + reason = (fu16_t)va_arg(ap, unsigned int); + destn = va_arg(ap, char *); + sprintf(buf, _("Your message to %s did not get sent: %s"), destn, + (reason < msgerrreasonlen) ? msgerrreason[reason] : _("Reason unknown")); + do_error_dialog(buf, _("Gaim - Error")); +static int gaim_parse_locerr(aim_session_t *sess, aim_frame_t *fr, ...) { + reason = (fu16_t)va_arg(ap, unsigned int); + destn = va_arg(ap, char *); + sprintf(buf, _("User information for %s unavailable: %s"), destn, + (reason < msgerrreasonlen) ? msgerrreason[reason] : _("Reason unknown")); + do_error_dialog(buf, _("Gaim - Error")); +static char *images(int flags) { + g_snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s", + (flags & AIM_FLAG_ACTIVEBUDDY) ? "<IMG SRC=\"ab_icon.gif\">" : "", + (flags & AIM_FLAG_UNCONFIRMED) ? "<IMG SRC=\"dt_icon.gif\">" : "", + (flags & AIM_FLAG_AOL) ? "<IMG SRC=\"aol_icon.gif\">" : "", + (flags & AIM_FLAG_ICQ) ? "<IMG SRC=\"icq_icon.gif\">" : "", + (flags & AIM_FLAG_ADMINISTRATOR) ? "<IMG SRC=\"admin_icon.gif\">" : "", + (flags & AIM_FLAG_FREE) ? "<IMG SRC=\"free_icon.gif\">" : "", + (flags & AIM_FLAG_WIRELESS) ? "<IMG SRC=\"wireless_icon.gif\">" : ""); +/* XXX This is horribly copied from ../../buddy.c. */ +static char *caps_string(guint caps) + static char buf[512], *tmp; + while (bit <= 0x10000) { + tmp = _("Send Buddy List"); + tmp = _("EveryBuddy Bug"); + tmp = _("ICQ Server Relay"); + tmp = _("ICQ Unknown"); + tmp = _("Trillian Encryption"); + i += g_snprintf(buf + i, sizeof(buf) - i, "%s%s", (count ? ", " : ""), +static int gaim_parse_user_info(aim_session_t *sess, aim_frame_t *fr, ...) { + char *prof_enc = NULL, *prof = NULL; + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *od = gc->proto_data; + GSList *l = od->evilhack; + gboolean evilhack = FALSE; + gchar *membersince = NULL, *onlinesince = NULL, *idle = NULL; + info = va_arg(ap, aim_userinfo_t *); + infotype = (fu16_t)va_arg(ap, unsigned int); + prof_enc = va_arg(ap, char *); + prof = va_arg(ap, char *); + g_snprintf(legend, sizeof legend, + _("<br><BODY BGCOLOR=WHITE><hr><I>Legend:</I><br><br>" + "<IMG SRC=\"free_icon.gif\"> : Normal AIM User<br>" + "<IMG SRC=\"aol_icon.gif\"> : AOL User <br>" + "<IMG SRC=\"dt_icon.gif\"> : Trial AIM User <br>" + "<IMG SRC=\"admin_icon.gif\"> : Administrator <br>" + "<IMG SRC=\"ab_icon.gif\"> : ActiveBuddy Interactive Agent<br>" + "<IMG SRC=\"wireless_icon.gif\"> : Wireless Device User<br>")); + if (info->present & AIM_USERINFO_PRESENT_ONLINESINCE) { + onlinesince = g_strdup_printf("Online Since : <B>%s</B><BR>\n", + asctime(localtime(&info->onlinesince))); + if (info->present & AIM_USERINFO_PRESENT_MEMBERSINCE) { + membersince = g_strdup_printf("Member Since : <B>%s</B><BR>\n", + asctime(localtime(&info->membersince))); + if (info->present & AIM_USERINFO_PRESENT_IDLE) { + idle = g_strdup_printf("Idle : <B>%d minutes</B>", + idle = g_strdup("Idle: <B>Active</B>"); + g_snprintf(header, sizeof header, + _("Username : <B>%s</B> %s <BR>\n" + "Warning Level : <B>%d %%</B><BR>\n" + info->sn, images(info->flags), + onlinesince ? onlinesince : "", + membersince ? membersince : "", + if (!strcmp(x, normalize(info->sn))) { + od->evilhack = g_slist_remove(od->evilhack, x); + if (infotype == AIM_GETINFO_AWAYMESSAGE) { + g_show_info_text(gc, info->sn, 2, + (prof && *prof) ? away_subs(prof, gc->username) : + _("<i>User has no away message</i>"), + g_show_info_text(gc, info->sn, 0, + (prof && *prof) ? away_subs(prof, gc->username) : NULL, + (prof && *prof) ? "<BR><HR><BR>" : NULL, + } else if (infotype == AIM_GETINFO_CAPABILITIES) { + g_show_info_text(gc, info->sn, 2, + "<i>", _("Client Capabilities: "), + caps_string(info->capabilities), + g_show_info_text(gc, info->sn, 1, + (prof && *prof) ? away_subs(prof, gc->username) : + _("<i>No Information Provided</i>"), +static int gaim_parse_motd(aim_session_t *sess, aim_frame_t *fr, ...) { + id = (fu16_t)va_arg(ap, unsigned int); + msg = va_arg(ap, char *); + aim_getbuildstring(buildbuf, sizeof(buildbuf)); + debug_printf("MOTD: %s (%d)\n", msg ? msg : "Unknown", id); + do_error_dialog(_("Your connection may be lost."), +static int gaim_chatnav_info(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + type = (fu16_t)va_arg(ap, unsigned int); + struct aim_chat_exchangeinfo *exchanges; + maxrooms = (fu8_t)va_arg(ap, unsigned int); + exchangecount = va_arg(ap, int); + exchanges = va_arg(ap, struct aim_chat_exchangeinfo *); + debug_printf("chat info: Chat Rights:\n"); + debug_printf("chat info: \tMax Concurrent Rooms: %d\n", maxrooms); + debug_printf("chat info: \tExchange List: (%d total)\n", exchangecount); + for (i = 0; i < exchangecount; i++) + debug_printf("chat info: \t\t%d %s\n", exchanges[i].number, exchanges[i].name ? exchanges[i].name : ""); + while (odata->create_rooms) { + struct create_room *cr = odata->create_rooms->data; + debug_printf("creating room %s\n", cr->name); + aim_chatnav_createroom(sess, fr->conn, cr->name, cr->exchange); + odata->create_rooms = g_slist_remove(odata->create_rooms, cr); + char *fqcn, *name, *ck; + fu16_t instance, flags, maxmsglen, maxoccupancy, unknown, exchange; + fqcn = va_arg(ap, char *); + instance = (fu16_t)va_arg(ap, unsigned int); + exchange = (fu16_t)va_arg(ap, unsigned int); + flags = (fu16_t)va_arg(ap, unsigned int); + createtime = va_arg(ap, fu32_t); + maxmsglen = (fu16_t)va_arg(ap, unsigned int); + maxoccupancy = (fu16_t)va_arg(ap, unsigned int); + createperms = (fu8_t)va_arg(ap, int); + unknown = (fu16_t)va_arg(ap, unsigned int); + name = va_arg(ap, char *); + ck = va_arg(ap, char *); + debug_printf("created room: %s %d %d %d %lu %d %d %d %d %s %s\n", + exchange, instance, flags, + maxmsglen, maxoccupancy, createperms, unknown, + aim_chat_join(odata->sess, odata->conn, exchange, ck, instance); + debug_printf("chatnav info: unknown type (%04x)\n", type); +static int gaim_chat_join(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *g = sess->aux_data; + struct chat_connection *c = NULL; + count = va_arg(ap, int); + info = va_arg(ap, aim_userinfo_t *); + c = find_oscar_chat_by_conn(g, fr->conn); + for (i = 0; i < count; i++) + add_chat_buddy(c->cnv, info[i].sn); +static int gaim_chat_leave(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *g = sess->aux_data; + struct chat_connection *c = NULL; + count = va_arg(ap, int); + info = va_arg(ap, aim_userinfo_t *); + c = find_oscar_chat_by_conn(g, fr->conn); + for (i = 0; i < count; i++) + remove_chat_buddy(c->cnv, info[i].sn, NULL); +static int gaim_chat_info_update(aim_session_t *sess, aim_frame_t *fr, ...) { + aim_userinfo_t *userinfo; + struct aim_chat_roominfo *roominfo; + fu16_t unknown_c9, unknown_d2, unknown_d5, maxmsglen, maxvisiblemsglen; + struct gaim_connection *gc = sess->aux_data; + struct chat_connection *ccon = find_oscar_chat_by_conn(gc, fr->conn); + roominfo = va_arg(ap, struct aim_chat_roominfo *); + roomname = va_arg(ap, char *); + usercount= va_arg(ap, int); + userinfo = va_arg(ap, aim_userinfo_t *); + roomdesc = va_arg(ap, char *); + unknown_c9 = (fu16_t)va_arg(ap, int); + creationtime = (fu32_t)va_arg(ap, unsigned long); + maxmsglen = (fu16_t)va_arg(ap, int); + unknown_d2 = (fu16_t)va_arg(ap, int); + unknown_d5 = (fu16_t)va_arg(ap, int); + maxvisiblemsglen = (fu16_t)va_arg(ap, int); + debug_printf("inside chat_info_update (maxmsglen = %d, maxvislen = %d)\n", + maxmsglen, maxvisiblemsglen); + ccon->maxlen = maxmsglen; + ccon->maxvis = maxvisiblemsglen; +static int gaim_chat_incoming_msg(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + struct chat_connection *ccon = find_oscar_chat_by_conn(gc, fr->conn); + info = va_arg(ap, aim_userinfo_t *); + msg = va_arg(ap, char *); + tmp = g_malloc(BUF_LONG); + g_snprintf(tmp, BUF_LONG, "%s", msg); + serv_got_chat_in(gc, ccon->id, info->sn, 0, tmp, time((time_t)NULL)); + * Recieved in response to an IM sent with the AIM_IMFLAGS_ACK option. +static int gaim_parse_msgack(aim_session_t *sess, aim_frame_t *fr, ...) { + type = (fu16_t)va_arg(ap, unsigned int); + sn = va_arg(ap, char *); + debug_printf("Sent message to %s.\n", sn); +static int gaim_parse_ratechange(aim_session_t *sess, aim_frame_t *fr, ...) { + static const char *codes[5] = { + fu16_t code, rateclass; + fu32_t windowsize, clear, alert, limit, disconnect, currentavg, maxavg; + code = (fu16_t)va_arg(ap, unsigned int); + rateclass= (fu16_t)va_arg(ap, unsigned int); + windowsize = (fu32_t)va_arg(ap, unsigned long); + clear = (fu32_t)va_arg(ap, unsigned long); + alert = (fu32_t)va_arg(ap, unsigned long); + limit = (fu32_t)va_arg(ap, unsigned long); + disconnect = (fu32_t)va_arg(ap, unsigned long); + currentavg = (fu32_t)va_arg(ap, unsigned long); + maxavg = (fu32_t)va_arg(ap, unsigned long); + debug_printf("rate %s (paramid 0x%04lx): curavg = %ld, maxavg = %ld, alert at %ld, " + "clear warning at %ld, limit at %ld, disconnect at %ld (window size = %ld)\n", + (code < 5) ? codes[code] : codes[0], + /* XXX fix these values */ + if (code == AIM_RATE_CODE_CHANGE) { + if (currentavg >= clear) + aim_conn_setlatency(fr->conn, 0); + } else if (code == AIM_RATE_CODE_WARNING) { + aim_conn_setlatency(fr->conn, windowsize/4); + } else if (code == AIM_RATE_CODE_LIMIT) { + do_error_dialog(_("The last message was not sent because you are over the rate limit. " + "Please wait 10 seconds and try again."), _("Gaim - Error")); + aim_conn_setlatency(fr->conn, windowsize/2); + } else if (code == AIM_RATE_CODE_CLEARLIMIT) { + aim_conn_setlatency(fr->conn, 0); +static int gaim_parse_evilnotify(aim_session_t *sess, aim_frame_t *fr, ...) { + aim_userinfo_t *userinfo; + struct gaim_connection *gc = sess->aux_data; + newevil = (fu16_t)va_arg(ap, unsigned int); + userinfo = va_arg(ap, aim_userinfo_t *); + serv_got_eviled(gc, (userinfo && userinfo->sn[0]) ? userinfo->sn : NULL, newevil / 10); +static int gaim_selfinfo(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + info = va_arg(ap, aim_userinfo_t *); + gc->evil = info->warnlevel/10; + /* gc->correction_time = (info->onlinesince - gc->login_time); */ +static int conninitdone_bos(aim_session_t *sess, aim_frame_t *fr, ...) { + aim_reqpersonalinfo(sess, fr->conn); + aim_bos_reqlocaterights(sess, fr->conn); + aim_bos_reqbuddyrights(sess, fr->conn); + aim_reqicbmparams(sess); + aim_bos_reqrights(sess, fr->conn); + aim_bos_setgroupperm(sess, fr->conn, AIM_FLAG_ALLUSERS); + aim_bos_setprivacyflags(sess, fr->conn, AIM_PRIVFLAGS_ALLOWIDLE | + AIM_PRIVFLAGS_ALLOWMEMBERSINCE); +static int conninitdone_admin(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *od = gc->proto_data; + aim_clientready(sess, fr->conn); + debug_printf("connected to admin\n"); + debug_printf("changing password\n"); + aim_admin_changepasswd(sess, fr->conn, od->newp, od->oldp); + debug_printf("formatting screenname\n"); + aim_admin_setnick(sess, fr->conn, od->newsn); + debug_printf("confirming account\n"); + aim_admin_reqconfirm(sess, fr->conn); + debug_printf("requesting email\n"); + aim_admin_getinfo(sess, fr->conn, 0x0011); + debug_printf("setting email\n"); + aim_admin_setemail(sess, fr->conn, od->email); +static int gaim_icbm_param_info(aim_session_t *sess, aim_frame_t *fr, ...) { + struct aim_icbmparameters *params; + params = va_arg(ap, struct aim_icbmparameters *); + /* evidently this crashes on solaris. i have no clue why + debug_printf("ICBM Parameters: maxchannel = %d, default flags = 0x%08lx, max msg len = %d, " + "max sender evil = %f, max receiver evil = %f, min msg interval = %ld\n", + params->maxchan, params->flags, params->maxmsglen, + ((float)params->maxsenderwarn)/10.0, ((float)params->maxrecverwarn)/10.0, + params->minmsginterval); + /* Maybe senderwarn and recverwarn should be user preferences... */ + params->maxmsglen = 8000; + params->minmsginterval = 0; + aim_seticbmparam(sess, params); +static int gaim_parse_locaterights(aim_session_t *sess, aim_frame_t *fr, ...) + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + maxsiglen = va_arg(ap, int); + debug_printf("locate rights: max sig len = %d\n", maxsiglen); + odata->rights.maxsiglen = odata->rights.maxawaymsglen = (guint)maxsiglen; + aim_bos_setprofile(sess, fr->conn, gc->user->user_info, NULL, gaim_caps); +static int gaim_parse_buddyrights(aim_session_t *sess, aim_frame_t *fr, ...) { + fu16_t maxbuddies, maxwatchers; + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + maxbuddies = (fu16_t)va_arg(ap, unsigned int); + maxwatchers = (fu16_t)va_arg(ap, unsigned int); + debug_printf("buddy list rights: Max buddies = %d / Max watchers = %d\n", maxbuddies, maxwatchers); + odata->rights.maxbuddies = (guint)maxbuddies; + odata->rights.maxwatchers = (guint)maxwatchers; +static int gaim_bosrights(aim_session_t *sess, aim_frame_t *fr, ...) { + fu16_t maxpermits, maxdenies; + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + maxpermits = (fu16_t)va_arg(ap, unsigned int); + maxdenies = (fu16_t)va_arg(ap, unsigned int); + debug_printf("BOS rights: Max permit = %d / Max deny = %d\n", maxpermits, maxdenies); + odata->rights.maxpermits = (guint)maxpermits; + odata->rights.maxdenies = (guint)maxdenies; + if (bud_list_cache_exists(gc)) + debug_printf("buddy list loaded\n"); + aim_clientready(sess, fr->conn); + aim_icq_reqofflinemsgs(sess); + aim_reqservice(sess, fr->conn, AIM_CONN_TYPE_CHATNAV); + debug_printf("ssi: requesting ssi list\n"); + aim_ssi_reqrights(sess, fr->conn); + aim_ssi_reqdata(sess, fr->conn, sess->ssi.timestamp, sess->ssi.revision); +static int gaim_offlinemsg(aim_session_t *sess, aim_frame_t *fr, ...) { + struct aim_icq_offlinemsg *msg; + struct gaim_connection *gc = sess->aux_data; + msg = va_arg(ap, struct aim_icq_offlinemsg *); + debug_printf("Received offline message of type 0x%04x\n", msg->type); + case 0x0001: { /* Basic offline message */ + char *dialog_msg = g_strdup(msg->msg); + time_t t = get_time(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0); + g_snprintf(sender, sizeof(sender), "%lu", msg->sender); + strip_linefeed(dialog_msg); + serv_got_im(gc, sender, dialog_msg, 0, t, -1); + case 0x0006: { /* Authorization request */ + gaim_icq_authask(gc, msg->sender, msg->msg); + case 0x0007: { /* Someone has denied you authorization */ + dialog_msg = g_strdup_printf(_("The user %lu has denied your request to add them to your contact list for the following reason:\n%s"), msg->sender, msg->msg ? msg->msg : _("No reason given.")); + do_error_dialog(dialog_msg, _("Gaim - ICQ Authorization Denied")); + case 0x0008: { /* Someone has granted you authorization */ + dialog_msg = g_strdup_printf(_("The user %lu has granted your request to add them to your contact list."), msg->sender); + do_error_dialog(dialog_msg, _("Gaim - ICQ Authorization Granted")); + /* Ack for authorizing/denying someone. Or possibly an ack for sending any system notice */ + debug_printf("unknown offline message type 0x%04x\n", msg->type); +static int gaim_offlinemsgdone(aim_session_t *sess, aim_frame_t *fr, ...) + aim_icq_ackofflinemsgs(sess); +static int gaim_simpleinfo(aim_session_t *sess, aim_frame_t *fr, ...) + struct gaim_connection *gc = sess->aux_data; + struct buddy *budlight; + struct aim_icq_simpleinfo *info; + info = va_arg(ap, struct aim_icq_simpleinfo *); + g_snprintf(who, sizeof who, "%lu", info->uin); + g_snprintf(buf, sizeof buf, + "<B>Name:</B> %s %s<BR>" + "<B>Email:</B> %s<BR>\n", + info->first, info->last, + /* If the contact is away, then we also want to get their status message + * and show it in the same window as info. g_show_info_text gets the status + * message if the third arg is 0 (this seems really gross to me). The + * parse-icq-status-message function knows if it is putting it's message in + * an info window because the name will _not_ be in od->evilhack. For getting + * only the away message the contact's UIN is put in od->evilhack. */ + if ((budlight = find_buddy(gc, who))) { + if ((budlight->uc >> 7) & (AIM_ICQ_STATE_AWAY || AIM_ICQ_STATE_DND || AIM_ICQ_STATE_OUT || AIM_ICQ_STATE_BUSY || AIM_ICQ_STATE_CHAT)) { + if (budlight->caps & AIM_CAPS_ICQSERVERRELAY) + g_show_info_text(gc, who, 0, buf, NULL); + char *state_msg = gaim_icq_status((budlight->uc & 0xff80) >> 7); + g_show_info_text(gc, who, 2, buf, "<B>Status:</B> ", state_msg, "<BR>\n<HR><BR><I>Remote client does not support sending status messages.</I><BR>\n", NULL); + char *state_msg = gaim_icq_status((budlight->uc & 0xff80) >> 7); + g_show_info_text(gc, who, 2, buf, "<B>Status:</B> ", state_msg, NULL); + g_show_info_text(gc, who, 2, buf, NULL); +static int gaim_popup(aim_session_t *sess, aim_frame_t *fr, ...) + fu16_t wid, hei, delay; + msg = va_arg(ap, char *); + url = va_arg(ap, char *); + wid = (fu16_t)va_arg(ap, int); + hei = (fu16_t)va_arg(ap, int); + delay = (fu16_t)va_arg(ap, int); + serv_got_popup(msg, url, wid, hei); +static int gaim_parse_searchreply(aim_session_t *sess, aim_frame_t *fr, ...) { + address = va_arg(ap, char *); + SNs = va_arg(ap, char *); + len = num * (MAXSNLEN + 1) + 1024; + at += g_snprintf(buf + at, len - at, "<B>%s has the following screen names:</B><BR>", address); + for (i = 0; i < num; i++) + at += g_snprintf(buf + at, len - at, "%s<BR>", &SNs[i * (MAXSNLEN + 1)]); + g_show_info_text(NULL, NULL, 2, buf, NULL); +static int gaim_parse_searcherror(aim_session_t *sess, aim_frame_t *fr, ...) { + address = va_arg(ap, char *); + g_snprintf(buf, sizeof(buf), "No results found for email address %s", address); + do_error_dialog(buf, _("Error")); +static int gaim_account_confirm(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + status = (fu16_t)va_arg(ap, unsigned int); /* status code of confirmation request */ + debug_printf("account confirmation returned status 0x%04x (%s)\n", status, + status ? "email sent" : "unknown"); + g_snprintf(msg, sizeof(msg), "You should receive an email asking to confirm %s.", + do_error_dialog(msg, "Confirm"); +static int gaim_info_change(aim_session_t *sess, aim_frame_t *fr, ...) { + fu16_t perms, type, length; + struct gaim_connection *gc = sess->aux_data; + change = va_arg(ap, int); + perms = (fu16_t)va_arg(ap, unsigned int); + type = (fu16_t)va_arg(ap, unsigned int); + length = (fu16_t)va_arg(ap, unsigned int); + val = va_arg(ap, char *); + debug_printf("info%s: perms = %d, type = %x, length = %d, val = %s\n", + change ? " change" : "", perms, type, length, str ? val : "(not string)"); + /* XXX Do something for other types too. */ + if ((type == 0x0011) && str && length) { + g_snprintf(buf, sizeof(buf), "The email address for %s is %s", gc->username, val); + do_error_dialog(buf, "Email"); +static void oscar_keepalive(struct gaim_connection *gc) { + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + aim_flap_nop(odata->sess, odata->conn); +static char *oscar_name() { +static int oscar_send_typing(struct gaim_connection *gc, char *name, int typing) { + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + struct direct_im *dim = find_direct_im(odata, name); + aim_send_typing(odata->sess, dim->conn, typing); +static void oscar_ask_direct_im(struct gaim_connection *gc, char *name); +static int oscar_send_im(struct gaim_connection *gc, char *name, char *message, int len, int imflags) { + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + struct direct_im *dim = find_direct_im(odata, name); + if (dim->connected) { /* If we're not connected yet, send through server */ + ret = aim_send_im_direct(odata->sess, dim->conn, message, len == -1 ? strlen(message) : len); + debug_printf("Direct IM pending, but not connected; sending through server\n"); + } else if (len != -1) { + /* Trying to send an IM image outside of a direct connection. */ + oscar_ask_direct_im(gc, name); + if (imflags & IM_FLAG_AWAY) { + ret = aim_send_im(odata->sess, name, AIM_IMFLAGS_AWAY, message); + struct aim_sendimext_args args; + GSList *h = odata->hasicons; + struct icon_req *ir = NULL; + char *who = normalize(name); + args.flags = AIM_IMFLAGS_ACK | AIM_IMFLAGS_CUSTOMFEATURES; + args.flags |= AIM_IMFLAGS_OFFLINE; + args.features = gaim_features; + args.featureslen = sizeof(gaim_features); + if (ir->request && !strcmp(who, ir->user)) + args.flags |= AIM_IMFLAGS_BUDDYREQ; + debug_printf("sending buddy icon request with message\n"); + if (gc->user->iconfile[0] && !stat(gc->user->iconfile, &st)) { + FILE *file = fopen(gc->user->iconfile, "r"); + char *buf = g_malloc(st.st_size); + fread(buf, 1, st.st_size, file); + args.iconlen = st.st_size; + args.iconsum = aim_iconsum(buf, st.st_size); + args.iconstamp = st.st_mtime; + args.flags |= AIM_IMFLAGS_HASICON; + debug_printf("Claiming to have an icon.\n"); + args.msglen = strlen(message); + ret = aim_send_im_ext(odata->sess, &args); +static void oscar_get_info(struct gaim_connection *g, char *name) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + aim_icq_getsimpleinfo(odata->sess, name); + /* people want the away message on the top, so we get the away message + * first and then get the regular info, since it's too difficult to + * insert in the middle. i hate people. */ + aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_AWAYMESSAGE); +static void oscar_get_away(struct gaim_connection *g, char *who) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + struct buddy *budlight = find_buddy(g, who); + if ((budlight->uc & 0xff80) >> 7) + if (budlight->caps & AIM_CAPS_ICQSERVERRELAY) + aim_send_im_ch2_geticqmessage(odata->sess, who, (budlight->uc & 0xff80) >> 7); + debug_printf("Error: Remote client does not support retrieval of status messages.\n"); + debug_printf("Error: The user %s has no status message, therefore not requesting.\n", who); + debug_printf("Error: Could not find %s in local contact list, therefore unable to request status message.\n", who); + aim_getinfo(odata->sess, odata->conn, who, AIM_GETINFO_GENERALINFO); +static void oscar_get_caps(struct gaim_connection *g, char *name) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_CAPABILITIES); +static void oscar_set_dir(struct gaim_connection *g, char *first, char *middle, char *last, + char *maiden, char *city, char *state, char *country, int web) { + /* FIXME : some of these things are wrong, but i'm lazy */ + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + aim_setdirectoryinfo(odata->sess, odata->conn, first, middle, last, + maiden, NULL, NULL, city, state, NULL, 0, web); +static void oscar_set_idle(struct gaim_connection *g, int time) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + aim_bos_setidle(odata->sess, odata->conn, time); +static void oscar_set_info(struct gaim_connection *g, char *info) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + if (odata->rights.maxsiglen == 0) + do_error_dialog("oscar_set_info called before locate rights received", "Protocol Error"); + if (strlen(info) > odata->rights.maxsiglen) { + errstr = g_strdup_printf("Maximum info length of %d bytes exceeded, truncating", odata->rights.maxsiglen); + do_error_dialog(errstr, "Info Too Long"); + inforeal = g_strndup(info, odata->rights.maxsiglen); + aim_bos_setprofile(odata->sess, odata->conn, inforeal, NULL, gaim_caps); +static void oscar_set_away_aim(struct gaim_connection *gc, struct oscar_data *od, const char *message) + if (od->rights.maxawaymsglen == 0) + do_error_dialog("oscar_set_away_aim called before locate rights received", "Protocol Error"); + aim_bos_setprofile(od->sess, od->conn, NULL, "", gaim_caps); + if (strlen(message) > od->rights.maxawaymsglen) { + errstr = g_strdup_printf("Maximum away message length of %d bytes exceeded, truncating", od->rights.maxawaymsglen); + do_error_dialog(errstr, "Away Message Too Long"); + gc->away = g_strndup(message, od->rights.maxawaymsglen); + aim_bos_setprofile(od->sess, od->conn, NULL, gc->away, gaim_caps); +static void oscar_set_away_icq(struct gaim_connection *gc, struct oscar_data *od, const char *state, const char *message) + if (!strcmp(state, "Online")) + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_NORMAL); + else if (!strcmp(state, "Away")) { + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_AWAY); + } else if (!strcmp(state, "Do Not Disturb")) { + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_DND | AIM_ICQ_STATE_BUSY); + } else if (!strcmp(state, "Not Available")) { + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_OUT | AIM_ICQ_STATE_AWAY); + } else if (!strcmp(state, "Occupied")) { + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_BUSY); + } else if (!strcmp(state, "Free For Chat")) { + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_CHAT); + } else if (!strcmp(state, "Invisible")) { + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_INVISIBLE); + } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_OUT | AIM_ICQ_STATE_AWAY); + aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_NORMAL); +static void oscar_set_away(struct gaim_connection *gc, char *state, char *message) + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + oscar_set_away_icq(gc, od, state, message); + oscar_set_away_aim(gc, od, message); +static void oscar_warn(struct gaim_connection *g, char *name, int anon) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + aim_send_warning(odata->sess, odata->conn, name, anon ? AIM_WARN_ANON : 0); +static void oscar_dir_search(struct gaim_connection *g, char *first, char *middle, char *last, + char *maiden, char *city, char *state, char *country, char *email) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + aim_usersearch_address(odata->sess, odata->conn, email); +static void oscar_add_buddy(struct gaim_connection *g, char *name) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + aim_add_buddy(odata->sess, odata->conn, name); + if ((odata->sess->ssi.received_data) && !(aim_ssi_itemlist_finditem(odata->sess->ssi.items, NULL, name, 0x0000))) { + debug_printf("ssi: adding buddy %s to group %s\n", name, find_group_by_buddy(g, name)->name); + aim_ssi_addbuddies(odata->sess, odata->conn, find_group_by_buddy(g, name)->name, &name, 1); +static void oscar_add_buddies(struct gaim_connection *g, GList *buddies) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + if (n > MSG_LEN - 18) { + aim_bos_setbuddylist(odata->sess, odata->conn, buf); + n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (char *)buddies->data); + buddies = buddies->next; + aim_bos_setbuddylist(odata->sess, odata->conn, buf); + if (odata->sess->ssi.received_data) { + GSList *curgrp, *curbud; + for (curgrp=g->groups; curgrp; curgrp=g_slist_next(curgrp)) { + for (curbud=((struct group*)curgrp->data)->members; curbud; curbud=curbud->next) + if (!aim_ssi_itemlist_finditem(odata->sess->ssi.items, NULL, ((struct buddy*)curbud->data)->name, 0x0000)) + char **sns = (char **)malloc(tmp*sizeof(char*)); + for (curbud=((struct group*)curgrp->data)->members; curbud; curbud=curbud->next) + if (!aim_ssi_itemlist_finditem(odata->sess->ssi.items, NULL, ((struct buddy*)curbud->data)->name, 0x0000)) { + debug_printf("ssi: adding buddy %s to group %s\n", ((struct buddy*)curbud->data)->name, ((struct group*)curgrp->data)->name); + sns[tmp] = (char *)((struct buddy*)curbud->data)->name; + aim_ssi_addbuddies(odata->sess, odata->conn, ((struct group*)curgrp->data)->name, sns, tmp); +static void oscar_move_buddy(struct gaim_connection *g, char *name, char *old_group, char *new_group) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + if (odata->sess->ssi.received_data) { + aim_ssi_movebuddy(odata->sess, odata->conn, old_group, new_group, name); + debug_printf("ssi: moved buddy %s from group %s to group %s\n", name, old_group, new_group); +static void oscar_remove_buddy(struct gaim_connection *g, char *name, char *group) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + aim_remove_buddy(odata->sess, odata->conn, name); + if (odata->sess->ssi.received_data) { + struct aim_ssi_item *ssigroup; + while (aim_ssi_itemlist_finditem(odata->sess->ssi.items, NULL, name, 0x0000) && (ssigroup = aim_ssi_itemlist_findparent(odata->sess->ssi.items, name)) && !aim_ssi_delbuddies(odata->sess, odata->conn, ssigroup->name, &name, 1)) + debug_printf("ssi: deleted buddy %s from group %s\n", name, group); +static void oscar_remove_buddies(struct gaim_connection *g, GList *buddies, char *group) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + for (cur=buddies; cur; cur=cur->next) + aim_remove_buddy(odata->sess, odata->conn, cur->data); + if (odata->sess->ssi.received_data) { + for (cur=buddies; cur; cur=cur->next) + if (aim_ssi_itemlist_finditem(odata->sess->ssi.items, NULL, cur->data, 0x0000)) + sns = (char **)malloc(tmp*sizeof(char*)); + for (cur=buddies; cur; cur=cur->next) + if (aim_ssi_itemlist_finditem(odata->sess->ssi.items, NULL, cur->data, 0x0000)) { + debug_printf("ssi: deleting buddy %s from group %s\n", cur->data, group); + aim_ssi_delbuddies(odata->sess, odata->conn, group, sns, tmp); +static int gaim_ssi_parserights(aim_session_t *sess, aim_frame_t *fr, ...) { +/* XXX - Fix parsing of the ssi rights packet and pass us the data + fu16_t maxbuddies, maxgroups, maxpermits, maxdenies; + maxbuddies = (fu16_t)va_arg(ap, unsigned int); + maxgroupss = (fu16_t)va_arg(ap, unsigned int); + maxpermits = (fu16_t)va_arg(ap, unsigned int); + maxdenies = (fu16_t)va_arg(ap, unsigned int); + debug_printf("ssi rights: Max buddies = %d / Max groups = %d / Max permits = %d / Max denies = %d\n", maxbuddies, maxgroups, maxpermits, maxdenies); +static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *odata = (struct oscar_data *)gc->proto_data; + struct aim_ssi_item *curitem; + debug_printf("ssi: syncing local list and server list\n"); + debug_printf("ssi: activating server-stored buddy list\n"); + aim_ssi_enable(sess, fr->conn); + /* Clean the buddy list */ + aim_ssi_cleanlist(sess, fr->conn); + /* Add from server list to local list */ + for (curitem=sess->ssi.items; curitem; curitem=curitem->next) { + switch (curitem->type) { + case 0x0000: /* Buddy */ + if ((curitem->name) && (!find_buddy(gc, curitem->name))) { + struct aim_ssi_item *curgroup = sess->ssi.items; + if ((curgroup->type == 0x0001) && (curgroup->gid == curitem->gid) && (curgroup->name)) { + debug_printf("ssi: adding buddy %s to group %s to local list\n", curitem->name, curgroup->name); + add_buddy(gc, curgroup->name, curitem->name, 0); + curgroup = curgroup->next; + case 0x0002: /* Permit buddy */ + for (list=gc->permit; (list && aim_sncmp(curitem->name, list->data)); list=list->next); + debug_printf("ssi: adding permit buddy %s to local list\n", curitem->name); + name = g_strdup(normalize(curitem->name)); + gc->permit = g_slist_append(gc->permit, name); + case 0x0003: /* Deny buddy */ + for (list=gc->deny; (list && aim_sncmp(curitem->name, list->data)); list=list->next); + debug_printf("ssi: adding deny buddy %s to local list\n", curitem->name); + name = g_strdup(normalize(curitem->name)); + gc->deny = g_slist_append(gc->deny, name); + case 0x0004: /* Permit/deny setting */ + if ((permdeny = aim_ssi_getpermdeny(sess->ssi.items)) && (permdeny != gc->permdeny)) { + debug_printf("ssi: changing permdeny from %d to %d\n", gc->permdeny, permdeny); + gc->permdeny = permdeny; + case 0x0005: /* Presence setting */ + /* We don't want to change Gaim's setting because it applies to all accounts */ + } /* End of switch on curitem->type */ + } /* End of for loop */ + /* Add from local list to server list */ + for (curbud=((struct group*)cur->data)->members; curbud; curbud=curbud->next) + if (!aim_ssi_itemlist_finditem(sess->ssi.items, NULL, ((struct buddy*)curbud->data)->name, 0x0000)) + sns = (char **)malloc(tmp*sizeof(char*)); + for (curbud=((struct group*)cur->data)->members; curbud; curbud=curbud->next) + if (!aim_ssi_itemlist_finditem(sess->ssi.items, NULL, ((struct buddy*)curbud->data)->name, 0x0000)) { + debug_printf("ssi: adding buddy %s from local list to server list\n", ((struct buddy*)curbud->data)->name); + sns[tmp] = ((char *)((struct buddy*)curbud->data)->name); + aim_ssi_addbuddies(sess, fr->conn, ((struct group*)cur->data)->name, sns, tmp); + cur = g_slist_next(cur); + for (cur=gc->permit; cur; cur=cur->next) + if (!aim_ssi_itemlist_finditem(sess->ssi.items, NULL, cur->data, 0x0002)) + sns = (char **)malloc(tmp*sizeof(char*)); + for (cur=gc->permit; cur; cur=cur->next) + if (!aim_ssi_itemlist_finditem(sess->ssi.items, NULL, cur->data, 0x0002)) { + debug_printf("ssi: adding permit %s from local list to server list\n", cur->data); + aim_ssi_addpord(sess, fr->conn, sns, tmp, AIM_SSI_TYPE_PERMIT); + for (cur=gc->deny; cur; cur=cur->next) + if (!aim_ssi_itemlist_finditem(sess->ssi.items, NULL, cur->data, 0x0003)) + sns = (char **)malloc(tmp*sizeof(char*)); + for (cur=gc->deny; cur; cur=cur->next) + if (!aim_ssi_itemlist_finditem(sess->ssi.items, NULL, cur->data, 0x0003)) { + debug_printf("ssi: adding deny %s from local list to server list\n", cur->data); + aim_ssi_addpord(sess, fr->conn, sns, tmp, AIM_SSI_TYPE_DENY); + /* Presence settings (idle time visibility) */ + if ((tmp = aim_ssi_getpresence(sess->ssi.items)) != 0xFFFFFFFF) + if (report_idle && !(tmp & 0x400)) + aim_ssi_setpresence(sess, fr->conn, tmp | 0x400); + /* Check for maximum number of buddies */ + for (cur=gc->groups, tmp=0; cur; cur=g_slist_next(cur)) { + struct group* gr = (struct group*)cur->data; + tmp = tmp + g_slist_length(gr->members); + if (tmp > odata->rights.maxbuddies) { + char *dialog_msg = g_strdup_printf(_("The maximum number of buddies allowed in your buddy list is %d, and you have %d." + " Until you are below the limit, some buddies will not show up as online."), + odata->rights.maxbuddies, tmp); + do_error_dialog(dialog_msg, _("Gaim - Warning")); +static GList *oscar_chat_info(struct gaim_connection *gc) { + struct proto_chat_entry *pce; + pce = g_new0(struct proto_chat_entry, 1); + pce->label = _("Join what group:"); + m = g_list_append(m, pce); + pce = g_new0(struct proto_chat_entry, 1); + pce->label = _("Exchange:"); + m = g_list_append(m, pce); +static void oscar_join_chat(struct gaim_connection *g, GList *data) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + if (!data || !data->next) + exchange = data->next->data; + debug_printf("Attempting to join chat room %s.\n", name); + if ((cur = aim_getconn_type(odata->sess, AIM_CONN_TYPE_CHATNAV))) { + debug_printf("chatnav exists, creating room\n"); + aim_chatnav_createroom(odata->sess, cur, name, *exchange); + struct create_room *cr = g_new0(struct create_room, 1); + debug_printf("chatnav does not exist, opening chatnav\n"); + cr->exchange = *exchange; + cr->name = g_strdup(name); + odata->create_rooms = g_slist_append(odata->create_rooms, cr); + aim_reqservice(odata->sess, odata->conn, AIM_CONN_TYPE_CHATNAV); +static void oscar_chat_invite(struct gaim_connection *g, int id, char *message, char *name) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + struct chat_connection *ccon = find_oscar_chat(g, id); + aim_chat_invite(odata->sess, odata->conn, name, message ? message : "", + ccon->exchange, ccon->name, 0x0); +static void oscar_chat_leave(struct gaim_connection *g, int id) { + struct oscar_data *odata = g ? (struct oscar_data *)g->proto_data : NULL; + GSList *bcs = g->buddy_chats; + struct conversation *b = NULL; + struct chat_connection *c = NULL; + b = (struct conversation *)bcs->data; + debug_printf("Attempting to leave room %s (currently in %d rooms)\n", b->name, count); + c = find_oscar_chat(g, b->id); + odata->oscar_chats = g_slist_remove(odata->oscar_chats, c); + gaim_input_remove(c->inpa); + aim_conn_kill(odata->sess, &c->conn); + /* we do this because with Oscar it doesn't tell us we left */ + serv_got_chat_left(g, b->id); +static int oscar_chat_send(struct gaim_connection *g, int id, char *message) { + struct oscar_data *odata = (struct oscar_data *)g->proto_data; + GSList *bcs = g->buddy_chats; + struct conversation *b = NULL; + struct chat_connection *c = NULL; + b = (struct conversation *)bcs->data; + bcs = odata->oscar_chats; + c = (struct chat_connection *)bcs->data; + buf = g_malloc(strlen(message) * 4 + 1); + for (i = 0, j = 0; i < strlen(message); i++) { + if (message[i] == '\n') { + if (strlen(buf) > c->maxlen) + buf2 = strip_html(buf); + if (strlen(buf2) > c->maxvis) { + aim_chat_send_im(odata->sess, c->conn, 0, buf, strlen(buf)); +static char **oscar_list_icon(int uc) { + return (char **)icon_online_xpm; + if (uc & AIM_ICQ_STATE_INVISIBLE) + return icon_offline_xpm; + if (uc & AIM_ICQ_STATE_CHAT) + if (uc & AIM_ICQ_STATE_DND) + if (uc & AIM_ICQ_STATE_OUT) + if (uc & AIM_ICQ_STATE_BUSY) + if (uc & AIM_ICQ_STATE_AWAY) + return icon_online_xpm; + if (uc & UC_UNAVAILABLE) + return (char **)away_icon_xpm; + return (char **)wireless_icon_xpm; + return (char **)ab_xpm; + return (char **)aol_icon_xpm; + return (char **)admin_icon_xpm; + if (uc & UC_UNCONFIRMED) + return (char **)dt_icon_xpm; + return (char **)free_icon_xpm; +static int gaim_directim_initiate(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + aim_conn_t *newconn, *listenerconn; + struct conversation *cnv; + newconn = va_arg(ap, aim_conn_t *); + listenerconn = va_arg(ap, aim_conn_t *); + aim_conn_close(listenerconn); + aim_conn_kill(sess, &listenerconn); + sn = g_strdup(aim_directim_getsn(newconn)); + debug_printf("DirectIM: initiate success to %s\n", sn); + dim = find_direct_im(od, sn); + if (!(cnv = find_conversation(sn))) + cnv = new_conversation(sn); + gaim_input_remove(dim->watcher); + dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, + oscar_callback, dim->conn); + g_snprintf(buf, sizeof buf, _("Direct IM with %s established"), sn); + write_to_conv(cnv, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); + aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, + gaim_directim_incoming, 0); + aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, + gaim_directim_typing, 0); + aim_conn_addhandler(sess, newconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_IMAGETRANSFER, +static int gaim_update_ui(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + struct conversation *c; + sn = va_arg(ap, char *); + percent = va_arg(ap, double); + if (!(dim = find_direct_im(od, sn))) + gaim_input_remove(dim->watcher); /* Otherwise, the callback will callback */ + while (gtk_events_pending()) + if ((c = find_conversation(sn))) + update_progress(c, percent); + dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, + oscar_callback, dim->conn); +static int gaim_directim_incoming(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + sn = va_arg(ap, char *); + msg = va_arg(ap, char *); + debug_printf("Got DirectIM message from %s\n", sn); + serv_got_im(gc, sn, msg, 0, time(NULL), len); +static int gaim_directim_typing(aim_session_t *sess, aim_frame_t *fr, ...) { + struct gaim_connection *gc = sess->aux_data; + sn = va_arg(ap, char *); + typing = va_arg(ap, int); + /* I had to leave this. It's just too funny. It reminds me of my sister. */ + debug_printf("ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", sn); + serv_got_typing(gc,sn,0); + serv_got_typing_stopped(gc,sn); + struct gaim_connection *gc; +static void oscar_cancel_direct_im(gpointer obj, struct ask_do_dir_im *data) { +static void oscar_direct_im(gpointer obj, struct ask_do_dir_im *data) { + struct gaim_connection *gc = data->gc; + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + dim = find_direct_im(od, data->who); + if (!(dim->connected)) { /* We'll free the old, unconnected dim, and start over */ + od->direct_ims = g_slist_remove(od->direct_ims, dim); + gaim_input_remove(dim->watcher); + debug_printf("Gave up on old direct IM, trying again\n"); + do_error_dialog("DirectIM already open.", "Gaim"); + dim = g_new0(struct direct_im, 1); + g_snprintf(dim->name, sizeof dim->name, "%s", data->who); + dim->conn = aim_directim_initiate(od->sess, data->who); + if (dim->conn != NULL) { + od->direct_ims = g_slist_append(od->direct_ims, dim); + dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, + oscar_callback, dim->conn); + aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, + gaim_directim_initiate, 0); + do_error_dialog(_("Unable to open Direct IM"), _("Error")); +static void oscar_ask_direct_im(struct gaim_connection *gc, gchar *who) { + struct ask_do_dir_im *data = g_new0(struct ask_do_dir_im, 1); + g_snprintf(buf, sizeof(buf), _("You have selected to open a Direct IM connection with %s." + " Doing this will let them see your IP address, and may be" + " a security risk. Do you wish to continue?"), who); + do_ask_dialog(buf, data, oscar_direct_im, oscar_cancel_direct_im); +static void oscar_get_away_msg(struct gaim_connection *gc, char *who) { + struct oscar_data *od = gc->proto_data; + od->evilhack = g_slist_append(od->evilhack, g_strdup(normalize(who))); + struct buddy *budlight = find_buddy(gc, who); + if ((budlight->uc >> 7) & (AIM_ICQ_STATE_AWAY || AIM_ICQ_STATE_DND || AIM_ICQ_STATE_OUT || AIM_ICQ_STATE_BUSY || AIM_ICQ_STATE_CHAT)) + if (budlight->caps & AIM_CAPS_ICQSERVERRELAY) + aim_send_im_ch2_geticqmessage(od->sess, who, (budlight->uc & 0xff80) >> 7); + char *state_msg = gaim_icq_status((budlight->uc & 0xff80) >> 7); + char *dialog_msg = g_strdup_printf(_("<B>UIN:</B> %s<BR><B>Status:</B> %s<BR><HR><BR><I>Remote client does not support sending status messages.</I><BR>"), who, state_msg); + g_show_info_text(gc, who, 2, dialog_msg, NULL); + char *state_msg = gaim_icq_status((budlight->uc & 0xff80) >> 7); + char *dialog_msg = g_strdup_printf(_("<B>UIN:</B> %s<BR><B>Status:</B> %s<BR><HR><BR><I>User has no status message.</I><BR>"), who, state_msg); + g_show_info_text(gc, who, 2, dialog_msg, NULL); + do_error_dialog("Could not find contact in local list, therefore unable to request status message.\n", "Gaim - Error"); + oscar_get_info(gc, who); +static GList *oscar_buddy_menu(struct gaim_connection *gc, char *who) { + struct proto_buddy_menu *pbm; + char *n = g_strdup(normalize(gc->username)); + struct oscar_data *odata = gc->proto_data; + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Info"); + pbm->callback = oscar_get_info; + m = g_list_append(m, pbm); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Status Msg"); + pbm->callback = oscar_get_away_msg; + m = g_list_append(m, pbm); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Away Msg"); + pbm->callback = oscar_get_away_msg; + m = g_list_append(m, pbm); + if (strcmp(n, normalize(who))) { + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Direct IM"); + pbm->callback = oscar_ask_direct_im; + m = g_list_append(m, pbm); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Capabilities"); + pbm->callback = oscar_get_caps; + m = g_list_append(m, pbm); +static GList *oscar_user_opts() + struct proto_user_opt *puo; + puo = g_new0(struct proto_user_opt, 1); + puo->label = "Auth Host:"; + puo->def = "login.oscar.aol.com"; + puo->pos = USEROPT_AUTH; + m = g_list_append(m, puo); + puo = g_new0(struct proto_user_opt, 1); + puo->label = "Auth Port:"; + puo->pos = USEROPT_AUTHPORT; + m = g_list_append(m, puo); +static void oscar_set_permit_deny(struct gaim_connection *gc) { + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_DENYADD, gc->username); + aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_PERMITADD, gc->username); + at += g_snprintf(buf + at, sizeof(buf) - at, "%s&", (char *)list->data); + aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_PERMITADD, buf); + at += g_snprintf(buf + at, sizeof(buf) - at, "%s&", (char *)list->data); + aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_DENYADD, buf); + if (od->sess->ssi.received_data) + aim_ssi_setpermdeny(od->sess, od->conn, gc->permdeny, 0xffffffff); +static void oscar_add_permit(struct gaim_connection *gc, char *who) { + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + if (gc->permdeny != 3) return; + oscar_set_permit_deny(gc); + debug_printf("ssi: About to add a permit\n"); + if (od->sess->ssi.received_data) + aim_ssi_addpord(od->sess, od->conn, &who, 1, AIM_SSI_TYPE_PERMIT); +static void oscar_add_deny(struct gaim_connection *gc, char *who) { + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + if (gc->permdeny != 4) return; + oscar_set_permit_deny(gc); + debug_printf("ssi: About to add a deny\n"); + if (od->sess->ssi.received_data) + aim_ssi_addpord(od->sess, od->conn, &who, 1, AIM_SSI_TYPE_DENY); +static void oscar_rem_permit(struct gaim_connection *gc, char *who) { + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + if (gc->permdeny != 3) return; + oscar_set_permit_deny(gc); + debug_printf("ssi: About to delete a permit\n"); + if (od->sess->ssi.received_data) + aim_ssi_delpord(od->sess, od->conn, &who, 1, AIM_SSI_TYPE_PERMIT); +static void oscar_rem_deny(struct gaim_connection *gc, char *who) { + struct oscar_data *od = (struct oscar_data *)gc->proto_data; + if (gc->permdeny != 4) return; + oscar_set_permit_deny(gc); + debug_printf("ssi: About to delete a deny\n"); + if (od->sess->ssi.received_data) + aim_ssi_delpord(od->sess, od->conn, &who, 1, AIM_SSI_TYPE_DENY); +static GList *oscar_away_states(struct gaim_connection *gc) + struct oscar_data *od = gc->proto_data; + return g_list_append(m, GAIM_AWAY_CUSTOM); + m = g_list_append(m, "Online"); + m = g_list_append(m, "Away"); + m = g_list_append(m, "Do Not Disturb"); + m = g_list_append(m, "Not Available"); + m = g_list_append(m, "Occupied"); + m = g_list_append(m, "Free For Chat"); + m = g_list_append(m, "Invisible"); +static void oscar_change_email(struct gaim_connection *gc, char *email) + struct oscar_data *od = gc->proto_data; + aim_conn_t *conn = aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH); + aim_admin_setemail(od->sess, conn, email); + od->email = g_strdup(email); + aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_AUTH); +static void oscar_format_screenname(struct gaim_connection *gc, char *nick) { + struct oscar_data *od = gc->proto_data; + if (!strcmp(normalize(nick), normalize(gc->username))) { + if (!aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH)) { + od->newsn = g_strdup(nick); + aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_AUTH); + aim_admin_setnick(od->sess, aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH), nick); + do_error_dialog("The new formatting is invalid.", "Gaim"); +static void oscar_do_action(struct gaim_connection *gc, char *act) + struct oscar_data *od = gc->proto_data; + aim_conn_t *conn = aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH); + if (!strcmp(act, "Set User Info")) { + } else if (!strcmp(act, "Change Password")) { + show_change_passwd(gc); + } else if (!strcmp(act, "Format Screenname")) { + do_prompt_dialog("New screenname formatting:", + gc->displayname, gc, oscar_format_screenname, NULL); + } else if (!strcmp(act, "Confirm Account")) { + aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_AUTH); + aim_admin_reqconfirm(od->sess, conn); + } else if (!strcmp(act, "Display Current Registered Address")) { + aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_AUTH); + aim_admin_getinfo(od->sess, conn, 0x11); + } else if (!strcmp(act, "Change Current Registered Address")) { + do_prompt_dialog("Change Address To: ", NULL, gc, oscar_change_email, NULL); + } else if (!strcmp(act, "Search for Buddy by Email")) { +static GList *oscar_actions() + m = g_list_append(m, "Set User Info"); + m = g_list_append(m, NULL); + m = g_list_append(m, "Change Password"); + m = g_list_append(m, "Format Screenname"); + m = g_list_append(m, "Confirm Account"); + m = g_list_append(m, "Display Current Registered Address"); + m = g_list_append(m, "Change Current Registered Address"); + m = g_list_append(m, NULL); + m = g_list_append(m, "Search for Buddy by Email"); +static void oscar_change_passwd(struct gaim_connection *gc, char *old, char *new) + struct oscar_data *od = gc->proto_data; + if (!aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH)) { + od->oldp = g_strdup(old); + od->newp = g_strdup(new); + aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_AUTH); + aim_admin_changepasswd(od->sess, aim_getconn_type(od->sess, AIM_CONN_TYPE_AUTH), +static void oscar_convo_closed(struct gaim_connection *gc, char *who) + struct oscar_data *od = gc->proto_data; + struct direct_im *dim = find_direct_im(od, who); + od->direct_ims = g_slist_remove(od->direct_ims, dim); + gaim_input_remove(dim->watcher); + aim_conn_kill(od->sess, &dim->conn); +static struct prpl *my_protocol = NULL; +void oscar_init(struct prpl *ret) { + ret->protocol = PROTO_OSCAR; + ret->options = OPT_PROTO_BUDDY_ICON | OPT_PROTO_IM_IMAGE; + ret->name = oscar_name; + ret->list_icon = oscar_list_icon; + ret->away_states = oscar_away_states; + ret->actions = oscar_actions; + ret->do_action = oscar_do_action; + ret->buddy_menu = oscar_buddy_menu; + ret->user_opts = oscar_user_opts; + ret->login = oscar_login; + ret->close = oscar_close; + ret->send_im = oscar_send_im; + ret->send_typing = oscar_send_typing; + ret->set_info = oscar_set_info; + ret->get_info = oscar_get_info; + ret->set_away = oscar_set_away; + ret->get_away = oscar_get_away; + ret->set_dir = oscar_set_dir; + ret->get_dir = NULL; /* Oscar really doesn't have this */ + ret->dir_search = oscar_dir_search; + ret->set_idle = oscar_set_idle; + ret->change_passwd = oscar_change_passwd; + ret->add_buddy = oscar_add_buddy; + ret->add_buddies = oscar_add_buddies; + ret->group_buddy = oscar_move_buddy; + ret->remove_buddy = oscar_remove_buddy; + ret->remove_buddies = oscar_remove_buddies; + ret->add_permit = oscar_add_permit; + ret->add_deny = oscar_add_deny; + ret->rem_permit = oscar_rem_permit; + ret->rem_deny = oscar_rem_deny; + ret->set_permit_deny = oscar_set_permit_deny; + ret->warn = oscar_warn; + ret->chat_info = oscar_chat_info; + ret->join_chat = oscar_join_chat; + ret->chat_invite = oscar_chat_invite; + ret->chat_leave = oscar_chat_leave; + ret->chat_whisper = NULL; + ret->chat_send = oscar_chat_send; + ret->keepalive = oscar_keepalive; + ret->convo_closed = oscar_convo_closed; +char *gaim_plugin_init(GModule *handle) + load_protocol(oscar_init, sizeof(struct prpl)); +void gaim_plugin_remove() + struct prpl *p = find_prpl(PROTO_OSCAR); + return PRPL_DESC("Oscar");