comparison plugins/oscar.c @ 999:0b5db8cdd30f

[gaim-migrate @ 1009] update to work with new per-protocol-connection data, i think committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 15 Oct 2000 03:55:23 +0000
parents 7e231bc0018a
children 91b7377e7b45
comparison
equal deleted inserted replaced
998:70c685de2be5 999:0b5db8cdd30f
46 #include "pixmaps/cancel.xpm" 46 #include "pixmaps/cancel.xpm"
47 #include "pixmaps/ok.xpm" 47 #include "pixmaps/ok.xpm"
48 48
49 int gaim_caps = AIM_CAPS_CHAT | AIM_CAPS_SENDFILE | AIM_CAPS_GETFILE | 49 int gaim_caps = AIM_CAPS_CHAT | AIM_CAPS_SENDFILE | AIM_CAPS_GETFILE |
50 AIM_CAPS_VOICE | AIM_CAPS_IMIMAGE | AIM_CAPS_BUDDYICON; 50 AIM_CAPS_VOICE | AIM_CAPS_IMIMAGE | AIM_CAPS_BUDDYICON;
51 int keepalv = -1; 51
52 struct oscar_data {
53 struct aim_session_t *sess;
54 struct aim_conn_t *conn;
55
56 int cnpa;
57 int paspa;
58
59 int create_exchange;
60 char *create_name;
61
62 GSList *oscar_chats;
63 };
52 64
53 struct chat_connection *find_oscar_chat(struct gaim_connection *gc, char *name) { 65 struct chat_connection *find_oscar_chat(struct gaim_connection *gc, char *name) {
54 GSList *g = gc->oscar_chats; 66 GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats;
55 struct chat_connection *c = NULL; 67 struct chat_connection *c = NULL;
56 if (gc->protocol != PROTO_OSCAR) return NULL; 68 if (gc->protocol != PROTO_OSCAR) return NULL;
57 69
58 while (g) { 70 while (g) {
59 c = (struct chat_connection *)g->data; 71 c = (struct chat_connection *)g->data;
66 return c; 78 return c;
67 } 79 }
68 80
69 static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc, 81 static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc,
70 struct aim_conn_t *conn) { 82 struct aim_conn_t *conn) {
71 GSList *g = gc->oscar_chats; 83 GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats;
72 struct chat_connection *c = NULL; 84 struct chat_connection *c = NULL;
73 85
74 while (g) { 86 while (g) {
75 c = (struct chat_connection *)g->data; 87 c = (struct chat_connection *)g->data;
76 if (c->conn == conn) 88 if (c->conn == conn)
86 GSList *g = connections; 98 GSList *g = connections;
87 struct gaim_connection *gc = NULL; 99 struct gaim_connection *gc = NULL;
88 100
89 while (g) { 101 while (g) {
90 gc = (struct gaim_connection *)g->data; 102 gc = (struct gaim_connection *)g->data;
91 if (sess == gc->oscar_sess) 103 if (sess == ((struct oscar_data *)gc->proto_data)->sess)
92 break; 104 break;
93 g = g->next; 105 g = g->next;
94 gc = NULL; 106 gc = NULL;
95 } 107 }
96 108
106 if (c->protocol != PROTO_OSCAR) { 118 if (c->protocol != PROTO_OSCAR) {
107 c = NULL; 119 c = NULL;
108 g = g->next; 120 g = g->next;
109 continue; 121 continue;
110 } 122 }
111 s = c->oscar_sess->connlist; 123 s = ((struct oscar_data *)c->proto_data)->sess->connlist;
112 while (s) { 124 while (s) {
113 if (conn == s) 125 if (conn == s)
114 break; 126 break;
115 s = s->next; 127 s = s->next;
116 } 128 }
182 194
183 static void oscar_callback(gpointer data, gint source, 195 static void oscar_callback(gpointer data, gint source,
184 GdkInputCondition condition) { 196 GdkInputCondition condition) {
185 struct aim_conn_t *conn = (struct aim_conn_t *)data; 197 struct aim_conn_t *conn = (struct aim_conn_t *)data;
186 struct gaim_connection *gc = find_gaim_conn_by_oscar_conn(conn); 198 struct gaim_connection *gc = find_gaim_conn_by_oscar_conn(conn);
199 struct oscar_data *odata = (struct oscar_data *)gc->proto_data;
187 if (!gc) { 200 if (!gc) {
188 /* oh boy. this is probably bad. i guess the only thing we can really do 201 /* oh boy. this is probably bad. i guess the only thing we can really do
189 * is return? */ 202 * is return? */
190 debug_print("oscar callback for closed connection.\n"); 203 debug_print("oscar callback for closed connection.\n");
191 return; 204 return;
192 } 205 }
193 206
194 if (condition & GDK_INPUT_EXCEPTION) { 207 if (condition & GDK_INPUT_EXCEPTION) {
195 hide_login_progress(gc->username, _("Disconnected.")); 208 hide_login_progress(gc, _("Disconnected."));
196 signoff(gc); 209 signoff(gc);
197 return; 210 return;
198 } 211 }
199 if (condition & GDK_INPUT_READ) { 212 if (condition & GDK_INPUT_READ) {
200 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { 213 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
201 debug_print("got information on rendezvous\n"); 214 debug_print("got information on rendezvous\n");
202 if (aim_handlerendconnect(gc->oscar_sess, conn) < 0) { 215 if (aim_handlerendconnect(odata->sess, conn) < 0) {
203 debug_print(_("connection error (rend)\n")); 216 debug_print(_("connection error (rend)\n"));
204 } 217 }
205 } else { 218 } else {
206 if (aim_get_command(gc->oscar_sess, conn) >= 0) { 219 if (aim_get_command(odata->sess, conn) >= 0) {
207 aim_rxdispatch(gc->oscar_sess); 220 aim_rxdispatch(odata->sess);
208 } else { 221 } else {
209 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS && 222 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS &&
210 conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { 223 conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) {
211 struct conversation *cnv = 224 struct conversation *cnv =
212 find_conversation(((struct aim_directim_priv *)conn->priv)->sn); 225 find_conversation(((struct aim_directim_priv *)conn->priv)->sn);
213 debug_print("connection error for directim\n"); 226 debug_print("connection error for directim\n");
214 if (cnv) { 227 if (cnv) {
215 make_direct(cnv, FALSE, NULL, 0); 228 make_direct(cnv, FALSE, NULL, 0);
216 } 229 }
217 aim_conn_kill(gc->oscar_sess, &conn); 230 aim_conn_kill(odata->sess, &conn);
218 } else if ((conn->type == AIM_CONN_TYPE_BOS) || 231 } else if ((conn->type == AIM_CONN_TYPE_BOS) ||
219 !(aim_getconn_type(gc->oscar_sess, AIM_CONN_TYPE_BOS))) { 232 !(aim_getconn_type(odata->sess, AIM_CONN_TYPE_BOS))) {
220 debug_print(_("major connection error\n")); 233 debug_print(_("major connection error\n"));
221 hide_login_progress(gc->username, _("Disconnected.")); 234 hide_login_progress(gc, _("Disconnected."));
222 signoff(gc); 235 signoff(gc);
223 } else if (conn->type == AIM_CONN_TYPE_CHAT) { 236 } else if (conn->type == AIM_CONN_TYPE_CHAT) {
224 struct chat_connection *c = find_oscar_chat_by_conn(gc, conn); 237 struct chat_connection *c = find_oscar_chat_by_conn(gc, conn);
225 char buf[BUF_LONG]; 238 char buf[BUF_LONG];
226 sprintf(debug_buff, "disconnected from chat room %s\n", c->name); 239 sprintf(debug_buff, "disconnected from chat room %s\n", c->name);
228 c->conn = NULL; 241 c->conn = NULL;
229 if (c->inpa > -1) 242 if (c->inpa > -1)
230 gdk_input_remove(c->inpa); 243 gdk_input_remove(c->inpa);
231 c->inpa = -1; 244 c->inpa = -1;
232 c->fd = -1; 245 c->fd = -1;
233 aim_conn_kill(gc->oscar_sess, &conn); 246 aim_conn_kill(odata->sess, &conn);
234 sprintf(buf, _("You have been disconnected from chat room %s."), c->name); 247 sprintf(buf, _("You have been disconnected from chat room %s."), c->name);
235 do_error_dialog(buf, _("Chat Error!")); 248 do_error_dialog(buf, _("Chat Error!"));
236 } else if (conn->type == AIM_CONN_TYPE_CHATNAV) { 249 } else if (conn->type == AIM_CONN_TYPE_CHATNAV) {
237 if (gc->cnpa > -1) 250 if (odata->cnpa > -1)
238 gdk_input_remove(gc->cnpa); 251 gdk_input_remove(odata->cnpa);
239 gc->cnpa = -1; 252 odata->cnpa = -1;
240 debug_print("removing chatnav input watcher\n"); 253 debug_print("removing chatnav input watcher\n");
241 aim_conn_kill(gc->oscar_sess, &conn); 254 aim_conn_kill(odata->sess, &conn);
242 } else { 255 } else {
243 sprintf(debug_buff, "holy crap! generic connection error! %d\n", 256 sprintf(debug_buff, "holy crap! generic connection error! %d\n",
244 conn->type); 257 conn->type);
245 debug_print(debug_buff); 258 debug_print(debug_buff);
246 aim_conn_kill(gc->oscar_sess, &conn); 259 aim_conn_kill(odata->sess, &conn);
247 } 260 }
248 } 261 }
249 } 262 }
250 } 263 }
251 } 264 }
252 265
253 void oscar_login(struct aim_user *user) { 266 void oscar_login(struct aim_user *user) {
254 struct aim_session_t *sess; 267 struct aim_session_t *sess;
255 struct aim_conn_t *conn; 268 struct aim_conn_t *conn;
256 char buf[256]; 269 char buf[256];
257 struct gaim_connection *gc; 270 struct gaim_connection *gc = new_gaim_conn(PROTO_OSCAR, user->username, user->password);
271 struct oscar_data *odata = gc->proto_data = g_new0(struct oscar_data, 1);
258 272
259 sprintf(debug_buff, _("Logging in %s\n"), user->username); 273 sprintf(debug_buff, _("Logging in %s\n"), user->username);
260 debug_print(debug_buff); 274 debug_print(debug_buff);
261 275
262 gc = new_gaim_conn(PROTO_OSCAR, user->username, user->password);
263 sess = g_new0(struct aim_session_t, 1); 276 sess = g_new0(struct aim_session_t, 1);
264 aim_session_init(sess); 277 aim_session_init(sess);
265 /* we need an immediate queue because we don't use a while-loop to 278 /* we need an immediate queue because we don't use a while-loop to
266 * see if things need to be sent. */ 279 * see if things need to be sent. */
267 sess->tx_enqueue = &aim_tx_enqueue__immediate; 280 sess->tx_enqueue = &aim_tx_enqueue__immediate;
268 gc->oscar_sess = sess; 281 odata->sess = sess;
269 282
270 sprintf(buf, _("Looking up %s"), FAIM_LOGIN_SERVER); 283 sprintf(buf, _("Looking up %s"), FAIM_LOGIN_SERVER);
284 set_login_progress(gc, 1, buf);
285 /* this creates a possible race condition, but hey, what can you do */
286 while (gtk_events_pending())
287 gtk_main_iteration();
271 conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, FAIM_LOGIN_SERVER); 288 conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, FAIM_LOGIN_SERVER);
272 289
273 if (conn == NULL) { 290 if (conn == NULL) {
274 debug_print(_("internal connection error\n")); 291 debug_print(_("internal connection error\n"));
275 hide_login_progress(gc->username, _("Unable to login to AIM")); 292 hide_login_progress(gc, _("Unable to login to AIM"));
276 destroy_gaim_conn(gc); 293 destroy_gaim_conn(gc);
277 return; 294 return;
278 } else if (conn->fd == -1) { 295 } else if (conn->fd == -1) {
279 if (conn->status & AIM_CONN_STATUS_RESOLVERR) { 296 if (conn->status & AIM_CONN_STATUS_RESOLVERR) {
280 sprintf(debug_buff, _("couldn't resolve host")); 297 sprintf(debug_buff, _("couldn't resolve host"));
281 debug_print(debug_buff); debug_print("\n"); 298 debug_print(debug_buff); debug_print("\n");
282 hide_login_progress(gc->username, debug_buff); 299 hide_login_progress(gc, debug_buff);
283 } else if (conn->status & AIM_CONN_STATUS_CONNERR) { 300 } else if (conn->status & AIM_CONN_STATUS_CONNERR) {
284 sprintf(debug_buff, _("couldn't connect to host")); 301 sprintf(debug_buff, _("couldn't connect to host"));
285 debug_print(debug_buff); debug_print("\n"); 302 debug_print(debug_buff); debug_print("\n");
286 hide_login_progress(gc->username, debug_buff); 303 hide_login_progress(gc, debug_buff);
287 } 304 }
288 destroy_gaim_conn(gc); 305 destroy_gaim_conn(gc);
289 return; 306 return;
290 } 307 }
291 g_snprintf(buf, sizeof(buf), _("Signon: %s"), gc->username); 308 g_snprintf(buf, sizeof(buf), _("Signon: %s"), gc->username);
309 set_login_progress(gc, 2, buf);
292 310
293 aim_conn_addhandler(sess, conn, 0x0017, 0x0007, gaim_parse_login, 0); 311 aim_conn_addhandler(sess, conn, 0x0017, 0x0007, gaim_parse_login, 0);
294 aim_conn_addhandler(sess, conn, 0x0017, 0x0003, gaim_parse_auth_resp, 0); 312 aim_conn_addhandler(sess, conn, 0x0017, 0x0003, gaim_parse_auth_resp, 0);
295 aim_sendconnack(sess, conn); 313 aim_sendconnack(sess, conn);
296 aim_request_login(sess, conn, gc->username); 314 aim_request_login(sess, conn, gc->username);
304 322
305 debug_print(_("Password sent, waiting for response\n")); 323 debug_print(_("Password sent, waiting for response\n"));
306 } 324 }
307 325
308 void oscar_close(struct gaim_connection *gc) { 326 void oscar_close(struct gaim_connection *gc) {
327 struct oscar_data *odata = (struct oscar_data *)gc->proto_data;
309 if (gc->protocol != PROTO_OSCAR) return; 328 if (gc->protocol != PROTO_OSCAR) return;
310 if (gc->inpa > 0) 329 if (gc->inpa > 0)
311 gdk_input_remove(gc->inpa); 330 gdk_input_remove(gc->inpa);
312 gc->inpa = -1; 331 if (odata->cnpa > 0)
313 if (gc->cnpa > 0) 332 gdk_input_remove(odata->cnpa);
314 gdk_input_remove(gc->cnpa); 333 if (odata->paspa > 0)
315 gc->cnpa = -1; 334 gdk_input_remove(odata->paspa);
316 if (gc->paspa > 0) 335 aim_logoff(odata->sess);
317 gdk_input_remove(gc->paspa); 336 g_free(odata->sess);
318 gc->paspa = -1; 337 g_free(gc->proto_data);
319 aim_logoff(gc->oscar_sess);
320 g_free(gc->oscar_sess);
321 debug_print(_("Signed off.\n")); 338 debug_print(_("Signed off.\n"));
322 } 339 }
323 340
324 int gaim_parse_auth_resp(struct aim_session_t *sess, 341 int gaim_parse_auth_resp(struct aim_session_t *sess,
325 struct command_rx_struct *command, ...) { 342 struct command_rx_struct *command, ...) {
355 debug_print(debug_buff); 372 debug_print(debug_buff);
356 #ifdef USE_APPLET 373 #ifdef USE_APPLET
357 set_user_state(offline); 374 set_user_state(offline);
358 #endif 375 #endif
359 gdk_input_remove(gc->inpa); 376 gdk_input_remove(gc->inpa);
360 hide_login_progress(gc->username, _("Authentication Failed")); 377 hide_login_progress(gc, _("Authentication Failed"));
361 signoff(gc); 378 signoff(gc);
362 return 0; 379 return 0;
363 } 380 }
364 381
365 382
377 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP); 394 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP);
378 if (bosconn == NULL) { 395 if (bosconn == NULL) {
379 #ifdef USE_APPLET 396 #ifdef USE_APPLET
380 set_user_state(offline); 397 set_user_state(offline);
381 #endif 398 #endif
382 hide_login_progress(gc->username, _("Internal Error")); 399 hide_login_progress(gc, _("Internal Error"));
383 destroy_gaim_conn(gc); 400 destroy_gaim_conn(gc);
384 return -1; 401 return -1;
385 } else if (bosconn->status != 0) { 402 } else if (bosconn->status != 0) {
386 #ifdef USE_APPLET 403 #ifdef USE_APPLET
387 set_user_state(offline); 404 set_user_state(offline);
388 #endif 405 #endif
389 hide_login_progress(gc->username, _("Could Not Connect")); 406 hide_login_progress(gc, _("Could Not Connect"));
390 destroy_gaim_conn(gc); 407 destroy_gaim_conn(gc);
391 return -1; 408 return -1;
392 } 409 }
393 410
394 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, gaim_bosrights, 0); 411 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, gaim_bosrights, 0);
412 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0); 429 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0);
413 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0); 430 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
414 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); 431 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0);
415 432
416 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie); 433 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie);
417 gc->oscar_conn = bosconn; 434 ((struct oscar_data *)gc->proto_data)->conn = bosconn;
418 gc->inpa = gdk_input_add(bosconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 435 gc->inpa = gdk_input_add(bosconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
419 oscar_callback, bosconn); 436 oscar_callback, bosconn);
437 set_login_progress(gc, 4, _("Connection established, cookie sent"));
420 return 1; 438 return 1;
421 } 439 }
422 440
423 int gaim_parse_login(struct aim_session_t *sess, 441 int gaim_parse_login(struct aim_session_t *sess,
424 struct command_rx_struct *command, ...) { 442 struct command_rx_struct *command, ...) {
480 va_list ap; 498 va_list ap;
481 int serviceid; 499 int serviceid;
482 char *ip; 500 char *ip;
483 unsigned char *cookie; 501 unsigned char *cookie;
484 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess); 502 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
503 struct oscar_data *odata = (struct oscar_data *)gc->proto_data;
485 504
486 va_start(ap, command); 505 va_start(ap, command);
487 serviceid = va_arg(ap, int); 506 serviceid = va_arg(ap, int);
488 ip = va_arg(ap, char *); 507 ip = va_arg(ap, char *);
489 cookie = va_arg(ap, unsigned char *); 508 cookie = va_arg(ap, unsigned char *);
494 { 513 {
495 struct aim_conn_t *tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip); 514 struct aim_conn_t *tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
496 if (tstconn == NULL || tstconn->status >= AIM_CONN_STATUS_RESOLVERR) 515 if (tstconn == NULL || tstconn->status >= AIM_CONN_STATUS_RESOLVERR)
497 debug_print("unable to reconnect with authorizer\n"); 516 debug_print("unable to reconnect with authorizer\n");
498 else { 517 else {
499 gc->paspa = gdk_input_add(tstconn->fd, 518 odata->paspa = gdk_input_add(tstconn->fd,
500 GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 519 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
501 oscar_callback, tstconn); 520 oscar_callback, tstconn);
502 aim_auth_sendcookie(sess, tstconn, cookie); 521 aim_auth_sendcookie(sess, tstconn, cookie);
503 } 522 }
504 } 523 }
510 debug_print("unable to connect to chatnav server\n"); 529 debug_print("unable to connect to chatnav server\n");
511 return 1; 530 return 1;
512 } 531 }
513 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); 532 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0);
514 aim_auth_sendcookie(sess, tstconn, cookie); 533 aim_auth_sendcookie(sess, tstconn, cookie);
515 gc->cnpa = gdk_input_add(tstconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 534 odata->cnpa = gdk_input_add(tstconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
516 oscar_callback, tstconn); 535 oscar_callback, tstconn);
517 } 536 }
518 debug_print("chatnav: connected\n"); 537 debug_print("chatnav: connected\n");
519 break; 538 break;
520 case 0xe: /* Chat */ 539 case 0xe: /* Chat */
536 555
537 ccon->inpa = gdk_input_add(tstconn->fd, 556 ccon->inpa = gdk_input_add(tstconn->fd,
538 GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 557 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
539 oscar_callback, tstconn); 558 oscar_callback, tstconn);
540 559
541 gc->oscar_chats = g_slist_append(gc->oscar_chats, ccon); 560 odata->oscar_chats = g_slist_append(odata->oscar_chats, ccon);
542 561
543 aim_chat_attachname(tstconn, roomname); 562 aim_chat_attachname(tstconn, roomname);
544 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); 563 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0);
545 aim_auth_sendcookie(sess, tstconn, cookie); 564 aim_auth_sendcookie(sess, tstconn, cookie);
546 } 565 }
608 static void accept_directim(GtkWidget *w, GtkWidget *m) 627 static void accept_directim(GtkWidget *w, GtkWidget *m)
609 { 628 {
610 struct aim_conn_t *newconn; 629 struct aim_conn_t *newconn;
611 struct aim_directim_priv *priv; 630 struct aim_directim_priv *priv;
612 struct gaim_connection *gc; 631 struct gaim_connection *gc;
632 struct oscar_data *odata;
613 int watcher; 633 int watcher;
614 634
615 priv = (struct aim_directim_priv *)gtk_object_get_user_data(GTK_OBJECT(m)); 635 priv = (struct aim_directim_priv *)gtk_object_get_user_data(GTK_OBJECT(m));
616 gc = (struct gaim_connection *)gtk_object_get_user_data(GTK_OBJECT(w)); 636 gc = (struct gaim_connection *)gtk_object_get_user_data(GTK_OBJECT(w));
637 odata = (struct oscar_data *)gc->proto_data;
617 gtk_widget_destroy(m); 638 gtk_widget_destroy(m);
618 639
619 if (!(newconn = aim_directim_connect(gc->oscar_sess, gc->oscar_conn, priv))) { 640 if (!(newconn = aim_directim_connect(odata->sess, odata->conn, priv))) {
620 debug_print("imimage: could not connect\n"); 641 debug_print("imimage: could not connect\n");
621 return; 642 return;
622 } 643 }
623 644
624 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0); 645 aim_conn_addhandler(odata->sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0);
625 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, gaim_directim_typing, 0); 646 aim_conn_addhandler(odata->sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, gaim_directim_typing, 0);
626 647
627 watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, 648 watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
628 oscar_callback, newconn); 649 oscar_callback, newconn);
629 650
630 sprintf(debug_buff, "DirectIM: connected to %s\n", priv->sn); 651 sprintf(debug_buff, "DirectIM: connected to %s\n", priv->sn);
905 int gaim_chatnav_info(struct aim_session_t *sess, 926 int gaim_chatnav_info(struct aim_session_t *sess,
906 struct command_rx_struct *command, ...) { 927 struct command_rx_struct *command, ...) {
907 va_list ap; 928 va_list ap;
908 u_short type; 929 u_short type;
909 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess); 930 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
931 struct oscar_data *odata = (struct oscar_data *)gc->proto_data;
910 932
911 va_start(ap, command); 933 va_start(ap, command);
912 type = (u_short)va_arg(ap, u_int); 934 type = (u_short)va_arg(ap, u_int);
913 935
914 switch(type) { 936 switch(type) {
934 exchanges[i].charset1, 956 exchanges[i].charset1,
935 exchanges[i].lang1); 957 exchanges[i].lang1);
936 debug_print(debug_buff); 958 debug_print(debug_buff);
937 i++; 959 i++;
938 } 960 }
939 if (gc->create_exchange) { 961 if (odata->create_exchange) {
940 sprintf(debug_buff, "creating room %s\n", 962 sprintf(debug_buff, "creating room %s\n", odata->create_name);
941 gc->create_name);
942 debug_print(debug_buff); 963 debug_print(debug_buff);
943 aim_chatnav_createroom(sess, command->conn, gc->create_name, gc->create_exchange); 964 aim_chatnav_createroom(sess, command->conn, odata->create_name,
944 gc->create_exchange = 0; 965 odata->create_exchange);
945 g_free(gc->create_name); 966 odata->create_exchange = 0;
946 gc->create_name = NULL; 967 g_free(odata->create_name);
968 odata->create_name = NULL;
947 } 969 }
948 } 970 }
949 break; 971 break;
950 case 0x0008: { 972 case 0x0008: {
951 char *fqcn, *name, *ck; 973 char *fqcn, *name, *ck;
968 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); 990 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);
969 debug_print(debug_buff); 991 debug_print(debug_buff);
970 if (flags & 0x4) { 992 if (flags & 0x4) {
971 sprintf(debug_buff, "joining %s on exchange 5\n", name); 993 sprintf(debug_buff, "joining %s on exchange 5\n", name);
972 debug_print(debug_buff); 994 debug_print(debug_buff);
973 aim_chat_join(gc->oscar_sess, gc->oscar_conn, 5, ck); 995 aim_chat_join(odata->sess, odata->conn, 5, ck);
974 } else 996 } else
975 sprintf(debug_buff, "joining %s on exchange 4\n", name);{ 997 sprintf(debug_buff, "joining %s on exchange 4\n", name);{
976 debug_print(debug_buff); 998 debug_print(debug_buff);
977 aim_chat_join(gc->oscar_sess, gc->oscar_conn, 4, ck); 999 aim_chat_join(odata->sess, odata->conn, 4, ck);
978 } 1000 }
979 } 1001 }
980 break; 1002 break;
981 default: 1003 default:
982 va_end(ap); 1004 va_end(ap);
1293 1315
1294 return 1; 1316 return 1;
1295 } 1317 }
1296 1318
1297 void oscar_do_directim(struct gaim_connection *gc, char *name) { 1319 void oscar_do_directim(struct gaim_connection *gc, char *name) {
1298 struct aim_conn_t *newconn = aim_directim_initiate(gc->oscar_sess, gc->oscar_conn, NULL, name); 1320 struct oscar_data *odata = (struct oscar_data *)gc->proto_data;
1299 struct conversation *cnv = find_conversation(name); /* this will never be null because it just got set up */ 1321 struct aim_conn_t *newconn = aim_directim_initiate(odata->sess, odata->conn, NULL, name);
1322 struct conversation *cnv = find_conversation(name); /* this will never be null because
1323 it just got set up */
1300 cnv->conn = newconn; 1324 cnv->conn = newconn;
1301 cnv->watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, newconn); 1325 cnv->watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, newconn);
1302 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, gaim_directim_initiate, 0); 1326 aim_conn_addhandler(odata->sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, gaim_directim_initiate, 0);
1303 } 1327 }
1304 1328
1305 static void oscar_keepalive(struct gaim_connection *gc) { 1329 static void oscar_keepalive(struct gaim_connection *gc) {
1306 aim_flap_nop(gc->oscar_sess, gc->oscar_conn); 1330 struct oscar_data *odata = (struct oscar_data *)gc->proto_data;
1331 aim_flap_nop(odata->sess, odata->conn);
1307 } 1332 }
1308 1333
1309 static char *oscar_name() { 1334 static char *oscar_name() {
1310 return "Oscar"; 1335 return "Oscar";
1311 } 1336 }
1312 1337
1313 char *name() {
1314 return "Oscar";
1315 }
1316
1317 char *description() {
1318 return "Allows gaim to use the Oscar protocol";
1319 }
1320
1321 static void oscar_send_im(struct gaim_connection *gc, char *name, char *message, int away) { 1338 static void oscar_send_im(struct gaim_connection *gc, char *name, char *message, int away) {
1339 struct oscar_data *odata = (struct oscar_data *)gc->proto_data;
1322 struct conversation *cnv = find_conversation(name); 1340 struct conversation *cnv = find_conversation(name);
1323 if (cnv && cnv->is_direct) { 1341 if (cnv && cnv->is_direct) {
1324 debug_printf("Sending DirectIM to %s\n", name); 1342 debug_printf("Sending DirectIM to %s\n", name);
1325 aim_send_im_direct(gc->oscar_sess, cnv->conn, message); 1343 aim_send_im_direct(odata->sess, cnv->conn, message);
1326 } else { 1344 } else {
1327 if (away) 1345 if (away)
1328 aim_send_im(gc->oscar_sess, gc->oscar_conn, name, AIM_IMFLAGS_AWAY, message); 1346 aim_send_im(odata->sess, odata->conn, name, AIM_IMFLAGS_AWAY, message);
1329 else 1347 else
1330 aim_send_im(gc->oscar_sess, gc->oscar_conn, name, AIM_IMFLAGS_ACK, message); 1348 aim_send_im(odata->sess, odata->conn, name, AIM_IMFLAGS_ACK, message);
1331 } 1349 }
1332 } 1350 }
1333 1351
1334 static void oscar_get_info(struct gaim_connection *g, char *name) { 1352 static void oscar_get_info(struct gaim_connection *g, char *name) {
1335 aim_getinfo(g->oscar_sess, g->oscar_conn, name, AIM_GETINFO_GENERALINFO); 1353 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1354 aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_GENERALINFO);
1336 } 1355 }
1337 1356
1338 static void oscar_get_away_msg(struct gaim_connection *g, char *name) { 1357 static void oscar_get_away_msg(struct gaim_connection *g, char *name) {
1339 aim_getinfo(g->oscar_sess, g->oscar_conn, name, AIM_GETINFO_AWAYMESSAGE); 1358 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1359 aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_AWAYMESSAGE);
1340 } 1360 }
1341 1361
1342 static void oscar_set_dir(struct gaim_connection *g, char *first, char *middle, char *last, 1362 static void oscar_set_dir(struct gaim_connection *g, char *first, char *middle, char *last,
1343 char *maiden, char *city, char *state, char *country, int web) { 1363 char *maiden, char *city, char *state, char *country, int web) {
1344 /* FIXME : some of these things are wrong, but i'm lazy */ 1364 /* FIXME : some of these things are wrong, but i'm lazy */
1345 aim_setdirectoryinfo(g->oscar_sess, g->oscar_conn, first, middle, last, 1365 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1366 aim_setdirectoryinfo(odata->sess, odata->conn, first, middle, last,
1346 maiden, NULL, NULL, city, state, NULL, 0, web); 1367 maiden, NULL, NULL, city, state, NULL, 0, web);
1347 } 1368 }
1348 1369
1349 1370
1350 static void oscar_set_idle(struct gaim_connection *g, int time) { 1371 static void oscar_set_idle(struct gaim_connection *g, int time) {
1351 aim_bos_setidle(g->oscar_sess, g->oscar_conn, time); 1372 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1373 aim_bos_setidle(odata->sess, odata->conn, time);
1352 } 1374 }
1353 1375
1354 static void oscar_set_info(struct gaim_connection *g, char *info) { 1376 static void oscar_set_info(struct gaim_connection *g, char *info) {
1377 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1355 if (awaymessage) 1378 if (awaymessage)
1356 aim_bos_setprofile(g->oscar_sess, g->oscar_conn, info, 1379 aim_bos_setprofile(odata->sess, odata->conn, info,
1357 awaymessage->message, gaim_caps); 1380 awaymessage->message, gaim_caps);
1358 else 1381 else
1359 aim_bos_setprofile(g->oscar_sess, g->oscar_conn, info, 1382 aim_bos_setprofile(odata->sess, odata->conn, info,
1360 NULL, gaim_caps); 1383 NULL, gaim_caps);
1361 } 1384 }
1362 1385
1363 static void oscar_set_away(struct gaim_connection *g, char *message) { 1386 static void oscar_set_away(struct gaim_connection *g, char *message) {
1364 aim_bos_setprofile(g->oscar_sess, g->oscar_conn, g->user_info, message, gaim_caps); 1387 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1388 aim_bos_setprofile(odata->sess, odata->conn, g->user_info, message, gaim_caps);
1365 } 1389 }
1366 1390
1367 static void oscar_warn(struct gaim_connection *g, char *name, int anon) { 1391 static void oscar_warn(struct gaim_connection *g, char *name, int anon) {
1368 aim_send_warning(g->oscar_sess, g->oscar_conn, name, anon); 1392 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1393 aim_send_warning(odata->sess, odata->conn, name, anon);
1369 } 1394 }
1370 1395
1371 static void oscar_dir_search(struct gaim_connection *g, char *first, char *middle, char *last, 1396 static void oscar_dir_search(struct gaim_connection *g, char *first, char *middle, char *last,
1372 char *maiden, char *city, char *state, char *country, char *email) { 1397 char *maiden, char *city, char *state, char *country, char *email) {
1398 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1373 if (strlen(email)) 1399 if (strlen(email))
1374 aim_usersearch_address(g->oscar_sess, g->oscar_conn, email); 1400 aim_usersearch_address(odata->sess, odata->conn, email);
1375 } 1401 }
1376 1402
1377 static void oscar_add_buddy(struct gaim_connection *g, char *name) { 1403 static void oscar_add_buddy(struct gaim_connection *g, char *name) {
1378 aim_add_buddy(g->oscar_sess, g->oscar_conn, name); 1404 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1405 aim_add_buddy(odata->sess, odata->conn, name);
1379 } 1406 }
1380 1407
1381 static void oscar_add_buddies(struct gaim_connection *g, GList *buddies) { 1408 static void oscar_add_buddies(struct gaim_connection *g, GList *buddies) {
1409 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1382 char buf[MSG_LEN]; 1410 char buf[MSG_LEN];
1383 int n = 0; 1411 int n = 0;
1384 while (buddies) { 1412 while (buddies) {
1385 if (n > MSG_LEN - 18) { 1413 if (n > MSG_LEN - 18) {
1386 aim_bos_setbuddylist(g->oscar_sess, g->oscar_conn, buf); 1414 aim_bos_setbuddylist(odata->sess, odata->conn, buf);
1387 n = 0; 1415 n = 0;
1388 } 1416 }
1389 n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (char *)buddies->data); 1417 n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (char *)buddies->data);
1390 buddies = buddies->next; 1418 buddies = buddies->next;
1391 } 1419 }
1392 aim_bos_setbuddylist(g->oscar_sess, g->oscar_conn, buf); 1420 aim_bos_setbuddylist(odata->sess, odata->conn, buf);
1393 } 1421 }
1394 1422
1395 static void oscar_remove_buddy(struct gaim_connection *g, char *name) { 1423 static void oscar_remove_buddy(struct gaim_connection *g, char *name) {
1396 aim_remove_buddy(g->oscar_sess, g->oscar_conn, name); 1424 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1425 aim_remove_buddy(odata->sess, odata->conn, name);
1397 } 1426 }
1398 1427
1399 static void oscar_join_chat(struct gaim_connection *g, int exchange, char *name) { 1428 static void oscar_join_chat(struct gaim_connection *g, int exchange, char *name) {
1429 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1400 struct aim_conn_t *cur = NULL; 1430 struct aim_conn_t *cur = NULL;
1401 sprintf(debug_buff, "Attempting to join chat room %s.\n", name); 1431 sprintf(debug_buff, "Attempting to join chat room %s.\n", name);
1402 debug_print(debug_buff); 1432 debug_print(debug_buff);
1403 if ((cur = aim_getconn_type(g->oscar_sess, AIM_CONN_TYPE_CHATNAV))) { 1433 if ((cur = aim_getconn_type(odata->sess, AIM_CONN_TYPE_CHATNAV))) {
1404 debug_print("chatnav exists, creating room\n"); 1434 debug_print("chatnav exists, creating room\n");
1405 aim_chatnav_createroom(g->oscar_sess, cur, name, exchange); 1435 aim_chatnav_createroom(odata->sess, cur, name, exchange);
1406 } else { 1436 } else {
1407 /* this gets tricky */ 1437 /* this gets tricky */
1408 debug_print("chatnav does not exist, opening chatnav\n"); 1438 debug_print("chatnav does not exist, opening chatnav\n");
1409 g->create_exchange = exchange; 1439 odata->create_exchange = exchange;
1410 g->create_name = g_strdup(name); 1440 odata->create_name = g_strdup(name);
1411 aim_bos_reqservice(g->oscar_sess, g->oscar_conn, AIM_CONN_TYPE_CHATNAV); 1441 aim_bos_reqservice(odata->sess, odata->conn, AIM_CONN_TYPE_CHATNAV);
1412 } 1442 }
1413 } 1443 }
1414 1444
1415 static void oscar_chat_invite(struct gaim_connection *g, int id, char *message, char *name) { 1445 static void oscar_chat_invite(struct gaim_connection *g, int id, char *message, char *name) {
1446 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1416 GSList *bcs = g->buddy_chats; 1447 GSList *bcs = g->buddy_chats;
1417 struct conversation *b = NULL; 1448 struct conversation *b = NULL;
1418 1449
1419 while (bcs) { 1450 while (bcs) {
1420 b = (struct conversation *)bcs->data; 1451 b = (struct conversation *)bcs->data;
1425 } 1456 }
1426 1457
1427 if (!b) 1458 if (!b)
1428 return; 1459 return;
1429 1460
1430 aim_chat_invite(g->oscar_sess, g->oscar_conn, name, 1461 aim_chat_invite(odata->sess, odata->conn, name,
1431 message ? message : "", 0x4, b->name, 0x0); 1462 message ? message : "", 0x4, b->name, 0x0);
1432 } 1463 }
1433 1464
1434 static void oscar_chat_leave(struct gaim_connection *g, int id) { 1465 static void oscar_chat_leave(struct gaim_connection *g, int id) {
1466 struct oscar_data *odata = g ? (struct oscar_data *)g->proto_data : NULL;
1435 GSList *bcs = g->buddy_chats; 1467 GSList *bcs = g->buddy_chats;
1436 struct conversation *b = NULL; 1468 struct conversation *b = NULL;
1437 struct chat_connection *c = NULL; 1469 struct chat_connection *c = NULL;
1438 int count = 0; 1470 int count = 0;
1439 1471
1453 b->name, count); 1485 b->name, count);
1454 debug_print(debug_buff); 1486 debug_print(debug_buff);
1455 1487
1456 c = find_oscar_chat(g, b->name); 1488 c = find_oscar_chat(g, b->name);
1457 if (c != NULL) { 1489 if (c != NULL) {
1458 g->oscar_chats = g_slist_remove(g->oscar_chats, c); 1490 if (odata)
1491 odata->oscar_chats = g_slist_remove(odata->oscar_chats, c);
1459 gdk_input_remove(c->inpa); 1492 gdk_input_remove(c->inpa);
1460 if (g && g->oscar_sess) 1493 if (g && odata->sess)
1461 aim_conn_kill(g->oscar_sess, &c->conn); 1494 aim_conn_kill(odata->sess, &c->conn);
1462 g_free(c->name); 1495 g_free(c->name);
1463 g_free(c); 1496 g_free(c);
1464 } 1497 }
1465 /* we do this because with Oscar it doesn't tell us we left */ 1498 /* we do this because with Oscar it doesn't tell us we left */
1466 serv_got_chat_left(g, b->id); 1499 serv_got_chat_left(g, b->id);
1470 do_error_dialog("Sorry, Oscar doesn't whisper. Send an IM. (The last message was not received.)", 1503 do_error_dialog("Sorry, Oscar doesn't whisper. Send an IM. (The last message was not received.)",
1471 "Gaim - Chat"); 1504 "Gaim - Chat");
1472 } 1505 }
1473 1506
1474 static void oscar_chat_send(struct gaim_connection *g, int id, char *message) { 1507 static void oscar_chat_send(struct gaim_connection *g, int id, char *message) {
1508 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
1475 struct aim_conn_t *cn; 1509 struct aim_conn_t *cn;
1476 GSList *bcs = g->buddy_chats; 1510 GSList *bcs = g->buddy_chats;
1477 struct conversation *b = NULL; 1511 struct conversation *b = NULL;
1478 1512
1479 while (bcs) { 1513 while (bcs) {
1484 b = NULL; 1518 b = NULL;
1485 } 1519 }
1486 if (!b) 1520 if (!b)
1487 return; 1521 return;
1488 1522
1489 cn = aim_chat_getconn(g->oscar_sess, b->name); 1523 cn = aim_chat_getconn(odata->sess, b->name);
1490 aim_chat_send_im(g->oscar_sess, cn, message); 1524 aim_chat_send_im(odata->sess, cn, message);
1491 } 1525 }
1492 1526
1493 struct prpl *oscar_init() { 1527 struct prpl *oscar_init() {
1494 struct prpl *ret = g_new0(struct prpl, 1); 1528 struct prpl *ret = g_new0(struct prpl, 1);
1495 1529
1522 ret->keepalive = oscar_keepalive; 1556 ret->keepalive = oscar_keepalive;
1523 1557
1524 return ret; 1558 return ret;
1525 } 1559 }
1526 1560
1561 char *name() {
1562 return "Oscar";
1563 }
1564
1565 char *description() {
1566 return "Allows gaim to use the Oscar protocol";
1567 }
1568
1527 int gaim_plugin_init(void *handle) { 1569 int gaim_plugin_init(void *handle) {
1528 protocols = g_slist_append(protocols, oscar_init()); 1570 protocols = g_slist_append(protocols, oscar_init());
1529 return 0; 1571 return 0;
1530 } 1572 }