comparison src/oscar.c @ 960:fa681641643d

[gaim-migrate @ 970] *** MULTIPLE-CONNECTIONS *** committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 10 Oct 2000 00:02:02 +0000
parents acd4d81f2afc
children 2cd7b73e2c9a
comparison
equal deleted inserted replaced
959:034d5d1d53eb 960:fa681641643d
35 #include <stdlib.h> 35 #include <stdlib.h>
36 #include <stdio.h> 36 #include <stdio.h>
37 #include <time.h> 37 #include <time.h>
38 #include <sys/socket.h> 38 #include <sys/socket.h>
39 #include <sys/stat.h> 39 #include <sys/stat.h>
40 #include "multi.h"
40 #include "gaim.h" 41 #include "gaim.h"
41 #include <aim.h> 42 #include "aim.h"
42 #include "gnome_applet_mgr.h" 43 #include "gnome_applet_mgr.h"
43 44
44 #include "pixmaps/cancel.xpm" 45 #include "pixmaps/cancel.xpm"
45 #include "pixmaps/ok.xpm" 46 #include "pixmaps/ok.xpm"
46 47
47 static int inpa = -1;
48 static int paspa = -1;
49 static int cnpa = -1;
50 struct aim_session_t *gaim_sess = NULL;
51 struct aim_conn_t *gaim_conn;
52 int gaim_caps = AIM_CAPS_CHAT | AIM_CAPS_SENDFILE | AIM_CAPS_GETFILE | 48 int gaim_caps = AIM_CAPS_CHAT | AIM_CAPS_SENDFILE | AIM_CAPS_GETFILE |
53 AIM_CAPS_VOICE | AIM_CAPS_IMIMAGE | AIM_CAPS_BUDDYICON; 49 AIM_CAPS_VOICE | AIM_CAPS_IMIMAGE | AIM_CAPS_BUDDYICON;
54 int USE_OSCAR = 0;
55 int keepalv = -1; 50 int keepalv = -1;
56 int create_exchange = 0; 51
57 char *create_name = NULL; 52 struct chat_connection *find_oscar_chat(struct gaim_connection *gc, char *name) {
58 53 GSList *g = gc->oscar_chats;
59 GList *oscar_chats = NULL;
60
61 struct chat_connection *find_oscar_chat(char *name) {
62 GList *g = oscar_chats;
63 struct chat_connection *c = NULL; 54 struct chat_connection *c = NULL;
55 if (gc->protocol != PROTO_OSCAR) return NULL;
64 56
65 while (g) { 57 while (g) {
66 c = (struct chat_connection *)g->data; 58 c = (struct chat_connection *)g->data;
67 if (!strcmp(name, c->name)) 59 if (!strcmp(name, c->name))
68 break; 60 break;
71 } 63 }
72 64
73 return c; 65 return c;
74 } 66 }
75 67
76 static struct chat_connection *find_oscar_chat_by_conn(struct aim_conn_t *conn) { 68 static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc,
77 GList *g = oscar_chats; 69 struct aim_conn_t *conn) {
70 GSList *g = gc->oscar_chats;
78 struct chat_connection *c = NULL; 71 struct chat_connection *c = NULL;
79 72
80 while (g) { 73 while (g) {
81 c = (struct chat_connection *)g->data; 74 c = (struct chat_connection *)g->data;
82 if (c->conn == conn) 75 if (c->conn == conn)
83 break; 76 break;
77 g = g->next;
78 c = NULL;
79 }
80
81 return c;
82 }
83
84 static struct gaim_connection *find_gaim_conn_by_aim_sess(struct aim_session_t *sess) {
85 GSList *g = connections;
86 struct gaim_connection *gc = NULL;
87
88 while (g) {
89 gc = (struct gaim_connection *)g->data;
90 if (sess == gc->oscar_sess)
91 break;
92 g = g->next;
93 gc = NULL;
94 }
95
96 return gc;
97 }
98
99 static struct gaim_connection *find_gaim_conn_by_oscar_conn(struct aim_conn_t *conn) {
100 GSList *g = connections;
101 struct gaim_connection *c = NULL;
102 struct aim_conn_t *s;
103 while (g) {
104 c = (struct gaim_connection *)g->data;
105 s = c->oscar_sess->connlist;
106 while (s) {
107 if (conn == s)
108 break;
109 s = s->next;
110 }
111 if (s) break;
84 g = g->next; 112 g = g->next;
85 c = NULL; 113 c = NULL;
86 } 114 }
87 115
88 return c; 116 return c;
144 "Queue full", 172 "Queue full",
145 "Not while on AOL" 173 "Not while on AOL"
146 }; 174 };
147 static int msgerrreasonlen = 25; 175 static int msgerrreasonlen = 25;
148 176
149 extern void auth_failed();
150
151 static void oscar_callback(gpointer data, gint source, 177 static void oscar_callback(gpointer data, gint source,
152 GdkInputCondition condition) { 178 GdkInputCondition condition) {
153 struct aim_conn_t *conn = (struct aim_conn_t *)data; 179 struct aim_conn_t *conn = (struct aim_conn_t *)data;
180 struct gaim_connection *gc = find_gaim_conn_by_oscar_conn(conn);
181 if (!gc) {
182 /* oh boy. this is probably bad. i guess the only thing we can really do
183 * is return? */
184 debug_print("oscar callback for closed connection.\n");
185 return;
186 }
154 187
155 if (condition & GDK_INPUT_EXCEPTION) { 188 if (condition & GDK_INPUT_EXCEPTION) {
156 signoff(); 189 signoff(gc);
157 hide_login_progress(_("Disconnected.")); 190 hide_login_progress(_("Disconnected."));
158 auth_failed();
159 return; 191 return;
160 } 192 }
161 if (condition & GDK_INPUT_READ) { 193 if (condition & GDK_INPUT_READ) {
162 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { 194 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
163 debug_print("got information on rendezvous\n"); 195 debug_print("got information on rendezvous\n");
164 if (aim_handlerendconnect(gaim_sess, conn) < 0) { 196 if (aim_handlerendconnect(gc->oscar_sess, conn) < 0) {
165 debug_print(_("connection error (rend)\n")); 197 debug_print(_("connection error (rend)\n"));
166 } 198 }
167 } else { 199 } else {
168 if (aim_get_command(gaim_sess, conn) >= 0) { 200 if (aim_get_command(gc->oscar_sess, conn) >= 0) {
169 aim_rxdispatch(gaim_sess); 201 aim_rxdispatch(gc->oscar_sess);
170 } else { 202 } else {
171 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS && 203 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS &&
172 conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { 204 conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) {
173 struct conversation *cnv = 205 struct conversation *cnv =
174 find_conversation(((struct aim_directim_priv *)conn->priv)->sn); 206 find_conversation(((struct aim_directim_priv *)conn->priv)->sn);
175 debug_print("connection error for directim\n"); 207 debug_print("connection error for directim\n");
176 if (cnv) { 208 if (cnv) {
177 make_direct(cnv, FALSE, NULL, 0); 209 make_direct(cnv, FALSE, NULL, 0);
178 } 210 }
179 aim_conn_kill(gaim_sess, &conn); 211 aim_conn_kill(gc->oscar_sess, &conn);
180 } else if ((conn->type == AIM_CONN_TYPE_BOS) || 212 } else if ((conn->type == AIM_CONN_TYPE_BOS) ||
181 !(aim_getconn_type(gaim_sess, AIM_CONN_TYPE_BOS))) { 213 !(aim_getconn_type(gc->oscar_sess, AIM_CONN_TYPE_BOS))) {
182 debug_print(_("major connection error\n")); 214 debug_print(_("major connection error\n"));
183 signoff(); 215 signoff(gc);
184 hide_login_progress(_("Disconnected.")); 216 hide_login_progress(_("Disconnected."));
185 auth_failed();
186 } else if (conn->type == AIM_CONN_TYPE_CHAT) { 217 } else if (conn->type == AIM_CONN_TYPE_CHAT) {
187 struct chat_connection *c = find_oscar_chat_by_conn(conn); 218 struct chat_connection *c = find_oscar_chat_by_conn(gc, conn);
188 char buf[BUF_LONG]; 219 char buf[BUF_LONG];
189 sprintf(debug_buff, "disconnected from chat room %s\n", c->name); 220 sprintf(debug_buff, "disconnected from chat room %s\n", c->name);
190 debug_print(debug_buff); 221 debug_print(debug_buff);
191 c->conn = NULL; 222 c->conn = NULL;
192 gdk_input_remove(c->inpa); 223 if (c->inpa > -1)
224 gdk_input_remove(c->inpa);
193 c->inpa = -1; 225 c->inpa = -1;
194 c->fd = -1; 226 c->fd = -1;
195 aim_conn_kill(gaim_sess, &conn); 227 aim_conn_kill(gc->oscar_sess, &conn);
196 sprintf(buf, _("You have been disconnected from chat room %s."), c->name); 228 sprintf(buf, _("You have been disconnected from chat room %s."), c->name);
197 do_error_dialog(buf, _("Chat Error!")); 229 do_error_dialog(buf, _("Chat Error!"));
198 } else if (conn->type == AIM_CONN_TYPE_CHATNAV) { 230 } else if (conn->type == AIM_CONN_TYPE_CHATNAV) {
199 gdk_input_remove(cnpa); 231 if (gc->cnpa > -1)
200 cnpa = -1; 232 gdk_input_remove(gc->cnpa);
233 gc->cnpa = -1;
201 debug_print("removing chatnav input watcher\n"); 234 debug_print("removing chatnav input watcher\n");
202 aim_conn_kill(gaim_sess, &conn); 235 aim_conn_kill(gc->oscar_sess, &conn);
203 } else { 236 } else {
204 sprintf(debug_buff, "holy crap! generic connection error! %d\n", 237 sprintf(debug_buff, "holy crap! generic connection error! %d\n",
205 conn->type); 238 conn->type);
206 debug_print(debug_buff); 239 debug_print(debug_buff);
207 aim_conn_kill(gaim_sess, &conn); 240 aim_conn_kill(gc->oscar_sess, &conn);
208 } 241 }
209 } 242 }
210 } 243 }
211 } 244 }
212 } 245 }
213 246
214 int oscar_login(char *username, char *password) { 247 struct gaim_connection *oscar_login(char *username, char *password) {
215 struct aim_session_t *sess; 248 struct aim_session_t *sess;
216 struct aim_conn_t *conn; 249 struct aim_conn_t *conn;
217 struct aim_user *u; 250 struct aim_user *u;
218 char buf[256]; 251 char buf[256];
252 struct gaim_connection *gc;
219 253
220 sprintf(debug_buff, _("Logging in %s\n"), username); 254 sprintf(debug_buff, _("Logging in %s\n"), username);
221 debug_print(debug_buff); 255 debug_print(debug_buff);
222 256
257 gc = new_gaim_conn(PROTO_OSCAR, username, password);
223 sess = g_new0(struct aim_session_t, 1); 258 sess = g_new0(struct aim_session_t, 1);
224 aim_session_init(sess); 259 aim_session_init(sess);
225 /* we need an immediate queue because we don't use a while-loop to 260 /* we need an immediate queue because we don't use a while-loop to
226 * see if things need to be sent. */ 261 * see if things need to be sent. */
227 sess->tx_enqueue = &aim_tx_enqueue__immediate; 262 sess->tx_enqueue = &aim_tx_enqueue__immediate;
228 gaim_sess = sess; 263 gc->oscar_sess = sess;
229 264
230 sprintf(buf, _("Looking up %s"), FAIM_LOGIN_SERVER); 265 sprintf(buf, _("Looking up %s"), FAIM_LOGIN_SERVER);
231 set_login_progress(1, buf); 266 set_login_progress(1, buf);
232 conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, FAIM_LOGIN_SERVER); 267 conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, FAIM_LOGIN_SERVER);
233 268
234 if (conn == NULL) { 269 if (conn == NULL) {
235 debug_print(_("internal connection error\n")); 270 debug_print(_("internal connection error\n"));
236 #ifdef USE_APPLET 271 #ifdef USE_APPLET
237 set_user_state(offline); 272 set_user_state(offline);
238 #endif 273 #endif
239 set_state(STATE_OFFLINE); 274 destroy_gaim_conn(gc);
240 hide_login_progress(_("Unable to login to AIM")); 275 hide_login_progress(_("Unable to login to AIM"));
241 return -1; 276 return NULL;
242 } else if (conn->fd == -1) { 277 } else if (conn->fd == -1) {
243 #ifdef USE_APPLET 278 #ifdef USE_APPLET
244 set_user_state(offline); 279 set_user_state(offline);
245 #endif 280 #endif
246 set_state(STATE_OFFLINE); 281 destroy_gaim_conn(gc);
247 if (conn->status & AIM_CONN_STATUS_RESOLVERR) { 282 if (conn->status & AIM_CONN_STATUS_RESOLVERR) {
248 sprintf(debug_buff, _("couldn't resolve host\n")); 283 sprintf(debug_buff, _("couldn't resolve host\n"));
249 debug_print(debug_buff); 284 debug_print(debug_buff);
250 hide_login_progress(debug_buff); 285 hide_login_progress(debug_buff);
251 } else if (conn->status & AIM_CONN_STATUS_CONNERR) { 286 } else if (conn->status & AIM_CONN_STATUS_CONNERR) {
252 sprintf(debug_buff, _("couldn't connect to host\n")); 287 sprintf(debug_buff, _("couldn't connect to host\n"));
253 debug_print(debug_buff); 288 debug_print(debug_buff);
254 hide_login_progress(debug_buff); 289 hide_login_progress(debug_buff);
255 } 290 }
256 return -1; 291 return NULL;
257 } 292 }
258 g_snprintf(buf, sizeof(buf), _("Signon: %s"), username); 293 g_snprintf(buf, sizeof(buf), _("Signon: %s"), username);
259 set_login_progress(2, buf); 294 set_login_progress(2, buf);
260 295
261 aim_conn_addhandler(sess, conn, 0x0017, 0x0007, gaim_parse_login, 0); 296 aim_conn_addhandler(sess, conn, 0x0017, 0x0007, gaim_parse_login, 0);
262 aim_conn_addhandler(sess, conn, 0x0017, 0x0003, gaim_parse_auth_resp, 0); 297 aim_conn_addhandler(sess, conn, 0x0017, 0x0003, gaim_parse_auth_resp, 0);
263 aim_sendconnack(sess, conn); 298 aim_sendconnack(sess, conn);
264 aim_request_login(sess, conn, username); 299 aim_request_login(sess, conn, username);
265 300
266 inpa = gdk_input_add(conn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 301 gc->inpa = gdk_input_add(conn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
267 oscar_callback, conn); 302 oscar_callback, conn);
268 303
269 u = find_user(username); 304 u = find_user(username);
270 305 sprintf(gc->user_info, "%s", u->user_info);
271 if (!u) { 306 gc->options = u->options;
272 u = g_new0(struct aim_user, 1);
273 g_snprintf(u->username, sizeof(u->username), DEFAULT_INFO);
274 aim_users = g_list_append(aim_users, u);
275 }
276 current_user = u;
277 g_snprintf(current_user->username, sizeof(current_user->username),
278 "%s", username);
279 g_snprintf(current_user->password, sizeof(current_user->password),
280 "%s", password);
281 save_prefs(); 307 save_prefs();
282 308
283 debug_print(_("Password sent, waiting for response\n")); 309 debug_print(_("Password sent, waiting for response\n"));
284 310
285 return 0; 311 return gc;
286 } 312 }
287 313
288 void oscar_close() { 314 void oscar_close(struct gaim_connection *gc) {
315 if (gc->protocol != PROTO_OSCAR) return;
289 #ifdef USE_APPLET 316 #ifdef USE_APPLET
290 set_user_state(offline); 317 set_user_state(offline);
291 #endif 318 #endif
292 set_state(STATE_OFFLINE); 319 if (gc->inpa > 0)
293 if (inpa > 0) 320 gdk_input_remove(gc->inpa);
294 gdk_input_remove(inpa); 321 gc->inpa = -1;
295 inpa = -1; 322 if (gc->cnpa > 0)
296 aim_logoff(gaim_sess); 323 gdk_input_remove(gc->cnpa);
297 g_free(gaim_sess); 324 gc->cnpa = -1;
298 gaim_sess = NULL; 325 if (gc->paspa > 0)
326 gdk_input_remove(gc->paspa);
327 gc->paspa = -1;
328 aim_logoff(gc->oscar_sess);
329 g_free(gc->oscar_sess);
299 debug_print(_("Signed off.\n")); 330 debug_print(_("Signed off.\n"));
300 } 331 }
301 332
302 int gaim_parse_auth_resp(struct aim_session_t *sess, 333 int gaim_parse_auth_resp(struct aim_session_t *sess,
303 struct command_rx_struct *command, ...) { 334 struct command_rx_struct *command, ...) {
304 struct aim_conn_t *bosconn = NULL; 335 struct aim_conn_t *bosconn = NULL;
336 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
305 sprintf(debug_buff, "inside auth_resp (Screen name: %s)\n", 337 sprintf(debug_buff, "inside auth_resp (Screen name: %s)\n",
306 sess->logininfo.screen_name); 338 sess->logininfo.screen_name);
307 debug_print(debug_buff); 339 debug_print(debug_buff);
308 340
309 if (sess->logininfo.errorcode) { 341 if (sess->logininfo.errorcode) {
331 sess->logininfo.errorurl); 363 sess->logininfo.errorurl);
332 debug_print(debug_buff); 364 debug_print(debug_buff);
333 #ifdef USE_APPLET 365 #ifdef USE_APPLET
334 set_user_state(offline); 366 set_user_state(offline);
335 #endif 367 #endif
336 set_state(STATE_OFFLINE); 368 gdk_input_remove(gc->inpa);
337 gdk_input_remove(inpa);
338 hide_login_progress(_("Authentication Failed")); 369 hide_login_progress(_("Authentication Failed"));
339 signoff(); 370 signoff(gc);
340 auth_failed();
341 return 0; 371 return 0;
342 } 372 }
343 373
344 374
345 if (sess->logininfo.email) { 375 if (sess->logininfo.email) {
348 } else { 378 } else {
349 debug_print("Email is NULL\n"); 379 debug_print("Email is NULL\n");
350 } 380 }
351 sprintf(debug_buff, "Closing auth connection...\n"); 381 sprintf(debug_buff, "Closing auth connection...\n");
352 debug_print(debug_buff); 382 debug_print(debug_buff);
353 gdk_input_remove(inpa); 383 gdk_input_remove(gc->inpa);
354 aim_conn_kill(sess, &command->conn); 384 aim_conn_kill(sess, &command->conn);
355 385
356 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP); 386 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP);
357 if (bosconn == NULL) { 387 if (bosconn == NULL) {
358 #ifdef USE_APPLET 388 #ifdef USE_APPLET
359 set_user_state(offline); 389 set_user_state(offline);
360 #endif 390 #endif
361 set_state(STATE_OFFLINE); 391 destroy_gaim_conn(gc);
362 hide_login_progress(_("Internal Error")); 392 hide_login_progress(_("Internal Error"));
363 auth_failed();
364 return -1; 393 return -1;
365 } else if (bosconn->status != 0) { 394 } else if (bosconn->status != 0) {
366 #ifdef USE_APPLET 395 #ifdef USE_APPLET
367 set_user_state(offline); 396 set_user_state(offline);
368 #endif 397 #endif
369 set_state(STATE_OFFLINE); 398 destroy_gaim_conn(gc);
370 hide_login_progress(_("Could Not Connect")); 399 hide_login_progress(_("Could Not Connect"));
371 auth_failed();
372 return -1; 400 return -1;
373 } 401 }
374 402
375 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, gaim_bosrights, 0); 403 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, gaim_bosrights, 0);
376 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0007, gaim_rateresp, 0); /* rate info */ 404 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0007, gaim_rateresp, 0); /* rate info */
393 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0); 421 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0);
394 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0); 422 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
395 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); 423 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0);
396 424
397 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie); 425 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie);
398 gaim_conn = bosconn; 426 gc->oscar_conn = bosconn;
399 inpa = gdk_input_add(bosconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 427 gc->inpa = gdk_input_add(bosconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
400 oscar_callback, bosconn); 428 oscar_callback, bosconn);
401 set_login_progress(4, _("Connection established, cookie sent")); 429 set_login_progress(4, _("Connection established, cookie sent"));
402 return 1; 430 return 1;
403 } 431 }
404 432
405 int gaim_parse_login(struct aim_session_t *sess, 433 int gaim_parse_login(struct aim_session_t *sess,
406 struct command_rx_struct *command, ...) { 434 struct command_rx_struct *command, ...) {
407 struct client_info_s info = {"AOL Instant Messenger (SM), version 4.1.2010/WIN32", 4, 30, 3141, "us", "en", 0x0004, 0x0001, 0x055}; 435 struct client_info_s info = {"AOL Instant Messenger (SM), version 4.1.2010/WIN32", 4, 30, 3141, "us", "en", 0x0004, 0x0001, 0x055};
408 char *key; 436 char *key;
409 va_list ap; 437 va_list ap;
438 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
410 439
411 va_start(ap, command); 440 va_start(ap, command);
412 key = va_arg(ap, char *); 441 key = va_arg(ap, char *);
413 va_end(ap); 442 va_end(ap);
414 443
415 aim_send_login(sess, command->conn, 444 aim_send_login(sess, command->conn, gc->username, gc->password, &info, key);
416 current_user->username, current_user->password, &info, key);
417 return 1; 445 return 1;
418 } 446 }
419 447
420 int gaim_server_ready(struct aim_session_t *sess, 448 int gaim_server_ready(struct aim_session_t *sess,
421 struct command_rx_struct *command, ...) { 449 struct command_rx_struct *command, ...) {
460 struct command_rx_struct *command, ...) { 488 struct command_rx_struct *command, ...) {
461 va_list ap; 489 va_list ap;
462 int serviceid; 490 int serviceid;
463 char *ip; 491 char *ip;
464 unsigned char *cookie; 492 unsigned char *cookie;
493 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
465 494
466 va_start(ap, command); 495 va_start(ap, command);
467 serviceid = va_arg(ap, int); 496 serviceid = va_arg(ap, int);
468 ip = va_arg(ap, char *); 497 ip = va_arg(ap, char *);
469 cookie = va_arg(ap, unsigned char *); 498 cookie = va_arg(ap, unsigned char *);
474 { 503 {
475 struct aim_conn_t *tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip); 504 struct aim_conn_t *tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
476 if (tstconn == NULL || tstconn->status >= AIM_CONN_STATUS_RESOLVERR) 505 if (tstconn == NULL || tstconn->status >= AIM_CONN_STATUS_RESOLVERR)
477 debug_print("unable to reconnect with authorizer\n"); 506 debug_print("unable to reconnect with authorizer\n");
478 else { 507 else {
479 paspa = gdk_input_add(tstconn->fd, 508 gc->paspa = gdk_input_add(tstconn->fd,
480 GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 509 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
481 oscar_callback, tstconn); 510 oscar_callback, tstconn);
482 aim_auth_sendcookie(sess, tstconn, cookie); 511 aim_auth_sendcookie(sess, tstconn, cookie);
483 } 512 }
484 } 513 }
490 debug_print("unable to connect to chatnav server\n"); 519 debug_print("unable to connect to chatnav server\n");
491 return 1; 520 return 1;
492 } 521 }
493 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); 522 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0);
494 aim_auth_sendcookie(sess, tstconn, cookie); 523 aim_auth_sendcookie(sess, tstconn, cookie);
495 cnpa = gdk_input_add(tstconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 524 gc->cnpa = gdk_input_add(tstconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
496 oscar_callback, tstconn); 525 oscar_callback, tstconn);
497 } 526 }
498 debug_print("chatnav: connected\n"); 527 debug_print("chatnav: connected\n");
499 break; 528 break;
500 case 0xe: /* Chat */ 529 case 0xe: /* Chat */
516 545
517 ccon->inpa = gdk_input_add(tstconn->fd, 546 ccon->inpa = gdk_input_add(tstconn->fd,
518 GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 547 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
519 oscar_callback, tstconn); 548 oscar_callback, tstconn);
520 549
521 oscar_chats = g_list_append(oscar_chats, ccon); 550 gc->oscar_chats = g_slist_append(gc->oscar_chats, ccon);
522 551
523 aim_chat_attachname(tstconn, roomname); 552 aim_chat_attachname(tstconn, roomname);
524 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); 553 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0);
525 aim_auth_sendcookie(sess, tstconn, cookie); 554 aim_auth_sendcookie(sess, tstconn, cookie);
526 } 555 }
587 616
588 static void accept_directim(GtkWidget *w, GtkWidget *m) 617 static void accept_directim(GtkWidget *w, GtkWidget *m)
589 { 618 {
590 struct aim_conn_t *newconn; 619 struct aim_conn_t *newconn;
591 struct aim_directim_priv *priv; 620 struct aim_directim_priv *priv;
621 struct gaim_connection *gc;
592 int watcher; 622 int watcher;
593 623
594 priv = (struct aim_directim_priv *)gtk_object_get_user_data(GTK_OBJECT(m)); 624 priv = (struct aim_directim_priv *)gtk_object_get_user_data(GTK_OBJECT(m));
625 gc = (struct gaim_connection *)gtk_object_get_user_data(GTK_OBJECT(w));
595 gtk_widget_destroy(m); 626 gtk_widget_destroy(m);
596 627
597 if (!(newconn = aim_directim_connect(gaim_sess, gaim_conn, priv))) { 628 if (!(newconn = aim_directim_connect(gc->oscar_sess, gc->oscar_conn, priv))) {
598 debug_print("imimage: could not connect\n"); 629 debug_print("imimage: could not connect\n");
599 return; 630 return;
600 } 631 }
601 632
602 aim_conn_addhandler(gaim_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0); 633 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0);
603 aim_conn_addhandler(gaim_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, gaim_directim_typing, 0); 634 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, gaim_directim_typing, 0);
604 635
605 watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 636 watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
606 oscar_callback, newconn); 637 oscar_callback, newconn);
607 638
608 sprintf(debug_buff, "DirectIM: connected to %s\n", priv->sn); 639 sprintf(debug_buff, "DirectIM: connected to %s\n", priv->sn);
609 debug_print(debug_buff); 640 debug_print(debug_buff);
610 641
611 serv_got_imimage(priv->sn, priv->cookie, priv->ip, newconn, watcher); 642 serv_got_imimage(gc, priv->sn, priv->cookie, priv->ip, newconn, watcher);
612 643
613 g_free(priv); 644 g_free(priv);
614 } 645 }
615 646
616 static void cancel_directim(GtkWidget *w, GtkWidget *m) 647 static void cancel_directim(GtkWidget *w, GtkWidget *m)
617 { 648 {
618 gtk_widget_destroy(m); 649 gtk_widget_destroy(m);
619 } 650 }
620 651
621 static void directim_dialog(struct aim_directim_priv *priv) 652 static void directim_dialog(struct gaim_connection *gc, struct aim_directim_priv *priv)
622 { 653 {
623 GtkWidget *window; 654 GtkWidget *window;
624 GtkWidget *vbox; 655 GtkWidget *vbox;
625 GtkWidget *hbox; 656 GtkWidget *hbox;
626 GtkWidget *label; 657 GtkWidget *label;
649 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); 680 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
650 gtk_widget_show(hbox); 681 gtk_widget_show(hbox);
651 682
652 yes = picture_button(window, _("Accept"), ok_xpm); 683 yes = picture_button(window, _("Accept"), ok_xpm);
653 gtk_box_pack_start(GTK_BOX(hbox), yes, FALSE, FALSE, 5); 684 gtk_box_pack_start(GTK_BOX(hbox), yes, FALSE, FALSE, 5);
685 gtk_object_set_user_data(GTK_OBJECT(yes), gc);
654 686
655 no = picture_button(window, _("Cancel"), cancel_xpm); 687 no = picture_button(window, _("Cancel"), cancel_xpm);
656 gtk_box_pack_end(GTK_BOX(hbox), no, FALSE, FALSE, 5); 688 gtk_box_pack_end(GTK_BOX(hbox), no, FALSE, FALSE, 5);
657 689
658 gtk_signal_connect(GTK_OBJECT(yes), "clicked", 690 gtk_signal_connect(GTK_OBJECT(yes), "clicked",
665 697
666 int gaim_parse_incoming_im(struct aim_session_t *sess, 698 int gaim_parse_incoming_im(struct aim_session_t *sess,
667 struct command_rx_struct *command, ...) { 699 struct command_rx_struct *command, ...) {
668 int channel; 700 int channel;
669 va_list ap; 701 va_list ap;
702 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
670 703
671 va_start(ap, command); 704 va_start(ap, command);
672 channel = va_arg(ap, int); 705 channel = va_arg(ap, int);
673 706
674 /* channel 1: standard message */ 707 /* channel 1: standard message */
685 flag1 = (u_short)va_arg(ap, u_int); 718 flag1 = (u_short)va_arg(ap, u_int);
686 flag2 = (u_short)va_arg(ap, u_int); 719 flag2 = (u_short)va_arg(ap, u_int);
687 va_end(ap); 720 va_end(ap);
688 721
689 g_snprintf(tmp, BUF_LONG, "%s", msg); 722 g_snprintf(tmp, BUF_LONG, "%s", msg);
690 serv_got_im(userinfo->sn, tmp, icbmflags & AIM_IMFLAGS_AWAY); 723 serv_got_im(gc, userinfo->sn, tmp, icbmflags & AIM_IMFLAGS_AWAY);
691 g_free(tmp); 724 g_free(tmp);
692 } else if (channel == 2) { 725 } else if (channel == 2) {
693 struct aim_userinfo_s *userinfo; 726 struct aim_userinfo_s *userinfo;
694 int rendtype = va_arg(ap, int); 727 int rendtype = va_arg(ap, int);
695 if (rendtype & AIM_CAPS_CHAT) { 728 if (rendtype & AIM_CAPS_CHAT) {
728 761
729 priv2 = g_new0(struct aim_directim_priv, 1); 762 priv2 = g_new0(struct aim_directim_priv, 1);
730 strcpy(priv2->cookie, priv->cookie); 763 strcpy(priv2->cookie, priv->cookie);
731 strcpy(priv2->sn, priv->sn); 764 strcpy(priv2->sn, priv->sn);
732 strcpy(priv2->ip, priv->ip); 765 strcpy(priv2->ip, priv->ip);
733 directim_dialog(priv2); 766 directim_dialog(gc, priv2);
734 } else { 767 } else {
735 sprintf(debug_buff, "Unknown rendtype %d\n", rendtype); 768 sprintf(debug_buff, "Unknown rendtype %d\n", rendtype);
736 debug_print(debug_buff); 769 debug_print(debug_buff);
737 } 770 }
738 } 771 }
813 struct command_rx_struct *command, ...) { 846 struct command_rx_struct *command, ...) {
814 struct aim_userinfo_s *info; 847 struct aim_userinfo_s *info;
815 char *prof_enc = NULL, *prof = NULL; 848 char *prof_enc = NULL, *prof = NULL;
816 u_short infotype; 849 u_short infotype;
817 char buf[BUF_LONG]; 850 char buf[BUF_LONG];
851 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
818 va_list ap; 852 va_list ap;
819 853
820 va_start(ap, command); 854 va_start(ap, command);
821 info = va_arg(ap, struct aim_userinfo_s *); 855 info = va_arg(ap, struct aim_userinfo_s *);
822 prof_enc = va_arg(ap, char *); 856 prof_enc = va_arg(ap, char *);
841 info->sn, 875 info->sn,
842 info->warnlevel/10, 876 info->warnlevel/10,
843 asctime(localtime(&info->onlinesince)), 877 asctime(localtime(&info->onlinesince)),
844 info->idletime, 878 info->idletime,
845 infotype == AIM_GETINFO_GENERALINFO ? prof : 879 infotype == AIM_GETINFO_GENERALINFO ? prof :
846 away_subs(prof, current_user->username)); 880 away_subs(prof, gc->username));
847 g_show_info_text(away_subs(buf, current_user->username)); 881 g_show_info_text(away_subs(buf, gc->username));
848 882
849 return 1; 883 return 1;
850 } 884 }
851 885
852 int gaim_parse_motd(struct aim_session_t *sess, 886 int gaim_parse_motd(struct aim_session_t *sess,
853 struct command_rx_struct *command, ...) { 887 struct command_rx_struct *command, ...) {
854 char *msg; 888 char *msg;
855 u_short id; 889 u_short id;
856 va_list ap; 890 va_list ap;
891 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
857 892
858 va_start(ap, command); 893 va_start(ap, command);
859 id = (u_short)va_arg(ap, u_int); 894 id = (u_short)va_arg(ap, u_int);
860 msg = va_arg(ap, char *); 895 msg = va_arg(ap, char *);
861 va_end(ap); 896 va_end(ap);
867 debug_print(debug_buff); 902 debug_print(debug_buff);
868 if (id != 4) 903 if (id != 4)
869 do_error_dialog(_("Your connection may be lost."), 904 do_error_dialog(_("Your connection may be lost."),
870 _("AOL error")); 905 _("AOL error"));
871 906
872 if (keepalv < 0) 907 if (gc->keepalive < 0)
873 update_keepalive(general_options & OPT_GEN_KEEPALIVE); 908 update_keepalive(gc, gc->keepalive);
874 909
875 return 1; 910 return 1;
876 } 911 }
877 912
878 int gaim_chatnav_info(struct aim_session_t *sess, 913 int gaim_chatnav_info(struct aim_session_t *sess,
879 struct command_rx_struct *command, ...) { 914 struct command_rx_struct *command, ...) {
880 va_list ap; 915 va_list ap;
881 u_short type; 916 u_short type;
917 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
882 918
883 va_start(ap, command); 919 va_start(ap, command);
884 type = (u_short)va_arg(ap, u_int); 920 type = (u_short)va_arg(ap, u_int);
885 921
886 switch(type) { 922 switch(type) {
906 exchanges[i].charset1, 942 exchanges[i].charset1,
907 exchanges[i].lang1); 943 exchanges[i].lang1);
908 debug_print(debug_buff); 944 debug_print(debug_buff);
909 i++; 945 i++;
910 } 946 }
911 if (create_exchange) { 947 if (gc->create_exchange) {
912 sprintf(debug_buff, "creating room %s\n", 948 sprintf(debug_buff, "creating room %s\n",
913 create_name); 949 gc->create_name);
914 debug_print(debug_buff); 950 debug_print(debug_buff);
915 aim_chatnav_createroom(sess, command->conn, create_name, create_exchange); 951 aim_chatnav_createroom(sess, command->conn, gc->create_name, gc->create_exchange);
916 create_exchange = 0; 952 gc->create_exchange = 0;
917 g_free(create_name); 953 g_free(gc->create_name);
918 create_name = NULL; 954 gc->create_name = NULL;
919 } 955 }
920 } 956 }
921 break; 957 break;
922 case 0x0008: { 958 case 0x0008: {
923 char *fqcn, *name, *ck; 959 char *fqcn, *name, *ck;
940 sprintf(debug_buff, "created room: %s %d %d %lu %d %d %d %d %s %s\n", fqcn, instance, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck); 976 sprintf(debug_buff, "created room: %s %d %d %lu %d %d %d %d %s %s\n", fqcn, instance, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck);
941 debug_print(debug_buff); 977 debug_print(debug_buff);
942 if (flags & 0x4) { 978 if (flags & 0x4) {
943 sprintf(debug_buff, "joining %s on exchange 5\n", name); 979 sprintf(debug_buff, "joining %s on exchange 5\n", name);
944 debug_print(debug_buff); 980 debug_print(debug_buff);
945 aim_chat_join(gaim_sess, gaim_conn, 5, ck); 981 aim_chat_join(gc->oscar_sess, gc->oscar_conn, 5, ck);
946 } else 982 } else
947 sprintf(debug_buff, "joining %s on exchange 4\n", name);{ 983 sprintf(debug_buff, "joining %s on exchange 4\n", name);{
948 debug_print(debug_buff); 984 debug_print(debug_buff);
949 aim_chat_join(gaim_sess, gaim_conn, 4, ck); 985 aim_chat_join(gc->oscar_sess, gc->oscar_conn, 4, ck);
950 } 986 }
951 } 987 }
952 break; 988 break;
953 default: 989 default:
954 va_end(ap); 990 va_end(ap);
1098 1134
1099 return 1; 1135 return 1;
1100 } 1136 }
1101 1137
1102 int gaim_rateresp(struct aim_session_t *sess, struct command_rx_struct *command, ...) { 1138 int gaim_rateresp(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
1139 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
1103 switch (command->conn->type) { 1140 switch (command->conn->type) {
1104 case AIM_CONN_TYPE_BOS: 1141 case AIM_CONN_TYPE_BOS:
1105 aim_bos_ackrateresp(sess, command->conn); 1142 aim_bos_ackrateresp(sess, command->conn);
1106 aim_bos_reqpersonalinfo(sess, command->conn); 1143 aim_bos_reqpersonalinfo(sess, command->conn);
1107 aim_bos_reqlocaterights(sess, command->conn); 1144 aim_bos_reqlocaterights(sess, command->conn);
1108 aim_bos_setprofile(sess, command->conn, current_user->user_info, 1145 aim_bos_setprofile(sess, command->conn, gc->user_info, NULL, gaim_caps);
1109 NULL, gaim_caps);
1110 aim_bos_reqbuddyrights(sess, command->conn); 1146 aim_bos_reqbuddyrights(sess, command->conn);
1111 1147
1112 gtk_widget_hide(mainwindow); 1148 gtk_widget_hide(mainwindow);
1113 show_buddy_list(); 1149 show_buddy_list();
1114 1150
1124 set_user_state(online); 1160 set_user_state(online);
1125 #else 1161 #else
1126 refresh_buddy_window(); 1162 refresh_buddy_window();
1127 #endif 1163 #endif
1128 1164
1129 serv_finish_login(); 1165 serv_finish_login(gc);
1130 gaim_setup(); 1166 gaim_setup(gc);
1131 1167
1132 if (bud_list_cache_exists()) 1168 if (bud_list_cache_exists(gc))
1133 do_import(NULL, 0); 1169 do_import(NULL, gc);
1134 1170
1135 debug_print("buddy list loaded\n"); 1171 debug_print("buddy list loaded\n");
1136 1172
1137 setup_buddy_chats(); 1173 setup_buddy_chats();
1138 1174
1200 1236
1201 int gaim_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...) { 1237 int gaim_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
1202 va_list ap; 1238 va_list ap;
1203 char *sn = NULL, *msg = NULL; 1239 char *sn = NULL, *msg = NULL;
1204 struct aim_conn_t *conn; 1240 struct aim_conn_t *conn;
1241 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
1205 1242
1206 va_start(ap, command); 1243 va_start(ap, command);
1207 conn = va_arg(ap, struct aim_conn_t *); 1244 conn = va_arg(ap, struct aim_conn_t *);
1208 sn = va_arg(ap, char *); 1245 sn = va_arg(ap, char *);
1209 msg = va_arg(ap, char *); 1246 msg = va_arg(ap, char *);
1210 va_end(ap); 1247 va_end(ap);
1211 1248
1212 sprintf(debug_buff, "Got DirectIM message from %s\n", sn); 1249 sprintf(debug_buff, "Got DirectIM message from %s\n", sn);
1213 debug_print(debug_buff); 1250 debug_print(debug_buff);
1214 1251
1215 serv_got_im(sn, msg, 0); 1252 serv_got_im(gc, sn, msg, 0);
1216 1253
1217 return 1; 1254 return 1;
1218 } 1255 }
1219 1256
1220 /* this is such a f*cked up function */ 1257 /* this is such a f*cked up function */
1259 debug_print(debug_buff); 1296 debug_print(debug_buff);
1260 1297
1261 return 1; 1298 return 1;
1262 } 1299 }
1263 1300
1264 void oscar_do_directim(char *name) { 1301 void oscar_do_directim(struct gaim_connection *gc, char *name) {
1265 struct aim_conn_t *newconn = aim_directim_initiate(gaim_sess, gaim_conn, NULL, name); 1302 struct aim_conn_t *newconn = aim_directim_initiate(gc->oscar_sess, gc->oscar_conn, NULL, name);
1266 struct conversation *cnv = find_conversation(name); /* this will never be null because it just got set up */ 1303 struct conversation *cnv = find_conversation(name); /* this will never be null because it just got set up */
1267 cnv->conn = newconn; 1304 cnv->conn = newconn;
1268 cnv->watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, newconn); 1305 cnv->watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, newconn);
1269 aim_conn_addhandler(gaim_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, gaim_directim_initiate, 0); 1306 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, gaim_directim_initiate, 0);
1270 } 1307 }
1271 1308
1272 void send_keepalive(gpointer d) { 1309 void send_keepalive(gpointer d) {
1310 struct gaim_connection *gc = (struct gaim_connection *)d;
1273 debug_print("sending oscar NOP\n"); 1311 debug_print("sending oscar NOP\n");
1274 if (USE_OSCAR) { /* keeping it open for TOC */ 1312 if (gc->protocol == PROTO_OSCAR) { /* keeping it open for TOC */
1275 aim_flap_nop(gaim_sess, gaim_conn); 1313 aim_flap_nop(gc->oscar_sess, gc->oscar_conn);
1276 } else { 1314 } else if (gc->protocol == PROTO_TOC) {
1277 sflap_send("", 0, TYPE_KEEPALIVE); 1315 sflap_send(gc, "", 0, TYPE_KEEPALIVE);
1278 } 1316 }
1279 } 1317 }
1280 1318
1281 void update_keepalive(gboolean on) { 1319 void update_keepalive(struct gaim_connection *gc, gboolean on) {
1282 if (on && keepalv < 0 && blist) { 1320 if (on && gc->keepalive < 0 && blist) {
1283 debug_print("allowing NOP\n"); 1321 debug_print("allowing NOP\n");
1284 keepalv = gtk_timeout_add(60000, (GtkFunction)send_keepalive, 0); 1322 gc->keepalive = gtk_timeout_add(60000, (GtkFunction)send_keepalive, gc);
1285 } else if (!on && keepalv > -1) { 1323 } else if (!on && gc->keepalive > -1) {
1286 debug_print("removing NOP\n"); 1324 debug_print("removing NOP\n");
1287 gtk_timeout_remove(keepalv); 1325 gtk_timeout_remove(gc->keepalive);
1288 keepalv = -1; 1326 gc->keepalive = -1;
1289 } 1327 }
1290 } 1328 }