Mercurial > pidgin.yaz
changeset 8982:a4fd6666bb83
[gaim-migrate @ 9757]
Some Direct IM fixes.
1. Let's send our correct ip. We were usually sending localhost, so the
other side would try to connect to localhost and immediately fail and so
say, hey! I can't connect to you! Connect to me instead!
2. Add some gaim_conversation_writes to keep the user more informed as
to what's going on.
This changes the libfaim API. libfaim users take note.
I removed the util get local ip function, and made the function
that used to use it take an ip as an argument instead, so that oscar.c
could just call gaim's function, which works better.
I also made it possible to specify a cookie to use, because I think I'll
need that later. Probably.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Thu, 20 May 2004 00:14:14 +0000 |
parents | e40f9afd420e |
children | 460d02fe03df |
files | src/protocols/oscar/aim.h src/protocols/oscar/ft.c src/protocols/oscar/im.c src/protocols/oscar/oscar.c src/protocols/oscar/util.c |
diffstat | 5 files changed, 44 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/src/protocols/oscar/aim.h Thu May 20 00:07:15 2004 +0000 +++ b/src/protocols/oscar/aim.h Thu May 20 00:14:14 2004 +0000 @@ -411,7 +411,7 @@ * Its really bad and the API/event model is quirky at best. * */ - aim_frame_t *queue_outgoing; + aim_frame_t *queue_outgoing; aim_frame_t *queue_incoming; /* @@ -865,7 +865,7 @@ /* 0x0006 */ faim_export int aim_im_sendch2_chatinvite(aim_session_t *sess, const char *sn, const char *msg, fu16_t exchange, const char *roomname, fu16_t instance); /* 0x0006 */ faim_export int aim_im_sendch2_icon(aim_session_t *sess, const char *sn, const fu8_t *icon, int iconlen, time_t stamp, fu16_t iconsum); /* 0x0006 */ faim_export int aim_im_sendch2_rtfmsg(aim_session_t *sess, struct aim_sendrtfmsg_args *args); -/* 0x0006 */ faim_export int aim_im_sendch2_odcrequest(aim_session_t *sess, fu8_t *cookie, const char *sn, const fu8_t *ip, fu16_t port); +/* 0x0006 */ faim_export int aim_im_sendch2_odcrequest(aim_session_t *sess, fu8_t *cookie, bool usecookie, const char *sn, const fu8_t *ip, fu16_t port); /* 0x0006 */ faim_export int aim_im_sendch2_sendfile_ask(aim_session_t *sess, struct aim_oft_info *oft_info); /* 0x0006 */ faim_export int aim_im_sendch2_sendfile_accept(aim_session_t *sess, struct aim_oft_info *info); /* 0x0006 */ faim_export int aim_im_sendch2_sendfile_cancel(aim_session_t *sess, struct aim_oft_info *oft_info); @@ -933,7 +933,8 @@ faim_export int aim_odc_send_im(aim_session_t *sess, aim_conn_t *conn, const char *msg, int len, int encoding, int isawaymsg); faim_export const char *aim_odc_getsn(aim_conn_t *conn); faim_export aim_conn_t *aim_odc_getconn(aim_session_t *sess, const char *sn); -faim_export aim_conn_t *aim_odc_initiate(aim_session_t *sess, const char *sn, int listenfd, fu16_t port); +faim_export aim_conn_t *aim_odc_initiate(aim_session_t *sess, const char *sn, int listenfd, + const fu8_t *localip, fu16_t port, const fu8_t *mycookie); faim_export aim_conn_t *aim_odc_connect(aim_session_t *sess, const char *sn, const char *addr, const fu8_t *cookie); faim_export struct aim_oft_info *aim_oft_createinfo(aim_session_t *sess, const fu8_t *cookie, const char *sn, const char *ip, fu16_t port, fu32_t size, fu32_t modtime, char *filename); @@ -1470,7 +1471,6 @@ faim_export int aimutil_putstr(char *, const char *, int); faim_export fu16_t aimutil_iconsum(const fu8_t *buf, int buflen); -faim_export int aim_util_getlocalip(fu8_t *ip); faim_export int aimutil_tokslen(char *toSearch, int theindex, char dl); faim_export int aimutil_itemcnt(char *toSearch, char dl); faim_export char *aimutil_itemindex(char *toSearch, int theindex, char dl);
--- a/src/protocols/oscar/ft.c Thu May 20 00:07:15 2004 +0000 +++ b/src/protocols/oscar/ft.c Thu May 20 00:14:14 2004 +0000 @@ -440,27 +440,31 @@ /** * For those times when we want to open up the direct connection channel ourselves. * - * You'll want to set up some kind of watcher on this socket. - * When the state changes, call aim_handlerendconnection with - * the connection returned by this. aim_handlerendconnection + * You'll want to set up some kind of watcher on this socket. + * When the state changes, call aim_handlerendconnection with + * the connection returned by this. aim_handlerendconnection * will accept the pending connection and stop listening. * * @param sess The session * @param sn The screen name to connect to. * @return The new connection. */ -faim_export aim_conn_t *aim_odc_initiate(aim_session_t *sess, const char *sn, int listenfd, fu16_t port) +faim_export aim_conn_t *aim_odc_initiate(aim_session_t *sess, const char *sn, int listenfd, + const fu8_t *localip, fu16_t port, const fu8_t *mycookie) { aim_conn_t *newconn; aim_msgcookie_t *cookie; struct aim_odc_intdata *priv; - fu8_t localip[4]; fu8_t ck[8]; - if (aim_util_getlocalip(localip) == -1) + if (!localip) return NULL; - aim_im_sendch2_odcrequest(sess, ck, sn, localip, port); + if (mycookie) { + memcpy(ck, mycookie, 8); + aim_im_sendch2_odcrequest(sess, ck, TRUE, sn, localip, port); + } else + aim_im_sendch2_odcrequest(sess, ck, FALSE, sn, localip, port); cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)); memcpy(cookie->cookie, ck, 8);
--- a/src/protocols/oscar/im.c Thu May 20 00:07:15 2004 +0000 +++ b/src/protocols/oscar/im.c Thu May 20 00:14:14 2004 +0000 @@ -680,7 +680,7 @@ * Subtype 0x0006 - Send an "I want to directly connect to you" message * */ -faim_export int aim_im_sendch2_odcrequest(aim_session_t *sess, fu8_t *cookie, const char *sn, const fu8_t *ip, fu16_t port) +faim_export int aim_im_sendch2_odcrequest(aim_session_t *sess, fu8_t *cookie, bool usecookie, const char *sn, const fu8_t *ip, fu16_t port) { aim_conn_t *conn; aim_frame_t *fr; @@ -709,11 +709,15 @@ * XXX - have I mentioned these should be generated in msgcookie.c? * */ - for (i = 0; i < 7; i++) - ck[i] = 0x30 + ((fu8_t) rand() % 10); + + if (cookie && usecookie) /* allow user-specified cookie */ + memcpy(ck, cookie, 8); + else + for (i = 0; i < 7; i++) + ck[i] = 0x30 + ((fu8_t) rand() % 10); ck[7] = '\0'; - if (cookie) + if (cookie && !usecookie) memcpy(cookie, ck, 8); /* ICBM header */
--- a/src/protocols/oscar/oscar.c Thu May 20 00:07:15 2004 +0000 +++ b/src/protocols/oscar/oscar.c Thu May 20 00:14:14 2004 +0000 @@ -819,6 +819,8 @@ struct oscar_direct_im *dim; char *host; int port = 5190; int i, rc; + char *tmp; + GaimConversation *conv; if (!g_list_find(gaim_connections_get_all(), gc)) { destroy_direct_im_request(d); @@ -864,6 +866,13 @@ dim->conn->status |= AIM_CONN_STATUS_INPROGRESS; dim->gpc_pend = TRUE; rc = gaim_proxy_connect(gc->account, host, port, oscar_odc_callback, dim); + + conv = gaim_conversation_new(GAIM_CONV_IM, dim->gc->account, d->sn); + tmp = g_strdup_printf(_("Attempting to connect to %s at %s:%hu for Direct IM."), d->sn, host, + port); + gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); + g_free(tmp); + g_free(host); if (rc < 0) { dim->gpc_pend = FALSE; @@ -1233,6 +1242,7 @@ OscarData *od; struct oscar_direct_im *dim; int listenfd; + const char *ip; if (!g_list_find(gaim_connections_get_all(), gc)) { g_free(data->who); @@ -1260,13 +1270,23 @@ g_snprintf(dim->name, sizeof dim->name, "%s", data->who); listenfd = gaim_network_listen_range(5190, 5199); - dim->conn = aim_odc_initiate(od->sess, data->who, listenfd, gaim_network_get_port_from_fd(listenfd)); + ip = gaim_network_get_my_ip(od->conn ? od->conn->fd : -1); + dim->conn = aim_odc_initiate(od->sess, data->who, listenfd, gaim_network_ip_atoi(ip), gaim_network_get_port_from_fd(listenfd), NULL); if (dim->conn != NULL) { + char *tmp; + GaimConversation *conv; + od->direct_ims = g_slist_append(od->direct_ims, dim); dim->watcher = gaim_input_add(dim->conn->fd, GAIM_INPUT_READ, oscar_callback, dim->conn); aim_conn_addhandler(od->sess, dim->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIM_ESTABLISHED, gaim_odc_initiate, 0); + + conv = gaim_conversation_new(GAIM_CONV_IM, dim->gc->account, data->who); + tmp = g_strdup_printf(_("Asking %s to connect to us at %s:%hu for Direct IM."), data->who, ip, + gaim_network_get_port_from_fd(listenfd)); + gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); + g_free(tmp); } else { gaim_notify_error(gc, NULL, _("Unable to open Direct IM"), NULL); oscar_direct_im_destroy(od, dim);
--- a/src/protocols/oscar/util.c Thu May 20 00:07:15 2004 +0000 +++ b/src/protocols/oscar/util.c Thu May 20 00:14:14 2004 +0000 @@ -139,24 +139,6 @@ return sum; } -faim_export int aim_util_getlocalip(fu8_t *ip) -{ - struct hostent *hptr; - char localhost[129]; - - /* XXX if available, use getaddrinfo() */ - /* XXX allow client to specify which IP to use for multihomed boxes */ - - if (gethostname(localhost, 128) < 0) - return -1; - - if (!(hptr = gethostbyname(localhost))) - return -1; - memcpy(ip, hptr->h_addr_list[0], 4); - - return 0; -} - /** * Check if the given screen name is a valid AIM screen name. * Example: BobDole