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