From 1f92a5851e0e3b1730e940980f2b0122c506c724 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 10 Apr 2010 03:27:50 +0100 Subject: Restore the storage module. --- storage_xml.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index b6745c75..b81e1d0c 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -146,7 +146,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,7 +180,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na 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 ); } @@ -214,7 +214,7 @@ 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 ); + //xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel ); } else { @@ -352,7 +352,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 ) @@ -395,7 +395,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) md5_byte_t pass_md5[21]; md5_state_t md5_state; - 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 ); @@ -421,17 +421,17 @@ 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, "\n", irc->nick, pass_buf, XML_FORMAT_VERSION ) ) + if( !xml_printf( fd, 0, "\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, "%s\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; @@ -469,6 +469,7 @@ 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; +#if 0 for( c = irc->chatrooms; c; c = c->next ) { if( c->acc != acc ) @@ -487,6 +488,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) if( !xml_printf( fd, 2, "\n" ) ) goto write_error; } +#endif if( !xml_printf( fd, 1, "\n" ) ) goto write_error; -- cgit v1.2.3 From 84c3a72604a292c41348d678eccf1875263cb8dd Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 27 Jun 2010 13:39:07 +0100 Subject: Import chatrooms configured in older BitlBee versions. Settings are currently ignored though. Also removing the old chat.[ch] files since they're really not important anymore. --- storage_xml.c | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index 3ce85713..73d77ade 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 @@ -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; @@ -175,9 +174,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; - else if( xd->current_account != NULL ) + else + */ + if( xd->current_account != NULL ) xd->current_set_head = &xd->current_account->set; else xd->current_set_head = &xd->irc->b->set; @@ -214,7 +216,24 @@ 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, "chat_type", "room" ) && + set_setstr( &ic->set, "account", acc ) && + set_setstr( &ic->set, "room", handle ) ) + { + /* Nothing else to do for now, really. */ + } + else if( ic ) + irc_channel_free( ic ); + + g_free( acc ); } else { @@ -244,7 +263,7 @@ static void xml_end_element( GMarkupParseContext *ctx, const gchar *element_name } else if( g_strcasecmp( element_name, "chat" ) == 0 ) { - xd->current_chat = NULL; + /* xd->current_chat = NULL; */ } } @@ -436,7 +455,6 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) 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 ); @@ -469,27 +487,6 @@ 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; -#if 0 - for( c = irc->chatrooms; c; c = c->next ) - { - if( c->acc != acc ) - continue; - - if( !xml_printf( fd, 2, "\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, "%s\n", - set->key, set->value ) ) - goto write_error; - - if( !xml_printf( fd, 2, "\n" ) ) - goto write_error; - } -#endif - if( !xml_printf( fd, 1, "\n" ) ) goto write_error; } -- cgit v1.2.3 From 547ea687b733113e06d7b941096b60632ac24de9 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 27 Jun 2010 16:32:12 +0100 Subject: Save and load channels. Also fixing a bug in creating non-control channels with a &-name. --- storage_xml.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index 73d77ade..d20469af 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -174,12 +174,9 @@ 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; - else - */ - if( xd->current_account != NULL ) + 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->b->set; @@ -207,6 +204,26 @@ 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; + } + + 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; @@ -224,11 +241,13 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na 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 ) ) { - /* Nothing else to do for now, really. */ + /* Try to pick up some settings where possible. */ + xd->current_channel = ic; } else if( ic ) irc_channel_free( ic ); @@ -261,9 +280,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; } } @@ -413,6 +433,7 @@ 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->user->nick ); nick_lc( path2 ); @@ -491,6 +512,23 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) goto write_error; } + for( l = irc->channels; l; l = l->next ) + { + irc_channel_t *ic = l->data; + + if( !xml_printf( fd, 1, "\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, "%s\n", set->key, set->value ) ) + goto write_error; + + if( !xml_printf( fd, 1, "\n" ) ) + goto write_error; + } + if( !xml_printf( fd, 0, "\n" ) ) goto write_error; -- cgit v1.2.3 From 1c40aa73b52e4507404c82056170069a859fb0cb Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 28 Jun 2010 01:07:46 +0100 Subject: Mark nameless groupchat channels as temporary so they don't stick around forever. --- storage_xml.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index d20469af..f97b2cd5 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -516,6 +516,9 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) { irc_channel_t *ic = l->data; + if( ic->flags & IRC_CHANNEL_TEMP ) + continue; + if( !xml_printf( fd, 1, "\n", ic->name, set_getstr( &ic->set, "type" ) ) ) goto write_error; -- cgit v1.2.3 From 7a6ba50d4824c4e33ebf1154e97038c9331f4f58 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 30 Jun 2010 00:44:17 +0100 Subject: Also allow selecting contacts for a channel by protocol instead of account. If someone has two MSN accts and wants contacts from both in one channel, this is now possible. --- storage_xml.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index f97b2cd5..a60769bb 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -218,6 +218,10 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na 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 ); -- cgit v1.2.3 From b1f818bcbd50eccd416127ed68346616295f54cd Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 11 Jul 2010 13:21:59 +0100 Subject: Use bee_user structs in all nick_* functions. Prepare for a nick_get() with more flexible nickname generation. --- storage_xml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index a60769bb..7a10cea7 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -196,7 +196,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 { -- cgit v1.2.3 From e135cd0997fb88ae644e63b6b7457ba08a60661a Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 24 Jul 2010 17:58:27 +0200 Subject: Use the account tag in a few places and store it in the XML file as an attribute, not as a setting (since all accounts have it anyway). --- storage_xml.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index db72025d..1d6757ae 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -126,7 +126,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na } else if( g_strcasecmp( element_name, "account" ) == 0 ) { - char *protocol, *handle, *server, *password = NULL, *autoconnect; + char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag; char *pass_b64 = NULL; unsigned char *pass_cr = NULL; int pass_len; @@ -136,6 +136,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na pass_b64 = xml_attr( attr_names, attr_values, "password" ); server = xml_attr( attr_names, attr_values, "server" ); autoconnect = xml_attr( attr_names, attr_values, "autoconnect" ); + tag = xml_attr( attr_names, attr_values, "tag" ); protocol = xml_attr( attr_names, attr_values, "protocol" ); if( protocol ) @@ -155,6 +156,8 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na set_setstr( &xd->current_account->set, "server", server ); if( autoconnect ) set_setstr( &xd->current_account->set, "auto_connect", autoconnect ); + if( tag ) + set_setstr( &xd->current_account->set, "tag", tag ); } else { @@ -243,16 +246,11 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na if( 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, "account", xd->current_account->tag ) && set_setstr( &ic->set, "room", handle ) ) { /* Try to pick up some settings where possible. */ @@ -260,8 +258,6 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na } else if( ic ) irc_channel_free( ic ); - - g_free( acc ); } else { @@ -501,7 +497,9 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) pass_b64 = base64_encode( pass_cr, pass_len ); g_free( pass_cr ); - if( !xml_printf( fd, 1, "prpl->name, acc->user, pass_b64, acc->auto_connect ) ) + if( !xml_printf( fd, 1, "prpl->name, acc->user, + pass_b64, acc->auto_connect, acc->tag ) ) { g_free( pass_b64 ); goto write_error; -- cgit v1.2.3