Changeset 2288705 for storage_xml.c


Ignore:
Timestamp:
2009-12-07T21:54:19Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1c3008a
Parents:
aac4017 (diff), 36cf9fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging head.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    raac4017 r2288705  
    2929#include "arc.h"
    3030#include "md5.h"
     31#include "chat.h"
     32
     33#if GLIB_CHECK_VERSION(2,8,0)
    3134#include <glib/gstdio.h>
    32 
    33 #if !GLIB_CHECK_VERSION(2,8,0)
     35#else
    3436/* GLib < 2.8.0 doesn't have g_access, so just use the system access(). */
     37#include <unistd.h>
    3538#define g_access access
    3639#endif
     
    5255        char *current_setting;
    5356        account_t *current_account;
     57        struct chat *current_chat;
     58        set_t **current_set_head;
    5459        char *given_nick;
    5560        char *given_pass;
     
    170175               
    171176                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                       
    172185                        xd->current_setting = g_strdup( setting );
     186                }
    173187                else
    174188                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
     
    192206                }
    193207        }
     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        }
    194225        else
    195226        {
     
    212243                xd->current_account = NULL;
    213244        }
     245        else if( g_strcasecmp( element_name, "chat" ) == 0 )
     246        {
     247                xd->current_chat = NULL;
     248        }
    214249}
    215250
     
    218253        char text[text_len+1];
    219254        struct xml_parsedata *xd = data;
    220         irc_t *irc = xd->irc;
    221255       
    222256        strncpy( text, text_orig, text_len );
     
    231265        else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting )
    232266        {
    233                 set_setstr( xd->current_account ? &xd->current_account->set : &irc->set,
    234                             xd->current_setting, (char*) text );
     267                set_setstr( xd->current_set_head, xd->current_setting, (char*) text );
    235268                g_free( xd->current_setting );
    236269                xd->current_setting = NULL;
     
    256289}
    257290
    258 static storage_status_t xml_load_real( const char *my_nick, const char *password, irc_t *irc, xml_pass_st action )
     291static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const char *password, xml_pass_st action )
    259292{
    260293        GMarkupParseContext *ctx;
     
    263296        GError *gerr = NULL;
    264297        int fd, st;
    265        
    266         if( irc && irc->status & USTATUS_IDENTIFIED )
    267                 return( 1 );
    268298       
    269299        xd = g_new0( struct xml_parsedata, 1 );
     
    318348                return STORAGE_OK;
    319349       
    320         irc->status |= USTATUS_IDENTIFIED;
    321        
    322350        return STORAGE_OK;
    323351}
    324352
    325 static storage_status_t xml_load( const char *my_nick, const char *password, irc_t *irc )
    326 {
    327         return xml_load_real( my_nick, password, irc, XML_PASS_UNKNOWN );
     353static storage_status_t xml_load( irc_t *irc, const char *password )
     354{
     355        return xml_load_real( irc, irc->nick, password, XML_PASS_UNKNOWN );
    328356}
    329357
     
    332360        /* This is a little bit risky because we have to pass NULL for the
    333361           irc_t argument. This *should* be fine, if I didn't miss anything... */
    334         return xml_load_real( my_nick, password, NULL, XML_PASS_CHECK_ONLY );
     362        return xml_load_real( NULL, my_nick, password, XML_PASS_CHECK_ONLY );
    335363}
    336364
     
    367395        md5_byte_t pass_md5[21];
    368396        md5_state_t md5_state;
    369        
    370         if( irc->password == NULL )
    371         {
    372                 irc_usermsg( irc, "Please register yourself if you want to save your settings." );
    373                 return STORAGE_OTHER_ERROR;
    374         }
    375397       
    376398        path2 = g_strdup( irc->nick );
     
    406428       
    407429        for( set = irc->set; set; set = set->next )
    408                 if( set->value && set->def )
     430                if( set->value )
    409431                        if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    410432                                goto write_error;
     
    415437                char *pass_b64;
    416438                int pass_len;
     439                struct chat *c;
    417440               
    418441                pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 );
     
    433456               
    434457                for( set = acc->set; set; set = set->next )
    435                         if( set->value && set->def && !( set->flags & ACC_SET_NOSAVE ) )
     458                        if( set->value && !( set->flags & ACC_SET_NOSAVE ) )
    436459                                if( !xml_printf( fd, 2, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    437460                                        goto write_error;
     
    447470                        goto write_error;
    448471               
     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               
    449491                if( !xml_printf( fd, 1, "</account>\n" ) )
    450492                        goto write_error;
Note: See TracChangeset for help on using the changeset viewer.