changeset 11162:ccb38cf22483

[gaim-migrate @ 13263] Get rid of the last of the errors in oscar. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 29 Jul 2005 01:14:23 +0000
parents 2e71eddc828b
children 4cf257598691
files src/protocols/oscar/aim.h src/protocols/oscar/conn.c src/protocols/oscar/ft.c src/protocols/oscar/oscar.c src/protocols/oscar/txqueue.c
diffstat 5 files changed, 29 insertions(+), 238 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/oscar/aim.h	Tue Jul 26 04:49:50 2005 +0000
+++ b/src/protocols/oscar/aim.h	Fri Jul 29 01:14:23 2005 +0000
@@ -577,7 +577,7 @@
 faim_export aim_conn_t *aim_conn_findbygroup(aim_session_t *sess, fu16_t group);
 faim_export aim_session_t *aim_conn_getsess(aim_conn_t *conn);
 faim_export void aim_conn_close(aim_conn_t *deadconn);
-faim_export aim_conn_t *aim_newconn(aim_session_t *, int type, const char *dest);
+faim_export aim_conn_t *aim_newconn(aim_session_t *, int type);
 faim_export int aim_conn_in_sess(aim_session_t *sess, aim_conn_t *conn);
 faim_export int aim_conn_isready(aim_conn_t *);
 faim_export int aim_conn_setstatus(aim_conn_t *, int);
