Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    r15d1469 rb75acf6  
    2929#include "arc.h"
    3030#include "md5.h"
     31#include "chat.h"
    3132
    3233#if GLIB_CHECK_VERSION(2,8,0)
     
    5455        char *current_setting;
    5556        account_t *current_account;
     57        struct chat *current_chat;
     58        set_t **current_set_head;
    5659        char *given_nick;
    5760        char *given_pass;
     
    172175               
    173176                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                       
    174185                        xd->current_setting = g_strdup( setting );
     186                }
    175187                else
    176188                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
     
    194206                }
    195207        }
     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        }
    196225        else
    197226        {
     
    214243                xd->current_account = NULL;
    215244        }
     245        else if( g_strcasecmp( element_name, "chat" ) == 0 )
     246        {
     247                xd->current_chat = NULL;
     248        }
    216249}
    217250
     
    220253        char text[text_len+1];
    221254        struct xml_parsedata *xd = data;
    222         irc_t *irc = xd->irc;
    223255       
    224256        strncpy( text, text_orig, text_len );
     
    233265        else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting )
    234266        {
    235                 set_setstr( xd->current_account ? &xd->current_account->set : &irc->set,
    236                             xd->current_setting, (char*) text );
     267                set_setstr( xd->current_set_head, xd->current_setting, (char*) text );
    237268                g_free( xd->current_setting );
    238269                xd->current_setting = NULL;
     
    397428       
    398429        for( set = irc->set; set; set = set->next )
    399                 if( set->value && set->def )
     430                if( set->value )
    400431                        if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    401432                                goto write_error;
     
    406437                char *pass_b64;
    407438                int pass_len;
     439                struct chat *c;
    408440               
    409441                pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 );
     
    424456               
    425457                for( set = acc->set; set; set = set->next )
    426                         if( set->value && set->def && !( set->flags & ACC_SET_NOSAVE ) )
     458                        if( set->value && !( set->flags & ACC_SET_NOSAVE ) )
    427459                                if( !xml_printf( fd, 2, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    428460                                        goto write_error;
     
    438470                        goto write_error;
    439471               
     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               
    440491                if( !xml_printf( fd, 1, "</account>\n" ) )
    441492                        goto write_error;
Note: See TracChangeset for help on using the changeset viewer.