Index: protocols/oscar/auth.c
===================================================================
--- protocols/oscar/auth.c	(revision 6b13103dad92d505e038c268af66aeb04b7b4d87)
+++ protocols/oscar/auth.c	(revision 0e4c3dd2cd5495d2f5d1247471c348e7676612b4)
@@ -4,5 +4,5 @@
  */
 
-#include <aim.h> 
+#include <aim.h>
 
 #include "md5.h"
@@ -10,5 +10,5 @@
 static int aim_encode_password(const char *password, unsigned char *encoded);
 
-/* 
+/*
  * This just pushes the passed cookie onto the passed connection, without
  * the SNAC header or any of that.
@@ -23,9 +23,10 @@
 	aim_tlvlist_t *tl = NULL;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4+2+2+AIM_COOKIELEN)))
+	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0001, 4 + 2 + 2 + AIM_COOKIELEN))) {
 		return -ENOMEM;
+	}
 
 	aimbs_put32(&fr->data, 0x00000001);
-	aim_addtlvtochain_raw(&tl, 0x0006, AIM_COOKIELEN, chipsahoy);	
+	aim_addtlvtochain_raw(&tl, 0x0006, AIM_COOKIELEN, chipsahoy);
 	aim_writetlvchain(&fr->data, &tl);
 	aim_freetlvchain(&tl);
@@ -48,6 +49,7 @@
 	aim_frame_t *fr;
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4)))
+	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 4))) {
 		return -ENOMEM;
+	}
 
 	aimbs_put32(&fr->data, 0x00000001);
@@ -95,22 +97,23 @@
 	aim_frame_t fr;
 	aim_rxcallback_t userfunc;
-	
+
 	sess->flags &= ~AIM_SESS_FLAGS_SNACLOGIN;
 	sess->flags |= AIM_SESS_FLAGS_XORLOGIN;
 
 	fr.conn = conn;
-	
-	if ((userfunc = aim_callhandler(sess, conn, 0x0017, 0x0007)))
+
+	if ((userfunc = aim_callhandler(sess, conn, 0x0017, 0x0007))) {
 		userfunc(sess, &fr, "");
-
-	return 0;
-}
-
-/*
- * In AIM 3.5 protocol, the first stage of login is to request login from the 
- * Authorizer, passing it the screen name for verification.  If the name is 
- * invalid, a 0017/0003 is spit back, with the standard error contents.  If 
- * valid, a 0017/0007 comes back, which is the signal to send it the main 
- * login command (0017/0002). 
+	}
+
+	return 0;
+}
+
+/*
+ * In AIM 3.5 protocol, the first stage of login is to request login from the
+ * Authorizer, passing it the screen name for verification.  If the name is
+ * invalid, a 0017/0003 is spit back, with the standard error contents.  If
+ * valid, a 0017/0007 comes back, which is the signal to send it the main
+ * login command (0017/0002).
  *
  */
@@ -121,10 +124,12 @@
 	aim_tlvlist_t *tl = NULL;
 	struct im_connection *ic = sess->aux_data;
-	
-	if (!sess || !conn || !sn)
+
+	if (!sess || !conn || !sn) {
 		return -EINVAL;
-
-	if (g_ascii_isdigit(sn[0]) && set_getbool(&ic->acc->set, "old_icq_auth"))
+	}
+
+	if (g_ascii_isdigit(sn[0]) && set_getbool(&ic->acc->set, "old_icq_auth")) {
 		return goddamnicq(sess, conn, sn);
+	}
 
 	sess->flags |= AIM_SESS_FLAGS_SNACLOGIN;
@@ -132,11 +137,12 @@
 	aim_sendflapver(sess, conn);
 
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(sn))))
+	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2 + strlen(sn)))) {
 		return -ENOMEM;
+	}
 
 	snacid = aim_cachesnac(sess, 0x0017, 0x0006, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x0017, 0x0006, 0x0000, snacid);
 
-	aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *)sn);
+	aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn);
 	aim_writetlvchain(&fr->data, &tl);
 	aim_freetlvchain(&tl);