--- a/src/protocols/oscar/conn.c	Tue Jul 26 04:49:50 2005 +0000
+++ b/src/protocols/oscar/conn.c	Fri Jul 29 01:14:23 2005 +0000
@@ -395,177 +395,6 @@
 }
 
 /**
- * Handle normal connections or SOCKS5 via an extrememly quick and
- * dirty SOCKS5 interface.
- *
- * Attempts to connect to the specified host via the configured
- * proxy settings, if present.  If no proxy is configured for
- * this session, the connection is done directly.
- *
- * XXX - this is really awful.
- * XXX - Split the SOCKS5 and the normal connection stuff into two
- *        separate functions.
- *
- * @param sess Session to connect.
- * @param host Host to connect to.
- * @param port Port to connect to.
- * @param statusret Return value of the connection.
- */
-static int aim_proxyconnect(aim_session_t *sess, const char *host, fu16_t port, fu32_t *statusret)
-{
-	int fd = -1;
-
-	if (strlen(sess->socksproxy.server)) { /* connecting via proxy */
-		int i;
-		unsigned char buf[512];
-		struct sockaddr_in sa;
-		struct hostent *hp;
-		char *proxy;
-		unsigned short proxyport = 1080;
-
-		for(i=0;i<(int)strlen(sess->socksproxy.server);i++) {
-			if (sess->socksproxy.server[i] == ':') {
-				proxyport = atoi(&(sess->socksproxy.server[i+1]));
-				break;
-			}
-		}
-
-		proxy = (char *)malloc(i+1);
-		strncpy(proxy, sess->socksproxy.server, i);
-		proxy[i] = '\0';
-
-		if (!(hp = gethostbyname(proxy))) {
-			faimdprintf(sess, 0, "proxyconnect: unable to resolve proxy name\n");
-			*statusret = (h_errno | AIM_CONN_STATUS_RESOLVERR);
-			return -1;
-		}
-		free(proxy);
-
-		memset(&sa.sin_zero, 0, 8);
-		sa.sin_port = htons(proxyport);
-		memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
-		sa.sin_family = hp->h_addrtype;
-
-		fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
-		if (connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
-			faimdprintf(sess, 0, "proxyconnect: unable to connect to proxy\n");
-			close(fd);
-			return -1;
-		}
-
-		i = 0;
-		buf[0] = 0x05; /* SOCKS version 5 */
-		if (strlen(sess->socksproxy.username)) {
-			buf[1] = 0x02; /* two methods */
-			buf[2] = 0x00; /* no authentication */
-			buf[3] = 0x02; /* username/password authentication */
-			i = 4;
-		} else {
-			buf[1] = 0x01;
-			buf[2] = 0x00;
-			i = 3;
-		}
-		if (write(fd, buf, i) < i) {
-			*statusret = errno;
-			close(fd);
-			return -1;
-		}
-		if (read(fd, buf, 2) < 2) {
-			*statusret = errno;
-			close(fd);
-			return -1;
-		}
-
-		if ((buf[0] != 0x05) || (buf[1] == 0xff)) {
-			*statusret = EINVAL;
-			close(fd);
-			return -1;
-		}
-
-		/* check if we're doing username authentication */
-		if (buf[1] == 0x02) {
-			i  = aimutil_put8(buf, 0x01); /* version 1 */
-			i += aimutil_put8(buf+i, strlen(sess->socksproxy.username));
-			i += aimutil_putstr(buf+i, sess->socksproxy.username, strlen(sess->socksproxy.username));
-			i += aimutil_put8(buf+i, strlen(sess->socksproxy.password));
-			i += aimutil_putstr(buf+i, sess->socksproxy.password, strlen(sess->socksproxy.password));
-			if (write(fd, buf, i) < i) {
-				*statusret = errno;
-				close(fd);
-				return -1;
-			}
-			if (read(fd, buf, 2) < 2) {
-				*statusret = errno;
-				close(fd);
-				return -1;
-			}
-			if ((buf[0] != 0x01) || (buf[1] != 0x00)) {
-				*statusret = EINVAL;
-				close(fd);
-				return -1;
-			}
-		}
-
-		i  = aimutil_put8(buf, 0x05);
-		i += aimutil_put8(buf+i, 0x01); /* CONNECT */
-		i += aimutil_put8(buf+i, 0x00); /* reserved */
-		i += aimutil_put8(buf+i, 0x03); /* address type: host name */
-		i += aimutil_put8(buf+i, strlen(host));
-		i += aimutil_putstr(buf+i, host, strlen(host));
-		i += aimutil_put16(buf+i, port);
-
-		if (write(fd, buf, i) < i) {
-			*statusret = errno;
-			close(fd);
-			return -1;
-		}
-
-		if (read(fd, buf, 10) < 10) {
-			*statusret = errno;
-			close(fd);
-			return -1;
-		}
-		if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
-			*statusret = EINVAL;
-			close(fd);
-			return -1;
-		}
-
-	} else { /* connecting directly */
-		struct sockaddr_in sa;
-		struct hostent *hp;
-
-		if (!(hp = gethostbyname(host))) {
-			*statusret = (h_errno | AIM_CONN_STATUS_RESOLVERR);
-			return -1;
-		}
-
-		memset(&sa, 0, sizeof(struct sockaddr_in));
-		sa.sin_port = htons(port);
-		memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
-		sa.sin_family = hp->h_addrtype;
-
-		fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
-
-		if (sess->nonblocking)
-			fcntl(fd, F_SETFL, O_NONBLOCK); /* XXX save flags */
-
-		if (connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
-			if (sess->nonblocking) {
-				if ((errno == EINPROGRESS) || (errno == EINTR)) {
-					if (statusret)
-						*statusret |= AIM_CONN_STATUS_INPROGRESS;
-					return fd;
-				}
-			}
-			close(fd);
-			fd = -1;
-		}
-	}
-	return fd;
-}
-
-/**
  * Clone an aim_conn_t.
  *
  * A new connection is allocated, and the values are filled in
@@ -611,65 +440,27 @@
 /**
  * Opens a new connection to the specified dest host of specified
  * type, using the proxy settings if available.  If @host is %NULL,
- * the connection is allocated and returned, but no connection 
+ * the connection is allocated and returned, but no connection
  * is made.
  *
  * FIXME: Return errors in a more sane way.
  *
  * @param sess Session to create connection in
  * @param type Type of connection to create
- * @param dest Host to connect to (in "host:port" syntax)
  */
