diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2008-08-31 15:54:39 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2008-08-31 15:54:39 +0100 |
commit | d995c9b5de1bff5e3eb5de47b7ffbd3e92e2ac3d (patch) | |
tree | 8c630131f1851da9fbf3d20fffb771f13b8c2848 | |
parent | 39f93f0ce1c0a179b51f5ff6474d57509e9e0d17 (diff) |
Added cleanup code.
-rw-r--r-- | account.c | 8 | ||||
-rw-r--r-- | chat.c | 25 | ||||
-rw-r--r-- | chat.h | 1 | ||||
-rw-r--r-- | root_commands.c | 17 |
4 files changed, 51 insertions, 0 deletions
@@ -189,6 +189,7 @@ account_t *account_get( irc_t *irc, char *id ) void account_del( irc_t *irc, account_t *acc ) { account_t *a, *l = NULL; + struct chat *c, *nc; if( acc->ic ) /* Caller should have checked, accounts still in use can't be deleted. */ @@ -202,6 +203,13 @@ void account_del( irc_t *irc, account_t *acc ) else irc->accounts = a->next; + for( c = irc->chatrooms; c; c = nc ) + if( acc == c->acc ) + { + nc = c->next; + chat_del( irc, c ); + } + while( a->set ) set_del( &a->set, a->set->key ); @@ -125,6 +125,31 @@ struct chat *chat_get( irc_t *irc, char *id ) return ret; } +int chat_del( irc_t *irc, struct chat *chat ) +{ + struct chat *c, *l = NULL; + + for( c = irc->chatrooms; c; c = (l=c)->next ) + if( c == chat ) + break; + + if( c == NULL ) + return 0; + else if( l == NULL ) + irc->chatrooms = c->next; + else + l->next = c->next; + + while( c->set ) + set_del( &c->set, c->set->key ); + + g_free( c->handle ); + g_free( c->channel ); + g_free( c ); + + return 1; +} + int chat_chancmp( char *a, char *b ) { if( !chat_chanok( a ) || !chat_chanok( b ) ) @@ -38,6 +38,7 @@ struct chat *chat_add( irc_t *irc, account_t *acc, char *handle, char *channel ) struct chat *chat_byhandle( irc_t *irc, account_t *acc, char *handle ); struct chat *chat_bychannel( irc_t *irc, char *channel ); struct chat *chat_get( irc_t *irc, char *id ); +int chat_del( irc_t *irc, struct chat *chat ); int chat_chancmp( char *a, char *b ); int chat_chanok( char *a ); diff --git a/root_commands.c b/root_commands.c index 97cadffe..5b709b0e 100644 --- a/root_commands.c +++ b/root_commands.c @@ -1050,6 +1050,23 @@ static void cmd_chat( irc_t *irc, char **cmd ) { cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead ); } + else if( g_strcasecmp( cmd[1], "del" ) == 0 ) + { + if( !cmd[2] ) + { + irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); + return; + } + + if( ( c = chat_get( irc, cmd[2] ) ) ) + { + chat_del( irc, c ); + } + else + { + irc_usermsg( irc, "Could not remove chat." ); + } + } else if( g_strcasecmp( cmd[1], "with" ) == 0 ) { user_t *u; |