# HG changeset patch # User Eric Warmenhoven # Date 964118065 0 # Node ID 3133ab511d92d7574126d3b17c45b45b218384d2 # Parent dab0c611029e0e91f7ddb1ea14b17ff836c5a553 [gaim-migrate @ 521] beginnings of directim, some improvements to oscar chat stuff committer: Tailor Script diff -r dab0c611029e -r 3133ab511d92 libfaim/faim/aim.h --- a/libfaim/faim/aim.h Thu Jul 20 16:45:21 2000 +0000 +++ b/libfaim/faim/aim.h Thu Jul 20 18:34:25 2000 +0000 @@ -526,7 +526,7 @@ int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *); int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command); -struct aim_conn_t * aim_directim_intiate(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *, char *); +struct aim_conn_t * aim_directim_initiate(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *, char *); int aim_send_im_direct(struct aim_session_t *, struct aim_conn_t *, char *); struct aim_conn_t *aim_directim_connect(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *); diff -r dab0c611029e -r 3133ab511d92 src/buddy.c --- a/src/buddy.c Thu Jul 20 16:45:21 2000 +0000 +++ b/src/buddy.c Thu Jul 20 18:34:25 2000 +0000 @@ -476,6 +476,14 @@ GTK_SIGNAL_FUNC(pressed_away_msg), b); gtk_menu_append(GTK_MENU(menu), button); gtk_widget_show(button); + +#if 0 + button = gtk_menu_item_new_with_label(_("Direct IM")); + gtk_signal_connect(GTK_OBJECT(button), "activate", + GTK_SIGNAL_FUNC(serv_do_imimage), b->name); + gtk_menu_append(GTK_MENU(menu), button); + gtk_widget_show(button); +#endif } button = gtk_menu_item_new_with_label(_("Toggle Logging")); diff -r dab0c611029e -r 3133ab511d92 src/conversation.c --- a/src/conversation.c Thu Jul 20 16:45:21 2000 +0000 +++ b/src/conversation.c Thu Jul 20 18:34:25 2000 +0000 @@ -299,10 +299,18 @@ gtk_widget_destroy(c->window); c->window = NULL; - if (c->is_chat) + if (c->is_chat) { serv_chat_leave(c->id); - else + } else { + if (c->is_direct) { + if (!USE_OSCAR) { + /* FIXME */ + } else { + aim_conn_kill(c->conn); + } + } delete_conversation(c); + } return TRUE; } diff -r dab0c611029e -r 3133ab511d92 src/gaim.h --- a/src/gaim.h Thu Jul 20 16:45:21 2000 +0000 +++ b/src/gaim.h Thu Jul 20 18:34:25 2000 +0000 @@ -273,6 +273,10 @@ /* something to distinguish */ gboolean is_chat; + + /* DirectIM stuff */ + gboolean is_direct; + struct aim_conn_t *conn; /* needed for Oscar */ }; struct file_header { @@ -375,7 +379,7 @@ #define TYPE_SIGNOFF 4 #define TYPE_KEEPALIVE 5 -#define REVISION "gaim:$Revision: 482 $" +#define REVISION "gaim:$Revision: 521 $" #define FLAPON "FLAPON\r\n\r\n" #define ROAST "Tic/Toc" @@ -574,6 +578,7 @@ extern void serv_chat_leave(int); extern void serv_chat_whisper(int, char *, char *); extern void serv_chat_send(int, char *); +extern void serv_do_imimage(GtkWidget *, char *); /* output from serv */ extern void serv_got_update(char *, int, int, time_t, time_t, int); @@ -623,6 +628,7 @@ extern int oscar_login(char *, char *); extern void oscar_close(); extern struct chat_connection *find_oscar_chat(char *name); +extern void oscar_do_directim(char *); /* Functions in toc.c */ extern void toc_close(); diff -r dab0c611029e -r 3133ab511d92 src/oscar.c --- a/src/oscar.c Thu Jul 20 16:45:21 2000 +0000 +++ b/src/oscar.c Thu Jul 20 18:34:25 2000 +0000 @@ -43,6 +43,7 @@ static int inpa = -1; static int paspa = -1; +static int cnpa = -1; struct aim_session_t *gaim_sess; struct aim_conn_t *gaim_conn; int gaim_caps = AIM_CAPS_CHAT | AIM_CAPS_SENDFILE | AIM_CAPS_GETFILE | @@ -69,7 +70,6 @@ static int gaim_parse_auth_resp (struct aim_session_t *, struct command_rx_struct *, ...); static int gaim_auth_server_ready(struct aim_session_t *, struct command_rx_struct *, ...); static int gaim_server_ready (struct aim_session_t *, struct command_rx_struct *, ...); -static int gaim_chat_server_ready(struct aim_session_t *, struct command_rx_struct *, ...); static int gaim_handle_redirect (struct aim_session_t *, struct command_rx_struct *, ...); static int gaim_parse_oncoming (struct aim_session_t *, struct command_rx_struct *, ...); static int gaim_parse_offgoing (struct aim_session_t *, struct command_rx_struct *, ...); @@ -85,6 +85,9 @@ static int gaim_parse_msgack (struct aim_session_t *, struct command_rx_struct *, ...); static int gaim_parse_ratechange (struct aim_session_t *, struct command_rx_struct *, ...); +static int gaim_directim_incoming (struct aim_session_t *, struct command_rx_struct *, ...); +static int gaim_directim_typing (struct aim_session_t *, struct command_rx_struct *, ...); + extern void auth_failed(); static void oscar_callback(gpointer data, gint source, @@ -326,6 +329,7 @@ int gaim_server_ready(struct aim_session_t *sess, struct command_rx_struct *command, ...) { + static int id = 1; switch (command->conn->type) { case AIM_CONN_TYPE_BOS: aim_bos_reqrate(sess, command->conn); @@ -343,6 +347,20 @@ aim_chatnav_clientready(sess, command->conn); aim_chatnav_reqrights(sess, command->conn); break; + case AIM_CONN_TYPE_CHAT: + debug_print("chat: got server ready\n"); + aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, gaim_chat_join, 0); + aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, gaim_chat_leave, 0); + aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, gaim_chat_info_update, 0); + aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, gaim_chat_incoming_msg, 0); + aim_bos_reqrate(sess, command->conn); + aim_bos_ackrateresp(sess, command->conn); + aim_chat_clientready(sess, command->conn); + serv_got_joined_chat(id++, aim_chat_getname(command->conn)); + break; + case AIM_CONN_TYPE_RENDEZVOUS: + aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0); + break; default: /* huh? */ sprintf(debug_buff, "server ready: got unexpected connection type %04x\n", command->conn->type); debug_print(debug_buff); @@ -351,21 +369,6 @@ return 1; } -int gaim_chat_server_ready(struct aim_session_t *sess, - struct command_rx_struct *command, ...) { - static int id = 1; - debug_print("chat: got server ready\n"); - aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, gaim_chat_join, 0); - aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, gaim_chat_leave, 0); - aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, gaim_chat_info_update, 0); - aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, gaim_chat_incoming_msg, 0); - aim_bos_reqrate(sess, command->conn); - aim_bos_ackrateresp(sess, command->conn); - aim_chat_clientready(sess, command->conn); - serv_got_joined_chat(id++, aim_chat_getname(command->conn)); - return 1; -} - int gaim_handle_redirect(struct aim_session_t *sess, struct command_rx_struct *command, ...) { va_list ap; @@ -440,6 +443,8 @@ } aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); aim_auth_sendcookie(sess, tstconn, cookie); + cnpa = gdk_input_add(tstconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, + oscar_callback, tstconn); } debug_print("chatnav: connected\n"); break; @@ -467,7 +472,7 @@ oscar_chats = g_list_append(oscar_chats, ccon); aim_chat_attachname(tstconn, roomname); - aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_chat_server_ready, 0); + aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, gaim_server_ready, 0); aim_auth_sendcookie(sess, tstconn, cookie); } break; @@ -579,6 +584,32 @@ } else if (rendtype & AIM_CAPS_BUDDYICON) { /* bah */ } else if (rendtype & AIM_CAPS_IMIMAGE) { + /* DirectIM stuff */ + struct aim_directim_priv *priv; + struct aim_conn_t *newconn; + + userinfo = va_arg(ap, struct aim_userinfo_s *); + priv = va_arg(ap, struct aim_directim_priv *); + va_end(ap); + + sprintf(debug_buff, "DirectIM request from %s (%s)\n", userinfo->sn, priv->ip); + debug_print(debug_buff); + + if (!(newconn = aim_directim_connect(sess, command->conn, priv))) { + debug_print("imimage: could not connect\n"); + return 1; + } + + aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, gaim_directim_incoming, 0); + aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, gaim_directim_typing, 0); + + gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, + oscar_callback, newconn); + + sprintf(debug_buff, "DirectIM: connected to %s\n", userinfo->sn); + debug_print(debug_buff); + + serv_got_imimage(priv->sn, priv->cookie, priv->ip, newconn); } else { sprintf(debug_buff, "Unknown rendtype %d\n", rendtype); debug_print(debug_buff); @@ -715,6 +746,8 @@ i++; } } + gdk_input_remove(cnpa); + cnpa = -1; aim_conn_kill(sess, &command->conn); break; default: @@ -852,3 +885,42 @@ return 1; }; + +int gaim_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...) { + va_list ap; + char *sn = NULL, *msg = NULL; + struct aim_conn_t *conn; + + va_start(ap, command); + conn = va_arg(ap, struct aim_conn_t *); + sn = va_arg(ap, char *); + msg = va_arg(ap, char *); + va_end(ap); + + sprintf(debug_buff, "Got DirectIM message from %s\n", sn); + debug_print(debug_buff); + + serv_got_im(sn, msg, 0); + + return 1; +} + +int gaim_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...) { + va_list ap; + char *sn; + + ap = va_start(ap, command); + sn = va_arg(ap, char *); + va_end(ap); + + /* I had to leave this. It's just too funny. It reminds me of my sister. */ + sprintf(debug_buff, "ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", sn); + debug_print(debug_buff); + + return 1; +} + +void oscar_do_directim(char *name) { + struct aim_conn_t *newconn = aim_directim_initiate(gaim_sess, gaim_conn, NULL, name); + gdk_input_add(newconn->fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, oscar_callback, newconn); +} diff -r dab0c611029e -r 3133ab511d92 src/server.c --- a/src/server.c Thu Jul 20 16:45:21 2000 +0000 +++ b/src/server.c Thu Jul 20 18:34:25 2000 +0000 @@ -157,17 +157,28 @@ void serv_send_im(char *name, char *message, int away) { - if (!USE_OSCAR) { - char buf[MSG_LEN - 7]; + struct conversation *cnv = find_conversation(name); + if (!cnv || !cnv->is_direct) { + if (!USE_OSCAR) { + char buf[MSG_LEN - 7]; - g_snprintf(buf, MSG_LEN - 8, "toc_send_im %s \"%s\"%s", normalize(name), - message, ((away) ? " auto" : "")); - sflap_send(buf, strlen(buf), TYPE_DATA); + g_snprintf(buf, MSG_LEN - 8, "toc_send_im %s \"%s\"%s", normalize(name), + message, ((away) ? " auto" : "")); + sflap_send(buf, strlen(buf), TYPE_DATA); + } else { + if (away) + aim_send_im(gaim_sess, gaim_conn, name, AIM_IMFLAGS_AWAY, message); + else + aim_send_im(gaim_sess, gaim_conn, name, AIM_IMFLAGS_ACK, message); + } } else { - if (away) - aim_send_im(gaim_sess, gaim_conn, name, AIM_IMFLAGS_AWAY, message); - else - aim_send_im(gaim_sess, gaim_conn, name, AIM_IMFLAGS_ACK, message); + if (!USE_OSCAR) { + /* FIXME */ + } else { + sprintf(debug_buff, "Sending DirectIM to %s\n", name); + debug_print(debug_buff); + aim_send_im_direct(gaim_sess, cnv->conn, message); + } } if (!away) serv_touch_idle(); @@ -176,20 +187,20 @@ void serv_get_info(char *name) { if (!USE_OSCAR) { - char buf[MSG_LEN]; - g_snprintf(buf, MSG_LEN, "toc_get_info %s", normalize(name)); - sflap_send(buf, -1, TYPE_DATA); + char buf[MSG_LEN]; + g_snprintf(buf, MSG_LEN, "toc_get_info %s", normalize(name)); + sflap_send(buf, -1, TYPE_DATA); } else { - aim_getinfo(gaim_sess, gaim_conn, name, AIM_GETINFO_GENERALINFO); + aim_getinfo(gaim_sess, gaim_conn, name, AIM_GETINFO_GENERALINFO); } } void serv_get_away_msg(char *name) { if (!USE_OSCAR) { - /* HAHA! TOC doesn't have this yet */ + /* HAHA! TOC doesn't have this yet */ } else { - aim_getinfo(gaim_sess, gaim_conn, name, AIM_GETINFO_AWAYMESSAGE); + aim_getinfo(gaim_sess, gaim_conn, name, AIM_GETINFO_AWAYMESSAGE); } } @@ -1090,3 +1101,22 @@ cookie, uid); sflap_send(buf, strlen(buf), TYPE_DATA); } + +void serv_do_imimage(GtkWidget *w, char *name) { + if (!USE_OSCAR) { + } else { + oscar_do_directim(name); + } +} + +void serv_got_imimage(char *name, char *cookie, char *ip, struct aim_conn_t *conn) +{ + if (!USE_OSCAR) { + /* FIXME */ + } else { + struct conversation *cnv = find_conversation(name); + if (!cnv) cnv = new_conversation(name); + cnv->is_direct = 1; + cnv->conn = conn; + } +}