aboutsummaryrefslogtreecommitdiffstats
path: root/storage_xml.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2009-10-17 18:24:52 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2009-10-17 18:24:52 +0100
commitc5bc47b3197d20ec2d73e3024b932db30dfa3533 (patch)
treec803b770edb779a331a7cf25a1c6fdad45450603 /storage_xml.c
parent0c41177b49c04893e0ce88dbb27f5f5b1aeb5896 (diff)
parent2e44b1f12fb58a6969a8fbaf2946d6ecdace484a (diff)
Merging BitlBee 1.2.4.
Diffstat (limited to 'storage_xml.c')
-rw-r--r--storage_xml.c60
1 files changed, 55 insertions, 5 deletions
diff --git a/storage_xml.c b/storage_xml.c
index d3d0f6d6..b78c3661 100644
--- a/storage_xml.c
+++ b/storage_xml.c
@@ -53,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;
@@ -171,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 );
@@ -193,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,
@@ -213,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;
@@ -232,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;
}
@@ -396,7 +426,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, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
goto write_error;
@@ -405,6 +435,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 );
@@ -423,7 +454,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, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
goto write_error;
@@ -437,6 +468,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, "<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;
}