changeset 9272:ac4480944fc3

[gaim-migrate @ 10075] Stu Tomlinson went crazy adding commands to SILC. He also made it so the gaim password field can be used as the SILC passphrase, and fixed some bugs while he was in there. Yay for Stu. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Sat, 12 Jun 2004 18:36:05 +0000
parents 3a5f2fcab7f6
children 227d3d6c6565
files src/protocols/silc/buddy.c src/protocols/silc/chat.c src/protocols/silc/ops.c src/protocols/silc/silc.c src/protocols/silc/silcgaim.h src/protocols/silc/util.c
diffstat 6 files changed, 370 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/silc/buddy.c	Sat Jun 12 17:34:59 2004 +0000
+++ b/src/protocols/silc/buddy.c	Sat Jun 12 18:36:05 2004 +0000
@@ -1471,23 +1471,23 @@
 	  return NULL;
 
 	if (client_entry->nickname)
-	  g_string_append_printf(s, "<b>%s:</b> %s\n", _("Nickname"),
+	  g_string_append_printf(s, "\n<b>%s:</b> %s", _("Nickname"),
 				 client_entry->nickname);
 	if (client_entry->username && client_entry->hostname)
-	  g_string_append_printf(s, "<b>%s:</b> %s@%s\n", _("Username"),
+	  g_string_append_printf(s, "\n<b>%s:</b> %s@%s", _("Username"),
 				 client_entry->username, client_entry->hostname);
 	if (client_entry->mode) {
-	  g_string_append_printf(s, "<b>%s:</b> ", _("Modes"));
+	  g_string_append_printf(s, "\n<b>%s:</b> ", _("Modes"));
 	  memset(tmp, 0, sizeof(tmp));
 	  silcgaim_get_umode_string(client_entry->mode,
 				    tmp, sizeof(tmp) - strlen(tmp));
-	  g_string_append_printf(s, "%s\n", tmp);
+	  g_string_append_printf(s, "%s", tmp);
 	}
 
 	attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_MOOD);
 	if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) {
 		if (mood)
-			g_string_append_printf(s, "<b>%s:</b> ", _("Mood"));
+			g_string_append_printf(s, "\n<b>%s:</b> ", _("Mood"));
 		if (mood & SILC_ATTRIBUTE_MOOD_HAPPY)
 			g_string_append_printf(s, "[%s] ", _("Happy"));
 		if (mood & SILC_ATTRIBUTE_MOOD_SAD)
@@ -1510,19 +1510,17 @@
 			g_string_append_printf(s, "[%s] ", _("Excited"));
 		if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS)
 			g_string_append_printf(s, "[%s] ", _("Anxious"));
-		if (mood)
-			g_string_append_printf(s, "\n");
 	}
 
 	attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_FREETEXT);
 	memset(tmp, 0, sizeof(tmp));
 	if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
-		g_string_append_printf(s, "<b>%s:</b> %s\n", _("Status Text"), tmp);
+		g_string_append_printf(s, "\n<b>%s:</b> %s", _("Status Text"), tmp);
 
 	attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT);
 	if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) {
 		if (contact)
-			g_string_append_printf(s, "<b>%s:</b> ", _("Preferred Contact"));
+			g_string_append_printf(s, "\n<b>%s:</b> ", _("Preferred Contact"));
 		if (contact & SILC_ATTRIBUTE_CONTACT_CHAT)
 			g_string_append_printf(s, "[%s] ", _("Chat"));
 		if (contact & SILC_ATTRIBUTE_CONTACT_EMAIL)
@@ -1537,18 +1535,17 @@
 			g_string_append_printf(s, "[%s] ", _("MMS"));
 		if (contact & SILC_ATTRIBUTE_CONTACT_VIDEO)
 			g_string_append_printf(s, "[%s] ", _("Video Conferencing"));
-		g_string_append_printf(s, "\n");
 	}
 
 	attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE);
 	memset(tmp, 0, sizeof(tmp));
 	if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