@@ -152,13 +158,14 @@
 static int goddamnicq2(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password)
 {
-	static const char clientstr[] = {"ICQ Inc. - Product of ICQ (TM) 2001b.5.17.1.3642.85"};
-	static const char lang[] = {"en"};
-	static const char country[] = {"us"};
+	static const char clientstr[] = { "ICQ Inc. - Product of ICQ (TM) 2001b.5.17.1.3642.85" };
+	static const char lang[] = { "en" };
+	static const char country[] = { "us" };
 	aim_frame_t *fr;
 	aim_tlvlist_t *tl = NULL;
 	guint8 *password_encoded;
 
-	if (!(password_encoded = (guint8 *) g_malloc(strlen(password))))
+	if (!(password_encoded = (guint8 *) g_malloc(strlen(password)))) {
 		return -ENOMEM;
+	}
 
 	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x01, 1152))) {
@@ -170,7 +177,7 @@
 
 	aimbs_put32(&fr->data, 0x00000001);
-	aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *)sn);
+	aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn);
 	aim_addtlvtochain_raw(&tl, 0x0002, strlen(password), password_encoded);
-	aim_addtlvtochain_raw(&tl, 0x0003, strlen(clientstr), (guint8 *)clientstr);
+	aim_addtlvtochain_raw(&tl, 0x0003, strlen(clientstr), (guint8 *) clientstr);
 	aim_addtlvtochain16(&tl, 0x0016, 0x010a); /* cliend ID */
 	aim_addtlvtochain16(&tl, 0x0017, 0x0005); /* major version */
@@ -179,6 +186,6 @@
 	aim_addtlvtochain16(&tl, 0x001a, 0x0e3a); /* build */
 	aim_addtlvtochain32(&tl, 0x0014, 0x00000055); /* distribution chan */
-	aim_addtlvtochain_raw(&tl, 0x000f, strlen(lang), (guint8 *)lang);
-	aim_addtlvtochain_raw(&tl, 0x000e, strlen(country), (guint8 *)country);
+	aim_addtlvtochain_raw(&tl, 0x000f, strlen(lang), (guint8 *) lang);
+	aim_addtlvtochain_raw(&tl, 0x000e, strlen(country), (guint8 *) country);
 
 	aim_writetlvchain(&fr->data, &tl);
@@ -194,5 +201,5 @@
 /*
  * send_login(int socket, char *sn, char *password)
- *  
+ *
  * This is the initial login request packet.
  *
@@ -249,5 +256,5 @@
  *   build  = 0x0013
  *   unknown= (not sent)
- *   
+ *
  * AIM for Linux 1.1.112:
  *   clientstring = "AOL Instant Messenger (SM)"
@@ -261,5 +268,6 @@
  *
  */
-int aim_send_login(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password, struct client_info_s *ci, const char *key)
+int aim_send_login(aim_session_t *sess, aim_conn_t *conn, const char *sn, const char *password,
+                   struct client_info_s *ci, const char *key)
 {
 	aim_frame_t *fr;
@@ -268,6 +276,7 @@
 	aim_snacid_t snacid;
 
-	if (!ci || !sn || !password)
+	if (!ci || !sn || !password) {
 		return -EINVAL;
+	}
 
 	/*
@@ -276,15 +285,17 @@
 	 *
 	 */
-	if (sess->flags & AIM_SESS_FLAGS_XORLOGIN)
+	if (sess->flags & AIM_SESS_FLAGS_XORLOGIN) {
 		return goddamnicq2(sess, conn, sn, password);
-
-
-	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
+	}
+
+
+	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) {
 		return -ENOMEM;
+	}
 
 	snacid = aim_cachesnac(sess, 0x0017, 0x0002, 0x0000, NULL, 0);
 	aim_putsnac(&fr->data, 0x0017, 0x0002, 0x0000, snacid);
 
-	aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *)sn);
+	aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), (guint8 *) sn);
 
 	aim_encode_password_md5(password, key, digest);
@@ -295,13 +306,14 @@
 	 */
 