-faim_export aim_conn_t *aim_newconn(aim_session_t *sess, int type, const char *dest)
+faim_export aim_conn_t *aim_newconn(aim_session_t *sess, int type)
 {
-	aim_conn_t *connstruct;
-	fu16_t port = FAIM_LOGIN_PORT;
-	char *host;
-	int i, ret;
+	aim_conn_t *conn;
 
-	if (!(connstruct = aim_conn_getnext(sess)))
+	if (!(conn = aim_conn_getnext(sess)))
 		return NULL;
 
-	connstruct->sessv = (void *)sess;
-	connstruct->type = type;
-
-	if (!dest) { /* just allocate a struct */
-		connstruct->fd = -1;
-		connstruct->status = 0;
-		return connstruct;
-	}
-
-	/*
-	 * As of 23 Jul 1999, AOL now sends the port number, preceded by a
-	 * colon, in the BOS redirect.  This fatally breaks all previous
-	 * libfaims.  Bad, bad AOL.
-	 *
-	 * We put this here to catch every case.
-	 *
-	 */
+	conn->sessv = (void *)sess;
+	conn->type = type;
 
-	for(i = 0; i < (int)strlen(dest); i++) {
-		if (dest[i] == ':') {
-			port = atoi(&(dest[i+1]));
-			break;
-		}
-	}
-
-	host = (char *)malloc(i+1);
-	strncpy(host, dest, i);
-	host[i] = '\0';
-
-	if ((ret = aim_proxyconnect(sess, host, port, &connstruct->status)) < 0) {
-		connstruct->fd = -1;
-		connstruct->status = (errno | AIM_CONN_STATUS_CONNERR);
-		free(host);
-		return connstruct;
-	} else
-		connstruct->fd = ret;
-
-	free(host);
-
-	return connstruct;
+	conn->fd = -1;
+	conn->status = 0;
+	return conn;
 }
 
 /**
--- a/src/protocols/oscar/ft.c	Tue Jul 26 04:49:50 2005 +0000
+++ b/src/protocols/oscar/ft.c	Fri Jul 29 01:14:23 2005 +0000
@@ -510,7 +510,7 @@
 	aim_cachecookie(sess, cookie);
 
 	/* XXX - switch to aim_cloneconn()? */
-	if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER, NULL))) {
+	if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER))) {
 		close(listenfd);
 		return NULL;
 	}
@@ -558,7 +558,7 @@
 		strncpy(intdata->ip, addr, sizeof(intdata->ip));
 
 	/* XXX - verify that non-blocking connects actually work */
-	if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, addr))) {
+	if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS))) {
 		free(intdata);
 		return NULL;
 	}
@@ -746,7 +746,7 @@
 	if (!oft_info)
 		return -EINVAL;
 
-	if (!(oft_info->conn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER, NULL))) {
+	if (!(oft_info->conn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER))) {
 		close(listenfd);
 		return -ENOMEM;
 	}
--- a/src/protocols/oscar/oscar.c	Tue Jul 26 04:49:50 2005 +0000
+++ b/src/protocols/oscar/oscar.c	Fri Jul 29 01:14:23 2005 +0000
@@ -1793,7 +1793,7 @@
 	aim_session_init(sess, TRUE, FAIM_DEBUG_LEVEL);
 	aim_setdebuggingcb(sess, oscar_debug);
 	/*
-	 * We need an immediate queue because we don't use a while-loop 
+	 * We need an immediate queue because we don't use a while-loop
 	 * to see if things need to be sent.
 	 */
 	aim_tx_setenqueue(sess, AIM_TX_IMMEDIATE, NULL);
@@ -1803,7 +1803,7 @@
 	/* Connect to core Gaim signals */
 	gaim_prefs_connect_callback(gc, "/plugins/prpl/oscar/recent_buddies", recent_buddies_cb, gc);
 
