[b7d3cc34] | 1 | /* |
---|
| 2 | * gaim |
---|
| 3 | * |
---|
[f66c701] | 4 | * Some code copyright (C) 2002-2006, Jelmer Vernooij <jelmer@samba.org> |
---|
| 5 | * and the BitlBee team. |
---|
[b7d3cc34] | 6 | * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> |
---|
| 7 | * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or modify |
---|
| 10 | * it under the terms of the GNU General Public License as published by |
---|
| 11 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | * (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include <errno.h> |
---|
| 26 | #include <ctype.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include <stdlib.h> |
---|
| 29 | #include <stdio.h> |
---|
| 30 | #include <time.h> |
---|
| 31 | #include <sys/stat.h> |
---|
| 32 | #include <glib.h> |
---|
| 33 | #include "nogaim.h" |
---|
| 34 | #include "bitlbee.h" |
---|
| 35 | #include "proxy.h" |
---|
[e4d6271] | 36 | #include "sock.h" |
---|
[b7d3cc34] | 37 | |
---|
| 38 | #include "aim.h" |
---|
| 39 | #include "icq.h" |
---|
| 40 | #include "bos.h" |
---|
| 41 | #include "ssi.h" |
---|
| 42 | #include "im.h" |
---|
| 43 | #include "info.h" |
---|
| 44 | #include "buddylist.h" |
---|
| 45 | #include "chat.h" |
---|
| 46 | #include "chatnav.h" |
---|
| 47 | |
---|
| 48 | /* constants to identify proto_opts */ |
---|
| 49 | #define USEROPT_AUTH 0 |
---|
| 50 | #define USEROPT_AUTHPORT 1 |
---|
| 51 | |
---|
| 52 | #define UC_AOL 0x02 |
---|
| 53 | #define UC_ADMIN 0x04 |
---|
| 54 | #define UC_UNCONFIRMED 0x08 |
---|
| 55 | #define UC_NORMAL 0x10 |
---|
| 56 | #define UC_AB 0x20 |
---|
| 57 | #define UC_WIRELESS 0x40 |
---|
| 58 | |
---|
| 59 | #define AIMHASHDATA "http://gaim.sourceforge.net/aim_data.php3" |
---|
| 60 | |
---|
| 61 | #define OSCAR_GROUP "Friends" |
---|
| 62 | |
---|
[424e663] | 63 | #define BUF_LEN 2048 |
---|
| 64 | #define BUF_LONG ( BUF_LEN * 2 ) |
---|
| 65 | |
---|
[b7d3cc34] | 66 | /* Don't know if support for UTF8 is really working. For now it's UTF16 here. |
---|
| 67 | static int gaim_caps = AIM_CAPS_UTF8; */ |
---|
| 68 | |
---|
[b8ef1b1] | 69 | static int gaim_caps = AIM_CAPS_INTEROP | AIM_CAPS_ICHAT | AIM_CAPS_ICQSERVERRELAY | AIM_CAPS_CHAT; |
---|
[b7d3cc34] | 70 | static guint8 gaim_features[] = {0x01, 0x01, 0x01, 0x02}; |
---|
| 71 | |
---|
| 72 | struct oscar_data { |
---|
| 73 | aim_session_t *sess; |
---|
| 74 | aim_conn_t *conn; |
---|
| 75 | |
---|
| 76 | guint cnpa; |
---|
| 77 | guint paspa; |
---|
| 78 | |
---|
| 79 | GSList *create_rooms; |
---|
| 80 | |
---|
| 81 | gboolean conf; |
---|
| 82 | gboolean reqemail; |
---|
| 83 | gboolean setemail; |
---|
| 84 | char *email; |
---|
| 85 | gboolean setnick; |
---|
| 86 | char *newsn; |
---|
| 87 | gboolean chpass; |
---|
| 88 | char *oldp; |
---|
| 89 | char *newp; |
---|
| 90 | |
---|
| 91 | GSList *oscar_chats; |
---|
| 92 | |
---|
[5469952] | 93 | gboolean killme, no_reconnect; |
---|
[b7d3cc34] | 94 | gboolean icq; |
---|
| 95 | GSList *evilhack; |
---|
[e64de00] | 96 | |
---|
| 97 | GHashTable *ips; |
---|
[b7d3cc34] | 98 | |
---|
| 99 | struct { |
---|
| 100 | guint maxbuddies; /* max users you can watch */ |
---|
| 101 | guint maxwatchers; /* max users who can watch you */ |
---|
| 102 | guint maxpermits; /* max users on permit list */ |
---|
| 103 | guint maxdenies; /* max users on deny list */ |
---|
| 104 | guint maxsiglen; /* max size (bytes) of profile */ |
---|
| 105 | guint maxawaymsglen; /* max size (bytes) of posted away message */ |
---|
| 106 | } rights; |
---|
| 107 | }; |
---|
| 108 | |
---|
| 109 | struct create_room { |
---|
| 110 | char *name; |
---|
| 111 | int exchange; |
---|
| 112 | }; |
---|
| 113 | |
---|
| 114 | struct chat_connection { |
---|
| 115 | char *name; |
---|
| 116 | char *show; /* AOL did something funny to us */ |
---|
| 117 | guint16 exchange; |
---|
| 118 | guint16 instance; |
---|
| 119 | int fd; /* this is redundant since we have the conn below */ |
---|
| 120 | aim_conn_t *conn; |
---|
| 121 | int inpa; |
---|
| 122 | int id; |
---|
[0da65d5] | 123 | struct im_connection *ic; /* i hate this. */ |
---|
| 124 | struct groupchat *cnv; /* bah. */ |
---|
[b7d3cc34] | 125 | int maxlen; |
---|
| 126 | int maxvis; |
---|
| 127 | }; |
---|
| 128 | |
---|
| 129 | struct ask_direct { |
---|
[0da65d5] | 130 | struct im_connection *ic; |
---|
[b7d3cc34] | 131 | char *sn; |
---|
| 132 | char ip[64]; |
---|
| 133 | guint8 cookie[8]; |
---|
| 134 | }; |
---|
| 135 | |
---|
| 136 | struct icq_auth { |
---|
[0da65d5] | 137 | struct im_connection *ic; |
---|
[b7d3cc34] | 138 | guint32 uin; |
---|
| 139 | }; |
---|
| 140 | |
---|
| 141 | static char *extract_name(const char *name) { |
---|
| 142 | char *tmp; |
---|
| 143 | int i, j; |
---|
| 144 | char *x = strchr(name, '-'); |
---|
[936ded6] | 145 | if (!x) return g_strdup(name); |
---|
[b7d3cc34] | 146 | x = strchr(++x, '-'); |
---|
[936ded6] | 147 | if (!x) return g_strdup(name); |
---|
[b7d3cc34] | 148 | tmp = g_strdup(++x); |
---|
| 149 | |
---|
| 150 | for (i = 0, j = 0; x[i]; i++) { |
---|
| 151 | char hex[3]; |
---|
| 152 | if (x[i] != '%') { |
---|
| 153 | tmp[j++] = x[i]; |
---|
| 154 | continue; |
---|
| 155 | } |
---|
| 156 | strncpy(hex, x + ++i, 2); hex[2] = 0; |
---|
| 157 | i++; |
---|
| 158 | tmp[j++] = (char)strtol(hex, NULL, 16); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | tmp[j] = 0; |
---|
| 162 | return tmp; |
---|
| 163 | } |
---|
| 164 | |
---|
[0da65d5] | 165 | static struct chat_connection *find_oscar_chat_by_conn(struct im_connection *ic, |
---|
[b7d3cc34] | 166 | aim_conn_t *conn) { |
---|
[0da65d5] | 167 | GSList *g = ((struct oscar_data *)ic->proto_data)->oscar_chats; |
---|
[b7d3cc34] | 168 | struct chat_connection *c = NULL; |
---|
| 169 | |
---|
| 170 | while (g) { |
---|
| 171 | c = (struct chat_connection *)g->data; |
---|
| 172 | if (c->conn == conn) |
---|
| 173 | break; |
---|
| 174 | g = g->next; |
---|
| 175 | c = NULL; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | return c; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | static int gaim_parse_auth_resp (aim_session_t *, aim_frame_t *, ...); |
---|
| 182 | static int gaim_parse_login (aim_session_t *, aim_frame_t *, ...); |
---|
[5469952] | 183 | static int gaim_parse_logout (aim_session_t *, aim_frame_t *, ...); |
---|
[b7d3cc34] | 184 | static int gaim_handle_redirect (aim_session_t *, aim_frame_t *, ...); |
---|
| 185 | static int gaim_parse_oncoming (aim_session_t *, aim_frame_t *, ...); |
---|
| 186 | static int gaim_parse_offgoing (aim_session_t *, aim_frame_t *, ...); |
---|
| 187 | static int gaim_parse_incoming_im(aim_session_t *, aim_frame_t *, ...); |
---|
| 188 | static int gaim_parse_misses (aim_session_t *, aim_frame_t *, ...); |
---|
| 189 | static int gaim_parse_motd (aim_session_t *, aim_frame_t *, ...); |
---|
| 190 | static int gaim_chatnav_info (aim_session_t *, aim_frame_t *, ...); |
---|
| 191 | static int gaim_chat_join (aim_session_t *, aim_frame_t *, ...); |
---|
| 192 | static int gaim_chat_leave (aim_session_t *, aim_frame_t *, ...); |
---|
| 193 | static int gaim_chat_info_update (aim_session_t *, aim_frame_t *, ...); |
---|
| 194 | static int gaim_chat_incoming_msg(aim_session_t *, aim_frame_t *, ...); |
---|
| 195 | static int gaim_parse_ratechange (aim_session_t *, aim_frame_t *, ...); |
---|
| 196 | static int gaim_bosrights (aim_session_t *, aim_frame_t *, ...); |
---|
| 197 | static int conninitdone_bos (aim_session_t *, aim_frame_t *, ...); |
---|
| 198 | static int conninitdone_admin (aim_session_t *, aim_frame_t *, ...); |
---|
| 199 | static int conninitdone_chat (aim_session_t *, aim_frame_t *, ...); |
---|
| 200 | static int conninitdone_chatnav (aim_session_t *, aim_frame_t *, ...); |
---|
| 201 | static int gaim_parse_msgerr (aim_session_t *, aim_frame_t *, ...); |
---|
| 202 | static int gaim_parse_locaterights(aim_session_t *, aim_frame_t *, ...); |
---|
| 203 | static int gaim_parse_buddyrights(aim_session_t *, aim_frame_t *, ...); |
---|
| 204 | static int gaim_parse_locerr (aim_session_t *, aim_frame_t *, ...); |
---|
| 205 | static int gaim_icbm_param_info (aim_session_t *, aim_frame_t *, ...); |
---|
| 206 | static int gaim_parse_genericerr (aim_session_t *, aim_frame_t *, ...); |
---|
| 207 | static int gaim_selfinfo (aim_session_t *, aim_frame_t *, ...); |
---|
| 208 | static int gaim_offlinemsg (aim_session_t *, aim_frame_t *, ...); |
---|
| 209 | static int gaim_offlinemsgdone (aim_session_t *, aim_frame_t *, ...); |
---|
| 210 | static int gaim_ssi_parserights (aim_session_t *, aim_frame_t *, ...); |
---|
| 211 | static int gaim_ssi_parselist (aim_session_t *, aim_frame_t *, ...); |
---|
| 212 | static int gaim_ssi_parseack (aim_session_t *, aim_frame_t *, ...); |
---|
[3e1de87] | 213 | static int gaim_parsemtn (aim_session_t *, aim_frame_t *, ...); |
---|
[b7d3cc34] | 214 | static int gaim_icqinfo (aim_session_t *, aim_frame_t *, ...); |
---|
| 215 | static int gaim_parseaiminfo (aim_session_t *, aim_frame_t *, ...); |
---|
| 216 | |
---|
| 217 | static char *msgerrreason[] = { |
---|
| 218 | "Invalid error", |
---|
| 219 | "Invalid SNAC", |
---|
| 220 | "Rate to host", |
---|
| 221 | "Rate to client", |
---|
| 222 | "Not logged in", |
---|
| 223 | "Service unavailable", |
---|
| 224 | "Service not defined", |
---|
| 225 | "Obsolete SNAC", |
---|
| 226 | "Not supported by host", |
---|
| 227 | "Not supported by client", |
---|
| 228 | "Refused by client", |
---|
| 229 | "Reply too big", |
---|
| 230 | "Responses lost", |
---|
| 231 | "Request denied", |
---|
| 232 | "Busted SNAC payload", |
---|
| 233 | "Insufficient rights", |
---|
| 234 | "In local permit/deny", |
---|
| 235 | "Too evil (sender)", |
---|
| 236 | "Too evil (receiver)", |
---|
| 237 | "User temporarily unavailable", |
---|
| 238 | "No match", |
---|
| 239 | "List overflow", |
---|
| 240 | "Request ambiguous", |
---|
| 241 | "Queue full", |
---|
| 242 | "Not while on AOL" |
---|
| 243 | }; |
---|
| 244 | static int msgerrreasonlen = 25; |
---|
| 245 | |
---|
[424e663] | 246 | /* Hurray, this function is NOT thread-safe \o/ */ |
---|
| 247 | static char *normalize(const char *s) |
---|
| 248 | { |
---|
| 249 | static char buf[BUF_LEN]; |
---|
| 250 | char *t, *u; |
---|
| 251 | int x = 0; |
---|
| 252 | |
---|
| 253 | g_return_val_if_fail((s != NULL), NULL); |
---|
| 254 | |
---|
| 255 | u = t = g_strdup(s); |
---|
| 256 | g_strdown(t); |
---|
| 257 | |
---|
| 258 | while (*t && (x < BUF_LEN - 1)) { |
---|
| 259 | if (*t != ' ' && *t != '!') { |
---|
| 260 | buf[x] = *t; |
---|
| 261 | x++; |
---|
| 262 | } |
---|
| 263 | t++; |
---|
| 264 | } |
---|
| 265 | buf[x] = '\0'; |
---|
| 266 | g_free(u); |
---|
| 267 | return buf; |
---|
| 268 | } |
---|
| 269 | |
---|
[ba9edaa] | 270 | static gboolean oscar_callback(gpointer data, gint source, |
---|
| 271 | b_input_condition condition) { |
---|
[b7d3cc34] | 272 | aim_conn_t *conn = (aim_conn_t *)data; |
---|
| 273 | aim_session_t *sess = aim_conn_getsess(conn); |
---|
[0da65d5] | 274 | struct im_connection *ic = sess ? sess->aux_data : NULL; |
---|
[b7d3cc34] | 275 | struct oscar_data *odata; |
---|
| 276 | |
---|
[0da65d5] | 277 | if (!ic) { |
---|
| 278 | /* ic is null. we return, else we seg SIGSEG on next line. */ |
---|
[ba9edaa] | 279 | return FALSE; |
---|
[b7d3cc34] | 280 | } |
---|
| 281 | |
---|
[0da65d5] | 282 | if (!g_slist_find(get_connections(), ic)) { |
---|
[b7d3cc34] | 283 | /* oh boy. this is probably bad. i guess the only thing we |
---|
| 284 | * can really do is return? */ |
---|
[ba9edaa] | 285 | return FALSE; |
---|
[b7d3cc34] | 286 | } |
---|
| 287 | |
---|
[0da65d5] | 288 | odata = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 289 | |
---|
[e046390] | 290 | if (condition & B_EV_IO_READ) { |
---|
[66c57924] | 291 | if (aim_get_command(odata->sess, conn) >= 0) { |
---|
| 292 | aim_rxdispatch(odata->sess); |
---|
| 293 | if (odata->killme) |
---|
[5469952] | 294 | imc_logout(ic, !odata->no_reconnect); |
---|
[b7d3cc34] | 295 | } else { |
---|
[66c57924] | 296 | if ((conn->type == AIM_CONN_TYPE_BOS) || |
---|
| 297 | !(aim_getconn_type(odata->sess, AIM_CONN_TYPE_BOS))) { |
---|
[84b045d] | 298 | imcb_error(ic, _("Disconnected.")); |
---|
[c2fb3809] | 299 | imc_logout(ic, TRUE); |
---|
[66c57924] | 300 | } else if (conn->type == AIM_CONN_TYPE_CHAT) { |
---|
[0da65d5] | 301 | struct chat_connection *c = find_oscar_chat_by_conn(ic, conn); |
---|
[66c57924] | 302 | c->conn = NULL; |
---|
| 303 | if (c->inpa > 0) |
---|
[ba9edaa] | 304 | b_event_remove(c->inpa); |
---|
[66c57924] | 305 | c->inpa = 0; |
---|
| 306 | c->fd = -1; |
---|
| 307 | aim_conn_kill(odata->sess, &conn); |
---|
[84b045d] | 308 | imcb_error(sess->aux_data, _("You have been disconnected from chat room %s."), c->name); |
---|
[66c57924] | 309 | } else if (conn->type == AIM_CONN_TYPE_CHATNAV) { |
---|
| 310 | if (odata->cnpa > 0) |
---|
[ba9edaa] | 311 | b_event_remove(odata->cnpa); |
---|
[66c57924] | 312 | odata->cnpa = 0; |
---|
| 313 | while (odata->create_rooms) { |
---|
| 314 | struct create_room *cr = odata->create_rooms->data; |
---|
| 315 | g_free(cr->name); |
---|
| 316 | odata->create_rooms = |
---|
| 317 | g_slist_remove(odata->create_rooms, cr); |
---|
| 318 | g_free(cr); |
---|
[84b045d] | 319 | imcb_error(sess->aux_data, _("Chat is currently unavailable")); |
---|
[b7d3cc34] | 320 | } |
---|
[66c57924] | 321 | aim_conn_kill(odata->sess, &conn); |
---|
| 322 | } else if (conn->type == AIM_CONN_TYPE_AUTH) { |
---|
| 323 | if (odata->paspa > 0) |
---|
[ba9edaa] | 324 | b_event_remove(odata->paspa); |
---|
[66c57924] | 325 | odata->paspa = 0; |
---|
| 326 | aim_conn_kill(odata->sess, &conn); |
---|
| 327 | } else { |
---|
| 328 | aim_conn_kill(odata->sess, &conn); |
---|
[b7d3cc34] | 329 | } |
---|
| 330 | } |
---|
[ba9edaa] | 331 | } else { |
---|
| 332 | /* WTF??? */ |
---|
| 333 | return FALSE; |
---|
[b7d3cc34] | 334 | } |
---|
[ba9edaa] | 335 | |
---|
| 336 | return TRUE; |
---|
[b7d3cc34] | 337 | } |
---|
| 338 | |
---|
[ba9edaa] | 339 | static gboolean oscar_login_connect(gpointer data, gint source, b_input_condition cond) |
---|
[b7d3cc34] | 340 | { |
---|
[0da65d5] | 341 | struct im_connection *ic = data; |
---|
[b7d3cc34] | 342 | struct oscar_data *odata; |
---|
| 343 | aim_session_t *sess; |
---|
| 344 | aim_conn_t *conn; |
---|
| 345 | |
---|
[0da65d5] | 346 | if (!g_slist_find(get_connections(), ic)) { |
---|
[b7d3cc34] | 347 | closesocket(source); |
---|
[ba9edaa] | 348 | return FALSE; |
---|
[b7d3cc34] | 349 | } |
---|
| 350 | |
---|
[0da65d5] | 351 | odata = ic->proto_data; |
---|
[b7d3cc34] | 352 | sess = odata->sess; |
---|
| 353 | conn = aim_getconn_type_all(sess, AIM_CONN_TYPE_AUTH); |
---|
| 354 | |
---|
| 355 | if (source < 0) { |
---|
[84b045d] | 356 | imcb_error(ic, _("Couldn't connect to host")); |
---|
[c2fb3809] | 357 | imc_logout(ic, TRUE); |
---|
[ba9edaa] | 358 | return FALSE; |
---|
[b7d3cc34] | 359 | } |
---|
| 360 | |
---|
| 361 | aim_conn_completeconnect(sess, conn); |
---|
[e046390] | 362 | ic->inpa = b_input_add(conn->fd, B_EV_IO_READ, |
---|
[b7d3cc34] | 363 | oscar_callback, conn); |
---|
[ba9edaa] | 364 | |
---|
| 365 | return FALSE; |
---|
[b7d3cc34] | 366 | } |
---|
| 367 | |
---|
[0da65d5] | 368 | static void oscar_init(account_t *acc) |
---|
[96863f6] | 369 | { |
---|
| 370 | set_t *s; |
---|
[6b96de6] | 371 | gboolean icq = isdigit(acc->user[0]); |
---|
[96863f6] | 372 | |
---|
[6b96de6] | 373 | if (icq) { |
---|
[545d7c0] | 374 | set_add(&acc->set, "ignore_auth_requests", "false", set_eval_bool, acc); |
---|
[3dc6d86] | 375 | set_add(&acc->set, "old_icq_auth", "false", set_eval_bool, acc); |
---|
[545d7c0] | 376 | } |
---|
| 377 | |
---|
[6b96de6] | 378 | s = set_add(&acc->set, "server", |
---|
| 379 | icq ? AIM_DEFAULT_LOGIN_SERVER_ICQ |
---|
| 380 | : AIM_DEFAULT_LOGIN_SERVER_AIM, set_eval_account, acc); |
---|
[96863f6] | 381 | s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY; |
---|
[d3a672c] | 382 | |
---|
[6b96de6] | 383 | if (icq) { |
---|
[545d7c0] | 384 | s = set_add(&acc->set, "web_aware", "false", set_eval_bool, acc); |
---|
[d3a672c] | 385 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 386 | } |
---|
[17f9522] | 387 | |
---|
| 388 | acc->flags |= ACC_FLAG_AWAY_MESSAGE; |
---|
[96863f6] | 389 | } |
---|
| 390 | |
---|
[0a3c243] | 391 | static void oscar_login(account_t *acc) { |
---|
[b7d3cc34] | 392 | aim_session_t *sess; |
---|
| 393 | aim_conn_t *conn; |
---|
[84b045d] | 394 | struct im_connection *ic = imcb_new(acc); |
---|
[0da65d5] | 395 | struct oscar_data *odata = ic->proto_data = g_new0(struct oscar_data, 1); |
---|
[b7d3cc34] | 396 | |
---|
[181e47a] | 397 | if (isdigit(acc->user[0])) |
---|
| 398 | odata->icq = TRUE; |
---|
| 399 | else |
---|
[6bbb939] | 400 | ic->flags |= OPT_DOES_HTML; |
---|
[b7d3cc34] | 401 | |
---|
| 402 | sess = g_new0(aim_session_t, 1); |
---|
| 403 | |
---|
| 404 | aim_session_init(sess, AIM_SESS_FLAGS_NONBLOCKCONNECT, 0); |
---|
| 405 | |
---|
| 406 | /* we need an immediate queue because we don't use a while-loop to |
---|
| 407 | * see if things need to be sent. */ |
---|
| 408 | aim_tx_setenqueue(sess, AIM_TX_IMMEDIATE, NULL); |
---|
| 409 | odata->sess = sess; |
---|
[0da65d5] | 410 | sess->aux_data = ic; |
---|
[b7d3cc34] | 411 | |
---|
| 412 | conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL); |
---|
| 413 | if (conn == NULL) { |
---|
[84b045d] | 414 | imcb_error(ic, _("Unable to login to AIM")); |
---|
[c2fb3809] | 415 | imc_logout(ic, TRUE); |
---|
[b7d3cc34] | 416 | return; |
---|
| 417 | } |
---|
| 418 | |
---|
[84b045d] | 419 | imcb_log(ic, _("Signon: %s"), ic->acc->user); |
---|
[b7d3cc34] | 420 | |
---|
| 421 | aim_conn_addhandler(sess, conn, 0x0017, 0x0007, gaim_parse_login, 0); |
---|
| 422 | aim_conn_addhandler(sess, conn, 0x0017, 0x0003, gaim_parse_auth_resp, 0); |
---|
| 423 | |
---|
| 424 | conn->status |= AIM_CONN_STATUS_INPROGRESS; |
---|
[30ce1ce] | 425 | conn->fd = proxy_connect(set_getstr(&acc->set, "server"), |
---|
| 426 | AIM_LOGIN_PORT, oscar_login_connect, ic); |
---|
[b7d3cc34] | 427 | if (conn->fd < 0) { |
---|
[84b045d] | 428 | imcb_error(ic, _("Couldn't connect to host")); |
---|
[c2fb3809] | 429 | imc_logout(ic, TRUE); |
---|
[b7d3cc34] | 430 | return; |
---|
| 431 | } |
---|
[c2fb3809] | 432 | aim_request_login(sess, conn, ic->acc->user); |
---|
[b7d3cc34] | 433 | } |
---|
| 434 | |
---|
[0da65d5] | 435 | static void oscar_logout(struct im_connection *ic) { |
---|
| 436 | struct oscar_data *odata = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 437 | |
---|
| 438 | while (odata->oscar_chats) { |
---|
| 439 | struct chat_connection *n = odata->oscar_chats->data; |
---|
| 440 | if (n->inpa > 0) |
---|
[ba9edaa] | 441 | b_event_remove(n->inpa); |
---|
[b7d3cc34] | 442 | g_free(n->name); |
---|
| 443 | g_free(n->show); |
---|
| 444 | odata->oscar_chats = g_slist_remove(odata->oscar_chats, n); |
---|
| 445 | g_free(n); |
---|
| 446 | } |
---|
| 447 | while (odata->create_rooms) { |
---|
| 448 | struct create_room *cr = odata->create_rooms->data; |
---|
| 449 | g_free(cr->name); |
---|
| 450 | odata->create_rooms = g_slist_remove(odata->create_rooms, cr); |
---|
| 451 | g_free(cr); |
---|
| 452 | } |
---|
[e64de00] | 453 | if (odata->ips) |
---|
| 454 | g_hash_table_destroy(odata->ips); |
---|
[b7d3cc34] | 455 | if (odata->email) |
---|
| 456 | g_free(odata->email); |
---|
| 457 | if (odata->newp) |
---|
| 458 | g_free(odata->newp); |
---|
| 459 | if (odata->oldp) |
---|
| 460 | g_free(odata->oldp); |
---|
[0da65d5] | 461 | if (ic->inpa > 0) |
---|
| 462 | b_event_remove(ic->inpa); |
---|
[b7d3cc34] | 463 | if (odata->cnpa > 0) |
---|
[ba9edaa] | 464 | b_event_remove(odata->cnpa); |
---|
[b7d3cc34] | 465 | if (odata->paspa > 0) |
---|
[ba9edaa] | 466 | b_event_remove(odata->paspa); |
---|
[b7d3cc34] | 467 | aim_session_kill(odata->sess); |
---|
| 468 | g_free(odata->sess); |
---|
| 469 | odata->sess = NULL; |
---|
[0da65d5] | 470 | g_free(ic->proto_data); |
---|
| 471 | ic->proto_data = NULL; |
---|
[b7d3cc34] | 472 | } |
---|
| 473 | |
---|
[ba9edaa] | 474 | static gboolean oscar_bos_connect(gpointer data, gint source, b_input_condition cond) { |
---|
[0da65d5] | 475 | struct im_connection *ic = data; |
---|
[b7d3cc34] | 476 | struct oscar_data *odata; |
---|
| 477 | aim_session_t *sess; |
---|
| 478 | aim_conn_t *bosconn; |
---|
| 479 | |
---|
[0da65d5] | 480 | if (!g_slist_find(get_connections(), ic)) { |
---|
[b7d3cc34] | 481 | closesocket(source); |
---|
[ba9edaa] | 482 | return FALSE; |
---|
[b7d3cc34] | 483 | } |
---|
| 484 | |
---|
[0da65d5] | 485 | odata = ic->proto_data; |
---|
[b7d3cc34] | 486 | sess = odata->sess; |
---|
| 487 | bosconn = odata->conn; |
---|
| 488 | |
---|
| 489 | if (source < 0) { |
---|
[84b045d] | 490 | imcb_error(ic, _("Could Not Connect")); |
---|
[c2fb3809] | 491 | imc_logout(ic, TRUE); |
---|
[ba9edaa] | 492 | return FALSE; |
---|
[b7d3cc34] | 493 | } |
---|
| 494 | |
---|
| 495 | aim_conn_completeconnect(sess, bosconn); |
---|
[e046390] | 496 | ic->inpa = b_input_add(bosconn->fd, B_EV_IO_READ, |
---|
[b7d3cc34] | 497 | oscar_callback, bosconn); |
---|
[84b045d] | 498 | imcb_log(ic, _("Connection established, cookie sent")); |
---|
[ba9edaa] | 499 | |
---|
| 500 | return FALSE; |
---|
[b7d3cc34] | 501 | } |
---|
| 502 | |
---|
| 503 | static int gaim_parse_auth_resp(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 504 | va_list ap; |
---|
| 505 | struct aim_authresp_info *info; |
---|
| 506 | int i; char *host; int port; |
---|
| 507 | aim_conn_t *bosconn; |
---|
| 508 | |
---|
[0da65d5] | 509 | struct im_connection *ic = sess->aux_data; |
---|
| 510 | struct oscar_data *od = ic->proto_data; |
---|
[0a3c243] | 511 | port = AIM_LOGIN_PORT; |
---|
[b7d3cc34] | 512 | |
---|
| 513 | va_start(ap, fr); |
---|
| 514 | info = va_arg(ap, struct aim_authresp_info *); |
---|
| 515 | va_end(ap); |
---|
| 516 | |
---|
| 517 | if (info->errorcode || !info->bosip || !info->cookie) { |
---|
| 518 | switch (info->errorcode) { |
---|
| 519 | case 0x05: |
---|
| 520 | /* Incorrect nick/password */ |
---|
[84b045d] | 521 | imcb_error(ic, _("Incorrect nickname or password.")); |
---|
[df61c35a] | 522 | { |
---|
| 523 | int max = od->icq ? 8 : 16; |
---|
| 524 | if (strlen(ic->acc->pass) > max) |
---|
| 525 | imcb_log(ic, "Note that the maximum password " |
---|
| 526 | "length supported by this protocol is " |
---|
| 527 | "%d characters, try logging in using " |
---|
| 528 | "a shorter password.", max); |
---|
| 529 | } |
---|
[b7d3cc34] | 530 | // plugin_event(event_error, (void *)980, 0, 0, 0); |
---|
| 531 | break; |
---|
| 532 | case 0x11: |
---|
| 533 | /* Suspended account */ |
---|
[84b045d] | 534 | imcb_error(ic, _("Your account is currently suspended.")); |
---|
[b7d3cc34] | 535 | break; |
---|
| 536 | case 0x18: |
---|
| 537 | /* connecting too frequently */ |
---|
[5469952] | 538 | od->no_reconnect = TRUE; |
---|
[84b045d] | 539 | imcb_error(ic, _("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.")); |
---|
[b7d3cc34] | 540 | break; |
---|
| 541 | case 0x1c: |
---|
| 542 | /* client too old */ |
---|
[84b045d] | 543 | imcb_error(ic, _("The client version you are using is too old. Please upgrade at " WEBSITE)); |
---|
[b7d3cc34] | 544 | break; |
---|
| 545 | default: |
---|
[84b045d] | 546 | imcb_error(ic, _("Authentication Failed")); |
---|
[b7d3cc34] | 547 | break; |
---|
| 548 | } |
---|
| 549 | od->killme = TRUE; |
---|
| 550 | return 1; |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | |
---|
| 554 | aim_conn_kill(sess, &fr->conn); |
---|
| 555 | |
---|
| 556 | bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, NULL); |
---|
| 557 | if (bosconn == NULL) { |
---|
[84b045d] | 558 | imcb_error(ic, _("Internal Error")); |
---|
[b7d3cc34] | 559 | od->killme = TRUE; |
---|
| 560 | return 0; |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_bos, 0); |
---|
| 564 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BOS, AIM_CB_BOS_RIGHTS, gaim_bosrights, 0); |
---|
| 565 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0); |
---|
| 566 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, gaim_handle_redirect, 0); |
---|
| 567 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_RIGHTSINFO, gaim_parse_locaterights, 0); |
---|
| 568 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_RIGHTSINFO, gaim_parse_buddyrights, 0); |
---|
| 569 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, gaim_parse_oncoming, 0); |
---|
| 570 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, gaim_parse_offgoing, 0); |
---|
| 571 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, gaim_parse_incoming_im, 0); |
---|
| 572 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, gaim_parse_locerr, 0); |
---|
| 573 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, gaim_parse_misses, 0); |
---|
| 574 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, gaim_parse_ratechange, 0); |
---|
| 575 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, gaim_parse_msgerr, 0); |
---|
| 576 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); |
---|
| 577 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_PARAMINFO, gaim_icbm_param_info, 0); |
---|
| 578 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_ERROR, gaim_parse_genericerr, 0); |
---|
| 579 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ERROR, gaim_parse_genericerr, 0); |
---|
| 580 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BOS, AIM_CB_BOS_ERROR, gaim_parse_genericerr, 0); |
---|
| 581 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SELFINFO, gaim_selfinfo, 0); |
---|
| 582 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG, gaim_offlinemsg, 0); |
---|
| 583 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE, gaim_offlinemsgdone, 0); |
---|
| 584 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_INFO, gaim_icqinfo, 0); |
---|
| 585 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_RIGHTSINFO, gaim_ssi_parserights, 0); |
---|
| 586 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_LIST, gaim_ssi_parselist, 0); |
---|
| 587 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_SRVACK, gaim_ssi_parseack, 0); |
---|
| 588 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, gaim_parseaiminfo, 0); |
---|
[3e1de87] | 589 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MTN, gaim_parsemtn, 0); |
---|
[5469952] | 590 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, gaim_parse_logout, 0); |
---|
[b7d3cc34] | 591 | |
---|
[0da65d5] | 592 | ((struct oscar_data *)ic->proto_data)->conn = bosconn; |
---|
[b7d3cc34] | 593 | for (i = 0; i < (int)strlen(info->bosip); i++) { |
---|
| 594 | if (info->bosip[i] == ':') { |
---|
| 595 | port = atoi(&(info->bosip[i+1])); |
---|
| 596 | break; |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | host = g_strndup(info->bosip, i); |
---|
| 600 | bosconn->status |= AIM_CONN_STATUS_INPROGRESS; |
---|
[0da65d5] | 601 | bosconn->fd = proxy_connect(host, port, oscar_bos_connect, ic); |
---|
[b7d3cc34] | 602 | g_free(host); |
---|
| 603 | if (bosconn->fd < 0) { |
---|
[84b045d] | 604 | imcb_error(ic, _("Could Not Connect")); |
---|
[b7d3cc34] | 605 | od->killme = TRUE; |
---|
| 606 | return 0; |
---|
| 607 | } |
---|
| 608 | aim_sendcookie(sess, bosconn, info->cookie); |
---|
[0da65d5] | 609 | b_event_remove(ic->inpa); |
---|
[b7d3cc34] | 610 | |
---|
| 611 | return 1; |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | /* size of icbmui.ocm, the largest module in AIM 3.5 */ |
---|
| 615 | #define AIM_MAX_FILE_SIZE 98304 |
---|
| 616 | |
---|
| 617 | static int gaim_parse_login(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 618 | #if 0 |
---|
| 619 | struct client_info_s info = {"gaim", 4, 1, 2010, "us", "en", 0x0004, 0x0000, 0x04b}; |
---|
| 620 | #else |
---|
| 621 | struct client_info_s info = AIM_CLIENTINFO_KNOWNGOOD; |
---|
| 622 | #endif |
---|
| 623 | char *key; |
---|
| 624 | va_list ap; |
---|
[0da65d5] | 625 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 626 | |
---|
| 627 | va_start(ap, fr); |
---|
| 628 | key = va_arg(ap, char *); |
---|
| 629 | va_end(ap); |
---|
| 630 | |
---|
[c2fb3809] | 631 | aim_send_login(sess, fr->conn, ic->acc->user, ic->acc->pass, &info, key); |
---|
[b7d3cc34] | 632 | |
---|
| 633 | return 1; |
---|
| 634 | } |
---|
| 635 | |
---|
[5469952] | 636 | static int gaim_parse_logout(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 637 | struct im_connection *ic = sess->aux_data; |
---|
| 638 | struct oscar_data *odata = ic->proto_data; |
---|
| 639 | int code; |
---|
| 640 | va_list ap; |
---|
| 641 | |
---|
| 642 | va_start(ap, fr); |
---|
| 643 | code = va_arg(ap, int); |
---|
| 644 | va_end(ap); |
---|
| 645 | |
---|
| 646 | imcb_error( ic, "Connection aborted by server: %s", code == 1 ? |
---|
| 647 | "someone else logged in with your account" : |
---|
| 648 | "unknown reason" ); |
---|
| 649 | |
---|
| 650 | /* Tell BitlBee to disable auto_reconnect if code == 1, since that |
---|
| 651 | means a concurrent login somewhere else. */ |
---|
| 652 | odata->no_reconnect = code == 1; |
---|
| 653 | |
---|
| 654 | /* DO NOT log out here! Just tell the callback to do it. */ |
---|
| 655 | odata->killme = TRUE; |
---|
| 656 | |
---|
| 657 | return 1; |
---|
| 658 | } |
---|
| 659 | |
---|
[b7d3cc34] | 660 | static int conninitdone_chat(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
[0da65d5] | 661 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 662 | struct chat_connection *chatcon; |
---|
[e5abfd4] | 663 | struct groupchat *c = NULL; |
---|
[b7d3cc34] | 664 | static int id = 1; |
---|
| 665 | |
---|
| 666 | aim_conn_addhandler(sess, fr->conn, 0x000e, 0x0001, gaim_parse_genericerr, 0); |
---|
| 667 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, gaim_chat_join, 0); |
---|
| 668 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, gaim_chat_leave, 0); |
---|
| 669 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, gaim_chat_info_update, 0); |
---|
| 670 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, gaim_chat_incoming_msg, 0); |
---|
| 671 | |
---|
| 672 | aim_clientready(sess, fr->conn); |
---|
| 673 | |
---|
[0da65d5] | 674 | chatcon = find_oscar_chat_by_conn(ic, fr->conn); |
---|
[b7d3cc34] | 675 | chatcon->id = id; |
---|
[e5abfd4] | 676 | |
---|
| 677 | c = bee_chat_by_title(ic->bee, ic, chatcon->show); |
---|
| 678 | if (c && !c->data) |
---|
| 679 | chatcon->cnv = c; |
---|
| 680 | else |
---|
[75610c3] | 681 | chatcon->cnv = imcb_chat_new(ic, chatcon->show); |
---|
[fa29d093] | 682 | chatcon->cnv->data = chatcon; |
---|
[b7d3cc34] | 683 | |
---|
| 684 | return 1; |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | static int conninitdone_chatnav(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 688 | |
---|
| 689 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CTN, AIM_CB_CTN_ERROR, gaim_parse_genericerr, 0); |
---|
| 690 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CTN, AIM_CB_CTN_INFO, gaim_chatnav_info, 0); |
---|
| 691 | |
---|
| 692 | aim_clientready(sess, fr->conn); |
---|
| 693 | |
---|
| 694 | aim_chatnav_reqrights(sess, fr->conn); |
---|
| 695 | |
---|
| 696 | return 1; |
---|
| 697 | } |
---|
| 698 | |
---|
[ba9edaa] | 699 | static gboolean oscar_chatnav_connect(gpointer data, gint source, b_input_condition cond) { |
---|
[0da65d5] | 700 | struct im_connection *ic = data; |
---|
[b7d3cc34] | 701 | struct oscar_data *odata; |
---|
| 702 | aim_session_t *sess; |
---|
| 703 | aim_conn_t *tstconn; |
---|
| 704 | |
---|
[0da65d5] | 705 | if (!g_slist_find(get_connections(), ic)) { |
---|
[b7d3cc34] | 706 | closesocket(source); |
---|
[ba9edaa] | 707 | return FALSE; |
---|
[b7d3cc34] | 708 | } |
---|
| 709 | |
---|
[0da65d5] | 710 | odata = ic->proto_data; |
---|
[b7d3cc34] | 711 | sess = odata->sess; |
---|
| 712 | tstconn = aim_getconn_type_all(sess, AIM_CONN_TYPE_CHATNAV); |
---|
| 713 | |
---|
| 714 | if (source < 0) { |
---|
| 715 | aim_conn_kill(sess, &tstconn); |
---|
[ba9edaa] | 716 | return FALSE; |
---|
[b7d3cc34] | 717 | } |
---|
| 718 | |
---|
| 719 | aim_conn_completeconnect(sess, tstconn); |
---|
[e046390] | 720 | odata->cnpa = b_input_add(tstconn->fd, B_EV_IO_READ, |
---|
[b7d3cc34] | 721 | oscar_callback, tstconn); |
---|
[ba9edaa] | 722 | |
---|
| 723 | return FALSE; |
---|
[b7d3cc34] | 724 | } |
---|
| 725 | |
---|
[ba9edaa] | 726 | static gboolean oscar_auth_connect(gpointer data, gint source, b_input_condition cond) |
---|
[b7d3cc34] | 727 | { |
---|
[0da65d5] | 728 | struct im_connection *ic = data; |
---|
[b7d3cc34] | 729 | struct oscar_data *odata; |
---|
| 730 | aim_session_t *sess; |
---|
| 731 | aim_conn_t *tstconn; |
---|
| 732 | |
---|
[0da65d5] | 733 | if (!g_slist_find(get_connections(), ic)) { |
---|
[b7d3cc34] | 734 | closesocket(source); |
---|
[ba9edaa] | 735 | return FALSE; |
---|
[b7d3cc34] | 736 | } |
---|
| 737 | |
---|
[0da65d5] | 738 | odata = ic->proto_data; |
---|
[b7d3cc34] | 739 | sess = odata->sess; |
---|
| 740 | tstconn = aim_getconn_type_all(sess, AIM_CONN_TYPE_AUTH); |
---|
| 741 | |
---|
| 742 | if (source < 0) { |
---|
| 743 | aim_conn_kill(sess, &tstconn); |
---|
[ba9edaa] | 744 | return FALSE; |
---|
[b7d3cc34] | 745 | } |
---|
| 746 | |
---|
| 747 | aim_conn_completeconnect(sess, tstconn); |
---|
[e046390] | 748 | odata->paspa = b_input_add(tstconn->fd, B_EV_IO_READ, |
---|
[b7d3cc34] | 749 | oscar_callback, tstconn); |
---|
[ba9edaa] | 750 | |
---|
| 751 | return FALSE; |
---|
[b7d3cc34] | 752 | } |
---|
| 753 | |
---|
[ba9edaa] | 754 | static gboolean oscar_chat_connect(gpointer data, gint source, b_input_condition cond) |
---|
[b7d3cc34] | 755 | { |
---|
| 756 | struct chat_connection *ccon = data; |
---|
[0da65d5] | 757 | struct im_connection *ic = ccon->ic; |
---|
[b7d3cc34] | 758 | struct oscar_data *odata; |
---|
| 759 | aim_session_t *sess; |
---|
| 760 | aim_conn_t *tstconn; |
---|
| 761 | |
---|
[0da65d5] | 762 | if (!g_slist_find(get_connections(), ic)) { |
---|
[b7d3cc34] | 763 | closesocket(source); |
---|
| 764 | g_free(ccon->show); |
---|
| 765 | g_free(ccon->name); |
---|
| 766 | g_free(ccon); |
---|
[ba9edaa] | 767 | return FALSE; |
---|
[b7d3cc34] | 768 | } |
---|
| 769 | |
---|
[0da65d5] | 770 | odata = ic->proto_data; |
---|
[b7d3cc34] | 771 | sess = odata->sess; |
---|
| 772 | tstconn = ccon->conn; |
---|
| 773 | |
---|
| 774 | if (source < 0) { |
---|
| 775 | aim_conn_kill(sess, &tstconn); |
---|
| 776 | g_free(ccon->show); |
---|
| 777 | g_free(ccon->name); |
---|
| 778 | g_free(ccon); |
---|
[ba9edaa] | 779 | return FALSE; |
---|
[b7d3cc34] | 780 | } |
---|
| 781 | |
---|
| 782 | aim_conn_completeconnect(sess, ccon->conn); |
---|
[ba9edaa] | 783 | ccon->inpa = b_input_add(tstconn->fd, |
---|
[e046390] | 784 | B_EV_IO_READ, |
---|
[b7d3cc34] | 785 | oscar_callback, tstconn); |
---|
| 786 | odata->oscar_chats = g_slist_append(odata->oscar_chats, ccon); |
---|
[ba9edaa] | 787 | |
---|
| 788 | return FALSE; |
---|
[b7d3cc34] | 789 | } |
---|
| 790 | |
---|
| 791 | /* Hrmph. I don't know how to make this look better. --mid */ |
---|
| 792 | static int gaim_handle_redirect(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 793 | va_list ap; |
---|
| 794 | struct aim_redirect_data *redir; |
---|
[0da65d5] | 795 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 796 | aim_conn_t *tstconn; |
---|
| 797 | int i; |
---|
| 798 | char *host; |
---|
| 799 | int port; |
---|
| 800 | |
---|
| 801 | va_start(ap, fr); |
---|
| 802 | redir = va_arg(ap, struct aim_redirect_data *); |
---|
| 803 | va_end(ap); |
---|
| 804 | |
---|
[0a3c243] | 805 | port = AIM_LOGIN_PORT; |
---|
[b7d3cc34] | 806 | for (i = 0; i < (int)strlen(redir->ip); i++) { |
---|
| 807 | if (redir->ip[i] == ':') { |
---|
| 808 | port = atoi(&(redir->ip[i+1])); |
---|
| 809 | break; |
---|
| 810 | } |
---|
| 811 | } |
---|
| 812 | host = g_strndup(redir->ip, i); |
---|
| 813 | |
---|
| 814 | switch(redir->group) { |
---|
| 815 | case 0x7: /* Authorizer */ |
---|
| 816 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL); |
---|
| 817 | if (tstconn == NULL) { |
---|
| 818 | g_free(host); |
---|
| 819 | return 1; |
---|
| 820 | } |
---|
| 821 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_admin, 0); |
---|
| 822 | // aim_conn_addhandler(sess, tstconn, 0x0007, 0x0003, gaim_info_change, 0); |
---|
| 823 | // aim_conn_addhandler(sess, tstconn, 0x0007, 0x0005, gaim_info_change, 0); |
---|
| 824 | // aim_conn_addhandler(sess, tstconn, 0x0007, 0x0007, gaim_account_confirm, 0); |
---|
| 825 | |
---|
| 826 | tstconn->status |= AIM_CONN_STATUS_INPROGRESS; |
---|
[0da65d5] | 827 | tstconn->fd = proxy_connect(host, port, oscar_auth_connect, ic); |
---|
[b7d3cc34] | 828 | if (tstconn->fd < 0) { |
---|
| 829 | aim_conn_kill(sess, &tstconn); |
---|
| 830 | g_free(host); |
---|
| 831 | return 1; |
---|
| 832 | } |
---|
| 833 | aim_sendcookie(sess, tstconn, redir->cookie); |
---|
| 834 | break; |
---|
| 835 | case 0xd: /* ChatNav */ |
---|
| 836 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, NULL); |
---|
| 837 | if (tstconn == NULL) { |
---|
| 838 | g_free(host); |
---|
| 839 | return 1; |
---|
| 840 | } |
---|
| 841 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_chatnav, 0); |
---|
| 842 | |
---|
| 843 | tstconn->status |= AIM_CONN_STATUS_INPROGRESS; |
---|
[0da65d5] | 844 | tstconn->fd = proxy_connect(host, port, oscar_chatnav_connect, ic); |
---|
[b7d3cc34] | 845 | if (tstconn->fd < 0) { |
---|
| 846 | aim_conn_kill(sess, &tstconn); |
---|
| 847 | g_free(host); |
---|
| 848 | return 1; |
---|
| 849 | } |
---|
| 850 | aim_sendcookie(sess, tstconn, redir->cookie); |
---|
| 851 | break; |
---|
| 852 | case 0xe: /* Chat */ |
---|
| 853 | { |
---|
| 854 | struct chat_connection *ccon; |
---|
| 855 | |
---|
| 856 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, NULL); |
---|
| 857 | if (tstconn == NULL) { |
---|
| 858 | g_free(host); |
---|
| 859 | return 1; |
---|
| 860 | } |
---|
| 861 | |
---|
| 862 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_chat, 0); |
---|
| 863 | |
---|
| 864 | ccon = g_new0(struct chat_connection, 1); |
---|
| 865 | ccon->conn = tstconn; |
---|
[0da65d5] | 866 | ccon->ic = ic; |
---|
[b7d3cc34] | 867 | ccon->fd = -1; |
---|
| 868 | ccon->name = g_strdup(redir->chat.room); |
---|
| 869 | ccon->exchange = redir->chat.exchange; |
---|
| 870 | ccon->instance = redir->chat.instance; |
---|
| 871 | ccon->show = extract_name(redir->chat.room); |
---|
| 872 | |
---|
| 873 | ccon->conn->status |= AIM_CONN_STATUS_INPROGRESS; |
---|
| 874 | ccon->conn->fd = proxy_connect(host, port, oscar_chat_connect, ccon); |
---|
| 875 | if (ccon->conn->fd < 0) { |
---|
| 876 | aim_conn_kill(sess, &tstconn); |
---|
| 877 | g_free(host); |
---|
| 878 | g_free(ccon->show); |
---|
| 879 | g_free(ccon->name); |
---|
| 880 | g_free(ccon); |
---|
| 881 | return 1; |
---|
| 882 | } |
---|
| 883 | aim_sendcookie(sess, tstconn, redir->cookie); |
---|
| 884 | } |
---|
| 885 | break; |
---|
| 886 | default: /* huh? */ |
---|
| 887 | break; |
---|
| 888 | } |
---|
| 889 | |
---|
| 890 | g_free(host); |
---|
| 891 | return 1; |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | static int gaim_parse_oncoming(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
[0da65d5] | 895 | struct im_connection *ic = sess->aux_data; |
---|
| 896 | struct oscar_data *od = ic->proto_data; |
---|
[b7d3cc34] | 897 | aim_userinfo_t *info; |
---|
| 898 | time_t time_idle = 0, signon = 0; |
---|
[6bbb939] | 899 | int flags = OPT_LOGGED_IN; |
---|
| 900 | char *tmp, *state_string = NULL; |
---|
[b7d3cc34] | 901 | |
---|
| 902 | va_list ap; |
---|
| 903 | va_start(ap, fr); |
---|
| 904 | info = va_arg(ap, aim_userinfo_t *); |
---|
| 905 | va_end(ap); |
---|
| 906 | |
---|
| 907 | if ((!od->icq) && (info->present & AIM_USERINFO_PRESENT_FLAGS)) { |
---|
| 908 | if (info->flags & AIM_FLAG_AWAY) |
---|
[6bbb939] | 909 | flags |= OPT_AWAY; |
---|
[b7d3cc34] | 910 | } |
---|
[6bbb939] | 911 | |
---|
[0ebf919] | 912 | /* Maybe this should be done just for AIM contacts, not sure. */ |
---|
| 913 | if (info->flags & AIM_FLAG_WIRELESS) |
---|
| 914 | flags |= OPT_MOBILE; |
---|
| 915 | |
---|
[b7d3cc34] | 916 | if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS) { |
---|
| 917 | if (!(info->icqinfo.status & AIM_ICQ_STATE_CHAT) && |
---|
| 918 | (info->icqinfo.status != AIM_ICQ_STATE_NORMAL)) { |
---|
[6bbb939] | 919 | flags |= OPT_AWAY; |
---|
[b7d3cc34] | 920 | } |
---|
[6bbb939] | 921 | |
---|
| 922 | if( info->icqinfo.status & AIM_ICQ_STATE_DND ) |
---|
| 923 | state_string = "Do Not Disturb"; |
---|
| 924 | else if( info->icqinfo.status & AIM_ICQ_STATE_OUT ) |
---|
| 925 | state_string = "Not Available"; |
---|
| 926 | else if( info->icqinfo.status & AIM_ICQ_STATE_BUSY ) |
---|
| 927 | state_string = "Occupied"; |
---|
| 928 | else if( info->icqinfo.status & AIM_ICQ_STATE_INVISIBLE ) |
---|
| 929 | state_string = "Invisible"; |
---|
[b7d3cc34] | 930 | } |
---|
| 931 | |
---|
| 932 | if (info->present & AIM_USERINFO_PRESENT_IDLE) { |
---|
| 933 | time(&time_idle); |
---|
| 934 | time_idle -= info->idletime*60; |
---|
| 935 | } |
---|
| 936 | |
---|
| 937 | if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN) |
---|
| 938 | signon = time(NULL) - info->sessionlen; |
---|
| 939 | |
---|
[e64de00] | 940 | if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR) { |
---|
| 941 | uint32_t *uin = g_new0(uint32_t, 1); |
---|
| 942 | |
---|
| 943 | if (od->ips == NULL) |
---|
| 944 | od->ips = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL); |
---|
| 945 | |
---|
| 946 | if (sscanf(info->sn, "%d", uin) == 1) |
---|
| 947 | g_hash_table_insert(od->ips, uin, (gpointer) (long) info->icqinfo.ipaddr); |
---|
| 948 | } |
---|
| 949 | |
---|
[c801d25] | 950 | if (!aim_sncmp(ic->acc->user, info->sn)) |
---|
[0da65d5] | 951 | g_snprintf(ic->displayname, sizeof(ic->displayname), "%s", info->sn); |
---|
[b7d3cc34] | 952 | |
---|
[424e663] | 953 | tmp = normalize(info->sn); |
---|
| 954 | imcb_buddy_status(ic, tmp, flags, state_string, NULL); |
---|
[56699f0] | 955 | imcb_buddy_times(ic, tmp, signon, time_idle); |
---|
[424e663] | 956 | |
---|
[b7d3cc34] | 957 | |
---|
| 958 | return 1; |
---|
| 959 | } |
---|
| 960 | |
---|
| 961 | static int gaim_parse_offgoing(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 962 | aim_userinfo_t *info; |
---|
| 963 | va_list ap; |
---|
[0da65d5] | 964 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 965 | |
---|
| 966 | va_start(ap, fr); |
---|
| 967 | info = va_arg(ap, aim_userinfo_t *); |
---|
| 968 | va_end(ap); |
---|
| 969 | |
---|
[424e663] | 970 | imcb_buddy_status(ic, normalize(info->sn), 0, NULL, NULL ); |
---|
[b7d3cc34] | 971 | |
---|
| 972 | return 1; |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | static int incomingim_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch1_args *args) { |
---|
| 976 | char *tmp = g_malloc(BUF_LONG + 1); |
---|
[0da65d5] | 977 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 978 | int flags = 0; |
---|
| 979 | |
---|
| 980 | if (args->icbmflags & AIM_IMFLAGS_AWAY) |
---|
[6bbb939] | 981 | flags |= OPT_AWAY; |
---|
[b7d3cc34] | 982 | |
---|
| 983 | if ((args->icbmflags & AIM_IMFLAGS_UNICODE) || (args->icbmflags & AIM_IMFLAGS_ISO_8859_1)) { |
---|
| 984 | char *src; |
---|
| 985 | |
---|
| 986 | if (args->icbmflags & AIM_IMFLAGS_UNICODE) |
---|
| 987 | src = "UNICODEBIG"; |
---|
| 988 | else |
---|
| 989 | src = "ISO8859-1"; |
---|
| 990 | |
---|
| 991 | /* Try to use iconv first to convert the message to UTF8 - which is what BitlBee expects */ |
---|
| 992 | if (do_iconv(src, "UTF-8", args->msg, tmp, args->msglen, BUF_LONG) >= 0) { |
---|
| 993 | // Successfully converted! |
---|
| 994 | } else if (args->icbmflags & AIM_IMFLAGS_UNICODE) { |
---|
| 995 | int i; |
---|
| 996 | |
---|
| 997 | for (i = 0, tmp[0] = '\0'; i < args->msglen; i += 2) { |
---|
| 998 | unsigned short uni; |
---|
| 999 | |
---|
| 1000 | uni = ((args->msg[i] & 0xff) << 8) | (args->msg[i+1] & 0xff); |
---|
| 1001 | |
---|
| 1002 | if ((uni < 128) || ((uni >= 160) && (uni <= 255))) { /* ISO 8859-1 */ |
---|
| 1003 | g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "%c", uni); |
---|
| 1004 | } else { /* something else, do UNICODE entity */ |
---|
| 1005 | g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "&#%04x;", uni); |
---|
| 1006 | } |
---|
| 1007 | } |
---|
| 1008 | } else { |
---|
| 1009 | g_snprintf(tmp, BUF_LONG, "%s", args->msg); |
---|
| 1010 | } |
---|
[be68d99] | 1011 | } else if (args->mpmsg.numparts == 0) { |
---|
[b7d3cc34] | 1012 | g_snprintf(tmp, BUF_LONG, "%s", args->msg); |
---|
[be68d99] | 1013 | } else { |
---|
[f774e01] | 1014 | aim_mpmsg_section_t *part; |
---|
[be68d99] | 1015 | |
---|
| 1016 | *tmp = 0; |
---|
[f774e01] | 1017 | for (part = args->mpmsg.parts; part; part = part->next) { |
---|
| 1018 | if (part->data) { |
---|
| 1019 | g_strlcat(tmp, (char*) part->data, BUF_LONG); |
---|
| 1020 | g_strlcat(tmp, "\n", BUF_LONG); |
---|
| 1021 | } |
---|
[be68d99] | 1022 | } |
---|
| 1023 | } |
---|
[b7d3cc34] | 1024 | |
---|
| 1025 | strip_linefeed(tmp); |
---|
[424e663] | 1026 | imcb_buddy_msg(ic, normalize(userinfo->sn), tmp, flags, 0); |
---|
[b7d3cc34] | 1027 | g_free(tmp); |
---|
| 1028 | |
---|
| 1029 | return 1; |
---|
| 1030 | } |
---|
| 1031 | |
---|
[9143aeb] | 1032 | void oscar_accept_chat(void *data); |
---|
| 1033 | void oscar_reject_chat(void *data); |
---|
[b8ef1b1] | 1034 | |
---|
[b7d3cc34] | 1035 | static int incomingim_chan2(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args) { |
---|
[0da65d5] | 1036 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 1037 | |
---|
| 1038 | if (args->status != AIM_RENDEZVOUS_PROPOSE) |
---|
| 1039 | return 1; |
---|
[b8ef1b1] | 1040 | |
---|
[b7d3cc34] | 1041 | if (args->reqclass & AIM_CAPS_CHAT) { |
---|
| 1042 | char *name = extract_name(args->info.chat.roominfo.name); |
---|
| 1043 | int *exch = g_new0(int, 1); |
---|
| 1044 | GList *m = NULL; |
---|
[11e090b] | 1045 | char txt[1024]; |
---|
| 1046 | struct aim_chat_invitation * inv = g_new0(struct aim_chat_invitation, 1); |
---|
| 1047 | |
---|
[b7d3cc34] | 1048 | m = g_list_append(m, g_strdup(name ? name : args->info.chat.roominfo.name)); |
---|
| 1049 | *exch = args->info.chat.roominfo.exchange; |
---|
| 1050 | m = g_list_append(m, exch); |
---|
[b8ef1b1] | 1051 | |
---|
[d4bc2d9] | 1052 | g_snprintf(txt, 1024, "Got an invitation to chatroom %s from %s: %s", name, userinfo->sn, args->msg); |
---|
[b8ef1b1] | 1053 | |
---|
[0da65d5] | 1054 | inv->ic = ic; |
---|
[b8ef1b1] | 1055 | inv->exchange = *exch; |
---|
| 1056 | inv->name = g_strdup(name); |
---|
| 1057 | |
---|
[d4bc2d9] | 1058 | imcb_ask(ic, txt, inv, oscar_accept_chat, oscar_reject_chat); |
---|
[b8ef1b1] | 1059 | |
---|
[b7d3cc34] | 1060 | if (name) |
---|
| 1061 | g_free(name); |
---|
[d4bc2d9] | 1062 | } else if (args->reqclass & AIM_CAPS_ICQRTF) { |
---|
| 1063 | // TODO: constify |
---|
[2334048] | 1064 | char text[strlen(args->info.rtfmsg.rtfmsg)+1]; |
---|
| 1065 | strncpy(text, args->info.rtfmsg.rtfmsg, sizeof(text)); |
---|
[d4bc2d9] | 1066 | imcb_buddy_msg(ic, normalize(userinfo->sn), text, 0, 0); |
---|
[b7d3cc34] | 1067 | } |
---|
[b8ef1b1] | 1068 | |
---|
[b7d3cc34] | 1069 | return 1; |
---|
| 1070 | } |
---|
| 1071 | |
---|
[9143aeb] | 1072 | static void gaim_icq_authgrant(void *data_) { |
---|
| 1073 | struct icq_auth *data = data_; |
---|
[b7d3cc34] | 1074 | char *uin, message; |
---|
[0da65d5] | 1075 | struct oscar_data *od = (struct oscar_data *)data->ic->proto_data; |
---|
[b7d3cc34] | 1076 | |
---|
| 1077 | uin = g_strdup_printf("%u", data->uin); |
---|
| 1078 | message = 0; |
---|
| 1079 | aim_ssi_auth_reply(od->sess, od->conn, uin, 1, ""); |
---|
| 1080 | // aim_send_im_ch4(od->sess, uin, AIM_ICQMSG_AUTHGRANTED, &message); |
---|
[81e04e1] | 1081 | imcb_ask_add(data->ic, uin, NULL); |
---|
[b7d3cc34] | 1082 | |
---|
| 1083 | g_free(uin); |
---|
| 1084 | g_free(data); |
---|
| 1085 | } |
---|
| 1086 | |
---|
[9143aeb] | 1087 | static void gaim_icq_authdeny(void *data_) { |
---|
| 1088 | struct icq_auth *data = data_; |
---|
[b7d3cc34] | 1089 | char *uin, *message; |
---|
[0da65d5] | 1090 | struct oscar_data *od = (struct oscar_data *)data->ic->proto_data; |
---|
[b7d3cc34] | 1091 | |
---|
| 1092 | uin = g_strdup_printf("%u", data->uin); |
---|
| 1093 | message = g_strdup_printf("No reason given."); |
---|
| 1094 | aim_ssi_auth_reply(od->sess, od->conn, uin, 0, ""); |
---|
| 1095 | // aim_send_im_ch4(od->sess, uin, AIM_ICQMSG_AUTHDENIED, message); |
---|
| 1096 | g_free(message); |
---|
| 1097 | |
---|
| 1098 | g_free(uin); |
---|
| 1099 | g_free(data); |
---|
| 1100 | } |
---|
| 1101 | |
---|
| 1102 | /* |
---|
| 1103 | * For when other people ask you for authorization |
---|
| 1104 | */ |
---|
[0da65d5] | 1105 | static void gaim_icq_authask(struct im_connection *ic, guint32 uin, char *msg) { |
---|
[545d7c0] | 1106 | struct icq_auth *data; |
---|
[b7d3cc34] | 1107 | char *reason = NULL; |
---|
| 1108 | char *dialog_msg; |
---|
[545d7c0] | 1109 | |
---|
| 1110 | if (set_getbool(&ic->acc->set, "ignore_auth_requests")) |
---|
| 1111 | return; |
---|
[b7d3cc34] | 1112 | |
---|
[545d7c0] | 1113 | data = g_new(struct icq_auth, 1); |
---|
| 1114 | |
---|
[b7d3cc34] | 1115 | if (strlen(msg) > 6) |
---|
| 1116 | reason = msg + 6; |
---|
| 1117 | |
---|
[aefa533e] | 1118 | dialog_msg = g_strdup_printf("The user %u wants to add you to their buddy list for the following reason: %s", uin, reason ? reason : "No reason given."); |
---|
[0da65d5] | 1119 | data->ic = ic; |
---|
[b7d3cc34] | 1120 | data->uin = uin; |
---|
[84b045d] | 1121 | imcb_ask(ic, dialog_msg, data, gaim_icq_authgrant, gaim_icq_authdeny); |
---|
[b7d3cc34] | 1122 | g_free(dialog_msg); |
---|
| 1123 | } |
---|
| 1124 | |
---|
| 1125 | static int incomingim_chan4(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch4_args *args) { |
---|
[0da65d5] | 1126 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 1127 | |
---|
| 1128 | switch (args->type) { |
---|
| 1129 | case 0x0001: { /* An almost-normal instant message. Mac ICQ sends this. It's peculiar. */ |
---|
| 1130 | char *uin, *message; |
---|
| 1131 | uin = g_strdup_printf("%u", args->uin); |
---|
| 1132 | message = g_strdup(args->msg); |
---|
| 1133 | strip_linefeed(message); |
---|
[424e663] | 1134 | imcb_buddy_msg(ic, normalize(uin), message, 0, 0); |
---|
[b7d3cc34] | 1135 | g_free(uin); |
---|
| 1136 | g_free(message); |
---|
| 1137 | } break; |
---|
| 1138 | |
---|
| 1139 | case 0x0004: { /* Someone sent you a URL */ |
---|
| 1140 | char *uin, *message; |
---|
| 1141 | char **m; |
---|
| 1142 | |
---|
| 1143 | uin = g_strdup_printf("%u", args->uin); |
---|
| 1144 | m = g_strsplit(args->msg, "\376", 2); |
---|
| 1145 | |
---|
| 1146 | if ((strlen(m[0]) != 0)) { |
---|
| 1147 | message = g_strjoinv(" -- ", m); |
---|
| 1148 | } else { |
---|
| 1149 | message = m[1]; |
---|
| 1150 | } |
---|
| 1151 | |
---|
| 1152 | strip_linefeed(message); |
---|
[424e663] | 1153 | imcb_buddy_msg(ic, normalize(uin), message, 0, 0); |
---|
[b7d3cc34] | 1154 | g_free(uin); |
---|
| 1155 | g_free(m); |
---|
| 1156 | g_free(message); |
---|
| 1157 | } break; |
---|
| 1158 | |
---|
| 1159 | case 0x0006: { /* Someone requested authorization */ |
---|
[0da65d5] | 1160 | gaim_icq_authask(ic, args->uin, args->msg); |
---|
[b7d3cc34] | 1161 | } break; |
---|
| 1162 | |
---|
| 1163 | case 0x0007: { /* Someone has denied you authorization */ |
---|
[84b045d] | 1164 | imcb_log(sess->aux_data, "The user %u 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.") ); |
---|
[b7d3cc34] | 1165 | } break; |
---|
| 1166 | |
---|
| 1167 | case 0x0008: { /* Someone has granted you authorization */ |
---|
[84b045d] | 1168 | imcb_log(sess->aux_data, "The user %u has granted your request to add them to your contact list for the following reason:\n%s", args->uin, args->msg ? args->msg : _("No reason given.") ); |
---|
[b7d3cc34] | 1169 | } break; |
---|
| 1170 | |
---|
| 1171 | case 0x0012: { |
---|
| 1172 | /* Ack for authorizing/denying someone. Or possibly an ack for sending any system notice */ |
---|
| 1173 | } break; |
---|
| 1174 | |
---|
| 1175 | default: {; |
---|
| 1176 | } break; |
---|
| 1177 | } |
---|
| 1178 | |
---|
| 1179 | return 1; |
---|
| 1180 | } |
---|
[9cb9868] | 1181 | |
---|
[b7d3cc34] | 1182 | static int gaim_parse_incoming_im(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1183 | int channel, ret = 0; |
---|
| 1184 | aim_userinfo_t *userinfo; |
---|
| 1185 | va_list ap; |
---|
| 1186 | |
---|
| 1187 | va_start(ap, fr); |
---|
| 1188 | channel = va_arg(ap, int); |
---|
| 1189 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1190 | |
---|
| 1191 | switch (channel) { |
---|
| 1192 | case 1: { /* standard message */ |
---|
| 1193 | struct aim_incomingim_ch1_args *args; |
---|
| 1194 | args = va_arg(ap, struct aim_incomingim_ch1_args *); |
---|
| 1195 | ret = incomingim_chan1(sess, fr->conn, userinfo, args); |
---|
| 1196 | } break; |
---|
| 1197 | |
---|
| 1198 | case 2: { /* rendevous */ |
---|
| 1199 | struct aim_incomingim_ch2_args *args; |
---|
| 1200 | args = va_arg(ap, struct aim_incomingim_ch2_args *); |
---|
| 1201 | ret = incomingim_chan2(sess, fr->conn, userinfo, args); |
---|
| 1202 | } break; |
---|
| 1203 | |
---|
| 1204 | case 4: { /* ICQ */ |
---|
| 1205 | struct aim_incomingim_ch4_args *args; |
---|
| 1206 | args = va_arg(ap, struct aim_incomingim_ch4_args *); |
---|
| 1207 | ret = incomingim_chan4(sess, fr->conn, userinfo, args); |
---|
| 1208 | } break; |
---|
| 1209 | |
---|
| 1210 | default: {; |
---|
| 1211 | } break; |
---|
| 1212 | } |
---|
| 1213 | |
---|
| 1214 | va_end(ap); |
---|
| 1215 | |
---|
| 1216 | return ret; |
---|
| 1217 | } |
---|
| 1218 | |
---|
| 1219 | static int gaim_parse_misses(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1220 | va_list ap; |
---|
| 1221 | guint16 chan, nummissed, reason; |
---|
| 1222 | aim_userinfo_t *userinfo; |
---|
| 1223 | |
---|
| 1224 | va_start(ap, fr); |
---|
| 1225 | chan = (guint16)va_arg(ap, unsigned int); |
---|
| 1226 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1227 | nummissed = (guint16)va_arg(ap, unsigned int); |
---|
| 1228 | reason = (guint16)va_arg(ap, unsigned int); |
---|
| 1229 | va_end(ap); |
---|
| 1230 | |
---|
| 1231 | switch(reason) { |
---|
| 1232 | case 0: |
---|
| 1233 | /* Invalid (0) */ |
---|
[84b045d] | 1234 | imcb_error(sess->aux_data, |
---|
[b7d3cc34] | 1235 | nummissed == 1 ? |
---|
| 1236 | _("You missed %d message from %s because it was invalid.") : |
---|
| 1237 | _("You missed %d messages from %s because they were invalid."), |
---|
| 1238 | nummissed, |
---|
| 1239 | userinfo->sn); |
---|
| 1240 | break; |
---|
| 1241 | case 1: |
---|
| 1242 | /* Message too large */ |
---|
[84b045d] | 1243 | imcb_error(sess->aux_data, |
---|
[b7d3cc34] | 1244 | nummissed == 1 ? |
---|
| 1245 | _("You missed %d message from %s because it was too large.") : |
---|
| 1246 | _("You missed %d messages from %s because they were too large."), |
---|
| 1247 | nummissed, |
---|
| 1248 | userinfo->sn); |
---|
| 1249 | break; |
---|
| 1250 | case 2: |
---|
| 1251 | /* Rate exceeded */ |
---|
[84b045d] | 1252 | imcb_error(sess->aux_data, |
---|
[b7d3cc34] | 1253 | nummissed == 1 ? |
---|
| 1254 | _("You missed %d message from %s because the rate limit has been exceeded.") : |
---|
| 1255 | _("You missed %d messages from %s because the rate limit has been exceeded."), |
---|
| 1256 | nummissed, |
---|
| 1257 | userinfo->sn); |
---|
| 1258 | break; |
---|
| 1259 | case 3: |
---|
| 1260 | /* Evil Sender */ |
---|
[84b045d] | 1261 | imcb_error(sess->aux_data, |
---|
[b7d3cc34] | 1262 | nummissed == 1 ? |
---|
| 1263 | _("You missed %d message from %s because it was too evil.") : |
---|
| 1264 | _("You missed %d messages from %s because they are too evil."), |
---|
| 1265 | nummissed, |
---|
| 1266 | userinfo->sn); |
---|
| 1267 | break; |
---|
| 1268 | case 4: |
---|
| 1269 | /* Evil Receiver */ |
---|
[84b045d] | 1270 | imcb_error(sess->aux_data, |
---|
[b7d3cc34] | 1271 | nummissed == 1 ? |
---|
| 1272 | _("You missed %d message from %s because you are too evil.") : |
---|
| 1273 | _("You missed %d messages from %s because you are too evil."), |
---|
| 1274 | nummissed, |
---|
| 1275 | userinfo->sn); |
---|
| 1276 | break; |
---|
| 1277 | default: |
---|
[84b045d] | 1278 | imcb_error(sess->aux_data, |
---|
[b7d3cc34] | 1279 | nummissed == 1 ? |
---|
| 1280 | _("You missed %d message from %s for unknown reasons.") : |
---|
| 1281 | _("You missed %d messages from %s for unknown reasons."), |
---|
| 1282 | nummissed, |
---|
| 1283 | userinfo->sn); |
---|
| 1284 | break; |
---|
| 1285 | } |
---|
| 1286 | |
---|
| 1287 | return 1; |
---|
| 1288 | } |
---|
| 1289 | |
---|
| 1290 | static int gaim_parse_genericerr(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1291 | va_list ap; |
---|
| 1292 | guint16 reason; |
---|
| 1293 | |
---|
| 1294 | va_start(ap, fr); |
---|
| 1295 | reason = (guint16)va_arg(ap, unsigned int); |
---|
| 1296 | va_end(ap); |
---|
| 1297 | |
---|
[84b045d] | 1298 | imcb_error(sess->aux_data, _("SNAC threw error: %s"), |
---|
[aef4828] | 1299 | reason < msgerrreasonlen ? msgerrreason[reason] : "Unknown error"); |
---|
[b7d3cc34] | 1300 | |
---|
| 1301 | return 1; |
---|
| 1302 | } |
---|
| 1303 | |
---|
| 1304 | static int gaim_parse_msgerr(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1305 | va_list ap; |
---|
| 1306 | char *destn; |
---|
| 1307 | guint16 reason; |
---|
| 1308 | |
---|
| 1309 | va_start(ap, fr); |
---|
| 1310 | reason = (guint16)va_arg(ap, unsigned int); |
---|
| 1311 | destn = va_arg(ap, char *); |
---|
| 1312 | va_end(ap); |
---|
| 1313 | |
---|
[84b045d] | 1314 | imcb_error(sess->aux_data, _("Your message to %s did not get sent: %s"), destn, |
---|
[b7d3cc34] | 1315 | (reason < msgerrreasonlen) ? msgerrreason[reason] : _("Reason unknown")); |
---|
| 1316 | |
---|
| 1317 | return 1; |
---|
| 1318 | } |
---|
| 1319 | |
---|
| 1320 | static int gaim_parse_locerr(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1321 | va_list ap; |
---|
| 1322 | char *destn; |
---|
| 1323 | guint16 reason; |
---|
| 1324 | |
---|
| 1325 | va_start(ap, fr); |
---|
| 1326 | reason = (guint16)va_arg(ap, unsigned int); |
---|
| 1327 | destn = va_arg(ap, char *); |
---|
| 1328 | va_end(ap); |
---|
| 1329 | |
---|
[84b045d] | 1330 | imcb_error(sess->aux_data, _("User information for %s unavailable: %s"), destn, |
---|
[b7d3cc34] | 1331 | (reason < msgerrreasonlen) ? msgerrreason[reason] : _("Reason unknown")); |
---|
| 1332 | |
---|
| 1333 | return 1; |
---|
| 1334 | } |
---|
| 1335 | |
---|
| 1336 | static int gaim_parse_motd(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1337 | char *msg; |
---|
| 1338 | guint16 id; |
---|
| 1339 | va_list ap; |
---|
| 1340 | |
---|
| 1341 | va_start(ap, fr); |
---|
| 1342 | id = (guint16)va_arg(ap, unsigned int); |
---|
| 1343 | msg = va_arg(ap, char *); |
---|
| 1344 | va_end(ap); |
---|
| 1345 | |
---|
| 1346 | if (id < 4) |
---|
[84b045d] | 1347 | imcb_error(sess->aux_data, _("Your connection may be lost.")); |
---|
[b7d3cc34] | 1348 | |
---|
| 1349 | return 1; |
---|
| 1350 | } |
---|
| 1351 | |
---|
| 1352 | static int gaim_chatnav_info(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1353 | va_list ap; |
---|
| 1354 | guint16 type; |
---|
[0da65d5] | 1355 | struct im_connection *ic = sess->aux_data; |
---|
| 1356 | struct oscar_data *odata = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 1357 | |
---|
| 1358 | va_start(ap, fr); |
---|
| 1359 | type = (guint16)va_arg(ap, unsigned int); |
---|
| 1360 | |
---|
| 1361 | switch(type) { |
---|
| 1362 | case 0x0002: { |
---|
| 1363 | guint8 maxrooms; |
---|
| 1364 | struct aim_chat_exchangeinfo *exchanges; |
---|
| 1365 | int exchangecount; // i; |
---|
| 1366 | |
---|
| 1367 | maxrooms = (guint8)va_arg(ap, unsigned int); |
---|
| 1368 | exchangecount = va_arg(ap, int); |
---|
| 1369 | exchanges = va_arg(ap, struct aim_chat_exchangeinfo *); |
---|
| 1370 | va_end(ap); |
---|
| 1371 | |
---|
| 1372 | while (odata->create_rooms) { |
---|
| 1373 | struct create_room *cr = odata->create_rooms->data; |
---|
| 1374 | aim_chatnav_createroom(sess, fr->conn, cr->name, cr->exchange); |
---|
| 1375 | g_free(cr->name); |
---|
| 1376 | odata->create_rooms = g_slist_remove(odata->create_rooms, cr); |
---|
| 1377 | g_free(cr); |
---|
| 1378 | } |
---|
| 1379 | } |
---|
| 1380 | break; |
---|
| 1381 | case 0x0008: { |
---|
| 1382 | char *fqcn, *name, *ck; |
---|
| 1383 | guint16 instance, flags, maxmsglen, maxoccupancy, unknown, exchange; |
---|
| 1384 | guint8 createperms; |
---|
| 1385 | guint32 createtime; |
---|
| 1386 | |
---|
| 1387 | fqcn = va_arg(ap, char *); |
---|
| 1388 | instance = (guint16)va_arg(ap, unsigned int); |
---|
| 1389 | exchange = (guint16)va_arg(ap, unsigned int); |
---|
| 1390 | flags = (guint16)va_arg(ap, unsigned int); |
---|
| 1391 | createtime = va_arg(ap, guint32); |
---|
| 1392 | maxmsglen = (guint16)va_arg(ap, unsigned int); |
---|
| 1393 | maxoccupancy = (guint16)va_arg(ap, unsigned int); |
---|
| 1394 | createperms = (guint8)va_arg(ap, int); |
---|
| 1395 | unknown = (guint16)va_arg(ap, unsigned int); |
---|
| 1396 | name = va_arg(ap, char *); |
---|
| 1397 | ck = va_arg(ap, char *); |
---|
| 1398 | va_end(ap); |
---|
| 1399 | |
---|
| 1400 | aim_chat_join(odata->sess, odata->conn, exchange, ck, instance); |
---|
| 1401 | } |
---|
| 1402 | break; |
---|
| 1403 | default: |
---|
| 1404 | va_end(ap); |
---|
| 1405 | break; |
---|
| 1406 | } |
---|
| 1407 | return 1; |
---|
| 1408 | } |
---|
| 1409 | |
---|
| 1410 | static int gaim_chat_join(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1411 | va_list ap; |
---|
| 1412 | int count, i; |
---|
| 1413 | aim_userinfo_t *info; |
---|
[0da65d5] | 1414 | struct im_connection *g = sess->aux_data; |
---|
[b7d3cc34] | 1415 | |
---|
| 1416 | struct chat_connection *c = NULL; |
---|
| 1417 | |
---|
| 1418 | va_start(ap, fr); |
---|
| 1419 | count = va_arg(ap, int); |
---|
| 1420 | info = va_arg(ap, aim_userinfo_t *); |
---|
| 1421 | va_end(ap); |
---|
| 1422 | |
---|
| 1423 | c = find_oscar_chat_by_conn(g, fr->conn); |
---|
| 1424 | if (!c) |
---|
| 1425 | return 1; |
---|
| 1426 | |
---|
| 1427 | for (i = 0; i < count; i++) |
---|
[424e663] | 1428 | imcb_chat_add_buddy(c->cnv, normalize(info[i].sn)); |
---|
[b7d3cc34] | 1429 | |
---|
| 1430 | return 1; |
---|
| 1431 | } |
---|
| 1432 | |
---|
| 1433 | static int gaim_chat_leave(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1434 | va_list ap; |
---|
| 1435 | int count, i; |
---|
| 1436 | aim_userinfo_t *info; |
---|
[0da65d5] | 1437 | struct im_connection *g = sess->aux_data; |
---|
[b7d3cc34] | 1438 | |
---|
| 1439 | struct chat_connection *c = NULL; |
---|
| 1440 | |
---|
| 1441 | va_start(ap, fr); |
---|
| 1442 | count = va_arg(ap, int); |
---|
| 1443 | info = va_arg(ap, aim_userinfo_t *); |
---|
| 1444 | va_end(ap); |
---|
| 1445 | |
---|
| 1446 | c = find_oscar_chat_by_conn(g, fr->conn); |
---|
| 1447 | if (!c) |
---|
| 1448 | return 1; |
---|
| 1449 | |
---|
| 1450 | for (i = 0; i < count; i++) |
---|
[424e663] | 1451 | imcb_chat_remove_buddy(c->cnv, normalize(info[i].sn), NULL); |
---|
[b7d3cc34] | 1452 | |
---|
| 1453 | return 1; |
---|
| 1454 | } |
---|
| 1455 | |
---|
| 1456 | static int gaim_chat_info_update(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1457 | va_list ap; |
---|
| 1458 | aim_userinfo_t *userinfo; |
---|
| 1459 | struct aim_chat_roominfo *roominfo; |
---|
| 1460 | char *roomname; |
---|
| 1461 | int usercount; |
---|
| 1462 | char *roomdesc; |
---|
| 1463 | guint16 unknown_c9, unknown_d2, unknown_d5, maxmsglen, maxvisiblemsglen; |
---|
| 1464 | guint32 creationtime; |
---|
[0da65d5] | 1465 | struct im_connection *ic = sess->aux_data; |
---|
| 1466 | struct chat_connection *ccon = find_oscar_chat_by_conn(ic, fr->conn); |
---|
[b7d3cc34] | 1467 | |
---|
| 1468 | va_start(ap, fr); |
---|
| 1469 | roominfo = va_arg(ap, struct aim_chat_roominfo *); |
---|
| 1470 | roomname = va_arg(ap, char *); |
---|
| 1471 | usercount= va_arg(ap, int); |
---|
| 1472 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1473 | roomdesc = va_arg(ap, char *); |
---|
| 1474 | unknown_c9 = (guint16)va_arg(ap, int); |
---|
| 1475 | creationtime = (guint32)va_arg(ap, unsigned long); |
---|
| 1476 | maxmsglen = (guint16)va_arg(ap, int); |
---|
| 1477 | unknown_d2 = (guint16)va_arg(ap, int); |
---|
| 1478 | unknown_d5 = (guint16)va_arg(ap, int); |
---|
| 1479 | maxvisiblemsglen = (guint16)va_arg(ap, int); |
---|
| 1480 | va_end(ap); |
---|
| 1481 | |
---|
| 1482 | ccon->maxlen = maxmsglen; |
---|
| 1483 | ccon->maxvis = maxvisiblemsglen; |
---|
| 1484 | |
---|
| 1485 | return 1; |
---|
| 1486 | } |
---|
| 1487 | |
---|
| 1488 | static int gaim_chat_incoming_msg(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1489 | va_list ap; |
---|
| 1490 | aim_userinfo_t *info; |
---|
| 1491 | char *msg; |
---|
[0da65d5] | 1492 | struct im_connection *ic = sess->aux_data; |
---|
| 1493 | struct chat_connection *ccon = find_oscar_chat_by_conn(ic, fr->conn); |
---|
[b7d3cc34] | 1494 | char *tmp; |
---|
| 1495 | |
---|
| 1496 | va_start(ap, fr); |
---|
| 1497 | info = va_arg(ap, aim_userinfo_t *); |
---|
| 1498 | msg = va_arg(ap, char *); |
---|
| 1499 | |
---|
| 1500 | tmp = g_malloc(BUF_LONG); |
---|
| 1501 | g_snprintf(tmp, BUF_LONG, "%s", msg); |
---|
[424e663] | 1502 | imcb_chat_msg(ccon->cnv, normalize(info->sn), tmp, 0, 0); |
---|
[b7d3cc34] | 1503 | g_free(tmp); |
---|
| 1504 | |
---|
| 1505 | return 1; |
---|
| 1506 | } |
---|
| 1507 | |
---|
| 1508 | static int gaim_parse_ratechange(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1509 | #if 0 |
---|
| 1510 | static const char *codes[5] = { |
---|
| 1511 | "invalid", |
---|
| 1512 | "change", |
---|
| 1513 | "warning", |
---|
| 1514 | "limit", |
---|
| 1515 | "limit cleared", |
---|
| 1516 | }; |
---|
| 1517 | #endif |
---|
| 1518 | va_list ap; |
---|
| 1519 | guint16 code, rateclass; |
---|
| 1520 | guint32 windowsize, clear, alert, limit, disconnect, currentavg, maxavg; |
---|
| 1521 | |
---|
| 1522 | va_start(ap, fr); |
---|
| 1523 | code = (guint16)va_arg(ap, unsigned int); |
---|
| 1524 | rateclass= (guint16)va_arg(ap, unsigned int); |
---|
| 1525 | windowsize = (guint32)va_arg(ap, unsigned long); |
---|
| 1526 | clear = (guint32)va_arg(ap, unsigned long); |
---|
| 1527 | alert = (guint32)va_arg(ap, unsigned long); |
---|
| 1528 | limit = (guint32)va_arg(ap, unsigned long); |
---|
| 1529 | disconnect = (guint32)va_arg(ap, unsigned long); |
---|
| 1530 | currentavg = (guint32)va_arg(ap, unsigned long); |
---|
| 1531 | maxavg = (guint32)va_arg(ap, unsigned long); |
---|
| 1532 | va_end(ap); |
---|
| 1533 | |
---|
| 1534 | /* XXX fix these values */ |
---|
| 1535 | if (code == AIM_RATE_CODE_CHANGE) { |
---|
| 1536 | if (currentavg >= clear) |
---|
| 1537 | aim_conn_setlatency(fr->conn, 0); |
---|
| 1538 | } else if (code == AIM_RATE_CODE_WARNING) { |
---|
| 1539 | aim_conn_setlatency(fr->conn, windowsize/4); |
---|
| 1540 | } else if (code == AIM_RATE_CODE_LIMIT) { |
---|
[84b045d] | 1541 | imcb_error(sess->aux_data, _("The last message was not sent because you are over the rate limit. " |
---|
[aef4828] | 1542 | "Please wait 10 seconds and try again.")); |
---|
[b7d3cc34] | 1543 | aim_conn_setlatency(fr->conn, windowsize/2); |
---|
| 1544 | } else if (code == AIM_RATE_CODE_CLEARLIMIT) { |
---|
| 1545 | aim_conn_setlatency(fr->conn, 0); |
---|
| 1546 | } |
---|
| 1547 | |
---|
| 1548 | return 1; |
---|
| 1549 | } |
---|
| 1550 | |
---|
| 1551 | static int gaim_selfinfo(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1552 | va_list ap; |
---|
| 1553 | aim_userinfo_t *info; |
---|
[0da65d5] | 1554 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 1555 | |
---|
| 1556 | va_start(ap, fr); |
---|
| 1557 | info = va_arg(ap, aim_userinfo_t *); |
---|
| 1558 | va_end(ap); |
---|
| 1559 | |
---|
[0da65d5] | 1560 | ic->evil = info->warnlevel/10; |
---|
| 1561 | /* ic->correction_time = (info->onlinesince - ic->login_time); */ |
---|
[b7d3cc34] | 1562 | |
---|
| 1563 | return 1; |
---|
| 1564 | } |
---|
| 1565 | |
---|
| 1566 | static int conninitdone_bos(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1567 | |
---|
| 1568 | aim_reqpersonalinfo(sess, fr->conn); |
---|
| 1569 | aim_bos_reqlocaterights(sess, fr->conn); |
---|
| 1570 | aim_bos_reqbuddyrights(sess, fr->conn); |
---|
| 1571 | |
---|
| 1572 | aim_reqicbmparams(sess); |
---|
| 1573 | |
---|
| 1574 | aim_bos_reqrights(sess, fr->conn); |
---|
| 1575 | aim_bos_setgroupperm(sess, fr->conn, AIM_FLAG_ALLUSERS); |
---|
| 1576 | aim_bos_setprivacyflags(sess, fr->conn, AIM_PRIVFLAGS_ALLOWIDLE | |
---|
| 1577 | AIM_PRIVFLAGS_ALLOWMEMBERSINCE); |
---|
| 1578 | |
---|
| 1579 | return 1; |
---|
| 1580 | } |
---|
| 1581 | |
---|
| 1582 | static int conninitdone_admin(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
[0da65d5] | 1583 | struct im_connection *ic = sess->aux_data; |
---|
| 1584 | struct oscar_data *od = ic->proto_data; |
---|
[b7d3cc34] | 1585 | |
---|
| 1586 | aim_clientready(sess, fr->conn); |
---|
| 1587 | |
---|
| 1588 | if (od->chpass) { |
---|
| 1589 | aim_admin_changepasswd(sess, fr->conn, od->newp, od->oldp); |
---|
| 1590 | g_free(od->oldp); |
---|
| 1591 | od->oldp = NULL; |
---|
| 1592 | g_free(od->newp); |
---|
| 1593 | od->newp = NULL; |
---|
| 1594 | od->chpass = FALSE; |
---|
| 1595 | } |
---|
| 1596 | if (od->setnick) { |
---|
| 1597 | aim_admin_setnick(sess, fr->conn, od->newsn); |
---|
| 1598 | g_free(od->newsn); |
---|
| 1599 | od->newsn = NULL; |
---|
| 1600 | od->setnick = FALSE; |
---|
| 1601 | } |
---|
| 1602 | if (od->conf) { |
---|
| 1603 | aim_admin_reqconfirm(sess, fr->conn); |
---|
| 1604 | od->conf = FALSE; |
---|
| 1605 | } |
---|
| 1606 | if (od->reqemail) { |
---|
| 1607 | aim_admin_getinfo(sess, fr->conn, 0x0011); |
---|
| 1608 | od->reqemail = FALSE; |
---|
| 1609 | } |
---|
| 1610 | if (od->setemail) { |
---|
| 1611 | aim_admin_setemail(sess, fr->conn, od->email); |
---|
| 1612 | g_free(od->email); |
---|
| 1613 | od->setemail = FALSE; |
---|
| 1614 | } |
---|
| 1615 | |
---|
| 1616 | return 1; |
---|
| 1617 | } |
---|
| 1618 | |
---|
| 1619 | static int gaim_icbm_param_info(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1620 | struct aim_icbmparameters *params; |
---|
| 1621 | va_list ap; |
---|
| 1622 | |
---|
| 1623 | va_start(ap, fr); |
---|
| 1624 | params = va_arg(ap, struct aim_icbmparameters *); |
---|
| 1625 | va_end(ap); |
---|
| 1626 | |
---|
| 1627 | /* Maybe senderwarn and recverwarn should be user preferences... */ |
---|
[3e1de87] | 1628 | params->flags = 0x0000000b; |
---|
[b7d3cc34] | 1629 | params->maxmsglen = 8000; |
---|
| 1630 | params->minmsginterval = 0; |
---|
| 1631 | |
---|
| 1632 | aim_seticbmparam(sess, params); |
---|
| 1633 | |
---|
| 1634 | return 1; |
---|
| 1635 | } |
---|
| 1636 | |
---|
| 1637 | static int gaim_parse_locaterights(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1638 | { |
---|
| 1639 | va_list ap; |
---|
| 1640 | guint16 maxsiglen; |
---|
[0da65d5] | 1641 | struct im_connection *ic = sess->aux_data; |
---|
| 1642 | struct oscar_data *odata = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 1643 | |
---|
| 1644 | va_start(ap, fr); |
---|
| 1645 | maxsiglen = va_arg(ap, int); |
---|
| 1646 | va_end(ap); |
---|
| 1647 | |
---|
| 1648 | odata->rights.maxsiglen = odata->rights.maxawaymsglen = (guint)maxsiglen; |
---|
| 1649 | |
---|
[0a3c243] | 1650 | /* FIXME: It seems we're not really using this, and it broke now that |
---|
| 1651 | struct aim_user is dead. |
---|
[0da65d5] | 1652 | aim_bos_setprofile(sess, fr->conn, ic->user->user_info, NULL, gaim_caps); |
---|
[0a3c243] | 1653 | */ |
---|
| 1654 | |
---|
[b7d3cc34] | 1655 | return 1; |
---|
| 1656 | } |
---|
| 1657 | |
---|
| 1658 | static int gaim_parse_buddyrights(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1659 | va_list ap; |
---|
| 1660 | guint16 maxbuddies, maxwatchers; |
---|
[0da65d5] | 1661 | struct im_connection *ic = sess->aux_data; |
---|
| 1662 | struct oscar_data *odata = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 1663 | |
---|
| 1664 | va_start(ap, fr); |
---|
| 1665 | maxbuddies = (guint16)va_arg(ap, unsigned int); |
---|
| 1666 | maxwatchers = (guint16)va_arg(ap, unsigned int); |
---|
| 1667 | va_end(ap); |
---|
| 1668 | |
---|
| 1669 | odata->rights.maxbuddies = (guint)maxbuddies; |
---|
| 1670 | odata->rights.maxwatchers = (guint)maxwatchers; |
---|
| 1671 | |
---|
| 1672 | return 1; |
---|
| 1673 | } |
---|
| 1674 | |
---|
| 1675 | static int gaim_bosrights(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1676 | guint16 maxpermits, maxdenies; |
---|
| 1677 | va_list ap; |
---|
[0da65d5] | 1678 | struct im_connection *ic = sess->aux_data; |
---|
| 1679 | struct oscar_data *odata = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 1680 | |
---|
| 1681 | va_start(ap, fr); |
---|
| 1682 | maxpermits = (guint16)va_arg(ap, unsigned int); |
---|
| 1683 | maxdenies = (guint16)va_arg(ap, unsigned int); |
---|
| 1684 | va_end(ap); |
---|
| 1685 | |
---|
| 1686 | odata->rights.maxpermits = (guint)maxpermits; |
---|
| 1687 | odata->rights.maxdenies = (guint)maxdenies; |
---|
| 1688 | |
---|
| 1689 | aim_clientready(sess, fr->conn); |
---|
| 1690 | |
---|
| 1691 | aim_reqservice(sess, fr->conn, AIM_CONN_TYPE_CHATNAV); |
---|
| 1692 | |
---|
| 1693 | aim_ssi_reqrights(sess, fr->conn); |
---|
| 1694 | aim_ssi_reqalldata(sess, fr->conn); |
---|
| 1695 | |
---|
| 1696 | return 1; |
---|
| 1697 | } |
---|
| 1698 | |
---|
| 1699 | static int gaim_offlinemsg(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1700 | va_list ap; |
---|
| 1701 | struct aim_icq_offlinemsg *msg; |
---|
[0da65d5] | 1702 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 1703 | |
---|
| 1704 | va_start(ap, fr); |
---|
| 1705 | msg = va_arg(ap, struct aim_icq_offlinemsg *); |
---|
| 1706 | va_end(ap); |
---|
| 1707 | |
---|
| 1708 | switch (msg->type) { |
---|
| 1709 | case 0x0001: { /* Basic offline message */ |
---|
| 1710 | char sender[32]; |
---|
| 1711 | char *dialog_msg = g_strdup(msg->msg); |
---|
| 1712 | time_t t = get_time(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0); |
---|
| 1713 | g_snprintf(sender, sizeof(sender), "%u", msg->sender); |
---|
| 1714 | strip_linefeed(dialog_msg); |
---|
[424e663] | 1715 | imcb_buddy_msg(ic, normalize(sender), dialog_msg, 0, t); |
---|
[b7d3cc34] | 1716 | g_free(dialog_msg); |
---|
| 1717 | } break; |
---|
| 1718 | |
---|
| 1719 | case 0x0004: { /* Someone sent you a URL */ |
---|
| 1720 | char sender[32]; |
---|
| 1721 | char *dialog_msg; |
---|
| 1722 | char **m; |
---|
| 1723 | |
---|
| 1724 | time_t t = get_time(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0); |
---|
| 1725 | g_snprintf(sender, sizeof(sender), "%u", msg->sender); |
---|
| 1726 | |
---|
| 1727 | m = g_strsplit(msg->msg, "\376", 2); |
---|
| 1728 | |
---|
| 1729 | if ((strlen(m[0]) != 0)) { |
---|
| 1730 | dialog_msg = g_strjoinv(" -- ", m); |
---|
| 1731 | } else { |
---|
| 1732 | dialog_msg = m[1]; |
---|
| 1733 | } |
---|
| 1734 | |
---|
| 1735 | strip_linefeed(dialog_msg); |
---|
[424e663] | 1736 | imcb_buddy_msg(ic, normalize(sender), dialog_msg, 0, t); |
---|
[b7d3cc34] | 1737 | g_free(dialog_msg); |
---|
| 1738 | g_free(m); |
---|
| 1739 | } break; |
---|
| 1740 | |
---|
| 1741 | case 0x0006: { /* Authorization request */ |
---|
[0da65d5] | 1742 | gaim_icq_authask(ic, msg->sender, msg->msg); |
---|
[b7d3cc34] | 1743 | } break; |
---|
| 1744 | |
---|
| 1745 | case 0x0007: { /* Someone has denied you authorization */ |
---|
[84b045d] | 1746 | imcb_log(sess->aux_data, "The user %u 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.") ); |
---|
[b7d3cc34] | 1747 | } break; |
---|
| 1748 | |
---|
| 1749 | case 0x0008: { /* Someone has granted you authorization */ |
---|
[84b045d] | 1750 | imcb_log(sess->aux_data, "The user %u has granted your request to add them to your contact list for the following reason:\n%s", msg->sender, msg->msg ? msg->msg : _("No reason given.") ); |
---|
[b7d3cc34] | 1751 | } break; |
---|
| 1752 | |
---|
| 1753 | case 0x0012: { |
---|
| 1754 | /* Ack for authorizing/denying someone. Or possibly an ack for sending any system notice */ |
---|
| 1755 | } break; |
---|
| 1756 | |
---|
| 1757 | default: {; |
---|
| 1758 | } |
---|
| 1759 | } |
---|
| 1760 | |
---|
| 1761 | return 1; |
---|
| 1762 | } |
---|
| 1763 | |
---|
| 1764 | static int gaim_offlinemsgdone(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1765 | { |
---|
| 1766 | aim_icq_ackofflinemsgs(sess); |
---|
| 1767 | return 1; |
---|
| 1768 | } |
---|
| 1769 | |
---|
[0da65d5] | 1770 | static void oscar_keepalive(struct im_connection *ic) { |
---|
| 1771 | struct oscar_data *odata = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 1772 | aim_flap_nop(odata->sess, odata->conn); |
---|
| 1773 | } |
---|
| 1774 | |
---|
[f6c963b] | 1775 | static int oscar_buddy_msg(struct im_connection *ic, char *name, char *message, int imflags) { |
---|
[0da65d5] | 1776 | struct oscar_data *odata = (struct oscar_data *)ic->proto_data; |
---|
| 1777 | int ret = 0, len = strlen(message); |
---|
[6bbb939] | 1778 | if (imflags & OPT_AWAY) { |
---|
[b7d3cc34] | 1779 | ret = aim_send_im(odata->sess, name, AIM_IMFLAGS_AWAY, message); |
---|
| 1780 | } else { |
---|
| 1781 | struct aim_sendimext_args args; |
---|
| 1782 | char *s; |
---|
| 1783 | |
---|
| 1784 | args.flags = AIM_IMFLAGS_ACK; |
---|
| 1785 | if (odata->icq) |
---|
| 1786 | args.flags |= AIM_IMFLAGS_OFFLINE; |
---|
| 1787 | for (s = message; *s; s++) |
---|
| 1788 | if (*s & 128) |
---|
| 1789 | break; |
---|
| 1790 | |
---|
| 1791 | /* Message contains high ASCII chars, time for some translation! */ |
---|
| 1792 | if (*s) { |
---|
| 1793 | s = g_malloc(BUF_LONG); |
---|
| 1794 | /* Try if we can put it in an ISO8859-1 string first. |
---|
| 1795 | If we can't, fall back to UTF16. */ |
---|
| 1796 | if ((ret = do_iconv("UTF-8", "ISO8859-1", message, s, len, BUF_LONG)) >= 0) { |
---|
| 1797 | args.flags |= AIM_IMFLAGS_ISO_8859_1; |
---|
| 1798 | len = ret; |
---|
| 1799 | } else if ((ret = do_iconv("UTF-8", "UNICODEBIG", message, s, len, BUF_LONG)) >= 0) { |
---|
| 1800 | args.flags |= AIM_IMFLAGS_UNICODE; |
---|
| 1801 | len = ret; |
---|
| 1802 | } else { |
---|
| 1803 | /* OOF, translation failed... Oh well.. */ |
---|
| 1804 | g_free( s ); |
---|
| 1805 | s = message; |
---|
| 1806 | } |
---|
| 1807 | } else { |
---|
| 1808 | s = message; |
---|
| 1809 | } |
---|
| 1810 | |
---|
| 1811 | args.features = gaim_features; |
---|
| 1812 | args.featureslen = sizeof(gaim_features); |
---|
| 1813 | |
---|
| 1814 | args.destsn = name; |
---|
| 1815 | args.msg = s; |
---|
| 1816 | args.msglen = len; |
---|
| 1817 | |
---|
| 1818 | ret = aim_send_im_ext(odata->sess, &args); |
---|
| 1819 | |
---|
| 1820 | if (s != message) { |
---|
| 1821 | g_free(s); |
---|
| 1822 | } |
---|
| 1823 | } |
---|
| 1824 | if (ret >= 0) |
---|
| 1825 | return 1; |
---|
| 1826 | return ret; |
---|
| 1827 | } |
---|
| 1828 | |
---|
[0da65d5] | 1829 | static void oscar_get_info(struct im_connection *g, char *name) { |
---|
[b7d3cc34] | 1830 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
---|
| 1831 | if (odata->icq) |
---|
| 1832 | aim_icq_getallinfo(odata->sess, name); |
---|
| 1833 | else { |
---|
| 1834 | aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_AWAYMESSAGE); |
---|
| 1835 | aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_GENERALINFO); |
---|
| 1836 | } |
---|
| 1837 | } |
---|
| 1838 | |
---|
[0da65d5] | 1839 | static void oscar_get_away(struct im_connection *g, char *who) { |
---|
[b7d3cc34] | 1840 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
---|
| 1841 | if (odata->icq) { |
---|
[81e04e1] | 1842 | /** FIXME(wilmer): Hmm, lost the ability to get away msgs here, do we care to get that back? |
---|
[f0cb961] | 1843 | struct buddy *budlight = imcb_find_buddy(g, who); |
---|
[b7d3cc34] | 1844 | if (budlight) |
---|
| 1845 | if ((budlight->uc & 0xff80) >> 7) |
---|
| 1846 | if (budlight->caps & AIM_CAPS_ICQSERVERRELAY) |
---|
| 1847 | aim_send_im_ch2_geticqmessage(odata->sess, who, (budlight->uc & 0xff80) >> 7); |
---|
[81e04e1] | 1848 | */ |
---|
[b7d3cc34] | 1849 | } else |
---|
| 1850 | aim_getinfo(odata->sess, odata->conn, who, AIM_GETINFO_AWAYMESSAGE); |
---|
| 1851 | } |
---|
| 1852 | |
---|
[0da65d5] | 1853 | static void oscar_set_away_aim(struct im_connection *ic, struct oscar_data *od, const char *state, const char *message) |
---|
[b7d3cc34] | 1854 | { |
---|
[68198e9] | 1855 | if (state == NULL) |
---|
| 1856 | state = ""; |
---|
[b7d3cc34] | 1857 | |
---|
| 1858 | if (!g_strcasecmp(state, _("Visible"))) { |
---|
| 1859 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_NORMAL); |
---|
| 1860 | return; |
---|
| 1861 | } else if (!g_strcasecmp(state, _("Invisible"))) { |
---|
| 1862 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_INVISIBLE); |
---|
| 1863 | return; |
---|
[17f9522] | 1864 | } else if (message == NULL) { |
---|
| 1865 | message = state; |
---|
| 1866 | } |
---|
[b7d3cc34] | 1867 | |
---|
| 1868 | if (od->rights.maxawaymsglen == 0) |
---|
[84b045d] | 1869 | imcb_error(ic, "oscar_set_away_aim called before locate rights received"); |
---|
[b7d3cc34] | 1870 | |
---|
| 1871 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_NORMAL); |
---|
| 1872 | |
---|
[c0c43fb] | 1873 | g_free(ic->away); |
---|
[0da65d5] | 1874 | ic->away = NULL; |
---|
[b7d3cc34] | 1875 | |
---|
| 1876 | if (!message) { |
---|
| 1877 | aim_bos_setprofile(od->sess, od->conn, NULL, "", gaim_caps); |
---|
| 1878 | return; |
---|
| 1879 | } |
---|
| 1880 | |
---|
| 1881 | if (strlen(message) > od->rights.maxawaymsglen) { |
---|
[84b045d] | 1882 | imcb_error(ic, "Maximum away message length of %d bytes exceeded, truncating", od->rights.maxawaymsglen); |
---|
[b7d3cc34] | 1883 | } |
---|
| 1884 | |
---|
[0da65d5] | 1885 | ic->away = g_strndup(message, od->rights.maxawaymsglen); |
---|
| 1886 | aim_bos_setprofile(od->sess, od->conn, NULL, ic->away, gaim_caps); |
---|
[b7d3cc34] | 1887 | |
---|
| 1888 | return; |
---|
| 1889 | } |
---|
| 1890 | |
---|
[0da65d5] | 1891 | static void oscar_set_away_icq(struct im_connection *ic, struct oscar_data *od, const char *state, const char *message) |
---|
[b7d3cc34] | 1892 | { |
---|
[c0c43fb] | 1893 | const char *msg = NULL; |
---|
[b7d3cc34] | 1894 | gboolean no_message = FALSE; |
---|
| 1895 | |
---|
| 1896 | /* clean old states */ |
---|
[c0c43fb] | 1897 | g_free(ic->away); |
---|
| 1898 | ic->away = NULL; |
---|
[b7d3cc34] | 1899 | od->sess->aim_icq_state = 0; |
---|
| 1900 | |
---|
| 1901 | /* if no message, then use an empty message */ |
---|
[c0c43fb] | 1902 | if (message) { |
---|
| 1903 | msg = message; |
---|
| 1904 | } else { |
---|
| 1905 | msg = ""; |
---|
[b7d3cc34] | 1906 | no_message = TRUE; |
---|
[c0c43fb] | 1907 | } |
---|
[b7d3cc34] | 1908 | |
---|
[68198e9] | 1909 | if (state == NULL) { |
---|
[b7d3cc34] | 1910 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_NORMAL); |
---|
| 1911 | } else if (!g_strcasecmp(state, "Away")) { |
---|
| 1912 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_AWAY); |
---|
[c0c43fb] | 1913 | ic->away = g_strdup(msg); |
---|
[b7d3cc34] | 1914 | od->sess->aim_icq_state = AIM_MTYPE_AUTOAWAY; |
---|
| 1915 | } else if (!g_strcasecmp(state, "Do Not Disturb")) { |
---|
| 1916 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_DND | AIM_ICQ_STATE_BUSY); |
---|
[c0c43fb] | 1917 | ic->away = g_strdup(msg); |
---|
[b7d3cc34] | 1918 | od->sess->aim_icq_state = AIM_MTYPE_AUTODND; |
---|
| 1919 | } else if (!g_strcasecmp(state, "Not Available")) { |
---|
| 1920 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_OUT | AIM_ICQ_STATE_AWAY); |
---|
[c0c43fb] | 1921 | ic->away = g_strdup(msg); |
---|
[b7d3cc34] | 1922 | od->sess->aim_icq_state = AIM_MTYPE_AUTONA; |
---|
| 1923 | } else if (!g_strcasecmp(state, "Occupied")) { |
---|
| 1924 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_BUSY); |
---|
[c0c43fb] | 1925 | ic->away = g_strdup(msg); |
---|
[b7d3cc34] | 1926 | od->sess->aim_icq_state = AIM_MTYPE_AUTOBUSY; |
---|
| 1927 | } else if (!g_strcasecmp(state, "Free For Chat")) { |
---|
| 1928 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_CHAT); |
---|
[c0c43fb] | 1929 | ic->away = g_strdup(msg); |
---|
[b7d3cc34] | 1930 | od->sess->aim_icq_state = AIM_MTYPE_AUTOFFC; |
---|
| 1931 | } else if (!g_strcasecmp(state, "Invisible")) { |
---|
| 1932 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_INVISIBLE); |
---|
[c0c43fb] | 1933 | ic->away = g_strdup(msg); |
---|
[17f9522] | 1934 | } else { |
---|
[b7d3cc34] | 1935 | if (no_message) { |
---|
| 1936 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_NORMAL); |
---|
| 1937 | } else { |
---|
| 1938 | aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_AWAY); |
---|
[c0c43fb] | 1939 | ic->away = g_strdup(msg); |
---|
[b7d3cc34] | 1940 | od->sess->aim_icq_state = AIM_MTYPE_AUTOAWAY; |
---|
| 1941 | } |
---|
| 1942 | } |
---|
| 1943 | |
---|
| 1944 | return; |
---|
| 1945 | } |
---|
| 1946 | |
---|
[0da65d5] | 1947 | static void oscar_set_away(struct im_connection *ic, char *state, char *message) |
---|
[b7d3cc34] | 1948 | { |
---|
[0da65d5] | 1949 | struct oscar_data *od = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 1950 | |
---|
[c0c43fb] | 1951 | oscar_set_away_aim(ic, od, state, message); |
---|
[b7d3cc34] | 1952 | if (od->icq) |
---|
[0da65d5] | 1953 | oscar_set_away_icq(ic, od, state, message); |
---|
[b7d3cc34] | 1954 | |
---|
| 1955 | return; |
---|
| 1956 | } |
---|
| 1957 | |
---|
[0da65d5] | 1958 | static void oscar_add_buddy(struct im_connection *g, char *name, char *group) { |
---|
[b7d3cc34] | 1959 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
---|
[42acba1] | 1960 | bee_user_t *bu; |
---|
| 1961 | |
---|
| 1962 | if (group && (bu = bee_user_by_handle(g->bee, g, name)) && bu->group) |
---|
| 1963 | aim_ssi_movebuddy(odata->sess, odata->conn, bu->group->name, group, name); |
---|
| 1964 | else |
---|
| 1965 | aim_ssi_addbuddies(odata->sess, odata->conn, group ? : OSCAR_GROUP, &name, 1, 0); |
---|
[b7d3cc34] | 1966 | } |
---|
| 1967 | |
---|
[0da65d5] | 1968 | static void oscar_remove_buddy(struct im_connection *g, char *name, char *group) { |
---|
[b7d3cc34] | 1969 | struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
---|
| 1970 | struct aim_ssi_item *ssigroup; |
---|
| 1971 | while ((ssigroup = aim_ssi_itemlist_findparent(odata->sess->ssi.items, name)) && !aim_ssi_delbuddies(odata->sess, odata->conn, ssigroup->name, &name, 1)); |
---|
| 1972 | } |
---|
| 1973 | |
---|
| 1974 | static int gaim_ssi_parserights(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
| 1975 | return 1; |
---|
| 1976 | } |
---|
| 1977 | |
---|
| 1978 | static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { |
---|
[0da65d5] | 1979 | struct im_connection *ic = sess->aux_data; |
---|
[f7d12f7] | 1980 | struct aim_ssi_item *curitem, *curgroup = NULL; |
---|
[b7d3cc34] | 1981 | int tmp; |
---|
[424e663] | 1982 | char *nrm; |
---|
[b7d3cc34] | 1983 | |
---|
| 1984 | /* Add from server list to local list */ |
---|
| 1985 | tmp = 0; |
---|
| 1986 | for (curitem=sess->ssi.items; curitem; curitem=curitem->next) { |
---|
[fab3d2d] | 1987 | nrm = curitem->name ? normalize(curitem->name) : NULL; |
---|
[de82335] | 1988 | |
---|
[b7d3cc34] | 1989 | switch (curitem->type) { |
---|
| 1990 | case 0x0000: /* Buddy */ |
---|
[81e04e1] | 1991 | if ((curitem->name) && (!imcb_buddy_by_handle(ic, nrm))) { |
---|
[b7d3cc34] | 1992 | char *realname = NULL; |
---|
| 1993 | |
---|
| 1994 | if (curitem->data && aim_gettlv(curitem->data, 0x0131, 1)) |
---|
| 1995 | realname = aim_gettlv_str(curitem->data, 0x0131, 1); |
---|
[5a673f3] | 1996 | |
---|
[f7d12f7] | 1997 | imcb_add_buddy(ic, nrm, curgroup ? (curgroup->gid == curitem->gid ? curgroup->name : NULL) : NULL); |
---|
[b7d3cc34] | 1998 | |
---|
[f0cb961] | 1999 | if (realname) { |
---|
[424e663] | 2000 | imcb_buddy_nick_hint(ic, nrm, realname); |
---|
| 2001 | imcb_rename_buddy(ic, nrm, realname); |
---|
[f0cb961] | 2002 | g_free(realname); |
---|
| 2003 | } |
---|
[b7d3cc34] | 2004 | } |
---|
| 2005 | break; |
---|
| 2006 | |
---|
[5a673f3] | 2007 | case 0x0001: /* Group */ |
---|
| 2008 | curgroup = curitem; |
---|
| 2009 | break; |
---|
| 2010 | |
---|
[b7d3cc34] | 2011 | case 0x0002: /* Permit buddy */ |
---|
| 2012 | if (curitem->name) { |
---|
| 2013 | GSList *list; |
---|
[0da65d5] | 2014 | for (list=ic->permit; (list && aim_sncmp(curitem->name, list->data)); list=list->next); |
---|
[b7d3cc34] | 2015 | if (!list) { |
---|
| 2016 | char *name; |
---|
[424e663] | 2017 | name = g_strdup(nrm); |
---|
[0da65d5] | 2018 | ic->permit = g_slist_append(ic->permit, name); |
---|
[b7d3cc34] | 2019 | tmp++; |
---|
| 2020 | } |
---|
| 2021 | } |
---|
| 2022 | break; |
---|
| 2023 | |
---|
| 2024 | case 0x0003: /* Deny buddy */ |
---|
| 2025 | if (curitem->name) { |
---|
| 2026 | GSList *list; |
---|
[0da65d5] | 2027 | for (list=ic->deny; (list && aim_sncmp(curitem->name, list->data)); list=list->next); |
---|
[b7d3cc34] | 2028 | if (!list) { |
---|
| 2029 | char *name; |
---|
[424e663] | 2030 | name = g_strdup(nrm); |
---|
[0da65d5] | 2031 | ic->deny = g_slist_append(ic->deny, name); |
---|
[b7d3cc34] | 2032 | tmp++; |
---|
| 2033 | } |
---|
| 2034 | } |
---|
| 2035 | break; |
---|
| 2036 | |
---|
| 2037 | case 0x0004: /* Permit/deny setting */ |
---|
| 2038 | if (curitem->data) { |
---|
| 2039 | guint8 permdeny; |
---|
[0da65d5] | 2040 | if ((permdeny = aim_ssi_getpermdeny(sess->ssi.items)) && (permdeny != ic->permdeny)) { |
---|
| 2041 | ic->permdeny = permdeny; |
---|
[b7d3cc34] | 2042 | tmp++; |
---|
| 2043 | } |
---|
| 2044 | } |
---|
| 2045 | break; |
---|
| 2046 | |
---|
| 2047 | case 0x0005: /* Presence setting */ |
---|
| 2048 | /* We don't want to change Gaim's setting because it applies to all accounts */ |
---|
| 2049 | break; |
---|
| 2050 | } /* End of switch on curitem->type */ |
---|
| 2051 | } /* End of for loop */ |
---|
| 2052 | |
---|
| 2053 | aim_ssi_enable(sess, fr->conn); |
---|
| 2054 | |
---|
| 2055 | /* Request offline messages, now that the buddy list is complete. */ |
---|
| 2056 | aim_icq_reqofflinemsgs(sess); |
---|
| 2057 | |
---|
| 2058 | /* Now that we have a buddy list, we can tell BitlBee that we're online. */ |
---|
[84b045d] | 2059 | imcb_connected(ic); |
---|
[b7d3cc34] | 2060 | |
---|
| 2061 | return 1; |
---|
| 2062 | } |
---|
| 2063 | |
---|
| 2064 | static int gaim_ssi_parseack( aim_session_t *sess, aim_frame_t *fr, ... ) |
---|
| 2065 | { |
---|
| 2066 | aim_snac_t *origsnac; |
---|
| 2067 | va_list ap; |
---|
| 2068 | |
---|
| 2069 | va_start( ap, fr ); |
---|
| 2070 | origsnac = va_arg( ap, aim_snac_t * ); |
---|
| 2071 | va_end( ap ); |
---|
| 2072 | |
---|
| 2073 | if( origsnac && origsnac->family == AIM_CB_FAM_SSI && origsnac->type == AIM_CB_SSI_ADD && origsnac->data ) |
---|
| 2074 | { |
---|
| 2075 | int i, st, count = aim_bstream_empty( &fr->data ); |
---|
| 2076 | char *list; |
---|
| 2077 | |
---|
| 2078 | if( count & 1 ) |
---|
| 2079 | { |
---|
| 2080 | /* Hmm, the length should be even... */ |
---|
[84b045d] | 2081 | imcb_error( sess->aux_data, "Received SSI ACK package with non-even length"); |
---|
[b7d3cc34] | 2082 | return( 0 ); |
---|
| 2083 | } |
---|
| 2084 | count >>= 1; |
---|
| 2085 | |
---|
| 2086 | list = (char *) origsnac->data; |
---|
| 2087 | for( i = 0; i < count; i ++ ) |
---|
| 2088 | { |
---|
[42acba1] | 2089 | struct aim_ssi_item *ssigroup = aim_ssi_itemlist_findparent( sess->ssi.items, list ); |
---|
| 2090 | char *group = ssigroup ? ssigroup->name : NULL; |
---|
| 2091 | |
---|
[b7d3cc34] | 2092 | st = aimbs_get16( &fr->data ); |
---|
[f0cb961] | 2093 | if( st == 0x00 ) |
---|
| 2094 | { |
---|
[42acba1] | 2095 | imcb_add_buddy( sess->aux_data, normalize(list), group ); |
---|
[f0cb961] | 2096 | } |
---|
| 2097 | else if( st == 0x0E ) |
---|
[b7d3cc34] | 2098 | { |
---|
[84b045d] | 2099 | imcb_log( sess->aux_data, "Buddy %s can't be added without authorization, requesting authorization", list ); |
---|
[b7d3cc34] | 2100 | |
---|
| 2101 | aim_ssi_auth_request( sess, fr->conn, list, "" ); |
---|
| 2102 | aim_ssi_addbuddies( sess, fr->conn, OSCAR_GROUP, &list, 1, 1 ); |
---|
| 2103 | } |
---|
[f0cb961] | 2104 | else |
---|
| 2105 | { |
---|
| 2106 | imcb_error( sess->aux_data, "Error while adding buddy: 0x%04x", st ); |
---|
| 2107 | } |
---|
[b7d3cc34] | 2108 | list += strlen( list ) + 1; |
---|
| 2109 | } |
---|
| 2110 | } |
---|
| 2111 | |
---|
| 2112 | return( 1 ); |
---|
| 2113 | } |
---|
| 2114 | |
---|
[0da65d5] | 2115 | static void oscar_set_permit_deny(struct im_connection *ic) { |
---|
| 2116 | struct oscar_data *od = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 2117 | if (od->icq) { |
---|
| 2118 | GSList *list; |
---|
| 2119 | char buf[MAXMSGLEN]; |
---|
| 2120 | int at; |
---|
| 2121 | |
---|
[0da65d5] | 2122 | switch(ic->permdeny) { |
---|
[b7d3cc34] | 2123 | case 1: |
---|
[c2fb3809] | 2124 | aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_DENYADD, ic->acc->user); |
---|
[b7d3cc34] | 2125 | break; |
---|
| 2126 | case 2: |
---|
[c2fb3809] | 2127 | aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_PERMITADD, ic->acc->user); |
---|
[b7d3cc34] | 2128 | break; |
---|
| 2129 | case 3: |
---|
[0da65d5] | 2130 | list = ic->permit; |
---|
[b7d3cc34] | 2131 | at = 0; |
---|
| 2132 | while (list) { |
---|
| 2133 | at += g_snprintf(buf + at, sizeof(buf) - at, "%s&", (char *)list->data); |
---|
| 2134 | list = list->next; |
---|
| 2135 | } |
---|
| 2136 | aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_PERMITADD, buf); |
---|
| 2137 | break; |
---|
| 2138 | case 4: |
---|
[0da65d5] | 2139 | list = ic->deny; |
---|
[b7d3cc34] | 2140 | at = 0; |
---|
| 2141 | while (list) { |
---|
| 2142 | at += g_snprintf(buf + at, sizeof(buf) - at, "%s&", (char *)list->data); |
---|
| 2143 | list = list->next; |
---|
| 2144 | } |
---|
| 2145 | aim_bos_changevisibility(od->sess, od->conn, AIM_VISIBILITYCHANGE_DENYADD, buf); |
---|
| 2146 | break; |
---|
| 2147 | default: |
---|
| 2148 | break; |
---|
| 2149 | } |
---|
| 2150 | } else { |
---|
| 2151 | if (od->sess->ssi.received_data) |
---|
[0da65d5] | 2152 | aim_ssi_setpermdeny(od->sess, od->conn, ic->permdeny, 0xffffffff); |
---|
[b7d3cc34] | 2153 | } |
---|
| 2154 | } |
---|
| 2155 | |
---|
[0da65d5] | 2156 | static void oscar_add_permit(struct im_connection *ic, char *who) { |
---|
| 2157 | struct oscar_data *od = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 2158 | if (od->icq) { |
---|
| 2159 | aim_ssi_auth_reply(od->sess, od->conn, who, 1, ""); |
---|
| 2160 | } else { |
---|
| 2161 | if (od->sess->ssi.received_data) |
---|
| 2162 | aim_ssi_addpord(od->sess, od->conn, &who, 1, AIM_SSI_TYPE_PERMIT); |
---|
| 2163 | } |
---|
| 2164 | } |
---|
| 2165 | |
---|
[0da65d5] | 2166 | static void oscar_add_deny(struct im_connection *ic, char *who) { |
---|
| 2167 | struct oscar_data *od = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 2168 | if (od->icq) { |
---|
| 2169 | aim_ssi_auth_reply(od->sess, od->conn, who, 0, ""); |
---|
| 2170 | } else { |
---|
| 2171 | if (od->sess->ssi.received_data) |
---|
| 2172 | aim_ssi_addpord(od->sess, od->conn, &who, 1, AIM_SSI_TYPE_DENY); |
---|
| 2173 | } |
---|
| 2174 | } |
---|
| 2175 | |
---|
[0da65d5] | 2176 | static void oscar_rem_permit(struct im_connection *ic, char *who) { |
---|
| 2177 | struct oscar_data *od = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 2178 | if (!od->icq) { |
---|
| 2179 | if (od->sess->ssi.received_data) |
---|
| 2180 | aim_ssi_delpord(od->sess, od->conn, &who, 1, AIM_SSI_TYPE_PERMIT); |
---|
| 2181 | } |
---|
| 2182 | } |
---|
| 2183 | |
---|
[0da65d5] | 2184 | static void oscar_rem_deny(struct im_connection *ic, char *who) { |
---|
| 2185 | struct oscar_data *od = (struct oscar_data *)ic->proto_data; |
---|
[b7d3cc34] | 2186 | if (!od->icq) { |
---|
| 2187 | if (od->sess->ssi.received_data) |
---|
| 2188 | aim_ssi_delpord(od->sess, od->conn, &who, 1, AIM_SSI_TYPE_DENY); |
---|
| 2189 | } |
---|
| 2190 | } |
---|
| 2191 | |
---|
[0da65d5] | 2192 | static GList *oscar_away_states(struct im_connection *ic) |
---|
[b7d3cc34] | 2193 | { |
---|
[0da65d5] | 2194 | struct oscar_data *od = ic->proto_data; |
---|
[b7d3cc34] | 2195 | |
---|
[17f9522] | 2196 | if (od->icq) { |
---|
| 2197 | static GList *m = NULL; |
---|
| 2198 | m = g_list_append(m, "Away"); |
---|
| 2199 | m = g_list_append(m, "Do Not Disturb"); |
---|
| 2200 | m = g_list_append(m, "Not Available"); |
---|
| 2201 | m = g_list_append(m, "Occupied"); |
---|
| 2202 | m = g_list_append(m, "Free For Chat"); |
---|
| 2203 | m = g_list_append(m, "Invisible"); |
---|
| 2204 | return m; |
---|
| 2205 | } else { |
---|
| 2206 | static GList *m = NULL; |
---|
| 2207 | m = g_list_append(m, "Away"); |
---|
| 2208 | return m; |
---|
| 2209 | } |
---|
[b7d3cc34] | 2210 | } |
---|
| 2211 | |
---|
| 2212 | static int gaim_icqinfo(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 2213 | { |
---|
[e64de00] | 2214 | struct im_connection *ic = sess->aux_data; |
---|
| 2215 | struct oscar_data *od = ic->proto_data; |
---|
| 2216 | gchar who[16]; |
---|
| 2217 | GString *str; |
---|
| 2218 | va_list ap; |
---|
| 2219 | struct aim_icq_info *info; |
---|
| 2220 | uint32_t ip; |
---|
| 2221 | |
---|
| 2222 | va_start(ap, fr); |
---|
| 2223 | info = va_arg(ap, struct aim_icq_info *); |
---|
| 2224 | va_end(ap); |
---|
| 2225 | |
---|
| 2226 | if (!info->uin) |
---|
| 2227 | return 0; |
---|
| 2228 | |
---|
| 2229 | str = g_string_sized_new(512); |
---|
| 2230 | g_snprintf(who, sizeof(who), "%u", info->uin); |
---|
| 2231 | |
---|
| 2232 | g_string_printf(str, "%s: %s - %s: %s", _("UIN"), who, _("Nick"), |
---|
| 2233 | info->nick ? info->nick : "-"); |
---|
| 2234 | g_string_append_printf(str, "\n%s: %s", _("First Name"), info->first); |
---|
| 2235 | g_string_append_printf(str, "\n%s: %s", _("Last Name"), info->last); |
---|
| 2236 | g_string_append_printf(str, "\n%s: %s", _("Email Address"), info->email); |
---|
| 2237 | if (info->numaddresses && info->email2) { |
---|
| 2238 | int i; |
---|
| 2239 | for (i = 0; i < info->numaddresses; i++) { |
---|
| 2240 | g_string_append_printf(str, "\n%s: %s", _("Email Address"), info->email2[i]); |
---|
| 2241 | } |
---|
| 2242 | } |
---|
[5588edf5] | 2243 | if (od->ips && (ip = (long) g_hash_table_lookup(od->ips, &info->uin)) != 0) { |
---|
[e64de00] | 2244 | g_string_append_printf(str, "\n%s: %d.%d.%d.%d", _("Last used IP address"), |
---|
| 2245 | (ip >> 24), (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff); |
---|
| 2246 | } |
---|
| 2247 | g_string_append_printf(str, "\n%s: %s", _("Mobile Phone"), info->mobile); |
---|
| 2248 | if (info->gender != 0) |
---|
| 2249 | g_string_append_printf(str, "\n%s: %s", _("Gender"), info->gender==1 ? _("Female") : _("Male")); |
---|
| 2250 | if (info->birthyear || info->birthmonth || info->birthday) { |
---|
| 2251 | char date[30]; |
---|
| 2252 | struct tm tm; |
---|
[613cc55] | 2253 | memset(&tm, 0, sizeof(struct tm)); |
---|
[e64de00] | 2254 | tm.tm_mday = (int)info->birthday; |
---|
| 2255 | tm.tm_mon = (int)info->birthmonth-1; |
---|
| 2256 | tm.tm_year = (int)info->birthyear%100; |
---|
| 2257 | strftime(date, sizeof(date), "%Y-%m-%d", &tm); |
---|
| 2258 | g_string_append_printf(str, "\n%s: %s", _("Birthday"), date); |
---|
| 2259 | } |
---|
| 2260 | if (info->age) { |
---|
| 2261 | char age[5]; |
---|
| 2262 | g_snprintf(age, sizeof(age), "%hhd", info->age); |
---|
| 2263 | g_string_append_printf(str, "\n%s: %s", _("Age"), age); |
---|
| 2264 | } |
---|
| 2265 | g_string_append_printf(str, "\n%s: %s", _("Personal Web Page"), info->personalwebpage); |
---|
| 2266 | if (info->info && info->info[0]) { |
---|
| 2267 | g_string_sprintfa(str, "\n%s:\n%s\n%s", _("Additional Information"), |
---|
| 2268 | info->info, _("End of Additional Information")); |
---|
| 2269 | } |
---|
| 2270 | g_string_append_c(str, '\n'); |
---|
| 2271 | if ((info->homeaddr && (info->homeaddr[0])) || (info->homecity && info->homecity[0]) || (info->homestate && info->homestate[0]) || (info->homezip && info->homezip[0])) { |
---|
| 2272 | g_string_append_printf(str, "%s:", _("Home Address")); |
---|
| 2273 | g_string_append_printf(str, "\n%s: %s", _("Address"), info->homeaddr); |
---|
| 2274 | g_string_append_printf(str, "\n%s: %s", _("City"), info->homecity); |
---|
| 2275 | g_string_append_printf(str, "\n%s: %s", _("State"), info->homestate); |
---|
| 2276 | g_string_append_printf(str, "\n%s: %s", _("Zip Code"), info->homezip); |
---|
| 2277 | g_string_append_c(str, '\n'); |
---|
| 2278 | } |
---|
| 2279 | if ((info->workaddr && info->workaddr[0]) || (info->workcity && info->workcity[0]) || (info->workstate && info->workstate[0]) || (info->workzip && info->workzip[0])) { |
---|
| 2280 | g_string_append_printf(str, "%s:", _("Work Address")); |
---|
| 2281 | g_string_append_printf(str, "\n%s: %s", _("Address"), info->workaddr); |
---|
| 2282 | g_string_append_printf(str, "\n%s: %s", _("City"), info->workcity); |
---|
| 2283 | g_string_append_printf(str, "\n%s: %s", _("State"), info->workstate); |
---|
| 2284 | g_string_append_printf(str, "\n%s: %s", _("Zip Code"), info->workzip); |
---|
| 2285 | g_string_append_c(str, '\n'); |
---|
| 2286 | } |
---|
| 2287 | if ((info->workcompany && info->workcompany[0]) || (info->workdivision && info->workdivision[0]) || (info->workposition && info->workposition[0]) || (info->workwebpage && info->workwebpage[0])) { |
---|
| 2288 | g_string_append_printf(str, "%s:", _("Work Information")); |
---|
| 2289 | g_string_append_printf(str, "\n%s: %s", _("Company"), info->workcompany); |
---|
| 2290 | g_string_append_printf(str, "\n%s: %s", _("Division"), info->workdivision); |
---|
| 2291 | g_string_append_printf(str, "\n%s: %s", _("Position"), info->workposition); |
---|
| 2292 | if (info->workwebpage && info->workwebpage[0]) { |
---|
| 2293 | g_string_append_printf(str, "\n%s: %s", _("Web Page"), info->workwebpage); |
---|
| 2294 | } |
---|
| 2295 | g_string_append_c(str, '\n'); |
---|
| 2296 | } |
---|
| 2297 | |
---|
| 2298 | imcb_log(ic, "%s\n%s", _("User Info"), str->str); |
---|
| 2299 | g_string_free(str, TRUE); |
---|
| 2300 | |
---|
| 2301 | return 1; |
---|
[b7d3cc34] | 2302 | |
---|
| 2303 | } |
---|
| 2304 | |
---|
| 2305 | static char *oscar_encoding_extract(const char *encoding) |
---|
| 2306 | { |
---|
| 2307 | char *ret = NULL; |
---|
| 2308 | char *begin, *end; |
---|
| 2309 | |
---|
| 2310 | g_return_val_if_fail(encoding != NULL, NULL); |
---|
| 2311 | |
---|
| 2312 | /* Make sure encoding begins with charset= */ |
---|
| 2313 | if (strncmp(encoding, "text/plain; charset=", 20) && |
---|
| 2314 | strncmp(encoding, "text/aolrtf; charset=", 21) && |
---|
| 2315 | strncmp(encoding, "text/x-aolrtf; charset=", 23)) |
---|
| 2316 | { |
---|
| 2317 | return NULL; |
---|
| 2318 | } |
---|
| 2319 | |
---|
| 2320 | begin = strchr(encoding, '"'); |
---|
| 2321 | end = strrchr(encoding, '"'); |
---|
| 2322 | |
---|
| 2323 | if ((begin == NULL) || (end == NULL) || (begin >= end)) |
---|
| 2324 | return NULL; |
---|
| 2325 | |
---|
| 2326 | ret = g_strndup(begin+1, (end-1) - begin); |
---|
| 2327 | |
---|
| 2328 | return ret; |
---|
| 2329 | } |
---|
| 2330 | |
---|
| 2331 | static char *oscar_encoding_to_utf8(char *encoding, char *text, int textlen) |
---|
| 2332 | { |
---|
| 2333 | char *utf8 = g_new0(char, 8192); |
---|
| 2334 | |
---|
| 2335 | if ((encoding == NULL) || encoding[0] == '\0') { |
---|
| 2336 | /* gaim_debug_info("oscar", "Empty encoding, assuming UTF-8\n");*/ |
---|
| 2337 | } else if (!g_strcasecmp(encoding, "iso-8859-1")) { |
---|
| 2338 | do_iconv("iso-8859-1", "UTF-8", text, utf8, textlen, 8192); |
---|
| 2339 | } else if (!g_strcasecmp(encoding, "ISO-8859-1-Windows-3.1-Latin-1")) { |
---|
| 2340 | do_iconv("Windows-1252", "UTF-8", text, utf8, textlen, 8192); |
---|
| 2341 | } else if (!g_strcasecmp(encoding, "unicode-2-0")) { |
---|
| 2342 | do_iconv("UCS-2BE", "UTF-8", text, utf8, textlen, 8192); |
---|
| 2343 | } else if (g_strcasecmp(encoding, "us-ascii") && strcmp(encoding, "utf-8")) { |
---|
| 2344 | /* gaim_debug_warning("oscar", "Unrecognized character encoding \"%s\", " |
---|
| 2345 | "attempting to convert to UTF-8 anyway\n", encoding);*/ |
---|
| 2346 | do_iconv(encoding, "UTF-8", text, utf8, textlen, 8192); |
---|
| 2347 | } |
---|
| 2348 | |
---|
| 2349 | /* |
---|
| 2350 | * If utf8 is still NULL then either the encoding is us-ascii/utf-8 or |
---|
| 2351 | * we have been unable to convert the text to utf-8 from the encoding |
---|
| 2352 | * that was specified. So we assume it's UTF-8 and hope for the best. |
---|
| 2353 | */ |
---|
| 2354 | if (*utf8 == 0) { |
---|
| 2355 | strncpy(utf8, text, textlen); |
---|
| 2356 | } |
---|
| 2357 | |
---|
| 2358 | return utf8; |
---|
| 2359 | } |
---|
| 2360 | |
---|
| 2361 | static int gaim_parseaiminfo(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 2362 | { |
---|
[0da65d5] | 2363 | struct im_connection *ic = sess->aux_data; |
---|
[b7d3cc34] | 2364 | va_list ap; |
---|
| 2365 | aim_userinfo_t *userinfo; |
---|
| 2366 | guint16 infotype; |
---|
| 2367 | char *text_encoding = NULL, *text = NULL, *extracted_encoding = NULL; |
---|
| 2368 | guint16 text_length; |
---|
| 2369 | char *utf8 = NULL; |
---|
| 2370 | |
---|
| 2371 | va_start(ap, fr); |
---|
| 2372 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 2373 | infotype = va_arg(ap, int); |
---|
| 2374 | text_encoding = va_arg(ap, char*); |
---|
| 2375 | text = va_arg(ap, char*); |
---|
| 2376 | text_length = va_arg(ap, int); |
---|
| 2377 | va_end(ap); |
---|
| 2378 | |
---|
| 2379 | if(text_encoding) |
---|
| 2380 | extracted_encoding = oscar_encoding_extract(text_encoding); |
---|
| 2381 | if(infotype == AIM_GETINFO_GENERALINFO) { |
---|
| 2382 | /*Display idle time*/ |
---|
| 2383 | char buff[256]; |
---|
| 2384 | struct tm idletime; |
---|
| 2385 | if(userinfo->idletime) { |
---|
| 2386 | memset(&idletime, 0, sizeof(struct tm)); |
---|
| 2387 | idletime.tm_mday = (userinfo->idletime / 60) / 24; |
---|
| 2388 | idletime.tm_hour = (userinfo->idletime / 60) % 24; |
---|
| 2389 | idletime.tm_min = userinfo->idletime % 60; |
---|
| 2390 | idletime.tm_sec = 0; |
---|
| 2391 | strftime(buff, 256, _("%d days %H hours %M minutes"), &idletime); |
---|
[84b045d] | 2392 | imcb_log(ic, "%s: %s", _("Idle Time"), buff); |
---|
[b7d3cc34] | 2393 | } |
---|
| 2394 | |
---|
| 2395 | if(text) { |
---|
| 2396 | utf8 = oscar_encoding_to_utf8(extracted_encoding, text, text_length); |
---|
[84b045d] | 2397 | imcb_log(ic, "%s\n%s", _("User Info"), utf8); |
---|
[b7d3cc34] | 2398 | } else { |
---|
[84b045d] | 2399 | imcb_log(ic, _("No user info available.")); |
---|
[b7d3cc34] | 2400 | } |
---|
| 2401 | } else if(infotype == AIM_GETINFO_AWAYMESSAGE && userinfo->flags & AIM_FLAG_AWAY) { |
---|
| 2402 | utf8 = oscar_encoding_to_utf8(extracted_encoding, text, text_length); |
---|
[84b045d] | 2403 | imcb_log(ic, "%s\n%s", _("Away Message"), utf8); |
---|
[b7d3cc34] | 2404 | } |
---|
| 2405 | |
---|
| 2406 | g_free(utf8); |
---|
| 2407 | |
---|
| 2408 | return 1; |
---|
| 2409 | } |
---|
| 2410 | |
---|
[3e1de87] | 2411 | int gaim_parsemtn(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 2412 | { |
---|
[0da65d5] | 2413 | struct im_connection * ic = sess->aux_data; |
---|
[3e1de87] | 2414 | va_list ap; |
---|
| 2415 | guint16 type1, type2; |
---|
| 2416 | char * sn; |
---|
| 2417 | |
---|
| 2418 | va_start(ap, fr); |
---|
| 2419 | type1 = va_arg(ap, int); |
---|
| 2420 | sn = va_arg(ap, char*); |
---|
| 2421 | type2 = va_arg(ap, int); |
---|
| 2422 | va_end(ap); |
---|
[e7f46c5] | 2423 | |
---|
| 2424 | if(type2 == 0x0002) { |
---|
| 2425 | /* User is typing */ |
---|
[424e663] | 2426 | imcb_buddy_typing(ic, normalize(sn), OPT_TYPING); |
---|
[e7f46c5] | 2427 | } |
---|
| 2428 | else if (type2 == 0x0001) { |
---|
| 2429 | /* User has typed something, but is not actively typing (stale) */ |
---|
[424e663] | 2430 | imcb_buddy_typing(ic, normalize(sn), OPT_THINKING); |
---|
[e7f46c5] | 2431 | } |
---|
| 2432 | else { |
---|
| 2433 | /* User has stopped typing */ |
---|
[424e663] | 2434 | imcb_buddy_typing(ic, normalize(sn), 0); |
---|
[e64de00] | 2435 | } |
---|
[e7f46c5] | 2436 | |
---|
[3e1de87] | 2437 | return 1; |
---|
| 2438 | } |
---|
| 2439 | |
---|
[0da65d5] | 2440 | int oscar_send_typing(struct im_connection *ic, char * who, int typing) |
---|
[3e1de87] | 2441 | { |
---|
[0da65d5] | 2442 | struct oscar_data *od = ic->proto_data; |
---|
[df1fb67] | 2443 | return( aim_im_sendmtn(od->sess, 1, who, (typing & OPT_TYPING) ? 0x0002 : 0x0000) ); |
---|
[3e1de87] | 2444 | } |
---|
| 2445 | |
---|
[f6c963b] | 2446 | void oscar_chat_msg(struct groupchat *c, char *message, int msgflags) |
---|
[b8ef1b1] | 2447 | { |
---|
[0da65d5] | 2448 | struct im_connection *ic = c->ic; |
---|
| 2449 | struct oscar_data * od = (struct oscar_data*)ic->proto_data; |
---|
[b8ef1b1] | 2450 | struct chat_connection * ccon; |
---|
| 2451 | int ret; |
---|
| 2452 | guint8 len = strlen(message); |
---|
[73cf7fd] | 2453 | guint16 flags; |
---|
[b8ef1b1] | 2454 | char *s; |
---|
[11e090b] | 2455 | |
---|
[e437366] | 2456 | if (!(ccon = c->data)) |
---|
| 2457 | return; |
---|
[b8ef1b1] | 2458 | |
---|
| 2459 | for (s = message; *s; s++) |
---|
| 2460 | if (*s & 128) |
---|
| 2461 | break; |
---|
[73cf7fd] | 2462 | |
---|
| 2463 | flags = AIM_CHATFLAGS_NOREFLECT; |
---|
| 2464 | |
---|
[b8ef1b1] | 2465 | /* Message contains high ASCII chars, time for some translation! */ |
---|
| 2466 | if (*s) { |
---|
| 2467 | s = g_malloc(BUF_LONG); |
---|
| 2468 | /* Try if we can put it in an ISO8859-1 string first. |
---|
| 2469 | If we can't, fall back to UTF16. */ |
---|
| 2470 | if ((ret = do_iconv("UTF-8", "ISO8859-1", message, s, len, BUF_LONG)) >= 0) { |
---|
[73cf7fd] | 2471 | flags |= AIM_CHATFLAGS_ISO_8859_1; |
---|
[b8ef1b1] | 2472 | len = ret; |
---|
| 2473 | } else if ((ret = do_iconv("UTF-8", "UNICODEBIG", message, s, len, BUF_LONG)) >= 0) { |
---|
[73cf7fd] | 2474 | flags |= AIM_CHATFLAGS_UNICODE; |
---|
[b8ef1b1] | 2475 | len = ret; |
---|
| 2476 | } else { |
---|
| 2477 | /* OOF, translation failed... Oh well.. */ |
---|
| 2478 | g_free( s ); |
---|
| 2479 | s = message; |
---|
| 2480 | } |
---|
| 2481 | } else { |
---|
| 2482 | s = message; |
---|
| 2483 | } |
---|
| 2484 | |
---|
[73cf7fd] | 2485 | ret = aim_chat_send_im(od->sess, ccon->conn, flags, s, len); |
---|
[b8ef1b1] | 2486 | |
---|
| 2487 | if (s != message) { |
---|
| 2488 | g_free(s); |
---|
| 2489 | } |
---|
| 2490 | |
---|
[0da65d5] | 2491 | /* return (ret >= 0); */ |
---|
[b8ef1b1] | 2492 | } |
---|
| 2493 | |
---|
[c058ff9] | 2494 | void oscar_chat_invite(struct groupchat *c, char *who, char *message) |
---|
[b8ef1b1] | 2495 | { |
---|
[0da65d5] | 2496 | struct im_connection *ic = c->ic; |
---|
| 2497 | struct oscar_data * od = (struct oscar_data *)ic->proto_data; |
---|
[e437366] | 2498 | struct chat_connection *ccon; |
---|
| 2499 | |
---|
| 2500 | if (!(ccon = c->data)) |
---|
| 2501 | return; |
---|
[b8ef1b1] | 2502 | |
---|
| 2503 | aim_chat_invite(od->sess, od->conn, who, message ? message : "", |
---|
| 2504 | ccon->exchange, ccon->name, 0x0); |
---|
| 2505 | } |
---|
| 2506 | |
---|
[0da65d5] | 2507 | void oscar_chat_kill(struct im_connection *ic, struct chat_connection *cc) |
---|
[b8ef1b1] | 2508 | { |
---|
[0da65d5] | 2509 | struct oscar_data *od = (struct oscar_data *)ic->proto_data; |
---|
[b8ef1b1] | 2510 | |
---|
| 2511 | /* Notify the conversation window that we've left the chat */ |
---|
[e35d1a1] | 2512 | imcb_chat_free(cc->cnv); |
---|
[b8ef1b1] | 2513 | |
---|
| 2514 | /* Destroy the chat_connection */ |
---|
| 2515 | od->oscar_chats = g_slist_remove(od->oscar_chats, cc); |
---|
| 2516 | if (cc->inpa > 0) |
---|
[ba9edaa] | 2517 | b_event_remove(cc->inpa); |
---|
[b8ef1b1] | 2518 | aim_conn_kill(od->sess, &cc->conn); |
---|
| 2519 | g_free(cc->name); |
---|
| 2520 | g_free(cc->show); |
---|
| 2521 | g_free(cc); |
---|
| 2522 | } |
---|
| 2523 | |
---|
[0da65d5] | 2524 | void oscar_chat_leave(struct groupchat *c) |
---|
[b8ef1b1] | 2525 | { |
---|
[e437366] | 2526 | if (!c->data) |
---|
| 2527 | return; |
---|
[0da65d5] | 2528 | oscar_chat_kill(c->ic, c->data); |
---|
[b8ef1b1] | 2529 | } |
---|
| 2530 | |
---|
[03f3828] | 2531 | struct groupchat *oscar_chat_join_internal(struct im_connection *ic, const char *room, |
---|
| 2532 | const char *nick, const char *password, int exchange_number) |
---|
[b8ef1b1] | 2533 | { |
---|
[0da65d5] | 2534 | struct oscar_data * od = (struct oscar_data *)ic->proto_data; |
---|
[7989d40d] | 2535 | struct groupchat *ret = imcb_chat_new(ic, room); |
---|
[b8ef1b1] | 2536 | aim_conn_t * cur; |
---|
| 2537 | |
---|
| 2538 | if((cur = aim_getconn_type(od->sess, AIM_CONN_TYPE_CHATNAV))) { |
---|
[c737ba7] | 2539 | int st; |
---|
| 2540 | |
---|
[03f3828] | 2541 | st = aim_chatnav_createroom(od->sess, cur, room, exchange_number); |
---|
[c737ba7] | 2542 | |
---|
[7989d40d] | 2543 | return ret; |
---|
[b8ef1b1] | 2544 | } else { |
---|
| 2545 | struct create_room * cr = g_new0(struct create_room, 1); |
---|
[c737ba7] | 2546 | |
---|
[03f3828] | 2547 | cr->exchange = exchange_number; |
---|
[c737ba7] | 2548 | cr->name = g_strdup(room); |
---|
[b8ef1b1] | 2549 | od->create_rooms = g_slist_append(od->create_rooms, cr); |
---|
| 2550 | aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_CHATNAV); |
---|
[c737ba7] | 2551 | |
---|
[7989d40d] | 2552 | return ret; |
---|
[b8ef1b1] | 2553 | } |
---|
| 2554 | } |
---|
| 2555 | |
---|
[03f3828] | 2556 | struct groupchat *oscar_chat_join(struct im_connection *ic, const char *room, |
---|
| 2557 | const char *nick, const char *password, set_t **sets) |
---|
| 2558 | { |
---|
| 2559 | return oscar_chat_join_internal(ic, room, nick, password, set_getint(sets, "exchange_number")); |
---|
| 2560 | } |
---|
| 2561 | |
---|
[0da65d5] | 2562 | struct groupchat *oscar_chat_with(struct im_connection * ic, char *who) |
---|
[b8ef1b1] | 2563 | { |
---|
[0da65d5] | 2564 | struct oscar_data * od = (struct oscar_data *)ic->proto_data; |
---|
[c737ba7] | 2565 | struct groupchat *ret; |
---|
[b8ef1b1] | 2566 | static int chat_id = 0; |
---|
[e437366] | 2567 | char * chatname, *s; |
---|
[75610c3] | 2568 | struct groupchat *c; |
---|
[11e090b] | 2569 | |
---|
[ef14a83] | 2570 | chatname = g_strdup_printf("%s%s%d", isdigit(*ic->acc->user) ? "icq" : "", |
---|
[75610c3] | 2571 | ic->acc->user, chat_id++); |
---|
| 2572 | |
---|
[e437366] | 2573 | for (s = chatname; *s; s ++) |
---|
| 2574 | if (!isalnum(*s)) |
---|
| 2575 | *s = '0'; |
---|
| 2576 | |
---|
[75610c3] | 2577 | c = imcb_chat_new(ic, chatname); |
---|
[03f3828] | 2578 | ret = oscar_chat_join_internal(ic, chatname, NULL, NULL, 4); |
---|
[b8ef1b1] | 2579 | aim_chat_invite(od->sess, od->conn, who, "", 4, chatname, 0x0); |
---|
| 2580 | |
---|
| 2581 | g_free(chatname); |
---|
| 2582 | |
---|
[fa29d093] | 2583 | return NULL; |
---|
[b8ef1b1] | 2584 | } |
---|
| 2585 | |
---|
[9143aeb] | 2586 | void oscar_accept_chat(void *data) |
---|
[b8ef1b1] | 2587 | { |
---|
[9143aeb] | 2588 | struct aim_chat_invitation * inv = data; |
---|
| 2589 | |
---|
[03f3828] | 2590 | oscar_chat_join_internal(inv->ic, inv->name, NULL, NULL, 4); |
---|
[b8ef1b1] | 2591 | g_free(inv->name); |
---|
| 2592 | g_free(inv); |
---|
| 2593 | } |
---|
| 2594 | |
---|
[9143aeb] | 2595 | void oscar_reject_chat(void *data) |
---|
[b8ef1b1] | 2596 | { |
---|
[9143aeb] | 2597 | struct aim_chat_invitation * inv = data; |
---|
| 2598 | |
---|
[b8ef1b1] | 2599 | g_free(inv->name); |
---|
| 2600 | g_free(inv); |
---|
| 2601 | } |
---|
| 2602 | |
---|
[03f3828] | 2603 | void oscar_chat_add_settings(account_t *acc, set_t **head) |
---|
| 2604 | { |
---|
| 2605 | set_add(head, "exchange_number", "4", set_eval_int, NULL); |
---|
| 2606 | } |
---|
| 2607 | |
---|
| 2608 | void oscar_chat_free_settings(account_t *acc, set_t **head) |
---|
| 2609 | { |
---|
| 2610 | set_del(head, "exchange_number"); |
---|
| 2611 | } |
---|
| 2612 | |
---|
[0da65d5] | 2613 | void oscar_initmodule() |
---|
[7b23afd] | 2614 | { |
---|
| 2615 | struct prpl *ret = g_new0(struct prpl, 1); |
---|
| 2616 | ret->name = "oscar"; |
---|
[5a71d9c] | 2617 | ret->mms = 2343; /* this guess taken from libotr UPGRADING file */ |
---|
[b7d3cc34] | 2618 | ret->away_states = oscar_away_states; |
---|
[0da65d5] | 2619 | ret->init = oscar_init; |
---|
[b7d3cc34] | 2620 | ret->login = oscar_login; |
---|
[0da65d5] | 2621 | ret->keepalive = oscar_keepalive; |
---|
| 2622 | ret->logout = oscar_logout; |
---|
[f6c963b] | 2623 | ret->buddy_msg = oscar_buddy_msg; |
---|
[b7d3cc34] | 2624 | ret->get_info = oscar_get_info; |
---|
| 2625 | ret->set_away = oscar_set_away; |
---|
| 2626 | ret->get_away = oscar_get_away; |
---|
| 2627 | ret->add_buddy = oscar_add_buddy; |
---|
| 2628 | ret->remove_buddy = oscar_remove_buddy; |
---|
[f6c963b] | 2629 | ret->chat_msg = oscar_chat_msg; |
---|
[b8ef1b1] | 2630 | ret->chat_invite = oscar_chat_invite; |
---|
| 2631 | ret->chat_leave = oscar_chat_leave; |
---|
[0da65d5] | 2632 | ret->chat_with = oscar_chat_with; |
---|
[c737ba7] | 2633 | ret->chat_join = oscar_chat_join; |
---|
[03f3828] | 2634 | ret->chat_add_settings = oscar_chat_add_settings; |
---|
| 2635 | ret->chat_free_settings = oscar_chat_free_settings; |
---|
[b7d3cc34] | 2636 | ret->add_permit = oscar_add_permit; |
---|
| 2637 | ret->add_deny = oscar_add_deny; |
---|
| 2638 | ret->rem_permit = oscar_rem_permit; |
---|
| 2639 | ret->rem_deny = oscar_rem_deny; |
---|
| 2640 | ret->set_permit_deny = oscar_set_permit_deny; |
---|
[3e1de87] | 2641 | ret->send_typing = oscar_send_typing; |
---|
[5b52a48] | 2642 | |
---|
| 2643 | ret->handle_cmp = aim_sncmp; |
---|
[3e1de87] | 2644 | |
---|
[7b23afd] | 2645 | register_protocol(ret); |
---|
[b7d3cc34] | 2646 | } |
---|