-	if (ci->clientstring)
-		aim_addtlvtochain_raw(&tl, 0x0003, strlen(ci->clientstring), (guint8 *)ci->clientstring);
-	aim_addtlvtochain16(&tl, 0x0016, (guint16)ci->clientid);
-	aim_addtlvtochain16(&tl, 0x0017, (guint16)ci->major);
-	aim_addtlvtochain16(&tl, 0x0018, (guint16)ci->minor);
-	aim_addtlvtochain16(&tl, 0x0019, (guint16)ci->point);
-	aim_addtlvtochain16(&tl, 0x001a, (guint16)ci->build);
-	aim_addtlvtochain_raw(&tl, 0x000e, strlen(ci->country), (guint8 *)ci->country);
-	aim_addtlvtochain_raw(&tl, 0x000f, strlen(ci->lang), (guint8 *)ci->lang);
+	if (ci->clientstring) {
+		aim_addtlvtochain_raw(&tl, 0x0003, strlen(ci->clientstring), (guint8 *) ci->clientstring);
+	}
+	aim_addtlvtochain16(&tl, 0x0016, (guint16) ci->clientid);
+	aim_addtlvtochain16(&tl, 0x0017, (guint16) ci->major);
+	aim_addtlvtochain16(&tl, 0x0018, (guint16) ci->minor);
+	aim_addtlvtochain16(&tl, 0x0019, (guint16) ci->point);
+	aim_addtlvtochain16(&tl, 0x001a, (guint16) ci->build);
+	aim_addtlvtochain_raw(&tl, 0x000e, strlen(ci->country), (guint8 *) ci->country);
+	aim_addtlvtochain_raw(&tl, 0x000f, strlen(ci->lang), (guint8 *) ci->lang);
 
 	/*
@@ -314,5 +326,5 @@
 
 	aim_freetlvchain(&tl);
-	
+
 	aim_tx_enqueue(sess, fr);
 
@@ -324,9 +336,9 @@
 	md5_state_t state;
 
-	md5_init(&state);	
-	md5_append(&state, (const md5_byte_t *)key, strlen(key));
-	md5_append(&state, (const md5_byte_t *)password, strlen(password));
-	md5_append(&state, (const md5_byte_t *)AIM_MD5_STRING, strlen(AIM_MD5_STRING));
-	md5_finish(&state, (md5_byte_t *)digest);
+	md5_init(&state);
+	md5_append(&state, (const md5_byte_t *) key, strlen(key));
+	md5_append(&state, (const md5_byte_t *) password, strlen(password));
+	md5_append(&state, (const md5_byte_t *) AIM_MD5_STRING, strlen(AIM_MD5_STRING));
+	md5_finish(&state, (md5_byte_t *) digest);
 
 	return 0;
@@ -345,5 +357,5 @@
  *
  * The encoding_table seems to be a fixed set of values.  We'll
- * hope it doesn't change over time!  
+ * hope it doesn't change over time!
  *
  * This is only used for the XOR method, not the better MD5 method.
@@ -353,5 +365,5 @@
 {
 	guint8 encoding_table[] = {
-	/* v2.1 table, also works for ICQ */
+		/* v2.1 table, also works for ICQ */
 		0xf3, 0x26, 0x81, 0xc4,
 		0x39, 0x86, 0xdb, 0x92,
@@ -361,6 +373,7 @@
 	int i;
 
-	for (i = 0; i < strlen(password); i++)
+	for (i = 0; i < strlen(password); i++) {
 		encoded[i] = (password[i] ^ encoding_table[i]);
+	}
 
 	return 0;
@@ -370,5 +383,5 @@
  * This is sent back as a general response to the login command.
  * It can be either an error or a success, depending on the
- * precense of certain TLVs.  
+ * precense of certain TLVs.
  *
  * The client should check the value passed as errorcode. If
@@ -404,14 +417,17 @@
 	 * have an error url.
 	 */
