Changeset 256899f for protocols/nogaim.c


Ignore:
Timestamp:
2007-11-19T23:16:18Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
7df5a08
Parents:
cd428e4 (diff), ef5c185 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging Jabber groupchat support.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    rcd428e4 r256899f  
    9999}
    100100
    101  
    102101struct prpl *find_protocol(const char *name)
    103102{
     
    289288{
    290289        irc_t *irc = ic->irc;
    291         user_t *t, *u = irc->users;
     290        user_t *t, *u;
    292291        account_t *a;
    293292       
     
    306305        b_event_remove( ic->inpa );
    307306       
     307        u = irc->users;
    308308        while( u )
    309309        {
     
    428428{
    429429        user_t *u = user_findhandle( ic, handle );
    430         char *s, newnick[MAX_NICK_LENGTH+1];
    431430       
    432431        if( !u || !realname ) return;
     
    440439                if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) )
    441440                        imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname );
    442                
    443                 if( !u->online && !nick_saved( ic->acc, handle ) )
    444                 {
    445                         /* Detect numeric handles: */
    446                         for( s = u->user; isdigit( *s ); s++ );
     441        }
     442}
     443
     444void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group )
     445{
     446        user_t *u;
     447       
     448        if( ( u = user_findhandle( ic, handle ) ) )
     449                user_del( ic->irc, u->nick );
     450}
     451
     452/* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM
     453   modules to suggest a nickname for a handle. */
     454void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick )
     455{
     456        user_t *u = user_findhandle( ic, handle );
     457        char newnick[MAX_NICK_LENGTH+1], *orig_nick;
     458       
     459        if( u && !u->online && !nick_saved( ic->acc, handle ) )
     460        {
     461                /* Only do this if the person isn't online yet (which should
     462                   be the case if we just added it) and if the user hasn't
     463                   assigned a nickname to this buddy already. */
     464               
     465                strncpy( newnick, nick, MAX_NICK_LENGTH );
     466                newnick[MAX_NICK_LENGTH] = 0;
     467               
     468                /* Some processing to make sure this string is a valid IRC nickname. */
     469                nick_strip( newnick );
     470                if( set_getbool( &ic->irc->set, "lcnicks" ) )
     471                        nick_lc( newnick );
     472               
     473                if( strcmp( u->nick, newnick ) != 0 )
     474                {
     475                        /* Only do this if newnick is different from the current one.
     476                           If rejoining a channel, maybe we got this nick already
     477                           (and dedupe would only add an underscore. */
     478                        nick_dedupe( ic->acc, handle, newnick );
    447479                       
    448                         if( *s == 0 )
    449                         {
    450                                 /* If we reached the end of the string, it only contained numbers.
    451                                    Seems to be an ICQ# then, so hopefully realname contains
    452                                    something more useful. */
    453                                 strcpy( newnick, realname );
    454                                
    455                                 /* Some processing to make sure this string is a valid IRC nickname. */
    456                                 nick_strip( newnick );
    457                                 if( set_getbool( &ic->irc->set, "lcnicks" ) )
    458                                         nick_lc( newnick );
    459                                
    460                                 u->nick = g_strdup( newnick );
    461                         }
    462                 }
    463         }
    464 }
    465 
     480                        /* u->nick will be freed halfway the process, so it can't be
     481                           passed as an argument. */
     482                        orig_nick = g_strdup( u->nick );
     483                        user_rename( ic->irc, orig_nick, newnick );
     484                        g_free( orig_nick );
     485                }
     486        }
     487}
    466488
    467489/* prpl.c */
     
    554576                u->online = 0;
    555577               
    556                 /* Remove him/her from the conversations to prevent PART messages after he/she QUIT already */
    557                 for( c = ic->conversations; c; c = c->next )
     578                /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */
     579                for( c = ic->groupchats; c; c = c->next )
    558580                        remove_chat_buddy_silent( c, handle );
    559581        }
     
    670692}
    671693
    672 void imcb_chat_removed( struct groupchat *c )
     694void imcb_chat_free( struct groupchat *c )
    673695{
    674696        struct im_connection *ic = c->ic;
    675         struct groupchat *l = NULL;
     697        struct groupchat *l;
    676698        GList *ir;
    677699       
     
    693715                }
    694716               
     717                /* Find the previous chat in the linked list. */
     718                for( l = ic->groupchats; l && l->next != c; l = l->next );
     719               
    695720                if( l )
    696721                        l->next = c->next;
    697722                else
    698                         ic->conversations = c->next;
     723                        ic->groupchats = c->next;
    699724               
    700725                for( ir = c->in_room; ir; ir = ir->next )
     
    735760}
    736761
     762void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at )
     763{
     764        struct im_connection *ic = c->ic;
     765        user_t *u = NULL;
     766       
     767        if( who == NULL)
     768                u = user_find( ic->irc, ic->irc->mynick );
     769        else if( g_strcasecmp( who, ic->acc->user ) == 0 )
     770                u = user_find( ic->irc, ic->irc->nick );
     771        else
     772                u = user_findhandle( ic, who );
     773       
     774        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
     775            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
     776                strip_html( topic );
     777       
     778        g_free( c->topic );
     779        c->topic = g_strdup( topic );
     780       
     781        if( c->joined && u )
     782                irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic );
     783}
     784
    737785struct groupchat *imcb_chat_new( struct im_connection *ic, char *handle )
    738786{
     
    741789        /* This one just creates the conversation structure, user won't see anything yet */
    742790       
    743         if( ic->conversations )
    744         {
    745                 for( c = ic->conversations; c->next; c = c->next );
     791        if( ic->groupchats )
     792        {
     793                for( c = ic->groupchats; c->next; c = c->next );
    746794                c = c->next = g_new0( struct groupchat, 1 );
    747795        }
    748796        else
    749                 ic->conversations = c = g_new0( struct groupchat, 1 );
     797                ic->groupchats = c = g_new0( struct groupchat, 1 );
    750798       
    751799        c->ic = ic;
    752800        c->title = g_strdup( handle );
    753801        c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ );
     802        c->topic = g_strdup_printf( "%s :BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->channel, c->title );
    754803       
    755804        if( set_getbool( &ic->irc->set, "debug" ) )
     
    796845}
    797846
     847/* This function is one BIG hack... :-( EREWRITE */
    798848void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason )
    799849{
     
    807857        if( g_strcasecmp( handle, b->ic->acc->user ) == 0 )
    808858        {
     859                if( b->joined == 0 )
     860                        return;
     861               
    809862                u = user_find( b->ic->irc, b->ic->irc->nick );
    810863                b->joined = 0;
     
    816869        }
    817870       
    818         if( remove_chat_buddy_silent( b, handle ) )
    819                 if( ( b->joined || me ) && u )
    820                         irc_part( b->ic->irc, u, b->channel );
     871        if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) )
     872                irc_part( b->ic->irc, u, b->channel );
    821873}
    822874
     
    844896
    845897/* Misc. BitlBee stuff which shouldn't really be here */
    846 
    847 struct groupchat *chat_by_channel( char *channel )
    848 {
    849         struct im_connection *ic;
    850         struct groupchat *c;
    851         GSList *l;
    852        
    853         /* This finds the connection which has a conversation which belongs to this channel */
    854         for( l = connections; l; l = l->next )
    855         {
    856                 ic = l->data;
    857                 for( c = ic->conversations; c && g_strcasecmp( c->channel, channel ) != 0; c = c->next );
    858                 if( c )
    859                         return c;
    860         }
    861        
    862         return NULL;
    863 }
    864898
    865899char *set_eval_away_devoice( set_t *set, char *value )
     
    10951129        ic->acc->prpl->rem_deny( ic, handle );
    10961130}
     1131
     1132void imcb_clean_handle( struct im_connection *ic, char *handle )
     1133{
     1134        /* Accepts a handle and does whatever is necessary to make it
     1135           BitlBee-friendly. Currently this means removing everything
     1136           outside 33-127 (ASCII printable excl spaces), @ (only one
     1137           is allowed) and ! and : */
     1138        char out[strlen(handle)+1];
     1139        int s, d;
     1140       
     1141        s = d = 0;
     1142        while( handle[s] )
     1143        {
     1144                if( handle[s] > ' ' && handle[s] != '!' && handle[s] != ':' &&
     1145                    ( handle[s] & 0x80 ) == 0 )
     1146                {
     1147                        if( handle[s] == '@' )
     1148                        {
     1149                                /* See if we got an @ already? */
     1150                                out[d] = 0;
     1151                                if( strchr( out, '@' ) )
     1152                                        continue;
     1153                        }
     1154                       
     1155                        out[d++] = handle[s];
     1156                }
     1157                s ++;
     1158        }
     1159        out[d] = handle[s];
     1160       
     1161        strcpy( handle, out );
     1162}
Note: See TracChangeset for help on using the changeset viewer.