Changeset 5100caa for storage_xml.c


Ignore:
Timestamp:
2006-07-01T15:52:05Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
fef6116
Parents:
0a3c243
Message:

Added "account set" command.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    r0a3c243 r5100caa  
    157157                        xd->current_account = account_add( irc, prpl, handle, password );
    158158                        if( server )
    159                                 xd->current_account->server = g_strdup( server );
     159                                set_setstr( &xd->current_account->set, "server", server );
    160160                        if( autoconnect )
    161                                 /* Return value doesn't matter, since account_add() already sets
    162                                    a default! */
    163                                 sscanf( autoconnect, "%d", &xd->current_account->auto_connect );
     161                                set_setstr( &xd->current_account->set, "auto_connect", autoconnect );
    164162                }
    165163                else
     
    176174        else if( g_strcasecmp( element_name, "setting" ) == 0 )
    177175        {
    178                 if( xd->current_account == NULL )
    179                 {
    180                         char *setting;
    181                        
    182                         if( xd->current_setting )
    183                         {
    184                                 g_free( xd->current_setting );
    185                                 xd->current_setting = NULL;
    186                         }
    187                        
    188                         if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) )
    189                                 xd->current_setting = g_strdup( setting );
    190                         else
    191                                 g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
    192                                              "Missing attributes for %s element", element_name );
    193                 }
     176                char *setting;
     177               
     178                if( xd->current_setting )
     179                {
     180                        g_free( xd->current_setting );
     181                        xd->current_setting = NULL;
     182                }
     183               
     184                if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) )
     185                        xd->current_setting = g_strdup( setting );
     186                else
     187                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
     188                                     "Missing attributes for %s element", element_name );
    194189        }
    195190        else if( g_strcasecmp( element_name, "buddy" ) == 0 )
     
    243238                   yet. */
    244239        }
    245         else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 &&
    246                  xd->current_setting && xd->current_account == NULL )
    247         {
    248                 set_setstr( &irc->set, xd->current_setting, (char*) text );
     240        else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting )
     241        {
     242                set_setstr( xd->current_account ? &xd->current_account->set : &irc->set,
     243                            xd->current_setting, (char*) text );
    249244                g_free( xd->current_setting );
    250245                xd->current_setting = NULL;
     
    348343}
    349344
    350 static int xml_printf( int fd, char *fmt, ... )
     345static int xml_printf( int fd, int indent, char *fmt, ... )
    351346{
    352347        va_list params;
    353348        char *out;
     349        char tabs[9] = "\t\t\t\t\t\t\t\t";
    354350        int len;
     351       
     352        /* Maybe not very clean, but who needs more than 8 levels of indentation anyway? */
     353        if( write( fd, tabs, indent <= 8 ? indent : 8 ) != indent )
     354                return 0;
    355355       
    356356        va_start( params, fmt );
     
    404404        pass_buf = base64_encode( (char*) pass_md5, 21 );
    405405       
    406         if( !xml_printf( fd, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->nick, pass_buf, XML_FORMAT_VERSION ) )
     406        if( !xml_printf( fd, 0, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->nick, pass_buf, XML_FORMAT_VERSION ) )
    407407                goto write_error;
    408408       
     
    411411        for( set = irc->set; set; set = set->next )
    412412                if( set->value && set->def )
    413                         if( !xml_printf( fd, "\t<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
     413                        if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    414414                                goto write_error;
    415415       
     
    423423                g_free( pass_rc4 );
    424424               
    425                 if( !xml_printf( fd, "\t<account protocol=\"%s\" handle=\"%s\" password=\"%s\" autoconnect=\"%d\"", acc->prpl->name, acc->user, pass_b64, acc->auto_connect ) )
     425                if( !xml_printf( fd, 1, "<account protocol=\"%s\" handle=\"%s\" password=\"%s\" autoconnect=\"%d\"", acc->prpl->name, acc->user, pass_b64, acc->auto_connect ) )
    426426                {
    427427                        g_free( pass_b64 );
     
    430430                g_free( pass_b64 );
    431431               
    432                 if( acc->server && acc->server[0] && !xml_printf( fd, " server=\"%s\"", acc->server ) )
     432                if( acc->server && acc->server[0] && !xml_printf( fd, 0, " server=\"%s\"", acc->server ) )
    433433                        goto write_error;
    434                 if( !xml_printf( fd, ">\n" ) )
     434                if( !xml_printf( fd, 0, ">\n" ) )
    435435                        goto write_error;
     436               
     437                for( set = acc->set; set; set = set->next )
     438                        if( set->value && set->def && !( set->flags & ACC_SET_NOSAVE ) )
     439                                if( !xml_printf( fd, 2, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
     440                                        goto write_error;
    436441               
    437442                for( nick = irc->nicks; nick; nick = nick->next )
    438443                        if( nick->proto == acc->prpl )
    439                                 if( !xml_printf( fd, "\t\t<buddy handle=\"%s\" nick=\"%s\" />\n", nick->handle, nick->nick ) )
     444                                if( !xml_printf( fd, 2, "<buddy handle=\"%s\" nick=\"%s\" />\n", nick->handle, nick->nick ) )
    440445                                        goto write_error;
    441446               
    442                 if( !xml_printf( fd, "\t</account>\n" ) )
     447                if( !xml_printf( fd, 1, "</account>\n" ) )
    443448                        goto write_error;
    444449        }
    445450       
    446         if( !xml_printf( fd, "</user>\n" ) )
     451        if( !xml_printf( fd, 0, "</user>\n" ) )
    447452                goto write_error;
    448453       
Note: See TracChangeset for help on using the changeset viewer.