Mercurial > pidgin.yaz
comparison src/oscar.c @ 998:70c685de2be5
[gaim-migrate @ 1008]
this is going to make it easier to add more protocols. each protocol now sets up connections with protocol-specific data.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 15 Oct 2000 03:50:32 +0000 |
parents | 9523b772e546 |
children | 91b7377e7b45 |
comparison
equal
deleted
inserted
replaced
997:56cff2fba28c | 998:70c685de2be5 |
---|---|
48 #include "pixmaps/cancel.xpm" | 48 #include "pixmaps/cancel.xpm" |
49 #include "pixmaps/ok.xpm" | 49 #include "pixmaps/ok.xpm" |
50 | 50 |
51 int gaim_caps = AIM_CAPS_CHAT | AIM_CAPS_SENDFILE | AIM_CAPS_GETFILE | | 51 int gaim_caps = AIM_CAPS_CHAT | AIM_CAPS_SENDFILE | AIM_CAPS_GETFILE | |
52 AIM_CAPS_VOICE | AIM_CAPS_IMIMAGE | AIM_CAPS_BUDDYICON; | 52 AIM_CAPS_VOICE | AIM_CAPS_IMIMAGE | AIM_CAPS_BUDDYICON; |
53 int keepalv = -1; | 53 |
54 struct oscar_data { | |
55 struct aim_session_t *sess; | |
56 struct aim_conn_t *conn; | |
57 | |
58 int cnpa; | |
59 int paspa; | |
60 | |
61 int create_exchange; | |
62 char *create_name; | |
63 | |
64 GSList *oscar_chats; | |
65 }; | |
54 | 66 |
55 struct chat_connection *find_oscar_chat(struct gaim_connection *gc, char *name) { | 67 struct chat_connection *find_oscar_chat(struct gaim_connection *gc, char *name) { |
56 GSList *g = gc->oscar_chats; | 68 GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats; |
57 struct chat_connection *c = NULL; | 69 struct chat_connection *c = NULL; |
58 if (gc->protocol != PROTO_OSCAR) return NULL; | 70 if (gc->protocol != PROTO_OSCAR) return NULL; |
59 | 71 |
60 while (g) { | 72 while (g) { |
61 c = (struct chat_connection *)g->data; | 73 c = (struct chat_connection *)g->data; |
68 return c; | 80 return c; |
69 } | 81 } |
70 | 82 |
71 static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc, | 83 static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc, |
72 struct aim_conn_t *conn) { | 84 struct aim_conn_t *conn) { |
73 GSList *g = gc->oscar_chats; | 85 GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats; |
74 struct chat_connection *c = NULL; | 86 struct chat_connection *c = NULL; |
75 | 87 |
76 while (g) { | 88 while (g) { |
77 c = (struct chat_connection *)g->data; | 89 c = (struct chat_connection *)g->data; |
78 if (c->conn == conn) | 90 if (c->conn == conn) |
88 GSList *g = connections; | 100 GSList *g = connections; |
89 struct gaim_connection *gc = NULL; | 101 struct gaim_connection *gc = NULL; |
90 | 102 |
91 while (g) { | 103 while (g) { |
92 gc = (struct gaim_connection *)g->data; | 104 gc = (struct gaim_connection *)g->data; |
93 if (sess == gc->oscar_sess) | 105 if (sess == ((struct oscar_data *)gc->proto_data)->sess) |
94 break; | 106 break; |
95 g = g->next; | 107 g = g->next; |
96 gc = NULL; | 108 gc = NULL; |
97 } | 109 } |
98 | 110 |
108 if (c->protocol != PROTO_OSCAR) { | 120 if (c->protocol != PROTO_OSCAR) { |
109 c = NULL; | 121 c = NULL; |
110 g = g->next; | 122 g = g->next; |
111 continue; | 123 continue; |
112 } | 124 } |
113 s = c->oscar_sess->connlist; | 125 s = ((struct oscar_data *)c->proto_data)->sess->connlist; |
114 while (s) { | 126 while (s) { |
115 if (conn == s) | 127 if (conn == s) |
116 break; | 128 break; |
117 s = s->next; | 129 s = s->next; |
118 } | 130 } |
184 | 196 |
185 static void oscar_callback(gpointer data, gint source, | 197 static void oscar_callback(gpointer data, gint source, |
186 GdkInputCondition condition) { | 198 GdkInputCondition condition) { |
187 struct aim_conn_t *conn = (struct aim_conn_t *)data; | 199 struct aim_conn_t *conn = (struct aim_conn_t *)data; |
188 struct gaim_connection *gc = find_gaim_conn_by_oscar_conn(conn); | 200 struct gaim_connection *gc = find_gaim_conn_by_oscar_conn(conn); |
201 struct oscar_data *odata = (struct oscar_data *)gc->proto_data; | |
189 if (!gc) { | 202 if (!gc) { |
190 /* oh boy. this is probably bad. i guess the only thing we can really do | 203 /* oh boy. this is probably bad. i guess the only thing we can really do |
191 * is return? */ | 204 * is return? */ |
192 debug_print("oscar callback for closed connection.\n"); | 205 debug_print("oscar callback for closed connection.\n"); |
193 return; | 206 return; |
199 return; | 212 return; |
200 } | 213 } |
201 if (condition & GDK_INPUT_READ) { | 214 if (condition & GDK_INPUT_READ) { |
202 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { | 215 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { |
203 debug_print("got information on rendezvous\n"); | 216 debug_print("got information on rendezvous\n"); |
204 if (aim_handlerendconnect(gc->oscar_sess, conn) < 0) { | 217 if (aim_handlerendconnect(odata->sess, conn) < 0) { |
205 debug_print(_("connection error (rend)\n")); | 218 debug_print(_("connection error (rend)\n")); |
206 } | 219 } |
207 } else { | 220 } else { |
208 if (aim_get_command(gc->oscar_sess, conn) >= 0) { | 221 if (aim_get_command(odata->sess, conn) >= 0) { |
209 aim_rxdispatch(gc->oscar_sess); | 222 aim_rxdispatch(odata->sess); |
210 } else { | 223 } else { |
211 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS && | 224 if (conn->type == AIM_CONN_TYPE_RENDEZVOUS && |
212 conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { | 225 conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { |
213 struct conversation *cnv = | 226 struct conversation *cnv = |
214 find_conversation(((struct aim_directim_priv *)conn->priv)->sn); | 227 find_conversation(((struct aim_directim_priv *)conn->priv)->sn); |
215 debug_print("connection error for directim\n"); | 228 debug_print("connection error for directim\n"); |
216 if (cnv) { | 229 if (cnv) { |
217 make_direct(cnv, FALSE, NULL, 0); | 230 make_direct(cnv, FALSE, NULL, 0); |
218 } | 231 } |
219 aim_conn_kill(gc->oscar_sess, &conn); | 232 aim_conn_kill(odata->sess, &conn); |
220 } else if ((conn->type == AIM_CONN_TYPE_BOS) || | 233 } else if ((conn->type == AIM_CONN_TYPE_BOS) || |
221 !(aim_getconn_type(gc->oscar_sess, AIM_CONN_TYPE_BOS))) { | 234 !(aim_getconn_type(odata->sess, AIM_CONN_TYPE_BOS))) { |
222 debug_print(_("major connection error\n")); | 235 debug_print(_("major connection error\n")); |
223 hide_login_progress(gc, _("Disconnected.")); | 236 hide_login_progress(gc, _("Disconnected.")); |
224 signoff(gc); | 237 signoff(gc); |
225 } else if (conn->type == AIM_CONN_TYPE_CHAT) { | 238 } else if (conn->type == AIM_CONN_TYPE_CHAT) { |
226 struct chat_connection *c = find_oscar_chat_by_conn(gc, conn); | 239 struct chat_connection *c = find_oscar_chat_by_conn(gc, conn); |
230 c->conn = NULL; | 243 c->conn = NULL; |
231 if (c->inpa > -1) | 244 if (c->inpa > -1) |
232 gdk_input_remove(c->inpa); | 245 gdk_input_remove(c->inpa); |
233 c->inpa = -1; | 246 c->inpa = -1; |
234 c->fd = -1; | 247 c->fd = -1; |
235 aim_conn_kill(gc->oscar_sess, &conn); | 248 aim_conn_kill(odata->sess, &conn); |
236 sprintf(buf, _("You have been disconnected from chat room %s."), c->name); | 249 sprintf(buf, _("You have been disconnected from chat room %s."), c->name); |
237 do_error_dialog(buf, _("Chat Error!")); | 250 do_error_dialog(buf, _("Chat Error!")); |
238 } else if (conn->type == AIM_CONN_TYPE_CHATNAV) { | 251 } else if (conn->type == AIM_CONN_TYPE_CHATNAV) { |
239 if (gc->cnpa > -1) | 252 if (odata->cnpa > -1) |
240 gdk_input_remove(gc->cnpa); | 253 gdk_input_remove(odata->cnpa); |
241 gc->cnpa = -1; | 254 odata->cnpa = -1; |
242 debug_print("removing chatnav input watcher\n"); | 255 debug_print("removing chatnav input watcher\n"); |
243 aim_conn_kill(gc->oscar_sess, &conn); | 256 aim_conn_kill(odata->sess, &conn); |
244 } else { | 257 } else { |
245 sprintf(debug_buff, "holy crap! generic connection error! %d\n", | 258 sprintf(debug_buff, "holy crap! generic connection error! %d\n", |
246 conn->type); | 259 conn->type); |
247 debug_print(debug_buff); | 260 debug_print(debug_buff); |
248 aim_conn_kill(gc->oscar_sess, &conn); | 261 aim_conn_kill(odata->sess, &conn); |
249 } | 262 } |
250 } | 263 } |
251 } | 264 } |
252 } | 265 } |
253 } | 266 } |
255 void oscar_login(struct aim_user *user) { | 268 void oscar_login(struct aim_user *user) { |
256 struct aim_session_t *sess; | 269 struct aim_session_t *sess; |
257 struct aim_conn_t *conn; | 270 struct aim_conn_t *conn; |
258 char buf[256]; | 271 char buf[256]; |
259 struct gaim_connection *gc = new_gaim_conn(PROTO_OSCAR, user->username, user->password); | 272 struct gaim_connection *gc = new_gaim_conn(PROTO_OSCAR, user->username, user->password); |
273 struct oscar_data *odata = gc->proto_data = g_new0(struct oscar_data, 1); | |
260 | 274 |
261 sprintf(debug_buff, _("Logging in %s\n"), user->username); | 275 sprintf(debug_buff, _("Logging in %s\n"), user->username); |
262 debug_print(debug_buff); | 276 debug_print(debug_buff); |
263 | 277 |
264 sess = g_new0(struct aim_session_t, 1); | 278 sess = g_new0(struct aim_session_t, 1); |
265 aim_session_init(sess); | 279 aim_session_init(sess); |
266 /* we need an immediate queue because we don't use a while-loop to | 280 /* we need an immediate queue because we don't use a while-loop to |
267 * see if things need to be sent. */ | 281 * see if things need to be sent. */ |
268 sess->tx_enqueue = &aim_tx_enqueue__immediate; | 282 sess->tx_enqueue = &aim_tx_enqueue__immediate; |
269 gc->oscar_sess = sess; | 283 odata->sess = sess; |
270 | 284 |
271 sprintf(buf, _("Looking up %s"), FAIM_LOGIN_SERVER); | 285 sprintf(buf, _("Looking up %s"), FAIM_LOGIN_SERVER); |
272 set_login_progress(gc, 1, buf); | 286 set_login_progress(gc, 1, buf); |
273 /* this creates a possible race condition, but hey, what can you do */ | 287 /* this creates a possible race condition, but hey, what can you do */ |
274 while (gtk_events_pending()) | 288 while (gtk_events_pending()) |
310 | 324 |
311 debug_print(_("Password sent, waiting for response\n")); | 325 debug_print(_("Password sent, waiting for response\n")); |
312 } | 326 } |
313 | 327 |
314 void oscar_close(struct gaim_connection *gc) { | 328 void oscar_close(struct gaim_connection *gc) { |
329 struct oscar_data *odata = (struct oscar_data *)gc->proto_data; | |
315 if (gc->protocol != PROTO_OSCAR) return; | 330 if (gc->protocol != PROTO_OSCAR) return; |
316 if (gc->inpa > 0) | 331 if (gc->inpa > 0) |
317 gdk_input_remove(gc->inpa); | 332 gdk_input_remove(gc->inpa); |
318 gc->inpa = -1; | 333 if (odata->cnpa > 0) |
319 if (gc->cnpa > 0) | 334 gdk_input_remove(odata->cnpa); |
320 gdk_input_remove(gc->cnpa); | 335 if (odata->paspa > 0) |
321 gc->cnpa = -1; | 336 gdk_input_remove(odata->paspa); |
322 if (gc->paspa > 0) | 337 aim_logoff(odata->sess); |
323 gdk_input_remove(gc->paspa); | 338 g_free(odata->sess); |
324 gc->paspa = -1; | 339 g_free(gc->proto_data); |
325 aim_logoff(gc->oscar_sess); | |
326 g_free(gc->oscar_sess); | |
327 debug_print(_("Signed off.\n")); | 340 debug_print(_("Signed off.\n")); |
328 } | 341 } |
329 | 342 |
330 int gaim_parse_auth_resp(struct aim_session_t *sess, | 343 int gaim_parse_auth_resp(struct aim_session_t *sess, |
331 struct command_rx_struct *command, ...) { | 344 struct command_rx_struct *command, ...) { |
418 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0); | 431 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0); |
419 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0); | 432 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0); |
420 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); | 433 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); |
421 | 434 |
422 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie); | 435 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie); |
423 gc->oscar_conn = bosconn; | 436 ((struct oscar_data *)gc->proto_data)->conn = bosconn; |
424 gc->inpa = gdk_input_add(bosconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, | 437 gc->inpa = gdk_input_add(bosconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, |
425 oscar_callback, bosconn); | 438 oscar_callback, bosconn); |
426 set_login_progress(gc, 4, _("Connection established, cookie sent")); | 439 set_login_progress(gc, 4, _("Connection established, cookie sent")); |
427 return 1; | 440 return 1; |
428 } | 441 } |
487 va_list ap; | 500 va_list ap; |
488 int serviceid; | 501 int serviceid; |
489 char *ip; | 502 char *ip; |
490 unsigned char *cookie; | 503 unsigned char *cookie; |
491 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess); | 504 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess); |
505 struct oscar_data *odata = (struct oscar_data *)gc->proto_data; | |
492 | 506 |
493 va_start(ap, command); | 507 va_start(ap, command); |
494 serviceid = va_arg(ap, int); | 508 serviceid = va_arg(ap, int); |
495 ip = va_arg(ap, char *); | 509 ip = va_arg(ap, char *); |
496 cookie = va_arg(ap, unsigned char *); | 510 cookie = va_arg(ap, unsigned char *); |
501 { | 515 { |
502 struct aim_conn_t *tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip); | 516 struct aim_conn_t *tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip); |
503 if (tstconn == NULL || tstconn->status >= AIM_CONN_STATUS_RESOLVERR) | 517 if (tstconn == NULL || tstconn->status >= AIM_CONN_STATUS_RESOLVERR) |
504 debug_print("unable to reconnect with authorizer\n"); | 518 debug_print("unable to reconnect with authorizer\n"); |
505 else { | 519 else { |
506 gc->paspa = gdk_input_add(tstconn->fd, | 520 odata->paspa = gdk_input_add(tstconn->fd, |
507 GDK_INPUT_READ | GDK_INPUT_EXCEPTION, | 521 GDK_INPUT_READ | GDK_INPUT_EXCEPTION, |
508 oscar_callback, tstconn); | 522 oscar_callback, tstconn); |
509 aim_auth_sendcookie(sess, tstconn, cookie); | 523 aim_auth_sendcookie(sess, tstconn, cookie); |
510 } | 524 } |
511 } | 525 } |
517 debug_print("unable to connect to chatnav server\n"); | 531 debug_print("unable to connect to chatnav server\n"); |
518 return 1; | 532 return 1; |
519 } | 533 } |
520 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); | 534 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); |
521 aim_auth_sendcookie(sess, tstconn, cookie); | 535 aim_auth_sendcookie(sess, tstconn, cookie); |
522 gc->cnpa = gdk_input_add(tstconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, | 536 odata->cnpa = gdk_input_add(tstconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, |
523 oscar_callback, tstconn); | 537 oscar_callback, tstconn); |
524 } | 538 } |
525 debug_print("chatnav: connected\n"); | 539 debug_print("chatnav: connected\n"); |
526 break; | 540 break; |
527 case 0xe: /* Chat */ | 541 case 0xe: /* Chat */ |
543 | 557 |
544 ccon->inpa = gdk_input_add(tstconn->fd, | 558 ccon->inpa = gdk_input_add(tstconn->fd, |
545 GDK_INPUT_READ | GDK_INPUT_EXCEPTION, | 559 GDK_INPUT_READ | GDK_INPUT_EXCEPTION, |
546 oscar_callback, tstconn); | 560 oscar_callback, tstconn); |
547 | 561 |
548 gc->oscar_chats = g_slist_append(gc->oscar_chats, ccon); | 562 odata->oscar_chats = g_slist_append(odata->oscar_chats, ccon); |
549 | 563 |
550 aim_chat_attachname(tstconn, roomname); | 564 aim_chat_attachname(tstconn, roomname); |
551 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); | 565 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); |
552 aim_auth_sendcookie(sess, tstconn, cookie); | 566 aim_auth_sendcookie(sess, tstconn, cookie); |
553 } | 567 } |
615 static void accept_directim(GtkWidget *w, GtkWidget *m) | 629 static void accept_directim(GtkWidget *w, GtkWidget *m) |
616 { | 630 { |
617 struct aim_conn_t *newconn; | 631 struct aim_conn_t *newconn; |
618 struct aim_directim_priv *priv; | 632 struct aim_directim_priv *priv; |
619 struct gaim_connection *gc; | 633 struct gaim_connection *gc; |
634 struct oscar_data *odata; | |
620 int watcher; | 635 int watcher; |
621 | 636 |
622 priv = (struct aim_directim_priv *)gtk_object_get_user_data(GTK_OBJECT(m)); | 637 priv = (struct aim_directim_priv *)gtk_object_get_user_data(GTK_OBJECT(m)); |
623 gc = (struct gaim_connection *)gtk_object_get_user_data(GTK_OBJECT(w)); | 638 gc = (struct gaim_connection *)gtk_object_get_user_data(GTK_OBJECT(w)); |
639 odata = (struct oscar_data *)gc->proto_data; | |
624 gtk_widget_destroy(m); | 640 gtk_widget_destroy(m); |
625 | 641 |
626 if (!(newconn = aim_directim_connect(gc->oscar_sess, gc->oscar_conn, priv))) { | 642 if (!(newconn = aim_directim_connect(odata->sess, odata->conn, priv))) { |
627 debug_print("imimage: could not connect\n"); | 643 debug_print("imimage: could not connect\n"); |
628 return; | 644 return; |
629 } | 645 } |
630 | 646 |
631 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0); | 647 aim_conn_addhandler(odata->sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0); |
632 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, gaim_directim_typing, 0); | 648 aim_conn_addhandler(odata->sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, gaim_directim_typing, 0); |
633 | 649 |
634 watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, | 650 watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, |
635 oscar_callback, newconn); | 651 oscar_callback, newconn); |
636 | 652 |
637 sprintf(debug_buff, "DirectIM: connected to %s\n", priv->sn); | 653 sprintf(debug_buff, "DirectIM: connected to %s\n", priv->sn); |
912 int gaim_chatnav_info(struct aim_session_t *sess, | 928 int gaim_chatnav_info(struct aim_session_t *sess, |
913 struct command_rx_struct *command, ...) { | 929 struct command_rx_struct *command, ...) { |
914 va_list ap; | 930 va_list ap; |
915 u_short type; | 931 u_short type; |
916 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess); | 932 struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess); |
933 struct oscar_data *odata = (struct oscar_data *)gc->proto_data; | |
917 | 934 |
918 va_start(ap, command); | 935 va_start(ap, command); |
919 type = (u_short)va_arg(ap, u_int); | 936 type = (u_short)va_arg(ap, u_int); |
920 | 937 |
921 switch(type) { | 938 switch(type) { |
941 exchanges[i].charset1, | 958 exchanges[i].charset1, |
942 exchanges[i].lang1); | 959 exchanges[i].lang1); |
943 debug_print(debug_buff); | 960 debug_print(debug_buff); |
944 i++; | 961 i++; |
945 } | 962 } |
946 if (gc->create_exchange) { | 963 if (odata->create_exchange) { |
947 sprintf(debug_buff, "creating room %s\n", | 964 sprintf(debug_buff, "creating room %s\n", odata->create_name); |
948 gc->create_name); | |
949 debug_print(debug_buff); | 965 debug_print(debug_buff); |
950 aim_chatnav_createroom(sess, command->conn, gc->create_name, gc->create_exchange); | 966 aim_chatnav_createroom(sess, command->conn, odata->create_name, |
951 gc->create_exchange = 0; | 967 odata->create_exchange); |
952 g_free(gc->create_name); | 968 odata->create_exchange = 0; |
953 gc->create_name = NULL; | 969 g_free(odata->create_name); |
970 odata->create_name = NULL; | |
954 } | 971 } |
955 } | 972 } |
956 break; | 973 break; |
957 case 0x0008: { | 974 case 0x0008: { |
958 char *fqcn, *name, *ck; | 975 char *fqcn, *name, *ck; |
975 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); | 992 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 debug_print(debug_buff); | 993 debug_print(debug_buff); |
977 if (flags & 0x4) { | 994 if (flags & 0x4) { |
978 sprintf(debug_buff, "joining %s on exchange 5\n", name); | 995 sprintf(debug_buff, "joining %s on exchange 5\n", name); |
979 debug_print(debug_buff); | 996 debug_print(debug_buff); |
980 aim_chat_join(gc->oscar_sess, gc->oscar_conn, 5, ck); | 997 aim_chat_join(odata->sess, odata->conn, 5, ck); |
981 } else | 998 } else |
982 sprintf(debug_buff, "joining %s on exchange 4\n", name);{ | 999 sprintf(debug_buff, "joining %s on exchange 4\n", name);{ |
983 debug_print(debug_buff); | 1000 debug_print(debug_buff); |
984 aim_chat_join(gc->oscar_sess, gc->oscar_conn, 4, ck); | 1001 aim_chat_join(odata->sess, odata->conn, 4, ck); |
985 } | 1002 } |
986 } | 1003 } |
987 break; | 1004 break; |
988 default: | 1005 default: |
989 va_end(ap); | 1006 va_end(ap); |
1300 | 1317 |
1301 return 1; | 1318 return 1; |
1302 } | 1319 } |
1303 | 1320 |
1304 void oscar_do_directim(struct gaim_connection *gc, char *name) { | 1321 void oscar_do_directim(struct gaim_connection *gc, char *name) { |
1305 struct aim_conn_t *newconn = aim_directim_initiate(gc->oscar_sess, gc->oscar_conn, NULL, name); | 1322 struct oscar_data *odata = (struct oscar_data *)gc->proto_data; |
1306 struct conversation *cnv = find_conversation(name); /* this will never be null because it just got set up */ | 1323 struct aim_conn_t *newconn = aim_directim_initiate(odata->sess, odata->conn, NULL, name); |
1324 struct conversation *cnv = find_conversation(name); /* this will never be null because | |
1325 it just got set up */ | |
1307 cnv->conn = newconn; | 1326 cnv->conn = newconn; |
1308 cnv->watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, newconn); | 1327 cnv->watcher = gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, newconn); |
1309 aim_conn_addhandler(gc->oscar_sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, gaim_directim_initiate, 0); | 1328 aim_conn_addhandler(odata->sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, gaim_directim_initiate, 0); |
1310 } | 1329 } |
1311 | 1330 |
1312 static void oscar_keepalive(struct gaim_connection *gc) { | 1331 static void oscar_keepalive(struct gaim_connection *gc) { |
1313 aim_flap_nop(gc->oscar_sess, gc->oscar_conn); | 1332 struct oscar_data *odata = (struct oscar_data *)gc->proto_data; |
1333 aim_flap_nop(odata->sess, odata->conn); | |
1314 } | 1334 } |
1315 | 1335 |
1316 static char *oscar_name() { | 1336 static char *oscar_name() { |
1317 return "Oscar"; | 1337 return "Oscar"; |
1318 } | 1338 } |
1319 | 1339 |
1320 static void oscar_send_im(struct gaim_connection *gc, char *name, char *message, int away) { | 1340 static void oscar_send_im(struct gaim_connection *gc, char *name, char *message, int away) { |
1341 struct oscar_data *odata = (struct oscar_data *)gc->proto_data; | |
1321 struct conversation *cnv = find_conversation(name); | 1342 struct conversation *cnv = find_conversation(name); |
1322 if (cnv && cnv->is_direct) { | 1343 if (cnv && cnv->is_direct) { |
1323 debug_printf("Sending DirectIM to %s\n", name); | 1344 debug_printf("Sending DirectIM to %s\n", name); |
1324 aim_send_im_direct(gc->oscar_sess, cnv->conn, message); | 1345 aim_send_im_direct(odata->sess, cnv->conn, message); |
1325 } else { | 1346 } else { |
1326 if (away) | 1347 if (away) |
1327 aim_send_im(gc->oscar_sess, gc->oscar_conn, name, AIM_IMFLAGS_AWAY, message); | 1348 aim_send_im(odata->sess, odata->conn, name, AIM_IMFLAGS_AWAY, message); |
1328 else | 1349 else |
1329 aim_send_im(gc->oscar_sess, gc->oscar_conn, name, AIM_IMFLAGS_ACK, message); | 1350 aim_send_im(odata->sess, odata->conn, name, AIM_IMFLAGS_ACK, message); |
1330 } | 1351 } |
1331 } | 1352 } |
1332 | 1353 |
1333 static void oscar_get_info(struct gaim_connection *g, char *name) { | 1354 static void oscar_get_info(struct gaim_connection *g, char *name) { |
1334 aim_getinfo(g->oscar_sess, g->oscar_conn, name, AIM_GETINFO_GENERALINFO); | 1355 struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
1356 aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_GENERALINFO); | |
1335 } | 1357 } |
1336 | 1358 |
1337 static void oscar_get_away_msg(struct gaim_connection *g, char *name) { | 1359 static void oscar_get_away_msg(struct gaim_connection *g, char *name) { |
1338 aim_getinfo(g->oscar_sess, g->oscar_conn, name, AIM_GETINFO_AWAYMESSAGE); | 1360 struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
1361 aim_getinfo(odata->sess, odata->conn, name, AIM_GETINFO_AWAYMESSAGE); | |
1339 } | 1362 } |
1340 | 1363 |
1341 static void oscar_set_dir(struct gaim_connection *g, char *first, char *middle, char *last, | 1364 static void oscar_set_dir(struct gaim_connection *g, char *first, char *middle, char *last, |
1342 char *maiden, char *city, char *state, char *country, int web) { | 1365 char *maiden, char *city, char *state, char *country, int web) { |
1343 /* FIXME : some of these things are wrong, but i'm lazy */ | 1366 /* FIXME : some of these things are wrong, but i'm lazy */ |
1344 aim_setdirectoryinfo(g->oscar_sess, g->oscar_conn, first, middle, last, | 1367 struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
1368 aim_setdirectoryinfo(odata->sess, odata->conn, first, middle, last, | |
1345 maiden, NULL, NULL, city, state, NULL, 0, web); | 1369 maiden, NULL, NULL, city, state, NULL, 0, web); |
1346 } | 1370 } |
1347 | 1371 |
1348 | 1372 |
1349 static void oscar_set_idle(struct gaim_connection *g, int time) { | 1373 static void oscar_set_idle(struct gaim_connection *g, int time) { |
1350 aim_bos_setidle(g->oscar_sess, g->oscar_conn, time); | 1374 struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
1375 aim_bos_setidle(odata->sess, odata->conn, time); | |
1351 } | 1376 } |
1352 | 1377 |
1353 static void oscar_set_info(struct gaim_connection *g, char *info) { | 1378 static void oscar_set_info(struct gaim_connection *g, char *info) { |
1379 struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
1354 if (awaymessage) | 1380 if (awaymessage) |
1355 aim_bos_setprofile(g->oscar_sess, g->oscar_conn, info, | 1381 aim_bos_setprofile(odata->sess, odata->conn, info, |
1356 awaymessage->message, gaim_caps); | 1382 awaymessage->message, gaim_caps); |
1357 else | 1383 else |
1358 aim_bos_setprofile(g->oscar_sess, g->oscar_conn, info, | 1384 aim_bos_setprofile(odata->sess, odata->conn, info, |
1359 NULL, gaim_caps); | 1385 NULL, gaim_caps); |
1360 } | 1386 } |
1361 | 1387 |
1362 static void oscar_set_away(struct gaim_connection *g, char *message) { | 1388 static void oscar_set_away(struct gaim_connection *g, char *message) { |
1363 aim_bos_setprofile(g->oscar_sess, g->oscar_conn, g->user_info, message, gaim_caps); | 1389 struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
1390 aim_bos_setprofile(odata->sess, odata->conn, g->user_info, message, gaim_caps); | |
1364 } | 1391 } |
1365 | 1392 |
1366 static void oscar_warn(struct gaim_connection *g, char *name, int anon) { | 1393 static void oscar_warn(struct gaim_connection *g, char *name, int anon) { |
1367 aim_send_warning(g->oscar_sess, g->oscar_conn, name, anon); | 1394 struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
1395 aim_send_warning(odata->sess, odata->conn, name, anon); | |
1368 } | 1396 } |
1369 | 1397 |
1370 static void oscar_dir_search(struct gaim_connection *g, char *first, char *middle, char *last, | 1398 static void oscar_dir_search(struct gaim_connection *g, char *first, char *middle, char *last, |
1371 char *maiden, char *city, char *state, char *country, char *email) { | 1399 char *maiden, char *city, char *state, char *country, char *email) { |
1400 struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
1372 if (strlen(email)) | 1401 if (strlen(email)) |
1373 aim_usersearch_address(g->oscar_sess, g->oscar_conn, email); | 1402 aim_usersearch_address(odata->sess, odata->conn, email); |
1374 } | 1403 } |
1375 | 1404 |
1376 static void oscar_add_buddy(struct gaim_connection *g, char *name) { | 1405 static void oscar_add_buddy(struct gaim_connection *g, char *name) { |
1377 aim_add_buddy(g->oscar_sess, g->oscar_conn, name); | 1406 struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
1407 aim_add_buddy(odata->sess, odata->conn, name); | |
1378 } | 1408 } |
1379 | 1409 |
1380 static void oscar_add_buddies(struct gaim_connection *g, GList *buddies) { | 1410 static void oscar_add_buddies(struct gaim_connection *g, GList *buddies) { |
1411 struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
1381 char buf[MSG_LEN]; | 1412 char buf[MSG_LEN]; |
1382 int n = 0; | 1413 int n = 0; |
1383 while (buddies) { | 1414 while (buddies) { |
1384 if (n > MSG_LEN - 18) { | 1415 if (n > MSG_LEN - 18) { |
1385 aim_bos_setbuddylist(g->oscar_sess, g->oscar_conn, buf); | 1416 aim_bos_setbuddylist(odata->sess, odata->conn, buf); |
1386 n = 0; | 1417 n = 0; |
1387 } | 1418 } |
1388 n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (char *)buddies->data); | 1419 n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (char *)buddies->data); |
1389 buddies = buddies->next; | 1420 buddies = buddies->next; |
1390 } | 1421 } |
1391 aim_bos_setbuddylist(g->oscar_sess, g->oscar_conn, buf); | 1422 aim_bos_setbuddylist(odata->sess, odata->conn, buf); |
1392 } | 1423 } |
1393 | 1424 |
1394 static void oscar_remove_buddy(struct gaim_connection *g, char *name) { | 1425 static void oscar_remove_buddy(struct gaim_connection *g, char *name) { |
1395 aim_remove_buddy(g->oscar_sess, g->oscar_conn, name); | 1426 struct oscar_data *odata = (struct oscar_data *)g->proto_data; |
1427 aim_remove_buddy(odata->sess, odata->conn, name); | |
1396 } | 1428 } |
1397 | 1429 |
1398 static void oscar_join_chat(struct gaim_connection *g, int exchange, char *name) { | 1430 static void oscar_join_chat(struct gaim_connection *g, int exchange, char *name) { |
1431 struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
1399 struct aim_conn_t *cur = NULL; | 1432 struct aim_conn_t *cur = NULL; |
1400 sprintf(debug_buff, "Attempting to join chat room %s.\n", name); | 1433 sprintf(debug_buff, "Attempting to join chat room %s.\n", name); |
1401 debug_print(debug_buff); | 1434 debug_print(debug_buff); |
1402 if ((cur = aim_getconn_type(g->oscar_sess, AIM_CONN_TYPE_CHATNAV))) { | 1435 if ((cur = aim_getconn_type(odata->sess, AIM_CONN_TYPE_CHATNAV))) { |
1403 debug_print("chatnav exists, creating room\n"); | 1436 debug_print("chatnav exists, creating room\n"); |
1404 aim_chatnav_createroom(g->oscar_sess, cur, name, exchange); | 1437 aim_chatnav_createroom(odata->sess, cur, name, exchange); |
1405 } else { | 1438 } else { |
1406 /* this gets tricky */ | 1439 /* this gets tricky */ |
1407 debug_print("chatnav does not exist, opening chatnav\n"); | 1440 debug_print("chatnav does not exist, opening chatnav\n"); |
1408 g->create_exchange = exchange; | 1441 odata->create_exchange = exchange; |
1409 g->create_name = g_strdup(name); | 1442 odata->create_name = g_strdup(name); |
1410 aim_bos_reqservice(g->oscar_sess, g->oscar_conn, AIM_CONN_TYPE_CHATNAV); | 1443 aim_bos_reqservice(odata->sess, odata->conn, AIM_CONN_TYPE_CHATNAV); |
1411 } | 1444 } |
1412 } | 1445 } |
1413 | 1446 |
1414 static void oscar_chat_invite(struct gaim_connection *g, int id, char *message, char *name) { | 1447 static void oscar_chat_invite(struct gaim_connection *g, int id, char *message, char *name) { |
1448 struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
1415 GSList *bcs = g->buddy_chats; | 1449 GSList *bcs = g->buddy_chats; |
1416 struct conversation *b = NULL; | 1450 struct conversation *b = NULL; |
1417 | 1451 |
1418 while (bcs) { | 1452 while (bcs) { |
1419 b = (struct conversation *)bcs->data; | 1453 b = (struct conversation *)bcs->data; |
1424 } | 1458 } |
1425 | 1459 |
1426 if (!b) | 1460 if (!b) |
1427 return; | 1461 return; |
1428 | 1462 |
1429 aim_chat_invite(g->oscar_sess, g->oscar_conn, name, | 1463 aim_chat_invite(odata->sess, odata->conn, name, |
1430 message ? message : "", 0x4, b->name, 0x0); | 1464 message ? message : "", 0x4, b->name, 0x0); |
1431 } | 1465 } |
1432 | 1466 |
1433 static void oscar_chat_leave(struct gaim_connection *g, int id) { | 1467 static void oscar_chat_leave(struct gaim_connection *g, int id) { |
1468 struct oscar_data *odata = g ? (struct oscar_data *)g->proto_data : NULL; | |
1434 GSList *bcs = g->buddy_chats; | 1469 GSList *bcs = g->buddy_chats; |
1435 struct conversation *b = NULL; | 1470 struct conversation *b = NULL; |
1436 struct chat_connection *c = NULL; | 1471 struct chat_connection *c = NULL; |
1437 int count = 0; | 1472 int count = 0; |
1438 | 1473 |
1452 b->name, count); | 1487 b->name, count); |
1453 debug_print(debug_buff); | 1488 debug_print(debug_buff); |
1454 | 1489 |
1455 c = find_oscar_chat(g, b->name); | 1490 c = find_oscar_chat(g, b->name); |
1456 if (c != NULL) { | 1491 if (c != NULL) { |
1457 g->oscar_chats = g_slist_remove(g->oscar_chats, c); | 1492 if (odata) |
1493 odata->oscar_chats = g_slist_remove(odata->oscar_chats, c); | |
1458 gdk_input_remove(c->inpa); | 1494 gdk_input_remove(c->inpa); |
1459 if (g && g->oscar_sess) | 1495 if (g && odata->sess) |
1460 aim_conn_kill(g->oscar_sess, &c->conn); | 1496 aim_conn_kill(odata->sess, &c->conn); |
1461 g_free(c->name); | 1497 g_free(c->name); |
1462 g_free(c); | 1498 g_free(c); |
1463 } | 1499 } |
1464 /* we do this because with Oscar it doesn't tell us we left */ | 1500 /* we do this because with Oscar it doesn't tell us we left */ |
1465 serv_got_chat_left(g, b->id); | 1501 serv_got_chat_left(g, b->id); |
1469 do_error_dialog("Sorry, Oscar doesn't whisper. Send an IM. (The last message was not received.)", | 1505 do_error_dialog("Sorry, Oscar doesn't whisper. Send an IM. (The last message was not received.)", |
1470 "Gaim - Chat"); | 1506 "Gaim - Chat"); |
1471 } | 1507 } |
1472 | 1508 |
1473 static void oscar_chat_send(struct gaim_connection *g, int id, char *message) { | 1509 static void oscar_chat_send(struct gaim_connection *g, int id, char *message) { |
1510 struct oscar_data *odata = (struct oscar_data *)g->proto_data; | |
1474 struct aim_conn_t *cn; | 1511 struct aim_conn_t *cn; |
1475 GSList *bcs = g->buddy_chats; | 1512 GSList *bcs = g->buddy_chats; |
1476 struct conversation *b = NULL; | 1513 struct conversation *b = NULL; |
1477 | 1514 |
1478 while (bcs) { | 1515 while (bcs) { |
1483 b = NULL; | 1520 b = NULL; |
1484 } | 1521 } |
1485 if (!b) | 1522 if (!b) |
1486 return; | 1523 return; |
1487 | 1524 |
1488 cn = aim_chat_getconn(g->oscar_sess, b->name); | 1525 cn = aim_chat_getconn(odata->sess, b->name); |
1489 aim_chat_send_im(g->oscar_sess, cn, message); | 1526 aim_chat_send_im(odata->sess, cn, message); |
1490 } | 1527 } |
1491 | 1528 |
1492 struct prpl *oscar_init() { | 1529 struct prpl *oscar_init() { |
1493 struct prpl *ret = g_new0(struct prpl, 1); | 1530 struct prpl *ret = g_new0(struct prpl, 1); |
1494 | 1531 |