Changeset 2288705 for storage_xml.c
- Timestamp:
- 2009-12-07T21:54:19Z (14 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
storage_xml.c
raac4017 r2288705 29 29 #include "arc.h" 30 30 #include "md5.h" 31 #include "chat.h" 32 33 #if GLIB_CHECK_VERSION(2,8,0) 31 34 #include <glib/gstdio.h> 32 33 #if !GLIB_CHECK_VERSION(2,8,0) 35 #else 34 36 /* GLib < 2.8.0 doesn't have g_access, so just use the system access(). */ 37 #include <unistd.h> 35 38 #define g_access access 36 39 #endif … … 52 55 char *current_setting; 53 56 account_t *current_account; 57 struct chat *current_chat; 58 set_t **current_set_head; 54 59 char *given_nick; 55 60 char *given_pass; … … 170 175 171 176 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 172 185 xd->current_setting = g_strdup( setting ); 186 } 173 187 else 174 188 g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, … … 192 206 } 193 207 } 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 } 194 225 else 195 226 { … … 212 243 xd->current_account = NULL; 213 244 } 245 else if( g_strcasecmp( element_name, "chat" ) == 0 ) 246 { 247 xd->current_chat = NULL; 248 } 214 249 } 215 250 … … 218 253 char text[text_len+1]; 219 254 struct xml_parsedata *xd = data; 220 irc_t *irc = xd->irc;221 255 222 256 strncpy( text, text_orig, text_len ); … … 231 265 else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting ) 232 266 { 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 ); 235 268 g_free( xd->current_setting ); 236 269 xd->current_setting = NULL; … … 256 289 } 257 290 258 static storage_status_t xml_load_real( const char *my_nick, const char *password, irc_t *irc, xml_pass_st action )291 static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const char *password, xml_pass_st action ) 259 292 { 260 293 GMarkupParseContext *ctx; … … 263 296 GError *gerr = NULL; 264 297 int fd, st; 265 266 if( irc && irc->status & USTATUS_IDENTIFIED )267 return( 1 );268 298 269 299 xd = g_new0( struct xml_parsedata, 1 ); … … 318 348 return STORAGE_OK; 319 349 320 irc->status |= USTATUS_IDENTIFIED;321 322 350 return STORAGE_OK; 323 351 } 324 352 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 );353 static storage_status_t xml_load( irc_t *irc, const char *password ) 354 { 355 return xml_load_real( irc, irc->nick, password, XML_PASS_UNKNOWN ); 328 356 } 329 357 … … 332 360 /* This is a little bit risky because we have to pass NULL for the 333 361 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 ); 335 363 } 336 364 … … 367 395 md5_byte_t pass_md5[21]; 368 396 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 }375 397 376 398 path2 = g_strdup( irc->nick ); … … 406 428 407 429 for( set = irc->set; set; set = set->next ) 408 if( set->value && set->def)430 if( set->value ) 409 431 if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) ) 410 432 goto write_error; … … 415 437 char *pass_b64; 416 438 int pass_len; 439 struct chat *c; 417 440 418 441 pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 ); … … 433 456 434 457 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 ) ) 436 459 if( !xml_printf( fd, 2, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) ) 437 460 goto write_error; … … 447 470 goto write_error; 448 471 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 449 491 if( !xml_printf( fd, 1, "</account>\n" ) ) 450 492 goto write_error;
Note: See TracChangeset
for help on using the changeset viewer.