From 5b52a4895e5a59ff6509f7771f4d8665737688c3 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 3 Jul 2006 23:22:45 +0200 Subject: Implemented per-account nick lists instead of per-protocol nick lists. nick_t is dead, instead nicks are just saves in a per-account_t GLib hash table. While doing this, the import_buddies command finally died and text_save() disappeared, because the old file format can't handle most of the new features in this branch anyway. Still have to implement support for the new nick lists in text_load()! --- storage_xml.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index 701d5144..b01f35d6 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( irc, handle, xd->current_account->prpl, nick ); + nick_set( xd->current_account, handle, nick ); } else { @@ -364,11 +364,12 @@ static int xml_printf( int fd, int indent, char *fmt, ... ) return len == 0; } +static gboolean xml_save_nick( gpointer key, gpointer value, gpointer data ); + static storage_status_t xml_save( irc_t *irc, int overwrite ) { char path[512], *path2, *pass_buf = NULL; set_t *set; - nick_t *nick; account_t *acc; int fd; md5_byte_t pass_md5[21]; @@ -439,10 +440,15 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) if( !xml_printf( fd, 2, "%s\n", set->key, set->value ) ) goto write_error; - for( nick = irc->nicks; nick; nick = nick->next ) - if( nick->proto == acc->prpl ) - if( !xml_printf( fd, 2, "\n", nick->handle, nick->nick ) ) - goto write_error; + /* This probably looks pretty strange. g_hash_table_foreach + is quite a PITA already (but it can't get much better in + C without using #define, I'm afraid), and since it + doesn't seem to be possible to abort the foreach on write + errors, so instead let's use the _find function and + return TRUE on write errors. Which means, if we found + something, there was an error. :-) */ + if( g_hash_table_find( acc->nicks, xml_save_nick, (gpointer) fd ) ) + goto write_error; if( !xml_printf( fd, 1, "\n" ) ) goto write_error; @@ -477,6 +483,11 @@ write_error: return STORAGE_OTHER_ERROR; } +static gboolean xml_save_nick( gpointer key, gpointer value, gpointer data ) +{ + return !xml_printf( (int) data, 2, "\n", key, value ); +} + static storage_status_t xml_remove( const char *nick, const char *password ) { char s[512]; -- cgit v1.2.3