diff options
Diffstat (limited to 'storage_xml.c')
| -rw-r--r-- | storage_xml.c | 114 | 
1 files changed, 79 insertions, 35 deletions
| diff --git a/storage_xml.c b/storage_xml.c index 7321637c..db72025d 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -28,7 +28,6 @@  #include "base64.h"  #include "arc.h"  #include "md5.h" -#include "chat.h"  #if GLIB_CHECK_VERSION(2,8,0)  #include <glib/gstdio.h> @@ -54,7 +53,7 @@ struct xml_parsedata  	irc_t *irc;  	char *current_setting;  	account_t *current_account; -	struct chat *current_chat; +	irc_channel_t *current_channel;  	set_t **current_set_head;  	char *given_nick;  	char *given_pass; @@ -151,7 +150,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na  		else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) &&  		                         arc_decode( pass_cr, pass_len, &password, xd->given_pass ) )  		{ -			xd->current_account = account_add( irc, prpl, handle, password ); +			xd->current_account = account_add( irc->b, prpl, handle, password );  			if( server )  				set_setstr( &xd->current_account->set, "server", server );  			if( autoconnect ) @@ -180,12 +179,12 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na  		if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) )  		{ -			if( xd->current_chat != NULL ) -				xd->current_set_head = &xd->current_chat->set; +			if( xd->current_channel != NULL ) +				xd->current_set_head = &xd->current_channel->set;  			else if( xd->current_account != NULL )  				xd->current_set_head = &xd->current_account->set;  			else -				xd->current_set_head = &xd->irc->set; +				xd->current_set_head = &xd->irc->b->set;  			xd->current_setting = g_strdup( setting );  		} @@ -202,7 +201,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na  		if( xd->current_account && handle && nick )  		{ -			nick_set( xd->current_account, handle, nick ); +			nick_set_raw( xd->current_account, handle, nick );  		}  		else  		{ @@ -210,6 +209,30 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na  			             "Missing attributes for %s element", element_name );  		}  	} +	else if( g_strcasecmp( element_name, "channel" ) == 0 ) +	{ +		char *name, *type; +		 +		name = xml_attr( attr_names, attr_values, "name" ); +		type = xml_attr( attr_names, attr_values, "type" ); +		 +		if( !name || !type ) +		{ +			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, +			             "Missing attributes for %s element", element_name ); +			return; +		} +		 +		/* The channel may exist already, for example if it's &bitlbee. +		   Also, it's possible that the user just reconnected and the +		   IRC client already rejoined all channels it was in. They +		   should still get the right settings. */ +		if( ( xd->current_channel = irc_channel_by_name( irc, name ) ) || +		    ( xd->current_channel = irc_channel_new( irc, name ) ) ) +			set_setstr( &xd->current_channel->set, "type", type ); +	} +	/* Backward compatibility: Keep this around for a while for people +	   switching from BitlBee 1.2.4+. */  	else if( g_strcasecmp( element_name, "chat" ) == 0 )  	{  		char *handle, *channel; @@ -219,7 +242,26 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na  		if( xd->current_account && handle && channel )  		{ -			xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel ); +			irc_channel_t *ic; +			char *acc; +			 +			acc = g_strdup_printf( "%s(%s)", +			                       xd->current_account->prpl->name, +			                       xd->current_account->user ); +			 +			if( ( ic = irc_channel_new( irc, channel ) ) && +			    set_setstr( &ic->set, "type", "chat" ) && +			    set_setstr( &ic->set, "chat_type", "room" ) && +			    set_setstr( &ic->set, "account", acc ) && +			    set_setstr( &ic->set, "room", handle ) ) +			{ +				/* Try to pick up some settings where possible. */ +				xd->current_channel = ic; +			} +			else if( ic ) +				irc_channel_free( ic ); +			 +			g_free( acc );  		}  		else  		{ @@ -258,9 +300,10 @@ static void xml_end_element( GMarkupParseContext *ctx, const gchar *element_name  	{  		xd->current_account = NULL;  	} -	else if( g_strcasecmp( element_name, "chat" ) == 0 ) +	else if( g_strcasecmp( element_name, "channel" ) == 0 || +	         g_strcasecmp( element_name, "chat" ) == 0 )  	{ -		xd->current_chat = NULL; +		xd->current_channel = NULL;  	}  } @@ -368,7 +411,7 @@ static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const ch  static storage_status_t xml_load( irc_t *irc, const char *password )  { -	return xml_load_real( irc, irc->nick, password, XML_PASS_UNKNOWN ); +	return xml_load_real( irc, irc->user->nick, password, XML_PASS_UNKNOWN );  }  static storage_status_t xml_check_pass( const char *my_nick, const char *password ) @@ -410,8 +453,9 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )  	int fd;  	md5_byte_t pass_md5[21];  	md5_state_t md5_state; +	GSList *l; -	path2 = g_strdup( irc->nick ); +	path2 = g_strdup( irc->user->nick );  	nick_lc( path2 );  	g_snprintf( path, sizeof( path ) - 2, "%s%s%s", global.conf->configdir, path2, ".xml" );  	g_free( path2 ); @@ -437,22 +481,21 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )  	/* Save the hash in base64-encoded form. */  	pass_buf = base64_encode( pass_md5, 21 ); -	if( !xml_printf( fd, 0, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->nick, pass_buf, XML_FORMAT_VERSION ) ) +	if( !xml_printf( fd, 0, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->user->nick, pass_buf, XML_FORMAT_VERSION ) )  		goto write_error;  	g_free( pass_buf ); -	for( set = irc->set; set; set = set->next ) +	for( set = irc->b->set; set; set = set->next )  		if( set->value )  			if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )  				goto write_error; -	for( acc = irc->accounts; acc; acc = acc->next ) +	for( acc = irc->b->accounts; acc; acc = acc->next )  	{  		unsigned char *pass_cr;  		char *pass_b64;  		int pass_len; -		struct chat *c;  		pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 );  		pass_b64 = base64_encode( pass_cr, pass_len ); @@ -485,29 +528,30 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )  		if( g_hash_table_find( acc->nicks, xml_save_nick, & fd ) )  			goto write_error; -		for( c = irc->chatrooms; c; c = c->next ) -		{ -			if( c->acc != acc ) -				continue; -			 -			if( !xml_printf( fd, 2, "<chat handle=\"%s\" channel=\"%s\" type=\"%s\">\n", -			                        c->handle, c->channel, "room" ) ) -				goto write_error; -			 -			for( set = c->set; set; set = set->next ) -				if( set->value && !( set->flags & ACC_SET_NOSAVE ) ) -					if( !xml_printf( fd, 3, "<setting name=\"%s\">%s</setting>\n", -					                        set->key, set->value ) ) -						goto write_error; - -			if( !xml_printf( fd, 2, "</chat>\n" ) ) -				goto write_error; -		} -		  		if( !xml_printf( fd, 1, "</account>\n" ) )  			goto write_error;  	} +	for( l = irc->channels; l; l = l->next ) +	{ +		irc_channel_t *ic = l->data; +		 +		if( ic->flags & IRC_CHANNEL_TEMP ) +			continue; +		 +		if( !xml_printf( fd, 1, "<channel name=\"%s\" type=\"%s\">\n", +		                 ic->name, set_getstr( &ic->set, "type" ) ) ) +			goto write_error; +		 +		for( set = ic->set; set; set = set->next ) +			if( set->value && strcmp( set->key, "type" ) != 0 ) +				if( !xml_printf( fd, 2, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) ) +					goto write_error; +		 +		if( !xml_printf( fd, 1, "</channel>\n" ) ) +			goto write_error; +	} +	  	if( !xml_printf( fd, 0, "</user>\n" ) )  		goto write_error; | 
