diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-03-29 08:25:01 -0400 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-03-29 08:25:01 -0400 |
commit | 10a96f44efbeb6af09e2728926ce15b6bda12131 (patch) | |
tree | 256bfa92a79775d4180a2c227a30512a56b39f26 /protocols | |
parent | 38ee0216a7058b0f227d1c32b288e041a397528a (diff) |
Start restoring IM-related bits, added bee_user.c with basic functions
and UI callbacks.
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Makefile | 2 | ||||
-rw-r--r-- | protocols/bee.h | 73 | ||||
-rw-r--r-- | protocols/bee_user.c | 82 | ||||
-rw-r--r-- | protocols/nogaim.c | 59 | ||||
-rw-r--r-- | protocols/user.c | 106 | ||||
-rw-r--r-- | protocols/user.h | 40 |
6 files changed, 180 insertions, 182 deletions
diff --git a/protocols/Makefile b/protocols/Makefile index f1133cc9..1f89ee5a 100644 --- a/protocols/Makefile +++ b/protocols/Makefile @@ -10,7 +10,7 @@ # [SH] Program variables #objects = account.o nogaim.o user.o -objects = bee.o +objects = bee.o bee_user.o nogaim.o # [SH] The next two lines should contain the directory name (in $(subdirs)) diff --git a/protocols/bee.h b/protocols/bee.h index b25f0e08..e5c21120 100644 --- a/protocols/bee.h +++ b/protocols/bee.h @@ -1,7 +1,32 @@ -typedef struct bee_ui -{ - void *data; -} bee_ui_t; + /********************************************************************\ + * BitlBee -- An IRC to other IM-networks gateway * + * * + * Copyright 2002-2010 Wilmer van der Gaast and others * + \********************************************************************/ + +/* Stuff to handle, save and search buddies */ + +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License with + the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, + Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __BEE_H__ +#define __BEE_H__ + +struct bee_ui_funcs; typedef struct bee { @@ -10,9 +35,47 @@ typedef struct bee GSList *users; GSList *accounts; - //const bee_ui_funcs_t *ui; + const struct bee_ui_funcs *ui; void *ui_data; } bee_t; bee_t *bee_new(); void bee_free( bee_t *b ); + +typedef enum +{ + BEE_USER_ONLINE = 1, + BEE_USER_AWAY = 2, +} bee_user_flags_t; + +typedef struct bee_user +{ + struct im_connection *ic; + char *handle; + char *fullname; + char *group; + + char *away; + char *status_msg; + + bee_t *bee; + void *ui_data; +} bee_user_t; + +typedef struct bee_ui_funcs +{ + gboolean (*user_new)( bee_t *bee, struct bee_user *bu ); + gboolean (*user_free)( bee_t *bee, struct bee_user *bu ); +} bee_ui_funcs_t; + + +/* bee.c */ +bee_t *bee_new(); +void bee_free( bee_t *b ); + +/* bee_user.c */ +bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *handle ); +int bee_user_free( bee_t *bee, struct im_connection *ic, const char *handle ); +bee_user_t *bee_user_by_handle( bee_t *bee, struct im_connection *ic, const char *handle ); + +#endif /* __BEE_H__ */ diff --git a/protocols/bee_user.c b/protocols/bee_user.c new file mode 100644 index 00000000..538aa509 --- /dev/null +++ b/protocols/bee_user.c @@ -0,0 +1,82 @@ + /********************************************************************\ + * BitlBee -- An IRC to other IM-networks gateway * + * * + * Copyright 2002-2010 Wilmer van der Gaast and others * + \********************************************************************/ + +/* Stuff to handle, save and search buddies */ + +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License with + the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, + Suite 330, Boston, MA 02111-1307 USA +*/ + +#define BITLBEE_CORE +#include "bitlbee.h" + +bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *handle ) +{ + bee_user_t *bu; + + if( bee_user_by_handle( bee, ic, handle ) != NULL ) + return NULL; + + bu = g_new0( bee_user_t, 1 ); + bu->bee = bee; + bu->ic = ic; + bu->handle = g_strdup( handle ); + bee->users = g_slist_prepend( bee->users, bu ); + + if( bee->ui->user_new ) + bee->ui->user_new( bee, bu ); + + return bu; +} + +int bee_user_free( bee_t *bee, struct im_connection *ic, const char *handle ) +{ + bee_user_t *bu; + + if( ( bu = bee_user_by_handle( bee, ic, handle ) ) == NULL ) + return 0; + + if( bee->ui->user_free ) + bee->ui->user_free( bee, bu ); + + g_free( bu->handle ); + g_free( bu->fullname ); + g_free( bu->group ); + g_free( bu->away ); + g_free( bu->status_msg ); + + bee->users = g_slist_remove( bee->users, bu ); + + return 1; +} + +bee_user_t *bee_user_by_handle( bee_t *bee, struct im_connection *ic, const char *handle ) +{ + GSList *l; + + for( l = bee->users; l; l = l->next ) + { + bee_user_t *bu = l->data; + + if( bu->ic == ic && ic->acc->prpl->handle_cmp( bu->handle, handle ) ) + return bu; + } + + return NULL; +} diff --git a/protocols/nogaim.c b/protocols/nogaim.c index c326e378..618616c7 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -198,8 +198,8 @@ static void serv_got_crap( struct im_connection *ic, char *format, ... ) text = g_strdup_vprintf( format, params ); va_end( params ); - if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || - ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) + if( ( g_strcasecmp( set_getstr( &ic->irc->b->set, "strip_html" ), "always" ) == 0 ) || + ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->b->set, "strip_html" ) ) ) strip_html( text ); /* Try to find a different connection on the same protocol. */ @@ -264,7 +264,6 @@ void imcb_connected( struct im_connection *ic ) { irc_t *irc = ic->irc; struct chat *c; - user_t *u; /* MSN servers sometimes redirect you to a different server and do the whole login sequence again, so these "late" calls to this @@ -272,8 +271,6 @@ void imcb_connected( struct im_connection *ic ) if( ic->flags & OPT_LOGGED_IN ) return; - u = user_find( ic->irc, ic->irc->nick ); - imcb_log( ic, "Logged in" ); ic->keepalive = b_timeout_add( 60000, send_keepalive, ic ); @@ -286,6 +283,7 @@ void imcb_connected( struct im_connection *ic ) exponential backoff timer. */ ic->acc->auto_reconnect_delay = 0; + /* for( c = irc->chatrooms; c; c = c->next ) { if( c->acc != ic->acc ) @@ -294,6 +292,7 @@ void imcb_connected( struct im_connection *ic ) if( set_getbool( &c->set, "auto_join" ) ) chat_join( irc, c, NULL ); } + */ } gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond ) @@ -359,7 +358,7 @@ void imc_logout( struct im_connection *ic, int allow_reconnect ) { /* Uhm... This is very sick. */ } - else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) && + else if( allow_reconnect && set_getbool( &irc->b->set, "auto_reconnect" ) && set_getbool( &a->set, "auto_reconnect" ) && ( delay = account_reconnect_delay( a ) ) > 0 ) { @@ -390,7 +389,7 @@ void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *g if( user_findhandle( ic, handle ) ) { - if( set_getbool( &irc->set, "debug" ) ) + if( set_getbool( &irc->b->set, "debug" ) ) imcb_log( ic, "User already exists, ignoring add request: %s", handle ); return; @@ -469,7 +468,7 @@ void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char u->realname = g_strdup( realname ); - if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) ) + if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->b->set, "display_namechanges" ) ) imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); } @@ -517,7 +516,7 @@ void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const c /* Some processing to make sure this string is a valid IRC nickname. */ nick_strip( newnick ); - if( set_getbool( &ic->irc->set, "lcnicks" ) ) + if( set_getbool( &ic->irc->b->set, "lcnicks" ) ) nick_lc( newnick ); if( strcmp( u->nick, newnick ) != 0 ) @@ -625,14 +624,14 @@ void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, if( !u ) { - if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 ) + if( g_strcasecmp( set_getstr( &ic->irc->b->set, "handle_unknown" ), "add" ) == 0 ) { imcb_add_buddy( ic, (char*) handle, NULL ); u = user_findhandle( ic, (char*) handle ); } else { - if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 ) + if( set_getbool( &ic->irc->b->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->b->set, "handle_unknown" ), "ignore" ) != 0 ) { imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle ); imcb_log( ic, "flags = %d, state = %s, message = %s", flags, @@ -692,14 +691,14 @@ void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, } /* LISPy... */ - if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ + if( ( set_getbool( &ic->irc->b->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 */ { char *from; - if( set_getbool( &ic->irc->set, "simulate_netsplit" ) ) + if( set_getbool( &ic->irc->b->set, "simulate_netsplit" ) ) { from = g_strdup( ic->irc->myhost ); } @@ -724,18 +723,18 @@ void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, ui if( !u ) { - char *h = set_getstr( &irc->set, "handle_unknown" ); + char *h = set_getstr( &irc->b->set, "handle_unknown" ); if( g_strcasecmp( h, "ignore" ) == 0 ) { - if( set_getbool( &irc->set, "debug" ) ) + if( set_getbool( &irc->b->set, "debug" ) ) imcb_log( ic, "Ignoring message from unknown handle %s", handle ); return; } else if( g_strncasecmp( h, "add", 3 ) == 0 ) { - int private = set_getbool( &irc->set, "private" ); + int private = set_getbool( &irc->b->set, "private" ); if( h[3] ) { @@ -756,8 +755,8 @@ void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, ui } } - if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || - ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) + if( ( g_strcasecmp( set_getstr( &ic->irc->b->set, "strip_html" ), "always" ) == 0 ) || + ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->b->set, "strip_html" ) ) ) strip_html( msg ); wrapped = word_wrap( msg, 425 ); @@ -769,7 +768,7 @@ void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags ) { user_t *u; - if( !set_getbool( &ic->irc->set, "typing_notice" ) ) + if( !set_getbool( &ic->irc->b->set, "typing_notice" ) ) return; if( ( u = user_findhandle( ic, handle ) ) ) @@ -800,7 +799,7 @@ struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle ) c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ ); c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); - if( set_getbool( &ic->irc->set, "debug" ) ) + if( set_getbool( &ic->irc->b->set, "debug" ) ) imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle ); return c; @@ -812,7 +811,7 @@ void imcb_chat_free( struct groupchat *c ) struct groupchat *l; GList *ir; - if( set_getbool( &ic->irc->set, "debug" ) ) + if( set_getbool( &ic->irc->b->set, "debug" ) ) imcb_log( ic, "You were removed from conversation %p", c ); if( c ) @@ -859,8 +858,8 @@ void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t fl u = user_findhandle( ic, who ); - if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || - ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) + if( ( g_strcasecmp( set_getstr( &ic->irc->b->set, "strip_html" ), "always" ) == 0 ) || + ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->b->set, "strip_html" ) ) ) strip_html( msg ); wrapped = word_wrap( msg, 425 ); @@ -905,8 +904,8 @@ void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at else u = user_findhandle( ic, who ); - if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || - ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) + if( ( g_strcasecmp( set_getstr( &ic->irc->b->set, "strip_html" ), "always" ) == 0 ) || + ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->b->set, "strip_html" ) ) ) strip_html( topic ); g_free( c->topic ); @@ -924,7 +923,7 @@ void imcb_chat_add_buddy( struct groupchat *b, const char *handle ) user_t *u = user_findhandle( b->ic, handle ); int me = 0; - if( set_getbool( &b->ic->irc->set, "debug" ) ) + if( set_getbool( &b->ic->irc->b->set, "debug" ) ) imcb_log( b->ic, "User %s added to conversation %p", handle, b ); /* It might be yourself! */ @@ -959,7 +958,7 @@ void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char user_t *u; int me = 0; - if( set_getbool( &b->ic->irc->set, "debug" ) ) + if( set_getbool( &b->ic->irc->b->set, "debug" ) ) imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" ); /* It might be yourself! */ @@ -1017,7 +1016,7 @@ char *set_eval_away_devoice( set_t *set, char *value ) /* Horror.... */ - if( st != set_getbool( &irc->set, "away_devoice" ) ) + if( st != set_getbool( &irc->b->set, "away_devoice" ) ) { char list[80] = ""; user_t *u = irc->users; @@ -1106,7 +1105,7 @@ int imc_away_send_update( struct im_connection *ic ) char *away, *msg = NULL; away = set_getstr( &ic->acc->set, "away" ) ? - : set_getstr( &ic->irc->set, "away" ); + : set_getstr( &ic->irc->b->set, "away" ); if( away && *away ) { GList *m = ic->acc->prpl->away_states( ic ); @@ -1117,7 +1116,7 @@ int imc_away_send_update( struct im_connection *ic ) { away = NULL; msg = set_getstr( &ic->acc->set, "status" ) ? - : set_getstr( &ic->irc->set, "status" ); + : set_getstr( &ic->irc->b->set, "status" ); } ic->acc->prpl->set_away( ic, away, msg ); diff --git a/protocols/user.c b/protocols/user.c deleted file mode 100644 index f014586b..00000000 --- a/protocols/user.c +++ /dev/null @@ -1,106 +0,0 @@ - /********************************************************************\ - * BitlBee -- An IRC to other IM-networks gateway * - * * - * Copyright 2002-2004 Wilmer van der Gaast and others * - \********************************************************************/ - -/* Stuff to handle, save and search buddies */ - -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License with - the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; - if not, write to the Free Software Foundation, Inc., 59 Temple Place, - Suite 330, Boston, MA 02111-1307 USA -*/ - -#define BITLBEE_CORE -#include "bitlbee.h" - -user_t *user_add( irc_t *irc, char *nick ) -{ - user_t *u, *lu = NULL; - char *key; - - if( !nick_ok( nick ) ) - return( NULL ); - - if( user_find( irc, nick ) != NULL ) - return( NULL ); - - return( u ); -} - -int user_del( irc_t *irc, char *nick ) -{ - user_t *u, *t; - char *key; - gpointer okey, ovalue; - - if( !nick_ok( nick ) ) - return( 0 ); - - u = irc->users; - t = NULL; - while( u ) - { - if( nick_cmp( u->nick, nick ) == 0 ) - { - /* Get this key now already, since "nick" might be free()d - at the time we start playing with the hash... */ - key = g_strdup( nick ); - nick_lc( key ); - - if( t ) - t->next = u->next; - else - irc->users = u->next; - if( u->online ) - irc_kill( irc, u ); - g_free( u->nick ); - if( u->nick != u->user ) g_free( u->user ); - if( u->nick != u->host ) g_free( u->host ); - if( u->nick != u->realname ) g_free( u->realname ); - g_free( u->group ); - g_free( u->away ); - g_free( u->handle ); - g_free( u->sendbuf ); - if( u->sendbuf_timer ) b_event_remove( u->sendbuf_timer ); - g_free( u ); - - return( 1 ); - } - u = (t=u)->next; - } - - return( 0 ); -} - -user_t *user_findhandle( struct im_connection *ic, const char *handle ) -{ - user_t *u; - char *nick; - - /* First, let's try a hash lookup. If it works, it's probably faster. */ - if( ( nick = g_hash_table_lookup( ic->acc->nicks, handle ) ) && - ( u = user_find( ic->irc, nick ) ) && - ( ic->acc->prpl->handle_cmp( handle, u->handle ) == 0 ) ) - return u; - - /* However, it doesn't always work, so in that case we'll have to dig - through the whole userlist. :-( */ - for( u = ic->irc->users; u; u = u->next ) - if( u->ic == ic && u->handle && ic->acc->prpl->handle_cmp( u->handle, handle ) == 0 ) - return u; - - return NULL; -} diff --git a/protocols/user.h b/protocols/user.h deleted file mode 100644 index 26697a3a..00000000 --- a/protocols/user.h +++ /dev/null @@ -1,40 +0,0 @@ - /********************************************************************\ - * BitlBee -- An IRC to other IM-networks gateway * - * * - * Copyright 2002-2004 Wilmer van der Gaast and others * - \********************************************************************/ - -/* Stuff to handle, save and search buddies */ - -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License with - the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; - if not, write to the Free Software Foundation, Inc., 59 Temple Place, - Suite 330, Boston, MA 02111-1307 USA -*/ - -#ifndef __USER_H__ -#define __USER_H__ - -struct __USER -{ - struct im_connection *ic; - char *handle; - char *fullname; - char *group; - - char *away; - char *status_msg; -} user_t; - -#endif /* __USER_H__ */ |