diff src/protocols/msn/servconn.c @ 9158:c30d81b4dd22

[gaim-migrate @ 9942] Patch from Felipe Contreras to sync our MSN prpl with what's in his tree. He says this may fix a couple bugs, but the important thing is the restructuring of how MsnMessages work. Lots of style changes and other stuff as well. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 01 Jun 2004 06:42:20 +0000
parents 6dd02df922b4
children 43ea2b858112
line wrap: on
line diff
--- a/src/protocols/msn/servconn.c	Tue Jun 01 01:55:55 2004 +0000
+++ b/src/protocols/msn/servconn.c	Tue Jun 01 06:42:20 2004 +0000
@@ -34,7 +34,7 @@
 
 	const char *names[] = { "Notification", "Switchboard" };
 	const char *name;
-
+	
 	gc = gaim_account_get_connection(servconn->session->account);
 	name = names[servconn->type];
 
@@ -49,8 +49,7 @@
 			break;
 		case MSN_ERROR_READ:
 			cmd = servconn->cmdproc->last_trans;
-			tmp = g_strdup_printf(_("Error reading from %s server. Last"
-									"command was:\n %s"), name, cmd);
+			tmp = g_strdup_printf(_("Error reading from %s server"), name);
 			gaim_debug_info("msn", "Last command was: %s\n", cmd);
 			break;
 		default:
@@ -59,7 +58,7 @@
 	}
 
 	gaim_connection_error(gc, tmp);
-
+	
 	g_free(tmp);
 }
 
@@ -68,8 +67,6 @@
 {
 	MsnServConn *servconn = data;
 
-	gaim_debug_info("msn", "In servconn's connect_cb\n");
-
 	servconn->fd = source;
 
 	if (source > 0)
@@ -87,7 +84,7 @@
 }
 
 MsnServConn *
-msn_servconn_new(MsnSession *session, MsnServerType type)
+msn_servconn_new(MsnSession *session, MsnServConnType type)
 {
 	MsnServConn *servconn;
 
@@ -113,11 +110,36 @@
 	return servconn;
 }
 
+void
+msn_servconn_destroy(MsnServConn *servconn)
+{
+	MsnSession *session;
+
+	g_return_if_fail(servconn != NULL);
+
+	if (servconn->processing)
+	{
+		servconn->wasted = TRUE;
+		return;
+	}
+
+	session = servconn->session;
+
+	session->servconns = g_list_remove(session->servconns, servconn);
+
+	if (servconn->connected)
+		msn_servconn_disconnect(servconn);
+
+	msn_cmdproc_destroy(servconn->cmdproc);
+
+	g_free(servconn);
+}
+
 gboolean
 msn_servconn_connect(MsnServConn *servconn, const char *host, int port)
 {
 	MsnSession *session;
-	int i;
+	int r;
 
 	g_return_val_if_fail(servconn != NULL, FALSE);
 	g_return_val_if_fail(host     != NULL, FALSE);
@@ -130,13 +152,13 @@
 
 	if (session->http_method)
 	{
-		servconn->http_data->gateway_ip = g_strdup(host);
+		servconn->http_data->gateway_host = g_strdup(host);
 	}
 
-	i = gaim_proxy_connect(session->account, host, port, connect_cb,
+	r = gaim_proxy_connect(session->account, host, port, connect_cb,
 						   servconn);
 
-	if (i == 0)
+	if (r == 0)
 		servconn->connected = TRUE;
 
 	return servconn->connected;
@@ -165,16 +187,17 @@
 		if (servconn->http_data->session_id != NULL)
 			g_free(servconn->http_data->session_id);
 
-		if (servconn->http_data->old_gateway_ip != NULL)
-			g_free(servconn->http_data->old_gateway_ip);
+		if (servconn->http_data->old_gateway_host != NULL)
+			g_free(servconn->http_data->old_gateway_host);
 
-		if (servconn->http_data->gateway_ip != NULL)
-			g_free(servconn->http_data->gateway_ip);
+		if (servconn->http_data->gateway_host != NULL)
+			g_free(servconn->http_data->gateway_host);
 
 		if (servconn->http_data->timer)
 			gaim_timeout_remove(servconn->http_data->timer);
 
 		g_free(servconn->http_data);
+		servconn->http_data = NULL;
 	}
 
 	servconn->rx_len = 0;
@@ -187,30 +210,6 @@
 }
 
 void
-msn_servconn_destroy(MsnServConn *servconn)
-{
-	MsnSession *session;
-
-	g_return_if_fail(servconn != NULL);
-
-	if (servconn->processing)
-	{
-		servconn->wasted = TRUE;
-		return;
-	}
-
-	session = servconn->session;
-
-	session->servconns = g_list_remove(session->servconns, servconn);
-
-	if (servconn->connected)
-		msn_servconn_disconnect(servconn);
-
-	msn_cmdproc_destroy(servconn->cmdproc);
-	g_free(servconn);
-}
-
-void
 msn_servconn_set_connect_cb(MsnServConn *servconn,
 							gboolean (*connect_cb)(MsnServConn *servconn))
 {
@@ -232,13 +231,15 @@
 static void
 failed_io(MsnServConn *servconn)
 {
+	g_return_if_fail(servconn != NULL);
+
 	show_error(servconn);
 
 	msn_servconn_disconnect(servconn);
 }
 
 size_t
-msn_servconn_write(MsnServConn *servconn, const char *buf, size_t size)
+msn_servconn_write(MsnServConn *servconn, const char *buf, size_t len)
 {
 	size_t ret = FALSE;
 
@@ -246,12 +247,12 @@
 
 	if (servconn->session->http_method)
 	{
-		ret = msn_http_servconn_write(servconn, buf, size,
-									   servconn->http_data->server_type);
+		ret = msn_http_servconn_write(servconn, buf, len,
+									  servconn->http_data->server_type);
 	}
 	else
 	{
-		ret = write(servconn->fd, buf, size);
+		ret = write(servconn->fd, buf, len);
 	}
 
 	if (ret < 0)
@@ -276,6 +277,7 @@
 	session = servconn->session;
 
 	len = read(servconn->fd, buf, sizeof(buf) - 1);
+	buf[len] = '\0';
 
 	if (len <= 0)
 	{
@@ -299,9 +301,9 @@
 
 		tmp = g_strndup(servconn->rx_buf, servconn->rx_len);
 
-		if (!msn_http_servconn_parse_data(servconn, tmp,
-										  servconn->rx_len, &result_msg,
-										  &result_len, &error))
+		if (!msn_http_servconn_parse_data(servconn, tmp, servconn->rx_len,
+										  &result_msg, &result_len,
+										  &error))
 		{
 			g_free(tmp);
 			return;
@@ -311,9 +313,8 @@
 
 		if (error)
 		{
-			gaim_connection_error(
-				gaim_account_get_connection(session->account),
-				_("Received HTTP error. Please report this."));
+			gaim_connection_error(gaim_account_get_connection(session->account),
+								  _("Received HTTP error. Please report this."));
 
 			return;
 		}
@@ -342,8 +343,7 @@
 			close(servconn->fd);
 
 			i = gaim_proxy_connect(session->account, servconn->host,
-								   servconn->port, servconn->login_cb,
-								   servconn);
+								   servconn->port, read_cb, servconn);
 
 			if (i == 0)
 				servconn->connected = TRUE;