-		g_string_append_printf(s, "<b>%s:</b> %s\n", _("Preferred Language"), tmp);
+		g_string_append_printf(s, "\n<b>%s:</b> %s", _("Preferred Language"), tmp);
 
 	attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_DEVICE_INFO);
 	memset(&device, 0, sizeof(device));
 	if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) {
-		g_string_append_printf(s, "<b>%s:</b> ", _("Device"));
+		g_string_append_printf(s, "\n<b>%s:</b> ", _("Device"));
 		if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER)
 		    g_string_append_printf(s, "%s: ", _("Computer"));
 		if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE)
@@ -1557,7 +1554,7 @@
 		    g_string_append_printf(s, "%s: ", _("PDA"));
 		if (device.type == SILC_ATTRIBUTE_DEVICE_TERMINAL)
 		    g_string_append_printf(s, "%s: ", _("Terminal"));
-		g_string_append_printf(s, "%s %s %s %s\n",
+		g_string_append_printf(s, "%s %s %s %s",
 				       device.manufacturer ? device.manufacturer : "",
 				       device.version ? device.version : "",
 				       device.model ? device.model : "",
@@ -1567,12 +1564,12 @@
 	attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_TIMEZONE);
 	memset(tmp, 0, sizeof(tmp));
 	if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp)))
-		g_string_append_printf(s, "<b>%s:</b> %s\n", _("Timezone"), tmp);
+		g_string_append_printf(s, "\n<b>%s:</b> %s", _("Timezone"), tmp);
 
 	attr = silcgaim_get_attr(client_entry->attrs, SILC_ATTRIBUTE_GEOLOCATION);
 	memset(&geo, 0, sizeof(geo));
 	if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo)))
-		g_string_append_printf(s, "<b>%s:</b> %s %s %s (%s)\n",
+		g_string_append_printf(s, "\n<b>%s:</b> %s %s %s (%s)",
 				       _("Geolocation"),
 				       geo.longitude ? geo.longitude : "",
 				       geo.latitude ? geo.latitude : "",
--- a/src/protocols/silc/chat.c	Sat Jun 12 17:34:59 2004 +0000
+++ b/src/protocols/silc/chat.c	Sat Jun 12 18:36:05 2004 +0000
@@ -161,7 +161,8 @@
 static void
 silcgaim_chat_getinfo_menu(GaimBlistNode *node, gpointer data)
 {
-
+	GaimChat *chat = (GaimChat *)node;
+	silcgaim_chat_getinfo(chat->account->gc, chat->components);
 }
 
 
--- a/src/protocols/silc/ops.c	Sat Jun 12 17:34:59 2004 +0000
+++ b/src/protocols/silc/ops.c	Sat Jun 12 18:36:05 2004 +0000
@@ -653,7 +653,7 @@
 				/* Find buddy by nickname */
 				b = gaim_find_buddy(sg->account, client_entry->nickname);
 				if (!b) {
-					fprintf(stderr, "WATCH for %s, unknown buddy",
+					gaim_debug_warning("silc", "WATCH for %s, unknown buddy",
 						client_entry->nickname);
 					break;
 				}
--- a/src/protocols/silc/silc.c	Sat Jun 12 17:34:59 2004 +0000
+++ b/src/protocols/silc/silc.c	Sat Jun 12 18:36:05 2004 +0000
@@ -278,8 +278,8 @@
 	/* Load SILC key pair */
 	if (!silc_load_key_pair(gaim_prefs_get_string("/plugins/prpl/silc/pubkey"),
 				gaim_prefs_get_string("/plugins/prpl/silc/privkey"),
-				"", &client->pkcs, &client->public_key,
-				&client->private_key)) {
+				(account->password == NULL) ? "" : account->password, &client->pkcs,
+				&client->public_key, &client->private_key)) {
 		gaim_connection_error(gc, ("Could not load SILC key pair"));
 		return;
 	}
@@ -318,21 +318,21 @@
 }
 
 static void
-silcgaim_close_convos(GaimConversation *convo)
-{
-	if (convo)
-		gaim_conversation_destroy(convo);
-}
-
-static void
 silcgaim_close(GaimConnection *gc)
 {
+	GList *l;
+	GaimConversation *conv;
 	SilcGaim sg = gc->proto_data;
 	if (!sg)
 		return;
 
-	/* Close all conversations */
-	gaim_conversation_foreach(silcgaim_close_convos);
+	/* Close all conversations for this connection */
+	for (l = gaim_get_conversations(); l; l = l->next)
+	{
+		conv = l->data;
+		if (gc == conv->account->gc)
+			gaim_conversation_destroy(conv);
+	}
 
 	/* Send QUIT */
 	silc_client_command_call(sg->client, sg->conn, NULL,
@@ -729,6 +729,31 @@
 			      sg->motd, NULL, NULL);
 }
 
+static void
+silcgaim_change_pass(GaimPluginAction *action)
+{
+	GaimConnection *gc = (GaimConnection *) action->context;
+	gaim_account_request_change_password(gaim_connection_get_account(gc));
+}
+
+static void
+silcgaim_change_passwd(GaimConnection *gc, const char *old, const char *new)
+{
+	silc_change_private_key_passphrase(gaim_prefs_get_string("/plugins/prpl/silc/privkey"), old, new);
+}
+
+static void
+silcgaim_show_set_info(GaimPluginAction *action)
+{
+	GaimConnection *gc = (GaimConnection *) action->context;
+	gaim_account_request_change_user_info(gaim_connection_get_account(gc));
+}
+
+static void
+silcgaim_set_info(GaimConnection *gc, const char *text)
+{
+}
+
 static GList *
 silcgaim_actions(GaimPlugin *plugin, gpointer context)
 {
@@ -750,6 +775,14 @@
 			silcgaim_view_motd);
 	list = g_list_append(list, act);
 
+	act = gaim_plugin_action_new(_("Change Password..."),
+			silcgaim_change_pass);
+	list = g_list_append(list, act);
+
+	act = gaim_plugin_action_new(_("Set User Info..."),
+			silcgaim_show_set_info);
+	list = g_list_append(list, act);
+
 	return list;
 }
 
