Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    rb84800d r15d1469  
    5454        char *current_setting;
    5555        account_t *current_account;
    56         struct chat *current_chat;
    57         set_t **current_set_head;
    5856        char *given_nick;
    5957        char *given_pass;
     
    174172               
    175173                if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) )
    176                 {
    177                         if( xd->current_chat != NULL )
    178                                 xd->current_set_head = &xd->current_chat->set;
    179                         else if( xd->current_account != NULL )
    180                                 xd->current_set_head = &xd->current_account->set;
    181                         else
    182                                 xd->current_set_head = &xd->irc->set;
    183                        
    184174                        xd->current_setting = g_strdup( setting );
    185                 }
    186175                else
    187176                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
     
    205194                }
    206195        }
    207         else if( g_strcasecmp( element_name, "chat" ) == 0 )
    208         {
    209                 char *handle, *channel;
    210                
    211                 handle = xml_attr( attr_names, attr_values, "handle" );
    212                 channel = xml_attr( attr_names, attr_values, "channel" );
    213                
    214                 if( xd->current_account && handle && channel )
    215                 {
    216                         xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel );
    217                 }
    218                 else
    219                 {
    220                         g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
    221                                      "Missing attributes for %s element", element_name );
    222                 }
    223         }
    224196        else
    225197        {
     
    242214                xd->current_account = NULL;
    243215        }
    244         else if( g_strcasecmp( element_name, "chat" ) == 0 )
    245         {
    246                 xd->current_chat = NULL;
    247         }
    248216}
    249217
     
    252220        char text[text_len+1];
    253221        struct xml_parsedata *xd = data;
     222        irc_t *irc = xd->irc;
    254223       
    255224        strncpy( text, text_orig, text_len );
     
    264233        else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting )
    265234        {
    266                 set_setstr( xd->current_set_head, xd->current_setting, (char*) text );
     235                set_setstr( xd->current_account ? &xd->current_account->set : &irc->set,
     236                            xd->current_setting, (char*) text );
    267237                g_free( xd->current_setting );
    268238                xd->current_setting = NULL;
     
    288258}
    289259
    290 static storage_status_t xml_load_real( const char *my_nick, const char *password, irc_t *irc, xml_pass_st action )
     260static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const char *password, xml_pass_st action )
    291261{
    292262        GMarkupParseContext *ctx;
     
    295265        GError *gerr = NULL;
    296266        int fd, st;
    297        
    298         if( irc && irc->status & USTATUS_IDENTIFIED )
    299                 return( 1 );
    300267       
    301268        xd = g_new0( struct xml_parsedata, 1 );
     
    350317                return STORAGE_OK;
    351318       
    352         irc->status |= USTATUS_IDENTIFIED;
    353        
    354319        return STORAGE_OK;
    355320}
    356321
    357 static storage_status_t xml_load( const char *my_nick, const char *password, irc_t *irc )
    358 {
    359         return xml_load_real( my_nick, password, irc, XML_PASS_UNKNOWN );
     322static storage_status_t xml_load( irc_t *irc, const char *password )
     323{
     324        return xml_load_real( irc, irc->nick, password, XML_PASS_UNKNOWN );
    360325}
    361326
     
    364329        /* This is a little bit risky because we have to pass NULL for the
    365330           irc_t argument. This *should* be fine, if I didn't miss anything... */
    366         return xml_load_real( my_nick, password, NULL, XML_PASS_CHECK_ONLY );
     331        return xml_load_real( NULL, my_nick, password, XML_PASS_CHECK_ONLY );
    367332}
    368333
     
    399364        md5_byte_t pass_md5[21];
    400365        md5_state_t md5_state;
    401        
    402         if( irc->password == NULL )
    403         {
    404                 irc_usermsg( irc, "Please register yourself if you want to save your settings." );
    405                 return STORAGE_OTHER_ERROR;
    406         }
    407366       
    408367        path2 = g_strdup( irc->nick );
     
    438397       
    439398        for( set = irc->set; set; set = set->next )
    440                 if( set->value )
     399                if( set->value && set->def )
    441400                        if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    442401                                goto write_error;
     
    447406                char *pass_b64;
    448407                int pass_len;
    449                 struct chat *c;
    450408               
    451409                pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 );
     
    466424               
    467425                for( set = acc->set; set; set = set->next )
    468                         if( set->value && !( set->flags & ACC_SET_NOSAVE ) )
     426                        if( set->value && set->def && !( set->flags & ACC_SET_NOSAVE ) )
    469427                                if( !xml_printf( fd, 2, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    470428                                        goto write_error;
     
    480438                        goto write_error;
    481439               
    482                 for( c = irc->chatrooms; c; c = c->next )
    483                 {
    484                         if( c->acc != acc )
    485                                 continue;
    486                        
    487                         if( !xml_printf( fd, 2, "<chat handle=\"%s\" channel=\"%s\" type=\"%s\">\n",
    488                                                 c->handle, c->channel, "room" ) )
    489                                 goto write_error;
    490                        
    491                         for( set = c->set; set; set = set->next )
    492                                 if( set->value && !( set->flags & ACC_SET_NOSAVE ) )
    493                                         if( !xml_printf( fd, 3, "<setting name=\"%s\">%s</setting>\n",
    494                                                                 set->key, set->value ) )
    495                                                 goto write_error;
    496 
    497                         if( !xml_printf( fd, 2, "</chat>\n" ) )
    498                                 goto write_error;
    499                 }
    500                
    501440                if( !xml_printf( fd, 1, "</account>\n" ) )
    502441                        goto write_error;
Note: See TracChangeset for help on using the changeset viewer.