Index: irc.c
===================================================================
--- irc.c	(revision b0a33a50735d93e1414a2e6c2007884d756429a3)
+++ irc.c	(revision 0383943c38ee308805798974bfccbd3327369c6a)
@@ -33,8 +33,11 @@
 GSList *irc_connection_list = NULL;
 
-static char *passchange (irc_t *irc, void *set, char *value) 
-{
-	irc_setpass (irc, value);
-	return (NULL);
+static char *passchange( set_t *set, char *value )
+{
+	irc_t *irc = set->data;
+	
+	irc_setpass( irc, value );
+	irc_usermsg( irc, "Password successfully changed" );
+	return NULL;
 }
 
@@ -123,24 +126,24 @@
 	irc_connection_list = g_slist_append( irc_connection_list, irc );
 	
-	set_add( irc, "away_devoice", "true",  set_eval_away_devoice );
-	set_add( irc, "auto_connect", "true", set_eval_bool );
-	set_add( irc, "auto_reconnect", "false", set_eval_bool );
-	set_add( irc, "auto_reconnect_delay", "300", set_eval_int );
-	set_add( irc, "buddy_sendbuffer", "false", set_eval_bool );
-	set_add( irc, "buddy_sendbuffer_delay", "200", set_eval_int );
-	set_add( irc, "charset", "iso8859-1", set_eval_charset );
-	set_add( irc, "debug", "false", set_eval_bool );
-	set_add( irc, "default_target", "root", NULL );
-	set_add( irc, "display_namechanges", "false", set_eval_bool );
-	set_add( irc, "handle_unknown", "root", NULL );
-	set_add( irc, "lcnicks", "true", set_eval_bool );
-	set_add( irc, "ops", "both", set_eval_ops );
-	set_add( irc, "private", "true", set_eval_bool );
-	set_add( irc, "query_order", "lifo", NULL );
-	set_add( irc, "save_on_quit", "true", set_eval_bool );
-	set_add( irc, "strip_html", "true", NULL );
-	set_add( irc, "to_char", ": ", set_eval_to_char );
-	set_add( irc, "typing_notice", "false", set_eval_bool );
-	set_add( irc, "password", NULL, passchange);
+	set_add( &irc->set, "away_devoice", "true",  set_eval_away_devoice, irc );
+	set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );
+	set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc );
+	set_add( &irc->set, "auto_reconnect_delay", "300", set_eval_int, irc );
+	set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
+	set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
+	set_add( &irc->set, "charset", "iso8859-1", set_eval_charset, irc );
+	set_add( &irc->set, "debug", "false", set_eval_bool, irc );
+	set_add( &irc->set, "default_target", "root", NULL, irc );
+	set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc );
+	set_add( &irc->set, "handle_unknown", "root", NULL, irc );
+	set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc );
+	set_add( &irc->set, "ops", "both", set_eval_ops, irc );
+	set_add( &irc->set, "password", NULL, passchange, irc );
+	set_add( &irc->set, "private", "true", set_eval_bool, irc );
+	set_add( &irc->set, "query_order", "lifo", NULL, irc );
+	set_add( &irc->set, "save_on_quit", "true", set_eval_bool, irc );
+	set_add( &irc->set, "strip_html", "true", NULL, irc );
+	set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );
+	set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc );
 	
 	conf_loaddefaults( irc );
@@ -206,13 +209,11 @@
 void irc_free(irc_t * irc)
 {
-	account_t *account, *accounttmp;
+	account_t *account;
 	user_t *user, *usertmp;
-	nick_t *nick, *nicktmp;
 	help_t *helpnode, *helpnodetmp;
-	set_t *setnode, *setnodetmp;
 	
 	log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd );
 	
-	if( irc->status & USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) ) 
+	if( irc->status & USTATUS_IDENTIFIED && set_getbool( &irc->set, "save_on_quit" ) ) 
 		if( storage_save( irc, TRUE ) != STORAGE_OK )
 			irc_usermsg( irc, "Error while saving settings!" );
@@ -254,15 +255,9 @@
 		query_del(irc, irc->queries);
 	
-	if (irc->accounts != NULL) {
-		account = irc->accounts;
-		while (account != NULL) {
-			g_free(account->user);
-			g_free(account->pass);
-			g_free(account->server);
-			accounttmp = account;
-			account = account->next;
-			g_free(accounttmp);
-		}
-	}
+	while (irc->accounts)
+		account_del(irc, irc->accounts);
+	
+	while (irc->set)
+		set_del(&irc->set, irc->set->key);
 	
 	if (irc->users != NULL) {
@@ -289,15 +284,4 @@
 	g_hash_table_destroy(irc->watches);
 	
-	if (irc->nicks != NULL) {
-		nick = irc->nicks;
-		while (nick != NULL) {
-			g_free(nick->nick);
-			g_free(nick->handle);
-					
-			nicktmp = nick;
-			nick = nick->next;
-			g_free(nicktmp);
-		}
-	}
 	if (irc->help != NULL) {
 		helpnode = irc->help;
@@ -310,16 +294,4 @@
 		}
 	}