@@ -893,9 +926,283 @@
 	}	
 }
 
+/********************************* Commands **********************************/
+
+static GaimCmdRet silcgaim_cmd_chat_part(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	GaimConnection *gc;
+	int id = 0;
+
+	gc = gaim_conversation_get_gc(conv);
+	id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
+
+	if (gc == NULL || id == 0)
+		return GAIM_CMD_RET_FAILED;
+
+	silcgaim_chat_leave(gc, id);
+
+	return GAIM_CMD_RET_OK;
+
+}
+
+static GaimCmdRet silcgaim_cmd_chat_topic(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	GaimConnection *gc;
+	int id = 0;
+
+	gc = gaim_conversation_get_gc(conv);
+	id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
+
+	if (gc == NULL || id == 0)
+		return GAIM_CMD_RET_FAILED;
+
+	silcgaim_chat_set_topic(gc, id, args ? args[0] : NULL);
+
+	return GAIM_CMD_RET_OK;
+}
+
+static GaimCmdRet silcgaim_cmd_chat_join(GaimConversation *conv,
+        const char *cmd, char **args, char **error)
+{
+	GHashTable *comp;
+
+	if(!args || !args[0])
+		return GAIM_CMD_RET_FAILED;
+
+	comp = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+
+	g_hash_table_replace(comp, "channel", args[0]);
+	if(args[1])
+		g_hash_table_replace(comp, "passphrase", args[1]);
+
+	silcgaim_chat_join(gaim_conversation_get_gc(conv), comp);
+
+	g_hash_table_destroy(comp);
+	return GAIM_CMD_RET_OK;
+}
+
+static GaimCmdRet silcgaim_cmd_chat_list(GaimConversation *conv,
+        const char *cmd, char **args, char **error)
+{
+	GaimConnection *gc;
+	gc = gaim_conversation_get_gc(conv);
+	gaim_roomlist_show_with_account(gaim_connection_get_account(gc));
+	return GAIM_CMD_RET_OK;
+}
+
+static GaimCmdRet silcgaim_cmd_whois(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	GaimConnection *gc;
+
+	gc = gaim_conversation_get_gc(conv);
+
+	if (gc == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	silcgaim_get_info(gc, args[0]);
+
+	return GAIM_CMD_RET_OK;
+}
+
+static GaimCmdRet silcgaim_cmd_chat_invite(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	int id;
+	GaimConnection *gc;
+
+	id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
+	gc = gaim_conversation_get_gc(conv);
+
+	if (gc == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	silcgaim_chat_invite(gc, id, NULL, args[0]);
+
+	return GAIM_CMD_RET_OK;
+}
+
+static GaimCmdRet silcgaim_cmd_msg(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	int ret;
+	GaimConnection *gc;
+
+	gc = gaim_conversation_get_gc(conv);
+
+	if (gc == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	ret = silcgaim_send_im(gc, args[0], args[1], GAIM_MESSAGE_SEND);
+
+	if (ret)
+		return GAIM_CMD_RET_OK;
+	else
+		return GAIM_CMD_RET_FAILED;
+}
+
+static GaimCmdRet silcgaim_cmd_query(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	int ret = 1;
+	GaimConversation *convo;
+	GaimConnection *gc;
+	GaimAccount *account;
+
+	if (!args || !args[0])
+		return GAIM_CMD_RET_FAILED;
+
+	gc = gaim_conversation_get_gc(conv);
+
+	if (gc == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	account = gaim_connection_get_account(gc);
+
+	convo = gaim_conversation_new(GAIM_CONV_IM, account, args[0]);
+
+	if (args[1]) {
+		ret = silcgaim_send_im(gc, args[0], args[1], GAIM_MESSAGE_SEND);
+		gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc),
+				args[1], GAIM_MESSAGE_SEND, time(NULL));
+	}
+
+	if (ret)
+		return GAIM_CMD_RET_OK;
+	else
+		return GAIM_CMD_RET_FAILED;
+}
+
+static GaimCmdRet silcgaim_cmd_motd(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	GaimConnection *gc;
+	SilcGaim sg;
+
+	gc = gaim_conversation_get_gc(conv);
+
+	if (gc == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	sg = gc->proto_data;
+
+	if (sg == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	if (!sg->motd) {
+		gaim_notify_error(
+				gc, _("Message of the Day"), _("No Message of the Day available"),
+				_("There is no Message of the Day associated with this connection"));
+		return GAIM_CMD_RET_FAILED;
+	}
+
+	gaim_notify_formatted(gc, _("Message of the Day"), _("Message of the Day"), NULL,
+			sg->motd, NULL, NULL);
+
+	return GAIM_CMD_RET_OK;
+}
+
+static GaimCmdRet silcgaim_cmd_detach(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	GaimConnection *gc;
+	SilcGaim sg;
+
+	gc = gaim_conversation_get_gc(conv);
+
+	if (gc == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	sg = gc->proto_data;
+
+	if (sg == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	silc_client_command_call(sg->client, sg->conn, "DETACH");
+	sg->detaching = TRUE;
+
+	return GAIM_CMD_RET_OK;
+}
+
+static GaimCmdRet silcgaim_cmd_umode(GaimConversation *conv,
+		const char *cmd, char **args, char **error)
+{
+	GaimConnection *gc;
+	SilcGaim sg;
+
+	gc = gaim_conversation_get_gc(conv);
+
+	if (gc == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	sg = gc->proto_data;
+
+	if (sg == NULL)
+		return GAIM_CMD_RET_FAILED;
+
+	silc_client_command_call(sg->client, sg->conn, NULL, "UMODE",
+			args[0], NULL);
+
+	return GAIM_CMD_RET_OK;
+}
+
 
 /************************** Plugin Initialization ****************************/
 
+static void
+silcgaim_register_commands(void)
+{
+	gaim_cmd_register("part", "", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
+			"prpl-silc", silcgaim_cmd_chat_part, _("part:  Leave the chat"));
+	gaim_cmd_register("leave", "", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
+			"prpl-silc", silcgaim_cmd_chat_part, _("leave:  Leave the chat"));
+	gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
+			GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc",
+			silcgaim_cmd_chat_topic, _("topic [&lt;new topic&gt;]:  View or change the topic"));
+	gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT |
+			GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS,
+			"prpl-silc", silcgaim_cmd_chat_join,
+			_("join &lt;channel&gt; [&lt;password&gt;]:  Join a chat on this network"));
+	gaim_cmd_register("list", "", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
+			GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc",
+			silcgaim_cmd_chat_list, _("list:  List channels on this network"));
+	gaim_cmd_register("whois", "w", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
+			"prpl-silc",
+			silcgaim_cmd_whois, _("whois &lt;nick&gt;:  View nick's informationc"));
+	gaim_cmd_register("invite", "w", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
+			"prpl-silc", silcgaim_cmd_chat_invite,
+			_("invite &lt;nick&gt;:  Invite nick to join this channel"));
+	gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
+			"prpl-silc", silcgaim_cmd_msg,
+			_("msg &lt;nick&gt; &lt;message&gt;:  Send a private message to a user"));
+	gaim_cmd_register("query", "ws", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
+			GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_query,
+			_("query &lt;nick&gt; [&lt;message&gt;]:  Send a private message to a user"));
+	gaim_cmd_register("motd", "", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
+			GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_motd,
+			_("motd:  View the server's Message Of The Day"));
+	gaim_cmd_register("detach", "", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
+			GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_detach,
+			_("detach:  Detach this session"));
+	gaim_cmd_register("umode", "w", GAIM_CMD_P_PRPL,
+			GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
+			"prpl-silc", silcgaim_cmd_umode,
+			_("umode &lt;usermodes&gt;:  Set your user options"));
+}
+
 static GaimPluginPrefFrame *
 silcgaim_pref_frame(GaimPlugin *plugin)
 {
@@ -968,12 +1275,12 @@
 	silcgaim_login,
 	silcgaim_close,
 	silcgaim_send_im,
-	NULL,
+	silcgaim_set_info,
 	NULL,
 	silcgaim_get_info,
 	silcgaim_set_away,
 	silcgaim_idle_set,
-	NULL,
+	silcgaim_change_passwd,
 	silcgaim_add_buddy,
 	silcgaim_add_buddies,
 	silcgaim_remove_buddy,
@@ -1094,6 +1401,8 @@
 	g_snprintf(tmp, sizeof(tmp), "%s/private_key.prv", silcgaim_silcdir());
 	gaim_prefs_add_string("/plugins/prpl/silc/privkey", tmp);
 	gaim_prefs_add_string("/plugins/prpl/silc/vcard", "");
+
+	silcgaim_register_commands();
 }
 
 GAIM_INIT_PLUGIN(silc, init_plugin, info);
--- a/src/protocols/silc/silcgaim.h	Sat Jun 12 17:34:59 2004 +0000
+++ b/src/protocols/silc/silcgaim.h	Sat Jun 12 18:36:05 2004 +0000
@@ -33,6 +33,7 @@
 #include "util.h"
 #include "roomlist.h"
 #include "ft.h"
+#include "cmds.h"
 
 /* Default public and private key file names */
 #define SILCGAIM_PUBLIC_KEY_NAME "public_key.pub"
--- a/src/protocols/silc/util.c	Sat Jun 12 17:34:59 2004 +0000
+++ b/src/protocols/silc/util.c	Sat Jun 12 18:36:05 2004 +0000
@@ -76,7 +76,7 @@
 
 	pw = getpwuid(getuid());
 	if (!pw) {
-		fprintf(stderr, "silc: %s\n", strerror(errno));
+		gaim_debug_error("silc", "silc: %s\n", strerror(errno));
 		return FALSE;
 	}
 
@@ -96,22 +96,22 @@
 		if (errno == ENOENT) {
 			if (pw->pw_uid == geteuid()) {
 				if ((mkdir(filename, 0755)) == -1) {
-					fprintf(stderr, "Couldn't create `%s' directory\n", filename);
+					gaim_debug_error("silc", "Couldn't create '%s' directory\n", filename);
 					return FALSE;
 				}
 			} else {
-				fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n",
+				gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n",
 					filename);
 				return FALSE;
 			}
 		} else {
-			fprintf(stderr, "%s\n", strerror(errno));
+			gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, strerror(errno));
 			return FALSE;
 		}
 	} else {
 		/* Check the owner of the dir */
 		if (st.st_uid != 0 && st.st_uid != pw->pw_uid) {
-			fprintf(stderr, "You don't seem to own `%s' directory\n",
+			gaim_debug_error("silc", "You don't seem to own '%s' directory\n",
 				filename);
 			return FALSE;
 		}
@@ -125,16 +125,17 @@
 		if (errno == ENOENT) {
 			if (pw->pw_uid == geteuid()) {
 				if ((mkdir(servfilename, 0755)) == -1) {
-					fprintf(stderr, "Couldn't create `%s' directory\n", servfilename);
+					gaim_debug_error("silc", "Couldn't create '%s' directory\n", servfilename);
 					return FALSE;
 				}
 			} else {
-				fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n",
+				gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n",
 					servfilename);
 				return FALSE;
 			}
 		} else {
-			fprintf(stderr, "%s\n", strerror(errno));
+			gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n",
+							 servfilename, strerror(errno));
 			return FALSE;
 		}
 	}
