Changes in account.c [c99af3a:5100caa]
Legend:
- Unmodified
- Added
- Removed
-
account.c
rc99af3a 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 ) 35 38 { 36 39 for( a = irc->accounts; a->next; a = a->next ); 37 a = a->next = g_new0 40 a = a->next = g_new0( account_t, 1 ); 38 41 } 39 42 else … … 45 48 a->user = g_strdup( user ); 46 49 a->pass = g_strdup( pass ); 50 a->auto_connect = 1; 47 51 a->irc = irc; 48 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 49 66 return( a ); 50 67 } 51 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; 108 } 109 52 110 account_t *account_get( irc_t *irc, char *id ) 53 111 { 54 112 account_t *a, *ret = NULL; 113 char *handle, *s; 55 114 int nr; 115 116 /* This checks if the id string ends with (...) */ 117 if( ( handle = strchr( id, '(' ) ) && ( s = strchr( handle, ')' ) ) && s[1] == 0 ) 118 { 119 struct prpl *proto; 120 121 *s = *handle = 0; 122 handle ++; 123 124 if( ( proto = find_protocol( id ) ) ) 125 { 126 for( a = irc->accounts; a; a = a->next ) 127 if( a->prpl == proto && 128 a->prpl->cmp_buddynames( handle, a->user ) == 0 ) 129 ret = a; 130 } 131 132 /* Restore the string. */ 133 handle --; 134 *handle = '('; 135 *s = ')'; 136 137 if( ret ) 138 return ret; 139 } 56 140 57 141 if( sscanf( id, "%d", &nr ) == 1 && nr < 1000 ) … … 103 187 } 104 188 189 while( a->set ) 190 set_del( &a->set, a->set->key ); 191 105 192 g_free( a->user ); 106 193 g_free( a->pass ); … … 116 203 void account_on( irc_t *irc, account_t *a ) 117 204 { 118 struct aim_user *u;119 120 205 if( a->gc ) 121 206 { … … 126 211 cancel_auto_reconnect( a ); 127 212 128 u = g_new0 ( struct aim_user, 1 );129 u->irc = irc;130 u->prpl = a->prpl;131 strncpy( u->username, a->user, sizeof( u->username ) - 1 );132 strncpy( u->password, a->pass, sizeof( u->password ) - 1 );133 if( a->server) strncpy( u->proto_opt[0], a->server, sizeof( u->proto_opt[0] ) - 1 );134 135 a->gc = (struct gaim_connection *) u; /* Bit hackish :-/ */136 213 a->reconnect = 0; 137 138 a->prpl->login( u ); 214 a->prpl->login( a ); 139 215 } 140 216
Note: See TracChangeset
for help on using the changeset viewer.