-	if (irc->set != NULL) {
-		setnode = irc->set;
-		while (setnode != NULL) {
-			g_free(setnode->key);
-			g_free(setnode->def);
-			g_free(setnode->value);
-			
-			setnodetmp = setnode;
-			setnode = setnode->next;
-			g_free(setnodetmp);
-		}
-	}
 	g_free(irc);
 	
@@ -332,9 +304,8 @@
 void irc_setpass (irc_t *irc, const char *pass) 
 {
-	if (irc->password) g_free (irc->password);
+	g_free (irc->password);
 	
 	if (pass) {
 		irc->password = g_strdup (pass);
-		irc_usermsg (irc, "Password successfully changed");
 	} else {
 		irc->password = NULL;
@@ -367,5 +338,5 @@
 			}
 			
-			if( ( cs = set_getstr( irc, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) )
+			if( ( cs = set_getstr( &irc->set, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) )
 			{
 				conv[IRC_MAX_LINE] = 0;
@@ -587,5 +558,5 @@
 	
 	strip_newlines( line );
-	if( ( cs = set_getstr( irc, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) )
+	if( ( cs = set_getstr( &irc->set, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) )
 	{
 		char conv[IRC_MAX_LINE+1];
@@ -655,5 +626,5 @@
 	char namelist[385] = "";
 	struct conversation *c = NULL;
-	char *ops = set_getstr( irc, "ops" );
+	char *ops = set_getstr( &irc->set, "ops" );
 	
 	/* RFCs say there is no error reply allowed on NAMES, so when the
@@ -670,5 +641,5 @@
 			}
 			
-			if( u->gc && !u->away && set_getint( irc, "away_devoice" ) )
+			if( u->gc && !u->away && set_getbool( &irc->set, "away_devoice" ) )
 				strcat( namelist, "+" );
 			else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
@@ -930,11 +901,11 @@
 {
 	char *nick, *s;
-	char reason[64];
+	char reason[128];
 	
 	if( u->gc && u->gc->flags & OPT_LOGGING_OUT )
 	{
-		if( u->gc->user->proto_opt[0][0] )
+		if( u->gc->acc->server )
 			g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost,
-			            u->gc->user->proto_opt[0] );
+			            u->gc->acc->server );
 		else if( ( s = strchr( u->gc->username, '@' ) ) )
 			g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost,
@@ -942,5 +913,5 @@
 		else
 			g_snprintf( reason, sizeof( reason ), "%s %s.%s", irc->myhost,
-			            u->gc->prpl->name, irc->myhost );
+			            u->gc->acc->prpl->name, irc->myhost );
 		
 		/* proto_opt might contain garbage after the : */
@@ -1018,5 +989,5 @@
 		else if( g_strncasecmp( s + 1, "TYPING", 6 ) == 0 )
 		{
-			if( u && u->gc && u->gc->prpl->send_typing && strlen( s ) >= 10 )
+			if( u && u->gc && u->gc->acc->prpl->send_typing && strlen( s ) >= 10 )
 			{
 				time_t current_typing_notice = time( NULL );
@@ -1024,5 +995,5 @@
 				if( current_typing_notice - u->last_typing_notice >= 5 )
 				{
-					u->gc->prpl->send_typing( u->gc, u->handle, s[8] == '1' );
+					u->gc->acc->prpl->send_typing( u->gc, u->handle, s[8] == '1' );
 					u->last_typing_notice = current_typing_notice;
 				}
@@ -1057,5 +1028,5 @@
 		}
 	}
-	else if( c && c->gc && c->gc->prpl )
+	else if( c && c->gc && c->gc->acc && c->gc->acc->prpl )
 	{
 		return( bim_chat_msg( c->gc, c->id, s ) );
@@ -1089,5 +1060,5 @@
 	if( !u || !u->gc ) return;
 	
-	if( set_getint( irc, "buddy_sendbuffer" ) && set_getint( irc, "buddy_sendbuffer_delay" ) > 0 )
+	if( set_getbool( &irc->set, "buddy_sendbuffer" ) && set_getint( &irc->set, "buddy_sendbuffer_delay" ) > 0 )
 	{
 		int delay;
@@ -1116,5 +1087,5 @@
 		strcat( u->sendbuf, "\n" );
 		
-		delay = set_getint( irc, "buddy_sendbuffer_delay" );
+		delay = set_getint( &irc->set, "buddy_sendbuffer_delay" );
 		if( delay <= 5 )
 			delay *= 1000;
@@ -1181,5 +1152,5 @@
 		int len = strlen( irc->nick) + 3;
 		prefix = g_new (char, len );
-		g_snprintf( prefix, len, "%s%s", irc->nick, set_getstr( irc, "to_char" ) );
+		g_snprintf( prefix, len, "%s%s", irc->nick, set_getstr( &irc->set, "to_char" ) );
 		prefix[len-1] = 0;
 	}