@@ -147,16 +148,17 @@
 		if (errno == ENOENT) {
 			if (pw->pw_uid == geteuid()) {
 				if ((mkdir(clientfilename, 0755)) == -1) {
-					fprintf(stderr, "Couldn't create `%s' directory\n", clientfilename);
+					gaim_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename);
 					return FALSE;
 				}
 			} else {
-				fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n",
+				gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n",
 					clientfilename);
 				return FALSE;
 			}
 		} else {
-			fprintf(stderr, "%s\n", strerror(errno));
+			gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n",
+							 clientfilename, strerror(errno));
 			return FALSE;
 		}
 	}
@@ -169,16 +171,17 @@
 		if (errno == ENOENT) {
 			if (pw->pw_uid == geteuid()) {
 				if ((mkdir(friendsfilename, 0755)) == -1) {
-					fprintf(stderr, "Couldn't create `%s' directory\n", friendsfilename);
+					gaim_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename);
 					return FALSE;
 				}
 			} else {
-				fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n",
+				gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n",
 					friendsfilename);
 				return FALSE;
 			}
 		} else {
-			fprintf(stderr, "%s\n", strerror(errno));
+			gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n",
+							 friendsfilename, strerror(errno));
 			return FALSE;
 		}
 	}
@@ -198,16 +201,19 @@
 			silc_create_key_pair(SILCGAIM_DEF_PKCS,
 					     SILCGAIM_DEF_PKCS_LEN,
 					     file_public_key, file_private_key, NULL,
-					     "", NULL, NULL, NULL, FALSE);
+					     (gc->account->password == NULL) ? "" : gc->account->password,
+						 NULL, NULL, NULL, FALSE);
+			stat(file_public_key, &st);
 		} else {
-			fprintf(stderr, "%s\n", strerror(errno));
+			gaim_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n",
+							 file_public_key, strerror(errno));
 			return FALSE;
 		}
 	}
 
 	/* Check the owner of the public key */
 	if (st.st_uid != 0 && st.st_uid != pw->pw_uid) {
-		fprintf(stderr, "You don't seem to own your public key!?\n");
+		gaim_debug_error("silc", "You don't seem to own your public key!?\n");
 		return FALSE;
 	}
 
