Changeset 5100caa
- Timestamp:
- 2006-07-01T15:52:05Z (18 years ago)
- Branches:
- master
- Children:
- fef6116
- Parents:
- 0a3c243
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
account.c
r0a3c243 r5100caa 28 28 #include "account.h" 29 29 30 char *set_eval_account( set_t *set, char *value ); 31 30 32 account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass ) 31 33 { 32 34 account_t *a; 35 set_t *s; 33 36 34 37 if( irc->accounts ) … … 48 51 a->irc = irc; 49 52 53 s = set_add( &a->set, "auto_connect", NULL, set_eval_account, a ); 54 s->flags |= ACC_SET_NOSAVE; 55 56 s = set_add( &a->set, "password", NULL, set_eval_account, a ); 57 s->flags |= ACC_SET_NOSAVE; 58 59 s = set_add( &a->set, "server", NULL, set_eval_account, a ); 60 s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY; 61 62 s = set_add( &a->set, "username", NULL, set_eval_account, a ); 63 s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY; 64 set_setstr( &a->set, "username", user ); 65 50 66 return( a ); 67 } 68 69 char *set_eval_account( set_t *set, char *value ) 70 { 71 account_t *acc = set->data; 72 73 /* Double-check: We refuse to edit on-line accounts. */ 74 if( acc->gc ) 75 return NULL; 76 77 if( strcmp( set->key, "username" ) == 0 ) 78 { 79 g_free( acc->user ); 80 acc->user = g_strdup( value ); 81 return value; 82 } 83 else if( strcmp( set->key, "password" ) == 0 ) 84 { 85 g_free( acc->pass ); 86 acc->pass = g_strdup( value ); 87 return NULL; /* password shouldn't be visible in plaintext! */ 88 } 89 else if( strcmp( set->key, "server" ) == 0 ) 90 { 91 g_free( acc->server ); 92 if( *value ) 93 acc->server = g_strdup( value ); 94 else 95 acc->server = NULL; 96 return value; 97 } 98 else if( strcmp( set->key, "auto_connect" ) == 0 ) 99 { 100 if( !is_bool( value ) ) 101 return NULL; 102 103 acc->auto_connect = bool2int( value ); 104 return value; 105 } 106 107 return NULL; 51 108 } 52 109 … … 130 187 } 131 188 189 while( a->set ) 190 set_del( &a->set, a->set->key ); 191 132 192 g_free( a->user ); 133 193 g_free( a->pass ); -
account.h
r0a3c243 r5100caa 37 37 int reconnect; 38 38 39 set_t *set; 40 39 41 struct irc *irc; 40 42 struct gaim_connection *gc; … … 48 50 void account_off( irc_t *irc, account_t *a ); 49 51 52 #define ACC_SET_NOSAVE 1 53 #define ACC_SET_OFFLINE_ONLY 2 54 50 55 #endif -
lib/misc.c
r0a3c243 r5100caa 486 486 } 487 487 } 488 489 int is_bool( char *value ) 490 { 491 if( *value == 0 ) 492 return 0; 493 494 if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) 495 return 1; 496 if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) 497 return 1; 498 499 while( *value ) 500 if( !isdigit( *value ) ) 501 return 0; 502 else 503 value ++; 504 505 return 1; 506 } 507 508 int bool2int( char *value ) 509 { 510 int i; 511 512 if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) 513 return 1; 514 if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) 515 return 0; 516 517 if( sscanf( value, "%d", &i ) == 1 ) 518 return i; 519 520 return 0; 521 } -
lib/misc.h
r0a3c243 r5100caa 51 51 G_MODULE_EXPORT void random_bytes( unsigned char *buf, int count ); 52 52 53 G_MODULE_EXPORT int is_bool( char *value ); 54 G_MODULE_EXPORT int bool2int( char *value ); 55 53 56 #endif -
lib/rc4.c
r0a3c243 r5100caa 165 165 if( clear_len < 0 ) 166 166 { 167 *clear = g_strdup( "" );167 *clear = (unsigned char*) g_strdup( "" ); 168 168 return 0; 169 169 } -
root_commands.c
r0a3c243 r5100caa 232 232 233 233 a = account_add( irc, prpl, cmd[3], cmd[4] ); 234 235 234 if( cmd[5] ) 236 a->server = g_strdup(cmd[5] );235 set_setstr( &a->set, "server", cmd[5] ); 237 236 238 237 irc_usermsg( irc, "Account successfully added" ); … … 358 357 } 359 358 } 359 else if( g_strcasecmp( cmd[1], "set" ) == 0 ) 360 { 361 char *acc_handle, *set_name = NULL, *tmp; 362 363 if( !cmd[2] ) 364 { 365 irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); 366 return; 367 } 368 369 acc_handle = g_strdup( cmd[2] ); 370 if( ( tmp = strchr( acc_handle, '/' ) ) ) 371 { 372 *tmp = 0; 373 set_name = tmp + 1; 374 } 375 a = account_get( irc, acc_handle ); 376 377 if( a == NULL ) 378 { 379 irc_usermsg( irc, "Invalid account" ); 380 return; 381 } 382 383 if( cmd[3] ) 384 { 385 set_t *s = set_find( &a->set, set_name ); 386 387 if( a->gc && s && s->flags & ACC_SET_OFFLINE_ONLY ) 388 { 389 irc_usermsg( irc, "This setting can only be changed when the account is off-line" ); 390 return; 391 } 392 393 set_setstr( &a->set, set_name, cmd[3] ); 394 395 if( ( strcmp( cmd[3], "=" ) ) == 0 && cmd[4] ) 396 irc_usermsg( irc, "Warning: Correct syntax: \002account set <variable> <value>\002 (without =)" ); 397 } 398 if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ 399 { 400 char *s = set_getstr( &a->set, set_name ); 401 if( s ) 402 irc_usermsg( irc, "%s = `%s'", set_name, s ); 403 else 404 irc_usermsg( irc, "%s is empty", set_name ); 405 } 406 else 407 { 408 set_t *s = a->set; 409 while( s ) 410 { 411 if( s->value || s->def ) 412 irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def ); 413 else 414 irc_usermsg( irc, "%s is empty", s->key ); 415 s = s->next; 416 } 417 } 418 419 g_free( acc_handle ); 420 } 360 421 else 361 422 { … … 682 743 if( s ) 683 744 irc_usermsg( irc, "%s = `%s'", cmd[1], s ); 745 else 746 irc_usermsg( irc, "%s is empty", cmd[1] ); 684 747 } 685 748 else … … 690 753 if( s->value || s->def ) 691 754 irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def ); 755 else 756 irc_usermsg( irc, "%s is empty", s->key ); 692 757 s = s->next; 693 758 } -
set.c
r0a3c243 r5100caa 101 101 } 102 102 103 int set_getbool( set_t **head, char *key ) 104 { 105 char *s = set_getstr( head, key ); 106 107 if( !s ) 108 return 0; 109 110 return bool2int( s ); 111 } 112 103 113 int set_setstr( set_t **head, char *key, char *value ) 104 114 { … … 166 176 167 177 for( s = value; *s; s ++ ) 168 if( *s < '0' || *s > '9')178 if( !isdigit( *s ) ) 169 179 return NULL; 170 180 … … 174 184 char *set_eval_bool( set_t *set, char *value ) 175 185 { 176 if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) 177 return( value ); 178 if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) 179 return( value ); 180 return( set_eval_int( set, value ) ); 186 return is_bool( value ) ? value : NULL; 181 187 } 182 188 -
set.h
r0a3c243 r5100caa 32 32 char *def; /* Default */ 33 33 34 int flags; 35 34 36 /* Eval: Returns NULL if the value is incorrect or exactly the 35 37 passed value variable. When returning a corrected value, … … 40 42 41 43 set_t *set_add( set_t **head, char *key, char *def, void *eval, void *data ); 42 G_MODULE_EXPORTset_t *set_find( set_t **head, char *key );44 set_t *set_find( set_t **head, char *key ); 43 45 G_MODULE_EXPORT char *set_getstr( set_t **head, char *key ); 44 46 G_MODULE_EXPORT int set_getint( set_t **head, char *key ); -
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.