aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--irc.c4
-rw-r--r--protocols/nogaim.c34
-rw-r--r--protocols/oscar/oscar.c4
-rw-r--r--protocols/oscar/rxhandlers.c4
-rw-r--r--root_commands.c2
-rw-r--r--set.h36
-rw-r--r--user.c2
7 files changed, 54 insertions, 32 deletions
diff --git a/irc.c b/irc.c
index 0373f176..87cc4c78 100644
--- a/irc.c
+++ b/irc.c
@@ -212,7 +212,7 @@ void irc_free(irc_t * irc)
log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd );
- if( irc->status & USTATUS_IDENTIFIED && set_getint( &irc->set, "save_on_quit" ) )
+ if( irc->status & USTATUS_IDENTIFIED && set_getbool( &irc->set, "save_on_quit" ) )
if( storage_save( irc, TRUE ) != STORAGE_OK )
irc_usermsg( irc, "Error while saving settings!" );
@@ -1057,7 +1057,7 @@ void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags )
{
if( !u || !u->gc ) return;
- if( set_getint( &irc->set, "buddy_sendbuffer" ) && set_getint( &irc->set, "buddy_sendbuffer_delay" ) > 0 )
+ if( set_getbool( &irc->set, "buddy_sendbuffer" ) && set_getint( &irc->set, "buddy_sendbuffer_delay" ) > 0 )
{
int delay;
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index f0008385..47e2bda6 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -207,7 +207,7 @@ void serv_got_crap( struct gaim_connection *gc, char *format, ... )
va_end( params );
if( ( g_strcasecmp( set_getstr( &gc->irc->set, "strip_html" ), "always" ) == 0 ) ||
- ( ( gc->flags & OPT_CONN_HTML ) && set_getint( &gc->irc->set, "strip_html" ) ) )
+ ( ( gc->flags & OPT_CONN_HTML ) && set_getbool( &gc->irc->set, "strip_html" ) ) )
strip_html( text );
/* Try to find a different connection on the same protocol. */
@@ -352,12 +352,12 @@ void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *rea
char *s;
irc_t *irc = gc->irc;
- if( set_getint( &irc->set, "debug" ) && 0 ) /* This message is too useless */
+ if( set_getbool( &irc->set, "debug" ) && 0 ) /* This message is too useless */
serv_got_crap( gc, "Receiving user add from handle: %s", handle );
if( user_findhandle( gc, handle ) )
{
- if( set_getint( &irc->set, "debug" ) )
+ if( set_getbool( &irc->set, "debug" ) )
serv_got_crap( gc, "User already exists, ignoring add request: %s", handle );
return;
@@ -445,7 +445,7 @@ void serv_buddy_rename( struct gaim_connection *gc, char *handle, char *realname
u->realname = g_strdup( realname );
- if( ( gc->flags & OPT_LOGGED_IN ) && set_getint( &gc->irc->set, "display_namechanges" ) )
+ if( ( gc->flags & OPT_LOGGED_IN ) && set_getbool( &gc->irc->set, "display_namechanges" ) )
serv_got_crap( gc, "User `%s' changed name to `%s'", u->nick, u->realname );
}
}
@@ -508,7 +508,7 @@ void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, in
}
else
{
- if( set_getint( &gc->irc->set, "debug" ) || g_strcasecmp( set_getstr( &gc->irc->set, "handle_unknown" ), "ignore" ) != 0 )
+ if( set_getbool( &gc->irc->set, "debug" ) || g_strcasecmp( set_getstr( &gc->irc->set, "handle_unknown" ), "ignore" ) != 0 )
{
serv_got_crap( gc, "serv_got_update() for handle %s:", handle );
serv_got_crap( gc, "loggedin = %d, type = %d", loggedin, type );
@@ -567,7 +567,7 @@ void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, in
u->away = NULL;
/* LISPy... */
- if( ( set_getint( &gc->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */
+ if( ( set_getbool( &gc->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */
( u->online ) && /* Don't touch offline people */
( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */
( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */
@@ -590,14 +590,14 @@ void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 f
if( g_strcasecmp( h, "ignore" ) == 0 )
{
- if( set_getint( &irc->set, "debug" ) )
+ if( set_getbool( &irc->set, "debug" ) )
serv_got_crap( gc, "Ignoring message from unknown handle %s", handle );
return;
}
else if( g_strncasecmp( h, "add", 3 ) == 0 )
{
- int private = set_getint( &irc->set, "private" );
+ int private = set_getbool( &irc->set, "private" );
if( h[3] )
{
@@ -619,7 +619,7 @@ void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 f
}
if( ( g_strcasecmp( set_getstr( &gc->irc->set, "strip_html" ), "always" ) == 0 ) ||
- ( ( gc->flags & OPT_CONN_HTML ) && set_getint( &gc->irc->set, "strip_html" ) ) )
+ ( ( gc->flags & OPT_CONN_HTML ) && set_getbool( &gc->irc->set, "strip_html" ) ) )
strip_html( msg );
while( strlen( msg ) > 425 )
@@ -659,7 +659,7 @@ void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout, int
{
user_t *u;
- if( !set_getint( &gc->irc->set, "typing_notice" ) )
+ if( !set_getbool( &gc->irc->set, "typing_notice" ) )
return;
if( ( u = user_findhandle( gc, handle ) ) ) {
@@ -681,7 +681,7 @@ void serv_got_chat_left( struct gaim_connection *gc, int id )
struct conversation *c, *l = NULL;
GList *ir;
- if( set_getint( &gc->irc->set, "debug" ) )
+ if( set_getbool( &gc->irc->set, "debug" ) )
serv_got_crap( gc, "You were removed from conversation %d", (int) id );
for( c = gc->conversations; c && c->id != id; c = (l=c)->next );
@@ -727,7 +727,7 @@ void serv_got_chat_in( struct gaim_connection *gc, int id, char *who, int whispe
for( c = gc->conversations; c && c->id != id; c = c->next );
if( ( g_strcasecmp( set_getstr( &gc->irc->set, "strip_html" ), "always" ) == 0 ) ||
- ( ( gc->flags & OPT_CONN_HTML ) && set_getint( &gc->irc->set, "strip_html" ) ) )
+ ( ( gc->flags & OPT_CONN_HTML ) && set_getbool( &gc->irc->set, "strip_html" ) ) )
strip_html( msg );
if( c && u )
@@ -760,7 +760,7 @@ struct conversation *serv_got_joined_chat( struct gaim_connection *gc, int id, c
c->channel = g_strdup( s );
g_free( s );
- if( set_getint( &gc->irc->set, "debug" ) )
+ if( set_getbool( &gc->irc->set, "debug" ) )
serv_got_crap( gc, "Creating new conversation: (id=%d,handle=%s)", id, handle );
return( c );
@@ -774,7 +774,7 @@ void add_chat_buddy( struct conversation *b, char *handle )
user_t *u = user_findhandle( b->gc, handle );
int me = 0;
- if( set_getint( &b->gc->irc->set, "debug" ) )
+ if( set_getbool( &b->gc->irc->set, "debug" ) )
serv_got_crap( b->gc, "User %s added to conversation %d", handle, b->id );
/* It might be yourself! */
@@ -808,7 +808,7 @@ void remove_chat_buddy( struct conversation *b, char *handle, char *reason )
user_t *u;
int me = 0;
- if( set_getint( &b->gc->irc->set, "debug" ) )
+ if( set_getbool( &b->gc->irc->set, "debug" ) )
serv_got_crap( b->gc, "User %s removed from conversation %d (%s)", handle, b->id, reason ? reason : "" );
/* It might be yourself! */
@@ -886,7 +886,7 @@ char *set_eval_away_devoice( set_t *set, char *value )
/* Horror.... */
- if( st != set_getint( &irc->set, "away_devoice" ) )
+ if( st != set_getbool( &irc->set, "away_devoice" ) )
{
char list[80] = "";
user_t *u = irc->users;
@@ -1006,7 +1006,7 @@ int bim_set_away( struct gaim_connection *gc, char *away )
if( s )
{
gc->acc->prpl->set_away( gc, s, away );
- if( set_getint( &gc->irc->set, "debug" ) )
+ if( set_getbool( &gc->irc->set, "debug" ) )
serv_got_crap( gc, "Setting away state to %s", s );
}
else
diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c
index d30ebbe8..b8cf521b 100644
--- a/protocols/oscar/oscar.c
+++ b/protocols/oscar/oscar.c
@@ -1251,10 +1251,6 @@ static int gaim_parse_incoming_im(aim_session_t *sess, aim_frame_t *fr, ...) {
channel = va_arg(ap, int);
userinfo = va_arg(ap, aim_userinfo_t *);
- if (set_getint(sess->aux_data, "debug")) {
- serv_got_crap(sess->aux_data, "channel %i called", channel);
- }
-
switch (channel) {
case 1: { /* standard message */
struct aim_incomingim_ch1_args *args;
diff --git a/protocols/oscar/rxhandlers.c b/protocols/oscar/rxhandlers.c
index be8aba44..7014e693 100644
--- a/protocols/oscar/rxhandlers.c
+++ b/protocols/oscar/rxhandlers.c
@@ -112,10 +112,6 @@ static int consumesnac(aim_session_t *sess, aim_frame_t *rx)
/* Following SNAC will be related */
}
- if (set_getint(sess->aux_data, "debug")) {
- serv_got_crap(sess->aux_data, "snac %x/%x received", snac.family, snac.subtype);
- }
-
for (cur = (aim_module_t *)sess->modlistv; cur; cur = cur->next) {
if (!(cur->flags & AIM_MODFLAG_MULTIFAMILY) &&
diff --git a/root_commands.c b/root_commands.c
index 389266eb..13567e8a 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -143,7 +143,7 @@ static void cmd_identify( irc_t *irc, char **cmd )
case STORAGE_OK:
irc_usermsg( irc, "Password accepted, settings and accounts loaded" );
irc_umode_set( irc, "+R", 1 );
- if( set_getint( &irc->set, "auto_connect" ) )
+ if( set_getbool( &irc->set, "auto_connect" ) )
cmd_account( irc, account_on );
break;
case STORAGE_OTHER_ERROR:
diff --git a/set.h b/set.h
index 48bc8145..14043c2f 100644
--- a/set.h
+++ b/set.h
@@ -23,15 +23,30 @@
Suite 330, Boston, MA 02111-1307 USA
*/
+/* This used to be specific to irc_t structures, but it's more generic now
+ (so it can also be used for account_t structs). It's pretty simple, but
+ so far pretty useful.
+
+ In short, it just keeps a linked list of settings/variables and it also
+ remembers a default value for every setting. And to prevent the user
+ from setting invalid values, you can write an evaluator function for
+ every setting, which can check a new value and block it by returning
+ NULL, or replace it by returning a new value. See struct set.eval. */
+
typedef struct set
{
- void *data;
+ void *data; /* Here you can save a pointer to the
+ object this settings belongs to. */
char *key;
char *value;
- char *def; /* Default */
+ char *def; /* Default value. If the set_setstr() function
+ notices a new value is exactly the same as
+ the default, value gets set to NULL. So when
+ you read a setting, don't forget about this! */
- int flags;
+ int flags; /* See account.h, for example. set.c doesn't use
+ this (yet?). */
/* Eval: Returns NULL if the value is incorrect or exactly the
passed value variable. When returning a corrected value,
@@ -40,18 +55,33 @@ typedef struct set
struct set *next;
} set_t;
+/* Should be pretty clear. */
set_t *set_add( set_t **head, char *key, char *def, void *eval, void *data );
+
+/* Returns the raw set_t. Might be useful sometimes. */
set_t *set_find( set_t **head, char *key );
+
+/* Returns a pointer to the string value of this setting. Don't modify the
+ returned string, and don't free() it! */
G_MODULE_EXPORT char *set_getstr( set_t **head, char *key );
+
+/* Get an integer. Right now this also converts true/false/on/off/etc to
+ numbers, but this is for historical reasons, please use set_getbool()
+ for booleans instead. */
G_MODULE_EXPORT int set_getint( set_t **head, char *key );
G_MODULE_EXPORT int set_getbool( set_t **head, char *key );
+
+/* set_setstr() strdup()s the given value, so after using this function
+ you can free() it, if you want. */
int set_setstr( set_t **head, char *key, char *value );
int set_setint( set_t **head, char *key, int value );
void set_del( set_t **head, char *key );
+/* Two very useful generic evaluators. */
char *set_eval_int( set_t *set, char *value );
char *set_eval_bool( set_t *set, char *value );
+/* Some not very generic evaluators that really shouldn't be here... */
char *set_eval_to_char( set_t *set, char *value );
char *set_eval_ops( set_t *set, char *value );
char *set_eval_charset( set_t *set, char *value );
diff --git a/user.c b/user.c
index 0892a23c..ff65fe66 100644
--- a/user.c
+++ b/user.c
@@ -66,7 +66,7 @@ user_t *user_add( irc_t *irc, char *nick )
}
u->user = u->realname = u->host = u->nick = g_strdup( nick );
- u->is_private = set_getint( &irc->set, "private" );
+ u->is_private = set_getbool( &irc->set, "private" );
key = g_strdup( nick );
nick_lc( key );