Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/presence.c

    r1bf1ae6 r1baaef8  
    3131        struct xt_node *c;
    3232        struct jabber_buddy *bud;
     33        int is_chat = 0, is_away = 0;
    3334        char *s;
    3435       
     
    3637                return XT_HANDLED;
    3738       
     39        if( ( s = strchr( from, '/' ) ) )
     40        {
     41                *s = 0;
     42                if( jabber_chat_by_name( ic, from ) )
     43                        is_chat = 1;
     44                *s = '/';
     45        }
     46       
    3847        if( type == NULL )
    3948        {
    40                 int is_away = 0;
    41                
    4249                if( !( bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT | GET_BUDDY_CREAT ) ) )
    4350                {
     
    7279                        bud->priority = 0;
    7380               
    74                 if( bud == jabber_buddy_by_jid( ic, bud->bare_jid, 0 ) )
     81                if( is_chat )
     82                        jabber_chat_pkt_presence( ic, bud, node );
     83                else if( bud == jabber_buddy_by_jid( ic, bud->bare_jid, 0 ) )
    7584                        imcb_buddy_status( ic, bud->bare_jid, OPT_LOGGED_IN | is_away,
    7685                                           ( is_away && bud->away_state ) ? bud->away_state->full_name : NULL,
     
    7988        else if( strcmp( type, "unavailable" ) == 0 )
    8089        {
    81                 if( jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT ) == NULL )
     90                if( ( bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT ) ) == NULL )
    8291                {
    8392                        if( set_getbool( &ic->irc->set, "debug" ) )
     
    8695                }
    8796               
     97                /* Handle this before we delete the JID. */
     98                if( is_chat )
     99                {
     100                        jabber_chat_pkt_presence( ic, bud, node );
     101                }
     102               
    88103                jabber_buddy_remove( ic, from );
    89104               
    90                 if( ( s = strchr( from, '/' ) ) )
     105                if( is_chat )
     106                {
     107                        /* Nothing else to do for now? */
     108                }
     109                else if( ( s = strchr( from, '/' ) ) )
    91110                {
    92111                        *s = 0;
    93112               
    94                         /* Only count this as offline if there's no other resource
    95                            available anymore. */
    96                         if( jabber_buddy_by_jid( ic, from, 0 ) == NULL )
     113                        /* If another resource is still available, send its presence
     114                           information. */
     115                        if( ( bud = jabber_buddy_by_jid( ic, from, 0 ) ) )
     116                        {
     117                                if( bud->away_state && ( *bud->away_state->code == 0 ||
     118                                    strcmp( bud->away_state->code, "chat" ) == 0 ) )
     119                                        is_away = OPT_AWAY;
     120                               
     121                                imcb_buddy_status( ic, bud->bare_jid, OPT_LOGGED_IN | is_away,
     122                                                   ( is_away && bud->away_state ) ? bud->away_state->full_name : NULL,
     123                                                   bud->away_message );
     124                        }
     125                        else
     126                        {
     127                                /* Otherwise, count him/her as offline now. */
    97128                                imcb_buddy_status( ic, from, 0, NULL, NULL );
     129                        }
    98130                       
    99131                        *s = '/';
     
    126158        else if( strcmp( type, "error" ) == 0 )
    127159        {
    128                 /* What to do with it? */
     160                struct jabber_error *err;
     161               
     162                if( ( c = xt_find_node( node->children, "error" ) ) )
     163                {
     164                        err = jabber_error_parse( c, XMLNS_STANZA_ERROR );
     165                        imcb_error( ic, "Stanza (%s) error: %s%s%s", node->name,
     166                                    err->code, err->text ? ": " : "",
     167                                    err->text ? err->text : "" );
     168                        jabber_error_free( err );
     169                }
     170                /* What else to do with it? */
     171        }
     172        else
     173        {
     174                printf( "Received PRES from %s:\n", from );
     175                xt_print( node );
    129176        }
    130177       
     
    140187        char *show = jd->away_state->code;
    141188        char *status = jd->away_message;
     189        struct groupchat *c;
    142190        int st;
    143191       
     
    151199        st = jabber_write_packet( ic, node );
    152200       
     201        /* Have to send this update to all groupchats too, the server won't
     202           do this automatically. */
     203        for( c = ic->groupchats; c && st; c = c->next )
     204        {
     205                struct jabber_chat *jc = c->data;
     206               
     207                xt_add_attr( node, "to", jc->my_full_jid );
     208                st = jabber_write_packet( ic, node );
     209        }
     210       
    153211        xt_free_node( node );
    154212        return st;
Note: See TracChangeset for help on using the changeset viewer.