[b7d3cc34] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
| 4 | * Copyright 2002-2004 Wilmer van der Gaast and others * |
---|
| 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* Stuff to handle, save and search buddies */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | This program is free software; you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License with |
---|
| 21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 23 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #define BITLBEE_CORE |
---|
| 27 | #include "bitlbee.h" |
---|
| 28 | |
---|
| 29 | user_t *user_add( irc_t *irc, char *nick ) |
---|
| 30 | { |
---|
| 31 | user_t *u, *lu = NULL; |
---|
| 32 | char *key; |
---|
| 33 | |
---|
| 34 | if( !nick_ok( nick ) ) |
---|
| 35 | return( NULL ); |
---|
| 36 | |
---|
| 37 | if( user_find( irc, nick ) != NULL ) |
---|
| 38 | return( NULL ); |
---|
| 39 | |
---|
| 40 | return( u ); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | int user_del( irc_t *irc, char *nick ) |
---|
| 44 | { |
---|
| 45 | user_t *u, *t; |
---|
| 46 | char *key; |
---|
| 47 | gpointer okey, ovalue; |
---|
| 48 | |
---|
| 49 | if( !nick_ok( nick ) ) |
---|
| 50 | return( 0 ); |
---|
| 51 | |
---|
| 52 | u = irc->users; |
---|
| 53 | t = NULL; |
---|
| 54 | while( u ) |
---|
| 55 | { |
---|
| 56 | if( nick_cmp( u->nick, nick ) == 0 ) |
---|
| 57 | { |
---|
| 58 | /* Get this key now already, since "nick" might be free()d |
---|
| 59 | at the time we start playing with the hash... */ |
---|
| 60 | key = g_strdup( nick ); |
---|
| 61 | nick_lc( key ); |
---|
| 62 | |
---|
| 63 | if( t ) |
---|
| 64 | t->next = u->next; |
---|
| 65 | else |
---|
| 66 | irc->users = u->next; |
---|
| 67 | if( u->online ) |
---|
| 68 | irc_kill( irc, u ); |
---|
| 69 | g_free( u->nick ); |
---|
| 70 | if( u->nick != u->user ) g_free( u->user ); |
---|
| 71 | if( u->nick != u->host ) g_free( u->host ); |
---|
| 72 | if( u->nick != u->realname ) g_free( u->realname ); |
---|
[38cc9d4] | 73 | g_free( u->group ); |
---|
| 74 | g_free( u->away ); |
---|
| 75 | g_free( u->handle ); |
---|
| 76 | g_free( u->sendbuf ); |
---|
[ba9edaa] | 77 | if( u->sendbuf_timer ) b_event_remove( u->sendbuf_timer ); |
---|
[b7d3cc34] | 78 | g_free( u ); |
---|
| 79 | |
---|
| 80 | return( 1 ); |
---|
| 81 | } |
---|
| 82 | u = (t=u)->next; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | return( 0 ); |
---|
| 86 | } |
---|
| 87 | |
---|
[fa295e36] | 88 | user_t *user_findhandle( struct im_connection *ic, const char *handle ) |
---|
[b7d3cc34] | 89 | { |
---|
[5b52a48] | 90 | user_t *u; |
---|
| 91 | char *nick; |
---|
[b7d3cc34] | 92 | |
---|
[5b52a48] | 93 | /* First, let's try a hash lookup. If it works, it's probably faster. */ |
---|
[0da65d5] | 94 | if( ( nick = g_hash_table_lookup( ic->acc->nicks, handle ) ) && |
---|
| 95 | ( u = user_find( ic->irc, nick ) ) && |
---|
| 96 | ( ic->acc->prpl->handle_cmp( handle, u->handle ) == 0 ) ) |
---|
[5b52a48] | 97 | return u; |
---|
[b7d3cc34] | 98 | |
---|
[5b52a48] | 99 | /* However, it doesn't always work, so in that case we'll have to dig |
---|
| 100 | through the whole userlist. :-( */ |
---|
[0da65d5] | 101 | for( u = ic->irc->users; u; u = u->next ) |
---|
| 102 | if( u->ic == ic && u->handle && ic->acc->prpl->handle_cmp( u->handle, handle ) == 0 ) |
---|
[5b52a48] | 103 | return u; |
---|
| 104 | |
---|
| 105 | return NULL; |
---|
[b7d3cc34] | 106 | } |
---|