[d09e5a1] | 1 | #include <stdio.h> |
---|
| 2 | #include <stdio.h> |
---|
| 3 | #include <sys/stat.h> |
---|
| 4 | #include "owl.h" |
---|
| 5 | |
---|
| 6 | /**********************************************************************/ |
---|
| 7 | |
---|
| 8 | struct owlfaim_priv { |
---|
| 9 | char *screenname; |
---|
| 10 | char *password; |
---|
| 11 | char *server; |
---|
| 12 | int connected; |
---|
| 13 | }; |
---|
| 14 | |
---|
[e19eb97] | 15 | static const char *msgerrreasons[] = { |
---|
[d09e5a1] | 16 | "Invalid error", |
---|
| 17 | "Invalid SNAC", |
---|
| 18 | "Rate to host", |
---|
| 19 | "Rate to client", |
---|
| 20 | "Not logged on", |
---|
| 21 | "Service unavailable", |
---|
| 22 | "Service not defined", |
---|
| 23 | "Obsolete SNAC", |
---|
| 24 | "Not supported by host", |
---|
| 25 | "Not supported by client", |
---|
| 26 | "Refused by client", |
---|
| 27 | "Reply too big", |
---|
| 28 | "Responses lost", |
---|
| 29 | "Request denied", |
---|
| 30 | "Busted SNAC payload", |
---|
| 31 | "Insufficient rights", |
---|
| 32 | "In local permit/deny", |
---|
| 33 | "Too evil (sender)", |
---|
| 34 | "Too evil (receiver)", |
---|
| 35 | "User temporarily unavailable", |
---|
| 36 | "No match", |
---|
| 37 | "List overflow", |
---|
| 38 | "Request ambiguous", |
---|
| 39 | "Queue full", |
---|
| 40 | "Not while on AOL", |
---|
| 41 | }; |
---|
| 42 | static int msgerrreasonslen = 25; |
---|
| 43 | |
---|
| 44 | static void faimtest_debugcb(aim_session_t *sess, int level, const char *format, va_list va); |
---|
| 45 | static int faimtest_parse_login(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 46 | static int faimtest_parse_authresp(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 47 | int faimtest_flapversion(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 48 | int faimtest_conncomplete(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 49 | void addcb_bos(aim_session_t *sess, aim_conn_t *bosconn); |
---|
| 50 | static int conninitdone_bos(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 51 | static int conninitdone_admin(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
[2674412] | 52 | static int conninitdone_chat (aim_session_t *, aim_frame_t *, ...); |
---|
[d09e5a1] | 53 | int logout(aim_session_t *sess); |
---|
| 54 | |
---|
| 55 | static int faimtest_parse_connerr(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 56 | static int faimtest_accountconfirm(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 57 | static int faimtest_infochange(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 58 | static int faimtest_handleredirect(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 59 | static int faimtest_icbmparaminfo(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 60 | static int faimtest_parse_buddyrights(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 61 | static int faimtest_bosrights(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 62 | static int faimtest_locrights(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 63 | static int faimtest_reportinterval(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
[f4d0975] | 64 | /* static int reportinterval(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs); */ |
---|
[d09e5a1] | 65 | static int faimtest_parse_motd(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
[8c46404] | 66 | /* static void printuserflags(fu16_t flags); */ |
---|
[d09e5a1] | 67 | static int faimtest_parse_userinfo(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 68 | static int faimtest_parse_incoming_im_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch1_args *args); |
---|
| 69 | static int faimtest_parse_incoming_im_chan2(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args); |
---|
| 70 | static int faimtest_parse_incoming_im(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 71 | static int faimtest_parse_oncoming(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 72 | static int faimtest_parse_offgoing(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 73 | int faimtest_parse_genericerr(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 74 | static int faimtest_parse_msgerr(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 75 | static int faimtest_parse_locerr(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 76 | static int faimtest_parse_misses(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 77 | static int faimtest_parse_msgack(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 78 | static int faimtest_parse_ratechange(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 79 | static int faimtest_parse_evilnotify(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 80 | static int faimtest_parse_searchreply(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 81 | static int faimtest_parse_searcherror(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 82 | static int handlepopup(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 83 | static int serverpause(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 84 | static int migrate(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 85 | static int ssirights(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 86 | static int ssidata(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 87 | static int ssidatanochange(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 88 | static int offlinemsg(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
| 89 | static int offlinemsgdone(aim_session_t *sess, aim_frame_t *fr, ...); |
---|
[cdf0ef1] | 90 | /* |
---|
[8c46404] | 91 | static int faimtest_ssi_parseerr (aim_session_t *, aim_frame_t *, ...); |
---|
| 92 | static int faimtest_ssi_parserights (aim_session_t *, aim_frame_t *, ...); |
---|
| 93 | static int faimtest_ssi_parselist (aim_session_t *, aim_frame_t *, ...); |
---|
| 94 | static int faimtest_ssi_parseack (aim_session_t *, aim_frame_t *, ...); |
---|
| 95 | static int faimtest_ssi_authgiven (aim_session_t *, aim_frame_t *, ...); |
---|
| 96 | static int faimtest_ssi_authrequest (aim_session_t *, aim_frame_t *, ...); |
---|
| 97 | static int faimtest_ssi_authreply (aim_session_t *, aim_frame_t *, ...); |
---|
| 98 | static int faimtest_ssi_gotadded (aim_session_t *, aim_frame_t *, ...); |
---|
[cdf0ef1] | 99 | */ |
---|
[8c46404] | 100 | |
---|
[d09e5a1] | 101 | void chatnav_redirect(aim_session_t *sess, struct aim_redirect_data *redir); |
---|
| 102 | void chat_redirect(aim_session_t *sess, struct aim_redirect_data *redir); |
---|
| 103 | |
---|
| 104 | /*****************************************************************/ |
---|
| 105 | |
---|
| 106 | void owl_aim_init(void) |
---|
| 107 | { |
---|
[2674412] | 108 | /* this has all been moved to owl_aim_login, but we'll leave the |
---|
| 109 | * function here, in case there's stuff we want to init in the |
---|
| 110 | * future. It's still called by Owl. |
---|
| 111 | */ |
---|
| 112 | |
---|
[d09e5a1] | 113 | } |
---|
| 114 | |
---|
[6b0b4f4] | 115 | gboolean owl_aim_send_nop(gpointer data) { |
---|
| 116 | owl_global *g = data; |
---|
| 117 | if (owl_global_is_doaimevents(g)) { |
---|
| 118 | aim_session_t *sess = owl_global_get_aimsess(g); |
---|
| 119 | aim_flap_nop(sess, aim_getconn_type(sess, AIM_CONN_TYPE_BOS)); |
---|
| 120 | } |
---|
| 121 | return TRUE; |
---|
[b7bb454] | 122 | } |
---|
| 123 | |
---|
[f4d0975] | 124 | |
---|
[e19eb97] | 125 | int owl_aim_login(const char *screenname, const char *password) |
---|
[d09e5a1] | 126 | { |
---|
| 127 | struct owlfaim_priv *priv; |
---|
[8c46404] | 128 | aim_conn_t *conn; |
---|
| 129 | aim_session_t *sess; |
---|
[d09e5a1] | 130 | |
---|
[8c46404] | 131 | sess=owl_global_get_aimsess(&g); |
---|
| 132 | |
---|
| 133 | aim_session_init(sess, TRUE, 0); |
---|
| 134 | aim_setdebuggingcb(sess, faimtest_debugcb); |
---|
| 135 | aim_tx_setenqueue(sess, AIM_TX_IMMEDIATE, NULL); |
---|
| 136 | |
---|
[d09e5a1] | 137 | /* this will leak, I know and just don't care right now */ |
---|
[96828e4] | 138 | priv=g_new0(struct owlfaim_priv, 1); |
---|
[d09e5a1] | 139 | |
---|
[d4927a7] | 140 | priv->screenname = g_strdup(screenname); |
---|
| 141 | priv->password = g_strdup(password); |
---|
| 142 | priv->server = g_strdup(FAIM_LOGIN_SERVER); |
---|
[8c46404] | 143 | sess->aux_data = priv; |
---|
[f4d0975] | 144 | |
---|
[8c46404] | 145 | conn=aim_newconn(sess, AIM_CONN_TYPE_AUTH, priv->server ? priv->server : FAIM_LOGIN_SERVER); |
---|
| 146 | /* conn=aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL); */ |
---|
| 147 | if (!conn) { |
---|
| 148 | owl_function_error("owl_aim_login: connection error during AIM login\n"); |
---|
| 149 | owl_global_set_aimnologgedin(&g); |
---|
| 150 | owl_global_set_no_doaimevents(&g); |
---|
| 151 | return (-1); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /* |
---|
| 155 | else if (conn->fd == -1) { |
---|
| 156 | if (conn->status & AIM_CONN_STATUS_RESOLVERR) { |
---|
| 157 | owl_function_error("owl_aim_login: could not resolve authorize name"); |
---|
| 158 | } else if (conn->status & AIM_CONN_STATUS_CONNERR) { |
---|
| 159 | owl_function_error("owl_aim_login: could not connect to authorizer"); |
---|
| 160 | } else { |
---|
| 161 | owl_function_error("owl_aim_login: unknown connection error"); |
---|
| 162 | } |
---|
[d09e5a1] | 163 | owl_global_set_aimnologgedin(&g); |
---|
[a352335c] | 164 | owl_global_set_no_doaimevents(&g); |
---|
[8c46404] | 165 | aim_conn_kill(sess, &conn); |
---|
[d09e5a1] | 166 | return(-1); |
---|
| 167 | } |
---|
[8c46404] | 168 | */ |
---|
[a0a5179] | 169 | |
---|
[8c46404] | 170 | |
---|
| 171 | aim_conn_addhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, faimtest_flapversion, 0); |
---|
| 172 | aim_conn_addhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0); |
---|
| 173 | |
---|
| 174 | aim_conn_addhandler(sess, conn, AIM_CB_FAM_ATH, AIM_CB_ATH_AUTHRESPONSE, faimtest_parse_login, 0); |
---|
| 175 | aim_conn_addhandler(sess, conn, AIM_CB_FAM_ATH, AIM_CB_ATH_LOGINRESPONSE, faimtest_parse_authresp, 0); |
---|
| 176 | /* aim_conn_addhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, gaim_connerr, 0); */ |
---|
| 177 | /* aim_conn_addhandler(sess, conn, 0x0017, 0x0007, gaim_parse_login, 0); */ |
---|
| 178 | /* aim_conn_addhandler(sess, conn, 0x0017, 0x0003, gaim_parse_auth_resp, 0); */ |
---|
| 179 | |
---|
[a0a5179] | 180 | /* start processing AIM events */ |
---|
[a352335c] | 181 | owl_global_set_doaimevents(&g); |
---|
[8c46404] | 182 | /* conn->status |= AIM_CONN_STATUS_INPROGRESS; */ |
---|
| 183 | owl_function_debugmsg("owl_aim_login: sending login request for %s", screenname); |
---|
| 184 | aim_request_login(sess, conn, screenname); |
---|
| 185 | owl_function_debugmsg("owl_aim_login: connecting"); |
---|
[c15bbfb] | 186 | |
---|
[6b0b4f4] | 187 | g.aim_nop_timer = g_timeout_add_seconds(30, owl_aim_send_nop, &g); |
---|
[b7bb454] | 188 | |
---|
[a352335c] | 189 | return(0); |
---|
| 190 | } |
---|
| 191 | |
---|
[6b0b4f4] | 192 | static gboolean owl_aim_unset_ignorelogin(void *data) |
---|
[e9c6fc8] | 193 | { |
---|
[6b0b4f4] | 194 | owl_global *g = data; |
---|
| 195 | owl_global_unset_ignore_aimlogin(g); |
---|
| 196 | return FALSE; /* only run once. */ |
---|
[b7bb454] | 197 | } |
---|
| 198 | |
---|
[a352335c] | 199 | /* stuff to run once login has been successful */ |
---|
[e19eb97] | 200 | void owl_aim_successful_login(const char *screenname) |
---|
[a352335c] | 201 | { |
---|
[1db061d] | 202 | char *buff; |
---|
[8c92848] | 203 | owl_function_debugmsg("doing owl_aim_successful_login"); |
---|
[d09e5a1] | 204 | owl_global_set_aimloggedin(&g, screenname); |
---|
[a352335c] | 205 | owl_global_set_doaimevents(&g); /* this should already be on */ |
---|
| 206 | owl_function_makemsg("%s logged in", screenname); |
---|
[3472845] | 207 | buff=g_strdup_printf("Logged in to AIM as %s", screenname); |
---|
[1db061d] | 208 | owl_function_adminmsg("", buff); |
---|
[ddbbcffa] | 209 | g_free(buff); |
---|
[a352335c] | 210 | |
---|
| 211 | owl_function_debugmsg("Successful AIM login for %s", screenname); |
---|
| 212 | |
---|
| 213 | /* start the ingorelogin timer */ |
---|
[b7bb454] | 214 | owl_global_set_ignore_aimlogin(&g); |
---|
[6b0b4f4] | 215 | g_timeout_add_seconds(owl_global_get_aim_ignorelogin_timer(&g), |
---|
| 216 | owl_aim_unset_ignorelogin, &g); |
---|
[c15bbfb] | 217 | |
---|
[2674412] | 218 | /* aim_ssi_setpresence(owl_global_get_aimsess(&g), 0x00000400); */ |
---|
[c15bbfb] | 219 | /* aim_bos_setidle(owl_global_get_aimsess(&g), owl_global_get_bosconn(&g), 5000); */ |
---|
[d09e5a1] | 220 | } |
---|
| 221 | |
---|
| 222 | void owl_aim_logout(void) |
---|
| 223 | { |
---|
| 224 | /* need to check if it's connected first, I think */ |
---|
[dff8d8a] | 225 | logout(owl_global_get_aimsess(&g)); |
---|
[1db061d] | 226 | |
---|
[e7bcd1b] | 227 | if (owl_global_is_aimloggedin(&g)) owl_function_adminmsg("", "Logged out of AIM"); |
---|
[d09e5a1] | 228 | owl_global_set_aimnologgedin(&g); |
---|
[a352335c] | 229 | owl_global_set_no_doaimevents(&g); |
---|
[6b0b4f4] | 230 | if (g.aim_nop_timer) { |
---|
| 231 | g_source_remove(g.aim_nop_timer); |
---|
| 232 | g.aim_nop_timer = 0; |
---|
| 233 | } |
---|
[d09e5a1] | 234 | } |
---|
| 235 | |
---|
[c79a047] | 236 | void owl_aim_logged_out(void) |
---|
[1077753b] | 237 | { |
---|
[e7bcd1b] | 238 | if (owl_global_is_aimloggedin(&g)) owl_function_adminmsg("", "Logged out of AIM"); |
---|
[1077753b] | 239 | owl_aim_logout(); |
---|
| 240 | } |
---|
| 241 | |
---|
[e19eb97] | 242 | void owl_aim_login_error(const char *message) |
---|
[c045455] | 243 | { |
---|
[a352335c] | 244 | if (message) { |
---|
[554a2b8] | 245 | owl_function_error("%s", message); |
---|
[a352335c] | 246 | } else { |
---|
[836ea3a3] | 247 | owl_function_error("Authentication error on login"); |
---|
[a352335c] | 248 | } |
---|
[c045455] | 249 | owl_function_beep(); |
---|
| 250 | owl_global_set_aimnologgedin(&g); |
---|
[a352335c] | 251 | owl_global_set_no_doaimevents(&g); |
---|
[6b0b4f4] | 252 | if (g.aim_nop_timer) { |
---|
| 253 | g_source_remove(g.aim_nop_timer); |
---|
| 254 | g.aim_nop_timer = 0; |
---|
| 255 | } |
---|
[c045455] | 256 | } |
---|
| 257 | |
---|
[82a79a6] | 258 | /* |
---|
| 259 | * I got these constants by skimming libfaim/im.c |
---|
| 260 | * |
---|
| 261 | * "UNICODE" actually means "UCS-2BE". |
---|
| 262 | */ |
---|
| 263 | #define AIM_CHARSET_ISO_8859_1 0x0003 |
---|
| 264 | #define AIM_CHARSET_UNICODE 0x0002 |
---|
| 265 | |
---|
[e9c6fc8] | 266 | static int owl_aim_do_send(const char *to, const char *msg, int flags) |
---|
[d09e5a1] | 267 | { |
---|
[f4d0975] | 268 | int ret; |
---|
[82a79a6] | 269 | char *encoded; |
---|
| 270 | struct aim_sendimext_args args; |
---|
| 271 | gsize len; |
---|
| 272 | |
---|
| 273 | encoded = g_convert(msg, -1, "ISO-8859-1", "UTF-8", NULL, &len, NULL); |
---|
| 274 | if (encoded) { |
---|
| 275 | owl_function_debugmsg("Encoded outgoing AIM as ISO-8859-1"); |
---|
| 276 | args.charset = AIM_CHARSET_ISO_8859_1; |
---|
| 277 | args.charsubset = 0; |
---|
| 278 | args.flags = AIM_IMFLAGS_ISO_8859_1; |
---|
| 279 | } else { |
---|
| 280 | owl_function_debugmsg("Encoding outgoing IM as UCS-2BE"); |
---|
| 281 | encoded = g_convert(msg, -1, "UCS-2BE", "UTF-8", NULL, &len, NULL); |
---|
| 282 | if (!encoded) { |
---|
| 283 | /* |
---|
| 284 | * TODO: Strip or HTML-encode characters, or figure out how to |
---|
| 285 | * send in a differen charset. |
---|
| 286 | */ |
---|
| 287 | owl_function_error("Unable to encode outgoing AIM message in UCS-2"); |
---|
| 288 | return 1; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | args.charset = AIM_CHARSET_UNICODE; |
---|
| 292 | args.charsubset = 0; |
---|
| 293 | args.flags = AIM_IMFLAGS_UNICODE; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | args.destsn = to; |
---|
| 297 | args.msg = encoded; |
---|
| 298 | args.msglen = len; |
---|
| 299 | args.flags |= flags; |
---|
| 300 | |
---|
| 301 | ret=aim_im_sendch1_ext(owl_global_get_aimsess(&g), &args); |
---|
| 302 | |
---|
[ddbbcffa] | 303 | g_free(encoded); |
---|
[f4d0975] | 304 | |
---|
[9854278] | 305 | return(ret); |
---|
| 306 | } |
---|
| 307 | |
---|
[82a79a6] | 308 | int owl_aim_send_im(const char *to, const char *msg) |
---|
[9854278] | 309 | { |
---|
[82a79a6] | 310 | return owl_aim_do_send(to, msg, 0); |
---|
| 311 | } |
---|
[0ff8fb57] | 312 | |
---|
[82a79a6] | 313 | int owl_aim_send_awaymsg(const char *to, const char *msg) |
---|
| 314 | { |
---|
| 315 | return owl_aim_do_send(to, msg, AIM_IMFLAGS_AWAY); |
---|
[d09e5a1] | 316 | } |
---|
| 317 | |
---|
[e19eb97] | 318 | void owl_aim_addbuddy(const char *name) |
---|
[fd93b41] | 319 | { |
---|
[a0a5179] | 320 | |
---|
[257a22f] | 321 | aim_ssi_addbuddy(owl_global_get_aimsess(&g), name, "Buddies", NULL, NULL, NULL, 0); |
---|
[a0a5179] | 322 | |
---|
| 323 | /* |
---|
| 324 | aim_ssi_addbuddy(owl_global_get_aimsess(&g), |
---|
| 325 | name, |
---|
| 326 | "Buddies", |
---|
| 327 | NULL, NULL, NULL, |
---|
| 328 | aim_ssi_waitingforauth(owl_global_get_aimsess(&g)->ssi.local, "Buddies", name)); |
---|
| 329 | */ |
---|
[fd93b41] | 330 | } |
---|
| 331 | |
---|
[e19eb97] | 332 | void owl_aim_delbuddy(const char *name) |
---|
[fd93b41] | 333 | { |
---|
[257a22f] | 334 | aim_ssi_delbuddy(owl_global_get_aimsess(&g), name, "Buddies"); |
---|
| 335 | owl_buddylist_offgoing(owl_global_get_buddylist(&g), name); |
---|
[fd93b41] | 336 | } |
---|
| 337 | |
---|
[e19eb97] | 338 | void owl_aim_search(const char *email) |
---|
[952bb256] | 339 | { |
---|
| 340 | int ret; |
---|
| 341 | |
---|
| 342 | owl_function_debugmsg("owl_aim_search: doing search for %s", email); |
---|
| 343 | ret=aim_search_address(owl_global_get_aimsess(&g), |
---|
| 344 | aim_getconn_type(owl_global_get_aimsess(&g), AIM_CONN_TYPE_BOS), |
---|
| 345 | email); |
---|
| 346 | |
---|
| 347 | if (ret) owl_function_error("owl_aim_search: aim_search_address returned %i", ret); |
---|
| 348 | } |
---|
| 349 | |
---|
[1077753b] | 350 | |
---|
[e19eb97] | 351 | int owl_aim_set_awaymsg(const char *msg) |
---|
[de03334] | 352 | { |
---|
[9854278] | 353 | int len; |
---|
| 354 | char *foo; |
---|
[1077753b] | 355 | /* there is a max away message lentgh we should check against */ |
---|
| 356 | |
---|
[d4927a7] | 357 | foo=g_strdup(msg); |
---|
[9854278] | 358 | len=strlen(foo); |
---|
| 359 | if (len>500) { |
---|
| 360 | foo[500]='\0'; |
---|
| 361 | len=499; |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | aim_locate_setprofile(owl_global_get_aimsess(&g), |
---|
| 365 | NULL, NULL, 0, |
---|
| 366 | "us-ascii", foo, len); |
---|
[ddbbcffa] | 367 | g_free(foo); |
---|
[9854278] | 368 | |
---|
[c8735aa] | 369 | /* |
---|
[1077753b] | 370 | aim_bos_setprofile(owl_global_get_aimsess(&g), |
---|
| 371 | owl_global_get_bosconn(&g), |
---|
| 372 | NULL, NULL, 0, "us-ascii", msg, |
---|
| 373 | strlen(msg), 0); |
---|
[c8735aa] | 374 | */ |
---|
[1077753b] | 375 | return(0); |
---|
[de03334] | 376 | } |
---|
| 377 | |
---|
[e19eb97] | 378 | void owl_aim_chat_join(const char *name, int exchange) |
---|
[d09e5a1] | 379 | { |
---|
[8c92848] | 380 | int ret; |
---|
[2674412] | 381 | aim_conn_t *cur; |
---|
| 382 | /* |
---|
[4d86e06] | 383 | OscarData *od = g->proto_data; |
---|
[e19eb97] | 384 | const char *name, *exchange; |
---|
[2674412] | 385 | */ |
---|
| 386 | |
---|
| 387 | owl_function_debugmsg("Attempting to join chatroom %s exchange %i", name, exchange); |
---|
| 388 | |
---|
| 389 | /* |
---|
| 390 | name = g_hash_table_lookup(data, "room"); |
---|
| 391 | exchange = g_hash_table_lookup(data, "exchange"); |
---|
| 392 | */ |
---|
| 393 | if ((cur = aim_getconn_type(owl_global_get_aimsess(&g), AIM_CONN_TYPE_CHATNAV))) { |
---|
| 394 | owl_function_debugmsg("owl_aim_chat_join: chatnav exists, creating room"); |
---|
| 395 | aim_chatnav_createroom(owl_global_get_aimsess(&g), cur, name, exchange); |
---|
| 396 | } else { |
---|
| 397 | /* struct create_room *cr = g_new0(struct create_room, 1); */ |
---|
| 398 | owl_function_debugmsg("owl_aim_chat_join: chatnav does not exist, opening chatnav"); |
---|
| 399 | /* |
---|
| 400 | cr->exchange = atoi(exchange); |
---|
| 401 | cr->name = g_strdup(name); |
---|
| 402 | od->create_rooms = g_slist_append(od->create_rooms, cr); |
---|
| 403 | */ |
---|
[9854278] | 404 | aim_reqservice(owl_global_get_aimsess(&g), |
---|
| 405 | aim_getconn_type(owl_global_get_aimsess(&g), AIM_CONN_TYPE_CHATNAV), |
---|
| 406 | AIM_CONN_TYPE_CHATNAV); |
---|
[2674412] | 407 | aim_reqservice(owl_global_get_aimsess(&g), NULL, AIM_CONN_TYPE_CHATNAV); |
---|
| 408 | aim_chatnav_createroom(owl_global_get_aimsess(&g), cur, name, exchange); |
---|
| 409 | ret=aim_chat_join(owl_global_get_aimsess(&g), owl_global_get_bosconn(&g), exchange, name, 0x0000); |
---|
| 410 | |
---|
| 411 | } |
---|
| 412 | return; |
---|
| 413 | /******/ |
---|
| 414 | |
---|
[8c92848] | 415 | |
---|
| 416 | /* ret=aim_chat_join(owl_global_get_aimsess(&g), owl_global_get_bosconn(&g), exchange, chatroom, 0x0000); */ |
---|
| 417 | /* |
---|
| 418 | ret=aim_chat_join(owl_global_get_aimsess(&g), |
---|
| 419 | aim_getconn_type(owl_global_get_aimsess(&g), AIM_CONN_TYPE_CHATNAV), exchange, chatroom, 0x0000); |
---|
| 420 | */ |
---|
| 421 | |
---|
| 422 | aim_reqservice(owl_global_get_aimsess(&g), owl_global_get_bosconn(&g), AIM_CONN_TYPE_CHATNAV); |
---|
| 423 | ret = aim_chatnav_createroom(owl_global_get_aimsess(&g), |
---|
[2674412] | 424 | aim_getconn_type(owl_global_get_aimsess(&g), AIM_CONN_TYPE_CHATNAV), name, exchange); |
---|
| 425 | ret=aim_chat_join(owl_global_get_aimsess(&g), owl_global_get_bosconn(&g), exchange, name, 0x0000); |
---|
[8c92848] | 426 | |
---|
[d09e5a1] | 427 | } |
---|
| 428 | |
---|
[e19eb97] | 429 | void owl_aim_chat_leave(const char *chatroom) |
---|
[d09e5a1] | 430 | { |
---|
| 431 | } |
---|
| 432 | |
---|
[e19eb97] | 433 | int owl_aim_chat_sendmsg(const char *chatroom, const char *msg) |
---|
[d09e5a1] | 434 | { |
---|
[0ff8fb57] | 435 | return(0); |
---|
[d09e5a1] | 436 | } |
---|
| 437 | |
---|
[651560f] | 438 | /* caller must free the return */ |
---|
[6829afc] | 439 | CALLER_OWN char *owl_aim_normalize_screenname(const char *in) |
---|
[8c92848] | 440 | { |
---|
[651560f] | 441 | char *out; |
---|
| 442 | int i, j, k; |
---|
| 443 | |
---|
| 444 | j=strlen(in); |
---|
[96828e4] | 445 | out=g_new(char, j+30); |
---|
[651560f] | 446 | k=0; |
---|
| 447 | for (i=0; i<j; i++) { |
---|
| 448 | if (in[i]!=' ') { |
---|
| 449 | out[k]=in[i]; |
---|
| 450 | k++; |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | out[k]='\0'; |
---|
| 454 | return(out); |
---|
| 455 | } |
---|
| 456 | |
---|
[dc1edbd] | 457 | int owl_aim_process_events(aim_session_t *aimsess) |
---|
[8c92848] | 458 | { |
---|
[d09e5a1] | 459 | aim_conn_t *waitingconn = NULL; |
---|
| 460 | struct timeval tv; |
---|
| 461 | int selstat = 0; |
---|
| 462 | struct owlfaim_priv *priv; |
---|
| 463 | |
---|
[4d86e06] | 464 | priv = aimsess->aux_data; |
---|
[d09e5a1] | 465 | |
---|
| 466 | /* do a select without blocking */ |
---|
| 467 | tv.tv_sec = 0; |
---|
| 468 | tv.tv_usec = 0; |
---|
| 469 | waitingconn = aim_select(aimsess, &tv, &selstat); |
---|
| 470 | |
---|
[f4d0975] | 471 | if (selstat == -1) { |
---|
[1077753b] | 472 | owl_aim_logged_out(); |
---|
[8c92848] | 473 | } else if (selstat == 0) { |
---|
[f4d0975] | 474 | /* no events pending */ |
---|
[d09e5a1] | 475 | } else if (selstat == 1) { /* outgoing data pending */ |
---|
| 476 | aim_tx_flushqueue(aimsess); |
---|
| 477 | } else if (selstat == 2) { /* incoming data pending */ |
---|
| 478 | /* printf("selstat == 2\n"); */ |
---|
[f4d0975] | 479 | |
---|
| 480 | if (aim_get_command(aimsess, waitingconn) >= 0) { |
---|
| 481 | aim_rxdispatch(aimsess); |
---|
[d09e5a1] | 482 | } else { |
---|
[f4d0975] | 483 | /* printf("connection error (type 0x%04x:0x%04x)\n", waitingconn->type, waitingconn->subtype); */ |
---|
| 484 | /* we should have callbacks for all these, else the library will do the conn_kill for us. */ |
---|
| 485 | if (waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS) { |
---|
| 486 | if (waitingconn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { |
---|
| 487 | /* printf("disconnected from %s\n", aim_directim_getsn(waitingconn)); */ |
---|
[d09e5a1] | 488 | aim_conn_kill(aimsess, &waitingconn); |
---|
[8c92848] | 489 | owl_aim_logged_out(); |
---|
[d09e5a1] | 490 | } |
---|
[f4d0975] | 491 | } else { |
---|
| 492 | aim_conn_kill(aimsess, &waitingconn); |
---|
[8c92848] | 493 | owl_aim_logged_out(); |
---|
[f4d0975] | 494 | } |
---|
| 495 | if (!aim_getconn_type(aimsess, AIM_CONN_TYPE_BOS)) { |
---|
| 496 | /* printf("major connection error\n"); */ |
---|
[8c92848] | 497 | owl_aim_logged_out(); |
---|
[f4d0975] | 498 | /* break; */ |
---|
[d09e5a1] | 499 | } |
---|
| 500 | } |
---|
| 501 | } |
---|
| 502 | /* exit(0); */ |
---|
[0ff8fb57] | 503 | return(0); |
---|
[d09e5a1] | 504 | } |
---|
| 505 | |
---|
| 506 | static void faimtest_debugcb(aim_session_t *sess, int level, const char *format, va_list va) |
---|
| 507 | { |
---|
| 508 | return; |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | static int faimtest_parse_login(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 512 | { |
---|
[4d86e06] | 513 | struct owlfaim_priv *priv = sess->aux_data; |
---|
[03ad7b2] | 514 | struct client_info_s info = CLIENTINFO_AIM_KNOWNGOOD; |
---|
| 515 | |
---|
[e19eb97] | 516 | const char *key; |
---|
[d09e5a1] | 517 | va_list ap; |
---|
| 518 | |
---|
| 519 | va_start(ap, fr); |
---|
[e19eb97] | 520 | key = va_arg(ap, const char *); |
---|
[d09e5a1] | 521 | va_end(ap); |
---|
| 522 | |
---|
| 523 | aim_send_login(sess, fr->conn, priv->screenname, priv->password, &info, key); |
---|
[b2b0773] | 524 | |
---|
[8c92848] | 525 | return(1); |
---|
[d09e5a1] | 526 | } |
---|
| 527 | |
---|
| 528 | |
---|
| 529 | static int faimtest_parse_authresp(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 530 | { |
---|
| 531 | va_list ap; |
---|
| 532 | struct aim_authresp_info *info; |
---|
| 533 | aim_conn_t *bosconn; |
---|
| 534 | |
---|
| 535 | va_start(ap, fr); |
---|
| 536 | info = va_arg(ap, struct aim_authresp_info *); |
---|
| 537 | va_end(ap); |
---|
| 538 | |
---|
| 539 | /* printf("Screen name: %s\n", info->sn); */ |
---|
[8c92848] | 540 | owl_function_debugmsg("doing faimtest_parse_authresp"); |
---|
[f4d0975] | 541 | owl_function_debugmsg("faimtest_parse_authresp: %s", info->sn); |
---|
[d09e5a1] | 542 | |
---|
| 543 | /* |
---|
| 544 | * Check for error. |
---|
| 545 | */ |
---|
| 546 | if (info->errorcode || !info->bosip || !info->cookie) { |
---|
| 547 | /* |
---|
| 548 | printf("Login Error Code 0x%04x\n", info->errorcode); |
---|
| 549 | printf("Error URL: %s\n", info->errorurl); |
---|
| 550 | */ |
---|
[a352335c] | 551 | if (info->errorcode==0x05) { |
---|
| 552 | owl_aim_login_error("Incorrect nickname or password."); |
---|
| 553 | } else if (info->errorcode==0x11) { |
---|
| 554 | owl_aim_login_error("Your account is currently suspended."); |
---|
| 555 | } else if (info->errorcode==0x14) { |
---|
| 556 | owl_aim_login_error("The AOL Instant Messenger service is temporarily unavailable."); |
---|
| 557 | } else if (info->errorcode==0x18) { |
---|
| 558 | owl_aim_login_error("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."); |
---|
| 559 | } else if (info->errorcode==0x1c) { |
---|
| 560 | owl_aim_login_error("The client version you are using is too old."); |
---|
| 561 | } else { |
---|
| 562 | owl_aim_login_error(NULL); |
---|
| 563 | } |
---|
| 564 | aim_conn_kill(sess, &fr->conn); |
---|
[8c92848] | 565 | return(1); |
---|
[d09e5a1] | 566 | } |
---|
| 567 | |
---|
| 568 | /* |
---|
| 569 | printf("Reg status: %d\n", info->regstatus); |
---|
| 570 | printf("Email: %s\n", info->email); |
---|
| 571 | printf("BOS IP: %s\n", info->bosip); |
---|
| 572 | */ |
---|
| 573 | |
---|
| 574 | /* printf("Closing auth connection...\n"); */ |
---|
| 575 | aim_conn_kill(sess, &fr->conn); |
---|
| 576 | if (!(bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, info->bosip))) { |
---|
| 577 | /* printf("could not connect to BOS: internal error\n"); */ |
---|
[8c92848] | 578 | return(1); |
---|
[d09e5a1] | 579 | } else if (bosconn->status & AIM_CONN_STATUS_CONNERR) { |
---|
| 580 | /* printf("could not connect to BOS\n"); */ |
---|
| 581 | aim_conn_kill(sess, &bosconn); |
---|
[8c92848] | 582 | return(1); |
---|
[d09e5a1] | 583 | } |
---|
[c15bbfb] | 584 | owl_global_set_bossconn(&g, bosconn); |
---|
[a352335c] | 585 | owl_aim_successful_login(info->sn); |
---|
[d09e5a1] | 586 | addcb_bos(sess, bosconn); |
---|
[f4d0975] | 587 | aim_sendcookie(sess, bosconn, info->cookielen, info->cookie); |
---|
[8c92848] | 588 | return(1); |
---|
[d09e5a1] | 589 | } |
---|
| 590 | |
---|
| 591 | int faimtest_flapversion(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 592 | { |
---|
[8c92848] | 593 | owl_function_debugmsg("doing faimtest_flapversion"); |
---|
| 594 | |
---|
[d09e5a1] | 595 | #if 0 |
---|
| 596 | /* XXX fix libfaim to support this */ |
---|
| 597 | printf("using FLAP version 0x%08x\n", /* aimutil_get32(fr->data)*/ 0xffffffff); |
---|
| 598 | |
---|
| 599 | /* |
---|
| 600 | * This is an alternate location for starting the login process. |
---|
| 601 | */ |
---|
| 602 | /* XXX should do more checking to make sure its really the right AUTH conn */ |
---|
| 603 | if (fr->conn->type == AIM_CONN_TYPE_AUTH) { |
---|
| 604 | /* do NOT send a flapversion, request_login will send it if needed */ |
---|
| 605 | aim_request_login(sess, fr->conn, priv->screenname); |
---|
| 606 | /* printf("faimtest: login request sent\n"); */ |
---|
| 607 | } |
---|
| 608 | #endif |
---|
| 609 | |
---|
| 610 | return 1; |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | |
---|
| 614 | int faimtest_conncomplete(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 615 | { |
---|
[8c92848] | 616 | owl_function_debugmsg("doing faimtest_conncomplete"); |
---|
[a352335c] | 617 | /* owl_aim_successful_login(info->sn); */ |
---|
[d09e5a1] | 618 | return 1; |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | void addcb_bos(aim_session_t *sess, aim_conn_t *bosconn) |
---|
| 622 | { |
---|
[8c92848] | 623 | owl_function_debugmsg("doing addcb_bos"); |
---|
[d09e5a1] | 624 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0); |
---|
| 625 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_bos, 0); |
---|
| 626 | |
---|
[aa5f725] | 627 | aim_conn_addhandler(sess, bosconn, 0x0013, 0x0003, ssirights, 0); |
---|
| 628 | aim_conn_addhandler(sess, bosconn, 0x0013, 0x0006, ssidata, 0); |
---|
| 629 | aim_conn_addhandler(sess, bosconn, 0x0013, 0x000f, ssidatanochange, 0); |
---|
| 630 | aim_conn_addhandler(sess, bosconn, 0x0008, 0x0002, handlepopup, 0); |
---|
| 631 | aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, faimtest_bosrights, 0); |
---|
| 632 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, faimtest_handleredirect, 0); |
---|
| 633 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, faimtest_reportinterval, 0); |
---|
| 634 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_RIGHTSINFO, faimtest_parse_buddyrights, 0); |
---|
| 635 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, faimtest_parse_motd, 0); |
---|
| 636 | aim_conn_addhandler(sess, bosconn, 0x0004, 0x0005, faimtest_icbmparaminfo, 0); |
---|
| 637 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, faimtest_parse_connerr, 0); |
---|
| 638 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_RIGHTSINFO, faimtest_locrights, 0); |
---|
| 639 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, faimtest_parse_oncoming, 0); |
---|
| 640 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, faimtest_parse_offgoing, 0); |
---|
| 641 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0); |
---|
| 642 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, faimtest_parse_locerr, 0); |
---|
| 643 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, faimtest_parse_misses, 0); |
---|
| 644 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, faimtest_parse_ratechange, 0); |
---|
| 645 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_EVIL, faimtest_parse_evilnotify, 0); |
---|
[952bb256] | 646 | |
---|
[aa5f725] | 647 | aim_conn_addhandler(sess, bosconn, 0x000a, 0x0001, faimtest_parse_searcherror, 0); |
---|
| 648 | aim_conn_addhandler(sess, bosconn, 0x000a, 0x0003, faimtest_parse_searchreply, 0); |
---|
[952bb256] | 649 | |
---|
| 650 | /* |
---|
| 651 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOK, AIM_CB_LOK_ERROR, faimtest_parse_searcherror, 0); |
---|
| 652 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOK, 0x0003, faimtest_parse_searchreply, 0); |
---|
| 653 | */ |
---|
| 654 | |
---|
[aa5f725] | 655 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, faimtest_parse_msgerr, 0); |
---|
| 656 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, faimtest_parse_userinfo, 0); |
---|
| 657 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, faimtest_parse_msgack, 0); |
---|
| 658 | |
---|
| 659 | aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, faimtest_parse_genericerr, 0); |
---|
| 660 | aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, faimtest_parse_genericerr, 0); |
---|
| 661 | aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, faimtest_parse_genericerr, 0); |
---|
| 662 | aim_conn_addhandler(sess, bosconn, 0x0001, 0x000b, serverpause, 0); |
---|
| 663 | aim_conn_addhandler(sess, bosconn, 0x0001, 0x0012, migrate, 0); |
---|
| 664 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG, offlinemsg, 0); |
---|
[d09e5a1] | 665 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE, offlinemsgdone, 0); |
---|
| 666 | |
---|
[8c46404] | 667 | /* |
---|
[2674412] | 668 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, gaim_connerr, 0); |
---|
| 669 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_chatnav, 0); |
---|
| 670 | */ |
---|
| 671 | |
---|
| 672 | /* |
---|
[8c46404] | 673 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_ERROR, faimtest_ssi_parseerr, 0); |
---|
| 674 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_RIGHTSINFO, faimtest_ssi_parserights, 0); |
---|
| 675 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_LIST, faimtest_ssi_parselist, 0); |
---|
| 676 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_NOLIST, faimtest_ssi_parselist, 0); |
---|
| 677 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_SRVACK, faimtest_ssi_parseack, 0); |
---|
| 678 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_RECVAUTH, faimtest_ssi_authgiven, 0); |
---|
| 679 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_RECVAUTHREQ, faimtest_ssi_authrequest, 0); |
---|
| 680 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_RECVAUTHREP, faimtest_ssi_authreply, 0); |
---|
| 681 | aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SSI, AIM_CB_SSI_ADDED, faimtest_ssi_gotadded, 0); |
---|
| 682 | */ |
---|
| 683 | |
---|
[d09e5a1] | 684 | return; |
---|
| 685 | } |
---|
| 686 | |
---|
[8c92848] | 687 | static int conninitdone_bos(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 688 | { |
---|
| 689 | owl_function_debugmsg("doing coninitdone_bos"); |
---|
[d09e5a1] | 690 | |
---|
[8c46404] | 691 | |
---|
| 692 | aim_reqpersonalinfo(sess, fr->conn); |
---|
[f4d0975] | 693 | aim_ssi_reqrights(sess); |
---|
| 694 | aim_ssi_reqdata(sess); |
---|
[8c46404] | 695 | aim_locate_reqrights(sess); |
---|
| 696 | aim_buddylist_reqrights(sess, fr->conn); |
---|
[d09e5a1] | 697 | |
---|
[f4d0975] | 698 | aim_im_reqparams(sess); |
---|
[8c46404] | 699 | /* aim_bos_reqrights(sess, fr->conn); */ /* XXX - Don't call this with ssi */ |
---|
[8c92848] | 700 | |
---|
[8c46404] | 701 | owl_function_debugmsg("conninitdone_bos: requesting rights"); |
---|
| 702 | aim_bos_reqrights(sess, fr->conn); /* XXX - Don't call this with ssi */ |
---|
[d09e5a1] | 703 | aim_bos_setgroupperm(sess, fr->conn, AIM_FLAG_ALLUSERS); |
---|
[f4d0975] | 704 | aim_bos_setprivacyflags(sess, fr->conn, AIM_PRIVFLAGS_ALLOWIDLE | AIM_PRIVFLAGS_ALLOWMEMBERSINCE); |
---|
[d09e5a1] | 705 | |
---|
[8c92848] | 706 | return(1); |
---|
[d09e5a1] | 707 | } |
---|
| 708 | |
---|
| 709 | static int conninitdone_admin(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 710 | { |
---|
| 711 | aim_clientready(sess, fr->conn); |
---|
[a0a5179] | 712 | owl_function_debugmsg("conninitdone_admin: initializtion done for admin connection"); |
---|
[d09e5a1] | 713 | return(1); |
---|
| 714 | } |
---|
| 715 | |
---|
| 716 | int logout(aim_session_t *sess) |
---|
| 717 | { |
---|
| 718 | aim_session_kill(sess); |
---|
[fd93b41] | 719 | owl_aim_init(); |
---|
[a0a5179] | 720 | |
---|
| 721 | owl_function_debugmsg("libfaim logout called"); |
---|
| 722 | /* |
---|
[d09e5a1] | 723 | if (faimtest_init() == -1) |
---|
| 724 | printf("faimtest_init failed\n"); |
---|
| 725 | */ |
---|
| 726 | |
---|
| 727 | return(0); |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | /**************************************************************************************************/ |
---|
| 731 | |
---|
| 732 | static int faimtest_parse_connerr(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 733 | { |
---|
[4d86e06] | 734 | struct owlfaim_priv *priv = sess->aux_data; |
---|
[d09e5a1] | 735 | va_list ap; |
---|
| 736 | fu16_t code; |
---|
[e19eb97] | 737 | const char *msg; |
---|
[d09e5a1] | 738 | |
---|
| 739 | va_start(ap, fr); |
---|
| 740 | code = va_arg(ap, int); |
---|
[e19eb97] | 741 | msg = va_arg(ap, const char *); |
---|
[d09e5a1] | 742 | va_end(ap); |
---|
| 743 | |
---|
[8c46404] | 744 | owl_function_error("faimtest_parse_connerr: Code 0x%04x: %s\n", code, msg); |
---|
[d09e5a1] | 745 | aim_conn_kill(sess, &fr->conn); /* this will break the main loop */ |
---|
| 746 | |
---|
| 747 | priv->connected = 0; |
---|
| 748 | |
---|
| 749 | return 1; |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | static int faimtest_accountconfirm(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 753 | { |
---|
| 754 | int status; |
---|
| 755 | va_list ap; |
---|
| 756 | |
---|
| 757 | va_start(ap, fr); |
---|
| 758 | status = va_arg(ap, int); /* status code of confirmation request */ |
---|
| 759 | va_end(ap); |
---|
[8c46404] | 760 | |
---|
| 761 | /* owl_function_debugmsg("faimtest_accountconfirm: Code 0x%04x: %s\n", code, msg); */ |
---|
| 762 | owl_function_debugmsg("faimtest_accountconfirm: account confirmation returned status 0x%04x (%s)\n", status, (status==0x0000)?"email sent":"unknown"); |
---|
[d09e5a1] | 763 | |
---|
| 764 | return 1; |
---|
| 765 | } |
---|
| 766 | |
---|
| 767 | static int faimtest_infochange(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 768 | { |
---|
| 769 | fu16_t change = 0, perms, type; |
---|
| 770 | int length, str; |
---|
[e19eb97] | 771 | const char *val; |
---|
[d09e5a1] | 772 | va_list ap; |
---|
| 773 | |
---|
| 774 | va_start(ap, fr); |
---|
| 775 | change = va_arg(ap, int); |
---|
| 776 | perms = (fu16_t)va_arg(ap, unsigned int); |
---|
| 777 | type = (fu16_t)va_arg(ap, unsigned int); |
---|
| 778 | length = va_arg(ap, int); |
---|
[e19eb97] | 779 | val = va_arg(ap, const char *); |
---|
[d09e5a1] | 780 | str = va_arg(ap, int); |
---|
| 781 | va_end(ap); |
---|
| 782 | |
---|
[8c46404] | 783 | owl_function_debugmsg("faimtest_infochange: info%s: perms = %d, type = %x, length = %d, val = %s", change?" change":"", perms, type, length, str?val:"(not string)"); |
---|
[d09e5a1] | 784 | |
---|
[8c46404] | 785 | return(1); |
---|
[d09e5a1] | 786 | } |
---|
| 787 | |
---|
| 788 | |
---|
| 789 | static int faimtest_handleredirect(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 790 | { |
---|
| 791 | va_list ap; |
---|
| 792 | struct aim_redirect_data *redir; |
---|
[2674412] | 793 | |
---|
| 794 | owl_function_debugmsg("faimtest_handledirect:"); |
---|
[d09e5a1] | 795 | |
---|
| 796 | va_start(ap, fr); |
---|
| 797 | redir = va_arg(ap, struct aim_redirect_data *); |
---|
| 798 | |
---|
| 799 | if (redir->group == 0x0005) { /* Adverts */ |
---|
| 800 | |
---|
| 801 | } else if (redir->group == 0x0007) { /* Authorizer */ |
---|
| 802 | aim_conn_t *tstconn; |
---|
[2674412] | 803 | |
---|
| 804 | owl_function_debugmsg("faimtest_handledirect: autorizer"); |
---|
[d09e5a1] | 805 | |
---|
| 806 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, redir->ip); |
---|
| 807 | if (!tstconn || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) { |
---|
[8c46404] | 808 | owl_function_error("faimtest_handleredirect: unable to reconnect with authorizer"); |
---|
[d09e5a1] | 809 | } else { |
---|
| 810 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, faimtest_flapversion, 0); |
---|
| 811 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0); |
---|
| 812 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_admin, 0); |
---|
| 813 | aim_conn_addhandler(sess, tstconn, 0x0007, 0x0007, faimtest_accountconfirm, 0); |
---|
| 814 | aim_conn_addhandler(sess, tstconn, 0x0007, 0x0003, faimtest_infochange, 0); |
---|
| 815 | aim_conn_addhandler(sess, tstconn, 0x0007, 0x0005, faimtest_infochange, 0); |
---|
| 816 | /* Send the cookie to the Auth */ |
---|
[f4d0975] | 817 | aim_sendcookie(sess, tstconn, redir->cookielen, redir->cookie); |
---|
[8c46404] | 818 | owl_function_debugmsg("faimtest_handleredirect: sent cookie to authorizer host"); |
---|
[d09e5a1] | 819 | } |
---|
| 820 | } else if (redir->group == 0x000d) { /* ChatNav */ |
---|
[2674412] | 821 | owl_function_debugmsg("faimtest_handledirect: chatnav"); |
---|
[d09e5a1] | 822 | chatnav_redirect(sess, redir); |
---|
| 823 | } else if (redir->group == 0x000e) { /* Chat */ |
---|
[2674412] | 824 | owl_function_debugmsg("faimtest_handledirect: chat"); |
---|
[d09e5a1] | 825 | chat_redirect(sess, redir); |
---|
| 826 | } else { |
---|
[8c46404] | 827 | owl_function_debugmsg("faimtest_handleredirect: uh oh... got redirect for unknown service 0x%04x!!", redir->group); |
---|
[d09e5a1] | 828 | } |
---|
| 829 | va_end(ap); |
---|
| 830 | return 1; |
---|
| 831 | } |
---|
| 832 | |
---|
| 833 | static int faimtest_icbmparaminfo(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 834 | { |
---|
| 835 | struct aim_icbmparameters *params; |
---|
| 836 | va_list ap; |
---|
| 837 | |
---|
| 838 | va_start(ap, fr); |
---|
| 839 | params = va_arg(ap, struct aim_icbmparameters *); |
---|
| 840 | va_end(ap); |
---|
| 841 | |
---|
[f278ff3] | 842 | owl_function_debugmsg("faimtest_icbmparaminfo: ICBM Parameters: maxchannel = %d, default flags = 0x%08x, max msg len = %d, max sender evil = %f, max reciever evil = %f, min msg interval = %u", |
---|
[8c46404] | 843 | params->maxchan, params->flags, params->maxmsglen, ((float)params->maxsenderwarn)/10.0, ((float)params->maxrecverwarn)/10.0, params->minmsginterval); |
---|
[d09e5a1] | 844 | |
---|
| 845 | /* |
---|
| 846 | * Set these to your taste, or client medium. Setting minmsginterval |
---|
| 847 | * higher is good for keeping yourself from getting flooded (esp |
---|
| 848 | * if you're on a slow connection or something where that would be |
---|
| 849 | * useful). |
---|
| 850 | */ |
---|
| 851 | params->maxmsglen = 8000; |
---|
| 852 | params->minmsginterval = 0; /* in milliseconds */ |
---|
[f4d0975] | 853 | /* aim_seticbmparam(sess, params); */ |
---|
| 854 | aim_im_setparams(sess, params); |
---|
[d09e5a1] | 855 | |
---|
| 856 | return 1; |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | static int faimtest_parse_buddyrights(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 860 | { |
---|
| 861 | va_list ap; |
---|
| 862 | fu16_t maxbuddies, maxwatchers; |
---|
| 863 | |
---|
| 864 | va_start(ap, fr); |
---|
| 865 | maxbuddies = va_arg(ap, int); |
---|
| 866 | maxwatchers = va_arg(ap, int); |
---|
| 867 | va_end(ap); |
---|
| 868 | |
---|
[8c46404] | 869 | owl_function_debugmsg("faimtest_parse_buddyrights: Max buddies = %d / Max watchers = %d\n", maxbuddies, maxwatchers); |
---|
[d09e5a1] | 870 | |
---|
[f4d0975] | 871 | /* aim_ssi_reqrights(sess, fr->conn); */ |
---|
| 872 | aim_ssi_reqrights(sess); |
---|
[d09e5a1] | 873 | |
---|
| 874 | return 1; |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | static int faimtest_bosrights(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 878 | { |
---|
| 879 | va_list ap; |
---|
| 880 | fu16_t maxpermits, maxdenies; |
---|
| 881 | |
---|
| 882 | va_start(ap, fr); |
---|
| 883 | maxpermits = va_arg(ap, int); |
---|
| 884 | maxdenies = va_arg(ap, int); |
---|
| 885 | va_end(ap); |
---|
| 886 | |
---|
[8c46404] | 887 | owl_function_debugmsg("faimtest_bosrights: Max permit = %d / Max deny = %d\n", maxpermits, maxdenies); |
---|
[d09e5a1] | 888 | aim_clientready(sess, fr->conn); |
---|
[8c92848] | 889 | owl_function_debugmsg("officially connected to BOS."); |
---|
[d09e5a1] | 890 | aim_icq_reqofflinemsgs(sess); |
---|
| 891 | return 1; |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | static int faimtest_locrights(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 895 | { |
---|
| 896 | va_list ap; |
---|
| 897 | fu16_t maxsiglen; |
---|
| 898 | |
---|
| 899 | va_start(ap, fr); |
---|
| 900 | maxsiglen = va_arg(ap, int); |
---|
| 901 | va_end(ap); |
---|
[8c92848] | 902 | |
---|
[8c46404] | 903 | owl_function_debugmsg("faimtest_locrights: rights: max signature length = %d\n", maxsiglen); |
---|
[d09e5a1] | 904 | |
---|
[8c92848] | 905 | return(1); |
---|
[d09e5a1] | 906 | } |
---|
| 907 | |
---|
| 908 | static int faimtest_reportinterval(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 909 | { |
---|
[4d86e06] | 910 | struct owlfaim_priv *priv = sess->aux_data; |
---|
[d09e5a1] | 911 | va_list ap; |
---|
| 912 | fu16_t interval; |
---|
[f4d0975] | 913 | |
---|
[d09e5a1] | 914 | va_start(ap, fr); |
---|
| 915 | interval = va_arg(ap, int); |
---|
| 916 | va_end(ap); |
---|
[f4d0975] | 917 | |
---|
[8c46404] | 918 | owl_function_debugmsg("faimtest_reportinterval: %d (seconds?)\n", interval); |
---|
[f4d0975] | 919 | |
---|
[d09e5a1] | 920 | if (!priv->connected) { |
---|
| 921 | priv->connected++; |
---|
| 922 | } |
---|
[f4d0975] | 923 | /* aim_reqicbmparams(sess); */ |
---|
| 924 | aim_im_reqparams(sess); |
---|
| 925 | /* kretch */ |
---|
[d09e5a1] | 926 | return 1; |
---|
| 927 | } |
---|
| 928 | |
---|
| 929 | static int faimtest_parse_motd(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 930 | { |
---|
[e19eb97] | 931 | const char *msg; |
---|
[0ff8fb57] | 932 | fu16_t id; |
---|
| 933 | va_list ap; |
---|
[8c46404] | 934 | static int codeslen = 5; |
---|
[e19eb97] | 935 | static const char *codes[] = { |
---|
[d09e5a1] | 936 | "Unknown", |
---|
| 937 | "Mandatory upgrade", |
---|
| 938 | "Advisory upgrade", |
---|
| 939 | "System bulletin", |
---|
| 940 | "Top o' the world!" |
---|
| 941 | }; |
---|
[0ff8fb57] | 942 | |
---|
[d09e5a1] | 943 | va_start(ap, fr); |
---|
| 944 | id = va_arg(ap, int); |
---|
[e19eb97] | 945 | msg = va_arg(ap, const char *); |
---|
[d09e5a1] | 946 | va_end(ap); |
---|
[8c46404] | 947 | |
---|
| 948 | owl_function_debugmsg("faimtest_parse_motd: %s (%d / %s)\n", msg?msg:"nomsg", id, (id < codeslen)?codes[id]:"unknown"); |
---|
[d09e5a1] | 949 | |
---|
| 950 | return 1; |
---|
| 951 | } |
---|
| 952 | |
---|
| 953 | /* |
---|
| 954 | static void printuserflags(fu16_t flags) |
---|
| 955 | { |
---|
[8c46404] | 956 | if (flags & AIM_FLAG_UNCONFIRMED) printf("UNCONFIRMED "); |
---|
| 957 | if (flags & AIM_FLAG_ADMINISTRATOR) printf("ADMINISTRATOR "); |
---|
| 958 | if (flags & AIM_FLAG_AOL) printf("AOL "); |
---|
| 959 | if (flags & AIM_FLAG_OSCAR_PAY) printf("OSCAR_PAY "); |
---|
| 960 | if (flags & AIM_FLAG_FREE) printf("FREE "); |
---|
| 961 | if (flags & AIM_FLAG_AWAY) printf("AWAY "); |
---|
| 962 | if (flags & AIM_FLAG_ICQ) printf("ICQ "); |
---|
| 963 | if (flags & AIM_FLAG_WIRELESS) printf("WIRELESS "); |
---|
| 964 | if (flags & AIM_FLAG_ACTIVEBUDDY) printf("ACTIVEBUDDY "); |
---|
[d09e5a1] | 965 | |
---|
| 966 | return; |
---|
| 967 | } |
---|
[8c46404] | 968 | */ |
---|
[d09e5a1] | 969 | |
---|
| 970 | static int faimtest_parse_userinfo(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 971 | { |
---|
| 972 | aim_userinfo_t *userinfo; |
---|
[e19eb97] | 973 | const char *prof_encoding = NULL; |
---|
| 974 | const char *prof = NULL; |
---|
[d09e5a1] | 975 | fu16_t inforeq = 0; |
---|
[f4d0975] | 976 | owl_buddy *b; |
---|
[d09e5a1] | 977 | va_list ap; |
---|
| 978 | va_start(ap, fr); |
---|
| 979 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 980 | inforeq = (fu16_t)va_arg(ap, unsigned int); |
---|
[e19eb97] | 981 | prof_encoding = va_arg(ap, const char *); |
---|
| 982 | prof = va_arg(ap, const char *); |
---|
[d09e5a1] | 983 | va_end(ap); |
---|
| 984 | |
---|
[de03334] | 985 | /* right now the only reason we call this is for idle times */ |
---|
[f4d0975] | 986 | owl_function_debugmsg("parse_userinfo sn: %s idle: %i", userinfo->sn, userinfo->idletime); |
---|
| 987 | b=owl_buddylist_get_aim_buddy(owl_global_get_buddylist(&g), |
---|
| 988 | userinfo->sn); |
---|
| 989 | if (!b) return(1); |
---|
| 990 | owl_buddy_set_idle_since(b, userinfo->idletime); |
---|
[de03334] | 991 | return(1); |
---|
[d09e5a1] | 992 | |
---|
[8c92848] | 993 | /* |
---|
[d09e5a1] | 994 | printf("userinfo: sn: %s\n", userinfo->sn); |
---|
| 995 | printf("userinfo: warnlevel: %f\n", aim_userinfo_warnlevel(userinfo)); |
---|
| 996 | printf("userinfo: flags: 0x%04x = ", userinfo->flags); |
---|
| 997 | printuserflags(userinfo->flags); |
---|
| 998 | printf("\n"); |
---|
[8c92848] | 999 | */ |
---|
[f4d0975] | 1000 | |
---|
| 1001 | /* |
---|
[d09e5a1] | 1002 | printf("userinfo: membersince: %lu\n", userinfo->membersince); |
---|
| 1003 | printf("userinfo: onlinesince: %lu\n", userinfo->onlinesince); |
---|
| 1004 | printf("userinfo: idletime: 0x%04x\n", userinfo->idletime); |
---|
| 1005 | printf("userinfo: capabilities = %s = 0x%08lx\n", (userinfo->present & AIM_USERINFO_PRESENT_CAPABILITIES) ? "present" : "not present", userinfo->capabilities); |
---|
[f4d0975] | 1006 | */ |
---|
[8c46404] | 1007 | |
---|
| 1008 | /* |
---|
[d09e5a1] | 1009 | if (inforeq == AIM_GETINFO_GENERALINFO) { |
---|
[8c92848] | 1010 | owl_function_debugmsg("userinfo: profile_encoding: %s\n", prof_encoding ? prof_encoding : "[none]"); |
---|
| 1011 | owl_function_debugmsg("userinfo: prof: %s\n", prof ? prof : "[none]"); |
---|
[d09e5a1] | 1012 | } else if (inforeq == AIM_GETINFO_AWAYMESSAGE) { |
---|
[8c92848] | 1013 | owl_function_debugmsg("userinfo: awaymsg_encoding: %s\n", prof_encoding ? prof_encoding : "[none]"); |
---|
| 1014 | owl_function_debugmsg("userinfo: awaymsg: %s\n", prof ? prof : "[none]"); |
---|
[d09e5a1] | 1015 | } else if (inforeq == AIM_GETINFO_CAPABILITIES) { |
---|
[8c92848] | 1016 | owl_function_debugmsg("userinfo: capabilities: see above\n"); |
---|
[d09e5a1] | 1017 | } else { |
---|
[8c92848] | 1018 | owl_function_debugmsg("userinfo: unknown info request\n"); |
---|
[d09e5a1] | 1019 | } |
---|
[8c46404] | 1020 | */ |
---|
[8c92848] | 1021 | return(1); |
---|
[d09e5a1] | 1022 | } |
---|
| 1023 | |
---|
| 1024 | /* |
---|
| 1025 | * Channel 1: Standard Message |
---|
| 1026 | */ |
---|
| 1027 | static int faimtest_parse_incoming_im_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch1_args *args) |
---|
| 1028 | { |
---|
| 1029 | owl_message *m; |
---|
[ab31454] | 1030 | char *stripmsg, *nz_screenname, *wrapmsg; |
---|
[1fdca1b] | 1031 | char *realmsg = NULL; |
---|
| 1032 | |
---|
| 1033 | if (!args->msg) { |
---|
[d4927a7] | 1034 | realmsg = g_strdup(""); |
---|
[1fdca1b] | 1035 | } else if (args->icbmflags & AIM_IMFLAGS_UNICODE) { |
---|
| 1036 | realmsg = g_convert(args->msg, args->msglen, "UTF-8", "UCS-2BE", |
---|
| 1037 | NULL, NULL, NULL); |
---|
| 1038 | } else if(args->icbmflags & AIM_IMFLAGS_ISO_8859_1) { |
---|
| 1039 | realmsg = g_convert(args->msg, args->msglen, "UTF-8", "ISO-8859-1", |
---|
| 1040 | NULL, NULL, NULL); |
---|
[d09e5a1] | 1041 | } else { |
---|
[d4927a7] | 1042 | realmsg = g_strdup(args->msg); |
---|
[1fdca1b] | 1043 | } |
---|
| 1044 | |
---|
| 1045 | if (!realmsg) { |
---|
[d4927a7] | 1046 | realmsg = g_strdup("[Error decoding incoming IM]"); |
---|
[d09e5a1] | 1047 | } |
---|
| 1048 | |
---|
[8c46404] | 1049 | owl_function_debugmsg("faimtest_parse_incoming_im_chan1: message from: %s", userinfo->sn?userinfo->sn:""); |
---|
[d09e5a1] | 1050 | /* create a message, and put it on the message queue */ |
---|
[3abf28b] | 1051 | stripmsg=owl_text_htmlstrip(realmsg); |
---|
[ab31454] | 1052 | wrapmsg=owl_text_wordwrap(stripmsg, 70); |
---|
[ae4cd12] | 1053 | nz_screenname=owl_aim_normalize_screenname(userinfo->sn); |
---|
[96828e4] | 1054 | m=g_new(owl_message, 1); |
---|
[d559df9] | 1055 | owl_message_create_aim(m, |
---|
| 1056 | nz_screenname, |
---|
| 1057 | owl_global_get_aim_screenname(&g), |
---|
[ab31454] | 1058 | wrapmsg, |
---|
[d559df9] | 1059 | OWL_MESSAGE_DIRECTION_IN, |
---|
| 1060 | 0); |
---|
[9854278] | 1061 | if (args->icbmflags & AIM_IMFLAGS_AWAY) owl_message_set_attribute(m, "isauto", ""); |
---|
[d09e5a1] | 1062 | owl_global_messagequeue_addmsg(&g, m); |
---|
[ddbbcffa] | 1063 | g_free(stripmsg); |
---|
| 1064 | g_free(wrapmsg); |
---|
| 1065 | g_free(nz_screenname); |
---|
[fd93b41] | 1066 | |
---|
| 1067 | return(1); |
---|
[8c46404] | 1068 | |
---|
| 1069 | owl_function_debugmsg("faimtest_parse_incoming_im_chan1: icbm: message: %s\n", realmsg); |
---|
[d09e5a1] | 1070 | |
---|
| 1071 | if (args->icbmflags & AIM_IMFLAGS_MULTIPART) { |
---|
| 1072 | aim_mpmsg_section_t *sec; |
---|
| 1073 | int z; |
---|
| 1074 | |
---|
[8c46404] | 1075 | owl_function_debugmsg("faimtest_parse_incoming_im_chan1: icbm: multipart: this message has %d parts\n", args->mpmsg.numparts); |
---|
[d09e5a1] | 1076 | |
---|
| 1077 | for (sec = args->mpmsg.parts, z = 0; sec; sec = sec->next, z++) { |
---|
| 1078 | if ((sec->charset == 0x0000) || (sec->charset == 0x0003) || (sec->charset == 0xffff)) { |
---|
[8c46404] | 1079 | owl_function_debugmsg("faimtest_parse_incoming_im_chan1: icbm: multipart: part %d: charset 0x%04x, subset 0x%04x, msg = %s\n", z, sec->charset, sec->charsubset, sec->data); |
---|
[d09e5a1] | 1080 | } else { |
---|
[8c46404] | 1081 | owl_function_debugmsg("faimtest_parse_incoming_im_chan1: icbm: multipart: part %d: charset 0x%04x, subset 0x%04x, binary or UNICODE data\n", z, sec->charset, sec->charsubset); |
---|
[d09e5a1] | 1082 | } |
---|
| 1083 | } |
---|
| 1084 | } |
---|
| 1085 | |
---|
| 1086 | if (args->icbmflags & AIM_IMFLAGS_HASICON) { |
---|
[651560f] | 1087 | /* aim_send_im(sess, userinfo->sn, AIM_IMFLAGS_BUDDYREQ, "You have an icon"); */ |
---|
[f278ff3] | 1088 | owl_function_debugmsg("faimtest_parse_incoming_im_chan1: icbm: their icon: iconstamp = %ld, iconlen = 0x%08x, iconsum = 0x%04x\n", args->iconstamp, args->iconlen, args->iconsum); |
---|
[d09e5a1] | 1089 | } |
---|
[fd93b41] | 1090 | |
---|
[ddbbcffa] | 1091 | g_free(realmsg); |
---|
[1fdca1b] | 1092 | |
---|
[8c92848] | 1093 | return(1); |
---|
[d09e5a1] | 1094 | } |
---|
| 1095 | |
---|
| 1096 | /* |
---|
| 1097 | * Channel 2: Rendevous Request |
---|
| 1098 | */ |
---|
| 1099 | static int faimtest_parse_incoming_im_chan2(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args) |
---|
| 1100 | { |
---|
| 1101 | /* |
---|
| 1102 | printf("rendezvous: source sn = %s\n", userinfo->sn); |
---|
| 1103 | printf("rendezvous: \twarnlevel = %f\n", aim_userinfo_warnlevel(userinfo)); |
---|
| 1104 | printf("rendezvous: \tclass = 0x%04x = ", userinfo->flags); |
---|
| 1105 | printuserflags(userinfo->flags); |
---|
| 1106 | printf("\n"); |
---|
| 1107 | |
---|
| 1108 | printf("rendezvous: \tonlinesince = %lu\n", userinfo->onlinesince); |
---|
| 1109 | printf("rendezvous: \tidletime = 0x%04x\n", userinfo->idletime); |
---|
| 1110 | |
---|
| 1111 | printf("rendezvous: message/description = %s\n", args->msg); |
---|
| 1112 | printf("rendezvous: encoding = %s\n", args->encoding); |
---|
| 1113 | printf("rendezvous: language = %s\n", args->language); |
---|
| 1114 | */ |
---|
| 1115 | |
---|
[f4d0975] | 1116 | if (args->reqclass == AIM_CAPS_SENDFILE) { |
---|
[8c46404] | 1117 | owl_function_debugmsg("faimtest_parse_incoming_im_chan2: send file!"); |
---|
[d09e5a1] | 1118 | } else if (args->reqclass == AIM_CAPS_CHAT) { |
---|
[8c46404] | 1119 | owl_function_debugmsg("faimtest_parse_incoming_im_chan2: chat invite: %s, %i, %i", args->info.chat.roominfo.name, args->info.chat.roominfo.exchange, args->info.chat.roominfo.instance); |
---|
[d09e5a1] | 1120 | /* |
---|
| 1121 | printf("chat invitation: room name = %s\n", args->info.chat.roominfo.name); |
---|
| 1122 | printf("chat invitation: exchange = 0x%04x\n", args->info.chat.roominfo.exchange); |
---|
| 1123 | printf("chat invitation: instance = 0x%04x\n", args->info.chat.roominfo.instance); |
---|
| 1124 | */ |
---|
| 1125 | /* Automatically join room... */ |
---|
| 1126 | /* printf("chat invitiation: autojoining %s...\n", args->info.chat.roominfo.name); */ |
---|
[fd93b41] | 1127 | |
---|
| 1128 | /* aim_chat_join(sess, conn, args->info.chat.roominfo.exchange, args->info.chat.roominfo.name, args->info.chat.roominfo.instance); */ |
---|
[d09e5a1] | 1129 | } else if (args->reqclass == AIM_CAPS_BUDDYICON) { |
---|
[f278ff3] | 1130 | owl_function_debugmsg("faimtest_parse_incoming_im_chan2: Buddy Icon from %s, length = %u\n", |
---|
[8c46404] | 1131 | userinfo->sn, args->info.icon.length); |
---|
[d09e5a1] | 1132 | } else if (args->reqclass == AIM_CAPS_ICQRTF) { |
---|
[f278ff3] | 1133 | owl_function_debugmsg("faimtest_parse_incoming_im_chan2: RTF message from %s: (fgcolor = 0x%08x, bgcolor = 0x%08x) %s\n", |
---|
[8c46404] | 1134 | userinfo->sn, args->info.rtfmsg.fgcolor, args->info.rtfmsg.bgcolor, args->info.rtfmsg.rtfmsg); |
---|
[d09e5a1] | 1135 | } else { |
---|
[8c46404] | 1136 | owl_function_debugmsg("faimtest_parse_incoming_im_chan2: icbm: unknown reqclass (%d)\n", args->reqclass); |
---|
[d09e5a1] | 1137 | } |
---|
| 1138 | return 1; |
---|
| 1139 | } |
---|
| 1140 | |
---|
| 1141 | static int faimtest_parse_incoming_im(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1142 | { |
---|
| 1143 | fu16_t channel; |
---|
| 1144 | aim_userinfo_t *userinfo; |
---|
| 1145 | va_list ap; |
---|
| 1146 | int ret = 0; |
---|
| 1147 | |
---|
| 1148 | va_start(ap, fr); |
---|
| 1149 | channel = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1150 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1151 | |
---|
| 1152 | if (channel == 1) { |
---|
| 1153 | struct aim_incomingim_ch1_args *args; |
---|
| 1154 | args = va_arg(ap, struct aim_incomingim_ch1_args *); |
---|
| 1155 | ret = faimtest_parse_incoming_im_chan1(sess, fr->conn, userinfo, args); |
---|
| 1156 | } else if (channel == 2) { |
---|
| 1157 | struct aim_incomingim_ch2_args *args; |
---|
| 1158 | args = va_arg(ap, struct aim_incomingim_ch2_args *); |
---|
| 1159 | ret = faimtest_parse_incoming_im_chan2(sess, fr->conn, userinfo, args); |
---|
| 1160 | } else { |
---|
[8c46404] | 1161 | owl_function_debugmsg("faimtest_parse_incoming_im: unsupported channel 0x%04x\n", channel); |
---|
[d09e5a1] | 1162 | } |
---|
| 1163 | va_end(ap); |
---|
[8c46404] | 1164 | owl_function_debugmsg("faimtest_parse_incoming_im: done with ICBM handling (ret = %d)\n", ret); |
---|
[d09e5a1] | 1165 | return 1; |
---|
| 1166 | } |
---|
| 1167 | |
---|
| 1168 | static int faimtest_parse_oncoming(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1169 | { |
---|
| 1170 | aim_userinfo_t *userinfo; |
---|
[ae4cd12] | 1171 | char *nz_screenname; |
---|
[f4d0975] | 1172 | owl_buddy *b; |
---|
[d09e5a1] | 1173 | va_list ap; |
---|
| 1174 | va_start(ap, fr); |
---|
| 1175 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1176 | va_end(ap); |
---|
[aa5f725] | 1177 | |
---|
[ae4cd12] | 1178 | nz_screenname=owl_aim_normalize_screenname(userinfo->sn); |
---|
[f4d0975] | 1179 | |
---|
[ae4cd12] | 1180 | owl_buddylist_oncoming(owl_global_get_buddylist(&g), nz_screenname); |
---|
[f4d0975] | 1181 | |
---|
| 1182 | if (userinfo->present & AIM_USERINFO_PRESENT_IDLE) { |
---|
[8c46404] | 1183 | owl_function_debugmsg("faimtest_parseoncoming: in empty part of userinfo present and present idle"); |
---|
[f4d0975] | 1184 | } |
---|
| 1185 | |
---|
| 1186 | b=owl_buddylist_get_aim_buddy(owl_global_get_buddylist(&g), nz_screenname); |
---|
| 1187 | if (!b) { |
---|
| 1188 | owl_function_debugmsg("Error: parse_oncoming setting idle time with no buddy present."); |
---|
| 1189 | return(1); |
---|
| 1190 | } |
---|
| 1191 | if (userinfo->idletime==0) { |
---|
| 1192 | owl_buddy_set_unidle(b); |
---|
| 1193 | } else { |
---|
| 1194 | owl_buddy_set_idle(b); |
---|
| 1195 | owl_buddy_set_idle_since(b, userinfo->idletime); |
---|
| 1196 | } |
---|
[8c92848] | 1197 | |
---|
| 1198 | if (userinfo->flags & AIM_FLAG_AWAY) { |
---|
| 1199 | owl_function_debugmsg("parse_oncoming sn: %s away flag!", userinfo->sn); |
---|
| 1200 | } |
---|
| 1201 | |
---|
[f4d0975] | 1202 | owl_function_debugmsg("parse_oncoming sn: %s idle: %i", userinfo->sn, userinfo->idletime); |
---|
| 1203 | |
---|
[ddbbcffa] | 1204 | g_free(nz_screenname); |
---|
[aa5f725] | 1205 | |
---|
[d09e5a1] | 1206 | /* |
---|
| 1207 | printf("%ld %s is now online (flags: %04x = %s%s%s%s%s%s%s%s) (caps = %s = 0x%08lx)\n", |
---|
| 1208 | time(NULL), |
---|
| 1209 | userinfo->sn, userinfo->flags, |
---|
| 1210 | (userinfo->flags&AIM_FLAG_UNCONFIRMED)?" UNCONFIRMED":"", |
---|
| 1211 | (userinfo->flags&AIM_FLAG_ADMINISTRATOR)?" ADMINISTRATOR":"", |
---|
| 1212 | (userinfo->flags&AIM_FLAG_AOL)?" AOL":"", |
---|
| 1213 | (userinfo->flags&AIM_FLAG_OSCAR_PAY)?" OSCAR_PAY":"", |
---|
| 1214 | (userinfo->flags&AIM_FLAG_FREE)?" FREE":"", |
---|
| 1215 | (userinfo->flags&AIM_FLAG_AWAY)?" AWAY":"", |
---|
| 1216 | (userinfo->flags&AIM_FLAG_ICQ)?" ICQ":"", |
---|
| 1217 | (userinfo->flags&AIM_FLAG_WIRELESS)?" WIRELESS":"", |
---|
| 1218 | (userinfo->present & AIM_USERINFO_PRESENT_CAPABILITIES) ? "present" : "not present", |
---|
| 1219 | userinfo->capabilities); |
---|
| 1220 | */ |
---|
[aa5f725] | 1221 | return(1); |
---|
[d09e5a1] | 1222 | } |
---|
| 1223 | |
---|
| 1224 | static int faimtest_parse_offgoing(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1225 | { |
---|
| 1226 | aim_userinfo_t *userinfo; |
---|
[ae4cd12] | 1227 | char *nz_screenname; |
---|
[d09e5a1] | 1228 | va_list ap; |
---|
| 1229 | |
---|
| 1230 | va_start(ap, fr); |
---|
| 1231 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1232 | va_end(ap); |
---|
| 1233 | |
---|
[ae4cd12] | 1234 | nz_screenname=owl_aim_normalize_screenname(userinfo->sn); |
---|
| 1235 | owl_buddylist_offgoing(owl_global_get_buddylist(&g), nz_screenname); |
---|
[ddbbcffa] | 1236 | g_free(nz_screenname); |
---|
[aa5f725] | 1237 | |
---|
[f4d0975] | 1238 | if (userinfo->present & AIM_USERINFO_PRESENT_IDLE) { |
---|
| 1239 | owl_function_debugmsg("parse_offgoing sn: %s idle time %i", userinfo->sn, userinfo->idletime); |
---|
| 1240 | } |
---|
| 1241 | |
---|
[d09e5a1] | 1242 | /* |
---|
| 1243 | printf("%ld %s is now offline (flags: %04x = %s%s%s%s%s%s%s%s) (caps = %s = 0x%08lx)\n", |
---|
| 1244 | time(NULL), |
---|
| 1245 | userinfo->sn, userinfo->flags, |
---|
| 1246 | (userinfo->flags&AIM_FLAG_UNCONFIRMED)?" UNCONFIRMED":"", |
---|
| 1247 | (userinfo->flags&AIM_FLAG_ADMINISTRATOR)?" ADMINISTRATOR":"", |
---|
| 1248 | (userinfo->flags&AIM_FLAG_AOL)?" AOL":"", |
---|
| 1249 | (userinfo->flags&AIM_FLAG_OSCAR_PAY)?" OSCAR_PAY":"", |
---|
| 1250 | (userinfo->flags&AIM_FLAG_FREE)?" FREE":"", |
---|
| 1251 | (userinfo->flags&AIM_FLAG_AWAY)?" AWAY":"", |
---|
| 1252 | (userinfo->flags&AIM_FLAG_ICQ)?" ICQ":"", |
---|
| 1253 | (userinfo->flags&AIM_FLAG_WIRELESS)?" WIRELESS":"", |
---|
| 1254 | (userinfo->present & AIM_USERINFO_PRESENT_CAPABILITIES) ? "present" : "not present", |
---|
| 1255 | userinfo->capabilities); |
---|
| 1256 | */ |
---|
| 1257 | |
---|
| 1258 | return 1; |
---|
| 1259 | } |
---|
| 1260 | |
---|
| 1261 | /* Used by chat as well. */ |
---|
| 1262 | int faimtest_parse_genericerr(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1263 | { |
---|
| 1264 | va_list ap; |
---|
| 1265 | fu16_t reason; |
---|
| 1266 | |
---|
| 1267 | va_start(ap, fr); |
---|
| 1268 | reason = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1269 | va_end(ap); |
---|
| 1270 | |
---|
| 1271 | /* printf("snac threw error (reason 0x%04x: %s)\n", reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */ |
---|
[554a2b8] | 1272 | if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]); |
---|
[d09e5a1] | 1273 | |
---|
| 1274 | return 1; |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | static int faimtest_parse_msgerr(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1278 | { |
---|
| 1279 | va_list ap; |
---|
[e19eb97] | 1280 | const char *destsn; |
---|
[d09e5a1] | 1281 | fu16_t reason; |
---|
| 1282 | |
---|
| 1283 | va_start(ap, fr); |
---|
| 1284 | reason = (fu16_t)va_arg(ap, unsigned int); |
---|
[e19eb97] | 1285 | destsn = va_arg(ap, const char *); |
---|
[d09e5a1] | 1286 | va_end(ap); |
---|
| 1287 | |
---|
| 1288 | /* printf("message to %s bounced (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */ |
---|
[554a2b8] | 1289 | if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]); |
---|
[a836200] | 1290 | |
---|
| 1291 | if (reason==4) { |
---|
| 1292 | owl_function_adminmsg("", "Could not send AIM message, user not logged on"); |
---|
| 1293 | } |
---|
[d09e5a1] | 1294 | |
---|
| 1295 | return 1; |
---|
| 1296 | } |
---|
| 1297 | |
---|
| 1298 | static int faimtest_parse_locerr(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1299 | { |
---|
| 1300 | va_list ap; |
---|
[e19eb97] | 1301 | const char *destsn; |
---|
[d09e5a1] | 1302 | fu16_t reason; |
---|
| 1303 | |
---|
| 1304 | va_start(ap, fr); |
---|
| 1305 | reason = (fu16_t)va_arg(ap, unsigned int); |
---|
[e19eb97] | 1306 | destsn = va_arg(ap, const char *); |
---|
[d09e5a1] | 1307 | va_end(ap); |
---|
| 1308 | |
---|
| 1309 | /* printf("user information for %s unavailable (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */ |
---|
[554a2b8] | 1310 | if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]); |
---|
[d09e5a1] | 1311 | |
---|
| 1312 | return 1; |
---|
| 1313 | } |
---|
| 1314 | |
---|
| 1315 | static int faimtest_parse_misses(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1316 | { |
---|
[e19eb97] | 1317 | static const char *missedreasons[] = { |
---|
[d09e5a1] | 1318 | "Invalid (0)", |
---|
| 1319 | "Message too large", |
---|
| 1320 | "Rate exceeded", |
---|
| 1321 | "Evil Sender", |
---|
| 1322 | "Evil Receiver" |
---|
| 1323 | }; |
---|
[8c46404] | 1324 | static int missedreasonslen = 5; |
---|
[d09e5a1] | 1325 | |
---|
| 1326 | va_list ap; |
---|
| 1327 | fu16_t chan, nummissed, reason; |
---|
| 1328 | aim_userinfo_t *userinfo; |
---|
| 1329 | |
---|
| 1330 | va_start(ap, fr); |
---|
| 1331 | chan = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1332 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1333 | nummissed = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1334 | reason = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1335 | va_end(ap); |
---|
| 1336 | |
---|
[8c46404] | 1337 | owl_function_debugmsg("faimtest_parse_misses: missed %d messages from %s on channel %d (reason %d: %s)\n", nummissed, userinfo->sn, chan, reason, (reason<missedreasonslen)?missedreasons[reason]:"unknown"); |
---|
[d09e5a1] | 1338 | |
---|
| 1339 | return 1; |
---|
| 1340 | } |
---|
| 1341 | |
---|
| 1342 | /* |
---|
| 1343 | * Received in response to an IM sent with the AIM_IMFLAGS_ACK option. |
---|
| 1344 | */ |
---|
| 1345 | static int faimtest_parse_msgack(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1346 | { |
---|
| 1347 | va_list ap; |
---|
| 1348 | fu16_t type; |
---|
[e19eb97] | 1349 | const char *sn = NULL; |
---|
[d09e5a1] | 1350 | |
---|
| 1351 | va_start(ap, fr); |
---|
| 1352 | type = (fu16_t)va_arg(ap, unsigned int); |
---|
[e19eb97] | 1353 | sn = va_arg(ap, const char *); |
---|
[d09e5a1] | 1354 | va_end(ap); |
---|
| 1355 | |
---|
[8c46404] | 1356 | owl_function_debugmsg("faimtest_parse_msgack: 0x%04x / %s\n", type, sn); |
---|
[d09e5a1] | 1357 | |
---|
| 1358 | return 1; |
---|
| 1359 | } |
---|
| 1360 | |
---|
| 1361 | static int faimtest_parse_ratechange(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1362 | { |
---|
[e19eb97] | 1363 | static const char *codes[5] = { |
---|
[d09e5a1] | 1364 | "invalid", |
---|
| 1365 | "change", |
---|
| 1366 | "warning", |
---|
| 1367 | "limit", |
---|
| 1368 | "limit cleared" |
---|
| 1369 | }; |
---|
| 1370 | va_list ap; |
---|
| 1371 | fu16_t code, rateclass; |
---|
| 1372 | fu32_t windowsize, clear, alert, limit, disconnect; |
---|
| 1373 | fu32_t currentavg, maxavg; |
---|
| 1374 | |
---|
| 1375 | va_start(ap, fr); |
---|
| 1376 | |
---|
| 1377 | /* See code explanations below */ |
---|
| 1378 | code = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1379 | |
---|
| 1380 | /* |
---|
| 1381 | * See comments above aim_parse_ratechange_middle() in aim_rxhandlers.c. |
---|
| 1382 | */ |
---|
| 1383 | rateclass = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1384 | |
---|
| 1385 | /* |
---|
| 1386 | * Not sure what this is exactly. I think its the temporal |
---|
| 1387 | * relation factor (ie, how to make the rest of the numbers |
---|
| 1388 | * make sense in the real world). |
---|
| 1389 | */ |
---|
| 1390 | windowsize = va_arg(ap, fu32_t); |
---|
| 1391 | |
---|
| 1392 | /* Explained below */ |
---|
| 1393 | clear = va_arg(ap, fu32_t); |
---|
| 1394 | alert = va_arg(ap, fu32_t); |
---|
| 1395 | limit = va_arg(ap, fu32_t); |
---|
| 1396 | disconnect = va_arg(ap, fu32_t); |
---|
| 1397 | currentavg = va_arg(ap, fu32_t); |
---|
| 1398 | maxavg = va_arg(ap, fu32_t); |
---|
| 1399 | |
---|
| 1400 | va_end(ap); |
---|
| 1401 | |
---|
[f278ff3] | 1402 | owl_function_debugmsg("faimtest_parse_ratechange: rate %s (rate class 0x%04x): curavg = %u, maxavg = %u, alert at %u, clear warning at %u, limit at %u, disconnect at %u (window size = %u)", |
---|
[8c46404] | 1403 | (code < 5)?codes[code]:"invalid", |
---|
| 1404 | rateclass, |
---|
| 1405 | currentavg, maxavg, |
---|
| 1406 | alert, clear, |
---|
| 1407 | limit, disconnect, |
---|
| 1408 | windowsize); |
---|
[d09e5a1] | 1409 | return 1; |
---|
| 1410 | } |
---|
| 1411 | |
---|
| 1412 | static int faimtest_parse_evilnotify(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1413 | { |
---|
| 1414 | va_list ap; |
---|
| 1415 | fu16_t newevil; |
---|
| 1416 | aim_userinfo_t *userinfo; |
---|
| 1417 | |
---|
| 1418 | va_start(ap, fr); |
---|
| 1419 | newevil = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1420 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1421 | va_end(ap); |
---|
| 1422 | |
---|
| 1423 | /* |
---|
| 1424 | * Evil Notifications that are lacking userinfo->sn are anon-warns |
---|
| 1425 | * if they are an evil increases, but are not warnings at all if its |
---|
| 1426 | * a decrease (its the natural backoff happening). |
---|
| 1427 | * |
---|
| 1428 | * newevil is passed as an int representing the new evil value times |
---|
| 1429 | * ten. |
---|
| 1430 | */ |
---|
[8c46404] | 1431 | owl_function_debugmsg("faimtest_parse_evilnotify: new value = %2.1f%% (caused by %s)\n", ((float)newevil)/10, (userinfo && strlen(userinfo->sn))?userinfo->sn:"anonymous"); |
---|
[d09e5a1] | 1432 | |
---|
| 1433 | return 1; |
---|
| 1434 | } |
---|
| 1435 | |
---|
| 1436 | static int faimtest_parse_searchreply(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1437 | { |
---|
| 1438 | va_list ap; |
---|
[e19eb97] | 1439 | const char *address, *SNs; |
---|
[8c46404] | 1440 | int num, i; |
---|
[e4524da] | 1441 | GPtrArray *list; |
---|
[d09e5a1] | 1442 | |
---|
| 1443 | va_start(ap, fr); |
---|
[e19eb97] | 1444 | address = va_arg(ap, const char *); |
---|
[d09e5a1] | 1445 | num = va_arg(ap, int); |
---|
[e19eb97] | 1446 | SNs = va_arg(ap, const char *); |
---|
[d09e5a1] | 1447 | va_end(ap); |
---|
[952bb256] | 1448 | |
---|
[e4524da] | 1449 | list = g_ptr_array_new(); |
---|
[d09e5a1] | 1450 | |
---|
[8c46404] | 1451 | owl_function_debugmsg("faimtest_parse_searchreply: E-Mail Search Results for %s: ", address); |
---|
[952bb256] | 1452 | for (i=0; i<num; i++) { |
---|
[8c46404] | 1453 | owl_function_debugmsg(" %s", &SNs[i*(MAXSNLEN+1)]); |
---|
[e4524da] | 1454 | g_ptr_array_add(list, (void *)&SNs[i*(MAXSNLEN+1)]); |
---|
[8c46404] | 1455 | } |
---|
[e4524da] | 1456 | owl_function_aimsearch_results(address, list); |
---|
| 1457 | g_ptr_array_free(list, true); |
---|
| 1458 | return 1; |
---|
[d09e5a1] | 1459 | } |
---|
| 1460 | |
---|
| 1461 | static int faimtest_parse_searcherror(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1462 | { |
---|
| 1463 | va_list ap; |
---|
[e19eb97] | 1464 | const char *address; |
---|
[d09e5a1] | 1465 | |
---|
| 1466 | va_start(ap, fr); |
---|
[e19eb97] | 1467 | address = va_arg(ap, const char *); |
---|
[d09e5a1] | 1468 | va_end(ap); |
---|
[952bb256] | 1469 | |
---|
| 1470 | owl_function_error("No results searching for %s", address); |
---|
[8c46404] | 1471 | owl_function_debugmsg("faimtest_parse_searcherror: E-Mail Search Results for %s: No Results or Invalid Email\n", address); |
---|
[d09e5a1] | 1472 | |
---|
[952bb256] | 1473 | return(1); |
---|
[d09e5a1] | 1474 | } |
---|
| 1475 | |
---|
| 1476 | static int handlepopup(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1477 | { |
---|
| 1478 | va_list ap; |
---|
[e19eb97] | 1479 | const char *msg, *url; |
---|
[d09e5a1] | 1480 | fu16_t width, height, delay; |
---|
| 1481 | |
---|
| 1482 | va_start(ap, fr); |
---|
[e19eb97] | 1483 | msg = va_arg(ap, const char *); |
---|
| 1484 | url = va_arg(ap, const char *); |
---|
[d09e5a1] | 1485 | width = va_arg(ap, unsigned int); |
---|
| 1486 | height = va_arg(ap, unsigned int); |
---|
| 1487 | delay = va_arg(ap, unsigned int); |
---|
| 1488 | va_end(ap); |
---|
| 1489 | |
---|
[8c46404] | 1490 | owl_function_debugmsg("handlepopup: (%dx%x:%d) %s (%s)\n", width, height, delay, msg, url); |
---|
[d09e5a1] | 1491 | |
---|
| 1492 | return 1; |
---|
| 1493 | } |
---|
| 1494 | |
---|
| 1495 | static int serverpause(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1496 | { |
---|
| 1497 | aim_sendpauseack(sess, fr->conn); |
---|
| 1498 | return 1; |
---|
| 1499 | } |
---|
| 1500 | |
---|
| 1501 | static int migrate(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1502 | { |
---|
| 1503 | va_list ap; |
---|
| 1504 | aim_conn_t *bosconn; |
---|
[e19eb97] | 1505 | const char *bosip; |
---|
[d09e5a1] | 1506 | fu8_t *cookie; |
---|
| 1507 | |
---|
| 1508 | va_start(ap, fr); |
---|
[e19eb97] | 1509 | bosip = va_arg(ap, const char *); |
---|
[d09e5a1] | 1510 | cookie = va_arg(ap, fu8_t *); |
---|
| 1511 | va_end(ap); |
---|
| 1512 | |
---|
[8c46404] | 1513 | owl_function_debugmsg("migrate: migration in progress -- new BOS is %s -- disconnecting", bosip); |
---|
[d09e5a1] | 1514 | aim_conn_kill(sess, &fr->conn); |
---|
| 1515 | |
---|
| 1516 | if (!(bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, bosip))) { |
---|
[8c46404] | 1517 | owl_function_debugmsg("migrate: could not connect to BOS: internal error"); |
---|
[d09e5a1] | 1518 | return 1; |
---|
| 1519 | } else if (bosconn->status & AIM_CONN_STATUS_CONNERR) { |
---|
[8c46404] | 1520 | owl_function_debugmsg("migrate: could not connect to BOS"); |
---|
[d09e5a1] | 1521 | aim_conn_kill(sess, &bosconn); |
---|
| 1522 | return 1; |
---|
| 1523 | } |
---|
| 1524 | |
---|
| 1525 | /* Login will happen all over again. */ |
---|
| 1526 | addcb_bos(sess, bosconn); |
---|
[8c46404] | 1527 | /* aim_sendcookie(sess, bosconn, cookie); */ /********/ |
---|
[d09e5a1] | 1528 | return 1; |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | static int ssirights(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1532 | { |
---|
[8c46404] | 1533 | owl_function_debugmsg("ssirights: got SSI rights, requesting data\n"); |
---|
[f4d0975] | 1534 | /* aim_ssi_reqdata(sess, fr->conn, 0, 0x0000); */ |
---|
| 1535 | aim_ssi_reqdata(sess); |
---|
[d09e5a1] | 1536 | |
---|
[8c92848] | 1537 | return(1); |
---|
[d09e5a1] | 1538 | } |
---|
| 1539 | |
---|
| 1540 | static int ssidata(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1541 | { |
---|
| 1542 | va_list ap; |
---|
| 1543 | fu8_t fmtver; |
---|
| 1544 | fu16_t itemcount; |
---|
| 1545 | fu32_t stamp; |
---|
[f4d0975] | 1546 | struct aim_ssi_item *list; |
---|
[cdf0ef1] | 1547 | /* |
---|
[f4d0975] | 1548 | struct aim_ssi_item *curitem; |
---|
[8c46404] | 1549 | struct aim_ssi_item *l; |
---|
[cdf0ef1] | 1550 | */ |
---|
[d09e5a1] | 1551 | |
---|
| 1552 | va_start(ap, fr); |
---|
| 1553 | fmtver = va_arg(ap, unsigned int); |
---|
| 1554 | itemcount = va_arg(ap, unsigned int); |
---|
| 1555 | stamp = va_arg(ap, fu32_t); |
---|
| 1556 | list = va_arg(ap, struct aim_ssi_item *); |
---|
| 1557 | va_end(ap); |
---|
| 1558 | |
---|
[f278ff3] | 1559 | owl_function_debugmsg("ssiddata: got SSI data (0x%02x, %d items, %u)", fmtver, itemcount, stamp); |
---|
[8c46404] | 1560 | /* |
---|
[f4d0975] | 1561 | for (curitem=sess->ssi.local; curitem; curitem=curitem->next) { |
---|
[8c46404] | 1562 | for (l = list; l; l = l->next) { |
---|
| 1563 | owl_function_debugmsg("\t0x%04x (%s) - 0x%04x/0x%04x", l->type, l->name, l->gid, l->bid); |
---|
| 1564 | } |
---|
[d09e5a1] | 1565 | } |
---|
[8c46404] | 1566 | */ |
---|
[f4d0975] | 1567 | aim_ssi_enable(sess); |
---|
[d09e5a1] | 1568 | |
---|
| 1569 | return 1; |
---|
| 1570 | } |
---|
| 1571 | |
---|
| 1572 | static int ssidatanochange(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1573 | { |
---|
[8c46404] | 1574 | owl_function_debugmsg("ssidatanochange: server says we have the latest SSI data already"); |
---|
[f4d0975] | 1575 | /* aim_ssi_enable(sess, fr->conn); */ |
---|
| 1576 | aim_ssi_enable(sess); |
---|
[d09e5a1] | 1577 | return 1; |
---|
| 1578 | } |
---|
| 1579 | |
---|
| 1580 | static int offlinemsg(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1581 | { |
---|
| 1582 | va_list ap; |
---|
| 1583 | struct aim_icq_offlinemsg *msg; |
---|
| 1584 | |
---|
| 1585 | va_start(ap, fr); |
---|
| 1586 | msg = va_arg(ap, struct aim_icq_offlinemsg *); |
---|
| 1587 | va_end(ap); |
---|
| 1588 | |
---|
| 1589 | if (msg->type == 0x0001) { |
---|
[f278ff3] | 1590 | owl_function_debugmsg("offlinemsg: from %u at %d/%d/%d %02d:%02d : %s", msg->sender, msg->year, msg->month, msg->day, msg->hour, msg->minute, msg->msg); |
---|
[d09e5a1] | 1591 | } else { |
---|
[8c46404] | 1592 | owl_function_debugmsg("unknown offline message type 0x%04x", msg->type); |
---|
[d09e5a1] | 1593 | } |
---|
| 1594 | return 1; |
---|
| 1595 | } |
---|
| 1596 | |
---|
| 1597 | static int offlinemsgdone(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1598 | { |
---|
| 1599 | /* Tell the server to delete them. */ |
---|
[8c46404] | 1600 | owl_function_debugmsg("offlinemsg done: "); |
---|
[d09e5a1] | 1601 | aim_icq_ackofflinemsgs(sess); |
---|
| 1602 | return 1; |
---|
| 1603 | } |
---|
| 1604 | |
---|
| 1605 | |
---|
| 1606 | /******************** chat.c **************************/ |
---|
| 1607 | |
---|
| 1608 | static int faimtest_chat_join(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1609 | { |
---|
| 1610 | va_list ap; |
---|
| 1611 | aim_userinfo_t *userinfo; |
---|
[0ff8fb57] | 1612 | int count; |
---|
| 1613 | /* int i; */ |
---|
[d09e5a1] | 1614 | |
---|
| 1615 | va_start(ap, fr); |
---|
| 1616 | count = va_arg(ap, int); |
---|
| 1617 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1618 | va_end(ap); |
---|
| 1619 | |
---|
[8c92848] | 1620 | owl_function_debugmsg("In faimtest_chat_join"); |
---|
[d09e5a1] | 1621 | /* |
---|
| 1622 | printf("chat: %s: New occupants have joined:\n", aim_chat_getname(fr->conn)); |
---|
| 1623 | for (i = 0; i < count; i++) |
---|
| 1624 | printf("chat: %s: \t%s\n", aim_chat_getname(fr->conn), userinfo[i].sn); |
---|
| 1625 | */ |
---|
| 1626 | return 1; |
---|
| 1627 | } |
---|
| 1628 | |
---|
| 1629 | static int faimtest_chat_leave(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1630 | { |
---|
| 1631 | aim_userinfo_t *userinfo; |
---|
[0ff8fb57] | 1632 | va_list ap; |
---|
| 1633 | int count; |
---|
| 1634 | /* int i; */ |
---|
| 1635 | |
---|
[d09e5a1] | 1636 | |
---|
| 1637 | va_start(ap, fr); |
---|
| 1638 | count = va_arg(ap, int); |
---|
| 1639 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
| 1640 | va_end(ap); |
---|
| 1641 | |
---|
| 1642 | /* |
---|
| 1643 | printf("chat: %s: Some occupants have left:\n", aim_chat_getname(fr->conn)); |
---|
| 1644 | |
---|
| 1645 | for (i = 0; i < count; i++) |
---|
| 1646 | printf("chat: %s: \t%s\n", aim_chat_getname(fr->conn), userinfo[i].sn); |
---|
| 1647 | */ |
---|
| 1648 | return 1; |
---|
| 1649 | } |
---|
| 1650 | |
---|
| 1651 | static int faimtest_chat_infoupdate(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1652 | { |
---|
| 1653 | va_list ap; |
---|
| 1654 | aim_userinfo_t *userinfo; |
---|
| 1655 | struct aim_chat_roominfo *roominfo; |
---|
[e19eb97] | 1656 | const char *roomname; |
---|
[0ff8fb57] | 1657 | int usercount; |
---|
[e19eb97] | 1658 | const char *roomdesc; |
---|
[d09e5a1] | 1659 | fu16_t flags, unknown_d2, unknown_d5, maxmsglen, maxvisiblemsglen; |
---|
| 1660 | fu32_t creationtime; |
---|
| 1661 | const char *croomname; |
---|
[0ff8fb57] | 1662 | /* int i; */ |
---|
[d09e5a1] | 1663 | |
---|
| 1664 | croomname = aim_chat_getname(fr->conn); |
---|
| 1665 | |
---|
| 1666 | va_start(ap, fr); |
---|
| 1667 | roominfo = va_arg(ap, struct aim_chat_roominfo *); |
---|
[e19eb97] | 1668 | roomname = va_arg(ap, const char *); |
---|
[d09e5a1] | 1669 | usercount = va_arg(ap, int); |
---|
| 1670 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
[e19eb97] | 1671 | roomdesc = va_arg(ap, const char *); |
---|
[d09e5a1] | 1672 | flags = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1673 | creationtime = va_arg(ap, fu32_t); |
---|
| 1674 | maxmsglen = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1675 | unknown_d2 = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1676 | unknown_d5 = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1677 | maxvisiblemsglen = (fu16_t)va_arg(ap, unsigned int); |
---|
| 1678 | va_end(ap); |
---|
| 1679 | |
---|
[8c92848] | 1680 | owl_function_debugmsg("In faimtest_chat_infoupdate"); |
---|
[d09e5a1] | 1681 | /* |
---|
| 1682 | printf("chat: %s: info update:\n", croomname); |
---|
| 1683 | printf("chat: %s: \tRoominfo: {%04x, %s, %04x}\n", croomname, roominfo->exchange, roominfo->name, roominfo->instance); |
---|
| 1684 | printf("chat: %s: \tRoomname: %s\n", croomname, roomname); |
---|
| 1685 | printf("chat: %s: \tRoomdesc: %s\n", croomname, roomdesc); |
---|
| 1686 | printf("chat: %s: \tOccupants: (%d)\n", croomname, usercount); |
---|
| 1687 | |
---|
| 1688 | for (i = 0; i < usercount; i++) |
---|
| 1689 | printf("chat: %s: \t\t%s\n", croomname, userinfo[i].sn); |
---|
| 1690 | |
---|
[8c92848] | 1691 | owl_function_debugmsg("chat: %s: \tRoom flags: 0x%04x (%s%s%s%s)\n", |
---|
[d09e5a1] | 1692 | croomname, flags, |
---|
| 1693 | (flags & AIM_CHATROOM_FLAG_EVILABLE) ? "Evilable, " : "", |
---|
| 1694 | (flags & AIM_CHATROOM_FLAG_NAV_ONLY) ? "Nav Only, " : "", |
---|
| 1695 | (flags & AIM_CHATROOM_FLAG_INSTANCING_ALLOWED) ? "Instancing allowed, " : "", |
---|
| 1696 | (flags & AIM_CHATROOM_FLAG_OCCUPANT_PEEK_ALLOWED) ? "Occupant peek allowed, " : ""); |
---|
| 1697 | printf("chat: %s: \tCreation time: %lu (time_t)\n", croomname, creationtime); |
---|
| 1698 | printf("chat: %s: \tUnknown_d2: 0x%04x\n", croomname, unknown_d2); |
---|
| 1699 | printf("chat: %s: \tUnknown_d5: 0x%02x\n", croomname, unknown_d5); |
---|
| 1700 | printf("chat: %s: \tMax message length: %d bytes\n", croomname, maxmsglen); |
---|
| 1701 | printf("chat: %s: \tMax visible message length: %d bytes\n", croomname, maxvisiblemsglen); |
---|
| 1702 | */ |
---|
| 1703 | |
---|
[8c92848] | 1704 | return(1); |
---|
[d09e5a1] | 1705 | } |
---|
| 1706 | |
---|
| 1707 | static int faimtest_chat_incomingmsg(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1708 | { |
---|
| 1709 | va_list ap; |
---|
| 1710 | aim_userinfo_t *userinfo; |
---|
[e19eb97] | 1711 | const char *msg; |
---|
[d09e5a1] | 1712 | char tmpbuf[1152]; |
---|
| 1713 | |
---|
| 1714 | va_start(ap, fr); |
---|
| 1715 | userinfo = va_arg(ap, aim_userinfo_t *); |
---|
[e19eb97] | 1716 | msg = va_arg(ap, const char *); |
---|
[d09e5a1] | 1717 | va_end(ap); |
---|
| 1718 | |
---|
[8c92848] | 1719 | owl_function_debugmsg("in faimtest_chat_incomingmsg"); |
---|
| 1720 | |
---|
[d09e5a1] | 1721 | /* |
---|
| 1722 | printf("chat: %s: incoming msg from %s: %s\n", aim_chat_getname(fr->conn), userinfo->sn, msg); |
---|
| 1723 | */ |
---|
| 1724 | |
---|
| 1725 | /* |
---|
| 1726 | * Do an echo for testing purposes. But not for ourselves ("oops!") |
---|
| 1727 | */ |
---|
| 1728 | if (strcmp(userinfo->sn, sess->sn) != 0) { |
---|
| 1729 | /* sprintf(tmpbuf, "(%s said \"%s\")", userinfo->sn, msg); */ |
---|
| 1730 | aim_chat_send_im(sess, fr->conn, 0, tmpbuf, strlen(tmpbuf)); |
---|
| 1731 | } |
---|
| 1732 | |
---|
| 1733 | return 1; |
---|
| 1734 | } |
---|
| 1735 | |
---|
| 1736 | static int conninitdone_chat(aim_session_t *sess, aim_frame_t *fr, ...) |
---|
| 1737 | { |
---|
[2674412] | 1738 | owl_function_debugmsg("faimtest_conninitdone_chat:"); |
---|
[d09e5a1] | 1739 | |
---|
[2674412] | 1740 | aim_conn_addhandler(sess, fr->conn, 0x000e, 0x0001, faimtest_parse_genericerr, 0); |
---|
| 1741 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, faimtest_chat_join, 0); |
---|
| 1742 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, faimtest_chat_leave, 0); |
---|
| 1743 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, faimtest_chat_infoupdate, 0); |
---|
| 1744 | aim_conn_addhandler(sess, fr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, faimtest_chat_incomingmsg, 0); |
---|
[8c92848] | 1745 | |
---|
[d09e5a1] | 1746 | aim_clientready(sess, fr->conn); |
---|
| 1747 | |
---|
[2674412] | 1748 | owl_function_debugmsg("Chat ready"); |
---|
| 1749 | |
---|
| 1750 | /* |
---|
| 1751 | chatcon = find_oscar_chat_by_conn(gc, fr->conn); |
---|
| 1752 | chatcon->id = id; |
---|
| 1753 | chatcon->cnv = serv_got_joined_chat(gc, id++, chatcon->show); |
---|
| 1754 | */ |
---|
| 1755 | return(1); |
---|
| 1756 | } |
---|
| 1757 | |
---|
[d09e5a1] | 1758 | void chatnav_redirect(aim_session_t *sess, struct aim_redirect_data *redir) |
---|
| 1759 | { |
---|
| 1760 | aim_conn_t *tstconn; |
---|
[8c92848] | 1761 | |
---|
| 1762 | owl_function_debugmsg("in faimtest_chatnav_redirect"); |
---|
[d09e5a1] | 1763 | |
---|
| 1764 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, redir->ip); |
---|
| 1765 | if (!tstconn || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) { |
---|
| 1766 | /* printf("unable to connect to chat(nav) server\n"); */ |
---|
| 1767 | if (tstconn) |
---|
| 1768 | aim_conn_kill(sess, &tstconn); |
---|
| 1769 | return; |
---|
| 1770 | } |
---|
| 1771 | |
---|
| 1772 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0); |
---|
| 1773 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_chat, 0); |
---|
[f4d0975] | 1774 | aim_sendcookie(sess, tstconn, redir->cookielen, redir->cookie); |
---|
[d09e5a1] | 1775 | /* printf("chatnav: connected\n"); */ |
---|
| 1776 | return; |
---|
| 1777 | } |
---|
| 1778 | |
---|
| 1779 | /* XXX this needs instance too */ |
---|
| 1780 | void chat_redirect(aim_session_t *sess, struct aim_redirect_data *redir) |
---|
| 1781 | { |
---|
| 1782 | aim_conn_t *tstconn; |
---|
[8c92848] | 1783 | |
---|
| 1784 | owl_function_debugmsg("in chat_redirect"); |
---|
[d09e5a1] | 1785 | |
---|
| 1786 | tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, redir->ip); |
---|
| 1787 | if (!tstconn || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) { |
---|
| 1788 | /* printf("unable to connect to chat server\n"); */ |
---|
| 1789 | if (tstconn) aim_conn_kill(sess, &tstconn); |
---|
| 1790 | return; |
---|
| 1791 | } |
---|
| 1792 | /* printf("chat: connected to %s instance %d on exchange %d\n", redir->chat.room, redir->chat.instance, redir->chat.exchange); */ |
---|
| 1793 | |
---|
| 1794 | /* |
---|
| 1795 | * We must do this to attach the stored name to the connection! |
---|
| 1796 | */ |
---|
| 1797 | aim_chat_attachname(tstconn, redir->chat.exchange, redir->chat.room, redir->chat.instance); |
---|
| 1798 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0); |
---|
| 1799 | aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNINITDONE, conninitdone_chat, 0); |
---|
[f4d0975] | 1800 | aim_sendcookie(sess, tstconn, redir->cookielen, redir->cookie); |
---|
[d09e5a1] | 1801 | return; |
---|
| 1802 | } |
---|
| 1803 | |
---|
[dc1edbd] | 1804 | typedef struct _owl_aim_event_source { /*noproto*/ |
---|
| 1805 | GSource source; |
---|
| 1806 | aim_session_t *sess; |
---|
| 1807 | GPtrArray *fds; |
---|
| 1808 | } owl_aim_event_source; |
---|
| 1809 | |
---|
| 1810 | static void truncate_pollfd_list(owl_aim_event_source *event_source, int len) |
---|
| 1811 | { |
---|
| 1812 | GPollFD *fd; |
---|
| 1813 | int i; |
---|
| 1814 | if (len < event_source->fds->len) |
---|
| 1815 | owl_function_debugmsg("Truncating AIM PollFDs to %d, was %d", len, event_source->fds->len); |
---|
| 1816 | for (i = len; i < event_source->fds->len; i++) { |
---|
| 1817 | fd = event_source->fds->pdata[i]; |
---|
| 1818 | g_source_remove_poll(&event_source->source, fd); |
---|
| 1819 | g_free(fd); |
---|
| 1820 | } |
---|
| 1821 | g_ptr_array_remove_range(event_source->fds, len, event_source->fds->len - len); |
---|
| 1822 | } |
---|
| 1823 | |
---|
| 1824 | static gboolean owl_aim_event_source_prepare(GSource *source, int *timeout) |
---|
[3381399] | 1825 | { |
---|
[dc1edbd] | 1826 | owl_aim_event_source *event_source = (owl_aim_event_source*)source; |
---|
| 1827 | aim_conn_t *cur; |
---|
| 1828 | GPollFD *fd; |
---|
| 1829 | int i; |
---|
| 1830 | |
---|
| 1831 | /* AIM HACK: |
---|
| 1832 | * |
---|
| 1833 | * The problem - I'm not sure where to hook into the owl/faim |
---|
| 1834 | * interface to keep track of when the AIM socket(s) open and |
---|
| 1835 | * close. In particular, the bosconn thing throws me off. So, |
---|
| 1836 | * rather than register particular dispatchers for AIM, I look up |
---|
| 1837 | * the relevant FDs and add them to select's watch lists, then |
---|
| 1838 | * check for them individually before moving on to the other |
---|
| 1839 | * dispatchers. --asedeno |
---|
| 1840 | */ |
---|
| 1841 | i = 0; |
---|
| 1842 | for (cur = event_source->sess->connlist; cur; cur = cur->next) { |
---|
| 1843 | if (cur->fd != -1) { |
---|
| 1844 | /* Add new GPollFDs as necessary. */ |
---|
| 1845 | if (i == event_source->fds->len) { |
---|
| 1846 | fd = g_new0(GPollFD, 1); |
---|
| 1847 | g_ptr_array_add(event_source->fds, fd); |
---|
| 1848 | g_source_add_poll(source, fd); |
---|
| 1849 | owl_function_debugmsg("Allocated new AIM PollFD, len = %d", event_source->fds->len); |
---|
| 1850 | } |
---|
| 1851 | fd = event_source->fds->pdata[i]; |
---|
| 1852 | fd->fd = cur->fd; |
---|
| 1853 | fd->events |= G_IO_IN | G_IO_HUP | G_IO_ERR; |
---|
| 1854 | if (cur->status & AIM_CONN_STATUS_INPROGRESS) { |
---|
| 1855 | /* Yes, we're checking writable sockets here. Without it, AIM |
---|
| 1856 | login is really slow. */ |
---|
| 1857 | fd->events |= G_IO_OUT; |
---|
| 1858 | } |
---|
| 1859 | i++; |
---|
| 1860 | } |
---|
[3381399] | 1861 | } |
---|
[dc1edbd] | 1862 | /* If the number of GPollFDs went down, clean up. */ |
---|
| 1863 | truncate_pollfd_list(event_source, i); |
---|
| 1864 | |
---|
| 1865 | *timeout = -1; |
---|
| 1866 | return FALSE; |
---|
| 1867 | } |
---|
| 1868 | |
---|
| 1869 | static gboolean owl_aim_event_source_check(GSource *source) |
---|
| 1870 | { |
---|
| 1871 | owl_aim_event_source *event_source = (owl_aim_event_source*)source; |
---|
| 1872 | int i; |
---|
| 1873 | |
---|
| 1874 | for (i = 0; i < event_source->fds->len; i++) { |
---|
| 1875 | GPollFD *fd = event_source->fds->pdata[i]; |
---|
| 1876 | if (fd->revents & fd->events) |
---|
| 1877 | return TRUE; |
---|
| 1878 | } |
---|
| 1879 | return FALSE; |
---|
| 1880 | } |
---|
| 1881 | |
---|
| 1882 | static gboolean owl_aim_event_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) |
---|
| 1883 | { |
---|
| 1884 | owl_aim_event_source *event_source = (owl_aim_event_source*)source; |
---|
| 1885 | owl_aim_process_events(event_source->sess); |
---|
| 1886 | return TRUE; |
---|
| 1887 | } |
---|
| 1888 | |
---|
| 1889 | static void owl_aim_event_source_finalize(GSource *source) |
---|
| 1890 | { |
---|
| 1891 | owl_aim_event_source *event_source = (owl_aim_event_source*)source; |
---|
| 1892 | truncate_pollfd_list(event_source, 0); |
---|
| 1893 | g_ptr_array_free(event_source->fds, TRUE); |
---|
| 1894 | } |
---|
| 1895 | |
---|
| 1896 | static GSourceFuncs aim_event_funcs = { |
---|
| 1897 | owl_aim_event_source_prepare, |
---|
| 1898 | owl_aim_event_source_check, |
---|
| 1899 | owl_aim_event_source_dispatch, |
---|
| 1900 | owl_aim_event_source_finalize, |
---|
| 1901 | }; |
---|
| 1902 | |
---|
| 1903 | GSource *owl_aim_event_source_new(aim_session_t *sess) |
---|
| 1904 | { |
---|
| 1905 | GSource *source; |
---|
| 1906 | owl_aim_event_source *event_source; |
---|
| 1907 | |
---|
| 1908 | source = g_source_new(&aim_event_funcs, sizeof(owl_aim_event_source)); |
---|
| 1909 | event_source = (owl_aim_event_source *)source; |
---|
| 1910 | event_source->sess = sess; |
---|
| 1911 | /* TODO: When we depend on glib 2.22+, use g_ptr_array_new_with_free_func. */ |
---|
| 1912 | event_source->fds = g_ptr_array_new(); |
---|
| 1913 | return source; |
---|
[3381399] | 1914 | } |
---|