Changeset 5100caa for storage_xml.c
- Timestamp:
- 2006-07-01T15:52:05Z (18 years ago)
- Branches:
- master
- Children:
- fef6116
- Parents:
- 0a3c243
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
storage_xml.c
r0a3c243 r5100caa 157 157 xd->current_account = account_add( irc, prpl, handle, password ); 158 158 if( server ) 159 xd->current_account->server = g_strdup(server );159 set_setstr( &xd->current_account->set, "server", server ); 160 160 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 ); 164 162 } 165 163 else … … 176 174 else if( g_strcasecmp( element_name, "setting" ) == 0 ) 177 175 { 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 ); 194 189 } 195 190 else if( g_strcasecmp( element_name, "buddy" ) == 0 ) … … 243 238 yet. */ 244 239 } 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 ); 249 244 g_free( xd->current_setting ); 250 245 xd->current_setting = NULL; … … 348 343 } 349 344 350 static int xml_printf( int fd, char *fmt, ... )345 static int xml_printf( int fd, int indent, char *fmt, ... ) 351 346 { 352 347 va_list params; 353 348 char *out; 349 char tabs[9] = "\t\t\t\t\t\t\t\t"; 354 350 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; 355 355 356 356 va_start( params, fmt ); … … 404 404 pass_buf = base64_encode( (char*) pass_md5, 21 ); 405 405 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 ) ) 407 407 goto write_error; 408 408 … … 411 411 for( set = irc->set; set; set = set->next ) 412 412 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 ) ) 414 414 goto write_error; 415 415 … … 423 423 g_free( pass_rc4 ); 424 424 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 ) ) 426 426 { 427 427 g_free( pass_b64 ); … … 430 430 g_free( pass_b64 ); 431 431 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 ) ) 433 433 goto write_error; 434 if( !xml_printf( fd, ">\n" ) )434 if( !xml_printf( fd, 0, ">\n" ) ) 435 435 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; 436 441 437 442 for( nick = irc->nicks; nick; nick = nick->next ) 438 443 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 ) ) 440 445 goto write_error; 441 446 442 if( !xml_printf( fd, "\t</account>\n" ) )447 if( !xml_printf( fd, 1, "</account>\n" ) ) 443 448 goto write_error; 444 449 } 445 450 446 if( !xml_printf( fd, "</user>\n" ) )451 if( !xml_printf( fd, 0, "</user>\n" ) ) 447 452 goto write_error; 448 453
Note: See TracChangeset
for help on using the changeset viewer.