Index: skype/skype.c
===================================================================
--- skype/skype.c	(revision c213d6be2b6f28bd7d9bf759aba819a2f19abdae)
+++ skype/skype.c	(revision 1f4fc807258b2d0b382534567bad61a3bfb50f3f)
@@ -21,4 +21,5 @@
 
 #define _XOPEN_SOURCE
+#define _BSD_SOURCE
 #include <poll.h>
 #include <bitlbee.h>
@@ -158,11 +159,21 @@
 }
 
+int skype_printf(struct im_connection *ic, char *fmt, ...)
+{
+	va_list args;
+	char str[IRC_LINE_SIZE];
+	
+	va_start(args, fmt);
+	vsnprintf(str, IRC_LINE_SIZE, fmt, args);
+	va_end(args);
+
+	return skype_write(ic, str);
+}
+
 static void skype_buddy_ask_yes(void *data)
 {
 	struct skype_buddy_ask_data *bla = data;
-	char *buf = g_strdup_printf("SET USER %s ISAUTHORIZED TRUE",
+	skype_printf(bla->ic, "SET USER %s ISAUTHORIZED TRUE",
 		bla->handle);
-	skype_write(bla->ic, buf);
-	g_free(buf);
 	g_free(bla->handle);
 	g_free(bla);
@@ -172,8 +183,6 @@
 {
 	struct skype_buddy_ask_data *bla = data;
-	char *buf = g_strdup_printf("SET USER %s ISAUTHORIZED FALSE",
+	skype_printf(bla->ic, "SET USER %s ISAUTHORIZED FALSE",
 		bla->handle);
-	skype_write(bla->ic, buf);
-	g_free(buf);
 	g_free(bla->handle);
 	g_free(bla);
@@ -198,8 +207,6 @@
 {
 	struct skype_buddy_ask_data *bla = data;
-	char *buf = g_strdup_printf("SET CALL %s STATUS INPROGRESS",
+	skype_printf(bla->ic, "SET CALL %s STATUS INPROGRESS",
 		bla->handle);
-	skype_write(bla->ic, buf);
-	g_free(buf);
 	g_free(bla->handle);
 	g_free(bla);
@@ -209,8 +216,6 @@
 {
 	struct skype_buddy_ask_data *bla = data;
-	char *buf = g_strdup_printf("SET CALL %s STATUS FINISHED",
+	skype_printf(bla->ic, "SET CALL %s STATUS FINISHED",
 		bla->handle);
-	skype_write(bla->ic, buf);
-	g_free(buf);
 	g_free(bla->handle);
 	g_free(bla);
@@ -272,12 +277,9 @@
 static void skype_parse_users(struct im_connection *ic, char *line)
 {
-	char **i, **nicks, *ptr;
+	char **i, **nicks;
 
 	nicks = g_strsplit(line + 6, ", ", 0);
-	for (i = nicks; *i; i++) {
-		ptr = g_strdup_printf("GET USER %s ONLINESTATUS\n", *i);
-		skype_write(ic, ptr);
-		g_free(ptr);
-	}
+	for (i = nicks; *i; i++)
+		skype_printf(ic, "GET USER %s ONLINESTATUS\n", *i);
 	g_strfreev(nicks);
 }
@@ -510,12 +512,8 @@
 		 * (4) Query chatname
 		 */
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHATMESSAGE %s FROM_HANDLE\n", id);
-		skype_write(ic, buf);
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHATMESSAGE %s BODY\n", id);
-		skype_write(ic, buf);
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHATMESSAGE %s TYPE\n", id);
-		skype_write(ic, buf);
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHATMESSAGE %s CHATNAME\n", id);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CHATMESSAGE %s FROM_HANDLE\n", id);
+		skype_printf(ic, "GET CHATMESSAGE %s BODY\n", id);
+		skype_printf(ic, "GET CHATMESSAGE %s TYPE\n", id);
+		skype_printf(ic, "GET CHATMESSAGE %s CHATNAME\n", id);
 	} else if (!strncmp(info, "FROM_HANDLE ", 12)) {
 		info += 12;
@@ -598,22 +596,17 @@
 			g_free(sd->call_id);
 		sd->call_id = g_strdup(id);
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CALL %s PARTNER_HANDLE\n", id);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
 		sd->call_status = SKYPE_CALL_RINGING;
 	} else if (!strcmp(info, "STATUS MISSED")) {
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CALL %s PARTNER_HANDLE\n", id);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
 		sd->call_status = SKYPE_CALL_MISSED;
 	} else if (!strcmp(info, "STATUS CANCELLED")) {
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CALL %s PARTNER_HANDLE\n", id);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
 		sd->call_status = SKYPE_CALL_CANCELLED;
 	} else if (!strcmp(info, "STATUS FINISHED")) {
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CALL %s PARTNER_HANDLE\n", id);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
 		sd->call_status = SKYPE_CALL_FINISHED;
 	} else if (!strcmp(info, "STATUS REFUSED")) {
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CALL %s PARTNER_HANDLE\n", id);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id);
 		sd->call_status = SKYPE_CALL_REFUSED;
 	} else if (!strcmp(info, "STATUS UNPLACED")) {
@@ -690,5 +683,4 @@
 {
 	struct skype_data *sd = ic->proto_data;
-	char buf[IRC_LINE_SIZE];
 	char *id = strchr(line, ' ');
 
@@ -702,12 +694,10 @@
 	info++;
 	if (!strcmp(info, "STATUS NEW")) {
-		g_snprintf(buf, IRC_LINE_SIZE, "GET FILETRANSFER %s PARTNER_HANDLE\n",
+		skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n",
 			id);
-		skype_write(ic, buf);
 		sd->filetransfer_status = SKYPE_FILETRANSFER_NEW;
 	} else if (!strcmp(info, "STATUS FAILED")) {
-		g_snprintf(buf, IRC_LINE_SIZE, "GET FILETRANSFER %s PARTNER_HANDLE\n",
+		skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n",
 			id);
-		skype_write(ic, buf);
 		sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED;
 	} else if (!strncmp(info, "PARTNER_HANDLE ", 15)) {
@@ -750,8 +740,6 @@
 	if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) {
 		imcb_chat_new(ic, id);
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHAT %s ADDER\n", id);
-		skype_write(ic, buf);
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHAT %s TOPIC\n", id);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CHAT %s ADDER\n", id);
+		skype_printf(ic, "GET CHAT %s TOPIC\n", id);
 	} else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) {
 		gc = imcb_chat_new(ic, id);
@@ -762,6 +750,5 @@
 		 * window on our client, so
 		 * just leave it out. */
-		/*g_snprintf(buf, IRC_LINE_SIZE, "OPEN CHAT %s\n", id);
-		  skype_write(ic, buf);*/
+		/*skype_printf(ic, "OPEN CHAT %s\n", id);*/
 		g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", sd->groupchat_with);
 		imcb_chat_add_buddy(gc, buf);
@@ -769,8 +756,6 @@
 		g_free(sd->groupchat_with);
 		sd->groupchat_with = NULL;
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHAT %s ADDER\n", id);
-		skype_write(ic, buf);
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHAT %s TOPIC\n", id);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CHAT %s ADDER\n", id);
+		skype_printf(ic, "GET CHAT %s TOPIC\n", id);
 	} else if (!strcmp(info, "STATUS UNSUBSCRIBED")) {
 		gc = skype_chat_by_name(ic, id);
@@ -834,10 +819,9 @@
 static void skype_parse_ping(struct im_connection *ic, char *line)
 {
-	skype_write(ic, "PONG\n");
+	skype_printf(ic, "PONG\n");
 }
 
 static void skype_parse_chats(struct im_connection *ic, char *line)
 {
-	char buf[IRC_LINE_SIZE];
 	char **i;
 	char **chats = g_strsplit(line + 6, ", ", 0);
@@ -845,8 +829,6 @@
 	i = chats;
 	while (*i) {
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHAT %s STATUS\n", *i);
-		skype_write(ic, buf);
-		g_snprintf(buf, IRC_LINE_SIZE, "GET CHAT %s ACTIVEMEMBERS\n", *i);
-		skype_write(ic, buf);
+		skype_printf(ic, "GET CHAT %s STATUS\n", *i);
+		skype_printf(ic, "GET CHAT %s ACTIVEMEMBERS\n", *i);
 		i++;
 	}
@@ -917,5 +899,4 @@
 {
 	struct skype_data *sd = ic->proto_data;
-	char *buf;
 	int st;
 
@@ -928,25 +909,14 @@
 
 	/* Log in */
-	buf = g_strdup_printf("USERNAME %s\n", ic->acc->user);
-	st = skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("PASSWORD %s\n", ic->acc->pass);
-	st = skype_write(ic, buf);
-	g_free(buf);
+	skype_printf(ic, "USERNAME %s\n", ic->acc->user);
+	skype_printf(ic, "PASSWORD %s\n", ic->acc->pass);
 
 	/* This will download all buddies. */
-	buf = g_strdup_printf("SEARCH FRIENDS\n");
-	st = skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("SET USERSTATUS ONLINE\n");
-	skype_write(ic, buf);
-	g_free(buf);
+	st = skype_printf(ic, "SEARCH FRIENDS\n");
+	skype_printf(ic, "SET USERSTATUS ONLINE\n");
 
 	/* Auto join to bookmarked chats if requested.*/
-	if (set_getbool(&ic->acc->set, "auto_join")) {
-		buf = g_strdup_printf("SEARCH BOOKMARKEDCHATS\n");
-		skype_write(ic, buf);
-		g_free(buf);
-	}
+	if (set_getbool(&ic->acc->set, "auto_join"))
+		skype_printf(ic, "SEARCH BOOKMARKEDCHATS\n");
 	return st;
 }
@@ -988,9 +958,6 @@
 {
 	struct skype_data *sd = ic->proto_data;
-	char *buf;
-
-	buf = g_strdup_printf("SET USERSTATUS OFFLINE\n");
-	skype_write(ic, buf);
-	g_free(buf);
+
+	skype_printf(ic, "SET USERSTATUS OFFLINE\n");
 
 	g_free(sd->username);
@@ -1003,5 +970,5 @@
 			   int flags)
 {
-	char *buf, *ptr, *nick;
+	char *ptr, *nick;
 	int st;
 
@@ -1012,10 +979,8 @@
 
 	if (!strncmp(who, "skypeconsole", 12))
-		buf = g_strdup_printf("%s\n", message);
+		st = skype_printf(ic, "%s\n", message);
 	else
-		buf = g_strdup_printf("MESSAGE %s %s\n", nick, message);
+		st = skype_printf(ic, "MESSAGE %s %s\n", nick, message);
 	g_free(nick);
-	st = skype_write(ic, buf);
-	g_free(buf);
 
 	return st;
@@ -1037,5 +1002,4 @@
 {
 	const struct skype_away_state *state;
-	char *buf;
 
 	if (strcmp(state_txt, GAIM_AWAY_CUSTOM) == 0)
@@ -1043,7 +1007,5 @@
 	else
 		state = skype_away_state_by_name(state_txt);
-	buf = g_strdup_printf("SET USERSTATUS %s\n", state->code);
-	skype_write(ic, buf);
-	g_free(buf);
+	skype_printf(ic, "SET USERSTATUS %s\n", state->code);
 }
 
@@ -1065,9 +1027,6 @@
 	account_t *acc = set->data;
 	struct im_connection *ic = acc->ic;
-	char *buf;
-
-	buf = g_strdup_printf("SET PROFILE FULLNAME %s", value);
-	skype_write(ic, buf);
-	g_free(buf);
+
+	skype_printf(ic, "SET PROFILE FULLNAME %s", value);
 	return value;
 }
@@ -1077,9 +1036,6 @@
 	account_t *acc = set->data;
 	struct im_connection *ic = acc->ic;
-	char *buf;
-
-	buf = g_strdup_printf("GET PROFILE PSTN_BALANCE");
-	skype_write(ic, buf);
-	g_free(buf);
+
+	skype_printf(ic, "GET PROFILE PSTN_BALANCE");
 	return value;
 }
@@ -1090,5 +1046,5 @@
 	struct im_connection *ic = acc->ic;
 	struct skype_data *sd = ic->proto_data;
-	char *nick, *ptr, *buf;
+	char *nick, *ptr;
 
 	if (value) {
@@ -1103,15 +1059,11 @@
 			*ptr = '\0';
 
-		buf = g_strdup_printf("CALL %s", nick);
-		skype_write(ic, buf);
-		g_free(buf);
+		skype_printf(ic, "CALL %s", nick);
 		g_free(nick);
 	} else {
 		/* We are ending a call */
 		if (sd->call_id) {
-			buf = g_strdup_printf("SET CALL %s STATUS FINISHED",
+			skype_printf(ic, "SET CALL %s STATUS FINISHED",
 				sd->call_id);
-			skype_write(ic, buf);
-			g_free(buf);
 			g_free(sd->call_id);
 			sd->call_id = NULL;
@@ -1124,5 +1076,5 @@
 static void skype_add_buddy(struct im_connection *ic, char *who, char *group)
 {
-	char *buf, *nick, *ptr;
+	char *nick, *ptr;
 
 	nick = g_strdup(who);
@@ -1130,7 +1082,6 @@
 	if (ptr)
 		*ptr = '\0';
-	buf = g_strdup_printf("SET USER %s BUDDYSTATUS 2 Please authorize me\n",
+	skype_printf(ic, "SET USER %s BUDDYSTATUS 2 Please authorize me\n",
 		nick);
-	skype_write(ic, buf);
 	g_free(nick);
 }
@@ -1138,5 +1089,5 @@
 static void skype_remove_buddy(struct im_connection *ic, char *who, char *group)
 {
-	char *buf, *nick, *ptr;
+	char *nick, *ptr;
 
 	nick = g_strdup(who);
@@ -1144,6 +1095,5 @@
 	if (ptr)
 		*ptr = '\0';
-	buf = g_strdup_printf("SET USER %s BUDDYSTATUS 1\n", nick);
-	skype_write(ic, buf);
+	skype_printf(ic, "SET USER %s BUDDYSTATUS 1\n", nick);
 	g_free(nick);
 }
@@ -1152,8 +1102,5 @@
 {
 	struct im_connection *ic = gc->ic;
-	char *buf;
-	buf = g_strdup_printf("CHATMESSAGE %s %s\n", gc->title, message);
-	skype_write(ic, buf);
-	g_free(buf);
+	skype_printf(ic, "CHATMESSAGE %s %s\n", gc->title, message);
 }
 
@@ -1161,8 +1108,5 @@
 {
 	struct im_connection *ic = gc->ic;
-	char *buf;
-	buf = g_strdup_printf("ALTER CHAT %s LEAVE\n", gc->title);
-	skype_write(ic, buf);
-	g_free(buf);
+	skype_printf(ic, "ALTER CHAT %s LEAVE\n", gc->title);
 	gc->data = (void *)TRUE;
 }
@@ -1171,12 +1115,10 @@
 {
 	struct im_connection *ic = gc->ic;
-	char *buf, *ptr, *nick;
+	char *ptr, *nick;
 	nick = g_strdup(message);
 	ptr = strchr(nick, '@');
 	if (ptr)
 		*ptr = '\0';
-	buf = g_strdup_printf("ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick);
-	skype_write(ic, buf);
-	g_free(buf);
+	skype_printf(ic, "ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick);
 	g_free(nick);
 }
@@ -1186,9 +1128,6 @@
 	struct im_connection *ic = gc->ic;
 	struct skype_data *sd = ic->proto_data;
-	char *buf;
-	buf = g_strdup_printf("ALTER CHAT %s SETTOPIC %s\n",
+	skype_printf(ic, "ALTER CHAT %s SETTOPIC %s\n",
 		gc->title, message);
-	skype_write(ic, buf);
-	g_free(buf);
 	sd->topic_wait = 1;
 }
@@ -1197,12 +1136,10 @@
 {
 	struct skype_data *sd = ic->proto_data;
-	char *ptr, *nick, *buf;
+	char *ptr, *nick;
 	nick = g_strdup(who);
 	ptr = strchr(nick, '@');
 	if (ptr)
 		*ptr = '\0';
-	buf = g_strdup_printf("CHAT CREATE %s\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
+	skype_printf(ic, "CHAT CREATE %s\n", nick);
 	sd->groupchat_with = g_strdup(nick);
 	g_free(nick);
@@ -1214,54 +1151,24 @@
 static void skype_get_info(struct im_connection *ic, char *who)
 {
-	char *ptr, *nick, *buf;
+	char *ptr, *nick;
 	nick = g_strdup(who);
 	ptr = strchr(nick, '@');
 	if (ptr)
 		*ptr = '\0';
-	buf = g_strdup_printf("GET USER %s FULLNAME\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s PHONE_HOME\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s PHONE_OFFICE\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s PHONE_MOBILE\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s NROF_AUTHED_BUDDIES\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s TIMEZONE\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s LASTONLINETIMESTAMP\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s BIRTHDAY\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s SEX\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s LANGUAGE\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s COUNTRY\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s PROVINCE\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s CITY\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s HOMEPAGE\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
-	buf = g_strdup_printf("GET USER %s ABOUT\n", nick);
-	skype_write(ic, buf);
-	g_free(buf);
+	skype_printf(ic, "GET USER %s FULLNAME\n", nick);
+	skype_printf(ic, "GET USER %s PHONE_HOME\n", nick);
+	skype_printf(ic, "GET USER %s PHONE_OFFICE\n", nick);
+	skype_printf(ic, "GET USER %s PHONE_MOBILE\n", nick);
+	skype_printf(ic, "GET USER %s NROF_AUTHED_BUDDIES\n", nick);
+	skype_printf(ic, "GET USER %s TIMEZONE\n", nick);
+	skype_printf(ic, "GET USER %s LASTONLINETIMESTAMP\n", nick);
+	skype_printf(ic, "GET USER %s BIRTHDAY\n", nick);
+	skype_printf(ic, "GET USER %s SEX\n", nick);
+	skype_printf(ic, "GET USER %s LANGUAGE\n", nick);
+	skype_printf(ic, "GET USER %s COUNTRY\n", nick);
+	skype_printf(ic, "GET USER %s PROVINCE\n", nick);
+	skype_printf(ic, "GET USER %s CITY\n", nick);
+	skype_printf(ic, "GET USER %s HOMEPAGE\n", nick);
+	skype_printf(ic, "GET USER %s ABOUT\n", nick);
 }
 
