diff src/protocols/oscar/ft.c @ 8240:609a62b8e748

[gaim-migrate @ 8963] Make oscar use marv's core listening code. Hopefully my changes won't make anything any worse... file transfer and odc really need some lovin. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 12 Feb 2004 17:51:21 +0000
parents 4720864c365d
children aa755705bcf5
line wrap: on
line diff
--- a/src/protocols/oscar/ft.c	Thu Feb 12 17:23:17 2004 +0000
+++ b/src/protocols/oscar/ft.c	Thu Feb 12 17:51:21 2004 +0000
@@ -158,85 +158,6 @@
 }
 
 /**
- * Create a listening socket on a given port.
- *
- * XXX - Give the client author the responsibility of setting up a 
- *       listener, then we no longer have a libfaim problem with broken 
- *       solaris *innocent smile* -- jbm
- *
- * @param portnum The port number to bind to.
- * @return The file descriptor of the listening socket.
- */
-static int listenestablish(fu16_t portnum)
-{
-#if HAVE_GETADDRINFO
-	int listenfd;
-	const int on = 1;
-	struct addrinfo hints, *res, *ressave;
-	char serv[5];
-
-	snprintf(serv, sizeof(serv), "%d", portnum);
-	memset(&hints, 0, sizeof(struct addrinfo));
-	hints.ai_flags = AI_PASSIVE;
-	hints.ai_family = AF_UNSPEC;
-	hints.ai_socktype = SOCK_STREAM;
-	if (getaddrinfo(NULL /* any IP */, serv, &hints, &res) != 0) {
-		perror("getaddrinfo");
-		return -1;
-	} 
-	ressave = res;
-	do { 
-		listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
-		if (listenfd < 0)
-			continue;
-		setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
-		if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
-			break; /* success */
-		close(listenfd);
-	} while ( (res = res->ai_next) );
-
-	if (!res)
-		return -1;
-
-	freeaddrinfo(ressave);
-#else
-	int listenfd;
-	const int on = 1;
-	struct sockaddr_in sockin;
-
-	if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-		perror("socket");
-		return -1;
-	}
-
-	if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) != 0) {
-		perror("setsockopt");
-		close(listenfd);
-		return -1;
-	}
-
-	memset(&sockin, 0, sizeof(struct sockaddr_in));
-	sockin.sin_family = AF_INET;
-	sockin.sin_port = htons(portnum);
-
-	if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
-		perror("bind");
-		close(listenfd);
-		return -1;
-	}
-#endif
-
-	if (listen(listenfd, 4) != 0) {
-		perror("listen");
-		close(listenfd);
-		return -1;
-	}
-	fcntl(listenfd, F_SETFL, O_NONBLOCK);
-
-	return listenfd;
-}
-
-/**
  * After establishing a listening socket, this is called to accept a connection.  It
  * clones the conn used by the listener, and passes both of these to a signal handler.
  * The signal handler should close the listener conn and keep track of the new conn,
@@ -527,22 +448,17 @@
  * @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)
+faim_export aim_conn_t *aim_odc_initiate(aim_session_t *sess, const char *sn, int listenfd, fu16_t port)
 {
 	aim_conn_t *newconn;
 	aim_msgcookie_t *cookie;
 	struct aim_odc_intdata *priv;
-	int listenfd;
-	fu16_t port = 4443;
 	fu8_t localip[4];
 	fu8_t ck[8];
 
 	if (aim_util_getlocalip(localip) == -1)
 		return NULL;
 
-	if ((listenfd = listenestablish(port)) == -1)
-		return NULL;
-
 	aim_im_sendch2_odcrequest(sess, ck, sn, localip, port);
 
 	cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t));
@@ -787,16 +703,11 @@
  *        connection.
  * @return Return 0 if no errors, otherwise return the error number.
  */
-faim_export int aim_sendfile_listen(aim_session_t *sess, struct aim_oft_info *oft_info)
+faim_export int aim_sendfile_listen(aim_session_t *sess, struct aim_oft_info *oft_info, int listenfd)
 {
-	int listenfd;
-
 	if (!oft_info)
 		return -EINVAL;
 
-	if ((listenfd = listenestablish(oft_info->port)) == -1)
-		return 1;
-
 	if (!(oft_info->conn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER, NULL))) {
 		close(listenfd);
 		return -ENOMEM;