Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    r823de9d rb75acf6  
    2929#include "arc.h"
    3030#include "md5.h"
     31#include "chat.h"
    3132
    3233#if GLIB_CHECK_VERSION(2,8,0)
     
    3839#endif
    3940
    40 #if !GLIB_CHECK_VERSION(2,8,0)
    41 /* GLib < 2.8.0 doesn't have g_access, so just use the system access(). */
    42 #define g_access access
    43 #endif
    44 
    4541typedef enum
    4642{
     
    5955        char *current_setting;
    6056        account_t *current_account;
     57        struct chat *current_chat;
     58        set_t **current_set_head;
    6159        char *given_nick;
    6260        char *given_pass;
     
    177175               
    178176                if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) )
     177                {
     178                        if( xd->current_chat != NULL )
     179                                xd->current_set_head = &xd->current_chat->set;
     180                        else if( xd->current_account != NULL )
     181                                xd->current_set_head = &xd->current_account->set;
     182                        else
     183                                xd->current_set_head = &xd->irc->set;
     184                       
    179185                        xd->current_setting = g_strdup( setting );
     186                }
    180187                else
    181188                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
     
    199206                }
    200207        }
     208        else if( g_strcasecmp( element_name, "chat" ) == 0 )
     209        {
     210                char *handle, *channel;
     211               
     212                handle = xml_attr( attr_names, attr_values, "handle" );
     213                channel = xml_attr( attr_names, attr_values, "channel" );
     214               
     215                if( xd->current_account && handle && channel )
     216                {
     217                        xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel );
     218                }
     219                else
     220                {
     221                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
     222                                     "Missing attributes for %s element", element_name );
     223                }
     224        }
    201225        else
    202226        {
     
    219243                xd->current_account = NULL;
    220244        }
     245        else if( g_strcasecmp( element_name, "chat" ) == 0 )
     246        {
     247                xd->current_chat = NULL;
     248        }
    221249}
    222250
     
    225253        char text[text_len+1];
    226254        struct xml_parsedata *xd = data;
    227         irc_t *irc = xd->irc;
    228255       
    229256        strncpy( text, text_orig, text_len );
     
    238265        else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting )
    239266        {
    240                 set_setstr( xd->current_account ? &xd->current_account->set : &irc->set,
    241                             xd->current_setting, (char*) text );
     267                set_setstr( xd->current_set_head, xd->current_setting, (char*) text );
    242268                g_free( xd->current_setting );
    243269                xd->current_setting = NULL;
     
    402428       
    403429        for( set = irc->set; set; set = set->next )
    404                 if( set->value && set->def )
     430                if( set->value )
    405431                        if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    406432                                goto write_error;
     
    411437                char *pass_b64;
    412438                int pass_len;
     439                struct chat *c;
    413440               
    414441                pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 );
     
    429456               
    430457                for( set = acc->set; set; set = set->next )
    431                         if( set->value && set->def && !( set->flags & ACC_SET_NOSAVE ) )
     458                        if( set->value && !( set->flags & ACC_SET_NOSAVE ) )
    432459                                if( !xml_printf( fd, 2, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    433460                                        goto write_error;
     
    443470                        goto write_error;
    444471               
     472                for( c = irc->chatrooms; c; c = c->next )
     473                {
     474                        if( c->acc != acc )
     475                                continue;
     476                       
     477                        if( !xml_printf( fd, 2, "<chat handle=\"%s\" channel=\"%s\" type=\"%s\">\n",
     478                                                c->handle, c->channel, "room" ) )
     479                                goto write_error;
     480                       
     481                        for( set = c->set; set; set = set->next )
     482                                if( set->value && !( set->flags & ACC_SET_NOSAVE ) )
     483                                        if( !xml_printf( fd, 3, "<setting name=\"%s\">%s</setting>\n",
     484                                                                set->key, set->value ) )
     485                                                goto write_error;
     486
     487                        if( !xml_printf( fd, 2, "</chat>\n" ) )
     488                                goto write_error;
     489                }
     490               
    445491                if( !xml_printf( fd, 1, "</account>\n" ) )
    446492                        goto write_error;
Note: See TracChangeset for help on using the changeset viewer.