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