-	if (aim_gettlv(tlvlist, 0x0008, 1)) 
+	if (aim_gettlv(tlvlist, 0x0008, 1)) {
 		info.errorcode = aim_gettlv16(tlvlist, 0x0008, 1);
-	if (aim_gettlv(tlvlist, 0x0004, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0004, 1)) {
 		info.errorurl = aim_gettlv_str(tlvlist, 0x0004, 1);
+	}
 
 	/*
 	 * BOS server address.
 	 */
-	if (aim_gettlv(tlvlist, 0x0005, 1))
+	if (aim_gettlv(tlvlist, 0x0005, 1)) {
 		info.bosip = aim_gettlv_str(tlvlist, 0x0005, 1);
+	}
 
 	/*
@@ -430,6 +446,7 @@
 	 *   Not available for ICQ logins.
 	 */
-	if (aim_gettlv(tlvlist, 0x0011, 1))
+	if (aim_gettlv(tlvlist, 0x0011, 1)) {
 		info.email = aim_gettlv_str(tlvlist, 0x0011, 1);
+	}
 
 	/*
@@ -445,32 +462,44 @@
 	 *
 	 */
-	if (aim_gettlv(tlvlist, 0x0013, 1))
+	if (aim_gettlv(tlvlist, 0x0013, 1)) {
 		info.regstatus = aim_gettlv16(tlvlist, 0x0013, 1);
-
-	if (aim_gettlv(tlvlist, 0x0040, 1))
+	}
+
+	if (aim_gettlv(tlvlist, 0x0040, 1)) {
 		info.latestbeta.build = aim_gettlv32(tlvlist, 0x0040, 1);
-	if (aim_gettlv(tlvlist, 0x0041, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0041, 1)) {
 		info.latestbeta.url = aim_gettlv_str(tlvlist, 0x0041, 1);
-	if (aim_gettlv(tlvlist, 0x0042, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0042, 1)) {
 		info.latestbeta.info = aim_gettlv_str(tlvlist, 0x0042, 1);
-	if (aim_gettlv(tlvlist, 0x0043, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0043, 1)) {
 		info.latestbeta.name = aim_gettlv_str(tlvlist, 0x0043, 1);
-	if (aim_gettlv(tlvlist, 0x0048, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0048, 1)) {
 		; /* no idea what this is */
 
-	if (aim_gettlv(tlvlist, 0x0044, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0044, 1)) {
 		info.latestrelease.build = aim_gettlv32(tlvlist, 0x0044, 1);
-	if (aim_gettlv(tlvlist, 0x0045, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0045, 1)) {
 		info.latestrelease.url = aim_gettlv_str(tlvlist, 0x0045, 1);
-	if (aim_gettlv(tlvlist, 0x0046, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0046, 1)) {
 		info.latestrelease.info = aim_gettlv_str(tlvlist, 0x0046, 1);
-	if (aim_gettlv(tlvlist, 0x0047, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0047, 1)) {
 		info.latestrelease.name = aim_gettlv_str(tlvlist, 0x0047, 1);
-	if (aim_gettlv(tlvlist, 0x0049, 1))
+	}
+	if (aim_gettlv(tlvlist, 0x0049, 1)) {
 		; /* no idea what this is */
 
 
-	if ((userfunc = aim_callhandler(sess, rx->conn, snac ? snac->family : 0x0017, snac ? snac->subtype : 0x0003)))
+	}
+	if ((userfunc = aim_callhandler(sess, rx->conn, snac ? snac->family : 0x0017, snac ? snac->subtype : 0x0003))) {
 		ret = userfunc(sess, rx, &info);
+	}
 
 	g_free(info.sn);
@@ -506,8 +535,9 @@
 	keystr = aimbs_getstr(bs, keylen);
 
-	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) {
 		ret = userfunc(sess, rx, keystr);
-
-	g_free(keystr); 
+	}
+
+	g_free(keystr);
 
 	return ret;
@@ -517,8 +547,9 @@
 {
 
-	if (snac->subtype == 0x0003)
+	if (snac->subtype == 0x0003) {
 		return parse(sess, mod, rx, snac, bs);
-	else if (snac->subtype == 0x0007)
+	} else if (snac->subtype == 0x0007) {
 		return keyparse(sess, mod, rx, snac, bs);
+	}
 
 	return 0;