-	conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL);
+	conn = aim_newconn(sess, AIM_CONN_TYPE_AUTH);
 	if (conn == NULL) {
 		gaim_debug_error("oscar", "internal connection error\n");
 		gaim_connection_error(gc, _("Unable to login to AIM"));
@@ -2023,12 +2023,12 @@
 	GaimXfer *xfer;
 	struct aim_oft_info *oft_info;
 	char *msg = NULL;
-	
+
 	gaim_debug_info("oscar","AAA - in oscar_clientip_timeout\n");
 	xfer = (GaimXfer*) data;
 	if(xfer->data) {
 		oft_info = (struct aim_oft_info*) xfer->data;
-		
+
 		/* Check to see if the clientip has produced any results */
 		if(oft_info->conn && oft_info->conn->status != AIM_CONN_STATUS_INPROGRESS) {
 			msg = g_strdup_printf(_("Transfer of file %s timed out."),gaim_xfer_get_filename(xfer));
@@ -2073,7 +2073,7 @@
 	}
 	return FALSE;
 }
- 
+
 static void oscar_xfer_init_recv(GaimXfer *xfer)
 {
 	struct aim_oft_info *oft_info = xfer->data;
@@ -2081,7 +2081,7 @@
 	OscarData *od = gc->proto_data;
 
 	gaim_debug_info("oscar", "AAA - in oscar_xfer_recv_init\n");
-	
+
 	/* Start a timer for this ip address
 	 * If the verifiedip fails, try the clientip
 	 * If clientip fails, declare the whole file transfer dead
@@ -2097,7 +2097,7 @@
 		}
 	}
 
-	oft_info->conn = aim_newconn(od->sess, AIM_CONN_TYPE_RENDEZVOUS, NULL);
+	oft_info->conn = aim_newconn(od->sess, AIM_CONN_TYPE_RENDEZVOUS);
 	if (oft_info->conn) {
 		oft_info->conn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE;
 		aim_conn_addhandler(od->sess, oft_info->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_PROMPT, oscar_sendfile_prompt, 0);
@@ -2362,7 +2362,7 @@
 			   "Closing auth connection...\n");
 	aim_conn_kill(sess, &fr->conn);
 
-	bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, NULL);
+	bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS);
 	if (bosconn == NULL) {
 		gaim_connection_error(gc, _("Internal Error"));
 		od->killme = TRUE;
@@ -2912,7 +2912,7 @@
 	case 0x7: /* Authorizer */
 		gaim_debug_info("oscar",
 				   "Reconnecting with authorizor...\n");
-		tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, NULL);
+		tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH);
 		if (tstconn == NULL) {
 			gaim_debug_error("oscar",
 					   "unable to reconnect with authorizer\n");
@@ -2934,7 +2934,7 @@
 	break;
 
 	case 0xd: /* ChatNav */
-		tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, NULL);
+		tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV);
 		if (tstconn == NULL) {
 			gaim_debug_error("oscar",
 					   "unable to connect to chatnav server\n");
@@ -2958,7 +2958,7 @@
 	case 0xe: { /* Chat */
 		struct chat_connection *ccon;
 
-		tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, NULL);
+		tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT);
 		if (tstconn == NULL) {
 			gaim_debug_error("oscar",
 					   "unable to connect to chat server\n");
@@ -2995,7 +2995,7 @@
 	} break;
 
 	case 0x0010: { /* icon */
-		if (!(tstconn = aim_newconn(sess, AIM_CONN_TYPE_ICON, NULL))) {
+		if (!(tstconn = aim_newconn(sess, AIM_CONN_TYPE_ICON))) {
 			gaim_debug_error("oscar",
 					   "unable to connect to icon server\n");
 			g_free(host);
@@ -3016,7 +3016,7 @@
 	} break;
 
 	case 0x0018: { /* email */
-		if (!(tstconn = aim_newconn(sess, AIM_CONN_TYPE_EMAIL, NULL))) {
+		if (!(tstconn = aim_newconn(sess, AIM_CONN_TYPE_EMAIL))) {
 			gaim_debug_error("oscar",
 					   "unable to connect to email server\n");
 			g_free(host);
--- a/src/protocols/oscar/txqueue.c	Tue Jul 26 04:49:50 2005 +0000
+++ b/src/protocols/oscar/txqueue.c	Fri Jul 29 01:14:23 2005 +0000
@@ -347,7 +347,7 @@
 	for (cur = sess->queue_outgoing; cur; cur = cur->next) {
 
 		if (cur->handled)
-	       		continue; /* already been sent */
+			continue; /* already been sent */
 
 		if (cur->conn && (cur->conn->status & AIM_CONN_STATUS_INPROGRESS))
 			continue;
@@ -357,8 +357,8 @@
 		 * latency and avoid missed messages.
 		 */
 		if ((cur->conn->lastactivity + cur->conn->forcedlatency) >= time(NULL)) {
-			/* 
-			 * XXX should be a break! we don't want to block the 
+			/*
+			 * XXX should be a break! we don't want to block the
 			 * upper layers
 			 *
 			 * XXX or better, just do this right.