@@ -218,30 +224,33 @@
 			silc_create_key_pair(SILCGAIM_DEF_PKCS,
 					     SILCGAIM_DEF_PKCS_LEN,
 					     file_public_key, file_private_key, NULL,
-					     "", NULL, NULL, NULL, FALSE);
+					     (gc->account->password == NULL) ? "" : gc->account->password,
+						 NULL, NULL, NULL, FALSE);
+			stat(file_private_key, &st);
 		} else {
-			fprintf(stderr, "%s\n", strerror(errno));
+			gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n",
+							 file_private_key, strerror(errno));
 			return FALSE;
 		}
 	}
 
 	/* Check the owner of the private key */
 	if (st.st_uid != 0 && st.st_uid != pw->pw_uid) {
-		fprintf(stderr, "You don't seem to own your private key!?\n");
+		gaim_debug_error("silc", "You don't seem to own your private key!?\n");
 		return FALSE;
 	}
 
 	/* Check the permissions for the private key */
 	if ((st.st_mode & 0777) != 0600) {
-		fprintf(stderr, "Wrong permissions in your private key file `%s'!\n"
+		gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n"
 			"Trying to change them ... ", file_private_key);
 		if ((chmod(file_private_key, 0600)) == -1) {
-			fprintf(stderr,
+			gaim_debug_error("silc",
 				"Failed to change permissions for private key file!\n"
 				"Permissions for your private key file must be 0600.\n");
 			return FALSE;
 		}
-		fprintf(stderr, "Done.\n\n");
+		gaim_debug_warning("silc", "Done.\n\n");
 	}
 
 	return TRUE;