Changeset f0071b7 for protocols


Ignore:
Timestamp:
2006-10-23T20:01:19Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
62d0c14
Parents:
e8a6211
Message:

Better handling of <message/> packets. (Headlines, JIDs without /resource
part, non-chat messages.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/message.c

    re8a6211 rf0071b7  
    2929        char *from = xt_find_attr( node, "from" );
    3030        char *type = xt_find_attr( node, "type" );
    31         struct xt_node *body = xt_find_node( node->children, "body" );
     31        struct xt_node *body = xt_find_node( node->children, "body" ), *c;
    3232        char *s;
    3333       
    34         if( !type )
    35                 return XT_HANDLED;      /* Grmbl... FIXME */
    36        
    37         if( strcmp( type, "chat" ) == 0 )
     34        if( type && strcmp( type, "error" ) == 0 )
     35        {
     36                /* Handle type=error packet. */
     37        }
     38        else if( type && strcmp( type, "groupchat" ) == 0 )
     39        {
     40                /* TODO! */
     41        }
     42        else /* "chat", "normal", "headline", no-type or whatever. Should all be pretty similar. */
    3843        {
    3944                struct jabber_buddy *bud = NULL;
     45                GString *fullmsg = g_string_new( "" );
    4046               
    41                 if( ( s = strchr( from, '/' ) ) == NULL )
     47                if( ( s = strchr( from, '/' ) ) )
    4248                {
    43                         /* It just shouldn't happen. */
    44                         hide_login_progress( gc, "Received message packet from bare JID" );
    45                         signoff( gc );
    46                         return XT_ABORT;
     49                        if( ( bud = jabber_buddy_by_jid( gc, from ) ) )
     50                                bud->last_act = time( NULL );
     51                        else
     52                                *s = 0; /* We need to generate a bare JID now. */
    4753                }
    4854               
    49                 if( ( bud = jabber_buddy_by_jid( gc, from ) ) )
    50                         bud->last_act = time( NULL );
    51                 else
    52                         *s = 0; /* We need to generate a bare JID now. */
     55                if( strcmp( type, "headline" ) == 0 )
     56                {
     57                        c = xt_find_node( node->children, "subject" );
     58                        g_string_append_printf( fullmsg, "Headline: %s\n", c && c->text_len > 0 ? c->text : "" );
     59                       
     60                        /* <x xmlns="jabber:x:oob"><url>http://....</url></x> can contain a URL, it seems. */
     61                        for( c = node->children; c; c = c->next )
     62                        {
     63                                struct xt_node *url;
     64                               
     65                                if( ( url = xt_find_node( c->children, "url" ) ) && url->text_len > 0 )
     66                                        g_string_append_printf( fullmsg, "URL: %s\n", url->text );
     67                        }
     68                }
     69                else if( ( c = xt_find_node( node->children, "subject" ) ) && c->text_len > 0 )
     70                {
     71                        g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Message with subject: %s >>\n", c->text );
     72                }
    5373               
    54                 if( body ) /* Could be just a typing notification. */
    55                         serv_got_im( gc, bud ? bud->handle : from, body->text, 0, 0, 0 );
     74                if( body && body->text_len > 0 ) /* Could be just a typing notification. */
     75                        fullmsg = g_string_append( fullmsg, body->text );
     76               
     77                if( fullmsg->len > 0 )
     78                        serv_got_im( gc, bud ? bud->handle : from, fullmsg->str, 0, 0, fullmsg->len );
     79               
     80                g_string_free( fullmsg, TRUE );
    5681               
    5782                /* Handling of incoming typing notifications. */
     
    76101                        *s = '/'; /* And convert it back to a full JID. */
    77102        }
    78         else
    79         {
    80                 printf( "Received MSG from %s:\n", from );
    81                 xt_print( node );
    82         }
    83103       
    84104        return XT_HANDLED;
Note: See TracChangeset for help on using the changeset viewer.