From 1917a1ec17dde7c159af5ec65d6455c3348bb250 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 30 Aug 2008 20:43:38 +0100 Subject: Added support for loading chatroom data from user .xml files. --- storage_xml.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index 8b205c5a..d8c5ffb7 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -28,7 +28,6 @@ #include "base64.h" #include "arc.h" #include "md5.h" -#include #if GLIB_CHECK_VERSION(2,8,0) #include @@ -54,6 +53,8 @@ struct xml_parsedata irc_t *irc; char *current_setting; account_t *current_account; + struct chat *current_chat; + set_t **current_set_head; char *given_nick; char *given_pass; xml_pass_st pass_st; @@ -172,7 +173,16 @@ 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 ) + xd->current_set_head = &xd->current_account->set; + else + xd->current_set_head = &xd->irc->set; + xd->current_setting = g_strdup( setting ); + } else g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Missing attributes for %s element", element_name ); @@ -194,6 +204,23 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na "Missing attributes for %s element", element_name ); } } + else if( g_strcasecmp( element_name, "chat" ) == 0 ) + { + char *handle, *channel; + + handle = xml_attr( attr_names, attr_values, "handle" ); + channel = xml_attr( attr_names, attr_values, "channel" ); + + if( xd->current_account && handle && channel ) + { + xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel ); + } + else + { + g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "Missing attributes for %s element", element_name ); + } + } else { g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, @@ -214,13 +241,16 @@ static void xml_end_element( GMarkupParseContext *ctx, const gchar *element_name { xd->current_account = NULL; } + else if( g_strcasecmp( element_name, "chat" ) == 0 ) + { + xd->current_chat = NULL; + } } static void xml_text( GMarkupParseContext *ctx, const gchar *text_orig, gsize text_len, gpointer data, GError **error ) { char text[text_len+1]; struct xml_parsedata *xd = data; - irc_t *irc = xd->irc; strncpy( text, text_orig, text_len ); text[text_len] = 0; @@ -233,8 +263,7 @@ static void xml_text( GMarkupParseContext *ctx, const gchar *text_orig, gsize te } else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting ) { - set_setstr( xd->current_account ? &xd->current_account->set : &irc->set, - xd->current_setting, (char*) text ); + set_setstr( xd->current_set_head, xd->current_setting, (char*) text ); g_free( xd->current_setting ); xd->current_setting = NULL; } -- cgit v1.2.3 From b84800d89604dee6fd837a2b8ab549346607e774 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 30 Aug 2008 22:30:13 +0100 Subject: Support for saving the chatroom list. Also removed the hack that was used to not save non-existent settings now that those simply aren't possible anymore. --- storage_xml.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index d8c5ffb7..240bb589 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -437,7 +437,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) g_free( pass_buf ); for( set = irc->set; set; set = set->next ) - if( set->value && set->def ) + if( set->value ) if( !xml_printf( fd, 1, "%s\n", set->key, set->value ) ) goto write_error; @@ -446,6 +446,7 @@ 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 ); @@ -464,7 +465,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) goto write_error; for( set = acc->set; set; set = set->next ) - if( set->value && set->def && !( set->flags & ACC_SET_NOSAVE ) ) + if( set->value && !( set->flags & ACC_SET_NOSAVE ) ) if( !xml_printf( fd, 2, "%s\n", set->key, set->value ) ) goto write_error; @@ -478,6 +479,25 @@ 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, "\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; + } + if( !xml_printf( fd, 1, "\n" ) ) goto write_error; } -- cgit v1.2.3