aboutsummaryrefslogtreecommitdiffstats
path: root/storage_xml.c
diff options
context:
space:
mode:
authorSven Moritz Hallberg <pesco@khjk.org>2009-03-12 20:33:28 +0100
committerSven Moritz Hallberg <pesco@khjk.org>2009-03-12 20:33:28 +0100
commit673a54c5a78afd1dd41b4cd8811df5ab65042583 (patch)
treebffaa961139ac2be20f0875ef0ed37c87d6b18a9 /storage_xml.c
parent823de9d44f262ea2364ac8ec6a1e18e0f7dab658 (diff)
parent9e768da723b4a770967efa0d4dcaf58ccef8917f (diff)
pretty blind try at merging in the latest trunk
Diffstat (limited to 'storage_xml.c')
-rw-r--r--storage_xml.c65
1 files changed, 55 insertions, 10 deletions
diff --git a/storage_xml.c b/storage_xml.c
index 09e2f328..b78c3661 100644
--- a/storage_xml.c
+++ b/storage_xml.c
@@ -37,11 +37,6 @@
#define g_access access
#endif
-#if !GLIB_CHECK_VERSION(2,8,0)
-/* GLib < 2.8.0 doesn't have g_access, so just use the system access(). */
-#define g_access access
-#endif
-
typedef enum
{
XML_PASS_CHECK_ONLY = -1,
@@ -58,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;
@@ -176,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 );
@@ -198,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,
@@ -218,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;
@@ -237,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;
}
@@ -401,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;
@@ -410,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 );
@@ -428,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;
@@ -442,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;
}